Browse Source

Merge pull request #987 from luke-jr/ipc_name_fix

Cleanup: Replace "URL" with "URI" where we aren't actually working with URLs
0.8
Gregory Maxwell 13 years ago
parent
commit
138d08c531
  1. 4
      bitcoin-qt.pro
  2. 22
      src/qt/bitcoin.cpp
  3. 12
      src/qt/bitcoingui.cpp
  4. 2
      src/qt/bitcoingui.h
  5. 18
      src/qt/guiutil.cpp
  6. 8
      src/qt/guiutil.h
  7. 13
      src/qt/qtipcserver.cpp
  8. 2
      src/qt/qtipcserver.h
  9. 4
      src/qt/sendcoinsdialog.cpp
  10. 2
      src/qt/sendcoinsdialog.h
  11. 4
      src/qt/test/test_main.cpp
  12. 48
      src/qt/test/uritests.cpp
  13. 15
      src/qt/test/uritests.h
  14. 15
      src/qt/test/urltests.h
  15. 2
      src/ui_interface.h

4
bitcoin-qt.pro

@ -225,8 +225,8 @@ FORMS += src/qt/forms/qrcodedialog.ui
contains(BITCOIN_QT_TEST, 1) { contains(BITCOIN_QT_TEST, 1) {
SOURCES += src/qt/test/test_main.cpp \ SOURCES += src/qt/test/test_main.cpp \
src/qt/test/urltests.cpp src/qt/test/uritests.cpp
HEADERS += src/qt/test/urltests.h HEADERS += src/qt/test/uritests.h
DEPENDPATH += src/qt/test DEPENDPATH += src/qt/test
QT += testlib QT += testlib
TARGET = bitcoin-qt_test TARGET = bitcoin-qt_test

22
src/qt/bitcoin.cpp

@ -74,13 +74,13 @@ bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption)
return payFee; return payFee;
} }
void ThreadSafeHandleURL(const std::string& strURL) void ThreadSafeHandleURI(const std::string& strURI)
{ {
if(!guiref) if(!guiref)
return; return;
QMetaObject::invokeMethod(guiref, "handleURL", GUIUtil::blockingGUIThreadConnection(), QMetaObject::invokeMethod(guiref, "handleURI", GUIUtil::blockingGUIThreadConnection(),
Q_ARG(QString, QString::fromStdString(strURL))); Q_ARG(QString, QString::fromStdString(strURI)));
} }
void MainFrameRepaint() void MainFrameRepaint()
@ -133,10 +133,10 @@ int main(int argc, char *argv[])
{ {
if (strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0) if (strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0)
{ {
const char *strURL = argv[i]; const char *strURI = argv[i];
try { try {
boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); boost::interprocess::message_queue mq(boost::interprocess::open_only, BITCOINURI_QUEUE_NAME);
if(mq.try_send(strURL, strlen(strURL), 0)) if(mq.try_send(strURI, strlen(strURI), 0))
exit(0); exit(0);
else else
break; break;
@ -248,21 +248,21 @@ int main(int argc, char *argv[])
window.show(); 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(); ipcInit();
#if !defined(MAC_OSX) && !defined(WIN32) #if !defined(MAC_OSX) && !defined(WIN32)
// TODO: implement qtipcserver.cpp for Mac and Windows // 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++) for (int i = 1; i < argc; i++)
{ {
if (strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0) if (strlen(argv[i]) > 7 && strncasecmp(argv[i], "bitcoin:", 8) == 0)
{ {
const char *strURL = argv[i]; const char *strURI = argv[i];
try { try {
boost::interprocess::message_queue mq(boost::interprocess::open_only, "BitcoinURL"); boost::interprocess::message_queue mq(boost::interprocess::open_only, BITCOINURI_QUEUE_NAME);
mq.try_send(strURL, strlen(strURL), 0); mq.try_send(strURI, strlen(strURI), 0);
} }
catch (boost::interprocess::interprocess_exception &ex) { catch (boost::interprocess::interprocess_exception &ex) {
} }

12
src/qt/bitcoingui.cpp

@ -715,7 +715,7 @@ void BitcoinGUI::gotoMessagePage(QString addr)
void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event) void BitcoinGUI::dragEnterEvent(QDragEnterEvent *event)
{ {
// Accept only URLs // Accept only URIs
if(event->mimeData()->hasUrls()) if(event->mimeData()->hasUrls())
event->acceptProposedAction(); event->acceptProposedAction();
} }
@ -725,20 +725,20 @@ void BitcoinGUI::dropEvent(QDropEvent *event)
if(event->mimeData()->hasUrls()) if(event->mimeData()->hasUrls())
{ {
gotoSendCoinsPage(); gotoSendCoinsPage();
QList<QUrl> urls = event->mimeData()->urls(); QList<QUrl> uris = event->mimeData()->urls();
foreach(const QUrl &url, urls) foreach(const QUrl &uri, uris)
{ {
sendCoinsPage->handleURL(url.toString()); sendCoinsPage->handleURI(uri.toString());
} }
} }
event->acceptProposedAction(); event->acceptProposedAction();
} }
void BitcoinGUI::handleURL(QString strURL) void BitcoinGUI::handleURI(QString strURI)
{ {
gotoSendCoinsPage(); gotoSendCoinsPage();
sendCoinsPage->handleURL(strURL); sendCoinsPage->handleURI(strURI);
if(!isActiveWindow()) if(!isActiveWindow())
activateWindow(); activateWindow();

2
src/qt/bitcoingui.h

@ -125,7 +125,7 @@ public slots:
@param[out] payFee true to pay the fee, false to not pay the fee @param[out] payFee true to pay the fee, false to not pay the fee
*/ */
void askFee(qint64 nFeeRequired, bool *payFee); void askFee(qint64 nFeeRequired, bool *payFee);
void handleURL(QString strURL); void handleURI(QString strURI);
void gotoMessagePage(); void gotoMessagePage();
void gotoMessagePage(QString); void gotoMessagePage(QString);

18
src/qt/guiutil.cpp

@ -52,15 +52,15 @@ void GUIUtil::setupAmountWidget(QLineEdit *widget, QWidget *parent)
widget->setAlignment(Qt::AlignRight|Qt::AlignVCenter); 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; return false;
SendCoinsRecipient rv; SendCoinsRecipient rv;
rv.address = url.path(); rv.address = uri.path();
rv.amount = 0; 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++) for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++)
{ {
bool fShouldReturnFalse = false; bool fShouldReturnFalse = false;
@ -97,18 +97,18 @@ bool GUIUtil::parseBitcoinURL(const QUrl &url, SendCoinsRecipient *out)
return true; return true;
} }
bool GUIUtil::parseBitcoinURL(QString url, SendCoinsRecipient *out) bool GUIUtil::parseBitcoinURI(QString uri, SendCoinsRecipient *out)
{ {
// Convert bitcoin:// to bitcoin: // Convert bitcoin:// to bitcoin:
// //
// Cannot handle this later, because bitcoin:// will cause Qt to see the part after // as host, // 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). // 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); QUrl uriInstance(uri);
return parseBitcoinURL(urlInstance, out); return parseBitcoinURI(uriInstance, out);
} }
QString GUIUtil::HtmlEscape(const QString& str, bool fMultiLine) QString GUIUtil::HtmlEscape(const QString& str, bool fMultiLine)

8
src/qt/guiutil.h

@ -29,10 +29,10 @@ public:
static void setupAddressWidget(QLineEdit *widget, QWidget *parent); static void setupAddressWidget(QLineEdit *widget, QWidget *parent);
static void setupAmountWidget(QLineEdit *widget, QWidget *parent); static void setupAmountWidget(QLineEdit *widget, QWidget *parent);
// Parse "bitcoin:" URL into recipient object, return true on succesful parsing // Parse "bitcoin:" URI into recipient object, return true on succesful parsing
// See Bitcoin URL definition discussion here: https://bitcointalk.org/index.php?topic=33490.0 // See Bitcoin URI definition discussion here: https://bitcointalk.org/index.php?topic=33490.0
static bool parseBitcoinURL(const QUrl &url, SendCoinsRecipient *out); static bool parseBitcoinURI(const QUrl &, SendCoinsRecipient *out);
static bool parseBitcoinURL(QString url, SendCoinsRecipient *out); static bool parseBitcoinURI(QString uri, SendCoinsRecipient *out);
// HTML escaping for rich text controls // HTML escaping for rich text controls
static QString HtmlEscape(const QString& str, bool fMultiLine=false); static QString HtmlEscape(const QString& str, bool fMultiLine=false);

13
src/qt/qtipcserver.cpp

@ -8,6 +8,7 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "headers.h" #include "headers.h"
#include "qtipcserver.h"
using namespace boost::interprocess; using namespace boost::interprocess;
using namespace boost::posix_time; using namespace boost::posix_time;
@ -16,7 +17,7 @@ using namespace std;
void ipcShutdown() void ipcShutdown()
{ {
message_queue::remove("BitcoinURL"); message_queue::remove(BITCOINURI_QUEUE_NAME);
} }
void ipcThread(void* parg) void ipcThread(void* parg)
@ -30,7 +31,7 @@ void ipcThread(void* parg)
ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(100); ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(100);
if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d)) if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d))
{ {
ThreadSafeHandleURL(std::string(strBuf, nSize)); ThreadSafeHandleURI(std::string(strBuf, nSize));
Sleep(1000); Sleep(1000);
} }
if (fShutdown) if (fShutdown)
@ -60,7 +61,7 @@ void ipcInit()
size_t nSize; size_t nSize;
unsigned int nPriority; unsigned int nPriority;
try { 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 // Make sure we don't lose any bitcoin: URIs
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
@ -68,15 +69,15 @@ void ipcInit()
ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(1); ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(1);
if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d)) if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d))
{ {
ThreadSafeHandleURL(std::string(strBuf, nSize)); ThreadSafeHandleURI(std::string(strBuf, nSize));
} }
else else
break; break;
} }
// Make sure only one bitcoin instance is listening // Make sure only one bitcoin instance is listening
message_queue::remove("BitcoinURL"); message_queue::remove(BITCOINURI_QUEUE_NAME);
mq = new message_queue(open_or_create, "BitcoinURL", 2, 256); mq = new message_queue(open_or_create, BITCOINURI_QUEUE_NAME, 2, 256);
} }
catch (interprocess_exception &ex) { catch (interprocess_exception &ex) {
return; return;

2
src/qt/qtipcserver.h

@ -1,2 +1,4 @@
#define BITCOINURI_QUEUE_NAME "BitcoinURI"
void ipcInit(); void ipcInit();
void ipcShutdown(); void ipcShutdown();

4
src/qt/sendcoinsdialog.cpp

@ -265,10 +265,10 @@ void SendCoinsDialog::pasteEntry(const SendCoinsRecipient &rv)
} }
void SendCoinsDialog::handleURL(const QString &url) void SendCoinsDialog::handleURI(const QString &uri)
{ {
SendCoinsRecipient rv; SendCoinsRecipient rv;
if(!GUIUtil::parseBitcoinURL(url, &rv)) if(!GUIUtil::parseBitcoinURI(uri, &rv))
{ {
return; return;
} }

2
src/qt/sendcoinsdialog.h

@ -30,7 +30,7 @@ public:
QWidget *setupTabChain(QWidget *prev); QWidget *setupTabChain(QWidget *prev);
void pasteEntry(const SendCoinsRecipient &rv); void pasteEntry(const SendCoinsRecipient &rv);
void handleURL(const QString &url); void handleURI(const QString &uri);
public slots: public slots:
void clear(); void clear();

4
src/qt/test/test_main.cpp

@ -1,11 +1,11 @@
#include <QTest> #include <QTest>
#include <QObject> #include <QObject>
#include "urltests.h" #include "uritests.h"
// This is all you need to run all the tests // This is all you need to run all the tests
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
URLTests test1; URITests test1;
QTest::qExec(&test1); QTest::qExec(&test1);
} }

