#include <QMetaMethod>
#include <QMetaProperty>
#include <QRegExp>
+#ifdef HAVE_SSL
+#include <QSslSocket>
+#endif
#include <QThread>
#include <QTime>
#include <QEvent>
dispatchPackedFunc(QVariant(packedFunc));
}
+bool SignalProxy::IODevicePeer::isSecure() const {
+#ifdef HAVE_SSL
+ QSslSocket *sslSocket = qobject_cast<QSslSocket *>(_device);
+ if(sslSocket)
+ return sslSocket->isEncrypted() || sslSocket->localAddress() == QHostAddress::LocalHost || sslSocket->localAddress() == QHostAddress::LocalHostIPv6;
+#endif
+
+ QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(_device);
+ if(socket)
+ return socket->localAddress() == QHostAddress::LocalHost || socket->localAddress() == QHostAddress::LocalHostIPv6;
+
+ return false;
+}
+
QString SignalProxy::IODevicePeer::address() const {
QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(_device);
if(socket)
void SignalProxy::init() {
connect(&_heartBeatTimer, SIGNAL(timeout()), this, SLOT(sendHeartBeat()));
_heartBeatTimer.start(30 * 1000);
+ _secure = false;
+ updateSecureState();
}
void SignalProxy::initServer() {
connect(iodev, SIGNAL(disconnected()), this, SLOT(removePeerBySender()));
connect(iodev, SIGNAL(readyRead()), this, SLOT(dataAvailable()));
+#ifdef HAVE_SSL
+ QSslSocket *sslSocket = qobject_cast<QSslSocket *>(iodev);
+ if(sslSocket) {
+ connect(iodev, SIGNAL(encrypted()), this, SLOT(updateSecureState()));
+ }
+#endif
+
if(!iodev->parent())
iodev->setParent(this);
if(_peers.count() == 1)
emit connected();
+ updateSecureState();
return true;
}
if(_peers.count() == 1)
emit connected();
+ updateSecureState();
return true;
}
delete peer;
+ updateSecureState();
+
if(_peers.isEmpty())
emit disconnected();
}
void SignalProxy::objectRenamed(const QString &newname, const QString &oldname) {
SyncableObject *syncObject = qobject_cast<SyncableObject *>(sender());
- const QMetaObject *meta = syncObject->metaObject();
+ const QMetaObject *meta = syncObject->syncMetaObject();
const QByteArray className(meta->className());
objectRenamed(className, newname, oldname);
}
void SignalProxy::detachObject(QObject* obj) {
+ stopSync(static_cast<SyncableObject *>(obj));
detachSignals(obj);
detachSlots(obj);
- stopSync(static_cast<SyncableObject *>(obj));
}
void SignalProxy::detachSignals(QObject* sender) {
bool SignalProxy::methodsMatch(const QMetaMethod &signal, const QMetaMethod &slot) const {
// if we don't even have the same basename it's a sure NO
- if(methodBaseName(signal) != methodBaseName(slot))
+ QString baseName = methodBaseName(signal);
+ if(baseName != methodBaseName(slot))
return false;
// are the signatures compatible?
return false;
// we take an educated guess if the signals and slots match
- QString signalsuffix = ::methodName(signal).mid(QString(::methodName(signal)).lastIndexOf(QRegExp("[A-Z]"))).toLower();
- QString slotprefix = ::methodName(slot).left(QString(::methodName(slot)).indexOf(QRegExp("[A-Z]"))).toLower();
+ QString signalsuffix = ::methodName(signal);
+ QString slotprefix = ::methodName(slot);
+ if(!baseName.isEmpty()) {
+ signalsuffix = signalsuffix.mid(baseName.count()).toLower();
+ slotprefix = slotprefix.left(slotprefix.count() - baseName.count()).toLower();
+ }
uint sizediff = qAbs(slotprefix.size() - signalsuffix.size());
int ratio = editingDistance(slotprefix, signalsuffix) - sizediff;
+// if(ratio < 2) {
+// qDebug() << Q_FUNC_INFO;
+// qDebug() << methodBaseName(signal) << methodBaseName(slot);
+// qDebug() << signalsuffix << slotprefix << sizediff << ratio;
+// }
return (ratio < 2);
}
QHash<QByteArray, int> syncMap_ = syncMap(object);
QHash<QByteArray, int>::const_iterator iter = syncMap_.constBegin();
while(iter != syncMap_.constEnd()) {
- qDebug() << iter.key() << "-->" << iter.value() << meta->method(iter.value()).signature();
+ qDebug() << qPrintable(QString("%1 --> %2 %3").arg(QString(iter.key()), 40).arg(iter.value()).arg(QString(meta->method(iter.value()).signature())));
iter++;
}
-// QHash<int, int> syncMap_ = syncMap(object);
-// QHash<int, int>::const_iterator iter = syncMap_.constBegin();
-// while(iter != syncMap_.constEnd()) {
-// qDebug() << iter.key() << meta->method(iter.key()).signature() << "-->" << iter.value() << meta->method(iter.value()).signature();
-// iter++;
-// }
+}
+
+void SignalProxy::updateSecureState() {
+ bool wasSecure = _secure;
+
+ _secure = !_peers.isEmpty();
+ PeerHash::const_iterator peerIter;
+ for(peerIter = _peers.constBegin(); peerIter != _peers.constEnd(); peerIter++) {
+ _secure &= (*peerIter)->isSecure();
+ }
+
+ if(wasSecure != _secure)
+ emit secureStateChanged(_secure);
}