comparison sat_pubsub/pgsql_storage.py @ 406:a58610ab2983

removed old code: - removed gateway which was an HTTP gateway inherited from Idavoll and which is not used is SàT Pubsub - removed memory_storage which has not been maintained since Idavoll and which is expected to be replaced by a sqlite-based backend - simplejson dependency is not used anymore
author Goffi <goffi@goffi.org>
date Fri, 16 Aug 2019 12:00:03 +0200
parents c56a728412f1
children ccb2a22ea0fc
comparison
equal deleted inserted replaced
405:c56a728412f1 406:a58610ab2983
1298 1298
1299 1299
1300 class CollectionNode(Node): 1300 class CollectionNode(Node):
1301 1301
1302 nodeType = 'collection' 1302 nodeType = 'collection'
1303
1304
1305
1306 class GatewayStorage(object):
1307 """
1308 Memory based storage facility for the XMPP-HTTP gateway.
1309 """
1310
1311 def __init__(self, dbpool):
1312 self.dbpool = dbpool
1313
1314 def _countCallbacks(self, cursor, service, nodeIdentifier):
1315 """
1316 Count number of callbacks registered for a node.
1317 """
1318 cursor.execute("""SELECT count(*) FROM callbacks
1319 WHERE service=%s and node=%s""",
1320 (service.full(),
1321 nodeIdentifier))
1322 results = cursor.fetchall()
1323 return results[0][0]
1324
1325 def addCallback(self, service, nodeIdentifier, callback):
1326 def interaction(cursor):
1327 cursor.execute("""SELECT 1 as bool FROM callbacks
1328 WHERE service=%s and node=%s and uri=%s""",
1329 (service.full(),
1330 nodeIdentifier,
1331 callback))
1332 if cursor.fetchall():
1333 return
1334
1335 cursor.execute("""INSERT INTO callbacks
1336 (service, node, uri) VALUES
1337 (%s, %s, %s)""",
1338 (service.full(),
1339 nodeIdentifier,
1340 callback))
1341
1342 return self.dbpool.runInteraction(interaction)
1343
1344 def removeCallback(self, service, nodeIdentifier, callback):
1345 def interaction(cursor):
1346 cursor.execute("""DELETE FROM callbacks
1347 WHERE service=%s and node=%s and uri=%s""",
1348 (service.full(),
1349 nodeIdentifier,
1350 callback))
1351
1352 if cursor.rowcount != 1:
1353 raise error.NotSubscribed()
1354
1355 last = not self._countCallbacks(cursor, service, nodeIdentifier)
1356 return last
1357
1358 return self.dbpool.runInteraction(interaction)
1359
1360 def getCallbacks(self, service, nodeIdentifier):
1361 def interaction(cursor):
1362 cursor.execute("""SELECT uri FROM callbacks
1363 WHERE service=%s and node=%s""",
1364 (service.full(),
1365 nodeIdentifier))
1366 results = cursor.fetchall()
1367
1368 if not results:
1369 raise error.NoCallbacks()
1370
1371 return [result[0] for result in results]
1372
1373 return self.dbpool.runInteraction(interaction)
1374
1375 def hasCallbacks(self, service, nodeIdentifier):
1376 def interaction(cursor):
1377 return bool(self._countCallbacks(cursor, service, nodeIdentifier))
1378
1379 return self.dbpool.runInteraction(interaction)