1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

jabber added message type handler functions

This commit is contained in:
James Booth 2012-11-07 00:34:43 +00:00
parent 8dfa373a01
commit 9d1f0473ce

View File

@ -430,40 +430,35 @@ _groupchat_message_handler(const char * const room_jid,
}
static int
_message_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
_error_message_handler(const char * const from, xmpp_stanza_t * const stanza)
{
gchar *type = xmpp_stanza_get_attribute(stanza, "type");
gchar *from = xmpp_stanza_get_attribute(stanza, "from");
if (strcmp(type, "groupchat") == 0) {
_groupchat_message_handler(from, stanza);
// handle regular messaging
} else {
if (type != NULL) {
if (strcmp(type, "error") == 0) {
char *err_msg = NULL;
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error");
if (error == NULL) {
log_debug("error message without <error/> received");
return 1;
} else {
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error);
if (err_cond == NULL) {
log_debug("error message without <defined-condition/> received");
return 1;
} else {
err_msg = xmpp_stanza_get_name(err_cond);
}
// TODO: process 'type' attribute from <error/> [RFC6120, 8.3.2]
}
prof_handle_error_message(from, err_msg);
return 1;
}
}
static int
_chat_message_handler(const char * const from, xmpp_stanza_t * const stanza)
{
char from_cpy[strlen(from) + 1];
strcpy(from_cpy, from);
char *short_from = strtok(from_cpy, "/");
@ -519,11 +514,32 @@ _message_handler(xmpp_conn_t * const conn,
char *message = xmpp_stanza_get_text(body);
prof_handle_incoming_message(short_from, message);
}
}
return 1;
}
static int
_message_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
gchar *type = xmpp_stanza_get_attribute(stanza, "type");
gchar *from = xmpp_stanza_get_attribute(stanza, "from");
if (type == NULL) {
log_error("Message stanza received with no type attribute");
return 1;
} else if (strcmp(type, "error") == 0) {
return _error_message_handler(from, stanza);
} else if (strcmp(type, "groupchat") == 0) {
return _groupchat_message_handler(from, stanza);
} else if (strcmp(type, "chat") == 0) {
return _chat_message_handler(from, stanza);
} else {
log_error("Message stanza received with unknown type: %s", type);
return 1;
}
}
static void
_connection_handler(xmpp_conn_t * const conn,
const xmpp_conn_event_t status, const int error,