winecoreaudio: Use mmdevapi's AudioClient's GetService.
[wine.git] / dlls / wldap32 / parse.c
blob26e8de14c858cf897c180eb22168e60756a1476d
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"
26 #include "wine/debug.h"
27 #include "winldap_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
31 /***********************************************************************
32 * ldap_parse_extended_resultA (WLDAP32.@)
34 ULONG CDECL ldap_parse_extended_resultA( LDAP *ld, WLDAP32_LDAPMessage *result, char **oid,
35 struct WLDAP32_berval **data, BOOLEAN free )
37 ULONG ret;
38 WCHAR *oidW = NULL;
40 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
42 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
43 if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
45 ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
46 if (oid && oidW)
48 char *str;
49 if ((str = strWtoA( oidW ))) *oid = str;
50 else ret = WLDAP32_LDAP_NO_MEMORY;
51 ldap_memfreeW( oidW );
53 return ret;
56 /***********************************************************************
57 * ldap_parse_extended_resultW (WLDAP32.@)
59 ULONG CDECL ldap_parse_extended_resultW( LDAP *ld, WLDAP32_LDAPMessage *result, WCHAR **oid,
60 struct WLDAP32_berval **data, BOOLEAN free )
62 ULONG ret;
63 char *oidU = NULL;
64 struct berval *dataU = NULL;
66 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
68 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
69 if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
70 else
72 ret = map_error( ldap_parse_extended_result( CTX(ld), result, &oidU, &dataU, free ) );
74 if (oid && oidU)
76 WCHAR *str;
77 if ((str = strUtoW( oidU ))) *oid = str;
78 else ret = WLDAP32_LDAP_NO_MEMORY;
79 ldap_memfree( oidU );
81 if (data && dataU)
83 struct WLDAP32_berval *bv;
84 if ((bv = bervalUtoW( dataU ))) *data = bv;
85 else ret = WLDAP32_LDAP_NO_MEMORY;
86 ber_bvfree( dataU );
89 return ret;
92 /***********************************************************************
93 * ldap_parse_referenceA (WLDAP32.@)
95 ULONG CDECL ldap_parse_referenceA( LDAP *ld, WLDAP32_LDAPMessage *message, char ***referrals )
97 ULONG ret;
98 WCHAR **referralsW = NULL;
100 TRACE( "(%p, %p, %p)\n", ld, message, referrals );
102 if (!ld) return ~0u;
104 ret = ldap_parse_referenceW( ld, message, &referralsW );
105 if (referralsW)
107 char **ref;
108 if ((ref = strarrayWtoA( referralsW ))) *referrals = ref;
109 else ret = WLDAP32_LDAP_NO_MEMORY;
110 ldap_value_freeW( referralsW );
112 return ret;
115 /***********************************************************************
116 * ldap_parse_referenceW (WLDAP32.@)
118 ULONG CDECL ldap_parse_referenceW( LDAP *ld, WLDAP32_LDAPMessage *message, WCHAR ***referrals )
120 ULONG ret = ~0u;
121 char **referralsU = NULL;
123 TRACE( "(%p, %p, %p)\n", ld, message, referrals );
125 if (ld) ret = map_error( ldap_parse_reference( CTX(ld), message, &referralsU, NULL, 0 ) );
127 if (referralsU)
129 WCHAR **ref;
130 if ((ref = strarrayUtoW( referralsU ))) *referrals = ref;
131 else ret = WLDAP32_LDAP_NO_MEMORY;
132 ldap_memfree( referralsU );
134 return ret;
137 /***********************************************************************
138 * ldap_parse_resultA (WLDAP32.@)
140 ULONG CDECL ldap_parse_resultA( LDAP *ld, WLDAP32_LDAPMessage *result, ULONG *retcode, char **matched, char **error,
141 char ***referrals, LDAPControlA ***serverctrls, BOOLEAN free )
143 ULONG ret;
144 WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
145 LDAPControlW **serverctrlsW = NULL;
147 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode, matched, error, referrals, serverctrls,
148 free );
150 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
151 if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
153 ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW, &referralsW, &serverctrlsW, free );
155 if (matched) *matched = strWtoA( matchedW );
156 if (error) *error = strWtoA( errorW );
157 if (referrals) *referrals = strarrayWtoA( referralsW );
158 if (serverctrls) *serverctrls = controlarrayWtoA( serverctrlsW );
160 ldap_memfreeW( matchedW );
161 ldap_memfreeW( errorW );
162 ldap_value_freeW( referralsW );
163 ldap_controls_freeW( serverctrlsW );
164 return ret;
167 /***********************************************************************
168 * ldap_parse_resultW (WLDAP32.@)
170 ULONG CDECL ldap_parse_resultW( LDAP *ld, WLDAP32_LDAPMessage *result, ULONG *retcode, WCHAR **matched, WCHAR **error,
171 WCHAR ***referrals, LDAPControlW ***serverctrls, BOOLEAN free )
173 ULONG ret;
174 char *matchedU = NULL, *errorU = NULL, **referralsU = NULL;
175 LDAPControl **serverctrlsU = NULL;
177 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode, matched, error, referrals, serverctrls,
178 free );
180 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
181 if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
183 ret = map_error( ldap_parse_result( CTX(ld), MSG(result), (int *)retcode, &matchedU, &errorU, &referralsU,
184 &serverctrlsU, free ) );
186 if (matched) *matched = strUtoW( matchedU );
187 if (error) *error = strUtoW( errorU );
188 if (referrals) *referrals = strarrayUtoW( referralsU );
189 if (serverctrls) *serverctrls = controlarrayUtoW( serverctrlsU );
191 ldap_memfree( matchedU );
192 ldap_memfree( errorU );
193 ldap_memfree( referralsU );
194 ldap_controls_free( serverctrlsU );
195 return ret;
198 /***********************************************************************
199 * ldap_parse_sort_controlA (WLDAP32.@)
201 ULONG CDECL ldap_parse_sort_controlA( LDAP *ld, LDAPControlA **control, ULONG *result, char **attr )
203 ULONG ret;
204 WCHAR *attrW = NULL;
205 LDAPControlW **controlW = NULL;
207 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
209 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
210 if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
211 if (!(controlW = controlarrayAtoW( control ))) return WLDAP32_LDAP_NO_MEMORY;
213 ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
215 *attr = strWtoA( attrW );
216 controlarrayfreeW( controlW );
217 return ret;
220 /***********************************************************************
221 * ldap_parse_sort_controlW (WLDAP32.@)
223 ULONG CDECL ldap_parse_sort_controlW( LDAP *ld, LDAPControlW **control, ULONG *result, WCHAR **attr )
225 ULONG ret;
226 char *attrU = NULL;
227 LDAPControl **controlU, *sortcontrol = NULL;
228 int res;
229 unsigned int i;
231 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
233 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
234 if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
235 if (!(controlU = controlarrayWtoU( control ))) return WLDAP32_LDAP_NO_MEMORY;
237 for (i = 0; controlU[i]; i++)
239 if (!strcmp( LDAP_SERVER_RESP_SORT_OID, controlU[i]->ldctl_oid ))
240 sortcontrol = controlU[i];
242 if (!sortcontrol)
244 controlarrayfreeU( controlU );
245 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
248 ret = map_error( ldap_parse_sortresponse_control( CTX(ld), sortcontrol, &res, &attrU ) );
249 if (ret == WLDAP32_LDAP_SUCCESS)
251 WCHAR *str;
252 if ((str = strUtoW( attrU )))
254 *attr = str;
255 *result = res;
257 else ret = WLDAP32_LDAP_NO_MEMORY;
258 ldap_memfree( attrU );
261 controlarrayfreeU( controlU );
262 return ret;
265 /***********************************************************************
266 * ldap_parse_vlv_controlA (WLDAP32.@)
268 int CDECL ldap_parse_vlv_controlA( LDAP *ld, LDAPControlA **control, ULONG *targetpos, ULONG *listcount,
269 struct WLDAP32_berval **context, int *errcode )
271 int ret;
272 LDAPControlW **controlW = NULL;
274 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos, listcount, context, errcode );
276 if (!ld) return ~0u;
278 if (control && !(controlW = controlarrayAtoW( control ))) return WLDAP32_LDAP_NO_MEMORY;
279 ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount, context, errcode );
280 controlarrayfreeW( controlW );
281 return ret;
284 /***********************************************************************
285 * ldap_parse_vlv_controlW (WLDAP32.@)
287 int CDECL ldap_parse_vlv_controlW( LDAP *ld, LDAPControlW **control, ULONG *targetpos, ULONG *listcount,
288 struct WLDAP32_berval **context, int *errcode )
290 int ret, pos, count;
291 LDAPControl **controlU, *vlvcontrolU = NULL;
292 struct berval *ctxU;
293 unsigned int i;
295 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos, listcount, context, errcode );
297 if (!ld || !control) return ~0u;
299 if (!(controlU = controlarrayWtoU( control ))) return WLDAP32_LDAP_NO_MEMORY;
301 for (i = 0; controlU[i]; i++)
303 if (!strcmp( LDAP_CONTROL_VLVRESPONSE, controlU[i]->ldctl_oid ))
304 vlvcontrolU = controlU[i];
306 if (!vlvcontrolU)
308 controlarrayfreeU( controlU );
309 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
312 ret = map_error( ldap_parse_vlvresponse_control( CTX(ld), vlvcontrolU, &pos, &count, &ctxU, errcode ) );
313 if (ret == WLDAP32_LDAP_SUCCESS)
315 struct WLDAP32_berval *bv;
316 if ((bv = bervalUtoW( ctxU )))
318 *context = bv;
319 *targetpos = pos;
320 *listcount = count;
322 else ret = WLDAP32_LDAP_NO_MEMORY;
323 ber_bvfree( ctxU );
326 controlarrayfreeU( controlU );
327 return ret;