]> git.ipfire.org Git - thirdparty/squid.git/blame - src/internal.cc
On some Unix OS include may be in /usr/local/include.
[thirdparty/squid.git] / src / internal.cc
CommitLineData
1da5651f 1
9cef6668 2/*
c8918a58 3 * $Id: internal.cc,v 1.38 2006/04/23 09:02:13 serassio Exp $
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.
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
1da5651f 36#include "squid.h"
e6ccf245 37#include "Store.h"
528b2c61 38#include "HttpRequest.h"
39#include "HttpReply.h"
0eb49b6d 40#include "MemBuf.h"
1da5651f 41
a1f5c896 42/* called when we "miss" on an internal object;
43 * generate known dynamic objects,
44 * return HTTP_NOT_FOUND for others
45 */
1da5651f 46void
190154cf 47internalStart(HttpRequest * request, StoreEntry * entry)
1da5651f 48{
865094d7 49 ErrorState *err;
528b2c61 50 const char *upath = request->urlpath.buf();
fd9f2966 51 debug(76, 3) ("internalStart: %s requesting '%s'\n",
62e76326 52 inet_ntoa(request->client_addr), upath);
53
1f38f50a 54 if (0 == strcmp(upath, "/squid-internal-dynamic/netdb")) {
62e76326 55 netdbBinaryExchange(entry);
1f38f50a 56 } else if (0 == strcmp(upath, "/squid-internal-periodic/store_digest")) {
57#if USE_CACHE_DIGESTS
62e76326 58 const char *msgbuf = "This cache is currently building its digest.\n";
1f38f50a 59#else
62e76326 60
61 const char *msgbuf = "This cache does not suport Cache Digests.\n";
1f38f50a 62#endif
62e76326 63
450e0c10 64 HttpVersion version(1, 0);
06a5ae20 65 HttpReply *reply = new HttpReply;
66 reply->setHeaders(version,
67 HTTP_NOT_FOUND,
68 "Not Found",
69 "text/plain",
70 strlen(msgbuf),
71 squid_curtime,
72 -2);
db237875 73 entry->replaceHttpReply(reply);
62e76326 74 storeAppend(entry, msgbuf, strlen(msgbuf));
75 entry->complete();
1f38f50a 76 } else {
62e76326 77 debugObj(76, 1, "internalStart: unknown request:\n",
78 request, (ObjPackMethod) & httpRequestPack);
79 err = errorCon(ERR_INVALID_REQ, HTTP_NOT_FOUND);
6dd9f4bd 80 err->request = HTTPMSGLOCK(request);
62e76326 81 errorAppendEntry(entry, err);
865094d7 82 }
1da5651f 83}
84
85int
86internalCheck(const char *urlpath)
87{
5999b776 88 return (0 == strncmp(urlpath, "/squid-internal-", 16));
1da5651f 89}
90
ba26bca4 91int
92internalStaticCheck(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 */
100char *
101internalRemoteUri(const char *host, u_short port, const char *dir, const char *name)
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);
1224d740 108 /*
109 * append the domain in order to mirror the requests with appended
110 * domains
111 */
62e76326 112
1224d740 113 if (Config.appendDomain && !strchr(lc_host, '.'))
62e76326 114 strncat(lc_host, Config.appendDomain, SQUIDHOSTNAMELEN -
115 strlen(lc_host) - 1);
116
137ee196 117 /* build uri in mb */
032785bf 118 static MemBuf mb;
119
2fe7eff9 120 mb.reset();
62e76326 121
2fe7eff9 122 mb.Printf("http://%s", lc_host);
62e76326 123
137ee196 124 /* append port if not default */
52f772de 125 if (port && port != urlDefaultPort(PROTO_HTTP))
2fe7eff9 126 mb.Printf(":%d", port);
62e76326 127
1da5651f 128 if (dir)
2fe7eff9 129 mb.Printf("%s", dir);
62e76326 130
2fe7eff9 131 mb.Printf("%s", name);
62e76326 132
137ee196 133 /* return a pointer to a local static buffer */
134 return mb.buf;
1da5651f 135}
136
137/*
138 * makes internal url with local host and port
139 */
140char *
141internalLocalUri(const char *dir, const char *name)
142{
7e3ce7b9 143 return internalRemoteUri(getMyHostname(),
62e76326 144 getMyPort(), dir, name);
1da5651f 145}
c68e9c6b 146
147const char *
148internalHostname(void)
149{
150 LOCAL_ARRAY(char, host, SQUIDHOSTNAMELEN + 1);
151 xstrncpy(host, getMyHostname(), SQUIDHOSTNAMELEN);
152 Tolower(host);
153 return host;
154}
1f38f50a 155
156int
157internalHostnameIs(const char *arg)
158{
159 wordlist *w;
62e76326 160
1f38f50a 161 if (0 == strcmp(arg, internalHostname()))
62e76326 162 return 1;
163
1f38f50a 164 for (w = Config.hostnameAliases; w; w = w->next)
62e76326 165 if (0 == strcmp(arg, w->key))
166 return 1;
167
1f38f50a 168 return 0;
169}