Browse Source

Begin parsing of a config file, storing btcd url, auth and pass

master
Con Kolivas 11 years ago
parent
commit
194c8e42f3
  1. 42
      src/ckpool.c
  2. 7
      src/generator.c
  3. 12
      src/libckpool.h

42
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");

7
src/generator.c

@ -7,13 +7,18 @@
* any later version. See COPYING for more details.
*/
#include "config.h"
#include <string.h>
#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;
}

12
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);

Loading…
Cancel
Save