Browse Source

Added a new abstraction: hash. A a lot of things within http are key/value things based on stings i created this generic hash class and use it to store the header right now. In future it will also be used to store cookie, get and post vars

master
Georg Hopp 14 years ago
parent
commit
646d1e1c50
  1. 20
      include/hash.h
  2. 2
      include/http/header.h
  3. 4
      include/http/message.h
  4. 38
      include/interface/hashable.h
  5. 10
      src/Makefile.am
  6. 42
      src/hash.c
  7. 32
      src/hash/add.c
  8. 25
      src/hash/delete.c
  9. 25
      src/hash/each.c
  10. 25
      src/hash/get.c
  11. 31
      src/http/header.c
  12. 69
      src/http/header/add.c
  13. 20
      src/http/message.c
  14. 3
      src/http/message/has_keep_alive.c
  15. 9
      src/http/message/header_size_get.c
  16. 11
      src/http/message/header_to_string.c
  17. 4
      src/http/parser/header.c
  18. 7
      src/http/response/304.c
  19. 3
      src/http/response/404.c
  20. 8
      src/http/response/asset.c
  21. 3
      src/http/response/login_form.c
  22. 116
      src/http/response/me.c
  23. 3
      src/http/response/randval.c
  24. 3
      src/http/response/session.c
  25. 14
      src/http/worker/add_common_header.c
  26. 5
      src/http/worker/get_asset.c
  27. 9
      src/http/worker/process.c
  28. 51
      src/interface/hashable.c

20
include/hash.h

@ -0,0 +1,20 @@
#ifndef __HASH_H__
#define __HASH_H__
#include <sys/types.h>
#include "class.h"
CLASS(Hash) {
void * root;
};
void * hashAdd(Hash, void *);
void * hashDelete(Hash, const char *, size_t);
void * hashGet(Hash, const char *, size_t);
void hashEach(Hash, void (*)(const void*));
#endif // __HASH_H__
// vim: set ts=4 sw=4:

2
include/http/header.h

@ -41,8 +41,6 @@ CLASS(HttpHeader) {
size_t size; //!< full size of this header
};
HttpHeader httpHeaderAdd(const HttpHeader *, HttpHeader);
HttpHeader httpHeaderGet(const HttpHeader *, const char *, size_t);
size_t httpHeaderToString(HttpHeader, char *);
#endif // __HTTP_HEADER_H__

4
include/http/message.h

