1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2014-01-27 22:13:27 +00:00
commit 18dfef0b83
8 changed files with 111 additions and 51 deletions

View File

@ -62,6 +62,18 @@ handle_recipient_not_found(const char * const recipient, const char * const err_
}
}
void
handle_recipient_error(const char * const recipient, const char * const err_msg)
{
ui_handle_recipient_error(recipient, err_msg);
}
void
handle_error(const char * const err_msg)
{
ui_handle_error(err_msg);
}
void
handle_login_account_success(char *account_name)
{

View File

@ -76,5 +76,7 @@ void handle_roster_remove(const char * const barejid);
void handle_roster_add(const char * const barejid, const char * const name);
void handle_autoping_cancel(void);
void handle_recipient_not_found(const char * const recipient, const char * const err_msg);
void handle_recipient_error(const char * const recipient, const char * const err_msg);
void handle_error(const char * const err_msg);
#endif

View File

@ -390,6 +390,39 @@ _ui_handle_recipient_not_found(const char * const recipient, const char * const
g_string_free(msg, TRUE);
}
static void
_ui_handle_recipient_error(const char * const recipient, const char * const err_msg)
{
ProfWin *win = wins_get_by_recipient(recipient);
GString *msg = g_string_new("");
g_string_printf(msg, "Error from %s: %s", recipient, err_msg);
// always show in console
cons_show_error(msg->str);
// show in window if exists for recipient
if (win != NULL) {
win_print_line(win, '!', COLOUR_ERROR, msg->str);
}
wins_refresh_current();
g_string_free(msg, TRUE);
}
static void
_ui_handle_error(const char * const err_msg)
{
GString *msg = g_string_new("");
g_string_printf(msg, "Error %s", err_msg);
cons_show_error(msg->str);
wins_refresh_current();
g_string_free(msg, TRUE);
}
static void
_ui_disconnected(void)
{
@ -1757,4 +1790,6 @@ ui_init_module(void)
ui_chat_win_contact_online = _ui_chat_win_contact_online;
ui_chat_win_contact_offline = _ui_chat_win_contact_offline;
ui_handle_recipient_not_found = _ui_handle_recipient_not_found;
ui_handle_recipient_error = _ui_handle_recipient_error;
ui_handle_error = _ui_handle_error;
}

View File

@ -131,6 +131,8 @@ 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_offline)(PContact contact, char *resource, char *status);
void (*ui_handle_recipient_not_found)(const char * const recipient, const char * const err_msg);
void (*ui_handle_recipient_error)(const char * const recipient, const char * const err_msg);
void (*ui_handle_error)(const char * const err_msg);
// contact status functions
void (*ui_status_room)(const char * const contact);

View File

@ -326,49 +326,6 @@ _connection_free_session_data(void)
presence_clear_sub_requests();
}
int
connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = connection_get_ctx();
gchar *err_msg = NULL;
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT);
if (error_stanza == NULL) {
log_debug("error message without <error/> received");
} else {
// check for text
if (text_stanza != NULL) {
err_msg = xmpp_stanza_get_text(text_stanza);
if (err_msg != NULL) {
handle_error_message(from, err_msg);
xmpp_free(ctx, err_msg);
}
// TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2]
// otherwise show defined-condition
} else {
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error_stanza);
if (err_cond == NULL) {
log_debug("error message without <defined-condition/> or <text/> received");
} else {
err_msg = xmpp_stanza_get_name(err_cond);
handle_error_message(from, err_msg);
// TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2]
}
}
}
return 1;
}
static jabber_conn_status_t
_jabber_connect(const char * const fulljid, const char * const passwd,
const char * const altdomain, int port)

View File

@ -29,8 +29,6 @@
xmpp_conn_t *connection_get_conn(void);
xmpp_ctx_t *connection_get_ctx(void);
int connection_error_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
void connection_set_priority(int priority);
void connection_set_presence_message(const char * const message);
void connection_add_available_resource(Resource *resource);

View File

@ -193,9 +193,10 @@ static int
_message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
// log message, function never returns NULL
char *id = xmpp_stanza_get_id(stanza);
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
// stanza_get_error never returns NULL
char *err_msg = stanza_get_error_message(stanza);
GString *log_msg = g_string_new("Error receievd");
@ -211,7 +212,7 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
}
g_string_append(log_msg, ", error: ");
g_string_append(log_msg, err_msg);
log_info(log_msg->str);
g_string_free(log_msg, TRUE);
@ -222,10 +223,17 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE);
}
// handle recipient not found
// handle recipient not found ('from' contains a value and type is 'cancel')
if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) {
char *cpy = strdup(from);
handle_recipient_not_found(cpy, err_msg);
handle_recipient_not_found(from, err_msg);
// handle any other error from recipient
} else if (from != NULL) {
handle_recipient_error(from, err_msg);
// handle errors from no recipient
} else {
handle_error(err_msg);
}
return 1;

View File

@ -55,6 +55,8 @@ static int _available_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _muc_user_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _presence_error_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static char* _get_caps_key(xmpp_stanza_t * const stanza);
static void _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence);
@ -72,7 +74,7 @@ presence_add_handlers(void)
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
HANDLE(NULL, STANZA_TYPE_ERROR, connection_error_handler);
HANDLE(NULL, STANZA_TYPE_ERROR, _presence_error_handler);
HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler);
HANDLE(NULL, STANZA_TYPE_UNAVAILABLE, _unavailable_handler);
HANDLE(NULL, STANZA_TYPE_SUBSCRIBE, _subscribe_handler);
@ -329,6 +331,50 @@ _presence_leave_chat_room(const char * const room_jid)
}
}
static int
_presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
xmpp_ctx_t *ctx = connection_get_ctx();
gchar *err_msg = NULL;
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT);
if (error_stanza == NULL) {
log_debug("error message without <error/> received");
} else {
// check for text
if (text_stanza != NULL) {
err_msg = xmpp_stanza_get_text(text_stanza);
if (err_msg != NULL) {
handle_error_message(from, err_msg);
xmpp_free(ctx, err_msg);
}
// TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2]
// otherwise show defined-condition
} else {
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error_stanza);
if (err_cond == NULL) {
log_debug("error message without <defined-condition/> or <text/> received");
} else {
err_msg = xmpp_stanza_get_name(err_cond);
handle_error_message(from, err_msg);
// TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2]
}
}
}
return 1;
}
static int
_unsubscribed_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)