diff --git a/build/src/internal.h b/build/src/internal.h index b47dbdfb..e2f05e1c 100644 --- a/build/src/internal.h +++ b/build/src/internal.h @@ -255,3 +255,105 @@ typedef int SOCKET; #define MG_BUF_LEN 8192 #define MAX_REQUEST_SIZE 16384 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) + +#ifdef DEBUG_TRACE +#undef DEBUG_TRACE +#define DEBUG_TRACE(x) +#else +#if defined(DEBUG) +#define DEBUG_TRACE(x) do { \ + flockfile(stdout); \ + printf("*** %lu.%p.%s.%d: ", \ + (unsigned long) time(NULL), (void *) pthread_self(), \ + __func__, __LINE__); \ + printf x; \ + putchar('\n'); \ + fflush(stdout); \ + funlockfile(stdout); \ +} while (0) +#else +#define DEBUG_TRACE(x) +#endif // DEBUG +#endif // DEBUG_TRACE + +// Darwin prior to 7.0 and Win32 do not have socklen_t +#ifdef NO_SOCKLEN_T +typedef int socklen_t; +#endif // NO_SOCKLEN_T +#define _DARWIN_UNLIMITED_SELECT + +#define IP_ADDR_STR_LEN 50 // IPv6 hex string is 46 chars + +#if !defined(MSG_NOSIGNAL) +#define MSG_NOSIGNAL 0 +#endif + +#if !defined(SOMAXCONN) +#define SOMAXCONN 100 +#endif + +#if !defined(PATH_MAX) +#define PATH_MAX 4096 +#endif + +// Size of the accepted socket queue +#if !defined(MGSQLEN) +#define MGSQLEN 20 +#endif + +// Extra HTTP headers to send in every static file reply +#if !defined(EXTRA_HTTP_HEADERS) +#define EXTRA_HTTP_HEADERS "" +#endif + +static const char *http_500_error = "Internal Server Error"; + +#if defined(NO_SSL_DL) +#include +#include +#else +// SSL loaded dynamically from DLL. +// I put the prototypes here to be independent from OpenSSL source installation. +typedef struct ssl_st SSL; +typedef struct ssl_method_st SSL_METHOD; +typedef struct ssl_ctx_st SSL_CTX; + +struct ssl_func { + const char *name; // SSL function name + void (*ptr)(void); // Function pointer +}; + +#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr) +#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr) +#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr) +#define SSL_read (* (int (*)(SSL *, void *, int)) ssl_sw[3].ptr) +#define SSL_write (* (int (*)(SSL *, const void *,int)) ssl_sw[4].ptr) +#define SSL_get_error (* (int (*)(SSL *, int)) ssl_sw[5].ptr) +#define SSL_set_fd (* (int (*)(SSL *, SOCKET)) ssl_sw[6].ptr) +#define SSL_new (* (SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr) +#define SSL_CTX_new (* (SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr) +#define SSLv23_server_method (* (SSL_METHOD * (*)(void)) ssl_sw[9].ptr) +#define SSL_library_init (* (int (*)(void)) ssl_sw[10].ptr) +#define SSL_CTX_use_PrivateKey_file (* (int (*)(SSL_CTX *, \ + const char *, int)) ssl_sw[11].ptr) +#define SSL_CTX_use_certificate_file (* (int (*)(SSL_CTX *, \ + const char *, int)) ssl_sw[12].ptr) +#define SSL_CTX_set_default_passwd_cb \ + (* (void (*)(SSL_CTX *, mg_event_handler_t)) ssl_sw[13].ptr) +#define SSL_CTX_free (* (void (*)(SSL_CTX *)) ssl_sw[14].ptr) +#define SSL_load_error_strings (* (void (*)(void)) ssl_sw[15].ptr) +#define SSL_CTX_use_certificate_chain_file \ + (* (int (*)(SSL_CTX *, const char *)) ssl_sw[16].ptr) +#define SSLv23_client_method (* (SSL_METHOD * (*)(void)) ssl_sw[17].ptr) +#define SSL_pending (* (int (*)(SSL *)) ssl_sw[18].ptr) +#define SSL_CTX_set_verify (* (void (*)(SSL_CTX *, int, int)) ssl_sw[19].ptr) +#define SSL_shutdown (* (int (*)(SSL *)) ssl_sw[20].ptr) + +#define CRYPTO_num_locks (* (int (*)(void)) crypto_sw[0].ptr) +#define CRYPTO_set_locking_callback \ + (* (void (*)(void (*)(int, int, const char *, int))) crypto_sw[1].ptr) +#define CRYPTO_set_id_callback \ + (* (void (*)(unsigned long (*)(void))) crypto_sw[2].ptr) +#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr) +#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr) + diff --git a/build/src/mongoose.c b/build/src/mongoose.c index e07d1a6b..65504e29 100644 --- a/build/src/mongoose.c +++ b/build/src/mongoose.c @@ -1,106 +1,5 @@ #include "internal.h" -#ifdef DEBUG_TRACE -#undef DEBUG_TRACE -#define DEBUG_TRACE(x) -#else -#if defined(DEBUG) -#define DEBUG_TRACE(x) do { \ - flockfile(stdout); \ - printf("*** %lu.%p.%s.%d: ", \ - (unsigned long) time(NULL), (void *) pthread_self(), \ - __func__, __LINE__); \ - printf x; \ - putchar('\n'); \ - fflush(stdout); \ - funlockfile(stdout); \ -} while (0) -#else -#define DEBUG_TRACE(x) -#endif // DEBUG -#endif // DEBUG_TRACE - -// Darwin prior to 7.0 and Win32 do not have socklen_t -#ifdef NO_SOCKLEN_T -typedef int socklen_t; -#endif // NO_SOCKLEN_T -#define _DARWIN_UNLIMITED_SELECT - -#define IP_ADDR_STR_LEN 50 // IPv6 hex string is 46 chars - -#if !defined(MSG_NOSIGNAL) -#define MSG_NOSIGNAL 0 -#endif - -#if !defined(SOMAXCONN) -#define SOMAXCONN 100 -#endif - -#if !defined(PATH_MAX) -#define PATH_MAX 4096 -#endif - -// Size of the accepted socket queue -#if !defined(MGSQLEN) -#define MGSQLEN 20 -#endif - -// Extra HTTP headers to send in every static file reply -#if !defined(EXTRA_HTTP_HEADERS) -#define EXTRA_HTTP_HEADERS "" -#endif - -static const char *http_500_error = "Internal Server Error"; - -#if defined(NO_SSL_DL) -#include -#include -#else -// SSL loaded dynamically from DLL. -// I put the prototypes here to be independent from OpenSSL source installation. -typedef struct ssl_st SSL; -typedef struct ssl_method_st SSL_METHOD; -typedef struct ssl_ctx_st SSL_CTX; - -struct ssl_func { - const char *name; // SSL function name - void (*ptr)(void); // Function pointer -}; - -#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr) -#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr) -#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr) -#define SSL_read (* (int (*)(SSL *, void *, int)) ssl_sw[3].ptr) -#define SSL_write (* (int (*)(SSL *, const void *,int)) ssl_sw[4].ptr) -#define SSL_get_error (* (int (*)(SSL *, int)) ssl_sw[5].ptr) -#define SSL_set_fd (* (int (*)(SSL *, SOCKET)) ssl_sw[6].ptr) -#define SSL_new (* (SSL * (*)(SSL_CTX *)) ssl_sw[7].ptr) -#define SSL_CTX_new (* (SSL_CTX * (*)(SSL_METHOD *)) ssl_sw[8].ptr) -#define SSLv23_server_method (* (SSL_METHOD * (*)(void)) ssl_sw[9].ptr) -#define SSL_library_init (* (int (*)(void)) ssl_sw[10].ptr) -#define SSL_CTX_use_PrivateKey_file (* (int (*)(SSL_CTX *, \ - const char *, int)) ssl_sw[11].ptr) -#define SSL_CTX_use_certificate_file (* (int (*)(SSL_CTX *, \ - const char *, int)) ssl_sw[12].ptr) -#define SSL_CTX_set_default_passwd_cb \ - (* (void (*)(SSL_CTX *, mg_event_handler_t)) ssl_sw[13].ptr) -#define SSL_CTX_free (* (void (*)(SSL_CTX *)) ssl_sw[14].ptr) -#define SSL_load_error_strings (* (void (*)(void)) ssl_sw[15].ptr) -#define SSL_CTX_use_certificate_chain_file \ - (* (int (*)(SSL_CTX *, const char *)) ssl_sw[16].ptr) -#define SSLv23_client_method (* (SSL_METHOD * (*)(void)) ssl_sw[17].ptr) -#define SSL_pending (* (int (*)(SSL *)) ssl_sw[18].ptr) -#define SSL_CTX_set_verify (* (void (*)(SSL_CTX *, int, int)) ssl_sw[19].ptr) -#define SSL_shutdown (* (int (*)(SSL *)) ssl_sw[20].ptr) - -#define CRYPTO_num_locks (* (int (*)(void)) crypto_sw[0].ptr) -#define CRYPTO_set_locking_callback \ - (* (void (*)(void (*)(int, int, const char *, int))) crypto_sw[1].ptr) -#define CRYPTO_set_id_callback \ - (* (void (*)(unsigned long (*)(void))) crypto_sw[2].ptr) -#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr) -#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr) - // set_ssl_option() function updates this array. // It loads SSL library dynamically and changes NULLs to the actual addresses // of respective functions. The macros above (like SSL_connect()) are really diff --git a/mongoose.c b/mongoose.c index dcb3b2c6..40c4d4b9 100644 --- a/mongoose.c +++ b/mongoose.c @@ -357,6 +357,7 @@ struct ssl_func { #define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr) #define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr) + // set_ssl_option() function updates this array. // It loads SSL library dynamically and changes NULLs to the actual addresses // of respective functions. The macros above (like SSL_connect()) are really @@ -3172,7 +3173,7 @@ static int forward_body_data(struct mg_connection *conn, FILE *fp, if (left > (int64_t) sizeof(buf)) { left = sizeof(buf); } - nread = pull(NULL, conn, buf, left); + nread = pull(NULL, conn, buf, (int) left); if (nread <= 0 || push(fp, sock, ssl, buf, nread) != nread) { break; } @@ -4250,7 +4251,7 @@ FILE *mg_upload(struct mg_connection *conn, const char *destination_dir, assert(len >= 0 && len <= buf_len); to_read = buf_len - len; if (to_read > left_to_read(conn)) { - to_read = left_to_read(conn); + to_read = (int) left_to_read(conn); } while (len < buf_len && (n = pull(NULL, conn, buf + len, to_read)) > 0) { @@ -4322,7 +4323,7 @@ FILE *mg_upload(struct mg_connection *conn, const char *destination_dir, } to_read = buf_len - len; if (to_read > left_to_read(conn)) { - to_read = left_to_read(conn); + to_read = (int) left_to_read(conn); } } while (!eof && (n = pull(NULL, conn, buf + len, to_read)) > 0); conn->data_len = conn->request_len + len;