@ -25,7 +25,7 @@
#define __HTTP_MESSAGE__
#include "class.h"
#include "http/header.h"
#include "hash.h"
#include "stream.h"
typedef enum e_HttpMessageType {
@ -37,7 +37,7 @@ typedef enum e_HttpMessageType {
CLASS(HttpMessage) {
char * version;
HttpHeader header;
Hash header;
HttpMessageType type;
Stream handle;

38
src/http/header/get.c → include/interface/hashable.h

@ -1,7 +1,6 @@
/**
* \file
* Get a header from a tree containing headers by its name.
* The key for the tree is the hased lowercase header identifier.
* The logger interface.
*
* \author Georg Hopp
*
@ -22,30 +21,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <search.h>
#include <stdlib.h>
#ifndef __INTERFACE_HASHABLE_H__
#define __INTERFACE_HASHABLE_H__
#include "http/header.h"
#include "utils/hash.h"
#include "interface.h"
static
inline
int
comp(const void * _a, const void * _b)
{
const unsigned long * a = _a;
HttpHeader b = (HttpHeader)_b;
return (*a < b->hash)? -1 : (*a > b->hash)? 1 : 0;
}
typedef unsigned long (* fptr_hashableGetHash)(void *);
typedef void (* fptr_hashableHandleDouble)(void *, void *);
HttpHeader
httpHeaderGet(const HttpHeader * root, const char * name, size_t nname)
{
unsigned long hash = sdbm((const unsigned char*)name, nname);
extern const struct interface i_Hashable;
HttpHeader * found = tfind(&hash, (void**)root, comp);
struct i_Hashable {
const struct interface * const _;
fptr_hashableGetHash getHash;
fptr_hashableHandleDouble handleDouble;
};
return (NULL != found)? *found : NULL;
}
extern unsigned long hashableGetHash(void *);
extern void hashableHandleDouble(void *, void *);
#endif // __INTERFACE_HASHABLE_H__
// vim: set ts=4 sw=4:

10
src/Makefile.am

@ -6,6 +6,12 @@ IFACE = interface/class.c interface/stream_reader.c interface/logger.c \
interface/subject.c interface/observer.c interface.c
SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c
STREAM = stream.c stream/read.c stream/write.c
HASH = hash.c \
hash/add.c \
hash/get.c \
hash/delete.c \
hash/each.c \
interface/hashable.c
SERVER = server.c server/run.c server/close_conn.c server/poll.c \
server/handle_accept.c server/read.c server/write.c
LOGGER = logger.c logger/stderr.c logger/syslog.c
@ -44,7 +50,7 @@ WORKER = http/worker.c \
http/worker/write.c \
http/worker/get_asset.c \
http/worker/add_common_header.c
HEADER = http/header.c http/header/get.c http/header/add.c \
HEADER = http/header.c \
http/header/to_string.c
SESSION = session.c session/add.c session/get.c session/delete.c
UTILS = utils/hash.c \
@ -61,6 +67,6 @@ bin_PROGRAMS = webgameserver
webgameserver_SOURCES = webgameserver.c \
$(IFACE) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \
$(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \
$(UTILS) $(MSGQ) $(SESSION) $(STREAM)
$(UTILS) $(MSGQ) $(SESSION) $(STREAM) $(HASH)
webgameserver_CFLAGS = -Wall -I ../include/
webgameserver_LDFLAGS = -lrt -lssl

42
src/hash.c

@ -0,0 +1,42 @@
#define _GNU_SOURCE
#include <search.h>
#include <stdarg.h>
#include "hash.h"
#include "class.h"
#include "interface/class.h"
static
int
hashCtor(void * _this, va_list * params)
{
return 0;
}
static
inline
void
tDelete(void * node)
{
delete(node);
}
static
void
hashDtor(void * _this)
{
Hash this = _this;
/**
* this is a GNU extension...anyway on most non
* GNUish systems i would not use tsearch anyway
* as the trees will be unbalanced.
*/
tdestroy(this->root, tDelete);
}
INIT_IFACE(Class, hashCtor, hashDtor, NULL);
CREATE_CLASS(Hash, NULL, IFACE(Class));
// vim: set ts=4 sw=4:

32
src/hash/add.c

@ -0,0 +1,32 @@
#include <search.h>
#include "hash.h"
#include "interface/hashable.h"
#include "interface/class.h"
static
inline
int
hashAddComp(const void * a, const void * b)
{
return hashableGetHash((void*)b) - hashableGetHash((void*)a);
}
void *
hashAdd(Hash this, void * operand)
{
void * found = tsearch(operand, &(this->root), hashAddComp);
if (NULL == found) {
return NULL;
}
if (operand != *(void**)found) {
hashableHandleDouble(*(void**)found, operand);
delete(operand);
}
return *(void**)found;
}
// vim: set ts=4 sw=4:

25
src/hash/delete.c

@ -0,0 +1,25 @@
#include <search.h>
#include <sys/types.h>
#include "hash.h"
#include "interface/hashable.h"
#include "utils/hash.h"
static
inline
int
hashDeleteComp(const void * a, const void * b)
{
return hashableGetHash((void*)b) - *(const unsigned long*)a;
}
void *
hashDelete(Hash this, const char * search, size_t nsearch)
{
unsigned long hash = sdbm((const unsigned char *)search, nsearch);
void * found = tfind(&hash, &(this->root), hashDeleteComp);
return (NULL != found)? *(void**)found : NULL;
}
// vim: set ts=4 sw=4:

25
src/hash/each.c

@ -0,0 +1,25 @@
#include <search.h>
#include "hash.h"
static void (*cb)(void*);
static
inline
void
walk(const void * node, const VISIT which, const int depth)
{
if (endorder == which || leaf == which) {
cb(*(void**)node);
}
}
void
hashEach(Hash this, void (*callback)(const void*))
{
cb = callback;
twalk(this->root, walk);
}
// vim: set ts=4 sw=4:

25
src/hash/get.c

@ -0,0 +1,25 @@
#include <search.h>
#include <sys/types.h>
#include "hash.h"
#include "interface/hashable.h"
#include "utils/hash.h"
static
inline
int
hashGetComp(const void * a, const void * b)
{
return hashableGetHash((void*)b) - *(const unsigned long*)a;
}
void *
hashGet(Hash this, const char * search, size_t nsearch)
{
unsigned long hash = sdbm((const unsigned char *)search, nsearch);
void * found = tfind(&hash, &(this->root), hashGetComp);
return (NULL != found)? *(void**)found : NULL;
}
// vim: set ts=4 sw=4:

31
src/http/header.c

@ -27,6 +27,7 @@
#include "class.h"
#include "interface/class.h"
#include "http/header.h"
#include "interface/hashable.h"
#include "utils/hash.h"
#include "utils/memory.h"
@ -72,7 +73,35 @@ httpHeaderDtor(void * _this)
}
}
static
unsigned long
httpHeaderGetHash(void * _this)
{
HttpHeader this = _this;
return this->hash;
}
static
void
httpHeaderHandleDouble(void * _this, void * _double)
{
HttpHeader this = _this;
HttpHeader doub = _double;
if (this->cvalue >= N_VALUES) {
//! \todo do dome error logging...or change to HEAP
return;
}
(this->nvalue)[this->cvalue] = (doub->nvalue)[0];
(this->value)[(this->cvalue)++] = (doub->value)[0];
this->size += doub->size;
(doub->value)[0] = NULL;
}
INIT_IFACE(Class, httpHeaderCtor, httpHeaderDtor, NULL);
CREATE_CLASS(HttpHeader, NULL, IFACE(Class));
INIT_IFACE(Hashable, httpHeaderGetHash, httpHeaderHandleDouble);
CREATE_CLASS(HttpHeader, NULL, IFACE(Class), IFACE(Hashable));
// vim: set ts=4 sw=4:

