usp10: Update tests in test_ScriptItemIzeShapePlace to match Windows results.
[wine/multimedia.git] / dlls / wldap32 / dn.c
blob755d310fc85f6f935aded75873c712ebd61d4d58
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"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS 0x00
36 #endif
38 #include "winldap_private.h"
39 #include "wldap32.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43 /***********************************************************************
44 * ldap_dn2ufnA (WLDAP32.@)
46 * See ldap_dn2ufnW.
48 PCHAR ldap_dn2ufnA( PCHAR dn )
50 PCHAR ret = NULL;
51 #ifdef HAVE_LDAP
52 WCHAR *dnW, *retW;
54 TRACE( "(%s)\n", debugstr_a(dn) );
56 dnW = strAtoW( dn );
57 if (!dnW) return NULL;
59 retW = ldap_dn2ufnW( dnW );
60 ret = strWtoA( retW );
62 strfreeW( dnW );
63 ldap_memfreeW( retW );
65 #endif
66 return ret;
69 /***********************************************************************
70 * ldap_dn2ufnW (WLDAP32.@)
72 * Convert a DN to a user-friendly name.
74 * PARAMS
75 * dn [I] DN to convert.
77 * RETURNS
78 * Success: Pointer to a string containing the user-friendly name.
79 * Failure: NULL
81 * NOTES
82 * Free the string with ldap_memfree.
84 PWCHAR ldap_dn2ufnW( PWCHAR dn )
86 PWCHAR ret = NULL;
87 #ifdef HAVE_LDAP
88 char *dnU, *retU;
90 TRACE( "(%s)\n", debugstr_w(dn) );
92 dnU = strWtoU( dn );
93 if (!dnU) return NULL;
95 retU = ldap_dn2ufn( dnU );
96 ret = strUtoW( retU );
98 strfreeU( dnU );
99 ldap_memfree( retU );
101 #endif
102 return ret;
105 /***********************************************************************
106 * ldap_explode_dnA (WLDAP32.@)
108 * See ldap_explode_dnW.
110 PCHAR *ldap_explode_dnA( PCHAR dn, ULONG notypes )
112 PCHAR *ret = NULL;
113 #ifdef HAVE_LDAP
114 WCHAR *dnW, **retW;
116 TRACE( "(%s, 0x%08lx)\n", debugstr_a(dn), notypes );
118 dnW = strAtoW( dn );
119 if (!dnW) return NULL;
121 retW = ldap_explode_dnW( dnW, notypes );
122 ret = strarrayWtoA( retW );
124 strfreeW( dnW );
125 ldap_value_freeW( retW );
127 #endif
128 return ret;
131 /***********************************************************************
132 * ldap_explode_dnW (WLDAP32.@)
134 * Break up a DN into its components.
136 * PARAMS
137 * dn [I] DN to break up.
138 * notypes [I] Remove attribute type information from the components.
140 * RETURNS
141 * Success: Pointer to a NULL-terminated array that contains the DN
142 * components.
143 * Failure: NULL
145 * NOTES
146 * Free the string array with ldap_value_free.
148 PWCHAR *ldap_explode_dnW( PWCHAR dn, ULONG notypes )
150 PWCHAR *ret = NULL;
151 #ifdef HAVE_LDAP
152 char *dnU, **retU;
154 TRACE( "(%s, 0x%08lx)\n", debugstr_w(dn), notypes );
156 dnU = strWtoU( dn );
157 if (!dnU) return NULL;
159 retU = ldap_explode_dn( dnU, notypes );
160 ret = strarrayUtoW( retU );
162 strfreeU( dnU );
163 ldap_memvfree( (void **)retU );
165 #endif
166 return ret;
169 /***********************************************************************
170 * ldap_get_dnA (WLDAP32.@)
172 * See ldap_get_dnW.
174 PCHAR ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
176 PCHAR ret = NULL;
177 #ifdef HAVE_LDAP
178 PWCHAR retW;
180 TRACE( "(%p, %p)\n", ld, entry );
182 if (!ld || !entry) return NULL;
184 retW = ldap_get_dnW( ld, entry );
186 ret = strWtoA( retW );
187 ldap_memfreeW( retW );
189 #endif
190 return ret;
193 /***********************************************************************
194 * ldap_get_dnW (WLDAP32.@)
196 * Retrieve the DN from a given LDAP message.
198 * PARAMS
199 * ld [I] Pointer to an LDAP context.
200 * entry [I] LDAPMessage structure to retrieve the DN from.
202 * RETURNS
203 * Success: Pointer to a string that contains the DN.
204 * Failure: NULL
206 * NOTES
207 * Free the string with ldap_memfree.
209 PWCHAR ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
211 PWCHAR ret = NULL;
212 #ifdef HAVE_LDAP
213 char *retU;
215 TRACE( "(%p, %p)\n", ld, entry );
217 if (!ld || !entry) return NULL;
219 retU = ldap_get_dn( ld, entry );
221 ret = strUtoW( retU );
222 ldap_memfree( retU );
224 #endif
225 return ret;
228 /***********************************************************************
229 * ldap_ufn2dnA (WLDAP32.@)
231 * See ldap_ufn2dnW.
233 ULONG ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
235 ULONG ret = LDAP_SUCCESS;
236 #ifdef HAVE_LDAP
237 PWCHAR ufnW = NULL, dnW = NULL;
239 TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
241 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
243 *dn = NULL;
245 if (ufn) {
246 ufnW = strAtoW( ufn );
247 if (!ufnW) return WLDAP32_LDAP_NO_MEMORY;
250 ret = ldap_ufn2dnW( ufnW, &dnW );
252 if (dnW) {
253 *dn = strWtoA( dnW );
254 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
257 strfreeW( ufnW );
258 ldap_memfreeW( dnW );
260 #endif
261 return ret;
264 /***********************************************************************
265 * ldap_ufn2dnW (WLDAP32.@)
267 * Convert a user-friendly name to a DN.
269 * PARAMS
270 * ufn [I] User-friendly name to convert.
271 * dn [O] Receives a pointer to a string containing the DN.
273 * RETURNS
274 * Success: LDAP_SUCCESS
275 * Failure: An LDAP error code.
277 * NOTES
278 * Free the string with ldap_memfree.
280 ULONG ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn )
282 ULONG ret = LDAP_SUCCESS;
283 #ifdef HAVE_LDAP
284 char *ufnU = NULL;
286 TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
288 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
290 *dn = NULL;
292 if (ufn) {
293 ufnU = strWtoU( ufn );
294 if (!ufnU) return WLDAP32_LDAP_NO_MEMORY;
296 /* FIXME: do more than just a copy */
297 *dn = strUtoW( ufnU );
298 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
301 strfreeU( ufnU );
303 #endif
304 return ret;