about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMaximilian Wuttke <mwuttke97@posteo.de>2021-03-09 17:47:37 +0100
committerMaximilian Wuttke <mwuttke97@posteo.de>2021-03-09 17:47:37 +0100
commit412485610085fd4b521c9699a964eb6b39255c1c (patch)
tree26d12f2fac63af3b2009d33d18ac979bc1194981
parent848169870569dab48a1ef7b2751d0e4b52e87e09 (diff)
downloadprofani-tty-412485610085fd4b521c9699a964eb6b39255c1c.tar.gz
Variadic version of `stanza_attach_publish_options`
-rw-r--r--src/xmpp/stanza.c49
-rw-r--r--src/xmpp/stanza.h4
2 files changed, 37 insertions, 16 deletions
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 06615aa9..2b39a023 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -1940,8 +1940,9 @@ stanza_get_error_message(xmpp_stanza_t* stanza)
     return strdup("unknown");
 }
 
+// Note that the `count' must be 2 * number of key/value pairs
 void
-stanza_attach_publish_options(xmpp_ctx_t* const ctx, xmpp_stanza_t* const iq, const char* const option, const char* const value)
+stanza_attach_publish_options_va(xmpp_ctx_t* const ctx, xmpp_stanza_t* const iq, int count, ...)
 {
     xmpp_stanza_t* publish_options = xmpp_stanza_new(ctx);
     xmpp_stanza_set_name(publish_options, STANZA_NAME_PUBLISH_OPTIONS);
@@ -1964,23 +1965,34 @@ stanza_attach_publish_options(xmpp_ctx_t* const ctx, xmpp_stanza_t* const iq, co
     xmpp_stanza_add_child(form_type, form_type_value);
     xmpp_stanza_add_child(x, form_type);
 
-    xmpp_stanza_t* access_model = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(access_model, STANZA_NAME_FIELD);
-    xmpp_stanza_set_attribute(access_model, STANZA_ATTR_VAR, option);
-    xmpp_stanza_t* access_model_value = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_name(access_model_value, STANZA_NAME_VALUE);
-    xmpp_stanza_t* access_model_value_text = xmpp_stanza_new(ctx);
-    xmpp_stanza_set_text(access_model_value_text, value);
-    xmpp_stanza_add_child(access_model_value, access_model_value_text);
-    xmpp_stanza_add_child(access_model, access_model_value);
-    xmpp_stanza_add_child(x, access_model);
-
     xmpp_stanza_t* pubsub = xmpp_stanza_get_child_by_ns(iq, STANZA_NS_PUBSUB);
     xmpp_stanza_add_child(pubsub, publish_options);
 
-    xmpp_stanza_release(access_model_value_text);
-    xmpp_stanza_release(access_model_value);
-    xmpp_stanza_release(access_model);
+    va_list ap;
+    va_start(ap, count);
+    int j;
+    for (j = 0; j < count; j += 2) {
+        const char* const option = va_arg(ap, char* const);
+        const char* const value  = va_arg(ap, char* const);
+
+        xmpp_stanza_t* field = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_name(field, STANZA_NAME_FIELD);
+        xmpp_stanza_set_attribute(field, STANZA_ATTR_VAR, option);
+        xmpp_stanza_t* field_value = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_name(field_value, STANZA_NAME_VALUE);
+        xmpp_stanza_t* field_value_text = xmpp_stanza_new(ctx);
+        xmpp_stanza_set_text(field_value_text, value);
+        xmpp_stanza_add_child(field_value, field_value_text);
+        xmpp_stanza_add_child(field, field_value);
+        xmpp_stanza_add_child(x, field);
+
+        xmpp_stanza_release(field_value_text);
+        xmpp_stanza_release(field_value);
+        xmpp_stanza_release(field);
+    }
+    va_end(ap);
+
+
     xmpp_stanza_release(form_type_value_text);
     xmpp_stanza_release(form_type_value);
     xmpp_stanza_release(form_type);
@@ -1989,6 +2001,13 @@ stanza_attach_publish_options(xmpp_ctx_t* const ctx, xmpp_stanza_t* const iq, co
 }
 
 void
+stanza_attach_publish_options(xmpp_ctx_t* const ctx, xmpp_stanza_t* const iq, const char* const option, const char* const value)
+{
+    stanza_attach_publish_options_va(ctx, iq, 2, option, value);
+}
+
+
+void
 stanza_attach_priority(xmpp_ctx_t* const ctx, xmpp_stanza_t* const presence, const int pri)
 {
     if (pri == 0) {
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index e35b4bcc..a4ac6b33 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -326,7 +326,9 @@ xmpp_stanza_t* stanza_create_room_kick_iq(xmpp_ctx_t* const ctx, const char* con
 xmpp_stanza_t* stanza_create_command_exec_iq(xmpp_ctx_t* ctx, const char* const target, const char* const node);
 xmpp_stanza_t* stanza_create_command_config_submit_iq(xmpp_ctx_t* ctx, const char* const room, const char* const node, const char* const sessionid, DataForm* form);
 
-void stanza_attach_publish_options(xmpp_ctx_t* const ctx, xmpp_stanza_t* const publish, const char* const option, const char* const value);
+void stanza_attach_publish_options_va(xmpp_ctx_t* const ctx, xmpp_stanza_t* const iq, int count, ...);
+void stanza_attach_publish_options(xmpp_ctx_t* const ctx, xmpp_stanza_t* const iq, const char* const option, const char* const value);
+
 
 xmpp_stanza_t* stanza_create_omemo_devicelist_request(xmpp_ctx_t* ctx, const char* const id, const char* const jid);
 xmpp_stanza_t* stanza_create_omemo_devicelist_subscribe(xmpp_ctx_t* ctx, const char* const jid);