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

wldap32.h
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 ULONG map_error( int );
00022 
00023 /* A set of helper functions to convert LDAP data structures
00024  * to and from ansi (A), wide character (W) and utf8 (U) encodings.
00025  */
00026 
00027 static inline char *strdupU( const char *src )
00028 {
00029     char *dst;
00030 
00031     if (!src) return NULL;
00032     dst = HeapAlloc( GetProcessHeap(), 0, (strlen( src ) + 1) * sizeof(char) );
00033     if (dst)
00034         strcpy( dst, src );
00035     return dst;
00036 }
00037 
00038 static inline LPWSTR strAtoW( LPCSTR str )
00039 {
00040     LPWSTR ret = NULL;
00041     if (str)
00042     {
00043         DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
00044         if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
00045             MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
00046     }
00047     return ret;
00048 }
00049 
00050 static inline LPSTR strWtoA( LPCWSTR str )
00051 {
00052     LPSTR ret = NULL;
00053     if (str)
00054     {
00055         DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
00056         if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
00057             WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
00058     }
00059     return ret;
00060 }
00061 
00062 static inline char *strWtoU( LPCWSTR str )
00063 {
00064     LPSTR ret = NULL;
00065     if (str)
00066     {
00067         DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
00068         if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
00069             WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
00070     }
00071     return ret;
00072 }
00073 
00074 static inline LPWSTR strUtoW( char *str )
00075 {
00076     LPWSTR ret = NULL;
00077     if (str)
00078     {
00079         DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
00080         if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
00081             MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
00082     }
00083     return ret;
00084 }
00085 
00086 static inline void strfreeA( LPSTR str )
00087 {
00088     HeapFree( GetProcessHeap(), 0, str );
00089 }
00090 
00091 static inline void strfreeW( LPWSTR str )
00092 {
00093     HeapFree( GetProcessHeap(), 0, str );
00094 }
00095 
00096 static inline void strfreeU( char *str )
00097 {
00098     HeapFree( GetProcessHeap(), 0, str );
00099 }
00100 
00101 static inline DWORD strarraylenA( LPSTR *strarray )
00102 {
00103     LPSTR *p = strarray;
00104     while (*p) p++;
00105     return p - strarray;
00106 }
00107 
00108 static inline DWORD strarraylenW( LPWSTR *strarray )
00109 {
00110     LPWSTR *p = strarray;
00111     while (*p) p++;
00112     return p - strarray;
00113 }
00114 
00115 static inline DWORD strarraylenU( char **strarray )
00116 {
00117     char **p = strarray;
00118     while (*p) p++;
00119     return p - strarray;
00120 }
00121 
00122 static inline LPWSTR *strarrayAtoW( LPSTR *strarray )
00123 {
00124     LPWSTR *strarrayW = NULL;
00125     DWORD size;
00126 
00127     if (strarray)
00128     {
00129         size  = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1);
00130         strarrayW = HeapAlloc( GetProcessHeap(), 0, size );
00131 
00132         if (strarrayW)
00133         {
00134             LPSTR *p = strarray;
00135             LPWSTR *q = strarrayW;
00136 
00137             while (*p) *q++ = strAtoW( *p++ );
00138             *q = NULL;
00139         }
00140     }
00141     return strarrayW;
00142 }
00143 
00144 static inline LPSTR *strarrayWtoA( LPWSTR *strarray )
00145 {
00146     LPSTR *strarrayA = NULL;
00147     DWORD size;
00148 
00149     if (strarray)
00150     {
00151         size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1);
00152         strarrayA = HeapAlloc( GetProcessHeap(), 0, size );
00153 
00154         if (strarrayA)
00155         {
00156             LPWSTR *p = strarray;
00157             LPSTR *q = strarrayA;
00158 
00159             while (*p) *q++ = strWtoA( *p++ );
00160             *q = NULL;
00161         }
00162     }
00163     return strarrayA;
00164 }
00165 
00166 static inline char **strarrayWtoU( LPWSTR *strarray )
00167 {
00168     char **strarrayU = NULL;
00169     DWORD size;
00170 
00171     if (strarray)
00172     {
00173         size = sizeof(char*) * (strarraylenW( strarray ) + 1);
00174         strarrayU = HeapAlloc( GetProcessHeap(), 0, size );
00175 
00176         if (strarrayU)
00177         {
00178             LPWSTR *p = strarray;
00179             char **q = strarrayU;
00180 
00181             while (*p) *q++ = strWtoU( *p++ );
00182             *q = NULL;
00183         }
00184     }
00185     return strarrayU;
00186 }
00187 
00188 static inline LPWSTR *strarrayUtoW( char **strarray )
00189 {
00190     LPWSTR *strarrayW = NULL;
00191     DWORD size;
00192 
00193     if (strarray)
00194     {
00195         size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1);
00196         strarrayW = HeapAlloc( GetProcessHeap(), 0, size );
00197 
00198         if (strarrayW)
00199         {
00200             char **p = strarray;
00201             LPWSTR *q = strarrayW;
00202 
00203             while (*p) *q++ = strUtoW( *p++ );
00204             *q = NULL;
00205         }
00206     }
00207     return strarrayW;
00208 }
00209 
00210 static inline void strarrayfreeA( LPSTR *strarray )
00211 {
00212     if (strarray)
00213     {
00214         LPSTR *p = strarray;
00215         while (*p) strfreeA( *p++ );
00216         HeapFree( GetProcessHeap(), 0, strarray );
00217     }
00218 }
00219 
00220 static inline void strarrayfreeW( LPWSTR *strarray )
00221 {
00222     if (strarray)
00223     {
00224         LPWSTR *p = strarray;
00225         while (*p) strfreeW( *p++ );
00226         HeapFree( GetProcessHeap(), 0, strarray );
00227     }
00228 }
00229 
00230 static inline void strarrayfreeU( char **strarray )
00231 {
00232     if (strarray)
00233     {
00234         char **p = strarray;
00235         while (*p) strfreeU( *p++ );
00236         HeapFree( GetProcessHeap(), 0, strarray );
00237     }
00238 }
00239 
00240 #ifdef HAVE_LDAP
00241 
00242 static inline struct berval *bvdup( struct berval *bv )
00243 {
00244     struct berval *berval;
00245     DWORD size = sizeof(struct berval) + bv->bv_len;
00246 
00247     berval = HeapAlloc( GetProcessHeap(), 0, size );
00248     if (berval)
00249     {
00250         char *val = (char *)berval + sizeof(struct berval);
00251 
00252         berval->bv_len = bv->bv_len;
00253         berval->bv_val = val;
00254         memcpy( val, bv->bv_val, bv->bv_len );
00255     }
00256     return berval;
00257 }
00258 
00259 static inline DWORD bvarraylen( struct berval **bv )
00260 {
00261     struct berval **p = bv;
00262     while (*p) p++;
00263     return p - bv;
00264 }
00265 
00266 static inline struct berval **bvarraydup( struct berval **bv )
00267 {
00268     struct berval **berval = NULL;
00269     DWORD size;
00270 
00271     if (bv)
00272     {
00273         size = sizeof(struct berval *) * (bvarraylen( bv ) + 1);
00274         berval = HeapAlloc( GetProcessHeap(), 0, size );
00275 
00276         if (berval)
00277         {
00278             struct berval **p = bv;
00279             struct berval **q = berval;
00280 
00281             while (*p) *q++ = bvdup( *p++ );
00282             *q = NULL;
00283         }
00284     }
00285     return berval;
00286 }
00287 
00288 static inline void bvarrayfree( struct berval **bv )
00289 {
00290     struct berval **p = bv;
00291     while (*p) HeapFree( GetProcessHeap(), 0, *p++ );
00292     HeapFree( GetProcessHeap(), 0, bv );
00293 }
00294 
00295 static inline LDAPModW *modAtoW( LDAPModA *mod )
00296 {
00297     LDAPModW *modW;
00298 
00299     modW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPModW) );
00300     if (modW)
00301     {
00302         modW->mod_op = mod->mod_op;
00303         modW->mod_type = strAtoW( mod->mod_type );
00304 
00305         if (mod->mod_op & LDAP_MOD_BVALUES)
00306             modW->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
00307         else
00308             modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
00309     }
00310     return modW;
00311 }
00312 
00313 static inline LDAPMod *modWtoU( LDAPModW *mod )
00314 {
00315     LDAPMod *modU;
00316 
00317     modU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPMod) );
00318     if (modU)
00319     {
00320         modU->mod_op = mod->mod_op;
00321         modU->mod_type = strWtoU( mod->mod_type );
00322 
00323         if (mod->mod_op & LDAP_MOD_BVALUES)
00324             modU->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
00325         else
00326             modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
00327     }
00328     return modU;
00329 }
00330 
00331 static inline void modfreeW( LDAPModW *mod )
00332 {
00333     if (mod->mod_op & LDAP_MOD_BVALUES)
00334         bvarrayfree( mod->mod_vals.modv_bvals );
00335     else
00336         strarrayfreeW( mod->mod_vals.modv_strvals );
00337     HeapFree( GetProcessHeap(), 0, mod );
00338 }
00339 
00340 static inline void modfreeU( LDAPMod *mod )
00341 {
00342     if (mod->mod_op & LDAP_MOD_BVALUES)
00343         bvarrayfree( mod->mod_vals.modv_bvals );
00344     else
00345         strarrayfreeU( mod->mod_vals.modv_strvals );
00346     HeapFree( GetProcessHeap(), 0, mod );
00347 }
00348 
00349 static inline DWORD modarraylenA( LDAPModA **modarray )
00350 {
00351     LDAPModA **p = modarray;
00352     while (*p) p++;
00353     return p - modarray;
00354 }
00355 
00356 static inline DWORD modarraylenW( LDAPModW **modarray )
00357 {
00358     LDAPModW **p = modarray;
00359     while (*p) p++;
00360     return p - modarray;
00361 }
00362 
00363 static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
00364 {
00365     LDAPModW **modarrayW = NULL;
00366     DWORD size;
00367 
00368     if (modarray)
00369     {
00370         size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1);
00371         modarrayW = HeapAlloc( GetProcessHeap(), 0, size );
00372 
00373         if (modarrayW)
00374         {
00375             LDAPModA **p = modarray;
00376             LDAPModW **q = modarrayW;
00377 
00378             while (*p) *q++ = modAtoW( *p++ );
00379             *q = NULL;
00380         }
00381     }
00382     return modarrayW;
00383 }
00384 
00385 static inline LDAPMod **modarrayWtoU( LDAPModW **modarray )
00386 {
00387     LDAPMod **modarrayU = NULL;
00388     DWORD size;
00389 
00390     if (modarray)
00391     {
00392         size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1);
00393         modarrayU = HeapAlloc( GetProcessHeap(), 0, size );
00394 
00395         if (modarrayU)
00396         {
00397             LDAPModW **p = modarray;
00398             LDAPMod **q = modarrayU;
00399 
00400             while (*p) *q++ = modWtoU( *p++ );
00401             *q = NULL;
00402         }
00403     }
00404     return modarrayU;
00405 }
00406 
00407 static inline void modarrayfreeW( LDAPModW **modarray )
00408 {
00409     if (modarray)
00410     {
00411         LDAPModW **p = modarray;
00412         while (*p) modfreeW( *p++ );
00413         HeapFree( GetProcessHeap(), 0, modarray );
00414     }
00415 }
00416 
00417 static inline void modarrayfreeU( LDAPMod **modarray )
00418 {
00419     if (modarray)
00420     {
00421         LDAPMod **p = modarray;
00422         while (*p) modfreeU( *p++ );
00423         HeapFree( GetProcessHeap(), 0, modarray );
00424     }
00425 }
00426 
00427 static inline LDAPControlW *controlAtoW( LDAPControlA *control )
00428 {
00429     LDAPControlW *controlW;
00430     DWORD len = control->ldctl_value.bv_len;
00431     char *val = NULL;
00432 
00433     if (control->ldctl_value.bv_val)
00434     {
00435         val = HeapAlloc( GetProcessHeap(), 0, len );
00436         if (!val) return NULL;
00437         memcpy( val, control->ldctl_value.bv_val, len );
00438     }
00439 
00440     controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
00441     if (!controlW)
00442     {
00443         HeapFree( GetProcessHeap(), 0, val );
00444         return NULL;
00445     }
00446 
00447     controlW->ldctl_oid = strAtoW( control->ldctl_oid );
00448     controlW->ldctl_value.bv_len = len; 
00449     controlW->ldctl_value.bv_val = val; 
00450     controlW->ldctl_iscritical = control->ldctl_iscritical;
00451 
00452     return controlW;
00453 }
00454 
00455 static inline LDAPControlA *controlWtoA( LDAPControlW *control )
00456 {
00457     LDAPControlA *controlA;
00458     DWORD len = control->ldctl_value.bv_len;
00459     char *val = NULL;
00460 
00461     if (control->ldctl_value.bv_val)
00462     {
00463         val = HeapAlloc( GetProcessHeap(), 0, len );
00464         if (!val) return NULL;
00465         memcpy( val, control->ldctl_value.bv_val, len );
00466     }
00467 
00468     controlA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlA) );
00469     if (!controlA)
00470     {
00471         HeapFree( GetProcessHeap(), 0, val );
00472         return NULL;
00473     }
00474 
00475     controlA->ldctl_oid = strWtoA( control->ldctl_oid );
00476     controlA->ldctl_value.bv_len = len; 
00477     controlA->ldctl_value.bv_val = val;
00478     controlA->ldctl_iscritical = control->ldctl_iscritical;
00479 
00480     return controlA;
00481 }
00482 
00483 static inline LDAPControl *controlWtoU( LDAPControlW *control )
00484 {
00485     LDAPControl *controlU;
00486     DWORD len = control->ldctl_value.bv_len;
00487     char *val = NULL;
00488 
00489     if (control->ldctl_value.bv_val)
00490     {
00491         val = HeapAlloc( GetProcessHeap(), 0, len );
00492         if (!val) return NULL;
00493         memcpy( val, control->ldctl_value.bv_val, len );
00494     }
00495 
00496     controlU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) );
00497     if (!controlU)
00498     {
00499         HeapFree( GetProcessHeap(), 0, val );
00500         return NULL;
00501     }
00502 
00503     controlU->ldctl_oid = strWtoU( control->ldctl_oid );
00504     controlU->ldctl_value.bv_len = len; 
00505     controlU->ldctl_value.bv_val = val; 
00506     controlU->ldctl_iscritical = control->ldctl_iscritical;
00507 
00508     return controlU;
00509 }
00510 
00511 static inline LDAPControlW *controlUtoW( LDAPControl *control )
00512 {
00513     LDAPControlW *controlW;
00514     DWORD len = control->ldctl_value.bv_len;
00515     char *val = NULL;
00516 
00517     if (control->ldctl_value.bv_val)
00518     {
00519         val = HeapAlloc( GetProcessHeap(), 0, len );
00520         if (!val) return NULL;
00521         memcpy( val, control->ldctl_value.bv_val, len );
00522     }
00523 
00524     controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
00525     if (!controlW)
00526     {
00527         HeapFree( GetProcessHeap(), 0, val );
00528         return NULL;
00529     }
00530 
00531     controlW->ldctl_oid = strUtoW( control->ldctl_oid );
00532     controlW->ldctl_value.bv_len = len; 
00533     controlW->ldctl_value.bv_val = val; 
00534     controlW->ldctl_iscritical = control->ldctl_iscritical;
00535  
00536     return controlW;
00537 }
00538 
00539 static inline void controlfreeA( LDAPControlA *control )
00540 {
00541     if (control)
00542     {
00543         strfreeA( control->ldctl_oid );
00544         HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
00545         HeapFree( GetProcessHeap(), 0, control );
00546     }
00547 }
00548 
00549 static inline void controlfreeW( LDAPControlW *control )
00550 {
00551     if (control)
00552     {
00553         strfreeW( control->ldctl_oid );
00554         HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
00555         HeapFree( GetProcessHeap(), 0, control );
00556     }
00557 }
00558 
00559 static inline void controlfreeU( LDAPControl *control )
00560 {
00561     if (control)
00562     {
00563         strfreeU( control->ldctl_oid );
00564         HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
00565         HeapFree( GetProcessHeap(), 0, control );
00566     }
00567 }
00568 
00569 static inline DWORD controlarraylenA( LDAPControlA **controlarray )
00570 {
00571     LDAPControlA **p = controlarray;
00572     while (*p) p++;
00573     return p - controlarray;
00574 }
00575 
00576 static inline DWORD controlarraylenW( LDAPControlW **controlarray )
00577 {
00578     LDAPControlW **p = controlarray;
00579     while (*p) p++;
00580     return p - controlarray;
00581 }
00582 
00583 static inline DWORD controlarraylenU( LDAPControl **controlarray )
00584 {
00585     LDAPControl **p = controlarray;
00586     while (*p) p++;
00587     return p - controlarray;
00588 }
00589 
00590 static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray )
00591 {
00592     LDAPControlW **controlarrayW = NULL;
00593     DWORD size;
00594 
00595     if (controlarray)
00596     {
00597         size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1);
00598         controlarrayW = HeapAlloc( GetProcessHeap(), 0, size );
00599 
00600         if (controlarrayW)
00601         {
00602             LDAPControlA **p = controlarray;
00603             LDAPControlW **q = controlarrayW;
00604 
00605             while (*p) *q++ = controlAtoW( *p++ );
00606             *q = NULL;
00607         }
00608     }
00609     return controlarrayW;
00610 }
00611 
00612 static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
00613 {
00614     LDAPControlA **controlarrayA = NULL;
00615     DWORD size;
00616 
00617     if (controlarray)
00618     {
00619         size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
00620         controlarrayA = HeapAlloc( GetProcessHeap(), 0, size );
00621 
00622         if (controlarrayA)
00623         {
00624             LDAPControlW **p = controlarray;
00625             LDAPControlA **q = controlarrayA;
00626 
00627             while (*p) *q++ = controlWtoA( *p++ );
00628             *q = NULL;
00629         }
00630     }
00631     return controlarrayA;
00632 }
00633 
00634 static inline LDAPControl **controlarrayWtoU( LDAPControlW **controlarray )
00635 {
00636     LDAPControl **controlarrayU = NULL;
00637     DWORD size;
00638 
00639     if (controlarray)
00640     {
00641         size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
00642         controlarrayU = HeapAlloc( GetProcessHeap(), 0, size );
00643 
00644         if (controlarrayU)
00645         {
00646             LDAPControlW **p = controlarray;
00647             LDAPControl **q = controlarrayU;
00648 
00649             while (*p) *q++ = controlWtoU( *p++ );
00650             *q = NULL;
00651         }
00652     }
00653     return controlarrayU;
00654 }
00655 
00656 static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray )
00657 {
00658     LDAPControlW **controlarrayW = NULL;
00659     DWORD size;
00660 
00661     if (controlarray)
00662     {
00663         size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1);
00664         controlarrayW = HeapAlloc( GetProcessHeap(), 0, size );
00665 
00666         if (controlarrayW)
00667         {
00668             LDAPControl **p = controlarray;
00669             LDAPControlW **q = controlarrayW;
00670 
00671             while (*p) *q++ = controlUtoW( *p++ );
00672             *q = NULL;
00673         }
00674     }
00675     return controlarrayW;
00676 }
00677 
00678 static inline void controlarrayfreeA( LDAPControlA **controlarray )
00679 {
00680     if (controlarray)
00681     {
00682         LDAPControlA **p = controlarray;
00683         while (*p) controlfreeA( *p++ );
00684         HeapFree( GetProcessHeap(), 0, controlarray );
00685     }
00686 }
00687 
00688 static inline void controlarrayfreeW( LDAPControlW **controlarray )
00689 {
00690     if (controlarray)
00691     {
00692         LDAPControlW **p = controlarray;
00693         while (*p) controlfreeW( *p++ );
00694         HeapFree( GetProcessHeap(), 0, controlarray );
00695     }
00696 }
00697 
00698 static inline void controlarrayfreeU( LDAPControl **controlarray )
00699 {
00700     if (controlarray)
00701     {
00702         LDAPControl **p = controlarray;
00703         while (*p) controlfreeU( *p++ );
00704         HeapFree( GetProcessHeap(), 0, controlarray );
00705     }
00706 }
00707 
00708 static inline LDAPSortKeyW *sortkeyAtoW( LDAPSortKeyA *sortkey )
00709 {
00710     LDAPSortKeyW *sortkeyW;
00711 
00712     sortkeyW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKeyW) );
00713     if (sortkeyW)
00714     {
00715         sortkeyW->sk_attrtype = strAtoW( sortkey->sk_attrtype );
00716         sortkeyW->sk_matchruleoid = strAtoW( sortkey->sk_matchruleoid );
00717         sortkeyW->sk_reverseorder = sortkey->sk_reverseorder;
00718     }
00719     return sortkeyW;
00720 }
00721 
00722 static inline LDAPSortKeyA *sortkeyWtoA( LDAPSortKeyW *sortkey )
00723 {
00724     LDAPSortKeyA *sortkeyA;
00725 
00726     sortkeyA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKeyA) );
00727     if (sortkeyA)
00728     {
00729         sortkeyA->sk_attrtype = strWtoA( sortkey->sk_attrtype );
00730         sortkeyA->sk_matchruleoid = strWtoA( sortkey->sk_matchruleoid );
00731         sortkeyA->sk_reverseorder = sortkey->sk_reverseorder;
00732     }
00733     return sortkeyA;
00734 }
00735 
00736 static inline LDAPSortKey *sortkeyWtoU( LDAPSortKeyW *sortkey )
00737 {
00738     LDAPSortKey *sortkeyU;
00739 
00740     sortkeyU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKey) );
00741     if (sortkeyU)
00742     {
00743         sortkeyU->attributeType = strWtoU( sortkey->sk_attrtype );
00744         sortkeyU->orderingRule = strWtoU( sortkey->sk_matchruleoid );
00745         sortkeyU->reverseOrder = sortkey->sk_reverseorder;
00746     }
00747     return sortkeyU;
00748 }
00749 
00750 static inline void sortkeyfreeA( LDAPSortKeyA *sortkey )
00751 {
00752     if (sortkey)
00753     {
00754         strfreeA( sortkey->sk_attrtype );
00755         strfreeA( sortkey->sk_matchruleoid );
00756         HeapFree( GetProcessHeap(), 0, sortkey );
00757     }
00758 }
00759 
00760 static inline void sortkeyfreeW( LDAPSortKeyW *sortkey )
00761 {
00762     if (sortkey)
00763     {
00764         strfreeW( sortkey->sk_attrtype );
00765         strfreeW( sortkey->sk_matchruleoid );
00766         HeapFree( GetProcessHeap(), 0, sortkey );
00767     }
00768 }
00769 
00770 static inline void sortkeyfreeU( LDAPSortKey *sortkey )
00771 {
00772     if (sortkey)
00773     {
00774         strfreeU( sortkey->attributeType );
00775         strfreeU( sortkey->orderingRule );
00776         HeapFree( GetProcessHeap(), 0, sortkey );
00777     }
00778 }
00779 
00780 static inline DWORD sortkeyarraylenA( LDAPSortKeyA **sortkeyarray )
00781 {
00782     LDAPSortKeyA **p = sortkeyarray;
00783     while (*p) p++;
00784     return p - sortkeyarray;
00785 }
00786 
00787 static inline DWORD sortkeyarraylenW( LDAPSortKeyW **sortkeyarray )
00788 {
00789     LDAPSortKeyW **p = sortkeyarray;
00790     while (*p) p++;
00791     return p - sortkeyarray;
00792 }
00793 
00794 static inline LDAPSortKeyW **sortkeyarrayAtoW( LDAPSortKeyA **sortkeyarray )
00795 {
00796     LDAPSortKeyW **sortkeyarrayW = NULL;
00797     DWORD size;
00798 
00799     if (sortkeyarray)
00800     {
00801         size = sizeof(LDAPSortKeyW*) * (sortkeyarraylenA( sortkeyarray ) + 1);
00802         sortkeyarrayW = HeapAlloc( GetProcessHeap(), 0, size );
00803 
00804         if (sortkeyarrayW)
00805         {
00806             LDAPSortKeyA **p = sortkeyarray;
00807             LDAPSortKeyW **q = sortkeyarrayW;
00808 
00809             while (*p) *q++ = sortkeyAtoW( *p++ );
00810             *q = NULL;
00811         }
00812     }
00813     return sortkeyarrayW;
00814 }
00815 
00816 static inline LDAPSortKey **sortkeyarrayWtoU( LDAPSortKeyW **sortkeyarray )
00817 {
00818     LDAPSortKey **sortkeyarrayU = NULL;
00819     DWORD size;
00820 
00821     if (sortkeyarray)
00822     {
00823         size = sizeof(LDAPSortKey*) * (sortkeyarraylenW( sortkeyarray ) + 1);
00824         sortkeyarrayU = HeapAlloc( GetProcessHeap(), 0, size );
00825 
00826         if (sortkeyarrayU)
00827         {
00828             LDAPSortKeyW **p = sortkeyarray;
00829             LDAPSortKey **q = sortkeyarrayU;
00830 
00831             while (*p) *q++ = sortkeyWtoU( *p++ );
00832             *q = NULL;
00833         }
00834     }
00835     return sortkeyarrayU;
00836 }
00837 
00838 static inline void sortkeyarrayfreeW( LDAPSortKeyW **sortkeyarray )
00839 {
00840     if (sortkeyarray)
00841     {
00842         LDAPSortKeyW **p = sortkeyarray;
00843         while (*p) sortkeyfreeW( *p++ );
00844         HeapFree( GetProcessHeap(), 0, sortkeyarray );
00845     }
00846 }
00847 
00848 static inline void sortkeyarrayfreeU( LDAPSortKey **sortkeyarray )
00849 {
00850     if (sortkeyarray)
00851     {
00852         LDAPSortKey **p = sortkeyarray;
00853         while (*p) sortkeyfreeU( *p++ );
00854         HeapFree( GetProcessHeap(), 0, sortkeyarray );
00855     }
00856 }
00857 
00858 #endif /* HAVE_LDAP */

Generated on Sun May 27 2012 04:27:05 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.