about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-05-25 13:04:19 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-05-25 13:04:19 +0200
commitde8975c008aa4016e7bc1b817a62d90f9f45cefa (patch)
tree20d979e8f67895d39ca8fee74e5b49999839ac2c /src/xmpp
parent4b5711fad5585149de65319a8f27cb7ba3a439a5 (diff)
downloadprofani-tty-de8975c008aa4016e7bc1b817a62d90f9f45cefa.tar.gz
Add and use connection_get_barejid()
Instead of connection_get_fulljid() and then creating a Jid from it.
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/connection.c12
-rw-r--r--src/xmpp/message.c8
-rw-r--r--src/xmpp/muc.c6
-rw-r--r--src/xmpp/roster.c8
-rw-r--r--src/xmpp/xmpp.h1
5 files changed, 24 insertions, 11 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 013a09e1..18b177c6 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -411,6 +411,18 @@ connection_get_fulljid(void)
     }
 }
 
+char*
+connection_get_barejid(void) {
+    const char *jid = connection_get_fulljid();
+    char *result;
+
+    Jid *jidp = jid_create(jid);
+    result = strdup(jidp->barejid);
+    jid_destroy(jidp);
+
+    return result;
+}
+
 void
 connection_features_received(const char *const jid)
 {
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index b8f4c367..c293a8f3 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -1075,9 +1075,9 @@ _handle_carbons(xmpp_stanza_t *const stanza)
         return TRUE;
     }
 
-    Jid *my_jid = jid_create(connection_get_fulljid());
+    char *mybarejid = connection_get_barejid();
     const char *const stanza_from = xmpp_stanza_get_from(stanza);
-    if (g_strcmp0(my_jid->barejid, stanza_from) != 0) {
+    if (g_strcmp0(mybarejid, stanza_from) != 0) {
         log_warning("Invalid carbon received, from: %s", stanza_from);
         return TRUE;
     }
@@ -1143,7 +1143,7 @@ _handle_carbons(xmpp_stanza_t *const stanza)
     //TODO: now that profmessage has from_jid AND to_jid we should save both. and maybe also add is_carbon so we can decide later on.
     if (message->plain || message->encrypted || message->body) {
         // if we are the recipient, treat as standard incoming message
-        if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) {
+        if (g_strcmp0(mybarejid, jid_to->barejid) == 0) {
             jid_destroy(jid_to);
             message->from_jid = jid_from;
             sv_ev_incoming_carbon(message);
@@ -1158,7 +1158,7 @@ _handle_carbons(xmpp_stanza_t *const stanza)
 
 out:
     message_free(message);
-    jid_destroy(my_jid);
+    free(mybarejid);
     return TRUE;
 }
 
diff --git a/src/xmpp/muc.c b/src/xmpp/muc.c
index 172bdb80..85f90ae6 100644
--- a/src/xmpp/muc.c
+++ b/src/xmpp/muc.c
@@ -886,11 +886,11 @@ muc_members_add(const char *const room, const char *const jid)
         if (g_hash_table_insert(chat_room->members, strdup(jid), NULL)) {
 #ifdef HAVE_OMEMO
             if(chat_room->anonymity_type == MUC_ANONYMITY_TYPE_NONANONYMOUS ) {
-                Jid *our_jid = jid_create(connection_get_fulljid());
-                if (strcmp(jid, our_jid->barejid) != 0) {
+                char *our_barejid = connection_get_barejid();
+                if (strcmp(jid, our_barejid) != 0) {
                     omemo_start_session(jid);
                 }
-                jid_destroy(our_jid);
+                free(our_barejid);
             }
 #endif
         }
diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c
index dd1b3747..64099335 100644
--- a/src/xmpp/roster.c
+++ b/src/xmpp/roster.c
@@ -211,14 +211,14 @@ roster_set_handler(xmpp_stanza_t *const stanza)
     }
 
     // if from attribute exists and it is not current users barejid, ignore push
-    Jid *my_jid = jid_create(connection_get_fulljid());
+    char *mybarejid = connection_get_barejid();
     const char *from = xmpp_stanza_get_from(stanza);
-    if (from && (strcmp(from, my_jid->barejid) != 0)) {
+    if (from && (strcmp(from, mybarejid) != 0)) {
         log_warning("Received alleged roster push from: %s", from);
-        jid_destroy(my_jid);
+        free(mybarejid);
         return;
     }
-    jid_destroy(my_jid);
+    free(mybarejid);
 
     const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID);
     gchar *barejid_lower = g_utf8_strdown(barejid, -1);
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 235df25d..5fd56733 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -175,6 +175,7 @@ jabber_conn_status_t connection_get_status(void);
 char *connection_get_presence_msg(void);
 void connection_set_presence_msg(const char *const message);
 const char* connection_get_fulljid(void);
+char* connection_get_barejid(void);
 char* connection_create_uuid(void);
 void connection_free_uuid(char *uuid);
 #ifdef HAVE_LIBMESODE