mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-23 09:56:21 +00:00
Handle recipient not found
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include "roster_list.h"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_MESSAGE, type, ctx)
|
||||
|
||||
@@ -50,6 +51,8 @@ static int _conference_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _captcha_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _message_error_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
|
||||
void
|
||||
message_add_handlers(void)
|
||||
@@ -57,7 +60,7 @@ message_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, _message_error_handler);
|
||||
HANDLE(NULL, STANZA_TYPE_GROUPCHAT, _groupchat_handler);
|
||||
HANDLE(NULL, STANZA_TYPE_CHAT, _chat_handler);
|
||||
HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler);
|
||||
@@ -186,6 +189,35 @@ _message_send_gone(const char * const recipient)
|
||||
chat_session_set_sent(recipient);
|
||||
}
|
||||
|
||||
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 *err_msg = stanza_get_error_message(stanza);
|
||||
char *id = xmpp_stanza_get_id(stanza);
|
||||
if (id != NULL) {
|
||||
log_info("Error recieved (id=%s): %s", id, err_msg);
|
||||
} else {
|
||||
log_info("Error received: %s", err_msg);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// handle recipient not found
|
||||
if ((from != NULL) && ((type != NULL && (strcmp(type, "cancel") == 0)))) {
|
||||
log_info("Recipient %s not found.", from);
|
||||
handle_recipient_not_found(from);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
_muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
|
||||
@@ -821,6 +821,71 @@ stanza_get_caps_str(xmpp_stanza_t * const stanza)
|
||||
return caps_str;
|
||||
}
|
||||
|
||||
char *
|
||||
stanza_get_error_message(xmpp_stanza_t *stanza)
|
||||
{
|
||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
|
||||
|
||||
// return nothing if no error stanza
|
||||
if (error_stanza == NULL) {
|
||||
return strdup("unknown");
|
||||
} else {
|
||||
xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT);
|
||||
|
||||
// check for text
|
||||
if (text_stanza != NULL) {
|
||||
gchar *err_msg = xmpp_stanza_get_text(text_stanza);
|
||||
if (err_msg != NULL) {
|
||||
char *result = strdup(err_msg);
|
||||
xmpp_free(ctx, err_msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
// otherwise check each defined-condition RFC-6120 8.3.3
|
||||
} else {
|
||||
xmpp_stanza_t *cond_stanza = NULL;
|
||||
|
||||
gchar *defined_conditions[] = {
|
||||
STANZA_NAME_BAD_REQUEST,
|
||||
STANZA_NAME_CONFLICT,
|
||||
STANZA_NAME_FEATURE_NOT_IMPLEMENTED,
|
||||
STANZA_NAME_FORBIDDEN,
|
||||
STANZA_NAME_GONE,
|
||||
STANZA_NAME_INTERNAL_SERVER_ERROR,
|
||||
STANZA_NAME_ITEM_NOT_FOUND,
|
||||
STANZA_NAME_JID_MALFORMED,
|
||||
STANZA_NAME_NOT_ACCEPTABLE,
|
||||
STANZA_NAME_NOT_ALLOWED,
|
||||
STANZA_NAME_NOT_AUTHORISED,
|
||||
STANZA_NAME_POLICY_VIOLATION,
|
||||
STANZA_NAME_RECIPIENT_UNAVAILABLE,
|
||||
STANZA_NAME_REDIRECT,
|
||||
STANZA_NAME_REGISTRATION_REQUIRED,
|
||||
STANZA_NAME_REMOTE_SERVER_NOT_FOUND,
|
||||
STANZA_NAME_REMOTE_SERVER_TIMEOUT,
|
||||
STANZA_NAME_RESOURCE_CONSTRAINT,
|
||||
STANZA_NAME_SERVICE_UNAVAILABLE,
|
||||
STANZA_NAME_SUBSCRIPTION_REQUIRED,
|
||||
STANZA_NAME_UNEXPECTED_REQUEST
|
||||
};
|
||||
|
||||
int i;
|
||||
for (i = 0; i < ARRAY_SIZE(defined_conditions); i++) {
|
||||
cond_stanza = xmpp_stanza_get_child_by_name(error_stanza, defined_conditions[i]);
|
||||
if (cond_stanza != NULL) {
|
||||
char *result = strdup(xmpp_stanza_get_name(cond_stanza));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// if undefined-condition or no condition, return nothing
|
||||
return strdup("unknown");
|
||||
}
|
||||
|
||||
DataForm *
|
||||
stanza_create_form(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
|
||||
@@ -56,6 +56,30 @@
|
||||
#define STANZA_NAME_STORAGE "storage"
|
||||
#define STANZA_NAME_CONFERENCE "conference"
|
||||
|
||||
// error conditions
|
||||
#define STANZA_NAME_BAD_REQUEST "bad-request"
|
||||
#define STANZA_NAME_CONFLICT "conflict"
|
||||
#define STANZA_NAME_FEATURE_NOT_IMPLEMENTED "feature-not-implemented"
|
||||
#define STANZA_NAME_FORBIDDEN "forbidden"
|
||||
#define STANZA_NAME_GONE "gone"
|
||||
#define STANZA_NAME_INTERNAL_SERVER_ERROR "internal-server-error"
|
||||
#define STANZA_NAME_ITEM_NOT_FOUND "item-not-found"
|
||||
#define STANZA_NAME_JID_MALFORMED "jid-malformed"
|
||||
#define STANZA_NAME_NOT_ACCEPTABLE "not-acceptable"
|
||||
#define STANZA_NAME_NOT_ALLOWED "not-allowed"
|
||||
#define STANZA_NAME_NOT_AUTHORISED "not-authorised"
|
||||
#define STANZA_NAME_POLICY_VIOLATION "policy-violation"
|
||||
#define STANZA_NAME_RECIPIENT_UNAVAILABLE "recipient-unavailable"
|
||||
#define STANZA_NAME_REDIRECT "redirect"
|
||||
#define STANZA_NAME_REGISTRATION_REQUIRED "registration-required"
|
||||
#define STANZA_NAME_REMOTE_SERVER_NOT_FOUND "remote-server-not-found"
|
||||
#define STANZA_NAME_REMOTE_SERVER_TIMEOUT "remote-server-timeout"
|
||||
#define STANZA_NAME_RESOURCE_CONSTRAINT "resource-constraint"
|
||||
#define STANZA_NAME_SERVICE_UNAVAILABLE "service-unavailable"
|
||||
#define STANZA_NAME_SUBSCRIPTION_REQUIRED "subscription-required"
|
||||
#define STANZA_NAME_UNDEFINED_CONDITION "undefined-condition"
|
||||
#define STANZA_NAME_UNEXPECTED_REQUEST "unexpected-request"
|
||||
|
||||
#define STANZA_TYPE_CHAT "chat"
|
||||
#define STANZA_TYPE_GROUPCHAT "groupchat"
|
||||
#define STANZA_TYPE_UNAVAILABLE "unavailable"
|
||||
@@ -190,4 +214,6 @@ xmpp_stanza_t * stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const id,
|
||||
xmpp_stanza_t * stanza_create_roster_remove_set(xmpp_ctx_t *ctx,
|
||||
const char * const barejid);
|
||||
|
||||
char * stanza_get_error_message(xmpp_stanza_t * const stanza);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user