Commit 7005c8860a9cf0e3e3bc6c02fed464e14a98b6b8

Authored by Georg Hopp
1 parent 8ae57a90

make install works now. So from now on taskrambler will not work when run from i…

…ts build dir, because it can't find its assets then. To make installation work a basic config file reader class was implemented.
... ... @@ -5,7 +5,55 @@ ACLOCAL_AMFLAGS = -I m4
5 5 #create_token_LDADD = src/libtoken.la $(LIBOBJS)
6 6 #create_token_CFLAGS = -Wall -I include
7 7
8   -EXTRA_DIST = include assets certs config run
  8 +EXTRA_DIST = include certs assets config run
  9 +
  10 +myetc_DATA = config/mime.types config/taskrambler.conf
  11 +
  12 +nobase_varlib_DATA = assets/html/example.html \
  13 + assets/html/_footer.html \
  14 + assets/html/_login.html \
  15 + assets/html/_menu.html \
  16 + assets/html/_signup.html \
  17 + assets/html/_statusline.html \
  18 + assets/html/_title.html \
  19 + assets/html/_author.html \
  20 + assets/html/_main.html \
  21 + assets/html/author.html \
  22 + assets/html/documentation.html \
  23 + assets/html/download.html \
  24 + assets/html/layout.html \
  25 + assets/html/main.html \
  26 + assets/html/_documentation.html \
  27 + assets/html/_download.html \
  28 + assets/image/waldschrat.jpg \
  29 + assets/image/fav128.png \
  30 + assets/image/fav16.png \
  31 + assets/image/fav256.png \
  32 + assets/image/fav32.png \
  33 + assets/image/fav64.png \
  34 + assets/image/favicon.ico \
  35 + assets/image/rambler-bg.jpg \
  36 + assets/image/rambler-border-b.jpg \
  37 + assets/image/rambler-border-bl.jpg \
  38 + assets/image/rambler-border-br.jpg \
  39 + assets/image/rambler-border-l.jpg \
  40 + assets/image/rambler-border-r.jpg \
  41 + assets/image/rambler-border-t.jpg \
  42 + assets/image/rambler-border-tl.jpg \
  43 + assets/image/rambler-border-tr.jpg \
  44 + assets/image/rambler-logo-small.jpg \
  45 + assets/image/rambler-logo2-small.jpg \
  46 + assets/js/jquery-1.7.1.js \
  47 + assets/js/jquery-1.7.1.min.js \
  48 + assets/js/jquery.js \
  49 + assets/js/serverval.js \
  50 + assets/js/session.js \
  51 + assets/js/init.js \
  52 + assets/other/OldNewspaperTypes.ttf \
  53 + assets/other/old_typewriter.ttf \
  54 + assets/style/taskrambler.css \
  55 + assets/style/common.css \
  56 + assets/favicon.ico
9 57
10 58 SUBDIRS = src tests docs
11 59
... ... @@ -20,3 +68,8 @@ if HAVE_GCOV
20 68 coverage-html:
21 69 -$(MAKE) -C tests $(AM_MAKEFLAGS) -k $@
22 70 endif
  71 +
  72 +install-data-hook:
  73 + mkdir -p $(varlibdir)/assets/doc $(varlibdir)/assets/html/doc $(varrundir)
  74 + $(LN_S) -f $(trdatadir)/docs/api/$(PACKAGE_VERSION)/html $(varlibdir)/assets/doc/$(PACKAGE_VERSION)
  75 + $(LN_S) -f $(trdatadir)/docs/api/$(PACKAGE_VERSION)/html $(varlibdir)/assets/html/doc/$(PACKAGE_VERSION)
