summaryrefslogtreecommitdiff
path: root/lib/util/parmlist.c
blob: 4ab660197d04e85a39bd7297d48d446ea54a4d91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* 
 *  Unix SMB/CIFS implementation.
 *  Copyright (C) Jelmer Vernooij			2009
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "includes.h"
#include "../lib/util/dlinklist.h"
#include "../lib/util/parmlist.h"

struct parmlist_entry *parmlist_get(struct parmlist *ctx, const char *name)
{
	struct parmlist_entry *e;
	for (e = ctx->entries; e; e = e->next) {
		if (strcasecmp(e->key, name) == 0)
			return e;
	}

	return NULL;
}

int parmlist_get_int(struct parmlist *ctx, const char *name, int default_v)
{
	struct parmlist_entry *p = parmlist_get(ctx, name);

	if (p != NULL)
		return strtol(p->value, NULL, 0); 

	return default_v;
}

const char *parmlist_get_string(struct parmlist *ctx, const char *name, const char *default_v)
{
	struct parmlist_entry *p = parmlist_get(ctx, name);

	if (p == NULL)
		return default_v;

	return p->value;
}

const char **parmlist_get_string_list(struct parmlist *ctx, const char *name, const char *separator)
{
	struct parmlist_entry *p = parmlist_get(ctx, name);

	if (p == NULL)
		return NULL;

	return (const char **)str_list_make(ctx, p->value, separator);
}