Skip to content

Commit

Permalink
[commhistory-daemon] Send MMS messages with sendMessageFd. JB#50793
Browse files Browse the repository at this point in the history
This allows to get around file system restrictions in case if mms-engine
and commhistoryd are running under different user accounts.
  • Loading branch information
monich committed Aug 25, 2020
1 parent 994c017 commit a472d3d
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 28 deletions.
19 changes: 13 additions & 6 deletions src/mmshandler.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
90 changes: 90 additions & 0 deletions 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 <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;
}
47 changes: 25 additions & 22 deletions src/mmspart.h
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions src/src.pro
Expand Up @@ -100,6 +100,7 @@ SOURCES += main.cpp \
lastdialedcache.cpp \
fscleanup.cpp \
mmshandler.cpp \
mmspart.cpp \
messagehandlerbase.cpp \
smartmessaging.cpp

Expand Down

0 comments on commit a472d3d

Please sign in to comment.