2008-02-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Fixed compilation error
	* src/ExpatMetalinkProcessor.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-02-27 15:04:42 +00:00
parent f9afa5eeac
commit c1fd47809d
2 changed files with 27 additions and 16 deletions

View File

@ -1,3 +1,8 @@
2008-02-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed compilation error
* src/ExpatMetalinkProcessor.cc
2008-02-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-02-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed compile error on Mac OS X, on 64Bit OS maybe. Fixed compile error on Mac OS X, on 64Bit OS maybe.

View File

@ -33,35 +33,37 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "ExpatMetalinkProcessor.h" #include "ExpatMetalinkProcessor.h"
#include "BinaryStream.h" #include "DefaultDiskWriter.h"
#include "MetalinkParserStateMachine.h" #include "MetalinkParserStateMachine.h"
#include "Metalinker.h"
#include "MetalinkEntry.h"
#include "Util.h" #include "Util.h"
#include "message.h" #include "message.h"
#include "DefaultDiskWriter.h" #include "DlAbortEx.h"
namespace aria2 {
class SessionData { class SessionData {
public: public:
MetalinkParserStateMachineHandle _stm; SharedHandle<MetalinkParserStateMachine> _stm;
Strings _charactersStack; std::deque<std::string> _charactersStack;
SessionData(const MetalinkParserStateMachineHandle& stm):_stm(stm) {} SessionData(const SharedHandle<MetalinkParserStateMachine>& stm):_stm(stm) {}
}; };
typedef SharedHandle<SessionData> SessionDataHandle;
static void mlStartElement(void* userData, const char* name, const char** attrs) static void mlStartElement(void* userData, const char* name, const char** attrs)
{ {
((SessionData*)userData)->_charactersStack.push_front(string()); ((SessionData*)userData)->_charactersStack.push_front(std::string());
map<string, string> attrmap; std::map<std::string, std::string> attrmap;
if(attrs) { if(attrs) {
const char** p = attrs; const char** p = attrs;
while(*p != 0) { while(*p != 0) {
string name = *p++; std::string name = *p++;
if(*p == 0) { if(*p == 0) {
break; break;
} }
string value = Util::trim(*p++); std::string value = Util::trim(*p++);
attrmap[name] = value; attrmap[name] = value;
} }
} }
@ -78,7 +80,7 @@ static void mlEndElement(void* userData, const char* name)
static void mlCharacters(void* userData, const char* ch, int len) static void mlCharacters(void* userData, const char* ch, int len)
{ {
((SessionData*)userData)->_charactersStack.front() += string(&ch[0], &ch[len]); ((SessionData*)userData)->_charactersStack.front() += std::string(&ch[0], &ch[len]);
} }
ExpatMetalinkProcessor::ExpatMetalinkProcessor(): ExpatMetalinkProcessor::ExpatMetalinkProcessor():
@ -86,21 +88,23 @@ ExpatMetalinkProcessor::ExpatMetalinkProcessor():
{} {}
MetalinkerHandle ExpatMetalinkProcessor::parseFile(const string& filename) SharedHandle<Metalinker>
ExpatMetalinkProcessor::parseFile(const std::string& filename)
{ {
DefaultDiskWriterHandle dw = new DefaultDiskWriter(); SharedHandle<DefaultDiskWriter> dw = new DefaultDiskWriter();
dw->openExistingFile(filename); dw->openExistingFile(filename);
return parseFromBinaryStream(dw); return parseFromBinaryStream(dw);
} }
MetalinkerHandle ExpatMetalinkProcessor::parseFromBinaryStream(const BinaryStreamHandle& binaryStream) SharedHandle<Metalinker>
ExpatMetalinkProcessor::parseFromBinaryStream(const SharedHandle<BinaryStream>& binaryStream)
{ {
_stm = new MetalinkParserStateMachine(); _stm = new MetalinkParserStateMachine();
int32_t bufSize = 4096; int32_t bufSize = 4096;
unsigned char buf[bufSize]; unsigned char buf[bufSize];
SessionDataHandle sessionData = new SessionData(_stm); SharedHandle<SessionData> sessionData = new SessionData(_stm);
XML_Parser parser = XML_ParserCreate(0); XML_Parser parser = XML_ParserCreate(0);
try { try {
XML_SetUserData(parser, sessionData.get()); XML_SetUserData(parser, sessionData.get());
@ -131,3 +135,5 @@ MetalinkerHandle ExpatMetalinkProcessor::parseFromBinaryStream(const BinaryStrea
} }
return _stm->getResult(); return _stm->getResult();
} }
} // namespace aria2