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
|
||||||
|
|
|
@ -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,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;
|
||||||
|
|
|
@ -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++;
|
||||||
|
|
|
@ -41,12 +41,12 @@ 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,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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
@ -67,45 +67,39 @@ typedef struct in_pktinfo IN_PKTINFO;
|
||||||
#define SOCKADDR sockaddr
|
#define SOCKADDR sockaddr
|
||||||
#define SOCKET int
|
#define SOCKET int
|
||||||
#define BOOL bool
|
#define BOOL bool
|
||||||
#define LPSOCKADDR sockaddr*
|
#define LPSOCKADDR sockaddr *
|
||||||
#define closesocket close
|
#define closesocket close
|
||||||
|
|
||||||
struct data7 //cache
|
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;
|
unsigned subnetFlg : 1;
|
||||||
unsigned subnetFlg: 1;
|
signed rangeInd : 8;
|
||||||
signed rangeInd: 8;
|
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;
|
||||||
|
@ -113,7 +107,7 @@ struct data7 //cache
|
||||||
MYBYTE data;
|
MYBYTE data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct data71 //Lump
|
struct data71//Lump
|
||||||
{
|
{
|
||||||
char *mapname;
|
char *mapname;
|
||||||
MYBYTE *response;
|
MYBYTE *response;
|
||||||
|
@ -127,12 +121,11 @@ struct data71 //Lump
|
||||||
MYBYTE dnsType;
|
MYBYTE dnsType;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef multimap<string, data7*> hostMap;
|
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,36 +279,33 @@ 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;
|
unsigned local : 1;
|
||||||
unsigned local: 1;
|
unsigned display : 1;
|
||||||
unsigned display: 1;
|
unsigned subnetFlg : 1;
|
||||||
unsigned subnetFlg: 1;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
MYDWORD ip;
|
MYDWORD ip;
|
||||||
|
@ -326,19 +315,17 @@ struct data8 //client
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
#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;
|
unsigned local : 1;
|
||||||
unsigned local: 1;
|
unsigned display : 1;
|
||||||
unsigned display: 1;
|
unsigned subnetFlg : 1;
|
||||||
unsigned subnetFlg: 1;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
MYDWORD ip;
|
MYDWORD ip;
|
||||||
|
@ -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,13 +362,12 @@ 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)];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct data13 //dhcp range
|
struct data13//dhcp range
|
||||||
{
|
{
|
||||||
MYBYTE rangeSetInd;
|
MYBYTE rangeSetInd;
|
||||||
MYDWORD rangeStart;
|
MYDWORD rangeStart;
|
||||||
|
@ -394,7 +378,7 @@ struct data13 //dhcp range
|
||||||
data7 **dhcpEntry;
|
data7 **dhcpEntry;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct data14 //rangeSet
|
struct data14//rangeSet
|
||||||
{
|
{
|
||||||
MYBYTE active;
|
MYBYTE active;
|
||||||
MYBYTE *macStart[MAX_RANGE_FILTERS];
|
MYBYTE *macStart[MAX_RANGE_FILTERS];
|
||||||
|
@ -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;
|
||||||
|
@ -450,11 +429,10 @@ struct data20
|
||||||
MYBYTE rangeSetInd;
|
MYBYTE rangeSetInd;
|
||||||
};
|
};
|
||||||
|
|
||||||
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,77 +534,76 @@ 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);
|
||||||
bool checkRange(data17*, char);
|
bool checkRange(data17 *, char);
|
||||||
bool detectChange();
|
bool detectChange();
|
||||||
bool getSection(const char*, char*, MYBYTE, char*);
|
bool getSection(const char *, char *, MYBYTE, char *);
|
||||||
bool isInt(char*);
|
bool isInt(char *);
|
||||||
bool isIP(char*);
|
bool isIP(char *);
|
||||||
FILE *openSection(const char*, MYBYTE);
|
FILE *openSection(const char *, MYBYTE);
|
||||||
MYBYTE pIP(void*, MYDWORD);
|
MYBYTE pIP(void *, MYDWORD);
|
||||||
MYBYTE pUInt(void*, MYDWORD);
|
MYBYTE pUInt(void *, MYDWORD);
|
||||||
MYBYTE pUShort(void*, MYWORD);
|
MYBYTE pUShort(void *, MYWORD);
|
||||||
MYBYTE addServer(MYDWORD*, MYBYTE, MYDWORD);
|
MYBYTE addServer(MYDWORD *, MYBYTE, MYDWORD);
|
||||||
int getRangeInd(MYDWORD);
|
int getRangeInd(MYDWORD);
|
||||||
char* myTrim(char*, char*);
|
char *myTrim(char *, char *);
|
||||||
char* myGetToken(char*, MYBYTE);
|
char *myGetToken(char *, MYBYTE);
|
||||||
char* cloneString(char*);
|
char *cloneString(char *);
|
||||||
char* getHexValue(MYBYTE*, char*, MYBYTE*);
|
char *getHexValue(MYBYTE *, char *, MYBYTE *);
|
||||||
char* genHostName(char*, const MYBYTE*, MYBYTE);
|
char *genHostName(char *, const MYBYTE *, MYBYTE);
|
||||||
char* hex2String(char*, const MYBYTE*, MYBYTE);
|
char *hex2String(char *, const MYBYTE *, MYBYTE);
|
||||||
char* IP2String(char*, MYDWORD);
|
char *IP2String(char *, MYDWORD);
|
||||||
char* IP2arpa(char*, MYDWORD);
|
char *IP2arpa(char *, MYDWORD);
|
||||||
char* IP62String(char*, MYBYTE*);
|
char *IP62String(char *, MYBYTE *);
|
||||||
char* myUpper(char* string);
|
char *myUpper(char *string);
|
||||||
char* myLower(char* string);
|
char *myLower(char *string);
|
||||||
char* readSection(char*, FILE*);
|
char *readSection(char *, FILE *);
|
||||||
data7* findDHCPEntry(char*);
|
data7 *findDHCPEntry(char *);
|
||||||
data7 *createCache(data71 *pLump);
|
data7 *createCache(data71 *pLump);
|
||||||
MYDWORD alad(data9*);
|
MYDWORD alad(data9 *);
|
||||||
MYDWORD calcMask(MYDWORD, MYDWORD);
|
MYDWORD calcMask(MYDWORD, MYDWORD);
|
||||||
MYDWORD chaddr(data9*);
|
MYDWORD chaddr(data9 *);
|
||||||
MYDWORD resad(data9*);
|
MYDWORD resad(data9 *);
|
||||||
MYDWORD fUInt(void *raw);
|
MYDWORD fUInt(void *raw);
|
||||||
MYDWORD sdmess(data9*);
|
MYDWORD sdmess(data9 *);
|
||||||
MYDWORD sendRepl(data9 *req);
|
MYDWORD sendRepl(data9 *req);
|
||||||
MYDWORD* findServer(MYDWORD*, MYBYTE, MYDWORD);
|
MYDWORD *findServer(MYDWORD *, MYBYTE, MYDWORD);
|
||||||
int getIndex(char, MYDWORD);
|
int getIndex(char, MYDWORD);
|
||||||
void addDHCPRange(char *dp);
|
void addDHCPRange(char *dp);
|
||||||
void addVendClass(MYBYTE rangeSetInd, char *vendClass, MYBYTE vendClassSize);
|
void addVendClass(MYBYTE rangeSetInd, char *vendClass, MYBYTE vendClassSize);
|
||||||
void addUserClass(MYBYTE rangeSetInd, char *userClass, MYBYTE userClassSize);
|
void addUserClass(MYBYTE rangeSetInd, char *userClass, MYBYTE userClassSize);
|
||||||
void addMacRange(MYBYTE rangeSetInd, char *macRange);
|
void addMacRange(MYBYTE rangeSetInd, char *macRange);
|
||||||
void addOptions(data9 *req);
|
void addOptions(data9 *req);
|
||||||
void calcRangeLimits(MYDWORD, MYDWORD, MYDWORD*, MYDWORD*);
|
void calcRangeLimits(MYDWORD, MYDWORD, MYDWORD *, MYDWORD *);
|
||||||
void catch_system_interupt(int sig_num);
|
void catch_system_interupt(int sig_num);
|
||||||
void checkSize(MYBYTE);
|
void checkSize(MYBYTE);
|
||||||
void closeConn();
|
void closeConn();
|
||||||
void getInterfaces(data1*);
|
void getInterfaces(data1 *);
|
||||||
void getSecondary();
|
void getSecondary();
|
||||||
void *init(void*);
|
void *init(void *);
|
||||||
void lockOptions(FILE*);
|
void lockOptions(FILE *);
|
||||||
void loadOptions(FILE*, const char*, data20*);
|
void loadOptions(FILE *, const char *, data20 *);
|
||||||
void logDHCPMess(char*, MYBYTE);
|
void logDHCPMess(char *, MYBYTE);
|
||||||
void mySplit(char*, char*, const char*, char);
|
void mySplit(char *, char *, const char *, char);
|
||||||
void *sendHTTP(void *lpParam);
|
void *sendHTTP(void *lpParam);
|
||||||
void procHTTP(data19*);
|
void procHTTP(data19 *);
|
||||||
void pvdata(data9*, data3*);
|
void pvdata(data9 *, data3 *);
|
||||||
void recvRepl(data9*);
|
void recvRepl(data9 *);
|
||||||
void runProg();
|
void runProg();
|
||||||
void lockIP(MYDWORD);
|
void lockIP(MYDWORD);
|
||||||
void sendScopeStatus(data19 *req);
|
void sendScopeStatus(data19 *req);
|
||||||
void sendStatus(data19 *req);
|
void sendStatus(data19 *req);
|
||||||
void setTempLease(data7*);
|
void setTempLease(data7 *);
|
||||||
void setLeaseExpiry(data7*);
|
void setLeaseExpiry(data7 *);
|
||||||
void setLeaseExpiry(data7*, MYDWORD);
|
void setLeaseExpiry(data7 *, MYDWORD);
|
||||||
void *updateStateFile(void*);
|
void *updateStateFile(void *);
|
||||||
MYWORD fUShort(void*);
|
MYWORD fUShort(void *);
|
||||||
MYWORD gdmess(data9*, MYBYTE);
|
MYWORD gdmess(data9 *, MYBYTE);
|
||||||
MYWORD myTokenize(char*, char*, const char*, bool);
|
MYWORD myTokenize(char *, char *, const char *, bool);
|
||||||
MYWORD pQu(char*, char*);
|
MYWORD pQu(char *, char *);
|
||||||
MYWORD qLen(char*);
|
MYWORD qLen(char *);
|
||||||
const char *getRequestMethod(const char *buffer);
|
const char *getRequestMethod(const char *buffer);
|
||||||
void prepareUserHtmlRespStatus(data19 *req);
|
void prepareUserHtmlRespStatus(data19 *req);
|
||||||
void opendhcp_init_http_server();
|
void opendhcp_init_http_server();
|
||||||
|
|
|
@ -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