selftest: also skip raw.search as it also spins
[Samba/gbeck.git] / lib / util / parmlist.c
blob0f2f3af8eea8f27601951c818304d937d2011c65
1 /*
2 * Unix SMB/CIFS implementation.
3 * Copyright (C) Jelmer Vernooij 2009
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include "includes.h"
20 #include "../lib/util/dlinklist.h"
21 #include "../lib/util/parmlist.h"
23 #undef strcasecmp
25 struct parmlist_entry *parmlist_get(struct parmlist *ctx, const char *name)
27 struct parmlist_entry *e;
28 for (e = ctx->entries; e; e = e->next) {
29 if (strcasecmp(e->key, name) == 0)
30 return e;
33 return NULL;
36 int parmlist_get_int(struct parmlist *ctx, const char *name, int default_v)
38 struct parmlist_entry *p = parmlist_get(ctx, name);
40 if (p != NULL)
41 return strtol(p->value, NULL, 0);
43 return default_v;
46 bool parmlist_get_bool(struct parmlist *ctx, const char *name, bool default_v)
48 struct parmlist_entry *p = parmlist_get(ctx, name);
49 bool ret;
51 if (p == NULL)
52 return default_v;
54 if (!set_boolean(p->value, &ret)) {
55 DEBUG(0,("lp_bool(%s): value is not boolean!\n", p->value));
56 return default_v;
59 return ret;
62 const char *parmlist_get_string(struct parmlist *ctx, const char *name,
63 const char *default_v)
65 struct parmlist_entry *p = parmlist_get(ctx, name);
67 if (p == NULL)
68 return default_v;
70 return p->value;
73 const char **parmlist_get_string_list(struct parmlist *ctx, const char *name,
74 const char *separator)
76 struct parmlist_entry *p = parmlist_get(ctx, name);
78 if (p == NULL)
79 return NULL;
81 return (const char **)str_list_make(ctx, p->value, separator);
84 static struct parmlist_entry *parmlist_get_add(struct parmlist *ctx, const char *name)
86 struct parmlist_entry *e = parmlist_get(ctx, name);
88 if (e != NULL)
89 return e;
91 e = talloc(ctx, struct parmlist_entry);
92 if (e == NULL)
93 return NULL;
94 e->key = talloc_strdup(e, name);
95 DLIST_ADD(ctx->entries, e);
96 return e;
99 int parmlist_set_string(struct parmlist *ctx, const char *name,
100 const char *value)
102 struct parmlist_entry *e = parmlist_get_add(ctx, name);
103 if (e == NULL)
104 return -1;
106 e->value = talloc_strdup(e, value);
107 return 0;