Re-org and start of API #47
3 changed files with 108 additions and 139 deletions
|
|
@ -24,7 +24,6 @@ def os_db_path(): # createdir=True):
|
||||||
|
|
||||||
|
|
||||||
def db_get():
|
def db_get():
|
||||||
try:
|
|
||||||
# Will create the database if it doesn't exist
|
# Will create the database if it doesn't exist
|
||||||
db = TinyDB(db_file())
|
db = TinyDB(db_file())
|
||||||
|
|
||||||
|
|
@ -36,12 +35,6 @@ def db_get():
|
||||||
|
|
||||||
return db
|
return db
|
||||||
|
|
||||||
except json.decoder.JSONDecodeError as jerr:
|
|
||||||
bumperlog.error("JsonErr: {} - Doc: {}".format(jerr.msg, jerr.doc))
|
|
||||||
|
|
||||||
except Exception as ex:
|
|
||||||
bumperlog.error(ex)
|
|
||||||
|
|
||||||
|
|
||||||
def user_add(userid):
|
def user_add(userid):
|
||||||
newuser = BumperUser()
|
newuser = BumperUser()
|
||||||
|
|
|
||||||
|
|
@ -354,7 +354,6 @@ class BumperMQTTServer_Plugin:
|
||||||
return authenticated
|
return authenticated
|
||||||
|
|
||||||
async def on_broker_client_connected(self, client_id):
|
async def on_broker_client_connected(self, client_id):
|
||||||
try:
|
|
||||||
|
|
||||||
didsplit = str(client_id).split("@")
|
didsplit = str(client_id).split("@")
|
||||||
|
|
||||||
|
|
@ -370,11 +369,8 @@ class BumperMQTTServer_Plugin:
|
||||||
bumper.client_set_mqtt(client["resource"], True)
|
bumper.client_set_mqtt(client["resource"], True)
|
||||||
return
|
return
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
mqttserverlog.exception("{}".format(e))
|
|
||||||
|
|
||||||
async def on_broker_client_disconnected(self, client_id):
|
async def on_broker_client_disconnected(self, client_id):
|
||||||
try:
|
|
||||||
didsplit = str(client_id).split("@")
|
didsplit = str(client_id).split("@")
|
||||||
|
|
||||||
bot = bumper.bot_get(didsplit[0])
|
bot = bumper.bot_get(didsplit[0])
|
||||||
|
|
@ -388,7 +384,3 @@ class BumperMQTTServer_Plugin:
|
||||||
if client:
|
if client:
|
||||||
bumper.client_set_mqtt(client["resource"], False)
|
bumper.client_set_mqtt(client["resource"], False)
|
||||||
return
|
return
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
mqttserverlog.exception("{}".format(e))
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class XMPPServer:
|
||||||
asyncio.create_task(bumper.shutdown())
|
asyncio.create_task(bumper.shutdown())
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
try:
|
|
||||||
xmppserverlog.debug("waiting for all clients to disconnect")
|
xmppserverlog.debug("waiting for all clients to disconnect")
|
||||||
for client in self.clients:
|
for client in self.clients:
|
||||||
client._disconnect()
|
client._disconnect()
|
||||||
|
|
@ -60,9 +60,6 @@ class XMPPServer:
|
||||||
xmppserverlog.debug("shutting down")
|
xmppserverlog.debug("shutting down")
|
||||||
self.server_coro.cancel()
|
self.server_coro.cancel()
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
xmppserverlog.error("{}".format(e))
|
|
||||||
|
|
||||||
|
|
||||||
class XMPPServer_Protocol(asyncio.Protocol):
|
class XMPPServer_Protocol(asyncio.Protocol):
|
||||||
client_id = None
|
client_id = None
|
||||||
|
|
@ -615,17 +612,12 @@ class XMPPAsyncClient:
|
||||||
xmppserverlog.exception("{}".format(e))
|
xmppserverlog.exception("{}".format(e))
|
||||||
|
|
||||||
def _handle_session(self, xml):
|
def _handle_session(self, xml):
|
||||||
try:
|
|
||||||
res = '<iq type="result" id="{}" />'.format(xml.get("id"))
|
res = '<iq type="result" id="{}" />'.format(xml.get("id"))
|
||||||
self._set_state("READY")
|
self._set_state("READY")
|
||||||
self.send(res)
|
self.send(res)
|
||||||
asyncio.Task(self.schedule_ping(30))
|
asyncio.Task(self.schedule_ping(30))
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
xmppserverlog.exception("{}".format(e))
|
|
||||||
|
|
||||||
def _handle_presence(self, xml):
|
def _handle_presence(self, xml):
|
||||||
try:
|
|
||||||
|
|
||||||
if len(xml) and xml[0].tag == "status":
|
if len(xml) and xml[0].tag == "status":
|
||||||
xmppserverlog.debug(
|
xmppserverlog.debug(
|
||||||
|
|
@ -636,9 +628,7 @@ class XMPPAsyncClient:
|
||||||
# Most likely a bot, possibly hello world in text
|
# Most likely a bot, possibly hello world in text
|
||||||
|
|
||||||
# Send dummy return
|
# Send dummy return
|
||||||
self.send(
|
self.send('<presence to="{}"> dummy </presence>'.format(self.bumper_jid))
|
||||||
'<presence to="{}"> dummy </presence>'.format(self.bumper_jid)
|
|
||||||
)
|
|
||||||
|
|
||||||
# If it is a BOT, send extras
|
# If it is a BOT, send extras
|
||||||
if self.type == self.BOT:
|
if self.type == self.BOT:
|
||||||
|
|
@ -687,9 +677,6 @@ class XMPPAsyncClient:
|
||||||
'<presence to="{}"> dummy </presence>'.format(self.bumper_jid)
|
'<presence to="{}"> dummy </presence>'.format(self.bumper_jid)
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
xmppserverlog.exception("{}".format(e))
|
|
||||||
|
|
||||||
def _parse_data(self, data):
|
def _parse_data(self, data):
|
||||||
|
|
||||||
if data.decode("utf-8").startswith(
|
if data.decode("utf-8").startswith(
|
||||||
|
|
@ -804,7 +791,7 @@ class XMPPAsyncClient:
|
||||||
xmppserverlog.exception("{}".format(e))
|
xmppserverlog.exception("{}".format(e))
|
||||||
|
|
||||||
def _handle_iq(self, xml, data):
|
def _handle_iq(self, xml, data):
|
||||||
try:
|
|
||||||
if len(xml):
|
if len(xml):
|
||||||
child = self._tag_strip_uri(xml[0].tag)
|
child = self._tag_strip_uri(xml[0].tag)
|
||||||
else:
|
else:
|
||||||
|
|
@ -832,6 +819,3 @@ class XMPPAsyncClient:
|
||||||
self._handle_result(xml, data)
|
self._handle_result(xml, data)
|
||||||
else:
|
else:
|
||||||
self._handle_result(xml, data)
|
self._handle_result(xml, data)
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
xmppserverlog.exception("{}".format(e))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue