]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpStatusLine.cc
gindent
[thirdparty/squid.git] / src / HttpStatusLine.cc
CommitLineData
cb69b4c7 1/*
adba4a64 2 * $Id: HttpStatusLine.cc,v 1.4 1998/02/26 08:10:55 rousskov Exp $
cb69b4c7 3 *
123abbe1 4 * DEBUG: section 57 HTTP Status-line
cb69b4c7 5 * AUTHOR: Alex Rousskov
6 *
7 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
8 * --------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from the
11 * Internet community. Development is led by Duane Wessels of the
12 * National Laboratory for Applied Network Research and funded by
13 * the National Science Foundation.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 */
30
31#include "squid.h"
32
33
34/* local constants */
35const char *HttpStatusLineFormat = "HTTP/%3.1f %3d %s\r\n";
36
37/* local routines */
38static const char *httpStatusString(http_status status);
39
adba4a64 40
41
cb69b4c7 42void
43httpStatusLineInit(HttpStatusLine *sline) {
44 httpStatusLineSet(sline, 0.0, 0, NULL);
45}
46
47void
48httpStatusLineClean(HttpStatusLine *sline) {
49 httpStatusLineSet(sline, 0.0, 500, NULL);
50}
51
adba4a64 52/* set values */
cb69b4c7 53void httpStatusLineSet(HttpStatusLine *sline, double version, http_status status, const char *reason) {
54 assert(sline);
55 sline->version = version;
56 sline->status = status;
57 /* Note: no xstrdup for 'reason', assumes constant 'reasons' */
58 sline->reason = reason;
59}
60
adba4a64 61/* parse a 0-terminating buffer and fill internal structires; returns true on success */
cb69b4c7 62void
63httpStatusLinePackInto(const HttpStatusLine *sline, Packer *p)
64{
65 assert(sline && p);
66 tmp_debug(here) ("packing sline %p using %p:\n", sline, p);
67 tmp_debug(here) (HttpStatusLineFormat, sline->version, sline->status,
68 sline->reason ? sline->reason : httpStatusString(sline->status));
69 packerPrintf(p, HttpStatusLineFormat,
70 sline->version, sline->status,
71 sline->reason ? sline->reason : httpStatusString(sline->status));
72}
73
adba4a64 74/* pack fields using Packer */
cb69b4c7 75int
76httpStatusLineParse(HttpStatusLine *sline, const char *start, const char *end) {
77 assert(sline);
78 sline->status = HTTP_INVALID_HEADER; /* Squid header parsing error */
79 if (strncasecmp(start, "HTTP/", 5))
80 return 0;
81 start += 5;
82 if (!isdigit(*start))
83 return 0;
84 sline->version = atof(start);
85 if (!(start = strchr(start, ' ')))
86 return 0;
87 sline->status = atoi(++start);
88 /* we ignore 'reason-phrase' */
89 return 1; /* success */
90}
91
92static const char *
93httpStatusString(http_status status)
94{
95 /* why not to return matching string instead of using "p" ? @?@ */
96 const char *p = NULL;
97 switch (status) {
98 case 0:
99 p = "Init"; /* we init .status with code 0 */
100 break;
101 case 100:
102 p = "Continue";
103 break;
104 case 101:
105 p = "Switching Protocols";
106 break;
107 case 200:
108 p = "OK";
109 break;
110 case 201:
111 p = "Created";
112 break;
113 case 202:
114 p = "Accepted";
115 break;
116 case 203:
117 p = "Non-Authoritative Information";
118 break;
119 case 204:
120 p = "No Content";
121 break;
122 case 205:
123 p = "Reset Content";
124 break;
125 case 206:
126 p = "Partial Content";
127 break;
128 case 300:
129 p = "Multiple Choices";
130 break;
131 case 301:
132 p = "Moved Permanently";
133 break;
134 case 302:
135 p = "Moved Temporarily";
136 break;
137 case 303:
138 p = "See Other";
139 break;
140 case 304:
141 p = "Not Modified";
142 break;
143 case 305:
144 p = "Use Proxy";
145 break;
146 case 400:
147 p = "Bad Request";
148 break;
149 case 401:
150 p = "Unauthorized";
151 break;
152 case 402:
153 p = "Payment Required";
154 break;
155 case 403:
156 p = "Forbidden";
157 break;
158 case 404:
159 p = "Not Found";
160 break;
161 case 405:
162 p = "Method Not Allowed";
163 break;
164 case 406:
165 p = "Not Acceptable";
166 break;
167 case 407:
168 p = "Proxy Authentication Required";
169 break;
170 case 408:
171 p = "Request Time-out";
172 break;
173 case 409:
174 p = "Conflict";
175 break;
176 case 410:
177 p = "Gone";
178 break;
179 case 411:
180 p = "Length Required";
181 break;
182 case 412:
183 p = "Precondition Failed";
184 break;
185 case 413:
186 p = "Request Entity Too Large";
187 break;
188 case 414:
189 p = "Request-URI Too Large";
190 break;
191 case 415:
192 p = "Unsupported Media Type";
193 break;
194 case 500:
195 p = "Internal Server Error";
196 break;
197 case 501:
198 p = "Not Implemented";
199 break;
200 case 502:
201 p = "Bad Gateway";
202 break;
203 case 503:
204 p = "Service Unavailable";
205 break;
206 case 504:
207 p = "Gateway Time-out";
208 break;
209 case 505:
210 p = "HTTP Version not supported";
211 break;
212 default:
213 p = "Unknown";
214 debug(11, 0) ("Unknown HTTP status code: %d\n", status);
215 break;
216 }
217 return p;
218}