d3d8/tests: Use a separate device for alpha_test().
[wine.git] / dlls / wldap32 / dn.c
blobfbe1a0c091c7c743e5f41b88da9e2027902d4890
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 "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #ifdef HAVE_LDAP_H
26 #include <ldap.h>
27 #endif
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
33 #include "winldap_private.h"
34 #include "wldap32.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
39 /***********************************************************************
40 * ldap_dn2ufnA (WLDAP32.@)
42 * See ldap_dn2ufnW.
44 PCHAR CDECL ldap_dn2ufnA( PCHAR dn )
46 PCHAR ret = NULL;
47 #ifdef HAVE_LDAP
48 WCHAR *dnW, *retW;
50 TRACE( "(%s)\n", debugstr_a(dn) );
52 dnW = strAtoW( dn );
53 if (!dnW) return NULL;
55 retW = ldap_dn2ufnW( dnW );
56 ret = strWtoA( retW );
58 strfreeW( dnW );
59 ldap_memfreeW( retW );
61 #endif
62 return ret;
65 /***********************************************************************
66 * ldap_dn2ufnW (WLDAP32.@)
68 * Convert a DN to a user-friendly name.
70 * PARAMS
71 * dn [I] DN to convert.
73 * RETURNS
74 * Success: Pointer to a string containing the user-friendly name.
75 * Failure: NULL
77 * NOTES
78 * Free the string with ldap_memfree.
80 PWCHAR CDECL ldap_dn2ufnW( PWCHAR dn )
82 PWCHAR ret = NULL;
83 #ifdef HAVE_LDAP
84 char *dnU, *retU;
86 TRACE( "(%s)\n", debugstr_w(dn) );
88 dnU = strWtoU( dn );
89 if (!dnU) return NULL;
91 retU = ldap_dn2ufn( dnU );
92 ret = strUtoW( retU );
94 strfreeU( dnU );
95 ldap_memfree( retU );
97 #endif
98 return ret;
101 /***********************************************************************
102 * ldap_explode_dnA (WLDAP32.@)
104 * See ldap_explode_dnW.
106 PCHAR * CDECL ldap_explode_dnA( PCHAR dn, ULONG notypes )
108 PCHAR *ret = NULL;
109 #ifdef HAVE_LDAP
110 WCHAR *dnW, **retW;
112 TRACE( "(%s, 0x%08x)\n", debugstr_a(dn), notypes );
114 dnW = strAtoW( dn );
115 if (!dnW) return NULL;
117 retW = ldap_explode_dnW( dnW, notypes );
118 ret = strarrayWtoA( retW );
120 strfreeW( dnW );
121 ldap_value_freeW( retW );
123 #endif
124 return ret;
127 /***********************************************************************
128 * ldap_explode_dnW (WLDAP32.@)
130 * Break up a DN into its components.
132 * PARAMS
133 * dn [I] DN to break up.
134 * notypes [I] Remove attribute type information from the components.
136 * RETURNS
137 * Success: Pointer to a NULL-terminated array that contains the DN
138 * components.
139 * Failure: NULL
141 * NOTES
142 * Free the string array with ldap_value_free.
144 PWCHAR * CDECL ldap_explode_dnW( PWCHAR dn, ULONG notypes )
146 PWCHAR *ret = NULL;
147 #ifdef HAVE_LDAP
148 char *dnU, **retU;
150 TRACE( "(%s, 0x%08x)\n", debugstr_w(dn), notypes );
152 dnU = strWtoU( dn );
153 if (!dnU) return NULL;
155 retU = ldap_explode_dn( dnU, notypes );
156 ret = strarrayUtoW( retU );
158 strfreeU( dnU );
159 ldap_memvfree( (void **)retU );
161 #endif
162 return ret;
165 /***********************************************************************
166 * ldap_get_dnA (WLDAP32.@)
168 * See ldap_get_dnW.
170 PCHAR CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
172 PCHAR ret = NULL;
173 #ifdef HAVE_LDAP
174 PWCHAR retW;
176 TRACE( "(%p, %p)\n", ld, entry );
178 if (!ld || !entry) return NULL;
180 retW = ldap_get_dnW( ld, entry );
182 ret = strWtoA( retW );
183 ldap_memfreeW( retW );
185 #endif
186 return ret;
189 /***********************************************************************
190 * ldap_get_dnW (WLDAP32.@)
192 * Retrieve the DN from a given LDAP message.
194 * PARAMS
195 * ld [I] Pointer to an LDAP context.
196 * entry [I] LDAPMessage structure to retrieve the DN from.
198 * RETURNS
199 * Success: Pointer to a string that contains the DN.
200 * Failure: NULL
202 * NOTES
203 * Free the string with ldap_memfree.
205 PWCHAR CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
207 PWCHAR ret = NULL;
208 #ifdef HAVE_LDAP
209 char *retU;
211 TRACE( "(%p, %p)\n", ld, entry );
213 if (!ld || !entry) return NULL;
215 retU = ldap_get_dn( ld, entry );
217 ret = strUtoW( retU );
218 ldap_memfree( retU );
220 #endif
221 return ret;
224 /***********************************************************************
225 * ldap_ufn2dnA (WLDAP32.@)
227 * See ldap_ufn2dnW.
229 ULONG CDECL ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
231 ULONG ret = WLDAP32_LDAP_SUCCESS;
232 #ifdef HAVE_LDAP
233 PWCHAR ufnW = NULL, dnW = NULL;
235 TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
237 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
239 *dn = NULL;
241 if (ufn) {
242 ufnW = strAtoW( ufn );
243 if (!ufnW) return WLDAP32_LDAP_NO_MEMORY;
246 ret = ldap_ufn2dnW( ufnW, &dnW );
248 if (dnW) {
249 *dn = strWtoA( dnW );
250 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
253 strfreeW( ufnW );
254 ldap_memfreeW( dnW );
256 #endif
257 return ret;
260 /***********************************************************************
261 * ldap_ufn2dnW (WLDAP32.@)
263 * Convert a user-friendly name to a DN.
265 * PARAMS
266 * ufn [I] User-friendly name to convert.
267 * dn [O] Receives a pointer to a string containing the DN.
269 * RETURNS
270 * Success: LDAP_SUCCESS
271 * Failure: An LDAP error code.
273 * NOTES
274 * Free the string with ldap_memfree.
276 ULONG CDECL ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn )
278 ULONG ret = WLDAP32_LDAP_SUCCESS;
279 #ifdef HAVE_LDAP
280 char *ufnU = NULL;
282 TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
284 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
286 *dn = NULL;
288 if (ufn) {
289 ufnU = strWtoU( ufn );
290 if (!ufnU) return WLDAP32_LDAP_NO_MEMORY;
292 /* FIXME: do more than just a copy */
293 *dn = strUtoW( ufnU );
294 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
297 strfreeU( ufnU );
299 #endif
300 return ret;