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

Added /autoping command to set ping interval or disable with 0

This commit is contained in:
James Booth 2012-11-26 23:58:24 +00:00
parent 791667fa86
commit 213ccc0150
6 changed files with 79 additions and 4 deletions

View File

@ -117,6 +117,7 @@ static gboolean _cmd_set_chlog(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_history(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_states(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_outtype(gchar **args, struct cmd_help_t help);
static gboolean _cmd_set_autoping(gchar **args, struct cmd_help_t help);
static gboolean _cmd_vercheck(gchar **args, struct cmd_help_t help);
static gboolean _cmd_away(gchar **args, struct cmd_help_t help);
static gboolean _cmd_online(gchar **args, struct cmd_help_t help);
@ -506,6 +507,18 @@ static struct cmd_t setting_commands[] =
"Config file value : reconnect=seconds",
NULL } } },
{ "/autoping",
_cmd_set_autoping, parse_args, 1, 1,
{ "/autoping seconds", "Server ping interval.",
{ "/autoping seconds",
"--------------------",
"Set the number of seconds between server pings, so ensure connection kept alive.",
"A value of 0 will switch off autopinging the server.",
"",
"Config file section : [jabber]",
"Config file value : autoping=seconds",
NULL } } },
{ "/priority",
_cmd_set_priority, parse_args, 1, 1,
{ "/priority <value>", "Set priority for connection.",
@ -1507,7 +1520,26 @@ _cmd_set_reconnect(gchar **args, struct cmd_help_t help)
cons_show("Usage: %s", help.usage);
}
/* TODO: make 'level' subcommand for debug level */
return TRUE;
}
static gboolean
_cmd_set_autoping(gchar **args, struct cmd_help_t help)
{
char *value = args[0];
int intval;
if (_strtoi(value, &intval, 0, INT_MAX) == 0) {
prefs_set_autoping(intval);
jabber_set_autoping(intval);
if (intval == 0) {
cons_show("Autoping disabled.", intval);
} else {
cons_show("Autoping interval set to %d seconds.", intval);
}
} else {
cons_show("Usage: %s", help.usage);
}
return TRUE;
}

View File

@ -35,8 +35,6 @@
#include "room_chat.h"
#include "stanza.h"
#define PING_INTERVAL 5000 // 2 minutes
static struct _jabber_conn_t {
xmpp_log_t *log;
xmpp_ctx_t *ctx;
@ -389,6 +387,22 @@ jabber_update_presence(jabber_presence_t status, const char * const msg)
xmpp_stanza_release(presence);
}
void
jabber_set_autoping(int seconds)
{
if (jabber_conn.conn_status != JABBER_CONNECTED) {
return;
} else {
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);
}
}
}
jabber_conn_status_t
jabber_get_connection_status(void)
{
@ -660,7 +674,11 @@ _connection_handler(xmpp_conn_t * const conn,
xmpp_handler_add(conn, _message_handler, NULL, STANZA_NAME_MESSAGE, NULL, ctx);
xmpp_handler_add(conn, _presence_handler, NULL, STANZA_NAME_PRESENCE, NULL, ctx);
xmpp_id_handler_add(conn, _roster_handler, "roster", ctx);
xmpp_timed_handler_add(conn, _ping_timed_handler, PING_INTERVAL, ctx);
if (prefs_get_autoping() != 0) {
int millis = prefs_get_autoping() * 1000;
xmpp_timed_handler_add(conn, _ping_timed_handler, millis, ctx);
}
_jabber_roster_request();
jabber_conn.conn_status = JABBER_CONNECTED;

View File

@ -69,5 +69,6 @@ jabber_presence_t jabber_get_presence(void);
char * jabber_get_status(void);
void jabber_free_resources(void);
void jabber_restart(void);
void jabber_set_autoping(int seconds);
#endif

View File

@ -252,6 +252,19 @@ prefs_set_reconnect(gint value)
_save_prefs();
}
gint
prefs_get_autoping(void)
{
return g_key_file_get_integer(prefs, "jabber", "autoping", NULL);
}
void
prefs_set_autoping(gint value)
{
g_key_file_set_integer(prefs, "jabber", "autoping", value);
_save_prefs();
}
gboolean
prefs_get_vercheck(void)
{

View File

@ -78,6 +78,8 @@ void prefs_set_priority(gint value);
gint prefs_get_priority(void);
void prefs_set_reconnect(gint value);
gint prefs_get_reconnect(void);
void prefs_set_autoping(gint value);
gint prefs_get_autoping(void);
void prefs_add_login(const char *jid);

View File

@ -1076,6 +1076,15 @@ cons_prefs(void)
cons_show("Reconnect interval : %d seconds", reconnect_interval);
}
gint autoping_interval = prefs_get_autoping();
if (autoping_interval == 0) {
cons_show("Autoping interval : OFF");
} else if (remind_period == 1) {
cons_show("Autoping interval : 1 second");
} else {
cons_show("Autoping interval : %d seconds", autoping_interval);
}
cons_show("");
if (current_index == 0) {