Revision: 14344
Author: adrian.chadd
Date: Mon Oct 26 23:58:33 2009
Log: Change method->string access to urlMethodGetConstStr().

This is to begin identifying and fixing places where a NULL method or
a non-NULL but unset method is used. There's a few places where that
is being done and I'd prefer to not crash in those instances.


http://code.google.com/p/lusca-cache/source/detail?r=14344

Modified:
  /branches/LUSCA_HEAD/src/HttpRequest.c
  /branches/LUSCA_HEAD/src/access_log.c
  /branches/LUSCA_HEAD/src/acl.c
  /branches/LUSCA_HEAD/src/client_side.c
  /branches/LUSCA_HEAD/src/errorpage.c
  /branches/LUSCA_HEAD/src/external_acl.c
  /branches/LUSCA_HEAD/src/forward.c
  /branches/LUSCA_HEAD/src/htcp.c
  /branches/LUSCA_HEAD/src/http.c
  /branches/LUSCA_HEAD/src/peer_select.c
  /branches/LUSCA_HEAD/src/protos.h
  /branches/LUSCA_HEAD/src/redirect.c
  /branches/LUSCA_HEAD/src/ssl.c
  /branches/LUSCA_HEAD/src/stat.c
  /branches/LUSCA_HEAD/src/store.c
  /branches/LUSCA_HEAD/src/store_key_md5.c
  /branches/LUSCA_HEAD/src/store_log.c
  /branches/LUSCA_HEAD/src/store_rewrite.c
  /branches/LUSCA_HEAD/src/url.c

=======================================
--- /branches/LUSCA_HEAD/src/HttpRequest.c      Tue Sep 29 22:27:40 2009
+++ /branches/LUSCA_HEAD/src/HttpRequest.c      Mon Oct 26 23:58:33 2009
@@ -127,7 +127,9 @@
      assert(req && p);
      /* pack request-line */
      packerPrintf(p, "%s %.*s HTTP/%d.%d\r\n",
-       req->method->string, strLen2(req->urlpath), strBuf2(req->urlpath),  
req->http_ver.major, req->http_ver.minor);
+       urlMethodGetConstStr(req->method),
+       strLen2(req->urlpath), strBuf2(req->urlpath),
+       req->http_ver.major, req->http_ver.minor);
      /* headers */
      httpHeaderPackInto(&req->header, p);
      /* trailer */
@@ -147,7 +149,9 @@
      packerPrintf(p, "\n");
      /* pack request-line */
      packerPrintf(p, "%s %s HTTP/%d.%d\r\n",
-       req->method->string, urlCanonical(req), req->http_ver.major,  
req->http_ver.minor);
+       urlMethodGetConstStr(req->method),
+       urlCanonical(req),
+       req->http_ver.major, req->http_ver.minor);
      /* headers */
      httpHeaderPackInto(&req->header, p);
      /* trailer */
