handle error messages from server

This commit is contained in:
Dmitry Podgorny
2012-10-18 18:18:44 +03:00
parent 7156436805
commit bfc9e9a72e
5 changed files with 94 additions and 1 deletions

View File

@@ -42,6 +42,18 @@ static struct _jabber_conn_t {
int tls_disabled;
} jabber_conn;
typedef struct _err_code_tbl_t {
int code;
char *condition;
} err_code_tbl_t;
static err_code_tbl_t err_code_tbl[] = {
{404, "recipient-unavailable"},
{503, "service-unavailable"},
{0, NULL}, // termination line
};
static char *_get_xmpp_err_by_code(const char * const err_code);
static log_level_t _get_log_level(xmpp_log_level_t xmpp_level);
static xmpp_log_level_t _get_xmpp_log_level();
static void _xmpp_file_logger(void * const userdata,
@@ -275,8 +287,23 @@ _message_handler(xmpp_conn_t * const conn,
// message body recieved
char *type = xmpp_stanza_get_attribute(stanza, "type");
if(strcmp(type, "error") == 0)
if(strcmp(type, "error") == 0) {
// error message received
char *from = xmpp_stanza_get_attribute(stanza, "from");
char *err_msg = NULL;
xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, "error");
if (error) {
xmpp_stanza_t *err_cond = xmpp_stanza_get_children(error);
if (err_cond) {
err_msg = xmpp_stanza_get_name(err_cond);
} else {
char *err_code = xmpp_stanza_get_attribute(error, "code");
err_msg = _get_xmpp_err_by_code(err_code);
}
}
prof_handle_error_message(from, err_msg);
return 1;
}
char *message = xmpp_stanza_get_text(body);
char *from = xmpp_stanza_get_attribute(stanza, "from");
@@ -436,6 +463,25 @@ _presence_handler(xmpp_conn_t * const conn,
return 1;
}
static char *
_get_xmpp_err_by_code(const char * const err_code)
{
int code;
int i = 0;
if (err_code == NULL)
return NULL;
code = atoi(err_code);
while (err_code_tbl[i].code != 0) {
if (err_code_tbl[i].code == code) {
return err_code_tbl[i].condition;
}
}
return NULL;
}
static log_level_t
_get_log_level(xmpp_log_level_t xmpp_level)
{