1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Merge branch 'master' into roomconfig

Conflicts:
	src/server_events.h
This commit is contained in:
James Booth 2014-09-07 21:54:04 +01:00
commit 14ede0e44c
3 changed files with 51 additions and 0 deletions

View File

@ -601,3 +601,13 @@ handle_ping_result(const char * const from, int millis)
cons_show("Ping response from %s: %dms.", from, millis);
}
}
void
handle_ping_error_result(const char * const from, const char * const error)
{
if (error == NULL) {
cons_show_error("Error returned from pinging %s.", from);
} else {
cons_show_error("Error returned form pinging %s: %s.", from, error);
}
}

View File

@ -95,6 +95,7 @@ void handle_presence_error(const char *from, const char * const type,
const char *err_msg);
void handle_xmpp_stanza(const char * const msg);
void handle_ping_result(const char * const from, int millis);
void handle_ping_error_result(const char * const from, const char * const error);
void handle_room_configure(const char * const room, DataForm *form);
void handle_room_configuration_form_error(void);

View File

@ -286,6 +286,8 @@ static int
_manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
GDateTime *sent = (GDateTime *)userdata;
GDateTime *now = g_date_time_new_now_local();
@ -296,6 +298,44 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza,
g_date_time_unref(now);
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *type = xmpp_stanza_get_type(stanza);
// handle error responses
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
// no error stanza
if (error == NULL) {
handle_ping_error_result(from, NULL);
return 0;
}
// no children of error stanza
xmpp_stanza_t *error_child = xmpp_stanza_get_children(error);
if (error_child == NULL) {
handle_ping_error_result(from, NULL);
return 0;
}
// text child found
xmpp_stanza_t *error_text_stanza = xmpp_stanza_get_child_by_name(error, STANZA_NAME_TEXT);
if (error_text_stanza != NULL) {
char *error_text = xmpp_stanza_get_text(error_text_stanza);
// text found
if (error_text != NULL) {
handle_ping_error_result(from, error_text);
xmpp_free(ctx, error_text);
return 0;
}
// no text child found
} else {
char *error_child_name = xmpp_stanza_get_name(error_child);
handle_ping_error_result(from, error_child_name);
return 0;
}
}
handle_ping_result(from, elapsed_millis);