]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/internal.cc
5 * DEBUG: section 76 Internal Squid Object handling
6 * AUTHOR: Duane, Alex, Henrik
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
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.
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.
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.
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.
37 #include "errorpage.h"
39 #include "HttpRequest.h"
40 #include "HttpReply.h"
42 #include "SquidTime.h"
44 #include "icmp/net_db.h"
46 /* called when we "miss" on an internal object;
47 * generate known dynamic objects,
48 * return HTTP_NOT_FOUND for others
51 internalStart(HttpRequest
* request
, StoreEntry
* entry
)
54 const char *upath
= request
->urlpath
.termedBuf();
55 debugs(76, 3, "internalStart: " << request
->client_addr
<< " requesting '" << upath
<< "'");
57 if (0 == strcmp(upath
, "/squid-internal-dynamic/netdb")) {
58 netdbBinaryExchange(entry
);
59 } else if (0 == strcmp(upath
, "/squid-internal-periodic/store_digest")) {
61 const char *msgbuf
= "This cache is currently building its digest.\n";
64 const char *msgbuf
= "This cache does not support Cache Digests.\n";
67 HttpReply
*reply
= new HttpReply
;
68 reply
->setHeaders(HTTP_NOT_FOUND
, "Not Found", "text/plain", strlen(msgbuf
), squid_curtime
, -2);
69 entry
->replaceHttpReply(reply
);
70 entry
->append(msgbuf
, strlen(msgbuf
));
73 debugObj(76, 1, "internalStart: unknown request:\n",
74 request
, (ObjPackMethod
) & httpRequestPack
);
75 err
= errorCon(ERR_INVALID_REQ
, HTTP_NOT_FOUND
, request
);
76 errorAppendEntry(entry
, err
);
81 internalCheck(const char *urlpath
)
83 return (0 == strncmp(urlpath
, "/squid-internal-", 16));
87 internalStaticCheck(const char *urlpath
)
89 return (0 == strncmp(urlpath
, "/squid-internal-static", 22));
93 * makes internal url with a given host and port (remote internal url)
96 internalRemoteUri(const char *host
, u_short port
, const char *dir
, const char *name
)
98 static char lc_host
[SQUIDHOSTNAMELEN
];
100 /* convert host name to lower case */
101 xstrncpy(lc_host
, host
, SQUIDHOSTNAMELEN
);
104 /* check for an IP address and format appropriately if found */
105 Ip::Address test
= lc_host
;
106 if ( !test
.IsAnyAddr() ) {
107 test
.ToHostname(lc_host
,SQUIDHOSTNAMELEN
);
111 * append the domain in order to mirror the requests with appended
115 /* For IPv6 addresses also check for a colon */
116 if (Config
.appendDomain
&& !strchr(lc_host
, '.') && !strchr(lc_host
, ':'))
117 strncat(lc_host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
118 strlen(lc_host
) - 1);
120 /* build uri in mb */
125 mb
.Printf("http://%s", lc_host
);
127 /* append port if not default */
128 if (port
&& port
!= urlDefaultPort(AnyP::PROTO_HTTP
))
129 mb
.Printf(":%d", port
);
132 mb
.Printf("%s", dir
);
134 mb
.Printf("%s", name
);
136 /* return a pointer to a local static buffer */
141 * makes internal url with local host and port
144 internalLocalUri(const char *dir
, const char *name
)
146 return internalRemoteUri(getMyHostname(),
147 getMyPort(), dir
, name
);
151 internalHostname(void)
153 LOCAL_ARRAY(char, host
, SQUIDHOSTNAMELEN
+ 1);
154 xstrncpy(host
, getMyHostname(), SQUIDHOSTNAMELEN
);
156 /* For IPv6 addresses also check for a colon */
157 if (Config
.appendDomain
&& !strchr(host
, '.') && !strchr(host
, ':'))
158 strncat(host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
167 internalHostnameIs(const char *arg
)
171 if (0 == strcmp(arg
, internalHostname()))
174 for (w
= Config
.hostnameAliases
; w
; w
= w
->next
)
175 if (0 == strcmp(arg
, w
->key
))