GNU libmicrohttpd  0.9.29
reason_phrase.c
Go to the documentation of this file.
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 */
27 #include "platform.h"
28 #include "microhttpd.h"
29 
30 #ifndef NULL
31 #define NULL ((void*)0)
32 #endif
33 
34 static const char *const invalid_hundred[] = {
35  NULL
36 };
37 
38 static const char *const one_hundred[] = {
39  "Continue",
40  "Switching Protocols",
41  "Processing"
42 };
43 
44 static const char *const two_hundred[] = {
45  "OK",
46  "Created",
47  "Accepted",
48  "Non-Authoritative Information",
49  "No Content",
50  "Reset Content",
51  "Partial Content",
52  "Multi-Status",
53  "Already Reported",
54  "Unknown",
55  "Unknown", /* 210 */
56  "Unknown",
57  "Unknown",
58  "Unknown",
59  "Unknown",
60  "Unknown", /* 215 */
61  "Unknown",
62  "Unknown",
63  "Unknown",
64  "Unknown",
65  "Unknown", /* 220 */
66  "Unknown",
67  "Unknown",
68  "Unknown",
69  "Unknown",
70  "Unknown", /* 225 */
71  "IM Used"
72 };
73 
74 static const char *const three_hundred[] = {
75  "Multiple Choices",
76  "Moved Permanently",
77  "Found",
78  "See Other",
79  "Not Modified",
80  "Use Proxy",
81  "Switch Proxy",
82  "Temporary Redirect",
83  "Permanent Redirect"
84 };
85 
86 static const char *const four_hundred[] = {
87  "Bad Request",
88  "Unauthorized",
89  "Payment Required",
90  "Forbidden",
91  "Not Found",
92  "Method Not Allowed",
93  "Not Acceptable",
94  "Proxy Authentication Required",
95  "Request Timeout",
96  "Conflict",
97  "Gone",
98  "Length Required",
99  "Precondition Failed",
100  "Payload Too Large",
101  "URI Too Long",
102  "Unsupported Media Type",
103  "Range Not Satisfiable",
104  "Expectation Failed",
105  "Unknown",
106  "Unknown",
107  "Unknown", /* 420 */
108  "Misdirected Request",
109  "Unprocessable Entity",
110  "Locked",
111  "Failed Dependency",
112  "Unordered Collection",
113  "Upgrade Required",
114  "Unknown",
115  "Precondition Required",
116  "Too Many Requests",
117  "Unknown", /* 430 */
118  "Request Header Fields Too Large",
119  "Unknown",
120  "Unknown",
121  "Unknown",
122  "Unknown", /* 435 */
123  "Unknown",
124  "Unknown",
125  "Unknown",
126  "Unknown",
127  "Unknown", /* 440 */
128  "Unknown",
129  "Unknown",
130  "Unknown",
131  "No Response",
132  "Unknown", /* 445 */
133  "Unknown",
134  "Unknown",
135  "Unknown",
136  "Retry With",
137  "Blocked by Windows Parental Controls", /* 450 */
138  "Unavailable For Legal Reasons"
139 };
140 
141 static const char *const five_hundred[] = {
142  "Internal Server Error",
143  "Not Implemented",
144  "Bad Gateway",
145  "Service Unavailable",
146  "Gateway Timeout",
147  "HTTP Version Not Supported",
148  "Variant Also Negotiates",
149  "Insufficient Storage",
150  "Loop Detected",
151  "Bandwidth Limit Exceeded",
152  "Not Extended",
153  "Network Authentication Required"
154 };
155 
156 
157 struct MHD_Reason_Block
158 {
159  size_t max;
160  const char *const*data;
161 };
162 
163 #define BLOCK(m) { (sizeof(m) / sizeof(char*)), m }
164 
165 static const struct MHD_Reason_Block reasons[] = {
167  BLOCK (one_hundred),
168  BLOCK (two_hundred),
172 };
173 
174 
175 const char *
176 MHD_get_reason_phrase_for (unsigned int code)
177 {
178  if ( (code >= 100) &&
179  (code < 600) &&
180  (reasons[code / 100].max > (code % 100)) )
181  return reasons[code / 100].data[code % 100];
182  return "Unknown";
183 }
public interface to libmicrohttpd
#define NULL
Definition: reason_phrase.c:31
static const char *const five_hundred[]
static const char *const three_hundred[]
Definition: reason_phrase.c:74
platform-specific includes for libmicrohttpd
static const char *const two_hundred[]
Definition: reason_phrase.c:44
static const struct MHD_Reason_Block reasons[]
static const char *const invalid_hundred[]
Definition: reason_phrase.c:34
const char * MHD_get_reason_phrase_for(unsigned int code)
static const char *const four_hundred[]
Definition: reason_phrase.c:86
#define BLOCK(m)
static const char *const one_hundred[]
Definition: reason_phrase.c:38