From 194c8e42f32f7a2321857aa7aa4d80b56a84d43f Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 21 Apr 2014 09:54:25 +1000 Subject: [PATCH] Begin parsing of a config file, storing btcd url, auth and pass --- src/ckpool.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/generator.c | 7 ++++++- src/libckpool.h | 12 ++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index c94bc928..1512cf84 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -158,6 +158,42 @@ static void sighandler(int sig) exit(0); } +static void json_get_string(char **store, json_t *val, const char *res) +{ + json_t *entry = json_object_get(val, res); + const char *buf; + + *store = NULL; + if (json_is_null(entry)) { + LOGDEBUG("Json did not find entry %s", res); + return; + } + if (!json_is_string(entry)) { + LOGWARNING("Json entry %s is not string", res); + return; + } + buf = json_string_value(entry); + LOGDEBUG("Json found entry %s: %s", res, buf); + *store = strdup(buf); +} + +static void parse_config(ckpool_t *ckp) +{ + json_error_t err_val; + json_t *json_conf; + + json_conf = json_load_file(ckp->config, JSON_DISABLE_EOF_CHECK, &err_val); + if (!json_conf) { + LOGWARNING("Json decode error for config file %s: (%d): %s", ckp->config, + err_val.line, err_val.text); + return; + } + json_get_string(&ckp->btcdurl, json_conf, "btcdurl"); + json_get_string(&ckp->btcdauth, json_conf, "btcdauth"); + json_get_string(&ckp->btcdpass, json_conf, "btcdpass"); + json_decref(json_conf); +} + int main(int argc, char **argv) { struct sigaction handler; @@ -184,6 +220,10 @@ int main(int argc, char **argv) } } + if (!ckp.name) + ckp.name = strdup("ckpool"); + if (!ckp.config) + ckp.config = strdup("ckpool.conf"); if (!ckp.socket_dir) ckp.socket_dir = strdup("/tmp/ckpool"); @@ -196,6 +236,8 @@ int main(int argc, char **argv) if (ret && errno != EEXIST) quit(1, "Failed to make directory %s", ckp.socket_dir); + parse_config(&ckp); + ckp.main.ckp = &ckp; ckp.main.processname = strdup("main"); ckp.main.sockname = strdup("listener"); diff --git a/src/generator.c b/src/generator.c index cd77e3f5..14abf05a 100644 --- a/src/generator.c +++ b/src/generator.c @@ -7,13 +7,18 @@ * any later version. See COPYING for more details. */ +#include "config.h" + +#include + #include "ckpool.h" #include "libckpool.h" #include "generator.h" int generator(proc_instance_t *pi) { - LOGDEBUG("Process %s started", pi->processname); + connsock_t cs; + memset(&cs, 0, sizeof(cs)); return 0; } \ No newline at end of file diff --git a/src/libckpool.h b/src/libckpool.h index fad3d077..ee8028f7 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -138,13 +138,21 @@ struct proc_instance { }; struct ckpool_instance { + /* Main process name */ + char *name; + /* Directory where sockets are created */ char *socket_dir; + /* Filename of config file */ char *config; - char *name; - /* Process instances of child processes */ + /* Process instance data of parent/child processes */ proc_instance_t main; proc_instance_t generator; + + /* Bitcoind data */ + char *btcdurl; + char *btcdauth; + char *btcdpass; }; void create_pthread(pthread_t *thread, void *(*start_routine)(void *), void *arg);