diff --git a/configure.ac b/configure.ac index 18f083b..09b5087 100644 --- a/configure.ac +++ b/configure.ac @@ -8,7 +8,7 @@ AC_INIT([taskrambler], LT_INIT AM_INIT_AUTOMAKE #AM_INIT_AUTOMAKE([subdir-objects]) -#AM_SILENT_RULES([yes]) +AM_SILENT_RULES([yes]) AC_COPYRIGHT([Copyright © 2013 Georg Hopp]) AC_REVISION([m4_esyscmd_s([git describe --always])]) AC_CONFIG_SRCDIR([src/taskrambler.c]) @@ -96,11 +96,8 @@ AC_CONFIG_FILES([Makefile src/hash/Makefile src/queue/Makefile src/http/Makefile - src/logger/Makefile src/server/Makefile src/session/Makefile - src/socket/Makefile - src/stream/Makefile src/tree/Makefile src/application/Makefile src/storage/Makefile diff --git a/include/cbuf.h b/include/cbuf.h index c65fd77..04c02fe 100644 --- a/include/cbuf.h +++ b/include/cbuf.h @@ -35,7 +35,7 @@ #include #include "trbase.h" -#include "stream.h" +#include "trio.h" #define ECBUFOVFL 100 @@ -53,8 +53,8 @@ TR_CLASS(Cbuf) { size_t read; }; -ssize_t cbufRead(Cbuf, Stream); -ssize_t cbufWrite(Cbuf, Stream); +ssize_t cbufRead(Cbuf, TR_Stream); +ssize_t cbufWrite(Cbuf, TR_Stream); char * cbufGetLine(Cbuf, char **); char * cbufGetData(Cbuf, size_t); diff --git a/include/http/message.h b/include/http/message.h index 06f1762..5211aef 100644 --- a/include/http/message.h +++ b/include/http/message.h @@ -25,8 +25,8 @@ #define __HTTP_MESSAGE__ #include "trbase.h" +#include "trio.h" #include "hash.h" -#include "stream.h" #include "asset.h" TR_CLASS(HttpMessage) { diff --git a/include/http/parser.h b/include/http/parser.h index 6d2ec2b..d59adbd 100644 --- a/include/http/parser.h +++ b/include/http/parser.h @@ -25,10 +25,10 @@ #define __HTTP_PARSER_H__ #include "trbase.h" +#include "trio.h" #include "http/message.h" #include "queue.h" #include "cbuf.h" -#include "stream.h" #define PARSER_MAX_BUF 131072 @@ -56,7 +56,7 @@ TR_CLASS(HttpParser) { HttpMessageState state; }; -ssize_t httpParserParse(void *, Stream); +ssize_t httpParserParse(void *, TR_Stream); void httpParserRequestVars(HttpParser); void httpParserHeader(HttpParser, const char *, const char *); void httpParserNewMessage(HttpParser, const char *, const char * lend); diff --git a/include/http/writer.h b/include/http/writer.h index e0b7ece..200d5ab 100644 --- a/include/http/writer.h +++ b/include/http/writer.h @@ -27,9 +27,9 @@ #include #include "trbase.h" +#include "trio.h" #include "http/message.h" #include "queue.h" -#include "stream.h" /* @@ -90,7 +90,7 @@ TR_CLASS(HttpWriter) { HttpWriterState state; }; -ssize_t httpWriterWrite(void *, Stream); +ssize_t httpWriterWrite(void *, TR_Stream); #endif // __HTTP_WRITER_H__ diff --git a/include/logger.h b/include/logger.h deleted file mode 100644 index 5680044..0000000 --- a/include/logger.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __LOGGER_H__ -#define __LOGGER_H__ - -#include "logger/logger.h" -#include "logger/interface/logger.h" - -#endif // __LOGGER_H__ - -// vim: set ts=4 sw=4: diff --git a/include/logger/interface/logger.h b/include/logger/interface/logger.h deleted file mode 100644 index 24fe6c0..0000000 --- a/include/logger/interface/logger.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - * \file - * The logger interface. - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __LOGGER_INTERFACE_LOGGER_H__ -#define __LOGGER_INTERFACE_LOGGER_H__ - -#include - -#include "trbase.h" -#include "logger.h" - -typedef void (* fptr_log)(void *, logger_level, const char * const); - -TR_INTERFACE(Logger) { - TR_IFID; - fptr_log log; -}; - -extern void loggerLog(void *, logger_level, const char * const, ...); - -#endif // __LOGGER_INTERFACE_LOGGER_H__ - -// vim: set ts=4 sw=4: diff --git a/include/logger/logger.h b/include/logger/logger.h deleted file mode 100644 index e1c3975..0000000 --- a/include/logger/logger.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * A generic logger class and two extended classes, One that logs to - * stderr and one that logs to the system syslog. - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __LOGGER_LOGGER_H__ -#define __LOGGER_LOGGER_H__ - -#include "trbase.h" - -typedef enum logger_level { - LOGGER_DEBUG=0, - LOGGER_INFO, - LOGGER_NOTICE, - LOGGER_WARNING, - LOGGER_ERR, - LOGGER_CRIT, - LOGGER_ALERT, - LOGGER_EMERG -} logger_level; - -extern const char * const logger_level_str[]; - -TR_CLASS(Logger) { - logger_level min_level; -}; - -TR_CLASS(LoggerStderr) { - TR_EXTENDS(Logger); -}; - -TR_CLASS(LoggerSyslog) { - TR_EXTENDS(Logger); -}; - -#endif // __LOGGER_LOGGER_H__ - -// vim: set ts=4 sw=4: diff --git a/include/server.h b/include/server.h index 6e2d09e..0a3cb16 100644 --- a/include/server.h +++ b/include/server.h @@ -32,22 +32,20 @@ #include #include "trbase.h" -#include "socket.h" -#include "logger.h" -#include "stream.h" +#include "trio.h" struct conns { - Sock sock; - Stream stream; - void * worker; + TR_Sock sock; + TR_Stream stream; + void * worker; }; TR_CLASS(Server) { - Logger logger; - Sock sock; - Sock sockSSL; - SSL_CTX * ctx; - void * worker; + TR_Logger logger; + TR_Sock sock; + TR_Sock sockSSL; + SSL_CTX * ctx; + void * worker; nfds_t nfds; struct pollfd * fds; diff --git a/include/socket.h b/include/socket.h deleted file mode 100644 index 74b2e3d..0000000 --- a/include/socket.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * \file - * Abstraction layer above BSD sockets. Capsules and simplifies connect - * accept and listen. - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __SOCKET_H__ -#define __SOCKET_H__ - -#include // for in_port_t - -#include "trbase.h" -#include "logger.h" - -TR_CLASS(Sock) { - Logger log; - in_port_t port; - struct sockaddr_in addr; - int handle; -}; - -void socketConnect(Sock this, const char * addr, char (*)[16]); -void socketListen(Sock this, int backlog); -Sock socketAccept(Sock this, char (*remoteAddr)[16]); -void socketNonblock(Sock this); - -#endif // __SOCKET_H__ - -// vim: set ts=4 sw=4: - diff --git a/include/stream.h b/include/stream.h deleted file mode 100644 index 2b3072b..0000000 --- a/include/stream.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __STREAM_H__ -#define __STREAM_H__ - -#include "stream/stream.h" -#include "stream/interface/reader.h" -#include "stream/interface/writer.h" - -#endif // __STREAM_H__ - -// vim: set ts=4 sw=4: diff --git a/include/stream/interface/reader.h b/include/stream/interface/reader.h deleted file mode 100644 index 5ff9079..0000000 --- a/include/stream/interface/reader.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * \file - * Interface whose implementations can read from a stream given as - * a handle. - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __STREAM_INTERFACE_READER_H__ -#define __STREAM_INTERFACE_READER_H__ - -#include - -#include "trbase.h" -#include "stream/stream.h" - -typedef ssize_t (* fptr_streamReaderRead)(void *, Stream); - -TR_INTERFACE(StreamReader) { - TR_IFID; - fptr_streamReaderRead read; -}; - -extern ssize_t streamReaderRead(void *, Stream); - -#endif // __STREAM_INTERFACE_READER_H__ - -// vim: set ts=4 sw=4: diff --git a/include/stream/interface/writer.h b/include/stream/interface/writer.h deleted file mode 100644 index 19a50d3..0000000 --- a/include/stream/interface/writer.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * \file - * Interface whose implementations can write from a stream given as - * a handle. - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __STREAM_INTERFACE_WRITER_H__ -#define __STREAM_INTERFACE_WRITER_H__ - -#include - -#include "trbase.h" -#include "stream/stream.h" - -typedef ssize_t (* fptr_streamWriterWrite)(void *, Stream); - -TR_INTERFACE(StreamWriter) { - TR_IFID; - fptr_streamWriterWrite write; -}; - -extern ssize_t streamWriterWrite(void *, Stream); - -#endif // __STREAM_INTERFACE_WRITER_H__ - -// vim: set ts=4 sw=4: diff --git a/include/stream/stream.h b/include/stream/stream.h deleted file mode 100644 index bf16e7b..0000000 --- a/include/stream/stream.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __STREAM_STREAM_H__ -#define __STREAM_STREAM_H__ - -#include -#include - -#include "trbase.h" - -typedef enum e_StreamHandleType { - STREAM_FD = 0, - STREAM_SSL -} StreamHandleType; - -TR_CLASS(Stream) { - StreamHandleType type; - union { - int fd; - SSL * ssl; - } handle; -}; - -ssize_t streamRead(Stream, void *, size_t); -ssize_t streamWrite(Stream, void *, size_t); - -#endif // __STREAM_STREAM_H__ - -// vim: set ts=4 sw=4: diff --git a/src/Makefile.am b/src/Makefile.am index f25a65f..5742be5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,14 +10,11 @@ TRUTILS = utils/http.c \ TRCOMMONLIBS = cbuf/libcbuf.la \ hash/libhash.la \ queue/libqueue.la \ - logger/liblogger.la \ - tree/libtree.la \ - stream/libstream.la + tree/libtree.la TRHTTPSERVER = http/libhttp.la \ asset/libasset.la \ - server/libserver.la \ - socket/libsocket.la + server/libserver.la TR = ./application/.libs/libapplication.a \ ./user/.libs/libuser.a \ @@ -27,7 +24,7 @@ TR = ./application/.libs/libapplication.a \ ./config/.libs/libconfig.a \ ./router/.libs/librouter.a -TRLIBS = -ltrbase -ltrhashing -ltrutils -ltrhttpserver -ltrcommon +TRLIBS = -ltrbase -ltrhashing -ltrio -ltrutils -ltrhttpserver -ltrcommon USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid AM_CFLAGS += -I../include/ @@ -54,5 +51,5 @@ taskrambler_LDFLAGS = -Wl,--export-dynamic \ -Wl,--whole-archive,./application/.libs/libapplication.a,--no-whole-archive SUBDIRS = asset auth cbuf hash queue http \ - logger server session socket stream tree application \ + server session tree application \ storage user config router diff --git a/src/cbuf/read.c b/src/cbuf/read.c index 37c6ccf..acaeeac 100644 --- a/src/cbuf/read.c +++ b/src/cbuf/read.c @@ -24,12 +24,12 @@ #include #include +#include "trio.h" #include "cbuf.h" -#include "stream.h" ssize_t -cbufRead(Cbuf this, Stream st) +cbufRead(Cbuf this, TR_Stream st) { size_t rsize = cbufGetFree(this); ssize_t rrsize; @@ -39,7 +39,7 @@ cbufRead(Cbuf this, Stream st) return -1; } - rrsize = streamRead(st, cbufGetWrite(this), rsize); + rrsize = TR_streamRead(st, cbufGetWrite(this), rsize); if (0 < rrsize) { cbufIncWrite(this, rrsize); diff --git a/src/http/parser.c b/src/http/parser.c index 1dc6062..9519512 100644 --- a/src/http/parser.c +++ b/src/http/parser.c @@ -25,7 +25,7 @@ #include #include "trbase.h" -#include "stream.h" +#include "trio.h" #include "http/parser.h" #include "queue.h" #include "http/request.h" @@ -66,7 +66,7 @@ httpParserDtor(void * _this) } TR_INIT_IFACE(TR_Class, httpParserCtor, httpParserDtor, NULL); -TR_INIT_IFACE(StreamReader, httpParserParse); -TR_CREATE_CLASS(HttpParser, NULL, TR_IF(TR_Class), TR_IF(StreamReader)); +TR_INIT_IFACE(TR_StreamReader, httpParserParse); +TR_CREATE_CLASS(HttpParser, NULL, TR_IF(TR_Class), TR_IF(TR_StreamReader)); // vim: set ts=4 sw=4: diff --git a/src/http/parser/parse.c b/src/http/parser/parse.c index 4c89950..92fe153 100644 --- a/src/http/parser/parse.c +++ b/src/http/parser/parse.c @@ -23,8 +23,8 @@ #include #include "trbase.h" +#include "trio.h" #include "cbuf.h" -#include "stream.h" #include "queue.h" #include "http/parser.h" @@ -33,7 +33,7 @@ ssize_t -httpParserParse(void * _this, Stream st) +httpParserParse(void * _this, TR_Stream st) { HttpParser this = _this; int cont = 1; diff --git a/src/http/response/asset.c b/src/http/response/asset.c index 9c3cf2e..0320ea0 100644 --- a/src/http/response/asset.c +++ b/src/http/response/asset.c @@ -42,7 +42,7 @@ #include #include "trbase.h" -#include "stream.h" +#include "trio.h" #include "http/response.h" #include "http/message.h" #include "http/header.h" diff --git a/src/http/worker.c b/src/http/worker.c index bea993b..bb0b21e 100644 --- a/src/http/worker.c +++ b/src/http/worker.c @@ -31,7 +31,7 @@ #include #include "trbase.h" -#include "stream.h" +#include "trio.h" #include "hash.h" #include "queue.h" #include "http/worker.h" @@ -116,8 +116,8 @@ httpWorkerClone(void * _this, void * _base) this->writer = TR_new(HttpWriter); } -ssize_t httpWorkerProcess(void *, Stream); -ssize_t httpWorkerWrite(void *, Stream); +ssize_t httpWorkerProcess(void *, TR_Stream); +ssize_t httpWorkerWrite(void *, TR_Stream); static void @@ -158,8 +158,8 @@ httpWorkerNotify(void * _this) } TR_INIT_IFACE(TR_Class, httpWorkerCtor, httpWorkerDtor, httpWorkerClone); -TR_INIT_IFACE(StreamReader, httpWorkerProcess); -TR_INIT_IFACE(StreamWriter, httpWorkerWrite); +TR_INIT_IFACE(TR_StreamReader, httpWorkerProcess); +TR_INIT_IFACE(TR_StreamWriter, httpWorkerWrite); TR_INIT_IFACE( TR_Subject, httpWorkerAttach, @@ -169,8 +169,8 @@ TR_CREATE_CLASS( HttpWorker, NULL, TR_IF(TR_Class), - TR_IF(StreamReader), - TR_IF(StreamWriter), + TR_IF(TR_StreamReader), + TR_IF(TR_StreamWriter), TR_IF(TR_Subject)); // vim: set ts=4 sw=4: diff --git a/src/http/worker/answer.c b/src/http/worker/answer.c index 1316414..3b65b38 100644 --- a/src/http/worker/answer.c +++ b/src/http/worker/answer.c @@ -22,12 +22,12 @@ #include +#include "trio.h" #include "http/worker.h" #include "http/writer.h" -#include "stream.h" ssize_t -httpWorkerWrite(HttpWorker this, Stream st) +httpWorkerWrite(HttpWorker this, TR_Stream st) { return httpWriterWrite(this->writer, st); } diff --git a/src/http/worker/process.c b/src/http/worker/process.c index 208a153..2abbbf7 100644 --- a/src/http/worker/process.c +++ b/src/http/worker/process.c @@ -48,7 +48,7 @@ void httpWorkerAddComputedHeader(HttpWorker); extern Config config; ssize_t -httpWorkerProcess(HttpWorker this, Stream st) +httpWorkerProcess(HttpWorker this, TR_Stream st) { ssize_t requests = httpParserParse(this->parser, st); diff --git a/src/http/writer.c b/src/http/writer.c index 91a2b9b..c745de7 100644 --- a/src/http/writer.c +++ b/src/http/writer.c @@ -23,7 +23,7 @@ #include #include "trbase.h" -#include "stream.h" +#include "trio.h" #include "queue.h" #include "http/writer.h" @@ -56,7 +56,7 @@ httpWriterDtor(void * _this) } TR_INIT_IFACE(TR_Class, httpWriterCtor, httpWriterDtor, NULL); -TR_INIT_IFACE(StreamWriter, httpWriterWrite); -TR_CREATE_CLASS(HttpWriter, NULL, TR_IF(TR_Class), TR_IF(StreamWriter)); +TR_INIT_IFACE(TR_StreamWriter, httpWriterWrite); +TR_CREATE_CLASS(HttpWriter, NULL, TR_IF(TR_Class), TR_IF(TR_StreamWriter)); // vim: set ts=4 sw=4: diff --git a/src/http/writer/write.c b/src/http/writer/write.c index 93c005a..4193a83 100644 --- a/src/http/writer/write.c +++ b/src/http/writer/write.c @@ -26,13 +26,13 @@ #include #include "http/message.h" +#include "trio.h" #include "queue.h" #include "http/writer.h" -#include "stream.h" ssize_t -httpWriterWrite(void * _this, Stream st) +httpWriterWrite(void * _this, TR_Stream st) { HttpWriter this = _this; @@ -94,7 +94,7 @@ httpWriterWrite(void * _this, Stream st) to_write = (this->nheader + this->nbody) - this->written; } - written = streamWrite(st, start, to_write); + written = TR_streamWrite(st, start, to_write); if (written < 0) { return written; diff --git a/src/logger/Makefile.am b/src/logger/Makefile.am deleted file mode 100644 index 0699e88..0000000 --- a/src/logger/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = liblogger.la - -liblogger_la_SOURCES = interface/i_logger.c logger.c stderr.c syslog.c -liblogger_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/logger/interface/i_logger.c b/src/logger/interface/i_logger.c deleted file mode 100644 index 5934a26..0000000 --- a/src/logger/interface/i_logger.c +++ /dev/null @@ -1,58 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include - -#include "logger/logger.h" -#include "logger/interface/logger.h" -#include "trbase.h" - -TR_CREATE_INTERFACE(Logger, 1); - -void -loggerLog(void * _object, logger_level level, const char * const fmt, ...) { - Logger object = _object; - - if (level >= object->min_level) { - char * msg = NULL; - size_t msg_size = 0; - va_list params; - - va_start(params, fmt); - msg_size = vsnprintf(NULL, msg_size, fmt, params); - va_end(params); - - msg = TR_malloc(msg_size + 1); - - va_start(params, fmt); - vsnprintf(msg, msg_size + 1, fmt, params); - va_end(params); - - TR_CALL(_object, Logger, log, level, msg); - - TR_MEM_FREE(msg); - } -} - -// vim: set ts=4 sw=4: diff --git a/src/logger/logger.c b/src/logger/logger.c deleted file mode 100644 index 83b423a..0000000 --- a/src/logger/logger.c +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include "trbase.h" -#include "logger/logger.h" -#include "logger/interface/logger.h" - -const -char * const -logger_level_str[] = { - "DEBUG", - "INFO", - "NOTICE", - "WARNING", - "ERR", - "CRIT", - "ALERT", - "EMERG" -}; - -static -int -loggerCtor(void * _this, va_list * params) -{ - Logger this = _this; - this->min_level = va_arg(*params, int); - - return 0; -} - -static void loggerDtor(void * _this) {} - -TR_INIT_IFACE(TR_Class, loggerCtor, loggerDtor, NULL); -TR_CREATE_CLASS(Logger, NULL, TR_IF(TR_Class)); - -// vim: set ts=4 sw=4: diff --git a/src/logger/stderr.c b/src/logger/stderr.c deleted file mode 100644 index 62871d2..0000000 --- a/src/logger/stderr.c +++ /dev/null @@ -1,39 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include "trbase.h" -#include "logger/logger.h" -#include "logger/interface/logger.h" - -static -void -logStderr(void * this, logger_level level, const char * const msg) -{ - fprintf(stderr, "[%s] %s\n", logger_level_str[level], msg); -} - -TR_INIT_IFACE(Logger, logStderr); -TR_CREATE_CLASS(LoggerStderr, Logger, TR_IF(Logger)); - -// vim: set ts=4 sw=4: diff --git a/src/logger/syslog.c b/src/logger/syslog.c deleted file mode 100644 index 3706023..0000000 --- a/src/logger/syslog.c +++ /dev/null @@ -1,52 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include "trbase.h" -#include "logger/logger.h" -#include "logger/interface/logger.h" - -static -const -int syslog_priority[] = { - LOG_USER | LOG_DEBUG, - LOG_USER | LOG_INFO, - LOG_USER | LOG_NOTICE, - LOG_USER | LOG_WARNING, - LOG_USER | LOG_ERR, - LOG_USER | LOG_CRIT, - LOG_USER | LOG_ALERT, - LOG_USER | LOG_EMERG -}; - -static -void -logSyslog(void * this, logger_level level, const char * const msg) -{ - syslog(syslog_priority[level], "[%s] %s", logger_level_str[level], msg); -} - -TR_INIT_IFACE(Logger, logSyslog); -TR_CREATE_CLASS(LoggerSyslog, Logger, TR_IF(Logger)); - -// vim: set ts=4 sw=4: diff --git a/src/server/close_conn.c b/src/server/close_conn.c index b44b33f..3d2e455 100644 --- a/src/server/close_conn.c +++ b/src/server/close_conn.c @@ -24,19 +24,19 @@ #include #include "trbase.h" +#include "trio.h" #include "server.h" -#include "stream.h" void serverCloseConn(Server this, unsigned int i) { - int fd = (this->fds)[i].fd; - Stream st = (this->conns[fd]).stream; + int fd = (this->fds)[i].fd; + TR_Stream st = (this->conns[fd]).stream; TR_delete((this->conns)[fd].sock); TR_delete((this->conns)[fd].worker); - if (NULL != st && STREAM_SSL == st->type) { + if (NULL != st && TR_STREAM_SSL == st->type) { SSL_shutdown((st->handle).ssl); SSL_free((st->handle).ssl); (st->handle).ssl = NULL; diff --git a/src/server/handle_accept.c b/src/server/handle_accept.c index bc6a56e..c614263 100644 --- a/src/server/handle_accept.c +++ b/src/server/handle_accept.c @@ -27,31 +27,30 @@ #include #include "trbase.h" +#include "trio.h" #include "http/worker.h" #include "server.h" -#include "logger.h" -#include "stream.h" int serverHandleAccept(Server this, unsigned int i) { - char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - Sock acc = NULL; - Stream st; + char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + TR_Sock acc = NULL; + TR_Stream st; if (this->nfds >= this->max_fds) { return -1; } - acc = socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr); + acc = TR_socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr); if (NULL != acc && -1 != acc->handle) { - socketNonblock(acc); + TR_socketNonblock(acc); switch(i) { case 0: // no SSL - st = TR_new(Stream, STREAM_FD, acc->handle); + st = TR_new(TR_Stream, TR_STREAM_FD, acc->handle); break; case 1: @@ -60,7 +59,7 @@ serverHandleAccept(Server this, unsigned int i) SSL * ssl = SSL_new(this->ctx); SSL_set_fd(ssl, acc->handle); SSL_accept(ssl); - st = TR_new(Stream, STREAM_SSL, ssl); + st = TR_new(TR_Stream, TR_STREAM_SSL, ssl); } break; @@ -85,15 +84,15 @@ serverHandleAccept(Server this, unsigned int i) switch(errno) { case EAGAIN|EWOULDBLOCK: case EINTR: - loggerLog(this->logger, - LOGGER_DEBUG, + TR_loggerLog(this->logger, + TR_LOGGER_DEBUG, "server accept blocks"); return -1; break; default: - loggerLog(this->logger, - LOGGER_DEBUG, + TR_loggerLog(this->logger, + TR_LOGGER_DEBUG, "server accept error"); return -2; break; @@ -101,8 +100,8 @@ serverHandleAccept(Server this, unsigned int i) } if (0 == this->nfds%200) { - loggerLog(this->logger, - LOGGER_DEBUG, "paralel connections: %lu", this->nfds); + TR_loggerLog(this->logger, + TR_LOGGER_DEBUG, "paralel connections: %lu", this->nfds); } return acc->handle; diff --git a/src/server/poll.c b/src/server/poll.c index 95bec71..7a29203 100644 --- a/src/server/poll.c +++ b/src/server/poll.c @@ -24,7 +24,7 @@ #include #include "server.h" -#include "logger.h" +#include "trio.h" #include "utils/signalHandling.h" @@ -69,7 +69,7 @@ serverPoll(Server this) { // DROP THROUGH case EINTR: - loggerLog(this->logger, LOGGER_CRIT, + TR_loggerLog(this->logger, TR_LOGGER_CRIT, "poll systemcall failed: [%s] - service terminated", strerror(errno)); } diff --git a/src/server/read.c b/src/server/read.c index 3350ecc..1606265 100644 --- a/src/server/read.c +++ b/src/server/read.c @@ -23,9 +23,7 @@ #include #include "server.h" -#include "logger.h" -#include "stream.h" - +#include "trio.h" ssize_t serverRead(Server this, unsigned int i) @@ -33,14 +31,14 @@ serverRead(Server this, unsigned int i) int fd = (this->fds)[i].fd; if (NULL == (this->conns)[fd].worker) { - loggerLog( + TR_loggerLog( this->logger, - LOGGER_INFO, + TR_LOGGER_INFO, "initialization error: NULL reader"); return -2; } - return streamReaderRead( + return TR_streamReaderRead( (this->conns)[fd].worker, (this->conns)[fd].stream); } diff --git a/src/server/run.c b/src/server/run.c index 65c3311..549d4de 100644 --- a/src/server/run.c +++ b/src/server/run.c @@ -21,7 +21,7 @@ */ #include "server.h" -#include "logger.h" +#include "trio.h" #include "utils/signalHandling.h" @@ -37,7 +37,7 @@ serverRun(Server this) { int events = 0; - loggerLog(this->logger, LOGGER_INFO, "service started"); + TR_loggerLog(this->logger, TR_LOGGER_INFO, "service started"); while (!doShutdown) //! until error or signal { diff --git a/src/server/server.c b/src/server/server.c index 6e827a6..b8a3a9b 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -28,9 +28,8 @@ #include #include "trbase.h" +#include "trio.h" #include "server.h" -#include "socket.h" -#include "logger.h" void serverCloseConn(Server, unsigned int); @@ -53,24 +52,24 @@ serverCtor(void * _this, va_list * params) } this->max_fds -= 10; - this->logger = va_arg(* params, Logger); + this->logger = va_arg(* params, TR_Logger); this->worker = va_arg(* params, void *); port = va_arg(* params, int); backlog = va_arg(* params, unsigned int); - loggerLog(this->logger, - LOGGER_INFO, + TR_loggerLog(this->logger, + TR_LOGGER_INFO, "accept up to %zu connections", this->max_fds); this->fds = TR_calloc(sizeof(struct pollfd), this->max_fds); this->conns = TR_calloc(sizeof(struct conns), this->max_fds); - this->sock = TR_new(Sock, this->logger, port); - socketNonblock(this->sock); + this->sock = TR_new(TR_Sock, this->logger, port); + TR_socketNonblock(this->sock); - this->sockSSL = TR_new(Sock, this->logger, port+1); - socketNonblock(this->sockSSL); + this->sockSSL = TR_new(TR_Sock, this->logger, port+1); + TR_socketNonblock(this->sockSSL); SSL_library_init(); OpenSSL_add_all_algorithms(); @@ -89,8 +88,8 @@ serverCtor(void * _this, va_list * params) CONFIGDIR "/taskrambler.pem", SSL_FILETYPE_PEM); - socketListen(this->sock, backlog); - socketListen(this->sockSSL, backlog); + TR_socketListen(this->sock, backlog); + TR_socketListen(this->sockSSL, backlog); (this->fds)[0].fd = this->sock->handle; (this->fds)[0].events = POLLIN; diff --git a/src/server/write.c b/src/server/write.c index d28ee1a..a69842e 100644 --- a/src/server/write.c +++ b/src/server/write.c @@ -23,8 +23,7 @@ #include #include "server.h" -#include "logger.h" -#include "stream.h" +#include "trio.h" ssize_t serverWrite(Server this, unsigned int i) @@ -32,14 +31,14 @@ serverWrite(Server this, unsigned int i) int fd = (this->fds)[i].fd; if (NULL == (this->conns)[fd].worker) { - loggerLog( + TR_loggerLog( this->logger, - LOGGER_INFO, + TR_LOGGER_INFO, "initialization error: NULL worker"); return -2; } - return streamWriterWrite( + return TR_streamWriterWrite( (this->conns)[fd].worker, (this->conns)[fd].stream); } diff --git a/src/socket/Makefile.am b/src/socket/Makefile.am deleted file mode 100644 index 21c0849..0000000 --- a/src/socket/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = libsocket.la - -libsocket_la_SOURCES = socket.c accept.c connect.c listen.c nonblock.c -libsocket_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/socket/accept.c b/src/socket/accept.c deleted file mode 100644 index e554e24..0000000 --- a/src/socket/accept.c +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include // for errno -#include -#include - -#include "trbase.h" -#include "socket.h" -#include "logger.h" - -Sock -socketAccept(Sock this, char (*remoteAddr)[16]) -{ - Sock sock; // Socket for client - unsigned int len; // Length of client address data structure - - // Set the size of the in-out parameter - len = sizeof(this->addr); - - sock = TR_new(Sock, this->log, -1); - - // Wait for a client to connect - sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len); - if (-1 == sock->handle) { - loggerLog(this->log, LOGGER_WARNING, - "error accepting connection: %s", strerror(errno)); - } else { - strcpy(*remoteAddr, inet_ntoa((sock->addr).sin_addr)); - - //loggerLog(this->log, LOGGER_INFO, - // "handling client %s\n", inet_ntoa((sock->addr).sin_addr)); - } - - return sock; -} - -// vim: set ts=4 sw=4: diff --git a/src/socket/connect.c b/src/socket/connect.c deleted file mode 100644 index 9b22cfb..0000000 --- a/src/socket/connect.c +++ /dev/null @@ -1,54 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include // for atoi() and exit() -#include // for errno - -#include "socket.h" -#include "logger.h" - - -void -socketConnect(Sock this, const char * addr, char (*remoteAddr)[16]) -{ - inet_pton(AF_INET, addr, &((this->addr).sin_addr)); - (this->addr).sin_family = AF_INET; // Internet address family - (this->addr).sin_port = htons(this->port); // Local port - - if (-1 == connect( - this->handle, - (struct sockaddr*) &(this->addr), - sizeof(this->addr))) - { - loggerLog(this->log, LOGGER_CRIT, - "error connection socket: %s - service terminated", - strerror(errno)); - exit(EXIT_FAILURE); - } else { - strcpy(*remoteAddr, inet_ntoa((this->addr).sin_addr)); - - loggerLog(this->log, LOGGER_INFO, - "handling connection %s\n", inet_ntoa((this->addr).sin_addr)); - } -} - -// vim: set ts=4 sw=4: diff --git a/src/socket/listen.c b/src/socket/listen.c deleted file mode 100644 index 3790cbe..0000000 --- a/src/socket/listen.c +++ /dev/null @@ -1,59 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include // for atoi() and exit() -#include // for errno - -#include "socket.h" -#include "logger.h" - - -void -socketListen(Sock this, int backlog) -{ - (this->addr).sin_family = AF_INET; // Internet address family - (this->addr).sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface - //(this->addr).sin_addr.s_addr = inet_addr("127.0.0.1"); // Any incoming interface - (this->addr).sin_port = htons(this->port); // Local port - - /** - * Bind to the local address - */ - if (-1 == bind(this->handle, (struct sockaddr *) &(this->addr), sizeof(this->addr))) { - loggerLog(this->log, LOGGER_CRIT, - "error binding socket: %s - service terminated", - strerror(errno)); - exit(EXIT_FAILURE); - } - - /** - * Mark the socket so it will listen for incoming connections - */ - if (-1 == listen(this->handle, backlog)) { - loggerLog(this->log, LOGGER_CRIT, - "error binding socket: %s - service terminated", - strerror(errno)); - exit(EXIT_FAILURE); - } -} - -// vim: set ts=4 sw=4: diff --git a/src/socket/nonblock.c b/src/socket/nonblock.c deleted file mode 100644 index e7595a0..0000000 --- a/src/socket/nonblock.c +++ /dev/null @@ -1,37 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include // for errno -#include -#include - -#include "socket.h" -#include "logger.h" - -void -socketNonblock(Sock this) -{ - int flags = fcntl(this->handle, F_GETFL, 0); - fcntl(this->handle, F_SETFL, flags | O_NONBLOCK); -} - -// vim: set ts=4 sw=4: diff --git a/src/socket/socket.c b/src/socket/socket.c deleted file mode 100644 index d8ccba4..0000000 --- a/src/socket/socket.c +++ /dev/null @@ -1,78 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include - -#include "socket.h" -#include "logger.h" -#include "trbase.h" - -static -int -socketCtor(void * _this, va_list * params) -{ - Sock this = _this; - int reUse = 1; //! \todo make this configurable - int port; - - this->log = va_arg(* params, Logger); - port = va_arg(* params, int); - - //! if port is -1 do not initialize the socket. (Used with accept) - if (-1 == port) { - return 0; - } else { - this->port = port; - } - - //! Create socket for incoming connections - if (-1 == (this->handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))) { - loggerLog(this->log, LOGGER_CRIT, - "error opening socket: %s - service terminated", - strerror(errno)); - return -1; - } - - //! Make the socket REUSE a TIME_WAIT socket - setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof(reUse)); - - return 0; -} - -static -void -socketDtor(void * _this) -{ - Sock this = _this; - - if (STDERR_FILENO < this->handle) { - shutdown(this->handle, SHUT_RDWR); - close(this->handle); - } -} - -TR_INIT_IFACE(TR_Class, socketCtor, socketDtor, NULL); -TR_CREATE_CLASS(Sock, NULL, TR_IF(TR_Class)); - -// vim: set ts=4 sw=4: diff --git a/src/stream/Makefile.am b/src/stream/Makefile.am deleted file mode 100644 index f408675..0000000 --- a/src/stream/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -STREAM = stream.c read.c write.c -IFACE = interface/reader.c \ - interface/writer.c - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = libstream.la - -libstream_la_SOURCES = $(STREAM) $(IFACE) -libstream_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/stream/interface/reader.c b/src/stream/interface/reader.c deleted file mode 100644 index f7ead6c..0000000 --- a/src/stream/interface/reader.c +++ /dev/null @@ -1,39 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "trbase.h" -#include "stream/stream.h" -#include "stream/interface/reader.h" - -TR_CREATE_INTERFACE(StreamReader, 1); - -ssize_t -streamReaderRead(void * object, Stream st) -{ - ssize_t ret; - - TR_RETCALL(object, StreamReader, read, ret, st); - - return ret; -} - -// vim: set ts=4 sw=4: diff --git a/src/stream/interface/writer.c b/src/stream/interface/writer.c deleted file mode 100644 index 9ea7e29..0000000 --- a/src/stream/interface/writer.c +++ /dev/null @@ -1,40 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "trbase.h" -#include "stream/stream.h" -#include "stream/interface/writer.h" - -TR_CREATE_INTERFACE(StreamWriter, 1); - - -ssize_t -streamWriterWrite(void * object, Stream st) -{ - ssize_t ret; - - TR_RETCALL(object, StreamWriter, write, ret, st); - - return ret; -} - -// vim: set ts=4 sw=4: diff --git a/src/stream/read.c b/src/stream/read.c deleted file mode 100644 index 7bfbdca..0000000 --- a/src/stream/read.c +++ /dev/null @@ -1,120 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include - -#include "stream.h" -#include "logger.h" - -extern Logger logger; - - -ssize_t -streamRead(Stream this, void * buf, size_t count) -{ - ssize_t done; - - switch(this->type) { - ssize_t _read; - - case STREAM_FD: - _read = read((this->handle).fd, buf, count); - - if (_read < 0) { - switch (errno) { - case EINTR: - case ENOMEM: - done = 0; - break; - case (EAGAIN|EWOULDBLOCK): - done = -1; - break; - default: - done = -2; - break; - } - } else if (_read == 0) { - done = -2; - } else { - done = _read; - } - - break; - - case STREAM_SSL: - done = SSL_read((this->handle).ssl, buf, count); - - if (0 == done) { - done = -2; - } else if (0 > done) { - switch (SSL_get_error((this->handle).ssl, done)) { - case SSL_ERROR_SYSCALL: - { - switch (errno) { - case EINTR: - case ENOBUFS: - case ENOMEM: - done = 0; - break; - case (EAGAIN|EWOULDBLOCK): - done = -1; - break; - default: - done = -1; - break; - } - } - break; - - case SSL_ERROR_SSL: - { - unsigned long err; - - while (0 != (err = ERR_get_error())) { - loggerLog( - logger, - LOGGER_DEBUG, - ERR_error_string(err, NULL)); - } - } - // DROP THROUGH - - case SSL_ERROR_ZERO_RETURN: - done = -2; - break; - } - } - - break; - - default: - done = -2; - break; - } - - return done; -} - -// vim: set ts=4 sw=4: diff --git a/src/stream/stream.c b/src/stream/stream.c deleted file mode 100644 index 7fe0aeb..0000000 --- a/src/stream/stream.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include "trbase.h" -#include "stream/stream.h" - - -static -int -streamCtor(void * _this, va_list * params) -{ - Stream this = _this; - this->type = va_arg(* params, StreamHandleType); - - switch(this->type) { - case STREAM_FD: - (this->handle).fd = va_arg(* params, int); - break; - - case STREAM_SSL: - (this->handle).ssl = va_arg(* params, SSL*); - break; - - default: - return -1; - } - - return 0; -} - -static -void -streamDtor(void * _this) -{ -} - -TR_INIT_IFACE(TR_Class, streamCtor, streamDtor, NULL); -TR_CREATE_CLASS(Stream, NULL, TR_IF(TR_Class)); - -// vim: set ts=4 sw=4: diff --git a/src/stream/write.c b/src/stream/write.c deleted file mode 100644 index b13638f..0000000 --- a/src/stream/write.c +++ /dev/null @@ -1,124 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include - -#include "stream.h" -#include "logger.h" - -extern Logger logger; - - -ssize_t -streamWrite(Stream this, void * buf, size_t count) -{ - ssize_t done; - - switch(this->type) { - ssize_t written; - - case STREAM_FD: - written = write((this->handle).fd, buf, count); - - if (written < 0) { - switch (errno) { - case EINTR: - case ENOBUFS: - case ENOMEM: - done = 0; - break; - case (EAGAIN|EWOULDBLOCK): - done = -1; - break; - default: - done = -2; - break; - } - } else { - done = written; - } - - break; - - case STREAM_SSL: - /** - * \todo I got a segfault in this call under unclear - * circumstances. Most likely it has to do with a - * write on a closed connection. - */ - done = SSL_write((this->handle).ssl, buf, count); - - if (0 == done) { - done = -2; - } else if (0 > done) { - switch (SSL_get_error((this->handle).ssl, done)) { - case SSL_ERROR_SYSCALL: - { - switch (errno) { - case EINTR: - case ENOBUFS: - case ENOMEM: - done = 0; - break; - case (EAGAIN|EWOULDBLOCK): - done = -1; - break; - default: - done = -2; - break; - } - } - break; - - case SSL_ERROR_SSL: - { - unsigned long err; - - while (0 != (err = ERR_get_error())) { - loggerLog( - logger, - LOGGER_DEBUG, - ERR_error_string(err, NULL)); - } - } - // DROP THROUGH - - case SSL_ERROR_ZERO_RETURN: - done = -2; - break; - } - } - - break; - - default: - done = -2; - break; - } - - return done; -} - -// vim: set ts=4 sw=4: diff --git a/src/taskrambler.c b/src/taskrambler.c index 3170917..09ad37e 100644 --- a/src/taskrambler.c +++ b/src/taskrambler.c @@ -38,9 +38,9 @@ #include #include +#include #include "server.h" -#include "logger.h" #include "http/worker.h" #include "auth.h" #include "application/application.h" @@ -48,8 +48,6 @@ #include "config/config.h" #include "config/value.h" -#include "logger.h" - #include "utils/signalHandling.h" #include "utils/mime_type.h" @@ -63,8 +61,8 @@ void nullhandler() {} void daemonize(void); -Logger logger; -Config config; +TR_Logger logger; +Config config; int main() @@ -77,15 +75,15 @@ main() int shm; struct randval * value; - logger = TR_new(LoggerSyslog, LOGGER_DEBUG); + logger = TR_new(TR_LoggerSyslog, TR_LOGGER_DEBUG); config = TR_new(Config, CONFIGDIR "/taskrambler.conf"); if (NULL == config) { - loggerLog(logger, LOGGER_INFO, + TR_loggerLog(logger, TR_LOGGER_INFO, "unable to load configuration file: %s\n", CONFIGDIR "/taskrambler.conf"); - if (! TR_INSTANCE_OF(LoggerStderr, logger)) { + if (! TR_INSTANCE_OF(TR_LoggerStderr, logger)) { fprintf(stderr, "unable to load configuration file: %s\n", CONFIGDIR "/taskrambler.conf"); @@ -255,19 +253,19 @@ main() if (0 < w) { if (WIFEXITED(status)) { - loggerLog(logger, LOGGER_INFO, + TR_loggerLog(logger, TR_LOGGER_INFO, "child exited, status=%d\n", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { - loggerLog(logger, LOGGER_INFO, + TR_loggerLog(logger, TR_LOGGER_INFO, "killed by signal %d\n", WTERMSIG(status)); } else if (WIFSTOPPED(status)) { - loggerLog(logger, LOGGER_INFO, + TR_loggerLog(logger, TR_LOGGER_INFO, "stopped by signal %d\n", WSTOPSIG(status)); } else if (WIFCONTINUED(status)) { - loggerLog(logger, LOGGER_INFO, "continued\n"); + TR_loggerLog(logger, TR_LOGGER_INFO, "continued\n"); } } } while (!WIFEXITED(status) && !WIFSIGNALED(status)); diff --git a/tests/mock/mock_worker.c b/tests/mock/mock_worker.c index b051e4b..1d94bd1 100644 --- a/tests/mock/mock_worker.c +++ b/tests/mock/mock_worker.c @@ -38,7 +38,7 @@ mockWorkerClone(void * _this, void * _base) static ssize_t -mockWorkerRead(void * _this, Stream st) +mockWorkerRead(void * _this, TR_Stream st) { MockWorker this = _this; size_t size; @@ -50,19 +50,19 @@ mockWorkerRead(void * _this, Stream st) static ssize_t -mockWorkerWrite(void * _this, Stream st) +mockWorkerWrite(void * _this, TR_Stream st) { return 0; } INIT_IFACE(Class, mockWorkerCtor, mockWorkerDtor, mockWorkerClone); -INIT_IFACE(StreamReader, mockWorkerRead); -INIT_IFACE(StreamWriter, mockWorkerWrite); +INIT_IFACE(TR_StreamReader, mockWorkerRead); +INIT_IFACE(TR_StreamWriter, mockWorkerWrite); CREATE_CLASS( MockWorker, NULL, IFACE(Class), - IFACE(StreamReader), - IFACE(StreamWriter)); + IFACE(TR_StreamReader), + IFACE(TR_StreamWriter)); // vim: set ts=4 sw=4: diff --git a/tests/socketTest.c b/tests/socketTest.c index f1c6d56..0595cb1 100644 --- a/tests/socketTest.c +++ b/tests/socketTest.c @@ -5,7 +5,7 @@ #include "runtest.h" #include "class.h" #include "socket.h" -#include "logger.h" +#include "trio.h" #include "mock/mock_logger.h"