#include <stdio.h>
#include <slp-internal.h>
SLPError slp_unpackDAAdvert(char *reply, char **surl, char **scopes,
char **attrs, char **spis, SLPError *errCode) {
unsigned short protoErrCode, dummy;
size_t len, off;
SLPError err = SLP_OK;
struct iovec iov[5];
size_t tmp_off;
int auth_cnt;
size_t abLen = 0;
*surl = *scopes = *attrs = *spis = NULL;
len = slp_get_length(reply);
off = SLP_HDRLEN + slp_get_langlen(reply);
if ((err = slp_get_sht(reply, len, &off, &protoErrCode)) != SLP_OK)
goto fail;
*errCode = slp_map_err(protoErrCode);
if (*errCode != SLP_OK) {
return (SLP_OK);
}
iov[0].iov_base = reply + off;
tmp_off = off;
if ((err = slp_get_sht(reply, len, &off, &dummy)) != SLP_OK) {
goto fail;
}
if ((err = slp_get_sht(reply, len, &off, &dummy)) != SLP_OK) {
goto fail;
}
iov[0].iov_len = off - tmp_off;
iov[1].iov_base = reply + off;
tmp_off = off;
if ((err = slp_get_string(reply, len, &off, surl)) != SLP_OK) {
goto fail;
}
iov[1].iov_len = off - tmp_off;
iov[3].iov_base = reply + off;
tmp_off = off;
if ((err = slp_get_string(reply, len, &off, scopes)) != SLP_OK) {
goto fail;
}
iov[3].iov_len = off - tmp_off;
iov[2].iov_base = reply + off;
tmp_off = off;
if ((err = slp_get_string(reply, len, &off, attrs)) != SLP_OK) {
goto fail;
}
iov[2].iov_len = off - tmp_off;
iov[4].iov_base = reply + off;
tmp_off = off;
if ((err = slp_get_string(reply, len, &off, spis)) != SLP_OK) {
goto fail;
}
iov[4].iov_len = off - tmp_off;
if ((err = slp_get_byte(reply, len, &off, &auth_cnt)) != SLP_OK) {
goto fail;
}
if (slp_get_security_on() || auth_cnt > 0) {
if ((err = slp_verify(iov, 5,
reply + off,
len - off,
auth_cnt,
&abLen)) != SLP_OK) {
goto fail;
}
}
return (SLP_OK);
fail:
if (*surl) free (*surl);
if (*scopes) free (*scopes);
if (*attrs) free (*attrs);
if (*spis) free (*spis);
return (err);
}