diff options
author | Paul Fariello <paul@fariello.eu> | 2018-09-26 12:32:56 +0200 |
---|---|---|
committer | Paul Fariello <paul@fariello.eu> | 2018-09-26 14:34:52 +0200 |
commit | 2e0bc27bf0d19f07fa60a48dfd8189edb4462f54 (patch) | |
tree | 1bb4ad7fe7c0fdff525094c7415c675d6e9bf181 /src | |
parent | 01428eb85855ea9dd148118ca35a0e20f42cd5ce (diff) | |
download | profani-tty-2e0bc27bf0d19f07fa60a48dfd8189edb4462f54.tar.gz |
Make _get_groups_from_item and roster _compare_* public
In order to avoid duplication with xep 0133 support in command execution
Diffstat (limited to 'src')
-rw-r--r-- | src/xmpp/iq.c | 14 | ||||
-rw-r--r-- | src/xmpp/roster.c | 9 | ||||
-rw-r--r-- | src/xmpp/roster.h | 1 | ||||
-rw-r--r-- | src/xmpp/roster_list.c | 24 | ||||
-rw-r--r-- | src/xmpp/roster_list.h | 2 |
5 files changed, 19 insertions, 31 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index dde803cb..e5a74fc4 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -1191,17 +1191,7 @@ _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata const char *ask = xmpp_stanza_get_attribute(child, STANZA_ATTR_ASK); GSList *groups = NULL; - xmpp_stanza_t *group_element = xmpp_stanza_get_children(child); - - while (group_element) { - if (strcmp(xmpp_stanza_get_name(group_element), STANZA_NAME_GROUP) == 0) { - char *groupname = xmpp_stanza_get_text(group_element); - if (groupname) { - groups = g_slist_append(groups, groupname); - } - } - group_element = xmpp_stanza_get_next(group_element); - } + groups = roster_get_groups_from_item(child); gboolean pending_out = FALSE; if (ask && (strcmp(ask, "subscribe") == 0)) { @@ -1209,7 +1199,7 @@ _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata } PContact contact = p_contact_new(barejid_lower, name, groups, sub, NULL, pending_out); - list = g_slist_append(list, contact); + list = g_slist_insert_sorted(list, contact, (GCompareFunc)roster_compare_name); child = xmpp_stanza_get_next(child); } diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 4fa70052..994269ec 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -75,9 +75,6 @@ static int _group_add_id_handler(xmpp_stanza_t *const stanza, void *const userda static int _group_remove_id_handler(xmpp_stanza_t *const stanza, void *const userdata); static void _free_group_data(GroupData *data); -// helper functions -GSList* _get_groups_from_item(xmpp_stanza_t *item); - void roster_request(void) { @@ -254,7 +251,7 @@ roster_set_handler(xmpp_stanza_t *const stanza) pending_out = TRUE; } - GSList *groups = _get_groups_from_item(item); + GSList *groups = roster_get_groups_from_item(item); // update the local roster PContact contact = roster_get_contact(barejid_lower); @@ -301,7 +298,7 @@ roster_result_handler(xmpp_stanza_t *const stanza) pending_out = TRUE; } - GSList *groups = _get_groups_from_item(item); + GSList *groups = roster_get_groups_from_item(item); gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (!added) { @@ -318,7 +315,7 @@ roster_result_handler(xmpp_stanza_t *const stanza) } GSList* -_get_groups_from_item(xmpp_stanza_t *item) +roster_get_groups_from_item(xmpp_stanza_t *item) { GSList *groups = NULL; xmpp_stanza_t *group_element = xmpp_stanza_get_children(item); diff --git a/src/xmpp/roster.h b/src/xmpp/roster.h index 15614377..be710561 100644 --- a/src/xmpp/roster.h +++ b/src/xmpp/roster.h @@ -38,5 +38,6 @@ void roster_request(void); void roster_set_handler(xmpp_stanza_t *const stanza); void roster_result_handler(xmpp_stanza_t *const stanza); +GSList* roster_get_groups_from_item(xmpp_stanza_t *const item); #endif diff --git a/src/xmpp/roster_list.c b/src/xmpp/roster_list.c index a2c5653d..71c86ff5 100644 --- a/src/xmpp/roster_list.c +++ b/src/xmpp/roster_list.c @@ -73,8 +73,6 @@ static gboolean _key_equals(void *key1, void *key2); static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2); static void _replace_name(const char *const current_name, const char *const new_name, const char *const barejid); static void _add_name_and_barejid(const char *const name, const char *const barejid); -static gint _compare_name(PContact a, PContact b); -static gint _compare_presence(PContact a, PContact b); void roster_create(void) @@ -397,7 +395,7 @@ roster_get_contacts_by_presence(const char *const presence) while (g_hash_table_iter_next(&iter, &key, &value)) { PContact contact = (PContact)value; if (g_strcmp0(p_contact_presence(contact), presence) == 0) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); + result = g_slist_insert_sorted(result, value, (GCompareFunc)roster_compare_name); } } @@ -417,9 +415,9 @@ roster_get_contacts(roster_ord_t order) GCompareFunc cmp_func; if (order == ROSTER_ORD_PRESENCE) { - cmp_func = (GCompareFunc) _compare_presence; + cmp_func = (GCompareFunc) roster_compare_presence; } else { - cmp_func = (GCompareFunc) _compare_name; + cmp_func = (GCompareFunc) roster_compare_name; } g_hash_table_iter_init(&iter, roster->contacts); @@ -444,7 +442,7 @@ roster_get_contacts_online(void) g_hash_table_iter_init(&iter, roster->contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { if(strcmp(p_contact_presence(value), "offline")) - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); + result = g_slist_insert_sorted(result, value, (GCompareFunc)roster_compare_name); } // return all contact structs @@ -499,9 +497,9 @@ roster_get_group(const char *const group, roster_ord_t order) GCompareFunc cmp_func; if (order == ROSTER_ORD_PRESENCE) { - cmp_func = (GCompareFunc) _compare_presence; + cmp_func = (GCompareFunc) roster_compare_presence; } else { - cmp_func = (GCompareFunc) _compare_name; + cmp_func = (GCompareFunc) roster_compare_name; } g_hash_table_iter_init(&iter, roster->contacts); @@ -605,8 +603,8 @@ _add_name_and_barejid(const char *const name, const char *const barejid) } } -static gint -_compare_name(PContact a, PContact b) +gint +roster_compare_name(PContact a, PContact b) { const char * utf8_str_a = NULL; const char * utf8_str_b = NULL; @@ -645,8 +643,8 @@ _get_presence_weight(const char *presence) } } -static gint -_compare_presence(PContact a, PContact b) +gint +roster_compare_presence(PContact a, PContact b) { const char *presence_a = p_contact_presence(a); const char *presence_b = p_contact_presence(b); @@ -663,6 +661,6 @@ _compare_presence(PContact a, PContact b) // otherwise order by name } else { - return _compare_name(a, b); + return roster_compare_name(a, b); } } diff --git a/src/xmpp/roster_list.h b/src/xmpp/roster_list.h index a0b01625..b7484c04 100644 --- a/src/xmpp/roster_list.h +++ b/src/xmpp/roster_list.h @@ -70,5 +70,7 @@ char* roster_group_autocomplete(const char *const search_str, gboolean previous) char* roster_barejid_autocomplete(const char *const search_str, gboolean previous); GSList* roster_get_contacts_by_presence(const char *const presence); char* roster_get_msg_display_name(const char *const barejid, const char *const resource); +gint roster_compare_name(PContact a, PContact b); +gint roster_compare_presence(PContact a, PContact b); #endif |