diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-07-27 19:32:35 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-07-27 19:32:35 +0900 |
| commit | 67e91c3431a4c89a76093e33cd121f89f5550fb7 (patch) | |
| tree | 50f6035024bd43716bf19a5e30c720bee5197e40 /src/HttpResponse.cc | |
| parent | 7c317de4e74a73e8ce55585f69bba6d4db5e6899 (diff) | |
HttpResponse::getDigest() now returns all Digest.
In addition, HttpResponse::getMetalinkHttpEntries() does not check
validity of URI. It is checked when we add it to FileEntry.
Diffstat (limited to 'src/HttpResponse.cc')
| -rw-r--r-- | src/HttpResponse.cc | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index 17313732..da637798 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -306,12 +306,11 @@ bool parseMetalinkHttpLink(MetalinkHttpEntry& result, const std::string& s) if(last == s.end()) { return false; } - std::string uri(first+1, last); - uri::UriStruct us; - if(uri::parse(us, uri)) { - result.uri = uri; - } else { + std::string uri = util::stripIter(first+1, last); + if(uri.empty()) { return false; + } else { + result.uri = uri; } last = std::find(last, s.end(), ';'); if(last != s.end()) { @@ -388,9 +387,9 @@ void HttpResponse::getMetalinKHttpEntries #ifdef ENABLE_MESSAGE_DIGEST // Digest header field is defined by // http://tools.ietf.org/html/rfc3230. -SharedHandle<Checksum> HttpResponse::getDigest() const +void HttpResponse::getDigest(std::vector<Checksum>& result) const { - SharedHandle<Checksum> res; + using std::swap; std::pair<std::multimap<std::string, std::string>::const_iterator, std::multimap<std::string, std::string>::const_iterator> p = httpHeader_->getIterator(HttpHeader::DIGEST); @@ -413,15 +412,29 @@ SharedHandle<Checksum> HttpResponse::getDigest() const if(!MessageDigest::isValidHash(hashType, hexDigest)) { continue; } - if(!res) { - res.reset(new Checksum(hashType, hexDigest)); - } else if(MessageDigest::isStronger(hashType, res->getAlgo())) { - res->setAlgo(hashType); - res->setMessageDigest(hexDigest); + result.push_back(Checksum(hashType, hexDigest)); + } + } + std::sort(result.begin(), result.end(), HashTypeStronger()); + std::vector<Checksum> temp; + for(std::vector<Checksum>::iterator i = result.begin(), + eoi = result.end(); i != eoi;) { + bool ok = true; + std::vector<Checksum>::iterator j = i+1; + for(; j != eoi; ++j) { + if((*i).getAlgo() != (*j).getAlgo()) { + break; } + if((*i).getMessageDigest() != (*j).getMessageDigest()) { + ok = false; + } + } + if(ok) { + temp.push_back(*i); } + i = j; } - return res; + swap(temp, result); } #endif // ENABLE_MESSAGE_DIGEST |
