summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/param/loadparm.h13
-rw-r--r--lib/util/parmlist.c111
-rw-r--r--lib/util/parmlist.h57
-rw-r--r--lib/util/tests/parmlist.c107
-rwxr-xr-xlib/util/wscript_build2
-rw-r--r--source4/torture/local/local.c1
-rw-r--r--source4/torture/local/wscript_build2
7 files changed, 14 insertions, 279 deletions
diff --git a/lib/param/loadparm.h b/lib/param/loadparm.h
index 89dcb17727c..b453aca5ef7 100644
--- a/lib/param/loadparm.h
+++ b/lib/param/loadparm.h
@@ -31,7 +31,18 @@
#define _LOADPARM_H
#include <talloc.h>
-#include "../lib/util/parmlist.h"
+
+struct parmlist_entry {
+ struct parmlist_entry *prev, *next;
+ char *key;
+ char *value;
+ char **list; /* For the source3 parametric options, to save the parsed list */
+ int priority;
+};
+
+struct parmlist {
+ struct parmlist_entry *entries;
+};
/* the following are used by loadparm for option lists */
typedef enum {
diff --git a/lib/util/parmlist.c b/lib/util/parmlist.c
deleted file mode 100644
index b3e1e9fc48e..00000000000
--- a/lib/util/parmlist.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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"
-
-#undef strcasecmp
-
-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;
-}
-
-bool parmlist_get_bool(struct parmlist *ctx, const char *name, bool default_v)
-{
- struct parmlist_entry *p = parmlist_get(ctx, name);
- bool ret;
-
- if (p == NULL)
- return default_v;
-
- if (!set_boolean(p->value, &ret)) {
- DEBUG(0,("lp_bool(%s): value is not boolean!\n", p->value));
- return default_v;
- }
-
- return ret;
-}
-
-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);
- char **l;
-
- if (p == NULL) {
- return NULL;
- }
-
- l = str_list_make(ctx, p->value, separator);
- return discard_const_p(const char *, l);
-}
-
-static struct parmlist_entry *parmlist_get_add(struct parmlist *ctx, const char *name)
-{
- struct parmlist_entry *e = parmlist_get(ctx, name);
-
- if (e != NULL)
- return e;
-
- e = talloc(ctx, struct parmlist_entry);
- if (e == NULL)
- return NULL;
- e->key = talloc_strdup(e, name);
- DLIST_ADD(ctx->entries, e);
- return e;
-}
-
-int parmlist_set_string(struct parmlist *ctx, const char *name,
- const char *value)
-{
- struct parmlist_entry *e = parmlist_get_add(ctx, name);
- if (e == NULL)
- return -1;
-
- e->value = talloc_strdup(e, value);
- return 0;
-}
diff --git a/lib/util/parmlist.h b/lib/util/parmlist.h
deleted file mode 100644
index 9bc4f361268..00000000000
--- a/lib/util/parmlist.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Generic parameter parsing interface
- 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/>.
-*/
-
-#ifndef _PARMLIST_H /* _PARMLIST_H */
-#define _PARMLIST_H
-
-struct parmlist_entry {
- struct parmlist_entry *prev, *next;
- char *key;
- char *value;
- char **list; /* For the source3 parametric options, to save the parsed list */
- int priority;
-};
-
-struct parmlist {
- struct parmlist_entry *entries;
-};
-
-/** Retrieve an integer from a parameter list. If not found, return default_v. */
-int parmlist_get_int(struct parmlist *ctx, const char *name, int default_v);
-
-/** Retrieve a string from a parameter list. If not found, return default_v. */
-const char *parmlist_get_string(struct parmlist *ctx, const char *name,
- const char *default_v);
-
-/** Retrieve the struct for an entry in a parmlist. */
-struct parmlist_entry *parmlist_get(struct parmlist *ctx, const char *name);
-
-/** Retrieve a string list from a parameter list.
- * separator can contain characters to consider separators or can be
- * NULL for the default set. */
-const char **parmlist_get_string_list(struct parmlist *ctx, const char *name,
- const char *separator);
-
-/** Retrieve boolean from a parameter list. If not set, return default_v. */
-bool parmlist_get_bool(struct parmlist *ctx, const char *name, bool default_v);
-
-/** Set a parameter. */
-int parmlist_set_string(struct parmlist *ctx, const char *name, const char *value);
-
-#endif /* _PARMLIST_H */
diff --git a/lib/util/tests/parmlist.c b/lib/util/tests/parmlist.c
deleted file mode 100644
index df589efe139..00000000000
--- a/lib/util/tests/parmlist.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- parmlist testing
-
- 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 "torture/torture.h"
-#include "torture/local/proto.h"
-#include "../lib/util/parmlist.h"
-
-static bool test_get_int(struct torture_context *tctx)
-{
- struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
- parmlist_set_string(pctx, "bar", "3");
- parmlist_set_string(pctx, "notint", "bla");
- torture_assert_int_equal(tctx, 3, parmlist_get_int(pctx, "bar", 42),
- "existing");
- torture_assert_int_equal(tctx, 42, parmlist_get_int(pctx, "foo", 42),
- "default");
- torture_assert_int_equal(tctx, 0, parmlist_get_int(pctx, "notint", 42),
- "Not an integer");
- return true;
-}
-
-static bool test_get_string(struct torture_context *tctx)
-{
- struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
- parmlist_set_string(pctx, "bar", "mystring");
- torture_assert_str_equal(tctx, "mystring",
- parmlist_get_string(pctx, "bar", "bla"), "existing");
- torture_assert_str_equal(tctx, "bla",
- parmlist_get_string(pctx, "foo", "bla"), "default");
- return true;
-}
-
-static bool test_get(struct torture_context *tctx)
-{
- struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
- struct parmlist_entry *e;
- parmlist_set_string(pctx, "bar", "mystring");
-
- e = parmlist_get(pctx, "bar");
- torture_assert(tctx, e != NULL, "entry");
- torture_assert_str_equal(tctx, e->key, "bar", "key");
- torture_assert_str_equal(tctx, e->value, "mystring", "value");
-
- e = parmlist_get(pctx, "non-existent");
- torture_assert(tctx, e == NULL, "non-existent");
- return true;
-}
-
-static bool test_get_bool(struct torture_context *tctx)
-{
- struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
- parmlist_set_string(pctx, "bar", "true");
- parmlist_set_string(pctx, "gasoline", "invalid");
-
- torture_assert(tctx, parmlist_get_bool(pctx, "bar", false), "set");
- torture_assert(tctx, !parmlist_get_bool(pctx, "foo", false), "default");
- torture_assert(tctx, !parmlist_get_bool(pctx, "gasoline", false),
- "invalid");
- return true;
-}
-
-static bool test_get_string_list(struct torture_context *tctx)
-{
- struct parmlist *pctx = talloc_zero(tctx, struct parmlist);
- const char **ret;
- parmlist_set_string(pctx, "bar", "true, false");
-
- ret = parmlist_get_string_list(pctx, "bar", NULL);
- torture_assert_int_equal(tctx, str_list_length(ret), 2, "length");
- torture_assert_str_equal(tctx, "true", ret[0], "ret[0]");
- torture_assert_str_equal(tctx, "false", ret[1], "ret[1]");
- torture_assert(tctx, NULL == parmlist_get_string_list(pctx, "non-existent", NULL), "non-existent");
-
- return true;
-}
-
-struct torture_suite *torture_local_util_parmlist(TALLOC_CTX *mem_ctx)
-{
- struct torture_suite *suite = torture_suite_create(mem_ctx, "parmlist");
-
- torture_suite_add_simple_test(suite, "get_int", test_get_int);
- torture_suite_add_simple_test(suite, "get_string", test_get_string);
- torture_suite_add_simple_test(suite, "get", test_get);
- torture_suite_add_simple_test(suite, "get_bool", test_get_bool);
- torture_suite_add_simple_test(suite, "get_string_list", test_get_string_list);
-
- return suite;
-}
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index e5c1a97d151..47d64c1ae8e 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -86,7 +86,7 @@ if not bld.env.SAMBA_UTIL_CORE_ONLY:
params.c util_id.c util_net.c
util_strlist.c util_paths.c idtree_random.c base64.c
util_str.c util_str_common.c ms_fnmatch.c
- server_id.c dprintf.c parmlist.c bitmap.c pidfile.c
+ server_id.c dprintf.c bitmap.c pidfile.c
tevent_debug.c util_process.c memcache.c''',
deps='samba-util-core DYNCONFIG close-low-fd tini tiniparser genrand',
diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c
index 5d3b4e1aa24..91e67f8117d 100644
--- a/source4/torture/local/local.c
+++ b/source4/torture/local/local.c
@@ -35,7 +35,6 @@
torture_local_messaging,
torture_local_irpc,
torture_local_util_strlist,
- torture_local_util_parmlist,
torture_local_util_file,
torture_local_util_str,
torture_local_util_time,
diff --git a/source4/torture/local/wscript_build b/source4/torture/local/wscript_build
index 570222ec344..eb45df804ee 100644
--- a/source4/torture/local/wscript_build
+++ b/source4/torture/local/wscript_build
@@ -5,7 +5,7 @@ TORTURE_LOCAL_SOURCE = '''../../../lib/util/charset/tests/iconv.c
../../lib/messaging/tests/irpc.c ../../librpc/tests/binding_string.c
../../../lib/util/tests/idtree.c ../../../lib/util/tests/dlinklist.c
../../lib/socket/testsuite.c ../../libcli/resolve/testsuite.c
- ../../../lib/util/tests/strlist.c ../../../lib/util/tests/parmlist.c
+ ../../../lib/util/tests/strlist.c
../../../lib/util/tests/str.c ../../../lib/util/tests/time.c
../../../lib/util/tests/asn1_tests.c ../../../lib/util/tests/data_blob.c
../../../lib/util/tests/file.c ../../../lib/util/tests/genrand.c