diff --git a/mongoose.c b/mongoose.c index 238f7961957e4cac004803f4d76ac0acbce5cf4f..8d0e290d1aa77795bbf36aed4e1c485df6f29428 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4851,8 +4851,8 @@ static void remove_double_dots(char *s) { #endif -static int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, - int is_form_url_encoded) { +int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, + int is_form_url_encoded) { int i, j, a, b; #define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W') diff --git a/mongoose.h b/mongoose.h index e5ce18007717e0f1c99d82b22679159b32c3a65e..f94d475aea91cd30ed56c9e6b45a11d6a5161dee 100644 --- a/mongoose.h +++ b/mongoose.h @@ -1690,6 +1690,19 @@ size_t mg_parse_multipart(const char *buf, size_t buf_len, char *var_name, */ int mg_get_http_var(const struct mg_str *, const char *, char *dst, size_t); +/* + * Decode URL-encoded string. + * + * Source string is specified by (`src`, `src_len`), and destination is + * (`dst`, `dst_len`). If `is_form_url_encoded` is non-zero, then + * `+` character is decoded as a blank space character. This function + * guarantees to `\0`-terminate the destination. If destination is too small, + * then source string is partially decoded and `-1` is returned. Otherwise, + * a length of decoded string is returned, not counting final `\0`. + */ +int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, + int is_form_url_encoded); + /* Create Digest authentication header for client request. */ int mg_http_create_digest_auth_header(char *buf, size_t buf_len, const char *method, const char *uri,