struct sort_context {
struct ldb_module *module;
- char *attributeName;
- char *orderingRule;
+ const char *attributeName;
+ const char *orderingRule;
int reverse;
struct ldb_request *req;
struct ldb_message **msgs;
char **referrals;
- int num_msgs;
- int num_refs;
+ unsigned int num_msgs;
+ unsigned int num_refs;
const struct ldb_schema_attribute *a;
int sort_result;
{
struct ldb_control **controls;
struct ldb_sort_resp_control *resp;
- int i;
+ unsigned int i;
if (*ctrls) {
controls = *ctrls;
ldb = ldb_module_get_ctx(ac->module);
- if (!ac || ac->sort_result != 0) {
+ if (ac->sort_result != 0) {
/* an error occurred previously,
* let's exit the sorting by returning always 0 */
return 0;
el1 = ldb_msg_find_element(*msg1, ac->attributeName);
el2 = ldb_msg_find_element(*msg2, ac->attributeName);
- if (!el1 || !el2) {
- /* the attribute was not found return and
- * set an error */
- ac->sort_result = LDB_ERR_UNWILLING_TO_PERFORM;
+ if (!el1 && el2) {
+ return 1;
+ }
+ if (el1 && !el2) {
+ return -1;
+ }
+ if (!el1 && !el2) {
return 0;
}
{
struct ldb_context *ldb;
struct ldb_reply *ares;
- int i, ret;
+ unsigned int i;
+ int ret;
ldb = ldb_module_get_ctx(ac->module);
ac->a = ldb_schema_attribute_by_name(ldb, ac->attributeName);
ac->sort_result = 0;
- ldb_qsort(ac->msgs, ac->num_msgs,
- sizeof(struct ldb_message *),
- ac, (ldb_qsort_cmp_fn_t)sort_compare);
+ LDB_TYPESAFE_QSORT(ac->msgs, ac->num_msgs, ac, sort_compare);
if (ac->sort_result != LDB_SUCCESS) {
return ac->sort_result;
ldb = ldb_module_get_ctx(module);
- /* check if there's a paged request control */
+ /* check if there's a server sort control */
control = ldb_request_get_control(req, LDB_CONTROL_SERVER_SORT_OID);
if (control == NULL) {
/* not found go on */
server_sort_search_callback,
req);
if (ret != LDB_SUCCESS) {
- return LDB_ERR_OPERATIONS_ERROR;
+ return ret;
}
/* save it locally and remove it from the list */
if (ret != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_WARNING,
"server_sort:"
- "Unable to register control with rootdse!\n");
+ "Unable to register control with rootdse!");
}
return ldb_next_init(module);