Browse Source

make install works now. So from now on taskrambler will not work when run from its build dir, because it can't find its assets then. To make installation work a basic config file reader class was implemented.

0.1.7
Georg Hopp 12 years ago
parent
commit
7005c8860a
  1. 55
      Makefile.am
  2. 19
      configure.ac
  3. 42
      include/config/config.h
  4. 55
      include/config/value.h
  5. 15
      src/Makefile.am
  6. 4
      src/application/Makefile.am
  7. 4
      src/asset/Makefile.am
  8. 4
      src/auth/Makefile.am
  9. 4
      src/cbuf/Makefile.am
  10. 4
      src/class/Makefile.am
  11. 11
      src/config/Makefile.am
  12. 122
      src/config/config.c
  13. 36
      src/config/get.c
  14. 100
      src/config/value.c
  15. 42
      src/configtest.c
  16. 4
      src/hash/Makefile.am
  17. 4
      src/http/Makefile.am
  18. 21
      src/http/worker/process.c
  19. 4
      src/logger/Makefile.am
  20. 4
      src/queue/Makefile.am
  21. 4
      src/server/Makefile.am
  22. 4
      src/session/Makefile.am
  23. 4
      src/socket/Makefile.am
  24. 3
      src/socket/listen.c
  25. 4
      src/storage/Makefile.am
  26. 4
      src/stream/Makefile.am
  27. 45
      src/taskrambler.c
  28. 23
      src/testconfig.cfg
  29. 4
      src/tree/Makefile.am
  30. 4
      src/user/Makefile.am
  31. 8
      src/utils/daemonize.c
  32. 4
      src/utils/mime_type.c

55
Makefile.am

@ -5,7 +5,55 @@ ACLOCAL_AMFLAGS = -I m4
#create_token_LDADD = src/libtoken.la $(LIBOBJS) #create_token_LDADD = src/libtoken.la $(LIBOBJS)
#create_token_CFLAGS = -Wall -I include #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 SUBDIRS = src tests docs
@ -20,3 +68,8 @@ if HAVE_GCOV
coverage-html: coverage-html:
-$(MAKE) -C tests $(AM_MAKEFLAGS) -k $@ -$(MAKE) -C tests $(AM_MAKEFLAGS) -k $@
endif 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)

19
configure.ac

@ -62,6 +62,24 @@ AC_TYPE_SIZE_T
#AC_FUNC_MALLOC #AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset]) 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 AC_CONFIG_FILES([Makefile
src/Makefile src/Makefile
src/asset/Makefile src/asset/Makefile
@ -80,6 +98,7 @@ AC_CONFIG_FILES([Makefile
src/application/Makefile src/application/Makefile
src/storage/Makefile src/storage/Makefile
src/user/Makefile src/user/Makefile
src/config/Makefile
docs/Makefile docs/Makefile
tests/Makefile]) tests/Makefile])
AC_OUTPUT AC_OUTPUT

42
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 <http://www.gnu.org/licenses/>.
*/
#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:

55
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 <http://www.gnu.org/licenses/>.
*/
#ifndef __CONFIG_VALUE_H__
#define __CONFIG_VALUE_H__
#include <sys/types.h>
#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:

15
src/Makefile.am

@ -26,23 +26,18 @@ LIBS = ./application/libapplication.a \
./session/libsession.a \ ./session/libsession.a \
./socket/libsocket.a \ ./socket/libsocket.a \
./stream/libstream.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 bin_PROGRAMS = taskrambler
taskrambler_SOURCES = taskrambler.c $(IFACE) $(UTILS) 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_LDADD = $(LIBS) -lrt -lssl -lldap -lgdbm -luuid
#taskrambler_LDFLAGS = $(COVERAGE_LDFLAGS) #taskrambler_LDFLAGS = $(COVERAGE_LDFLAGS)
SUBDIRS = asset auth cbuf class hash queue http \ SUBDIRS = asset auth cbuf class hash queue http \
logger server session socket stream tree application \ logger server session socket stream tree application \
storage user
storage user config

4
src/application/Makefile.am

