|
|
|
@ -148,6 +148,25 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|
|
|
|
except TypeError as e:
|
|
|
|
|
raise APIError(22, "Decode error - " + str(e))
|
|
|
|
|
|
|
|
|
|
def _verifyAddress(self, address):
|
|
|
|
|
status, addressVersionNumber, streamNumber, ripe = decodeAddress(address)
|
|
|
|
|
if status != 'success':
|
|
|
|
|
logger.warn('API Error 0007: Could not decode address %s. Status: %s.', address, status)
|
|
|
|
|
|
|
|
|
|
if status == 'checksumfailed':
|
|
|
|
|
raise APIError(8, 'Checksum failed for address: ' + address)
|
|
|
|
|
if status == 'invalidcharacters':
|
|
|
|
|
raise APIError(9, 'Invalid characters in address: ' + address)
|
|
|
|
|
if status == 'versiontoohigh':
|
|
|
|
|
raise APIError(10, 'Address version number too high (or zero) in address: ' + address)
|
|
|
|
|
raise APIError(7, 'Could not decode address: ' + address + ' : ' + status)
|
|
|
|
|
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
|
|
|
|
raise APIError(11, 'The address version number currently must be 2 or 3. Others aren\'t supported. Check the address.')
|
|
|
|
|
if streamNumber != 1:
|
|
|
|
|
raise APIError(12, 'The stream number must be 1. Others aren\'t supported. Check the address.')
|
|
|
|
|
|
|
|
|
|
return (status, addressVersionNumber, streamNumber, ripe)
|
|
|
|
|
|
|
|
|
|
def _handle_request(self, method, params):
|
|
|
|
|
if method == 'helloWorld':
|
|
|
|
|
(a, b) = params
|
|
|
|
@ -183,6 +202,33 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|
|
|
|
data += json.dumps({'label':label.encode('base64'), 'address': address}, indent=4, separators=(',', ': '))
|
|
|
|
|
data += ']}'
|
|
|
|
|
return data
|
|
|
|
|
elif method == 'addAddressBook' or method == 'addAddressbook':
|
|
|
|
|
if len(params) != 2:
|
|
|
|
|
raise APIError(0, "I need label and address")
|
|
|
|
|
label, address = params
|
|
|
|
|
label = self._decode(label, "base64")
|
|
|
|
|
address = addBMIfNotPresent(address)
|
|
|
|
|
self._verifyAddress(address)
|
|
|
|
|
queryreturn = sqlQuery("SELECT address FROM addressbook WHERE address=?", address)
|
|
|
|
|
if queryreturn != []:
|
|
|
|
|
raise APIError(16, 'You already have this address in your address book.')
|
|
|
|
|
|
|
|
|
|
sqlExecute("INSERT INTO addressbook VALUES(?,?)", label, address)
|
|
|
|
|
shared.UISignalQueue.put(('rerenderInboxFromLabels',''))
|
|
|
|
|
shared.UISignalQueue.put(('rerenderSentToLabels',''))
|
|
|
|
|
shared.UISignalQueue.put(('rerenderAddressBook',''))
|
|
|
|
|
return "Added address %s to address book" % address
|
|
|
|
|
elif method == 'deleteAddressBook' or method == 'deleteAddressbook':
|
|
|
|
|
if len(params) != 1:
|
|
|
|
|
raise APIError(0, "I need an address")
|
|
|
|
|
address, = params
|
|
|
|
|
address = addBMIfNotPresent(address)
|
|
|
|
|
self._verifyAddress(address)
|
|
|
|
|
sqlExecute('DELETE FROM addressbook WHERE address=?', address)
|
|
|
|
|
shared.UISignalQueue.put(('rerenderInboxFromLabels',''))
|
|
|
|
|
shared.UISignalQueue.put(('rerenderSentToLabels',''))
|
|
|
|
|
shared.UISignalQueue.put(('rerenderAddressBook',''))
|
|
|
|
|
return "Deleted address book entry for %s if it existed" % address
|
|
|
|
|
elif method == 'createRandomAddress':
|
|
|
|
|
if len(params) == 0:
|
|
|
|
|
raise APIError(0, 'I need parameters!')
|
|
|
|
@ -496,40 +542,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|
|
|
|
raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.')
|
|
|
|
|
subject = self._decode(subject, "base64")
|
|
|
|
|
message = self._decode(message, "base64")
|
|
|
|
|
status, addressVersionNumber, streamNumber, toRipe = decodeAddress(
|
|
|
|
|
toAddress)
|
|
|
|
|
if status != 'success':
|
|
|
|
|
logger.warn('API Error 0007: Could not decode address %s. Status: %s.', toAddress, status)
|
|
|
|
|
|
|
|
|
|
if status == 'checksumfailed':
|
|
|
|
|
raise APIError(8, 'Checksum failed for address: ' + toAddress)
|
|
|
|
|
if status == 'invalidcharacters':
|
|
|
|
|
raise APIError(9, 'Invalid characters in address: ' + toAddress)
|
|
|
|
|
if status == 'versiontoohigh':
|
|
|
|
|
raise APIError(10, 'Address version number too high (or zero) in address: ' + toAddress)
|
|
|
|
|
raise APIError(7, 'Could not decode address: ' + toAddress + ' : ' + status)
|
|
|
|
|
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
|
|
|
|
raise APIError(11, 'The address version number currently must be 2 or 3. Others aren\'t supported. Check the toAddress.')
|
|
|
|
|
if streamNumber != 1:
|
|
|
|
|
raise APIError(12, 'The stream number must be 1. Others aren\'t supported. Check the toAddress.')
|
|
|
|
|
status, addressVersionNumber, streamNumber, fromRipe = decodeAddress(
|
|
|
|
|
fromAddress)
|
|
|
|
|
if status != 'success':
|
|
|
|
|
logger.warn('API Error 0007: Could not decode address %s. Status: %s.', fromAddress, status)
|
|
|
|
|
|
|
|
|
|
if status == 'checksumfailed':
|
|
|
|
|
raise APIError(8, 'Checksum failed for address: ' + fromAddress)
|
|
|
|
|
if status == 'invalidcharacters':
|
|
|
|
|
raise APIError(9, 'Invalid characters in address: ' + fromAddress)
|
|
|
|
|
if status == 'versiontoohigh':
|
|
|
|
|
raise APIError(10, 'Address version number too high (or zero) in address: ' + fromAddress)
|
|
|
|
|
raise APIError(7, 'Could not decode address: ' + fromAddress + ' : ' + status)
|
|
|
|
|
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
|
|
|
|
raise APIError(11, 'The address version number currently must be 2 or 3. Others aren\'t supported. Check the fromAddress.')
|
|
|
|
|
if streamNumber != 1:
|
|
|
|
|
raise APIError(12, 'The stream number must be 1. Others aren\'t supported. Check the fromAddress.')
|
|
|
|
|
toAddress = addBMIfNotPresent(toAddress)
|
|
|
|
|
fromAddress = addBMIfNotPresent(fromAddress)
|
|
|
|
|
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(toAddress)
|
|
|
|
|
self._verifyAddress(fromAddress)
|
|
|
|
|
try:
|
|
|
|
|
fromAddressEnabled = shared.config.getboolean(
|
|
|
|
|
fromAddress, 'enabled')
|
|
|
|
@ -570,23 +586,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|
|
|
|
subject = self._decode(subject, "base64")
|
|
|
|
|
message = self._decode(message, "base64")
|
|
|
|
|
|
|
|
|
|
status, addressVersionNumber, streamNumber, fromRipe = decodeAddress(
|
|
|
|
|
fromAddress)
|
|
|
|
|
if status != 'success':
|
|
|
|
|
logger.warn('API Error 0007: Could not decode address %s. Status: %s.', fromAddress, status)
|
|
|
|
|
|
|
|
|
|
if status == 'checksumfailed':
|
|
|
|
|
raise APIError(8, 'Checksum failed for address: ' + fromAddress)
|
|
|
|
|
if status == 'invalidcharacters':
|
|
|
|
|
raise APIError(9, 'Invalid characters in address: ' + fromAddress)
|
|
|
|
|
if status == 'versiontoohigh':
|
|
|
|
|
raise APIError(10, 'Address version number too high (or zero) in address: ' + fromAddress)
|
|
|
|
|
raise APIError(7, 'Could not decode address: ' + fromAddress + ' : ' + status)
|
|
|
|
|
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
|
|
|
|
raise APIError(11, 'the address version number currently must be 2 or 3. Others aren\'t supported. Check the fromAddress.')
|
|
|
|
|
if streamNumber != 1:
|
|
|
|
|
raise APIError(12, 'the stream number must be 1. Others aren\'t supported. Check the fromAddress.')
|
|
|
|
|
fromAddress = addBMIfNotPresent(fromAddress)
|
|
|
|
|
self._verifyAddress(fromAddress)
|
|
|
|
|
try:
|
|
|
|
|
fromAddressEnabled = shared.config.getboolean(
|
|
|
|
|
fromAddress, 'enabled')
|
|
|
|
@ -638,22 +639,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|
|
|
|
if len(params) > 2:
|
|
|
|
|
raise APIError(0, 'I need either 1 or 2 parameters!')
|
|
|
|
|
address = addBMIfNotPresent(address)
|
|
|
|
|
status, addressVersionNumber, streamNumber, toRipe = decodeAddress(
|
|
|
|
|
address)
|
|
|
|
|
if status != 'success':
|
|
|
|
|
logger.warn('API Error 0007: Could not decode address %s. Status: %s.', address, status)
|
|
|
|
|
|
|
|
|
|
if status == 'checksumfailed':
|
|
|
|
|
raise APIError(8, 'Checksum failed for address: ' + address)
|
|
|
|
|
if status == 'invalidcharacters':
|
|
|
|
|
raise APIError(9, 'Invalid characters in address: ' + address)
|
|
|
|
|
if status == 'versiontoohigh':
|
|
|
|
|
raise APIError(10, 'Address version number too high (or zero) in address: ' + address)
|
|
|
|
|
raise APIError(7, 'Could not decode address: ' + address + ' : ' + status)
|
|
|
|
|
if addressVersionNumber < 2 or addressVersionNumber > 3:
|
|
|
|
|
raise APIError(11, 'The address version number currently must be 2 or 3. Others aren\'t supported.')
|
|
|
|
|
if streamNumber != 1:
|
|
|
|
|
raise APIError(12, 'The stream number must be 1. Others aren\'t supported.')
|
|
|
|
|
self._verifyAddress(address)
|
|
|
|
|
# First we must check to see if the address is already in the
|
|
|
|
|
# subscriptions list.
|
|
|
|
|
queryreturn = sqlQuery('''select * from subscriptions where address=?''', address)
|
|
|
|
|