Exemplo n.º 1
0
KviCachedPixmap::KviCachedPixmap(QPixmap * pPix, const QString & szPath)
{
	m_szPath = szPath;
	m_tLastAccess = kvi_unixTime();
	m_pPixmap = pPix;
	m_uSize = m_pPixmap->width() * m_pPixmap->height() * (m_pPixmap->depth() / 8);
}
Exemplo n.º 2
0
void KviAvatarCache::load(const QString &szFileName)
{
	m_pAvatarDict->clear();

	KviConfigurationFile cfg(szFileName,KviConfigurationFile::Read);

	kvi_time_t tNow = kvi_unixTime();

	KviConfigurationFileIterator it(*(cfg.dict()));

	int cnt = 0;

	while(it.current())
	{
		cfg.setGroup(it.currentKey());

		kvi_time_t tLastAccess = cfg.readUIntEntry("LastAccess",0);
		if((tNow - tLastAccess) < MAX_UNACCESSED_TIME)
		{
			QString szIdString = cfg.readEntry("Avatar","");

			if(!szIdString.isEmpty())
			{
				KviAvatarCacheEntry * e = new KviAvatarCacheEntry;
				e->tLastAccess = tLastAccess;
				e->szIdString = szIdString;
				m_pAvatarDict->replace(it.currentKey(),e);
				cnt++;
				if(cnt >= MAX_AVATARS_IN_CACHE)return; // done
			}
		}
		++it;
	}
}
Exemplo n.º 3
0
HttpFileTransfer::HttpFileTransfer()
: KviFileTransfer()
{
	init(); // ensure we're initialized
	g_pHttpFileTransfers->append(this);

	m_tStartTime = kvi_unixTime();
	m_tTransferStartTime = 0;
	m_tTransferEndTime = 0;

	m_bNotifyCompletion = true;
	m_bAutoClean = false;
	m_pAutoCleanTimer = 0;
	m_bNoOutput = false;

	m_pHttpRequest = new KviHttpRequest();

	connect(m_pHttpRequest,SIGNAL(status(const QString &)),this,SLOT(statusMessage(const QString &)));
	connect(m_pHttpRequest,SIGNAL(terminated(bool)),this,SLOT(transferTerminated(bool)));
	connect(m_pHttpRequest,SIGNAL(header(KviPointerHashTable<const char *,KviCString> *)),this,SLOT(headersReceived(KviPointerHashTable<const char *,KviCString> *)));
	connect(m_pHttpRequest,SIGNAL(resolvingHost(const QString &)),this,SLOT(resolvingHost(const QString &)));
	connect(m_pHttpRequest,SIGNAL(requestSent(const QStringList &)),this,SLOT(requestSent(const QStringList &)));
	connect(m_pHttpRequest,SIGNAL(contactingHost(const QString &)),this,SLOT(contactingHost(const QString &)));
	connect(m_pHttpRequest,SIGNAL(receivedResponse(const QString &)),this,SLOT(receivedResponse(const QString &)));
	connect(m_pHttpRequest,SIGNAL(connectionEstabilished()),this,SLOT(connectionEstabilished()));

	m_eGeneralStatus = Initializing;
	m_szStatusString = __tr2qs_ctx("Initializing","http");
}
Exemplo n.º 4
0
void HttpFileTransfer::transferTerminated(bool bSuccess)
{
	KviWindow * out = transferWindow();

	m_tTransferEndTime = kvi_unixTime();

	KviKvsVariantList vParams;
	vParams.append(bSuccess);
	vParams.append(new KviKvsVariant(m_pHttpRequest->url().url(), true));
	vParams.append(new KviKvsVariant(m_pHttpRequest->fileName(), true));
	vParams.append(new KviKvsVariant(m_vMagicIdentifier));

	if(m_szCompletionCallback.isNull())
	{
		KVS_TRIGGER_EVENT(KviEvent_OnHTTPGetTerminated,out ? out : (KviWindow *)(g_pApp->activeConsole()),&vParams)
	} else {
		KviKvsScript::run(m_szCompletionCallback,out ? out : (KviWindow *)(g_pApp->activeConsole()),&vParams);
	}

	if(bSuccess)
	{
		m_szStatusString = __tr2qs_ctx("Transfer completed","http");
		m_eGeneralStatus = Success;
		displayUpdate();
		if(out && (!m_bNoOutput))out->output(KVI_OUT_GENERICSUCCESS,__tr2qs_ctx("[HTTP %d]: Transfer completed","http"),id());
		g_pApp->fileDownloadTerminated(
				true,
				m_pHttpRequest->url().url(),
				m_pHttpRequest->fileName(),
				QString(),
				QString(),
				!m_bNotifyCompletion
			);
	} else {
		m_szStatusString = __tr2qs_ctx("Transfer failed","http");
		m_szStatusString += ": ";
		m_szStatusString += m_pHttpRequest->lastError();
		m_eGeneralStatus = Failure;
		displayUpdate();
		if(out && (!m_bNoOutput))out->output(KVI_OUT_GENERICERROR,__tr2qs_ctx("[HTTP %d]: Transfer failed: %Q","http"),id(),&(m_pHttpRequest->lastError()));
		g_pApp->fileDownloadTerminated(
				false,
				m_pHttpRequest->url().url(),
				m_pHttpRequest->fileName(),
				QString(),
				m_pHttpRequest->lastError(),
				!m_bNotifyCompletion
			);
	}

	if(m_bAutoClean)
	{
		if(m_pAutoCleanTimer)delete m_pAutoCleanTimer;
		m_pAutoCleanTimer = new QTimer();
		connect(m_pAutoCleanTimer,SIGNAL(timeout()),this,SLOT(autoClean()));
		m_pAutoCleanTimer->start(100);
		m_TimerId=m_pAutoCleanTimer->timerId();
	}
}
Exemplo n.º 5
0
void HttpFileTransfer::receivedResponse(const QString &response)
{
	m_lHeaders.clear();
	m_lHeaders.append(response);
	m_szStatusString = __tr2qs_ctx("Transferring data (%1)","http").arg(response);
	m_tTransferStartTime = kvi_unixTime();
	m_eGeneralStatus = Downloading;
	displayUpdate();
}
Exemplo n.º 6
0
	int fillRandomIV(unsigned char * pIn, int iLen)
	{
		if(!bDidInit)
		{
			srand((int)kvi_unixTime());
			bDidInit = true;
		}

		for(int i=0;i<iLen;i++)
			pIn[i] = (unsigned char)(rand() % 256);

		return iLen;
	}
