diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-01-02 07:49:29 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:07:55 -0500 |
commit | 1a988ec9af7960616fb4661b20d86ff05146d836 (patch) | |
tree | 725eb92b6b97133b23972215f5c69117e29c339c /source4/lib/ldb/common/ldb_parse.c | |
parent | 65f96eba32b93ced0717c2639007bba59da55fa4 (diff) | |
download | samba-1a988ec9af7960616fb4661b20d86ff05146d836.tar.gz samba-1a988ec9af7960616fb4661b20d86ff05146d836.tar.xz samba-1a988ec9af7960616fb4661b20d86ff05146d836.zip |
r4474: - converted ldb to use talloc internally
- added gcov flags to Makefile.ldb
- expanded ldb test suite to get more coverage
(This used to be commit 0ab98f50a7e0fe15347a99e5c29a6590a87729a0)
Diffstat (limited to 'source4/lib/ldb/common/ldb_parse.c')
-rw-r--r-- | source4/lib/ldb/common/ldb_parse.c | 119 |
1 files changed, 47 insertions, 72 deletions
diff --git a/source4/lib/ldb/common/ldb_parse.c b/source4/lib/ldb/common/ldb_parse.c index 1e00a05d554..6ee6f992537 100644 --- a/source4/lib/ldb/common/ldb_parse.c +++ b/source4/lib/ldb/common/ldb_parse.c @@ -65,7 +65,7 @@ a filter is defined by: /* return next token element. Caller frees */ -static char *ldb_parse_lex(struct ldb_context *ldb, const char **s, const char *sep) +static char *ldb_parse_lex(TALLOC_CTX *ctx, const char **s, const char *sep) { const char *p = *s; char *ret; @@ -81,7 +81,7 @@ static char *ldb_parse_lex(struct ldb_context *ldb, const char **s, const char * if (strchr(sep, *p)) { (*s) = p+1; - ret = ldb_strndup(ldb, p, 1); + ret = talloc_strndup(ctx, p, 1); if (!ret) { errno = ENOMEM; } @@ -96,7 +96,7 @@ static char *ldb_parse_lex(struct ldb_context *ldb, const char **s, const char * return NULL; } - ret = ldb_strndup(ldb, *s, p - *s); + ret = talloc_strndup(ctx, *s, p - *s); if (!ret) { errno = ENOMEM; } @@ -128,47 +128,46 @@ static const char *match_brace(const char *s) } -static struct ldb_parse_tree *ldb_parse_filter(struct ldb_context *ldb, const char **s); +static struct ldb_parse_tree *ldb_parse_filter(TALLOC_CTX *ctx, const char **s); /* <simple> ::= <attributetype> <filtertype> <attributevalue> */ -static struct ldb_parse_tree *ldb_parse_simple(struct ldb_context *ldb, const char *s) +static struct ldb_parse_tree *ldb_parse_simple(TALLOC_CTX *ctx, const char *s) { char *eq, *val, *l; struct ldb_parse_tree *ret; - l = ldb_parse_lex(ldb, &s, LDB_ALL_SEP); + ret = talloc_p(ctx, struct ldb_parse_tree); + if (!ret) { + errno = ENOMEM; + return NULL; + } + + l = ldb_parse_lex(ret, &s, LDB_ALL_SEP); if (!l) { + talloc_free(ret); return NULL; } if (strchr("()&|=", *l)) { - ldb_free(ldb, l); + talloc_free(ret); return NULL; } - eq = ldb_parse_lex(ldb, &s, LDB_ALL_SEP); + eq = ldb_parse_lex(ret, &s, LDB_ALL_SEP); if (!eq || strcmp(eq, "=") != 0) { - ldb_free(ldb, l); - if (eq) ldb_free(ldb, eq); + talloc_free(ret); return NULL; } - ldb_free(ldb, eq); + talloc_free(eq); - val = ldb_parse_lex(ldb, &s, ")"); + val = ldb_parse_lex(ret, &s, ")"); if (val && strchr("()&|", *val)) { - ldb_free(ldb, l); - if (val) ldb_free(ldb, val); + talloc_free(ret); return NULL; } - ret = ldb_malloc_p(ldb, struct ldb_parse_tree); - if (!ret) { - errno = ENOMEM; - return NULL; - } - ret->operation = LDB_OP_SIMPLE; ret->u.simple.attr = l; ret->u.simple.value.data = val; @@ -184,12 +183,12 @@ static struct ldb_parse_tree *ldb_parse_simple(struct ldb_context *ldb, const ch <or> ::= '|' <filterlist> <filterlist> ::= <filter> | <filter> <filterlist> */ -static struct ldb_parse_tree *ldb_parse_filterlist(struct ldb_context *ldb, +static struct ldb_parse_tree *ldb_parse_filterlist(TALLOC_CTX *ctx, enum ldb_parse_op op, const char *s) { struct ldb_parse_tree *ret, *next; - ret = ldb_malloc_p(ldb, struct ldb_parse_tree); + ret = talloc_p(ctx, struct ldb_parse_tree); if (!ret) { errno = ENOMEM; return NULL; @@ -197,31 +196,29 @@ static struct ldb_parse_tree *ldb_parse_filterlist(struct ldb_context *ldb, ret->operation = op; ret->u.list.num_elements = 1; - ret->u.list.elements = ldb_malloc_p(ldb, struct ldb_parse_tree *); + ret->u.list.elements = talloc_p(ret, struct ldb_parse_tree *); if (!ret->u.list.elements) { errno = ENOMEM; - ldb_free(ldb, ret); + talloc_free(ret); return NULL; } - ret->u.list.elements[0] = ldb_parse_filter(ldb, &s); + ret->u.list.elements[0] = ldb_parse_filter(ret->u.list.elements, &s); if (!ret->u.list.elements[0]) { - ldb_free(ldb, ret->u.list.elements); - ldb_free(ldb, ret); + talloc_free(ret); return NULL; } while (isspace(*s)) s++; - while (*s && (next = ldb_parse_filter(ldb, &s))) { + while (*s && (next = ldb_parse_filter(ret->u.list.elements, &s))) { struct ldb_parse_tree **e; - e = ldb_realloc_p(ldb, ret->u.list.elements, - struct ldb_parse_tree *, - ret->u.list.num_elements+1); + e = talloc_realloc_p(ret, ret->u.list.elements, + struct ldb_parse_tree *, + ret->u.list.num_elements+1); if (!e) { errno = ENOMEM; - ldb_parse_tree_free(ldb, next); - ldb_parse_tree_free(ldb, ret); + talloc_free(ret); return NULL; } ret->u.list.elements = e; @@ -237,20 +234,20 @@ static struct ldb_parse_tree *ldb_parse_filterlist(struct ldb_context *ldb, /* <not> ::= '!' <filter> */ -static struct ldb_parse_tree *ldb_parse_not(struct ldb_context *ldb, const char *s) +static struct ldb_parse_tree *ldb_parse_not(TALLOC_CTX *ctx, const char *s) { struct ldb_parse_tree *ret; - ret = ldb_malloc_p(ldb, struct ldb_parse_tree); + ret = talloc_p(ctx, struct ldb_parse_tree); if (!ret) { errno = ENOMEM; return NULL; } ret->operation = LDB_OP_NOT; - ret->u.not.child = ldb_parse_filter(ldb, &s); + ret->u.not.child = ldb_parse_filter(ret, &s); if (!ret->u.not.child) { - ldb_free(ldb, ret); + talloc_free(ret); return NULL; } @@ -261,49 +258,48 @@ static struct ldb_parse_tree *ldb_parse_not(struct ldb_context *ldb, const char parse a filtercomp <filtercomp> ::= <and> | <or> | <not> | <simple> */ -static struct ldb_parse_tree *ldb_parse_filtercomp(struct ldb_context *ldb, - const char *s) +static struct ldb_parse_tree *ldb_parse_filtercomp(TALLOC_CTX *ctx, const char *s) { while (isspace(*s)) s++; switch (*s) { case '&': - return ldb_parse_filterlist(ldb, LDB_OP_AND, s+1); + return ldb_parse_filterlist(ctx, LDB_OP_AND, s+1); case '|': - return ldb_parse_filterlist(ldb, LDB_OP_OR, s+1); + return ldb_parse_filterlist(ctx, LDB_OP_OR, s+1); case '!': - return ldb_parse_not(ldb, s+1); + return ldb_parse_not(ctx, s+1); case '(': case ')': return NULL; } - return ldb_parse_simple(ldb, s); + return ldb_parse_simple(ctx, s); } /* <filter> ::= '(' <filtercomp> ')' */ -static struct ldb_parse_tree *ldb_parse_filter(struct ldb_context *ldb, const char **s) +static struct ldb_parse_tree *ldb_parse_filter(TALLOC_CTX *ctx, const char **s) { char *l, *s2; const char *p, *p2; struct ldb_parse_tree *ret; - l = ldb_parse_lex(ldb, s, LDB_ALL_SEP); + l = ldb_parse_lex(ctx, s, LDB_ALL_SEP); if (!l) { return NULL; } if (strcmp(l, "(") != 0) { - ldb_free(ldb, l); + talloc_free(l); return NULL; } - ldb_free(ldb, l); + talloc_free(l); p = match_brace(*s); if (!p) { @@ -311,14 +307,14 @@ static struct ldb_parse_tree *ldb_parse_filter(struct ldb_context *ldb, const ch } p2 = p + 1; - s2 = ldb_strndup(ldb, *s, p - *s); + s2 = talloc_strndup(ctx, *s, p - *s); if (!s2) { errno = ENOMEM; return NULL; } - ret = ldb_parse_filtercomp(ldb, s2); - ldb_free(ldb, s2); + ret = ldb_parse_filtercomp(ctx, s2); + talloc_free(s2); *s = p2; @@ -347,27 +343,6 @@ struct ldb_parse_tree *ldb_parse_tree(struct ldb_context *ldb, const char *s) */ void ldb_parse_tree_free(struct ldb_context *ldb, struct ldb_parse_tree *tree) { - unsigned int i; - - switch (tree->operation) { - case LDB_OP_SIMPLE: - ldb_free(ldb, tree->u.simple.attr); - if (tree->u.simple.value.data) ldb_free(ldb, tree->u.simple.value.data); - break; - - case LDB_OP_AND: - case LDB_OP_OR: - for (i=0;i<tree->u.list.num_elements;i++) { - ldb_parse_tree_free(ldb, tree->u.list.elements[i]); - } - if (tree->u.list.elements) ldb_free(ldb, tree->u.list.elements); - break; - - case LDB_OP_NOT: - ldb_parse_tree_free(ldb, tree->u.not.child); - break; - } - - ldb_free(ldb, tree); + talloc_free(tree); } |