Commit a472d3d1 authored by Slava Monich's avatar Slava Monich

[commhistory-daemon] Send MMS messages with sendMessageFd. JB#50793

This allows to get around file system restrictions in case if mms-engine
and commhistoryd are running under different user accounts.
parent 994c017a
......@@ -2,8 +2,8 @@
**
** This file is part of commhistory-daemon.
**
** Copyright (C) 2014-2017 Jolla Ltd.
** Contact: Slava Monich <slava.monich@jolla.com>
** 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<MmsPart>();
qDBusRegisterMetaType<MmsPartFd>();
qDBusRegisterMetaType<MmsPartList>();
qDBusRegisterMetaType<MmsPartFdList>();
qDBusRegisterMetaType<QList<CommHistory::Event> >();
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;
......
/******************************************************************************
**
** 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 <unistd.h>
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;
}
......@@ -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 <QtDBus>
#include <QString>
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<MmsPart> MmsPartList;
typedef QList<MmsPartFd> MmsPartFdList;
Q_DECLARE_METATYPE(MmsPart);
Q_DECLARE_METATYPE(MmsPartFd);
Q_DECLARE_METATYPE(MmsPartList);
Q_DECLARE_METATYPE(MmsPartFdList);
#endif // MMSPART_H
......@@ -100,6 +100,7 @@ SOURCES += main.cpp \
lastdialedcache.cpp \
fscleanup.cpp \
mmshandler.cpp \
mmspart.cpp \
messagehandlerbase.cpp \
smartmessaging.cpp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment