makefiles: Always use the global SOURCES variable for .l files.
[wine.git] / dlls / wldap32 / parse.c
blob9eff55e4f0e66bfdb778162bb90f7cd554c0b9d7
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 if (free) ldap_msgfree( result );
192 ldap_memfree( matchedU );
193 ldap_memfree( errorU );
194 ldap_memfree( referralsU );
195 ldap_controls_free( serverctrlsU );
196 return ret;
199 /***********************************************************************
200 * ldap_parse_sort_controlA (WLDAP32.@)
202 ULONG CDECL ldap_parse_sort_controlA( LDAP *ld, LDAPControlA **control, ULONG *result, char **attr )
204 ULONG ret;
205 WCHAR *attrW = NULL;
206 LDAPControlW **controlW = NULL;
208 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
210 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
211 if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
212 if (!(controlW = controlarrayAtoW( control ))) return WLDAP32_LDAP_NO_MEMORY;
214 ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
216 *attr = strWtoA( attrW );
217 controlarrayfreeW( controlW );
218 return ret;
221 /***********************************************************************
222 * ldap_parse_sort_controlW (WLDAP32.@)
224 ULONG CDECL ldap_parse_sort_controlW( LDAP *ld, LDAPControlW **control, ULONG *result, WCHAR **attr )
226 ULONG ret;
227 char *attrU = NULL;
228 LDAPControl **controlU, *sortcontrol = NULL;
229 int res;
230 unsigned int i;
232 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
234 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
235 if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
236 if (!(controlU = controlarrayWtoU( control ))) return WLDAP32_LDAP_NO_MEMORY;
238 for (i = 0; controlU[i]; i++)
240 if (!strcmp( LDAP_SERVER_RESP_SORT_OID, controlU[i]->ldctl_oid ))
241 sortcontrol = controlU[i];
243 if (!sortcontrol)
245 controlarrayfreeU( controlU );
246 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
249 ret = map_error( ldap_parse_sortresponse_control( CTX(ld), sortcontrol, &res, &attrU ) );
250 if (ret == WLDAP32_LDAP_SUCCESS)
252 WCHAR *str;
253 if ((str = strUtoW( attrU )))
255 *attr = str;
256 *result = res;
258 else ret = WLDAP32_LDAP_NO_MEMORY;
259 ldap_memfree( attrU );
262 controlarrayfreeU( controlU );
263 return ret;
266 /***********************************************************************
267 * ldap_parse_vlv_controlA (WLDAP32.@)
269 int CDECL ldap_parse_vlv_controlA( LDAP *ld, LDAPControlA **control, ULONG *targetpos, ULONG *listcount,
270 struct WLDAP32_berval **context, int *errcode )
272 int ret;
273 LDAPControlW **controlW = NULL;
275 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos, listcount, context, errcode );
277 if (!ld) return ~0u;
279 if (control && !(controlW = controlarrayAtoW( control ))) return WLDAP32_LDAP_NO_MEMORY;
280 ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount, context, errcode );
281 controlarrayfreeW( controlW );
282 return ret;
285 /***********************************************************************
286 * ldap_parse_vlv_controlW (WLDAP32.@)
288 int CDECL ldap_parse_vlv_controlW( LDAP *ld, LDAPControlW **control, ULONG *targetpos, ULONG *listcount,
289 struct WLDAP32_berval **context, int *errcode )
291 int ret, pos, count;
292 LDAPControl **controlU, *vlvcontrolU = NULL;
293 struct berval *ctxU;
294 unsigned int i;
296 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos, listcount, context, errcode );
298 if (!ld || !control) return ~0u;
300 if (!(controlU = controlarrayWtoU( control ))) return WLDAP32_LDAP_NO_MEMORY;
302 for (i = 0; controlU[i]; i++)
304 if (!strcmp( LDAP_CONTROL_VLVRESPONSE, controlU[i]->ldctl_oid ))
305 vlvcontrolU = controlU[i];
307 if (!vlvcontrolU)
309 controlarrayfreeU( controlU );
310 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
313 ret = map_error( ldap_parse_vlvresponse_control( CTX(ld), vlvcontrolU, &pos, &count, &ctxU, errcode ) );
314 if (ret == WLDAP32_LDAP_SUCCESS)
316 struct WLDAP32_berval *bv;
317 if ((bv = bervalUtoW( ctxU )))
319 *context = bv;
320 *targetpos = pos;
321 *listcount = count;
323 else ret = WLDAP32_LDAP_NO_MEMORY;
324 ber_bvfree( ctxU );
327 controlarrayfreeU( controlU );
328 return ret;