Commit 151a4ebf0099447b56118f929473f9890633e35d

Authored by Georg Hopp
1 parent b6df6201

now use libtrio for all io operations.

... ... @@ -8,7 +8,7 @@ AC_INIT([taskrambler],
8 8 LT_INIT
9 9 AM_INIT_AUTOMAKE
10 10 #AM_INIT_AUTOMAKE([subdir-objects])
11   -#AM_SILENT_RULES([yes])
  11 +AM_SILENT_RULES([yes])
12 12 AC_COPYRIGHT([Copyright © 2013 Georg Hopp])
13 13 AC_REVISION([m4_esyscmd_s([git describe --always])])
14 14 AC_CONFIG_SRCDIR([src/taskrambler.c])
... ... @@ -96,11 +96,8 @@ AC_CONFIG_FILES([Makefile
96 96 src/hash/Makefile
97 97 src/queue/Makefile
98 98 src/http/Makefile
99   - src/logger/Makefile
100 99 src/server/Makefile
101 100 src/session/Makefile
102   - src/socket/Makefile
103   - src/stream/Makefile
104 101 src/tree/Makefile
105 102 src/application/Makefile
106 103 src/storage/Makefile
... ...
... ... @@ -35,7 +35,7 @@
35 35 #include <sys/types.h>
36 36
37 37 #include "trbase.h"
38   -#include "stream.h"
  38 +#include "trio.h"
39 39
40 40 #define ECBUFOVFL 100
41 41
... ... @@ -53,8 +53,8 @@ TR_CLASS(Cbuf) {
53 53 size_t read;
54 54 };
55 55
56   -ssize_t cbufRead(Cbuf, Stream);
57   -ssize_t cbufWrite(Cbuf, Stream);
  56 +ssize_t cbufRead(Cbuf, TR_Stream);
  57 +ssize_t cbufWrite(Cbuf, TR_Stream);
58 58
59 59 char * cbufGetLine(Cbuf, char **);
60 60 char * cbufGetData(Cbuf, size_t);
... ...
... ... @@ -25,8 +25,8 @@
25 25 #define __HTTP_MESSAGE__
26 26
27 27 #include "trbase.h"
  28 +#include "trio.h"
28 29 #include "hash.h"
29   -#include "stream.h"
30 30 #include "asset.h"
31 31
32 32 TR_CLASS(HttpMessage) {
... ...
... ... @@ -25,10 +25,10 @@
25 25 #define __HTTP_PARSER_H__
26 26
27 27 #include "trbase.h"
  28 +#include "trio.h"
28 29 #include "http/message.h"
29 30 #include "queue.h"
30 31 #include "cbuf.h"
31   -#include "stream.h"
32 32
33 33
34 34 #define PARSER_MAX_BUF 131072
... ... @@ -56,7 +56,7 @@ TR_CLASS(HttpParser) {
56 56 HttpMessageState state;
57 57 };
58 58
59   -ssize_t httpParserParse(void *, Stream);
  59 +ssize_t httpParserParse(void *, TR_Stream);
60 60 void httpParserRequestVars(HttpParser);
61 61 void httpParserHeader(HttpParser, const char *, const char *);
62 62 void httpParserNewMessage(HttpParser, const char *, const char * lend);
... ...
... ... @@ -27,9 +27,9 @@
27 27 #include <sys/types.h>
28 28
29 29 #include "trbase.h"
  30 +#include "trio.h"
30 31 #include "http/message.h"
31 32 #include "queue.h"
32   -#include "stream.h"
33 33
34 34
35 35 /*
... ... @@ -90,7 +90,7 @@ TR_CLASS(HttpWriter) {
90 90 HttpWriterState state;
91 91 };
92 92
93   -ssize_t httpWriterWrite(void *, Stream);
  93 +ssize_t httpWriterWrite(void *, TR_Stream);
94 94
95 95 #endif // __HTTP_WRITER_H__
96 96
... ...
1   -#ifndef __LOGGER_H__
2   -#define __LOGGER_H__
3   -
4   -#include "logger/logger.h"
5   -#include "logger/interface/logger.h"
6   -
7   -#endif // __LOGGER_H__
8   -
9   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - * The logger interface.
4   - *
5   - * \author Georg Hopp
6   - *
7   - * \copyright
8   - * Copyright © 2012 Georg Hopp
9   - *
10   - * This program is free software: you can redistribute it and/or modify
11   - * it under the terms of the GNU General Public License as published by
12   - * the Free Software Foundation, either version 3 of the License, or
13   - * (at your option) any later version.
14   - *
15   - * This program is distributed in the hope that it will be useful,
16   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18   - * GNU General Public License for more details.
19   - *
20   - * You should have received a copy of the GNU General Public License
21   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
22   - */
23   -
24   -#ifndef __LOGGER_INTERFACE_LOGGER_H__
25   -#define __LOGGER_INTERFACE_LOGGER_H__
26   -
27   -#include <stdarg.h>
28   -
29   -#include "trbase.h"
30   -#include "logger.h"
31   -
32   -typedef void (* fptr_log)(void *, logger_level, const char * const);
33   -
34   -TR_INTERFACE(Logger) {
35   - TR_IFID;
36   - fptr_log log;
37   -};
38   -
39   -extern void loggerLog(void *, logger_level, const char * const, ...);
40   -
41   -#endif // __LOGGER_INTERFACE_LOGGER_H__
42   -
43   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - * A generic logger class and two extended classes, One that logs to
4   - * stderr and one that logs to the system syslog.
5   - *
6   - * \author Georg Hopp
7   - *
8   - * \copyright
9   - * Copyright © 2012 Georg Hopp
10   - *
11   - * This program is free software: you can redistribute it and/or modify
12   - * it under the terms of the GNU General Public License as published by
13   - * the Free Software Foundation, either version 3 of the License, or
14   - * (at your option) any later version.
15   - *
16   - * This program is distributed in the hope that it will be useful,
17   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19   - * GNU General Public License for more details.
20   - *
21   - * You should have received a copy of the GNU General Public License
22   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
23   - */
24   -
25   -#ifndef __LOGGER_LOGGER_H__
26   -#define __LOGGER_LOGGER_H__
27   -
28   -#include "trbase.h"
29   -
30   -typedef enum logger_level {
31   - LOGGER_DEBUG=0,
32   - LOGGER_INFO,
33   - LOGGER_NOTICE,
34   - LOGGER_WARNING,
35   - LOGGER_ERR,
36   - LOGGER_CRIT,
37   - LOGGER_ALERT,
38   - LOGGER_EMERG
39   -} logger_level;
40   -
41   -extern const char * const logger_level_str[];
42   -
43   -TR_CLASS(Logger) {
44   - logger_level min_level;
45   -};
46   -
47   -TR_CLASS(LoggerStderr) {
48   - TR_EXTENDS(Logger);
49   -};
50   -
51   -TR_CLASS(LoggerSyslog) {
52   - TR_EXTENDS(Logger);
53   -};
54   -
55   -#endif // __LOGGER_LOGGER_H__
56   -
57   -// vim: set ts=4 sw=4:
... ... @@ -32,22 +32,20 @@
32 32 #include <openssl/ssl.h>
33 33
34 34 #include "trbase.h"
35   -#include "socket.h"
36   -#include "logger.h"
37   -#include "stream.h"
  35 +#include "trio.h"
38 36
39 37 struct conns {
40   - Sock sock;
41   - Stream stream;
42   - void * worker;
  38 + TR_Sock sock;
  39 + TR_Stream stream;
  40 + void * worker;
43 41 };
44 42
45 43 TR_CLASS(Server) {
46   - Logger logger;
47   - Sock sock;
48   - Sock sockSSL;
49   - SSL_CTX * ctx;
50   - void * worker;
  44 + TR_Logger logger;
  45 + TR_Sock sock;
  46 + TR_Sock sockSSL;
  47 + SSL_CTX * ctx;
  48 + void * worker;
51 49
52 50 nfds_t nfds;
53 51 struct pollfd * fds;
... ...
1   -/**
2   - * \file
3   - * Abstraction layer above BSD sockets. Capsules and simplifies connect
4   - * accept and listen.
5   - *
6   - * \author Georg Hopp
7   - *
8   - * \copyright
9   - * Copyright © 2012 Georg Hopp
10   - *
11   - * This program is free software: you can redistribute it and/or modify
12   - * it under the terms of the GNU General Public License as published by
13   - * the Free Software Foundation, either version 3 of the License, or
14   - * (at your option) any later version.
15   - *
16   - * This program is distributed in the hope that it will be useful,
17   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19   - * GNU General Public License for more details.
20   - *
21   - * You should have received a copy of the GNU General Public License
22   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
23   - */
24   -
25   -#ifndef __SOCKET_H__
26   -#define __SOCKET_H__
27   -
28   -#include <arpa/inet.h> // for in_port_t
29   -
30   -#include "trbase.h"
31   -#include "logger.h"
32   -
33   -TR_CLASS(Sock) {
34   - Logger log;
35   - in_port_t port;
36   - struct sockaddr_in addr;
37   - int handle;
38   -};
39   -
40   -void socketConnect(Sock this, const char * addr, char (*)[16]);
41   -void socketListen(Sock this, int backlog);
42   -Sock socketAccept(Sock this, char (*remoteAddr)[16]);
43   -void socketNonblock(Sock this);
44   -
45   -#endif // __SOCKET_H__
46   -
47   -// vim: set ts=4 sw=4:
48   -
1   -#ifndef __STREAM_H__
2   -#define __STREAM_H__
3   -
4   -#include "stream/stream.h"
5   -#include "stream/interface/reader.h"
6   -#include "stream/interface/writer.h"
7   -
8   -#endif // __STREAM_H__
9   -
10   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - * Interface whose implementations can read from a stream given as
4   - * a handle.
5   - *
6   - * \author Georg Hopp
7   - *
8   - * \copyright
9   - * Copyright © 2012 Georg Hopp
10   - *
11   - * This program is free software: you can redistribute it and/or modify
12   - * it under the terms of the GNU General Public License as published by
13   - * the Free Software Foundation, either version 3 of the License, or
14   - * (at your option) any later version.
15   - *
16   - * This program is distributed in the hope that it will be useful,
17   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19   - * GNU General Public License for more details.
20   - *
21   - * You should have received a copy of the GNU General Public License
22   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
23   - */
24   -
25   -#ifndef __STREAM_INTERFACE_READER_H__
26   -#define __STREAM_INTERFACE_READER_H__
27   -
28   -#include <sys/types.h>
29   -
30   -#include "trbase.h"
31   -#include "stream/stream.h"
32   -
33   -typedef ssize_t (* fptr_streamReaderRead)(void *, Stream);
34   -
35   -TR_INTERFACE(StreamReader) {
36   - TR_IFID;
37   - fptr_streamReaderRead read;
38   -};
39   -
40   -extern ssize_t streamReaderRead(void *, Stream);
41   -
42   -#endif // __STREAM_INTERFACE_READER_H__
43   -
44   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - * Interface whose implementations can write from a stream given as
4   - * a handle.
5   - *
6   - * \author Georg Hopp
7   - *
8   - * \copyright
9   - * Copyright © 2012 Georg Hopp
10   - *
11   - * This program is free software: you can redistribute it and/or modify
12   - * it under the terms of the GNU General Public License as published by
13   - * the Free Software Foundation, either version 3 of the License, or
14   - * (at your option) any later version.
15   - *
16   - * This program is distributed in the hope that it will be useful,
17   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19   - * GNU General Public License for more details.
20   - *
21   - * You should have received a copy of the GNU General Public License
22   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
23   - */
24   -
25   -#ifndef __STREAM_INTERFACE_WRITER_H__
26   -#define __STREAM_INTERFACE_WRITER_H__
27   -
28   -#include <sys/types.h>
29   -
30   -#include "trbase.h"
31   -#include "stream/stream.h"
32   -
33   -typedef ssize_t (* fptr_streamWriterWrite)(void *, Stream);
34   -
35   -TR_INTERFACE(StreamWriter) {
36   - TR_IFID;
37   - fptr_streamWriterWrite write;
38   -};
39   -
40   -extern ssize_t streamWriterWrite(void *, Stream);
41   -
42   -#endif // __STREAM_INTERFACE_WRITER_H__
43   -
44   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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 __STREAM_STREAM_H__
24   -#define __STREAM_STREAM_H__
25   -
26   -#include <sys/types.h>
27   -#include <openssl/ssl.h>
28   -
29   -#include "trbase.h"
30   -
31   -typedef enum e_StreamHandleType {
32   - STREAM_FD = 0,
33   - STREAM_SSL
34   -} StreamHandleType;
35   -
36   -TR_CLASS(Stream) {
37   - StreamHandleType type;
38   - union {
39   - int fd;
40   - SSL * ssl;
41   - } handle;
42   -};
43   -
44   -ssize_t streamRead(Stream, void *, size_t);
45   -ssize_t streamWrite(Stream, void *, size_t);
46   -
47   -#endif // __STREAM_STREAM_H__
48   -
49   -// vim: set ts=4 sw=4:
... ... @@ -10,14 +10,11 @@ TRUTILS = utils/http.c \
10 10 TRCOMMONLIBS = cbuf/libcbuf.la \
11 11 hash/libhash.la \
12 12 queue/libqueue.la \
13   - logger/liblogger.la \
14   - tree/libtree.la \
15   - stream/libstream.la
  13 + tree/libtree.la
16 14
17 15 TRHTTPSERVER = http/libhttp.la \
18 16 asset/libasset.la \
19   - server/libserver.la \
20   - socket/libsocket.la
  17 + server/libserver.la
21 18
22 19 TR = ./application/.libs/libapplication.a \
23 20 ./user/.libs/libuser.a \
... ... @@ -27,7 +24,7 @@ TR = ./application/.libs/libapplication.a \
27 24 ./config/.libs/libconfig.a \
28 25 ./router/.libs/librouter.a
29 26
30   -TRLIBS = -ltrbase -ltrhashing -ltrutils -ltrhttpserver -ltrcommon
  27 +TRLIBS = -ltrbase -ltrhashing -ltrio -ltrutils -ltrhttpserver -ltrcommon
31 28 USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid
32 29
33 30 AM_CFLAGS += -I../include/
... ... @@ -54,5 +51,5 @@ taskrambler_LDFLAGS = -Wl,--export-dynamic \
54 51 -Wl,--whole-archive,./application/.libs/libapplication.a,--no-whole-archive
55 52
56 53 SUBDIRS = asset auth cbuf hash queue http \
57   - logger server session socket stream tree application \
  54 + server session tree application \
58 55 storage user config router
... ...
... ... @@ -24,12 +24,12 @@
24 24 #include <unistd.h>
25 25 #include <errno.h>
26 26
  27 +#include "trio.h"
27 28 #include "cbuf.h"
28   -#include "stream.h"
29 29
30 30
31 31 ssize_t
32   -cbufRead(Cbuf this, Stream st)
  32 +cbufRead(Cbuf this, TR_Stream st)
33 33 {
34 34 size_t rsize = cbufGetFree(this);
35 35 ssize_t rrsize;
... ... @@ -39,7 +39,7 @@ cbufRead(Cbuf this, Stream st)
39 39 return -1;
40 40 }
41 41
42   - rrsize = streamRead(st, cbufGetWrite(this), rsize);
  42 + rrsize = TR_streamRead(st, cbufGetWrite(this), rsize);
43 43
44 44 if (0 < rrsize) {
45 45 cbufIncWrite(this, rrsize);
... ...
... ... @@ -25,7 +25,7 @@
25 25 #include <stdarg.h>
26 26
27 27 #include "trbase.h"
28   -#include "stream.h"
  28 +#include "trio.h"
29 29 #include "http/parser.h"
30 30 #include "queue.h"
31 31 #include "http/request.h"
... ... @@ -66,7 +66,7 @@ httpParserDtor(void * _this)
66 66 }
67 67
68 68 TR_INIT_IFACE(TR_Class, httpParserCtor, httpParserDtor, NULL);
69   -TR_INIT_IFACE(StreamReader, httpParserParse);
70   -TR_CREATE_CLASS(HttpParser, NULL, TR_IF(TR_Class), TR_IF(StreamReader));
  69 +TR_INIT_IFACE(TR_StreamReader, httpParserParse);
  70 +TR_CREATE_CLASS(HttpParser, NULL, TR_IF(TR_Class), TR_IF(TR_StreamReader));
71 71
72 72 // vim: set ts=4 sw=4:
... ...
... ... @@ -23,8 +23,8 @@
23 23 #include <stdlib.h>
24 24
25 25 #include "trbase.h"
  26 +#include "trio.h"
26 27 #include "cbuf.h"
27   -#include "stream.h"
28 28 #include "queue.h"
29 29
30 30 #include "http/parser.h"
... ... @@ -33,7 +33,7 @@
33 33
34 34
35 35 ssize_t
36   -httpParserParse(void * _this, Stream st)
  36 +httpParserParse(void * _this, TR_Stream st)
37 37 {
38 38 HttpParser this = _this;
39 39 int cont = 1;
... ...
... ... @@ -42,7 +42,7 @@
42 42 #include <sys/types.h>
43 43
44 44 #include "trbase.h"
45   -#include "stream.h"
  45 +#include "trio.h"
46 46 #include "http/response.h"
47 47 #include "http/message.h"
48 48 #include "http/header.h"
... ...
... ... @@ -31,7 +31,7 @@
31 31 #include <search.h>
32 32
33 33 #include "trbase.h"
34   -#include "stream.h"
  34 +#include "trio.h"
35 35 #include "hash.h"
36 36 #include "queue.h"
37 37 #include "http/worker.h"
... ... @@ -116,8 +116,8 @@ httpWorkerClone(void * _this, void * _base)
116 116 this->writer = TR_new(HttpWriter);
117 117 }
118 118
119   -ssize_t httpWorkerProcess(void *, Stream);
120   -ssize_t httpWorkerWrite(void *, Stream);
  119 +ssize_t httpWorkerProcess(void *, TR_Stream);
  120 +ssize_t httpWorkerWrite(void *, TR_Stream);
121 121
122 122 static
123 123 void
... ... @@ -158,8 +158,8 @@ httpWorkerNotify(void * _this)
158 158 }
159 159
160 160 TR_INIT_IFACE(TR_Class, httpWorkerCtor, httpWorkerDtor, httpWorkerClone);
161   -TR_INIT_IFACE(StreamReader, httpWorkerProcess);
162   -TR_INIT_IFACE(StreamWriter, httpWorkerWrite);
  161 +TR_INIT_IFACE(TR_StreamReader, httpWorkerProcess);
  162 +TR_INIT_IFACE(TR_StreamWriter, httpWorkerWrite);
163 163 TR_INIT_IFACE(
164 164 TR_Subject,
165 165 httpWorkerAttach,
... ... @@ -169,8 +169,8 @@ TR_CREATE_CLASS(
169 169 HttpWorker,
170 170 NULL,
171 171 TR_IF(TR_Class),
172   - TR_IF(StreamReader),
173   - TR_IF(StreamWriter),
  172 + TR_IF(TR_StreamReader),
  173 + TR_IF(TR_StreamWriter),
174 174 TR_IF(TR_Subject));
175 175
176 176 // vim: set ts=4 sw=4:
... ...
... ... @@ -22,12 +22,12 @@
22 22
23 23 #include <sys/types.h>
24 24
  25 +#include "trio.h"
25 26 #include "http/worker.h"
26 27 #include "http/writer.h"
27   -#include "stream.h"
28 28
29 29 ssize_t
30   -httpWorkerWrite(HttpWorker this, Stream st)
  30 +httpWorkerWrite(HttpWorker this, TR_Stream st)
31 31 {
32 32 return httpWriterWrite(this->writer, st);
33 33 }
... ...
... ... @@ -48,7 +48,7 @@ void httpWorkerAddComputedHeader(HttpWorker);
48 48 extern Config config;
49 49
50 50 ssize_t
51   -httpWorkerProcess(HttpWorker this, Stream st)
  51 +httpWorkerProcess(HttpWorker this, TR_Stream st)
52 52 {
53 53 ssize_t requests = httpParserParse(this->parser, st);
54 54
... ...
... ... @@ -23,7 +23,7 @@
23 23 #include <stdarg.h>
24 24
25 25 #include "trbase.h"
26   -#include "stream.h"
  26 +#include "trio.h"
27 27 #include "queue.h"
28 28 #include "http/writer.h"
29 29
... ... @@ -56,7 +56,7 @@ httpWriterDtor(void * _this)
56 56 }
57 57
58 58 TR_INIT_IFACE(TR_Class, httpWriterCtor, httpWriterDtor, NULL);
59   -TR_INIT_IFACE(StreamWriter, httpWriterWrite);
60   -TR_CREATE_CLASS(HttpWriter, NULL, TR_IF(TR_Class), TR_IF(StreamWriter));
  59 +TR_INIT_IFACE(TR_StreamWriter, httpWriterWrite);
  60 +TR_CREATE_CLASS(HttpWriter, NULL, TR_IF(TR_Class), TR_IF(TR_StreamWriter));
61 61
62 62 // vim: set ts=4 sw=4:
... ...
... ... @@ -26,13 +26,13 @@
26 26 #include <trbase.h>
27 27
28 28 #include "http/message.h"
  29 +#include "trio.h"
29 30 #include "queue.h"
30 31 #include "http/writer.h"
31   -#include "stream.h"
32 32
33 33
34 34 ssize_t
35   -httpWriterWrite(void * _this, Stream st)
  35 +httpWriterWrite(void * _this, TR_Stream st)
36 36 {
37 37 HttpWriter this = _this;
38 38
... ... @@ -94,7 +94,7 @@ httpWriterWrite(void * _this, Stream st)
94 94 to_write = (this->nheader + this->nbody) - this->written;
95 95 }
96 96
97   - written = streamWrite(st, start, to_write);
  97 + written = TR_streamWrite(st, start, to_write);
98 98
99 99 if (written < 0) {
100 100 return written;
... ...
1   -ACLOCAL_AMFLAGS = -I m4
2   -AUTOMAKE_OPTIONS = subdir-objects
3   -
4   -AM_CFLAGS += -I../../include/
5   -
6   -noinst_LTLIBRARIES = liblogger.la
7   -
8   -liblogger_la_SOURCES = interface/i_logger.c logger.c stderr.c syslog.c
9   -liblogger_la_CFLAGS = $(AM_CFLAGS)
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <stdlib.h>
24   -#include <stdio.h>
25   -#include <stdarg.h>
26   -
27   -#include "logger/logger.h"
28   -#include "logger/interface/logger.h"
29   -#include "trbase.h"
30   -
31   -TR_CREATE_INTERFACE(Logger, 1);
32   -
33   -void
34   -loggerLog(void * _object, logger_level level, const char * const fmt, ...) {
35   - Logger object = _object;
36   -
37   - if (level >= object->min_level) {
38   - char * msg = NULL;
39   - size_t msg_size = 0;
40   - va_list params;
41   -
42   - va_start(params, fmt);
43   - msg_size = vsnprintf(NULL, msg_size, fmt, params);
44   - va_end(params);
45   -
46   - msg = TR_malloc(msg_size + 1);
47   -
48   - va_start(params, fmt);
49   - vsnprintf(msg, msg_size + 1, fmt, params);
50   - va_end(params);
51   -
52   - TR_CALL(_object, Logger, log, level, msg);
53   -
54   - TR_MEM_FREE(msg);
55   - }
56   -}
57   -
58   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <stdarg.h>
24   -
25   -#include "trbase.h"
26   -#include "logger/logger.h"
27   -#include "logger/interface/logger.h"
28   -
29   -const
30   -char * const
31   -logger_level_str[] = {
32   - "DEBUG",
33   - "INFO",
34   - "NOTICE",
35   - "WARNING",
36   - "ERR",
37   - "CRIT",
38   - "ALERT",
39   - "EMERG"
40   -};
41   -
42   -static
43   -int
44   -loggerCtor(void * _this, va_list * params)
45   -{
46   - Logger this = _this;
47   - this->min_level = va_arg(*params, int);
48   -
49   - return 0;
50   -}
51   -
52   -static void loggerDtor(void * _this) {}
53   -
54   -TR_INIT_IFACE(TR_Class, loggerCtor, loggerDtor, NULL);
55   -TR_CREATE_CLASS(Logger, NULL, TR_IF(TR_Class));
56   -
57   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <stdio.h>
24   -
25   -#include "trbase.h"
26   -#include "logger/logger.h"
27   -#include "logger/interface/logger.h"
28   -
29   -static
30   -void
31   -logStderr(void * this, logger_level level, const char * const msg)
32   -{
33   - fprintf(stderr, "[%s] %s\n", logger_level_str[level], msg);
34   -}
35   -
36   -TR_INIT_IFACE(Logger, logStderr);
37   -TR_CREATE_CLASS(LoggerStderr, Logger, TR_IF(Logger));
38   -
39   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <syslog.h>
24   -
25   -#include "trbase.h"
26   -#include "logger/logger.h"
27   -#include "logger/interface/logger.h"
28   -
29   -static
30   -const
31   -int syslog_priority[] = {
32   - LOG_USER | LOG_DEBUG,
33   - LOG_USER | LOG_INFO,
34   - LOG_USER | LOG_NOTICE,
35   - LOG_USER | LOG_WARNING,
36   - LOG_USER | LOG_ERR,
37   - LOG_USER | LOG_CRIT,
38   - LOG_USER | LOG_ALERT,
39   - LOG_USER | LOG_EMERG
40   -};
41   -
42   -static
43   -void
44   -logSyslog(void * this, logger_level level, const char * const msg)
45   -{
46   - syslog(syslog_priority[level], "[%s] %s", logger_level_str[level], msg);
47   -}
48   -
49   -TR_INIT_IFACE(Logger, logSyslog);
50   -TR_CREATE_CLASS(LoggerSyslog, Logger, TR_IF(Logger));
51   -
52   -// vim: set ts=4 sw=4:
... ... @@ -24,19 +24,19 @@
24 24 #include <string.h>
25 25
26 26 #include "trbase.h"
  27 +#include "trio.h"
27 28 #include "server.h"
28   -#include "stream.h"
29 29
30 30 void
31 31 serverCloseConn(Server this, unsigned int i)
32 32 {
33   - int fd = (this->fds)[i].fd;
34   - Stream st = (this->conns[fd]).stream;
  33 + int fd = (this->fds)[i].fd;
  34 + TR_Stream st = (this->conns[fd]).stream;
35 35
36 36 TR_delete((this->conns)[fd].sock);
37 37 TR_delete((this->conns)[fd].worker);
38 38
39   - if (NULL != st && STREAM_SSL == st->type) {
  39 + if (NULL != st && TR_STREAM_SSL == st->type) {
40 40 SSL_shutdown((st->handle).ssl);
41 41 SSL_free((st->handle).ssl);
42 42 (st->handle).ssl = NULL;
... ...
... ... @@ -27,31 +27,30 @@
27 27 #include <openssl/ssl.h>
28 28
29 29 #include "trbase.h"
  30 +#include "trio.h"
30 31 #include "http/worker.h"
31 32 #include "server.h"
32   -#include "logger.h"
33   -#include "stream.h"
34 33
35 34 int
36 35 serverHandleAccept(Server this, unsigned int i)
37 36 {
38   - char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
39   - Sock acc = NULL;
40   - Stream st;
  37 + char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  38 + TR_Sock acc = NULL;
  39 + TR_Stream st;
41 40
42 41 if (this->nfds >= this->max_fds) {
43 42 return -1;
44 43 }
45 44
46   - acc = socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr);
  45 + acc = TR_socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr);
47 46
48 47 if (NULL != acc && -1 != acc->handle) {
49   - socketNonblock(acc);
  48 + TR_socketNonblock(acc);
50 49
51 50 switch(i) {
52 51 case 0:
53 52 // no SSL
54   - st = TR_new(Stream, STREAM_FD, acc->handle);
  53 + st = TR_new(TR_Stream, TR_STREAM_FD, acc->handle);
55 54 break;
56 55
57 56 case 1:
... ... @@ -60,7 +59,7 @@ serverHandleAccept(Server this, unsigned int i)
60 59 SSL * ssl = SSL_new(this->ctx);
61 60 SSL_set_fd(ssl, acc->handle);
62 61 SSL_accept(ssl);
63   - st = TR_new(Stream, STREAM_SSL, ssl);
  62 + st = TR_new(TR_Stream, TR_STREAM_SSL, ssl);
64 63 }
65 64 break;
66 65
... ... @@ -85,15 +84,15 @@ serverHandleAccept(Server this, unsigned int i)
85 84 switch(errno) {
86 85 case EAGAIN|EWOULDBLOCK:
87 86 case EINTR:
88   - loggerLog(this->logger,
89   - LOGGER_DEBUG,
  87 + TR_loggerLog(this->logger,
  88 + TR_LOGGER_DEBUG,
90 89 "server accept blocks");
91 90 return -1;
92 91 break;
93 92
94 93 default:
95   - loggerLog(this->logger,
96   - LOGGER_DEBUG,
  94 + TR_loggerLog(this->logger,
  95 + TR_LOGGER_DEBUG,
97 96 "server accept error");
98 97 return -2;
99 98 break;
... ... @@ -101,8 +100,8 @@ serverHandleAccept(Server this, unsigned int i)
101 100 }
102 101
103 102 if (0 == this->nfds%200) {
104   - loggerLog(this->logger,
105   - LOGGER_DEBUG, "paralel connections: %lu", this->nfds);
  103 + TR_loggerLog(this->logger,
  104 + TR_LOGGER_DEBUG, "paralel connections: %lu", this->nfds);
106 105 }
107 106
108 107 return acc->handle;
... ...
... ... @@ -24,7 +24,7 @@
24 24 #include <errno.h>
25 25
26 26 #include "server.h"
27   -#include "logger.h"
  27 +#include "trio.h"
28 28
29 29 #include "utils/signalHandling.h"
30 30
... ... @@ -69,7 +69,7 @@ serverPoll(Server this) {
69 69 // DROP THROUGH
70 70
71 71 case EINTR:
72   - loggerLog(this->logger, LOGGER_CRIT,
  72 + TR_loggerLog(this->logger, TR_LOGGER_CRIT,
73 73 "poll systemcall failed: [%s] - service terminated",
74 74 strerror(errno));
75 75 }
... ...
... ... @@ -23,9 +23,7 @@
23 23 #include <errno.h>
24 24
25 25 #include "server.h"
26   -#include "logger.h"
27   -#include "stream.h"
28   -
  26 +#include "trio.h"
29 27
30 28 ssize_t
31 29 serverRead(Server this, unsigned int i)
... ... @@ -33,14 +31,14 @@ serverRead(Server this, unsigned int i)
33 31 int fd = (this->fds)[i].fd;
34 32
35 33 if (NULL == (this->conns)[fd].worker) {
36   - loggerLog(
  34 + TR_loggerLog(
37 35 this->logger,
38   - LOGGER_INFO,
  36 + TR_LOGGER_INFO,
39 37 "initialization error: NULL reader");
40 38 return -2;
41 39 }
42 40
43   - return streamReaderRead(
  41 + return TR_streamReaderRead(
44 42 (this->conns)[fd].worker,
45 43 (this->conns)[fd].stream);
46 44 }
... ...
... ... @@ -21,7 +21,7 @@
21 21 */
22 22
23 23 #include "server.h"
24   -#include "logger.h"
  24 +#include "trio.h"
25 25
26 26 #include "utils/signalHandling.h"
27 27
... ... @@ -37,7 +37,7 @@ serverRun(Server this)
37 37 {
38 38 int events = 0;
39 39
40   - loggerLog(this->logger, LOGGER_INFO, "service started");
  40 + TR_loggerLog(this->logger, TR_LOGGER_INFO, "service started");
41 41
42 42 while (!doShutdown) //! until error or signal
43 43 {
... ...
... ... @@ -28,9 +28,8 @@
28 28 #include <openssl/err.h>
29 29
30 30 #include "trbase.h"
  31 +#include "trio.h"
31 32 #include "server.h"
32   -#include "socket.h"
33   -#include "logger.h"
34 33
35 34
36 35 void serverCloseConn(Server, unsigned int);
... ... @@ -53,24 +52,24 @@ serverCtor(void * _this, va_list * params)
53 52 }
54 53 this->max_fds -= 10;
55 54
56   - this->logger = va_arg(* params, Logger);
  55 + this->logger = va_arg(* params, TR_Logger);
57 56 this->worker = va_arg(* params, void *);
58 57 port = va_arg(* params, int);
59 58 backlog = va_arg(* params, unsigned int);
60 59
61   - loggerLog(this->logger,
62   - LOGGER_INFO,
  60 + TR_loggerLog(this->logger,
  61 + TR_LOGGER_INFO,
63 62 "accept up to %zu connections",
64 63 this->max_fds);
65 64
66 65 this->fds = TR_calloc(sizeof(struct pollfd), this->max_fds);
67 66 this->conns = TR_calloc(sizeof(struct conns), this->max_fds);
68 67
69   - this->sock = TR_new(Sock, this->logger, port);
70   - socketNonblock(this->sock);
  68 + this->sock = TR_new(TR_Sock, this->logger, port);
  69 + TR_socketNonblock(this->sock);
71 70
72   - this->sockSSL = TR_new(Sock, this->logger, port+1);
73   - socketNonblock(this->sockSSL);
  71 + this->sockSSL = TR_new(TR_Sock, this->logger, port+1);
  72 + TR_socketNonblock(this->sockSSL);
74 73
75 74 SSL_library_init();
76 75 OpenSSL_add_all_algorithms();
... ... @@ -89,8 +88,8 @@ serverCtor(void * _this, va_list * params)
89 88 CONFIGDIR "/taskrambler.pem",
90 89 SSL_FILETYPE_PEM);
91 90
92   - socketListen(this->sock, backlog);
93   - socketListen(this->sockSSL, backlog);
  91 + TR_socketListen(this->sock, backlog);
  92 + TR_socketListen(this->sockSSL, backlog);
94 93
95 94 (this->fds)[0].fd = this->sock->handle;
96 95 (this->fds)[0].events = POLLIN;
... ...
... ... @@ -23,8 +23,7 @@
23 23 #include <errno.h>
24 24
25 25 #include "server.h"
26   -#include "logger.h"
27   -#include "stream.h"
  26 +#include "trio.h"
28 27
29 28 ssize_t
30 29 serverWrite(Server this, unsigned int i)
... ... @@ -32,14 +31,14 @@ serverWrite(Server this, unsigned int i)
32 31 int fd = (this->fds)[i].fd;
33 32
34 33 if (NULL == (this->conns)[fd].worker) {
35   - loggerLog(
  34 + TR_loggerLog(
36 35 this->logger,
37   - LOGGER_INFO,
  36 + TR_LOGGER_INFO,
38 37 "initialization error: NULL worker");
39 38 return -2;
40 39 }
41 40
42   - return streamWriterWrite(
  41 + return TR_streamWriterWrite(
43 42 (this->conns)[fd].worker,
44 43 (this->conns)[fd].stream);
45 44 }
... ...
1   -ACLOCAL_AMFLAGS = -I m4
2   -AUTOMAKE_OPTIONS = subdir-objects
3   -
4   -AM_CFLAGS += -I../../include/
5   -
6   -noinst_LTLIBRARIES = libsocket.la
7   -
8   -libsocket_la_SOURCES = socket.c accept.c connect.c listen.c nonblock.c
9   -libsocket_la_CFLAGS = $(AM_CFLAGS)
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <errno.h> // for errno
24   -#include <unistd.h>
25   -#include <fcntl.h>
26   -
27   -#include "trbase.h"
28   -#include "socket.h"
29   -#include "logger.h"
30   -
31   -Sock
32   -socketAccept(Sock this, char (*remoteAddr)[16])
33   -{
34   - Sock sock; // Socket for client
35   - unsigned int len; // Length of client address data structure
36   -
37   - // Set the size of the in-out parameter
38   - len = sizeof(this->addr);
39   -
40   - sock = TR_new(Sock, this->log, -1);
41   -
42   - // Wait for a client to connect
43   - sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len);
44   - if (-1 == sock->handle) {
45   - loggerLog(this->log, LOGGER_WARNING,
46   - "error accepting connection: %s", strerror(errno));
47   - } else {
48   - strcpy(*remoteAddr, inet_ntoa((sock->addr).sin_addr));
49   -
50   - //loggerLog(this->log, LOGGER_INFO,
51   - // "handling client %s\n", inet_ntoa((sock->addr).sin_addr));
52   - }
53   -
54   - return sock;
55   -}
56   -
57   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <stdlib.h> // for atoi() and exit()
24   -#include <errno.h> // for errno
25   -
26   -#include "socket.h"
27   -#include "logger.h"
28   -
29   -
30   -void
31   -socketConnect(Sock this, const char * addr, char (*remoteAddr)[16])
32   -{
33   - inet_pton(AF_INET, addr, &((this->addr).sin_addr));
34   - (this->addr).sin_family = AF_INET; // Internet address family
35   - (this->addr).sin_port = htons(this->port); // Local port
36   -
37   - if (-1 == connect(
38   - this->handle,
39   - (struct sockaddr*) &(this->addr),
40   - sizeof(this->addr)))
41   - {
42   - loggerLog(this->log, LOGGER_CRIT,
43   - "error connection socket: %s - service terminated",
44   - strerror(errno));
45   - exit(EXIT_FAILURE);
46   - } else {
47   - strcpy(*remoteAddr, inet_ntoa((this->addr).sin_addr));
48   -
49   - loggerLog(this->log, LOGGER_INFO,
50   - "handling connection %s\n", inet_ntoa((this->addr).sin_addr));
51   - }
52   -}
53   -
54   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <stdlib.h> // for atoi() and exit()
24   -#include <errno.h> // for errno
25   -
26   -#include "socket.h"
27   -#include "logger.h"
28   -
29   -
30   -void
31   -socketListen(Sock this, int backlog)
32   -{
33   - (this->addr).sin_family = AF_INET; // Internet address family
34   - (this->addr).sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface
35   - //(this->addr).sin_addr.s_addr = inet_addr("127.0.0.1"); // Any incoming interface
36   - (this->addr).sin_port = htons(this->port); // Local port
37   -
38   - /**
39   - * Bind to the local address
40   - */
41   - if (-1 == bind(this->handle, (struct sockaddr *) &(this->addr), sizeof(this->addr))) {
42   - loggerLog(this->log, LOGGER_CRIT,
43   - "error binding socket: %s - service terminated",
44   - strerror(errno));
45   - exit(EXIT_FAILURE);
46   - }
47   -
48   - /**
49   - * Mark the socket so it will listen for incoming connections
50   - */
51   - if (-1 == listen(this->handle, backlog)) {
52   - loggerLog(this->log, LOGGER_CRIT,
53   - "error binding socket: %s - service terminated",
54   - strerror(errno));
55   - exit(EXIT_FAILURE);
56   - }
57   -}
58   -
59   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <errno.h> // for errno
24   -#include <unistd.h>
25   -#include <fcntl.h>
26   -
27   -#include "socket.h"
28   -#include "logger.h"
29   -
30   -void
31   -socketNonblock(Sock this)
32   -{
33   - int flags = fcntl(this->handle, F_GETFL, 0);
34   - fcntl(this->handle, F_SETFL, flags | O_NONBLOCK);
35   -}
36   -
37   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <errno.h>
24   -#include <stdlib.h>
25   -#include <unistd.h>
26   -
27   -#include "socket.h"
28   -#include "logger.h"
29   -#include "trbase.h"
30   -
31   -static
32   -int
33   -socketCtor(void * _this, va_list * params)
34   -{
35   - Sock this = _this;
36   - int reUse = 1; //! \todo make this configurable
37   - int port;
38   -
39   - this->log = va_arg(* params, Logger);
40   - port = va_arg(* params, int);
41   -
42   - //! if port is -1 do not initialize the socket. (Used with accept)
43   - if (-1 == port) {
44   - return 0;
45   - } else {
46   - this->port = port;
47   - }
48   -
49   - //! Create socket for incoming connections
50   - if (-1 == (this->handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))) {
51   - loggerLog(this->log, LOGGER_CRIT,
52   - "error opening socket: %s - service terminated",
53   - strerror(errno));
54   - return -1;
55   - }
56   -
57   - //! Make the socket REUSE a TIME_WAIT socket
58   - setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof(reUse));
59   -
60   - return 0;
61   -}
62   -
63   -static
64   -void
65   -socketDtor(void * _this)
66   -{
67   - Sock this = _this;
68   -
69   - if (STDERR_FILENO < this->handle) {
70   - shutdown(this->handle, SHUT_RDWR);
71   - close(this->handle);
72   - }
73   -}
74   -
75   -TR_INIT_IFACE(TR_Class, socketCtor, socketDtor, NULL);
76   -TR_CREATE_CLASS(Sock, NULL, TR_IF(TR_Class));
77   -
78   -// vim: set ts=4 sw=4:
1   -ACLOCAL_AMFLAGS = -I m4
2   -AUTOMAKE_OPTIONS = subdir-objects
3   -
4   -STREAM = stream.c read.c write.c
5   -IFACE = interface/reader.c \
6   - interface/writer.c
7   -
8   -AM_CFLAGS += -I../../include/
9   -
10   -noinst_LTLIBRARIES = libstream.la
11   -
12   -libstream_la_SOURCES = $(STREAM) $(IFACE)
13   -libstream_la_CFLAGS = $(AM_CFLAGS)
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include "trbase.h"
24   -#include "stream/stream.h"
25   -#include "stream/interface/reader.h"
26   -
27   -TR_CREATE_INTERFACE(StreamReader, 1);
28   -
29   -ssize_t
30   -streamReaderRead(void * object, Stream st)
31   -{
32   - ssize_t ret;
33   -
34   - TR_RETCALL(object, StreamReader, read, ret, st);
35   -
36   - return ret;
37   -}
38   -
39   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include "trbase.h"
24   -#include "stream/stream.h"
25   -#include "stream/interface/writer.h"
26   -
27   -TR_CREATE_INTERFACE(StreamWriter, 1);
28   -
29   -
30   -ssize_t
31   -streamWriterWrite(void * object, Stream st)
32   -{
33   - ssize_t ret;
34   -
35   - TR_RETCALL(object, StreamWriter, write, ret, st);
36   -
37   - return ret;
38   -}
39   -
40   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <openssl/err.h>
24   -#include <openssl/ssl.h>
25   -#include <unistd.h>
26   -#include <errno.h>
27   -
28   -#include "stream.h"
29   -#include "logger.h"
30   -
31   -extern Logger logger;
32   -
33   -
34   -ssize_t
35   -streamRead(Stream this, void * buf, size_t count)
36   -{
37   - ssize_t done;
38   -
39   - switch(this->type) {
40   - ssize_t _read;
41   -
42   - case STREAM_FD:
43   - _read = read((this->handle).fd, buf, count);
44   -
45   - if (_read < 0) {
46   - switch (errno) {
47   - case EINTR:
48   - case ENOMEM:
49   - done = 0;
50   - break;
51   - case (EAGAIN|EWOULDBLOCK):
52   - done = -1;
53   - break;
54   - default:
55   - done = -2;
56   - break;
57   - }
58   - } else if (_read == 0) {
59   - done = -2;
60   - } else {
61   - done = _read;
62   - }
63   -
64   - break;
65   -
66   - case STREAM_SSL:
67   - done = SSL_read((this->handle).ssl, buf, count);
68   -
69   - if (0 == done) {
70   - done = -2;
71   - } else if (0 > done) {
72   - switch (SSL_get_error((this->handle).ssl, done)) {
73   - case SSL_ERROR_SYSCALL:
74   - {
75   - switch (errno) {
76   - case EINTR:
77   - case ENOBUFS:
78   - case ENOMEM:
79   - done = 0;
80   - break;
81   - case (EAGAIN|EWOULDBLOCK):
82   - done = -1;
83   - break;
84   - default:
85   - done = -1;
86   - break;
87   - }
88   - }
89   - break;
90   -
91   - case SSL_ERROR_SSL:
92   - {
93   - unsigned long err;
94   -
95   - while (0 != (err = ERR_get_error())) {
96   - loggerLog(
97   - logger,
98   - LOGGER_DEBUG,
99   - ERR_error_string(err, NULL));
100   - }
101   - }
102   - // DROP THROUGH
103   -
104   - case SSL_ERROR_ZERO_RETURN:
105   - done = -2;
106   - break;
107   - }
108   - }
109   -
110   - break;
111   -
112   - default:
113   - done = -2;
114   - break;
115   - }
116   -
117   - return done;
118   -}
119   -
120   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <stdarg.h>
24   -#include <openssl/ssl.h>
25   -
26   -#include "trbase.h"
27   -#include "stream/stream.h"
28   -
29   -
30   -static
31   -int
32   -streamCtor(void * _this, va_list * params)
33   -{
34   - Stream this = _this;
35   - this->type = va_arg(* params, StreamHandleType);
36   -
37   - switch(this->type) {
38   - case STREAM_FD:
39   - (this->handle).fd = va_arg(* params, int);
40   - break;
41   -
42   - case STREAM_SSL:
43   - (this->handle).ssl = va_arg(* params, SSL*);
44   - break;
45   -
46   - default:
47   - return -1;
48   - }
49   -
50   - return 0;
51   -}
52   -
53   -static
54   -void
55   -streamDtor(void * _this)
56   -{
57   -}
58   -
59   -TR_INIT_IFACE(TR_Class, streamCtor, streamDtor, NULL);
60   -TR_CREATE_CLASS(Stream, NULL, TR_IF(TR_Class));
61   -
62   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 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   -#include <openssl/err.h>
24   -#include <openssl/ssl.h>
25   -#include <unistd.h>
26   -#include <errno.h>
27   -
28   -#include "stream.h"
29   -#include "logger.h"
30   -
31   -extern Logger logger;
32   -
33   -
34   -ssize_t
35   -streamWrite(Stream this, void * buf, size_t count)
36   -{
37   - ssize_t done;
38   -
39   - switch(this->type) {
40   - ssize_t written;
41   -
42   - case STREAM_FD:
43   - written = write((this->handle).fd, buf, count);
44   -
45   - if (written < 0) {
46   - switch (errno) {
47   - case EINTR:
48   - case ENOBUFS:
49   - case ENOMEM:
50   - done = 0;
51   - break;
52   - case (EAGAIN|EWOULDBLOCK):
53   - done = -1;
54   - break;
55   - default:
56   - done = -2;
57   - break;
58   - }
59   - } else {
60   - done = written;
61   - }
62   -
63   - break;
64   -
65   - case STREAM_SSL:
66   - /**
67   - * \todo I got a segfault in this call under unclear
68   - * circumstances. Most likely it has to do with a
69   - * write on a closed connection.
70   - */
71   - done = SSL_write((this->handle).ssl, buf, count);
72   -
73   - if (0 == done) {
74   - done = -2;
75   - } else if (0 > done) {
76   - switch (SSL_get_error((this->handle).ssl, done)) {
77   - case SSL_ERROR_SYSCALL:
78   - {
79   - switch (errno) {
80   - case EINTR:
81   - case ENOBUFS:
82   - case ENOMEM:
83   - done = 0;
84   - break;
85   - case (EAGAIN|EWOULDBLOCK):
86   - done = -1;
87   - break;
88   - default:
89   - done = -2;
90   - break;
91   - }
92   - }
93   - break;
94   -
95   - case SSL_ERROR_SSL:
96   - {
97   - unsigned long err;
98   -
99   - while (0 != (err = ERR_get_error())) {
100   - loggerLog(
101   - logger,
102   - LOGGER_DEBUG,
103   - ERR_error_string(err, NULL));
104   - }
105   - }
106   - // DROP THROUGH
107   -
108   - case SSL_ERROR_ZERO_RETURN:
109   - done = -2;
110   - break;
111   - }
112   - }
113   -
114   - break;
115   -
116   - default:
117   - done = -2;
118   - break;
119   - }
120   -
121   - return done;
122   -}
123   -
124   -// vim: set ts=4 sw=4:
... ... @@ -38,9 +38,9 @@
38 38
39 39 #include <trbase.h>
40 40 #include <trhash.h>
  41 +#include <trio.h>
41 42
42 43 #include "server.h"
43   -#include "logger.h"
44 44 #include "http/worker.h"
45 45 #include "auth.h"
46 46 #include "application/application.h"
... ... @@ -48,8 +48,6 @@
48 48 #include "config/config.h"
49 49 #include "config/value.h"
50 50
51   -#include "logger.h"
52   -
53 51 #include "utils/signalHandling.h"
54 52 #include "utils/mime_type.h"
55 53
... ... @@ -63,8 +61,8 @@ void nullhandler() {}
63 61
64 62 void daemonize(void);
65 63
66   -Logger logger;
67   -Config config;
  64 +TR_Logger logger;
  65 +Config config;
68 66
69 67 int
70 68 main()
... ... @@ -77,15 +75,15 @@ main()
77 75 int shm;
78 76 struct randval * value;
79 77
80   - logger = TR_new(LoggerSyslog, LOGGER_DEBUG);
  78 + logger = TR_new(TR_LoggerSyslog, TR_LOGGER_DEBUG);
81 79 config = TR_new(Config, CONFIGDIR "/taskrambler.conf");
82 80
83 81 if (NULL == config) {
84   - loggerLog(logger, LOGGER_INFO,
  82 + TR_loggerLog(logger, TR_LOGGER_INFO,
85 83 "unable to load configuration file: %s\n",
86 84 CONFIGDIR "/taskrambler.conf");
87 85
88   - if (! TR_INSTANCE_OF(LoggerStderr, logger)) {
  86 + if (! TR_INSTANCE_OF(TR_LoggerStderr, logger)) {
89 87 fprintf(stderr,
90 88 "unable to load configuration file: %s\n",
91 89 CONFIGDIR "/taskrambler.conf");
... ... @@ -255,19 +253,19 @@ main()
255 253
256 254 if (0 < w) {
257 255 if (WIFEXITED(status)) {
258   - loggerLog(logger, LOGGER_INFO,
  256 + TR_loggerLog(logger, TR_LOGGER_INFO,
259 257 "child exited, status=%d\n",
260 258 WEXITSTATUS(status));
261 259 } else if (WIFSIGNALED(status)) {
262   - loggerLog(logger, LOGGER_INFO,
  260 + TR_loggerLog(logger, TR_LOGGER_INFO,
263 261 "killed by signal %d\n",
264 262 WTERMSIG(status));
265 263 } else if (WIFSTOPPED(status)) {
266   - loggerLog(logger, LOGGER_INFO,
  264 + TR_loggerLog(logger, TR_LOGGER_INFO,
267 265 "stopped by signal %d\n",
268 266 WSTOPSIG(status));
269 267 } else if (WIFCONTINUED(status)) {
270   - loggerLog(logger, LOGGER_INFO, "continued\n");
  268 + TR_loggerLog(logger, TR_LOGGER_INFO, "continued\n");
271 269 }
272 270 }
273 271 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
... ...
... ... @@ -38,7 +38,7 @@ mockWorkerClone(void * _this, void * _base)
38 38
39 39 static
40 40 ssize_t
41   -mockWorkerRead(void * _this, Stream st)
  41 +mockWorkerRead(void * _this, TR_Stream st)
42 42 {
43 43 MockWorker this = _this;
44 44 size_t size;
... ... @@ -50,19 +50,19 @@ mockWorkerRead(void * _this, Stream st)
50 50
51 51 static
52 52 ssize_t
53   -mockWorkerWrite(void * _this, Stream st)
  53 +mockWorkerWrite(void * _this, TR_Stream st)
54 54 {
55 55 return 0;
56 56 }
57 57
58 58 INIT_IFACE(Class, mockWorkerCtor, mockWorkerDtor, mockWorkerClone);
59   -INIT_IFACE(StreamReader, mockWorkerRead);
60   -INIT_IFACE(StreamWriter, mockWorkerWrite);
  59 +INIT_IFACE(TR_StreamReader, mockWorkerRead);
  60 +INIT_IFACE(TR_StreamWriter, mockWorkerWrite);
61 61 CREATE_CLASS(
62 62 MockWorker,
63 63 NULL,
64 64 IFACE(Class),
65   - IFACE(StreamReader),
66   - IFACE(StreamWriter));
  65 + IFACE(TR_StreamReader),
  66 + IFACE(TR_StreamWriter));
67 67
68 68 // vim: set ts=4 sw=4:
... ...
... ... @@ -5,7 +5,7 @@
5 5 #include "runtest.h"
6 6 #include "class.h"
7 7 #include "socket.h"
8   -#include "logger.h"
  8 +#include "trio.h"
9 9 #include "mock/mock_logger.h"
10 10
11 11
... ...
Please register or login to post a comment