69
src/http/header/add.c

@ -1,69 +0,0 @@
/**
* \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/>.
*/
#include <search.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "class.h"
#include "interface/class.h"
#include "http/header.h"
#include "utils/hash.h"
static
inline
int
comp(const void * _a, const void * _b)
{
HttpHeader a = (HttpHeader)_a;
HttpHeader b = (HttpHeader)_b;
return (a->hash < b->hash)? -1 : (a->hash > b->hash)? 1 : 0;
}
HttpHeader
httpHeaderAdd(const HttpHeader * root, HttpHeader header)
{
HttpHeader * _found = tsearch(header, (void **)root, comp);
HttpHeader found;
if (NULL == _found) {
return NULL;
}
found = *_found;
if (found != header) {
if (found->cvalue >= N_VALUES) {
return NULL;
}
(found->nvalue)[found->cvalue] = (header->nvalue)[0];
(found->value)[(found->cvalue)++] = (header->value)[0];
found->size += header->size;
(header->value)[0] = NULL;
delete(header);
}
return found;
}
// vim: set ts=4 sw=4:

20
src/http/message.c

@ -32,19 +32,11 @@
#include "class.h"
#include "interface/class.h"
#include "hash.h"
#include "http/message.h"
#include "utils/memory.h"
static
inline
void
tDelete(void * node)
{
delete(node);
}
static
int
httpMessageCtor(void * _this, va_list * params)
@ -55,6 +47,8 @@ httpMessageCtor(void * _this, va_list * params)
this->version = calloc(1, strlen(version)+1);
strcpy(this->version, version);
this->header = new(Hash);
return 0;
}
@ -64,15 +58,9 @@ httpMessageDtor(void * _this)
{
HttpMessage this = _this;
delete(this->header);
FREE(this->version);
/**
* this is a GNU extension...anyway on most non
* GNUish systems i would not use tsearch anyway
* as the trees will be unbalanced.
*/
tdestroy(this->header, tDelete);
switch (this->type) {
case HTTP_MESSAGE_BUFFERED:
FREE(this->body);

3
src/http/message/has_keep_alive.c

@ -31,6 +31,7 @@
#include "utils/memory.h"
#include "commons.h"
#include "hash.h"
char
httpMessageHasKeepAlive(HttpMessage message)
@ -39,7 +40,7 @@ httpMessageHasKeepAlive(HttpMessage message)
size_t size;
char * value;
header = httpHeaderGet(&(message->header), CSTRA("connection"));
header = hashGet(message->header, CSTRA("connection"));
if (NULL == header) {
return 0;

9
src/http/message/header_size_get.c

@ -28,17 +28,16 @@
#include "http/response.h"
#include "http/header.h"
#include "interface/http_intro.h"
#include "hash.h"
static size_t size;
static
inline
void
addHeaderSize(const void * node, const VISIT which, const int depth)
addHeaderSize(const void * node)
{
if (endorder == which || leaf == which) {
size += (*(HttpHeader *)node)->size;
}
size += ((HttpHeader)node)->size;
}
size_t
@ -46,7 +45,7 @@ httpMessageHeaderSizeGet(HttpMessage message)
{
size = httpIntroSizeGet(message);
twalk(message->header, addHeaderSize);
hashEach(message->header, addHeaderSize);
size += 2;
return size;

11
src/http/message/header_to_string.c

@ -27,15 +27,16 @@
#include "http/response.h"
#include "http/header.h"
#include "interface/http_intro.h"
#include "hash.h"
static char * string;
static
inline
void
addHeaderString(const void * node, const VISIT which, const int depth)
addHeaderString(const void * node)
{
if (endorder == which || leaf == which) {
string += httpHeaderToString(*(HttpHeader *)node, string);
}
string += httpHeaderToString((HttpHeader)node, string);
}
char *
@ -45,7 +46,7 @@ httpMessageHeaderToString(HttpMessage response, char * _string)
string = httpIntroToString(response, _string);
twalk(message->header, addHeaderString);
hashEach(message->header, addHeaderString);
*string++ = '\r';
*string++ = '\n';

4
src/http/parser/header.c

@ -29,6 +29,7 @@
#include "http/header.h"
#include "http/parser.h"
#include "http/message.h"
#include "hash.h"
#define MAX(x,y) ((x) > (y) ? (x) : (y))
@ -66,8 +67,7 @@ httpParserHeader(
current->dbody = 0;
}
httpHeaderAdd(
&(current->header),
hashAdd(current->header,
new(HttpHeader, name, nname, value, lend - value));
}

7
src/http/response/304.c

@ -30,6 +30,7 @@
#include "http/header.h"
#include "utils/memory.h"
#include "hash.h"
HttpResponse
httpResponse304(
@ -47,11 +48,11 @@ httpResponse304(
message->nbody = 0;
message->body = NULL;
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), mime, nmime));
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("ETag"), etag, netag));
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime));
return response;

