-
/*
- * $Id$
- *
- * DEBUG: section 52 URN Parsing
- * AUTHOR: Kostas Anagnostakis
- *
- * 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-2015 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 52 URN Parsing */
+
#include "squid.h"
+#include "cbdata.h"
#include "errorpage.h"
-#include "StoreClient.h"
-#include "Store.h"
+#include "FwdState.h"
+#include "globals.h"
#include "HttpReply.h"
#include "HttpRequest.h"
+#include "icmp/net_db.h"
#include "MemBuf.h"
-#include "forward.h"
-#include "globals.h"
+#include "mime_header.h"
+#include "RequestFlags.h"
#include "SquidTime.h"
-#include "icmp/net_db.h"
-#include "protos.h"
+#include "Store.h"
+#include "StoreClient.h"
+#include "tools.h"
#include "URL.h"
+#include "urn.h"
-#define URN_REQBUF_SZ 4096
+#define URN_REQBUF_SZ 4096
class UrnState : public StoreClient
{
+ CBDATA_CLASS(UrnState);
public:
void created (StoreEntry *newEntry);
- void *operator new (size_t byteCount);
- void operator delete (void *address);
void start (HttpRequest *, StoreEntry *);
char *getHost (String &urlpath);
void setUriResFromRequest(HttpRequest *);
virtual ~UrnState();
-
StoreEntry *entry;
store_client *sc;
StoreEntry *urlres_e;
- HttpRequest *request;
- HttpRequest *urlres_r;
+ HttpRequest::Pointer request;
+ HttpRequest::Pointer urlres_r;
struct {
- unsigned int force_menu:1;
+ bool force_menu;
} flags;
char reqbuf[URN_REQBUF_SZ];
int reqofs;
static const char *const crlf = "\r\n";
static QS url_entry_sort;
-CBDATA_TYPE(UrnState);
-void *
-UrnState::operator new (size_t byteCount)
-{
- /* derived classes with different sizes must implement their own new */
- assert (byteCount == sizeof (UrnState));
- CBDATA_INIT_TYPE(UrnState);
- return cbdataAlloc(UrnState);
+CBDATA_CLASS_INIT(UrnState);
-}
-
-void
-UrnState::operator delete (void *address)
-{
- UrnState * tmp = (UrnState *)address;
- cbdataFree (tmp);
-}
-
-UrnState::~UrnState ()
+UrnState::~UrnState()
{
safe_free(urlres);
}
static url_entry *
-urnFindMinRtt(url_entry * urls, const HttpRequestMethod& m, int *rtt_ret)
+urnFindMinRtt(url_entry * urls, const HttpRequestMethod &, int *rtt_ret)
{
int min_rtt = 0;
url_entry *u = NULL;
char *host = getHost (uri);
snprintf(local_urlres, 4096, "http://%s/uri-res/N2L?urn:" SQUIDSTRINGPH,
host, SQUIDSTRINGPRINT(uri));
- safe_free (host);
- safe_free (urlres);
- urlres = xstrdup (local_urlres);
+ safe_free(host);
+ safe_free(urlres);
+ urlres = xstrdup(local_urlres);
urlres_r = HttpRequest::CreateFromUrl(urlres);
}
{
if (RequestNeedsMenu(r)) {
updateRequestURL(r, r->urlpath.rawBuf() + 5, r->urlpath.size() - 5 );
- flags.force_menu = 1;
+ flags.force_menu = true;
}
createUriResRequest (r->urlpath);
if (urlres_r == NULL) {
debugs(52, 3, "urnStart: Bad uri-res URL " << urlres);
- ErrorState *err = new ErrorState(ERR_URN_RESOLVE, HTTP_NOT_FOUND, r);
+ ErrorState *err = new ErrorState(ERR_URN_RESOLVE, Http::scNotFound, r);
err->url = urlres;
urlres = NULL;
errorAppendEntry(entry, err);
return;
}
- HTTPMSGLOCK(urlres_r);
urlres_r->header.putStr(HDR_ACCEPT, "text/plain");
}
{
debugs(52, 3, "urnStart: '" << e->url() << "'" );
entry = e;
- request = HTTPMSGLOCK(r);
+ request = r;
- entry->lock();
+ entry->lock("UrnState::start");
setUriResFromRequest(r);
if (urlres_r == NULL)
return;
- StoreEntry::getPublic (this, urlres, METHOD_GET);
+ StoreEntry::getPublic (this, urlres, Http::METHOD_GET);
}
void
urlres_e = newEntry;
if (urlres_e->isNull()) {
- urlres_e = storeCreateEntry(urlres, urlres, request_flags(), METHOD_GET);
+ urlres_e = storeCreateEntry(urlres, urlres, RequestFlags(), Http::METHOD_GET);
sc = storeClientListAdd(urlres_e, this);
- FwdState::fwdStart(Comm::ConnectionPointer(), urlres_e, urlres_r);
+ FwdState::fwdStart(Comm::ConnectionPointer(), urlres_e, urlres_r.getRaw());
} else {
-
- urlres_e->lock();
+ urlres_e->lock("UrnState::created");
sc = storeClientListAdd(urlres_e, this);
}
static void
urnHandleReplyError(UrnState *urnState, StoreEntry *urlres_e)
{
- urlres_e->unlock();
- urnState->entry->unlock();
- HTTPMSGUNLOCK(urnState->request);
- HTTPMSGUNLOCK(urnState->urlres_r);
+ urlres_e->unlock("urnHandleReplyError+res");
+ urnState->entry->unlock("urnHandleReplyError+prime");
delete urnState;
}
assert(urlres_e->getReply());
rep = new HttpReply;
rep->parseCharBuf(buf, k);
- debugs(52, 3, "reply exists, code=" << rep->sline.status << ".");
+ debugs(52, 3, "reply exists, code=" << rep->sline.status() << ".");
- if (rep->sline.status != HTTP_OK) {
+ if (rep->sline.status() != Http::scOkay) {
debugs(52, 3, "urnHandleReply: failed.");
- err = new ErrorState(ERR_URN_RESOLVE, HTTP_NOT_FOUND, urnState->request);
+ err = new ErrorState(ERR_URN_RESOLVE, Http::scNotFound, urnState->request.getRaw());
err->url = xstrdup(e->url());
errorAppendEntry(e, err);
delete rep;
debugs(53, 3, "urnFindMinRtt: Counted " << i << " URLs");
- if (urls == NULL) { /* unkown URN error */
- debugs(52, 3, "urnTranslateDone: unknown URN " << e->url() );
- err = new ErrorState(ERR_URN_RESOLVE, HTTP_NOT_FOUND, urnState->request);
+ if (urls == NULL) { /* unkown URN error */
+ debugs(52, 3, "urnTranslateDone: unknown URN " << e->url());
+ err = new ErrorState(ERR_URN_RESOLVE, Http::scNotFound, urnState->request.getRaw());
err->url = xstrdup(e->url());
errorAppendEntry(e, err);
urnHandleReplyError(urnState, urlres_e);
"</ADDRESS>\n",
APP_FULLNAME, getMyHostname());
rep = new HttpReply;
- rep->setHeaders(HTTP_MOVED_TEMPORARILY, NULL, "text/html", mb->contentSize(), 0, squid_curtime);
+ rep->setHeaders(Http::scFound, NULL, "text/html", mb->contentSize(), 0, squid_curtime);
if (urnState->flags.force_menu) {
debugs(51, 3, "urnHandleReply: forcing menu");
debugs(52, 3, "urnParseReply: Found " << i << " URLs");
return list;
}
+