Add mk-sbuf-strings.awk script to produce a global array of SBuf for the
string objects of registered methods. This can be re-used to convert
other enum name arrays as we go forward.

Use an SBuf to store unknown method names "image". Including a few
string comparison upgrades.

Removes use of RequestMethodStr() wrapper in debugs to reduce the amount
of overheads calling c_str() when debug printing method strings.


Amos
=== modified file 'src/FwdState.cc'
--- src/FwdState.cc     2014-03-31 06:57:27 +0000
+++ src/FwdState.cc     2014-04-05 02:01:24 +0000
@@ -1214,7 +1214,7 @@
 void
 FwdState::dispatch()
 {
-    debugs(17, 3, HERE << clientConn << ": Fetching '" << 
RequestMethodStr(request->method) << " " << entry->url() << "'");
+    debugs(17, 3, clientConn << ": Fetching '" << request->method << " " << 
entry->url() << "'");
     /*
      * Assert that server_fd is set.  This is to guarantee that fwdState
      * is attached to something and will be deallocated when server_fd

=== modified file 'src/HttpRequest.cc'
--- src/HttpRequest.cc  2014-03-15 02:50:12 +0000
+++ src/HttpRequest.cc  2014-04-05 12:47:03 +0000
@@ -414,7 +414,7 @@
 int
 HttpRequest::prefixLen()
 {
-    return strlen(RequestMethodStr(method)) + 1 +
+    return method.image().length() + 1 +
            urlpath.size() + 1 +
            4 + 1 + 3 + 2 +
            header.len + 2;

=== modified file 'src/HttpRequestMethod.cc'
--- src/HttpRequestMethod.cc    2013-12-18 00:48:33 +0000
+++ src/HttpRequestMethod.cc    2014-04-05 12:48:43 +0000
@@ -47,35 +47,38 @@
         return;
     }
 
+    SBuf str(begin, end-begin);
+
     for (++theMethod; theMethod < Http::METHOD_ENUM_END; ++theMethod) {
         // RFC 2616 section 5.1.1 - Method names are case-sensitive
         // NP: this is not a HTTP_VIOLATIONS case since there is no 
MUST/SHOULD involved.
-        if (0 == strncasecmp(begin, Http::MethodType_str[theMethod], 
end-begin)) {
+        if (0 == image().caseCmp(str)) {
 
             // relaxed parser allows mixed-case and corrects them on output
             if (Config.onoff.relaxed_header_parser)
                 return;
 
-            if (0 == strncmp(begin, Http::MethodType_str[theMethod], 
end-begin))
+            if (0 == image().cmp(str))
                 return;
         }
     }
 
     // if method not found and method string is not null then it is other 
method
     theMethod = Http::METHOD_OTHER;
-    theImage.limitInit(begin,end-begin);
+    theImage = str;
 }
 
-char const*
+const SBuf
 HttpRequestMethod::image() const
 {
+    static SBuf OTHER("METHOD_OTHER");
     if (Http::METHOD_OTHER != theMethod) {
-        return Http::MethodType_str[theMethod];
+        return Http::MethodType_sb[theMethod];
     } else {
-        if (theImage.size()>0) {
-            return theImage.termedBuf();
+        if (!theImage.isEmpty()) {
+            return theImage;
         } else {
-            return "METHOD_OTHER";
+            return OTHER;
         }
     }
 }

=== modified file 'src/HttpRequestMethod.h'
--- src/HttpRequestMethod.h     2012-10-26 11:36:45 +0000
+++ src/HttpRequestMethod.h     2014-04-06 08:03:38 +0000
@@ -2,8 +2,7 @@
 #define SQUID_HTTPREQUESTMETHOD_H
 
 #include "http/MethodType.h"
-#include "SquidString.h"
-#include "SquidString.h"
+#include "SBuf.h"
 
 class SquidConfig;
 
@@ -41,7 +40,7 @@
 
     HttpRequestMethod & operator = (Http::MethodType const aMethod) {
         theMethod = aMethod;
-        theImage.clean();
+        theImage.clear();
         return *this;
     }
 
@@ -74,7 +73,7 @@
     Http::MethodType id() const { return theMethod; }
 
     /** Get a char string representation of the method. */
-    char const * image() const;
+    const SBuf image() const;
 
     /// Whether this method is defined as a "safe" in HTTP/1.1
     /// see RFC 2616 section 9.1.1
@@ -112,10 +111,8 @@
     bool purgesOthers() const;
 
 private:
-    static const char *RequestMethodStr[];
-
     Http::MethodType theMethod; ///< Method type
-    String theImage;     ///< Used for storing the Http::METHOD_OTHER only. A 
copy of the parsed method text.
+    SBuf theImage;     ///< Used for storing the Http::METHOD_OTHER only. A 
copy of the parsed method text.
 };
 
 inline std::ostream &
