urlmon: Remove 'recursive registry key delete' function.
[wine/multimedia.git] / dlls / wldap32 / value.c
blob61bcfc3c877db2c34a5ab4bcc6f800b1e06f1bf7
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 "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
37 #endif
39 #include "winldap_private.h"
40 #include "wldap32.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 /***********************************************************************
45 * ldap_count_values_len (WLDAP32.@)
47 * Count the number of values in an array of berval structures.
49 * PARAMS
50 * vals [I] Pointer to an array of berval structures.
52 * RETURNS
53 * Success: The number of values counted.
54 * Failure: 0
56 * NOTES
57 * Call ldap_count_values_len with the result of a call to
58 * ldap_get_values_len.
60 ULONG CDECL WLDAP32_ldap_count_values_len( struct WLDAP32_berval **vals )
62 ULONG ret = LDAP_NOT_SUPPORTED;
63 #ifdef HAVE_LDAP
65 TRACE( "(%p)\n", vals );
66 ret = ldap_count_values_len( (struct berval **)vals );
68 #endif
69 return ret;
72 /***********************************************************************
73 * ldap_count_valuesA (WLDAP32.@)
75 * See ldap_count_valuesW.
77 ULONG CDECL ldap_count_valuesA( PCHAR *vals )
79 ULONG ret = LDAP_NOT_SUPPORTED;
80 #ifdef HAVE_LDAP
81 WCHAR **valsW = NULL;
83 TRACE( "(%p)\n", vals );
85 if (!vals) return 0;
87 valsW = strarrayAtoW( vals );
88 if (!valsW) return WLDAP32_LDAP_NO_MEMORY;
90 ret = ldap_count_valuesW( valsW );
91 strarrayfreeW( valsW );
93 #endif
94 return ret;
97 /***********************************************************************
98 * ldap_count_valuesW (WLDAP32.@)
100 * Count the number of values in a string array.
102 * PARAMS
103 * vals [I] Pointer to an array of strings.
105 * RETURNS
106 * Success: The number of values counted.
107 * Failure: 0
109 * NOTES
110 * Call ldap_count_valuesW with the result of a call to
111 * ldap_get_valuesW.
113 ULONG CDECL ldap_count_valuesW( PWCHAR *vals )
115 ULONG ret = LDAP_NOT_SUPPORTED;
116 #ifdef HAVE_LDAP
117 WCHAR **p = vals;
119 TRACE( "(%p)\n", vals );
121 if (!vals) return 0;
123 ret = 0;
124 while (*p++) ret++;
126 #endif
127 return ret;
130 /***********************************************************************
131 * ldap_get_valuesA (WLDAP32.@)
133 * See ldap_get_valuesW.
135 PCHAR * CDECL ldap_get_valuesA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PCHAR attr )
137 PCHAR *ret = NULL;
138 #ifdef HAVE_LDAP
139 WCHAR *attrW = NULL, **retW;
141 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_a(attr) );
143 if (!ld || !entry || !attr) return NULL;
145 attrW = strAtoW( attr );
146 if (!attrW) return NULL;
148 retW = ldap_get_valuesW( ld, entry, attrW );
150 ret = strarrayWtoA( retW );
151 ldap_value_freeW( retW );
152 strfreeW( attrW );
154 #endif
155 return ret;
158 #ifdef HAVE_LDAP
159 static char *bv2str( struct berval *bv )
161 char *str = NULL;
162 unsigned int len = bv->bv_len;
164 str = HeapAlloc( GetProcessHeap(), 0, len + 1 );
165 if (str)
167 memcpy( str, bv->bv_val, len );
168 str[len] = '\0';
170 return str;
173 static char **bv2str_array( struct berval **bv )
175 unsigned int len = 0, i = 0;
176 struct berval **p = bv;
177 char **str;
179 while (*p)
181 len++;
182 p++;
184 str = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(char *) );
185 if (!str) return NULL;
187 p = bv;
188 while (*p)
190 str[i] = bv2str( *p );
191 if (!str[i])
193 while (i > 0) HeapFree( GetProcessHeap(), 0, str[--i] );
194 HeapFree( GetProcessHeap(), 0, str );
195 return NULL;
197 i++;
198 p++;
200 str[i] = NULL;
201 return str;
203 #endif
205 /***********************************************************************
206 * ldap_get_valuesW (WLDAP32.@)
208 * Retrieve string values for a given attribute.
210 * PARAMS
211 * ld [I] Pointer to an LDAP context.
212 * entry [I] Entry to retrieve values from.
213 * attr [I] Attribute to retrieve values for.
215 * RETURNS
216 * Success: Pointer to a character array holding the values.
217 * Failure: NULL
219 * NOTES
220 * Call ldap_get_valuesW with the result of a call to
221 * ldap_first_entry or ldap_next_entry. Free the returned
222 * array with a call to ldap_value_freeW.
224 PWCHAR * CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr )
226 PWCHAR *ret = NULL;
227 #ifdef HAVE_LDAP
228 char *attrU = NULL, **retU;
229 struct berval **bv;
231 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
233 if (!ld || !entry || !attr) return NULL;
235 attrU = strWtoU( attr );
236 if (!attrU) return NULL;
238 bv = ldap_get_values_len( ld, entry, attrU );
240 retU = bv2str_array( bv );
241 ret = strarrayUtoW( retU );
243 ldap_value_free_len( bv );
244 strarrayfreeU( retU );
245 strfreeU( attrU );
247 #endif
248 return ret;
251 /***********************************************************************
252 * ldap_get_values_lenA (WLDAP32.@)
254 * See ldap_get_values_lenW.
256 struct WLDAP32_berval ** CDECL ldap_get_values_lenA( WLDAP32_LDAP *ld,
257 WLDAP32_LDAPMessage *message, PCHAR attr )
259 #ifdef HAVE_LDAP
260 WCHAR *attrW = NULL;
261 struct WLDAP32_berval **ret;
263 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
265 if (!ld || !message || !attr) return NULL;
267 attrW = strAtoW( attr );
268 if (!attrW) return NULL;
270 ret = ldap_get_values_lenW( ld, message, attrW );
272 strfreeW( attrW );
273 return ret;
275 #else
276 return NULL;
277 #endif
280 /***********************************************************************
281 * ldap_get_values_lenW (WLDAP32.@)
283 * Retrieve binary values for a given attribute.
285 * PARAMS
286 * ld [I] Pointer to an LDAP context.
287 * message [I] Entry to retrieve values from.
288 * attr [I] Attribute to retrieve values for.
290 * RETURNS
291 * Success: Pointer to a berval array holding the values.
292 * Failure: NULL
294 * NOTES
295 * Call ldap_get_values_lenW with the result of a call to
296 * ldap_first_entry or ldap_next_entry. Free the returned
297 * array with a call to ldap_value_free_len.
299 struct WLDAP32_berval ** CDECL ldap_get_values_lenW( WLDAP32_LDAP *ld,
300 WLDAP32_LDAPMessage *message, PWCHAR attr )
302 #ifdef HAVE_LDAP
303 char *attrU = NULL;
304 struct berval **ret;
306 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
308 if (!ld || !message || !attr) return NULL;
310 attrU = strWtoU( attr );
311 if (!attrU) return NULL;
313 ret = ldap_get_values_len( ld, message, attrU );
315 strfreeU( attrU );
316 return (struct WLDAP32_berval **)ret;
318 #else
319 return NULL;
320 #endif
323 /***********************************************************************
324 * ldap_value_free_len (WLDAP32.@)
326 * Free an array of berval structures.
328 * PARAMS
329 * vals [I] Array of berval structures.
331 * RETURNS
332 * Success: LDAP_SUCCESS
333 * Failure: An LDAP error code.
335 ULONG CDECL WLDAP32_ldap_value_free_len( struct WLDAP32_berval **vals )
337 #ifdef HAVE_LDAP
339 TRACE( "(%p)\n", vals );
340 ldap_value_free_len( (struct berval **)vals );
342 #endif
343 return LDAP_SUCCESS;
346 /***********************************************************************
347 * ldap_value_freeA (WLDAP32.@)
349 * See ldap_value_freeW.
351 ULONG CDECL ldap_value_freeA( PCHAR *vals )
353 TRACE( "(%p)\n", vals );
355 strarrayfreeA( vals );
356 return LDAP_SUCCESS;
359 /***********************************************************************
360 * ldap_value_freeW (WLDAP32.@)
362 * Free an array of string values.
364 * PARAMS
365 * vals [I] Array of string values.
367 * RETURNS
368 * Success: LDAP_SUCCESS
369 * Failure: An LDAP error code.
371 ULONG CDECL ldap_value_freeW( PWCHAR *vals )
373 TRACE( "(%p)\n", vals );
375 strarrayfreeW( vals );
376 return LDAP_SUCCESS;