diff options
author | Günther Deschner <gdeschner@redhat.com> | 2012-10-23 14:05:14 +0200 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2013-04-08 09:26:59 -0400 |
commit | 19d091b9eaddc52d9c33ab0419029603f15db1da (patch) | |
tree | 4f9923a7f2ecbfe517bc882f0ccf5d99ad9f0991 /proxy/src/gp_config_iniparser.c | |
parent | 31d5d819608e9534af9147c77d1760eebe9a252b (diff) | |
download | gss-proxy-19d091b9eaddc52d9c33ab0419029603f15db1da.tar.gz gss-proxy-19d091b9eaddc52d9c33ab0419029603f15db1da.tar.xz gss-proxy-19d091b9eaddc52d9c33ab0419029603f15db1da.zip |
Abstract configuration layer for gssproxy.
Signed-off-by: Günther Deschner <gdeschner@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'proxy/src/gp_config_iniparser.c')
-rw-r--r-- | proxy/src/gp_config_iniparser.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/proxy/src/gp_config_iniparser.c b/proxy/src/gp_config_iniparser.c new file mode 100644 index 0000000..34288d4 --- /dev/null +++ b/proxy/src/gp_config_iniparser.c @@ -0,0 +1,136 @@ +/* + GSS-PROXY + + Copyright (C) 2011 Red Hat, Inc. + Copyright (C) 2011 Simo Sorce <simo.sorce@redhat.com> + Copyright (C) 2012 Guenther Deschner <guenther.deschner@redhat.com> + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "config.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include "gp_proxy.h" +#include "gp_config.h" +#include "gp_config_iniparser.h" + +#ifdef HAVE_INIPARSER + +#include <iniparser.h> + +char *gp_iniparser_get_string(struct gp_ini_context *ctx, + const char *secname, + const char *key) +{ + dictionary *dict; + char *skey; + char *value; + int ret; + + dict = (dictionary *)ctx->private_data; + + ret = asprintf(&skey, "%s:%s", secname, key); + if (ret == -1) { + return NULL; + } + + value = iniparser_getstring(dict, skey, NULL); + free(skey); + return value; +} + +int gp_iniparser_get_int(struct gp_ini_context *ctx, + const char *secname, + const char *key) +{ + dictionary *dict; + char *skey; + int ret; + + dict = (dictionary *)ctx->private_data; + + ret = asprintf(&skey, "%s:%s", secname, key); + if (ret == -1) { + return -1; + } + + ret = iniparser_getint(dict, skey, -1); + free(skey); + return ret; +} + +int gp_iniparser_init(const char *config_file, + struct gp_ini_context *ctx) +{ + dictionary *d; + + if (!ctx) { + return EINVAL; + } + + d = iniparser_load(config_file); + if (!d) { + return ENOENT; + } + + ctx->private_data = d; + + return 0; +} + +int gp_iniparser_close(struct gp_ini_context *ctx) +{ + dictionary *dict; + + if (!ctx) { + return 0; + } + + dict = (dictionary *)ctx->private_data; + + iniparser_freedict(dict); + + return 0; +} + +int gp_iniparser_get_nsec(struct gp_ini_context *ctx) +{ + dictionary *dict = dict = (dictionary *)ctx->private_data; + + return iniparser_getnsec(dict); +} + +char *gp_iniparser_get_secname(struct gp_ini_context *ctx, + int i) +{ + dictionary *dict = dict = (dictionary *)ctx->private_data; + char *value; + + value = iniparser_getsecname(dict, i); + if (!value) { + return NULL; + } + + return strdup(value); +} + +#endif /* HAVE_INIPARSER */ |