@@ -128,13 +125,13 @@
 inline const char*
 RequestMethodStr(const Http::MethodType m)
 {
-    return HttpRequestMethod(m).image();
+    return SBuf(HttpRequestMethod(m).image()).c_str();
 }
 
 inline const char*
 RequestMethodStr(const HttpRequestMethod& m)
 {
-    return m.image();
+    return SBuf(m.image()).c_str();
 }
 
 #endif /* SQUID_HTTPREQUESTMETHOD_H */

=== modified file 'src/Makefile.am'
--- src/Makefile.am     2014-03-31 04:46:50 +0000
+++ src/Makefile.am     2014-04-06 13:29:39 +0000
@@ -824,6 +824,7 @@
        DiskIO/modules.sh \
        mk-globals-c.pl \
        mk-globals-c.awk \
+       mk-sbuf-arrays.awk \
        mk-string-arrays.pl \
        mk-string-arrays.awk \
        repl_modules.sh \
@@ -3804,6 +3805,9 @@
        fatal.h \
        tests/stub_fatal.cc \
        tests/stub_MemBuf.cc \
+       $(SBUF_SOURCE) \
+       SBufDetailedStats.h \
+       tests/stub_SBufDetailedStats.cc \
        StatHist.cc \
        StatHist.h \
        String.cc \
@@ -3822,6 +3826,7 @@
        repl_modules.h \
        tests/stub_store.cc \
        tests/stub_store_stats.cc \
+       time.cc \
        tools.h \
        tests/stub_tools.cc \
        tests/testMain.cc \

=== modified file 'src/Server.cc'
--- src/Server.cc       2014-01-01 19:20:49 +0000
+++ src/Server.cc       2014-04-05 05:29:06 +0000
@@ -517,7 +517,7 @@
 
     // XXX: should we use originalRequest() here?
     const char *reqUrl = urlCanonical(request);
-    debugs(88, 5, "maybe purging due to " << RequestMethodStr(request->method) 
<< ' ' << reqUrl);
+    debugs(88, 5, "maybe purging due to " << request->method << ' ' << reqUrl);
     purgeEntriesByUrl(request, reqUrl);
     purgeEntriesByHeader(request, reqUrl, theFinalReply, HDR_LOCATION);
     purgeEntriesByHeader(request, reqUrl, theFinalReply, HDR_CONTENT_LOCATION);

=== modified file 'src/cache_diff.cc'
--- src/cache_diff.cc   2012-09-01 14:38:36 +0000
+++ src/cache_diff.cc   2014-04-06 08:01:34 +0000
@@ -59,18 +59,6 @@
     unsigned char key_arr[SQUID_MD5_DIGEST_LENGTH];
 } CacheEntry;
 
-/* copied from url.c */
-const char *RequestMethodStr[] = {
-    "NONE",
-    "GET",
-    "POST",
-    "PUT",
-    "HEAD",
-    "CONNECT",
-    "TRACE",
-    "PURGE"
-};
-
 static int cacheIndexScan(CacheIndex * idx, const char *fname, FILE * file);
 
 static CacheEntry *

