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