ctdb-logging: Add logging via UDP to 127.0.0.1:514 to syslog backend
[Samba.git] / lib / util / parmlist.c
blobb3e1e9fc48e1ccb5303c9ed1f169b80742df818d
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);
77 char **l;
79 if (p == NULL) {
80 return NULL;
83 l = str_list_make(ctx, p->value, separator);
84 return discard_const_p(const char *, l);
87 static struct parmlist_entry *parmlist_get_add(struct parmlist *ctx, const char *name)
89 struct parmlist_entry *e = parmlist_get(ctx, name);
91 if (e != NULL)
92 return e;
94 e = talloc(ctx, struct parmlist_entry);
95 if (e == NULL)
96 return NULL;
97 e->key = talloc_strdup(e, name);
98 DLIST_ADD(ctx->entries, e);
99 return e;
102 int parmlist_set_string(struct parmlist *ctx, const char *name,
103 const char *value)
105 struct parmlist_entry *e = parmlist_get_add(ctx, name);
106 if (e == NULL)
107 return -1;
109 e->value = talloc_strdup(e, value);
110 return 0;