]> git.ipfire.org Git - thirdparty/squid.git/blob - src/internal.cc
Summary: Final MSVC fixups.
[thirdparty/squid.git] / src / internal.cc
1
2 /*
3 * $Id: internal.cc,v 1.29 2003/08/10 11:00:43 robertc Exp $
4 *
5 * DEBUG: section 76 Internal Squid Object handling
6 * AUTHOR: Duane, Alex, Henrik
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 */
35
36 #include "squid.h"
37 #include "Store.h"
38 #include "HttpRequest.h"
39 #include "HttpReply.h"
40
41 /* called when we "miss" on an internal object;
42 * generate known dynamic objects,
43 * return HTTP_NOT_FOUND for others
44 */
45 void
46 internalStart(HttpRequest * request, StoreEntry * entry)
47 {
48 ErrorState *err;
49 const char *upath = request->urlpath.buf();
50 http_version_t version;
51 debug(76, 3) ("internalStart: %s requesting '%s'\n",
52 inet_ntoa(request->client_addr), upath);
53
54 if (0 == strcmp(upath, "/squid-internal-dynamic/netdb")) {
55 netdbBinaryExchange(entry);
56 } else if (0 == strcmp(upath, "/squid-internal-periodic/store_digest")) {
57 #if USE_CACHE_DIGESTS
58 const char *msgbuf = "This cache is currently building its digest.\n";
59 #else
60
61 const char *msgbuf = "This cache does not suport Cache Digests.\n";
62 #endif
63
64 httpBuildVersion(&version, 1, 0);
65 HttpReply *reply = httpReplyCreate ();
66 httpReplySetHeaders(reply,
67 version,
68 HTTP_NOT_FOUND,
69 "Not Found",
70 "text/plain",
71 strlen(msgbuf),
72 squid_curtime,
73 -2);
74 httpReplySwapOut(reply, entry);
75 storeAppend(entry, msgbuf, strlen(msgbuf));
76 entry->complete();
77 } else {
78 debugObj(76, 1, "internalStart: unknown request:\n",
79 request, (ObjPackMethod) & httpRequestPack);
80 err = errorCon(ERR_INVALID_REQ, HTTP_NOT_FOUND);
81 err->request = requestLink(request);
82 errorAppendEntry(entry, err);
83 }
84 }
85
86 int
87 internalCheck(const char *urlpath)
88 {
89 return (0 == strncmp(urlpath, "/squid-internal-", 16));
90 }
91
92 int
93 internalStaticCheck(const char *urlpath)
94 {
95 return (0 == strncmp(urlpath, "/squid-internal-static", 22));
96 }
97
98 /*
99 * makes internal url with a given host and port (remote internal url)
100 */
101 char *
102 internalRemoteUri(const char *host, u_short port, const char *dir, const char *name)
103 {
104 static MemBuf mb = MemBufNULL;
105 static char lc_host[SQUIDHOSTNAMELEN];
106 assert(host && name);
107 /* convert host name to lower case */
108 xstrncpy(lc_host, host, SQUIDHOSTNAMELEN - 1);
109 Tolower(lc_host);
110 /*
111 * append the domain in order to mirror the requests with appended
112 * domains
113 */
114
115 if (Config.appendDomain && !strchr(lc_host, '.'))
116 strncat(lc_host, Config.appendDomain, SQUIDHOSTNAMELEN -
117 strlen(lc_host) - 1);
118
119 /* build uri in mb */
120 memBufReset(&mb);
121
122 memBufPrintf(&mb, "http://%s", lc_host);
123
124 /* append port if not default */
125 if (port && port != urlDefaultPort(PROTO_HTTP))
126 memBufPrintf(&mb, ":%d", port);
127
128 if (dir)
129 memBufPrintf(&mb, "%s", dir);
130
131 memBufPrintf(&mb, "%s", name);
132
133 /* return a pointer to a local static buffer */
134 return mb.buf;
135 }
136
137 /*
138 * makes internal url with local host and port
139 */
140 char *
141 internalLocalUri(const char *dir, const char *name)
142 {
143 return internalRemoteUri(getMyHostname(),
144 getMyPort(), dir, name);
145 }
146
147 const char *
148 internalHostname(void)
149 {
150 LOCAL_ARRAY(char, host, SQUIDHOSTNAMELEN + 1);
151 xstrncpy(host, getMyHostname(), SQUIDHOSTNAMELEN);
152 Tolower(host);
153 return host;
154 }
155
156 int
157 internalHostnameIs(const char *arg)
158 {
159 wordlist *w;
160
161 if (0 == strcmp(arg, internalHostname()))
162 return 1;
163
164 for (w = Config.hostnameAliases; w; w = w->next)
165 if (0 == strcmp(arg, w->key))
166 return 1;
167
168 return 0;
169 }