diff --git a/.gitignore b/.gitignore index dfd2105..0846e85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ .*.swp *.o +*.a +*.gcda +*.gcno .dirstamp .deps/ Makefile @@ -8,6 +11,10 @@ Makefile.in m4/ /docs/ /INSTALL +coverage.base +coverage.run +coverage.info +coveragereport/ *.m4 /autom4te.cache/ /compile @@ -18,4 +25,5 @@ m4/ /ltmain.sh /missing stamp-h1 -src/webgameserver +src/taskrambler +/tests/*Test diff --git a/AUTHORS b/AUTHORS index e69de29..354d97f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -0,0 +1 @@ +Georg Hopp diff --git a/Makefile.am b/Makefile.am index 796e33b..c413a9b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,6 +5,8 @@ ACLOCAL_AMFLAGS = -I m4 #create_token_LDADD = src/libtoken.la $(LIBOBJS) #create_token_CFLAGS = -Wall -I include -EXTRA_DIST = include assets +EXTRA_DIST = include assets certs SUBDIRS = src tests + +include $(top_srcdir)/Makefile.am.coverage diff --git a/Makefile.am.coverage b/Makefile.am.coverage new file mode 100644 index 0000000..470d456 --- /dev/null +++ b/Makefile.am.coverage @@ -0,0 +1,33 @@ + +# Coverage targets + +#if HAVE_GCOV + + .PHONY: clean-gcda + clean-gcda: + @echo Removing old coverage results + -find -name '*.gcda' -print | xargs -r rm + + .PHONY: coverage-html generate-coverage-html clean-coverage-html + coverage-html: clean-gcda + -$(MAKE) -C tests $(AM_MAKEFLAGS) -k check-build + $(MAKE) $(AM_MAKEFLAGS) init-coverage-html + -$(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html + + init-coverage-html: + $(LCOV) -d $(top_builddir) -c -i -o coverage.base --no-checksum --compat-libtool + + generate-coverage-html: + @echo Collecting coverage data + $(LCOV) -d $(top_builddir) -c -o coverage.run --no-checksum --compat-libtool + $(LCOV) -d $(top_builddir) -a ./coverage.base -a ./coverage.run -o coverage.info --no-checksum --compat-libtool + LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --branch-coverage --show-details coverage.info + + clean-coverage-html: clean-gcda + -$(LCOV) --directory $(top_builddir) -z + -rm -rf coverage.info coveragereport + + clean-local: clean-coverage-html + +#endif # HAVE_GCOV diff --git a/configure.ac b/configure.ac index edf5325..c8200b1 100644 --- a/configure.ac +++ b/configure.ac @@ -3,13 +3,22 @@ AC_PREREQ([2.68]) AC_INIT([webgameserver], [0.0.2], [Georg Hopp ]) +LT_INIT AM_INIT_AUTOMAKE -AC_COPYRIGHT([Copyright (C) 2012 Georg Hopp]) -AC_REVISION([$Revision: 0.03 $]) +#AM_INIT_AUTOMAKE([subdir-objects]) +AM_SILENT_RULES([yes]) +AC_COPYRIGHT([Copyright © 2012 Georg Hopp]) +AC_REVISION([$Revision: 0.04 $]) AC_CONFIG_SRCDIR([src/webgameserver.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) +m4_include([m4/gcov.m4]) +AC_TDD_GCOV +AC_SUBST(COVERAGE_CFLAGS) +AC_SUBST(COVERAGE_CXXFLAGS) +AC_SUBST(COVERAGE_LDFLAGS) + # Checks for programs. AC_PROG_CXX AC_PROG_CC @@ -37,5 +46,17 @@ AC_TYPE_SIZE_T #AC_FUNC_MALLOC AC_CHECK_FUNCS([memset]) -AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile]) +AC_CONFIG_FILES([Makefile + src/Makefile + src/auth/Makefile + src/cbuf/Makefile + src/class/Makefile + src/hash/Makefile + src/http/Makefile + src/logger/Makefile + src/server/Makefile + src/session/Makefile + src/socket/Makefile + src/stream/Makefile + tests/Makefile]) AC_OUTPUT diff --git a/include/auth.h b/include/auth.h index a83eb51..db49b3c 100644 --- a/include/auth.h +++ b/include/auth.h @@ -1,44 +1,10 @@ -/** - * \file - * Authenticatio module factory - * - * A factory to get a specific authentication module. - * An authentication module is a class that implement the Auth interface. - * - * \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 __AUTH_H__ #define __AUTH_H__ -#include "class.h" +#include "auth/auth.h" #include "auth/ldap.h" - -typedef enum e_AuthModule { - AUTH_LDAP = 0 -} AuthModule; - -CLASS(Auth) { -}; - -void * authCreateById(Auth, int); -AuthLdap authCreateLdap(Auth); +#include "auth/credential.h" +#include "auth/interface/auth.h" #endif // __AUTH_H__ diff --git a/include/auth/auth.h b/include/auth/auth.h new file mode 100644 index 0000000..2518918 --- /dev/null +++ b/include/auth/auth.h @@ -0,0 +1,45 @@ +/** + * \file + * Authenticatio module factory + * + * A factory to get a specific authentication module. + * An authentication module is a class that implement the Auth interface. + * + * \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 __AUTH_AUTH_H__ +#define __AUTH_AUTH_H__ + +#include "class.h" +#include "auth/ldap.h" + +typedef enum e_AuthModule { + AUTH_LDAP = 0 +} AuthModule; + +CLASS(Auth) { +}; + +void * authCreateById(Auth, int); +AuthLdap authCreateLdap(Auth); + +#endif // __AUTH_AUTH_H__ + +// vim: set ts=4 sw=4: diff --git a/include/auth/credential.h b/include/auth/credential.h new file mode 100644 index 0000000..01394e8 --- /dev/null +++ b/include/auth/credential.h @@ -0,0 +1,54 @@ +/** + * \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 __AUTH_CREDENTIAL_H__ +#define __AUTH_CREDENTIAL_H__ + +#include + +#include "class.h" + +#define CRED_PWD(c) (((c)->cred).pwd) + +typedef enum e_CredentialType { + CRED_PASSWORD = 0 +} CredentialType; + + +CLASS(Credential) { + CredentialType type; + + union { + + struct { + char * user; + size_t nuser; + char * pass; + size_t npass; + } pwd; + + } cred; +}; + +#endif // __AUTH_CREDENTIAL_H__ + +// vim: set ts=4 sw=4: diff --git a/include/interface/auth.h b/include/auth/interface/auth.h similarity index 89% rename from include/interface/auth.h rename to include/auth/interface/auth.h index ed552e7..8dccfa2 100644 --- a/include/interface/auth.h +++ b/include/auth/interface/auth.h @@ -25,13 +25,13 @@ * along with this program. If not, see . */ -#ifndef __INTERFACE_AUTH_H__ -#define __INTERFACE_AUTH_H__ +#ifndef __AUTH_INTERFACE_AUTH_H__ +#define __AUTH_INTERFACE_AUTH_H__ #include -#include "interface.h" -#include "credential.h" +#include "class.h" +#include "auth/credential.h" typedef int (* fptr_authenticate)(void *, Credential); @@ -44,6 +44,6 @@ struct i_Auth { extern int authenticate(void *, Credential); -#endif // __INTERFACE_AUTH_H__ +#endif // __AUTH_INTERFACE_AUTH_H__ // vim: set ts=4 sw=4: diff --git a/include/auth/ldap.h b/include/auth/ldap.h index 5529fd9..4c6e98c 100644 --- a/include/auth/ldap.h +++ b/include/auth/ldap.h @@ -1,3 +1,25 @@ +/** + * \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 __AUTH_LDAP_H__ #define __AUTH_LDAP_H__ diff --git a/include/cbuf.h b/include/cbuf.h index 053b836..dd2de94 100644 --- a/include/cbuf.h +++ b/include/cbuf.h @@ -11,7 +11,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/class.h b/include/class.h index efecb79..6c07bbc 100644 --- a/include/class.h +++ b/include/class.h @@ -1,131 +1,9 @@ -/** - * \file - * My own class implementation for C. It combines a data structure - * with a set of dynamically linked methods defined by an interface. A - * dynamically linked method will be called via a selector method which in - * turn gets the implementation stored in the class. - * - * \author Georg Hopp - * - * \copyright - * Copyright (C) 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 __CLASS_H__ #define __CLASS_H__ -#include -#include -#include -#include - -#include "interface.h" - -#ifndef _ISOC99_SOURCE -#define _ISOC99_SOURCE -#endif - -#define CLASS_MAGIC 0xFEFE - -#define CLASS(name) \ - struct c_##name; \ - typedef struct c_##name * name; \ - extern struct class * const _##name; \ - struct c_##name - -#define EXTENDS(parent) \ - 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__) \ - }; struct class * const _##name = &c_##name - -#define GET_CLASS(object) (*(class_ptr *)((object) - sizeof(void*))) -#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface))) -#define IFACE_EXISTS(class,iface) (NULL != IFACE_GET((class),(iface))) - -/** - * \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); \ - } while(0) - -#define CALL(object,_iface,method,...) \ - do { \ - struct i_##_iface * iface; \ - _CALL(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__); \ - } 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__); \ - } while(0) - - -#define HAS_PARENT(class) (NULL != ((class)->parent)) - -typedef void (* fptr_classInit)(void); - -struct class; -typedef struct class * class_ptr; -struct class { - const int magic; - class_ptr parent; - size_t object_size; - fptr_classInit init; - struct iface_impl impl; -}; +#include "class/class.h" +#include "class/interface.h" +#include "class/interface/class.h" #endif // __CLASS_H__ diff --git a/include/class/class.h b/include/class/class.h new file mode 100644 index 0000000..b8b38cc --- /dev/null +++ b/include/class/class.h @@ -0,0 +1,128 @@ +/** + * \file + * My own class implementation for C. It combines a data structure + * with a set of dynamically linked methods defined by an interface. A + * dynamically linked method will be called via a selector method which in + * turn gets the implementation stored in the class. + * + * \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 __CLASS_CLASS_H__ +#define __CLASS_CLASS_H__ + +#include +#include +#include +#include + +#include "class/interface.h" + +#ifndef _ISOC99_SOURCE +#define _ISOC99_SOURCE +#endif + +#define CLASS_MAGIC 0xFEFE + +#define CLASS(name) \ + struct c_##name; \ + typedef struct c_##name * name; \ + extern struct class * const _##name; \ + struct c_##name + +#define EXTENDS(parent) \ + const char _[sizeof(struct c_##parent)] + +#define _NULL NULL +#define CREATE_CLASS(name,_parent,...) \ + static struct class c_##name; \ + static class_ptr _classInit##name##_(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##name##_, \ + INIT_IFACE_IMPL(__VA_ARGS__) \ + }; struct class * const _##name = &c_##name + +#define INIT_CLASS(class) ((class)->init? (class)->init() : (class)) +#define GET_CLASS(object) (INIT_CLASS(*(class_ptr *)((void*)(object) - sizeof(void*)))) +#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface))) +#define HAS_PARENT(class) (NULL != ((class)->parent) && INIT_CLASS((class)->parent)) + +#define IS_OBJECT(obj) ((GET_CLASS((obj)))->magic == CLASS_MAGIC) +#define INSTANCE_OF(class,obj) ((GET_CLASS((obj))) == _##class) + +/** + * \todo actually i use gcc feature ## for variadoc... think about + * a way to make this standard. + */ +#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(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(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 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) + + +struct class; +typedef struct class * class_ptr; +typedef class_ptr (* fptr_classInit)(void); +struct class { + const int magic; + class_ptr parent; + size_t object_size; + fptr_classInit init; + struct iface_impl impl; +}; + +#endif // __CLASS_CLASS_H__ + +// vim: set ts=4 sw=4: diff --git a/include/interface.h b/include/class/interface.h similarity index 86% rename from include/interface.h rename to include/class/interface.h index f3e3c56..941f43c 100644 --- a/include/interface.h +++ b/include/class/interface.h @@ -8,7 +8,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,8 +24,8 @@ * along with this program. If not, see . */ -#ifndef __INTERFACE_H__ -#define __INTERFACE_H__ +#ifndef __CLASS_INTERFACE_H__ +#define __CLASS_INTERFACE_H__ #include @@ -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,8 +52,8 @@ 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__ +#endif // __CLASS_INTERFACE_H__ // vim: set ts=4 sw=4: diff --git a/include/interface/class.h b/include/class/interface/class.h similarity index 88% rename from include/interface/class.h rename to include/class/interface/class.h index 748b16b..98cbdbd 100644 --- a/include/interface/class.h +++ b/include/class/interface/class.h @@ -7,7 +7,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -23,13 +23,13 @@ * along with this program. If not, see . */ -#ifndef __INTERFACE_CLASS_H__ -#define __INTERFACE_CLASS_H__ +#ifndef __CLASS_INTERFACE_CLASS_H__ +#define __CLASS_INTERFACE_CLASS_H__ #include -#include "class.h" -#include "interface.h" +#include "class/class.h" +#include "class/interface.h" typedef int (* fptr_ctor)(void *, va_list *); typedef void (* fptr_dtor)(void *); @@ -52,6 +52,6 @@ extern void * classClone(void *); #define delete(object) classDelete((void **)&(object)) #define clone(object) classClone((void *)(object)) -#endif // __INTERFACE_CLASS_H__ +#endif // __CLASS_INTERFACE_CLASS_H__ // vim: set ts=4 sw=4: diff --git a/include/commons.h b/include/commons.h index e9642f5..7f354f7 100644 --- a/include/commons.h +++ b/include/commons.h @@ -1,3 +1,25 @@ +/** + * \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 __COMMONS_H__ #define __COMMONS_H__ diff --git a/include/credential.h b/include/credential.h deleted file mode 100644 index f512b47..0000000 --- a/include/credential.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __CREDENTIAL_H__ -#define __CREDENTIAL_H__ - -#include - -#include "class.h" - -#define CRED_PWD(c) (((c)->cred).pwd) - -typedef enum e_CredentialType { - CRED_PASSWORD = 0 -} CredentialType; - - -CLASS(Credential) { - CredentialType type; - - union { - - struct { - char * user; - size_t nuser; - char * pass; - size_t npass; - } pwd; - - } cred; -}; - -#endif // __CREDENTIAL_H__ - -// vim: set ts=4 sw=4: diff --git a/include/hash.h b/include/hash.h index 0738df9..54868d7 100644 --- a/include/hash.h +++ b/include/hash.h @@ -1,19 +1,9 @@ #ifndef __HASH_H__ #define __HASH_H__ -#include - -#include "class.h" - - -CLASS(Hash) { - void * root; -}; - -void * hashAdd(Hash, void *); -void * hashDelete(Hash, const char *, size_t); -void * hashGet(Hash, const char *, size_t); -void hashEach(Hash, void (*)(const void*)); +#include "hash/hash.h" +#include "hash/value.h" +#include "hash/interface/hashable.h" #endif // __HASH_H__ diff --git a/include/hash/hash.h b/include/hash/hash.h new file mode 100644 index 0000000..1ddcf2e --- /dev/null +++ b/include/hash/hash.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 __HASH_HASH_H__ +#define __HASH_HASH_H__ + +#include + +#include "class.h" + + +CLASS(Hash) { + void * root; +}; + +void * hashAdd(Hash, void *); +void * hashDelete(Hash, const char *, size_t); +void * hashGet(Hash, const char *, size_t); +void hashEach(Hash, void (*)(const void*)); + +#endif // __HASH_HASH_H__ + +// vim: set ts=4 sw=4: diff --git a/include/interface/hashable.h b/include/hash/interface/hashable.h similarity index 87% rename from include/interface/hashable.h rename to include/hash/interface/hashable.h index 4f71b52..1a33d58 100644 --- a/include/interface/hashable.h +++ b/include/hash/interface/hashable.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -21,10 +21,10 @@ * along with this program. If not, see . */ -#ifndef __INTERFACE_HASHABLE_H__ -#define __INTERFACE_HASHABLE_H__ +#ifndef __HASH_INTERFACE_HASHABLE_H__ +#define __HASH_INTERFACE_HASHABLE_H__ -#include "interface.h" +#include "class.h" typedef unsigned long (* fptr_hashableGetHash)(void *); typedef void (* fptr_hashableHandleDouble)(void *, void *); @@ -40,6 +40,6 @@ struct i_Hashable { extern unsigned long hashableGetHash(void *); extern void hashableHandleDouble(void *, void *); -#endif // __INTERFACE_HASHABLE_H__ +#endif // __HASH_INTERFACE_HASHABLE_H__ // vim: set ts=4 sw=4: diff --git a/include/hash/value.h b/include/hash/value.h new file mode 100644 index 0000000..17a4f6c --- /dev/null +++ b/include/hash/value.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 __HASH_VALUE_H__ +#define __HASH_VALUE_H__ + +#include + +#include "class.h" + +CLASS(HashValue) { + unsigned long hash; + + char * key; + void * value; + + size_t nkey; + size_t nvalue; +}; + +#endif // __HASH_VALUE_H__ + +// vim: set ts=4 sw=4: diff --git a/include/hash_value.h b/include/hash_value.h deleted file mode 100644 index f2b1c98..0000000 --- a/include/hash_value.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __HASH_VALUE_H__ -#define __HASH_VALUE_H__ - -#include - -#include "class.h" - -CLASS(HashValue) { - unsigned long hash; - - char * key; - void * value; - - size_t nkey; - size_t nvalue; -}; - -#endif // __HASH_VALUE_H__ - -// vim: set ts=4 sw=4: diff --git a/include/http.h b/include/http.h new file mode 100644 index 0000000..5eb5f04 --- /dev/null +++ b/include/http.h @@ -0,0 +1,17 @@ +#ifndef __HTTP_H__ +#define __HTTP_H__ + +#include "http/cookie.h" +#include "http/header.h" +#include "http/message.h" +#include "http/message/queue.h" +#include "http/request.h" +#include "http/response.h" +#include "http/parser.h" +#include "http/writer.h" +#include "http/worker.h" +#include "http/interface/http_intro.h" + +#endif // __HTTP_H__ + +// vim: set ts=4 sw=4: diff --git a/include/http/cookie.h b/include/http/cookie.h index 935958a..18e52fd 100644 --- a/include/http/cookie.h +++ b/include/http/cookie.h @@ -1,3 +1,25 @@ +/** + * \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 __HTTP_COOKIE_H__ #define __HTTP_COOKIE_H__ diff --git a/include/http/header.h b/include/http/header.h index fbd7ee8..865ffd7 100644 --- a/include/http/header.h +++ b/include/http/header.h @@ -6,7 +6,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/interface/http_intro.h b/include/http/interface/http_intro.h similarity index 97% rename from include/interface/http_intro.h rename to include/http/interface/http_intro.h index 81b6afe..60edf93 100644 --- a/include/interface/http_intro.h +++ b/include/http/interface/http_intro.h @@ -7,7 +7,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/http/message.h b/include/http/message.h index 11b1dfa..2161793 100644 --- a/include/http/message.h +++ b/include/http/message.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -38,7 +38,6 @@ CLASS(HttpMessage) { char * version; Hash header; - Hash cookies; HttpMessageType type; Stream handle; diff --git a/include/http/message/queue.h b/include/http/message/queue.h index b4d6052..7b024e0 100644 --- a/include/http/message/queue.h +++ b/include/http/message/queue.h @@ -7,7 +7,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/http/parser.h b/include/http/parser.h index cefe9db..7ca76e2 100644 --- a/include/http/parser.h +++ b/include/http/parser.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/http/request.h b/include/http/request.h index 5f9cddb..45eac76 100644 --- a/include/http/request.h +++ b/include/http/request.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/http/response.h b/include/http/response.h index 4a3090b..98818ff 100644 --- a/include/http/response.h +++ b/include/http/response.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/http/worker.h b/include/http/worker.h index c62134e..cfc7255 100644 --- a/include/http/worker.h +++ b/include/http/worker.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/http/writer.h b/include/http/writer.h index 9c1d143..c6b1470 100644 --- a/include/http/writer.h +++ b/include/http/writer.h @@ -5,20 +5,20 @@ * \author Georg Hopp * * \copyright - * - Copyright (C) 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/observer.h b/include/interface/observer.h index ffb1840..077823c 100644 --- a/include/interface/observer.h +++ b/include/interface/observer.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/interface/subject.h b/include/interface/subject.h index 62c3b3a..16ef044 100644 --- a/include/interface/subject.h +++ b/include/interface/subject.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/logger.h b/include/logger.h index 26ee2bf..5680044 100644 --- a/include/logger.h +++ b/include/logger.h @@ -1,56 +1,8 @@ -/** - * \file - * A generic logger class and two extended classes, One that logs to - * stderr and one that logs to the system syslog. - * - * \author Georg Hopp - * - * \copyright - * Copyright (C) 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 __LOGGER_H__ #define __LOGGER_H__ -#include "class.h" - -typedef enum logger_level { - LOGGER_DEBUG=0, - LOGGER_INFO, - LOGGER_NOTICE, - LOGGER_WARNING, - LOGGER_ERR, - LOGGER_CRIT, - LOGGER_ALERT, - LOGGER_EMERG -} logger_level; - -extern const char * const logger_level_str[]; - -CLASS(Logger) { - logger_level min_level; -}; - -CLASS(LoggerStderr) { - EXTENDS(Logger); -}; - -CLASS(LoggerSyslog) { - EXTENDS(Logger); -}; +#include "logger/logger.h" +#include "logger/interface/logger.h" #endif // __LOGGER_H__ diff --git a/include/interface/logger.h b/include/logger/interface/logger.h similarity index 86% rename from include/interface/logger.h rename to include/logger/interface/logger.h index 769ecb4..549f584 100644 --- a/include/interface/logger.h +++ b/include/logger/interface/logger.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -21,12 +21,12 @@ * along with this program. If not, see . */ -#ifndef __INTERFACE_LOGGER_H__ -#define __INTERFACE_LOGGER_H__ +#ifndef __LOGGER_INTERFACE_LOGGER_H__ +#define __LOGGER_INTERFACE_LOGGER_H__ #include -#include "interface.h" +#include "class.h" #include "logger.h" typedef void (* fptr_log)(void *, logger_level, const char * const); @@ -40,6 +40,6 @@ struct i_Logger { extern void loggerLog(void *, logger_level, const char * const, ...); -#endif // __INTERFACE_LOGGER_H__ +#endif // __LOGGER_INTERFACE_LOGGER_H__ // vim: set ts=4 sw=4: diff --git a/include/logger/logger.h b/include/logger/logger.h new file mode 100644 index 0000000..fc10124 --- /dev/null +++ b/include/logger/logger.h @@ -0,0 +1,57 @@ +/** + * \file + * A generic logger class and two extended classes, One that logs to + * stderr and one that logs to the system syslog. + * + * \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 __LOGGER_LOGGER_H__ +#define __LOGGER_LOGGER_H__ + +#include "class.h" + +typedef enum logger_level { + LOGGER_DEBUG=0, + LOGGER_INFO, + LOGGER_NOTICE, + LOGGER_WARNING, + LOGGER_ERR, + LOGGER_CRIT, + LOGGER_ALERT, + LOGGER_EMERG +} logger_level; + +extern const char * const logger_level_str[]; + +CLASS(Logger) { + logger_level min_level; +}; + +CLASS(LoggerStderr) { + EXTENDS(Logger); +}; + +CLASS(LoggerSyslog) { + EXTENDS(Logger); +}; + +#endif // __LOGGER_LOGGER_H__ + +// vim: set ts=4 sw=4: diff --git a/include/server.h b/include/server.h index 198aac1..0468e39 100644 --- a/include/server.h +++ b/include/server.h @@ -7,7 +7,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/session.h b/include/session.h index 67571f3..02f7aec 100644 --- a/include/session.h +++ b/include/session.h @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/socket.h b/include/socket.h index af68ac9..7e1442f 100644 --- a/include/socket.h +++ b/include/socket.h @@ -6,7 +6,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/stream.h b/include/stream.h index 0bae954..2b3072b 100644 --- a/include/stream.h +++ b/include/stream.h @@ -1,26 +1,9 @@ #ifndef __STREAM_H__ #define __STREAM_H__ -#include -#include - -#include "class.h" - -typedef enum e_StreamHandleType { - STREAM_FD = 0, - STREAM_SSL -} StreamHandleType; - -CLASS(Stream) { - StreamHandleType type; - union { - int fd; - SSL * ssl; - } handle; -}; - -ssize_t streamRead(Stream, void *, size_t); -ssize_t streamWrite(Stream, void *, size_t); +#include "stream/stream.h" +#include "stream/interface/reader.h" +#include "stream/interface/writer.h" #endif // __STREAM_H__ diff --git a/include/interface/stream_reader.h b/include/stream/interface/reader.h similarity index 86% rename from include/interface/stream_reader.h rename to include/stream/interface/reader.h index 1478e5d..8719099 100644 --- a/include/interface/stream_reader.h +++ b/include/stream/interface/reader.h @@ -6,7 +6,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -22,12 +22,12 @@ * along with this program. If not, see . */ -#ifndef __STREAM_READER_H__ -#define __STREAM_READER_H__ +#ifndef __STREAM_INTERFACE_READER_H__ +#define __STREAM_INTERFACE_READER_H__ #include -#include "stream.h" +#include "stream/stream.h" typedef ssize_t (* fptr_streamReaderRead)(void *, Stream); @@ -40,6 +40,6 @@ struct i_StreamReader { extern ssize_t streamReaderRead(void *, Stream); -#endif // __STREAM_READER_H__ +#endif // __STREAM_INTERFACE_READER_H__ // vim: set ts=4 sw=4: diff --git a/include/interface/stream_writer.h b/include/stream/interface/writer.h similarity index 86% rename from include/interface/stream_writer.h rename to include/stream/interface/writer.h index 3229705..99d434d 100644 --- a/include/interface/stream_writer.h +++ b/include/stream/interface/writer.h @@ -6,7 +6,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -22,12 +22,12 @@ * along with this program. If not, see . */ -#ifndef __STREAM_WRITER_H__ -#define __STREAM_WRITER_H__ +#ifndef __STREAM_INTERFACE_WRITER_H__ +#define __STREAM_INTERFACE_WRITER_H__ #include -#include "stream.h" +#include "stream/stream.h" typedef ssize_t (* fptr_streamWriterWrite)(void *, Stream); @@ -40,6 +40,6 @@ struct i_StreamWriter { extern ssize_t streamWriterWrite(void *, Stream); -#endif // __STREAM_WRITER_H__ +#endif // __STREAM_INTERFACE_WRITER_H__ // vim: set ts=4 sw=4: diff --git a/include/stream/stream.h b/include/stream/stream.h new file mode 100644 index 0000000..eb16104 --- /dev/null +++ b/include/stream/stream.h @@ -0,0 +1,49 @@ +/** + * \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 __STREAM_STREAM_H__ +#define __STREAM_STREAM_H__ + +#include +#include + +#include "class.h" + +typedef enum e_StreamHandleType { + STREAM_FD = 0, + STREAM_SSL +} StreamHandleType; + +CLASS(Stream) { + StreamHandleType type; + union { + int fd; + SSL * ssl; + } handle; +}; + +ssize_t streamRead(Stream, void *, size_t); +ssize_t streamWrite(Stream, void *, size_t); + +#endif // __STREAM_STREAM_H__ + +// vim: set ts=4 sw=4: diff --git a/include/utils/hash.h b/include/utils/hash.h index a247590..27c36c5 100644 --- a/include/utils/hash.h +++ b/include/utils/hash.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/utils/http.h b/include/utils/http.h index 38d4511..5e877bb 100644 --- a/include/utils/http.h +++ b/include/utils/http.h @@ -1,3 +1,25 @@ +/** + * \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 __UTILS_HTTP_H__ #define __UTILS_HTTP_H__ diff --git a/include/utils/memory.h b/include/utils/memory.h index 4755cac..2e9b65a 100644 --- a/include/utils/memory.h +++ b/include/utils/memory.h @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/include/utils/signalHandling.h b/include/utils/signalHandling.h index 269d1fe..cd1c973 100644 --- a/include/utils/signalHandling.h +++ b/include/utils/signalHandling.h @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/Makefile.am b/src/Makefile.am index 3abd3d2..4e0f9ff 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,71 +1,31 @@ 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 -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 +IFACE = interface/subject.c \ + interface/observer.c +UTILS = utils/hash.c \ + utils/memory.c \ + utils/http.c \ + utils/daemonize.c \ + utils/signalHandling.c +LIBS = ./http/libhttp.a \ + ./auth/libauth.a \ + ./cbuf/libcbuf.a \ + ./class/libclass.a \ + ./hash/libhash.a \ + ./logger/liblogger.a \ + ./server/libserver.a \ + ./session/libsession.a \ + ./socket/libsocket.a \ + ./stream/libstream.a AM_CFLAGS = -Wall -I ../include/ bin_PROGRAMS = webgameserver -webgameserver_SOURCES = webgameserver.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 +webgameserver_SOURCES = webgameserver.c $(IFACE) $(UTILS) +webgameserver_CFLAGS = -Wall -I ../include/# $(COVERAGE_CFLAGS) +webgameserver_LDADD = $(LIBS) -lrt -lssl -lldap +#webgameserver_LDFLAGS = $(COVERAGE_LDFLAGS) + +SUBDIRS = auth cbuf class hash http logger server session socket stream diff --git a/src/auth/Makefile.am b/src/auth/Makefile.am new file mode 100644 index 0000000..f35a61c --- /dev/null +++ b/src/auth/Makefile.am @@ -0,0 +1,6 @@ +ACLOCAL_AMFLAGS = -I m4 + +noinst_LIBRARIES = libauth.a + +libauth_a_SOURCES = interface/auth.c credential.c ldap.c +libauth_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/credential.c b/src/auth/credential.c similarity index 62% rename from src/credential.c rename to src/auth/credential.c index e2ea93d..f5c3ef1 100644 --- a/src/credential.c +++ b/src/auth/credential.c @@ -1,14 +1,35 @@ +/** + * \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 "credential.h" #include "class.h" -#include "interface/class.h" - #include "utils/memory.h" +#include "auth/credential.h" + static int credentialCtor(void * _this, va_list * params) diff --git a/src/interface/auth.c b/src/auth/interface/auth.c similarity index 91% rename from src/interface/auth.c rename to src/auth/interface/auth.c index bc2e1bc..fa98183 100644 --- a/src/interface/auth.c +++ b/src/auth/interface/auth.c @@ -20,9 +20,9 @@ * along with this program. If not, see . */ -#include "auth.h" -#include "credential.h" -#include "interface/auth.h" +#include "auth/auth.h" +#include "auth/credential.h" +#include "auth/interface/auth.h" const struct interface i_Auth = { "auth", diff --git a/src/auth/ldap.c b/src/auth/ldap.c index d4fd81f..3ac2cfd 100644 --- a/src/auth/ldap.c +++ b/src/auth/ldap.c @@ -1,18 +1,39 @@ +/** + * \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 "auth/ldap.h" #include "class.h" -#include "credential.h" -#include "interface/class.h" -#include "interface/auth.h" - #include "utils/memory.h" #include "commons.h" +#include "auth/ldap.h" +#include "auth/credential.h" +#include "auth/interface/auth.h" + static int authLdapCtor(void * _this, va_list * params) diff --git a/src/cbuf/Makefile.am b/src/cbuf/Makefile.am new file mode 100644 index 0000000..c9d9f29 --- /dev/null +++ b/src/cbuf/Makefile.am @@ -0,0 +1,13 @@ +ACLOCAL_AMFLAGS = -I m4 + +CB = cbuf.c read.c write.c \ + get_line.c set_data.c get_data.c \ + addr_index.c get_free.c get_read.c get_write.c \ + inc_read.c inc_write.c is_empty.c memchr.c \ + skip_non_alpha.c is_locked.c lock.c release.c \ + empty.c + +noinst_LIBRARIES = libcbuf.a + +libcbuf_a_SOURCES = $(CB) +libcbuf_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/cbuf/addr_index.c b/src/cbuf/addr_index.c index f66df81..69eb5e6 100644 --- a/src/cbuf/addr_index.c +++ b/src/cbuf/addr_index.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf.c b/src/cbuf/cbuf.c similarity index 97% rename from src/cbuf.c rename to src/cbuf/cbuf.c index 4d05fa5..0ee216d 100644 --- a/src/cbuf.c +++ b/src/cbuf/cbuf.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -34,7 +34,6 @@ #include #include "class.h" -#include "interface/class.h" #include "utils/memory.h" #include "cbuf.h" diff --git a/src/cbuf/empty.c b/src/cbuf/empty.c index 02196de..b41a6a3 100644 --- a/src/cbuf/empty.c +++ b/src/cbuf/empty.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/get_data.c b/src/cbuf/get_data.c index c5191f3..b41f5b8 100644 --- a/src/cbuf/get_data.c +++ b/src/cbuf/get_data.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/get_free.c b/src/cbuf/get_free.c index eb747fd..1117081 100644 --- a/src/cbuf/get_free.c +++ b/src/cbuf/get_free.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/get_line.c b/src/cbuf/get_line.c index 526c22a..647722f 100644 --- a/src/cbuf/get_line.c +++ b/src/cbuf/get_line.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/get_read.c b/src/cbuf/get_read.c index 6464b08..cbbbdc3 100644 --- a/src/cbuf/get_read.c +++ b/src/cbuf/get_read.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/get_write.c b/src/cbuf/get_write.c index dbd2dc3..02f1a55 100644 --- a/src/cbuf/get_write.c +++ b/src/cbuf/get_write.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/inc_read.c b/src/cbuf/inc_read.c index 869a780..bfd6dab 100644 --- a/src/cbuf/inc_read.c +++ b/src/cbuf/inc_read.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/inc_write.c b/src/cbuf/inc_write.c index 1221493..f329813 100644 --- a/src/cbuf/inc_write.c +++ b/src/cbuf/inc_write.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/is_empty.c b/src/cbuf/is_empty.c index 799ced6..849c032 100644 --- a/src/cbuf/is_empty.c +++ b/src/cbuf/is_empty.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/is_locked.c b/src/cbuf/is_locked.c index fa5a2c3..097bd69 100644 --- a/src/cbuf/is_locked.c +++ b/src/cbuf/is_locked.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/lock.c b/src/cbuf/lock.c index e1579e4..df5256f 100644 --- a/src/cbuf/lock.c +++ b/src/cbuf/lock.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/memchr.c b/src/cbuf/memchr.c index 58894fa..0183351 100644 --- a/src/cbuf/memchr.c +++ b/src/cbuf/memchr.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/read.c b/src/cbuf/read.c index a68eb07..1e49fa0 100644 --- a/src/cbuf/read.c +++ b/src/cbuf/read.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/release.c b/src/cbuf/release.c index 8a3edac..eb32a73 100644 --- a/src/cbuf/release.c +++ b/src/cbuf/release.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/set_data.c b/src/cbuf/set_data.c index 0e3055e..514d052 100644 --- a/src/cbuf/set_data.c +++ b/src/cbuf/set_data.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/skip_non_alpha.c b/src/cbuf/skip_non_alpha.c index 72ef3aa..395c296 100644 --- a/src/cbuf/skip_non_alpha.c +++ b/src/cbuf/skip_non_alpha.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/cbuf/write.c b/src/cbuf/write.c index 01c26b1..03820aa 100644 --- a/src/cbuf/write.c +++ b/src/cbuf/write.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/class/Makefile.am b/src/class/Makefile.am new file mode 100644 index 0000000..2b5b0ad --- /dev/null +++ b/src/class/Makefile.am @@ -0,0 +1,6 @@ +ACLOCAL_AMFLAGS = -I m4 + +noinst_LIBRARIES = libclass.a + +libclass_a_SOURCES = interface.c interface/i_class.c +libclass_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/interface.c b/src/class/interface.c similarity index 89% rename from src/interface.c rename to src/class/interface.c index 04ef14a..661561b 100644 --- a/src/interface.c +++ b/src/class/interface.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -23,7 +23,7 @@ #include #include -#include "interface.h" +#include "class/interface.h" #include "commons.h" static @@ -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/class/interface/i_class.c similarity index 93% rename from src/interface/class.c rename to src/class/interface/i_class.c index 8327e89..0113902 100644 --- a/src/interface/class.c +++ b/src/class/interface/i_class.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,8 +24,8 @@ #include #include -#include "class.h" -#include "interface/class.h" +#include "class/class.h" +#include "class/interface/class.h" const struct interface i_Class = { @@ -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/src/hash.c b/src/hash.c deleted file mode 100644 index ce26584..0000000 --- a/src/hash.c +++ /dev/null @@ -1,42 +0,0 @@ -#define _GNU_SOURCE - -#include -#include - -#include "hash.h" -#include "class.h" -#include "interface/class.h" - -static -int -hashCtor(void * _this, va_list * params) -{ - return 0; -} - -static -inline -void -tDelete(void * node) -{ - delete(node); -} - -static -void -hashDtor(void * _this) -{ - Hash this = _this; - - /** - * this is a GNU extension...anyway on most non - * GNUish systems i would not use tsearch anyway - * as the trees will be unbalanced. - */ - tdestroy(this->root, tDelete); -} - -INIT_IFACE(Class, hashCtor, hashDtor, NULL); -CREATE_CLASS(Hash, NULL, IFACE(Class)); - -// vim: set ts=4 sw=4: diff --git a/src/hash/Makefile.am b/src/hash/Makefile.am new file mode 100644 index 0000000..8eb86ff --- /dev/null +++ b/src/hash/Makefile.am @@ -0,0 +1,9 @@ +ACLOCAL_AMFLAGS = -I m4 + +HASH = hash.c add.c get.c delete.c each.c value.c \ + interface/hashable.c + +noinst_LIBRARIES = libhash.a + +libhash_a_SOURCES = $(HASH) +libhash_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/hash/add.c b/src/hash/add.c index 330d158..7613034 100644 --- a/src/hash/add.c +++ b/src/hash/add.c @@ -1,8 +1,29 @@ +/** + * \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 "hash.h" -#include "interface/hashable.h" -#include "interface/class.h" +#include "class.h" static inline diff --git a/src/hash/delete.c b/src/hash/delete.c index b48f06a..1731fbe 100644 --- a/src/hash/delete.c +++ b/src/hash/delete.c @@ -1,8 +1,29 @@ +/** + * \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 "hash.h" -#include "interface/hashable.h" #include "utils/hash.h" static diff --git a/src/hash/each.c b/src/hash/each.c index 1fa06c7..4df28d1 100644 --- a/src/hash/each.c +++ b/src/hash/each.c @@ -1,3 +1,25 @@ +/** + * \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 "hash.h" diff --git a/src/hash/get.c b/src/hash/get.c index 97b08de..2d64514 100644 --- a/src/hash/get.c +++ b/src/hash/get.c @@ -1,8 +1,29 @@ +/** + * \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 "hash.h" -#include "interface/hashable.h" #include "utils/hash.h" static diff --git a/src/hash/hash.c b/src/hash/hash.c new file mode 100644 index 0000000..ba8cba2 --- /dev/null +++ b/src/hash/hash.c @@ -0,0 +1,63 @@ +/** + * \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 . + */ + +#define _GNU_SOURCE + +#include +#include + +#include "hash/hash.h" +#include "class.h" + +static +int +hashCtor(void * _this, va_list * params) +{ + return 0; +} + +static +inline +void +tDelete(void * node) +{ + delete(node); +} + +static +void +hashDtor(void * _this) +{ + Hash this = _this; + + /** + * this is a GNU extension...anyway on most non + * GNUish systems i would not use tsearch anyway + * as the trees will be unbalanced. + */ + tdestroy(this->root, tDelete); +} + +INIT_IFACE(Class, hashCtor, hashDtor, NULL); +CREATE_CLASS(Hash, NULL, IFACE(Class)); + +// vim: set ts=4 sw=4: diff --git a/src/interface/hashable.c b/src/hash/interface/hashable.c similarity index 96% rename from src/interface/hashable.c rename to src/hash/interface/hashable.c index 7e4b280..0113388 100644 --- a/src/interface/hashable.c +++ b/src/hash/interface/hashable.c @@ -25,7 +25,7 @@ #include #include "class.h" -#include "interface/hashable.h" +#include "hash/interface/hashable.h" const struct interface i_Hashable = { "hashable", diff --git a/src/hash_value.c b/src/hash/value.c similarity index 67% rename from src/hash_value.c rename to src/hash/value.c index 340a0ce..c32b760 100644 --- a/src/hash_value.c +++ b/src/hash/value.c @@ -1,14 +1,37 @@ +/** + * \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 "hash_value.h" +#include "class.h" #include "utils/hash.h" #include "utils/memory.h" #include "commons.h" -#include "interface/class.h" -#include "interface/hashable.h" + +#include "hash/value.h" +#include "hash/interface/hashable.h" static int diff --git a/src/http/Makefile.am b/src/http/Makefile.am new file mode 100644 index 0000000..e6b2ace --- /dev/null +++ b/src/http/Makefile.am @@ -0,0 +1,41 @@ +ACLOCAL_AMFLAGS = -I m4 + +MSG = message.c \ + message/has_keep_alive.c \ + message/header_size_get.c \ + message/header_to_string.c \ + message/get_version.c \ + message/has_valid_version.c +MSGQ = message/queue.c +REQ = request.c \ + request/has_valid_method.c +RESP = response.c \ + response/304.c \ + response/404.c \ + response/403.c \ + response/login_form.c \ + response/asset.c \ + response/randval.c \ + response/session.c +PARSER = parser.c \ + parser/parse.c \ + parser/new_message.c \ + parser/p_header.c \ + parser/p_body.c \ + parser/p_request_vars.c \ + parser/p_post_vars.c +WRITER = writer.c \ + writer/write.c +WORKER = worker.c \ + worker/process.c \ + worker/answer.c \ + worker/get_asset.c \ + worker/add_common_header.c +HEADER = header.c \ + header/to_string.c + +noinst_LIBRARIES = libhttp.a + +libhttp_a_SOURCES = $(MSG) $(MSGQ) $(REQ) $(RESP) $(PARSER) $(WRITER) \ + $(WORKER) $(HEADER) interface/i_http_intro.c +libhttp_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/http/cookie.c b/src/http/cookie.c index 8faff71..8b0a50b 100644 --- a/src/http/cookie.c +++ b/src/http/cookie.c @@ -1,11 +1,33 @@ +/** + * \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 "cookie.h" -#include "interface/class.h" -#include "interface/hashable" +#include "class.h" +#include "hash.h" +#include "http/cookie.h" #include "utils/hash.h" #include "utils/memory.h" diff --git a/src/http/header.c b/src/http/header.c index 0f66f15..42ecfd9 100644 --- a/src/http/header.c +++ b/src/http/header.c @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -25,9 +25,8 @@ #include #include "class.h" -#include "interface/class.h" +#include "hash.h" #include "http/header.h" -#include "interface/hashable.h" #include "utils/hash.h" #include "utils/memory.h" diff --git a/src/http/header/to_string.c b/src/http/header/to_string.c index 124e804..089ee51 100644 --- a/src/http/header/to_string.c +++ b/src/http/header/to_string.c @@ -5,7 +5,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/interface/http_intro.c b/src/http/interface/i_http_intro.c similarity index 96% rename from src/interface/http_intro.c rename to src/http/interface/i_http_intro.c index bf14c4d..125f475 100644 --- a/src/interface/http_intro.c +++ b/src/http/interface/i_http_intro.c @@ -21,7 +21,7 @@ */ #include "class.h" -#include "interface/http_intro.h" +#include "http/interface/http_intro.h" const struct interface i_HttpIntro = { "httpIntro", diff --git a/src/http/message.c b/src/http/message.c index d0bb0ed..5786b76 100644 --- a/src/http/message.c +++ b/src/http/message.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -31,7 +31,6 @@ #include #include "class.h" -#include "interface/class.h" #include "hash.h" #include "http/message.h" #include "utils/memory.h" @@ -47,8 +46,7 @@ httpMessageCtor(void * _this, va_list * params) this->version = calloc(1, strlen(version)+1); strcpy(this->version, version); - this->header = new(Hash); - this->cookies = new(Hash); + this->header = new(Hash); return 0; } @@ -60,7 +58,6 @@ httpMessageDtor(void * _this) HttpMessage this = _this; delete(this->header); - delete(this->cookies); FREE(this->version); diff --git a/src/http/message/get_version.c b/src/http/message/get_version.c index be83528..0db7d99 100644 --- a/src/http/message/get_version.c +++ b/src/http/message/get_version.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/http/message/has_keep_alive.c b/src/http/message/has_keep_alive.c index d6aab1d..136b673 100644 --- a/src/http/message/has_keep_alive.c +++ b/src/http/message/has_keep_alive.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/http/message/has_valid_version.c b/src/http/message/has_valid_version.c index 1195995..c72e7b1 100644 --- a/src/http/message/has_valid_version.c +++ b/src/http/message/has_valid_version.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/http/message/header_size_get.c b/src/http/message/header_size_get.c index dc0a70d..59b10b3 100644 --- a/src/http/message/header_size_get.c +++ b/src/http/message/header_size_get.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -27,7 +27,7 @@ #include "http/message.h" #include "http/response.h" #include "http/header.h" -#include "interface/http_intro.h" +#include "http/interface/http_intro.h" #include "hash.h" static size_t size; diff --git a/src/http/message/header_to_string.c b/src/http/message/header_to_string.c index a4a8707..37a2814 100644 --- a/src/http/message/header_to_string.c +++ b/src/http/message/header_to_string.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -26,7 +26,7 @@ #include "http/response.h" #include "http/header.h" -#include "interface/http_intro.h" +#include "http/interface/http_intro.h" #include "hash.h" static char * string; diff --git a/src/http/message/queue.c b/src/http/message/queue.c index f6c3ff5..72dcf34 100644 --- a/src/http/message/queue.c +++ b/src/http/message/queue.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -23,7 +23,6 @@ #include #include "class.h" -#include "interface/class.h" #include "http/message/queue.h" diff --git a/src/http/parser.c b/src/http/parser.c index d294a67..d5b227a 100644 --- a/src/http/parser.c +++ b/src/http/parser.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -25,8 +25,7 @@ #include #include "class.h" -#include "interface/class.h" -#include "interface/stream_reader.h" +#include "stream.h" #include "http/parser.h" #include "http/message/queue.h" diff --git a/src/http/parser/new_message.c b/src/http/parser/new_message.c index 5c392fc..e265a9c 100644 --- a/src/http/parser/new_message.c +++ b/src/http/parser/new_message.c @@ -1,3 +1,25 @@ +/** + * \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 "http/parser.h" #include "utils/http.h" diff --git a/src/http/parser/body.c b/src/http/parser/p_body.c similarity index 97% rename from src/http/parser/body.c rename to src/http/parser/p_body.c index 310203e..07b3162 100644 --- a/src/http/parser/body.c +++ b/src/http/parser/p_body.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/http/parser/header.c b/src/http/parser/p_header.c similarity index 96% rename from src/http/parser/header.c rename to src/http/parser/p_header.c index e902c99..2272362 100644 --- a/src/http/parser/header.c +++ b/src/http/parser/p_header.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -25,13 +25,11 @@ #include #include "class.h" -#include "interface/class.h" #include "http/header.h" #include "http/parser.h" #include "http/message.h" #include "http/request.h" #include "hash.h" -#include "hash_value.h" #define MAX(x,y) ((x) > (y) ? (x) : (y)) diff --git a/src/http/parser/post_vars.c b/src/http/parser/p_post_vars.c similarity index 56% rename from src/http/parser/post_vars.c rename to src/http/parser/p_post_vars.c index 27ac86f..b266940 100644 --- a/src/http/parser/post_vars.c +++ b/src/http/parser/p_post_vars.c @@ -1,11 +1,32 @@ +/** + * \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 "http/parser.h" #include "http/request.h" -#include "hash_value.h" #include "hash.h" -#include "interface/class.h" +#include "class.h" /** * \todo this is very similar to other pair parsing diff --git a/src/http/parser/request_vars.c b/src/http/parser/p_request_vars.c similarity index 55% rename from src/http/parser/request_vars.c rename to src/http/parser/p_request_vars.c index a524e64..fbcf192 100644 --- a/src/http/parser/request_vars.c +++ b/src/http/parser/p_request_vars.c @@ -1,12 +1,33 @@ +/** + * \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 "http/parser.h" #include "http/request.h" -#include "hash_value.h" #include "hash.h" -#include "interface/class.h" +#include "class.h" void httpParserRequestVars(HttpParser this) diff --git a/src/http/parser/parse.c b/src/http/parser/parse.c index 7ff1804..39eb16b 100644 --- a/src/http/parser/parse.c +++ b/src/http/parser/parse.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -22,13 +22,14 @@ #include -#include "http/parser.h" -#include "http/header.h" -#include "interface/class.h" -#include "interface/http_intro.h" +#include "class.h" #include "cbuf.h" #include "stream.h" +#include "http/parser.h" +#include "http/header.h" +#include "http/interface/http_intro.h" + #include "utils/memory.h" #include "commons.h" @@ -166,16 +167,16 @@ httpParserParse(void * _this, Stream st) httpParserPostVars(this); } - /** - * enqueue current request - */ - this->queue->msgs[(this->queue->nmsgs)++] = this->current; - this->current = NULL; + /** + * enqueue current request + */ + this->queue->msgs[(this->queue->nmsgs)++] = this->current; + this->current = NULL; - /** - * prepare for next request - */ - this->state = HTTP_MESSAGE_GARBAGE; + /** + * prepare for next request + */ + this->state = HTTP_MESSAGE_GARBAGE; } break; diff --git a/src/http/request.c b/src/http/request.c index 2304be0..b380301 100644 --- a/src/http/request.c +++ b/src/http/request.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -26,8 +26,8 @@ #include #include "class.h" -#include "interface/class.h" -#include "interface/http_intro.h" +#include "hash.h" +#include "http/interface/http_intro.h" #include "http/request.h" #include "utils/memory.h" diff --git a/src/http/request/has_valid_method.c b/src/http/request/has_valid_method.c index 08a02be..c44dcc3 100644 --- a/src/http/request/has_valid_method.c +++ b/src/http/request/has_valid_method.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/http/response.c b/src/http/response.c index b35e7b9..db53354 100644 --- a/src/http/response.c +++ b/src/http/response.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -27,11 +27,10 @@ #include #include "class.h" -#include "interface/class.h" -#include "interface/http_intro.h" +#include "utils/memory.h" #include "http/response.h" -#include "utils/memory.h" +#include "http/interface/http_intro.h" static diff --git a/src/http/response/304.c b/src/http/response/304.c index 694a4da..81519a7 100644 --- a/src/http/response/304.c +++ b/src/http/response/304.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -23,7 +23,6 @@ #include #include "class.h" -#include "interface/class.h" #include "http/response.h" #include "http/message.h" diff --git a/src/http/response/403.c b/src/http/response/403.c index ded0e4d..b1ef08f 100644 --- a/src/http/response/403.c +++ b/src/http/response/403.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -26,7 +26,6 @@ #include #include "class.h" -#include "interface/class.h" #include "http/response.h" #include "http/message.h" diff --git a/src/http/response/404.c b/src/http/response/404.c index e80c0f9..1947de1 100644 --- a/src/http/response/404.c +++ b/src/http/response/404.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -26,7 +26,6 @@ #include #include "class.h" -#include "interface/class.h" #include "http/response.h" #include "http/message.h" diff --git a/src/http/response/asset.c b/src/http/response/asset.c index d7e4b6f..e2bc0cc 100644 --- a/src/http/response/asset.c +++ b/src/http/response/asset.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -27,7 +27,6 @@ #include #include "class.h" -#include "interface/class.h" #include "stream.h" #include "http/response.h" diff --git a/src/http/response/login_form.c b/src/http/response/login_form.c index 4086565..f01063d 100644 --- a/src/http/response/login_form.c +++ b/src/http/response/login_form.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -27,7 +27,6 @@ #include #include "class.h" -#include "interface/class.h" #include "http/response.h" #include "http/message.h" diff --git a/src/http/response/randval.c b/src/http/response/randval.c index a01b2a4..b98449e 100644 --- a/src/http/response/randval.c +++ b/src/http/response/randval.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -27,7 +27,6 @@ #include #include "class.h" -#include "interface/class.h" #include "http/response.h" #include "http/message.h" diff --git a/src/http/response/session.c b/src/http/response/session.c index fd9b56e..396b6a6 100644 --- a/src/http/response/session.c +++ b/src/http/response/session.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -27,7 +27,6 @@ #include #include "class.h" -#include "interface/class.h" #include "http/response.h" #include "http/message.h" diff --git a/src/http/worker.c b/src/http/worker.c index cd96685..b74eb54 100644 --- a/src/http/worker.c +++ b/src/http/worker.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -34,10 +34,6 @@ #include "http/parser.h" #include "http/writer.h" -#include "interface/class.h" -#include "interface/stream_reader.h" -#include "interface/stream_writer.h" - #include "utils/memory.h" static @@ -63,7 +59,6 @@ httpWorkerCtor(void * _this, va_list * params) this->writer = new(HttpWriter, this->wbuf); this->sroot = &(this->session); - this->auth = va_arg(* params, void *); return 0; diff --git a/src/http/worker/add_common_header.c b/src/http/worker/add_common_header.c index 6c9d8bd..981c4da 100644 --- a/src/http/worker/add_common_header.c +++ b/src/http/worker/add_common_header.c @@ -1,8 +1,29 @@ +/** + * \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 "class.h" -#include "interface/class.h" #include "http/message.h" #include "http/header.h" diff --git a/src/http/worker/write.c b/src/http/worker/answer.c similarity index 96% rename from src/http/worker/write.c rename to src/http/worker/answer.c index ca1889c..1316414 100644 --- a/src/http/worker/write.c +++ b/src/http/worker/answer.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/http/worker/get_asset.c b/src/http/worker/get_asset.c index 7ea6a52..36f69ce 100644 --- a/src/http/worker/get_asset.c +++ b/src/http/worker/get_asset.c @@ -1,3 +1,25 @@ +/** + * \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 "http/header.h" diff --git a/src/http/worker/process.c b/src/http/worker/process.c index bfa60bf..3d9b7d7 100644 --- a/src/http/worker/process.c +++ b/src/http/worker/process.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -28,8 +28,7 @@ #include #include "class.h" -#include "interface/class.h" -#include "interface/auth.h" +#include "auth.h" #include "http/worker.h" #include "http/header.h" @@ -40,9 +39,7 @@ #include "http/parser.h" #include "session.h" #include "stream.h" -#include "hash_value.h" #include "hash.h" -#include "credential.h" #include "utils/memory.h" #include "hash.h" @@ -79,11 +76,11 @@ httpWorkerProcess(HttpWorker this, Stream st) if (NULL == this->session) { HashValue sidstr = hashGet(request->cookies, CSTRA("sid")); - if (NULL != sidstr) { - unsigned long sid; + if (NULL != sidstr) { + unsigned long sid; sid = strtoul((char*)(sidstr->value), NULL, 10); - this->session = sessionGet(this->sroot, sid); + this->session = sessionGet(this->sroot, sid); } } @@ -130,8 +127,8 @@ httpWorkerProcess(HttpWorker this, Stream st) response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden"); } else { if (NULL == this->session) { - this->session = sessionAdd( - this->sroot, + this->session = sessionAdd( + this->sroot, new(Session, username->value, username->nvalue)); diff --git a/src/http/writer.c b/src/http/writer.c index 00104e9..612c574 100644 --- a/src/http/writer.c +++ b/src/http/writer.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -23,8 +23,7 @@ #include #include "class.h" -#include "interface/class.h" -#include "interface/stream_writer.h" +#include "stream.h" #include "http/message/queue.h" #include "http/writer.h" diff --git a/src/http/writer/write.c b/src/http/writer/write.c index 75d1dbc..5942242 100644 --- a/src/http/writer/write.c +++ b/src/http/writer/write.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,7 +24,6 @@ #include #include "class.h" -#include "interface/class.h" #include "http/message.h" #include "http/writer.h" #include "cbuf.h" diff --git a/src/interface/observer.c b/src/interface/observer.c index b2424e7..7775c6b 100644 --- a/src/interface/observer.c +++ b/src/interface/observer.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/logger/Makefile.am b/src/logger/Makefile.am new file mode 100644 index 0000000..261a0b9 --- /dev/null +++ b/src/logger/Makefile.am @@ -0,0 +1,6 @@ +ACLOCAL_AMFLAGS = -I m4 + +noinst_LIBRARIES = liblogger.a + +liblogger_a_SOURCES = interface/i_logger.c logger.c stderr.c syslog.c +liblogger_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/interface/logger.c b/src/logger/interface/i_logger.c similarity index 93% rename from src/interface/logger.c rename to src/logger/interface/i_logger.c index bb2a75e..1ab7c2d 100644 --- a/src/interface/logger.c +++ b/src/logger/interface/i_logger.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,8 +24,8 @@ #include #include -#include "logger.h" -#include "interface/logger.h" +#include "logger/logger.h" +#include "logger/interface/logger.h" const struct interface i_Logger = { "logger", diff --git a/src/logger.c b/src/logger/logger.c similarity index 90% rename from src/logger.c rename to src/logger/logger.c index 859ceed..4d8ab63 100644 --- a/src/logger.c +++ b/src/logger/logger.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -22,9 +22,9 @@ #include -#include "logger.h" -#include "interface/class.h" -#include "interface/logger.h" +#include "class.h" +#include "logger/logger.h" +#include "logger/interface/logger.h" const char * const diff --git a/src/logger/stderr.c b/src/logger/stderr.c index dd26e1b..8df121e 100644 --- a/src/logger/stderr.c +++ b/src/logger/stderr.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -22,8 +22,8 @@ #include -#include "logger.h" -#include "interface/logger.h" +#include "logger/logger.h" +#include "logger/interface/logger.h" static void diff --git a/src/logger/syslog.c b/src/logger/syslog.c index 3667606..4f331ac 100644 --- a/src/logger/syslog.c +++ b/src/logger/syslog.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -22,8 +22,8 @@ #include -#include "logger.h" -#include "interface/logger.h" +#include "logger/logger.h" +#include "logger/interface/logger.h" static const diff --git a/src/server/Makefile.am b/src/server/Makefile.am new file mode 100644 index 0000000..a73bb16 --- /dev/null +++ b/src/server/Makefile.am @@ -0,0 +1,9 @@ +ACLOCAL_AMFLAGS = -I m4 + +SERVER = server.c run.c close_conn.c poll.c \ + handle_accept.c read.c write.c + +noinst_LIBRARIES = libserver.a + +libserver_a_SOURCES = $(SERVER) +libserver_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/server/close_conn.c b/src/server/close_conn.c index 1da15fc..33d2dd4 100644 --- a/src/server/close_conn.c +++ b/src/server/close_conn.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,7 +24,7 @@ #include #include "server.h" -#include "interface/class.h" +#include "class.h" #include "stream.h" void diff --git a/src/server/handle_accept.c b/src/server/handle_accept.c index ce17153..ab0cb83 100644 --- a/src/server/handle_accept.c +++ b/src/server/handle_accept.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -28,15 +28,15 @@ #include "http/worker.h" #include "server.h" -#include "interface/class.h" -#include "interface/logger.h" +#include "class.h" +#include "logger.h" #include "stream.h" int serverHandleAccept(Server this, unsigned int i) { char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - Sock acc = NULL; + Sock acc = NULL; Stream st; if (this->nfds >= this->max_fds) { @@ -46,25 +46,25 @@ serverHandleAccept(Server this, unsigned int i) acc = socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr); if (-1 != acc->handle) { - switch(i) { - case 0: - // no SSL - st = new(Stream, STREAM_FD, acc->handle); - break; - - case 1: - // SSL - { - SSL * ssl = SSL_new(this->ctx); - SSL_set_fd(ssl, acc->handle); - SSL_accept(ssl); - st = new(Stream, STREAM_SSL, ssl); - } - break; - - default: - break; - } + switch(i) { + case 0: + // no SSL + st = new(Stream, STREAM_FD, acc->handle); + break; + + case 1: + // SSL + { + SSL * ssl = SSL_new(this->ctx); + SSL_set_fd(ssl, acc->handle); + SSL_accept(ssl); + st = new(Stream, STREAM_SSL, ssl); + } + break; + + default: + break; + } // save the socket handle (this->conns)[acc->handle].sock = acc; diff --git a/src/server/poll.c b/src/server/poll.c index 0e97c61..cf061c8 100644 --- a/src/server/poll.c +++ b/src/server/poll.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,7 +24,7 @@ #include #include "server.h" -#include "interface/logger.h" +#include "logger.h" #include "utils/signalHandling.h" diff --git a/src/server/read.c b/src/server/read.c index 0eda967..a8add3e 100644 --- a/src/server/read.c +++ b/src/server/read.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -21,8 +21,8 @@ */ #include "server.h" -#include "interface/logger.h" -#include "interface/stream_reader.h" +#include "logger.h" +#include "stream.h" void serverCloseConn(Server, unsigned int); diff --git a/src/server/run.c b/src/server/run.c index 950a292..3ba416c 100644 --- a/src/server/run.c +++ b/src/server/run.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -21,7 +21,7 @@ */ #include "server.h" -#include "interface/logger.h" +#include "logger.h" #include "utils/signalHandling.h" diff --git a/src/server.c b/src/server/server.c similarity index 97% rename from src/server.c rename to src/server/server.c index 9e77d36..5f43eb0 100644 --- a/src/server.c +++ b/src/server/server.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -31,7 +31,6 @@ #include "server.h" #include "socket.h" #include "logger.h" -#include "interface/class.h" #include "utils/memory.h" diff --git a/src/server/write.c b/src/server/write.c index aa5e69a..cad36da 100644 --- a/src/server/write.c +++ b/src/server/write.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -21,8 +21,8 @@ */ #include "server.h" -#include "interface/logger.h" -#include "interface/stream_writer.h" +#include "logger.h" +#include "stream.h" void serverCloseConn(Server, unsigned int); diff --git a/src/session/Makefile.am b/src/session/Makefile.am new file mode 100644 index 0000000..7b6d884 --- /dev/null +++ b/src/session/Makefile.am @@ -0,0 +1,6 @@ +ACLOCAL_AMFLAGS = -I m4 + +noinst_LIBRARIES = libsession.a + +libsession_a_SOURCES = session.c add.c get.c delete.c +libsession_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/session/add.c b/src/session/add.c index 07adfa2..f6a9d2c 100644 --- a/src/session/add.c +++ b/src/session/add.c @@ -1,7 +1,29 @@ +/** + * \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 "session.h" -#include "interface/class.h" +#include "class.h" static diff --git a/src/session/delete.c b/src/session/delete.c index ef560ee..33d203d 100644 --- a/src/session/delete.c +++ b/src/session/delete.c @@ -1,7 +1,29 @@ +/** + * \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 "session.h" -#include "interface/class.h" +#include "class.h" static diff --git a/src/session/get.c b/src/session/get.c index 2b622ee..ed3734e 100644 --- a/src/session/get.c +++ b/src/session/get.c @@ -1,3 +1,25 @@ +/** + * \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 diff --git a/src/session.c b/src/session/session.c similarity index 52% rename from src/session.c rename to src/session/session.c index 698cc03..b768da4 100644 --- a/src/session.c +++ b/src/session/session.c @@ -1,3 +1,25 @@ +/** + * \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 @@ -7,7 +29,6 @@ #include "session.h" #include "class.h" -#include "interface/class.h" #include "utils/hash.h" #include "utils/memory.h" diff --git a/src/socket/Makefile.am b/src/socket/Makefile.am new file mode 100644 index 0000000..89ef4f0 --- /dev/null +++ b/src/socket/Makefile.am @@ -0,0 +1,6 @@ +ACLOCAL_AMFLAGS = -I m4 + +noinst_LIBRARIES = libsocket.a + +libsocket_a_SOURCES = socket.c accept.c connect.c listen.c +libsocket_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/socket/accept.c b/src/socket/accept.c index 3d97e20..28ce4bf 100644 --- a/src/socket/accept.c +++ b/src/socket/accept.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,8 +24,8 @@ #include #include "socket.h" -#include "interface/class.h" -#include "interface/logger.h" +#include "class.h" +#include "logger.h" Sock socketAccept(Sock this, char (*remoteAddr)[16]) diff --git a/src/socket/connect.c b/src/socket/connect.c index 66aa19c..6502288 100644 --- a/src/socket/connect.c +++ b/src/socket/connect.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,8 +24,8 @@ #include // for errno #include "socket.h" -#include "interface/class.h" -#include "interface/logger.h" +#include "class.h" +#include "logger.h" void diff --git a/src/socket/listen.c b/src/socket/listen.c index 4992058..aff5273 100644 --- a/src/socket/listen.c +++ b/src/socket/listen.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -24,8 +24,8 @@ #include // for errno #include "socket.h" -#include "interface/class.h" -#include "interface/logger.h" +#include "class.h" +#include "logger.h" void diff --git a/src/socket.c b/src/socket/socket.c similarity index 95% rename from src/socket.c rename to src/socket/socket.c index 3603513..ead4f00 100644 --- a/src/socket.c +++ b/src/socket/socket.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -26,8 +26,7 @@ #include "socket.h" #include "logger.h" -#include "interface/class.h" -#include "interface/logger.h" +#include "class.h" static int diff --git a/src/stream.c b/src/stream.c deleted file mode 100644 index 49cf067..0000000 --- a/src/stream.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - -#include "class.h" -#include "interface/class.h" -#include "stream.h" - - -static -int -streamCtor(void * _this, va_list * params) -{ - Stream this = _this; - this->type = va_arg(* params, StreamHandleType); - - switch(this->type) { - case STREAM_FD: - (this->handle).fd = va_arg(* params, int); - break; - - case STREAM_SSL: - (this->handle).ssl = va_arg(* params, SSL*); - break; - - default: - return -1; - } - - return 0; -} - -static -void -streamDtor(void * _this) -{ -} - -INIT_IFACE(Class, streamCtor, streamDtor, NULL); -CREATE_CLASS(Stream, NULL, IFACE(Class)); - -// vim: set ts=4 sw=4: diff --git a/src/stream/Makefile.am b/src/stream/Makefile.am new file mode 100644 index 0000000..bf8134e --- /dev/null +++ b/src/stream/Makefile.am @@ -0,0 +1,10 @@ +ACLOCAL_AMFLAGS = -I m4 + +STREAM = stream.c read.c write.c +IFACE = interface/reader.c \ + interface/writer.c + +noinst_LIBRARIES = libstream.a + +libstream_a_SOURCES = $(STREAM) $(IFACE) +libstream_a_CFLAGS = -Wall -I ../../include/ diff --git a/src/interface/stream_reader.c b/src/stream/interface/reader.c similarity index 90% rename from src/interface/stream_reader.c rename to src/stream/interface/reader.c index c23895e..abd042b 100644 --- a/src/interface/stream_reader.c +++ b/src/stream/interface/reader.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -21,8 +21,9 @@ */ #include "class.h" -#include "interface/stream_reader.h" -#include "stream.h" + +#include "stream/stream.h" +#include "stream/interface/reader.h" const struct interface i_StreamReader = { "streamReader", diff --git a/src/interface/stream_writer.c b/src/stream/interface/writer.c similarity index 90% rename from src/interface/stream_writer.c rename to src/stream/interface/writer.c index 8489a0d..1928328 100644 --- a/src/interface/stream_writer.c +++ b/src/stream/interface/writer.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 @@ -21,8 +21,9 @@ */ #include "class.h" -#include "interface/stream_writer.h" -#include "stream.h" + +#include "stream/stream.h" +#include "stream/interface/writer.h" const struct interface i_StreamWriter = { "streamWriter", diff --git a/src/stream/read.c b/src/stream/read.c index b7bb058..9050e65 100644 --- a/src/stream/read.c +++ b/src/stream/read.c @@ -1,3 +1,25 @@ +/** + * \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 diff --git a/src/stream/stream.c b/src/stream/stream.c new file mode 100644 index 0000000..e417cbc --- /dev/null +++ b/src/stream/stream.c @@ -0,0 +1,62 @@ +/** + * \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 "class.h" +#include "stream/stream.h" + + +static +int +streamCtor(void * _this, va_list * params) +{ + Stream this = _this; + this->type = va_arg(* params, StreamHandleType); + + switch(this->type) { + case STREAM_FD: + (this->handle).fd = va_arg(* params, int); + break; + + case STREAM_SSL: + (this->handle).ssl = va_arg(* params, SSL*); + break; + + default: + return -1; + } + + return 0; +} + +static +void +streamDtor(void * _this) +{ +} + +INIT_IFACE(Class, streamCtor, streamDtor, NULL); +CREATE_CLASS(Stream, NULL, IFACE(Class)); + +// vim: set ts=4 sw=4: diff --git a/src/stream/write.c b/src/stream/write.c index 475e9e9..540fade 100644 --- a/src/stream/write.c +++ b/src/stream/write.c @@ -1,3 +1,25 @@ +/** + * \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 diff --git a/src/utils/daemonize.c b/src/utils/daemonize.c index bdd61f5..6dd8318 100644 --- a/src/utils/daemonize.c +++ b/src/utils/daemonize.c @@ -6,7 +6,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/src/utils/hash.c b/src/utils/hash.c index dc6dcea..ea46085 100644 --- a/src/utils/hash.c +++ b/src/utils/hash.c @@ -1,3 +1,26 @@ +/** + * \file + * + * \author Georg Hopp + * \author Unknown (find out) + * + * \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 diff --git a/src/utils/http.c b/src/utils/http.c index 61e833b..e24ce9d 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -1,3 +1,25 @@ +/** + * \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 @@ -6,7 +28,7 @@ #include "http/request.h" #include "http/response.h" -#include "interface/class.h" +#include "class.h" #include "commons.h" diff --git a/src/utils/memory.c b/src/utils/memory.c index 853b613..8784759 100644 --- a/src/utils/memory.c +++ b/src/utils/memory.c @@ -1,3 +1,25 @@ +/** + * \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 "utils/memory.h" diff --git a/src/utils/signalHandling.c b/src/utils/signalHandling.c index 4771fa0..a0f11c0 100644 --- a/src/utils/signalHandling.c +++ b/src/utils/signalHandling.c @@ -4,7 +4,7 @@ * \author Georg Hopp * * \copyright - * Copyright (C) 2012 Georg Hopp + * 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 diff --git a/tests/Makefile.am b/tests/Makefile.am index d3c0391..18fb04c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,29 +1,71 @@ ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects TESTS_ENVIRONMENT = valgrind --error-exitcode=123 --leak-check=full --quiet -TESTS = cclassTest loggerTest socketTest serverTest -check_PROGRAMS = cclassTest loggerTest socketTest serverTest +TESTS = classTest loggerTest socketTest serverTest +check_PROGRAMS = classTest loggerTest socketTest serverTest -COMMON = runtest.c ../src/interface/class.c -CCLASS = $(COMMON) mock/class.c -LOGGER = $(COMMON) ../src/logger.c ../src/interface/logger.c \ - ../src/logger/stderr.c ../src/logger/syslog.c -SOCKET = $(LOGGER) ../src/socket.c ../src/socket/listen.c \ - ../src/socket/accept.c ../src/socket/connect.c -SERVER = $(SOCKET) ../src/server.c ../src/server/run.c \ - ../src/server/close_conn.c ../src/utils/signalHandling.c +COMMON = runtest.c +CLASS = $(COMMON) \ + ../src/class/interface.c \ + ../src/class/interface/i_class.c \ + mock/mock_class.c -cclassTest_SOURCES = $(CCLASS) cclassTest.c -cclassTest_CFLAGS = -Wall -ggdb -O0 -finline-functions -I ../include -I .. -I . +LOGGER = $(CLASS) \ + ../src/logger/logger.c \ + ../src/logger/stderr.c \ + ../src/logger/syslog.c \ + ../src/logger/interface/i_logger.c \ + mock/mock_logger.c + +SOCKET = $(LOGGER) \ + ../src/socket/socket.c \ + ../src/socket/listen.c \ + ../src/socket/accept.c \ + ../src/socket/connect.c + +STREAM_OBJ = ./stream/stream.o \ + ./stream/read.o \ + ./stream/write.o \ + ./stream/reader.o \ + ./stream/writer.o + +SERVER = $(SOCKET) \ + ../src/server/server.c \ + ../src/server/run.c \ + ../src/server/close_conn.c \ + ../src/server/handle_accept.c \ + ../src/server/poll.c \ + ../src/server/read.c \ + ../src/server/write.c \ + ../src/utils/signalHandling.c \ + ../src/utils/memory.c \ + mock/mock_worker.c + +classTest_SOURCES = $(CLASS) classTest.c +classTest_CFLAGS = -Wall -ggdb -O0 -fprofile-arcs -ftest-coverage -I ../include -I .. -I . +classTest_LDFLAGS = -lgcov loggerTest_SOURCES = $(LOGGER) loggerTest.c -loggerTest_CFLAGS = -Wall -ggdb -O0 -I ../include -I .. -I . +loggerTest_CFLAGS = -Wall -ggdb -O0 -fprofile-arcs -ftest-coverage -I ../include -I .. -I . +loggerTest_LDFLAGS = -lgcov socketTest_SOURCES = $(SOCKET) socketTest.c -socketTest_CFLAGS = -Wall -ggdb -O0 -I ../include -I .. -I . +socketTest_CFLAGS = -Wall -ggdb -O0 -fprofile-arcs -ftest-coverage -I ../include -I .. -I . +socketTest_LDFLAGS = -lgcov serverTest_SOURCES = $(SERVER) serverTest.c -serverTest_CFLAGS = -Wall -ggdb -O0 -I ../include -I .. -I . +serverTest_CFLAGS = -Wall -ggdb -O0 -fprofile-arcs -ftest-coverage -I ../include -I .. -I . +serverTest_LDFLAGS = $(STREAM_OBJ) -lgcov + +EXTRA_DIST = runtest.h mock/mock_class.h mock/mock_logger.h + +.PHONY: stream +stream: + $(MAKE) -C stream $(AM_MAKEFLAGS) + +$(check_PROGRAMS): stream +check-build: $(check_PROGRAMS) + +all-local: stream -EXTRA_DIST = runtest.h mock/class.h +SUBDIRS = stream diff --git a/tests/cclassTest.c b/tests/classTest.c similarity index 65% rename from tests/cclassTest.c rename to tests/classTest.c index 45f92a0..a9847e8 100644 --- a/tests/cclassTest.c +++ b/tests/classTest.c @@ -18,15 +18,15 @@ */ #include #include -#include #include "runtest.h" -#include "mock/class.h" -#include "cclass.h" +#include "mock/mock_class.h" + +#include "class.h" const char testname[] = "cclassTest"; -MOCK_CLASS mock = NULL; +MockClass mock = NULL; static int @@ -45,7 +45,7 @@ __tearDown() { if (NULL != mock) { ASSERT_OBJECT(mock); - delete(&mock); + delete(mock); } return TEST_OK; @@ -56,27 +56,22 @@ static int testNew(void) { - mock = new(MOCK_CLASS, 123); + mock = new(MockClass, 123); ASSERT_OBJECT_NOT_NULL(mock); ASSERT_EQUAL(1, _called); - ASSERT_EQUAL(123, mock_class_getValue(mock)); + ASSERT_EQUAL(123, mock->value); return TEST_OK; } static int -testNewFromJson(void) +testNewFail(void) { - struct json_object * json = json_object_new_int(123); - - mock = newFromJson(MOCK_CLASS, json); - json_object_put(json); + mock = new(MockClass, 321); - ASSERT_OBJECT_NOT_NULL(mock); - ASSERT_EQUAL(1, _called); - ASSERT_EQUAL(123, mock_class_getValue(mock)); + ASSERT_NULL(mock); return TEST_OK; } @@ -85,12 +80,12 @@ static int testDelete(void) { - mock = new(MOCK_CLASS, 123); + mock = new(MockClass, 123); ASSERT_NOT_NULL(mock); _reset(); - delete(&mock); + delete(mock); ASSERT_NULL(mock); ASSERT_EQUAL(1, _called); @@ -100,31 +95,26 @@ testDelete(void) static int -testToJson(void) +testClone(void) { - struct json_object * json = NULL; - mock = new(MOCK_CLASS, 123); - int value; - - _reset(); - toJson(mock, &json); + MockClass clone; - ASSERT_NOT_NULL(json); + mock = new(MockClass, 123); + clone = clone(mock); - value = json_object_get_int(json); - json_object_put(json); + ASSERT_INSTANCE_OF(MockClass, clone); + ASSERT_EQUAL(mock->value, clone->value); - ASSERT_EQUAL(123, value); - ASSERT_EQUAL(1, _called); + delete(clone); return TEST_OK; } const testfunc tests[] = { testNew, - testNewFromJson, + testNewFail, testDelete, - testToJson + testClone }; const size_t count = FUNCS_COUNT(tests); diff --git a/tests/loggerTest.c b/tests/loggerTest.c index 2727a47..acf6bff 100644 --- a/tests/loggerTest.c +++ b/tests/loggerTest.c @@ -21,73 +21,94 @@ #include #include "runtest.h" -#include "cclass.h" +#include "class.h" #include "logger.h" +#include "mock/mock_logger.h" -int level = -1; -char * msg = NULL; +const char testname[] = "loggerTest"; +Logger logger = NULL; + -static void -logfnct_mock(int _level, const char * _msg) +static +int +__setUp() { - level = _level; - msg = malloc(strlen(_msg) + 1); - strcpy(msg, _msg); + return TEST_OK; } +int (* const setUp)() = __setUp; -const char testname[] = "loggerTest"; -LOGGER logger = NULL; +static +int +__tearDown() +{ + if (NULL != logger) { + ASSERT_OBJECT(logger); + delete(logger); + } + return TEST_OK; +} +int (* const tearDown)() = __tearDown; static int -__setUp() +testLoggerLevel() { - logger = new(LOGGER, NULL); + logger = new(MockLogger, LOGGER_ERR); - ASSERT_INSTANCE_OF(LOGGER, logger); + ASSERT_INSTANCE_OF(MockLogger, logger); + ASSERT_EQUAL(LOGGER_ERR, logger->min_level); - logger_add(logger, logfnct_mock); + loggerLog(logger, LOGGER_WARNING, "foo %d %s", 123, "bar"); + + ASSERT_STRING_EQUAL("", ((MockLogger)logger)->message); + + loggerLog(logger, LOGGER_ERR, "foo %d %s", 123, "bar"); + ASSERT_STRING_EQUAL("[ERR] foo 123 bar", ((MockLogger)logger)->message); + + mockLoggerCleanMsg((MockLogger)logger); + loggerLog(logger, LOGGER_CRIT, "foo %d %s", 123, "bar"); + ASSERT_STRING_EQUAL("[CRIT] foo 123 bar", ((MockLogger)logger)->message); return TEST_OK; } -int (* const setUp)() = __setUp; static int -__tearDown() +testLoggerStderr() { - level = -1; + logger = new(LoggerStderr, LOGGER_ERR); - if (NULL != msg) { - free(msg); - msg = NULL; - } + freopen("/dev/null", "w", stderr); + loggerLog(logger, LOGGER_ERR, "foo %d %s", 123, "bar"); - if (NULL != logger) { - ASSERT_OBJECT(logger); - delete(&logger); - } + /** + * \todo think about a way to assert something here + */ return TEST_OK; } -int (* const tearDown)() = __tearDown; static int -testLogger() +testLoggerSyslog() { - logger_log(logger, LOGGER_ERR, "foo %d %s", 123, "bar"); + logger = new(LoggerSyslog, LOGGER_ERR); + + loggerLog(logger, LOGGER_ERR, "foo %d %s", 123, "bar"); - ASSERT_EQUAL(LOGGER_ERR, level); - ASSERT_STRING_EQUAL("foo 123 bar", msg); + /** + * \todo think about a way to assert something here + */ return TEST_OK; } const testfunc tests[] = { - testLogger + testLoggerLevel, + testLoggerStderr, + testLoggerSyslog }; const size_t count = FUNCS_COUNT(tests); diff --git a/tests/mock/class.c b/tests/mock/mock_class.c similarity index 56% rename from tests/mock/class.c rename to tests/mock/mock_class.c index 8a9da0a..6088e16 100644 --- a/tests/mock/class.c +++ b/tests/mock/mock_class.c @@ -18,71 +18,55 @@ */ #include -#include +#include -#include "cclass.h" #include "class.h" +#include "mock_class.h" char _called; -INIT_CLASS(MOCK_CLASS); - -__construct(MOCK_CLASS) +void +_reset() { - _called = 1; - this->value = va_arg(* params, int); + _called = 0; } -__jsonConst(MOCK_CLASS) +static +inline +int +mockCtor(void * _this, va_list * params) { - _called = 1; - assert(json_type_int == json_object_get_type(json)); + MockClass this = _this; - this->value = json_object_get_int(json); -} + _called = 1; + this->value = va_arg(* params, int); -__clear(MOCK_CLASS) {} + if (321 == this->value) + return -1; -__destruct(MOCK_CLASS) -{ - _called = 1; + return 0; } -__toJson(MOCK_CLASS) +static +inline +void +mockDtor(void * _this) { - *json = json_object_new_int(this->value); _called = 1; } -/** - * ~~~ method implementations ~~~~~~~~ - */ - -int -mock_class_getValue(MOCK_CLASS this) -{ - return this->value; -} - +static +inline void -mock_class_setValue(MOCK_CLASS this, int value) +mockClone(void * _this, void * _base) { - this->value = value; -} + MockClass this = _this; + MockClass base = _base; -/** - * ~~~ helper for mock assertions ~~~~~~~~ - */ -void * -getConstruct() -{ - return __construct; + this->value = base->value; } -void * -getJsonConst() -{ - return __jsonConst; -} +INIT_IFACE(Class, mockCtor, mockDtor, mockClone); +CREATE_CLASS(MockClass, NULL, IFACE(Class)); // vim: set et ts=4 sw=4: diff --git a/tests/mock/class.h b/tests/mock/mock_class.h similarity index 74% rename from tests/mock/class.h rename to tests/mock/mock_class.h index e439bb1..2c2b9f6 100644 --- a/tests/mock/class.h +++ b/tests/mock/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 @@ -16,25 +20,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef __MOCK_CLASS_H__ -#define __MOCK_CLASS_H__ +#ifndef __MOCK_MOCK_CLASS_H__ +#define __MOCK_MOCK_CLASS_H__ -#include "cclass.h" +#include "class.h" extern char _called; #ifndef _RESET #define _RESET -void -inline -_reset() -{ - _called = 0; -} -#endif//_RESET +void _reset(); +#endif // _RESET -CLASS(MOCK_CLASS) { +CLASS(MockClass) { int value; }; @@ -42,8 +41,9 @@ CLASS(MOCK_CLASS) { * ~~~ method declarations ~~~~~~~~ */ -int mock_class_getValue(MOCK_CLASS this); -void mock_class_setValue(MOCK_CLASS this, int value); +int mockClassGetValue(MockClass this); +void mockClassSetValue(MockClass this, int value); + +#endif//__MOCK_MOCK_CLASS_H__ -#endif//__MOCK_CLASS_H__ // vim: set et ts=4 sw=4: diff --git a/tests/mock/mock_logger.c b/tests/mock/mock_logger.c new file mode 100644 index 0000000..6423f8c --- /dev/null +++ b/tests/mock/mock_logger.c @@ -0,0 +1,29 @@ +#include + +#include "class.h" +#include "logger.h" +#include "mock/mock_logger.h" + +static +void +logMock(void * _this, logger_level level, const char * const msg) +{ + MockLogger this = _this; + + snprintf(this->message, + MOCK_MESSAGE_MAX - 1, + "[%s] %s", + logger_level_str[level], + msg); +} + +void +mockLoggerCleanMsg(MockLogger this) +{ + this->message[0] = 0; +} + +INIT_IFACE(Logger, logMock); +CREATE_CLASS(MockLogger, Logger, IFACE(Logger)); + +// vim: set ts=4 sw=4: diff --git a/tests/mock/mock_logger.h b/tests/mock/mock_logger.h new file mode 100644 index 0000000..47dbcee --- /dev/null +++ b/tests/mock/mock_logger.h @@ -0,0 +1,20 @@ +#ifndef __MOCK_MOCK_LOGGER_H__ +#define __MOCK_MOCK_LOGGER_H__ + +#define MOCK_MESSAGE_MAX 1024 + +#include "class.h" +#include "logger.h" + +CLASS(MockLogger) +{ + EXTENDS(Logger); + + char message[MOCK_MESSAGE_MAX]; +}; + +void mockLoggerCleanMsg(MockLogger); + +#endif // __MOCK_MOCK_LOGGER_H__ + +// vim: set ts=4 sw=4: diff --git a/tests/mock/mock_worker.c b/tests/mock/mock_worker.c new file mode 100644 index 0000000..b051e4b --- /dev/null +++ b/tests/mock/mock_worker.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#include "class.h" +#include "stream.h" +#include "mock_worker.h" + +static +int +mockWorkerCtor(void * _this, va_list * params) +{ + MockWorker this = _this; + + this->rbuf = &(this->_rbuf[0]); + this->wbuf = &(this->_wbuf[0]); + + return 0; +} + +static +void +mockWorkerDtor(void * _this) +{ +} + +static +void +mockWorkerClone(void * _this, void * _base) +{ + MockWorker this = _this; + MockWorker base = _base; + + this->rbuf = &(base->_rbuf[0]); + this->wbuf = &(base->_wbuf[0]); +} + +static +ssize_t +mockWorkerRead(void * _this, Stream st) +{ + MockWorker this = _this; + size_t size; + + size = read((st->handle).fd, this->rbuf, 1024); + + return size; +} + +static +ssize_t +mockWorkerWrite(void * _this, Stream st) +{ + return 0; +} + +INIT_IFACE(Class, mockWorkerCtor, mockWorkerDtor, mockWorkerClone); +INIT_IFACE(StreamReader, mockWorkerRead); +INIT_IFACE(StreamWriter, mockWorkerWrite); +CREATE_CLASS( + MockWorker, + NULL, + IFACE(Class), + IFACE(StreamReader), + IFACE(StreamWriter)); + +// vim: set ts=4 sw=4: diff --git a/tests/mock/mock_worker.h b/tests/mock/mock_worker.h new file mode 100644 index 0000000..e11200e --- /dev/null +++ b/tests/mock/mock_worker.h @@ -0,0 +1,14 @@ +#ifndef __MOCK_MOCK_WORKER_H__ +#define __MOCK_MOCK_WORKER_H__ +#endif // __MOCK_MOCK_WORKER_H__ + +#include "class.h" + +CLASS(MockWorker) { + char _rbuf[1024]; + char _wbuf[1024]; + char * rbuf; + char * wbuf; +}; + +// vim: set ts=4 sw=4: diff --git a/tests/runtest.c b/tests/runtest.c index b363cc8..450ae19 100644 --- a/tests/runtest.c +++ b/tests/runtest.c @@ -22,7 +22,7 @@ #include #include "runtest.h" -#include "cclass.h" +#include "class.h" #define TEST_OK_CHAR '.' @@ -37,15 +37,15 @@ const char results[3] = { }; int -isObjectNull(void * _object) +isObjectNull(void * object) { - const CCLASS * class = _object - sizeof(CCLASS); + class_ptr class = GET_CLASS(object); - if (! isObject(_object)) { + if (! IS_OBJECT(object)) { return 0; } - return isMemNull(_object, (*class)->size); + return isMemNull(object, class->object_size); } int diff --git a/tests/runtest.h b/tests/runtest.h index 7b15945..1b60fd7 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 @@ -22,6 +26,7 @@ #include #include +#include "class.h" enum RESULT_TYPES { TEST_OK=0, @@ -90,7 +95,7 @@ enum RESULT_TYPES { return TEST_FAILED; } #define ASSERT_OBJECT(val) \ - if (! isObject((val))) { \ + if (! IS_OBJECT((val))) { \ printf("%s[%d]: Assertion failed that %s IS an object\n", \ __FILE__, __LINE__, #val); \ return TEST_FAILED; } @@ -108,7 +113,7 @@ enum RESULT_TYPES { return TEST_FAILED; } #define ASSERT_INSTANCE_OF(class, val) \ - if (! instanceOf(class, val)) { \ + if (! INSTANCE_OF(class, val)) { \ printf("%s[%d]: Assertion failed that %s is instance of %s\n", \ __FILE__, __LINE__, #val, #class); \ return TEST_FAILED; } diff --git a/tests/serverTest.c b/tests/serverTest.c index 3eae940..83bbd29 100644 --- a/tests/serverTest.c +++ b/tests/serverTest.c @@ -3,61 +3,44 @@ #include #include #include +#include #include "runtest.h" #include "logger.h" -#include "cclass.h" +#include "class.h" #include "server.h" -#include "signalHandling.h" +#include "utils/signalHandling.h" +#include "mock/mock_logger.h" +#include "mock/mock_worker.h" #define TEST_PORT 11212 #define TEST_DATA "test" -int level = -1; -char msg[1024]; char buffer[1025]; -static void -read_hook(const char * _buffer, size_t size) -{ - memset(buffer, 0, 1025); - - if (NULL != _buffer) { - strncpy(buffer, _buffer, 1024>size? size : 1024); - } - - doShutdown = 1; -} - -static void -logfnct_mock(int _level, const char * _msg) -{ - level = _level; - strncpy(msg, _msg, 1023); -} - const char testname[] = "serverTest"; -LOGGER logger = NULL; -SERVER server = NULL; + +MockLogger logger = NULL; +MockWorker worker = NULL; +Server server = NULL; static int __setUp() { - logger = new(LOGGER, NULL); - logger_add(logger, logfnct_mock); + logger = new(MockLogger, LOGGER_DEBUG); + worker = new(MockWorker); - server = new(SERVER, logger, TEST_PORT, SOMAXCONN); + server = new(Server, logger, worker, TEST_PORT, SOMAXCONN); - ASSERT_INSTANCE_OF(SERVER, server); - ASSERT_INSTANCE_OF(LOGGER, server->logger); - ASSERT_INSTANCE_OF(SOCK, server->sock); + ASSERT_INSTANCE_OF(Server, server); + ASSERT_INSTANCE_OF(MockLogger, server->logger); + ASSERT_INSTANCE_OF(MockWorker, server->worker); + ASSERT_INSTANCE_OF(Sock, server->sock); ASSERT_EQUAL(TEST_PORT, server->sock->port); - server->read_hook = read_hook; - return TEST_OK; } int (* const setUp)() = __setUp; @@ -66,16 +49,19 @@ static int __tearDown() { - level = -1; - if (NULL != server) { ASSERT_OBJECT(server); - delete(&server); + delete(server); + } + + if (NULL != worker) { + ASSERT_OBJECT(worker); + delete(worker); } if (NULL != logger) { ASSERT_OBJECT(logger); - delete(&logger); + delete(logger); } return TEST_OK; @@ -86,19 +72,23 @@ static int testDummy() { - SOCK con; - pid_t pid; + Sock con; + pid_t pid, ppid; + char addr[16]; - pid = fork(); + ppid = getpid(); + pid = fork(); switch(pid) { case 0: - con = new(SOCK, logger, TEST_PORT); + con = new(Sock, logger, TEST_PORT); sleep(1); - sock_connect(con, "127.0.0.1"); + socketConnect(con, "127.0.0.1", &addr); write(con->handle, TEST_DATA, strlen(TEST_DATA)+1); - delete(&con); + sleep(1); + delete(con); __tearDown(); + kill(ppid, SIGINT); exit(EXIT_SUCCESS); case -1: @@ -106,10 +96,10 @@ testDummy() default: init_signals(); - server_run(server); + serverRun(server); } - ASSERT_STRING_EQUAL(TEST_DATA, buffer); + ASSERT_STRING_EQUAL(TEST_DATA, worker->rbuf); return TEST_OK; } diff --git a/tests/socketTest.c b/tests/socketTest.c index 64447da..48797f5 100644 --- a/tests/socketTest.c +++ b/tests/socketTest.c @@ -3,40 +3,30 @@ #include #include "runtest.h" -#include "logger.h" -#include "cclass.h" +#include "class.h" #include "socket.h" +#include "logger.h" +#include "mock/mock_logger.h" #define TEST_PORT 11212 -int level = -1; -char * msg = NULL; - -static void -logfnct_mock(int _level, const char * _msg) -{ - level = _level; - msg = malloc(strlen(_msg) + 1); - strcpy(msg, _msg); -} - const char testname[] = "socketTest"; -LOGGER logger = NULL; -SOCK sock = NULL; + +MockLogger logger = NULL; +Sock sock = NULL; static int __setUp() { - logger = new(LOGGER, NULL); - logger_add(logger, logfnct_mock); + logger = new(MockLogger, LOGGER_DEBUG); - sock = new(SOCK, logger, TEST_PORT); + sock = new(Sock, logger, TEST_PORT); - ASSERT_INSTANCE_OF(SOCK, sock); - ASSERT_INSTANCE_OF(LOGGER, sock->logger); + ASSERT_INSTANCE_OF(Sock, sock); + ASSERT_INSTANCE_OF(MockLogger, sock->log); ASSERT_EQUAL(TEST_PORT, sock->port); ASSERT_NOT_EQUAL(0, sock->handle); @@ -48,21 +38,14 @@ static int __tearDown() { - level = -1; - - if (NULL != msg) { - free(msg); - msg = NULL; - } - if (NULL != logger) { ASSERT_OBJECT(logger); - delete(&logger); + delete(logger); } if (NULL != sock) { ASSERT_OBJECT(sock); - delete(&sock); + delete(sock); } return TEST_OK; @@ -73,29 +56,29 @@ static int testListen() { - sock_listen(sock, 10); + socketListen(sock, 10); return TEST_OK; } static int -testAccept() +testAcceptConnect() { - SOCK acc, con; + Sock acc, con; char addr[16]; pid_t pid; - sock_listen(sock, 10); + socketListen(sock, 10); pid = fork(); switch(pid) { case 0: - con = new(SOCK, logger, TEST_PORT); + con = new(Sock, logger, TEST_PORT); sleep(1); - sock_connect(con, "127.0.0.1"); - delete(&con); + socketConnect(con, "127.0.0.1", &addr); + delete(con); __tearDown(); exit(EXIT_SUCCESS); @@ -103,12 +86,12 @@ testAccept() return TEST_FAILED; default: - acc = sock_accept(sock, addr); + acc = socketAccept(sock, &addr); } if (NULL != acc) { ASSERT_OBJECT(acc); - delete(&acc); + delete(acc); } return TEST_OK; @@ -116,7 +99,7 @@ testAccept() const testfunc tests[] = { testListen, - testAccept + testAcceptConnect }; const size_t count = FUNCS_COUNT(tests);