From efff8f95ba1b1ed65f19382b56852d53e24b7539 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 30 Oct 2018 09:17:54 +0200 Subject: [PATCH] Prefix based command filter --- src/api.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/api.py b/src/api.py index d1566630..ee7c05fa 100644 --- a/src/api.py +++ b/src/api.py @@ -169,9 +169,16 @@ class CommandHandler(type): mcs, name, bases, namespace) result.config = BMConfigParser() result._handlers = {} + apivariant = result.config.safeGet('bitmessagesettings', 'apivariant') for func in namespace.values(): try: for alias in getattr(func, '_cmd'): + try: + prefix, alias = alias.split(':') + if apivariant != prefix: + continue + except ValueError: + pass result._handlers[alias] = func except AttributeError: pass @@ -418,7 +425,7 @@ class BMRPCDispatcher(object): return {'addresses': data} # the listAddressbook alias should be removed eventually. - @command('listAddressBookEntries', 'listAddressbook') + @command('listAddressBookEntries', 'legacy:listAddressbook') def HandleListAddressBookEntries(self, label=None): queryreturn = sqlQuery( "SELECT label, address from addressbook WHERE label = ?", @@ -434,7 +441,7 @@ class BMRPCDispatcher(object): return {'addresses': data} # the addAddressbook alias should be deleted eventually. - @command('addAddressBookEntry', 'addAddressbook') + @command('addAddressBookEntry', 'legacy:addAddressbook') def HandleAddAddressBookEntry(self, address, label): label = self._decode(label, "base64") address = addBMIfNotPresent(address) @@ -453,7 +460,7 @@ class BMRPCDispatcher(object): return "Added address %s to address book" % address # the deleteAddressbook alias should be deleted eventually. - @command('deleteAddressBookEntry', 'deleteAddressbook') + @command('deleteAddressBookEntry', 'legacy:deleteAddressbook') def HandleDeleteAddressBookEntry(self, address): address = addBMIfNotPresent(address) self._verifyAddress(address) @@ -766,7 +773,7 @@ class BMRPCDispatcher(object): ]} # after some time getInboxMessagesByAddress should be removed - @command('getInboxMessagesByReceiver', 'getInboxMessagesByAddress') + @command('getInboxMessagesByReceiver', 'legacy:getInboxMessagesByAddress') def HandleInboxMessagesByReceiver(self, toAddress): """Handle a request to get inbox messages by receiver"""