------------------------------------------------------------ revno: 13544 revision-id: squid3@treenet.co.nz-20140823111732-cftwfc0gzujwiokc parent: squid3@treenet.co.nz-20140823110540-dyjakp0otgwitqol committer: Amos Jeffries branch nick: trunk timestamp: Sat 2014-08-23 04:17:32 -0700 message: Cleanup: remove goto from logformat token parser ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140823111732-cftwfc0gzujwiokc # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 2a15ac3296b04de43d751678654cd04a84e7e6c8 # timestamp: 2014-08-23 11:54:09 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20140823110540-\ # dyjakp0otgwitqol # # Begin patch === modified file 'src/format/Token.cc' --- src/format/Token.cc 2014-05-08 10:17:41 +0000 +++ src/format/Token.cc 2014-08-23 11:17:32 +0000 @@ -271,129 +271,124 @@ --l; } - goto done; - } - - if (!*cur) - goto done; - - ++cur; - - // select quoting style for his particular token - switch (*cur) { - - case '"': - quote = LOG_QUOTE_QUOTES; - ++cur; - break; - - case '\'': - quote = LOG_QUOTE_RAW; - ++cur; - break; - - case '[': - quote = LOG_QUOTE_MIMEBLOB; - ++cur; - break; - - case '#': - quote = LOG_QUOTE_URL; - ++cur; - break; - - default: - quote = *quoting; - break; - } - - if (*cur == '-') { - left = true; - ++cur; - } - - if (*cur == '0') { - zero = true; - ++cur; - } - - char *endp; - if (xisdigit(*cur)) { - widthMin = strtol(cur, &endp, 10); - cur = endp; - } - - if (*cur == '.' && xisdigit(*(++cur))) { - widthMax = strtol(cur, &endp, 10); - cur = endp; - } - - 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; - } - - type = LFT_NONE; - - // Scan each registered token namespace - debugs(46, 9, HERE << "check for token in " << TheConfig.tokens.size() << " namespaces."); - for (std::list::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; - } - } - - 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; - - // 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 (*cur == ' ') { - space = true; - ++cur; - } - -done: + } else if (*cur) { + + ++cur; + + // select quoting style for his particular token + switch (*cur) { + + case '"': + quote = LOG_QUOTE_QUOTES; + ++cur; + break; + + case '\'': + quote = LOG_QUOTE_RAW; + ++cur; + break; + + case '[': + quote = LOG_QUOTE_MIMEBLOB; + ++cur; + break; + + case '#': + quote = LOG_QUOTE_URL; + ++cur; + break; + + default: + quote = *quoting; + break; + } + + if (*cur == '-') { + left = true; + ++cur; + } + + if (*cur == '0') { + zero = true; + ++cur; + } + + char *endp; + if (xisdigit(*cur)) { + widthMin = strtol(cur, &endp, 10); + cur = endp; + } + + if (*cur == '.' && xisdigit(*(++cur))) { + widthMax = strtol(cur, &endp, 10); + cur = endp; + } + + 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; + } + + type = LFT_NONE; + + // Scan each registered token namespace + debugs(46, 9, HERE << "check for token in " << TheConfig.tokens.size() << " namespaces."); + for (std::list::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; + } + } + + 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; + + // 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 (*cur == ' ') { + space = true; + ++cur; + } + } switch (type) {