Implement LDAP_OPT_API_FEATURE_INFO and LDAP_OPT_API_INFO.
[wine/multimedia.git] / dlls / wldap32 / wldap32.h
blobc84fb57aad5de30b5ad256454f28390f037b732a
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* A set of helper functions to convert LDAP data structures
22 * to and from ansi (A), wide character (W) and utf8 (U) encodings.
25 static inline LPWSTR strAtoW( LPCSTR str )
27 LPWSTR ret = NULL;
28 if (str)
30 DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
31 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
32 MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
34 return ret;
37 static inline LPSTR strWtoA( LPCWSTR str )
39 LPSTR ret = NULL;
40 if (str)
42 DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
43 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
44 WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
46 return ret;
49 static inline char *strWtoU( LPCWSTR str )
51 LPSTR ret = NULL;
52 if (str)
54 DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
55 if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
56 WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
58 return ret;
61 static inline LPWSTR strUtoW( char *str )
63 LPWSTR ret = NULL;
64 if (str)
66 DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
67 if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
68 MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
70 return ret;
73 static inline void strfreeA( LPSTR str )
75 HeapFree( GetProcessHeap(), 0, str );
78 static inline void strfreeW( LPWSTR str )
80 HeapFree( GetProcessHeap(), 0, str );
83 static inline void strfreeU( char *str )
85 HeapFree( GetProcessHeap(), 0, str );
88 static inline DWORD strarraylenA( LPSTR *strarray )
90 LPSTR *p = strarray;
91 while (*p) p++;
92 return p - strarray;
95 static inline DWORD strarraylenW( LPWSTR *strarray )
97 LPWSTR *p = strarray;
98 while (*p) p++;
99 return p - strarray;
102 static inline DWORD strarraylenU( char **strarray )
104 char **p = strarray;
105 while (*p) p++;
106 return p - strarray;
109 static inline LPWSTR *strarrayAtoW( LPSTR *strarray )
111 LPWSTR *strarrayW = NULL;
112 DWORD size;
114 if (strarray)
116 size = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1);
117 strarrayW = HeapAlloc( GetProcessHeap(), 0, size );
119 if (strarrayW)
121 LPSTR *p = strarray;
122 LPWSTR *q = strarrayW;
124 while (*p) *q++ = strAtoW( *p++ );
125 *q = NULL;
128 return strarrayW;
131 static inline LPSTR *strarrayWtoA( LPWSTR *strarray )
133 LPSTR *strarrayA = NULL;
134 DWORD size;
136 if (strarray)
138 size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1);
139 strarrayA = HeapAlloc( GetProcessHeap(), 0, size );
141 if (strarrayA)
143 LPWSTR *p = strarray;
144 LPSTR *q = strarrayA;
146 while (*p) *q++ = strWtoA( *p++ );
147 *q = NULL;
150 return strarrayA;
153 static inline char **strarrayWtoU( LPWSTR *strarray )
155 char **strarrayU = NULL;
156 DWORD size;
158 if (strarray)
160 size = sizeof(char*) * (strarraylenW( strarray ) + 1);
161 strarrayU = HeapAlloc( GetProcessHeap(), 0, size );
163 if (strarrayU)
165 LPWSTR *p = strarray;
166 char **q = strarrayU;
168 while (*p) *q++ = strWtoU( *p++ );
169 *q = NULL;
172 return strarrayU;
175 static inline LPWSTR *strarrayUtoW( char **strarray )
177 LPWSTR *strarrayW = NULL;
178 DWORD size;
180 if (strarray)
182 size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1);
183 strarrayW = HeapAlloc( GetProcessHeap(), 0, size );
185 if (strarrayW)
187 char **p = strarray;
188 LPWSTR *q = strarrayW;
190 while (*p) *q++ = strUtoW( *p++ );
191 *q = NULL;
194 return strarrayW;
197 static inline void strarrayfreeA( LPSTR *strarray )
199 if (strarray)
201 LPSTR *p = strarray;
202 while (*p) strfreeA( *p++ );
203 HeapFree( GetProcessHeap(), 0, strarray );
207 static inline void strarrayfreeW( LPWSTR *strarray )
209 if (strarray)
211 LPWSTR *p = strarray;
212 while (*p) strfreeW( *p++ );
213 HeapFree( GetProcessHeap(), 0, strarray );
217 static inline void strarrayfreeU( char **strarray )
219 if (strarray)
221 char **p = strarray;
222 while (*p) strfreeU( *p++ );
223 HeapFree( GetProcessHeap(), 0, strarray );
227 #ifdef HAVE_LDAP
229 static inline LDAPModW *modAtoW( LDAPModA *mod )
231 LDAPModW *modW;
233 modW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPModW) );
234 if (modW)
236 modW->mod_op = mod->mod_op;
237 modW->mod_type = strAtoW( mod->mod_type );
239 if (mod->mod_op & LDAP_MOD_BVALUES)
240 modW->mod_vals.modv_bvals = mod->mod_vals.modv_bvals;
241 else
242 modW->mod_vals.modv_strvals = strarrayAtoW( mod->mod_vals.modv_strvals );
244 return modW;
247 static inline LDAPMod *modWtoU( LDAPModW *mod )
249 LDAPMod *modU;
251 modU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPMod) );
252 if (modU)
254 modU->mod_op = mod->mod_op;
255 modU->mod_type = strWtoU( mod->mod_type );
257 if (mod->mod_op & LDAP_MOD_BVALUES)
258 modU->mod_vals.modv_bvals = mod->mod_vals.modv_bvals;
259 else
260 modU->mod_vals.modv_strvals = strarrayWtoU( mod->mod_vals.modv_strvals );
262 return modU;
265 static inline void modfreeW( LDAPModW *mod )
267 if (!(mod->mod_op & LDAP_MOD_BVALUES))
268 strarrayfreeW( mod->mod_vals.modv_strvals );
269 HeapFree( GetProcessHeap(), 0, mod );
272 static inline void modfreeU( LDAPMod *mod )
274 if (!(mod->mod_op & LDAP_MOD_BVALUES))
275 strarrayfreeU( mod->mod_vals.modv_strvals );
276 HeapFree( GetProcessHeap(), 0, mod );
279 static inline DWORD modarraylenA( LDAPModA **modarray )
281 LDAPModA **p = modarray;
282 while (*p) p++;
283 return p - modarray;
286 static inline DWORD modarraylenW( LDAPModW **modarray )
288 LDAPModW **p = modarray;
289 while (*p) p++;
290 return p - modarray;
293 static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
295 LDAPModW **modarrayW = NULL;
296 DWORD size;
298 if (modarray)
300 size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1);
301 modarrayW = HeapAlloc( GetProcessHeap(), 0, size );
303 if (modarrayW)
305 LDAPModA **p = modarray;
306 LDAPModW **q = modarrayW;
308 while (*p) *q++ = modAtoW( *p++ );
309 *q = NULL;
312 return modarrayW;
315 static inline LDAPMod **modarrayWtoU( LDAPModW **modarray )
317 LDAPMod **modarrayU = NULL;
318 DWORD size;
320 if (modarray)
322 size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1);
323 modarrayU = HeapAlloc( GetProcessHeap(), 0, size );
325 if (modarrayU)
327 LDAPModW **p = modarray;
328 LDAPMod **q = modarrayU;
330 while (*p) *q++ = modWtoU( *p++ );
331 *q = NULL;
334 return modarrayU;
337 static inline void modarrayfreeW( LDAPModW **modarray )
339 if (modarray)
341 LDAPModW **p = modarray;
342 while (*p) modfreeW( *p++ );
343 HeapFree( GetProcessHeap(), 0, modarray );
347 static inline void modarrayfreeU( LDAPMod **modarray )
349 if (modarray)
351 LDAPMod **p = modarray;
352 while (*p) modfreeU( *p++ );
353 HeapFree( GetProcessHeap(), 0, modarray );
357 static inline LDAPControlW *controlAtoW( LDAPControlA *control )
359 LDAPControlW *controlW;
361 controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
362 if (controlW)
364 memcpy( controlW, control, sizeof(LDAPControlW) );
365 controlW->ldctl_oid = strAtoW( control->ldctl_oid );
367 return controlW;
370 static inline LDAPControlA *controlWtoA( LDAPControlW *control )
372 LDAPControlA *controlA;
374 controlA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) );
375 if (controlA)
377 memcpy( controlA, control, sizeof(LDAPControlA) );
378 controlA->ldctl_oid = strWtoA( control->ldctl_oid );
380 return controlA;
383 static inline LDAPControl *controlWtoU( LDAPControlW *control )
385 LDAPControl *controlU;
387 controlU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) );
388 if (controlU)
390 memcpy( controlU, control, sizeof(LDAPControl) );
391 controlU->ldctl_oid = strWtoU( control->ldctl_oid );
393 return controlU;
396 static inline LDAPControlW *controlUtoW( LDAPControl *control )
398 LDAPControlW *controlW;
400 controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
401 if (controlW)
403 memcpy( controlW, control, sizeof(LDAPControlW) );
404 controlW->ldctl_oid = strUtoW( control->ldctl_oid );
406 return controlW;
409 static inline void controlfreeA( LDAPControlA *control )
411 if (control)
413 strfreeA( control->ldctl_oid );
414 HeapFree( GetProcessHeap(), 0, control );
418 static inline void controlfreeW( LDAPControlW *control )
420 if (control)
422 strfreeW( control->ldctl_oid );
423 HeapFree( GetProcessHeap(), 0, control );
427 static inline void controlfreeU( LDAPControl *control )
429 if (control)
431 strfreeU( control->ldctl_oid );
432 HeapFree( GetProcessHeap(), 0, control );
436 static inline DWORD controlarraylenA( LDAPControlA **controlarray )
438 LDAPControlA **p = controlarray;
439 while (*p) p++;
440 return p - controlarray;
443 static inline DWORD controlarraylenW( LDAPControlW **controlarray )
445 LDAPControlW **p = controlarray;
446 while (*p) p++;
447 return p - controlarray;
450 static inline DWORD controlarraylenU( LDAPControl **controlarray )
452 LDAPControl **p = controlarray;
453 while (*p) p++;
454 return p - controlarray;
457 static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray )
459 LDAPControlW **controlarrayW = NULL;
460 DWORD size;
462 if (controlarray)
464 size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1);
465 controlarrayW = HeapAlloc( GetProcessHeap(), 0, size );
467 if (controlarrayW)
469 LDAPControlA **p = controlarray;
470 LDAPControlW **q = controlarrayW;
472 while (*p) *q++ = controlAtoW( *p++ );
473 *q = NULL;
476 return controlarrayW;
479 static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
481 LDAPControlA **controlarrayA = NULL;
482 DWORD size;
484 if (controlarray)
486 size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
487 controlarrayA = HeapAlloc( GetProcessHeap(), 0, size );
489 if (controlarrayA)
491 LDAPControlW **p = controlarray;
492 LDAPControlA **q = controlarrayA;
494 while (*p) *q++ = controlWtoA( *p++ );
495 *q = NULL;
498 return controlarrayA;
501 static inline LDAPControl **controlarrayWtoU( LDAPControlW **controlarray )
503 LDAPControl **controlarrayU = NULL;
504 DWORD size;
506 if (controlarray)
508 size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
509 controlarrayU = HeapAlloc( GetProcessHeap(), 0, size );
511 if (controlarrayU)
513 LDAPControlW **p = controlarray;
514 LDAPControl **q = controlarrayU;
516 while (*p) *q++ = controlWtoU( *p++ );
517 *q = NULL;
520 return controlarrayU;
523 static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray )
525 LDAPControlW **controlarrayW = NULL;
526 DWORD size;
528 if (controlarray)
530 size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1);
531 controlarrayW = HeapAlloc( GetProcessHeap(), 0, size );
533 if (controlarrayW)
535 LDAPControl **p = controlarray;
536 LDAPControlW **q = controlarrayW;
538 while (*p) *q++ = controlUtoW( *p++ );
539 *q = NULL;
542 return controlarrayW;
545 static inline void controlarrayfreeA( LDAPControlA **controlarray )
547 if (controlarray)
549 LDAPControlA **p = controlarray;
550 while (*p) controlfreeA( *p++ );
551 HeapFree( GetProcessHeap(), 0, controlarray );
555 static inline void controlarrayfreeW( LDAPControlW **controlarray )
557 if (controlarray)
559 LDAPControlW **p = controlarray;
560 while (*p) controlfreeW( *p++ );
561 HeapFree( GetProcessHeap(), 0, controlarray );
565 static inline void controlarrayfreeU( LDAPControl **controlarray )
567 if (controlarray)
569 LDAPControl **p = controlarray;
570 while (*p) controlfreeU( *p++ );
571 HeapFree( GetProcessHeap(), 0, controlarray );
575 static inline LDAPSortKeyW *sortkeyAtoW( LDAPSortKeyA *sortkey )
577 LDAPSortKeyW *sortkeyW;
579 sortkeyW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKeyW) );
580 if (sortkeyW)
582 sortkeyW->sk_attrtype = strAtoW( sortkey->sk_attrtype );
583 sortkeyW->sk_matchruleoid = strAtoW( sortkey->sk_matchruleoid );
584 sortkeyW->sk_reverseorder = sortkey->sk_reverseorder;
586 return sortkeyW;
589 static inline LDAPSortKeyA *sortkeyWtoA( LDAPSortKeyW *sortkey )
591 LDAPSortKeyA *sortkeyA;
593 sortkeyA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKeyA) );
594 if (sortkeyA)
596 sortkeyA->sk_attrtype = strWtoA( sortkey->sk_attrtype );
597 sortkeyA->sk_matchruleoid = strWtoA( sortkey->sk_matchruleoid );
598 sortkeyA->sk_reverseorder = sortkey->sk_reverseorder;
600 return sortkeyA;
603 static inline LDAPSortKey *sortkeyWtoU( LDAPSortKeyW *sortkey )
605 LDAPSortKey *sortkeyU;
607 sortkeyU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKey) );
608 if (sortkeyU)
610 sortkeyU->attributeType = strWtoU( sortkey->sk_attrtype );
611 sortkeyU->orderingRule = strWtoU( sortkey->sk_matchruleoid );
612 sortkeyU->reverseOrder = sortkey->sk_reverseorder;
614 return sortkeyU;
617 static inline void sortkeyfreeA( LDAPSortKeyA *sortkey )
619 if (sortkey)
621 strfreeA( sortkey->sk_attrtype );
622 strfreeA( sortkey->sk_matchruleoid );
623 HeapFree( GetProcessHeap(), 0, sortkey );
627 static inline void sortkeyfreeW( LDAPSortKeyW *sortkey )
629 if (sortkey)
631 strfreeW( sortkey->sk_attrtype );
632 strfreeW( sortkey->sk_matchruleoid );
633 HeapFree( GetProcessHeap(), 0, sortkey );
637 static inline void sortkeyfreeU( LDAPSortKey *sortkey )
639 if (sortkey)
641 strfreeU( sortkey->attributeType );
642 strfreeU( sortkey->orderingRule );
643 HeapFree( GetProcessHeap(), 0, sortkey );
647 static inline DWORD sortkeyarraylenA( LDAPSortKeyA **sortkeyarray )
649 LDAPSortKeyA **p = sortkeyarray;
650 while (*p) p++;
651 return p - sortkeyarray;
654 static inline DWORD sortkeyarraylenW( LDAPSortKeyW **sortkeyarray )
656 LDAPSortKeyW **p = sortkeyarray;
657 while (*p) p++;
658 return p - sortkeyarray;
661 static inline LDAPSortKeyW **sortkeyarrayAtoW( LDAPSortKeyA **sortkeyarray )
663 LDAPSortKeyW **sortkeyarrayW = NULL;
664 DWORD size;
666 if (sortkeyarray)
668 size = sizeof(LDAPSortKeyW*) * (sortkeyarraylenA( sortkeyarray ) + 1);
669 sortkeyarrayW = HeapAlloc( GetProcessHeap(), 0, size );
671 if (sortkeyarrayW)
673 LDAPSortKeyA **p = sortkeyarray;
674 LDAPSortKeyW **q = sortkeyarrayW;
676 while (*p) *q++ = sortkeyAtoW( *p++ );
677 *q = NULL;
680 return sortkeyarrayW;
683 static inline LDAPSortKey **sortkeyarrayWtoU( LDAPSortKeyW **sortkeyarray )
685 LDAPSortKey **sortkeyarrayU = NULL;
686 DWORD size;
688 if (sortkeyarray)
690 size = sizeof(LDAPSortKey*) * (sortkeyarraylenW( sortkeyarray ) + 1);
691 sortkeyarrayU = HeapAlloc( GetProcessHeap(), 0, size );
693 if (sortkeyarrayU)
695 LDAPSortKeyW **p = sortkeyarray;
696 LDAPSortKey **q = sortkeyarrayU;
698 while (*p) *q++ = sortkeyWtoU( *p++ );
699 *q = NULL;
702 return sortkeyarrayU;
705 static inline void sortkeyarrayfreeW( LDAPSortKeyW **sortkeyarray )
707 if (sortkeyarray)
709 LDAPSortKeyW **p = sortkeyarray;
710 while (*p) sortkeyfreeW( *p++ );
711 HeapFree( GetProcessHeap(), 0, sortkeyarray );
715 static inline void sortkeyarrayfreeU( LDAPSortKey **sortkeyarray )
717 if (sortkeyarray)
719 LDAPSortKey **p = sortkeyarray;
720 while (*p) sortkeyfreeU( *p++ );
721 HeapFree( GetProcessHeap(), 0, sortkeyarray );
725 #endif /* HAVE_LDAP */