+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, ARGS,
+ "parseValuesReturnFilter: conn %d vrFilter: %s\n",
+ conn->c_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
+#else
+ Debug( LDAP_DEBUG_ARGS, " vrFilter: %s\n",
+ fstr.bv_len ? fstr.bv_val : "empty", 0, 0 );
+#endif
+
+ op->o_valuesreturnfilter = ctrl->ldctl_iscritical
+ ? SLAP_CRITICAL_CONTROL
+ : SLAP_NONCRITICAL_CONTROL;
+
+ return LDAP_SUCCESS;
+}
+#endif
+
+#ifdef LDAP_CLIENT_UPDATE
+static int parseClientUpdate (
+ Connection *conn,
+ Operation *op,
+ LDAPControl *ctrl,
+ const char **text )
+{
+ ber_tag_t tag;
+ BerElement *ber;
+ ber_int_t type;
+ ber_int_t interval;
+ ber_len_t len;
+ struct berval scheme = { 0, NULL };
+ struct berval cookie = { 0, NULL };
+
+ if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
+ *text = "LCUP client update control specified multiple times";
+ return LDAP_PROTOCOL_ERROR;
+ }
+
+ if ( ctrl->ldctl_value.bv_len == 0 ) {
+ *text = "LCUP client update control value is empty";
+ return LDAP_PROTOCOL_ERROR;
+ }
+
+ /* Parse the control value
+ * ClientUpdateControlValue ::= SEQUENCE {
+ * updateType ENUMERATED {
+ * synchronizeOnly {0},
+ * synchronizeAndPersist {1},
+ * persistOnly {2} },
+ * sendCookieInterval INTEGER OPTIONAL,
+ * cookie LCUPCookie OPTIONAL
+ * }
+ */
+
+ ber = ber_init( &ctrl->ldctl_value );
+ if( ber == NULL ) {
+ *text = "internal error";
+ return LDAP_OTHER;
+ }
+
+ if ( (tag = ber_scanf( ber, "{i" /*}*/, &type )) == LBER_ERROR ) {
+ *text = "LCUP client update control : decoding error";
+ return LDAP_PROTOCOL_ERROR;
+ }
+
+ switch( type ) {
+ case LDAP_CUP_SYNC_ONLY:
+ type = SLAP_LCUP_SYNC;
+ break;
+ case LDAP_CUP_SYNC_AND_PERSIST:
+ type = SLAP_LCUP_SYNC_AND_PERSIST;
+ break;
+ case LDAP_CUP_PERSIST_ONLY:
+ type = SLAP_LCUP_PERSIST;
+ break;
+ default:
+ *text = "LCUP client update control : unknown update type";
+ return LDAP_PROTOCOL_ERROR;
+ }
+
+ if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
+ *text = "LCUP client update control : decoding error";
+ return LDAP_PROTOCOL_ERROR;
+ }
+
+ if ( tag == LDAP_TAG_INTERVAL ) {
+ if ( (tag = ber_scanf( ber, "i", &interval )) == LBER_ERROR ) {
+ *text = "LCUP client update control : decoding error";
+ return LDAP_PROTOCOL_ERROR;
+ }
+
+ if ( interval <= 0 ) {
+ /* server chooses interval */
+ interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
+ }
+
+ } else {
+ /* server chooses interval */
+ interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
+ }
+
+ if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
+ *text = "LCUP client update control : decoding error";
+ return LDAP_PROTOCOL_ERROR;
+ }
+
+ if ( tag == LDAP_TAG_COOKIE ) {
+ if ( (tag = ber_scanf( ber, /*{*/ "{mm}}",
+ &scheme, &cookie )) == LBER_ERROR ) {
+ *text = "LCUP client update control : decoding error";
+ return LDAP_PROTOCOL_ERROR;
+ }
+ }
+
+ /* TODO : Cookie Scheme Validation */
+#if 0
+ if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
+ *text = "Unsupported LCUP cookie scheme";
+ return LCUP_UNSUPPORTED_SCHEME;
+ }
+
+ if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
+ *text = "Invalid LCUP cookie";
+ return LCUP_INVALID_COOKIE;
+ }
+#endif
+
+ ber_dupbv( &op->o_clientupdate_state, &cookie );
+
+ (void) ber_free( ber, 1 );
+
+ op->o_clientupdate_type = (char) type;
+ op->o_clientupdate_interval = interval;
+
+ op->o_clientupdate = ctrl->ldctl_iscritical
+ ? SLAP_CRITICAL_CONTROL
+ : SLAP_NONCRITICAL_CONTROL;
+
+ return LDAP_SUCCESS;
+}
+#endif /* LDAP_CLIENT_UPDATE */