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
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-12-04 11:12:56 +00:00
|
|
|
*
|
|
|
|
* 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 --> */
|
2010-10-31 07:23:53 +00:00
|
|
|
#ifndef D_METALINK_PARSER_STATE_MACHINE_H
|
|
|
|
#define D_METALINK_PARSER_STATE_MACHINE_H
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2011-11-10 13:38:01 +00:00
|
|
|
#include "ParserStateMachine.h"
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <string>
|
2010-02-25 14:40:18 +00:00
|
|
|
#include <vector>
|
2009-10-03 12:52:16 +00:00
|
|
|
#include <stack>
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2009-05-29 12:12:22 +00:00
|
|
|
#include "SharedHandle.h"
|
|
|
|
#include "MetalinkParserController.h"
|
2010-02-25 14:40:18 +00:00
|
|
|
#include "MetalinkParserState.h"
|
2009-05-29 12:12:22 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
class Metalinker;
|
|
|
|
|
2011-11-10 13:38:01 +00:00
|
|
|
class MetalinkParserStateMachine : public ParserStateMachine {
|
2007-12-04 11:12:56 +00:00
|
|
|
private:
|
2010-06-21 13:51:56 +00:00
|
|
|
SharedHandle<MetalinkParserController> ctrl_;
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
std::stack<MetalinkParserState*> stateStack_;
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-03-02 14:07:30 +00:00
|
|
|
// Error messages encountered while parsing document.
|
2010-06-21 13:51:56 +00:00
|
|
|
std::vector<std::string> errors_;
|
2010-03-02 14:07:30 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
static MetalinkParserState* initialState_;
|
|
|
|
static MetalinkParserState* skipTagState_;
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
// Metalink3
|
2010-06-21 13:51:56 +00:00
|
|
|
static MetalinkParserState* metalinkState_;
|
|
|
|
static MetalinkParserState* filesState_; // Metalink3Spec
|
|
|
|
static MetalinkParserState* fileState_;
|
|
|
|
static MetalinkParserState* sizeState_;
|
|
|
|
static MetalinkParserState* versionState_;
|
|
|
|
static MetalinkParserState* languageState_;
|
|
|
|
static MetalinkParserState* osState_;
|
|
|
|
static MetalinkParserState* verificationState_; // Metalink3Spec
|
|
|
|
static MetalinkParserState* hashState_;
|
|
|
|
static MetalinkParserState* piecesState_; // Metalink3Spec
|
|
|
|
static MetalinkParserState* pieceHashState_; // Metalink3Spec
|
|
|
|
static MetalinkParserState* signatureState_;
|
|
|
|
static MetalinkParserState* resourcesState_; // Metalink3Spec
|
|
|
|
static MetalinkParserState* urlState_;
|
2010-02-25 14:40:18 +00:00
|
|
|
|
|
|
|
// Metalink4
|
2010-06-21 13:51:56 +00:00
|
|
|
static MetalinkParserState* metalinkStateV4_;
|
|
|
|
static MetalinkParserState* fileStateV4_;
|
|
|
|
static MetalinkParserState* sizeStateV4_;
|
|
|
|
static MetalinkParserState* versionStateV4_;
|
|
|
|
static MetalinkParserState* languageStateV4_;
|
|
|
|
static MetalinkParserState* osStateV4_;
|
|
|
|
static MetalinkParserState* hashStateV4_;
|
|
|
|
static MetalinkParserState* piecesStateV4_; // Metalink4Spec
|
|
|
|
static MetalinkParserState* pieceHashStateV4_; // Metalink4Spec
|
|
|
|
static MetalinkParserState* signatureStateV4_;
|
|
|
|
static MetalinkParserState* urlStateV4_;
|
|
|
|
static MetalinkParserState* metaurlStateV4_;
|
2007-12-04 11:12:56 +00:00
|
|
|
public:
|
|
|
|
MetalinkParserStateMachine();
|
|
|
|
|
2011-11-10 13:38:01 +00:00
|
|
|
virtual ~MetalinkParserStateMachine();
|
|
|
|
|
|
|
|
virtual bool needsCharactersBuffering() const;
|
|
|
|
|
|
|
|
virtual bool finished() const;
|
|
|
|
|
|
|
|
virtual void beginElement
|
|
|
|
(const char* localname,
|
|
|
|
const char* prefix,
|
|
|
|
const char* nsUri,
|
|
|
|
const std::vector<XmlAttr>& attrs);
|
|
|
|
|
|
|
|
virtual void endElement
|
|
|
|
(const char* localname,
|
|
|
|
const char* prefix,
|
|
|
|
const char* nsUri,
|
|
|
|
const std::string& characters);
|
2010-11-14 07:17:55 +00:00
|
|
|
|
2012-07-12 15:53:56 +00:00
|
|
|
virtual void reset();
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setSkipTagState();
|
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
void setMetalinkState();
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setFilesState(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
void setFileState();
|
|
|
|
|
|
|
|
void setSizeState();
|
|
|
|
|
|
|
|
void setVersionState();
|
|
|
|
|
|
|
|
void setLanguageState();
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
void setOSState();
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setVerificationState(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
void setHashState();
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setPiecesState(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setPieceHashState(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-07-12 13:35:35 +00:00
|
|
|
void setSignatureState();
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setResourcesState(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
void setURLState();
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
// Metalink4
|
|
|
|
void setMetalinkStateV4();
|
|
|
|
void setFileStateV4();
|
|
|
|
void setSizeStateV4();
|
|
|
|
void setVersionStateV4();
|
|
|
|
void setLanguageStateV4();
|
|
|
|
void setOSStateV4();
|
|
|
|
void setHashStateV4();
|
|
|
|
void setPiecesStateV4(); // Metalink4Spec
|
|
|
|
void setPieceHashStateV4(); // Metalink4Spec
|
|
|
|
void setSignatureStateV4();
|
|
|
|
void setURLStateV4();
|
2010-02-25 16:00:24 +00:00
|
|
|
void setMetaurlStateV4();
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
void newEntryTransaction();
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setFileNameOfEntry(const std::string& filename);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2012-06-25 14:35:24 +00:00
|
|
|
void setFileLengthOfEntry(int64_t length);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setVersionOfEntry(const std::string& version);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setLanguageOfEntry(const std::string& language);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setOSOfEntry(const std::string& os);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setMaxConnectionsOfEntry(int maxConnections); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
void commitEntryTransaction();
|
|
|
|
|
2010-03-02 15:14:39 +00:00
|
|
|
void cancelEntryTransaction();
|
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
void newResourceTransaction();
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setURLOfResource(const std::string& url);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setTypeOfResource(const std::string& type);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setLocationOfResource(const std::string& location);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setPriorityOfResource(int priority);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setMaxConnectionsOfResource(int maxConnections); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
void commitResourceTransaction();
|
|
|
|
|
|
|
|
void cancelResourceTransaction();
|
|
|
|
|
|
|
|
void newChecksumTransaction();
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setTypeOfChecksum(const std::string& type);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void setHashOfChecksum(const std::string& md);
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
void commitChecksumTransaction();
|
|
|
|
|
|
|
|
void cancelChecksumTransaction();
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void newChunkChecksumTransactionV4(); // Metalink4Spec
|
|
|
|
|
|
|
|
void setLengthOfChunkChecksumV4(size_t length); // Metalink4Spec
|
|
|
|
|
|
|
|
void setTypeOfChunkChecksumV4(const std::string& type); // Metalink4Spec
|
|
|
|
|
|
|
|
void addHashOfChunkChecksumV4(const std::string& md); // Metalink4Spec
|
|
|
|
|
|
|
|
void commitChunkChecksumTransactionV4(); // Metalink4Spec
|
|
|
|
|
|
|
|
void cancelChunkChecksumTransactionV4(); // Metalink4Spec
|
|
|
|
|
|
|
|
void newChunkChecksumTransaction(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setLengthOfChunkChecksum(size_t length); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setTypeOfChunkChecksum(const std::string& type); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void createNewHashOfChunkChecksum(size_t order); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void setMessageDigestOfChunkChecksum(const std::string& md); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void addHashOfChunkChecksum(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void commitChunkChecksumTransaction(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void cancelChunkChecksumTransaction(); // Metalink3Spec
|
2007-12-04 11:12:56 +00:00
|
|
|
|
2008-07-12 13:35:35 +00:00
|
|
|
void newSignatureTransaction();
|
|
|
|
|
|
|
|
void setTypeOfSignature(const std::string& type);
|
|
|
|
|
|
|
|
void setFileOfSignature(const std::string& file);
|
|
|
|
|
|
|
|
void setBodyOfSignature(const std::string& body);
|
|
|
|
|
|
|
|
void commitSignatureTransaction();
|
|
|
|
|
|
|
|
void cancelSignatureTransaction();
|
|
|
|
|
2010-02-25 16:00:24 +00:00
|
|
|
void newMetaurlTransaction();
|
|
|
|
|
|
|
|
void setURLOfMetaurl(const std::string& url);
|
|
|
|
|
|
|
|
void setMediatypeOfMetaurl(const std::string& mediatype);
|
|
|
|
|
|
|
|
void setPriorityOfMetaurl(int priority);
|
|
|
|
|
2010-02-26 08:55:10 +00:00
|
|
|
void setNameOfMetaurl(const std::string& name);
|
|
|
|
|
2010-02-25 16:00:24 +00:00
|
|
|
void commitMetaurlTransaction();
|
|
|
|
|
|
|
|
void cancelMetaurlTransaction();
|
|
|
|
|
2010-03-02 14:07:30 +00:00
|
|
|
// Only stores first 10 errors.
|
|
|
|
void logError(const std::string& log);
|
|
|
|
|
|
|
|
const std::vector<std::string>& getErrors() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return errors_;
|
2010-03-02 14:07:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string getErrorString() const;
|
|
|
|
|
2009-05-29 12:12:22 +00:00
|
|
|
const SharedHandle<Metalinker>& getResult() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return ctrl_->getResult();
|
2009-05-29 12:12:22 +00:00
|
|
|
}
|
2011-05-07 09:41:18 +00:00
|
|
|
|
|
|
|
void setBaseUri(const std::string& uri);
|
2007-12-04 11:12:56 +00:00
|
|
|
};
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|
|
|
|
|
2010-10-31 07:23:53 +00:00
|
|
|
#endif // D_METALINK_PARSER_STATE_MACHINE_H
|