@ -12,7 +12,9 @@ APPLICATION = application.c \
ADAPTERHTTP = adapter/http/http.c \ ADAPTERHTTP = adapter/http/http.c \
adapter/http/update.c adapter/http/update.c
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libapplication.a noinst_LIBRARIES = libapplication.a
libapplication_a_SOURCES = $(APPLICATION) $(ADAPTERHTTP) libapplication_a_SOURCES = $(APPLICATION) $(ADAPTERHTTP)
libapplication_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../ -I ../../include/
libapplication_a_CFLAGS = $(AM_CFLAGS)

4
src/asset/Makefile.am

@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libasset.a noinst_LIBRARIES = libasset.a
libasset_a_SOURCES = asset.c pool.c libasset_a_SOURCES = asset.c pool.c
libasset_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libasset_a_CFLAGS = $(AM_CFLAGS)

4
src/auth/Makefile.am

@ -1,6 +1,8 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libauth.a noinst_LIBRARIES = libauth.a
libauth_a_SOURCES = interface/auth.c \ libauth_a_SOURCES = interface/auth.c \
@ -8,4 +10,4 @@ libauth_a_SOURCES = interface/auth.c \
ldap.c \ ldap.c \
storage/storage.c \ storage/storage.c \
storage/hash_pw.c storage/hash_pw.c
libauth_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libauth_a_CFLAGS = $(AM_CFLAGS)

4
src/cbuf/Makefile.am

@ -8,7 +8,9 @@ CB = cbuf.c read.c \
skip_non_alpha.c is_locked.c lock.c release.c \ skip_non_alpha.c is_locked.c lock.c release.c \
empty.c empty.c
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libcbuf.a noinst_LIBRARIES = libcbuf.a
libcbuf_a_SOURCES = $(CB) libcbuf_a_SOURCES = $(CB)
libcbuf_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libcbuf_a_CFLAGS = $(AM_CFLAGS)

4
src/class/Makefile.am

@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libclass.a noinst_LIBRARIES = libclass.a
libclass_a_SOURCES = interface.c interface/i_class.c libclass_a_SOURCES = interface.c interface/i_class.c
libclass_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libclass_a_CFLAGS = $(AM_CFLAGS)

11
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)

122
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 <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#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:

36
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 <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#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:

100
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 <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#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:

42
src/configtest.c

@ -0,0 +1,42 @@
#include <stdio.h>
#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:

4
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 \ HASH = hash.c add.c get.c get_first.c delete.c each.c value.c \
cleanup.c interface/hashable.c cleanup.c interface/hashable.c
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libhash.a noinst_LIBRARIES = libhash.a
libhash_a_SOURCES = $(HASH) libhash_a_SOURCES = $(HASH)
libhash_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libhash_a_CFLAGS = $(AM_CFLAGS)

4
src/http/Makefile.am

@ -38,8 +38,10 @@ WORKER = worker.c \
HEADER = header.c \ HEADER = header.c \
header/to_string.c header/to_string.c
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libhttp.a noinst_LIBRARIES = libhttp.a
libhttp_a_SOURCES = $(MSG) $(REQ) $(RESP) $(PARSER) $(WRITER) \ libhttp_a_SOURCES = $(MSG) $(REQ) $(RESP) $(PARSER) $(WRITER) \
$(WORKER) $(HEADER) interface/i_http_intro.c $(WORKER) $(HEADER) interface/i_http_intro.c
libhttp_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../ -I ../../include/
libhttp_a_CFLAGS = $(AM_CFLAGS)

21
src/http/worker/process.c

