MetalinkParserStateMachine.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 <map>
  39. class MetalinkParserController;
  40. typedef SharedHandle<MetalinkParserController> MetalinkParserControllerHandle;
  41. class MetalinkParserState;
  42. class SkipTagMetalinkParserState;
  43. class Metalinker;
  44. typedef SharedHandle<Metalinker> MetalinkerHandle;
  45. class MetalinkParserStateMachine {
  46. private:
  47. MetalinkParserControllerHandle _ctrl;
  48. MetalinkParserState* _state;
  49. static MetalinkParserState* _initialState;
  50. static MetalinkParserState* _metalinkState;
  51. static MetalinkParserState* _filesState;
  52. static MetalinkParserState* _fileState;
  53. static MetalinkParserState* _sizeState;
  54. static MetalinkParserState* _versionState;
  55. static MetalinkParserState* _languageState;
  56. static MetalinkParserState* _osState;
  57. static MetalinkParserState* _verificationState;
  58. static MetalinkParserState* _hashState;
  59. static MetalinkParserState* _piecesState;
  60. static MetalinkParserState* _pieceHashState;
  61. static MetalinkParserState* _resourcesState;
  62. static MetalinkParserState* _urlState;
  63. static MetalinkParserState* _finState;
  64. SkipTagMetalinkParserState* _skipTagState;
  65. public:
  66. MetalinkParserStateMachine();
  67. ~MetalinkParserStateMachine();
  68. void setMetalinkState();
  69. void setFilesState();
  70. void setFileState();
  71. void setSizeState();
  72. void setVersionState();
  73. void setLanguageState();
  74. void setOSState();
  75. void setVerificationState();
  76. void setHashState();
  77. void setPiecesState();
  78. void setPieceHashState();
  79. void setResourcesState();
  80. void setURLState();
  81. void setFinState();
  82. void setSkipTagState(MetalinkParserState* prevSate);
  83. void restoreSavedState();
  84. bool finished() const;
  85. bool error() const;
  86. void beginElement(const string& name, const map<string, string>& attrs);
  87. void endElement(const string& name, const string& characters);
  88. void newEntryTransaction();
  89. void setFileNameOfEntry(const string& filename);
  90. void setFileLengthOfEntry(int64_t length);
  91. void setVersionOfEntry(const string& version);
  92. void setLanguageOfEntry(const string& language);
  93. void setOSOfEntry(const string& os);
  94. void setMaxConnectionsOfEntry(int32_t maxConnections);
  95. void commitEntryTransaction();
  96. void newResourceTransaction();
  97. void setURLOfResource(const string& url);
  98. void setTypeOfResource(const string& type);
  99. void setLocationOfResource(const string& location);
  100. void setPreferenceOfResource(int32_t preference);
  101. void setMaxConnectionsOfResource(int32_t maxConnections);
  102. void commitResourceTransaction();
  103. void cancelResourceTransaction();
  104. void newChecksumTransaction();
  105. void setTypeOfChecksum(const string& type);
  106. void setHashOfChecksum(const string& md);
  107. void commitChecksumTransaction();
  108. void cancelChecksumTransaction();
  109. void newChunkChecksumTransaction();
  110. void setLengthOfChunkChecksum(int32_t length);
  111. void setTypeOfChunkChecksum(const string& type);
  112. void createNewHashOfChunkChecksum(int32_t order);
  113. void setMessageDigestOfChunkChecksum(const string& md);
  114. void addHashOfChunkChecksum();
  115. void commitChunkChecksumTransaction();
  116. void cancelChunkChecksumTransaction();
  117. MetalinkerHandle getResult() const;
  118. };
  119. typedef SharedHandle<MetalinkParserStateMachine> MetalinkParserStateMachineHandle;
  120. #endif // _D_METALINK_PARSER_STATE_MACHINE_H_