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:51:10 +00:00
commit 7374d8aa58
4 changed files with 81 additions and 57 deletions

View File

@ -170,7 +170,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
if (conn_status == JABBER_DISCONNECTED) { if (conn_status == JABBER_DISCONNECTED) {
cons_show_error("Connection attempt for %s failed.", jid); cons_show_error("Connection attempt for %s failed.", jid);
log_debug("Connection attempt for %s failed", jid); log_info("Connection attempt for %s failed", jid);
} }
free(jid); free(jid);

View File

@ -62,6 +62,7 @@ static char * _get_groupchat_log_filename(const char * const room,
static gchar * _get_chatlog_dir(void); static gchar * _get_chatlog_dir(void);
static gchar * _get_log_file(void); static gchar * _get_log_file(void);
static void _rotate_log_file(void); static void _rotate_log_file(void);
static char* _log_string_from_level(log_level_t level);
void void
log_debug(const char * const msg, ...) log_debug(const char * const msg, ...)
@ -143,8 +144,11 @@ log_msg(log_level_t level, const char * const area, const char * const msg)
long result; long result;
dt = g_date_time_new_now(tz); dt = g_date_time_new_now(tz);
char *level_str = _log_string_from_level(level);
gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S"); gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S");
fprintf(logp, "%s: %s: %s\n", date_fmt, area, msg);
fprintf(logp, "%s: %s: %s: %s\n", date_fmt, area, level_str, msg);
g_date_time_unref(dt); g_date_time_unref(dt);
fflush(logp); fflush(logp);
@ -523,3 +527,21 @@ _get_log_file(void)
return result; return result;
} }
static char*
_log_string_from_level(log_level_t level)
{
switch (level)
{
case PROF_LEVEL_ERROR:
return "ERR";
case PROF_LEVEL_WARN:
return "WRN";
case PROF_LEVEL_INFO:
return "INF";
case PROF_LEVEL_DEBUG:
return "DBG";
default:
return "LOG";
}
}

View File

@ -195,34 +195,35 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
{ {
char *id = xmpp_stanza_get_id(stanza); char *id = xmpp_stanza_get_id(stanza);
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); 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");
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) {
type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE);
} }
// stanza_get_error never returns NULL
char *err_msg = stanza_get_error_message(stanza);
GString *log_msg = g_string_new("message stanza error received");
if (id != NULL) {
g_string_append(log_msg, " id=");
g_string_append(log_msg, id);
}
if (from != NULL) {
g_string_append(log_msg, " from=");
g_string_append(log_msg, from);
}
if (type != NULL) {
g_string_append(log_msg, " type=");
g_string_append(log_msg, type);
}
g_string_append(log_msg, " error=");
g_string_append(log_msg, err_msg);
log_info(log_msg->str);
g_string_free(log_msg, TRUE);
// handle recipient not found ('from' contains a value and type is 'cancel') // handle recipient not found ('from' contains a value and type is 'cancel')
if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) { if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) {
handle_recipient_not_found(from, err_msg); handle_recipient_not_found(from, err_msg);
@ -236,6 +237,8 @@ _message_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
handle_error(err_msg); handle_error(err_msg);
} }
free(err_msg);
return 1; return 1;
} }

View File

@ -335,41 +335,40 @@ static int
_presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata) void * const userdata)
{ {
xmpp_ctx_t *ctx = connection_get_ctx(); char *id = xmpp_stanza_get_id(stanza);
gchar *err_msg = NULL; char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
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 *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); char *type = NULL;
if (error_stanza != NULL) {
if (error_stanza == NULL) { type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE);
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] // stanza_get_error never returns NULL
char *err_msg = stanza_get_error_message(stanza);
// otherwise show defined-condition GString *log_msg = g_string_new("presence stanza error received");
} else { if (id != NULL) {
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error_stanza); g_string_append(log_msg, " id=");
g_string_append(log_msg, id);
}
if (from != NULL) {
g_string_append(log_msg, " from=");
g_string_append(log_msg, from);
}
if (type != NULL) {
g_string_append(log_msg, " type=");
g_string_append(log_msg, type);
}
g_string_append(log_msg, " error=");
g_string_append(log_msg, err_msg);
if (err_cond == NULL) { log_info(log_msg->str);
log_debug("error message without <defined-condition/> or <text/> received");
g_string_free(log_msg, TRUE);
} else {
err_msg = xmpp_stanza_get_name(err_cond);
handle_error_message(from, err_msg); handle_error_message(from, err_msg);
// TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2] free(err_msg);
}
}
}
return 1; return 1;
} }