=== modified file 'src/client_side.cc'
--- src/client_side.cc  2014-03-31 06:57:27 +0000
+++ src/client_side.cc  2014-04-04 12:54:26 +0000
@@ -898,10 +898,8 @@
 {
     HttpRequest *request = http->request;
 
-    debugs(33, 3, "clientSetKeepaliveFlag: http_ver = " <<
-           request->http_ver.major << "." << request->http_ver.minor);
-    debugs(33, 3, "clientSetKeepaliveFlag: method = " <<
-           RequestMethodStr(request->method));
+    debugs(33, 3, "http_ver = " << request->http_ver.major << "." << 
request->http_ver.minor);
+    debugs(33, 3, "method = " << request->method);
 
     // TODO: move to HttpRequest::hdrCacheInit, just like HttpReply.
     request->flags.proxyKeepalive = request->persistent();

=== modified file 'src/client_side_reply.cc'
--- src/client_side_reply.cc    2014-03-31 06:57:27 +0000
+++ src/client_side_reply.cc    2014-04-04 12:57:46 +0000
@@ -631,7 +631,7 @@
     char *url = http->uri;
     HttpRequest *r = http->request;
     ErrorState *err = NULL;
-    debugs(88, 4, "clientProcessMiss: '" << RequestMethodStr(r->method) << " " 
<< url << "'");
+    debugs(88, 4, "clientProcessMiss: '" << r->method << " " << url << "'");
 
     /**
      * We might have a left-over StoreEntry from a failed cache hit
@@ -708,8 +708,7 @@
 void
 clientReplyContext::processOnlyIfCachedMiss()
 {
-    debugs(88, 4, "clientProcessOnlyIfCachedMiss: '" <<
-           RequestMethodStr(http->request->method) << " " << http->uri << "'");
+    debugs(88, 4, "'" << http->request->method << " " << http->uri << "'");
     http->al->http.code = Http::scGatewayTimeout;
     ErrorState *err = clientBuildError(ERR_ONLY_IF_CACHED_MISS, 
Http::scGatewayTimeout, NULL,
                                        
http->getConn()->clientConnection->remote, http->request);
@@ -835,7 +834,7 @@
     for (HttpRequestMethod m(Http::METHOD_NONE); m != Http::METHOD_ENUM_END; 
++m) {
         if (m.respMaybeCacheable()) {
             if (StoreEntry *entry = storeGetPublic(url, m)) {
-                debugs(88, 5, "purging " << *entry << ' ' << 
RequestMethodStr(m) << ' ' << url);
+                debugs(88, 5, "purging " << *entry << ' ' << m << ' ' << url);
 #if USE_HTCP
                 neighborsHtcpClear(entry, url, req, m, HTCP_CLR_INVALIDATION);
                 if (m == Http::METHOD_GET || m == Http::METHOD_HEAD) {
@@ -1995,7 +1994,7 @@
 void
 clientReplyContext::processReplyAccessResult(const allow_t &accessAllowed)
 {
-    debugs(88, 2, "The reply for " << RequestMethodStr(http->request->method)
+    debugs(88, 2, "The reply for " << http->request->method
            << " " << http->uri << " is " << accessAllowed << ", because it 
matched '"
            << (AclMatchedName ? AclMatchedName : "NO ACL's") << "'" );
 

=== modified file 'src/client_side_request.cc'
--- src/client_side_request.cc  2014-03-31 06:57:27 +0000
+++ src/client_side_request.cc  2014-04-04 12:59:23 +0000
@@ -758,8 +758,7 @@
     acl_checklist = NULL;
     err_type page_id;
     Http::StatusCode status;
-    debugs(85, 2, "The request " <<
-           RequestMethodStr(http->request->method) << " " <<
+    debugs(85, 2, "The request " << http->request->method << " " <<
            http->uri << " is " << answer <<
            "; last ACL checked: " << (AclMatchedName ? AclMatchedName : 
"[none]"));
 
@@ -1516,7 +1515,7 @@
 void
 ClientHttpRequest::processRequest()
 {
-    debugs(85, 4, "clientProcessRequest: " << 
RequestMethodStr(request->method) << " '" << uri << "'");
+    debugs(85, 4, request->method << " '" << uri << "'");
 
     if (request->method == Http::METHOD_CONNECT && !redirect.status) {
 #if USE_OPENSSL

=== modified file 'src/format/Format.cc'
--- src/format/Format.cc        2014-03-30 12:00:34 +0000
+++ src/format/Format.cc        2014-04-05 13:24:23 +0000
@@ -916,7 +916,7 @@
 
         case LFT_CLIENT_REQ_METHOD:
             if (al->request) {
-                out = al->request->method.image();
+                out = RequestMethodStr(al->request->method);
                 quote = 1;
             }
             break;
@@ -967,7 +967,7 @@
 
         case LFT_SERVER_REQ_METHOD:
             if (al->adapted_request) {
-                out = al->adapted_request->method.image();
+                out = RequestMethodStr(al->adapted_request->method);
                 quote = 1;
             }
             break;

=== modified file 'src/http.cc'
--- src/http.cc 2014-03-31 06:57:27 +0000
+++ src/http.cc 2014-04-05 13:20:49 +0000
@@ -1046,7 +1046,7 @@
      * connection.
      */
     if (!flags.request_sent) {
-        debugs(11, 2, "statusIfComplete: Request not yet fully sent \"" << 
RequestMethodStr(request->method) << " " << entry->url() << "\"" );
+        debugs(11, 2, "Request not yet fully sent \"" << request->method << " 
" << entry->url() << "\"" );
         return COMPLETE_NONPERSISTENT_MSG;
     }
 
@@ -2269,7 +2269,7 @@
 void
 httpStart(FwdState *fwd)
 {
-    debugs(11, 3, "httpStart: \"" << RequestMethodStr(fwd->request->method) << 
" " << fwd->entry->url() << "\"" );
+    debugs(11, 3, "\"" << fwd->request->method << " " << fwd->entry->url() << 
"\"");
     AsyncJob::Start(new HttpStateData(fwd));
 }
 

=== modified file 'src/http/Makefile.am'
--- src/http/Makefile.am        2013-03-18 04:55:51 +0000
+++ src/http/Makefile.am        2014-04-04 11:55:54 +0000
@@ -12,8 +12,8 @@
        StatusLine.cc \
        StatusLine.h
 
-MethodType.cc: MethodType.h $(top_srcdir)/src/mk-string-arrays.awk
-       ($(AWK) -f $(top_srcdir)/src/mk-string-arrays.awk < 
$(srcdir)/MethodType.h | \
+MethodType.cc: MethodType.h $(top_srcdir)/src/mk-sbuf-arrays.awk
+       ($(AWK) -f $(top_srcdir)/src/mk-sbuf-arrays.awk < 
$(srcdir)/MethodType.h | \
                sed -e 's%METHOD_%%' -e 's%_C%-C%' >$@) || ($(RM) -f $@ && exit 
1)
 
 CLEANFILES += MethodType.cc

=== modified file 'src/http/MethodType.h'
--- src/http/MethodType.h       2014-03-31 10:28:35 +0000
+++ src/http/MethodType.h       2014-04-04 11:53:14 +0000
@@ -1,6 +1,8 @@
 #ifndef SQUID_SRC_HTTP_METHODTYPE_H
 #define SQUID_SRC_HTTP_METHODTYPE_H
 
+#include "SBuf.h"
+
 namespace Http
 {
 
@@ -83,12 +85,12 @@
     METHOD_ENUM_END  // MUST be last, (yuck) this is used as an 
array-initialization index constant!
 } MethodType;
 
-extern const char *MethodType_str[];
+extern const SBuf MethodType_sb[];
 
-inline const char*
+inline const SBuf
 MethodStr(const MethodType m)
 {
-    return MethodType_str[m];
+    return MethodType_sb[m];
 }
 
 }; // namespace Http

=== modified file 'src/mgr/ActionParams.cc'
--- src/mgr/ActionParams.cc     2013-03-21 21:06:48 +0000
+++ src/mgr/ActionParams.cc     2014-04-04 12:44:54 +0000
@@ -33,7 +33,7 @@
 Mgr::ActionParams::pack(Ipc::TypedMsgHdr &msg) const
 {
     msg.putString(httpUri);
-    String foo(httpMethod.image());
+    String foo(httpMethod.image().toString());
     msg.putString(foo);
     msg.putPod(httpFlags);
     msg.putString(httpOrigin);

=== added file 'src/mk-sbuf-arrays.awk'
--- src/mk-sbuf-arrays.awk      1970-01-01 00:00:00 +0000
+++ src/mk-sbuf-arrays.awk      2014-04-05 07:31:34 +0000
@@ -0,0 +1,68 @@
+# tested with gawk, mawk, and nawk.
+# drop-in replacement for mk-string-arrays.pl.
+# creates "enum.c" (on stdout) from "enum.h".
+# invoke similarly: perl -f mk-string-arrays.pl         enum.h
+#              -->  awk -f mk-string-arrays.awk enum.h
+#
+# 2006 by Christopher Kerr.
+#
+# 2009 modified by Amos Jeffries
+#   Adapted to convert individual enum headers
+#
+
+BEGIN {
+       print "/*"
+       print " * Auto-Generated File. Changes will be destroyed."
+       print " */"
+       print "#include \"squid.h\""
+       print "#include \"SBuf.h\""
+        codeSkip = 1
+        e = 0
+        nspath = ""
+}
+
+# when namespace is encountered store it
+/^namespace [a-zA-Z]+/ {
+       nspath = tolower($2) "/"                # nested folder
+       namespace = $2                          # code namespace reconstruct
+       next
+}
+
+# Skip all lines outside of typedef {}
+/^typedef/             { codeSkip = 0; next }
+codeSkip == 1          { next }
+
+/^[ \t]*[A-Z]/ {
+       split($1, t, ",")                       # remove ,
+       Element[++e] = t[1]
+       next
+}
+
+/^#/ {
+       if (codeSkip) next
+
+       Wrapper[++e] = $0
+       next
+}
+
+/^} / {
+       split($2, t, ";")                       # remove ;
+       type = t[1]
+        codeSkip = 1
+
+       print "#include \"" nspath type ".h\""
+
+       # if namesapce is not empty ??
+       if (namespace) print "namespace " namespace
+       if (namespace) print "{"
+
+       print "\nconst SBuf " type "_sb[] = {"
+       for ( i = 1; i < e; ++i)
+               if (Wrapper[i]) print Wrapper[i]
+               else print "\tSBuf(\"" Element[i] "\"),"
+
+       print "\tSBuf(\"" Element[i] "\")"
+       print "};"
+       if (namespace) print "}; // namespace " namespace
+       next
+}

