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:
parent
8dfa373a01
commit
9d1f0473ce
52
src/jabber.c
52
src/jabber.c
@ -430,40 +430,35 @@ _groupchat_message_handler(const char * const room_jid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_message_handler(xmpp_conn_t * const conn,
|
_error_message_handler(const char * const from, xmpp_stanza_t * const stanza)
|
||||||
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 (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;
|
char *err_msg = NULL;
|
||||||
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error");
|
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error");
|
||||||
|
|
||||||
if (error == NULL) {
|
if (error == NULL) {
|
||||||
log_debug("error message without <error/> received");
|
log_debug("error message without <error/> received");
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error);
|
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error);
|
||||||
|
|
||||||
if (err_cond == NULL) {
|
if (err_cond == NULL) {
|
||||||
log_debug("error message without <defined-condition/> received");
|
log_debug("error message without <defined-condition/> received");
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
err_msg = xmpp_stanza_get_name(err_cond);
|
err_msg = xmpp_stanza_get_name(err_cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: process 'type' attribute from <error/> [RFC6120, 8.3.2]
|
// TODO: process 'type' attribute from <error/> [RFC6120, 8.3.2]
|
||||||
}
|
}
|
||||||
prof_handle_error_message(from, err_msg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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];
|
char from_cpy[strlen(from) + 1];
|
||||||
strcpy(from_cpy, from);
|
strcpy(from_cpy, from);
|
||||||
char *short_from = strtok(from_cpy, "/");
|
char *short_from = strtok(from_cpy, "/");
|
||||||
@ -519,11 +514,32 @@ _message_handler(xmpp_conn_t * const conn,
|
|||||||
char *message = xmpp_stanza_get_text(body);
|
char *message = xmpp_stanza_get_text(body);
|
||||||
prof_handle_incoming_message(short_from, message);
|
prof_handle_incoming_message(short_from, message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
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
|
static void
|
||||||
_connection_handler(xmpp_conn_t * const conn,
|
_connection_handler(xmpp_conn_t * const conn,
|
||||||
const xmpp_conn_event_t status, const int error,
|
const xmpp_conn_event_t status, const int error,
|
||||||
|
Loading…
Reference in New Issue
Block a user