From a290b61f1a3a6223b5405d68fd10aa1957887c1c Mon Sep 17 00:00:00 2001 From: Amos Bairn Date: Thu, 22 Aug 2013 07:35:48 -0700 Subject: [PATCH 1/2] Add listAddressbook to api listAddressbook returns label and address for each address in the addressbook. --- src/bitmessagemain.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index fd233bd5..00c79247 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -164,6 +164,21 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): streamNumber, 'enabled': shared.config.getboolean(addressInKeysFile, 'enabled')}, indent=4, separators=(',', ': ')) data += ']}' return data + elif method == 'listAddressbook': + shared.sqlLock.acquire() + shared.sqlSubmitQueue.put('''SELECT label, address from addressbook''') + shared.sqlSubmitQueue.put('') + queryreturn = shared.sqlReturnQueue.get() + shared.sqlLock.release() + data = '{"addresses":[' + for row in queryreturn: + label, address = row + label = shared.fixPotentiallyInvalidUTF8Data(label) + if len(data) > 20: + data += ',' + data += json.dumps({'label':label.encode('base64'), 'address': address}) + data += ']}' + return data elif method == 'createRandomAddress': if len(params) == 0: return 'API Error 0000: I need parameters!' From 3ca4578f7ff576c7feb8678c416d58a217144164 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Tue, 3 Sep 2013 00:30:48 -0400 Subject: [PATCH 2/2] minor changes to previous commit- adding listAddressBook to API --- src/bitmessagemain.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 71ad201e..570d13c2 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -171,19 +171,15 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): streamNumber, 'enabled': shared.config.getboolean(addressInKeysFile, 'enabled')}, indent=4, separators=(',', ': ')) data += ']}' return data - elif method == 'listAddressbook': - shared.sqlLock.acquire() - shared.sqlSubmitQueue.put('''SELECT label, address from addressbook''') - shared.sqlSubmitQueue.put('') - queryreturn = shared.sqlReturnQueue.get() - shared.sqlLock.release() + elif method == 'listAddressBook' or method == 'listAddressbook': + queryreturn = sqlQuery('''SELECT label, address from addressbook''') data = '{"addresses":[' for row in queryreturn: label, address = row label = shared.fixPotentiallyInvalidUTF8Data(label) if len(data) > 20: data += ',' - data += json.dumps({'label':label.encode('base64'), 'address': address}) + data += json.dumps({'label':label.encode('base64'), 'address': address}, indent=4, separators=(',', ': ')) data += ']}' return data elif method == 'createRandomAddress':