MetalinkParserStateMachine.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef _D_METALINK_PARSER_STATE_MACHINE_H_
  36. #define _D_METALINK_PARSER_STATE_MACHINE_H_
  37. #include "common.h"
  38. #include <string>
  39. #include <vector>
  40. #include <stack>
  41. #include "SharedHandle.h"
  42. #include "MetalinkParserController.h"
  43. #include "MetalinkParserState.h"
  44. namespace aria2 {
  45. class Metalinker;
  46. class MetalinkParserStateMachine {
  47. private:
  48. SharedHandle<MetalinkParserController> _ctrl;
  49. std::stack<MetalinkParserState*> _stateStack;
  50. static MetalinkParserState* _initialState;
  51. static MetalinkParserState* _skipTagState;
  52. // Metalink3
  53. static MetalinkParserState* _metalinkState;
  54. static MetalinkParserState* _filesState; // Metalink3Spec
  55. static MetalinkParserState* _fileState;
  56. static MetalinkParserState* _sizeState;
  57. static MetalinkParserState* _versionState;
  58. static MetalinkParserState* _languageState;
  59. static MetalinkParserState* _osState;
  60. static MetalinkParserState* _verificationState; // Metalink3Spec
  61. static MetalinkParserState* _hashState;
  62. static MetalinkParserState* _piecesState; // Metalink3Spec
  63. static MetalinkParserState* _pieceHashState; // Metalink3Spec
  64. static MetalinkParserState* _signatureState;
  65. static MetalinkParserState* _resourcesState; // Metalink3Spec
  66. static MetalinkParserState* _urlState;
  67. // Metalink4
  68. static MetalinkParserState* _metalinkStateV4;
  69. static MetalinkParserState* _fileStateV4;
  70. static MetalinkParserState* _sizeStateV4;
  71. static MetalinkParserState* _versionStateV4;
  72. static MetalinkParserState* _languageStateV4;
  73. static MetalinkParserState* _osStateV4;
  74. static MetalinkParserState* _hashStateV4;
  75. static MetalinkParserState* _piecesStateV4; // Metalink4Spec
  76. static MetalinkParserState* _pieceHashStateV4; // Metalink4Spec
  77. static MetalinkParserState* _signatureStateV4;
  78. static MetalinkParserState* _urlStateV4;
  79. static MetalinkParserState* _metaurlStateV4;
  80. public:
  81. MetalinkParserStateMachine();
  82. void setSkipTagState();
  83. void setMetalinkState();
  84. void setFilesState(); // Metalink3Spec
  85. void setFileState();
  86. void setSizeState();
  87. void setVersionState();
  88. void setLanguageState();
  89. void setOSState();
  90. void setVerificationState(); // Metalink3Spec
  91. void setHashState();
  92. void setPiecesState(); // Metalink3Spec
  93. void setPieceHashState(); // Metalink3Spec
  94. void setSignatureState();
  95. void setResourcesState(); // Metalink3Spec
  96. void setURLState();
  97. // Metalink4
  98. void setMetalinkStateV4();
  99. void setFileStateV4();
  100. void setSizeStateV4();
  101. void setVersionStateV4();
  102. void setLanguageStateV4();
  103. void setOSStateV4();
  104. void setHashStateV4();
  105. void setPiecesStateV4(); // Metalink4Spec
  106. void setPieceHashStateV4(); // Metalink4Spec
  107. void setSignatureStateV4();
  108. void setURLStateV4();
  109. void setMetaurlStateV4();
  110. bool finished() const;
  111. void beginElement
  112. (const std::string& localname,
  113. const std::string& prefix,
  114. const std::string& nsUri,
  115. const std::vector<XmlAttr>& attrs);
  116. void endElement
  117. (const std::string& localname,
  118. const std::string& prefix,
  119. const std::string& nsUri,
  120. const std::string& characters);
  121. void newEntryTransaction();
  122. void setFileNameOfEntry(const std::string& filename);
  123. void setFileLengthOfEntry(uint64_t length);
  124. void setVersionOfEntry(const std::string& version);
  125. void setLanguageOfEntry(const std::string& language);
  126. void setOSOfEntry(const std::string& os);
  127. void setMaxConnectionsOfEntry(int maxConnections); // Metalink3Spec
  128. void commitEntryTransaction();
  129. void newResourceTransaction();
  130. void setURLOfResource(const std::string& url);
  131. void setTypeOfResource(const std::string& type);
  132. void setLocationOfResource(const std::string& location);
  133. void setPriorityOfResource(int priority);
  134. void setMaxConnectionsOfResource(int maxConnections); // Metalink3Spec
  135. void commitResourceTransaction();
  136. void cancelResourceTransaction();
  137. void newChecksumTransaction();
  138. void setTypeOfChecksum(const std::string& type);
  139. void setHashOfChecksum(const std::string& md);
  140. void commitChecksumTransaction();
  141. void cancelChecksumTransaction();
  142. void newChunkChecksumTransactionV4(); // Metalink4Spec
  143. void setLengthOfChunkChecksumV4(size_t length); // Metalink4Spec
  144. void setTypeOfChunkChecksumV4(const std::string& type); // Metalink4Spec
  145. void addHashOfChunkChecksumV4(const std::string& md); // Metalink4Spec
  146. void commitChunkChecksumTransactionV4(); // Metalink4Spec
  147. void cancelChunkChecksumTransactionV4(); // Metalink4Spec
  148. void newChunkChecksumTransaction(); // Metalink3Spec
  149. void setLengthOfChunkChecksum(size_t length); // Metalink3Spec
  150. void setTypeOfChunkChecksum(const std::string& type); // Metalink3Spec
  151. void createNewHashOfChunkChecksum(size_t order); // Metalink3Spec
  152. void setMessageDigestOfChunkChecksum(const std::string& md); // Metalink3Spec
  153. void addHashOfChunkChecksum(); // Metalink3Spec
  154. void commitChunkChecksumTransaction(); // Metalink3Spec
  155. void cancelChunkChecksumTransaction(); // Metalink3Spec
  156. void newSignatureTransaction();
  157. void setTypeOfSignature(const std::string& type);
  158. void setFileOfSignature(const std::string& file);
  159. void setBodyOfSignature(const std::string& body);
  160. void commitSignatureTransaction();
  161. void cancelSignatureTransaction();
  162. void newMetaurlTransaction();
  163. void setURLOfMetaurl(const std::string& url);
  164. void setMediatypeOfMetaurl(const std::string& mediatype);
  165. void setPriorityOfMetaurl(int priority);
  166. void commitMetaurlTransaction();
  167. void cancelMetaurlTransaction();
  168. bool needsCharactersBuffering() const;
  169. const SharedHandle<Metalinker>& getResult() const
  170. {
  171. return _ctrl->getResult();
  172. }
  173. };
  174. } // namespace aria2
  175. #endif // _D_METALINK_PARSER_STATE_MACHINE_H_