]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: Added fs_lookup_metadata() wrapper to fs_get_metadata()
authorTimo Sirainen <tss@iki.fi>
Sat, 15 Nov 2014 00:22:56 +0000 (02:22 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 15 Nov 2014 00:22:56 +0000 (02:22 +0200)
src/lib-fs/fs-api.c
src/lib-fs/fs-api.h

index 9701867942897f91ceffbd57bcd2f721cc8ee402..a53f7afba6f95d99928bd3ca36b9ebed45dc308a 100644 (file)
@@ -265,6 +265,24 @@ int fs_get_metadata(struct fs_file *file,
        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 :
index 8dfa6a2680ca015e8b95cb0c8671a8a35ed8aa20..535293b393341e83e6ddcda0aeedfbf1fd02b096 100644 (file)
@@ -132,6 +132,10 @@ void fs_set_metadata(struct fs_file *file, const char *key, const char *value);
 /* 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,