Exemplo n.º 1
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.º 2
0
void KviHttpRequest::slotSocketConnected()
{
	if(m_p->pConnectTimeoutTimer)
	{
		delete m_p->pConnectTimeoutTimer;
		m_p->pConnectTimeoutTimer = NULL;
	}

	emit connectionEstabilished();
	emit status(
			__tr2qs("Connected to %1:%2: sending request")
					.arg(m_p->pSocket->peerAddress().toString())
					.arg(m_p->pSocket->peerPort())
		);

	KviCString szMethod;

	bool bIsPost = false;

	if(m_eProcessingType == HeadersOnly)
		szMethod = "HEAD";
	else if(m_szPostData.isEmpty())
		szMethod = "GET";
	else {
		szMethod = "POST";
		bIsPost = true;
	}

	KviCString szRequest(
			KviCString::Format,
			"%s %s HTTP/1.1\r\n" \
			"Host: %s\r\n" \
			"Connection: Close\r\n" \
			"User-Agent: KVIrc-http-slave/1.0.0\r\n" \
			"Accept: */*\r\n",
			szMethod.ptr(),
			m_connectionUrl.path().toUtf8().data(),
			m_connectionUrl.host().toUtf8().data()
		);

	if(m_uContentOffset > 0)
		szRequest.append(KviCString::Format,"Range: bytes=%u-\r\n",m_uContentOffset);

	if(bIsPost)
	{
		szRequest.append(KviCString::Format,"Content-Type: application/x-www-form-urlencoded\r\n" \
				"Content-Length: %u\r\n" \
				"Cache-control: no-cache\r\n" \
				"Pragma: no-cache\r\n",m_szPostData.length());
	}

	szRequest += "\r\n";

	if(bIsPost)
	{
		if(!m_szPostData.isEmpty())
			szRequest.append(m_szPostData);
		szRequest += "\r\n";
	}

	// FIXME: Handle this better!
	int written = m_p->pSocket->write(szRequest.ptr(),szRequest.len());
	if(written < szRequest.len())
	{
		m_szLastError = __tr2qs("Socket write error");
		resetInternalStatus();
		emit terminated(false);
	}

	// FIXME: Handle this better
	QString req = QString::fromLatin1(szRequest.ptr());
	QStringList sl = req.split("\r\n");
	emit requestSent(sl);

	// now wait for the response

	// FIXME: Handle read timeouts!
}