1 /* $NetBSD: tags.c,v 1.1.1.1 2008/12/22 00:18:17 haad Exp $ */
2
3 /*
4 * Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
6 *
7 * This file is part of LVM2.
8 *
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 #include "lib.h"
19 #include "metadata.h"
20 #include "import-export.h"
21 #include "str_list.h"
22 #include "lvm-string.h"
23
print_tags(struct dm_list * tags,char * buffer,size_t size)24 int print_tags(struct dm_list *tags, char *buffer, size_t size)
25 {
26 struct str_list *sl;
27 int first = 1;
28
29 if (!emit_to_buffer(&buffer, &size, "["))
30 return_0;
31
32 dm_list_iterate_items(sl, tags) {
33 if (!first) {
34 if (!emit_to_buffer(&buffer, &size, ", "))
35 return_0;
36 } else
37 first = 0;
38
39 if (!emit_to_buffer(&buffer, &size, "\"%s\"", sl->str))
40 return_0;
41 }
42
43 if (!emit_to_buffer(&buffer, &size, "]"))
44 return_0;
45
46 return 1;
47 }
48
read_tags(struct dm_pool * mem,struct dm_list * tags,struct config_value * cv)49 int read_tags(struct dm_pool *mem, struct dm_list *tags, struct config_value *cv)
50 {
51 if (cv->type == CFG_EMPTY_ARRAY)
52 return 1;
53
54 while (cv) {
55 if (cv->type != CFG_STRING) {
56 log_error("Found a tag that is not a string");
57 return 0;
58 }
59
60 if (!str_list_add(mem, tags, dm_pool_strdup(mem, cv->v.str)))
61 return_0;
62
63 cv = cv->next;
64 }
65
66 return 1;
67 }
68