1
/* Copyright (C) 2002 Max Caines, All Rights Reserved.
2
This file is part of the nss_ldap library.
3
Contributed by Max Caines, <Max.Caines@wlv.ac.uk>, April 2002.
4
This software is not subject to any license of the University
7
The nss_ldap library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Library General Public License as
9
published by the Free Software Foundation; either version 2 of the
10
License, or (at your option) any later version.
12
The nss_ldap library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Library General Public License for more details.
17
You should have received a copy of the GNU Library General Public
18
License along with the nss_ldap library; see the file COPYING.LIB. If not,
19
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
Boston, MA 02111-1307, USA.
23
static char rcsId[] = "$Id: pagectrl.c,v 2.4 2006/01/13 10:24:59 lukeh Exp $";
37
#ifndef LDAP_CONTROL_PAGE_OID
38
#define LDAP_CONTROL_PAGE_OID "1.2.840.113556.1.4.319"
41
#ifndef HAVE_LDAP_CREATE_PAGE_CONTROL
43
ldap_create_page_control
45
Create and encode the Paged Results control.
47
ld (IN) An LDAP session handle, as obtained from a call to
50
pagesize (IN) The number of entries to return in each page
52
cookiep (IN) Pointer to a berVal structure that the server uses to
53
determine the current location in the
54
result set (opaque). Set to NULL the
57
iscritical (IN) Is this control critical to the search?
59
ctrlp (OUT) A result parameter that will be assigned the address
60
of an LDAPControl structure that contains the
61
PagedResult control created by this function.
62
The memory occupied by the LDAPControl structure
63
SHOULD be freed when it is no longer in use by
64
calling ldap_control_free().
69
PageResult ::= SEQUENCE {
74
Note: The first time the Page control is created, the cookie
75
should be set to a zero-length string. The cookie obtained
76
from calling ldap_parse_page_control() should be used as
77
the cookie in the next ldap_create_page_control call.
81
#ifndef HAVE_LDAP_CREATE_CONTROL
82
#error LDAP client library does not support ldap_create_control()
85
ldap_create_page_control (LDAP * ld,
86
unsigned long pagesize,
87
struct berval *cookiep,
88
int iscritical, LDAPControl ** ctrlp)
92
BerElement *ldap_alloc_ber_with_options (LDAP * ld);
95
if ((ld == NULL) || (ctrlp == NULL))
97
return (LDAP_PARAM_ERROR);
100
if ((ber = ldap_alloc_ber_with_options (ld)) == NULL)
102
return (LDAP_NO_MEMORY);
105
tag = ber_printf (ber, "{i", pagesize);
106
if (tag == LBER_ERROR)
110
tag = ber_printf (ber, "o", "", 0);
112
tag = ber_printf (ber, "O", cookiep);
113
if (tag == LBER_ERROR)
116
tag = ber_printf (ber, /*{ */ "N}");
117
if (tag == LBER_ERROR)
120
rc = ldap_create_control (LDAP_CONTROL_PAGE_OID, ber, iscritical, ctrlp);
127
return (LDAP_ENCODING_ERROR);
129
#endif /* HAVE_LDAP_CREATE_CONTROL */
130
#endif /* HAVE_LDAP_CREATE_PAGE_CONTROL */
132
#ifndef HAVE_LDAP_PARSE_PAGE_CONTROL
134
ldap_parse_page_control
136
Decode the Virtual List View control return information.
138
ld (IN) An LDAP session handle.
140
ctrls (IN) The address of a NULL-terminated array of
141
LDAPControl structures, typically obtained
142
by a call to ldap_parse_result().
144
list_countp (OUT) This result parameter is filled in with the number
145
of entries returned in this page
147
cookiep (OUT) This result parameter is filled in with the address
148
of a struct berval that contains the server-
150
The returned cookie SHOULD be used in the next call
151
to create a Page sort control. The struct berval
152
returned SHOULD be disposed of by calling ber_bvfree()
153
when it is no longer needed.
157
#ifndef HAVE_LDAP_CREATE_CONTROL
158
#error LDAP client library does not support ldap_create_control()
161
ldap_parse_page_control (LDAP * ld,
162
LDAPControl ** ctrls,
163
unsigned long *list_countp, struct berval **cookiep)
166
LDAPControl *pControl;
173
*cookiep = NULL; /* Make sure we return a NULL if error occurs. */
178
return (LDAP_PARAM_ERROR);
183
return (LDAP_CONTROL_NOT_FOUND);
186
/* Search the list of control responses for a Page control. */
187
for (i = 0; ctrls[i]; i++)
190
if (!strcmp (LDAP_CONTROL_PAGE_OID, pControl->ldctl_oid))
191
goto foundPageControl;
194
/* No page control was found. */
195
return (LDAP_CONTROL_NOT_FOUND);
198
/* Create a BerElement from the berval returned in the control. */
199
ber = ber_init (&pControl->ldctl_value);
203
return (LDAP_NO_MEMORY);
206
/* Extract the data returned in the control. */
207
tag = ber_scanf (ber, "{iO" /*} */ , &count, cookiep);
209
if (tag == LBER_ERROR)
212
return (LDAP_DECODING_ERROR);
217
/* Return data to the caller for items that were requested. */
220
*list_countp = count;
223
return (LDAP_SUCCESS);
225
#endif /* HAVE_LDAP_CREATE_CONTROL */
226
#endif /* HAVE_LDAP_PARSE_PAGE_CONTROL */