dinput: When handling axes, ignore the ABS_HAT.* as they are handled as POV.
[wine/wine64.git] / dlls / wldap32 / value.c
blob4a9aa374da94647af8e5adcb1a138545efda1d32
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 for (--i; i >= 0; i--)
194 HeapFree( GetProcessHeap(), 0, str[i] );
196 HeapFree( GetProcessHeap(), 0, str );
197 return NULL;
199 i++;
200 p++;
202 str[i] = NULL;
203 return str;
205 #endif
207 /***********************************************************************
208 * ldap_get_valuesW (WLDAP32.@)
210 * Retrieve string values for a given attribute.
212 * PARAMS
213 * ld [I] Pointer to an LDAP context.
214 * entry [I] Entry to retrieve values from.
215 * attr [I] Attribute to retrieve values for.
217 * RETURNS
218 * Success: Pointer to a character array holding the values.
219 * Failure: NULL
221 * NOTES
222 * Call ldap_get_valuesW with the result of a call to
223 * ldap_first_entry or ldap_next_entry. Free the returned
224 * array with a call to ldap_value_freeW.
226 PWCHAR * CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr )
228 PWCHAR *ret = NULL;
229 #ifdef HAVE_LDAP
230 char *attrU = NULL, **retU;
231 struct berval **bv;
233 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
235 if (!ld || !entry || !attr) return NULL;
237 attrU = strWtoU( attr );
238 if (!attrU) return NULL;
240 bv = ldap_get_values_len( ld, entry, attrU );
242 retU = bv2str_array( bv );
243 ret = strarrayUtoW( retU );
245 ldap_value_free_len( bv );
246 strarrayfreeU( retU );
247 strfreeU( attrU );
249 #endif
250 return ret;
253 /***********************************************************************
254 * ldap_get_values_lenA (WLDAP32.@)
256 * See ldap_get_values_lenW.
258 struct WLDAP32_berval ** CDECL ldap_get_values_lenA( WLDAP32_LDAP *ld,
259 WLDAP32_LDAPMessage *message, PCHAR attr )
261 #ifdef HAVE_LDAP
262 WCHAR *attrW = NULL;
263 struct WLDAP32_berval **ret;
265 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
267 if (!ld || !message || !attr) return NULL;
269 attrW = strAtoW( attr );
270 if (!attrW) return NULL;
272 ret = ldap_get_values_lenW( ld, message, attrW );
274 strfreeW( attrW );
275 return ret;
277 #endif
278 return NULL;
281 /***********************************************************************
282 * ldap_get_values_lenW (WLDAP32.@)
284 * Retrieve binary values for a given attribute.
286 * PARAMS
287 * ld [I] Pointer to an LDAP context.
288 * message [I] Entry to retrieve values from.
289 * attr [I] Attribute to retrieve values for.
291 * RETURNS
292 * Success: Pointer to a berval array holding the values.
293 * Failure: NULL
295 * NOTES
296 * Call ldap_get_values_lenW with the result of a call to
297 * ldap_first_entry or ldap_next_entry. Free the returned
298 * array with a call to ldap_value_free_len.
300 struct WLDAP32_berval ** CDECL ldap_get_values_lenW( WLDAP32_LDAP *ld,
301 WLDAP32_LDAPMessage *message, PWCHAR attr )
303 #ifdef HAVE_LDAP
304 char *attrU = NULL;
305 struct berval **ret;
307 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
309 if (!ld || !message || !attr) return NULL;
311 attrU = strWtoU( attr );
312 if (!attrU) return NULL;
314 ret = ldap_get_values_len( ld, message, attrU );
316 strfreeU( attrU );
317 return (struct WLDAP32_berval **)ret;
319 #endif
320 return NULL;
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;