Exemplo n.º 7
0
const QString & KviAvatarCache::lookup(const KviIrcMask &mask,const QString &szNetwork)
{
	QString szKey;

	mask.mask(szKey,KviIrcMask::NickCleanUserSmartNet);
	szKey.append(QChar('+'));
	szKey.append(szNetwork);

	KviAvatarCacheEntry * e = m_pAvatarDict->find(szKey);
	if(!e)return KviQString::Empty;
	e->tLastAccess = kvi_unixTime();
	return e->szIdString;
}
Exemplo n.º 8
0
void KviIrcContext::timerEvent(QTimerEvent * e)
{
	if(e->timerId() != m_iHeartbeatTimerId)
	{
		QObject::timerEvent(e);
		return;
	}

	// our heartbeat
	kvi_time_t tNow = kvi_unixTime();

	if(m_pConnection)
		m_pConnection->heartbeat(tNow);
}
KviIrcConnectionStateData::KviIrcConnectionStateData()
{
	m_bSentStartTls = false;
	m_bSentQuit = false;
	m_bInsideInitialCapLs = false;
	m_bInsideInitialCapReq = false;
	m_bInsideInitialStartTls = false;
	m_bIgnoreOneYouHaveNotRegisteredError = false;
	m_eLoginNickNameState = UsedConnectionSpecificNickName;
	m_bSimulateUnexpectedDisconnect = false;
	m_tLastReceivedChannelWhoReply = kvi_unixTime();
	m_tLastSentChannelWhoRequest = m_tLastReceivedChannelWhoReply;
	m_tLastReceivedWhoisReply = 0;
	m_bIdentifyMsgCapabilityEnabled = false;
}
Exemplo n.º 10
0
void KviAvatarCache::replace(const QString &szIdString,const KviIrcMask &mask,const QString &szNetwork)
{
	QString szKey;

	mask.mask(szKey,KviIrcMask::NickCleanUserSmartNet);
	szKey.append(QChar('+'));
	szKey.append(szNetwork);

	KviAvatarCacheEntry * e = new KviAvatarCacheEntry;
	e->szIdString = szIdString;
	e->tLastAccess = kvi_unixTime();

	m_pAvatarDict->replace(szKey,e);

	if(m_pAvatarDict->count() > MAX_AVATARS_IN_CACHE)
	{
		cleanup();
	}
}
Exemplo n.º 11
0
void KviCachedPixmap::updateLastAccessTime()
{
	m_tLastAccess = kvi_unixTime();
}
Exemplo n.º 12
0
void HttpFileTransfer::displayPaint(QPainter * p,int column, QRect rect)
{
	int width = rect.width(), height = rect.height();
	QString txt;
	bool bIsTerminated = ((m_eGeneralStatus == Success) || (m_eGeneralStatus == Failure));

	switch(column)
	{
		case COLUMN_TRANSFERTYPE:
		{
			int offset = 0;
			switch(m_eGeneralStatus)
			{
				case Initializing:
				case Connecting: offset = 0; break;
				case Downloading: offset = 48; break;
				case Success: offset = 96; break;
				case Failure: offset = 144; break;
			}
			if(g_pHttpIcon)
				p->drawPixmap(width / 2 - 48 / 2,rect.top() + height / 2 - 64 / 2,*g_pHttpIcon,offset,0,48,64);
		}
		break;
		case COLUMN_FILEINFO:
		{
			QFontMetrics fm(p->font());

			QString szFrom = __tr2qs_ctx("From: ","http");
			QString szTo   = __tr2qs_ctx("To: ","http");

			int daW1 = fm.width(szFrom);
			int daW2 = fm.width(szTo);
			if(daW1 < daW2)daW1 = daW2;
			int iLineSpacing = fm.lineSpacing();

			p->setPen(Qt::black);

			int iY = rect.top() + 4;

			p->drawText(rect.left() + 4 + daW1,iY,width - (8 + daW1),height - 8,Qt::AlignTop | Qt::AlignLeft,m_pHttpRequest->url().url());
			iY += iLineSpacing;
			if(!(m_pHttpRequest->fileName().isEmpty()))
			{
				p->drawText(rect.left() + 4 + daW1,iY,width - (8 + daW1),height - 8,Qt::AlignTop | Qt::AlignLeft,m_pHttpRequest->fileName());
			}
			iY += iLineSpacing;


			p->setPen(Qt::darkGray);

			p->drawText(rect.left() + 4, rect.top() + 4,width - 8,height - 8,Qt::AlignTop | Qt::AlignLeft,szFrom);
			p->drawText(rect.left() + 4, rect.top() + 4 + iLineSpacing,width - 8,height - 8,Qt::AlignTop | Qt::AlignLeft,szTo);

			p->setPen(QColor(180,180,200));

			iLineSpacing += 2;

			p->drawRect(rect.left() + 4, rect.top() + height - (iLineSpacing + 4),width - 8,iLineSpacing);
			p->fillRect(rect.left() + 5, rect.top() + height - (iLineSpacing + 3),width - 10,iLineSpacing - 2,bIsTerminated ? QColor(210,210,210) : QColor(190,190,240));
			p->setPen(Qt::black);
			p->drawText(rect.left() + 7, rect.top() + height - (iLineSpacing + 4),width - 14,iLineSpacing,Qt::AlignVCenter | Qt::AlignLeft,m_szStatusString);
		}
		break;
		case COLUMN_PROGRESS:
		{
			QFontMetrics fm(p->font());

			unsigned int uTotal = m_pHttpRequest->totalSize();
			unsigned int uRecvd = m_pHttpRequest->receivedSize();
			int iW = width - 8;

			p->setPen(bIsTerminated ? Qt::lightGray : QColor(210,210,240));
			p->drawRect(rect.left() + 4, rect.top() + 4,iW,12);

			int iAvgSpeed = -1;
			int iEta = -1;

			if(m_tTransferStartTime > 0)
			{
				int tSpan = kvi_timeSpan(m_tTransferEndTime > 0 ? m_tTransferEndTime : kvi_unixTime(),m_tTransferStartTime);
				if(tSpan > 0)
				{
					//qDebug("SPAN: %d (%d - %d)",tSpan,m_tTransferEndTime > 0 ? m_tTransferEndTime : kvi_unixTime(),m_tTransferStartTime);
					iAvgSpeed = uRecvd / tSpan;
					if(!bIsTerminated && (uTotal >= uRecvd))
					{
						unsigned int uRemaining = uTotal - uRecvd;
						iEta = uRemaining / iAvgSpeed;
					}
				}
			}

			if(uTotal > 0)
			{
				double dPerc = (double)(((double)uRecvd) * 100.0) / (double)uTotal;
				iW -= 2;
				int iL = (int) ((((double)iW) * dPerc) / 100.0);
				//iR = iW - iL;
				p->fillRect(rect.left() + 5, rect.top() + 5,iL,10,bIsTerminated ? QColor(140,110,110) : QColor(200,100,100));

				txt = QString(__tr2qs_ctx("%1 of %2 (%3 %)","http")).arg(KviQString::makeSizeReadable(uRecvd),
					KviQString::makeSizeReadable(uTotal)).arg(dPerc,0,'f',2);
			} else {
				txt = KviQString::makeSizeReadable(m_pHttpRequest->receivedSize());
			}

			p->setPen(Qt::black);

			p->drawText(rect.left() + 4, rect.top() + 19,width - 8,height - 8,Qt::AlignTop | Qt::AlignLeft,txt);

			int iLeftHalf = (iW - 2) / 2;
			int iRightHalf = iW - (iLeftHalf + 1);
			int iLineSpacing = fm.lineSpacing() + 2;
			/*
			txt = __tr2qs_ctx("Spd:","dcc");
			txt += " ";
			if(iInstantSpeed >= 0)
			{
				QString tmpisp;
				KviNetUtils::formatNetworkBandwidthString(tmpisp,iAvgSpeed);
				txt += tmpisp;
			} else {
				txt += "? B/s";
			}
			*/
			txt = __tr2qs_ctx("Avg:","dcc");
			txt += " ";
			if(iAvgSpeed >= 0)
			{
				QString tmpspd;
				KviNetUtils::formatNetworkBandwidthString(tmpspd,iAvgSpeed);
				txt += tmpspd;
			} else {
				txt += "? B/s";
			}



			int iDaH = height - (iLineSpacing + 4);

			p->setPen(QColor(180,180,200));
			p->drawRect(rect.left() + 4, rect.top() + iDaH,iLeftHalf,iLineSpacing);
			p->fillRect(rect.left() + 5, rect.top() + iDaH + 1,iLeftHalf - 2,iLineSpacing - 2,bIsTerminated ? QColor(210,210,210) : QColor(190,190,240));
			p->setPen(bIsTerminated ? Qt::darkGray : Qt::black);
			p->drawText(rect.left() + 6, rect.top() + iDaH,iLeftHalf - 4,iLineSpacing,Qt::AlignLeft | Qt::AlignVCenter,txt);

			unsigned int uD,uH,uM,uS;

			if(bIsTerminated)
			{
				KviTimeUtils::secondsToDaysHoursMinsSecs(kvi_timeSpan(m_tTransferEndTime,m_tTransferStartTime),&uD,&uH,&uM,&uS);
				txt = "TOT: ";
				if(uD > 0)txt += __tr2qs_ctx("%1d %2h %3m %4s","http").arg(uD).arg(uH).arg(uM).arg(uS);
				else if(uH > 0)txt += __tr2qs_ctx("%1h %2m %3s","http").arg(uH).arg(uM).arg(uS);
				else txt += __tr2qs_ctx("%1m %2s","http").arg(uM).arg(uS);
			} else {
				if(iEta >= 0)
				{
					KviTimeUtils::secondsToDaysHoursMinsSecs(iEta,&uD,&uH,&uM,&uS);
					txt = "ETA: ";
					if(uD > 0)txt += __tr2qs_ctx("%1d %2h %3m %4s","http").arg(uD).arg(uH).arg(uM).arg(uS);
					else if(uH > 0)txt += __tr2qs_ctx("%1h %2m %3s","http").arg(uH).arg(uM).arg(uS);
					else txt += __tr2qs_ctx("%1m %2s","http").arg(uM).arg(uS);
				} else {
					txt = "ETA: Unknown";
				}
			}

			p->setPen(QColor(180,180,200));
			p->drawRect(rect.left() + width - (4 + iRightHalf), rect.top() + iDaH,iRightHalf,iLineSpacing);
			p->fillRect(rect.left() + width - (3 + iRightHalf), rect.top() + iDaH + 1,iRightHalf - 2,iLineSpacing - 2,bIsTerminated ? QColor(210,210,210) : QColor(190,190,240));
			p->setPen(bIsTerminated ? Qt::darkGray : Qt::black);
			p->drawText(rect.left() + width - (2 + iRightHalf), rect.top() + iDaH,iRightHalf - 4,iLineSpacing,Qt::AlignLeft | Qt::AlignVCenter,txt);

		}
		break;
	}
}
Exemplo n.º 13
0
void KviIrcConnectionUserInfo::setAway()
{
	m_szNickBeforeAway = m_szNickName;
	m_tAway = kvi_unixTime();
	m_bAway = true;
}
Exemplo n.º 14
0
void KviAvatarCache::cleanup()
{
	// first do a quick run deleting the avatars really too old
	KviPointerHashTableIterator<QString,KviAvatarCacheEntry> it(*m_pAvatarDict);

	kvi_time_t tNow = kvi_unixTime();

	KviPointerList<QString> l;
	l.setAutoDelete(false);

	KviAvatarCacheEntry * e;

	while((e = it.current()))
	{
		if((tNow - e->tLastAccess) > MAX_UNACCESSED_TIME)
		{
			l.append(new QString(it.currentKey()));
		}
		++it;
	}

	for(QString *s = l.first();s;s = l.next())m_pAvatarDict->remove(*s);

	if(m_pAvatarDict->count() < CACHE_GUARD_LEVEL)return;

	// not done.. need to kill the last accessed :/

	it.toFirst();

	KviPointerList<KviAvatarCacheEntry> ll;
	ll.setAutoDelete(true);

	// here we use the cache entries in another way
	// szAvatar is the KEY instead of the avatar name

	while((e = it.current()))
	{
		KviAvatarCacheEntry * current = ll.first();
		unsigned int idx = 0;
		while(current)
		{
			// if the current is newer than the inserted one
			// then stop searching and insert it just before
			if(current->tLastAccess > e->tLastAccess)break;
			// otherwise the current is older and the inserted
			// one goes after
			current = ll.next();
			idx++;
		}

		KviAvatarCacheEntry * xx = new KviAvatarCacheEntry;
		xx->szIdString = it.currentKey();
		xx->tLastAccess = e->tLastAccess;

		if(current)ll.insert(idx,xx);
		else ll.append(xx);
		++it;
	}

	// the oldest keys are at the beginning
	int uRemove = ll.count() - CACHE_GUARD_LEVEL;
	if(uRemove < 1)return; // huh ?

	// remember that szAvatar contains the key!
	for(e = ll.first();e && (uRemove > 0);e = ll.next())
	{
		m_pAvatarDict->remove(e->szIdString);
		uRemove--;
	}
	// now we should be ok
}
Exemplo n.º 15
0
void KviIrcConnectionRequestQueue::timerSlot()
{
	if(m_channels.isEmpty())
	{
		m_timer.stop();
	} else {
		KviChannelWindow * pChan = m_channels.head();
		QByteArray encodedChan = pChan->connection()->encodeText(pChan->target()).data();
		/* The following switch will let the execution flow pass-through if any request type
		 * is currently disabled (or not available on the server). Channel's "MODE" request is
		 * the only mandatory request.
		 */
		switch(m_curType)
		{
			case BanException:
				if(pChan->serverInfo()->supportedListModes().contains('e') &&
					!KVI_OPTION_BOOL(KviOption_boolDisableBanExceptionListRequestOnJoin) &&
					!(	pChan->serverInfo()->getNeedsOpToListModeseI() &&
						!pChan->isMeOp()
					 )
				)
				{
					if(!pChan->connection()->sendFmtData("MODE %s e",encodedChan.data()))
						clearAll(); // disconnected
					else pChan->setSentListRequest('e');
					m_curType = Invite;
					break;
				}
			case Invite:
				if(pChan->serverInfo()->supportedListModes().contains('I') &&
					!KVI_OPTION_BOOL(KviOption_boolDisableInviteListRequestOnJoin) &&
					!(	pChan->serverInfo()->getNeedsOpToListModeseI() &&
						!pChan->isMeOp()
					 )
				)
				{
					if(!pChan->connection()->sendFmtData("MODE %s I",encodedChan.data()))
						clearAll(); // disconnected
					else pChan->setSentListRequest('I');
					m_curType = QuietBan;
					break;
				}
			case QuietBan:
				if(pChan->serverInfo()->supportedListModes().contains('q') &&
					!KVI_OPTION_BOOL(KviOption_boolDisableQuietBanListRequestOnJoin))
				{
					if(!pChan->connection()->sendFmtData("MODE %s q",encodedChan.data()))
						clearAll(); // disconnected
					else pChan->setSentListRequest('q');
					m_curType = Who;
					break;
				}
			case Who:
				if(!KVI_OPTION_BOOL(KviOption_boolDisableWhoRequestOnJoin))
				{
					// TODO: cleanup
					pChan->connection()->stateData()->setLastSentChannelWhoRequest(kvi_unixTime());
					if(pChan->connection()->lagMeter())
					{
						KviCString tmp;
						if(pChan->serverInfo()->supportsWhox())
							tmp.sprintf("WHO %s %acdfhlnrsu",encodedChan.data());
						else
							tmp.sprintf("WHO %s",encodedChan.data());
						pChan->connection()->lagMeter()->lagCheckRegister(tmp.ptr(),60);
					}
					if(pChan->serverInfo()->supportsWhox())
					{
						if(!pChan->connection()->sendFmtData("WHO %s %acdfhlnrsu",encodedChan.data()))
							clearAll(); // disconnected
						else pChan->setSentWhoRequest();
					} else {
						if(!pChan->connection()->sendFmtData("WHO %s",encodedChan.data()))
							clearAll(); // disconnected
						else pChan->setSentWhoRequest();
					}
					m_curType = Ban;
					break;
				}
			case Ban:
				if(!KVI_OPTION_BOOL(KviOption_boolDisableBanListRequestOnJoin))
				{
					if(!pChan->connection()->sendFmtData("MODE %s b",encodedChan.data()))
					{
						clearAll(); // disconnected
					} else {
						pChan->setSentListRequest('b');
						m_channels.dequeue();
					}
					m_curType = Mode;
					break;
				}
			default:
				// we're at the end of the list
				m_channels.dequeue();
				pChan->checkChannelSync();
				m_curType = Mode;
				if(m_channels.isEmpty())
				{
					m_timer.stop();
					return;
				}
				pChan = m_channels.head();
				encodedChan = pChan->connection()->encodeText(pChan->target());
			case Mode:
				if(!pChan->connection()->sendFmtData("MODE %s",encodedChan.data()))
				{
					clearAll(); // disconnected
					break;
				}
				m_curType = BanException;
				break;
		}
	}
}