mfmediaengine: Remove vertical flipping of video frames.
[wine.git] / dlls / wldap32 / parse.c
blob88e801b30532b464fdda1f19543e134344b6ef0e
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 <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winnls.h"
25 #include "winldap.h"
27 #include "wine/debug.h"
28 #include "winldap_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
32 /***********************************************************************
33 * ldap_parse_extended_resultA (WLDAP32.@)
35 * See ldap_parse_extended_resultW.
37 ULONG CDECL ldap_parse_extended_resultA( LDAP *ld, LDAPMessage *result, char **oid, struct berval **data,
38 BOOLEAN free )
40 ULONG ret;
41 WCHAR *oidW = NULL;
43 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
45 if (!ld) return LDAP_PARAM_ERROR;
46 if (!result) return LDAP_NO_RESULTS_RETURNED;
48 ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
49 if (oid && oidW)
51 char *str;
52 if ((str = strWtoA( oidW ))) *oid = str;
53 else ret = LDAP_NO_MEMORY;
54 ldap_memfreeW( oidW );
56 return ret;
59 /***********************************************************************
60 * ldap_parse_extended_resultW (WLDAP32.@)
62 * Parse the result of an extended operation.
64 * PARAMS
65 * ld [I] Pointer to an LDAP context.
66 * result [I] Result message from an extended operation.
67 * oid [O] OID of the extended operation.
68 * data [O] Result data.
69 * free [I] Free the result message?
71 * RETURNS
72 * Success: LDAP_SUCCESS
73 * Failure: An LDAP error code.
75 * NOTES
76 * Free the OID and result data with ldap_memfree. Pass a nonzero
77 * value for 'free' or call ldap_msgfree to free the result message.
79 ULONG CDECL ldap_parse_extended_resultW( LDAP *ld, LDAPMessage *result, WCHAR **oid, struct berval **data,
80 BOOLEAN free )
82 ULONG ret;
83 char *oidU = NULL;
84 struct bervalU *dataU = NULL;
86 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
88 if (!ld) return LDAP_PARAM_ERROR;
89 if (!result) return LDAP_NO_RESULTS_RETURNED;
90 else
92 struct ldap_parse_extended_result_params params = { CTX(ld), result, &oidU, &dataU, free };
93 ret = map_error( LDAP_CALL( ldap_parse_extended_result, &params ));
95 if (oid && oidU)
97 WCHAR *str;
98 if ((str = strUtoW( oidU ))) *oid = str;
99 else ret = LDAP_NO_MEMORY;
100 LDAP_CALL( ldap_memfree, oidU );
102 if (data && dataU)
104 struct berval *bv;
105 if ((bv = bervalUtoW( dataU ))) *data = bv;
106 else ret = LDAP_NO_MEMORY;
107 LDAP_CALL( ber_bvfree, dataU );
110 return ret;
113 /***********************************************************************
114 * ldap_parse_referenceA (WLDAP32.@)
116 * See ldap_parse_referenceW.
118 ULONG CDECL ldap_parse_referenceA( LDAP *ld, LDAPMessage *message, char ***referrals )
120 ULONG ret;
121 WCHAR **referralsW = NULL;
123 TRACE( "(%p, %p, %p)\n", ld, message, referrals );
125 if (!ld) return ~0u;
127 ret = ldap_parse_referenceW( ld, message, &referralsW );
128 if (referralsW)
130 char **ref;
131 if ((ref = strarrayWtoA( referralsW ))) *referrals = ref;
132 else ret = LDAP_NO_MEMORY;
133 ldap_value_freeW( referralsW );
135 return ret;
138 /***********************************************************************
139 * ldap_parse_referenceW (WLDAP32.@)
141 * Return any referrals from a result message.
143 * PARAMS
144 * ld [I] Pointer to an LDAP context.
145 * result [I] Result message.
146 * referrals [O] Array of referral URLs.
148 * RETURNS
149 * Success: LDAP_SUCCESS
150 * Failure: An LDAP error code.
152 * NOTES
153 * Free the referrals with ldap_value_free.
155 ULONG CDECL ldap_parse_referenceW( LDAP *ld, LDAPMessage *message, WCHAR ***referrals )
157 ULONG ret = ~0u;
158 char **referralsU = NULL;
160 TRACE( "(%p, %p, %p)\n", ld, message, referrals );
162 if (ld)
164 struct ldap_parse_reference_params params = { CTX(ld), message, &referralsU, NULL, 0 };
165 ret = map_error( LDAP_CALL( ldap_parse_reference, &params ));
167 if (referralsU)
169 WCHAR **ref;
170 if ((ref = strarrayUtoW( referralsU ))) *referrals = ref;
171 else ret = LDAP_NO_MEMORY;
172 LDAP_CALL( ldap_memfree, referralsU );
174 return ret;
177 /***********************************************************************
178 * ldap_parse_resultA (WLDAP32.@)
180 * See ldap_parse_resultW.
182 ULONG CDECL ldap_parse_resultA( LDAP *ld, LDAPMessage *result, ULONG *retcode, char **matched, char **error,
183 char ***referrals, LDAPControlA ***serverctrls, BOOLEAN free )
185 ULONG ret;
186 WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
187 LDAPControlW **serverctrlsW = NULL;
189 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode, matched, error, referrals, serverctrls,
190 free );
192 if (!ld) return LDAP_PARAM_ERROR;
194 ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW, &referralsW, &serverctrlsW, free );
196 if (matched) *matched = strWtoA( matchedW );
197 if (error) *error = strWtoA( errorW );
198 if (referrals) *referrals = strarrayWtoA( referralsW );
199 if (serverctrls) *serverctrls = controlarrayWtoA( serverctrlsW );
201 ldap_memfreeW( matchedW );
202 ldap_memfreeW( errorW );
203 ldap_value_freeW( referralsW );
204 ldap_controls_freeW( serverctrlsW );
205 return ret;
208 /***********************************************************************
209 * ldap_parse_resultW (WLDAP32.@)
211 * Parse a result message.
213 * PARAMS
214 * ld [I] Pointer to an LDAP context.
215 * result [I] Result message.
216 * retcode [O] Return code for the server operation.
217 * matched [O] DNs matched in the operation.
218 * error [O] Error message for the operation.
219 * referrals [O] Referrals found in the result message.
220 * serverctrls [O] Controls used in the operation.
221 * free [I] Free the result message?
223 * RETURNS
224 * Success: LDAP_SUCCESS
225 * Failure: An LDAP error code.
227 * NOTES
228 * Free the DNs and error message with ldap_memfree. Free
229 * the referrals with ldap_value_free and the controls with
230 * ldap_controls_free. Pass a nonzero value for 'free' or call
231 * ldap_msgfree to free the result message.
233 ULONG CDECL ldap_parse_resultW( LDAP *ld, LDAPMessage *result, ULONG *retcode, WCHAR **matched, WCHAR **error,
234 WCHAR ***referrals, LDAPControlW ***serverctrls, BOOLEAN free )
236 ULONG ret;
237 char *matchedU = NULL, *errorU = NULL, **referralsU = NULL;
238 LDAPControlU **serverctrlsU = NULL;
240 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode, matched, error, referrals, serverctrls,
241 free );
243 if (ld)
245 struct ldap_parse_result_params params = { CTX(ld), MSG(result), (int *)retcode, &matchedU,
246 &errorU, &referralsU, &serverctrlsU, free };
247 ret = map_error( LDAP_CALL( ldap_parse_result, &params ));
249 else return LDAP_PARAM_ERROR;
251 if (matched) *matched = strUtoW( matchedU );
252 if (error) *error = strUtoW( errorU );
253 if (referrals) *referrals = strarrayUtoW( referralsU );
254 if (serverctrls) *serverctrls = controlarrayUtoW( serverctrlsU );
256 LDAP_CALL( ldap_memfree, matchedU );
257 LDAP_CALL( ldap_memfree, errorU );
258 LDAP_CALL( ldap_memvfree, referralsU );
259 LDAP_CALL( ldap_controls_free, serverctrlsU );
260 return ret;
263 /***********************************************************************
264 * ldap_parse_sort_controlA (WLDAP32.@)
266 * See ldap_parse_sort_controlW.
268 ULONG CDECL ldap_parse_sort_controlA( LDAP *ld, LDAPControlA **control, ULONG *result, char **attr )
270 ULONG ret;
271 WCHAR *attrW = NULL;
272 LDAPControlW **controlW = NULL;
274 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
276 if (!ld) return LDAP_PARAM_ERROR;
277 if (!control) return LDAP_CONTROL_NOT_FOUND;
278 if (!(controlW = controlarrayAtoW( control ))) return LDAP_NO_MEMORY;
280 ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
282 *attr = strWtoA( attrW );
283 controlarrayfreeW( controlW );
284 return ret;
287 /***********************************************************************
288 * ldap_parse_sort_controlW (WLDAP32.@)
290 * Parse a sort control.
292 * PARAMS
293 * ld [I] Pointer to an LDAP context.
294 * control [I] Control obtained from a result message.
295 * result [O] Result code.
296 * attr [O] Failing attribute.
298 * RETURNS
299 * Success: LDAP_SUCCESS
300 * Failure: An LDAP error code.
302 * NOTES
303 * If the function fails, free the failing attribute with ldap_memfree.
305 ULONG CDECL ldap_parse_sort_controlW( LDAP *ld, LDAPControlW **control, ULONG *result, WCHAR **attr )
307 ULONG ret;
308 char *attrU = NULL;
309 LDAPControlU **controlU, *sortcontrol = NULL;
310 int res;
311 unsigned int i;
313 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
315 if (!ld) return LDAP_PARAM_ERROR;
316 if (!control) return LDAP_CONTROL_NOT_FOUND;
317 if (!(controlU = controlarrayWtoU( control ))) return LDAP_NO_MEMORY;
319 for (i = 0; controlU[i]; i++)
321 if (!strcmp( LDAP_SERVER_RESP_SORT_OID, controlU[i]->ldctl_oid ))
322 sortcontrol = controlU[i];
324 if (!sortcontrol)
326 controlarrayfreeU( controlU );
327 return LDAP_CONTROL_NOT_FOUND;
329 else
331 struct ldap_parse_sortresponse_control_params params = { CTX(ld), sortcontrol, &res, &attrU };
332 ret = map_error( LDAP_CALL( ldap_parse_sortresponse_control, &params ));
334 if (ret == LDAP_SUCCESS)
336 WCHAR *str;
337 if ((str = strUtoW( attrU )))
339 *attr = str;
340 *result = res;
342 else ret = LDAP_NO_MEMORY;
343 LDAP_CALL( ldap_memfree, attrU );
346 controlarrayfreeU( controlU );
347 return ret;
350 /***********************************************************************
351 * ldap_parse_vlv_controlA (WLDAP32.@)
353 * See ldap_parse_vlv_controlW.
355 int CDECL ldap_parse_vlv_controlA( LDAP *ld, LDAPControlA **control, ULONG *targetpos, ULONG *listcount,
356 struct berval **context, int *errcode )
358 int ret;
359 LDAPControlW **controlW = NULL;
361 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos, listcount, context, errcode );
363 if (!ld) return ~0u;
365 if (control && !(controlW = controlarrayAtoW( control ))) return LDAP_NO_MEMORY;
366 ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount, context, errcode );
367 controlarrayfreeW( controlW );
368 return ret;
371 /***********************************************************************
372 * ldap_parse_vlv_controlW (WLDAP32.@)
374 * Parse a virtual list view control.
376 * PARAMS
377 * ld [I] Pointer to an LDAP context.
378 * control [I] Controls obtained from a result message.
379 * targetpos [O] Position of the target in the result list.
380 * listcount [O] Estimate of the number of results in the list.
381 * context [O] Server side context.
382 * errcode [O] Error code from the listview operation.
384 * RETURNS
385 * Success: LDAP_SUCCESS
386 * Failure: An LDAP error code.
388 * NOTES
389 * Free the server context with ber_bvfree.
391 int CDECL ldap_parse_vlv_controlW( LDAP *ld, LDAPControlW **control, ULONG *targetpos, ULONG *listcount,
392 struct berval **context, int *errcode )
394 int ret, pos, count;
395 LDAPControlU **controlU, *vlvcontrolU = NULL;
396 struct bervalU *ctxU;
397 unsigned int i;
399 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos, listcount, context, errcode );
401 if (!ld || !control) return ~0u;
403 if (!(controlU = controlarrayWtoU( control ))) return LDAP_NO_MEMORY;
405 for (i = 0; controlU[i]; i++)
407 if (!strcmp( LDAP_CONTROL_VLVRESPONSE, controlU[i]->ldctl_oid ))
408 vlvcontrolU = controlU[i];
410 if (!vlvcontrolU)
412 controlarrayfreeU( controlU );
413 return LDAP_CONTROL_NOT_FOUND;
415 else
417 struct ldap_parse_vlvresponse_control_params params = { CTX(ld), vlvcontrolU, &pos, &count, &ctxU, errcode };
418 ret = map_error( LDAP_CALL( ldap_parse_vlvresponse_control, &params ));
420 if (ret == LDAP_SUCCESS)
422 struct berval *bv;
423 if ((bv = bervalUtoW( ctxU )))
425 *context = bv;
426 *targetpos = pos;
427 *listcount = count;
429 else ret = LDAP_NO_MEMORY;
430 LDAP_CALL( ber_bvfree, ctxU );
433 controlarrayfreeU( controlU );
434 return ret;