Browse Source
structural changes for worker/process. @TODO actually i have no idea why this happens.
master
structural changes for worker/process. @TODO actually i have no idea why this happens.
master
33 changed files with 238 additions and 290 deletions
-
8ChangeLog
-
4TODO
-
6include/http/header.h
-
5include/http/response.h
-
2include/interface/class.h
-
2include/utils/memory.h
-
6src/Makefile.am
-
28src/cbuf.c
-
16src/http/header.c
-
17src/http/header/add.c
-
4src/http/header/size_get.c
-
12src/http/message.c
-
8src/http/message/queue.c
-
14src/http/request.c
-
17src/http/request/parser.c
-
8src/http/response.c
-
33src/http/response/304.c
-
2src/http/response/404.c
-
42src/http/response/asset.c
-
75src/http/response/image.c
-
2src/http/response/me.c
-
10src/http/response/writer.c
-
4src/http/response/writer/write.c
-
19src/http/worker.c
-
37src/http/worker/add_common_header.c
-
29src/http/worker/get_asset.c
-
76src/http/worker/process.c
-
6src/logger.c
-
16src/server.c
-
4src/server/close_conn.c
-
2src/server/handle_accept.c
-
8src/socket.c
-
6src/testserver.c
@ -1,6 +1,6 @@ |
|||
VERY BIG TODO: |
|||
- give a contructor a way to fail, so that no object will be created at all |
|||
|
|||
- right now i will use long polling ajax calls when feedback from to the client |
|||
is needed. In the long term this should be changed to websockets (ws). But |
|||
right now ws specification is not final anyway. :) |
|||
|
|||
- handle errors after all system call...especially open, close, etc. |
|||
@ -1,75 +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 <stdio.h> |
|||
#include <sys/stat.h> |
|||
#include <fcntl.h> |
|||
|
|||
#include "class.h" |
|||
#include "interface/class.h" |
|||
|
|||
#include "http/response.h" |
|||
#include "http/message.h" |
|||
#include "http/header.h" |
|||
|
|||
|
|||
HttpResponse |
|||
httpResponseImage(int handle) |
|||
{ |
|||
char buffer[200]; |
|||
struct stat st; |
|||
HttpResponse response; |
|||
HttpMessage message; |
|||
|
|||
fstat(handle, &st); |
|||
|
|||
response = new(HttpResponse, "HTTP/1.1", 200, "OK"); |
|||
message = (HttpMessage)response; |
|||
|
|||
httpHeaderAdd(&(message->header), |
|||
new(HttpHeader, "Content-Type", "image/jpeg")); |
|||
httpHeaderAdd(&(message->header), |
|||
new(HttpHeader, "Server", "testserver")); |
|||
|
|||
message->type = HTTP_MESSAGE_PIPED; |
|||
message->handle = handle; |
|||
message->nbody = st.st_size; |
|||
|
|||
sprintf(buffer, "%d", message->nbody); |
|||
httpHeaderAdd(&(message->header), |
|||
new(HttpHeader, "Content-Length", buffer)); |
|||
|
|||
tmp = localtime(&(st.st_mtime)); |
|||
strftime(buffer, sizeof(buffer), "%s", tmp); |
|||
httpHeaderAdd(&(message->header), |
|||
new(HttpHeader, "ETag", buffer)); |
|||
|
|||
t = time(NULL); |
|||
tmp = localtime(&t); |
|||
strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp); |
|||
httpHeaderAdd(&(message->header), |
|||
new(HttpHeader, "Date", buffer)); |
|||
|
|||
return response; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,37 @@ |
|||
#include <time.h> |
|||
|
|||
#include "class.h" |
|||
#include "interface/class.h" |
|||
|
|||
#include "http/message.h" |
|||
#include "http/response.h" |
|||
|
|||
void |
|||
httpWorkerAddCommonHeader(HttpMessage request, HttpMessage response) |
|||
{ |
|||
time_t t; |
|||
struct tm * tmp; |
|||
char buffer[200]; |
|||
|
|||
if (httpMessageHasKeepAlive(request)) { |
|||
httpHeaderAdd( |
|||
&(response->header), |
|||
new(HttpHeader, "Connection", "Keep-Alive")); |
|||
} |
|||
else { |
|||
httpHeaderAdd( |
|||
&(response->header), |
|||
new(HttpHeader, "Connection", "Close")); |
|||
} |
|||
|
|||
httpHeaderAdd(&(response->header), |
|||
new(HttpHeader, "Server", "testserver")); |
|||
|
|||
t = time(NULL); |
|||
tmp = localtime(&t); |
|||
strftime(buffer, sizeof(buffer), "%a, %d %b %Y %T %Z", tmp); |
|||
httpHeaderAdd(&(response->header), |
|||
new(HttpHeader, "Date", buffer)); |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -0,0 +1,29 @@ |
|||
#include "http/header.h" |
|||
#include "http/message.h" |
|||
#include "http/request.h" |
|||
#include "http/response.h" |
|||
|
|||
HttpMessage |
|||
httpWorkerGetAsset( |
|||
HttpRequest request, |
|||
const char * fname, |
|||
const char * mime) |
|||
{ |
|||
char * match; |
|||
HttpHeader header; |
|||
|
|||
header = httpHeaderGet( |
|||
&(((HttpMessage)request)->header), |
|||
"If-None-Match"); |
|||
|
|||
if (NULL == header) { |
|||
match = ""; |
|||
} |
|||
else { |
|||
match = (header->value)[0]; |
|||
} |
|||
|
|||
return (HttpMessage)httpResponseAsset(fname, mime, match); |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue