Refactor probe sending
darcs-hash:20070408175758-86b55-933dcd6fc56871993bd9b8dfecd98b61d68db070.gz
This commit is contained in:
@@ -103,9 +103,6 @@ class JCLComponent(Component, object):
|
|||||||
signal.signal(signal.SIGINT, self.signal_handler)
|
signal.signal(signal.SIGINT, self.signal_handler)
|
||||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||||
|
|
||||||
# TODO : delete
|
|
||||||
self.account_classes = (Account,)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Main loop
|
"""Main loop
|
||||||
Connect to Jabber server
|
Connect to Jabber server
|
||||||
@@ -206,21 +203,7 @@ class JCLComponent(Component, object):
|
|||||||
|
|
||||||
self.stream.set_message_handler("normal", \
|
self.stream.set_message_handler("normal", \
|
||||||
self.handle_message)
|
self.handle_message)
|
||||||
current_jid = None
|
self.send_stanzas(self.account_manager.probe_all_accounts_presence())
|
||||||
self.db_connect()
|
|
||||||
for _account in self.account_classes[0].select(clauseTables = ["account"], \
|
|
||||||
orderBy = "user_jid"):
|
|
||||||
if _account.user_jid != current_jid:
|
|
||||||
presence = Presence(from_jid = unicode(self.jid), \
|
|
||||||
to_jid = _account.user_jid, \
|
|
||||||
stanza_type = "probe")
|
|
||||||
self.stream.send(presence)
|
|
||||||
current_jid = _account.user_jid
|
|
||||||
presence = Presence(from_jid = _account.jid, \
|
|
||||||
to_jid = _account.user_jid, \
|
|
||||||
stanza_type = "probe")
|
|
||||||
self.stream.send(presence)
|
|
||||||
self.db_disconnect()
|
|
||||||
|
|
||||||
def signal_handler(self, signum, frame):
|
def signal_handler(self, signum, frame):
|
||||||
"""Stop method handler
|
"""Stop method handler
|
||||||
@@ -455,9 +438,9 @@ class JCLComponent(Component, object):
|
|||||||
name = message.get_to().node
|
name = message.get_to().node
|
||||||
base_from_jid = unicode(message.get_from().bare())
|
base_from_jid = unicode(message.get_from().bare())
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = self.account_classes[0].select(\
|
accounts = Account.select(\
|
||||||
AND(self.account_classes[0].q.name == name, \
|
AND(Account.q.name == name, \
|
||||||
self.account_classes[0].q.user_jid == base_from_jid))
|
Account.q.user_jid == base_from_jid))
|
||||||
if accounts.count() == 1:
|
if accounts.count() == 1:
|
||||||
_account = list(accounts)[0]
|
_account = list(accounts)[0]
|
||||||
if hasattr(_account, 'password') \
|
if hasattr(_account, 'password') \
|
||||||
@@ -896,6 +879,10 @@ class AccountManager(object):
|
|||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def probe_all_accounts_presence(self):
|
||||||
|
"""Send presence probe to all registered accounts"""
|
||||||
|
return self.send_presence_all("probe")
|
||||||
|
|
||||||
###### Utils methods ######
|
###### Utils methods ######
|
||||||
def _has_account(self, from_jid, name = None):
|
def _has_account(self, from_jid, name = None):
|
||||||
"""Check if user with \"from_jid\" JID has an account.
|
"""Check if user with \"from_jid\" JID has an account.
|
||||||
@@ -1016,32 +1003,38 @@ class AccountManager(object):
|
|||||||
"""Compose account jid from account name"""
|
"""Compose account jid from account name"""
|
||||||
return name + u"@" + unicode(self.component.jid)
|
return name + u"@" + unicode(self.component.jid)
|
||||||
|
|
||||||
|
def _send_presence_probe_root(self, to_jid):
|
||||||
|
"""Send presence probe to account's user from root JID"""
|
||||||
|
return [Presence(from_jid = self.component.jid, \
|
||||||
|
to_jid = to_jid, \
|
||||||
|
stanza_type = "probe")]
|
||||||
|
|
||||||
|
def _send_presence_probe(self, _account):
|
||||||
|
"""Send presence probe to account's user"""
|
||||||
|
return [Presence(from_jid = _account.jid, \
|
||||||
|
to_jid = _account.user_jid, \
|
||||||
|
stanza_type = "probe")]
|
||||||
|
|
||||||
def _send_presence_unavailable_root(self, to_jid):
|
def _send_presence_unavailable_root(self, to_jid):
|
||||||
"""Send unavailable presence to account's user from root JID"""
|
"""Send unavailable presence to account's user from root JID"""
|
||||||
result = []
|
return [Presence(from_jid = self.component.jid, \
|
||||||
result.append(Presence(from_jid = self.component.jid, \
|
to_jid = to_jid, \
|
||||||
to_jid = to_jid, \
|
stanza_type = "unavailable")]
|
||||||
stanza_type = "unavailable"))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _send_presence_unavailable(self, _account):
|
def _send_presence_unavailable(self, _account):
|
||||||
"""Send unavailable presence to account's user"""
|
"""Send unavailable presence to account's user"""
|
||||||
result = []
|
|
||||||
_account.status = account.OFFLINE
|
_account.status = account.OFFLINE
|
||||||
result.append(Presence(from_jid = _account.jid, \
|
return [Presence(from_jid = _account.jid, \
|
||||||
to_jid = _account.user_jid, \
|
to_jid = _account.user_jid, \
|
||||||
stanza_type = "unavailable"))
|
stanza_type = "unavailable")]
|
||||||
return result
|
|
||||||
|
|
||||||
def _send_presence_available_root(self, to_jid, show, status_msg):
|
def _send_presence_available_root(self, to_jid, show, status_msg):
|
||||||
"""Send available presence to account's user from root JID"""
|
"""Send available presence to account's user from root JID"""
|
||||||
result = []
|
return [Presence(from_jid = self.component.jid, \
|
||||||
result.append(Presence(from_jid = self.component.jid, \
|
to_jid = to_jid, \
|
||||||
to_jid = to_jid, \
|
status = status_msg, \
|
||||||
status = status_msg, \
|
show = show, \
|
||||||
show = show, \
|
stanza_type = "available")]
|
||||||
stanza_type = "available"))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _send_presence_available(self, _account, show, lang_class):
|
def _send_presence_available(self, _account, show, lang_class):
|
||||||
"""Send available presence to account's user and ask for password
|
"""Send available presence to account's user and ask for password
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import logging
|
|||||||
|
|
||||||
from jcl.jabber.component import JCLComponent
|
from jcl.jabber.component import JCLComponent
|
||||||
from jcl.lang import Lang
|
from jcl.lang import Lang
|
||||||
|
from jcl.model.account import Account
|
||||||
|
|
||||||
class FeederComponent(JCLComponent):
|
class FeederComponent(JCLComponent):
|
||||||
"""Implement a feeder sender behavior based on the
|
"""Implement a feeder sender behavior based on the
|
||||||
@@ -61,8 +62,8 @@ class FeederComponent(JCLComponent):
|
|||||||
def handle_tick(self):
|
def handle_tick(self):
|
||||||
"""Implement main feed/send behavior"""
|
"""Implement main feed/send behavior"""
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.account_classes[0].select(clauseTables = ["account"], \
|
for _account in Account.select(clauseTables = ["account"], \
|
||||||
orderBy = "user_jid"):
|
orderBy = "user_jid"):
|
||||||
for data in self.feeder.feed(_account):
|
for data in self.feeder.feed(_account):
|
||||||
self.sender.send(_account, data)
|
self.sender.send(_account, data)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
|
|||||||
Reference in New Issue
Block a user