quartz: Don't cast WSTR to BSTR, convert properly instead.
[wine/testsucceed.git] / dlls / wldap32 / page.c
blobb3c2d78d81ee8868d4292d0f000a96155f133280
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 #endif
36 #include "winldap_private.h"
37 #include "wldap32.h"
39 #ifndef LDAP_MAXINT
40 #define LDAP_MAXINT 2147483647
41 #endif
43 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
45 /***********************************************************************
46 * ldap_create_page_controlA (WLDAP32.@)
48 * See ldap_create_page_controlW.
50 ULONG CDECL ldap_create_page_controlA( WLDAP32_LDAP *ld, ULONG pagesize,
51 struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlA *control )
53 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
54 #ifdef HAVE_LDAP
55 LDAPControlW *controlW = NULL;
57 TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
58 critical, control );
60 if (!ld || !control || pagesize > LDAP_MAXINT)
61 return WLDAP32_LDAP_PARAM_ERROR;
63 ret = ldap_create_page_controlW( ld, pagesize, cookie, critical, &controlW );
64 if (ret == LDAP_SUCCESS)
66 *control = controlWtoA( controlW );
67 ldap_control_freeW( controlW );
70 #endif
71 return ret;
74 #ifdef HAVE_LDAP
76 /* create a page control by hand */
77 static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie,
78 UCHAR critical, PLDAPControlW *control )
80 LDAPControlW *ctrl;
81 BerElement *ber;
82 ber_tag_t tag;
83 struct berval *berval, null_cookie = { 0, NULL };
84 INT ret, len;
85 char *val;
87 ber = ber_alloc_t( LBER_USE_DER );
88 if (!ber) return WLDAP32_LDAP_NO_MEMORY;
90 if (cookie)
91 tag = ber_printf( ber, "{iO}", (ber_int_t)pagesize, cookie );
92 else
93 tag = ber_printf( ber, "{iO}", (ber_int_t)pagesize, &null_cookie );
95 ret = ber_flatten( ber, &berval );
96 ber_free( ber, 1 );
98 if (tag == LBER_ERROR)
99 return WLDAP32_LDAP_ENCODING_ERROR;
101 if (ret == -1)
102 return WLDAP32_LDAP_NO_MEMORY;
104 /* copy the berval so it can be properly freed by the caller */
105 val = HeapAlloc( GetProcessHeap(), 0, berval->bv_len );
106 if (!val) return WLDAP32_LDAP_NO_MEMORY;
108 len = berval->bv_len;
109 memcpy( val, berval->bv_val, len );
110 ber_bvfree( berval );
112 ctrl = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
113 if (!ctrl)
115 HeapFree( GetProcessHeap(), 0, val );
116 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 WLDAP32_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 #ifdef HAVE_LDAP
153 TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
154 critical, control );
156 if (!ld || !control || pagesize > LDAP_MAXINT)
157 return WLDAP32_LDAP_PARAM_ERROR;
159 return create_page_control( pagesize, cookie, critical, control );
161 #else
162 return WLDAP32_LDAP_NOT_SUPPORTED;
163 #endif
166 ULONG CDECL ldap_get_next_page( WLDAP32_LDAP *ld, PLDAPSearch search, ULONG pagesize,
167 ULONG *message )
169 FIXME( "(%p, %p, 0x%08x, %p)\n", ld, search, pagesize, message );
171 if (!ld) return ~0u;
172 return WLDAP32_LDAP_NOT_SUPPORTED;
175 ULONG CDECL ldap_get_next_page_s( WLDAP32_LDAP *ld, PLDAPSearch search,
176 struct l_timeval *timeout, ULONG pagesize, ULONG *count,
177 WLDAP32_LDAPMessage **results )
179 FIXME( "(%p, %p, %p, 0x%08x, %p, %p)\n", ld, search, timeout,
180 pagesize, count, results );
182 if (!ld) return ~0u;
183 return WLDAP32_LDAP_NOT_SUPPORTED;
186 ULONG CDECL ldap_get_paged_count( WLDAP32_LDAP *ld, PLDAPSearch search,
187 ULONG *count, WLDAP32_LDAPMessage *results )
189 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
190 #ifdef HAVE_LDAP
191 FIXME( "(%p, %p, %p, %p)\n", ld, search, count, results );
193 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
194 /* FIXME: save the cookie from the server here */
196 #endif
197 return ret;
200 /***********************************************************************
201 * ldap_parse_page_controlA (WLDAP32.@)
203 ULONG CDECL ldap_parse_page_controlA( WLDAP32_LDAP *ld, PLDAPControlA *ctrls,
204 ULONG *count, struct WLDAP32_berval **cookie )
206 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
207 #ifdef HAVE_LDAP
208 LDAPControlW **ctrlsW = NULL;
210 TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
212 if (!ld || !ctrls || !count || !cookie)
213 return WLDAP32_LDAP_PARAM_ERROR;
215 ctrlsW = controlarrayAtoW( ctrls );
216 if (!ctrlsW) return WLDAP32_LDAP_NO_MEMORY;
218 ret = ldap_parse_page_controlW( ld, ctrlsW, count, cookie );
219 controlarrayfreeW( ctrlsW );
221 #endif
222 return ret;
225 /***********************************************************************
226 * ldap_parse_page_controlW (WLDAP32.@)
228 ULONG CDECL ldap_parse_page_controlW( WLDAP32_LDAP *ld, PLDAPControlW *ctrls,
229 ULONG *count, struct WLDAP32_berval **cookie )
231 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
232 #ifdef HAVE_LDAP
233 LDAPControlW *control = NULL;
234 BerElement *ber;
235 ber_tag_t tag;
236 ULONG i;
238 TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
240 if (!ld || !ctrls || !count || !cookie)
241 return WLDAP32_LDAP_PARAM_ERROR;
243 for (i = 0; ctrls[i]; i++)
245 if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W, ctrls[i]->ldctl_oid ))
246 control = ctrls[i];
249 if (!control)
250 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
252 ber = ber_init( &((LDAPControl *)control)->ldctl_value );
253 if (!ber)
254 return WLDAP32_LDAP_NO_MEMORY;
256 tag = ber_scanf( ber, "{iO}", count, cookie );
257 if ( tag == LBER_ERROR )
258 ret = WLDAP32_LDAP_DECODING_ERROR;
259 else
260 ret = WLDAP32_LDAP_SUCCESS;
262 ber_free( ber, 1 );
264 #endif
265 return ret;
268 ULONG CDECL ldap_search_abandon_page( WLDAP32_LDAP *ld, PLDAPSearch search )
270 FIXME( "(%p, %p)\n", ld, search );
272 if (!ld) return ~0u;
273 return WLDAP32_LDAP_SUCCESS;
276 PLDAPSearch CDECL ldap_search_init_pageA( WLDAP32_LDAP *ld, PCHAR dn, ULONG scope,
277 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
278 PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyA *sortkeys )
280 FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_a(dn),
281 scope, debugstr_a(filter), attrs, attrsonly );
282 return NULL;
285 PLDAPSearch CDECL ldap_search_init_pageW( WLDAP32_LDAP *ld, PWCHAR dn, ULONG scope,
286 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
287 PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyW *sortkeys )
289 FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_w(dn),
290 scope, debugstr_w(filter), attrs, attrsonly );
291 return NULL;