aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-09 14:36:32 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-09 14:36:32 +0000
commit195afc0e0159c8ed89c4b374a9d9ba6aacfddc6b (patch)
tree5a909ada7e8d79a6252934d811c4dcd9d1b5ab11 /source
parent47f2f46a5e390ffe15070a415df7f194b498abd9 (diff)
downloadqxmpp-195afc0e0159c8ed89c4b374a9d9ba6aacfddc6b.tar.gz
rework internal XML RPC APIs
Diffstat (limited to 'source')
-rw-r--r--source/QXmppClient.cpp4
-rw-r--r--source/QXmppRemoteMethod.cpp4
-rw-r--r--source/QXmppRpcIq.cpp33
-rw-r--r--source/QXmppRpcIq.h16
-rw-r--r--source/xmlrpc.cpp43
-rw-r--r--source/xmlrpc.h30
6 files changed, 70 insertions, 60 deletions
diff --git a/source/QXmppClient.cpp b/source/QXmppClient.cpp
index f054f130..ab2595c7 100644
--- a/source/QXmppClient.cpp
+++ b/source/QXmppClient.cpp
@@ -486,12 +486,12 @@ void QXmppClient::invokeInterfaceMethod( const QXmppRpcInvokeIq &iq )
if ( iface->interfaces().contains( iq.method() ) )
{
QVariant result = iface->dispatch(iq.method().toLatin1(),
- iq.payload() );
+ iq.arguments() );
QXmppRpcResponseIq resultIq;
resultIq.setId(iq.id());
resultIq.setTo(iq.from());
resultIq.setFrom(m_stream->configuration().jid());
- resultIq.setPayload(QVariantList() << result);
+ resultIq.setValues(QVariantList() << result);
m_stream->sendPacket( resultIq );
return;
}
diff --git a/source/QXmppRemoteMethod.cpp b/source/QXmppRemoteMethod.cpp
index f78b459c..3d501438 100644
--- a/source/QXmppRemoteMethod.cpp
+++ b/source/QXmppRemoteMethod.cpp
@@ -14,7 +14,7 @@ QXmppRemoteMethod::QXmppRemoteMethod(const QString &jid, const QString &method,
m_payload.setFrom( client->getConfiguration().jid() );
m_payload.setInterface( method.section('.', 0, 0 ) );
m_payload.setMethod( method.section('.', 1) );
- m_payload.setPayload( args );
+ m_payload.setArguments( args );
}
QXmppRemoteMethodResult QXmppRemoteMethod::call( )
@@ -45,7 +45,7 @@ void QXmppRemoteMethod::gotResult( const QXmppRpcResponseIq &iq )
if ( iq.id() == m_payload.id() )
{
m_result.hasError = false;
- m_result.result = iq.payload();
+ m_result.result = iq.values();
emit callDone();
}
}
diff --git a/source/QXmppRpcIq.cpp b/source/QXmppRpcIq.cpp
index 6f15918e..3eb8af08 100644
--- a/source/QXmppRpcIq.cpp
+++ b/source/QXmppRpcIq.cpp
@@ -43,14 +43,14 @@ QXmppRpcResponseIq::QXmppRpcResponseIq() : QXmppIq( QXmppIq::Result )
{
}
-QVariantList QXmppRpcResponseIq::payload() const
+QVariantList QXmppRpcResponseIq::values() const
{
- return m_payload;
+ return m_values;
}
-void QXmppRpcResponseIq::setPayload( const QVariantList &payload )
+void QXmppRpcResponseIq::setValues(const QVariantList &values)
{
- m_payload = payload;
+ m_values = values;
}
bool QXmppRpcResponseIq::isRpcResponseIq(const QDomElement &element)
@@ -68,14 +68,17 @@ void QXmppRpcResponseIq::parseElementFromChild(const QDomElement &element)
XMLRPC::ResponseMessage message;
if (message.parse(methodElement))
- m_payload = message.values();
+ m_values = message.values();
}
void QXmppRpcResponseIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
- XMLRPC::ResponseMessage message(m_payload);
writer->writeStartElement(ns_rpc, "query");
+
+ XMLRPC::ResponseMessage message;
+ message.setValues(m_values);
message.writeXml(writer);
+
writer->writeEndElement();
}
@@ -83,14 +86,14 @@ QXmppRpcInvokeIq::QXmppRpcInvokeIq() : QXmppIq( QXmppIq::Set )
{
}
-QVariantList QXmppRpcInvokeIq::payload() const
+QVariantList QXmppRpcInvokeIq::arguments() const
{
- return m_payload;
+ return m_arguments;
}
-void QXmppRpcInvokeIq::setPayload( const QVariantList &payload )
+void QXmppRpcInvokeIq::setArguments(const QVariantList &arguments)
{
- m_payload = payload;
+ m_arguments = arguments;
}
QString QXmppRpcInvokeIq::method() const
@@ -130,16 +133,20 @@ void QXmppRpcInvokeIq::parseElementFromChild(const QDomElement &element)
{
m_interface = message.method().split('.').value(0);
m_method = message.method().split('.').value(1);
- m_payload = message.args();
+ m_arguments = message.arguments();
}
}
void QXmppRpcInvokeIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
- QString methodName = m_interface + "." + m_method;
- XMLRPC::RequestMessage message( methodName.toLatin1(), m_payload );
writer->writeStartElement(ns_rpc, "query");
+
+ QString methodName = m_interface + "." + m_method;
+ XMLRPC::RequestMessage message;
+ message.setMethod(methodName.toLatin1());
+ message.setArguments(m_arguments);
message.writeXml(writer);
+
writer->writeEndElement();
}
diff --git a/source/QXmppRpcIq.h b/source/QXmppRpcIq.h
index fd2b7a36..d60fe308 100644
--- a/source/QXmppRpcIq.h
+++ b/source/QXmppRpcIq.h
@@ -12,8 +12,8 @@ class QXmppRpcResponseIq : public QXmppIq
public:
QXmppRpcResponseIq();
- QVariantList payload() const;
- void setPayload( const QVariantList &payload );
+ QVariantList values() const;
+ void setValues(const QVariantList &values);
static bool isRpcResponseIq(const QDomElement &element);
@@ -22,7 +22,7 @@ protected:
void toXmlElementFromChild(QXmlStreamWriter *writer) const;
private:
- QVariantList m_payload;
+ QVariantList m_values;
};
class QXmppRpcInvokeIq : public QXmppIq
@@ -30,14 +30,14 @@ class QXmppRpcInvokeIq : public QXmppIq
public:
QXmppRpcInvokeIq();
- QVariantList payload() const;
- void setPayload( const QVariantList &payload );
+ QString interface() const;
+ void setInterface( const QString &interface );
QString method() const;
void setMethod( const QString &method );
- QString interface() const;
- void setInterface( const QString &interface );
+ QVariantList arguments() const;
+ void setArguments(const QVariantList &arguments);
static bool isRpcInvokeIq(const QDomElement &element);
@@ -46,7 +46,7 @@ protected:
void toXmlElementFromChild(QXmlStreamWriter *writer) const;
private:
- QVariantList m_payload;
+ QVariantList m_arguments;
QString m_method;
QString m_interface;
diff --git a/source/xmlrpc.cpp b/source/xmlrpc.cpp
index 82830c46..3db63f0d 100644
--- a/source/xmlrpc.cpp
+++ b/source/xmlrpc.cpp
@@ -37,8 +37,8 @@ static void marshall( QXmlStreamWriter *writer, const QVariant &value)
{
writer->writeStartElement("array");
writer->writeStartElement("data");
- foreach( QVariant item, value.toList() )
- marshall( writer, item );
+ foreach(const QVariant &item, value.toList())
+ marshall(writer, item);
writer->writeEndElement();
writer->writeEndElement();
break;
@@ -119,7 +119,7 @@ static QVariant demarshall(const QDomElement &elem, QStringList &errors)
return QVariant( QDateTime::fromString( typeData.text(), Qt::ISODate ) );
else if( typeName == "array" )
{
- QList<QVariant> arr;
+ QVariantList arr;
QDomNode valueNode = typeData.firstChild().firstChild();
while (!valueNode.isNull() && errors.isEmpty())
{
@@ -160,11 +160,6 @@ static QVariant demarshall(const QDomElement &elem, QStringList &errors)
return QVariant();
}
-XMLRPC::RequestMessage::RequestMessage(const QByteArray &method, const QList<QVariant> &args)
- : m_method(method), m_args(args)
-{
-}
-
bool XMLRPC::RequestMessage::parse(const QDomElement &element)
{
QStringList errors;
@@ -199,16 +194,26 @@ bool XMLRPC::RequestMessage::parse(const QDomElement &element)
return true;
}
-QList< QVariant > XMLRPC::RequestMessage::args() const
+QVariantList XMLRPC::RequestMessage::arguments() const
{
return m_args;
}
+void XMLRPC::RequestMessage::setArguments(const QVariantList &args)
+{
+ m_args = args;
+}
+
QByteArray XMLRPC::RequestMessage::method() const
{
return m_method;
}
+void XMLRPC::RequestMessage::setMethod(const QByteArray &method)
+{
+ m_method = method;
+}
+
void XMLRPC::RequestMessage::writeXml( QXmlStreamWriter *writer ) const
{
writer->writeStartElement("methodCall");
@@ -216,10 +221,10 @@ void XMLRPC::RequestMessage::writeXml( QXmlStreamWriter *writer ) const
if( !m_args.isEmpty() )
{
writer->writeStartElement("params");
- foreach( QVariant arg, m_args)
+ foreach(const QVariant &arg, m_args)
{
writer->writeStartElement("param");
- marshall( writer, arg );
+ marshall(writer, arg);
writer->writeEndElement();
}
writer->writeEndElement();
@@ -227,11 +232,6 @@ void XMLRPC::RequestMessage::writeXml( QXmlStreamWriter *writer ) const
writer->writeEndElement();
}
-XMLRPC::ResponseMessage::ResponseMessage( const QList< QVariant > & theValue )
- : m_values(theValue)
-{
-}
-
bool XMLRPC::ResponseMessage::parse(const QDomElement &element)
{
QStringList errors;
@@ -266,11 +266,16 @@ bool XMLRPC::ResponseMessage::parse(const QDomElement &element)
}
}
-QList< QVariant > XMLRPC::ResponseMessage::values() const
+QVariantList XMLRPC::ResponseMessage::values() const
{
return m_values;
}
+void XMLRPC::ResponseMessage::setValues(const QVariantList &values)
+{
+ m_values = values;
+}
+
void XMLRPC::ResponseMessage::writeXml( QXmlStreamWriter *writer ) const
{
writer->writeStartElement("methodResponse");
@@ -278,10 +283,10 @@ void XMLRPC::ResponseMessage::writeXml( QXmlStreamWriter *writer ) const
if( !m_values.isEmpty() )
{
writer->writeStartElement("params");
- foreach( QVariant arg, m_values)
+ foreach (const QVariant &arg, m_values)
{
writer->writeStartElement("param");
- marshall( writer, arg );
+ marshall(writer, arg);
writer->writeEndElement();
}
writer->writeEndElement();
diff --git a/source/xmlrpc.h b/source/xmlrpc.h
index d27ec491..f9b179df 100644
--- a/source/xmlrpc.h
+++ b/source/xmlrpc.h
@@ -1,5 +1,5 @@
-#ifndef PACKET_H
-#define PACKET_H
+#ifndef QXMPPXMLRPC_H
+#define QXMPPXMLRPC_H
#include <QDomElement>
#include <QVariant>
@@ -19,15 +19,19 @@
* @code
* QList<QVariant> args;
* args << m_db << m_username << m_password << dbQuery;
-* RequestMessage msg( "data.query", args );
-* ResponseMessage resp( SomeHttpDispatchObject( msg.xml() ) );
-* if( resp.isValid() )
+* RequestMessage msg;
+* msg.setMethod("data.query");
+* msg.setArguments(args);
+*
+* ResponseMessage resp;
+* if (resp.parse(someDomElement))
* {
* int rows = resp.values().first().toMap()["widgets"].toInt();
* }
* else
* qWarning("Error: %s", resp.error().latin1() );
* @endcode
+*
* This example will construct invoke the data.query() method on the XMLRPC
* interface with the args. It will then check for the response to see if
* it was valid. If its valid the message contains a struct of values, one of
@@ -50,11 +54,6 @@ class RequestMessage
{
public:
/**
- * Creates a method packet that will call method with a list of args.
- */
- RequestMessage(const QByteArray &method = QByteArray(), const QVariantList &args = QVariantList());
-
- /**
* Parse an xml packet.
*/
bool parse(const QDomElement &element);
@@ -65,7 +64,10 @@ public:
void writeXml( QXmlStreamWriter *writer ) const;
QByteArray method() const;
- QVariantList args() const;
+ void setMethod(const QByteArray &method);
+
+ QVariantList arguments() const;
+ void setArguments(const QVariantList &args);
private:
QByteArray m_method;
@@ -80,11 +82,6 @@ class ResponseMessage
{
public:
/**
- * Create a new response message with data.
- */
- ResponseMessage(const QVariantList &values = QVariantList());
-
- /**
* Parse an xml packet.
*/
bool parse(const QDomElement &element);
@@ -95,6 +92,7 @@ public:
void writeXml( QXmlStreamWriter *writer ) const;
QVariantList values() const;
+ void setValues(const QVariantList &values);
private:
QList<QVariant> m_values;