From fbbc65738055b7f61aab89e0715bb09ef531c593 Mon Sep 17 00:00:00 2001 From: "Grant T. Olson" Date: Tue, 30 Jul 2013 19:41:40 -0400 Subject: [PATCH] Add listSubscriptions method to API --- src/bitmessagemain.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 51b9a82d..add370a0 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -677,6 +677,23 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): shared.UISignalQueue.put(('rerenderInboxFromLabels', '')) shared.UISignalQueue.put(('rerenderSubscriptions', '')) return 'Deleted subscription if it existed.' + elif method == 'listSubscriptions': + if len(params) != 0: + return "API Error 0000: I don't accept parameters!" + shared.sqlLock.acquire() + shared.sqlSubmitQueue.put('''SELECT label, address, enabled FROM subscriptions''') + shared.sqlSubmitQueue.put('') + queryreturn = shared.sqlReturnQueue.get() + shared.sqlLock.release() + data = '{"subscriptions":[' + for row in queryreturn: + label, address, enabled = row + label = shared.fixPotentiallyInvalidUTF8Data(label) + if len(data) > 20: + data += ',' + data += json.dumps({'label':label.encode('base64'), 'address': address, 'enabled': enabled == 1}, indent=4, separators=(',',': ')) + data += ']}' + return data elif method == 'clientStatus': return '{ "networkConnections" : "%s" }' % str(len(shared.connectedHostsList)) else: