Work on request header parsing

This commit is contained in:
2014-07-18 23:40:15 +01:00
parent 6d3ca314d4
commit e56f8f3715
10 changed files with 165 additions and 7 deletions

View File

@@ -12,16 +12,26 @@
#include <strings.h>
#include "ut/utlist.h"
#include "ut/utarray.h"
#include "main.h"
#include "socket.h"
#include "http/http.h"
#include "http/request.h"
int serverfd = 0;
char* teststr = "GET /testing/123 HTTP/1.1\r\n";
/*
*
*/
int main(int argc, char** argv) {
/*char *test = calloc(strlen(teststr)+1, sizeof(char));
strcpy(test, teststr);
http_request *req = http_request_new();
parse_request(req, test);
return 0;*/
skt_elem *connections = NULL;
serverfd = svr_create();
@@ -38,6 +48,7 @@ int main(int argc, char** argv) {
if (info != NULL) {
skt_elem* newconn = calloc(1, sizeof(skt_elem));
newconn->info = info;
newconn->current_request = http_request_new();
LL_APPEND(connections, newconn);
}
}
@@ -90,6 +101,9 @@ int main(int argc, char** argv) {
if (elem->info->closed) {
LL_DELETE(connections, elem);
skt_delete(elem->info);
if (elem->current_request != NULL) {
http_request_delete(elem->current_request);
}
free(elem);
}
}
@@ -124,4 +138,46 @@ void info(char* msg, ...) {
vfprintf(stdout, msg, va);
fputc('\n', stdout);
va_end(va);
}
char** str_splitlines(char *str, size_t *line_count) {
char **result;
*line_count = 0;
char *tmp = str;
while(*tmp) {
if (*tmp == '\n') {
(*line_count)++;
}
tmp++;
}
if (*line_count == 0) {
result = calloc(1, sizeof(char*));
result[0] = calloc(strlen(str), sizeof(char));
strcpy(result[0], str);
return result;
}
result = calloc(*line_count, sizeof(char*));
if (result == NULL) {
fatal("calloc failed");
}
size_t i=0, linelen = 0;
char *line = strtok(str, "\n");
while(line) {
linelen = strlen(line);
result[i] = calloc(linelen+1, sizeof(char));
if (result[i] == NULL) {
fatal("calloc failed");
}
strcpy(result[i], line);
if (result[i][linelen-1] == '\r') {
result[i][linelen-1] = '\0';
result[i] = realloc(result[i], linelen);
}
line = strtok(NULL, "\n");
i++;
}
return result;
}