Add configuration system
authorChip Black <bytex64@bytex64.net>
Thu, 2 Jan 2014 09:54:52 +0000 (03:54 -0600)
committerChip Black <bytex64@bytex64.net>
Sat, 29 Mar 2014 03:56:24 +0000 (22:56 -0500)
Makefile
config.h
configure.in
database/configuration.c [new file with mode: 0644]
database/configuration.h [new file with mode: 0644]
database/database.c
database/database.h

index fe4691f..e305aaa 100644 (file)
--- 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
index b363206..b0e00bd 100644 (file)
--- 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"
index a4f7731..d82aed5 100644 (file)
@@ -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 (file)
index 0000000..9db0d73
--- /dev/null
@@ -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
new file mode 100644 (file)
index 0000000..90bfb9d
--- /dev/null
@@ -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
index 9079ff4..91e6aa2 100644 (file)
@@ -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"
                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);
index e60d609..7971249 100644 (file)
@@ -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);