diff --git a/configure.ac b/configure.ac index 24cfc7e..f526f52 100644 --- a/configure.ac +++ b/configure.ac @@ -3,8 +3,9 @@ AC_PREREQ([2.68]) AC_INIT([taskrambler], [0.0.1], [Georg Hopp ]) -AM_INIT_AUTOMAKE -AC_COPYRIGHT([Copyright (C) 2012 Georg Hopp]) +AM_INIT_AUTOMAKE([subdir-objects]) +AM_SILENT_RULES([yes]) +AC_COPYRIGHT([Copyright © 2012 Georg Hopp]) AC_REVISION([$Revision: 0.01 $]) AC_CONFIG_SRCDIR([src/taskrambler.c]) AC_CONFIG_HEADERS([config.h]) diff --git a/include/class.h b/include/class.h index 6f34fe9..d08e85f 100644 --- a/include/class.h +++ b/include/class.h @@ -40,9 +40,9 @@ #define CLASS_MAGIC 0xFEFE -#define CLASS(name) \ - struct c_##name; \ - typedef struct c_##name * name; \ +#define CLASS(name) \ + struct c_##name; \ + typedef struct c_##name * name; \ extern struct class * const _##name; \ struct c_##name @@ -50,75 +50,68 @@ const char _[sizeof(struct c_##parent)] #define _NULL NULL -#define CREATE_CLASS(name,_parent,...) \ - static struct class c_##name; \ - static void _classInit_(void) { \ - c_##name.parent = _##_parent; \ - c_##name.init = NULL; \ - } \ - static struct class c_##name = { \ - CLASS_MAGIC, \ - NULL, \ - sizeof(struct c_##name), \ - _classInit_, \ - INIT_IMPL(__VA_ARGS__) \ +#define CREATE_CLASS(name,_parent,...) \ + static struct class c_##name; \ + static class_ptr _classInit_(void) { \ + c_##name.parent = _##_parent; \ + c_##name.init = NULL; \ + return &c_##name; \ + } \ + static struct class c_##name = { \ + CLASS_MAGIC, \ + NULL, \ + sizeof(struct c_##name), \ + _classInit_, \ + INIT_IFACE_IMPL(__VA_ARGS__) \ }; struct class * const _##name = &c_##name -#define GET_CLASS(object) (*(class_ptr *)((object) - sizeof(void*))) +#define INIT_CLASS(class) ((class)->init? (class)->init() : (class)) +#define GET_CLASS(object) (INIT_CLASS(*(class_ptr *)((object) - sizeof(void*)))) #define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface))) -#define IFACE_EXISTS(class,iface) (NULL != IFACE_GET((class),(iface))) +#define HAS_PARENT(class) (NULL != ((class)->parent) && INIT_CLASS((class)->parent)) /** * \todo actually i use gcc feature ## for variadoc... think about * a way to make this standard. */ -#define _CALL(object,_iface,method,...) \ - do { \ - class_ptr class = GET_CLASS((object)); \ - if (class->init) class->init(); \ - iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ - while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \ - class = class->parent; \ - if (class->init) class->init(); \ - iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ - }; \ - assert(NULL != iface->method); \ +#define _CALL(_class,_iface,method,...) \ + do { \ + class_ptr class = _class; \ + iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ + while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \ + class = class->parent; \ + iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ + } \ + assert(NULL != iface->method); \ } while(0) -#define CALL(object,_iface,method,...) \ - do { \ - struct i_##_iface * iface; \ - _CALL(object, _iface, method, ##__VA_ARGS__); \ - iface->method(object, ##__VA_ARGS__); \ +#define CALL(object,_iface,method,...) \ + do { \ + struct i_##_iface * iface; \ + _CALL(GET_CLASS(object), _iface, method, ##__VA_ARGS__); \ + iface->method(object, ##__VA_ARGS__); \ } while(0) -#define RETCALL(object,_iface,method,ret,...) \ - do { \ - struct i_##_iface * iface; \ - _CALL(object, _iface, method, ##__VA_ARGS__); \ - ret = iface->method(object, ##__VA_ARGS__); \ +#define RETCALL(object,_iface,method,ret,...) \ + do { \ + struct i_##_iface * iface; \ + _CALL(GET_CLASS(object), _iface, method, ##__VA_ARGS__); \ + ret = iface->method(object, ##__VA_ARGS__); \ } while(0) -#define PARENTCALL(object,_iface,method,...) \ - do { \ - struct i_##_iface * iface; \ - class_ptr class = GET_CLASS((object)); \ - if (class->init) class->init(); \ - assert(HAS_PARENT(class)); \ - class = class->parent; \ - if (class->init) class->init(); \ - iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ - assert(NULL != iface->method); \ - iface->method(object, ##__VA_ARGS__); \ +#define PARENTCALL(object,_iface,method,...) \ + do { \ + struct i_##_iface * iface; \ + class_ptr pc_class = GET_CLASS((object)); \ + assert(HAS_PARENT(pc_class)); \ + _CALL(pc_class->parent, _iface, method, ##__VA_ARGS__); \ + iface->method(object, ##__VA_ARGS__); \ } while(0) -#define HAS_PARENT(class) (NULL != ((class)->parent)) - -typedef void (* fptr_classInit)(void); - struct class; typedef struct class * class_ptr; +typedef class_ptr (* fptr_classInit)(void); struct class { const int magic; class_ptr parent; diff --git a/include/http/cookie.h b/include/http/cookie.h index 358be49..18e52fd 100644 --- a/include/http/cookie.h +++ b/include/http/cookie.h @@ -4,20 +4,20 @@ * \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 . + * 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 __HTTP_COOKIE_H__ diff --git a/include/http/writer.h b/include/http/writer.h index 3fb91bb..c6b1470 100644 --- a/include/http/writer.h +++ b/include/http/writer.h @@ -5,20 +5,20 @@ * \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 . + * 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 __HTTP_WRITER_H__ diff --git a/include/interface.h b/include/interface.h index bebe14c..34c3fcb 100644 --- a/include/interface.h +++ b/include/interface.h @@ -36,7 +36,7 @@ static const struct i_##name i_##name##_impl = {&i_##name,__VA_ARGS__} #define NUMARGS(...) (sizeof((const void*[]){__VA_ARGS__})/sizeof(void*)) -#define INIT_IMPL(...) {NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}} +#define INIT_IFACE_IMPL(...) {NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}} struct interface { @@ -52,7 +52,7 @@ struct iface_impl { }; typedef struct iface_impl * iface_impl_ptr; -extern struct interface * interfaceGet(iface_impl_ptr, const iface_ptr); +extern iface_ptr interfaceGet(iface_impl_ptr, const iface_ptr); #endif // __INTERFACE_H__ diff --git a/src/Makefile.am b/src/Makefile.am index 3abd3d2..de4d510 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,71 +1,70 @@ ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects -IFACE = interface/class.c interface/stream_reader.c interface/logger.c \ - interface/stream_writer.c interface/http_intro.c \ - interface/subject.c interface/observer.c interface.c -SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c -STREAM = stream.c stream/read.c stream/write.c -HASH = hash.c hash/add.c hash/get.c hash/delete.c \ - hash/each.c interface/hashable.c hash_value.c -SERVER = server.c server/run.c server/close_conn.c server/poll.c \ - server/handle_accept.c server/read.c server/write.c -LOGGER = logger.c logger/stderr.c logger/syslog.c -CB = cbuf.c cbuf/read.c cbuf/write.c \ - cbuf/get_line.c cbuf/set_data.c cbuf/get_data.c \ - cbuf/addr_index.c cbuf/get_free.c cbuf/get_read.c cbuf/get_write.c \ - cbuf/inc_read.c cbuf/inc_write.c cbuf/is_empty.c cbuf/memchr.c \ - cbuf/skip_non_alpha.c cbuf/is_locked.c cbuf/lock.c cbuf/release.c \ - cbuf/empty.c -MSG = http/message.c \ - http/message/has_keep_alive.c \ - http/message/header_size_get.c \ - http/message/header_to_string.c \ - http/message/get_version.c \ - http/message/has_valid_version.c -MSGQ = http/message/queue.c -REQ = http/request.c \ - http/request/has_valid_method.c -RESP = http/response.c \ - http/response/304.c \ - http/response/404.c \ - http/response/403.c \ - http/response/login_form.c \ - http/response/asset.c \ - http/response/randval.c \ - http/response/session.c -PARSER = http/parser.c \ - http/parser/parse.c \ - http/parser/new_message.c \ - http/parser/header.c \ - http/parser/body.c \ - http/parser/request_vars.c \ - http/parser/post_vars.c -WRITER = http/writer.c \ - http/writer/write.c -WORKER = http/worker.c \ - http/worker/process.c \ - http/worker/write.c \ - http/worker/get_asset.c \ - http/worker/add_common_header.c -HEADER = http/header.c \ - http/header/to_string.c +IFACE = interface/class.c interface/stream_reader.c interface/logger.c \ + interface/stream_writer.c interface/http_intro.c \ + interface/subject.c interface/observer.c interface.c +SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c +STREAM = stream.c stream/read.c stream/write.c +HASH = hash.c hash/add.c hash/get.c hash/delete.c \ + hash/each.c interface/hashable.c hash_value.c +SERVER = server.c server/run.c server/close_conn.c server/poll.c \ + server/handle_accept.c server/read.c server/write.c +LOGGER = logger.c logger/stderr.c logger/syslog.c +CB = cbuf.c cbuf/read.c cbuf/write.c \ + cbuf/get_line.c cbuf/set_data.c cbuf/get_data.c \ + cbuf/addr_index.c cbuf/get_free.c cbuf/get_read.c cbuf/get_write.c \ + cbuf/inc_read.c cbuf/inc_write.c cbuf/is_empty.c cbuf/memchr.c \ + cbuf/skip_non_alpha.c cbuf/is_locked.c cbuf/lock.c cbuf/release.c \ + cbuf/empty.c +MSG = http/message.c \ + http/message/has_keep_alive.c \ + http/message/header_size_get.c \ + http/message/header_to_string.c \ + http/message/get_version.c \ + http/message/has_valid_version.c +MSGQ = http/message/queue.c +REQ = http/request.c \ + http/request/has_valid_method.c +RESP = http/response.c \ + http/response/304.c \ + http/response/404.c \ + http/response/403.c \ + http/response/login_form.c \ + http/response/asset.c \ + http/response/randval.c \ + http/response/session.c +PARSER = http/parser.c \ + http/parser/parse.c \ + http/parser/new_message.c \ + http/parser/header.c \ + http/parser/body.c \ + http/parser/request_vars.c \ + http/parser/post_vars.c +WRITER = http/writer.c \ + http/writer/write.c +WORKER = http/worker.c \ + http/worker/process.c \ + http/worker/write.c \ + http/worker/get_asset.c \ + http/worker/add_common_header.c +HEADER = http/header.c \ + http/header/to_string.c SESSION = session.c session/add.c session/get.c session/delete.c -UTILS = utils/hash.c \ - utils/memory.c \ - utils/http.c \ - utils/daemonize.c \ - utils/signalHandling.c -AUTH = interface/auth.c auth/ldap.c credential.c +UTILS = utils/hash.c \ + utils/memory.c \ + utils/http.c \ + utils/daemonize.c \ + utils/signalHandling.c +AUTH = interface/auth.c auth/ldap.c credential.c AM_CFLAGS = -Wall -I ../include/ -bin_PROGRAMS = webgameserver +bin_PROGRAMS = taskrambler -webgameserver_SOURCES = webgameserver.c \ +taskrambler_SOURCES = taskrambler.c \ $(IFACE) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ $(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \ $(UTILS) $(MSGQ) $(SESSION) $(STREAM) $(HASH) $(AUTH) -webgameserver_CFLAGS = -Wall -I ../include/ -webgameserver_LDFLAGS = -lrt -lssl -lldap +taskrambler_CFLAGS = -Wall -I ../include/ +taskrambler_LDFLAGS = -lrt -lssl -lldap diff --git a/src/interface.c b/src/interface.c index 3131ab7..9d4d6b9 100644 --- a/src/interface.c +++ b/src/interface.c @@ -40,25 +40,25 @@ comp(const void * _a, const void * _b) * this one is important in selector functions to get the correct interface * implementation of a class. */ -struct interface * +iface_ptr interfaceGet(iface_impl_ptr iface_impl, const iface_ptr _iface) { const iface_ptr * iface = &_iface; - void * dummy; + iface_ptr * found; if (! iface_impl->simpl) { qsort((void**)(iface_impl->impl), iface_impl->nimpl, sizeof(iface_ptr), comp); iface_impl->simpl=TRUE; } - dummy = bsearch( + found = bsearch( &iface, iface_impl->impl, iface_impl->nimpl, sizeof(iface_ptr), comp); - return dummy? *(struct interface **)dummy : dummy; + return found? *found : (iface_ptr)NULL; } // vim: set ts=4 sw=4: diff --git a/src/interface/class.c b/src/interface/class.c index 2909a68..cfdcf83 100644 --- a/src/interface/class.c +++ b/src/interface/class.c @@ -40,8 +40,6 @@ classNew(class_ptr class, ...) va_list params; int ret; - if (class->init) class->init(); - * (class_ptr *)object = class; object += sizeof(void*); diff --git a/tests/Makefile.am b/tests/Makefile.am index d3c0391..f2906f6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,4 @@ ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects TESTS_ENVIRONMENT = valgrind --error-exitcode=123 --leak-check=full --quiet TESTS = cclassTest loggerTest socketTest serverTest diff --git a/tests/mock/class.h b/tests/mock/class.h index e439bb1..83c810c 100644 --- a/tests/mock/class.h +++ b/tests/mock/class.h @@ -1,6 +1,10 @@ /** * \file * mock/class.h: definitions for my mock to test my oop stuff + * + * \author Georg Hopp + * + * \copyright * Copyright (C) 2011 Georg Hopp * * This program is free software: you can redistribute it and/or modify diff --git a/tests/runtest.h b/tests/runtest.h index 7b15945..e62e562 100644 --- a/tests/runtest.h +++ b/tests/runtest.h @@ -1,6 +1,10 @@ /** * \file * runtest.h: assertions and other definitions for all my tests + * + * \author Georg Hopp + * + * \copyright * Copyright (C) 2011 Georg Hopp * * This program is free software: you can redistribute it and/or modify