1 #pragma ident "%Z%%M% %I% %E% SMI"
3 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
5 * The contents of this file are subject to the Netscape Public License
6 * Version 1.0 (the "NPL"); you may not use this file except in
7 * compliance with the NPL. You may obtain a copy of the NPL at
8 * http://www.mozilla.org/NPL/
10 * Software distributed under the NPL is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
12 * for the specific language governing rights and limitations under the
15 * The Initial Developer of this code under the NPL is Netscape
16 * Communications Corporation. Portions created by Netscape are
17 * Copyright (C) 1998 Netscape Communications Corporation. All Rights
21 * psearch.c - Persistent search and "Entry Change Notification" support.
28 ldap_create_persistentsearch_control( LDAP
*ld
, int changetypes
,
29 int changesonly
, int return_echg_ctls
, char ctl_iscritical
,
35 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
)) {
36 return( LDAP_PARAM_ERROR
);
39 if ( ctrlp
== NULL
|| ( changetypes
& ~LDAP_CHANGETYPE_ANY
) != 0 ) {
40 rc
= LDAP_PARAM_ERROR
;
41 goto report_error_and_return
;
45 * create a Persistent Search control. The control value looks like this:
47 * PersistentSearch ::= SEQUENCE {
48 * changeTypes INTEGER,
49 * -- the changeTypes field is the logical OR of
50 * -- one or more of these values: add (1), delete (2),
51 * -- modify (4), modDN (8). It specifies which types of
52 * -- changes will cause an entry to be returned.
53 * changesOnly BOOLEAN, -- skip initial search?
54 * returnECs BOOLEAN, -- return "Entry Change" controls?
57 if (( nsldapi_alloc_ber_with_options( ld
, &ber
)) != LDAP_SUCCESS
) {
59 goto report_error_and_return
;
62 if ( ber_printf( ber
, "{ibb}", changetypes
, changesonly
,
63 return_echg_ctls
) == -1 ) {
65 rc
= LDAP_ENCODING_ERROR
;
66 goto report_error_and_return
;
69 rc
= nsldapi_build_control( LDAP_CONTROL_PERSISTENTSEARCH
, ber
, 1,
70 ctl_iscritical
, ctrlp
);
72 report_error_and_return
:
73 LDAP_SET_LDERRNO( ld
, rc
, NULL
, NULL
);
80 ldap_parse_entrychange_control( LDAP
*ld
, LDAPControl
**ctrls
, int *chgtypep
,
81 char **prevdnp
, int *chgnumpresentp
, ber_int_t
*chgnump
)
84 int rc
, i
, changetype
;
89 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
)) {
90 return( LDAP_PARAM_ERROR
);
94 * find the entry change notification in the list of controls
96 for ( i
= 0; ctrls
!= NULL
&& ctrls
[i
] != NULL
; ++i
) {
97 if ( strcmp( ctrls
[i
]->ldctl_oid
, LDAP_CONTROL_ENTRYCHANGE
) == 0 ) {
102 if ( ctrls
== NULL
|| ctrls
[i
] == NULL
) {
103 rc
= LDAP_CONTROL_NOT_FOUND
;
104 goto report_error_and_return
;
108 * allocate a BER element from the control value and parse it. The control
109 * value should look like this:
111 * EntryChangeNotification ::= SEQUENCE {
112 * changeType ENUMERATED {
113 * add (1), -- these values match the
114 * delete (2), -- values used for changeTypes
115 * modify (4), -- in the PersistentSearch control.
118 * previousDN LDAPDN OPTIONAL, -- modDN ops. only
119 * changeNumber INTEGER OPTIONAL, -- if supported
122 if (( ber
= ber_init( &(ctrls
[i
]->ldctl_value
))) == NULL
) {
124 goto report_error_and_return
;
127 if ( ber_scanf( ber
, "{e", &along
) == LBER_ERROR
) {
129 rc
= LDAP_DECODING_ERROR
;
130 goto report_error_and_return
;
132 changetype
= (int)along
; /* XXX lossy cast */
134 if ( changetype
== LDAP_CHANGETYPE_MODDN
) {
135 if ( ber_scanf( ber
, "a", &previousdn
) == LBER_ERROR
) {
137 rc
= LDAP_DECODING_ERROR
;
138 goto report_error_and_return
;
144 if ( chgtypep
!= NULL
) {
145 *chgtypep
= changetype
;
147 if ( prevdnp
!= NULL
) {
148 *prevdnp
= previousdn
;
149 } else if ( previousdn
!= NULL
) {
150 NSLDAPI_FREE( previousdn
);
153 if ( chgnump
!= NULL
) { /* check for optional changenumber */
154 if ( ber_peek_tag( ber
, &len
) == LBER_INTEGER
155 && ber_get_int( ber
, chgnump
) != LBER_ERROR
) {
156 if ( chgnumpresentp
!= NULL
) {
160 if ( chgnumpresentp
!= NULL
) {
169 report_error_and_return
:
170 LDAP_SET_LDERRNO( ld
, rc
, NULL
, NULL
);