Browse Source

some code cleanups...no changes in the logic

master
Georg Hopp 14 years ago
parent
commit
7f688412ea
  1. 6
      ChangeLog
  2. 8
      include/hash.h
  3. 1
      include/server.h
  4. 31
      include/utils/hash.h
  5. 28
      include/utils/memory.h
  6. 6
      include/utils/signalHandling.h
  7. 6
      src/Makefile.am
  8. 4
      src/http/header.c
  9. 3
      src/http/header/add.c
  10. 2
      src/http/header/get.c
  11. 14
      src/http/message.c
  12. 6
      src/http/request.c
  13. 3
      src/http/request/parser.c
  14. 10
      src/http/request/parser/get_header.c
  15. 3
      src/http/request/parser/get_request_line.c
  16. 3
      src/http/request/parser/parse.c
  17. 4
      src/http/response.c
  18. 2
      src/http/response/304.c
  19. 2
      src/http/response/image.c
  20. 3
      src/http/response/writer.c
  21. 5
      src/http/response/writer/write.c
  22. 4
      src/server.c
  23. 16
      src/server/handle_accept.c
  24. 6
      src/server/poll.c
  25. 5
      src/server/read.c
  26. 14
      src/server/run.c
  27. 4
      src/testserver.c
  28. 0
      src/utils/daemonize.c
  29. 2
      src/utils/hash.c
  30. 14
      src/utils/memory.c
  31. 0
      src/utils/signalHandling.c

6
ChangeLog

@ -1,6 +1,10 @@
2012-02-20 21:36:55 +0100 Georg Hopp
* some code cleanups...no changes in the logic (HEAD, master)
2012-02-20 18:08:23 +0100 Georg Hopp
* move sdbm implementation in one file. (HEAD, master)
* move sdbm implementation in one file.
2012-02-20 17:16:44 +0100 Georg Hopp

8
include/hash.h

@ -1,8 +0,0 @@
#ifndef __HASH_H__
#define __HASH_H__
unsigned long sdbm(const unsigned char *);
#endif // __HASH_H__
// vim: set ts=4 sw=4:

1
include/server.h

@ -63,7 +63,6 @@ CLASS(Server) {
};
void serverRun(Server this);
void serverCloseConn(Server this, unsigned int handle);
#endif // __SERVER_H__

31
src/http/message/helper.c → include/utils/hash.h

@ -1,5 +1,6 @@
/**
* \file
* Functions to handle varios signals send to the application.
*
* \author Georg Hopp
*
@ -20,33 +21,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __HTTP_MESSAGE_HELPER_C__
#define __HTTP_MESSAGE_HELPER_C__
#ifndef __UTILS_HASH_H__
#define __UTILS_HASH_H__
#include <stdlib.h>
unsigned long sdbm(const unsigned char *);
#include "class.h"
#include "interface/class.h"
static
inline
void
_free(void ** data)
{
if (NULL != *data) {
free(*data);
}
}
static
inline
void
tDelete(void * node)
{
delete(&node);
}
#endif // __HTTP_MESSAGE_HELPER_C__
#endif // __UTILS_HASH_H__
// vim: set ts=4 sw=4:

28
include/utils/memory.h

@ -0,0 +1,28 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright (C) 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __UTILS_MEMORY_H__
#define __UTILS_MEMORY_H__
void ffree(void **);
#endif // __UTILS_MEMORY_H__

6
include/signalHandling.h → include/utils/signalHandling.h

@ -21,13 +21,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SIGNAL_HANDLING_H__
#define __SIGNAL_HANDLING_H__
#ifndef __UTILS_SIGNAL_HANDLING_H__
#define __UTILS_SIGNAL_HANDLING_H__
extern volatile int doShutdown;
void terminate(int signum);
void init_signals(void);
#endif // __SIGNAL_HANDLING_H__
#endif // __UTILS_SIGNAL_HANDLING_H__

6
src/Makefile.am

@ -7,7 +7,8 @@ IFACE = interface/class.c interface/stream_reader.c interface/logger.c \
CLASS = class.c interface.c
RB = ringbuffer.c ringbuffer/rb_read.c
SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c
SERVER = server.c server/run.c server/close_conn.c
SERVER = server.c server/run.c server/close_conn.c server/poll.c \
server/handle_accept.c server/read.c
LOGGER = logger.c logger/stderr.c logger/syslog.c
CB = cbuf.c cbuf/read.c cbuf/write.c \
cbuf/get_line.c cbuf/set_data.c cbuf/get_data.c \
@ -31,6 +32,7 @@ HEADER = http/header.c http/header/get.c http/header/add.c \
PARSER = http/request/parser.c http/request/parser/get_header.c \
http/request/parser/parse.c http/request/parser/get_request_line.c \
http/request/parser/get_body.c
UTILS = utils/hash.c utils/memory.c utils/daemonize.c utils/signalHandling.c
AM_CFLAGS = -Wall -I ../include/
@ -40,6 +42,6 @@ bin_PROGRAMS = testserver
testserver_SOURCES = testserver.c \
$(IFACE) $(CLASS) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \
$(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \
signalHandling.c daemonize.c hash.c
$(UTILS)
testserver_CFLAGS = -Wall -I ../include/
testserver_LDFLAGS = -lrt

4
src/http/header.c

@ -24,12 +24,12 @@
#include <stdlib.h>
#include <string.h>
#include "hash.h"
#include "class.h"
#include "interface/class.h"
#include "http/header.h"
#include "utils/hash.h"
static
void
ctor(void * _this, va_list * params) {

3
src/http/header/add.c

@ -21,13 +21,12 @@
*/
#include <search.h>
#include <stdlib.h>
#include <stdio.h>
#include "hash.h"
#include "class.h"
#include "interface/class.h"
#include "http/header.h"
#include "utils/hash.h"
static
inline

