File: libslpattr_tiny.c

package info (click to toggle)
openslp-dfsg 1.2.1-7.5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,556 kB
  • ctags: 2,620
  • sloc: ansic: 21,723; sh: 9,326; yacc: 597; lex: 335; makefile: 286
file content (335 lines) | stat: -rw-r--r-- 8,651 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/***************************************************************************/
/*                                                                         */
/* Project:     OpenSLP - OpenSource implementation of Service Location    */
/*              Protocol Version 2                                         */
/*                                                                         */
/* File:        slpd_database.c                                            */
/*                                                                         */
/* Abstract:    A "tiny" implementation of slp_attr. Instead of providing  */
/*              the full functionality, we give a minimal interface for    */
/*              use in slpd.                                               */
/***************************************************************************/

#include <libslpattr.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

/*****************************************************************************
 *
 * Implemented functions. 
 * 
 ****************************************************************************/

/* The tiny attribute structure. */
struct xx_TinyAttr
{
    char *attributes; /* A null terminated attribute string. */
    int attr_len; /* The length of the attributes member. */
};

SLPError SLPAttrAlloc(
                     const char *lang, 
                     const FILE *template_h,
                     const SLPBoolean strict, 
                     SLPAttributes *slp_attr_h
                     )
{
    struct xx_TinyAttr **slp_attr;
    slp_attr = (struct xx_TinyAttr**)slp_attr_h;

    /* Don't bother sanity checking. */
    /* FIXME Should we check? */

    (*slp_attr) = (struct xx_TinyAttr*)malloc( sizeof(struct xx_TinyAttr) );
    if(*slp_attr == NULL)
    {
        return SLP_MEMORY_ALLOC_FAILED;
    }

    (*slp_attr)->attributes = NULL;
    (*slp_attr)->attr_len = 0;

    return SLP_OK;
}


void SLPAttrFree(SLPAttributes attr_h)
{
    struct xx_TinyAttr *slp_attr = (struct xx_TinyAttr*)attr_h;

    /***** Free data. *****/
    if(slp_attr->attributes)
    {
        free(slp_attr->attributes);
    }
    slp_attr->attr_len = 0;

    /***** Free struct. *****/
    free(slp_attr);
    slp_attr = NULL;
}

/* TODO/FIXME Does not freshen, instead replaces. */
SLPError SLPAttrFreshen(SLPAttributes attr_h, const char *new_attrs)
{
    struct xx_TinyAttr *slp_attr = (struct xx_TinyAttr*)attr_h;

    /***** Free old data. *****/
    if(slp_attr->attributes)
    {
        free(slp_attr->attributes);
    }
    slp_attr->attr_len = 0;

    /***** Copy new data. *****/
    slp_attr->attributes = strdup(new_attrs);
    if(slp_attr->attributes == NULL)
    {
        return SLP_MEMORY_ALLOC_FAILED;
    }
    slp_attr->attr_len = strlen(new_attrs);

    /***** Done. *****/
    return SLP_OK;
}


SLPError SLPAttrSerialize(SLPAttributes attr_h,
                          const char* tags /* NULL terminated */,
                          char **out_buffer /* Where to write. if *out_buffer == NULL, space is alloc'd */,
                          int bufferlen, /* Size of buffer. */
                          int* count, /* Bytes needed/written. */
                          SLPBoolean find_delta
                         )
{
    struct xx_TinyAttr *slp_attr = (struct xx_TinyAttr*)attr_h;

    /* Write the amount of space we need. */
    if(count != NULL)
    {
        *count = slp_attr->attr_len + 1; /* For the null. */
    }

    /* Check that we have somewhere to write to. */
    if(bufferlen < slp_attr->attr_len + 1)
    { /* +1 for null. */
        return SLP_BUFFER_OVERFLOW;
    }
    assert(out_buffer != NULL && *out_buffer != NULL); /* Verify we have somewhere to write. */


    /* Check for empty string. */
    if(slp_attr->attr_len == 0)
    {
        **out_buffer = 0; /* Empty string. */
        return SLP_OK;
    }

    /* Copy. */
    strcpy(*out_buffer, slp_attr->attributes);

    return SLP_OK;
}



