ReactOS 0.4.15-dev-7788-g1ad9096
value.c
Go to the documentation of this file.
1/*
2 * WLDAP32 - LDAP support for Wine
3 *
4 * Copyright 2005 Hans Leidekker
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "config.h"
22#include "wine/port.h"
23
24#include <stdarg.h>
25#ifdef HAVE_LDAP_H
26#include <ldap.h>
27#endif
28
29#include "windef.h"
30#include "winbase.h"
31#include "winnls.h"
32
33#include "winldap_private.h"
34#include "wldap32.h"
35#include "wine/debug.h"
36
38
39/***********************************************************************
40 * ldap_count_values_len (WLDAP32.@)
41 *
42 * Count the number of values in an array of berval structures.
43 *
44 * PARAMS
45 * vals [I] Pointer to an array of berval structures.
46 *
47 * RETURNS
48 * Success: The number of values counted.
49 * Failure: 0
50 *
51 * NOTES
52 * Call ldap_count_values_len with the result of a call to
53 * ldap_get_values_len.
54 */
56{
58#ifdef HAVE_LDAP
59
60 TRACE( "(%p)\n", vals );
61 ret = ldap_count_values_len( (struct berval **)vals );
62
63#endif
64 return ret;
65}
66
67/***********************************************************************
68 * ldap_count_valuesA (WLDAP32.@)
69 *
70 * See ldap_count_valuesW.
71 */
73{
75#ifdef HAVE_LDAP
76 WCHAR **valsW = NULL;
77
78 TRACE( "(%p)\n", vals );
79
80 if (!vals) return 0;
81
82 valsW = strarrayAtoW( vals );
83 if (!valsW) return WLDAP32_LDAP_NO_MEMORY;
84
85 ret = ldap_count_valuesW( valsW );
86 strarrayfreeW( valsW );
87
88#endif
89 return ret;
90}
91
92/***********************************************************************
93 * ldap_count_valuesW (WLDAP32.@)
94 *
95 * Count the number of values in a string array.
96 *
97 * PARAMS
98 * vals [I] Pointer to an array of strings.
99 *
100 * RETURNS
101 * Success: The number of values counted.
102 * Failure: 0
103 *
104 * NOTES
105 * Call ldap_count_valuesW with the result of a call to
106 * ldap_get_valuesW.
107 */
109{
111#ifdef HAVE_LDAP
112 WCHAR **p = vals;
113
114 TRACE( "(%p)\n", vals );
115
116 if (!vals) return 0;
117
118 ret = 0;
119 while (*p++) ret++;
120
121#endif
122 return ret;
123}
124
125/***********************************************************************
126 * ldap_get_valuesA (WLDAP32.@)
127 *
128 * See ldap_get_valuesW.
129 */
131{
132 PCHAR *ret = NULL;
133#ifdef HAVE_LDAP
134 WCHAR *attrW = NULL, **retW;
135
136 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_a(attr) );
137
138 if (!ld || !entry || !attr) return NULL;
139
140 attrW = strAtoW( attr );
141 if (!attrW) return NULL;
142
143 retW = ldap_get_valuesW( ld, entry, attrW );
144
145 ret = strarrayWtoA( retW );
146 ldap_value_freeW( retW );
147 strfreeW( attrW );
148
149#endif
150 return ret;
151}
152
153#ifdef HAVE_LDAP
154static char *bv2str( struct berval *bv )
155{
156 char *str = NULL;
157 unsigned int len = bv->bv_len;
158
159 if ((str = heap_alloc( len + 1 )))
160 {
161 memcpy( str, bv->bv_val, len );
162 str[len] = '\0';
163 }
164 return str;
165}
166
167static char **bv2str_array( struct berval **bv )
168{
169 unsigned int len = 0, i = 0;
170 struct berval **p = bv;
171 char **str;
172
173 while (*p)
174 {
175 len++;
176 p++;
177 }
178 if (!(str = heap_alloc( (len + 1) * sizeof(char *) ))) return NULL;
179
180 p = bv;
181 while (*p)
182 {
183 str[i] = bv2str( *p );
184 if (!str[i])
185 {
186 while (i > 0) heap_free( str[--i] );
187 heap_free( str );
188 return NULL;
189 }
190 i++;
191 p++;
192 }
193 str[i] = NULL;
194 return str;
195}
196#endif
197
198/***********************************************************************
199 * ldap_get_valuesW (WLDAP32.@)
200 *
201 * Retrieve string values for a given attribute.
202 *
203 * PARAMS
204 * ld [I] Pointer to an LDAP context.
205 * entry [I] Entry to retrieve values from.
206 * attr [I] Attribute to retrieve values for.
207 *
208 * RETURNS
209 * Success: Pointer to a character array holding the values.
210 * Failure: NULL
211 *
212 * NOTES
213 * Call ldap_get_valuesW with the result of a call to
214 * ldap_first_entry or ldap_next_entry. Free the returned
215 * array with a call to ldap_value_freeW.
216 */
218{
219 PWCHAR *ret = NULL;
220#ifdef HAVE_LDAP
221 char *attrU = NULL, **retU;
222 struct berval **bv;
223
224 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
225
226 if (!ld || !entry || !attr) return NULL;
227
228 attrU = strWtoU( attr );
229 if (!attrU) return NULL;
230
231 bv = ldap_get_values_len( ld, entry, attrU );
232
233 retU = bv2str_array( bv );
234 ret = strarrayUtoW( retU );
235
237 strarrayfreeU( retU );
238 strfreeU( attrU );
239
240#endif
241 return ret;
242}
243
244/***********************************************************************
245 * ldap_get_values_lenA (WLDAP32.@)
246 *
247 * See ldap_get_values_lenW.
248 */
251{
252#ifdef HAVE_LDAP
253 WCHAR *attrW = NULL;
254 struct WLDAP32_berval **ret;
255
256 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
257
258 if (!ld || !message || !attr) return NULL;
259
260 attrW = strAtoW( attr );
261 if (!attrW) return NULL;
262
263 ret = ldap_get_values_lenW( ld, message, attrW );
264
265 strfreeW( attrW );
266 return ret;
267
268#else
269 return NULL;
270#endif
271}
272
273/***********************************************************************
274 * ldap_get_values_lenW (WLDAP32.@)
275 *
276 * Retrieve binary values for a given attribute.
277 *
278 * PARAMS
279 * ld [I] Pointer to an LDAP context.
280 * message [I] Entry to retrieve values from.
281 * attr [I] Attribute to retrieve values for.
282 *
283 * RETURNS
284 * Success: Pointer to a berval array holding the values.
285 * Failure: NULL
286 *
287 * NOTES
288 * Call ldap_get_values_lenW with the result of a call to
289 * ldap_first_entry or ldap_next_entry. Free the returned
290 * array with a call to ldap_value_free_len.
291 */
294{
295#ifdef HAVE_LDAP
296 char *attrU = NULL;
297 struct berval **ret;
298
299 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
300
301 if (!ld || !message || !attr) return NULL;
302
303 attrU = strWtoU( attr );
304 if (!attrU) return NULL;
305
306 ret = ldap_get_values_len( ld, message, attrU );
307
308 strfreeU( attrU );
309 return (struct WLDAP32_berval **)ret;
310
311#else
312 return NULL;
313#endif
314}
315
316/***********************************************************************
317 * ldap_value_free_len (WLDAP32.@)
318 *
319 * Free an array of berval structures.
320 *
321 * PARAMS
322 * vals [I] Array of berval structures.
323 *
324 * RETURNS
325 * Success: LDAP_SUCCESS
326 * Failure: An LDAP error code.
327 */
329{
330#ifdef HAVE_LDAP
331
332 TRACE( "(%p)\n", vals );
333 ldap_value_free_len( (struct berval **)vals );
334
335#endif
337}
338
339/***********************************************************************
340 * ldap_value_freeA (WLDAP32.@)
341 *
342 * See ldap_value_freeW.
343 */
345{
346 TRACE( "(%p)\n", vals );
347
348 strarrayfreeA( vals );
350}
351
352/***********************************************************************
353 * ldap_value_freeW (WLDAP32.@)
354 *
355 * Free an array of string values.
356 *
357 * PARAMS
358 * vals [I] Array of string values.
359 *
360 * RETURNS
361 * Success: LDAP_SUCCESS
362 * Failure: An LDAP error code.
363 */
365{
366 TRACE( "(%p)\n", vals );
367
368 strarrayfreeW( vals );
370}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define NULL
Definition: types.h:112
#define CDECL
Definition: compat.h:29
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static LPWSTR strAtoW(const char *str)
uint32_t entry
Definition: isohybrid.c:63
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
const WCHAR * str
#define TRACE(s)
Definition: solgame.cpp:4
Definition: cookie.c:202
Definition: winber.h:32
char * bv_val
Definition: winber.h:34
ber_len_t bv_len
Definition: winber.h:33
Definition: tftpd.h:60
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
PWCHAR *CDECL ldap_get_valuesW(WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr)
Definition: value.c:217
PCHAR *CDECL ldap_get_valuesA(WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PCHAR attr)
Definition: value.c:130
ULONG CDECL ldap_value_freeA(PCHAR *vals)
Definition: value.c:344
struct WLDAP32_berval **CDECL ldap_get_values_lenA(WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message, PCHAR attr)
Definition: value.c:249
ULONG CDECL WLDAP32_ldap_value_free_len(struct WLDAP32_berval **vals)
Definition: value.c:328
struct WLDAP32_berval **CDECL ldap_get_values_lenW(WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message, PWCHAR attr)
Definition: value.c:292
ULONG CDECL ldap_value_freeW(PWCHAR *vals)
Definition: value.c:364
ULONG CDECL ldap_count_valuesW(PWCHAR *vals)
Definition: value.c:108
ULONG CDECL WLDAP32_ldap_count_values_len(struct WLDAP32_berval **vals)
Definition: value.c:55
ULONG CDECL ldap_count_valuesA(PCHAR *vals)
Definition: value.c:72
int ret
WINLDAPAPI ULONG ldap_count_values_len(struct berval **)
#define ldap_get_values_len
Definition: winldap.h:671
WINLDAPAPI ULONG ldap_value_free_len(struct berval **)
@ WLDAP32_LDAP_NOT_SUPPORTED
@ WLDAP32_LDAP_SUCCESS
@ WLDAP32_LDAP_NO_MEMORY
static void strfreeU(char *str)
Definition: wldap32.h:108
static void strarrayfreeW(LPWSTR *strarray)
Definition: wldap32.h:224
static void strfreeW(LPWSTR str)
Definition: wldap32.h:103
static void strarrayfreeU(char **strarray)
Definition: wldap32.h:234
static char * strWtoU(LPCWSTR str)
Definition: wldap32.h:74
static LPWSTR * strarrayUtoW(char **strarray)
Definition: wldap32.h:194
static LPSTR * strarrayWtoA(LPWSTR *strarray)
Definition: wldap32.h:154
static void strarrayfreeA(LPSTR *strarray)
Definition: wldap32.h:214
static LPWSTR * strarrayAtoW(LPSTR *strarray)
Definition: wldap32.h:134
__wchar_t WCHAR
Definition: xmlstorage.h:180