resource fixed and code formatted

This commit is contained in:
Volkan Şahin 2016-08-15 11:21:23 +03:00
parent 18c65ca87b
commit bf37183005
3 changed files with 29 additions and 13 deletions

View file

@ -6,12 +6,12 @@ import json
import sys
from sleekxmpp import ClientXMPP
sys.path.append('../..')
from base.Scope import Scope
sys.path.append('../..')
class AnonymousMessager(ClientXMPP):
class AnonymousMessenger(ClientXMPP):
def __init__(self, message):
# global scope of ahenk
scope = Scope().getInstance()
@ -28,7 +28,12 @@ class AnonymousMessager(ClientXMPP):
ClientXMPP.__init__(self, self.service, None)
self.message = message
self.receiver = self.configuration_manager.get('CONNECTION', 'receiverjid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/' + self.configuration_manager.get('CONNECTION', 'receiverresource')
self.receiver_resource = self.configuration_manager.get('CONNECTION', 'receiverresource')
self.receiver = self.configuration_manager.get('CONNECTION',
'receiverjid') + '@' + self.configuration_manager.get(
'CONNECTION', 'servicename')
if self.receiver_resource:
self.receiver += '/' + self.receiver_resource
self.logger.debug('[AnonymousMessenger] XMPP Receiver parameters were set')
@ -72,7 +77,7 @@ class AnonymousMessager(ClientXMPP):
return False
def recv_direct_message(self, msg):
if msg['type'] in ('normal'):
if msg['type'] in ['normal']:
self.logger.debug('[AnonymousMessenger] ---------->Received message: {}'.format(str(msg['body'])))
self.logger.debug('[AnonymousMessenger] Disconnecting...')
self.disconnect()

View file

@ -21,7 +21,9 @@ class Messenger(ClientXMPP):
self.event_manger = scope.getEventManager()
self.execution_manager = scope.getExecutionManager()
self.my_jid = str(self.configuration_manager.get('CONNECTION', 'uid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename'))
self.my_jid = str(
self.configuration_manager.get('CONNECTION', 'uid') + '@' + self.configuration_manager.get('CONNECTION',
'servicename'))
self.my_pass = str(self.configuration_manager.get('CONNECTION', 'password'))
ClientXMPP.__init__(self, self.my_jid, self.my_pass)
@ -30,8 +32,15 @@ class Messenger(ClientXMPP):
self.auto_subscribe = True
self.hostname = self.configuration_manager.get('CONNECTION', 'host')
self.resource_name = self.configuration_manager.get('CONNECTION', 'receiverresource')
self.receiver = self.configuration_manager.get('CONNECTION', 'receiverjid') + '@' + self.configuration_manager.get('CONNECTION', 'servicename') + '/' + self.resource_name
self.receiver_resource = self.configuration_manager.get('CONNECTION', 'receiverresource')
self.receiver = self.configuration_manager.get('CONNECTION',
'receiverjid') + '@' + self.configuration_manager.get(
'CONNECTION', 'servicename')
if self.receiver_resource:
self.receiver += '/' + self.receiver_resource
self.logger.debug('[Messenger] XMPP Messager parameters were set')
self.register_extensions()
@ -79,10 +88,11 @@ class Messenger(ClientXMPP):
self.logger.debug('[Messenger] <<--------Sending message: {}'.format(msg))
self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
except Exception as e:
self.logger.error('[Messenger] A problem occurred while sending direct message. Error Message: {}'.format(str(e)))
self.logger.error(
'[Messenger] A problem occurred while sending direct message. Error Message: {}'.format(str(e)))
def recv_direct_message(self, msg):
if msg['type'] in ('normal'):
if msg['type'] in ['normal']:
self.logger.debug('[Messenger] ---------->Received message: {}'.format(str(msg['body'])))
try:
j = json.loads(str(msg['body']))
@ -90,4 +100,5 @@ class Messenger(ClientXMPP):
self.event_manger.fireEvent(message_type, str(msg['body']))
self.logger.debug('[Messenger] Fired event is: {}'.format(message_type))
except Exception as e:
self.logger.error('[Messenger] A problem occurred while keeping message. Error Message: {}'.format(str(e)))
self.logger.error(
'[Messenger] A problem occurred while keeping message. Error Message: {}'.format(str(e)))

View file

@ -8,7 +8,7 @@ import uuid
from uuid import getnode as get_mac
from base.Scope import Scope
from base.messaging.AnonymousMessenger import AnonymousMessager
from base.messaging.AnonymousMessenger import AnonymousMessenger
from base.system.system import System
from base.timer.setup_timer import SetupTimer
from base.timer.timer import Timer
@ -35,7 +35,7 @@ class Registration:
self.logger.debug('[Registration] Requesting registration')
SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,
checker_func=self.is_registered, kwargs=None))
anon_messenger = AnonymousMessager(self.message_manager.registration_msg())
anon_messenger = AnonymousMessenger(self.message_manager.registration_msg())
anon_messenger.connect_to_server()
def ldap_registration_request(self):