user32: Treat the top-level message window as a desktop window.
[wine/multimedia.git] / dlls / wldap32 / value.c
blobdf813ad2ebc578452d11b6e30b59b2874127ebb6
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 #endif
36 #include "winldap_private.h"
37 #include "wldap32.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
41 /***********************************************************************
42 * ldap_count_values_len (WLDAP32.@)
44 * Count the number of values in an array of berval structures.
46 * PARAMS
47 * vals [I] Pointer to an array of berval structures.
49 * RETURNS
50 * Success: The number of values counted.
51 * Failure: 0
53 * NOTES
54 * Call ldap_count_values_len with the result of a call to
55 * ldap_get_values_len.
57 ULONG CDECL WLDAP32_ldap_count_values_len( struct WLDAP32_berval **vals )
59 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
60 #ifdef HAVE_LDAP
62 TRACE( "(%p)\n", vals );
63 ret = ldap_count_values_len( (struct berval **)vals );
65 #endif
66 return ret;
69 /***********************************************************************
70 * ldap_count_valuesA (WLDAP32.@)
72 * See ldap_count_valuesW.
74 ULONG CDECL ldap_count_valuesA( PCHAR *vals )
76 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
77 #ifdef HAVE_LDAP
78 WCHAR **valsW = NULL;
80 TRACE( "(%p)\n", vals );
82 if (!vals) return 0;
84 valsW = strarrayAtoW( vals );
85 if (!valsW) return WLDAP32_LDAP_NO_MEMORY;
87 ret = ldap_count_valuesW( valsW );
88 strarrayfreeW( valsW );
90 #endif
91 return ret;
94 /***********************************************************************
95 * ldap_count_valuesW (WLDAP32.@)
97 * Count the number of values in a string array.
99 * PARAMS
100 * vals [I] Pointer to an array of strings.
102 * RETURNS
103 * Success: The number of values counted.
104 * Failure: 0
106 * NOTES
107 * Call ldap_count_valuesW with the result of a call to
108 * ldap_get_valuesW.
110 ULONG CDECL ldap_count_valuesW( PWCHAR *vals )
112 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
113 #ifdef HAVE_LDAP
114 WCHAR **p = vals;
116 TRACE( "(%p)\n", vals );
118 if (!vals) return 0;
120 ret = 0;
121 while (*p++) ret++;
123 #endif
124 return ret;
127 /***********************************************************************
128 * ldap_get_valuesA (WLDAP32.@)
130 * See ldap_get_valuesW.
132 PCHAR * CDECL ldap_get_valuesA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PCHAR attr )
134 PCHAR *ret = NULL;
135 #ifdef HAVE_LDAP
136 WCHAR *attrW = NULL, **retW;
138 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_a(attr) );
140 if (!ld || !entry || !attr) return NULL;
142 attrW = strAtoW( attr );
143 if (!attrW) return NULL;
145 retW = ldap_get_valuesW( ld, entry, attrW );
147 ret = strarrayWtoA( retW );
148 ldap_value_freeW( retW );
149 strfreeW( attrW );
151 #endif
152 return ret;
155 #ifdef HAVE_LDAP
156 static char *bv2str( struct berval *bv )
158 char *str = NULL;
159 unsigned int len = bv->bv_len;
161 str = HeapAlloc( GetProcessHeap(), 0, len + 1 );
162 if (str)
164 memcpy( str, bv->bv_val, len );
165 str[len] = '\0';
167 return str;
170 static char **bv2str_array( struct berval **bv )
172 unsigned int len = 0, i = 0;
173 struct berval **p = bv;
174 char **str;
176 while (*p)
178 len++;
179 p++;
181 str = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(char *) );
182 if (!str) return NULL;
184 p = bv;
185 while (*p)
187 str[i] = bv2str( *p );
188 if (!str[i])
190 while (i > 0) HeapFree( GetProcessHeap(), 0, str[--i] );
191 HeapFree( GetProcessHeap(), 0, str );
192 return NULL;
194 i++;
195 p++;
197 str[i] = NULL;
198 return str;
200 #endif
202 /***********************************************************************
203 * ldap_get_valuesW (WLDAP32.@)
205 * Retrieve string values for a given attribute.
207 * PARAMS
208 * ld [I] Pointer to an LDAP context.
209 * entry [I] Entry to retrieve values from.
210 * attr [I] Attribute to retrieve values for.
212 * RETURNS
213 * Success: Pointer to a character array holding the values.
214 * Failure: NULL
216 * NOTES
217 * Call ldap_get_valuesW with the result of a call to
218 * ldap_first_entry or ldap_next_entry. Free the returned
219 * array with a call to ldap_value_freeW.
221 PWCHAR * CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr )
223 PWCHAR *ret = NULL;
224 #ifdef HAVE_LDAP
225 char *attrU = NULL, **retU;
226 struct berval **bv;
228 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
230 if (!ld || !entry || !attr) return NULL;
232 attrU = strWtoU( attr );
233 if (!attrU) return NULL;
235 bv = ldap_get_values_len( ld, entry, attrU );
237 retU = bv2str_array( bv );
238 ret = strarrayUtoW( retU );
240 ldap_value_free_len( bv );
241 strarrayfreeU( retU );
242 strfreeU( attrU );
244 #endif
245 return ret;
248 /***********************************************************************
249 * ldap_get_values_lenA (WLDAP32.@)
251 * See ldap_get_values_lenW.
253 struct WLDAP32_berval ** CDECL ldap_get_values_lenA( WLDAP32_LDAP *ld,
254 WLDAP32_LDAPMessage *message, PCHAR attr )
256 #ifdef HAVE_LDAP
257 WCHAR *attrW = NULL;
258 struct WLDAP32_berval **ret;
260 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
262 if (!ld || !message || !attr) return NULL;
264 attrW = strAtoW( attr );
265 if (!attrW) return NULL;
267 ret = ldap_get_values_lenW( ld, message, attrW );
269 strfreeW( attrW );
270 return ret;
272 #else
273 return NULL;
274 #endif
277 /***********************************************************************
278 * ldap_get_values_lenW (WLDAP32.@)
280 * Retrieve binary values for a given attribute.
282 * PARAMS
283 * ld [I] Pointer to an LDAP context.
284 * message [I] Entry to retrieve values from.
285 * attr [I] Attribute to retrieve values for.
287 * RETURNS
288 * Success: Pointer to a berval array holding the values.
289 * Failure: NULL
291 * NOTES
292 * Call ldap_get_values_lenW with the result of a call to
293 * ldap_first_entry or ldap_next_entry. Free the returned
294 * array with a call to ldap_value_free_len.
296 struct WLDAP32_berval ** CDECL ldap_get_values_lenW( WLDAP32_LDAP *ld,
297 WLDAP32_LDAPMessage *message, PWCHAR attr )
299 #ifdef HAVE_LDAP
300 char *attrU = NULL;
301 struct berval **ret;
303 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
305 if (!ld || !message || !attr) return NULL;
307 attrU = strWtoU( attr );
308 if (!attrU) return NULL;
310 ret = ldap_get_values_len( ld, message, attrU );
312 strfreeU( attrU );
313 return (struct WLDAP32_berval **)ret;
315 #else
316 return NULL;
317 #endif
320 /***********************************************************************
321 * ldap_value_free_len (WLDAP32.@)
323 * Free an array of berval structures.
325 * PARAMS
326 * vals [I] Array of berval structures.
328 * RETURNS
329 * Success: LDAP_SUCCESS
330 * Failure: An LDAP error code.
332 ULONG CDECL WLDAP32_ldap_value_free_len( struct WLDAP32_berval **vals )
334 #ifdef HAVE_LDAP
336 TRACE( "(%p)\n", vals );
337 ldap_value_free_len( (struct berval **)vals );
339 #endif
340 return WLDAP32_LDAP_SUCCESS;
343 /***********************************************************************
344 * ldap_value_freeA (WLDAP32.@)
346 * See ldap_value_freeW.
348 ULONG CDECL ldap_value_freeA( PCHAR *vals )
350 TRACE( "(%p)\n", vals );
352 strarrayfreeA( vals );
353 return WLDAP32_LDAP_SUCCESS;
356 /***********************************************************************
357 * ldap_value_freeW (WLDAP32.@)
359 * Free an array of string values.
361 * PARAMS
362 * vals [I] Array of string values.
364 * RETURNS
365 * Success: LDAP_SUCCESS
366 * Failure: An LDAP error code.
368 ULONG CDECL ldap_value_freeW( PWCHAR *vals )
370 TRACE( "(%p)\n", vals );
372 strarrayfreeW( vals );
373 return WLDAP32_LDAP_SUCCESS;