diff options
author | erikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-30 13:28:44 +0000 |
---|---|---|
committer | erikwright@chromium.org <erikwright@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-30 13:28:44 +0000 |
commit | e3fe59bfb0912596e8975f9c50b01683c19ee5d9 (patch) | |
tree | 04b9c722b6f9db105acfc70bd286cb4f78c7d843 /net/http/http_auth.cc | |
parent | d1cd0715ae8b15982b7ca46f4497eeddb4b73bca (diff) | |
download | chromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.zip chromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.tar.gz chromium_src-e3fe59bfb0912596e8975f9c50b01683c19ee5d9.tar.bz2 |
Extract name-value pair parsing from http_auth.cc (ChallengeTokenizer) into http_util.cc (NameValuePairsIterator). In preparation for re-use of name-value pair parsing in ChromeFrame (for X-UA-Compatible header).
BUG=None
TEST=net_unittests (HttpAuth* and HttpUtilTest.NameValuePairs*)
Review URL: http://codereview.chromium.org/3525004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61061 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth.cc')
-rw-r--r-- | net/http/http_auth.cc | 79 |
1 files changed, 18 insertions, 61 deletions
diff --git a/net/http/http_auth.cc b/net/http/http_auth.cc index debcca7..fe7005a 100644 --- a/net/http/http_auth.cc +++ b/net/http/http_auth.cc @@ -88,7 +88,7 @@ void HttpAuth::ChallengeTokenizer::Init(std::string::const_iterator begin, // is separated by 1*SP. StringTokenizer tok(begin, end, HTTP_LWS); if (!tok.GetNext()) { - valid_ = false; + // Default param and scheme iterators provide empty strings return; } @@ -96,70 +96,27 @@ void HttpAuth::ChallengeTokenizer::Init(std::string::const_iterator begin, scheme_begin_ = tok.token_begin(); scheme_end_ = tok.token_end(); - // Everything past scheme_end_ is a (comma separated) value list. - props_ = HttpUtil::ValuesIterator(scheme_end_, end, ','); + params_begin_ = scheme_end_; + params_end_ = end; + HttpUtil::TrimLWS(¶ms_begin_, ¶ms_end_); } -// We expect properties to be formatted as one of: -// name="value" -// name=value -// name= -// Due to buggy implementations found in some embedded devices, we also -// accept values with missing close quotemark (http://crbug.com/39836): -// name="value -bool HttpAuth::ChallengeTokenizer::GetNext() { - if (!props_.GetNext()) - return false; - - // Set the value as everything. Next we will split out the name. - value_begin_ = props_.value_begin(); - value_end_ = props_.value_end(); - name_begin_ = name_end_ = value_end_; - - if (expect_base64_token_) { - expect_base64_token_ = false; - // Strip off any padding. - // (See https://bugzilla.mozilla.org/show_bug.cgi?id=230351.) - // - // Our base64 decoder requires that the length be a multiple of 4. - int encoded_length = value_end_ - value_begin_; - while (encoded_length > 0 && encoded_length % 4 != 0 && - value_begin_[encoded_length - 1] == '=') { - --encoded_length; - --value_end_; - } - return true; - } - - // Scan for the equals sign. - std::string::const_iterator equals = std::find(value_begin_, value_end_, '='); - if (equals == value_end_ || equals == value_begin_) - return valid_ = false; // Malformed - - // Verify that the equals sign we found wasn't inside of quote marks. - for (std::string::const_iterator it = value_begin_; it != equals; ++it) { - if (HttpUtil::IsQuote(*it)) - return valid_ = false; // Malformed - } - - name_begin_ = value_begin_; - name_end_ = equals; - value_begin_ = equals + 1; - - value_is_quoted_ = false; - if (value_begin_ != value_end_ && HttpUtil::IsQuote(*value_begin_)) { - // Trim surrounding quotemarks off the value - if (*value_begin_ != *(value_end_ - 1) || value_begin_ + 1 == value_end_) - value_begin_ = equals + 2; // Gracefully recover from mismatching quotes. - else - value_is_quoted_ = true; - } - return true; +HttpUtil::NameValuePairsIterator HttpAuth::ChallengeTokenizer::param_pairs() + const { + return HttpUtil::NameValuePairsIterator(params_begin_, params_end_, ','); } -// If value() has quotemarks, unquote it. -std::string HttpAuth::ChallengeTokenizer::unquoted_value() const { - return HttpUtil::Unquote(value_begin_, value_end_); +std::string HttpAuth::ChallengeTokenizer::base64_param() const { + // Strip off any padding. + // (See https://bugzilla.mozilla.org/show_bug.cgi?id=230351.) + // + // Our base64 decoder requires that the length be a multiple of 4. + int encoded_length = params_end_ - params_begin_; + while (encoded_length > 0 && encoded_length % 4 != 0 && + params_begin_[encoded_length - 1] == '=') { + --encoded_length; + } + return std::string(params_begin_, params_begin_ + encoded_length); } // static |