MetalinkParserStateMachine.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. // Error messages encountered while parsing document.
  51. std::vector<std::string> errors_;
  52. static MetalinkParserState* initialState_;
  53. static MetalinkParserState* skipTagState_;
  54. // Metalink3
  55. static MetalinkParserState* metalinkState_;
  56. static MetalinkParserState* filesState_; // Metalink3Spec
  57. static MetalinkParserState* fileState_;
  58. static MetalinkParserState* sizeState_;
  59. static MetalinkParserState* versionState_;
  60. static MetalinkParserState* languageState_;
  61. static MetalinkParserState* osState_;
  62. static MetalinkParserState* verificationState_; // Metalink3Spec
  63. static MetalinkParserState* hashState_;
  64. static MetalinkParserState* piecesState_; // Metalink3Spec
  65. static MetalinkParserState* pieceHashState_; // Metalink3Spec
  66. static MetalinkParserState* signatureState_;
  67. static MetalinkParserState* resourcesState_; // Metalink3Spec
  68. static MetalinkParserState* urlState_;
  69. // Metalink4
  70. static MetalinkParserState* metalinkStateV4_;
  71. static MetalinkParserState* fileStateV4_;
  72. static MetalinkParserState* sizeStateV4_;
  73. static MetalinkParserState* versionStateV4_;
  74. static MetalinkParserState* languageStateV4_;
  75. static MetalinkParserState* osStateV4_;
  76. static MetalinkParserState* hashStateV4_;
  77. static MetalinkParserState* piecesStateV4_; // Metalink4Spec
  78. static MetalinkParserState* pieceHashStateV4_; // Metalink4Spec
  79. static MetalinkParserState* signatureStateV4_;
  80. static MetalinkParserState* urlStateV4_;
  81. static MetalinkParserState* metaurlStateV4_;
  82. public:
  83. MetalinkParserStateMachine();
  84. ~MetalinkParserStateMachine();
  85. void setSkipTagState();
  86. void setMetalinkState();
  87. void setFilesState(); // Metalink3Spec
  88. void setFileState();
  89. void setSizeState();
  90. void setVersionState();
  91. void setLanguageState();
  92. void setOSState();
  93. void setVerificationState(); // Metalink3Spec
  94. void setHashState();
  95. void setPiecesState(); // Metalink3Spec
  96. void setPieceHashState(); // Metalink3Spec
  97. void setSignatureState();
  98. void setResourcesState(); // Metalink3Spec
  99. void setURLState();
  100. // Metalink4
  101. void setMetalinkStateV4();
  102. void setFileStateV4();
  103. void setSizeStateV4();
  104. void setVersionStateV4();
  105. void setLanguageStateV4();
  106. void setOSStateV4();
  107. void setHashStateV4();
  108. void setPiecesStateV4(); // Metalink4Spec
  109. void setPieceHashStateV4(); // Metalink4Spec
  110. void setSignatureStateV4();
  111. void setURLStateV4();
  112. void setMetaurlStateV4();
  113. bool finished() const;
  114. void beginElement
  115. (const std::string& localname,
  116. const std::string& prefix,
  117. const std::string& nsUri,
  118. const std::vector<XmlAttr>& attrs);
  119. void endElement
  120. (const std::string& localname,
  121. const std::string& prefix,
  122. const std::string& nsUri,
  123. const std::string& characters);
  124. void newEntryTransaction();
  125. void setFileNameOfEntry(const std::string& filename);
  126. void setFileLengthOfEntry(uint64_t length);
  127. void setVersionOfEntry(const std::string& version);
  128. void setLanguageOfEntry(const std::string& language);
  129. void setOSOfEntry(const std::string& os);
  130. void setMaxConnectionsOfEntry(int maxConnections); // Metalink3Spec
  131. void commitEntryTransaction();
  132. void cancelEntryTransaction();
  133. void newResourceTransaction();
  134. void setURLOfResource(const std::string& url);
  135. void setTypeOfResource(const std::string& type);
  136. void setLocationOfResource(const std::string& location);
  137. void setPriorityOfResource(int priority);
  138. void setMaxConnectionsOfResource(int maxConnections); // Metalink3Spec
  139. void commitResourceTransaction();
  140. void cancelResourceTransaction();
  141. void newChecksumTransaction();
  142. void setTypeOfChecksum(const std::string& type);
  143. void setHashOfChecksum(const std::string& md);
  144. void commitChecksumTransaction();
  145. void cancelChecksumTransaction();
  146. void newChunkChecksumTransactionV4(); // Metalink4Spec
  147. void setLengthOfChunkChecksumV4(size_t length); // Metalink4Spec
  148. void setTypeOfChunkChecksumV4(const std::string& type); // Metalink4Spec
  149. void addHashOfChunkChecksumV4(const std::string& md); // Metalink4Spec
  150. void commitChunkChecksumTransactionV4(); // Metalink4Spec
  151. void cancelChunkChecksumTransactionV4(); // Metalink4Spec
  152. void newChunkChecksumTransaction(); // Metalink3Spec
  153. void setLengthOfChunkChecksum(size_t length); // Metalink3Spec
  154. void setTypeOfChunkChecksum(const std::string& type); // Metalink3Spec
  155. void createNewHashOfChunkChecksum(size_t order); // Metalink3Spec
  156. void setMessageDigestOfChunkChecksum(const std::string& md); // Metalink3Spec
  157. void addHashOfChunkChecksum(); // Metalink3Spec
  158. void commitChunkChecksumTransaction(); // Metalink3Spec
  159. void cancelChunkChecksumTransaction(); // Metalink3Spec
  160. void newSignatureTransaction();
  161. void setTypeOfSignature(const std::string& type);
  162. void setFileOfSignature(const std::string& file);
  163. void setBodyOfSignature(const std::string& body);
  164. void commitSignatureTransaction();
  165. void cancelSignatureTransaction();
  166. void newMetaurlTransaction();
  167. void setURLOfMetaurl(const std::string& url);
  168. void setMediatypeOfMetaurl(const std::string& mediatype);
  169. void setPriorityOfMetaurl(int priority);
  170. void setNameOfMetaurl(const std::string& name);
  171. void commitMetaurlTransaction();
  172. void cancelMetaurlTransaction();
  173. bool needsCharactersBuffering() const;
  174. // Only stores first 10 errors.
  175. void logError(const std::string& log);
  176. const std::vector<std::string>& getErrors() const
  177. {
  178. return errors_;
  179. }
  180. std::string getErrorString() const;
  181. const SharedHandle<Metalinker>& getResult() const
  182. {
  183. return ctrl_->getResult();
  184. }
  185. void setBaseUri(const std::string& uri);
  186. };
  187. } // namespace aria2
  188. #endif // D_METALINK_PARSER_STATE_MACHINE_H