dovecot-2.2: lib-fs: Added fs_lookup_metadata() wrapper to fs_ge...

dovecot at dovecot.org dovecot at dovecot.org
Sat Nov 15 00:24:17 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/372de41933c0
changeset: 18093:372de41933c0
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Nov 15 02:22:56 2014 +0200
description:
lib-fs: Added fs_lookup_metadata() wrapper to fs_get_metadata()

diffstat:

 src/lib-fs/fs-api.c |  18 ++++++++++++++++++
 src/lib-fs/fs-api.h |   4 ++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diffs (42 lines):

diff -r ef8b7e44e96c -r 372de41933c0 src/lib-fs/fs-api.c
--- 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 :
diff -r ef8b7e44e96c -r 372de41933c0 src/lib-fs/fs-api.h
--- 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,


More information about the dovecot-cvs mailing list