Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenvalue.c
Go to the documentation of this file.
00001 /* 00002 * WLDAP32 - LDAP support for Wine 00003 * 00004 * Copyright 2005 Hans Leidekker 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include "config.h" 00022 00023 #include "wine/port.h" 00024 #include "wine/debug.h" 00025 00026 #include <stdarg.h> 00027 00028 #include "windef.h" 00029 #include "winbase.h" 00030 #include "winnls.h" 00031 00032 #ifdef HAVE_LDAP_H 00033 #include <ldap.h> 00034 #endif 00035 00036 #include "winldap_private.h" 00037 #include "wldap32.h" 00038 00039 WINE_DEFAULT_DEBUG_CHANNEL(wldap32); 00040 00041 /*********************************************************************** 00042 * ldap_count_values_len (WLDAP32.@) 00043 * 00044 * Count the number of values in an array of berval structures. 00045 * 00046 * PARAMS 00047 * vals [I] Pointer to an array of berval structures. 00048 * 00049 * RETURNS 00050 * Success: The number of values counted. 00051 * Failure: 0 00052 * 00053 * NOTES 00054 * Call ldap_count_values_len with the result of a call to 00055 * ldap_get_values_len. 00056 */ 00057 ULONG CDECL WLDAP32_ldap_count_values_len( struct WLDAP32_berval **vals ) 00058 { 00059 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 00060 #ifdef HAVE_LDAP 00061 00062 TRACE( "(%p)\n", vals ); 00063 ret = ldap_count_values_len( (struct berval **)vals ); 00064 00065 #endif 00066 return ret; 00067 } 00068 00069 /*********************************************************************** 00070 * ldap_count_valuesA (WLDAP32.@) 00071 * 00072 * See ldap_count_valuesW. 00073 */ 00074 ULONG CDECL ldap_count_valuesA( PCHAR *vals ) 00075 { 00076 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 00077 #ifdef HAVE_LDAP 00078 WCHAR **valsW = NULL; 00079 00080 TRACE( "(%p)\n", vals ); 00081 00082 if (!vals) return 0; 00083 00084 valsW = strarrayAtoW( vals ); 00085 if (!valsW) return WLDAP32_LDAP_NO_MEMORY; 00086 00087 ret = ldap_count_valuesW( valsW ); 00088 strarrayfreeW( valsW ); 00089 00090 #endif 00091 return ret; 00092 } 00093 00094 /*********************************************************************** 00095 * ldap_count_valuesW (WLDAP32.@) 00096 * 00097 * Count the number of values in a string array. 00098 * 00099 * PARAMS 00100 * vals [I] Pointer to an array of strings. 00101 * 00102 * RETURNS 00103 * Success: The number of values counted. 00104 * Failure: 0 00105 * 00106 * NOTES 00107 * Call ldap_count_valuesW with the result of a call to 00108 * ldap_get_valuesW. 00109 */ 00110 ULONG CDECL ldap_count_valuesW( PWCHAR *vals ) 00111 { 00112 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; 00113 #ifdef HAVE_LDAP 00114 WCHAR **p = vals; 00115 00116 TRACE( "(%p)\n", vals ); 00117 00118 if (!vals) return 0; 00119 00120 ret = 0; 00121 while (*p++) ret++; 00122 00123 #endif 00124 return ret; 00125 } 00126 00127 /*********************************************************************** 00128 * ldap_get_valuesA (WLDAP32.@) 00129 * 00130 * See ldap_get_valuesW. 00131 */ 00132 PCHAR * CDECL ldap_get_valuesA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PCHAR attr ) 00133 { 00134 PCHAR *ret = NULL; 00135 #ifdef HAVE_LDAP 00136 WCHAR *attrW = NULL, **retW; 00137 00138 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_a(attr) ); 00139 00140 if (!ld || !entry || !attr) return NULL; 00141 00142 attrW = strAtoW( attr ); 00143 if (!attrW) return NULL; 00144 00145 retW = ldap_get_valuesW( ld, entry, attrW ); 00146 00147 ret = strarrayWtoA( retW ); 00148 ldap_value_freeW( retW ); 00149 strfreeW( attrW ); 00150 00151 #endif 00152 return ret; 00153 } 00154 00155 #ifdef HAVE_LDAP 00156 static char *bv2str( struct berval *bv ) 00157 { 00158 char *str = NULL; 00159 unsigned int len = bv->bv_len; 00160 00161 str = HeapAlloc( GetProcessHeap(), 0, len + 1 ); 00162 if (str) 00163 { 00164 memcpy( str, bv->bv_val, len ); 00165 str[len] = '\0'; 00166 } 00167 return str; 00168 } 00169 00170 static char **bv2str_array( struct berval **bv ) 00171 { 00172 unsigned int len = 0, i = 0; 00173 struct berval **p = bv; 00174 char **str; 00175 00176 while (*p) 00177 { 00178 len++; 00179 p++; 00180 } 00181 str = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(char *) ); 00182 if (!str) return NULL; 00183 00184 p = bv; 00185 while (*p) 00186 { 00187 str[i] = bv2str( *p ); 00188 if (!str[i]) 00189 { 00190 while (i > 0) HeapFree( GetProcessHeap(), 0, str[--i] ); 00191 HeapFree( GetProcessHeap(), 0, str ); 00192 return NULL; 00193 } 00194 i++; 00195 p++; 00196 } 00197 str[i] = NULL; 00198 return str; 00199 } 00200 #endif 00201 00202 /*********************************************************************** 00203 * ldap_get_valuesW (WLDAP32.@) 00204 * 00205 * Retrieve string values for a given attribute. 00206 * 00207 * PARAMS 00208 * ld [I] Pointer to an LDAP context. 00209 * entry [I] Entry to retrieve values from. 00210 * attr [I] Attribute to retrieve values for. 00211 * 00212 * RETURNS 00213 * Success: Pointer to a character array holding the values. 00214 * Failure: NULL 00215 * 00216 * NOTES 00217 * Call ldap_get_valuesW with the result of a call to 00218 * ldap_first_entry or ldap_next_entry. Free the returned 00219 * array with a call to ldap_value_freeW. 00220 */ 00221 PWCHAR * CDECL ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr ) 00222 { 00223 PWCHAR *ret = NULL; 00224 #ifdef HAVE_LDAP 00225 char *attrU = NULL, **retU; 00226 struct berval **bv; 00227 00228 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) ); 00229 00230 if (!ld || !entry || !attr) return NULL; 00231 00232 attrU = strWtoU( attr ); 00233 if (!attrU) return NULL; 00234 00235 bv = ldap_get_values_len( ld, entry, attrU ); 00236 00237 retU = bv2str_array( bv ); 00238 ret = strarrayUtoW( retU ); 00239 00240 ldap_value_free_len( bv ); 00241 strarrayfreeU( retU ); 00242 strfreeU( attrU ); 00243 00244 #endif 00245 return ret; 00246 } 00247 00248 /*********************************************************************** 00249 * ldap_get_values_lenA (WLDAP32.@) 00250 * 00251 * See ldap_get_values_lenW. 00252 */ 00253 struct WLDAP32_berval ** CDECL ldap_get_values_lenA( WLDAP32_LDAP *ld, 00254 WLDAP32_LDAPMessage *message, PCHAR attr ) 00255 { 00256 #ifdef HAVE_LDAP 00257 WCHAR *attrW = NULL; 00258 struct WLDAP32_berval **ret; 00259 00260 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) ); 00261 00262 if (!ld || !message || !attr) return NULL; 00263 00264 attrW = strAtoW( attr ); 00265 if (!attrW) return NULL; 00266 00267 ret = ldap_get_values_lenW( ld, message, attrW ); 00268 00269 strfreeW( attrW ); 00270 return ret; 00271 00272 #else 00273 return NULL; 00274 #endif 00275 } 00276 00277 /*********************************************************************** 00278 * ldap_get_values_lenW (WLDAP32.@) 00279 * 00280 * Retrieve binary values for a given attribute. 00281 * 00282 * PARAMS 00283 * ld [I] Pointer to an LDAP context. 00284 * message [I] Entry to retrieve values from. 00285 * attr [I] Attribute to retrieve values for. 00286 * 00287 * RETURNS 00288 * Success: Pointer to a berval array holding the values. 00289 * Failure: NULL 00290 * 00291 * NOTES 00292 * Call ldap_get_values_lenW with the result of a call to 00293 * ldap_first_entry or ldap_next_entry. Free the returned 00294 * array with a call to ldap_value_free_len. 00295 */ 00296 struct WLDAP32_berval ** CDECL ldap_get_values_lenW( WLDAP32_LDAP *ld, 00297 WLDAP32_LDAPMessage *message, PWCHAR attr ) 00298 { 00299 #ifdef HAVE_LDAP 00300 char *attrU = NULL; 00301 struct berval **ret; 00302 00303 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) ); 00304 00305 if (!ld || !message || !attr) return NULL; 00306 00307 attrU = strWtoU( attr ); 00308 if (!attrU) return NULL; 00309 00310 ret = ldap_get_values_len( ld, message, attrU ); 00311 00312 strfreeU( attrU ); 00313 return (struct WLDAP32_berval **)ret; 00314 00315 #else 00316 return NULL; 00317 #endif 00318 } 00319 00320 /*********************************************************************** 00321 * ldap_value_free_len (WLDAP32.@) 00322 * 00323 * Free an array of berval structures. 00324 * 00325 * PARAMS 00326 * vals [I] Array of berval structures. 00327 * 00328 * RETURNS 00329 * Success: LDAP_SUCCESS 00330 * Failure: An LDAP error code. 00331 */ 00332 ULONG CDECL WLDAP32_ldap_value_free_len( struct WLDAP32_berval **vals ) 00333 { 00334 #ifdef HAVE_LDAP 00335 00336 TRACE( "(%p)\n", vals ); 00337 ldap_value_free_len( (struct berval **)vals ); 00338 00339 #endif 00340 return WLDAP32_LDAP_SUCCESS; 00341 } 00342 00343 /*********************************************************************** 00344 * ldap_value_freeA (WLDAP32.@) 00345 * 00346 * See ldap_value_freeW. 00347 */ 00348 ULONG CDECL ldap_value_freeA( PCHAR *vals ) 00349 { 00350 TRACE( "(%p)\n", vals ); 00351 00352 strarrayfreeA( vals ); 00353 return WLDAP32_LDAP_SUCCESS; 00354 } 00355 00356 /*********************************************************************** 00357 * ldap_value_freeW (WLDAP32.@) 00358 * 00359 * Free an array of string values. 00360 * 00361 * PARAMS 00362 * vals [I] Array of string values. 00363 * 00364 * RETURNS 00365 * Success: LDAP_SUCCESS 00366 * Failure: An LDAP error code. 00367 */ 00368 ULONG CDECL ldap_value_freeW( PWCHAR *vals ) 00369 { 00370 TRACE( "(%p)\n", vals ); 00371 00372 strarrayfreeW( vals ); 00373 return WLDAP32_LDAP_SUCCESS; 00374 } Generated on Sat May 26 2012 04:25:36 for ReactOS by
1.7.6.1
|