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

Show original error message

This commit is contained in:
James Booth 2014-01-26 22:50:22 +00:00
parent 50f1a5ecc0
commit 1a300ce7d3
5 changed files with 32 additions and 24 deletions

View File

@ -53,12 +53,11 @@ handle_error_message(const char *from, const char *err_msg)
} }
void void
handle_recipient_not_found(const char *from) handle_recipient_not_found(const char * const recipient, const char * const err_msg)
{ {
log_info("Removing chat session for %s", from); ui_handle_recipient_not_found(recipient, err_msg);
ui_handle_recipient_not_found(from); if (prefs_get_boolean(PREF_STATES) && chat_session_exists(recipient)) {
if (prefs_get_boolean(PREF_STATES) && chat_session_exists(from)) { chat_session_set_recipient_supports(recipient, FALSE);
chat_session_set_recipient_supports(from, FALSE);
} }
} }

View File

@ -75,6 +75,6 @@ void handle_group_remove(const char * const contact,
void handle_roster_remove(const char * const barejid); void handle_roster_remove(const char * const barejid);
void handle_roster_add(const char * const barejid, const char * const name); void handle_roster_add(const char * const barejid, const char * const name);
void handle_autoping_cancel(void); void handle_autoping_cancel(void);
void handle_recipient_not_found(const char *from); void handle_recipient_not_found(const char * const recipient, const char * const err_msg);
#endif #endif

View File

@ -355,14 +355,14 @@ _ui_handle_error_message(const char * const from, const char * const err_msg)
} }
static void static void
_ui_handle_recipient_not_found(const char * const from) _ui_handle_recipient_not_found(const char * const recipient, const char * const err_msg)
{ {
ProfWin *win = wins_get_by_recipient(from); ProfWin *win = wins_get_by_recipient(recipient);
GString *msg = g_string_new(""); GString *msg = g_string_new("");
// no window for intended recipient, show message in current and console // no window for intended recipient, show message in current and console
if (win == NULL) { if (win == NULL) {
g_string_printf(msg, "Recipient %s not found at server.", from); g_string_printf(msg, "Recipient %s not found: %s", recipient, err_msg);
cons_show_error(msg->str); cons_show_error(msg->str);
win = wins_get_current(); win = wins_get_current();
if (win->type != WIN_CONSOLE) { if (win->type != WIN_CONSOLE) {
@ -371,16 +371,13 @@ _ui_handle_recipient_not_found(const char * const from)
// intended recipient was invalid chat room // intended recipient was invalid chat room
} else if (win->type == WIN_MUC) { } else if (win->type == WIN_MUC) {
g_string_printf(msg, "You have not joined %s.", from); g_string_printf(msg, "Room %s not found: %s", recipient, err_msg);
cons_show_error(msg->str); cons_show_error(msg->str);
win_print_line(win, '!', COLOUR_ERROR, msg->str); win_print_line(win, '!', COLOUR_ERROR, msg->str);
// unknown chat recipient // unknown chat recipient
} else { } else {
if (prefs_get_boolean(PREF_STATES) && chat_session_exists(from)) { g_string_printf(msg, "Recipient %s not found: %s", recipient, err_msg);
chat_session_set_recipient_supports(from, FALSE);
}
g_string_printf(msg, "Recipient %s not found at server.", from);
cons_show_error(msg->str); cons_show_error(msg->str);
win_print_line(win, '!', COLOUR_ERROR, msg->str); win_print_line(win, '!', COLOUR_ERROR, msg->str);
} }

View File

@ -130,7 +130,7 @@ void (*ui_group_added)(const char * const contact, const char * const group);
void (*ui_group_removed)(const char * const contact, const char * const group); void (*ui_group_removed)(const char * const contact, const char * const group);
void (*ui_chat_win_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity); void (*ui_chat_win_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity);
void (*ui_chat_win_contact_offline)(PContact contact, char *resource, char *status); void (*ui_chat_win_contact_offline)(PContact contact, char *resource, char *status);
void (*ui_handle_recipient_not_found)(const char * const from); void (*ui_handle_recipient_not_found)(const char * const recipient, const char * const err_msg);
// contact status functions // contact status functions
void (*ui_status_room)(const char * const contact); void (*ui_status_room)(const char * const contact);

View File

@ -194,15 +194,28 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata) void * const userdata)
{ {
// log message, function never returns NULL // log message, function never returns NULL
char *err_msg = stanza_get_error_message(stanza);
char *id = xmpp_stanza_get_id(stanza); char *id = xmpp_stanza_get_id(stanza);
if (id != NULL) {
log_info("Error recieved (id=%s): %s", id, err_msg);
} else {
log_info("Error received: %s", err_msg);
}
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *err_msg = stanza_get_error_message(stanza);
GString *log_msg = g_string_new("Error receievd");
if (id != NULL) {
g_string_append(log_msg, " (id:");
g_string_append(log_msg, id);
g_string_append(log_msg, ")");
}
if (from != NULL) {
g_string_append(log_msg, " (from:");
g_string_append(log_msg, from);
g_string_append(log_msg, ")");
}
g_string_append(log_msg, ", error: ");
g_string_append(log_msg, err_msg);
log_info(log_msg->str);
g_string_free(log_msg, TRUE);
xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
char *type = NULL; char *type = NULL;
if (error_stanza != NULL) { if (error_stanza != NULL) {
@ -212,8 +225,7 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
// handle recipient not found // handle recipient not found
if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) { if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) {
char *cpy = strdup(from); char *cpy = strdup(from);
log_info("Recipient %s not found.", cpy); handle_recipient_not_found(cpy, err_msg);
handle_recipient_not_found(cpy);
} }
return 1; return 1;