~ubuntu-branches/ubuntu/trusty/quassel/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/coresessioneventprocessor.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-02-18 23:18:25 UTC
  • mto: This revision was merged to the branch mainline in revision 98.
  • Revision ID: package-import@ubuntu.com-20140218231825-hfgaeo3nmszt2pth
Tags: upstream-0.10~beta1
ImportĀ upstreamĀ versionĀ 0.10~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *   Copyright (C) 2005-2013 by the Quassel Project                        *
 
2
 *   Copyright (C) 2005-2014 by the Quassel Project                        *
3
3
 *   devel@quassel-irc.org                                                 *
4
4
 *                                                                         *
5
5
 *   This program is free software; you can redistribute it and/or modify  *
23
23
#include "coreirclisthelper.h"
24
24
#include "corenetwork.h"
25
25
#include "coresession.h"
 
26
#include "coretransfer.h"
 
27
#include "coretransfermanager.h"
26
28
#include "ctcpevent.h"
27
29
#include "ircevent.h"
28
30
#include "ircuser.h"
 
31
#include "logger.h"
29
32
#include "messageevent.h"
30
33
#include "netsplit.h"
31
34
#include "quassel.h"
1014
1017
}
1015
1018
 
1016
1019
 
 
1020
// http://www.irchelp.org/irchelp/rfc/ctcpspec.html
 
1021
// http://en.wikipedia.org/wiki/Direct_Client-to-Client
 
1022
void CoreSessionEventProcessor::handleCtcpDcc(CtcpEvent *e)
 
1023
{
 
1024
    // DCC support is unfinished, experimental and potentially dangerous, so make it opt-in
 
1025
    if (!Quassel::isOptionSet("enable-experimental-dcc")) {
 
1026
        quInfo() << "DCC disabled, start core with --enable-experimental-dcc if you really want to try it out";
 
1027
        return;
 
1028
    }
 
1029
 
 
1030
    // normal:  SEND <filename> <ip> <port> [<filesize>]
 
1031
    // reverse: SEND <filename> <ip> 0 <filesize> <token>
 
1032
    QStringList params = e->param().split(' ');
 
1033
    if (params.count()) {
 
1034
        QString cmd = params[0].toUpper();
 
1035
        if (cmd == "SEND") {
 
1036
            if (params.count() < 4) {
 
1037
                qWarning() << "Invalid DCC SEND request:" << e;  // TODO emit proper error to client
 
1038
                return;
 
1039
            }
 
1040
            QString filename = params[1];
 
1041
            QHostAddress address;
 
1042
            quint16 port = params[3].toUShort();
 
1043
            quint64 size = 0;
 
1044
            QString numIp = params[2]; // this is either IPv4 as a 32 bit value, or IPv6 (which always contains a colon)
 
1045
            if (numIp.contains(':')) { // IPv6
 
1046
                if (!address.setAddress(numIp)) {
 
1047
                    qWarning() << "Invalid IPv6:" << numIp;
 
1048
                    return;
 
1049
                }
 
1050
            }
 
1051
            else {
 
1052
                address.setAddress(numIp.toUInt());
 
1053
            }
 
1054
 
 
1055
            if (port == 0) { // Reverse DCC is indicated by a 0 port
 
1056
                emit newEvent(new MessageEvent(Message::Error, e->network(), tr("Reverse DCC SEND not supported"), e->prefix(), e->target(), Message::None, e->timestamp()));
 
1057
                return;
 
1058
            }
 
1059
            if (port < 1024) {
 
1060
                qWarning() << "Privileged port requested:" << port; // FIXME ask user if this is ok
 
1061
            }
 
1062
 
 
1063
 
 
1064
            if (params.count() > 4) { // filesize is optional
 
1065
                size = params[4].toULong();
 
1066
            }
 
1067
 
 
1068
            // TODO: check if target is the right thing to use for the partner
 
1069
            CoreTransfer *transfer = new CoreTransfer(Transfer::Receive, e->target(), filename, address, port, size, this);
 
1070
            coreSession()->signalProxy()->synchronize(transfer);
 
1071
            coreSession()->transferManager()->addTransfer(transfer);
 
1072
        }
 
1073
        else {
 
1074
            emit newEvent(new MessageEvent(Message::Error, e->network(), tr("DCC %1 not supported").arg(cmd), e->prefix(), e->target(), Message::None, e->timestamp()));
 
1075
            return;
 
1076
        }
 
1077
    }
 
1078
}
 
1079
 
 
1080
 
1017
1081
void CoreSessionEventProcessor::handleCtcpPing(CtcpEvent *e)
1018
1082
{
1019
1083
    e->setReply(e->param().isNull() ? "" : e->param());