diff --git a/ape_http_parser.c b/ape_http_parser.c index 607a4e2..d07561a 100644 --- a/ape_http_parser.c +++ b/ape_http_parser.c @@ -72,7 +72,7 @@ typedef enum classes { } parser_class; -static int ascii_class[128] = { +static parser_class ascii_class[128] = { /* This array maps the 128 ASCII characters into character classes. The remaining Unicode characters should be mapped to C_ETC. @@ -126,7 +126,7 @@ typedef enum actions { } parser_actions; -static int state_transition_table[NR_STATES][NR_CLASSES] = { +static int8_t /*parser_state*/ state_transition_table[NR_STATES][NR_CLASSES] = { /* nul white etc ABDF | space | \r\n : , " \ / + - . ? % 09 | * | E G T P H O S C N L _ */ @@ -211,7 +211,7 @@ int parse_http_char(struct _http_parser *parser, const unsigned char c) #define HTTP_BODY_AS_ENDED() (HTTP_ISBODYCONTENT() && --parser->cl == 0 && (parser->rx |= HTTP_FLG_READY, 1)) parser_class c_classe; - int8_t state; + int8_t /*parser_state*/ state; unsigned char ch; if (c >= 128) { @@ -376,7 +376,7 @@ int parse_http_char(struct _http_parser *parser, const unsigned char c) parser->state = R9; break; case RC: /* HTTP response code */ - if ((parser->rcode = (parser->rcode*10) + (c - '0')) > MAX_RCODE) { + if ((parser->rcode = (uint16_t) ((parser->rcode*10) + (c - '0')) > MAX_RCODE)) { return 0; } parser->state = RN; @@ -400,7 +400,7 @@ static int parse_callback(void **ctx, callback_type type, int value, uint32_t st { switch(type) { case HTTP_METHOD: - switch(value) { + switch( (http_method_t) value) { case HTTP_GET: printf("GET method detected\n"); break; @@ -447,7 +447,7 @@ static int parse_callback(void **ctx, callback_type type, int value, uint32_t st int main() { int length = 0, i; - struct _http_parser p; + http_parser p; /* Process BYTE_GET/POST opti check before running the parser */ diff --git a/ape_socket.c b/ape_socket.c index d5c17f1..a1e2417 100644 --- a/ape_socket.c +++ b/ape_socket.c @@ -103,7 +103,7 @@ __inline static void ape_socket_release_data(unsigned char *data, ape_socket_dat } } -ape_socket *APE_socket_new(uint8_t pt, int from, ape_global *ape) +ape_socket *APE_socket_new(enum ape_socket_proto pt, int from, ape_global *ape) { int sock = from, proto = SOCK_STREAM; diff --git a/ape_socket.h b/ape_socket.h index e34d72a..7a845a4 100644 --- a/ape_socket.h +++ b/ape_socket.h @@ -91,19 +91,31 @@ struct iovec enum ape_socket_flags { APE_SOCKET_WOULD_BLOCK = (1 << 0), APE_SOCKET_CORK = (1 << 1) +#ifdef _MSC_VER }; +#else +} __attribute__ ((__packed__)); +#endif enum ape_socket_proto { APE_SOCKET_PT_TCP, APE_SOCKET_PT_UDP, APE_SOCKET_PT_SSL +#ifdef _MSC_VER }; +#else +} __attribute__ ((__packed__)); +#endif enum ape_socket_type { APE_SOCKET_TP_UNKNOWN, APE_SOCKET_TP_SERVER, APE_SOCKET_TP_CLIENT +#ifdef _MSC_VER }; +#else +} __attribute__ ((__packed__)); +#endif enum ape_socket_state { APE_SOCKET_ST_ONLINE, @@ -111,8 +123,11 @@ enum ape_socket_state { APE_SOCKET_ST_PENDING, APE_SOCKET_ST_OFFLINE, APE_SOCKET_ST_SHUTDOWN +#ifdef _MSC_VER }; - +#else +} __attribute__ ((__packed__)); +#endif typedef enum _ape_socket_data_autorelease { APE_DATA_STATIC, @@ -173,12 +188,20 @@ struct _ape_socket { struct _ape_dns_cb_argv *dns_state; +#ifdef _MSC_VER +#pragma pack(push, 1) struct { - uint8_t flags; - uint8_t proto; - uint8_t type; - uint8_t state; +#else + struct __attribute__ ((__packed__)) { +#endif + enum ape_socket_flags flags; + enum ape_socket_proto proto; + enum ape_socket_type type; + enum ape_socket_state state; } states; +#ifdef _MSC_VER +#pragma pack(pop) +#endif #ifdef _HAVE_SSL_SUPPORT struct { @@ -206,7 +229,7 @@ struct _ape_socket_packet { extern "C" { #endif -ape_socket *APE_socket_new(uint8_t pt, int from, ape_global *ape); +ape_socket *APE_socket_new(enum ape_socket_proto pt, int from, ape_global *ape); int APE_socket_listen(ape_socket *socket, uint16_t port, const char *local_ip, int defer_accept, int reuse_port); diff --git a/ape_timers.h b/ape_timers.h index 99d4d3c..d56de7b 100644 --- a/ape_timers.h +++ b/ape_timers.h @@ -35,7 +35,7 @@ struct _ticks_callback int delta; int times; unsigned int identifier; - int flag; + ape_timer_flags flag; void *func; void *params; diff --git a/ape_timers_next.h b/ape_timers_next.h index 7e527b4..ded70b0 100644 --- a/ape_timers_next.h +++ b/ape_timers_next.h @@ -24,15 +24,15 @@ typedef int (*timer_callback)(void *arg); -enum { +typedef enum { APE_TIMER_IS_PROTECTED = 1 << 0, APE_TIMER_IS_CLEARED = 1 << 1 -}; +} ape_timerng_flags; typedef struct _ape_timer { int identifier; - int flags; + ape_timerng_flags flags; uint64_t ticks_needs; uint64_t schedule; int nexec;