... ...
... ... @@ -62,6 +62,24 @@ AC_TYPE_SIZE_T
62 62 #AC_FUNC_MALLOC
63 63 AC_CHECK_FUNCS([memset])
64 64
  65 +myetcdir=${sysconfdir}/taskrambler
  66 +varlibdir=${localstatedir}/lib/taskrambler
  67 +varrundir=${localstatedir}/run/taskrambler
  68 +trdatadir=${datadir}/taskrambler
  69 +AC_SUBST(myetcdir)
  70 +AC_SUBST(varlibdir)
  71 +AC_SUBST(varrundir)
  72 +AC_SUBST(trdatadir)
  73 +
  74 +AM_CFLAGS="${AM_CFLAGS} ${DRAGONEGG_FLAGS}"
  75 +AM_CFLAGS="${AM_CFLAGS} ${MEM_OPT_FLAGS}"
  76 +AM_CFLAGS="${AM_CFLAGS} -DPWD=\\\"${PWD}\\\""
  77 +AM_CFLAGS="${AM_CFLAGS} -DCONFIGDIR=\\\"${myetcdir}\\\""
  78 +AM_CFLAGS="${AM_CFLAGS} ${CFLAGS}"
  79 +AC_SUBST(AM_CFLAGS)
  80 +
  81 +AC_CONFIG_FILES([config/taskrambler.conf])
  82 +
