]> git.sur5r.net Git - openldap/commitdiff
Added a conformant sortedResults support which is unable to sort anything.
authorKurt Zeilenga <kurt@openldap.org>
Fri, 1 Apr 2005 02:40:29 +0000 (02:40 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 1 Apr 2005 02:40:29 +0000 (02:40 +0000)
servers/slapd/controls.c
servers/slapd/result.c
servers/slapd/slap.h

index 7b1604468369bcb9d44e59409d36207386e2b794..78199b1d2e5e5425d2940fd92e02abb3957fedb4 100644 (file)
@@ -32,6 +32,9 @@ static SLAP_CTRL_PARSE_FN parseManageDSAit;
 static SLAP_CTRL_PARSE_FN parseModifyIncrement;
 static SLAP_CTRL_PARSE_FN parseNoOp;
 static SLAP_CTRL_PARSE_FN parsePagedResults;
+#ifdef LDAP_DEVEL
+static SLAP_CTRL_PARSE_FN parseSortedResults;
+#endif
 static SLAP_CTRL_PARSE_FN parseValuesReturnFilter;
 static SLAP_CTRL_PARSE_FN parsePermissiveModify;
 static SLAP_CTRL_PARSE_FN parseDomainScope;
@@ -112,6 +115,12 @@ static struct slap_control control_defs[] = {
                (int)offsetof(struct slap_control_ids, sc_pagedResults),
                SLAP_CTRL_SEARCH, NULL,
                parsePagedResults, LDAP_SLIST_ENTRY_INITIALIZER(next) },
+#ifdef LDAP_DEVEL
+       { LDAP_CONTROL_SORTREQUEST,
+               (int)offsetof(struct slap_control_ids, sc_sortedResults),
+               SLAP_CTRL_GLOBAL|SLAP_CTRL_SEARCH|SLAP_CTRL_HIDE, NULL,
+               parseSortedResults, LDAP_SLIST_ENTRY_INITIALIZER(next) },
+#endif
 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
        { LDAP_CONTROL_X_DOMAIN_SCOPE,
                (int)offsetof(struct slap_control_ids, sc_domainScope),
@@ -950,6 +959,34 @@ done:;
        return rc;
 }
 
+#ifdef LDAP_DEVEL
+static int parseSortedResults (
+       Operation *op,
+       SlapReply *rs,
+       LDAPControl *ctrl )
+{
+       int             rc = LDAP_SUCCESS;
+
+       if ( op->o_sortedresults != SLAP_CONTROL_NONE ) {
+               rs->sr_text = "sorted results control specified multiple times";
+               return LDAP_PROTOCOL_ERROR;
+       }
+
+       if ( BER_BVISEMPTY( &ctrl->ldctl_value ) ) {
+               rs->sr_text = "sorted results control value is empty (or absent)";
+               return LDAP_PROTOCOL_ERROR;
+       }
+
+       /* blow off parsing the value */
+
+       op->o_sortedresults = ctrl->ldctl_iscritical
+               ? SLAP_CONTROL_CRITICAL
+               : SLAP_CONTROL_NONCRITICAL;
+
+       return rc;
+}
+#endif
+
 static int parseAssert (
        Operation *op,
        SlapReply *rs,
index f1abb5110b8970cc2a1af9b83cdd7adf807beb4b..38bad417eba14a7146dcb1d46788a1d8e24629f8 100644 (file)
@@ -254,7 +254,9 @@ send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c )
         * plugin.
         */
 
-       if ( o->o_pb && slapi_pblock_get( o->o_pb, SLAPI_RESCONTROLS, &sctrls ) != 0 ) {
+       if ( o->o_pb &&
+               slapi_pblock_get( o->o_pb, SLAPI_RESCONTROLS, &sctrls ) != 0 )
+       {
                sctrls = NULL;
        }
 
@@ -269,10 +271,37 @@ send_ldap_controls( Operation *o, BerElement *ber, LDAPControl **c )
 #ifdef LDAP_SLAPI
        if ( c != NULL )
 #endif /* LDAP_SLAPI */
-       for( ; *c != NULL; c++) {
-               rc = send_ldap_control( ber, *c );
+       {
+               for( ; *c != NULL; c++) {
+                       rc = send_ldap_control( ber, *c );
+                       if( rc == -1 ) return rc;
+               }
+       }
+
+#ifdef LDAP_DEVEL
+       /* this is a hack to avoid having to modify op->s_ctrls */
+       if( o->o_sortedresults ) {
+               BerElementBuffer berbuf;
+               BerElement *sber = (BerElement *) &berbuf;
+               LDAPControl sorted;
+               BER_BVZERO( &sorted.ldctl_value );
+               sorted.ldctl_oid = LDAP_CONTROL_SORTRESPONSE;
+               sorted.ldctl_iscritical = 0;
+
+               ber_init2( sber, NULL, LBER_USE_DER );
+
+               ber_printf( sber, "{i}", LDAP_UNWILLING_TO_PERFORM );
+
+               if( ber_flatten2( ber, &sorted.ldctl_value, 0 ) == -1 ) {
+                       return LBER_ERROR;
+               }
+
+               (void) ber_free_buf( ber );
+
+               rc = send_ldap_control( ber, &sorted );
                if( rc == -1 ) return rc;
        }
+#endif
 
 #ifdef LDAP_SLAPI
        if ( sctrls != NULL ) {
@@ -1405,8 +1434,7 @@ str2result(
     char       *s,
     int                *code,
     char       **matched,
-    char       **info
-)
+    char       **info )
 {
        int     rc;
        char    *c;
@@ -1567,8 +1595,10 @@ slap_attr_flags( AttributeName *an )
                flags |= ( SLAP_OPATTRS_NO | SLAP_USERATTRS_YES );
 
        } else {
-               flags |= an_find( an, &AllOper ) ?  SLAP_OPATTRS_YES : SLAP_OPATTRS_NO;
-               flags |= an_find( an, &AllUser ) ?  SLAP_USERATTRS_YES : SLAP_USERATTRS_NO;
+               flags |= an_find( an, &AllOper )
+                       ? SLAP_OPATTRS_YES : SLAP_OPATTRS_NO;
+               flags |= an_find( an, &AllUser )
+                       ? SLAP_USERATTRS_YES : SLAP_USERATTRS_NO;
        }
 
        return flags;
index 2768a8face1315ae457a925015a1e665ba828813..29755901fea50c993e6d9202bf872225615442a9 100644 (file)
@@ -2166,6 +2166,9 @@ struct slap_control_ids {
        int sc_modifyIncrement;
        int sc_noOp;
        int sc_pagedResults;
+#ifdef LDAP_DEVEL
+       int sc_sortedResults;
+#endif
        int sc_valuesReturnFilter;
        int sc_permissiveModify;
        int sc_domainScope;
@@ -2370,10 +2373,13 @@ typedef struct slap_op {
 
 #define o_pagedresults o_ctrlflag[slap_cids.sc_pagedResults]
 #define o_pagedresults_state   o_controls[slap_cids.sc_pagedResults]
+#define get_pagedresults(op)                   ((int)(op)->o_pagedresults)
 
-#define o_sync                 o_ctrlflag[slap_cids.sc_LDAPsync]
+#ifdef LDAP_DEVEL
+#define o_sortedresults                o_ctrlflag[slap_cids.sc_sortedResults]
+#endif
 
-#define get_pagedresults(op)                   ((int)(op)->o_pagedresults)
+#define o_sync                 o_ctrlflag[slap_cids.sc_LDAPsync]
 
        AuthorizationInformation o_authz;