dict-cdb.c (dovecot-2.3.16) | : | dict-cdb.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 29 | skipping to change at line 29 | |||
struct cdb cdb; | struct cdb cdb; | |||
char *path; | char *path; | |||
int fd, flag; | int fd, flag; | |||
}; | }; | |||
struct cdb_dict_iterate_context { | struct cdb_dict_iterate_context { | |||
struct dict_iterate_context ctx; | struct dict_iterate_context ctx; | |||
enum dict_iterate_flags flags; | enum dict_iterate_flags flags; | |||
buffer_t *buffer; | buffer_t *buffer; | |||
const char **paths, *values[2]; | const char *values[2]; | |||
char *path; | ||||
unsigned cptr; | unsigned cptr; | |||
char *error; | char *error; | |||
}; | }; | |||
static void cdb_dict_deinit(struct dict *_dict); | static void cdb_dict_deinit(struct dict *_dict); | |||
static int | static int | |||
cdb_dict_init(struct dict *driver, const char *uri, | cdb_dict_init(struct dict *driver, const char *uri, | |||
const struct dict_settings *set ATTR_UNUSED, | const struct dict_settings *set ATTR_UNUSED, | |||
struct dict **dict_r, const char **error_r) | struct dict **dict_r, const char **error_r) | |||
skipping to change at line 86 | skipping to change at line 87 | |||
/* we can safely deinit unallocated cdb */ | /* we can safely deinit unallocated cdb */ | |||
cdb_free(&dict->cdb); | cdb_free(&dict->cdb); | |||
i_close_fd_path(&dict->fd, dict->path); | i_close_fd_path(&dict->fd, dict->path); | |||
i_free(dict->path); | i_free(dict->path); | |||
i_free(dict); | i_free(dict); | |||
} | } | |||
static int | static int | |||
cdb_dict_lookup(struct dict *_dict, pool_t pool, | cdb_dict_lookup(struct dict *_dict, | |||
const struct dict_op_settings *set ATTR_UNUSED, | ||||
pool_t pool, | ||||
const char *key, const char **value_r, | const char *key, const char **value_r, | |||
const char **error_r) | const char **error_r) | |||
{ | { | |||
struct cdb_dict *dict = (struct cdb_dict *)_dict; | struct cdb_dict *dict = (struct cdb_dict *)_dict; | |||
unsigned datalen; | unsigned datalen; | |||
int ret = 0; | int ret = 0; | |||
char *data; | char *data; | |||
/* keys and values may be null terminated... */ | /* keys and values may be null terminated... */ | |||
if ((dict->flag & CDB_WITH_NULL) != 0) { | if ((dict->flag & CDB_WITH_NULL) != 0) { | |||
skipping to change at line 131 | skipping to change at line 134 | |||
data = p_malloc(pool, datalen + 1); | data = p_malloc(pool, datalen + 1); | |||
if (cdb_read(&dict->cdb, data, datalen, cdb_datapos(&dict->cdb)) < 0) { | if (cdb_read(&dict->cdb, data, datalen, cdb_datapos(&dict->cdb)) < 0) { | |||
*error_r = t_strdup_printf("cdb_read(%s) failed: %m", dict->path) ; | *error_r = t_strdup_printf("cdb_read(%s) failed: %m", dict->path) ; | |||
return -1; | return -1; | |||
} | } | |||
*value_r = data; | *value_r = data; | |||
return 1; | return 1; | |||
} | } | |||
static struct dict_iterate_context * | static struct dict_iterate_context * | |||
cdb_dict_iterate_init(struct dict *_dict, const char *const *paths, | cdb_dict_iterate_init(struct dict *_dict, | |||
enum dict_iterate_flags flags) | const struct dict_op_settings *set ATTR_UNUSED, | |||
const char *path, enum dict_iterate_flags flags) | ||||
{ | { | |||
struct cdb_dict_iterate_context *ctx = | struct cdb_dict_iterate_context *ctx = | |||
i_new(struct cdb_dict_iterate_context, 1); | i_new(struct cdb_dict_iterate_context, 1); | |||
struct cdb_dict *dict = (struct cdb_dict *)_dict; | struct cdb_dict *dict = (struct cdb_dict *)_dict; | |||
ctx->ctx.dict = &dict->dict; | ctx->ctx.dict = &dict->dict; | |||
ctx->paths = p_strarray_dup(default_pool, paths); | ctx->path = i_strdup(path); | |||
ctx->flags = flags; | ctx->flags = flags; | |||
ctx->buffer = buffer_create_dynamic(default_pool, 256); | ctx->buffer = buffer_create_dynamic(default_pool, 256); | |||
cdb_seqinit(&ctx->cptr, &dict->cdb); | cdb_seqinit(&ctx->cptr, &dict->cdb); | |||
return &ctx->ctx; | return &ctx->ctx; | |||
} | } | |||
static bool | static bool | |||
cdb_dict_next(struct cdb_dict_iterate_context *ctx, const char **key_r) | cdb_dict_next(struct cdb_dict_iterate_context *ctx, const char **key_r) | |||
skipping to change at line 186 | skipping to change at line 190 | |||
return TRUE; | return TRUE; | |||
} | } | |||
static bool cdb_dict_iterate(struct dict_iterate_context *_ctx, | static bool cdb_dict_iterate(struct dict_iterate_context *_ctx, | |||
const char **key_r, const char *const **values_r) | const char **key_r, const char *const **values_r) | |||
{ | { | |||
struct cdb_dict_iterate_context *ctx = | struct cdb_dict_iterate_context *ctx = | |||
(struct cdb_dict_iterate_context *)_ctx; | (struct cdb_dict_iterate_context *)_ctx; | |||
struct cdb_dict *dict = (struct cdb_dict *)_ctx->dict; | struct cdb_dict *dict = (struct cdb_dict *)_ctx->dict; | |||
const char *key, **ptr; | const char *key; | |||
bool match = FALSE; | bool match = FALSE; | |||
char *data; | char *data; | |||
unsigned datalen; | unsigned datalen; | |||
if (ctx->error != NULL) | if (ctx->error != NULL) | |||
return FALSE; | return FALSE; | |||
while(!match && cdb_dict_next(ctx, &key)) { | while(!match && cdb_dict_next(ctx, &key)) { | |||
/* if it matches any of the paths */ | if (((ctx->flags & DICT_ITERATE_FLAG_EXACT_KEY) != 0 && | |||
for(ptr = ctx->paths; *ptr != NULL; ptr++) { | strcmp(key, ctx->path) == 0) || | |||
if (((ctx->flags & DICT_ITERATE_FLAG_EXACT_KEY) != 0 && | ((ctx->flags & DICT_ITERATE_FLAG_RECURSE) != 0 && | |||
strcmp(key, *ptr) == 0) || | str_begins(key, ctx->path)) || | |||
((ctx->flags & DICT_ITERATE_FLAG_RECURSE) != 0 && | ((ctx->flags & DICT_ITERATE_FLAG_RECURSE) == 0 && | |||
str_begins(key, *ptr)) || | str_begins(key, ctx->path) && | |||
((ctx->flags & DICT_ITERATE_FLAG_RECURSE) == 0 && | strchr(key + strlen(ctx->path), '/') == NULL)) { | |||
str_begins(key, *ptr) && | match = TRUE; | |||
strchr(key + strlen(*ptr), '/') == NULL)) { | break; | |||
match = TRUE; | ||||
break; | ||||
} | ||||
} | } | |||
} | } | |||
if (!match) | if (!match) | |||
return FALSE; | return FALSE; | |||
*key_r = key; | *key_r = key; | |||
if ((ctx->flags & DICT_ITERATE_FLAG_NO_VALUE) != 0) | if ((ctx->flags & DICT_ITERATE_FLAG_NO_VALUE) != 0) | |||
return TRUE; | return TRUE; | |||
skipping to change at line 247 | skipping to change at line 248 | |||
int ret = 0; | int ret = 0; | |||
struct cdb_dict_iterate_context *ctx = | struct cdb_dict_iterate_context *ctx = | |||
(struct cdb_dict_iterate_context *)_ctx; | (struct cdb_dict_iterate_context *)_ctx; | |||
if (ctx->error != NULL) { | if (ctx->error != NULL) { | |||
*error_r = t_strdup(ctx->error); | *error_r = t_strdup(ctx->error); | |||
ret = -1; | ret = -1; | |||
} | } | |||
buffer_free(&ctx->buffer); | buffer_free(&ctx->buffer); | |||
i_free(ctx->error); | i_free(ctx->error); | |||
i_free(ctx->paths); | i_free(ctx->path); | |||
i_free(ctx); | i_free(ctx); | |||
return ret; | return ret; | |||
} | } | |||
struct dict dict_driver_cdb = { | struct dict dict_driver_cdb = { | |||
.name = "cdb", | .name = "cdb", | |||
{ | { | |||
.init = cdb_dict_init, | .init = cdb_dict_init, | |||
.deinit = cdb_dict_deinit, | .deinit = cdb_dict_deinit, | |||
End of changes. 7 change blocks. | ||||
19 lines changed or deleted | 20 lines changed or added |