-
/*
- * DEBUG: section 76 Internal Squid Object handling
- * AUTHOR: Duane, Alex, Henrik
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
*/
+/* DEBUG: section 76 Internal Squid Object handling */
+
#include "squid.h"
+#include "AccessLogEntry.h"
#include "CacheManager.h"
#include "comm/Connection.h"
#include "errorpage.h"
-#include "icmp/net_db.h"
-#include "Store.h"
-#include "HttpRequest.h"
#include "HttpReply.h"
+#include "HttpRequest.h"
+#include "icmp/net_db.h"
#include "MemBuf.h"
#include "SquidConfig.h"
#include "SquidTime.h"
+#include "Store.h"
#include "tools.h"
-#include "URL.h"
+#include "util.h"
#include "wordlist.h"
/* called when we "miss" on an internal object;
* generate known dynamic objects,
- * return HTTP_NOT_FOUND for others
+ * return Http::scNotFound for others
*/
void
-internalStart(const Comm::ConnectionPointer &clientConn, HttpRequest * request, StoreEntry * entry)
+internalStart(const Comm::ConnectionPointer &clientConn, HttpRequest * request, StoreEntry * entry, const AccessLogEntry::Pointer &ale)
{
ErrorState *err;
- const char *upath = request->urlpath.termedBuf();
- debugs(76, 3, HERE << clientConn << " requesting '" << upath << "'");
+ const SBuf upath = request->url.path();
+ debugs(76, 3, clientConn << " requesting '" << upath << "'");
- if (0 == strcmp(upath, "/squid-internal-dynamic/netdb")) {
+ static const SBuf netdbUri("/squid-internal-dynamic/netdb");
+ static const SBuf storeDigestUri("/squid-internal-periodic/store_digest");
+ static const SBuf mgrPfx("/squid-internal-mgr/");
+
+ if (upath == netdbUri) {
netdbBinaryExchange(entry);
- } else if (0 == strcmp(upath, "/squid-internal-periodic/store_digest")) {
+ } else if (upath == storeDigestUri) {
#if USE_CACHE_DIGESTS
const char *msgbuf = "This cache is currently building its digest.\n";
#else
#endif
HttpReply *reply = new HttpReply;
- reply->setHeaders(HTTP_NOT_FOUND, "Not Found", "text/plain", strlen(msgbuf), squid_curtime, -2);
+ reply->setHeaders(Http::scNotFound, "Not Found", "text/plain", strlen(msgbuf), squid_curtime, -2);
entry->replaceHttpReply(reply);
entry->append(msgbuf, strlen(msgbuf));
entry->complete();
- } else if (0 == strncmp(upath, "/squid-internal-mgr/", 20)) {
- CacheManager::GetInstance()->Start(clientConn, request, entry);
+ } else if (upath.startsWith(mgrPfx)) {
+ debugs(17, 2, "calling CacheManager due to URL-path " << mgrPfx);
+ CacheManager::GetInstance()->start(clientConn, request, entry, ale);
} else {
debugObj(76, 1, "internalStart: unknown request:\n",
request, (ObjPackMethod) & httpRequestPack);
- err = new ErrorState(ERR_INVALID_REQ, HTTP_NOT_FOUND, request);
+ err = new ErrorState(ERR_INVALID_REQ, Http::scNotFound, request, ale);
errorAppendEntry(entry, err);
}
}
-int
-internalCheck(const char *urlpath)
+bool
+internalCheck(const SBuf &urlPath)
{
- return (0 == strncmp(urlpath, "/squid-internal-", 16));
+ static const SBuf InternalPfx("/squid-internal-");
+ return urlPath.startsWith(InternalPfx);
}
-int
-internalStaticCheck(const char *urlpath)
+bool
+internalStaticCheck(const SBuf &urlPath)
{
- return (0 == strncmp(urlpath, "/squid-internal-static", 22));
+ static const SBuf InternalStaticPfx("/squid-internal-static");
+ return urlPath.startsWith(InternalStaticPfx);
}
/*
* makes internal url with a given host and port (remote internal url)
*/
char *
-internalRemoteUri(const char *host, unsigned short port, const char *dir, const char *name)
+internalRemoteUri(bool encrypt, const char *host, unsigned short port, const char *dir, const SBuf &name)
{
static char lc_host[SQUIDHOSTNAMELEN];
- assert(host && name);
+ assert(host && !name.isEmpty());
/* convert host name to lower case */
xstrncpy(lc_host, host, SQUIDHOSTNAMELEN);
Tolower(lc_host);
/* check for an IP address and format appropriately if found */
Ip::Address test = lc_host;
- if ( !test.IsAnyAddr() ) {
- test.ToHostname(lc_host,SQUIDHOSTNAMELEN);
+ if ( !test.isAnyAddr() ) {
+ test.toHostStr(lc_host,SQUIDHOSTNAMELEN);
}
/*
* append the domain in order to mirror the requests with appended
- * domains
+ * domains. If that fails, just use the hostname anyway.
*/
+ (void)urlAppendDomain(lc_host);
- /* For IPv6 addresses also check for a colon */
- if (Config.appendDomain && !strchr(lc_host, '.') && !strchr(lc_host, ':'))
- strncat(lc_host, Config.appendDomain, SQUIDHOSTNAMELEN -
- strlen(lc_host) - 1);
+ /* build URI */
+ AnyP::Uri tmp(AnyP::PROTO_HTTP);
+ tmp.host(lc_host);
+ if (port)
+ tmp.port(port);
- /* build uri in mb */
static MemBuf mb;
mb.reset();
-
- mb.Printf("http://%s", lc_host);
-
- /* append port if not default */
- if (port && port != urlDefaultPort(AnyP::PROTO_HTTP))
- mb.Printf(":%d", port);
+ mb.appendf("%s://" SQUIDSBUFPH, encrypt ? "https" : "http", SQUIDSBUFPRINT(tmp.authority()));
if (dir)
- mb.Printf("%s", dir);
+ mb.append(dir, strlen(dir));
- mb.Printf("%s", name);
+ mb.append(name.rawContent(), name.length());
/* return a pointer to a local static buffer */
return mb.buf;
* makes internal url with local host and port
*/
char *
-internalLocalUri(const char *dir, const char *name)
+internalLocalUri(const char *dir, const SBuf &name)
{
- return internalRemoteUri(getMyHostname(),
+ // XXX: getMy*() may return https_port info, but we force http URIs
+ // because we have not checked whether the callers can handle https.
+ const bool secure = false;
+ return internalRemoteUri(secure, getMyHostname(),
getMyPort(), dir, name);
}
return 0;
}
+