root / modules / gadu_protocol / dcc / dcc-manager.cpp @ ea3566bd
History | View | Annotate | Download (14.6 kB)
| 1 | 18636b4a | Wojciech Treter | /***************************************************************************
|
|---|---|---|---|
| 2 | 18636b4a | Wojciech Treter | * * |
| 3 | 18636b4a | Wojciech Treter | * This program is free software; you can redistribute it and/or modify * |
| 4 | 18636b4a | Wojciech Treter | * it under the terms of the GNU General Public License as published by * |
| 5 | 18636b4a | Wojciech Treter | * the Free Software Foundation; either version 2 of the License, or * |
| 6 | 18636b4a | Wojciech Treter | * (at your option) any later version. * |
| 7 | 18636b4a | Wojciech Treter | * * |
| 8 | 18636b4a | Wojciech Treter | ***************************************************************************/ |
| 9 | 18636b4a | Wojciech Treter | |
| 10 | 18636b4a | Wojciech Treter | #include <QtCore/QtGlobal> |
| 11 | 18636b4a | Wojciech Treter | |
| 12 | 18636b4a | Wojciech Treter | #ifdef Q_OS_WIN
|
| 13 | 18636b4a | Wojciech Treter | #include <winsock2.h> |
| 14 | 18636b4a | Wojciech Treter | #else
|
| 15 | 18636b4a | Wojciech Treter | #include <arpa/inet.h> |
| 16 | 18636b4a | Wojciech Treter | #endif
|
| 17 | 18636b4a | Wojciech Treter | |
| 18 | 18636b4a | Wojciech Treter | #include "accounts/account.h" |
| 19 | d72b8f74 | Rafał Malinowski | #include "buddies/buddy.h" |
| 20 | d72b8f74 | Rafał Malinowski | #include "buddies/buddy-manager.h" |
| 21 | 28488f51 | Rafał Malinowski | #include "configuration/configuration-file.h" |
| 22 | 28488f51 | Rafał Malinowski | #include "contacts/contact.h" |
| 23 | 9469ed1a | Bartlomiej Zimon | #include "contacts/contact-manager.h" |
| 24 | ea3566bd | Rafał Malinowski | #include "file-transfer/file-transfer-manager.h" |
| 25 | 5c8d5ff9 | Michał Podsiadlik | #include "gui/windows/message-dialog.h" |
| 26 | 18636b4a | Wojciech Treter | |
| 27 | 18636b4a | Wojciech Treter | #include "debug.h" |
| 28 | 18636b4a | Wojciech Treter | #include "misc/misc.h" |
| 29 | 18636b4a | Wojciech Treter | |
| 30 | 18636b4a | Wojciech Treter | #include "dcc/dcc-manager.h" |
| 31 | 18636b4a | Wojciech Treter | #include "dcc/dcc-socket-notifiers.h" |
| 32 | ea3566bd | Rafał Malinowski | #include "file-transfer/gadu-file-transfer-handler.h" |
| 33 | 18636b4a | Wojciech Treter | #include "services/gadu-file-transfer-service.h" |
| 34 | 18636b4a | Wojciech Treter | #include "socket-notifiers/gadu-protocol-socket-notifiers.h" |
| 35 | a2e41fe6 | Rafał Malinowski | #include "gadu-account-details.h" |
| 36 | dec9a28f | Rafał Malinowski | #include "gadu-contact-details.h" |
| 37 | 18636b4a | Wojciech Treter | |
| 38 | 18636b4a | Wojciech Treter | #include "gadu-protocol.h" |
| 39 | 18636b4a | Wojciech Treter | |
| 40 | 18636b4a | Wojciech Treter | |
| 41 | 18636b4a | Wojciech Treter | DccManager::DccManager(GaduProtocol *protocol) : |
| 42 | 18636b4a | Wojciech Treter | QObject(protocol), Protocol(protocol), MainSocketNotifiers(0)
|
| 43 | 18636b4a | Wojciech Treter | {
|
| 44 | 18636b4a | Wojciech Treter | kdebugf(); |
| 45 | 18636b4a | Wojciech Treter | |
| 46 | 18636b4a | Wojciech Treter | setUpDcc(); |
| 47 | 18636b4a | Wojciech Treter | |
| 48 | 18636b4a | Wojciech Treter | kdebugf2(); |
| 49 | 18636b4a | Wojciech Treter | } |
| 50 | 18636b4a | Wojciech Treter | |
| 51 | 18636b4a | Wojciech Treter | DccManager::~DccManager() |
| 52 | 18636b4a | Wojciech Treter | {
|
| 53 | 18636b4a | Wojciech Treter | kdebugf(); |
| 54 | 18636b4a | Wojciech Treter | |
| 55 | 18636b4a | Wojciech Treter | closeDcc(); |
| 56 | 18636b4a | Wojciech Treter | |
| 57 | 18636b4a | Wojciech Treter | kdebugf2(); |
| 58 | 18636b4a | Wojciech Treter | } |
| 59 | 18636b4a | Wojciech Treter | |
| 60 | 18636b4a | Wojciech Treter | void DccManager::setUpExternalAddress(gg_login_params &loginParams)
|
| 61 | 18636b4a | Wojciech Treter | {
|
| 62 | 18636b4a | Wojciech Treter | bool haveExternalDcc = !DccExternalIP.isNull() && DccExternalPort > 1023; |
| 63 | 18636b4a | Wojciech Treter | loginParams.external_addr = haveExternalDcc ? htonl(DccExternalIP.toIPv4Address()) : 0;
|
| 64 | 18636b4a | Wojciech Treter | loginParams.external_port = haveExternalDcc ? DccExternalPort : 0;
|
| 65 | 18636b4a | Wojciech Treter | } |
| 66 | 18636b4a | Wojciech Treter | |
| 67 | 18636b4a | Wojciech Treter | |
| 68 | 18636b4a | Wojciech Treter | /*
|
| 69 | 18636b4a | Wojciech Treter | void DccManager::mainConfigurationWindowCreated(MainConfigurationWindow *mainConfigurationWindow) |
| 70 | 18636b4a | Wojciech Treter | {
|
| 71 | 18636b4a | Wojciech Treter | QWidget *allowDCC = mainConfigurationWindow->widgetById("dcc/AllowDCC");
|
| 72 | 18636b4a | Wojciech Treter | QWidget *fileTransfers = mainConfigurationWindow->widgetById("dcc/fileTransfers");
|
| 73 | 18636b4a | Wojciech Treter | QWidget *ip = mainConfigurationWindow->widgetById("dcc/ip");
|
| 74 | 18636b4a | Wojciech Treter | |
| 75 | 18636b4a | Wojciech Treter | connect(allowDCC, SIGNAL(toggled(bool)), fileTransfers, SLOT(setEnabled(bool))); |
| 76 | 18636b4a | Wojciech Treter | connect(allowDCC, SIGNAL(toggled(bool)), ip, SLOT(setEnabled(bool))); |
| 77 | 18636b4a | Wojciech Treter | |
| 78 | 18636b4a | Wojciech Treter | QWidget *ipAutotetect = mainConfigurationWindow->widgetById("dcc/ipAutodetect");
|
| 79 | 18636b4a | Wojciech Treter | ipAddress = mainConfigurationWindow->widgetById("dcc/ipAddress");
|
| 80 | 18636b4a | Wojciech Treter | forwarding = dynamic_cast<QCheckBox *>(mainConfigurationWindow->widgetById("dcc/forwarding"));
|
| 81 | 18636b4a | Wojciech Treter | forwardingExternalIp = mainConfigurationWindow->widgetById("dcc/forwardingExternalIp");
|
| 82 | 18636b4a | Wojciech Treter | forwardingExternalPort = mainConfigurationWindow->widgetById("dcc/forwardingExternalPort");
|
| 83 | 18636b4a | Wojciech Treter | forwardingLocalPort = mainConfigurationWindow->widgetById("dcc/forwardingLocalPort");
|
| 84 | 18636b4a | Wojciech Treter | |
| 85 | 18636b4a | Wojciech Treter | connect(forwarding, SIGNAL(toggled(bool)), forwardingExternalIp, SLOT(setEnabled(bool))); |
| 86 | 18636b4a | Wojciech Treter | connect(forwarding, SIGNAL(toggled(bool)), forwardingExternalPort, SLOT(setEnabled(bool))); |
| 87 | 18636b4a | Wojciech Treter | connect(forwarding, SIGNAL(toggled(bool)), forwardingLocalPort, SLOT(setEnabled(bool))); |
| 88 | 18636b4a | Wojciech Treter | |
| 89 | 18636b4a | Wojciech Treter | connect(ipAutotetect, SIGNAL(toggled(bool)), ipAddress, SLOT(setDisabled(bool))); |
| 90 | 18636b4a | Wojciech Treter | connect(ipAutotetect, SIGNAL(toggled(bool)), this, SLOT(onIpAutotetectToggled(bool))); |
| 91 | 18636b4a | Wojciech Treter | }*/ |
| 92 | 18636b4a | Wojciech Treter | |
| 93 | 18636b4a | Wojciech Treter | void DccManager::setUpDcc()
|
| 94 | 18636b4a | Wojciech Treter | {
|
| 95 | 18636b4a | Wojciech Treter | kdebugf(); |
| 96 | 18636b4a | Wojciech Treter | |
| 97 | 18636b4a | Wojciech Treter | WaitingFileTransfers.clear(); |
| 98 | 18636b4a | Wojciech Treter | |
| 99 | 946ac1c4 | Rafał Malinowski | GaduAccountDetails *gaduAccountDetails = dynamic_cast<GaduAccountDetails *>(Protocol->account().details());
|
| 100 | a2e41fe6 | Rafał Malinowski | if (!gaduAccountDetails)
|
| 101 | 18636b4a | Wojciech Treter | return;
|
| 102 | 18636b4a | Wojciech Treter | |
| 103 | a2e41fe6 | Rafał Malinowski | struct gg_dcc *socket = gg_dcc_socket_create(gaduAccountDetails->uin(), gaduAccountDetails->dccLocalPort());
|
| 104 | 18636b4a | Wojciech Treter | if (!socket)
|
| 105 | 18636b4a | Wojciech Treter | {
|
| 106 | 18636b4a | Wojciech Treter | kdebugmf(KDEBUG_NETWORK | KDEBUG_INFO, "Couldn't bind DCC socket.\n");
|
| 107 | 18636b4a | Wojciech Treter | |
| 108 | 18636b4a | Wojciech Treter | // TODO: 0.6.6
|
| 109 | 5c8d5ff9 | Michał Podsiadlik | // MessageDialog::msg(tr("Couldn't create DCC socket.\nDirect connections disabled."), true, "Warning");
|
| 110 | 18636b4a | Wojciech Treter | kdebugf2(); |
| 111 | 18636b4a | Wojciech Treter | return;
|
| 112 | 18636b4a | Wojciech Treter | } |
| 113 | 18636b4a | Wojciech Treter | |
| 114 | 18636b4a | Wojciech Treter | MainSocketNotifiers = new DccSocketNotifiers(Protocol, this); |
| 115 | 18636b4a | Wojciech Treter | SocketNotifiers = QList<DccSocketNotifiers *>(); |
| 116 | 18636b4a | Wojciech Treter | |
| 117 | 18636b4a | Wojciech Treter | QHostAddress DCCIP; |
| 118 | 18636b4a | Wojciech Treter | short int DCCPort; |
| 119 | 18636b4a | Wojciech Treter | |
| 120 | a2e41fe6 | Rafał Malinowski | if (gaduAccountDetails->dccIpDetect())
|
| 121 | 18636b4a | Wojciech Treter | DCCIP.setAddress("255.255.255.255");
|
| 122 | 18636b4a | Wojciech Treter | else
|
| 123 | a2e41fe6 | Rafał Malinowski | DCCIP = gaduAccountDetails->dccIP(); |
| 124 | 18636b4a | Wojciech Treter | |
| 125 | 18636b4a | Wojciech Treter | QHostAddress ext_ip; |
| 126 | 18636b4a | Wojciech Treter | |
| 127 | a2e41fe6 | Rafał Malinowski | bool forwarding = gaduAccountDetails->dccForwarding() && !gaduAccountDetails->dccExternalIP().isNull();
|
| 128 | 18636b4a | Wojciech Treter | |
| 129 | 18636b4a | Wojciech Treter | DccExternalIP = forwarding ? ext_ip : QHostAddress(); |
| 130 | a2e41fe6 | Rafał Malinowski | DccExternalPort = forwarding ? gaduAccountDetails->dccExternalPort() : 0;
|
| 131 | 18636b4a | Wojciech Treter | |
| 132 | 18636b4a | Wojciech Treter | gg_dcc_ip = htonl(DCCIP.toIPv4Address()); |
| 133 | 18636b4a | Wojciech Treter | gg_dcc_port = socket->port; |
| 134 | 18636b4a | Wojciech Treter | |
| 135 | 18636b4a | Wojciech Treter | kdebugmf(KDEBUG_NETWORK | KDEBUG_INFO, "DCC_IP=%s DCC_PORT=%d\n", qPrintable(DCCIP.toString()), DCCPort);
|
| 136 | 18636b4a | Wojciech Treter | |
| 137 | 18636b4a | Wojciech Treter | DccEnabled = true;
|
| 138 | 18636b4a | Wojciech Treter | |
| 139 | 18636b4a | Wojciech Treter | connectSocketNotifiers(MainSocketNotifiers); |
| 140 | 18636b4a | Wojciech Treter | MainSocketNotifiers->watchFor(socket); |
| 141 | 18636b4a | Wojciech Treter | |
| 142 | 18636b4a | Wojciech Treter | kdebugf2(); |
| 143 | 18636b4a | Wojciech Treter | } |
| 144 | 18636b4a | Wojciech Treter | /*
|
| 145 | 18636b4a | Wojciech Treter | void DccManager::onIpAutotetectToggled(bool toggled) |
| 146 | 18636b4a | Wojciech Treter | {
|
| 147 | 18636b4a | Wojciech Treter | forwarding->setEnabled(!toggled); |
| 148 | 18636b4a | Wojciech Treter | |
| 149 | 18636b4a | Wojciech Treter | if (toggled) |
| 150 | 18636b4a | Wojciech Treter | {
|
| 151 | 18636b4a | Wojciech Treter | forwardingExternalIp->setEnabled(false); |
| 152 | 18636b4a | Wojciech Treter | forwardingExternalPort->setEnabled(false); |
| 153 | 18636b4a | Wojciech Treter | forwardingLocalPort->setEnabled(false); |
| 154 | 18636b4a | Wojciech Treter | } |
| 155 | 18636b4a | Wojciech Treter | else |
| 156 | 18636b4a | Wojciech Treter | {
|
| 157 | 18636b4a | Wojciech Treter | forwardingExternalIp->setEnabled(forwarding->isChecked()); |
| 158 | 18636b4a | Wojciech Treter | forwardingExternalPort->setEnabled(forwarding->isChecked()); |
| 159 | 18636b4a | Wojciech Treter | forwardingLocalPort->setEnabled(forwarding->isChecked()); |
| 160 | 18636b4a | Wojciech Treter | } |
| 161 | 18636b4a | Wojciech Treter | }*/ |
| 162 | 18636b4a | Wojciech Treter | |
| 163 | 18636b4a | Wojciech Treter | void DccManager::configurationUpdated()
|
| 164 | 18636b4a | Wojciech Treter | {
|
| 165 | 18636b4a | Wojciech Treter | // GaduAccount *account = dynamic_cast<GaduAccount *>(Protocol->account());
|
| 166 | 18636b4a | Wojciech Treter | // if (!account)
|
| 167 | 18636b4a | Wojciech Treter | // return;
|
| 168 | 18636b4a | Wojciech Treter | // account->loadConfiguration(xml_config_file);
|
| 169 | 18636b4a | Wojciech Treter | |
| 170 | 18636b4a | Wojciech Treter | |
| 171 | 18636b4a | Wojciech Treter | |
| 172 | 18636b4a | Wojciech Treter | // kadu->reconnect() ??
|
| 173 | 18636b4a | Wojciech Treter | } |
| 174 | 18636b4a | Wojciech Treter | |
| 175 | 18636b4a | Wojciech Treter | bool DccManager::dccEnabled() const |
| 176 | 18636b4a | Wojciech Treter | {
|
| 177 | 18636b4a | Wojciech Treter | return DccEnabled;
|
| 178 | 18636b4a | Wojciech Treter | } |
| 179 | 18636b4a | Wojciech Treter | |
| 180 | 18636b4a | Wojciech Treter | // void DccManager::timeout()
|
| 181 | 18636b4a | Wojciech Treter | // {
|
| 182 | 18636b4a | Wojciech Treter | // TODO: change into notification
|
| 183 | 5c8d5ff9 | Michał Podsiadlik | // MessageDialog::msg(tr("Direct connection timeout!\nThe receiver doesn't support direct connections or\nboth machines are behind routers with NAT."), true, "Warning");
|
| 184 | 18636b4a | Wojciech Treter | // }
|
| 185 | 18636b4a | Wojciech Treter | |
| 186 | 18636b4a | Wojciech Treter | void DccManager::closeDcc()
|
| 187 | 18636b4a | Wojciech Treter | {
|
| 188 | 18636b4a | Wojciech Treter | kdebugf(); |
| 189 | 18636b4a | Wojciech Treter | |
| 190 | 18636b4a | Wojciech Treter | gg_dcc_ip = 0;
|
| 191 | 18636b4a | Wojciech Treter | gg_dcc_port = 0;
|
| 192 | 18636b4a | Wojciech Treter | DccEnabled = false;
|
| 193 | 18636b4a | Wojciech Treter | |
| 194 | 18636b4a | Wojciech Treter | kdebugf2(); |
| 195 | 18636b4a | Wojciech Treter | } |
| 196 | 18636b4a | Wojciech Treter | |
| 197 | 18636b4a | Wojciech Treter | void DccManager::connectSocketNotifiers(DccSocketNotifiers *notifiers)
|
| 198 | 18636b4a | Wojciech Treter | {
|
| 199 | 18636b4a | Wojciech Treter | connect(notifiers, SIGNAL(destroyed(QObject *)), |
| 200 | 18636b4a | Wojciech Treter | this, SLOT(socketNotifiersDestroyed(QObject *)));
|
| 201 | 18636b4a | Wojciech Treter | connect(notifiers, SIGNAL(incomingConnection(struct gg_dcc *)),
|
| 202 | 18636b4a | Wojciech Treter | this, SLOT(dccIncomingConnection(struct gg_dcc *))); |
| 203 | 18636b4a | Wojciech Treter | } |
| 204 | 18636b4a | Wojciech Treter | |
| 205 | 18636b4a | Wojciech Treter | void DccManager::disconnectSocketNotifiers(DccSocketNotifiers *notifiers)
|
| 206 | 18636b4a | Wojciech Treter | {
|
| 207 | 18636b4a | Wojciech Treter | disconnect(notifiers, SIGNAL(destroyed(QObject *)), |
| 208 | 18636b4a | Wojciech Treter | this, SLOT(socketNotifiersDestroyed(QObject *)));
|
| 209 | 18636b4a | Wojciech Treter | disconnect(notifiers, SIGNAL(incomingConnection(struct gg_dcc *)),
|
| 210 | 18636b4a | Wojciech Treter | this, SLOT(dccIncomingConnection(struct gg_dcc *))); |
| 211 | 18636b4a | Wojciech Treter | } |
| 212 | 18636b4a | Wojciech Treter | |
| 213 | 18636b4a | Wojciech Treter | void DccManager::socketNotifiersDestroyed(QObject *socketNotifiers)
|
| 214 | 18636b4a | Wojciech Treter | {
|
| 215 | 18636b4a | Wojciech Treter | SocketNotifiers.removeAll(dynamic_cast<DccSocketNotifiers *>(socketNotifiers));
|
| 216 | 18636b4a | Wojciech Treter | } |
| 217 | 18636b4a | Wojciech Treter | |
| 218 | 9469ed1a | Bartlomiej Zimon | void DccManager::connectionRequestReceived(Contact contact)
|
| 219 | 18636b4a | Wojciech Treter | {
|
| 220 | 18636b4a | Wojciech Treter | kdebugf(); |
| 221 | 18636b4a | Wojciech Treter | |
| 222 | dec9a28f | Rafał Malinowski | if (contact.isNull())
|
| 223 | 18636b4a | Wojciech Treter | return;
|
| 224 | a2e41fe6 | Rafał Malinowski | |
| 225 | 9469ed1a | Bartlomiej Zimon | GaduContactDetails *details = Protocol->gaduContactDetails(contact); |
| 226 | dec9a28f | Rafał Malinowski | if (!details)
|
| 227 | 18636b4a | Wojciech Treter | return;
|
| 228 | 18636b4a | Wojciech Treter | |
| 229 | dec9a28f | Rafał Malinowski | struct gg_dcc *dcc = gg_dcc_get_file(htonl(contact.address().toIPv4Address()), contact.port(), details->uin(), details->uin());
|
| 230 | 18636b4a | Wojciech Treter | if (!dcc)
|
| 231 | 18636b4a | Wojciech Treter | return;
|
| 232 | 18636b4a | Wojciech Treter | |
| 233 | 18636b4a | Wojciech Treter | DccSocketNotifiers *dccSocketNotifiers = new DccSocketNotifiers(Protocol, this); |
| 234 | 18636b4a | Wojciech Treter | SocketNotifiers << dccSocketNotifiers; |
| 235 | 18636b4a | Wojciech Treter | connectSocketNotifiers(dccSocketNotifiers); |
| 236 | 18636b4a | Wojciech Treter | dccSocketNotifiers->watchFor(dcc); |
| 237 | 18636b4a | Wojciech Treter | |
| 238 | 18636b4a | Wojciech Treter | kdebugf2(); |
| 239 | 18636b4a | Wojciech Treter | } |
| 240 | 18636b4a | Wojciech Treter | |
| 241 | 18636b4a | Wojciech Treter | bool DccManager::acceptConnection(unsigned int uin, unsigned int peerUin, unsigned int peerAddr) |
| 242 | 18636b4a | Wojciech Treter | {
|
| 243 | 946ac1c4 | Rafał Malinowski | GaduAccountDetails *gaduAccountDetails = dynamic_cast<GaduAccountDetails *>(Protocol->account().details());
|
| 244 | a2e41fe6 | Rafał Malinowski | if (!gaduAccountDetails)
|
| 245 | 18636b4a | Wojciech Treter | return false; |
| 246 | 18636b4a | Wojciech Treter | |
| 247 | 9469ed1a | Bartlomiej Zimon | Contact contact = ContactManager::instance()->byId(Protocol->account(), QString::number(peerUin)); |
| 248 | 9469ed1a | Bartlomiej Zimon | if (contact.isNull())
|
| 249 | 9469ed1a | Bartlomiej Zimon | return false; |
| 250 | 9469ed1a | Bartlomiej Zimon | |
| 251 | 9469ed1a | Bartlomiej Zimon | Buddy buddy = contact.ownerBuddy(); |
| 252 | 1d848ea7 | Rafał Malinowski | if (uin != gaduAccountDetails->uin() || buddy.isAnonymous() || buddy.isNull())
|
| 253 | 18636b4a | Wojciech Treter | {
|
| 254 | 18636b4a | Wojciech Treter | kdebugm(KDEBUG_WARNING, "insane values: uin:%d peer_uin:%d\n", uin, peerUin);
|
| 255 | 18636b4a | Wojciech Treter | return false; |
| 256 | 18636b4a | Wojciech Treter | } |
| 257 | 18636b4a | Wojciech Treter | |
| 258 | 1d848ea7 | Rafał Malinowski | if (buddy.isIgnored())
|
| 259 | 18636b4a | Wojciech Treter | {
|
| 260 | 18636b4a | Wojciech Treter | kdebugm(KDEBUG_WARNING, "unbidden user: %d\n", peerUin);
|
| 261 | 18636b4a | Wojciech Treter | return false; |
| 262 | 18636b4a | Wojciech Treter | } |
| 263 | 18636b4a | Wojciech Treter | |
| 264 | 18636b4a | Wojciech Treter | QHostAddress remoteAddress(ntohl(peerAddr)); |
| 265 | 18636b4a | Wojciech Treter | |
| 266 | dec9a28f | Rafał Malinowski | if (remoteAddress == contact.address())
|
| 267 | 18636b4a | Wojciech Treter | return true; |
| 268 | 18636b4a | Wojciech Treter | |
| 269 | 18636b4a | Wojciech Treter | kdebugm(KDEBUG_WARNING, "possible spoofing attempt from %s (uin:%d)\n", qPrintable(remoteAddress.toString()), peerUin);
|
| 270 | 18636b4a | Wojciech Treter | |
| 271 | 5c8d5ff9 | Michał Podsiadlik | return MessageDialog::ask(narg(
|
| 272 | 18636b4a | Wojciech Treter | tr("%1 is asking for direct connection but his/her\n"
|
| 273 | 18636b4a | Wojciech Treter | "IP address (%2) differs from what GG server returned\n"
|
| 274 | 18636b4a | Wojciech Treter | "as his/her IP address (%3). It may be spoofing\n"
|
| 275 | 18636b4a | Wojciech Treter | "or he/she has port forwarding. Continue connection?"),
|
| 276 | 1d848ea7 | Rafał Malinowski | buddy.display(), |
| 277 | 18636b4a | Wojciech Treter | remoteAddress.toString(), |
| 278 | dec9a28f | Rafał Malinowski | contact.address().toString())); |
| 279 | 18636b4a | Wojciech Treter | } |
| 280 | 18636b4a | Wojciech Treter | |
| 281 | 18636b4a | Wojciech Treter | void DccManager::needIncomingFileTransferAccept(DccSocketNotifiers *socket)
|
| 282 | 18636b4a | Wojciech Treter | {
|
| 283 | ea3566bd | Rafał Malinowski | FileTransfer fileTransfer = FileTransfer::create(); |
| 284 | ea3566bd | Rafał Malinowski | fileTransfer.setFileTransferAccount(Protocol->account()); |
| 285 | ea3566bd | Rafał Malinowski | fileTransfer.setFileTransferContact(ContactManager::instance()->byId(Protocol->account(), QString::number(socket->peerUin()), true));
|
| 286 | ea3566bd | Rafał Malinowski | fileTransfer.setTransferType(TypeReceive); |
| 287 | ea3566bd | Rafał Malinowski | FileTransferManager::instance()->addItem(fileTransfer); |
| 288 | 18636b4a | Wojciech Treter | |
| 289 | ea3566bd | Rafał Malinowski | GaduFileTransferHandler *handler = new GaduFileTransferHandler(fileTransfer);
|
| 290 | ea3566bd | Rafał Malinowski | fileTransfer.setHandler(handler); |
| 291 | 18636b4a | Wojciech Treter | |
| 292 | ea3566bd | Rafał Malinowski | handler->setFileTransferNotifiers(socket); |
| 293 | ea3566bd | Rafał Malinowski | socket->setGaduFileTransferHandler(handler); |
| 294 | ea3566bd | Rafał Malinowski | |
| 295 | ea3566bd | Rafał Malinowski | emit Protocol->CurrentFileTransferService->incomingFileTransfer(fileTransfer); |
| 296 | 18636b4a | Wojciech Treter | } |
| 297 | 18636b4a | Wojciech Treter | |
| 298 | ea3566bd | Rafał Malinowski | GaduFileTransferHandler * DccManager::findFileTransferHandler(DccSocketNotifiers *notifiers) |
| 299 | 18636b4a | Wojciech Treter | {
|
| 300 | ea3566bd | Rafał Malinowski | foreach (GaduFileTransferHandler *handler, WaitingFileTransfers) |
| 301 | 18636b4a | Wojciech Treter | {
|
| 302 | ea3566bd | Rafał Malinowski | UinType uin = Protocol->uin(handler->transfer().fileTransferContact()); |
| 303 | 18636b4a | Wojciech Treter | if (uin == notifiers->peerUin())
|
| 304 | 18636b4a | Wojciech Treter | {
|
| 305 | 18636b4a | Wojciech Treter | disconnectSocketNotifiers(notifiers); |
| 306 | 18636b4a | Wojciech Treter | SocketNotifiers.removeAll(notifiers); |
| 307 | ea3566bd | Rafał Malinowski | return handler;
|
| 308 | 18636b4a | Wojciech Treter | } |
| 309 | 18636b4a | Wojciech Treter | } |
| 310 | 18636b4a | Wojciech Treter | |
| 311 | 18636b4a | Wojciech Treter | return 0; |
| 312 | 18636b4a | Wojciech Treter | } |
| 313 | 18636b4a | Wojciech Treter | |
| 314 | 18636b4a | Wojciech Treter | void DccManager::handleEventDccNew(struct gg_event *e) { |
| 315 | 18636b4a | Wojciech Treter | kdebugmf(KDEBUG_NETWORK | KDEBUG_INFO, "GG_EVENT_DCC_NEW\n");
|
| 316 | 18636b4a | Wojciech Treter | |
| 317 | 18636b4a | Wojciech Treter | DccSocketNotifiers *newSocketNotifiers = new DccSocketNotifiers(Protocol, this); |
| 318 | 18636b4a | Wojciech Treter | SocketNotifiers << newSocketNotifiers; |
| 319 | 18636b4a | Wojciech Treter | connectSocketNotifiers(newSocketNotifiers); |
| 320 | 18636b4a | Wojciech Treter | newSocketNotifiers->watchFor(e->event.dcc_new); |
| 321 | 18636b4a | Wojciech Treter | |
| 322 | 18636b4a | Wojciech Treter | e->event.dcc_new = 0;
|
| 323 | 18636b4a | Wojciech Treter | } |
| 324 | 18636b4a | Wojciech Treter | |
| 325 | 18636b4a | Wojciech Treter | void DccManager::handleEventDcc7New(struct gg_event *e) |
| 326 | 18636b4a | Wojciech Treter | {
|
| 327 | 18636b4a | Wojciech Treter | kdebugf(); |
| 328 | 18636b4a | Wojciech Treter | |
| 329 | 18636b4a | Wojciech Treter | struct gg_dcc7 *dcc = e->event.dcc7_new;
|
| 330 | 18636b4a | Wojciech Treter | /*
|
| 331 | 18636b4a | Wojciech Treter | if (!acceptConnection(dcc->uin, dcc->peer_uin, dcc->remote_addr)) |
| 332 | 18636b4a | Wojciech Treter | {
|
| 333 | 18636b4a | Wojciech Treter | gg_dcc7_reject(dcc, 0); |
| 334 | 18636b4a | Wojciech Treter | gg_dcc7_free(dcc); |
| 335 | 18636b4a | Wojciech Treter | return; |
| 336 | 18636b4a | Wojciech Treter | } |
| 337 | 18636b4a | Wojciech Treter | */ |
| 338 | 18636b4a | Wojciech Treter | switch (dcc->dcc_type)
|
| 339 | 18636b4a | Wojciech Treter | {
|
| 340 | 18636b4a | Wojciech Treter | case GG_DCC7_TYPE_FILE:
|
| 341 | 18636b4a | Wojciech Treter | {
|
| 342 | 18636b4a | Wojciech Treter | // TODO: ZARAZ
|
| 343 | 18636b4a | Wojciech Treter | DccSocketNotifiers *newSocketNotifiers = new DccSocketNotifiers(Protocol, this); |
| 344 | 18636b4a | Wojciech Treter | SocketNotifiers << newSocketNotifiers; |
| 345 | 18636b4a | Wojciech Treter | connectSocketNotifiers(newSocketNotifiers); |
| 346 | 18636b4a | Wojciech Treter | newSocketNotifiers->watchFor(e->event.dcc7_new); |
| 347 | 18636b4a | Wojciech Treter | needIncomingFileTransferAccept(newSocketNotifiers); |
| 348 | 18636b4a | Wojciech Treter | // file_transfer_manager->dcc7IncomingFileTransfer(new DccSocket(dcc));
|
| 349 | 18636b4a | Wojciech Treter | break;
|
| 350 | 18636b4a | Wojciech Treter | } |
| 351 | 18636b4a | Wojciech Treter | |
| 352 | 18636b4a | Wojciech Treter | default:
|
| 353 | 18636b4a | Wojciech Treter | gg_dcc7_reject(dcc, GG_DCC7_REJECT_USER); |
| 354 | 18636b4a | Wojciech Treter | gg_dcc7_free(dcc); |
| 355 | 18636b4a | Wojciech Treter | break;
|
| 356 | 18636b4a | Wojciech Treter | } |
| 357 | 18636b4a | Wojciech Treter | |
| 358 | 18636b4a | Wojciech Treter | kdebugf2(); |
| 359 | 18636b4a | Wojciech Treter | } |
| 360 | 18636b4a | Wojciech Treter | |
| 361 | 18636b4a | Wojciech Treter | void DccManager::handleEventDcc7Accept(struct gg_event *e) |
| 362 | 18636b4a | Wojciech Treter | {
|
| 363 | 18636b4a | Wojciech Treter | kdebugf(); |
| 364 | 18636b4a | Wojciech Treter | |
| 365 | 18636b4a | Wojciech Treter | foreach (DccSocketNotifiers *socketNotifiers, SocketNotifiers) |
| 366 | 18636b4a | Wojciech Treter | {
|
| 367 | 18636b4a | Wojciech Treter | if (socketNotifiers->Socket7 == e->event.dcc7_accept.dcc7)
|
| 368 | 18636b4a | Wojciech Treter | {
|
| 369 | 18636b4a | Wojciech Treter | socketNotifiers->handleEventDcc7Accept(e); |
| 370 | 18636b4a | Wojciech Treter | return;
|
| 371 | 18636b4a | Wojciech Treter | } |
| 372 | 18636b4a | Wojciech Treter | } |
| 373 | 18636b4a | Wojciech Treter | } |
| 374 | 18636b4a | Wojciech Treter | |
| 375 | 18636b4a | Wojciech Treter | void DccManager::handleEventDcc7Reject(struct gg_event *e) |
| 376 | 18636b4a | Wojciech Treter | {
|
| 377 | 18636b4a | Wojciech Treter | kdebugf(); |
| 378 | 18636b4a | Wojciech Treter | |
| 379 | 18636b4a | Wojciech Treter | foreach (DccSocketNotifiers *socketNotifiers, SocketNotifiers) |
| 380 | 18636b4a | Wojciech Treter | {
|
| 381 | 18636b4a | Wojciech Treter | if (socketNotifiers->Socket7 == e->event.dcc7_accept.dcc7)
|
| 382 | 18636b4a | Wojciech Treter | {
|
| 383 | 18636b4a | Wojciech Treter | socketNotifiers->handleEventDcc7Reject(e); |
| 384 | 18636b4a | Wojciech Treter | return;
|
| 385 | 18636b4a | Wojciech Treter | } |
| 386 | 18636b4a | Wojciech Treter | } |
| 387 | 18636b4a | Wojciech Treter | } |
| 388 | 18636b4a | Wojciech Treter | |
| 389 | 18636b4a | Wojciech Treter | void DccManager::handleEventDcc7Pending(struct gg_event *e) |
| 390 | 18636b4a | Wojciech Treter | {
|
| 391 | 18636b4a | Wojciech Treter | kdebugf(); |
| 392 | 18636b4a | Wojciech Treter | |
| 393 | 18636b4a | Wojciech Treter | foreach (DccSocketNotifiers *socketNotifiers, SocketNotifiers) |
| 394 | 18636b4a | Wojciech Treter | {
|
| 395 | 18636b4a | Wojciech Treter | socketNotifiers->handleEventDcc7Pending(e); |
| 396 | 18636b4a | Wojciech Treter | return;
|
| 397 | 18636b4a | Wojciech Treter | } |
| 398 | 18636b4a | Wojciech Treter | } |
| 399 | 18636b4a | Wojciech Treter | |
| 400 | 18636b4a | Wojciech Treter | void DccManager::handleEventDcc7Error(struct gg_event *e) |
| 401 | 18636b4a | Wojciech Treter | {
|
| 402 | 18636b4a | Wojciech Treter | kdebugf(); |
| 403 | 18636b4a | Wojciech Treter | |
| 404 | 18636b4a | Wojciech Treter | foreach (DccSocketNotifiers *socketNotifiers, SocketNotifiers) |
| 405 | 18636b4a | Wojciech Treter | {
|
| 406 | 18636b4a | Wojciech Treter | // if (socketNotifiers->Socket7 == e->event.dcc7_error)
|
| 407 | 18636b4a | Wojciech Treter | // {
|
| 408 | 18636b4a | Wojciech Treter | // socketNotifiers->handleEventDcc7Error(e);
|
| 409 | 18636b4a | Wojciech Treter | // return;
|
| 410 | 18636b4a | Wojciech Treter | // }
|
| 411 | 18636b4a | Wojciech Treter | } |
| 412 | 18636b4a | Wojciech Treter | } |
| 413 | 18636b4a | Wojciech Treter | |
| 414 | ea3566bd | Rafał Malinowski | void DccManager::fileTransferHandlerDestroyed(QObject *object)
|
| 415 | ea3566bd | Rafał Malinowski | {
|
| 416 | ea3566bd | Rafał Malinowski | GaduFileTransferHandler *handler = qobject_cast<GaduFileTransferHandler *>(object); |
| 417 | ea3566bd | Rafał Malinowski | |
| 418 | ea3566bd | Rafał Malinowski | if (handler)
|
| 419 | ea3566bd | Rafał Malinowski | WaitingFileTransfers.removeAll(handler); |
| 420 | ea3566bd | Rafał Malinowski | } |
| 421 | ea3566bd | Rafał Malinowski | |
| 422 | ea3566bd | Rafał Malinowski | void DccManager::attachSendFileTransferSocket6(unsigned int uin, Contact contact, GaduFileTransferHandler *handler) |
| 423 | 18636b4a | Wojciech Treter | {
|
| 424 | 18636b4a | Wojciech Treter | kdebugf(); |
| 425 | 18636b4a | Wojciech Treter | |
| 426 | dec9a28f | Rafał Malinowski | if (contact.isNull())
|
| 427 | dec9a28f | Rafał Malinowski | return;
|
| 428 | dec9a28f | Rafał Malinowski | |
| 429 | 9469ed1a | Bartlomiej Zimon | GaduContactDetails *details = Protocol->gaduContactDetails(contact); |
| 430 | dec9a28f | Rafał Malinowski | if (!details)
|
| 431 | dec9a28f | Rafał Malinowski | return;
|
| 432 | dec9a28f | Rafał Malinowski | |
| 433 | dec9a28f | Rafał Malinowski | int port = contact.port();
|
| 434 | 18636b4a | Wojciech Treter | if (port >= 10) |
| 435 | 18636b4a | Wojciech Treter | {
|
| 436 | dec9a28f | Rafał Malinowski | struct gg_dcc *socket = gg_dcc_send_file(htonl(contact.address().toIPv4Address()), port, uin, details->uin());
|
| 437 | 18636b4a | Wojciech Treter | if (socket)
|
| 438 | 18636b4a | Wojciech Treter | {
|
| 439 | 18636b4a | Wojciech Treter | DccSocketNotifiers *fileTransferNotifiers = new DccSocketNotifiers(Protocol, this); |
| 440 | ea3566bd | Rafał Malinowski | handler->setFileTransferNotifiers(fileTransferNotifiers); |
| 441 | 18636b4a | Wojciech Treter | fileTransferNotifiers->watchFor(socket); |
| 442 | 18636b4a | Wojciech Treter | return;
|
| 443 | 18636b4a | Wojciech Treter | } |
| 444 | 18636b4a | Wojciech Treter | } |
| 445 | 18636b4a | Wojciech Treter | |
| 446 | 18636b4a | Wojciech Treter | kdebugmf(KDEBUG_INFO | KDEBUG_NETWORK, "needs callback\n");
|
| 447 | 18636b4a | Wojciech Treter | |
| 448 | 18636b4a | Wojciech Treter | // startTimeOut
|
| 449 | ea3566bd | Rafał Malinowski | connect(handler, SIGNAL(destroyed(QObject *)), this, SLOT(fileTransferHandlerDestroyed(QObject *)));
|
| 450 | ea3566bd | Rafał Malinowski | WaitingFileTransfers << handler; |
| 451 | dec9a28f | Rafał Malinowski | gg_dcc_request(Protocol->gaduSession(), details->uin()); |
| 452 | 18636b4a | Wojciech Treter | } |
| 453 | 18636b4a | Wojciech Treter | |
| 454 | ea3566bd | Rafał Malinowski | void DccManager::attachSendFileTransferSocket7(unsigned int uin, Contact contact, GaduFileTransferHandler *handler) |
| 455 | 18636b4a | Wojciech Treter | {
|
| 456 | 18636b4a | Wojciech Treter | kdebugf(); |
| 457 | 18636b4a | Wojciech Treter | |
| 458 | dec9a28f | Rafał Malinowski | if (contact.isNull())
|
| 459 | dec9a28f | Rafał Malinowski | return;
|
| 460 | dec9a28f | Rafał Malinowski | |
| 461 | 9469ed1a | Bartlomiej Zimon | GaduContactDetails *details = Protocol->gaduContactDetails(contact); |
| 462 | dec9a28f | Rafał Malinowski | if (!details)
|
| 463 | dec9a28f | Rafał Malinowski | return;
|
| 464 | dec9a28f | Rafał Malinowski | |
| 465 | dec9a28f | Rafał Malinowski | gg_dcc7 *dcc = gg_dcc7_send_file(Protocol->gaduSession(), details->uin(), |
| 466 | ea3566bd | Rafał Malinowski | qPrintable(handler->transfer().localFileName()), unicode2cp(handler->transfer().localFileName()).data(), 0);
|
| 467 | 18636b4a | Wojciech Treter | |
| 468 | 18636b4a | Wojciech Treter | if (dcc)
|
| 469 | 18636b4a | Wojciech Treter | {
|
| 470 | 18636b4a | Wojciech Treter | DccSocketNotifiers *fileTransferNotifiers = new DccSocketNotifiers(Protocol, this); |
| 471 | ea3566bd | Rafał Malinowski | handler->setFileTransferNotifiers(fileTransferNotifiers); |
| 472 | ea3566bd | Rafał Malinowski | handler->transfer().setTransferStatus(StatusWaitingForAccept); |
| 473 | 18636b4a | Wojciech Treter | fileTransferNotifiers->watchFor(dcc); |
| 474 | 18636b4a | Wojciech Treter | |
| 475 | 18636b4a | Wojciech Treter | SocketNotifiers << fileTransferNotifiers; |
| 476 | 18636b4a | Wojciech Treter | } |
| 477 | 18636b4a | Wojciech Treter | else
|
| 478 | ea3566bd | Rafał Malinowski | handler->socketNotAvailable(); |
| 479 | 18636b4a | Wojciech Treter | } |
| 480 | 18636b4a | Wojciech Treter | |
| 481 | ea3566bd | Rafał Malinowski | void DccManager::attachSendFileTransferSocket(GaduFileTransferHandler *handler)
|
| 482 | 18636b4a | Wojciech Treter | {
|
| 483 | ea3566bd | Rafał Malinowski | Contact contact = handler->transfer().fileTransferContact(); |
| 484 | dec9a28f | Rafał Malinowski | if (contact.isNull())
|
| 485 | dec9a28f | Rafał Malinowski | return;
|
| 486 | dec9a28f | Rafał Malinowski | |
| 487 | 9469ed1a | Bartlomiej Zimon | GaduContactDetails *details = Protocol->gaduContactDetails(contact); |
| 488 | dec9a28f | Rafał Malinowski | if (!details)
|
| 489 | 18636b4a | Wojciech Treter | return;
|
| 490 | 18636b4a | Wojciech Treter | |
| 491 | 946ac1c4 | Rafał Malinowski | GaduAccountDetails *account = dynamic_cast<GaduAccountDetails *>(Protocol->account().details());
|
| 492 | 18636b4a | Wojciech Treter | if (!account)
|
| 493 | 18636b4a | Wojciech Treter | return;
|
| 494 | 18636b4a | Wojciech Treter | |
| 495 | dec9a28f | Rafał Malinowski | DccVersion version = (details->gaduProtocolVersion() & 0x0000ffff) >= 0x29 |
| 496 | 18636b4a | Wojciech Treter | ? Dcc7 |
| 497 | 18636b4a | Wojciech Treter | : Dcc6; |
| 498 | 18636b4a | Wojciech Treter | |
| 499 | 18636b4a | Wojciech Treter | switch (version)
|
| 500 | 18636b4a | Wojciech Treter | {
|
| 501 | 18636b4a | Wojciech Treter | case Dcc6:
|
| 502 | ea3566bd | Rafał Malinowski | attachSendFileTransferSocket6(account->uin(), contact, handler); |
| 503 | 18636b4a | Wojciech Treter | break;
|
| 504 | 18636b4a | Wojciech Treter | |
| 505 | 18636b4a | Wojciech Treter | case Dcc7:
|
| 506 | ea3566bd | Rafał Malinowski | attachSendFileTransferSocket7(account->uin(), contact, handler); |
| 507 | 18636b4a | Wojciech Treter | break;
|
| 508 | 18636b4a | Wojciech Treter | } |
| 509 | 18636b4a | Wojciech Treter | } |
| 510 | 18636b4a | Wojciech Treter | |
| 511 | 18636b4a | Wojciech Treter | /*void DccManager::getVoiceSocket(uint32_t ip, uint16_t port, UinType myUin, UinType peerUin, DccHandler *handler, bool request)
|
| 512 | 18636b4a | Wojciech Treter | {
|
| 513 | 18636b4a | Wojciech Treter | kdebugf(); |
| 514 | 18636b4a | Wojciech Treter | |
| 515 | 18636b4a | Wojciech Treter | if ((port >= 10) && !request) |
| 516 | 18636b4a | Wojciech Treter | {
|
| 517 | 18636b4a | Wojciech Treter | |
| 518 | 18636b4a | Wojciech Treter | struct gg_dcc *sock = gg_dcc_voice_chat(htonl(ip), port, myUin, peerUin); |
| 519 | 18636b4a | Wojciech Treter | |
| 520 | 18636b4a | Wojciech Treter | if (sock) |
| 521 | 18636b4a | Wojciech Treter | {
|
| 522 | 18636b4a | Wojciech Treter | DccSocket *result = new DccSocket(this, sock); |
| 523 | 18636b4a | Wojciech Treter | result->setHandler(handler); |
| 524 | 18636b4a | Wojciech Treter | return; |
| 525 | 18636b4a | Wojciech Treter | } |
| 526 | 18636b4a | Wojciech Treter | } |
| 527 | 18636b4a | Wojciech Treter | |
| 528 | 18636b4a | Wojciech Treter | startTimeout(); |
| 529 | 18636b4a | Wojciech Treter | requests.insert(peerUin, handler); |
| 530 | 18636b4a | Wojciech Treter | Protocol->dccRequest(peerUin); |
| 531 | 18636b4a | Wojciech Treter | |
| 532 | 18636b4a | Wojciech Treter | kdebugf2(); |
| 533 | 18636b4a | Wojciech Treter | }*/ |