Mercurial > dovecot > core-2.2
changeset 18093:372de41933c0
lib-fs: Added fs_lookup_metadata() wrapper to fs_get_metadata()
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 15 Nov 2014 02:22:56 +0200 |
parents | ef8b7e44e96c |
children | a350812e07bf |
files | src/lib-fs/fs-api.c src/lib-fs/fs-api.h |
diffstat | 2 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-fs/fs-api.c Sat Nov 15 00:30:06 2014 +0200 +++ b/src/lib-fs/fs-api.c Sat Nov 15 02:22:56 2014 +0200 @@ -265,6 +265,24 @@ return ret; } +int fs_lookup_metadata(struct fs_file *file, const char *key, + const char **value_r) +{ + const ARRAY_TYPE(fs_metadata) *metadata; + const struct fs_metadata *md; + + if (fs_get_metadata(file, &metadata) < 0) + return -1; + array_foreach(metadata, md) { + if (strcmp(md->key, key) == 0) { + *value_r = md->value; + return 1; + } + } + *value_r = NULL; + return 0; +} + const char *fs_file_path(struct fs_file *file) { return file->fs->v.get_path == NULL ? file->path :
--- a/src/lib-fs/fs-api.h Sat Nov 15 00:30:06 2014 +0200 +++ b/src/lib-fs/fs-api.h Sat Nov 15 02:22:56 2014 +0200 @@ -132,6 +132,10 @@ /* Return file's all metadata. */ int fs_get_metadata(struct fs_file *file, const ARRAY_TYPE(fs_metadata) **metadata_r); +/* Wrapper to fs_get_metadata() to lookup a specific key. Returns 1 if value_r + is set, 0 if key wasn't found, -1 if error. */ +int fs_lookup_metadata(struct fs_file *file, const char *key, + const char **value_r); /* Returns the path given to fs_open(). If file was opened with FS_OPEN_MODE_CREATE_UNIQUE_128 and the write has already finished,