From b541c9fa4c3a707f5dc310079e5821ec0785e7e9 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 13 Dec 2009 09:52:28 +0000 Subject: [PATCH] - Added Hex Magnet Link support (new standard, used for example by ThePirateBay) --- Changelog | 1 + src/misc.h | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index fc841a8ab..fdf971ef4 100644 --- a/Changelog +++ b/Changelog @@ -5,6 +5,7 @@ - BUGFIX: ~/qBT_dir is created only when it is actually used - BUGFIX: Fix possible missing slot message (toggleSelectedTorrentsSuperSeeding) - BUGFIX: Fix possible crash in torrent properties (files) + - BUGFIX: Added Hex Magnet Links support (Thanks Haypo) * Thu Dec 10 2009 - Christophe Dumez - v2.0.0 - FEATURE: Added program option to disable splash screen diff --git a/src/misc.h b/src/misc.h index 37a3f33f6..4c1fde600 100644 --- a/src/misc.h +++ b/src/misc.h @@ -266,14 +266,30 @@ public: static QString magnetUriToHash(QString magnet_uri) { QString hash = ""; - QRegExp reg("urn:btih:([A-Z2-7=]+)"); - int pos = reg.indexIn(magnet_uri); + QRegExp regHex("urn:btih:([0-9A-Za-z]+)"); + // Hex + int pos = regHex.indexIn(magnet_uri); if(pos > -1) { - sha1_hash sha1; - sha1.assign(base32decode(reg.cap(1).toStdString())); - hash = misc::toQString(sha1); + QString found = regHex.cap(1); + if(found.length() == 40) { + sha1_hash sha1; + sha1.assign(QString(QByteArray::fromHex(regHex.cap(1).toLocal8Bit())).toStdString()); + qDebug("magnetUriToHash (Hex): hash: %s", misc::toString(sha1).c_str()); + return misc::toQString(sha1); + } } - qDebug("magnetUriToHash: hash: %s", hash.toLocal8Bit().data()); + // Base 32 + QRegExp regBase32("urn:btih:([A-Za-z2-7=]+)"); + pos = regBase32.indexIn(magnet_uri); + if(pos > -1) { + QString found = regBase32.cap(1); + if(found.length() > 20) { + sha1_hash sha1; + sha1.assign(base32decode(regBase32.cap(1).toStdString())); + hash = misc::toQString(sha1); + } + } + qDebug("magnetUriToHash (base32): hash: %s", hash.toLocal8Bit().data()); return hash; }