~ubuntu-branches/ubuntu/quantal/aria2/quantal

« back to all changes in this revision

Viewing changes to src/MetalinkPostDownloadHandler.cc

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry
  • Date: 2011-05-26 22:22:12 UTC
  • mfrom: (2.5.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110526222212-8ck4ia81l227m44l
Tags: 1.11.2-1
* New upstream release
* debian/control:
  + Updated Standards-Version to 3.9.2
* debian/copyright:
  + Updated as per latest DEP-5 specification

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 */
34
34
/* copyright --> */
35
35
#include "MetalinkPostDownloadHandler.h"
 
36
 
 
37
#include <deque>
 
38
 
36
39
#include "RequestGroup.h"
37
40
#include "Metalink2RequestGroup.h"
38
41
#include "Logger.h"
47
50
#include "DownloadContext.h"
48
51
#include "download_helper.h"
49
52
#include "fmt.h"
 
53
#include "FileEntry.h"
50
54
 
51
55
namespace aria2 {
52
56
 
63
67
 
64
68
MetalinkPostDownloadHandler::~MetalinkPostDownloadHandler() {}
65
69
 
 
70
namespace {
 
71
const std::string& getBaseUri(RequestGroup* requestGroup)
 
72
{
 
73
  const SharedHandle<DownloadContext>& dctx =
 
74
    requestGroup->getDownloadContext();
 
75
  if(dctx->getFileEntries().empty()) {
 
76
    return A2STR::NIL;
 
77
  } else {
 
78
    // TODO Check download result for each URI
 
79
    const SharedHandle<FileEntry>& entry = dctx->getFirstFileEntry();
 
80
    const std::deque<std::string>& spentUris = entry->getSpentUris();
 
81
    if(spentUris.empty()) {
 
82
      const std::deque<std::string>& remainingUris = entry->getRemainingUris();
 
83
      if(remainingUris.empty()) {
 
84
        return A2STR::NIL;
 
85
      } else {
 
86
        return remainingUris.front();
 
87
      }
 
88
    } else {
 
89
      return spentUris.back();
 
90
    }
 
91
  }
 
92
}
 
93
} // namespace
 
94
 
66
95
void MetalinkPostDownloadHandler::getNextRequestGroups
67
96
(std::vector<SharedHandle<RequestGroup> >& groups,
68
97
 RequestGroup* requestGroup)
74
103
  try {
75
104
    diskAdaptor->openExistingFile();
76
105
    //requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
 
106
    const std::string& baseUri = getBaseUri(requestGroup);
77
107
    std::vector<SharedHandle<RequestGroup> > newRgs;
78
108
    Metalink2RequestGroup().generate(newRgs, diskAdaptor,
79
 
                                     requestGroup->getOption());
 
109
                                     requestGroup->getOption(), baseUri);
80
110
    requestGroup->followedBy(newRgs.begin(), newRgs.end());
81
111
    SharedHandle<MetadataInfo> mi =
82
112
      createMetadataInfoFromFirstFileEntry(requestGroup->getDownloadContext());