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'
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
InsertBraces: true
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: Consecutive
|
||||
AlignConsecutiveAssignments: Consecutive
|
||||
|
|
|
@ -23,8 +23,8 @@ endif (UNIX)
|
|||
INCLUDE_DIRECTORIES(./include ./src ../libs/include)
|
||||
|
||||
file(GLOB_RECURSE HW_HEADS
|
||||
./src/haywire/*.h
|
||||
./src/haywire/configuration/*.h)
|
||||
./src/haywire/*.h
|
||||
./src/haywire/configuration/*.h)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(src/haywire HW_SRC)
|
||||
AUX_SOURCE_DIRECTORY(src/haywire/configuration HW_SRC)
|
||||
|
@ -34,6 +34,6 @@ INCLUDE_DIRECTORIES(. ./include)
|
|||
#find_package(Threads REQUIRED)
|
||||
|
||||
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>
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Windows - set up dll import/export decorators. */
|
||||
#ifdef BUILDING_HAYWIRE_SHARED
|
||||
/* Building shared library. */
|
||||
#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
|
||||
/* Windows - set up dll import/export decorators. */
|
||||
#ifdef BUILDING_HAYWIRE_SHARED
|
||||
/* Building shared library. */
|
||||
#define HAYWIRE_EXTERN __declspec(dllexport)
|
||||
#else
|
||||
/* Building static library. */
|
||||
#define HAYWIRE_EXTERN /* nothing */
|
||||
#define HAYWIRE_CALLING_CONVENTION /* nothing */
|
||||
#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
|
||||
/* Building static library. */
|
||||
#define HAYWIRE_EXTERN /* nothing */
|
||||
#define HAYWIRE_CALLING_CONVENTION /* nothing */
|
||||
#endif
|
||||
|
||||
/* Informational 1xx */
|
||||
|
@ -93,100 +93,107 @@ extern "C" {
|
|||
|
||||
/* Request Methods */
|
||||
#define HW_HTTP_METHOD_MAP(XX) \
|
||||
XX(0, DELETE, DELETE) \
|
||||
XX(1, GET, GET) \
|
||||
XX(2, HEAD, HEAD) \
|
||||
XX(3, POST, POST) \
|
||||
XX(4, PUT, PUT) \
|
||||
/* pathological */ \
|
||||
XX(5, CONNECT, CONNECT) \
|
||||
XX(6, OPTIONS, OPTIONS) \
|
||||
XX(7, TRACE, TRACE) \
|
||||
/* webdav */ \
|
||||
XX(8, COPY, COPY) \
|
||||
XX(9, LOCK, LOCK) \
|
||||
XX(10, MKCOL, MKCOL) \
|
||||
XX(11, MOVE, MOVE) \
|
||||
XX(12, PROPFIND, PROPFIND) \
|
||||
XX(13, PROPPATCH, PROPPATCH) \
|
||||
XX(14, SEARCH, SEARCH) \
|
||||
XX(15, UNLOCK, UNLOCK) \
|
||||
/* subversion */ \
|
||||
XX(16, REPORT, REPORT) \
|
||||
XX(17, MKACTIVITY, MKACTIVITY) \
|
||||
XX(18, CHECKOUT, CHECKOUT) \
|
||||
XX(19, MERGE, MERGE) \
|
||||
/* upnp */ \
|
||||
XX(20, MSEARCH, M-SEARCH) \
|
||||
XX(21, NOTIFY, NOTIFY) \
|
||||
XX(22, SUBSCRIBE, SUBSCRIBE) \
|
||||
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
|
||||
/* RFC-5789 */ \
|
||||
XX(24, PATCH, PATCH) \
|
||||
XX(25, PURGE, PURGE) \
|
||||
XX(0, DELETE, DELETE) \
|
||||
XX(1, GET, GET) \
|
||||
XX(2, HEAD, HEAD) \
|
||||
XX(3, POST, POST) \
|
||||
XX(4, PUT, PUT) \
|
||||
/* pathological */ \
|
||||
XX(5, CONNECT, CONNECT) \
|
||||
XX(6, OPTIONS, OPTIONS) \
|
||||
XX(7, TRACE, TRACE) \
|
||||
/* webdav */ \
|
||||
XX(8, COPY, COPY) \
|
||||
XX(9, LOCK, LOCK) \
|
||||
XX(10, MKCOL, MKCOL) \
|
||||
XX(11, MOVE, MOVE) \
|
||||
XX(12, PROPFIND, PROPFIND) \
|
||||
XX(13, PROPPATCH, PROPPATCH) \
|
||||
XX(14, SEARCH, SEARCH) \
|
||||
XX(15, UNLOCK, UNLOCK) \
|
||||
/* subversion */ \
|
||||
XX(16, REPORT, REPORT) \
|
||||
XX(17, MKACTIVITY, MKACTIVITY) \
|
||||
XX(18, CHECKOUT, CHECKOUT) \
|
||||
XX(19, MERGE, MERGE) \
|
||||
/* upnp */ \
|
||||
XX(20, MSEARCH, M - SEARCH) \
|
||||
XX(21, NOTIFY, NOTIFY) \
|
||||
XX(22, SUBSCRIBE, SUBSCRIBE) \
|
||||
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) \
|
||||
/* RFC-5789 */ \
|
||||
XX(24, PATCH, PATCH) \
|
||||
XX(25, PURGE, PURGE)
|
||||
|
||||
enum hw_http_method
|
||||
{
|
||||
enum hw_http_method {
|
||||
#define XX(num, name, string) HW_HTTP_##name = num,
|
||||
HW_HTTP_METHOD_MAP(XX)
|
||||
#undef XX
|
||||
};
|
||||
|
||||
#define STRLENOF(s) strlen(s)
|
||||
#define SETSTRING(s,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)
|
||||
#define SETSTRING(s, 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
|
||||
{
|
||||
char* value;
|
||||
typedef struct {
|
||||
char *value;
|
||||
size_t length;
|
||||
} hw_string;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* http_listen_address;
|
||||
typedef struct {
|
||||
char *http_listen_address;
|
||||
unsigned int http_listen_port;
|
||||
unsigned int thread_count;
|
||||
char* balancer;
|
||||
char* parser;
|
||||
bool tcp_nodelay;
|
||||
char *balancer;
|
||||
char *parser;
|
||||
bool tcp_nodelay;
|
||||
unsigned int listen_backlog;
|
||||
unsigned int max_request_size;
|
||||
} configuration;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
unsigned short http_major;
|
||||
unsigned short http_minor;
|
||||
unsigned char method;
|
||||
int keep_alive;
|
||||
hw_string* url;
|
||||
void* headers;
|
||||
hw_string* body;
|
||||
size_t body_length;
|
||||
enum {OK, SIZE_EXCEEDED, BAD_REQUEST, INTERNAL_ERROR} state;
|
||||
unsigned char method;
|
||||
int keep_alive;
|
||||
hw_string *url;
|
||||
void *headers;
|
||||
hw_string *body;
|
||||
size_t body_length;
|
||||
enum {
|
||||
OK,
|
||||
SIZE_EXCEEDED,
|
||||
BAD_REQUEST,
|
||||
INTERNAL_ERROR
|
||||
} state;
|
||||
} 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_response_complete_callback)(void* user_data);
|
||||
typedef void(HAYWIRE_CALLING_CONVENTION *http_request_callback)(http_request *request, hw_http_response *response,
|
||||
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_with_config(configuration* config);
|
||||
HAYWIRE_EXTERN int hw_http_open();
|
||||
HAYWIRE_EXTERN void free_http_server();
|
||||
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 int hw_init_from_config(char *configuration_filename);
|
||||
HAYWIRE_EXTERN int hw_init_with_config(configuration *config);
|
||||
HAYWIRE_EXTERN int hw_http_open();
|
||||
HAYWIRE_EXTERN void free_http_server();
|
||||
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 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_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_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_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_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_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_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
|
||||
}
|
||||
|
|
|
@ -21,15 +21,17 @@
|
|||
/* Strip whitespace chars off end of given string, in place. Return s. */
|
||||
static char *rstrip(char *s) {
|
||||
char *p = s + strlen(s);
|
||||
while (p > s && isspace(*--p))
|
||||
while (p > s && isspace(*--p)) {
|
||||
*p = '\0';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Return pointer to first non-whitespace char in given string. */
|
||||
static char *lskip(const char *s) {
|
||||
while (*s && isspace(*s))
|
||||
while (*s && isspace(*s)) {
|
||||
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) {
|
||||
/* Non-black line with leading whitespace, treat as continuation
|
||||
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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (*start == '[') {
|
||||
|
@ -104,14 +107,16 @@ int ini_parse_file(FILE *file, int (*handler)(void *, const char *, const char *
|
|||
name = rstrip(start);
|
||||
value = lskip(end + 1);
|
||||
end = find_char_or_comment(value, '\0');
|
||||
if (*end == ';')
|
||||
if (*end == ';') {
|
||||
*end = '\0';
|
||||
}
|
||||
rstrip(value);
|
||||
|
||||
/* Valid name[=:]value pair found, call handler */
|
||||
strncpy0(prev_name, name, sizeof(prev_name));
|
||||
if (!handler(user, section, name, value) && !error)
|
||||
if (!handler(user, section, name, value) && !error) {
|
||||
error = lineno;
|
||||
}
|
||||
} else if (!error) {
|
||||
/* No '=' or ':' found on name[=:]value line */
|
||||
error = lineno;
|
||||
|
@ -128,8 +133,9 @@ int ini_parse(const char *filename, int (*handler)(void *, const char *, const c
|
|||
int error;
|
||||
|
||||
file = fopen(filename, "r");
|
||||
if (!file)
|
||||
if (!file) {
|
||||
return -1;
|
||||
}
|
||||
error = ini_parse_file(file, handler, user);
|
||||
fclose(file);
|
||||
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) {
|
||||
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_accept(handle, ctx->server_handle);
|
||||
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) {
|
||||
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_accept(ipc_pipe, (uv_stream_t *)&pc->peer_handle);
|
||||
rc = uv_write2(
|
||||
&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);
|
||||
}
|
||||
}
|
||||
|
||||
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_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);
|
||||
}
|
||||
|
||||
rc = uv_run(loop, UV_RUN_DEFAULT);
|
||||
uv_close((uv_handle_t *)&ctx.server_handle, NULL);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
if (CURRENT_STATE() == s_header_value)
|
||||
}
|
||||
if (CURRENT_STATE() == s_header_value) {
|
||||
header_value_mark = data;
|
||||
}
|
||||
switch (CURRENT_STATE()) {
|
||||
case s_req_path:
|
||||
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++) {
|
||||
ch = *p;
|
||||
|
||||
if (PARSING_HEADER(CURRENT_STATE()))
|
||||
if (PARSING_HEADER(CURRENT_STATE())) {
|
||||
COUNT_HEADER_SIZE(1);
|
||||
}
|
||||
|
||||
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
|
||||
* the parser will error out if it reads another message
|
||||
*/
|
||||
if (LIKELY(ch == CR || ch == LF))
|
||||
if (LIKELY(ch == CR || ch == LF)) {
|
||||
break;
|
||||
}
|
||||
|
||||
SET_ERRNO(HPE_CLOSED_CONNECTION);
|
||||
goto error;
|
||||
|
||||
case s_start_req_or_res: {
|
||||
if (ch == CR || ch == LF)
|
||||
if (ch == CR || ch == LF) {
|
||||
break;
|
||||
}
|
||||
parser->flags = 0;
|
||||
parser->content_length = ULLONG_MAX;
|
||||
|
||||
|
@ -1028,8 +1033,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
|||
break;
|
||||
|
||||
case s_start_req: {
|
||||
if (ch == CR || ch == LF)
|
||||
if (ch == CR || ch == LF) {
|
||||
break;
|
||||
}
|
||||
parser->flags = 0;
|
||||
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: {
|
||||
if (ch == ' ')
|
||||
if (ch == ' ') {
|
||||
break;
|
||||
}
|
||||
|
||||
MARK(url);
|
||||
if (parser->method == HTTP_CONNECT) {
|
||||
|
@ -1419,8 +1426,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
|||
ch = *p;
|
||||
c = TOKEN(ch);
|
||||
|
||||
if (!c)
|
||||
if (!c) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (parser->header_state) {
|
||||
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_transfer_encoding:
|
||||
case h_upgrade:
|
||||
if (ch != ' ')
|
||||
if (ch != ' ') {
|
||||
parser->header_state = h_general;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1539,8 +1548,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
|||
}
|
||||
|
||||
case s_header_value_discard_ws:
|
||||
if (ch == ' ' || ch == '\t')
|
||||
if (ch == ' ' || ch == '\t') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ch == CR) {
|
||||
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_lf = memchr(p, LF, limit);
|
||||
if (p_cr != NULL) {
|
||||
if (p_lf != NULL && p_cr >= p_lf)
|
||||
if (p_lf != NULL && p_cr >= p_lf) {
|
||||
p = p_lf;
|
||||
else
|
||||
} else {
|
||||
p = p_cr;
|
||||
}
|
||||
} else if (UNLIKELY(p_lf != NULL)) {
|
||||
p = p_lf;
|
||||
} else {
|
||||
|
@ -1666,8 +1677,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
|||
case h_content_length: {
|
||||
uint64_t t;
|
||||
|
||||
if (ch == ' ')
|
||||
if (ch == ' ') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (UNLIKELY(!IS_NUM(ch))) {
|
||||
SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
|
||||
|
@ -1754,8 +1766,9 @@ size_t http_parser_execute(http_parser *parser, const http_parser_settings *sett
|
|||
break;
|
||||
|
||||
case h_transfer_encoding_chunked:
|
||||
if (ch != ' ')
|
||||
if (ch != ' ') {
|
||||
h_state = h_general;
|
||||
}
|
||||
break;
|
||||
|
||||
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);
|
||||
|
||||
if (p == data + len)
|
||||
if (p == data + len) {
|
||||
--p;
|
||||
}
|
||||
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) {
|
||||
khint_t h = s->length > 0 ? (khint_t)*s->value : 0;
|
||||
if (h)
|
||||
for (int i = 0; i < s->length; i++)
|
||||
if (h) {
|
||||
for (int i = 0; i < s->length; i++) {
|
||||
h = (h << 5) - h + (khint_t) * (s->value + i);
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,8 +54,9 @@ void hw_set_body(hw_http_response *response, hw_string *body) {
|
|||
|
||||
int num_chars(int n) {
|
||||
int r = 1;
|
||||
if (n < 0)
|
||||
if (n < 0) {
|
||||
n = (n == INT_MIN) ? INT_MAX : -n;
|
||||
}
|
||||
while (n > 9) {
|
||||
n /= 10;
|
||||
r++;
|
||||
|
|
|
@ -39,14 +39,14 @@ static uv_tcp_t server;
|
|||
static http_parser_settings parser_settings;
|
||||
static struct sockaddr_in listen_address;
|
||||
|
||||
uv_loop_t *uv_loop;
|
||||
void *routes;
|
||||
hw_string* http_v1_0;
|
||||
hw_string *http_v1_1;
|
||||
hw_string *server_name;
|
||||
int listener_count;
|
||||
uv_async_t *listener_async_handles;
|
||||
uv_loop_t* listener_event_loops;
|
||||
uv_loop_t *uv_loop;
|
||||
void *routes;
|
||||
hw_string *http_v1_0;
|
||||
hw_string *http_v1_1;
|
||||
hw_string *server_name;
|
||||
int listener_count;
|
||||
uv_async_t *listener_async_handles;
|
||||
uv_loop_t *listener_event_loops;
|
||||
uv_barrier_t *listeners_created_barrier;
|
||||
|
||||
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) {
|
||||
khint_t h = (khint_t)*s;
|
||||
if (h)
|
||||
for (++s; *s; ++s)
|
||||
if (h) {
|
||||
for (++s; *s; ++s) {
|
||||
h = (h << 5) - h + (khint_t)*s;
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
/*! @function
|
||||
|
|
|
@ -141,8 +141,9 @@ static const char *get_token_to_eol(const char *buf, const char *buf_end, const
|
|||
;
|
||||
int found;
|
||||
buf = findchar_fast(buf, buf_end, ranges1, sizeof(ranges1) - 1, &found);
|
||||
if (found)
|
||||
if (found) {
|
||||
goto FOUND_CTL;
|
||||
}
|
||||
#else
|
||||
/* find non-printable char within the next 8 bytes, this is the hottest code; manually inlined */
|
||||
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:
|
||||
for (;; ++src) {
|
||||
int v;
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
}
|
||||
if ((v = decode_hex(buf[src])) == -1) {
|
||||
if (decoder->_hex_count == 0) {
|
||||
ret = -1;
|
||||
|
@ -505,10 +507,12 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
case CHUNKED_IN_CHUNK_EXT:
|
||||
/* RFC 7230 A.2 "Line folding in chunk extensions is disallowed" */
|
||||
for (;; ++src) {
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
if (buf[src] == '\012')
|
||||
}
|
||||
if (buf[src] == '\012') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
++src;
|
||||
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: {
|
||||
size_t avail = bufsz - src;
|
||||
if (avail < decoder->bytes_left_in_chunk) {
|
||||
if (dst != src)
|
||||
if (dst != src) {
|
||||
memmove(buf + dst, buf + src, avail);
|
||||
}
|
||||
src += avail;
|
||||
dst += avail;
|
||||
decoder->bytes_left_in_chunk -= avail;
|
||||
goto Exit;
|
||||
}
|
||||
if (dst != src)
|
||||
if (dst != src) {
|
||||
memmove(buf + dst, buf + src, decoder->bytes_left_in_chunk);
|
||||
}
|
||||
src += decoder->bytes_left_in_chunk;
|
||||
dst += decoder->bytes_left_in_chunk;
|
||||
decoder->bytes_left_in_chunk = 0;
|
||||
|
@ -541,10 +547,12 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
/* fallthru */
|
||||
case CHUNKED_IN_CHUNK_CRLF:
|
||||
for (;; ++src) {
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
if (buf[src] != '\015')
|
||||
}
|
||||
if (buf[src] != '\015') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (buf[src] != '\012') {
|
||||
ret = -1;
|
||||
|
@ -555,21 +563,26 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
break;
|
||||
case CHUNKED_IN_TRAILERS_LINE_HEAD:
|
||||
for (;; ++src) {
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
if (buf[src] != '\015')
|
||||
}
|
||||
if (buf[src] != '\015') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (buf[src++] == '\012')
|
||||
if (buf[src++] == '\012') {
|
||||
goto Complete;
|
||||
}
|
||||
decoder->_state = CHUNKED_IN_TRAILERS_LINE_MIDDLE;
|
||||
/* fallthru */
|
||||
case CHUNKED_IN_TRAILERS_LINE_MIDDLE:
|
||||
for (;; ++src) {
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
if (buf[src] == '\012')
|
||||
}
|
||||
if (buf[src] == '\012') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
++src;
|
||||
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:
|
||||
ret = bufsz - src;
|
||||
Exit:
|
||||
if (dst != src)
|
||||
if (dst != src) {
|
||||
memmove(buf + dst, buf + src, bufsz - src);
|
||||
}
|
||||
*_bufsz = dst;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -125,7 +125,6 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
|
|||
void user_uninit() {
|
||||
task_manager_exit();
|
||||
free_http_server();
|
||||
uv_sleep(1000);
|
||||
mq_uninit();
|
||||
zlog_fini();
|
||||
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));
|
||||
|
||||
if(req == nullptr) {
|
||||
if (req == nullptr) {
|
||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
||||
return;
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ static void opendhcp_http_get_userinfo(http_request *request, hw_http_response *
|
|||
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
|
||||
if(req == nullptr) {
|
||||
if (req == nullptr) {
|
||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
||||
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));
|
||||
|
||||
if(req == nullptr) {
|
||||
if (req == nullptr) {
|
||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue