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
27 #include "wine/debug.h"
28 #include "winldap_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
32 /***********************************************************************
33 * ldap_count_values_len (WLDAP32.@)
35 ULONG CDECL
WLDAP32_ldap_count_values_len( struct WLDAP32_berval
**values
)
38 struct WLDAP32_berval
**ptr
= values
;
40 TRACE( "(%p)\n", values
);
42 if (!values
) return 0;
47 /***********************************************************************
48 * ldap_count_valuesA (WLDAP32.@)
50 ULONG CDECL
ldap_count_valuesA( char **values
)
55 TRACE( "(%p)\n", values
);
57 if (!values
) return 0;
62 /***********************************************************************
63 * ldap_count_valuesW (WLDAP32.@)
65 ULONG CDECL
ldap_count_valuesW( WCHAR
**values
)
70 TRACE( "(%p)\n", values
);
72 if (!values
) return 0;
77 /***********************************************************************
78 * ldap_get_valuesA (WLDAP32.@)
80 char ** CDECL
ldap_get_valuesA( LDAP
*ld
, WLDAP32_LDAPMessage
*entry
, char *attr
)
83 WCHAR
*attrW
= NULL
, **retW
;
85 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_a(attr
) );
87 if (!ld
|| !entry
|| !attr
|| !(attrW
= strAtoW( attr
))) return NULL
;
89 retW
= ldap_get_valuesW( ld
, entry
, attrW
);
90 ret
= strarrayWtoA( retW
);
92 ldap_value_freeW( retW
);
97 static char *bv2str( struct berval
*bv
)
100 unsigned int len
= bv
->bv_len
;
102 if ((str
= malloc( len
+ 1 )))
104 memcpy( str
, bv
->bv_val
, len
);
110 static char **bv2str_array( struct berval
**bv
)
112 unsigned int len
= 0, i
= 0;
113 struct berval
**p
= bv
;
121 if (!(str
= malloc( (len
+ 1) * sizeof(char *) ))) return NULL
;
126 str
[i
] = bv2str( *p
);
129 while (i
> 0) free( str
[--i
] );
140 /***********************************************************************
141 * ldap_get_valuesW (WLDAP32.@)
143 WCHAR
** CDECL
ldap_get_valuesW( LDAP
*ld
, WLDAP32_LDAPMessage
*entry
, WCHAR
*attr
)
149 TRACE( "(%p, %p, %s)\n", ld
, entry
, debugstr_w(attr
) );
151 if (ld
&& entry
&& attr
&& (attrU
= strWtoU( attr
)))
153 if ((bv
= ldap_get_values_len( CTX(ld
), MSG(entry
), attrU
)))
155 retU
= bv2str_array( bv
);
156 ret
= strarrayUtoW( retU
);
158 ldap_value_free_len( bv
);
159 strarrayfreeU( retU
);
166 /***********************************************************************
167 * ldap_get_values_lenA (WLDAP32.@)
169 struct WLDAP32_berval
** CDECL
ldap_get_values_lenA( LDAP
*ld
, LDAPMessage
*message
, char *attr
)
172 struct WLDAP32_berval
**ret
;
174 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_a(attr
) );
176 if (!ld
|| !message
|| !attr
|| !(attrW
= strAtoW( attr
))) return NULL
;
178 ret
= ldap_get_values_lenW( ld
, message
, attrW
);
184 /***********************************************************************
185 * ldap_get_values_lenW (WLDAP32.@)
187 struct WLDAP32_berval
** CDECL
ldap_get_values_lenW( LDAP
*ld
, WLDAP32_LDAPMessage
*message
, WCHAR
*attr
)
190 struct berval
**retU
;
191 struct WLDAP32_berval
**ret
= NULL
;
193 TRACE( "(%p, %p, %s)\n", ld
, message
, debugstr_w(attr
) );
195 if (ld
&& message
&& attr
&& (attrU
= strWtoU( attr
)))
197 if ((retU
= ldap_get_values_len( CTX(ld
), MSG(message
), attrU
)))
199 ret
= bvarrayUtoW( retU
);
200 bvarrayfreeU( retU
);
207 /***********************************************************************
208 * ldap_value_free_len (WLDAP32.@)
210 ULONG CDECL
WLDAP32_ldap_value_free_len( struct WLDAP32_berval
**values
)
212 TRACE( "(%p)\n", values
);
214 bvarrayfreeW( values
);
215 return WLDAP32_LDAP_SUCCESS
;
218 /***********************************************************************
219 * ldap_value_freeA (WLDAP32.@)
221 ULONG CDECL
ldap_value_freeA( char **values
)
223 TRACE( "(%p)\n", values
);
225 strarrayfreeA( values
);
226 return WLDAP32_LDAP_SUCCESS
;
229 /***********************************************************************
230 * ldap_value_freeW (WLDAP32.@)
232 ULONG CDECL
ldap_value_freeW( WCHAR
**values
)
234 TRACE( "(%p)\n", values
);
236 strarrayfreeW( values
);
237 return WLDAP32_LDAP_SUCCESS
;