windowscodecs: Add locking to the PNG encoder.
[wine] / dlls / wldap32 / dn.c
CommitLineData
2be395db
HL
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
360a3f91 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
2be395db
HL
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>
2be395db
HL
34#endif
35
36#include "winldap_private.h"
37#include "wldap32.h"
38
39WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
40
548d0888
HL
41/***********************************************************************
42 * ldap_dn2ufnA (WLDAP32.@)
43 *
44 * See ldap_dn2ufnW.
45 */
91e45c62 46PCHAR CDECL ldap_dn2ufnA( PCHAR dn )
2be395db
HL
47{
48 PCHAR ret = NULL;
49#ifdef HAVE_LDAP
50 WCHAR *dnW, *retW;
51
52 TRACE( "(%s)\n", debugstr_a(dn) );
53
54 dnW = strAtoW( dn );
55 if (!dnW) return NULL;
56
57 retW = ldap_dn2ufnW( dnW );
58 ret = strWtoA( retW );
59
60 strfreeW( dnW );
61 ldap_memfreeW( retW );
62
63#endif
64 return ret;
65}
66
548d0888
HL
67/***********************************************************************
68 * ldap_dn2ufnW (WLDAP32.@)
69 *
70 * Convert a DN to a user-friendly name.
71 *
72 * PARAMS
73 * dn [I] DN to convert.
74 *
75 * RETURNS
76 * Success: Pointer to a string containing the user-friendly name.
77 * Failure: NULL
78 *
79 * NOTES
80 * Free the string with ldap_memfree.
81 */
91e45c62 82PWCHAR CDECL ldap_dn2ufnW( PWCHAR dn )
2be395db
HL
83{
84 PWCHAR ret = NULL;
85#ifdef HAVE_LDAP
86 char *dnU, *retU;
87
88 TRACE( "(%s)\n", debugstr_w(dn) );
89
90 dnU = strWtoU( dn );
91 if (!dnU) return NULL;
92
93 retU = ldap_dn2ufn( dnU );
94 ret = strUtoW( retU );
95
96 strfreeU( dnU );
97 ldap_memfree( retU );
98
99#endif
100 return ret;
101}
102
548d0888
HL
103/***********************************************************************
104 * ldap_explode_dnA (WLDAP32.@)
105 *
106 * See ldap_explode_dnW.
107 */
91e45c62 108PCHAR * CDECL ldap_explode_dnA( PCHAR dn, ULONG notypes )
2be395db
HL
109{
110 PCHAR *ret = NULL;
111#ifdef HAVE_LDAP
112 WCHAR *dnW, **retW;
113
54d18992 114 TRACE( "(%s, 0x%08x)\n", debugstr_a(dn), notypes );
2be395db
HL
115
116 dnW = strAtoW( dn );
117 if (!dnW) return NULL;
118
119 retW = ldap_explode_dnW( dnW, notypes );
120 ret = strarrayWtoA( retW );
121
122 strfreeW( dnW );
123 ldap_value_freeW( retW );
124
125#endif
126 return ret;
127}
128
548d0888
HL
129/***********************************************************************
130 * ldap_explode_dnW (WLDAP32.@)
131 *
132 * Break up a DN into its components.
133 *
134 * PARAMS
135 * dn [I] DN to break up.
136 * notypes [I] Remove attribute type information from the components.
137 *
138 * RETURNS
139 * Success: Pointer to a NULL-terminated array that contains the DN
140 * components.
141 * Failure: NULL
142 *
143 * NOTES
144 * Free the string array with ldap_value_free.
145 */
91e45c62 146PWCHAR * CDECL ldap_explode_dnW( PWCHAR dn, ULONG notypes )
2be395db
HL
147{
148 PWCHAR *ret = NULL;
149#ifdef HAVE_LDAP
150 char *dnU, **retU;
151
54d18992 152 TRACE( "(%s, 0x%08x)\n", debugstr_w(dn), notypes );
2be395db
HL
153
154 dnU = strWtoU( dn );
155 if (!dnU) return NULL;
156
157 retU = ldap_explode_dn( dnU, notypes );
158 ret = strarrayUtoW( retU );
159
160 strfreeU( dnU );
6c4011e7 161 ldap_memvfree( (void **)retU );
2be395db
HL
162
163#endif
164 return ret;
165}
166
548d0888
HL
167/***********************************************************************
168 * ldap_get_dnA (WLDAP32.@)
169 *
170 * See ldap_get_dnW.
171 */
91e45c62 172PCHAR CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
2be395db
HL
173{
174 PCHAR ret = NULL;
175#ifdef HAVE_LDAP
176 PWCHAR retW;
177
178 TRACE( "(%p, %p)\n", ld, entry );
179
180 if (!ld || !entry) return NULL;
181
182 retW = ldap_get_dnW( ld, entry );
183
184 ret = strWtoA( retW );
185 ldap_memfreeW( retW );
186
187#endif
188 return ret;
189}
190
548d0888
HL
191/***********************************************************************
192 * ldap_get_dnW (WLDAP32.@)
193 *
194 * Retrieve the DN from a given LDAP message.
195 *
196 * PARAMS
197 * ld [I] Pointer to an LDAP context.
198 * entry [I] LDAPMessage structure to retrieve the DN from.
199 *
200 * RETURNS
201 * Success: Pointer to a string that contains the DN.
202 * Failure: NULL
203 *
204 * NOTES
205 * Free the string with ldap_memfree.
206 */
91e45c62 207PWCHAR CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
2be395db
HL
208{
209 PWCHAR ret = NULL;
210#ifdef HAVE_LDAP
211 char *retU;
212
213 TRACE( "(%p, %p)\n", ld, entry );
214
215 if (!ld || !entry) return NULL;
216
217 retU = ldap_get_dn( ld, entry );
218
219 ret = strUtoW( retU );
220 ldap_memfree( retU );
221
222#endif
223 return ret;
224}
225
548d0888
HL
226/***********************************************************************
227 * ldap_ufn2dnA (WLDAP32.@)
228 *
229 * See ldap_ufn2dnW.
230 */
91e45c62 231ULONG CDECL ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
2be395db 232{
46906871 233 ULONG ret = WLDAP32_LDAP_SUCCESS;
2be395db
HL
234#ifdef HAVE_LDAP
235 PWCHAR ufnW = NULL, dnW = NULL;
236
237 TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
238
239 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
240
241 *dn = NULL;
242
243 if (ufn) {
244 ufnW = strAtoW( ufn );
245 if (!ufnW) return WLDAP32_LDAP_NO_MEMORY;
246 }
247
248 ret = ldap_ufn2dnW( ufnW, &dnW );
249
250 if (dnW) {
251 *dn = strWtoA( dnW );
252 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
253 }
254
255 strfreeW( ufnW );
256 ldap_memfreeW( dnW );
257
258#endif
259 return ret;
260}
261
548d0888
HL
262/***********************************************************************
263 * ldap_ufn2dnW (WLDAP32.@)
264 *
265 * Convert a user-friendly name to a DN.
266 *
267 * PARAMS
268 * ufn [I] User-friendly name to convert.
269 * dn [O] Receives a pointer to a string containing the DN.
270 *
271 * RETURNS
272 * Success: LDAP_SUCCESS
273 * Failure: An LDAP error code.
274 *
275 * NOTES
276 * Free the string with ldap_memfree.
277 */
91e45c62 278ULONG CDECL ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn )
2be395db 279{
46906871 280 ULONG ret = WLDAP32_LDAP_SUCCESS;
2be395db
HL
281#ifdef HAVE_LDAP
282 char *ufnU = NULL;
283
284 TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
285
286 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
287
288 *dn = NULL;
289
290 if (ufn) {
291 ufnU = strWtoU( ufn );
292 if (!ufnU) return WLDAP32_LDAP_NO_MEMORY;
293
294 /* FIXME: do more than just a copy */
295 *dn = strUtoW( ufnU );
296 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
297 }
298
299 strfreeU( ufnU );
300
301#endif
302 return ret;
303}