shell32: Fix the file version string of the version resource.
[wine/multimedia.git] / dlls / wldap32 / ber.c
blobc037a16e515e71dd6bbef7b00727cc121351981b
1 /*
2 * WLDAP32 - LDAP support for Wine
4 * Copyright 2005 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winldap.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
31 #ifndef LBER_ERROR
32 # define LBER_ERROR (~0U)
33 #endif
35 /***********************************************************************
36 * ber_alloc_t (WLDAP32.@)
38 * Allocate a berelement structure.
40 * PARAMS
41 * options [I] Must be LBER_USE_DER.
43 * RETURNS
44 * Success: Pointer to an allocated berelement structure.
45 * Failure: NULL
47 * NOTES
48 * Free the berelement structure with ber_free.
50 BerElement * CDECL WLDAP32_ber_alloc_t( INT options )
52 #ifdef HAVE_LDAP
53 return ber_alloc_t( options );
54 #else
55 return NULL;
56 #endif
60 /***********************************************************************
61 * ber_bvdup (WLDAP32.@)
63 * Copy a berval structure.
65 * PARAMS
66 * berval [I] Pointer to the berval structure to be copied.
68 * RETURNS
69 * Success: Pointer to a copy of the berval structure.
70 * Failure: NULL
72 * NOTES
73 * Free the copy with ber_bvfree.
75 BERVAL * CDECL WLDAP32_ber_bvdup( BERVAL *berval )
77 #ifdef HAVE_LDAP
78 return ber_bvdup( berval );
79 #else
80 return NULL;
81 #endif
85 /***********************************************************************
86 * ber_bvecfree (WLDAP32.@)
88 * Free an array of berval structures.
90 * PARAMS
91 * berval [I] Pointer to an array of berval structures.
93 * RETURNS
94 * Nothing.
96 * NOTES
97 * Use this function only to free an array of berval structures
98 * returned by a call to ber_scanf with a 'V' in the format string.
100 void CDECL WLDAP32_ber_bvecfree( PBERVAL *berval )
102 #ifdef HAVE_LDAP
103 ber_bvecfree( berval );
104 #endif
108 /***********************************************************************
109 * ber_bvfree (WLDAP32.@)
111 * Free a berval structure.
113 * PARAMS
114 * berval [I] Pointer to a berval structure.
116 * RETURNS
117 * Nothing.
119 * NOTES
120 * Use this function only to free berval structures allocated by
121 * an LDAP API.
123 void CDECL WLDAP32_ber_bvfree( BERVAL *berval )
125 #ifdef HAVE_LDAP
126 ber_bvfree( berval );
127 #endif
131 /***********************************************************************
132 * ber_first_element (WLDAP32.@)
134 * Return the tag of the first element in a set or sequence.
136 * PARAMS
137 * berelement [I] Pointer to a berelement structure.
138 * len [O] Receives the length of the first element.
139 * opaque [O] Receives a pointer to a cookie.
141 * RETURNS
142 * Success: Tag of the first element.
143 * Failure: LBER_DEFAULT (no more data).
145 * NOTES
146 * len and cookie should be passed to ber_next_element.
148 ULONG CDECL WLDAP32_ber_first_element( BerElement *berelement, ULONG *len, CHAR **opaque )
150 #ifdef HAVE_LDAP
151 return ber_first_element( berelement, len, opaque );
152 #else
153 return LBER_ERROR;
154 #endif
158 /***********************************************************************
159 * ber_flatten (WLDAP32.@)
161 * Flatten a berelement structure into a berval structure.
163 * PARAMS
164 * berlement [I] Pointer to a berelement structure.
165 * berval [O] Pointer to a berval structure.
167 * RETURNS
168 * Success: 0
169 * Failure: LBER_ERROR
171 * NOTES
172 * Free the berval structure with ber_bvfree.
174 INT CDECL WLDAP32_ber_flatten( BerElement *berelement, PBERVAL *berval )
176 #ifdef HAVE_LDAP
177 return ber_flatten( berelement, berval );
178 #else
179 return LBER_ERROR;
180 #endif
184 /***********************************************************************
185 * ber_free (WLDAP32.@)
187 * Free a berelement structure.
189 * PARAMS
190 * berlement [I] Pointer to the berelement structure to be freed.
191 * buf [I] Flag.
193 * RETURNS
194 * Nothing.
196 * NOTES
197 * Set buf to 0 if the berelement was allocated with ldap_first_attribute
198 * or ldap_next_attribute, otherwise set it to 1.
200 void CDECL WLDAP32_ber_free( BerElement *berelement, INT buf )
202 #ifdef HAVE_LDAP
203 ber_free( berelement, buf );
204 #endif
208 /***********************************************************************
209 * ber_init (WLDAP32.@)
211 * Initialise a berelement structure from a berval structure.
213 * PARAMS
214 * berval [I] Pointer to a berval structure.
216 * RETURNS
217 * Success: Pointer to a berelement structure.
218 * Failure: NULL
220 * NOTES
221 * Call ber_free to free the returned berelement structure.
223 BerElement * CDECL WLDAP32_ber_init( BERVAL *berval )
225 #ifdef HAVE_LDAP
226 return ber_init( berval );
227 #else
228 return NULL;
229 #endif
233 /***********************************************************************
234 * ber_next_element (WLDAP32.@)
236 * Return the tag of the next element in a set or sequence.
238 * PARAMS
239 * berelement [I] Pointer to a berelement structure.
240 * len [I/O] Receives the length of the next element.
241 * opaque [I/O] Pointer to a cookie.
243 * RETURNS
244 * Success: Tag of the next element.
245 * Failure: LBER_DEFAULT (no more data).
247 * NOTES
248 * len and cookie are intitialised by ber_first_element and should
249 * be passed on in subsequent calls to ber_next_element.
251 ULONG CDECL WLDAP32_ber_next_element( BerElement *berelement, ULONG *len, CHAR *opaque )
253 #ifdef HAVE_LDAP
254 return ber_next_element( berelement, len, opaque );
255 #else
256 return LBER_ERROR;
257 #endif
261 /***********************************************************************
262 * ber_peek_tag (WLDAP32.@)
264 * Return the tag of the next element.
266 * PARAMS
267 * berelement [I] Pointer to a berelement structure.
268 * len [O] Receives the length of the next element.
270 * RETURNS
271 * Success: Tag of the next element.
272 * Failure: LBER_DEFAULT (no more data).
274 ULONG CDECL WLDAP32_ber_peek_tag( BerElement *berelement, ULONG *len )
276 #ifdef HAVE_LDAP
277 return ber_peek_tag( berelement, len );
278 #else
279 return LBER_ERROR;
280 #endif
284 /***********************************************************************
285 * ber_skip_tag (WLDAP32.@)
287 * Skip the current tag and return the tag of the next element.
289 * PARAMS
290 * berelement [I] Pointer to a berelement structure.
291 * len [O] Receives the length of the skipped element.
293 * RETURNS
294 * Success: Tag of the next element.
295 * Failure: LBER_DEFAULT (no more data).
297 ULONG CDECL WLDAP32_ber_skip_tag( BerElement *berelement, ULONG *len )
299 #ifdef HAVE_LDAP
300 return ber_skip_tag( berelement, len );
301 #else
302 return LBER_ERROR;
303 #endif
307 /***********************************************************************
308 * ber_printf (WLDAP32.@)
310 * Encode a berelement structure.
312 * PARAMS
313 * berelement [I/O] Pointer to a berelement structure.
314 * fmt [I] Format string.
315 * ... [I] Values to encode.
317 * RETURNS
318 * Success: Non-negative number.
319 * Failure: LBER_ERROR
321 * NOTES
322 * berelement must have been allocated with ber_alloc_t. This function
323 * can be called multiple times to append data.
325 INT CDECL WLDAP32_ber_printf( BerElement *berelement, PCHAR fmt, ... )
327 #ifdef HAVE_LDAP
328 va_list list;
329 int ret = 0;
330 char new_fmt[2];
332 new_fmt[1] = 0;
333 va_start( list, fmt );
334 while (*fmt)
336 new_fmt[0] = *fmt++;
337 switch(new_fmt[0])
339 case 'b':
340 case 'e':
341 case 'i':
343 int i = va_arg( list, int );
344 ret = ber_printf( berelement, new_fmt, i );
345 break;
347 case 'o':
348 case 's':
350 char *str = va_arg( list, char * );
351 ret = ber_printf( berelement, new_fmt, str );
352 break;
354 case 't':
356 unsigned int tag = va_arg( list, unsigned int );
357 ret = ber_printf( berelement, new_fmt, tag );
358 break;
360 case 'v':
362 char **array = va_arg( list, char ** );
363 ret = ber_printf( berelement, new_fmt, array );
364 break;
366 case 'V':
368 struct berval **array = va_arg( list, struct berval ** );
369 ret = ber_printf( berelement, new_fmt, array );
370 break;
372 case 'X':
374 char *str = va_arg( list, char * );
375 int len = va_arg( list, int );
376 ret = ber_printf( berelement, "B" /* 'X' is deprecated */, str, len );
377 break;
379 case 'n':
380 case '{':
381 case '}':
382 case '[':
383 case ']':
384 ret = ber_printf( berelement, new_fmt );
385 break;
386 default:
387 FIXME( "Unknown format '%c'\n", new_fmt[0] );
388 ret = -1;
389 break;
391 if (ret == -1) break;
393 va_end( list );
394 return ret;
395 #else
396 return LBER_ERROR;
397 #endif
401 /***********************************************************************
402 * ber_scanf (WLDAP32.@)
404 * Decode a berelement structure.
406 * PARAMS
407 * berelement [I/O] Pointer to a berelement structure.
408 * fmt [I] Format string.
409 * ... [I] Pointers to values to be decoded.
411 * RETURNS
412 * Success: Non-negative number.
413 * Failure: LBER_ERROR
415 * NOTES
416 * berelement must have been allocated with ber_init. This function
417 * can be called multiple times to decode data.
419 INT CDECL WLDAP32_ber_scanf( BerElement *berelement, PCHAR fmt, ... )
421 #ifdef HAVE_LDAP
422 va_list list;
423 int ret = 0;
424 char new_fmt[2];
426 new_fmt[1] = 0;
427 va_start( list, fmt );
428 while (*fmt)
430 new_fmt[0] = *fmt++;
431 switch(new_fmt[0])
433 case 'a':
435 char **ptr = va_arg( list, char ** );
436 ret = ber_scanf( berelement, new_fmt, ptr );
437 break;
439 case 'b':
440 case 'e':
441 case 'i':
443 int *i = va_arg( list, int * );
444 ret = ber_scanf( berelement, new_fmt, i );
445 break;
447 case 't':
449 unsigned int *tag = va_arg( list, unsigned int * );
450 ret = ber_scanf( berelement, new_fmt, tag );
451 break;
453 case 'v':
455 char ***array = va_arg( list, char *** );
456 ret = ber_scanf( berelement, new_fmt, array );
457 break;
459 case 'B':
461 char **str = va_arg( list, char ** );
462 int *len = va_arg( list, int * );
463 ret = ber_scanf( berelement, new_fmt, str, len );
464 break;
466 case 'O':
468 struct berval **ptr = va_arg( list, struct berval ** );
469 ret = ber_scanf( berelement, new_fmt, ptr );
470 break;
472 case 'V':
474 struct berval ***array = va_arg( list, struct berval *** );
475 ret = ber_scanf( berelement, new_fmt, array );
476 break;
478 case 'n':
479 case 'x':
480 case '{':
481 case '}':
482 case '[':
483 case ']':
484 ret = ber_scanf( berelement, new_fmt );
485 break;
486 default:
487 FIXME( "Unknown format '%c'\n", new_fmt[0] );
488 ret = -1;
489 break;
491 if (ret == -1) break;
493 va_end( list );
494 return ret;
495 #else
496 return LBER_ERROR;
497 #endif