From 224d18589f3608a1ee5b08973212856114f72f96 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Sat, 2 Nov 2013 10:24:30 +0000 Subject: [PATCH] Fixed -DNO_SSL build --- build/src/http_client.c | 6 +++++- build/src/mongoose.c | 5 ++++- build/src/ssl.c | 1 - mongoose.c | 12 +++++++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/build/src/http_client.c b/build/src/http_client.c index db06b206..0e4a6c7a 100644 --- a/build/src/http_client.c +++ b/build/src/http_client.c @@ -3,14 +3,18 @@ static SOCKET conn2(const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len) { struct sockaddr_in sin; - struct hostent *he; + struct hostent *he = NULL; SOCKET sock = INVALID_SOCKET; + (void) use_ssl; // Prevent warning for -DNO_SSL case + if (host == NULL) { snprintf(ebuf, ebuf_len, "%s", "NULL host"); +#ifndef NO_SSL } else if (use_ssl && SSLv23_client_method == NULL) { snprintf(ebuf, ebuf_len, "%s", "SSL is not initialized"); // TODO(lsm): use something threadsafe instead of gethostbyname() +#endif } else if ((he = gethostbyname(host)) == NULL) { snprintf(ebuf, ebuf_len, "gethostbyname(%s): %s", host, strerror(ERRNO)); } else if ((sock = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { diff --git a/build/src/mongoose.c b/build/src/mongoose.c index 8a461b9b..5a4d9105 100644 --- a/build/src/mongoose.c +++ b/build/src/mongoose.c @@ -149,9 +149,12 @@ static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, // How many bytes we send in this iteration k = len - sent > INT_MAX ? INT_MAX : (int) (len - sent); +#if !defined(NO_SSL) if (ssl != NULL) { n = SSL_write(ssl, buf + sent, k); - } else if (fp != NULL) { + } else +#endif + if (fp != NULL) { n = (int) fwrite(buf + sent, 1, (size_t) k, fp); if (ferror(fp)) n = -1; diff --git a/build/src/ssl.c b/build/src/ssl.c index 6da584b5..9a52e250 100644 --- a/build/src/ssl.c +++ b/build/src/ssl.c @@ -176,4 +176,3 @@ static void uninitialize_ssl(struct mg_context *ctx) { } } #endif // !NO_SSL - diff --git a/mongoose.c b/mongoose.c index 36e4386a..a24e6221 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2072,18 +2072,21 @@ static void uninitialize_ssl(struct mg_context *ctx) { } #endif // !NO_SSL - static SOCKET conn2(const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len) { struct sockaddr_in sin; - struct hostent *he; + struct hostent *he = NULL; SOCKET sock = INVALID_SOCKET; + (void) use_ssl; // Prevent warning for -DNO_SSL case + if (host == NULL) { snprintf(ebuf, ebuf_len, "%s", "NULL host"); +#ifndef NO_SSL } else if (use_ssl && SSLv23_client_method == NULL) { snprintf(ebuf, ebuf_len, "%s", "SSL is not initialized"); // TODO(lsm): use something threadsafe instead of gethostbyname() +#endif } else if ((he = gethostbyname(host)) == NULL) { snprintf(ebuf, ebuf_len, "gethostbyname(%s): %s", host, strerror(ERRNO)); } else if ((sock = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { @@ -2314,9 +2317,12 @@ static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf, // How many bytes we send in this iteration k = len - sent > INT_MAX ? INT_MAX : (int) (len - sent); +#if !defined(NO_SSL) if (ssl != NULL) { n = SSL_write(ssl, buf + sent, k); - } else if (fp != NULL) { + } else +#endif + if (fp != NULL) { n = (int) fwrite(buf + sent, 1, (size_t) k, fp); if (ferror(fp)) n = -1;