mshtml: Make msec argument of setTimeout optional.
[wine.git] / dlls / wldap32 / add.c
blob0a24d95f32471be3aa24736a1ad5b2c4e6f36044
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"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #ifdef HAVE_LDAP_H
26 #include <ldap.h>
27 #endif
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
33 #include "winldap_private.h"
34 #include "wldap32.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
39 #ifdef HAVE_LDAP
40 static LDAPMod *nullattrs[] = { NULL };
41 #endif
43 /***********************************************************************
44 * ldap_addA (WLDAP32.@)
46 * See ldap_addW.
48 ULONG CDECL ldap_addA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
50 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
51 #ifdef HAVE_LDAP
52 WCHAR *dnW = NULL;
53 LDAPModW **attrsW = NULL;
55 ret = WLDAP32_LDAP_NO_MEMORY;
57 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
59 if (!ld) return ~0u;
61 if (dn) {
62 dnW = strAtoW( dn );
63 if (!dnW) goto exit;
65 if (attrs) {
66 attrsW = modarrayAtoW( attrs );
67 if (!attrsW) goto exit;
70 ret = ldap_addW( ld, dnW, attrsW );
72 exit:
73 strfreeW( dnW );
74 modarrayfreeW( attrsW );
76 #endif
77 return ret;
80 /***********************************************************************
81 * ldap_addW (WLDAP32.@)
83 * Add an entry to a directory tree (asynchronous operation).
85 * PARAMS
86 * ld [I] Pointer to an LDAP context.
87 * dn [I] DN of the entry to add.
88 * attrs [I] Pointer to an array of LDAPModW structures, each
89 * specifying an attribute and its values to add.
91 * RETURNS
92 * Success: Message ID of the add operation.
93 * Failure: An LDAP error code.
95 * NOTES
96 * Call ldap_result with the message ID to get the result of
97 * the operation. Cancel the operation by calling ldap_abandon
98 * with the message ID.
100 ULONG CDECL ldap_addW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
102 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
103 #ifdef HAVE_LDAP
104 char *dnU = NULL;
105 LDAPMod **attrsU = NULL;
106 int msg;
108 ret = WLDAP32_LDAP_NO_MEMORY;
110 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
112 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
114 if (dn) {
115 dnU = strWtoU( dn );
116 if (!dnU) goto exit;
118 if (attrs) {
119 attrsU = modarrayWtoU( attrs );
120 if (!attrsU) goto exit;
123 ret = ldap_add_ext( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, NULL, NULL, &msg );
125 if (ret == LDAP_SUCCESS)
126 ret = msg;
127 else
128 ret = ~0u;
130 exit:
131 strfreeU( dnU );
132 modarrayfreeU( attrsU );
134 #endif
135 return ret;
138 /***********************************************************************
139 * ldap_add_extA (WLDAP32.@)
141 * See ldap_add_extW.
143 ULONG CDECL ldap_add_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
144 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
146 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
147 #ifdef HAVE_LDAP
148 WCHAR *dnW = NULL;
149 LDAPModW **attrsW = NULL;
150 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
152 ret = WLDAP32_LDAP_NO_MEMORY;
154 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
155 serverctrls, clientctrls, message );
157 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
159 if (dn) {
160 dnW = strAtoW( dn );
161 if (!dnW) goto exit;
163 if (attrs) {
164 attrsW = modarrayAtoW( attrs );
165 if (!attrsW) goto exit;
167 if (serverctrls) {
168 serverctrlsW = controlarrayAtoW( serverctrls );
169 if (!serverctrlsW) goto exit;
171 if (clientctrls) {
172 clientctrlsW = controlarrayAtoW( clientctrls );
173 if (!clientctrlsW) goto exit;
176 ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
178 exit:
179 strfreeW( dnW );
180 modarrayfreeW( attrsW );
181 controlarrayfreeW( serverctrlsW );
182 controlarrayfreeW( clientctrlsW );
184 #endif
185 return ret;
188 /***********************************************************************
189 * ldap_add_extW (WLDAP32.@)
191 * Add an entry to a directory tree (asynchronous operation).
193 * PARAMS
194 * ld [I] Pointer to an LDAP context.
195 * dn [I] DN of the entry to add.
196 * attrs [I] Pointer to an array of LDAPModW structures, each
197 * specifying an attribute and its values to add.
198 * serverctrls [I] Array of LDAP server controls.
199 * clientctrls [I] Array of LDAP client controls.
200 * message [O] Message ID of the add operation.
202 * RETURNS
203 * Success: LDAP_SUCCESS
204 * Failure: An LDAP error code.
206 * NOTES
207 * Call ldap_result with the message ID to get the result of
208 * the operation. The serverctrls and clientctrls parameters are
209 * optional and should be set to NULL if not used.
211 ULONG CDECL ldap_add_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
212 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
214 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
215 #ifdef HAVE_LDAP
216 char *dnU = NULL;
217 LDAPMod **attrsU = NULL;
218 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
219 int dummy;
221 ret = WLDAP32_LDAP_NO_MEMORY;
223 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
224 serverctrls, clientctrls, message );
226 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
228 if (dn) {
229 dnU = strWtoU( dn );
230 if (!dnU) goto exit;
232 if (attrs) {
233 attrsU = modarrayWtoU( attrs );
234 if (!attrsU) goto exit;
236 if (serverctrls) {
237 serverctrlsU = controlarrayWtoU( serverctrls );
238 if (!serverctrlsU) goto exit;
240 if (clientctrls) {
241 clientctrlsU = controlarrayWtoU( clientctrls );
242 if (!clientctrlsU) goto exit;
245 ret = map_error( ldap_add_ext( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, serverctrlsU,
246 clientctrlsU, message ? (int *)message : &dummy ));
248 exit:
249 strfreeU( dnU );
250 modarrayfreeU( attrsU );
251 controlarrayfreeU( serverctrlsU );
252 controlarrayfreeU( clientctrlsU );
254 #endif
255 return ret;
258 /***********************************************************************
259 * ldap_add_ext_sA (WLDAP32.@)
261 * See ldap_add_ext_sW.
263 ULONG CDECL ldap_add_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
264 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
266 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
267 #ifdef HAVE_LDAP
268 WCHAR *dnW = NULL;
269 LDAPModW **attrsW = NULL;
270 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
272 ret = WLDAP32_LDAP_NO_MEMORY;
274 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
275 serverctrls, clientctrls );
277 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
279 if (dn) {
280 dnW = strAtoW( dn );
281 if (!dnW) goto exit;
283 if (attrs) {
284 attrsW = modarrayAtoW( attrs );
285 if (!attrsW) goto exit;
287 if (serverctrls) {
288 serverctrlsW = controlarrayAtoW( serverctrls );
289 if (!serverctrlsW) goto exit;
291 if (clientctrls) {
292 clientctrlsW = controlarrayAtoW( clientctrls );
293 if (!clientctrlsW) goto exit;
296 ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
298 exit:
299 strfreeW( dnW );
300 modarrayfreeW( attrsW );
301 controlarrayfreeW( serverctrlsW );
302 controlarrayfreeW( clientctrlsW );
304 #endif
305 return ret;
308 /***********************************************************************
309 * ldap_add_ext_sW (WLDAP32.@)
311 * Add an entry to a directory tree (synchronous operation).
313 * PARAMS
314 * ld [I] Pointer to an LDAP context.
315 * dn [I] DN of the entry to add.
316 * attrs [I] Pointer to an array of LDAPModW structures, each
317 * specifying an attribute and its values to add.
318 * serverctrls [I] Array of LDAP server controls.
319 * clientctrls [I] Array of LDAP client controls.
321 * RETURNS
322 * Success: LDAP_SUCCESS
323 * Failure: An LDAP error code.
325 * NOTES
326 * The serverctrls and clientctrls parameters are optional and
327 * should be set to NULL if not used.
329 ULONG CDECL ldap_add_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
330 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
332 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
333 #ifdef HAVE_LDAP
334 char *dnU = NULL;
335 LDAPMod **attrsU = NULL;
336 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
338 ret = WLDAP32_LDAP_NO_MEMORY;
340 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
341 serverctrls, clientctrls );
343 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
345 if (dn) {
346 dnU = strWtoU( dn );
347 if (!dnU) goto exit;
349 if (attrs) {
350 attrsU = modarrayWtoU( attrs );
351 if (!attrsU) goto exit;
353 if (serverctrls) {
354 serverctrlsU = controlarrayWtoU( serverctrls );
355 if (!serverctrlsU) goto exit;
357 if (clientctrls) {
358 clientctrlsU = controlarrayWtoU( clientctrls );
359 if (!clientctrlsU) goto exit;
362 ret = map_error( ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs,
363 serverctrlsU, clientctrlsU ));
365 exit:
366 strfreeU( dnU );
367 modarrayfreeU( attrsU );
368 controlarrayfreeU( serverctrlsU );
369 controlarrayfreeU( clientctrlsU );
371 #endif
372 return ret;
375 /***********************************************************************
376 * ldap_add_sA (WLDAP32.@)
378 * See ldap_add_sW.
380 ULONG CDECL ldap_add_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
382 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
383 #ifdef HAVE_LDAP
384 WCHAR *dnW = NULL;
385 LDAPModW **attrsW = NULL;
387 ret = WLDAP32_LDAP_NO_MEMORY;
389 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
391 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
393 if (dn) {
394 dnW = strAtoW( dn );
395 if (!dnW) goto exit;
397 if (attrs) {
398 attrsW = modarrayAtoW( attrs );
399 if (!attrsW) goto exit;
402 ret = ldap_add_sW( ld, dnW, attrsW );
404 exit:
405 strfreeW( dnW );
406 modarrayfreeW( attrsW );
408 #endif
409 return ret;
412 /***********************************************************************
413 * ldap_add_sW (WLDAP32.@)
415 * Add an entry to a directory tree (synchronous operation).
417 * PARAMS
418 * ld [I] Pointer to an LDAP context.
419 * dn [I] DN of the entry to add.
420 * attrs [I] Pointer to an array of LDAPModW structures, each
421 * specifying an attribute and its values to add.
423 * RETURNS
424 * Success: LDAP_SUCCESS
425 * Failure: An LDAP error code.
427 ULONG CDECL ldap_add_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
429 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
430 #ifdef HAVE_LDAP
431 char *dnU = NULL;
432 LDAPMod **attrsU = NULL;
434 ret = WLDAP32_LDAP_NO_MEMORY;
436 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
438 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
440 if (dn) {
441 dnU = strWtoU( dn );
442 if (!dnU) goto exit;
444 if (attrs) {
445 attrsU = modarrayWtoU( attrs );
446 if (!attrsU) goto exit;
449 ret = map_error( ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, NULL, NULL ));
451 exit:
452 strfreeU( dnU );
453 modarrayfreeU( attrsU );
455 #endif
456 return ret;