wldap32: Implement ldap_connect.
[wine.git] / dlls / wldap32 / control.c
blob131ea4dad64d23a7484f0b3ddd056f9c48127c65
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"
26 #include "wine/debug.h"
27 #include "winldap_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
31 /***********************************************************************
32 * ldap_control_freeA (WLDAP32.@)
34 ULONG CDECL ldap_control_freeA( LDAPControlA *control )
36 TRACE( "(%p)\n", control );
37 controlfreeA( control );
38 return WLDAP32_LDAP_SUCCESS;
41 /***********************************************************************
42 * ldap_control_freeW (WLDAP32.@)
44 ULONG CDECL ldap_control_freeW( LDAPControlW *control )
46 TRACE( "(%p)\n", control );
47 controlfreeW( control );
48 return WLDAP32_LDAP_SUCCESS;
51 /***********************************************************************
52 * ldap_controls_freeA (WLDAP32.@)
54 ULONG CDECL ldap_controls_freeA( LDAPControlA **controls )
56 TRACE( "(%p)\n", controls );
57 controlarrayfreeA( controls );
58 return WLDAP32_LDAP_SUCCESS;
61 /***********************************************************************
62 * ldap_controls_freeW (WLDAP32.@)
64 ULONG CDECL ldap_controls_freeW( LDAPControlW **controls )
66 TRACE( "(%p)\n", controls );
67 controlarrayfreeW( controls );
68 return WLDAP32_LDAP_SUCCESS;
71 /***********************************************************************
72 * ldap_create_sort_controlA (WLDAP32.@)
74 ULONG CDECL ldap_create_sort_controlA( LDAP *ld, LDAPSortKeyA **sortkey, UCHAR critical, LDAPControlA **control )
76 ULONG ret;
77 LDAPSortKeyW **sortkeyW;
78 LDAPControlW *controlW;
80 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
82 if (!ld || !sortkey || !control) return WLDAP32_LDAP_PARAM_ERROR;
84 if (!(sortkeyW = sortkeyarrayAtoW( sortkey ))) return WLDAP32_LDAP_NO_MEMORY;
86 ret = ldap_create_sort_controlW( ld, sortkeyW, critical, &controlW );
87 if (ret == WLDAP32_LDAP_SUCCESS)
89 LDAPControlA *controlA = controlWtoA( controlW );
90 if (controlA) *control = controlA;
91 else ret = WLDAP32_LDAP_NO_MEMORY;
92 ldap_control_freeW( controlW );
95 sortkeyarrayfreeW( sortkeyW );
96 return ret;
99 /***********************************************************************
100 * ldap_create_sort_controlW (WLDAP32.@)
102 ULONG CDECL ldap_create_sort_controlW( LDAP *ld, LDAPSortKeyW **sortkey, UCHAR critical, LDAPControlW **control )
104 ULONG ret;
105 LDAPSortKey **sortkeyU;
106 LDAPControl *controlU;
108 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
110 if (!ld || !sortkey || !control) return WLDAP32_LDAP_PARAM_ERROR;
112 if (!(sortkeyU = sortkeyarrayWtoU( sortkey ))) return WLDAP32_LDAP_NO_MEMORY;
114 ret = map_error( ldap_create_sort_control( CTX(ld), sortkeyU, critical, &controlU ) );
115 if (ret == WLDAP32_LDAP_SUCCESS)
117 LDAPControlW *controlW = controlUtoW( controlU );
118 if (controlW) *control = controlW;
119 else ret = WLDAP32_LDAP_NO_MEMORY;
120 ldap_control_free( controlU );
123 sortkeyarrayfreeU( sortkeyU );
124 return ret;
127 /***********************************************************************
128 * ldap_create_vlv_controlA (WLDAP32.@)
130 INT CDECL ldap_create_vlv_controlA( LDAP *ld, WLDAP32_LDAPVLVInfo *info, UCHAR critical, LDAPControlA **control )
132 INT ret;
133 LDAPControlW *controlW;
135 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
137 if (!ld || !control) return ~0u;
139 ret = ldap_create_vlv_controlW( ld, info, critical, &controlW );
140 if (ret == WLDAP32_LDAP_SUCCESS)
142 LDAPControlA *controlA = controlWtoA( controlW );
143 if (controlA) *control = controlA;
144 else ret = WLDAP32_LDAP_NO_MEMORY;
145 ldap_control_freeW( controlW );
148 return ret;
151 /***********************************************************************
152 * ldap_create_vlv_controlW (WLDAP32.@)
154 INT CDECL ldap_create_vlv_controlW( LDAP *ld, WLDAP32_LDAPVLVInfo *info, UCHAR critical, LDAPControlW **control )
156 ULONG ret;
157 LDAPVLVInfo *infoU = NULL;
158 LDAPControl *controlU;
160 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
162 if (!ld || !control) return ~0u;
164 if (info && !(infoU = vlvinfoWtoU( info ))) return WLDAP32_LDAP_NO_MEMORY;
166 ret = map_error( ldap_create_vlv_control( CTX(ld), infoU, &controlU ) );
167 if (ret == WLDAP32_LDAP_SUCCESS)
169 LDAPControlW *controlW = controlUtoW( controlU );
170 if (controlW) *control = controlW;
171 else ret = WLDAP32_LDAP_NO_MEMORY;
172 ldap_control_free( controlU );
175 vlvinfofreeU( infoU );
176 return ret;
179 static inline void bv_val_dup( const struct WLDAP32_berval *src, struct WLDAP32_berval *dst )
181 if ((dst->bv_val = RtlAllocateHeap( GetProcessHeap(), 0 , src->bv_len )))
183 memcpy( dst->bv_val, src->bv_val, src->bv_len );
184 dst->bv_len = src->bv_len;
186 else
187 dst->bv_len = 0;
190 /***********************************************************************
191 * ldap_encode_sort_controlA (WLDAP32.@)
193 ULONG CDECL ldap_encode_sort_controlA( LDAP *ld, LDAPSortKeyA **sortkeys, LDAPControlA *ret, BOOLEAN critical )
195 LDAPControlA *control;
196 ULONG result;
198 if ((result = ldap_create_sort_controlA( ld, sortkeys, critical, &control )) == WLDAP32_LDAP_SUCCESS)
200 ret->ldctl_oid = strdup( control->ldctl_oid );
201 bv_val_dup( &control->ldctl_value, &ret->ldctl_value );
202 ret->ldctl_iscritical = control->ldctl_iscritical;
203 ldap_control_freeA( control );
205 return result;
208 /***********************************************************************
209 * ldap_encode_sort_controlW (WLDAP32.@)
211 ULONG CDECL ldap_encode_sort_controlW( LDAP *ld, LDAPSortKeyW **sortkeys, LDAPControlW *ret, BOOLEAN critical )
213 LDAPControlW *control;
214 ULONG result;
216 if ((result = ldap_create_sort_controlW( ld, sortkeys, critical, &control )) == WLDAP32_LDAP_SUCCESS)
218 ret->ldctl_oid = wcsdup( control->ldctl_oid );
219 bv_val_dup( &control->ldctl_value, &ret->ldctl_value );
220 ret->ldctl_iscritical = control->ldctl_iscritical;
221 ldap_control_freeW( control );
223 return result;
226 /***********************************************************************
227 * ldap_free_controlsA (WLDAP32.@)
229 ULONG CDECL ldap_free_controlsA( LDAPControlA **controls )
231 return ldap_controls_freeA( controls );
234 /***********************************************************************
235 * ldap_free_controlsW (WLDAP32.@)
237 ULONG CDECL ldap_free_controlsW( LDAPControlW **controls )
239 return ldap_controls_freeW( controls );