XmlRpcRequestParserStateMachine.cc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2011 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. #include "XmlRpcRequestParserStateMachine.h"
  36. #include "XmlRpcRequestParserController.h"
  37. #include "XmlRpcRequestParserStateImpl.h"
  38. namespace aria2 {
  39. namespace rpc {
  40. namespace {
  41. auto initialState = new InitialXmlRpcRequestParserState();
  42. auto unknownElementState = new UnknownElementXmlRpcRequestParserState();
  43. auto methodCallState = new MethodCallXmlRpcRequestParserState();
  44. auto methodNameState = new MethodNameXmlRpcRequestParserState();
  45. auto paramsState = new ParamsXmlRpcRequestParserState();
  46. auto paramState = new ParamXmlRpcRequestParserState();
  47. auto valueState = new ValueXmlRpcRequestParserState();
  48. auto intState = new IntXmlRpcRequestParserState();
  49. auto stringState = new StringXmlRpcRequestParserState();
  50. auto base64State = new Base64XmlRpcRequestParserState();
  51. auto structState = new StructXmlRpcRequestParserState();
  52. auto memberState = new MemberXmlRpcRequestParserState();
  53. auto nameState = new NameXmlRpcRequestParserState();
  54. auto arrayState = new ArrayXmlRpcRequestParserState();
  55. auto dataState = new DataXmlRpcRequestParserState();
  56. auto arrayValueState = new ArrayValueXmlRpcRequestParserState();
  57. } // namespace
  58. XmlRpcRequestParserStateMachine::XmlRpcRequestParserStateMachine()
  59. : controller_(new XmlRpcRequestParserController())
  60. {
  61. stateStack_.push(initialState);
  62. }
  63. XmlRpcRequestParserStateMachine::~XmlRpcRequestParserStateMachine()
  64. {
  65. delete controller_;
  66. }
  67. void XmlRpcRequestParserStateMachine::reset()
  68. {
  69. controller_->reset();
  70. while (!stateStack_.empty()) {
  71. stateStack_.pop();
  72. }
  73. stateStack_.push(initialState);
  74. }
  75. bool XmlRpcRequestParserStateMachine::needsCharactersBuffering() const
  76. {
  77. return stateStack_.top()->needsCharactersBuffering();
  78. }
  79. bool XmlRpcRequestParserStateMachine::finished() const
  80. {
  81. return stateStack_.top() == initialState;
  82. }
  83. void XmlRpcRequestParserStateMachine::beginElement(
  84. const char* localname, const char* prefix, const char* nsUri,
  85. const std::vector<XmlAttr>& attrs)
  86. {
  87. stateStack_.top()->beginElement(this, localname, attrs);
  88. }
  89. void XmlRpcRequestParserStateMachine::endElement(const char* localname,
  90. const char* prefix,
  91. const char* nsUri,
  92. std::string characters)
  93. {
  94. stateStack_.top()->endElement(this, localname, std::move(characters));
  95. stateStack_.pop();
  96. }
  97. void XmlRpcRequestParserStateMachine::setMethodName(std::string methodName)
  98. {
  99. controller_->setMethodName(std::move(methodName));
  100. }
  101. const std::string& XmlRpcRequestParserStateMachine::getMethodName() const
  102. {
  103. return controller_->getMethodName();
  104. }
  105. void XmlRpcRequestParserStateMachine::popArrayFrame()
  106. {
  107. controller_->popArrayFrame();
  108. }
  109. void XmlRpcRequestParserStateMachine::popStructFrame()
  110. {
  111. controller_->popStructFrame();
  112. }
  113. void XmlRpcRequestParserStateMachine::pushFrame() { controller_->pushFrame(); }
  114. void XmlRpcRequestParserStateMachine::setCurrentFrameValue(
  115. std::unique_ptr<ValueBase> value)
  116. {
  117. controller_->setCurrentFrameValue(std::move(value));
  118. }
  119. const std::unique_ptr<ValueBase>&
  120. XmlRpcRequestParserStateMachine::getCurrentFrameValue() const
  121. {
  122. return controller_->getCurrentFrameValue();
  123. }
  124. std::unique_ptr<ValueBase>
  125. XmlRpcRequestParserStateMachine::popCurrentFrameValue()
  126. {
  127. return controller_->popCurrentFrameValue();
  128. }
  129. void XmlRpcRequestParserStateMachine::setCurrentFrameName(std::string name)
  130. {
  131. controller_->setCurrentFrameName(std::move(name));
  132. }
  133. void XmlRpcRequestParserStateMachine::pushUnknownElementState()
  134. {
  135. stateStack_.push(unknownElementState);
  136. }
  137. void XmlRpcRequestParserStateMachine::pushMethodCallState()
  138. {
  139. stateStack_.push(methodCallState);
  140. }
  141. void XmlRpcRequestParserStateMachine::pushMethodNameState()
  142. {
  143. stateStack_.push(methodNameState);
  144. }
  145. void XmlRpcRequestParserStateMachine::pushParamsState()
  146. {
  147. stateStack_.push(paramsState);
  148. }
  149. void XmlRpcRequestParserStateMachine::pushParamState()
  150. {
  151. stateStack_.push(paramState);
  152. }
  153. void XmlRpcRequestParserStateMachine::pushValueState()
  154. {
  155. stateStack_.push(valueState);
  156. }
  157. void XmlRpcRequestParserStateMachine::pushIntState()
  158. {
  159. stateStack_.push(intState);
  160. }
  161. void XmlRpcRequestParserStateMachine::pushStringState()
  162. {
  163. stateStack_.push(stringState);
  164. }
  165. void XmlRpcRequestParserStateMachine::pushBase64State()
  166. {
  167. stateStack_.push(base64State);
  168. }
  169. void XmlRpcRequestParserStateMachine::pushStructState()
  170. {
  171. stateStack_.push(structState);
  172. }
  173. void XmlRpcRequestParserStateMachine::pushMemberState()
  174. {
  175. stateStack_.push(memberState);
  176. }
  177. void XmlRpcRequestParserStateMachine::pushNameState()
  178. {
  179. stateStack_.push(nameState);
  180. }
  181. void XmlRpcRequestParserStateMachine::pushArrayState()
  182. {
  183. stateStack_.push(arrayState);
  184. }
  185. void XmlRpcRequestParserStateMachine::pushDataState()
  186. {
  187. stateStack_.push(dataState);
  188. }
  189. void XmlRpcRequestParserStateMachine::pushArrayValueState()
  190. {
  191. stateStack_.push(arrayValueState);
  192. }
  193. } // namespace rpc
  194. } // namespace aria2