]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/urn.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / urn.cc
index 6b057e57ba6707ce1828ed48091f39c05b709002..b66e617292aa22893f65735a520c0b2ea8b40f05 100644 (file)
@@ -1,62 +1,39 @@
-
 /*
- * $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 "MemBuf.h"
-#include "forward.h"
-#include "globals.h"
-#include "SquidTime.h"
 #include "icmp/net_db.h"
+#include "MemBuf.h"
 #include "mime_header.h"
-#include "protos.h"
+#include "RequestFlags.h"
+#include "SquidTime.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 *);
@@ -69,11 +46,11 @@ public:
     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;
@@ -97,31 +74,15 @@ static url_entry *urnParseReply(const char *inbuf, const HttpRequestMethod&);
 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);
-
-}
-
-void
-UrnState::operator delete (void *address)
-{
-    UrnState * tmp = (UrnState *)address;
-    cbdataFree (tmp);
-}
+CBDATA_CLASS_INIT(UrnState);
 
-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;
@@ -206,9 +167,9 @@ UrnState::createUriResRequest (String &uri)
     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);
 }
 
@@ -217,21 +178,20 @@ UrnState::setUriResFromRequest(HttpRequest *r)
 {
     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");
 }
 
@@ -240,15 +200,15 @@ UrnState::start(HttpRequest * r, StoreEntry * e)
 {
     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
@@ -257,12 +217,11 @@ UrnState::created(StoreEntry *newEntry)
     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);
     }
 
@@ -303,10 +262,8 @@ url_entry_sort(const void *A, const void *B)
 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;
 }
 
@@ -372,11 +329,11 @@ urnHandleReply(void *data, StoreIOBuffer result)
     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;
@@ -396,9 +353,9 @@ urnHandleReply(void *data, StoreIOBuffer result)
 
     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);
@@ -439,7 +396,7 @@ urnHandleReply(void *data, StoreIOBuffer result)
         "</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");
@@ -517,3 +474,4 @@ urnParseReply(const char *inbuf, const HttpRequestMethod& m)
     debugs(52, 3, "urnParseReply: Found " << i << " URLs");
     return list;
 }
+