@@ -181,7 +185,7 @@
  httpRequestPrefixLen(const request_t * req)
  {
      assert(req);
-    return strlen(req->method->string) + 1 +
+    return strlen(urlMethodGetConstStr(req->method)) + 1 +
        strLen(req->urlpath) + 1 +
        4 + 1 + 3 + 2 +
        req->header.len + 2;
=======================================
--- /branches/LUSCA_HEAD/src/access_log.c       Fri May 22 02:20:20 2009
+++ /branches/LUSCA_HEAD/src/access_log.c       Mon Oct 26 23:58:33 2009
@@ -1165,7 +1165,7 @@
      if (al->icp.opcode)
        al->private.method_str = icp_opcode_str[al->icp.opcode];
      else
-       al->private.method_str = al->http.method->string;
+       al->private.method_str = urlMethodGetConstStr(al->http.method);
      if (al->hier.host[0] == '\0')
        xstrncpy(al->hier.host, dash_str, SQUIDHOSTNAMELEN);

=======================================
--- /branches/LUSCA_HEAD/src/acl.c      Mon Feb  2 12:04:44 2009
+++ /branches/LUSCA_HEAD/src/acl.c      Mon Oct 26 23:58:33 2009
@@ -1976,7 +1976,7 @@
        return aclMatchInteger(ae->data, r->protocol);
        /* NOTREACHED */
      case ACL_METHOD:
-       return aclMatchWordListInsensitive(ae->data, r->method->string);
+       return aclMatchWordListInsensitive(ae->data,  
urlMethodGetConstStr(r->method));
        /* NOTREACHED */
      case ACL_BROWSER:
        browser = httpHeaderGetStr(&checklist->request->header, HDR_USER_AGENT);
=======================================
--- /branches/LUSCA_HEAD/src/client_side.c      Thu Oct 15 16:08:35 2009
+++ /branches/LUSCA_HEAD/src/client_side.c      Mon Oct 26 23:58:33 2009
@@ -440,7 +440,7 @@
      ErrorState *err = NULL;
      char *proxy_auth_msg = NULL;
      debug(33, 2) ("The request %s %s is %s, because it matched '%s'\n",
-       http->request->method->string, http->uri,
+       urlMethodGetConstStr(http->request->method), http->uri,
        answer == ACCESS_ALLOWED ? "ALLOWED" : "DENIED",
        AclMatchedName ? AclMatchedName : "NO ACL's");
      proxy_auth_msg =  
authenticateAuthUserRequestMessage(http->conn->auth_user_request ?  
http->conn->auth_user_request : http->request->auth_user_request);
@@ -505,7 +505,7 @@
      ErrorState *err = NULL;
      char *proxy_auth_msg = NULL;
      debug(33, 2) ("The request %s %s is %s, because it matched '%s'\n",
-       http->request->method->string, http->uri,
+       urlMethodGetConstStr(http->request->method), http->uri,
        answer == ACCESS_ALLOWED ? "ALLOWED" : "DENIED",
        AclMatchedName ? AclMatchedName : "NO ACL's");
      proxy_auth_msg =  
authenticateAuthUserRequestMessage(http->conn->auth_user_request ?  
http->conn->auth_user_request : http->request->auth_user_request);
@@ -1510,7 +1510,7 @@
      debug(33, 3) ("clientSetKeepaliveFlag: http_ver = %d.%d\n",
        request->http_ver.major, request->http_ver.minor);
      debug(33, 3) ("clientSetKeepaliveFlag: method = %s\n",
-       request->method->string);
+       urlMethodGetConstStr(request->method));
      {
        http_version_t http_ver;
        if (http->conn->port->http11)
@@ -2990,7 +2990,7 @@
  {
      clientHttpRequest *http = data;
      debug(33, 2) ("The reply for %s %s is %s, because it matched '%s'\n",
-       http->request->method->string, http->uri,
+       urlMethodGetConstStr(http->request->method), http->uri,
        answer ? "ALLOWED" : "DENIED",
        AclMatchedName ? AclMatchedName : "NO ACL's");
      if (answer != ACCESS_ALLOWED) {
@@ -3402,7 +3402,7 @@
      ErrorState *err = NULL;
      http->flags.hit = 0;
      debug(33, 4) ("clientProcessOnlyIfCachedMiss: '%s %s'\n",
-       r->method->string, url);
+       urlMethodGetConstStr(r->method), url);
      http->al.http.code = HTTP_GATEWAY_TIMEOUT;
      err = errorCon(ERR_ONLY_IF_CACHED_MISS, HTTP_GATEWAY_TIMEOUT,  
http->orig_request);
      if (http->entry) {
@@ -3543,7 +3543,7 @@
      char *url = http->uri;
      request_t *r = http->request;
      HttpReply *rep;
-    debug(33, 4) ("clientProcessRequest: %s '%s'\n", r->method->string,  
url);
+    debug(33, 4) ("clientProcessRequest: %s '%s'\n",  
urlMethodGetConstStr(r->method), url);
      r->flags.collapsed = 0;
      if (httpHeaderHas(&r->header, HDR_EXPECT)) {
        int ignore = 0;
@@ -3684,7 +3684,7 @@
      char *url = http->uri;
      request_t *r = http->request;
      ErrorState *err = NULL;
-    debug(33, 4) ("clientProcessMiss: '%s %s'\n", r->method->string, url);
+    debug(33, 4) ("clientProcessMiss: '%s %s'\n",  
urlMethodGetConstStr(r->method), url);
      http->flags.hit = 0;
      r->flags.collapsed = 0;
      /*
@@ -3848,7 +3848,7 @@
      /* Wrap the request method */
      method = urlMethodGet(hmsg->buf + hmsg->m_start, hmsg->m_len);

-    debug(33, 5) ("parseHttpRequest: Method is '%s'\n", method->string);
+    debug(33, 5) ("parseHttpRequest: Method is '%s'\n",  
urlMethodGetConstStr(method));
      if (method->code == METHOD_OTHER) {
        debug(33, 5) ("parseHttpRequest: Unknown method, continuing 
regardless");
      }
=======================================
--- /branches/LUSCA_HEAD/src/errorpage.c        Sat Jan 17 12:42:09 2009
+++ /branches/LUSCA_HEAD/src/errorpage.c        Mon Oct 26 23:58:33 2009
@@ -528,7 +528,7 @@
        p = authenticateAuthUserRequestMessage(err->auth_user_request) ?  
authenticateAuthUserRequestMessage(err->auth_user_request) : "[not  
available]";
        break;
      case 'M':
-       p = r ? r->method->string : "[unknown method]";
+       p = r ? urlMethodGetConstStr(r->method) : "[unknown method]";
        break;
      case 'o':
        p = external_acl_message;
@@ -549,7 +549,7 @@
        if (NULL != r) {
            Packer p;
            memBufPrintf(&mb, "%s %.*s HTTP/%d.%d\n",
-               r->method->string,
+               urlMethodGetConstStr(r->method),
                strLen2(r->urlpath) ? strLen2(r->urlpath) : 1,
                strLen2(r->urlpath) ? strBuf2(r->urlpath) : "/",
                r->http_ver.major, r->http_ver.minor);
=======================================
--- /branches/LUSCA_HEAD/src/external_acl.c     Mon Feb  2 10:51:34 2009
+++ /branches/LUSCA_HEAD/src/external_acl.c     Mon Oct 26 23:58:33 2009
@@ -676,7 +676,7 @@
            do_free = 1;
            break;
        case EXT_ACL_METHOD:
-           str = request->method->string;
+           str = urlMethodGetConstStr(request->method);
            break;
        case EXT_ACL_HEADER:
            sb = httpHeaderGetByName(&request->header, format->header);
=======================================
--- /branches/LUSCA_HEAD/src/forward.c  Sun Jul 26 21:46:32 2009
+++ /branches/LUSCA_HEAD/src/forward.c  Mon Oct 26 23:58:33 2009
@@ -764,7 +764,7 @@
      int server_fd = fwdState->server_fd;
      FwdServer *fs = fwdState->servers;
      debug(17, 3) ("fwdDispatch: FD %d: Fetching '%s %s'\n",
-       fwdState->client_fd, request->method->string, storeUrl(entry));
+       fwdState->client_fd, urlMethodGetConstStr(request->method),  
storeUrl(entry));
      /*
       * Assert that server_fd is set.  This is to guarantee that fwdState
       * is attached to something and will be deallocated when server_fd
@@ -1257,7 +1257,7 @@
      logfilePrintf(logfile, "%9d.%03d %03d %s %s\n",
        (int) current_time.tv_sec,
        (int) current_time.tv_usec / 1000,
-       fwdState->last_status, fwdState->request->method->string,
+       fwdState->last_status, urlMethodGetConstStr(fwdState->request->method),
        fwdState->request->canonical);
  }

=======================================
--- /branches/LUSCA_HEAD/src/htcp.c     Sun Feb  1 15:14:02 2009
+++ /branches/LUSCA_HEAD/src/htcp.c     Mon Oct 26 23:58:33 2009
@@ -1221,7 +1221,7 @@
      stuff.f1 = 1;
      stuff.response = 0;
      stuff.msg_id = ++msg_id_counter;
-    stuff.S.method = (char *) req->method->string;
+    stuff.S.method = (char *) urlMethodGetConstStr(req->method);
      stuff.S.uri = (char *) storeUrl(e);
      stuff.S.version = vbuf;
      httpBuildRequestHeader(req, req, e, &hdr, flags);
@@ -1277,7 +1277,7 @@
        stuff.reason = 0;
        break;
      }
-    stuff.S.method = (char *) method->string;
+    stuff.S.method = (char *) urlMethodGetConstStr(method);
      if (e == NULL || e->mem_obj == NULL) {
        if (uri == NULL) {
            return;
=======================================
--- /branches/LUSCA_HEAD/src/http.c     Tue Sep  8 03:40:58 2009
+++ /branches/LUSCA_HEAD/src/http.c     Mon Oct 26 23:58:33 2009
@@ -261,7 +261,8 @@
      if (e->mem_obj->method->flags.purges_all && status < 400) {
        req = e->mem_obj->request;
        reqUrl = urlCanonical(req);
-       debug(88, 5) ("httpMaybeRemovePublic: purging due to %s %s\n",  
req->method->string, reqUrl);
+       debug(88, 5) ("httpMaybeRemovePublic: purging due to %s %s\n",
+         urlMethodGetConstStr(req->method), reqUrl);
        storePurgeEntriesByUrl(req, reqUrl);
        httpRemovePublicByHeader(req, reply, HDR_LOCATION);
        httpRemovePublicByHeader(req, reply, HDR_CONTENT_LOCATION);
@@ -921,7 +922,7 @@
       */
      if (len > 0 && httpState->chunk_size == 0) {
        debug(11, 1) ("httpReadReply: Unexpected reply body data from  
\"%s %s\"\n",
-           orig_request->method->string,
+           urlMethodGetConstStr(orig_request->method),
            storeUrl(entry));
        comm_close(fd);
        return;
@@ -929,7 +930,7 @@
      if (len > 0) {
        debug(11, Config.onoff.relaxed_header_parser <= 0 || keep_alive ? 1 : 2)
            ("httpReadReply: Excess data from \"%s %s\"\n",
-           orig_request->method->string,
+           urlMethodGetConstStr(orig_request->method),
            storeUrl(entry));
        comm_close(fd);
        return;
@@ -950,7 +951,7 @@
       */
      if (!httpState->flags.request_sent) {
        debug(11, 1) ("httpAppendBody: Request not yet fully sent \"%s %s\"\n",
-           orig_request->method->string,
+           urlMethodGetConstStr(orig_request->method),
            storeUrl(entry));
        keep_alive = 0;
      }
@@ -1660,7 +1661,7 @@
  {
      const int offset = mb->size;
      memBufPrintf(mb, "%s %.*s HTTP/1.%d\r\n",
-        request->method->string,
+        urlMethodGetConstStr(request->method),
        strLen2(request->urlpath) ? strLen2(request->urlpath) : 1,
        strLen2(request->urlpath) ? strBuf2(request->urlpath) : "/",
        flags.http11);
@@ -1756,7 +1757,7 @@
      HttpStateData *httpState;
      request_t *proxy_req;
      request_t *orig_req = fwd->request;
-    debug(11, 3) ("httpStart: \"%s %s\"\n", orig_req->method->string,
+    debug(11, 3) ("httpStart: \"%s %s\"\n",  
urlMethodGetConstStr(orig_req->method),
        storeUrl(fwd->entry));
      CBDATA_INIT_TYPE(HttpStateData);
      httpState = cbdataAlloc(HttpStateData);
=======================================
--- /branches/LUSCA_HEAD/src/peer_select.c      Sat Jan 17 12:15:04 2009
+++ /branches/LUSCA_HEAD/src/peer_select.c      Mon Oct 26 23:58:33 2009
@@ -139,7 +139,7 @@
      if (entry)
        debug(44, 3) ("peerSelect: %s\n", storeUrl(entry));
      else
-       debug(44, 3) ("peerSelect: %s\n", request->method->string);
+       debug(44, 3) ("peerSelect: %s\n", 
urlMethodGetConstStr(request->method));
      CBDATA_INIT_TYPE(ps_state);
      psstate = cbdataAlloc(ps_state);
      psstate->request = requestLink(request);
@@ -239,7 +239,7 @@
  {
      StoreEntry *entry = ps->entry;
      request_t *request = ps->request;
-    debug(44, 3) ("peerSelectFoo: '%s %s'\n", request->method->string,
+    debug(44, 3) ("peerSelectFoo: '%s %s'\n",  
urlMethodGetConstStr(request->method),
        request->host);
      if (ps->direct == DIRECT_UNKNOWN) {
        if (ps->always_direct == 0 && Config.accessList.AlwaysDirect) {
@@ -459,7 +459,7 @@
      peer *p;
      request_t *request = ps->request;
      hier_code code = HIER_NONE;
-    debug(44, 3) ("peerGetSomeParent: %s %s\n", request->method->string,
+    debug(44, 3) ("peerGetSomeParent: %s %s\n",  
urlMethodGetConstStr(request->method),
        request->host);
      if (ps->direct == DIRECT_YES)
        return;
=======================================
--- /branches/LUSCA_HEAD/src/protos.h   Thu Oct 15 16:08:35 2009
+++ /branches/LUSCA_HEAD/src/protos.h   Mon Oct 26 23:58:33 2009
@@ -811,6 +811,7 @@
  extern method_t *urlMethodGetKnown(const char *, int len);
  extern method_t *urlMethodGetKnownByCode(method_code_t);
  extern method_t *urlMethodDup(method_t *);
+extern const char * urlMethodGetConstStr(method_t *method);
  extern void urlMethodFree(method_t *);
  extern void urlInitialize(void);
  extern request_t *urlParse(method_t *, char *);
=======================================
--- /branches/LUSCA_HEAD/src/redirect.c Mon Feb  2 10:57:30 2009
+++ /branches/LUSCA_HEAD/src/redirect.c Mon Oct 26 23:58:33 2009
@@ -126,7 +126,7 @@
  #endif
      if (!r->client_ident)
        r->client_ident = dash_str;
-    r->method_s = http->request->method->string;
+    r->method_s = urlMethodGetConstStr(http->request->method);
      r->handler = handler;
      r->data = data;
      cbdataLock(r->data);
@@ -423,7 +423,7 @@
            str = req->request->extacl_user;
            break;
        case RFT_METHOD:
-           str = req->request->method->string;
+           str = urlMethodGetConstStr(req->request->method);
            break;
        case RFT_PROTOCOL:
            str = ProtocolStr[req->request->protocol];
=======================================
--- /branches/LUSCA_HEAD/src/ssl.c      Sat Jan 17 12:15:04 2009
+++ /branches/LUSCA_HEAD/src/ssl.c      Mon Oct 26 23:58:33 2009
@@ -516,7 +516,7 @@
            return;
        }
      }
-    debug(26, 3) ("sslStart: '%s %s'\n", request->method->string, url);
+    debug(26, 3) ("sslStart: '%s %s'\n",  
urlMethodGetConstStr(request->method), url);
      statCounter.server.all.requests++;
      statCounter.server.other.requests++;
      outgoing = getOutgoingAddr(request);
=======================================
--- /branches/LUSCA_HEAD/src/stat.c     Thu Aug 13 04:41:15 2009
+++ /branches/LUSCA_HEAD/src/stat.c     Mon Oct 26 23:58:33 2009
@@ -251,7 +251,7 @@
      memBufPrintf(mb, "KEY %s\n", storeKeyText(e->hash.key));
      /* XXX should this url be escaped? */
      if (mem)
-       memBufPrintf(mb, "\t%s %s\n", mem->method->string, mem->url);
+       memBufPrintf(mb, "\t%s %s\n", urlMethodGetConstStr(mem->method),  
mem->url);
      if (mem && mem->store_url)
        memBufPrintf(mb, "\tStore lookup URL: %s\n", mem->store_url);
      memBufPrintf(mb, "\t%s\n", describeStatuses(e));
=======================================
--- /branches/LUSCA_HEAD/src/store.c    Mon Aug 31 22:47:36 2009
+++ /branches/LUSCA_HEAD/src/store.c    Mon Oct 26 23:58:33 2009
@@ -441,7 +441,7 @@
            continue;
        }
        debug(20, 5) ("storePurgeEntriesByUrl: purging %s %s\n",
-           method->string, url);
+           urlMethodGetConstStr(method), url);
  #if USE_HTCP
        if (m == METHOD_HEAD) {
            method = urlMethodGetKnownByCode(METHOD_GET);
=======================================
--- /branches/LUSCA_HEAD/src/store_key_md5.c    Sat Jan 17 12:15:04 2009
+++ /branches/LUSCA_HEAD/src/store_key_md5.c    Mon Oct 26 23:58:33 2009
@@ -99,7 +99,7 @@
      int zero = 0;
      SQUID_MD5_CTX M;
      assert(id > 0);
-    debug(20, 3) ("storeKeyPrivate: %s %s\n", method->string, url);
+    debug(20, 3) ("storeKeyPrivate: %s %s\n",  
urlMethodGetConstStr(method), url);
      SQUID_MD5Init(&M);
      SQUID_MD5Update(&M, (unsigned char *) &id, sizeof(id));
      if (method == NULL) {
=======================================
--- /branches/LUSCA_HEAD/src/store_log.c        Sat Jan 17 12:15:04 2009
+++ /branches/LUSCA_HEAD/src/store_log.c        Mon Oct 26 23:58:33 2009
@@ -80,7 +80,7 @@
            strLen2(reply->content_type) ?  
strBuf2(reply->content_type) : "unknown",
            reply->content_length,
            mem->inmem_hi - mem->reply->hdr_sz,
-           mem->method->string,
+           urlMethodGetConstStr(mem->method),
            rfc1738_escape_unescaped(mem->url));
        logfileLineEnd(storelog);
      } else {
=======================================
--- /branches/LUSCA_HEAD/src/store_rewrite.c    Sat Jan 17 12:15:04 2009
+++ /branches/LUSCA_HEAD/src/store_rewrite.c    Mon Oct 26 23:58:33 2009
@@ -126,7 +126,7 @@
  #endif
      if (!r->client_ident)
        r->client_ident = dash_str;
-    r->method_s = http->request->method->string;
+    r->method_s = urlMethodGetConstStr(http->request->method);
      r->handler = handler;
      r->data = data;
      cbdataLock(r->data);
=======================================
--- /branches/LUSCA_HEAD/src/url.c      Mon Feb  2 12:00:35 2009
+++ /branches/LUSCA_HEAD/src/url.c      Mon Oct 26 23:58:33 2009
@@ -291,6 +291,16 @@

      return (method);
  }
+
+/*
+ * return the string for the method name
+ */
+const char *
+urlMethodGetConstStr(method_t *method)
+{
+       /* XXX this will later on handle the incorrect case where 
method->string  
is NULL */
+       return method->string;
+}

  void
  urlMethodFree(method_t * method)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to