From 1307358fbdcb52eed419bc561f55a1c00b95187f Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Wed, 4 Dec 2013 22:46:57 +0000 Subject: [PATCH] moved the class and memory management into a separate project libtrbase / prefix all of the public interface of libtrbase with TR_ --- configure.ac | 6 +- include/application/adapter/http.h | 4 +- include/application/application.h | 4 +- include/asset.h | 5 +- include/auth/auth.h | 4 +- include/auth/credential.h | 4 +- include/auth/interface/auth.h | 12 +- include/auth/ldap.h | 4 +- include/auth/storage.h | 4 +- include/cbuf.h | 7 +- include/class.h | 10 - include/class/class.h | 143 --- include/class/interface.h | 59 -- include/class/interface/class.h | 64 -- include/commons.h | 48 - include/config/config.h | 4 +- include/config/value.h | 4 +- include/hash/hash.h | 4 +- include/hash/interface/hashable.h | 12 +- include/hash/value.h | 4 +- include/http/cookie.h | 4 +- include/http/header.h | 4 +- include/http/interface/http_intro.h | 12 +- include/http/message.h | 4 +- include/http/parser.h | 5 +- include/http/request.h | 6 +- include/http/response.h | 6 +- include/http/worker.h | 5 +- include/http/writer.h | 6 +- include/interface/indexable.h | 49 - include/interface/observer.h | 40 - include/interface/serializable.h | 42 - include/interface/subject.h | 46 - include/logger/interface/logger.h | 10 +- include/logger/logger.h | 12 +- include/permission.h | 4 +- include/queue.h | 5 +- include/rbac/object.h | 4 +- include/rbac/operation.h | 4 +- include/rbac/user.h | 4 +- include/role.h | 4 +- include/router.h | 4 +- include/server.h | 4 +- include/session.h | 4 +- include/socket.h | 4 +- include/storage/storage.h | 4 +- include/stream/interface/reader.h | 9 +- include/stream/interface/writer.h | 9 +- include/stream/stream.h | 4 +- include/tree.h | 4 +- include/user.h | 5 +- include/utils/memory.h | 40 - include/uuid.h | 5 +- src/Makefile.am | 33 +- src/application/adapter/http/http.c | 16 +- src/application/adapter/http/update.c | 3 +- src/application/application.c | 19 +- .../controller/_get_credential_from_args.c | 5 +- .../controller/_get_user_from_args.c | 6 +- .../controller/_process_user_create_args.c | 7 +- .../controller/_update_user_from_args.c | 8 +- src/application/controller/_validate_email.c | 4 +- .../controller/_validate_password.c | 3 +- .../controller/_validate_password_repeat.c | 4 +- .../controller/authenticate/create.c | 7 +- .../controller/authenticate/delete.c | 2 - src/application/controller/currentuser/read.c | 6 +- src/application/controller/loc/read.c | 5 +- src/application/controller/randval/read.c | 6 +- src/application/controller/sessinfo/read.c | 5 +- src/application/controller/signup/create.c | 8 +- src/application/controller/user/create.c | 8 +- src/application/controller/user/read.c | 6 +- src/application/controller/user/update.c | 5 +- src/application/controller/version/read.c | 5 +- src/application/create_user.c | 14 +- src/application/get_user.c | 12 +- src/application/login.c | 27 +- src/application/logout.c | 5 +- src/application/session_cleanup.c | 7 +- src/application/session_get.c | 3 - src/application/session_start.c | 5 +- src/application/session_stop.c | 3 - src/application/update_password.c | 12 +- src/application/update_user.c | 13 +- src/asset/asset.c | 8 +- src/asset/pool.c | 16 +- src/auth/auth.c | 12 +- src/auth/create.c | 9 +- src/auth/credential.c | 16 +- src/auth/interface/auth.c | 7 +- src/auth/ldap.c | 18 +- src/auth/storage/hash_pw.c | 10 +- src/auth/storage/storage.c | 16 +- src/cbuf/cbuf.c | 16 +- src/cbuf/is_locked.c | 2 - src/class/Makefile.am | 9 - src/class/interface.c | 64 -- src/class/interface/i_class.c | 99 -- src/config/config.c | 22 +- src/config/get.c | 1 - src/config/value.c | 13 +- src/hash/add.c | 3 +- src/hash/cleanup.c | 4 +- src/hash/hash.c | 8 +- src/hash/interface/hashable.c | 27 +- src/hash/value.c | 19 +- src/http/cookie.c | 23 +- src/http/header.c | 18 +- src/http/interface/i_http_intro.c | 11 +- src/http/message.c | 18 +- src/http/message/has_keep_alive.c | 4 +- src/http/parser.c | 19 +- src/http/parser/p_body.c | 2 +- src/http/parser/p_header.c | 10 +- src/http/parser/p_post_vars.c | 4 +- src/http/parser/p_request_vars.c | 8 +- src/http/parser/parse.c | 13 +- src/http/request.c | 48 +- src/http/response.c | 22 +- src/http/response/304.c | 13 +- src/http/response/403.c | 5 +- src/http/response/404.c | 11 +- src/http/response/500.c | 11 +- src/http/response/asset.c | 15 +- src/http/response/json.c | 14 +- src/http/worker.c | 62 +- src/http/worker/add_common_header.c | 17 +- src/http/worker/add_computed_header.c | 5 - src/http/worker/get_asset.c | 5 +- src/http/worker/process.c | 15 +- src/http/writer.c | 19 +- src/http/writer/write.c | 15 +- src/interface/indexable.c | 42 - src/interface/observer.c | 37 - src/interface/serializable.c | 49 - src/interface/subject.c | 49 - src/logger/interface/i_logger.c | 31 +- src/logger/logger.c | 6 +- src/logger/stderr.c | 5 +- src/logger/syslog.c | 5 +- src/queue/get.c | 4 +- src/queue/put.c | 4 +- src/queue/queue.c | 10 +- src/router/route.c | 10 +- src/router/router.c | 10 +- src/server/close_conn.c | 8 +- src/server/handle_accept.c | 10 +- src/server/server.c | 24 +- src/session/session.c | 12 +- src/socket/accept.c | 4 +- src/socket/connect.c | 1 - src/socket/listen.c | 1 - src/socket/nonblock.c | 1 - src/socket/socket.c | 6 +- src/storage/delete.c | 3 - src/storage/get.c | 9 +- src/storage/put.c | 3 - src/storage/storage.c | 11 +- src/storage/update.c | 3 - src/stream/interface/reader.c | 10 +- src/stream/interface/writer.c | 11 +- src/stream/stream.c | 6 +- src/taskrambler.c | 50 +- src/testers/rbtree2.c | 7 +- src/testers/uuid.c | 5 +- src/tree/delete.c | 7 +- src/tree/destroy.c | 3 +- src/tree/insert.c | 7 +- src/tree/tree.c | 6 +- src/user/user.c | 35 +- src/utils/http.c | 8 +- src/utils/memory.c | 869 ------------------ src/utils/mime_type.c | 11 +- src/uuid/_format3or5.c | 1 - src/uuid/compare.c | 1 - src/uuid/parse.c | 4 +- src/uuid/unparse.c | 1 - src/uuid/uuid.c | 8 +- src/uuid/version1.c | 4 +- src/uuid/version3.c | 8 +- src/uuid/version5.c | 8 +- 182 files changed, 637 insertions(+), 2647 deletions(-) delete mode 100644 include/class.h delete mode 100644 include/class/class.h delete mode 100644 include/class/interface.h delete mode 100644 include/class/interface/class.h delete mode 100644 include/commons.h delete mode 100644 include/interface/indexable.h delete mode 100644 include/interface/observer.h delete mode 100644 include/interface/serializable.h delete mode 100644 include/interface/subject.h delete mode 100644 include/utils/memory.h delete mode 100644 src/class/Makefile.am delete mode 100644 src/class/interface.c delete mode 100644 src/class/interface/i_class.c delete mode 100644 src/interface/indexable.c delete mode 100644 src/interface/observer.c delete mode 100644 src/interface/serializable.c delete mode 100644 src/interface/subject.c delete mode 100644 src/utils/memory.c diff --git a/configure.ac b/configure.ac index a2d32fd..ee9ad3a 100644 --- a/configure.ac +++ b/configure.ac @@ -18,8 +18,9 @@ AC_CONFIG_MACRO_DIR([m4]) m4_include([m4/gcov.m4]) AC_TDD_GCOV -m4_include([m4/memopt.m4]) -AC_MEM_OPT +m4_include([m4/trlibs.m4]) +AC_TRLIBS_ROOT +AC_NEED_TRBASE m4_include([m4/chkamd.m4]) AC_CHK_AMD @@ -89,7 +90,6 @@ AC_CONFIG_FILES([Makefile src/asset/Makefile src/auth/Makefile src/cbuf/Makefile - src/class/Makefile src/hash/Makefile src/queue/Makefile src/http/Makefile diff --git a/include/application/adapter/http.h b/include/application/adapter/http.h index 956a06e..3c39cd6 100644 --- a/include/application/adapter/http.h +++ b/include/application/adapter/http.h @@ -23,12 +23,12 @@ #ifndef __APPLICATION_ADAPTER_HTTP_H__ #define __APPLICATION_ADAPTER_HTTP_H__ -#include "class.h" +#include "trbase.h" #include "router.h" #include "application/application.h" -CLASS(ApplicationAdapterHttp) { +TR_CLASS(ApplicationAdapterHttp) { Application application; Router router; }; diff --git a/include/application/application.h b/include/application/application.h index 3a80c99..7f6de49 100644 --- a/include/application/application.h +++ b/include/application/application.h @@ -25,7 +25,7 @@ #include -#include "class.h" +#include "trbase.h" #include "session.h" #include "hash.h" @@ -42,7 +42,7 @@ struct randval { int value; }; -CLASS(Application) { +TR_CLASS(Application) { Hash * active_sessions; time_t session_time_ofs; diff --git a/include/asset.h b/include/asset.h index 1b9a7bf..c67a29a 100644 --- a/include/asset.h +++ b/include/asset.h @@ -26,12 +26,11 @@ #include -#include "class.h" -#include "commons.h" +#include "trbase.h" #include "hash.h" -CLASS(Asset) { +TR_CLASS(Asset) { unsigned long hash; char fname[2049]; diff --git a/include/auth/auth.h b/include/auth/auth.h index b8e308e..3c6cf10 100644 --- a/include/auth/auth.h +++ b/include/auth/auth.h @@ -42,7 +42,7 @@ #ifndef __AUTH_AUTH_H__ #define __AUTH_AUTH_H__ -#include "class.h" +#include "trbase.h" #include "uuid.h" #include "auth.h" #include "auth/credential.h" @@ -55,7 +55,7 @@ typedef enum e_AuthModule { #define MAX_AUTH AUTH_STORAGE -CLASS(Auth) { +TR_CLASS(Auth) { void * auth[MAX_AUTH + 1]; }; diff --git a/include/auth/credential.h b/include/auth/credential.h index 01394e8..1f492aa 100644 --- a/include/auth/credential.h +++ b/include/auth/credential.h @@ -25,7 +25,7 @@ #include -#include "class.h" +#include "trbase.h" #define CRED_PWD(c) (((c)->cred).pwd) @@ -34,7 +34,7 @@ typedef enum e_CredentialType { } CredentialType; -CLASS(Credential) { +TR_CLASS(Credential) { CredentialType type; union { diff --git a/include/auth/interface/auth.h b/include/auth/interface/auth.h index 9e4b696..f4cc845 100644 --- a/include/auth/interface/auth.h +++ b/include/auth/interface/auth.h @@ -28,19 +28,15 @@ #ifndef __AUTH_INTERFACE_AUTH_H__ #define __AUTH_INTERFACE_AUTH_H__ -#include - -#include "class.h" +#include "trbase.h" #include "uuid.h" #include "auth/credential.h" typedef int (* fptr_authenticate)(void *, Credential, Uuid); -extern const struct interface i_Auth; - -struct i_Auth { - const struct interface * const _; - fptr_authenticate authenticate; +TR_INTERFACE(Auth) { + TR_IFID; + fptr_authenticate authenticate; }; extern int authenticate(void *, Credential, Uuid); diff --git a/include/auth/ldap.h b/include/auth/ldap.h index 4c6e98c..baffcfb 100644 --- a/include/auth/ldap.h +++ b/include/auth/ldap.h @@ -26,9 +26,9 @@ #include #include -#include "class.h" +#include "trbase.h" -CLASS(AuthLdap) { +TR_CLASS(AuthLdap) { LDAP * ldap; char * url; char * base_dn; diff --git a/include/auth/storage.h b/include/auth/storage.h index 85ba557..e00b53a 100644 --- a/include/auth/storage.h +++ b/include/auth/storage.h @@ -27,7 +27,7 @@ #include -#include "class.h" +#include "trbase.h" #include "storage/storage.h" @@ -35,7 +35,7 @@ #define HASH_SIZE SHA512_DIGEST_LENGTH -CLASS(AuthStorage) { +TR_CLASS(AuthStorage) { Storage store; }; diff --git a/include/cbuf.h b/include/cbuf.h index dd3fd87..c65fd77 100644 --- a/include/cbuf.h +++ b/include/cbuf.h @@ -34,16 +34,13 @@ #include #include -#include "class.h" +#include "trbase.h" #include "stream.h" -#include "commons.h" -#include "utils/memory.h" - #define ECBUFOVFL 100 -CLASS(Cbuf) { +TR_CLASS(Cbuf) { char * shm_name; // shared memory identifier char * data; diff --git a/include/class.h b/include/class.h deleted file mode 100644 index 6c07bbc..0000000 --- a/include/class.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __CLASS_H__ -#define __CLASS_H__ - -#include "class/class.h" -#include "class/interface.h" -#include "class/interface/class.h" - -#endif // __CLASS_H__ - -// vim: set ts=4 sw=4: diff --git a/include/class/class.h b/include/class/class.h deleted file mode 100644 index 1956559..0000000 --- a/include/class/class.h +++ /dev/null @@ -1,143 +0,0 @@ -/** - * \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; \ - struct c_##name##_object { void * class; struct c_##name data; } - - -/** - * create a static instance of a class. - * \todo - * this macro requires to close the initializer - * with an extra curly brancket. This is not nice...find a - * way to prevent this. - */ -#define INSTANCE(class, name) \ - struct c_##class##_object _##name; \ - class name = &(_##name.data); \ - struct c_##class##_object _##name = { \ - &c_##class, - -#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/class/interface.h b/include/class/interface.h deleted file mode 100644 index 941f43c..0000000 --- a/include/class/interface.h +++ /dev/null @@ -1,59 +0,0 @@ -/** - * \file - * Interface definition code. Each interface is a set of selector functions - * as well as a data structure where the concrete implementation will be stored. - * This structure is the intergrated in the class that implements the - * 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 __CLASS_INTERFACE_H__ -#define __CLASS_INTERFACE_H__ - -#include - -#define MAX_IFACE 32 // ATTENTION: every iface_impl will use MAX_IFACE * sizeof(void*) - -#define IFACE(name) ((const struct i_##name const*)&i_##name##_impl) -#define INIT_IFACE(name,...) \ - static const struct i_##name i_##name##_impl = {&i_##name,__VA_ARGS__} - -#define NUMARGS(...) (sizeof((const void*[]){__VA_ARGS__})/sizeof(void*)) -#define INIT_IFACE_IMPL(...) {NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}} - - -struct interface { - const char * name; - const size_t nmethods; -}; -typedef const struct interface * iface_ptr; - -struct iface_impl { - const size_t nimpl; // number of interface implementations - char simpl; // implementations sorted?? - const void * impl[MAX_IFACE]; // implementations -}; -typedef struct iface_impl * iface_impl_ptr; - -extern iface_ptr interfaceGet(iface_impl_ptr, const iface_ptr); - -#endif // __CLASS_INTERFACE_H__ - -// vim: set ts=4 sw=4: diff --git a/include/class/interface/class.h b/include/class/interface/class.h deleted file mode 100644 index 721af7b..0000000 --- a/include/class/interface/class.h +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \file - * Interface for class handling. Defines new, delete and clone selectors - * which in turn use the ctor, dtor and clone implementation from the - * class implementation. - * - * \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_INTERFACE_CLASS_H__ -#define __CLASS_INTERFACE_CLASS_H__ - -#include - -#include "class/class.h" -#include "class/interface.h" - -typedef int (* fptr_ctor)(void *, va_list *); -typedef void (* fptr_dtor)(void *); -typedef void (* fptr_clone)(void *, void * const); - -extern const struct interface i_Class; - -struct i_Class { - const struct interface * const _; - fptr_ctor ctor; - fptr_dtor dtor; - fptr_clone clone; -}; - -extern void * classNew(class_ptr, ...); -extern void classDelete(void **); -extern void * classClone(void *); - -#define new(class,...) classNew(_##class, ##__VA_ARGS__) -#define delete(object) classDelete((void **)&(object)) -#define clone(object) classClone((void *)(object)) - -/** - * With this one we can create a new instance via a - * intermidiary that gets the arguments. - */ -extern void * classNewParams(class_ptr, va_list *); -#define newParams(class,args) classNewParams(_##class, args) - -#endif // __CLASS_INTERFACE_CLASS_H__ - -// vim: set ts=4 sw=4: diff --git a/include/commons.h b/include/commons.h deleted file mode 100644 index 7f354f7..0000000 --- a/include/commons.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * \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__ - -#define Bool char -#define TRUE 1 -#define FALSE 0 - -#ifndef MAX -# define MAX(a,b) ((a)>(b)? (a) : (b)) -#endif - -#ifndef MIN -# define MIN(a,b) ((a)<(b)? (a) : (b)) -#endif - -#define SWAP_FUN(a, b) ((a)^=(b),(b)^=(a),(a)^=(b)) - -#define SWAP(type, a, b) do { \ - type tmp = (a); \ - (a) = (b); \ - (b) = tmp; \ -} while(0); - -#endif // __COMMONS_H__ - -// vim: set ts=4 sw=4: diff --git a/include/config/config.h b/include/config/config.h index 983b389..716bea1 100644 --- a/include/config/config.h +++ b/include/config/config.h @@ -23,14 +23,14 @@ #ifndef __CONFIG_H__ #define __CONFIG_H__ +#include "trbase.h" #include "hash.h" -#include "class.h" #include "config/value.h" #define MAX_CONFIG_LINE 256 -CLASS(Config) { +TR_CLASS(Config) { char * cnf_file; Hash config; }; diff --git a/include/config/value.h b/include/config/value.h index 0ed8875..5696585 100644 --- a/include/config/value.h +++ b/include/config/value.h @@ -25,8 +25,8 @@ #include +#include "trbase.h" #include "hash.h" -#include "class.h" #define MAX_CONFIG_LINE 256 @@ -38,7 +38,7 @@ typedef enum e_ConfigValueType { CONFIG_VALUE_STRING = 1 } ConfigValueType; -CLASS(ConfigValue) { +TR_CLASS(ConfigValue) { union { char * string; long long number; diff --git a/include/hash/hash.h b/include/hash/hash.h index 1ba1550..555f5cb 100644 --- a/include/hash/hash.h +++ b/include/hash/hash.h @@ -25,12 +25,12 @@ #include -#include "class.h" +#include "trbase.h" #include "tree.h" #define HASH_IS_EMPTY(h) ((h)->root) -CLASS(Hash) { +TR_CLASS(Hash) { Tree root; }; diff --git a/include/hash/interface/hashable.h b/include/hash/interface/hashable.h index 1a33d58..c003cd2 100644 --- a/include/hash/interface/hashable.h +++ b/include/hash/interface/hashable.h @@ -24,17 +24,15 @@ #ifndef __HASH_INTERFACE_HASHABLE_H__ #define __HASH_INTERFACE_HASHABLE_H__ -#include "class.h" +#include "trbase.h" typedef unsigned long (* fptr_hashableGetHash)(void *); typedef void (* fptr_hashableHandleDouble)(void *, void *); -extern const struct interface i_Hashable; - -struct i_Hashable { - const struct interface * const _; - fptr_hashableGetHash getHash; - fptr_hashableHandleDouble handleDouble; +TR_INTERFACE(Hashable) { + TR_IFID; + fptr_hashableGetHash getHash; + fptr_hashableHandleDouble handleDouble; }; extern unsigned long hashableGetHash(void *); diff --git a/include/hash/value.h b/include/hash/value.h index 17a4f6c..891e9e1 100644 --- a/include/hash/value.h +++ b/include/hash/value.h @@ -25,9 +25,9 @@ #include -#include "class.h" +#include "trbase.h" -CLASS(HashValue) { +TR_CLASS(HashValue) { unsigned long hash; char * key; diff --git a/include/http/cookie.h b/include/http/cookie.h index 18e52fd..194b64c 100644 --- a/include/http/cookie.h +++ b/include/http/cookie.h @@ -26,9 +26,9 @@ #include #include -#include "class.h" +#include "trbase.h" -CLASS(HttpCookie) { +TR_CLASS(HttpCookie) { unsigned long hash; char * key; diff --git a/include/http/header.h b/include/http/header.h index 865ffd7..8270ce3 100644 --- a/include/http/header.h +++ b/include/http/header.h @@ -27,11 +27,11 @@ #include -#include "class.h" +#include "trbase.h" #define N_VALUES 128 -CLASS(HttpHeader) { +TR_CLASS(HttpHeader) { unsigned long hash; char * name; char * value[N_VALUES]; diff --git a/include/http/interface/http_intro.h b/include/http/interface/http_intro.h index 60edf93..480e8de 100644 --- a/include/http/interface/http_intro.h +++ b/include/http/interface/http_intro.h @@ -28,15 +28,15 @@ #include +#include "trbase.h" + typedef size_t (* fptr_httpIntroSizeGet)(void *); typedef char * (* fptr_httpIntroToString)(void *, char *); -extern const struct interface i_HttpIntro; - -struct i_HttpIntro { - const struct interface * const _; - fptr_httpIntroSizeGet sizeGet; - fptr_httpIntroToString toString; +TR_INTERFACE(HttpIntro) { + TR_IFID; + fptr_httpIntroSizeGet sizeGet; + fptr_httpIntroToString toString; }; extern size_t httpIntroSizeGet(void *); diff --git a/include/http/message.h b/include/http/message.h index 53042cb..06f1762 100644 --- a/include/http/message.h +++ b/include/http/message.h @@ -24,12 +24,12 @@ #ifndef __HTTP_MESSAGE__ #define __HTTP_MESSAGE__ -#include "class.h" +#include "trbase.h" #include "hash.h" #include "stream.h" #include "asset.h" -CLASS(HttpMessage) { +TR_CLASS(HttpMessage) { char * version; Hash header; diff --git a/include/http/parser.h b/include/http/parser.h index 7e689e3..6d2ec2b 100644 --- a/include/http/parser.h +++ b/include/http/parser.h @@ -24,13 +24,12 @@ #ifndef __HTTP_PARSER_H__ #define __HTTP_PARSER_H__ -#include "class.h" +#include "trbase.h" #include "http/message.h" #include "queue.h" #include "cbuf.h" #include "stream.h" -#include "commons.h" #define PARSER_MAX_BUF 131072 @@ -44,7 +43,7 @@ typedef enum e_HttpMessageState { } HttpMessageState; -CLASS(HttpParser) { +TR_CLASS(HttpParser) { Cbuf buffer; Bool ourLock; diff --git a/include/http/request.h b/include/http/request.h index 8455495..67bda30 100644 --- a/include/http/request.h +++ b/include/http/request.h @@ -24,7 +24,7 @@ #ifndef __HTTP_REQUEST_H__ #define __HTTP_REQUEST_H__ -#include "class.h" +#include "trbase.h" #include "http/message.h" #include "hash.h" @@ -43,8 +43,8 @@ typedef enum e_HttpMethod { HTTP_CONNECT } HttpMethod; -CLASS(HttpRequest) { - EXTENDS(HttpMessage); +TR_CLASS(HttpRequest) { + TR_EXTENDS(HttpMessage); char * method; char * uri; diff --git a/include/http/response.h b/include/http/response.h index 329b945..b6df1cc 100644 --- a/include/http/response.h +++ b/include/http/response.h @@ -27,15 +27,15 @@ #include #include -#include "class.h" +#include "trbase.h" #include "http/message.h" #include "session.h" #include "user.h" #include "asset.h" -CLASS(HttpResponse) { - EXTENDS(HttpMessage); +TR_CLASS(HttpResponse) { + TR_EXTENDS(HttpMessage); unsigned int status; char * reason; diff --git a/include/http/worker.h b/include/http/worker.h index 00414a2..1d7011f 100644 --- a/include/http/worker.h +++ b/include/http/worker.h @@ -27,7 +27,7 @@ #include #include -#include "class.h" +#include "trbase.h" #include "hash.h" #include "http/parser.h" #include "http/writer.h" @@ -37,10 +37,9 @@ #include "http/request.h" #include "http/response.h" #include "queue.h" -#include "commons.h" -CLASS(HttpWorker) { +TR_CLASS(HttpWorker) { char * id; Cbuf pbuf; diff --git a/include/http/writer.h b/include/http/writer.h index 36e34ad..e0b7ece 100644 --- a/include/http/writer.h +++ b/include/http/writer.h @@ -26,13 +26,11 @@ #include -#include "class.h" +#include "trbase.h" #include "http/message.h" #include "queue.h" #include "stream.h" -#include "commons.h" - /* * the buffer that will be written back to an http client. @@ -78,7 +76,7 @@ typedef enum e_HttpWriterState { HTTP_WRITER_DONE } HttpWriterState; -CLASS(HttpWriter) { +TR_CLASS(HttpWriter) { char * buffer; Queue queue; diff --git a/include/interface/indexable.h b/include/interface/indexable.h deleted file mode 100644 index 74a037d..0000000 --- a/include/interface/indexable.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * \file - * This interface provides only one function at all. - * indexUuid will generate a uuid to the current object. - * - * \todo - * Maybe merge hashable and indexable. Thus we might get an - * easy way to exchange the hashing mechanism used for my - * associative arrays. - * - * \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 __INDEXABLE_H__ -#define __INDEXABLE_H__ - -#include "uuid.h" - - -typedef Uuid (* fptr_indexUuid)(void *, Uuid); - -extern const struct interface i_Indexable; - -struct i_Indexable { - const struct interface * const _; - fptr_indexUuid uuid; -}; - -extern Uuid indexUuid(void *, Uuid); - -#endif // __INDEXABLE_H__ - -// vim: set ts=4 sw=4: diff --git a/include/interface/observer.h b/include/interface/observer.h deleted file mode 100644 index 927c5d8..0000000 --- a/include/interface/observer.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * \file - * Definition of the observer pattern implementation. - * - * \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 __OBSERVER_H__ -#define __OBSERVER_H__ - -typedef void (* fptr_observerUpdate)(void *, void*); - -extern const struct interface i_Observer; - -struct i_Observer { - const struct interface * const _; - fptr_observerUpdate update; -}; - -extern void observerUpdate(void *, void *); - -#endif // __OBSERVER_H__ - -// vim: set ts=4 sw=4: diff --git a/include/interface/serializable.h b/include/interface/serializable.h deleted file mode 100644 index 742197e..0000000 --- a/include/interface/serializable.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * \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 __SERIALIZABLE_H__ -#define __SERIALIZABLE_H__ - -typedef void (* fptr_serialize)(void *, unsigned char **, size_t *); -typedef void (* fptr_unserialize)(void *, const unsigned char *, size_t); - -extern const struct interface i_Serializable; - -struct i_Serializable { - const struct interface * const _; - fptr_serialize serialize; - fptr_unserialize unserialize; -}; - -extern void serialize(void *, unsigned char **, size_t *); -extern void unserialize(void *, const unsigned char *, size_t); - -#endif // __SERIALIZABLE_H__ - -// vim: set ts=4 sw=4: diff --git a/include/interface/subject.h b/include/interface/subject.h deleted file mode 100644 index 16ef044..0000000 --- a/include/interface/subject.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * \file - * Definition of the subject pattern implementation. - * - * \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 __SUBJECT_H__ -#define __SUBJECT_H__ - -typedef void (* fptr_subjectAttach)(void *, void *); -typedef void (* fptr_subjectDetach)(void *, void *); -typedef void (* fptr_subjectNotify)(void *); - -extern const struct interface i_Subject; - -struct i_Subject { - const struct interface * const _; - fptr_subjectAttach attach; - fptr_subjectDetach detach; - fptr_subjectNotify notify; -}; - -extern void subjectAttach(void *, void *); -extern void subjectDetach(void *, void *); -extern void subjectNotify(void *); - -#endif // __SUBJECT_H__ - -// vim: set ts=4 sw=4: diff --git a/include/logger/interface/logger.h b/include/logger/interface/logger.h index 549f584..24fe6c0 100644 --- a/include/logger/interface/logger.h +++ b/include/logger/interface/logger.h @@ -26,16 +26,14 @@ #include -#include "class.h" +#include "trbase.h" #include "logger.h" typedef void (* fptr_log)(void *, logger_level, const char * const); -extern const struct interface i_Logger; - -struct i_Logger { - const struct interface * const _; - fptr_log log; +TR_INTERFACE(Logger) { + TR_IFID; + fptr_log log; }; extern void loggerLog(void *, logger_level, const char * const, ...); diff --git a/include/logger/logger.h b/include/logger/logger.h index fc10124..e1c3975 100644 --- a/include/logger/logger.h +++ b/include/logger/logger.h @@ -25,7 +25,7 @@ #ifndef __LOGGER_LOGGER_H__ #define __LOGGER_LOGGER_H__ -#include "class.h" +#include "trbase.h" typedef enum logger_level { LOGGER_DEBUG=0, @@ -40,16 +40,16 @@ typedef enum logger_level { extern const char * const logger_level_str[]; -CLASS(Logger) { +TR_CLASS(Logger) { logger_level min_level; }; -CLASS(LoggerStderr) { - EXTENDS(Logger); +TR_CLASS(LoggerStderr) { + TR_EXTENDS(Logger); }; -CLASS(LoggerSyslog) { - EXTENDS(Logger); +TR_CLASS(LoggerSyslog) { + TR_EXTENDS(Logger); }; #endif // __LOGGER_LOGGER_H__ diff --git a/include/permission.h b/include/permission.h index bbf4283..000eccd 100644 --- a/include/permission.h +++ b/include/permission.h @@ -25,7 +25,7 @@ #include -#include "class.h" +#include "trbase.h" #include "storage/storage.h" /** @@ -45,7 +45,7 @@ typedef enum e_ResourceActions { } ResourceAction; -CLASS(Permission) { +TR_CLASS(Permission) { char id[37]; unsigned long hash; diff --git a/include/queue.h b/include/queue.h index 05f6f9c..097aefd 100644 --- a/include/queue.h +++ b/include/queue.h @@ -28,11 +28,10 @@ #include -#include "class.h" -#include "commons.h" +#include "trbase.h" -CLASS(Queue) { +TR_CLASS(Queue) { void * msg; Queue next; diff --git a/include/rbac/object.h b/include/rbac/object.h index 34b6d0c..77b977c 100644 --- a/include/rbac/object.h +++ b/include/rbac/object.h @@ -25,11 +25,11 @@ #include -#include "class.h" +#include "trbase.h" #include "storage/storage.h" -CLASS(RbacObject) { +TR_CLASS(RbacObject) { char * name; size_t nname; }; diff --git a/include/rbac/operation.h b/include/rbac/operation.h index 05bf232..495ec96 100644 --- a/include/rbac/operation.h +++ b/include/rbac/operation.h @@ -25,10 +25,10 @@ #include -#include "class.h" +#include "trbase.h" -CLASS(RbacOperation) { +TR_CLASS(RbacOperation) { char * name; size_t nname; }; diff --git a/include/rbac/user.h b/include/rbac/user.h index b5cf751..cff8786 100644 --- a/include/rbac/user.h +++ b/include/rbac/user.h @@ -25,7 +25,7 @@ #include -#include "class.h" +#include "trbase.h" /** @@ -37,7 +37,7 @@ * tricky to find the correct interface when we want to * be flexible in future. */ -CLASS(RbacUser) { +TR_CLASS(RbacUser) { char * name; size_t nname; }; diff --git a/include/role.h b/include/role.h index e94af6c..aaa2ba9 100644 --- a/include/role.h +++ b/include/role.h @@ -25,12 +25,12 @@ #include -#include "class.h" +#include "trbase.h" #include "ebac/permission.h" #include "storage/storage.h" -CLASS(Role) { +TR_CLASS(Role) { char id[37]; unsigned long hash; diff --git a/include/router.h b/include/router.h index 644af94..d86295e 100644 --- a/include/router.h +++ b/include/router.h @@ -33,7 +33,7 @@ #include -#include "class.h" +#include "trbase.h" #include "hash.h" #include "session.h" #include "http/request.h" @@ -42,7 +42,7 @@ typedef char * (* fptr_routable)(Application, Session, Hash); -CLASS(Router) { +TR_CLASS(Router) { Hash functions; Application application; diff --git a/include/server.h b/include/server.h index 0468e39..6e2d09e 100644 --- a/include/server.h +++ b/include/server.h @@ -31,7 +31,7 @@ #include -#include "class.h" +#include "trbase.h" #include "socket.h" #include "logger.h" #include "stream.h" @@ -42,7 +42,7 @@ struct conns { void * worker; }; -CLASS(Server) { +TR_CLASS(Server) { Logger logger; Sock sock; Sock sockSSL; diff --git a/include/session.h b/include/session.h index ccc68fa..97be928 100644 --- a/include/session.h +++ b/include/session.h @@ -27,13 +27,13 @@ #include #include -#include "class.h" +#include "trbase.h" // livetime of a session in seconds #define SESSION_LIVETIME 300 // 5 minutes -CLASS(Session) { +TR_CLASS(Session) { char id[37]; unsigned long hash; diff --git a/include/socket.h b/include/socket.h index 797aec1..74b2e3d 100644 --- a/include/socket.h +++ b/include/socket.h @@ -27,10 +27,10 @@ #include // for in_port_t -#include "class.h" +#include "trbase.h" #include "logger.h" -CLASS(Sock) { +TR_CLASS(Sock) { Logger log; in_port_t port; struct sockaddr_in addr; diff --git a/include/storage/storage.h b/include/storage/storage.h index 593f515..403985a 100644 --- a/include/storage/storage.h +++ b/include/storage/storage.h @@ -26,7 +26,7 @@ #include #include -#include "class.h" +#include "trbase.h" typedef enum e_StoragePutResults { @@ -37,7 +37,7 @@ typedef enum e_StoragePutResults { } StoragePutResult; -CLASS(Storage) { +TR_CLASS(Storage) { GDBM_FILE gdbm; char * db_name; }; diff --git a/include/stream/interface/reader.h b/include/stream/interface/reader.h index 8719099..5ff9079 100644 --- a/include/stream/interface/reader.h +++ b/include/stream/interface/reader.h @@ -27,15 +27,14 @@ #include +#include "trbase.h" #include "stream/stream.h" typedef ssize_t (* fptr_streamReaderRead)(void *, Stream); -extern const struct interface i_StreamReader; - -struct i_StreamReader { - const struct interface * const _; - fptr_streamReaderRead read; +TR_INTERFACE(StreamReader) { + TR_IFID; + fptr_streamReaderRead read; }; extern ssize_t streamReaderRead(void *, Stream); diff --git a/include/stream/interface/writer.h b/include/stream/interface/writer.h index 99d434d..19a50d3 100644 --- a/include/stream/interface/writer.h +++ b/include/stream/interface/writer.h @@ -27,15 +27,14 @@ #include +#include "trbase.h" #include "stream/stream.h" typedef ssize_t (* fptr_streamWriterWrite)(void *, Stream); -extern const struct interface i_StreamWriter; - -struct i_StreamWriter { - const struct interface * const _; - fptr_streamWriterWrite write; +TR_INTERFACE(StreamWriter) { + TR_IFID; + fptr_streamWriterWrite write; }; extern ssize_t streamWriterWrite(void *, Stream); diff --git a/include/stream/stream.h b/include/stream/stream.h index eb16104..bf16e7b 100644 --- a/include/stream/stream.h +++ b/include/stream/stream.h @@ -26,14 +26,14 @@ #include #include -#include "class.h" +#include "trbase.h" typedef enum e_StreamHandleType { STREAM_FD = 0, STREAM_SSL } StreamHandleType; -CLASS(Stream) { +TR_CLASS(Stream) { StreamHandleType type; union { int fd; diff --git a/include/tree.h b/include/tree.h index 49d9154..0accb44 100644 --- a/include/tree.h +++ b/include/tree.h @@ -23,7 +23,7 @@ #ifndef __TREE_H__ #define __TREE_H__ -#include "class.h" +#include "trbase.h" #define TREE_RIGHT(node) (NULL!=(node)?(node)->right:NULL) #define TREE_LEFT(node) (NULL!=(node)?(node)->left:NULL) @@ -114,7 +114,7 @@ enum rbColor {rbBlack=1, rbRed=2}; -CLASS(Tree) { +TR_CLASS(Tree) { void * data; enum rbColor color; diff --git a/include/user.h b/include/user.h index c3c89c3..fee02f0 100644 --- a/include/user.h +++ b/include/user.h @@ -25,12 +25,11 @@ #include -#include "class.h" +#include "trbase.h" #include "uuid.h" #include "auth.h" -#include "storage/storage.h" -CLASS(User) { +TR_CLASS(User) { unsigned long hash; AuthModule auth_type; diff --git a/include/utils/memory.h b/include/utils/memory.h deleted file mode 100644 index e1a8fc9..0000000 --- a/include/utils/memory.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * \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_MEMORY_H__ -#define __UTILS_MEMORY_H__ - -#define CSTRA(val) val, sizeof(val)-1 //!< Const STRing Argument - -#define MEM_FREE(seg) (memFree((void **)&(seg))) - -#include - -void * memMalloc(size_t); -void * memCalloc(size_t, size_t); -void memFree(void **); -size_t memGetSize(void *); -void memCleanup(); - -#endif // __UTILS_MEMORY_H__ - -// vim: set ts=4 sw=4: diff --git a/include/uuid.h b/include/uuid.h index a81fbbc..23eb2f9 100644 --- a/include/uuid.h +++ b/include/uuid.h @@ -33,13 +33,12 @@ #include #include -#include "class.h" -#include "commons.h" +#include "trbase.h" typedef char UuidString[37]; -CLASS(Uuid) { +TR_CLASS(Uuid) { union { uuid_t value; struct { diff --git a/src/Makefile.am b/src/Makefile.am index a5fd50b..dcc4a8c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,25 +3,18 @@ AUTOMAKE_OPTIONS = subdir-objects TRUTILS = utils/hash.c \ - utils/memory.c \ utils/http.c \ utils/daemonize.c \ utils/signalHandling.c \ utils/mime_type.c -TRBASESRC = interface/subject.c \ - interface/observer.c \ - interface/serializable.c \ - interface/indexable.c - -TRBASELIBS = class/libclass.la \ - cbuf/libcbuf.la \ - hash/libhash.la \ - queue/libqueue.la \ - logger/liblogger.la \ - tree/libtree.la \ - stream/libstream.la \ - uuid/libuuid.la +TRCOMMONLIBS = cbuf/libcbuf.la \ + hash/libhash.la \ + queue/libqueue.la \ + logger/liblogger.la \ + tree/libtree.la \ + stream/libstream.la \ + uuid/libuuid.la TRHTTPSERVER = http/libhttp.la \ asset/libasset.la \ @@ -36,21 +29,21 @@ TR = ./application/.libs/libapplication.a \ ./config/.libs/libconfig.a \ ./router/.libs/librouter.a -TRLIBS = -ltrutils -ltrhttpserver -ltrbase +TRLIBS = -ltrutils -ltrhttpserver -ltrcommon USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid -ldl AM_CFLAGS += -I../include/ bin_PROGRAMS = taskrambler -lib_LTLIBRARIES = libtrutils.la libtrbase.la libtrhttpserver.la +lib_LTLIBRARIES = libtrutils.la libtrcommon.la libtrhttpserver.la libtrutils_la_SOURCES = $(TRUTILS) libtrutils_la_CFLAGS = $(AM_CFLAGS) libtrutils_la_LIBADD = -libtrbase_la_SOURCES = $(TRBASESRC) -libtrbase_la_CFLAGS = $(AM_CFLAGS) -libtrbase_la_LIBADD = $(TRBASELIBS) +libtrcommon_la_SOURCES = +libtrcommon_la_CFLAGS = $(AM_CFLAGS) +libtrcommon_la_LIBADD = $(TRCOMMONLIBS) libtrhttpserver_la_SOURCES = libtrhttpserver_la_CFLAGS = $(AM_CFLAGS) @@ -62,6 +55,6 @@ taskrambler_LDADD = $(TRLIBS) $(TR) $(USEDLIBS) taskrambler_LDFLAGS = -Wl,--export-dynamic \ -Wl,--whole-archive,./application/.libs/libapplication.a,--no-whole-archive -SUBDIRS = asset auth cbuf class hash queue http \ +SUBDIRS = asset auth cbuf hash queue http \ logger server session socket stream tree application \ storage user config router uuid diff --git a/src/application/adapter/http/http.c b/src/application/adapter/http/http.c index ef6ddf4..74e0a16 100644 --- a/src/application/adapter/http/http.c +++ b/src/application/adapter/http/http.c @@ -24,13 +24,11 @@ #include -#include "class.h" +#include "trbase.h" #include "router.h" #include "application/application.h" #include "application/adapter/http.h" -#include "utils/memory.h" -#include "interface/observer.h" static int @@ -54,16 +52,16 @@ applicationAdapterHttpDtor(void * _this) void applicationAdapterHttpUpdate(void *, void *); -INIT_IFACE( - Class, +TR_INIT_IFACE( + TR_Class, applicationAdapterHttpCtor, applicationAdapterHttpDtor, NULL); -INIT_IFACE(Observer, applicationAdapterHttpUpdate); -CREATE_CLASS( +TR_INIT_IFACE(TR_Observer, applicationAdapterHttpUpdate); +TR_CREATE_CLASS( ApplicationAdapterHttp, NULL, - IFACE(Class), - IFACE(Observer)); + TR_IF(TR_Class), + TR_IF(TR_Observer)); // vim: set ts=4 sw=4: diff --git a/src/application/adapter/http/update.c b/src/application/adapter/http/update.c index 4d2bc0d..d4829e3 100644 --- a/src/application/adapter/http/update.c +++ b/src/application/adapter/http/update.c @@ -25,6 +25,7 @@ #include #include +#include "trbase.h" #include "application/application.h" #include "application/adapter/http.h" #include "hash.h" @@ -74,7 +75,7 @@ applicationAdapterHttpUpdate(void * _this, void * subject) nbuf = sprintf(buf, "sid=%s;Path=/", session->id); queuePut( worker->additional_headers, - new(HttpHeader, CSTRA("Set-Cookie"), buf, nbuf)); + TR_new(HttpHeader, CSTRA("Set-Cookie"), buf, nbuf)); worker->current_response = (HttpMessage)routerRoute( this->router, diff --git a/src/application/application.c b/src/application/application.c index a35b371..97f3356 100644 --- a/src/application/application.c +++ b/src/application/application.c @@ -24,13 +24,12 @@ #include -#include "class.h" +#include "trbase.h" #include "hash.h" #include "uuid.h" #include "application/application.h" #include "storage/storage.h" -#include "utils/memory.h" #include "config.h" static @@ -57,9 +56,9 @@ applicationCtor(void * _this, va_list * params) this->auth = va_arg(*params, void *); - this->active_sessions = memCalloc(SESSION_LIVETIME, sizeof(Hash)); + this->active_sessions = TR_calloc(SESSION_LIVETIME, sizeof(Hash)); for (i=0; iactive_sessions[i] = new(Hash); + this->active_sessions[i] = TR_new(Hash); } this->version = VERSION; @@ -75,18 +74,18 @@ applicationDtor(void * _this) Application this = _this; size_t i; - delete(this->user_namespace); + TR_delete(this->user_namespace); for (i=0; iactive_sessions[i]); + TR_delete(this->active_sessions[i]); } - MEM_FREE(this->active_sessions); - MEM_FREE(this->auth); + TR_MEM_FREE(this->active_sessions); + TR_MEM_FREE(this->auth); } -INIT_IFACE(Class, applicationCtor, applicationDtor, NULL); -CREATE_CLASS(Application, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, applicationCtor, applicationDtor, NULL); +TR_CREATE_CLASS(Application, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/application/controller/_get_credential_from_args.c b/src/application/controller/_get_credential_from_args.c index fb4831d..3add63e 100644 --- a/src/application/controller/_get_credential_from_args.c +++ b/src/application/controller/_get_credential_from_args.c @@ -22,11 +22,10 @@ #define _GNU_SOURCE +#include "trbase.h" #include "hash.h" #include "auth/credential.h" -#include "utils/memory.h" -#include "commons.h" int _controllerValidatePasswordRepeat(char *, size_t, char *, size_t); @@ -54,7 +53,7 @@ _controllerGetCredentialFromArgs(Hash args) return FALSE; } - return new(Credential, + return TR_new(Credential, CRED_PASSWORD, (char *)(email->value), email->nvalue, (char *)(password->value), password->nvalue); diff --git a/src/application/controller/_get_user_from_args.c b/src/application/controller/_get_user_from_args.c index 16cd562..112b8a7 100644 --- a/src/application/controller/_get_user_from_args.c +++ b/src/application/controller/_get_user_from_args.c @@ -22,12 +22,10 @@ #define _GNU_SOURCE +#include "trbase.h" #include "hash.h" #include "user.h" -#include "utils/memory.h" -#include "commons.h" - User _controllerGetUserFromArgs(Hash args) @@ -44,7 +42,7 @@ _controllerGetUserFromArgs(Hash args) return FALSE; } - return new(User, + return TR_new(User, (char *)(email->value), email->nvalue, (char *)(email->value), email->nvalue, (char *)(firstname->value), firstname->nvalue, diff --git a/src/application/controller/_process_user_create_args.c b/src/application/controller/_process_user_create_args.c index ee9448e..c0fe839 100644 --- a/src/application/controller/_process_user_create_args.c +++ b/src/application/controller/_process_user_create_args.c @@ -22,12 +22,11 @@ #define _GNU_SOURCE +#include "trbase.h" #include "hash.h" #include "user.h" #include "auth/credential.h" -#include "utils/memory.h" -#include "commons.h" User _controllerGetUserFromArgs(Hash args); Credential _controllerGetCredentialFromArgs(Hash args); @@ -39,8 +38,8 @@ _controllerProcessUserCreateArgs(Hash args, User * user, Credential * cred) *cred = _controllerGetCredentialFromArgs(args); if (NULL == *user || NULL == *cred) { - delete(*user); - delete(*cred); + TR_delete(*user); + TR_delete(*cred); return FALSE; } diff --git a/src/application/controller/_update_user_from_args.c b/src/application/controller/_update_user_from_args.c index 7fd6973..a3246bb 100644 --- a/src/application/controller/_update_user_from_args.c +++ b/src/application/controller/_update_user_from_args.c @@ -22,12 +22,10 @@ #define _GNU_SOURCE +#include "trbase.h" #include "hash.h" #include "user.h" -#include "utils/memory.h" -#include "commons.h" - int _controllerUpdateUserFromArgs(Hash args, User * user) @@ -45,13 +43,13 @@ _controllerUpdateUserFromArgs(Hash args, User * user) return FALSE; } - new_user = new(User, + new_user = TR_new(User, (char *)((*user)->username), *(*user)->nusername, (char *)(email->value), email->nvalue, (char *)(firstname->value), firstname->nvalue, (char *)(surname->value), surname->nvalue); - delete(*user); + TR_delete(*user); *user = new_user; return TRUE; diff --git a/src/application/controller/_validate_email.c b/src/application/controller/_validate_email.c index 1a0e6bc..1da99a1 100644 --- a/src/application/controller/_validate_email.c +++ b/src/application/controller/_validate_email.c @@ -22,13 +22,13 @@ #define _GNU_SOURCE +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" #include "auth/credential.h" #include "user.h" -#include "utils/memory.h" User _controllerCreateUserFromArgs(Hash args) @@ -49,7 +49,7 @@ _controllerCreateUserFromArgs(Hash args) return NULL; } - return new(User, + return TR_new(User, (char *)(email->value), email->nvalue, (char *)(firstname->value), firstname->nvalue, (char *)(surname->value), surname->nvalue); diff --git a/src/application/controller/_validate_password.c b/src/application/controller/_validate_password.c index e6a30e0..e0d609a 100644 --- a/src/application/controller/_validate_password.c +++ b/src/application/controller/_validate_password.c @@ -20,11 +20,10 @@ * along with this program. If not, see . */ +#include "trbase.h" #include "hash.h" #include "auth/credential.h" -#include "utils/memory.h" -#include "commons.h" int _controllerValidatePassword( diff --git a/src/application/controller/_validate_password_repeat.c b/src/application/controller/_validate_password_repeat.c index e2ece39..dc70b6a 100644 --- a/src/application/controller/_validate_password_repeat.c +++ b/src/application/controller/_validate_password_repeat.c @@ -20,12 +20,10 @@ * along with this program. If not, see . */ +#include "trbase.h" #include "hash.h" #include "auth/credential.h" -#include "utils/memory.h" -#include "commons.h" - int _controllerValidatePasswordRepeat( char * password, diff --git a/src/application/controller/authenticate/create.c b/src/application/controller/authenticate/create.c index 3f09f70..9f8d7a9 100644 --- a/src/application/controller/authenticate/create.c +++ b/src/application/controller/authenticate/create.c @@ -22,14 +22,13 @@ #define _GNU_SOURCE -#include "class.h" +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" #include "auth/credential.h" #include "user.h" -#include "utils/memory.h" char * controllerCurrentuserRead(Application, Session, Hash); @@ -56,7 +55,7 @@ controllerAuthenticateCreate( return NULL; } - credential = new(Credential, + credential = TR_new(Credential, CRED_PASSWORD, (char *)(username->value), username->nvalue, (char *)(password->value), password->nvalue); @@ -67,7 +66,7 @@ controllerAuthenticateCreate( response_data = controllerCurrentuserRead(application, session, NULL); } - delete(credential); + TR_delete(credential); return response_data; } diff --git a/src/application/controller/authenticate/delete.c b/src/application/controller/authenticate/delete.c index 85e15ed..3b14ff7 100644 --- a/src/application/controller/authenticate/delete.c +++ b/src/application/controller/authenticate/delete.c @@ -22,12 +22,10 @@ #define _GNU_SOURCE -#include "class.h" #include "application/application.h" #include "session.h" #include "hash.h" -#include "utils/memory.h" char * controllerCurrentuserRead(Application, Session, Hash); diff --git a/src/application/controller/currentuser/read.c b/src/application/controller/currentuser/read.c index 4a3796d..d643e21 100644 --- a/src/application/controller/currentuser/read.c +++ b/src/application/controller/currentuser/read.c @@ -25,13 +25,11 @@ #include #include -#include "class.h" +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" -#include "utils/memory.h" - #define USER_JSON \ "{\"username\":\"%s\",\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}" @@ -47,7 +45,7 @@ controllerCurrentuserRead(Application app, Session sess, Hash args) (NULL != sess->user)? sess->user->email : "", (NULL != sess->user)? sess->user->firstname : "", (NULL != sess->user)? sess->user->surname : ""); - buffer = memMalloc(nbuffer); + buffer = TR_malloc(nbuffer); nbuffer = sprintf(buffer, USER_JSON, (NULL != sess->user)? sess->user->username : "", (NULL != sess->user)? sess->user->email : "", diff --git a/src/application/controller/loc/read.c b/src/application/controller/loc/read.c index ba26370..06f4ebd 100644 --- a/src/application/controller/loc/read.c +++ b/src/application/controller/loc/read.c @@ -25,12 +25,11 @@ #include #include +#include "trbase.h" #include "application/application.h" #include "hash.h" #include "session.h" -#include "utils/memory.h" - #define LOC_JSON "{\"loc\":\"%s\"}" char * @@ -40,7 +39,7 @@ controllerLocRead(Application app, Session sess, Hash args) size_t nbuffer; nbuffer = snprintf(NULL, 0, LOC_JSON, app->loc? app->loc : ""); - buffer = memMalloc(nbuffer); + buffer = TR_malloc(nbuffer); sprintf(buffer, LOC_JSON, app->loc? app->loc : ""); return buffer; diff --git a/src/application/controller/randval/read.c b/src/application/controller/randval/read.c index 3c6dab7..d04d495 100644 --- a/src/application/controller/randval/read.c +++ b/src/application/controller/randval/read.c @@ -25,14 +25,14 @@ #include #include +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" -#include "utils/memory.h" - #define RANDVAL_JSON "{\"ctime\":%ld,\"vnext\":%ld,\"value\":\"%02d\"}" + char * controllerRandvalRead(Application app, Session sess, Hash args) { @@ -49,7 +49,7 @@ controllerRandvalRead(Application app, Session sess, Hash args) app->val->timestamp, remaining, app->val->value); - buffer = memMalloc(nbuffer); + buffer = TR_malloc(nbuffer); sprintf( buffer, RANDVAL_JSON, diff --git a/src/application/controller/sessinfo/read.c b/src/application/controller/sessinfo/read.c index 02b9df0..13e3169 100644 --- a/src/application/controller/sessinfo/read.c +++ b/src/application/controller/sessinfo/read.c @@ -25,12 +25,11 @@ #include #include +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" -#include "utils/memory.h" - #define SESSION_JSON "{\"id\":\"%s\",\"timeout\":%d,\"timeleft\":%ld}" @@ -47,7 +46,7 @@ controllerSessinfoRead( (NULL != session)? session->id : "", (NULL != session)? SESSION_LIVETIME : 0, (NULL != session)? session->livetime - time(NULL) : 0); - buffer = memMalloc(nbuffer); + buffer = TR_malloc(nbuffer); sprintf(buffer, SESSION_JSON, (NULL != session)? session->id : "", (NULL != session)? SESSION_LIVETIME : 0, diff --git a/src/application/controller/signup/create.c b/src/application/controller/signup/create.c index 8b34d0e..accdeeb 100644 --- a/src/application/controller/signup/create.c +++ b/src/application/controller/signup/create.c @@ -22,13 +22,13 @@ #define _GNU_SOURCE +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" #include "auth/credential.h" #include "user.h" -#include "utils/memory.h" char * controllerCurrentuserRead(Application, Session, Hash); int _controllerProcessUserCreateArgs(Hash, User *, Credential *); @@ -55,9 +55,9 @@ controllerSignupCreate( response_data = controllerCurrentuserRead(application, session, NULL); } - delete(credential); - delete(user); - delete(user_id); + TR_delete(credential); + TR_delete(user); + TR_delete(user_id); return response_data; diff --git a/src/application/controller/user/create.c b/src/application/controller/user/create.c index 9a4a197..00bd5b5 100644 --- a/src/application/controller/user/create.c +++ b/src/application/controller/user/create.c @@ -22,13 +22,13 @@ #define _GNU_SOURCE +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" #include "auth/credential.h" #include "user.h" -#include "utils/memory.h" char * controllerCurrentuserRead(Application, Session, Hash); int _controllerProcessUserCreateArgs(Hash, User *, Credential *); @@ -53,9 +53,9 @@ controllerUserCreate( response_data = controllerCurrentuserRead(application, session, NULL); } - delete(credential); - delete(user); - delete(user_id); + TR_delete(credential); + TR_delete(user); + TR_delete(user_id); return response_data; } diff --git a/src/application/controller/user/read.c b/src/application/controller/user/read.c index 5a3fa64..6b9f5e4 100644 --- a/src/application/controller/user/read.c +++ b/src/application/controller/user/read.c @@ -25,13 +25,11 @@ #include #include -#include "class.h" +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" -#include "utils/memory.h" - #define USER_JSON \ "{\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}" @@ -49,7 +47,7 @@ controllerUserRead(Application app, Session sess, Hash args) user->email, user->firstname, user->surname); - buffer = memMalloc(nbuffer); + buffer = TR_malloc(nbuffer); nbuffer = sprintf(buffer, USER_JSON, user->email, user->firstname, diff --git a/src/application/controller/user/update.c b/src/application/controller/user/update.c index 7a41b83..6fd4b94 100644 --- a/src/application/controller/user/update.c +++ b/src/application/controller/user/update.c @@ -22,13 +22,12 @@ #define _GNU_SOURCE +#include "trbase.h" #include "application/application.h" #include "session.h" #include "hash.h" #include "user.h" -#include "utils/memory.h" -#include "commons.h" char * controllerCurrentuserRead(Application, Session, Hash); int _controllerUpdateUserFromArgs(Hash, User *); @@ -49,7 +48,7 @@ controllerUserUpdate( if (0 == uuidCompare(uuidZero, user_id)) { return NULL; } - delete(user_id); + TR_delete(user_id); return controllerCurrentuserRead(application, session, NULL); } diff --git a/src/application/controller/version/read.c b/src/application/controller/version/read.c index ed2d6c9..a546238 100644 --- a/src/application/controller/version/read.c +++ b/src/application/controller/version/read.c @@ -25,12 +25,11 @@ #include #include +#include "trbase.h" #include "application/application.h" #include "hash.h" #include "session.h" -#include "utils/memory.h" - #define VERSION_JSON "{\"version\":\"%s\"}" char * @@ -40,7 +39,7 @@ controllerVersionRead(Application app, Session sess, Hash args) size_t nbuffer; nbuffer = snprintf(NULL, 0, VERSION_JSON, app->version? app->version : ""); - buffer = memMalloc(nbuffer); + buffer = TR_malloc(nbuffer); sprintf(buffer, VERSION_JSON, app->version? app->version : ""); return buffer; diff --git a/src/application/create_user.c b/src/application/create_user.c index 278e259..7ee8c81 100644 --- a/src/application/create_user.c +++ b/src/application/create_user.c @@ -26,19 +26,13 @@ #include #include -#include "class.h" +#include "trbase.h" #include "auth.h" #include "user.h" #include "uuid.h" #include "storage/storage.h" #include "application/application.h" -#include "interface/serializable.h" -#include "interface/indexable.h" - -#include "utils/memory.h" -#include "commons.h" - Uuid applicationCreateUser( Application this, @@ -49,8 +43,8 @@ applicationCreateUser( size_t nuser_serialized; Uuid index; - index = indexUuid(user, this->user_namespace); - serialize(user, (unsigned char **)&user_serialized, &nuser_serialized); + index = TR_indexUuid(user, this->user_namespace); + TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized); if (SPR_OK != storagePut( this->users, @@ -62,7 +56,7 @@ applicationCreateUser( return uuidZero; } - MEM_FREE(user_serialized); + TR_MEM_FREE(user_serialized); if (! applicationUpdatePassword(this, cred, user)) { /** diff --git a/src/application/get_user.c b/src/application/get_user.c index 09c9bff..f30368b 100644 --- a/src/application/get_user.c +++ b/src/application/get_user.c @@ -24,19 +24,13 @@ #include #include -#include "class.h" +#include "trbase.h" #include "auth.h" #include "user.h" #include "uuid.h" #include "storage/storage.h" #include "application/application.h" -#include "interface/serializable.h" -#include "interface/indexable.h" - -#include "utils/memory.h" -#include "commons.h" - User applicationGetUser(Application this, Uuid uuid) { @@ -52,11 +46,11 @@ applicationGetUser(Application this, Uuid uuid) &nuser_serialized); if (NULL != user_serialized) { - unserialize( + TR_unserialize( user, (unsigned char *)user_serialized, nuser_serialized); - MEM_FREE(user_serialized); + TR_MEM_FREE(user_serialized); } return user; diff --git a/src/application/login.c b/src/application/login.c index 52eec44..4016c64 100644 --- a/src/application/login.c +++ b/src/application/login.c @@ -26,15 +26,10 @@ #include #include -#include "class.h" +#include "trbase.h" #include "auth.h" #include "uuid.h" #include "storage/storage.h" - -#include "interface/serializable.h" -#include "interface/indexable.h" - -#include "utils/memory.h" #include "application/application.h" @@ -47,11 +42,11 @@ applicationLogin( Uuid search; AuthModule auth_module; - User user = new(User, NULL); + User user = TR_new(User, NULL); user->username = CRED_PWD(credential).user; user->nusername = &CRED_PWD(credential).nuser; - search = indexUuid(user, this->user_namespace); + search = TR_indexUuid(user, this->user_namespace); auth_module = authenticate(this->auth, credential, search); @@ -71,11 +66,11 @@ applicationLogin( &nuser_serialized); if (NULL != user_serialized) { - unserialize( + TR_unserialize( session->user, (unsigned char *)user_serialized, nuser_serialized); - MEM_FREE(user_serialized); + TR_MEM_FREE(user_serialized); } else { /** * this is a user authenticated via another method @@ -87,15 +82,15 @@ applicationLogin( * the delete will not free it. */ session->user->username = NULL; - delete(session->user); - session->user = new(User, + TR_delete(session->user); + session->user = TR_new(User, CRED_PWD(credential).user, CRED_PWD(credential).nuser, CSTRA(""), CSTRA(""), CSTRA("")); - serialize( + TR_serialize( session->user, (unsigned char **)&user_serialized, &nuser_serialized); @@ -110,7 +105,7 @@ applicationLogin( sizeof((search->uuid).value), user_serialized, nuser_serialized); - MEM_FREE(user_serialized); + TR_MEM_FREE(user_serialized); } session->user->auth_type = auth_module; @@ -120,11 +115,11 @@ applicationLogin( break; } - delete(search); + TR_delete(search); return TRUE; } - delete(search); + TR_delete(search); return FALSE; } diff --git a/src/application/logout.c b/src/application/logout.c index 5f9993a..0d1ccae 100644 --- a/src/application/logout.c +++ b/src/application/logout.c @@ -22,17 +22,16 @@ #define _GNU_SOURCE -#include "class.h" +#include "trbase.h" #include "auth.h" -#include "utils/memory.h" #include "application/application.h" void applicationLogout(Application this, Session session) { - delete(session->user); + TR_delete(session->user); } // vim: set ts=4 sw=4: diff --git a/src/application/session_cleanup.c b/src/application/session_cleanup.c index 0625464..4c408f4 100644 --- a/src/application/session_cleanup.c +++ b/src/application/session_cleanup.c @@ -25,12 +25,11 @@ #include #include -#include "class.h" +#include "trbase.h" #include "session.h" #include "hash.h" #include "application/application.h" -#include "utils/memory.h" void applicationSessionCleanup(Application this, time_t now) @@ -43,7 +42,7 @@ applicationSessionCleanup(Application this, time_t now) } if (0 < expired && SESSION_LIVETIME > expired) { - Hash * tmp_buf = memCalloc(SESSION_LIVETIME, sizeof(Hash)); + Hash * tmp_buf = TR_calloc(SESSION_LIVETIME, sizeof(Hash)); memcpy( &(tmp_buf[expired]), @@ -54,7 +53,7 @@ applicationSessionCleanup(Application this, time_t now) &(this->active_sessions[SESSION_LIVETIME - expired]), expired * sizeof(Hash)); - MEM_FREE(this->active_sessions); + TR_MEM_FREE(this->active_sessions); this->active_sessions = tmp_buf; } diff --git a/src/application/session_get.c b/src/application/session_get.c index d15e04c..eede20a 100644 --- a/src/application/session_get.c +++ b/src/application/session_get.c @@ -24,13 +24,10 @@ #include -#include "class.h" #include "session.h" #include "hash.h" #include "application/application.h" -#include "utils/memory.h" - Session applicationSessionGet(Application this, const char * sid) diff --git a/src/application/session_start.c b/src/application/session_start.c index fcbeed2..2831bb8 100644 --- a/src/application/session_start.c +++ b/src/application/session_start.c @@ -25,17 +25,16 @@ #include #include -#include "class.h" +#include "trbase.h" #include "session.h" #include "hash.h" #include "application/application.h" -#include "utils/memory.h" Session applicationSessionStart(Application this) { - Session sess = new(Session); + Session sess = TR_new(Session); hashAdd((this->active_sessions)[0], sess); diff --git a/src/application/session_stop.c b/src/application/session_stop.c index 33a3152..8e10db8 100644 --- a/src/application/session_stop.c +++ b/src/application/session_stop.c @@ -24,12 +24,9 @@ #include -#include "class.h" #include "session.h" #include "application/application.h" -#include "utils/memory.h" - void applicationSessionStop(Application this, Session session) diff --git a/src/application/update_password.c b/src/application/update_password.c index 730f4af..e8c17f5 100644 --- a/src/application/update_password.c +++ b/src/application/update_password.c @@ -26,16 +26,12 @@ #include #include -#include "class.h" +#include "trbase.h" #include "auth.h" #include "user.h" #include "storage/storage.h" #include "application/application.h" -#include "interface/indexable.h" - -#include "utils/memory.h" -#include "commons.h" int applicationUpdatePassword( @@ -57,16 +53,16 @@ applicationUpdatePassword( } memcpy(hash_data, salt, SALT_SIZE); - MEM_FREE(salt); + TR_MEM_FREE(salt); - index = indexUuid(user, this->user_namespace); + index = TR_indexUuid(user, this->user_namespace); storageUpdate( this->passwords, (char *)(index->uuid).value, sizeof((index->uuid).value), (char *)hash_data, SALT_SIZE + HASH_SIZE); - delete(index); + TR_delete(index); return TRUE; } diff --git a/src/application/update_user.c b/src/application/update_user.c index 63d6f7c..41b36a6 100644 --- a/src/application/update_user.c +++ b/src/application/update_user.c @@ -26,18 +26,13 @@ #include #include -#include "class.h" +#include "trbase.h" #include "auth.h" #include "user.h" #include "uuid.h" #include "storage/storage.h" #include "application/application.h" -#include "interface/serializable.h" -#include "interface/indexable.h" - -#include "utils/memory.h" -#include "commons.h" Uuid applicationUpdateUser( @@ -48,8 +43,8 @@ applicationUpdateUser( size_t nuser_serialized; Uuid index; - index = indexUuid(user, this->user_namespace); - serialize(user, (unsigned char **)&user_serialized, &nuser_serialized); + index = TR_indexUuid(user, this->user_namespace); + TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized); if (SPR_OK != storageUpdate( this->users, @@ -61,7 +56,7 @@ applicationUpdateUser( return uuidZero; } - MEM_FREE(user_serialized); + TR_MEM_FREE(user_serialized); return index; } diff --git a/src/asset/asset.c b/src/asset/asset.c index 1d69b64..05fb493 100644 --- a/src/asset/asset.c +++ b/src/asset/asset.c @@ -37,7 +37,7 @@ #include -#include "class.h" +#include "trbase.h" #include "asset.h" #include "hash.h" @@ -138,8 +138,8 @@ assetHandleDouble(void * _this, void * _doub) { } -INIT_IFACE(Class, assetCtor, assetDtor, NULL); -INIT_IFACE(Hashable, assetGetHash, assetHandleDouble); -CREATE_CLASS(Asset, NULL, IFACE(Class), IFACE(Hashable)); +TR_INIT_IFACE(TR_Class, assetCtor, assetDtor, NULL); +TR_INIT_IFACE(Hashable, assetGetHash, assetHandleDouble); +TR_CREATE_CLASS(Asset, NULL, TR_IF(TR_Class), TR_IF(Hashable)); // vim: set ts=4 sw=4: diff --git a/src/asset/pool.c b/src/asset/pool.c index 356c55b..9e1adbe 100644 --- a/src/asset/pool.c +++ b/src/asset/pool.c @@ -25,7 +25,7 @@ // for strlen -#include "class.h" +#include "trbase.h" #include "asset.h" #include "hash.h" @@ -36,7 +36,7 @@ inline void freeAsset(const void * _node) { - delete(_node); + TR_delete(_node); } Asset @@ -45,13 +45,13 @@ assetPoolGet(const char * path, size_t npath) Asset asset = NULL; if (NULL == asset_pool) { - asset_pool = new(Hash); + asset_pool = TR_new(Hash); } else { asset = hashGet(asset_pool, path, npath); } if (NULL == asset) { - asset = new(Asset, path, npath); + asset = TR_new(Asset, path, npath); if (NULL != asset) { hashAdd(asset_pool, asset); } @@ -75,9 +75,11 @@ assetPoolRelease(Asset asset) asset_pool, asset->fname, asset->nfname); if (found == asset) { - delete(found); + TR_delete(found); } else { - // this should never happen....error log... + /** + * \todo this should never happen....error log... + */ } } @@ -89,7 +91,7 @@ assetPoolCleanup(void) { if (NULL != asset_pool) { hashEach(asset_pool, freeAsset); - delete(asset_pool); + TR_delete(asset_pool); } } diff --git a/src/auth/auth.c b/src/auth/auth.c index 9775269..c5f3100 100644 --- a/src/auth/auth.c +++ b/src/auth/auth.c @@ -26,10 +26,8 @@ #include #include -#include "class.h" +#include "trbase.h" #include "uuid.h" -#include "utils/memory.h" -#include "commons.h" #include "auth.h" #include "auth/credential.h" @@ -57,7 +55,7 @@ authDtor(void * _this) int i; for (i=1; i<=MAX_AUTH; i++) { - delete(this->auth[i]); + TR_delete(this->auth[i]); } } @@ -77,8 +75,8 @@ authAuthenticate(void * _this, Credential cred, Uuid user_index) return FALSE; } -INIT_IFACE(Class, authCtor, authDtor, NULL); -INIT_IFACE(Auth, authAuthenticate); -CREATE_CLASS(Auth, NULL, IFACE(Class), IFACE(Auth)); +TR_INIT_IFACE(TR_Class, authCtor, authDtor, NULL); +TR_INIT_IFACE(Auth, authAuthenticate); +TR_CREATE_CLASS(Auth, NULL, TR_IF(TR_Class), TR_IF(Auth)); // vim: set ts=4 sw=4: diff --git a/src/auth/create.c b/src/auth/create.c index e5923ef..5a57712 100644 --- a/src/auth/create.c +++ b/src/auth/create.c @@ -23,11 +23,10 @@ #include #include -#include "class.h" +#include "trbase.h" #include "auth.h" #include "auth/ldap.h" #include "auth/storage.h" -#include "commons.h" int authCreate(Auth this, AuthModule module, ...) @@ -35,18 +34,18 @@ authCreate(Auth this, AuthModule module, ...) va_list params; if (NULL != this->auth[module]) { - delete(this->auth[module]); + TR_delete(this->auth[module]); } va_start(params, module); switch (module) { case AUTH_LDAP: - this->auth[module] = newParams(AuthLdap, ¶ms); + this->auth[module] = TR_newv(AuthLdap, ¶ms); break; case AUTH_STORAGE: - this->auth[module] = newParams(AuthStorage, ¶ms); + this->auth[module] = TR_newv(AuthStorage, ¶ms); break; } diff --git a/src/auth/credential.c b/src/auth/credential.c index fb9c306..25b00a7 100644 --- a/src/auth/credential.c +++ b/src/auth/credential.c @@ -25,9 +25,7 @@ #include #include -#include "class.h" -#include "utils/memory.h" - +#include "trbase.h" #include "auth/credential.h" static @@ -48,11 +46,11 @@ credentialCtor(void * _this, va_list * params) pass = va_arg(* params, char*); CRED_PWD(this).npass = va_arg(* params, size_t); - CRED_PWD(this).user = memMalloc(CRED_PWD(this).nuser + 1); + CRED_PWD(this).user = TR_malloc(CRED_PWD(this).nuser + 1); CRED_PWD(this).user[CRED_PWD(this).nuser] = 0; memcpy(CRED_PWD(this).user, user, CRED_PWD(this).nuser); - CRED_PWD(this).pass = memMalloc(CRED_PWD(this).npass + 1); + CRED_PWD(this).pass = TR_malloc(CRED_PWD(this).npass + 1); CRED_PWD(this).pass[CRED_PWD(this).npass] = 0; memcpy(CRED_PWD(this).pass, pass, CRED_PWD(this).npass); } @@ -73,13 +71,13 @@ credentialDtor(void * _this) switch(this->type) { case CRED_PASSWORD: - MEM_FREE(CRED_PWD(this).user); - MEM_FREE(CRED_PWD(this).pass); + TR_MEM_FREE(CRED_PWD(this).user); + TR_MEM_FREE(CRED_PWD(this).pass); break; } } -INIT_IFACE(Class, credentialCtor, credentialDtor, NULL); -CREATE_CLASS(Credential, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, credentialCtor, credentialDtor, NULL); +TR_CREATE_CLASS(Credential, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/auth/interface/auth.c b/src/auth/interface/auth.c index a2745d6..e5156a4 100644 --- a/src/auth/interface/auth.c +++ b/src/auth/interface/auth.c @@ -25,17 +25,14 @@ #include "auth/credential.h" #include "auth/interface/auth.h" -const struct interface i_Auth = { - "auth", - 1 -}; +TR_CREATE_INTERFACE(Auth, 1); int authenticate(void * auth, Credential cred, Uuid user_index) { int ret; - RETCALL(auth, Auth, authenticate, ret, cred, user_index); + TR_RETCALL(auth, Auth, authenticate, ret, cred, user_index); return ret; } diff --git a/src/auth/ldap.c b/src/auth/ldap.c index 82c9f8e..dc64f72 100644 --- a/src/auth/ldap.c +++ b/src/auth/ldap.c @@ -26,10 +26,8 @@ #include #include -#include "class.h" +#include "trbase.h" #include "uuid.h" -#include "utils/memory.h" -#include "commons.h" #include "auth/ldap.h" #include "auth/credential.h" @@ -43,7 +41,7 @@ authLdapCtor(void * _this, va_list * params) char * url = va_arg(*params, char*); char * base_dn; - this->url = memMalloc(strlen(url) + 1); + this->url = TR_malloc(strlen(url) + 1); strcpy(this->url, url); this->version = 3; @@ -51,7 +49,7 @@ authLdapCtor(void * _this, va_list * params) base_dn = va_arg(* params, char *); this->nbase_dn = va_arg(* params, size_t); - this->base_dn = memMalloc(this->nbase_dn + 1); + this->base_dn = TR_malloc(this->nbase_dn + 1); this->base_dn[this->nbase_dn] = 0; memcpy(this->base_dn, base_dn, this->nbase_dn); @@ -64,8 +62,8 @@ authLdapDtor(void * _this) { AuthLdap this = _this; - MEM_FREE(this->base_dn); - MEM_FREE(this->url); + TR_MEM_FREE(this->base_dn); + TR_MEM_FREE(this->url); } static @@ -118,8 +116,8 @@ authLdapAuthenticate(void * _this, Credential cred, Uuid user_index) return FALSE; } -INIT_IFACE(Class, authLdapCtor, authLdapDtor, NULL); -INIT_IFACE(Auth, authLdapAuthenticate); -CREATE_CLASS(AuthLdap, NULL, IFACE(Class), IFACE(Auth)); +TR_INIT_IFACE(TR_Class, authLdapCtor, authLdapDtor, NULL); +TR_INIT_IFACE(Auth, authLdapAuthenticate); +TR_CREATE_CLASS(AuthLdap, NULL, TR_IF(TR_Class), TR_IF(Auth)); // vim: set ts=4 sw=4: diff --git a/src/auth/storage/hash_pw.c b/src/auth/storage/hash_pw.c index 8fad687..804e83c 100644 --- a/src/auth/storage/hash_pw.c +++ b/src/auth/storage/hash_pw.c @@ -25,10 +25,8 @@ #include #include -#include "class.h" +#include "trbase.h" #include "auth/storage.h" -#include "utils/memory.h" -#include "commons.h" /* * I have to hash the passwords, maybe this will move in @@ -78,9 +76,9 @@ hash_pw( unsigned char ** salt) { if (NULL == *salt) { - *salt = memCalloc(SALT_SIZE, sizeof(unsigned char)); + *salt = TR_calloc(SALT_SIZE, sizeof(unsigned char)); if (0 > RAND_pseudo_bytes(*salt, SALT_SIZE)) { - MEM_FREE(*salt); + TR_MEM_FREE(*salt); return FALSE; } } @@ -94,7 +92,7 @@ hash_pw( EVP_sha512(), HASH_SIZE, hash)) { - MEM_FREE(*salt); + TR_MEM_FREE(*salt); return FALSE; } diff --git a/src/auth/storage/storage.c b/src/auth/storage/storage.c index 4210ebc..348226a 100644 --- a/src/auth/storage/storage.c +++ b/src/auth/storage/storage.c @@ -20,13 +20,11 @@ * along with this program. If not, see . */ -#include "class.h" +#include "trbase.h" #include "storage/storage.h" #include "auth.h" #include "uuid.h" #include "user.h" -#include "commons.h" -#include "utils/memory.h" static int @@ -77,21 +75,21 @@ authStorageAuthenticate(void * _this, Credential cred, Uuid user_index) CRED_PWD(cred).npass, current_hash, &found_hash)) { - MEM_FREE(found_hash); + TR_MEM_FREE(found_hash); return FALSE; } if (0 != memcmp(current_hash, found_hash+SALT_SIZE, HASH_SIZE)) { - MEM_FREE(found_hash); + TR_MEM_FREE(found_hash); return FALSE; } - MEM_FREE(found_hash); + TR_MEM_FREE(found_hash); return TRUE; } -INIT_IFACE(Class, authStorageCtor, authStorageDtor, NULL); -INIT_IFACE(Auth, authStorageAuthenticate); -CREATE_CLASS(AuthStorage, NULL, IFACE(Class), IFACE(Auth)); +TR_INIT_IFACE(TR_Class, authStorageCtor, authStorageDtor, NULL); +TR_INIT_IFACE(Auth, authStorageAuthenticate); +TR_CREATE_CLASS(AuthStorage, NULL, TR_IF(TR_Class), TR_IF(Auth)); // vim: set ts=4 sw=4: diff --git a/src/cbuf/cbuf.c b/src/cbuf/cbuf.c index a2b6e1c..a313422 100644 --- a/src/cbuf/cbuf.c +++ b/src/cbuf/cbuf.c @@ -33,9 +33,7 @@ #include #include -#include "class.h" -#include "utils/memory.h" - +#include "trbase.h" #include "cbuf.h" @@ -53,15 +51,15 @@ cbufCtor(void * _this, va_list * params) int shm; char * data; - this->shm_name = memMalloc(strlen(shm_name) + 7 + 2); + this->shm_name = TR_malloc(strlen(shm_name) + 7 + 2); sprintf(this->shm_name, "/%06d_%s", getpid(), shm_name); /** * align size at page boundary. * increase as neccessary */ - size = va_arg(*params, size_t); - size = (0 >= size)? 1 : (0 != size%psize)? (size/psize)+1 : size/psize; + size = va_arg(*params, size_t); + size = (0 >= size)? 1 : (0 != size%psize)? (size/psize)+1 : size/psize; this->bsize = psize * size; while (-1 == state) { @@ -110,7 +108,7 @@ cbufDtor(void * _this) { Cbuf this = _this; - MEM_FREE(this->shm_name); + TR_MEM_FREE(this->shm_name); if (NULL != this->data && MAP_FAILED != this->data) { munmap(this->data, this->bsize << 1); @@ -119,7 +117,7 @@ cbufDtor(void * _this) this->data = NULL; } -INIT_IFACE(Class, cbufCtor, cbufDtor, NULL); -CREATE_CLASS(Cbuf, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, cbufCtor, cbufDtor, NULL); +TR_CREATE_CLASS(Cbuf, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/cbuf/is_locked.c b/src/cbuf/is_locked.c index 097bd69..449ceb6 100644 --- a/src/cbuf/is_locked.c +++ b/src/cbuf/is_locked.c @@ -22,8 +22,6 @@ #include "cbuf.h" -#include "commons.h" - Bool cbufIsLocked(Cbuf this) { diff --git a/src/class/Makefile.am b/src/class/Makefile.am deleted file mode 100644 index 118d65b..0000000 --- a/src/class/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = libclass.la - -libclass_la_SOURCES = interface.c interface/i_class.c -libclass_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/class/interface.c b/src/class/interface.c deleted file mode 100644 index 661561b..0000000 --- a/src/class/interface.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * \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/interface.h" -#include "commons.h" - -static -inline -int -comp(const void * _a, const void * _b) -{ - const struct interface * a = **(const struct interface ***)_a; - const struct interface * b = **(const struct interface ***)_b; - return ((a)<(b))? -1 : ((a)>(b))? 1 : 0; -} - -/** - * this one is important in selector functions to get the correct interface - * implementation of a class. - */ -iface_ptr -interfaceGet(iface_impl_ptr iface_impl, const iface_ptr _iface) -{ - const iface_ptr * iface = &_iface; - iface_ptr * found; - - if (! iface_impl->simpl) { - qsort((void**)(iface_impl->impl), iface_impl->nimpl, sizeof(iface_ptr), comp); - iface_impl->simpl=TRUE; - } - - found = bsearch( - &iface, - iface_impl->impl, - iface_impl->nimpl, - sizeof(iface_ptr), - comp); - - return found? *found : (iface_ptr)NULL; -} - -// vim: set ts=4 sw=4: diff --git a/src/class/interface/i_class.c b/src/class/interface/i_class.c deleted file mode 100644 index 25b1608..0000000 --- a/src/class/interface/i_class.c +++ /dev/null @@ -1,99 +0,0 @@ -/** - * \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 "class/class.h" -#include "class/interface/class.h" - -#include "utils/memory.h" - - -const -struct interface i_Class = { - "class", - 3 -}; - -void * -classNewParams(class_ptr class, va_list * params) -{ - void * object = memCalloc(1, class->object_size + sizeof(void*)); - int ret; - - * (class_ptr *)object = class; - object += sizeof(void*); - - RETCALL(object, Class, ctor, ret, params); - - if (-1 == ret) { - classDelete(&object); - } - - return object; -} - -void * -classNew(class_ptr class, ...) -{ - va_list params; - void * object; - - va_start(params, class); - object = classNewParams(class, ¶ms); - va_end(params); - - return object; -} - -void -classDelete(void ** object) -{ - if (NULL != *object) { - void * mem; - - CALL(*object, Class, dtor); - - mem = *object - sizeof(void*); - MEM_FREE(mem); - *object = NULL; - } -} - -void * -classClone(void * _object) -{ - class_ptr class = GET_CLASS(_object); - void * object = memCalloc(1, class->object_size + sizeof(void*)); - - * (class_ptr *)object = class; - object += sizeof(void*); - -#undef clone - CALL(object, Class, clone, _object); - - return object; -} - -// vim: set ts=4 sw=4: diff --git a/src/config/config.c b/src/config/config.c index af85bf5..45711a1 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -26,10 +26,9 @@ #include #include -#include "class.h" +#include "trbase.h" #include "config/config.h" #include "config/value.h" -#include "utils/memory.h" static int @@ -42,17 +41,17 @@ configCtor(void * _this, va_list * params) char * cnf_file = va_arg(*params, char *); size_t ncnf_file = strlen(cnf_file); - this->cnf_file = memMalloc(ncnf_file + 1); + this->cnf_file = TR_malloc(ncnf_file + 1); memcpy(this->cnf_file, cnf_file, ncnf_file); this->cnf_file[ncnf_file] = '\0'; handle = fopen(this->cnf_file, "r"); if (NULL == handle) { - MEM_FREE(this->cnf_file); + TR_MEM_FREE(this->cnf_file); return -1; } - this->config = new(Hash); + this->config = TR_new(Hash); line[MAX_CONFIG_LINE] = '\0'; @@ -99,7 +98,7 @@ configCtor(void * _this, va_list * params) if (0 != nkey && 0 != nvalue) { hashAdd( this->config, - new(ConfigValue, key, nkey, value, nvalue)); + TR_new(ConfigValue, key, nkey, value, nvalue)); } } @@ -108,15 +107,16 @@ configCtor(void * _this, va_list * params) return 0; } -static void configDtor(void * _this) +static +void configDtor(void * _this) { Config this = _this; - MEM_FREE(this->cnf_file); - delete(this->config); + TR_MEM_FREE(this->cnf_file); + TR_delete(this->config); } -INIT_IFACE(Class, configCtor, configDtor, NULL); -CREATE_CLASS(Config, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, configCtor, configDtor, NULL); +TR_CREATE_CLASS(Config, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/config/get.c b/src/config/get.c index 5a2babc..5e3c320 100644 --- a/src/config/get.c +++ b/src/config/get.c @@ -22,7 +22,6 @@ #include -#include "class.h" #include "hash/hash.h" #include "config/config.h" #include "config/value.h" diff --git a/src/config/value.c b/src/config/value.c index b9628b6..7cd961c 100644 --- a/src/config/value.c +++ b/src/config/value.c @@ -25,9 +25,8 @@ #include #include -#include "class.h" +#include "trbase.h" #include "config/value.h" -#include "utils/memory.h" #include "utils/hash.h" static @@ -53,7 +52,7 @@ configValueCtor(void * _this, va_list * params) || ('\'' == value[0] && '\'' == value[nvalue-1])) { this->type = CONFIG_VALUE_STRING; - (this->value).string = memMalloc(nvalue-1); + (this->value).string = TR_malloc(nvalue-1); (this->value).string[nvalue-2] = '\0'; memcpy((this->value).string, value+1, nvalue-2); this->nvalue = nvalue; @@ -73,7 +72,7 @@ configValueDtor(void * _this) ConfigValue this = _this; if (CONFIG_VALUE_STRING == this->type) { - MEM_FREE((this->value).string); + TR_MEM_FREE((this->value).string); } } @@ -93,8 +92,8 @@ configValueHandleDouble(void * _this, void * _double) /* right now I do nothing...but I could :D */ } -INIT_IFACE(Class, configValueCtor, configValueDtor, NULL); -INIT_IFACE(Hashable, configValueGetHash, configValueHandleDouble); -CREATE_CLASS(ConfigValue, NULL, IFACE(Class), IFACE(Hashable)); +TR_INIT_IFACE(TR_Class, configValueCtor, configValueDtor, NULL); +TR_INIT_IFACE(Hashable, configValueGetHash, configValueHandleDouble); +TR_CREATE_CLASS(ConfigValue, NULL, TR_IF(TR_Class), TR_IF(Hashable)); // vim: set ts=4 sw=4: diff --git a/src/hash/add.c b/src/hash/add.c index feb287f..abcd537 100644 --- a/src/hash/add.c +++ b/src/hash/add.c @@ -23,7 +23,6 @@ #include #include "hash.h" -#include "class.h" static inline @@ -55,7 +54,7 @@ hashAdd(Hash this, void * operand) if (operand != found) { hashableHandleDouble(found, operand); - delete(operand); + TR_delete(operand); } return found; diff --git a/src/hash/cleanup.c b/src/hash/cleanup.c index 4c2544a..539f4c4 100644 --- a/src/hash/cleanup.c +++ b/src/hash/cleanup.c @@ -21,14 +21,14 @@ */ #include "hash/hash.h" -#include "class.h" +#include "trbase.h" static inline void tDelete(const void * node, const int depth) { - delete(node); + TR_delete(node); } void diff --git a/src/hash/hash.c b/src/hash/hash.c index 1e4432d..574c7d4 100644 --- a/src/hash/hash.c +++ b/src/hash/hash.c @@ -26,7 +26,7 @@ #include #include "hash/hash.h" -#include "class.h" +#include "trbase.h" static int @@ -40,7 +40,7 @@ inline void tDelete(const void * node, const int depth) { - delete(node); + TR_delete(node); } static @@ -52,7 +52,7 @@ hashDtor(void * _this) hashCleanup(this); } -INIT_IFACE(Class, hashCtor, hashDtor, NULL); -CREATE_CLASS(Hash, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, hashCtor, hashDtor, NULL); +TR_CREATE_CLASS(Hash, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/hash/interface/hashable.c b/src/hash/interface/hashable.c index 6c0bc7f..5b7b2ad 100644 --- a/src/hash/interface/hashable.c +++ b/src/hash/interface/hashable.c @@ -24,36 +24,17 @@ #include #include -#include "class.h" +#include "trbase.h" #include "hash/interface/hashable.h" -const struct interface i_Hashable = { - "hashable", - 2 -}; +TR_CREATE_INTERFACE(Hashable, 2); unsigned long hashableGetHash(void * hashable) { unsigned long ret; - //RETCALL(hashable, Hashable, getHash, ret); - do { - struct i_Hashable * iface; - //_CALL(GET_CLASS(hashable), Hashable, getHash); - do { - class_ptr class = GET_CLASS(hashable); - iface = (struct i_Hashable *)IFACE_GET(class, &i_Hashable); - while ((NULL == iface || NULL == iface->getHash) && HAS_PARENT(class)) { - class = class->parent; - iface = (struct i_Hashable *)IFACE_GET(class, &i_Hashable); - } - assert(NULL != iface->getHash); - } while(0); - - ret = iface->getHash(hashable); - } while(0); - + TR_RETCALL(hashable, Hashable, getHash, ret); return ret; } @@ -61,7 +42,7 @@ hashableGetHash(void * hashable) void hashableHandleDouble(void * hashable, void * new_hashable) { - CALL(hashable, Hashable, handleDouble, new_hashable); + TR_CALL(hashable, Hashable, handleDouble, new_hashable); } // vim: set ts=4 sw=4: diff --git a/src/hash/value.c b/src/hash/value.c index 77ffe1e..f5b495d 100644 --- a/src/hash/value.c +++ b/src/hash/value.c @@ -25,11 +25,8 @@ #include #include -#include "class.h" +#include "trbase.h" #include "utils/hash.h" -#include "utils/memory.h" -#include "commons.h" - #include "hash/value.h" #include "hash/interface/hashable.h" @@ -45,14 +42,14 @@ hashValueCtor(void * _this, va_list * params) value = va_arg(* params, void*); this->nvalue = va_arg(* params, size_t); - this->key = memMalloc(this->nkey + 1); + this->key = TR_malloc(this->nkey + 1); this->key[this->nkey] = 0; memcpy(this->key, key, this->nkey); this->hash = sdbm((unsigned char *)this->key, this->nkey); if (NULL != value) { - this->value = memMalloc(this->nvalue + 1); + this->value = TR_malloc(this->nvalue + 1); ((char*)this->value)[this->nvalue] = 0; memcpy(this->value, value, this->nvalue); } @@ -66,8 +63,8 @@ hashValueDtor(void * _this) { HashValue this = _this; - MEM_FREE(this->key); - MEM_FREE(this->value); + TR_MEM_FREE(this->key); + TR_MEM_FREE(this->value); } static @@ -103,8 +100,8 @@ hashValueHandleDouble(void * _this, void * _double) doub->nvalue = tmp_nvalue; } -INIT_IFACE(Class, hashValueCtor, hashValueDtor, NULL); -INIT_IFACE(Hashable, hashValueGetHash, hashValueHandleDouble); -CREATE_CLASS(HashValue, NULL, IFACE(Class), IFACE(Hashable)); +TR_INIT_IFACE(TR_Class, hashValueCtor, hashValueDtor, NULL); +TR_INIT_IFACE(Hashable, hashValueGetHash, hashValueHandleDouble); +TR_CREATE_CLASS(HashValue, NULL, TR_IF(TR_Class), TR_IF(Hashable)); // vim: set ts=4 sw=4: diff --git a/src/http/cookie.c b/src/http/cookie.c index bc1a520..0ed6f5c 100644 --- a/src/http/cookie.c +++ b/src/http/cookie.c @@ -25,13 +25,10 @@ #include #include -#include "class.h" +#include "trbase.h" #include "hash.h" #include "http/cookie.h" - #include "utils/hash.h" -#include "utils/memory.h" -#include "commons.h" static @@ -46,11 +43,11 @@ httpCookieCtor(void * _this, va_list * params) value = va_arg(* params, char*); this->nvalue = va_arg(* params, size_t); - this->key = memMalloc(this->nkey + 1); + this->key = TR_malloc(this->nkey + 1); this->key[this->nkey] = 0; memcpy(this->key, key, this->nkey); - this->value = memMalloc(this->nvalue + 1); + this->value = TR_malloc(this->nvalue + 1); this->value[this->nvalue] = 0; memcpy(this->value, value, this->nvalue); @@ -65,10 +62,10 @@ httpCookieDtor(void * _this, va_list * params) { HttpCookie this = _this; - MEM_FREE(this->key); - MEM_FREE(this->value); - MEM_FREE(this->domain); - MEM_FREE(this->path); + TR_MEM_FREE(this->key); + TR_MEM_FREE(this->value); + TR_MEM_FREE(this->domain); + TR_MEM_FREE(this->path); } static @@ -97,8 +94,8 @@ httpCookieHandleDouble(void * _this, void * _double) } -INIT_IFACE(Class, httpCookieCtor, httpCookieDtor, NULL); -INIT_IFACE(Hashable, httpCookieGetHash, httpCookieHandleDouble); -CREATE_CLASS(HttpCookie, NULL, IFACE(Class), IFACE(Hashable)); +TR_INIT_IFACE(TR_Class, httpCookieCtor, httpCookieDtor, NULL); +TR_INIT_IFACE(Hashable, httpCookieGetHash, httpCookieHandleDouble); +TR_CREATE_CLASS(HttpCookie, NULL, TR_IF(TR_Class), TR_IF(Hashable)); // vim: set ts=4 sw=4: diff --git a/src/http/header.c b/src/http/header.c index 103d024..e9d4b75 100644 --- a/src/http/header.c +++ b/src/http/header.c @@ -24,12 +24,10 @@ #include #include -#include "class.h" +#include "trbase.h" #include "hash.h" #include "http/header.h" - #include "utils/hash.h" -#include "utils/memory.h" static int @@ -43,13 +41,13 @@ httpHeaderCtor(void * _this, va_list * params) { value = va_arg(* params, char *); this->nvalue[0] = va_arg(* params, size_t); - this->name = memMalloc(this->nname + 1); + this->name = TR_malloc(this->nname + 1); this->name[this->nname] = 0; memcpy(this->name, name, this->nname); this->hash = sdbm((unsigned char *)name, this->nname); - (this->value)[0] = memMalloc((this->nvalue)[0] + 1); + (this->value)[0] = TR_malloc((this->nvalue)[0] + 1); (this->value)[0][(this->nvalue)[0]] = 0; memcpy((this->value)[0], value, (this->nvalue)[0]); this->cvalue = 1; @@ -65,10 +63,10 @@ httpHeaderDtor(void * _this) HttpHeader this = _this; size_t i; - MEM_FREE(this->name); + TR_MEM_FREE(this->name); for (i=0; icvalue; i++) { - MEM_FREE(this->value[i]); + TR_MEM_FREE(this->value[i]); } } @@ -99,8 +97,8 @@ httpHeaderHandleDouble(void * _this, void * _double) (doub->value)[0] = NULL; } -INIT_IFACE(Class, httpHeaderCtor, httpHeaderDtor, NULL); -INIT_IFACE(Hashable, httpHeaderGetHash, httpHeaderHandleDouble); -CREATE_CLASS(HttpHeader, NULL, IFACE(Class), IFACE(Hashable)); +TR_INIT_IFACE(TR_Class, httpHeaderCtor, httpHeaderDtor, NULL); +TR_INIT_IFACE(Hashable, httpHeaderGetHash, httpHeaderHandleDouble); +TR_CREATE_CLASS(HttpHeader, NULL, TR_IF(TR_Class), TR_IF(Hashable)); // vim: set ts=4 sw=4: diff --git a/src/http/interface/i_http_intro.c b/src/http/interface/i_http_intro.c index 125f475..ed5df73 100644 --- a/src/http/interface/i_http_intro.c +++ b/src/http/interface/i_http_intro.c @@ -20,20 +20,17 @@ * along with this program. If not, see . */ -#include "class.h" +#include "trbase.h" #include "http/interface/http_intro.h" -const struct interface i_HttpIntro = { - "httpIntro", - 2 -}; +TR_CREATE_INTERFACE(HttpIntro, 2); size_t httpIntroSizeGet(void * object) { size_t ret; - RETCALL(object, HttpIntro, sizeGet, ret); + TR_RETCALL(object, HttpIntro, sizeGet, ret); return ret; } @@ -43,7 +40,7 @@ httpIntroToString(void * object, char * string) { char * ret; - RETCALL(object, HttpIntro, toString, ret, string); + TR_RETCALL(object, HttpIntro, toString, ret, string); return ret; } diff --git a/src/http/message.c b/src/http/message.c index 60837ac..aab5a3f 100644 --- a/src/http/message.c +++ b/src/http/message.c @@ -30,10 +30,9 @@ #include #include -#include "class.h" +#include "trbase.h" #include "hash.h" #include "http/message.h" -#include "utils/memory.h" static @@ -43,10 +42,10 @@ httpMessageCtor(void * _this, va_list * params) HttpMessage this = _this; char * version = va_arg(* params, char *); - this->version = memCalloc(1, strlen(version)+1); + this->version = TR_calloc(1, strlen(version)+1); strcpy(this->version, version); - this->header = new(Hash); + this->header = TR_new(Hash); return 0; } @@ -57,12 +56,11 @@ httpMessageDtor(void * _this) { HttpMessage this = _this; - delete(this->header); - - MEM_FREE(this->version); + TR_delete(this->header); + TR_MEM_FREE(this->version); if (NULL == this->asset) { - MEM_FREE(this->body); + TR_MEM_FREE(this->body); } else { assetPoolRelease(this->asset); this->asset = NULL; @@ -70,7 +68,7 @@ httpMessageDtor(void * _this) } } -INIT_IFACE(Class, httpMessageCtor, httpMessageDtor, NULL); -CREATE_CLASS(HttpMessage, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, httpMessageCtor, httpMessageDtor, NULL); +TR_CREATE_CLASS(HttpMessage, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/http/message/has_keep_alive.c b/src/http/message/has_keep_alive.c index 136b673..52effe3 100644 --- a/src/http/message/has_keep_alive.c +++ b/src/http/message/has_keep_alive.c @@ -28,9 +28,7 @@ #include "http/request.h" #include "http/header.h" -#include "utils/memory.h" - -#include "commons.h" +#include "trbase.h" #include "hash.h" char diff --git a/src/http/parser.c b/src/http/parser.c index 532e985..1dc6062 100644 --- a/src/http/parser.c +++ b/src/http/parser.c @@ -24,17 +24,14 @@ #include #include -#include "class.h" +#include "trbase.h" #include "stream.h" - #include "http/parser.h" #include "queue.h" #include "http/request.h" #include "http/response.h" #include "cbuf.h" -#include "utils/memory.h" - static int @@ -48,7 +45,7 @@ httpParserCtor(void * _this, va_list * params) return -1; } - this->queue = new(Queue); + this->queue = TR_new(Queue); return 0; } @@ -59,17 +56,17 @@ httpParserDtor(void * _this) { HttpParser this = _this; - delete(this->queue); + TR_delete(this->queue); if (TRUE == this->ourLock) cbufRelease(this->buffer); - MEM_FREE(this->incomplete); - delete(this->current); + TR_MEM_FREE(this->incomplete); + TR_delete(this->current); } -INIT_IFACE(Class, httpParserCtor, httpParserDtor, NULL); -INIT_IFACE(StreamReader, httpParserParse); -CREATE_CLASS(HttpParser, NULL, IFACE(Class), IFACE(StreamReader)); +TR_INIT_IFACE(TR_Class, httpParserCtor, httpParserDtor, NULL); +TR_INIT_IFACE(StreamReader, httpParserParse); +TR_CREATE_CLASS(HttpParser, NULL, TR_IF(TR_Class), TR_IF(StreamReader)); // vim: set ts=4 sw=4: diff --git a/src/http/parser/p_body.c b/src/http/parser/p_body.c index 07b3162..12ac4c8 100644 --- a/src/http/parser/p_body.c +++ b/src/http/parser/p_body.c @@ -28,7 +28,7 @@ #include "http/parser.h" #include "cbuf.h" -#include "commons.h" +#include "trbase.h" size_t httpParserBody(HttpParser this, const char * buf, size_t nbuf) diff --git a/src/http/parser/p_header.c b/src/http/parser/p_header.c index abc8c51..d71d1ee 100644 --- a/src/http/parser/p_header.c +++ b/src/http/parser/p_header.c @@ -24,15 +24,13 @@ #include #include -#include "class.h" +#include "trbase.h" #include "http/header.h" #include "http/parser.h" #include "http/message.h" #include "http/request.h" #include "hash.h" -#include "utils/memory.h" - void httpParserHeader( HttpParser this, @@ -57,7 +55,7 @@ httpParserHeader( if (0 == strncasecmp("content-length", name, nname-1)) { current->nbody = strtoul(value, NULL, 10); if (0 < this->current->nbody) { - current->body = memMalloc(current->nbody); + current->body = TR_malloc(current->nbody); } current->dbody = 0; } @@ -91,7 +89,7 @@ httpParserHeader( val = (0 != nval)? eqsign+1 : NULL; hashAdd(request->cookies, - new(HashValue, key, eqsign-key, val, nval)); + TR_new(HashValue, key, eqsign-key, val, nval)); pair++; togo -= (pair - eqsign); @@ -99,7 +97,7 @@ httpParserHeader( } hashAdd(current->header, - new(HttpHeader, name, nname, value, lend - value)); + TR_new(HttpHeader, name, nname, value, lend - value)); } // vim: set ts=4 sw=4: diff --git a/src/http/parser/p_post_vars.c b/src/http/parser/p_post_vars.c index 105c192..758038d 100644 --- a/src/http/parser/p_post_vars.c +++ b/src/http/parser/p_post_vars.c @@ -26,7 +26,7 @@ #include "http/parser.h" #include "http/request.h" #include "hash.h" -#include "class.h" +#include "trbase.h" #include "utils/http.h" @@ -64,7 +64,7 @@ httpParserPostVars(HttpParser this) nvalue = urldecode(value, nvalue); hashAdd(request->post, - new(HashValue, key, eqsign-key, value, nvalue)); + TR_new(HashValue, key, eqsign-key, value, nvalue)); pair++; togo -= (pair - eqsign); diff --git a/src/http/parser/p_request_vars.c b/src/http/parser/p_request_vars.c index 464c3a2..7003938 100644 --- a/src/http/parser/p_request_vars.c +++ b/src/http/parser/p_request_vars.c @@ -24,12 +24,10 @@ #include #include +#include "trbase.h" #include "http/parser.h" #include "http/request.h" #include "hash.h" -#include "class.h" - -#include "utils/memory.h" void httpParserRequestVars(HttpParser this) @@ -41,7 +39,7 @@ httpParserRequestVars(HttpParser this) delim = request->uri + strlen(request->uri); } - request->path = memMalloc(delim - request->uri + 1); + request->path = TR_malloc(delim - request->uri + 1); request->path[delim - request->uri] = 0; memcpy(request->path, request->uri, delim - request->uri); @@ -65,7 +63,7 @@ httpParserRequestVars(HttpParser this) value = (0 != nvalue)? eqsign+1 : NULL; hashAdd(request->get, - new(HashValue, key, eqsign-key, value, nvalue)); + TR_new(HashValue, key, eqsign-key, value, nvalue)); } } diff --git a/src/http/parser/parse.c b/src/http/parser/parse.c index 1a7abe4..4c89950 100644 --- a/src/http/parser/parse.c +++ b/src/http/parser/parse.c @@ -22,7 +22,7 @@ #include -#include "class.h" +#include "trbase.h" #include "cbuf.h" #include "stream.h" #include "queue.h" @@ -31,11 +31,6 @@ #include "http/header.h" #include "http/interface/http_intro.h" -#include "utils/memory.h" -#include "commons.h" - -#define MIN(a,b) ((a)<(b)? (a) : (b)) - ssize_t httpParserParse(void * _this, Stream st) @@ -57,7 +52,7 @@ httpParserParse(void * _this, Stream st) if (NULL != this->incomplete) { cbufSetData(this->buffer, this->incomplete, this->isize); - MEM_FREE(this->incomplete); + TR_MEM_FREE(this->incomplete); } if (0 > (read = cbufRead(this->buffer, st))) { @@ -84,7 +79,7 @@ httpParserParse(void * _this, Stream st) if (NULL == (line = cbufGetLine(this->buffer, &line_end))) { if (! cbufIsEmpty(this->buffer)) { this->isize = this->buffer->bused; - this->incomplete = memMalloc(this->isize); + this->incomplete = TR_malloc(this->isize); memcpy(this->incomplete, cbufGetData(this->buffer, this->isize), this->isize); @@ -109,7 +104,7 @@ httpParserParse(void * _this, Stream st) if (NULL == (line = cbufGetLine(this->buffer, &line_end))) { if (! cbufIsEmpty(this->buffer)) { this->isize = this->buffer->bused; - this->incomplete = memMalloc(this->isize); + this->incomplete = TR_malloc(this->isize); memcpy(this->incomplete, cbufGetData(this->buffer, this->isize), this->isize); diff --git a/src/http/request.c b/src/http/request.c index b97f999..7c1c389 100644 --- a/src/http/request.c +++ b/src/http/request.c @@ -25,12 +25,10 @@ #include #include -#include "class.h" +#include "trbase.h" #include "hash.h" #include "http/interface/http_intro.h" - #include "http/request.h" -#include "utils/memory.h" static @@ -46,31 +44,31 @@ httpRequestCtor(void * _this, va_list * params) uri = va_arg(* params, char *); ulen = va_arg(* params, size_t); - PARENTCALL(_this, Class, ctor, params); + TR_PARENTCALL(_this, TR_Class, ctor, params); - this->method = memMalloc(mlen + 1); + this->method = TR_malloc(mlen + 1); this->method[mlen] = 0; memcpy(this->method, method, mlen); - this->uri = memMalloc(ulen + 1); + this->uri = TR_malloc(ulen + 1); this->uri[ulen] = 0; memcpy(this->uri, uri, ulen); this->method_id = httpRequestGetMethodId(this); if (-1 == this->method_id) { - MEM_FREE(this->uri); - MEM_FREE(this->method); - MEM_FREE(this->path); /** \todo looks like path is not used at all */ + TR_MEM_FREE(this->uri); + TR_MEM_FREE(this->method); + TR_MEM_FREE(this->path); /** \todo looks like path is not used at all */ - PARENTCALL(_this, Class, dtor); + TR_PARENTCALL(_this, TR_Class, dtor); return -1; } - this->get = new(Hash); - this->post = new(Hash); - this->cookies = new(Hash); + this->get = TR_new(Hash); + this->post = TR_new(Hash); + this->cookies = TR_new(Hash); return 0; } @@ -81,15 +79,15 @@ httpRequestDtor(void * _this) { HttpRequest this = _this; - delete(this->get); - delete(this->post); - delete(this->cookies); + TR_delete(this->get); + TR_delete(this->post); + TR_delete(this->cookies); - MEM_FREE(this->uri); - MEM_FREE(this->method); - MEM_FREE(this->path); + TR_MEM_FREE(this->uri); + TR_MEM_FREE(this->method); + TR_MEM_FREE(this->path); - PARENTCALL(_this, Class, dtor); + TR_PARENTCALL(_this, TR_Class, dtor); } static @@ -128,11 +126,11 @@ toString(void * _this, char * string) return string; } -INIT_IFACE(Class, httpRequestCtor, httpRequestDtor, NULL); -INIT_IFACE(HttpIntro, sizeGet, toString); -CREATE_CLASS(HttpRequest, +TR_INIT_IFACE(TR_Class, httpRequestCtor, httpRequestDtor, NULL); +TR_INIT_IFACE(HttpIntro, sizeGet, toString); +TR_CREATE_CLASS(HttpRequest, HttpMessage, - IFACE(Class), - IFACE(HttpIntro)); + TR_IF(TR_Class), + TR_IF(HttpIntro)); // vim: set ts=4 sw=4: diff --git a/src/http/response.c b/src/http/response.c index b950c11..1fbb2a8 100644 --- a/src/http/response.c +++ b/src/http/response.c @@ -26,9 +26,7 @@ #include #include -#include "class.h" -#include "utils/memory.h" - +#include "trbase.h" #include "http/response.h" #include "http/interface/http_intro.h" @@ -40,12 +38,12 @@ httpResponseCtor(void * _this, va_list * params) HttpResponse this = _this; char * reason; - PARENTCALL(_this, Class, ctor, params); + TR_PARENTCALL(_this, TR_Class, ctor, params); this->status = va_arg(* params, unsigned int); reason = va_arg(* params, char *); - this->reason = memCalloc(1, strlen(reason)+1); + this->reason = TR_calloc(1, strlen(reason)+1); strcpy(this->reason, reason); return 0; @@ -57,9 +55,9 @@ httpResponseDtor(void * _this) { HttpResponse this = _this; - MEM_FREE(this->reason); + TR_MEM_FREE(this->reason); - PARENTCALL(_this, Class, dtor); + TR_PARENTCALL(_this, TR_Class, dtor); } static @@ -98,12 +96,12 @@ toString(void * _this, char * string) return string; } -INIT_IFACE(Class, httpResponseCtor, httpResponseDtor, NULL); -INIT_IFACE(HttpIntro, sizeGet, toString); -CREATE_CLASS( +TR_INIT_IFACE(TR_Class, httpResponseCtor, httpResponseDtor, NULL); +TR_INIT_IFACE(HttpIntro, sizeGet, toString); +TR_CREATE_CLASS( HttpResponse, HttpMessage, - IFACE(Class), - IFACE(HttpIntro)); + TR_IF(TR_Class), + TR_IF(HttpIntro)); // vim: set ts=4 sw=4: diff --git a/src/http/response/304.c b/src/http/response/304.c index c3223f0..3e01e2b 100644 --- a/src/http/response/304.c +++ b/src/http/response/304.c @@ -22,13 +22,10 @@ #include -#include "class.h" - +#include "trbase.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" - -#include "utils/memory.h" #include "hash.h" HttpResponse @@ -40,18 +37,18 @@ httpResponse304( HttpResponse response; HttpMessage message; - response = new(HttpResponse, "HTTP/1.1", 304, "Not Modified"); + response = TR_new(HttpResponse, "HTTP/1.1", 304, "Not Modified"); message = (HttpMessage)response; message->nbody = 0; message->body = NULL; hashAdd(message->header, - new(HttpHeader, CSTRA("Content-Type"), mime, nmime)); + TR_new(HttpHeader, CSTRA("Content-Type"), mime, nmime)); hashAdd(message->header, - new(HttpHeader, CSTRA("ETag"), etag, netag)); + TR_new(HttpHeader, CSTRA("ETag"), etag, netag)); hashAdd(message->header, - new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime)); + TR_new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime)); return response; } diff --git a/src/http/response/403.c b/src/http/response/403.c index 7321bcc..ddda52f 100644 --- a/src/http/response/403.c +++ b/src/http/response/403.c @@ -25,8 +25,7 @@ #include #include -#include "class.h" - +#include "trbase.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" @@ -38,7 +37,7 @@ httpResponse403() HttpResponse response; HttpMessage message; - response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden"); + response = TR_new(HttpResponse, "HTTP/1.1", 403, "Forbidden"); message = (HttpMessage)response; message->nbody = 0; diff --git a/src/http/response/404.c b/src/http/response/404.c index 0dc5120..484dfd0 100644 --- a/src/http/response/404.c +++ b/src/http/response/404.c @@ -25,13 +25,10 @@ #include #include -#include "class.h" - +#include "trbase.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" - -#include "utils/memory.h" #include "hash.h" #define RESP_DATA "\n" \ @@ -49,14 +46,14 @@ httpResponse404() HttpResponse response; HttpMessage message; - response = new(HttpResponse, "HTTP/1.1", 404, "Not Found"); + response = TR_new(HttpResponse, "HTTP/1.1", 404, "Not Found"); message = (HttpMessage)response; hashAdd(message->header, - new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); + TR_new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); message->nbody = sizeof(RESP_DATA) - 1; - message->body = memMalloc(sizeof(RESP_DATA)); + message->body = TR_malloc(sizeof(RESP_DATA)); memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)); return response; diff --git a/src/http/response/500.c b/src/http/response/500.c index c05dd31..5261ece 100644 --- a/src/http/response/500.c +++ b/src/http/response/500.c @@ -25,13 +25,10 @@ #include #include -#include "class.h" - +#include "trbase.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" - -#include "utils/memory.h" #include "hash.h" #define RESP_DATA "\n" \ @@ -49,14 +46,14 @@ httpResponse500() HttpResponse response; HttpMessage message; - response = new(HttpResponse, "HTTP/1.1", 500, "Internal Server Error"); + response = TR_new(HttpResponse, "HTTP/1.1", 500, "Internal Server Error"); message = (HttpMessage)response; hashAdd(message->header, - new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); + TR_new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); message->nbody = sizeof(RESP_DATA) - 1; - message->body = memMalloc(sizeof(RESP_DATA)); + message->body = TR_malloc(sizeof(RESP_DATA)); memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)); return response; diff --git a/src/http/response/asset.c b/src/http/response/asset.c index a003e9e..9c3cf2e 100644 --- a/src/http/response/asset.c +++ b/src/http/response/asset.c @@ -41,14 +41,11 @@ #include #include -#include "class.h" +#include "trbase.h" #include "stream.h" - #include "http/response.h" #include "http/message.h" #include "http/header.h" - -#include "utils/memory.h" #include "utils/http.h" #include "hash.h" @@ -68,7 +65,7 @@ httpResponseAsset(const char * fname, size_t nfname, time_t exptime) return NULL; } - response = new(HttpResponse, "HTTP/1.1", 200, "OK"); + response = TR_new(HttpResponse, "HTTP/1.1", 200, "OK"); message = (HttpMessage)response; message->asset = asset; @@ -78,14 +75,14 @@ httpResponseAsset(const char * fname, size_t nfname, time_t exptime) nexpires = rfc1123Gmt(expires, sizeof(expires), &exptime); hashAdd(message->header, - new(HttpHeader, CSTRA("Content-Type"), + TR_new(HttpHeader, CSTRA("Content-Type"), asset->mime_type, asset->nmime_type)); hashAdd(message->header, - new(HttpHeader, CSTRA("ETag"), asset->etag, asset->netag)); + TR_new(HttpHeader, CSTRA("ETag"), asset->etag, asset->netag)); hashAdd(message->header, - new(HttpHeader, CSTRA("Expires"), expires, nexpires)); + TR_new(HttpHeader, CSTRA("Expires"), expires, nexpires)); hashAdd(message->header, - new(HttpHeader, CSTRA("Last-Modified"), + TR_new(HttpHeader, CSTRA("Last-Modified"), asset->mtime, asset->nmtime)); return response; diff --git a/src/http/response/json.c b/src/http/response/json.c index 9fcd1ce..19316d4 100644 --- a/src/http/response/json.c +++ b/src/http/response/json.c @@ -26,14 +26,11 @@ #include #include -#include "class.h" - +#include "trbase.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" #include "session.h" - -#include "utils/memory.h" #include "hash.h" HttpResponse @@ -42,14 +39,17 @@ httpResponseJson(const char * body, size_t nbody) HttpResponse response; HttpMessage message; - response = new(HttpResponse, "HTTP/1.1", 200, "OK"); + response = TR_new(HttpResponse, "HTTP/1.1", 200, "OK"); message = (HttpMessage)response; hashAdd(message->header, - new(HttpHeader, CSTRA("Content-Type"), CSTRA("application/json"))); + TR_new( + HttpHeader, + CSTRA("Content-Type"), + CSTRA("application/json"))); message->nbody = nbody; - message->body = memMalloc(nbody); + message->body = TR_malloc(nbody); memcpy(message->body, body, nbody); return response; diff --git a/src/http/worker.c b/src/http/worker.c index 8d59303..bea993b 100644 --- a/src/http/worker.c +++ b/src/http/worker.c @@ -30,7 +30,7 @@ #include #include -#include "class.h" +#include "trbase.h" #include "stream.h" #include "hash.h" #include "queue.h" @@ -38,10 +38,6 @@ #include "http/parser.h" #include "http/writer.h" -#include "utils/memory.h" -#include "interface/subject.h" -#include "interface/observer.h" - static int httpWorkerCtor(void * _this, va_list * params) @@ -50,18 +46,18 @@ httpWorkerCtor(void * _this, va_list * params) char * id = va_arg(*params, char *); char cbuf_id[100]; - this->id = memMalloc(strlen(id) + 1); + this->id = TR_malloc(strlen(id) + 1); strcpy(this->id, id); - this->asset_pool = new(Hash); + this->asset_pool = TR_new(Hash); sprintf(cbuf_id, "%s_%s", "parser", id); - this->pbuf = new(Cbuf, cbuf_id, PARSER_MAX_BUF); + this->pbuf = TR_new(Cbuf, cbuf_id, PARSER_MAX_BUF); - this->additional_headers = new(Queue); + this->additional_headers = TR_new(Queue); - this->parser = new(HttpParser, this->pbuf); - this->writer = new(HttpWriter); + this->parser = TR_new(HttpParser, this->pbuf); + this->writer = TR_new(HttpWriter); return 0; } @@ -72,16 +68,16 @@ httpWorkerDtor(void * _this) { HttpWorker this = _this; - MEM_FREE(this->id); + TR_MEM_FREE(this->id); - delete(this->additional_headers); + TR_delete(this->additional_headers); - delete(this->parser); - delete(this->writer); + TR_delete(this->parser); + TR_delete(this->writer); if (NULL != this->pbuf) { - delete(this->asset_pool); - delete(this->pbuf); //!< cloned workers have NULL, so delete won't do anything + TR_delete(this->asset_pool); + TR_delete(this->pbuf); //!< cloned workers have NULL, so delete won't do anything } } @@ -95,9 +91,9 @@ httpWorkerClone(void * _this, void * _base) this->asset_pool = base->asset_pool; this->application_adapter = base->application_adapter; - this->additional_headers = new(Queue); + this->additional_headers = TR_new(Queue); - this->parser = new(HttpParser, base->pbuf); + this->parser = TR_new(HttpParser, base->pbuf); /* * I am pretty sure that it is not neccessary to have a * separeate writer for each connection... @@ -117,7 +113,7 @@ httpWorkerClone(void * _this, void * _base) * At the end I think it might be best to leave it as * it is. */ - this->writer = new(HttpWriter); + this->writer = TR_new(HttpWriter); } ssize_t httpWorkerProcess(void *, Stream); @@ -130,7 +126,7 @@ httpWorkerDetach(void * _this, void * adapter) HttpWorker this = (HttpWorker)_this; if (NULL != this->application_adapter) { - delete(this->application_adapter); + TR_delete(this->application_adapter); } } @@ -158,19 +154,23 @@ httpWorkerNotify(void * _this) { HttpWorker this = (HttpWorker)_this; - observerUpdate(this->application_adapter, _this); + TR_observerUpdate(this->application_adapter, _this); } -INIT_IFACE(Class, httpWorkerCtor, httpWorkerDtor, httpWorkerClone); -INIT_IFACE(StreamReader, httpWorkerProcess); -INIT_IFACE(StreamWriter, httpWorkerWrite); -INIT_IFACE(Subject, httpWorkerAttach, httpWorkerDetach, httpWorkerNotify); -CREATE_CLASS( +TR_INIT_IFACE(TR_Class, httpWorkerCtor, httpWorkerDtor, httpWorkerClone); +TR_INIT_IFACE(StreamReader, httpWorkerProcess); +TR_INIT_IFACE(StreamWriter, httpWorkerWrite); +TR_INIT_IFACE( + TR_Subject, + httpWorkerAttach, + httpWorkerDetach, + httpWorkerNotify); +TR_CREATE_CLASS( HttpWorker, NULL, - IFACE(Class), - IFACE(StreamReader), - IFACE(StreamWriter), - IFACE(Subject)); + TR_IF(TR_Class), + TR_IF(StreamReader), + TR_IF(StreamWriter), + TR_IF(TR_Subject)); // vim: set ts=4 sw=4: diff --git a/src/http/worker/add_common_header.c b/src/http/worker/add_common_header.c index f5cb04c..749cf13 100644 --- a/src/http/worker/add_common_header.c +++ b/src/http/worker/add_common_header.c @@ -22,17 +22,12 @@ #include -#include "class.h" - +#include "trbase.h" #include "http/message.h" #include "http/header.h" #include "http/worker.h" - #include "hash.h" - -#include "utils/memory.h" #include "utils/http.h" - #include "config.h" @@ -44,15 +39,15 @@ httpWorkerAddCommonHeader(HttpWorker this) if (httpMessageHasKeepAlive((HttpMessage)this->current_request)) { hashAdd(this->current_response->header, - new(HttpHeader, CSTRA("Connection"), CSTRA("Keep-Alive"))); + TR_new(HttpHeader, CSTRA("Connection"), CSTRA("Keep-Alive"))); } else { hashAdd(this->current_response->header, - new(HttpHeader, CSTRA("Connection"), CSTRA("Close"))); + TR_new(HttpHeader, CSTRA("Connection"), CSTRA("Close"))); } hashAdd(this->current_response->header, - new(HttpHeader, CSTRA("Server"), CSTRA(PACKAGE_STRING))); + TR_new(HttpHeader, CSTRA("Server"), CSTRA(PACKAGE_STRING))); switch(((HttpResponse)this->current_response)->status) { case 304: @@ -61,12 +56,12 @@ httpWorkerAddCommonHeader(HttpWorker this) default: nbuf = sprintf(buffer, "%d", this->current_response->nbody); hashAdd(this->current_response->header, - new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf)); + TR_new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf)); } nbuf = rfc1123GmtNow(buffer, sizeof(buffer)); hashAdd(this->current_response->header, - new(HttpHeader, CSTRA("Date"), buffer, nbuf)); + TR_new(HttpHeader, CSTRA("Date"), buffer, nbuf)); } // vim: set ts=4 sw=4: diff --git a/src/http/worker/add_computed_header.c b/src/http/worker/add_computed_header.c index 52d37e3..cd2731f 100644 --- a/src/http/worker/add_computed_header.c +++ b/src/http/worker/add_computed_header.c @@ -22,16 +22,11 @@ #include -#include "class.h" - #include "http/message.h" #include "http/header.h" #include "http/worker.h" - #include "queue.h" -#include "utils/memory.h" - void httpWorkerAddComputedHeader(HttpWorker this) diff --git a/src/http/worker/get_asset.c b/src/http/worker/get_asset.c index 7489e1b..d140a6d 100644 --- a/src/http/worker/get_asset.c +++ b/src/http/worker/get_asset.c @@ -23,13 +23,12 @@ #include #include +#include "trbase.h" #include "http/header.h" #include "http/message.h" #include "http/request.h" #include "http/response.h" #include "http/worker.h" - -#include "utils/memory.h" #include "hash.h" HttpMessage @@ -76,7 +75,7 @@ httpWorkerGetAsset(HttpWorker this, const char * fname) message->asset->etag, message->asset->netag, message->asset->mtime, message->asset->nmtime); - delete(message); + TR_delete(message); return new_message; } diff --git a/src/http/worker/process.c b/src/http/worker/process.c index c2c5a1f..208a153 100644 --- a/src/http/worker/process.c +++ b/src/http/worker/process.c @@ -27,27 +27,18 @@ #include #include -#include "class.h" -#include "auth.h" +#include "trbase.h" #include "queue.h" -#include "session.h" -#include "stream.h" -#include "hash.h" #include "http/worker.h" #include "http/header.h" #include "http/message.h" -#include "http/request.h" #include "http/response.h" #include "http/parser.h" #include "config/config.h" #include "config/value.h" -#include "interface/subject.h" - -#include "utils/memory.h" #include "utils/mime_type.h" -#include "commons.h" HttpMessage httpWorkerGetAsset(HttpWorker, const char *); @@ -74,7 +65,7 @@ httpWorkerProcess(HttpWorker this, Stream st) * let our observers...application (or better their * http adapter) try to create an answer. */ - subjectNotify(this); + TR_subjectNotify(this); if (NULL == this->current_response) { if (0 == strcmp("POST", this->current_request->method) || @@ -132,7 +123,7 @@ httpWorkerProcess(HttpWorker this, Stream st) httpWorkerAddCommonHeader(this); httpWorkerAddComputedHeader(this); - delete(this->current_request); + TR_delete(this->current_request); queuePut(this->writer->queue, this->current_response); this->current_response = NULL; } diff --git a/src/http/writer.c b/src/http/writer.c index 5d390cd..91a2b9b 100644 --- a/src/http/writer.c +++ b/src/http/writer.c @@ -22,21 +22,18 @@ #include -#include "class.h" +#include "trbase.h" #include "stream.h" - #include "queue.h" #include "http/writer.h" -#include "utils/memory.h" - static int httpWriterCtor(void * _this, va_list * params) { HttpWriter this = _this; - this->queue = new(Queue); + this->queue = TR_new(Queue); return 0; } @@ -47,19 +44,19 @@ httpWriterDtor(void * _this) { HttpWriter this = _this; - delete(this->queue); + TR_delete(this->queue); if (NULL != this->buffer) { - MEM_FREE(this->buffer); + TR_MEM_FREE(this->buffer); } if (NULL != this->current) { - delete(this->current); + TR_delete(this->current); } } -INIT_IFACE(Class, httpWriterCtor, httpWriterDtor, NULL); -INIT_IFACE(StreamWriter, httpWriterWrite); -CREATE_CLASS(HttpWriter, NULL, IFACE(Class), IFACE(StreamWriter)); +TR_INIT_IFACE(TR_Class, httpWriterCtor, httpWriterDtor, NULL); +TR_INIT_IFACE(StreamWriter, httpWriterWrite); +TR_CREATE_CLASS(HttpWriter, NULL, TR_IF(TR_Class), TR_IF(StreamWriter)); // vim: set ts=4 sw=4: diff --git a/src/http/writer/write.c b/src/http/writer/write.c index 5120a88..fc7b78b 100644 --- a/src/http/writer/write.c +++ b/src/http/writer/write.c @@ -23,15 +23,12 @@ #include #include -#include "class.h" +#include "trbase.h" #include "http/message.h" #include "queue.h" #include "http/writer.h" #include "stream.h" -#include "commons.h" -#include "utils/memory.h" - ssize_t httpWriterWrite(void * _this, Stream st) @@ -51,7 +48,7 @@ httpWriterWrite(void * _this, Stream st) this->written = 0; this->nheader = httpMessageHeaderSizeGet(this->current); - if (this->nheader > memGetSize(this->buffer)) { + if (this->nheader > TR_memGetSize(this->buffer)) { ssize_t size = this->nheader; size = (0 != size%WRITER_BUF_CHUNK)? @@ -60,10 +57,10 @@ httpWriterWrite(void * _this, Stream st) size *= WRITER_BUF_CHUNK; if (NULL != this->buffer) { - MEM_FREE(this->buffer); + TR_MEM_FREE(this->buffer); } - this->buffer = memMalloc(size); + this->buffer = TR_malloc(size); this->nbuffer = size; } @@ -138,10 +135,10 @@ httpWriterWrite(void * _this, Stream st) * underlying connection should be closed at their side. * Then we close to connection. */ - delete(this->current); + TR_delete(this->current); return -2; } - delete(this->current); + TR_delete(this->current); break; } diff --git a/src/interface/indexable.c b/src/interface/indexable.c deleted file mode 100644 index 82f734f..0000000 --- a/src/interface/indexable.c +++ /dev/null @@ -1,42 +0,0 @@ -/** - * \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 "class.h" -#include "uuid.h" -#include "interface/indexable.h" - -const struct interface i_Indexable = { - "indexable", - 1 -}; - -Uuid -indexUuid(void * indexable, Uuid namespace) -{ - Uuid ret; - - RETCALL(indexable, Indexable, uuid, ret, namespace); - - return ret; -} - -// vim: set ts=4 sw=4: diff --git a/src/interface/observer.c b/src/interface/observer.c deleted file mode 100644 index 90b1d19..0000000 --- a/src/interface/observer.c +++ /dev/null @@ -1,37 +0,0 @@ -/** - * \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 "class.h" -#include "interface/observer.h" - -const struct interface i_Observer = { - "observer", - 1 -}; - -void -observerUpdate(void * observer, void * subject) -{ - CALL(observer, Observer, update, subject); -} - -// vim: set ts=4 sw=4: diff --git a/src/interface/serializable.c b/src/interface/serializable.c deleted file mode 100644 index 528e3fb..0000000 --- a/src/interface/serializable.c +++ /dev/null @@ -1,49 +0,0 @@ -/** - * \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 "class.h" -#include "interface/serializable.h" - -const struct interface i_Serializable = { - "serializable", - 2 -}; - -void -serialize( - void * serializable, - unsigned char ** serialized, - size_t * nserialized) -{ - CALL(serializable, Serializable, serialize, serialized, nserialized); -} - -void -unserialize( - void * serializable, - const unsigned char * serialized, - size_t nserialized) -{ - CALL(serializable, Serializable, unserialize, serialized, nserialized); -} - -// vim: set ts=4 sw=4: diff --git a/src/interface/subject.c b/src/interface/subject.c deleted file mode 100644 index 831553e..0000000 --- a/src/interface/subject.c +++ /dev/null @@ -1,49 +0,0 @@ -/** - * \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 "class.h" -#include "interface/subject.h" - -const struct interface i_Subject = { - "subject", - 3 -}; - -void -subjectAttach(void * subject, void * observer) -{ - CALL(subject, Subject, attach, observer); -} - -void -subjectDetach(void * subject, void * observer) -{ - CALL(subject, Subject, detach, observer); -} - -void -subjectNotify(void * subject) -{ - CALL(subject, Subject, notify); -} - -// vim: set ts=4 sw=4: diff --git a/src/logger/interface/i_logger.c b/src/logger/interface/i_logger.c index 0f9045f..5934a26 100644 --- a/src/logger/interface/i_logger.c +++ b/src/logger/interface/i_logger.c @@ -26,13 +26,9 @@ #include "logger/logger.h" #include "logger/interface/logger.h" +#include "trbase.h" -#include "utils/memory.h" - -const struct interface i_Logger = { - "logger", - 1 -}; +TR_CREATE_INTERFACE(Logger, 1); void loggerLog(void * _object, logger_level level, const char * const fmt, ...) { @@ -47,32 +43,15 @@ loggerLog(void * _object, logger_level level, const char * const fmt, ...) { msg_size = vsnprintf(NULL, msg_size, fmt, params); va_end(params); - msg = memMalloc(msg_size + 1); + msg = TR_malloc(msg_size + 1); va_start(params, fmt); vsnprintf(msg, msg_size + 1, fmt, params); va_end(params); -// // ----- DEBUG ------ -// do { -// struct i_Logger * iface; -// -// do { -// class_ptr class = GET_CLASS(_object); -// iface = (struct i_Logger *)IFACE_GET(class, &i_Logger); -// while ((NULL == iface || NULL == iface->log) && HAS_PARENT(class)) { -// class = class->parent; -// iface = (struct i_Logger *)IFACE_GET(class, &i_Logger); -// } -// assert(NULL != iface->log); -// } while(0); -// -// iface->log(_object, level, msg); -// } while(0); -// // ----- DEBUG ------ - CALL(_object, Logger, log, level, msg); + TR_CALL(_object, Logger, log, level, msg); - MEM_FREE(msg); + TR_MEM_FREE(msg); } } diff --git a/src/logger/logger.c b/src/logger/logger.c index 4d8ab63..83b423a 100644 --- a/src/logger/logger.c +++ b/src/logger/logger.c @@ -22,7 +22,7 @@ #include -#include "class.h" +#include "trbase.h" #include "logger/logger.h" #include "logger/interface/logger.h" @@ -51,7 +51,7 @@ loggerCtor(void * _this, va_list * params) static void loggerDtor(void * _this) {} -INIT_IFACE(Class, loggerCtor, loggerDtor, NULL); -CREATE_CLASS(Logger, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, loggerCtor, loggerDtor, NULL); +TR_CREATE_CLASS(Logger, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/logger/stderr.c b/src/logger/stderr.c index 8df121e..62871d2 100644 --- a/src/logger/stderr.c +++ b/src/logger/stderr.c @@ -22,6 +22,7 @@ #include +#include "trbase.h" #include "logger/logger.h" #include "logger/interface/logger.h" @@ -32,7 +33,7 @@ logStderr(void * this, logger_level level, const char * const msg) fprintf(stderr, "[%s] %s\n", logger_level_str[level], msg); } -INIT_IFACE(Logger, logStderr); -CREATE_CLASS(LoggerStderr, Logger, IFACE(Logger)); +TR_INIT_IFACE(Logger, logStderr); +TR_CREATE_CLASS(LoggerStderr, Logger, TR_IF(Logger)); // vim: set ts=4 sw=4: diff --git a/src/logger/syslog.c b/src/logger/syslog.c index 4f331ac..3706023 100644 --- a/src/logger/syslog.c +++ b/src/logger/syslog.c @@ -22,6 +22,7 @@ #include +#include "trbase.h" #include "logger/logger.h" #include "logger/interface/logger.h" @@ -45,7 +46,7 @@ logSyslog(void * this, logger_level level, const char * const msg) syslog(syslog_priority[level], "[%s] %s", logger_level_str[level], msg); } -INIT_IFACE(Logger, logSyslog); -CREATE_CLASS(LoggerSyslog, Logger, IFACE(Logger)); +TR_INIT_IFACE(Logger, logSyslog); +TR_CREATE_CLASS(LoggerSyslog, Logger, TR_IF(Logger)); // vim: set ts=4 sw=4: diff --git a/src/queue/get.c b/src/queue/get.c index fdbf41e..a667f80 100644 --- a/src/queue/get.c +++ b/src/queue/get.c @@ -20,7 +20,7 @@ * along with this program. If not, see . */ -#include "class.h" +#include "trbase.h" #include "queue.h" void * @@ -39,7 +39,7 @@ queueGet(Queue this) if (this->first == this->last) { this->last = NULL; } - delete(this->first); + TR_delete(this->first); this->next = first; this->first = first; diff --git a/src/queue/put.c b/src/queue/put.c index 3640843..f8993f0 100644 --- a/src/queue/put.c +++ b/src/queue/put.c @@ -20,7 +20,7 @@ * along with this program. If not, see . */ -#include "class.h" +#include "trbase.h" #include "queue.h" void @@ -28,7 +28,7 @@ queuePut(Queue this, void * msg) { Queue node = (this->last)? this->last : this; - node->next = new(Queue); + node->next = TR_new(Queue); this->last = node->next; if (node == this) { diff --git a/src/queue/queue.c b/src/queue/queue.c index e50b693..2cb6ea9 100644 --- a/src/queue/queue.c +++ b/src/queue/queue.c @@ -22,7 +22,7 @@ #include -#include "class.h" +#include "trbase.h" #include "queue.h" static @@ -41,13 +41,13 @@ queueDtor(void * _this) while (NULL != node) { Queue next = node->next; - delete(node->msg); - delete(node); + TR_delete(node->msg); + TR_delete(node); node = next; } } -INIT_IFACE(Class, queueCtor, queueDtor, NULL); -CREATE_CLASS(Queue, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, queueCtor, queueDtor, NULL); +TR_CREATE_CLASS(Queue, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/router/route.c b/src/router/route.c index 0abe276..7883bc0 100644 --- a/src/router/route.c +++ b/src/router/route.c @@ -35,6 +35,7 @@ // for toupper #include +#include "trbase.h" #include "router.h" #include "hash.h" #include "session.h" @@ -42,9 +43,6 @@ #include "http/response.h" #include "application/application.h" -#include "utils/memory.h" -#include "commons.h" - #define COMMAND_LEN 128 @@ -102,7 +100,7 @@ routerRoute( */ switch (request->method_id) { case HTTP_GET: - args = new(Hash); + args = request->get; strcpy(&(functionName[this->nprefix + ncommand]), "Read"); break; @@ -255,7 +253,7 @@ routerRoute( switch (request->method_id) { case HTTP_GET: - delete(args); + TR_delete(args); break; case HTTP_POST: @@ -268,7 +266,7 @@ routerRoute( if (NULL != response_data) { response = httpResponseJson(response_data, strlen(response_data)); - MEM_FREE(response_data); + TR_MEM_FREE(response_data); } else { response = httpResponse404(); } diff --git a/src/router/router.c b/src/router/router.c index 8305c87..eaa75a8 100644 --- a/src/router/router.c +++ b/src/router/router.c @@ -25,7 +25,7 @@ // for dlopen, dlsym #include -#include "class.h" +#include "trbase.h" #include "router.h" #include "hash.h" #include "application/application.h" @@ -39,7 +39,7 @@ routerCtor(void * _this, va_list * params) Router this = _this; this->application = va_arg(*params, Application); - this->functions = new(Hash); + this->functions = TR_new(Hash); this->handle = dlopen(NULL, RTLD_LAZY); this->prefix = PREFIX; this->nprefix = sizeof(PREFIX) - 1; @@ -56,11 +56,11 @@ void routerDtor(void * _this) { Router this = _this; - delete(this->functions); + TR_delete(this->functions); dlclose(this->handle); } -INIT_IFACE(Class, routerCtor, routerDtor, NULL); -CREATE_CLASS(Router, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, routerCtor, routerDtor, NULL); +TR_CREATE_CLASS(Router, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/server/close_conn.c b/src/server/close_conn.c index ab5d9d1..b44b33f 100644 --- a/src/server/close_conn.c +++ b/src/server/close_conn.c @@ -23,8 +23,8 @@ #include #include +#include "trbase.h" #include "server.h" -#include "class.h" #include "stream.h" void @@ -33,8 +33,8 @@ serverCloseConn(Server this, unsigned int i) int fd = (this->fds)[i].fd; Stream st = (this->conns[fd]).stream; - delete((this->conns)[fd].sock); - delete((this->conns)[fd].worker); + TR_delete((this->conns)[fd].sock); + TR_delete((this->conns)[fd].worker); if (NULL != st && STREAM_SSL == st->type) { SSL_shutdown((st->handle).ssl); @@ -42,7 +42,7 @@ serverCloseConn(Server this, unsigned int i) (st->handle).ssl = NULL; } - delete(st); + TR_delete(st); memset(&(this->fds[i]), 0, sizeof(struct pollfd)); } diff --git a/src/server/handle_accept.c b/src/server/handle_accept.c index b8fe584..bc6a56e 100644 --- a/src/server/handle_accept.c +++ b/src/server/handle_accept.c @@ -26,9 +26,9 @@ #include +#include "trbase.h" #include "http/worker.h" #include "server.h" -#include "class.h" #include "logger.h" #include "stream.h" @@ -51,7 +51,7 @@ serverHandleAccept(Server this, unsigned int i) switch(i) { case 0: // no SSL - st = new(Stream, STREAM_FD, acc->handle); + st = TR_new(Stream, STREAM_FD, acc->handle); break; case 1: @@ -60,7 +60,7 @@ serverHandleAccept(Server this, unsigned int i) SSL * ssl = SSL_new(this->ctx); SSL_set_fd(ssl, acc->handle); SSL_accept(ssl); - st = new(Stream, STREAM_SSL, ssl); + st = TR_new(Stream, STREAM_SSL, ssl); } break; @@ -73,14 +73,14 @@ serverHandleAccept(Server this, unsigned int i) (this->conns)[acc->handle].sock = acc; // clone worker - (this->conns)[acc->handle].worker = clone(this->worker); + (this->conns)[acc->handle].worker = TR_clone(this->worker); (this->conns)[acc->handle].stream = st; (this->fds)[this->nfds].fd = acc->handle; (this->fds)[this->nfds].events = POLLIN; this->nfds++; } else { - delete(acc); + TR_delete(acc); switch(errno) { case EAGAIN|EWOULDBLOCK: diff --git a/src/server/server.c b/src/server/server.c index 0c45958..6e827a6 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -27,13 +27,11 @@ #include #include -#include "class.h" +#include "trbase.h" #include "server.h" #include "socket.h" #include "logger.h" -#include "utils/memory.h" - void serverCloseConn(Server, unsigned int); @@ -65,13 +63,13 @@ serverCtor(void * _this, va_list * params) "accept up to %zu connections", this->max_fds); - this->fds = memCalloc(sizeof(struct pollfd), this->max_fds); - this->conns = memCalloc(sizeof(struct conns), this->max_fds); + this->fds = TR_calloc(sizeof(struct pollfd), this->max_fds); + this->conns = TR_calloc(sizeof(struct conns), this->max_fds); - this->sock = new(Sock, this->logger, port); + this->sock = TR_new(Sock, this->logger, port); socketNonblock(this->sock); - this->sockSSL = new(Sock, this->logger, port+1); + this->sockSSL = TR_new(Sock, this->logger, port+1); socketNonblock(this->sockSSL); SSL_library_init(); @@ -117,17 +115,17 @@ serverDtor(void * _this) } } - MEM_FREE(this->fds); - MEM_FREE(this->conns); + TR_MEM_FREE(this->fds); + TR_MEM_FREE(this->conns); - delete(this->sock); - delete(this->sockSSL); + TR_delete(this->sock); + TR_delete(this->sockSSL); SSL_CTX_free(this->ctx); ERR_free_strings(); } -INIT_IFACE(Class, serverCtor, serverDtor, NULL); -CREATE_CLASS(Server, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, serverCtor, serverDtor, NULL); +TR_CREATE_CLASS(Server, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/session/session.c b/src/session/session.c index aeca7d1..274e8e4 100644 --- a/src/session/session.c +++ b/src/session/session.c @@ -28,12 +28,10 @@ #include #include +#include "trbase.h" #include "session.h" #include "hash.h" -#include "class.h" - #include "utils/hash.h" -#include "utils/memory.h" static @@ -58,7 +56,7 @@ sessionDtor(void * _this) { Session this = _this; - delete(this->user); + TR_delete(this->user); } static @@ -76,8 +74,8 @@ sessionHandleDouble(void * _this, void * _doub) { } -INIT_IFACE(Class, sessionCtor, sessionDtor, NULL); -INIT_IFACE(Hashable, sessionGetHash, sessionHandleDouble); -CREATE_CLASS(Session, NULL, IFACE(Class), IFACE(Hashable)); +TR_INIT_IFACE(TR_Class, sessionCtor, sessionDtor, NULL); +TR_INIT_IFACE(Hashable, sessionGetHash, sessionHandleDouble); +TR_CREATE_CLASS(Session, NULL, TR_IF(TR_Class), TR_IF(Hashable)); // vim: set ts=4 sw=4: diff --git a/src/socket/accept.c b/src/socket/accept.c index e4ff648..e554e24 100644 --- a/src/socket/accept.c +++ b/src/socket/accept.c @@ -24,8 +24,8 @@ #include #include +#include "trbase.h" #include "socket.h" -#include "class.h" #include "logger.h" Sock @@ -37,7 +37,7 @@ socketAccept(Sock this, char (*remoteAddr)[16]) // Set the size of the in-out parameter len = sizeof(this->addr); - sock = new(Sock, this->log, -1); + sock = TR_new(Sock, this->log, -1); // Wait for a client to connect sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len); diff --git a/src/socket/connect.c b/src/socket/connect.c index 6502288..9b22cfb 100644 --- a/src/socket/connect.c +++ b/src/socket/connect.c @@ -24,7 +24,6 @@ #include // for errno #include "socket.h" -#include "class.h" #include "logger.h" diff --git a/src/socket/listen.c b/src/socket/listen.c index f837051..3790cbe 100644 --- a/src/socket/listen.c +++ b/src/socket/listen.c @@ -24,7 +24,6 @@ #include // for errno #include "socket.h" -#include "class.h" #include "logger.h" diff --git a/src/socket/nonblock.c b/src/socket/nonblock.c index 4a45d69..e7595a0 100644 --- a/src/socket/nonblock.c +++ b/src/socket/nonblock.c @@ -25,7 +25,6 @@ #include #include "socket.h" -#include "class.h" #include "logger.h" void diff --git a/src/socket/socket.c b/src/socket/socket.c index ead4f00..d8ccba4 100644 --- a/src/socket/socket.c +++ b/src/socket/socket.c @@ -26,7 +26,7 @@ #include "socket.h" #include "logger.h" -#include "class.h" +#include "trbase.h" static int @@ -72,7 +72,7 @@ socketDtor(void * _this) } } -INIT_IFACE(Class, socketCtor, socketDtor, NULL); -CREATE_CLASS(Sock, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, socketCtor, socketDtor, NULL); +TR_CREATE_CLASS(Sock, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/storage/delete.c b/src/storage/delete.c index 3b5ba2d..48d9560 100644 --- a/src/storage/delete.c +++ b/src/storage/delete.c @@ -24,11 +24,8 @@ #include #include -#include "class.h" #include "storage/storage.h" -#include "utils/memory.h" -#include "commons.h" int storageDelete(Storage this, char * _key, size_t nkey) diff --git a/src/storage/get.c b/src/storage/get.c index 4020462..577691b 100644 --- a/src/storage/get.c +++ b/src/storage/get.c @@ -25,10 +25,9 @@ #include #include -#include "class.h" +#include "trbase.h" #include "storage/storage.h" -#include "utils/memory.h" void storageGet( @@ -36,7 +35,7 @@ storageGet( char * _key, size_t nkey, char ** data, size_t * ndata) { - char * key = memMalloc(nkey); + char * key = TR_malloc(nkey); datum gdbm_key = {key, nkey}; datum value; @@ -47,11 +46,11 @@ storageGet( memcpy(key, _key, nkey); value = gdbm_fetch(this->gdbm, gdbm_key); - MEM_FREE(key); + TR_MEM_FREE(key); if (NULL != value.dptr) { *ndata = value.dsize; - *data = memMalloc(value.dsize); + *data = TR_malloc(value.dsize); memcpy(*data, value.dptr, value.dsize); free(value.dptr); diff --git a/src/storage/put.c b/src/storage/put.c index d902a51..a7c2e71 100644 --- a/src/storage/put.c +++ b/src/storage/put.c @@ -24,11 +24,8 @@ #include #include -#include "class.h" #include "storage/storage.h" -#include "utils/memory.h" - StoragePutResult storagePut(Storage this, char * _key, size_t nkey, char * data, size_t ndata) diff --git a/src/storage/storage.c b/src/storage/storage.c index 4fd56db..bfce57d 100644 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -24,10 +24,9 @@ #include #include -#include "class.h" +#include "trbase.h" #include "storage/storage.h" -#include "utils/memory.h" static int @@ -36,7 +35,7 @@ storageCtor(void * _this, va_list * params) Storage this = _this; char * db_name = va_arg(* params, void *); - this->db_name = memMalloc(strlen(db_name) + 1); + this->db_name = TR_malloc(strlen(db_name) + 1); strcpy(this->db_name, db_name); this->gdbm = gdbm_open( @@ -59,14 +58,14 @@ storageDtor(void * _this) { Storage this = _this; - if (NULL != this->db_name) MEM_FREE(this->db_name); + if (NULL != this->db_name) TR_MEM_FREE(this->db_name); if (NULL != this->gdbm) { gdbm_close(this->gdbm); this->gdbm = NULL; } } -INIT_IFACE(Class, storageCtor, storageDtor, NULL); -CREATE_CLASS(Storage, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, storageCtor, storageDtor, NULL); +TR_CREATE_CLASS(Storage, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/storage/update.c b/src/storage/update.c index 283171e..96e8a1d 100644 --- a/src/storage/update.c +++ b/src/storage/update.c @@ -24,11 +24,8 @@ #include #include -#include "class.h" #include "storage/storage.h" -#include "utils/memory.h" - StoragePutResult storageUpdate( Storage this, diff --git a/src/stream/interface/reader.c b/src/stream/interface/reader.c index abd042b..f7ead6c 100644 --- a/src/stream/interface/reader.c +++ b/src/stream/interface/reader.c @@ -20,22 +20,18 @@ * along with this program. If not, see . */ -#include "class.h" - +#include "trbase.h" #include "stream/stream.h" #include "stream/interface/reader.h" -const struct interface i_StreamReader = { - "streamReader", - 1 -}; +TR_CREATE_INTERFACE(StreamReader, 1); ssize_t streamReaderRead(void * object, Stream st) { ssize_t ret; - RETCALL(object, StreamReader, read, ret, st); + TR_RETCALL(object, StreamReader, read, ret, st); return ret; } diff --git a/src/stream/interface/writer.c b/src/stream/interface/writer.c index 1928328..9ea7e29 100644 --- a/src/stream/interface/writer.c +++ b/src/stream/interface/writer.c @@ -20,22 +20,19 @@ * along with this program. If not, see . */ -#include "class.h" - +#include "trbase.h" #include "stream/stream.h" #include "stream/interface/writer.h" -const struct interface i_StreamWriter = { - "streamWriter", - 1 -}; +TR_CREATE_INTERFACE(StreamWriter, 1); + ssize_t streamWriterWrite(void * object, Stream st) { ssize_t ret; - RETCALL(object, StreamWriter, write, ret, st); + TR_RETCALL(object, StreamWriter, write, ret, st); return ret; } diff --git a/src/stream/stream.c b/src/stream/stream.c index e417cbc..7fe0aeb 100644 --- a/src/stream/stream.c +++ b/src/stream/stream.c @@ -23,7 +23,7 @@ #include #include -#include "class.h" +#include "trbase.h" #include "stream/stream.h" @@ -56,7 +56,7 @@ streamDtor(void * _this) { } -INIT_IFACE(Class, streamCtor, streamDtor, NULL); -CREATE_CLASS(Stream, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, streamCtor, streamDtor, NULL); +TR_CREATE_CLASS(Stream, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/taskrambler.c b/src/taskrambler.c index 1df673f..fe91346 100644 --- a/src/taskrambler.c +++ b/src/taskrambler.c @@ -42,15 +42,13 @@ #include "auth.h" #include "application/application.h" #include "application/adapter/http.h" -#include "interface/subject.h" #include "config/config.h" #include "config/value.h" -#include "class.h" +#include "trbase.h" #include "logger.h" #include "utils/signalHandling.h" -#include "utils/memory.h" #include "utils/mime_type.h" #define DEFAULT_SECS 10 @@ -77,15 +75,15 @@ main() int shm; struct randval * value; - logger = new(LoggerSyslog, LOGGER_DEBUG); - config = new(Config, CONFIGDIR "/taskrambler.conf"); + logger = TR_new(LoggerSyslog, LOGGER_DEBUG); + config = TR_new(Config, CONFIGDIR "/taskrambler.conf"); if (NULL == config) { loggerLog(logger, LOGGER_INFO, "unable to load configuration file: %s\n", CONFIGDIR "/taskrambler.conf"); - if (! INSTANCE_OF(LoggerStderr, logger)) { + if (! TR_INSTANCE_OF(LoggerStderr, logger)) { fprintf(stderr, "unable to load configuration file: %s\n", CONFIGDIR "/taskrambler.conf"); @@ -190,15 +188,15 @@ main() shm_unlink("/fooshm"); close(shm); - auth = new(Auth); + auth = TR_new(Auth); authCreate( auth, AUTH_LDAP, (ldap_host->value).string, CONFSTRA(ldap_base)); - users = new(Storage, user_storage); - passwords = new(Storage, password_storage); + users = TR_new(Storage, user_storage); + passwords = TR_new(Storage, password_storage); if (NULL == users || NULL == passwords) { puts("error opening database files...\n"); @@ -207,7 +205,7 @@ main() authCreate(auth, AUTH_STORAGE, passwords); - application = new( + application = TR_new( Application, value, users, @@ -215,13 +213,13 @@ main() "14de9e60-d497-4754-be72-f3bed52541fc", auth); - router = new(Router, application); - adapterHttp = new(ApplicationAdapterHttp, application, router); + router = TR_new(Router, application); + adapterHttp = TR_new(ApplicationAdapterHttp, application, router); - worker = new(HttpWorker, "taskrambler"); - subjectAttach(worker, adapterHttp); + worker = TR_new(HttpWorker, "taskrambler"); + TR_subjectAttach(worker, adapterHttp); - server = new( + server = TR_new( Server, logger, worker, @@ -269,14 +267,14 @@ main() } } while (!WIFEXITED(status) && !WIFSIGNALED(status)); - delete(server); - delete(worker); - delete(adapterHttp); - delete(router); - delete(application); - delete(passwords); - delete(users); - delete(auth); + TR_delete(server); + TR_delete(worker); + TR_delete(adapterHttp); + TR_delete(router); + TR_delete(application); + TR_delete(passwords); + TR_delete(users); + TR_delete(auth); clearMimeTypes(); assetPoolCleanup(); @@ -285,9 +283,9 @@ main() break; } - delete(config); - delete(logger); - memCleanup(); + TR_delete(config); + TR_delete(logger); + TR_memCleanup(); return 0; } diff --git a/src/testers/rbtree2.c b/src/testers/rbtree2.c index 23d8163..de4c662 100644 --- a/src/testers/rbtree2.c +++ b/src/testers/rbtree2.c @@ -1,10 +1,7 @@ #include #include -#include "class.h" -#include "commons.h" -#include "utils/memory.h" - +#include "tr_base.h" #include "tree.h" #include "utils/memory.h" @@ -20,7 +17,7 @@ void freeNode(const void * data, const int depth) { printf("now free %d at %p\n", *(int*)data, data); - MEM_FREE(data); + TR_MEM_FREE(data); } void diff --git a/src/testers/uuid.c b/src/testers/uuid.c index 62053c7..01a04da 100644 --- a/src/testers/uuid.c +++ b/src/testers/uuid.c @@ -1,12 +1,9 @@ #include #include -#include "class.h" +#include "trbase.h" #include "uuid.h" -#include "commons.h" -#include "utils/memory.h" - #define UUID_NS "4f947b70-6f9f-43b6-8dc1-1321977c8240" diff --git a/src/tree/delete.c b/src/tree/delete.c index 82bc7e2..8499119 100644 --- a/src/tree/delete.c +++ b/src/tree/delete.c @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include "trbase.h" #include "tree.h" Tree inOrderSuccessor(Tree); @@ -100,7 +101,7 @@ treeDelete(Tree * this, const void * search, TreeComp comp) if (rbBlack == node->color) { if (NULL != child && rbRed == child->color) { child->color = rbBlack; - delete(node); + TR_delete(node); return data; } else { del_node = node; @@ -113,7 +114,7 @@ treeDelete(Tree * this, const void * search, TreeComp comp) } } } else { - delete(node); + TR_delete(node); return data; } } @@ -239,7 +240,7 @@ treeDelete(Tree * this, const void * search, TreeComp comp) break; } - delete(del_node); + TR_delete(del_node); /* * not sure if deleting here is correct. */ diff --git a/src/tree/destroy.c b/src/tree/destroy.c index 364db9d..c776b50 100644 --- a/src/tree/destroy.c +++ b/src/tree/destroy.c @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include "trbase.h" #include "tree.h" void @@ -48,7 +49,7 @@ treeDestroy(Tree * this, TreeAction action) action(node->data, depth); previous = node; - delete(node); + TR_delete(node); node = parent; depth--; diff --git a/src/tree/insert.c b/src/tree/insert.c index f5d4c46..5bb34cf 100644 --- a/src/tree/insert.c +++ b/src/tree/insert.c @@ -20,6 +20,7 @@ * along with this program. If not, see . */ +#include "trbase.h" #include "tree.h" void treeRotateLeft(Tree *, Tree); @@ -40,7 +41,7 @@ treeInsert(Tree * this, const void * search, TreeComp comp) * if the root is NULL we simple add the element and set * node to it. */ - *this = node = new_node = new(Tree, search); + *this = node = new_node = TR_new(Tree, search); } else { /* * first search for it and if its found return the data @@ -78,11 +79,11 @@ treeInsert(Tree * this, const void * search, TreeComp comp) * as we have not found it now add a new element. */ if (0 < comparison) { - node->left = new(Tree, search); + node->left = TR_new(Tree, search); TREE_LEFT(node)->parent = node; node = new_node = TREE_LEFT(node); } else { - node->right = new(Tree, search); + node->right = TR_new(Tree, search); TREE_RIGHT(node)->parent = node; node = new_node = TREE_RIGHT(node); } diff --git a/src/tree/tree.c b/src/tree/tree.c index cc3bcd1..06272ae 100644 --- a/src/tree/tree.c +++ b/src/tree/tree.c @@ -24,8 +24,8 @@ #include +#include "trbase.h" #include "tree.h" -#include "class.h" static int @@ -48,7 +48,7 @@ treeDtor(void * _this) { } -INIT_IFACE(Class, treeCtor, treeDtor, NULL); -CREATE_CLASS(Tree, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, treeCtor, treeDtor, NULL); +TR_CREATE_CLASS(Tree, NULL, TR_IF(TR_Class)); // vim: set ts=4 sw=4: diff --git a/src/user/user.c b/src/user/user.c index 5d2bdc3..9d9f4f5 100644 --- a/src/user/user.c +++ b/src/user/user.c @@ -22,12 +22,7 @@ #include "user.h" #include "uuid.h" -#include "class.h" - -#include "interface/serializable.h" -#include "interface/indexable.h" - -#include "utils/memory.h" +#include "trbase.h" static @@ -53,7 +48,7 @@ userCtor(void * _this, va_list * params) nsurname + 1 + 4 * sizeof(size_t); - this->username = memMalloc(storage_size); + this->username = TR_malloc(storage_size); memcpy(this->username, username, nusername); this->username[nusername] = '\0'; @@ -92,7 +87,7 @@ userDtor(void * _this) User this = _this; if (NULL != this->username) { - MEM_FREE(this->username); + TR_MEM_FREE(this->username); } } @@ -112,7 +107,7 @@ userSerialize( *this->nsurname + 1 + 4 * sizeof(size_t); - *serialized = memMalloc(*nserialized); + *serialized = TR_malloc(*nserialized); memcpy(*serialized, this->username, *nserialized); } @@ -127,7 +122,7 @@ userUnserialize( User this = _this; size_t * user_data_sizes; - this->username = memMalloc(nserialized); + this->username = TR_malloc(nserialized); memcpy(this->username, serialized, nserialized); user_data_sizes = @@ -144,10 +139,11 @@ userUnserialize( } static -Uuid -userIndexUuid(void * _this, Uuid namespace) +void * +userIndexUuid(void * _this, void * _namespace) { - User this = _this; + User this = _this; + Uuid namespace = _namespace; return uuidVersion3( (unsigned char *)this->username, @@ -156,9 +152,14 @@ userIndexUuid(void * _this, Uuid namespace) } -INIT_IFACE(Class, userCtor, userDtor, NULL); -INIT_IFACE(Serializable, userSerialize, userUnserialize); -INIT_IFACE(Indexable, userIndexUuid); -CREATE_CLASS(User, NULL, IFACE(Class), IFACE(Serializable), IFACE(Indexable)); +TR_INIT_IFACE(TR_Class, userCtor, userDtor, NULL); +TR_INIT_IFACE(TR_Serializable, userSerialize, userUnserialize); +TR_INIT_IFACE(TR_Indexable, userIndexUuid); +TR_CREATE_CLASS( + User, + NULL, + TR_IF(TR_Class), + TR_IF(TR_Serializable), + TR_IF(TR_Indexable)); // vim: set ts=4 sw=4: diff --git a/src/utils/http.c b/src/utils/http.c index 0001eaa..1719d51 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -30,9 +30,7 @@ #include "http/request.h" #include "http/response.h" -#include "class.h" - -#include "commons.h" +#include "trbase.h" #define ALPHAVAL(x) (tolower((x)) - 'a' + 0xa) #define DIGITVAL(x) ((x) - '0') @@ -130,14 +128,14 @@ httpGetMessage( const char * part3, size_t len3) { if (isHttpVersion(part1, len1)) { - return new(HttpResponse, + return TR_new(HttpResponse, part1, len1, strtoul(part2, NULL, 10), part3, len3); } if (isHttpVersion(part3, len3)) { - return new(HttpRequest, + return TR_new(HttpRequest, part1, len1, part2, len2, part3, len3); diff --git a/src/utils/memory.c b/src/utils/memory.c deleted file mode 100644 index f00e435..0000000 --- a/src/utils/memory.c +++ /dev/null @@ -1,869 +0,0 @@ -/** - * \file This holds all stufff related our memory managent. - * I try the best as far as I can to reduce memory fragmentation - * and unneccessary calls to alloc and free. - * - * To achive this I try an approach described here as "Quick Fit". - * http://www.flounder.com/memory_allocation.htm - * - * The basic idea is to keep allocated memory segments and don't free - * them again. Instead I will put them in a tree indexed by their size. - * To get new memory I first have a look in the tree if there is - * a fitting memory segment. Fitting mean, larger or exactly the size - * I need. If there is one, use it. If not create a new one using - * usual malloc approach. - * I won't split the reagions at all because most likely they will be - * free soon again. This way I might waste some memory, so I have to - * keep an eye on this. - * - * Right now I don't build an upper limit for allocation. The limit - * still is the system memory itself. - * - * This is not implemented as a class because it will be used in the - * process of object creation. - * - * The data structure is a balanced tree with size as key. - * Under the size key is a list of elements of the same size. - * - * \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 -#include -#include - -#include "utils/memory.h" -#include "tree.h" - - -struct memSegment -{ - size_t ref_count; - size_t size; - void * ptr; - - enum rbColor color; - - struct memSegment * next; - struct memSegment * last; - - struct memSegment * parent; - struct memSegment * left; - struct memSegment * right; -}; - -struct memSegment * -newElement(size_t size) -{ - struct memSegment * element = malloc(size); - - element->ref_count = 1; - element->size = size; - element->ptr = (void*)element + sizeof(struct memSegment); - - element->next = NULL; - element->last = NULL; - - element->color = rbRed; - element->parent = NULL; - element->left = NULL; - element->right = NULL; - - return element; -} - -/** - * find element in tree - */ -struct memSegment * -findElement(struct memSegment * tree, size_t size) -{ - struct memSegment * fitting = NULL; - - while (NULL != tree) { - if (tree->size == size) { - fitting = tree; - break; - } - - if (size > tree->size) { - tree = tree->right; - } else { - fitting = tree; - tree = tree->left; - } - } - - return fitting; -} - -/* - * function to get specific elements needed for - * rb handling, grandparent, uncle and sibbling - */ -struct memSegment * -grandparent(struct memSegment * node) -{ - if (NULL != node && NULL != node->parent) { - return node->parent->parent; - } - - return NULL; -} - -struct memSegment * -uncle(struct memSegment * node) -{ - struct memSegment * gp = grandparent(node); - - if (NULL == gp) { - return NULL; - } - - if (node->parent == gp->left) { - return gp->right; - } - - return gp->left; -} - -struct memSegment * -sibling(struct memSegment * node) -{ - if (NULL == node) { - return NULL; - } - - if (NULL == node->parent->left || node == node->parent->left) { - return node->parent->right; - } else { - return node->parent->left; - } -} - -/* - * tree modifications...needed for rb handling. - */ -void -rotateLeft(struct memSegment ** tree, struct memSegment * node) -{ - struct memSegment * rightChild = node->right; - struct memSegment * rcLeftSub = node->right->left; - - rightChild->left = node; - rightChild->parent = node->parent; - node->right = rcLeftSub; - if (NULL != rcLeftSub) { - rcLeftSub->parent = node; - } - - if (node->parent) { - if (node->parent->left == node) { - node->parent->left = rightChild; - } else { - node->parent->right = rightChild; - } - } else { - *tree = rightChild; - } - - node->parent = rightChild; -} - -void -rotateRight(struct memSegment ** tree, struct memSegment * node) -{ - struct memSegment * leftChild = node->left; - struct memSegment * lcRightSub = node->left->right; - - leftChild->right = node; - leftChild->parent = node->parent; - node->left = lcRightSub; - if (NULL != lcRightSub) { - lcRightSub->parent = node; - } - - if (node->parent) { - if (node->parent->left == node) { - node->parent->left = leftChild; - } else { - node->parent->right = leftChild; - } - } else { - *tree = leftChild; - } - - node->parent = leftChild; -} - -void -replaceNode( - struct memSegment ** tree, - struct memSegment * node1, - struct memSegment * node2) -{ - if (NULL != node1->parent) { - if (node1 == node1->parent->left) { - node1->parent->left = node2; - } else { - node1->parent->right = node2; - } - } else { - *tree = node2; - } - - if (NULL != node2) { - node2->parent = node1->parent; - } -} - - -/** - * insert element in tree - */ -struct memSegment * -insertElement(struct memSegment ** tree, struct memSegment * element) -{ - struct memSegment * node = *tree; - struct memSegment * new_node = NULL; - struct memSegment * u; - struct memSegment * g; - - element->next = NULL; - element->last = NULL; - - element->color = rbRed; - element->parent = NULL; - element->left = NULL; - element->right = NULL; - - // if tree is empty it's simple... :) - if (NULL == node) { - *tree = node = new_node = element; - } else { - // normal binary tree add.... - while (NULL != node) { - if (element->size < node->size) { - if (NULL == node->left) { - node->left = element; - node->left->parent = node; - new_node = node = node->left; - break; - } else { - node = node->left; - } - } else if (element->size > node->size) { - if (NULL == node->right) { - node->right = element; - node->right->parent = node; - new_node = node = node->right; - break; - } else { - node = node->right; - } - } else { - if (NULL == node->next) { - node->next = element; - node->last = element; - } else { - node->last->next = element; - node->last = element; - } - return node; - } - } - } - - if (NULL != new_node) { - /* - * handle reballancing rb style - */ - while (1) { - // case 1 - if (node->parent == NULL) { - node->color = rbBlack; - // we're done.... :) - break; - } - - // case 2 - if (node->parent->color == rbBlack) { - // Tree is still valid ... wow, again we're done... :) - break; - } - - // case 3 - u = uncle(node); - g = grandparent(node); - - if (u != NULL && u->color == rbRed) { - node->parent->color = rbBlack; - u->color = rbBlack; - g->color = rbRed; - - node = g; - continue; - } - - // case 4 - if (node == node->parent->right && node->parent == g->left) { - rotateLeft(tree, node->parent); - node = node->left; - } else if (node == node->parent->left && node->parent == g->right) { - - rotateRight(tree, node->parent); - node = node->right; - } - - // case 5 - g = grandparent(node); - - node->parent->color = rbBlack; - g->color = rbRed; - - if (node == node->parent->left) { - rotateRight(tree, g); - } else { - rotateLeft(tree, g); - } - - // we're done.. - break; - } - } - - return new_node; -} - -/** - * delete element from tree - * here multiple functions are involved.... - * ======================================================================= - */ -/** - * find minimum of the right subtree aka leftmost leaf of right subtree - * aka left in-order successor. - * We return the parent of the element in the out argument parent. - * This can be NULL wenn calling. - * - * 2: *successor = {size = 80, ptr = 0x603ae0, color = rbRed, parent = 0x603160, - * left = 0x0, right = 0x0} - * 1: *node = {size = 70, ptr = 0x603a60, color = rbBlack, parent = 0x603070, - * left = 0x6030e0, right = 0x6031e0} - * - */ -struct memSegment * -findInOrderSuccessor(struct memSegment * tree) -{ - struct memSegment * node = tree->right; - - while (NULL != node->left) { - node = node->left; - } - - return node; -} - -struct memSegment * -deleteElement(struct memSegment ** tree, struct memSegment * element) -{ - struct memSegment * node = *tree; - struct memSegment * del_node; - struct memSegment * child; - struct memSegment * s; - - // find the relevant node and it's parent - while (NULL != node) { - - if (element->size < node->size) { - node = node->left; - } else if (element->size > node->size) { - node = node->right; - } else { - if (NULL != node->next) { - if (NULL != node->parent) { - if (node == node->parent->left) { - node->parent->left = node->next; - } else { - node->parent->right = node->next; - } - } else { - *tree = node->next; - } - - if (NULL != node->left) { - node->left->parent = node->next; - } - - if (NULL != node->right) { - node->right->parent = node->next; - } - - node->next->last = node->last; - node->next->color = node->color; - node->next->parent = node->parent; - node->next->left = node->left; - node->next->right = node->right; - - return node; - } - break; - } - } - - // element not found - if (NULL == node) { - return node; - } - - del_node = node; - - // now our cases follows...the first one is the same as with - // simple binary search trees. Two non null children. - - // case 1: two children - if (NULL != node->left && NULL != node->right) { - struct memSegment * successor = findInOrderSuccessor(node); - - enum rbColor tmpcolor = successor->color; - struct memSegment * tmpparent = successor->parent; - struct memSegment * tmpleft = successor->left; - struct memSegment * tmpright = successor->right; - - replaceNode(tree, node, successor); - - successor->color = node->color; - successor->left = node->left; - successor->left->parent = successor; - // the right one might be successor... - if (node->right == successor) { - successor->right = node; - node->parent = successor; - } else { - successor->right = node->right; - node->right->parent = successor; - node->parent = tmpparent; - tmpparent->left = node; - } - - node->color = tmpcolor; - node->left = tmpleft; - node->right = tmpright; - } - - // Precondition: n has at most one non-null child. - child = (NULL == node->right) ? node->left : node->right; - replaceNode(tree, node, child); - - // delete one child case - // TODO this is overly complex as simply derived from the function... - // maybe this can be simplified. Maybe not...check. - if (node->color == rbBlack) { - if (NULL != child && child->color == rbRed) { - child->color = rbBlack; - // done despite modifying tree itself if neccessary.. - return del_node; - } else { - if (NULL != child) { - node = child; - } else { - node->color = rbBlack; - node->left = NULL; - node->right = NULL; - } - } - } else { - return del_node; - } - - // delete and rb rebalance... - while(1) { - // case 1 - if (NULL == node->parent) { - // done again - break; - } - - // case 2 - s = sibling(node); - - if (NULL != s && s->color == rbRed) { - node->parent->color = rbRed; - s->color = rbBlack; - - /* - * detect which child we are...assumption - * if we are not parent->right and parent->right is not - * null we must be left, even if its set to NULL previously - */ - if (NULL != node->parent->right && node != node->parent->right) { - rotateLeft(tree, node->parent); - } else { - rotateRight(tree, node->parent); - } - } - - s = sibling(node); - // case 3 / 4 - if (NULL == s || ((s->color == rbBlack) && - (NULL == s->left || s->left->color == rbBlack) && - (NULL == s->right || s->right->color == rbBlack))) { - - if (NULL != s) { - s->color = rbRed; - } - - if (node->parent->color == rbBlack) { - // case 3 - node = node->parent; - continue; - } else { - // case 4 - node->parent->color = rbBlack; - // and done again... - break; - } - } - - // case 5 - if (NULL != s && s->color == rbBlack) { - // this if statement is trivial, - // due to case 2 (even though case 2 changed the sibling to a - // sibling's child, - // the sibling's child can't be red, since no red parent can - // have a red child). - // - // the following statements just force the red to be on the - // left of the left of the parent, - // or right of the right, so case 6 will rotate correctly. - if ((node == node->parent->left) && - (NULL == s->right || s->right->color == rbBlack) && - (NULL != s->left && s->left->color == rbRed)) { - - // this last test is trivial too due to cases 2-4. - s->color = rbRed; - s->left->color = rbBlack; - - rotateRight(tree, s); - } else if ((node == node->parent->right) && - (NULL == s->left || s->left->color == rbBlack) && - (NULL != s->right && s->right->color == rbRed)) { - // this last test is trivial too due to cases 2-4. - s->color = rbRed; - s->right->color = rbBlack; - - rotateLeft(tree, s); - } - } - - s = sibling(node); - // case 6 - if (NULL != s) { - s->color = node->parent->color; - } - - if (NULL != node && NULL != node->parent) { - node->parent->color = rbBlack; - - /* - * detect which child we are...assumption - * if we are not parent->right and parent->right is not - * null we must be left, even if its set to NULL previously - */ - if (NULL != node->parent->right && node != node->parent->right) { - if (NULL != s->right) { - s->right->color = rbBlack; - } - rotateLeft(tree, node->parent); - } else { - if (NULL != s->left) { - s->left->color = rbBlack; - } - rotateRight(tree, node->parent); - } - } - - // done... - break; - } - - return del_node; -} - - -void -traverse(struct memSegment * tree, void (*cb)(struct memSegment *, int)) -{ - struct memSegment * previous = tree; - struct memSegment * node = tree; - int depth = 1; - - /* - * I think this has something like O(n+log(n)) on a ballanced - * tree because I have to traverse back the rightmost leaf to - * the root to get a break condition. - */ - while (node) { - /* - * If we come from the right so nothing and go to our - * next parent. - */ - if (previous == node->right) { - previous = node; - node = node->parent; - depth--; - continue; - } - - if ((NULL == node->left || previous == node->left)) { - /* - * If there are no more elements to the left or we - * came from the left, process data. - */ - cb(node, depth); - previous = node; - - if (NULL != node->right) { - node = node->right; - depth++; - } else { - node = node->parent; - depth--; - } - } else { - /* - * if there are more elements to the left go there. - */ - previous = node; - node = node->left; - depth++; - } - } -} - -void -post(struct memSegment * tree, void (*cb)(struct memSegment *, int)) -{ - struct memSegment * previous = tree; - struct memSegment * node = tree; - int depth = 1; - - /* - * I think this has something like O(n+log(n)) on a ballanced - * tree because I have to traverse back the rightmost leaf to - * the root to get a break condition. - */ - while (node) { - /* - * If we come from the right so nothing and go to our - * next parent. - */ - if (((NULL == node->left || previous == node->left) - && NULL == node->right) - || previous == node->right) { - - struct memSegment * parent = node->parent; - - cb(node, depth); - - previous = node; - node = parent; - depth--; - continue; - } - - if ((NULL == node->left || previous == node->left)) { - /* - * If there are no more elements to the left or we - * came from the left, process data. - */ - previous = node; - - if (NULL != node->right) { - node = node->right; - depth++; - } else { - node = node->parent; - depth--; - } - } else { - /* - * if there are more elements to the left go there. - */ - previous = node; - node = node->left; - depth++; - } - } -} - -void printElement(struct memSegment * node, int depth) -{ - int i; - - printf("%s %010zu:%p(%02d)", - (node->color==rbRed)?"R":"B", - node->size, - node->ptr, - depth); - for (i=0; inext; - while (NULL != node) { - printf(" %s %010zu:%p(%02d)", - (node->color==rbRed)?"R":"B", - node->size, - node->ptr, - depth); - for (i=0; inext; - } -} - -void -cleanup(struct memSegment * node, int depth) -{ - while (NULL != node) { - struct memSegment * next = node->next; - free(node); - node = next; - } -} - -struct memSegment * segments = NULL; - -static -void -segmentFree(struct memSegment * segment, int depth) -{ - while (NULL != segment) { - struct memSegment * next = segment->next; - free(segment); - segment = next; - } -} - -void * -memNewRef(void * mem) -{ - struct memSegment * seg = (mem - sizeof(struct memSegment)); - - seg->ref_count++; - - return mem; -} - -/* - * This will always allocate a multiple of PAGESIZE - */ -void * -memMalloc(size_t size) -{ - struct memSegment * seg = NULL; - //long psize = sysconf(_SC_PAGESIZE); - long psize = 64; - - size += sizeof(struct memSegment); - - /* allocate only blocks of a multiple of pagesize, similar to cbuf */ - size = (0>=size)?1:(0!=size%psize)?(size/psize)+1:size/psize; - size *= psize; - -#ifdef MEM_OPT - seg = findElement(segments, size); -#endif - - if (NULL == seg) { - seg = newElement(size); - } else { - // remove the found one from the tree as we use it now. - seg = deleteElement(&segments, seg); - } - - return seg->ptr; -} - -/** - * this is a really memory wasting solution....just to be able to - * use calloc, which might be faster then malloc/memset solution. - * - * Maybe this is a bad idea, as we need to memset the buffer anyway - * if it comes from our tree, which hopefully should be the majority - * of cases. - */ -void * -memCalloc(size_t nmemb, size_t size) -{ - size_t _size = nmemb * size; - void * mem = memMalloc(_size); - - memset(mem, 0, _size); - - return mem; -} - -void -memFree(void ** mem) -{ - if (NULL != *mem) { - struct memSegment * seg = (*mem - sizeof(struct memSegment)); - - if (1 < seg->ref_count) { - seg->ref_count--; - } else { -#ifdef MEM_OPT - insertElement(&segments, seg); -#else - free(seg); -#endif - } - - *mem = NULL; - } -} - -size_t -memGetSize(void * mem) -{ - struct memSegment * segment; - - if (NULL == mem) { - return 0; - } - - segment = (struct memSegment *)(mem - sizeof(struct memSegment)); - return segment->size; -} - -void -memCleanup() -{ -#ifdef MEM_OPT - post(segments, segmentFree); -#endif -} - -// vim: set ts=4 sw=4: diff --git a/src/utils/mime_type.c b/src/utils/mime_type.c index 641f70e..f328693 100644 --- a/src/utils/mime_type.c +++ b/src/utils/mime_type.c @@ -27,11 +27,8 @@ // for fopen #include - #include "hash.h" - -#include "class.h" -#include "commons.h" +#include "trbase.h" Hash mime_types = NULL; @@ -45,7 +42,7 @@ readMimeTypes(void) char buffer[512]; buffer[511] = '\0'; - mime_types = new(Hash); + mime_types = TR_new(Hash); while (NULL != fgets(buffer, 511, handle)) { char * tmp; @@ -72,7 +69,7 @@ readMimeTypes(void) } hashAdd(mime_types, - new(HashValue, key, nkey, value, nvalue)); + TR_new(HashValue, key, nkey, value, nvalue)); } fclose(handle); @@ -105,7 +102,7 @@ getMimeType(const char * ext, size_t len) void clearMimeTypes(void) { - delete(mime_types); + TR_delete(mime_types); } // vim: set ts=4 sw=4: diff --git a/src/uuid/_format3or5.c b/src/uuid/_format3or5.c index f4efec3..10734bf 100644 --- a/src/uuid/_format3or5.c +++ b/src/uuid/_format3or5.c @@ -29,7 +29,6 @@ // for already available uuid functionality #include -#include "class.h" #include "uuid.h" void diff --git a/src/uuid/compare.c b/src/uuid/compare.c index 31adf96..fa106f4 100644 --- a/src/uuid/compare.c +++ b/src/uuid/compare.c @@ -23,7 +23,6 @@ // for already available uuid functionality #include -#include "class.h" #include "uuid.h" int diff --git a/src/uuid/parse.c b/src/uuid/parse.c index 69d12a7..c13bb2c 100644 --- a/src/uuid/parse.c +++ b/src/uuid/parse.c @@ -23,13 +23,13 @@ // for already available uuid functionality #include -#include "class.h" +#include "trbase.h" #include "uuid.h" Uuid uuidParse(const UuidString uuid_str) { - Uuid uuid = new(Uuid); + Uuid uuid = TR_new(Uuid); uuid_parse(uuid_str, (uuid->uuid).value); return uuid; diff --git a/src/uuid/unparse.c b/src/uuid/unparse.c index 11623b5..1663312 100644 --- a/src/uuid/unparse.c +++ b/src/uuid/unparse.c @@ -23,7 +23,6 @@ // for already available uuid functionality #include -#include "class.h" #include "uuid.h" void diff --git a/src/uuid/uuid.c b/src/uuid/uuid.c index 8d08e52..0796d0a 100644 --- a/src/uuid/uuid.c +++ b/src/uuid/uuid.c @@ -23,7 +23,7 @@ #include #include -#include "class.h" +#include "trbase.h" #include "uuid.h" @@ -50,10 +50,10 @@ uuidClone(void * _this, void * _base) memcpy((this->uuid).value, (base->uuid).value, 16); } -INIT_IFACE(Class, uuidCtor, uuidDtor, uuidClone); -CREATE_CLASS(Uuid, NULL, IFACE(Class)); +TR_INIT_IFACE(TR_Class, uuidCtor, uuidDtor, uuidClone); +TR_CREATE_CLASS(Uuid, NULL, TR_IF(TR_Class)); -INSTANCE(Uuid, uuidZero) { +TR_INSTANCE(Uuid, uuidZero) { .uuid.value = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }}; diff --git a/src/uuid/version1.c b/src/uuid/version1.c index 3da4438..1b12838 100644 --- a/src/uuid/version1.c +++ b/src/uuid/version1.c @@ -23,13 +23,13 @@ // for already available uuid functionality #include -#include "class.h" +#include "trbase.h" #include "uuid.h" Uuid uuidVersion1() { - Uuid uuid = new(Uuid); + Uuid uuid = TR_new(Uuid); uuid_generate((uuid->uuid).value); return uuid; diff --git a/src/uuid/version3.c b/src/uuid/version3.c index f25e2d9..d4a24b9 100644 --- a/src/uuid/version3.c +++ b/src/uuid/version3.c @@ -30,7 +30,7 @@ #include // for already available uuid functionality -#include "class.h" +#include "trbase.h" #include "uuid.h" void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version); @@ -40,8 +40,8 @@ uuidVersion3(const unsigned char * name, size_t nname, Uuid nsid) { MD5_CTX ctx; unsigned char hash[16]; - Uuid net_nsid = clone(nsid); - Uuid uuid = new(Uuid); + Uuid net_nsid = TR_clone(nsid); + Uuid uuid = TR_new(Uuid); /* * put the namespace id into network byte order. @@ -61,7 +61,7 @@ uuidVersion3(const unsigned char * name, size_t nname, Uuid nsid) MD5_Update(&ctx, name, nname); MD5_Final(hash, &ctx); - delete(net_nsid); + TR_delete(net_nsid); _uuidFormat3or5(uuid, hash, 3); diff --git a/src/uuid/version5.c b/src/uuid/version5.c index 0274fcb..e1586df 100644 --- a/src/uuid/version5.c +++ b/src/uuid/version5.c @@ -30,7 +30,7 @@ #include // for already available uuid functionality -#include "class.h" +#include "trbase.h" #include "uuid.h" void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version); @@ -40,8 +40,8 @@ uuidVersion5(const unsigned char * name, size_t nname, Uuid nsid) { SHA_CTX ctx; unsigned char hash[20]; - Uuid net_nsid = clone(nsid); - Uuid uuid = new(Uuid); + Uuid net_nsid = TR_clone(nsid); + Uuid uuid = TR_new(Uuid); /* * put the namespace id into network byte order. @@ -61,7 +61,7 @@ uuidVersion5(const unsigned char * name, size_t nname, Uuid nsid) SHA1_Update(&ctx, name, nname); SHA1_Final(hash, &ctx); - delete(net_nsid); + TR_delete(net_nsid); _uuidFormat3or5(uuid, hash, 5);