Now xml attribute and characters in RPC request is not stripped at all.

Changed XmlRpcRequestParserState so that name is now const char*.
pull/2/head
Tatsuhiro Tsujikawa 2011-11-09 00:21:02 +09:00
parent bdaa87c73b
commit f114a6fba4
5 changed files with 68 additions and 67 deletions

View File

@ -34,6 +34,7 @@
/* copyright --> */
#include "Xml2XmlRpcRequestProcessor.h"
#include <cstring>
#include <stack>
#include <libxml/parser.h>
@ -64,16 +65,15 @@ void mlStartElement(void* userData, const xmlChar* name,
SessionData* sd = reinterpret_cast<SessionData*>(userData);
std::map<std::string, std::string> attrmap;
if(attrs) {
const xmlChar** p = attrs;
const char** p = reinterpret_cast<const char**>(attrs);
while(*p != 0) {
std::string name = reinterpret_cast<const char*>(*p);
std::string name = *p;
++p;
if(*p == 0) {
break;
}
std::string value = util::strip(reinterpret_cast<const char*>(*p));
attrmap[name].assign(*p, *p+strlen(*p));
++p;
attrmap[name] = value;
}
}
sd->stm_->beginElement(reinterpret_cast<const char*>(name), attrmap);
@ -87,12 +87,13 @@ namespace {
void mlEndElement(void* userData, const xmlChar* name)
{
SessionData* sd = reinterpret_cast<SessionData*>(userData);
std::string characters;
if(sd->stm_->needsCharactersBuffering()) {
characters = util::strip(sd->charactersStack_.top());
sd->stm_->endElement(reinterpret_cast<const char*>(name),
sd->charactersStack_.top());
sd->charactersStack_.pop();
} else {
sd->stm_->endElement(reinterpret_cast<const char*>(name), A2STR::NIL);
}
sd->stm_->endElement(reinterpret_cast<const char*>(name), characters);
}
} // namespace

View File

@ -51,11 +51,11 @@ public:
virtual ~XmlRpcRequestParserState() {}
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)= 0;
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters) = 0;
virtual bool needsCharactersBuffering() const = 0;

View File

