From a8766058f325d727261b4e76e12b15fbc4a18eb6 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Wed, 26 Nov 2014 01:10:40 +0200 Subject: [PATCH] Use parse_magnet_uri() where possible. --- src/misc.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 236188729..d974f4c13 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -382,29 +382,27 @@ QString misc::bcLinkToMagnet(QString bc_link) QString misc::magnetUriToName(const QString& magnet_uri) { - QString name = ""; - QRegExp regHex("dn=([^&]+)"); - const int pos = regHex.indexIn(magnet_uri); - if (pos > -1) { - const QString found = regHex.cap(1); - // URL decode - name = QUrl::fromPercentEncoding(found.toLocal8Bit()).replace("+", " "); - } - return name; + add_torrent_params p; + error_code ec; + parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec); + + if (ec) + return QString::null; + return toQStringU(p.name); } QList misc::magnetUriToTrackers(const QString& magnet_uri) { QList trackers; - QRegExp rx("tr=([^&]+)"); - int pos = 0; - - while ((pos = rx.indexIn(magnet_uri, pos)) != -1) { - const QUrl tracker = QUrl::fromEncoded(rx.cap(1).toUtf8()); - qDebug() << Q_FUNC_INFO << "Found tracker: " << tracker.toString(); - trackers << tracker; - pos += rx.matchedLength(); - } + add_torrent_params p; + error_code ec; + parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec); + + if (ec) + return trackers; + + for (std::vector::const_iterator i = p.trackers.begin(), e = p.trackers.end(); i != e; ++i) + trackers.push_back(QUrl(toQStringU(*i))); return trackers; }