48
src/qt/test/urltests.cpp → src/qt/test/uritests.cpp

@ -1,4 +1,4 @@
#include "urltests.h" #include "uritests.h"
#include "../guiutil.h" #include "../guiutil.h"
#include "../walletmodel.h" #include "../walletmodel.h"
@ -13,59 +13,59 @@ struct SendCoinsRecipient
}; };
*/ */
void URLTests::urlTests() void URITests::uriTests()
{ {
SendCoinsRecipient rv; SendCoinsRecipient rv;
QUrl url; QUrl uri;
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist=")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-dontexist="));
QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist=")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?dontexist="));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
QVERIFY(rv.label == QString()); QVERIFY(rv.label == QString());
QVERIFY(rv.amount == 0); QVERIFY(rv.amount == 0);
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?label=Wikipedia Example Address"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
QVERIFY(rv.label == QString("Wikipedia Example Address")); QVERIFY(rv.label == QString("Wikipedia Example Address"));
QVERIFY(rv.amount == 0); QVERIFY(rv.amount == 0);
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=0.001"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
QVERIFY(rv.label == QString()); QVERIFY(rv.label == QString());
QVERIFY(rv.amount == 100000); QVERIFY(rv.amount == 100000);
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1.001"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
QVERIFY(rv.label == QString()); QVERIFY(rv.label == QString());
QVERIFY(rv.amount == 100100000); QVERIFY(rv.amount == 100100000);
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=100&label=Wikipedia Example"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
QVERIFY(rv.amount == 10000000000); QVERIFY(rv.amount == 10000000000);
QVERIFY(rv.label == QString("Wikipedia Example")); QVERIFY(rv.label == QString("Wikipedia Example"));
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?message=Wikipedia Example Address"));
QVERIFY(GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W")); QVERIFY(rv.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
QVERIFY(rv.label == QString()); 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.address == QString("175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W"));
QVERIFY(rv.label == QString()); QVERIFY(rv.label == QString());
// We currently dont implement the message paramenter (ok, yea, we break spec...) // We currently dont implement the message paramenter (ok, yea, we break spec...)
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?req-message=Wikipedia Example Address"));
QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000&label=Wikipedia Example"));
QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
url.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example")); uri.setUrl(QString("bitcoin:175tWpb8K1S7NmH4Zx6rewF9WQrcZv245W?amount=1,000.0&label=Wikipedia Example"));
QVERIFY(!GUIUtil::parseBitcoinURL(url, &rv)); QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
} }

15
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

15
src/qt/test/urltests.h

@ -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

2
src/ui_interface.h

@ -40,7 +40,7 @@
extern int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK); extern int ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style=wxOK);
extern bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption); 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 MainFrameRepaint();
extern void AddressBookRepaint(); extern void AddressBookRepaint();
extern void QueueShutdown(); extern void QueueShutdown();

Loading…
Cancel
Save