/*****************************************************************************
 *
 * Unimplemented functions.
 * 
 ****************************************************************************/

SLPError SLPAttrAllocStr(
                        const char *lang, 
                        const FILE *template_h,
                        const SLPBoolean strict, 
                        SLPAttributes *slp_attr,
                        const char *str
                        )
{
    return SLP_NOT_IMPLEMENTED;
}


/* Attribute manipulation. */
SLPError SLPAttrSet_bool(
                        SLPAttributes attr_h,
                        const char *attribute_tag,
                        SLPBoolean val
                        )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPAttrSet_str(
                       SLPAttributes attr_h,
                       const char *tag,
                       const char *val,
                       SLPInsertionPolicy pol
                       )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPAttrSet_keyw(
                        SLPAttributes attr_h,
                        const char *attribute_tag
                        )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPAttrSet_int(
                       SLPAttributes attr_h,
                       const char *tag,
                       int val,
                       SLPInsertionPolicy policy
                       )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPAttrSet_opaque(
                          SLPAttributes attr_h,
                          const char *tag,
                          const char *val,
                          const unsigned int len, 
                          SLPInsertionPolicy policy
                          )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPAttrSet_guess(
                         SLPAttributes attr_h,
                         const char *tag,
                         const char *val,
                         SLPInsertionPolicy policy
                         )
{
    return SLP_NOT_IMPLEMENTED;
}



/* Attribute Querying. */
SLPError SLPAttrGet_bool(
                        SLPAttributes attr_h,
                        const char *tag,
                        SLPBoolean *val
                        )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPAttrGet_keyw(
                        SLPAttributes attr_h,
                        const char *tag
                        )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPAttrGet_int(
                       SLPAttributes attr_h,
                       const char *tag,
                       int *val[],
                       int *size
                       )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPAttrGet_str(
                       SLPAttributes attr_h,
                       const char *tag,
                       char ***val,
                       int *size
                       )
{
    return SLP_NOT_IMPLEMENTED;
}



SLPError SLPAttrGet_opaque(
                          SLPAttributes attr_h,
                          const char *tag,
                          SLPOpaque ***val,
                          int *size
                          )
{
    return SLP_NOT_IMPLEMENTED;
}



/* Misc. */
SLPError SLPAttrGetType(SLPAttributes attr_h, const char *tag, SLPType *type)
{
    return SLP_NOT_IMPLEMENTED;
}

/* Functions. */
SLPError SLPRegAttr(
                   SLPHandle slp_h, 
                   const char* srvurl, 
                   unsigned short lifetime, 
                   const char* srvtype, 
                   SLPAttributes attr_h, 
                   SLPBoolean fresh, 
                   SLPRegReport callback, 
                   void* cookie 
                   )
{
    return SLP_NOT_IMPLEMENTED;
}


SLPError SLPFindAttrObj (
                        SLPHandle hslp, 
                        const char* srvurlorsrvtype, 
                        const char* scopelist, 
                        const char* attrids, 
                        SLPAttrObjCallback *callback, 
                        void* cookie
                        )
{
    return SLP_NOT_IMPLEMENTED;
}




/*****************************************************************************
 *
 * Functions for the iterator struct
 * 
 ****************************************************************************/

SLPError SLPAttrIteratorAlloc(SLPAttributes attr, SLPAttrIterator *iter)
{
    return SLP_NOT_IMPLEMENTED;
}

void SLPAttrIteratorFree(SLPAttrIterator iter)
{
    return ;
}


SLPBoolean SLPAttrIterNext(SLPAttrIterator iter_h, char const **tag, SLPType *type)
{
    return SLP_NOT_IMPLEMENTED;
}