@ -47,7 +47,7 @@ namespace rpc {
void InitialXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::METHOD_CALL) {
@ -59,7 +59,7 @@ void InitialXmlRpcRequestParserState::beginElement
void InitialXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{}
@ -67,7 +67,7 @@ void InitialXmlRpcRequestParserState::endElement
void UnknownElementXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
stm->pushUnknownElementState();
@ -77,7 +77,7 @@ void UnknownElementXmlRpcRequestParserState::beginElement
void MethodCallXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::METHOD_NAME) {
@ -94,7 +94,7 @@ void MethodCallXmlRpcRequestParserState::beginElement
void MethodNameXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
stm->pushUnknownElementState();
@ -102,7 +102,7 @@ void MethodNameXmlRpcRequestParserState::beginElement
void MethodNameXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
stm->setMethodName(characters);
@ -112,7 +112,7 @@ void MethodNameXmlRpcRequestParserState::endElement
void ParamsXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::PARAM) {
@ -127,7 +127,7 @@ void ParamsXmlRpcRequestParserState::beginElement
void ParamXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::VALUE) {
@ -139,7 +139,7 @@ void ParamXmlRpcRequestParserState::beginElement
void ParamXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
stm->popArrayFrame();
@ -149,7 +149,7 @@ void ParamXmlRpcRequestParserState::endElement
void ValueXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::I4 || name == elements::INT) {
@ -171,7 +171,7 @@ void ValueXmlRpcRequestParserState::beginElement
void ValueXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
// XML-RPC specification says that if no data type tag is used, the
@ -186,7 +186,7 @@ void ValueXmlRpcRequestParserState::endElement
void IntXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
stm->pushUnknownElementState();
@ -194,7 +194,7 @@ void IntXmlRpcRequestParserState::beginElement
void IntXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
try {
@ -209,7 +209,7 @@ void IntXmlRpcRequestParserState::endElement
void StringXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
stm->pushUnknownElementState();
@ -217,7 +217,7 @@ void StringXmlRpcRequestParserState::beginElement
void StringXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
stm->setCurrentFrameValue(String::g(characters));
@ -227,7 +227,7 @@ void StringXmlRpcRequestParserState::endElement
void Base64XmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
stm->pushUnknownElementState();
@ -235,7 +235,7 @@ void Base64XmlRpcRequestParserState::beginElement
void Base64XmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
stm->setCurrentFrameValue
@ -246,7 +246,7 @@ void Base64XmlRpcRequestParserState::endElement
void StructXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::MEMBER) {
@ -261,7 +261,7 @@ void StructXmlRpcRequestParserState::beginElement
void MemberXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::NAME) {
@ -275,7 +275,7 @@ void MemberXmlRpcRequestParserState::beginElement
void MemberXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
stm->popStructFrame();
@ -285,7 +285,7 @@ void MemberXmlRpcRequestParserState::endElement
void NameXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
stm->pushUnknownElementState();
@ -293,7 +293,7 @@ void NameXmlRpcRequestParserState::beginElement
void NameXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
stm->setCurrentFrameName(characters);
@ -303,7 +303,7 @@ void NameXmlRpcRequestParserState::endElement
void ArrayXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::DATA) {
@ -317,7 +317,7 @@ void ArrayXmlRpcRequestParserState::beginElement
void DataXmlRpcRequestParserState::beginElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs)
{
if(name == elements::VALUE) {
@ -332,7 +332,7 @@ void DataXmlRpcRequestParserState::beginElement
void ArrayValueXmlRpcRequestParserState::endElement
(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters)
{
ValueXmlRpcRequestParserState::endElement(stm, name, characters);

View File

@ -44,11 +44,11 @@ namespace rpc {
class InitialXmlRpcRequestParserState:public XmlRpcRequestParserState {
public:
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return false; }
@ -57,11 +57,11 @@ public:
class UnknownElementXmlRpcRequestParserState:public XmlRpcRequestParserState {
public:
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters) {}
virtual bool needsCharactersBuffering() const { return false; }
@ -70,11 +70,11 @@ public:
class MethodCallXmlRpcRequestParserState:public XmlRpcRequestParserState {
public:
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters) {}
virtual bool needsCharactersBuffering() const { return false; }
@ -83,11 +83,11 @@ public:
class MethodNameXmlRpcRequestParserState:public XmlRpcRequestParserState {
public:
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return true; }
@ -95,11 +95,11 @@ public:
class ParamsXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters) {}
virtual bool needsCharactersBuffering() const { return false; }
@ -107,11 +107,11 @@ class ParamsXmlRpcRequestParserState:public XmlRpcRequestParserState {
class ParamXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return false; }
@ -119,11 +119,11 @@ class ParamXmlRpcRequestParserState:public XmlRpcRequestParserState {
class ValueXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
protected:
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return true; }
@ -131,11 +131,11 @@ protected:
class IntXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return true; }
@ -143,11 +143,11 @@ class IntXmlRpcRequestParserState:public XmlRpcRequestParserState {
class StringXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return true; }
@ -155,11 +155,11 @@ class StringXmlRpcRequestParserState:public XmlRpcRequestParserState {
class Base64XmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return true; }
@ -167,11 +167,11 @@ class Base64XmlRpcRequestParserState:public XmlRpcRequestParserState {
class StructXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters) {}
virtual bool needsCharactersBuffering() const { return false; }
@ -179,11 +179,11 @@ class StructXmlRpcRequestParserState:public XmlRpcRequestParserState {
class MemberXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return false; }
@ -191,11 +191,11 @@ class MemberXmlRpcRequestParserState:public XmlRpcRequestParserState {
class NameXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
virtual bool needsCharactersBuffering() const { return true; }
@ -203,11 +203,11 @@ class NameXmlRpcRequestParserState:public XmlRpcRequestParserState {
class ArrayXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters) {}
virtual bool needsCharactersBuffering() const { return false; }
@ -215,11 +215,11 @@ class ArrayXmlRpcRequestParserState:public XmlRpcRequestParserState {
class DataXmlRpcRequestParserState:public XmlRpcRequestParserState {
virtual void beginElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::map<std::string, std::string>& attrs);
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters) {}
virtual bool needsCharactersBuffering() const { return false; }
@ -227,7 +227,7 @@ class DataXmlRpcRequestParserState:public XmlRpcRequestParserState {
class ArrayValueXmlRpcRequestParserState:public ValueXmlRpcRequestParserState {
virtual void endElement(XmlRpcRequestParserStateMachine* stm,
const std::string& name,
const char* name,
const std::string& characters);
};

View File

@ -77,13 +77,13 @@ public:
~XmlRpcRequestParserStateMachine();
void beginElement(const std::string& name,
void beginElement(const char* name,
const std::map<std::string, std::string>& attrs)
{
stateStack_.top()->beginElement(this, name, attrs);
}
void endElement(const std::string& name, const std::string& characters)
void endElement(const char* name, const std::string& characters)
{
stateStack_.top()->endElement(this, name, characters);
stateStack_.pop();