dsound: Base fragment size off of the MMDevice's period.
[wine.git] / dlls / wldap32 / page.c
blob15d5119902eb4e7fae25ab55a06f2a0c69b84cb8
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"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #ifdef HAVE_LDAP_H
26 #include <ldap.h>
27 #endif
28 #ifndef LDAP_MAXINT
29 #define LDAP_MAXINT 2147483647
30 #endif
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winnls.h"
36 #include "winldap_private.h"
37 #include "wldap32.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
42 /***********************************************************************
43 * ldap_create_page_controlA (WLDAP32.@)
45 * See ldap_create_page_controlW.
47 ULONG CDECL ldap_create_page_controlA( WLDAP32_LDAP *ld, ULONG pagesize,
48 struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlA *control )
50 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
51 #ifdef HAVE_LDAP
52 LDAPControlW *controlW = NULL;
54 TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
55 critical, control );
57 if (!ld || !control || pagesize > LDAP_MAXINT)
58 return WLDAP32_LDAP_PARAM_ERROR;
60 ret = ldap_create_page_controlW( ld, pagesize, cookie, critical, &controlW );
61 if (ret == LDAP_SUCCESS)
63 *control = controlWtoA( controlW );
64 ldap_control_freeW( controlW );
67 #endif
68 return ret;
71 #ifdef HAVE_LDAP
73 /* create a page control by hand */
74 static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie,
75 UCHAR critical, PLDAPControlW *control )
77 LDAPControlW *ctrl;
78 BerElement *ber;
79 ber_tag_t tag;
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 tag = ber_printf( ber, "{iO}", (ber_int_t)pagesize, cookie );
89 else
90 tag = ber_printf( ber, "{iO}", (ber_int_t)pagesize, &null_cookie );
92 ret = ber_flatten( ber, &berval );
93 ber_free( ber, 1 );
95 if (tag == LBER_ERROR)
96 return WLDAP32_LDAP_ENCODING_ERROR;
98 if (ret == -1)
99 return WLDAP32_LDAP_NO_MEMORY;
101 /* copy the berval so it can be properly freed by the caller */
102 val = HeapAlloc( GetProcessHeap(), 0, berval->bv_len );
103 if (!val) return WLDAP32_LDAP_NO_MEMORY;
105 len = berval->bv_len;
106 memcpy( val, berval->bv_val, len );
107 ber_bvfree( berval );
109 ctrl = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
110 if (!ctrl)
112 HeapFree( GetProcessHeap(), 0, val );
113 return WLDAP32_LDAP_NO_MEMORY;
116 ctrl->ldctl_oid = strAtoW( LDAP_PAGED_RESULT_OID_STRING );
117 ctrl->ldctl_value.bv_len = len;
118 ctrl->ldctl_value.bv_val = val;
119 ctrl->ldctl_iscritical = critical;
121 *control = ctrl;
123 return WLDAP32_LDAP_SUCCESS;
126 #endif /* HAVE_LDAP */
128 /***********************************************************************
129 * ldap_create_page_controlW (WLDAP32.@)
131 * Create a control for paged search results.
133 * PARAMS
134 * ld [I] Pointer to an LDAP context.
135 * pagesize [I] Number of entries to return per page.
136 * cookie [I] Used by the server to track its location in the
137 * search results.
138 * critical [I] Tells the server this control is critical to the
139 * search operation.
140 * control [O] LDAPControl created.
142 * RETURNS
143 * Success: LDAP_SUCCESS
144 * Failure: An LDAP error code.
146 ULONG CDECL ldap_create_page_controlW( WLDAP32_LDAP *ld, ULONG pagesize,
147 struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlW *control )
149 #ifdef HAVE_LDAP
150 TRACE( "(%p, 0x%08x, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
151 critical, control );
153 if (!ld || !control || pagesize > LDAP_MAXINT)
154 return WLDAP32_LDAP_PARAM_ERROR;
156 return create_page_control( pagesize, cookie, critical, control );
158 #else
159 return WLDAP32_LDAP_NOT_SUPPORTED;
160 #endif
163 ULONG CDECL ldap_get_next_page( WLDAP32_LDAP *ld, PLDAPSearch search, ULONG pagesize,
164 ULONG *message )
166 FIXME( "(%p, %p, 0x%08x, %p)\n", ld, search, pagesize, message );
168 if (!ld) return ~0u;
169 return WLDAP32_LDAP_NOT_SUPPORTED;
172 ULONG CDECL ldap_get_next_page_s( WLDAP32_LDAP *ld, PLDAPSearch search,
173 struct l_timeval *timeout, ULONG pagesize, ULONG *count,
174 WLDAP32_LDAPMessage **results )
176 FIXME( "(%p, %p, %p, 0x%08x, %p, %p)\n", ld, search, timeout,
177 pagesize, count, results );
179 if (!ld) return ~0u;
180 return WLDAP32_LDAP_NOT_SUPPORTED;
183 ULONG CDECL ldap_get_paged_count( WLDAP32_LDAP *ld, PLDAPSearch search,
184 ULONG *count, WLDAP32_LDAPMessage *results )
186 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
187 #ifdef HAVE_LDAP
188 FIXME( "(%p, %p, %p, %p)\n", ld, search, count, results );
190 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
191 /* FIXME: save the cookie from the server here */
193 #endif
194 return ret;
197 /***********************************************************************
198 * ldap_parse_page_controlA (WLDAP32.@)
200 ULONG CDECL ldap_parse_page_controlA( WLDAP32_LDAP *ld, PLDAPControlA *ctrls,
201 ULONG *count, struct WLDAP32_berval **cookie )
203 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
204 #ifdef HAVE_LDAP
205 LDAPControlW **ctrlsW = NULL;
207 TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
209 if (!ld || !ctrls || !count || !cookie)
210 return WLDAP32_LDAP_PARAM_ERROR;
212 ctrlsW = controlarrayAtoW( ctrls );
213 if (!ctrlsW) return WLDAP32_LDAP_NO_MEMORY;
215 ret = ldap_parse_page_controlW( ld, ctrlsW, count, cookie );
216 controlarrayfreeW( ctrlsW );
218 #endif
219 return ret;
222 /***********************************************************************
223 * ldap_parse_page_controlW (WLDAP32.@)
225 ULONG CDECL ldap_parse_page_controlW( WLDAP32_LDAP *ld, PLDAPControlW *ctrls,
226 ULONG *count, struct WLDAP32_berval **cookie )
228 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
229 #ifdef HAVE_LDAP
230 LDAPControlW *control = NULL;
231 BerElement *ber;
232 ber_tag_t tag;
233 ULONG i;
235 TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
237 if (!ld || !ctrls || !count || !cookie)
238 return WLDAP32_LDAP_PARAM_ERROR;
240 for (i = 0; ctrls[i]; i++)
242 if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W, ctrls[i]->ldctl_oid ))
243 control = ctrls[i];
246 if (!control)
247 return WLDAP32_LDAP_CONTROL_NOT_FOUND;
249 ber = ber_init( &((LDAPControl *)control)->ldctl_value );
250 if (!ber)
251 return WLDAP32_LDAP_NO_MEMORY;
253 tag = ber_scanf( ber, "{iO}", count, cookie );
254 if ( tag == LBER_ERROR )
255 ret = WLDAP32_LDAP_DECODING_ERROR;
256 else
257 ret = WLDAP32_LDAP_SUCCESS;
259 ber_free( ber, 1 );
261 #endif
262 return ret;
265 ULONG CDECL ldap_search_abandon_page( WLDAP32_LDAP *ld, PLDAPSearch search )
267 FIXME( "(%p, %p)\n", ld, search );
269 if (!ld) return ~0u;
270 return WLDAP32_LDAP_SUCCESS;
273 PLDAPSearch CDECL ldap_search_init_pageA( WLDAP32_LDAP *ld, PCHAR dn, ULONG scope,
274 PCHAR filter, PCHAR attrs[], ULONG attrsonly, PLDAPControlA *serverctrls,
275 PLDAPControlA *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyA *sortkeys )
277 FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_a(dn),
278 scope, debugstr_a(filter), attrs, attrsonly );
279 return NULL;
282 PLDAPSearch CDECL ldap_search_init_pageW( WLDAP32_LDAP *ld, PWCHAR dn, ULONG scope,
283 PWCHAR filter, PWCHAR attrs[], ULONG attrsonly, PLDAPControlW *serverctrls,
284 PLDAPControlW *clientctrls, ULONG timelimit, ULONG sizelimit, PLDAPSortKeyW *sortkeys )
286 FIXME( "(%p, %s, 0x%08x, %s, %p, 0x%08x)\n", ld, debugstr_w(dn),
287 scope, debugstr_w(filter), attrs, attrsonly );
288 return NULL;