commit:0647b76522be38edfe4b1fbae32addbbf8bb4128
author:Chip Black
committer:Chip Black
date:Thu Jan 2 03:54:52 2014 -0600
parents:f150483b5abafe36f63821457e7867373dc7c49d
Add configuration system
diff --git a/Makefile b/Makefile
line changes: +1/-1
index fe4691f..e305aaa
--- 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
line changes: +1/-0
index b363206..b0e00bd
--- 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
line changes: +16/-2
index a4f7731..d82aed5
--- 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
line changes: +22/-0
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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#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
line changes: +17/-0
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 <stdio.h>
+
+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
line changes: +8/-0
index 9079ff4..91e6aa2
--- a/database/database.c
+++ b/database/database.c
@@ -13,6 +13,7 @@
 #include <sys/file.h>
 #include <fcntl.h>
 #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
line changes: +1/-0
index e60d609..7971249
--- 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);