diff options
-rw-r--r-- | lib/util/parmlist.c | 22 | ||||
-rw-r--r-- | lib/util/parmlist.h | 18 |
2 files changed, 36 insertions, 4 deletions
diff --git a/lib/util/parmlist.c b/lib/util/parmlist.c index 4ab660197d..ffcd19a4ab 100644 --- a/lib/util/parmlist.c +++ b/lib/util/parmlist.c @@ -41,7 +41,24 @@ int parmlist_get_int(struct parmlist *ctx, const char *name, int default_v) return default_v; } -const char *parmlist_get_string(struct parmlist *ctx, const char *name, const char *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); @@ -51,7 +68,8 @@ const char *parmlist_get_string(struct parmlist *ctx, const char *name, const ch return p->value; } -const char **parmlist_get_string_list(struct parmlist *ctx, const char *name, const char *separator) +const char **parmlist_get_string_list(struct parmlist *ctx, const char *name, + const char *separator) { struct parmlist_entry *p = parmlist_get(ctx, name); diff --git a/lib/util/parmlist.h b/lib/util/parmlist.h index 0fa518d1c4..47d2f89d63 100644 --- a/lib/util/parmlist.h +++ b/lib/util/parmlist.h @@ -31,9 +31,23 @@ 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); -const char *parmlist_get_string(struct parmlist *ctx, const char *name, const char *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); -const char **parmlist_get_string_list(struct parmlist *ctx, const char *name, const char *separator); + +/** 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); #endif /* _PARMLIST_H */ |