summaryrefslogtreecommitdiffstats
path: root/eurephiadm/client_context.c
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-01 23:10:24 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-01 23:10:24 +0100
commitcfecad2e0e5efc55394b282cbfbb5caa859f5d16 (patch)
tree91b55864b922c4d9a4549ebcb2dc78a76242fae0 /eurephiadm/client_context.c
parent57024bc8f3b7e4fee7521c8de2dca929bdc35e82 (diff)
downloadeurephia-cfecad2e0e5efc55394b282cbfbb5caa859f5d16.tar.gz
eurephia-cfecad2e0e5efc55394b282cbfbb5caa859f5d16.tar.xz
eurephia-cfecad2e0e5efc55394b282cbfbb5caa859f5d16.zip
Receive eurephiaVALUES struct with config instead of char *db interface.
Get the database driver directly from config file. Implemented also log settings via config file as well, which can be overridden by future command line arguments.
Diffstat (limited to 'eurephiadm/client_context.c')
-rw-r--r--eurephiadm/client_context.c47
1 files changed, 43 insertions, 4 deletions
diff --git a/eurephiadm/client_context.c b/eurephiadm/client_context.c
index adcabcf..e849420 100644
--- a/eurephiadm/client_context.c
+++ b/eurephiadm/client_context.c
@@ -25,21 +25,60 @@
#include <eurephia_nullsafe.h>
#include <eurephia_context.h>
+#include <eurephia_values_struct.h>
+#include <eurephia_values.h>
#include <eurephiadb.h>
-eurephiaCTX *eurephiaCTX_init(FILE *log, const int loglevel, const char *dbi) {
+eurephiaCTX *eurephiaCTX_init(FILE *log, const int loglevel, eurephiaVALUES *cfg) {
eurephiaCTX *ctx = NULL;
+ char *dbdriver = NULL, *logfile = NULL;
+ int cfgloglvl = 0;
+
+ dbdriver = eGet_value(cfg, "database_driver");
+ if( dbdriver == NULL ) {
+ eurephia_log(ctx, LOG_PANIC, 0, "No database driver given in config file (database_driver)");
+ return NULL;
+ }
ctx = (eurephiaCTX *) malloc(sizeof(eurephiaCTX)+2);
assert(ctx != NULL);
memset(ctx, 0, sizeof(eurephiaCTX)+2);
ctx->context_type = ECTX_ADMIN_CONSOLE;
- ctx->log = log;
- ctx->loglevel = loglevel;
+ // Open log file. Use config file as default if it exists, if not use input param.
+ logfile = eGet_value(cfg, "log");
+ if( (logfile != NULL) && (log == NULL) ) {
+ if( strcmp(logfile, "stdout:") == 0 ) {
+ ctx->log = stdout;
+ } else if( strcmp(logfile, "stderr:") == 0 ) {
+ ctx->log = stderr;
+ } else if( strcmp(logfile, "none:") == 0 ) {
+ ctx->log = NULL;
+ } else if( (ctx->log = fopen(logfile, "aw")) == NULL ) {
+ fprintf(stderr, "ERROR: Could not open log file: %s\n", logfile);
+ free_nullsafe(ctx);
+ return NULL;
+ }
+ } else if( logfile == NULL ) {
+ // If not log file is set in config, use input log parameter. But if
+ // no log file is defined even here, use stderr. If no logging is wanted, it
+ // must be defined as none: in the config file.
+ ctx->log = (log != NULL ? log : stderr);
+ }
+
+ // Set log level. Use config file as default if it exists, if not input param defaults.
+ // But if input param loglevel > 0, then override config file.
+ // Only set loglevel if logging is enabled.
+ if( ctx->log != NULL ) {
+ cfgloglvl = ((eGet_value(cfg, "log_level") == NULL)
+ ? loglevel : atoi_nullsafe(eGet_value(cfg, "log_level")));
+ ctx->loglevel = (loglevel > 0 ? loglevel : cfgloglvl);
+ } else {
+ ctx->loglevel = 0;
+ }
- if( !eDBlink_init(ctx, dbi, 2) ){
+ if( !eDBlink_init(ctx, dbdriver, 2) ) {
eurephia_log(ctx, LOG_PANIC, 0, "Could not load the database driver");
free_nullsafe(ctx);
return NULL;