From 517b8c2446029901e9062e858b723906cf20d7ef Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 5 Jun 2006 18:13:07 +0000 Subject: * qt/dbus: Add directory. I had forgotten to add this yesterday after the move... * qt/examples/Makefile.am: * qt/examples/dbus.cpp: Moved to qt/tools/dbus.cpp. * qt/tools/Makefile.am: * qt/tools/dbus.cpp: Moved from qt/examples/dbus.cpp. Added feature to get and set properties. Added validation of service, object path and interface names. * qt/tools/dbusidl2cpp.cpp: Two new features: 1) Allow specifying both the header and the source file names, by separating them with a colon. 2) Don't write an interface output if the -p switch wasn't given, but the -a was. * qt/src/*: Fix usage of Iterators and ConstIterators. Fix shadowing of variables by other variables (-Wshadow). Fix keyword-cleanliness in headers. Fix ASCII-cast (QLatin1String, QLatin1Char). Fix validation of member names. Add extra checking of introspection data during XML parsing. Various bug fixes. --- qt/dbus/qdbus.h | 1 + qt/dbus/qdbusabstractadaptor.h | 1 + qt/dbus/qdbusabstractadaptor_p.h | 1 + qt/dbus/qdbusabstractinterface.h | 1 + qt/dbus/qdbusabstractinterface_p.h | 1 + qt/dbus/qdbusbus.h | 1 + qt/dbus/qdbusconnection.h | 1 + qt/dbus/qdbusconnection_p.h | 1 + qt/dbus/qdbuserror.h | 1 + qt/dbus/qdbusinterface.h | 1 + qt/dbus/qdbusinterface_p.h | 1 + qt/dbus/qdbusintrospection_p.h | 1 + qt/dbus/qdbusmacros.h | 1 + qt/dbus/qdbusmarshall_p.h | 1 + qt/dbus/qdbusmessage.h | 1 + qt/dbus/qdbusmessage_p.h | 1 + qt/dbus/qdbusmetaobject_p.h | 1 + qt/dbus/qdbusreply.h | 1 + qt/dbus/qdbusserver.h | 1 + qt/dbus/qdbustype_p.h | 1 + qt/dbus/qdbustypehelper_p.h | 1 + qt/dbus/qdbusutil.h | 1 + qt/dbus/qdbusxmlparser_p.h | 1 + qt/examples/Makefile.am | 3 +- qt/examples/complexpong.cpp | 1 + qt/examples/dbus.cpp | 316 ----------------------------- qt/examples/pong.cpp | 1 + qt/src/qdbusabstractadaptor.cpp | 21 +- qt/src/qdbusabstractinterface.cpp | 9 +- qt/src/qdbusbus.cpp | 46 ++--- qt/src/qdbusbus.h | 34 ++-- qt/src/qdbusconnection.cpp | 43 ++-- qt/src/qdbusconnection.h | 10 +- qt/src/qdbuserror.cpp | 16 +- qt/src/qdbuserror.h | 2 +- qt/src/qdbusintegrator.cpp | 56 +++--- qt/src/qdbusinterface.cpp | 12 +- qt/src/qdbusinternalfilters.cpp | 2 +- qt/src/qdbusmessage.cpp | 18 +- qt/src/qdbusmessage.h | 2 +- qt/src/qdbusmetaobject.cpp | 62 +++--- qt/src/qdbusreply.h | 12 +- qt/src/qdbusserver.cpp | 4 +- qt/src/qdbusutil.cpp | 38 ++-- qt/src/qdbusxmlgenerator.cpp | 16 +- qt/src/qdbusxmlparser.cpp | 85 ++++++-- qt/tools/Makefile.am | 5 +- qt/tools/dbus.cpp | 397 +++++++++++++++++++++++++++++++++++++ qt/tools/dbuscpp2xml.cpp | 23 ++- qt/tools/dbusidl2cpp.cpp | 118 ++++++----- 50 files changed, 777 insertions(+), 598 deletions(-) create mode 100644 qt/dbus/qdbus.h create mode 100644 qt/dbus/qdbusabstractadaptor.h create mode 100644 qt/dbus/qdbusabstractadaptor_p.h create mode 100644 qt/dbus/qdbusabstractinterface.h create mode 100644 qt/dbus/qdbusabstractinterface_p.h create mode 100644 qt/dbus/qdbusbus.h create mode 100644 qt/dbus/qdbusconnection.h create mode 100644 qt/dbus/qdbusconnection_p.h create mode 100644 qt/dbus/qdbuserror.h create mode 100644 qt/dbus/qdbusinterface.h create mode 100644 qt/dbus/qdbusinterface_p.h create mode 100644 qt/dbus/qdbusintrospection_p.h create mode 100644 qt/dbus/qdbusmacros.h create mode 100644 qt/dbus/qdbusmarshall_p.h create mode 100644 qt/dbus/qdbusmessage.h create mode 100644 qt/dbus/qdbusmessage_p.h create mode 100644 qt/dbus/qdbusmetaobject_p.h create mode 100644 qt/dbus/qdbusreply.h create mode 100644 qt/dbus/qdbusserver.h create mode 100644 qt/dbus/qdbustype_p.h create mode 100644 qt/dbus/qdbustypehelper_p.h create mode 100644 qt/dbus/qdbusutil.h create mode 100644 qt/dbus/qdbusxmlparser_p.h delete mode 100644 qt/examples/dbus.cpp create mode 100644 qt/tools/dbus.cpp (limited to 'qt') diff --git a/qt/dbus/qdbus.h b/qt/dbus/qdbus.h new file mode 100644 index 00000000..9fbc27aa --- /dev/null +++ b/qt/dbus/qdbus.h @@ -0,0 +1 @@ +#include "../src/qdbus.h" diff --git a/qt/dbus/qdbusabstractadaptor.h b/qt/dbus/qdbusabstractadaptor.h new file mode 100644 index 00000000..94cc3a22 --- /dev/null +++ b/qt/dbus/qdbusabstractadaptor.h @@ -0,0 +1 @@ +#include "../src/qdbusabstractadaptor.h" diff --git a/qt/dbus/qdbusabstractadaptor_p.h b/qt/dbus/qdbusabstractadaptor_p.h new file mode 100644 index 00000000..d55bef36 --- /dev/null +++ b/qt/dbus/qdbusabstractadaptor_p.h @@ -0,0 +1 @@ +#include "../src/qdbusabstractadaptor_p.h" diff --git a/qt/dbus/qdbusabstractinterface.h b/qt/dbus/qdbusabstractinterface.h new file mode 100644 index 00000000..e7ab181a --- /dev/null +++ b/qt/dbus/qdbusabstractinterface.h @@ -0,0 +1 @@ +#include "../src/qdbusabstractinterface.h" diff --git a/qt/dbus/qdbusabstractinterface_p.h b/qt/dbus/qdbusabstractinterface_p.h new file mode 100644 index 00000000..5f6e7d5d --- /dev/null +++ b/qt/dbus/qdbusabstractinterface_p.h @@ -0,0 +1 @@ +#include "../src/qdbusabstractinterface_p.h" diff --git a/qt/dbus/qdbusbus.h b/qt/dbus/qdbusbus.h new file mode 100644 index 00000000..eb849ac8 --- /dev/null +++ b/qt/dbus/qdbusbus.h @@ -0,0 +1 @@ +#include "../src/qdbusbus.h" diff --git a/qt/dbus/qdbusconnection.h b/qt/dbus/qdbusconnection.h new file mode 100644 index 00000000..99ac3239 --- /dev/null +++ b/qt/dbus/qdbusconnection.h @@ -0,0 +1 @@ +#include "../src/qdbusconnection.h" diff --git a/qt/dbus/qdbusconnection_p.h b/qt/dbus/qdbusconnection_p.h new file mode 100644 index 00000000..aaabb231 --- /dev/null +++ b/qt/dbus/qdbusconnection_p.h @@ -0,0 +1 @@ +#include "../src/qdbusconnection_p.h" diff --git a/qt/dbus/qdbuserror.h b/qt/dbus/qdbuserror.h new file mode 100644 index 00000000..680395a1 --- /dev/null +++ b/qt/dbus/qdbuserror.h @@ -0,0 +1 @@ +#include "../src/qdbuserror.h" diff --git a/qt/dbus/qdbusinterface.h b/qt/dbus/qdbusinterface.h new file mode 100644 index 00000000..c7024c8b --- /dev/null +++ b/qt/dbus/qdbusinterface.h @@ -0,0 +1 @@ +#include "../src/qdbusinterface.h" diff --git a/qt/dbus/qdbusinterface_p.h b/qt/dbus/qdbusinterface_p.h new file mode 100644 index 00000000..95384483 --- /dev/null +++ b/qt/dbus/qdbusinterface_p.h @@ -0,0 +1 @@ +#include "../src/qdbusinterface_p.h" diff --git a/qt/dbus/qdbusintrospection_p.h b/qt/dbus/qdbusintrospection_p.h new file mode 100644 index 00000000..210ed1ea --- /dev/null +++ b/qt/dbus/qdbusintrospection_p.h @@ -0,0 +1 @@ +#include "../src/qdbusintrospection_p.h" diff --git a/qt/dbus/qdbusmacros.h b/qt/dbus/qdbusmacros.h new file mode 100644 index 00000000..dcd725e9 --- /dev/null +++ b/qt/dbus/qdbusmacros.h @@ -0,0 +1 @@ +#include "../src/qdbusmacros.h" diff --git a/qt/dbus/qdbusmarshall_p.h b/qt/dbus/qdbusmarshall_p.h new file mode 100644 index 00000000..1e911852 --- /dev/null +++ b/qt/dbus/qdbusmarshall_p.h @@ -0,0 +1 @@ +#include "../src/qdbusmarshall_p.h" diff --git a/qt/dbus/qdbusmessage.h b/qt/dbus/qdbusmessage.h new file mode 100644 index 00000000..e993c1f9 --- /dev/null +++ b/qt/dbus/qdbusmessage.h @@ -0,0 +1 @@ +#include "../src/qdbusmessage.h" diff --git a/qt/dbus/qdbusmessage_p.h b/qt/dbus/qdbusmessage_p.h new file mode 100644 index 00000000..2b942017 --- /dev/null +++ b/qt/dbus/qdbusmessage_p.h @@ -0,0 +1 @@ +#include "../src/qdbusmessage_p.h" diff --git a/qt/dbus/qdbusmetaobject_p.h b/qt/dbus/qdbusmetaobject_p.h new file mode 100644 index 00000000..37a6e300 --- /dev/null +++ b/qt/dbus/qdbusmetaobject_p.h @@ -0,0 +1 @@ +#include "../src/qdbusmetaobject_p.h" diff --git a/qt/dbus/qdbusreply.h b/qt/dbus/qdbusreply.h new file mode 100644 index 00000000..8c87a715 --- /dev/null +++ b/qt/dbus/qdbusreply.h @@ -0,0 +1 @@ +#include "../src/qdbusreply.h" diff --git a/qt/dbus/qdbusserver.h b/qt/dbus/qdbusserver.h new file mode 100644 index 00000000..a8ca4ed4 --- /dev/null +++ b/qt/dbus/qdbusserver.h @@ -0,0 +1 @@ +#include "../src/qdbusserver.h" diff --git a/qt/dbus/qdbustype_p.h b/qt/dbus/qdbustype_p.h new file mode 100644 index 00000000..1f946019 --- /dev/null +++ b/qt/dbus/qdbustype_p.h @@ -0,0 +1 @@ +#include "../src/qdbustype_p.h" diff --git a/qt/dbus/qdbustypehelper_p.h b/qt/dbus/qdbustypehelper_p.h new file mode 100644 index 00000000..1e3c3427 --- /dev/null +++ b/qt/dbus/qdbustypehelper_p.h @@ -0,0 +1 @@ +#include "../src/qdbustypehelper_p.h" diff --git a/qt/dbus/qdbusutil.h b/qt/dbus/qdbusutil.h new file mode 100644 index 00000000..1b9dbd0f --- /dev/null +++ b/qt/dbus/qdbusutil.h @@ -0,0 +1 @@ +#include "../src/qdbusutil.h" diff --git a/qt/dbus/qdbusxmlparser_p.h b/qt/dbus/qdbusxmlparser_p.h new file mode 100644 index 00000000..f3e11008 --- /dev/null +++ b/qt/dbus/qdbusxmlparser_p.h @@ -0,0 +1 @@ +#include "../src/qdbusxmlparser_p.h" diff --git a/qt/examples/Makefile.am b/qt/examples/Makefile.am index 5d1e0542..ab569448 100644 --- a/qt/examples/Makefile.am +++ b/qt/examples/Makefile.am @@ -16,9 +16,8 @@ CHAT=chat endif -noinst_PROGRAMS = hello listnames dbus ping pong complexping complexpong $(CHAT) +noinst_PROGRAMS = hello listnames ping pong complexping complexpong $(CHAT) hello_SOURCES = hello.cpp -dbus_SOURCES = dbus.cpp listnames_SOURCES = listnames.cpp ping_SOURCES = ping.cpp diff --git a/qt/examples/complexpong.cpp b/qt/examples/complexpong.cpp index 1d9c9756..ff767407 100644 --- a/qt/examples/complexpong.cpp +++ b/qt/examples/complexpong.cpp @@ -20,6 +20,7 @@ */ #include +#include #include #include diff --git a/qt/examples/dbus.cpp b/qt/examples/dbus.cpp deleted file mode 100644 index 32fcc3fa..00000000 --- a/qt/examples/dbus.cpp +++ /dev/null @@ -1,316 +0,0 @@ -/* -*- C++ -*- - * - * Copyright (C) 2006 Trolltech AS. All rights reserved. - * Author: Thiago Macieira - * - * 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 Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include - -#include -#include -#include -#include -#include -#include - -Q_DECLARE_METATYPE(QVariant) -QDBusConnection *connection; - -void listObjects(const QString &service, const QString &path) -{ - QDBusInterfacePtr iface(*connection, service, path.isEmpty() ? "/" : path, - "org.freedesktop.DBus.Introspectable"); - if (!iface->isValid()) { - QDBusError err(iface->lastError()); - fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n", - qPrintable(path.isEmpty() ? "/" : path), qPrintable(service), - qPrintable(err.name()), qPrintable(err.message())); - exit(1); - } - QDBusReply xml = iface->call("Introspect"); - - if (xml.isError()) - return; // silently - - QDomDocument doc; - doc.setContent(xml); - QDomElement node = doc.documentElement(); - QDomElement child = node.firstChildElement(); - while (!child.isNull()) { - if (child.tagName() == QLatin1String("node")) { - QString sub = path + '/' + child.attribute("name"); - printf("%s\n", qPrintable(sub)); - listObjects(service, sub); - } - child = child.nextSiblingElement(); - } -} - -void listInterface(const QString &service, const QString &path, const QString &interface) -{ - QDBusInterfacePtr iface(*connection, service, path, interface); - if (!iface->isValid()) { - QDBusError err(iface->lastError()); - fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n", - qPrintable(interface), qPrintable(path), qPrintable(service), - qPrintable(err.name()), qPrintable(err.message())); - exit(1); - } - const QMetaObject *mo = iface->metaObject(); - - // properties - for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) { - QMetaProperty mp = mo->property(i); - printf("property "); - - if (mp.isReadable() && mp.isWritable()) - printf("readwrite"); - else if (mp.isReadable()) - printf("read"); - else - printf("write"); - - printf(" %s %s.%s\n", mp.typeName(), qPrintable(interface), mp.name()); - } - - // methods (signals and slots) - for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) { - QMetaMethod mm = mo->method(i); - - QByteArray signature = mm.signature(); - signature.truncate(signature.indexOf('(')); - printf("%s %s%s%s %s.%s(", - mm.methodType() == QMetaMethod::Signal ? "signal" : "method", - mm.tag(), *mm.tag() ? " " : "", - *mm.typeName() ? mm.typeName() : "void", - qPrintable(interface), signature.constData()); - - QList types = mm.parameterTypes(); - QList names = mm.parameterNames(); - bool first = true; - for (int i = 0; i < types.count(); ++i) { - printf("%s%s", - first ? "" : ", ", - types.at(i).constData()); - if (!names.at(i).isEmpty()) - printf(" %s", names.at(i).constData()); - first = false; - } - printf(")\n"); - } -} - -void listAllInterfaces(const QString &service, const QString &path) -{ - QDBusInterfacePtr iface(*connection, service, path, "org.freedesktop.DBus.Introspectable"); - if (!iface->isValid()) { - QDBusError err(iface->lastError()); - fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n", - qPrintable(path), qPrintable(service), - qPrintable(err.name()), qPrintable(err.message())); - exit(1); - } - QDBusReply xml = iface->call("Introspect"); - - if (xml.isError()) - return; // silently - - QDomDocument doc; - doc.setContent(xml); - QDomElement node = doc.documentElement(); - QDomElement child = node.firstChildElement(); - while (!child.isNull()) { - if (child.tagName() == QLatin1String("interface")) { - listInterface(service, path, child.attribute("name")); - } - child = child.nextSiblingElement(); - } -} - -QStringList readList(int &argc, const char *const *&argv) -{ - --argc; - ++argv; - - QStringList retval; - while (argc && QLatin1String(argv[0]) != ")") - retval += QString::fromLocal8Bit(argv[0]); - - return retval; -} - -void placeCall(const QString &service, const QString &path, const QString &interface, - const QString &member, int argc, const char *const *argv) -{ - QDBusInterfacePtr iface(*connection, service, path, interface); - if (!iface->isValid()) { - QDBusError err(iface->lastError()); - fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n", - qPrintable(interface), qPrintable(path), qPrintable(service), - qPrintable(err.name()), qPrintable(err.message())); - exit(1); - } - - const QMetaObject *mo = iface->metaObject(); - QByteArray match = member.toLatin1(); - match += '('; - - int midx = -1; - for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) { - QMetaMethod mm = mo->method(i); - QByteArray signature = mm.signature(); - if (signature.startsWith(match)) { - midx = i; - break; - } - } - - if (midx == -1) { - fprintf(stderr, "Cannot find '%s.%s' in object %s at %s\n", - qPrintable(interface), qPrintable(member), qPrintable(path), - qPrintable(service)); - exit(1); - } - - QMetaMethod mm = mo->method(midx); - QList types = mm.parameterTypes(); - - QVariantList params; - for (int i = 0; argc && i < types.count(); ++i) { - int id = QVariant::nameToType(types.at(i)); - if ((id == QVariant::UserType || id == QVariant::Map) && types.at(i) != "QVariant") { - fprintf(stderr, "Sorry, can't pass arg of type %s yet\n", - types.at(i).constData()); - exit(1); - } - if (id == QVariant::UserType) - id = QMetaType::type(types.at(i)); - - Q_ASSERT(id); - - QVariant p; - if ((id == QVariant::List || id == QVariant::StringList) && QLatin1String("(") == argv[0]) - p = readList(argc, argv); - else - p = QString::fromLocal8Bit(argv[0]); - - if (id < int(QVariant::UserType)) - // avoid calling it for QVariant - p.convert( QVariant::Type(id) ); - else if (types.at(i) == "QVariant") { - QVariant tmp(id, p.constData()); - p = tmp; - } - params += p; - --argc; - ++argv; - } - if (params.count() != types.count()) { - fprintf(stderr, "Invalid number of parameters\n"); - exit(1); - } - - QDBusMessage reply = iface->callWithArgs(member, params); - if (reply.type() == QDBusMessage::ErrorMessage) { - QDBusError err = reply; - printf("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); - exit(2); - } else if (reply.type() != QDBusMessage::ReplyMessage) { - fprintf(stderr, "Invalid reply type %d\n", int(reply.type())); - exit(1); - } - - foreach (QVariant v, reply) { - if (v.userType() == QVariant::StringList) { - foreach (QString s, v.toStringList()) - printf("%s\n", qPrintable(s)); - } else { - if (v.userType() == qMetaTypeId()) - v = qvariant_cast(v); - printf("%s\n", qPrintable(v.toString())); - } - } - - exit(0); -} - -int main(int argc, char **argv) -{ - QCoreApplication app(argc, argv); - if (argc >= 1 && qstrcmp(argv[1], "--system") == 0) { - connection = &QDBus::systemBus(); - --argc; - ++argv; - } else - connection = &QDBus::sessionBus(); - - if (!connection->isConnected()) { - fprintf(stderr, "Could not connect to D-Bus server: %s: %s\n", - qPrintable(connection->lastError().name()), - qPrintable(connection->lastError().message())); - return 1; - } - QDBusBusService *bus = connection->busService(); - - if (argc == 1) { - QStringList names = bus->ListNames(); - foreach (QString name, names) - printf("%s\n", qPrintable(name)); - exit(0); - } - - QString service = QLatin1String(argv[1]); - if (!QDBusUtil::isValidBusName(service)) { - fprintf(stderr, "Service '%s' is not a valid name.\n", qPrintable(service)); - exit(1); - } - if (!bus->NameHasOwner(service)) { - fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service)); - exit(1); - } - - if (argc == 2) { - printf("/\n"); - listObjects(service, QString()); - exit(0); - } - - QString path = QLatin1String(argv[2]); - if (!QDBusUtil::isValidObjectPath(path)) { - fprintf(stderr, "Path '%s' is not a valid path name.\n", qPrintable(path)); - exit(1); - } - if (argc == 3) { - listAllInterfaces(service, path); - exit(0); - } - - QString interface = QLatin1String(argv[3]); - QString member; - int pos = interface.lastIndexOf(QLatin1Char('.')); - if (pos == -1) { - member = interface; - interface.clear(); - } else { - member = interface.mid(pos + 1); - interface.truncate(pos); - } - - placeCall(service, path, interface, member, argc - 4, argv + 4); -} - diff --git a/qt/examples/pong.cpp b/qt/examples/pong.cpp index 3917bb58..b85f1f0c 100644 --- a/qt/examples/pong.cpp +++ b/qt/examples/pong.cpp @@ -20,6 +20,7 @@ */ #include +#include #include #include diff --git a/qt/src/qdbusabstractadaptor.cpp b/qt/src/qdbusabstractadaptor.cpp index b7c41888..4592b29a 100644 --- a/qt/src/qdbusabstractadaptor.cpp +++ b/qt/src/qdbusabstractadaptor.cpp @@ -88,8 +88,7 @@ void QDBusAbstractAdaptorPrivate::saveIntrospectionXml(QDBusAbstractAdaptor *ada } /*! - \page usingannotations.html - \title Using annotations in adaptors + \page usingannotations.html Using annotations in adaptors It is currently not possible to specify arbitrary annotations in adaptors. */ @@ -121,12 +120,12 @@ void QDBusAbstractAdaptorPrivate::saveIntrospectionXml(QDBusAbstractAdaptor *ada */ /*! - Constructs a QDBusAbstractAdaptor with \a parent as the object we refer to. + Constructs a QDBusAbstractAdaptor with \a obj as the parent object. */ -QDBusAbstractAdaptor::QDBusAbstractAdaptor(QObject* parent) - : QObject(parent), d(new QDBusAbstractAdaptorPrivate) +QDBusAbstractAdaptor::QDBusAbstractAdaptor(QObject* obj) + : QObject(obj), d(new QDBusAbstractAdaptorPrivate) { - QDBusAdaptorConnector *connector = qDBusCreateAdaptorConnector(parent); + QDBusAdaptorConnector *connector = qDBusCreateAdaptorConnector(obj); connector->waitingForPolish = true; QTimer::singleShot(0, connector, SLOT(polish())); @@ -181,8 +180,8 @@ void QDBusAbstractAdaptor::setAutoRelaySignals(bool enable) } } -QDBusAdaptorConnector::QDBusAdaptorConnector(QObject *parent) - : QObject(parent), waitingForPolish(false), lastSignalIdx(0), argv(0) +QDBusAdaptorConnector::QDBusAdaptorConnector(QObject *obj) + : QObject(obj), waitingForPolish(false), lastSignalIdx(0), argv(0) { } @@ -258,18 +257,18 @@ void QDBusAdaptorConnector::relaySlot() relay(sender()); } -void QDBusAdaptorConnector::relay(QObject *sender) +void QDBusAdaptorConnector::relay(QObject *senderObj) { // we're being called because there is a signal being emitted that we must relay Q_ASSERT(lastSignalIdx); Q_ASSERT(argv); Q_ASSERT(senderMetaObject); - if (senderMetaObject != sender->metaObject()) { + if (senderMetaObject != senderObj->metaObject()) { qWarning("Inconsistency detected: QDBusAdaptorConnector::relay got called with unexpected sender object!"); } else { QMetaMethod mm = senderMetaObject->method(lastSignalIdx); - QObject *object = static_cast(sender)->parent(); + QObject *object = static_cast(senderObj)->parent(); // break down the parameter list QList types; diff --git a/qt/src/qdbusabstractinterface.cpp b/qt/src/qdbusabstractinterface.cpp index 2a6bcf04..ffe5d67e 100644 --- a/qt/src/qdbusabstractinterface.cpp +++ b/qt/src/qdbusabstractinterface.cpp @@ -31,7 +31,8 @@ QVariant QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp) const { // try to read this property - QDBusMessage msg = QDBusMessage::methodCall(service, path, DBUS_INTERFACE_PROPERTIES, + QDBusMessage msg = QDBusMessage::methodCall(service, path, + QLatin1String(DBUS_INTERFACE_PROPERTIES), QLatin1String("Get")); msg << interface << QString::fromUtf8(mp.name()); QDBusMessage reply = connp->sendWithReply(msg, QDBusConnection::NoUseEventLoop); @@ -72,7 +73,8 @@ QVariant QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp) const void QDBusAbstractInterfacePrivate::setProperty(const QMetaProperty &mp, const QVariant &value) { // send the value - QDBusMessage msg = QDBusMessage::methodCall(service, path, DBUS_INTERFACE_PROPERTIES, + QDBusMessage msg = QDBusMessage::methodCall(service, path, + QLatin1String(DBUS_INTERFACE_PROPERTIES), QLatin1String("Set")); msg.setSignature(QLatin1String("ssv")); msg << interface << QString::fromUtf8(mp.name()) << value; @@ -185,7 +187,6 @@ QDBusError QDBusAbstractInterface::lastError() const } /*! - \threadsafe Places a call to the remote method specified by \a method on this interface, using \a args as arguments. This function returns the message that was received as a reply, which can be a normal QDBusMessage::ReplyMessage (indicating success) or QDBusMessage::ErrorMessage (if the call @@ -199,6 +200,8 @@ QDBusError QDBusAbstractInterface::lastError() const \warning If you use \c UseEventLoop, your code must be prepared to deal with any reentrancy: other method calls and signals may be delivered before this function returns, as well as other Qt queued signals and events. + + \threadsafe */ QDBusMessage QDBusAbstractInterface::callWithArgs(const QString& method, const QList& args, CallMode mode) diff --git a/qt/src/qdbusbus.cpp b/qt/src/qdbusbus.cpp index 02c231eb..f46966b4 100644 --- a/qt/src/qdbusbus.cpp +++ b/qt/src/qdbusbus.cpp @@ -151,21 +151,21 @@ QDBusReply QDBusBusService::ListNames() } /*! - \fn QDBusBusService::listQueuedOwners(const QString &service) + \fn QDBusBusService::listQueuedOwners(const QString &serviceName) Returns a list of all unique connection names in queue for the service name \a service. */ -QDBusReply QDBusBusService::ListQueuedOwners(const QString &service) +QDBusReply QDBusBusService::ListQueuedOwners(const QString &serviceName) { - return call(QLatin1String("ListQueuedOwners.s"), service); + return call(QLatin1String("ListQueuedOwners.s"), serviceName); } /*! - \fn QDBusBusService::nameHasOwner(const QString &service) + \fn QDBusBusService::nameHasOwner(const QString &serviceName) Returns true if the service name \a service has an owner. */ -QDBusReply QDBusBusService::NameHasOwner(const QString &service) +QDBusReply QDBusBusService::NameHasOwner(const QString &serviceName) { - return call(QLatin1String("NameHasOwner.s"), service); + return call(QLatin1String("NameHasOwner.s"), serviceName); } /*! @@ -189,31 +189,31 @@ QDBusReply QDBusBusService::RemoveMatch(const QString &rule) } /*! - \fn QDBusBusService::connectionSELinuxSecurityContext(const QString &service) + \fn QDBusBusService::connectionSELinuxSecurityContext(const QString &serviceName) Returns the SELinux security context of the process currently holding the bus service \a service. */ -QDBusReply QDBusBusService::GetConnectionSELinuxSecurityContext(const QString &service) +QDBusReply QDBusBusService::GetConnectionSELinuxSecurityContext(const QString &serviceName) { - return call(QLatin1String("GetConnectionSELinuxSecurityContext.s"), service); + return call(QLatin1String("GetConnectionSELinuxSecurityContext.s"), serviceName); } /*! - \fn QDBusBusService::connectionUnixProcessID(const QString &service) + \fn QDBusBusService::connectionUnixProcessID(const QString &serviceName) Returns the Unix Process ID (PID) for the process currently holding the bus service \a service. */ -QDBusReply QDBusBusService::GetConnectionUnixProcessID(const QString &service) +QDBusReply QDBusBusService::GetConnectionUnixProcessID(const QString &serviceName) { - return call(QLatin1String("GetConnectionUnixProcessID.s"), service); + return call(QLatin1String("GetConnectionUnixProcessID.s"), serviceName); } /*! - \fn QDBusBusService::connectionUnixUser(const QString &service) + \fn QDBusBusService::connectionUnixUser(const QString &serviceName) Returns the Unix User ID (UID) for the process currently holding the bus service \a service. */ -QDBusReply QDBusBusService::GetConnectionUnixUser(const QString &service) +QDBusReply QDBusBusService::GetConnectionUnixUser(const QString &serviceName) { - return call(QLatin1String("GetConnectionUnixUser.s"), service); + return call(QLatin1String("GetConnectionUnixUser.s"), serviceName); } /*! @@ -244,36 +244,36 @@ inline QDBUS_EXPORT int qDBusMetaTypeId(QDBusBusService::RequestNameReply *) { return QVariant::Int; } /*! - \fn QDBusBusService::requestName(const QString &service, RequestNameOptions flags) + \fn QDBusBusService::requestName(const QString &serviceName, RequestNameOptions flags) Requests the bus service name \a service from the bus. The \a flags parameter specifies how the bus server daemon should act when the same name is requested by two different applications. \sa releaseName() */ QDBusReply -QDBusBusService::RequestName(const QString &service, RequestNameOptions flags) +QDBusBusService::RequestName(const QString &serviceName, RequestNameOptions flags) { - return call(QLatin1String("RequestName.su"), service, uint(int(flags))); + return call(QLatin1String("RequestName.su"), serviceName, uint(int(flags))); } inline QDBUS_EXPORT int qDBusMetaTypeId(QDBusBusService::ReleaseNameReply *) { return QVariant::Int; } /*! - \fn QDBusBusService::releaseName(const QString &service) + \fn QDBusBusService::releaseName(const QString &serviceName) Releases the claim on the bus service name \a service, that had been previously requested with requestName(). If this application had ownership of the name, it will be released for other applications to claim. If it only had the name queued, it gives up its position in the queue. */ QDBusReply -QDBusBusService::ReleaseName(const QString &service) +QDBusBusService::ReleaseName(const QString &serviceName) { - return call(QLatin1String("ReleaseName.s"), service); + return call(QLatin1String("ReleaseName.s"), serviceName); } // signals /*! - \fn QDBusBusService::nameAcquired(const QString &service) + \fn QDBusBusService::nameAcquired(const QString &serviceName) This signal is emitted by the D-Bus bus server when the bus service name (unique connection name or well-known service name) given by \a service is acquired by this application. @@ -282,7 +282,7 @@ QDBusBusService::ReleaseName(const QString &service) */ /*! - \fn QDBusBusService::nameLost(const QString &service) + \fn QDBusBusService::nameLost(const QString &serviceName) This signal is emitted by the D-Bus bus server when the application loses ownership of the bus service name given by \a service. diff --git a/qt/src/qdbusbus.h b/qt/src/qdbusbus.h index 22606852..1f695798 100644 --- a/qt/src/qdbusbus.h +++ b/qt/src/qdbusbus.h @@ -105,14 +105,14 @@ public: // METHODS QDBusReply StartServiceByName(const QString &name, uint flags); -signals: // SIGNALS +Q_SIGNALS: // SIGNALS void NameAcquired(const QString &service); void NameLost(const QString &service); void NameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); #endif // Qt-style naming -public slots: +public Q_SLOTS: QDBusReply hello() { return Hello(); } QDBusReply reloadConfig() @@ -121,33 +121,33 @@ public slots: QDBusReply listNames() { return ListNames(); } - QDBusReply nameHasOwner(const QString &service) - { return NameHasOwner(service); } + QDBusReply nameHasOwner(const QString &serviceName) + { return NameHasOwner(serviceName); } QDBusReply nameOwner(const QString &name) { return GetNameOwner(name); } - QDBusReply releaseName(const QString &service) - { return ReleaseName(service); } - QDBusReply requestName(const QString &service, RequestNameOptions flags) - { return RequestName(service, flags); } - QDBusReply listQueuedOwners(const QString &service) - { return ListQueuedOwners(service); } + QDBusReply releaseName(const QString &serviceName) + { return ReleaseName(serviceName); } + QDBusReply requestName(const QString &serviceName, RequestNameOptions flags) + { return RequestName(serviceName, flags); } + QDBusReply listQueuedOwners(const QString &serviceName) + { return ListQueuedOwners(serviceName); } QDBusReply addMatch(const QString &rule) { return AddMatch(rule); } QDBusReply removeMatch(const QString &rule) { return RemoveMatch(rule); } - QDBusReply connectionSELinuxSecurityContext(const QString &service) - { return GetConnectionSELinuxSecurityContext(service); } - QDBusReply connectionUnixProcessID(const QString &service) - { return GetConnectionUnixProcessID(service); } - QDBusReply connectionUnixUser(const QString &service) - { return GetConnectionUnixUser(service); } + QDBusReply connectionSELinuxSecurityContext(const QString &serviceName) + { return GetConnectionSELinuxSecurityContext(serviceName); } + QDBusReply connectionUnixProcessID(const QString &serviceName) + { return GetConnectionUnixProcessID(serviceName); } + QDBusReply connectionUnixUser(const QString &serviceName) + { return GetConnectionUnixUser(serviceName); } QDBusReply startServiceByName(const QString &name, uint flags) { return StartServiceByName(name, flags); } -signals: +Q_SIGNALS: void nameAcquired(const QString &service); void nameLost(const QString &service); void nameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); diff --git a/qt/src/qdbusconnection.cpp b/qt/src/qdbusconnection.cpp index 6cd733cb..7049857d 100644 --- a/qt/src/qdbusconnection.cpp +++ b/qt/src/qdbusconnection.cpp @@ -294,7 +294,7 @@ QDBusConnection QDBusConnection::addConnection(BusType type, const QString &name QDBusAbstractInterfacePrivate *p; p = retval.findInterface_helper(QLatin1String(DBUS_SERVICE_DBUS), QLatin1String(DBUS_PATH_DBUS), - QLatin1String(DBUS_INTERFACE_DBUS)); + DBUS_INTERFACE_DBUS); if (p) { d->busService = new QDBusBusService(p); d->busService->setParent(d); // auto-deletion @@ -330,7 +330,7 @@ QDBusConnection QDBusConnection::addConnection(const QString &address, QDBusAbstractInterfacePrivate *p; p = retval.findInterface_helper(QLatin1String(DBUS_SERVICE_DBUS), QLatin1String(DBUS_PATH_DBUS), - QLatin1String(DBUS_INTERFACE_DBUS)); + DBUS_INTERFACE_DBUS); if (p) { d->busService = new QDBusBusService(p); d->busService->setParent(d); // auto-deletion @@ -451,7 +451,7 @@ bool QDBusConnection::connect(const QString &service, const QString &path, const // avoid duplicating: QWriteLocker locker(&d->lock); QDBusConnectionPrivate::SignalHookHash::ConstIterator it = d->signalHooks.find(key); - for ( ; it != d->signalHooks.end() && it.key() == key; ++it) { + for ( ; it != d->signalHooks.constEnd() && it.key() == key; ++it) { const QDBusConnectionPrivate::SignalHook &entry = it.value(); if (entry.sender == hook.sender && entry.path == hook.path && @@ -481,6 +481,8 @@ bool QDBusConnection::connect(const QString &service, const QString &path, const */ bool QDBusConnection::registerObject(const QString &path, QObject *object, RegisterOptions options) { + Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registerObject", + "Invalid object path given"); if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path)) return false; @@ -601,6 +603,12 @@ void QDBusConnection::unregisterObject(const QString &path, UnregisterMode mode) QDBusInterface *QDBusConnection::findInterface(const QString& service, const QString& path, const QString& interface) { + Q_ASSERT_X(QDBusUtil::isValidBusName(service), + "QDBusConnection::findInterface", "Invalid service name"); + Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), + "QDBusConnection::findInterface", "Invalid object path given"); + Q_ASSERT_X(interface.isEmpty() || QDBusUtil::isValidInterfaceName(interface), + "QDBusConnection::findInterface", "Invalid interface name"); if (!d) return 0; @@ -636,24 +644,31 @@ QDBusBusService *QDBusConnection::busService() const QDBusAbstractInterfacePrivate * QDBusConnection::findInterface_helper(const QString &service, const QString &path, - const QString &interface) + const char *iface) { + QString interface = QLatin1String(iface); + // service and path can be empty here, but interface can't + Q_ASSERT_X(service.isEmpty() || QDBusUtil::isValidBusName(service), + "QDBusConnection::findInterface", "Invalid service name"); + Q_ASSERT_X(path.isEmpty() || QDBusUtil::isValidObjectPath(path), + "QDBusConnection::findInterface", "Invalid object path given"); + Q_ASSERT_X(QDBusUtil::isValidInterfaceName(interface), + "QDBusConnection::findInterface", "Invalid interface class!"); if (!d) return 0; - if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface)) - return 0; - + QString owner; if (!service.isEmpty()) { - if (!QDBusUtil::isValidObjectPath(path)) - return 0; - // check if it's there first -- FIXME: add binding mode owner = d->getNameOwner(service); - if (owner.isEmpty()) - return 0; - } else if (!path.isEmpty()) - return 0; + if (owner.isEmpty()) { + QDBusAbstractInterfacePrivate *p; + p = new QDBusAbstractInterfacePrivate(*this, d, service, path, interface); + p->isValid = false; + p->lastError = d->lastError; + return p; + } + } return new QDBusAbstractInterfacePrivate(*this, d, owner, path, interface); } diff --git a/qt/src/qdbusconnection.h b/qt/src/qdbusconnection.h index c1c420a6..61a3439e 100644 --- a/qt/src/qdbusconnection.h +++ b/qt/src/qdbusconnection.h @@ -101,17 +101,17 @@ public: private: QDBusAbstractInterfacePrivate *findInterface_helper(const QString &, const QString &, - const QString&); + const char*); QDBusConnectionPrivate *d; }; template inline Interface *QDBusConnection::findInterface(const QString &service, const QString &path) { - register QDBusAbstractInterfacePrivate *d; - d = findInterface_helper(service, path, Interface::staticInterfaceName()); - if (d) - return new Interface(d); + register QDBusAbstractInterfacePrivate *d_ptr; + d_ptr = findInterface_helper(service, path, Interface::staticInterfaceName()); + if (d_ptr) + return new Interface(d_ptr); return 0; } diff --git a/qt/src/qdbuserror.cpp b/qt/src/qdbuserror.cpp index d5cd6758..ee6ce12c 100644 --- a/qt/src/qdbuserror.cpp +++ b/qt/src/qdbuserror.cpp @@ -135,11 +135,11 @@ Q_GLOBAL_STATIC(ErrorMessageMapping, errorMessages) pre-defined values (\c org.freedesktop.DBus.Error.LimitsExceeded) \value AccessDenied The call/operation tried to access a resource it isn't allowed to (\c org.freedesktop.DBus.Error.AccessDenied) - \value NoServer \i{Documentation doesn't say what this is for} + \value NoServer \e {Documentation doesn't say what this is for} (\c org.freedesktop.DBus.Error.NoServer) - \value Timeout \i{Documentation doesn't say what this is for or how it's used} + \value Timeout \e {Documentation doesn't say what this is for or how it's used} (\c org.freedesktop.DBus.Error.Timeout) - \value NoNetwork \i{Documentation doesn't say what this is for} + \value NoNetwork \e {Documentation doesn't say what this is for} (\c org.freedesktop.DBus.Error.NoNetwork) \value AddressInUse QDBusServer tried to bind to an address that is already in use (\c org.freedesktop.DBus.Error.AddressInUse) @@ -149,7 +149,7 @@ Q_GLOBAL_STATIC(ErrorMessageMapping, errorMessages) (\c org.freedesktop.DBus.Error.InvalidArgs) \value UnknownMethod The method called was not found in this object/interface with the given parameters (\c org.freedesktop.DBus.Error.UnknownMethod) - \value TimedOut \i{Documentation doesn't say...} + \value TimedOut \e {Documentation doesn't say...} (\c org.freedesktop.DBus.Error.TimedOut) \value InvalidSignature The type signature is not valid or compatible (\c org.freedesktop.DBus.Error.InvalidSignature) @@ -194,11 +194,11 @@ QDBusError::QDBusError(const QDBusMessage &qdmsg) \internal Constructs a QDBusError from a well-known error code */ -QDBusError::QDBusError(KnownErrors error, const QString &message) +QDBusError::QDBusError(KnownErrors error, const QString &mess) : code(error) { - nm = errorMessages()->get(error); - msg = message; + nm = QLatin1String(errorMessages()->get(error)); + msg = mess; } /*! @@ -233,7 +233,7 @@ QDBusError::QDBusError(KnownErrors error, const QString &message) match. */ -#ifndef QT_NO_DEBUG +#ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QDBusError &msg) { dbg.nospace() << "QDBusError(" << msg.name() << ", " << msg.message() << ")"; diff --git a/qt/src/qdbuserror.h b/qt/src/qdbuserror.h index 71c636df..e7aacdb0 100644 --- a/qt/src/qdbuserror.h +++ b/qt/src/qdbuserror.h @@ -86,7 +86,7 @@ inline bool operator!=(QDBusError::KnownErrors p1, const QDBusError &p2) inline bool operator!=(const QDBusError &p1, QDBusError::KnownErrors p2) { return !(p1 == p2); } -#ifndef QT_NO_DEBUG +#ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug, const QDBusError &); #endif diff --git a/qt/src/qdbusintegrator.cpp b/qt/src/qdbusintegrator.cpp index 07921cf9..de012c19 100644 --- a/qt/src/qdbusintegrator.cpp +++ b/qt/src/qdbusintegrator.cpp @@ -507,13 +507,13 @@ bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, { const QMetaObject *mo = object->metaObject(); QDBusTypeList typeList(msg.signature().toUtf8()); - QByteArray name = msg.name().toUtf8(); + QByteArray memberName = msg.name().toUtf8(); // find a slot that matches according to the rules above - idx = ::findSlot(mo, name, flags, typeList, metaTypes); + idx = ::findSlot(mo, memberName, flags, typeList, metaTypes); if (idx == -1) { // try with no parameters, but with a QDBusMessage - idx = ::findSlot(mo, name, flags, QDBusTypeList(), metaTypes); + idx = ::findSlot(mo, memberName, flags, QDBusTypeList(), metaTypes); if (metaTypes.count() != 2 || metaTypes.at(1) != messageMetaType) return false; } @@ -594,7 +594,7 @@ void QDBusConnectionPrivate::deliverCall(const CallDeliveryEvent& data) const const QVariant &in = msg.at(i - 1); QVariant &out = auxParameters[auxParameters.count() - 1]; - bool error = false; + bool isOk = true; if (id == QVariant::List) { int mid = in.userType(); // the only conversion possible here is from a specialised QList to QVariantList @@ -615,7 +615,7 @@ void QDBusConnectionPrivate::deliverCall(const CallDeliveryEvent& data) const else if (mid == QDBusTypeHelper::listId()) out = qVariantFromValue(QDBusTypeHelper::toVariantList(in)); else - error = true; + isOk = false; } else if (in.type() == QVariant::UInt) { if (id == QMetaType::UChar) { uchar uc = in.toUInt(); @@ -624,20 +624,20 @@ void QDBusConnectionPrivate::deliverCall(const CallDeliveryEvent& data) const ushort us = in.toUInt(); out = qVariantFromValue(us); } else { - error = true; + isOk = false; } } else if (in.type() == QVariant::Int) { if (id == QMetaType::Short) { short s = in.toInt(); out = qVariantFromValue(s); } else { - error = true; + isOk = false; } } else { - error = true; + isOk = false; } - if (error) + if (!isOk) qFatal("Internal error: got invalid meta type %d when trying to convert to meta type %d", in.userType(), id); @@ -697,10 +697,10 @@ void QDBusConnectionPrivate::deliverCall(const CallDeliveryEvent& data) const return; } -void QDBusConnectionPrivate::customEvent(QEvent *event) +void QDBusConnectionPrivate::customEvent(QEvent *e) { // nothing else should be sending custom events at us - CallDeliveryEvent* call = static_cast(event); + CallDeliveryEvent* call = static_cast(e); // self check: Q_ASSERT(call->conn == this); @@ -708,8 +708,8 @@ void QDBusConnectionPrivate::customEvent(QEvent *event) deliverCall(*call); } -QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *parent) - : QObject(parent), ref(1), mode(InvalidMode), connection(0), server(0), busService(0) +QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p) + : QObject(p), ref(1), mode(InvalidMode), connection(0), server(0), busService(0) { extern bool qDBusInitThreads(); static const int msgType = registerMessageMetaType(); @@ -845,16 +845,16 @@ void QDBusConnectionPrivate::objectDestroyed(QObject *obj) obj->disconnect(this); } -void QDBusConnectionPrivate::relaySignal(QObject *obj, const char *interface, const char *name, +void QDBusConnectionPrivate::relaySignal(QObject *obj, const char *interface, const char *memberName, const QVariantList &args) { QReadLocker locker(&lock); QDBusMessage message = QDBusMessage::signal(QLatin1String("/"), QLatin1String(interface), - QLatin1String(name)); + QLatin1String(memberName)); message += args; DBusMessage *msg = message.toDBusMessage(); if (!msg) { - qWarning("Could not emit signal %s.%s", interface, name); + qWarning("Could not emit signal %s.%s", interface, memberName); return; } @@ -910,7 +910,7 @@ bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hoo } key = mname; key.reserve(interface.length() + 1 + mname.length()); - key += ':'; + key += QLatin1Char(':'); key += interface; if (buildSignature) { @@ -973,7 +973,7 @@ bool QDBusConnectionPrivate::activateObject(const ObjectTreeNode *node, const QD QDBusAdaptorConnector::AdaptorMap::ConstIterator it; it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(), msg.interface()); - if (it != connector->adaptors.end() && it->interface == msg.interface()) + if (it != connector->adaptors.constEnd() && it->interface == msg.interface()) if (activateCall(it->adaptor, newflags, msg)) return true; } @@ -1114,7 +1114,7 @@ bool QDBusConnectionPrivate::handleSignal(const QDBusMessage& msg) { QString key = msg.member(); key.reserve(key.length() + 1 + msg.interface().length()); - key += ':'; + key += QLatin1Char(':'); key += msg.interface(); QReadLocker locker(&lock); @@ -1257,9 +1257,9 @@ int QDBusConnectionPrivate::send(const QDBusMessage& message) const } QDBusMessage QDBusConnectionPrivate::sendWithReply(const QDBusMessage &message, - int mode) + int sendMode) { - if (!QCoreApplication::instance() || mode == QDBusConnection::NoUseEventLoop) { + if (!QCoreApplication::instance() || sendMode == QDBusConnection::NoUseEventLoop) { DBusMessage *msg = message.toDBusMessage(); if (!msg) return QDBusMessage(); @@ -1368,7 +1368,7 @@ void QDBusConnectionPrivate::connectRelay(const QString &service, const QString // add it to our list: QWriteLocker locker(&lock); SignalHookHash::ConstIterator it = signalHooks.find(key); - SignalHookHash::ConstIterator end = signalHooks.end(); + SignalHookHash::ConstIterator end = signalHooks.constEnd(); for ( ; it != end && it.key() == key; ++it) { const SignalHook &entry = it.value(); if (entry.sender == hook.sender && @@ -1415,17 +1415,17 @@ void QDBusConnectionPrivate::disconnectRelay(const QString &service, const QStri qWarning("QDBusConnectionPrivate::disconnectRelay called for a signal that was not found"); } -QString QDBusConnectionPrivate::getNameOwner(const QString& name) +QString QDBusConnectionPrivate::getNameOwner(const QString& serviceName) { - if (QDBusUtil::isValidUniqueConnectionName(name)) - return name; - if (!connection || !QDBusUtil::isValidBusName(name)) + if (QDBusUtil::isValidUniqueConnectionName(serviceName)) + return serviceName; + if (!connection || !QDBusUtil::isValidBusName(serviceName)) return QString(); QDBusMessage msg = QDBusMessage::methodCall(QLatin1String(DBUS_SERVICE_DBUS), QLatin1String(DBUS_PATH_DBUS), QLatin1String(DBUS_INTERFACE_DBUS), QLatin1String("GetNameOwner")); - msg << name; + msg << serviceName; QDBusMessage reply = sendWithReply(msg, QDBusConnection::NoUseEventLoop); if (!lastError.isValid() && reply.type() == QDBusMessage::ReplyMessage) return reply.first().toString(); @@ -1459,12 +1459,14 @@ QDBusConnectionPrivate::findInterface(const QString &service, else if (owner.isEmpty()) p->lastError = QDBusError(QDBusError::ServiceUnknown, QString(QLatin1String("Service %1 is unknown")).arg(service)); +#if 0 // caught by Q_ASSERT in QDBusConnection::findInterface else if (!QDBusUtil::isValidObjectPath(path)) p->lastError = QDBusError(QDBusError::InvalidArgs, QString(QLatin1String("Object path %1 is invalid")).arg(path)); else if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface)) p->lastError = QDBusError(QDBusError::InvalidArgs, QString(QLatin1String("Interface %1 is invalid")).arg(interface)); +#endif else p->lastError = QDBusError(QDBusError::Other, QLatin1String("Unknown error")); } diff --git a/qt/src/qdbusinterface.cpp b/qt/src/qdbusinterface.cpp index 6367654d..72097077 100644 --- a/qt/src/qdbusinterface.cpp +++ b/qt/src/qdbusinterface.cpp @@ -75,7 +75,7 @@ void *QDBusInterface::qt_metacast(const char *_clname) if (!_clname) return 0; if (!strcmp(_clname, "QDBusInterface")) return static_cast(const_cast(this)); - if (d_func()->interface == _clname) + if (d_func()->interface.toLatin1() == _clname) return static_cast(const_cast(this)); return QDBusAbstractInterface::qt_metacast(_clname); } @@ -107,7 +107,7 @@ int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv) } else if (mm.methodType() == QMetaMethod::Slot) { // method call relay from Qt world to D-Bus world // get D-Bus equivalent signature - QString methodName = metaObject->dbusNameForMethod(id); + QString methodName = QLatin1String(metaObject->dbusNameForMethod(id)); const int *inputTypes = metaObject->inputTypesForMethod(id); const int *outputTypes = metaObject->outputTypesForMethod(id); @@ -191,13 +191,13 @@ int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv) } QDBusInterfacePtr::QDBusInterfacePtr(QDBusConnection &conn, const QString &service, const QString &path, - const QString &interface) - : d(conn.findInterface(service, path, interface)) + const QString &iface) + : d(conn.findInterface(service, path, iface)) { } -QDBusInterfacePtr::QDBusInterfacePtr(const QString &service, const QString &path, const QString &interface) - : d(QDBus::sessionBus().findInterface(service, path, interface)) +QDBusInterfacePtr::QDBusInterfacePtr(const QString &service, const QString &path, const QString &iface) + : d(QDBus::sessionBus().findInterface(service, path, iface)) { } diff --git a/qt/src/qdbusinternalfilters.cpp b/qt/src/qdbusinternalfilters.cpp index 8886d3bf..ed210744 100644 --- a/qt/src/qdbusinternalfilters.cpp +++ b/qt/src/qdbusinternalfilters.cpp @@ -165,7 +165,7 @@ void qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode *node, const QDBusAdaptorConnector::AdaptorMap::ConstIterator it; it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(), interface_name); - if (it != connector->adaptors.end() && it->interface == interface_name) + if (it != connector->adaptors.constEnd() && it->interface == interface_name) value = it->adaptor->property(property_name); } diff --git a/qt/src/qdbusmessage.cpp b/qt/src/qdbusmessage.cpp index d0a0f1e5..ec24100e 100644 --- a/qt/src/qdbusmessage.cpp +++ b/qt/src/qdbusmessage.cpp @@ -55,12 +55,10 @@ QDBusMessagePrivate::~QDBusMessagePrivate() This object can represent any of four different types of messages possible on the bus (see MessageType) - \list - \o Method calls - \o Method return values - \o Signal emissions - \o Error codes - \endlist + - Method calls + - Method return values + - Signal emissions + - Error codes Objects of this type are created with the four static functions signal, methodCall, methodReply and error. @@ -432,7 +430,7 @@ QString QDBusMessage::signature() const /*! Sets the signature for the output arguments of this method call to be the value of \a - signature. This function has no meaning in other types of messages or when dealing with received + sig. This function has no meaning in other types of messages or when dealing with received method calls. A message's signature indicate the type of the parameters to @@ -442,10 +440,10 @@ QString QDBusMessage::signature() const when a variant of type QVariant::Invalid is converted to the type). */ -void QDBusMessage::setSignature(const QString &signature) +void QDBusMessage::setSignature(const QString &sig) { qAtomicDetach(d_ptr); - d_ptr->signature = signature; + d_ptr->signature = sig; } /*! @@ -569,7 +567,7 @@ QDBusMessage::MessageType QDBusMessage::type() const value. */ -#ifndef QT_NO_DEBUG +#ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t) { switch (t) diff --git a/qt/src/qdbusmessage.h b/qt/src/qdbusmessage.h index f8feeae4..a36d3983 100644 --- a/qt/src/qdbusmessage.h +++ b/qt/src/qdbusmessage.h @@ -91,7 +91,7 @@ private: QDBusMessagePrivate *d_ptr; }; -#ifndef QT_NO_DEBUG +#ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug, const QDBusMessage &); #endif diff --git a/qt/src/qdbusmetaobject.cpp b/qt/src/qdbusmetaobject.cpp index a923d79a..60675d5d 100644 --- a/qt/src/qdbusmetaobject.cpp +++ b/qt/src/qdbusmetaobject.cpp @@ -154,7 +154,7 @@ void QDBusMetaObjectGenerator::parseMethods() break; } - mm.inputSignature += arg.type; + mm.inputSignature += arg.type.toLatin1(); mm.inputTypes.append(typeId); mm.parameters.append(arg.name.toLatin1()); @@ -175,7 +175,7 @@ void QDBusMetaObjectGenerator::parseMethods() break; } - mm.outputSignature += arg.type; + mm.outputSignature += arg.type.toLatin1(); mm.outputTypes.append(typeId); if (i == 0) { @@ -230,7 +230,7 @@ void QDBusMetaObjectGenerator::parseSignals() break; } - mm.inputSignature += arg.type; + mm.inputSignature += arg.type.toLatin1(); mm.inputTypes.append(typeId); mm.parameters.append(arg.name.toLatin1()); @@ -297,16 +297,16 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) if (className.isEmpty()) className = QLatin1String("QDBusInterface"); - QVarLengthArray data; - data.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int)); + QVarLengthArray idata; + idata.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int)); - QDBusMetaObjectPrivate *header = reinterpret_cast(data.data()); + QDBusMetaObjectPrivate *header = reinterpret_cast(idata.data()); header->revision = 1; header->className = 0; header->classInfoCount = 0; header->classInfoData = 0; header->methodCount = methods.count(); - header->methodData = data.size(); + header->methodData = idata.size(); header->propertyCount = properties.count(); header->propertyData = header->methodData + header->methodCount * 5; header->enumeratorCount = 0; @@ -314,12 +314,12 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) header->propertyDBusData = header->propertyData + header->propertyCount * 3; header->methodDBusData = header->propertyDBusData + header->propertyCount * intsPerProperty; - int data_size = data.size() + + int data_size = idata.size() + (header->methodCount * (5+intsPerMethod)) + (header->propertyCount * (3+intsPerProperty)); foreach (const Method &mm, methods) data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count(); - data.resize(data_size + 1); + idata.resize(data_size + 1); char null('\0'); QByteArray stringdata = className.toLatin1(); @@ -329,7 +329,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) int offset = header->methodData; int signatureOffset = header->methodDBusData; int typeidOffset = header->methodDBusData + header->methodCount * intsPerMethod; - data[typeidOffset++] = 0; // eod + idata[typeidOffset++] = 0; // eod // add each method: for (QMap::ConstIterator it = methods.constBegin(); @@ -337,41 +337,41 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) // form "prototype\0parameters\0typeName\0tag\0inputSignature\0outputSignature" const Method &mm = it.value(); - data[offset++] = stringdata.length(); + idata[offset++] = stringdata.length(); stringdata += it.key(); // prototype stringdata += null; - data[offset++] = stringdata.length(); + idata[offset++] = stringdata.length(); stringdata += mm.parameters; stringdata += null; - data[offset++] = stringdata.length(); + idata[offset++] = stringdata.length(); stringdata += mm.typeName; stringdata += null; - data[offset++] = stringdata.length(); + idata[offset++] = stringdata.length(); stringdata += mm.tag; stringdata += null; - data[offset++] = mm.flags; + idata[offset++] = mm.flags; - data[signatureOffset++] = stringdata.length(); + idata[signatureOffset++] = stringdata.length(); stringdata += mm.inputSignature; stringdata += null; - data[signatureOffset++] = stringdata.length(); + idata[signatureOffset++] = stringdata.length(); stringdata += mm.outputSignature; stringdata += null; - data[signatureOffset++] = typeidOffset; - data[typeidOffset++] = mm.inputTypes.count(); - memcpy(data.data() + typeidOffset, mm.inputTypes.data(), mm.inputTypes.count() * sizeof(int)); + idata[signatureOffset++] = typeidOffset; + idata[typeidOffset++] = mm.inputTypes.count(); + memcpy(idata.data() + typeidOffset, mm.inputTypes.data(), mm.inputTypes.count() * sizeof(int)); typeidOffset += mm.inputTypes.count(); - data[signatureOffset++] = typeidOffset; - data[typeidOffset++] = mm.outputTypes.count(); - memcpy(data.data() + typeidOffset, mm.outputTypes.data(), mm.outputTypes.count() * sizeof(int)); + idata[signatureOffset++] = typeidOffset; + idata[typeidOffset++] = mm.outputTypes.count(); + memcpy(idata.data() + typeidOffset, mm.outputTypes.data(), mm.outputTypes.count() * sizeof(int)); typeidOffset += mm.outputTypes.count(); } Q_ASSERT(offset == header->propertyData); Q_ASSERT(signatureOffset == header->methodDBusData + header->methodCount * intsPerMethod); - Q_ASSERT(typeidOffset == data.size()); + Q_ASSERT(typeidOffset == idata.size()); // add each property signatureOffset = header->propertyDBusData; @@ -380,18 +380,18 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) const Property &mp = it.value(); // form is "name\0typeName\0signature\0" - data[offset++] = stringdata.length(); + idata[offset++] = stringdata.length(); stringdata += it.key(); // name stringdata += null; - data[offset++] = stringdata.length(); + idata[offset++] = stringdata.length(); stringdata += mp.typeName; stringdata += null; - data[offset++] = mp.flags; + idata[offset++] = mp.flags; - data[signatureOffset++] = stringdata.length(); + idata[signatureOffset++] = stringdata.length(); stringdata += mp.signature; stringdata += null; - data[signatureOffset++] = mp.type; + idata[signatureOffset++] = mp.type; } Q_ASSERT(offset == header->propertyDBusData); @@ -400,8 +400,8 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj) char *string_data = new char[stringdata.length()]; memcpy(string_data, stringdata, stringdata.length()); - uint *uint_data = new uint[data.size()]; - memcpy(uint_data, data.data(), data.size() * sizeof(int)); + uint *uint_data = new uint[idata.size()]; + memcpy(uint_data, idata.data(), idata.size() * sizeof(int)); // put the metaobject together obj->d.data = uint_data; diff --git a/qt/src/qdbusreply.h b/qt/src/qdbusreply.h index 0b5c12d9..2b69cbb5 100644 --- a/qt/src/qdbusreply.h +++ b/qt/src/qdbusreply.h @@ -53,13 +53,13 @@ public: return *this; } - inline QDBusReply(const QDBusError &error = QDBusError()) - : m_error(error), m_data(Type()) + inline QDBusReply(const QDBusError &dbusError = QDBusError()) + : m_error(dbusError), m_data(Type()) { } - inline QDBusReply& operator=(const QDBusError& error) + inline QDBusReply& operator=(const QDBusError& dbusError) { - m_error = error; + m_error = dbusError; m_data = Type(); return *this; } @@ -114,8 +114,8 @@ public: : m_error(reply) { } - inline QDBusReply(const QDBusError &error) - : m_error(error) + inline QDBusReply(const QDBusError &dbusError) + : m_error(dbusError) { } diff --git a/qt/src/qdbusserver.cpp b/qt/src/qdbusserver.cpp index b3b9835e..4f5b5105 100644 --- a/qt/src/qdbusserver.cpp +++ b/qt/src/qdbusserver.cpp @@ -25,8 +25,8 @@ #include "qdbusserver.h" #include "qdbusconnection_p.h" -QDBusServer::QDBusServer(const QString &addr, QObject *parent) - : QObject(parent) +QDBusServer::QDBusServer(const QString &addr, QObject *p) + : QObject(p) { d = new QDBusConnectionPrivate(this); diff --git a/qt/src/qdbusutil.cpp b/qt/src/qdbusutil.cpp index 872434c5..22ce3a81 100644 --- a/qt/src/qdbusutil.cpp +++ b/qt/src/qdbusutil.cpp @@ -42,13 +42,11 @@ namespace QDBusUtil Returns true if this is \a ifaceName is a valid interface name. Valid interface names must: - \list - \o not be empty - \o not exceed 255 characters in length - \o be composed of dot-separated string components that contain only ASCII letters, digits - and the underscore ("_") character - \o contain at least two such components - \endlist + - not be empty + - not exceed 255 characters in length + - be composed of dot-separated string components that contain only ASCII letters, digits + and the underscore ("_") character + - contain at least two such components */ bool isValidInterfaceName(const QString& ifaceName) { @@ -96,13 +94,11 @@ namespace QDBusUtil Returns true if \a busName is a valid bus name. A valid bus name is either a valid unique connection name or follows the rules: - \list - \o is not empty - \o does not exceed 255 characters in length - \o be composed of dot-separated string components that contain only ASCII letters, digits, - hyphens or underscores ("_"), but don't start with a digit - \o contains at least two such elements - \endlist + - is not empty + - does not exceed 255 characters in length + - be composed of dot-separated string components that contain only ASCII letters, digits, + hyphens or underscores ("_"), but don't start with a digit + - contains at least two such elements \sa isValidUniqueConnectionName() */ @@ -137,7 +133,7 @@ namespace QDBusUtil if (memberName.isEmpty() || memberName.length() > DBUS_MAXIMUM_NAME_LENGTH) return false; - QRegExp regex(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]+")); + QRegExp regex(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*")); return regex.exactMatch(memberName); } @@ -156,13 +152,11 @@ namespace QDBusUtil Returns true if \a path is valid object path. Valid object paths follow the rules: - \list - \o start with the slash character ("/") - \o do not end in a slash, unless the path is just the initial slash - \o do not contain any two slashes in sequence - \o contain slash-separated parts, each of which is composed of ASCII letters, digits and - underscores ("_") - \endlist + - start with the slash character ("/") + - do not end in a slash, unless the path is just the initial slash + - do not contain any two slashes in sequence + - contain slash-separated parts, each of which is composed of ASCII letters, digits and + underscores ("_") */ bool isValidObjectPath(const QString &path) { diff --git a/qt/src/qdbusxmlgenerator.cpp b/qt/src/qdbusxmlgenerator.cpp index cbd5388b..135b8d1c 100644 --- a/qt/src/qdbusxmlgenerator.cpp +++ b/qt/src/qdbusxmlgenerator.cpp @@ -62,7 +62,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method continue; retval += QString(QLatin1String(" \n")) - .arg(mp.name()) + .arg(QLatin1String(mp.name())) .arg(QLatin1String( QDBusUtil::typeToSignature( QVariant::Type(typeId) ))) .arg(QLatin1String( accessvalues[access] )); } @@ -165,7 +165,8 @@ QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo, con if (interface.startsWith( QLatin1String("QDBus") )) { interface.prepend( QLatin1String("com.trolltech.QtDBus.") ); - } else if (interface.startsWith( QLatin1Char('Q') )) { + } else if (interface.startsWith( QLatin1Char('Q') ) && + interface.length() >= 2 && interface.at(1).isUpper()) { // assume it's Qt interface.prepend( QLatin1String("com.trolltech.Qt.") ); } else if (!QCoreApplication::instance() || @@ -173,9 +174,14 @@ QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo, con interface.prepend( QLatin1String("local.") ); } else { interface.prepend(QLatin1Char('.')).prepend( QCoreApplication::instance()->applicationName() ); - QStringList domainName = QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.')); - foreach (const QString &part, domainName) - interface.prepend(QLatin1Char('.')).prepend(part); + QStringList domainName = + QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'), + QString::SkipEmptyParts); + if (domainName.isEmpty()) + interface.prepend("local."); + else + foreach (const QString &part, domainName) + interface.prepend(QLatin1Char('.')).prepend(part); } } } diff --git a/qt/src/qdbusxmlparser.cpp b/qt/src/qdbusxmlparser.cpp index 0370cb23..359967bf 100644 --- a/qt/src/qdbusxmlparser.cpp +++ b/qt/src/qdbusxmlparser.cpp @@ -47,8 +47,11 @@ parseAnnotations(const QDomElement& elem) QString name = ann.attribute(QLatin1String("name")), value = ann.attribute(QLatin1String("value")); - if (name.isEmpty()) + if (!QDBusUtil::isValidInterfaceName(name)) { + qWarning("Invalid D-BUS annotation '%s' found while parsing introspection", + qPrintable(name)); continue; + } retval.insert(name, value); } @@ -74,8 +77,11 @@ parseArgs(const QDomElement& elem, const QLatin1String& direction, bool acceptEm if (arg.hasAttribute(QLatin1String("name"))) argData.name = arg.attribute(QLatin1String("name")); // can be empty argData.type = arg.attribute(QLatin1String("type")); - if (!QDBusUtil::isValidSingleSignature(argData.type)) + if (!QDBusUtil::isValidSingleSignature(argData.type)) { + qWarning("Invalid D-BUS type signature '%s' found while parsing introspection", + qPrintable(argData.type)); continue; + } retval << argData; } @@ -106,13 +112,18 @@ QDBusXmlParser::interfaces() const if (m_node.isNull()) return retval; - QDomNodeList interfaces = m_node.elementsByTagName(QLatin1String("interface")); - for (int i = 0; i < interfaces.count(); ++i) + QDomNodeList interfaceList = m_node.elementsByTagName(QLatin1String("interface")); + for (int i = 0; i < interfaceList.count(); ++i) { - QDomElement iface = interfaces.item(i).toElement(); + QDomElement iface = interfaceList.item(i).toElement(); QString ifaceName = iface.attribute(QLatin1String("name")); - if (iface.isNull() || ifaceName.isEmpty()) + if (iface.isNull()) continue; // for whatever reason + if (!QDBusUtil::isValidInterfaceName(ifaceName)) { + qWarning("Invalid D-BUS interface name '%s' found while parsing introspection", + qPrintable(ifaceName)); + continue; + } QDBusIntrospection::Interface *ifaceData = new QDBusIntrospection::Interface; ifaceData->name = ifaceName; @@ -131,8 +142,13 @@ QDBusXmlParser::interfaces() const { QDomElement method = list.item(j).toElement(); QString methodName = method.attribute(QLatin1String("name")); - if (method.isNull() || methodName.isEmpty()) + if (method.isNull()) continue; + if (!QDBusUtil::isValidMemberName(methodName)) { + qWarning("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection", + qPrintable(methodName), qPrintable(ifaceName)); + continue; + } QDBusIntrospection::Method methodData; methodData.name = methodName; @@ -152,8 +168,13 @@ QDBusXmlParser::interfaces() const { QDomElement signal = list.item(j).toElement(); QString signalName = signal.attribute(QLatin1String("name")); - if (signal.isNull() || signalName.isEmpty()) + if (signal.isNull()) + continue; + if (!QDBusUtil::isValidMemberName(signalName)) { + qWarning("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection", + qPrintable(signalName), qPrintable(ifaceName)); continue; + } QDBusIntrospection::Signal signalData; signalData.name = signalName; @@ -172,8 +193,13 @@ QDBusXmlParser::interfaces() const { QDomElement property = list.item(j).toElement(); QString propertyName = property.attribute(QLatin1String("name")); - if (property.isNull() || propertyName.isEmpty()) + if (property.isNull()) continue; + if (!QDBusUtil::isValidMemberName(propertyName)) { + qWarning("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection", + qPrintable(propertyName), qPrintable(ifaceName)); + continue; + } QDBusIntrospection::Property propertyData; @@ -182,22 +208,27 @@ QDBusXmlParser::interfaces() const propertyData.type = property.attribute(QLatin1String("type")); propertyData.annotations = parseAnnotations(property); - if (!QDBusUtil::isValidSingleSignature(propertyData.type)) + if (!QDBusUtil::isValidSingleSignature(propertyData.type)) { // cannot be! + qWarning("Invalid D-BUS type signature '%s' found in property '%s.%s' while parsing introspection", + qPrintable(propertyData.type), qPrintable(ifaceName), + qPrintable(propertyName)); continue; + } QString access = property.attribute(QLatin1String("access")); - if (access.isEmpty()) - // can't be empty either! - continue; - else if (access == QLatin1String("read")) + if (access == QLatin1String("read")) propertyData.access = QDBusIntrospection::Property::Read; else if (access == QLatin1String("write")) propertyData.access = QDBusIntrospection::Property::Write; else if (access == QLatin1String("readwrite")) propertyData.access = QDBusIntrospection::Property::ReadWrite; - else + else { + qWarning("Invalid D-BUS property access '%s' found in property '%s.%s' while parsing introspection", + qPrintable(access), qPrintable(ifaceName), + qPrintable(propertyName)); continue; // invalid one! + } // add it ifaceData->properties.insert(propertyName, propertyData); @@ -231,18 +262,28 @@ QDBusXmlParser::object() const for (int i = 0; i < objects.count(); ++i) { QDomElement obj = objects.item(i).toElement(); QString objName = obj.attribute(QLatin1String("name")); - if (obj.isNull() || objName.isEmpty()) + if (obj.isNull()) continue; // for whatever reason + if (!QDBusUtil::isValidObjectPath(m_path + QLatin1Char('/') + objName)) { + qWarning("Invalid D-BUS object path '%s/%s' found while parsing introspection", + qPrintable(m_path), qPrintable(objName)); + continue; + } objData->childObjects.append(objName); } - QDomNodeList interfaces = m_node.elementsByTagName(QLatin1String("interface")); - for (int i = 0; i < interfaces.count(); ++i) { - QDomElement iface = interfaces.item(i).toElement(); + QDomNodeList interfaceList = m_node.elementsByTagName(QLatin1String("interface")); + for (int i = 0; i < interfaceList.count(); ++i) { + QDomElement iface = interfaceList.item(i).toElement(); QString ifaceName = iface.attribute(QLatin1String("name")); - if (iface.isNull() || ifaceName.isEmpty()) + if (iface.isNull()) + continue; + if (!QDBusUtil::isValidInterfaceName(ifaceName)) { + qWarning("Invalid D-BUS interface name '%s' found while parsing introspection", + qPrintable(ifaceName)); continue; + } objData->interfaces.append(ifaceName); } @@ -287,8 +328,8 @@ QDBusXmlParser::objectTree() const if (!obj.firstChild().isNull()) { // yes, introspect this object QString xml; - QTextStream ts(&xml); - obj.save(ts,0); + QTextStream ts2(&xml); + obj.save(ts2,0); // parse it QString objAbsName = m_path; diff --git a/qt/tools/Makefile.am b/qt/tools/Makefile.am index a79aafd6..4da3870f 100644 --- a/qt/tools/Makefile.am +++ b/qt/tools/Makefile.am @@ -1,5 +1,5 @@ INCLUDES=-I$(top_srcdir)/qt $(DBUS_CLIENT_CFLAGS) $(DBUS_QT_CFLAGS) -DDBUS_COMPILATION -bin_PROGRAMS = dbusidl2cpp dbuscpp2xml +bin_PROGRAMS = dbusidl2cpp dbuscpp2xml dbus dbusidl2cpp_SOURCES = dbusidl2cpp.cpp dbusidl2cpp_LDFLAGS = -no-undefined @@ -8,3 +8,6 @@ dbusidl2cpp_LDADD = $(DBUS_QT_LIBS) ../src/libdbus-qt4-1.la dbuscpp2xml_SOURCES = dbuscpp2xml.cpp dbuscpp2xml_LDFLAGS = -no-undefined dbuscpp2xml_LDADD = $(DBUS_QT_LIBS) ../src/libdbus-qt4-1.la + +dbus_SOURCES = dbus.cpp +dbus_LDADD = $(DBUS_QT_LIBS) ../src/libdbus-qt4-1.la diff --git a/qt/tools/dbus.cpp b/qt/tools/dbus.cpp new file mode 100644 index 00000000..b2556ef8 --- /dev/null +++ b/qt/tools/dbus.cpp @@ -0,0 +1,397 @@ +/* -*- C++ -*- + * + * Copyright (C) 2006 Trolltech AS. All rights reserved. + * Author: Thiago Macieira + * + * 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 Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +Q_DECLARE_METATYPE(QVariant) +QDBusConnection *connection; + +void listObjects(const QString &service, const QString &path) +{ + QDBusInterfacePtr iface(*connection, service, path.isEmpty() ? "/" : path, + "org.freedesktop.DBus.Introspectable"); + if (!iface->isValid()) { + QDBusError err(iface->lastError()); + fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n", + qPrintable(path.isEmpty() ? "/" : path), qPrintable(service), + qPrintable(err.name()), qPrintable(err.message())); + exit(1); + } + QDBusReply xml = iface->call("Introspect"); + + if (xml.isError()) + return; // silently + + QDomDocument doc; + doc.setContent(xml); + QDomElement node = doc.documentElement(); + QDomElement child = node.firstChildElement(); + while (!child.isNull()) { + if (child.tagName() == QLatin1String("node")) { + QString sub = path + '/' + child.attribute("name"); + printf("%s\n", qPrintable(sub)); + listObjects(service, sub); + } + child = child.nextSiblingElement(); + } +} + +void listInterface(const QString &service, const QString &path, const QString &interface) +{ + QDBusInterfacePtr iface(*connection, service, path, interface); + if (!iface->isValid()) { + QDBusError err(iface->lastError()); + fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n", + qPrintable(interface), qPrintable(path), qPrintable(service), + qPrintable(err.name()), qPrintable(err.message())); + exit(1); + } + const QMetaObject *mo = iface->metaObject(); + + // properties + for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) { + QMetaProperty mp = mo->property(i); + printf("property "); + + if (mp.isReadable() && mp.isWritable()) + printf("readwrite"); + else if (mp.isReadable()) + printf("read"); + else + printf("write"); + + printf(" %s %s.%s\n", mp.typeName(), qPrintable(interface), mp.name()); + } + + // methods (signals and slots) + for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) { + QMetaMethod mm = mo->method(i); + + QByteArray signature = mm.signature(); + signature.truncate(signature.indexOf('(')); + printf("%s %s%s%s %s.%s(", + mm.methodType() == QMetaMethod::Signal ? "signal" : "method", + mm.tag(), *mm.tag() ? " " : "", + *mm.typeName() ? mm.typeName() : "void", + qPrintable(interface), signature.constData()); + + QList types = mm.parameterTypes(); + QList names = mm.parameterNames(); + bool first = true; + for (int i = 0; i < types.count(); ++i) { + printf("%s%s", + first ? "" : ", ", + types.at(i).constData()); + if (!names.at(i).isEmpty()) + printf(" %s", names.at(i).constData()); + first = false; + } + printf(")\n"); + } +} + +void listAllInterfaces(const QString &service, const QString &path) +{ + QDBusInterfacePtr iface(*connection, service, path, "org.freedesktop.DBus.Introspectable"); + if (!iface->isValid()) { + QDBusError err(iface->lastError()); + fprintf(stderr, "Cannot introspect object %s at %s:\n%s (%s)\n", + qPrintable(path), qPrintable(service), + qPrintable(err.name()), qPrintable(err.message())); + exit(1); + } + QDBusReply xml = iface->call("Introspect"); + + if (xml.isError()) + return; // silently + + QDomDocument doc; + doc.setContent(xml); + QDomElement node = doc.documentElement(); + QDomElement child = node.firstChildElement(); + while (!child.isNull()) { + if (child.tagName() == QLatin1String("interface")) { + QString ifaceName = child.attribute("name"); + if (QDBusUtil::isValidInterfaceName(ifaceName)) + listInterface(service, path, ifaceName); + else { + qWarning("Invalid D-BUS interface name '%s' found while parsing introspection", + qPrintable(ifaceName)); + } + } + child = child.nextSiblingElement(); + } +} + +QStringList readList(int &argc, const char *const *&argv) +{ + --argc; + ++argv; + + QStringList retval; + while (argc && QLatin1String(argv[0]) != ")") + retval += QString::fromLocal8Bit(argv[0]); + + return retval; +} + +void placeCall(const QString &service, const QString &path, const QString &interface, + const QString &member, int argc, const char *const *argv) +{ + QDBusInterfacePtr iface(*connection, service, path, interface); + if (!iface->isValid()) { + QDBusError err(iface->lastError()); + fprintf(stderr, "Interface '%s' not available in object %s at %s:\n%s (%s)\n", + qPrintable(interface), qPrintable(path), qPrintable(service), + qPrintable(err.name()), qPrintable(err.message())); + exit(1); + } + + const QMetaObject *mo = iface->metaObject(); + QByteArray match = member.toLatin1(); + match += '('; + + int midx = -1; + for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) { + QMetaMethod mm = mo->method(i); + QByteArray signature = mm.signature(); + if (signature.startsWith(match)) { + midx = i; + break; + } + } + + if (midx == -1) { + fprintf(stderr, "Cannot find '%s.%s' in object %s at %s\n", + qPrintable(interface), qPrintable(member), qPrintable(path), + qPrintable(service)); + exit(1); + } + + QMetaMethod mm = mo->method(midx); + QList types = mm.parameterTypes(); + + QVariantList params; + for (int i = 0; argc && i < types.count(); ++i) { + int id = QVariant::nameToType(types.at(i)); + if ((id == QVariant::UserType || id == QVariant::Map) && types.at(i) != "QVariant") { + fprintf(stderr, "Sorry, can't pass arg of type %s yet\n", + types.at(i).constData()); + exit(1); + } + if (id == QVariant::UserType) + id = QMetaType::type(types.at(i)); + + Q_ASSERT(id); + + QVariant p; + if ((id == QVariant::List || id == QVariant::StringList) && QLatin1String("(") == argv[0]) + p = readList(argc, argv); + else + p = QString::fromLocal8Bit(argv[0]); + + if (id < int(QVariant::UserType)) { + // avoid calling it for QVariant + p.convert( QVariant::Type(id) ); + if (p.type() == QVariant::Invalid) { + fprintf(stderr, "Could not convert '%s' to type '%s'.\n", + argv[0], types.at(i).constData()); + exit(1); + } + } else if (types.at(i) == "QVariant") { + QVariant tmp(id, p.constData()); + p = tmp; + } + params += p; + --argc; + ++argv; + } + if (params.count() != types.count()) { + fprintf(stderr, "Invalid number of parameters\n"); + exit(1); + } + + QDBusMessage reply = iface->callWithArgs(member, params); + if (reply.type() == QDBusMessage::ErrorMessage) { + QDBusError err = reply; + printf("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); + exit(2); + } else if (reply.type() != QDBusMessage::ReplyMessage) { + fprintf(stderr, "Invalid reply type %d\n", int(reply.type())); + exit(1); + } + + foreach (QVariant v, reply) { + if (v.userType() == QVariant::StringList) { + foreach (QString s, v.toStringList()) + printf("%s\n", qPrintable(s)); + } else { + if (v.userType() == qMetaTypeId()) + v = qvariant_cast(v); + printf("%s\n", qPrintable(v.toString())); + } + } + + exit(0); +} + +bool splitInterfaceAndName(const QString &interfaceAndName, const char *type, + QString &interface, QString &member) +{ + interface = interfaceAndName; + int pos = interface.lastIndexOf(QLatin1Char('.')); + if (pos != -1) { + member = interface.mid(pos + 1); + interface.truncate(pos); + } + + if (!QDBusUtil::isValidInterfaceName(interface)) { + fprintf(stderr, "Interface '%s' is not a valid interface name.\n", qPrintable(interface)); + return false; + } else if (!QDBusUtil::isValidMemberName(member)) { + fprintf(stderr, "%s name '%s' is not a valid member name.\n", type, qPrintable(member)); + return false; + } + return true; +} + +void getProperty(const QString &service, const QString &path, const QString &interfaceAndName) +{ + QString property; + QString interface; + if (!splitInterfaceAndName(interfaceAndName, "Property", interface, property)) + exit(1); + + QDBusInterfacePtr iface(*connection, service, path, interface); + QVariant reply = iface->property(property.toLatin1()); + if (reply.isNull()) { + QDBusError error = iface->lastError(); + fprintf(stderr, "Could not get property '%s' on interface '%s': %s (%s)\n", + qPrintable(property), qPrintable(interface), qPrintable(error.name()), + qPrintable(error.message())); + exit(1); + } + + printf("%s\n", qPrintable(reply.toString())); +} + +void setProperty(const QString &service, const QString &path, const QString &interfaceAndName, + const QString &valueStr) +{ + QString property; + QString interface; + if (!splitInterfaceAndName(interfaceAndName, "Property", interface, property)) + exit(1); + + QDBusInterfacePtr iface(*connection, service, path, interface); + iface->setProperty(property.toLatin1(), valueStr); +} + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + if (argc >= 1 && qstrcmp(argv[1], "--system") == 0) { + connection = &QDBus::systemBus(); + --argc; + ++argv; + } else + connection = &QDBus::sessionBus(); + + if (!connection->isConnected()) { + fprintf(stderr, "Could not connect to D-Bus server: %s: %s\n", + qPrintable(connection->lastError().name()), + qPrintable(connection->lastError().message())); + return 1; + } + QDBusBusService *bus = connection->busService(); + + if (argc == 1) { + QStringList names = bus->ListNames(); + foreach (QString name, names) + printf("%s\n", qPrintable(name)); + exit(0); + } + + QString service = QLatin1String(argv[1]); + if (!QDBusUtil::isValidBusName(service)) { + fprintf(stderr, "Service '%s' is not a valid name.\n", qPrintable(service)); + exit(1); + } + if (!bus->NameHasOwner(service)) { + fprintf(stderr, "Service '%s' does not exist.\n", qPrintable(service)); + exit(1); + } + + if (argc == 2) { + printf("/\n"); + listObjects(service, QString()); + exit(0); + } + + QString path = QLatin1String(argv[2]); + if (!QDBusUtil::isValidObjectPath(path)) { + fprintf(stderr, "Path '%s' is not a valid path name.\n", qPrintable(path)); + exit(1); + } + if (argc == 3) { + listAllInterfaces(service, path); + exit(0); + } + + QString interface = QLatin1String(argv[3]); + QString member; + int pos = interface.lastIndexOf(QLatin1Char('.')); + if (pos == -1) { + member = interface; + interface.clear(); + } else { + member = interface.mid(pos + 1); + interface.truncate(pos); + } + if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface)) { + fprintf(stderr, "Interface '%s' is not a valid interface name.\n", qPrintable(interface)); + exit(1); + } + if (!QDBusUtil::isValidMemberName(member)) { + fprintf(stderr, "Method name '%s' is not a valid member name.\n", qPrintable(member)); + exit(1); + } + + if (interface.isEmpty()) { + if (member.toLower() == QLatin1String("get") && argc == 5) { + getProperty(service, path, QLatin1String(argv[4])); + return 0; + } else if (member.toLower() == QLatin1String("set") && argc == 6) { + setProperty(service, path, QLatin1String(argv[4]), QLatin1String(argv[5])); + return 0; + } + } + placeCall(service, path, interface, member, argc - 4, argv + 4); +} + diff --git a/qt/tools/dbuscpp2xml.cpp b/qt/tools/dbuscpp2xml.cpp index dd08b5fd..42d78312 100644 --- a/qt/tools/dbuscpp2xml.cpp +++ b/qt/tools/dbuscpp2xml.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -76,7 +77,7 @@ class MocParser QIODevice *input; const char *filename; - int line; + int lineNumber; public: ~MocParser(); void parse(const char *filename, QIODevice *input, int lineNumber = 0); @@ -86,13 +87,13 @@ public: void MocParser::parseError() { - fprintf(stderr, PROGRAMNAME ": error parsing input file '%s' line %d \n", filename, line); + fprintf(stderr, PROGRAMNAME ": error parsing input file '%s' line %d \n", filename, lineNumber); exit(1); } QByteArray MocParser::readLine() { - ++line; + ++lineNumber; return input->readLine(); } @@ -100,15 +101,15 @@ void MocParser::loadIntData(uint *&data) { data = 0; // initialise QVarLengthArray array; - QRegExp rx("(\\d+|0x[0-9abcdef]+)", Qt::CaseInsensitive); + QRegExp rx(QLatin1String("(\\d+|0x[0-9abcdef]+)"), Qt::CaseInsensitive); while (!input->atEnd()) { QString line = QLatin1String(readLine()); - int pos = line.indexOf("//"); + int pos = line.indexOf(QLatin1String("//")); if (pos != -1) line.truncate(pos); // drop comments - if (line == "};\n") { + if (line == QLatin1String("};\n")) { // end of data data = new uint[array.count()]; memcpy(data, array.data(), array.count() * sizeof(*data)); @@ -118,7 +119,7 @@ void MocParser::loadIntData(uint *&data) pos = 0; while ((pos = rx.indexIn(line, pos)) != -1) { QString num = rx.cap(1); - if (num.startsWith("0x")) + if (num.startsWith(QLatin1String("0x"))) array.append(num.mid(2).toUInt(0, 16)); else array.append(num.toUInt()); @@ -205,7 +206,7 @@ void MocParser::loadStringData(char *&stringdata) } } else { // octal - QRegExp octal("([0-7]+)"); + QRegExp octal(QLatin1String("([0-7]+)")); if (octal.indexIn(QLatin1String(line), start) == -1) parseError(); array.append(char(octal.cap(1).toInt(0, 8))); @@ -218,11 +219,11 @@ void MocParser::loadStringData(char *&stringdata) parseError(); } -void MocParser::parse(const char *fname, QIODevice *io, int lineNumber) +void MocParser::parse(const char *fname, QIODevice *io, int lineNum) { filename = fname; input = io; - line = lineNumber; + lineNumber = lineNum; while (!input->atEnd()) { QByteArray line = readLine(); @@ -360,7 +361,7 @@ int main(int argc, char **argv) else { // run moc on this file QProcess proc; - proc.start("moc", QStringList() << QFile::encodeName(argv[i])); + proc.start(QLatin1String("moc"), QStringList() << QFile::decodeName(argv[i])); if (!proc.waitForStarted()) { fprintf(stderr, PROGRAMNAME ": could not execute moc! Aborting.\n"); diff --git a/qt/tools/dbusidl2cpp.cpp b/qt/tools/dbusidl2cpp.cpp index 091685b4..216c7ced 100644 --- a/qt/tools/dbusidl2cpp.cpp +++ b/qt/tools/dbusidl2cpp.cpp @@ -37,7 +37,7 @@ #include "../src/qdbusintrospection_p.h" #define PROGRAMNAME "dbusidl2cpp" -#define PROGRAMVERSION "0.4" +#define PROGRAMVERSION "0.5" #define PROGRAMCOPYRIGHT "Copyright (C) 2006 Trolltech AS. All rights reserved." #define ANNOTATION_NO_WAIT "org.freedesktop.DBus.Method.NoReply" @@ -68,7 +68,9 @@ static const char help[] = " -V Show the program version and quit.\n" "\n" "If the file name given to the options -a and -p does not end in .cpp or .h, the\n" - "program will automatically append the suffixes and produce both files.\n"; + "program will automatically append the suffixes and produce both files.\n" + "You can also use a colon (:) to separate the header name from the source file\n" + "name, as in '-a filename_p.h:filename.cpp'."; static const char includeList[] = "#include \n" @@ -154,7 +156,7 @@ static void parseCmdLine(int argc, char **argv) static QDBusIntrospection::Interfaces readInput() { QFile input(QFile::decodeName(inputFile)); - if (inputFile && QLatin1String("-") != inputFile) + if (inputFile && qstrcmp(inputFile, "-") != 0) input.open(QIODevice::ReadOnly); else input.open(stdin, QIODevice::ReadOnly); @@ -190,9 +192,11 @@ static QString header(const char *name) if (!name || (name[0] == '-' && name[1] == '\0')) return QString(); - QString retval = QFile::decodeName(name); - if (!retval.endsWith(".h") && !retval.endsWith(".cpp") && !retval.endsWith(".cc")) - retval.append(".h"); + QStringList parts = QFile::decodeName(name).split(QLatin1Char(':')); + QString retval = parts.first(); + if (!retval.endsWith(QLatin1String(".h")) && !retval.endsWith(QLatin1String(".cpp")) && + !retval.endsWith(QLatin1String(".cc"))) + retval.append(QLatin1String(".h")); return retval; } @@ -203,9 +207,11 @@ static QString cpp(const char *name) if (!name || (name[0] == '-' && name[1] == '\0')) return QString(); - QString retval = QFile::decodeName(name); - if (!retval.endsWith(".h") && !retval.endsWith(".cpp") && !retval.endsWith(".cc")) - retval.append(".cpp"); + QStringList parts = QFile::decodeName(name).split(QLatin1Char(':')); + QString retval = parts.last(); + if (!retval.endsWith(QLatin1String(".h")) && !retval.endsWith(QLatin1String(".cpp")) && + !retval.endsWith(QLatin1String(".cc"))) + retval.append(QLatin1String(".cpp")); return retval; } @@ -235,7 +241,7 @@ static QString classNameForInterface(const QString &interface, ClassType classTy if (globalClassName) return QLatin1String(globalClassName); - QStringList parts = interface.split('.'); + QStringList parts = interface.split(QLatin1Char('.')); QString retval; if (classType == Proxy) @@ -249,9 +255,9 @@ static QString classNameForInterface(const QString &interface, ClassType classTy } if (classType == Proxy) - retval += "Interface"; + retval += QLatin1String("Interface"); else - retval += "Adaptor"; + retval += QLatin1String("Adaptor"); return retval; } @@ -283,7 +289,7 @@ static QString constRefArg(const QByteArray &arg) if (!arg.startsWith('Q')) return QLatin1String(arg + ' '); else - return QString("const %1 &").arg( QLatin1String(arg) ); + return QString( QLatin1String("const %1 &") ).arg( QLatin1String(arg) ); } static QStringList makeArgNames(const QDBusIntrospection::Arguments &inputArgs, @@ -295,18 +301,18 @@ static QStringList makeArgNames(const QDBusIntrospection::Arguments &inputArgs, const QDBusIntrospection::Argument &arg = inputArgs.at(i); QString name = arg.name; if (name.isEmpty()) - name = QString("in%1").arg(i); + name = QString( QLatin1String("in%1") ).arg(i); while (retval.contains(name)) - name += "_"; + name += QLatin1String("_"); retval << name; } for (int i = 0; i < outputArgs.count(); ++i) { const QDBusIntrospection::Argument &arg = outputArgs.at(i); QString name = arg.name; if (name.isEmpty()) - name = QString("out%1").arg(i); + name = QString( QLatin1String("out%1") ).arg(i); while (retval.contains(name)) - name += "_"; + name += QLatin1String("_"); retval << name; } return retval; @@ -346,7 +352,7 @@ static void writeArgList(QTextStream &ts, const QStringList &argNames, static QString propertyGetter(const QDBusIntrospection::Property &property) { - QString getter = property.annotations.value("com.trolltech.QtDBus.propertyGetter"); + QString getter = property.annotations.value(QLatin1String("com.trolltech.QtDBus.propertyGetter")); if (getter.isEmpty()) { getter = property.name; getter[0] = getter[0].toLower(); @@ -356,9 +362,9 @@ static QString propertyGetter(const QDBusIntrospection::Property &property) static QString propertySetter(const QDBusIntrospection::Property &property) { - QString setter = property.annotations.value("com.trolltech.QtDBus.propertySetter"); + QString setter = property.annotations.value(QLatin1String("com.trolltech.QtDBus.propertySetter")); if (setter.isEmpty()) { - setter = "set" + property.name; + setter = QLatin1String("set") + property.name; setter[3] = setter[3].toUpper(); } return setter; @@ -369,21 +375,21 @@ static QString stringify(const QString &data) QString retval; int i; for (i = 0; i < data.length(); ++i) { - retval += '\"'; - for ( ; i < data.length() && data[i] != QChar('\n'); ++i) - if (data[i] == '\"') - retval += "\\\""; + retval += QLatin1Char('\"'); + for ( ; i < data.length() && data[i] != QLatin1Char('\n'); ++i) + if (data[i] == QLatin1Char('\"')) + retval += QLatin1String("\\\""); else retval += data[i]; - retval += "\\n\"\n"; + retval += QLatin1String("\\n\"\n"); } return retval; } -static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfaces &interfaces) +static void writeProxy(const char *filename, const QDBusIntrospection::Interfaces &interfaces) { // open the file - QString headerName = header(proxyFile); + QString headerName = header(filename); QFile file(headerName); if (!headerName.isEmpty()) file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text); @@ -391,7 +397,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac file.open(stdout, QIODevice::WriteOnly | QIODevice::Text); QTextStream hs(&file); - QString cppName = cpp(proxyFile); + QString cppName = cpp(filename); QByteArray cppData; QTextStream cs(&cppData); @@ -401,14 +407,14 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac // include guards: QString includeGuard; if (!headerName.isEmpty()) { - includeGuard = headerName.toUpper().replace(QChar('.'), QChar('_')); - int pos = includeGuard.lastIndexOf('/'); + includeGuard = headerName.toUpper().replace(QLatin1Char('.'), QLatin1Char('_')); + int pos = includeGuard.lastIndexOf(QLatin1Char('/')); if (pos != -1) includeGuard = includeGuard.mid(pos + 1); } else { - includeGuard = QString("QDBUSIDL2CPP_PROXY"); + includeGuard = QLatin1String("QDBUSIDL2CPP_PROXY"); } - includeGuard = QString("%1_%2%3") + includeGuard = QString(QLatin1String("%1_%2%3")) .arg(includeGuard) .arg(getpid()) .arg(QDateTime::currentDateTime().toTime_t()); @@ -512,7 +518,8 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac // methods: hs << "public Q_SLOTS: // METHODS" << endl; foreach (const QDBusIntrospection::Method &method, interface->methods) { - bool isAsync = method.annotations.value(ANNOTATION_NO_WAIT) == "true"; + bool isAsync = + method.annotations.value(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true"); if (isAsync && !method.outputArgs.isEmpty()) { fprintf(stderr, "warning: method %s in interface %s is marked 'async' but has output arguments.\n", qPrintable(method.name), qPrintable(interface->name)); @@ -521,7 +528,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac hs << " inline "; - if (method.annotations.value("org.freedesktop.DBus.Deprecated") == "true") + if (method.annotations.value(QLatin1String("org.freedesktop.DBus.Deprecated")) == QLatin1String("true")) hs << "Q_DECL_DEPRECATED "; if (isAsync) @@ -548,7 +555,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac hs << " call(NoWaitForReply, QLatin1String(\""; // rebuild the method input signature: - QString signature = QChar('.'); + QString signature = QLatin1String("."); foreach (const QDBusIntrospection::Argument &arg, method.inputArgs) signature += arg.type; if (signature.length() == 1) @@ -583,7 +590,8 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac hs << "Q_SIGNALS: // SIGNALS" << endl; foreach (const QDBusIntrospection::Signal &signal, interface->signals_) { hs << " "; - if (signal.annotations.value("org.freedesktop.DBus.Deprecated") == "true") + if (signal.annotations.value(QLatin1String("org.freedesktop.DBus.Deprecated")) == + QLatin1String("true")) hs << "Q_DECL_DEPRECATED "; hs << "void " << signal.name << "("; @@ -607,7 +615,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac QStringList current; QString name; if (it != interfaces.constEnd()) { - current = it->constData()->name.split('.'); + current = it->constData()->name.split(QLatin1Char('.')); name = current.takeLast(); } @@ -618,15 +626,15 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac // i parts matched // close last.count() - i namespaces: for (int j = i; j < last.count(); ++j) - hs << QString((last.count() - j - 1 + i) * 2, ' ') << "}" << endl; + hs << QString((last.count() - j - 1 + i) * 2, QLatin1Char(' ')) << "}" << endl; // open current.count() - i namespaces for (int j = i; j < current.count(); ++j) - hs << QString(j * 2, ' ') << "namespace " << current.at(j) << " {" << endl; + hs << QString(j * 2, QLatin1Char(' ')) << "namespace " << current.at(j) << " {" << endl; // add this class: if (!name.isEmpty()) { - hs << QString(current.count() * 2, ' ') + hs << QString(current.count() * 2, QLatin1Char(' ')) << "typedef ::" << classNameForInterface(it->constData()->name, Proxy) << " " << name << ";" << endl; } @@ -643,7 +651,7 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac if (includeMocs) cs << endl - << "#include \"" << proxyFile << ".moc\"" << endl; + << "#include \"" << filename << ".moc\"" << endl; cs.flush(); hs.flush(); @@ -657,10 +665,10 @@ static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfac } } -static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Interfaces &interfaces) +static void writeAdaptor(const char *filename, const QDBusIntrospection::Interfaces &interfaces) { // open the file - QString headerName = header(adaptorFile); + QString headerName = header(filename); QFile file(headerName); if (!headerName.isEmpty()) file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text); @@ -668,7 +676,7 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte file.open(stdout, QIODevice::WriteOnly | QIODevice::Text); QTextStream hs(&file); - QString cppName = cpp(adaptorFile); + QString cppName = cpp(filename); QByteArray cppData; QTextStream cs(&cppData); @@ -678,14 +686,14 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte // include guards: QString includeGuard; if (!headerName.isEmpty()) { - includeGuard = headerName.toUpper().replace(QChar('.'), QChar('_')); - int pos = includeGuard.lastIndexOf('/'); + includeGuard = headerName.toUpper().replace(QLatin1Char('.'), QLatin1Char('_')); + int pos = includeGuard.lastIndexOf(QLatin1Char('/')); if (pos != -1) includeGuard = includeGuard.mid(pos + 1); } else { - includeGuard = QString("QDBUSIDL2CPP_ADAPTOR"); + includeGuard = QLatin1String("QDBUSIDL2CPP_ADAPTOR"); } - includeGuard = QString("%1_%2%3") + includeGuard = QString(QLatin1String("%1_%2%3")) .arg(includeGuard) .arg(getpid()) .arg(QDateTime::currentDateTime().toTime_t()); @@ -794,7 +802,8 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte hs << "public Q_SLOTS: // METHODS" << endl; foreach (const QDBusIntrospection::Method &method, interface->methods) { - bool isAsync = method.annotations.value(ANNOTATION_NO_WAIT) == "true"; + bool isAsync = + method.annotations.value(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true"); if (isAsync && !method.outputArgs.isEmpty()) { fprintf(stderr, "warning: method %s in interface %s is marked 'async' but has output arguments.\n", qPrintable(method.name), qPrintable(interface->name)); @@ -802,7 +811,8 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte } hs << " "; - if (method.annotations.value("org.freedesktop.DBus.Deprecated") == "true") + if (method.annotations.value(QLatin1String("org.freedesktop.DBus.Deprecated")) == + QLatin1String("true")) hs << "Q_DECL_DEPRECATED "; QByteArray returnType; @@ -888,7 +898,8 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte hs << "Q_SIGNALS: // SIGNALS" << endl; foreach (const QDBusIntrospection::Signal &signal, interface->signals_) { hs << " "; - if (signal.annotations.value("org.freedesktop.DBus.Deprecated") == "true") + if (signal.annotations.value(QLatin1String("org.freedesktop.DBus.Deprecated")) == + QLatin1String("true")) hs << "Q_DECL_DEPRECATED "; hs << "void " << signal.name << "("; @@ -909,7 +920,7 @@ static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Inte if (includeMocs) cs << endl - << "#include \"" << adaptorFile << ".moc\"" << endl; + << "#include \"" << filename << ".moc\"" << endl; cs.flush(); hs.flush(); @@ -930,7 +941,8 @@ int main(int argc, char **argv) QDBusIntrospection::Interfaces interfaces = readInput(); cleanInterfaces(interfaces); - writeProxy(proxyFile, interfaces); + if (proxyFile || (!proxyFile && !adaptorFile)) + writeProxy(proxyFile, interfaces); if (adaptorFile) writeAdaptor(adaptorFile, interfaces); -- cgit