]> git.ipfire.org Git - thirdparty/squid.git/blame - src/internal.cc
2.1 branch merge
[thirdparty/squid.git] / src / internal.cc
CommitLineData
1da5651f 1
9cef6668 2/*
c68e9c6b 3 * $Id: internal.cc,v 1.15 1998/11/12 06:28:11 wessels Exp $
9cef6668 4 *
5 * DEBUG: section 76 Internal Squid Object handling
6 * AUTHOR: Duane, Alex, Henrik
7 *
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by the
14 * National Science Foundation. Squid is Copyrighted (C) 1998 by
15 * Duane Wessels and the University of California San Diego. Please
16 * see the COPYRIGHT file for full details. Squid incorporates
17 * software developed and/or copyrighted by other sources. Please see
18 * 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
1da5651f 36#include "squid.h"
37
a1f5c896 38/* called when we "miss" on an internal object;
39 * generate known dynamic objects,
40 * return HTTP_NOT_FOUND for others
41 */
1da5651f 42void
43internalStart(request_t * request, StoreEntry * entry)
44{
865094d7 45 ErrorState *err;
1da5651f 46 const char *upath = strBuf(request->urlpath);
fd9f2966 47 debug(76, 3) ("internalStart: %s requesting '%s'\n",
5999b776 48 inet_ntoa(request->client_addr), upath);
1da5651f 49 if (0 == strcmp(upath, "/squid-internal-dynamic/netdb"))
50 netdbBinaryExchange(entry);
865094d7 51 else {
9cef6668 52 debugObj(76, 1, "internalStart: unknown request:\n", request, (ObjPackMethod) & httpRequestPack);
865094d7 53 err = errorCon(ERR_INVALID_REQ, HTTP_NOT_FOUND);
54 err->request = requestLink(request);
55 errorAppendEntry(entry, err);
56 }
1da5651f 57}
58
59int
60internalCheck(const char *urlpath)
61{
5999b776 62 return (0 == strncmp(urlpath, "/squid-internal-", 16));
1da5651f 63}
64
ba26bca4 65int
66internalStaticCheck(const char *urlpath)
67{
5999b776 68 return (0 == strncmp(urlpath, "/squid-internal-static", 22));
ba26bca4 69}
70
1da5651f 71/*
72 * makes internal url with a given host and port (remote internal url)
73 */
74char *
75internalRemoteUri(const char *host, u_short port, const char *dir, const char *name)
76{
137ee196 77 static MemBuf mb = MemBufNULL;
1da5651f 78 static char lc_host[SQUIDHOSTNAMELEN];
79 assert(host && port && name);
137ee196 80 /* convert host name to lower case */
81 xstrncpy(lc_host, host, sizeof(lc_host));
1da5651f 82 Tolower(lc_host);
137ee196 83 /* build uri in mb */
84 memBufReset(&mb);
85 memBufPrintf(&mb, "http://%s", lc_host);
86 /* append port if not default */
1da5651f 87 if (port != urlDefaultPort(PROTO_HTTP))
137ee196 88 memBufPrintf(&mb, ":%d", port);
1da5651f 89 if (dir)
137ee196 90 memBufPrintf(&mb, "%s", dir);
91 memBufPrintf(&mb, "%s", name);
92 /* return a pointer to a local static buffer */
93 return mb.buf;
1da5651f 94}
95
96/*
97 * makes internal url with local host and port
98 */
99char *
100internalLocalUri(const char *dir, const char *name)
101{
102 return internalRemoteUri(getMyHostname(), Config.Port.http->i, dir, name);
103}
c68e9c6b 104
105const char *
106internalHostname(void)
107{
108 LOCAL_ARRAY(char, host, SQUIDHOSTNAMELEN + 1);
109 xstrncpy(host, getMyHostname(), SQUIDHOSTNAMELEN);
110 Tolower(host);
111 return host;
112}