Fix compilation warnings in smtp.h (cgreco)

This commit is contained in:
Christophe Dumez
2011-06-05 16:08:30 +00:00
parent 53900c386b
commit 02fbd6a135
87 changed files with 11700 additions and 9106 deletions

View File

@@ -39,6 +39,10 @@
#include "torrentpersistentdata.h"
#include <QDebug>
#include <QTranslator>
#ifndef QT_NO_OPENSSL
#include <QSslCertificate>
#include <QSslKey>
#endif
using namespace libtorrent;
@@ -180,6 +184,14 @@ void EventManager::setGlobalPreferences(QVariantMap m) const {
pref.setMailNotificationEmail(m["mail_notification_email"].toString());
if(m.contains("mail_notification_smtp"))
pref.setMailNotificationSMTP(m["mail_notification_smtp"].toString());
if(m.contains("mail_notification_ssl_enabled"))
pref.setMailNotificationSMTPSSL(m["mail_notification_ssl_enabled"].toBool());
if(m.contains("mail_notification_auth_enabled"))
pref.setMailNotificationSMTPAuth(m["mail_notification_auth_enabled"].toBool());
if(m.contains("mail_notification_username"))
pref.setMailNotificationSMTPUsername(m["mail_notification_username"].toString());
if(m.contains("mail_notification_password"))
pref.setMailNotificationSMTPPassword(m["mail_notification_password"].toString());
if(m.contains("autorun_enabled"))
pref.setAutoRunEnabled(m["autorun_enabled"].toBool());
if(m.contains("autorun_program"))
@@ -213,6 +225,14 @@ void EventManager::setGlobalPreferences(QVariantMap m) const {
pref.setMaxConnecsPerTorrent(m["max_connec_per_torrent"].toInt());
if(m.contains("max_uploads_per_torrent"))
pref.setMaxUploadsPerTorrent(m["max_uploads_per_torrent"].toInt());
#if LIBTORRENT_VERSION_MINOR >= 16
if(m.contains("enable_utp"))
pref.setuTPEnabled(m["enable_utp"].toBool());
if(m.contains("limit_utp_rate"))
pref.setuTPRateLimited(m["limit_utp_rate"].toBool());
#endif
if(m.contains("limit_tcp_overhead"))
pref.includeOverheadInLimits(m["limit_tcp_overhead"].toBool());
// Bittorrent
if(m.contains("dht"))
pref.setDHTEnabled(m["dht"].toBool());
@@ -254,6 +274,33 @@ void EventManager::setGlobalPreferences(QVariantMap m) const {
pref.setWebUiUsername(m["web_ui_username"].toString());
if(m.contains("web_ui_password"))
pref.setWebUiPassword(m["web_ui_password"].toString());
if(m.contains("bypass_local_auth"))
pref.setWebUiLocalAuthEnabled(!m["bypass_local_auth"].toBool());
if(m.contains("use_https"))
pref.setWebUiHttpsEnabled(m["use_https"].toBool());
#ifndef QT_NO_OPENSSL
if(m.contains("ssl_key")) {
QByteArray raw_key = m["ssl_key"].toString().toAscii();
if (!QSslKey(raw_key, QSsl::Rsa).isNull())
pref.setWebUiHttpsKey(raw_key);
}
if(m.contains("ssl_cert")) {
QByteArray raw_cert = m["ssl_cert"].toString().toAscii();
if (!QSslCertificate(raw_cert).isNull())
pref.setWebUiHttpsCertificate(raw_cert);
}
#endif
// Dyndns
if(m.contains("dyndns_enabled"))
pref.setDynDNSEnabled(m["dyndns_enabled"].toBool());
if(m.contains("dyndns_service"))
pref.setDynDNSService(m["dyndns_service"].toInt());
if(m.contains("dyndns_username"))
pref.setDynDNSUsername(m["dyndns_username"].toString());
if(m.contains("dyndns_password"))
pref.setDynDNSPassword(m["dyndns_password"].toString());
if(m.contains("dyndns_domain"))
pref.setDynDomainName(m["dyndns_domain"].toString());
// Reload preferences
QBtSession::instance()->configureSession();
}
@@ -278,6 +325,10 @@ QVariantMap EventManager::getGlobalPreferences() const {
data["mail_notification_enabled"] = pref.isMailNotificationEnabled();
data["mail_notification_email"] = pref.getMailNotificationEmail();
data["mail_notification_smtp"] = pref.getMailNotificationSMTP();
data["mail_notification_ssl_enabled"] = pref.getMailNotificationSMTPSSL();
data["mail_notification_auth_enabled"] = pref.getMailNotificationSMTPAuth();
data["mail_notification_username"] = pref.getMailNotificationSMTPUsername();
data["mail_notification_password"] = pref.getMailNotificationSMTPPassword();
data["autorun_enabled"] = pref.isAutoRunEnabled();
data["autorun_program"] = pref.getAutoRunProgram();
data["preallocate_all"] = pref.preAllocateAllFiles();
@@ -296,6 +347,11 @@ QVariantMap EventManager::getGlobalPreferences() const {
data["max_connec"] = pref.getMaxConnecs();
data["max_connec_per_torrent"] = pref.getMaxConnecsPerTorrent();
data["max_uploads_per_torrent"] = pref.getMaxUploadsPerTorrent();
#if LIBTORRENT_VERSION_MINOR >= 16
data["enable_utp"] = pref.isuTPEnabled();
data["limit_utp_rate"] = pref.isuTPRateLimited();
#endif
data["limit_tcp_overhead"] = pref.includeOverheadInLimits();
// Bittorrent
data["dht"] = pref.isDHTEnabled();
data["dhtSameAsBT"] = pref.isDHTPortSameAsBT();
@@ -318,6 +374,16 @@ QVariantMap EventManager::getGlobalPreferences() const {
data["web_ui_port"] = pref.getWebUiPort();
data["web_ui_username"] = pref.getWebUiUsername();
data["web_ui_password"] = pref.getWebUiPassword();
data["bypass_local_auth"] = !pref.isWebUiLocalAuthEnabled();
data["use_https"] = pref.isWebUiHttpsEnabled();
data["ssl_key"] = QString::fromAscii(pref.getWebUiHttpsKey());
data["ssl_cert"] = QString::fromAscii(pref.getWebUiHttpsCertificate());
// DynDns
data["dyndns_enabled"] = pref.isDynDNSEnabled();
data["dyndns_service"] = pref.getDynDNSService();
data["dyndns_username"] = pref.getDynDNSUsername();
data["dyndns_password"] = pref.getDynDNSPassword();
data["dyndns_domain"] = pref.getDynDomainName();
return data;
}
@@ -421,7 +487,7 @@ void EventManager::modifiedTorrent(const QTorrentHandle& h)
event["state"] = QVariant("stalledDL");
event["eta"] = misc::userFriendlyDuration(QBtSession::instance()->getETA(hash));
break;
default:
default:
qDebug("No status, should not happen!!! status is %d", h.state());
event["state"] = QVariant();
}

View File

@@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>_(Download from URL)</title>
<title>_(Add &link to torrent...)</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script type="text/javascript" src="scripts/mootools-1.2-core-yc.js" charset="utf-8"></script>
<script type="text/javascript" src="scripts/download.js" charset="utf-8"></script>

View File

@@ -70,8 +70,8 @@
</div>
<div id="mochaToolbar">
&nbsp;&nbsp;
<a id="uploadButton"><img class="mochaToolButton" title="_(Download local torrent)" src="theme/list-add" width="24" height="24" onload="fixPNG(this)"/></a>
<a id="downloadButton"><img class="mochaToolButton" title="_(Download from URL)" src="theme/insert-link" width="24" height="24" onload="fixPNG(this)"/></a>
<a id="uploadButton"><img class="mochaToolButton" title="_(&Add torrent file...)" src="theme/list-add" width="24" height="24" onload="fixPNG(this)"/></a>
<a id="downloadButton"><img class="mochaToolButton" title="_(Add &link to torrent...)" src="theme/insert-link" width="24" height="24" onload="fixPNG(this)"/></a>
<a id="deleteButton" class="divider"><img class="mochaToolButton" title="_(Delete)" src="theme/list-remove" width="24" height="24" onload="fixPNG(this)"/></a>
<a id="resumeButton" class="divider"><img class="mochaToolButton" title="_(Resume)" src="theme/media-playback-start" width="24" height="24" onload="fixPNG(this)"/></a>
<a id="pauseButton"><img class="mochaToolButton" title="_(Pause)" src="theme/media-playback-pause" width="24" height="24" onload="fixPNG(this)"/></a>

File diff suppressed because it is too large Load Diff

View File

@@ -116,7 +116,7 @@ QString HttpConnection::translateDocument(QString data) {
bool found = false;
do {
found = false;
QRegExp regex(QString::fromUtf8("_\\(([\\w\\s?!:\\/\\(\\),%µ&\\-\\.]+)\\)"));
static QRegExp regex(QString::fromUtf8("_\\(([\\w\\s?!:\\/\\(\\),%µ&\\-\\.]+)\\)"));
i = regex.indexIn(data, i);
if(i >= 0) {
//qDebug("Found translatable string: %s", regex.cap(1).toUtf8().data());
@@ -128,7 +128,8 @@ QString HttpConnection::translateDocument(QString data) {
++context_index;
}while(translation == word && context_index < 15);
// Remove keyboard shortcuts
translation = translation.replace("&", "");
static QRegExp mnemonic("\\(?&([a-zA-Z]?\\))?");
translation = translation.replace(mnemonic, "");
//qDebug("Translation is %s", translation.toUtf8().data());
data = data.replace(i, regex.matchedLength(), translation);
i += translation.length();

View File

@@ -38,14 +38,19 @@
#include <QTime>
#include <QRegExp>
#include <QTimer>
#ifndef QT_NO_OPENSSL
#include <QSslSocket>
#else
#include <QTcpSocket>
#endif
using namespace libtorrent;
const int BAN_TIME = 3600000; // 1 hour
class UnbanTimer: public QTimer {
public:
public:
UnbanTimer(QObject *parent, QString peer_ip): QTimer(parent), peer_ip(peer_ip){
setSingleShot(true);
setInterval(BAN_TIME);
@@ -88,12 +93,13 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent) {
username = pref.getWebUiUsername().toLocal8Bit();
password_ha1 = pref.getWebUiPassword().toLocal8Bit();
m_localAuth = pref.isWebUiLocalAuthEnabled();
#ifndef QT_NO_OPENSSL
m_https = pref.isWebUiHttpsEnabled();
if (m_https) {
m_certificate = pref.getWebUiHttpsCertificate();
m_key = pref.getWebUiHttpsKey();
m_certificate = QSslCertificate(pref.getWebUiHttpsCertificate());
m_key = QSslKey(pref.getWebUiHttpsKey(), QSsl::Rsa);
}
connect(this, SIGNAL(newConnection()), this, SLOT(newHttpConnection()));
#endif
manager = new EventManager(this);
//add torrents
std::vector<torrent_handle> torrents = QBtSession::instance()->getTorrents();
@@ -147,52 +153,58 @@ HttpServer::~HttpServer()
delete manager;
}
#ifndef QT_NO_OPENSSL
void HttpServer::enableHttps(const QSslCertificate &certificate, const QSslKey &key)
{
m_certificate = certificate;
m_key = key;
m_https = true;
}
void HttpServer::disableHttps()
{
m_https = false;
m_certificate.clear();
m_key.clear();
}
#endif
void HttpServer::incomingConnection(int socketDescriptor)
{
QTcpSocket *serverSocket;
QSslSocket *serverSslSocket;
#ifndef QT_NO_OPENSSL
if (m_https)
{
serverSslSocket = new QSslSocket;
serverSocket = serverSslSocket;
}
serverSocket = new QSslSocket(this);
else
{
serverSocket = new QTcpSocket;
}
if (serverSocket->setSocketDescriptor(socketDescriptor))
{
if (m_https)
{
serverSslSocket->setProtocol(QSsl::AnyProtocol);
serverSslSocket->setPrivateKey(m_key);
serverSslSocket->setLocalCertificate(m_certificate);
serverSslSocket->startServerEncryption();
#endif
serverSocket = new QTcpSocket(this);
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
#ifndef QT_NO_OPENSSL
if (m_https) {
static_cast<QSslSocket*>(serverSocket)->setProtocol(QSsl::AnyProtocol);
static_cast<QSslSocket*>(serverSocket)->setPrivateKey(m_key);
static_cast<QSslSocket*>(serverSocket)->setLocalCertificate(m_certificate);
static_cast<QSslSocket*>(serverSocket)->startServerEncryption();
}
addPendingConnection(serverSocket);
}
else
{
delete serverSocket;
#endif
handleNewConnection(serverSocket);
} else {
serverSocket->deleteLater();
}
}
void HttpServer::newHttpConnection()
void HttpServer::handleNewConnection(QTcpSocket *socket)
{
QTcpSocket *socket;
while((socket = nextPendingConnection()))
{
HttpConnection *connection = new HttpConnection(socket, this);
//connect connection to QBtSession::instance()
connect(connection, SIGNAL(UrlReadyToBeDownloaded(QString)), QBtSession::instance(), SLOT(downloadUrlAndSkipDialog(QString)));
connect(connection, SIGNAL(MagnetReadyToBeDownloaded(QString)), QBtSession::instance(), SLOT(addMagnetSkipAddDlg(QString)));
connect(connection, SIGNAL(torrentReadyToBeDownloaded(QString, bool, QString, bool)), QBtSession::instance(), SLOT(addTorrent(QString, bool, QString, bool)));
connect(connection, SIGNAL(deleteTorrent(QString, bool)), QBtSession::instance(), SLOT(deleteTorrent(QString, bool)));
connect(connection, SIGNAL(pauseTorrent(QString)), QBtSession::instance(), SLOT(pauseTorrent(QString)));
connect(connection, SIGNAL(resumeTorrent(QString)), QBtSession::instance(), SLOT(resumeTorrent(QString)));
connect(connection, SIGNAL(pauseAllTorrents()), QBtSession::instance(), SLOT(pauseAllTorrents()));
connect(connection, SIGNAL(resumeAllTorrents()), QBtSession::instance(), SLOT(resumeAllTorrents()));
}
HttpConnection *connection = new HttpConnection(socket, this);
//connect connection to QBtSession::instance()
connect(connection, SIGNAL(UrlReadyToBeDownloaded(QString)), QBtSession::instance(), SLOT(downloadUrlAndSkipDialog(QString)));
connect(connection, SIGNAL(MagnetReadyToBeDownloaded(QString)), QBtSession::instance(), SLOT(addMagnetSkipAddDlg(QString)));
connect(connection, SIGNAL(torrentReadyToBeDownloaded(QString, bool, QString, bool)), QBtSession::instance(), SLOT(addTorrent(QString, bool, QString, bool)));
connect(connection, SIGNAL(deleteTorrent(QString, bool)), QBtSession::instance(), SLOT(deleteTorrent(QString, bool)));
connect(connection, SIGNAL(pauseTorrent(QString)), QBtSession::instance(), SLOT(pauseTorrent(QString)));
connect(connection, SIGNAL(resumeTorrent(QString)), QBtSession::instance(), SLOT(resumeTorrent(QString)));
connect(connection, SIGNAL(pauseAllTorrents()), QBtSession::instance(), SLOT(pauseAllTorrents()));
connect(connection, SIGNAL(resumeAllTorrents()), QBtSession::instance(), SLOT(resumeAllTorrents()));
}
void HttpServer::onTimer() {

View File

@@ -36,6 +36,12 @@
#include <QTcpServer>
#include <QByteArray>
#include <QHash>
#ifndef QT_NO_OPENSSL
#include <QSslCertificate>
#include <QSslKey>
#endif
#include "preferences.h"
class EventManager;
@@ -63,14 +69,21 @@ public:
void increaseNbFailedAttemptsForIp(QString ip);
void resetNbFailedAttemptsForIp(QString ip);
#ifndef QT_NO_OPENSSL
void enableHttps(const QSslCertificate &certificate, const QSslKey &key);
void disableHttps();
#endif
private:
void incomingConnection(int socketDescriptor);
private slots:
void newHttpConnection();
void onTimer();
void UnbanTimerEvent();
private:
void handleNewConnection(QTcpSocket *socket);
private:
QByteArray username;
QByteArray password_ha1;
@@ -78,9 +91,11 @@ private:
QTimer *timer;
QHash<QString, int> client_failed_attempts;
bool m_localAuth;
#ifndef QT_NO_OPENSSL
bool m_https;
QSslCertificate m_certificate;
QSslKey m_key;
#endif
};
#endif

View File

@@ -47,7 +47,6 @@ namespace json {
case QVariant::LongLong:
case QVariant::UInt:
case QVariant::ULongLong:
//case QMetaType::Float:
return v.value<QString>();
case QVariant::StringList:
case QVariant::List: {
@@ -57,13 +56,11 @@ namespace json {
}
return "["+strList.join(",")+"]";
}
case QVariant::String:
{
case QVariant::String: {
QString s = v.value<QString>();
QString result = "\"";
for(int i=0; i<s.size(); i++)
{
QChar ch = s[i];
for(int i=0; i<s.size(); ++i) {
const QChar ch = s[i];
switch(ch.toAscii())
{
case '\b':
@@ -102,8 +99,9 @@ namespace json {
QString toJson(QVariantMap m) {
QStringList vlist;
foreach(QString key, m.keys()) {
vlist << toJson(key)+":"+toJson(m[key]);
QVariantMap::ConstIterator it;
for (it = m.constBegin(); it != m.constEnd(); it++) {
vlist << toJson(it.key())+":"+toJson(it.value());
}
return "{"+vlist.join(",")+"}";
}
@@ -112,47 +110,40 @@ namespace json {
qDebug("JSON is %s", qPrintable(json));
QVariantMap m;
if(json.startsWith("{") && json.endsWith("}")) {
json.chop(1);
json = json.replace(0, 1, "");
json = json.mid(1, json.length()-2);
QStringList couples;
QString tmp = "";
bool in_list = false;
foreach(QChar c, json) {
foreach(const QChar &c, json) {
if(c == ',' && !in_list) {
couples << tmp;
tmp = "";
} else {
if(c == '[') {
if(c == '[')
in_list = true;
} else {
if(c == ']') {
in_list = false;
}
}
else if(c == ']')
in_list = false;
tmp += c;
}
}
if(!tmp.isEmpty()) couples << tmp;
foreach(QString couple, couples) {
foreach(const QString &couple, couples) {
QStringList parts = couple.split(":");
if(parts.size() != 2) continue;
QString key = parts.first();
if(key.startsWith("\"") && key.endsWith("\"")) {
key.chop(1);
key = key.replace(0, 1, "");
key = key.mid(1, key.length()-2);
}
QString value_str = parts.last();
QVariant value;
if(value_str.startsWith("[") && value_str.endsWith("]")) {
value_str.chop(1);
value_str.replace(0, 1, "");
value_str = value_str.mid(1, value_str.length()-2);
QStringList list_elems = value_str.split(",", QString::SkipEmptyParts);
QVariantList varlist;
foreach(QString list_val, list_elems) {
foreach(const QString &list_val, list_elems) {
if(list_val.startsWith("\"") && list_val.endsWith("\"")) {
list_val.chop(1);
list_val = list_val.replace(0, 1, "");
varlist << list_val;
varlist << list_val.mid(1, list_val.length()-2).replace("\\n", "\n");
} else {
varlist << list_val.toInt();
}
@@ -160,14 +151,18 @@ namespace json {
value = varlist;
} else {
if(value_str.startsWith("\"") && value_str.endsWith("\"")) {
value_str.chop(1);
value_str = value_str.replace(0, 1, "");
value_str = value_str.mid(1, value_str.length()-2).replace("\\n", "\n");
value = value_str;
} else {
value = value_str.toInt();
if (value_str.compare("false", Qt::CaseInsensitive) == 0)
value = false;
else if (value_str.compare("true", Qt::CaseInsensitive) == 0)
value = true;
else
value = value_str.toInt();
}
}
m.insert(key,value);
m.insert(key, value);
qDebug("%s:%s", key.toLocal8Bit().data(), value_str.toLocal8Bit().data());
}
}
@@ -178,8 +173,9 @@ namespace json {
QStringList res;
foreach(QVariantMap m, v) {
QStringList vlist;
foreach(QString key, m.keys()) {
vlist << toJson(key)+":"+toJson(m[key]);
QVariantMap::ConstIterator it;
for(it = m.constBegin(); it != m.constEnd(); it++) {
vlist << toJson(it.key())+":"+toJson(it.value());
}
res << "{"+vlist.join(",")+"}";
}