dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libldap5 / sources / ldap / common / spagectrl.c
blob7287ad16d56482c625ad08420ce4a910dfd58fe7
1 /*
2 * Copyright (c) 2001 by Sun Microsystems, Inc.
3 * All rights reserved.
4 */
6 #pragma ident "%Z%%M% %I% %E% SMI"
8 #include <stdio.h>
9 #include <string.h>
11 #ifdef MACOS
12 #include "macos.h"
13 #endif /* MACOS */
15 #if !defined( MACOS ) && !defined( DOS )
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #endif
20 #include "lber.h"
21 #include "ldap.h"
22 #include "ldap-int.h"
24 int ldap_create_page_control(LDAP *ld, unsigned int pagesize, struct berval *cookie, char isCritical, LDAPControl **output)
26 BerElement *ber;
27 int rc;
29 if (NULL == ld || NULL == output)
30 return (LDAP_PARAM_ERROR);
32 if ((ber = ber_alloc_t(LBER_USE_DER)) == NULLBER){
33 return (LDAP_NO_MEMORY);
36 if (ber_printf(ber, "{io}", pagesize,
37 (cookie && cookie->bv_val) ? cookie->bv_val : "",
38 (cookie && cookie->bv_val) ? cookie->bv_len : 0)
39 == LBER_ERROR) {
40 ber_free(ber, 1);
41 return (LDAP_ENCODING_ERROR);
44 rc = nsldapi_build_control(LDAP_CONTROL_SIMPLE_PAGE, ber, 1, isCritical,
45 output);
47 ld->ld_errno = rc;
48 return (rc);
51 int ldap_parse_page_control(LDAP *ld, LDAPControl **controls, unsigned int *totalcount, struct berval **cookie)
53 int i, rc;
54 BerElement *theBer;
55 LDAPControl *listCtrlp;
57 for (i = 0; controls[i] != NULL; i++){
58 if (strcmp(controls[i]->ldctl_oid, "1.2.840.113556.1.4.319") == 0) {
59 listCtrlp = controls[i];
60 if ((theBer = ber_init(&listCtrlp->ldctl_value)) == NULLBER){
61 return (LDAP_NO_MEMORY);
63 if ((rc = ber_scanf(theBer, "{iO}", totalcount, cookie)) == LBER_ERROR){
64 ber_free(theBer, 1);
65 return (LDAP_DECODING_ERROR);
67 ber_free(theBer, 1);
68 return (LDAP_SUCCESS);
71 return (LDAP_CONTROL_NOT_FOUND);