mfmediaengine: Remove vertical flipping of video frames.
[wine.git] / dlls / wldap32 / winldap_private.h
blobb8b6daf5a507656f03fb9c81ae80390d8cab8b5c
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 <stdlib.h>
23 #include "winternl.h"
24 #include "winnls.h"
25 #include "libldap.h"
27 typedef struct ldapsearch
29 WCHAR *dn;
30 WCHAR *filter;
31 WCHAR **attrs;
32 ULONG scope;
33 ULONG attrsonly;
34 LDAPControlW **serverctrls;
35 LDAPControlW **clientctrls;
36 struct l_timeval timeout;
37 ULONG sizelimit;
38 struct berval *cookie;
39 } LDAPSearch;
41 #define CTX(ld) (*(void **)ld->Reserved3)
42 #define SERVER_CTRLS(ld) (*(void **)(ld->Reserved3 + sizeof(void *)))
43 #define MSG(entry) (entry->Request)
44 #define BER(ber) (ber->opaque)
46 ULONG map_error( int ) DECLSPEC_HIDDEN;
48 static inline char *strdupU( const char *src )
50 char *dst;
51 if (!src) return NULL;
52 if ((dst = malloc( strlen( src ) + 1 ))) strcpy( dst, src );
53 return dst;
56 static inline WCHAR *strdupW( const WCHAR *src )
58 WCHAR *dst;
59 if (!src) return NULL;
60 if ((dst = malloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) ))) lstrcpyW( dst, src );
61 return dst;
64 static inline char *strWtoU( const WCHAR *str )
66 char *ret = NULL;
67 if (str)
69 int len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
70 if ((ret = malloc( len ))) WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
72 return ret;
75 static inline char *strnWtoU( const WCHAR *str, DWORD in_len, DWORD *out_len )
77 char *ret = NULL;
78 *out_len = 0;
79 if (str)
81 DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, in_len, NULL, 0, NULL, NULL );
82 if ((ret = malloc( len + 1 )))
84 WideCharToMultiByte( CP_UTF8, 0, str, in_len, ret, len, NULL, NULL );
85 ret[len] = 0;
86 *out_len = len;
89 return ret;
92 static inline WCHAR *strAtoW( const char *str )
94 WCHAR *ret = NULL;
95 if (str)
97 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
98 if ((ret = malloc( len * sizeof(WCHAR) ))) MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
100 return ret;
103 static inline WCHAR *strnAtoW( const char *str, DWORD in_len, DWORD *out_len )
105 WCHAR *ret = NULL;
106 *out_len = 0;
107 if (str)
109 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, in_len, NULL, 0 );
110 if ((ret = malloc( (len + 1) * sizeof(WCHAR) )))
112 MultiByteToWideChar( CP_ACP, 0, str, in_len, ret, len );
113 ret[len] = 0;
114 *out_len = len;
117 return ret;
120 static inline DWORD bvarraylenW( struct berval **bv )
122 struct berval **p = bv;
123 while (*p) p++;
124 return p - bv;
127 static inline DWORD strarraylenW( WCHAR **strarray )
129 WCHAR **p = strarray;
130 while (*p) p++;
131 return p - strarray;
134 static inline char **strarrayWtoU( WCHAR **strarray )
136 char **strarrayU = NULL;
137 DWORD size;
139 if (strarray)
141 size = sizeof(char *) * (strarraylenW( strarray ) + 1);
142 if ((strarrayU = malloc( size )))
144 WCHAR **p = strarray;
145 char **q = strarrayU;
147 while (*p) *q++ = strWtoU( *p++ );
148 *q = NULL;
151 return strarrayU;
154 static inline WCHAR **strarraydupW( WCHAR **strarray )
156 WCHAR **strarrayW = NULL;
157 DWORD size;
159 if (strarray)
161 size = sizeof(WCHAR *) * (strarraylenW( strarray ) + 1);
162 if ((strarrayW = malloc( size )))
164 WCHAR **p = strarray;
165 WCHAR **q = strarrayW;
167 while (*p) *q++ = strdupW( *p++ );
168 *q = NULL;
171 return strarrayW;
174 static inline char *strWtoA( const WCHAR *str )
176 char *ret = NULL;
177 if (str)
179 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
180 if ((ret = malloc( len ))) WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
182 return ret;
185 static inline char **strarrayWtoA( WCHAR **strarray )
187 char **strarrayA = NULL;
188 DWORD size;
190 if (strarray)
192 size = sizeof(char *) * (strarraylenW( strarray ) + 1);
193 if ((strarrayA = malloc( size )))
195 WCHAR **p = strarray;
196 char **q = strarrayA;
198 while (*p) *q++ = strWtoA( *p++ );
199 *q = NULL;
202 return strarrayA;
205 static inline DWORD modarraylenW( LDAPModW **modarray )
207 LDAPModW **p = modarray;
208 while (*p) p++;
209 return p - modarray;
212 static inline struct bervalU *bervalWtoU( const struct berval *bv )
214 struct bervalU *berval;
215 DWORD size = sizeof(*berval) + bv->bv_len;
217 if ((berval = malloc( size )))
219 char *val = (char *)(berval + 1);
221 berval->bv_len = bv->bv_len;
222 berval->bv_val = val;
223 memcpy( val, bv->bv_val, bv->bv_len );
225 return berval;
228 static inline DWORD bvarraylenU( struct bervalU **bv )
230 struct bervalU **p = bv;
231 while (*p) p++;
232 return p - bv;
235 static inline struct berval *bervalUtoW( const struct bervalU *bv )
237 struct berval *berval;
238 DWORD size = sizeof(*berval) + bv->bv_len;
240 assert( bv->bv_len <= ~0u );
242 if ((berval = malloc( size )))
244 char *val = (char *)(berval + 1);
246 berval->bv_len = bv->bv_len;
247 berval->bv_val = val;
248 memcpy( val, bv->bv_val, bv->bv_len );
250 return berval;
253 static inline struct berval **bvarrayUtoW( struct bervalU **bv )
255 struct berval **berval = NULL;
256 DWORD size;
258 if (bv)
260 size = sizeof(*berval) * (bvarraylenU( bv ) + 1);
261 if ((berval = malloc( size )))
263 struct bervalU **p = bv;
264 struct berval **q = berval;
266 while (*p) *q++ = bervalUtoW( *p++ );
267 *q = NULL;
270 return berval;
273 static inline void bvfreeU( struct bervalU *berval )
275 free( berval );
278 static inline struct bervalU **bvarrayWtoU( struct berval **bv )
280 struct bervalU **berval = NULL;
281 DWORD size;
283 if (bv)
285 size = sizeof(*berval) * (bvarraylenW( bv ) + 1);
286 if ((berval = malloc( size )))
288 struct berval **p = bv;
289 struct bervalU **q = berval;
291 while (*p) *q++ = bervalWtoU( *p++ );
292 *q = NULL;
295 return berval;
298 static inline LDAPModU *modWtoU( const LDAPModW *mod )
300 LDAPModU *modU;
302 if ((modU = malloc( sizeof(*modU) )))
304 modU->mod_op = mod->mod_op;
305 modU->mod_type = strWtoU( mod->mod_type );
307 if (mod->mod_op & LDAP_MOD_BVALUES)
308 modU->mod_vals.modv_bvals = bvarrayWtoU( mod->mod_vals.modv_bvals );
309 else
310 modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
312 return modU;
315 static inline LDAPModU **modarrayWtoU( LDAPModW **modarray )
317 LDAPModU **modarrayU = NULL;
318 DWORD size;
320 if (modarray)
322 size = sizeof(LDAPModU *) * (modarraylenW( modarray ) + 1);
323 if ((modarrayU = malloc( size )))
325 LDAPModW **p = modarray;
326 LDAPModU **q = modarrayU;
328 while (*p) *q++ = modWtoU( *p++ );
329 *q = NULL;
332 return modarrayU;
335 static inline void bvarrayfreeU( struct bervalU **bv )
337 struct bervalU **p = bv;
338 while (*p) free( *p++ );
339 free( bv );
342 static inline void strarrayfreeU( char **strarray )
344 if (strarray)
346 char **p = strarray;
347 while (*p) free( *p++ );
348 free( strarray );
352 static inline void modfreeU( LDAPModU *mod )
354 if (mod->mod_op & LDAP_MOD_BVALUES)
355 bvarrayfreeU( mod->mod_vals.modv_bvals );
356 else
357 strarrayfreeU( mod->mod_vals.modv_strvals );
358 free( mod );
361 static inline void modarrayfreeU( LDAPModU **modarray )
363 if (modarray)
365 LDAPModU **p = modarray;
366 while (*p) modfreeU( *p++ );
367 free( modarray );
371 static inline DWORD modarraylenA( LDAPModA **modarray )
373 LDAPModA **p = modarray;
374 while (*p) p++;
375 return p - modarray;
378 static inline struct berval *bervalWtoW( const struct berval *bv )
380 struct berval *berval;
381 DWORD size = sizeof(*berval) + bv->bv_len;
383 if ((berval = malloc( size )))
385 char *val = (char *)(berval + 1);
387 berval->bv_len = bv->bv_len;
388 berval->bv_val = val;
389 memcpy( val, bv->bv_val, bv->bv_len );
391 return berval;
394 static inline struct berval **bvarrayWtoW( struct berval **bv )
396 struct berval **berval = NULL;
397 DWORD size;
399 if (bv)
401 size = sizeof(*berval) * (bvarraylenW( bv ) + 1);
402 if ((berval = malloc( size )))
404 struct berval **p = bv;
405 struct berval **q = berval;
407 while (*p) *q++ = bervalWtoW( *p++ );
408 *q = NULL;
411 return berval;
414 static inline DWORD strarraylenA( char **strarray )
416 char **p = strarray;
417 while (*p) p++;
418 return p - strarray;
421 static inline WCHAR **strarrayAtoW( char **strarray )
423 WCHAR **strarrayW = NULL;
424 DWORD size;
426 if (strarray)
428 size = sizeof(WCHAR *) * (strarraylenA( strarray ) + 1);
429 if ((strarrayW = malloc( size )))
431 char **p = strarray;
432 WCHAR **q = strarrayW;
434 while (*p) *q++ = strAtoW( *p++ );
435 *q = NULL;
438 return strarrayW;
441 static inline LDAPModW *modAtoW( const LDAPModA *mod )
443 LDAPModW *modW;
445 if ((modW = malloc( sizeof(*modW) )))
447 modW->mod_op = mod->mod_op;
448 modW->mod_type = strAtoW( mod->mod_type );
450 if (mod->mod_op & LDAP_MOD_BVALUES)
451 modW->mod_vals.modv_bvals = bvarrayWtoW( mod->mod_vals.modv_bvals );
452 else
453 modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
455 return modW;
458 static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
460 LDAPModW **modarrayW = NULL;
461 DWORD size;
463 if (modarray)
465 size = sizeof(LDAPModW *) * (modarraylenA( modarray ) + 1);
466 if ((modarrayW = malloc( size )))
468 LDAPModA **p = modarray;
469 LDAPModW **q = modarrayW;
471 while (*p) *q++ = modAtoW( *p++ );
472 *q = NULL;
475 return modarrayW;
478 static inline void bvarrayfreeW( struct berval **bv )
480 struct berval **p = bv;
481 while (*p) free( *p++ );
482 free( bv );
485 static inline void strarrayfreeW( WCHAR **strarray )
487 if (strarray)
489 WCHAR **p = strarray;
490 while (*p) free( *p++ );
491 free( strarray );
495 static inline void modfreeW( LDAPModW *mod )
497 if (mod->mod_op & LDAP_MOD_BVALUES)
498 bvarrayfreeW( mod->mod_vals.modv_bvals );
499 else
500 strarrayfreeW( mod->mod_vals.modv_strvals );
501 free( mod );
504 static inline void modarrayfreeW( LDAPModW **modarray )
506 if (modarray)
508 LDAPModW **p = modarray;
509 while (*p) modfreeW( *p++ );
510 free( modarray );
514 static inline DWORD controlarraylenA( LDAPControlA **controlarray )
516 LDAPControlA **p = controlarray;
517 while (*p) p++;
518 return p - controlarray;
521 static inline LDAPControlW *controlAtoW( const LDAPControlA *control )
523 LDAPControlW *controlW;
524 DWORD len = control->ldctl_value.bv_len;
525 char *val = NULL;
527 if (control->ldctl_value.bv_val)
529 if (!(val = malloc( len ))) return NULL;
530 memcpy( val, control->ldctl_value.bv_val, len );
533 if (!(controlW = malloc( sizeof(*controlW) )))
535 free( val );
536 return NULL;
539 controlW->ldctl_oid = strAtoW( control->ldctl_oid );
540 controlW->ldctl_value.bv_len = len;
541 controlW->ldctl_value.bv_val = val;
542 controlW->ldctl_iscritical = control->ldctl_iscritical;
544 return controlW;
547 static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray )
549 LDAPControlW **controlarrayW = NULL;
550 DWORD size;
552 if (controlarray)
554 size = sizeof(LDAPControlW *) * (controlarraylenA( controlarray ) + 1);
555 if ((controlarrayW = malloc( size )))
557 LDAPControlA **p = controlarray;
558 LDAPControlW **q = controlarrayW;
560 while (*p) *q++ = controlAtoW( *p++ );
561 *q = NULL;
564 return controlarrayW;
567 static inline void controlfreeW( LDAPControlW *control )
569 if (control)
571 free( control->ldctl_oid );
572 free( control->ldctl_value.bv_val );
573 free( control );
577 static inline void controlarrayfreeW( LDAPControlW **controlarray )
579 if (controlarray)
581 LDAPControlW **p = controlarray;
582 while (*p) controlfreeW( *p++ );
583 free( controlarray );
587 static inline DWORD controlarraylenW( LDAPControlW **controlarray )
589 LDAPControlW **p = controlarray;
590 while (*p) p++;
591 return p - controlarray;
594 static inline LDAPControlA *controlWtoA( const LDAPControlW *control )
596 LDAPControlA *controlA;
597 DWORD len = control->ldctl_value.bv_len;
598 char *val = NULL;
600 if (control->ldctl_value.bv_val)
602 if (!(val = malloc( len ))) return NULL;
603 memcpy( val, control->ldctl_value.bv_val, len );
606 if (!(controlA = malloc( sizeof(*controlA) )))
608 free( val );
609 return NULL;
612 controlA->ldctl_oid = strWtoA( control->ldctl_oid );
613 controlA->ldctl_value.bv_len = len;
614 controlA->ldctl_value.bv_val = val;
615 controlA->ldctl_iscritical = control->ldctl_iscritical;
617 return controlA;
620 static inline void strarrayfreeA( char **strarray )
622 if (strarray)
624 char **p = strarray;
625 while (*p) free( *p++ );
626 free( strarray );
630 static inline void controlfreeA( LDAPControlA *control )
632 if (control)
634 free( control->ldctl_oid );
635 free( control->ldctl_value.bv_val );
636 free( control );
640 static inline void controlarrayfreeA( LDAPControlA **controlarray )
642 if (controlarray)
644 LDAPControlA **p = controlarray;
645 while (*p) controlfreeA( *p++ );
646 free( controlarray );
650 static inline LDAPControlU *controlWtoU( const LDAPControlW *control )
652 LDAPControlU *controlU;
653 DWORD len = control->ldctl_value.bv_len;
654 char *val = NULL;
656 if (control->ldctl_value.bv_val)
658 if (!(val = malloc( len ))) return NULL;
659 memcpy( val, control->ldctl_value.bv_val, len );
662 if (!(controlU = malloc( sizeof(*controlU) )))
664 free( val );
665 return NULL;
668 controlU->ldctl_oid = strWtoU( control->ldctl_oid );
669 controlU->ldctl_value.bv_len = len;
670 controlU->ldctl_value.bv_val = val;
671 controlU->ldctl_iscritical = control->ldctl_iscritical;
673 return controlU;
676 static inline LDAPControlU **controlarrayWtoU( LDAPControlW **controlarray )
678 LDAPControlU **controlarrayU = NULL;
679 DWORD size;
681 if (controlarray)
683 size = sizeof(LDAPControlU *) * (controlarraylenW( controlarray ) + 1);
684 if ((controlarrayU = malloc( size )))
686 LDAPControlW **p = controlarray;
687 LDAPControlU **q = controlarrayU;
689 while (*p) *q++ = controlWtoU( *p++ );
690 *q = NULL;
693 return controlarrayU;
696 static inline void controlfreeU( LDAPControlU *control )
698 if (control)
700 free( control->ldctl_oid );
701 free( control->ldctl_value.bv_val );
702 free( control );
706 static inline void controlarrayfreeU( LDAPControlU **controlarray )
708 if (controlarray)
710 LDAPControlU **p = controlarray;
711 while (*p) controlfreeU( *p++ );
712 free( controlarray );
716 static inline DWORD controlarraylenU( LDAPControlU **controlarray )
718 LDAPControlU **p = controlarray;
719 while (*p) p++;
720 return p - controlarray;
723 static inline LDAPControlW *controldupW( LDAPControlW *control )
725 LDAPControlW *controlW;
726 DWORD len = control->ldctl_value.bv_len;
727 char *val = NULL;
729 if (control->ldctl_value.bv_val)
731 if (!(val = malloc( len ))) return NULL;
732 memcpy( val, control->ldctl_value.bv_val, len );
735 if (!(controlW = malloc( sizeof(*controlW) )))
737 free( val );
738 return NULL;
741 controlW->ldctl_oid = strdupW( control->ldctl_oid );
742 controlW->ldctl_value.bv_len = len;
743 controlW->ldctl_value.bv_val = val;
744 controlW->ldctl_iscritical = control->ldctl_iscritical;
746 return controlW;
749 static inline LDAPControlW **controlarraydupW( LDAPControlW **controlarray )
751 LDAPControlW **controlarrayW = NULL;
752 DWORD size;
754 if (controlarray)
756 size = sizeof(LDAPControlW *) * (controlarraylenW( controlarray ) + 1);
757 if ((controlarrayW = malloc( size )))
759 LDAPControlW **p = controlarray;
760 LDAPControlW **q = controlarrayW;
762 while (*p) *q++ = controldupW( *p++ );
763 *q = NULL;
766 return controlarrayW;
769 static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
771 LDAPControlA **controlarrayA = NULL;
772 DWORD size;
774 if (controlarray)
776 size = sizeof(LDAPControlA *) * (controlarraylenW( controlarray ) + 1);
777 if ((controlarrayA = malloc( size )))
779 LDAPControlW **p = controlarray;
780 LDAPControlA **q = controlarrayA;
782 while (*p) *q++ = controlWtoA( *p++ );
783 *q = NULL;
786 return controlarrayA;
789 static inline WCHAR *strUtoW( const char *str )
791 WCHAR *ret = NULL;
792 if (str)
794 DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
795 if ((ret = malloc( len * sizeof(WCHAR) ))) MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
797 return ret;
800 static inline DWORD strarraylenU( char **strarray )
802 char **p = strarray;
803 while (*p) p++;
804 return p - strarray;
807 static inline WCHAR **strarrayUtoW( char **strarray )
809 WCHAR **strarrayW = NULL;
810 DWORD size;
812 if (strarray)
814 size = sizeof(WCHAR *) * (strarraylenU( strarray ) + 1);
815 if ((strarrayW = malloc( size )))
817 char **p = strarray;
818 WCHAR **q = strarrayW;
820 while (*p) *q++ = strUtoW( *p++ );
821 *q = NULL;
824 return strarrayW;
827 static inline char **strarrayUtoU( char **strarray )
829 char **strarrayU = NULL;
830 DWORD size;
832 if (strarray)
834 size = sizeof(char *) * (strarraylenU( strarray ) + 1);
835 if ((strarrayU = malloc( size )))
837 char **p = strarray;
838 char **q = strarrayU;
840 while (*p) *q++ = strdupU( *p++ );
841 *q = NULL;
844 return strarrayU;
847 static inline LDAPControlW *controlUtoW( const LDAPControlU *control )
849 LDAPControlW *controlW;
850 DWORD len = control->ldctl_value.bv_len;
851 char *val = NULL;
853 if (control->ldctl_value.bv_val)
855 if (!(val = malloc( len ))) return NULL;
856 memcpy( val, control->ldctl_value.bv_val, len );
859 if (!(controlW = malloc( sizeof(*controlW) )))
861 free( val );
862 return NULL;
865 controlW->ldctl_oid = strUtoW( control->ldctl_oid );
866 controlW->ldctl_value.bv_len = len;
867 controlW->ldctl_value.bv_val = val;
868 controlW->ldctl_iscritical = control->ldctl_iscritical;
870 return controlW;
873 static inline LDAPControlW **controlarrayUtoW( LDAPControlU **controlarray )
875 LDAPControlW **controlarrayW = NULL;
876 DWORD size;
878 if (controlarray)
880 size = sizeof(LDAPControlW *) * (controlarraylenU( controlarray ) + 1);
881 if ((controlarrayW = malloc( size )))
883 LDAPControlU **p = controlarray;
884 LDAPControlW **q = controlarrayW;
886 while (*p) *q++ = controlUtoW( *p++ );
887 *q = NULL;
890 return controlarrayW;
893 static inline DWORD sortkeyarraylenA( LDAPSortKeyA **sortkeyarray )
895 LDAPSortKeyA **p = sortkeyarray;
896 while (*p) p++;
897 return p - sortkeyarray;
900 static inline LDAPSortKeyW *sortkeyAtoW( const LDAPSortKeyA *sortkey )
902 LDAPSortKeyW *sortkeyW;
904 if ((sortkeyW = malloc( sizeof(*sortkeyW) )))
906 sortkeyW->sk_attrtype = strAtoW( sortkey->sk_attrtype );
907 sortkeyW->sk_matchruleoid = strAtoW( sortkey->sk_matchruleoid );
908 sortkeyW->sk_reverseorder = sortkey->sk_reverseorder;
910 return sortkeyW;
913 static inline LDAPSortKeyW **sortkeyarrayAtoW( LDAPSortKeyA **sortkeyarray )
915 LDAPSortKeyW **sortkeyarrayW = NULL;
916 DWORD size;
918 if (sortkeyarray)
920 size = sizeof(LDAPSortKeyW *) * (sortkeyarraylenA( sortkeyarray ) + 1);
921 if ((sortkeyarrayW = malloc( size )))
923 LDAPSortKeyA **p = sortkeyarray;
924 LDAPSortKeyW **q = sortkeyarrayW;
926 while (*p) *q++ = sortkeyAtoW( *p++ );
927 *q = NULL;
930 return sortkeyarrayW;
933 static inline void sortkeyfreeW( LDAPSortKeyW *sortkey )
935 if (sortkey)
937 free( sortkey->sk_attrtype );
938 free( sortkey->sk_matchruleoid );
939 free( sortkey );
943 static inline void sortkeyarrayfreeW( LDAPSortKeyW **sortkeyarray )
945 if (sortkeyarray)
947 LDAPSortKeyW **p = sortkeyarray;
948 while (*p) sortkeyfreeW( *p++ );
949 free( sortkeyarray );
953 static inline DWORD sortkeyarraylenW( LDAPSortKeyW **sortkeyarray )
955 LDAPSortKeyW **p = sortkeyarray;
956 while (*p) p++;
957 return p - sortkeyarray;
960 static inline LDAPSortKeyU *sortkeyWtoU( const LDAPSortKeyW *sortkey )
962 LDAPSortKeyU *sortkeyU;
964 if ((sortkeyU = malloc( sizeof(*sortkeyU) )))
966 sortkeyU->attributeType = strWtoU( sortkey->sk_attrtype );
967 sortkeyU->orderingRule = strWtoU( sortkey->sk_matchruleoid );
968 sortkeyU->reverseOrder = sortkey->sk_reverseorder;
970 return sortkeyU;
973 static inline LDAPSortKeyU **sortkeyarrayWtoU( LDAPSortKeyW **sortkeyarray )
975 LDAPSortKeyU **sortkeyarrayU = NULL;
976 DWORD size;
978 if (sortkeyarray)
980 size = sizeof(LDAPSortKeyU *) * (sortkeyarraylenW( sortkeyarray ) + 1);
981 if ((sortkeyarrayU = malloc( size )))
983 LDAPSortKeyW **p = sortkeyarray;
984 LDAPSortKeyU **q = sortkeyarrayU;
986 while (*p) *q++ = sortkeyWtoU( *p++ );
987 *q = NULL;
990 return sortkeyarrayU;
993 static inline void sortkeyfreeU( LDAPSortKeyU *sortkey )
995 if (sortkey)
997 free( sortkey->attributeType );
998 free( sortkey->orderingRule );
999 free( sortkey );
1003 static inline void sortkeyarrayfreeU( LDAPSortKeyU **sortkeyarray )
1005 if (sortkeyarray)
1007 LDAPSortKeyU **p = sortkeyarray;
1008 while (*p) sortkeyfreeU( *p++ );
1009 free( sortkeyarray );
1013 static inline LDAPVLVInfoU *vlvinfoWtoU( const LDAPVLVInfo *info )
1015 LDAPVLVInfoU *infoU;
1017 if ((infoU = malloc( sizeof(*infoU) )))
1019 infoU->ldvlv_version = info->ldvlv_version;
1020 infoU->ldvlv_before_count = info->ldvlv_before_count;
1021 infoU->ldvlv_after_count = info->ldvlv_after_count;
1022 infoU->ldvlv_offset = info->ldvlv_offset;
1023 infoU->ldvlv_count = info->ldvlv_count;
1024 if (!(infoU->ldvlv_attrvalue = bervalWtoU( info->ldvlv_attrvalue )))
1026 free( infoU );
1027 return NULL;
1029 if (!(infoU->ldvlv_context = bervalWtoU( info->ldvlv_context )))
1031 free( infoU->ldvlv_attrvalue );
1032 free( infoU );
1033 return NULL;
1035 infoU->ldvlv_extradata = info->ldvlv_extradata;
1037 return infoU;
1040 static inline void vlvinfofreeU( LDAPVLVInfoU *info )
1042 free( info->ldvlv_attrvalue );
1043 free( info->ldvlv_context );
1044 free( info );