windowscodecs: Silence fixme for IID_CMetaBitmapRenderTarget.
[wine.git] / dlls / wldap32 / value.c
blob54addd7ad70d8b58b95d623e3030a524331caf36
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 <stdlib.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnls.h"
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 )
37 ULONG ret = 0;
38 struct WLDAP32_berval **ptr = values;
40 TRACE( "(%p)\n", values );
42 if (!values) return 0;
43 while (*ptr++) ret++;
44 return ret;
47 /***********************************************************************
48 * ldap_count_valuesA (WLDAP32.@)
50 ULONG CDECL ldap_count_valuesA( char **values )
52 ULONG ret = 0;
53 char **ptr = values;
55 TRACE( "(%p)\n", values );
57 if (!values) return 0;
58 while (*ptr++) ret++;
59 return ret;
62 /***********************************************************************
63 * ldap_count_valuesW (WLDAP32.@)
65 ULONG CDECL ldap_count_valuesW( WCHAR **values )
67 ULONG ret = 0;
68 WCHAR **p = values;
70 TRACE( "(%p)\n", values );
72 if (!values) return 0;
73 while (*p++) ret++;
74 return ret;
77 /***********************************************************************
78 * ldap_get_valuesA (WLDAP32.@)
80 char ** CDECL ldap_get_valuesA( LDAP *ld, WLDAP32_LDAPMessage *entry, char *attr )
82 char **ret;
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 );
93 free( attrW );
94 return ret;
97 static char *bv2str( struct berval *bv )
99 char *str = NULL;
100 unsigned int len = bv->bv_len;
102 if ((str = malloc( len + 1 )))
104 memcpy( str, bv->bv_val, len );
105 str[len] = '\0';
107 return str;
110 static char **bv2str_array( struct berval **bv )
112 unsigned int len = 0, i = 0;
113 struct berval **p = bv;
114 char **str;
116 while (*p)
118 len++;
119 p++;
121 if (!(str = malloc( (len + 1) * sizeof(char *) ))) return NULL;
123 p = bv;
124 while (*p)
126 str[i] = bv2str( *p );
127 if (!str[i])
129 while (i > 0) free( str[--i] );
130 free( str );
131 return NULL;
133 i++;
134 p++;
136 str[i] = NULL;
137 return str;
140 /***********************************************************************
141 * ldap_get_valuesW (WLDAP32.@)
143 WCHAR ** CDECL ldap_get_valuesW( LDAP *ld, WLDAP32_LDAPMessage *entry, WCHAR *attr )
145 WCHAR **ret = NULL;
146 char *attrU, **retU;
147 struct berval **bv;
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 );
161 free( attrU );
163 return ret;
166 /***********************************************************************
167 * ldap_get_values_lenA (WLDAP32.@)
169 struct WLDAP32_berval ** CDECL ldap_get_values_lenA( LDAP *ld, LDAPMessage *message, char *attr )
171 WCHAR *attrW;
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 );
180 free( attrW );
181 return ret;
184 /***********************************************************************
185 * ldap_get_values_lenW (WLDAP32.@)
187 struct WLDAP32_berval ** CDECL ldap_get_values_lenW( LDAP *ld, WLDAP32_LDAPMessage *message, WCHAR *attr )
189 char *attrU = NULL;
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 );
202 free( attrU );
204 return ret;
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;