Branched v2.2.x

This commit is contained in:
Christophe Dumez
2010-03-14 20:44:17 +00:00
parent 9034094cf9
commit b10e606dda
92 changed files with 11223 additions and 12340 deletions

View File

@@ -47,7 +47,7 @@
#include <QTemporaryFile>
HttpConnection::HttpConnection(QTcpSocket *socket, Bittorrent *BTSession, HttpServer *parent)
: QObject(parent), socket(socket), parent(parent), BTSession(BTSession)
: QObject(parent), socket(socket), parent(parent), BTSession(BTSession)
{
socket->setParent(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(read()));
@@ -117,7 +117,7 @@ QString HttpConnection::translateDocument(QString data) {
QString translation = word;
int context_index= 0;
do {
translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().data(), 0, QCoreApplication::UnicodeUTF8, 1);
translation = qApp->translate(contexts[context_index].c_str(), word.toLocal8Bit().constData(), 0, QCoreApplication::UnicodeUTF8, 1);
++context_index;
}while(translation == word && context_index < 12);
//qDebug("Translation is %s", translation.toUtf8().data());
@@ -131,19 +131,20 @@ QString HttpConnection::translateDocument(QString data) {
void HttpConnection::respond() {
//qDebug("Respond called");
int nb_fail = parent->client_failed_attempts.value(socket->peerAddress().toString(), 0);
if(nb_fail > 4) {
const QString &peer_ip = socket->peerAddress().toString();
const int nb_fail = parent->NbFailedAttemptsForIp(peer_ip);
if(nb_fail >= MAX_AUTH_FAILED_ATTEMPTS) {
generator.setStatusLine(403, "Forbidden");
generator.setMessage(tr("Your IP address has been banned after too many failed authentication attempts."));
write();
return;
}
QString auth = parser.value("Authorization");
qDebug("Auth: %s", auth.split(" ").first().toLocal8Bit().data());
qDebug("Auth: %s", qPrintable(auth.split(" ").first()));
if (QString::compare(auth.split(" ").first(), "Digest", Qt::CaseInsensitive) != 0 || !parent->isAuthorized(auth.toLocal8Bit(), parser.method())) {
// Update failed attempt counter
parent->client_failed_attempts.insert(socket->peerAddress().toString(), nb_fail+1);
qDebug("client IP: %s (%d failed attempts)", socket->peerAddress().toString().toLocal8Bit().data(), nb_fail);
parent->increaseNbFailedAttemptsForIp(peer_ip);
qDebug("client IP: %s (%d failed attempts)", qPrintable(peer_ip), nb_fail+1);
// Return unauthorized header
generator.setStatusLine(401, "Unauthorized");
generator.setValue("WWW-Authenticate", "Digest realm=\""+QString(QBT_REALM)+"\", nonce=\""+parent->generateNonce()+"\", algorithm=\"MD5\", qop=\"auth\"");
@@ -151,7 +152,7 @@ void HttpConnection::respond() {
return;
}
// Client sucessfuly authenticated, reset number of failed attempts
parent->client_failed_attempts.remove(socket->peerAddress().toString());
parent->resetNbFailedAttemptsForIp(peer_ip);
QString url = parser.url();
// Favicon
if(url.endsWith("favicon.ico")) {
@@ -225,7 +226,6 @@ void HttpConnection::respond() {
else
list.prepend("webui");
url = ":/" + list.join("/");
//qDebug("Resource URL: %s", url.toLocal8Bit().data());
QFile file(url);
if(!file.open(QIODevice::ReadOnly))
{
@@ -261,7 +261,6 @@ void HttpConnection::respondJson()
QString string = json::toJson(manager->getEventList());
generator.setStatusLine(200, "OK");
generator.setContentTypeByExt("js");
//qDebug("JSON: %s", string.toLocal8Bit().data());
generator.setMessage(string);
write();
}
@@ -290,7 +289,6 @@ void HttpConnection::respondFilesPropertiesJson(QString hash) {
generator.setStatusLine(200, "OK");
generator.setContentTypeByExt("js");
generator.setMessage(string);
//qDebug("JSON: %s", string.toLocal8Bit().data());
write();
}
@@ -391,7 +389,6 @@ void HttpConnection::respondCommand(QString command)
}
if(command == "setPreferences") {
QString json_str = parser.post("json");
//qDebug("setPreferences, json: %s", json_str.toLocal8Bit().data());
EventManager* manager = parent->eventManager();
manager->setGlobalPreferences(json::fromJson(json_str));
}