Commit 7f688412eac190e43f86501a6b95fd22a88a858d
1 parent
8298740d
some code cleanups...no changes in the logic
Showing
31 changed files
with
107 additions
and
108 deletions
1 | +2012-02-20 21:36:55 +0100 Georg Hopp | |
2 | + | |
3 | + * some code cleanups...no changes in the logic (HEAD, master) | |
4 | + | |
1 | 5 | 2012-02-20 18:08:23 +0100 Georg Hopp |
2 | 6 | |
3 | - * move sdbm implementation in one file. (HEAD, master) | |
7 | + * move sdbm implementation in one file. | |
4 | 8 | |
5 | 9 | 2012-02-20 17:16:44 +0100 Georg Hopp |
6 | 10 | ... | ... |
include/hash.h
deleted
100644 → 0
1 | 1 | /** |
2 | 2 | * \file |
3 | + * Functions to handle varios signals send to the application. | |
3 | 4 | * |
4 | 5 | * \author Georg Hopp |
5 | 6 | * |
... | ... | @@ -20,33 +21,11 @@ |
20 | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 22 | */ |
22 | 23 | |
23 | -#ifndef __HTTP_MESSAGE_HELPER_C__ | |
24 | -#define __HTTP_MESSAGE_HELPER_C__ | |
24 | +#ifndef __UTILS_HASH_H__ | |
25 | +#define __UTILS_HASH_H__ | |
25 | 26 | |
26 | -#include <stdlib.h> | |
27 | +unsigned long sdbm(const unsigned char *); | |
27 | 28 | |
28 | -#include "class.h" | |
29 | -#include "interface/class.h" | |
30 | - | |
31 | - | |
32 | -static | |
33 | -inline | |
34 | -void | |
35 | -_free(void ** data) | |
36 | -{ | |
37 | - if (NULL != *data) { | |
38 | - free(*data); | |
39 | - } | |
40 | -} | |
41 | - | |
42 | -static | |
43 | -inline | |
44 | -void | |
45 | -tDelete(void * node) | |
46 | -{ | |
47 | - delete(&node); | |
48 | -} | |
49 | - | |
50 | -#endif // __HTTP_MESSAGE_HELPER_C__ | |
29 | +#endif // __UTILS_HASH_H__ | |
51 | 30 | |
52 | 31 | // vim: set ts=4 sw=4: | ... | ... |
include/utils/memory.h
0 → 100644
1 | +/** | |
2 | + * \file | |
3 | + * | |
4 | + * \author Georg Hopp | |
5 | + * | |
6 | + * \copyright | |
7 | + * Copyright (C) 2012 Georg Hopp | |
8 | + * | |
9 | + * This program is free software: you can redistribute it and/or modify | |
10 | + * it under the terms of the GNU General Public License as published by | |
11 | + * the Free Software Foundation, either version 3 of the License, or | |
12 | + * (at your option) any later version. | |
13 | + * | |
14 | + * This program is distributed in the hope that it will be useful, | |
15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | + * GNU General Public License for more details. | |
18 | + * | |
19 | + * You should have received a copy of the GNU General Public License | |
20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | + */ | |
22 | + | |
23 | +#ifndef __UTILS_MEMORY_H__ | |
24 | +#define __UTILS_MEMORY_H__ | |
25 | + | |
26 | +void ffree(void **); | |
27 | + | |
28 | +#endif // __UTILS_MEMORY_H__ | ... | ... |
... | ... | @@ -21,13 +21,13 @@ |
21 | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | 22 | */ |
23 | 23 | |
24 | -#ifndef __SIGNAL_HANDLING_H__ | |
25 | -#define __SIGNAL_HANDLING_H__ | |
24 | +#ifndef __UTILS_SIGNAL_HANDLING_H__ | |
25 | +#define __UTILS_SIGNAL_HANDLING_H__ | |
26 | 26 | |
27 | 27 | extern volatile int doShutdown; |
28 | 28 | |
29 | 29 | void terminate(int signum); |
30 | 30 | void init_signals(void); |
31 | 31 | |
32 | -#endif // __SIGNAL_HANDLING_H__ | |
32 | +#endif // __UTILS_SIGNAL_HANDLING_H__ | |
33 | 33 | ... | ... |
... | ... | @@ -7,7 +7,8 @@ IFACE = interface/class.c interface/stream_reader.c interface/logger.c \ |
7 | 7 | CLASS = class.c interface.c |
8 | 8 | RB = ringbuffer.c ringbuffer/rb_read.c |
9 | 9 | SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c |
10 | -SERVER = server.c server/run.c server/close_conn.c | |
10 | +SERVER = server.c server/run.c server/close_conn.c server/poll.c \ | |
11 | + server/handle_accept.c server/read.c | |
11 | 12 | LOGGER = logger.c logger/stderr.c logger/syslog.c |
12 | 13 | CB = cbuf.c cbuf/read.c cbuf/write.c \ |
13 | 14 | cbuf/get_line.c cbuf/set_data.c cbuf/get_data.c \ |
... | ... | @@ -31,6 +32,7 @@ HEADER = http/header.c http/header/get.c http/header/add.c \ |
31 | 32 | PARSER = http/request/parser.c http/request/parser/get_header.c \ |
32 | 33 | http/request/parser/parse.c http/request/parser/get_request_line.c \ |
33 | 34 | http/request/parser/get_body.c |
35 | +UTILS = utils/hash.c utils/memory.c utils/daemonize.c utils/signalHandling.c | |
34 | 36 | |
35 | 37 | |
36 | 38 | AM_CFLAGS = -Wall -I ../include/ |
... | ... | @@ -40,6 +42,6 @@ bin_PROGRAMS = testserver |
40 | 42 | testserver_SOURCES = testserver.c \ |
41 | 43 | $(IFACE) $(CLASS) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \ |
42 | 44 | $(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \ |
43 | - signalHandling.c daemonize.c hash.c | |
45 | + $(UTILS) | |
44 | 46 | testserver_CFLAGS = -Wall -I ../include/ |
45 | 47 | testserver_LDFLAGS = -lrt | ... | ... |
... | ... | @@ -24,12 +24,12 @@ |
24 | 24 | #include <stdlib.h> |
25 | 25 | #include <string.h> |
26 | 26 | |
27 | -#include "hash.h" | |
28 | 27 | #include "class.h" |
29 | 28 | #include "interface/class.h" |
30 | - | |
31 | 29 | #include "http/header.h" |
32 | 30 | |
31 | +#include "utils/hash.h" | |
32 | + | |
33 | 33 | static |
34 | 34 | void |
35 | 35 | ctor(void * _this, va_list * params) { | ... | ... |
... | ... | @@ -21,13 +21,12 @@ |
21 | 21 | */ |
22 | 22 | |
23 | 23 | #include <search.h> |
24 | -#include <stdlib.h> | |
25 | 24 | #include <stdio.h> |
26 | 25 | |
27 | -#include "hash.h" | |
28 | 26 | #include "class.h" |
29 | 27 | #include "interface/class.h" |
30 | 28 | #include "http/header.h" |
29 | +#include "utils/hash.h" | |
31 | 30 | |
32 | 31 | static |
33 | 32 | inline | ... | ... |
... | ... | @@ -34,10 +34,18 @@ |
34 | 34 | #include "interface/class.h" |
35 | 35 | |
36 | 36 | #include "http/message.h" |
37 | -#include "message/helper.c" | |
37 | +#include "utils/memory.h" | |
38 | 38 | |
39 | 39 | |
40 | 40 | static |
41 | +inline | |
42 | +void | |
43 | +tDelete(void * node) | |
44 | +{ | |
45 | + delete(&node); | |
46 | +} | |
47 | + | |
48 | +static | |
41 | 49 | void |
42 | 50 | ctor(void * _this, va_list * params) |
43 | 51 | { |
... | ... | @@ -54,7 +62,7 @@ dtor(void * _this) |
54 | 62 | { |
55 | 63 | HttpMessage this = _this; |
56 | 64 | |
57 | - _free((void **)&(this->version)); | |
65 | + ffree((void **)&(this->version)); | |
58 | 66 | |
59 | 67 | /** |
60 | 68 | * this is a GNU extension...anyway on most non |
... | ... | @@ -65,7 +73,7 @@ dtor(void * _this) |
65 | 73 | |
66 | 74 | switch (this->type) { |
67 | 75 | case HTTP_MESSAGE_BUFFERED: |
68 | - _free((void **)&(this->body)); | |
76 | + ffree((void **)&(this->body)); | |
69 | 77 | break; |
70 | 78 | |
71 | 79 | case HTTP_MESSAGE_PIPED: | ... | ... |
... | ... | @@ -30,7 +30,7 @@ |
30 | 30 | #include "interface/http_intro.h" |
31 | 31 | |
32 | 32 | #include "http/request.h" |
33 | -#include "message/helper.c" | |
33 | +#include "utils/memory.h" | |
34 | 34 | |
35 | 35 | |
36 | 36 | static |
... | ... | @@ -43,8 +43,8 @@ dtor(void * _this) |
43 | 43 | { |
44 | 44 | HttpRequest this = _this; |
45 | 45 | |
46 | - _free((void **)&(this->uri)); | |
47 | - _free((void **)&(this->method)); | |
46 | + ffree((void **)&(this->uri)); | |
47 | + ffree((void **)&(this->method)); | |
48 | 48 | |
49 | 49 | PARENTCALL(_this, Class, dtor); |
50 | 50 | } | ... | ... |
... | ... | @@ -20,10 +20,9 @@ |
20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 21 | */ |
22 | 22 | |
23 | -#include <unistd.h> | |
24 | -#include <stdio.h> | |
25 | 23 | #include <stdlib.h> |
26 | 24 | #include <sys/types.h> |
25 | +#include <stdarg.h> | |
27 | 26 | |
28 | 27 | #include "class.h" |
29 | 28 | #include "interface/class.h" | ... | ... |
... | ... | @@ -20,9 +20,7 @@ |
20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 21 | */ |
22 | 22 | |
23 | -#include <search.h> | |
24 | -#include <ctype.h> | |
25 | -#include <stdio.h> | |
23 | +#include <string.h> | |
26 | 24 | |
27 | 25 | #include "class.h" |
28 | 26 | #include "interface/class.h" |
... | ... | @@ -31,8 +29,8 @@ |
31 | 29 | #include "http/request/parser.h" |
32 | 30 | #include "ringbuffer.h" |
33 | 31 | |
34 | -ssize_t | |
35 | -httpRequestParserGetHeader(HttpRequestParser this, char * cr) | |
32 | +void | |
33 | +httpRequestParserGetHeader(HttpMessage message, char * line) | |
36 | 34 | { |
37 | 35 | HttpMessage message = (HttpMessage)this->cur_request; |
38 | 36 | char * value; |
... | ... | @@ -53,7 +51,7 @@ httpRequestParserGetHeader(HttpRequestParser this, char * cr) |
53 | 51 | |
54 | 52 | httpHeaderAdd(&(message->header), new(HttpHeader, name, value)); |
55 | 53 | |
56 | - return 1; //* @TODO: return something useful here | |
54 | + httpHeaderAdd(&(message->header), new(HttpHeader, name, value)); | |
57 | 55 | } |
58 | 56 | |
59 | 57 | // vim: set ts=4 sw=4: | ... | ... |
... | ... | @@ -31,7 +31,7 @@ |
31 | 31 | #include "interface/http_intro.h" |
32 | 32 | |
33 | 33 | #include "http/response.h" |
34 | -#include "message/helper.c" | |
34 | +#include "utils/memory.h" | |
35 | 35 | |
36 | 36 | |
37 | 37 | static |
... | ... | @@ -56,7 +56,7 @@ dtor(void * _this) |
56 | 56 | { |
57 | 57 | HttpResponse this = _this; |
58 | 58 | |
59 | - _free((void **)&(this->reason)); | |
59 | + ffree((void **)&(this->reason)); | |
60 | 60 | |
61 | 61 | PARENTCALL(_this, Class, dtor); |
62 | 62 | } | ... | ... |
... | ... | @@ -20,13 +20,8 @@ |
20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 21 | */ |
22 | 22 | |
23 | -#include <stdio.h> | |
24 | 23 | #include <unistd.h> |
25 | -#include <stdlib.h> | |
26 | -#include <string.h> | |
27 | -#include <sys/types.h> | |
28 | 24 | #include <sys/stat.h> |
29 | -#include <fcntl.h> | |
30 | 25 | |
31 | 26 | #include "class.h" |
32 | 27 | #include "interface/class.h" | ... | ... |
... | ... | @@ -20,10 +20,6 @@ |
20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 21 | */ |
22 | 22 | |
23 | -#include <poll.h> /* for select system call and related */ | |
24 | -#include <string.h> /* for memset and stuff */ | |
25 | -#include <stdlib.h> /* for getopt */ | |
26 | -#include <unistd.h> | |
27 | 23 | #include <fcntl.h> |
28 | 24 | |
29 | 25 | #include "class.h" | ... | ... |
... | ... | @@ -25,11 +25,10 @@ |
25 | 25 | #include <stdlib.h> |
26 | 26 | |
27 | 27 | #include "http/worker.h" |
28 | +#include "server.h" | |
29 | +#include "interface/class.h" | |
30 | +#include "interface/logger.h" | |
28 | 31 | |
29 | - | |
30 | -#include "http/worker.h" | |
31 | - | |
32 | -static | |
33 | 32 | int |
34 | 33 | serverHandleAccept(Server this) |
35 | 34 | { |
... | ... | @@ -45,15 +44,6 @@ serverHandleAccept(Server this) |
45 | 44 | // clone worker |
46 | 45 | (this->conns)[acc->handle].worker = clone(this->worker); |
47 | 46 | |
48 | - /** | |
49 | - * \todo | |
50 | - * set worker id---this would better be accomplished | |
51 | - * as a worker method. | |
52 | - * The same is true for server information stuff only | |
53 | - * that this should become an interface. | |
54 | - * At a second thought both has to be an interface. | |
55 | - */ | |
56 | - | |
57 | 47 | (this->fds)[this->nfds].fd = acc->handle; |
58 | 48 | (this->fds)[this->nfds].events = POLLIN; |
59 | 49 | this->nfds++; | ... | ... |
... | ... | @@ -23,10 +23,14 @@ |
23 | 23 | #include <poll.h> |
24 | 24 | #include <errno.h> |
25 | 25 | |
26 | +#include "server.h" | |
27 | +#include "interface/logger.h" | |
28 | + | |
29 | +#include "utils/signalHandling.h" | |
30 | + | |
26 | 31 | #define POLLFD(ptr) ((struct pollfd *)(ptr)) |
27 | 32 | #define SWAP(a, b) ((a)^=(b),(b)^=(a),(a)^=(b)) |
28 | 33 | |
29 | -static | |
30 | 34 | int |
31 | 35 | serverPoll(Server this) { |
32 | 36 | int events; | ... | ... |
... | ... | @@ -20,7 +20,10 @@ |
20 | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | 21 | */ |
22 | 22 | |
23 | -static | |
23 | +#include "server.h" | |
24 | +#include "interface/logger.h" | |
25 | +#include "interface/stream_reader.h" | |
26 | + | |
24 | 27 | ssize_t |
25 | 28 | serverRead(Server this, unsigned int i) |
26 | 29 | { | ... | ... |
... | ... | @@ -21,20 +21,18 @@ |
21 | 21 | */ |
22 | 22 | |
23 | 23 | #include "server.h" |
24 | -#include "socket.h" | |
25 | -#include "logger.h" | |
26 | -#include "signalHandling.h" | |
27 | -#include "interface/class.h" | |
28 | -#include "interface/stream_reader.h" | |
29 | 24 | #include "interface/stream_writer.h" |
30 | 25 | #include "interface/logger.h" |
31 | 26 | |
27 | +#include "utils/signalHandling.h" | |
28 | + | |
32 | 29 | #undef MAX |
33 | 30 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) |
34 | 31 | |
35 | -#include "poll.c" | |
36 | -#include "handle_accept.c" | |
37 | -#include "read.c" | |
32 | +int serverPoll(Server); | |
33 | +int serverHandleAccept(Server); | |
34 | +void serverCloseConn(Server, unsigned int); | |
35 | +ssize_t serverRead(Server, unsigned int); | |
38 | 36 | |
39 | 37 | void |
40 | 38 | serverRun(Server this) | ... | ... |
src/utils/memory.c
0 → 100644
Please
register
or
login
to post a comment