2 * Unix SMB/CIFS implementation.
3 * Copyright (C) Jelmer Vernooij 2009
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.
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/>.
20 #include "../lib/util/dlinklist.h"
21 #include "../lib/util/parmlist.h"
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)
36 int parmlist_get_int(struct parmlist
*ctx
, const char *name
, int default_v
)
38 struct parmlist_entry
*p
= parmlist_get(ctx
, name
);
41 return strtol(p
->value
, NULL
, 0);
46 bool parmlist_get_bool(struct parmlist
*ctx
, const char *name
, bool default_v
)
48 struct parmlist_entry
*p
= parmlist_get(ctx
, name
);
54 if (!set_boolean(p
->value
, &ret
)) {
55 DEBUG(0,("lp_bool(%s): value is not boolean!\n", p
->value
));
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
);
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
);
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
);
94 e
= talloc(ctx
, struct parmlist_entry
);
97 e
->key
= talloc_strdup(e
, name
);
98 DLIST_ADD(ctx
->entries
, e
);
102 int parmlist_set_string(struct parmlist
*ctx
, const char *name
,
105 struct parmlist_entry
*e
= parmlist_get_add(ctx
, name
);
109 e
->value
= talloc_strdup(e
, value
);