ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ber.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 <stdarg.h>
00024 #include "windef.h"
00025 #include "winbase.h"
00026 #include "winldap.h"
00027 #include "wine/debug.h"
00028 
00029 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
00030 
00031 #ifndef LBER_ERROR
00032 # define LBER_ERROR (~0U)
00033 #endif
00034 
00035 /***********************************************************************
00036  *      ber_alloc_t     (WLDAP32.@)
00037  *
00038  * Allocate a berelement structure.
00039  *
00040  * PARAMS
00041  *  options [I] Must be LBER_USE_DER.
00042  *
00043  * RETURNS
00044  *  Success: Pointer to an allocated berelement structure.
00045  *  Failure: NULL
00046  *
00047  * NOTES
00048  *  Free the berelement structure with ber_free.
00049  */
00050 BerElement * CDECL WLDAP32_ber_alloc_t( INT options )
00051 {
00052 #ifdef HAVE_LDAP
00053     return ber_alloc_t( options );
00054 #else
00055     return NULL;
00056 #endif
00057 }
00058 
00059 
00060 /***********************************************************************
00061  *      ber_bvdup     (WLDAP32.@)
00062  *
00063  * Copy a berval structure.
00064  *
00065  * PARAMS
00066  *  berval [I] Pointer to the berval structure to be copied.
00067  *
00068  * RETURNS
00069  *  Success: Pointer to a copy of the berval structure.
00070  *  Failure: NULL
00071  *
00072  * NOTES
00073  *  Free the copy with ber_bvfree.
00074  */
00075 BERVAL * CDECL WLDAP32_ber_bvdup( BERVAL *berval )
00076 {
00077 #ifdef HAVE_LDAP
00078     return ber_bvdup( berval );
00079 #else
00080     return NULL;
00081 #endif
00082 }
00083 
00084 
00085 /***********************************************************************
00086  *      ber_bvecfree     (WLDAP32.@)
00087  *
00088  * Free an array of berval structures.
00089  *
00090  * PARAMS
00091  *  berval [I] Pointer to an array of berval structures.
00092  *
00093  * RETURNS
00094  *  Nothing.
00095  *
00096  * NOTES
00097  *  Use this function only to free an array of berval structures
00098  *  returned by a call to ber_scanf with a 'V' in the format string.
00099  */
00100 void CDECL WLDAP32_ber_bvecfree( PBERVAL *berval )
00101 {
00102 #ifdef HAVE_LDAP
00103     ber_bvecfree( berval );
00104 #endif
00105 }
00106 
00107 
00108 /***********************************************************************
00109  *      ber_bvfree     (WLDAP32.@)
00110  *
00111  * Free a berval structure.
00112  *
00113  * PARAMS
00114  *  berval [I] Pointer to a berval structure.
00115  *
00116  * RETURNS
00117  *  Nothing.
00118  *
00119  * NOTES
00120  *  Use this function only to free berval structures allocated by
00121  *  an LDAP API.
00122  */
00123 void CDECL WLDAP32_ber_bvfree( BERVAL *berval )
00124 {
00125 #ifdef HAVE_LDAP
00126     ber_bvfree( berval );
00127 #endif
00128 }
00129 
00130 
00131 /***********************************************************************
00132  *      ber_first_element     (WLDAP32.@)
00133  *
00134  * Return the tag of the first element in a set or sequence.
00135  *
00136  * PARAMS
00137  *  berelement [I] Pointer to a berelement structure.
00138  *  len        [O] Receives the length of the first element.
00139  *  opaque     [O] Receives a pointer to a cookie.
00140  *
00141  * RETURNS
00142  *  Success: Tag of the first element.
00143  *  Failure: LBER_DEFAULT (no more data).
00144  *
00145  * NOTES
00146  *  len and cookie should be passed to ber_next_element.
00147  */
00148 ULONG CDECL WLDAP32_ber_first_element( BerElement *berelement, ULONG *len, CHAR **opaque )
00149 {
00150 #ifdef HAVE_LDAP
00151     return ber_first_element( berelement, len, opaque );
00152 #else
00153     return LBER_ERROR;
00154 #endif
00155 }
00156 
00157 
00158 /***********************************************************************
00159  *      ber_flatten     (WLDAP32.@)
00160  *
00161  * Flatten a berelement structure into a berval structure.
00162  *
00163  * PARAMS
00164  *  berelement [I] Pointer to a berelement structure.
00165  *  berval    [O] Pointer to a berval structure.
00166  *
00167  * RETURNS
00168  *  Success: 0
00169  *  Failure: LBER_ERROR
00170  *
00171  * NOTES
00172  *  Free the berval structure with ber_bvfree.
00173  */
00174 INT CDECL WLDAP32_ber_flatten( BerElement *berelement, PBERVAL *berval )
00175 {
00176 #ifdef HAVE_LDAP
00177     return ber_flatten( berelement, berval );
00178 #else
00179     return LBER_ERROR;
00180 #endif
00181 }
00182 
00183 
00184 /***********************************************************************
00185  *      ber_free     (WLDAP32.@)
00186  *
00187  * Free a berelement structure.
00188  *
00189  * PARAMS
00190  *  berelement [I] Pointer to the berelement structure to be freed.
00191  *  buf       [I] Flag.
00192  *
00193  * RETURNS
00194  *  Nothing.
00195  *
00196  * NOTES
00197  *  Set buf to 0 if the berelement was allocated with ldap_first_attribute
00198  *  or ldap_next_attribute, otherwise set it to 1.
00199  */
00200 void CDECL WLDAP32_ber_free( BerElement *berelement, INT buf )
00201 {
00202 #ifdef HAVE_LDAP
00203     ber_free( berelement, buf );
00204 #endif
00205 }
00206 
00207 
00208 /***********************************************************************
00209  *      ber_init     (WLDAP32.@)
00210  *
00211  * Initialise a berelement structure from a berval structure.
00212  *
00213  * PARAMS
00214  *  berval [I] Pointer to a berval structure.
00215  *
00216  * RETURNS
00217  *  Success: Pointer to a berelement structure.
00218  *  Failure: NULL
00219  *
00220  * NOTES
00221  *  Call ber_free to free the returned berelement structure.
00222  */
00223 BerElement * CDECL WLDAP32_ber_init( BERVAL *berval )
00224 {
00225 #ifdef HAVE_LDAP
00226     return ber_init( berval );
00227 #else
00228     return NULL;
00229 #endif
00230 }
00231 
00232 
00233 /***********************************************************************
00234  *      ber_next_element     (WLDAP32.@)
00235  *
00236  * Return the tag of the next element in a set or sequence.
00237  *
00238  * PARAMS
00239  *  berelement [I]   Pointer to a berelement structure.
00240  *  len        [I/O] Receives the length of the next element.
00241  *  opaque     [I/O] Pointer to a cookie.
00242  *
00243  * RETURNS
00244  *  Success: Tag of the next element.
00245  *  Failure: LBER_DEFAULT (no more data).
00246  *
00247  * NOTES
00248  *  len and cookie are initialized by ber_first_element and should
00249  *  be passed on in subsequent calls to ber_next_element.
00250  */
00251 ULONG CDECL WLDAP32_ber_next_element( BerElement *berelement, ULONG *len, CHAR *opaque )
00252 {
00253 #ifdef HAVE_LDAP
00254     return ber_next_element( berelement, len, opaque );
00255 #else
00256     return LBER_ERROR;
00257 #endif
00258 }
00259 
00260 
00261 /***********************************************************************
00262  *      ber_peek_tag     (WLDAP32.@)
00263  *
00264  * Return the tag of the next element.
00265  *
00266  * PARAMS
00267  *  berelement [I] Pointer to a berelement structure.
00268  *  len        [O] Receives the length of the next element.
00269  *
00270  * RETURNS
00271  *  Success: Tag of the next element.
00272  *  Failure: LBER_DEFAULT (no more data).
00273  */
00274 ULONG CDECL WLDAP32_ber_peek_tag( BerElement *berelement, ULONG *len )
00275 {
00276 #ifdef HAVE_LDAP
00277     return ber_peek_tag( berelement, len );
00278 #else
00279     return LBER_ERROR;
00280 #endif
00281 }
00282 
00283 
00284 /***********************************************************************
00285  *      ber_skip_tag     (WLDAP32.@)
00286  *
00287  * Skip the current tag and return the tag of the next element.
00288  *
00289  * PARAMS
00290  *  berelement [I] Pointer to a berelement structure.
00291  *  len        [O] Receives the length of the skipped element.
00292  *
00293  * RETURNS
00294  *  Success: Tag of the next element.
00295  *  Failure: LBER_DEFAULT (no more data).
00296  */
00297 ULONG CDECL WLDAP32_ber_skip_tag( BerElement *berelement, ULONG *len )
00298 {
00299 #ifdef HAVE_LDAP
00300     return ber_skip_tag( berelement, len );
00301 #else
00302     return LBER_ERROR;
00303 #endif
00304 }
00305 
00306 
00307 /***********************************************************************
00308  *      ber_printf     (WLDAP32.@)
00309  *
00310  * Encode a berelement structure.
00311  *
00312  * PARAMS
00313  *  berelement [I/O] Pointer to a berelement structure.
00314  *  fmt        [I]   Format string.
00315  *  ...        [I]   Values to encode.
00316  *
00317  * RETURNS
00318  *  Success: Non-negative number. 
00319  *  Failure: LBER_ERROR
00320  *
00321  * NOTES
00322  *  berelement must have been allocated with ber_alloc_t. This function
00323  *  can be called multiple times to append data.
00324  */
00325 INT CDECL WLDAP32_ber_printf( BerElement *berelement, PCHAR fmt, ... )
00326 {
00327 #ifdef HAVE_LDAP
00328     __ms_va_list list;
00329     int ret = 0;
00330     char new_fmt[2];
00331 
00332     new_fmt[1] = 0;
00333     __ms_va_start( list, fmt );
00334     while (*fmt)
00335     {
00336         new_fmt[0] = *fmt++;
00337         switch(new_fmt[0])
00338         {
00339         case 'b':
00340         case 'e':
00341         case 'i':
00342             {
00343                 int i = va_arg( list, int );
00344                 ret = ber_printf( berelement, new_fmt, i );
00345                 break;
00346             }
00347         case 'o':
00348         case 's':
00349             {
00350                 char *str = va_arg( list, char * );
00351                 ret = ber_printf( berelement, new_fmt, str );
00352                 break;
00353             }
00354         case 't':
00355             {
00356                 unsigned int tag = va_arg( list, unsigned int );
00357                 ret = ber_printf( berelement, new_fmt, tag );
00358                 break;
00359             }
00360         case 'v':
00361             {
00362                 char **array = va_arg( list, char ** );
00363                 ret = ber_printf( berelement, new_fmt, array );
00364                 break;
00365             }
00366         case 'V':
00367             {
00368                 struct berval **array = va_arg( list, struct berval ** );
00369                 ret = ber_printf( berelement, new_fmt, array );
00370                 break;
00371             }
00372         case 'X':
00373             {
00374                 char *str = va_arg( list, char * );
00375                 int len = va_arg( list, int );
00376                 new_fmt[0] = 'B';  /* 'X' is deprecated */
00377                 ret = ber_printf( berelement, new_fmt, str, len );
00378                 break;
00379             }
00380         case 'n':
00381         case '{':
00382         case '}':
00383         case '[':
00384         case ']':
00385             ret = ber_printf( berelement, new_fmt );
00386             break;
00387         default:
00388             FIXME( "Unknown format '%c'\n", new_fmt[0] );
00389             ret = -1;
00390             break;
00391         }
00392         if (ret == -1) break;
00393     }
00394     __ms_va_end( list );
00395     return ret;
00396 #else
00397     return LBER_ERROR;
00398 #endif
00399 }
00400 
00401 
00402 /***********************************************************************
00403  *      ber_scanf     (WLDAP32.@)
00404  *
00405  * Decode a berelement structure.
00406  *
00407  * PARAMS
00408  *  berelement [I/O] Pointer to a berelement structure.
00409  *  fmt        [I]   Format string.
00410  *  ...        [I]   Pointers to values to be decoded.
00411  *
00412  * RETURNS
00413  *  Success: Non-negative number. 
00414  *  Failure: LBER_ERROR
00415  *
00416  * NOTES
00417  *  berelement must have been allocated with ber_init. This function
00418  *  can be called multiple times to decode data.
00419  */
00420 INT CDECL WLDAP32_ber_scanf( BerElement *berelement, PCHAR fmt, ... )
00421 {
00422 #ifdef HAVE_LDAP
00423     __ms_va_list list;
00424     int ret = 0;
00425     char new_fmt[2];
00426 
00427     new_fmt[1] = 0;
00428     __ms_va_start( list, fmt );
00429     while (*fmt)
00430     {
00431         new_fmt[0] = *fmt++;
00432         switch(new_fmt[0])
00433         {
00434         case 'a':
00435             {
00436                 char **ptr = va_arg( list, char ** );
00437                 ret = ber_scanf( berelement, new_fmt, ptr );
00438                 break;
00439             }
00440         case 'b':
00441         case 'e':
00442         case 'i':
00443             {
00444                 int *i = va_arg( list, int * );
00445                 ret = ber_scanf( berelement, new_fmt, i );
00446                 break;
00447             }
00448         case 't':
00449             {
00450                 unsigned int *tag = va_arg( list, unsigned int * );
00451                 ret = ber_scanf( berelement, new_fmt, tag );
00452                 break;
00453             }
00454         case 'v':
00455             {
00456                 char ***array = va_arg( list, char *** );
00457                 ret = ber_scanf( berelement, new_fmt, array );
00458                 break;
00459             }
00460         case 'B':
00461             {
00462                 char **str = va_arg( list, char ** );
00463                 int *len = va_arg( list, int * );
00464                 ret = ber_scanf( berelement, new_fmt, str, len );
00465                 break;
00466             }
00467         case 'O':
00468             {
00469                 struct berval **ptr = va_arg( list, struct berval ** );
00470                 ret = ber_scanf( berelement, new_fmt, ptr );
00471                 break;
00472             }
00473         case 'V':
00474             {
00475                 struct berval ***array = va_arg( list, struct berval *** );
00476                 ret = ber_scanf( berelement, new_fmt, array );
00477                 break;
00478             }
00479         case 'n':
00480         case 'x':
00481         case '{':
00482         case '}':
00483         case '[':
00484         case ']':
00485             ret = ber_scanf( berelement, new_fmt );
00486             break;
00487         default:
00488             FIXME( "Unknown format '%c'\n", new_fmt[0] );
00489             ret = -1;
00490             break;
00491         }
00492         if (ret == -1) break;
00493     }
00494     __ms_va_end( list );
00495     return ret;
00496 #else
00497     return LBER_ERROR;
00498 #endif
00499 }

Generated on Sat May 26 2012 04:25:33 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.