diff --git a/configure.ac b/configure.ac index 290af7b..7c50ab9 100644 --- a/configure.ac +++ b/configure.ac @@ -89,13 +89,9 @@ AC_CONFIG_FILES([Makefile src/Makefile src/asset/Makefile src/auth/Makefile - src/cbuf/Makefile - src/hash/Makefile - src/queue/Makefile src/http/Makefile src/server/Makefile src/session/Makefile - src/tree/Makefile src/application/Makefile src/storage/Makefile src/user/Makefile diff --git a/include/application/application.h b/include/application/application.h index 229f853..31b342f 100644 --- a/include/application/application.h +++ b/include/application/application.h @@ -25,11 +25,11 @@ #include -#include -#include +#include "trbase.h" +#include "trhash.h" +#include "trdata.h" #include "session.h" -#include "hash.h" #include "auth.h" #include "auth/credential.h" #include "storage/storage.h" @@ -43,24 +43,24 @@ struct randval { }; TR_CLASS(Application) { - Hash * active_sessions; + TR_Hash * active_sessions; time_t session_time_ofs; Auth auth; - struct randval * val; + struct randval * val; - Storage users; - Storage passwords; - Storage roles; + Storage users; + Storage passwords; + Storage roles; - TR_Uuid user_namespace; + TR_Uuid user_namespace; - Hash roles_user_index; - Hash roles_resource_index; + TR_Hash roles_user_index; + TR_Hash roles_resource_index; - const char * version; - const char * loc; + const char * version; + const char * loc; }; int applicationLogin(Application, Credential, Session); diff --git a/include/asset.h b/include/asset.h index c67a29a..301d12b 100644 --- a/include/asset.h +++ b/include/asset.h @@ -27,7 +27,6 @@ #include #include "trbase.h" -#include "hash.h" TR_CLASS(Asset) { diff --git a/include/cbuf.h b/include/cbuf.h deleted file mode 100644 index 04c02fe..0000000 --- a/include/cbuf.h +++ /dev/null @@ -1,79 +0,0 @@ -/** - * \file - * My implementation of a ringbuffer. - * It maps a shared memory object twice directly following - * thus make it possible to read and write from any - * position within the buffer without the nasty wrap - * calculations. - * This is achived because the same memory region is mapped - * at the two addresses. - * - * \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 __CBUF_H__ -#define __CBUF_H__ - -#include -#include -#include - -#include "trbase.h" -#include "trio.h" - -#define ECBUFOVFL 100 - - -TR_CLASS(Cbuf) { - char * shm_name; // shared memory identifier - - char * data; - Bool lock; - - size_t bsize; - size_t bused; - - size_t write; - size_t read; -}; - -ssize_t cbufRead(Cbuf, TR_Stream); -ssize_t cbufWrite(Cbuf, TR_Stream); - -char * cbufGetLine(Cbuf, char **); -char * cbufGetData(Cbuf, size_t); -char * cbufSetData(Cbuf, const void *, size_t); -void cbufEmpty(Cbuf); - -char * cbufGetRead(Cbuf this); -char * cbufGetWrite(Cbuf this); -char * cbufMemchr(Cbuf this, int c); -size_t cbufAddrIndex(Cbuf this, const void * c); -void cbufIncRead(Cbuf this, size_t n); -void cbufIncWrite(Cbuf this, size_t n); -size_t cbufGetFree(Cbuf this); -char cbufIsEmpty(Cbuf this); -void cbufSkipNonAlpha(Cbuf this); -Bool cbufIsLocked(Cbuf this); -void cbufLock(Cbuf this); -void cbufRelease(Cbuf this); - -#endif // __CBUF_H__ - -// vim: set ts=4 sw=4: diff --git a/include/config/config.h b/include/config/config.h index 716bea1..ab6f959 100644 --- a/include/config/config.h +++ b/include/config/config.h @@ -24,15 +24,15 @@ #define __CONFIG_H__ #include "trbase.h" -#include "hash.h" +#include "trdata.h" #include "config/value.h" #define MAX_CONFIG_LINE 256 TR_CLASS(Config) { - char * cnf_file; - Hash config; + char * cnf_file; + TR_Hash config; }; ConfigValue configGet(Config, const char *, size_t); diff --git a/include/config/value.h b/include/config/value.h index 5696585..049a460 100644 --- a/include/config/value.h +++ b/include/config/value.h @@ -26,7 +26,6 @@ #include #include "trbase.h" -#include "hash.h" #define MAX_CONFIG_LINE 256 diff --git a/include/hash.h b/include/hash.h deleted file mode 100644 index 54868d7..0000000 --- a/include/hash.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __HASH_H__ -#define __HASH_H__ - -#include "hash/hash.h" -#include "hash/value.h" -#include "hash/interface/hashable.h" - -#endif // __HASH_H__ - -// vim: set ts=4 sw=4: diff --git a/include/hash/hash.h b/include/hash/hash.h deleted file mode 100644 index 555f5cb..0000000 --- a/include/hash/hash.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 __HASH_HASH_H__ -#define __HASH_HASH_H__ - -#include - -#include "trbase.h" -#include "tree.h" - -#define HASH_IS_EMPTY(h) ((h)->root) - -TR_CLASS(Hash) { - Tree root; -}; - -void * hashAdd(Hash, void *); -void * hashDelete(Hash, const char *, size_t); -void * hashGet(Hash, const char *, size_t); -void * hashGetFirst(Hash); -void * hashDeleteByVal(Hash, unsigned long); -void * hashGetByVal(Hash, unsigned long); -void hashEach(Hash, void (*)(const void*)); -void hashCleanup(Hash); - -#endif // __HASH_HASH_H__ - -// vim: set ts=4 sw=4: diff --git a/include/hash/interface/hashable.h b/include/hash/interface/hashable.h deleted file mode 100644 index c003cd2..0000000 --- a/include/hash/interface/hashable.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - * \file - * The logger 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 __HASH_INTERFACE_HASHABLE_H__ -#define __HASH_INTERFACE_HASHABLE_H__ - -#include "trbase.h" - -typedef unsigned long (* fptr_hashableGetHash)(void *); -typedef void (* fptr_hashableHandleDouble)(void *, void *); - -TR_INTERFACE(Hashable) { - TR_IFID; - fptr_hashableGetHash getHash; - fptr_hashableHandleDouble handleDouble; -}; - -extern unsigned long hashableGetHash(void *); -extern void hashableHandleDouble(void *, void *); - -#endif // __HASH_INTERFACE_HASHABLE_H__ - -// vim: set ts=4 sw=4: diff --git a/include/hash/value.h b/include/hash/value.h deleted file mode 100644 index 891e9e1..0000000 --- a/include/hash/value.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 __HASH_VALUE_H__ -#define __HASH_VALUE_H__ - -#include - -#include "trbase.h" - -TR_CLASS(HashValue) { - unsigned long hash; - - char * key; - void * value; - - size_t nkey; - size_t nvalue; -}; - -#endif // __HASH_VALUE_H__ - -// vim: set ts=4 sw=4: diff --git a/include/http/message.h b/include/http/message.h index 5211aef..c96e454 100644 --- a/include/http/message.h +++ b/include/http/message.h @@ -25,20 +25,19 @@ #define __HTTP_MESSAGE__ #include "trbase.h" -#include "trio.h" -#include "hash.h" +#include "trdata.h" #include "asset.h" TR_CLASS(HttpMessage) { - char * version; + char * version; - Hash header; + TR_Hash header; - Asset asset; - char * body; + Asset asset; + char * body; - int nbody; - int dbody; + int nbody; + int dbody; }; char httpMessageHasKeepAlive(HttpMessage); diff --git a/include/http/parser.h b/include/http/parser.h index d59adbd..98f9620 100644 --- a/include/http/parser.h +++ b/include/http/parser.h @@ -26,9 +26,8 @@ #include "trbase.h" #include "trio.h" +#include "trdata.h" #include "http/message.h" -#include "queue.h" -#include "cbuf.h" #define PARSER_MAX_BUF 131072 @@ -44,13 +43,13 @@ typedef enum e_HttpMessageState { TR_CLASS(HttpParser) { - Cbuf buffer; + TR_Cbuf buffer; Bool ourLock; char * incomplete; size_t isize; - Queue queue; + TR_Queue queue; HttpMessage current; HttpMessageState state; diff --git a/include/http/request.h b/include/http/request.h index 67bda30..97ee690 100644 --- a/include/http/request.h +++ b/include/http/request.h @@ -25,8 +25,8 @@ #define __HTTP_REQUEST_H__ #include "trbase.h" +#include "trdata.h" #include "http/message.h" -#include "hash.h" #define N_HTTP_METHOD 8 @@ -52,9 +52,9 @@ TR_CLASS(HttpRequest) { HttpMethod method_id; - Hash get; - Hash post; - Hash cookies; + TR_Hash get; + TR_Hash post; + TR_Hash cookies; }; HttpMethod httpRequestGetMethodId(HttpRequest); diff --git a/include/http/worker.h b/include/http/worker.h index 1d7011f..906a29d 100644 --- a/include/http/worker.h +++ b/include/http/worker.h @@ -28,32 +28,30 @@ #include #include "trbase.h" -#include "hash.h" +#include "trdata.h" #include "http/parser.h" #include "http/writer.h" -#include "cbuf.h" #include "session.h" #include "http/request.h" #include "http/response.h" -#include "queue.h" TR_CLASS(HttpWorker) { - char * id; + char * id; - Cbuf pbuf; - Hash asset_pool; + TR_Cbuf pbuf; + TR_Hash asset_pool; - void * application_adapter; + void * application_adapter; - HttpRequest current_request; - HttpMessage current_response; + HttpRequest current_request; + HttpMessage current_response; - Queue additional_headers; + TR_Queue additional_headers; - HttpParser parser; - HttpWriter writer; + HttpParser parser; + HttpWriter writer; }; #endif // __HTTP_WORKER_H__ diff --git a/include/http/writer.h b/include/http/writer.h index 200d5ab..9ae6b37 100644 --- a/include/http/writer.h +++ b/include/http/writer.h @@ -28,8 +28,8 @@ #include "trbase.h" #include "trio.h" +#include "trdata.h" #include "http/message.h" -#include "queue.h" /* @@ -79,7 +79,7 @@ typedef enum e_HttpWriterState { TR_CLASS(HttpWriter) { char * buffer; - Queue queue; + TR_Queue queue; HttpMessage current; size_t nbuffer; // size of buffer diff --git a/include/queue.h b/include/queue.h deleted file mode 100644 index 097aefd..0000000 --- a/include/queue.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * \file - * Holds requests ready for processing. - * - * \todo change this to a real queue. - * - * \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 __QUEUE_H__ -#define __QUEUE_H__ - -#include - -#include "trbase.h" - - -TR_CLASS(Queue) { - void * msg; - Queue next; - - /** - * first and last are only available in the initial queue - * element (the root). This elelment does not contain any message - * and exists only for organizational purpose. - * - * \todo next and first always have to be the same...so get rid - * of first. - */ - Queue first; - Queue last; - size_t nmsg; -}; - -void queuePut(Queue, void *); -void * queueGet(Queue); - -#define queueEmpty(this) (0 >= (this)->nmsg) - -#endif // __QUEUE_H__ - -// vim: set ts=4 sw=4: diff --git a/include/router.h b/include/router.h index d86295e..42f92d1 100644 --- a/include/router.h +++ b/include/router.h @@ -34,22 +34,22 @@ #include #include "trbase.h" -#include "hash.h" +#include "trdata.h" + #include "session.h" #include "http/request.h" #include "http/response.h" #include "application/application.h" -typedef char * (* fptr_routable)(Application, Session, Hash); +typedef char * (* fptr_routable)(Application, Session, TR_Hash); TR_CLASS(Router) { - Hash functions; + TR_Hash functions; Application application; void * handle; char * prefix; size_t nprefix; - }; HttpResponse routerRoute(Router, HttpRequest, Session); diff --git a/include/tree.h b/include/tree.h deleted file mode 100644 index 0accb44..0000000 --- a/include/tree.h +++ /dev/null @@ -1,138 +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 __TREE_H__ -#define __TREE_H__ - -#include "trbase.h" - -#define TREE_RIGHT(node) (NULL!=(node)?(node)->right:NULL) -#define TREE_LEFT(node) (NULL!=(node)?(node)->left:NULL) -#define TREE_PARENT(node) (NULL!=(node)?(node)->parent:NULL) - -#define TREE_CHILD(node) \ - (NULL==TREE_RIGHT((node))?TREE_LEFT((node)):TREE_RIGHT((node))) - -#define TREE_RIGHT_LEFT(node) \ - (NULL!=TREE_RIGHT((node))?TREE_LEFT(TREE_RIGHT((node))):NULL) - -#define TREE_LEFT_RIGHT(node) \ - (NULL!=TREE_LEFT((node))?TREE_RIGHT(TREE_LEFT((node))):NULL) - -#define TREE_SIBLING(node) \ - (NULL!=TREE_PARENT((node))? \ - ((node)==TREE_PARENT((node))->left? \ - TREE_PARENT((node))->right: \ - TREE_PARENT((node))->left): \ - NULL) - -#define TREE_GRANDPARENT(node) \ - (NULL!=TREE_PARENT((node))?TREE_PARENT((node))->parent:NULL) - -#define TREE_UNCLE(node) \ - (NULL!=TREE_GRANDPARENT((node))? \ - (TREE_PARENT((node))==TREE_GRANDPARENT((node))->left? \ - TREE_GRANDPARENT((node))->right: \ - TREE_GRANDPARENT((node))->left): \ - NULL) - -#define TREE_ROTATE_LEFT(root, node) \ - do { \ - if (NULL != TREE_RIGHT_LEFT((node))) { \ - TREE_RIGHT_LEFT((node))->parent = (node); \ - } \ - TREE_RIGHT((node))->left = (node); \ - if (NULL != TREE_PARENT((node))) { \ - if (TREE_PARENT((node))->left==(node)) { \ - TREE_PARENT((node))->left = (node)->right; \ - } else { \ - TREE_PARENT((node))->right = (node)->right; \ - } \ - } else { \ - *(root) = (node)->right; \ - } \ - (node)->right = TREE_RIGHT_LEFT((node)); \ - (node)->parent = (node)->right; \ - TREE_RIGHT((node))->parent = (node)->parent; \ - } while(0) - -#define TREE_ROTATE_RIGHT(root, node) \ - do { \ - if (NULL != TREE_LEFT_RIGHT((node))) { \ - TREE_LEFT_RIGHT((node))->parent = (node); \ - } \ - TREE_LEFT((node))->right = (node); \ - if (NULL != TREE_PARENT((node))) { \ - if (TREE_PARENT((node))->left==(node)) { \ - TREE_PARENT((node))->left = (node)->left; \ - } else { \ - TREE_PARENT((node))->right = (node)->left; \ - } \ - } else { \ - *(root) = (node)->left; \ - } \ - TREE_LEFT((node))->parent = (node)->parent; \ - (node)->left = TREE_LEFT_RIGHT((node)); \ - (node)->parent = (node)->right; \ - } while(0) - -#define TREE_REPLACE_NODE(root, node1, node2) \ - do { \ - if (NULL != TREE_PARENT((node1))) { \ - if ((node1) == TREE_PARENT((node1))->left) { \ - TREE_PARENT((node1))->left = (node2); \ - } else { \ - TREE_PARENT((node1))->right = (node2); \ - } \ - } else { \ - *(root) = (node2); \ - } \ - if (NULL != (node2)) { \ - (node2)->parent = (node1)->parent; \ - } \ - } while(0) - - -enum rbColor {rbBlack=1, rbRed=2}; - -TR_CLASS(Tree) { - void * data; - - enum rbColor color; - - Tree parent; - Tree left; - Tree right; -}; - -typedef int (*TreeComp)(const void *, const void *); -typedef void (*TreeAction)(const void *, const int); - -void * treeFind(Tree, const void *, TreeComp); -void * treeInsert(Tree *, const void *, TreeComp); -void * treeDelete(Tree *, const void *, TreeComp); -void treeWalk(Tree, TreeAction); -void treeDestroy(Tree *, TreeAction); - -#endif // __TREE_H__ - -// vim: set ts=4 sw=4: diff --git a/src/Makefile.am b/src/Makefile.am index 5742be5..6dfc2bf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,11 +7,6 @@ TRUTILS = utils/http.c \ utils/signalHandling.c \ utils/mime_type.c -TRCOMMONLIBS = cbuf/libcbuf.la \ - hash/libhash.la \ - queue/libqueue.la \ - tree/libtree.la - TRHTTPSERVER = http/libhttp.la \ asset/libasset.la \ server/libserver.la @@ -24,22 +19,18 @@ TR = ./application/.libs/libapplication.a \ ./config/.libs/libconfig.a \ ./router/.libs/librouter.a -TRLIBS = -ltrbase -ltrhashing -ltrio -ltrutils -ltrhttpserver -ltrcommon +TRLIBS = -ltrbase -ltrhashing -ltrio -ltrdata -ltrutils -ltrhttpserver USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid AM_CFLAGS += -I../include/ bin_PROGRAMS = taskrambler -lib_LTLIBRARIES = libtrutils.la libtrcommon.la libtrhttpserver.la +lib_LTLIBRARIES = libtrutils.la libtrhttpserver.la libtrutils_la_SOURCES = $(TRUTILS) libtrutils_la_CFLAGS = $(AM_CFLAGS) libtrutils_la_LIBADD = -libtrcommon_la_SOURCES = -libtrcommon_la_CFLAGS = $(AM_CFLAGS) -libtrcommon_la_LIBADD = $(TRCOMMONLIBS) - libtrhttpserver_la_SOURCES = libtrhttpserver_la_CFLAGS = $(AM_CFLAGS) libtrhttpserver_la_LIBADD = $(TRHTTPSERVER) @@ -50,6 +41,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 hash queue http \ - server session tree application \ +SUBDIRS = asset auth http \ + server session application \ storage user config router diff --git a/src/application/adapter/http/update.c b/src/application/adapter/http/update.c index d4829e3..d08de8c 100644 --- a/src/application/adapter/http/update.c +++ b/src/application/adapter/http/update.c @@ -26,9 +26,10 @@ #include #include "trbase.h" +#include "trdata.h" + #include "application/application.h" #include "application/adapter/http.h" -#include "hash.h" #include "http/worker.h" #include "http/header.h" #include "http/message.h" @@ -39,9 +40,9 @@ static inline char * -getSessionId(Hash cookies) +getSessionId(TR_Hash cookies) { - HashValue sidstr = hashGet(cookies, CSTRA("sid")); + TR_HashValue sidstr = TR_hashGet(cookies, CSTRA("sid")); if (NULL != sidstr) { return (char*)sidstr->value; @@ -73,7 +74,7 @@ applicationAdapterHttpUpdate(void * _this, void * subject) // send session cookie nbuf = sprintf(buf, "sid=%s;Path=/", session->id); - queuePut( + TR_queuePut( worker->additional_headers, TR_new(HttpHeader, CSTRA("Set-Cookie"), buf, nbuf)); diff --git a/src/application/application.c b/src/application/application.c index 98ebc34..7f203a0 100644 --- a/src/application/application.c +++ b/src/application/application.c @@ -24,8 +24,9 @@ #include -#include -#include +#include "trbase.h" +#include "trhash.h" +#include "trdata.h" #include "application/application.h" #include "storage/storage.h" @@ -56,9 +57,9 @@ applicationCtor(void * _this, va_list * params) this->auth = va_arg(*params, void *); - this->active_sessions = TR_calloc(SESSION_LIVETIME, sizeof(Hash)); + this->active_sessions = TR_calloc(SESSION_LIVETIME, sizeof(TR_Hash)); for (i=0; iactive_sessions[i] = TR_new(Hash); + this->active_sessions[i] = TR_new(TR_Hash); } this->version = VERSION; diff --git a/src/application/controller/_get_credential_from_args.c b/src/application/controller/_get_credential_from_args.c index 3add63e..345e458 100644 --- a/src/application/controller/_get_credential_from_args.c +++ b/src/application/controller/_get_credential_from_args.c @@ -23,18 +23,18 @@ #define _GNU_SOURCE #include "trbase.h" -#include "hash.h" +#include "trdata.h" #include "auth/credential.h" int _controllerValidatePasswordRepeat(char *, size_t, char *, size_t); Credential -_controllerGetCredentialFromArgs(Hash args) +_controllerGetCredentialFromArgs(TR_Hash args) { - HashValue email = hashGet(args, CSTRA("email")); - HashValue password = hashGet(args, CSTRA("password")); - HashValue pwrepeat = hashGet(args, CSTRA("pwrepeat")); + TR_HashValue email = TR_hashGet(args, CSTRA("email")); + TR_HashValue password = TR_hashGet(args, CSTRA("password")); + TR_HashValue pwrepeat = TR_hashGet(args, CSTRA("pwrepeat")); if ( NULL == email || diff --git a/src/application/controller/_get_user_from_args.c b/src/application/controller/_get_user_from_args.c index 0dcc168..91d7e7b 100644 --- a/src/application/controller/_get_user_from_args.c +++ b/src/application/controller/_get_user_from_args.c @@ -25,16 +25,16 @@ #include #include -#include "hash.h" +#include "trdata.h" #include "user.h" User -_controllerGetUserFromArgs(Hash args) +_controllerGetUserFromArgs(TR_Hash args) { - HashValue email = hashGet(args, CSTRA("email")); - HashValue firstname = hashGet(args, CSTRA("firstname")); - HashValue surname = hashGet(args, CSTRA("surname")); + TR_HashValue email = TR_hashGet(args, CSTRA("email")); + TR_HashValue firstname = TR_hashGet(args, CSTRA("firstname")); + TR_HashValue surname = TR_hashGet(args, CSTRA("surname")); if ( NULL == email || diff --git a/src/application/controller/_process_user_create_args.c b/src/application/controller/_process_user_create_args.c index c0fe839..6975deb 100644 --- a/src/application/controller/_process_user_create_args.c +++ b/src/application/controller/_process_user_create_args.c @@ -23,16 +23,16 @@ #define _GNU_SOURCE #include "trbase.h" -#include "hash.h" +#include "trdata.h" #include "user.h" #include "auth/credential.h" -User _controllerGetUserFromArgs(Hash args); -Credential _controllerGetCredentialFromArgs(Hash args); +User _controllerGetUserFromArgs(TR_Hash args); +Credential _controllerGetCredentialFromArgs(TR_Hash args); int -_controllerProcessUserCreateArgs(Hash args, User * user, Credential * cred) +_controllerProcessUserCreateArgs(TR_Hash args, User * user, Credential * cred) { *user = _controllerGetUserFromArgs(args); *cred = _controllerGetCredentialFromArgs(args); diff --git a/src/application/controller/_update_user_from_args.c b/src/application/controller/_update_user_from_args.c index 81adf2e..6a7b5a7 100644 --- a/src/application/controller/_update_user_from_args.c +++ b/src/application/controller/_update_user_from_args.c @@ -24,17 +24,17 @@ #include #include +#include -#include "hash.h" #include "user.h" int -_controllerUpdateUserFromArgs(Hash args, User * user) +_controllerUpdateUserFromArgs(TR_Hash args, User * user) { - HashValue email = hashGet(args, CSTRA("email")); - HashValue firstname = hashGet(args, CSTRA("firstname")); - HashValue surname = hashGet(args, CSTRA("surname")); + TR_HashValue email = TR_hashGet(args, CSTRA("email")); + TR_HashValue firstname = TR_hashGet(args, CSTRA("firstname")); + TR_HashValue surname = TR_hashGet(args, CSTRA("surname")); User new_user; if ( diff --git a/src/application/controller/_validate_password.c b/src/application/controller/_validate_password.c index e0d609a..9998641 100644 --- a/src/application/controller/_validate_password.c +++ b/src/application/controller/_validate_password.c @@ -21,7 +21,6 @@ */ #include "trbase.h" -#include "hash.h" #include "auth/credential.h" diff --git a/src/application/controller/_validate_password_repeat.c b/src/application/controller/_validate_password_repeat.c index dc70b6a..2dfca69 100644 --- a/src/application/controller/_validate_password_repeat.c +++ b/src/application/controller/_validate_password_repeat.c @@ -21,7 +21,6 @@ */ #include "trbase.h" -#include "hash.h" #include "auth/credential.h" int diff --git a/src/application/controller/authenticate/create.c b/src/application/controller/authenticate/create.c index 9f8d7a9..b788e6b 100644 --- a/src/application/controller/authenticate/create.c +++ b/src/application/controller/authenticate/create.c @@ -23,32 +23,33 @@ #define _GNU_SOURCE #include "trbase.h" +#include "trdata.h" + #include "application/application.h" #include "session.h" -#include "hash.h" #include "auth/credential.h" #include "user.h" -char * controllerCurrentuserRead(Application, Session, Hash); +char * controllerCurrentuserRead(Application, Session, TR_Hash); char * controllerAuthenticateCreate( Application application, Session session, - Hash args) + TR_Hash args) { - HashValue username; - HashValue password; - Credential credential; + TR_HashValue username; + TR_HashValue password; + Credential credential; - char * response_data; + char * response_data; - username = hashGet(args, CSTRA("username")); - password = hashGet(args, CSTRA("password")); + username = TR_hashGet(args, CSTRA("username")); + password = TR_hashGet(args, CSTRA("password")); if (NULL == username) { - username = hashGet(args, CSTRA("email")); + username = TR_hashGet(args, CSTRA("email")); } if (NULL == username || NULL == password) { diff --git a/src/application/controller/authenticate/delete.c b/src/application/controller/authenticate/delete.c index 3b14ff7..24f3ae3 100644 --- a/src/application/controller/authenticate/delete.c +++ b/src/application/controller/authenticate/delete.c @@ -22,18 +22,18 @@ #define _GNU_SOURCE +#include "trdata.h" + #include "application/application.h" #include "session.h" -#include "hash.h" - -char * controllerCurrentuserRead(Application, Session, Hash); +char * controllerCurrentuserRead(Application, Session, TR_Hash); char * controllerAuthenticateDelete( Application application, Session session, - Hash args) + TR_Hash args) { applicationLogout(application, session); return controllerCurrentuserRead(application, session, NULL); diff --git a/src/application/controller/currentuser/read.c b/src/application/controller/currentuser/read.c index d643e21..ef82269 100644 --- a/src/application/controller/currentuser/read.c +++ b/src/application/controller/currentuser/read.c @@ -26,16 +26,16 @@ #include #include "trbase.h" +#include "trdata.h" #include "application/application.h" #include "session.h" -#include "hash.h" #define USER_JSON \ "{\"username\":\"%s\",\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}" char * -controllerCurrentuserRead(Application app, Session sess, Hash args) +controllerCurrentuserRead(Application app, Session sess, TR_Hash args) { char * buffer; size_t nbuffer; diff --git a/src/application/controller/loc/read.c b/src/application/controller/loc/read.c index 06f4ebd..412ae3b 100644 --- a/src/application/controller/loc/read.c +++ b/src/application/controller/loc/read.c @@ -26,14 +26,15 @@ #include #include "trbase.h" +#include "trdata.h" + #include "application/application.h" -#include "hash.h" #include "session.h" #define LOC_JSON "{\"loc\":\"%s\"}" char * -controllerLocRead(Application app, Session sess, Hash args) +controllerLocRead(Application app, Session sess, TR_Hash args) { char * buffer; size_t nbuffer; diff --git a/src/application/controller/randval/read.c b/src/application/controller/randval/read.c index d04d495..c8663e8 100644 --- a/src/application/controller/randval/read.c +++ b/src/application/controller/randval/read.c @@ -26,15 +26,16 @@ #include #include "trbase.h" +#include "trdata.h" + #include "application/application.h" #include "session.h" -#include "hash.h" #define RANDVAL_JSON "{\"ctime\":%ld,\"vnext\":%ld,\"value\":\"%02d\"}" char * -controllerRandvalRead(Application app, Session sess, Hash args) +controllerRandvalRead(Application app, Session sess, TR_Hash args) { char * buffer; size_t nbuffer; diff --git a/src/application/controller/sessinfo/read.c b/src/application/controller/sessinfo/read.c index 13e3169..9e863d5 100644 --- a/src/application/controller/sessinfo/read.c +++ b/src/application/controller/sessinfo/read.c @@ -26,9 +26,10 @@ #include #include "trbase.h" +#include "trdata.h" + #include "application/application.h" #include "session.h" -#include "hash.h" #define SESSION_JSON "{\"id\":\"%s\",\"timeout\":%d,\"timeleft\":%ld}" @@ -37,7 +38,7 @@ char * controllerSessinfoRead( Application application, Session session, - Hash args) + TR_Hash args) { char * buffer; size_t nbuffer; diff --git a/src/application/controller/signup/create.c b/src/application/controller/signup/create.c index 7e574fc..9c100e4 100644 --- a/src/application/controller/signup/create.c +++ b/src/application/controller/signup/create.c @@ -24,23 +24,23 @@ #include #include +#include #include "application/application.h" #include "session.h" -#include "hash.h" #include "auth/credential.h" #include "user.h" -char * controllerCurrentuserRead(Application, Session, Hash); -int _controllerProcessUserCreateArgs(Hash, User *, Credential *); +char * controllerCurrentuserRead(Application, Session, TR_Hash); +int _controllerProcessUserCreateArgs(TR_Hash, User *, Credential *); char * controllerSignupCreate( Application application, Session session, - Hash args) + TR_Hash args) { Credential credential; User user; diff --git a/src/application/controller/user/create.c b/src/application/controller/user/create.c index ec98acd..a02222c 100644 --- a/src/application/controller/user/create.c +++ b/src/application/controller/user/create.c @@ -24,22 +24,22 @@ #include #include +#include #include "application/application.h" #include "session.h" -#include "hash.h" #include "auth/credential.h" #include "user.h" -char * controllerCurrentuserRead(Application, Session, Hash); -int _controllerProcessUserCreateArgs(Hash, User *, Credential *); +char * controllerCurrentuserRead(Application, Session, TR_Hash); +int _controllerProcessUserCreateArgs(TR_Hash, User *, Credential *); char * controllerUserCreate( Application application, Session session, - Hash args) + TR_Hash args) { Credential credential; User user; diff --git a/src/application/controller/user/read.c b/src/application/controller/user/read.c index 1baea02..98b3a3a 100644 --- a/src/application/controller/user/read.c +++ b/src/application/controller/user/read.c @@ -27,23 +27,23 @@ #include #include +#include #include "application/application.h" #include "session.h" -#include "hash.h" #define USER_JSON \ "{\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}" char * -controllerUserRead(Application app, Session sess, Hash args) +controllerUserRead(Application app, Session sess, TR_Hash args) { - char * buffer; - size_t nbuffer; - HashValue id = hashGet(args, CSTRA("id")); - TR_Uuid search = TR_uuidParse(id->value); - User user = applicationGetUser(app, search); + char * buffer; + size_t nbuffer; + TR_HashValue id = TR_hashGet(args, CSTRA("id")); + TR_Uuid search = TR_uuidParse(id->value); + User user = applicationGetUser(app, search); nbuffer = snprintf(NULL, 0, USER_JSON, user->email, diff --git a/src/application/controller/user/update.c b/src/application/controller/user/update.c index 35a5d3c..a0b8257 100644 --- a/src/application/controller/user/update.c +++ b/src/application/controller/user/update.c @@ -24,21 +24,21 @@ #include #include +#include #include "application/application.h" #include "session.h" -#include "hash.h" #include "user.h" -char * controllerCurrentuserRead(Application, Session, Hash); -int _controllerUpdateUserFromArgs(Hash, User *); +char * controllerCurrentuserRead(Application, Session, TR_Hash); +int _controllerUpdateUserFromArgs(TR_Hash, User *); char * controllerUserUpdate( Application application, Session session, - Hash args) + TR_Hash args) { TR_Uuid user_id; diff --git a/src/application/controller/version/read.c b/src/application/controller/version/read.c index a546238..3b4906d 100644 --- a/src/application/controller/version/read.c +++ b/src/application/controller/version/read.c @@ -26,14 +26,14 @@ #include #include "trbase.h" +#include "trdata.h" #include "application/application.h" -#include "hash.h" #include "session.h" #define VERSION_JSON "{\"version\":\"%s\"}" char * -controllerVersionRead(Application app, Session sess, Hash args) +controllerVersionRead(Application app, Session sess, TR_Hash args) { char * buffer; size_t nbuffer; diff --git a/src/application/session_cleanup.c b/src/application/session_cleanup.c index 4c408f4..205e6e6 100644 --- a/src/application/session_cleanup.c +++ b/src/application/session_cleanup.c @@ -25,9 +25,10 @@ #include #include +#include "trdata.h" + #include "trbase.h" #include "session.h" -#include "hash.h" #include "application/application.h" @@ -42,23 +43,23 @@ applicationSessionCleanup(Application this, time_t now) } if (0 < expired && SESSION_LIVETIME > expired) { - Hash * tmp_buf = TR_calloc(SESSION_LIVETIME, sizeof(Hash)); + TR_Hash * tmp_buf = TR_calloc(SESSION_LIVETIME, sizeof(TR_Hash)); memcpy( &(tmp_buf[expired]), this->active_sessions, - (SESSION_LIVETIME - expired) * sizeof(Hash)); + (SESSION_LIVETIME - expired) * sizeof(TR_Hash)); memcpy( tmp_buf, &(this->active_sessions[SESSION_LIVETIME - expired]), - expired * sizeof(Hash)); + expired * sizeof(TR_Hash)); TR_MEM_FREE(this->active_sessions); this->active_sessions = tmp_buf; } for (i=0; iactive_sessions[i]); + TR_hashCleanup(this->active_sessions[i]); } this->session_time_ofs = now; diff --git a/src/application/session_get.c b/src/application/session_get.c index eede20a..097198e 100644 --- a/src/application/session_get.c +++ b/src/application/session_get.c @@ -24,8 +24,9 @@ #include +#include "trdata.h" + #include "session.h" -#include "hash.h" #include "application/application.h" @@ -40,7 +41,7 @@ applicationSessionGet(Application this, const char * sid) * now get the session if not expired */ for (index=0; indexactive_sessions)[index], sid, 36); if (NULL != sess) { break; @@ -52,7 +53,7 @@ applicationSessionGet(Application this, const char * sid) */ if (NULL != sess) { sess->livetime = this->session_time_ofs + SESSION_LIVETIME; - hashAdd((this->active_sessions)[0], sess); + TR_hashAdd((this->active_sessions)[0], sess); } } diff --git a/src/application/session_start.c b/src/application/session_start.c index 2831bb8..aee94d6 100644 --- a/src/application/session_start.c +++ b/src/application/session_start.c @@ -26,8 +26,9 @@ #include #include "trbase.h" +#include "trdata.h" + #include "session.h" -#include "hash.h" #include "application/application.h" @@ -36,7 +37,7 @@ applicationSessionStart(Application this) { Session sess = TR_new(Session); - hashAdd((this->active_sessions)[0], sess); + TR_hashAdd((this->active_sessions)[0], sess); return sess; } diff --git a/src/application/session_stop.c b/src/application/session_stop.c index 8e10db8..3d91373 100644 --- a/src/application/session_stop.c +++ b/src/application/session_stop.c @@ -24,6 +24,8 @@ #include +#include "trdata.h" + #include "session.h" #include "application/application.h" @@ -35,7 +37,7 @@ applicationSessionStop(Application this, Session session) (session->livetime - this->session_time_ofs); if (SESSION_LIVETIME > index) { - hashDeleteByVal((this->active_sessions)[index], session->hash); + TR_hashDeleteByVal((this->active_sessions)[index], session->hash); } } diff --git a/src/asset/asset.c b/src/asset/asset.c index f6b7fa0..ebbd5ea 100644 --- a/src/asset/asset.c +++ b/src/asset/asset.c @@ -40,7 +40,6 @@ #include #include "asset.h" -#include "hash.h" #include "utils/mime_type.h" #include "utils/http.h" @@ -139,7 +138,7 @@ assetHandleDouble(void * _this, void * _doub) } 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)); +TR_INIT_IFACE(TR_Hashable, assetGetHash, assetHandleDouble); +TR_CREATE_CLASS(Asset, NULL, TR_IF(TR_Class), TR_IF(TR_Hashable)); // vim: set ts=4 sw=4: diff --git a/src/asset/pool.c b/src/asset/pool.c index 9e1adbe..e15b549 100644 --- a/src/asset/pool.c +++ b/src/asset/pool.c @@ -26,10 +26,10 @@ // for strlen #include "trbase.h" +#include "trdata.h" #include "asset.h" -#include "hash.h" -Hash asset_pool = NULL; +TR_Hash asset_pool = NULL; static inline @@ -45,15 +45,15 @@ assetPoolGet(const char * path, size_t npath) Asset asset = NULL; if (NULL == asset_pool) { - asset_pool = TR_new(Hash); + asset_pool = TR_new(TR_Hash); } else { - asset = hashGet(asset_pool, path, npath); + asset = TR_hashGet(asset_pool, path, npath); } if (NULL == asset) { asset = TR_new(Asset, path, npath); if (NULL != asset) { - hashAdd(asset_pool, asset); + TR_hashAdd(asset_pool, asset); } } else { asset->ref_count++; @@ -71,7 +71,7 @@ assetPoolRelease(Asset asset) } if (NULL != asset) { - Asset found = (Asset)hashDelete( + Asset found = (Asset)TR_hashDelete( asset_pool, asset->fname, asset->nfname); if (found == asset) { @@ -90,7 +90,7 @@ void assetPoolCleanup(void) { if (NULL != asset_pool) { - hashEach(asset_pool, freeAsset); + TR_hashEach(asset_pool, freeAsset); TR_delete(asset_pool); } } diff --git a/src/cbuf/Makefile.am b/src/cbuf/Makefile.am deleted file mode 100644 index c743a89..0000000 --- a/src/cbuf/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -CB = cbuf.c read.c \ - get_line.c set_data.c get_data.c \ - addr_index.c get_free.c get_read.c get_write.c \ - inc_read.c inc_write.c is_empty.c memchr.c \ - skip_non_alpha.c is_locked.c lock.c release.c \ - empty.c - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = libcbuf.la - -libcbuf_la_SOURCES = $(CB) -libcbuf_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/cbuf/addr_index.c b/src/cbuf/addr_index.c deleted file mode 100644 index 69eb5e6..0000000 --- a/src/cbuf/addr_index.c +++ /dev/null @@ -1,33 +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 "cbuf.h" - -size_t -cbufAddrIndex(Cbuf this, const void * c) -{ - return c - (const void *)cbufGetRead(this); -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/cbuf.c b/src/cbuf/cbuf.c deleted file mode 100644 index a313422..0000000 --- a/src/cbuf/cbuf.c +++ /dev/null @@ -1,123 +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 . - */ - -#define _POSIX_SOURCE -#define _POSIX_C_SOURCE 200112L -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "trbase.h" -#include "cbuf.h" - - -static void cbufDtor(void*); - -static -int -cbufCtor(void * _this, va_list * params) -{ - Cbuf this = _this; - char state = -1; - char * shm_name = va_arg(*params, char*); - long psize = sysconf(_SC_PAGESIZE); - size_t size; - int shm; - char * data; - - 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; - this->bsize = psize * size; - - while (-1 == state) { - shm = shm_open(this->shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRWXU); - if (-1 == shm) { - break; - } - - if (-1 == ftruncate(shm, this->bsize)) { - break; - } - - this->data = mmap (0, this->bsize << 1, - PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - if (this->data == MAP_FAILED) { - this->data = NULL; - break; - } - - data = mmap (this->data, this->bsize, - PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, shm, 0); - if (data != this->data) { - break; - } - - data = mmap (this->data + this->bsize, this->bsize, - PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, shm, 0); - if (data != this->data + this->bsize) { - break; - } - - state = 0; - } - - if (-1 != shm) { - shm_unlink(this->shm_name); - close(shm); - } - - return state; -} - -static -void -cbufDtor(void * _this) -{ - Cbuf this = _this; - - TR_MEM_FREE(this->shm_name); - - if (NULL != this->data && MAP_FAILED != this->data) { - munmap(this->data, this->bsize << 1); - } - - this->data = NULL; -} - -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/empty.c b/src/cbuf/empty.c deleted file mode 100644 index b41a6a3..0000000 --- a/src/cbuf/empty.c +++ /dev/null @@ -1,32 +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 "cbuf.h" - -void -cbufEmpty(Cbuf this) -{ - this->bused = 0; - this->read = this->write; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/get_data.c b/src/cbuf/get_data.c deleted file mode 100644 index b41f5b8..0000000 --- a/src/cbuf/get_data.c +++ /dev/null @@ -1,41 +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 "cbuf.h" - -char * -cbufGetData(Cbuf this, size_t n) -{ - char * ret = cbufGetRead(this); - - if (n > this->bused) { - return (char *)-1; - } - - cbufIncRead(this, n); - return ret; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/get_free.c b/src/cbuf/get_free.c deleted file mode 100644 index 1117081..0000000 --- a/src/cbuf/get_free.c +++ /dev/null @@ -1,33 +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 "cbuf.h" - -size_t -cbufGetFree(Cbuf this) -{ - return this->bsize - this->bused; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/get_line.c b/src/cbuf/get_line.c deleted file mode 100644 index 647722f..0000000 --- a/src/cbuf/get_line.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 - -#include - -#include "cbuf.h" - -char * -cbufGetLine(Cbuf this, char ** line_end) -{ - char * nl = cbufMemchr(this, '\n'); - char * ret = NULL; - - if (NULL != nl) { - size_t len = cbufAddrIndex(this, nl) + 1; - - *line_end = nl - 1; - *nl = 0; - *(nl-1) = ('\r' == *(nl-1))? 0 : *(nl-1); - - ret = cbufGetRead(this); - cbufIncRead(this, len); - } - - return ret; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/get_read.c b/src/cbuf/get_read.c deleted file mode 100644 index cbbbdc3..0000000 --- a/src/cbuf/get_read.c +++ /dev/null @@ -1,31 +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 "cbuf.h" - -char * -cbufGetRead(Cbuf this) -{ - return this->data + this->read; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/get_write.c b/src/cbuf/get_write.c deleted file mode 100644 index 02f1a55..0000000 --- a/src/cbuf/get_write.c +++ /dev/null @@ -1,31 +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 "cbuf.h" - -char * -cbufGetWrite(Cbuf this) -{ - return this->data + this->write; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/inc_read.c b/src/cbuf/inc_read.c deleted file mode 100644 index bfd6dab..0000000 --- a/src/cbuf/inc_read.c +++ /dev/null @@ -1,36 +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 "cbuf.h" - -void -cbufIncRead(Cbuf this, size_t n) -{ - this->read += n; - this->read = (this->read >= this->bsize)? - this->read - this->bsize : this->read; - this->bused -= n; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/inc_write.c b/src/cbuf/inc_write.c deleted file mode 100644 index f329813..0000000 --- a/src/cbuf/inc_write.c +++ /dev/null @@ -1,36 +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 "cbuf.h" - -void -cbufIncWrite(Cbuf this, size_t n) -{ - this->write += n; - this->write = (this->write >= this->bsize)? - this->write - this->bsize : this->write; - this->bused += n; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/is_empty.c b/src/cbuf/is_empty.c deleted file mode 100644 index 849c032..0000000 --- a/src/cbuf/is_empty.c +++ /dev/null @@ -1,31 +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 "cbuf.h" - -char -cbufIsEmpty(Cbuf this) -{ - return (0 == this->bused); -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/is_locked.c b/src/cbuf/is_locked.c deleted file mode 100644 index 449ceb6..0000000 --- a/src/cbuf/is_locked.c +++ /dev/null @@ -1,31 +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 "cbuf.h" - -Bool -cbufIsLocked(Cbuf this) -{ - return this->lock; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/lock.c b/src/cbuf/lock.c deleted file mode 100644 index df5256f..0000000 --- a/src/cbuf/lock.c +++ /dev/null @@ -1,31 +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 "cbuf.h" - -void -cbufLock(Cbuf this) -{ - this->lock = TRUE; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/memchr.c b/src/cbuf/memchr.c deleted file mode 100644 index 0183351..0000000 --- a/src/cbuf/memchr.c +++ /dev/null @@ -1,33 +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 "cbuf.h" - -char * -cbufMemchr(Cbuf this, int c) -{ - return memchr(cbufGetRead(this), c, this->bused); -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/read.c b/src/cbuf/read.c deleted file mode 100644 index acaeeac..0000000 --- a/src/cbuf/read.c +++ /dev/null @@ -1,51 +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 "trio.h" -#include "cbuf.h" - - -ssize_t -cbufRead(Cbuf this, TR_Stream st) -{ - size_t rsize = cbufGetFree(this); - ssize_t rrsize; - - if (0 == rsize) { - errno = ECBUFOVFL; - return -1; - } - - rrsize = TR_streamRead(st, cbufGetWrite(this), rsize); - - if (0 < rrsize) { - cbufIncWrite(this, rrsize); - } - - return rrsize; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/release.c b/src/cbuf/release.c deleted file mode 100644 index eb32a73..0000000 --- a/src/cbuf/release.c +++ /dev/null @@ -1,31 +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 "cbuf.h" - -void -cbufRelease(Cbuf this) -{ - this->lock = FALSE; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/set_data.c b/src/cbuf/set_data.c deleted file mode 100644 index 514d052..0000000 --- a/src/cbuf/set_data.c +++ /dev/null @@ -1,45 +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 "cbuf.h" - -char * -cbufSetData(Cbuf this, const void * src, size_t n) -{ - char * addr; - - if (n > cbufGetFree(this)) { - errno = ECBUFOVFL; - return (char *)-1; - } - - addr = memcpy(cbufGetWrite(this), src, n); - cbufIncWrite(this, n); - - return addr; -} - -// vim: set ts=4 sw=4: diff --git a/src/cbuf/skip_non_alpha.c b/src/cbuf/skip_non_alpha.c deleted file mode 100644 index 395c296..0000000 --- a/src/cbuf/skip_non_alpha.c +++ /dev/null @@ -1,34 +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 "cbuf.h" - -void -cbufSkipNonAlpha(Cbuf this) -{ - while(0 < this->bused && !isalpha(*cbufGetRead(this))) - cbufIncRead(this, 1); -} - -// vim: set ts=4 sw=4: diff --git a/src/config/config.c b/src/config/config.c index 45711a1..fb93ddb 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -27,6 +27,8 @@ #include #include "trbase.h" +#include "trdata.h" + #include "config/config.h" #include "config/value.h" @@ -51,7 +53,7 @@ configCtor(void * _this, va_list * params) return -1; } - this->config = TR_new(Hash); + this->config = TR_new(TR_Hash); line[MAX_CONFIG_LINE] = '\0'; @@ -96,7 +98,7 @@ configCtor(void * _this, va_list * params) value[nvalue] = '\0'; if (0 != nkey && 0 != nvalue) { - hashAdd( + TR_hashAdd( this->config, TR_new(ConfigValue, key, nkey, value, nvalue)); } diff --git a/src/config/get.c b/src/config/get.c index 5e3c320..7ce9a6d 100644 --- a/src/config/get.c +++ b/src/config/get.c @@ -22,7 +22,8 @@ #include -#include "hash/hash.h" +#include "trdata.h" + #include "config/config.h" #include "config/value.h" @@ -33,7 +34,7 @@ configGet(Config this, const char * key, size_t nkey) return NULL; } - return hashGet(this->config, key, nkey); + return TR_hashGet(this->config, key, nkey); } // vim: set ts=4 sw=4: diff --git a/src/config/value.c b/src/config/value.c index 2876b3a..327898f 100644 --- a/src/config/value.c +++ b/src/config/value.c @@ -27,6 +27,7 @@ #include #include +#include #include "config/value.h" @@ -94,7 +95,7 @@ configValueHandleDouble(void * _this, void * _double) } 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)); +TR_INIT_IFACE(TR_Hashable, configValueGetHash, configValueHandleDouble); +TR_CREATE_CLASS(ConfigValue, NULL, TR_IF(TR_Class), TR_IF(TR_Hashable)); // vim: set ts=4 sw=4: diff --git a/src/hash/Makefile.am b/src/hash/Makefile.am deleted file mode 100644 index 5eab16f..0000000 --- a/src/hash/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -HASH = hash.c add.c get.c get_first.c delete.c each.c value.c \ - cleanup.c interface/hashable.c - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = libhash.la - -libhash_la_SOURCES = $(HASH) -libhash_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/hash/add.c b/src/hash/add.c deleted file mode 100644 index abcd537..0000000 --- a/src/hash/add.c +++ /dev/null @@ -1,63 +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 "hash.h" - -static -inline -int -hashAddComp(const void * a, const void * b) -{ - unsigned long hash_a = hashableGetHash((void*)a); - unsigned long hash_b = hashableGetHash((void*)b); - - if (hash_a < hash_b) { - return -1; - } - - if (hash_a > hash_b) { - return 1; - } - - return 0; -} - -void * -hashAdd(Hash this, void * operand) -{ - void * found = treeInsert(&this->root, operand, hashAddComp); - - if (NULL == found) { - return NULL; - } - - if (operand != found) { - hashableHandleDouble(found, operand); - TR_delete(operand); - } - - return found; -} - -// vim: set ts=4 sw=4: diff --git a/src/hash/cleanup.c b/src/hash/cleanup.c deleted file mode 100644 index 539f4c4..0000000 --- a/src/hash/cleanup.c +++ /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 . - */ - -#include "hash/hash.h" -#include "trbase.h" - -static -inline -void -tDelete(const void * node, const int depth) -{ - TR_delete(node); -} - -void -hashCleanup(Hash this) -{ - treeDestroy(&(this->root), tDelete); -} - -// vim: set ts=4 sw=4: diff --git a/src/hash/delete.c b/src/hash/delete.c deleted file mode 100644 index e806f35..0000000 --- a/src/hash/delete.c +++ /dev/null @@ -1,67 +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 "asset.h" -#include "hash.h" - -static -inline -int -hashDeleteComp(const void * a, const void * b) -{ - unsigned long hash_a = hashableGetHash((void*)a); - - if (hash_a < *(const unsigned long*)b) { - return -1; - } - - if (hash_a > *(const unsigned long*)b) { - return 1; - } - - return 0; -} - -void * -hashDelete(Hash this, const char * search, size_t nsearch) -{ - unsigned long hash = TR_sdbm((const unsigned char *)search, nsearch); - void * found = NULL; - - found = treeDelete(&(this->root), &hash, hashDeleteComp); - - return found; -} - -void * -hashDeleteByVal(Hash this, unsigned long hash) -{ - void * found = treeDelete(&(this->root), &hash, hashDeleteComp); - - return found; -} - -// vim: set ts=4 sw=4: diff --git a/src/hash/each.c b/src/hash/each.c deleted file mode 100644 index be1c1bc..0000000 --- a/src/hash/each.c +++ /dev/null @@ -1,45 +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 "hash.h" - -static void (*cb)(const void*); - -static -inline -void -walk(const void * node, const int depth) -{ - cb(node); -} - -void -hashEach(Hash this, void (*callback)(const void*)) -{ - cb = callback; - - treeWalk(this->root, walk); -} - -// vim: set ts=4 sw=4: diff --git a/src/hash/get.c b/src/hash/get.c deleted file mode 100644 index a051a21..0000000 --- a/src/hash/get.c +++ /dev/null @@ -1,67 +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 - -#include "hash.h" -#include "tree.h" - -static -inline -int -hashGetComp(const void * a, const void * b) -{ - unsigned long hash_a = hashableGetHash((void*)a); - - if (hash_a < *(const unsigned long*)b) { - return -1; - } - - if (hash_a > *(const unsigned long*)b) { - return 1; - } - - return 0; -} - -void * -hashGet(Hash this, const char * search, size_t nsearch) -{ - unsigned long hash = TR_sdbm((const unsigned char *)search, nsearch); - void * found = treeFind(this->root, &hash, hashGetComp); - - return found; -} - -void * -hashGetByVal(Hash this, unsigned long hash) -{ - void * found = treeFind(this->root, &hash, hashGetComp); - - return found; -} -// vim: set ts=4 sw=4: diff --git a/src/hash/get_first.c b/src/hash/get_first.c deleted file mode 100644 index d181eaa..0000000 --- a/src/hash/get_first.c +++ /dev/null @@ -1,39 +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 - -#include "hash.h" -#include "tree.h" - -void * -hashGetFirst(Hash this) -{ - return this->root; -} - -// vim: set ts=4 sw=4: diff --git a/src/hash/hash.c b/src/hash/hash.c deleted file mode 100644 index 574c7d4..0000000 --- a/src/hash/hash.c +++ /dev/null @@ -1,58 +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 . - */ - -#define _GNU_SOURCE - -#include -#include - -#include "hash/hash.h" -#include "trbase.h" - -static -int -hashCtor(void * _this, va_list * params) -{ - return 0; -} - -static -inline -void -tDelete(const void * node, const int depth) -{ - TR_delete(node); -} - -static -void -hashDtor(void * _this) -{ - Hash this = _this; - - hashCleanup(this); -} - -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 deleted file mode 100644 index 5b7b2ad..0000000 --- a/src/hash/interface/hashable.c +++ /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 . - */ - -#include -#include -#include - -#include "trbase.h" -#include "hash/interface/hashable.h" - -TR_CREATE_INTERFACE(Hashable, 2); - -unsigned long -hashableGetHash(void * hashable) -{ - unsigned long ret; - - TR_RETCALL(hashable, Hashable, getHash, ret); - - return ret; -} - -void -hashableHandleDouble(void * hashable, void * 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 deleted file mode 100644 index dabbcec..0000000 --- a/src/hash/value.c +++ /dev/null @@ -1,108 +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 - -#include -#include - -#include "hash/value.h" -#include "hash/interface/hashable.h" - -static -int -hashValueCtor(void * _this, va_list * params) -{ - HashValue this = _this; - char * key = va_arg(* params, char*); - void * value; - - this->nkey = va_arg(* params, size_t); - value = va_arg(* params, void*); - this->nvalue = va_arg(* params, size_t); - - this->key = TR_malloc(this->nkey + 1); - this->key[this->nkey] = 0; - memcpy(this->key, key, this->nkey); - - this->hash = TR_sdbm((unsigned char *)this->key, this->nkey); - - if (NULL != value) { - this->value = TR_malloc(this->nvalue + 1); - ((char*)this->value)[this->nvalue] = 0; - memcpy(this->value, value, this->nvalue); - } - - return 0; -} - -static -void -hashValueDtor(void * _this) -{ - HashValue this = _this; - - TR_MEM_FREE(this->key); - TR_MEM_FREE(this->value); -} - -static -unsigned long -hashValueGetHash(void * _this) -{ - HashValue this = _this; - - return this->hash; -} - -static -void -hashValueHandleDouble(void * _this, void * _double) -{ - HashValue this = _this; - HashValue doub = _double; - void * tmp_value; - size_t tmp_nvalue; - - /** - * here we swap the internal data of both objects, - * effectively overwriting the old entry. We need not - * to free anything here as _double will be deleted - * afterwards anyway (\see hash/add.c). - */ - tmp_value = this->value; - this->value = doub->value; - doub->value = tmp_value; - - tmp_nvalue = this->nvalue; - this->nvalue = doub->nvalue; - doub->nvalue = tmp_nvalue; -} - -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/header.c b/src/http/header.c index 2b65219..982133e 100644 --- a/src/http/header.c +++ b/src/http/header.c @@ -24,10 +24,10 @@ #include #include -#include -#include +#include "trbase.h" +#include "trhash.h" +#include "trdata.h" -#include "hash.h" #include "http/header.h" static @@ -99,7 +99,7 @@ httpHeaderHandleDouble(void * _this, void * _double) } 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)); +TR_INIT_IFACE(TR_Hashable, httpHeaderGetHash, httpHeaderHandleDouble); +TR_CREATE_CLASS(HttpHeader, NULL, TR_IF(TR_Class), TR_IF(TR_Hashable)); // vim: set ts=4 sw=4: diff --git a/src/http/message.c b/src/http/message.c index aab5a3f..42893e9 100644 --- a/src/http/message.c +++ b/src/http/message.c @@ -31,7 +31,7 @@ #include #include "trbase.h" -#include "hash.h" +#include "trdata.h" #include "http/message.h" @@ -45,7 +45,7 @@ httpMessageCtor(void * _this, va_list * params) this->version = TR_calloc(1, strlen(version)+1); strcpy(this->version, version); - this->header = TR_new(Hash); + this->header = TR_new(TR_Hash); return 0; } diff --git a/src/http/message/has_keep_alive.c b/src/http/message/has_keep_alive.c index 52effe3..e3f61b6 100644 --- a/src/http/message/has_keep_alive.c +++ b/src/http/message/has_keep_alive.c @@ -29,7 +29,7 @@ #include "http/header.h" #include "trbase.h" -#include "hash.h" +#include "trdata.h" char httpMessageHasKeepAlive(HttpMessage message) @@ -38,7 +38,7 @@ httpMessageHasKeepAlive(HttpMessage message) size_t size; char * value; - header = hashGet(message->header, CSTRA("connection")); + header = TR_hashGet(message->header, CSTRA("connection")); if (NULL == header) { return 0; diff --git a/src/http/message/header_size_get.c b/src/http/message/header_size_get.c index 59b10b3..15cbedd 100644 --- a/src/http/message/header_size_get.c +++ b/src/http/message/header_size_get.c @@ -24,11 +24,11 @@ #include #include +#include "trdata.h" #include "http/message.h" #include "http/response.h" #include "http/header.h" #include "http/interface/http_intro.h" -#include "hash.h" static size_t size; @@ -45,7 +45,7 @@ httpMessageHeaderSizeGet(HttpMessage message) { size = httpIntroSizeGet(message); - hashEach(message->header, addHeaderSize); + TR_hashEach(message->header, addHeaderSize); size += 2; return size; diff --git a/src/http/message/header_to_string.c b/src/http/message/header_to_string.c index 37a2814..7a2a0ca 100644 --- a/src/http/message/header_to_string.c +++ b/src/http/message/header_to_string.c @@ -24,10 +24,10 @@ #include #include +#include "trdata.h" #include "http/response.h" #include "http/header.h" #include "http/interface/http_intro.h" -#include "hash.h" static char * string; @@ -46,7 +46,7 @@ httpMessageHeaderToString(HttpMessage response, char * _string) string = httpIntroToString(response, _string); - hashEach(message->header, addHeaderString); + TR_hashEach(message->header, addHeaderString); *string++ = '\r'; *string++ = '\n'; diff --git a/src/http/parser.c b/src/http/parser.c index 9519512..69d7232 100644 --- a/src/http/parser.c +++ b/src/http/parser.c @@ -26,11 +26,10 @@ #include "trbase.h" #include "trio.h" +#include "trdata.h" #include "http/parser.h" -#include "queue.h" #include "http/request.h" #include "http/response.h" -#include "cbuf.h" static @@ -39,13 +38,13 @@ httpParserCtor(void * _this, va_list * params) { HttpParser this = _this; - this->buffer = va_arg(* params, Cbuf); + this->buffer = va_arg(* params, TR_Cbuf); if (NULL == this->buffer) { return -1; } - this->queue = TR_new(Queue); + this->queue = TR_new(TR_Queue); return 0; } @@ -59,7 +58,7 @@ httpParserDtor(void * _this) TR_delete(this->queue); if (TRUE == this->ourLock) - cbufRelease(this->buffer); + TR_cbufRelease(this->buffer); TR_MEM_FREE(this->incomplete); TR_delete(this->current); diff --git a/src/http/parser/p_body.c b/src/http/parser/p_body.c index 12ac4c8..3bb41f8 100644 --- a/src/http/parser/p_body.c +++ b/src/http/parser/p_body.c @@ -23,12 +23,11 @@ #include #include +#include "trbase.h" + #include "http/header.h" #include "http/message.h" #include "http/parser.h" -#include "cbuf.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 d71d1ee..9361567 100644 --- a/src/http/parser/p_header.c +++ b/src/http/parser/p_header.c @@ -25,11 +25,11 @@ #include #include "trbase.h" +#include "trdata.h" #include "http/header.h" #include "http/parser.h" #include "http/message.h" #include "http/request.h" -#include "hash.h" void httpParserHeader( @@ -88,15 +88,15 @@ httpParserHeader( nval = pair-eqsign-1; val = (0 != nval)? eqsign+1 : NULL; - hashAdd(request->cookies, - TR_new(HashValue, key, eqsign-key, val, nval)); + TR_hashAdd(request->cookies, + TR_new(TR_HashValue, key, eqsign-key, val, nval)); pair++; togo -= (pair - eqsign); } } - hashAdd(current->header, + TR_hashAdd(current->header, TR_new(HttpHeader, name, nname, value, lend - value)); } diff --git a/src/http/parser/p_post_vars.c b/src/http/parser/p_post_vars.c index 758038d..c3beff4 100644 --- a/src/http/parser/p_post_vars.c +++ b/src/http/parser/p_post_vars.c @@ -23,10 +23,10 @@ #include #include +#include "trbase.h" +#include "trdata.h" #include "http/parser.h" #include "http/request.h" -#include "hash.h" -#include "trbase.h" #include "utils/http.h" @@ -63,8 +63,8 @@ httpParserPostVars(HttpParser this) value = (0 != nvalue)? eqsign+1 : NULL; nvalue = urldecode(value, nvalue); - hashAdd(request->post, - TR_new(HashValue, key, eqsign-key, value, nvalue)); + TR_hashAdd(request->post, + TR_new(TR_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 7003938..a87a4ba 100644 --- a/src/http/parser/p_request_vars.c +++ b/src/http/parser/p_request_vars.c @@ -25,9 +25,9 @@ #include #include "trbase.h" +#include "trdata.h" #include "http/parser.h" #include "http/request.h" -#include "hash.h" void httpParserRequestVars(HttpParser this) @@ -62,8 +62,8 @@ httpParserRequestVars(HttpParser this) nvalue = delim-eqsign-1; value = (0 != nvalue)? eqsign+1 : NULL; - hashAdd(request->get, - TR_new(HashValue, key, eqsign-key, value, nvalue)); + TR_hashAdd(request->get, + TR_new(TR_HashValue, key, eqsign-key, value, nvalue)); } } diff --git a/src/http/parser/parse.c b/src/http/parser/parse.c index 92fe153..5afd17e 100644 --- a/src/http/parser/parse.c +++ b/src/http/parser/parse.c @@ -24,8 +24,7 @@ #include "trbase.h" #include "trio.h" -#include "cbuf.h" -#include "queue.h" +#include "trdata.h" #include "http/parser.h" #include "http/header.h" @@ -41,22 +40,22 @@ httpParserParse(void * _this, TR_Stream st) char * line; char * line_end; - if (cbufIsLocked(this->buffer)) { + if (TR_cbufIsLocked(this->buffer)) { if (FALSE == this->ourLock) return 0; } else { - cbufLock(this->buffer); + TR_cbufLock(this->buffer); this->ourLock = TRUE; } if (NULL != this->incomplete) { - cbufSetData(this->buffer, this->incomplete, this->isize); + TR_cbufSetData(this->buffer, this->incomplete, this->isize); TR_MEM_FREE(this->incomplete); } - if (0 > (read = cbufRead(this->buffer, st))) { - cbufRelease(this->buffer); + if (0 > (read = TR_cbufRead(this->buffer, st))) { + TR_cbufRelease(this->buffer); this->ourLock = FALSE; return read; } @@ -64,27 +63,27 @@ httpParserParse(void * _this, TR_Stream st) while (cont) { switch(this->state) { case HTTP_MESSAGE_GARBAGE: - cbufSkipNonAlpha(this->buffer); - if (! cbufIsEmpty(this->buffer)) { + TR_cbufSkipNonAlpha(this->buffer); + if (! TR_cbufIsEmpty(this->buffer)) { this->state = HTTP_MESSAGE_START; } else { - cbufRelease(this->buffer); + TR_cbufRelease(this->buffer); this->ourLock = FALSE; cont = 0; break; } case HTTP_MESSAGE_START: - if (NULL == (line = cbufGetLine(this->buffer, &line_end))) { - if (! cbufIsEmpty(this->buffer)) { + if (NULL == (line = TR_cbufGetLine(this->buffer, &line_end))) { + if (! TR_cbufIsEmpty(this->buffer)) { this->isize = this->buffer->bused; this->incomplete = TR_malloc(this->isize); memcpy(this->incomplete, - cbufGetData(this->buffer, this->isize), + TR_cbufGetData(this->buffer, this->isize), this->isize); } - cbufRelease(this->buffer); + TR_cbufRelease(this->buffer); this->ourLock = FALSE; cont = 0; break; @@ -92,7 +91,7 @@ httpParserParse(void * _this, TR_Stream st) httpParserNewMessage(this, line, line_end); if (NULL == this->current) { - cbufRelease(this->buffer); + TR_cbufRelease(this->buffer); this->ourLock = FALSE; return -2; // a server error occured can't process... } @@ -101,15 +100,15 @@ httpParserParse(void * _this, TR_Stream st) this->state = HTTP_MESSAGE_INTRO_DONE; case HTTP_MESSAGE_INTRO_DONE: - if (NULL == (line = cbufGetLine(this->buffer, &line_end))) { - if (! cbufIsEmpty(this->buffer)) { + if (NULL == (line = TR_cbufGetLine(this->buffer, &line_end))) { + if (! TR_cbufIsEmpty(this->buffer)) { this->isize = this->buffer->bused; this->incomplete = TR_malloc(this->isize); memcpy(this->incomplete, - cbufGetData(this->buffer, this->isize), + TR_cbufGetData(this->buffer, this->isize), this->isize); } - cbufRelease(this->buffer); + TR_cbufRelease(this->buffer); this->ourLock = FALSE; cont = 0; break; @@ -126,18 +125,18 @@ httpParserParse(void * _this, TR_Stream st) if (this->current->dbody == this->current->nbody) { this->state = HTTP_MESSAGE_DONE; } else { - if (cbufIsEmpty(this->buffer)) { - cbufRelease(this->buffer); + if (TR_cbufIsEmpty(this->buffer)) { + TR_cbufRelease(this->buffer); this->ourLock = FALSE; cont = 0; break; } - cbufIncRead( + TR_cbufIncRead( this->buffer, httpParserBody( this, - cbufGetRead(this->buffer), + TR_cbufGetRead(this->buffer), this->buffer->bused)); break; @@ -145,7 +144,7 @@ httpParserParse(void * _this, TR_Stream st) case HTTP_MESSAGE_DONE: { - HttpHeader enc = hashGet( + HttpHeader enc = TR_hashGet( this->current->header, CSTRA("content-type")); @@ -164,7 +163,7 @@ httpParserParse(void * _this, TR_Stream st) /** * enqueue current request */ - queuePut(this->queue, this->current); + TR_queuePut(this->queue, this->current); this->current = NULL; /** diff --git a/src/http/request.c b/src/http/request.c index 7c1c389..186d424 100644 --- a/src/http/request.c +++ b/src/http/request.c @@ -26,7 +26,7 @@ #include #include "trbase.h" -#include "hash.h" +#include "trdata.h" #include "http/interface/http_intro.h" #include "http/request.h" @@ -66,9 +66,9 @@ httpRequestCtor(void * _this, va_list * params) return -1; } - this->get = TR_new(Hash); - this->post = TR_new(Hash); - this->cookies = TR_new(Hash); + this->get = TR_new(TR_Hash); + this->post = TR_new(TR_Hash); + this->cookies = TR_new(TR_Hash); return 0; } diff --git a/src/http/response/304.c b/src/http/response/304.c index 3e01e2b..b49cac1 100644 --- a/src/http/response/304.c +++ b/src/http/response/304.c @@ -23,10 +23,10 @@ #include #include "trbase.h" +#include "trdata.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" -#include "hash.h" HttpResponse httpResponse304( @@ -43,11 +43,11 @@ httpResponse304( message->nbody = 0; message->body = NULL; - hashAdd(message->header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("Content-Type"), mime, nmime)); - hashAdd(message->header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("ETag"), etag, netag)); - hashAdd(message->header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime)); return response; diff --git a/src/http/response/404.c b/src/http/response/404.c index 484dfd0..ff2744c 100644 --- a/src/http/response/404.c +++ b/src/http/response/404.c @@ -26,10 +26,10 @@ #include #include "trbase.h" +#include "trdata.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" -#include "hash.h" #define RESP_DATA "\n" \ "header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); message->nbody = sizeof(RESP_DATA) - 1; diff --git a/src/http/response/500.c b/src/http/response/500.c index 5261ece..85c22ff 100644 --- a/src/http/response/500.c +++ b/src/http/response/500.c @@ -26,10 +26,10 @@ #include #include "trbase.h" +#include "trdata.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" -#include "hash.h" #define RESP_DATA "\n" \ "header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); message->nbody = sizeof(RESP_DATA) - 1; diff --git a/src/http/response/asset.c b/src/http/response/asset.c index 0320ea0..9a516d2 100644 --- a/src/http/response/asset.c +++ b/src/http/response/asset.c @@ -43,11 +43,11 @@ #include "trbase.h" #include "trio.h" +#include "trdata.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" #include "utils/http.h" -#include "hash.h" #include "asset.h" @@ -74,14 +74,14 @@ httpResponseAsset(const char * fname, size_t nfname, time_t exptime) nexpires = rfc1123Gmt(expires, sizeof(expires), &exptime); - hashAdd(message->header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("Content-Type"), asset->mime_type, asset->nmime_type)); - hashAdd(message->header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("ETag"), asset->etag, asset->netag)); - hashAdd(message->header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("Expires"), expires, nexpires)); - hashAdd(message->header, + TR_hashAdd(message->header, TR_new(HttpHeader, CSTRA("Last-Modified"), asset->mtime, asset->nmtime)); diff --git a/src/http/response/json.c b/src/http/response/json.c index 19316d4..b976f76 100644 --- a/src/http/response/json.c +++ b/src/http/response/json.c @@ -27,11 +27,11 @@ #include #include "trbase.h" +#include "trdata.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" #include "session.h" -#include "hash.h" HttpResponse httpResponseJson(const char * body, size_t nbody) @@ -42,7 +42,7 @@ httpResponseJson(const char * body, size_t nbody) response = TR_new(HttpResponse, "HTTP/1.1", 200, "OK"); message = (HttpMessage)response; - hashAdd(message->header, + TR_hashAdd(message->header, TR_new( HttpHeader, CSTRA("Content-Type"), diff --git a/src/http/worker.c b/src/http/worker.c index bb0b21e..cafd80f 100644 --- a/src/http/worker.c +++ b/src/http/worker.c @@ -32,8 +32,6 @@ #include "trbase.h" #include "trio.h" -#include "hash.h" -#include "queue.h" #include "http/worker.h" #include "http/parser.h" #include "http/writer.h" @@ -49,12 +47,12 @@ httpWorkerCtor(void * _this, va_list * params) this->id = TR_malloc(strlen(id) + 1); strcpy(this->id, id); - this->asset_pool = TR_new(Hash); + this->asset_pool = TR_new(TR_Hash); sprintf(cbuf_id, "%s_%s", "parser", id); - this->pbuf = TR_new(Cbuf, cbuf_id, PARSER_MAX_BUF); + this->pbuf = TR_new(TR_Cbuf, cbuf_id, PARSER_MAX_BUF); - this->additional_headers = TR_new(Queue); + this->additional_headers = TR_new(TR_Queue); this->parser = TR_new(HttpParser, this->pbuf); this->writer = TR_new(HttpWriter); @@ -91,7 +89,7 @@ httpWorkerClone(void * _this, void * _base) this->asset_pool = base->asset_pool; this->application_adapter = base->application_adapter; - this->additional_headers = TR_new(Queue); + this->additional_headers = TR_new(TR_Queue); this->parser = TR_new(HttpParser, base->pbuf); /* diff --git a/src/http/worker/add_common_header.c b/src/http/worker/add_common_header.c index 749cf13..e10232a 100644 --- a/src/http/worker/add_common_header.c +++ b/src/http/worker/add_common_header.c @@ -23,10 +23,10 @@ #include #include "trbase.h" +#include "trdata.h" #include "http/message.h" #include "http/header.h" #include "http/worker.h" -#include "hash.h" #include "utils/http.h" #include "config.h" @@ -38,15 +38,15 @@ httpWorkerAddCommonHeader(HttpWorker this) size_t nbuf; if (httpMessageHasKeepAlive((HttpMessage)this->current_request)) { - hashAdd(this->current_response->header, + TR_hashAdd(this->current_response->header, TR_new(HttpHeader, CSTRA("Connection"), CSTRA("Keep-Alive"))); } else { - hashAdd(this->current_response->header, + TR_hashAdd(this->current_response->header, TR_new(HttpHeader, CSTRA("Connection"), CSTRA("Close"))); } - hashAdd(this->current_response->header, + TR_hashAdd(this->current_response->header, TR_new(HttpHeader, CSTRA("Server"), CSTRA(PACKAGE_STRING))); switch(((HttpResponse)this->current_response)->status) { @@ -55,12 +55,12 @@ httpWorkerAddCommonHeader(HttpWorker this) default: nbuf = sprintf(buffer, "%d", this->current_response->nbody); - hashAdd(this->current_response->header, + TR_hashAdd(this->current_response->header, TR_new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf)); } nbuf = rfc1123GmtNow(buffer, sizeof(buffer)); - hashAdd(this->current_response->header, + TR_hashAdd(this->current_response->header, TR_new(HttpHeader, CSTRA("Date"), buffer, nbuf)); } diff --git a/src/http/worker/add_computed_header.c b/src/http/worker/add_computed_header.c index cd2731f..1e1091e 100644 --- a/src/http/worker/add_computed_header.c +++ b/src/http/worker/add_computed_header.c @@ -22,20 +22,20 @@ #include +#include "trdata.h" #include "http/message.h" #include "http/header.h" #include "http/worker.h" -#include "queue.h" void httpWorkerAddComputedHeader(HttpWorker this) { - HttpHeader header = (HttpHeader)queueGet(this->additional_headers); + HttpHeader header = (HttpHeader)TR_queueGet(this->additional_headers); while(NULL != header) { - hashAdd(this->current_response->header, header); - header = (HttpHeader)queueGet(this->additional_headers); + TR_hashAdd(this->current_response->header, header); + header = (HttpHeader)TR_queueGet(this->additional_headers); } } diff --git a/src/http/worker/get_asset.c b/src/http/worker/get_asset.c index d140a6d..cbee9ec 100644 --- a/src/http/worker/get_asset.c +++ b/src/http/worker/get_asset.c @@ -24,12 +24,12 @@ #include #include "trbase.h" +#include "trdata.h" #include "http/header.h" #include "http/message.h" #include "http/request.h" #include "http/response.h" #include "http/worker.h" -#include "hash.h" HttpMessage httpWorkerGetAsset(HttpWorker this, const char * fname) @@ -41,7 +41,7 @@ httpWorkerGetAsset(HttpWorker this, const char * fname) size_t nfname = strlen(fname); - header = hashGet( + header = TR_hashGet( ((HttpMessage)this->current_request)->header, CSTRA("If-None-Match")); diff --git a/src/http/worker/process.c b/src/http/worker/process.c index 2abbbf7..f7c47f9 100644 --- a/src/http/worker/process.c +++ b/src/http/worker/process.c @@ -28,7 +28,7 @@ #include #include "trbase.h" -#include "queue.h" +#include "trdata.h" #include "http/worker.h" #include "http/header.h" @@ -57,8 +57,8 @@ httpWorkerProcess(HttpWorker this, TR_Stream st) } if (0 < requests) { - while (! queueEmpty(this->parser->queue)) { - this->current_request = queueGet(this->parser->queue); + while (! TR_queueEmpty(this->parser->queue)) { + this->current_request = TR_queueGet(this->parser->queue); this->current_response = NULL; /* @@ -124,7 +124,7 @@ httpWorkerProcess(HttpWorker this, TR_Stream st) httpWorkerAddCommonHeader(this); httpWorkerAddComputedHeader(this); TR_delete(this->current_request); - queuePut(this->writer->queue, this->current_response); + TR_queuePut(this->writer->queue, this->current_response); this->current_response = NULL; } } diff --git a/src/http/writer.c b/src/http/writer.c index c745de7..298eb4f 100644 --- a/src/http/writer.c +++ b/src/http/writer.c @@ -24,7 +24,7 @@ #include "trbase.h" #include "trio.h" -#include "queue.h" +#include "trdata.h" #include "http/writer.h" static @@ -33,7 +33,7 @@ httpWriterCtor(void * _this, va_list * params) { HttpWriter this = _this; - this->queue = TR_new(Queue); + this->queue = TR_new(TR_Queue); return 0; } diff --git a/src/http/writer/write.c b/src/http/writer/write.c index 4193a83..b2bbf87 100644 --- a/src/http/writer/write.c +++ b/src/http/writer/write.c @@ -27,7 +27,7 @@ #include "http/message.h" #include "trio.h" -#include "queue.h" +#include "trdata.h" #include "http/writer.h" @@ -43,8 +43,8 @@ httpWriterWrite(void * _this, TR_Stream st) case HTTP_WRITER_GET: - if (! queueEmpty(this->queue)) { - this->current = queueGet(this->queue); + if (! TR_queueEmpty(this->queue)) { + this->current = TR_queueGet(this->queue); this->written = 0; this->nheader = httpMessageHeaderSizeGet(this->current); diff --git a/src/queue/Makefile.am b/src/queue/Makefile.am deleted file mode 100644 index 838dd53..0000000 --- a/src/queue/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = libqueue.la - -libqueue_la_SOURCES = queue.c get.c put.c -libqueue_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/queue/get.c b/src/queue/get.c deleted file mode 100644 index a667f80..0000000 --- a/src/queue/get.c +++ /dev/null @@ -1,51 +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 "trbase.h" -#include "queue.h" - -void * -queueGet(Queue this) -{ - Queue first; - void * msg; - - if (NULL == this->first) { - return NULL; - } - - msg = this->first->msg; - first = this->first->next; - - if (this->first == this->last) { - this->last = NULL; - } - TR_delete(this->first); - - this->next = first; - this->first = first; - this->nmsg--; - - return msg; -} - -// vim: set ts=4 sw=4: diff --git a/src/queue/put.c b/src/queue/put.c deleted file mode 100644 index f8993f0..0000000 --- a/src/queue/put.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 "trbase.h" -#include "queue.h" - -void -queuePut(Queue this, void * msg) -{ - Queue node = (this->last)? this->last : this; - - node->next = TR_new(Queue); - this->last = node->next; - - if (node == this) { - this->first = node->next; - } - - node->next->msg = msg; - this->nmsg++; -} - -// vim: set ts=4 sw=4: diff --git a/src/queue/queue.c b/src/queue/queue.c deleted file mode 100644 index 2cb6ea9..0000000 --- a/src/queue/queue.c +++ /dev/null @@ -1,53 +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 "trbase.h" -#include "queue.h" - -static -int -queueCtor(void * _this, va_list * params) -{ - return 0; -} - -static -void -queueDtor(void * _this) -{ - Queue this = _this; - Queue node = this->first; - - while (NULL != node) { - Queue next = node->next; - TR_delete(node->msg); - TR_delete(node); - node = next; - } -} - -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 7883bc0..0ba08d0 100644 --- a/src/router/route.c +++ b/src/router/route.c @@ -36,8 +36,9 @@ #include #include "trbase.h" +#include "trdata.h" + #include "router.h" -#include "hash.h" #include "session.h" #include "http/request.h" #include "http/response.h" @@ -54,7 +55,7 @@ routerRoute( Session sess) { char functionName[COMMAND_LEN + this->nprefix * 10]; - Hash args = NULL; + TR_Hash args = NULL; fptr_routable function; char * tmp; diff --git a/src/router/router.c b/src/router/router.c index eaa75a8..6118098 100644 --- a/src/router/router.c +++ b/src/router/router.c @@ -26,8 +26,9 @@ #include #include "trbase.h" +#include "trdata.h" + #include "router.h" -#include "hash.h" #include "application/application.h" #define PREFIX "controller" @@ -39,7 +40,7 @@ routerCtor(void * _this, va_list * params) Router this = _this; this->application = va_arg(*params, Application); - this->functions = TR_new(Hash); + this->functions = TR_new(TR_Hash); this->handle = dlopen(NULL, RTLD_LAZY); this->prefix = PREFIX; this->nprefix = sizeof(PREFIX) - 1; diff --git a/src/session/session.c b/src/session/session.c index 2322499..83a2ebf 100644 --- a/src/session/session.c +++ b/src/session/session.c @@ -30,9 +30,9 @@ #include #include +#include #include "session.h" -#include "hash.h" static @@ -76,7 +76,7 @@ sessionHandleDouble(void * _this, void * _doub) } 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)); +TR_INIT_IFACE(TR_Hashable, sessionGetHash, sessionHandleDouble); +TR_CREATE_CLASS(Session, NULL, TR_IF(TR_Class), TR_IF(TR_Hashable)); // vim: set ts=4 sw=4: diff --git a/src/taskrambler.c b/src/taskrambler.c index 09ad37e..185701d 100644 --- a/src/taskrambler.c +++ b/src/taskrambler.c @@ -99,7 +99,7 @@ main() setrlimit(RLIMIT_NOFILE, &limit); init_signals(); - daemonize(); + //daemonize(); shm = shm_open("/fooshm", O_RDWR|O_CREAT, S_IRWXU); if (-1 == ftruncate(shm, psize)) { diff --git a/src/tree/Makefile.am b/src/tree/Makefile.am deleted file mode 100644 index 49c09b7..0000000 --- a/src/tree/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -TREE = tree.c find.c insert.c inOrderSuccessor.c delete.c walk.c \ - rotateLeft.c rotateRight.c destroy.c - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = libtree.la - -libtree_la_SOURCES = $(TREE) -libtree_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/tree/delete.c b/src/tree/delete.c deleted file mode 100644 index 8499119..0000000 --- a/src/tree/delete.c +++ /dev/null @@ -1,250 +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 "trbase.h" -#include "tree.h" - -Tree inOrderSuccessor(Tree); -void treeRotateLeft(Tree *, Tree); -void treeRotateRight(Tree *, Tree); - - -void * -treeDelete(Tree * this, const void * search, TreeComp comp) -{ - Tree node = *this; - Tree del_node; - - void * data; - - /* - * first search for it and if its found return the data - * and we are done... - */ - while (NULL != node) { - int comparison = comp(node->data, search); - - if (0 < comparison) { - node = TREE_LEFT(node); - continue; - } - - if (0 > comparison) { - node = TREE_RIGHT(node); - continue; - } - - if (0 == comparison) { - break; - } - } - - /* - * nothing was found...return NULL to indicate this. - */ - if (NULL == node) { - return NULL; - } - - /* - * we found an element, store its data pointer as we are - * up to delete it. - */ - data = node->data; - - /* - * now remove the element. - */ - - /* - * if we have two children replace data with the one from - * out inOrderSuccessor and remove the inOrderSuccessor. - */ - if (NULL != TREE_LEFT(node) && NULL != TREE_RIGHT(node)) { - Tree successor = inOrderSuccessor(node); - - node->data = successor->data; - node = successor; - } - - { - Tree child = TREE_CHILD(node); - - /* - * if we still have one child replace ourself with it. - */ - TREE_REPLACE_NODE(this, node, child); - - /* - * and finally delete the node...and prepare ourselfs - * for rebalancing. - */ - if (rbBlack == node->color) { - if (NULL != child && rbRed == child->color) { - child->color = rbBlack; - TR_delete(node); - return data; - } else { - del_node = node; - if (NULL != child) { - node = child; - } else { - node->color = rbBlack; - node->left = NULL; - node->right = NULL; - } - } - } else { - TR_delete(node); - return data; - } - } - - /* - * now comes rebalancing...note that if we came to this point - * the node is still not deleted. - * This is because I am not sure if it is needed during the - * rebalancing process...(this does not make much sense, but - * to be honest I don't know now.) - */ - while(1) { - // case 1 - if (NULL == TREE_PARENT(node)) { - break; - } - - // case 2 - if (NULL != TREE_SIBLING(node) - && rbRed == TREE_SIBLING(node)->color) { - - TREE_PARENT(node)->color = rbRed; - TREE_SIBLING(node)->color = rbBlack; - - if (NULL != TREE_PARENT(node)->right && - node != TREE_PARENT(node)->right) { - - //TREE_ROTATE_LEFT(this, TREE_PARENT(node)); - treeRotateLeft(this, TREE_PARENT(node)); - - } else { - - //TREE_ROTATE_RIGHT(this, TREE_PARENT(node)); - treeRotateRight(this, TREE_PARENT(node)); - - } - } - - // case 3 / 4 - if (NULL == TREE_SIBLING(node) - || (rbBlack == TREE_SIBLING(node)->color - && (NULL == TREE_SIBLING(node)->left - || rbBlack == TREE_SIBLING(node)->left->color) - && (NULL == TREE_SIBLING(node)->right - || rbBlack == TREE_SIBLING(node)->right->color))) { - - if (NULL != TREE_SIBLING(node)) { - TREE_SIBLING(node)->color = rbRed; - } - - - /* - * this is the point where during the balancing our tree - * node can be finally deleted. - */ - if (rbBlack == TREE_PARENT(node)->color) { - // case 3 - Tree parent = node->parent; - node = parent; - continue; - } else { - // case 4 - TREE_PARENT(node)->color = rbBlack; - break; - } - } - - // case 5 - if (NULL != TREE_SIBLING(node) - && rbBlack == TREE_SIBLING(node)->color) { - - if (node == TREE_PARENT(node)->left - && (NULL == TREE_SIBLING(node)->right - || rbBlack == TREE_SIBLING(node)->right->color) - && (NULL != TREE_SIBLING(node)->left - && rbRed == TREE_SIBLING(node)->left->color)) { - - TREE_SIBLING(node)->color = rbRed; - TREE_SIBLING(node)->left->color = rbBlack; - - //TREE_ROTATE_RIGHT(this, TREE_SIBLING(node)); - treeRotateRight(this, TREE_SIBLING(node)); - - } else if (node == TREE_PARENT(node)->right - && (NULL == TREE_SIBLING(node)->left - || rbBlack == TREE_SIBLING(node)->left->color) - && (NULL != TREE_SIBLING(node)->right - && rbRed == TREE_SIBLING(node)->right->color)) { - - TREE_SIBLING(node)->color = rbRed; - TREE_SIBLING(node)->right->color = rbBlack; - - //TREE_ROTATE_LEFT(this, TREE_SIBLING(node)); - treeRotateLeft(this, TREE_SIBLING(node)); - } - } - - // case 6 - if (NULL != TREE_SIBLING(node)) { - TREE_SIBLING(node)->color = TREE_PARENT(node)->color; - } - - if (NULL != node && NULL != TREE_PARENT(node)) { - TREE_PARENT(node)->color = rbBlack; - - if (NULL != TREE_PARENT(node)->right - && node != TREE_PARENT(node)->right) { - - if (NULL != TREE_SIBLING(node)->right) { - TREE_SIBLING(node)->right->color = rbBlack; - } - //TREE_ROTATE_LEFT(this, TREE_PARENT(node)); - treeRotateLeft(this, TREE_PARENT(node)); - } else { - if (NULL != TREE_SIBLING(node)->left) { - TREE_SIBLING(node)->left->color = rbBlack; - } - //TREE_ROTATE_RIGHT(this, TREE_PARENT(node)); - treeRotateRight(this, TREE_PARENT(node)); - } - } - - break; - } - - TR_delete(del_node); - /* - * not sure if deleting here is correct. - */ - return data; -} - -// vim: set ts=4 sw=4: diff --git a/src/tree/destroy.c b/src/tree/destroy.c deleted file mode 100644 index c776b50..0000000 --- a/src/tree/destroy.c +++ /dev/null @@ -1,86 +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 "trbase.h" -#include "tree.h" - -void -treeDestroy(Tree * this, TreeAction action) -{ - Tree previous = * this; - Tree node = * this; - 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 (NULL != node) { - /* - * If we come from the right so nothing and go to our - * next parent. - */ - if (((NULL == TREE_LEFT(node) - || previous == TREE_LEFT(node)) && NULL == TREE_RIGHT(node)) - || previous == TREE_RIGHT(node)) { - - Tree parent = TREE_PARENT(node); - - action(node->data, depth); - - previous = node; - TR_delete(node); - node = parent; - depth--; - - continue; - } - - if ((NULL == TREE_LEFT(node) || previous == TREE_LEFT(node))) { - /* - * If there are no more elements to the left or we - * came from the left, process data. - */ - previous = node; - - if (NULL != TREE_RIGHT(node)) { - node = TREE_RIGHT(node); - depth++; - } else { - node = TREE_PARENT(node); - depth--; - } - } else { - /* - * if there are more elements to the left go there. - */ - previous = node; - node = TREE_LEFT(node); - depth++; - } - } - - *this = NULL; -} - -// vim: set ts=4 sw=4: diff --git a/src/tree/find.c b/src/tree/find.c deleted file mode 100644 index 535a70a..0000000 --- a/src/tree/find.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 "tree.h" - -void * -treeFind(Tree this, const void * search, TreeComp comp) -{ - while (NULL != this) { - int comparison = comp(this->data, search); - - if (0 < comparison) { - this = TREE_LEFT(this); - continue; - } - - if (0 > comparison) { - this = TREE_RIGHT(this); - continue; - } - - if (0 == comparison) { - break; - } - } - - return NULL != this ? this->data : NULL; -} - -// vim: set ts=4 sw=4: diff --git a/src/tree/inOrderSuccessor.c b/src/tree/inOrderSuccessor.c deleted file mode 100644 index 52c36f2..0000000 --- a/src/tree/inOrderSuccessor.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 "tree.h" - -Tree -inOrderSuccessor(Tree this) -{ - this = TREE_RIGHT(this); - - while (NULL != TREE_LEFT(this)) { - this = TREE_LEFT(this); - } - - return this; -} - -// vim: set ts=4 sw=4: diff --git a/src/tree/insert.c b/src/tree/insert.c deleted file mode 100644 index 5bb34cf..0000000 --- a/src/tree/insert.c +++ /dev/null @@ -1,153 +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 "trbase.h" -#include "tree.h" - -void treeRotateLeft(Tree *, Tree); -void treeRotateRight(Tree *, Tree); - -void * -treeInsert(Tree * this, const void * search, TreeComp comp) -{ - Tree node = *this; - Tree new_node = NULL; - - /* - * insert the node or return the one in tree if comparison - * succeeds. - */ - if (NULL == node) { - /* - * if the root is NULL we simple add the element and set - * node to it. - */ - *this = node = new_node = TR_new(Tree, search); - } else { - /* - * first search for it and if its found return the data - * and we are done... - */ - int comparison; - - while (NULL != node) { - comparison = comp(node->data, search); - - if (0 < comparison) { - if (NULL != TREE_LEFT(node)) { - node = TREE_LEFT(node); - continue; - } else { - break; - } - } - - if (0 > comparison) { - if (NULL != TREE_RIGHT(node)) { - node = TREE_RIGHT(node); - continue; - } else { - break; - } - } - - if (0 == comparison) { - return node->data; - } - } - - /* - * as we have not found it now add a new element. - */ - if (0 < comparison) { - node->left = TR_new(Tree, search); - TREE_LEFT(node)->parent = node; - node = new_node = TREE_LEFT(node); - } else { - node->right = TR_new(Tree, search); - TREE_RIGHT(node)->parent = node; - node = new_node = TREE_RIGHT(node); - } - } - - /* - * we expect node not to be NULL and pointing to our - * new node at this point...now rabalance the tree - */ - while (1) { - // case 1 - if (NULL == TREE_PARENT(node)) { - node->color = rbBlack; - break; - } - - // case 2 - if (rbBlack == TREE_PARENT(node)->color) { - break; - } - - // case 3 - if (NULL != TREE_UNCLE(node) && rbRed == TREE_UNCLE(node)->color) { - TREE_PARENT(node)->color = rbBlack; - TREE_UNCLE(node)->color = rbBlack; - TREE_GRANDPARENT(node)->color = rbRed; - - node = TREE_GRANDPARENT(node); - continue; - } - - // case 4 - if (node == TREE_PARENT(node)->right - && TREE_PARENT(node) == TREE_GRANDPARENT(node)->left) { - - //TREE_ROTATE_LEFT(this, TREE_PARENT(node)); - treeRotateLeft(this, TREE_PARENT(node)); - node = TREE_LEFT(node); - - } else if (node == TREE_PARENT(node)->left - && TREE_PARENT(node) == TREE_GRANDPARENT(node)->right) { - - //TREE_ROTATE_RIGHT(this, TREE_PARENT(node)); - treeRotateRight(this, TREE_PARENT(node)); - node = TREE_RIGHT(node); - - } - - // case 5 - TREE_PARENT(node)->color = rbBlack; - TREE_GRANDPARENT(node)->color = rbRed; - - if (node == TREE_PARENT(node)->left) { - //TREE_ROTATE_RIGHT(this, TREE_GRANDPARENT(node)); - treeRotateRight(this, TREE_GRANDPARENT(node)); - } else { - //TREE_ROTATE_LEFT(this, TREE_GRANDPARENT(node)); - treeRotateLeft(this, TREE_GRANDPARENT(node)); - } - - break; - } - - return new_node->data; -} - -// vim: set ts=4 sw=4: diff --git a/src/tree/rotateLeft.c b/src/tree/rotateLeft.c deleted file mode 100644 index d14508d..0000000 --- a/src/tree/rotateLeft.c +++ /dev/null @@ -1,51 +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 "tree.h" - -void -treeRotateLeft(Tree * this, Tree node) -{ - Tree rightChild = TREE_RIGHT(node); - Tree rcLeftSub = TREE_RIGHT_LEFT(node); - - rightChild->left = node; - rightChild->parent = TREE_PARENT(node); - node->right = rcLeftSub; - if (NULL != rcLeftSub) { - rcLeftSub->parent = node; - } - - if (NULL != TREE_PARENT(node)) { - if (TREE_PARENT(node)->left == node) { - TREE_PARENT(node)->left = rightChild; - } else { - TREE_PARENT(node)->right = rightChild; - } - } else { - *this = rightChild; - } - - node->parent = rightChild; -} - -// vim: set ts=4 sw=4: diff --git a/src/tree/rotateRight.c b/src/tree/rotateRight.c deleted file mode 100644 index 75c29a9..0000000 --- a/src/tree/rotateRight.c +++ /dev/null @@ -1,51 +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 "tree.h" - -void -treeRotateRight(Tree * this, Tree node) -{ - Tree leftChild = TREE_LEFT(node); - Tree lcRightSub = TREE_LEFT_RIGHT(node); - - leftChild->right = node; - leftChild->parent = TREE_PARENT(node); - node->left = lcRightSub; - if (NULL != lcRightSub) { - lcRightSub->parent = node; - } - - if (NULL != TREE_PARENT(node)) { - if (TREE_PARENT(node)->left == node) { - TREE_PARENT(node)->left = leftChild; - } else { - TREE_PARENT(node)->right = leftChild; - } - } else { - *this = leftChild; - } - - node->parent = leftChild; -} - -// vim: set ts=4 sw=4: diff --git a/src/tree/tree.c b/src/tree/tree.c deleted file mode 100644 index 06272ae..0000000 --- a/src/tree/tree.c +++ /dev/null @@ -1,54 +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 . - */ - -#define _GNU_SOURCE - -#include - -#include "trbase.h" -#include "tree.h" - -static -int -treeCtor(void * _this, va_list * params) -{ - Tree this = _this; - - this->data = va_arg(*params, void *); - this->color = rbRed; - this->parent = NULL; - this->left = NULL; - this->right = NULL; - - return 0; -} - -static -void -treeDtor(void * _this) -{ -} - -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/tree/walk.c b/src/tree/walk.c deleted file mode 100644 index 992e742..0000000 --- a/src/tree/walk.c +++ /dev/null @@ -1,59 +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 "tree.h" - -void -treeWalk(Tree this, TreeAction action) -{ - Tree previous = this; - Tree node = this; - int depth = 1; - - while (NULL != node) { - if (previous == TREE_RIGHT(node)) { - previous = node; - node = node->parent; - depth--; - continue; - } - - if (NULL == TREE_LEFT(node) || previous == TREE_LEFT(node)) { - action(node->data, depth); - previous = node; - - if (NULL != TREE_RIGHT(node)) { - node = TREE_RIGHT(node); - depth++; - } else { - node = TREE_PARENT(node); - depth--; - } - } else { - previous = node; - node = TREE_LEFT(node); - depth++; - } - } -} - -// vim: set ts=4 sw=4: diff --git a/src/utils/mime_type.c b/src/utils/mime_type.c index f328693..6504965 100644 --- a/src/utils/mime_type.c +++ b/src/utils/mime_type.c @@ -27,10 +27,11 @@ // for fopen #include -#include "hash.h" + #include "trbase.h" +#include "trdata.h" -Hash mime_types = NULL; +TR_Hash mime_types = NULL; void readMimeTypes(void) @@ -42,7 +43,7 @@ readMimeTypes(void) char buffer[512]; buffer[511] = '\0'; - mime_types = TR_new(Hash); + mime_types = TR_new(TR_Hash); while (NULL != fgets(buffer, 511, handle)) { char * tmp; @@ -68,8 +69,8 @@ readMimeTypes(void) value[nvalue] = '\0'; } - hashAdd(mime_types, - TR_new(HashValue, key, nkey, value, nvalue)); + TR_hashAdd(mime_types, + TR_new(TR_HashValue, key, nkey, value, nvalue)); } fclose(handle); @@ -80,7 +81,7 @@ readMimeTypes(void) char * getMimeType(const char * ext, size_t len) { - HashValue type; + TR_HashValue type; if (NULL == mime_types) { readMimeTypes(); @@ -90,7 +91,7 @@ getMimeType(const char * ext, size_t len) } } - type = hashGet(mime_types, ext, len); + type = TR_hashGet(mime_types, ext, len); if (NULL == type) { return NULL;