def handle_kernel(sender,receiver,tag,message): global BASEPATH MSGDB_PATH0 = os.path.join(BASEPATH,'cache','msgdb.') try: tag = json.loads(tag.decode('hex')) tag['hash'] = hashlib.sha1(str(sender) +str(message) +str(tag['timestamp']) +str(tag['tag']) ).hexdigest() reconstructed = {'sender':sender, 'receiver':receiver, 'message':message, 'info':tag} # filter duplicate messages if is_duplicate(tag['hash']): return True # Call plugins if not reconstructed['info']['tag'].startswith('im_'): # Call related programs here ! plugins.plugin_do(reconstructed) return True else: if reconstructed['info']['tag'] not in ('im_receipt',): quickview = rich2plain(reconstructed['message']) if reconstructed['info']['xi']: notifier.gnotify(u'来自 %s 的机密消息' % sender, quickview) else: notifier.gnotify(u'来自 %s 的普通消息' % sender, quickview) # Store message for dialogs while True: if os.path.isfile(MSGDB_PATH0 + 'lock'): print 'Orichalcum processor: Message database locked, waiting.' time.sleep(0.5) else: dblock = open(MSGDB_PATH0 + 'lock','w+') dblock.close() break db = shelve.open(MSGDB_PATH0 + 'db' , writeback=True) newhash = reconstructed['info']['hash'] newkey = reconstructed['sender'].strip().encode('hex') if not db.has_key(newkey): db[newkey] = {newhash:reconstructed} else: db[newkey][newhash] = reconstructed db.close() except Exception,e: print "Error saving message: %s" % e
def handle_kernel(sender,receiver,tag,message,isxi): global BASEPATH MSGDB_PATH0 = os.path.join(BASEPATH,'configs','msgdb.') try: guidance = parse(message,tag,sender) # Mix rubbish up. Poor design. tag = guidance['more'] if guidance['tag'] != 'im': # Call related programs here ! plugins.plugin_do(guidance) return True else: message = guidance['message'] # Store message #notifier.showMessage(message['sender'],message['message']) while True: if os.path.isfile(MSGDB_PATH0 + 'lock'): print 'Orichalcum processor: Message database locked, waiting.' time.sleep(0.5) else: dblock = open(MSGDB_PATH0 + 'lock','w+') dblock.close() break db = shelve.open(MSGDB_PATH0 + 'db' , writeback=True) newpiece = {'message':message,'timestamp':tag['timestamp'],'account':tag['account'],'xi':isxi} newhash = base64.encodestring(hashlib.md5(message + tag['timestamp']).digest()).strip() newkey = base64.encodestring(sender) if db.has_key(newkey) == False: db[newkey] = {newhash:newpiece} else: db[newkey][newhash] = newpiece db.close() if isxi: notifier.gnotify('来自 %s 的机密消息' % sender,message) else: notifier.gnotify('来自 %s 的普通消息' % sender, message) except Exception,e: print "Error saving message: %s" % e