[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/ioslaves/kio_magnet
From: Christian Weilbach <christian () whiletaker ! homeip ! net>
Date: 2010-10-24 0:35:02
Message-ID: 20101024003502.9FD6DAC897 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1189089 by weilbach:
Work towards different whitelist by torrent file address, needs to be designed better \
though. Adjustments to recent KTorrent fixes, e.g. pt for path parameter instead of \
"fl". Fixes.
M +52 -57 ktorrentdbusinterface.cpp
M +4 -1 ktorrentdbusinterface.h
M +2 -15 magnetsettings.kcfg
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.cpp #1189088:1189089
@@ -34,6 +34,9 @@
#include <KUrl>
#include <kdebug.h>
#include <kmessagebox.h>
+#include <KMimeType>
+#include <kio/jobclasses.h>
+#include <kio/job.h>
const int timeout = 5000;
const int repeat = 6;
@@ -134,15 +137,15 @@
i18n("Could not get the group list, do you have a compatible \
KTorrent version running?")); return;
} else {
- if (!groupList.value().contains("Web Share")) {
- m_coreInt->addGroup("Web Share");
- org::ktorrent::group groupInt("org.ktorrent.ktorrent", "/group/Web \
Share", bus ); + if (!groupList.value().contains("MagnetShare")) {
+ m_coreInt->addGroup("MagnetShare");
+ org::ktorrent::group groupInt("org.ktorrent.ktorrent", \
"/group/MagnetShare", bus ); KStandardDirs *dirs = new KStandardDirs();
- groupInt.setDefaultSaveLocation(dirs->saveLocation("data","kio_torrent/"));
+ groupInt.setDefaultSaveLocation(dirs->saveLocation("data","kio_magnet/"));
groupInt.setMaxShareRatio(MagnetSettings::maxShareRatio());
delete dirs;
} else {
- org::ktorrent::group groupInt("org.ktorrent.ktorrent", "/group/Web \
Share", bus ); + org::ktorrent::group groupInt("org.ktorrent.ktorrent", \
"/group/MagnetShare", bus ); // respect changes inside KTorrent
if(groupInt.maxShareRatio().isValid())
MagnetSettings::setMaxShareRatio(groupInt.maxShareRatio());
@@ -163,54 +166,21 @@
{
kDebug() << u.url() << " Thread: " << thread();
m_mutex.lock();
- KUrl url = u;
+ m_url = u;
- // TODO merge this properly in KTorrents magnet support
- QString xt = url.queryItemValue("xt");
- QStringList args = xt.split(":");
-
- int aSize = args.size();
- int btihIndex = args.indexOf("btih");
- if ( btihIndex==-1 || aSize==btihIndex ) {
- QString msg = i18n("This magnet-link is <b>not supported</b>. \
- Torrent support is necessary at the moment, so you need to have at least a \
btih:HASHVALUE \
- in the xt-parameter. Try to copy and paste the link into a supported \
application.");
- m_slave->error(KIO::ERR_ABORTED,msg);
- m_slave->finish();
+ QString xt = m_url.queryItem("xt");
+ m_tor = xt.remove("urn:btih:");
+ if (m_tor.isEmpty()) {
+ m_slave->error(KIO::ERR_ABORTED, i18n("The link for %1 does not contain the \
required btih hash-parameter.").arg(u.url())); m_mutex.unlock();
return;
}
- m_tor = args[btihIndex+1].toLower();
- int flidIndex = args.indexOf("flid");
- m_file = ( flidIndex!=-1 && aSize>flidIndex ) ? args[flidIndex+1].toUInt() : -1;
-
- int licIndex = args.indexOf("lic");
- m_lic = (licIndex!=-1 && aSize>licIndex ) ? args[licIndex+1] : "unkown";
- if ( !MagnetSettings::allowedLicenses().contains(m_lic) ) {
- if (MagnetSettings::recheckUnknownLicense()) {
- if ( m_slave->messageBox(KIO::SlaveBase::WarningYesNo,
- i18n("The magnet-link for \"%1\" has the \
license \"%2\". When you proceed you might break the\
- law of your country, as you start distributing \
the file yourself.\
- Would you like to \
continue?").arg(url.queryItemValue("dn")).arg(m_lic),
- i18n("License issue")) != KMessageBox::Yes ) {
- kDebug()<<"license rejected.";
- m_slave->close();
- }
- } else {
- m_slave->error(KIO::ERR_ABORTED,i18n("The license\"%1\" is not enabled.\
- You can reconfigure the licenses at \
- settings:/network-and-connectivity/sharing") // \
TODO fix link
- .arg(m_lic));
- m_mutex.unlock();
- return;
- }
- }
-
m_torrentInt = new org::ktorrent::torrent("org.ktorrent.ktorrent", \
"/torrent/"+m_tor, QDBusConnection::sessionBus());
QDBusReply<QString>name = m_torrentInt->name();
if (name.isValid()) {
+ findFile();
kDebug() << "Torrent " + name.value() + "("+ m_tor + ") already loaded in \
KTorrent."; if (m_file==-1&&m_torrentInt->bytesLeftToDownload()==0) {
m_slave->setPath(m_torrentInt->pathOnDisk());
@@ -226,23 +196,47 @@
m_slave->finish();
} else {
- QString u;
- if (!url.host().isEmpty()&&!url.path().isEmpty()&&url.host()!="localhost") { \
// assume the http link works
- u = url.url().split("?")[0].replace("magnet:","http:");
+ m_torrentUrl = m_url.queryItem("to");
+ KUrl source( m_torrentUrl );
+ if (!MagnetSettings::trustedHosts().contains(source.host())) {
+ if ( m_slave->messageBox(KIO::SlaveBase::WarningYesNo,
+ i18n("The host \"%1\" is not known yet. Do you \
want to trust its shared sources?") + \
.arg(source.host()), + i18n("Host not known")) != \
KMessageBox::Yes ) { + kDebug()<<"host rejected.";
+ m_slave->error(KIO::ERR_ABORTED,i18n("Host rejected."));
+ m_mutex.unlock();
+ return;
} else {
- u = "magnet:?" + url.url().split("?")[1];
- if ( m_file != -1)
- u.remove(QString(":flid:%1").arg(m_file));
- u.remove(QString(":lic:"+m_lic));
+ QStringList hosts = MagnetSettings::trustedHosts();
+ hosts << source.host();
+ MagnetSettings::setTrustedHosts(hosts);
}
-
- kDebug() << "Load torrent in KTorrent: " << u;
- m_coreInt->loadSilently(u, "Web Share");
- m_coreInt->stop(m_tor);
}
+ m_coreInt->loadSilently(m_url.url(),"MagnetShare");
+ }
+
m_mutex.unlock();
}
+void KTorrentDBusInterface::findFile()
+{
+ kDebug();
+ Q_ASSERT(m_torrentInt->isValid());
+
+ QStringList files;
+ for (int i=0; i<m_torrentInt->numFiles(); i++) {
+ files << m_torrentInt->filePath(i);
+ }
+
+ if (files.isEmpty()) {
+ m_file=-1;
+ } else {
+ m_file=files.indexOf(m_url.queryItemValue("pt"));
+ kDebug() << "file: " << m_url.queryItemValue("pt") << "id: " << m_file;
+ }
+}
+
void KTorrentDBusInterface::cleanup()
{
kDebug();
@@ -276,8 +270,8 @@
}
delete torrentInt;
}
- // TODO add ktorrent plugin/support to allow sane total size management?
- // this only removes torrents when we run out of space, starting with the most \
shared ones + // TODO add ktorrent plugin/support to allow sane group size \
management? + // this only removes torrents when we run out of configured space, \
starting with the most shared ones
if (totalSize>MagnetSettings::shareSize()*1024*1024&&m_torrentInt->isValid()) {
totalSize+=m_file!=-1 ? m_torrentInt->fileSize(m_file) : \
m_torrentInt->totalSize();
@@ -336,6 +330,7 @@
MagnetSettings::self()->writeConfig();
cleanup();
+ findFile();
QDBusReply<uint>numFiles = m_torrentInt->numFiles();
int n = numFiles.value();
--- trunk/playground/ioslaves/kio_magnet/ktorrentdbusinterface.h #1189088:1189089
@@ -27,6 +27,8 @@
#include <QtDBus/QDBusConnection>
#include <KUrl>
#include <KProcess>
+#include <kio/authinfo.h>
+#include <kio/jobclasses.h>
class MagnetProtocol;
class DBusThread;
@@ -51,6 +53,7 @@
private:
void initDBus();
void setupDBus();
+ void findFile();
org::ktorrent::core* m_coreInt;
org::ktorrent::torrent* m_torrentInt;
KProcess* m_process;
@@ -59,7 +62,7 @@
QMutex m_mutex;
QThread* m_thread;
MagnetProtocol* m_slave;
- QString m_tor, m_lic;
+ QString m_tor, m_lic, m_torrentUrl;
int m_file, m_passedTime;
qulonglong m_fileSize;
};
--- trunk/playground/ioslaves/kio_magnet/magnetsettings.kcfg #1189088:1189089
@@ -14,22 +14,9 @@
<label>Total maximum size used by the share in MiB.</label>
<default>5120</default>
</entry>
- <entry name="AllowedLicenses" type="StringList">
- <label>List of all licenses accepted on loading</label>
- <default>fairuse,publicdomain,bsd,gpl2,gpl3,lgpl2,lgpl3,gfdl,ccsa</default>
+ <entry name="TrustedHosts" type="StringList">
+ <label>List of hosts which are directly accepted on loading</label>
</entry>
- <entry name="RecheckUnknownLicense" type="Bool">
- <label>Ask on unkown licenses.</label>
- <default>true</default>
- </entry>
- <entry name="UploadSpeed" type="Int">
- <label>Upload speed of the share.</label>
- <default>0</default>
- </entry>
- <entry name="DownloadSpeed" type="Int">
- <label>Download speed of the share.</label>
- <default>0</default>
- </entry>
<entry name="ManagedTorrents" type="StringList">
<label>Torrents inside KTorrent which are managed by this modules.</label>
</entry>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic