]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/internal.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 76 Internal Squid Object handling */
12 #include "CacheManager.h"
13 #include "comm/Connection.h"
14 #include "errorpage.h"
15 #include "HttpReply.h"
16 #include "HttpRequest.h"
17 #include "icmp/net_db.h"
19 #include "SquidConfig.h"
20 #include "SquidTime.h"
27 /* called when we "miss" on an internal object;
28 * generate known dynamic objects,
29 * return Http::scNotFound for others
32 internalStart(const Comm::ConnectionPointer
&clientConn
, HttpRequest
* request
, StoreEntry
* entry
)
35 const SBuf upath
= request
->url
.path();
36 debugs(76, 3, clientConn
<< " requesting '" << upath
<< "'");
38 static const SBuf
netdbUri("/squid-internal-dynamic/netdb");
39 static const SBuf
storeDigestUri("/squid-internal-periodic/store_digest");
40 static const SBuf
mgrPfx("/squid-internal-mgr/");
42 if (upath
== netdbUri
) {
43 netdbBinaryExchange(entry
);
44 } else if (upath
== storeDigestUri
) {
46 const char *msgbuf
= "This cache is currently building its digest.\n";
49 const char *msgbuf
= "This cache does not support Cache Digests.\n";
52 HttpReply
*reply
= new HttpReply
;
53 reply
->setHeaders(Http::scNotFound
, "Not Found", "text/plain", strlen(msgbuf
), squid_curtime
, -2);
54 entry
->replaceHttpReply(reply
);
55 entry
->append(msgbuf
, strlen(msgbuf
));
57 } else if (upath
.startsWith(mgrPfx
)) {
58 debugs(17, 2, "calling CacheManager due to URL-path " << mgrPfx
);
59 CacheManager::GetInstance()->Start(clientConn
, request
, entry
);
61 debugObj(76, 1, "internalStart: unknown request:\n",
62 request
, (ObjPackMethod
) & httpRequestPack
);
63 err
= new ErrorState(ERR_INVALID_REQ
, Http::scNotFound
, request
);
64 errorAppendEntry(entry
, err
);
69 internalCheck(const SBuf
&urlPath
)
71 static const SBuf
InternalPfx("/squid-internal-");
72 return urlPath
.startsWith(InternalPfx
);
76 internalStaticCheck(const SBuf
&urlPath
)
78 static const SBuf
InternalStaticPfx("/squid-internal-static");
79 return urlPath
.startsWith(InternalStaticPfx
);
83 * makes internal url with a given host and port (remote internal url)
86 internalRemoteUri(const char *host
, unsigned short port
, const char *dir
, const SBuf
&name
)
88 static char lc_host
[SQUIDHOSTNAMELEN
];
89 assert(host
&& !name
.isEmpty());
90 /* convert host name to lower case */
91 xstrncpy(lc_host
, host
, SQUIDHOSTNAMELEN
);
94 /* check for an IP address and format appropriately if found */
95 Ip::Address test
= lc_host
;
96 if ( !test
.isAnyAddr() ) {
97 test
.toHostStr(lc_host
,SQUIDHOSTNAMELEN
);
101 * append the domain in order to mirror the requests with appended
105 /* For IPv6 addresses also check for a colon */
106 if (Config
.appendDomain
&& !strchr(lc_host
, '.') && !strchr(lc_host
, ':'))
107 strncat(lc_host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
108 strlen(lc_host
) - 1);
111 URL
tmp(AnyP::PROTO_HTTP
);
119 mb
.appendf("http://" SQUIDSBUFPH
, SQUIDSBUFPRINT(tmp
.authority()));
122 mb
.append(dir
, strlen(dir
));
124 mb
.append(name
.rawContent(), name
.length());
126 /* return a pointer to a local static buffer */
131 * makes internal url with local host and port
134 internalLocalUri(const char *dir
, const SBuf
&name
)
136 return internalRemoteUri(getMyHostname(),
137 getMyPort(), dir
, name
);
141 internalHostname(void)
143 LOCAL_ARRAY(char, host
, SQUIDHOSTNAMELEN
+ 1);
144 xstrncpy(host
, getMyHostname(), SQUIDHOSTNAMELEN
);
146 /* For IPv6 addresses also check for a colon */
147 if (Config
.appendDomain
&& !strchr(host
, '.') && !strchr(host
, ':'))
148 strncat(host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
157 internalHostnameIs(const char *arg
)
161 if (0 == strcmp(arg
, internalHostname()))
164 for (w
= Config
.hostnameAliases
; w
; w
= w
->next
)
165 if (0 == strcmp(arg
, w
->key
))