mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Tidied error handling for room forms
This commit is contained in:
parent
9d74bdb58d
commit
41a069278a
@ -470,9 +470,21 @@ handle_room_configure(const char * const room, DataForm *form)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_room_configuration_form_error(void)
|
handle_room_configuration_form_error(const char * const room, const char * const message)
|
||||||
{
|
{
|
||||||
cons_show("Error parsing room configuration form.");
|
if (room != NULL) {
|
||||||
|
if (message != NULL) {
|
||||||
|
cons_show_error("Room config error for %s: %s.", room, message);
|
||||||
|
} else {
|
||||||
|
cons_show_error("Room config error for %s.", room);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (message != NULL) {
|
||||||
|
cons_show_error("Room config error: %s.", message);
|
||||||
|
} else {
|
||||||
|
cons_show_error("Room config error.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -97,6 +97,6 @@ void handle_xmpp_stanza(const char * const msg);
|
|||||||
void handle_ping_result(const char * const from, int millis);
|
void handle_ping_result(const char * const from, int millis);
|
||||||
void handle_ping_error_result(const char * const from, const char * const error);
|
void handle_ping_error_result(const char * const from, const char * const error);
|
||||||
void handle_room_configure(const char * const room, DataForm *form);
|
void handle_room_configure(const char * const room, DataForm *form);
|
||||||
void handle_room_configuration_form_error(void);
|
void handle_room_configuration_form_error(const char * const from, const char * const message);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -594,8 +594,9 @@ static int
|
|||||||
_room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
_room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata)
|
void * const userdata)
|
||||||
{
|
{
|
||||||
// TODO handle errors
|
|
||||||
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
|
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
|
||||||
|
const char *type = xmpp_stanza_get_type(stanza);
|
||||||
|
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
|
|
||||||
if (id != NULL) {
|
if (id != NULL) {
|
||||||
log_debug("IQ room config handler fired, id: %s.", id);
|
log_debug("IQ room config handler fired, id: %s.", id);
|
||||||
@ -603,35 +604,43 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
log_debug("IQ room config handler fired.");
|
log_debug("IQ room config handler fired.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
// handle error responses
|
||||||
|
if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
||||||
|
char *error_message = stanza_get_error_message(stanza);
|
||||||
|
handle_room_configuration_form_error(from, error_message);
|
||||||
|
free(error_message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (from == NULL) {
|
if (from == NULL) {
|
||||||
log_error("No from attribute for IQ destroy room result");
|
log_error("No from attribute for IQ config request result");
|
||||||
} else {
|
handle_room_configuration_form_error(from, "No from attribute for room cofig response.");
|
||||||
// get form
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
||||||
if (query == NULL) {
|
if (query == NULL) {
|
||||||
log_error("No query element found parsing room config response");
|
log_error("No query element found parsing room config response");
|
||||||
handle_room_configuration_form_error();
|
handle_room_configuration_form_error(from, "No query element found parsing room config response");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA);
|
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA);
|
||||||
if (x == NULL) {
|
if (x == NULL) {
|
||||||
log_error("No x element found with %s namespace parsing room config response", STANZA_NS_DATA);
|
log_error("No x element found with %s namespace parsing room config response", STANZA_NS_DATA);
|
||||||
handle_room_configuration_form_error();
|
handle_room_configuration_form_error(from, "No form data element found parsing room config response");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *type = xmpp_stanza_get_attribute(x, STANZA_ATTR_TYPE);
|
char *form_type = xmpp_stanza_get_attribute(x, STANZA_ATTR_TYPE);
|
||||||
if (g_strcmp0(type, "form") != 0) {
|
if (g_strcmp0(form_type, "form") != 0) {
|
||||||
log_error("x element not of type 'form' parsing room config response");
|
log_error("x element not of type 'form' parsing room config response");
|
||||||
handle_room_configuration_form_error();
|
handle_room_configuration_form_error(from, "Form not of type 'form' parsing room config response.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataForm *form = form_create(x);
|
DataForm *form = form_create(x);
|
||||||
handle_room_configure(from, form);
|
handle_room_configure(from, form);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user