Changeset 561 for trunk/src/dbus/qdbusmessage.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/dbus/qdbusmessage.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtDBus module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 45 45 #include <qstringlist.h> 46 46 47 #include <qdbus_symbols_p.h>47 #include "qdbus_symbols_p.h" 48 48 49 49 #include "qdbusargument_p.h" … … 63 63 QDBusMessagePrivate::QDBusMessagePrivate() 64 64 : msg(0), reply(0), type(DBUS_MESSAGE_TYPE_INVALID), 65 timeout(-1), localReply(0), ref(1), delayedReply(false), localMessage(false) 65 timeout(-1), localReply(0), ref(1), delayedReply(false), localMessage(false), 66 parametersValidated(false) 66 67 { 67 68 } … … 95 96 Constructs a DBusMessage object from this object. The returned value must be de-referenced 96 97 with q_dbus_message_unref. 97 */ 98 DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message) 99 { 100 if (!qdbus_loadLibDBus()) 98 99 The \a error object is set to indicate the error if anything went wrong with the 100 marshalling. Usually, this error message will be placed in the reply, as if the call failed. 101 The \a error pointer must not be null. 102 */ 103 DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDBusError *error) 104 { 105 if (!qdbus_loadLibDBus()) { 106 *error = QDBusError(QDBusError::Failed, QLatin1String("Could not open lidbus-1 library")); 101 107 return 0; 108 } 102 109 103 110 DBusMessage *msg = 0; … … 109 116 break; 110 117 case DBUS_MESSAGE_TYPE_METHOD_CALL: 111 msg = q_dbus_message_new_method_call(data(d_ptr->service.toUtf8()), data(d_ptr->path.toUtf8()), 112 data(d_ptr->interface.toUtf8()), data(d_ptr->name.toUtf8())); 118 // only service and interface can be empty -> path and name must not be empty 119 if (!d_ptr->parametersValidated) { 120 if (!QDBusUtil::checkBusName(d_ptr->service, QDBusUtil::EmptyAllowed, error)) 121 return 0; 122 if (!QDBusUtil::checkObjectPath(d_ptr->path, QDBusUtil::EmptyNotAllowed, error)) 123 return 0; 124 if (!QDBusUtil::checkInterfaceName(d_ptr->interface, QDBusUtil::EmptyAllowed, error)) 125 return 0; 126 if (!QDBusUtil::checkMemberName(d_ptr->name, QDBusUtil::EmptyNotAllowed, error, "method")) 127 return 0; 128 } 129 130 msg = q_dbus_message_new_method_call(data(d_ptr->service.toUtf8()), d_ptr->path.toUtf8(), 131 data(d_ptr->interface.toUtf8()), d_ptr->name.toUtf8()); 113 132 break; 114 133 case DBUS_MESSAGE_TYPE_METHOD_RETURN: … … 120 139 break; 121 140 case DBUS_MESSAGE_TYPE_ERROR: 141 // error name can't be empty 142 if (!d_ptr->parametersValidated 143 && !QDBusUtil::checkErrorName(d_ptr->name, QDBusUtil::EmptyNotAllowed, error)) 144 return 0; 145 122 146 msg = q_dbus_message_new(DBUS_MESSAGE_TYPE_ERROR); 123 q_dbus_message_set_error_name(msg, d ata(d_ptr->name.toUtf8()));147 q_dbus_message_set_error_name(msg, d_ptr->name.toUtf8()); 124 148 if (!d_ptr->localMessage) { 125 149 q_dbus_message_set_destination(msg, q_dbus_message_get_sender(d_ptr->reply)); … … 128 152 break; 129 153 case DBUS_MESSAGE_TYPE_SIGNAL: 130 msg = q_dbus_message_new_signal(data(d_ptr->path.toUtf8()), data(d_ptr->interface.toUtf8()), 131 data(d_ptr->name.toUtf8())); 154 // nothing can be empty here 155 if (!d_ptr->parametersValidated) { 156 if (!QDBusUtil::checkObjectPath(d_ptr->path, QDBusUtil::EmptyNotAllowed, error)) 157 return 0; 158 if (!QDBusUtil::checkInterfaceName(d_ptr->interface, QDBusUtil::EmptyAllowed, error)) 159 return 0; 160 if (!QDBusUtil::checkMemberName(d_ptr->name, QDBusUtil::EmptyNotAllowed, error, "method")) 161 return 0; 162 } 163 164 msg = q_dbus_message_new_signal(d_ptr->path.toUtf8(), d_ptr->interface.toUtf8(), 165 d_ptr->name.toUtf8()); 132 166 break; 133 167 default: … … 135 169 break; 136 170 } 137 #if 0 138 DBusError err; 139 q_dbus_error_init(&err); 140 if (q_dbus_error_is_set(&err)) { 141 QDBusError qe(&err); 142 qDebug() << "QDBusMessagePrivate::toDBusMessage" << qe; 143 } 144 #endif 145 if (!msg) 146 return 0; 171 172 // if we got here, the parameters validated 173 // and since the message parameters cannot be changed once the message is created 174 // we can record this fact 175 d_ptr->parametersValidated = true; 147 176 148 177 QDBusMarshaller marshaller; … … 162 191 // not ok; 163 192 q_dbus_message_unref(msg); 164 Q_ASSERT(false);193 *error = QDBusError(QDBusError::Failed, QLatin1String("Marshalling failed: ") + marshaller.errorString); 165 194 return 0; 166 195 } … … 240 269 // we must marshall and demarshall again so as to create QDBusArgument 241 270 // entries for the complex types 242 DBusMessage *message = toDBusMessage(asSent); 271 QDBusError error; 272 DBusMessage *message = toDBusMessage(asSent, &error); 273 if (!message) { 274 // failed to marshall, so it's a call error 275 return QDBusMessage::createError(error); 276 } 277 243 278 q_dbus_message_set_sender(message, conn.baseService.toUtf8()); 244 279 … … 459 494 the message \a msg. Returns the DBus message. 460 495 */ 496 QDBusMessage QDBusMessage::createErrorReply(QDBusError::ErrorType atype, const QString &amsg) const 497 { 498 QDBusMessage msg = createErrorReply(QDBusError::errorString(atype), amsg); 499 msg.d_ptr->parametersValidated = true; 500 return msg; 501 } 502 461 503 462 504 /*! … … 666 708 */ 667 709 #ifndef QT_NO_DEBUG_STREAM 668 QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t)710 static QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t) 669 711 { 670 712 switch (t)
Note:
See TracChangeset
for help on using the changeset viewer.