Small documentation tweaks to avoid winapi_check warnings.
[wine] / dlls / wldap32 / page.c
1 /*
2  * WLDAP32 - LDAP support for Wine
3  *
4  * Copyright 2005 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include "wine/port.h"
24 #include "wine/debug.h"
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS        0x00
36 #define LDAP_NOT_SUPPORTED  0x5c
37 #endif
38
39 #include "winldap_private.h"
40 #include "wldap32.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43
44 /***********************************************************************
45  *      ldap_create_page_controlA     (WLDAP32.@)
46  *
47  * See ldap_create_page_controlW.
48  */
49 ULONG ldap_create_page_controlA( WLDAP32_LDAP *ld, ULONG pagesize,
50     struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlA *control )
51 {
52     ULONG ret = LDAP_NOT_SUPPORTED;
53 #ifdef HAVE_LDAP
54     LDAPControlW *controlW = NULL;
55
56     TRACE( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
57            critical, control );
58
59     if (!ld || !control) return WLDAP32_LDAP_PARAM_ERROR;
60
61     ret = ldap_create_page_controlW( ld, pagesize, cookie, critical, &controlW );
62     if (ret == LDAP_SUCCESS)
63     {
64         *control = controlWtoA( controlW );
65         ldap_control_freeW( controlW );
66     }
67
68 #endif
69     return ret;
70 }
71
72 #ifdef HAVE_LDAP
73
74 /* create a page control by hand */
75 static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie,
76     UCHAR critical, PLDAPControlW *control )
77 {
78     LDAPControlW *ctrl;
79     BerElement *ber;
80     struct berval *berval, null_cookie = { 0, NULL };
81     INT ret, len;
82     char *val;
83
84     ber = ber_alloc_t( LBER_USE_DER );
85     if (!ber) return WLDAP32_LDAP_NO_MEMORY;
86
87     if (cookie)
88         ber_printf( ber, "{iO}", pagesize, cookie );
89     else
90         ber_printf( ber, "{iO}", pagesize, &null_cookie );
91
92     ret = ber_flatten( ber, &berval );
93     ber_free( ber, 1 );
94
95     if (ret == -1)
96         return WLDAP32_LDAP_NO_MEMORY;
97
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;
101
102     len = berval->bv_len;
103     memcpy( val, berval->bv_val, len );
104     ber_bvfree( berval );
105
106     ctrl = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
107     if (!ctrl)
108         return WLDAP32_LDAP_NO_MEMORY;
109
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;
114
115     *control = ctrl;
116
117     return LDAP_SUCCESS;
118 }
119
120 #endif /* HAVE_LDAP */
121
122 /***********************************************************************
123  *      ldap_create_page_controlW     (WLDAP32.@)
124  *
125  * Create a control for paged search results.
126  *
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.
135  *
136  * RETURNS
137  *  Success: LDAP_SUCCESS
138  *  Failure: An LDAP error code.
139  */
140 ULONG ldap_create_page_controlW( WLDAP32_LDAP *ld, ULONG pagesize,
141     struct WLDAP32_berval *cookie, UCHAR critical, PLDAPControlW *control )
142 {
143     ULONG ret = LDAP_NOT_SUPPORTED;
144 #ifdef HAVE_LDAP
145
146     TRACE( "(%p, 0x%08lx, %p, 0x%02x, %p)\n", ld, pagesize, cookie,
147            critical, control );
148
149     if (!ld || !control) return WLDAP32_LDAP_PARAM_ERROR;
150     return create_page_control( pagesize, cookie, critical, control );
151
152 #endif
153     return ret;
154 }
155
156 ULONG ldap_get_next_page( WLDAP32_LDAP *ld, PLDAPSearch search, ULONG pagesize,
157     ULONG *message )
158 {
159     FIXME( "(%p, %p, 0x%08lx, %p)\n", ld, search, pagesize, message );
160
161     if (!ld) return ~0UL;
162     return LDAP_NOT_SUPPORTED;
163 }
164
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 )
168 {
169     FIXME( "(%p, %p, %p, 0x%08lx, %p, %p)\n", ld, search, timeout,
170            pagesize, count, results );
171
172     if (!ld) return ~0UL;
173     return LDAP_NOT_SUPPORTED;
174 }
175
176 ULONG ldap_get_paged_count( WLDAP32_LDAP *ld, PLDAPSearch search,
177     ULONG *count, WLDAP32_LDAPMessage *results )
178 {
179     ULONG ret = LDAP_NOT_SUPPORTED;
180 #ifdef HAVE_LDAP
181     FIXME( "(%p, %p, %p, %p)\n", ld, search, count, results );
182
183     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
184     /* FIXME: save the cookie from the server here */
185
186 #endif
187     return ret;
188 }
189
190 /***********************************************************************
191  *      ldap_parse_page_controlA      (WLDAP32.@)
192  */
193 ULONG ldap_parse_page_controlA( WLDAP32_LDAP *ld, PLDAPControlA *ctrls,
194     ULONG *count, struct WLDAP32_berval **cookie )
195 {
196     ULONG ret = LDAP_NOT_SUPPORTED;
197 #ifdef HAVE_LDAP
198     LDAPControlW **ctrlsW = NULL;
199
200     TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
201
202     if (!ld || !ctrls || !count || !cookie)
203         return WLDAP32_LDAP_PARAM_ERROR;
204
205     ctrlsW = controlarrayAtoW( ctrls );
206     if (!ctrlsW) return WLDAP32_LDAP_NO_MEMORY;
207
208     ret = ldap_parse_page_controlW( ld, ctrlsW, count, cookie );
209     controlarrayfreeW( ctrlsW );
210  
211 #endif
212     return ret;
213 }
214
215 /***********************************************************************
216  *      ldap_parse_page_controlW      (WLDAP32.@)
217  */
218 ULONG ldap_parse_page_controlW( WLDAP32_LDAP *ld, PLDAPControlW *ctrls,
219     ULONG *count, struct WLDAP32_berval **cookie )
220 {
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;
227
228     TRACE( "(%p, %p, %p, %p)\n", ld, ctrls, count, cookie );
229
230     if (!ld || !ctrls || !count || !cookie)
231         return WLDAP32_LDAP_PARAM_ERROR;
232
233     for (i = 0; ctrls[i]; i++)
234     {
235         if (!lstrcmpW( LDAP_PAGED_RESULT_OID_STRING_W, ctrls[i]->ldctl_oid ))
236             control = ctrls[i];
237     }
238
239     if (!control)
240         return WLDAP32_LDAP_CONTROL_NOT_FOUND; 
241             
242     ber = ber_init( &((LDAPControl *)control)->ldctl_value );
243     if (!ber)
244         return WLDAP32_LDAP_NO_MEMORY;
245
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;
251
252     ber_free( ber, 1 );
253     
254 #endif
255     return ret;
256 }
257
258 ULONG ldap_search_abandon_page( WLDAP32_LDAP *ld, PLDAPSearch search )
259 {
260     FIXME( "(%p, %p)\n", ld, search );
261
262     if (!ld) return ~0UL;
263     return LDAP_SUCCESS;
264 }
265
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 )
269 {
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;
273 }
274
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 )
278 {
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;
282 }