mf/tests: Add some WMA decoder GetInputAvailableType tests.
[wine.git] / dlls / wldap32 / control.c
blob9601fb6a96a143445898c800813b6f04df572898
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"
25 #include "winldap.h"
27 #include "wine/debug.h"
28 #include "winldap_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
32 /***********************************************************************
33 * ldap_control_freeA (WLDAP32.@)
35 * See ldap_control_freeW.
37 ULONG CDECL ldap_control_freeA( LDAPControlA *control )
39 TRACE( "(%p)\n", control );
40 controlfreeA( control );
41 return LDAP_SUCCESS;
44 /***********************************************************************
45 * ldap_control_freeW (WLDAP32.@)
47 * Free an LDAPControl structure.
49 * PARAMS
50 * control [I] LDAPControl structure to free.
52 * RETURNS
53 * LDAP_SUCCESS
55 ULONG CDECL ldap_control_freeW( LDAPControlW *control )
57 TRACE( "(%p)\n", control );
58 controlfreeW( control );
59 return LDAP_SUCCESS;
62 /***********************************************************************
63 * ldap_controls_freeA (WLDAP32.@)
65 * See ldap_controls_freeW.
67 ULONG CDECL ldap_controls_freeA( LDAPControlA **controls )
69 TRACE( "(%p)\n", controls );
70 controlarrayfreeA( controls );
71 return LDAP_SUCCESS;
74 /***********************************************************************
75 * ldap_controls_freeW (WLDAP32.@)
77 * Free an array of LDAPControl structures.
79 * PARAMS
80 * controls [I] Array of LDAPControl structures to free.
82 * RETURNS
83 * LDAP_SUCCESS
85 ULONG CDECL ldap_controls_freeW( LDAPControlW **controls )
87 TRACE( "(%p)\n", controls );
88 controlarrayfreeW( controls );
89 return LDAP_SUCCESS;
92 /***********************************************************************
93 * ldap_create_sort_controlA (WLDAP32.@)
95 * See ldap_create_sort_controlW.
97 ULONG CDECL ldap_create_sort_controlA( LDAP *ld, LDAPSortKeyA **sortkey, UCHAR critical, LDAPControlA **control )
99 ULONG ret;
100 LDAPSortKeyW **sortkeyW;
101 LDAPControlW *controlW;
103 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
105 if (!ld || !sortkey || !control) return LDAP_PARAM_ERROR;
107 if (!(sortkeyW = sortkeyarrayAtoW( sortkey ))) return LDAP_NO_MEMORY;
109 ret = ldap_create_sort_controlW( ld, sortkeyW, critical, &controlW );
110 if (ret == LDAP_SUCCESS)
112 LDAPControlA *controlA = controlWtoA( controlW );
113 if (controlA) *control = controlA;
114 else ret = LDAP_NO_MEMORY;
115 ldap_control_freeW( controlW );
118 sortkeyarrayfreeW( sortkeyW );
119 return ret;
122 /***********************************************************************
123 * ldap_create_sort_controlW (WLDAP32.@)
125 * Create a control for server sorted search results.
127 * PARAMS
128 * ld [I] Pointer to an LDAP context.
129 * sortkey [I] Array of LDAPSortKey structures, each specifying an
130 * attribute to use as a sort key, a matching rule and
131 * the sort order (ascending or descending).
132 * critical [I] Tells the server this control is critical to the
133 * search operation.
134 * control [O] LDAPControl created.
136 * RETURNS
137 * Success: LDAP_SUCCESS
138 * Failure: An LDAP error code.
140 * NOTES
141 * Pass the created control as a server control in subsequent calls
142 * to ldap_search_ext(_s) to obtain sorted search results.
144 ULONG CDECL ldap_create_sort_controlW( LDAP *ld, LDAPSortKeyW **sortkey, UCHAR critical, LDAPControlW **control )
146 ULONG ret;
147 LDAPSortKeyU **sortkeyU;
148 LDAPControlU *controlU;
150 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
152 if (!ld || !sortkey || !control) return LDAP_PARAM_ERROR;
154 if ((sortkeyU = sortkeyarrayWtoU( sortkey )))
156 struct ldap_create_sort_control_params params = { CTX(ld), sortkeyU, critical, &controlU };
157 ret = map_error( LDAP_CALL( ldap_create_sort_control, &params ));
159 else return LDAP_NO_MEMORY;
161 if (ret == LDAP_SUCCESS)
163 LDAPControlW *controlW = controlUtoW( controlU );
164 if (controlW) *control = controlW;
165 else ret = LDAP_NO_MEMORY;
166 LDAP_CALL( ldap_control_free, controlU );
169 sortkeyarrayfreeU( sortkeyU );
170 return ret;
173 /***********************************************************************
174 * ldap_create_vlv_controlA (WLDAP32.@)
176 * See ldap_create_vlv_controlW.
178 INT CDECL ldap_create_vlv_controlA( LDAP *ld, LDAPVLVInfo *info, UCHAR critical, LDAPControlA **control )
180 INT ret;
181 LDAPControlW *controlW;
183 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
185 if (!ld || !control) return ~0u;
187 ret = ldap_create_vlv_controlW( ld, info, critical, &controlW );
188 if (ret == LDAP_SUCCESS)
190 LDAPControlA *controlA = controlWtoA( controlW );
191 if (controlA) *control = controlA;
192 else ret = LDAP_NO_MEMORY;
193 ldap_control_freeW( controlW );
196 return ret;
199 /***********************************************************************
200 * ldap_create_vlv_controlW (WLDAP32.@)
202 * Create a virtual list view control.
204 * PARAMS
205 * ld [I] Pointer to an LDAP context.
206 * info [I] LDAPVLVInfo structure specifying a list view window.
207 * critical [I] Tells the server this control is critical to the
208 * search operation.
209 * control [O] LDAPControl created.
211 * RETURNS
212 * Success: LDAP_SUCCESS
213 * Failure: An LDAP error code.
215 * NOTES
216 * Pass the created control in conjunction with a sort control as
217 * server controls in subsequent calls to ldap_search_ext(_s). The
218 * server will then return a sorted, contiguous subset of results
219 * that meets the criteria specified in the LDAPVLVInfo structure.
221 INT CDECL ldap_create_vlv_controlW( LDAP *ld, LDAPVLVInfo *info, UCHAR critical, LDAPControlW **control )
223 ULONG ret;
224 LDAPVLVInfoU *infoU = NULL;
225 LDAPControlU *controlU;
227 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
229 if (!ld || !control) return ~0u;
231 if (info && !(infoU = vlvinfoWtoU( info ))) return LDAP_NO_MEMORY;
232 else
234 struct ldap_create_vlv_control_params params = { CTX(ld), infoU, &controlU };
235 ret = map_error( LDAP_CALL( ldap_create_vlv_control, &params ));
237 if (ret == LDAP_SUCCESS)
239 LDAPControlW *controlW = controlUtoW( controlU );
240 if (controlW) *control = controlW;
241 else ret = LDAP_NO_MEMORY;
242 LDAP_CALL( ldap_control_free, controlU );
245 vlvinfofreeU( infoU );
246 return ret;
249 static inline void bv_val_dup( const struct berval *src, struct berval *dst )
251 if ((dst->bv_val = RtlAllocateHeap( GetProcessHeap(), 0 , src->bv_len )))
253 memcpy( dst->bv_val, src->bv_val, src->bv_len );
254 dst->bv_len = src->bv_len;
256 else
257 dst->bv_len = 0;
260 /***********************************************************************
261 * ldap_encode_sort_controlA (WLDAP32.@)
263 * See ldap_encode_sort_controlW.
265 ULONG CDECL ldap_encode_sort_controlA( LDAP *ld, LDAPSortKeyA **sortkeys, LDAPControlA *ret, BOOLEAN critical )
267 LDAPControlA *control;
268 ULONG result;
270 if ((result = ldap_create_sort_controlA( ld, sortkeys, critical, &control )) == LDAP_SUCCESS)
272 ret->ldctl_oid = strdupU(control->ldctl_oid);
273 bv_val_dup( &control->ldctl_value, &ret->ldctl_value );
274 ret->ldctl_iscritical = control->ldctl_iscritical;
275 ldap_control_freeA( control );
277 return result;
280 /***********************************************************************
281 * ldap_encode_sort_controlW (WLDAP32.@)
283 * Create a control for server sorted search results.
285 * PARAMS
286 * ld [I] Pointer to an LDAP context.
287 * sortkey [I] Array of LDAPSortKey structures, each specifying an
288 * attribute to use as a sort key, a matching rule and
289 * the sort order (ascending or descending).
290 * critical [I] Tells the server this control is critical to the
291 * search operation.
292 * control [O] LDAPControl created.
294 * RETURNS
295 * Success: LDAP_SUCCESS
296 * Failure: An LDAP error code.
298 * NOTES
299 * This function is obsolete. Use its equivalent
300 * ldap_create_sort_control instead.
302 ULONG CDECL ldap_encode_sort_controlW( LDAP *ld, LDAPSortKeyW **sortkeys, LDAPControlW *ret, BOOLEAN critical )
304 LDAPControlW *control;
305 ULONG result;
307 if ((result = ldap_create_sort_controlW( ld, sortkeys, critical, &control )) == LDAP_SUCCESS)
309 ret->ldctl_oid = strdupW(control->ldctl_oid);
310 bv_val_dup( &control->ldctl_value, &ret->ldctl_value );
311 ret->ldctl_iscritical = control->ldctl_iscritical;
312 ldap_control_freeW( control );
314 return result;
317 /***********************************************************************
318 * ldap_free_controlsA (WLDAP32.@)
320 * See ldap_free_controlsW.
322 ULONG CDECL ldap_free_controlsA( LDAPControlA **controls )
324 return ldap_controls_freeA( controls );
327 /***********************************************************************
328 * ldap_free_controlsW (WLDAP32.@)
330 * Free an array of LDAPControl structures.
332 * PARAMS
333 * controls [I] Array of LDAPControl structures to free.
335 * RETURNS
336 * LDAP_SUCCESS
338 * NOTES
339 * Obsolete, use ldap_controls_freeW.
341 ULONG CDECL ldap_free_controlsW( LDAPControlW **controls )
343 return ldap_controls_freeW( controls );