msvcrt: Import fmod implementation from musl.
[wine.git] / dlls / wldap32 / extended.c
blob3b33b0e588b8ce09abcaff9275ba0dabc9ef96b6
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_close_extended_op (WLDAP32.@)
35 * Close an extended operation.
37 * PARAMS
38 * ld [I] Pointer to an LDAP context.
39 * msgid [I] Message ID of the operation to be closed.
41 * RETURNS
42 * Success: LDAP_SUCCESS
43 * Failure: An LDAP error code.
45 * NOTES
46 * Contrary to native, OpenLDAP does not require us to close
47 * extended operations, so this is a no-op.
49 ULONG CDECL ldap_close_extended_op( LDAP *ld, ULONG msgid )
51 TRACE( "(%p, 0x%08x)\n", ld, msgid );
53 if (!ld) return LDAP_PARAM_ERROR;
54 return LDAP_SUCCESS;
57 /***********************************************************************
58 * ldap_extended_operationA (WLDAP32.@)
60 * See ldap_extended_operationW.
62 ULONG CDECL ldap_extended_operationA( LDAP *ld, char *oid, struct berval *data, LDAPControlA **serverctrls,
63 LDAPControlA **clientctrls, ULONG *message )
65 ULONG ret = LDAP_NO_MEMORY;
66 WCHAR *oidW = NULL;
67 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
69 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls, clientctrls, message );
71 if (!ld || !message) return LDAP_PARAM_ERROR;
73 if (oid && !(oidW = strAtoW( oid ))) goto exit;
74 if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
75 if (clientctrls && !(clientctrlsW = controlarrayAtoW( clientctrls ))) goto exit;
77 ret = ldap_extended_operationW( ld, oidW, data, serverctrlsW, clientctrlsW, message );
79 exit:
80 free( oidW );
81 controlarrayfreeW( serverctrlsW );
82 controlarrayfreeW( clientctrlsW );
83 return ret;
86 /***********************************************************************
87 * ldap_extended_operationW (WLDAP32.@)
89 * Perform an extended operation (asynchronous mode).
91 * PARAMS
92 * ld [I] Pointer to an LDAP context.
93 * oid [I] OID of the extended operation.
94 * data [I] Data needed by the operation.
95 * serverctrls [I] Array of LDAP server controls.
96 * clientctrls [I] Array of LDAP client controls.
97 * message [O] Message ID of the extended operation.
99 * RETURNS
100 * Success: LDAP_SUCCESS
101 * Failure: An LDAP error code.
103 * NOTES
104 * The data parameter should be set to NULL if the operation
105 * requires no data. Call ldap_result with the message ID to
106 * get the result of the operation or ldap_abandon to cancel
107 * the operation. The serverctrls and clientctrls parameters
108 * are optional and should be set to NULL if not used. Call
109 * ldap_close_extended_op to close the operation.
111 ULONG CDECL ldap_extended_operationW( LDAP *ld, WCHAR *oid, struct berval *data, LDAPControlW **serverctrls,
112 LDAPControlW **clientctrls, ULONG *message )
114 ULONG ret = LDAP_NO_MEMORY;
115 char *oidU = NULL;
116 LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
117 struct bervalU *dataU = NULL;
119 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls, clientctrls, message );
121 if (!ld || !message) return LDAP_PARAM_ERROR;
123 if (oid && !(oidU = strWtoU( oid ))) goto exit;
124 if (data && !(dataU = bervalWtoU( data ))) goto exit;
125 if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
126 if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
128 ret = map_error( ldap_funcs->fn_ldap_extended_operation( CTX(ld), oidU, dataU, serverctrlsU, clientctrlsU,
129 message ) );
131 exit:
132 free( oidU );
133 bvfreeU( dataU );
134 controlarrayfreeU( serverctrlsU );
135 controlarrayfreeU( clientctrlsU );
136 return ret;
139 /***********************************************************************
140 * ldap_extended_operation_sA (WLDAP32.@)
142 * See ldap_extended_operation_sW.
144 ULONG CDECL ldap_extended_operation_sA( LDAP *ld, char *oid, struct berval *data, LDAPControlA **serverctrls,
145 LDAPControlA **clientctrls, char **retoid, struct berval **retdata )
147 ULONG ret = LDAP_NO_MEMORY;
148 WCHAR *oidW = NULL, *retoidW = NULL;
149 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
151 TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_a(oid), data, serverctrls, clientctrls, retoid, retdata );
153 if (!ld) return LDAP_PARAM_ERROR;
155 if (oid && !(oidW = strAtoW( oid ))) goto exit;
156 if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
157 if (clientctrls && !(clientctrlsW = controlarrayAtoW( clientctrls ))) goto exit;
159 ret = ldap_extended_operation_sW( ld, oidW, data, serverctrlsW, clientctrlsW, &retoidW, retdata );
160 if (retoid && retoidW)
162 char *str = strWtoA( retoidW );
163 if (str) *retoid = str;
164 else ret = LDAP_NO_MEMORY;
165 ldap_memfreeW( retoidW );
168 exit:
169 free( oidW );
170 controlarrayfreeW( serverctrlsW );
171 controlarrayfreeW( clientctrlsW );
172 return ret;
175 /***********************************************************************
176 * ldap_extended_operation_sW (WLDAP32.@)
178 * Perform an extended operation (synchronous mode).
180 * PARAMS
181 * ld [I] Pointer to an LDAP context.
182 * oid [I] OID of the extended operation.
183 * data [I] Data needed by the operation.
184 * serverctrls [I] Array of LDAP server controls.
185 * clientctrls [I] Array of LDAP client controls.
186 * retoid [O] OID of the server response message.
187 * retdata [O] Data returned by the server.
189 * RETURNS
190 * Success: LDAP_SUCCESS
191 * Failure: An LDAP error code.
193 * NOTES
194 * The data parameter should be set to NULL if the operation
195 * requires no data. The serverctrls, clientctrls, retoid and
196 * and retdata parameters are also optional. Set to NULL if not
197 * used. Free retoid and retdata after use with ldap_memfree.
199 ULONG CDECL ldap_extended_operation_sW( LDAP *ld, WCHAR *oid, struct berval *data, LDAPControlW **serverctrls,
200 LDAPControlW **clientctrls, WCHAR **retoid, struct berval **retdata )
202 ULONG ret = LDAP_NO_MEMORY;
203 char *oidU = NULL, *retoidU = NULL;
204 LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
205 struct bervalU *retdataU, *dataU = NULL;
207 TRACE( "(%p, %s, %p, %p, %p, %p, %p)\n", ld, debugstr_w(oid), data, serverctrls, clientctrls, retoid, retdata );
209 if (!ld) return LDAP_PARAM_ERROR;
211 if (oid && !(oidU = strWtoU( oid ))) goto exit;
212 if (data && !(dataU = bervalWtoU( data ))) goto exit;
213 if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
214 if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
216 ret = map_error( ldap_funcs->fn_ldap_extended_operation_s( CTX(ld), oidU, dataU, serverctrlsU, clientctrlsU,
217 &retoidU, &retdataU ) );
218 if (retoid && retoidU)
220 WCHAR *str = strUtoW( retoidU );
221 if (str) *retoid = str;
222 else ret = LDAP_NO_MEMORY;
223 ldap_funcs->fn_ldap_memfree( retoidU );
225 if (retdata && retdataU)
227 struct berval *bv = bervalUtoW( retdataU );
228 if (bv) *retdata = bv;
229 else ret = LDAP_NO_MEMORY;
230 ldap_funcs->fn_ber_bvfree( retdataU );
233 exit:
234 free( oidU );
235 bvfreeU( dataU );
236 controlarrayfreeU( serverctrlsU );
237 controlarrayfreeU( clientctrlsU );
238 return ret;