Added CSIDL_MYVIDEO|MYPICTURES|MYMUSIC to _SHRegisterUserShellFolders.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 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  * Parameters
67  *  control  [I] LDAPControl structure to free.
68  *
69  * RETURNS
70  *  LDAP_SUCCESS
71  */
72 ULONG 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 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  * Parameters
107  *  controls  [I] Array of LDAPControl structures to free.
108  *
109  * RETURNS
110  *  LDAP_SUCCESS
111  */
112 ULONG 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_page_controlA     (WLDAP32.@)
126  *
127  * See ldap_create_page_controlW.
128  */
129 ULONG ldap_create_page_controlA( WLDAP32_LDAP *ld, ULONG pagesize,
130     struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlA *control )
131 {
132     FIXME( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
133            critical, control );
134     return LDAP_NOT_SUPPORTED;
135 }
136
137 /***********************************************************************
138  *      ldap_create_page_controlW     (WLDAP32.@)
139  *
140  * Create a control for paged search results.
141  *
142  * Parameters
143  *  ld       [I] Pointer to an LDAP context.
144  *  pagesize [I] Number of entries to return per page.
145  *  cookie   [I] Used by the server to track its location in the
146  *               search results.
147  *  critical [I] Tells the server this control is critical to the
148  *               search operation.
149  *  control  [O] LDAPControl created.
150  *
151  * RETURNS
152  *  Success: LDAP_SUCCESS
153  *  Failure: An LDAP error code.
154  *
155  * NOTES
156  *  Not implemented. It may be possible to implement this function
157  *  on top of ldap_create_vlv_control.
158  */
159 ULONG ldap_create_page_controlW( WLDAP32_LDAP *ld, ULONG pagesize,
160     struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlW *control )
161 {
162     FIXME( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
163            critical, control );
164     return LDAP_NOT_SUPPORTED;
165 }
166
167 /***********************************************************************
168  *      ldap_create_sort_controlA     (WLDAP32.@)
169  *
170  * See ldap_create_sort_controlW.
171  */
172 ULONG ldap_create_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkey,
173     UCHAR critical, PLDAPControlA *control )
174 {
175     ULONG ret = LDAP_NOT_SUPPORTED;
176 #ifdef HAVE_LDAP
177     LDAPSortKeyW **sortkeyW = NULL;
178     LDAPControlW *controlW = NULL;
179
180     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
181
182     if (!ld || !sortkey || !control)
183         return WLDAP32_LDAP_PARAM_ERROR;
184
185     sortkeyW = sortkeyarrayAtoW( sortkey );
186     if (!sortkeyW) return WLDAP32_LDAP_NO_MEMORY;
187
188     ret = ldap_create_sort_controlW( ld, sortkeyW, critical, &controlW );
189
190     *control = controlWtoA( controlW );
191     if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
192
193     ldap_control_freeW( controlW );
194     sortkeyarrayfreeW( sortkeyW );
195
196 #endif
197     return ret;
198 }
199
200 /***********************************************************************
201  *      ldap_create_sort_controlW     (WLDAP32.@)
202  *
203  * Create a control for server sorted search results.
204  *
205  * Parameters
206  *  ld       [I] Pointer to an LDAP context.
207  *  sortkey  [I] Array of LDAPSortKey structures, each specifying an
208  *               attribute to use as a sort key, a matching rule and
209  *               the sort order (ascending or descending).
210  *  critical [I] Tells the server this control is critical to the
211  *               search operation.
212  *  control  [O] LDAPControl created.
213  *
214  * RETURNS
215  *  Success: LDAP_SUCCESS
216  *  Failure: An LDAP error code.
217  *
218  * NOTES
219  *  Pass the created control as a server control in subsequent calls
220  *  to ldap_search_ext(_s) to obtain sorted search results.
221  */
222 ULONG ldap_create_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkey,
223     UCHAR critical, PLDAPControlW *control )
224 {
225     ULONG ret = LDAP_NOT_SUPPORTED;
226 #ifdef HAVE_LDAP
227     LDAPSortKey **sortkeyU = NULL;
228     LDAPControl *controlU = NULL;
229
230     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
231
232     if (!ld || !sortkey || !control)
233         return WLDAP32_LDAP_PARAM_ERROR;
234
235     sortkeyU = sortkeyarrayWtoU( sortkey );
236     if (!sortkeyU) return WLDAP32_LDAP_NO_MEMORY;
237
238     ret = ldap_create_sort_control( ld, sortkeyU, critical, &controlU );
239
240     *control = controlUtoW( controlU );
241     if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
242
243     ldap_control_free( controlU );
244     sortkeyarrayfreeU( sortkeyU );
245
246 #endif
247     return ret;
248 }
249
250 /***********************************************************************
251  *      ldap_create_vlv_controlA     (WLDAP32.@)
252  *
253  * See ldap_create_vlv_controlW.
254  */
255 INT ldap_create_vlv_controlA( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
256     UCHAR critical, LDAPControlA **control )
257 {
258     INT ret = LDAP_NOT_SUPPORTED;
259 #ifdef HAVE_LDAP
260     LDAPControlW **controlW = NULL;
261
262     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
263
264     if (!ld) return ~0UL;
265
266     ret = ldap_create_vlv_controlW( ld, info, critical, controlW );
267
268     *control = controlWtoA( *controlW );
269     ldap_control_freeW( *controlW );
270
271 #endif
272     return ret;
273 }
274
275 /***********************************************************************
276  *      ldap_create_vlv_controlW     (WLDAP32.@)
277  *
278  * Create a virtual list view control.
279  *
280  * Parameters
281  *  ld       [I] Pointer to an LDAP context.
282  *  info     [I] LDAPVLVInfo structure specifying a list view window.
283  *  critical [I] Tells the server this control is critical to the
284  *               search operation.
285  *  control  [O] LDAPControl created.
286  *
287  * RETURNS
288  *  Success: LDAP_SUCCESS
289  *  Failure: An LDAP error code.
290  *
291  * NOTES
292  *  Pass the created control in conjuction with a sort control as
293  *  server controls in subsequent calls to ldap_search_ext(_s). The
294  *  server will then return a sorted, contiguous subset of results
295  *  that meets the criteria specified in the LDAPVLVInfo structure.
296  */
297 INT ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
298     UCHAR critical, LDAPControlW **control )
299 {
300     INT ret = LDAP_NOT_SUPPORTED;
301 #ifdef HAVE_LDAP
302     LDAPControl **controlU = NULL;
303
304     TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
305
306     if (!ld) return ~0UL;
307
308     ret = ldap_create_vlv_control( ld, (LDAPVLVInfo *)info, controlU );
309
310     *control = controlUtoW( *controlU );
311     ldap_control_free( *controlU );
312
313 #endif
314     return ret;
315 }
316
317 /***********************************************************************
318  *      ldap_encode_sort_controlA     (WLDAP32.@)
319  *
320  * See ldap_encode_sort_controlW.
321  */
322 ULONG ldap_encode_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkeys,
323     PLDAPControlA control, BOOLEAN critical )
324 {
325     return ldap_create_sort_controlA( ld, sortkeys, critical, &control );
326 }
327
328 /***********************************************************************
329  *      ldap_encode_sort_controlW     (WLDAP32.@)
330  *
331  * Create a control for server sorted search results.
332  *
333  * Parameters
334  *  ld       [I] Pointer to an LDAP context.
335  *  sortkey  [I] Array of LDAPSortKey structures, each specifying an
336  *               attribute to use as a sort key, a matching rule and
337  *               the sort order (ascending or descending).
338  *  critical [I] Tells the server this control is critical to the
339  *               search operation.
340  *  control  [O] LDAPControl created.
341  *
342  * RETURNS
343  *  Success: LDAP_SUCCESS
344  *  Failure: An LDAP error code.
345  *
346  * NOTES
347  *  This function is obsolete. Use its equivalent
348  *  ldap_create_sort_control instead.
349  */
350 ULONG ldap_encode_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkeys,
351     PLDAPControlW control, BOOLEAN critical )
352 {
353     return ldap_create_sort_controlW( ld, sortkeys, critical, &control );
354 }
355
356 /***********************************************************************
357  *      ldap_free_controlsA     (WLDAP32.@)
358  *
359  * See ldap_free_controlsW.
360  */
361 ULONG ldap_free_controlsA( LDAPControlA **controls )
362 {
363     return ldap_controls_freeA( controls );
364 }
365
366 /***********************************************************************
367  *      ldap_free_controlsW     (WLDAP32.@)
368  *
369  * Free an array of LDAPControl structures.
370  *
371  * Parameters
372  *  controls  [I] Array of LDAPControl structures to free.
373  *
374  * RETURNS
375  *  LDAP_SUCCESS
376  *  
377  * NOTES
378  *  Obsolete, use ldap_controls_freeW.
379  */
380 ULONG ldap_free_controlsW( LDAPControlW **controls )
381 {
382     return ldap_controls_freeW( controls );
383 }