From 6eec552ea4420217d65d4ea9b5dc14217f93b2ad Mon Sep 17 00:00:00 2001 From: "nullable.type" Date: Sat, 27 Oct 2012 14:04:41 +0200 Subject: [PATCH 1/6] Added declaration to avoid warning C4115 (named type definition in parentheses) issued by Visual Studio 2012. --- mongoose.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mongoose.c b/mongoose.c index e124135f..ccaf5e22 100644 --- a/mongoose.c +++ b/mongoose.c @@ -146,6 +146,8 @@ static int pthread_mutex_lock(pthread_mutex_t *); static int pthread_mutex_unlock(pthread_mutex_t *); static void to_unicode(const char *path, wchar_t *wbuf, size_t wbuf_len); + +struct file; static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p); #if defined(HAVE_STDINT) From 73a845a327c24e1c0ee99427bada7c0b4bd33427 Mon Sep 17 00:00:00 2001 From: "nullable.type" Date: Sat, 27 Oct 2012 14:07:06 +0200 Subject: [PATCH 2/6] Suppress warning C4204 (non-constant aggregate initializer) issued by Visual Studio 2012 due to missing C99 support. --- mongoose.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mongoose.c b/mongoose.c index ccaf5e22..c3edd4a8 100644 --- a/mongoose.c +++ b/mongoose.c @@ -29,6 +29,10 @@ #define __STDC_LIMIT_MACROS // C++ wants that for INT64_MAX #endif +#if defined (_MSC_VER) +#pragma warning (disable : 4204) // non-constant aggregate initializer: issued due to missing C99 support +#endif + // Disable WIN32_LEAN_AND_MEAN. // This makes windows.h always include winsock2.h #ifdef WIN32_LEAN_AND_MEAN From c5ba6016aa714fcb13585a5690a1461bdf39e8f4 Mon Sep 17 00:00:00 2001 From: "nullable.type" Date: Sat, 27 Oct 2012 14:09:26 +0200 Subject: [PATCH 3/6] Suppress warning C4127 (conditional expression is constant) issued by Visual Studio 2012 introduced by FD_SET(..) which is using the do-while(0) trick. --- mongoose.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoose.c b/mongoose.c index c3edd4a8..9ed3c638 100644 --- a/mongoose.c +++ b/mongoose.c @@ -30,6 +30,7 @@ #endif #if defined (_MSC_VER) +#pragma warning (disable : 4127) // conditional expression is constant: introduced by FD_SET(..) #pragma warning (disable : 4204) // non-constant aggregate initializer: issued due to missing C99 support #endif From eb92b5f1b3f1c513fb70cef15d5be6f8d82d2f3d Mon Sep 17 00:00:00 2001 From: "nullable.type" Date: Fri, 2 Nov 2012 22:52:47 +0100 Subject: [PATCH 4/6] Avoid memory leaks if duplicate options are passed. --- mongoose.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoose.c b/mongoose.c index 9ed3c638..acfb3787 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4976,6 +4976,7 @@ struct mg_context *mg_start(mg_callback_t user_callback, void *user_data, } if (ctx->config[i] != NULL) { cry(fc(ctx), "warning: %s: duplicate option", name); + free(ctx->config[i]); } ctx->config[i] = mg_strdup(value); DEBUG_TRACE(("[%s] -> [%s]", name, value)); From 786caaecb2fb1f409ba8a1653e6fe0bd3405020e Mon Sep 17 00:00:00 2001 From: Eric Bakan Date: Mon, 12 Nov 2012 10:40:19 -0500 Subject: [PATCH 5/6] Added support for Ogg Vorbis audio files --- mongoose.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mongoose.c b/mongoose.c index e124135f..9c654c00 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1889,6 +1889,7 @@ static const struct { {".mp3", 4, "audio/x-mp3"}, {".mid", 4, "audio/mid"}, {".m3u", 4, "audio/x-mpegurl"}, + {".ogg", 4, "audio/ogg"}, {".ram", 4, "audio/x-pn-realaudio"}, {".xml", 4, "text/xml"}, {".json", 5, "text/json"}, From c9183f385129d044f922c64fcc41cb44a8b0d1ae Mon Sep 17 00:00:00 2001 From: "nullable.type" Date: Sun, 16 Dec 2012 12:27:53 +0100 Subject: [PATCH 6/6] Made the names of the function arguments of the declaration and the definition of mg_get_var(..) the same. Changed the error codes to have a consistent way of reporting errors. -2 is returned if there is a problem with the size of the destination buffer. -1 is returned if the variable is not found. Updated the documentation of mg_get_var(..) in mongoose.h and removed the redundant comments from mongoose.c. --- mongoose.c | 23 +++++++++++------------ mongoose.h | 12 ++++++------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/mongoose.c b/mongoose.c index ed0e2f92..d341c76b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1646,13 +1646,7 @@ static int url_decode(const char *src, int src_len, char *dst, return i >= src_len ? j : -1; } -// Scan given buffer and fetch the value of the given variable. -// It can be specified in query string, or in the POST data. -// Return -1 if the variable not found, or length of the URL-decoded value -// stored in dst. The dst buffer is guaranteed to be NUL-terminated if it -// is not NULL or zero-length. If dst is NULL or zero-length, then -// -2 is returned. -int mg_get_var(const char *buf, size_t buf_len, const char *name, +int mg_get_var(const char *data, size_t data_len, const char *name, char *dst, size_t dst_len) { const char *p, *e, *s; size_t name_len; @@ -1660,18 +1654,18 @@ int mg_get_var(const char *buf, size_t buf_len, const char *name, if (dst == NULL || dst_len == 0) { len = -2; - } else if (buf == NULL || name == NULL || buf_len == 0) { + } else if (data == NULL || name == NULL || data_len == 0) { len = -1; dst[0] = '\0'; } else { name_len = strlen(name); - e = buf + buf_len; + e = data + data_len; len = -1; dst[0] = '\0'; - // buf is "var1=val1&var2=val2...". Find variable first - for (p = buf; p + name_len < e; p++) { - if ((p == buf || p[-1] == '&') && p[name_len] == '=' && + // data is "var1=val1&var2=val2...". Find variable first + for (p = data; p + name_len < e; p++) { + if ((p == data || p[-1] == '&') && p[name_len] == '=' && !mg_strncasecmp(name, p, name_len)) { // Point p to variable value @@ -1686,6 +1680,11 @@ int mg_get_var(const char *buf, size_t buf_len, const char *name, // Decode variable into destination buffer len = url_decode(p, (size_t)(s - p), dst, dst_len, 1); + + // Redirect error code from -1 to -2 (destination buffer too small). + if (len == -1) { + len = -2; + } break; } } diff --git a/mongoose.h b/mongoose.h index c51baad4..a9f98c34 100644 --- a/mongoose.h +++ b/mongoose.h @@ -286,19 +286,19 @@ const char *mg_get_header(const struct mg_connection *, const char *name); // or request_info.query_string. // data_len: length of the encoded data. // var_name: variable name to decode from the buffer -// buf: destination buffer for the decoded variable -// buf_len: length of the destination buffer +// dst: destination buffer for the decoded variable +// dst_len: length of the destination buffer // // Return: // On success, length of the decoded variable. // On error: -// -1 (variable not found, or destination buffer is too small). -// -2 (destination buffer is NULL or zero length). +// -1 (variable not found). +// -2 (destination buffer is NULL, zero length or too small to hold the decoded variable). // // Destination buffer is guaranteed to be '\0' - terminated if it is not -// NULL or zero length. In case of failure, dst[0] == '\0'. +// NULL or zero length. int mg_get_var(const char *data, size_t data_len, - const char *var_name, char *buf, size_t buf_len); + const char *var_name, char *dst, size_t dst_len); // Fetch value of certain cookie variable into the destination buffer. //