2012-02-05 18:29:09 -05:00
|
|
|
#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)
|
|
|
|
{
|
2012-02-06 17:29:05 -05:00
|
|
|
char *message;
|
2012-02-05 18:29:09 -05:00
|
|
|
|
|
|
|
if(!xmpp_stanza_get_child_by_name(stanza, "body"))
|
|
|
|
return 1;
|
|
|
|
if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error"))
|
|
|
|
return 1;
|
|
|
|
|
2012-02-06 17:29:05 -05:00
|
|
|
message = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
|
2012-02-05 18:29:09 -05:00
|
|
|
|
|
|
|
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
|
|
|
char *short_from = strtok(from, "@");
|
2012-02-06 17:29:05 -05:00
|
|
|
show_incomming_msg(short_from, message);
|
2012-02-05 18:29:09 -05:00
|
|
|
|
|
|
|
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;
|
2012-02-06 17:29:05 -05:00
|
|
|
logmsg(CONN, "connected");
|
2012-02-05 18:29:09 -05:00
|
|
|
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 {
|
2012-02-06 17:29:05 -05:00
|
|
|
logmsg(CONN, "disconnected");
|
2012-02-05 18:29:09 -05:00
|
|
|
xmpp_stop(ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-05 18:38:35 -05:00
|
|
|
void prof_send(char *msg, xmpp_ctx_t *ctx, xmpp_conn_t *conn)
|
|
|
|
{
|
|
|
|
xmpp_stanza_t *reply, *body, *text;
|
|
|
|
|
|
|
|
reply = xmpp_stanza_new(ctx);
|
|
|
|
xmpp_stanza_set_name(reply, "message");
|
|
|
|
xmpp_stanza_set_type(reply, "chat");
|
|
|
|
xmpp_stanza_set_attribute(reply, "to", "boothj5@localhost");
|
2012-02-05 18:29:09 -05:00
|
|
|
|
2012-02-05 18:38:35 -05:00
|
|
|
body = xmpp_stanza_new(ctx);
|
|
|
|
xmpp_stanza_set_name(body, "body");
|
|
|
|
|
|
|
|
text = xmpp_stanza_new(ctx);
|
|
|
|
xmpp_stanza_set_text(text, msg);
|
|
|
|
xmpp_stanza_add_child(body, text);
|
|
|
|
xmpp_stanza_add_child(reply, body);
|
|
|
|
|
|
|
|
xmpp_send(conn, reply);
|
|
|
|
xmpp_stanza_release(reply);
|
|
|
|
}
|
2012-02-05 18:29:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
|