OCT 重新格式化代码
This commit is contained in:
parent
b05d9987f1
commit
e34c25a0e3
|
@ -1,6 +1,7 @@
|
||||||
# ClangFormatConfigureSource: 'clang-format-file://D:/development/c/daemon_agent/.clang-format'
|
# ClangFormatConfigureSource: 'clang-format-file://D:/development/c/daemon_agent/.clang-format'
|
||||||
Language: Cpp
|
Language: Cpp
|
||||||
AccessModifierOffset: -4
|
AccessModifierOffset: -4
|
||||||
|
InsertBraces: true
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveMacros: Consecutive
|
AlignConsecutiveMacros: Consecutive
|
||||||
AlignConsecutiveAssignments: Consecutive
|
AlignConsecutiveAssignments: Consecutive
|
||||||
|
|
|
@ -23,8 +23,8 @@ endif (UNIX)
|
||||||
INCLUDE_DIRECTORIES(./include ./src ../libs/include)
|
INCLUDE_DIRECTORIES(./include ./src ../libs/include)
|
||||||
|
|
||||||
file(GLOB_RECURSE HW_HEADS
|
file(GLOB_RECURSE HW_HEADS
|
||||||
./src/haywire/*.h
|
./src/haywire/*.h
|
||||||
./src/haywire/configuration/*.h)
|
./src/haywire/configuration/*.h)
|
||||||
|
|
||||||
AUX_SOURCE_DIRECTORY(src/haywire HW_SRC)
|
AUX_SOURCE_DIRECTORY(src/haywire HW_SRC)
|
||||||
AUX_SOURCE_DIRECTORY(src/haywire/configuration HW_SRC)
|
AUX_SOURCE_DIRECTORY(src/haywire/configuration HW_SRC)
|
||||||
|
@ -34,6 +34,6 @@ INCLUDE_DIRECTORIES(. ./include)
|
||||||
#find_package(Threads REQUIRED)
|
#find_package(Threads REQUIRED)
|
||||||
|
|
||||||
add_library(haywire STATIC ${HW_SRC} ${HW_HEADS})
|
add_library(haywire STATIC ${HW_SRC} ${HW_HEADS})
|
||||||
target_link_libraries (haywire -luv -pthread)
|
target_link_libraries(haywire -luv -pthread)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,25 +8,25 @@ extern "C" {
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Windows - set up dll import/export decorators. */
|
/* Windows - set up dll import/export decorators. */
|
||||||
#ifdef BUILDING_HAYWIRE_SHARED
|
#ifdef BUILDING_HAYWIRE_SHARED
|
||||||
/* Building shared library. */
|
/* Building shared library. */
|
||||||
#define HAYWIRE_EXTERN __declspec(dllexport)
|
#define HAYWIRE_EXTERN __declspec(dllexport)
|
||||||
#else
|
|
||||||
#ifdef USING_HAYWIRE_SHARED
|
|
||||||
/* Using shared library. */
|
|
||||||
#define HAYWIRE_EXTERN __declspec(dllimport)
|
|
||||||
#else
|
|
||||||
/* Building static library. */
|
|
||||||
#define HAYWIRE_EXTERN /* nothing */
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HAYWIRE_CALLING_CONVENTION __cdecl
|
|
||||||
#else
|
#else
|
||||||
/* Building static library. */
|
#ifdef USING_HAYWIRE_SHARED
|
||||||
#define HAYWIRE_EXTERN /* nothing */
|
/* Using shared library. */
|
||||||
#define HAYWIRE_CALLING_CONVENTION /* nothing */
|
#define HAYWIRE_EXTERN __declspec(dllimport)
|
||||||
|
#else
|
||||||
|
/* Building static library. */
|
||||||
|
#define HAYWIRE_EXTERN /* nothing */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define HAYWIRE_CALLING_CONVENTION __cdecl
|
||||||
|
#else
|
||||||
|
/* Building static library. */
|
||||||
|
#define HAYWIRE_EXTERN /* nothing */
|
||||||
|
#define HAYWIRE_CALLING_CONVENTION /* nothing */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Informational 1xx */
|
/* Informational 1xx */
|
||||||
|
@ -93,100 +93,107 @@ extern "C" {
|
||||||
|
|
||||||
/* Request Methods */
|
/* Request Methods */
|
||||||
#define HW_HTTP_METHOD_MAP(XX) \
|
#define HW_HTTP_METHOD_MAP(XX) \
|
||||||
XX(0, DELETE, DELETE) \
|
XX(0, DELETE, DELETE) \
|
||||||
XX(1, GET, GET) \
|
XX(1, GET, GET) \
|
||||||
XX(2, HEAD, HEAD) \
|
XX(2, HEAD, HEAD) \
|
||||||
XX(3, POST, POST) \
|
XX(3, POST, POST) \
|
||||||
XX(4, PUT, PUT) \
|
XX(4, PUT, PUT) \
|
||||||
/* pathological */ \
|
/* pathological */ \
|
||||||
XX(5, CONNECT, CONNECT) \
|
XX(5, CONNECT, CONNECT) \
|
||||||
XX(6, OPTIONS, OPTIONS) \
|
XX(6, OPTIONS, OPTIONS) \
|
||||||
XX(7, TRACE, TRACE) \
|
XX(7, TRACE, TRACE) \
|
||||||
/* webdav */ \
|
/* webdav */ \
|
||||||
XX(8, COPY, COPY) \
|
XX(8, COPY, COPY) \
|
||||||
XX(9, LOCK, LOCK) \
|
XX(9, LOCK, LOCK) \
|
||||||
XX(10, MKCOL, MKCOL) \
|
XX(10, MKCOL, MKCOL) \
|
||||||
XX(11, MOVE, MOVE) \
|
XX(11, MOVE, MOVE) \
|
||||||
XX(12, PROPFIND, PROPFIND) \
|
XX(12, PROPFIND, PROPFIND) \
|
||||||
XX(13, PROPPATCH, PROPPATCH) \
|
XX(13, PROPPATCH, PROPPATCH) \
|
||||||
XX(14, SEARCH, SEARCH) \
|
XX(14, SEARCH, SEARCH) \
|
||||||
XX(15, UNLOCK, UNLOCK) \
|
XX(15, UNLOCK, UNLOCK) \
|
||||||
/* subversion */ \
|
/* subversion */ \
|
||||||
XX(16, REPORT, REPORT) \
|
XX(16, REPORT, REPORT) \
|
||||||
XX(17, MKACTIVITY, MKACTIVITY) \
|
XX(17, MKACTIVITY, MKACTIVITY) \
|
||||||
XX(18, CHECKOUT, CHECKOUT) \
|
XX(18, CHECKOUT, CHECKOUT) \
|
||||||
XX(19, MERGE, MERGE) \
|
XX(19, MERGE, MERGE) \
|
||||||
/* upnp */ \
|
/* upnp */ \
|
||||||
XX(20, MSEARCH, M-SEARCH) \
|
XX(20, MSEARCH, M - SEARCH) \
|
||||||
XX(21, NOTIFY, NOTIFY) \
|
XX(21, NOTIFY, NOTIFY) \
|
||||||
XX(22, SUBSCRIBE, SUBSCRIBE) \
|
XX(22, SUBSCRIBE, SUBSCRIBE) \
|
||||||
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
|
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
|
||||||
/* RFC-5789 */ \
|
/* RFC-5789 */ \
|
||||||
XX(24, PATCH, PATCH) \
|
XX(24, PATCH, PATCH) \
|
||||||
XX(25, PURGE, PURGE) \
|
XX(25, PURGE, PURGE)
|
||||||
|
|
||||||
enum hw_http_method
|
enum hw_http_method {
|
||||||
{
|
|
||||||
#define XX(num, name, string) HW_HTTP_##name = num,
|
#define XX(num, name, string) HW_HTTP_##name = num,
|
||||||
HW_HTTP_METHOD_MAP(XX)
|
HW_HTTP_METHOD_MAP(XX)
|
||||||
#undef XX
|
#undef XX
|
||||||
};
|
};
|
||||||
|
|
||||||
#define STRLENOF(s) strlen(s)
|
#define STRLENOF(s) strlen(s)
|
||||||
#define SETSTRING(s,val) s.value=val; s.length=STRLENOF(val)
|
#define SETSTRING(s, val) \
|
||||||
#define APPENDSTRING(s,val) memcpy((char*)s->value + s->length, val, STRLENOF(val)); s->length+=STRLENOF(val)
|
s.value = val; \
|
||||||
|
s.length = STRLENOF(val)
|
||||||
|
#define APPENDSTRING(s, val) \
|
||||||
|
memcpy((char *)s->value + s->length, val, STRLENOF(val)); \
|
||||||
|
s->length += STRLENOF(val)
|
||||||
|
|
||||||
typedef void* hw_http_response;
|
typedef void *hw_http_response;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
char *value;
|
||||||
char* value;
|
|
||||||
size_t length;
|
size_t length;
|
||||||
} hw_string;
|
} hw_string;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
char *http_listen_address;
|
||||||
char* http_listen_address;
|
|
||||||
unsigned int http_listen_port;
|
unsigned int http_listen_port;
|
||||||
unsigned int thread_count;
|
unsigned int thread_count;
|
||||||
char* balancer;
|
char *balancer;
|
||||||
char* parser;
|
char *parser;
|
||||||
bool tcp_nodelay;
|
bool tcp_nodelay;
|
||||||
unsigned int listen_backlog;
|
unsigned int listen_backlog;
|
||||||
unsigned int max_request_size;
|
unsigned int max_request_size;
|
||||||
} configuration;
|
} configuration;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
unsigned short http_major;
|
unsigned short http_major;
|
||||||
unsigned short http_minor;
|
unsigned short http_minor;
|
||||||
unsigned char method;
|
unsigned char method;
|
||||||
int keep_alive;
|
int keep_alive;
|
||||||
hw_string* url;
|
hw_string *url;
|
||||||
void* headers;
|
void *headers;
|
||||||
hw_string* body;
|
hw_string *body;
|
||||||
size_t body_length;
|
size_t body_length;
|
||||||
enum {OK, SIZE_EXCEEDED, BAD_REQUEST, INTERNAL_ERROR} state;
|
enum {
|
||||||
|
OK,
|
||||||
|
SIZE_EXCEEDED,
|
||||||
|
BAD_REQUEST,
|
||||||
|
INTERNAL_ERROR
|
||||||
|
} state;
|
||||||
} http_request;
|
} http_request;
|
||||||
|
|
||||||
typedef void (HAYWIRE_CALLING_CONVENTION *http_request_callback)(http_request* request, hw_http_response* response, void* user_data);
|
typedef void(HAYWIRE_CALLING_CONVENTION *http_request_callback)(http_request *request, hw_http_response *response,
|
||||||
typedef void (HAYWIRE_CALLING_CONVENTION *http_response_complete_callback)(void* user_data);
|
void *user_data);
|
||||||
|
typedef void(HAYWIRE_CALLING_CONVENTION *http_response_complete_callback)(void *user_data);
|
||||||
|
|
||||||
HAYWIRE_EXTERN int hw_init_from_config(char* configuration_filename);
|
HAYWIRE_EXTERN int hw_init_from_config(char *configuration_filename);
|
||||||
HAYWIRE_EXTERN int hw_init_with_config(configuration* config);
|
HAYWIRE_EXTERN int hw_init_with_config(configuration *config);
|
||||||
HAYWIRE_EXTERN int hw_http_open();
|
HAYWIRE_EXTERN int hw_http_open();
|
||||||
HAYWIRE_EXTERN void free_http_server();
|
HAYWIRE_EXTERN void free_http_server();
|
||||||
HAYWIRE_EXTERN void hw_http_add_route(char* route, http_request_callback callback, void* user_data);
|
HAYWIRE_EXTERN void hw_http_add_route(char *route, http_request_callback callback, void *user_data);
|
||||||
HAYWIRE_EXTERN hw_string* hw_get_header(http_request* request, hw_string* key);
|
HAYWIRE_EXTERN hw_string *hw_get_header(http_request *request, hw_string *key);
|
||||||
|
|
||||||
HAYWIRE_EXTERN void hw_free_http_response(hw_http_response* response);
|
HAYWIRE_EXTERN void hw_free_http_response(hw_http_response *response);
|
||||||
HAYWIRE_EXTERN void hw_set_http_version(hw_http_response* response, unsigned short major, unsigned short minor);
|
HAYWIRE_EXTERN void hw_set_http_version(hw_http_response *response, unsigned short major, unsigned short minor);
|
||||||
HAYWIRE_EXTERN void hw_set_response_status_code(hw_http_response* response, hw_string* status_code);
|
HAYWIRE_EXTERN void hw_set_response_status_code(hw_http_response *response, hw_string *status_code);
|
||||||
HAYWIRE_EXTERN void hw_set_response_header(hw_http_response* response, hw_string* name, hw_string* value);
|
HAYWIRE_EXTERN void hw_set_response_header(hw_http_response *response, hw_string *name, hw_string *value);
|
||||||
HAYWIRE_EXTERN void hw_set_body(hw_http_response* response, hw_string* body);
|
HAYWIRE_EXTERN void hw_set_body(hw_http_response *response, hw_string *body);
|
||||||
HAYWIRE_EXTERN void hw_http_response_send(hw_http_response* response, void* user_data, http_response_complete_callback callback);
|
HAYWIRE_EXTERN void hw_http_response_send(hw_http_response *response, void *user_data,
|
||||||
|
http_response_complete_callback callback);
|
||||||
HAYWIRE_EXTERN void hw_http_response_send_error(hw_http_response *response, const char *error, const char *err_msg);
|
HAYWIRE_EXTERN void hw_http_response_send_error(hw_http_response *response, const char *error, const char *err_msg);
|
||||||
HAYWIRE_EXTERN void hw_print_request_headers(http_request* request);
|
HAYWIRE_EXTERN void hw_print_request_headers(http_request *request);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,17 @@
|
||||||
/* Strip whitespace chars off end of given string, in place. Return s. */
|
/* Strip whitespace chars off end of given string, in place. Return s. */
|
||||||
static char *rstrip(char *s) {
|
static char *rstrip(char *s) {
|
||||||
char *p = s + strlen(s);
|
char *p = s + strlen(s);
|
||||||
while (p > s && isspace(*--p))
|
while (p > s && isspace(*--p)) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return pointer to first non-whitespace char in given string. */
|
/* Return pointer to first non-whitespace char in given string. */
|
||||||
static char *lskip(const char *s) {
|
static char *lskip(const char *s) {
|
||||||
while (*s && isspace(*s))
|
while (*s && isspace(*s)) {
|
||||||
s++;
|
s++;
|
||||||
|
}
|
||||||
return (char *)s;
|
return (char *)s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +80,9 @@ int ini_parse_file(FILE *file, int (*handler)(void *, const char *, const char *
|
||||||
else if (*prev_name && *start && start > line) {
|
else if (*prev_name && *start && start > line) {
|
||||||
/* Non-black line with leading whitespace, treat as continuation
|
/* Non-black line with leading whitespace, treat as continuation
|
||||||
of previous name's value (as per Python ConfigParser). */
|
of previous name's value (as per Python ConfigParser). */
|
||||||
if (!handler(user, section, prev_name, start) && !error)
|
if (!handler(user, section, prev_name, start) && !error) {
|
||||||
error = lineno;
|
error = lineno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (*start == '[') {
|
else if (*start == '[') {
|
||||||
|
@ -104,14 +107,16 @@ int ini_parse_file(FILE *file, int (*handler)(void *, const char *, const char *
|
||||||
name = rstrip(start);
|
name = rstrip(start);
|
||||||
value = lskip(end + 1);
|
value = lskip(end + 1);
|
||||||
end = find_char_or_comment(value, '\0');
|
end = find_char_or_comment(value, '\0');
|
||||||
if (*end == ';')
|
if (*end == ';') {
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
|
}
|
||||||
rstrip(value);
|
rstrip(value);
|
||||||
|
|
||||||
/* Valid name[=:]value pair found, call handler */
|
/* Valid name[=:]value pair found, call handler */
|
||||||
strncpy0(prev_name, name, sizeof(prev_name));
|
strncpy0(prev_name, name, sizeof(prev_name));
|
||||||
if (!handler(user, section, name, value) && !error)
|
if (!handler(user, section, name, value) && !error) {
|
||||||
error = lineno;
|
error = lineno;
|
||||||
|
}
|
||||||
} else if (!error) {
|
} else if (!error) {
|
||||||
/* No '=' or ':' found on name[=:]value line */
|
/* No '=' or ':' found on name[=:]value line */
|
||||||
error = lineno;
|
error = lineno;
|
||||||
|
@ -128,8 +133,9 @@ int ini_parse(const char *filename, int (*handler)(void *, const char *, const c
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
file = fopen(filename, "r");
|
file = fopen(filename, "r");
|
||||||
if (!file)
|
if (!file) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
error = ini_parse_file(file, handler, user);
|
error = ini_parse_file(file, handler, user);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return error;
|
return error;
|
||||||
|
|
|
@ -27,8 +27,9 @@ void ipc_read_cb(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) {
|
||||||
if (tcp_nodelay) {
|
if (tcp_nodelay) {
|
||||||
rc = uv_tcp_nodelay((uv_tcp_t *)ctx->server_handle, 1);
|
rc = uv_tcp_nodelay((uv_tcp_t *)ctx->server_handle, 1);
|
||||||
}
|
}
|
||||||
} else if (type == UV_NAMED_PIPE)
|
} else if (type == UV_NAMED_PIPE) {
|
||||||
rc = uv_pipe_init(loop, (uv_pipe_t *)ctx->server_handle, 0);
|
rc = uv_pipe_init(loop, (uv_pipe_t *)ctx->server_handle, 0);
|
||||||
|
}
|
||||||
|
|
||||||
rc = uv_accept(handle, ctx->server_handle);
|
rc = uv_accept(handle, ctx->server_handle);
|
||||||
uv_close((uv_handle_t *)&ctx->ipc_pipe, NULL);
|
uv_close((uv_handle_t *)&ctx->ipc_pipe, NULL);
|
||||||
|
|
|
@ -36,15 +36,17 @@ void ipc_connection_cb(uv_stream_t *ipc_pipe, int status) {
|
||||||
if (sc->tcp_nodelay) {
|
if (sc->tcp_nodelay) {
|
||||||
rc = uv_tcp_nodelay((uv_tcp_t *)&pc->peer_handle, 1);
|
rc = uv_tcp_nodelay((uv_tcp_t *)&pc->peer_handle, 1);
|
||||||
}
|
}
|
||||||
} else if (ipc_pipe->type == UV_NAMED_PIPE)
|
} else if (ipc_pipe->type == UV_NAMED_PIPE) {
|
||||||
rc = uv_pipe_init(loop, (uv_pipe_t *)&pc->peer_handle, 1);
|
rc = uv_pipe_init(loop, (uv_pipe_t *)&pc->peer_handle, 1);
|
||||||
|
}
|
||||||
|
|
||||||
rc = uv_accept(ipc_pipe, (uv_stream_t *)&pc->peer_handle);
|
rc = uv_accept(ipc_pipe, (uv_stream_t *)&pc->peer_handle);
|
||||||
rc = uv_write2(
|
rc = uv_write2(
|
||||||
&pc->write_req, (uv_stream_t *)&pc->peer_handle, &buf, 1, (uv_stream_t *)&sc->server_handle, ipc_write_cb);
|
&pc->write_req, (uv_stream_t *)&pc->peer_handle, &buf, 1, (uv_stream_t *)&sc->server_handle, ipc_write_cb);
|
||||||
|
|
||||||
if (--sc->num_connects == 0)
|
if (--sc->num_connects == 0) {
|
||||||
uv_close((uv_handle_t *)ipc_pipe, NULL);
|
uv_close((uv_handle_t *)ipc_pipe, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void print_configuration();
|
extern void print_configuration();
|
||||||
|
@ -81,13 +83,15 @@ void start_connection_dispatching(uv_handle_type type, unsigned int num_servers,
|
||||||
rc = uv_pipe_bind(&ctx.ipc_pipe, "HAYWIRE_CONNECTION_DISPATCH_PIPE_NAME");
|
rc = uv_pipe_bind(&ctx.ipc_pipe, "HAYWIRE_CONNECTION_DISPATCH_PIPE_NAME");
|
||||||
rc = uv_listen((uv_stream_t *)&ctx.ipc_pipe, listen_backlog, ipc_connection_cb);
|
rc = uv_listen((uv_stream_t *)&ctx.ipc_pipe, listen_backlog, ipc_connection_cb);
|
||||||
|
|
||||||
for (i = 0; i < num_servers; i++)
|
for (i = 0; i < num_servers; i++) {
|
||||||
uv_sem_post(&servers[i].semaphore);
|
uv_sem_post(&servers[i].semaphore);
|
||||||
|
}
|
||||||
|
|
||||||
rc = uv_run(loop, UV_RUN_DEFAULT);
|
rc = uv_run(loop, UV_RUN_DEFAULT);
|
||||||
uv_close((uv_handle_t *)&ctx.server_handle, NULL);
|
uv_close((uv_handle_t *)&ctx.server_handle, NULL);
|
||||||
rc = uv_run(loop, UV_RUN_DEFAULT);
|
rc = uv_run(loop, UV_RUN_DEFAULT);
|
||||||
|
|
||||||
for (i = 0; i < num_servers; i++)
|
for (i = 0; i < num_servers; i++) {
|
||||||
uv_sem_wait(&servers[i].semaphore);
|
uv_sem_wait(&servers[i].semaphore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -758,10 +758,12 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CURRENT_STATE() == s_header_field)
|
if (CURRENT_STATE() == s_header_field) {
|
||||||
header_field_mark = data;
|
header_field_mark = data;
|
||||||
if (CURRENT_STATE() == s_header_value)
|
}
|
||||||
|
if (CURRENT_STATE() == s_header_value) {
|
||||||
header_value_mark = data;
|
header_value_mark = data;
|
||||||
|
}
|
||||||
switch (CURRENT_STATE()) {
|
switch (CURRENT_STATE()) {
|
||||||
case s_req_path:
|
case s_req_path:
|
||||||
case s_req_schema:
|
case s_req_schema:
|
||||||
|
@ -786,8 +788,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
for (p = data; p != data + len; p++) {
|
for (p = data; p != data + len; p++) {
|
||||||
ch = *p;
|
ch = *p;
|
||||||
|
|
||||||
if (PARSING_HEADER(CURRENT_STATE()))
|
if (PARSING_HEADER(CURRENT_STATE())) {
|
||||||
COUNT_HEADER_SIZE(1);
|
COUNT_HEADER_SIZE(1);
|
||||||
|
}
|
||||||
|
|
||||||
switch (CURRENT_STATE()) {
|
switch (CURRENT_STATE()) {
|
||||||
|
|
||||||
|
@ -795,15 +798,17 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
/* this state is used after a 'Connection: close' message
|
/* this state is used after a 'Connection: close' message
|
||||||
* the parser will error out if it reads another message
|
* the parser will error out if it reads another message
|
||||||
*/
|
*/
|
||||||
if (LIKELY(ch == CR || ch == LF))
|
if (LIKELY(ch == CR || ch == LF)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
SET_ERRNO(HPE_CLOSED_CONNECTION);
|
SET_ERRNO(HPE_CLOSED_CONNECTION);
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
case s_start_req_or_res: {
|
case s_start_req_or_res: {
|
||||||
if (ch == CR || ch == LF)
|
if (ch == CR || ch == LF) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
parser->flags = 0;
|
parser->flags = 0;
|
||||||
parser->content_length = ULLONG_MAX;
|
parser->content_length = ULLONG_MAX;
|
||||||
|
|
||||||
|
@ -1028,8 +1033,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case s_start_req: {
|
case s_start_req: {
|
||||||
if (ch == CR || ch == LF)
|
if (ch == CR || ch == LF) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
parser->flags = 0;
|
parser->flags = 0;
|
||||||
parser->content_length = ULLONG_MAX;
|
parser->content_length = ULLONG_MAX;
|
||||||
|
|
||||||
|
@ -1177,8 +1183,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
}
|
}
|
||||||
|
|
||||||
case s_req_spaces_before_url: {
|
case s_req_spaces_before_url: {
|
||||||
if (ch == ' ')
|
if (ch == ' ') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
MARK(url);
|
MARK(url);
|
||||||
if (parser->method == HTTP_CONNECT) {
|
if (parser->method == HTTP_CONNECT) {
|
||||||
|
@ -1419,8 +1426,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
ch = *p;
|
ch = *p;
|
||||||
c = TOKEN(ch);
|
c = TOKEN(ch);
|
||||||
|
|
||||||
if (!c)
|
if (!c) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (parser->header_state) {
|
switch (parser->header_state) {
|
||||||
case h_general:
|
case h_general:
|
||||||
|
@ -1511,8 +1519,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
case h_content_length:
|
case h_content_length:
|
||||||
case h_transfer_encoding:
|
case h_transfer_encoding:
|
||||||
case h_upgrade:
|
case h_upgrade:
|
||||||
if (ch != ' ')
|
if (ch != ' ') {
|
||||||
parser->header_state = h_general;
|
parser->header_state = h_general;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -1539,8 +1548,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
}
|
}
|
||||||
|
|
||||||
case s_header_value_discard_ws:
|
case s_header_value_discard_ws:
|
||||||
if (ch == ' ' || ch == '\t')
|
if (ch == ' ' || ch == '\t') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (ch == CR) {
|
if (ch == CR) {
|
||||||
UPDATE_STATE(s_header_value_discard_ws_almost_done);
|
UPDATE_STATE(s_header_value_discard_ws_almost_done);
|
||||||
|
@ -1644,10 +1654,11 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
p_cr = memchr(p, CR, limit);
|
p_cr = memchr(p, CR, limit);
|
||||||
p_lf = memchr(p, LF, limit);
|
p_lf = memchr(p, LF, limit);
|
||||||
if (p_cr != NULL) {
|
if (p_cr != NULL) {
|
||||||
if (p_lf != NULL && p_cr >= p_lf)
|
if (p_lf != NULL && p_cr >= p_lf) {
|
||||||
p = p_lf;
|
p = p_lf;
|
||||||
else
|
} else {
|
||||||
p = p_cr;
|
p = p_cr;
|
||||||
|
}
|
||||||
} else if (UNLIKELY(p_lf != NULL)) {
|
} else if (UNLIKELY(p_lf != NULL)) {
|
||||||
p = p_lf;
|
p = p_lf;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1666,8 +1677,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
case h_content_length: {
|
case h_content_length: {
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
|
|
||||||
if (ch == ' ')
|
if (ch == ' ') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (UNLIKELY(!IS_NUM(ch))) {
|
if (UNLIKELY(!IS_NUM(ch))) {
|
||||||
SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
|
SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
|
||||||
|
@ -1754,8 +1766,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case h_transfer_encoding_chunked:
|
case h_transfer_encoding_chunked:
|
||||||
if (ch != ' ')
|
if (ch != ' ') {
|
||||||
h_state = h_general;
|
h_state = h_general;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case h_connection_keep_alive:
|
case h_connection_keep_alive:
|
||||||
|
@ -1786,8 +1799,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
||||||
|
|
||||||
COUNT_HEADER_SIZE(p - start);
|
COUNT_HEADER_SIZE(p - start);
|
||||||
|
|
||||||
if (p == data + len)
|
if (p == data + len) {
|
||||||
--p;
|
--p;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,11 @@ static const char response_404[] = "HTTP/1.1 404 Not Found" CRLF "Server: Haywir
|
||||||
|
|
||||||
static kh_inline khint_t hw_string_hash_func(hw_string *s) {
|
static kh_inline khint_t hw_string_hash_func(hw_string *s) {
|
||||||
khint_t h = s->length > 0 ? (khint_t)*s->value : 0;
|
khint_t h = s->length > 0 ? (khint_t)*s->value : 0;
|
||||||
if (h)
|
if (h) {
|
||||||
for (int i = 0; i < s->length; i++)
|
for (int i = 0; i < s->length; i++) {
|
||||||
h = (h << 5) - h + (khint_t) * (s->value + i);
|
h = (h << 5) - h + (khint_t) * (s->value + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,9 @@ void hw_set_body(hw_http_response *response, hw_string *body) {
|
||||||
|
|
||||||
int num_chars(int n) {
|
int num_chars(int n) {
|
||||||
int r = 1;
|
int r = 1;
|
||||||
if (n < 0)
|
if (n < 0) {
|
||||||
n = (n == INT_MIN) ? INT_MAX : -n;
|
n = (n == INT_MIN) ? INT_MAX : -n;
|
||||||
|
}
|
||||||
while (n > 9) {
|
while (n > 9) {
|
||||||
n /= 10;
|
n /= 10;
|
||||||
r++;
|
r++;
|
||||||
|
|
|
@ -39,14 +39,14 @@ static uv_tcp_t server;
|
||||||
static http_parser_settings parser_settings;
|
static http_parser_settings parser_settings;
|
||||||
static struct sockaddr_in listen_address;
|
static struct sockaddr_in listen_address;
|
||||||
|
|
||||||
uv_loop_t *uv_loop;
|
uv_loop_t *uv_loop;
|
||||||
void *routes;
|
void *routes;
|
||||||
hw_string* http_v1_0;
|
hw_string *http_v1_0;
|
||||||
hw_string *http_v1_1;
|
hw_string *http_v1_1;
|
||||||
hw_string *server_name;
|
hw_string *server_name;
|
||||||
int listener_count;
|
int listener_count;
|
||||||
uv_async_t *listener_async_handles;
|
uv_async_t *listener_async_handles;
|
||||||
uv_loop_t* listener_event_loops;
|
uv_loop_t *listener_event_loops;
|
||||||
uv_barrier_t *listeners_created_barrier;
|
uv_barrier_t *listeners_created_barrier;
|
||||||
|
|
||||||
int hw_init_with_config(configuration *c) {
|
int hw_init_with_config(configuration *c) {
|
||||||
|
|
|
@ -413,9 +413,11 @@ static const double __ac_HASH_UPPER = 0.77;
|
||||||
*/
|
*/
|
||||||
static kh_inline khint_t __ac_X31_hash_string(const char *s) {
|
static kh_inline khint_t __ac_X31_hash_string(const char *s) {
|
||||||
khint_t h = (khint_t)*s;
|
khint_t h = (khint_t)*s;
|
||||||
if (h)
|
if (h) {
|
||||||
for (++s; *s; ++s)
|
for (++s; *s; ++s) {
|
||||||
h = (h << 5) - h + (khint_t)*s;
|
h = (h << 5) - h + (khint_t)*s;
|
||||||
|
}
|
||||||
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
/*! @function
|
/*! @function
|
||||||
|
|
|
@ -141,8 +141,9 @@ static const char *get_token_to_eol(const char *buf, const char *buf_end, const
|
||||||
;
|
;
|
||||||
int found;
|
int found;
|
||||||
buf = findchar_fast(buf, buf_end, ranges1, sizeof(ranges1) - 1, &found);
|
buf = findchar_fast(buf, buf_end, ranges1, sizeof(ranges1) - 1, &found);
|
||||||
if (found)
|
if (found) {
|
||||||
goto FOUND_CTL;
|
goto FOUND_CTL;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
/* find non-printable char within the next 8 bytes, this is the hottest code; manually inlined */
|
/* find non-printable char within the next 8 bytes, this is the hottest code; manually inlined */
|
||||||
while (likely(buf_end - buf >= 8)) {
|
while (likely(buf_end - buf >= 8)) {
|
||||||
|
@ -483,8 +484,9 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
||||||
case CHUNKED_IN_CHUNK_SIZE:
|
case CHUNKED_IN_CHUNK_SIZE:
|
||||||
for (;; ++src) {
|
for (;; ++src) {
|
||||||
int v;
|
int v;
|
||||||
if (src == bufsz)
|
if (src == bufsz) {
|
||||||
goto Exit;
|
goto Exit;
|
||||||
|
}
|
||||||
if ((v = decode_hex(buf[src])) == -1) {
|
if ((v = decode_hex(buf[src])) == -1) {
|
||||||
if (decoder->_hex_count == 0) {
|
if (decoder->_hex_count == 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
@ -505,10 +507,12 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
||||||
case CHUNKED_IN_CHUNK_EXT:
|
case CHUNKED_IN_CHUNK_EXT:
|
||||||
/* RFC 7230 A.2 "Line folding in chunk extensions is disallowed" */
|
/* RFC 7230 A.2 "Line folding in chunk extensions is disallowed" */
|
||||||
for (;; ++src) {
|
for (;; ++src) {
|
||||||
if (src == bufsz)
|
if (src == bufsz) {
|
||||||
goto Exit;
|
goto Exit;
|
||||||
if (buf[src] == '\012')
|
}
|
||||||
|
if (buf[src] == '\012') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
++src;
|
++src;
|
||||||
if (decoder->bytes_left_in_chunk == 0) {
|
if (decoder->bytes_left_in_chunk == 0) {
|
||||||
|
@ -524,15 +528,17 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
||||||
case CHUNKED_IN_CHUNK_DATA: {
|
case CHUNKED_IN_CHUNK_DATA: {
|
||||||
size_t avail = bufsz - src;
|
size_t avail = bufsz - src;
|
||||||
if (avail < decoder->bytes_left_in_chunk) {
|
if (avail < decoder->bytes_left_in_chunk) {
|
||||||
if (dst != src)
|
if (dst != src) {
|
||||||
memmove(buf + dst, buf + src, avail);
|
memmove(buf + dst, buf + src, avail);
|
||||||
|
}
|
||||||
src += avail;
|
src += avail;
|
||||||
dst += avail;
|
dst += avail;
|
||||||
decoder->bytes_left_in_chunk -= avail;
|
decoder->bytes_left_in_chunk -= avail;
|
||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
if (dst != src)
|
if (dst != src) {
|
||||||
memmove(buf + dst, buf + src, decoder->bytes_left_in_chunk);
|
memmove(buf + dst, buf + src, decoder->bytes_left_in_chunk);
|
||||||
|
}
|
||||||
src += decoder->bytes_left_in_chunk;
|
src += decoder->bytes_left_in_chunk;
|
||||||
dst += decoder->bytes_left_in_chunk;
|
dst += decoder->bytes_left_in_chunk;
|
||||||
decoder->bytes_left_in_chunk = 0;
|
decoder->bytes_left_in_chunk = 0;
|
||||||
|
@ -541,10 +547,12 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
||||||
/* fallthru */
|
/* fallthru */
|
||||||
case CHUNKED_IN_CHUNK_CRLF:
|
case CHUNKED_IN_CHUNK_CRLF:
|
||||||
for (;; ++src) {
|
for (;; ++src) {
|
||||||
if (src == bufsz)
|
if (src == bufsz) {
|
||||||
goto Exit;
|
goto Exit;
|
||||||
if (buf[src] != '\015')
|
}
|
||||||
|
if (buf[src] != '\015') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (buf[src] != '\012') {
|
if (buf[src] != '\012') {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
@ -555,21 +563,26 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
||||||
break;
|
break;
|
||||||
case CHUNKED_IN_TRAILERS_LINE_HEAD:
|
case CHUNKED_IN_TRAILERS_LINE_HEAD:
|
||||||
for (;; ++src) {
|
for (;; ++src) {
|
||||||
if (src == bufsz)
|
if (src == bufsz) {
|
||||||
goto Exit;
|
goto Exit;
|
||||||
if (buf[src] != '\015')
|
}
|
||||||
|
if (buf[src] != '\015') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (buf[src++] == '\012')
|
if (buf[src++] == '\012') {
|
||||||
goto Complete;
|
goto Complete;
|
||||||
|
}
|
||||||
decoder->_state = CHUNKED_IN_TRAILERS_LINE_MIDDLE;
|
decoder->_state = CHUNKED_IN_TRAILERS_LINE_MIDDLE;
|
||||||
/* fallthru */
|
/* fallthru */
|
||||||
case CHUNKED_IN_TRAILERS_LINE_MIDDLE:
|
case CHUNKED_IN_TRAILERS_LINE_MIDDLE:
|
||||||
for (;; ++src) {
|
for (;; ++src) {
|
||||||
if (src == bufsz)
|
if (src == bufsz) {
|
||||||
goto Exit;
|
goto Exit;
|
||||||
if (buf[src] == '\012')
|
}
|
||||||
|
if (buf[src] == '\012') {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
++src;
|
++src;
|
||||||
decoder->_state = CHUNKED_IN_TRAILERS_LINE_HEAD;
|
decoder->_state = CHUNKED_IN_TRAILERS_LINE_HEAD;
|
||||||
|
@ -582,8 +595,9 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
||||||
Complete:
|
Complete:
|
||||||
ret = bufsz - src;
|
ret = bufsz - src;
|
||||||
Exit:
|
Exit:
|
||||||
if (dst != src)
|
if (dst != src) {
|
||||||
memmove(buf + dst, buf + src, bufsz - src);
|
memmove(buf + dst, buf + src, bufsz - src);
|
||||||
|
}
|
||||||
*_bufsz = dst;
|
*_bufsz = dst;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,6 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
|
||||||
void user_uninit() {
|
void user_uninit() {
|
||||||
task_manager_exit();
|
task_manager_exit();
|
||||||
free_http_server();
|
free_http_server();
|
||||||
uv_sleep(1000);
|
|
||||||
mq_uninit();
|
mq_uninit();
|
||||||
zlog_fini();
|
zlog_fini();
|
||||||
uv_loop_close(get_task_manager());
|
uv_loop_close(get_task_manager());
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -257,7 +257,7 @@ static void opendhcp_http_info(http_request *request, hw_http_response *response
|
||||||
|
|
||||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||||
|
|
||||||
if(req == nullptr) {
|
if (req == nullptr) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ static void opendhcp_http_get_userinfo(http_request *request, hw_http_response *
|
||||||
|
|
||||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||||
|
|
||||||
if(req == nullptr) {
|
if (req == nullptr) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -343,7 +343,7 @@ static void opendhcp_http_get_alluser(http_request *request, hw_http_response *r
|
||||||
|
|
||||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||||
|
|
||||||
if(req == nullptr) {
|
if (req == nullptr) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue