mshtml: Added IHTMLElement2::blur implementation.
[wine/multimedia.git] / dlls / wldap32 / parse.c
blob62ffdbab0da271439028227e9f9bc597128b0c7f
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 /***********************************************************************
40 * ldap_parse_extended_resultA (WLDAP32.@)
42 * See ldap_parse_extended_resultW.
44 ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
45 PCHAR *oid, struct WLDAP32_berval **data, BOOLEAN free )
47 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
48 #ifdef HAVE_LDAP
49 WCHAR *oidW = NULL;
51 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
53 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
54 if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
56 ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
58 if (oid) {
59 *oid = strWtoA( oidW );
60 if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
61 ldap_memfreeW( oidW );
64 #endif
65 return ret;
68 /***********************************************************************
69 * ldap_parse_extended_resultW (WLDAP32.@)
71 * Parse the result of an extended operation.
73 * PARAMS
74 * ld [I] Pointer to an LDAP context.
75 * result [I] Result message from an extended operation.
76 * oid [O] OID of the extended operation.
77 * data [O] Result data.
78 * free [I] Free the result message?
80 * RETURNS
81 * Success: LDAP_SUCCESS
82 * Failure: An LDAP error code.
84 * NOTES
85 * Free the OID and result data with ldap_memfree. Pass a nonzero
86 * value for 'free' or call ldap_msgfree to free the result message.
88 ULONG CDECL ldap_parse_extended_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
89 PWCHAR *oid, struct WLDAP32_berval **data, BOOLEAN free )
91 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
92 #ifdef HAVE_LDAP
93 char *oidU = NULL;
95 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
97 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
98 if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
100 ret = map_error( ldap_parse_extended_result( ld, result, &oidU, (struct berval **)data, free ) );
102 if (oid) {
103 *oid = strUtoW( oidU );
104 if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
105 ldap_memfree( oidU );
108 #endif
109 return ret;
112 /***********************************************************************
113 * ldap_parse_referenceA (WLDAP32.@)
115 * See ldap_parse_referenceW.
117 ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
118 PCHAR **referrals )
120 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
121 #ifdef HAVE_LDAP
122 WCHAR **referralsW = NULL;
124 TRACE( "(%p, %p, %p)\n", ld, message, referrals );
126 if (!ld) return ~0u;
128 ret = ldap_parse_referenceW( ld, message, &referralsW );
130 *referrals = strarrayWtoA( referralsW );
131 ldap_value_freeW( referralsW );
133 #endif
134 return ret;
137 /***********************************************************************
138 * ldap_parse_referenceW (WLDAP32.@)
140 * Return any referrals from a result message.
142 * PARAMS
143 * ld [I] Pointer to an LDAP context.
144 * result [I] Result message.
145 * referrals [O] Array of referral URLs.
147 * RETURNS
148 * Success: LDAP_SUCCESS
149 * Failure: An LDAP error code.
151 * NOTES
152 * Free the referrals with ldap_value_free.
154 ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
155 PWCHAR **referrals )
157 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
158 #ifdef HAVE_LDAP_PARSE_REFERENCE
159 char **referralsU = NULL;
161 TRACE( "(%p, %p, %p)\n", ld, message, referrals );
163 if (!ld) return ~0u;
165 ret = map_error( ldap_parse_reference( ld, message, &referralsU, NULL, 0 ));
167 *referrals = strarrayUtoW( referralsU );
168 ldap_memfree( referralsU );
170 #endif
171 return ret;
174 /***********************************************************************
175 * ldap_parse_resultA (WLDAP32.@)
177 * See ldap_parse_resultW.
179 ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
180 ULONG *retcode, PCHAR *matched, PCHAR *error, PCHAR **referrals,
181 PLDAPControlA **serverctrls, BOOLEAN free )
183 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
184 #ifdef HAVE_LDAP
185 WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
186 LDAPControlW **serverctrlsW = NULL;
188 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
189 matched, error, referrals, serverctrls, free );
191 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
193 ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW,
194 &referralsW, &serverctrlsW, free );
196 if (matched) *matched = strWtoA( matchedW );
197 if (error) *error = strWtoA( errorW );
199 if (referrals) *referrals = strarrayWtoA( referralsW );
200 if (serverctrls) *serverctrls = controlarrayWtoA( serverctrlsW );
202 ldap_memfreeW( matchedW );
203 ldap_memfreeW( errorW );
204 ldap_value_freeW( referralsW );
205 ldap_controls_freeW( serverctrlsW );
207 #endif
208 return ret;
211 /***********************************************************************
212 * ldap_parse_resultW (WLDAP32.@)
214 * Parse a result message.
216 * PARAMS
217 * ld [I] Pointer to an LDAP context.
218 * result [I] Result message.
219 * retcode [O] Return code for the server operation.
220 * matched [O] DNs matched in the operation.
221 * error [O] Error message for the operation.
222 * referrals [O] Referrals found in the result message.
223 * serverctrls [O] Controls used in the operation.
224 * free [I] Free the result message?
226 * RETURNS
227 * Success: LDAP_SUCCESS
228 * Failure: An LDAP error code.
230 * NOTES
231 * Free the DNs and error message with ldap_memfree. Free
232 * the referrals with ldap_value_free and the controls with
233 * ldap_controls_free. Pass a nonzero value for 'free' or call
234 * ldap_msgfree to free the result message.
236 ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
237 ULONG *retcode, PWCHAR *matched, PWCHAR *error, PWCHAR **referrals,
238 PLDAPControlW **serverctrls, BOOLEAN free )
240 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
241 #ifdef HAVE_LDAP
242 char *matchedU = NULL, *errorU = NULL, **referralsU = NULL;
243 LDAPControl **serverctrlsU = NULL;
245 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
246 matched, error, referrals, serverctrls, free );
248 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
250 ret = map_error( ldap_parse_result( ld, result, (int *)retcode, &matchedU, &errorU,
251 &referralsU, &serverctrlsU, free ));
253 if (matched) *matched = strUtoW( matchedU );
254 if (error) *error = strUtoW( errorU );
256 if (referrals) *referrals = strarrayUtoW( referralsU );
257 if (serverctrls) *serverctrls = controlarrayUtoW( serverctrlsU );
259 ldap_memfree( matchedU );
260 ldap_memfree( errorU );
261 strarrayfreeU( referralsU );
262 ldap_controls_free( serverctrlsU );
264 #endif
265 return ret;
268 /***********************************************************************
269 * ldap_parse_sort_controlA (WLDAP32.@)
271 * See ldap_parse_sort_controlW.
273 ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
274 ULONG *result, PCHAR *attr )
276 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
277 #ifdef HAVE_LDAP
278 WCHAR *attrW = NULL;
279 LDAPControlW **controlW = NULL;
281 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
283 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
284 if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
286 controlW = controlarrayAtoW( control );
287 if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
289 ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
291 *attr = strWtoA( attrW );
292 controlarrayfreeW( controlW );
294 #endif
295 return ret;
298 /***********************************************************************
299 * ldap_parse_sort_controlW (WLDAP32.@)
301 * Parse a sort control.
303 * PARAMS
304 * ld [I] Pointer to an LDAP context.
305 * control [I] Control obtained from a result message.
306 * result [O] Result code.
307 * attr [O] Failing attribute.
309 * RETURNS
310 * Success: LDAP_SUCCESS
311 * Failure: An LDAP error code.
313 * NOTES
314 * If the function fails, free the failing attribute with ldap_memfree.
316 ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
317 ULONG *result, PWCHAR *attr )
319 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
320 #ifdef HAVE_LDAP
321 char *attrU = NULL;
322 LDAPControl **controlU = NULL;
323 #ifdef HAVE_LDAP_PARSE_SORT_CONTROL
324 unsigned long res;
325 #elif defined(HAVE_LDAP_PARSE_SORTRESPONSE_CONTROL)
326 ber_int_t res;
327 LDAPControl *sortcontrol = NULL;
328 unsigned int i;
329 #endif
331 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
333 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
334 if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
336 controlU = controlarrayWtoU( control );
337 if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
339 #ifdef HAVE_LDAP_PARSE_SORT_CONTROL
340 if (!(ret = ldap_parse_sort_control( ld, controlU, &res, &attrU )))
342 *result = res;
343 *attr = strUtoW( attrU );
345 #elif defined(HAVE_LDAP_PARSE_SORTRESPONSE_CONTROL)
346 for (i = 0; controlU[i]; i++)
348 if (!strcmp( LDAP_SERVER_RESP_SORT_OID, controlU[i]->ldctl_oid ))
349 sortcontrol = controlU[i];
351 if (!sortcontrol)
353 controlarrayfreeU( controlU );
354 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
356 if (!(ret = ldap_parse_sortresponse_control( ld, sortcontrol, &res, &attrU )))
358 *result = res;
359 *attr = strUtoW( attrU );
361 #endif
362 controlarrayfreeU( controlU );
364 #endif
365 return map_error( ret );
368 /***********************************************************************
369 * ldap_parse_vlv_controlA (WLDAP32.@)
371 * See ldap_parse_vlv_controlW.
373 INT CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
374 PULONG targetpos, PULONG listcount,
375 struct WLDAP32_berval **context, PINT errcode )
377 int ret = WLDAP32_LDAP_NOT_SUPPORTED;
378 #ifdef HAVE_LDAP
379 LDAPControlW **controlW = NULL;
381 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos,
382 listcount, context, errcode );
384 if (!ld) return ~0u;
386 if (control) {
387 controlW = controlarrayAtoW( control );
388 if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
391 ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount,
392 context, errcode );
394 controlarrayfreeW( controlW );
396 #endif
397 return ret;
400 /***********************************************************************
401 * ldap_parse_vlv_controlW (WLDAP32.@)
403 * Parse a virtual list view control.
405 * PARAMS
406 * ld [I] Pointer to an LDAP context.
407 * control [I] Controls obtained from a result message.
408 * targetpos [O] Position of the target in the result list.
409 * listcount [O] Estimate of the number of results in the list.
410 * context [O] Server side context.
411 * errcode [O] Error code from the listview operation.
413 * RETURNS
414 * Success: LDAP_SUCCESS
415 * Failure: An LDAP error code.
417 * NOTES
418 * Free the server context with ber_bvfree.
420 INT CDECL ldap_parse_vlv_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
421 PULONG targetpos, PULONG listcount,
422 struct WLDAP32_berval **context, PINT errcode )
424 int ret = WLDAP32_LDAP_NOT_SUPPORTED;
425 #ifdef HAVE_LDAP
426 LDAPControl **controlU = NULL;
427 #ifdef HAVE_LDAP_PARSE_VLV_CONTROL
428 unsigned long pos, count;
429 #elif defined(HAVE_LDAP_PARSE_VLVRESPONSE_CONTROL)
430 ber_int_t pos, count;
431 LDAPControl *vlvcontrol = NULL;
432 unsigned int i;
433 #endif
435 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos,
436 listcount, context, errcode );
438 if (!ld || !control) return ~0u;
440 controlU = controlarrayWtoU( control );
441 if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
443 #ifdef HAVE_LDAP_PARSE_VLV_CONTROL
444 if (!(ret = ldap_parse_vlv_control( ld, controlU, &pos, &count,
445 (struct berval **)context, errcode )))
447 *targetpos = pos;
448 *listcount = count;
450 #elif defined(HAVE_LDAP_PARSE_VLVRESPONSE_CONTROL)
451 for (i = 0; controlU[i]; i++)
453 if (!strcmp( LDAP_CONTROL_VLVRESPONSE, controlU[i]->ldctl_oid ))
454 vlvcontrol = controlU[i];
456 if (!vlvcontrol)
458 controlarrayfreeU( controlU );
459 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
461 if (!(ret = ldap_parse_vlvresponse_control( ld, vlvcontrol, &pos, &count,
462 (struct berval **)context, errcode )))
464 *targetpos = pos;
465 *listcount = count;
467 #endif
468 controlarrayfreeU( controlU );
470 #endif
471 return map_error( ret );