about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-05-14 19:13:27 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-05-14 19:13:27 +0200
commit9c853d9f4644360e7f5065546f4738eb8daac878 (patch)
tree14c3f28582929aff2fa4292dc3b521f7893a56df /src
parent9243655a223092f8cf74986c4d49542b8b1bbda1 (diff)
downloadprofani-tty-9c853d9f4644360e7f5065546f4738eb8daac878.tar.gz
xep-0092: make it possible to ask servers or components for software
This adds the new `/serversoftware` command.

```
/software user@domain.org/resource
/serversoftware domain.org
```

Fix https://github.com/profanity-im/profanity/issues/1338
Diffstat (limited to 'src')
-rw-r--r--src/command/cmd_defs.c17
-rw-r--r--src/command/cmd_funcs.c19
-rw-r--r--src/command/cmd_funcs.h1
-rw-r--r--src/xmpp/iq.c45
4 files changed, 65 insertions, 17 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 7cf7b2ef..db55eaf4 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2433,6 +2433,23 @@ static struct cmd_t command_defs[] =
             { "on|off", "Enable or disable slashguard." })
         CMD_NOEXAMPLES
     },
+
+    { "/serversoftware",
+        parse_args, 1, 1, NULL,
+        CMD_NOSUBFUNCS
+        CMD_MAINFUNC(cmd_serversoftware)
+        CMD_TAGS(
+            CMD_TAG_DISCOVERY)
+        CMD_SYN(
+            "/serversoftware <domain>")
+        CMD_DESC(
+            "Find server or component software version information.")
+        CMD_ARGS(
+            { "<domain>", "The jid of your server or component." })
+        CMD_EXAMPLES(
+            "/software valhalla.edda",
+            "/software xmpp.vanaheimr.edda")
+    }
 };
 
 static GHashTable *search_index;
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index d29244a9..96f6c372 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -3522,6 +3522,25 @@ cmd_software(ProfWin *window, const char *const command, gchar **args)
 }
 
 gboolean
+cmd_serversoftware(ProfWin *window, const char *const command, gchar **args)
+{
+    jabber_conn_status_t conn_status = connection_get_status();
+
+    if (conn_status != JABBER_CONNECTED) {
+        cons_show("You are not currently connected.");
+        return TRUE;
+    }
+
+    if (args[0]) {
+        iq_send_software_version(args[0]);
+    } else {
+        cons_show("You must provide a jid to the /serversoftware command.");
+    }
+
+    return TRUE;
+}
+
+gboolean
 cmd_join(ProfWin *window, const char *const command, gchar **args)
 {
     jabber_conn_status_t conn_status = connection_get_status();
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index 4b7b6017..6f82a88a 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -231,4 +231,5 @@ gboolean cmd_os(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_slashguard(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_serversoftware(ProfWin *window, const char *const command, gchar **args);
 #endif
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 0b013c33..8c373f77 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -1505,28 +1505,39 @@ _version_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
     xmpp_ctx_t *ctx = xmpp_conn_get_context(conn);
 
     Jid *jidp = jid_create((char*)userdata);
+
     const char *presence = NULL;
-    if (muc_active(jidp->barejid)) {
-        Occupant *occupant = muc_roster_item(jidp->barejid, jidp->resourcepart);
-        presence = string_from_resource_presence(occupant->presence);
-    } else {
-        PContact contact = roster_get_contact(jidp->barejid);
-        if (contact) {
-            Resource *resource = p_contact_get_resource(contact, jidp->resourcepart);
-            if (!resource) {
-                ui_handle_software_version_error(jidp->fulljid, "Unknown resource");
-                if (name_str) xmpp_free(ctx, name_str);
-                if (version_str) xmpp_free(ctx, version_str);
-                if (os_str) xmpp_free(ctx, os_str);
-                return 0;
-            }
-            presence = string_from_resource_presence(resource->presence);
+
+    // if it has a fulljid it is a regular user (not server or component)
+    if (jidp->fulljid) {
+        if (muc_active(jidp->barejid)) {
+            Occupant *occupant = muc_roster_item(jidp->barejid, jidp->resourcepart);
+            presence = string_from_resource_presence(occupant->presence);
         } else {
-            presence = "offline";
+            PContact contact = roster_get_contact(jidp->barejid);
+            if (contact) {
+                Resource *resource = p_contact_get_resource(contact, jidp->resourcepart);
+                if (!resource) {
+                    ui_handle_software_version_error(jidp->fulljid, "Unknown resource");
+                    if (name_str) xmpp_free(ctx, name_str);
+                    if (version_str) xmpp_free(ctx, version_str);
+                    if (os_str) xmpp_free(ctx, os_str);
+                    return 0;
+                }
+                presence = string_from_resource_presence(resource->presence);
+            } else {
+                presence = "offline";
+            }
         }
     }
 
-    ui_show_software_version(jidp->fulljid, presence, name_str, version_str, os_str);
+    if (jidp->fulljid) {
+        // regular user
+        ui_show_software_version(jidp->fulljid, presence, name_str, version_str, os_str);
+    } else {
+        // server or component
+        ui_show_software_version(jidp->barejid, "online", name_str, version_str, os_str);
+    }
 
     jid_destroy(jidp);