OCT 重新格式化代码

This commit is contained in:
huangxin 2022-11-08 18:09:54 +08:00
parent b05d9987f1
commit e34c25a0e3
16 changed files with 1208 additions and 975 deletions

View File

@ -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

View File

@ -123,29 +123,30 @@ 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;
@ -156,8 +157,7 @@ typedef struct
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;
@ -166,10 +166,16 @@ typedef struct
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,
void *user_data);
typedef void(HAYWIRE_CALLING_CONVENTION *http_response_complete_callback)(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);
@ -184,7 +190,8 @@ HAYWIRE_EXTERN void hw_set_http_version(hw_http_response* response, unsigned sho
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);

View File

@ -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,9 +80,10 @@ 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 == '[') {
/* A "[section]" line */ /* A "[section]" line */
@ -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;

View File

@ -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);

View File

@ -36,16 +36,18 @@ 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();
/* Set up an IPC pipe server that hands out listen sockets to the worker /* Set up an IPC pipe server that hands out listen sockets to the worker
@ -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);
} }
}

View File

@ -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;
} }

View File

@ -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;
} }

View File

@ -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++;

View File

@ -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

View File

@ -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,11 +507,13 @@ 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) {
if (decoder->consume_trailer) { if (decoder->consume_trailer) {
@ -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,11 +547,13 @@ 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;
goto Exit; goto Exit;
@ -555,22 +563,27 @@ 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;
break; break;
@ -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;
} }

View File

@ -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

View File

@ -74,17 +74,14 @@ struct data7 //cache
{ {
char *mapname; char *mapname;
time_t expiry; time_t expiry;
union union {
{ struct {
struct
{
MYBYTE cType; MYBYTE cType;
MYBYTE dnsType; MYBYTE dnsType;
MYBYTE sockInd; MYBYTE sockInd;
MYBYTE dnsIndex; MYBYTE dnsIndex;
}; };
struct struct {
{
unsigned fixed : 1; unsigned fixed : 1;
unsigned local : 1; unsigned local : 1;
unsigned display : 1; unsigned display : 1;
@ -93,19 +90,16 @@ struct data7 //cache
unsigned dhcpInd : 20; unsigned dhcpInd : 20;
}; };
}; };
union union {
{
char *name; char *name;
MYBYTE *options; MYBYTE *options;
}; };
union union {
{
int bytes; int bytes;
MYDWORD ip; MYDWORD ip;
SOCKADDR_IN *addr; SOCKADDR_IN *addr;
}; };
union union {
{
MYBYTE *response; MYBYTE *response;
char *hostname; char *hostname;
char *query; char *query;
@ -131,8 +125,7 @@ typedef multimap<string, data7*> hostMap;
typedef multimap<time_t, data7 *> expiryMap; typedef multimap<time_t, data7 *> expiryMap;
typedef map<string, data7 *> dhcpMap; typedef map<string, data7 *> dhcpMap;
struct ConnType struct ConnType {
{
SOCKET sock; SOCKET sock;
SOCKADDR_IN addr; SOCKADDR_IN addr;
MYDWORD server; MYDWORD server;
@ -154,7 +147,6 @@ struct ConnType
#define DHCP_MESS_RELEASE 7 #define DHCP_MESS_RELEASE 7
#define DHCP_MESS_INFORM 8 #define DHCP_MESS_INFORM 8
// DHCP OPTIONS // DHCP OPTIONS
#define DHCP_OPTION_PAD 0 #define DHCP_OPTION_PAD 0
#define DHCP_OPTION_NETMASK 1 #define DHCP_OPTION_NETMASK 1
@ -287,30 +279,27 @@ struct ConnType
#define VM_STANFORD 0x5354414EUL #define VM_STANFORD 0x5354414EUL
#define VM_RFC1048 0x63825363UL #define VM_RFC1048 0x63825363UL
struct data3 struct data3 {
{
MYBYTE opt_code; MYBYTE opt_code;
MYBYTE size; MYBYTE size;
MYBYTE value[256]; MYBYTE value[256];
}; };
struct data4 struct data4 {
{
char opName[40]; char opName[40];
MYBYTE opTag; MYBYTE opTag;
MYBYTE opType; MYBYTE opType;
bool permitted; bool permitted;
}; };
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) #if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) \
|| defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
#define MY_MAX_TIME UINT_MAX #define MY_MAX_TIME UINT_MAX
struct data8//client struct data8//client
{ {
union union {
{
MYDWORD filler; MYDWORD filler;
struct struct {
{
unsigned dhcpInd : 20; unsigned dhcpInd : 20;
unsigned bp_hlen : 8; unsigned bp_hlen : 8;
unsigned fixed : 1; unsigned fixed : 1;
@ -328,11 +317,9 @@ struct data8 //client
#define MY_MAX_TIME INT_MAX #define MY_MAX_TIME INT_MAX
struct data8//client struct data8//client
{ {
union union {
{
MYDWORD filler; MYDWORD filler;
struct struct {
{
unsigned dhcpInd : 20; unsigned dhcpInd : 20;
unsigned bp_hlen : 8; unsigned bp_hlen : 8;
unsigned fixed : 1; unsigned fixed : 1;
@ -349,16 +336,14 @@ struct data8 //client
}; };
#endif #endif
struct msg_control struct msg_control {
{
ulong cmsg_len; ulong cmsg_len;
int cmsg_level; int cmsg_level;
int cmsg_type; int cmsg_type;
in_pktinfo pktinfo; in_pktinfo pktinfo;
}; };
struct dhcp_header struct dhcp_header {
{
MYBYTE bp_op; MYBYTE bp_op;
MYBYTE bp_htype; MYBYTE bp_htype;
MYBYTE bp_hlen; MYBYTE bp_hlen;
@ -377,8 +362,7 @@ struct dhcp_header
MYBYTE bp_magic_num[4]; MYBYTE bp_magic_num[4];
}; };
struct dhcp_packet struct dhcp_packet {
{
dhcp_header header; dhcp_header header;
MYBYTE vend_data[1024 - sizeof(dhcp_header)]; MYBYTE vend_data[1024 - sizeof(dhcp_header)];
}; };
@ -408,18 +392,15 @@ struct data14 //rangeSet
MYDWORD targetIP; MYDWORD targetIP;
}; };
struct data15 struct data15 {
{ union {
union
{
//MYDWORD ip; //MYDWORD ip;
unsigned ip : 32; unsigned ip : 32;
MYBYTE octate[4]; MYBYTE octate[4];
}; };
}; };
struct data17 struct data17 {
{
MYBYTE macArray[MAX_RANGE_SETS]; MYBYTE macArray[MAX_RANGE_SETS];
MYBYTE vendArray[MAX_RANGE_SETS]; MYBYTE vendArray[MAX_RANGE_SETS];
MYBYTE userArray[MAX_RANGE_SETS]; MYBYTE userArray[MAX_RANGE_SETS];
@ -430,8 +411,7 @@ struct data17
bool subnetFound; bool subnetFound;
}; };
struct data19 struct data19 {
{
SOCKET sock; SOCKET sock;
socklen_t sockLen; socklen_t sockLen;
SOCKADDR_IN remote; SOCKADDR_IN remote;
@ -441,8 +421,7 @@ struct data19
char *dp; char *dp;
}; };
struct data20 struct data20 {
{
MYBYTE options[sizeof(dhcp_packet)]; MYBYTE options[sizeof(dhcp_packet)];
MYWORD optionSize; MYWORD optionSize;
MYDWORD ip; MYDWORD ip;
@ -453,8 +432,7 @@ struct data20
struct data9//dhcpRequst struct data9//dhcpRequst
{ {
MYDWORD lease; MYDWORD lease;
union union {
{
char raw[sizeof(dhcp_packet)]; char raw[sizeof(dhcp_packet)];
dhcp_packet dhcpp; dhcp_packet dhcpp;
}; };
@ -486,8 +464,7 @@ struct data9 //dhcpRequst
MYBYTE sockInd; MYBYTE sockInd;
}; };
struct DhcpConnType struct DhcpConnType {
{
SOCKET sock; SOCKET sock;
SOCKADDR_IN addr; SOCKADDR_IN addr;
MYDWORD server; MYDWORD server;
@ -497,20 +474,17 @@ struct DhcpConnType
MYDWORD mask; MYDWORD mask;
int reUseVal; int reUseVal;
int reUseSize; int reUseSize;
union union {
{
int broadCastVal; int broadCastVal;
bool pktinfoVal; bool pktinfoVal;
}; };
union union {
{
int broadCastSize; int broadCastSize;
unsigned int pktinfoSize; unsigned int pktinfoSize;
}; };
}; };
struct data1 struct data1 {
{
DhcpConnType dhcpConn[MAX_SERVERS]; DhcpConnType dhcpConn[MAX_SERVERS];
DhcpConnType dhcpListener; DhcpConnType dhcpListener;
ConnType httpConn; ConnType httpConn;
@ -525,8 +499,7 @@ struct data1
bool busy; bool busy;
}; };
struct data2 struct data2 {
{
char servername[128]; char servername[128];
char servername_fqn[256]; char servername_fqn[256];
char zone[256]; char zone[256];
@ -561,7 +534,6 @@ struct data2
char rangeCount; char rangeCount;
}; };
//Function Prototypes //Function Prototypes
bool checkIP(data9 *req, data17 *rangeData, MYDWORD ip); bool checkIP(data9 *req, data17 *rangeData, MYDWORD ip);
bool checkMask(MYDWORD); bool checkMask(MYDWORD);