dsound: Class factory cleanup.
[wine] / dlls / wldap32 / control.c
1 /*
2  * WLDAP32 - LDAP support for Wine
3  *
4  * Copyright 2005 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include "wine/port.h"
24 #include "wine/debug.h"
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS        0x00
36 #define LDAP_NOT_SUPPORTED  0x5c
37 #endif
38
39 #include "winldap_private.h"
40 #include "wldap32.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43
44 /***********************************************************************
45  *      ldap_control_freeA     (WLDAP32.@)
46  *
47  * See ldap_control_freeW.
48  */
49 ULONG CDECL ldap_control_freeA( LDAPControlA *control )
50 {
51     ULONG ret = LDAP_SUCCESS;
52 #ifdef HAVE_LDAP
53
54     TRACE( "(%p)\n", control );
55     controlfreeA( control );
56
57 #endif
58     return ret;
59 }
60
61 /***********************************************************************
62  *      ldap_control_freeW     (WLDAP32.@)
63  *
64  * Free an LDAPControl structure.
65  *
66  * PARAMS
67  *  control  [I] LDAPControl structure to free.
68  *
69  * RETURNS
70  *  LDAP_SUCCESS
71  */
72 ULONG CDECL ldap_control_freeW( LDAPControlW *control )
73 {
74     ULONG ret = LDAP_SUCCESS;
75 #ifdef HAVE_LDAP
76
77     TRACE( "(%p)\n", control );
78     controlfreeW( control );
79
80 #endif
81     return ret;
82 }
83
84 /***********************************************************************
85  *      ldap_controls_freeA     (WLDAP32.@)
86  *
87  * See ldap_controls_freeW.
88  */
89 ULONG CDECL ldap_controls_freeA( LDAPControlA **controls )
90 {
91     ULONG ret = LDAP_SUCCESS;
92 #ifdef HAVE_LDAP
93
94     TRACE( "(%p)\n", controls );
95     controlarrayfreeA( controls );
96
97 #endif
98     return ret;
99 }
100
101 /***********************************************************************
102  *      ldap_controls_freeW     (WLDAP32.@)
103  *
104  * Free an array of LDAPControl structures.
105  *
106  * PARAMS
107  *  controls  [I] Array of LDAPControl structures to free.
108  *
109  * RETURNS
110  *  LDAP_SUCCESS
111  */
112 ULONG CDECL ldap_controls_freeW( LDAPControlW **controls )
113 {
114     ULONG ret = LDAP_SUCCESS;
115 #ifdef HAVE_LDAP
116
117     TRACE( "(%p)\n", controls );
118     controlarrayfreeW( controls );
119
120 #endif
121     return ret;
122 }
123
124 /***********************************************************************
125  *      ldap_create_sort_controlA     (WLDAP32.@)
126  *
127  * See ldap_create_sort_controlW.
128  */
129 ULONG CDECL ldap_create_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkey,
130     UCHAR critical, PLDAPControlA *control )
131 {
132     ULONG ret = LDAP_NOT_SUPPORTED;
133 #ifdef HAVE_LDAP
134     LDAPSortKeyW **sortkeyW = NULL;
135     LDAPControlW *controlW = NULL;
136
137     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
138
139     if (!ld || !sortkey || !control)
140         return WLDAP32_LDAP_PARAM_ERROR;
141
142     sortkeyW = sortkeyarrayAtoW( sortkey );
143     if (!sortkeyW) return WLDAP32_LDAP_NO_MEMORY;
144
145     ret = ldap_create_sort_controlW( ld, sortkeyW, critical, &controlW );
146
147     *control = controlWtoA( controlW );
148     if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
149
150     ldap_control_freeW( controlW );
151     sortkeyarrayfreeW( sortkeyW );
152
153 #endif
154     return ret;
155 }
156
157 /***********************************************************************
158  *      ldap_create_sort_controlW     (WLDAP32.@)
159  *
160  * Create a control for server sorted search results.
161  *
162  * PARAMS
163  *  ld       [I] Pointer to an LDAP context.
164  *  sortkey  [I] Array of LDAPSortKey structures, each specifying an
165  *               attribute to use as a sort key, a matching rule and
166  *               the sort order (ascending or descending).
167  *  critical [I] Tells the server this control is critical to the
168  *               search operation.
169  *  control  [O] LDAPControl created.
170  *
171  * RETURNS
172  *  Success: LDAP_SUCCESS
173  *  Failure: An LDAP error code.
174  *
175  * NOTES
176  *  Pass the created control as a server control in subsequent calls
177  *  to ldap_search_ext(_s) to obtain sorted search results.
178  */
179 ULONG CDECL ldap_create_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkey,
180     UCHAR critical, PLDAPControlW *control )
181 {
182     ULONG ret = LDAP_NOT_SUPPORTED;
183 #ifdef HAVE_LDAP
184     LDAPSortKey **sortkeyU = NULL;
185     LDAPControl *controlU = NULL;
186
187     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
188
189     if (!ld || !sortkey || !control)
190         return WLDAP32_LDAP_PARAM_ERROR;
191
192     sortkeyU = sortkeyarrayWtoU( sortkey );
193     if (!sortkeyU) return WLDAP32_LDAP_NO_MEMORY;
194
195     ret = ldap_create_sort_control( ld, sortkeyU, critical, &controlU );
196
197     *control = controlUtoW( controlU );
198     if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
199
200     ldap_control_free( controlU );
201     sortkeyarrayfreeU( sortkeyU );
202
203 #endif
204     return ret;
205 }
206
207 /***********************************************************************
208  *      ldap_create_vlv_controlA     (WLDAP32.@)
209  *
210  * See ldap_create_vlv_controlW.
211  */
212 INT CDECL ldap_create_vlv_controlA( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
213     UCHAR critical, LDAPControlA **control )
214 {
215     INT ret = LDAP_NOT_SUPPORTED;
216 #ifdef HAVE_LDAP
217     LDAPControlW *controlW = NULL;
218
219     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
220
221     if (!ld || !control) return ~0UL;
222
223     ret = ldap_create_vlv_controlW( ld, info, critical, &controlW );
224
225     if (ret == LDAP_SUCCESS)
226     {
227         *control = controlWtoA( controlW );
228         if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
229         ldap_control_freeW( controlW );
230     }
231
232 #endif
233     return ret;
234 }
235
236 /***********************************************************************
237  *      ldap_create_vlv_controlW     (WLDAP32.@)
238  *
239  * Create a virtual list view control.
240  *
241  * PARAMS
242  *  ld       [I] Pointer to an LDAP context.
243  *  info     [I] LDAPVLVInfo structure specifying a list view window.
244  *  critical [I] Tells the server this control is critical to the
245  *               search operation.
246  *  control  [O] LDAPControl created.
247  *
248  * RETURNS
249  *  Success: LDAP_SUCCESS
250  *  Failure: An LDAP error code.
251  *
252  * NOTES
253  *  Pass the created control in conjuction with a sort control as
254  *  server controls in subsequent calls to ldap_search_ext(_s). The
255  *  server will then return a sorted, contiguous subset of results
256  *  that meets the criteria specified in the LDAPVLVInfo structure.
257  */
258 INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
259     UCHAR critical, LDAPControlW **control )
260 {
261     INT ret = LDAP_NOT_SUPPORTED;
262 #ifdef HAVE_LDAP
263     LDAPControl *controlU = NULL;
264
265     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
266
267     if (!ld || !control) return ~0UL;
268
269     ret = ldap_create_vlv_control( ld, (LDAPVLVInfo *)info, &controlU );
270
271     if (ret == LDAP_SUCCESS)
272     {
273         *control = controlUtoW( controlU );
274         if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
275         ldap_control_free( controlU );
276     }
277
278 #endif
279     return ret;
280 }
281
282 /***********************************************************************
283  *      ldap_encode_sort_controlA     (WLDAP32.@)
284  *
285  * See ldap_encode_sort_controlW.
286  */
287 ULONG CDECL ldap_encode_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkeys,
288     PLDAPControlA control, BOOLEAN critical )
289 {
290     return ldap_create_sort_controlA( ld, sortkeys, critical, &control );
291 }
292
293 /***********************************************************************
294  *      ldap_encode_sort_controlW     (WLDAP32.@)
295  *
296  * Create a control for server sorted search results.
297  *
298  * PARAMS
299  *  ld       [I] Pointer to an LDAP context.
300  *  sortkey  [I] Array of LDAPSortKey structures, each specifying an
301  *               attribute to use as a sort key, a matching rule and
302  *               the sort order (ascending or descending).
303  *  critical [I] Tells the server this control is critical to the
304  *               search operation.
305  *  control  [O] LDAPControl created.
306  *
307  * RETURNS
308  *  Success: LDAP_SUCCESS
309  *  Failure: An LDAP error code.
310  *
311  * NOTES
312  *  This function is obsolete. Use its equivalent
313  *  ldap_create_sort_control instead.
314  */
315 ULONG CDECL ldap_encode_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkeys,
316     PLDAPControlW control, BOOLEAN critical )
317 {
318     return ldap_create_sort_controlW( ld, sortkeys, critical, &control );
319 }
320
321 /***********************************************************************
322  *      ldap_free_controlsA     (WLDAP32.@)
323  *
324  * See ldap_free_controlsW.
325  */
326 ULONG CDECL ldap_free_controlsA( LDAPControlA **controls )
327 {
328     return ldap_controls_freeA( controls );
329 }
330
331 /***********************************************************************
332  *      ldap_free_controlsW     (WLDAP32.@)
333  *
334  * Free an array of LDAPControl structures.
335  *
336  * PARAMS
337  *  controls  [I] Array of LDAPControl structures to free.
338  *
339  * RETURNS
340  *  LDAP_SUCCESS
341  *  
342  * NOTES
343  *  Obsolete, use ldap_controls_freeW.
344  */
345 ULONG CDECL ldap_free_controlsW( LDAPControlW **controls )
346 {
347     return ldap_controls_freeW( controls );
348 }