Improve connectivity handling (Thank you. mathieui).

This commit is contained in:
Schimon Jehudah, Adv. 2025-03-10 11:05:35 +02:00
parent 3fa7aa9b40
commit a6ef961a55
2 changed files with 13 additions and 12 deletions

View file

@ -1274,20 +1274,21 @@ class HttpInstance:
response: Response,
jabber_id: str = Form(...),
password: str = Form(...)):
request_url_path = request.url.path
function_name = sys._getframe().f_code.co_name
logger.debug(f'{function_name},{jabber_id},Start')
logger.debug(f'{function_name},{request_url_path},Start')
if not UtilitiesHttp.is_jid_matches_to_session(accounts, sessions, request):
# Store a variable in the request's state
request.app.state.jabber_id = jabber_id
session_key = str(random.random())
request.app.state.session_key = session_key
accounts[jabber_id] = XmppInstance(jabber_id + '/blasta', password)
breakpoint()
# accounts[jabber_id].authenticated
# dir(accounts[jabber_id])
# accounts[jabber_id].failed_auth
# accounts[jabber_id].event_when_connected
sessions[jabber_id] = session_key
if accounts[jabber_id].is_connected:
sessions[jabber_id] = session_key
else:
del accounts[jabber_id]
jabber_id = None
# Check if the user and password are present and valid
# If not valid, return "Could not connect to JID"
@ -1348,7 +1349,7 @@ class HttpInstance:
message = 'Blasta system message » Authorization has failed.'
description = 'Connection has failed'
path = 'error'
logger.error(f'{function_name},{request_url_path},{description}')
logger.error(f'{function_name},{jabber_id},{description}')
response = result_post(request, jabber_id, description, message, path)
logger.debug(f'{function_name},{request_url_path},Finish')
return response

View file

@ -24,22 +24,22 @@ class XmppInstance(ClientXMPP):
self.register_plugin('xep_0163') # XEP-0163: Personal Eventing Protocol
self.register_plugin('xep_0223') # XEP-0223: Persistent Storage of Private Data via PubSub
self.connect()
self.connection_accepted = False
self.is_connected = False
def on_connection_failed(self, event):
function_name = sys._getframe().f_code.co_name
logger.debug(f'{function_name},{event},Start')
self.connection_accepted = False
self.is_connected = False
logger.debug(f'{function_name},{event},Finish')
def on_failed_auth(self, event):
function_name = sys._getframe().f_code.co_name
logger.debug(f'{function_name},{event},Start')
self.connection_accepted = False
self.is_connected = False
logger.debug(f'{function_name},{event},Finish')
def on_session_start(self, event):
function_name = sys._getframe().f_code.co_name
logger.debug(f'{function_name},{event},Start')
self.connection_accepted = True
self.is_connected = True
logger.debug(f'{function_name},{event},Finish')