diff options
Diffstat (limited to 'src/microhttpd/reason_phrase.c')
-rw-r--r-- | src/microhttpd/reason_phrase.c | 240 |
1 files changed, 126 insertions, 114 deletions
diff --git a/src/microhttpd/reason_phrase.c b/src/microhttpd/reason_phrase.c index 4e54d920..969cf95a 100644 --- a/src/microhttpd/reason_phrase.c +++ b/src/microhttpd/reason_phrase.c | |||
@@ -26,142 +26,143 @@ | |||
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "microhttpd.h" | 28 | #include "microhttpd.h" |
29 | #include "mhd_str.h" | ||
29 | 30 | ||
30 | #ifndef NULL | 31 | #ifndef NULL |
31 | #define NULL ((void*) 0) | 32 | #define NULL ((void*) 0) |
32 | #endif | 33 | #endif |
33 | 34 | ||
34 | static const char *const invalid_hundred[] = { | 35 | static const struct _MHD_str_w_len invalid_hundred[] = { |
35 | NULL | 36 | { NULL, 0 } |
36 | }; | 37 | }; |
37 | 38 | ||
38 | static const char *const one_hundred[] = { | 39 | static const struct _MHD_str_w_len one_hundred[] = { |
39 | /* 100 */ "Continue", /* RFC7231, Section 6.2.1 */ | 40 | /* 100 */ _MHD_S_STR_W_LEN ("Continue"), /* RFC7231, Section 6.2.1 */ |
40 | /* 101 */ "Switching Protocols", /* RFC7231, Section 6.2.2 */ | 41 | /* 101 */ _MHD_S_STR_W_LEN ("Switching Protocols"), /* RFC7231, Section 6.2.2 */ |
41 | /* 102 */ "Processing", /* RFC2518 */ | 42 | /* 102 */ _MHD_S_STR_W_LEN ("Processing"), /* RFC2518 */ |
42 | /* 103 */ "Early Hints" /* RFC8297 */ | 43 | /* 103 */ _MHD_S_STR_W_LEN ("Early Hints") /* RFC8297 */ |
43 | }; | 44 | }; |
44 | 45 | ||
45 | static const char *const two_hundred[] = { | 46 | static const struct _MHD_str_w_len two_hundred[] = { |
46 | /* 200 */ "OK", /* RFC7231, Section 6.3.1 */ | 47 | /* 200 */ _MHD_S_STR_W_LEN ("OK"), /* RFC7231, Section 6.3.1 */ |
47 | /* 201 */ "Created", /* RFC7231, Section 6.3.2 */ | 48 | /* 201 */ _MHD_S_STR_W_LEN ("Created"), /* RFC7231, Section 6.3.2 */ |
48 | /* 202 */ "Accepted", /* RFC7231, Section 6.3.3 */ | 49 | /* 202 */ _MHD_S_STR_W_LEN ("Accepted"), /* RFC7231, Section 6.3.3 */ |
49 | /* 203 */ "Non-Authoritative Information", /* RFC7231, Section 6.3.4 */ | 50 | /* 203 */ _MHD_S_STR_W_LEN ("Non-Authoritative Information"), /* RFC7231, Section 6.3.4 */ |
50 | /* 204 */ "No Content", /* RFC7231, Section 6.3.5 */ | 51 | /* 204 */ _MHD_S_STR_W_LEN ("No Content"), /* RFC7231, Section 6.3.5 */ |
51 | /* 205 */ "Reset Content", /* RFC7231, Section 6.3.6 */ | 52 | /* 205 */ _MHD_S_STR_W_LEN ("Reset Content"), /* RFC7231, Section 6.3.6 */ |
52 | /* 206 */ "Partial Content", /* RFC7233, Section 4.1 */ | 53 | /* 206 */ _MHD_S_STR_W_LEN ("Partial Content"), /* RFC7233, Section 4.1 */ |
53 | /* 207 */ "Multi-Status", /* RFC4918 */ | 54 | /* 207 */ _MHD_S_STR_W_LEN ("Multi-Status"), /* RFC4918 */ |
54 | /* 208 */ "Already Reported", /* RFC5842 */ | 55 | /* 208 */ _MHD_S_STR_W_LEN ("Already Reported"), /* RFC5842 */ |
55 | /* 209 */ "Unknown", /* Not used */ | 56 | /* 209 */ {"Unknown", 0}, /* Not used */ |
56 | /* 210 */ "Unknown", /* Not used */ | 57 | /* 210 */ {"Unknown", 0}, /* Not used */ |
57 | /* 211 */ "Unknown", /* Not used */ | 58 | /* 211 */ {"Unknown", 0}, /* Not used */ |
58 | /* 212 */ "Unknown", /* Not used */ | 59 | /* 212 */ {"Unknown", 0}, /* Not used */ |
59 | /* 213 */ "Unknown", /* Not used */ | 60 | /* 213 */ {"Unknown", 0}, /* Not used */ |
60 | /* 214 */ "Unknown", /* Not used */ | 61 | /* 214 */ {"Unknown", 0}, /* Not used */ |
61 | /* 215 */ "Unknown", /* Not used */ | 62 | /* 215 */ {"Unknown", 0}, /* Not used */ |
62 | /* 216 */ "Unknown", /* Not used */ | 63 | /* 216 */ {"Unknown", 0}, /* Not used */ |
63 | /* 217 */ "Unknown", /* Not used */ | 64 | /* 217 */ {"Unknown", 0}, /* Not used */ |
64 | /* 218 */ "Unknown", /* Not used */ | 65 | /* 218 */ {"Unknown", 0}, /* Not used */ |
65 | /* 219 */ "Unknown", /* Not used */ | 66 | /* 219 */ {"Unknown", 0}, /* Not used */ |
66 | /* 220 */ "Unknown", /* Not used */ | 67 | /* 220 */ {"Unknown", 0}, /* Not used */ |
67 | /* 221 */ "Unknown", /* Not used */ | 68 | /* 221 */ {"Unknown", 0}, /* Not used */ |
68 | /* 222 */ "Unknown", /* Not used */ | 69 | /* 222 */ {"Unknown", 0}, /* Not used */ |
69 | /* 223 */ "Unknown", /* Not used */ | 70 | /* 223 */ {"Unknown", 0}, /* Not used */ |
70 | /* 224 */ "Unknown", /* Not used */ | 71 | /* 224 */ {"Unknown", 0}, /* Not used */ |
71 | /* 225 */ "Unknown", /* Not used */ | 72 | /* 225 */ {"Unknown", 0}, /* Not used */ |
72 | /* 226 */ "IM Used" /* RFC3229 */ | 73 | /* 226 */ _MHD_S_STR_W_LEN ("IM Used") /* RFC3229 */ |
73 | }; | 74 | }; |
74 | 75 | ||
75 | static const char *const three_hundred[] = { | 76 | static const struct _MHD_str_w_len three_hundred[] = { |
76 | /* 300 */ "Multiple Choices", /* RFC7231, Section 6.4.1 */ | 77 | /* 300 */ _MHD_S_STR_W_LEN ("Multiple Choices"), /* RFC7231, Section 6.4.1 */ |
77 | /* 301 */ "Moved Permanently", /* RFC7231, Section 6.4.2 */ | 78 | /* 301 */ _MHD_S_STR_W_LEN ("Moved Permanently"), /* RFC7231, Section 6.4.2 */ |
78 | /* 302 */ "Found", /* RFC7231, Section 6.4.3 */ | 79 | /* 302 */ _MHD_S_STR_W_LEN ("Found"), /* RFC7231, Section 6.4.3 */ |
79 | /* 303 */ "See Other", /* RFC7231, Section 6.4.4 */ | 80 | /* 303 */ _MHD_S_STR_W_LEN ("See Other"), /* RFC7231, Section 6.4.4 */ |
80 | /* 304 */ "Not Modified", /* RFC7232, Section 4.1 */ | 81 | /* 304 */ _MHD_S_STR_W_LEN ("Not Modified"), /* RFC7232, Section 4.1 */ |
81 | /* 305 */ "Use Proxy", /* RFC7231, Section 6.4.5 */ | 82 | /* 305 */ _MHD_S_STR_W_LEN ("Use Proxy"), /* RFC7231, Section 6.4.5 */ |
82 | /* 306 */ "Switch Proxy", /* Not used! RFC7231, Section 6.4.6 */ | 83 | /* 306 */ _MHD_S_STR_W_LEN ("Switch Proxy"), /* Not used! RFC7231, Section 6.4.6 */ |
83 | /* 307 */ "Temporary Redirect", /* RFC7231, Section 6.4.7 */ | 84 | /* 307 */ _MHD_S_STR_W_LEN ("Temporary Redirect"), /* RFC7231, Section 6.4.7 */ |
84 | /* 308 */ "Permanent Redirect" /* RFC7538 */ | 85 | /* 308 */ _MHD_S_STR_W_LEN ("Permanent Redirect") /* RFC7538 */ |
85 | }; | 86 | }; |
86 | 87 | ||
87 | static const char *const four_hundred[] = { | 88 | static const struct _MHD_str_w_len four_hundred[] = { |
88 | /* 400 */ "Bad Request", /* RFC7231, Section 6.5.1 */ | 89 | /* 400 */ _MHD_S_STR_W_LEN ("Bad Request"), /* RFC7231, Section 6.5.1 */ |
89 | /* 401 */ "Unauthorized", /* RFC7235, Section 3.1 */ | 90 | /* 401 */ _MHD_S_STR_W_LEN ("Unauthorized"), /* RFC7235, Section 3.1 */ |
90 | /* 402 */ "Payment Required", /* RFC7231, Section 6.5.2 */ | 91 | /* 402 */ _MHD_S_STR_W_LEN ("Payment Required"), /* RFC7231, Section 6.5.2 */ |
91 | /* 403 */ "Forbidden", /* RFC7231, Section 6.5.3 */ | 92 | /* 403 */ _MHD_S_STR_W_LEN ("Forbidden"), /* RFC7231, Section 6.5.3 */ |
92 | /* 404 */ "Not Found", /* RFC7231, Section 6.5.4 */ | 93 | /* 404 */ _MHD_S_STR_W_LEN ("Not Found"), /* RFC7231, Section 6.5.4 */ |
93 | /* 405 */ "Method Not Allowed", /* RFC7231, Section 6.5.5 */ | 94 | /* 405 */ _MHD_S_STR_W_LEN ("Method Not Allowed"), /* RFC7231, Section 6.5.5 */ |
94 | /* 406 */ "Not Acceptable", /* RFC7231, Section 6.5.6 */ | 95 | /* 406 */ _MHD_S_STR_W_LEN ("Not Acceptable"), /* RFC7231, Section 6.5.6 */ |
95 | /* 407 */ "Proxy Authentication Required", /* RFC7235, Section 3.2 */ | 96 | /* 407 */ _MHD_S_STR_W_LEN ("Proxy Authentication Required"), /* RFC7235, Section 3.2 */ |
96 | /* 408 */ "Request Timeout", /* RFC7231, Section 6.5.7 */ | 97 | /* 408 */ _MHD_S_STR_W_LEN ("Request Timeout"), /* RFC7231, Section 6.5.7 */ |
97 | /* 409 */ "Conflict", /* RFC7231, Section 6.5.8 */ | 98 | /* 409 */ _MHD_S_STR_W_LEN ("Conflict"), /* RFC7231, Section 6.5.8 */ |
98 | /* 410 */ "Gone", /* RFC7231, Section 6.5.9 */ | 99 | /* 410 */ _MHD_S_STR_W_LEN ("Gone"), /* RFC7231, Section 6.5.9 */ |
99 | /* 411 */ "Length Required", /* RFC7231, Section 6.5.10 */ | 100 | /* 411 */ _MHD_S_STR_W_LEN ("Length Required"), /* RFC7231, Section 6.5.10 */ |
100 | /* 412 */ "Precondition Failed", /* RFC7232, Section 4.2; RFC8144, Section 3.2 */ | 101 | /* 412 */ _MHD_S_STR_W_LEN ("Precondition Failed"), /* RFC7232, Section 4.2; RFC8144, Section 3.2 */ |
101 | /* 413 */ "Payload Too Large", /* RFC7231, Section 6.5.11 */ | 102 | /* 413 */ _MHD_S_STR_W_LEN ("Payload Too Large"), /* RFC7231, Section 6.5.11 */ |
102 | /* 414 */ "URI Too Long", /* RFC7231, Section 6.5.12 */ | 103 | /* 414 */ _MHD_S_STR_W_LEN ("URI Too Long"), /* RFC7231, Section 6.5.12 */ |
103 | /* 415 */ "Unsupported Media Type", /* RFC7231, Section 6.5.13; RFC7694, Section 3 */ | 104 | /* 415 */ _MHD_S_STR_W_LEN ("Unsupported Media Type"), /* RFC7231, Section 6.5.13; RFC7694, Section 3 */ |
104 | /* 416 */ "Range Not Satisfiable", /* RFC7233, Section 4.4 */ | 105 | /* 416 */ _MHD_S_STR_W_LEN ("Range Not Satisfiable"), /* RFC7233, Section 4.4 */ |
105 | /* 417 */ "Expectation Failed", /* RFC7231, Section 6.5.14 */ | 106 | /* 417 */ _MHD_S_STR_W_LEN ("Expectation Failed"), /* RFC7231, Section 6.5.14 */ |
106 | /* 418 */ "Unknown", /* Not used */ | 107 | /* 418 */ {"Unknown", 0}, /* Not used */ |
107 | /* 419 */ "Unknown", /* Not used */ | 108 | /* 419 */ {"Unknown", 0}, /* Not used */ |
108 | /* 420 */ "Unknown", /* Not used */ | 109 | /* 420 */ {"Unknown", 0}, /* Not used */ |
109 | /* 421 */ "Misdirected Request", /* RFC7540, Section 9.1.2 */ | 110 | /* 421 */ _MHD_S_STR_W_LEN ("Misdirected Request"), /* RFC7540, Section 9.1.2 */ |
110 | /* 422 */ "Unprocessable Entity", /* RFC4918 */ | 111 | /* 422 */ _MHD_S_STR_W_LEN ("Unprocessable Entity"), /* RFC4918 */ |
111 | /* 423 */ "Locked", /* RFC4918 */ | 112 | /* 423 */ _MHD_S_STR_W_LEN ("Locked"), /* RFC4918 */ |
112 | /* 424 */ "Failed Dependency", /* RFC4918 */ | 113 | /* 424 */ _MHD_S_STR_W_LEN ("Failed Dependency"), /* RFC4918 */ |
113 | /* 425 */ "Too Early", /* RFC8470 */ | 114 | /* 425 */ _MHD_S_STR_W_LEN ("Too Early"), /* RFC8470 */ |
114 | /* 426 */ "Upgrade Required", /* RFC7231, Section 6.5.15 */ | 115 | /* 426 */ _MHD_S_STR_W_LEN ("Upgrade Required"), /* RFC7231, Section 6.5.15 */ |
115 | /* 427 */ "Unknown", /* Not used */ | 116 | /* 427 */ {"Unknown", 0}, /* Not used */ |
116 | /* 428 */ "Precondition Required", /* RFC6585 */ | 117 | /* 428 */ _MHD_S_STR_W_LEN ("Precondition Required"), /* RFC6585 */ |
117 | /* 429 */ "Too Many Requests", /* RFC6585 */ | 118 | /* 429 */ _MHD_S_STR_W_LEN ("Too Many Requests"), /* RFC6585 */ |
118 | /* 430 */ "Unknown", /* Not used */ | 119 | /* 430 */ {"Unknown", 0}, /* Not used */ |
119 | /* 431 */ "Request Header Fields Too Large", /* RFC6585 */ | 120 | /* 431 */ _MHD_S_STR_W_LEN ("Request Header Fields Too Large"), /* RFC6585 */ |
120 | /* 432 */ "Unknown", /* Not used */ | 121 | /* 432 */ {"Unknown", 0}, /* Not used */ |
121 | /* 433 */ "Unknown", /* Not used */ | 122 | /* 433 */ {"Unknown", 0}, /* Not used */ |
122 | /* 434 */ "Unknown", /* Not used */ | 123 | /* 434 */ {"Unknown", 0}, /* Not used */ |
123 | /* 435 */ "Unknown", /* Not used */ | 124 | /* 435 */ {"Unknown", 0}, /* Not used */ |
124 | /* 436 */ "Unknown", /* Not used */ | 125 | /* 436 */ {"Unknown", 0}, /* Not used */ |
125 | /* 437 */ "Unknown", /* Not used */ | 126 | /* 437 */ {"Unknown", 0}, /* Not used */ |
126 | /* 438 */ "Unknown", /* Not used */ | 127 | /* 438 */ {"Unknown", 0}, /* Not used */ |
127 | /* 439 */ "Unknown", /* Not used */ | 128 | /* 439 */ {"Unknown", 0}, /* Not used */ |
128 | /* 440 */ "Unknown", /* Not used */ | 129 | /* 440 */ {"Unknown", 0}, /* Not used */ |
129 | /* 441 */ "Unknown", /* Not used */ | 130 | /* 441 */ {"Unknown", 0}, /* Not used */ |
130 | /* 442 */ "Unknown", /* Not used */ | 131 | /* 442 */ {"Unknown", 0}, /* Not used */ |
131 | /* 443 */ "Unknown", /* Not used */ | 132 | /* 443 */ {"Unknown", 0}, /* Not used */ |
132 | /* 444 */ "Unknown", /* Not used */ | 133 | /* 444 */ {"Unknown", 0}, /* Not used */ |
133 | /* 445 */ "Unknown", /* Not used */ | 134 | /* 445 */ {"Unknown", 0}, /* Not used */ |
134 | /* 446 */ "Unknown", /* Not used */ | 135 | /* 446 */ {"Unknown", 0}, /* Not used */ |
135 | /* 447 */ "Unknown", /* Not used */ | 136 | /* 447 */ {"Unknown", 0}, /* Not used */ |
136 | /* 448 */ "Unknown", /* Not used */ | 137 | /* 448 */ {"Unknown", 0}, /* Not used */ |
137 | /* 449 */ "Reply With", /* MS IIS extension */ | 138 | /* 449 */ _MHD_S_STR_W_LEN ("Reply With"), /* MS IIS extension */ |
138 | /* 450 */ "Blocked by Windows Parental Controls", /* MS extension */ | 139 | /* 450 */ _MHD_S_STR_W_LEN ("Blocked by Windows Parental Controls"), /* MS extension */ |
139 | /* 451 */ "Unavailable For Legal Reasons" /* RFC7725 */ | 140 | /* 451 */ _MHD_S_STR_W_LEN ("Unavailable For Legal Reasons") /* RFC7725 */ |
140 | }; | 141 | }; |
141 | 142 | ||
142 | static const char *const five_hundred[] = { | 143 | static const struct _MHD_str_w_len five_hundred[] = { |
143 | /* 500 */ "Internal Server Error", /* RFC7231, Section 6.6.1 */ | 144 | /* 500 */ _MHD_S_STR_W_LEN ("Internal Server Error"), /* RFC7231, Section 6.6.1 */ |
144 | /* 501 */ "Not Implemented", /* RFC7231, Section 6.6.2 */ | 145 | /* 501 */ _MHD_S_STR_W_LEN ("Not Implemented"), /* RFC7231, Section 6.6.2 */ |
145 | /* 502 */ "Bad Gateway", /* RFC7231, Section 6.6.3 */ | 146 | /* 502 */ _MHD_S_STR_W_LEN ("Bad Gateway"), /* RFC7231, Section 6.6.3 */ |
146 | /* 503 */ "Service Unavailable", /* RFC7231, Section 6.6.4 */ | 147 | /* 503 */ _MHD_S_STR_W_LEN ("Service Unavailable"), /* RFC7231, Section 6.6.4 */ |
147 | /* 504 */ "Gateway Timeout", /* RFC7231, Section 6.6.5 */ | 148 | /* 504 */ _MHD_S_STR_W_LEN ("Gateway Timeout"), /* RFC7231, Section 6.6.5 */ |
148 | /* 505 */ "HTTP Version Not Supported", /* RFC7231, Section 6.6.6 */ | 149 | /* 505 */ _MHD_S_STR_W_LEN ("HTTP Version Not Supported"), /* RFC7231, Section 6.6.6 */ |
149 | /* 506 */ "Variant Also Negotiates", /* RFC2295 */ | 150 | /* 506 */ _MHD_S_STR_W_LEN ("Variant Also Negotiates"), /* RFC2295 */ |
150 | /* 507 */ "Insufficient Storage", /* RFC4918 */ | 151 | /* 507 */ _MHD_S_STR_W_LEN ("Insufficient Storage"), /* RFC4918 */ |
151 | /* 508 */ "Loop Detected", /* RFC5842 */ | 152 | /* 508 */ _MHD_S_STR_W_LEN ("Loop Detected"), /* RFC5842 */ |
152 | /* 509 */ "Bandwidth Limit Exceeded", /* Apache extension */ | 153 | /* 509 */ _MHD_S_STR_W_LEN ("Bandwidth Limit Exceeded"), /* Apache extension */ |
153 | /* 510 */ "Not Extended", /* RFC2774 */ | 154 | /* 510 */ _MHD_S_STR_W_LEN ("Not Extended"), /* RFC2774 */ |
154 | /* 511 */ "Network Authentication Required" /* RFC6585 */ | 155 | /* 511 */ _MHD_S_STR_W_LEN ("Network Authentication Required") /* RFC6585 */ |
155 | }; | 156 | }; |
156 | 157 | ||
157 | 158 | ||
158 | struct MHD_Reason_Block | 159 | struct MHD_Reason_Block |
159 | { | 160 | { |
160 | size_t max; | 161 | size_t max; |
161 | const char *const*data; | 162 | const struct _MHD_str_w_len *const data; |
162 | }; | 163 | }; |
163 | 164 | ||
164 | #define BLOCK(m) { (sizeof(m) / sizeof(char*)), m } | 165 | #define BLOCK(m) { (sizeof(m) / sizeof(m[0])), m } |
165 | 166 | ||
166 | static const struct MHD_Reason_Block reasons[] = { | 167 | static const struct MHD_Reason_Block reasons[] = { |
167 | BLOCK (invalid_hundred), | 168 | BLOCK (invalid_hundred), |
@@ -179,6 +180,17 @@ MHD_get_reason_phrase_for (unsigned int code) | |||
179 | if ( (code >= 100) && | 180 | if ( (code >= 100) && |
180 | (code < 600) && | 181 | (code < 600) && |
181 | (reasons[code / 100].max > (code % 100)) ) | 182 | (reasons[code / 100].max > (code % 100)) ) |
182 | return reasons[code / 100].data[code % 100]; | 183 | return reasons[code / 100].data[code % 100].str; |
183 | return "Unknown"; | 184 | return "Unknown"; |
184 | } | 185 | } |
186 | |||
187 | |||
188 | size_t | ||
189 | MHD_get_reason_phrase_len_for (unsigned int code) | ||
190 | { | ||
191 | if ( (code >= 100) && | ||
192 | (code < 600) && | ||
193 | (reasons[code / 100].max > (code % 100)) ) | ||
194 | return reasons[code / 100].data[code % 100].len; | ||
195 | return 0; | ||
196 | } | ||