|
|
@ -55,24 +55,24 @@ KviHttpRequest::KviHttpRequest()
|
|
|
|
m_bHeaderProcessed = false;
|
|
|
|
m_bHeaderProcessed = false;
|
|
|
|
m_pBuffer = new KviDataBuffer();
|
|
|
|
m_pBuffer = new KviDataBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
resettqStatus();
|
|
|
|
resetStatus();
|
|
|
|
resetData();
|
|
|
|
resetData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KviHttpRequest::~KviHttpRequest()
|
|
|
|
KviHttpRequest::~KviHttpRequest()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
delete m_pBuffer;
|
|
|
|
delete m_pBuffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KviHttpRequest::abort()
|
|
|
|
void KviHttpRequest::abort()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Aborted");
|
|
|
|
m_szLastError = __tr2qs("Aborted");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KviHttpRequest::resetInternaltqStatus()
|
|
|
|
void KviHttpRequest::resetInternalStatus()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(m_pThread)delete m_pThread;
|
|
|
|
if(m_pThread)delete m_pThread;
|
|
|
|
if(m_pDns)delete m_pDns;
|
|
|
|
if(m_pDns)delete m_pDns;
|
|
|
@ -91,7 +91,7 @@ void KviHttpRequest::resetInternaltqStatus()
|
|
|
|
KviThreadManager::killPendingEvents(this);
|
|
|
|
KviThreadManager::killPendingEvents(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KviHttpRequest::resettqStatus()
|
|
|
|
void KviHttpRequest::resetStatus()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_szLastError = __tr2qs("No request");
|
|
|
|
m_szLastError = __tr2qs("No request");
|
|
|
|
m_uTotalSize = 0;
|
|
|
|
m_uTotalSize = 0;
|
|
|
@ -114,9 +114,9 @@ void KviHttpRequest::resetData()
|
|
|
|
|
|
|
|
|
|
|
|
void KviHttpRequest::reset()
|
|
|
|
void KviHttpRequest::reset()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resettqStatus();
|
|
|
|
resetStatus();
|
|
|
|
resetData();
|
|
|
|
resetData();
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KviHttpRequest::get(const KviUrl &u,ProcessingType p,const TQString &szFileName)
|
|
|
|
bool KviHttpRequest::get(const KviUrl &u,ProcessingType p,const TQString &szFileName)
|
|
|
@ -131,8 +131,8 @@ bool KviHttpRequest::get(const KviUrl &u,ProcessingType p,const TQString &szFile
|
|
|
|
bool KviHttpRequest::start()
|
|
|
|
bool KviHttpRequest::start()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// ensure that the file is closed
|
|
|
|
// ensure that the file is closed
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
resettqStatus();
|
|
|
|
resetStatus();
|
|
|
|
|
|
|
|
|
|
|
|
if(m_eProcessingType == StoreToFile)
|
|
|
|
if(m_eProcessingType == StoreToFile)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -156,14 +156,14 @@ bool KviHttpRequest::start()
|
|
|
|
|
|
|
|
|
|
|
|
if(m_url.host().isEmpty())
|
|
|
|
if(m_url.host().isEmpty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Invalid URL: Missing hostname");
|
|
|
|
m_szLastError = __tr2qs("Invalid URL: Missing hostname");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if((!kvi_strEqualCI(m_url.protocol().ptr(),"http")) && (!kvi_strEqualCI(m_url.protocol().ptr(),"https")))
|
|
|
|
if((!kvi_strEqualCI(m_url.protocol().ptr(),"http")) && (!kvi_strEqualCI(m_url.protocol().ptr(),"https")))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError=__tr2qs("Unsupported protocol %1").tqarg(m_url.protocol().ptr());
|
|
|
|
m_szLastError=__tr2qs("Unsupported protocol %1").tqarg(m_url.protocol().ptr());
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -185,7 +185,7 @@ bool KviHttpRequest::startDnsLookup()
|
|
|
|
|
|
|
|
|
|
|
|
if(!m_pDns->lookup(m_url.host().ptr(),KviDns::IpV4))
|
|
|
|
if(!m_pDns->lookup(m_url.host().ptr(),KviDns::IpV4))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Unable to start the DNS lookup");
|
|
|
|
m_szLastError = __tr2qs("Unable to start the DNS lookup");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -212,7 +212,7 @@ void KviHttpRequest::dnsLookupDone(KviDns *d)
|
|
|
|
haveServerIp();
|
|
|
|
haveServerIp();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
int iErr = d->error();
|
|
|
|
int iErr = d->error();
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = KviError::getDescription(iErr);
|
|
|
|
m_szLastError = KviError::getDescription(iErr);
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -242,7 +242,7 @@ void KviHttpRequest::haveServerIp()
|
|
|
|
|
|
|
|
|
|
|
|
if(!m_pThread->start())
|
|
|
|
if(!m_pThread->start())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Unable to start the request slave thread");
|
|
|
|
m_szLastError = __tr2qs("Unable to start the request slave thread");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -318,7 +318,7 @@ bool KviHttpRequest::event(TQEvent *e)
|
|
|
|
// nothing... just make gcc happy
|
|
|
|
// nothing... just make gcc happy
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Success");
|
|
|
|
m_szLastError = __tr2qs("Success");
|
|
|
|
emit terminated(true);
|
|
|
|
emit terminated(true);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -328,7 +328,7 @@ bool KviHttpRequest::event(TQEvent *e)
|
|
|
|
KviStr * err = ((KviThreadDataEvent<KviStr> *)e)->getData();
|
|
|
|
KviStr * err = ((KviThreadDataEvent<KviStr> *)e)->getData();
|
|
|
|
m_szLastError = __tr2qs_no_xgettext(err->ptr());
|
|
|
|
m_szLastError = __tr2qs_no_xgettext(err->ptr());
|
|
|
|
delete err;
|
|
|
|
delete err;
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -425,7 +425,7 @@ bool KviHttpRequest::openFile()
|
|
|
|
if(!d.rename(m_szFileName,tmp))
|
|
|
|
if(!d.rename(m_szFileName,tmp))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// fail :(
|
|
|
|
// fail :(
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Failed to rename the existing file, please rename manually and retry");
|
|
|
|
m_szLastError = __tr2qs("Failed to rename the existing file, please rename manually and retry");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -443,7 +443,7 @@ bool KviHttpRequest::openFile()
|
|
|
|
|
|
|
|
|
|
|
|
if(!m_pFile->openForWriting(bAppend))
|
|
|
|
if(!m_pFile->openForWriting(bAppend))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
KviTQString::sprintf(m_szLastError,__tr2qs("Can't open file \"%Q\" for writing"),&m_szFileName);
|
|
|
|
KviTQString::sprintf(m_szLastError,__tr2qs("Can't open file \"%Q\" for writing"),&m_szFileName);
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -473,7 +473,7 @@ bool KviHttpRequest::processHeader(KviStr &szHeader)
|
|
|
|
|
|
|
|
|
|
|
|
bool bValid = false;
|
|
|
|
bool bValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int utqStatus = 0;
|
|
|
|
unsigned int uStatus = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// check the response value
|
|
|
|
// check the response value
|
|
|
|
if(kvi_strEqualCSN(szResponse.ptr(),"HTTP",4))
|
|
|
|
if(kvi_strEqualCSN(szResponse.ptr(),"HTTP",4))
|
|
|
@ -486,14 +486,14 @@ bool KviHttpRequest::processHeader(KviStr &szHeader)
|
|
|
|
if(idx != -1)szNumber = szR.left(idx);
|
|
|
|
if(idx != -1)szNumber = szR.left(idx);
|
|
|
|
else szNumber = szR;
|
|
|
|
else szNumber = szR;
|
|
|
|
bool bOk;
|
|
|
|
bool bOk;
|
|
|
|
utqStatus = szNumber.toUInt(&bOk);
|
|
|
|
uStatus = szNumber.toUInt(&bOk);
|
|
|
|
if(bOk)bValid = true;
|
|
|
|
if(bOk)bValid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!bValid)
|
|
|
|
if(!bValid)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// the response is invalid ?
|
|
|
|
// the response is invalid ?
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError=__tr2qs("Invalid HTTP response: %s").tqarg(szResponse.ptr());
|
|
|
|
m_szLastError=__tr2qs("Invalid HTTP response: %s").tqarg(szResponse.ptr());
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -608,14 +608,14 @@ bool KviHttpRequest::processHeader(KviStr &szHeader)
|
|
|
|
// case 504: // Gateway timeout
|
|
|
|
// case 504: // Gateway timeout
|
|
|
|
// case 505: // HTTP Version not supported
|
|
|
|
// case 505: // HTTP Version not supported
|
|
|
|
|
|
|
|
|
|
|
|
if((utqStatus != 200) && (utqStatus != 206))
|
|
|
|
if((uStatus != 200) && (uStatus != 206))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// this is not "OK" and not "Partial content"
|
|
|
|
// this is not "OK" and not "Partial content"
|
|
|
|
// Error , redirect or something confusing
|
|
|
|
// Error , redirect or something confusing
|
|
|
|
if(m_eProcessingType != HeadersOnly)
|
|
|
|
if(m_eProcessingType != HeadersOnly)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// this is an error then
|
|
|
|
// this is an error then
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = szResponse.ptr();
|
|
|
|
m_szLastError = szResponse.ptr();
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -624,7 +624,7 @@ bool KviHttpRequest::processHeader(KviStr &szHeader)
|
|
|
|
|
|
|
|
|
|
|
|
if((m_uMaxContentLength > 0) && (m_uTotalSize > ((unsigned int)m_uMaxContentLength)))
|
|
|
|
if((m_uMaxContentLength > 0) && (m_uTotalSize > ((unsigned int)m_uMaxContentLength)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError=__tr2qs("Stream exceeding maximum length");
|
|
|
|
m_szLastError=__tr2qs("Stream exceeding maximum length");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -657,7 +657,7 @@ void KviHttpRequest::processData(KviDataBuffer * data)
|
|
|
|
// header not complete
|
|
|
|
// header not complete
|
|
|
|
if(m_pBuffer->size() > 4096)
|
|
|
|
if(m_pBuffer->size() > 4096)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Header too long: exceeded 4096 bytes");
|
|
|
|
m_szLastError = __tr2qs("Header too long: exceeded 4096 bytes");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -706,7 +706,7 @@ void KviHttpRequest::processData(KviDataBuffer * data)
|
|
|
|
|
|
|
|
|
|
|
|
if(((m_uTotalSize > 0) && (m_uReceivedSize > m_uTotalSize)) || ((m_uMaxContentLength > 0) && (m_uReceivedSize > m_uMaxContentLength)))
|
|
|
|
if(((m_uTotalSize > 0) && (m_uReceivedSize > m_uTotalSize)) || ((m_uMaxContentLength > 0) && (m_uReceivedSize > m_uMaxContentLength)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError=__tr2qs("Stream exceeded expected length");
|
|
|
|
m_szLastError=__tr2qs("Stream exceeded expected length");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -794,7 +794,7 @@ void KviHttpRequest::processData(KviDataBuffer * data)
|
|
|
|
m_uRemainingChunkSize = szHexHeader.toLong(&bOk,16);
|
|
|
|
m_uRemainingChunkSize = szHexHeader.toLong(&bOk,16);
|
|
|
|
if(!bOk)
|
|
|
|
if(!bOk)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Protocol error: invalid chunk size");
|
|
|
|
m_szLastError = __tr2qs("Protocol error: invalid chunk size");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -814,7 +814,7 @@ void KviHttpRequest::processData(KviDataBuffer * data)
|
|
|
|
// chunk header not complete
|
|
|
|
// chunk header not complete
|
|
|
|
if(m_pBuffer->size() > 4096)
|
|
|
|
if(m_pBuffer->size() > 4096)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError = __tr2qs("Chunk header too long: exceeded 4096 bytes");
|
|
|
|
m_szLastError = __tr2qs("Chunk header too long: exceeded 4096 bytes");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -848,7 +848,7 @@ check_stream_length:
|
|
|
|
|
|
|
|
|
|
|
|
if(((m_uTotalSize > 0) && (m_uReceivedSize > m_uTotalSize)) || ((m_uMaxContentLength > 0) && (m_uReceivedSize > m_uMaxContentLength)))
|
|
|
|
if(((m_uTotalSize > 0) && (m_uReceivedSize > m_uTotalSize)) || ((m_uMaxContentLength > 0) && (m_uReceivedSize > m_uMaxContentLength)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
resetInternaltqStatus();
|
|
|
|
resetInternalStatus();
|
|
|
|
m_szLastError=__tr2qs("Stream exceeded expected length");
|
|
|
|
m_szLastError=__tr2qs("Stream exceeded expected length");
|
|
|
|
emit terminated(false);
|
|
|
|
emit terminated(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|