Logo Search packages:      
Sourcecode: ldb version File versions  Download package

int ldb_search_default_callback ( struct ldb_context *  ldb,
void *  context,
struct ldb_reply *  ares 
)

The default async search callback function

Parameters:
ldb the context associated with the database (from ldb_init())
context the callback context (struct ldb_result *)
ares a single reply from the async core
Returns:
result code (LDB_SUCCESS on success, or a failure code)
Note:
this function expects the context to always be an struct ldb_result pointer AND a talloc context, this function will steal on the context each message from the ares reply passed on by the async core so that in the end all the messages will be in the context (ldb_result) memory tree. Freeing the passed context (ldb_result tree) will free all the resources (the request need to be freed separately and the result doe not depend on the request that can be freed as sson as the search request is finished)

Definition at line 573 of file ldb.c.

References LDB_ERR_OPERATIONS_ERROR, and LDB_SUCCESS.

{
      struct ldb_result *res;
      int n;
      
      if (!context) {
            ldb_set_errstring(ldb, "NULL Context in callback");
            return LDB_ERR_OPERATIONS_ERROR;
      }     

      res = talloc_get_type(context, struct ldb_result);

      if (!res || !ares) {
            ldb_set_errstring(ldb, "NULL res or ares in callback");
            goto error;
      }

      switch (ares->type) {
      case LDB_REPLY_ENTRY:
            res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2);
            if (! res->msgs) {
                  goto error;
            }

            res->msgs[res->count + 1] = NULL;

            res->msgs[res->count] = talloc_move(res->msgs, &ares->message);
            res->count++;
            break;
      case LDB_REPLY_REFERRAL:
            if (res->refs) {
                  for (n = 0; res->refs[n]; n++) /*noop*/ ;
            } else {
                  n = 0;
            }

            res->refs = talloc_realloc(res, res->refs, char *, n + 2);
            if (! res->refs) {
                  goto error;
            }

            res->refs[n] = talloc_move(res->refs, &ares->referral);
            res->refs[n + 1] = NULL;
            break;
      case LDB_REPLY_EXTENDED:
      case LDB_REPLY_DONE:
            /* TODO: we should really support controls on entries and referrals too! */
            res->controls = talloc_move(res, &ares->controls);
            break;            
      }
      talloc_free(ares);
      return LDB_SUCCESS;

error:
      talloc_free(ares);
      return LDB_ERR_OPERATIONS_ERROR;
}


Generated by  Doxygen 1.6.0   Back to index