mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
resource fixed and code formatted
This commit is contained in:
parent
18c65ca87b
commit
bf37183005
3 changed files with 29 additions and 13 deletions
|
@ -6,12 +6,12 @@ import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from sleekxmpp import ClientXMPP
|
from sleekxmpp import ClientXMPP
|
||||||
|
|
||||||
sys.path.append('../..')
|
|
||||||
from base.Scope import Scope
|
from base.Scope import Scope
|
||||||
|
|
||||||
|
sys.path.append('../..')
|
||||||
|
|
||||||
class AnonymousMessager(ClientXMPP):
|
|
||||||
|
class AnonymousMessenger(ClientXMPP):
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
# global scope of ahenk
|
# global scope of ahenk
|
||||||
scope = Scope().getInstance()
|
scope = Scope().getInstance()
|
||||||
|
@ -28,7 +28,12 @@ class AnonymousMessager(ClientXMPP):
|
||||||
ClientXMPP.__init__(self, self.service, None)
|
ClientXMPP.__init__(self, self.service, None)
|
||||||
|
|
||||||
self.message = message
|
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')
|
self.logger.debug('[AnonymousMessenger] XMPP Receiver parameters were set')
|
||||||
|
|
||||||
|
@ -72,7 +77,7 @@ class AnonymousMessager(ClientXMPP):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def recv_direct_message(self, msg):
|
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] ---------->Received message: {}'.format(str(msg['body'])))
|
||||||
self.logger.debug('[AnonymousMessenger] Disconnecting...')
|
self.logger.debug('[AnonymousMessenger] Disconnecting...')
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
|
@ -21,7 +21,9 @@ class Messenger(ClientXMPP):
|
||||||
self.event_manger = scope.getEventManager()
|
self.event_manger = scope.getEventManager()
|
||||||
self.execution_manager = scope.getExecutionManager()
|
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'))
|
self.my_pass = str(self.configuration_manager.get('CONNECTION', 'password'))
|
||||||
|
|
||||||
ClientXMPP.__init__(self, self.my_jid, self.my_pass)
|
ClientXMPP.__init__(self, self.my_jid, self.my_pass)
|
||||||
|
@ -30,8 +32,15 @@ class Messenger(ClientXMPP):
|
||||||
self.auto_subscribe = True
|
self.auto_subscribe = True
|
||||||
|
|
||||||
self.hostname = self.configuration_manager.get('CONNECTION', 'host')
|
self.hostname = self.configuration_manager.get('CONNECTION', 'host')
|
||||||
self.resource_name = 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') + '/' + self.resource_name
|
|
||||||
|
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.logger.debug('[Messenger] XMPP Messager parameters were set')
|
||||||
|
|
||||||
self.register_extensions()
|
self.register_extensions()
|
||||||
|
@ -79,10 +88,11 @@ class Messenger(ClientXMPP):
|
||||||
self.logger.debug('[Messenger] <<--------Sending message: {}'.format(msg))
|
self.logger.debug('[Messenger] <<--------Sending message: {}'.format(msg))
|
||||||
self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
|
self.send_message(mto=self.receiver, mbody=msg, mtype='normal')
|
||||||
except Exception as e:
|
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):
|
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'])))
|
self.logger.debug('[Messenger] ---------->Received message: {}'.format(str(msg['body'])))
|
||||||
try:
|
try:
|
||||||
j = json.loads(str(msg['body']))
|
j = json.loads(str(msg['body']))
|
||||||
|
@ -90,4 +100,5 @@ class Messenger(ClientXMPP):
|
||||||
self.event_manger.fireEvent(message_type, str(msg['body']))
|
self.event_manger.fireEvent(message_type, str(msg['body']))
|
||||||
self.logger.debug('[Messenger] Fired event is: {}'.format(message_type))
|
self.logger.debug('[Messenger] Fired event is: {}'.format(message_type))
|
||||||
except Exception as e:
|
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)))
|
||||||
|
|
|
@ -8,7 +8,7 @@ import uuid
|
||||||
from uuid import getnode as get_mac
|
from uuid import getnode as get_mac
|
||||||
|
|
||||||
from base.Scope import Scope
|
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.system.system import System
|
||||||
from base.timer.setup_timer import SetupTimer
|
from base.timer.setup_timer import SetupTimer
|
||||||
from base.timer.timer import Timer
|
from base.timer.timer import Timer
|
||||||
|
@ -35,7 +35,7 @@ class Registration:
|
||||||
self.logger.debug('[Registration] Requesting registration')
|
self.logger.debug('[Registration] Requesting registration')
|
||||||
SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,
|
SetupTimer.start(Timer(System.Ahenk.registration_timeout(), timeout_function=self.registration_timeout,
|
||||||
checker_func=self.is_registered, kwargs=None))
|
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()
|
anon_messenger.connect_to_server()
|
||||||
|
|
||||||
def ldap_registration_request(self):
|
def ldap_registration_request(self):
|
||||||
|
|
Loading…
Reference in a new issue