]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpRequestMethod.cc
More decoupling work:
[thirdparty/squid.git] / src / HttpRequestMethod.cc
CommitLineData
985c86bc 1
2/*
3 * $Id: HttpRequestMethod.cc,v 1.1 2006/05/08 23:38:33 robertc Exp $
4 *
5 * DEBUG: section 73 HTTP Request
6 * AUTHOR: Duane Wessels
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
35 */
36
37#include "squid.h"
38#include "HttpRequestMethod.h"
39#include "wordlist.h"
40
41const char *RequestMethodStr[] =
42 {
43 "NONE",
44 "GET",
45 "POST",
46 "PUT",
47 "HEAD",
48 "CONNECT",
49 "TRACE",
50 "PURGE",
51 "OPTIONS",
52 "DELETE",
53 "PROPFIND",
54 "PROPPATCH",
55 "MKCOL",
56 "COPY",
57 "MOVE",
58 "LOCK",
59 "UNLOCK",
60 "BMOVE",
61 "BDELETE",
62 "BPROPFIND",
63 "BPROPPATCH",
64 "BCOPY",
65 "SEARCH",
66 "SUBSCRIBE",
67 "UNSUBSCRIBE",
68 "POLL",
69 "REPORT",
70 "%EXT00",
71 "%EXT01",
72 "%EXT02",
73 "%EXT03",
74 "%EXT04",
75 "%EXT05",
76 "%EXT06",
77 "%EXT07",
78 "%EXT08",
79 "%EXT09",
80 "%EXT10",
81 "%EXT11",
82 "%EXT12",
83 "%EXT13",
84 "%EXT14",
85 "%EXT15",
86 "%EXT16",
87 "%EXT17",
88 "%EXT18",
89 "%EXT19",
90 "ERROR"
91 };
92
93static
94method_t &operator++ (method_t &aMethod)
95{
96 int tmp = (int)aMethod;
97 aMethod = (method_t)(++tmp);
98 return aMethod;
99}
100
101/*
102 * Construct a HttpRequestMethod from a NULL terminated string such as "GET"
103 * or from a range of chars, * such as "GET" from "GETFOOBARBAZ"
104 * (pass in pointer to G and pointer to F.)
105 */
106HttpRequestMethod::HttpRequestMethod(char const *begin, char const *end) : theMethod (METHOD_NONE)
107{
108 if (begin == NULL)
109 return;
110
111 /*
112 * This check for '%' makes sure that we don't
113 * match one of the extension method placeholders,
114 * which have the form %EXT[0-9][0-9]
115 */
116
117 if (*begin == '%')
118 return;
119
120 /*
121 * if e is NULL, b must be NULL terminated and we
122 * make e point to the first whitespace character
123 * after b.
124 */
125 if (NULL == end)
126 end = begin + strcspn(begin, w_space);
127
128 for (++theMethod; theMethod < METHOD_ENUM_END; ++theMethod) {
129 if (0 == strncasecmp(begin, RequestMethodStr[theMethod], end-begin))
130 return;
131 }
132
133 /* reset to none */
134 theMethod = METHOD_NONE;
135}
136
137void
138HttpRequestMethod::AddExtension(const char *mstr)
139{
140 method_t method = METHOD_NONE;
141
142 for (++method; method < METHOD_ENUM_END; ++method) {
143 if (0 == strcmp(mstr, RequestMethodStr[method])) {
144 debug(23, 2) ("Extension method '%s' already exists\n", mstr);
145 return;
146 }
147
148 if (0 != strncmp("%EXT", RequestMethodStr[method], 4))
149 continue;
150
151 /* Don't free statically allocated "%EXTnn" string */
152 RequestMethodStr[method] = xstrdup(mstr);
153
154 debug(23, 1) ("Extension method '%s' added, enum=%d\n", mstr, (int) method);
155
156 return;
157 }
158
159 debug(23, 1) ("WARNING: Could not add new extension method '%s' due to lack of array space\n", mstr);
160}
161
162void
163HttpRequestMethod::Configure(SquidConfig &Config)
164{
165 wordlist *w = Config.ext_methods;
166
167 while (w) {
168 char *s;
169
170 for (s = w->key; *s; s++)
171 *s = xtoupper(*s);
172
173 AddExtension(w->key);
174
175 w = w->next;
176 }
177}