about summary refs log tree commit diff stats
path: root/src/xmpp/jid.c
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2019-04-12 11:46:01 +0200
committerPaul Fariello <paul@fariello.eu>2019-04-12 15:49:54 +0200
commit9714d1d867bac6fdbc3d124f923a36a1dc2ea504 (patch)
tree9a9b1c2951e91e1cb13a2c85b1b94d6efb2c466b /src/xmpp/jid.c
parent0dfe61c01cddf48a0a614927bb29a52625464525 (diff)
downloadprofani-tty-9714d1d867bac6fdbc3d124f923a36a1dc2ea504.tar.gz
Add random string at the end of the default resource
When connecting for the first time or when creating a new account don't
use only 'profanity' as default resource.

Some server don't support having 2 connection with same resource. Using
profanity as default lead to deconnections.
Diffstat (limited to 'src/xmpp/jid.c')
-rw-r--r--src/xmpp/jid.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c
index 51e1fa3c..49bf7b9c 100644
--- a/src/xmpp/jid.c
+++ b/src/xmpp/jid.c
@@ -194,3 +194,22 @@ jid_fulljid_or_barejid(Jid *jid)
         return jid->barejid;
     }
 }
+
+char*
+jid_random_resource(void)
+{
+    GRand *prng;
+    char rand[5];
+    char alphabet[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+    prng = g_rand_new();
+
+    int i;
+    for (i = 0; i < 4; i++) {
+        rand[i] = alphabet[g_rand_int_range(prng, 0, sizeof(alphabet))];
+    }
+    rand[4] = '\0';
+    g_rand_free(prng);
+
+    return g_strdup_printf("profanity.%s", rand);
+}