diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2022-04-08 22:48:00 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2022-04-08 22:54:11 +0900 |
| commit | ba36a38a6c4be38fe4e09cc95a40b58a48daed79 (patch) | |
| tree | 6110994e4a9f28608da92e41b235990257ba13eb /src | |
| parent | 37a7419fed8e6035a77c30bef456e36cbfd60245 (diff) | |
Allow empty dist name in bencode which is needed for hybrid torrent
Diffstat (limited to 'src')
| -rw-r--r-- | src/GenericParser.h | 9 | ||||
| -rw-r--r-- | src/ValueBaseBencodeParser.h | 2 | ||||
| -rw-r--r-- | src/ValueBaseStructParserStateMachine.cc | 5 | ||||
| -rw-r--r-- | src/ValueBaseStructParserStateMachine.h | 2 | ||||
| -rw-r--r-- | src/XmlRpcRequestParserController.cc | 7 | ||||
| -rw-r--r-- | src/XmlRpcRequestParserController.h | 11 |
6 files changed, 31 insertions, 5 deletions
diff --git a/src/GenericParser.h b/src/GenericParser.h index 86c6ca92..7373b066 100644 --- a/src/GenericParser.h +++ b/src/GenericParser.h @@ -42,9 +42,14 @@ namespace aria2 { -template <typename Parser, typename ParserStateMachine> class GenericParser { +template <typename Parser, typename ParserStateMachine, + bool allowEmptyName = false> +class GenericParser { public: - GenericParser() : parser_{&psm_} {} + GenericParser() : parser_{&psm_} + { + psm_.setAllowEmptyMemberName(allowEmptyName); + } ~GenericParser() = default; diff --git a/src/ValueBaseBencodeParser.h b/src/ValueBaseBencodeParser.h index cfc43145..91cfc37b 100644 --- a/src/ValueBaseBencodeParser.h +++ b/src/ValueBaseBencodeParser.h @@ -43,7 +43,7 @@ namespace aria2 { namespace bittorrent { -typedef GenericParser<BencodeParser, ValueBaseStructParserStateMachine> +typedef GenericParser<BencodeParser, ValueBaseStructParserStateMachine, true> ValueBaseBencodeParser; } // namespace bittorrent diff --git a/src/ValueBaseStructParserStateMachine.cc b/src/ValueBaseStructParserStateMachine.cc index b026758a..caf6296e 100644 --- a/src/ValueBaseStructParserStateMachine.cc +++ b/src/ValueBaseStructParserStateMachine.cc @@ -213,4 +213,9 @@ void ValueBaseStructParserStateMachine::pushNullState() stateStack_.push(nullState); } +void ValueBaseStructParserStateMachine::setAllowEmptyMemberName(bool b) +{ + ctrl_->setAllowEmptyMemberName(b); +} + } // namespace aria2 diff --git a/src/ValueBaseStructParserStateMachine.h b/src/ValueBaseStructParserStateMachine.h index a049de3a..c309cfb6 100644 --- a/src/ValueBaseStructParserStateMachine.h +++ b/src/ValueBaseStructParserStateMachine.h @@ -106,6 +106,8 @@ public: void pushBoolState(); void pushNullState(); + void setAllowEmptyMemberName(bool b); + private: std::unique_ptr<rpc::XmlRpcRequestParserController> ctrl_; std::stack<ValueBaseStructParserState*> stateStack_; diff --git a/src/XmlRpcRequestParserController.cc b/src/XmlRpcRequestParserController.cc index 25a5addc..a3c9a857 100644 --- a/src/XmlRpcRequestParserController.cc +++ b/src/XmlRpcRequestParserController.cc @@ -54,7 +54,7 @@ void XmlRpcRequestParserController::popStructFrame() Dict* dict = downcast<Dict>(parentFrame.value_); assert(dict); frameStack_.pop(); - if (currentFrame_.validMember()) { + if (currentFrame_.validMember(allowEmptyMemberName_)) { dict->put(std::move(currentFrame_.name_), std::move(currentFrame_.value_)); } currentFrame_ = std::move(parentFrame); @@ -110,6 +110,11 @@ void XmlRpcRequestParserController::setMethodName(std::string methodName) methodName_ = std::move(methodName); } +void XmlRpcRequestParserController::setAllowEmptyMemberName(bool b) +{ + allowEmptyMemberName_ = b; +} + } // namespace rpc } // namespace aria2 diff --git a/src/XmlRpcRequestParserController.h b/src/XmlRpcRequestParserController.h index 7892147b..b84a7de1 100644 --- a/src/XmlRpcRequestParserController.h +++ b/src/XmlRpcRequestParserController.h @@ -52,7 +52,10 @@ private: std::unique_ptr<ValueBase> value_; std::string name_; - bool validMember() const { return value_ && !name_.empty(); } + bool validMember(bool allowEmptyMemberName) const + { + return value_ && (allowEmptyMemberName || !name_.empty()); + } void reset() { @@ -67,7 +70,11 @@ private: std::string methodName_; + bool allowEmptyMemberName_; + public: + XmlRpcRequestParserController() : allowEmptyMemberName_(false) {} + void pushFrame(); // Pops StateFrame p from frameStack_ and set p[currentFrame_.name_] @@ -90,6 +97,8 @@ public: const std::string& getMethodName() const { return methodName_; } + void setAllowEmptyMemberName(bool b); + void reset(); }; |
