mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Use DiscoIdentity in EntityCapabilities
This commit is contained in:
parent
80eb5bee90
commit
0bd5b5200a
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -109,43 +109,52 @@ caps_init(void)
|
||||
void
|
||||
caps_add_by_ver(const char *const ver, EntityCapabilities *caps)
|
||||
{
|
||||
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 (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);
|
||||
}
|
||||
g_key_file_set_string_list(cache, ver, "features", features_list, num);
|
||||
}
|
||||
|
||||
_save_cache();
|
||||
if (ver == NULL || caps == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
gboolean cached = g_key_file_has_group(cache, ver);
|
||||
if (cached) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (caps->identity) {
|
||||
DiscoIdentity *identity = caps->identity;
|
||||
if (identity->name) {
|
||||
g_key_file_set_string(cache, ver, "name", identity->name);
|
||||
}
|
||||
if (identity->category) {
|
||||
g_key_file_set_string(cache, ver, "category", identity->category);
|
||||
}
|
||||
if (identity->type) {
|
||||
g_key_file_set_string(cache, ver, "type", identity->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 (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);
|
||||
}
|
||||
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);
|
||||
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->category = NULL;
|
||||
}
|
||||
if (type) {
|
||||
new_caps->type = strdup(type);
|
||||
} else {
|
||||
new_caps->type = NULL;
|
||||
}
|
||||
if (name) {
|
||||
new_caps->name = strdup(name);
|
||||
} 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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user