about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/console.c40
-rw-r--r--src/ui/window.c40
-rw-r--r--src/xmpp/capabilities.c142
-rw-r--r--src/xmpp/xmpp.h16
4 files changed, 128 insertions, 110 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index 50ab60a6..882b5da8 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -558,25 +558,27 @@ cons_show_caps(const char *const fulljid, resource_presence_t presence)
         win_print(console, '-', 0, NULL, NO_DATE, 0, "", ":");
 
         // show identity
-        if (caps->category || caps->type || caps->name) {
+        if (caps->identity) {
+            DiscoIdentity *identity = caps->identity;
             win_print(console, '-', 0, NULL, NO_EOL, 0, "", "Identity: ");
-            if (caps->name) {
-                win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->name);
-                if (caps->category || caps->type) {
+            if (identity->name) {
+                win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->name);
+                if (identity->category || identity->type) {
                     win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " ");
                 }
             }
-            if (caps->type) {
-                win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->type);
-                if (caps->category) {
+            if (identity->type) {
+                win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->type);
+                if (identity->category) {
                     win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " ");
                 }
             }
-            if (caps->category) {
-                win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->category);
+            if (identity->category) {
+                win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->category);
             }
             win_newline(console);
         }
+
         if (caps->software) {
             win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "Software: %s", caps->software);
         }
@@ -1007,25 +1009,27 @@ cons_show_account(ProfAccount *account)
 
             if (caps) {
                 // show identity
-                if (caps->category || caps->type || caps->name) {
+                if (caps->identity) {
+                    DiscoIdentity *identity = caps->identity;
                     win_print(console, '-', 0, NULL, NO_EOL, 0, "", "    Identity: ");
-                    if (caps->name) {
-                        win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->name);
-                        if (caps->category || caps->type) {
+                    if (identity->name) {
+                        win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->name);
+                        if (identity->category || identity->type) {
                             win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " ");
                         }
                     }
-                    if (caps->type) {
-                        win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->type);
-                        if (caps->category) {
+                    if (identity->type) {
+                        win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->type);
+                        if (identity->category) {
                             win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " ");
                         }
                     }
-                    if (caps->category) {
-                        win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->category);
+                    if (identity->category) {
+                        win_print(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->category);
                     }
                     win_newline(console);
                 }
+
                 if (caps->software) {
                     win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "    Software: %s", caps->software);
                 }
