From 0647b76522be38edfe4b1fbae32addbbf8bb4128 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Thu, 2 Jan 2014 03:54:52 -0600 Subject: [PATCH] Add configuration system --- Makefile | 2 +- config.h | 1 + configure.in | 18 ++++++++++++++++-- database/configuration.c | 22 ++++++++++++++++++++++ database/configuration.h | 17 +++++++++++++++++ database/database.c | 8 ++++++++ database/database.h | 1 + 7 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 database/configuration.c create mode 100644 database/configuration.h diff --git a/Makefile b/Makefile index fe4691f..e305aaa 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ HTTP_LIBDIRS = $(MHD_LIBDIR) $(YAJL_LIBDIR) CGI_LIBDIRS = $(CGI_UTIL_LIBDIR) $(YAJL_LIBDIR) targets = blerg.a blerg_auth.a blergtool blerglatest blerg.cgi www/build/enyo-blerg.js -blerg_a_objects = database/database.o database/tags.o database/util.o database/subscription.o common/stringbucket.o +blerg_a_objects = database/database.o database/tags.o database/util.o database/configuration.o database/subscription.o common/stringbucket.o blerg_auth_a_objects = common/auth.o common/md5.o blergtool_objects = tools/blergtool.o blerg.a blerglatest_objects = tools/blerglatest.o blerg.a common/json.o diff --git a/config.h b/config.h index b363206..b0e00bd 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,7 @@ #ifndef _CONFIG_H #define _CONFIG_H +#define BLERG_PATH "/var/lib/blerg" #define DATA_PATH "data" #define HASH_TAGS_PATH "hash_tags" #define REF_TAGS_PATH "ref_tags" diff --git a/configure.in b/configure.in index a4f7731..d82aed5 100644 --- a/configure.in +++ b/configure.in @@ -40,13 +40,27 @@ AC_FUNC_REALLOC AC_CHECK_FUNCS([ftruncate memset mkdir munmap select strchr strtoull]) # Needed variables for programs to function... +AC_ARG_WITH([blerg-path], +AC_HELP_STRING([--with-blerg-path=@<:@DIR@:>@], +[Base directory for database default=/var/lib/blerg] +), +[ +if test "$withval" != "no"; then + AC_DEFINE_UNQUOTED([DATA_PATH], ["$withval"], [Base data directory]) +else + AC_MSG_ERROR(blerg-path MUST be defined) +fi +], +[AC_DEFINE([BLERG_PATH], ["/var/lib/blerg"], [Base data directory])] +) + AC_ARG_WITH([blerg-data-path], AC_HELP_STRING([--with-blerg-data-path=@<:@DIR@:>@], -[Where database files will be stored default=data] +[Where account data will be stored default=data] ), [ if test "$withval" != "no"; then - AC_DEFINE_UNQUOTED([DATA_PATH], ["$withval"], [Where data is located]) + AC_DEFINE_UNQUOTED([DATA_PATH], ["$withval"], [Where account data is located]) else AC_MSG_ERROR(blerg-data-path MUST be defined) fi diff --git a/database/configuration.c b/database/configuration.c new file mode 100644 index 0000000..9db0d73 --- /dev/null +++ b/database/configuration.c @@ -0,0 +1,22 @@ +/* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a + * BSD-style license. Please see the COPYING file for details. + */ +#include +#include +#include +#include "configuration.h" +#include "config.h" + +struct blerg_configuration blergconf; + +int blerg_configuration_init() { + char *a; + + a = getenv("BLERG_PATH"); + if (a == NULL) { + strncpy(blergconf.base_path, BLERG_PATH, FILENAME_MAX); + } else { + strncpy(blergconf.base_path, a, FILENAME_MAX); + } + return 1; +} diff --git a/database/configuration.h b/database/configuration.h new file mode 100644 index 0000000..90bfb9d --- /dev/null +++ b/database/configuration.h @@ -0,0 +1,17 @@ +/* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a + * BSD-style license. Please see the COPYING file for details. + */ +#ifndef _CONFIGURATION_H +#define _CONFIGURATION_H + +#include + +struct blerg_configuration { + char base_path[FILENAME_MAX]; +}; + +int blerg_configuration_init(); + +extern struct blerg_configuration blergconf; + +#endif //_CONFIGURATION_H diff --git a/database/database.c b/database/database.c index 9079ff4..91e6aa2 100644 --- a/database/database.c +++ b/database/database.c @@ -13,6 +13,7 @@ #include #include #include "database.h" +#include "configuration.h" #include "subscription.h" #include "util.h" #include "config.h" @@ -23,6 +24,13 @@ return r; \ } +int blerg_init() { + if (!blerg_configuration_init()) { + return 0; + } + return 1; +} + uint64_t blerg_get_record_count(struct blerg *blerg) { uint64_t count; flock(blerg->meta_fd, LOCK_SH); diff --git a/database/database.h b/database/database.h index e60d609..7971249 100644 --- a/database/database.h +++ b/database/database.h @@ -40,6 +40,7 @@ struct blerg { #define BLERG_INVALID_RECORD 0xFFFFFFFFFFFFFFFF +int blerg_init(); int blerg_exists(const char *name); struct blerg *blerg_open(const char *name); int blerg_close(struct blerg *blerg); -- 2.25.1