mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-19 11:09:42 +00:00
get_request_len() moved to string.c
This commit is contained in:
1 parent
37751a2875
commit
886dcb3f5d
3 files changed
+50
-50
No files matched your search
@@ -285,3 +285,28 @@ void mg_url_encode(const char *src, char *dst, size_t dst_len) {
|
||||
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
// Check whether full request is buffered. Return:
|
||||
// -1 if request is malformed
|
||||
// 0 if request is not yet fully buffered
|
||||
// >0 actual request length, including last \r\n\r\n
|
||||
static int get_request_len(const char *buf, int buf_len) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < buf_len; i++) {
|
||||
// Control characters are not allowed but >=128 is.
|
||||
// Abort scan as soon as one malformed character is found;
|
||||
// don't let subsequent \r\n\r\n win us over anyhow
|
||||
if (!isprint(* (const unsigned char *) &buf[i]) && buf[i] != '\r' &&
|
||||
buf[i] != '\n' && * (const unsigned char *) &buf[i] < 128) {
|
||||
return -1;
|
||||
} else if (buf[i] == '\n' && i + 1 < buf_len && buf[i + 1] == '\n') {
|
||||
return i + 2;
|
||||
} else if (buf[i] == '\n' && i + 2 < buf_len && buf[i + 1] == '\r' &&
|
||||
buf[i + 2] == '\n') {
|
||||
return i + 3;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user