Add: debugging for freezing api call

This commit is contained in:
Peter Surda 2015-09-28 20:22:54 +02:00 committed by Peter Surda
parent f0f9f679e6
commit d3345e051a

View File

@ -565,127 +565,104 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
streamNumber, 'unused API address', numberOfAddresses, passphrase, eighteenByteRipe)) streamNumber, 'unused API address', numberOfAddresses, passphrase, eighteenByteRipe))
return shared.apiAddressGeneratorReturnQueue.get() return shared.apiAddressGeneratorReturnQueue.get()
def HandleCreateChan(self, params): elif method == 'getAllInboxMessages':
if len(params) == 0: queryreturn = sqlQuery(
raise APIError(0, 'I need parameters.') '''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype, read FROM inbox where folder='inbox' ORDER BY received''')
elif len(params) == 1: data = '{"inboxMessages":['
passphrase, = params for row in queryreturn:
passphrase = self._decode(passphrase, "base64") msgid, toAddress, fromAddress, subject, received, message, encodingtype, read = row
if len(passphrase) == 0: subject = shared.fixPotentiallyInvalidUTF8Data(subject)
raise APIError(1, 'The specified passphrase is blank.') message = shared.fixPotentiallyInvalidUTF8Data(message)
# It would be nice to make the label the passphrase but it is if len(data) > 25:
# possible that the passphrase contains non-utf-8 characters. data += ','
try: data += json.dumps({'msgid': msgid.encode('hex'), 'toAddress': toAddress, 'fromAddress': fromAddress, 'subject': subject.encode(
unicode(passphrase, 'utf-8') 'base64'), 'message': message.encode('base64'), 'encodingType': encodingtype, 'receivedTime': received, 'read': read}, indent=4, separators=(',', ': '))
label = str_chan + ' ' + passphrase data += ']}'
except: return data
label = str_chan + ' ' + repr(passphrase) elif method == 'getAllInboxMessageIds' or method == 'getAllInboxMessageIDs':
queryreturn = sqlQuery(
addressVersionNumber = 4 '''SELECT msgid FROM inbox where folder='inbox' ORDER BY received''')
streamNumber = 1 data = '{"inboxMessageIds":['
shared.apiAddressGeneratorReturnQueue.queue.clear() for row in queryreturn:
logger.debug('Requesting that the addressGenerator create chan %s.', passphrase) msgid = row[0]
shared.addressGeneratorQueue.put(('createChan', addressVersionNumber, streamNumber, label, passphrase)) if len(data) > 25:
queueReturn = shared.apiAddressGeneratorReturnQueue.get() data += ','
if len(queueReturn) == 0: data += json.dumps({'msgid': msgid.encode('hex')}, indent=4, separators=(',', ': '))
raise APIError(24, 'Chan address is already present.') data += ']}'
address = queueReturn[0] return data
return address elif method == 'getInboxMessageById' or method == 'getInboxMessageByID':
if len(params) == 0:
def HandleJoinChan(self, params): raise APIError(0, 'I need parameters!')
if len(params) < 2: elif len(params) == 1:
raise APIError(0, 'I need two parameters.') msgid = self._decode(params[0], "hex")
elif len(params) == 2: elif len(params) >= 2:
passphrase, suppliedAddress= params msgid = self._decode(params[0], "hex")
passphrase = self._decode(passphrase, "base64") readStatus = params[1]
if len(passphrase) == 0: if not isinstance(readStatus, bool):
raise APIError(1, 'The specified passphrase is blank.') raise APIError(23, 'Bool expected in readStatus, saw %s instead.' % type(readStatus))
# It would be nice to make the label the passphrase but it is queryreturn = sqlQuery('''SELECT read FROM inbox WHERE msgid=?''', msgid)
# possible that the passphrase contains non-utf-8 characters. # UPDATE is slow, only update if status is different
try: if queryreturn != [] and (queryreturn[0][0] == 1) != readStatus:
unicode(passphrase, 'utf-8') sqlExecute('''UPDATE inbox set read = ? WHERE msgid=?''', readStatus, msgid)
label = str_chan + ' ' + passphrase shared.UISignalQueue.put(('changedInboxUnread', None))
except: queryreturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype, read FROM inbox WHERE msgid=?''', msgid)
label = str_chan + ' ' + repr(passphrase) data = '{"inboxMessage":['
for row in queryreturn:
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(suppliedAddress) msgid, toAddress, fromAddress, subject, received, message, encodingtype, read = row
suppliedAddress = addBMIfNotPresent(suppliedAddress) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
shared.apiAddressGeneratorReturnQueue.queue.clear() message = shared.fixPotentiallyInvalidUTF8Data(message)
shared.addressGeneratorQueue.put(('joinChan', suppliedAddress, label, passphrase)) data += json.dumps({'msgid':msgid.encode('hex'), 'toAddress':toAddress, 'fromAddress':fromAddress, 'subject':subject.encode('base64'), 'message':message.encode('base64'), 'encodingType':encodingtype, 'receivedTime':received, 'read': read}, indent=4, separators=(',', ': '))
addressGeneratorReturnValue = shared.apiAddressGeneratorReturnQueue.get() data += ']}'
return data
if addressGeneratorReturnValue == 'chan name does not match address': elif method == 'getAllSentMessages':
raise APIError(18, 'Chan name does not match address.') import pprint
if len(addressGeneratorReturnValue) == 0: try:
raise APIError(24, 'Chan address is already present.') queryreturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, lastactiontime, message, encodingtype, status, ackdata FROM sent where folder='sent' ORDER BY lastactiontime''')
#TODO: this variable is not used to anything except:
createdAddress = addressGeneratorReturnValue[0] # in case we ever want it for anything. print "Exception in getallSentMessages"
return "success" pprint.pprint (queryreturn)
data = '{"sentMessages":['
def HandleLeaveChan(self, params): if type(queryreturn) is list:
if len(params) == 0: for row in queryreturn:
raise APIError(0, 'I need parameters.') msgid, toAddress, fromAddress, subject, lastactiontime, message, encodingtype, status, ackdata = row
elif len(params) == 1: subject = shared.fixPotentiallyInvalidUTF8Data(subject)
address, = params message = shared.fixPotentiallyInvalidUTF8Data(message)
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address) if len(data) > 25:
address = addBMIfNotPresent(address) data += ','
if not shared.config.has_section(address): data += json.dumps({'msgid':msgid.encode('hex'), 'toAddress':toAddress, 'fromAddress':fromAddress, 'subject':subject.encode('base64'), 'message':message.encode('base64'), 'encodingType':encodingtype, 'lastActionTime':lastactiontime, 'status':status, 'ackData':ackdata.encode('hex')}, indent=4, separators=(',', ': '))
raise APIError(13, 'Could not find this address in your keys.dat file.') else:
if not shared.safeConfigGetBoolean(address, 'chan'): print "queryreturn is not a list"
raise APIError(25, 'Specified address is not a chan address. Use deleteAddress API call instead.') pprint.pprint (queryreturn)
shared.config.remove_section(address) data += ']}'
with open(shared.appdata + 'keys.dat', 'wb') as configfile: return data
shared.config.write(configfile) elif method == 'getAllSentMessageIds' or method == 'getAllSentMessageIDs':
return 'success' queryreturn = sqlQuery('''SELECT msgid FROM sent where folder='sent' ORDER BY lastactiontime''')
data = '{"sentMessageIds":['
def HandleDeleteAddress(self, params): for row in queryreturn:
if len(params) == 0: msgid = row[0]
raise APIError(0, 'I need parameters.') if len(data) > 25:
elif len(params) == 1: data += ','
address, = params data += json.dumps({'msgid':msgid.encode('hex')}, indent=4, separators=(',', ': '))
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address) data += ']}'
address = addBMIfNotPresent(address) return data
if not shared.config.has_section(address): elif method == 'getInboxMessagesByReceiver' or method == 'getInboxMessagesByAddress': #after some time getInboxMessagesByAddress should be removed
raise APIError(13, 'Could not find this address in your keys.dat file.') if len(params) == 0:
shared.config.remove_section(address) raise APIError(0, 'I need parameters!')
with open(shared.appdata + 'keys.dat', 'wb') as configfile: toAddress = params[0]
shared.config.write(configfile) queryreturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype FROM inbox WHERE folder='inbox' AND toAddress=?''', toAddress)
shared.UISignalQueue.put(('rerenderInboxFromLabels','')) data = '{"inboxMessages":['
shared.UISignalQueue.put(('rerenderSentToLabels','')) for row in queryreturn:
shared.reloadMyAddressHashes() msgid, toAddress, fromAddress, subject, received, message, encodingtype = row
return 'success' subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
def HandleGetAllInboxMessages(self, params): if len(data) > 25:
queryreturn = sqlQuery( data += ','
'''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype, read FROM inbox where folder='inbox' ORDER BY received''') data += json.dumps({'msgid':msgid.encode('hex'), 'toAddress':toAddress, 'fromAddress':fromAddress, 'subject':subject.encode('base64'), 'message':message.encode('base64'), 'encodingType':encodingtype, 'receivedTime':received}, indent=4, separators=(',', ': '))
data = '{"inboxMessages":[' data += ']}'
for row in queryreturn: return data
msgid, toAddress, fromAddress, subject, received, message, encodingtype, read = row elif method == 'getSentMessageById' or method == 'getSentMessageByID':
subject = shared.fixPotentiallyInvalidUTF8Data(subject) if len(params) == 0:
message = shared.fixPotentiallyInvalidUTF8Data(message) raise APIError(0, 'I need parameters!')
if len(data) > 25:
data += ','
data += json.dumps({'msgid': msgid.encode('hex'), 'toAddress': toAddress, 'fromAddress': fromAddress, 'subject': subject.encode(
'base64'), 'message': message.encode('base64'), 'encodingType': encodingtype, 'receivedTime': received, 'read': read}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetAllInboxMessageIds(self, params):
queryreturn = sqlQuery(
'''SELECT msgid FROM inbox where folder='inbox' ORDER BY received''')
data = '{"inboxMessageIds":['
for row in queryreturn:
msgid = row[0]
if len(data) > 25:
data += ','
data += json.dumps({'msgid': msgid.encode('hex')}, indent=4, separators=(',', ': '))
data += ']}'
return data
def HandleGetInboxMessageById(self, params):
if len(params) == 0:
raise APIError(0, 'I need parameters!')
elif len(params) == 1:
msgid = self._decode(params[0], "hex") msgid = self._decode(params[0], "hex")
elif len(params) >= 2: elif len(params) >= 2:
msgid = self._decode(params[0], "hex") msgid = self._decode(params[0], "hex")