2013-10-03 19:04:55 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Dominik Schmidt <dev@dominik-schmidt.de>
|
2014-07-14 17:28:26 +04:00
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
2015-03-16 18:26:35 +03:00
|
|
|
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
|
2013-10-03 19:04:55 +04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "socketapi.h"
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2015-06-22 14:53:05 +03:00
|
|
|
#include "config.h"
|
2014-11-10 01:25:57 +03:00
|
|
|
#include "configfile.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "folderman.h"
|
|
|
|
#include "folder.h"
|
|
|
|
#include "utility.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "syncjournalfilerecord.h"
|
2016-03-17 14:26:44 +03:00
|
|
|
#include "syncengine.h"
|
2014-07-11 02:31:24 +04:00
|
|
|
#include "syncfileitem.h"
|
2014-09-18 19:08:53 +04:00
|
|
|
#include "filesystem.h"
|
2014-08-27 14:02:47 +04:00
|
|
|
#include "version.h"
|
2015-09-10 16:39:37 +03:00
|
|
|
#include "account.h"
|
2015-03-16 18:26:35 +03:00
|
|
|
#include "accountstate.h"
|
2015-10-06 10:39:24 +03:00
|
|
|
#include "account.h"
|
|
|
|
#include "capabilities.h"
|
2013-10-03 19:04:55 +04:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QMetaObject>
|
|
|
|
#include <QStringList>
|
2014-06-02 14:08:06 +04:00
|
|
|
#include <QScopedPointer>
|
2013-10-03 19:04:55 +04:00
|
|
|
#include <QFile>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QApplication>
|
2014-09-29 14:19:33 +04:00
|
|
|
#include <QLocalSocket>
|
2015-10-08 19:26:30 +03:00
|
|
|
#include <QStringBuilder>
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2014-10-13 16:14:43 +04:00
|
|
|
#include <sqlite3.h>
|
|
|
|
|
|
|
|
|
2014-09-29 15:54:13 +04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#endif
|
|
|
|
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2014-08-27 14:02:47 +04:00
|
|
|
// This is the version that is returned when the client asks for the VERSION.
|
|
|
|
// The first number should be changed if there is an incompatible change that breaks old clients.
|
|
|
|
// The second number should be changed when there are new features.
|
|
|
|
#define MIRALL_SOCKET_API_VERSION "1.0"
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-10-03 19:04:55 +04:00
|
|
|
|
|
|
|
#define DEBUG qDebug() << "SocketApi: "
|
|
|
|
|
2014-07-17 17:00:21 +04:00
|
|
|
SocketApi::SocketApi(QObject* parent)
|
2013-10-03 19:04:55 +04:00
|
|
|
: QObject(parent)
|
2014-06-19 16:08:30 +04:00
|
|
|
{
|
2014-09-29 14:19:33 +04:00
|
|
|
QString socketPath;
|
2014-09-29 15:54:13 +04:00
|
|
|
|
2014-09-29 14:19:33 +04:00
|
|
|
if (Utility::isWindows()) {
|
|
|
|
socketPath = QLatin1String("\\\\.\\pipe\\")
|
2014-10-24 01:46:17 +04:00
|
|
|
+ QLatin1String("ownCloud");
|
|
|
|
// TODO: once the windows extension supports multiple
|
|
|
|
// client connections, switch back to the theme name
|
|
|
|
// See issue #2388
|
|
|
|
// + Theme::instance()->appName();
|
2014-09-30 09:36:20 +04:00
|
|
|
} else if (Utility::isMac()) {
|
2015-06-22 14:53:05 +03:00
|
|
|
// This must match the code signing Team setting of the extension
|
|
|
|
// Example for developer builds (with ad-hoc signing identity): "" "com.owncloud.desktopclient" ".socketApi"
|
|
|
|
// Example for official signed packages: "9B5WD74GWJ." "com.owncloud.desktopclient" ".socketApi"
|
|
|
|
socketPath = SOCKETAPI_TEAM_IDENTIFIER_PREFIX APPLICATION_REV_DOMAIN ".socketApi";
|
2015-01-09 00:40:47 +03:00
|
|
|
} else if( Utility::isLinux() || Utility::isBSD() ) {
|
2014-09-29 15:54:13 +04:00
|
|
|
QString runtimeDir;
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
|
|
|
|
#else
|
|
|
|
runtimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR"));
|
2014-12-01 14:05:14 +03:00
|
|
|
if (runtimeDir.isEmpty()) {
|
|
|
|
runtimeDir = QDir::tempPath() + QLatin1String("/runtime-")
|
|
|
|
+ QString::fromLocal8Bit(qgetenv("USER"));
|
|
|
|
QDir().mkdir(runtimeDir);
|
|
|
|
}
|
2014-09-29 15:54:13 +04:00
|
|
|
#endif
|
|
|
|
socketPath = runtimeDir + "/" + Theme::instance()->appName() + "/socket";
|
2014-09-30 13:15:27 +04:00
|
|
|
} else {
|
|
|
|
DEBUG << "An unexpected system detected";
|
2014-06-19 17:35:29 +04:00
|
|
|
}
|
2014-06-19 16:08:30 +04:00
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
SocketApiServer::removeServer(socketPath);
|
2014-09-29 15:54:13 +04:00
|
|
|
QFileInfo info(socketPath);
|
|
|
|
if (!info.dir().exists()) {
|
|
|
|
bool result = info.dir().mkpath(".");
|
|
|
|
DEBUG << "creating" << info.dir().path() << result;
|
2014-09-30 13:16:49 +04:00
|
|
|
if( result ) {
|
|
|
|
QFile::setPermissions(socketPath,
|
|
|
|
QFile::Permissions(QFile::ReadOwner+QFile::WriteOwner+QFile::ExeOwner));
|
|
|
|
}
|
2014-06-19 16:08:30 +04:00
|
|
|
}
|
2014-09-29 14:19:33 +04:00
|
|
|
if(!_localServer.listen(socketPath)) {
|
|
|
|
DEBUG << "can't start server" << socketPath;
|
2014-06-19 16:08:30 +04:00
|
|
|
} else {
|
2014-09-29 14:19:33 +04:00
|
|
|
DEBUG << "server started, listening at " << socketPath;
|
2014-06-19 16:08:30 +04:00
|
|
|
}
|
2014-06-19 17:35:29 +04:00
|
|
|
|
2014-09-29 14:19:33 +04:00
|
|
|
connect(&_localServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
2013-10-03 19:04:55 +04:00
|
|
|
|
|
|
|
// folder watcher
|
2015-05-12 16:50:38 +03:00
|
|
|
connect(FolderMan::instance(), SIGNAL(folderSyncStateChange(Folder*)), this, SLOT(slotUpdateFolderView(Folder*)));
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SocketApi::~SocketApi()
|
|
|
|
{
|
|
|
|
DEBUG << "dtor";
|
2014-09-29 14:19:33 +04:00
|
|
|
_localServer.close();
|
2015-04-01 15:40:34 +03:00
|
|
|
// All remaining sockets will be destroyed with _localServer, their parent
|
|
|
|
Q_ASSERT(_listeners.isEmpty() || _listeners.first()->parent() == &_localServer);
|
|
|
|
_listeners.clear();
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
|
|
|
|
2014-06-02 14:08:06 +04:00
|
|
|
void SocketApi::slotNewConnection()
|
2013-10-03 19:04:55 +04:00
|
|
|
{
|
2015-06-15 15:51:11 +03:00
|
|
|
QIODevice* socket = _localServer.nextPendingConnection();
|
2014-07-10 17:50:24 +04:00
|
|
|
|
2014-06-02 14:08:06 +04:00
|
|
|
if( ! socket ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-17 17:00:21 +04:00
|
|
|
DEBUG << "New connection" << socket;
|
2014-06-02 14:08:06 +04:00
|
|
|
connect(socket, SIGNAL(readyRead()), this, SLOT(slotReadSocket()));
|
2013-10-03 19:04:55 +04:00
|
|
|
connect(socket, SIGNAL(disconnected()), this, SLOT(onLostConnection()));
|
|
|
|
Q_ASSERT(socket->readAll().isEmpty());
|
|
|
|
|
|
|
|
_listeners.append(socket);
|
2014-07-15 19:55:55 +04:00
|
|
|
|
2015-03-13 20:30:45 +03:00
|
|
|
foreach( Folder *f, FolderMan::instance()->map() ) {
|
|
|
|
QString message = buildRegisterPathMessage(f->path());
|
|
|
|
sendMessage(socket, message);
|
2014-07-15 19:55:55 +04:00
|
|
|
}
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SocketApi::onLostConnection()
|
|
|
|
{
|
|
|
|
DEBUG << "Lost connection " << sender();
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
QIODevice* socket = qobject_cast<QIODevice*>(sender());
|
2013-10-03 19:04:55 +04:00
|
|
|
_listeners.removeAll(socket);
|
2015-02-11 11:41:32 +03:00
|
|
|
socket->deleteLater();
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-02 14:08:06 +04:00
|
|
|
void SocketApi::slotReadSocket()
|
2013-10-03 19:04:55 +04:00
|
|
|
{
|
2015-06-15 15:51:11 +03:00
|
|
|
QIODevice* socket = qobject_cast<QIODevice*>(sender());
|
2013-10-03 19:04:55 +04:00
|
|
|
Q_ASSERT(socket);
|
|
|
|
|
2014-06-02 14:08:06 +04:00
|
|
|
while(socket->canReadLine()) {
|
2015-10-26 12:06:10 +03:00
|
|
|
QString line = QString::fromUtf8(socket->readLine());
|
|
|
|
line.chop(1); // remove the '\n'
|
|
|
|
QString command = line.split(":").value(0);
|
2013-10-03 19:04:55 +04:00
|
|
|
QString function = QString(QLatin1String("command_")).append(command);
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
QString functionWithArguments = function + QLatin1String("(QString,QIODevice*)");
|
2013-10-03 19:04:55 +04:00
|
|
|
int indexOfMethod = this->metaObject()->indexOfMethod(functionWithArguments.toAscii());
|
|
|
|
|
2015-10-26 12:06:10 +03:00
|
|
|
QString argument = line.remove(0, command.length()+1);
|
2014-06-02 14:08:06 +04:00
|
|
|
if(indexOfMethod != -1) {
|
2015-06-15 15:51:11 +03:00
|
|
|
QMetaObject::invokeMethod(this, function.toAscii(), Q_ARG(QString, argument), Q_ARG(QIODevice*, socket));
|
2014-06-02 14:08:06 +04:00
|
|
|
} else {
|
2013-10-03 19:04:55 +04:00
|
|
|
DEBUG << "The command is not supported by this version of the client:" << command << "with argument:" << argument;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-25 14:10:45 +04:00
|
|
|
void SocketApi::slotRegisterPath( const QString& alias )
|
2013-10-03 19:04:55 +04:00
|
|
|
{
|
2014-07-25 14:10:45 +04:00
|
|
|
Folder *f = FolderMan::instance()->folder(alias);
|
|
|
|
if (f) {
|
2015-03-13 20:30:45 +03:00
|
|
|
QString message = buildRegisterPathMessage(f->path());
|
2015-06-15 15:51:11 +03:00
|
|
|
foreach(QIODevice *socket, _listeners) {
|
2015-03-13 20:30:45 +03:00
|
|
|
sendMessage(socket, message);
|
|
|
|
}
|
2014-07-25 14:10:45 +04:00
|
|
|
}
|
|
|
|
}
|
2014-07-11 13:30:47 +04:00
|
|
|
|
2014-07-25 14:10:45 +04:00
|
|
|
void SocketApi::slotUnregisterPath( const QString& alias )
|
|
|
|
{
|
2014-07-11 13:30:47 +04:00
|
|
|
Folder *f = FolderMan::instance()->folder(alias);
|
2016-03-17 22:58:51 +03:00
|
|
|
if (f)
|
2014-08-20 18:24:06 +04:00
|
|
|
broadcastMessage(QLatin1String("UNREGISTER_PATH"), f->path(), QString::null, true );
|
2014-07-25 14:10:45 +04:00
|
|
|
}
|
2014-07-11 13:30:47 +04:00
|
|
|
|
2015-05-12 16:50:38 +03:00
|
|
|
void SocketApi::slotUpdateFolderView(Folder *f)
|
2014-07-25 14:10:45 +04:00
|
|
|
{
|
2014-10-21 17:26:51 +04:00
|
|
|
if (_listeners.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-25 14:10:45 +04:00
|
|
|
if (f) {
|
|
|
|
// do only send UPDATE_VIEW for a couple of status
|
|
|
|
if( f->syncResult().status() == SyncResult::SyncPrepare ||
|
|
|
|
f->syncResult().status() == SyncResult::Success ||
|
2014-08-07 16:07:08 +04:00
|
|
|
f->syncResult().status() == SyncResult::Paused ||
|
2014-07-25 14:10:45 +04:00
|
|
|
f->syncResult().status() == SyncResult::Problem ||
|
|
|
|
f->syncResult().status() == SyncResult::Error ||
|
|
|
|
f->syncResult().status() == SyncResult::SetupError ) {
|
2014-10-21 17:26:51 +04:00
|
|
|
|
|
|
|
broadcastMessage(QLatin1String("STATUS"), f->path() ,
|
2016-03-17 14:26:44 +03:00
|
|
|
f->syncEngine().syncFileStatusTracker().fileStatus("").toSocketAPIString());
|
2014-10-21 17:26:51 +04:00
|
|
|
|
2014-10-21 16:57:50 +04:00
|
|
|
broadcastMessage(QLatin1String("UPDATE_VIEW"), f->path() );
|
2014-10-13 19:23:42 +04:00
|
|
|
} else {
|
2015-05-12 16:50:38 +03:00
|
|
|
qDebug() << "Not sending UPDATE_VIEW for" << f->alias() << "because status() is" << f->syncResult().status();
|
2014-07-25 14:10:45 +04:00
|
|
|
}
|
|
|
|
}
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
|
|
|
|
2016-03-21 14:35:57 +03:00
|
|
|
void SocketApi::slotFileStatusChanged(const QString& systemFileName, SyncFileStatus fileStatus)
|
2014-06-06 17:52:55 +04:00
|
|
|
{
|
2016-03-21 14:35:57 +03:00
|
|
|
broadcastMessage(QLatin1String("STATUS"), systemFileName, fileStatus.toSocketAPIString());
|
2014-06-06 17:52:55 +04:00
|
|
|
}
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
void SocketApi::sendMessage(QIODevice *socket, const QString& message, bool doWait)
|
2013-10-03 19:04:55 +04:00
|
|
|
{
|
|
|
|
DEBUG << "Sending message: " << message;
|
|
|
|
QString localMessage = message;
|
2014-07-25 14:10:45 +04:00
|
|
|
if( ! localMessage.endsWith(QLatin1Char('\n'))) {
|
|
|
|
localMessage.append(QLatin1Char('\n'));
|
|
|
|
}
|
2014-10-10 18:20:57 +04:00
|
|
|
|
|
|
|
QByteArray bytesToSend = localMessage.toUtf8();
|
|
|
|
qint64 sent = socket->write(bytesToSend);
|
2014-08-20 18:24:06 +04:00
|
|
|
if( doWait ) {
|
|
|
|
socket->waitForBytesWritten(1000);
|
|
|
|
}
|
2014-10-10 18:20:57 +04:00
|
|
|
if( sent != bytesToSend.length() ) {
|
2014-07-25 14:10:45 +04:00
|
|
|
qDebug() << "WARN: Could not send all data on socket for " << localMessage;
|
|
|
|
}
|
|
|
|
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
|
|
|
|
2014-08-20 18:24:06 +04:00
|
|
|
void SocketApi::broadcastMessage( const QString& verb, const QString& path, const QString& status, bool doWait )
|
2013-10-03 19:04:55 +04:00
|
|
|
{
|
2014-07-25 14:10:45 +04:00
|
|
|
QString msg(verb);
|
|
|
|
|
|
|
|
if( !status.isEmpty() ) {
|
|
|
|
msg.append(QLatin1Char(':'));
|
|
|
|
msg.append(status);
|
|
|
|
}
|
|
|
|
if( !path.isEmpty() ) {
|
|
|
|
msg.append(QLatin1Char(':'));
|
2014-12-09 22:48:06 +03:00
|
|
|
QFileInfo fi(path);
|
2015-01-07 16:36:06 +03:00
|
|
|
msg.append(QDir::toNativeSeparators(fi.absoluteFilePath()));
|
2014-07-25 14:10:45 +04:00
|
|
|
}
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
foreach(QIODevice *socket, _listeners) {
|
2014-08-20 18:24:06 +04:00
|
|
|
sendMessage(socket, msg, doWait);
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
void SocketApi::command_RETRIEVE_FOLDER_STATUS(const QString& argument, QIODevice* socket)
|
2013-10-03 19:04:55 +04:00
|
|
|
{
|
2014-06-19 17:02:27 +04:00
|
|
|
// This command is the same as RETRIEVE_FILE_STATUS
|
2013-10-03 19:04:55 +04:00
|
|
|
|
2014-10-22 16:43:23 +04:00
|
|
|
//qDebug() << Q_FUNC_INFO << argument;
|
2014-06-19 17:02:27 +04:00
|
|
|
command_RETRIEVE_FILE_STATUS(argument, socket);
|
2014-06-06 17:37:04 +04:00
|
|
|
}
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
void SocketApi::command_RETRIEVE_FILE_STATUS(const QString& argument, QIODevice* socket)
|
2014-06-06 17:37:04 +04:00
|
|
|
{
|
|
|
|
if( !socket ) {
|
|
|
|
qDebug() << "No valid socket object.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << Q_FUNC_INFO << argument;
|
|
|
|
|
|
|
|
QString statusString;
|
|
|
|
|
2014-07-10 16:27:52 +04:00
|
|
|
Folder* syncFolder = FolderMan::instance()->folderForPath( argument );
|
|
|
|
if (!syncFolder) {
|
|
|
|
// this can happen in offline mode e.g.: nothing to worry about
|
2014-06-06 17:37:04 +04:00
|
|
|
statusString = QLatin1String("NOP");
|
2014-07-10 16:27:52 +04:00
|
|
|
} else {
|
2015-05-05 18:34:01 +03:00
|
|
|
const QString file = QDir::cleanPath(argument).mid(syncFolder->cleanPath().length()+1);
|
2016-03-17 14:26:44 +03:00
|
|
|
SyncFileStatus fileStatus = syncFolder->syncEngine().syncFileStatusTracker().fileStatus(file);
|
2014-06-06 17:37:04 +04:00
|
|
|
|
2014-07-10 16:27:52 +04:00
|
|
|
statusString = fileStatus.toSocketAPIString();
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
2014-06-06 17:37:04 +04:00
|
|
|
|
2015-10-08 19:26:30 +03:00
|
|
|
const QString message = QLatin1String("STATUS:") % statusString % QLatin1Char(':') % QDir::toNativeSeparators(argument);
|
2014-06-06 17:37:04 +04:00
|
|
|
sendMessage(socket, message);
|
2013-10-03 19:04:55 +04:00
|
|
|
}
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
void SocketApi::command_SHARE(const QString& localFile, QIODevice* socket)
|
2014-09-03 18:12:21 +04:00
|
|
|
{
|
2014-12-23 18:30:37 +03:00
|
|
|
if (!socket) {
|
2015-01-11 15:41:15 +03:00
|
|
|
qDebug() << Q_FUNC_INFO << "No valid socket object.";
|
2014-12-23 18:30:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-21 17:03:01 +03:00
|
|
|
qDebug() << Q_FUNC_INFO << localFile;
|
2014-12-23 18:30:37 +03:00
|
|
|
|
2016-02-22 15:53:45 +03:00
|
|
|
auto theme = Theme::instance();
|
|
|
|
|
2015-01-21 17:03:01 +03:00
|
|
|
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
|
2014-12-23 18:30:37 +03:00
|
|
|
if (!shareFolder) {
|
2015-01-29 20:09:46 +03:00
|
|
|
const QString message = QLatin1String("SHARE:NOP:")+QDir::toNativeSeparators(localFile);
|
|
|
|
// files that are not within a sync folder are not synced.
|
2014-12-23 18:30:37 +03:00
|
|
|
sendMessage(socket, message);
|
2015-03-16 18:26:35 +03:00
|
|
|
} else if (!shareFolder->accountState()->isConnected()) {
|
|
|
|
const QString message = QLatin1String("SHARE:NOTCONNECTED:")+QDir::toNativeSeparators(localFile);
|
|
|
|
// if the folder isn't connected, don't open the share dialog
|
|
|
|
sendMessage(socket, message);
|
2016-02-22 15:53:45 +03:00
|
|
|
} else if (!theme->linkSharing() && (
|
|
|
|
!theme->userGroupSharing() ||
|
|
|
|
shareFolder->accountState()->account()->serverVersionInt() < ((8 << 16) + (2 << 8)))) {
|
|
|
|
const QString message = QLatin1String("SHARE:NOP:")+QDir::toNativeSeparators(localFile);
|
|
|
|
sendMessage(socket, message);
|
2014-12-23 18:30:37 +03:00
|
|
|
} else {
|
2016-01-04 13:57:51 +03:00
|
|
|
const QString localFileClean = QDir::cleanPath(localFile);
|
|
|
|
const QString file = localFileClean.mid(shareFolder->cleanPath().length()+1);
|
2016-03-17 14:26:44 +03:00
|
|
|
SyncFileStatus fileStatus = shareFolder->syncEngine().syncFileStatusTracker().fileStatus(file);
|
2015-11-20 11:26:45 +03:00
|
|
|
|
|
|
|
// Verify the file is on the server (to our knowledge of course)
|
2016-03-24 20:20:49 +03:00
|
|
|
if (fileStatus.tag() != SyncFileStatus::StatusUpToDate) {
|
2015-11-20 11:26:45 +03:00
|
|
|
const QString message = QLatin1String("SHARE:NOTSYNCED:")+QDir::toNativeSeparators(localFile);
|
|
|
|
sendMessage(socket, message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-21 16:10:37 +03:00
|
|
|
const QString remotePath = QDir(shareFolder->remotePath()).filePath(file);
|
2015-03-11 16:09:31 +03:00
|
|
|
|
2015-07-24 11:02:18 +03:00
|
|
|
// Can't share root folder
|
2016-01-04 13:57:51 +03:00
|
|
|
if (remotePath == "/") {
|
2015-11-20 11:26:45 +03:00
|
|
|
const QString message = QLatin1String("SHARE:CANNOTSHAREROOT:")+QDir::toNativeSeparators(localFile);
|
2015-07-24 11:02:18 +03:00
|
|
|
sendMessage(socket, message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-17 22:58:51 +03:00
|
|
|
SyncJournalFileRecord rec = shareFolder->journalDb()->getFileRecord(localFileClean);
|
2015-03-11 16:09:31 +03:00
|
|
|
|
|
|
|
bool allowReshare = true; // lets assume the good
|
|
|
|
if( rec.isValid() ) {
|
|
|
|
// check the permission: Is resharing allowed?
|
|
|
|
if( !rec._remotePerm.contains('R') ) {
|
|
|
|
allowReshare = false;
|
|
|
|
}
|
|
|
|
}
|
2015-01-21 17:03:01 +03:00
|
|
|
const QString message = QLatin1String("SHARE:OK:")+QDir::toNativeSeparators(localFile);
|
2014-12-23 18:30:37 +03:00
|
|
|
sendMessage(socket, message);
|
2015-01-14 12:35:09 +03:00
|
|
|
|
2016-01-04 13:57:51 +03:00
|
|
|
emit shareCommandReceived(remotePath, localFileClean, allowReshare);
|
2014-12-23 18:30:37 +03:00
|
|
|
}
|
2014-09-03 18:12:21 +04:00
|
|
|
}
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
void SocketApi::command_VERSION(const QString&, QIODevice* socket)
|
2014-08-27 14:02:47 +04:00
|
|
|
{
|
2014-08-29 19:28:36 +04:00
|
|
|
sendMessage(socket, QLatin1String("VERSION:" MIRALL_VERSION_STRING ":" MIRALL_SOCKET_API_VERSION));
|
2014-08-27 14:02:47 +04:00
|
|
|
}
|
|
|
|
|
2015-10-06 10:39:24 +03:00
|
|
|
void SocketApi::command_SHARE_STATUS(const QString &localFile, QIODevice *socket)
|
|
|
|
{
|
|
|
|
if (!socket) {
|
|
|
|
qDebug() << Q_FUNC_INFO << "No valid socket object.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << Q_FUNC_INFO << localFile;
|
|
|
|
|
|
|
|
Folder *shareFolder = FolderMan::instance()->folderForPath(localFile);
|
|
|
|
|
|
|
|
if (!shareFolder) {
|
|
|
|
const QString message = QLatin1String("SHARE_STATUS:NOP:")+QDir::toNativeSeparators(localFile);
|
|
|
|
sendMessage(socket, message);
|
|
|
|
} else {
|
2015-11-25 11:40:21 +03:00
|
|
|
const QString file = QDir::cleanPath(localFile).mid(shareFolder->cleanPath().length()+1);
|
2016-03-17 14:26:44 +03:00
|
|
|
SyncFileStatus fileStatus = shareFolder->syncEngine().syncFileStatusTracker().fileStatus(file);
|
2015-11-25 11:40:21 +03:00
|
|
|
|
|
|
|
// Verify the file is on the server (to our knowledge of course)
|
2016-03-24 20:20:49 +03:00
|
|
|
if (fileStatus.tag() != SyncFileStatus::StatusUpToDate) {
|
2015-11-25 11:40:21 +03:00
|
|
|
const QString message = QLatin1String("SHARE_STATUS:NOTSYNCED:")+QDir::toNativeSeparators(localFile);
|
|
|
|
sendMessage(socket, message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:39:24 +03:00
|
|
|
const Capabilities capabilities = shareFolder->accountState()->account()->capabilities();
|
|
|
|
|
|
|
|
if (!capabilities.shareAPI()) {
|
|
|
|
const QString message = QLatin1String("SHARE_STATUS:DISABLED:")+QDir::toNativeSeparators(localFile);
|
|
|
|
sendMessage(socket, message);
|
|
|
|
} else {
|
2016-02-22 15:53:45 +03:00
|
|
|
auto theme = Theme::instance();
|
|
|
|
QString available;
|
2015-10-06 10:39:24 +03:00
|
|
|
|
2016-02-22 15:53:45 +03:00
|
|
|
if (theme->userGroupSharing()) {
|
|
|
|
available = "USER,GROUP";
|
2015-10-06 10:39:24 +03:00
|
|
|
}
|
|
|
|
|
2016-02-22 15:53:45 +03:00
|
|
|
if (theme->linkSharing() && capabilities.sharePublicLink()) {
|
|
|
|
if (available.isEmpty()) {
|
|
|
|
available = "LINK";
|
|
|
|
} else {
|
|
|
|
available += ",LINK";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (available.isEmpty()) {
|
|
|
|
const QString message = QLatin1String("SHARE_STATUS:DISABLED") + ":" + QDir::toNativeSeparators(localFile);
|
|
|
|
sendMessage(socket, message);
|
|
|
|
} else {
|
|
|
|
const QString message = QLatin1String("SHARE_STATUS:") + available + ":" + QDir::toNativeSeparators(localFile);
|
|
|
|
sendMessage(socket, message);
|
|
|
|
}
|
2015-10-06 10:39:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-15 15:51:11 +03:00
|
|
|
void SocketApi::command_SHARE_MENU_TITLE(const QString &, QIODevice* socket)
|
2015-01-23 18:09:38 +03:00
|
|
|
{
|
|
|
|
sendMessage(socket, QLatin1String("SHARE_MENU_TITLE:") + tr("Share with %1", "parameter is ownCloud").arg(Theme::instance()->appNameGUI()));
|
|
|
|
}
|
|
|
|
|
2015-03-13 20:30:45 +03:00
|
|
|
QString SocketApi::buildRegisterPathMessage(const QString& path)
|
|
|
|
{
|
|
|
|
QFileInfo fi(path);
|
|
|
|
QString message = QLatin1String("REGISTER_PATH:");
|
|
|
|
message.append(QDir::toNativeSeparators(fi.absoluteFilePath()));
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|