]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: remove goto from logformat token parser
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 23 Aug 2014 11:17:32 +0000 (04:17 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 23 Aug 2014 11:17:32 +0000 (04:17 -0700)
src/format/Token.cc

index 606633df00a897f1f7cf58ca148efdc31ce680b4..04be5b27ee45f4561d2889dda188e024cb8a14c7 100644 (file)
@@ -271,130 +271,125 @@ Format::Token::parse(const char *def, Quoting *quoting)
             --l;
         }
 
-        goto done;
-    }
-
-    if (!*cur)
-        goto done;
-
-    ++cur;
-
-    // select quoting style for his particular token
-    switch (*cur) {
-
-    case '"':
-        quote = LOG_QUOTE_QUOTES;
-        ++cur;
-        break;
+    } else if (*cur) {
 
-    case '\'':
-        quote = LOG_QUOTE_RAW;
         ++cur;
-        break;
 
-    case '[':
-        quote = LOG_QUOTE_MIMEBLOB;
-        ++cur;
-        break;
+        // select quoting style for his particular token
+        switch (*cur) {
 
-    case '#':
-        quote = LOG_QUOTE_URL;
-        ++cur;
-        break;
-
-    default:
-        quote = *quoting;
-        break;
-    }
+        case '"':
+            quote = LOG_QUOTE_QUOTES;
+            ++cur;
+            break;
 
-    if (*cur == '-') {
-        left = true;
-        ++cur;
-    }
+        case '\'':
+            quote = LOG_QUOTE_RAW;
+            ++cur;
+            break;
 
-    if (*cur == '0') {
-        zero = true;
-        ++cur;
-    }
+        case '[':
+            quote = LOG_QUOTE_MIMEBLOB;
+            ++cur;
+            break;
 
-    char *endp;
-    if (xisdigit(*cur)) {
-        widthMin = strtol(cur, &endp, 10);
-        cur = endp;
-    }
+        case '#':
+            quote = LOG_QUOTE_URL;
+            ++cur;
+            break;
 
-    if (*cur == '.' && xisdigit(*(++cur))) {
-        widthMax = strtol(cur, &endp, 10);
-        cur = endp;
-    }
+        default:
+            quote = *quoting;
+            break;
+        }
 
-    if (*cur == '{') {
-        char *cp;
-        ++cur;
-        l = strcspn(cur, "}");
-        cp = (char *)xmalloc(l + 1);
-        xstrncpy(cp, cur, l + 1);
-        data.string = cp;
-        cur += l;
+        if (*cur == '-') {
+            left = true;
+            ++cur;
+        }
 
-        if (*cur == '}')
+        if (*cur == '0') {
+            zero = true;
             ++cur;
-    }
+        }
 
