diff options
-rw-r--r-- | kde3/src/dapiimpl.cpp | 255 | ||||
-rw-r--r-- | kde3/src/dapiimpl.h | 2 | ||||
-rw-r--r-- | kde3/src/kabchandler.cpp | 9 | ||||
-rw-r--r-- | kde3/src/kabchandler.h | 2 |
4 files changed, 220 insertions, 48 deletions
diff --git a/kde3/src/dapiimpl.cpp b/kde3/src/dapiimpl.cpp index a08a4a8..28dd0bc 100644 --- a/kde3/src/dapiimpl.cpp +++ b/kde3/src/dapiimpl.cpp @@ -22,6 +22,8 @@ #include <kglobalsettings.h> #include <kprocess.h> #include <krun.h> +#include <kurl.h> +#include <kio/netaccess.h> // Qt D-Bus includes #include <dbus/qdbusdata.h> @@ -123,9 +125,9 @@ bool DAPIImpl::Capabilities(Q_INT32& capabilities, QDBusError& error) capabilities |= DAPI_CAP_RUNASUSER; capabilities |= DAPI_CAP_SUSPENDSCREENSAVING; capabilities |= DAPI_CAP_MAILTO; - //capabilities |= DAPI_CAP_LOCALFILE; - //capabilities |= DAPI_CAP_UPLOADFILE; - //capabilities |= DAPI_CAP_REMOVETEMPORARYLOCALFILE; + capabilities |= DAPI_CAP_LOCALFILE; + capabilities |= DAPI_CAP_UPLOADFILE; + capabilities |= DAPI_CAP_REMOVETEMPORARYLOCALFILE; capabilities |= DAPI_CAP_ADDRESSBOOKLIST; capabilities |= DAPI_CAP_ADDRESSBOOKGETNAME; capabilities |= DAPI_CAP_ADDRESSBOOKGETEMAILS; @@ -143,9 +145,14 @@ bool DAPIImpl::OpenUrl(const QString& url, const QDBusVariant& windowinfo, { Q_UNUSED(windowinfo); - error = QDBusError("org.freedesktop.dapi.Error", "OpenUrl failed"); + KURL realURL = KURL::fromPathOrURL(url); - if (url.isEmpty()) return false; + if (!realURL.isValid()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + QString("Parameter 'url'(%1) malformed").arg(url)); + return false; + } QCString startupInfo = dapiMakeStartupInfo(windowinfo); @@ -161,9 +168,14 @@ bool DAPIImpl::ExecuteUrl(const QString& url, const QDBusVariant& windowinfo, { Q_UNUSED(windowinfo); - error = QDBusError("org.freedesktop.dapi.Error", "ExecuteUrl failed"); + KURL realURL = KURL::fromPathOrURL(url); - if (url.isEmpty()) return false; + if (!realURL.isValid()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + QString("Parameter 'url'(%1) malformed").arg(url)); + return false; + } KRun* run = new KRun(url); @@ -175,7 +187,14 @@ bool DAPIImpl::ExecuteUrl(const QString& url, const QDBusVariant& windowinfo, QObject::connect(run, SIGNAL(destroyed()), widget, SLOT(deleteLater())); } - return !run->hasError(); + if (run->hasError()) + { + error = QDBusError("org.freedesktop.DBus.Error.Failed", + QString("Executing (%1) failed").arg(url)); + return false; + } + + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -198,9 +217,14 @@ bool DAPIImpl::RunAsUser(const QString& user, const QString& command, { Q_UNUSED(windowinfo); - error = QDBusError("org.freedesktop.dapi.Error", "RunAsUser failed"); + if (user.isEmpty() || command.isEmpty()) + { + QString message("Parameter 'user'(%1) or paramerter 'command' empty"); + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + message.arg(user).arg(command)); - if (user.isEmpty() || command.isEmpty()) return false; + return false; + } KProcess proc; // TODO use windowinfo proc.setUseShell(true); // TODO quoting @@ -209,7 +233,16 @@ bool DAPIImpl::RunAsUser(const QString& user, const QString& command, proc << "-u" << user; proc << "--" << command; - return proc.start( KProcess::DontCare ); + if (proc.start(KProcess::DontCare)) + { + QString message("Executing command (%1) failed. Exit status (%2)"); + error = QDBusError("org.freedesktop.DBus.Error.Failed", + message.arg(command).arg(proc.exitStatus())); + + return false; + } + + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -255,15 +288,58 @@ bool DAPIImpl::LocalFile(const QString& url, const QString& local, bool allow_download, QString& filename, const QDBusVariant& windowinfo, QDBusError& error) { - Q_UNUSED(url); - Q_UNUSED(local); - Q_UNUSED(allow_download); - Q_UNUSED(filename); - Q_UNUSED(windowinfo); + // save sender since downloading will allow other calls to come in + QString sender = m_currentMethodCall.sender(); + + KURL realURL = KURL::fromPathOrURL(url); + + if (!realURL.isValid()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + QString("Parameter 'url'(%1) malformed").arg(url)); + return false; + } - error = QDBusError("org.freedesktop.dapi.Error", "NotImplementedYet"); + if (realURL.isLocalFile()) + { + filename = realURL.path(); + } + else if (!allow_download) + { + error = QDBusError("org.freedesktop.DBus.Error.Failed", + "Parameter 'url' points to remote file, " + "but downloading is not allowed"); + return false; + } + else + { + QWidget* widget = 0; + WId windowID = dapiWindowID(windowinfo); + if (windowID != 0) + { + widget = new KDapiFakeWidget(windowID); + } + + // initialize download target filename + filename = local; + + bool result = KIO::NetAccess::download(realURL, filename, widget); + + delete widget; + + if (!result) + { + error = QDBusError("org.freedesktop.DBus.Error.Failed", + KIO::NetAccess::lastErrorString()); - return false; + return false; + } + + // if the passed filename is empty, NetAccess has created a temporary file + if (local.isEmpty()) m_temporaryFiles.insert(filename, sender); + } + + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -272,25 +348,92 @@ bool DAPIImpl::UploadFile(const QString& local, const QString& url, bool remove_local, const QDBusVariant& windowinfo, QDBusError& error) { - Q_UNUSED(local); - Q_UNUSED(url); - Q_UNUSED(remove_local); - Q_UNUSED(windowinfo); + KURL localURL = KURL::fromPathOrURL(local); + if (!localURL.isValid()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + QString("Parameter 'local'(%1) malformed").arg(local)); + return false; + } + + if (!localURL.isLocalFile()) + { + QString message("Parameter 'local'(%1) is not a local file"); + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + message.arg(local)); + return false; + } - error = QDBusError("org.freedesktop.dapi.Error", "NotImplementedYet"); + KURL realURL = KURL::fromPathOrURL(url); - return false; + if (!realURL.isValid()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + QString("Parameter 'url'(%1) malformed").arg(url)); + return false; + } + + if (realURL.isLocalFile() && localURL.pathOrURL() == realURL.pathOrURL()) + { + // source and destination actually the same file + return true; + } + else + { + QWidget* widget = 0; + WId windowID = dapiWindowID(windowinfo); + if (windowID != 0) + { + widget = new KDapiFakeWidget(windowID); + } + + bool result = false; + + if (remove_local) + result = KIO::NetAccess::move(localURL, realURL, widget); + else + result = KIO::NetAccess::upload(localURL.pathOrURL(), realURL, widget); + + delete widget; + + if (!result) + { + error = QDBusError("org.freedesktop.DBus.Error.Failed", + KIO::NetAccess::lastErrorString()); + + return false; + } + } + + return true; } /////////////////////////////////////////////////////////////////////////////// bool DAPIImpl::RemoveTemporaryLocalFile(const QString& local, QDBusError& error) { - Q_UNUSED(local); + QMap<QString, QString>::const_iterator it = m_temporaryFiles.find(local); + if (it == m_temporaryFiles.end()) + { + QString message("Parameter 'local' (%1) is not a valid temporary file"); + + error = QDBusError("org.freedesktop.DBus.Error.FileNotFound", + message.arg(local)); + return false; + } - error = QDBusError("org.freedesktop.dapi.Error", "NotImplementedYet"); + if (it.data() != m_currentMethodCall.sender()) + { + QString message("Temporary file (%1) owned by connection (%2)"); + error = QDBusError("org.freedesktop.DBus.Error.AcessDenied", + message.arg(local).arg(it.data())); + return false; + } - return false; + m_temporaryFiles.remove(local); + KIO::NetAccess::removeTempFile(local); + + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -298,11 +441,11 @@ bool DAPIImpl::RemoveTemporaryLocalFile(const QString& local, QDBusError& error) bool DAPIImpl::AddressBookList(QStringList& contact_ids, QDBusError& error) { - error = QDBusError("org.freedesktop.dapi.Error", "AddressBookList failed"); + Q_UNUSED(error); contact_ids = addressBook()->listUIDs(); - return !contact_ids.isEmpty(); + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -322,14 +465,16 @@ bool DAPIImpl::AddressBookFindByName(const QString& name, QStringList& contact_ids, QDBusError& error) { - error = QDBusError("org.freedesktop.dapi.Error", - "AddressBookFindByName failed"); - - if (name.isEmpty()) return false; + if (name.isEmpty()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + "Parameter 'name' is empty"); + return false; + } contact_ids = addressBook()->findByName(name); - return !contact_ids.isEmpty(); + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -338,9 +483,12 @@ bool DAPIImpl::AddressBookGetName(const QString& contact_id, QString& given_name QString& family_name, QString& full_name, QDBusError& error) { - error = QDBusError("org.freedesktop.dapi.Error", "AddressBookGetName failed"); - - if (contact_id.isEmpty()) return false; + if (contact_id.isEmpty()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + "Parameter 'contact_id' is empty"); + return false; + } return addressBook()->getNames(contact_id, given_name, family_name, full_name); } @@ -351,9 +499,12 @@ bool DAPIImpl::AddressBookGetEmails(const QString& contact_id, QStringList& email_addresses, QDBusError& error) { - error = QDBusError("org.freedesktop.dapi.Error", "AddressBookGetEmails failed"); - - if (contact_id.isEmpty()) return false; + if (contact_id.isEmpty()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + "Parameter 'contact_id' is empty"); + return false; + } return addressBook()->getEmails(contact_id, email_addresses); } @@ -363,14 +514,25 @@ bool DAPIImpl::AddressBookGetEmails(const QString& contact_id, bool DAPIImpl::AddressBookGetVCard30(const QString& contact_id, QString& vcard, QDBusError& error) { - error = QDBusError("org.freedesktop.dapi.Error", - "AddressBookGetVCarf30 failed"); + if (contact_id.isEmpty()) + { + error = QDBusError("org.freedesktop.DBus.Error.InvalidArgs", + "Parameter 'contact_id' is empty"); + return false; + } - if (contact_id.isEmpty()) return false; + bool found = false; + vcard = addressBook()->vcard30(contact_id, found); - vcard = addressBook()->vcard30(contact_id); + if (found && vcard.isEmpty()) + { + QString message("Convering data for 'contact_id'(%1) to VCard 3.0 failed"); + error = QDBusError("org.freedesktop.DBus.Error.Failed", + message.arg(contact_id)); + return false; + } - return !vcard.isEmpty(); + return true; } /////////////////////////////////////////////////////////////////////////////// @@ -384,6 +546,9 @@ void DAPIImpl::handleMethodReply(const QDBusMessage& reply) bool DAPIImpl::handleMethodCall(const QDBusMessage& message) { + QString call = message.interface() + "." + message.member(); + qDebug("Received method call '%s' from '%s'", + call.latin1(), message.sender().latin1()); // some method calls need the context data from the call, e.g. // SuspendScreenSaving needs the sender name, so we store the the // message before calling the generated method handler diff --git a/kde3/src/dapiimpl.h b/kde3/src/dapiimpl.h index 424d7fd..982cd59 100644 --- a/kde3/src/dapiimpl.h +++ b/kde3/src/dapiimpl.h @@ -96,6 +96,8 @@ private: StringSet m_screenSaverSuspendConnections; + QMap<QString, QString> m_temporaryFiles; + QDBusMessage m_currentMethodCall; private: diff --git a/kde3/src/kabchandler.cpp b/kde3/src/kabchandler.cpp index 1b78e61..f2b5339 100644 --- a/kde3/src/kabchandler.cpp +++ b/kde3/src/kabchandler.cpp @@ -119,12 +119,17 @@ QString KABCHandler::owner() const /////////////////////////////////////////////////////////////////////////////// -QString KABCHandler::vcard30(const QString& uid) const +QString KABCHandler::vcard30(const QString& uid, bool& found) const { Addressee contact = m_addressBook->findByUid(uid); - if (contact.isEmpty()) return QString::null; + if (contact.isEmpty()) + { + found = false; + return QString::null; + } + found = true; return m_vcardConverter->createVCard(contact, VCardConverter::v3_0); } diff --git a/kde3/src/kabchandler.h b/kde3/src/kabchandler.h index f20514c..f38374c 100644 --- a/kde3/src/kabchandler.h +++ b/kde3/src/kabchandler.h @@ -50,7 +50,7 @@ public: QString owner() const; - QString vcard30(const QString& uid) const; + QString vcard30(const QString& uid, bool& found) const; private: KABC::StdAddressBook* m_addressBook; |