/*
- * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "fs_io.h"
#include "FwdState.h"
#include "HttpReply.h"
-#include "HttpRequest.h"
#include "icmp/net_db.h"
#include "internal.h"
#include "ip/Address.h"
#include "Store.h"
#include "StoreClient.h"
#include "tools.h"
-#include "URL.h"
#include "wordlist.h"
#if HAVE_SYS_STAT_H
CBDATA_CLASS(netdbExchangeState);
public:
- netdbExchangeState(CachePeer *aPeer, HttpRequest *theReq) :
- p(cbdataReference(aPeer)),
- e(NULL),
- sc(NULL),
- r(theReq),
- used(0),
- buf_sz(NETDB_REQBUF_SZ),
- buf_ofs(0),
- connstate(STATE_HEADER)
+ netdbExchangeState(CachePeer *aPeer, const HttpRequestPointer &theReq) :
+ p(aPeer),
+ r(theReq)
{
*buf = 0;
-
- assert(NULL != r);
- HTTPMSGLOCK(r);
+ assert(r);
// TODO: check if we actually need to do this. should be implicit
r->http_ver = Http::ProtocolVersion();
}
debugs(38, 3, e->url());
storeUnregister(sc, e, this);
e->unlock("netdbExchangeDone");
- HTTPMSGUNLOCK(r);
- cbdataReferenceDone(p);
}
- CachePeer *p;
- StoreEntry *e;
- store_client *sc;
- HttpRequest *r;
- int64_t used;
- size_t buf_sz;
+ CbcPointer<CachePeer> p;
+ StoreEntry *e = nullptr;
+ store_client *sc = nullptr;
+ HttpRequestPointer r;
+ int64_t used = 0;
+ size_t buf_sz = NETDB_REQBUF_SZ;
char buf[NETDB_REQBUF_SZ];
- int buf_ofs;
- netdb_conn_state_t connstate;
+ int buf_ofs = 0;
+ netdb_conn_state_t connstate = STATE_HEADER;
};
CBDATA_CLASS_INIT(netdbExchangeState);
netdbHashInsert(netdbEntry * n, Ip::Address &addr)
{
networkFromInaddr(addr).toStr(n->network, MAX_IPSTRLEN);
- n->hash.key = n->network;
+ n->key = n->network;
assert(hash_lookup(addr_table, n->network) == NULL);
- hash_join(addr_table, &n->hash);
+ hash_join(addr_table, n);
}
static void
next(e ? e->hosts : nullptr),
net_db_entry(e)
{
- hash.key = xstrdup(hostname);
+ key = xstrdup(hostname);
if (e) {
e->hosts = this;
++ e->link_count;
{
net_db_name *x = new net_db_name(hostname, n);
assert(hash_lookup(host_table, hostname) == NULL);
- hash_join(host_table, &x->hash);
+ hash_join(host_table, x);
}
static void
return;
}
- addr = ia->in_addrs[ia->cur];
+ addr = ia->current();
if ((n = netdbLookupHost(hostname)) == NULL) {
n = netdbAdd(addr);
(int) n->last_use_time);
for (x = n->hosts; x; x = x->next)
- logfilePrintf(lf, " %s", hashKeyStr(&x->hash));
+ logfilePrintf(lf, " %s", hashKeyStr(x));
logfilePrintf(lf, "\n");
rec_sz += 1 + sizeof(int);
debugs(38, 3, "netdbExchangeHandleReply: " << receivedData.length << " read bytes");
- if (!cbdataReferenceValid(ex->p)) {
+ if (!ex->p.valid()) {
debugs(38, 3, "netdbExchangeHandleReply: Peer became invalid");
delete ex;
return;
}
if (!addr.isAnyAddr() && rtt > 0)
- netdbExchangeUpdatePeer(addr, ex->p, rtt, hops);
+ netdbExchangeUpdatePeer(addr, ex->p.get(), rtt, hops);
assert(o == rec_sz);
n->hops);
for (x = n->hosts; x; x = x->next)
- storeAppendPrintf(sentry, " %s", hashKeyStr(&x->hash));
+ storeAppendPrintf(sentry, " %s", hashKeyStr(x));
storeAppendPrintf(sentry, "\n");
CachePeer *p = (CachePeer *)data;
static const SBuf netDB("netdb");
char *uri = internalRemoteUri(p->host, p->http_port, "/squid-internal-dynamic/", netDB);
- debugs(38, 3, "netdbExchangeStart: Requesting '" << uri << "'");
- assert(NULL != uri);
- HttpRequest *req = HttpRequest::CreateFromUrl(uri);
+ debugs(38, 3, "Requesting '" << uri << "'");
+ const MasterXaction::Pointer mx = new MasterXaction(XactionInitiator::initIcmp);
+ HttpRequestPointer req(HttpRequest::FromUrl(uri, mx));
- if (req == NULL) {
- debugs(38, DBG_IMPORTANT, "netdbExchangeStart: Bad URI " << uri);
+ if (!req) {
+ debugs(38, DBG_IMPORTANT, MYNAME << ": Bad URI " << uri);
return;
}
if (p->login)
ex->r->url.userInfo(SBuf(p->login));
- FwdState::fwdStart(Comm::ConnectionPointer(), ex->e, ex->r);
-
+ FwdState::fwdStart(Comm::ConnectionPointer(), ex->e, ex->r.getRaw());
#endif
}
ia = ipcache_gethostbyname(request->url.host(), 0);
if (NULL != ia)
- n = netdbLookupAddr(ia->in_addrs[ia->cur]);
+ n = netdbLookupAddr(ia->current());
}
if (NULL == n)