Added relative URI support to ExpatMetalinkProcessor

pull/1/head
Tatsuhiro Tsujikawa 2011-05-16 01:37:19 +09:00
parent f6625f8dc5
commit c9fe4c64f5
2 changed files with 21 additions and 7 deletions

View File

@ -177,20 +177,25 @@ void checkError(XML_Parser parser)
} // namespace
SharedHandle<Metalinker>
MetalinkProcessor::parseFile(const std::string& filename)
MetalinkProcessor::parseFile
(const std::string& filename,
const std::string& baseUri)
{
if(filename == DEV_STDIN) {
return parseFile(std::cin);
} else {
std::ifstream infile(filename.c_str(), std::ios::binary);
return parseFile(infile);
return parseFile(infile, baseUri);
}
}
SharedHandle<Metalinker>
MetalinkProcessor::parseFile(std::istream& stream)
MetalinkProcessor::parseFile
(std::istream& stream,
const std::string& baseUri)
{
stm_.reset(new MetalinkParserStateMachine());
stm_->setBaseUri(baseUri);
char buf[4096];
SharedHandle<SessionData> sessionData(new SessionData(stm_));
@ -212,9 +217,12 @@ MetalinkProcessor::parseFile(std::istream& stream)
}
SharedHandle<Metalinker>
MetalinkProcessor::parseFromBinaryStream(const SharedHandle<BinaryStream>& binaryStream)
MetalinkProcessor::parseFromBinaryStream
(const SharedHandle<BinaryStream>& binaryStream,
const std::string& baseUri)
{
stm_.reset(new MetalinkParserStateMachine());
stm_->setBaseUri(baseUri);
ssize_t bufSize = 4096;
unsigned char buf[bufSize];

View File

@ -42,6 +42,7 @@
#include <expat.h>
#include "SharedHandle.h"
#include "A2STR.h"
namespace aria2 {
@ -53,12 +54,17 @@ class MetalinkProcessor {
private:
SharedHandle<MetalinkParserStateMachine> stm_;
public:
SharedHandle<Metalinker> parseFile(const std::string& filename);
SharedHandle<Metalinker> parseFile
(const std::string& filename,
const std::string& baseUri = A2STR::NIL);
SharedHandle<Metalinker> parseFile(std::istream& stream);
SharedHandle<Metalinker> parseFile
(std::istream& stream,
const std::string& baseUri = A2STR::NIL);
SharedHandle<Metalinker> parseFromBinaryStream
(const SharedHandle<BinaryStream>& binaryStream);
(const SharedHandle<BinaryStream>& binaryStream,
const std::string& baseUri = A2STR::NIL);
};
} // namespace aria2