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
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
32 # define LBER_ERROR (~0U)
35 /***********************************************************************
36 * ber_alloc_t (WLDAP32.@)
38 * Allocate a berelement structure.
41 * options [I] Must be LBER_USE_DER.
44 * Success: Pointer to an allocated berelement structure.
48 * Free the berelement structure with ber_free.
50 BerElement * CDECL WLDAP32_ber_alloc_t( INT options )
53 return ber_alloc_t( options );
60 /***********************************************************************
61 * ber_bvdup (WLDAP32.@)
63 * Copy a berval structure.
66 * berval [I] Pointer to the berval structure to be copied.
69 * Success: Pointer to a copy of the berval structure.
73 * Free the copy with ber_bvfree.
75 BERVAL * CDECL WLDAP32_ber_bvdup( BERVAL *berval )
78 return ber_bvdup( berval );
85 /***********************************************************************
86 * ber_bvecfree (WLDAP32.@)
88 * Free an array of berval structures.
91 * berval [I] Pointer to an array of berval structures.
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 )
103 ber_bvecfree( berval );
108 /***********************************************************************
109 * ber_bvfree (WLDAP32.@)
111 * Free a berval structure.
114 * berval [I] Pointer to a berval structure.
120 * Use this function only to free berval structures allocated by
123 void CDECL WLDAP32_ber_bvfree( BERVAL *berval )
126 ber_bvfree( berval );
131 /***********************************************************************
132 * ber_first_element (WLDAP32.@)
134 * Return the tag of the first element in a set or sequence.
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.
142 * Success: Tag of the first element.
143 * Failure: LBER_DEFAULT (no more data).
146 * len and cookie should be passed to ber_next_element.
148 ULONG CDECL WLDAP32_ber_first_element( BerElement *berelement, ULONG *len, CHAR **opaque )
151 return ber_first_element( berelement, len, opaque );
158 /***********************************************************************
159 * ber_flatten (WLDAP32.@)
161 * Flatten a berelement structure into a berval structure.
164 * berelement [I] Pointer to a berelement structure.
165 * berval [O] Pointer to a berval structure.
169 * Failure: LBER_ERROR
172 * Free the berval structure with ber_bvfree.
174 INT CDECL WLDAP32_ber_flatten( BerElement *berelement, PBERVAL *berval )
177 return ber_flatten( berelement, berval );
184 /***********************************************************************
185 * ber_free (WLDAP32.@)
187 * Free a berelement structure.
190 * berelement [I] Pointer to the berelement structure to be freed.
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 )
203 ber_free( berelement, buf );
208 /***********************************************************************
209 * ber_init (WLDAP32.@)
211 * Initialise a berelement structure from a berval structure.
214 * berval [I] Pointer to a berval structure.
217 * Success: Pointer to a berelement structure.
221 * Call ber_free to free the returned berelement structure.
223 BerElement * CDECL WLDAP32_ber_init( BERVAL *berval )
226 return ber_init( berval );
233 /***********************************************************************
234 * ber_next_element (WLDAP32.@)
236 * Return the tag of the next element in a set or sequence.
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.
244 * Success: Tag of the next element.
245 * Failure: LBER_DEFAULT (no more data).
248 * len and cookie are initialized 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 )
254 return ber_next_element( berelement, len, opaque );
261 /***********************************************************************
262 * ber_peek_tag (WLDAP32.@)
264 * Return the tag of the next element.
267 * berelement [I] Pointer to a berelement structure.
268 * len [O] Receives the length of the next element.
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 )
277 return ber_peek_tag( berelement, len );
284 /***********************************************************************
285 * ber_skip_tag (WLDAP32.@)
287 * Skip the current tag and return the tag of the next element.
290 * berelement [I] Pointer to a berelement structure.
291 * len [O] Receives the length of the skipped element.
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 )
300 return ber_skip_tag( berelement, len );
307 /***********************************************************************
308 * ber_printf (WLDAP32.@)
310 * Encode a berelement structure.
313 * berelement [I/O] Pointer to a berelement structure.
314 * fmt [I] Format string.
315 * ... [I] Values to encode.
318 * Success: Non-negative number.
319 * Failure: LBER_ERROR
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, ... )
333 va_start( list, fmt );
343 int i = va_arg( list, int );
344 ret = ber_printf( berelement, new_fmt, i );
350 char *str = va_arg( list, char * );
351 ret = ber_printf( berelement, new_fmt, str );
356 unsigned int tag = va_arg( list, unsigned int );
357 ret = ber_printf( berelement, new_fmt, tag );
362 char **array = va_arg( list, char ** );
363 ret = ber_printf( berelement, new_fmt, array );
368 struct berval **array = va_arg( list, struct berval ** );
369 ret = ber_printf( berelement, new_fmt, array );
374 char *str = va_arg( list, char * );
375 int len = va_arg( list, int );
376 new_fmt[0] = 'B'; /* 'X' is deprecated */
377 ret = ber_printf( berelement, new_fmt, str, len );
385 ret = ber_printf( berelement, new_fmt );
388 FIXME( "Unknown format '%c'\n", new_fmt[0] );
392 if (ret == -1) break;
402 /***********************************************************************
403 * ber_scanf (WLDAP32.@)
405 * Decode a berelement structure.
408 * berelement [I/O] Pointer to a berelement structure.
409 * fmt [I] Format string.
410 * ... [I] Pointers to values to be decoded.
413 * Success: Non-negative number.
414 * Failure: LBER_ERROR
417 * berelement must have been allocated with ber_init. This function
418 * can be called multiple times to decode data.
420 INT CDECL WLDAP32_ber_scanf( BerElement *berelement, PCHAR fmt, ... )
428 va_start( list, fmt );
436 char **ptr = va_arg( list, char ** );
437 ret = ber_scanf( berelement, new_fmt, ptr );
444 int *i = va_arg( list, int * );
445 ret = ber_scanf( berelement, new_fmt, i );
450 unsigned int *tag = va_arg( list, unsigned int * );
451 ret = ber_scanf( berelement, new_fmt, tag );
456 char ***array = va_arg( list, char *** );
457 ret = ber_scanf( berelement, new_fmt, array );
462 char **str = va_arg( list, char ** );
463 int *len = va_arg( list, int * );
464 ret = ber_scanf( berelement, new_fmt, str, len );
469 struct berval **ptr = va_arg( list, struct berval ** );
470 ret = ber_scanf( berelement, new_fmt, ptr );
475 struct berval ***array = va_arg( list, struct berval *** );
476 ret = ber_scanf( berelement, new_fmt, array );
485 ret = ber_scanf( berelement, new_fmt );
488 FIXME( "Unknown format '%c'\n", new_fmt[0] );
492 if (ret == -1) break;