2007-12-04 11:12:56 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "MetalinkParserStateMachine.h"
|
|
|
|
#include "MetalinkParserController.h"
|
|
|
|
#include "InitialMetalinkParserState.h"
|
|
|
|
#include "MetalinkMetalinkParserState.h"
|
|
|
|
#include "FilesMetalinkParserState.h"
|
|
|
|
#include "FileMetalinkParserState.h"
|
|
|
|
#include "SizeMetalinkParserState.h"
|
|
|
|
#include "VersionMetalinkParserState.h"
|
|
|
|
#include "LanguageMetalinkParserState.h"
|
|
|
|
#include "OSMetalinkParserState.h"
|
|
|
|
#include "VerificationMetalinkParserState.h"
|
|
|
|
#include "HashMetalinkParserState.h"
|
|
|
|
#include "PiecesMetalinkParserState.h"
|
|
|
|
#include "PieceHashMetalinkParserState.h"
|
|
|
|
#include "ResourcesMetalinkParserState.h"
|
|
|
|
#include "URLMetalinkParserState.h"
|
|
|
|
#include "FinMetalinkParserState.h"
|
|
|
|
#include "SkipTagMetalinkParserState.h"
|
|
|
|
#include "Metalinker.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "MetalinkEntry.h"
|
|
|
|
|
|
|
|
namespace aria2 {
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_initialState = new InitialMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_metalinkState = new MetalinkMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_filesState = new FilesMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_fileState = new FileMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_sizeState = new SizeMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_versionState = new VersionMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_languageState = new LanguageMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_osState = new OSMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_verificationState = new VerificationMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_hashState = new HashMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_piecesState = new PiecesMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_pieceHashState = new PieceHashMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_resourcesState = new ResourcesMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_urlState = new URLMetalinkParserState();
|
|
|
|
MetalinkParserState* MetalinkParserStateMachine::_finState = new FinMetalinkParserState();
|
|
|
|
|
|
|
|
MetalinkParserStateMachine::MetalinkParserStateMachine():
|
|
|
|
_ctrl(new MetalinkParserController()),
|
|
|
|
_state(_initialState),
|
|
|
|
_skipTagState(0) {}
|
|
|
|
|
|
|
|
MetalinkParserStateMachine::~MetalinkParserStateMachine()
|
|
|
|
{
|
|
|
|
delete _skipTagState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setMetalinkState()
|
|
|
|
{
|
|
|
|
_state = _metalinkState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setFilesState()
|
|
|
|
{
|
|
|
|
_state = _filesState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setFileState()
|
|
|
|
{
|
|
|
|
_state = _fileState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setSizeState()
|
|
|
|
{
|
|
|
|
_state = _sizeState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setVersionState()
|
|
|
|
{
|
|
|
|
_state = _versionState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setLanguageState()
|
|
|
|
{
|
|
|
|
_state = _languageState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setOSState()
|
|
|
|
{
|
|
|
|
_state = _osState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setVerificationState()
|
|
|
|
{
|
|
|
|
_state = _verificationState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setHashState()
|
|
|
|
{
|
|
|
|
_state = _hashState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setPiecesState()
|
|
|
|
{
|
|
|
|
_state = _piecesState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setPieceHashState()
|
|
|
|
{
|
|
|
|
_state = _pieceHashState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setResourcesState()
|
|
|
|
{
|
|
|
|
_state = _resourcesState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setURLState()
|
|
|
|
{
|
|
|
|
_state = _urlState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setFinState()
|
|
|
|
{
|
|
|
|
_state = _finState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::setSkipTagState(MetalinkParserState* prevSate)
|
|
|
|
{
|
|
|
|
_state = new SkipTagMetalinkParserState(prevSate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::restoreSavedState()
|
|
|
|
{
|
|
|
|
_state = ((SkipTagMetalinkParserState*)_state)->getPreviousState();
|
|
|
|
delete _skipTagState;
|
|
|
|
_skipTagState = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetalinkParserStateMachine::finished() const
|
|
|
|
{
|
|
|
|
return _state == _finState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::newEntryTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->newEntryTransaction();
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setFileNameOfEntry(const std::string& filename)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setFileNameOfEntry(filename);
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserStateMachine::setFileLengthOfEntry(uint64_t length)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setFileLengthOfEntry(length);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setVersionOfEntry(const std::string& version)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setVersionOfEntry(version);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setLanguageOfEntry(const std::string& language)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setLanguageOfEntry(language);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setOSOfEntry(const std::string& os)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setOSOfEntry(os);
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserStateMachine::setMaxConnectionsOfEntry(int maxConnections)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setMaxConnectionsOfEntry(maxConnections);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::commitEntryTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->commitEntryTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::newResourceTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->newResourceTransaction();
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setURLOfResource(const std::string& url)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setURLOfResource(url);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setTypeOfResource(const std::string& type)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setTypeOfResource(type);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setLocationOfResource(const std::string& location)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setLocationOfResource(location);
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserStateMachine::setPreferenceOfResource(int preference)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setPreferenceOfResource(preference);
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserStateMachine::setMaxConnectionsOfResource(int maxConnections)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setMaxConnectionsOfResource(maxConnections);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::commitResourceTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->commitResourceTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::cancelResourceTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->cancelResourceTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::newChecksumTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->newChecksumTransaction();
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setTypeOfChecksum(const std::string& type)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setTypeOfChecksum(type);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setHashOfChecksum(const std::string& md)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setHashOfChecksum(md);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::commitChecksumTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->commitChecksumTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::cancelChecksumTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->cancelChecksumTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::newChunkChecksumTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->newChunkChecksumTransaction();
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserStateMachine::setLengthOfChunkChecksum(size_t length)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setLengthOfChunkChecksum(length);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setTypeOfChunkChecksum(const std::string& type)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setTypeOfChunkChecksum(type);
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserStateMachine::createNewHashOfChunkChecksum(size_t order)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->createNewHashOfChunkChecksum(order);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::setMessageDigestOfChunkChecksum(const std::string& md)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_ctrl->setMessageDigestOfChunkChecksum(md);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::addHashOfChunkChecksum()
|
|
|
|
{
|
|
|
|
_ctrl->addHashOfChunkChecksum();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::commitChunkChecksumTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->commitChunkChecksumTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserStateMachine::cancelChunkChecksumTransaction()
|
|
|
|
{
|
|
|
|
_ctrl->cancelChunkChecksumTransaction();
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::beginElement(const std::string& name,
|
|
|
|
const std::map<std::string, std::string>& attrs)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_state->beginElement(this, name, attrs);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserStateMachine::endElement(const std::string& name, const std::string& characters)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
_state->endElement(this, name, characters);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Metalinker> MetalinkParserStateMachine::getResult() const
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
return _ctrl->getResult();
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|