wldap32: Mark internal symbols with hidden visibility.
[wine] / dlls / wldap32 / extended.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 #endif
35
36 #include "winldap_private.h"
37 #include "wldap32.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
40
41 /***********************************************************************
42  *      ldap_close_extended_op     (WLDAP32.@)
43  *
44  * Close an extended operation.
45  *
46  * PARAMS
47  *  ld    [I] Pointer to an LDAP context.
48  *  msgid [I] Message ID of the operation to be closed.
49  *
50  * RETURNS
51  *  Success: LDAP_SUCCESS
52  *  Failure: An LDAP error code.
53  *
54  * NOTES
55  *  Contrary to native, OpenLDAP does not require us to close
56  *  extended operations, so this is a no-op.
57  */
58 ULONG CDECL ldap_close_extended_op( WLDAP32_LDAP *ld, ULONG msgid )
59 {
60     TRACE( "(%p, 0x%08x)\n", ld, msgid );
61
62     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
63     return WLDAP32_LDAP_SUCCESS;
64 }
65
66 /***********************************************************************
67  *      ldap_extended_operationA     (WLDAP32.@)
68  *
69  * See ldap_extended_operationW.
70  */
71 ULONG CDECL ldap_extended_operationA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
72     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
73 {
74     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
75 #ifdef HAVE_LDAP
76     WCHAR *oidW = NULL;
77     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
78
79     ret = WLDAP32_LDAP_NO_MEMORY;
80
81     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
82            clientctrls, message );
83
84     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
85
86     if (oid) {
87         oidW = strAtoW( oid );
88         if (!oidW) goto exit;
89     }
90     if (serverctrls) {
91         serverctrlsW = controlarrayAtoW( serverctrls );
92         if (!serverctrlsW) goto exit;
93     }
94     if (clientctrls) {
95         clientctrlsW = controlarrayAtoW( clientctrls );
96         if (!clientctrlsW) goto exit;
97     }
98
99     ret = ldap_extended_operationW( ld, oidW, data, serverctrlsW, clientctrlsW, message );
100
101 exit:
102     strfreeW( oidW );
103     controlarrayfreeW( serverctrlsW );
104     controlarrayfreeW( clientctrlsW );
105
106 #endif
107     return ret;
108 }
109
110 /***********************************************************************
111  *      ldap_extended_operationW     (WLDAP32.@)
112  *
113  * Perform an extended operation (asynchronous mode).
114  *
115  * PARAMS
116  *  ld          [I] Pointer to an LDAP context.
117  *  oid         [I] OID of the extended operation.
118  *  data        [I] Data needed by the operation.
119  *  serverctrls [I] Array of LDAP server controls.
120  *  clientctrls [I] Array of LDAP client controls.
121  *  message     [O] Message ID of the extended operation.
122  *
123  * RETURNS
124  *  Success: LDAP_SUCCESS
125  *  Failure: An LDAP error code.
126  *
127  * NOTES
128  *  The data parameter should be set to NULL if the operation
129  *  requires no data. Call ldap_result with the message ID to
130  *  get the result of the operation or ldap_abandon to cancel
131  *  the operation. The serverctrls and clientctrls parameters
132  *  are optional and should be set to NULL if not used. Call
133  *  ldap_close_extended_op to close the operation.
134  */
135 ULONG CDECL ldap_extended_operationW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
136     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
137 {
138     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
139 #ifdef HAVE_LDAP
140     char *oidU = NULL;
141     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
142
143     ret = WLDAP32_LDAP_NO_MEMORY;
144
145     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
146            clientctrls, message );
147
148     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
149
150     if (oid) {
151         oidU = strWtoU( oid );
152         if (!oidU) goto exit;
153     }
154     if (serverctrls) {
155         serverctrlsU = controlarrayWtoU( serverctrls );
156         if (!serverctrlsU) goto exit;
157     }
158     if (clientctrls) {
159         clientctrlsU = controlarrayWtoU( clientctrls );
160         if (!clientctrlsU) goto exit;
161     }
162
163     ret = map_error( ldap_extended_operation( ld, oid ? oidU : "", (struct berval *)data,
164                                               serverctrlsU, clientctrlsU, (int *)message ));
165
166 exit:
167     strfreeU( oidU );
168     controlarrayfreeU( serverctrlsU );
169     controlarrayfreeU( clientctrlsU );
170
171 #endif
172     return ret;
173 }
174
175 /***********************************************************************
176  *      ldap_extended_operation_sA     (WLDAP32.@)
177  *
178  * See ldap_extended_operation_sW.
179  */
180 ULONG CDECL ldap_extended_operation_sA( WLDAP32_LDAP *ld, PCHAR oid, struct WLDAP32_berval *data,
181     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, PCHAR *retoid,
182     struct WLDAP32_berval **retdata )
183 {
184     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
185 #ifdef HAVE_LDAP
186     WCHAR *oidW = NULL, *retoidW = NULL;
187     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
188
189     ret = WLDAP32_LDAP_NO_MEMORY;
190
191     TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls,
192            clientctrls, retoid, retdata );
193
194     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
195
196     if (oid) {
197         oidW = strAtoW( oid );
198         if (!oidW) goto exit;
199     }
200     if (serverctrls) {
201         serverctrlsW = controlarrayAtoW( serverctrls );
202         if (!serverctrlsW) goto exit;
203     }
204     if (clientctrls) {
205         clientctrlsW = controlarrayAtoW( clientctrls );
206         if (!clientctrlsW) goto exit;
207     }
208
209     ret = ldap_extended_operation_sW( ld, oidW, data, serverctrlsW, clientctrlsW,
210                                       &retoidW, retdata );
211
212     if (retoid && retoidW) {
213         *retoid = strWtoA( retoidW );
214         if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
215         ldap_memfreeW( retoidW );
216     }
217
218 exit:
219     strfreeW( oidW );
220     controlarrayfreeW( serverctrlsW );
221     controlarrayfreeW( clientctrlsW );
222
223 #endif
224     return ret;
225 }
226
227 /***********************************************************************
228  *      ldap_extended_operation_sW     (WLDAP32.@)
229  *
230  * Perform an extended operation (synchronous mode).
231  *
232  * PARAMS
233  *  ld          [I] Pointer to an LDAP context.
234  *  oid         [I] OID of the extended operation.
235  *  data        [I] Data needed by the operation.
236  *  serverctrls [I] Array of LDAP server controls.
237  *  clientctrls [I] Array of LDAP client controls.
238  *  retoid      [O] OID of the server response message.
239  *  retdata     [O] Data returned by the server.
240  *
241  * RETURNS
242  *  Success: LDAP_SUCCESS
243  *  Failure: An LDAP error code.
244  *
245  * NOTES
246  *  The data parameter should be set to NULL if the operation
247  *  requires no data. The serverctrls, clientctrls, retoid and
248  *  and retdata parameters are also optional. Set to NULL if not
249  *  used. Free retoid and retdata after use with ldap_memfree.
250  */
251 ULONG CDECL ldap_extended_operation_sW( WLDAP32_LDAP *ld, PWCHAR oid, struct WLDAP32_berval *data,
252     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, PWCHAR *retoid,
253     struct WLDAP32_berval **retdata )
254 {
255     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
256 #ifdef HAVE_LDAP
257     char *oidU = NULL, *retoidU = NULL;
258     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
259
260     ret = WLDAP32_LDAP_NO_MEMORY;
261
262     TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls,
263            clientctrls, retoid, retdata );
264
265     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
266
267     if (oid) {
268         oidU = strWtoU( oid );
269         if (!oidU) goto exit;
270     }
271     if (serverctrls) {
272         serverctrlsU = controlarrayWtoU( serverctrls );
273         if (!serverctrlsU) goto exit;
274     }
275     if (clientctrls) {
276         clientctrlsU = controlarrayWtoU( clientctrls );
277         if (!clientctrlsU) goto exit;
278     }
279
280     ret = map_error( ldap_extended_operation_s( ld, oid ? oidU : "", (struct berval *)data, serverctrlsU,
281                                                 clientctrlsU, &retoidU, (struct berval **)retdata ));
282
283     if (retoid && retoidU) {
284         *retoid = strUtoW( retoidU );
285         if (!*retoid) ret = WLDAP32_LDAP_NO_MEMORY;
286         ldap_memfree( retoidU );
287     }
288
289 exit:
290     strfreeU( oidU );
291     controlarrayfreeU( serverctrlsU );
292     controlarrayfreeU( clientctrlsU );
293
294 #endif
295     return ret;
296 }