1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Moved roster output handling to profanity module

This commit is contained in:
James Booth 2012-10-02 01:04:53 +01:00
parent 02224ea7bb
commit 28b1723876
3 changed files with 56 additions and 17 deletions

View File

@ -399,36 +399,33 @@ _roster_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
xmpp_stanza_t *query, *item;
char *type, *name, *jid;
type = xmpp_stanza_get_type(stanza);
char *type = xmpp_stanza_get_type(stanza);
if (strcmp(type, "error") == 0)
log_error("Roster query failed");
else {
query = xmpp_stanza_get_child_by_name(stanza, "query");
cons_show("Roster:");
GSList *roster = NULL;
item = xmpp_stanza_get_children(query);
while (item != NULL) {
name = xmpp_stanza_get_attribute(item, "name");
jid = xmpp_stanza_get_attribute(item, "jid");
const char *name = xmpp_stanza_get_attribute(item, "name");
const char *jid = xmpp_stanza_get_attribute(item, "jid");
jabber_roster_entry *entry = malloc(sizeof(jabber_roster_entry));
if (name != NULL) {
char line[strlen(name) + 2 + strlen(jid) + 1 + 1];
sprintf(line, "%s (%s)", name, jid);
cons_show(line);
entry->name = strdup(name);
} else {
char line[strlen(jid) + 1];
sprintf(line, "%s", jid);
cons_show(line);
entry->name = NULL;
}
entry->jid = strdup(jid);
roster = g_slist_append(roster, entry);
item = xmpp_stanza_get_next(item);
win_page_off();
}
prof_handle_roster(roster);
}
return 1;

View File

@ -35,11 +35,13 @@
#include "log.h"
#include "preferences.h"
#include "profanity.h"
#include "jabber.h"
#include "ui.h"
static log_level_t _get_log_level(char *log_level);
gboolean _process_input(char *inp);
static void _create_config_directory();
static void _free_roster_entry(jabber_roster_entry *entry);
void
profanity_run(void)
@ -247,6 +249,30 @@ prof_handle_contact_offline(char *contact, char *show, char *status)
win_page_off();
}
void prof_handle_roster(GSList *roster)
{
cons_show("Roster:");
while (roster != NULL) {
jabber_roster_entry *entry = roster->data;
if (entry->name != NULL) {
char line[strlen(entry->name) + 2 + strlen(entry->jid) + 1 + 1];
sprintf(line, "%s (%s)", entry->name, entry->jid);
cons_show(line);
} else {
char line[strlen(entry->jid) + 1];
sprintf(line, "%s", entry->jid);
cons_show(line);
}
roster = g_slist_next(roster);
win_page_off();
}
g_slist_free_full(roster, (GDestroyNotify)_free_roster_entry);
}
static void
_create_config_directory()
{
@ -256,3 +282,13 @@ _create_config_directory()
g_string_free(dir, TRUE);
}
static void
_free_roster_entry(jabber_roster_entry *entry)
{
if (entry->name != NULL) {
free(entry->name);
entry->name = NULL;
}
free(entry->jid);
}

View File

@ -32,7 +32,13 @@ void prof_handle_typing(char *from);
void prof_handle_contact_online(char *contact, char *show, char *status);
void prof_handle_contact_offline(char *contact, char *show, char *status);
void prof_handle_incoming_message(char *from, char *message);
void prof_handle_roster(GSList *roster);
void profanity_shutdown_init(void);
void profanity_shutdown(void);
typedef struct roster_entry_t {
char *name;
char *jid;
} jabber_roster_entry;
#endif