1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Moved ping iq creation to stanza

This commit is contained in:
James Booth 2012-11-10 00:43:09 +00:00
parent 0da40a34d5
commit 7512d70ff5
3 changed files with 56 additions and 41 deletions

View File

@ -314,6 +314,27 @@ _jabber_roster_request(void)
xmpp_stanza_release(iq);
}
static int
_message_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
gchar *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
if (type == NULL) {
log_error("Message stanza received with no type attribute");
return 1;
} else if (strcmp(type, STANZA_TYPE_ERROR) == 0) {
return _error_message_handler(stanza);
} else if (strcmp(type, STANZA_TYPE_GROUPCHAT) == 0) {
return _groupchat_message_handler(stanza);
} else if (strcmp(type, STANZA_TYPE_CHAT) == 0) {
return _chat_message_handler(stanza);
} else {
log_error("Message stanza received with unknown type: %s", type);
return 1;
}
}
static int
_groupchat_message_handler(xmpp_stanza_t * const stanza)
{
@ -406,11 +427,7 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
// determine chatstate support of recipient
gboolean recipient_supports = FALSE;
if ((xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ACTIVE) != NULL) ||
(xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) ||
(xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) ||
(xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) ||
(xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL)) {
if (stanza_contains_chat_state(stanza)) {
recipient_supports = TRUE;
}
@ -464,27 +481,6 @@ _chat_message_handler(xmpp_stanza_t * const stanza)
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, STANZA_ATTR_TYPE);
if (type == NULL) {
log_error("Message stanza received with no type attribute");
return 1;
} else if (strcmp(type, STANZA_TYPE_ERROR) == 0) {
return _error_message_handler(stanza);
} else if (strcmp(type, STANZA_TYPE_GROUPCHAT) == 0) {
return _groupchat_message_handler(stanza);
} else if (strcmp(type, STANZA_TYPE_CHAT) == 0) {
return _chat_message_handler(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,
@ -571,20 +567,7 @@ _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata)
if (jabber_conn.conn_status == JABBER_CONNECTED) {
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
xmpp_stanza_t *iq, *ping;
iq = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
xmpp_stanza_set_id(iq, "c2s1");
ping = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(ping, STANZA_NAME_PING);
xmpp_stanza_set_ns(ping, STANZA_NS_PING);
xmpp_stanza_add_child(iq, ping);
xmpp_stanza_release(ping);
xmpp_stanza_t *iq = stanza_create_ping_iq(ctx);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}

View File

@ -168,3 +168,32 @@ stanza_create_roster_iq(xmpp_ctx_t *ctx)
return iq;
}
gboolean
stanza_contains_chat_state(xmpp_stanza_t *stanza)
{
return ((xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ACTIVE) != NULL) ||
(xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) ||
(xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) ||
(xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) ||
(xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL));
}
xmpp_stanza_t *
stanza_create_ping_iq(xmpp_ctx_t *ctx)
{
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
xmpp_stanza_set_id(iq, "c2s1");
xmpp_stanza_t *ping = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(ping, STANZA_NAME_PING);
xmpp_stanza_set_ns(ping, STANZA_NS_PING);
xmpp_stanza_add_child(iq, ping);
xmpp_stanza_release(ping);
return iq;
}

View File

@ -85,5 +85,8 @@ xmpp_stanza_t* stanza_create_presence(xmpp_ctx_t *ctx, const char * const show,
const char * const status);
xmpp_stanza_t* stanza_create_roster_iq(xmpp_ctx_t *ctx);
xmpp_stanza_t* stanza_create_ping_iq(xmpp_ctx_t *ctx);
gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
#endif