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