]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: Added internal fs_metadata_find() helper function
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 10 Oct 2016 22:04:39 +0000 (01:04 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 17 Oct 2016 20:11:18 +0000 (23:11 +0300)
src/lib-fs/fs-api-private.h
src/lib-fs/fs-api.c

index 3b084e515522b6c617c2fef4b6cfba1e896ed417..9167b1113a273a898da027d7bb7953d92d671f8f 100644 (file)
@@ -168,6 +168,8 @@ void fs_metadata_init(struct fs_file *file);
 void fs_metadata_init_or_clear(struct fs_file *file);
 void fs_default_set_metadata(struct fs_file *file,
                             const char *key, const char *value);
+const char *fs_metadata_find(const ARRAY_TYPE(fs_metadata) *metadata,
+                            const char *key);
 int fs_default_copy(struct fs_file *src, struct fs_file *dest);
 
 void fs_file_timing_end(struct fs_file *file, enum fs_op op);
index aa8591d6989b9f25d6d59b9504fb8b42971d792a..dbf36db7a4efd4aa48d8e0c07439f4565f63ac6f 100644 (file)
@@ -323,6 +323,21 @@ void fs_default_set_metadata(struct fs_file *file,
        metadata->value = p_strdup(file->metadata_pool, value);
 }
 
+const char *fs_metadata_find(const ARRAY_TYPE(fs_metadata) *metadata,
+                            const char *key)
+{
+       const struct fs_metadata *md;
+
+       if (array_is_created(metadata))
+               return NULL;
+
+       array_foreach(metadata, md) {
+               if (strcmp(md->key, key) == 0)
+                       return md->value;
+       }
+       return NULL;
+}
+
 void fs_set_metadata(struct fs_file *file, const char *key, const char *value)
 {
        i_assert(key != NULL);
@@ -403,18 +418,11 @@ 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;
+       *value_r = fs_metadata_find(metadata, key);
+       return *value_r != NULL ? 1 : 0;
 }
 
 const char *fs_file_path(struct fs_file *file)