2009-05-08 03:24:24 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-05-08 03:24:24 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "XmlRpcRequestParserStateImpl.h"
|
|
|
|
#include "XmlRpcRequestParserStateMachine.h"
|
|
|
|
#include "XmlRpcElements.h"
|
|
|
|
#include "RecoverableException.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2011-11-05 12:13:49 +00:00
|
|
|
#include "base64.h"
|
2009-05-08 03:24:24 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
2011-03-14 07:38:54 +00:00
|
|
|
namespace rpc {
|
2009-05-08 03:24:24 +00:00
|
|
|
|
|
|
|
// InitialXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void InitialXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::METHOD_CALL) {
|
|
|
|
stm->pushMethodCallState();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitialXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// UnknownElementXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void UnknownElementXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
|
|
|
|
// MethodCallXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void MethodCallXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::METHOD_NAME) {
|
|
|
|
stm->pushMethodNameState();
|
2009-08-08 16:08:56 +00:00
|
|
|
} else if(name == elements::A2_PARAMS) {
|
2010-06-19 17:54:54 +00:00
|
|
|
stm->setCurrentFrameValue(List::g());
|
2009-05-08 03:24:24 +00:00
|
|
|
stm->pushParamsState();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MethodNameXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void MethodNameXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MethodNameXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
|
|
|
stm->setMethodName(characters);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParamsXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void ParamsXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::PARAM) {
|
|
|
|
stm->pushFrame();
|
|
|
|
stm->pushParamState();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParamXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void ParamXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::VALUE) {
|
|
|
|
stm->pushValueState();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParamXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
|
|
|
stm->popArrayFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValueXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void ValueXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::I4 || name == elements::INT) {
|
|
|
|
stm->pushIntState();
|
|
|
|
} else if(name == elements::STRUCT) {
|
2010-06-19 17:54:54 +00:00
|
|
|
stm->setCurrentFrameValue(Dict::g());
|
2009-05-08 03:24:24 +00:00
|
|
|
stm->pushStructState();
|
|
|
|
} else if(name == elements::ARRAY) {
|
2010-06-19 17:54:54 +00:00
|
|
|
stm->setCurrentFrameValue(List::g());
|
2009-05-08 03:24:24 +00:00
|
|
|
stm->pushArrayState();
|
|
|
|
} else if(name == elements::STRING || name == elements::DOUBLE) {
|
|
|
|
stm->pushStringState();
|
|
|
|
} else if(name == elements::BASE64) {
|
|
|
|
stm->pushBase64State();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
2011-04-22 14:02:28 +00:00
|
|
|
|
|
|
|
void ValueXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2011-04-22 14:02:28 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
|
|
|
// XML-RPC specification says that if no data type tag is used, the
|
|
|
|
// data must be treated as string. To prevent from overwriting
|
|
|
|
// current frame value, we first check it is still null.
|
|
|
|
if(!stm->getCurrentFrameValue() && !characters.empty()) {
|
|
|
|
stm->setCurrentFrameValue(String::g(characters));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-08 03:24:24 +00:00
|
|
|
// IntXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void IntXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
|
|
|
try {
|
2011-11-03 09:51:31 +00:00
|
|
|
int64_t value = util::parseLLInt(characters.begin(), characters.end());
|
2010-06-19 17:54:54 +00:00
|
|
|
stm->setCurrentFrameValue(Integer::g(value));
|
2009-05-08 03:24:24 +00:00
|
|
|
} catch(RecoverableException& e) {
|
2010-06-19 17:54:54 +00:00
|
|
|
// nothing to do here: We just leave current frame value to null.
|
2009-05-08 03:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// StringXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void StringXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
2010-06-19 17:54:54 +00:00
|
|
|
stm->setCurrentFrameValue(String::g(characters));
|
2009-05-08 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Base64XmlRpcRequestParserState
|
|
|
|
|
|
|
|
void Base64XmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Base64XmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
2011-11-05 14:30:46 +00:00
|
|
|
stm->setCurrentFrameValue
|
|
|
|
(String::g(base64::decode(characters.begin(), characters.end())));
|
2009-05-08 03:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StructXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void StructXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::MEMBER) {
|
|
|
|
stm->pushFrame();
|
|
|
|
stm->pushMemberState();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MemberXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void MemberXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::NAME) {
|
|
|
|
stm->pushNameState();
|
|
|
|
} else if(name == elements::VALUE) {
|
|
|
|
stm->pushValueState();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemberXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
|
|
|
stm->popStructFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
// NameXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void NameXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NameXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
|
|
|
stm->setCurrentFrameName(characters);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ArrayXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void ArrayXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::DATA) {
|
|
|
|
stm->pushDataState();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DataXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void DataXmlRpcRequestParserState::beginElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::map<std::string, std::string>& attrs)
|
|
|
|
{
|
|
|
|
if(name == elements::VALUE) {
|
|
|
|
stm->pushFrame();
|
|
|
|
stm->pushArrayValueState();
|
|
|
|
} else {
|
|
|
|
stm->pushUnknownElementState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ArrayValueXmlRpcRequestParserState
|
|
|
|
|
|
|
|
void ArrayValueXmlRpcRequestParserState::endElement
|
|
|
|
(XmlRpcRequestParserStateMachine* stm,
|
2011-11-08 15:21:02 +00:00
|
|
|
const char* name,
|
2009-05-08 03:24:24 +00:00
|
|
|
const std::string& characters)
|
|
|
|
{
|
2011-04-22 14:02:28 +00:00
|
|
|
ValueXmlRpcRequestParserState::endElement(stm, name, characters);
|
2009-05-08 03:24:24 +00:00
|
|
|
stm->popArrayFrame();
|
|
|
|
}
|
|
|
|
|
2011-03-14 07:38:54 +00:00
|
|
|
} // namespace rpc
|
2009-05-08 03:24:24 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|