summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusdemarshaller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus/qdbusdemarshaller.cpp')
-rw-r--r--src/dbus/qdbusdemarshaller.cpp51
1 files changed, 44 insertions, 7 deletions
diff --git a/src/dbus/qdbusdemarshaller.cpp b/src/dbus/qdbusdemarshaller.cpp
index 4103552db1..0b6767f2a0 100644
--- a/src/dbus/qdbusdemarshaller.cpp
+++ b/src/dbus/qdbusdemarshaller.cpp
@@ -130,19 +130,43 @@ inline double QDBusDemarshaller::toDouble()
return qIterGet<double>(&iterator);
}
-inline QString QDBusDemarshaller::toString()
+inline QString QDBusDemarshaller::toStringUnchecked()
{
return QString::fromUtf8(qIterGet<char *>(&iterator));
}
+inline QString QDBusDemarshaller::toString()
+{
+ if (isCurrentTypeStringLike())
+ return toStringUnchecked();
+ else
+ return QString();
+}
+
+inline QDBusObjectPath QDBusDemarshaller::toObjectPathUnchecked()
+ {
+ return QDBusObjectPath(QString::fromUtf8(qIterGet<char *>(&iterator)));
+ }
+
inline QDBusObjectPath QDBusDemarshaller::toObjectPath()
{
- return QDBusObjectPath(QString::fromUtf8(qIterGet<char *>(&iterator)));
+ if (isCurrentTypeStringLike())
+ return toObjectPathUnchecked();
+ else
+ return QDBusObjectPath();
}
+inline QDBusSignature QDBusDemarshaller::toSignatureUnchecked()
+ {
+ return QDBusSignature(QString::fromUtf8(qIterGet<char *>(&iterator)));
+ }
+
inline QDBusSignature QDBusDemarshaller::toSignature()
{
- return QDBusSignature(QString::fromUtf8(qIterGet<char *>(&iterator)));
+ if (isCurrentTypeStringLike())
+ return toSignatureUnchecked();
+ else
+ return QDBusSignature();
}
inline QDBusUnixFileDescriptor QDBusDemarshaller::toUnixFileDescriptor()
@@ -236,11 +260,11 @@ QVariant QDBusDemarshaller::toVariantInternal()
case DBUS_TYPE_UINT64:
return toULongLong();
case DBUS_TYPE_STRING:
- return toString();
+ return toStringUnchecked();
case DBUS_TYPE_OBJECT_PATH:
- return QVariant::fromValue(toObjectPath());
+ return QVariant::fromValue(toObjectPathUnchecked());
case DBUS_TYPE_SIGNATURE:
- return QVariant::fromValue(toSignature());
+ return QVariant::fromValue(toSignatureUnchecked());
case DBUS_TYPE_VARIANT:
return QVariant::fromValue(toVariant());
@@ -280,6 +304,19 @@ QVariant QDBusDemarshaller::toVariantInternal()
};
}
+bool QDBusDemarshaller::isCurrentTypeStringLike()
+{
+ const int type = q_dbus_message_iter_get_arg_type(&iterator);
+ switch (type) {
+ case DBUS_TYPE_STRING: //FALLTHROUGH
+ case DBUS_TYPE_OBJECT_PATH: //FALLTHROUGH
+ case DBUS_TYPE_SIGNATURE:
+ return true;
+ default:
+ return false;
+ }
+}
+
QStringList QDBusDemarshaller::toStringList()
{
QStringList list;
@@ -288,7 +325,7 @@ QStringList QDBusDemarshaller::toStringList()
q_dbus_message_iter_recurse(&iterator, &sub.iterator);
q_dbus_message_iter_next(&iterator);
while (!sub.atEnd())
- list.append(sub.toString());
+ list.append(sub.toStringUnchecked());
return list;
}