d2d1: Create feature level 10.0 device context state objects.
[wine.git] / dlls / wldap32 / dn.c
blob40e62fafa1ed2b1e114f9cdd3f836841328e6c57
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 = NULL;
72 char *dnU, *retU;
74 TRACE( "(%s)\n", debugstr_w(dn) );
76 if ((dnU = strWtoU( dn )))
78 struct ldap_dn2ufn_params params = { dnU, &retU };
79 LDAP_CALL( ldap_dn2ufn, &params );
81 ret = strUtoW( retU );
83 free( dnU );
84 LDAP_CALL( ldap_memfree, retU );
86 return ret;
89 /***********************************************************************
90 * ldap_explode_dnA (WLDAP32.@)
92 * See ldap_explode_dnW.
94 char ** CDECL ldap_explode_dnA( char *dn, ULONG notypes )
96 char **ret;
97 WCHAR *dnW, **retW;
99 TRACE( "(%s, 0x%08x)\n", debugstr_a(dn), notypes );
101 if (!(dnW = strAtoW( dn ))) return NULL;
103 retW = ldap_explode_dnW( dnW, notypes );
104 ret = strarrayWtoA( retW );
106 free( dnW );
107 ldap_value_freeW( retW );
108 return ret;
111 /***********************************************************************
112 * ldap_explode_dnW (WLDAP32.@)
114 * Break up a DN into its components.
116 * PARAMS
117 * dn [I] DN to break up.
118 * notypes [I] Remove attribute type information from the components.
120 * RETURNS
121 * Success: Pointer to a NULL-terminated array that contains the DN
122 * components.
123 * Failure: NULL
125 * NOTES
126 * Free the string array with ldap_value_free.
128 WCHAR ** CDECL ldap_explode_dnW( WCHAR *dn, ULONG notypes )
130 WCHAR **ret = NULL;
131 char *dnU, **retU;
133 TRACE( "(%s, 0x%08x)\n", debugstr_w(dn), notypes );
135 if ((dnU = strWtoU( dn )))
137 struct ldap_explode_dn_params params = { dnU, notypes, &retU };
138 LDAP_CALL( ldap_explode_dn, &params );
139 ret = strarrayUtoW( retU );
141 free( dnU );
142 LDAP_CALL( ldap_memvfree, retU );
144 return ret;
147 /***********************************************************************
148 * ldap_get_dnA (WLDAP32.@)
150 * See ldap_get_dnW.
152 char * CDECL ldap_get_dnA( LDAP *ld, LDAPMessage *entry )
154 char *ret;
155 WCHAR *retW;
157 TRACE( "(%p, %p)\n", ld, entry );
159 if (!ld || !entry) return NULL;
161 retW = ldap_get_dnW( ld, entry );
163 ret = strWtoA( retW );
164 ldap_memfreeW( retW );
165 return ret;
168 /***********************************************************************
169 * ldap_get_dnW (WLDAP32.@)
171 * Retrieve the DN from a given LDAP message.
173 * PARAMS
174 * ld [I] Pointer to an LDAP context.
175 * entry [I] LDAPMessage structure to retrieve the DN from.
177 * RETURNS
178 * Success: Pointer to a string that contains the DN.
179 * Failure: NULL
181 * NOTES
182 * Free the string with ldap_memfree.
184 WCHAR * CDECL ldap_get_dnW( LDAP *ld, LDAPMessage *entry )
186 WCHAR *ret = NULL;
187 char *retU;
189 TRACE( "(%p, %p)\n", ld, entry );
191 if (ld && entry)
193 struct ldap_get_dn_params params = { CTX(ld), MSG(entry), &retU };
194 LDAP_CALL( ldap_get_dn, &params );
196 ret = strUtoW( retU );
197 LDAP_CALL( ldap_memfree, retU );
199 return ret;
202 /***********************************************************************
203 * ldap_ufn2dnA (WLDAP32.@)
205 * See ldap_ufn2dnW.
207 ULONG CDECL ldap_ufn2dnA( char *ufn, char **dn )
209 ULONG ret;
210 WCHAR *ufnW = NULL, *dnW = NULL;
212 TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
214 if (!dn) return LDAP_PARAM_ERROR;
216 *dn = NULL;
217 if (ufn && !(ufnW = strAtoW( ufn ))) return LDAP_NO_MEMORY;
219 ret = ldap_ufn2dnW( ufnW, &dnW );
220 if (dnW)
222 char *str;
223 if (!(str = strWtoA( dnW ))) ret = LDAP_NO_MEMORY;
224 else *dn = str;
227 free( ufnW );
228 ldap_memfreeW( dnW );
229 return ret;
232 /***********************************************************************
233 * ldap_ufn2dnW (WLDAP32.@)
235 * Convert a user-friendly name to a DN.
237 * PARAMS
238 * ufn [I] User-friendly name to convert.
239 * dn [O] Receives a pointer to a string containing the DN.
241 * RETURNS
242 * Success: LDAP_SUCCESS
243 * Failure: An LDAP error code.
245 * NOTES
246 * Free the string with ldap_memfree.
248 ULONG CDECL ldap_ufn2dnW( WCHAR *ufn, WCHAR **dn )
250 ULONG ret = LDAP_SUCCESS;
251 char *ufnU = NULL;
253 TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
255 if (!dn) return LDAP_PARAM_ERROR;
257 *dn = NULL;
258 if (ufn)
260 WCHAR *str;
261 if (!(ufnU = strWtoU( ufn ))) return LDAP_NO_MEMORY;
263 /* FIXME: do more than just a copy */
264 if (!(str = strUtoW( ufnU ))) ret = LDAP_NO_MEMORY;
265 else *dn = str;
268 free( ufnU );
269 return ret;