wldap32: Convert berval structures.
[wine.git] / dlls / wldap32 / wldap32.h
blob5b099c9fabc6acd3b497d2dabe60e6c5293eafd9
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 <assert.h>
22 #include "wine/heap.h"
23 #include "wine/unicode.h"
25 extern HINSTANCE hwldap32 DECLSPEC_HIDDEN;
27 ULONG map_error( int ) DECLSPEC_HIDDEN;
29 /* A set of helper functions to convert LDAP data structures
30 * to and from ansi (A), wide character (W) and utf8 (U) encodings.
33 static inline char *strdupU( const char *src )
35 char *dst;
36 if (!src) return NULL;
37 if ((dst = heap_alloc( (strlen( src ) + 1) * sizeof(char) ))) strcpy( dst, src );
38 return dst;
41 static inline WCHAR *strdupW( const WCHAR *src )
43 WCHAR *dst;
44 if (!src) return NULL;
45 if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
46 return dst;
49 static inline LPWSTR strAtoW( LPCSTR str )
51 LPWSTR ret = NULL;
52 if (str)
54 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
55 if ((ret = heap_alloc( len * sizeof(WCHAR) )))
56 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
58 return ret;
61 static inline LPSTR strWtoA( LPCWSTR str )
63 LPSTR ret = NULL;
64 if (str)
66 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
67 if ((ret = heap_alloc( len )))
68 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
70 return ret;
73 static inline char *strWtoU( LPCWSTR str )
75 LPSTR ret = NULL;
76 if (str)
78 DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
79 if ((ret = heap_alloc( len )))
80 WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
82 return ret;
85 static inline LPWSTR strUtoW( char *str )
87 LPWSTR ret = NULL;
88 if (str)
90 DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
91 if ((ret = heap_alloc( len * sizeof(WCHAR) )))
92 MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
94 return ret;
97 static inline LPWSTR strnAtoW( LPCSTR str, DWORD inlen, DWORD *outlen )
99 LPWSTR ret = NULL;
100 *outlen = 0;
101 if (str)
103 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, inlen, NULL, 0 );
104 if ((ret = heap_alloc( (len+1) * sizeof(WCHAR) )))
106 MultiByteToWideChar( CP_ACP, 0, str, inlen, ret, len );
107 ret[len] = 0;
108 *outlen = len;
111 return ret;
114 static inline char *strnWtoU( LPCWSTR str, DWORD inlen, DWORD *outlen )
116 LPSTR ret = NULL;
117 *outlen = 0;
118 if (str)
120 DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, inlen, NULL, 0, NULL, NULL );
121 if ((ret = heap_alloc( len + 1 )))
123 WideCharToMultiByte( CP_UTF8, 0, str, inlen, ret, len, NULL, NULL );
124 ret[len] = 0;
125 *outlen = len;
128 return ret;
131 static inline void strfreeA( LPSTR str )
133 heap_free( str );
136 static inline void strfreeW( LPWSTR str )
138 heap_free( str );
141 static inline void strfreeU( char *str )
143 heap_free( str );
146 static inline DWORD strarraylenA( LPSTR *strarray )
148 LPSTR *p = strarray;
149 while (*p) p++;
150 return p - strarray;
153 static inline DWORD strarraylenW( LPWSTR *strarray )
155 LPWSTR *p = strarray;
156 while (*p) p++;
157 return p - strarray;
160 static inline DWORD strarraylenU( char **strarray )
162 char **p = strarray;
163 while (*p) p++;
164 return p - strarray;
167 static inline LPWSTR *strarrayAtoW( LPSTR *strarray )
169 LPWSTR *strarrayW = NULL;
170 DWORD size;
172 if (strarray)
174 size = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1);
175 if ((strarrayW = heap_alloc( size )))
177 LPSTR *p = strarray;
178 LPWSTR *q = strarrayW;
180 while (*p) *q++ = strAtoW( *p++ );
181 *q = NULL;
184 return strarrayW;
187 static inline LPSTR *strarrayWtoA( LPWSTR *strarray )
189 LPSTR *strarrayA = NULL;
190 DWORD size;
192 if (strarray)
194 size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1);
195 if ((strarrayA = heap_alloc( size )))
197 LPWSTR *p = strarray;
198 LPSTR *q = strarrayA;
200 while (*p) *q++ = strWtoA( *p++ );
201 *q = NULL;
204 return strarrayA;
207 static inline char **strarrayWtoU( LPWSTR *strarray )
209 char **strarrayU = NULL;
210 DWORD size;
212 if (strarray)
214 size = sizeof(char*) * (strarraylenW( strarray ) + 1);
215 if ((strarrayU = heap_alloc( size )))
217 LPWSTR *p = strarray;
218 char **q = strarrayU;
220 while (*p) *q++ = strWtoU( *p++ );
221 *q = NULL;
224 return strarrayU;
227 static inline LPWSTR *strarrayUtoW( char **strarray )
229 LPWSTR *strarrayW = NULL;
230 DWORD size;
232 if (strarray)
234 size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1);
235 if ((strarrayW = heap_alloc( size )))
237 char **p = strarray;
238 LPWSTR *q = strarrayW;
240 while (*p) *q++ = strUtoW( *p++ );
241 *q = NULL;
244 return strarrayW;
247 static inline LPWSTR *strarraydupW( LPWSTR *strarray )
249 LPWSTR *strarrayW = NULL;
250 DWORD size;
252 if (strarray)
254 size = sizeof(WCHAR*) * (strarraylenW( strarray ) + 1);
255 if ((strarrayW = heap_alloc( size )))
257 LPWSTR *p = strarray;
258 LPWSTR *q = strarrayW;
260 while (*p) *q++ = strdupW( *p++ );
261 *q = NULL;
264 return strarrayW;
267 static inline void strarrayfreeA( LPSTR *strarray )
269 if (strarray)
271 LPSTR *p = strarray;
272 while (*p) strfreeA( *p++ );
273 heap_free( strarray );
277 static inline void strarrayfreeW( LPWSTR *strarray )
279 if (strarray)
281 LPWSTR *p = strarray;
282 while (*p) strfreeW( *p++ );
283 heap_free( strarray );
287 static inline void strarrayfreeU( char **strarray )
289 if (strarray)
291 char **p = strarray;
292 while (*p) strfreeU( *p++ );
293 heap_free( strarray );
297 static inline struct WLDAP32_berval *bervalWtoW( struct WLDAP32_berval *bv )
299 struct WLDAP32_berval *berval;
300 DWORD size = sizeof(*berval) + bv->bv_len;
302 if ((berval = heap_alloc( size )))
304 char *val = (char *)(berval + 1);
306 berval->bv_len = bv->bv_len;
307 berval->bv_val = val;
308 memcpy( val, bv->bv_val, bv->bv_len );
310 return berval;
313 static inline void bvarrayfreeW( struct WLDAP32_berval **bv )
315 struct WLDAP32_berval **p = bv;
316 while (*p) heap_free( *p++ );
317 heap_free( bv );
320 #ifdef HAVE_LDAP
322 static inline struct berval *bervalWtoU( struct WLDAP32_berval *bv )
324 struct berval *berval;
325 DWORD size = sizeof(*berval) + bv->bv_len;
327 if ((berval = heap_alloc( size )))
329 char *val = (char *)(berval + 1);
331 berval->bv_len = bv->bv_len;
332 berval->bv_val = val;
333 memcpy( val, bv->bv_val, bv->bv_len );
335 return berval;
338 static inline struct WLDAP32_berval *bervalUtoW( struct berval *bv )
340 struct WLDAP32_berval *berval;
341 DWORD size = sizeof(*berval) + bv->bv_len;
343 assert( bv->bv_len <= ~0u );
345 if ((berval = heap_alloc( size )))
347 char *val = (char *)(berval + 1);
349 berval->bv_len = bv->bv_len;
350 berval->bv_val = val;
351 memcpy( val, bv->bv_val, bv->bv_len );
353 return berval;
356 static inline DWORD bvarraylenU( struct berval **bv )
358 struct berval **p = bv;
359 while (*p) p++;
360 return p - bv;
363 static inline DWORD bvarraylenW( struct WLDAP32_berval **bv )
365 struct WLDAP32_berval **p = bv;
366 while (*p) p++;
367 return p - bv;
370 static inline struct WLDAP32_berval **bvarrayWtoW( struct WLDAP32_berval **bv )
372 struct WLDAP32_berval **berval = NULL;
373 DWORD size;
375 if (bv)
377 size = sizeof(*berval) * (bvarraylenW( bv ) + 1);
378 if ((berval = heap_alloc( size )))
380 struct WLDAP32_berval **p = bv;
381 struct WLDAP32_berval **q = berval;
383 while (*p) *q++ = bervalWtoW( *p++ );
384 *q = NULL;
387 return berval;
390 static inline struct berval **bvarrayWtoU( struct WLDAP32_berval **bv )
392 struct berval **berval = NULL;
393 DWORD size;
395 if (bv)
397 size = sizeof(*berval) * (bvarraylenW( bv ) + 1);
398 if ((berval = heap_alloc( size )))
400 struct WLDAP32_berval **p = bv;
401 struct berval **q = berval;
403 while (*p) *q++ = bervalWtoU( *p++ );
404 *q = NULL;
407 return berval;
410 static inline struct WLDAP32_berval **bvarrayUtoW( struct berval **bv )
412 struct WLDAP32_berval **berval = NULL;
413 DWORD size;
415 if (bv)
417 size = sizeof(*berval) * (bvarraylenU( bv ) + 1);
418 if ((berval = heap_alloc( size )))
420 struct berval **p = bv;
421 struct WLDAP32_berval **q = berval;
423 while (*p) *q++ = bervalUtoW( *p++ );
424 *q = NULL;
427 return berval;
430 static inline void bvarrayfreeU( struct berval **bv )
432 struct berval **p = bv;
433 while (*p) heap_free( *p++ );
434 heap_free( bv );
437 static inline LDAPModW *modAtoW( LDAPModA *mod )
439 LDAPModW *modW;
441 if ((modW = heap_alloc( sizeof(LDAPModW) )))
443 modW->mod_op = mod->mod_op;
444 modW->mod_type = strAtoW( mod->mod_type );
446 if (mod->mod_op & LDAP_MOD_BVALUES)
447 modW->mod_vals.modv_bvals = bvarrayWtoW( mod->mod_vals.modv_bvals );
448 else
449 modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
451 return modW;
454 static inline LDAPMod *modWtoU( LDAPModW *mod )
456 LDAPMod *modU;
458 if ((modU = heap_alloc( sizeof(LDAPMod) )))
460 modU->mod_op = mod->mod_op;
461 modU->mod_type = strWtoU( mod->mod_type );
463 if (mod->mod_op & LDAP_MOD_BVALUES)
464 modU->mod_vals.modv_bvals = bvarrayWtoU( mod->mod_vals.modv_bvals );
465 else
466 modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
468 return modU;
471 static inline void modfreeW( LDAPModW *mod )
473 if (mod->mod_op & LDAP_MOD_BVALUES)
474 bvarrayfreeW( mod->mod_vals.modv_bvals );
475 else
476 strarrayfreeW( mod->mod_vals.modv_strvals );
477 heap_free( mod );
480 static inline void modfreeU( LDAPMod *mod )
482 if (mod->mod_op & LDAP_MOD_BVALUES)
483 bvarrayfreeU( mod->mod_vals.modv_bvals );
484 else
485 strarrayfreeU( mod->mod_vals.modv_strvals );
486 heap_free( mod );
489 static inline DWORD modarraylenA( LDAPModA **modarray )
491 LDAPModA **p = modarray;
492 while (*p) p++;
493 return p - modarray;
496 static inline DWORD modarraylenW( LDAPModW **modarray )
498 LDAPModW **p = modarray;
499 while (*p) p++;
500 return p - modarray;
503 static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
505 LDAPModW **modarrayW = NULL;
506 DWORD size;
508 if (modarray)
510 size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1);
511 if ((modarrayW = heap_alloc( size )))
513 LDAPModA **p = modarray;
514 LDAPModW **q = modarrayW;
516 while (*p) *q++ = modAtoW( *p++ );
517 *q = NULL;
520 return modarrayW;
523 static inline LDAPMod **modarrayWtoU( LDAPModW **modarray )
525 LDAPMod **modarrayU = NULL;
526 DWORD size;
528 if (modarray)
530 size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1);
531 if ((modarrayU = heap_alloc( size )))
533 LDAPModW **p = modarray;
534 LDAPMod **q = modarrayU;
536 while (*p) *q++ = modWtoU( *p++ );
537 *q = NULL;
540 return modarrayU;
543 static inline void modarrayfreeW( LDAPModW **modarray )
545 if (modarray)
547 LDAPModW **p = modarray;
548 while (*p) modfreeW( *p++ );
549 heap_free( modarray );
553 static inline void modarrayfreeU( LDAPMod **modarray )
555 if (modarray)
557 LDAPMod **p = modarray;
558 while (*p) modfreeU( *p++ );
559 heap_free( modarray );
563 static inline LDAPControlW *controlAtoW( LDAPControlA *control )
565 LDAPControlW *controlW;
566 DWORD len = control->ldctl_value.bv_len;
567 char *val = NULL;
569 if (control->ldctl_value.bv_val)
571 if (!(val = heap_alloc( len ))) return NULL;
572 memcpy( val, control->ldctl_value.bv_val, len );
575 if (!(controlW = heap_alloc( sizeof(LDAPControlW) )))
577 heap_free( val );
578 return NULL;
581 controlW->ldctl_oid = strAtoW( control->ldctl_oid );
582 controlW->ldctl_value.bv_len = len;
583 controlW->ldctl_value.bv_val = val;
584 controlW->ldctl_iscritical = control->ldctl_iscritical;
586 return controlW;
589 static inline LDAPControlA *controlWtoA( LDAPControlW *control )
591 LDAPControlA *controlA;
592 DWORD len = control->ldctl_value.bv_len;
593 char *val = NULL;
595 if (control->ldctl_value.bv_val)
597 if (!(val = heap_alloc( len ))) return NULL;
598 memcpy( val, control->ldctl_value.bv_val, len );
601 if (!(controlA = heap_alloc( sizeof(LDAPControlA) )))
603 heap_free( val );
604 return NULL;
607 controlA->ldctl_oid = strWtoA( control->ldctl_oid );
608 controlA->ldctl_value.bv_len = len;
609 controlA->ldctl_value.bv_val = val;
610 controlA->ldctl_iscritical = control->ldctl_iscritical;
612 return controlA;
615 static inline LDAPControl *controlWtoU( LDAPControlW *control )
617 LDAPControl *controlU;
618 DWORD len = control->ldctl_value.bv_len;
619 char *val = NULL;
621 if (control->ldctl_value.bv_val)
623 if (!(val = heap_alloc( len ))) return NULL;
624 memcpy( val, control->ldctl_value.bv_val, len );
627 if (!(controlU = heap_alloc( sizeof(LDAPControl) )))
629 heap_free( val );
630 return NULL;
633 controlU->ldctl_oid = strWtoU( control->ldctl_oid );
634 controlU->ldctl_value.bv_len = len;
635 controlU->ldctl_value.bv_val = val;
636 controlU->ldctl_iscritical = control->ldctl_iscritical;
638 return controlU;
641 static inline LDAPControlW *controlUtoW( LDAPControl *control )
643 LDAPControlW *controlW;
644 DWORD len = control->ldctl_value.bv_len;
645 char *val = NULL;
647 if (control->ldctl_value.bv_val)
649 if (!(val = heap_alloc( len ))) return NULL;
650 memcpy( val, control->ldctl_value.bv_val, len );
653 if (!(controlW = heap_alloc( sizeof(LDAPControlW) )))
655 heap_free( val );
656 return NULL;
659 controlW->ldctl_oid = strUtoW( control->ldctl_oid );
660 controlW->ldctl_value.bv_len = len;
661 controlW->ldctl_value.bv_val = val;
662 controlW->ldctl_iscritical = control->ldctl_iscritical;
664 return controlW;
667 static inline LDAPControlW *controldupW( LDAPControlW *control )
669 LDAPControlW *controlW;
670 DWORD len = control->ldctl_value.bv_len;
671 char *val = NULL;
673 if (control->ldctl_value.bv_val)
675 if (!(val = heap_alloc( len ))) return NULL;
676 memcpy( val, control->ldctl_value.bv_val, len );
679 if (!(controlW = heap_alloc( sizeof(LDAPControlW) )))
681 heap_free( val );
682 return NULL;
685 controlW->ldctl_oid = strdupW( control->ldctl_oid );
686 controlW->ldctl_value.bv_len = len;
687 controlW->ldctl_value.bv_val = val;
688 controlW->ldctl_iscritical = control->ldctl_iscritical;
690 return controlW;
693 static inline void controlfreeA( LDAPControlA *control )
695 if (control)
697 strfreeA( control->ldctl_oid );
698 heap_free( control->ldctl_value.bv_val );
699 heap_free( control );
703 static inline void controlfreeW( LDAPControlW *control )
705 if (control)
707 strfreeW( control->ldctl_oid );
708 heap_free( control->ldctl_value.bv_val );
709 heap_free( control );
713 static inline void controlfreeU( LDAPControl *control )
715 if (control)
717 strfreeU( control->ldctl_oid );
718 heap_free( control->ldctl_value.bv_val );
719 heap_free( control );
723 static inline DWORD controlarraylenA( LDAPControlA **controlarray )
725 LDAPControlA **p = controlarray;
726 while (*p) p++;
727 return p - controlarray;
730 static inline DWORD controlarraylenW( LDAPControlW **controlarray )
732 LDAPControlW **p = controlarray;
733 while (*p) p++;
734 return p - controlarray;
737 static inline DWORD controlarraylenU( LDAPControl **controlarray )
739 LDAPControl **p = controlarray;
740 while (*p) p++;
741 return p - controlarray;
744 static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray )
746 LDAPControlW **controlarrayW = NULL;
747 DWORD size;
749 if (controlarray)
751 size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1);
752 if ((controlarrayW = heap_alloc( size )))
754 LDAPControlA **p = controlarray;
755 LDAPControlW **q = controlarrayW;
757 while (*p) *q++ = controlAtoW( *p++ );
758 *q = NULL;
761 return controlarrayW;
764 static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
766 LDAPControlA **controlarrayA = NULL;
767 DWORD size;
769 if (controlarray)
771 size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
772 if ((controlarrayA = heap_alloc( size )))
774 LDAPControlW **p = controlarray;
775 LDAPControlA **q = controlarrayA;
777 while (*p) *q++ = controlWtoA( *p++ );
778 *q = NULL;
781 return controlarrayA;
784 static inline LDAPControl **controlarrayWtoU( LDAPControlW **controlarray )
786 LDAPControl **controlarrayU = NULL;
787 DWORD size;
789 if (controlarray)
791 size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
792 if ((controlarrayU = heap_alloc( size )))
794 LDAPControlW **p = controlarray;
795 LDAPControl **q = controlarrayU;
797 while (*p) *q++ = controlWtoU( *p++ );
798 *q = NULL;
801 return controlarrayU;
804 static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray )
806 LDAPControlW **controlarrayW = NULL;
807 DWORD size;
809 if (controlarray)
811 size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1);
812 if ((controlarrayW = heap_alloc( size )))
814 LDAPControl **p = controlarray;
815 LDAPControlW **q = controlarrayW;
817 while (*p) *q++ = controlUtoW( *p++ );
818 *q = NULL;
821 return controlarrayW;
824 static inline LDAPControlW **controlarraydupW( LDAPControlW **controlarray )
826 LDAPControlW **controlarrayW = NULL;
827 DWORD size;
829 if (controlarray)
831 size = sizeof(LDAPControlW*) * (controlarraylenW( controlarray ) + 1);
832 if ((controlarrayW = heap_alloc( size )))
834 LDAPControlW **p = controlarray;
835 LDAPControlW **q = controlarrayW;
837 while (*p) *q++ = controldupW( *p++ );
838 *q = NULL;
841 return controlarrayW;
844 static inline void controlarrayfreeA( LDAPControlA **controlarray )
846 if (controlarray)
848 LDAPControlA **p = controlarray;
849 while (*p) controlfreeA( *p++ );
850 heap_free( controlarray );
854 static inline void controlarrayfreeW( LDAPControlW **controlarray )
856 if (controlarray)
858 LDAPControlW **p = controlarray;
859 while (*p) controlfreeW( *p++ );
860 heap_free( controlarray );
864 static inline void controlarrayfreeU( LDAPControl **controlarray )
866 if (controlarray)
868 LDAPControl **p = controlarray;
869 while (*p) controlfreeU( *p++ );
870 heap_free( controlarray );
874 static inline LDAPSortKeyW *sortkeyAtoW( LDAPSortKeyA *sortkey )
876 LDAPSortKeyW *sortkeyW;
878 if ((sortkeyW = heap_alloc( sizeof(LDAPSortKeyW) )))
880 sortkeyW->sk_attrtype = strAtoW( sortkey->sk_attrtype );
881 sortkeyW->sk_matchruleoid = strAtoW( sortkey->sk_matchruleoid );
882 sortkeyW->sk_reverseorder = sortkey->sk_reverseorder;
884 return sortkeyW;
887 static inline LDAPSortKeyA *sortkeyWtoA( LDAPSortKeyW *sortkey )
889 LDAPSortKeyA *sortkeyA;
891 if ((sortkeyA = heap_alloc( sizeof(LDAPSortKeyA) )))
893 sortkeyA->sk_attrtype = strWtoA( sortkey->sk_attrtype );
894 sortkeyA->sk_matchruleoid = strWtoA( sortkey->sk_matchruleoid );
895 sortkeyA->sk_reverseorder = sortkey->sk_reverseorder;
897 return sortkeyA;
900 static inline LDAPSortKey *sortkeyWtoU( LDAPSortKeyW *sortkey )
902 LDAPSortKey *sortkeyU;
904 if ((sortkeyU = heap_alloc( sizeof(LDAPSortKey) )))
906 sortkeyU->attributeType = strWtoU( sortkey->sk_attrtype );
907 sortkeyU->orderingRule = strWtoU( sortkey->sk_matchruleoid );
908 sortkeyU->reverseOrder = sortkey->sk_reverseorder;
910 return sortkeyU;
913 static inline void sortkeyfreeA( LDAPSortKeyA *sortkey )
915 if (sortkey)
917 strfreeA( sortkey->sk_attrtype );
918 strfreeA( sortkey->sk_matchruleoid );
919 heap_free( sortkey );
923 static inline void sortkeyfreeW( LDAPSortKeyW *sortkey )
925 if (sortkey)
927 strfreeW( sortkey->sk_attrtype );
928 strfreeW( sortkey->sk_matchruleoid );
929 heap_free( sortkey );
933 static inline void sortkeyfreeU( LDAPSortKey *sortkey )
935 if (sortkey)
937 strfreeU( sortkey->attributeType );
938 strfreeU( sortkey->orderingRule );
939 heap_free( sortkey );
943 static inline DWORD sortkeyarraylenA( LDAPSortKeyA **sortkeyarray )
945 LDAPSortKeyA **p = sortkeyarray;
946 while (*p) p++;
947 return p - sortkeyarray;
950 static inline DWORD sortkeyarraylenW( LDAPSortKeyW **sortkeyarray )
952 LDAPSortKeyW **p = sortkeyarray;
953 while (*p) p++;
954 return p - sortkeyarray;
957 static inline LDAPSortKeyW **sortkeyarrayAtoW( LDAPSortKeyA **sortkeyarray )
959 LDAPSortKeyW **sortkeyarrayW = NULL;
960 DWORD size;
962 if (sortkeyarray)
964 size = sizeof(LDAPSortKeyW*) * (sortkeyarraylenA( sortkeyarray ) + 1);
965 if ((sortkeyarrayW = heap_alloc( size )))
967 LDAPSortKeyA **p = sortkeyarray;
968 LDAPSortKeyW **q = sortkeyarrayW;
970 while (*p) *q++ = sortkeyAtoW( *p++ );
971 *q = NULL;
974 return sortkeyarrayW;
977 static inline LDAPSortKey **sortkeyarrayWtoU( LDAPSortKeyW **sortkeyarray )
979 LDAPSortKey **sortkeyarrayU = NULL;
980 DWORD size;
982 if (sortkeyarray)
984 size = sizeof(LDAPSortKey*) * (sortkeyarraylenW( sortkeyarray ) + 1);
985 if ((sortkeyarrayU = heap_alloc( size )))
987 LDAPSortKeyW **p = sortkeyarray;
988 LDAPSortKey **q = sortkeyarrayU;
990 while (*p) *q++ = sortkeyWtoU( *p++ );
991 *q = NULL;
994 return sortkeyarrayU;
997 static inline void sortkeyarrayfreeW( LDAPSortKeyW **sortkeyarray )
999 if (sortkeyarray)
1001 LDAPSortKeyW **p = sortkeyarray;
1002 while (*p) sortkeyfreeW( *p++ );
1003 heap_free( sortkeyarray );
1007 static inline void sortkeyarrayfreeU( LDAPSortKey **sortkeyarray )
1009 if (sortkeyarray)
1011 LDAPSortKey **p = sortkeyarray;
1012 while (*p) sortkeyfreeU( *p++ );
1013 heap_free( sortkeyarray );
1016 #endif /* HAVE_LDAP */