From 4f49323af05f718d21b61f9763d73280430beaf2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 4 Nov 2008 17:31:40 -0500 Subject: Add some more service functions --- server/confdb/confdb.c | 42 ++++++++++++++++++++++++++++++++++++++++++ server/confdb/confdb.h | 4 ++++ 2 files changed, 46 insertions(+) (limited to 'server') diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c index 1dd79982..bab94b3f 100644 --- a/server/confdb/confdb.c +++ b/server/confdb/confdb.c @@ -316,6 +316,48 @@ int confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx, return EOK; } +int confdb_get_int(struct confdb_ctx *cdb, TALLOC_CTX *ctx, + const char *section, const char *attribute, + int defval, int *result) +{ + char **values; + long int val; + int ret; + + ret = confdb_get_param(cdb, ctx, section, attribute, &values); + if (ret != EOK) { + return ret; + } + + if (values[0]) { + if (values[1] != NULL) { + /* too many values */ + talloc_free(values); + return EINVAL; + } + + errno = 0; + val = strtol(values[0], NULL, 0); + if (errno) { + talloc_free(values); + return errno; + } + + if (val < INT_MIN || val > INT_MAX) { + talloc_free(values); + return ERANGE; + } + + } else { + val = defval; + } + + talloc_free(values); + + *result = (int)val; + return EOK; +} + static int confdb_test(struct confdb_ctx *cdb) { char **values; diff --git a/server/confdb/confdb.h b/server/confdb/confdb.h index b8b68531..7841d4c1 100644 --- a/server/confdb/confdb.h +++ b/server/confdb/confdb.h @@ -38,6 +38,10 @@ int confdb_get_string(struct confdb_ctx *cdb, TALLOC_CTX *ctx, const char *section, const char *attribute, const char *defstr, char **result); +int confdb_get_int(struct confdb_ctx *cdb, TALLOC_CTX *ctx, + const char *section, const char *attribute, + int defval, int *result); + int confdb_init(TALLOC_CTX *mem_ctx, struct event_context *ev, struct confdb_ctx **cdb_ctx); -- cgit