2
src/http/header/get.c

@ -25,8 +25,8 @@
#include <search.h>
#include <stdlib.h>
#include "hash.h"
#include "http/header.h"
#include "utils/hash.h"
static
inline

14
src/http/message.c

@ -34,9 +34,17 @@
#include "interface/class.h"
#include "http/message.h"
#include "message/helper.c"
#include "utils/memory.h"
static
inline
void
tDelete(void * node)
{
delete(&node);
}
static
void
ctor(void * _this, va_list * params)
@ -54,7 +62,7 @@ dtor(void * _this)
{
HttpMessage this = _this;
_free((void **)&(this->version));
ffree((void **)&(this->version));
/**
* this is a GNU extension...anyway on most non
@ -65,7 +73,7 @@ dtor(void * _this)
switch (this->type) {
case HTTP_MESSAGE_BUFFERED:
_free((void **)&(this->body));
ffree((void **)&(this->body));
break;
case HTTP_MESSAGE_PIPED:

6
src/http/request.c

@ -30,7 +30,7 @@
#include "interface/http_intro.h"
#include "http/request.h"
#include "message/helper.c"
#include "utils/memory.h"
static
@ -43,8 +43,8 @@ dtor(void * _this)
{
HttpRequest this = _this;
_free((void **)&(this->uri));
_free((void **)&(this->method));
ffree((void **)&(this->uri));
ffree((void **)&(this->method));
PARENTCALL(_this, Class, dtor);
}

3
src/http/request/parser.c

@ -20,10 +20,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <stdarg.h>
#include "class.h"
#include "interface/class.h"

10
src/http/request/parser/get_header.c

@ -20,9 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "class.h"
#include "interface/class.h"
@ -31,8 +29,8 @@
#include "http/request/parser.h"
#include "ringbuffer.h"
ssize_t
httpRequestParserGetHeader(HttpRequestParser this, char * cr)
void
httpRequestParserGetHeader(HttpMessage message, char * line)
{
HttpMessage message = (HttpMessage)this->cur_request;
char * value;
@ -53,7 +51,7 @@ httpRequestParserGetHeader(HttpRequestParser this, char * cr)
httpHeaderAdd(&(message->header), new(HttpHeader, name, value));
return 1; //* @TODO: return something useful here
httpHeaderAdd(&(message->header), new(HttpHeader, name, value));
}
// vim: set ts=4 sw=4:

3
src/http/request/parser/get_request_line.c

@ -25,8 +25,7 @@
#include "http/message.h"
#include "http/request.h"
#include "http/request/parser.h"
#include "ringbuffer.h"
#include "http/message.h"
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MIN(x,y) ((x) < (y) ? (x) : (y))

3
src/http/request/parser/parse.c

@ -21,9 +21,6 @@
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include "http/request.h"
#include "http/message.h"

4
src/http/response.c

@ -31,7 +31,7 @@
#include "interface/http_intro.h"
#include "http/response.h"
#include "message/helper.c"
#include "utils/memory.h"
static
@ -56,7 +56,7 @@ dtor(void * _this)
{
HttpResponse this = _this;
_free((void **)&(this->reason));
ffree((void **)&(this->reason));
PARENTCALL(_this, Class, dtor);
}

2
src/http/response/304.c

@ -20,8 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/stat.h>

2
src/http/response/image.c

@ -20,8 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>

3
src/http/response/writer.c

@ -20,8 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "class.h"
#include "interface/class.h"

5
src/http/response/writer/write.c

@ -20,13 +20,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "class.h"
#include "interface/class.h"

4
src/server.c

@ -20,10 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <poll.h> /* for select system call and related */
#include <string.h> /* for memset and stuff */
#include <stdlib.h> /* for getopt */
#include <unistd.h>
#include <fcntl.h>
#include "class.h"

16
src/server/handle_accept.c

@ -25,11 +25,10 @@
#include <stdlib.h>
#include "http/worker.h"
#include "server.h"
#include "interface/class.h"
#include "interface/logger.h"
#include "http/worker.h"
static
int
serverHandleAccept(Server this)
{
@ -45,15 +44,6 @@ serverHandleAccept(Server this)
// clone worker
(this->conns)[acc->handle].worker = clone(this->worker);
/**
* \todo
* set worker id---this would better be accomplished
* as a worker method.
* The same is true for server information stuff only
* that this should become an interface.
* At a second thought both has to be an interface.
*/
(this->fds)[this->nfds].fd = acc->handle;
(this->fds)[this->nfds].events = POLLIN;
this->nfds++;

6
src/server/poll.c

@ -23,10 +23,14 @@
#include <poll.h>
#include <errno.h>
#include "server.h"
#include "interface/logger.h"
#include "utils/signalHandling.h"
#define POLLFD(ptr) ((struct pollfd *)(ptr))
#define SWAP(a, b) ((a)^=(b),(b)^=(a),(a)^=(b))
static
int
serverPoll(Server this) {
int events;

5
src/server/read.c

@ -20,7 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
static
#include "server.h"
#include "interface/logger.h"
#include "interface/stream_reader.h"
ssize_t
serverRead(Server this, unsigned int i)
{

14
src/server/run.c

@ -21,20 +21,18 @@
*/
#include "server.h"
#include "socket.h"
#include "logger.h"
#include "signalHandling.h"
#include "interface/class.h"
#include "interface/stream_reader.h"
#include "interface/stream_writer.h"
#include "interface/logger.h"
#include "utils/signalHandling.h"
#undef MAX
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#include "poll.c"
#include "handle_accept.c"
#include "read.c"
int serverPoll(Server);
int serverHandleAccept(Server);
void serverCloseConn(Server, unsigned int);
ssize_t serverRead(Server, unsigned int);
void
serverRun(Server this)

4
src/testserver.c

@ -31,10 +31,10 @@
#include "logger.h"
#include "http/worker.h"
#include "signalHandling.h"
#include "interface/class.h"
#include "utils/signalHandling.h"
void daemonize(void);
int

0
src/daemonize.c → src/utils/daemonize.c

2
src/hash.c → src/utils/hash.c

@ -1,6 +1,6 @@
#include <ctype.h>
#include "hash.h"
#include "utils/hash.h"
/**
* SDBM hashing algorithm:

14
src/utils/memory.c

@ -0,0 +1,14 @@
#include <stdlib.h>
#include "utils/memory.h"
void
ffree(void ** data)
{
if (NULL != *data) {
free(*data);
*data = NULL;
}
}
// vim: set ts=4 sw=4:

0
src/signalHandling.c → src/utils/signalHandling.c

Loading…
Cancel
Save