diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-01 16:52:42 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-01 16:52:42 +0100 |
commit | 3710027b43a178c02f4eee439d4d92030466df04 (patch) | |
tree | e4a60c9c6b911551ecff8f89729f9e0db4f5444a /eurephiadm/client_context.c | |
parent | 5084b8eb16d6a8c3bae1863f5aa217521c1a12a1 (diff) | |
download | eurephia-3710027b43a178c02f4eee439d4d92030466df04.tar.gz eurephia-3710027b43a178c02f4eee439d4d92030466df04.tar.xz eurephia-3710027b43a178c02f4eee439d4d92030466df04.zip |
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.
Diffstat (limited to 'eurephiadm/client_context.c')
-rw-r--r-- | eurephiadm/client_context.c | 76 |
1 files changed, 76 insertions, 0 deletions
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 <dazo@users.sourceforge.net> + * + * 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 <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <eurephia_nullsafe.h> +#include <eurephia_context.h> +#include <eurephiadb.h> + + +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); +} |