annotate Resources/Patches/mongoose-3.8-patch.diff @ 3754:ef625518c27c storage-commitment

closing branch storage-commitment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 16 Mar 2020 12:15:52 +0100
parents 72e809e57ba4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
1 --- mongoose.c.orig 2019-07-31 14:06:36.043726677 +0200
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
2 +++ mongoose.c 2019-07-31 14:10:06.767727652 +0200
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 @@ -50,6 +50,14 @@
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
4 #define PATH_MAX FILENAME_MAX
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
5 #endif // __SYMBIAN32__
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
6
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
7 +#if __gnu_hurd__ == 1
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
8 +/**
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
9 + * There is no limit on the length on a path under GNU Hurd, so we set
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
10 + * it to an arbitrary constant.
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
11 + **/
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
12 +#define PATH_MAX 4096
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
13 +#endif
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
14 +
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
15 #ifndef _WIN32_WCE // Some ANSI #includes are not available on Windows CE
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
16 #include <sys/types.h>
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
17 #include <sys/stat.h>
1112
a119f9ae3640 upgrade to Mongoose 3.8
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 @@ -108,8 +116,9 @@
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
19 #define strtoll(x, y, z) _atoi64(x)
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
20 #else
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
21 #define __func__ __FUNCTION__
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
22 -#define strtoull(x, y, z) _strtoui64(x, y, z)
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
23 -#define strtoll(x, y, z) _strtoi64(x, y, z)
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
24 +#include <stdlib.h>
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
25 +//#define strtoull(x, y, z) _strtoui64(x, y, z)
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
26 +//#define strtoll(x, y, z) _strtoi64(x, y, z)
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
27 #endif // _MSC_VER
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
28
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
29 #define ERRNO GetLastError()
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
30 @@ -2997,19 +3006,19 @@
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
31 }
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
32 }
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
33
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
34 -static int is_valid_http_method(const char *method) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
35 - return !strcmp(method, "GET") || !strcmp(method, "POST") ||
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
36 +static int is_valid_http_method(const char *method, int *isValidHttpMethod) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
37 + *isValidHttpMethod = !strcmp(method, "GET") || !strcmp(method, "POST") ||
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
38 !strcmp(method, "HEAD") || !strcmp(method, "CONNECT") ||
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
39 !strcmp(method, "PUT") || !strcmp(method, "DELETE") ||
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
40 !strcmp(method, "OPTIONS") || !strcmp(method, "PROPFIND")
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
41 - || !strcmp(method, "MKCOL")
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
42 - ;
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
43 + || !strcmp(method, "MKCOL");
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
44 + return *isValidHttpMethod;
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
45 }
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
46
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
47 // Parse HTTP request, fill in mg_request_info structure.
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
48 // This function modifies the buffer by NUL-terminating
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
49 // HTTP request components, header names and header values.
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
50 -static int parse_http_message(char *buf, int len, struct mg_request_info *ri) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
51 +static int parse_http_message(char *buf, int len, struct mg_request_info *ri, int *isValidHttpMethod) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
52 int is_request, request_length = get_request_len(buf, len);
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
53 if (request_length > 0) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
54 // Reset attributes. DO NOT TOUCH is_ssl, remote_ip, remote_port
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
55 @@ -3025,7 +3034,7 @@
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
56 ri->request_method = skip(&buf, " ");
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
57 ri->uri = skip(&buf, " ");
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
58 ri->http_version = skip(&buf, "\r\n");
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
59 - if (((is_request = is_valid_http_method(ri->request_method)) &&
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
60 + if (((is_request = is_valid_http_method(ri->request_method, isValidHttpMethod)) &&
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
61 memcmp(ri->http_version, "HTTP/", 5) != 0) ||
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
62 (!is_request && memcmp(ri->request_method, "HTTP/", 5)) != 0) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
63 request_length = -1;
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
64 @@ -4930,7 +4939,7 @@
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
65 return uri[0] == '/' || (uri[0] == '*' && uri[1] == '\0');
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
66 }
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
67
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
68 -static int getreq(struct mg_connection *conn, char *ebuf, size_t ebuf_len) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
69 +static int getreq(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *isValidHttpMethod) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
70 const char *cl;
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
71
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
72 ebuf[0] = '\0';
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
73 @@ -4944,7 +4953,7 @@
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
74 } else if (conn->request_len <= 0) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
75 snprintf(ebuf, ebuf_len, "%s", "Client closed connection");
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
76 } else if (parse_http_message(conn->buf, conn->buf_size,
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
77 - &conn->request_info) <= 0) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
78 + &conn->request_info, isValidHttpMethod) <= 0) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
79 snprintf(ebuf, ebuf_len, "Bad request: [%.*s]", conn->data_len, conn->buf);
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
80 } else {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
81 // Request is valid
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
82 @@ -4973,7 +4982,8 @@
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
83 } else if (mg_vprintf(conn, fmt, ap) <= 0) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
84 snprintf(ebuf, ebuf_len, "%s", "Error sending request");
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
85 } else {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
86 - getreq(conn, ebuf, ebuf_len);
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
87 + int isValidHttpMethod = 1; /* unused in this case */
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
88 + getreq(conn, ebuf, ebuf_len, &isValidHttpMethod);
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
89 }
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
90 if (ebuf[0] != '\0' && conn != NULL) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
91 mg_close_connection(conn);
3119
8f2bda0719f4 Fix issue #125 (Mongoose: /instances/{id} returns 500 on invalid HTTP Method)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1112
diff changeset
92 @@ -4995,8 +5005,13 @@
3475
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
93 // to crule42.
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
94 conn->data_len = 0;
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
95 do {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
96 - if (!getreq(conn, ebuf, sizeof(ebuf))) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
97 + int isValidHttpMethod = 1;
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
98 + if (!getreq(conn, ebuf, sizeof(ebuf), &isValidHttpMethod)) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
99 + if (isValidHttpMethod) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
100 send_http_error(conn, 500, "Server Error", "%s", ebuf);
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
101 + } else {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
102 + send_http_error(conn, 400, "Bad Request", "%s", ebuf);
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
103 + }
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
104 conn->must_close = 1;
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
105 } else if (!is_valid_uri(conn->request_info.uri)) {
72e809e57ba4 fix whitespace problem in mongoose-3.8-patch.diff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3373
diff changeset
106 snprintf(ebuf, sizeof(ebuf), "Invalid URI: [%s]", ri->uri);