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
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
)
36 if (!src
) return NULL
;
37 if ((dst
= heap_alloc( (strlen( src
) + 1) * sizeof(char) ))) strcpy( dst
, src
);
41 static inline WCHAR
*strdupW( const WCHAR
*src
)
44 if (!src
) return NULL
;
45 if ((dst
= heap_alloc( (strlenW( src
) + 1) * sizeof(WCHAR
) ))) strcpyW( dst
, src
);
49 static inline LPWSTR
strAtoW( LPCSTR 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
);
61 static inline LPSTR
strWtoA( LPCWSTR 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
);
73 static inline char *strWtoU( LPCWSTR 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
);
85 static inline LPWSTR
strUtoW( char *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
);
97 static inline LPWSTR
strnAtoW( LPCSTR str
, DWORD inlen
, DWORD
*outlen
)
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
);
114 static inline char *strnWtoU( LPCWSTR str
, DWORD inlen
, DWORD
*outlen
)
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
);
131 static inline void strfreeA( LPSTR str
)
136 static inline void strfreeW( LPWSTR str
)
141 static inline void strfreeU( char *str
)
146 static inline DWORD
strarraylenA( LPSTR
*strarray
)
153 static inline DWORD
strarraylenW( LPWSTR
*strarray
)
155 LPWSTR
*p
= strarray
;
160 static inline DWORD
strarraylenU( char **strarray
)
167 static inline LPWSTR
*strarrayAtoW( LPSTR
*strarray
)
169 LPWSTR
*strarrayW
= NULL
;
174 size
= sizeof(WCHAR
*) * (strarraylenA( strarray
) + 1);
175 if ((strarrayW
= heap_alloc( size
)))
178 LPWSTR
*q
= strarrayW
;
180 while (*p
) *q
++ = strAtoW( *p
++ );
187 static inline LPSTR
*strarrayWtoA( LPWSTR
*strarray
)
189 LPSTR
*strarrayA
= NULL
;
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
++ );
207 static inline char **strarrayWtoU( LPWSTR
*strarray
)
209 char **strarrayU
= NULL
;
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
++ );
227 static inline LPWSTR
*strarrayUtoW( char **strarray
)
229 LPWSTR
*strarrayW
= NULL
;
234 size
= sizeof(WCHAR
*) * (strarraylenU( strarray
) + 1);
235 if ((strarrayW
= heap_alloc( size
)))
238 LPWSTR
*q
= strarrayW
;
240 while (*p
) *q
++ = strUtoW( *p
++ );
247 static inline LPWSTR
*strarraydupW( LPWSTR
*strarray
)
249 LPWSTR
*strarrayW
= NULL
;
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
++ );
267 static inline void strarrayfreeA( LPSTR
*strarray
)
272 while (*p
) strfreeA( *p
++ );
273 heap_free( strarray
);
277 static inline void strarrayfreeW( LPWSTR
*strarray
)
281 LPWSTR
*p
= strarray
;
282 while (*p
) strfreeW( *p
++ );
283 heap_free( strarray
);
287 static inline void strarrayfreeU( char **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
);
313 static inline void bvarrayfreeW( struct WLDAP32_berval
**bv
)
315 struct WLDAP32_berval
**p
= bv
;
316 while (*p
) heap_free( *p
++ );
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
);
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
);
356 static inline DWORD
bvarraylenU( struct berval
**bv
)
358 struct berval
**p
= bv
;
363 static inline DWORD
bvarraylenW( struct WLDAP32_berval
**bv
)
365 struct WLDAP32_berval
**p
= bv
;
370 static inline struct WLDAP32_berval
**bvarrayWtoW( struct WLDAP32_berval
**bv
)
372 struct WLDAP32_berval
**berval
= NULL
;
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
++ );
390 static inline struct berval
**bvarrayWtoU( struct WLDAP32_berval
**bv
)
392 struct berval
**berval
= NULL
;
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
++ );
410 static inline struct WLDAP32_berval
**bvarrayUtoW( struct berval
**bv
)
412 struct WLDAP32_berval
**berval
= NULL
;
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
++ );
430 static inline void bvarrayfreeU( struct berval
**bv
)
432 struct berval
**p
= bv
;
433 while (*p
) heap_free( *p
++ );
437 static inline LDAPModW
*modAtoW( LDAPModA
*mod
)
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
);
449 modW
->mod_vals
.modv_strvals
= strarrayAtoW( mod
->mod_vals
.modv_strvals
);
454 static inline LDAPMod
*modWtoU( LDAPModW
*mod
)
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
);
466 modU
->mod_vals
.modv_strvals
= strarrayWtoU( mod
->mod_vals
.modv_strvals
);
471 static inline void modfreeW( LDAPModW
*mod
)
473 if (mod
->mod_op
& LDAP_MOD_BVALUES
)
474 bvarrayfreeW( mod
->mod_vals
.modv_bvals
);
476 strarrayfreeW( mod
->mod_vals
.modv_strvals
);
480 static inline void modfreeU( LDAPMod
*mod
)
482 if (mod
->mod_op
& LDAP_MOD_BVALUES
)
483 bvarrayfreeU( mod
->mod_vals
.modv_bvals
);
485 strarrayfreeU( mod
->mod_vals
.modv_strvals
);
489 static inline DWORD
modarraylenA( LDAPModA
**modarray
)
491 LDAPModA
**p
= modarray
;
496 static inline DWORD
modarraylenW( LDAPModW
**modarray
)
498 LDAPModW
**p
= modarray
;
503 static inline LDAPModW
**modarrayAtoW( LDAPModA
**modarray
)
505 LDAPModW
**modarrayW
= NULL
;
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
++ );
523 static inline LDAPMod
**modarrayWtoU( LDAPModW
**modarray
)
525 LDAPMod
**modarrayU
= NULL
;
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
++ );
543 static inline void modarrayfreeW( LDAPModW
**modarray
)
547 LDAPModW
**p
= modarray
;
548 while (*p
) modfreeW( *p
++ );
549 heap_free( modarray
);
553 static inline void modarrayfreeU( LDAPMod
**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
;
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
) )))
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
;
589 static inline LDAPControlA
*controlWtoA( LDAPControlW
*control
)
591 LDAPControlA
*controlA
;
592 DWORD len
= control
->ldctl_value
.bv_len
;
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
) )))
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
;
615 static inline LDAPControl
*controlWtoU( LDAPControlW
*control
)
617 LDAPControl
*controlU
;
618 DWORD len
= control
->ldctl_value
.bv_len
;
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
) )))
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
;
641 static inline LDAPControlW
*controlUtoW( LDAPControl
*control
)
643 LDAPControlW
*controlW
;
644 DWORD len
= control
->ldctl_value
.bv_len
;
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
) )))
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
;
667 static inline LDAPControlW
*controldupW( LDAPControlW
*control
)
669 LDAPControlW
*controlW
;
670 DWORD len
= control
->ldctl_value
.bv_len
;
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
) )))
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
;
693 static inline void controlfreeA( LDAPControlA
*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
)
707 strfreeW( control
->ldctl_oid
);
708 heap_free( control
->ldctl_value
.bv_val
);
709 heap_free( control
);
713 static inline void controlfreeU( LDAPControl
*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
;
727 return p
- controlarray
;
730 static inline DWORD
controlarraylenW( LDAPControlW
**controlarray
)
732 LDAPControlW
**p
= controlarray
;
734 return p
- controlarray
;
737 static inline DWORD
controlarraylenU( LDAPControl
**controlarray
)
739 LDAPControl
**p
= controlarray
;
741 return p
- controlarray
;
744 static inline LDAPControlW
**controlarrayAtoW( LDAPControlA
**controlarray
)
746 LDAPControlW
**controlarrayW
= NULL
;
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
++ );
761 return controlarrayW
;
764 static inline LDAPControlA
**controlarrayWtoA( LDAPControlW
**controlarray
)
766 LDAPControlA
**controlarrayA
= NULL
;
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
++ );
781 return controlarrayA
;
784 static inline LDAPControl
**controlarrayWtoU( LDAPControlW
**controlarray
)
786 LDAPControl
**controlarrayU
= NULL
;
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
++ );
801 return controlarrayU
;
804 static inline LDAPControlW
**controlarrayUtoW( LDAPControl
**controlarray
)
806 LDAPControlW
**controlarrayW
= NULL
;
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
++ );
821 return controlarrayW
;
824 static inline LDAPControlW
**controlarraydupW( LDAPControlW
**controlarray
)
826 LDAPControlW
**controlarrayW
= NULL
;
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
++ );
841 return controlarrayW
;
844 static inline void controlarrayfreeA( LDAPControlA
**controlarray
)
848 LDAPControlA
**p
= controlarray
;
849 while (*p
) controlfreeA( *p
++ );
850 heap_free( controlarray
);
854 static inline void controlarrayfreeW( LDAPControlW
**controlarray
)
858 LDAPControlW
**p
= controlarray
;
859 while (*p
) controlfreeW( *p
++ );
860 heap_free( controlarray
);
864 static inline void controlarrayfreeU( LDAPControl
**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
;
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
;
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
;
913 static inline void sortkeyfreeA( LDAPSortKeyA
*sortkey
)
917 strfreeA( sortkey
->sk_attrtype
);
918 strfreeA( sortkey
->sk_matchruleoid
);
919 heap_free( sortkey
);
923 static inline void sortkeyfreeW( LDAPSortKeyW
*sortkey
)
927 strfreeW( sortkey
->sk_attrtype
);
928 strfreeW( sortkey
->sk_matchruleoid
);
929 heap_free( sortkey
);
933 static inline void sortkeyfreeU( LDAPSortKey
*sortkey
)
937 strfreeU( sortkey
->attributeType
);
938 strfreeU( sortkey
->orderingRule
);
939 heap_free( sortkey
);
943 static inline DWORD
sortkeyarraylenA( LDAPSortKeyA
**sortkeyarray
)
945 LDAPSortKeyA
**p
= sortkeyarray
;
947 return p
- sortkeyarray
;
950 static inline DWORD
sortkeyarraylenW( LDAPSortKeyW
**sortkeyarray
)
952 LDAPSortKeyW
**p
= sortkeyarray
;
954 return p
- sortkeyarray
;
957 static inline LDAPSortKeyW
**sortkeyarrayAtoW( LDAPSortKeyA
**sortkeyarray
)
959 LDAPSortKeyW
**sortkeyarrayW
= NULL
;
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
++ );
974 return sortkeyarrayW
;
977 static inline LDAPSortKey
**sortkeyarrayWtoU( LDAPSortKeyW
**sortkeyarray
)
979 LDAPSortKey
**sortkeyarrayU
= NULL
;
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
++ );
994 return sortkeyarrayU
;
997 static inline void sortkeyarrayfreeW( LDAPSortKeyW
**sortkeyarray
)
1001 LDAPSortKeyW
**p
= sortkeyarray
;
1002 while (*p
) sortkeyfreeW( *p
++ );
1003 heap_free( sortkeyarray
);
1007 static inline void sortkeyarrayfreeU( LDAPSortKey
**sortkeyarray
)
1011 LDAPSortKey
**p
= sortkeyarray
;
1012 while (*p
) sortkeyfreeU( *p
++ );
1013 heap_free( sortkeyarray
);
1016 #endif /* HAVE_LDAP */