]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/internal.cc
2 * Copyright (C) 1996-2023 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 "AccessLogEntry.h"
13 #include "base/Assure.h"
14 #include "CacheManager.h"
15 #include "comm/Connection.h"
16 #include "errorpage.h"
17 #include "HttpReply.h"
18 #include "HttpRequest.h"
19 #include "icmp/net_db.h"
22 #include "SquidConfig.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
, const AccessLogEntry::Pointer
&ale
)
37 const SBuf upath
= request
->url
.path();
38 debugs(76, 3, clientConn
<< " requesting '" << upath
<< "'");
40 Assure(request
->flags
.internal
);
42 static const SBuf
netdbUri("/squid-internal-dynamic/netdb");
43 static const SBuf
storeDigestUri("/squid-internal-periodic/store_digest");
45 if (upath
== netdbUri
) {
46 netdbBinaryExchange(entry
);
47 } else if (upath
== storeDigestUri
) {
49 const char *msgbuf
= "This cache is currently building its digest.\n";
52 const char *msgbuf
= "This cache does not support Cache Digests.\n";
55 HttpReply
*reply
= new HttpReply
;
56 reply
->setHeaders(Http::scNotFound
, "Not Found", "text/plain", strlen(msgbuf
), squid_curtime
, -2);
57 entry
->replaceHttpReply(reply
);
58 entry
->append(msgbuf
, strlen(msgbuf
));
60 } else if (ForSomeCacheManager(upath
)) {
61 debugs(17, 2, "calling CacheManager due to URL-path");
62 CacheManager::GetInstance()->start(clientConn
, request
, entry
, ale
);
64 debugObj(76, 1, "internalStart: unknown request:\n",
65 request
, (ObjPackMethod
) & httpRequestPack
);
66 err
= new ErrorState(ERR_INVALID_REQ
, Http::scNotFound
, request
, ale
);
67 errorAppendEntry(entry
, err
);
72 internalCheck(const SBuf
&urlPath
)
74 static const SBuf
InternalPfx("/squid-internal-");
75 return urlPath
.startsWith(InternalPfx
);
79 internalStaticCheck(const SBuf
&urlPath
)
81 static const SBuf
InternalStaticPfx("/squid-internal-static");
82 return urlPath
.startsWith(InternalStaticPfx
);
86 ForSomeCacheManager(const SBuf
&urlPath
)
88 return urlPath
.startsWith(CacheManager::WellKnownUrlPathPrefix());
92 * makes internal url with a given host and port (remote internal url)
95 internalRemoteUri(bool encrypt
, const char *host
, unsigned short port
, const char *dir
, const SBuf
&name
)
97 static char lc_host
[SQUIDHOSTNAMELEN
];
98 assert(host
&& !name
.isEmpty());
99 /* convert host name to lower case */
100 xstrncpy(lc_host
, host
, SQUIDHOSTNAMELEN
);
103 /* check for an IP address and format appropriately if found */
104 Ip::Address test
= lc_host
;
105 if ( !test
.isAnyAddr() ) {
106 test
.toHostStr(lc_host
,SQUIDHOSTNAMELEN
);
110 * append the domain in order to mirror the requests with appended
111 * domains. If that fails, just use the hostname anyway.
113 (void)urlAppendDomain(lc_host
);
116 AnyP::Uri
tmp(AnyP::PROTO_HTTP
);
124 mb
.appendf("%s://" SQUIDSBUFPH
, encrypt
? "https" : "http", SQUIDSBUFPRINT(tmp
.authority()));
127 mb
.append(dir
, strlen(dir
));
129 mb
.append(name
.rawContent(), name
.length());
131 /* return a pointer to a local static buffer */
136 * makes internal url with local host and port
139 internalLocalUri(const char *dir
, const SBuf
&name
)
141 // XXX: getMy*() may return https_port info, but we force http URIs
142 // because we have not checked whether the callers can handle https.
143 const bool secure
= false;
144 return internalRemoteUri(secure
, getMyHostname(),
145 getMyPort(), dir
, name
);
149 internalHostname(void)
151 LOCAL_ARRAY(char, host
, SQUIDHOSTNAMELEN
+ 1);
152 xstrncpy(host
, getMyHostname(), SQUIDHOSTNAMELEN
);
154 /* For IPv6 addresses also check for a colon */
155 if (Config
.appendDomain
&& !strchr(host
, '.') && !strchr(host
, ':'))
156 strncat(host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
165 internalHostnameIs(const SBuf
&arg
)
167 if (arg
.caseCmp(internalHostname()) == 0)
170 for (const auto &w
: Config
.hostnameAliases
) {
171 if (w
.caseCmp(arg
) == 0)