Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/dbus/qdbusmessage.cpp

    r2 r561  
    22**
    33** 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)
    56**
    67** This file is part of the QtDBus module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** 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.
    3838** $QT_END_LICENSE$
    3939**
     
    4545#include <qstringlist.h>
    4646
    47 #include <qdbus_symbols_p.h>
     47#include "qdbus_symbols_p.h"
    4848
    4949#include "qdbusargument_p.h"
     
    6363QDBusMessagePrivate::QDBusMessagePrivate()
    6464    : 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)
    6667{
    6768}
     
    9596    Constructs a DBusMessage object from this object. The returned value must be de-referenced
    9697    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*/
     103DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDBusError *error)
     104{
     105    if (!qdbus_loadLibDBus()) {
     106        *error = QDBusError(QDBusError::Failed, QLatin1String("Could not open lidbus-1 library"));
    101107        return 0;
     108    }
    102109
    103110    DBusMessage *msg = 0;
     
    109116        break;
    110117    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());
    113132        break;
    114133    case DBUS_MESSAGE_TYPE_METHOD_RETURN:
     
    120139        break;
    121140    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
    122146        msg = q_dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
    123         q_dbus_message_set_error_name(msg, data(d_ptr->name.toUtf8()));
     147        q_dbus_message_set_error_name(msg, d_ptr->name.toUtf8());
    124148        if (!d_ptr->localMessage) {
    125149            q_dbus_message_set_destination(msg, q_dbus_message_get_sender(d_ptr->reply));
     
    128152        break;
    129153    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());
    132166        break;
    133167    default:
     
    135169        break;
    136170    }
    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;
    147176
    148177    QDBusMarshaller marshaller;
     
    162191    // not ok;
    163192    q_dbus_message_unref(msg);
    164     Q_ASSERT(false);
     193    *error = QDBusError(QDBusError::Failed, QLatin1String("Marshalling failed: ") + marshaller.errorString);
    165194    return 0;
    166195}
     
    240269            // we must marshall and demarshall again so as to create QDBusArgument
    241270            // 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
    243278            q_dbus_message_set_sender(message, conn.baseService.toUtf8());
    244279
     
    459494  the message \a msg. Returns the DBus message.
    460495*/
     496QDBusMessage 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
    461503
    462504/*!
     
    666708*/
    667709#ifndef QT_NO_DEBUG_STREAM
    668 QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t)
     710static QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t)
    669711{
    670712    switch (t)
Note: See TracChangeset for help on using the changeset viewer.