1 /*
2 *
3 * Copyright 1999 Sun Microsystems, Inc. All rights reserved.
4 * Use is subject to license terms.
5 *
6 *
7 * Comments:
8 *
9 */
10
11 #pragma ident "%Z%%M% %I% %E% SMI"
12
13 #include <stdio.h>
14 #include <string.h>
15
16 #ifdef MACOS
17 #include "macos.h"
18 #endif /* MACOS */
19
20 #if !defined( MACOS ) && !defined( DOS )
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #endif
24
25 #include "lber.h"
26 #include "ldap.h"
27 #include "ldap-private.h"
28 #include "ldap-int.h"
29
ldap_create_page_control(LDAP * ld,unsigned int pagesize,struct berval * cookie,char isCritical,LDAPControl ** output)30 int ldap_create_page_control(LDAP *ld, unsigned int pagesize, struct berval *cookie, char isCritical, LDAPControl **output)
31 {
32 BerElement *ber;
33 int rc;
34
35 if (NULL == ld || NULL == output)
36 return (LDAP_PARAM_ERROR);
37
38 if ((ber = ber_alloc_t(LBER_USE_DER)) == NULLBER){
39 return (LDAP_NO_MEMORY);
40 }
41
42 if (ber_printf(ber, "{io}", pagesize,
43 (cookie && cookie->bv_val) ? cookie->bv_val : "",
44 (cookie && cookie->bv_val) ? cookie->bv_len : 0)
45 == LBER_ERROR) {
46 ber_free(ber, 1);
47 return (LDAP_ENCODING_ERROR);
48 }
49
50 rc = ldap_build_control(LDAP_CONTROL_SIMPLE_PAGE, ber, 1, isCritical,
51 output);
52
53 ld->ld_errno = rc;
54 return (rc);
55 }
56
ldap_parse_page_control(LDAP * ld,LDAPControl ** controls,unsigned int * totalcount,struct berval ** cookie)57 int ldap_parse_page_control(LDAP *ld, LDAPControl **controls, unsigned int *totalcount, struct berval **cookie)
58 {
59 int i, rc;
60 BerElement *theBer;
61 LDAPControl *listCtrlp;
62
63 for (i = 0; controls[i] != NULL; i++){
64 if (strcmp(controls[i]->ldctl_oid, "1.2.840.113556.1.4.319") == 0) {
65 listCtrlp = controls[i];
66 if ((theBer = ber_init(&listCtrlp->ldctl_value)) == NULLBER){
67 return (LDAP_NO_MEMORY);
68 }
69 if ((rc = ber_scanf(theBer, "{iO}", totalcount, cookie)) == LBER_ERROR){
70 ber_free(theBer, 1);
71 return (LDAP_DECODING_ERROR);
72 }
73 ber_free(theBer, 1);
74 return (LDAP_SUCCESS);
75 }
76 }
77 return (LDAP_CONTROL_NOT_FOUND);
78 }
79
80