return rc;
}
-/*
- * Quick-n-dirty host extraction from a URL. Steps:
- * Look for a colon
- * Skip any '/' after the colon
- * Copy the next SQUID_MAXHOSTNAMELEN bytes to host[]
- * Look for an ending '/' or ':' and terminate
- * Look for login info preceded by '@'
- */
-
-class URLHostName
-{
-
-public:
- char * extract(char const *url);
-
-private:
- static char Host [SQUIDHOSTNAMELEN];
- void init(char const *);
- void findHostStart();
- void trimTrailingChars();
- void trimAuth();
- char const *hostStart;
- char const *url;
-};
-
-char *
-urlHostname(const char *url)
-{
- return URLHostName().extract(url);
-}
-
-char URLHostName::Host[SQUIDHOSTNAMELEN];
-
-void
-URLHostName::init(char const *aUrl)
-{
- Host[0] = '\0';
- url = aUrl;
-}
-
-void
-URLHostName::findHostStart()
-{
- if (NULL == (hostStart = strchr(url, ':')))
- return;
-
- ++hostStart;
-
- while (*hostStart != '\0' && *hostStart == '/')
- ++hostStart;
-
- if (*hostStart == ']')
- ++hostStart;
-}
-
-void
-URLHostName::trimTrailingChars()
-{
- char *t;
-
- if ((t = strchr(Host, '/')))
- *t = '\0';
-
- if ((t = strrchr(Host, ':')))
- *t = '\0';
-
- if ((t = strchr(Host, ']')))
- *t = '\0';
-}
-
-void
-URLHostName::trimAuth()
-{
- char *t;
-
- if ((t = strrchr(Host, '@'))) {
- ++t;
- memmove(Host, t, strlen(t) + 1);
- }
-}
-
-char *
-URLHostName::extract(char const *aUrl)
-{
- init(aUrl);
- findHostStart();
-
- if (hostStart == NULL)
- return NULL;
-
- xstrncpy(Host, hostStart, SQUIDHOSTNAMELEN);
-
- trimTrailingChars();
-
- trimAuth();
-
- return Host;
-}
-
AnyP::Uri::Uri(AnyP::UriScheme const &aScheme) :
scheme_(aScheme),
hostIsNumeric_(false),
*/
int matchDomainName(const char *host, const char *domain, MatchDomainNameFlags flags = mdnNone);
int urlCheckRequest(const HttpRequest *);
-char *urlHostname(const char *url);
void urlExtMethodConfigure(void);
#endif /* SQUID_SRC_ANYP_URI_H */
const cache_key *key = storeKeyPublic(url, m);
debugs(88, 5, m << ' ' << url << ' ' << storeKeyText(key));
#if USE_HTCP
- neighborsHtcpClear(nullptr, url, req, m, HTCP_CLR_INVALIDATION);
+ neighborsHtcpClear(nullptr, req, m, HTCP_CLR_INVALIDATION);
#endif
Store::Root().evictIfFound(key);
}
/* Release the cached URI */
debugs(88, 4, "clientPurgeRequest: GET '" << newEntry->url() << "'" );
#if USE_HTCP
- neighborsHtcpClear(newEntry, NULL, http->request, HttpRequestMethod(Http::METHOD_GET), HTCP_CLR_PURGE);
+ neighborsHtcpClear(newEntry, http->request, HttpRequestMethod(Http::METHOD_GET), HTCP_CLR_PURGE);
#endif
newEntry->release(true);
purgeStatus = Http::scOkay;
if (newEntry) {
debugs(88, 4, "HEAD " << newEntry->url());
#if USE_HTCP
- neighborsHtcpClear(newEntry, NULL, http->request, HttpRequestMethod(Http::METHOD_HEAD), HTCP_CLR_PURGE);
+ neighborsHtcpClear(newEntry, http->request, HttpRequestMethod(Http::METHOD_HEAD), HTCP_CLR_PURGE);
#endif
newEntry->release(true);
purgeStatus = Http::scOkay;
if (entry) {
debugs(88, 4, "Vary GET " << entry->url());
#if USE_HTCP
- neighborsHtcpClear(entry, NULL, http->request, HttpRequestMethod(Http::METHOD_GET), HTCP_CLR_PURGE);
+ neighborsHtcpClear(entry, http->request, HttpRequestMethod(Http::METHOD_GET), HTCP_CLR_PURGE);
#endif
entry->release(true);
purgeStatus = Http::scOkay;
if (entry) {
debugs(88, 4, "Vary HEAD " << entry->url());
#if USE_HTCP
- neighborsHtcpClear(entry, NULL, http->request, HttpRequestMethod(Http::METHOD_HEAD), HTCP_CLR_PURGE);
+ neighborsHtcpClear(entry, http->request, HttpRequestMethod(Http::METHOD_HEAD), HTCP_CLR_PURGE);
#endif
entry->release(true);
purgeStatus = Http::scOkay;
static bool
sameUrlHosts(const char *url1, const char *url2)
{
- // XXX: Want urlHostname() here, but it uses static storage and copying
+ // XXX: Want AnyP::Uri::parse() here, but it uses static storage and copying
const char *host1 = strchr(url1, ':');
const char *host2 = strchr(url2, ':');
public:
const char *method = nullptr;
- char *uri = nullptr;
+ const char *uri = nullptr;
char *version = nullptr;
char *req_hdrs = nullptr;
size_t reqHdrsSz = 0; ///< size of the req_hdrs content
if (spec) {
stuff.S.method = spec->method;
+ stuff.S.request = spec->request;
stuff.S.uri = spec->uri;
stuff.S.version = spec->version;
stuff.S.req_hdrs = spec->req_hdrs;
hdr.clean();
#if USE_ICMP
- if (char *host = urlHostname(spec->uri)) {
+ if (const char *host = spec->request->url.host()) {
int rtt = 0;
int hops = 0;
int samp = 0;
netdbHostData(host, &samp, &rtt, &hops);
if (rtt || hops) {
- char cto_buf[128];
- snprintf(cto_buf, 128, "%s %d %f %d",
+ char cto_buf[SQUIDHOSTNAMELEN+128];
+ snprintf(cto_buf, sizeof(cto_buf), "%s %d %f %d",
host, samp, 0.001 * rtt, hops);
hdr.putExt("Cache-to-Origin", cto_buf);
}
* Send an HTCP CLR message for a specified item to a given CachePeer.
*/
void
-htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestMethod &, CachePeer * p, htcp_clr_reason reason)
+htcpClear(StoreEntry * e, HttpRequest * req, const HttpRequestMethod &, CachePeer * p, htcp_clr_reason reason)
{
static char pkt[8192];
ssize_t pktlen;
SBuf sb = req->method.image();
stuff.S.method = sb.c_str();
- if (e == NULL || e->mem_obj == NULL) {
- if (uri == NULL) {
- return;
- }
- stuff.S.uri = xstrdup(uri);
- } else {
- stuff.S.uri = (char *) e->url();
- }
+ stuff.S.request = req;
+ SBuf uri = req->effectiveRequestUri();
+ stuff.S.uri = uri.c_str();
stuff.S.version = vbuf;
if (reason != HTCP_CLR_INVALIDATION) {
HttpStateData::httpBuildRequestHeader(req, e, NULL, &hdr, flags);
if (reason != HTCP_CLR_INVALIDATION) {
mb.clean();
}
- if (e == NULL) {
- xfree(stuff.S.uri);
- }
if (!pktlen) {
debugs(31, 3, "htcpClear: htcpBuildPacket() failed");
return;
int htcpQuery(StoreEntry * e, HttpRequest * req, CachePeer * p);
/// \ingroup ServerProtocolHTCP
-void htcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestMethod &method, CachePeer * p, htcp_clr_reason reason);
+void htcpClear(StoreEntry * e, HttpRequest * req, const HttpRequestMethod &method, CachePeer * p, htcp_clr_reason reason);
/// \ingroup ServerProtocolHTCP
void htcpSocketShutdown(void);
if (pe != NULL) {
assert(e != pe);
#if USE_HTCP
- neighborsHtcpClear(e, nullptr, e->mem_obj->request.getRaw(), e->mem_obj->method, HTCP_CLR_INVALIDATION);
+ neighborsHtcpClear(e, e->mem_obj->request.getRaw(), e->mem_obj->method, HTCP_CLR_INVALIDATION);
#endif
pe->release(true);
}
if (pe != NULL) {
assert(e != pe);
#if USE_HTCP
- neighborsHtcpClear(e, nullptr, e->mem_obj->request.getRaw(), HttpRequestMethod(Http::METHOD_HEAD), HTCP_CLR_INVALIDATION);
+ neighborsHtcpClear(e, e->mem_obj->request.getRaw(), HttpRequestMethod(Http::METHOD_HEAD), HTCP_CLR_INVALIDATION);
#endif
pe->release(true);
}
* Send HTCP CLR messages to all peers configured to receive them.
*/
void
-neighborsHtcpClear(StoreEntry * e, const char *uri, HttpRequest * req, const HttpRequestMethod &method, htcp_clr_reason reason)
+neighborsHtcpClear(StoreEntry * e, HttpRequest * req, const HttpRequestMethod &method, htcp_clr_reason reason)
{
CachePeer *p;
char buf[128];
continue;
}
debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p->in_addr.toUrl(buf, 128));
- htcpClear(e, uri, req, method, p, reason);
+ htcpClear(e, req, method, p, reason);
}
}
void neighborAdd(const char *, const char *, int, int, int, int, int);
void neighbors_init(void);
#if USE_HTCP
-void neighborsHtcpClear(StoreEntry *, const char *, HttpRequest *, const HttpRequestMethod &, htcp_clr_reason);
+void neighborsHtcpClear(StoreEntry *, HttpRequest *, const HttpRequestMethod &, htcp_clr_reason);
#endif
CachePeer *peerFindByName(const char *);
CachePeer *peerFindByNameAndPort(const char *, unsigned short);
char *urlInternal(const char *, const char *) STUB_RETVAL(nullptr)
int matchDomainName(const char *, const char *, enum MatchDomainNameFlags) STUB_RETVAL(0)
int urlCheckRequest(const HttpRequest *) STUB_RETVAL(0)
-char *urlHostname(const char *) STUB_RETVAL(nullptr)
void urlExtMethodConfigure() STUB
{
char *buf = xstrdup(inbuf);
char *token;
- char *host;
url_entry *list;
url_entry *old;
int n = 32;
safe_free(old);
}
- host = urlHostname(token);
-
- if (NULL == host)
+ AnyP::Uri uri;
+ if (!uri.parse(m, SBuf(token)) || !*uri.host())
continue;
#if USE_ICMP
- list[i].rtt = netdbHostRtt(host);
+ list[i].rtt = netdbHostRtt(uri.host());
if (0 == list[i].rtt) {
- debugs(52, 3, "urnParseReply: Pinging " << host);
- netdbPingSite(host);
+ debugs(52, 3, "Pinging " << uri.host());
+ netdbPingSite(uri.host());
}
#else
list[i].rtt = 0;
#endif
- list[i].url = xstrdup(token);
- list[i].host = xstrdup(host);
+ list[i].url = xstrdup(uri.absolute().c_str());
+ list[i].host = xstrdup(uri.host());
// TODO: Use storeHas() or lock/unlock entry to avoid creating unlocked
// ones.
list[i].flags.cached = storeGetPublic(list[i].url, m) ? 1 : 0;