]>
Commit | Line | Data |
---|---|---|
1da5651f | 1 | |
9cef6668 | 2 | /* |
9cef6668 | 3 | * DEBUG: section 76 Internal Squid Object handling |
4 | * AUTHOR: Duane, Alex, Henrik | |
5 | * | |
2b6662ba | 6 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
9cef6668 | 7 | * ---------------------------------------------------------- |
8 | * | |
2b6662ba | 9 | * Squid is the result of efforts by numerous individuals from |
10 | * the Internet community; see the CONTRIBUTORS file for full | |
11 | * details. Many organizations have provided support for Squid's | |
12 | * development; see the SPONSORS file for full details. Squid is | |
13 | * Copyrighted (C) 2001 by the Regents of the University of | |
14 | * California; see the COPYRIGHT file for full details. Squid | |
15 | * incorporates software developed and/or copyrighted by other | |
16 | * sources; see the CREDITS file for full details. | |
9cef6668 | 17 | * |
18 | * This program is free software; you can redistribute it and/or modify | |
19 | * it under the terms of the GNU General Public License as published by | |
20 | * the Free Software Foundation; either version 2 of the License, or | |
21 | * (at your option) any later version. | |
26ac0430 | 22 | * |
9cef6668 | 23 | * This program is distributed in the hope that it will be useful, |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 | * GNU General Public License for more details. | |
26ac0430 | 27 | * |
9cef6668 | 28 | * You should have received a copy of the GNU General Public License |
29 | * along with this program; if not, write to the Free Software | |
30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
31 | * | |
32 | */ | |
33 | ||
582c2af2 | 34 | #include "squid.h" |
e37bd29b AJ |
35 | #include "CacheManager.h" |
36 | #include "comm/Connection.h" | |
aa839030 | 37 | #include "errorpage.h" |
528b2c61 | 38 | #include "HttpReply.h" |
602d9612 A |
39 | #include "HttpRequest.h" |
40 | #include "icmp/net_db.h" | |
0eb49b6d | 41 | #include "MemBuf.h" |
4d5904f7 | 42 | #include "SquidConfig.h" |
985c86bc | 43 | #include "SquidTime.h" |
602d9612 | 44 | #include "Store.h" |
4e540555 | 45 | #include "tools.h" |
b1bd952a | 46 | #include "URL.h" |
d295d770 | 47 | #include "wordlist.h" |
1da5651f | 48 | |
a1f5c896 | 49 | /* called when we "miss" on an internal object; |
26ac0430 | 50 | * generate known dynamic objects, |
955394ce | 51 | * return Http::scNotFound for others |
a1f5c896 | 52 | */ |
1da5651f | 53 | void |
e37bd29b | 54 | internalStart(const Comm::ConnectionPointer &clientConn, HttpRequest * request, StoreEntry * entry) |
1da5651f | 55 | { |
865094d7 | 56 | ErrorState *err; |
b4f2886c | 57 | const char *upath = request->urlpath.termedBuf(); |
e37bd29b | 58 | debugs(76, 3, HERE << clientConn << " requesting '" << upath << "'"); |
62e76326 | 59 | |
1f38f50a | 60 | if (0 == strcmp(upath, "/squid-internal-dynamic/netdb")) { |
62e76326 | 61 | netdbBinaryExchange(entry); |
1f38f50a | 62 | } else if (0 == strcmp(upath, "/squid-internal-periodic/store_digest")) { |
63 | #if USE_CACHE_DIGESTS | |
62e76326 | 64 | const char *msgbuf = "This cache is currently building its digest.\n"; |
1f38f50a | 65 | #else |
62e76326 | 66 | |
9b5c4a9a | 67 | const char *msgbuf = "This cache does not support Cache Digests.\n"; |
1f38f50a | 68 | #endif |
62e76326 | 69 | |
06a5ae20 | 70 | HttpReply *reply = new HttpReply; |
955394ce | 71 | reply->setHeaders(Http::scNotFound, "Not Found", "text/plain", strlen(msgbuf), squid_curtime, -2); |
db237875 | 72 | entry->replaceHttpReply(reply); |
3900307b | 73 | entry->append(msgbuf, strlen(msgbuf)); |
62e76326 | 74 | entry->complete(); |
e37bd29b AJ |
75 | } else if (0 == strncmp(upath, "/squid-internal-mgr/", 20)) { |
76 | CacheManager::GetInstance()->Start(clientConn, request, entry); | |
1f38f50a | 77 | } else { |
62e76326 | 78 | debugObj(76, 1, "internalStart: unknown request:\n", |
79 | request, (ObjPackMethod) & httpRequestPack); | |
955394ce | 80 | err = new ErrorState(ERR_INVALID_REQ, Http::scNotFound, request); |
62e76326 | 81 | errorAppendEntry(entry, err); |
865094d7 | 82 | } |
1da5651f | 83 | } |
84 | ||
85 | int | |
86 | internalCheck(const char *urlpath) | |
87 | { | |
5999b776 | 88 | return (0 == strncmp(urlpath, "/squid-internal-", 16)); |
1da5651f | 89 | } |
90 | ||
ba26bca4 | 91 | int |
92 | internalStaticCheck(const char *urlpath) | |
93 | { | |
5999b776 | 94 | return (0 == strncmp(urlpath, "/squid-internal-static", 22)); |
ba26bca4 | 95 | } |
96 | ||
1da5651f | 97 | /* |
98 | * makes internal url with a given host and port (remote internal url) | |
99 | */ | |
100 | char * | |
f45dd259 | 101 | internalRemoteUri(const char *host, unsigned short port, const char *dir, const char *name) |
1da5651f | 102 | { |
1da5651f | 103 | static char lc_host[SQUIDHOSTNAMELEN]; |
52f772de | 104 | assert(host && name); |
137ee196 | 105 | /* convert host name to lower case */ |
c8918a58 | 106 | xstrncpy(lc_host, host, SQUIDHOSTNAMELEN); |
1da5651f | 107 | Tolower(lc_host); |
cc192b50 | 108 | |
cc192b50 | 109 | /* check for an IP address and format appropriately if found */ |
b7ac5457 | 110 | Ip::Address test = lc_host; |
4dd643d5 AJ |
111 | if ( !test.isAnyAddr() ) { |
112 | test.toHostStr(lc_host,SQUIDHOSTNAMELEN); | |
cc192b50 | 113 | } |
cc192b50 | 114 | |
1224d740 | 115 | /* |
116 | * append the domain in order to mirror the requests with appended | |
117 | * domains | |
118 | */ | |
62e76326 | 119 | |
055421ee | 120 | /* For IPv6 addresses also check for a colon */ |
532e5dd4 | 121 | if (Config.appendDomain && !strchr(lc_host, '.') && !strchr(lc_host, ':')) |
62e76326 | 122 | strncat(lc_host, Config.appendDomain, SQUIDHOSTNAMELEN - |
123 | strlen(lc_host) - 1); | |
124 | ||
137ee196 | 125 | /* build uri in mb */ |
032785bf | 126 | static MemBuf mb; |
127 | ||
2fe7eff9 | 128 | mb.reset(); |
62e76326 | 129 | |
2fe7eff9 | 130 | mb.Printf("http://%s", lc_host); |
62e76326 | 131 | |
137ee196 | 132 | /* append port if not default */ |
0c3d3f65 | 133 | if (port && port != urlDefaultPort(AnyP::PROTO_HTTP)) |
2fe7eff9 | 134 | mb.Printf(":%d", port); |
62e76326 | 135 | |
1da5651f | 136 | if (dir) |
2fe7eff9 | 137 | mb.Printf("%s", dir); |
62e76326 | 138 | |
2fe7eff9 | 139 | mb.Printf("%s", name); |
62e76326 | 140 | |
137ee196 | 141 | /* return a pointer to a local static buffer */ |
142 | return mb.buf; | |
1da5651f | 143 | } |
144 | ||
145 | /* | |
146 | * makes internal url with local host and port | |
147 | */ | |
148 | char * | |
149 | internalLocalUri(const char *dir, const char *name) | |
150 | { | |
7e3ce7b9 | 151 | return internalRemoteUri(getMyHostname(), |
62e76326 | 152 | getMyPort(), dir, name); |
1da5651f | 153 | } |
c68e9c6b | 154 | |
155 | const char * | |
156 | internalHostname(void) | |
157 | { | |
158 | LOCAL_ARRAY(char, host, SQUIDHOSTNAMELEN + 1); | |
159 | xstrncpy(host, getMyHostname(), SQUIDHOSTNAMELEN); | |
b3ef8c0d | 160 | |
055421ee | 161 | /* For IPv6 addresses also check for a colon */ |
532e5dd4 | 162 | if (Config.appendDomain && !strchr(host, '.') && !strchr(host, ':')) |
b3ef8c0d | 163 | strncat(host, Config.appendDomain, SQUIDHOSTNAMELEN - |
164 | strlen(host) - 1); | |
165 | ||
c68e9c6b | 166 | Tolower(host); |
b3ef8c0d | 167 | |
c68e9c6b | 168 | return host; |
169 | } | |
1f38f50a | 170 | |
171 | int | |
172 | internalHostnameIs(const char *arg) | |
173 | { | |
174 | wordlist *w; | |
62e76326 | 175 | |
1f38f50a | 176 | if (0 == strcmp(arg, internalHostname())) |
62e76326 | 177 | return 1; |
178 | ||
1f38f50a | 179 | for (w = Config.hostnameAliases; w; w = w->next) |
62e76326 | 180 | if (0 == strcmp(arg, w->key)) |
181 | return 1; | |
182 | ||
1f38f50a | 183 | return 0; |
184 | } |