winspool/tests: Add tests for GetFormA().
[wine.git] / dlls / wldap32 / dn.c
blob1528d8aef1e3093134df8e3687b34b2e88f902aa
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_dn2ufnA (WLDAP32.@)
35 * See ldap_dn2ufnW.
37 char * CDECL ldap_dn2ufnA( char *dn )
39 char *ret;
40 WCHAR *dnW, *retW;
42 TRACE( "(%s)\n", debugstr_a(dn) );
44 if (!(dnW = strAtoW( dn ))) return NULL;
46 retW = ldap_dn2ufnW( dnW );
47 ret = strWtoA( retW );
49 free( dnW );
50 ldap_memfreeW( retW );
51 return ret;
54 /***********************************************************************
55 * ldap_dn2ufnW (WLDAP32.@)
57 * Convert a DN to a user-friendly name.
59 * PARAMS
60 * dn [I] DN to convert.
62 * RETURNS
63 * Success: Pointer to a string containing the user-friendly name.
64 * Failure: NULL
66 * NOTES
67 * Free the string with ldap_memfree.
69 WCHAR * CDECL ldap_dn2ufnW( WCHAR *dn )
71 WCHAR *ret;
72 char *dnU, *retU;
74 TRACE( "(%s)\n", debugstr_w(dn) );
76 if (!(dnU = strWtoU( dn ))) return NULL;
78 retU = ldap_funcs->fn_ldap_dn2ufn( dnU );
79 ret = strUtoW( retU );
81 free( dnU );
82 ldap_funcs->fn_ldap_memfree( retU );
83 return ret;
86 /***********************************************************************
87 * ldap_explode_dnA (WLDAP32.@)
89 * See ldap_explode_dnW.
91 char ** CDECL ldap_explode_dnA( char *dn, ULONG notypes )
93 char **ret;
94 WCHAR *dnW, **retW;
96 TRACE( "(%s, 0x%08x)\n", debugstr_a(dn), notypes );
98 if (!(dnW = strAtoW( dn ))) return NULL;
100 retW = ldap_explode_dnW( dnW, notypes );
101 ret = strarrayWtoA( retW );
103 free( dnW );
104 ldap_value_freeW( retW );
105 return ret;
108 /***********************************************************************
109 * ldap_explode_dnW (WLDAP32.@)
111 * Break up a DN into its components.
113 * PARAMS
114 * dn [I] DN to break up.
115 * notypes [I] Remove attribute type information from the components.
117 * RETURNS
118 * Success: Pointer to a NULL-terminated array that contains the DN
119 * components.
120 * Failure: NULL
122 * NOTES
123 * Free the string array with ldap_value_free.
125 WCHAR ** CDECL ldap_explode_dnW( WCHAR *dn, ULONG notypes )
127 WCHAR **ret;
128 char *dnU, **retU;
130 TRACE( "(%s, 0x%08x)\n", debugstr_w(dn), notypes );
132 if (!(dnU = strWtoU( dn ))) return NULL;
134 retU = ldap_funcs->fn_ldap_explode_dn( dnU, notypes );
135 ret = strarrayUtoW( retU );
137 free( dnU );
138 ldap_funcs->fn_ldap_memvfree( (void **)retU );
139 return ret;
142 /***********************************************************************
143 * ldap_get_dnA (WLDAP32.@)
145 * See ldap_get_dnW.
147 char * CDECL ldap_get_dnA( LDAP *ld, LDAPMessage *entry )
149 char *ret;
150 WCHAR *retW;
152 TRACE( "(%p, %p)\n", ld, entry );
154 if (!ld || !entry) return NULL;
156 retW = ldap_get_dnW( ld, entry );
158 ret = strWtoA( retW );
159 ldap_memfreeW( retW );
160 return ret;
163 /***********************************************************************
164 * ldap_get_dnW (WLDAP32.@)
166 * Retrieve the DN from a given LDAP message.
168 * PARAMS
169 * ld [I] Pointer to an LDAP context.
170 * entry [I] LDAPMessage structure to retrieve the DN from.
172 * RETURNS
173 * Success: Pointer to a string that contains the DN.
174 * Failure: NULL
176 * NOTES
177 * Free the string with ldap_memfree.
179 WCHAR * CDECL ldap_get_dnW( LDAP *ld, LDAPMessage *entry )
181 WCHAR *ret;
182 char *retU;
184 TRACE( "(%p, %p)\n", ld, entry );
186 if (!ld || !entry) return NULL;
188 retU = ldap_funcs->fn_ldap_get_dn( CTX(ld), MSG(entry) );
190 ret = strUtoW( retU );
191 ldap_funcs->fn_ldap_memfree( retU );
192 return ret;
195 /***********************************************************************
196 * ldap_ufn2dnA (WLDAP32.@)
198 * See ldap_ufn2dnW.
200 ULONG CDECL ldap_ufn2dnA( char *ufn, char **dn )
202 ULONG ret;
203 WCHAR *ufnW = NULL, *dnW = NULL;
205 TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
207 if (!dn) return LDAP_PARAM_ERROR;
209 *dn = NULL;
210 if (ufn && !(ufnW = strAtoW( ufn ))) return LDAP_NO_MEMORY;
212 ret = ldap_ufn2dnW( ufnW, &dnW );
213 if (dnW)
215 char *str;
216 if (!(str = strWtoA( dnW ))) ret = LDAP_NO_MEMORY;
217 else *dn = str;
220 free( ufnW );
221 ldap_memfreeW( dnW );
222 return ret;
225 /***********************************************************************
226 * ldap_ufn2dnW (WLDAP32.@)
228 * Convert a user-friendly name to a DN.
230 * PARAMS
231 * ufn [I] User-friendly name to convert.
232 * dn [O] Receives a pointer to a string containing the DN.
234 * RETURNS
235 * Success: LDAP_SUCCESS
236 * Failure: An LDAP error code.
238 * NOTES
239 * Free the string with ldap_memfree.
241 ULONG CDECL ldap_ufn2dnW( WCHAR *ufn, WCHAR **dn )
243 ULONG ret = LDAP_SUCCESS;
244 char *ufnU = NULL;
246 TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
248 if (!dn) return LDAP_PARAM_ERROR;
250 *dn = NULL;
251 if (ufn)
253 WCHAR *str;
254 if (!(ufnU = strWtoU( ufn ))) return LDAP_NO_MEMORY;
256 /* FIXME: do more than just a copy */
257 if (!(str = strUtoW( ufnU ))) ret = LDAP_NO_MEMORY;
258 else *dn = str;
261 free( ufnU );
262 return ret;