package com.sun.slp;
import java.util.*;
import java.io.*;
class SSAAdvert extends SrvLocMsgImpl {
SSAAdvert(int version,
short xid,
Locale locale,
ServiceURL url,
Vector scopes,
Vector attrs)
throws ServiceLocationException {
hdr = new SLPServerHeaderV2();
Assert.slpassert(hdr != null,
"version_number_error",
new Object[] {Integer.valueOf(version)});
hdr.functionCode = SrvLocHeader.SAAdvert;
hdr.xid = xid;
hdr.locale = locale;
this.initialize(url, scopes, attrs);
}
void initialize(ServiceURL url, Vector scopes, Vector attrs)
throws ServiceLocationException {
SLPServerHeaderV2 hdr = (SLPServerHeaderV2)getHeader();
ServiceType serviceType = url.getServiceType();
if (!serviceType.equals(Defaults.SA_SERVICE_TYPE)) {
throw
new ServiceLocationException(
ServiceLocationException.PARSE_ERROR,
"ssaadv_nonsaurl",
new Object[] {serviceType});
}
DATable.validateScopes(scopes, hdr.locale);
hdr.scopes = (Vector)scopes.clone();
hdr.escapeScopeStrings(scopes);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String surl = url.toString();
byte[] urlBytes = hdr.putString(surl, baos);
byte[] scopeBytes =
hdr.parseCommaSeparatedListOut(scopes, baos);
byte[] attrBytes = hdr.parseAttributeVectorOut(attrs,
url.getLifetime(),
false,
null,
baos,
false);
Hashtable auth = null;
byte nBlocks = 0;
if (SLPConfig.getSLPConfig().getHasSecurity()) {
Object[] message = new Object[6];
ByteArrayOutputStream abaos = new ByteArrayOutputStream();
hdr.putInteger(urlBytes.length, abaos);
message[0] = abaos.toByteArray();
message[1] = urlBytes;
abaos = new ByteArrayOutputStream();
hdr.putInteger(attrBytes.length, abaos);
message[2] = abaos.toByteArray();
message[3] = attrBytes;
abaos = new ByteArrayOutputStream();
hdr.putInteger(scopeBytes.length, abaos);
message[4] = abaos.toByteArray();
message[5] = scopeBytes;
auth = hdr.getCheckedAuthBlockList(message,
url.getLifetime());
nBlocks = (byte) auth.size();
}
baos.write(nBlocks);
hdr.nbytes++;
if (auth != null) {
AuthBlock.externalizeAll(hdr, auth, baos);
}
hdr.payload = baos.toByteArray();
hdr.constructDescription("SAAdvert",
" URL=``" + url + "''\n" +
" attrs=``" + attrs + "''\n" +
" auth block="+AuthBlock.desc(auth) +
"\n");
}
}