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.
+2006-06-05 Thiago Macieira <thiago.macieira@trolltech.com>
+
+ * 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.
+
2006-06-04 Thiago Macieira <thiago.macieira@trolltech.com>
* dbus/Makefile.am:
--- /dev/null
+#include "../src/qdbus.h"
--- /dev/null
+#include "../src/qdbusabstractadaptor.h"
--- /dev/null
+#include "../src/qdbusabstractadaptor_p.h"
--- /dev/null
+#include "../src/qdbusabstractinterface.h"
--- /dev/null
+#include "../src/qdbusabstractinterface_p.h"
--- /dev/null
+#include "../src/qdbusbus.h"
--- /dev/null
+#include "../src/qdbusconnection.h"
--- /dev/null
+#include "../src/qdbusconnection_p.h"
--- /dev/null
+#include "../src/qdbuserror.h"
--- /dev/null
+#include "../src/qdbusinterface.h"
--- /dev/null
+#include "../src/qdbusinterface_p.h"
--- /dev/null
+#include "../src/qdbusintrospection_p.h"
--- /dev/null
+#include "../src/qdbusmacros.h"
--- /dev/null
+#include "../src/qdbusmarshall_p.h"
--- /dev/null
+#include "../src/qdbusmessage.h"
--- /dev/null
+#include "../src/qdbusmessage_p.h"
--- /dev/null
+#include "../src/qdbusmetaobject_p.h"
--- /dev/null
+#include "../src/qdbusreply.h"
--- /dev/null
+#include "../src/qdbusserver.h"
--- /dev/null
+#include "../src/qdbustype_p.h"
--- /dev/null
+#include "../src/qdbustypehelper_p.h"
--- /dev/null
+#include "../src/qdbusutil.h"
--- /dev/null
+#include "../src/qdbusxmlparser_p.h"
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
*/
#include <stdio.h>
+#include <stdlib.h>
#include <dbus/qdbus.h>
#include <QtCore/QCoreApplication>
*/
#include <stdio.h>
+#include <stdlib.h>
#include <dbus/qdbus.h>
#include <QtCore/QCoreApplication>
}
/*!
- \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.
*/
*/
/*!
- 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()));
}
}
-QDBusAdaptorConnector::QDBusAdaptorConnector(QObject *parent)
- : QObject(parent), waitingForPolish(false), lastSignalIdx(0), argv(0)
+QDBusAdaptorConnector::QDBusAdaptorConnector(QObject *obj)
+ : QObject(obj), waitingForPolish(false), lastSignalIdx(0), argv(0)
{
}
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<QDBusAbstractAdaptor *>(sender)->parent();
+ QObject *object = static_cast<QDBusAbstractAdaptor *>(senderObj)->parent();
// break down the parameter list
QList<int> types;
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);
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;
}
/*!
- \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
\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<QVariant>& args,
CallMode mode)
}
/*!
- \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<QStringList> QDBusBusService::ListQueuedOwners(const QString &service)
+QDBusReply<QStringList> 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<bool> QDBusBusService::NameHasOwner(const QString &service)
+QDBusReply<bool> QDBusBusService::NameHasOwner(const QString &serviceName)
{
- return call(QLatin1String("NameHasOwner.s"), service);
+ return call(QLatin1String("NameHasOwner.s"), serviceName);
}
/*!
}
/*!
- \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<QByteArray> QDBusBusService::GetConnectionSELinuxSecurityContext(const QString &service)
+QDBusReply<QByteArray> 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<uint> QDBusBusService::GetConnectionUnixProcessID(const QString &service)
+QDBusReply<uint> 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<uint> QDBusBusService::GetConnectionUnixUser(const QString &service)
+QDBusReply<uint> QDBusBusService::GetConnectionUnixUser(const QString &serviceName)
{
- return call(QLatin1String("GetConnectionUnixUser.s"), service);
+ return call(QLatin1String("GetConnectionUnixUser.s"), serviceName);
}
/*!
{ 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::RequestNameReply>
-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::ReleaseNameReply>
-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.
*/
/*!
- \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.
QDBusReply<StartServiceReply> 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<QString> hello()
{ return Hello(); }
QDBusReply<void> reloadConfig()
QDBusReply<QStringList> listNames()
{ return ListNames(); }
- QDBusReply<bool> nameHasOwner(const QString &service)
- { return NameHasOwner(service); }
+ QDBusReply<bool> nameHasOwner(const QString &serviceName)
+ { return NameHasOwner(serviceName); }
QDBusReply<QString> nameOwner(const QString &name)
{ return GetNameOwner(name); }
- QDBusReply<ReleaseNameReply> releaseName(const QString &service)
- { return ReleaseName(service); }
- QDBusReply<RequestNameReply> requestName(const QString &service, RequestNameOptions flags)
- { return RequestName(service, flags); }
- QDBusReply<QStringList> listQueuedOwners(const QString &service)
- { return ListQueuedOwners(service); }
+ QDBusReply<ReleaseNameReply> releaseName(const QString &serviceName)
+ { return ReleaseName(serviceName); }
+ QDBusReply<RequestNameReply> requestName(const QString &serviceName, RequestNameOptions flags)
+ { return RequestName(serviceName, flags); }
+ QDBusReply<QStringList> listQueuedOwners(const QString &serviceName)
+ { return ListQueuedOwners(serviceName); }
QDBusReply<void> addMatch(const QString &rule)
{ return AddMatch(rule); }
QDBusReply<void> removeMatch(const QString &rule)
{ return RemoveMatch(rule); }
- QDBusReply<QByteArray> connectionSELinuxSecurityContext(const QString &service)
- { return GetConnectionSELinuxSecurityContext(service); }
- QDBusReply<uint> connectionUnixProcessID(const QString &service)
- { return GetConnectionUnixProcessID(service); }
- QDBusReply<uint> connectionUnixUser(const QString &service)
- { return GetConnectionUnixUser(service); }
+ QDBusReply<QByteArray> connectionSELinuxSecurityContext(const QString &serviceName)
+ { return GetConnectionSELinuxSecurityContext(serviceName); }
+ QDBusReply<uint> connectionUnixProcessID(const QString &serviceName)
+ { return GetConnectionUnixProcessID(serviceName); }
+ QDBusReply<uint> connectionUnixUser(const QString &serviceName)
+ { return GetConnectionUnixUser(serviceName); }
QDBusReply<StartServiceReply> 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);
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
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
// 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 &&
*/
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;
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;
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);
}
private:
QDBusAbstractInterfacePrivate *findInterface_helper(const QString &, const QString &,
- const QString&);
+ const char*);
QDBusConnectionPrivate *d;
};
template<class Interface>
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;
}
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)
(\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)
\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;
}
/*!
match.
*/
-#ifndef QT_NO_DEBUG
+#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QDBusError &msg)
{
dbg.nospace() << "QDBusError(" << msg.name() << ", " << msg.message() << ")";
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
{
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;
}
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<T> to QVariantList
else if (mid == QDBusTypeHelper<double>::listId())
out = qVariantFromValue(QDBusTypeHelper<double>::toVariantList(in));
else
- error = true;
+ isOk = false;
} else if (in.type() == QVariant::UInt) {
if (id == QMetaType::UChar) {
uchar uc = in.toUInt();
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);
return;
}
-void QDBusConnectionPrivate::customEvent(QEvent *event)
+void QDBusConnectionPrivate::customEvent(QEvent *e)
{
// nothing else should be sending custom events at us
- CallDeliveryEvent* call = static_cast<CallDeliveryEvent *>(event);
+ CallDeliveryEvent* call = static_cast<CallDeliveryEvent *>(e);
// self check:
Q_ASSERT(call->conn == this);
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();
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;
}
}
key = mname;
key.reserve(interface.length() + 1 + mname.length());
- key += ':';
+ key += QLatin1Char(':');
key += interface;
if (buildSignature) {
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;
}
{
QString key = msg.member();
key.reserve(key.length() + 1 + msg.interface().length());
- key += ':';
+ key += QLatin1Char(':');
key += msg.interface();
QReadLocker locker(&lock);
}
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();
// 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 &&
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();
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"));
}
if (!_clname) return 0;
if (!strcmp(_clname, "QDBusInterface"))
return static_cast<void*>(const_cast<QDBusInterface*>(this));
- if (d_func()->interface == _clname)
+ if (d_func()->interface.toLatin1() == _clname)
return static_cast<void*>(const_cast<QDBusInterface*>(this));
return QDBusAbstractInterface::qt_metacast(_clname);
}
} 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);
}
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))
{
}
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);
}
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.
/*!
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
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;
}
/*!
value.
*/
-#ifndef QT_NO_DEBUG
+#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t)
{
switch (t)
QDBusMessagePrivate *d_ptr;
};
-#ifndef QT_NO_DEBUG
+#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug, const QDBusMessage &);
#endif
break;
}
- mm.inputSignature += arg.type;
+ mm.inputSignature += arg.type.toLatin1();
mm.inputTypes.append(typeId);
mm.parameters.append(arg.name.toLatin1());
break;
}
- mm.outputSignature += arg.type;
+ mm.outputSignature += arg.type.toLatin1();
mm.outputTypes.append(typeId);
if (i == 0) {
break;
}
- mm.inputSignature += arg.type;
+ mm.inputSignature += arg.type.toLatin1();
mm.inputTypes.append(typeId);
mm.parameters.append(arg.name.toLatin1());
if (className.isEmpty())
className = QLatin1String("QDBusInterface");
- QVarLengthArray<int> data;
- data.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int));
+ QVarLengthArray<int> idata;
+ idata.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int));
- QDBusMetaObjectPrivate *header = reinterpret_cast<QDBusMetaObjectPrivate *>(data.data());
+ QDBusMetaObjectPrivate *header = reinterpret_cast<QDBusMetaObjectPrivate *>(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;
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();
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<QByteArray, Method>::ConstIterator it = methods.constBegin();
// 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;
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);
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;
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;
}
: m_error(reply)
{
}
- inline QDBusReply(const QDBusError &error)
- : m_error(error)
+ inline QDBusReply(const QDBusError &dbusError)
+ : m_error(dbusError)
{
}
#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);
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)
{
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()
*/
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);
}
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)
{
continue;
retval += QString(QLatin1String(" <property name=\"%1\" type=\"%2\" access=\"%3\" />\n"))
- .arg(mp.name())
+ .arg(QLatin1String(mp.name()))
.arg(QLatin1String( QDBusUtil::typeToSignature( QVariant::Type(typeId) )))
.arg(QLatin1String( accessvalues[access] ));
}
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() ||
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);
}
}
}
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);
}
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;
}
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;
{
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;
{
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;
{
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;
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);
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);
}
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;
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
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
*/
#include <stdio.h>
+#include <stdlib.h>
#include <dbus/qdbus.h>
#include <QtCore/QCoreApplication>
QDomElement child = node.firstChildElement();
while (!child.isNull()) {
if (child.tagName() == QLatin1String("interface")) {
- listInterface(service, path, child.attribute("name"));
+ 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();
}
else
p = QString::fromLocal8Bit(argv[0]);
- if (id < int(QVariant::UserType))
+ if (id < int(QVariant::UserType)) {
// avoid calling it for QVariant
p.convert( QVariant::Type(id) );
- else if (types.at(i) == "QVariant") {
+ 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;
}
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);
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);
}
#include <QRegExp>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
QIODevice *input;
const char *filename;
- int line;
+ int lineNumber;
public:
~MocParser();
void parse(const char *filename, QIODevice *input, int lineNumber = 0);
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();
}
{
data = 0; // initialise
QVarLengthArray<uint> 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));
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());
}
} 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)));
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();
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");
#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"
" -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 <QtCore/QByteArray>\n"
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);
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;
}
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;
}
if (globalClassName)
return QLatin1String(globalClassName);
- QStringList parts = interface.split('.');
+ QStringList parts = interface.split(QLatin1Char('.'));
QString retval;
if (classType == Proxy)
}
if (classType == Proxy)
- retval += "Interface";
+ retval += QLatin1String("Interface");
else
- retval += "Adaptor";
+ retval += QLatin1String("Adaptor");
return retval;
}
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,
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;
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();
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;
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);
file.open(stdout, QIODevice::WriteOnly | QIODevice::Text);
QTextStream hs(&file);
- QString cppName = cpp(proxyFile);
+ QString cppName = cpp(filename);
QByteArray cppData;
QTextStream cs(&cppData);
// 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());
// 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));
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)
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)
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 << "(";
QStringList current;
QString name;
if (it != interfaces.constEnd()) {
- current = it->constData()->name.split('.');
+ current = it->constData()->name.split(QLatin1Char('.'));
name = current.takeLast();
}
// 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;
}
if (includeMocs)
cs << endl
- << "#include \"" << proxyFile << ".moc\"" << endl;
+ << "#include \"" << filename << ".moc\"" << endl;
cs.flush();
hs.flush();
}
}
-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);
file.open(stdout, QIODevice::WriteOnly | QIODevice::Text);
QTextStream hs(&file);
- QString cppName = cpp(adaptorFile);
+ QString cppName = cpp(filename);
QByteArray cppData;
QTextStream cs(&cppData);
// 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());
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));
}
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;
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 << "(";
if (includeMocs)
cs << endl
- << "#include \"" << adaptorFile << ".moc\"" << endl;
+ << "#include \"" << filename << ".moc\"" << endl;
cs.flush();
hs.flush();
QDBusIntrospection::Interfaces interfaces = readInput();
cleanInterfaces(interfaces);
- writeProxy(proxyFile, interfaces);
+ if (proxyFile || (!proxyFile && !adaptorFile))
+ writeProxy(proxyFile, interfaces);
if (adaptorFile)
writeAdaptor(adaptorFile, interfaces);