Partially implement and test the shelllink object's
[wine/multimedia.git] / dlls / wldap32 / compare.c
bloba6de42ee333a01313b84c2e362e03e1e676fe22f
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_NOT_SUPPORTED 0x5c
36 #endif
38 #include "winldap_private.h"
39 #include "wldap32.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43 ULONG ldap_compareA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
45 ULONG ret = LDAP_NOT_SUPPORTED;
46 #ifdef HAVE_LDAP
47 WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
49 ret = WLDAP32_LDAP_NO_MEMORY;
51 TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr),
52 debugstr_a(value) );
54 if (!ld) return ~0UL;
56 if (dn) {
57 dnW = strAtoW( dn );
58 if (!dnW) goto exit;
60 if (attr) {
61 attrW = strAtoW( attr );
62 if (!attrW) goto exit;
64 if (value) {
65 valueW = strAtoW( value );
66 if (!valueW) goto exit;
69 ret = ldap_compareW( ld, dnW, attrW, valueW );
71 exit:
72 strfreeW( dnW );
73 strfreeW( attrW );
74 strfreeW( valueW );
76 #endif
77 return ret;
80 ULONG ldap_compareW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value )
82 ULONG ret = LDAP_NOT_SUPPORTED;
83 #ifdef HAVE_LDAP
84 char *dnU = NULL, *attrU = NULL, *valueU = NULL;
86 ret = WLDAP32_LDAP_NO_MEMORY;
88 TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr),
89 debugstr_w(value) );
91 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
92 if (!attr) return ~0UL;
94 if (dn) {
95 dnU = strWtoU( dn );
96 if (!dnU) goto exit;
99 attrU = strWtoU( attr );
100 if (!attrU) goto exit;
102 if (value) {
103 valueU = strWtoU( value );
104 if (!valueU) goto exit;
107 ret = ldap_compare( ld, dn ? dnU : "", attrU, value ? valueU : "" );
109 exit:
110 strfreeU( dnU );
111 strfreeU( attrU );
112 strfreeU( valueU );
114 #endif
115 return ret;
118 ULONG ldap_compare_extA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
119 struct WLDAP32_berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls,
120 ULONG *message )
122 ULONG ret = LDAP_NOT_SUPPORTED;
123 #ifdef HAVE_LDAP
124 WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
125 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
127 ret = WLDAP32_LDAP_NO_MEMORY;
129 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn),
130 debugstr_a(attr), debugstr_a(value), data, serverctrls,
131 clientctrls, message );
133 if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
135 if (dn) {
136 dnW = strAtoW( dn );
137 if (!dnW) goto exit;
139 if (attr) {
140 attrW = strAtoW( attr );
141 if (!attrW) goto exit;
143 if (value) {
144 valueW = strAtoW( value );
145 if (!valueW) goto exit;
147 if (serverctrls) {
148 serverctrlsW = controlarrayAtoW( serverctrls );
149 if (!serverctrlsW) goto exit;
151 if (clientctrls) {
152 clientctrlsW = controlarrayAtoW( clientctrls );
153 if (!clientctrlsW) goto exit;
156 ret = ldap_compare_extW( ld, dnW, attrW, valueW, data,
157 serverctrlsW, clientctrlsW, message );
159 exit:
160 strfreeW( dnW );
161 strfreeW( attrW );
162 strfreeW( valueW );
163 controlarrayfreeW( serverctrlsW );
164 controlarrayfreeW( clientctrlsW );
166 #endif
167 return ret;
170 ULONG ldap_compare_extW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value,
171 struct WLDAP32_berval *data, PLDAPControlW *serverctrls, PLDAPControlW *clientctrls,
172 ULONG *message )
174 ULONG ret = LDAP_NOT_SUPPORTED;
175 #ifdef HAVE_LDAP
176 char *dnU = NULL, *attrU = NULL, *valueU = NULL;
177 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
178 struct berval berval;
180 ret = WLDAP32_LDAP_NO_MEMORY;
182 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn),
183 debugstr_w(attr), debugstr_w(value), data, serverctrls,
184 clientctrls, message );
186 if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
187 if (!attr) return WLDAP32_LDAP_NO_MEMORY;
189 if (dn) {
190 dnU = strWtoU( dn );
191 if (!dnU) goto exit;
194 attrU = strWtoU( attr );
195 if (!attrU) goto exit;
197 if (!data) {
198 if (value) {
199 valueU = strWtoU( value );
200 if (!valueU) goto exit;
202 berval.bv_len = valueU ? strlen( valueU ) : 0;
203 berval.bv_val = valueU;
205 if (serverctrls) {
206 serverctrlsU = controlarrayWtoU( serverctrls );
207 if (!serverctrlsU) goto exit;
209 if (clientctrls) {
210 clientctrlsU = controlarrayWtoU( clientctrls );
211 if (!clientctrlsU) goto exit;
214 ret = ldap_compare_ext( ld, dn ? dnU : "", attrU, data ? (struct berval *)data : &berval,
215 serverctrlsU, clientctrlsU, (int *)message );
217 exit:
218 strfreeU( dnU );
219 strfreeU( attrU );
220 strfreeU( valueU );
221 controlarrayfreeU( serverctrlsU );
222 controlarrayfreeU( clientctrlsU );
224 #endif
225 return ret;
228 ULONG ldap_compare_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value,
229 struct WLDAP32_berval *data, PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
231 ULONG ret = LDAP_NOT_SUPPORTED;
232 #ifdef HAVE_LDAP
233 WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
234 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
236 ret = WLDAP32_LDAP_NO_MEMORY;
238 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld, debugstr_a(dn),
239 debugstr_a(attr), debugstr_a(value), data, serverctrls,
240 clientctrls );
242 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
244 if (dn) {
245 dnW = strAtoW( dn );
246 if (!dnW) goto exit;
248 if (attr) {
249 attrW = strAtoW( attr );
250 if (!attrW) goto exit;
252 if (value) {
253 valueW = strAtoW( value );
254 if (!valueW) goto exit;
256 if (serverctrls) {
257 serverctrlsW = controlarrayAtoW( serverctrls );
258 if (!serverctrlsW) goto exit;
260 if (clientctrls) {
261 clientctrlsW = controlarrayAtoW( clientctrls );
262 if (!clientctrlsW) goto exit;
265 ret = ldap_compare_ext_sW( ld, dnW, attrW, valueW, data, serverctrlsW,
266 clientctrlsW );
268 exit:
269 strfreeW( dnW );
270 strfreeW( attrW );
271 strfreeW( valueW );
272 controlarrayfreeW( serverctrlsW );
273 controlarrayfreeW( clientctrlsW );
275 #endif
276 return ret;
279 ULONG ldap_compare_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value,
280 struct WLDAP32_berval *data, PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
282 ULONG ret = LDAP_NOT_SUPPORTED;
283 #ifdef HAVE_LDAP
284 struct berval berval;
285 char *dnU = NULL, *attrU = NULL, *valueU = NULL;
286 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
288 ret = WLDAP32_LDAP_NO_MEMORY;
290 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld, debugstr_w(dn),
291 debugstr_w(attr), debugstr_w(value), data, serverctrls,
292 clientctrls );
294 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
296 if (dn) {
297 dnU = strWtoU( dn );
298 if (!dnU) goto exit;
300 if (attr) {
301 attrU = strWtoU( attr );
302 if (!attrU) goto exit;
304 if (!data) {
305 if (value) {
306 valueU = strWtoU( value );
307 if (!valueU) goto exit;
309 berval.bv_len = valueU ? strlen( valueU ) : 0;
310 berval.bv_val = valueU;
312 if (serverctrls) {
313 serverctrlsU = controlarrayWtoU( serverctrls );
314 if (!serverctrlsU) goto exit;
316 if (clientctrls) {
317 clientctrlsU = controlarrayWtoU( clientctrls );
318 if (!clientctrlsU) goto exit;
321 ret = ldap_compare_ext_s( ld, dn ? dnU : "", attr ? attrU : "", data ? (struct berval *)data : &berval,
322 serverctrlsU, clientctrlsU );
324 exit:
325 strfreeU( dnU );
326 strfreeU( attrU );
327 strfreeU( valueU );
328 controlarrayfreeU( serverctrlsU );
329 controlarrayfreeU( clientctrlsU );
331 #endif
332 return ret;
335 ULONG ldap_compare_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR attr, PCHAR value )
337 ULONG ret = LDAP_NOT_SUPPORTED;
338 #ifdef HAVE_LDAP
339 WCHAR *dnW = NULL, *attrW = NULL, *valueW = NULL;
341 ret = WLDAP32_LDAP_NO_MEMORY;
343 TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(attr),
344 debugstr_a(value) );
346 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
348 if (dn) {
349 dnW = strAtoW( dn );
350 if (!dnW) goto exit;
352 if (attr) {
353 attrW = strAtoW( attr );
354 if (!attrW) goto exit;
356 if (value) {
357 valueW = strAtoW( value );
358 if (!valueW) goto exit;
361 ret = ldap_compare_sW( ld, dnW, attrW, valueW );
363 exit:
364 strfreeW( dnW );
365 strfreeW( attrW );
366 strfreeW( valueW );
368 #endif
369 return ret;
372 ULONG ldap_compare_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR attr, PWCHAR value )
374 ULONG ret = LDAP_NOT_SUPPORTED;
375 #ifdef HAVE_LDAP
376 char *dnU = NULL, *attrU = NULL, *valueU = NULL;
378 ret = WLDAP32_LDAP_NO_MEMORY;
380 TRACE( "(%p, %s, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(attr),
381 debugstr_w(value) );
383 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
385 if (dn) {
386 dnU = strWtoU( dn );
387 if (!dnU) goto exit;
389 if (attr) {
390 attrU = strWtoU( attr );
391 if (!attrU) goto exit;
393 if (value) {
394 valueU = strWtoU( value );
395 if (!valueU) goto exit;
398 ret = ldap_compare_s( ld, dn ? dnU : "", attr ? attrU : "", value ? valueU : "" );
400 exit:
401 strfreeU( dnU );
402 strfreeU( attrU );
403 strfreeU( valueU );
405 #endif
406 return ret;