Author: idra
Date: 2005-12-11 18:34:07 +0000 (Sun, 11 Dec 2005)
New Revision: 12184

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=12184

Log:

ok now sort works, it was an ber encoding problem in the control
plus some weird bug when the connection is sealed made me not think
about that immediately.

Simo.


Modified:
   branches/tmp/samba4_ldap_controls/source/lib/ldb/modules/sort.c
   branches/tmp/samba4_ldap_controls/source/lib/ldb/tools/ldbtest_controls.c


Changeset:
Modified: branches/tmp/samba4_ldap_controls/source/lib/ldb/modules/sort.c
===================================================================
--- branches/tmp/samba4_ldap_controls/source/lib/ldb/modules/sort.c     
2005-12-11 18:32:58 UTC (rev 12183)
+++ branches/tmp/samba4_ldap_controls/source/lib/ldb/modules/sort.c     
2005-12-11 18:34:07 UTC (rev 12184)
@@ -62,6 +62,7 @@
        struct ldb_server_sort_control **sort_ctrls;
        struct ldb_sort_resp_control *sort_resp;
        int i, cnum, ret;
+       BOOL do_sort = True;
 
        /* check if there's a paged request control */
        if (req->controls != NULL) {
@@ -82,7 +83,38 @@
        sort_ctrls = (struct ldb_server_sort_control 
**)req->controls[cnum]->data;
 
        /* FIXME: we do not support more than one attribute for sorting right 
now */
-       if (sort_ctrls[1] != NULL) {
+       /* FIXME: we need to check if the attribute type exist or return an 
error */
+       if (sort_ctrls[1] != NULL)
+               do_sort = False;
+               
+       if (!do_sort && req->controls[cnum]->critical) {
+               sort_result = talloc(req, struct ldb_result);
+               if (!sort_result)
+                       return LDB_ERR_OPERATIONS_ERROR;
+
+               sort_result->count = 0;
+               sort_result->msgs = NULL;
+               sort_result->controls = talloc_array(sort_result, struct 
ldb_control *, 2);
+               if (! sort_result->controls )
+                       return LDB_ERR_OPERATIONS_ERROR;
+
+               sort_result->controls[0] = talloc(sort_result->controls, struct 
ldb_control);
+               if (! sort_result->controls[0] )
+                       return LDB_ERR_OPERATIONS_ERROR;
+
+               sort_result->controls[0]->oid = LDB_CONTROL_SORT_RESP_OID;
+               sort_result->controls[0]->critical = False;
+               sort_resp = talloc(sort_result->controls[0], struct 
ldb_sort_resp_control);
+               if (! sort_resp )
+                       return LDB_ERR_OPERATIONS_ERROR;
+
+               sort_resp->result = 53; /* unwilling to perform */
+               sort_resp->attr_desc = "sort control is not complete yet";
+               sort_result->controls[0]->data = sort_resp;
+               sort_result->controls[1] = NULL;
+
+               req->op.search.res = sort_result;
+
                return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
        }
 
@@ -113,29 +145,31 @@
        }
 
        /* SORT HERE */
-       sort_result = req->op.search.res;
-       sort_control = sort_ctrls[0];
-       ldbctx = module->ldb;
-       h = ldb_attrib_handler(ldbctx, sort_control->attributeName);
+       if (do_sort) {
+               sort_result = req->op.search.res;
+               sort_control = sort_ctrls[0];
+               ldbctx = module->ldb;
+               h = ldb_attrib_handler(ldbctx, sort_control->attributeName);
 
-       /* FIXME: I don't like to use a static structure like sort_control
-        * we need to either:
-        * a) write a qsort function that takes a third void parameter
-        * or
-        * b) prepare a structure with all elements pre digested like:
-        *      struct element {
-        *              struct ldb_message_element *el;
-        *              struct ldb_message *msg;
-        *      }
-        *
-        *      this mean we will have to do a linear scan of
-        *      the msgs array to build the new sort array, and
-        *      then do a linear scan of the resulting array
-        *      to rebuild the msgs array in the original shape.
-        */
+               /* FIXME: I don't like to use a static structure like 
sort_control
+                * we need to either:
+                * a) write a qsort function that takes a third void parameter
+                * or
+                * b) prepare a structure with all elements pre digested like:
+                *      struct element {
+                *              struct ldb_message_element *el;
+                *              struct ldb_message *msg;
+                *      }
+                *
+                *      this mean we will have to do a linear scan of
+                *      the msgs array to build the new sort array, and
+                *      then do a linear scan of the resulting array
+                *      to rebuild the msgs array in the original shape.
+                */
 
-       qsort(sort_result->msgs, sort_result->count,
-               sizeof(struct ldb_message *), (comparison_fn_t)sort_compare);
+               qsort(sort_result->msgs, sort_result->count,
+                       sizeof(struct ldb_message *), 
(comparison_fn_t)sort_compare);
+       }
 
        if (sort_result->controls) {
                for (i = 0; sort_result->controls[i]; i++);
@@ -158,7 +192,11 @@
        if (! sort_resp )
                return LDB_ERR_OPERATIONS_ERROR;
 
-       sort_resp->result = 0;
+       if (do_sort) {
+               sort_resp->result = 0;
+       } else {
+               sort_resp->result = 53;
+       }
        sort_resp->attr_desc = "sort control is not complete yet";
        sort_result->controls[i]->data = sort_resp;
 

Modified: 
branches/tmp/samba4_ldap_controls/source/lib/ldb/tools/ldbtest_controls.c
===================================================================
--- branches/tmp/samba4_ldap_controls/source/lib/ldb/tools/ldbtest_controls.c   
2005-12-11 18:32:58 UTC (rev 12183)
+++ branches/tmp/samba4_ldap_controls/source/lib/ldb/tools/ldbtest_controls.c   
2005-12-11 18:34:07 UTC (rev 12184)
@@ -262,7 +262,7 @@
                fprintf(stderr, "ERROR: No control reply even if control was 
marked as critical\n");
        } else {
                sort_result = (struct ldb_sort_resp_control 
*)result->controls[0]->data;
-               fprintf(stderr, "Sort result: %d (%s)\n", sort_result->result, 
sort_result->attr_desc);
+               fprintf(stderr, "Sort result: %d (%s)\n", sort_result->result, 
sort_result->attr_desc?sort_result->attr_desc:"null");
        }
 
        ret = talloc_free(result);

Reply via email to