about summary refs log tree commit diff stats
path: root/src/xmpp/iq.c
diff options
context:
space:
mode:
authorJohn Hernandez <129467592+H3rnand3zzz@users.noreply.github.com>2023-04-03 17:58:09 +0200
committerJohn Hernandez <129467592+H3rnand3zzz@users.noreply.github.com>2023-04-09 14:17:01 +0200
commit5d3c8ce7c164f74f606ff06d1adf849821591a51 (patch)
tree22163056dd27624216d91de3ab8b4053e5289a7b /src/xmpp/iq.c
parent6b597f6608c454e48000847bb3c0b5c2fdc4f292 (diff)
downloadprofani-tty-5d3c8ce7c164f74f606ff06d1adf849821591a51.tar.gz
Allow setting client identification name/version manually
Add changes allowing user to switch client name and version.

Useful for enhancing user privacy.

Minor cleanup.
Diffstat (limited to 'src/xmpp/iq.c')
-rw-r--r--src/xmpp/iq.c102
1 files changed, 58 insertions, 44 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 9fe6b061..f898914b 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -1612,6 +1612,17 @@ _version_get_handler(xmpp_stanza_t* const stanza)
     xmpp_ctx_t* const ctx = connection_get_ctx();
     const char* id = xmpp_stanza_get_id(stanza);
     const char* from = xmpp_stanza_get_from(stanza);
+    ProfAccount* account = accounts_get_account(session_get_account_name());
+    auto_char char* client = account->client != NULL ? strdup(account->client) : NULL;
+    bool is_custom_client = client != NULL;
+    gchar* custom_version_str = NULL;
+    if (is_custom_client) {
+        custom_version_str = strstr(client, " ");
+        if (custom_version_str != NULL) {
+            *custom_version_str = '\0'; // Split string on name and version
+            custom_version_str++;
+        }
+    }
 
     if (id) {
         log_debug("IQ version get handler fired, id: %s.", id);
@@ -1619,28 +1630,35 @@ _version_get_handler(xmpp_stanza_t* const stanza)
         log_debug("IQ version get handler fired.");
     }
 
-    if (from) {
-        if (prefs_get_boolean(PREF_ADV_NOTIFY_DISCO_OR_VERSION)) {
-            cons_show("Received IQ version request (XEP-0092) from %s", from);
-        }
+    if (!from)
+        return;
 
-        xmpp_stanza_t* response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, id);
-        xmpp_stanza_set_to(response, from);
+    if (prefs_get_boolean(PREF_ADV_NOTIFY_DISCO_OR_VERSION)) {
+        cons_show("Received IQ version request (XEP-0092) from %s", from);
+    }
 
-        xmpp_stanza_t* query = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
-        xmpp_stanza_set_ns(query, STANZA_NS_VERSION);
-
-        xmpp_stanza_t* name = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_name(name, "name");
-        xmpp_stanza_t* name_txt = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_text(name_txt, "Profanity");
-        xmpp_stanza_add_child(name, name_txt);
-
-        xmpp_stanza_t* version = xmpp_stanza_new(ctx);
-        xmpp_stanza_set_name(version, "version");
-        xmpp_stanza_t* version_txt = xmpp_stanza_new(ctx);
-        GString* version_str = g_string_new(PACKAGE_VERSION);
+    xmpp_stanza_t* response = xmpp_iq_new(ctx, STANZA_TYPE_RESULT, id);
+    xmpp_stanza_set_to(response, from);
+
+    xmpp_stanza_t* query = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
+    xmpp_stanza_set_ns(query, STANZA_NS_VERSION);
+
+    xmpp_stanza_t* name = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(name, "name");
+    xmpp_stanza_t* name_txt = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_text(name_txt, is_custom_client ? client : "Profanity");
+    xmpp_stanza_add_child(name, name_txt);
+    xmpp_stanza_add_child(query, name);
+    bool include_os = prefs_get_boolean(PREF_REVEAL_OS) && !is_custom_client;
+    xmpp_stanza_t* os;
+    xmpp_stanza_t* os_txt;
+    xmpp_stanza_t* version = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(version, "version");
+    xmpp_stanza_t* version_txt = xmpp_stanza_new(ctx);
+    GString* version_str = g_string_new(PACKAGE_VERSION);
+
+    if (!is_custom_client) {
         if (strcmp(PACKAGE_STATUS, "development") == 0) {
 #ifdef HAVE_GIT_VERSION
             g_string_append(version_str, "dev.");
@@ -1653,11 +1671,8 @@ _version_get_handler(xmpp_stanza_t* const stanza)
         }
         xmpp_stanza_set_text(version_txt, version_str->str);
         xmpp_stanza_add_child(version, version_txt);
+        xmpp_stanza_add_child(query, version);
 
-        xmpp_stanza_t* os;
-        xmpp_stanza_t* os_txt;
-
-        bool include_os = prefs_get_boolean(PREF_REVEAL_OS);
         if (include_os) {
             os = xmpp_stanza_new(ctx);
             xmpp_stanza_set_name(os, "os");
@@ -1680,31 +1695,30 @@ _version_get_handler(xmpp_stanza_t* const stanza)
             xmpp_stanza_set_text(os_txt, "Unknown");
 #endif
             xmpp_stanza_add_child(os, os_txt);
-        }
-
-        xmpp_stanza_add_child(query, name);
-        xmpp_stanza_add_child(query, version);
-        if (include_os) {
             xmpp_stanza_add_child(query, os);
         }
-        xmpp_stanza_add_child(response, query);
+    }
+    if (is_custom_client && custom_version_str != NULL) {
+        xmpp_stanza_set_text(version_txt, custom_version_str);
+        xmpp_stanza_add_child(version, version_txt);
+        xmpp_stanza_add_child(query, version);
+    }
 
-        iq_send_stanza(response);
+    xmpp_stanza_add_child(response, query);
+    iq_send_stanza(response);
 
-        g_string_free(version_str, TRUE);
-        xmpp_stanza_release(name_txt);
-        xmpp_stanza_release(version_txt);
-        if (include_os) {
-            xmpp_stanza_release(os_txt);
-        }
-        xmpp_stanza_release(name);
-        xmpp_stanza_release(version);
-        if (include_os) {
-            xmpp_stanza_release(os);
-        }
-        xmpp_stanza_release(query);
-        xmpp_stanza_release(response);
+    // Cleanup
+    g_string_free(version_str, TRUE);
+    xmpp_stanza_release(version_txt);
+    xmpp_stanza_release(name_txt);
+    if (include_os) {
+        xmpp_stanza_release(os_txt);
+        xmpp_stanza_release(os);
     }
+    xmpp_stanza_release(name);
+    xmpp_stanza_release(version);
+    xmpp_stanza_release(query);
+    xmpp_stanza_release(response);
 }
 
 static void