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
28 #include "wine/debug.h"
29 #include "winldap_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
33 /***********************************************************************
34 * ldap_count_values_len (WLDAP32.@)
36 * Count the number of values in an array of berval structures.
39 * values [I] Pointer to an array of berval structures.
42 * Success: The number of values counted.
46 * Call ldap_count_values_len with the result of a call to
47 * ldap_get_values_len.
49 ULONG CDECL
ldap_count_values_len( struct berval
**values
)
52 struct berval
**ptr
= values
;
54 TRACE( "(%p)\n", values
);
56 if (!values
) return 0;
61 /***********************************************************************
62 * ldap_count_valuesA (WLDAP32.@)
64 * See ldap_count_valuesW.
66 ULONG CDECL
ldap_count_valuesA( char **values
)
71 TRACE( "(%p)\n", values
);
73 if (!values
) return 0;
78 /***********************************************************************
79 * ldap_count_valuesW (WLDAP32.@)
81 * Count the number of values in a string array.
84 * values [I] Pointer to an array of strings.
87 * Success: The number of values counted.
91 * Call ldap_count_valuesW with the result of a call to
94 ULONG CDECL
ldap_count_valuesW( WCHAR
**values
)
99 TRACE( "(%p)\n", values
);
101 if (!values
) return 0;
106 /***********************************************************************
107 * ldap_get_valuesA (WLDAP32.@)
109 * See ldap_get_valuesW.
111 char ** CDECL
ldap_get_valuesA( LDAP
*ld
, LDAPMessage
*entry
, char *attr
)
114 WCHAR
*attrW
= NULL
, **retW
;
116 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_a(attr
) );
118 if (!ld
|| !entry
|| !attr
|| !(attrW
= strAtoW( attr
))) return NULL
;
120 retW
= ldap_get_valuesW( ld
, entry
, attrW
);
121 ret
= strarrayWtoA( retW
);
123 ldap_value_freeW( retW
);
128 static char *bv2str( struct bervalU
*bv
)
131 unsigned int len
= bv
->bv_len
;
133 if ((str
= malloc( len
+ 1 )))
135 memcpy( str
, bv
->bv_val
, len
);
141 static char **bv2str_array( struct bervalU
**bv
)
143 unsigned int len
= 0, i
= 0;
144 struct bervalU
**p
= bv
;
152 if (!(str
= malloc( (len
+ 1) * sizeof(char *) ))) return NULL
;
157 str
[i
] = bv2str( *p
);
160 while (i
> 0) free( str
[--i
] );
171 /***********************************************************************
172 * ldap_get_valuesW (WLDAP32.@)
174 * Retrieve string values for a given attribute.
177 * ld [I] Pointer to an LDAP context.
178 * entry [I] Entry to retrieve values from.
179 * attr [I] Attribute to retrieve values for.
182 * Success: Pointer to a character array holding the values.
186 * Call ldap_get_valuesW with the result of a call to
187 * ldap_first_entry or ldap_next_entry. Free the returned
188 * array with a call to ldap_value_freeW.
190 WCHAR
** CDECL
ldap_get_valuesW( LDAP
*ld
, LDAPMessage
*entry
, WCHAR
*attr
)
196 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_w(attr
) );
198 if (ld
&& entry
&& attr
&& (attrU
= strWtoU( attr
)))
200 struct ldap_get_values_len_params params
= { CTX(ld
), MSG(entry
), attrU
, &bv
};
202 if (!LDAP_CALL( ldap_get_values_len
, ¶ms
))
204 retU
= bv2str_array( bv
);
205 ret
= strarrayUtoW( retU
);
207 LDAP_CALL( ldap_value_free_len
, bv
);
208 strarrayfreeU( retU
);
215 /***********************************************************************
216 * ldap_get_values_lenA (WLDAP32.@)
218 * See ldap_get_values_lenW.
220 struct berval
** CDECL
ldap_get_values_lenA( LDAP
*ld
, LDAPMessage
*message
, char *attr
)
225 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_a(attr
) );
227 if (!ld
|| !message
|| !attr
|| !(attrW
= strAtoW( attr
))) return NULL
;
229 ret
= ldap_get_values_lenW( ld
, message
, attrW
);
235 /***********************************************************************
236 * ldap_get_values_lenW (WLDAP32.@)
238 * Retrieve binary values for a given attribute.
241 * ld [I] Pointer to an LDAP context.
242 * message [I] Entry to retrieve values from.
243 * attr [I] Attribute to retrieve values for.
246 * Success: Pointer to a berval array holding the values.
250 * Call ldap_get_values_lenW with the result of a call to
251 * ldap_first_entry or ldap_next_entry. Free the returned
252 * array with a call to ldap_value_free_len.
254 struct berval
** CDECL
ldap_get_values_lenW( LDAP
*ld
, LDAPMessage
*message
, WCHAR
*attr
)
257 struct bervalU
**retU
;
258 struct berval
**ret
= NULL
;
260 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_w(attr
) );
262 if (ld
&& message
&& attr
&& (attrU
= strWtoU( attr
)))
264 struct ldap_get_values_len_params params
= { CTX(ld
), MSG(message
), attrU
, &retU
};
266 if (!LDAP_CALL( ldap_get_values_len
, ¶ms
))
268 ret
= bvarrayUtoW( retU
);
269 bvarrayfreeU( retU
);
277 /***********************************************************************
278 * ldap_value_free_len (WLDAP32.@)
280 * Free an array of berval structures.
283 * values [I] Array of berval structures.
286 * Success: LDAP_SUCCESS
287 * Failure: An LDAP error code.
289 ULONG CDECL
ldap_value_free_len( struct berval
**values
)
291 TRACE( "(%p)\n", values
);
293 bvarrayfreeW( values
);
297 /***********************************************************************
298 * ldap_value_freeA (WLDAP32.@)
300 * See ldap_value_freeW.
302 ULONG CDECL
ldap_value_freeA( char **values
)
304 TRACE( "(%p)\n", values
);
306 strarrayfreeA( values
);
310 /***********************************************************************
311 * ldap_value_freeW (WLDAP32.@)
313 * Free an array of string values.
316 * values [I] Array of string values.
319 * Success: LDAP_SUCCESS
320 * Failure: An LDAP error code.
322 ULONG CDECL
ldap_value_freeW( WCHAR
**values
)
324 TRACE( "(%p)\n", values
);
326 strarrayfreeW( values
);