summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-06-28 15:09:02 +0200
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-06-28 15:09:02 +0200
commitfbe376b6db019adbcf32a7b869cba600c5503f8e (patch)
tree7bd3e06f615a742adbaf569201c2ebe985c7764e
parent7b3a116d7602a25dd71b16133be44a35cb3d7cf1 (diff)
downloadpoezio-fbe376b6db019adbcf32a7b869cba600c5503f8e.tar.gz
poezio-fbe376b6db019adbcf32a7b869cba600c5503f8e.tar.bz2
poezio-fbe376b6db019adbcf32a7b869cba600c5503f8e.tar.xz
poezio-fbe376b6db019adbcf32a7b869cba600c5503f8e.zip
Reintroduce the concept of resource, but named device_id and generated.
-rw-r--r--data/default_config.cfg4
-rw-r--r--poezio/config.py1
-rw-r--r--poezio/connection.py10
3 files changed, 15 insertions, 0 deletions
diff --git a/data/default_config.cfg b/data/default_config.cfg
index a71fa42c..3b8d17f0 100644
--- a/data/default_config.cfg
+++ b/data/default_config.cfg
@@ -22,6 +22,10 @@ password =
# manager like secret-tool on gnome, or anything you want
eval_password =
+# This identifies this client over time with the server, to let it optimise
+# offline storage and various other features.
+device_id =
+
# Path to a PEM certificate file to use for certificate authentication
# through SASL External. If set, keyfile MUST be provided as well in
# order to login.
diff --git a/poezio/config.py b/poezio/config.py
index e90cac8b..ed295c92 100644
--- a/poezio/config.py
+++ b/poezio/config.py
@@ -47,6 +47,7 @@ DEFAULT_CONFIG = {
'data_dir': '',
'default_nick': '',
'deterministic_nick_colors': True,
+ 'device_id': '',
'nick_color_aliases': True,
'display_activity_notifications': False,
'display_gaming_notifications': False,
diff --git a/poezio/connection.py b/poezio/connection.py
index 8a74635d..c97365f8 100644
--- a/poezio/connection.py
+++ b/poezio/connection.py
@@ -14,6 +14,8 @@ log = logging.getLogger(__name__)
import getpass
import subprocess
import sys
+import base64
+import random
import slixmpp
from slixmpp.xmlstream import ET
@@ -38,6 +40,13 @@ class Connection(slixmpp.ClientXMPP):
keyfile = config.get('keyfile')
certfile = config.get('certfile')
+ device_id = config.get('device_id')
+ if not device_id:
+ rng = random.SystemRandom()
+ device_id = base64.urlsafe_b64encode(
+ rng.getrandbits(24).to_bytes(3, 'little')).decode('ascii')
+ config.set_and_save('device_id', device_id)
+
if config.get('jid'):
# Field used to know if we are anonymous or not.
# many features will be handled differently
@@ -72,6 +81,7 @@ class Connection(slixmpp.ClientXMPP):
jid = config.get('server')
password = None
jid = safeJID(jid)
+ jid.resource = '%s-%s' % (jid.resource, device_id) if jid.resource else 'poezio-%s' % device_id
# TODO: use the system language
slixmpp.ClientXMPP.__init__(
self, jid, password, lang=config.get('lang'))