diff --git a/Makefile.am b/Makefile.am
index bfe6e99..149f750 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,55 @@ ACLOCAL_AMFLAGS = -I m4
#create_token_LDADD = src/libtoken.la $(LIBOBJS)
#create_token_CFLAGS = -Wall -I include
-EXTRA_DIST = include assets certs config run
+EXTRA_DIST = include certs assets config run
+
+myetc_DATA = config/mime.types config/taskrambler.conf
+
+nobase_varlib_DATA = assets/html/example.html \
+ assets/html/_footer.html \
+ assets/html/_login.html \
+ assets/html/_menu.html \
+ assets/html/_signup.html \
+ assets/html/_statusline.html \
+ assets/html/_title.html \
+ assets/html/_author.html \
+ assets/html/_main.html \
+ assets/html/author.html \
+ assets/html/documentation.html \
+ assets/html/download.html \
+ assets/html/layout.html \
+ assets/html/main.html \
+ assets/html/_documentation.html \
+ assets/html/_download.html \
+ assets/image/waldschrat.jpg \
+ assets/image/fav128.png \
+ assets/image/fav16.png \
+ assets/image/fav256.png \
+ assets/image/fav32.png \
+ assets/image/fav64.png \
+ assets/image/favicon.ico \
+ assets/image/rambler-bg.jpg \
+ assets/image/rambler-border-b.jpg \
+ assets/image/rambler-border-bl.jpg \
+ assets/image/rambler-border-br.jpg \
+ assets/image/rambler-border-l.jpg \
+ assets/image/rambler-border-r.jpg \
+ assets/image/rambler-border-t.jpg \
+ assets/image/rambler-border-tl.jpg \
+ assets/image/rambler-border-tr.jpg \
+ assets/image/rambler-logo-small.jpg \
+ assets/image/rambler-logo2-small.jpg \
+ assets/js/jquery-1.7.1.js \
+ assets/js/jquery-1.7.1.min.js \
+ assets/js/jquery.js \
+ assets/js/serverval.js \
+ assets/js/session.js \
+ assets/js/init.js \
+ assets/other/OldNewspaperTypes.ttf \
+ assets/other/old_typewriter.ttf \
+ assets/style/taskrambler.css \
+ assets/style/common.css \
+ assets/favicon.ico
SUBDIRS = src tests docs
@@ -20,3 +68,8 @@ if HAVE_GCOV
coverage-html:
-$(MAKE) -C tests $(AM_MAKEFLAGS) -k $@
endif
+
+install-data-hook:
+ mkdir -p $(varlibdir)/assets/doc $(varlibdir)/assets/html/doc $(varrundir)
+ $(LN_S) -f $(trdatadir)/docs/api/$(PACKAGE_VERSION)/html $(varlibdir)/assets/doc/$(PACKAGE_VERSION)
+ $(LN_S) -f $(trdatadir)/docs/api/$(PACKAGE_VERSION)/html $(varlibdir)/assets/html/doc/$(PACKAGE_VERSION)
diff --git a/configure.ac b/configure.ac
index b4912da..37e0189 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,6 +62,24 @@ AC_TYPE_SIZE_T
#AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset])
+myetcdir=${sysconfdir}/taskrambler
+varlibdir=${localstatedir}/lib/taskrambler
+varrundir=${localstatedir}/run/taskrambler
+trdatadir=${datadir}/taskrambler
+AC_SUBST(myetcdir)
+AC_SUBST(varlibdir)
+AC_SUBST(varrundir)
+AC_SUBST(trdatadir)
+
+AM_CFLAGS="${AM_CFLAGS} ${DRAGONEGG_FLAGS}"
+AM_CFLAGS="${AM_CFLAGS} ${MEM_OPT_FLAGS}"
+AM_CFLAGS="${AM_CFLAGS} -DPWD=\\\"${PWD}\\\""
+AM_CFLAGS="${AM_CFLAGS} -DCONFIGDIR=\\\"${myetcdir}\\\""
+AM_CFLAGS="${AM_CFLAGS} ${CFLAGS}"
+AC_SUBST(AM_CFLAGS)
+
+AC_CONFIG_FILES([config/taskrambler.conf])
+
AC_CONFIG_FILES([Makefile
src/Makefile
src/asset/Makefile
@@ -80,6 +98,7 @@ AC_CONFIG_FILES([Makefile
src/application/Makefile
src/storage/Makefile
src/user/Makefile
+ src/config/Makefile
docs/Makefile
tests/Makefile])
AC_OUTPUT
diff --git a/include/config/config.h b/include/config/config.h
new file mode 100644
index 0000000..983b389
--- /dev/null
+++ b/include/config/config.h
@@ -0,0 +1,42 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 2012 Georg Hopp
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see .
+ */
+
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+#include "hash.h"
+#include "class.h"
+#include "config/value.h"
+
+#define MAX_CONFIG_LINE 256
+
+
+CLASS(Config) {
+ char * cnf_file;
+ Hash config;
+};
+
+ConfigValue configGet(Config, const char *, size_t);
+
+#endif // __CONFIG_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/config/value.h b/include/config/value.h
new file mode 100644
index 0000000..0ed8875
--- /dev/null
+++ b/include/config/value.h
@@ -0,0 +1,55 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 2012 Georg Hopp
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see .
+ */
+
+#ifndef __CONFIG_VALUE_H__
+#define __CONFIG_VALUE_H__
+
+#include
+
+#include "hash.h"
+#include "class.h"
+
+#define MAX_CONFIG_LINE 256
+
+#define CONFSTRA(val) ((val)->value).string, (val)->nvalue
+
+
+typedef enum e_ConfigValueType {
+ CONFIG_VALUE_NUMERIC = 0,
+ CONFIG_VALUE_STRING = 1
+} ConfigValueType;
+
+CLASS(ConfigValue) {
+ union {
+ char * string;
+ long long number;
+ } value;
+
+ size_t nvalue;
+ ConfigValueType type;
+
+ unsigned long hash;
+};
+
+#endif // __CONFIG_VALUE_H__
+
+// vim: set ts=4 sw=4:
diff --git a/src/Makefile.am b/src/Makefile.am
index 32ef9d3..09f6e6e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,23 +26,18 @@ LIBS = ./application/libapplication.a \
./session/libsession.a \
./socket/libsocket.a \
./stream/libstream.a \
- ./tree/libtree.a
+ ./tree/libtree.a \
+ ./config/libconfig.a
-AM_CFLAGS = -Wall -I ../include/
+AM_CFLAGS += -I../include/
bin_PROGRAMS = taskrambler
-
taskrambler_SOURCES = taskrambler.c $(IFACE) $(UTILS)
-taskrambler_CFLAGS = $(CFLAGS) \
- $(DRAGONEGG_FLAGS) \
- -Wall \
- -DPWD=\"$(PWD)\" \
- $(MEM_OPT_FLAGS) \
- -I../include/ # $(COVERAGE_CFLAGS)
+taskrambler_CFLAGS = $(AM_CFLAGS)
taskrambler_LDADD = $(LIBS) -lrt -lssl -lldap -lgdbm -luuid
#taskrambler_LDFLAGS = $(COVERAGE_LDFLAGS)
SUBDIRS = asset auth cbuf class hash queue http \
logger server session socket stream tree application \
- storage user
+ storage user config
diff --git a/src/application/Makefile.am b/src/application/Makefile.am
index 1c01321..7be0e8f 100644
--- a/src/application/Makefile.am
+++ b/src/application/Makefile.am
@@ -12,7 +12,9 @@ APPLICATION = application.c \
ADAPTERHTTP = adapter/http/http.c \
adapter/http/update.c
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libapplication.a
libapplication_a_SOURCES = $(APPLICATION) $(ADAPTERHTTP)
-libapplication_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../ -I ../../include/
+libapplication_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/asset/Makefile.am b/src/asset/Makefile.am
index 98cd248..9a96670 100644
--- a/src/asset/Makefile.am
+++ b/src/asset/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libasset.a
libasset_a_SOURCES = asset.c pool.c
-libasset_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libasset_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/auth/Makefile.am b/src/auth/Makefile.am
index 524363a..be28d13 100644
--- a/src/auth/Makefile.am
+++ b/src/auth/Makefile.am
@@ -1,6 +1,8 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libauth.a
libauth_a_SOURCES = interface/auth.c \
@@ -8,4 +10,4 @@ libauth_a_SOURCES = interface/auth.c \
ldap.c \
storage/storage.c \
storage/hash_pw.c
-libauth_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libauth_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/cbuf/Makefile.am b/src/cbuf/Makefile.am
index 7bbc002..6397e1e 100644
--- a/src/cbuf/Makefile.am
+++ b/src/cbuf/Makefile.am
@@ -8,7 +8,9 @@ CB = cbuf.c read.c \
skip_non_alpha.c is_locked.c lock.c release.c \
empty.c
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libcbuf.a
libcbuf_a_SOURCES = $(CB)
-libcbuf_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libcbuf_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/class/Makefile.am b/src/class/Makefile.am
index b8af60b..b776aeb 100644
--- a/src/class/Makefile.am
+++ b/src/class/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libclass.a
libclass_a_SOURCES = interface.c interface/i_class.c
-libclass_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libclass_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/config/Makefile.am b/src/config/Makefile.am
new file mode 100644
index 0000000..71b5e23
--- /dev/null
+++ b/src/config/Makefile.am
@@ -0,0 +1,11 @@
+ACLOCAL_AMFLAGS = -I m4
+AUTOMAKE_OPTIONS = subdir-objects
+
+CONFIG = config.c value.c get.c
+
+AM_CFLAGS += -I../../include/
+
+noinst_LIBRARIES = libconfig.a
+
+libconfig_a_SOURCES = $(CONFIG)
+libconfig_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/config/config.c b/src/config/config.c
new file mode 100644
index 0000000..909c25f
--- /dev/null
+++ b/src/config/config.c
@@ -0,0 +1,122 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 2012 Georg Hopp
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see .
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include "class.h"
+#include "config/config.h"
+#include "config/value.h"
+#include "utils/memory.h"
+
+static
+int
+configCtor(void * _this, va_list * params)
+{
+ Config this = _this;
+
+ FILE * handle;
+ char line[MAX_CONFIG_LINE];
+ char * cnf_file = va_arg(*params, char *);
+ size_t ncnf_file = strlen(cnf_file);
+
+ this->cnf_file = memMalloc(ncnf_file + 1);
+ memcpy(this->cnf_file, cnf_file, ncnf_file);
+ this->cnf_file[ncnf_file] = '\0';
+
+ handle = fopen(this->cnf_file, "r");
+ if (NULL == handle) {
+ MEM_FREE(this->cnf_file);
+ return -1;
+ }
+
+ this->config = new(Hash);
+
+ line[MAX_CONFIG_LINE] = '\0';
+
+ while(NULL != fgets(line, MAX_CONFIG_LINE, handle)) {
+ char * key = line;
+ size_t nkey = 0;
+ size_t nvalue = 0;
+ size_t nspaces = 0;
+ char * value;
+
+ while (isspace(*key)) {
+ key++;
+ }
+
+ if ('#' == *key) {
+ continue;
+ }
+
+ while (! isspace(key[nkey])) {
+ nkey++;
+ }
+
+ value = &(key[nkey+1]);
+ while (isspace(*value)) {
+ value++;
+ }
+
+ while ('\0' != value[nvalue+nspaces]
+ && '\n' != value[nvalue+nspaces])
+ {
+ if (isspace(value[nvalue+nspaces])) {
+ nspaces++;
+ } else {
+ if (0 != nspaces) {
+ nvalue += nspaces;
+ nspaces = 0;
+ }
+ nvalue++;
+ }
+ }
+
+ value[nvalue] = '\0';
+
+ if (0 != nkey && 0 != nvalue) {
+ hashAdd(
+ this->config,
+ new(ConfigValue, key, nkey, value, nvalue));
+ }
+ }
+
+ fclose(handle);
+
+ return 0;
+}
+
+static void configDtor(void * _this)
+{
+ Config this = _this;
+
+ MEM_FREE(this->cnf_file);
+ delete(this->config);
+}
+
+INIT_IFACE(Class, configCtor, configDtor, NULL);
+CREATE_CLASS(Config, NULL, IFACE(Class));
+
+// vim: set ts=4 sw=4:
diff --git a/src/config/get.c b/src/config/get.c
new file mode 100644
index 0000000..4e1dd34
--- /dev/null
+++ b/src/config/get.c
@@ -0,0 +1,36 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 2012 Georg Hopp
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see .
+ */
+
+#include
+
+#include "class.h"
+#include "hash/hash.h"
+#include "config/config.h"
+#include "config/value.h"
+
+ConfigValue
+configGet(Config this, const char * key, size_t nkey)
+{
+ return hashGet(this->config, key, nkey);
+}
+
+// vim: set ts=4 sw=4:
diff --git a/src/config/value.c b/src/config/value.c
new file mode 100644
index 0000000..7472dd5
--- /dev/null
+++ b/src/config/value.c
@@ -0,0 +1,100 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 2012 Georg Hopp
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, see .
+ */
+
+#include
+#include
+#include
+#include
+
+#include "class.h"
+#include "config/value.h"
+#include "utils/memory.h"
+#include "utils/hash.h"
+
+static
+int
+configValueCtor(void * _this, va_list * params)
+{
+ ConfigValue this = _this;
+
+ char * key = va_arg(*params, char *);
+ size_t nkey = va_arg(*params, size_t);
+ char * value = va_arg(*params, char *);
+ size_t nvalue = va_arg(*params, size_t);
+
+ this->hash = sdbm((unsigned char *)key, nkey);
+
+ /**
+ * if we find the value enclosed by single or double
+ * quotes we take it as a string, else we take it
+ * as a numeric which is treated as a long long
+ * right now.
+ */
+ if (('"' == value[0] && '"' == value[nvalue-1])
+ || ('\'' == value[0] && '\'' == value[nvalue-1]))
+ {
+ this->type = CONFIG_VALUE_STRING;
+ (this->value).string = memMalloc(nvalue-1);
+ (this->value).string[nvalue-1] = '\0';
+ memcpy((this->value).string, value+1, nvalue-2);
+ this->nvalue = nvalue;
+ } else {
+ this->type = CONFIG_VALUE_NUMERIC;
+ (this->value).number = atoll(value);
+ this->nvalue = sizeof(long long);
+ }
+
+ return 0;
+}
+
+static
+void
+configValueDtor(void * _this)
+{
+ ConfigValue this = _this;
+
+ if (CONFIG_VALUE_STRING == this->type) {
+ MEM_FREE((this->value).string);
+ }
+}
+
+static
+unsigned long
+configValueGetHash(void * _this)
+{
+ ConfigValue this = _this;
+
+ return this->hash;
+}
+
+static
+void
+configValueHandleDouble(void * _this, void * _double)
+{
+ /* right now I do nothing...but I could :D */
+}
+
+INIT_IFACE(Class, configValueCtor, configValueDtor, NULL);
+INIT_IFACE(Hashable, configValueGetHash, configValueHandleDouble);
+CREATE_CLASS(ConfigValue, NULL, IFACE(Class), IFACE(Hashable));
+
+// vim: set ts=4 sw=4:
diff --git a/src/configtest.c b/src/configtest.c
new file mode 100644
index 0000000..9ae31e0
--- /dev/null
+++ b/src/configtest.c
@@ -0,0 +1,42 @@
+#include
+
+#include "class.h"
+#include "commons.h"
+#include "config/config.h"
+#include "config/value.h"
+#include "utils/memory.h"
+
+int
+main(int argc, char * argv[])
+{
+ Config config = new(Config, "./testconfig.cfg");
+ ConfigValue val;
+
+ val = configGet(config, CSTRA("dummy"));
+
+ if (NULL != val) {
+ switch (val->type) {
+ case CONFIG_VALUE_STRING:
+ printf(
+ "Value for dummy: (STRING): %s\n",
+ (val->value).string);
+ break;
+
+ case CONFIG_VALUE_NUMERIC:
+ printf(
+ "Value for dummy: (NUMERIC): %lld\n",
+ (val->value).number);
+ break;
+
+ default:
+ printf("Invalid config...that should never happen\n");
+ }
+ }
+
+ delete(config);
+ memCleanup();
+
+ return 0;
+}
+
+// vim: set et ts=4 sw=4:
diff --git a/src/hash/Makefile.am b/src/hash/Makefile.am
index 914273e..699bdfb 100644
--- a/src/hash/Makefile.am
+++ b/src/hash/Makefile.am
@@ -4,7 +4,9 @@ AUTOMAKE_OPTIONS = subdir-objects
HASH = hash.c add.c get.c get_first.c delete.c each.c value.c \
cleanup.c interface/hashable.c
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libhash.a
libhash_a_SOURCES = $(HASH)
-libhash_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libhash_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/http/Makefile.am b/src/http/Makefile.am
index 176ff2e..434e403 100644
--- a/src/http/Makefile.am
+++ b/src/http/Makefile.am
@@ -38,8 +38,10 @@ WORKER = worker.c \
HEADER = header.c \
header/to_string.c
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libhttp.a
libhttp_a_SOURCES = $(MSG) $(REQ) $(RESP) $(PARSER) $(WRITER) \
$(WORKER) $(HEADER) interface/i_http_intro.c
-libhttp_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../ -I ../../include/
+libhttp_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/http/worker/process.c b/src/http/worker/process.c
index 2e5f90f..c7093b1 100644
--- a/src/http/worker/process.c
+++ b/src/http/worker/process.c
@@ -40,6 +40,8 @@
#include "http/request.h"
#include "http/response.h"
#include "http/parser.h"
+#include "config/config.h"
+#include "config/value.h"
#include "interface/subject.h"
@@ -52,6 +54,7 @@ HttpMessage httpWorkerGetAsset(HttpWorker, const char *);
void httpWorkerAddCommonHeader(HttpWorker);
void httpWorkerAddComputedHeader(HttpWorker);
+extern Config config;
ssize_t
httpWorkerProcess(HttpWorker this, Stream st)
@@ -82,14 +85,20 @@ httpWorkerProcess(HttpWorker this, Stream st)
}
if (0 == strcmp("GET", this->current_request->method)) {
- char html_asset[2048] = "./assets/html";
- char base_asset[2048] = "./assets";
- char main_asset[] = "/main.html";
+ ConfigValue assets_dir =
+ configGet(config, CSTRA("assets_dir"));
+
+ char asset_path[2048];
+
+ char html_asset[] = "/assets/html";
+ char base_asset[] = "/assets";
+ char main_asset[] = "/main.html";
- char * asset_path = base_asset;
char * asset;
char * mime_type;
+ strcpy(asset_path, (assets_dir->value).string);
+
if (0 == strcmp("/", this->current_request->path)) {
asset = main_asset;
} else {
@@ -104,7 +113,9 @@ httpWorkerProcess(HttpWorker this, Stream st)
if (NULL != mime_type &&
0 == memcmp(mime_type, CSTRA("text/html"))) {
- asset_path = html_asset;
+ strcat(asset_path, html_asset);
+ } else {
+ strcat(asset_path, base_asset);
}
strcat(asset_path, asset);
diff --git a/src/logger/Makefile.am b/src/logger/Makefile.am
index 3129465..f0bf5dc 100644
--- a/src/logger/Makefile.am
+++ b/src/logger/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = liblogger.a
liblogger_a_SOURCES = interface/i_logger.c logger.c stderr.c syslog.c
-liblogger_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+liblogger_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/queue/Makefile.am b/src/queue/Makefile.am
index fa604dd..c4f01ca 100644
--- a/src/queue/Makefile.am
+++ b/src/queue/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libqueue.a
libqueue_a_SOURCES = queue.c get.c put.c
-libqueue_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libqueue_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/server/Makefile.am b/src/server/Makefile.am
index 6223abc..9a67a09 100644
--- a/src/server/Makefile.am
+++ b/src/server/Makefile.am
@@ -4,7 +4,9 @@ AUTOMAKE_OPTIONS = subdir-objects
SERVER = server.c run.c close_conn.c poll.c \
handle_accept.c read.c write.c
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libserver.a
libserver_a_SOURCES = $(SERVER)
-libserver_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libserver_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/session/Makefile.am b/src/session/Makefile.am
index a0b69b5..a20394b 100644
--- a/src/session/Makefile.am
+++ b/src/session/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libsession.a
libsession_a_SOURCES = session.c
-libsession_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libsession_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/socket/Makefile.am b/src/socket/Makefile.am
index 8157bb1..b93c272 100644
--- a/src/socket/Makefile.am
+++ b/src/socket/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libsocket.a
libsocket_a_SOURCES = socket.c accept.c connect.c listen.c nonblock.c
-libsocket_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libsocket_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/socket/listen.c b/src/socket/listen.c
index aff5273..a23ee41 100644
--- a/src/socket/listen.c
+++ b/src/socket/listen.c
@@ -32,7 +32,8 @@ void
socketListen(Sock this, int backlog)
{
(this->addr).sin_family = AF_INET; // Internet address family
- (this->addr).sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface
+ //(this->addr).sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface
+ (this->addr).sin_addr.s_addr = inet_addr("127.0.0.1"); // Any incoming interface
(this->addr).sin_port = htons(this->port); // Local port
/**
diff --git a/src/storage/Makefile.am b/src/storage/Makefile.am
index 1b2aab1..e00006c 100644
--- a/src/storage/Makefile.am
+++ b/src/storage/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libstorage.a
libstorage_a_SOURCES = storage.c get.c put.c update.c
-libstorage_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libstorage_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/stream/Makefile.am b/src/stream/Makefile.am
index 172ff84..88e74b8 100644
--- a/src/stream/Makefile.am
+++ b/src/stream/Makefile.am
@@ -5,7 +5,9 @@ STREAM = stream.c read.c write.c
IFACE = interface/reader.c \
interface/writer.c
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libstream.a
libstream_a_SOURCES = $(STREAM) $(IFACE)
-libstream_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libstream_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/taskrambler.c b/src/taskrambler.c
index 27722e5..0c7b317 100644
--- a/src/taskrambler.c
+++ b/src/taskrambler.c
@@ -42,6 +42,8 @@
#include "application/application.h"
#include "application/adapter/http.h"
#include "interface/subject.h"
+#include "config/config.h"
+#include "config/value.h"
#include "class.h"
#include "logger.h"
@@ -55,14 +57,13 @@
//#define DEFAULT_SECS 1
#define DEFAULT_USECS 0
-#define LDAP_BASE "ou=user,dc=yabrog,dc=weird-web-workers,dc=org"
-
void nullhandler() {}
void daemonize(void);
Logger logger;
+Config config;
int
main()
@@ -73,6 +74,8 @@ main()
int shm;
struct randval * value;
+ config = new(Config, CONFIGDIR "/taskrambler.conf");
+
struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY};
setrlimit(RLIMIT_CPU, &limit);
@@ -149,6 +152,23 @@ main()
HttpWorker worker;
Server server;
+ ConfigValue ldap_base =
+ configGet(config, CSTRA("ldap_base"));
+ ConfigValue ldap_host =
+ configGet(config, CSTRA("ldap_host"));
+ ConfigValue runtime_dir =
+ configGet(config, CSTRA("runtime_dir"));
+ ConfigValue port =
+ configGet(config, CSTRA("port"));
+
+ char user_storage[512];
+ char password_storage[512];
+
+ strcpy(user_storage, (runtime_dir->value).string);
+ strcpy(password_storage, (runtime_dir->value).string);
+ strcat(user_storage, "/users.db");
+ strcat(password_storage, "/passwords.db");
+
value = mmap (0, sizeof(int), PROT_READ|PROT_WRITE,
MAP_SHARED, shm, 0);
@@ -159,11 +179,11 @@ main()
authLdap = new(
AuthLdap,
- "ldap://hosted/",
- CSTRA(LDAP_BASE));
+ (ldap_host->value).string,
+ CONFSTRA(ldap_base));
- users = new(Storage, "./run/users.db");
- passwords = new(Storage, "./run/passwords.db");
+ users = new(Storage, user_storage);
+ passwords = new(Storage, password_storage);
authStorage = new(AuthStorage, passwords);
application = new(
@@ -177,10 +197,15 @@ main()
adapterHttp = new(ApplicationAdapterHttp, application);
- worker = new(HttpWorker, "testserver");
+ worker = new(HttpWorker, "taskrambler");
subjectAttach(worker, adapterHttp);
- server = new(Server, logger, worker, 11212, SOMAXCONN);
+ server = new(
+ Server,
+ logger,
+ worker,
+ (int)(port->value).number,
+ SOMAXCONN);
if (NULL != server) {
serverRun(server);
@@ -236,12 +261,14 @@ main()
clearMimeTypes();
assetPoolCleanup();
- memCleanup();
}
break;
}
+ delete(config);
+ memCleanup();
+
return 0;
}
diff --git a/src/testconfig.cfg b/src/testconfig.cfg
new file mode 100644
index 0000000..83955c0
--- /dev/null
+++ b/src/testconfig.cfg
@@ -0,0 +1,23 @@
+##
+# basic configuration file for taskrambler
+#
+# syntax:
+#
+# ::= any whitespace as defined by isspace
+# ::= any character except whitespace
+# ::= |
+# ::= any character
+# ::= " | '
+# ::=
+# ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
+#
+# Whitespaces at the beginning or the end of a line are
+# ignored.
+# everything after a # is ignored.
+#
+
+ldap_base "ou=user,dc=yabrog,dc=weird-web-workers,dc=org"
+ldap_host "ldap://hosted/"
+assets_dir "/usr/local/var/lib/taskrambler"
+runtime_dir "/usr/local/var/run/taskrambler"
+port 11212
diff --git a/src/tree/Makefile.am b/src/tree/Makefile.am
index cb44d61..9538685 100644
--- a/src/tree/Makefile.am
+++ b/src/tree/Makefile.am
@@ -4,7 +4,9 @@ AUTOMAKE_OPTIONS = subdir-objects
TREE = tree.c find.c insert.c inOrderSuccessor.c delete.c walk.c \
rotateLeft.c rotateRight.c destroy.c
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libtree.a
libtree_a_SOURCES = $(TREE)
-libtree_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libtree_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/user/Makefile.am b/src/user/Makefile.am
index 3d8f82e..a1e6ad5 100644
--- a/src/user/Makefile.am
+++ b/src/user/Makefile.am
@@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
+AM_CFLAGS += -I../../include/
+
noinst_LIBRARIES = libuser.a
libuser_a_SOURCES = user.c load.c save.c
-libuser_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
+libuser_a_CFLAGS = $(AM_CFLAGS)
diff --git a/src/utils/daemonize.c b/src/utils/daemonize.c
index bab09c8..881c506 100644
--- a/src/utils/daemonize.c
+++ b/src/utils/daemonize.c
@@ -57,10 +57,10 @@ void daemonize(void) {
// set umask and change to working directory to /
umask(UMASK);
- if (-1 == chdir(PWD)) { // this should root and assets needs to be found
- perror("daemonize"); // via some kind of configuration.
+ if (-1 == chdir("/")) {
+ perror("daemonize");
exit(EXIT_FAILURE);
- }
+ }
// we should close all open filedescriptors now.
// But I assume that this function is called at the very start of the
@@ -72,3 +72,5 @@ void daemonize(void) {
stdin = freopen("/dev/null", "r", stdin);
stdout = freopen("/dev/null", "w", stdout);
}
+
+// vim: set ts=4 sw=4:
diff --git a/src/utils/mime_type.c b/src/utils/mime_type.c
index 11899a5..641f70e 100644
--- a/src/utils/mime_type.c
+++ b/src/utils/mime_type.c
@@ -38,8 +38,8 @@ Hash mime_types = NULL;
void
readMimeTypes(void)
{
- if (0 == access("./config/mime.types", O_RDONLY)) {
- FILE * handle = fopen("./config/mime.types", "r");
+ if (0 == access(CONFIGDIR "/mime.types", O_RDONLY)) {
+ FILE * handle = fopen(CONFIGDIR "/mime.types", "r");
if (NULL != handle) {
char buffer[512];