Commit fa2544e7 authored by Luke Dashjr's avatar Luke Dashjr

Bugfix: Replace "URL" with "URI" where we aren't actually working with URLs

parent 9362da78
......@@ -225,8 +225,8 @@ FORMS += src/qt/forms/qrcodedialog.ui
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
......
......@@ -74,13 +74,13 @@ bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption)
return payFee;
}
void ThreadSafeHandleURL(const std::string& strURL)
void ThreadSafeHandleURI(const std::string& strURI)
{
if(!guiref)
return;
QMetaObject::invokeMethod(guiref, "handleURL", GUIUtil::blockingGUIThreadConnection(),
Q_ARG(QString, QString::fromStdString(strURL)));
QMetaObject::invokeMethod(guiref, "handleURI", GUIUtil::blockingGUIThreadConnection(),
Q_ARG(QString, QString::fromStdString(strURI)));
}
void MainFrameRepaint()
......@@ -133,10 +133,10 @@ int main(int argc, char *argv[])
{
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;
......@@ -248,21 +248,21 @@ int main(int argc, char *argv[])
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) {
}
......
......@@ -715,7 +715,7 @@ void BitcoinGUI::gotoMessagePage(QString addr)
void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
{
// Accept only URLs
// Accept only URIs
if(event->mimeData()->hasUrls())
event->acceptProposedAction();
}
......@@ -725,20 +725,20 @@ void BitcoinGUI::dropEvent(QDropEvent *event)
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();
......
......@@ -125,7 +125,7 @@ public slots:
@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);
......
......@@ -52,15 +52,15 @@ void GUIUtil::setupAmountWidget(QLineEdit *widget, QWidget *parent)
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;
......@@ -97,18 +97,18 @@ bool GUIUtil::parseBitcoinURL(const QUrl &url, SendCoinsRecipient *out)
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)
......
......@@ -29,10 +29,10 @@ public:
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);
......
......@@ -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 @@ using namespace std;
void ipcShutdown()
{
message_queue::remove("BitcoinURL");
message_queue::remove(BITCOINURI_QUEUE_NAME);
}
void ipcThread(void* parg)
......@@ -30,7 +31,7 @@ void ipcThread(void* parg)
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 @@ void ipcInit()
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 @@ void ipcInit()
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;
......
#define BITCOINURI_QUEUE_NAME "BitcoinURI"
void ipcInit();
void ipcShutdown();
......@@ -265,10 +265,10 @@ void SendCoinsDialog::pasteEntry(const SendCoinsRecipient &rv)
}
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;
}
......
......@@ -30,7 +30,7 @@ public:
QWidget *setupTabChain(QWidget *prev);
void pasteEntry(const SendCoinsRecipient &rv);
void handleURL(const QString &url);
void handleURI(const QString &uri);
public slots:
void clear();
......
#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);
}
#include "urltests.h"
#include "uritests.h"
#include "../guiutil.h"
#include "../walletmodel.h"
......@@ -13,59 +13,59 @@ struct SendCoinsRecipient
};
*/
void URLTests::urlTests()
void URITests::uriTests()
{
SendCoinsRecipient rv;
QUrl url;
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist="));
QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv));
QUrl uri;
uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist="));
QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist="));
QVERIFY(GUIUtil::parseBitcoinURL(url, &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);
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv));
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);
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv));
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);
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv));
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);
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv));
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"));
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv));
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::parseBitcoinURL("bitcoin://175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address", &rv));
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...)
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address"));
QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv));
uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address"));
QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example"));
QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv));
uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example"));
QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example"));
QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv));
uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example"));
QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
}
#ifndef URLTESTS_H
#define URLTESTS_H
#ifndef URITESTS_H
#define URITESTS_H
#include <QTest>
#include <QObject>
class URLTests : public QObject
class URITests : public QObject
{
Q_OBJECT
private slots:
void urlTests();
void uriTests();
};
#endif // URLTESTS_H
#endif // URITESTS_H
......@@ -40,7 +40,7 @@
extern int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK);
extern bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption);
extern void ThreadSafeHandleURL(const std::string& strURL);
extern void ThreadSafeHandleURI(const std::string& strURI);
extern void MainFrameRepaint();
extern void AddressBookRepaint();
extern void QueueShutdown();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment