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

Moved xmpp ping to iq module

This commit is contained in:
James Booth 2014-01-26 00:15:34 +00:00
parent fbdecdad0c
commit 5472c6965a
4 changed files with 43 additions and 39 deletions

View File

@ -2257,7 +2257,7 @@ cmd_autoping(gchar **args, struct cmd_help_t help)
if (_strtoi(value, &intval, 0, INT_MAX) == 0) { if (_strtoi(value, &intval, 0, INT_MAX) == 0) {
prefs_set_autoping(intval); prefs_set_autoping(intval);
jabber_set_autoping(intval); iq_set_autoping(intval);
if (intval == 0) { if (intval == 0) {
cons_show("Autoping disabled.", intval); cons_show("Autoping disabled.", intval);
} else { } else {

View File

@ -87,7 +87,6 @@ static void _jabber_reconnect(void);
static void _connection_handler(xmpp_conn_t * const conn, static void _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,
xmpp_stream_error_t * const stream_error, void * const userdata); xmpp_stream_error_t * const stream_error, void * const userdata);
static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata);
void _connection_free_saved_account(void); void _connection_free_saved_account(void);
void _connection_free_saved_details(void); void _connection_free_saved_details(void);
@ -224,20 +223,6 @@ _jabber_process_events(void)
} }
static void
_jabber_set_autoping(const int seconds)
{
if (jabber_conn.conn_status == JABBER_CONNECTED) {
xmpp_timed_handler_delete(jabber_conn.conn, _ping_timed_handler);
if (seconds != 0) {
int millis = seconds * 1000;
xmpp_timed_handler_add(jabber_conn.conn, _ping_timed_handler, millis,
jabber_conn.ctx);
}
}
}
static GList * static GList *
_jabber_get_available_resources(void) _jabber_get_available_resources(void)
{ {
@ -459,8 +444,6 @@ _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,
xmpp_stream_error_t * const stream_error, void * const userdata) xmpp_stream_error_t * const stream_error, void * const userdata)
{ {
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
// login success // login success
if (status == XMPP_CONN_CONNECT) { if (status == XMPP_CONN_CONNECT) {
log_debug("Connection handler: XMPP_CONN_CONNECT"); log_debug("Connection handler: XMPP_CONN_CONNECT");
@ -494,11 +477,6 @@ _connection_handler(xmpp_conn_t * const conn,
presence_add_handlers(); presence_add_handlers();
iq_add_handlers(); iq_add_handlers();
if (prefs_get_autoping() != 0) {
int millis = prefs_get_autoping() * 1000;
xmpp_timed_handler_add(conn, _ping_timed_handler, millis, ctx);
}
roster_request(); roster_request();
bookmark_request(); bookmark_request();
jabber_conn.conn_status = JABBER_CONNECTED; jabber_conn.conn_status = JABBER_CONNECTED;
@ -556,20 +534,6 @@ _connection_handler(xmpp_conn_t * const conn,
} }
} }
static int
_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 = stanza_create_ping_iq(ctx);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
return 1;
}
static log_level_t static log_level_t
_get_log_level(const xmpp_log_level_t xmpp_level) _get_log_level(const xmpp_log_level_t xmpp_level)
{ {
@ -629,7 +593,6 @@ jabber_init_module(void)
jabber_disconnect = _jabber_disconnect; jabber_disconnect = _jabber_disconnect;
jabber_shutdown = _jabber_shutdown; jabber_shutdown = _jabber_shutdown;
jabber_process_events = _jabber_process_events; jabber_process_events = _jabber_process_events;
jabber_set_autoping = _jabber_set_autoping;
jabber_get_available_resources = _jabber_get_available_resources; jabber_get_available_resources = _jabber_get_available_resources;
jabber_get_connection_status = _jabber_get_connection_status; jabber_get_connection_status = _jabber_get_connection_status;
jabber_get_fulljid = _jabber_get_fulljid; jabber_get_fulljid = _jabber_get_fulljid;

View File

@ -35,6 +35,7 @@
#include "log.h" #include "log.h"
#include "muc.h" #include "muc.h"
#include "profanity.h" #include "profanity.h"
#include "config/preferences.h"
#include "server_events.h" #include "server_events.h"
#include "xmpp/capabilities.h" #include "xmpp/capabilities.h"
#include "xmpp/connection.h" #include "xmpp/connection.h"
@ -60,6 +61,8 @@ static int _disco_items_result_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata); xmpp_stanza_t * const stanza, void * const userdata);
static int _disco_items_get_handler(xmpp_conn_t * const conn, static int _disco_items_get_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata); xmpp_stanza_t * const stanza, void * const userdata);
static int _ping_timed_handler(xmpp_conn_t * const conn,
void * const userdata);
void void
iq_add_handlers(void) iq_add_handlers(void)
@ -79,6 +82,28 @@ iq_add_handlers(void)
HANDLE(STANZA_NS_VERSION, STANZA_TYPE_RESULT, _version_result_handler); HANDLE(STANZA_NS_VERSION, STANZA_TYPE_RESULT, _version_result_handler);
HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _ping_get_handler); HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _ping_get_handler);
if (prefs_get_autoping() != 0) {
int millis = prefs_get_autoping() * 1000;
xmpp_timed_handler_add(conn, _ping_timed_handler, millis, ctx);
}
}
static void
_iq_set_autoping(const int seconds)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
if (jabber_get_connection_status() == JABBER_CONNECTED) {
xmpp_timed_handler_delete(conn, _ping_timed_handler);
if (seconds != 0) {
int millis = seconds * 1000;
xmpp_timed_handler_add(conn, _ping_timed_handler, millis,
ctx);
}
}
} }
static void static void
@ -136,6 +161,21 @@ _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1; return 1;
} }
static int
_ping_timed_handler(xmpp_conn_t * const conn, void * const userdata)
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
if (jabber_get_connection_status() == JABBER_CONNECTED) {
xmpp_stanza_t *iq = stanza_create_ping_iq(ctx);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
return 1;
}
static int static int
_version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata) void * const userdata)
@ -581,4 +621,5 @@ iq_init_module(void)
iq_disco_info_request = _iq_disco_info_request; iq_disco_info_request = _iq_disco_info_request;
iq_disco_items_request = _iq_disco_items_request; iq_disco_items_request = _iq_disco_items_request;
iq_send_software_version = _iq_send_software_version; iq_send_software_version = _iq_send_software_version;
iq_set_autoping = _iq_set_autoping;
} }

View File

@ -94,7 +94,6 @@ const char * (*jabber_get_fulljid)(void);
const char * (*jabber_get_domain)(void); const char * (*jabber_get_domain)(void);
jabber_conn_status_t (*jabber_get_connection_status)(void); jabber_conn_status_t (*jabber_get_connection_status)(void);
char * (*jabber_get_presence_message)(void); char * (*jabber_get_presence_message)(void);
void (*jabber_set_autoping)(int seconds);
char* (*jabber_get_account_name)(void); char* (*jabber_get_account_name)(void);
GList * (*jabber_get_available_resources)(void); GList * (*jabber_get_available_resources)(void);
@ -127,6 +126,7 @@ void (*iq_send_software_version)(const char * const fulljid);
void (*iq_room_list_request)(gchar *conferencejid); void (*iq_room_list_request)(gchar *conferencejid);
void (*iq_disco_info_request)(gchar *jid); void (*iq_disco_info_request)(gchar *jid);
void (*iq_disco_items_request)(gchar *jid); void (*iq_disco_items_request)(gchar *jid);
void (*iq_set_autoping)(int seconds);
// caps functions // caps functions
Capabilities* (*caps_get)(const char * const caps_str); Capabilities* (*caps_get)(const char * const caps_str);