diff options
author | James Booth <boothj5@gmail.com> | 2014-01-27 22:35:04 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-01-27 22:35:04 +0000 |
commit | e9959d5d38c5bbe9c4030ef6d59f4b606113b478 (patch) | |
tree | d71a22c32f614f505a6283cb10fc3a649e3bb197 /src/xmpp | |
parent | 27293ebbc2171f52d6db6d0075b63db8fcacc0be (diff) | |
download | profani-tty-e9959d5d38c5bbe9c4030ef6d59f4b606113b478.tar.gz |
Refactored presence_error_handler
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/message.c | 27 | ||||
-rw-r--r-- | src/xmpp/presence.c | 55 |
2 files changed, 42 insertions, 40 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 6f340b2d..5ea54f2d 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -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 *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); + char *type = NULL; + if (error_stanza != NULL) { + 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("Error receievd"); + 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="); 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, from); - g_string_append(log_msg, ")"); } - g_string_append(log_msg, ", error: "); + 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); - xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); - char *type = NULL; - if (error_stanza != NULL) { - type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); - } - // handle recipient not found ('from' contains a value and type is 'cancel') if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) { 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); } + free(err_msg); + return 1; } diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index f61d605d..538898f8 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -335,41 +335,40 @@ 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); + char *id = xmpp_stanza_get_id(stanza); + char *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 { + char *type = NULL; + if (error_stanza != NULL) { + type = xmpp_stanza_get_attribute(error_stanza, STANZA_ATTR_TYPE); + } - // 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); - } + // stanza_get_error never returns NULL + char *err_msg = stanza_get_error_message(stanza); - // TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2] + GString *log_msg = g_string_new("presence 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); - // otherwise show defined-condition - } else { - xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error_stanza); + log_info(log_msg->str); - if (err_cond == NULL) { - 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; } |