diff --git a/src/ui/window.c b/src/ui/window.c
index b62c5e86..6e405563 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -765,25 +765,27 @@ win_show_occupant_info(ProfWin *window, const char *const room, Occupant *occupa
 
     if (caps) {
         // show identity
-        if (caps->category || caps->type || caps->name) {
+        if (caps->identity) {
+            DiscoIdentity *identity = caps->identity;
             win_print(window, '!', 0, NULL, NO_EOL, 0, "", "  Identity: ");
-            if (caps->name) {
-                win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->name);
-                if (caps->category || caps->type) {
+            if (identity->name) {
+                win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->name);
+                if (identity->category || identity->type) {
                     win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " ");
                 }
             }
-            if (caps->type) {
-                win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->type);
-                if (caps->category) {
+            if (identity->type) {
+                win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->type);
+                if (identity->category) {
                     win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", " ");
                 }
             }
-            if (caps->category) {
-                win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->category);
+            if (identity->category) {
+                win_print(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->category);
             }
             win_newline(window);
         }
+
         if (caps->software) {
             win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", "  Software: %s", caps->software);
         }
@@ -883,25 +885,27 @@ win_show_info(ProfWin *window, PContact contact)
 
         if (caps) {
             // show identity
-            if (caps->category || caps->type || caps->name) {
+            if (caps->identity) {
+                DiscoIdentity *identity = caps->identity;
                 win_print(window, '-', 0, NULL, NO_EOL, 0, "", "    Identity: ");
-                if (caps->name) {
-                    win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->name);
-                    if (caps->category || caps->type) {
+                if (identity->name) {
+                    win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->name);
+                    if (identity->category || identity->type) {
                         win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " ");
                     }
                 }
-                if (caps->type) {
-                    win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->type);
-                    if (caps->category) {
+                if (identity->type) {
+                    win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->type);
+                    if (identity->category) {
                         win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", " ");
                     }
                 }
-                if (caps->category) {
-                    win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", caps->category);
+                if (identity->category) {
+                    win_print(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", identity->category);
                 }
                 win_newline(window);
             }
+
             if (caps->software) {
                 win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", "    Software: %s", caps->software);
             }
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c
index 7f532a0d..fe3a855c 100644
--- a/src/xmpp/capabilities.c
+++ b/src/xmpp/capabilities.c
@@ -109,43 +109,52 @@ caps_init(void)
 void
 caps_add_by_ver(const char *const ver, EntityCapabilities *caps)
 {
+    if (ver == NULL || caps == NULL) {
+        return;
+    }
+
     gboolean cached = g_key_file_has_group(cache, ver);
-    if (!cached) {
-        if (caps->name) {
-            g_key_file_set_string(cache, ver, "name", caps->name);
-        }
-        if (caps->category) {
-            g_key_file_set_string(cache, ver, "category", caps->category);
-        }
-        if (caps->type) {
-            g_key_file_set_string(cache, ver, "type", caps->type);
-        }
-        if (caps->software) {
-            g_key_file_set_string(cache, ver, "software", caps->software);
-        }
-        if (caps->software_version) {
-            g_key_file_set_string(cache, ver, "software_version", caps->software_version);
+    if (cached) {
+        return;
+    }
+
+    if (caps->identity) {
+        DiscoIdentity *identity = caps->identity;
+        if (identity->name) {
+            g_key_file_set_string(cache, ver, "name", identity->name);
         }
-        if (caps->os) {
-            g_key_file_set_string(cache, ver, "os", caps->os);
+        if (identity->category) {
+            g_key_file_set_string(cache, ver, "category", identity->category);
         }
-        if (caps->os_version) {
-            g_key_file_set_string(cache, ver, "os_version", caps->os_version);
+        if (identity->type) {
+            g_key_file_set_string(cache, ver, "type", identity->type);
         }
-        if (caps->features) {
-            GSList *curr_feature = caps->features;
-            int num = g_slist_length(caps->features);
-            const gchar* features_list[num];
-            int curr = 0;
-            while (curr_feature) {
-                features_list[curr++] = curr_feature->data;
-                curr_feature = g_slist_next(curr_feature);
-            }
-            g_key_file_set_string_list(cache, ver, "features", features_list, num);
+    }
+    if (caps->software) {
+        g_key_file_set_string(cache, ver, "software", caps->software);
+    }
+    if (caps->software_version) {
+        g_key_file_set_string(cache, ver, "software_version", caps->software_version);
+    }
+    if (caps->os) {
+        g_key_file_set_string(cache, ver, "os", caps->os);
+    }
+    if (caps->os_version) {
+        g_key_file_set_string(cache, ver, "os_version", caps->os_version);
+    }
+    if (caps->features) {
+        GSList *curr_feature = caps->features;
+        int num = g_slist_length(caps->features);
+        const gchar* features_list[num];
+        int curr = 0;
+        while (curr_feature) {
+            features_list[curr++] = curr_feature->data;
+            curr_feature = g_slist_next(curr_feature);
         }
-
-        _save_cache();
+        g_key_file_set_string_list(cache, ver, "features", features_list, num);
     }
+
+    _save_cache();
 }
 
 void
@@ -173,24 +182,16 @@ _caps_by_ver(const char *const ver)
         EntityCapabilities *new_caps = malloc(sizeof(struct entity_capabilities_t));
 
         char *category = g_key_file_get_string(cache, ver, "category", NULL);
-        if (category) {
-            new_caps->category = category;
-        } else {
-            new_caps->category = NULL;
-        }
-
         char *type = g_key_file_get_string(cache, ver, "type", NULL);
-        if (type) {
-            new_caps->type = type;
-        } else {
-            new_caps->type = NULL;
-        }
-
         char *name = g_key_file_get_string(cache, ver, "name", NULL);
-        if (name) {
-            new_caps->name = name;
+        if (category || type || name) {
+            DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t));
+            identity->category = category;
+            identity->type = type;
+            identity->name = name;
+            new_caps->identity = identity;
         } else {
-            new_caps->name = NULL;
+            new_caps->identity = NULL;
         }
 
         char *software = g_key_file_get_string(cache, ver, "software", NULL);
@@ -275,9 +276,17 @@ _caps_copy(EntityCapabilities *caps)
         return NULL;
     } else {
         EntityCapabilities *result = (EntityCapabilities *)malloc(sizeof(EntityCapabilities));
-        result->category = caps->category ? strdup(caps->category) : NULL;
-        result->type = caps->type ? strdup(caps->type) : NULL;
-        result->name = caps->name ? strdup(caps->name) : NULL;
+
+        if (caps->identity) {
+            DiscoIdentity *identity = (DiscoIdentity*)malloc(sizeof(DiscoIdentity));
+            identity->category = caps->identity->category ? strdup(caps->identity->category) : NULL;
+            identity->type = caps->identity->type ? strdup(caps->identity->type) : NULL;
+            identity->name = caps->identity->name ? strdup(caps->identity->name) : NULL;
+            result->identity = identity;
+        } else {
+            result->identity = NULL;
+        }
+
         result->software = caps->software ? strdup(caps->software) : NULL;
         result->software_version = caps->software_version ? strdup(caps->software_version) : NULL;
         result->os = caps->os ? strdup(caps->os) : NULL;
@@ -503,21 +512,16 @@ caps_create(xmpp_stanza_t *query)
 
     EntityCapabilities *new_caps = malloc(sizeof(struct entity_capabilities_t));
 
-    if (category) {
-        new_caps->category = strdup(category);
-    } else {
-        new_caps->category = NULL;
-    }
-    if (type) {
-        new_caps->type = strdup(type);
-    } else {
-        new_caps->type = NULL;
-    }
-    if (name) {
-        new_caps->name = strdup(name);
+    if (category || type || name) {
+        DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t));
+        identity->category = category ? strdup(category) : NULL;
+        identity->type = type ? strdup(type) : NULL;
+        identity->name = name ? strdup(name) : NULL;
+        new_caps->identity = identity;
     } else {
-        new_caps->name = NULL;
+        new_caps->identity = NULL;
     }
+
     if (software) {
         new_caps->software = software;
     } else {
@@ -637,13 +641,21 @@ caps_close(void)
     prof_features = NULL;
 }
 
+static void
+_disco_identity_destroy(DiscoIdentity *disco_identity)
+{
+    if (disco_identity) {
+        free(disco_identity->category);
+        free(disco_identity->name);
+        free(disco_identity->type);
+    }
+}
+
 void
 caps_destroy(EntityCapabilities *caps)
 {
     if (caps) {
-        free(caps->category);
-        free(caps->type);
-        free(caps->name);
+        _disco_identity_destroy(caps->identity);
         free(caps->software);
         free(caps->software_version);
         free(caps->os);
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 3f1094a5..3ab5fb56 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -82,10 +82,14 @@ typedef struct bookmark_t {
     gboolean autojoin;
 } Bookmark;
 
-typedef struct entity_capabilities_t {
-    char *category;
-    char *type;
+typedef struct disco_identity_t {
     char *name;
+    char *type;
+    char *category;
+} DiscoIdentity;
+
+typedef struct entity_capabilities_t {
+    DiscoIdentity *identity;
     char *software;
     char *software_version;
     char *os;
@@ -98,12 +102,6 @@ typedef struct disco_item_t {
     char *name;
 } DiscoItem;
 
-typedef struct disco_identity_t {
-    char *name;
-    char *type;
-    char *category;
-} DiscoIdentity;
-
 void session_init(void);
 jabber_conn_status_t session_connect_with_details(const char *const jid, const char *const passwd,
     const char *const altdomain, const int port, const char *const tls_policy);