Add IrcParser to handle data between the ircd and Quassel
[quassel.git] / src / core / corenetwork.cpp
index 76a9d55..05da413 100644 (file)
 
 #include "corenetwork.h"
 
 
 #include "corenetwork.h"
 
+#include "ctcphandler.h"
 #include "core.h"
 #include "core.h"
-#include "coresession.h"
 #include "coreidentity.h"
 #include "corenetworkconfig.h"
 #include "coreidentity.h"
 #include "corenetworkconfig.h"
-
-#include "ircserverhandler.h"
+#include "coresession.h"
 #include "coreuserinputhandler.h"
 #include "coreuserinputhandler.h"
-#include "ctcphandler.h"
+#include "ircserverhandler.h"
+#include "networkevent.h"
 
 INIT_SYNCABLE_OBJECT(CoreNetwork)
 CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session)
 
 INIT_SYNCABLE_OBJECT(CoreNetwork)
 CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session)
@@ -276,6 +276,39 @@ void CoreNetwork::removeChannelKey(const QString &channel) {
   _channelKeys.remove(channel.toLower());
 }
 
   _channelKeys.remove(channel.toLower());
 }
 
+#ifdef HAVE_QCA2
+Cipher *CoreNetwork::cipher(const QString &target) const {
+  if(target.isEmpty())
+    return 0;
+
+  QByteArray key = cipherKey(target);
+  if(key.isEmpty())
+    return 0;
+
+  CoreIrcChannel *channel = qobject_cast<CoreIrcChannel *>(ircChannel(target));
+  if(channel) {
+    if(channel->cipher()->setKey(key))
+      return channel->cipher();
+  } else {
+    CoreIrcUser *user = qobject_cast<CoreIrcUser *>(ircUser(target));
+    if(user && user->cipher()->setKey(key))
+      return user->cipher();
+  }
+  return 0;
+}
+
+QByteArray CoreNetwork::cipherKey(const QString &recipient) const {
+  return _cipherKeys.value(recipient.toLower(), QByteArray());
+}
+
+void CoreNetwork::setCipherKey(const QString &recipient, const QByteArray &key) {
+  if(!key.isEmpty())
+    _cipherKeys[recipient.toLower()] = key;
+  else
+    _cipherKeys.remove(recipient.toLower());
+}
+#endif /* HAVE_QCA2 */
+
 bool CoreNetwork::setAutoWhoDone(const QString &channel) {
   QString chan = channel.toLower();
   if(_autoWhoPending.value(chan, 0) <= 0)
 bool CoreNetwork::setAutoWhoDone(const QString &channel) {
   QString chan = channel.toLower();
   if(_autoWhoPending.value(chan, 0) <= 0)
@@ -294,7 +327,9 @@ void CoreNetwork::setMyNick(const QString &mynick) {
 void CoreNetwork::socketHasData() {
   while(socket.canReadLine()) {
     QByteArray s = socket.readLine().trimmed();
 void CoreNetwork::socketHasData() {
   while(socket.canReadLine()) {
     QByteArray s = socket.readLine().trimmed();
-    ircServerHandler()->handleServerMsg(s);
+    ircServerHandler()->handleServerMsg(s); // FIXME remove with events
+
+    coreSession()->eventManager()->sendEvent(new NetworkDataEvent(EventManager::NetworkIncoming, this, s));
   }
 }
 
   }
 }
 
@@ -632,7 +667,7 @@ void CoreNetwork::sendPing() {
   uint now = QDateTime::currentDateTime().toTime_t();
   if(_pingCount != 0) {
     qDebug() << "UserId:" << userId() << "Network:" << networkName() << "missed" << _pingCount << "pings."
   uint now = QDateTime::currentDateTime().toTime_t();
   if(_pingCount != 0) {
     qDebug() << "UserId:" << userId() << "Network:" << networkName() << "missed" << _pingCount << "pings."
-            << "BA:" << socket.bytesAvailable() << "BTW:" << socket.bytesToWrite();
+             << "BA:" << socket.bytesAvailable() << "BTW:" << socket.bytesToWrite();
   }
   if((int)_pingCount >= networkConfig()->maxPingCount() && now - _lastPingTime <= (uint)(_pingTimer.interval() / 1000) + 1) {
     // the second check compares the actual elapsed time since the last ping and the pingTimer interval
   }
   if((int)_pingCount >= networkConfig()->maxPingCount() && now - _lastPingTime <= (uint)(_pingTimer.interval() / 1000) + 1) {
     // the second check compares the actual elapsed time since the last ping and the pingTimer interval