|
|
@ -95,6 +95,7 @@ void HttpConnection::read() |
|
|
|
qWarning() << Q_FUNC_INFO << "header parsing error"; |
|
|
|
qWarning() << Q_FUNC_INFO << "header parsing error"; |
|
|
|
m_receivedData.clear(); |
|
|
|
m_receivedData.clear(); |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -107,6 +108,7 @@ void HttpConnection::read() |
|
|
|
if (expected_length > 10000000 /* ~10MB */) { |
|
|
|
if (expected_length > 10000000 /* ~10MB */) { |
|
|
|
qWarning() << "Bad request: message too long"; |
|
|
|
qWarning() << "Bad request: message too long"; |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
m_receivedData.clear(); |
|
|
|
m_receivedData.clear(); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -127,6 +129,7 @@ void HttpConnection::read() |
|
|
|
if (m_parser.isError()) { |
|
|
|
if (m_parser.isError()) { |
|
|
|
qWarning() << Q_FUNC_INFO << "message parsing error"; |
|
|
|
qWarning() << Q_FUNC_INFO << "message parsing error"; |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
respond(); |
|
|
|
respond(); |
|
|
@ -188,6 +191,7 @@ void HttpConnection::respond() { |
|
|
|
if (nb_fail >= MAX_AUTH_FAILED_ATTEMPTS) { |
|
|
|
if (nb_fail >= MAX_AUTH_FAILED_ATTEMPTS) { |
|
|
|
m_generator.setStatusLine(403, "Forbidden"); |
|
|
|
m_generator.setStatusLine(403, "Forbidden"); |
|
|
|
m_generator.setMessage(tr("Your IP address has been banned after too many failed authentication attempts.")); |
|
|
|
m_generator.setMessage(tr("Your IP address has been banned after too many failed authentication attempts.")); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -197,6 +201,7 @@ void HttpConnection::respond() { |
|
|
|
qDebug("Auth is Empty..."); |
|
|
|
qDebug("Auth is Empty..."); |
|
|
|
m_generator.setStatusLine(401, "Unauthorized"); |
|
|
|
m_generator.setStatusLine(401, "Unauthorized"); |
|
|
|
m_generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+m_httpserver->generateNonce()+"\", opaque=\""+m_httpserver->generateNonce()+"\", stale=\"false\", algorithm=\"MD5\", qop=\"auth\""); |
|
|
|
m_generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+m_httpserver->generateNonce()+"\", opaque=\""+m_httpserver->generateNonce()+"\", stale=\"false\", algorithm=\"MD5\", qop=\"auth\""); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -209,6 +214,7 @@ void HttpConnection::respond() { |
|
|
|
// Return unauthorized header
|
|
|
|
// Return unauthorized header
|
|
|
|
m_generator.setStatusLine(401, "Unauthorized"); |
|
|
|
m_generator.setStatusLine(401, "Unauthorized"); |
|
|
|
m_generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+m_httpserver->generateNonce()+"\", opaque=\""+m_httpserver->generateNonce()+"\", stale=\"false\", algorithm=\"MD5\", qop=\"auth\""); |
|
|
|
m_generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+m_httpserver->generateNonce()+"\", opaque=\""+m_httpserver->generateNonce()+"\", stale=\"false\", algorithm=\"MD5\", qop=\"auth\""); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -226,6 +232,7 @@ void HttpConnection::respond() { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("png"); |
|
|
|
m_generator.setContentTypeByExt("png"); |
|
|
|
m_generator.setMessage(data); |
|
|
|
m_generator.setMessage(data); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
respondNotFound(); |
|
|
|
respondNotFound(); |
|
|
@ -284,6 +291,7 @@ void HttpConnection::respond() { |
|
|
|
// need to reply to the Web UI before
|
|
|
|
// need to reply to the Web UI before
|
|
|
|
// actually shutting down.
|
|
|
|
// actually shutting down.
|
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
qApp->processEvents(); |
|
|
|
qApp->processEvents(); |
|
|
|
// Exit application
|
|
|
|
// Exit application
|
|
|
@ -291,6 +299,7 @@ void HttpConnection::respond() { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
respondCommand(command); |
|
|
|
respondCommand(command); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
@ -343,11 +352,13 @@ void HttpConnection::respond() { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt(ext); |
|
|
|
m_generator.setContentTypeByExt(ext); |
|
|
|
m_generator.setMessage(data); |
|
|
|
m_generator.setMessage(data); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::respondNotFound() { |
|
|
|
void HttpConnection::respondNotFound() { |
|
|
|
m_generator.setStatusLine(404, "File not found"); |
|
|
|
m_generator.setStatusLine(404, "File not found"); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -355,6 +366,7 @@ void HttpConnection::respondTorrentsJson() { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setMessage(btjson::getTorrents()); |
|
|
|
m_generator.setMessage(btjson::getTorrents()); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -362,6 +374,7 @@ void HttpConnection::respondGenPropertiesJson(const QString& hash) { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setMessage(btjson::getPropertiesForTorrent(hash)); |
|
|
|
m_generator.setMessage(btjson::getPropertiesForTorrent(hash)); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -369,6 +382,7 @@ void HttpConnection::respondTrackersPropertiesJson(const QString& hash) { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setMessage(btjson::getTrackersForTorrent(hash)); |
|
|
|
m_generator.setMessage(btjson::getTrackersForTorrent(hash)); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -376,6 +390,7 @@ void HttpConnection::respondFilesPropertiesJson(const QString& hash) { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setMessage(btjson::getFilesForTorrent(hash)); |
|
|
|
m_generator.setMessage(btjson::getFilesForTorrent(hash)); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -383,6 +398,7 @@ void HttpConnection::respondPreferencesJson() { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setMessage(prefjson::getPreferences()); |
|
|
|
m_generator.setMessage(prefjson::getPreferences()); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -390,6 +406,7 @@ void HttpConnection::respondGlobalTransferInfoJson() { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setContentTypeByExt("js"); |
|
|
|
m_generator.setMessage(btjson::getTransferInfo()); |
|
|
|
m_generator.setMessage(btjson::getTransferInfo()); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -458,6 +475,7 @@ void HttpConnection::respondCommand(const QString& command) { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("html"); |
|
|
|
m_generator.setContentTypeByExt("html"); |
|
|
|
m_generator.setMessage(QString("<script type=\"text/javascript\">window.parent.hideAll();</script>")); |
|
|
|
m_generator.setMessage(QString("<script type=\"text/javascript\">window.parent.hideAll();</script>")); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -495,6 +513,7 @@ void HttpConnection::respondCommand(const QString& command) { |
|
|
|
#else |
|
|
|
#else |
|
|
|
m_generator.setMessage(QByteArray::number(QBtSession::instance()->getSession()->upload_rate_limit())); |
|
|
|
m_generator.setMessage(QByteArray::number(QBtSession::instance()->getSession()->upload_rate_limit())); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -506,6 +525,7 @@ void HttpConnection::respondCommand(const QString& command) { |
|
|
|
#else |
|
|
|
#else |
|
|
|
m_generator.setMessage(QByteArray::number(QBtSession::instance()->getSession()->download_rate_limit())); |
|
|
|
m_generator.setMessage(QByteArray::number(QBtSession::instance()->getSession()->download_rate_limit())); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -516,6 +536,7 @@ void HttpConnection::respondCommand(const QString& command) { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("html"); |
|
|
|
m_generator.setContentTypeByExt("html"); |
|
|
|
m_generator.setMessage(QByteArray::number(h.upload_limit())); |
|
|
|
m_generator.setMessage(QByteArray::number(h.upload_limit())); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
@ -527,6 +548,7 @@ void HttpConnection::respondCommand(const QString& command) { |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setContentTypeByExt("html"); |
|
|
|
m_generator.setContentTypeByExt("html"); |
|
|
|
m_generator.setMessage(QByteArray::number(h.download_limit())); |
|
|
|
m_generator.setMessage(QByteArray::number(h.download_limit())); |
|
|
|
|
|
|
|
m_generator.setContentEncoding(m_parser.acceptsEncoding()); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|