server: Moved get/set_thread_context implementation to ptrace.c.
[wine/wine-kai.git] / dlls / wldap32 / page.c
blob556758598dbdf817710133079e30749d2f719cba
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 "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 #ifndef LDAP_MAXINT
43 #define LDAP_MAXINT 2147483647
44 #endif
46 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
48 /***********************************************************************
49 * ldap_create_page_controlA (WLDAP32.@)
51 * See ldap_create_page_controlW.
53 ULONG CDECL ldap_create_page_controlA( WLDAP32_LDAP *ld, ULONG pagesize,
54 struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlA *control )
56 ULONG ret = LDAP_NOT_SUPPORTED;
57 #ifdef HAVE_LDAP
58 LDAPControlW *controlW = NULL;
60 TRACE( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
61 critical, control );
63 if (!ld || !control || pagesize > LDAP_MAXINT)
64 return WLDAP32_LDAP_PARAM_ERROR;
66 ret = ldap_create_page_controlW( ld, pagesize, cookie, critical, &controlW );
67 if (ret == LDAP_SUCCESS)
69 *control = controlWtoA( controlW );
70 ldap_control_freeW( controlW );
73 #endif
74 return ret;
77 #ifdef HAVE_LDAP
79 /* create a page control by hand */
80 static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie,
81 UCHAR critical, PLDAPControlW *control )
83 LDAPControlW *ctrl;
84 BerElement *ber;
85 ber_tag_t tag;
86 struct berval *berval, null_cookie = { 0, NULL };
87 INT ret, len;
88 char *val;
90 ber = ber_alloc_t( LBER_USE_DER );
91 if (!ber) return WLDAP32_LDAP_NO_MEMORY;
93 if (cookie)
94 tag = ber_printf( ber, "{iO}", (ber_int_t)pagesize, cookie );
95 else
96 tag = ber_printf( ber, "{iO}", (ber_int_t)pagesize, &null_cookie );
98 ret = ber_flatten( ber, &berval );
99 ber_free( ber, 1 );
101 if (tag == LBER_ERROR)
102 return WLDAP32_LDAP_ENCODING_ERROR;
104 if (ret == -1)
105 return WLDAP32_LDAP_NO_MEMORY;
107 /* copy the berval so it can be properly freed by the caller */
108 val = HeapAlloc( GetProcessHeap(), 0, berval->bv_len );
109 if (!val) return WLDAP32_LDAP_NO_MEMORY;
111 len = berval->bv_len;
112 memcpy( val, berval->bv_val, len );
113 ber_bvfree( berval );
115 ctrl = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
116 if (!ctrl)
117 return WLDAP32_LDAP_NO_MEMORY;
119 ctrl->ldctl_oid = strAtoW( LDAP_PAGED_RESULT_OID_STRING );
120 ctrl->ldctl_value.bv_len = len;
121 ctrl->ldctl_value.bv_val = val;
122 ctrl->ldctl_iscritical = critical;
124 *control = ctrl;
126 return LDAP_SUCCESS;
129 #endif /* HAVE_LDAP */
131 /***********************************************************************
132 * ldap_create_page_controlW (WLDAP32.@)
134 * Create a control for paged search results.
136 * PARAMS
137 * ld [I] Pointer to an LDAP context.
138 * pagesize [I] Number of entries to return per page.
139 * cookie [I] Used by the server to track its location in the
140 * search results.
141 * critical [I] Tells the server this control is critical to the
142 * search operation.
143 * control [O] LDAPControl created.
145 * RETURNS
146 * Success: LDAP_SUCCESS
147 * Failure: An LDAP error code.
149 ULONG CDECL ldap_create_page_controlW( WLDAP32_LDAP *ld, ULONG pagesize,
150 struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlW *control )
152 ULONG ret = LDAP_NOT_SUPPORTED;
153 #ifdef HAVE_LDAP
155 TRACE( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
156 critical, control );
158 if (!ld || !control || pagesize > LDAP_MAXINT)
159 return WLDAP32_LDAP_PARAM_ERROR;
161 return create_page_control( pagesize, cookie, critical, control );
163 #endif
164 return ret;
167 ULONG CDECL ldap_get_next_page( WLDAP32_LDAP *ld, PLDAPSearch search, ULONG pagesize,
168 ULONG *message )
170 FIXME( "(%p, %p, 0x%08lx, %p)\n", ld, search, pagesize, message );
172 if (!ld) return ~0UL;
173 return LDAP_NOT_SUPPORTED;
176 ULONG CDECL ldap_get_next_page_s( WLDAP32_LDAP *ld, PLDAPSearch search,
177 struct l_timeval *timeout, ULONG pagesize, ULONG *count,
178 WLDAP32_LDAPMessage **results )
180 FIXME( "(%p, %p, %p, 0x%08lx, %p, %p)\n", ld, search, timeout,
181 pagesize, count, results );
183 if (!ld) return ~0UL;
184 return LDAP_NOT_SUPPORTED;
187 ULONG CDECL ldap_get_paged_count( WLDAP32_LDAP *ld, PLDAPSearch search,
188 ULONG *count, WLDAP32_LDAPMessage *results )
190 ULONG ret = LDAP_NOT_SUPPORTED;
191 #ifdef HAVE_LDAP
192 FIXME( "(%p, %p, %p, %p)\n", ld, search, count, results );
194 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
195 /* FIXME: save the cookie from the server here */
197 #endif
198 return ret;
201 /***********************************************************************
202 * ldap_parse_page_controlA (WLDAP32.@)
204 ULONG CDECL ldap_parse_page_controlA( WLDAP32_LDAP *ld, PLDAPControlA *ctrls,
205 ULONG *count, struct WLDAP32_berval **cookie )
207 ULONG ret = LDAP_NOT_SUPPORTED;
208 #ifdef HAVE_LDAP
209 LDAPControlW **ctrlsW = NULL;
211 TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
213 if (!ld || !ctrls || !count || !cookie)
214 return WLDAP32_LDAP_PARAM_ERROR;
216 ctrlsW = controlarrayAtoW( ctrls );
217 if (!ctrlsW) return WLDAP32_LDAP_NO_MEMORY;
219 ret = ldap_parse_page_controlW( ld, ctrlsW, count, cookie );
220 controlarrayfreeW( ctrlsW );
222 #endif
223 return ret;
226 /***********************************************************************
227 * ldap_parse_page_controlW (WLDAP32.@)
229 ULONG CDECL ldap_parse_page_controlW( WLDAP32_LDAP *ld, PLDAPControlW *ctrls,
230 ULONG *count, struct WLDAP32_berval **cookie )
232 ULONG ret = LDAP_NOT_SUPPORTED;
233 #ifdef HAVE_LDAP
234 LDAPControlW *control = NULL;
235 BerElement *ber;
236 ber_tag_t tag;
237 ULONG i;
239 TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
241 if (!ld || !ctrls || !count || !cookie)
242 return WLDAP32_LDAP_PARAM_ERROR;
244 for (i = 0; ctrls[i]; i++)
246 if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W, ctrls[i]->ldctl_oid ))
247 control = ctrls[i];
250 if (!control)
251 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
253 ber = ber_init( &((LDAPControl *)control)->ldctl_value );
254 if (!ber)
255 return WLDAP32_LDAP_NO_MEMORY;
257 tag = ber_scanf( ber, "{iO}", count, cookie );
258 if ( tag == LBER_ERROR )
259 ret = WLDAP32_LDAP_DECODING_ERROR;
260 else
261 ret = LDAP_SUCCESS;
263 ber_free( ber, 1 );
265 #endif
266 return ret;
269 ULONG CDECL ldap_search_abandon_page( WLDAP32_LDAP *ld, PLDAPSearch search )
271 FIXME( "(%p, %p)\n", ld, search );
273 if (!ld) return ~0UL;
274 return LDAP_SUCCESS;
277 PLDAPSearch CDECL ldap_search_init_pageA( WLDAP32_LDAP *ld, PCHAR dn, ULONG scope,
278 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
279 PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyA *sortkeys )
281 FIXME( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn),
282 scope, debugstr_a(filter), attrs, attrsonly );
283 return NULL;
286 PLDAPSearch CDECL ldap_search_init_pageW( WLDAP32_LDAP *ld, PWCHAR dn, ULONG scope,
287 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
288 PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyW *sortkeys )
290 FIXME( "(%p, %s, 0x%08lx, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn),
291 scope, debugstr_w(filter), attrs, attrsonly );
292 return NULL;