@ -40,6 +40,8 @@
#include "http/request.h" #include "http/request.h"
#include "http/response.h" #include "http/response.h"
#include "http/parser.h" #include "http/parser.h"
#include "config/config.h"
#include "config/value.h"
#include "interface/subject.h" #include "interface/subject.h"
@ -52,6 +54,7 @@ HttpMessage httpWorkerGetAsset(HttpWorker, const char *);
void httpWorkerAddCommonHeader(HttpWorker); void httpWorkerAddCommonHeader(HttpWorker);
void httpWorkerAddComputedHeader(HttpWorker); void httpWorkerAddComputedHeader(HttpWorker);
extern Config config;
ssize_t ssize_t
httpWorkerProcess(HttpWorker this, Stream st) httpWorkerProcess(HttpWorker this, Stream st)
@ -82,14 +85,20 @@ httpWorkerProcess(HttpWorker this, Stream st)
} }
if (0 == strcmp("GET", this->current_request->method)) { 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 * asset;
char * mime_type; char * mime_type;
strcpy(asset_path, (assets_dir->value).string);
if (0 == strcmp("/", this->current_request->path)) { if (0 == strcmp("/", this->current_request->path)) {
asset = main_asset; asset = main_asset;
} else { } else {
@ -104,7 +113,9 @@ httpWorkerProcess(HttpWorker this, Stream st)
if (NULL != mime_type && if (NULL != mime_type &&
0 == memcmp(mime_type, CSTRA("text/html"))) { 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); strcat(asset_path, asset);

4
src/logger/Makefile.am

@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = liblogger.a noinst_LIBRARIES = liblogger.a
liblogger_a_SOURCES = interface/i_logger.c logger.c stderr.c syslog.c 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)

4
src/queue/Makefile.am

@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libqueue.a noinst_LIBRARIES = libqueue.a
libqueue_a_SOURCES = queue.c get.c put.c libqueue_a_SOURCES = queue.c get.c put.c
libqueue_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libqueue_a_CFLAGS = $(AM_CFLAGS)

4
src/server/Makefile.am

@ -4,7 +4,9 @@ AUTOMAKE_OPTIONS = subdir-objects
SERVER = server.c run.c close_conn.c poll.c \ SERVER = server.c run.c close_conn.c poll.c \
handle_accept.c read.c write.c handle_accept.c read.c write.c
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libserver.a noinst_LIBRARIES = libserver.a
libserver_a_SOURCES = $(SERVER) libserver_a_SOURCES = $(SERVER)
libserver_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libserver_a_CFLAGS = $(AM_CFLAGS)

4
src/session/Makefile.am

@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libsession.a noinst_LIBRARIES = libsession.a
libsession_a_SOURCES = session.c libsession_a_SOURCES = session.c
libsession_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libsession_a_CFLAGS = $(AM_CFLAGS)

4
src/socket/Makefile.am

@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libsocket.a noinst_LIBRARIES = libsocket.a
libsocket_a_SOURCES = socket.c accept.c connect.c listen.c nonblock.c 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)

3
src/socket/listen.c

@ -32,7 +32,8 @@ void
socketListen(Sock this, int backlog) socketListen(Sock this, int backlog)
{ {
(this->addr).sin_family = AF_INET; // Internet address family (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 (this->addr).sin_port = htons(this->port); // Local port
/** /**

4
src/storage/Makefile.am

@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libstorage.a noinst_LIBRARIES = libstorage.a
libstorage_a_SOURCES = storage.c get.c put.c update.c 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)

4
src/stream/Makefile.am

@ -5,7 +5,9 @@ STREAM = stream.c read.c write.c
IFACE = interface/reader.c \ IFACE = interface/reader.c \
interface/writer.c interface/writer.c
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libstream.a noinst_LIBRARIES = libstream.a
libstream_a_SOURCES = $(STREAM) $(IFACE) libstream_a_SOURCES = $(STREAM) $(IFACE)
libstream_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libstream_a_CFLAGS = $(AM_CFLAGS)

45
src/taskrambler.c

@ -42,6 +42,8 @@
#include "application/application.h" #include "application/application.h"
#include "application/adapter/http.h" #include "application/adapter/http.h"
#include "interface/subject.h" #include "interface/subject.h"
#include "config/config.h"
#include "config/value.h"
#include "class.h" #include "class.h"
#include "logger.h" #include "logger.h"
@ -55,14 +57,13 @@
//#define DEFAULT_SECS 1 //#define DEFAULT_SECS 1
#define DEFAULT_USECS 0 #define DEFAULT_USECS 0
#define LDAP_BASE "ou=user,dc=yabrog,dc=weird-web-workers,dc=org"
void nullhandler() {} void nullhandler() {}
void daemonize(void); void daemonize(void);
Logger logger; Logger logger;
Config config;
int int
main() main()
@ -73,6 +74,8 @@ main()
int shm; int shm;
struct randval * value; struct randval * value;
config = new(Config, CONFIGDIR "/taskrambler.conf");
struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY}; struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY};
setrlimit(RLIMIT_CPU, &limit); setrlimit(RLIMIT_CPU, &limit);
@ -149,6 +152,23 @@ main()
HttpWorker worker; HttpWorker worker;
Server server; 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, value = mmap (0, sizeof(int), PROT_READ|PROT_WRITE,
MAP_SHARED, shm, 0); MAP_SHARED, shm, 0);
@ -159,11 +179,11 @@ main()
authLdap = new( authLdap = new(
AuthLdap, 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); authStorage = new(AuthStorage, passwords);
application = new( application = new(
@ -177,10 +197,15 @@ main()
adapterHttp = new(ApplicationAdapterHttp, application); adapterHttp = new(ApplicationAdapterHttp, application);
worker = new(HttpWorker, "testserver");
worker = new(HttpWorker, "taskrambler");
subjectAttach(worker, adapterHttp); subjectAttach(worker, adapterHttp);
server = new(Server, logger, worker, 11212, SOMAXCONN);
server = new(
Server,
logger,
worker,
(int)(port->value).number,
SOMAXCONN);
if (NULL != server) { if (NULL != server) {
serverRun(server); serverRun(server);
@ -236,12 +261,14 @@ main()
clearMimeTypes(); clearMimeTypes();
assetPoolCleanup(); assetPoolCleanup();
memCleanup();
} }
break; break;
} }
delete(config);
memCleanup();
return 0; return 0;
} }

23
src/testconfig.cfg

@ -0,0 +1,23 @@
##
# basic configuration file for taskrambler
#
# syntax: <ws><key><ws><value><ws>
#
# <ws> ::= any whitespace as defined by isspace
# <key> ::= any character except whitespace
# <value> ::= <string> | <number>
# <string> ::= <quote>any character<quote>
# <quote> ::= " | '
# <number> ::= <digit><number>
# <digit> ::= 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

4
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 \ TREE = tree.c find.c insert.c inOrderSuccessor.c delete.c walk.c \
rotateLeft.c rotateRight.c destroy.c rotateLeft.c rotateRight.c destroy.c
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libtree.a noinst_LIBRARIES = libtree.a
libtree_a_SOURCES = $(TREE) libtree_a_SOURCES = $(TREE)
libtree_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libtree_a_CFLAGS = $(AM_CFLAGS)

4
src/user/Makefile.am

@ -1,7 +1,9 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LIBRARIES = libuser.a noinst_LIBRARIES = libuser.a
libuser_a_SOURCES = user.c load.c save.c libuser_a_SOURCES = user.c load.c save.c
libuser_a_CFLAGS = $(CFLAGS) $(DRAGONEGG_FLAGS) -Wall -I ../../include/
libuser_a_CFLAGS = $(AM_CFLAGS)

8
src/utils/daemonize.c

@ -57,10 +57,10 @@ void daemonize(void) {
// set umask and change to working directory to / // set umask and change to working directory to /
umask(UMASK); 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); exit(EXIT_FAILURE);
}
}
// we should close all open filedescriptors now. // we should close all open filedescriptors now.
// But I assume that this function is called at the very start of the // 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); stdin = freopen("/dev/null", "r", stdin);
stdout = freopen("/dev/null", "w", stdout); stdout = freopen("/dev/null", "w", stdout);
} }
// vim: set ts=4 sw=4:

4
src/utils/mime_type.c

@ -38,8 +38,8 @@ Hash mime_types = NULL;
void void
readMimeTypes(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) { if (NULL != handle) {
char buffer[512]; char buffer[512];

Loading…
Cancel
Save