3
src/http/response/404.c

@ -33,6 +33,7 @@
#include "http/header.h"
#include "utils/memory.h"
#include "hash.h"
#define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \
@ -52,7 +53,7 @@ httpResponse404()
response = new(HttpResponse, "HTTP/1.1", 404, "Not Found");
message = (HttpMessage)response;
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
message->type = HTTP_MESSAGE_BUFFERED;

8
src/http/response/asset.c

@ -35,7 +35,7 @@
#include "http/header.h"
#include "utils/memory.h"
#include "hash.h"
HttpResponse
httpResponseAsset(
@ -73,11 +73,11 @@ httpResponseAsset(
message->handle = new(Stream, STREAM_FD, handle);
message->nbody = st.st_size;
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), mime, nmime));
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("ETag"), etag, netag));
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime));
return response;

3
src/http/response/login_form.c

@ -34,6 +34,7 @@
#include "http/header.h"
#include "utils/memory.h"
#include "hash.h"
#define RESP_DATA "<form action=\"/me/\" method=\"POST\">" \
"<input name=\"username\" type=\"text\" />" \
@ -49,7 +50,7 @@ httpResponseLoginForm()
response = new(HttpResponse, "HTTP/1.1", 200, "OK");
message = (HttpMessage)response;
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
message->type = HTTP_MESSAGE_BUFFERED;

