119 changed files with 277 additions and 2956 deletions
-
4configure.ac
-
12include/application/application.h
-
1include/asset.h
-
79include/cbuf.h
-
4include/config/config.h
-
1include/config/value.h
-
10include/hash.h
-
48include/hash/hash.h
-
43include/hash/interface/hashable.h
-
42include/hash/value.h
-
5include/http/message.h
-
7include/http/parser.h
-
8include/http/request.h
-
10include/http/worker.h
-
4include/http/writer.h
-
58include/queue.h
-
8include/router.h
-
138include/tree.h
-
17src/Makefile.am
-
9src/application/adapter/http/update.c
-
9src/application/application.c
-
10src/application/controller/_get_credential_from_args.c
-
10src/application/controller/_get_user_from_args.c
-
8src/application/controller/_process_user_create_args.c
-
10src/application/controller/_update_user_from_args.c
-
1src/application/controller/_validate_password.c
-
1src/application/controller/_validate_password_repeat.c
-
17src/application/controller/authenticate/create.c
-
8src/application/controller/authenticate/delete.c
-
4src/application/controller/currentuser/read.c
-
5src/application/controller/loc/read.c
-
5src/application/controller/randval/read.c
-
5src/application/controller/sessinfo/read.c
-
8src/application/controller/signup/create.c
-
8src/application/controller/user/create.c
-
6src/application/controller/user/read.c
-
8src/application/controller/user/update.c
-
4src/application/controller/version/read.c
-
11src/application/session_cleanup.c
-
7src/application/session_get.c
-
5src/application/session_start.c
-
4src/application/session_stop.c
-
5src/asset/asset.c
-
14src/asset/pool.c
-
16src/cbuf/Makefile.am
-
33src/cbuf/addr_index.c
-
123src/cbuf/cbuf.c
-
32src/cbuf/empty.c
-
41src/cbuf/get_data.c
-
33src/cbuf/get_free.c
-
49src/cbuf/get_line.c
-
31src/cbuf/get_read.c
-
31src/cbuf/get_write.c
-
36src/cbuf/inc_read.c
-
36src/cbuf/inc_write.c
-
31src/cbuf/is_empty.c
-
31src/cbuf/is_locked.c
-
31src/cbuf/lock.c
-
33src/cbuf/memchr.c
-
51src/cbuf/read.c
-
31src/cbuf/release.c
-
45src/cbuf/set_data.c
-
34src/cbuf/skip_non_alpha.c
-
6src/config/config.c
-
5src/config/get.c
-
5src/config/value.c
-
12src/hash/Makefile.am
-
63src/hash/add.c
-
40src/hash/cleanup.c
-
67src/hash/delete.c
-
45src/hash/each.c
-
67src/hash/get.c
-
39src/hash/get_first.c
-
58src/hash/hash.c
-
48src/hash/interface/hashable.c
-
108src/hash/value.c
-
10src/http/header.c
-
4src/http/message.c
-
4src/http/message/has_keep_alive.c
-
4src/http/message/header_size_get.c
-
4src/http/message/header_to_string.c
-
9src/http/parser.c
-
5src/http/parser/p_body.c
-
8src/http/parser/p_header.c
-
8src/http/parser/p_post_vars.c
-
6src/http/parser/p_request_vars.c
-
49src/http/parser/parse.c
-
8src/http/request.c
-
8src/http/response/304.c
-
4src/http/response/404.c
-
4src/http/response/500.c
-
10src/http/response/asset.c
-
4src/http/response/json.c
-
10src/http/worker.c
-
12src/http/worker/add_common_header.c
-
8src/http/worker/add_computed_header.c
-
4src/http/worker/get_asset.c
-
8src/http/worker/process.c
-
4src/http/writer.c
-
6src/http/writer/write.c
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __CBUF_H__ |
|||
#define __CBUF_H__ |
|||
|
|||
#include <ctype.h> |
|||
#include <string.h> |
|||
#include <sys/types.h> |
|||
|
|||
#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: |
|||
@ -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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __HASH_HASH_H__ |
|||
#define __HASH_HASH_H__ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __HASH_VALUE_H__ |
|||
#define __HASH_VALUE_H__ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __QUEUE_H__ |
|||
#define __QUEUE_H__ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#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: |
|||
@ -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) |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
size_t |
|||
cbufAddrIndex(Cbuf this, const void * c) |
|||
{ |
|||
return c - (const void *)cbufGetRead(this); |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#define _POSIX_SOURCE |
|||
#define _POSIX_C_SOURCE 200112L |
|||
#define _GNU_SOURCE |
|||
|
|||
#include <sys/types.h> |
|||
#include <sys/stat.h> |
|||
#include <sys/mman.h> |
|||
#include <stdarg.h> |
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <unistd.h> |
|||
#include <fcntl.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
void |
|||
cbufEmpty(Cbuf this) |
|||
{ |
|||
this->bused = 0; |
|||
this->read = this->write; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
#include <string.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
size_t |
|||
cbufGetFree(Cbuf this) |
|||
{ |
|||
return this->bsize - this->bused; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#include <string.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
char * |
|||
cbufGetRead(Cbuf this) |
|||
{ |
|||
return this->data + this->read; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
char * |
|||
cbufGetWrite(Cbuf this) |
|||
{ |
|||
return this->data + this->write; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
char |
|||
cbufIsEmpty(Cbuf this) |
|||
{ |
|||
return (0 == this->bused); |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
Bool |
|||
cbufIsLocked(Cbuf this) |
|||
{ |
|||
return this->lock; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
void |
|||
cbufLock(Cbuf this) |
|||
{ |
|||
this->lock = TRUE; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <string.h> |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
char * |
|||
cbufMemchr(Cbuf this, int c) |
|||
{ |
|||
return memchr(cbufGetRead(this), c, this->bused); |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
#include <unistd.h> |
|||
#include <errno.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
void |
|||
cbufRelease(Cbuf this) |
|||
{ |
|||
this->lock = FALSE; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
#include <string.h> |
|||
#include <errno.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <ctype.h> |
|||
|
|||
#include "cbuf.h" |
|||
|
|||
void |
|||
cbufSkipNonAlpha(Cbuf this) |
|||
{ |
|||
while(0 < this->bused && !isalpha(*cbufGetRead(this))) |
|||
cbufIncRead(this, 1); |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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) |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <search.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#include <trhash.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <search.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <stdio.h> |
|||
|
|||
#include <search.h> |
|||
#include <sys/types.h> |
|||
|
|||
#include <trhash.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <stdio.h> |
|||
|
|||
#include <search.h> |
|||
#include <sys/types.h> |
|||
|
|||
#include <trhash.h> |
|||
|
|||
#include "hash.h" |
|||
#include "tree.h" |
|||
|
|||
void * |
|||
hashGetFirst(Hash this) |
|||
{ |
|||
return this->root; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#define _GNU_SOURCE |
|||
|
|||
#include <search.h> |
|||
#include <stdarg.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <stdarg.h> |
|||
|
|||
#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: |
|||
@ -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 <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <stdarg.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
#include <sys/types.h> |
|||
|
|||
#include <trbase.h> |
|||
#include <trhash.h> |
|||
|
|||
#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: |
|||
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue