Showing
10 changed files
with
43 additions
and
76 deletions
@@ -4,7 +4,8 @@ ACLOCAL_AMFLAGS = -I m4 | @@ -4,7 +4,8 @@ ACLOCAL_AMFLAGS = -I m4 | ||
4 | #create_token_SOURCES = base64.c createToken.c | 4 | #create_token_SOURCES = base64.c createToken.c |
5 | #create_token_LDADD = src/libtoken.la $(LIBOBJS) | 5 | #create_token_LDADD = src/libtoken.la $(LIBOBJS) |
6 | #create_token_CFLAGS = -Wall -I include | 6 | #create_token_CFLAGS = -Wall -I include |
7 | -# | ||
8 | -#EXTRA_DIST = base64.h | 7 | + |
8 | + | ||
9 | +EXTRA_DIST = include | ||
9 | 10 | ||
10 | SUBDIRS = src tests | 11 | SUBDIRS = src tests |
1 | /* | 1 | /* |
2 | + * Klassen sind eine Vereinigung von Daten und der Art wie diese auf | ||
3 | + * messages reagieren. Oft reagieren Sie auf eine message identisch, aber | ||
4 | + * die Details koennen variieren. Ein beispiel dafuer waere die message | ||
5 | + * "fahre an einen bestimmten Ort". Die meisten Objekte die auf diese | ||
6 | + * message reagieren koennen brauchen dafuer ein Rad...ein Luftschiff | ||
7 | + * allerdings faehrt auch (sprachliche definition) benoetigt dafuer aber | ||
8 | + * kein Rad. Das Ergebnis der message ist allerdings das gleiche wenn | ||
9 | + * alles korrekt functioniert. Das Objekt erreicht das definierte Ziel. | ||
10 | + * | ||
2 | * Was wir unter C tun müssen ist separate definition von Interface und | 11 | * Was wir unter C tun müssen ist separate definition von Interface und |
3 | * und Daten sowie Methoden....das Interface ist dabei immer verantwortlich | 12 | * und Daten sowie Methoden....das Interface ist dabei immer verantwortlich |
4 | * dafür die zur Klasse gehörende Implementation einer Methode aufzurufen. | 13 | * dafür die zur Klasse gehörende Implementation einer Methode aufzurufen. |
@@ -67,7 +76,7 @@ void * draw(const __SHAPE_PTR shape) | @@ -67,7 +76,7 @@ void * draw(const __SHAPE_PTR shape) | ||
67 | } | 76 | } |
68 | } | 77 | } |
69 | 78 | ||
70 | -// === KLASSEN IMPLEMENTATION ======== | 79 | +// === KLASSEN INITIALIZATION ======== |
71 | 80 | ||
72 | static void draw(CIRCLE * this); | 81 | static void draw(CIRCLE * this); |
73 | 82 |
@@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
21 | MOVE_SIZE(sizeof(((server)->conns)[0]),(idx))) | 21 | MOVE_SIZE(sizeof(((server)->conns)[0]),(idx))) |
22 | 22 | ||
23 | 23 | ||
24 | -typedef void (*server_read_hook)(const char *); | 24 | +typedef void (*server_read_hook)(const char *, size_t); |
25 | 25 | ||
26 | CLASS(SERVER) { | 26 | CLASS(SERVER) { |
27 | LOGGER logger; | 27 | LOGGER logger; |
@@ -3,8 +3,9 @@ ACLOCAL_AMFLAGS = -I m4 | @@ -3,8 +3,9 @@ ACLOCAL_AMFLAGS = -I m4 | ||
3 | CCLASS = cclass.c | 3 | CCLASS = cclass.c |
4 | SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c | 4 | SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c |
5 | SERVER = server.c server/run.c server/close_conn.c | 5 | SERVER = server.c server/run.c server/close_conn.c |
6 | +LOGGER = logger.c logger/add.c logger/log.c logger/syslog.c | ||
6 | 7 | ||
7 | bin_PROGRAMS = testserver | 8 | bin_PROGRAMS = testserver |
8 | 9 | ||
9 | -testserver_SOURCES = testserver.c $(CCLASS) $(SOCKET) $(SERVER) signalHandling.c logger.c | 10 | +testserver_SOURCES = testserver.c $(CCLASS) $(SOCKET) $(SERVER) $(LOGGER) signalHandling.c |
10 | testserver_CFLAGS = -Wall -I ../include | 11 | testserver_CFLAGS = -Wall -I ../include |
@@ -34,7 +34,7 @@ void * | @@ -34,7 +34,7 @@ void * | ||
34 | _new(const CCLASS _class, ...) | 34 | _new(const CCLASS _class, ...) |
35 | { | 35 | { |
36 | const CCLASS class = _class; | 36 | const CCLASS class = _class; |
37 | - void * object = calloc(1, class->size + sizeof(CCLASS)); | 37 | + void * object = calloc(1, class->size + sizeof(void *)); |
38 | 38 | ||
39 | * (const struct _CCLASS **)object = class; | 39 | * (const struct _CCLASS **)object = class; |
40 | object += sizeof(CCLASS); | 40 | object += sizeof(CCLASS); |
@@ -86,16 +86,16 @@ clear(void * _object) | @@ -86,16 +86,16 @@ clear(void * _object) | ||
86 | } | 86 | } |
87 | 87 | ||
88 | void | 88 | void |
89 | -delete(void * _object) | 89 | +delete(void ** _object) |
90 | { | 90 | { |
91 | - const CCLASS * class = (*(void**)_object) - sizeof(CCLASS); | 91 | + const CCLASS * class = (*_object) - sizeof(CCLASS); |
92 | 92 | ||
93 | - if (*(void**)_object && *class && (*class)->__destruct) { | ||
94 | - (*class)->__destruct(*(void**)_object); | 93 | + if (*_object && *class && (*class)->__destruct) { |
94 | + (*class)->__destruct(*_object); | ||
95 | } | 95 | } |
96 | 96 | ||
97 | free((void *)class); | 97 | free((void *)class); |
98 | - *(void**)_object = NULL; | 98 | + *_object = NULL; |
99 | } | 99 | } |
100 | 100 | ||
101 | void | 101 | void |
1 | -#define _ISOC99_SOURCE | ||
2 | - | ||
3 | -#include <syslog.h> | ||
4 | -#include <stdio.h> | ||
5 | -#include <string.h> | ||
6 | - | ||
7 | #include "logger.h" | 1 | #include "logger.h" |
8 | 2 | ||
9 | -const int priority[] = { | ||
10 | - LOG_USER | LOG_EMERG, | ||
11 | - LOG_USER | LOG_ALERT, | ||
12 | - LOG_USER | LOG_CRIT, | ||
13 | - LOG_USER | LOG_ERR, | ||
14 | - LOG_USER | LOG_WARNING, | ||
15 | - LOG_USER | LOG_NOTICE, | ||
16 | - LOG_USER | LOG_INFO, | ||
17 | - LOG_USER | LOG_DEBUG | ||
18 | -}; | 3 | +extern void logger_syslog(int level, const char * msg); |
19 | 4 | ||
20 | INIT_CLASS(LOGGER); | 5 | INIT_CLASS(LOGGER); |
21 | 6 | ||
22 | -static void | ||
23 | -logger_syslog(int level, const char * msg) | ||
24 | -{ | ||
25 | - syslog(priority[level], "%s", msg); | ||
26 | -} | ||
27 | - | ||
28 | __construct(LOGGER) | 7 | __construct(LOGGER) |
29 | { | 8 | { |
30 | - this->logfncts[0] = logger_syslog; | 9 | + this->logfncts[0] = logger_syslog; |
31 | this->logfncts_count = 1; | 10 | this->logfncts_count = 1; |
32 | } | 11 | } |
33 | 12 | ||
@@ -36,34 +15,4 @@ __jsonConst(LOGGER) {} | @@ -36,34 +15,4 @@ __jsonConst(LOGGER) {} | ||
36 | __toJson(LOGGER) {} | 15 | __toJson(LOGGER) {} |
37 | __clear(LOGGER) {} | 16 | __clear(LOGGER) {} |
38 | 17 | ||
39 | -void | ||
40 | -logger_log(LOGGER this, int level, const char * message, ...) { | ||
41 | - va_list args; | ||
42 | - char buffer[1025]; | ||
43 | - logger_logfnct * logfnct; | ||
44 | - | ||
45 | - int maxBuf = sizeof(buffer)/sizeof(buffer[0]); | ||
46 | - | ||
47 | - memset(buffer, 0, maxBuf); | ||
48 | - | ||
49 | - va_start(args, message); | ||
50 | - vsnprintf(buffer, 1024, message, args); | ||
51 | - va_end(args); | ||
52 | - | ||
53 | - logfnct = this->logfncts; | ||
54 | - | ||
55 | - while (NULL != *logfnct) { | ||
56 | - (*logfnct)(level, buffer); | ||
57 | - logfnct++; | ||
58 | - } | ||
59 | -} | ||
60 | - | ||
61 | -void | ||
62 | -logger_add(LOGGER this, logger_logfnct logfunc) { | ||
63 | - if (this->logfncts_count < MAX_LOG_FNCTS) { | ||
64 | - this->logfncts[this->logfncts_count] = logfunc; | ||
65 | - this->logfncts_count++; | ||
66 | - } | ||
67 | -} | ||
68 | - | ||
69 | // vim: set ts=4 sw=4: | 18 | // vim: set ts=4 sw=4: |
@@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
14 | 14 | ||
15 | static | 15 | static |
16 | int | 16 | int |
17 | -server_select(SERVER this) { | 17 | +server_poll(SERVER this) { |
18 | int events; | 18 | int events; |
19 | 19 | ||
20 | /* | 20 | /* |
@@ -73,8 +73,7 @@ server_read(SERVER this) | @@ -73,8 +73,7 @@ server_read(SERVER this) | ||
73 | 73 | ||
74 | for (i=1; i<this->nfds; i++) { | 74 | for (i=1; i<this->nfds; i++) { |
75 | if (0 != ((this->fds)[i].revents & POLLIN)) { | 75 | if (0 != ((this->fds)[i].revents & POLLIN)) { |
76 | - memset(buffer, 0, 1024); | ||
77 | - switch (_read = read((this->fds)[i].fd, buffer, 1023)) { | 76 | + switch (_read = read((this->fds)[i].fd, buffer, 1024)) { |
78 | case 0: | 77 | case 0: |
79 | /* | 78 | /* |
80 | * normal close: write remaining data | 79 | * normal close: write remaining data |
@@ -92,7 +91,7 @@ server_read(SERVER this) | @@ -92,7 +91,7 @@ server_read(SERVER this) | ||
92 | default: | 91 | default: |
93 | (this->fds)[i].revents |= POLLIN; | 92 | (this->fds)[i].revents |= POLLIN; |
94 | if (NULL != this->read_hook) { | 93 | if (NULL != this->read_hook) { |
95 | - this->read_hook(buffer); | 94 | + this->read_hook(buffer, _read); |
96 | } | 95 | } |
97 | break; | 96 | break; |
98 | } | 97 | } |
@@ -117,7 +116,7 @@ server_run(SERVER this) | @@ -117,7 +116,7 @@ server_run(SERVER this) | ||
117 | * @TODO take return value of poll into account with | 116 | * @TODO take return value of poll into account with |
118 | * further handling! | 117 | * further handling! |
119 | */ | 118 | */ |
120 | - events = server_select(this); | 119 | + events = server_poll(this); |
121 | if (doShutdown) break; | 120 | if (doShutdown) break; |
122 | 121 | ||
123 | /* | 122 | /* |
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <socket.h> | 2 | #include <socket.h> |
3 | +#include <string.h> | ||
3 | 4 | ||
4 | #include "server.h" | 5 | #include "server.h" |
5 | #include "signalHandling.h" | 6 | #include "signalHandling.h" |
6 | 7 | ||
7 | static void | 8 | static void |
8 | -read_hook(const char * _buffer) | 9 | +read_hook(const char * _buffer, size_t size) |
9 | { | 10 | { |
10 | - printf("%s\n", _buffer); | 11 | + char buffer[1025]; |
12 | + | ||
13 | + memset(buffer, 0, 1025); | ||
14 | + snprintf(buffer, size, _buffer); | ||
15 | + | ||
16 | + printf("%s\n", buffer); | ||
11 | } | 17 | } |
12 | 18 | ||
13 | int | 19 | int |
@@ -6,7 +6,8 @@ check_PROGRAMS = cclassTest loggerTest socketTest serverTest | @@ -6,7 +6,8 @@ check_PROGRAMS = cclassTest loggerTest socketTest serverTest | ||
6 | 6 | ||
7 | COMMON = runtest.c ../src/cclass.c | 7 | COMMON = runtest.c ../src/cclass.c |
8 | CCLASS = $(COMMON) mock/class.c | 8 | CCLASS = $(COMMON) mock/class.c |
9 | -LOGGER = $(COMMON) ../src/logger.c | 9 | +LOGGER = $(COMMON) ../src/logger.c ../src/logger/add.c \ |
10 | + ../src/logger/log.c ../src/logger/syslog.c | ||
10 | SOCKET = $(LOGGER) ../src/socket.c ../src/socket/listen.c \ | 11 | SOCKET = $(LOGGER) ../src/socket.c ../src/socket/listen.c \ |
11 | ../src/socket/accept.c ../src/socket/connect.c | 12 | ../src/socket/accept.c ../src/socket/connect.c |
12 | SERVER = $(SOCKET) ../src/server.c ../src/server/run.c \ | 13 | SERVER = $(SOCKET) ../src/server.c ../src/server/run.c \ |
@@ -17,13 +17,15 @@ | @@ -17,13 +17,15 @@ | ||
17 | 17 | ||
18 | int level = -1; | 18 | int level = -1; |
19 | char msg[1024]; | 19 | char msg[1024]; |
20 | -char buffer[1024]; | 20 | +char buffer[1025]; |
21 | 21 | ||
22 | static void | 22 | static void |
23 | -read_hook(const char * _buffer) | 23 | +read_hook(const char * _buffer, size_t size) |
24 | { | 24 | { |
25 | + memset(buffer, 0, 1025); | ||
26 | + | ||
25 | if (NULL != _buffer) { | 27 | if (NULL != _buffer) { |
26 | - strncpy(buffer, _buffer, 1023); | 28 | + strncpy(buffer, _buffer, 1024>size? size : 1024); |
27 | } | 29 | } |
28 | 30 | ||
29 | doShutdown = 1; | 31 | doShutdown = 1; |
@@ -86,7 +88,6 @@ testDummy() | @@ -86,7 +88,6 @@ testDummy() | ||
86 | { | 88 | { |
87 | SOCK con; | 89 | SOCK con; |
88 | pid_t pid; | 90 | pid_t pid; |
89 | - int status; | ||
90 | 91 | ||
91 | pid = fork(); | 92 | pid = fork(); |
92 | 93 |
Please
register
or
login
to post a comment