8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libslp / clib / DAAdvert.c
blob80f90d06d1c8e7b4bc987822fd6ba4e57b63a4f1
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * DAAdvert functionality. For all normal UA calls, libslp queries
31 * slpd for available DAs. This file contains functionality to handle
32 * DAAdverts explicitly requested by a call to SLPFindSrvs()
33 * or SLPFindAttrs() with service-type = "service:directory-agent".
36 #include <stdio.h>
37 #include <slp-internal.h>
39 SLPError slp_unpackDAAdvert(char *reply, char **surl, char **scopes,
40 char **attrs, char **spis, SLPError *errCode) {
41 unsigned short protoErrCode, dummy;
42 size_t len, off;
43 SLPError err = SLP_OK;
44 /* authentication components */
45 struct iovec iov[5];
46 size_t tmp_off;
47 int auth_cnt;
48 size_t abLen = 0;
50 *surl = *scopes = *attrs = *spis = NULL;
52 len = slp_get_length(reply);
53 off = SLP_HDRLEN + slp_get_langlen(reply);
54 /* err code */
55 if ((err = slp_get_sht(reply, len, &off, &protoErrCode)) != SLP_OK)
56 goto fail;
57 /* internal errors should have been filtered out by the net code */
58 *errCode = slp_map_err(protoErrCode);
59 if (*errCode != SLP_OK) {
60 return (SLP_OK);
63 /* skip timestamp (4 bytes) */
64 iov[0].iov_base = reply + off;
65 tmp_off = off;
66 if ((err = slp_get_sht(reply, len, &off, &dummy)) != SLP_OK) {
67 goto fail;
69 if ((err = slp_get_sht(reply, len, &off, &dummy)) != SLP_OK) {
70 goto fail;
72 iov[0].iov_len = off - tmp_off;
74 /* service URL */
75 iov[1].iov_base = reply + off;
76 tmp_off = off;
77 if ((err = slp_get_string(reply, len, &off, surl)) != SLP_OK) {
78 goto fail;
80 iov[1].iov_len = off - tmp_off;
82 /* scopes */
83 iov[3].iov_base = reply + off;
84 tmp_off = off;
85 if ((err = slp_get_string(reply, len, &off, scopes)) != SLP_OK) {
86 goto fail;
88 iov[3].iov_len = off - tmp_off;
90 /* attributes */
91 iov[2].iov_base = reply + off;
92 tmp_off = off;
93 if ((err = slp_get_string(reply, len, &off, attrs)) != SLP_OK) {
94 goto fail;
96 iov[2].iov_len = off - tmp_off;
98 /* SPIs */
99 iov[4].iov_base = reply + off;
100 tmp_off = off;
101 if ((err = slp_get_string(reply, len, &off, spis)) != SLP_OK) {
102 goto fail;
104 iov[4].iov_len = off - tmp_off;
106 /* auth blocks */
107 if ((err = slp_get_byte(reply, len, &off, &auth_cnt)) != SLP_OK) {
108 goto fail;
110 if (slp_get_security_on() || auth_cnt > 0) {
111 if ((err = slp_verify(iov, 5,
112 reply + off,
113 len - off,
114 auth_cnt,
115 &abLen)) != SLP_OK) {
116 goto fail;
120 return (SLP_OK);
122 fail:
123 if (*surl) free (*surl);
124 if (*scopes) free (*scopes);
125 if (*attrs) free (*attrs);
126 if (*spis) free (*spis);
128 return (err);