Compare commits
5 Commits
bdff48c765
...
feat/autop
| Author | SHA1 | Date | |
|---|---|---|---|
|
14fb6e3b41
|
|||
|
19bfad76ba
|
|||
|
b5bbad8d2c
|
|||
|
7fd0cded3d
|
|||
|
2012e15c0b
|
@@ -99,11 +99,11 @@ static void _disco_items_result_handler(xmpp_stanza_t* const stanza);
|
||||
static void _last_activity_get_handler(xmpp_stanza_t* const stanza);
|
||||
static void _version_get_handler(xmpp_stanza_t* const stanza);
|
||||
static void _ping_get_handler(xmpp_stanza_t* const stanza);
|
||||
static void _disco_autoping_warning_message(GHashTable* features);
|
||||
|
||||
static int _version_result_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _disco_autoping_warning_message(GHashTable* features);
|
||||
static int _http_upload_response_id_handler(xmpp_stanza_t* const stanza, void* const upload_ctx);
|
||||
static int _last_activity_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
static int _room_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
@@ -2431,7 +2431,8 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* con
|
||||
child = xmpp_stanza_get_next(child);
|
||||
}
|
||||
|
||||
if (!from) {
|
||||
// Prevent repetitions by avoiding checks of disco items (from connection_set_disco_items)
|
||||
if (from && g_ascii_strcasecmp(from, connection_get_domain()) == 0) {
|
||||
_disco_autoping_warning_message(features);
|
||||
}
|
||||
}
|
||||
@@ -2441,20 +2442,19 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t* const stanza, void* con
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
static void
|
||||
_disco_autoping_warning_message(GHashTable* features)
|
||||
{
|
||||
gboolean server_supports_ping = g_hash_table_contains(features, "urn:xmpp:ping");
|
||||
gboolean users_prefers_warning = prefs_get_boolean(PREF_AUTOPING_WARNING);
|
||||
gboolean user_prefers_warning = prefs_get_boolean(PREF_AUTOPING_WARNING);
|
||||
gboolean is_autoping_enabled = prefs_get_autoping() != 0;
|
||||
|
||||
if (!is_autoping_enabled && server_supports_ping && users_prefers_warning) {
|
||||
if (!is_autoping_enabled && server_supports_ping && user_prefers_warning) {
|
||||
cons_show("This server supports XEP-0199: XMPP Ping (better keepalive detection),\n"
|
||||
"but autoping feature is currently disabled in settings.\n"
|
||||
"Consider enabling it (e.g., `/autoping set 30`) for improved connection stability.\n"
|
||||
"Use `/autoping warning off` to disable this message.");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -155,6 +155,8 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_when_server_unsupported),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_when_autoping_enabled),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_when_user_disabled),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_for_user_jid),
|
||||
PROF_FUNC_TEST(autoping_warning_not_shown_for_subdomain_service),
|
||||
|
||||
/* Service Discovery - XEP-0030 */
|
||||
PROF_FUNC_TEST(disco_info_shows_identity),
|
||||
|
||||
@@ -194,7 +194,7 @@ autoping_warning_not_shown_when_autoping_enabled(void** state)
|
||||
void
|
||||
autoping_warning_not_shown_when_user_disabled(void** state)
|
||||
{
|
||||
// User opted out -> no warning. Command takes on|off ("enable|disable" doc is wrong).
|
||||
// User opted out -> no warning.
|
||||
_stub_server_disco(TRUE);
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
@@ -208,3 +208,48 @@ autoping_warning_not_shown_when_user_disabled(void** state)
|
||||
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
||||
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_warning_not_shown_for_user_jid(void** state)
|
||||
{
|
||||
// disco#info from a user JID (with '@') should not trigger the warning,
|
||||
// only server responses (no '@') should.
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='buddy1@localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='person' type='chat' name='Buddy1'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
||||
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_warning_not_shown_for_subdomain_service(void** state)
|
||||
{
|
||||
// disco#info from a subdomain service should not trigger the warning, only the server's own domain should
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='conf.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='conference' type='text' name='Conference Service'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_timeout(NEGATIVE_ASSERT_TIMEOUT);
|
||||
assert_false(prof_output_regex(AUTOPING_WARNING_MATCH));
|
||||
}
|
||||
|
||||
@@ -8,3 +8,5 @@ void autoping_warning_shown_when_disabled(void** state);
|
||||
void autoping_warning_not_shown_when_server_unsupported(void** state);
|
||||
void autoping_warning_not_shown_when_autoping_enabled(void** state);
|
||||
void autoping_warning_not_shown_when_user_disabled(void** state);
|
||||
void autoping_warning_not_shown_for_user_jid(void** state);
|
||||
void autoping_warning_not_shown_for_subdomain_service(void** state);
|
||||
|
||||
Reference in New Issue
Block a user