GNU libmicrohttpd  0.9.76
reason_phrase.c
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  Copyright (C) 2007, 2011, 2017, 2019 Christian Grothoff, Karlson2k (Evgeny Grin)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
27 #include "platform.h"
28 #include "microhttpd.h"
29 #include "mhd_str.h"
30 
31 #ifndef NULL
32 #define NULL ((void*) 0)
33 #endif
34 
35 static const struct _MHD_str_w_len invalid_hundred[] = {
36  { NULL, 0 }
37 };
38 
39 static const struct _MHD_str_w_len one_hundred[] = {
40  /* 100 */ _MHD_S_STR_W_LEN ("Continue"), /* RFC-ietf-httpbis-semantics, Section 15.2.1 */
41  /* 101 */ _MHD_S_STR_W_LEN ("Switching Protocols"), /* RFC-ietf-httpbis-semantics, Section 15.2.2 */
42  /* 102 */ _MHD_S_STR_W_LEN ("Processing"), /* RFC2518 */
43  /* 103 */ _MHD_S_STR_W_LEN ("Early Hints") /* RFC8297 */
44 };
45 
46 static const struct _MHD_str_w_len two_hundred[] = {
47  /* 200 */ _MHD_S_STR_W_LEN ("OK"), /* RFC-ietf-httpbis-semantics, Section 15.3.1 */
48  /* 201 */ _MHD_S_STR_W_LEN ("Created"), /* RFC-ietf-httpbis-semantics, Section 15.3.2 */
49  /* 202 */ _MHD_S_STR_W_LEN ("Accepted"), /* RFC-ietf-httpbis-semantics, Section 15.3.3 */
50  /* 203 */ _MHD_S_STR_W_LEN ("Non-Authoritative Information"), /* RFC-ietf-httpbis-semantics, Section 15.3.4 */
51  /* 204 */ _MHD_S_STR_W_LEN ("No Content"), /* RFC-ietf-httpbis-semantics, Section 15.3.5 */
52  /* 205 */ _MHD_S_STR_W_LEN ("Reset Content"), /* RFC-ietf-httpbis-semantics, Section 15.3.6 */
53  /* 206 */ _MHD_S_STR_W_LEN ("Partial Content"), /* RFC-ietf-httpbis-semantics, Section 15.3.7 */
54  /* 207 */ _MHD_S_STR_W_LEN ("Multi-Status"), /* RFC4918 */
55  /* 208 */ _MHD_S_STR_W_LEN ("Already Reported"), /* RFC5842 */
56  /* 209 */ {"Unknown", 0}, /* Not used */
57  /* 210 */ {"Unknown", 0}, /* Not used */
58  /* 211 */ {"Unknown", 0}, /* Not used */
59  /* 212 */ {"Unknown", 0}, /* Not used */
60  /* 213 */ {"Unknown", 0}, /* Not used */
61  /* 214 */ {"Unknown", 0}, /* Not used */
62  /* 215 */ {"Unknown", 0}, /* Not used */
63  /* 216 */ {"Unknown", 0}, /* Not used */
64  /* 217 */ {"Unknown", 0}, /* Not used */
65  /* 218 */ {"Unknown", 0}, /* Not used */
66  /* 219 */ {"Unknown", 0}, /* Not used */
67  /* 220 */ {"Unknown", 0}, /* Not used */
68  /* 221 */ {"Unknown", 0}, /* Not used */
69  /* 222 */ {"Unknown", 0}, /* Not used */
70  /* 223 */ {"Unknown", 0}, /* Not used */
71  /* 224 */ {"Unknown", 0}, /* Not used */
72  /* 225 */ {"Unknown", 0}, /* Not used */
73  /* 226 */ _MHD_S_STR_W_LEN ("IM Used") /* RFC3229 */
74 };
75 
76 static const struct _MHD_str_w_len three_hundred[] = {
77  /* 300 */ _MHD_S_STR_W_LEN ("Multiple Choices"), /* RFC-ietf-httpbis-semantics, Section 15.4.1 */
78  /* 301 */ _MHD_S_STR_W_LEN ("Moved Permanently"), /* RFC-ietf-httpbis-semantics, Section 15.4.2 */
79  /* 302 */ _MHD_S_STR_W_LEN ("Found"), /* RFC-ietf-httpbis-semantics, Section 15.4.3 */
80  /* 303 */ _MHD_S_STR_W_LEN ("See Other"), /* RFC-ietf-httpbis-semantics, Section 15.4.4 */
81  /* 304 */ _MHD_S_STR_W_LEN ("Not Modified"), /* RFC-ietf-httpbis-semantics, Section 15.4.5 */
82  /* 305 */ _MHD_S_STR_W_LEN ("Use Proxy"), /* RFC-ietf-httpbis-semantics, Section 15.4.6 */
83  /* 306 */ _MHD_S_STR_W_LEN ("Switch Proxy"), /* Not used! RFC-ietf-httpbis-semantics, Section 15.4.7 */
84  /* 307 */ _MHD_S_STR_W_LEN ("Temporary Redirect"), /* RFC-ietf-httpbis-semantics, Section 15.4.8 */
85  /* 308 */ _MHD_S_STR_W_LEN ("Permanent Redirect") /* RFC-ietf-httpbis-semantics, Section 15.4.9 */
86 };
87 
88 static const struct _MHD_str_w_len four_hundred[] = {
89  /* 400 */ _MHD_S_STR_W_LEN ("Bad Request"), /* RFC-ietf-httpbis-semantics, Section 15.5.1 */
90  /* 401 */ _MHD_S_STR_W_LEN ("Unauthorized"), /* RFC-ietf-httpbis-semantics, Section 15.5.2 */
91  /* 402 */ _MHD_S_STR_W_LEN ("Payment Required"), /* RFC-ietf-httpbis-semantics, Section 15.5.3 */
92  /* 403 */ _MHD_S_STR_W_LEN ("Forbidden"), /* RFC-ietf-httpbis-semantics, Section 15.5.4 */
93  /* 404 */ _MHD_S_STR_W_LEN ("Not Found"), /* RFC-ietf-httpbis-semantics, Section 15.5.5 */
94  /* 405 */ _MHD_S_STR_W_LEN ("Method Not Allowed"), /* RFC-ietf-httpbis-semantics, Section 15.5.6 */
95  /* 406 */ _MHD_S_STR_W_LEN ("Not Acceptable"), /* RFC-ietf-httpbis-semantics, Section 15.5.7 */
96  /* 407 */ _MHD_S_STR_W_LEN ("Proxy Authentication Required"), /* RFC-ietf-httpbis-semantics, Section 15.5.8 */
97  /* 408 */ _MHD_S_STR_W_LEN ("Request Timeout"), /* RFC-ietf-httpbis-semantics, Section 15.5.9 */
98  /* 409 */ _MHD_S_STR_W_LEN ("Conflict"), /* RFC-ietf-httpbis-semantics, Section 15.5.10 */
99  /* 410 */ _MHD_S_STR_W_LEN ("Gone"), /* RFC-ietf-httpbis-semantics, Section 15.5.11 */
100  /* 411 */ _MHD_S_STR_W_LEN ("Length Required"), /* RFC-ietf-httpbis-semantics, Section 15.5.12 */
101  /* 412 */ _MHD_S_STR_W_LEN ("Precondition Failed"), /* RFC-ietf-httpbis-semantics, Section 15.5.13 */
102  /* 413 */ _MHD_S_STR_W_LEN ("Content Too Large"), /* RFC-ietf-httpbis-semantics, Section 15.5.14 */
103  /* 414 */ _MHD_S_STR_W_LEN ("URI Too Long"), /* RFC-ietf-httpbis-semantics, Section 15.5.15 */
104  /* 415 */ _MHD_S_STR_W_LEN ("Unsupported Media Type"), /* RFC-ietf-httpbis-semantics, Section 15.5.16 */
105  /* 416 */ _MHD_S_STR_W_LEN ("Range Not Satisfiable"), /* RFC-ietf-httpbis-semantics, Section 15.5.17 */
106  /* 417 */ _MHD_S_STR_W_LEN ("Expectation Failed"), /* RFC-ietf-httpbis-semantics, Section 15.5.18 */
107  /* 418 */ {"Unknown", 0}, /* Not used */
108  /* 419 */ {"Unknown", 0}, /* Not used */
109  /* 420 */ {"Unknown", 0}, /* Not used */
110  /* 421 */ _MHD_S_STR_W_LEN ("Misdirected Request"), /* RFC-ietf-httpbis-semantics, Section 15.5.20 */
111  /* 422 */ _MHD_S_STR_W_LEN ("Unprocessable Content"), /* RFC-ietf-httpbis-semantics, Section 15.5.21 */
112  /* 423 */ _MHD_S_STR_W_LEN ("Locked"), /* RFC4918 */
113  /* 424 */ _MHD_S_STR_W_LEN ("Failed Dependency"), /* RFC4918 */
114  /* 425 */ _MHD_S_STR_W_LEN ("Too Early"), /* RFC8470 */
115  /* 426 */ _MHD_S_STR_W_LEN ("Upgrade Required"), /* RFC-ietf-httpbis-semantics, Section 15.5.22 */
116  /* 427 */ {"Unknown", 0}, /* Not used */
117  /* 428 */ _MHD_S_STR_W_LEN ("Precondition Required"), /* RFC6585 */
118  /* 429 */ _MHD_S_STR_W_LEN ("Too Many Requests"), /* RFC6585 */
119  /* 430 */ {"Unknown", 0}, /* Not used */
120  /* 431 */ _MHD_S_STR_W_LEN ("Request Header Fields Too Large"), /* RFC6585 */
121  /* 432 */ {"Unknown", 0}, /* Not used */
122  /* 433 */ {"Unknown", 0}, /* Not used */
123  /* 434 */ {"Unknown", 0}, /* Not used */
124  /* 435 */ {"Unknown", 0}, /* Not used */
125  /* 436 */ {"Unknown", 0}, /* Not used */
126  /* 437 */ {"Unknown", 0}, /* Not used */
127  /* 438 */ {"Unknown", 0}, /* Not used */
128  /* 439 */ {"Unknown", 0}, /* Not used */
129  /* 440 */ {"Unknown", 0}, /* Not used */
130  /* 441 */ {"Unknown", 0}, /* Not used */
131  /* 442 */ {"Unknown", 0}, /* Not used */
132  /* 443 */ {"Unknown", 0}, /* Not used */
133  /* 444 */ {"Unknown", 0}, /* Not used */
134  /* 445 */ {"Unknown", 0}, /* Not used */
135  /* 446 */ {"Unknown", 0}, /* Not used */
136  /* 447 */ {"Unknown", 0}, /* Not used */
137  /* 448 */ {"Unknown", 0}, /* Not used */
138  /* 449 */ _MHD_S_STR_W_LEN ("Reply With"), /* MS IIS extension */
139  /* 450 */ _MHD_S_STR_W_LEN ("Blocked by Windows Parental Controls"), /* MS extension */
140  /* 451 */ _MHD_S_STR_W_LEN ("Unavailable For Legal Reasons") /* RFC7725 */
141 };
142 
143 static const struct _MHD_str_w_len five_hundred[] = {
144  /* 500 */ _MHD_S_STR_W_LEN ("Internal Server Error"), /* RFC-ietf-httpbis-semantics, Section 15.6.1 */
145  /* 501 */ _MHD_S_STR_W_LEN ("Not Implemented"), /* RFC-ietf-httpbis-semantics, Section 15.6.2 */
146  /* 502 */ _MHD_S_STR_W_LEN ("Bad Gateway"), /* RFC-ietf-httpbis-semantics, Section 15.6.3 */
147  /* 503 */ _MHD_S_STR_W_LEN ("Service Unavailable"), /* RFC-ietf-httpbis-semantics, Section 15.6.4 */
148  /* 504 */ _MHD_S_STR_W_LEN ("Gateway Timeout"), /* RFC-ietf-httpbis-semantics, Section 15.6.5 */
149  /* 505 */ _MHD_S_STR_W_LEN ("HTTP Version Not Supported"), /* RFC-ietf-httpbis-semantics, Section 15.6.6 */
150  /* 506 */ _MHD_S_STR_W_LEN ("Variant Also Negotiates"), /* RFC2295 */
151  /* 507 */ _MHD_S_STR_W_LEN ("Insufficient Storage"), /* RFC4918 */
152  /* 508 */ _MHD_S_STR_W_LEN ("Loop Detected"), /* RFC5842 */
153  /* 509 */ _MHD_S_STR_W_LEN ("Bandwidth Limit Exceeded"), /* Apache extension */
154  /* 510 */ _MHD_S_STR_W_LEN ("Not Extended"), /* RFC2774 */
155  /* 511 */ _MHD_S_STR_W_LEN ("Network Authentication Required") /* RFC6585 */
156 };
157 
158 
159 struct MHD_Reason_Block
160 {
161  size_t max;
162  const struct _MHD_str_w_len *const data;
163 };
164 
165 #define BLOCK(m) { (sizeof(m) / sizeof(m[0])), m }
166 
167 static const struct MHD_Reason_Block reasons[] = {
169  BLOCK (one_hundred),
170  BLOCK (two_hundred),
174 };
175 
176 
177 const char *
178 MHD_get_reason_phrase_for (unsigned int code)
179 {
180  if ( (code >= 100) &&
181  (code < 600) &&
182  (reasons[code / 100].max > (code % 100)) )
183  return reasons[code / 100].data[code % 100].str;
184  return "Unknown";
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 }
const char * MHD_get_reason_phrase_for(enum MHD_HTTP_StatusCode code)
Header for string manipulating helpers.
#define _MHD_S_STR_W_LEN(str)
Definition: mhd_str.h:66
#define NULL
Definition: reason_phrase.c:32
static const struct _MHD_str_w_len one_hundred[]
Definition: reason_phrase.c:39
static const struct MHD_Reason_Block reasons[]
#define BLOCK(m)
static const struct _MHD_str_w_len two_hundred[]
Definition: reason_phrase.c:46
static const struct _MHD_str_w_len five_hundred[]
static const struct _MHD_str_w_len invalid_hundred[]
Definition: reason_phrase.c:35
size_t MHD_get_reason_phrase_len_for(unsigned int code)
static const struct _MHD_str_w_len three_hundred[]
Definition: reason_phrase.c:76
static const struct _MHD_str_w_len four_hundred[]
Definition: reason_phrase.c:88
public interface to libmicrohttpd
void * data
Definition: microhttpd.h:3428
platform-specific includes for libmicrohttpd