mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-19 22:36:22 +00:00
Implemented /room config submit for saving room configuration
This commit is contained in:
@@ -236,6 +236,86 @@ form_create(xmpp_stanza_t * const form_stanza)
|
||||
return form;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *
|
||||
form_create_submission(DataForm *form)
|
||||
{
|
||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||
|
||||
xmpp_stanza_t *x = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(x, STANZA_NAME_X);
|
||||
xmpp_stanza_set_ns(x, STANZA_NS_DATA);
|
||||
xmpp_stanza_set_type(x, "submit");
|
||||
|
||||
GSList *curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField *field = curr_field->data;
|
||||
|
||||
xmpp_stanza_t *field_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(field_stanza, "field");
|
||||
xmpp_stanza_set_attribute(field_stanza, "var", field->var);
|
||||
|
||||
xmpp_stanza_t *value_stanza = NULL;
|
||||
GSList *curr_value = NULL;
|
||||
|
||||
switch (field->type_t) {
|
||||
|
||||
case FIELD_HIDDEN:
|
||||
case FIELD_TEXT_SINGLE:
|
||||
case FIELD_TEXT_PRIVATE:
|
||||
case FIELD_BOOLEAN:
|
||||
case FIELD_LIST_SINGLE:
|
||||
case FIELD_JID_SINGLE:
|
||||
case FIELD_FIXED:
|
||||
value_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(value_stanza, "value");
|
||||
if (field->values != NULL) {
|
||||
if (field->values->data != NULL) {
|
||||
xmpp_stanza_t *text_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(text_stanza, field->values->data);
|
||||
xmpp_stanza_add_child(value_stanza, text_stanza);
|
||||
xmpp_stanza_release(text_stanza);
|
||||
}
|
||||
}
|
||||
xmpp_stanza_add_child(field_stanza, value_stanza);
|
||||
xmpp_stanza_release(value_stanza);
|
||||
|
||||
break;
|
||||
|
||||
case FIELD_TEXT_MULTI:
|
||||
case FIELD_LIST_MUTLI:
|
||||
case FIELD_JID_MULTI:
|
||||
curr_value = field->values;
|
||||
while (curr_value != NULL) {
|
||||
char *value = curr_value->data;
|
||||
|
||||
value_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(value_stanza, "value");
|
||||
if (value != NULL) {
|
||||
xmpp_stanza_t *text_stanza = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_text(text_stanza, value);
|
||||
xmpp_stanza_add_child(value_stanza, text_stanza);
|
||||
xmpp_stanza_release(text_stanza);
|
||||
}
|
||||
|
||||
xmpp_stanza_add_child(field_stanza, value_stanza);
|
||||
xmpp_stanza_release(value_stanza);
|
||||
|
||||
curr_value = g_slist_next(curr_value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
xmpp_stanza_add_child(x, field_stanza);
|
||||
xmpp_stanza_release(field_stanza);
|
||||
|
||||
curr_field = g_slist_next(curr_field);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static void
|
||||
_free_option(FormOption *option)
|
||||
{
|
||||
|
||||
@@ -36,5 +36,6 @@
|
||||
#define FROM_H
|
||||
|
||||
DataForm* form_create(xmpp_stanza_t * const stanza);
|
||||
xmpp_stanza_t* form_create_submission(DataForm *form);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -78,6 +78,8 @@ static int _destroy_room_result_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _room_config_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _room_config_submit_handler(xmpp_conn_t * const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _manual_pong_handler(xmpp_conn_t *const conn,
|
||||
xmpp_stanza_t * const stanza, void * const userdata);
|
||||
static int _ping_timed_handler(xmpp_conn_t * const conn,
|
||||
@@ -203,6 +205,20 @@ _iq_request_room_config_form(const char * const room_jid)
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
static void
|
||||
_iq_submit_room_config(const char * const room, DataForm *form)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_room_config_submit_iq(ctx, room, form);
|
||||
|
||||
char *id = xmpp_stanza_get_id(iq);
|
||||
xmpp_id_handler_add(conn, _room_config_submit_handler, id, NULL);
|
||||
|
||||
xmpp_send(conn, iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
static void
|
||||
_iq_room_config_cancel(const char * const room_jid)
|
||||
{
|
||||
@@ -645,6 +661,23 @@ _room_config_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_room_config_submit_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
void * const userdata)
|
||||
{
|
||||
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
|
||||
|
||||
if (id != NULL) {
|
||||
log_debug("IQ room config handler fired, id: %s.", id);
|
||||
} else {
|
||||
log_debug("IQ room config handler fired.");
|
||||
}
|
||||
|
||||
handle_room_config_submit_result();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_identity_destroy(DiscoIdentity *identity)
|
||||
{
|
||||
@@ -897,4 +930,5 @@ iq_init_module(void)
|
||||
iq_send_ping = _iq_send_ping;
|
||||
iq_request_room_config_form = _iq_request_room_config_form;
|
||||
iq_room_config_cancel = _iq_room_config_cancel;
|
||||
iq_submit_room_config = _iq_submit_room_config;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "xmpp/connection.h"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/capabilities.h"
|
||||
#include "xmpp/form.h"
|
||||
|
||||
#include "muc.h"
|
||||
|
||||
@@ -616,6 +617,31 @@ stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char * const id,
|
||||
return iq;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *
|
||||
stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx, const char * const room, DataForm *form)
|
||||
{
|
||||
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
|
||||
xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
|
||||
xmpp_stanza_set_attribute(iq, STANZA_ATTR_TO, room);
|
||||
char *id = create_unique_id("roomconf_submit");
|
||||
xmpp_stanza_set_id(iq, id);
|
||||
free(id);
|
||||
|
||||
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
|
||||
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
|
||||
xmpp_stanza_set_ns(query, STANZA_NS_MUC_OWNER);
|
||||
|
||||
xmpp_stanza_t *x = form_create_submission(form);
|
||||
xmpp_stanza_add_child(query, x);
|
||||
xmpp_stanza_release(x);
|
||||
|
||||
xmpp_stanza_add_child(iq, query);
|
||||
xmpp_stanza_release(query);
|
||||
|
||||
return iq;
|
||||
}
|
||||
|
||||
gboolean
|
||||
stanza_contains_chat_state(xmpp_stanza_t *stanza)
|
||||
{
|
||||
|
||||
@@ -202,6 +202,8 @@ xmpp_stanza_t* stanza_create_room_config_request_iq(xmpp_ctx_t *ctx,
|
||||
const char * const room_jid);
|
||||
xmpp_stanza_t* stanza_create_room_config_cancel_iq(xmpp_ctx_t *ctx,
|
||||
const char * const room_jid);
|
||||
xmpp_stanza_t* stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx,
|
||||
const char * const room, DataForm *form);
|
||||
|
||||
int stanza_get_idle_time(xmpp_stanza_t * const stanza);
|
||||
char * stanza_get_caps_str(xmpp_stanza_t * const stanza);
|
||||
|
||||
@@ -180,6 +180,7 @@ void (*iq_set_autoping)(int seconds);
|
||||
void (*iq_confirm_instant_room)(const char * const room_jid);
|
||||
void (*iq_destroy_instant_room)(const char * const room_jid);
|
||||
void (*iq_request_room_config_form)(const char * const room_jid);
|
||||
void (*iq_submit_room_config)(const char * const room, DataForm *form);
|
||||
void (*iq_room_config_cancel)(const char * const room_jid);
|
||||
void (*iq_send_ping)(const char * const target);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user