]>
Commit | Line | Data |
---|---|---|
1da5651f | 1 | |
9cef6668 | 2 | /* |
262a0e14 | 3 | * $Id$ |
9cef6668 | 4 | * |
5 | * DEBUG: section 76 Internal Squid Object handling | |
6 | * AUTHOR: Duane, Alex, Henrik | |
7 | * | |
2b6662ba | 8 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
9cef6668 | 9 | * ---------------------------------------------------------- |
10 | * | |
2b6662ba | 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. | |
9cef6668 | 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. | |
26ac0430 | 24 | * |
9cef6668 | 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. | |
26ac0430 | 29 | * |
9cef6668 | 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 | */ | |
35 | ||
1da5651f | 36 | #include "squid.h" |
aa839030 | 37 | #include "errorpage.h" |
e6ccf245 | 38 | #include "Store.h" |
528b2c61 | 39 | #include "HttpRequest.h" |
40 | #include "HttpReply.h" | |
0eb49b6d | 41 | #include "MemBuf.h" |
985c86bc | 42 | #include "SquidTime.h" |
d295d770 | 43 | #include "wordlist.h" |
9b5c4a9a | 44 | #include "icmp/net_db.h" |
1da5651f | 45 | |
a1f5c896 | 46 | /* called when we "miss" on an internal object; |
26ac0430 | 47 | * generate known dynamic objects, |
a1f5c896 | 48 | * return HTTP_NOT_FOUND for others |
49 | */ | |
1da5651f | 50 | void |
190154cf | 51 | internalStart(HttpRequest * request, StoreEntry * entry) |
1da5651f | 52 | { |
865094d7 | 53 | ErrorState *err; |
b4f2886c | 54 | const char *upath = request->urlpath.termedBuf(); |
cc192b50 | 55 | debugs(76, 3, "internalStart: " << request->client_addr << " requesting '" << upath << "'"); |
62e76326 | 56 | |
1f38f50a | 57 | if (0 == strcmp(upath, "/squid-internal-dynamic/netdb")) { |
62e76326 | 58 | netdbBinaryExchange(entry); |
1f38f50a | 59 | } else if (0 == strcmp(upath, "/squid-internal-periodic/store_digest")) { |
60 | #if USE_CACHE_DIGESTS | |
62e76326 | 61 | const char *msgbuf = "This cache is currently building its digest.\n"; |
1f38f50a | 62 | #else |
62e76326 | 63 | |
9b5c4a9a | 64 | const char *msgbuf = "This cache does not support Cache Digests.\n"; |
1f38f50a | 65 | #endif |
62e76326 | 66 | |
06a5ae20 | 67 | HttpReply *reply = new HttpReply; |
11992b6f | 68 | reply->setHeaders(HTTP_NOT_FOUND, "Not Found", "text/plain", strlen(msgbuf), squid_curtime, -2); |
db237875 | 69 | entry->replaceHttpReply(reply); |
3900307b | 70 | entry->append(msgbuf, strlen(msgbuf)); |
62e76326 | 71 | entry->complete(); |
1f38f50a | 72 | } else { |
62e76326 | 73 | debugObj(76, 1, "internalStart: unknown request:\n", |
74 | request, (ObjPackMethod) & httpRequestPack); | |
2cc81f1f | 75 | err = errorCon(ERR_INVALID_REQ, HTTP_NOT_FOUND, request); |
62e76326 | 76 | errorAppendEntry(entry, err); |
865094d7 | 77 | } |
1da5651f | 78 | } |
79 | ||
80 | int | |
81 | internalCheck(const char *urlpath) | |
82 | { | |
5999b776 | 83 | return (0 == strncmp(urlpath, "/squid-internal-", 16)); |
1da5651f | 84 | } |
85 | ||
ba26bca4 | 86 | int |
87 | internalStaticCheck(const char *urlpath) | |
88 | { | |
5999b776 | 89 | return (0 == strncmp(urlpath, "/squid-internal-static", 22)); |
ba26bca4 | 90 | } |
91 | ||
1da5651f | 92 | /* |
93 | * makes internal url with a given host and port (remote internal url) | |
94 | */ | |
95 | char * | |
96 | internalRemoteUri(const char *host, u_short port, const char *dir, const char *name) | |
97 | { | |
1da5651f | 98 | static char lc_host[SQUIDHOSTNAMELEN]; |
52f772de | 99 | assert(host && name); |
137ee196 | 100 | /* convert host name to lower case */ |
c8918a58 | 101 | xstrncpy(lc_host, host, SQUIDHOSTNAMELEN); |
1da5651f | 102 | Tolower(lc_host); |
cc192b50 | 103 | |
104 | #if USE_IPV6 | |
105 | /* check for an IP address and format appropriately if found */ | |
b7ac5457 | 106 | Ip::Address test = lc_host; |
cc192b50 | 107 | if ( !test.IsAnyAddr() ) { |
108 | test.ToHostname(lc_host,SQUIDHOSTNAMELEN); | |
109 | } | |
110 | #endif | |
111 | ||
1224d740 | 112 | /* |
113 | * append the domain in order to mirror the requests with appended | |
114 | * domains | |
115 | */ | |
62e76326 | 116 | |
532e5dd4 AJ |
117 | #if USE_IPV6 |
118 | /* For IPV6 addresses also check for a colon */ | |
119 | if (Config.appendDomain && !strchr(lc_host, '.') && !strchr(lc_host, ':')) | |
120 | #else | |
1224d740 | 121 | if (Config.appendDomain && !strchr(lc_host, '.')) |
532e5dd4 | 122 | #endif |
62e76326 | 123 | strncat(lc_host, Config.appendDomain, SQUIDHOSTNAMELEN - |
124 | strlen(lc_host) - 1); | |
125 | ||
137ee196 | 126 | /* build uri in mb */ |
032785bf | 127 | static MemBuf mb; |
128 | ||
2fe7eff9 | 129 | mb.reset(); |
62e76326 | 130 | |
2fe7eff9 | 131 | mb.Printf("http://%s", lc_host); |
62e76326 | 132 | |
137ee196 | 133 | /* append port if not default */ |
52f772de | 134 | if (port && port != urlDefaultPort(PROTO_HTTP)) |
2fe7eff9 | 135 | mb.Printf(":%d", port); |
62e76326 | 136 | |
1da5651f | 137 | if (dir) |
2fe7eff9 | 138 | mb.Printf("%s", dir); |
62e76326 | 139 | |
2fe7eff9 | 140 | mb.Printf("%s", name); |
62e76326 | 141 | |
137ee196 | 142 | /* return a pointer to a local static buffer */ |
143 | return mb.buf; | |
1da5651f | 144 | } |
145 | ||
146 | /* | |
147 | * makes internal url with local host and port | |
148 | */ | |
149 | char * | |
150 | internalLocalUri(const char *dir, const char *name) | |
151 | { | |
7e3ce7b9 | 152 | return internalRemoteUri(getMyHostname(), |
62e76326 | 153 | getMyPort(), dir, name); |
1da5651f | 154 | } |
c68e9c6b | 155 | |
156 | const char * | |
157 | internalHostname(void) | |
158 | { | |
159 | LOCAL_ARRAY(char, host, SQUIDHOSTNAMELEN + 1); | |
160 | xstrncpy(host, getMyHostname(), SQUIDHOSTNAMELEN); | |
b3ef8c0d | 161 | |
532e5dd4 AJ |
162 | #if USE_IPV6 |
163 | /* For IPV6 addresses also check for a colon */ | |
164 | if (Config.appendDomain && !strchr(host, '.') && !strchr(host, ':')) | |
165 | #else | |
b3ef8c0d | 166 | if (Config.appendDomain && !strchr(host, '.')) |
532e5dd4 | 167 | #endif |
b3ef8c0d | 168 | strncat(host, Config.appendDomain, SQUIDHOSTNAMELEN - |
169 | strlen(host) - 1); | |
170 | ||
c68e9c6b | 171 | Tolower(host); |
b3ef8c0d | 172 | |
c68e9c6b | 173 | return host; |
174 | } | |
1f38f50a | 175 | |
176 | int | |
177 | internalHostnameIs(const char *arg) | |
178 | { | |
179 | wordlist *w; | |
62e76326 | 180 | |
1f38f50a | 181 | if (0 == strcmp(arg, internalHostname())) |
62e76326 | 182 | return 1; |
183 | ||
1f38f50a | 184 | for (w = Config.hostnameAliases; w; w = w->next) |
62e76326 | 185 | if (0 == strcmp(arg, w->key)) |
186 | return 1; | |
187 | ||
1f38f50a | 188 | return 0; |
189 | } |