summaryrefslogtreecommitdiffstats
path: root/src/pvs.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-10-06 00:04:49 +0200
committerSebastien Braun2010-10-06 00:04:49 +0200
commitf07fc3b426815e28fde23313242fbbb998a08d45 (patch)
treeba9eda1a83135a1727d2d35661d6facabee53b95 /src/pvs.cpp
parentFix recognition of letters in keyboard handler (diff)
parentMerge remote branch 'openslx/master' into mcastft (diff)
downloadpvs-f07fc3b426815e28fde23313242fbbb998a08d45.tar.gz
pvs-f07fc3b426815e28fde23313242fbbb998a08d45.tar.xz
pvs-f07fc3b426815e28fde23313242fbbb998a08d45.zip
Merge remote branch 'openslx/mcastft' into input
Conflicts: CMakeLists.txt i18n/pvs_ar_JO.ts i18n/pvs_de_DE.ts i18n/pvs_es_MX.ts i18n/pvs_fr_FR.ts i18n/pvs_pl_PL.ts i18n/pvsmgr_ar_JO.ts i18n/pvsmgr_de_DE.ts i18n/pvsmgr_es_MX.ts i18n/pvsmgr_fr_FR.ts i18n/pvsmgr_pl_PL.ts icons/README pvsmgr.qrc src/gui/mainWindow.cpp src/pvs.cpp src/pvs.h src/pvsDaemon.cpp src/util/clientGUIUtils.h
Diffstat (limited to 'src/pvs.cpp')
-rwxr-xr-x[-rw-r--r--]src/pvs.cpp323
1 files changed, 295 insertions, 28 deletions
diff --git a/src/pvs.cpp b/src/pvs.cpp
index 911ed0d..eda63f5 100644..100755
--- a/src/pvs.cpp
+++ b/src/pvs.cpp
@@ -10,6 +10,10 @@
# General information about OpenSLX can be found at http://openslx.org/
*/
+#include <QCryptographicHash>
+#include <QDataStream>
+#include <QDateTime>
+
#include "pvs.h"
#include "src/util/dispatcher.h"
#include "src/net/pvsMsg.h"
@@ -18,6 +22,9 @@
#include "src/input/inputEvent.h"
#include "src/input/inputHandlerChain.h"
#include "src/input/x11InputUtils.h"
+#include "src/net/mcast/McastConfiguration.h"
+#include "src/net/pvsOutgoingMulticastTransfer.h"
+#include "src/net/pvsIncomingMulticastTransfer.h"
// D-Bus
#include "pvsadaptor.h"
@@ -39,12 +46,17 @@ PVS::PVS() :
_vncRequested = false;
readPolicyFiles();
loadCommands();
- _blankScreen = NULL;
+ /*#ifndef __WIN32__*/
+ _blankScreen = NULL;
+ /*#endif*/
_vncPort = -1;
+ _masterMcastConfig = new McastConfiguration(this);
+ _masterMcastConfig->loadFrom(&_settings, "multicast");
+
// add a notify to the allow file, so we get informed when the file is changed
- QString watchPath("/home/");
- watchPath.append(getUserName().append(QString("/.pvs/.allow")));
+ QString watchPath(getPolicyDir());
+ watchPath.append(QString(".allow"));
_notify = new QFileSystemWatcher(this);
_notify->addPath(QString(watchPath.toUtf8().data()));
@@ -54,8 +66,10 @@ PVS::PVS() :
// connect to D-Bus
new PvsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
- dbus.registerObject("/", this);
- dbus.registerService("org.openslx.pvs");
+ if (!dbus.registerObject("/", this))
+ qDebug("[ERROR] DBus: Could not register object");
+ if (!dbus.registerService("org.openslx.pvs"))
+ qDebug("[ERROR] DBus: Could not register service");
_sdClient = new PVSServiceDiscovery(this);
@@ -67,6 +81,7 @@ PVS::PVS() :
_timerLockTest = 0;
_timerLockDelay = 0;
+ #ifndef __WIN32__
//add signalhandling for sigterm signals
struct sigaction act;
act.sa_handler = &PVS::signalHandler;
@@ -80,6 +95,7 @@ PVS::PVS() :
sigaction(SIGQUIT, &act, 0);
initializeInputEventHandling();
+ #endif /*__WIN32__*/
}
PVS::~PVS()
@@ -186,6 +202,74 @@ void PVS::onCommand(PVSMsg cmdMessage)
eventFromString(message, evt);
handleInputEvent(evt);
}
+ if (ident.compare("MCASTFTRETRY") == 0)
+ {
+ QStringList fields = message.split(':');
+ if (fields[0].compare(getUserName()) == 0)
+ {
+ quint64 id = fields[1].toULongLong();
+ PVSOutgoingMulticastTransfer* transfer = _outgoingTransfers.value(id, 0);
+ if (transfer)
+ transfer->retry();
+ }
+ }
+ if (ident.compare("MCASTFTANNOUNCE") == 0)
+ {
+ QStringList fields = message.split(':');
+ bool ok;
+ QString sender;
+ qulonglong transferID;
+ QString basename;
+ qulonglong size;
+ ushort port;
+
+ if (!fields.size() == 5)
+ {
+ goto malformedAnnounce;
+ }
+ sender = fields[0];
+ transferID = fields[1].toULongLong(&ok);
+ if (!ok)
+ {
+ goto malformedAnnounce;
+ }
+ basename = fields[2];
+ size = fields[3].toULongLong(&ok);
+ if (!ok)
+ {
+ goto malformedAnnounce;
+ }
+ port = fields[4].toUShort(&ok);
+ if (!ok)
+ {
+ goto malformedAnnounce;
+ }
+
+ onIncomingMulticastTransfer(sender, transferID, basename, size, port);
+ return;
+
+ malformedAnnounce:
+ qDebug() << "Ignoring malformed MCASTFTANNOUNCE command: " << message;
+ return;
+ }
+ if (ident.compare("MCASTFTCONFIG") == 0)
+ {
+ loadMcastConfig(message);
+ return;
+ }
+ if (ident.compare("SHOWPROCESSES") == 0)
+ {
+ // do stuff to show processes
+ // to test if SHOWPROCESSES command is submitted correct uncomment following lines
+ // a messagebox will appear on the client
+ // emit showMessage("Show Processes", "", true);
+ return;
+ }
+ if (ident.compare("KILLPROCESS") == 0)
+ {
+ // do stuff to kill a process
+ return;
+ }
#ifdef never
// prototype
@@ -327,24 +411,9 @@ bool PVS::allowExists()
*/
bool PVS::getVNCAllow()
{
- if (allowExists())
- {
- if (getAllowed())
- {
- _vncAllowed = true;
- }
- else
- {
- _vncAllowed = false;
- }
- }
- else
- {
- ConsoleLog writeError("No .allow file found.");
- _vncAllowed = false;
- //make sure the vncsever is off
- ConsoleLog writeError("Shutting down vnc-server because we have no .allow file.");
- }
+
+ QString value = getConfigValue("Permissions/vnc_lecturer");
+ _vncAllowed = (value == "rw" || value == "ro");
if (_vncAllowed && _vncRequested)
{
@@ -459,12 +528,13 @@ void PVS::setScriptPath(QString path)
bool PVS::gotVNCScript()
{
- if (fileExists(_vncScriptPath))
+ if (!_vncScriptPath.isEmpty() && fileExists(_vncScriptPath))
return true;
- if (policyFileExists(_vncScriptName))
+
+ if (!_vncScriptName.isEmpty() && policyFileExists(_vncScriptName))
return true;
- return false;
+ return false;
}
/**
* setup password and port
@@ -510,14 +580,19 @@ int PVS::startVNCScript(int port, QString pass, QString rwpass)
commandLine.append(rwpass);
if (!system(NULL))
ConsoleLog writeError("No Command processor available");
-
int result = system(commandLine.toUtf8().data());
+ #ifndef __WIN32__
+//TODO Win32
result = WEXITSTATUS(result);
if (result != 0)
ConsoleLog writeError(QString("VNC-Server is not running, code: ") + int2String(result));
else
ConsoleLog writeLine("VNC-Server should be running");
return result;
+ #else
+ /*Code fuer VNC-Aufruf unter Windows einfuegen*/
+ return 0;
+ #endif /*__WIN32__*/
}
else
{
@@ -533,6 +608,7 @@ int PVS::stopVNCScript()
{
if (gotVNCScript())
{
+ #ifndef __WIN32__
ConsoleLog writeLine("Stopping VNC-Script");
QString commandLine(_vncScriptPath);
commandLine.append(" ");
@@ -544,6 +620,10 @@ int PVS::stopVNCScript()
ConsoleLog writeLine("VNC-Server should be stopped");
int result = system(commandLine.toUtf8().data());
return WEXITSTATUS(result);
+ #else
+ /*Code fuer VNC-Server stoppen unter Windows einfuegen*/
+ return 0;
+ #endif /*__WIN32__*/
}
else
{
@@ -551,9 +631,10 @@ int PVS::stopVNCScript()
}
}
-void PVS::start()
+bool PVS::start()
{
_pvsServerConnection->sendMessage(PVSMsg(PVSCOMMAND, "PROJECTING", "YES"));
+ return true;
}
void PVS::onConnected(QString name)
@@ -620,6 +701,7 @@ QString PVS::getIpByNick(QString nick)
void PVS::signalHandler(int signal)
{
ConsoleLog writeLine(QString("Received Signal ").append (int2String(signal)));
+ #ifndef __WIN32__
switch (signal) {
case SIGHUP:
mainClient->quit();
@@ -634,9 +716,37 @@ void PVS::signalHandler(int signal)
mainClient->quit();
break;
}
+ #else
+ ConsoleLog writeLine("Abfang nicht definiert fuer Windows");
+ #endif /*__WIN32__*/
}
+bool PVS::createMulticastTransfer(QString const& objectPath, quint64& transferID, QString& errorReason)
+{
+ transferID = generateMcastTransferID();
+
+ PVSOutgoingMulticastTransfer* transfer = new PVSOutgoingMulticastTransfer(getUserName(), transferID, objectPath, this);
+ if (transfer->isError())
+ {
+ errorReason = transfer->reason();
+ delete transfer;
+ return false;
+ }
+
+ _outgoingTransfers.insert(transferID, transfer);
+ connect(transfer, SIGNAL(started(qulonglong)), SIGNAL(outgoingMulticastTransferStarted(qulonglong)));
+ connect(transfer, SIGNAL(finished(qulonglong)), SIGNAL(outgoingMulticastTransferFinished(qulonglong)));
+ connect(transfer, SIGNAL(failed(qulonglong, QString const)), SIGNAL(outgoingMulticastTransferFailed(qulonglong, QString const)));
+ connect(transfer, SIGNAL(progress(qulonglong, qulonglong, qulonglong)), SIGNAL(outgoingMulticastTransferProgress(qulonglong, qulonglong, qulonglong)));
+ connect(transfer, SIGNAL(announce(PVSMsg)), _pvsServerConnection, SLOT(sendMessage(PVSMsg)));
+ connect(transfer, SIGNAL(finished(qulonglong)), SLOT(outgoingMulticastTransferDelete(qulonglong)));
+ connect(transfer, SIGNAL(failed(qulonglong, QString const)), SLOT(outgoingMulticastTransferDelete(qulonglong)));
+ QTimer::singleShot(0, transfer, SLOT(start()));
+ errorReason = "";
+ return true;
+}
+
// Input handling
void PVS::handleInputEvent(InputEvent const& evt)
@@ -651,3 +761,160 @@ void PVS::initializeInputEventHandling()
X11InputUtils::setDisplay(X11Info::display());
_inputEventHandlers.initialize();
}
+
+void PVS::cancelOutgoingMulticastTransfer(quint64 transferID)
+{
+ PVSOutgoingMulticastTransfer* transfer = _outgoingTransfers.value(transferID, 0);
+
+ if (transfer)
+ {
+ _outgoingTransfers.remove(transferID);
+ delete transfer;
+ }
+}
+
+void PVS::cancelIncomingMulticastTransfer(qulonglong transferID)
+{
+ PVSIncomingMulticastTransfer* transfer = _incomingTransfers.value(transferID, 0);
+
+ if(transfer)
+ {
+ _incomingTransfers.remove(transferID);
+ delete transfer;
+ }
+}
+
+void PVS::onIncomingMulticastTransfer(QString const& sender, qulonglong transferID,
+ QString const& basename, qulonglong size, ushort port)
+{
+ if (_outgoingTransfers.contains(transferID))
+ return;
+
+ PVSIncomingMulticastTransfer* transfer;
+ if (transfer = _incomingTransfers.value(transferID, 0))
+ {
+ transfer->updatePort(port);
+ QTimer::singleShot(0, transfer, SLOT(start()));
+ }
+ else
+ {
+ QString filename = QFileInfo(QDir::home(), QString("%1.part.%2").arg(basename).arg(transferID, 0, 16)).absoluteFilePath();
+ transfer = new PVSIncomingMulticastTransfer(sender, transferID, size, filename, port, _masterMcastConfig, this);
+ _incomingTransfers.insert(transferID, transfer);
+
+ connect(transfer, SIGNAL(retry(QString const&, qulonglong)), SLOT(onIncomingMulticastTransferRetry(QString const&, qulonglong)));
+ connect(transfer, SIGNAL(started(qulonglong)), SIGNAL(incomingMulticastTransferStarted(qulonglong)));
+ connect(transfer, SIGNAL(progress(qulonglong, qulonglong, qulonglong)), SIGNAL(incomingMulticastTransferProgress(qulonglong, qulonglong, qulonglong)));
+ connect(transfer, SIGNAL(finished(qulonglong)), SIGNAL(incomingMulticastTransferFinished(qulonglong)));
+ connect(transfer, SIGNAL(failed(qulonglong, QString const&)), SIGNAL(incomingMulticastTransferFailed(qulonglong, QString)));
+ connect(transfer, SIGNAL(finished(qulonglong)), SLOT(incomingMulticastTransferDelete(qulonglong)));
+ connect(transfer, SIGNAL(failed(qulonglong, QString const&)), SLOT(incomingMulticastTransferDelete(qulonglong)));
+
+ emit incomingMulticastTransferNew(transferID, sender, filename, size);
+ QTimer::singleShot(0, transfer, SLOT(start()));
+ }
+}
+
+void PVS::onIncomingMulticastTransferRetry(QString const& sender, qulonglong transferID)
+{
+ PVSMsg retryMessage(PVSCOMMAND, "MCASTFTRETRY", QString("%1:%2").arg(sender).arg(transferID));
+ _pvsServerConnection->sendMessage(retryMessage);
+}
+
+quint64 PVS::generateMcastTransferID()
+{
+ static quint64 nodeID = 0;
+ static quint16 counter = 0;
+
+ if (!nodeID)
+ {
+ QDateTime t = QDateTime::currentDateTime();
+ QCryptographicHash h(QCryptographicHash::Md5);
+ h.addData(getUserName().toLocal8Bit());
+ h.addData(t.toString().toLocal8Bit());
+ QDataStream(h.result()) >> nodeID;
+ }
+
+ return (nodeID & Q_UINT64_C(0xffffffffffff0000)) | (quint64)(++counter);
+}
+
+void PVS::outgoingMulticastTransferDelete(qulonglong transferID)
+{
+ PVSOutgoingMulticastTransfer* transfer = _outgoingTransfers.value(transferID, 0);
+ if (!transfer)
+ return;
+
+ _outgoingTransfers.remove(transferID);
+ transfer->deleteLater();
+}
+
+void PVS::incomingMulticastTransferDelete(qulonglong transferID)
+{
+ PVSIncomingMulticastTransfer* transfer = _incomingTransfers.value(transferID, 0);
+ if (!transfer)
+ {
+ return;
+ }
+
+ _incomingTransfers.remove(transferID);
+ transfer->deleteLater();
+}
+
+void PVS::loadMcastConfig(QString const& message)
+{
+ QByteArray ba = QByteArray::fromBase64(message.toAscii());
+ QDataStream d(&ba, QIODevice::ReadOnly);
+ quint16 ver, udpp, dp, sp, mtu, wsz;
+ quint32 rate;
+ QString addr;
+ bool useudp;
+
+ d >> ver;
+ if(ver != 1)
+ {
+ ConsoleLog writeLine(QString("Unable to decode multicast configuration message: Unknown version %1").arg(ver));
+ return;
+ }
+
+ d >> addr
+ >> udpp
+ >> dp
+ >> sp
+ >> mtu
+ >> wsz
+ >> rate
+ >> useudp;
+ if(d.status() != QDataStream::Ok)
+ {
+ ConsoleLog writeLine(QString("Unable to decode multicast configuration message: There was an error reading"));
+ return;
+ }
+
+ _masterMcastConfig->multicastUDPPortBase(udpp);
+ _masterMcastConfig->multicastDPort(dp);
+ _masterMcastConfig->multicastSPort(sp);
+ _masterMcastConfig->multicastMTU(mtu);
+ _masterMcastConfig->multicastWinSize(wsz);
+ _masterMcastConfig->multicastRate(rate);
+ _masterMcastConfig->multicastAddress(addr);
+ _masterMcastConfig->multicastUseUDP(useudp);
+
+ QSettings settings;
+ _masterMcastConfig->writeTo(&settings, "multicast");
+ settings.sync();
+
+ ConsoleLog writeLine(QString("Reconfigured multicast filetransfer to IP %1, UDP port base %2, destination port %3, source port %4, MTU %5, Window Size %6, rate %7, %8using UDP")
+ .arg(addr).arg(udpp).arg(dp).arg(sp).arg(mtu).arg(wsz).arg(rate).arg(useudp ? "" : "not "));
+}
+
+void PVS::setConfigValue(QString key, QString value)
+{
+ _settings.setValue(key, value);
+ _settings.sync();
+ getVNCAllow();
+}
+
+QString PVS::getConfigValue(QString key)
+{
+ return _settings.value(key).toString();
+}