Beispiel #1
0
void DccVoiceWindow::updateInfo()
{
    if(m_pSlaveThread)
    {
        m_pSlaveThread->m_pInfoMutex->lock();
        int iOSize = m_pSlaveThread->m_iOutputBufferSize;
        int iISize = m_pSlaveThread->m_iInputBufferSize;
        m_pSlaveThread->m_pInfoMutex->unlock();
        KviCString tmp(KviCString::Format,__tr_ctx("Input buffer: %d bytes","dcc"),iISize);
        m_pInputLabel->setText(tmp.ptr());
        tmp.sprintf(__tr_ctx("Output buffer: %d bytes","dcc"),iOSize);
        m_pOutputLabel->setText(tmp.ptr());
    }
}
Beispiel #2
0
static void dcc_fill_local_nick_user_host(DccDescriptor * d, KviDccRequest * dcc)
{
	if(dcc->pConsole->connection())
	{
		d->szLocalNick = dcc->pConsole->connection()->userInfo()->nickName();
		d->szLocalUser = dcc->pConsole->connection()->userInfo()->userName();
		d->szLocalHost = dcc->pConsole->connection()->userInfo()->hostName();
	}
	else
	{
		d->szLocalNick = __tr_ctx("unknown", "dcc");
		d->szLocalUser = __tr2qs_ctx("unknown", "dcc");
		d->szLocalHost = __tr2qs_ctx("unknown", "dcc");
	}
}
Beispiel #3
0
static void dccModuleParseDccGet(KviDccRequest * dcc)
{
	// DCC [TS]GET <filename> [filesize]
	// -> DCC [TS]SEND <filename> <ipaddr> <port> <filesize>
	// ...
	dcc->szParam1 = dcc->pConsole->decodeText(dcc->szParam1);
	bool bOk;
	unsigned int uSize = dcc->szParam2.toUInt(&bOk);
	if(!bOk)
		uSize = 0;

	if(!dcc_module_check_limits(dcc))
		return;
	if(!dcc_module_check_concurrent_transfers_limit(dcc))
		return;

	KviCString szExtensions = dcc->szType;
	szExtensions.cutRight(3); // cut off GET

	bool bTurboExtension = szExtensions.contains('T', false);
#ifdef COMPILE_SSL_SUPPORT
	bool bSSLExtension = szExtensions.contains('S', false);
#else  //!COMPILE_SSL_SUPPORT
	if(szExtensions.contains('S', false))
	{
		dcc_module_request_error(dcc, __tr2qs_ctx("This executable has been compiled without SSL support, the SSL extension to DCC GET is not available", "dcc"));
		return;
	}
#endif //!COMPILE_SSL_SUPPORT

	KviSharedFile * o = g_pSharedFilesManager->lookupSharedFile(dcc->szParam1.ptr(), dcc->ctcpMsg->pSource, uSize);
	if(!o)
	{
		if(!dcc->ctcpMsg->msg->haltOutput())
		{
			QString szError = QString(__tr2qs_ctx("No file offer named '%1' (with size %2) available for %3 [%4@%5]", "dcc")).arg(dcc->szParam1.ptr()).arg(uSize > 0 ? dcc->szParam2.ptr() : __tr_ctx("\"any\"", "dcc")).arg(dcc->ctcpMsg->pSource->nick(), dcc->ctcpMsg->pSource->user(), dcc->ctcpMsg->pSource->host());
			dcc_module_request_error(dcc, szError);
		}
		return;
	}

	//#warning "IF NOT IGNORE DCC GET!"
	//#warning "CREATE IT MINIMIZED ETC..."
	//#warning "MAYBE USE A DIALOG TO ACCEPT THE REQUEST ?"
	//#warning "DO NOT ACCEPT /etc/* requests..."

	if(KVI_OPTION_BOOL(KviOption_boolCantAcceptIncomingDccConnections))
	{
		// we have to use DCC RSEND, otherwise it will not work
		KviCString szSubproto("RSEND");
		szSubproto.prepend(szExtensions);

		QString szFileName = QFileInfo(o->absFilePath()).fileName();
		if(o->name() != szFileName)
		{
			// BUG
			//   If the file offer was added with a name that is senseless (like "mediaXYZ" for an *.mp3 file)
			//   then we would be going to RSEND that name here: the remote user woulnd't be
			//   able to recognize the file.
			//   Here we add another temporary offer with the right filename.

			// now add a file offer, so he we will accept it automatically
			// 120 secs is a reasonable timeout
			QString szMask;
			dcc->ctcpMsg->pSource->mask(szMask, KviIrcMask::NickUserHost);

			KviSharedFile * pOld = o;
			o = g_pSharedFilesManager->addSharedFile(szFileName, o->absFilePath(), szMask, 120);
			if(!o)
				o = pOld; // give up (FIXME: should we notify that ?)
		}

		if(!dcc->ctcpMsg->msg->haltOutput())
		{
			dcc->ctcpMsg->msg->console()->output(KVI_OUT_DCCMSG,
			    __tr2qs_ctx("Accepting file request from %Q [%Q@%Q] for '%s' (real file: %Q), offering DCC %s since we can't accept incoming connections (user option)", "dcc"),
			    &(dcc->ctcpMsg->pSource->nick()),
			    &(dcc->ctcpMsg->pSource->user()),
			    &(dcc->ctcpMsg->pSource->host()), dcc->szParam1.ptr(),
			    &(o->absFilePath()), szSubproto.ptr());
		}

		dcc->pConsole->connection()->sendFmtData("PRIVMSG %s :%cDCC %s %s %s%c",
		    dcc->pConsole->connection()->encodeText(dcc->ctcpMsg->pSource->nick()).data(),
		    0x01, szSubproto.ptr(),
		    dcc->pConsole->connection()->encodeText(dcc->szParam1.ptr()).data(),
		    dcc->pConsole->connection()->encodeText(QString::number(o->fileSize())).data(),
		    0x01);
		return;
	}

	DccDescriptor * d = new DccDescriptor(dcc->pConsole);
	d->szNick = dcc->ctcpMsg->pSource->nick();
	d->szLocalFileName = o->absFilePath();
	d->szUser = dcc->ctcpMsg->pSource->user();
	d->szHost = dcc->ctcpMsg->pSource->host();
	d->bRecvFile = false;
	dcc_fill_local_nick_user_host(d, dcc);

	QString tmp;
	if(!dcc_kvs_get_listen_ip_address(nullptr, d->console(), tmp))
	{
		d->console()->output(KVI_OUT_DCCMSG,
		    __tr2qs_ctx("No suitable interface to listen on, trying to continue anyway...", "dcc"));
		d->szListenIp = "0.0.0.0";
	}
	else
		d->szListenIp = QString(tmp);
	//#warning "DO STH WITH THIS PORT (HOW TO SPECIFY IT ?)"
	d->szListenPort = "0"; // any port is ok

	if(KVI_OPTION_BOOL(KviOption_boolDccSendFakeAddressByDefault))
	{
		d->szFakeIp = KVI_OPTION_STRING(KviOption_stringDefaultDccFakeAddress);
		if(d->szFakeIp.isEmpty())
			KVI_OPTION_BOOL(KviOption_boolDccSendFakeAddressByDefault) = false;
	}

	d->bDoTimeout = true;
	d->szIp = __tr2qs_ctx("(unknown)", "dcc");
	d->szPort = d->szIp;
	d->bActive = false;
	d->bSendRequest = true;
	d->bIsTdcc = bTurboExtension;
#ifdef COMPILE_SSL_SUPPORT
	d->bIsSSL = bSSLExtension;
#endif
	d->bNoAcks = d->bIsTdcc;
	d->bOverrideMinimize = false;

	dcc_module_set_dcc_type(d, "SEND");

	if(!dcc->ctcpMsg->msg->haltOutput())
	{
		dcc->ctcpMsg->msg->console()->output(KVI_OUT_DCCMSG,
		    __tr2qs_ctx("Accepting file request from %Q [%Q@%Q] for '%s' (real file: %Q), offering DCC %Q", "dcc"),
		    &(dcc->ctcpMsg->pSource->nick()),
		    &(dcc->ctcpMsg->pSource->user()),
		    &(dcc->ctcpMsg->pSource->host()),
		    dcc->szParam1.ptr(),
		    &(o->absFilePath()), &(d->szType));
	}
	d->triggerCreationEvent();
	g_pDccBroker->sendFileExecute(nullptr, d);
}
Beispiel #4
0
static void dccModuleParseDccRSend(KviDccRequest * dcc)
{
	// DCC RSEND <filename> <filesize>
	//#warning "Ignore files depending on file type ? (MediaType ?)"
	//
	// We have received a DCC RSEND request in the following form
	//
	//      DCC [ST]RSEND <filename> <filesize>
	//
	dcc->szParam1 = dcc->pConsole->decodeText(dcc->szParam1);
	if(!dcc_module_check_limits(dcc))
		return;
	if(!dcc_module_check_concurrent_transfers_limit(dcc))
		return;

	if(!(dcc->szParam2.isUnsignedNum()))
	{
		if(!dcc->ctcpMsg->msg->haltOutput())
		{
			dcc->ctcpMsg->msg->console()->output(KVI_OUT_DCCMSG,
			    __tr2qs_ctx("The above request is broken: the fourth parameter should be the file size but doesn't appear to be an unsigned number; trying to continue", "dcc"), dcc->szParam2.ptr());
		}
		dcc->szParam2 = __tr_ctx("<unknown size>", "dcc");
	}

	if(dcc->szParam1.contains('/'))
	{
		if(!dcc->ctcpMsg->msg->haltOutput())
		{
			dcc->ctcpMsg->msg->console()->output(KVI_OUT_DCCMSG,
			    __tr2qs_ctx("The above request is broken: the filename contains path components, stripping the leading path and trying to continue", "dcc"), dcc->szParam1.ptr());
		}
		dcc->szParam1.cutToLast('/');
	}

	KviCString szExtensions = dcc->szType;
	szExtensions.cutRight(4); // cut off SEND

	bool bTurboExtension = szExtensions.contains('T', false);
#ifdef COMPILE_SSL_SUPPORT
	bool bSSLExtension = szExtensions.contains('S', false);
#else  //!COMPILE_SSL_SUPPORT
	if(szExtensions.contains('S', false))
	{
		dcc_module_request_error(dcc, __tr2qs_ctx("This executable has been compiled without SSL support, the SSL extension to DCC RSEND is not available", "dcc"));
		return;
	}
#endif //!COMPILE_SSL_SUPPORT

	//#warning "When behind a firewall, we should reply an error message and avoid setting up the listening connection"

	DccDescriptor * d = new DccDescriptor(dcc->pConsole);
	d->szNick = dcc->ctcpMsg->pSource->nick();
	d->szUser = dcc->ctcpMsg->pSource->user();
	d->szHost = dcc->ctcpMsg->pSource->host();
	d->szIp = __tr2qs_ctx("(unknown)", "dcc");
	d->szPort = d->szIp;
	QString tmp;
	if(!dcc_kvs_get_listen_ip_address(nullptr, d->console(), tmp))
	{
		d->console()->output(KVI_OUT_DCCMSG,
		    __tr2qs_ctx("No suitable interface to listen on, trying to continue anyway...", "dcc"));
		d->szListenIp = "0.0.0.0";
	}
	else
		d->szListenIp = QString(tmp);

	d->szListenPort = "0";
	dcc_fill_local_nick_user_host(d, dcc);

	d->szFileName = dcc->szParam1.ptr();
	d->szFileSize = dcc->szParam2.ptr();
	d->bActive = false; // we have to listen!
	d->bResume = false;
	d->bRecvFile = true; // we have to receive the file!

#ifdef COMPILE_SSL_SUPPORT
	d->bIsSSL = bSSLExtension;
#endif
	d->bIsTdcc = bTurboExtension;
	d->bSendRequest = true; // we have to send the [ST]RECV request back
	d->bNoAcks = d->bIsTdcc;
	d->bOverrideMinimize = false;
	d->bAutoAccept = KVI_OPTION_BOOL(KviOption_boolAutoAcceptDccSend);
	d->bIsIncomingAvatar = g_pApp->findPendingAvatarChange(dcc->pConsole, d->szNick.toUtf8().data(), d->szFileName.toUtf8().data());

	if(KVI_OPTION_BOOL(KviOption_boolDccSendFakeAddressByDefault))
	{
		d->szFakeIp = KVI_OPTION_STRING(KviOption_stringDefaultDccFakeAddress);
		if(d->szFakeIp.isEmpty())
			KVI_OPTION_BOOL(KviOption_boolDccSendFakeAddressByDefault) = false;
	}

	if(KVI_OPTION_BOOL(KviOption_boolAutoAcceptIncomingAvatars))
		d->bAutoAccept = d->bAutoAccept || d->bIsIncomingAvatar;

	dcc_module_set_dcc_type(d, "RECV");
	d->triggerCreationEvent();
	g_pDccBroker->recvFileManage(d);
}