diff --git a/src/mmshandler.cpp b/src/mmshandler.cpp index c660ed0..233820c 100644 --- a/src/mmshandler.cpp +++ b/src/mmshandler.cpp @@ -2,8 +2,8 @@ ** ** This file is part of commhistory-daemon. ** -** Copyright (C) 2014-2017 Jolla Ltd. -** Contact: Slava Monich +** Copyright (C) 2014-2020 Jolla Ltd. +** Copyright (C) 2020 Open Mobile Platform LLC. ** ** This library is free software; you can redistribute it and/or modify it ** under the terms of the GNU Lesser General Public License version 2.1 as @@ -85,7 +85,9 @@ MmsHandler::MmsHandler(QObject* parent) , m_imsiSettings(new MDConfGroup("/imsi", this)) { qDBusRegisterMetaType(); + qDBusRegisterMetaType(); qDBusRegisterMetaType(); + qDBusRegisterMetaType(); qDBusRegisterMetaType >(); QOfonoManager* ofonoManager = m_ofonoManager.data(); @@ -776,10 +778,15 @@ void MmsHandler::sendMessageFromEvent(int eventId) Event::EventStatus MmsHandler::sendMessageFromEvent(Event &event) { - MmsPartList parts; + MmsPartFdList parts; foreach (const MessagePart &part, event.messageParts()) { - MmsPart p = { part.path(), part.contentType(), part.contentId() }; - parts.append(p); + MmsPartFd p(part.path(), part.contentType(), part.contentId()); + if (p.file.isOpen()) { + parts.append(p); + } else { + qWarning() << "Failed to open" << part.path(); + return Event::TemporarilyFailedStatus; + } } QString imsi = event.subscriberIdentity(); @@ -795,7 +802,7 @@ Event::EventStatus MmsHandler::sendMessageFromEvent(Event &event) m_activeEvents.insert(getModemPath(imsi), event.id()); - QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(callEngine("sendMessage", args), this); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(callEngine("sendMessageFd", args), this); watcher->setProperty(kCallPropertyEventId, event.id()); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), SLOT(onSendMessageFinished(QDBusPendingCallWatcher*))); return Event::SendingStatus; diff --git a/src/mmspart.cpp b/src/mmspart.cpp new file mode 100644 index 0000000..fd29d44 --- /dev/null +++ b/src/mmspart.cpp @@ -0,0 +1,90 @@ +/****************************************************************************** +** +** This file is part of commhistory-daemon. +** +** Copyright (C) 2014-2020 Jolla Ltd. +** Copyright (C) 2020 Open Mobile Platform LLC. +** +** This library is free software; you can redistribute it and/or modify it +** under the terms of the GNU Lesser General Public License version 2.1 as +** published by the Free Software Foundation. +** +** This library 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 Lesser General Public +** License for more details. +** +******************************************************************************/ + +#include "mmspart.h" +#include + +MmsPartFd::MmsPartFd(const QString path, const QString ct, const QString cid) : + file(path), + fileName(QFileInfo(path).fileName()), + contentType(ct), + contentId(cid) +{ + file.open(QIODevice::ReadOnly); +} + +MmsPartFd::MmsPartFd(const MmsPartFd &that) : + fileName(that.fileName), + contentType(that.contentType), + contentId(that.contentId) +{ + if (that.file.isOpen()) { + file.open(dup(that.file.handle()), QIODevice::ReadOnly, QFileDevice::AutoCloseHandle); + } +} + +MmsPartFd &MmsPartFd::operator=(const MmsPartFd &that) +{ + fileName = that.fileName; + contentType = that.contentType; + contentId = that.contentId; + file.close(); + if (that.file.isOpen()) { + file.open(dup(that.file.handle()), QIODevice::ReadOnly, QFileDevice::AutoCloseHandle); + } + return *this; +} + +QDBusArgument &operator<<(QDBusArgument &arg, const MmsPart &part) +{ + arg.beginStructure(); + arg << part.fileName << part.contentType << part.contentId; + arg.endStructure(); + return arg; +} + +QDBusArgument &operator<<(QDBusArgument &arg, const MmsPartFd &part) +{ + QDBusUnixFileDescriptor fd(part.file.handle()); + arg.beginStructure(); + arg << fd << part.fileName << part.contentType << part.contentId; + arg.endStructure(); + return arg; +} + +const QDBusArgument &operator>>(const QDBusArgument &arg, MmsPart &part) +{ + arg.beginStructure(); + arg >> part.fileName >> part.contentType >> part.contentId; + arg.endStructure(); + return arg; +} + +const QDBusArgument &operator>>(const QDBusArgument &arg, MmsPartFd &part) +{ + QDBusUnixFileDescriptor fd; + arg.beginStructure(); + arg >> fd >> part.fileName >> part.contentType >> part.contentId; + arg.endStructure(); + + part.file.close(); + if (fd.isValid()) { + part.file.open(dup(fd.fileDescriptor()), QIODevice::ReadOnly, QFileDevice::AutoCloseHandle); + } + return arg; +} diff --git a/src/mmspart.h b/src/mmspart.h index f0ef9a7..99ed0c7 100644 --- a/src/mmspart.h +++ b/src/mmspart.h @@ -2,7 +2,8 @@ ** ** This file is part of commhistory-daemon. ** -** Copyright (C) 2014 Jolla Ltd. +** Copyright (C) 2014-2020 Jolla Ltd. +** Copyright (C) 2020 Open Mobile Platform LLC. ** ** This library is free software; you can redistribute it and/or modify it ** under the terms of the GNU Lesser General Public License version 2.1 as @@ -13,10 +14,6 @@ ** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public ** License for more details. ** -** You should have received a copy of the GNU Lesser General Public License -** along with this library; if not, write to the Free Software Foundation, Inc., -** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -** ******************************************************************************/ #ifndef MMSPART_H @@ -25,32 +22,38 @@ #include #include -struct MmsPart -{ +struct MmsPart { + QString fileName; + QString contentType; + QString contentId; +}; + +class MmsPartFd { +public: + QFile file; QString fileName; QString contentType; QString contentId; + +public: + MmsPartFd() {} + MmsPartFd(const QString path, const QString ct, const QString cid); + MmsPartFd(const MmsPartFd &that); + MmsPartFd &operator=(const MmsPartFd &that); }; -inline QDBusArgument& operator<<(QDBusArgument &arg, const MmsPart &part) -{ - arg.beginStructure(); - arg << part.fileName << part.contentType << part.contentId; - arg.endStructure(); - return arg; -} - -inline const QDBusArgument& operator>>(const QDBusArgument &arg, MmsPart &part) -{ - arg.beginStructure(); - arg >> part.fileName >> part.contentType >> part.contentId; - arg.endStructure(); - return arg; -} +QDBusArgument &operator<<(QDBusArgument &arg, const MmsPart &part); +QDBusArgument &operator<<(QDBusArgument &arg, const MmsPartFd &part); + +const QDBusArgument &operator>>(const QDBusArgument &arg, MmsPart &part); +const QDBusArgument &operator>>(const QDBusArgument &arg, MmsPartFd &part); typedef QList MmsPartList; +typedef QList MmsPartFdList; Q_DECLARE_METATYPE(MmsPart); +Q_DECLARE_METATYPE(MmsPartFd); Q_DECLARE_METATYPE(MmsPartList); +Q_DECLARE_METATYPE(MmsPartFdList); #endif // MMSPART_H diff --git a/src/src.pro b/src/src.pro index 3fea0db..0c250fd 100644 --- a/src/src.pro +++ b/src/src.pro @@ -100,6 +100,7 @@ SOURCES += main.cpp \ lastdialedcache.cpp \ fscleanup.cpp \ mmshandler.cpp \ + mmspart.cpp \ messagehandlerbase.cpp \ smartmessaging.cpp