summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2011-02-15 09:33:27 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2011-03-29 10:44:43 (GMT)
commit15b58e2b7d0550c433531550d9ad21e44a3435d8 (patch)
tree811713631b06133fb72a7fde2392b7b66bd49e4b /src/dbus
parentee1af4d59da999df32276889d3b40fb01deb0acc (diff)
downloadQt-15b58e2b7d0550c433531550d9ad21e44a3435d8.zip
Qt-15b58e2b7d0550c433531550d9ad21e44a3435d8.tar.gz
Qt-15b58e2b7d0550c433531550d9ad21e44a3435d8.tar.bz2
Add a 'capabilities' flag to the marshaller and demarshaller
The marshaller and demarshaller need to know the features negotiated with the peer so as to determine what's permitted. This is especially important to the marshaller: the libdbus-1 API may "throw a fit" if we try to pass a type that isn't allowed or the server may disconnect us. The use of the capabilities in the demarshaller are for symmetry and for us to toggle the feature in unit tests. Task-number: QTBUG-17478
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/qdbusargument.cpp8
-rw-r--r--src/dbus/qdbusargument_p.h10
-rw-r--r--src/dbus/qdbusdemarshaller.cpp8
-rw-r--r--src/dbus/qdbusintegrator.cpp14
-rw-r--r--src/dbus/qdbusmarshaller.cpp11
-rw-r--r--src/dbus/qdbusmessage.cpp17
-rw-r--r--src/dbus/qdbusmessage_p.h6
7 files changed, 40 insertions, 34 deletions
diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp
index 00f49ba..09f0e82 100644
--- a/src/dbus/qdbusargument.cpp
+++ b/src/dbus/qdbusargument.cpp
@@ -72,7 +72,7 @@ QByteArray QDBusArgumentPrivate::createSignature(int id)
return "";
QByteArray signature;
- QDBusMarshaller *marshaller = new QDBusMarshaller;
+ QDBusMarshaller *marshaller = new QDBusMarshaller(0);
marshaller->ba = &signature;
// run it
@@ -114,7 +114,7 @@ bool QDBusArgumentPrivate::checkWrite(QDBusArgumentPrivate *&d)
return false;
if (d->message && d->ref != 1) {
- QDBusMarshaller *dd = new QDBusMarshaller;
+ QDBusMarshaller *dd = new QDBusMarshaller(d->capabilities);
dd->message = q_dbus_message_copy(d->message);
q_dbus_message_iter_init_append(dd->message, &dd->iterator);
@@ -157,7 +157,7 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d)
if (d->ref == 1)
return true; // no need to detach
- QDBusDemarshaller *dd = new QDBusDemarshaller;
+ QDBusDemarshaller *dd = new QDBusDemarshaller(d->capabilities);
dd->message = q_dbus_message_ref(d->message);
dd->iterator = static_cast<QDBusDemarshaller*>(d)->iterator;
@@ -295,7 +295,7 @@ QDBusArgument::QDBusArgument()
return;
}
- QDBusMarshaller *dd = new QDBusMarshaller;
+ QDBusMarshaller *dd = new QDBusMarshaller(0);
d = dd;
// create a new message with any type, we won't sent it anyways
diff --git a/src/dbus/qdbusargument_p.h b/src/dbus/qdbusargument_p.h
index fe3a9cd..89a383f 100644
--- a/src/dbus/qdbusargument_p.h
+++ b/src/dbus/qdbusargument_p.h
@@ -65,8 +65,8 @@ class QDBusDemarshaller;
class QDBusArgumentPrivate
{
public:
- inline QDBusArgumentPrivate()
- : message(0), ref(1)
+ inline QDBusArgumentPrivate(int flags = 0)
+ : message(0), ref(1), capabilities(flags)
{ }
~QDBusArgumentPrivate();
@@ -89,6 +89,7 @@ public:
public:
DBusMessage *message;
QAtomicInt ref;
+ int capabilities;
enum Direction {
Marshalling,
Demarshalling
@@ -98,7 +99,7 @@ public:
class QDBusMarshaller: public QDBusArgumentPrivate
{
public:
- QDBusMarshaller() : parent(0), ba(0), closeCode(0), ok(true)
+ QDBusMarshaller(int flags) : QDBusArgumentPrivate(flags), parent(0), ba(0), closeCode(0), ok(true)
{ direction = Marshalling; }
~QDBusMarshaller();
@@ -153,7 +154,8 @@ private:
class QDBusDemarshaller: public QDBusArgumentPrivate
{
public:
- inline QDBusDemarshaller() : parent(0) { direction = Demarshalling; }
+ inline QDBusDemarshaller(int flags) : QDBusArgumentPrivate(flags), parent(0)
+ { direction = Demarshalling; }
~QDBusDemarshaller();
QString currentSignature();
diff --git a/src/dbus/qdbusdemarshaller.cpp b/src/dbus/qdbusdemarshaller.cpp
index 6638263..111122e 100644
--- a/src/dbus/qdbusdemarshaller.cpp
+++ b/src/dbus/qdbusdemarshaller.cpp
@@ -128,7 +128,7 @@ inline QDBusSignature QDBusDemarshaller::toSignature()
inline QDBusVariant QDBusDemarshaller::toVariant()
{
- QDBusDemarshaller sub;
+ QDBusDemarshaller sub(capabilities);
sub.message = q_dbus_message_ref(message);
q_dbus_message_iter_recurse(&iterator, &sub.iterator);
q_dbus_message_iter_next(&iterator);
@@ -249,7 +249,7 @@ QStringList QDBusDemarshaller::toStringList()
{
QStringList list;
- QDBusDemarshaller sub;
+ QDBusDemarshaller sub(capabilities);
q_dbus_message_iter_recurse(&iterator, &sub.iterator);
q_dbus_message_iter_next(&iterator);
while (!sub.atEnd())
@@ -297,7 +297,7 @@ inline QDBusDemarshaller *QDBusDemarshaller::beginMapEntry()
QDBusDemarshaller *QDBusDemarshaller::beginCommon()
{
- QDBusDemarshaller *d = new QDBusDemarshaller;
+ QDBusDemarshaller *d = new QDBusDemarshaller(capabilities);
d->parent = this;
d->message = q_dbus_message_ref(message);
@@ -336,7 +336,7 @@ QDBusDemarshaller *QDBusDemarshaller::endCommon()
QDBusArgument QDBusDemarshaller::duplicate()
{
- QDBusDemarshaller *d = new QDBusDemarshaller;
+ QDBusDemarshaller *d = new QDBusDemarshaller(capabilities);
d->iterator = iterator;
d->message = q_dbus_message_ref(message);
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 77c4223..ee917a5 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -535,7 +535,7 @@ qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data)
if (d->mode == QDBusConnectionPrivate::InvalidMode)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(message);
+ QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(message, d->capabilities);
qDBusDebug() << d << "got message (signal):" << amsg;
return d->handleMessage(amsg) ?
@@ -1204,7 +1204,7 @@ void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, in
QDBusMessagePrivate::setParametersValidated(message, true);
message.setArguments(args);
QDBusError error;
- DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, &error);
+ DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error);
if (!msg) {
qWarning("QDBusConnection: Could not emit signal %s.%s: %s", qPrintable(interface), memberName.constData(),
qPrintable(error.message()));
@@ -1754,7 +1754,7 @@ void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call)
if (call->pending) {
// decode the message
DBusMessage *reply = q_dbus_pending_call_steal_reply(call->pending);
- msg = QDBusMessagePrivate::fromDBusMessage(reply);
+ msg = QDBusMessagePrivate::fromDBusMessage(reply, connection->capabilities);
q_dbus_message_unref(reply);
}
qDBusDebug() << connection << "got message reply (async):" << msg;
@@ -1805,7 +1805,7 @@ int QDBusConnectionPrivate::send(const QDBusMessage& message)
// through the d_ptr->localReply link
QDBusError error;
- DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, &error);
+ DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error);
if (!msg) {
if (message.type() == QDBusMessage::MethodCallMessage)
qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
@@ -1851,7 +1851,7 @@ QDBusMessage QDBusConnectionPrivate::sendWithReply(const QDBusMessage &message,
if (!QCoreApplication::instance() || sendMode == QDBus::Block) {
QDBusError err;
- DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, &err);
+ DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &err);
if (!msg) {
qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
qPrintable(message.service()), qPrintable(message.path()),
@@ -1872,7 +1872,7 @@ QDBusMessage QDBusConnectionPrivate::sendWithReply(const QDBusMessage &message,
return QDBusMessage::createError(err);
}
- QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(reply);
+ QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(reply, capabilities);
q_dbus_message_unref(reply);
qDBusDebug() << this << "got message reply (blocking):" << amsg;
@@ -1948,7 +1948,7 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM
pcall->ref = 0;
QDBusError error;
- DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, &error);
+ DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error);
if (!msg) {
qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
qPrintable(message.service()), qPrintable(message.path()),
diff --git a/src/dbus/qdbusmarshaller.cpp b/src/dbus/qdbusmarshaller.cpp
index 15e56e7..76d76cc 100644
--- a/src/dbus/qdbusmarshaller.cpp
+++ b/src/dbus/qdbusmarshaller.cpp
@@ -188,7 +188,7 @@ inline bool QDBusMarshaller::append(const QDBusVariant &arg)
return false;
}
- QDBusMarshaller sub;
+ QDBusMarshaller sub(capabilities);
open(sub, DBUS_TYPE_VARIANT, signature);
bool isOk = sub.appendVariantInternal(value);
// don't call sub.close(): it auto-closes
@@ -203,7 +203,7 @@ inline void QDBusMarshaller::append(const QStringList &arg)
return;
}
- QDBusMarshaller sub;
+ QDBusMarshaller sub(capabilities);
open(sub, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING);
QStringList::ConstIterator it = arg.constBegin();
QStringList::ConstIterator end = arg.constEnd();
@@ -280,6 +280,7 @@ void QDBusMarshaller::open(QDBusMarshaller &sub, int code, const char *signature
sub.parent = this;
sub.ba = ba;
sub.ok = true;
+ sub.capabilities = capabilities;
if (ba)
switch (code) {
@@ -303,7 +304,7 @@ void QDBusMarshaller::open(QDBusMarshaller &sub, int code, const char *signature
QDBusMarshaller *QDBusMarshaller::beginCommon(int code, const char *signature)
{
- QDBusMarshaller *d = new QDBusMarshaller;
+ QDBusMarshaller *d = new QDBusMarshaller(capabilities);
open(*d, code, signature);
return d;
}
@@ -362,7 +363,7 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
if (!d->message)
return false; // can't append this one...
- QDBusDemarshaller demarshaller;
+ QDBusDemarshaller demarshaller(capabilities);
demarshaller.message = q_dbus_message_ref(d->message);
if (d->direction == Demarshalling) {
@@ -528,7 +529,7 @@ bool QDBusMarshaller::appendCrossMarshalling(QDBusDemarshaller *demarshaller)
// We have to recurse
QDBusDemarshaller *drecursed = demarshaller->beginCommon();
- QDBusMarshaller mrecursed; // create on the stack makes it autoclose
+ QDBusMarshaller mrecursed(capabilities); // create on the stack makes it autoclose
QByteArray subSignature;
const char *sig = 0;
if (code == DBUS_TYPE_VARIANT || code == DBUS_TYPE_ARRAY) {
diff --git a/src/dbus/qdbusmessage.cpp b/src/dbus/qdbusmessage.cpp
index c13d483..bd77c77 100644
--- a/src/dbus/qdbusmessage.cpp
+++ b/src/dbus/qdbusmessage.cpp
@@ -95,14 +95,15 @@ QString QDBusMessage::errorMessage() const
/*!
\internal
- Constructs a DBusMessage object from this object. The returned value must be de-referenced
- with q_dbus_message_unref.
+ Constructs a DBusMessage object from \a message. The returned value must be de-referenced
+ with q_dbus_message_unref. The \a capabilities flags indicates which capabilities to use.
The \a error object is set to indicate the error if anything went wrong with the
marshalling. Usually, this error message will be placed in the reply, as if the call failed.
The \a error pointer must not be null.
*/
-DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDBusError *error)
+DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDBusConnection::ConnectionCapabilities capabilities,
+ QDBusError *error)
{
if (!qdbus_loadLibDBus()) {
*error = QDBusError(QDBusError::Failed, QLatin1String("Could not open lidbus-1 library"));
@@ -177,7 +178,7 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
// we can record this fact
d_ptr->parametersValidated = true;
- QDBusMarshaller marshaller;
+ QDBusMarshaller marshaller(capabilities);
QVariantList::ConstIterator it = d_ptr->arguments.constBegin();
QVariantList::ConstIterator cend = d_ptr->arguments.constEnd();
q_dbus_message_iter_init_append(msg, &marshaller.iterator);
@@ -222,7 +223,7 @@ DBUS_DISABLE_CHECKS
\internal
Constructs a QDBusMessage by parsing the given DBusMessage object.
*/
-QDBusMessage QDBusMessagePrivate::fromDBusMessage(DBusMessage *dmsg)
+QDBusMessage QDBusMessagePrivate::fromDBusMessage(DBusMessage *dmsg, QDBusConnection::ConnectionCapabilities capabilities)
{
QDBusMessage message;
if (!dmsg)
@@ -238,7 +239,7 @@ QDBusMessage QDBusMessagePrivate::fromDBusMessage(DBusMessage *dmsg)
message.d_ptr->signature = QString::fromUtf8(q_dbus_message_get_signature(dmsg));
message.d_ptr->msg = q_dbus_message_ref(dmsg);
- QDBusDemarshaller demarshaller;
+ QDBusDemarshaller demarshaller(capabilities);
demarshaller.message = q_dbus_message_ref(dmsg);
if (q_dbus_message_iter_init(demarshaller.message, &demarshaller.iterator))
while (!demarshaller.atEnd())
@@ -272,7 +273,7 @@ QDBusMessage QDBusMessagePrivate::makeLocal(const QDBusConnectionPrivate &conn,
// we must marshall and demarshall again so as to create QDBusArgument
// entries for the complex types
QDBusError error;
- DBusMessage *message = toDBusMessage(asSent, &error);
+ DBusMessage *message = toDBusMessage(asSent, conn.capabilities, &error);
if (!message) {
// failed to marshall, so it's a call error
return QDBusMessage::createError(error);
@@ -280,7 +281,7 @@ QDBusMessage QDBusMessagePrivate::makeLocal(const QDBusConnectionPrivate &conn,
q_dbus_message_set_sender(message, conn.baseService.toUtf8());
- QDBusMessage retval = fromDBusMessage(message);
+ QDBusMessage retval = fromDBusMessage(message, conn.capabilities);
retval.d_ptr->localMessage = true;
q_dbus_message_unref(message);
if (retval.d_ptr->service.isEmpty())
diff --git a/src/dbus/qdbusmessage_p.h b/src/dbus/qdbusmessage_p.h
index 6747976..52d4d25 100644
--- a/src/dbus/qdbusmessage_p.h
+++ b/src/dbus/qdbusmessage_p.h
@@ -56,6 +56,7 @@
#include <qatomic.h>
#include <qstring.h>
#include <qdbusmessage.h>
+#include <qdbusconnection.h>
struct DBusMessage;
@@ -92,8 +93,9 @@ public:
static void setParametersValidated(QDBusMessage &msg, bool enable)
{ msg.d_ptr->parametersValidated = enable; }
- static DBusMessage *toDBusMessage(const QDBusMessage &message, QDBusError *error);
- static QDBusMessage fromDBusMessage(DBusMessage *dmsg);
+ static DBusMessage *toDBusMessage(const QDBusMessage &message, QDBusConnection::ConnectionCapabilities capabilities,
+ QDBusError *error);
+ static QDBusMessage fromDBusMessage(DBusMessage *dmsg, QDBusConnection::ConnectionCapabilities capabilities);
static bool isLocal(const QDBusMessage &msg);
static QDBusMessage makeLocal(const QDBusConnectionPrivate &conn,