09aa9f26318368a1274f66f2dfc15db5a07d7571
[reactos.git] / reactos / dll / win32 / wldap32 / wldap32.h
1 /*
2 * WLDAP32 - LDAP support for Wine
3 *
4 * Copyright 2005 Hans Leidekker
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #pragma once
22
23 extern HINSTANCE hwldap32 DECLSPEC_HIDDEN;
24
25 ULONG map_error( int ) DECLSPEC_HIDDEN;
26
27 /* A set of helper functions to convert LDAP data structures
28 * to and from ansi (A), wide character (W) and utf8 (U) encodings.
29 */
30
31 static inline char *strdupU( const char *src )
32 {
33 char *dst;
34
35 if (!src) return NULL;
36 dst = HeapAlloc( GetProcessHeap(), 0, (strlen( src ) + 1) * sizeof(char) );
37 if (dst)
38 strcpy( dst, src );
39 return dst;
40 }
41
42 static inline LPWSTR strAtoW( LPCSTR str )
43 {
44 LPWSTR ret = NULL;
45 if (str)
46 {
47 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
48 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
49 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
50 }
51 return ret;
52 }
53
54 static inline LPSTR strWtoA( LPCWSTR str )
55 {
56 LPSTR ret = NULL;
57 if (str)
58 {
59 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
60 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
61 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
62 }
63 return ret;
64 }
65
66 static inline char *strWtoU( LPCWSTR str )
67 {
68 LPSTR ret = NULL;
69 if (str)
70 {
71 DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
72 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
73 WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
74 }
75 return ret;
76 }
77
78 static inline LPWSTR strUtoW( char *str )
79 {
80 LPWSTR ret = NULL;
81 if (str)
82 {
83 DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
84 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
85 MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
86 }
87 return ret;
88 }
89
90 static inline void strfreeA( LPSTR str )
91 {
92 HeapFree( GetProcessHeap(), 0, str );
93 }
94
95 static inline void strfreeW( LPWSTR str )
96 {
97 HeapFree( GetProcessHeap(), 0, str );
98 }
99
100 static inline void strfreeU( char *str )
101 {
102 HeapFree( GetProcessHeap(), 0, str );
103 }
104
105 static inline DWORD strarraylenA( LPSTR *strarray )
106 {
107 LPSTR *p = strarray;
108 while (*p) p++;
109 return p - strarray;
110 }
111
112 static inline DWORD strarraylenW( LPWSTR *strarray )
113 {
114 LPWSTR *p = strarray;
115 while (*p) p++;
116 return p - strarray;
117 }
118
119 static inline DWORD strarraylenU( char **strarray )
120 {
121 char **p = strarray;
122 while (*p) p++;
123 return p - strarray;
124 }
125
126 static inline LPWSTR *strarrayAtoW( LPSTR *strarray )
127 {
128 LPWSTR *strarrayW = NULL;
129 DWORD size;
130
131 if (strarray)
132 {
133 size = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1);
134 strarrayW = HeapAlloc( GetProcessHeap(), 0, size );
135
136 if (strarrayW)
137 {
138 LPSTR *p = strarray;
139 LPWSTR *q = strarrayW;
140
141 while (*p) *q++ = strAtoW( *p++ );
142 *q = NULL;
143 }
144 }
145 return strarrayW;
146 }
147
148 static inline LPSTR *strarrayWtoA( LPWSTR *strarray )
149 {
150 LPSTR *strarrayA = NULL;
151 DWORD size;
152
153 if (strarray)
154 {
155 size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1);
156 strarrayA = HeapAlloc( GetProcessHeap(), 0, size );
157
158 if (strarrayA)
159 {
160 LPWSTR *p = strarray;
161 LPSTR *q = strarrayA;
162
163 while (*p) *q++ = strWtoA( *p++ );
164 *q = NULL;
165 }
166 }
167 return strarrayA;
168 }
169
170 static inline char **strarrayWtoU( LPWSTR *strarray )
171 {
172 char **strarrayU = NULL;
173 DWORD size;
174
175 if (strarray)
176 {
177 size = sizeof(char*) * (strarraylenW( strarray ) + 1);
178 strarrayU = HeapAlloc( GetProcessHeap(), 0, size );
179
180 if (strarrayU)
181 {
182 LPWSTR *p = strarray;
183 char **q = strarrayU;
184
185 while (*p) *q++ = strWtoU( *p++ );
186 *q = NULL;
187 }
188 }
189 return strarrayU;
190 }
191
192 static inline LPWSTR *strarrayUtoW( char **strarray )
193 {
194 LPWSTR *strarrayW = NULL;
195 DWORD size;
196
197 if (strarray)
198 {
199 size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1);
200 strarrayW = HeapAlloc( GetProcessHeap(), 0, size );
201
202 if (strarrayW)
203 {
204 char **p = strarray;
205 LPWSTR *q = strarrayW;
206
207 while (*p) *q++ = strUtoW( *p++ );
208 *q = NULL;
209 }
210 }
211 return strarrayW;
212 }
213
214 static inline void strarrayfreeA( LPSTR *strarray )
215 {
216 if (strarray)
217 {
218 LPSTR *p = strarray;
219 while (*p) strfreeA( *p++ );
220 HeapFree( GetProcessHeap(), 0, strarray );
221 }
222 }
223
224 static inline void strarrayfreeW( LPWSTR *strarray )
225 {
226 if (strarray)
227 {
228 LPWSTR *p = strarray;
229 while (*p) strfreeW( *p++ );
230 HeapFree( GetProcessHeap(), 0, strarray );
231 }
232 }
233
234 static inline void strarrayfreeU( char **strarray )
235 {
236 if (strarray)
237 {
238 char **p = strarray;
239 while (*p) strfreeU( *p++ );
240 HeapFree( GetProcessHeap(), 0, strarray );
241 }
242 }
243
244 #ifdef HAVE_LDAP
245
246 static inline struct berval *bvdup( struct berval *bv )
247 {
248 struct berval *berval;
249 DWORD size = sizeof(struct berval) + bv->bv_len;
250
251 berval = HeapAlloc( GetProcessHeap(), 0, size );
252 if (berval)
253 {
254 char *val = (char *)berval + sizeof(struct berval);
255
256 berval->bv_len = bv->bv_len;
257 berval->bv_val = val;
258 memcpy( val, bv->bv_val, bv->bv_len );
259 }
260 return berval;
261 }
262
263 static inline DWORD bvarraylen( struct berval **bv )
264 {
265 struct berval **p = bv;
266 while (*p) p++;
267 return p - bv;
268 }
269
270 static inline struct berval **bvarraydup( struct berval **bv )
271 {
272 struct berval **berval = NULL;
273 DWORD size;
274
275 if (bv)
276 {
277 size = sizeof(struct berval *) * (bvarraylen( bv ) + 1);
278 berval = HeapAlloc( GetProcessHeap(), 0, size );
279
280 if (berval)
281 {
282 struct berval **p = bv;
283 struct berval **q = berval;
284
285 while (*p) *q++ = bvdup( *p++ );
286 *q = NULL;
287 }
288 }
289 return berval;
290 }
291
292 static inline void bvarrayfree( struct berval **bv )
293 {
294 struct berval **p = bv;
295 while (*p) HeapFree( GetProcessHeap(), 0, *p++ );
296 HeapFree( GetProcessHeap(), 0, bv );
297 }
298
299 static inline LDAPModW *modAtoW( LDAPModA *mod )
300 {
301 LDAPModW *modW;
302
303 modW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPModW) );
304 if (modW)
305 {
306 modW->mod_op = mod->mod_op;
307 modW->mod_type = strAtoW( mod->mod_type );
308
309 if (mod->mod_op & LDAP_MOD_BVALUES)
310 modW->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
311 else
312 modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
313 }
314 return modW;
315 }
316
317 static inline LDAPMod *modWtoU( LDAPModW *mod )
318 {
319 LDAPMod *modU;
320
321 modU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPMod) );
322 if (modU)
323 {
324 modU->mod_op = mod->mod_op;
325 modU->mod_type = strWtoU( mod->mod_type );
326
327 if (mod->mod_op & LDAP_MOD_BVALUES)
328 modU->mod_vals.modv_bvals = bvarraydup( mod->mod_vals.modv_bvals );
329 else
330 modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
331 }
332 return modU;
333 }
334
335 static inline void modfreeW( LDAPModW *mod )
336 {
337 if (mod->mod_op & LDAP_MOD_BVALUES)
338 bvarrayfree( mod->mod_vals.modv_bvals );
339 else
340 strarrayfreeW( mod->mod_vals.modv_strvals );
341 HeapFree( GetProcessHeap(), 0, mod );
342 }
343
344 static inline void modfreeU( LDAPMod *mod )
345 {
346 if (mod->mod_op & LDAP_MOD_BVALUES)
347 bvarrayfree( mod->mod_vals.modv_bvals );
348 else
349 strarrayfreeU( mod->mod_vals.modv_strvals );
350 HeapFree( GetProcessHeap(), 0, mod );
351 }
352
353 static inline DWORD modarraylenA( LDAPModA **modarray )
354 {
355 LDAPModA **p = modarray;
356 while (*p) p++;
357 return p - modarray;
358 }
359
360 static inline DWORD modarraylenW( LDAPModW **modarray )
361 {
362 LDAPModW **p = modarray;
363 while (*p) p++;
364 return p - modarray;
365 }
366
367 static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
368 {
369 LDAPModW **modarrayW = NULL;
370 DWORD size;
371
372 if (modarray)
373 {
374 size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1);
375 modarrayW = HeapAlloc( GetProcessHeap(), 0, size );
376
377 if (modarrayW)
378 {
379 LDAPModA **p = modarray;
380 LDAPModW **q = modarrayW;
381
382 while (*p) *q++ = modAtoW( *p++ );
383 *q = NULL;
384 }
385 }
386 return modarrayW;
387 }
388
389 static inline LDAPMod **modarrayWtoU( LDAPModW **modarray )
390 {
391 LDAPMod **modarrayU = NULL;
392 DWORD size;
393
394 if (modarray)
395 {
396 size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1);
397 modarrayU = HeapAlloc( GetProcessHeap(), 0, size );
398
399 if (modarrayU)
400 {
401 LDAPModW **p = modarray;
402 LDAPMod **q = modarrayU;
403
404 while (*p) *q++ = modWtoU( *p++ );
405 *q = NULL;
406 }
407 }
408 return modarrayU;
409 }
410
411 static inline void modarrayfreeW( LDAPModW **modarray )
412 {
413 if (modarray)
414 {
415 LDAPModW **p = modarray;
416 while (*p) modfreeW( *p++ );
417 HeapFree( GetProcessHeap(), 0, modarray );
418 }
419 }
420
421 static inline void modarrayfreeU( LDAPMod **modarray )
422 {
423 if (modarray)
424 {
425 LDAPMod **p = modarray;
426 while (*p) modfreeU( *p++ );
427 HeapFree( GetProcessHeap(), 0, modarray );
428 }
429 }
430
431 static inline LDAPControlW *controlAtoW( LDAPControlA *control )
432 {
433 LDAPControlW *controlW;
434 DWORD len = control->ldctl_value.bv_len;
435 char *val = NULL;
436
437 if (control->ldctl_value.bv_val)
438 {
439 val = HeapAlloc( GetProcessHeap(), 0, len );
440 if (!val) return NULL;
441 memcpy( val, control->ldctl_value.bv_val, len );
442 }
443
444 controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
445 if (!controlW)
446 {
447 HeapFree( GetProcessHeap(), 0, val );
448 return NULL;
449 }
450
451 controlW->ldctl_oid = strAtoW( control->ldctl_oid );
452 controlW->ldctl_value.bv_len = len;
453 controlW->ldctl_value.bv_val = val;
454 controlW->ldctl_iscritical = control->ldctl_iscritical;
455
456 return controlW;
457 }
458
459 static inline LDAPControlA *controlWtoA( LDAPControlW *control )
460 {
461 LDAPControlA *controlA;
462 DWORD len = control->ldctl_value.bv_len;
463 char *val = NULL;
464
465 if (control->ldctl_value.bv_val)
466 {
467 val = HeapAlloc( GetProcessHeap(), 0, len );
468 if (!val) return NULL;
469 memcpy( val, control->ldctl_value.bv_val, len );
470 }
471
472 controlA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlA) );
473 if (!controlA)
474 {
475 HeapFree( GetProcessHeap(), 0, val );
476 return NULL;
477 }
478
479 controlA->ldctl_oid = strWtoA( control->ldctl_oid );
480 controlA->ldctl_value.bv_len = len;
481 controlA->ldctl_value.bv_val = val;
482 controlA->ldctl_iscritical = control->ldctl_iscritical;
483
484 return controlA;
485 }
486
487 static inline LDAPControl *controlWtoU( LDAPControlW *control )
488 {
489 LDAPControl *controlU;
490 DWORD len = control->ldctl_value.bv_len;
491 char *val = NULL;
492
493 if (control->ldctl_value.bv_val)
494 {
495 val = HeapAlloc( GetProcessHeap(), 0, len );
496 if (!val) return NULL;
497 memcpy( val, control->ldctl_value.bv_val, len );
498 }
499
500 controlU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) );
501 if (!controlU)
502 {
503 HeapFree( GetProcessHeap(), 0, val );
504 return NULL;
505 }
506
507 controlU->ldctl_oid = strWtoU( control->ldctl_oid );
508 controlU->ldctl_value.bv_len = len;
509 controlU->ldctl_value.bv_val = val;
510 controlU->ldctl_iscritical = control->ldctl_iscritical;
511
512 return controlU;
513 }
514
515 static inline LDAPControlW *controlUtoW( LDAPControl *control )
516 {
517 LDAPControlW *controlW;
518 DWORD len = control->ldctl_value.bv_len;
519 char *val = NULL;
520
521 if (control->ldctl_value.bv_val)
522 {
523 val = HeapAlloc( GetProcessHeap(), 0, len );
524 if (!val) return NULL;
525 memcpy( val, control->ldctl_value.bv_val, len );
526 }
527
528 controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
529 if (!controlW)
530 {
531 HeapFree( GetProcessHeap(), 0, val );
532 return NULL;
533 }
534
535 controlW->ldctl_oid = strUtoW( control->ldctl_oid );
536 controlW->ldctl_value.bv_len = len;
537 controlW->ldctl_value.bv_val = val;
538 controlW->ldctl_iscritical = control->ldctl_iscritical;
539
540 return controlW;
541 }
542
543 static inline void controlfreeA( LDAPControlA *control )
544 {
545 if (control)
546 {
547 strfreeA( control->ldctl_oid );
548 HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
549 HeapFree( GetProcessHeap(), 0, control );
550 }
551 }
552
553 static inline void controlfreeW( LDAPControlW *control )
554 {
555 if (control)
556 {
557 strfreeW( control->ldctl_oid );
558 HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
559 HeapFree( GetProcessHeap(), 0, control );
560 }
561 }
562
563 static inline void controlfreeU( LDAPControl *control )
564 {
565 if (control)
566 {
567 strfreeU( control->ldctl_oid );
568 HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
569 HeapFree( GetProcessHeap(), 0, control );
570 }
571 }
572
573 static inline DWORD controlarraylenA( LDAPControlA **controlarray )
574 {
575 LDAPControlA **p = controlarray;
576 while (*p) p++;
577 return p - controlarray;
578 }
579
580 static inline DWORD controlarraylenW( LDAPControlW **controlarray )
581 {
582 LDAPControlW **p = controlarray;
583 while (*p) p++;
584 return p - controlarray;
585 }
586
587 static inline DWORD controlarraylenU( LDAPControl **controlarray )
588 {
589 LDAPControl **p = controlarray;
590 while (*p) p++;
591 return p - controlarray;
592 }
593
594 static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray )
595 {
596 LDAPControlW **controlarrayW = NULL;
597 DWORD size;
598
599 if (controlarray)
600 {
601 size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1);
602 controlarrayW = HeapAlloc( GetProcessHeap(), 0, size );
603
604 if (controlarrayW)
605 {
606 LDAPControlA **p = controlarray;
607 LDAPControlW **q = controlarrayW;
608
609 while (*p) *q++ = controlAtoW( *p++ );
610 *q = NULL;
611 }
612 }
613 return controlarrayW;
614 }
615
616 static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
617 {
618 LDAPControlA **controlarrayA = NULL;
619 DWORD size;
620
621 if (controlarray)
622 {
623 size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
624 controlarrayA = HeapAlloc( GetProcessHeap(), 0, size );
625
626 if (controlarrayA)
627 {
628 LDAPControlW **p = controlarray;
629 LDAPControlA **q = controlarrayA;
630
631 while (*p) *q++ = controlWtoA( *p++ );
632 *q = NULL;
633 }
634 }
635 return controlarrayA;
636 }
637
638 static inline LDAPControl **controlarrayWtoU( LDAPControlW **controlarray )
639 {
640 LDAPControl **controlarrayU = NULL;
641 DWORD size;
642
643 if (controlarray)
644 {
645 size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
646 controlarrayU = HeapAlloc( GetProcessHeap(), 0, size );
647
648 if (controlarrayU)
649 {
650 LDAPControlW **p = controlarray;
651 LDAPControl **q = controlarrayU;
652
653 while (*p) *q++ = controlWtoU( *p++ );
654 *q = NULL;
655 }
656 }
657 return controlarrayU;
658 }
659
660 static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray )
661 {
662 LDAPControlW **controlarrayW = NULL;
663 DWORD size;
664
665 if (controlarray)
666 {
667 size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1);
668 controlarrayW = HeapAlloc( GetProcessHeap(), 0, size );
669
670 if (controlarrayW)
671 {
672 LDAPControl **p = controlarray;
673 LDAPControlW **q = controlarrayW;
674
675 while (*p) *q++ = controlUtoW( *p++ );
676 *q = NULL;
677 }
678 }
679 return controlarrayW;
680 }
681
682 static inline void controlarrayfreeA( LDAPControlA **controlarray )
683 {
684 if (controlarray)
685 {
686 LDAPControlA **p = controlarray;
687 while (*p) controlfreeA( *p++ );
688 HeapFree( GetProcessHeap(), 0, controlarray );
689 }
690 }
691
692 static inline void controlarrayfreeW( LDAPControlW **controlarray )
693 {
694 if (controlarray)
695 {
696 LDAPControlW **p = controlarray;
697 while (*p) controlfreeW( *p++ );
698 HeapFree( GetProcessHeap(), 0, controlarray );
699 }
700 }
701
702 static inline void controlarrayfreeU( LDAPControl **controlarray )
703 {
704 if (controlarray)
705 {
706 LDAPControl **p = controlarray;
707 while (*p) controlfreeU( *p++ );
708 HeapFree( GetProcessHeap(), 0, controlarray );
709 }
710 }
711
712 static inline LDAPSortKeyW *sortkeyAtoW( LDAPSortKeyA *sortkey )
713 {
714 LDAPSortKeyW *sortkeyW;
715
716 sortkeyW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKeyW) );
717 if (sortkeyW)
718 {
719 sortkeyW->sk_attrtype = strAtoW( sortkey->sk_attrtype );
720 sortkeyW->sk_matchruleoid = strAtoW( sortkey->sk_matchruleoid );
721 sortkeyW->sk_reverseorder = sortkey->sk_reverseorder;
722 }
723 return sortkeyW;
724 }
725
726 static inline LDAPSortKeyA *sortkeyWtoA( LDAPSortKeyW *sortkey )
727 {
728 LDAPSortKeyA *sortkeyA;
729
730 sortkeyA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKeyA) );
731 if (sortkeyA)
732 {
733 sortkeyA->sk_attrtype = strWtoA( sortkey->sk_attrtype );
734 sortkeyA->sk_matchruleoid = strWtoA( sortkey->sk_matchruleoid );
735 sortkeyA->sk_reverseorder = sortkey->sk_reverseorder;
736 }
737 return sortkeyA;
738 }
739
740 static inline LDAPSortKey *sortkeyWtoU( LDAPSortKeyW *sortkey )
741 {
742 LDAPSortKey *sortkeyU;
743
744 sortkeyU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKey) );
745 if (sortkeyU)
746 {
747 sortkeyU->attributeType = strWtoU( sortkey->sk_attrtype );
748 sortkeyU->orderingRule = strWtoU( sortkey->sk_matchruleoid );
749 sortkeyU->reverseOrder = sortkey->sk_reverseorder;
750 }
751 return sortkeyU;
752 }
753
754 static inline void sortkeyfreeA( LDAPSortKeyA *sortkey )
755 {
756 if (sortkey)
757 {
758 strfreeA( sortkey->sk_attrtype );
759 strfreeA( sortkey->sk_matchruleoid );
760 HeapFree( GetProcessHeap(), 0, sortkey );
761 }
762 }
763
764 static inline void sortkeyfreeW( LDAPSortKeyW *sortkey )
765 {
766 if (sortkey)
767 {
768 strfreeW( sortkey->sk_attrtype );
769 strfreeW( sortkey->sk_matchruleoid );
770 HeapFree( GetProcessHeap(), 0, sortkey );
771 }
772 }
773
774 static inline void sortkeyfreeU( LDAPSortKey *sortkey )
775 {
776 if (sortkey)
777 {
778 strfreeU( sortkey->attributeType );
779 strfreeU( sortkey->orderingRule );
780 HeapFree( GetProcessHeap(), 0, sortkey );
781 }
782 }
783
784 static inline DWORD sortkeyarraylenA( LDAPSortKeyA **sortkeyarray )
785 {
786 LDAPSortKeyA **p = sortkeyarray;
787 while (*p) p++;
788 return p - sortkeyarray;
789 }
790
791 static inline DWORD sortkeyarraylenW( LDAPSortKeyW **sortkeyarray )
792 {
793 LDAPSortKeyW **p = sortkeyarray;
794 while (*p) p++;
795 return p - sortkeyarray;
796 }
797
798 static inline LDAPSortKeyW **sortkeyarrayAtoW( LDAPSortKeyA **sortkeyarray )
799 {
800 LDAPSortKeyW **sortkeyarrayW = NULL;
801 DWORD size;
802
803 if (sortkeyarray)
804 {
805 size = sizeof(LDAPSortKeyW*) * (sortkeyarraylenA( sortkeyarray ) + 1);
806 sortkeyarrayW = HeapAlloc( GetProcessHeap(), 0, size );
807
808 if (sortkeyarrayW)
809 {
810 LDAPSortKeyA **p = sortkeyarray;
811 LDAPSortKeyW **q = sortkeyarrayW;
812
813 while (*p) *q++ = sortkeyAtoW( *p++ );
814 *q = NULL;
815 }
816 }
817 return sortkeyarrayW;
818 }
819
820 static inline LDAPSortKey **sortkeyarrayWtoU( LDAPSortKeyW **sortkeyarray )
821 {
822 LDAPSortKey **sortkeyarrayU = NULL;
823 DWORD size;
824
825 if (sortkeyarray)
826 {
827 size = sizeof(LDAPSortKey*) * (sortkeyarraylenW( sortkeyarray ) + 1);
828 sortkeyarrayU = HeapAlloc( GetProcessHeap(), 0, size );
829
830 if (sortkeyarrayU)
831 {
832 LDAPSortKeyW **p = sortkeyarray;
833 LDAPSortKey **q = sortkeyarrayU;
834
835 while (*p) *q++ = sortkeyWtoU( *p++ );
836 *q = NULL;
837 }
838 }
839 return sortkeyarrayU;
840 }
841
842 static inline void sortkeyarrayfreeW( LDAPSortKeyW **sortkeyarray )
843 {
844 if (sortkeyarray)
845 {
846 LDAPSortKeyW **p = sortkeyarray;
847 while (*p) sortkeyfreeW( *p++ );
848 HeapFree( GetProcessHeap(), 0, sortkeyarray );
849 }
850 }
851
852 static inline void sortkeyarrayfreeU( LDAPSortKey **sortkeyarray )
853 {
854 if (sortkeyarray)
855 {
856 LDAPSortKey **p = sortkeyarray;
857 while (*p) sortkeyfreeU( *p++ );
858 HeapFree( GetProcessHeap(), 0, sortkeyarray );
859 }
860 }
861 #endif /* HAVE_LDAP */