]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/internal.cc
2 * Copyright (C) 1996-2019 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"
26 /* called when we "miss" on an internal object;
27 * generate known dynamic objects,
28 * return Http::scNotFound for others
31 internalStart(const Comm::ConnectionPointer
&clientConn
, HttpRequest
* request
, StoreEntry
* entry
)
34 const SBuf upath
= request
->url
.path();
35 debugs(76, 3, clientConn
<< " requesting '" << upath
<< "'");
37 static const SBuf
netdbUri("/squid-internal-dynamic/netdb");
38 static const SBuf
storeDigestUri("/squid-internal-periodic/store_digest");
39 static const SBuf
mgrPfx("/squid-internal-mgr/");
41 if (upath
== netdbUri
) {
42 netdbBinaryExchange(entry
);
43 } else if (upath
== storeDigestUri
) {
45 const char *msgbuf
= "This cache is currently building its digest.\n";
48 const char *msgbuf
= "This cache does not support Cache Digests.\n";
51 HttpReply
*reply
= new HttpReply
;
52 reply
->setHeaders(Http::scNotFound
, "Not Found", "text/plain", strlen(msgbuf
), squid_curtime
, -2);
53 entry
->replaceHttpReply(reply
);
54 entry
->append(msgbuf
, strlen(msgbuf
));
56 } else if (upath
.startsWith(mgrPfx
)) {
57 debugs(17, 2, "calling CacheManager due to URL-path " << mgrPfx
);
58 CacheManager::GetInstance()->Start(clientConn
, request
, entry
);
60 debugObj(76, 1, "internalStart: unknown request:\n",
61 request
, (ObjPackMethod
) & httpRequestPack
);
62 err
= new ErrorState(ERR_INVALID_REQ
, Http::scNotFound
, request
);
63 errorAppendEntry(entry
, err
);
68 internalCheck(const SBuf
&urlPath
)
70 static const SBuf
InternalPfx("/squid-internal-");
71 return urlPath
.startsWith(InternalPfx
);
75 internalStaticCheck(const SBuf
&urlPath
)
77 static const SBuf
InternalStaticPfx("/squid-internal-static");
78 return urlPath
.startsWith(InternalStaticPfx
);
82 * makes internal url with a given host and port (remote internal url)
85 internalRemoteUri(bool encrypt
, const char *host
, unsigned short port
, const char *dir
, const SBuf
&name
)
87 static char lc_host
[SQUIDHOSTNAMELEN
];
88 assert(host
&& !name
.isEmpty());
89 /* convert host name to lower case */
90 xstrncpy(lc_host
, host
, SQUIDHOSTNAMELEN
);
93 /* check for an IP address and format appropriately if found */
94 Ip::Address test
= lc_host
;
95 if ( !test
.isAnyAddr() ) {
96 test
.toHostStr(lc_host
,SQUIDHOSTNAMELEN
);
100 * append the domain in order to mirror the requests with appended
104 /* For IPv6 addresses also check for a colon */
105 if (Config
.appendDomain
&& !strchr(lc_host
, '.') && !strchr(lc_host
, ':'))
106 strncat(lc_host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
107 strlen(lc_host
) - 1);
110 AnyP::Uri
tmp(AnyP::PROTO_HTTP
);
118 mb
.appendf("%s://" SQUIDSBUFPH
, encrypt
? "https" : "http", SQUIDSBUFPRINT(tmp
.authority()));
121 mb
.append(dir
, strlen(dir
));
123 mb
.append(name
.rawContent(), name
.length());
125 /* return a pointer to a local static buffer */
130 * makes internal url with local host and port
133 internalLocalUri(const char *dir
, const SBuf
&name
)
135 // XXX: getMy*() may return https_port info, but we force http URIs
136 // because we have not checked whether the callers can handle https.
137 const bool secure
= false;
138 return internalRemoteUri(secure
, getMyHostname(),
139 getMyPort(), dir
, name
);
143 internalHostname(void)
145 LOCAL_ARRAY(char, host
, SQUIDHOSTNAMELEN
+ 1);
146 xstrncpy(host
, getMyHostname(), SQUIDHOSTNAMELEN
);
148 /* For IPv6 addresses also check for a colon */
149 if (Config
.appendDomain
&& !strchr(host
, '.') && !strchr(host
, ':'))
150 strncat(host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
159 internalHostnameIs(const char *arg
)
163 if (0 == strcmp(arg
, internalHostname()))
166 for (w
= Config
.hostnameAliases
; w
; w
= w
->next
)
167 if (0 == strcmp(arg
, w
->key
))