116
src/http/response/me.c

@ -1,116 +0,0 @@
/**
* \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/>.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include "class.h"
#include "interface/class.h"
#include "http/response.h"
#include "http/message.h"
#include "http/header.h"
#include "utils/memory.h"
#define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" \
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" \
"<head>" \
"<title>My own little Web-App</title>" \
"<style type=\"text/css\">" \
"div#randval {" \
"left: 200px;" \
"top: 100px;" \
"position: fixed;" \
"background-color: white;" \
"border: 1px solid black;" \
"}" \
"div.hide#randval {" \
"top: -500px;" \
"}" \
".small {" \
"font-size: small;" \
"}" \
"</style>" \
"<script type=\"text/javascript\" src=\"/assets/js/jquery\"></script>" \
"<script type=\"text/javascript\" src=\"/assets/js/serverval\"></script>" \
"<script>" \
"$(document).ready(function() {" \
"var sval = new ServerVal(\"#randval\");" \
"$(\"a\").click(function() {" \
"sval.start();" \
"});" \
"});" \
"</script>" \
"</head>" \
"<body>"
"<ul id=\"menu\">" \
"<li>serverval</li>" \
"</ul>" \
"<div id=\"randval\" class=\"hide\">" \
"<span class=\"small\">" \
"Value created at: <br /><span></span><br>" \
"Next value in: <span></span><br />" \
"</span>" \
"Value: <span></span>" \
"</div>" \
"<div id=\"main\">" \
"<h1>Testpage</h1>" \
"Welcome %s<br />" \
"<img src=\"/image/\" />" \
"</div>" \
"<hr /><div id=\"msg\"></div>" \
"</body>" \
"</html>"
HttpResponse
httpResponseMe(char * uname)
{
HttpResponse response;
HttpMessage message;
response = new(HttpResponse, "HTTP/1.1", 200, "OK");
message = (HttpMessage)response;
httpHeaderAdd(&(message->header),
new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
httpHeaderAdd(&(message->header),
new(HttpHeader, CSTRA("Set-Cookie"), CSTRA("name=Georg+Hopp")));
httpHeaderAdd(&(message->header),
new(HttpHeader, CSTRA("Set-Cookie"), CSTRA("profession=coder")));
message->type = HTTP_MESSAGE_BUFFERED;
message->nbody = sizeof(RESP_DATA)-1-2+strlen(uname); //!< the two are the %s
message->body = malloc(message->nbody+1);
sprintf(message->body, RESP_DATA, uname);
//memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)-1);
return response;
}
// vim: set ts=4 sw=4:

3
src/http/response/randval.c

@ -34,6 +34,7 @@
#include "http/header.h"
#include "utils/memory.h"
#include "hash.h"
#define RESP_DATA "{\"ctime\":%ld,\"vnext\":%ld,\"value\":\"%02d\"}"
@ -49,7 +50,7 @@ httpResponseRandval(time_t ctime, int value)
response = new(HttpResponse, "HTTP/1.1", 200, "OK");
message = (HttpMessage)response;
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), CSTRA("application/json")));
message->type = HTTP_MESSAGE_BUFFERED;

3
src/http/response/session.c

@ -35,6 +35,7 @@
#include "session.h"
#include "utils/memory.h"
#include "hash.h"
#define RESP_DATA "{\"id\":\"%lu\",\"timeout\":%d,\"timeleft\":%ld,\"username\":\"%s\"}"
@ -49,7 +50,7 @@ httpResponseSession(Session session)
response = new(HttpResponse, "HTTP/1.1", 200, "OK");
message = (HttpMessage)response;
httpHeaderAdd(&(message->header),
hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), CSTRA("application/json")));
message->type = HTTP_MESSAGE_BUFFERED;

14
src/http/worker/add_common_header.c

@ -5,9 +5,11 @@
#include "interface/class.h"
#include "http/message.h"
#include "http/header.h"
#include "http/response.h"
#include "utils/memory.h"
#include "hash.h"
void
httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response)
@ -18,17 +20,15 @@ httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response)
size_t nbuf;
if (httpMessageHasKeepAlive(request)) {
httpHeaderAdd(
&(response->header),
hashAdd(response->header,
new(HttpHeader, CSTRA("Connection"), CSTRA("Keep-Alive")));
}
else {
httpHeaderAdd(
&(response->header),
hashAdd(response->header,
new(HttpHeader, CSTRA("Connection"), CSTRA("Close")));
}
httpHeaderAdd(&(response->header),
hashAdd(response->header,
new(HttpHeader, CSTRA("Server"), CSTRA("testserver")));
switch(((HttpResponse)response)->status) {
@ -37,14 +37,14 @@ httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response)
default:
nbuf = sprintf(buffer, "%d", response->nbody);
httpHeaderAdd(&(response->header),
hashAdd(response->header,
new(HttpHeader, CSTRA("Content-Length"), buffer, nbuf));
}
t = time(NULL);
tmp = localtime(&t);
nbuf = strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp);
httpHeaderAdd(&(response->header),
hashAdd(response->header,
new(HttpHeader, CSTRA("Date"), buffer, nbuf));
}

5
src/http/worker/get_asset.c

@ -6,6 +6,7 @@
#include "http/response.h"
#include "utils/memory.h"
#include "hash.h"
HttpMessage
httpWorkerGetAsset(
@ -18,8 +19,8 @@ httpWorkerGetAsset(
size_t nmatch;
HttpHeader header;
header = httpHeaderGet(
&(((HttpMessage)request)->header),
header = hashGet(
((HttpMessage)request)->header,
CSTRA("If-None-Match"));
if (NULL == header) {

9
src/http/worker/process.c

@ -30,6 +30,7 @@
#include "interface/class.h"
#include "http/worker.h"
#include "http/header.h"
#include "http/message.h"
#include "http/request.h"
#include "http/response.h"
@ -39,6 +40,7 @@
#include "stream.h"
#include "utils/memory.h"
#include "hash.h"
HttpMessage httpWorkerGetAsset(HttpRequest, const char *, const char *, size_t);
void httpWorkerAddCommonHeader(HttpMessage, HttpMessage);
@ -60,8 +62,8 @@ httpWorkerProcess(HttpWorker this, Stream st)
HttpMessage rmessage = reqq->msgs[i];
HttpRequest request = (HttpRequest)(reqq->msgs[i]);
HttpMessage response = NULL;
HttpHeader cookie = httpHeaderGet(
&(rmessage->header),
HttpHeader cookie = hashGet(
rmessage->header,
CSTRA("cookie"));
if (NULL == this->session && NULL != cookie) {
@ -111,8 +113,7 @@ httpWorkerProcess(HttpWorker this, Stream st)
response = (HttpMessage)httpResponseSession(this->session);
httpHeaderAdd(
&(response->header),
hashAdd(response->header,
new(HttpHeader, CSTRA("Set-Cookie"), buffer, nbuf));
}
}

51
src/interface/hashable.c

@ -0,0 +1,51 @@
/**
* \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 <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "class.h"
#include "interface/hashable.h"
const struct interface i_Hashable = {
"hashable",
2
};
unsigned long
hashableGetHash(void * hashable)
{
unsigned long ret;
RETCALL(hashable, Hashable, getHash, ret);
return ret;
}
void
hashableHandleDouble(void * hashable, void * new_hashable)
{
CALL(hashable, Hashable, handleDouble, new_hashable);
}
// vim: set ts=4 sw=4:
Loading…
Cancel
Save