Prefix based command filter

This commit is contained in:
Dmitri Bogomolov 2018-10-30 09:17:54 +02:00
parent fabbccbeac
commit efff8f95ba
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -169,9 +169,16 @@ class CommandHandler(type):
mcs, name, bases, namespace) mcs, name, bases, namespace)
result.config = BMConfigParser() result.config = BMConfigParser()
result._handlers = {} result._handlers = {}
apivariant = result.config.safeGet('bitmessagesettings', 'apivariant')
for func in namespace.values(): for func in namespace.values():
try: try:
for alias in getattr(func, '_cmd'): for alias in getattr(func, '_cmd'):
try:
prefix, alias = alias.split(':')
if apivariant != prefix:
continue
except ValueError:
pass
result._handlers[alias] = func result._handlers[alias] = func
except AttributeError: except AttributeError:
pass pass
@ -418,7 +425,7 @@ class BMRPCDispatcher(object):
return {'addresses': data} return {'addresses': data}
# the listAddressbook alias should be removed eventually. # the listAddressbook alias should be removed eventually.
@command('listAddressBookEntries', 'listAddressbook') @command('listAddressBookEntries', 'legacy:listAddressbook')
def HandleListAddressBookEntries(self, label=None): def HandleListAddressBookEntries(self, label=None):
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT label, address from addressbook WHERE label = ?", "SELECT label, address from addressbook WHERE label = ?",
@ -434,7 +441,7 @@ class BMRPCDispatcher(object):
return {'addresses': data} return {'addresses': data}
# the addAddressbook alias should be deleted eventually. # the addAddressbook alias should be deleted eventually.
@command('addAddressBookEntry', 'addAddressbook') @command('addAddressBookEntry', 'legacy:addAddressbook')
def HandleAddAddressBookEntry(self, address, label): def HandleAddAddressBookEntry(self, address, label):
label = self._decode(label, "base64") label = self._decode(label, "base64")
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
@ -453,7 +460,7 @@ class BMRPCDispatcher(object):
return "Added address %s to address book" % address return "Added address %s to address book" % address
# the deleteAddressbook alias should be deleted eventually. # the deleteAddressbook alias should be deleted eventually.
@command('deleteAddressBookEntry', 'deleteAddressbook') @command('deleteAddressBookEntry', 'legacy:deleteAddressbook')
def HandleDeleteAddressBookEntry(self, address): def HandleDeleteAddressBookEntry(self, address):
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
self._verifyAddress(address) self._verifyAddress(address)
@ -766,7 +773,7 @@ class BMRPCDispatcher(object):
]} ]}
# after some time getInboxMessagesByAddress should be removed # after some time getInboxMessagesByAddress should be removed
@command('getInboxMessagesByReceiver', 'getInboxMessagesByAddress') @command('getInboxMessagesByReceiver', 'legacy:getInboxMessagesByAddress')
def HandleInboxMessagesByReceiver(self, toAddress): def HandleInboxMessagesByReceiver(self, toAddress):
"""Handle a request to get inbox messages by receiver""" """Handle a request to get inbox messages by receiver"""