More changes
This commit is contained in:
@@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define _UNUSED_
|
#define _UNUSED_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ OBJECTFILES= \
|
|||||||
${OBJECTDIR}/src/main.o \
|
${OBJECTDIR}/src/main.o \
|
||||||
${OBJECTDIR}/src/mime.o \
|
${OBJECTDIR}/src/mime.o \
|
||||||
${OBJECTDIR}/src/queue.o \
|
${OBJECTDIR}/src/queue.o \
|
||||||
|
${OBJECTDIR}/src/server-connection.o \
|
||||||
${OBJECTDIR}/src/server-socket.o \
|
${OBJECTDIR}/src/server-socket.o \
|
||||||
${OBJECTDIR}/src/socket.o \
|
${OBJECTDIR}/src/socket.o \
|
||||||
${OBJECTDIR}/src/thread-pool.o \
|
${OBJECTDIR}/src/thread-pool.o \
|
||||||
@@ -137,6 +138,11 @@ ${OBJECTDIR}/src/queue.o: nbproject/Makefile-${CND_CONF}.mk src/queue.c
|
|||||||
${RM} "$@.d"
|
${RM} "$@.d"
|
||||||
$(COMPILE.c) -g -Werror -DINI_ALLOW_BOM=0 -DINI_ALLOW_MULTILINE=0 -D_GNU_SOURCE -Ilib -std=c99 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/queue.o src/queue.c
|
$(COMPILE.c) -g -Werror -DINI_ALLOW_BOM=0 -DINI_ALLOW_MULTILINE=0 -D_GNU_SOURCE -Ilib -std=c99 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/queue.o src/queue.c
|
||||||
|
|
||||||
|
${OBJECTDIR}/src/server-connection.o: nbproject/Makefile-${CND_CONF}.mk src/server-connection.c
|
||||||
|
${MKDIR} -p ${OBJECTDIR}/src
|
||||||
|
${RM} "$@.d"
|
||||||
|
$(COMPILE.c) -g -Werror -DINI_ALLOW_BOM=0 -DINI_ALLOW_MULTILINE=0 -D_GNU_SOURCE -Ilib -std=c99 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/server-connection.o src/server-connection.c
|
||||||
|
|
||||||
${OBJECTDIR}/src/server-socket.o: nbproject/Makefile-${CND_CONF}.mk src/server-socket.c
|
${OBJECTDIR}/src/server-socket.o: nbproject/Makefile-${CND_CONF}.mk src/server-socket.c
|
||||||
${MKDIR} -p ${OBJECTDIR}/src
|
${MKDIR} -p ${OBJECTDIR}/src
|
||||||
${RM} "$@.d"
|
${RM} "$@.d"
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ OBJECTFILES= \
|
|||||||
${OBJECTDIR}/src/main.o \
|
${OBJECTDIR}/src/main.o \
|
||||||
${OBJECTDIR}/src/mime.o \
|
${OBJECTDIR}/src/mime.o \
|
||||||
${OBJECTDIR}/src/queue.o \
|
${OBJECTDIR}/src/queue.o \
|
||||||
|
${OBJECTDIR}/src/server-connection.o \
|
||||||
${OBJECTDIR}/src/server-socket.o \
|
${OBJECTDIR}/src/server-socket.o \
|
||||||
${OBJECTDIR}/src/socket.o \
|
${OBJECTDIR}/src/socket.o \
|
||||||
${OBJECTDIR}/src/thread-pool.o \
|
${OBJECTDIR}/src/thread-pool.o \
|
||||||
@@ -137,6 +138,11 @@ ${OBJECTDIR}/src/queue.o: nbproject/Makefile-${CND_CONF}.mk src/queue.c
|
|||||||
${RM} "$@.d"
|
${RM} "$@.d"
|
||||||
$(COMPILE.c) -O2 -Werror -DINI_ALLOW_BOM=0 -DINI_ALLOW_MULTILINE=0 -D_GNU_SOURCE -Ilib -std=c99 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/queue.o src/queue.c
|
$(COMPILE.c) -O2 -Werror -DINI_ALLOW_BOM=0 -DINI_ALLOW_MULTILINE=0 -D_GNU_SOURCE -Ilib -std=c99 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/queue.o src/queue.c
|
||||||
|
|
||||||
|
${OBJECTDIR}/src/server-connection.o: nbproject/Makefile-${CND_CONF}.mk src/server-connection.c
|
||||||
|
${MKDIR} -p ${OBJECTDIR}/src
|
||||||
|
${RM} "$@.d"
|
||||||
|
$(COMPILE.c) -O2 -Werror -DINI_ALLOW_BOM=0 -DINI_ALLOW_MULTILINE=0 -D_GNU_SOURCE -Ilib -std=c99 -MMD -MP -MF "$@.d" -o ${OBJECTDIR}/src/server-connection.o src/server-connection.c
|
||||||
|
|
||||||
${OBJECTDIR}/src/server-socket.o: nbproject/Makefile-${CND_CONF}.mk src/server-socket.c
|
${OBJECTDIR}/src/server-socket.o: nbproject/Makefile-${CND_CONF}.mk src/server-socket.c
|
||||||
${MKDIR} -p ${OBJECTDIR}/src
|
${MKDIR} -p ${OBJECTDIR}/src
|
||||||
${RM} "$@.d"
|
${RM} "$@.d"
|
||||||
|
|||||||
@@ -11,15 +11,18 @@
|
|||||||
<itemPath>src/http.h</itemPath>
|
<itemPath>src/http.h</itemPath>
|
||||||
<itemPath>lib/http_parser.h</itemPath>
|
<itemPath>lib/http_parser.h</itemPath>
|
||||||
<itemPath>lib/ini.h</itemPath>
|
<itemPath>lib/ini.h</itemPath>
|
||||||
|
<itemPath>src/khttp.h</itemPath>
|
||||||
<itemPath>src/log.h</itemPath>
|
<itemPath>src/log.h</itemPath>
|
||||||
<itemPath>src/main-loop.h</itemPath>
|
<itemPath>src/main-loop.h</itemPath>
|
||||||
<itemPath>src/main.h</itemPath>
|
<itemPath>src/main.h</itemPath>
|
||||||
<itemPath>src/mime.h</itemPath>
|
<itemPath>src/mime.h</itemPath>
|
||||||
<itemPath>src/queue.h</itemPath>
|
<itemPath>src/queue.h</itemPath>
|
||||||
|
<itemPath>src/server-connection.h</itemPath>
|
||||||
<itemPath>src/server-socket.h</itemPath>
|
<itemPath>src/server-socket.h</itemPath>
|
||||||
<itemPath>src/socket.h</itemPath>
|
<itemPath>src/socket.h</itemPath>
|
||||||
<itemPath>src/thread-pool.h</itemPath>
|
<itemPath>src/thread-pool.h</itemPath>
|
||||||
<itemPath>src/util.h</itemPath>
|
<itemPath>src/util.h</itemPath>
|
||||||
|
<itemPath>src/version.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="ResourceFiles"
|
<logicalFolder name="ResourceFiles"
|
||||||
displayName="Resource Files"
|
displayName="Resource Files"
|
||||||
@@ -40,6 +43,7 @@
|
|||||||
<itemPath>src/main.c</itemPath>
|
<itemPath>src/main.c</itemPath>
|
||||||
<itemPath>src/mime.c</itemPath>
|
<itemPath>src/mime.c</itemPath>
|
||||||
<itemPath>src/queue.c</itemPath>
|
<itemPath>src/queue.c</itemPath>
|
||||||
|
<itemPath>src/server-connection.c</itemPath>
|
||||||
<itemPath>src/server-socket.c</itemPath>
|
<itemPath>src/server-socket.c</itemPath>
|
||||||
<itemPath>src/socket.c</itemPath>
|
<itemPath>src/socket.c</itemPath>
|
||||||
<itemPath>src/thread-pool.c</itemPath>
|
<itemPath>src/thread-pool.c</itemPath>
|
||||||
@@ -127,6 +131,8 @@
|
|||||||
</item>
|
</item>
|
||||||
<item path="src/http.h" ex="false" tool="3" flavor2="0">
|
<item path="src/http.h" ex="false" tool="3" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
|
<item path="src/khttp.h" ex="false" tool="3" flavor2="0">
|
||||||
|
</item>
|
||||||
<item path="src/log.c" ex="false" tool="0" flavor2="0">
|
<item path="src/log.c" ex="false" tool="0" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
<item path="src/log.h" ex="false" tool="3" flavor2="0">
|
<item path="src/log.h" ex="false" tool="3" flavor2="0">
|
||||||
@@ -147,6 +153,10 @@
|
|||||||
</item>
|
</item>
|
||||||
<item path="src/queue.h" ex="false" tool="3" flavor2="0">
|
<item path="src/queue.h" ex="false" tool="3" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
|
<item path="src/server-connection.c" ex="false" tool="0" flavor2="0">
|
||||||
|
</item>
|
||||||
|
<item path="src/server-connection.h" ex="false" tool="3" flavor2="0">
|
||||||
|
</item>
|
||||||
<item path="src/server-socket.c" ex="false" tool="0" flavor2="0">
|
<item path="src/server-socket.c" ex="false" tool="0" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
<item path="src/server-socket.h" ex="false" tool="3" flavor2="0">
|
<item path="src/server-socket.h" ex="false" tool="3" flavor2="0">
|
||||||
@@ -163,6 +173,8 @@
|
|||||||
</item>
|
</item>
|
||||||
<item path="src/util.h" ex="false" tool="3" flavor2="0">
|
<item path="src/util.h" ex="false" tool="3" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
|
<item path="src/version.h" ex="false" tool="3" flavor2="0">
|
||||||
|
</item>
|
||||||
</conf>
|
</conf>
|
||||||
<conf name="Release" type="1">
|
<conf name="Release" type="1">
|
||||||
<toolsSet>
|
<toolsSet>
|
||||||
@@ -229,6 +241,8 @@
|
|||||||
</item>
|
</item>
|
||||||
<item path="src/http.h" ex="false" tool="3" flavor2="0">
|
<item path="src/http.h" ex="false" tool="3" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
|
<item path="src/khttp.h" ex="false" tool="3" flavor2="0">
|
||||||
|
</item>
|
||||||
<item path="src/log.c" ex="false" tool="0" flavor2="0">
|
<item path="src/log.c" ex="false" tool="0" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
<item path="src/log.h" ex="false" tool="3" flavor2="0">
|
<item path="src/log.h" ex="false" tool="3" flavor2="0">
|
||||||
@@ -249,6 +263,10 @@
|
|||||||
</item>
|
</item>
|
||||||
<item path="src/queue.h" ex="false" tool="3" flavor2="0">
|
<item path="src/queue.h" ex="false" tool="3" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
|
<item path="src/server-connection.c" ex="false" tool="0" flavor2="0">
|
||||||
|
</item>
|
||||||
|
<item path="src/server-connection.h" ex="false" tool="3" flavor2="0">
|
||||||
|
</item>
|
||||||
<item path="src/server-socket.c" ex="false" tool="0" flavor2="0">
|
<item path="src/server-socket.c" ex="false" tool="0" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
<item path="src/server-socket.h" ex="false" tool="3" flavor2="0">
|
<item path="src/server-socket.h" ex="false" tool="3" flavor2="0">
|
||||||
@@ -265,6 +283,8 @@
|
|||||||
</item>
|
</item>
|
||||||
<item path="src/util.h" ex="false" tool="3" flavor2="0">
|
<item path="src/util.h" ex="false" tool="3" flavor2="0">
|
||||||
</item>
|
</item>
|
||||||
|
<item path="src/version.h" ex="false" tool="3" flavor2="0">
|
||||||
|
</item>
|
||||||
</conf>
|
</conf>
|
||||||
</confs>
|
</confs>
|
||||||
</configurationDescriptor>
|
</configurationDescriptor>
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "util.h"
|
||||||
#include "ini.h"
|
#include "ini.h"
|
||||||
|
|
||||||
const char *default_servername = "localhost";
|
const char *default_servername = "localhost";
|
||||||
|
|||||||
@@ -8,11 +8,13 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#define CONFIG_SERVER_FOREACH_HOST(config, elem) \
|
#define CONFIG_SERVER_FOREACH_HOST(config, elem) \
|
||||||
elem = config->hosts != NULL ? config->hosts[0] : NULL; \
|
elem = config->hosts != NULL ? config->hosts[0] : NULL; \
|
||||||
@@ -32,7 +34,6 @@ extern "C" {
|
|||||||
char *servername;
|
char *servername;
|
||||||
char *administrator;
|
char *administrator;
|
||||||
uint16_t listen_port;
|
uint16_t listen_port;
|
||||||
|
|
||||||
config_host **hosts;
|
config_host **hosts;
|
||||||
size_t host_count;
|
size_t host_count;
|
||||||
} config_server;
|
} config_server;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "ut/utlist.h"
|
#include "ut/utlist.h"
|
||||||
|
|
||||||
#include "data-buffer.h"
|
#include "data-buffer.h"
|
||||||
|
|
||||||
data_buffer_list* data_buffer_list_new() {
|
data_buffer_list* data_buffer_list_new() {
|
||||||
@@ -31,7 +30,7 @@ void data_buffer_list_delete(data_buffer_list *list) {
|
|||||||
free(list->rdlock);
|
free(list->rdlock);
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
int data_buffer_list_append(data_buffer_list *list, const char* src, size_t n) {
|
void data_buffer_list_append(data_buffer_list *list, const char* src, size_t n) {
|
||||||
assert(list!=NULL);
|
assert(list!=NULL);
|
||||||
assert(src!=NULL && n>0);
|
assert(src!=NULL && n>0);
|
||||||
BUFFER_LIST_WR_LOCK(list);
|
BUFFER_LIST_WR_LOCK(list);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ extern "C" {
|
|||||||
|
|
||||||
data_buffer_list* data_buffer_list_new();
|
data_buffer_list* data_buffer_list_new();
|
||||||
void data_buffer_list_delete(data_buffer_list *list);
|
void data_buffer_list_delete(data_buffer_list *list);
|
||||||
int data_buffer_list_append(data_buffer_list *list, const char* src, size_t n);
|
void data_buffer_list_append(data_buffer_list *list, const char* src, size_t n);
|
||||||
void data_buffer_list_lock(data_buffer_list *list, bool rd, bool wr);
|
void data_buffer_list_lock(data_buffer_list *list, bool rd, bool wr);
|
||||||
void data_buffer_list_unlock(data_buffer_list *list, bool rd, bool wr);
|
void data_buffer_list_unlock(data_buffer_list *list, bool rd, bool wr);
|
||||||
|
|
||||||
|
|||||||
@@ -3,21 +3,20 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "main.h"
|
#include "util.h"
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
#include "http_parser.h"
|
#include "server-connection.h"
|
||||||
#include "http-reader.h"
|
#include "http-reader.h"
|
||||||
#include "main-loop.h"
|
|
||||||
|
|
||||||
#define GET_CB_STR(str, at, length) do { \
|
#define GET_CB_STR(str, at, length) do { \
|
||||||
str = calloc(length+1, sizeof(char));\
|
str = calloc(length+1, sizeof(char));\
|
||||||
strncpy(str, at, length);\
|
strncpy(str, at, length);\
|
||||||
}while(0);
|
}while(0);
|
||||||
#define SKT(parser) ((hmain_parse_data*)parser->data)
|
#define SKT(parser) ((request_parse_state*)parser->data)
|
||||||
|
|
||||||
http_parser_settings *parser_settings = NULL;
|
http_parser_settings *parser_settings = NULL;
|
||||||
|
|
||||||
http_parser_settings* parser_get_settings(hmain_parse_data *data) {
|
http_parser_settings* parser_get_settings() {
|
||||||
if (parser_settings == NULL) {
|
if (parser_settings == NULL) {
|
||||||
parser_settings = calloc(1, sizeof(http_parser_settings));
|
parser_settings = calloc(1, sizeof(http_parser_settings));
|
||||||
parser_settings->on_body = parser_cb_on_body;
|
parser_settings->on_body = parser_cb_on_body;
|
||||||
@@ -28,6 +27,7 @@ http_parser_settings* parser_get_settings(hmain_parse_data *data) {
|
|||||||
parser_settings->on_message_complete = parser_cb_on_message_complete;
|
parser_settings->on_message_complete = parser_cb_on_message_complete;
|
||||||
parser_settings->on_status = parser_cb_on_status;
|
parser_settings->on_status = parser_cb_on_status;
|
||||||
parser_settings->on_url = parser_cb_on_url;
|
parser_settings->on_url = parser_cb_on_url;
|
||||||
|
|
||||||
}
|
}
|
||||||
return parser_settings;
|
return parser_settings;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,20 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "http_parser.h"
|
#include <stddef.h>
|
||||||
#include "http.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "main-loop.h"
|
|
||||||
|
|
||||||
http_parser_settings* parser_get_settings(hmain_parse_data *elem);
|
#include "http.h"
|
||||||
|
#include "http_parser.h"
|
||||||
|
|
||||||
|
typedef struct request_parse_state {
|
||||||
|
http_request *current_request;
|
||||||
|
bool request_complete;
|
||||||
|
struct http_parser *parser;
|
||||||
|
http_header *parser_current_header;
|
||||||
|
enum {HSTATE_NONE, HSTATE_VALUE, HSTATE_FIELD} parser_header_state;
|
||||||
|
} request_parse_state;
|
||||||
|
|
||||||
|
http_parser_settings* parser_get_settings();
|
||||||
void parser_free_settings();
|
void parser_free_settings();
|
||||||
|
|
||||||
int parser_cb_on_message_begin(http_parser* parser);
|
int parser_cb_on_message_begin(http_parser* parser);
|
||||||
|
|||||||
@@ -9,13 +9,14 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "ut/utstring.h"
|
||||||
|
|
||||||
#include "http_parser.h"
|
#include "http_parser.h"
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
#include "main.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "http-server.h"
|
#include "http-server.h"
|
||||||
#include "mime.h"
|
#include "mime.h"
|
||||||
#include "ut/utstring.h"
|
#include "util.h"
|
||||||
|
|
||||||
http_response* server_process_request(config_server* config, http_request *request) {
|
http_response* server_process_request(config_server* config, http_request *request) {
|
||||||
http_response* response = NULL;
|
http_response* response = NULL;
|
||||||
|
|||||||
@@ -12,12 +12,12 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
#include "main.h"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
typedef struct server_file_result {
|
typedef struct server_file_result {
|
||||||
bool error;
|
bool error;
|
||||||
|
|||||||
@@ -4,10 +4,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "main.h"
|
|
||||||
#include "ut/utarray.h"
|
#include "ut/utarray.h"
|
||||||
#include "ut/utstring.h"
|
#include "ut/utstring.h"
|
||||||
|
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
void http_header_icd_init_f(void* elem) {
|
void http_header_icd_init_f(void* elem) {
|
||||||
memset(elem, 1, sizeof(http_header));
|
memset(elem, 1, sizeof(http_header));
|
||||||
|
|||||||
10
src/http.h
10
src/http.h
@@ -8,14 +8,16 @@
|
|||||||
#ifndef HTTP_H
|
#ifndef HTTP_H
|
||||||
#define HTTP_H
|
#define HTTP_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "ut/utarray.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "ut/utarray.h"
|
|
||||||
|
|
||||||
#define HEADER_CONTENT_TYPE "Content-Type"
|
#define HEADER_CONTENT_TYPE "Content-Type"
|
||||||
#define HEADER_CONTENT_LENGTH "Content-Length"
|
#define HEADER_CONTENT_LENGTH "Content-Length"
|
||||||
#define HEADER_USER_AGENT "User-Agent"
|
#define HEADER_USER_AGENT "User-Agent"
|
||||||
|
|||||||
@@ -8,16 +8,18 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "main-loop.h"
|
|
||||||
#include "mime.h"
|
#include "mime.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "thread-pool.h"
|
#include "thread-pool.h"
|
||||||
#include "queue.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "http_parser.h"
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
#include "http-reader.h"
|
#include "http-reader.h"
|
||||||
#include "server-socket.h"
|
#include "server-socket.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "main-loop.h"
|
||||||
|
|
||||||
hmain_connection* hmain_connection_new(int fd, hmain_status *status) {
|
hmain_connection* hmain_connection_new(int fd, hmain_status *status) {
|
||||||
static u_int64_t nextid = 1;
|
static u_int64_t nextid = 1;
|
||||||
@@ -121,12 +123,10 @@ void hmain_setup(hmain_status *status) {
|
|||||||
status->pools[POOL_WORKERS] = pool;
|
status->pools[POOL_WORKERS] = pool;
|
||||||
thread_pool_start(pool);
|
thread_pool_start(pool);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void hmain_teardown(hmain_status *status) {
|
void hmain_teardown(hmain_status *status) {
|
||||||
if (status == NULL) {
|
assert(status!=NULL);
|
||||||
fatal("hmain is not setup");
|
|
||||||
}
|
|
||||||
//Stop pools
|
//Stop pools
|
||||||
size_t pool_count = sizeof(status->pools) / sizeof(status->pools[0]);
|
size_t pool_count = sizeof(status->pools) / sizeof(status->pools[0]);
|
||||||
for(int i=0; i<pool_count; i++) {
|
for(int i=0; i<pool_count; i++) {
|
||||||
@@ -238,7 +238,6 @@ void* thloop_read(void * arg) {
|
|||||||
}
|
}
|
||||||
hmain_connection *conn = (hmain_connection*)item->data;
|
hmain_connection *conn = (hmain_connection*)item->data;
|
||||||
CONN_LOCK(conn);
|
CONN_LOCK(conn);
|
||||||
conn->isReading = true;
|
|
||||||
|
|
||||||
char buffer[16*1024];
|
char buffer[16*1024];
|
||||||
int count;
|
int count;
|
||||||
@@ -269,7 +268,6 @@ void* thloop_read(void * arg) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} while(count > 0);
|
} while(count > 0);
|
||||||
conn->isReading = false;
|
|
||||||
CONN_UNLOCK(conn);
|
CONN_UNLOCK(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,11 +282,10 @@ void* thloop_write(void * arg) {
|
|||||||
hmain_connection *conn = (hmain_connection*)item->data;
|
hmain_connection *conn = (hmain_connection*)item->data;
|
||||||
do {
|
do {
|
||||||
CONN_LOCK(conn);
|
CONN_LOCK(conn);
|
||||||
conn->isWriting = true;
|
|
||||||
|
|
||||||
|
|
||||||
}while(0);
|
}while(0);
|
||||||
conn->isWriting = false;
|
|
||||||
CONN_UNLOCK(conn);
|
CONN_UNLOCK(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,21 +8,14 @@
|
|||||||
#ifndef MAIN_LOOP_H
|
#ifndef MAIN_LOOP_H
|
||||||
#define MAIN_LOOP_H
|
#define MAIN_LOOP_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include "http_parser.h"
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "thread-pool.h"
|
|
||||||
#include "http.h"
|
|
||||||
#include "data-buffer.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#define EPOLL_MAXEVENTS 128
|
#define EPOLL_MAXEVENTS 128
|
||||||
|
|
||||||
#define CONN_LOCK(c) pthread_mutex_lock(c->mutex)
|
#define CONN_LOCK(c) pthread_mutex_lock(c->mutex)
|
||||||
@@ -32,7 +25,7 @@ extern "C" {
|
|||||||
POOL_READ, POOL_WRITE, POOL_WORKERS, POOL_DISK_READ
|
POOL_READ, POOL_WRITE, POOL_WORKERS, POOL_DISK_READ
|
||||||
} hmain_pool;
|
} hmain_pool;
|
||||||
|
|
||||||
typedef enum skt_elem_hstate {HSTATE_NONE, HSTATE_VALUE, HSTATE_FIELD} skt_elem_hstate;
|
//typedef enum skt_elem_hstate {HSTATE_NONE, HSTATE_VALUE, HSTATE_FIELD} skt_elem_hstate;
|
||||||
|
|
||||||
typedef struct hmain_connection {
|
typedef struct hmain_connection {
|
||||||
uint64_t cid;
|
uint64_t cid;
|
||||||
@@ -64,7 +57,7 @@ extern "C" {
|
|||||||
bool request_complete;
|
bool request_complete;
|
||||||
http_parser *parser;
|
http_parser *parser;
|
||||||
http_header *parser_current_header;
|
http_header *parser_current_header;
|
||||||
skt_elem_hstate parser_header_state;
|
int parser_header_state;
|
||||||
} hmain_parse_data;
|
} hmain_parse_data;
|
||||||
|
|
||||||
hmain_connection* hmain_connection_new(int fd, hmain_status *status);
|
hmain_connection* hmain_connection_new(int fd, hmain_status *status);
|
||||||
|
|||||||
28
src/main.c
28
src/main.c
@@ -17,38 +17,10 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <bits/stdio2.h>
|
#include <bits/stdio2.h>
|
||||||
|
|
||||||
#include "http_parser.h"
|
|
||||||
|
|
||||||
#include "ut/utlist.h"
|
|
||||||
#include "ut/utarray.h"
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "socket.h"
|
|
||||||
#include "http.h"
|
|
||||||
#include "http-reader.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "http-server.h"
|
|
||||||
#include "mime.h"
|
|
||||||
#include "queue.h"
|
|
||||||
#include "thread-pool.h"
|
|
||||||
#include "log.h"
|
|
||||||
#include "main-loop.h"
|
|
||||||
|
|
||||||
int serverfd = 0;
|
|
||||||
volatile static bool stop = false;
|
|
||||||
|
|
||||||
static void signal_int(int signum) {
|
|
||||||
fprintf(stderr, "Terminating...\n");
|
|
||||||
stop = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
hmain_status *status = calloc(1, sizeof(hmain_status));
|
|
||||||
hmain_setup(status);
|
|
||||||
|
|
||||||
hmain_loop(status);
|
|
||||||
|
|
||||||
hmain_teardown(status);
|
|
||||||
|
|
||||||
return (EXIT_SUCCESS);
|
return (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
@@ -12,12 +12,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SERVER_NAME "KHTTP/0.1"
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "http.h"
|
|
||||||
#include "util.h"
|
|
||||||
|
|
||||||
int main(int argc, char** argv);
|
int main(int argc, char** argv);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
28
src/queue.c
28
src/queue.c
@@ -3,9 +3,9 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "queue.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "ut/utlist.h"
|
#include "ut/utlist.h"
|
||||||
|
#include "queue.h"
|
||||||
|
|
||||||
queue_item* queue_item_new() {
|
queue_item* queue_item_new() {
|
||||||
static uint64_t nextid = 0;
|
static uint64_t nextid = 0;
|
||||||
@@ -18,7 +18,7 @@ queue_item* queue_item_new() {
|
|||||||
queue_item* queue_item_new2(char* tag, void* data) {
|
queue_item* queue_item_new2(char* tag, void* data) {
|
||||||
queue_item *item = queue_item_new();
|
queue_item *item = queue_item_new();
|
||||||
item->tag[0] = '\0';
|
item->tag[0] = '\0';
|
||||||
strncat(item->tag, tag, (sizeof(item->tag)/sizeof(char))+1);
|
strncat(item->tag, tag, (sizeof(item->tag)/sizeof(char))-1);
|
||||||
item->data = data;
|
item->data = data;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -65,16 +65,35 @@ int queue_add(queue *q, queue_item *item) {
|
|||||||
}
|
}
|
||||||
int queue_remove(queue *q, queue_item *item) {
|
int queue_remove(queue *q, queue_item *item) {
|
||||||
QUEUE_LOCK(q);
|
QUEUE_LOCK(q);
|
||||||
|
int result = 0;
|
||||||
queue_item *elem, *tmp;
|
queue_item *elem, *tmp;
|
||||||
DL_FOREACH_SAFE(q->list, elem, tmp) {
|
DL_FOREACH_SAFE(q->list, elem, tmp) {
|
||||||
if (elem == item) {
|
if (elem == item) {
|
||||||
DL_DELETE(q->list, elem);
|
DL_DELETE(q->list, elem);
|
||||||
queue_item_delete(elem);
|
queue_item_delete(elem);
|
||||||
|
result = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
q->count--;
|
q->count -= result;
|
||||||
QUEUE_UNLOCK(q);
|
QUEUE_UNLOCK(q);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
int queue_remove_byptr(queue *q, void* ptr) {
|
||||||
|
QUEUE_LOCK(q);
|
||||||
|
|
||||||
|
int result = 0;
|
||||||
|
queue_item *elem, *tmp;
|
||||||
|
DL_FOREACH_SAFE(q->list, elem, tmp) {
|
||||||
|
if (elem->data == ptr) {
|
||||||
|
DL_DELETE(q->list, elem);
|
||||||
|
queue_item_delete(elem);
|
||||||
|
result ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
q->count -= result;
|
||||||
|
QUEUE_UNLOCK(q);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
queue_item* queue_fetchone(queue *q, bool blocking) {
|
queue_item* queue_fetchone(queue *q, bool blocking) {
|
||||||
queue_item *item = NULL;
|
queue_item *item = NULL;
|
||||||
@@ -91,8 +110,7 @@ queue_item* queue_fetchone(queue *q, bool blocking) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
item = q->list;
|
DL_DELETE(q->list, item);
|
||||||
DL_DELETE(q->list, q->list);
|
|
||||||
q->count--;
|
q->count--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ extern "C" {
|
|||||||
void queue_delete(queue *q);
|
void queue_delete(queue *q);
|
||||||
int queue_add(queue *q, queue_item *item);
|
int queue_add(queue *q, queue_item *item);
|
||||||
int queue_remove(queue *q, queue_item *item);
|
int queue_remove(queue *q, queue_item *item);
|
||||||
|
int queue_remove_byptr(queue *q, void* ptr);
|
||||||
queue_item* queue_fetchone(queue *q, bool blocking);
|
queue_item* queue_fetchone(queue *q, bool blocking);
|
||||||
void queue_unblock(queue *q, uint64_t itemid);
|
void queue_unblock(queue *q, uint64_t itemid);
|
||||||
void queue_clear(queue *q);
|
void queue_clear(queue *q);
|
||||||
|
|||||||
33
src/server-connection.c
Normal file
33
src/server-connection.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "http.h"
|
||||||
|
#include "server-connection.h"
|
||||||
|
|
||||||
|
|
||||||
|
server_connection* server_connection_new(skt_info *skt) {
|
||||||
|
static uint64_t nextid = 1;
|
||||||
|
assert(skt!=null);
|
||||||
|
|
||||||
|
server_connection *conn = calloc(1, sizeof(server_connection));
|
||||||
|
conn->id = __atomic_fetch_add(&nextid, 1, __ATOMIC_SEQ_CST);
|
||||||
|
conn->last_activity = time(NULL);
|
||||||
|
conn->parse_state = NULL;
|
||||||
|
conn->pending_responses = http_response_list_new();
|
||||||
|
conn->pending_writes = data_buffer_list_new();
|
||||||
|
conn->skt = skt;
|
||||||
|
conn->write_qid = 0;
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
void server_connection_delete(server_connection *conn) {
|
||||||
|
assert(conn!=NULL);
|
||||||
|
|
||||||
|
http_response_list_delete(conn->pending_responses);
|
||||||
|
data_buffer_list_delete(conn->pending_writes);
|
||||||
|
skt_delete(conn->skt);
|
||||||
|
free(conn);
|
||||||
|
}
|
||||||
42
src/server-connection.h
Normal file
42
src/server-connection.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* File: server-connection.h
|
||||||
|
* Author: sam
|
||||||
|
*
|
||||||
|
* Created on 15 August 2014, 18:07
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SERVER_CONNECTION_H
|
||||||
|
#define SERVER_CONNECTION_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "data-buffer.h"
|
||||||
|
#include "http.h"
|
||||||
|
#include "http-reader.h"
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
|
typedef struct server_connection {
|
||||||
|
uint64_t id;
|
||||||
|
struct skt_info *skt;
|
||||||
|
time_t last_activity;
|
||||||
|
http_response_list *pending_responses;
|
||||||
|
data_buffer_list *pending_writes;
|
||||||
|
uint64_t write_qid;//item id in write queue
|
||||||
|
request_parse_state *parse_state;
|
||||||
|
struct server_connection *next;
|
||||||
|
} server_connection;
|
||||||
|
|
||||||
|
server_connection* server_connection_new(skt_info *skt);
|
||||||
|
void server_connection_delete(server_connection *conn);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* SERVER_CONNECTION_H */
|
||||||
|
|
||||||
@@ -9,10 +9,11 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "server-socket.h"
|
#include "server-socket.h"
|
||||||
#include "main.h"
|
#include "util.h"
|
||||||
|
|
||||||
int server_socket_create() {
|
int server_socket_create() {
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
|
|||||||
@@ -8,12 +8,14 @@
|
|||||||
#ifndef SERVER_SOCKET_H
|
#ifndef SERVER_SOCKET_H
|
||||||
#define SERVER_SOCKET_H
|
#define SERVER_SOCKET_H
|
||||||
|
|
||||||
#include "socket.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
int server_socket_create();
|
int server_socket_create();
|
||||||
void server_socket_listen(int fd, uint16_t port);
|
void server_socket_listen(int fd, uint16_t port);
|
||||||
void server_socket_release(int fd);
|
void server_socket_release(int fd);
|
||||||
|
|||||||
@@ -12,14 +12,15 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "socket.h"
|
|
||||||
#include "ut/utstring.h"
|
#include "ut/utstring.h"
|
||||||
#include "data-buffer.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "ut/utlist.h"
|
#include "ut/utlist.h"
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
#include "data-buffer.h"
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
u_int64_t skt_nextid() {
|
u_int64_t skt_nextid() {
|
||||||
static u_int64_t id = 0;
|
static u_int64_t id = 1;
|
||||||
return __atomic_fetch_add(&id, 1, __ATOMIC_SEQ_CST);
|
return __atomic_fetch_add(&id, 1, __ATOMIC_SEQ_CST);
|
||||||
}
|
}
|
||||||
skt_info* skt_new(int fd) {
|
skt_info* skt_new(int fd) {
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/types.h>
|
#include <stddef.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "http.h"
|
|
||||||
#include "ut/utstring.h"
|
|
||||||
#include "data-buffer.h"
|
#include "data-buffer.h"
|
||||||
|
|
||||||
typedef struct skt_info {
|
typedef struct skt_info {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ extern "C" {
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
|
||||||
typedef struct thread {
|
typedef struct thread {
|
||||||
|
|||||||
23
src/version.h
Normal file
23
src/version.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* File: version.h
|
||||||
|
* Author: sam
|
||||||
|
*
|
||||||
|
* Created on 15 August 2014, 19:05
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VERSION_H
|
||||||
|
#define VERSION_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SERVER_NAME "KHTTP/0.1"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* VERSION_H */
|
||||||
|
|
||||||
Reference in New Issue
Block a user