aboutsummaryrefslogtreecommitdiff
path: root/src/lib/reason_phrase.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/reason_phrase.c')
-rw-r--r--src/lib/reason_phrase.c182
1 files changed, 182 insertions, 0 deletions
diff --git a/src/lib/reason_phrase.c b/src/lib/reason_phrase.c
new file mode 100644
index 00000000..97ace0a3
--- /dev/null
+++ b/src/lib/reason_phrase.c
@@ -0,0 +1,182 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007, 2011, 2017 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*/
20/**
21 * @file reason_phrase.c
22 * @brief Tables of the string response phrases
23 * @author Elliot Glaysher
24 * @author Christian Grothoff (minor code clean up)
25 * @author Karlson2k (Evgeny Grin)
26 */
27#include "internal.h"
28
29#ifndef NULL
30#define NULL ((void*)0)
31#endif
32
33static const char *const invalid_hundred[] = {
34 NULL
35};
36
37static const char *const one_hundred[] = {
38 "Continue",
39 "Switching Protocols",
40 "Processing"
41};
42
43static const char *const two_hundred[] = {
44 "OK",
45 "Created",
46 "Accepted",
47 "Non-Authoritative Information",
48 "No Content",
49 "Reset Content",
50 "Partial Content",
51 "Multi-Status",
52 "Already Reported",
53 "Unknown",
54 "Unknown", /* 210 */
55 "Unknown",
56 "Unknown",
57 "Unknown",
58 "Unknown",
59 "Unknown", /* 215 */
60 "Unknown",
61 "Unknown",
62 "Unknown",
63 "Unknown",
64 "Unknown", /* 220 */
65 "Unknown",
66 "Unknown",
67 "Unknown",
68 "Unknown",
69 "Unknown", /* 225 */
70 "IM Used"
71};
72
73static const char *const three_hundred[] = {
74 "Multiple Choices",
75 "Moved Permanently",
76 "Found",
77 "See Other",
78 "Not Modified",
79 "Use Proxy",
80 "Switch Proxy",
81 "Temporary Redirect",
82 "Permanent Redirect"
83};
84
85static const char *const four_hundred[] = {
86 "Bad Request",
87 "Unauthorized",
88 "Payment Required",
89 "Forbidden",
90 "Not Found",
91 "Method Not Allowed",
92 "Not Acceptable",
93 "Proxy Authentication Required",
94 "Request Timeout",
95 "Conflict",
96 "Gone",
97 "Length Required",
98 "Precondition Failed",
99 "Payload Too Large",
100 "URI Too Long",
101 "Unsupported Media Type",
102 "Range Not Satisfiable",
103 "Expectation Failed",
104 "Unknown",
105 "Unknown",
106 "Unknown", /* 420 */
107 "Misdirected Request",
108 "Unprocessable Entity",
109 "Locked",
110 "Failed Dependency",
111 "Unordered Collection",
112 "Upgrade Required",
113 "Unknown",
114 "Precondition Required",
115 "Too Many Requests",
116 "Unknown", /* 430 */
117 "Request Header Fields Too Large",
118 "Unknown",
119 "Unknown",
120 "Unknown",
121 "Unknown", /* 435 */
122 "Unknown",
123 "Unknown",
124 "Unknown",
125 "Unknown",
126 "Unknown", /* 440 */
127 "Unknown",
128 "Unknown",
129 "Unknown",
130 "No Response",
131 "Unknown", /* 445 */
132 "Unknown",
133 "Unknown",
134 "Unknown",
135 "Retry With",
136 "Blocked by Windows Parental Controls", /* 450 */
137 "Unavailable For Legal Reasons"
138};
139
140static const char *const five_hundred[] = {
141 "Internal Server Error",
142 "Not Implemented",
143 "Bad Gateway",
144 "Service Unavailable",
145 "Gateway Timeout",
146 "HTTP Version Not Supported",
147 "Variant Also Negotiates",
148 "Insufficient Storage",
149 "Loop Detected",
150 "Bandwidth Limit Exceeded",
151 "Not Extended",
152 "Network Authentication Required"
153};
154
155
156struct MHD_Reason_Block
157{
158 size_t max;
159 const char *const*data;
160};
161
162#define BLOCK(m) { (sizeof(m) / sizeof(char*)), m }
163
164static const struct MHD_Reason_Block reasons[] = {
165 BLOCK (invalid_hundred),
166 BLOCK (one_hundred),
167 BLOCK (two_hundred),
168 BLOCK (three_hundred),
169 BLOCK (four_hundred),
170 BLOCK (five_hundred),
171};
172
173
174const char *
175MHD_get_reason_phrase_for (enum MHD_HTTP_StatusCode code)
176{
177 if ( (code >= 100) &&
178 (code < 600) &&
179 (reasons[code / 100].max > (code % 100)) )
180 return reasons[code / 100].data[code % 100];
181 return "Unknown";
182}