XmlRpcRequestParserStateMachine.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2009 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_XML_RPC_REQUEST_PARSER_STATE_MACHINE_H
  36. #define D_XML_RPC_REQUEST_PARSER_STATE_MACHINE_H
  37. #include "common.h"
  38. #include <string>
  39. #include <map>
  40. #include <stack>
  41. #include "XmlRpcRequestParserController.h"
  42. #include "XmlRpcRequestParserStateImpl.h"
  43. #include "ValueBase.h"
  44. namespace aria2 {
  45. namespace rpc {
  46. class XmlRpcRequestParserStateMachine {
  47. private:
  48. XmlRpcRequestParserController* controller_;
  49. std::stack<XmlRpcRequestParserState*> stateStack_;
  50. static InitialXmlRpcRequestParserState* initialState_;
  51. static MethodCallXmlRpcRequestParserState* methodCallState_;
  52. static MethodNameXmlRpcRequestParserState* methodNameState_;
  53. static ParamsXmlRpcRequestParserState* paramsState_;
  54. static ParamXmlRpcRequestParserState* paramState_;
  55. static ValueXmlRpcRequestParserState* valueState_;
  56. static IntXmlRpcRequestParserState* intState_;
  57. static StringXmlRpcRequestParserState* stringState_;
  58. static Base64XmlRpcRequestParserState* base64State_;
  59. static StructXmlRpcRequestParserState* structState_;
  60. static MemberXmlRpcRequestParserState* memberState_;
  61. static NameXmlRpcRequestParserState* nameState_;
  62. static ArrayXmlRpcRequestParserState* arrayState_;
  63. static DataXmlRpcRequestParserState* dataState_;
  64. static ArrayValueXmlRpcRequestParserState* arrayValueState_;
  65. static UnknownElementXmlRpcRequestParserState* unknownElementState_;
  66. public:
  67. XmlRpcRequestParserStateMachine();
  68. ~XmlRpcRequestParserStateMachine();
  69. void beginElement(const std::string& name,
  70. const std::map<std::string, std::string>& attrs)
  71. {
  72. stateStack_.top()->beginElement(this, name, attrs);
  73. }
  74. void endElement(const std::string& name, const std::string& characters)
  75. {
  76. stateStack_.top()->endElement(this, name, characters);
  77. stateStack_.pop();
  78. }
  79. void setMethodName(const std::string& methodName)
  80. {
  81. controller_->setMethodName(methodName);
  82. }
  83. const std::string& getMethodName() const
  84. {
  85. return controller_->getMethodName();
  86. }
  87. void popArrayFrame()
  88. {
  89. controller_->popArrayFrame();
  90. }
  91. void popStructFrame()
  92. {
  93. controller_->popStructFrame();
  94. }
  95. void pushFrame()
  96. {
  97. controller_->pushFrame();
  98. }
  99. void setCurrentFrameValue(const SharedHandle<ValueBase>& value)
  100. {
  101. controller_->setCurrentFrameValue(value);
  102. }
  103. const SharedHandle<ValueBase>& getCurrentFrameValue() const
  104. {
  105. return controller_->getCurrentFrameValue();
  106. }
  107. void setCurrentFrameName(const std::string& name)
  108. {
  109. controller_->setCurrentFrameName(name);
  110. }
  111. bool needsCharactersBuffering() const
  112. {
  113. return stateStack_.top()->needsCharactersBuffering();
  114. }
  115. void pushUnknownElementState() { stateStack_.push(unknownElementState_); }
  116. void pushMethodCallState() { stateStack_.push(methodCallState_); }
  117. void pushMethodNameState() { stateStack_.push(methodNameState_); }
  118. void pushParamsState() { stateStack_.push(paramsState_); }
  119. void pushParamState() { stateStack_.push(paramState_); }
  120. void pushValueState() { stateStack_.push(valueState_); }
  121. void pushIntState() { stateStack_.push(intState_); }
  122. void pushStringState() { stateStack_.push(stringState_); }
  123. void pushBase64State() { stateStack_.push(base64State_); }
  124. void pushStructState() { stateStack_.push(structState_); }
  125. void pushMemberState() { stateStack_.push(memberState_); }
  126. void pushNameState() { stateStack_.push(nameState_); }
  127. void pushArrayState() { stateStack_.push(arrayState_); }
  128. void pushDataState() { stateStack_.push(dataState_); }
  129. void pushArrayValueState() { stateStack_.push(arrayValueState_); }
  130. };
  131. } // namespace rpc
  132. } // namespace aria2
  133. #endif // D_XML_RPC_REQUEST_PARSER_STATE_MACHINE_H