mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added roster command
This commit is contained in:
parent
bdf5e483c6
commit
f5013914ef
5
app.c
5
app.c
@ -96,6 +96,11 @@ static void main_event_loop(void)
|
||||
cons_help();
|
||||
inp_clear();
|
||||
|
||||
// /who -> request roster
|
||||
} else if (strncmp(command, "/who", 4) == 0) {
|
||||
jabber_roster_request();
|
||||
inp_clear();
|
||||
|
||||
// /close -> close the current chat window, if in chat
|
||||
} else if (strncmp(command, "/close", 6) == 0) {
|
||||
if (in_chat()) {
|
||||
|
58
jabber.c
58
jabber.c
@ -20,6 +20,9 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event
|
||||
static int _jabber_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata);
|
||||
|
||||
static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata);
|
||||
|
||||
void jabber_connect(char *user, char *passwd)
|
||||
{
|
||||
xmpp_initialize();
|
||||
@ -45,7 +48,6 @@ void jabber_process_events(void)
|
||||
xmpp_run_once(_ctx, 10);
|
||||
}
|
||||
|
||||
|
||||
void jabber_send(char *msg, char *recipient)
|
||||
{
|
||||
xmpp_stanza_t *reply, *body, *text;
|
||||
@ -67,6 +69,25 @@ void jabber_send(char *msg, char *recipient)
|
||||
xmpp_stanza_release(reply);
|
||||
}
|
||||
|
||||
void jabber_roster_request(void)
|
||||
{
|
||||
xmpp_stanza_t *iq, *query;
|
||||
|
||||
iq = xmpp_stanza_new(_ctx);
|
||||
xmpp_stanza_set_name(iq, "iq");
|
||||
xmpp_stanza_set_type(iq, "get");
|
||||
xmpp_stanza_set_id(iq, "roster");
|
||||
|
||||
query = xmpp_stanza_new(_ctx);
|
||||
xmpp_stanza_set_name(query, "query");
|
||||
xmpp_stanza_set_ns(query, XMPP_NS_ROSTER);
|
||||
|
||||
xmpp_stanza_add_child(iq, query);
|
||||
xmpp_stanza_release(query);
|
||||
xmpp_send(_conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
static int _jabber_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
@ -95,6 +116,7 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event
|
||||
xmpp_stanza_t* pres;
|
||||
log_msg(CONN, "connected");
|
||||
xmpp_handler_add(conn, _jabber_message_handler, NULL, "message", NULL, ctx);
|
||||
xmpp_id_handler_add(conn, _roster_handler, "roster", ctx);
|
||||
|
||||
pres = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(pres, "presence");
|
||||
@ -106,3 +128,37 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event
|
||||
xmpp_stop(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
xmpp_stanza_t *query, *item;
|
||||
char *type, *name;
|
||||
|
||||
type = xmpp_stanza_get_type(stanza);
|
||||
|
||||
if (strcmp(type, "error") == 0)
|
||||
log_msg(CONN, "ERROR: query failed");
|
||||
else {
|
||||
query = xmpp_stanza_get_child_by_name(stanza, "query");
|
||||
cons_show("Roster:");
|
||||
for (item = xmpp_stanza_get_children(query); item;
|
||||
item = xmpp_stanza_get_next(item)) {
|
||||
if ((name = xmpp_stanza_get_attribute(item, "name"))) {
|
||||
char line[200];
|
||||
sprintf(line, " %s (%s) sub=%s", name,
|
||||
xmpp_stanza_get_attribute(item, "jid"),
|
||||
xmpp_stanza_get_attribute(item, "subscription"));
|
||||
cons_show(line);
|
||||
} else {
|
||||
char line[200];
|
||||
sprintf(line, " %s sub=%s",
|
||||
xmpp_stanza_get_attribute(item, "jid"),
|
||||
xmpp_stanza_get_attribute(item, "subscription"));
|
||||
cons_show(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
1
jabber.h
1
jabber.h
@ -3,6 +3,7 @@
|
||||
|
||||
void jabber_connect(char *user, char *passwd);
|
||||
void jabber_disconnect(void);
|
||||
void jabber_roster_request(void);
|
||||
void jabber_process_events(void);
|
||||
void jabber_send(char *msg, char *recipient);
|
||||
|
||||
|
28
windows.c
28
windows.c
@ -142,11 +142,15 @@ void cons_help(void)
|
||||
char tstmp[80];
|
||||
get_time(tstmp);
|
||||
|
||||
wprintw(wins[0].win, " [%s] Help\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] ----\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] /help - This help.\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] /connect <username@host> - Login to jabber.\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] /quit - Quits Profanity.\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] Help:\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] Commands:\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] /help : This help.\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] /connect <username@host> : Login to jabber.\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] /who : Get roster.\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] /close : Close a chat window.\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] /quit : Quits Profanity.\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] Shortcuts:\n", tstmp);
|
||||
wprintw(wins[0].win, " [%s] F Keys : Chat windows.\n", tstmp);
|
||||
|
||||
// if its the current window, draw it
|
||||
if (curr_win == 0) {
|
||||
@ -155,6 +159,20 @@ void cons_help(void)
|
||||
}
|
||||
}
|
||||
|
||||
void cons_show(char *msg)
|
||||
{
|
||||
char tstmp[80];
|
||||
get_time(tstmp);
|
||||
|
||||
wprintw(wins[0].win, " [%s] %s\n", tstmp, msg);
|
||||
|
||||
// if its the current window, draw it
|
||||
if (curr_win == 0) {
|
||||
touchwin(wins[0].win);
|
||||
wrefresh(wins[0].win);
|
||||
}
|
||||
}
|
||||
|
||||
void cons_bad_command(char *cmd)
|
||||
{
|
||||
char tstmp[80];
|
||||
|
Loading…
Reference in New Issue
Block a user