1 /*-------------------------------------------------------------------------
2 * Copyright (C) 2000 Caldera Systems, Inc
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of Caldera Systems nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CALDERA
24 * SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *-------------------------------------------------------------------------*/
32
33 /** Tiny attribute parser.
34 *
35 * A "tiny" implementation of slp_attr. Instead of providing the full
36 * functionality, we give a minimal interface for use in slpd.
37 *
38 * @file libslpattr_tiny.c
39 * @author Matthew Peterson, John Calcote (jcalcote@novell.com)
40 * @attention Please submit patches to http://www.openslp.org
41 * @ingroup CommonCodeAttrs
42 */
43
44 #include "libslpattr.h"
45 #include "../common/slp_debug.h"
46
47 /*****************************************************************************
48 *
49 * Implemented functions.
50 *
51 ****************************************************************************/
52
53 /* The tiny attribute structure. */
54 struct xx_TinyAttr
55 {
56 char * attributes; /* A null terminated attribute string. */
57 int attr_len; /* The length of the attributes member. */
58 };
59
SLPAttrAlloc(const char * lang,const FILE * template_h,const SLPBoolean strict,SLPAttributes * slp_attr_h)60 SLPError SLPAttrAlloc(const char * lang, const FILE * template_h,
61 const SLPBoolean strict, SLPAttributes * slp_attr_h)
62 {
63 struct xx_TinyAttr ** slp_attr;
64 slp_attr = (struct xx_TinyAttr * *) slp_attr_h;
65
66 /* Don't bother sanity checking. */
67 /* FIXME Should we check? */
68
69 (*slp_attr) = (struct xx_TinyAttr *) malloc(sizeof(struct xx_TinyAttr));
70 if (*slp_attr == NULL)
71 return SLP_MEMORY_ALLOC_FAILED;
72
73 (*slp_attr)->attributes = NULL;
74 (*slp_attr)->attr_len = 0;
75
76 return SLP_OK;
77 }
78
79
SLPAttrFree(SLPAttributes attr_h)80 void SLPAttrFree(SLPAttributes attr_h)
81 {
82 struct xx_TinyAttr * slp_attr = (struct xx_TinyAttr *) attr_h;
83
84 /***** Free data. *****/
85 if (slp_attr->attributes)
86 free(slp_attr->attributes);
87 slp_attr->attr_len = 0;
88
89 /***** Free struct. *****/
90 free(slp_attr);
91 slp_attr = NULL;
92 }
93
94 /* TODO/FIXME Does not freshen, instead replaces. */
SLPAttrFreshen(SLPAttributes attr_h,const char * new_attrs)95 SLPError SLPAttrFreshen(SLPAttributes attr_h, const char * new_attrs)
96 {
97 struct xx_TinyAttr * slp_attr = (struct xx_TinyAttr *) attr_h;
98
99 /***** Free old data. *****/
100 if (slp_attr->attributes)
101 free(slp_attr->attributes);
102 slp_attr->attr_len = 0;
103
104 /***** Copy new data. *****/
105 slp_attr->attributes = strdup(new_attrs);
106 if (slp_attr->attributes == NULL)
107 return SLP_MEMORY_ALLOC_FAILED;
108 slp_attr->attr_len = strlen(new_attrs);
109
110 /***** Done. *****/
111 return SLP_OK;
112 }
113
114
SLPAttrSerialize(SLPAttributes attr_h,const char * tags,char ** out_buffer,size_t bufferlen,size_t * count,SLPBoolean find_delta)115 SLPError SLPAttrSerialize(SLPAttributes attr_h,
116 const char * tags /* NULL terminated */,
117 char ** out_buffer /* Where to write. if *out_buffer == NULL, space is alloc'd */,
118 size_t bufferlen, /* Size of buffer. */
119 size_t * count, /* Bytes needed/written. */
120 SLPBoolean find_delta)
121 {
122 struct xx_TinyAttr * slp_attr = (struct xx_TinyAttr *) attr_h;
123
124 /* Write the amount of space we need. */
125 if (count != NULL)
126 {
127 *count = slp_attr->attr_len + 1; /* For the null. */
128 }
129
130 /* Check that we have somewhere to write to. */
131 if (bufferlen < slp_attr->attr_len + 1)
132 {
133 /* +1 for null. */
134 return SLP_BUFFER_OVERFLOW;
135 }
136 SLP_ASSERT(out_buffer != NULL && *out_buffer != NULL); /* Verify we have somewhere to write. */
137
138
139 /* Check for empty string. */
140 if (slp_attr->attr_len == 0)
141 {
142 **out_buffer = 0; /* Empty string. */
143 return SLP_OK;
144 }
145
146 /* Copy. */
147 strcpy(*out_buffer, slp_attr->attributes);
148
149 return SLP_OK;
150 }
151
152
153
154 /*****************************************************************************
155 *
156 * Unimplemented functions.
157 *
158 ****************************************************************************/
159
SLPAttrAllocStr(const char * lang,const FILE * template_h,const SLPBoolean strict,SLPAttributes * slp_attr,const char * str)160 SLPError SLPAttrAllocStr(const char * lang, const FILE * template_h,
161 const SLPBoolean strict, SLPAttributes * slp_attr, const char * str)
162 {
163 return SLP_NOT_IMPLEMENTED;
164 }
165
166
167 /* Attribute manipulation. */
SLPAttrSet_bool(SLPAttributes attr_h,const char * attribute_tag,SLPBoolean val)168 SLPError SLPAttrSet_bool(SLPAttributes attr_h, const char * attribute_tag,
169 SLPBoolean val)
170 {
171 return SLP_NOT_IMPLEMENTED;
172 }
173
174
SLPAttrSet_str(SLPAttributes attr_h,const char * tag,const char * val,SLPInsertionPolicy pol)175 SLPError SLPAttrSet_str(SLPAttributes attr_h, const char * tag,
176 const char * val, SLPInsertionPolicy pol)
177 {
178 return SLP_NOT_IMPLEMENTED;
179 }
180
181
SLPAttrSet_keyw(SLPAttributes attr_h,const char * attribute_tag)182 SLPError SLPAttrSet_keyw(SLPAttributes attr_h, const char * attribute_tag)
183 {
184 return SLP_NOT_IMPLEMENTED;
185 }
186
187
SLPAttrSet_int(SLPAttributes attr_h,const char * tag,int val,SLPInsertionPolicy policy)188 SLPError SLPAttrSet_int(SLPAttributes attr_h, const char * tag, int val,
189 SLPInsertionPolicy policy)
190 {
191 return SLP_NOT_IMPLEMENTED;
192 }
193
194
SLPAttrSet_opaque(SLPAttributes attr_h,const char * tag,const char * val,const unsigned int len,SLPInsertionPolicy policy)195 SLPError SLPAttrSet_opaque(SLPAttributes attr_h, const char * tag,
196 const char * val, const unsigned int len, SLPInsertionPolicy policy)
197 {
198 return SLP_NOT_IMPLEMENTED;
199 }
200
201
SLPAttrSet_guess(SLPAttributes attr_h,const char * tag,const char * val,SLPInsertionPolicy policy)202 SLPError SLPAttrSet_guess(SLPAttributes attr_h, const char * tag,
203 const char * val, SLPInsertionPolicy policy)
204 {
205 return SLP_NOT_IMPLEMENTED;
206 }
207
208
209
210 /* Attribute Querying. */
SLPAttrGet_bool(SLPAttributes attr_h,const char * tag,SLPBoolean * val)211 SLPError SLPAttrGet_bool(SLPAttributes attr_h, const char * tag,
212 SLPBoolean * val)
213 {
214 return SLP_NOT_IMPLEMENTED;
215 }
216
217
SLPAttrGet_keyw(SLPAttributes attr_h,const char * tag)218 SLPError SLPAttrGet_keyw(SLPAttributes attr_h, const char * tag)
219 {
220 return SLP_NOT_IMPLEMENTED;
221 }
222
223
SLPAttrGet_int(SLPAttributes attr_h,const char * tag,int * val[],size_t * size)224 SLPError SLPAttrGet_int(SLPAttributes attr_h, const char * tag, int * val[],
225 size_t * size)
226 {
227 return SLP_NOT_IMPLEMENTED;
228 }
229
230
SLPAttrGet_str(SLPAttributes attr_h,const char * tag,char *** val,size_t * size)231 SLPError SLPAttrGet_str(SLPAttributes attr_h, const char * tag, char *** val,
232 size_t * size)
233 {
234 return SLP_NOT_IMPLEMENTED;
235 }
236
237
238
SLPAttrGet_opaque(SLPAttributes attr_h,const char * tag,SLPOpaque *** val,size_t * size)239 SLPError SLPAttrGet_opaque(SLPAttributes attr_h, const char * tag,
240 SLPOpaque *** val, size_t * size)
241 {
242 return SLP_NOT_IMPLEMENTED;
243 }
244
245
246
247 /* Misc. */
SLPAttrGetType(SLPAttributes attr_h,const char * tag,SLPType * type)248 SLPError SLPAttrGetType(SLPAttributes attr_h, const char * tag, SLPType * type)
249 {
250 return SLP_NOT_IMPLEMENTED;
251 }
252
253 /* Functions. */
SLPRegAttr(SLPHandle slp_h,const char * srvurl,unsigned short lifetime,const char * srvtype,SLPAttributes attr_h,SLPBoolean fresh,SLPRegReport callback,void * cookie)254 SLPError SLPRegAttr(SLPHandle slp_h, const char * srvurl,
255 unsigned short lifetime, const char * srvtype, SLPAttributes attr_h,
256 SLPBoolean fresh, SLPRegReport callback, void * cookie)
257 {
258 return SLP_NOT_IMPLEMENTED;
259 }
260
261
SLPFindAttrObj(SLPHandle hslp,const char * srvurlorsrvtype,const char * scopelist,const char * attrids,SLPAttrObjCallback * callback,void * cookie)262 SLPError SLPFindAttrObj(SLPHandle hslp, const char * srvurlorsrvtype,
263 const char * scopelist, const char * attrids,
264 SLPAttrObjCallback * callback, void * cookie)
265 {
266 return SLP_NOT_IMPLEMENTED;
267 }
268
269
270
271
272 /*****************************************************************************
273 *
274 * Functions for the iterator struct
275 *
276 ****************************************************************************/
277
SLPAttrIteratorAlloc(SLPAttributes attr,SLPAttrIterator * iter)278 SLPError SLPAttrIteratorAlloc(SLPAttributes attr, SLPAttrIterator * iter)
279 {
280 return SLP_NOT_IMPLEMENTED;
281 }
282
SLPAttrIteratorFree(SLPAttrIterator iter)283 void SLPAttrIteratorFree(SLPAttrIterator iter)
284 {
285 return ;
286 }
287
288
SLPAttrIterNext(SLPAttrIterator iter_h,char const ** tag,SLPType * type)289 SLPBoolean SLPAttrIterNext(SLPAttrIterator iter_h, char const * *tag,
290 SLPType * type)
291 {
292 return SLP_NOT_IMPLEMENTED;
293 }
294
SLPAttrIterValueNext(SLPAttrIterator iter_h,SLPValue * value)295 SLPBoolean SLPAttrIterValueNext(SLPAttrIterator iter_h, SLPValue *value)
296 {
297 return SLP_NOT_IMPLEMENTED;
298 }
299
300 /*=========================================================================*/
301