diff options
author | James Booth <boothj5@gmail.com> | 2012-02-05 23:29:09 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-02-05 23:29:09 +0000 |
commit | 0c0246074fb7fc957a7edd726a04be5089e819a0 (patch) | |
tree | 3c81cf74d327249021c6abc66992dc07151261d5 /jabber.c | |
parent | 134e5d17013866e9df81c683197596c0c3cc2bad (diff) | |
download | profani-tty-0c0246074fb7fc957a7edd726a04be5089e819a0.tar.gz |
Added jabber module
Diffstat (limited to 'jabber.c')
-rw-r--r-- | jabber.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/jabber.c b/jabber.c new file mode 100644 index 00000000..7c6fb26c --- /dev/null +++ b/jabber.c @@ -0,0 +1,63 @@ +#include <string.h> +#include <strophe/strophe.h> +#include <ncurses.h> + +#include "windows.h" +#include "log.h" + +extern FILE *logp; + +extern WINDOW *main_win; + + +int in_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, + void * const userdata) +{ + char *intext; + + if(!xmpp_stanza_get_child_by_name(stanza, "body")) + return 1; + if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error")) + return 1; + + intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); + + char in_line[200]; + char *from = xmpp_stanza_get_attribute(stanza, "from"); + + char *short_from = strtok(from, "@"); + + sprintf(in_line, "%s: %s\n", short_from, intext); + + wprintw(main_win, in_line); + wrefresh(main_win); + + return 1; +} + +void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, + const int error, xmpp_stream_error_t * const stream_error, + void * const userdata) +{ + xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; + + if (status == XMPP_CONN_CONNECT) { + xmpp_stanza_t* pres; + fprintf(logp, "DEBUG: connected\n"); + xmpp_handler_add(conn,in_message_handler, NULL, "message", NULL, ctx); + + pres = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(pres, "presence"); + xmpp_send(conn, pres); + xmpp_stanza_release(pres); + } + else { + fprintf(logp, "DEBUG: disconnected\n"); + xmpp_stop(ctx); + } +} + + + + + |