mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-31 20:58:07 -06:00
Coding style clean up
This commit is contained in:
@@ -58,23 +58,23 @@ QList<QVariantMap> EventManager::getEventList() const {
|
||||
QList<QVariantMap> EventManager::getPropTrackersInfo(QString hash) const {
|
||||
QList<QVariantMap> trackersInfo;
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid()) {
|
||||
if (h.is_valid()) {
|
||||
QHash<QString, TrackerInfos> trackers_data = QBtSession::instance()->getTrackersInfo(hash);
|
||||
std::vector<announce_entry> vect_trackers = h.trackers();
|
||||
std::vector<announce_entry>::iterator it;
|
||||
for(it = vect_trackers.begin(); it != vect_trackers.end(); it++) {
|
||||
for (it = vect_trackers.begin(); it != vect_trackers.end(); it++) {
|
||||
QVariantMap tracker;
|
||||
QString tracker_url = misc::toQString(it->url);
|
||||
tracker["url"] = tracker_url;
|
||||
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
QString error_message = data.last_message.trimmed();
|
||||
if(it->verified) {
|
||||
if (it->verified) {
|
||||
tracker["status"] = tr("Working");
|
||||
} else {
|
||||
if(it->updating && it->fails == 0) {
|
||||
if (it->updating && it->fails == 0) {
|
||||
tracker["status"] = tr("Updating...");
|
||||
} else {
|
||||
if(it->fails > 0) {
|
||||
if (it->fails > 0) {
|
||||
tracker["status"] = tr("Not working");
|
||||
} else {
|
||||
tracker["status"] = tr("Not contacted yet");
|
||||
@@ -92,21 +92,21 @@ QList<QVariantMap> EventManager::getPropTrackersInfo(QString hash) const {
|
||||
QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
|
||||
QList<QVariantMap> files;
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(!h.is_valid() || !h.has_metadata()) return files;
|
||||
if (!h.is_valid() || !h.has_metadata()) return files;
|
||||
std::vector<int> priorities = h.file_priorities();
|
||||
std::vector<size_type> fp;
|
||||
h.file_progress(fp);
|
||||
for(int i=0; i<h.num_files(); ++i) {
|
||||
for (int i=0; i<h.num_files(); ++i) {
|
||||
QVariantMap file;
|
||||
file["name"] = h.filename_at(i);
|
||||
libtorrent::size_type size = h.filesize_at(i);
|
||||
file["size"] = misc::friendlyUnit((double)size);
|
||||
if(size > 0)
|
||||
if (size > 0)
|
||||
file["progress"] = fp[i]/(double)size;
|
||||
else
|
||||
file["progress"] = 1.; // Empty file...
|
||||
file["priority"] = priorities[i];
|
||||
if(i == 0)
|
||||
if (i == 0)
|
||||
file["is_seed"] = h.is_seed();
|
||||
files << file;
|
||||
}
|
||||
@@ -116,11 +116,11 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
|
||||
void EventManager::setGlobalPreferences(QVariantMap m) {
|
||||
// UI
|
||||
Preferences pref;
|
||||
if(m.contains("locale")) {
|
||||
if (m.contains("locale")) {
|
||||
QString locale = m["locale"].toString();
|
||||
if(pref.getLocale() != locale) {
|
||||
if (pref.getLocale() != locale) {
|
||||
QTranslator *translator = new QTranslator;
|
||||
if(translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale)){
|
||||
if (translator->load(QString::fromUtf8(":/lang/qbittorrent_") + locale)){
|
||||
qDebug("%s locale recognized, using translation.", qPrintable(locale));
|
||||
}else{
|
||||
qDebug("%s locale unrecognized, using default (en_GB).", qPrintable(locale));
|
||||
@@ -132,184 +132,184 @@ void EventManager::setGlobalPreferences(QVariantMap m) {
|
||||
}
|
||||
}
|
||||
// Downloads
|
||||
if(m.contains("save_path"))
|
||||
if (m.contains("save_path"))
|
||||
pref.setSavePath(m["save_path"].toString());
|
||||
if(m.contains("temp_path_enabled"))
|
||||
if (m.contains("temp_path_enabled"))
|
||||
pref.setTempPathEnabled(m["temp_path_enabled"].toBool());
|
||||
if(m.contains("temp_path"))
|
||||
if (m.contains("temp_path"))
|
||||
pref.setTempPath(m["temp_path"].toString());
|
||||
if(m.contains("scan_dirs") && m.contains("download_in_scan_dirs")) {
|
||||
if (m.contains("scan_dirs") && m.contains("download_in_scan_dirs")) {
|
||||
QVariantList download_at_path_tmp = m["download_in_scan_dirs"].toList();
|
||||
QList<bool> download_at_path;
|
||||
foreach(QVariant var, download_at_path_tmp) {
|
||||
foreach (QVariant var, download_at_path_tmp) {
|
||||
download_at_path << var.toBool();
|
||||
}
|
||||
QStringList old_folders = pref.getScanDirs();
|
||||
QStringList new_folders = m["scan_dirs"].toStringList();
|
||||
if(download_at_path.size() == new_folders.size()) {
|
||||
if (download_at_path.size() == new_folders.size()) {
|
||||
pref.setScanDirs(new_folders);
|
||||
pref.setDownloadInScanDirs(download_at_path);
|
||||
foreach(const QString &old_folder, old_folders) {
|
||||
foreach (const QString &old_folder, old_folders) {
|
||||
// Update deleted folders
|
||||
if(!new_folders.contains(old_folder)) {
|
||||
if (!new_folders.contains(old_folder)) {
|
||||
QBtSession::instance()->getScanFoldersModel()->removePath(old_folder);
|
||||
}
|
||||
}
|
||||
int i = 0;
|
||||
foreach(const QString &new_folder, new_folders) {
|
||||
foreach (const QString &new_folder, new_folders) {
|
||||
qDebug("New watched folder: %s", qPrintable(new_folder));
|
||||
// Update new folders
|
||||
if(!old_folders.contains(new_folder)) {
|
||||
if (!old_folders.contains(new_folder)) {
|
||||
QBtSession::instance()->getScanFoldersModel()->addPath(new_folder, download_at_path.at(i));
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m.contains("export_dir"))
|
||||
if (m.contains("export_dir"))
|
||||
pref.setExportDir(m["export_dir"].toString());
|
||||
if(m.contains("mail_notification_enabled"))
|
||||
if (m.contains("mail_notification_enabled"))
|
||||
pref.setMailNotificationEnabled(m["mail_notification_enabled"].toBool());
|
||||
if(m.contains("mail_notification_email"))
|
||||
if (m.contains("mail_notification_email"))
|
||||
pref.setMailNotificationEmail(m["mail_notification_email"].toString());
|
||||
if(m.contains("mail_notification_smtp"))
|
||||
if (m.contains("mail_notification_smtp"))
|
||||
pref.setMailNotificationSMTP(m["mail_notification_smtp"].toString());
|
||||
if(m.contains("mail_notification_ssl_enabled"))
|
||||
if (m.contains("mail_notification_ssl_enabled"))
|
||||
pref.setMailNotificationSMTPSSL(m["mail_notification_ssl_enabled"].toBool());
|
||||
if(m.contains("mail_notification_auth_enabled"))
|
||||
if (m.contains("mail_notification_auth_enabled"))
|
||||
pref.setMailNotificationSMTPAuth(m["mail_notification_auth_enabled"].toBool());
|
||||
if(m.contains("mail_notification_username"))
|
||||
if (m.contains("mail_notification_username"))
|
||||
pref.setMailNotificationSMTPUsername(m["mail_notification_username"].toString());
|
||||
if(m.contains("mail_notification_password"))
|
||||
if (m.contains("mail_notification_password"))
|
||||
pref.setMailNotificationSMTPPassword(m["mail_notification_password"].toString());
|
||||
if(m.contains("autorun_enabled"))
|
||||
if (m.contains("autorun_enabled"))
|
||||
pref.setAutoRunEnabled(m["autorun_enabled"].toBool());
|
||||
if(m.contains("autorun_program"))
|
||||
if (m.contains("autorun_program"))
|
||||
pref.setAutoRunProgram(m["autorun_program"].toString());
|
||||
if(m.contains("preallocate_all"))
|
||||
if (m.contains("preallocate_all"))
|
||||
pref.preAllocateAllFiles(m["preallocate_all"].toBool());
|
||||
if(m.contains("queueing_enabled"))
|
||||
if (m.contains("queueing_enabled"))
|
||||
pref.setQueueingSystemEnabled(m["queueing_enabled"].toBool());
|
||||
if(m.contains("max_active_downloads"))
|
||||
if (m.contains("max_active_downloads"))
|
||||
pref.setMaxActiveDownloads(m["max_active_downloads"].toInt());
|
||||
if(m.contains("max_active_torrents"))
|
||||
if (m.contains("max_active_torrents"))
|
||||
pref.setMaxActiveTorrents(m["max_active_torrents"].toInt());
|
||||
if(m.contains("max_active_uploads"))
|
||||
if (m.contains("max_active_uploads"))
|
||||
pref.setMaxActiveUploads(m["max_active_uploads"].toInt());
|
||||
if(m.contains("dont_count_slow_torrents"))
|
||||
if (m.contains("dont_count_slow_torrents"))
|
||||
pref.setIgnoreSlowTorrentsForQueueing(m["dont_count_slow_torrents"].toBool());
|
||||
if(m.contains("incomplete_files_ext"))
|
||||
if (m.contains("incomplete_files_ext"))
|
||||
pref.useIncompleteFilesExtension(m["incomplete_files_ext"].toBool());
|
||||
// Connection
|
||||
if(m.contains("listen_port"))
|
||||
if (m.contains("listen_port"))
|
||||
pref.setSessionPort(m["listen_port"].toInt());
|
||||
if(m.contains("upnp"))
|
||||
if (m.contains("upnp"))
|
||||
pref.setUPnPEnabled(m["upnp"].toBool());
|
||||
if(m.contains("dl_limit"))
|
||||
if (m.contains("dl_limit"))
|
||||
pref.setGlobalDownloadLimit(m["dl_limit"].toInt());
|
||||
if(m.contains("up_limit"))
|
||||
if (m.contains("up_limit"))
|
||||
pref.setGlobalUploadLimit(m["up_limit"].toInt());
|
||||
if(m.contains("max_connec"))
|
||||
if (m.contains("max_connec"))
|
||||
pref.setMaxConnecs(m["max_connec"].toInt());
|
||||
if(m.contains("max_connec_per_torrent"))
|
||||
if (m.contains("max_connec_per_torrent"))
|
||||
pref.setMaxConnecsPerTorrent(m["max_connec_per_torrent"].toInt());
|
||||
if(m.contains("max_uploads_per_torrent"))
|
||||
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"))
|
||||
if (m.contains("enable_utp"))
|
||||
pref.setuTPEnabled(m["enable_utp"].toBool());
|
||||
if(m.contains("limit_utp_rate"))
|
||||
if (m.contains("limit_utp_rate"))
|
||||
pref.setuTPRateLimited(m["limit_utp_rate"].toBool());
|
||||
#endif
|
||||
if(m.contains("limit_tcp_overhead"))
|
||||
if (m.contains("limit_tcp_overhead"))
|
||||
pref.includeOverheadInLimits(m["limit_tcp_overhead"].toBool());
|
||||
if(m.contains("alt_dl_limit"))
|
||||
if (m.contains("alt_dl_limit"))
|
||||
pref.setAltGlobalDownloadLimit(m["alt_dl_limit"].toInt());
|
||||
if(m.contains("alt_up_limit"))
|
||||
if (m.contains("alt_up_limit"))
|
||||
pref.setAltGlobalUploadLimit(m["alt_up_limit"].toInt());
|
||||
if(m.contains("scheduler_enabled"))
|
||||
if (m.contains("scheduler_enabled"))
|
||||
pref.setSchedulerEnabled(m["scheduler_enabled"].toBool());
|
||||
if(m.contains("schedule_from_hour") && m.contains("schedule_from_min")) {
|
||||
if (m.contains("schedule_from_hour") && m.contains("schedule_from_min")) {
|
||||
pref.setSchedulerStartTime(QTime(m["schedule_from_hour"].toInt(),
|
||||
m["schedule_from_min"].toInt()));
|
||||
}
|
||||
if(m.contains("schedule_to_hour") && m.contains("schedule_to_min")) {
|
||||
if (m.contains("schedule_to_hour") && m.contains("schedule_to_min")) {
|
||||
pref.setSchedulerEndTime(QTime(m["schedule_to_hour"].toInt(),
|
||||
m["schedule_to_min"].toInt()));
|
||||
}
|
||||
if(m.contains("scheduler_days"))
|
||||
if (m.contains("scheduler_days"))
|
||||
pref.setSchedulerDays(scheduler_days(m["scheduler_days"].toInt()));
|
||||
// Bittorrent
|
||||
if(m.contains("dht"))
|
||||
if (m.contains("dht"))
|
||||
pref.setDHTEnabled(m["dht"].toBool());
|
||||
if(m.contains("dhtSameAsBT"))
|
||||
if (m.contains("dhtSameAsBT"))
|
||||
pref.setDHTPortSameAsBT(m["dhtSameAsBT"].toBool());
|
||||
if(m.contains("dht_port"))
|
||||
if (m.contains("dht_port"))
|
||||
pref.setDHTPort(m["dht_port"].toInt());
|
||||
if(m.contains("pex"))
|
||||
if (m.contains("pex"))
|
||||
pref.setPeXEnabled(m["pex"].toBool());
|
||||
qDebug("Pex support: %d", (int)m["pex"].toBool());
|
||||
if(m.contains("lsd"))
|
||||
if (m.contains("lsd"))
|
||||
pref.setLSDEnabled(m["lsd"].toBool());
|
||||
if(m.contains("encryption"))
|
||||
if (m.contains("encryption"))
|
||||
pref.setEncryptionSetting(m["encryption"].toInt());
|
||||
#if LIBTORRENT_VERSION_MINOR >= 16
|
||||
if(m.contains("anonymous_mode"))
|
||||
if (m.contains("anonymous_mode"))
|
||||
pref.enableAnonymousMode(m["anonymous_mode"].toBool());
|
||||
#endif
|
||||
// Proxy
|
||||
if(m.contains("proxy_type"))
|
||||
if (m.contains("proxy_type"))
|
||||
pref.setProxyType(m["proxy_type"].toInt());
|
||||
if(m.contains("proxy_ip"))
|
||||
if (m.contains("proxy_ip"))
|
||||
pref.setProxyIp(m["proxy_ip"].toString());
|
||||
if(m.contains("proxy_port"))
|
||||
if (m.contains("proxy_port"))
|
||||
pref.setProxyPort(m["proxy_port"].toUInt());
|
||||
if(m.contains("proxy_peer_connections"))
|
||||
if (m.contains("proxy_peer_connections"))
|
||||
pref.setProxyPeerConnections(m["proxy_peer_connections"].toBool());
|
||||
if(m.contains("proxy_auth_enabled"))
|
||||
if (m.contains("proxy_auth_enabled"))
|
||||
pref.setProxyAuthEnabled(m["proxy_auth_enabled"].toBool());
|
||||
if(m.contains("proxy_username"))
|
||||
if (m.contains("proxy_username"))
|
||||
pref.setProxyUsername(m["proxy_username"].toString());
|
||||
if(m.contains("proxy_password"))
|
||||
if (m.contains("proxy_password"))
|
||||
pref.setProxyPassword(m["proxy_password"].toString());
|
||||
// IP Filter
|
||||
if(m.contains("ip_filter_enabled"))
|
||||
if (m.contains("ip_filter_enabled"))
|
||||
pref.setFilteringEnabled(m["ip_filter_enabled"].toBool());
|
||||
if(m.contains("ip_filter_path"))
|
||||
if (m.contains("ip_filter_path"))
|
||||
pref.setFilter(m["ip_filter_path"].toString());
|
||||
// Web UI
|
||||
if(m.contains("web_ui_port"))
|
||||
if (m.contains("web_ui_port"))
|
||||
pref.setWebUiPort(m["web_ui_port"].toUInt());
|
||||
if(m.contains("web_ui_username"))
|
||||
if (m.contains("web_ui_username"))
|
||||
pref.setWebUiUsername(m["web_ui_username"].toString());
|
||||
if(m.contains("web_ui_password"))
|
||||
if (m.contains("web_ui_password"))
|
||||
pref.setWebUiPassword(m["web_ui_password"].toString());
|
||||
if(m.contains("bypass_local_auth"))
|
||||
if (m.contains("bypass_local_auth"))
|
||||
pref.setWebUiLocalAuthEnabled(!m["bypass_local_auth"].toBool());
|
||||
if(m.contains("use_https"))
|
||||
if (m.contains("use_https"))
|
||||
pref.setWebUiHttpsEnabled(m["use_https"].toBool());
|
||||
#ifndef QT_NO_OPENSSL
|
||||
if(m.contains("ssl_key")) {
|
||||
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")) {
|
||||
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"))
|
||||
if (m.contains("dyndns_enabled"))
|
||||
pref.setDynDNSEnabled(m["dyndns_enabled"].toBool());
|
||||
if(m.contains("dyndns_service"))
|
||||
if (m.contains("dyndns_service"))
|
||||
pref.setDynDNSService(m["dyndns_service"].toInt());
|
||||
if(m.contains("dyndns_username"))
|
||||
if (m.contains("dyndns_username"))
|
||||
pref.setDynDNSUsername(m["dyndns_username"].toString());
|
||||
if(m.contains("dyndns_password"))
|
||||
if (m.contains("dyndns_password"))
|
||||
pref.setDynDNSPassword(m["dyndns_password"].toString());
|
||||
if(m.contains("dyndns_domain"))
|
||||
if (m.contains("dyndns_domain"))
|
||||
pref.setDynDomainName(m["dyndns_domain"].toString());
|
||||
// Reload preferences
|
||||
QBtSession::instance()->configureSession();
|
||||
@@ -326,7 +326,7 @@ QVariantMap EventManager::getGlobalPreferences() const {
|
||||
data["temp_path"] = pref.getTempPath();
|
||||
data["scan_dirs"] = pref.getScanDirs();
|
||||
QVariantList var_list;
|
||||
foreach(bool b, pref.getDownloadInScanDirs()) {
|
||||
foreach (bool b, pref.getDownloadInScanDirs()) {
|
||||
var_list << b;
|
||||
}
|
||||
data["download_in_scan_dirs"] = var_list;
|
||||
@@ -412,10 +412,10 @@ QVariantMap EventManager::getGlobalPreferences() const {
|
||||
QVariantMap EventManager::getPropGeneralInfo(QString hash) const {
|
||||
QVariantMap data;
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid() && h.has_metadata()) {
|
||||
if (h.is_valid() && h.has_metadata()) {
|
||||
// Save path
|
||||
QString p = TorrentPersistentData::getSavePath(hash);
|
||||
if(p.isEmpty()) p = h.save_path();
|
||||
if (p.isEmpty()) p = h.save_path();
|
||||
data["save_path"] = p;
|
||||
// Creation date
|
||||
data["creation_date"] = h.creation_date();
|
||||
@@ -426,23 +426,23 @@ QVariantMap EventManager::getPropGeneralInfo(QString hash) const {
|
||||
data["total_wasted"] = QVariant(misc::friendlyUnit(h.total_failed_bytes()+h.total_redundant_bytes()));
|
||||
data["total_uploaded"] = QVariant(misc::friendlyUnit(h.all_time_upload()) + " ("+misc::friendlyUnit(h.total_payload_upload())+" "+tr("this session")+")");
|
||||
data["total_downloaded"] = QVariant(misc::friendlyUnit(h.all_time_download()) + " ("+misc::friendlyUnit(h.total_payload_download())+" "+tr("this session")+")");
|
||||
if(h.upload_limit() <= 0)
|
||||
if (h.upload_limit() <= 0)
|
||||
data["up_limit"] = QString::fromUtf8("∞");
|
||||
else
|
||||
data["up_limit"] = QVariant(misc::friendlyUnit(h.upload_limit())+tr("/s", "/second (i.e. per second)"));
|
||||
if(h.download_limit() <= 0)
|
||||
if (h.download_limit() <= 0)
|
||||
data["dl_limit"] = QString::fromUtf8("∞");
|
||||
else
|
||||
data["dl_limit"] = QVariant(misc::friendlyUnit(h.download_limit())+tr("/s", "/second (i.e. per second)"));
|
||||
QString elapsed_txt = misc::userFriendlyDuration(h.active_time());
|
||||
if(h.is_seed()) {
|
||||
if (h.is_seed()) {
|
||||
elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")";
|
||||
}
|
||||
data["time_elapsed"] = elapsed_txt;
|
||||
data["nb_connections"] = QVariant(QString::number(h.num_connections())+" ("+tr("%1 max", "e.g. 10 max").arg(QString::number(h.connections_limit()))+")");
|
||||
// Update ratio info
|
||||
qreal ratio = QBtSession::instance()->getRealRatio(h.hash());
|
||||
if(ratio > 100.)
|
||||
if (ratio > 100.)
|
||||
data["share_ratio"] = QString::fromUtf8("∞");
|
||||
else
|
||||
data["share_ratio"] = QString(QByteArray::number(ratio, 'f', 1));
|
||||
@@ -465,18 +465,18 @@ void EventManager::modifiedTorrent(const QTorrentHandle& h)
|
||||
QString hash = h.hash();
|
||||
QVariantMap event;
|
||||
event["eta"] = QVariant(QString::fromUtf8("∞"));
|
||||
if(h.is_paused()) {
|
||||
if(h.has_error()) {
|
||||
if (h.is_paused()) {
|
||||
if (h.has_error()) {
|
||||
event["state"] = QVariant("error");
|
||||
} else {
|
||||
if(h.is_seed())
|
||||
if (h.is_seed())
|
||||
event["state"] = QVariant("pausedUP");
|
||||
else
|
||||
event["state"] = QVariant("pausedDL");
|
||||
}
|
||||
} else {
|
||||
if(QBtSession::instance()->isQueueingEnabled() && h.is_queued()) {
|
||||
if(h.is_seed())
|
||||
if (QBtSession::instance()->isQueueingEnabled() && h.is_queued()) {
|
||||
if (h.is_seed())
|
||||
event["state"] = QVariant("queuedUP");
|
||||
else
|
||||
event["state"] = QVariant("queuedDL");
|
||||
@@ -485,7 +485,7 @@ void EventManager::modifiedTorrent(const QTorrentHandle& h)
|
||||
{
|
||||
case torrent_status::finished:
|
||||
case torrent_status::seeding:
|
||||
if(h.upload_payload_rate() > 0) {
|
||||
if (h.upload_payload_rate() > 0) {
|
||||
event["state"] = QVariant("uploading");
|
||||
} else {
|
||||
event["state"] = QVariant("stalledUP");
|
||||
@@ -495,7 +495,7 @@ void EventManager::modifiedTorrent(const QTorrentHandle& h)
|
||||
case torrent_status::checking_files:
|
||||
case torrent_status::queued_for_checking:
|
||||
case torrent_status::checking_resume_data:
|
||||
if(h.is_seed()) {
|
||||
if (h.is_seed()) {
|
||||
event["state"] = QVariant("checkingUP");
|
||||
} else {
|
||||
event["state"] = QVariant("checkingDL");
|
||||
@@ -503,7 +503,7 @@ void EventManager::modifiedTorrent(const QTorrentHandle& h)
|
||||
break;
|
||||
case torrent_status::downloading:
|
||||
case torrent_status::downloading_metadata:
|
||||
if(h.download_payload_rate() > 0)
|
||||
if (h.download_payload_rate() > 0)
|
||||
event["state"] = QVariant("downloading");
|
||||
else
|
||||
event["state"] = QVariant("stalledDL");
|
||||
@@ -519,8 +519,8 @@ void EventManager::modifiedTorrent(const QTorrentHandle& h)
|
||||
event["size"] = QVariant(misc::friendlyUnit(h.actual_size()));
|
||||
event["progress"] = QVariant((double)h.progress());
|
||||
event["dlspeed"] = QVariant(tr("%1/s", "e.g. 120 KiB/s").arg(misc::friendlyUnit(h.download_payload_rate())));
|
||||
if(QBtSession::instance()->isQueueingEnabled()) {
|
||||
if(h.queue_position() >= 0)
|
||||
if (QBtSession::instance()->isQueueingEnabled()) {
|
||||
if (h.queue_position() >= 0)
|
||||
event["priority"] = QVariant(QString::number(h.queue_position()));
|
||||
else
|
||||
event["priority"] = "*";
|
||||
@@ -529,16 +529,16 @@ void EventManager::modifiedTorrent(const QTorrentHandle& h)
|
||||
}
|
||||
event["upspeed"] = QVariant(tr("%1/s", "e.g. 120 KiB/s").arg(misc::friendlyUnit(h.upload_payload_rate())));
|
||||
QString seeds = QString::number(h.num_seeds());
|
||||
if(h.num_complete() > 0)
|
||||
if (h.num_complete() > 0)
|
||||
seeds += " ("+QString::number(h.num_complete())+")";
|
||||
event["num_seeds"] = QVariant(seeds);
|
||||
QString leechs = QString::number(h.num_peers()-h.num_seeds());
|
||||
if(h.num_incomplete() > 0)
|
||||
if (h.num_incomplete() > 0)
|
||||
leechs += " ("+QString::number(h.num_incomplete())+")";
|
||||
event["num_leechs"] = QVariant(leechs);
|
||||
event["seed"] = QVariant(h.is_seed());
|
||||
qreal ratio = QBtSession::instance()->getRealRatio(hash);
|
||||
if(ratio > 100.)
|
||||
if (ratio > 100.)
|
||||
event["ratio"] = QString::fromUtf8("∞");
|
||||
else
|
||||
event["ratio"] = QVariant(QString::number(ratio, 'f', 1));
|
||||
|
||||
@@ -120,7 +120,7 @@ void HttpConnection::read() {
|
||||
m_parser.writeMessage(message);
|
||||
}
|
||||
|
||||
if(m_parser.isError()) {
|
||||
if (m_parser.isError()) {
|
||||
qDebug() << Q_FUNC_INFO << "message parsing error";
|
||||
m_generator.setStatusLine(400, "Bad Request");
|
||||
write();
|
||||
@@ -150,7 +150,7 @@ void HttpConnection::translateDocument(QString& data) {
|
||||
found = false;
|
||||
|
||||
i = regex.indexIn(data, i);
|
||||
if(i >= 0) {
|
||||
if (i >= 0) {
|
||||
//qDebug("Found translatable string: %s", regex.cap(1).toUtf8().data());
|
||||
QByteArray word = regex.cap(1).toLocal8Bit();
|
||||
|
||||
@@ -173,20 +173,20 @@ void HttpConnection::translateDocument(QString& data) {
|
||||
}
|
||||
|
||||
void HttpConnection::respond() {
|
||||
if((m_socket->peerAddress() != QHostAddress::LocalHost
|
||||
if ((m_socket->peerAddress() != QHostAddress::LocalHost
|
||||
&& m_socket->peerAddress() != QHostAddress::LocalHostIPv6)
|
||||
|| m_httpserver->isLocalAuthEnabled()) {
|
||||
// Authentication
|
||||
const QString peer_ip = m_socket->peerAddress().toString();
|
||||
const int nb_fail = m_httpserver->NbFailedAttemptsForIp(peer_ip);
|
||||
if(nb_fail >= MAX_AUTH_FAILED_ATTEMPTS) {
|
||||
if (nb_fail >= MAX_AUTH_FAILED_ATTEMPTS) {
|
||||
m_generator.setStatusLine(403, "Forbidden");
|
||||
m_generator.setMessage(tr("Your IP address has been banned after too many failed authentication attempts."));
|
||||
write();
|
||||
return;
|
||||
}
|
||||
QString auth = m_parser.header().value("Authorization");
|
||||
if(auth.isEmpty()) {
|
||||
if (auth.isEmpty()) {
|
||||
// Return unauthorized header
|
||||
qDebug("Auth is Empty...");
|
||||
m_generator.setStatusLine(401, "Unauthorized");
|
||||
@@ -211,10 +211,10 @@ void HttpConnection::respond() {
|
||||
}
|
||||
QString url = m_parser.url();
|
||||
// Favicon
|
||||
if(url.endsWith("favicon.ico")) {
|
||||
if (url.endsWith("favicon.ico")) {
|
||||
qDebug("Returning favicon");
|
||||
QFile favicon(":/Icons/skin/qbittorrent16.png");
|
||||
if(favicon.open(QIODevice::ReadOnly)) {
|
||||
if (favicon.open(QIODevice::ReadOnly)) {
|
||||
QByteArray data = favicon.readAll();
|
||||
favicon.close();
|
||||
m_generator.setStatusLine(200, "OK");
|
||||
@@ -242,28 +242,28 @@ void HttpConnection::respond() {
|
||||
respondJson();
|
||||
return;
|
||||
}
|
||||
if(list.size() > 2) {
|
||||
if(list[1] == "propertiesGeneral") {
|
||||
if (list.size() > 2) {
|
||||
if (list[1] == "propertiesGeneral") {
|
||||
const QString& hash = list[2];
|
||||
respondGenPropertiesJson(hash);
|
||||
return;
|
||||
}
|
||||
if(list[1] == "propertiesTrackers") {
|
||||
if (list[1] == "propertiesTrackers") {
|
||||
const QString& hash = list[2];
|
||||
respondTrackersPropertiesJson(hash);
|
||||
return;
|
||||
}
|
||||
if(list[1] == "propertiesFiles") {
|
||||
if (list[1] == "propertiesFiles") {
|
||||
const QString& hash = list[2];
|
||||
respondFilesPropertiesJson(hash);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(list[1] == "preferences") {
|
||||
if (list[1] == "preferences") {
|
||||
respondPreferencesJson();
|
||||
return;
|
||||
} else {
|
||||
if(list[1] == "transferInfo") {
|
||||
if (list[1] == "transferInfo") {
|
||||
respondGlobalTransferInfoJson();
|
||||
return;
|
||||
}
|
||||
@@ -281,7 +281,7 @@ void HttpConnection::respond() {
|
||||
|
||||
// Icons from theme
|
||||
qDebug() << "list[0]" << list[0];
|
||||
if(list[0] == "theme" && list.size() == 2) {
|
||||
if (list[0] == "theme" && list.size() == 2) {
|
||||
#ifdef DISABLE_GUI
|
||||
url = ":/Icons/oxygen/"+list[1]+".png";
|
||||
#else
|
||||
@@ -292,14 +292,14 @@ void HttpConnection::respond() {
|
||||
if (list[0] == "images") {
|
||||
list[0] = "Icons";
|
||||
} else {
|
||||
if(list.last().endsWith(".html"))
|
||||
if (list.last().endsWith(".html"))
|
||||
list.prepend("html");
|
||||
list.prepend("webui");
|
||||
}
|
||||
url = ":/" + list.join("/");
|
||||
}
|
||||
QFile file(url);
|
||||
if(!file.open(QIODevice::ReadOnly)) {
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
qDebug("File %s was not found!", qPrintable(url));
|
||||
respondNotFound();
|
||||
return;
|
||||
@@ -314,7 +314,7 @@ void HttpConnection::respond() {
|
||||
file.close();
|
||||
|
||||
// Translate the page
|
||||
if(ext == "html" || (ext == "js" && !list.last().startsWith("excanvas"))) {
|
||||
if (ext == "html" || (ext == "js" && !list.last().startsWith("excanvas"))) {
|
||||
QString dataStr = QString::fromUtf8(data.constData());
|
||||
translateDocument(dataStr);
|
||||
if (url.endsWith("about.html")) {
|
||||
@@ -391,17 +391,17 @@ void HttpConnection::respondGlobalTransferInfoJson() {
|
||||
}
|
||||
|
||||
void HttpConnection::respondCommand(const QString& command) {
|
||||
if(command == "download") {
|
||||
if (command == "download") {
|
||||
QString urls = m_parser.post("urls");
|
||||
QStringList list = urls.split('\n');
|
||||
foreach(QString url, list){
|
||||
foreach (QString url, list){
|
||||
url = url.trimmed();
|
||||
if(!url.isEmpty()){
|
||||
if(url.startsWith("bc://bt/", Qt::CaseInsensitive)) {
|
||||
if (!url.isEmpty()){
|
||||
if (url.startsWith("bc://bt/", Qt::CaseInsensitive)) {
|
||||
qDebug("Converting bc link to magnet link");
|
||||
url = misc::bcLinkToMagnet(url);
|
||||
}
|
||||
if(url.startsWith("magnet:", Qt::CaseInsensitive)) {
|
||||
if (url.startsWith("magnet:", Qt::CaseInsensitive)) {
|
||||
emit MagnetReadyToBeDownloaded(url);
|
||||
} else {
|
||||
qDebug("Downloading url: %s", (const char*)url.toLocal8Bit());
|
||||
@@ -412,14 +412,14 @@ void HttpConnection::respondCommand(const QString& command) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(command == "addTrackers") {
|
||||
if (command == "addTrackers") {
|
||||
QString hash = m_parser.post("hash");
|
||||
if(!hash.isEmpty()) {
|
||||
if (!hash.isEmpty()) {
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid() && h.has_metadata()) {
|
||||
if (h.is_valid() && h.has_metadata()) {
|
||||
QString urls = m_parser.post("urls");
|
||||
QStringList list = urls.split('\n');
|
||||
foreach(const QString& url, list) {
|
||||
foreach (const QString& url, list) {
|
||||
announce_entry e(url.toStdString());
|
||||
h.add_tracker(e);
|
||||
}
|
||||
@@ -427,7 +427,7 @@ void HttpConnection::respondCommand(const QString& command) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "upload") {
|
||||
if (command == "upload") {
|
||||
qDebug() << Q_FUNC_INFO << "upload";
|
||||
// Get a unique filename
|
||||
QTemporaryFile *tmpfile = new QTemporaryFile (QDir::temp().absoluteFilePath("qBT-XXXXXX.torrent"));
|
||||
@@ -454,35 +454,35 @@ void HttpConnection::respondCommand(const QString& command) {
|
||||
write();
|
||||
return;
|
||||
}
|
||||
if(command == "resumeall") {
|
||||
if (command == "resumeall") {
|
||||
emit resumeAllTorrents();
|
||||
return;
|
||||
}
|
||||
if(command == "pauseall") {
|
||||
if (command == "pauseall") {
|
||||
emit pauseAllTorrents();
|
||||
return;
|
||||
}
|
||||
if(command == "resume") {
|
||||
if (command == "resume") {
|
||||
emit resumeTorrent(m_parser.post("hash"));
|
||||
return;
|
||||
}
|
||||
if(command == "setPreferences") {
|
||||
if (command == "setPreferences") {
|
||||
QString json_str = m_parser.post("json");
|
||||
EventManager* manager = m_httpserver->eventManager();
|
||||
manager->setGlobalPreferences(json::fromJson(json_str));
|
||||
return;
|
||||
}
|
||||
if(command == "setFilePrio") {
|
||||
if (command == "setFilePrio") {
|
||||
QString hash = m_parser.post("hash");
|
||||
int file_id = m_parser.post("id").toInt();
|
||||
int priority = m_parser.post("priority").toInt();
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid() && h.has_metadata()) {
|
||||
if (h.is_valid() && h.has_metadata()) {
|
||||
h.file_priority(file_id, priority);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "getGlobalUpLimit") {
|
||||
if (command == "getGlobalUpLimit") {
|
||||
m_generator.setStatusLine(200, "OK");
|
||||
m_generator.setContentTypeByExt("html");
|
||||
#if LIBTORRENT_VERSION_MINOR > 15
|
||||
@@ -493,7 +493,7 @@ void HttpConnection::respondCommand(const QString& command) {
|
||||
write();
|
||||
return;
|
||||
}
|
||||
if(command == "getGlobalDlLimit") {
|
||||
if (command == "getGlobalDlLimit") {
|
||||
m_generator.setStatusLine(200, "OK");
|
||||
m_generator.setContentTypeByExt("html");
|
||||
#if LIBTORRENT_VERSION_MINOR > 15
|
||||
@@ -504,10 +504,10 @@ void HttpConnection::respondCommand(const QString& command) {
|
||||
write();
|
||||
return;
|
||||
}
|
||||
if(command == "getTorrentUpLimit") {
|
||||
if (command == "getTorrentUpLimit") {
|
||||
QString hash = m_parser.post("hash");
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid()) {
|
||||
if (h.is_valid()) {
|
||||
m_generator.setStatusLine(200, "OK");
|
||||
m_generator.setContentTypeByExt("html");
|
||||
m_generator.setMessage(QString::number(h.upload_limit()));
|
||||
@@ -515,10 +515,10 @@ void HttpConnection::respondCommand(const QString& command) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "getTorrentDlLimit") {
|
||||
if (command == "getTorrentDlLimit") {
|
||||
QString hash = m_parser.post("hash");
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid()) {
|
||||
if (h.is_valid()) {
|
||||
m_generator.setStatusLine(200, "OK");
|
||||
m_generator.setContentTypeByExt("html");
|
||||
m_generator.setMessage(QString::number(h.download_limit()));
|
||||
@@ -526,81 +526,81 @@ void HttpConnection::respondCommand(const QString& command) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "setTorrentUpLimit") {
|
||||
if (command == "setTorrentUpLimit") {
|
||||
QString hash = m_parser.post("hash");
|
||||
qlonglong limit = m_parser.post("limit").toLongLong();
|
||||
if(limit == 0) limit = -1;
|
||||
if (limit == 0) limit = -1;
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid()) {
|
||||
if (h.is_valid()) {
|
||||
h.set_upload_limit(limit);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "setTorrentDlLimit") {
|
||||
if (command == "setTorrentDlLimit") {
|
||||
QString hash = m_parser.post("hash");
|
||||
qlonglong limit = m_parser.post("limit").toLongLong();
|
||||
if(limit == 0) limit = -1;
|
||||
if (limit == 0) limit = -1;
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid()) {
|
||||
if (h.is_valid()) {
|
||||
h.set_download_limit(limit);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "setGlobalUpLimit") {
|
||||
if (command == "setGlobalUpLimit") {
|
||||
qlonglong limit = m_parser.post("limit").toLongLong();
|
||||
if(limit == 0) limit = -1;
|
||||
if (limit == 0) limit = -1;
|
||||
QBtSession::instance()->setUploadRateLimit(limit);
|
||||
Preferences().setGlobalUploadLimit(limit/1024.);
|
||||
return;
|
||||
}
|
||||
if(command == "setGlobalDlLimit") {
|
||||
if (command == "setGlobalDlLimit") {
|
||||
qlonglong limit = m_parser.post("limit").toLongLong();
|
||||
if(limit == 0) limit = -1;
|
||||
if (limit == 0) limit = -1;
|
||||
QBtSession::instance()->setDownloadRateLimit(limit);
|
||||
Preferences().setGlobalDownloadLimit(limit/1024.);
|
||||
return;
|
||||
}
|
||||
if(command == "pause") {
|
||||
if (command == "pause") {
|
||||
emit pauseTorrent(m_parser.post("hash"));
|
||||
return;
|
||||
}
|
||||
if(command == "delete") {
|
||||
if (command == "delete") {
|
||||
QStringList hashes = m_parser.post("hashes").split("|");
|
||||
foreach(const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes) {
|
||||
emit deleteTorrent(hash, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "deletePerm") {
|
||||
if (command == "deletePerm") {
|
||||
QStringList hashes = m_parser.post("hashes").split("|");
|
||||
foreach(const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes) {
|
||||
emit deleteTorrent(hash, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "increasePrio") {
|
||||
if (command == "increasePrio") {
|
||||
increaseTorrentsPriority(m_parser.post("hashes").split("|"));
|
||||
return;
|
||||
}
|
||||
if(command == "decreasePrio") {
|
||||
if (command == "decreasePrio") {
|
||||
decreaseTorrentsPriority(m_parser.post("hashes").split("|"));
|
||||
return;
|
||||
}
|
||||
if(command == "topPrio") {
|
||||
foreach(const QString &hash, m_parser.post("hashes").split("|")) {
|
||||
if (command == "topPrio") {
|
||||
foreach (const QString &hash, m_parser.post("hashes").split("|")) {
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid()) h.queue_position_top();
|
||||
if (h.is_valid()) h.queue_position_top();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "bottomPrio") {
|
||||
foreach(const QString &hash, m_parser.post("hashes").split("|")) {
|
||||
if (command == "bottomPrio") {
|
||||
foreach (const QString &hash, m_parser.post("hashes").split("|")) {
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(h.is_valid()) h.queue_position_bottom();
|
||||
if (h.is_valid()) h.queue_position_bottom();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(command == "recheck"){
|
||||
if (command == "recheck"){
|
||||
QBtSession::instance()->recheckTorrent(m_parser.post("hash"));
|
||||
return;
|
||||
}
|
||||
@@ -612,10 +612,10 @@ void HttpConnection::decreaseTorrentsPriority(const QStringList &hashes) {
|
||||
std::vector<QPair<int, QTorrentHandle> >,
|
||||
std::less<QPair<int, QTorrentHandle> > > torrent_queue;
|
||||
// Sort torrents by priority
|
||||
foreach(const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes) {
|
||||
try {
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(!h.is_seed()) {
|
||||
if (!h.is_seed()) {
|
||||
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||
}
|
||||
}catch(invalid_handle&){}
|
||||
@@ -637,10 +637,10 @@ void HttpConnection::increaseTorrentsPriority(const QStringList &hashes)
|
||||
std::vector<QPair<int, QTorrentHandle> >,
|
||||
std::greater<QPair<int, QTorrentHandle> > > torrent_queue;
|
||||
// Sort torrents by priority
|
||||
foreach(const QString &hash, hashes) {
|
||||
foreach (const QString &hash, hashes) {
|
||||
try {
|
||||
QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash);
|
||||
if(!h.is_seed()) {
|
||||
if (!h.is_seed()) {
|
||||
torrent_queue.push(qMakePair(h.queue_position(), h));
|
||||
}
|
||||
}catch(invalid_handle&){}
|
||||
|
||||
@@ -87,7 +87,7 @@ void HttpRequestParser::writeMessage(const QByteArray& ba) {
|
||||
qDebug() << Q_FUNC_INFO << "m_data.size(): " << m_data.size();
|
||||
|
||||
// Parse POST data
|
||||
if(m_header.contentType() == "application/x-www-form-urlencoded") {
|
||||
if (m_header.contentType() == "application/x-www-form-urlencoded") {
|
||||
QUrl url;
|
||||
url.setEncodedQuery(m_data);
|
||||
QListIterator<QPair<QString, QString> > i(url.queryItems());
|
||||
|
||||
@@ -42,23 +42,23 @@ void HttpResponseGenerator::setMessage(const QString& message) {
|
||||
}
|
||||
|
||||
void HttpResponseGenerator::setContentTypeByExt(const QString& ext) {
|
||||
if(ext == "css") {
|
||||
if (ext == "css") {
|
||||
setContentType("text/css");
|
||||
return;
|
||||
}
|
||||
if(ext == "gif") {
|
||||
if (ext == "gif") {
|
||||
setContentType("image/gif");
|
||||
return;
|
||||
}
|
||||
if(ext == "htm" || ext == "html") {
|
||||
if (ext == "htm" || ext == "html") {
|
||||
setContentType("text/html");
|
||||
return;
|
||||
}
|
||||
if(ext == "js") {
|
||||
if (ext == "js") {
|
||||
setContentType("text/javascript");
|
||||
return;
|
||||
}
|
||||
if(ext == "png") {
|
||||
if (ext == "png") {
|
||||
setContentType("image/x-png");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ int HttpServer::NbFailedAttemptsForIp(const QString& ip) const {
|
||||
void HttpServer::increaseNbFailedAttemptsForIp(const QString& ip) {
|
||||
const int nb_fail = m_clientFailedAttempts.value(ip, 0) + 1;
|
||||
m_clientFailedAttempts.insert(ip, nb_fail);
|
||||
if(nb_fail == MAX_AUTH_FAILED_ATTEMPTS) {
|
||||
if (nb_fail == MAX_AUTH_FAILED_ATTEMPTS) {
|
||||
// Max number of failed attempts reached
|
||||
// Start ban period
|
||||
UnbanTimer* ubantimer = new UnbanTimer(ip, this);
|
||||
@@ -112,9 +112,9 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
|
||||
// Add torrents
|
||||
std::vector<torrent_handle> torrents = QBtSession::instance()->getTorrents();
|
||||
std::vector<torrent_handle>::iterator torrentIT;
|
||||
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
|
||||
for (torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
|
||||
QTorrentHandle h = QTorrentHandle(*torrentIT);
|
||||
if(h.is_valid())
|
||||
if (h.is_valid())
|
||||
m_eventManager->addedTorrent(h);
|
||||
}
|
||||
|
||||
@@ -217,9 +217,9 @@ void HttpServer::handleNewConnection(QTcpSocket *socket)
|
||||
void HttpServer::onTimer() {
|
||||
std::vector<torrent_handle> torrents = QBtSession::instance()->getTorrents();
|
||||
std::vector<torrent_handle>::iterator torrentIT;
|
||||
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
|
||||
for (torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
|
||||
QTorrentHandle h = QTorrentHandle(*torrentIT);
|
||||
if(h.is_valid())
|
||||
if (h.is_valid())
|
||||
m_eventManager->modifiedTorrent(h);
|
||||
}
|
||||
}
|
||||
@@ -245,28 +245,28 @@ bool HttpServer::isAuthorized(const QByteArray& auth,
|
||||
//qDebug("AUTH string is %s", auth.data());
|
||||
// Get user name
|
||||
QRegExp regex_user(".*username=\"([^\"]+)\".*"); // Must be a quoted string
|
||||
if(regex_user.indexIn(auth) < 0) return false;
|
||||
if (regex_user.indexIn(auth) < 0) return false;
|
||||
QString prop_user = regex_user.cap(1);
|
||||
//qDebug("AUTH: Proposed username is %s, real username is %s", prop_user.toLocal8Bit().data(), username.data());
|
||||
if(prop_user != m_username) {
|
||||
if (prop_user != m_username) {
|
||||
// User name is invalid, we can reject already
|
||||
qDebug("AUTH-PROB: Username is invalid");
|
||||
return false;
|
||||
}
|
||||
// Get realm
|
||||
QRegExp regex_realm(".*realm=\"([^\"]+)\".*"); // Must be a quoted string
|
||||
if(regex_realm.indexIn(auth) < 0) {
|
||||
if (regex_realm.indexIn(auth) < 0) {
|
||||
qDebug("AUTH-PROB: Missing realm");
|
||||
return false;
|
||||
}
|
||||
QByteArray prop_realm = regex_realm.cap(1).toLocal8Bit();
|
||||
if(prop_realm != QBT_REALM) {
|
||||
if (prop_realm != QBT_REALM) {
|
||||
qDebug("AUTH-PROB: Wrong realm");
|
||||
return false;
|
||||
}
|
||||
// get nonce
|
||||
QRegExp regex_nonce(".*nonce=[\"]?([\\w=]+)[\"]?.*");
|
||||
if(regex_nonce.indexIn(auth) < 0) {
|
||||
if (regex_nonce.indexIn(auth) < 0) {
|
||||
qDebug("AUTH-PROB: missing nonce");
|
||||
return false;
|
||||
}
|
||||
@@ -274,7 +274,7 @@ bool HttpServer::isAuthorized(const QByteArray& auth,
|
||||
//qDebug("prop nonce is: %s", prop_nonce.data());
|
||||
// get uri
|
||||
QRegExp regex_uri(".*uri=\"([^\"]+)\".*");
|
||||
if(regex_uri.indexIn(auth) < 0) {
|
||||
if (regex_uri.indexIn(auth) < 0) {
|
||||
qDebug("AUTH-PROB: Missing uri");
|
||||
return false;
|
||||
}
|
||||
@@ -282,7 +282,7 @@ bool HttpServer::isAuthorized(const QByteArray& auth,
|
||||
//qDebug("prop uri is: %s", prop_uri.data());
|
||||
// get response
|
||||
QRegExp regex_response(".*response=[\"]?([\\w=]+)[\"]?.*");
|
||||
if(regex_response.indexIn(auth) < 0) {
|
||||
if (regex_response.indexIn(auth) < 0) {
|
||||
qDebug("AUTH-PROB: Missing response");
|
||||
return false;
|
||||
}
|
||||
@@ -293,25 +293,25 @@ bool HttpServer::isAuthorized(const QByteArray& auth,
|
||||
md5_ha2.addData(method.toLocal8Bit() + ":" + prop_uri);
|
||||
QByteArray ha2 = md5_ha2.result().toHex();
|
||||
QByteArray response = "";
|
||||
if(auth.contains("qop=")) {
|
||||
if (auth.contains("qop=")) {
|
||||
QCryptographicHash md5_ha(QCryptographicHash::Md5);
|
||||
// Get nc
|
||||
QRegExp regex_nc(".*nc=[\"]?([\\w=]+)[\"]?.*");
|
||||
if(regex_nc.indexIn(auth) < 0) {
|
||||
if (regex_nc.indexIn(auth) < 0) {
|
||||
qDebug("AUTH-PROB: qop but missing nc");
|
||||
return false;
|
||||
}
|
||||
QByteArray prop_nc = regex_nc.cap(1).toLocal8Bit();
|
||||
//qDebug("prop nc is: %s", prop_nc.data());
|
||||
QRegExp regex_cnonce(".*cnonce=[\"]?([\\w=]+)[\"]?.*");
|
||||
if(regex_cnonce.indexIn(auth) < 0) {
|
||||
if (regex_cnonce.indexIn(auth) < 0) {
|
||||
qDebug("AUTH-PROB: qop but missing cnonce");
|
||||
return false;
|
||||
}
|
||||
QByteArray prop_cnonce = regex_cnonce.cap(1).toLocal8Bit();
|
||||
//qDebug("prop cnonce is: %s", prop_cnonce.data());
|
||||
QRegExp regex_qop(".*qop=[\"]?(\\w+)[\"]?.*");
|
||||
if(regex_qop.indexIn(auth) < 0) {
|
||||
if (regex_qop.indexIn(auth) < 0) {
|
||||
qDebug("AUTH-PROB: missing qop");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace json {
|
||||
case QVariant::StringList:
|
||||
case QVariant::List: {
|
||||
QStringList strList;
|
||||
foreach(const QVariant &var, v.toList()) {
|
||||
foreach (const QVariant &var, v.toList()) {
|
||||
strList << toJson(var);
|
||||
}
|
||||
return "["+strList.join(",")+"]";
|
||||
@@ -59,7 +59,7 @@ namespace json {
|
||||
case QVariant::String: {
|
||||
QString s = v.value<QString>();
|
||||
QString result = "\"";
|
||||
for(int i=0; i<s.size(); ++i) {
|
||||
for (int i=0; i<s.size(); ++i) {
|
||||
const QChar ch = s[i];
|
||||
switch(ch.toAscii())
|
||||
{
|
||||
@@ -109,39 +109,39 @@ namespace json {
|
||||
QVariantMap fromJson(const QString& json) {
|
||||
qDebug("JSON is %s", qPrintable(json));
|
||||
QVariantMap m;
|
||||
if(json.startsWith("{") && json.endsWith("}")) {
|
||||
if (json.startsWith("{") && json.endsWith("}")) {
|
||||
QStringList couples;
|
||||
QString tmp = "";
|
||||
bool in_list = false;
|
||||
foreach(const QChar &c, json.mid(1, json.length()-2)) {
|
||||
if(c == ',' && !in_list) {
|
||||
foreach (const QChar &c, json.mid(1, json.length()-2)) {
|
||||
if (c == ',' && !in_list) {
|
||||
couples << tmp;
|
||||
tmp = "";
|
||||
} else {
|
||||
if(c == '[')
|
||||
if (c == '[')
|
||||
in_list = true;
|
||||
else if(c == ']')
|
||||
else if (c == ']')
|
||||
in_list = false;
|
||||
tmp += c;
|
||||
}
|
||||
}
|
||||
if(!tmp.isEmpty()) couples << tmp;
|
||||
if (!tmp.isEmpty()) couples << tmp;
|
||||
|
||||
foreach(const QString &couple, couples) {
|
||||
foreach (const QString &couple, couples) {
|
||||
QStringList parts = couple.split(":");
|
||||
if(parts.size() != 2) continue;
|
||||
if (parts.size() != 2) continue;
|
||||
QString key = parts.first();
|
||||
if(key.startsWith("\"") && key.endsWith("\"")) {
|
||||
if (key.startsWith("\"") && key.endsWith("\"")) {
|
||||
key = key.mid(1, key.length()-2);
|
||||
}
|
||||
QString value_str = parts.last();
|
||||
QVariant value;
|
||||
if(value_str.startsWith("[") && value_str.endsWith("]")) {
|
||||
if (value_str.startsWith("[") && value_str.endsWith("]")) {
|
||||
value_str = value_str.mid(1, value_str.length()-2);
|
||||
QStringList list_elems = value_str.split(",", QString::SkipEmptyParts);
|
||||
QVariantList varlist;
|
||||
foreach(const QString &list_val, list_elems) {
|
||||
if(list_val.startsWith("\"") && list_val.endsWith("\"")) {
|
||||
foreach (const QString &list_val, list_elems) {
|
||||
if (list_val.startsWith("\"") && list_val.endsWith("\"")) {
|
||||
varlist << list_val.mid(1, list_val.length()-2).replace("\\n", "\n");
|
||||
} else {
|
||||
varlist << list_val.toInt();
|
||||
@@ -149,7 +149,7 @@ namespace json {
|
||||
}
|
||||
value = varlist;
|
||||
} else {
|
||||
if(value_str.startsWith("\"") && value_str.endsWith("\"")) {
|
||||
if (value_str.startsWith("\"") && value_str.endsWith("\"")) {
|
||||
value_str = value_str.mid(1, value_str.length()-2).replace("\\n", "\n");
|
||||
value = value_str;
|
||||
} else {
|
||||
@@ -170,10 +170,10 @@ namespace json {
|
||||
|
||||
QString toJson(const QList<QVariantMap>& v) {
|
||||
QStringList res;
|
||||
foreach(QVariantMap m, v) {
|
||||
foreach (QVariantMap m, v) {
|
||||
QStringList vlist;
|
||||
QVariantMap::ConstIterator it;
|
||||
for(it = m.constBegin(); it != m.constEnd(); it++) {
|
||||
for (it = m.constBegin(); it != m.constEnd(); it++) {
|
||||
vlist << toJson(it.key())+":"+toJson(it.value());
|
||||
}
|
||||
res << "{"+vlist.join(",")+"}";
|
||||
|
||||
Reference in New Issue
Block a user