]>
Commit | Line | Data |
---|---|---|
985c86bc | 1 | |
2 | /* | |
914b89a2 | 3 | * $Id: HttpRequestMethod.cc,v 1.6 2008/02/03 10:00:29 amosjeffries Exp $ |
985c86bc | 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 | ||
60745f24 | 41 | const char* HttpRequestMethod::RequestMethodStr[] = |
985c86bc | 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", | |
dd13ffdb | 70 | "MKACTIVITY", |
71 | "CHECKOUT", | |
72 | "MERGE", | |
985c86bc | 73 | "%EXT00", |
74 | "%EXT01", | |
75 | "%EXT02", | |
76 | "%EXT03", | |
77 | "%EXT04", | |
78 | "%EXT05", | |
79 | "%EXT06", | |
80 | "%EXT07", | |
81 | "%EXT08", | |
82 | "%EXT09", | |
83 | "%EXT10", | |
84 | "%EXT11", | |
85 | "%EXT12", | |
86 | "%EXT13", | |
87 | "%EXT14", | |
88 | "%EXT15", | |
89 | "%EXT16", | |
90 | "%EXT17", | |
91 | "%EXT18", | |
92 | "%EXT19", | |
93 | "ERROR" | |
94 | }; | |
95 | ||
96 | static | |
60745f24 | 97 | _method_t &operator++ (_method_t &aMethod) |
985c86bc | 98 | { |
99 | int tmp = (int)aMethod; | |
60745f24 | 100 | aMethod = (_method_t)(++tmp); |
985c86bc | 101 | return aMethod; |
102 | } | |
103 | ||
104 | /* | |
105 | * Construct a HttpRequestMethod from a NULL terminated string such as "GET" | |
106 | * or from a range of chars, * such as "GET" from "GETFOOBARBAZ" | |
107 | * (pass in pointer to G and pointer to F.) | |
108 | */ | |
109 | HttpRequestMethod::HttpRequestMethod(char const *begin, char const *end) : theMethod (METHOD_NONE) | |
110 | { | |
111 | if (begin == NULL) | |
112 | return; | |
113 | ||
114 | /* | |
115 | * This check for '%' makes sure that we don't | |
116 | * match one of the extension method placeholders, | |
117 | * which have the form %EXT[0-9][0-9] | |
118 | */ | |
119 | ||
120 | if (*begin == '%') | |
121 | return; | |
122 | ||
123 | /* | |
124 | * if e is NULL, b must be NULL terminated and we | |
125 | * make e point to the first whitespace character | |
126 | * after b. | |
127 | */ | |
128 | if (NULL == end) | |
129 | end = begin + strcspn(begin, w_space); | |
60745f24 | 130 | |
131 | if (end == begin) { | |
132 | theMethod = METHOD_NONE; | |
133 | return; | |
134 | } | |
135 | ||
985c86bc | 136 | for (++theMethod; theMethod < METHOD_ENUM_END; ++theMethod) { |
60745f24 | 137 | if (0 == strncasecmp(begin, RequestMethodStr[theMethod], end-begin)) { |
985c86bc | 138 | return; |
60745f24 | 139 | } |
985c86bc | 140 | } |
141 | ||
60745f24 | 142 | // if method not found and method string is not null then it is other method |
143 | theMethod = METHOD_OTHER; | |
144 | theImage.limitInit(begin,end-begin); | |
985c86bc | 145 | } |
146 | ||
914b89a2 | 147 | /** \todo AYJ: this _should_ be obsolete. Since all such methods fit nicely into METHOD_OTHER now. */ |
985c86bc | 148 | void |
149 | HttpRequestMethod::AddExtension(const char *mstr) | |
150 | { | |
60745f24 | 151 | _method_t method = METHOD_NONE; |
985c86bc | 152 | |
153 | for (++method; method < METHOD_ENUM_END; ++method) { | |
154 | if (0 == strcmp(mstr, RequestMethodStr[method])) { | |
bf8fe701 | 155 | debugs(23, 2, "Extension method '" << mstr << "' already exists"); |
985c86bc | 156 | return; |
157 | } | |
158 | ||
159 | if (0 != strncmp("%EXT", RequestMethodStr[method], 4)) | |
160 | continue; | |
161 | ||
162 | /* Don't free statically allocated "%EXTnn" string */ | |
163 | RequestMethodStr[method] = xstrdup(mstr); | |
164 | ||
4a7a3d56 | 165 | debugs(23, 1, "Extension method '" << mstr << "' added, enum=" << method); |
985c86bc | 166 | |
167 | return; | |
168 | } | |
169 | ||
bf8fe701 | 170 | debugs(23, 1, "WARNING: Could not add new extension method '" << mstr << "' due to lack of array space"); |
985c86bc | 171 | } |
172 | ||
173 | void | |
174 | HttpRequestMethod::Configure(SquidConfig &Config) | |
175 | { | |
176 | wordlist *w = Config.ext_methods; | |
177 | ||
178 | while (w) { | |
179 | char *s; | |
180 | ||
181 | for (s = w->key; *s; s++) | |
182 | *s = xtoupper(*s); | |
183 | ||
184 | AddExtension(w->key); | |
185 | ||
186 | w = w->next; | |
187 | } | |
188 | } | |
60745f24 | 189 | |
190 | char const* | |
914b89a2 | 191 | HttpRequestMethod::image() const |
192 | { | |
193 | if (METHOD_OTHER != theMethod) { | |
194 | return RequestMethodStr[theMethod]; | |
195 | } | |
196 | else { | |
197 | if (theImage.size()>0) { | |
198 | return theImage.buf(); | |
199 | } else { | |
200 | return "METHOD_OTHER"; | |
201 | } | |
202 | } | |
60745f24 | 203 | } |
204 | ||
205 | bool | |
206 | HttpRequestMethod::isCacheble() const | |
207 | { | |
208 | if (theMethod == METHOD_CONNECT) | |
209 | return false; | |
210 | ||
211 | if (theMethod == METHOD_TRACE) | |
212 | return false; | |
213 | ||
214 | if (theMethod == METHOD_PUT) | |
215 | return false; | |
216 | ||
217 | if (theMethod == METHOD_POST) | |
218 | return false; | |
219 | ||
220 | if (theMethod == METHOD_OTHER) | |
221 | return false; | |
222 | ||
223 | return true; | |
224 | } |