-    type = LFT_NONE;
-
-    // Scan each registered token namespace
-    debugs(46, 9, HERE << "check for token in " << TheConfig.tokens.size() << " namespaces.");
-    for (std::list<TokenNamespace>::const_iterator itr = TheConfig.tokens.begin(); itr != TheConfig.tokens.end(); ++itr) {
-        debugs(46, 7, HERE << "check for possible " << itr->prefix << ":: token");
-        const size_t len = itr->prefix.size();
-        if (itr->prefix.cmp(cur, len) == 0 && cur[len] == ':' && cur[len+1] == ':') {
-            debugs(46, 5, HERE << "check for " << itr->prefix << ":: token in '" << cur << "'");
-            const char *old = cur;
-            cur = scanForToken(itr->tokenSet, cur+len+2);
-            if (old != cur) // found
-                break;
-            else // reset to start of namespace
-                cur = cur - len - 2;
+        char *endp;
+        if (xisdigit(*cur)) {
+            widthMin = strtol(cur, &endp, 10);
+            cur = endp;
         }
-    }
 
-    if (type == LFT_NONE) {
-        // For upward compatibility, assume "http::" prefix as default prefix
-        // for all log access formatting codes, except those starting with a
-        // "%" or a known namespace. (ie "icap::", "adapt::")
-        if (strncmp(cur,"http::", 6) == 0 && *(cur+6) != '%' )
-            cur += 6;
+        if (*cur == '.' && xisdigit(*(++cur))) {
+            widthMax = strtol(cur, &endp, 10);
+            cur = endp;
+        }
 
-        // NP: scan the sets of tokens in decreasing size to guarantee no
-        //     mistakes made with overlapping names. (Bug 3310)
+        if (*cur == '{') {
+            char *cp;
+            ++cur;
+            l = strcspn(cur, "}");
+            cp = (char *)xmalloc(l + 1);
+            xstrncpy(cp, cur, l + 1);
+            data.string = cp;
+            cur += l;
+
+            if (*cur == '}')
+                ++cur;
+        }
 
-        // Scan for various long tokens
-        debugs(46, 5, HERE << "scan for possible Misc token");
-        cur = scanForToken(TokenTableMisc, cur);
-        // scan for 2-char tokens
-        if (type == LFT_NONE) {
-            debugs(46, 5, HERE << "scan for possible 2C token");
-            cur = scanForToken(TokenTable2C, cur);
+        type = LFT_NONE;
+
+        // Scan each registered token namespace
+        debugs(46, 9, HERE << "check for token in " << TheConfig.tokens.size() << " namespaces.");
+        for (std::list<TokenNamespace>::const_iterator itr = TheConfig.tokens.begin(); itr != TheConfig.tokens.end(); ++itr) {
+            debugs(46, 7, HERE << "check for possible " << itr->prefix << ":: token");
+            const size_t len = itr->prefix.size();
+            if (itr->prefix.cmp(cur, len) == 0 && cur[len] == ':' && cur[len+1] == ':') {
+                debugs(46, 5, HERE << "check for " << itr->prefix << ":: token in '" << cur << "'");
+                const char *old = cur;
+                cur = scanForToken(itr->tokenSet, cur+len+2);
+                if (old != cur) // found
+                    break;
+                else // reset to start of namespace
+                    cur = cur - len - 2;
+            }
         }
-        // finally scan for 1-char tokens.
+
         if (type == LFT_NONE) {
-            debugs(46, 5, HERE << "scan for possible 1C token");
-            cur = scanForToken(TokenTable1C, cur);
+            // For upward compatibility, assume "http::" prefix as default prefix
+            // for all log access formatting codes, except those starting with a
+            // "%" or a known namespace. (ie "icap::", "adapt::")
+            if (strncmp(cur,"http::", 6) == 0 && *(cur+6) != '%' )
+                cur += 6;
+
+            // NP: scan the sets of tokens in decreasing size to guarantee no
+            //     mistakes made with overlapping names. (Bug 3310)
+
+            // Scan for various long tokens
+            debugs(46, 5, HERE << "scan for possible Misc token");
+            cur = scanForToken(TokenTableMisc, cur);
+            // scan for 2-char tokens
+            if (type == LFT_NONE) {
+                debugs(46, 5, HERE << "scan for possible 2C token");
+                cur = scanForToken(TokenTable2C, cur);
+            }
+            // finally scan for 1-char tokens.
+            if (type == LFT_NONE) {
+                debugs(46, 5, HERE << "scan for possible 1C token");
+                cur = scanForToken(TokenTable1C, cur);
+            }
         }
-    }
 
-    if (type == LFT_NONE) {
-        fatalf("Can't parse configuration token: '%s'\n", def);
-    }
+        if (type == LFT_NONE) {
+            fatalf("Can't parse configuration token: '%s'\n", def);
+        }
 
-    if (*cur == ' ') {
-        space = true;
-        ++cur;
+        if (*cur == ' ') {
+            space = true;
+            ++cur;
+        }
     }
 
-done:
-
     switch (type) {
 
 #if USE_ADAPTATION