Mercurial > hg > bitcoin
changeset 2882:b9d44c87c27b draft
Bugfix: Replace "URL" with "URI" where we aren't actually working with URLs
author | Luke Dashjr <luke-jr+git@utopios.org> |
---|---|
date | Sun, 25 Mar 2012 17:25:10 -0400 |
parents | c5b81cf9ed1f |
children | e669d74eef2a |
files | bitcoin-qt.pro src/qt/bitcoin.cpp src/qt/bitcoingui.cpp src/qt/bitcoingui.h src/qt/guiutil.cpp src/qt/guiutil.h src/qt/qtipcserver.cpp src/qt/qtipcserver.h src/qt/sendcoinsdialog.cpp src/qt/sendcoinsdialog.h src/qt/test/test_main.cpp src/qt/test/uritests.cpp src/qt/test/uritests.h src/qt/test/urltests.cpp src/qt/test/urltests.h src/qtui.h |
diffstat | 16 files changed, 134 insertions(+), 131 deletions(-) [+] |
line wrap: on
line diff
--- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -231,8 +231,8 @@ contains(BITCOIN_QT_TEST, 1) { SOURCES += src/qt/test/test_main.cpp \ - src/qt/test/urltests.cpp -HEADERS += src/qt/test/urltests.h + src/qt/test/uritests.cpp +HEADERS += src/qt/test/uritests.h DEPENDPATH += src/qt/test QT += testlib TARGET = bitcoin-qt_test
--- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -81,7 +81,7 @@ return payFee; } -void ThreadSafeHandleURL(const std::string& strURL) +void ThreadSafeHandleURI(const std::string& strURI) { if(!guiref) return; @@ -93,8 +93,8 @@ { connectionType = Qt::BlockingQueuedConnection; } - QMetaObject::invokeMethod(guiref, "handleURL", connectionType, - Q_ARG(QString, QString::fromStdString(strURL))); + QMetaObject::invokeMethod(guiref, "handleURI", connectionType, + Q_ARG(QString, QString::fromStdString(strURI))); } void CalledSetStatusBar(const std::string& strText, int nField) @@ -141,10 +141,10 @@ { if (strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0) { - const char *strURL = argv[i]; + const char *strURI = argv[i]; try { - boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); - if(mq.try_send(strURL, strlen(strURL), 0)) + boost::interprocess::message_queue mq(boost::interprocess::open_only, BITCOINURI_QUEUE_NAME); + if(mq.try_send(strURI, strlen(strURI), 0)) exit(0); else break; @@ -254,21 +254,21 @@ window.show(); } - // Place this here as guiref has to be defined if we dont want to lose URLs + // Place this here as guiref has to be defined if we dont want to lose URIs ipcInit(); #if !defined(MAC_OSX) && !defined(WIN32) // TODO: implement qtipcserver.cpp for Mac and Windows - // Check for URL in argv + // Check for URI in argv for (int i = 1; i < argc; i++) { if (strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0) { - const char *strURL = argv[i]; + const char *strURI = argv[i]; try { - boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); - mq.try_send(strURL, strlen(strURL), 0); + boost::interprocess::message_queue mq(boost::interprocess::open_only, BITCOINURI_QUEUE_NAME); + mq.try_send(strURI, strlen(strURI), 0); } catch (boost::interprocess::interprocess_exception &ex) { }
--- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -714,7 +714,7 @@ void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event) { - // Accept only URLs + // Accept only URIs if(event->mimeData()->hasUrls()) event->acceptProposedAction(); } @@ -724,20 +724,20 @@ if(event->mimeData()->hasUrls()) { gotoSendCoinsPage(); - QList<QUrl> urls = event->mimeData()->urls(); - foreach(const QUrl &url, urls) + QList<QUrl> uris = event->mimeData()->urls(); + foreach(const QUrl &uri, uris) { - sendCoinsPage->handleURL(url.toString()); + sendCoinsPage->handleURI(uri.toString()); } } event->acceptProposedAction(); } -void BitcoinGUI::handleURL(QString strURL) +void BitcoinGUI::handleURI(QString strURI) { gotoSendCoinsPage(); - sendCoinsPage->handleURL(strURL); + sendCoinsPage->handleURI(strURI); if(!isActiveWindow()) activateWindow();
--- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -127,7 +127,7 @@ @param[out] payFee true to pay the fee, false to not pay the fee */ void askFee(qint64 nFeeRequired, bool *payFee); - void handleURL(QString strURL); + void handleURI(QString strURI); void gotoMessagePage(); void gotoMessagePage(QString);
--- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -51,15 +51,15 @@ widget->setAlignment(Qt::AlignRight|Qt::AlignVCenter); } -bool GUIUtil::parseBitcoinURL(const QUrl &url, SendCoinsRecipient *out) +bool GUIUtil::parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) { - if(url.scheme() != QString("bitcoin")) + if(uri.scheme() != QString("bitcoin")) return false; SendCoinsRecipient rv; - rv.address = url.path(); + rv.address = uri.path(); rv.amount = 0; - QList<QPair<QString, QString> > items = url.queryItems(); + QList<QPair<QString, QString> > items = uri.queryItems(); for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++) { bool fShouldReturnFalse = false; @@ -96,18 +96,18 @@ return true; } -bool GUIUtil::parseBitcoinURL(QString url, SendCoinsRecipient *out) +bool GUIUtil::parseBitcoinURI(QString uri, SendCoinsRecipient *out) { // Convert bitcoin:// to bitcoin: // // Cannot handle this later, because bitcoin:// will cause Qt to see the part after // as host, // which will lowercase it (and thus invalidate the address). - if(url.startsWith("bitcoin://")) + if(uri.startsWith("bitcoin://")) { - url.replace(0, 10, "bitcoin:"); + uri.replace(0, 10, "bitcoin:"); } - QUrl urlInstance(url); - return parseBitcoinURL(urlInstance, out); + QUrl uriInstance(uri); + return parseBitcoinURI(uriInstance, out); } QString GUIUtil::HtmlEscape(const QString& str, bool fMultiLine)
--- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -29,10 +29,10 @@ static void setupAddressWidget(QLineEdit *widget, QWidget *parent); static void setupAmountWidget(QLineEdit *widget, QWidget *parent); - // Parse "bitcoin:" URL into recipient object, return true on succesful parsing - // See Bitcoin URL definition discussion here: https://bitcointalk.org/index.php?topic=33490.0 - static bool parseBitcoinURL(const QUrl &url, SendCoinsRecipient *out); - static bool parseBitcoinURL(QString url, SendCoinsRecipient *out); + // Parse "bitcoin:" URI into recipient object, return true on succesful parsing + // See Bitcoin URI definition discussion here: https://bitcointalk.org/index.php?topic=33490.0 + static bool parseBitcoinURI(const QUrl &, SendCoinsRecipient *out); + static bool parseBitcoinURI(QString uri, SendCoinsRecipient *out); // HTML escaping for rich text controls static QString HtmlEscape(const QString& str, bool fMultiLine=false);
--- a/src/qt/qtipcserver.cpp +++ b/src/qt/qtipcserver.cpp @@ -8,6 +8,7 @@ #include <boost/date_time/posix_time/posix_time.hpp> #include "headers.h" +#include "qtipcserver.h" using namespace boost::interprocess; using namespace boost::posix_time; @@ -16,7 +17,7 @@ void ipcShutdown() { - message_queue::remove("BitcoinURL"); + message_queue::remove(BITCOINURI_QUEUE_NAME); } void ipcThread(void* parg) @@ -30,7 +31,7 @@ ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(100); if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d)) { - ThreadSafeHandleURL(std::string(strBuf, nSize)); + ThreadSafeHandleURI(std::string(strBuf, nSize)); Sleep(1000); } if (fShutdown) @@ -60,7 +61,7 @@ size_t nSize; unsigned int nPriority; try { - mq = new message_queue(open_or_create, "BitcoinURL", 2, 256); + mq = new message_queue(open_or_create, BITCOINURI_QUEUE_NAME, 2, 256); // Make sure we don't lose any bitcoin: URIs for (int i = 0; i < 2; i++) @@ -68,15 +69,15 @@ ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(1); if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d)) { - ThreadSafeHandleURL(std::string(strBuf, nSize)); + ThreadSafeHandleURI(std::string(strBuf, nSize)); } else break; } // Make sure only one bitcoin instance is listening - message_queue::remove("BitcoinURL"); - mq = new message_queue(open_or_create, "BitcoinURL", 2, 256); + message_queue::remove(BITCOINURI_QUEUE_NAME); + mq = new message_queue(open_or_create, BITCOINURI_QUEUE_NAME, 2, 256); } catch (interprocess_exception &ex) { return;
--- a/src/qt/qtipcserver.h +++ b/src/qt/qtipcserver.h @@ -1,2 +1,4 @@ +#define BITCOINURI_QUEUE_NAME "BitcoinURI" + void ipcInit(); void ipcShutdown();
--- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -265,10 +265,10 @@ } -void SendCoinsDialog::handleURL(const QString &url) +void SendCoinsDialog::handleURI(const QString &uri) { SendCoinsRecipient rv; - if(!GUIUtil::parseBitcoinURL(url, &rv)) + if(!GUIUtil::parseBitcoinURI(uri, &rv)) { return; }
--- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -30,7 +30,7 @@ QWidget *setupTabChain(QWidget *prev); void pasteEntry(const SendCoinsRecipient &rv); - void handleURL(const QString &url); + void handleURI(const QString &uri); public slots: void clear();
--- a/src/qt/test/test_main.cpp +++ b/src/qt/test/test_main.cpp @@ -1,11 +1,11 @@ #include <QTest> #include <QObject> -#include "urltests.h" +#include "uritests.h" // This is all you need to run all the tests int main(int argc, char *argv[]) { - URLTests test1; + URITests test1; QTest::qExec(&test1); }
new file mode 100644 --- /dev/null +++ b/src/qt/test/uritests.cpp @@ -0,0 +1,71 @@ +#include "uritests.h" +#include "../guiutil.h" +#include "../walletmodel.h" + +#include <QUrl> + +/* +struct SendCoinsRecipient +{ + QString address; + QString label; + qint64 amount; +}; +*/ + +void URITests::uriTests() +{ + SendCoinsRecipient rv; + QUrl uri; + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist=")); + QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); + + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist=")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + QVERIFY(rv.amount == 0); + + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString("Wikipedia Example Address")); + QVERIFY(rv.amount == 0); + + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + QVERIFY(rv.amount == 100000); + + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + QVERIFY(rv.amount == 100100000); + + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.amount == 10000000000); + QVERIFY(rv.label == QString("Wikipedia Example")); + + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + + QVERIFY(GUIUtil::parseBitcoinURI("bitcoin://175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address", &rv)); + QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); + QVERIFY(rv.label == QString()); + + // We currently dont implement the message paramenter (ok, yea, we break spec...) + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address")); + QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); + + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example")); + QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); + + uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example")); + QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); +}
new file mode 100644 --- /dev/null +++ b/src/qt/test/uritests.h @@ -0,0 +1,15 @@ +#ifndef URITESTS_H +#define URITESTS_H + +#include <QTest> +#include <QObject> + +class URITests : public QObject +{ + Q_OBJECT + +private slots: + void uriTests(); +}; + +#endif // URITESTS_H
deleted file mode 100644 --- a/src/qt/test/urltests.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "urltests.h" -#include "../guiutil.h" -#include "../walletmodel.h" - -#include <QUrl> - -/* -struct SendCoinsRecipient -{ - QString address; - QString label; - qint64 amount; -}; -*/ - -void URLTests::urlTests() -{ - SendCoinsRecipient rv; - QUrl url; - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist=")); - QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv)); - - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist=")); - QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); - QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); - QVERIFY(rv.label == QString()); - QVERIFY(rv.amount == 0); - - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address")); - QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); - QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); - QVERIFY(rv.label == QString("Wikipedia Example Address")); - QVERIFY(rv.amount == 0); - - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001")); - QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); - QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); - QVERIFY(rv.label == QString()); - QVERIFY(rv.amount == 100000); - - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001")); - QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); - QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); - QVERIFY(rv.label == QString()); - QVERIFY(rv.amount == 100100000); - - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example")); - QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); - QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); - QVERIFY(rv.amount == 10000000000); - QVERIFY(rv.label == QString("Wikipedia Example")); - - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address")); - QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); - QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); - QVERIFY(rv.label == QString()); - - QVERIFY(GUIUtil::parseBitcoinURL("bitcoin://175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address", &rv)); - QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); - QVERIFY(rv.label == QString()); - - // We currently dont implement the message paramenter (ok, yea, we break spec...) - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address")); - QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv)); - - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example")); - QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv)); - - url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example")); - QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv)); -}
deleted file mode 100644 --- a/src/qt/test/urltests.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef URLTESTS_H -#define URLTESTS_H - -#include <QTest> -#include <QObject> - -class URLTests : public QObject -{ - Q_OBJECT - -private slots: - void urlTests(); -}; - -#endif // URLTESTS_H
--- a/src/qtui.h +++ b/src/qtui.h @@ -42,7 +42,7 @@ #define wxMessageBox MyMessageBox extern int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1); extern bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption, wxWindow* parent); -extern void ThreadSafeHandleURL(const std::string& strURL); +extern void ThreadSafeHandleURI(const std::string& strURI); extern void CalledSetStatusBar(const std::string& strText, int nField); extern void UIThreadCall(boost::function0<void> fn); extern void MainFrameRepaint();