]>
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 char *upath
= request
->urlpath
.termedBuf();
36 debugs(76, 3, HERE
<< clientConn
<< " requesting '" << upath
<< "'");
38 if (0 == strcmp(upath
, "/squid-internal-dynamic/netdb")) {
39 netdbBinaryExchange(entry
);
40 } else if (0 == strcmp(upath
, "/squid-internal-periodic/store_digest")) {
42 const char *msgbuf
= "This cache is currently building its digest.\n";
45 const char *msgbuf
= "This cache does not support Cache Digests.\n";
48 HttpReply
*reply
= new HttpReply
;
49 reply
->setHeaders(Http::scNotFound
, "Not Found", "text/plain", strlen(msgbuf
), squid_curtime
, -2);
50 entry
->replaceHttpReply(reply
);
51 entry
->append(msgbuf
, strlen(msgbuf
));
53 } else if (0 == strncmp(upath
, "/squid-internal-mgr/", 20)) {
54 debugs(17, 2, "calling CacheManager due to URL-path /squid-internal-mgr/");
55 CacheManager::GetInstance()->Start(clientConn
, request
, entry
);
57 debugObj(76, 1, "internalStart: unknown request:\n",
58 request
, (ObjPackMethod
) & httpRequestPack
);
59 err
= new ErrorState(ERR_INVALID_REQ
, Http::scNotFound
, request
);
60 errorAppendEntry(entry
, err
);
65 internalCheck(const char *urlpath
)
67 return (0 == strncmp(urlpath
, "/squid-internal-", 16));
71 internalStaticCheck(const char *urlpath
)
73 return (0 == strncmp(urlpath
, "/squid-internal-static", 22));
77 * makes internal url with a given host and port (remote internal url)
80 internalRemoteUri(const char *host
, unsigned short port
, const char *dir
, const char *name
)
82 static char lc_host
[SQUIDHOSTNAMELEN
];
84 /* convert host name to lower case */
85 xstrncpy(lc_host
, host
, SQUIDHOSTNAMELEN
);
88 /* check for an IP address and format appropriately if found */
89 Ip::Address test
= lc_host
;
90 if ( !test
.isAnyAddr() ) {
91 test
.toHostStr(lc_host
,SQUIDHOSTNAMELEN
);
95 * append the domain in order to mirror the requests with appended
99 /* For IPv6 addresses also check for a colon */
100 if (Config
.appendDomain
&& !strchr(lc_host
, '.') && !strchr(lc_host
, ':'))
101 strncat(lc_host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
102 strlen(lc_host
) - 1);
104 /* build uri in mb */
108 mb
.appendf("http://%s", lc_host
);
110 /* append port if not default */
111 if (port
&& port
!= urlDefaultPort(AnyP::PROTO_HTTP
))
112 mb
.appendf(":%u", port
);
115 mb
.append(dir
, strlen(dir
));
117 mb
.append(name
, strlen(name
));
119 /* return a pointer to a local static buffer */
124 * makes internal url with local host and port
127 internalLocalUri(const char *dir
, const char *name
)
129 return internalRemoteUri(getMyHostname(),
130 getMyPort(), dir
, name
);
134 internalHostname(void)
136 LOCAL_ARRAY(char, host
, SQUIDHOSTNAMELEN
+ 1);
137 xstrncpy(host
, getMyHostname(), SQUIDHOSTNAMELEN
);
139 /* For IPv6 addresses also check for a colon */
140 if (Config
.appendDomain
&& !strchr(host
, '.') && !strchr(host
, ':'))
141 strncat(host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
150 internalHostnameIs(const char *arg
)
154 if (0 == strcmp(arg
, internalHostname()))
157 for (w
= Config
.hostnameAliases
; w
; w
= w
->next
)
158 if (0 == strcmp(arg
, w
->key
))