addAddressBook and deleteAddressBook API calls #482
|
@ -148,6 +148,25 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
raise APIError(22, "Decode error - " + str(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):
|
def _handle_request(self, method, params):
|
||||||
if method == 'helloWorld':
|
if method == 'helloWorld':
|
||||||
(a, b) = params
|
(a, b) = params
|
||||||
|
@ -183,6 +202,33 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
data += json.dumps({'label':label.encode('base64'), 'address': address}, indent=4, separators=(',', ': '))
|
data += json.dumps({'label':label.encode('base64'), 'address': address}, indent=4, separators=(',', ': '))
|
||||||
data += ']}'
|
data += ']}'
|
||||||
return data
|
return data
|
||||||
|
elif method == 'addAddressBook' or method == 'addAddressbook':
|
||||||
|
if len(params) != 2:
|
||||||
|
raise APIError(0, "I need label and address")
|
||||||
|
address, label = 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':
|
elif method == 'createRandomAddress':
|
||||||
if len(params) == 0:
|
if len(params) == 0:
|
||||||
raise APIError(0, 'I need parameters!')
|
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.')
|
raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.')
|
||||||
subject = self._decode(subject, "base64")
|
subject = self._decode(subject, "base64")
|
||||||
message = self._decode(message, "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)
|
toAddress = addBMIfNotPresent(toAddress)
|
||||||
fromAddress = addBMIfNotPresent(fromAddress)
|
fromAddress = addBMIfNotPresent(fromAddress)
|
||||||
|
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(toAddress)
|
||||||
|
self._verifyAddress(fromAddress)
|
||||||
try:
|
try:
|
||||||
fromAddressEnabled = shared.config.getboolean(
|
fromAddressEnabled = shared.config.getboolean(
|
||||||
fromAddress, 'enabled')
|
fromAddress, 'enabled')
|
||||||
|
@ -570,23 +586,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
subject = self._decode(subject, "base64")
|
subject = self._decode(subject, "base64")
|
||||||
message = self._decode(message, "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)
|
fromAddress = addBMIfNotPresent(fromAddress)
|
||||||
|
self._verifyAddress(fromAddress)
|
||||||
try:
|
try:
|
||||||
fromAddressEnabled = shared.config.getboolean(
|
fromAddressEnabled = shared.config.getboolean(
|
||||||
fromAddress, 'enabled')
|
fromAddress, 'enabled')
|
||||||
|
@ -638,22 +639,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
if len(params) > 2:
|
if len(params) > 2:
|
||||||
raise APIError(0, 'I need either 1 or 2 parameters!')
|
raise APIError(0, 'I need either 1 or 2 parameters!')
|
||||||
address = addBMIfNotPresent(address)
|
address = addBMIfNotPresent(address)
|
||||||
status, addressVersionNumber, streamNumber, toRipe = decodeAddress(
|
self._verifyAddress(address)
|
||||||
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.')
|
|
||||||
# First we must check to see if the address is already in the
|
# First we must check to see if the address is already in the
|
||||||
# subscriptions list.
|
# subscriptions list.
|
||||||
queryreturn = sqlQuery('''select * from subscriptions where address=?''', address)
|
queryreturn = sqlQuery('''select * from subscriptions where address=?''', address)
|
||||||
|
|
|
@ -351,16 +351,7 @@ class MyForm(QtGui.QMainWindow):
|
||||||
self.loadSent()
|
self.loadSent()
|
||||||
|
|
||||||
# Initialize the address book
|
# Initialize the address book
|
||||||
queryreturn = sqlQuery('SELECT * FROM addressbook')
|
self.rerenderAddressBook()
|
||||||
for row in queryreturn:
|
|
||||||
label, address = row
|
|
||||||
self.ui.tableWidgetAddressBook.insertRow(0)
|
|
||||||
newItem = QtGui.QTableWidgetItem(unicode(label, 'utf-8'))
|
|
||||||
self.ui.tableWidgetAddressBook.setItem(0, 0, newItem)
|
|
||||||
newItem = QtGui.QTableWidgetItem(address)
|
|
||||||
newItem.setFlags(
|
|
||||||
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
|
|
||||||
|
|
||||||
# Initialize the Subscriptions
|
# Initialize the Subscriptions
|
||||||
self.rerenderSubscriptions()
|
self.rerenderSubscriptions()
|
||||||
|
@ -427,6 +418,10 @@ class MyForm(QtGui.QMainWindow):
|
||||||
"setStatusIcon(PyQt_PyObject)"), self.setStatusIcon)
|
"setStatusIcon(PyQt_PyObject)"), self.setStatusIcon)
|
||||||
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
"rerenderInboxFromLabels()"), self.rerenderInboxFromLabels)
|
"rerenderInboxFromLabels()"), self.rerenderInboxFromLabels)
|
||||||
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
|
"rerenderSentToLabels()"), self.rerenderSentToLabels)
|
||||||
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
|
"rerenderAddressBook()"), self.rerenderAddressBook)
|
||||||
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
"rerenderSubscriptions()"), self.rerenderSubscriptions)
|
"rerenderSubscriptions()"), self.rerenderSubscriptions)
|
||||||
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
|
||||||
|
@ -1478,6 +1473,19 @@ class MyForm(QtGui.QMainWindow):
|
||||||
self.ui.tableWidgetSent.item(
|
self.ui.tableWidgetSent.item(
|
||||||
i, 0).setText(unicode(toLabel, 'utf-8'))
|
i, 0).setText(unicode(toLabel, 'utf-8'))
|
||||||
|
|
||||||
|
def rerenderAddressBook(self):
|
||||||
|
self.ui.tableWidgetAddressBook.setRowCount(0)
|
||||||
|
queryreturn = sqlQuery('SELECT * FROM addressbook')
|
||||||
|
for row in queryreturn:
|
||||||
|
label, address = row
|
||||||
|
self.ui.tableWidgetAddressBook.insertRow(0)
|
||||||
|
newItem = QtGui.QTableWidgetItem(unicode(label, 'utf-8'))
|
||||||
|
self.ui.tableWidgetAddressBook.setItem(0, 0, newItem)
|
||||||
|
newItem = QtGui.QTableWidgetItem(address)
|
||||||
|
newItem.setFlags(
|
||||||
|
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||||
|
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
|
||||||
|
|
||||||
def rerenderSubscriptions(self):
|
def rerenderSubscriptions(self):
|
||||||
self.ui.tableWidgetSubscriptions.setRowCount(0)
|
self.ui.tableWidgetSubscriptions.setRowCount(0)
|
||||||
queryreturn = sqlQuery('SELECT label, address, enabled FROM subscriptions')
|
queryreturn = sqlQuery('SELECT label, address, enabled FROM subscriptions')
|
||||||
|
@ -3185,6 +3193,10 @@ class UISignaler(QThread):
|
||||||
self.emit(SIGNAL("setStatusIcon(PyQt_PyObject)"), data)
|
self.emit(SIGNAL("setStatusIcon(PyQt_PyObject)"), data)
|
||||||
elif command == 'rerenderInboxFromLabels':
|
elif command == 'rerenderInboxFromLabels':
|
||||||
self.emit(SIGNAL("rerenderInboxFromLabels()"))
|
self.emit(SIGNAL("rerenderInboxFromLabels()"))
|
||||||
|
elif command == 'rerenderSentToLabels':
|
||||||
|
self.emit(SIGNAL("rerenderSentToLabels()"))
|
||||||
|
elif command == 'rerenderAddressBook':
|
||||||
|
self.emit(SIGNAL("rerenderAddressBook()"))
|
||||||
elif command == 'rerenderSubscriptions':
|
elif command == 'rerenderSubscriptions':
|
||||||
self.emit(SIGNAL("rerenderSubscriptions()"))
|
self.emit(SIGNAL("rerenderSubscriptions()"))
|
||||||
elif command == 'removeInboxRowByMsgid':
|
elif command == 'removeInboxRowByMsgid':
|
||||||
|
|
Reference in New Issue
Block a user