mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Added ping for keepalive
This commit is contained in:
parent
91b369edf6
commit
b512f3b8ff
30
jabber.c
30
jabber.c
@ -27,6 +27,8 @@
|
||||
#include "log.h"
|
||||
#include "windows.h"
|
||||
|
||||
#define PING_INTERVAL 120000 // 2 minutes
|
||||
|
||||
// log reference
|
||||
extern FILE *logp;
|
||||
|
||||
@ -65,6 +67,8 @@ static int _jabber_message_handler(xmpp_conn_t * const conn,
|
||||
static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata);
|
||||
|
||||
static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata);
|
||||
|
||||
void jabber_init(int disable_tls)
|
||||
{
|
||||
jabber_conn.conn_status = JABBER_STARTED;
|
||||
@ -196,6 +200,7 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t* pres;
|
||||
xmpp_handler_add(conn, _jabber_message_handler, NULL, "message", NULL, ctx);
|
||||
xmpp_id_handler_add(conn, _roster_handler, "roster", ctx);
|
||||
xmpp_timed_handler_add(conn, _ping_timed_handler, PING_INTERVAL, ctx);
|
||||
|
||||
pres = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(pres, "presence");
|
||||
@ -248,3 +253,28 @@ static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata)
|
||||
{
|
||||
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
|
||||
|
||||
xmpp_stanza_t *iq, *ping;
|
||||
|
||||
iq = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(iq, "iq");
|
||||
xmpp_stanza_set_type(iq, "get");
|
||||
xmpp_stanza_set_id(iq, "c2s1");
|
||||
|
||||
ping = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(ping, "ping");
|
||||
|
||||
// FIXME add ping namespace to libstrophe
|
||||
xmpp_stanza_set_ns(ping, "urn:xmpp:ping");
|
||||
|
||||
xmpp_stanza_add_child(iq, ping);
|
||||
xmpp_stanza_release(ping);
|
||||
xmpp_send(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user