diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-06-13 23:17:06 -0700 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-06-13 23:17:06 -0700 |
commit | 64d46e7c6af724a6e4fa5719fb74a0f76def02e2 (patch) | |
tree | 5b26eebcf25445eb710904f15e42cef689b394d8 /src | |
parent | 0f10b21719e1b0d9683a142f0a7105e65f095694 (diff) | |
parent | 93b7af309904e68d8b7b2f6bdd2b9bcfb18f9e24 (diff) |
Merge pull request #1002 from Diapolo/URL-handling_2
URI-handling code update: added safety checks and notifications
Diffstat (limited to 'src')
-rw-r--r-- | src/qt/bitcoingui.cpp | 23 | ||||
-rw-r--r-- | src/qt/guiutil.cpp | 23 | ||||
-rw-r--r-- | src/qt/sendcoinsdialog.cpp | 12 | ||||
-rw-r--r-- | src/qt/sendcoinsdialog.h | 2 |
4 files changed, 39 insertions, 21 deletions
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index e15bc6690a..c143411c76 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -744,12 +744,19 @@ void BitcoinGUI::dropEvent(QDropEvent *event) { if(event->mimeData()->hasUrls()) { - gotoSendCoinsPage(); + int nValidUrisFound = 0; QList<QUrl> uris = event->mimeData()->urls(); foreach(const QUrl &uri, uris) { - sendCoinsPage->handleURI(uri.toString()); + if (sendCoinsPage->handleURI(uri.toString())) + nValidUrisFound++; } + + // if valid URIs were found + if (nValidUrisFound) + gotoSendCoinsPage(); + else + notificator->notify(Notificator::Warning, tr("URI handling"), tr("URI can not be parsed! This can be caused by an invalid Bitcoin address or malformed URI parameters.")); } event->acceptProposedAction(); @@ -757,10 +764,14 @@ void BitcoinGUI::dropEvent(QDropEvent *event) void BitcoinGUI::handleURI(QString strURI) { - gotoSendCoinsPage(); - sendCoinsPage->handleURI(strURI); - - showNormalIfMinimized(); + // URI has to be valid + if (sendCoinsPage->handleURI(strURI)) + { + showNormalIfMinimized(); + gotoSendCoinsPage(); + } + else + notificator->notify(Notificator::Warning, tr("URI handling"), tr("URI can not be parsed! This can be caused by an invalid Bitcoin address or malformed URI parameters.")); } void BitcoinGUI::setEncryptionStatus(int status) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 5dedc90d69..a8c2328853 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -4,6 +4,7 @@ #include "bitcoinunits.h" #include "util.h" #include "init.h" +#include "base58.h" #include <QString> #include <QDateTime> @@ -80,6 +81,11 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) if(uri.scheme() != QString("bitcoin")) return false; + // check if the address is valid + CBitcoinAddress addressFromUri(uri.path().toStdString()); + if (!addressFromUri.IsValid()) + return false; + SendCoinsRecipient rv; rv.address = uri.path(); rv.amount = 0; @@ -222,19 +228,18 @@ Qt::ConnectionType blockingGUIThreadConnection() bool checkPoint(const QPoint &p, const QWidget *w) { - QWidget *atW = qApp->widgetAt(w->mapToGlobal(p)); - if(!atW) return false; - return atW->topLevelWidget() == w; + QWidget *atW = qApp->widgetAt(w->mapToGlobal(p)); + if (!atW) return false; + return atW->topLevelWidget() == w; } bool isObscured(QWidget *w) { - - return !(checkPoint(QPoint(0, 0), w) - && checkPoint(QPoint(w->width() - 1, 0), w) - && checkPoint(QPoint(0, w->height() - 1), w) - && checkPoint(QPoint(w->width() - 1, w->height() - 1), w) - && checkPoint(QPoint(w->width()/2, w->height()/2), w)); + return !(checkPoint(QPoint(0, 0), w) + && checkPoint(QPoint(w->width() - 1, 0), w) + && checkPoint(QPoint(0, w->height() - 1), w) + && checkPoint(QPoint(w->width() - 1, w->height() - 1), w) + && checkPoint(QPoint(w->width() / 2, w->height() / 2), w)); } void openDebugLogfile() diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 2eb228d1d4..76952e44ec 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -266,15 +266,17 @@ void SendCoinsDialog::pasteEntry(const SendCoinsRecipient &rv) entry->setValue(rv); } - -void SendCoinsDialog::handleURI(const QString &uri) +bool SendCoinsDialog::handleURI(const QString &uri) { SendCoinsRecipient rv; - if(!GUIUtil::parseBitcoinURI(uri, &rv)) + // URI has to be valid + if (GUIUtil::parseBitcoinURI(uri, &rv)) { - return; + pasteEntry(rv); + return true; } - pasteEntry(rv); + + return false; } void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance) diff --git a/src/qt/sendcoinsdialog.h b/src/qt/sendcoinsdialog.h index 358c8cf85f..915b7ad465 100644 --- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -30,7 +30,7 @@ public: QWidget *setupTabChain(QWidget *prev); void pasteEntry(const SendCoinsRecipient &rv); - void handleURI(const QString &uri); + bool handleURI(const QString &uri); public slots: void clear(); |