|
|
@ -80,7 +80,7 @@ void HttpConnection::handleDownloadFailure(const QString& url, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::read() { |
|
|
|
void HttpConnection::read() { |
|
|
|
QByteArray input = m_socket->readAll(); |
|
|
|
const QByteArray input = m_socket->readAll(); |
|
|
|
if(input.size() > 100000) { |
|
|
|
if(input.size() > 100000) { |
|
|
|
qDebug("Request too big"); |
|
|
|
qDebug("Request too big"); |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
@ -88,24 +88,17 @@ void HttpConnection::read() { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
m_parser.write(input); |
|
|
|
m_parser.write(input); |
|
|
|
if(m_parser.isError()) |
|
|
|
if(m_parser.isError()) { |
|
|
|
{ |
|
|
|
|
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
m_generator.setStatusLine(400, "Bad Request"); |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
else |
|
|
|
|
|
|
|
if (m_parser.isParsable()) |
|
|
|
if (m_parser.isParsable()) |
|
|
|
respond(); |
|
|
|
respond(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::write() |
|
|
|
void HttpConnection::write() { |
|
|
|
{ |
|
|
|
m_socket->write(m_generator.toByteArray()); |
|
|
|
QByteArray output = m_generator.toByteArray(); |
|
|
|
|
|
|
|
/*qDebug(" --------");
|
|
|
|
|
|
|
|
qDebug("|RESPONSE|"); |
|
|
|
|
|
|
|
qDebug(" --------"); |
|
|
|
|
|
|
|
qDebug()<<output;*/ |
|
|
|
|
|
|
|
m_socket->write(output); |
|
|
|
|
|
|
|
m_socket->disconnectFromHost(); |
|
|
|
m_socket->disconnectFromHost(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -118,7 +111,7 @@ void HttpConnection::translateDocument(QString& data) { |
|
|
|
"options_imp", "Preferences", "TrackersAdditionDlg", |
|
|
|
"options_imp", "Preferences", "TrackersAdditionDlg", |
|
|
|
"ScanFoldersModel", "PropTabBar", "TorrentModel", |
|
|
|
"ScanFoldersModel", "PropTabBar", "TorrentModel", |
|
|
|
"downloadFromURL"}; |
|
|
|
"downloadFromURL"}; |
|
|
|
int i=0; |
|
|
|
int i = 0; |
|
|
|
bool found; |
|
|
|
bool found; |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
@ -149,8 +142,9 @@ void HttpConnection::translateDocument(QString& data) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::respond() { |
|
|
|
void HttpConnection::respond() { |
|
|
|
if((m_socket->peerAddress() != QHostAddress::LocalHost && m_socket->peerAddress() != QHostAddress::LocalHostIPv6) |
|
|
|
if((m_socket->peerAddress() != QHostAddress::LocalHost |
|
|
|
|| m_httpserver->isLocalAuthEnabled()) { |
|
|
|
&& m_socket->peerAddress() != QHostAddress::LocalHostIPv6) |
|
|
|
|
|
|
|
|| m_httpserver->isLocalAuthEnabled()) { |
|
|
|
// Authentication
|
|
|
|
// Authentication
|
|
|
|
const QString peer_ip = m_socket->peerAddress().toString(); |
|
|
|
const QString peer_ip = m_socket->peerAddress().toString(); |
|
|
|
const int nb_fail = m_httpserver->NbFailedAttemptsForIp(peer_ip); |
|
|
|
const int nb_fail = m_httpserver->NbFailedAttemptsForIp(peer_ip); |
|
|
@ -199,36 +193,35 @@ void HttpConnection::respond() { |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QStringList list = url.split('/', QString::SkipEmptyParts); |
|
|
|
QStringList list = url.split('/', QString::SkipEmptyParts); |
|
|
|
if (list.contains(".") || list.contains("..")) |
|
|
|
if (list.contains(".") || list.contains("..")) { |
|
|
|
{ |
|
|
|
|
|
|
|
respondNotFound(); |
|
|
|
respondNotFound(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (list.size() == 0) |
|
|
|
|
|
|
|
|
|
|
|
if (list.isEmpty()) |
|
|
|
list.append("index.html"); |
|
|
|
list.append("index.html"); |
|
|
|
if (list.size() >= 2) |
|
|
|
|
|
|
|
{ |
|
|
|
if (list.size() >= 2) { |
|
|
|
if (list[0] == "json") |
|
|
|
if (list[0] == "json") { |
|
|
|
{ |
|
|
|
if (list[1] == "events") { |
|
|
|
if (list[1] == "events") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
respondJson(); |
|
|
|
respondJson(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if(list.size() > 2) { |
|
|
|
if(list.size() > 2) { |
|
|
|
if(list[1] == "propertiesGeneral") { |
|
|
|
if(list[1] == "propertiesGeneral") { |
|
|
|
QString hash = list[2]; |
|
|
|
const QString& hash = list[2]; |
|
|
|
respondGenPropertiesJson(hash); |
|
|
|
respondGenPropertiesJson(hash); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if(list[1] == "propertiesTrackers") { |
|
|
|
if(list[1] == "propertiesTrackers") { |
|
|
|
QString hash = list[2]; |
|
|
|
const QString& hash = list[2]; |
|
|
|
respondTrackersPropertiesJson(hash); |
|
|
|
respondTrackersPropertiesJson(hash); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if(list[1] == "propertiesFiles") { |
|
|
|
if(list[1] == "propertiesFiles") { |
|
|
|
QString hash = list[2]; |
|
|
|
const QString& hash = list[2]; |
|
|
|
respondFilesPropertiesJson(hash); |
|
|
|
respondFilesPropertiesJson(hash); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -244,8 +237,7 @@ void HttpConnection::respond() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (list[0] == "command") |
|
|
|
if (list[0] == "command") { |
|
|
|
{ |
|
|
|
|
|
|
|
QString command = list[1]; |
|
|
|
QString command = list[1]; |
|
|
|
respondCommand(command); |
|
|
|
respondCommand(command); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
@ -253,6 +245,7 @@ void HttpConnection::respond() { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Icons from theme
|
|
|
|
// Icons from theme
|
|
|
|
qDebug() << "list[0]" << list[0]; |
|
|
|
qDebug() << "list[0]" << list[0]; |
|
|
|
if(list[0] == "theme" && list.size() == 2) { |
|
|
|
if(list[0] == "theme" && list.size() == 2) { |
|
|
@ -318,7 +311,7 @@ void HttpConnection::respondJson() |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::respondGenPropertiesJson(QString hash) { |
|
|
|
void HttpConnection::respondGenPropertiesJson(const QString& hash) { |
|
|
|
EventManager* manager = m_httpserver->eventManager(); |
|
|
|
EventManager* manager = m_httpserver->eventManager(); |
|
|
|
QString string = json::toJson(manager->getPropGeneralInfo(hash)); |
|
|
|
QString string = json::toJson(manager->getPropGeneralInfo(hash)); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
@ -327,7 +320,7 @@ void HttpConnection::respondGenPropertiesJson(QString hash) { |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::respondTrackersPropertiesJson(QString hash) { |
|
|
|
void HttpConnection::respondTrackersPropertiesJson(const QString& hash) { |
|
|
|
EventManager* manager = m_httpserver->eventManager(); |
|
|
|
EventManager* manager = m_httpserver->eventManager(); |
|
|
|
QString string = json::toJson(manager->getPropTrackersInfo(hash)); |
|
|
|
QString string = json::toJson(manager->getPropTrackersInfo(hash)); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
@ -336,7 +329,7 @@ void HttpConnection::respondTrackersPropertiesJson(QString hash) { |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::respondFilesPropertiesJson(QString hash) { |
|
|
|
void HttpConnection::respondFilesPropertiesJson(const QString& hash) { |
|
|
|
EventManager* manager = m_httpserver->eventManager(); |
|
|
|
EventManager* manager = m_httpserver->eventManager(); |
|
|
|
QString string = json::toJson(manager->getPropFilesInfo(hash)); |
|
|
|
QString string = json::toJson(manager->getPropFilesInfo(hash)); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
|
m_generator.setStatusLine(200, "OK"); |
|
|
@ -366,7 +359,7 @@ void HttpConnection::respondGlobalTransferInfoJson() { |
|
|
|
write(); |
|
|
|
write(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::respondCommand(QString command) |
|
|
|
void HttpConnection::respondCommand(const QString& command) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(command == "download") |
|
|
|
if(command == "download") |
|
|
|
{ |
|
|
|
{ |
|
|
@ -574,7 +567,7 @@ void HttpConnection::respondCommand(QString command) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void HttpConnection::recheckTorrent(QString hash) { |
|
|
|
void HttpConnection::recheckTorrent(const QString& hash) { |
|
|
|
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); |
|
|
|
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); |
|
|
|
if(h.is_valid()){ |
|
|
|
if(h.is_valid()){ |
|
|
|
QBtSession::instance()->recheckTorrent(h.hash()); |
|
|
|
QBtSession::instance()->recheckTorrent(h.hash()); |
|
|
|