mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge pull request #46 from pasis/master
Improved error handling. Handles when user does not exist at server, and when the server cannot be contacted (for example if the server name is typed incorrectly in the JID).
This commit is contained in:
commit
382e961563
32
src/jabber.c
32
src/jabber.c
@ -255,6 +255,32 @@ static int
|
|||||||
_message_handler(xmpp_conn_t * const conn,
|
_message_handler(xmpp_conn_t * const conn,
|
||||||
xmpp_stanza_t * const stanza, void * const userdata)
|
xmpp_stanza_t * const stanza, void * const userdata)
|
||||||
{
|
{
|
||||||
|
char *type;
|
||||||
|
char *from;
|
||||||
|
|
||||||
|
type = xmpp_stanza_get_attribute(stanza, "type");
|
||||||
|
from = xmpp_stanza_get_attribute(stanza, "from");
|
||||||
|
|
||||||
|
if (strcmp(type, "error") == 0) {
|
||||||
|
char *err_msg = NULL;
|
||||||
|
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error");
|
||||||
|
if (error == NULL) {
|
||||||
|
log_debug("error message without <error/> received");
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error);
|
||||||
|
if (err_cond == NULL) {
|
||||||
|
log_debug("error message without <defined-condition/> received");
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
err_msg = xmpp_stanza_get_name(err_cond);
|
||||||
|
}
|
||||||
|
// TODO: process 'type' attribute from <error/> [RFC6120, 8.3.2]
|
||||||
|
}
|
||||||
|
prof_handle_error_message(from, err_msg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body");
|
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body");
|
||||||
|
|
||||||
// if no message, check for chatstates
|
// if no message, check for chatstates
|
||||||
@ -265,7 +291,6 @@ _message_handler(xmpp_conn_t * const conn,
|
|||||||
// active
|
// active
|
||||||
} else if (xmpp_stanza_get_child_by_name(stanza, "composing") != NULL) {
|
} else if (xmpp_stanza_get_child_by_name(stanza, "composing") != NULL) {
|
||||||
// composing
|
// composing
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
|
||||||
prof_handle_typing(from);
|
prof_handle_typing(from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,12 +299,7 @@ _message_handler(xmpp_conn_t * const conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// message body recieved
|
// message body recieved
|
||||||
char *type = xmpp_stanza_get_attribute(stanza, "type");
|
|
||||||
if(strcmp(type, "error") == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
char *message = xmpp_stanza_get_text(body);
|
char *message = xmpp_stanza_get_text(body);
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
|
||||||
prof_handle_incoming_message(from, message);
|
prof_handle_incoming_message(from, message);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -114,6 +114,24 @@ prof_handle_incoming_message(char *from, char *message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
prof_handle_error_message(const char *from, const char *err_msg)
|
||||||
|
{
|
||||||
|
char *msg, *fmt;
|
||||||
|
|
||||||
|
if (err_msg != NULL) {
|
||||||
|
fmt = "Error received from server: %s";
|
||||||
|
msg = (char *)malloc(strlen(err_msg) + strlen(fmt) - 1);
|
||||||
|
if (msg == NULL)
|
||||||
|
goto loop_out;
|
||||||
|
sprintf(msg, fmt, err_msg);
|
||||||
|
cons_bad_show(msg);
|
||||||
|
free(msg);
|
||||||
|
}
|
||||||
|
loop_out:
|
||||||
|
win_show_error_msg(from, err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
prof_handle_login_success(const char *jid)
|
prof_handle_login_success(const char *jid)
|
||||||
{
|
{
|
||||||
|
@ -37,6 +37,7 @@ void prof_handle_typing(char *from);
|
|||||||
void prof_handle_contact_online(char *contact, char *show, char *status);
|
void prof_handle_contact_online(char *contact, char *show, char *status);
|
||||||
void prof_handle_contact_offline(char *contact, char *show, char *status);
|
void prof_handle_contact_offline(char *contact, char *show, char *status);
|
||||||
void prof_handle_incoming_message(char *from, char *message);
|
void prof_handle_incoming_message(char *from, char *message);
|
||||||
|
void prof_handle_error_message(const char *from, const char *err_msg);
|
||||||
void prof_handle_roster(GSList *roster);
|
void prof_handle_roster(GSList *roster);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
1
src/ui.h
1
src/ui.h
@ -88,6 +88,7 @@ int win_in_chat(void);
|
|||||||
char *win_get_recipient(void);
|
char *win_get_recipient(void);
|
||||||
void win_show_typing(const char * const from);
|
void win_show_typing(const char * const from);
|
||||||
void win_show_incomming_msg(const char * const from, const char * const message);
|
void win_show_incomming_msg(const char * const from, const char * const message);
|
||||||
|
void win_show_error_msg(const char * const from, const char *err_msg);
|
||||||
void win_show_outgoing_msg(const char * const from, const char * const to,
|
void win_show_outgoing_msg(const char * const from, const char * const to,
|
||||||
const char * const message);
|
const char * const message);
|
||||||
void win_handle_special_keys(const int * const ch);
|
void win_handle_special_keys(const int * const ch);
|
||||||
|
@ -73,6 +73,7 @@ static void _win_switch_if_active(const int i);
|
|||||||
static void _win_show_time(WINDOW *win);
|
static void _win_show_time(WINDOW *win);
|
||||||
static void _win_show_user(WINDOW *win, const char * const user, const int colour);
|
static void _win_show_user(WINDOW *win, const char * const user, const int colour);
|
||||||
static void _win_show_message(WINDOW *win, const char * const message);
|
static void _win_show_message(WINDOW *win, const char * const message);
|
||||||
|
static void _win_show_error_msg(WINDOW *win, const char * const message);
|
||||||
static void _show_status_string(WINDOW *win, const char * const from,
|
static void _show_status_string(WINDOW *win, const char * const from,
|
||||||
const char * const show, const char * const status, const char * const pre,
|
const char * const show, const char * const status, const char * const pre,
|
||||||
const char * const default_show);
|
const char * const default_show);
|
||||||
@ -302,6 +303,27 @@ win_show_incomming_msg(const char * const from, const char * const message)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
win_show_error_msg(const char * const from, const char *err_msg)
|
||||||
|
{
|
||||||
|
int win_index;
|
||||||
|
WINDOW *win;
|
||||||
|
|
||||||
|
if (from == NULL || err_msg == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
win_index = _find_prof_win_index(from);
|
||||||
|
// chat window exists
|
||||||
|
if (win_index < NUM_WINS) {
|
||||||
|
win = _wins[win_index].win;
|
||||||
|
_win_show_time(win);
|
||||||
|
_win_show_error_msg(win, err_msg);
|
||||||
|
if (win_index == _curr_prof_win) {
|
||||||
|
dirty = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBNOTIFY
|
#ifdef HAVE_LIBNOTIFY
|
||||||
static void
|
static void
|
||||||
_win_notify(const char * const message, int timeout,
|
_win_notify(const char * const message, int timeout,
|
||||||
@ -371,10 +393,6 @@ win_show_outgoing_msg(const char * const from, const char * const to,
|
|||||||
{
|
{
|
||||||
// if the contact is offline, show a message
|
// if the contact is offline, show a message
|
||||||
PContact contact = contact_list_get_contact(to);
|
PContact contact = contact_list_get_contact(to);
|
||||||
|
|
||||||
if (contact == NULL) {
|
|
||||||
cons_show("%s is not one of your contacts.");
|
|
||||||
} else {
|
|
||||||
int win_index = _find_prof_win_index(to);
|
int win_index = _find_prof_win_index(to);
|
||||||
WINDOW *win = NULL;
|
WINDOW *win = NULL;
|
||||||
|
|
||||||
@ -387,11 +405,13 @@ win_show_outgoing_msg(const char * const from, const char * const to,
|
|||||||
_win_show_history(win, win_index, to);
|
_win_show_history(win, win_index, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contact != NULL) {
|
||||||
if (strcmp(p_contact_show(contact), "offline") == 0) {
|
if (strcmp(p_contact_show(contact), "offline") == 0) {
|
||||||
const char const *show = p_contact_show(contact);
|
const char const *show = p_contact_show(contact);
|
||||||
const char const *status = p_contact_status(contact);
|
const char const *status = p_contact_status(contact);
|
||||||
_show_status_string(win, to, show, status, "--", "offline");
|
_show_status_string(win, to, show, status, "--", "offline");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// use existing window
|
// use existing window
|
||||||
} else {
|
} else {
|
||||||
@ -402,7 +422,6 @@ win_show_outgoing_msg(const char * const from, const char * const to,
|
|||||||
_win_show_user(win, from, 0);
|
_win_show_user(win, from, 0);
|
||||||
_win_show_message(win, message);
|
_win_show_message(win, message);
|
||||||
_win_switch_if_active(win_index);
|
_win_switch_if_active(win_index);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -901,6 +920,14 @@ _win_show_message(WINDOW *win, const char * const message)
|
|||||||
wprintw(win, "%s\n", message);
|
wprintw(win, "%s\n", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_win_show_error_msg(WINDOW *win, const char * const message)
|
||||||
|
{
|
||||||
|
wattron(win, COLOUR_ERR);
|
||||||
|
wprintw(win, "%s\n", message);
|
||||||
|
wattroff(win, COLOUR_ERR);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_current_window_refresh(void)
|
_current_window_refresh(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user