From 3710027b43a178c02f4eee439d4d92030466df04 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Mon, 1 Dec 2008 16:52:42 +0100 Subject: Split eurephiadm.c into several files As the code size on eurephiadm.c have grown quite a lot, it was about time to split it into categories. client_config.[ch] Manages unified config file and filenames, including directory for these files. It also has the possibility to also override defaults via environment variables. It also contains a simple config file parser which puts the config values into an eurephiaVALUES struct. client_context.[ch] Functions for creating and destroying an eurephia context needed for proper implementation. client_session.[ch] Functions for creating and reopening old eurephia sessions, needed for proper implementation. Also went through all include statements, to make sure each file do not include more than absolutely needed. --- eurephiadm/client_context.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 eurephiadm/client_context.c (limited to 'eurephiadm/client_context.c') diff --git a/eurephiadm/client_context.c b/eurephiadm/client_context.c new file mode 100644 index 0000000..adcabcf --- /dev/null +++ b/eurephiadm/client_context.c @@ -0,0 +1,76 @@ +/* context.c -- Handles eurephia contexts used by admin interfaces + * + * GPLv2 - Copyright (C) 2008 David Sommerseth + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * +*/ + +#include +#include +#include +#include + +#include +#include +#include + + +eurephiaCTX *eurephiaCTX_init(FILE *log, const int loglevel, const char *dbi) { + eurephiaCTX *ctx = 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; + + if( !eDBlink_init(ctx, dbi, 2) ){ + eurephia_log(ctx, LOG_PANIC, 0, "Could not load the database driver"); + free_nullsafe(ctx); + return NULL; + } + return ctx; +} + +void eurephiaCTX_destroy(eurephiaCTX *ctx) { + if( ctx == NULL ) { + return; + } + + if( (ctx->dbc != NULL) && (ctx->dbc->dbhandle != NULL) ) { + eDBdisconnect(ctx); + } + + if( ctx->eurephia_driver != NULL ) { + eDBlink_close(ctx); + } + + if( ctx->log != NULL ) { + fflush(ctx->log); + + // Do not close log file if we're on stdout or stderr + if( (ctx->log != stderr) && (ctx->log != stdout) ) { + eurephia_log(ctx, LOG_INFO, 2, "Closing log file"); + fclose(ctx->log); + } + + ctx->log = NULL; + ctx->loglevel = 0; + } + free_nullsafe(ctx); +} -- cgit