GNU libmicrohttpd  0.9.5
reason_phrase.c
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  (C) 2007 Lymba
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 
28 #include "reason_phrase.h"
29 
30 #ifndef NULL
31 #define NULL (void*)0
32 #endif // !NULL
33 
34 static const char *invalid_hundred[] = { NULL };
35 
36 static const char *one_hundred[] = {
37  "Continue",
38  "Switching Protocols",
39  "Processing"
40 };
41 
42 static const char *two_hundred[] = {
43  "OK",
44  "Created",
45  "Accepted",
46  "Non-Authoritative Information",
47  "No Content",
48  "Reset Content",
49  "Partial Content",
50  "Multi Status"
51 };
52 
53 static const char *three_hundred[] = {
54  "Multiple Choices",
55  "Moved Permanently",
56  "Moved Temporarily",
57  "See Other",
58  "Not Modified",
59  "Use Proxy",
60  "Switch Proxy",
61  "Temporary Redirect"
62 };
63 
64 static const char *four_hundred[] = {
65  "Bad Request",
66  "Unauthorized",
67  "Payment Required",
68  "Forbidden",
69  "Not Found",
70  "Method Not Allowed",
71  "Not Acceptable",
72  "Proxy Authentication Required",
73  "Request Time-out",
74  "Conflict",
75  "Gone",
76  "Length Required",
77  "Precondition Failed",
78  "Request Entity Too Large",
79  "Request-URI Too Large",
80  "Unsupported Media Type",
81  "Requested Range Not Satisfiable",
82  "Expectation Failed",
83  "Unprocessable Entity",
84  "Locked",
85  "Failed Dependency",
86  "Unordered Collection",
87  "Upgrade Required",
88  "Retry With"
89 };
90 
91 static const char *five_hundred[] = {
92  "Internal Server Error",
93  "Not Implemented",
94  "Bad Gateway",
95  "Service Unavailable",
96  "Gateway Time-out",
97  "HTTP Version not supported",
98  "Variant Also Negotiates",
99  "Insufficient Storage",
100  "Bandwidth Limit Exceeded",
101  "Not Extended"
102 };
103 
104 
105 struct MHD_Reason_Block
106 {
107  unsigned int max;
108  const char **data;
109 };
110 
111 #define BLOCK(m) { (sizeof(m) / sizeof(char*)), m }
112 
113 static const struct MHD_Reason_Block reasons[] = {
115  BLOCK (one_hundred),
116  BLOCK (two_hundred),
120 };
121 
122 const char *
123 MHD_get_reason_phrase_for (unsigned int code)
124 {
125  if ((code >= 100 && code < 600) && (reasons[code / 100].max > code % 100))
126  return reasons[code / 100].data[code % 100];
127  return "Unknown";
128 }