65 83 AC_CONFIG_FILES([Makefile
66 84 src/Makefile
67 85 src/asset/Makefile
... ... @@ -80,6 +98,7 @@ AC_CONFIG_FILES([Makefile
80 98 src/application/Makefile
81 99 src/storage/Makefile
82 100 src/user/Makefile
  101 + src/config/Makefile
83 102 docs/Makefile
84 103 tests/Makefile])
85 104 AC_OUTPUT
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#ifndef __CONFIG_H__
  24 +#define __CONFIG_H__
  25 +
  26 +#include "hash.h"
  27 +#include "class.h"
  28 +#include "config/value.h"
  29 +
  30 +#define MAX_CONFIG_LINE 256
  31 +
  32 +
  33 +CLASS(Config) {
  34 + char * cnf_file;
  35 + Hash config;
  36 +};
  37 +
  38 +ConfigValue configGet(Config, const char *, size_t);
  39 +
  40 +#endif // __CONFIG_H__
  41 +
  42 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#ifndef __CONFIG_VALUE_H__
  24 +#define __CONFIG_VALUE_H__
  25 +
  26 +#include <sys/types.h>
  27 +
  28 +#include "hash.h"
  29 +#include "class.h"
  30 +
  31 +#define MAX_CONFIG_LINE 256
  32 +
  33 +#define CONFSTRA(val) ((val)->value).string, (val)->nvalue
  34 +
  35 +
  36 +typedef enum e_ConfigValueType {
  37 + CONFIG_VALUE_NUMERIC = 0,
  38 + CONFIG_VALUE_STRING = 1
  39 +} ConfigValueType;
  40 +
  41 +CLASS(ConfigValue) {
  42 + union {
  43 + char * string;
  44 + long long number;
  45 + } value;
  46 +
  47 + size_t nvalue;
  48 + ConfigValueType type;
  49 +
  50 + unsigned long hash;
  51 +};
  52 +
  53 +#endif // __CONFIG_VALUE_H__
  54 +
  55 +// vim: set ts=4 sw=4:
... ...
... ... @@ -26,23 +26,18 @@ LIBS = ./application/libapplication.a \
26 26 ./session/libsession.a \
27 27 ./socket/libsocket.a \
28 28 ./stream/libstream.a \
29   - ./tree/libtree.a
  29 + ./tree/libtree.a \
  30 + ./config/libconfig.a
30 31
31   -AM_CFLAGS = -Wall -I ../include/
  32 +AM_CFLAGS += -I../include/
32 33
33 34 bin_PROGRAMS = taskrambler
34 35
35   -
36 36 taskrambler_SOURCES = taskrambler.c $(IFACE) $(UTILS)
37   -taskrambler_CFLAGS = $(CFLAGS) \
38   - $(DRAGONEGG_FLAGS) \
39   - -Wall \
40   - -DPWD=\"$(PWD)\" \
41   - $(MEM_OPT_FLAGS) \
42   - -I../include/ # $(COVERAGE_CFLAGS)
  37 +taskrambler_CFLAGS = $(AM_CFLAGS)
43 38 taskrambler_LDADD = $(LIBS) -lrt -lssl -lldap -lgdbm -luuid
44 39 #taskrambler_LDFLAGS = $(COVERAGE_LDFLAGS)
45 40
46 41 SUBDIRS = asset auth cbuf class hash queue http \
47 42 logger server session socket stream tree application \
48   - storage user
  43 + storage user config
... ...
... ... @@ -12,7 +12,9 @@ APPLICATION = application.c \
12 12 ADAPTERHTTP = adapter/http/http.c \
13 13 adapter/http/update.c
14 14
  15 +AM_CFLAGS += -I../../include/
  16 +
15 17 noinst_LIBRARIES = libapplication.a
16 18
17 19 libapplication_a_SOURCES = $(APPLICATION) $(ADAPTERHTTP)
18   -libapplication_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../ -I ../../include/
  20 +libapplication_a_CFLAGS = $(AM_CFLAGS)
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = libasset.a
5 7
6 8 libasset_a_SOURCES = asset.c pool.c
7   -libasset_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  9 +libasset_a_CFLAGS = $(AM_CFLAGS)
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = libauth.a
5 7
6 8 libauth_a_SOURCES = interface/auth.c \
... ... @@ -8,4 +10,4 @@ libauth_a_SOURCES = interface/auth.c \
8 10 ldap.c \
9 11 storage/storage.c \
10 12 storage/hash_pw.c
11   -libauth_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  13 +libauth_a_CFLAGS = $(AM_CFLAGS)
... ...
... ... @@ -8,7 +8,9 @@ CB = cbuf.c read.c \
8 8 skip_non_alpha.c is_locked.c lock.c release.c \
9 9 empty.c
10 10
  11 +AM_CFLAGS += -I../../include/
  12 +
11 13 noinst_LIBRARIES = libcbuf.a
12 14
13 15 libcbuf_a_SOURCES = $(CB)
14   -libcbuf_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  16 +libcbuf_a_CFLAGS = $(AM_CFLAGS)
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = libclass.a
5 7
6 8 libclass_a_SOURCES = interface.c interface/i_class.c
7   -libclass_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  9 +libclass_a_CFLAGS = $(AM_CFLAGS)
... ...
  1 +ACLOCAL_AMFLAGS = -I m4
  2 +AUTOMAKE_OPTIONS = subdir-objects
  3 +
  4 +CONFIG = config.c value.c get.c
  5 +
  6 +AM_CFLAGS += -I../../include/
  7 +
  8 +noinst_LIBRARIES = libconfig.a
  9 +
  10 +libconfig_a_SOURCES = $(CONFIG)
  11 +libconfig_a_CFLAGS = $(AM_CFLAGS)
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <stdarg.h>
  24 +#include <string.h>
  25 +#include <stdio.h>
  26 +#include <ctype.h>
  27 +#include <sys/types.h>
  28 +
  29 +#include "class.h"
  30 +#include "config/config.h"
  31 +#include "config/value.h"
  32 +#include "utils/memory.h"
  33 +
  34 +static
  35 +int
  36 +configCtor(void * _this, va_list * params)
  37 +{
  38 + Config this = _this;
  39 +
  40 + FILE * handle;
  41 + char line[MAX_CONFIG_LINE];
  42 + char * cnf_file = va_arg(*params, char *);
  43 + size_t ncnf_file = strlen(cnf_file);
  44 +
  45 + this->cnf_file = memMalloc(ncnf_file + 1);
  46 + memcpy(this->cnf_file, cnf_file, ncnf_file);
  47 + this->cnf_file[ncnf_file] = '\0';
  48 +
  49 + handle = fopen(this->cnf_file, "r");
  50 + if (NULL == handle) {
  51 + MEM_FREE(this->cnf_file);
  52 + return -1;
  53 + }
  54 +
  55 + this->config = new(Hash);
  56 +
  57 + line[MAX_CONFIG_LINE] = '\0';
  58 +
  59 + while(NULL != fgets(line, MAX_CONFIG_LINE, handle)) {
  60 + char * key = line;
  61 + size_t nkey = 0;
  62 + size_t nvalue = 0;
  63 + size_t nspaces = 0;
  64 + char * value;
  65 +
  66 + while (isspace(*key)) {
  67 + key++;
  68 + }
  69 +
  70 + if ('#' == *key) {
  71 + continue;
  72 + }
  73 +
  74 + while (! isspace(key[nkey])) {
  75 + nkey++;
  76 + }
  77 +
  78 + value = &(key[nkey+1]);
  79 + while (isspace(*value)) {
  80 + value++;
  81 + }
  82 +
  83 + while ('\0' != value[nvalue+nspaces]
  84 + && '\n' != value[nvalue+nspaces])
  85 + {
  86 + if (isspace(value[nvalue+nspaces])) {
  87 + nspaces++;
  88 + } else {
  89 + if (0 != nspaces) {
  90 + nvalue += nspaces;
  91 + nspaces = 0;
  92 + }
  93 + nvalue++;
  94 + }
  95 + }
  96 +
  97 + value[nvalue] = '\0';
  98 +
  99 + if (0 != nkey && 0 != nvalue) {
  100 + hashAdd(
  101 + this->config,
  102 + new(ConfigValue, key, nkey, value, nvalue));
  103 + }
  104 + }
  105 +
  106 + fclose(handle);
  107 +
  108 + return 0;
  109 +}
  110 +
  111 +static void configDtor(void * _this)
  112 +{
  113 + Config this = _this;
  114 +
  115 + MEM_FREE(this->cnf_file);
  116 + delete(this->config);
  117 +}
  118 +
  119 +INIT_IFACE(Class, configCtor, configDtor, NULL);
  120 +CREATE_CLASS(Config, NULL, IFACE(Class));
  121 +
  122 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <sys/types.h>
  24 +
  25 +#include "class.h"
  26 +#include "hash/hash.h"
  27 +#include "config/config.h"
  28 +#include "config/value.h"
  29 +
  30 +ConfigValue
  31 +configGet(Config this, const char * key, size_t nkey)
  32 +{
  33 + return hashGet(this->config, key, nkey);
  34 +}
  35 +
  36 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <stdarg.h>
  24 +#include <stdlib.h>
  25 +#include <string.h>
  26 +#include <sys/types.h>
  27 +
  28 +#include "class.h"
  29 +#include "config/value.h"
  30 +#include "utils/memory.h"
  31 +#include "utils/hash.h"
  32 +
  33 +static
  34 +int
  35 +configValueCtor(void * _this, va_list * params)
  36 +{
  37 + ConfigValue this = _this;
  38 +
  39 + char * key = va_arg(*params, char *);
  40 + size_t nkey = va_arg(*params, size_t);
  41 + char * value = va_arg(*params, char *);
  42 + size_t nvalue = va_arg(*params, size_t);
  43 +
  44 + this->hash = sdbm((unsigned char *)key, nkey);
  45 +
  46 + /**
  47 + * if we find the value enclosed by single or double
  48 + * quotes we take it as a string, else we take it
  49 + * as a numeric which is treated as a long long
  50 + * right now.
  51 + */
  52 + if (('"' == value[0] && '"' == value[nvalue-1])
  53 + || ('\'' == value[0] && '\'' == value[nvalue-1]))
  54 + {
  55 + this->type = CONFIG_VALUE_STRING;
  56 + (this->value).string = memMalloc(nvalue-1);
  57 + (this->value).string[nvalue-1] = '\0';
  58 + memcpy((this->value).string, value+1, nvalue-2);
  59 + this->nvalue = nvalue;
  60 + } else {
  61 + this->type = CONFIG_VALUE_NUMERIC;
  62 + (this->value).number = atoll(value);
  63 + this->nvalue = sizeof(long long);
  64 + }
  65 +
  66 + return 0;
  67 +}
  68 +
  69 +static
  70 +void
  71 +configValueDtor(void * _this)
  72 +{
  73 + ConfigValue this = _this;
  74 +
  75 + if (CONFIG_VALUE_STRING == this->type) {
  76 + MEM_FREE((this->value).string);
  77 + }
  78 +}
  79 +
  80 +static
  81 +unsigned long
  82 +configValueGetHash(void * _this)
  83 +{
  84 + ConfigValue this = _this;
  85 +
  86 + return this->hash;
  87 +}
  88 +
  89 +static
  90 +void
  91 +configValueHandleDouble(void * _this, void * _double)
  92 +{
  93 + /* right now I do nothing...but I could :D */
  94 +}
  95 +
  96 +INIT_IFACE(Class, configValueCtor, configValueDtor, NULL);
  97 +INIT_IFACE(Hashable, configValueGetHash, configValueHandleDouble);
  98 +CREATE_CLASS(ConfigValue, NULL, IFACE(Class), IFACE(Hashable));
  99 +
  100 +// vim: set ts=4 sw=4:
... ...
  1 +#include <stdio.h>
  2 +
  3 +#include "class.h"
  4 +#include "commons.h"
  5 +#include "config/config.h"
  6 +#include "config/value.h"
  7 +#include "utils/memory.h"
  8 +
  9 +int
  10 +main(int argc, char * argv[])
  11 +{
  12 + Config config = new(Config, "./testconfig.cfg");
  13 + ConfigValue val;
  14 +
  15 + val = configGet(config, CSTRA("dummy"));
  16 +
  17 + if (NULL != val) {
  18 + switch (val->type) {
  19 + case CONFIG_VALUE_STRING:
  20 + printf(
  21 + "Value for dummy: (STRING): %s\n",
  22 + (val->value).string);
  23 + break;
  24 +
  25 + case CONFIG_VALUE_NUMERIC:
  26 + printf(
  27 + "Value for dummy: (NUMERIC): %lld\n",
  28 + (val->value).number);
  29 + break;
  30 +
  31 + default:
  32 + printf("Invalid config...that should never happen\n");
  33 + }
  34 + }
  35 +
  36 + delete(config);
  37 + memCleanup();
  38 +
  39 + return 0;
  40 +}
  41 +
  42 +// vim: set et ts=4 sw=4:
... ...
... ... @@ -4,7 +4,9 @@ AUTOMAKE_OPTIONS = subdir-objects
4 4 HASH = hash.c add.c get.c get_first.c delete.c each.c value.c \
5 5 cleanup.c interface/hashable.c
6 6
  7 +AM_CFLAGS += -I../../include/
  8 +
7 9 noinst_LIBRARIES = libhash.a
8 10
9 11 libhash_a_SOURCES = $(HASH)
10   -libhash_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  12 +libhash_a_CFLAGS = $(AM_CFLAGS)
... ...
... ... @@ -38,8 +38,10 @@ WORKER = worker.c \
38 38 HEADER = header.c \
39 39 header/to_string.c
40 40
  41 +AM_CFLAGS += -I../../include/
  42 +
41 43 noinst_LIBRARIES = libhttp.a
42 44
43 45 libhttp_a_SOURCES = $(MSG) $(REQ) $(RESP) $(PARSER) $(WRITER) \
44 46 $(WORKER) $(HEADER) interface/i_http_intro.c
45   -libhttp_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../ -I ../../include/
  47 +libhttp_a_CFLAGS = $(AM_CFLAGS)
... ...
... ... @@ -40,6 +40,8 @@
40 40 #include "http/request.h"
41 41 #include "http/response.h"
42 42 #include "http/parser.h"
  43 +#include "config/config.h"
  44 +#include "config/value.h"
43 45
44 46 #include "interface/subject.h"
45 47
... ... @@ -52,6 +54,7 @@ HttpMessage httpWorkerGetAsset(HttpWorker, const char *);
52 54 void httpWorkerAddCommonHeader(HttpWorker);
53 55 void httpWorkerAddComputedHeader(HttpWorker);
54 56
  57 +extern Config config;
55 58
56 59 ssize_t
57 60 httpWorkerProcess(HttpWorker this, Stream st)
... ... @@ -82,14 +85,20 @@ httpWorkerProcess(HttpWorker this, Stream st)
82 85 }
83 86
84 87 if (0 == strcmp("GET", this->current_request->method)) {
85   - char html_asset[2048] = "./assets/html";
86   - char base_asset[2048] = "./assets";
87   - char main_asset[] = "/main.html";
  88 + ConfigValue assets_dir =
  89 + configGet(config, CSTRA("assets_dir"));
  90 +
  91 + char asset_path[2048];
  92 +
  93 + char html_asset[] = "/assets/html";
  94 + char base_asset[] = "/assets";
  95 + char main_asset[] = "/main.html";
88 96
89   - char * asset_path = base_asset;
90 97 char * asset;
91 98 char * mime_type;
92 99
  100 + strcpy(asset_path, (assets_dir->value).string);
  101 +
93 102 if (0 == strcmp("/", this->current_request->path)) {
94 103 asset = main_asset;
95 104 } else {
... ... @@ -104,7 +113,9 @@ httpWorkerProcess(HttpWorker this, Stream st)
104 113
105 114 if (NULL != mime_type &&
106 115 0 == memcmp(mime_type, CSTRA("text/html"))) {
107   - asset_path = html_asset;
  116 + strcat(asset_path, html_asset);
  117 + } else {
  118 + strcat(asset_path, base_asset);
108 119 }
109 120
110 121 strcat(asset_path, asset);
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = liblogger.a
5 7
6 8 liblogger_a_SOURCES = interface/i_logger.c logger.c stderr.c syslog.c
7   -liblogger_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  9 +liblogger_a_CFLAGS = $(AM_CFLAGS)
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = libqueue.a
5 7
6 8 libqueue_a_SOURCES = queue.c get.c put.c
7   -libqueue_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  9 +libqueue_a_CFLAGS = $(AM_CFLAGS)
... ...
... ... @@ -4,7 +4,9 @@ AUTOMAKE_OPTIONS = subdir-objects
4 4 SERVER = server.c run.c close_conn.c poll.c \
5 5 handle_accept.c read.c write.c
6 6
  7 +AM_CFLAGS += -I../../include/
  8 +
7 9 noinst_LIBRARIES = libserver.a
8 10
9 11 libserver_a_SOURCES = $(SERVER)
10   -libserver_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  12 +libserver_a_CFLAGS = $(AM_CFLAGS)
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = libsession.a
5 7
6 8 libsession_a_SOURCES = session.c
7   -libsession_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  9 +libsession_a_CFLAGS = $(AM_CFLAGS)
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = libsocket.a
5 7
6 8 libsocket_a_SOURCES = socket.c accept.c connect.c listen.c nonblock.c
7   -libsocket_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  9 +libsocket_a_CFLAGS = $(AM_CFLAGS)
... ...
... ... @@ -32,7 +32,8 @@ void
32 32 socketListen(Sock this, int backlog)
33 33 {
34 34 (this->addr).sin_family = AF_INET; // Internet address family
35   - (this->addr).sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface
  35 + //(this->addr).sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface
  36 + (this->addr).sin_addr.s_addr = inet_addr("127.0.0.1"); // Any incoming interface
36 37 (this->addr).sin_port = htons(this->port); // Local port
37 38
38 39 /**
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = libstorage.a
5 7
6 8 libstorage_a_SOURCES = storage.c get.c put.c update.c
7   -libstorage_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  9 +libstorage_a_CFLAGS = $(AM_CFLAGS)
... ...
... ... @@ -5,7 +5,9 @@ STREAM = stream.c read.c write.c
5 5 IFACE = interface/reader.c \
6 6 interface/writer.c
7 7
  8 +AM_CFLAGS += -I../../include/
  9 +
8 10 noinst_LIBRARIES = libstream.a
9 11
10 12 libstream_a_SOURCES = $(STREAM) $(IFACE)
11   -libstream_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  13 +libstream_a_CFLAGS = $(AM_CFLAGS)
... ...
... ... @@ -42,6 +42,8 @@
42 42 #include "application/application.h"
43 43 #include "application/adapter/http.h"
44 44 #include "interface/subject.h"
  45 +#include "config/config.h"
  46 +#include "config/value.h"
45 47
46 48 #include "class.h"
47 49 #include "logger.h"
... ... @@ -55,14 +57,13 @@
55 57 //#define DEFAULT_SECS 1
56 58 #define DEFAULT_USECS 0
57 59
58   -#define LDAP_BASE "ou=user,dc=yabrog,dc=weird-web-workers,dc=org"
59   -
60 60
61 61 void nullhandler() {}
62 62
63 63 void daemonize(void);
64 64
65 65 Logger logger;
  66 +Config config;
66 67
67 68 int
68 69 main()
... ... @@ -73,6 +74,8 @@ main()
73 74 int shm;
74 75 struct randval * value;
75 76
  77 + config = new(Config, CONFIGDIR "/taskrambler.conf");
  78 +
76 79 struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY};
77 80 setrlimit(RLIMIT_CPU, &limit);
78 81
... ... @@ -149,6 +152,23 @@ main()
149 152 HttpWorker worker;
150 153 Server server;
151 154
  155 + ConfigValue ldap_base =
  156 + configGet(config, CSTRA("ldap_base"));
  157 + ConfigValue ldap_host =
  158 + configGet(config, CSTRA("ldap_host"));
  159 + ConfigValue runtime_dir =
  160 + configGet(config, CSTRA("runtime_dir"));
  161 + ConfigValue port =
  162 + configGet(config, CSTRA("port"));
  163 +
  164 + char user_storage[512];
  165 + char password_storage[512];
  166 +
  167 + strcpy(user_storage, (runtime_dir->value).string);
  168 + strcpy(password_storage, (runtime_dir->value).string);
  169 + strcat(user_storage, "/users.db");
  170 + strcat(password_storage, "/passwords.db");
  171 +
152 172 value = mmap (0, sizeof(int), PROT_READ|PROT_WRITE,
153 173 MAP_SHARED, shm, 0);
154 174
... ... @@ -159,11 +179,11 @@ main()
159 179
160 180 authLdap = new(
161 181 AuthLdap,
162   - "ldap://hosted/",
163   - CSTRA(LDAP_BASE));
  182 + (ldap_host->value).string,
  183 + CONFSTRA(ldap_base));
164 184
165   - users = new(Storage, "./run/users.db");
166   - passwords = new(Storage, "./run/passwords.db");
  185 + users = new(Storage, user_storage);
  186 + passwords = new(Storage, password_storage);
167 187 authStorage = new(AuthStorage, passwords);
168 188
169 189 application = new(
... ... @@ -177,10 +197,15 @@ main()
177 197
178 198 adapterHttp = new(ApplicationAdapterHttp, application);
179 199
180   - worker = new(HttpWorker, "testserver");
  200 + worker = new(HttpWorker, "taskrambler");
181 201 subjectAttach(worker, adapterHttp);
182 202
183   - server = new(Server, logger, worker, 11212, SOMAXCONN);
  203 + server = new(
  204 + Server,
  205 + logger,
  206 + worker,
  207 + (int)(port->value).number,
  208 + SOMAXCONN);
184 209
185 210 if (NULL != server) {
186 211 serverRun(server);
... ... @@ -236,12 +261,14 @@ main()
236 261
237 262 clearMimeTypes();
238 263 assetPoolCleanup();
239   - memCleanup();
240 264 }
241 265
242 266 break;
243 267 }
244 268
  269 + delete(config);
  270 + memCleanup();
  271 +
245 272 return 0;
246 273 }
247 274
... ...
  1 +##
  2 +# basic configuration file for taskrambler
  3 +#
  4 +# syntax: <ws><key><ws><value><ws>
  5 +#
  6 +# <ws> ::= any whitespace as defined by isspace
  7 +# <key> ::= any character except whitespace
  8 +# <value> ::= <string> | <number>
  9 +# <string> ::= <quote>any character<quote>
  10 +# <quote> ::= " | '
  11 +# <number> ::= <digit><number>
  12 +# <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
  13 +#
  14 +# Whitespaces at the beginning or the end of a line are
  15 +# ignored.
  16 +# everything after a # is ignored.
  17 +#
  18 +
  19 +ldap_base "ou=user,dc=yabrog,dc=weird-web-workers,dc=org"
  20 +ldap_host "ldap://hosted/"
  21 +assets_dir "/usr/local/var/lib/taskrambler"
  22 +runtime_dir "/usr/local/var/run/taskrambler"
  23 +port 11212
... ...
... ... @@ -4,7 +4,9 @@ AUTOMAKE_OPTIONS = subdir-objects
4 4 TREE = tree.c find.c insert.c inOrderSuccessor.c delete.c walk.c \
5 5 rotateLeft.c rotateRight.c destroy.c
6 6
  7 +AM_CFLAGS += -I../../include/
  8 +
7 9 noinst_LIBRARIES = libtree.a
8 10
9 11 libtree_a_SOURCES = $(TREE)
10   -libtree_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  12 +libtree_a_CFLAGS = $(AM_CFLAGS)
... ...
1 1 ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
  4 +AM_CFLAGS += -I../../include/
  5 +
4 6 noinst_LIBRARIES = libuser.a
5 7
6 8 libuser_a_SOURCES = user.c load.c save.c
7   -libuser_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
  9 +libuser_a_CFLAGS = $(AM_CFLAGS)
... ...
... ... @@ -57,10 +57,10 @@ void daemonize(void) {
57 57
58 58 // set umask and change to working directory to /
59 59 umask(UMASK);
60   - if (-1 == chdir(PWD)) { // this should root and assets needs to be found
61   - perror("daemonize"); // via some kind of configuration.
  60 + if (-1 == chdir("/")) {
  61 + perror("daemonize");
62 62 exit(EXIT_FAILURE);
63   - }
  63 + }
64 64
65 65 // we should close all open filedescriptors now.
66 66 // But I assume that this function is called at the very start of the
... ... @@ -72,3 +72,5 @@ void daemonize(void) {
72 72 stdin = freopen("/dev/null", "r", stdin);
73 73 stdout = freopen("/dev/null", "w", stdout);
74 74 }
  75 +
  76 +// vim: set ts=4 sw=4:
... ...
... ... @@ -38,8 +38,8 @@ Hash mime_types = NULL;
38 38 void
39 39 readMimeTypes(void)
40 40 {
41   - if (0 == access("./config/mime.types", O_RDONLY)) {
42   - FILE * handle = fopen("./config/mime.types", "r");
  41 + if (0 == access(CONFIGDIR "/mime.types", O_RDONLY)) {
  42 + FILE * handle = fopen(CONFIGDIR "/mime.types", "r");
43 43
44 44 if (NULL != handle) {
45 45 char buffer[512];
... ...
Please register or login to post a comment