=== modified file 'src/peer_select.cc'
--- src/peer_select.cc  2014-04-03 10:22:52 +0000
+++ src/peer_select.cc  2014-04-05 03:13:56 +0000
@@ -156,9 +156,9 @@
     ps_state *psstate;
 
     if (entry)
-        debugs(44, 3, "peerSelect: " << entry->url()  );
+        debugs(44, 3, entry->url());
     else
-        debugs(44, 3, "peerSelect: " << RequestMethodStr(request->method));
+        debugs(44, 3, request->method);
 
     psstate = new ps_state;
 
@@ -459,7 +459,7 @@
 
     StoreEntry *entry = ps->entry;
     HttpRequest *request = ps->request;
-    debugs(44, 3, "peerSelectFoo: '" << RequestMethodStr(request->method) << " 
" << request->GetHost() << "'");
+    debugs(44, 3, request->method << " " << request->GetHost());
 
     /** If we don't know whether DIRECT is permitted ... */
     if (ps->direct == DIRECT_UNKNOWN) {
@@ -703,7 +703,7 @@
     CachePeer *p;
     HttpRequest *request = ps->request;
     hier_code code = HIER_NONE;
-    debugs(44, 3, "peerGetSomeParent: " << RequestMethodStr(request->method) 
<< " " << request->GetHost());
+    debugs(44, 3, request->method << " " << request->GetHost());
 
     if (ps->direct == DIRECT_YES)
         return;

=== modified file 'src/test_cache_digest.cc'
--- src/test_cache_digest.cc    2012-09-01 14:38:36 +0000
+++ src/test_cache_digest.cc    2014-04-06 08:02:33 +0000
@@ -103,18 +103,6 @@
 static time_t cur_time = -1;   /* timestamp of the current log entry */
 
 /* copied from url.c */
-const char *RequestMethodStr[] = {
-    "NONE",
-    "GET",
-    "POST",
-    "PUT",
-    "HEAD",
-    "CONNECT",
-    "TRACE",
-    "PURGE"
-};
-
-/* copied from url.c */
 static HttpRequestMethod
 methodStrToId(const char *s)
 {

=== modified file 'src/tests/testHttpRequestMethod.cc'
--- src/tests/testHttpRequestMethod.cc  2014-02-21 10:46:19 +0000
+++ src/tests/testHttpRequestMethod.cc  2014-04-05 09:27:56 +0000
@@ -84,15 +84,15 @@
 {
     // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
     Config.onoff.relaxed_header_parser = 1;
-    CPPUNIT_ASSERT_EQUAL(String("POST"), 
String(HttpRequestMethod("POST",NULL).image()));
-    CPPUNIT_ASSERT_EQUAL(String("POST"), 
String(HttpRequestMethod("pOsT",NULL).image()));
-    CPPUNIT_ASSERT_EQUAL(String("POST"), 
String(HttpRequestMethod("post",NULL).image()));
+    CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("POST",NULL).image());
+    CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("pOsT",NULL).image());
+    CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("post",NULL).image());
 
     // strict RFC-compliance parse HTTP methods are case sensitive
     Config.onoff.relaxed_header_parser = 0;
-    CPPUNIT_ASSERT_EQUAL(String("POST"), 
String(HttpRequestMethod("POST",NULL).image()));
-    CPPUNIT_ASSERT_EQUAL(String("pOsT"), 
String(HttpRequestMethod("pOsT",NULL).image()));
-    CPPUNIT_ASSERT_EQUAL(String("post"), 
String(HttpRequestMethod("post",NULL).image()));
+    CPPUNIT_ASSERT_EQUAL(SBuf("POST"), HttpRequestMethod("POST",NULL).image());
+    CPPUNIT_ASSERT_EQUAL(SBuf("pOsT"), HttpRequestMethod("pOsT",NULL).image());
+    CPPUNIT_ASSERT_EQUAL(SBuf("post"), HttpRequestMethod("post",NULL).image());
 }
 
 /*

=== modified file 'src/tunnel.cc'
--- src/tunnel.cc       2014-02-21 10:46:19 +0000
+++ src/tunnel.cc       2014-04-05 07:15:07 +0000
@@ -873,7 +873,7 @@
         }
     }
 
-    debugs(26, 3, HERE << "'" << RequestMethodStr(request->method) << " " << 
url << " " << request->http_ver << "'");
+    debugs(26, 3, "'" << request->method << " " << url << " " << 
request->http_ver << "'");
     ++statCounter.server.all.requests;
     ++statCounter.server.other.requests;
 

Reply via email to