widl: Fix the detection of conformant and pointer structs.
[wine/wine64.git] / dlls / wldap32 / page.c
blobef700575f31ed1749340fecaf5fd02384f4db9ba
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 #include "config.h"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
37 #endif
39 #include "winldap_private.h"
40 #include "wldap32.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 /***********************************************************************
45 * ldap_create_page_controlA (WLDAP32.@)
47 * See ldap_create_page_controlW.
49 ULONG ldap_create_page_controlA( WLDAP32_LDAP *ld, ULONG pagesize,
50 struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlA *control )
52 ULONG ret = LDAP_NOT_SUPPORTED;
53 #ifdef HAVE_LDAP
54 LDAPControlW *controlW = NULL;
56 TRACE( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
57 critical, control );
59 if (!ld || !control) return WLDAP32_LDAP_PARAM_ERROR;
61 ret = ldap_create_page_controlW( ld, pagesize, cookie, critical, &controlW );
62 if (ret == LDAP_SUCCESS)
64 *control = controlWtoA( controlW );
65 ldap_control_freeW( controlW );
68 #endif
69 return ret;
72 #ifdef HAVE_LDAP
74 /* create a page control by hand */
75 static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie,
76 UCHAR critical, PLDAPControlW *control )
78 LDAPControlW *ctrl;
79 BerElement *ber;
80 struct berval *berval, null_cookie = { 0, NULL };
81 INT ret, len;
82 char *val;
84 ber = ber_alloc_t( LBER_USE_DER );
85 if (!ber) return WLDAP32_LDAP_NO_MEMORY;
87 if (cookie)
88 ber_printf( ber, "{iO}", pagesize, cookie );
89 else
90 ber_printf( ber, "{iO}", pagesize, &null_cookie );
92 ret = ber_flatten( ber, &berval );
93 ber_free( ber, 1 );
95 if (ret == -1)
96 return WLDAP32_LDAP_NO_MEMORY;
98 /* copy the berval so it can be properly freed by the caller */
99 val = HeapAlloc( GetProcessHeap(), 0, berval->bv_len );
100 if (!val) return WLDAP32_LDAP_NO_MEMORY;
102 len = berval->bv_len;
103 memcpy( val, berval->bv_val, len );
104 ber_bvfree( berval );
106 ctrl = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
107 if (!ctrl)
108 return WLDAP32_LDAP_NO_MEMORY;
110 ctrl->ldctl_oid = strAtoW( LDAP_PAGED_RESULT_OID_STRING );
111 ctrl->ldctl_value.bv_len = len;
112 ctrl->ldctl_value.bv_val = val;
113 ctrl->ldctl_iscritical = critical;
115 *control = ctrl;
117 return LDAP_SUCCESS;
120 #endif /* HAVE_LDAP */
122 /***********************************************************************
123 * ldap_create_page_controlW (WLDAP32.@)
125 * Create a control for paged search results.
127 * PARAMS
128 * ld [I] Pointer to an LDAP context.
129 * pagesize [I] Number of entries to return per page.
130 * cookie [I] Used by the server to track its location in the
131 * search results.
132 * critical [I] Tells the server this control is critical to the
133 * search operation.
134 * control [O] LDAPControl created.
136 * RETURNS
137 * Success: LDAP_SUCCESS
138 * Failure: An LDAP error code.
140 ULONG ldap_create_page_controlW( WLDAP32_LDAP *ld, ULONG pagesize,
141 struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlW *control )
143 ULONG ret = LDAP_NOT_SUPPORTED;
144 #ifdef HAVE_LDAP
146 TRACE( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
147 critical, control );
149 if (!ld || !control) return WLDAP32_LDAP_PARAM_ERROR;
150 return create_page_control( pagesize, cookie, critical, control );
152 #endif
153 return ret;
156 ULONG ldap_get_next_page( WLDAP32_LDAP *ld, PLDAPSearch search, ULONG pagesize,
157 ULONG *message )
159 FIXME( "(%p, %p, 0x%08lx, %p)\n", ld, search, pagesize, message );
161 if (!ld) return ~0UL;
162 return LDAP_NOT_SUPPORTED;
165 ULONG ldap_get_next_page_s( WLDAP32_LDAP *ld, PLDAPSearch search,
166 struct l_timeval *timeout, ULONG pagesize, ULONG *count,
167 WLDAP32_LDAPMessage **results )
169 FIXME( "(%p, %p, %p, 0x%08lx, %p, %p)\n", ld, search, timeout,
170 pagesize, count, results );
172 if (!ld) return ~0UL;
173 return LDAP_NOT_SUPPORTED;
176 ULONG ldap_get_paged_count( WLDAP32_LDAP *ld, PLDAPSearch search,
177 ULONG *count, WLDAP32_LDAPMessage *results )
179 ULONG ret = LDAP_NOT_SUPPORTED;
180 #ifdef HAVE_LDAP
181 FIXME( "(%p, %p, %p, %p)\n", ld, search, count, results );
183 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
184 /* FIXME: save the cookie from the server here */
186 #endif
187 return ret;
190 /***********************************************************************
191 * ldap_parse_page_controlA (WLDAP32.@)
193 ULONG ldap_parse_page_controlA( WLDAP32_LDAP *ld, PLDAPControlA *ctrls,
194 ULONG *count, struct WLDAP32_berval **cookie )
196 ULONG ret = LDAP_NOT_SUPPORTED;
197 #ifdef HAVE_LDAP
198 LDAPControlW **ctrlsW = NULL;
200 TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
202 if (!ld || !ctrls || !count || !cookie)
203 return WLDAP32_LDAP_PARAM_ERROR;
205 ctrlsW = controlarrayAtoW( ctrls );
206 if (!ctrlsW) return WLDAP32_LDAP_NO_MEMORY;
208 ret = ldap_parse_page_controlW( ld, ctrlsW, count, cookie );
209 controlarrayfreeW( ctrlsW );
211 #endif
212 return ret;
215 /***********************************************************************
216 * ldap_parse_page_controlW (WLDAP32.@)
218 ULONG ldap_parse_page_controlW( WLDAP32_LDAP *ld, PLDAPControlW *ctrls,
219 ULONG *count, struct WLDAP32_berval **cookie )
221 ULONG ret = LDAP_NOT_SUPPORTED;
222 #ifdef HAVE_LDAP
223 LDAPControlW *control = NULL;
224 BerElement *ber;
225 ber_tag_t tag;
226 ULONG i;
228 TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
230 if (!ld || !ctrls || !count || !cookie)
231 return WLDAP32_LDAP_PARAM_ERROR;
233 for (i = 0; ctrls[i]; i++)
235 if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W, ctrls[i]->ldctl_oid ))
236 control = ctrls[i];
239 if (!control)
240 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
242 ber = ber_init( &((LDAPControl *)control)->ldctl_value );
243 if (!ber)
244 return WLDAP32_LDAP_NO_MEMORY;
246 tag = ber_scanf( ber, "{iO}", count, cookie );
247 if ( tag == LBER_ERROR )
248 ret = WLDAP32_LDAP_DECODING_ERROR;
249 else
250 ret = LDAP_SUCCESS;
252 ber_free( ber, 1 );
254 #endif
255 return ret;
258 ULONG ldap_search_abandon_page( WLDAP32_LDAP *ld, PLDAPSearch search )
260 FIXME( "(%p, %p)\n", ld, search );
262 if (!ld) return ~0UL;
263 return LDAP_SUCCESS;
266 PLDAPSearch ldap_search_init_pageA( WLDAP32_LDAP *ld, PCHAR dn, ULONG scope,
267 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
268 PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyA *sortkeys )
270 FIXME( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn),
271 scope, debugstr_a(filter), attrs, attrsonly );
272 return NULL;
275 PLDAPSearch ldap_search_init_pageW( WLDAP32_LDAP *ld, PWCHAR dn, ULONG scope,
276 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
277 PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyW *sortkeys )
279 FIXME( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn),
280 scope, debugstr_w(filter), attrs, attrsonly );
281 return NULL;