]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/internal.cc
2 * Copyright (C) 1996-2014 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 */
109 mb
.Printf("http://%s", lc_host
);
111 /* append port if not default */
112 if (port
&& port
!= urlDefaultPort(AnyP::PROTO_HTTP
))
113 mb
.Printf(":%d", port
);
116 mb
.Printf("%s", dir
);
118 mb
.Printf("%s", name
);
120 /* return a pointer to a local static buffer */
125 * makes internal url with local host and port
128 internalLocalUri(const char *dir
, const char *name
)
130 return internalRemoteUri(getMyHostname(),
131 getMyPort(), dir
, name
);
135 internalHostname(void)
137 LOCAL_ARRAY(char, host
, SQUIDHOSTNAMELEN
+ 1);
138 xstrncpy(host
, getMyHostname(), SQUIDHOSTNAMELEN
);
140 /* For IPv6 addresses also check for a colon */
141 if (Config
.appendDomain
&& !strchr(host
, '.') && !strchr(host
, ':'))
142 strncat(host
, Config
.appendDomain
, SQUIDHOSTNAMELEN
-
151 internalHostnameIs(const char *arg
)
155 if (0 == strcmp(arg
, internalHostname()))
158 for (w
= Config
.hostnameAliases
; w
; w
= w
->next
)
159 if (0 == strcmp(arg
, w
->key
))