mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Using vargs in cons_bad_show
This commit is contained in:
parent
81f9292948
commit
a5082a54bd
11
src/jabber.c
11
src/jabber.c
@ -63,7 +63,7 @@ static void _connection_handler(xmpp_conn_t * const conn,
|
||||
static int _message_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _groupchat_message_handler(xmpp_stanza_t * const stanza);
|
||||
static int _error_message_handler(xmpp_stanza_t * const stanza);
|
||||
static int _error_handler(xmpp_stanza_t * const stanza);
|
||||
static int _chat_message_handler(xmpp_stanza_t * const stanza);
|
||||
|
||||
static int _roster_handler(xmpp_conn_t * const conn,
|
||||
@ -322,7 +322,7 @@ _message_handler(xmpp_conn_t * const conn,
|
||||
log_error("Message stanza received with no type attribute");
|
||||
return 1;
|
||||
} else if (strcmp(type, STANZA_TYPE_ERROR) == 0) {
|
||||
return _error_message_handler(stanza);
|
||||
return _error_handler(stanza);
|
||||
} else if (strcmp(type, STANZA_TYPE_GROUPCHAT) == 0) {
|
||||
return _groupchat_message_handler(stanza);
|
||||
} else if (strcmp(type, STANZA_TYPE_CHAT) == 0) {
|
||||
@ -387,7 +387,7 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza)
|
||||
}
|
||||
|
||||
static int
|
||||
_error_message_handler(xmpp_stanza_t * const stanza)
|
||||
_error_handler(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
char *err_msg = NULL;
|
||||
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
|
||||
@ -647,6 +647,11 @@ _presence_handler(xmpp_conn_t * const conn,
|
||||
char *short_jid = strtok(jid_cpy, "/");
|
||||
|
||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
||||
|
||||
if ((type != NULL) && (strcmp(type, STANZA_TYPE_ERROR) == 0)) {
|
||||
return _error_handler(stanza);
|
||||
}
|
||||
|
||||
// handle chat room presence
|
||||
if (room_is_active(from)) {
|
||||
|
@ -135,18 +135,12 @@ prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp)
|
||||
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);
|
||||
cons_bad_show("Error received from server: %s", err_msg);
|
||||
} else {
|
||||
cons_bad_show("Unknown error received from server.");
|
||||
}
|
||||
loop_out:
|
||||
|
||||
win_show_error_msg(from, err_msg);
|
||||
}
|
||||
|
||||
|
2
src/ui.h
2
src/ui.h
@ -126,7 +126,7 @@ void cons_navigation_help(void);
|
||||
void cons_prefs(void);
|
||||
void cons_bad_command(const char * const cmd);
|
||||
void cons_show(const char * const cmd, ...);
|
||||
void cons_bad_show(const char * const cmd);
|
||||
void cons_bad_show(const char * const cmd, ...);
|
||||
void cons_highlight_show(const char * const cmd);
|
||||
void cons_show_contacts(GSList * list);
|
||||
void cons_check_version(gboolean not_available_msg);
|
||||
|
@ -1000,12 +1000,18 @@ cons_show_contacts(GSList *list)
|
||||
}
|
||||
|
||||
void
|
||||
cons_bad_show(const char * const msg)
|
||||
cons_bad_show(const char * const msg, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, msg);
|
||||
GString *fmt_msg = g_string_new(NULL);
|
||||
g_string_vprintf(fmt_msg, msg, arg);
|
||||
_win_show_time(_cons_win);
|
||||
wattron(_cons_win, COLOUR_ERR);
|
||||
wprintw(_cons_win, "%s\n", msg);
|
||||
wprintw(_cons_win, "%s\n", fmt_msg->str);
|
||||
wattroff(_cons_win, COLOUR_ERR);
|
||||
g_string_free(fmt_msg, TRUE);
|
||||
va_end(arg);
|
||||
|
||||
if (_curr_prof_win == 0)
|
||||
dirty = TRUE;
|
||||
|
Loading…
Reference in New Issue
Block a user