mirror of
https://github.com/cesanta/mongoose.git
synced 2025-06-11 12:14:41 +08:00
Fix mg_get_http_var retval
PUBLISHED_FROM=257deff5ea20302627e77a0f29cf2359276a41d4
This commit is contained in:
parent
af22fb7a06
commit
8b67274cc0
@ -12,5 +12,6 @@ Fetches a HTTP form variable.
|
|||||||
Fetches a variable `name` from a `buf` into a buffer specified by `dst`,
|
Fetches a variable `name` from a `buf` into a buffer specified by `dst`,
|
||||||
`dst_len`. The destination is always zero-terminated. Returns the length of
|
`dst_len`. The destination is always zero-terminated. Returns the length of
|
||||||
a fetched variable. If not found, 0 is returned. `buf` must be valid
|
a fetched variable. If not found, 0 is returned. `buf` must be valid
|
||||||
url-encoded buffer. If destination is too small, `-1` is returned.
|
url-encoded buffer. If destination is too small or an error occured,
|
||||||
|
negative number is returned.
|
||||||
|
|
||||||
|
12
mongoose.c
12
mongoose.c
@ -6492,6 +6492,13 @@ int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
|
|||||||
size_t name_len;
|
size_t name_len;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* According to the documentation function returns negative
|
||||||
|
* value in case of error. For debug purposes it returns:
|
||||||
|
* -1 - src is wrong (NUUL)
|
||||||
|
* -2 - dst is wrong (NULL)
|
||||||
|
* -3 - failed to decode url or dst is to small
|
||||||
|
*/
|
||||||
if (dst == NULL || dst_len == 0) {
|
if (dst == NULL || dst_len == 0) {
|
||||||
len = -2;
|
len = -2;
|
||||||
} else if (buf->p == NULL || name == NULL || buf->len == 0) {
|
} else if (buf->p == NULL || name == NULL || buf->len == 0) {
|
||||||
@ -6500,7 +6507,7 @@ int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
|
|||||||
} else {
|
} else {
|
||||||
name_len = strlen(name);
|
name_len = strlen(name);
|
||||||
e = buf->p + buf->len;
|
e = buf->p + buf->len;
|
||||||
len = -1;
|
len = 0;
|
||||||
dst[0] = '\0';
|
dst[0] = '\0';
|
||||||
|
|
||||||
for (p = buf->p; p + name_len < e; p++) {
|
for (p = buf->p; p + name_len < e; p++) {
|
||||||
@ -6512,8 +6519,9 @@ int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
|
|||||||
s = e;
|
s = e;
|
||||||
}
|
}
|
||||||
len = mg_url_decode(p, (size_t)(s - p), dst, dst_len, 1);
|
len = mg_url_decode(p, (size_t)(s - p), dst, dst_len, 1);
|
||||||
|
/* -1 means: failed to decode or dst is too small */
|
||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
len = -2;
|
len = -3;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -4516,7 +4516,8 @@ size_t mg_parse_multipart(const char *buf, size_t buf_len, char *var_name,
|
|||||||
* Fetches a variable `name` from a `buf` into a buffer specified by `dst`,
|
* Fetches a variable `name` from a `buf` into a buffer specified by `dst`,
|
||||||
* `dst_len`. The destination is always zero-terminated. Returns the length of
|
* `dst_len`. The destination is always zero-terminated. Returns the length of
|
||||||
* a fetched variable. If not found, 0 is returned. `buf` must be valid
|
* a fetched variable. If not found, 0 is returned. `buf` must be valid
|
||||||
* url-encoded buffer. If destination is too small, `-1` is returned.
|
* url-encoded buffer. If destination is too small or an error occured,
|
||||||
|
* negative number is returned.
|
||||||
*/
|
*/
|
||||||
int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
|
int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
|
||||||
size_t dst_len);
|
size_t dst_len);
|
||||||
|
Loading…
Reference in New Issue
Block a user