From f8bdfca972308753e4e6ac9a2528705537b06d77 Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Fri, 31 May 2024 14:58:49 +0300 Subject: [PATCH] Segregate XMPP (Jabber) client and component; each to its respective module. --- slixfeed/__main__.py | 71 -------------------------------------- slixfeed/version.py | 4 +-- slixfeed/xmpp/client.py | 48 ++++++++++++++++++++++++++ slixfeed/xmpp/component.py | 28 +++++++++++++++ 4 files changed, 78 insertions(+), 73 deletions(-) diff --git a/slixfeed/__main__.py b/slixfeed/__main__.py index 10a94fa..492094c 100644 --- a/slixfeed/__main__.py +++ b/slixfeed/__main__.py @@ -107,82 +107,11 @@ match account_mode: class JabberComponent: def __init__(self, jid, secret, hostname, port, alias=None): xmpp = SlixfeedComponent(jid, secret, hostname, port, alias) - xmpp.register_plugin('xep_0004') # Data Forms - xmpp.register_plugin('xep_0030') # Service Discovery - xmpp.register_plugin('xep_0045') # Multi-User Chat - # xmpp.register_plugin('xep_0048') # Bookmarks - xmpp.register_plugin('xep_0050') # Ad-Hoc Commands - xmpp.register_plugin('xep_0054') # vcard-temp - xmpp.register_plugin('xep_0060') # Publish-Subscribe - # xmpp.register_plugin('xep_0065') # SOCKS5 Bytestreams - xmpp.register_plugin('xep_0066') # Out of Band Data - xmpp.register_plugin('xep_0071') # XHTML-IM - xmpp.register_plugin('xep_0084') # User Avatar - xmpp.register_plugin('xep_0085') # Chat State Notifications - xmpp.register_plugin('xep_0115') # Entity Capabilities - xmpp.register_plugin('xep_0122') # Data Forms Validation - xmpp.register_plugin('xep_0153') # vCard-Based Avatars - xmpp.register_plugin('xep_0199') # XMPP Ping - xmpp.register_plugin('xep_0203') # Delayed Delivery - xmpp.register_plugin('xep_0249') # Direct MUC Invitations - xmpp.register_plugin('xep_0297') # Stanza Forwarding - xmpp.register_plugin('xep_0356') # Privileged Entity - xmpp.register_plugin('xep_0363') # HTTP File Upload - xmpp.register_plugin('xep_0402') # PEP Native Bookmarks - xmpp.register_plugin('xep_0444') # Message Reactions - xmpp.connect() - xmpp.process() class JabberClient: def __init__(self, jid, password, hostname=None, port=None, alias=None): xmpp = Slixfeed(jid, password, hostname, port, alias) - xmpp.register_plugin('xep_0004') # Data Forms - xmpp.register_plugin('xep_0030') # Service Discovery - xmpp.register_plugin('xep_0045') # Multi-User Chat - xmpp.register_plugin('xep_0048') # Bookmarks - xmpp.register_plugin('xep_0050') # Ad-Hoc Commands - xmpp.register_plugin('xep_0054') # vcard-temp - xmpp.register_plugin('xep_0060') # Publish-Subscribe - # xmpp.register_plugin('xep_0065') # SOCKS5 Bytestreams - xmpp.register_plugin('xep_0066') # Out of Band Data - xmpp.register_plugin('xep_0071') # XHTML-IM - xmpp.register_plugin('xep_0084') # User Avatar - xmpp.register_plugin('xep_0085') # Chat State Notifications - xmpp.register_plugin('xep_0115') # Entity Capabilities - xmpp.register_plugin('xep_0122') # Data Forms Validation - xmpp.register_plugin('xep_0153') # vCard-Based Avatars - xmpp.register_plugin('xep_0199', {'keepalive': True}) # XMPP Ping - xmpp.register_plugin('xep_0249') # Direct MUC Invitations - xmpp.register_plugin('xep_0363') # HTTP File Upload - xmpp.register_plugin('xep_0402') # PEP Native Bookmarks - xmpp.register_plugin('xep_0444') # Message Reactions - - # proxy_enabled = config.get_value('accounts', 'XMPP', 'proxy_enabled') - # if proxy_enabled == '1': - # values = config.get_value('accounts', 'XMPP', [ - # 'proxy_host', - # 'proxy_port', - # 'proxy_username', - # 'proxy_password' - # ]) - # print('Proxy is enabled: {}:{}'.format(values[0], values[1])) - # xmpp.use_proxy = True - # xmpp.proxy_config = { - # 'host': values[0], - # 'port': values[1], - # 'username': values[2], - # 'password': values[3] - # } - # proxy = {'socks5': (values[0], values[1])} - # xmpp.proxy = {'socks5': ('localhost', 9050)} - - # Connect to the XMPP server and start processing XMPP stanzas. - if hostname and port: - xmpp.connect((hostname, port)) - else: - xmpp.connect() - xmpp.process() def main(): diff --git a/slixfeed/version.py b/slixfeed/version.py index d389854..1f6e480 100644 --- a/slixfeed/version.py +++ b/slixfeed/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.69' -__version_info__ = (0, 1, 69) +__version__ = '0.1.70' +__version_info__ = (0, 1, 70) diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index 977b8e7..67746be 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -149,6 +149,47 @@ class Slixfeed(slixmpp.ClientXMPP): self.max_connection_attempts = 10 self.reconnect_timeout = config.get_values('accounts.toml', 'xmpp')['settings']['reconnect_timeout'] + self.register_plugin('xep_0004') # Data Forms + self.register_plugin('xep_0030') # Service Discovery + self.register_plugin('xep_0045') # Multi-User Chat + self.register_plugin('xep_0048') # Bookmarks + self.register_plugin('xep_0050') # Ad-Hoc Commands + self.register_plugin('xep_0054') # vcard-temp + self.register_plugin('xep_0060') # Publish-Subscribe + # self.register_plugin('xep_0065') # SOCKS5 Bytestreams + self.register_plugin('xep_0066') # Out of Band Data + self.register_plugin('xep_0071') # XHTML-IM + self.register_plugin('xep_0084') # User Avatar + self.register_plugin('xep_0085') # Chat State Notifications + self.register_plugin('xep_0115') # Entity Capabilities + self.register_plugin('xep_0122') # Data Forms Validation + self.register_plugin('xep_0153') # vCard-Based Avatars + self.register_plugin('xep_0199', {'keepalive': True}) # XMPP Ping + self.register_plugin('xep_0203') # Delayed Delivery + self.register_plugin('xep_0249') # Direct MUC Invitations + self.register_plugin('xep_0363') # HTTP File Upload + self.register_plugin('xep_0402') # PEP Native Bookmarks + self.register_plugin('xep_0444') # Message Reactions + + # proxy_enabled = config.get_value('accounts', 'XMPP', 'proxy_enabled') + # if proxy_enabled == '1': + # values = config.get_value('accounts', 'XMPP', [ + # 'proxy_host', + # 'proxy_port', + # 'proxy_username', + # 'proxy_password' + # ]) + # print('Proxy is enabled: {}:{}'.format(values[0], values[1])) + # self.use_proxy = True + # self.proxy_config = { + # 'host': values[0], + # 'port': values[1], + # 'username': values[2], + # 'password': values[3] + # } + # proxy = {'socks5': (values[0], values[1])} + # self.proxy = {'socks5': ('localhost', 9050)} + self.add_event_handler("session_start", self.on_session_start) self.add_event_handler("session_resumed", @@ -208,6 +249,13 @@ class Slixfeed(slixmpp.ClientXMPP): self.add_event_handler('session_end', self.on_session_end) + # Connect to the XMPP server and start processing XMPP stanzas. + if hostname and port: + self.connect((hostname, port)) + else: + self.connect() + self.process() + # TODO Test async def on_groupchat_invite(self, message): diff --git a/slixfeed/xmpp/component.py b/slixfeed/xmpp/component.py index f5ff3ca..23111d5 100644 --- a/slixfeed/xmpp/component.py +++ b/slixfeed/xmpp/component.py @@ -139,6 +139,30 @@ class SlixfeedComponent(slixmpp.ComponentXMPP): self.max_connection_attempts = 10 self.reconnect_timeout = config.get_values('accounts.toml', 'xmpp')['settings']['reconnect_timeout'] + self.register_plugin('xep_0004') # Data Forms + self.register_plugin('xep_0030') # Service Discovery + self.register_plugin('xep_0045') # Multi-User Chat + # self.register_plugin('xep_0048') # Bookmarks + self.register_plugin('xep_0050') # Ad-Hoc Commands + self.register_plugin('xep_0054') # vcard-temp + self.register_plugin('xep_0060') # Publish-Subscribe + # self.register_plugin('xep_0065') # SOCKS5 Bytestreams + self.register_plugin('xep_0066') # Out of Band Data + self.register_plugin('xep_0071') # XHTML-IM + self.register_plugin('xep_0084') # User Avatar + self.register_plugin('xep_0085') # Chat State Notifications + self.register_plugin('xep_0115') # Entity Capabilities + self.register_plugin('xep_0122') # Data Forms Validation + self.register_plugin('xep_0153') # vCard-Based Avatars + self.register_plugin('xep_0199') # XMPP Ping + self.register_plugin('xep_0203') # Delayed Delivery + self.register_plugin('xep_0249') # Direct MUC Invitations + self.register_plugin('xep_0297') # Stanza Forwarding + self.register_plugin('xep_0356') # Privileged Entity + self.register_plugin('xep_0363') # HTTP File Upload + self.register_plugin('xep_0402') # PEP Native Bookmarks + self.register_plugin('xep_0444') # Message Reactions + self.add_event_handler("session_start", self.on_session_start) self.add_event_handler("session_resumed", @@ -198,6 +222,10 @@ class SlixfeedComponent(slixmpp.ComponentXMPP): self.add_event_handler('session_end', self.on_session_end) + # Connect to the XMPP server and start processing XMPP stanzas. + self.connect() + self.process() + async def on_groupchat_invite(self, message): # logging.warning("on_groupchat_invite")