summaryrefslogtreecommitdiff
path: root/src/ContentTypeRequestGroupCriteria.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-09-22 23:19:41 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-09-22 23:19:41 +0900
commit461a542c5e236a22bb4edba3fae9610df4ba44c6 (patch)
tree47898cc7a938ff49866b8889095b651c54e3df3c /src/ContentTypeRequestGroupCriteria.cc
parent9d294741fd1bb469ed6be4e46af2f6521ce75054 (diff)
Rewritten DownloadHandlerConstants
DownloadHandlerConstants was simplified. MIME type handling in Accept header was also reworked. DownloadContext's metalinkServerContacted_ is replaced with acceptMetalink_ and its boolean value is reverted. RequestGroup and HttpRequest now do not hold vector of accepting types. HttpRequest has the flag acceptMetalink_ which will be set by the same value of DownloadContext::accpetMetalink_ and if it is true, Metalink MIME types are added to Accept header field.
Diffstat (limited to 'src/ContentTypeRequestGroupCriteria.cc')
-rw-r--r--src/ContentTypeRequestGroupCriteria.cc41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/ContentTypeRequestGroupCriteria.cc b/src/ContentTypeRequestGroupCriteria.cc
index 078ef7df..68cc7f07 100644
--- a/src/ContentTypeRequestGroupCriteria.cc
+++ b/src/ContentTypeRequestGroupCriteria.cc
@@ -34,8 +34,6 @@
/* copyright --> */
#include "ContentTypeRequestGroupCriteria.h"
-#include <algorithm>
-
#include "RequestGroup.h"
#include "util.h"
#include "FileEntry.h"
@@ -43,19 +41,13 @@
namespace aria2 {
-namespace {
-template<typename InputIterator>
-bool tailMatch
-(InputIterator first, InputIterator last, const std::string& target)
-{
- for(; first != last; ++first) {
- if(util::endsWith(target, *first)) {
- return true;
- }
- }
- return false;
-}
-} // namespace
+ContentTypeRequestGroupCriteria::ContentTypeRequestGroupCriteria
+(const char** contentTypes, const char** extensions)
+ : contentTypes_(contentTypes),
+ extensions_(extensions)
+{}
+
+ContentTypeRequestGroupCriteria::~ContentTypeRequestGroupCriteria() {}
bool ContentTypeRequestGroupCriteria::match
(const RequestGroup* requestGroup) const
@@ -63,15 +55,18 @@ bool ContentTypeRequestGroupCriteria::match
if(requestGroup->getDownloadContext()->getFileEntries().size() != 1) {
return false;
}
- if(tailMatch(extensions_.begin(), extensions_.end(),
- requestGroup->getFirstFilePath())) {
- return true;
- } else {
- return
- std::find(contentTypes_.begin(), contentTypes_.end(),
- requestGroup->getDownloadContext()->getFirstFileEntry()->
- getContentType()) != contentTypes_.end();
+ for(size_t i = 0; extensions_[i]; ++i) {
+ if(util::iendsWith(requestGroup->getFirstFilePath(), extensions_[i])) {
+ return true;
+ }
}
+ for(size_t i = 0; contentTypes_[i]; ++i) {
+ if(util::strieq(requestGroup->getDownloadContext()->getFirstFileEntry()->
+ getContentType(), contentTypes_[i])) {
+ return true;
+ }
+ }
+ return false;
}
} // namespace aria2