about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/iq.c19
-rw-r--r--src/xmpp/stanza.c82
-rw-r--r--src/xmpp/stanza.h3
-rw-r--r--src/xmpp/xmpp.h1
4 files changed, 105 insertions, 0 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 07a68bce..b36ca229 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -2499,3 +2499,22 @@ _iq_free_affiliation_list(ProfAffiliationList *affiliation_list)
         free(affiliation_list);
     }
 }
+
+void
+iq_mam_request(ProfChatWin *win)
+{
+   //TODDO: check for mam feature
+   //if (connection_supports(XMPP_FEATURE_PING) == FALSE) {
+
+    xmpp_ctx_t * const ctx = connection_get_ctx();
+    char *id = connection_create_stanza_id();
+    xmpp_stanza_t *iq = stanza_create_mam_iq(ctx, win->barejid, "2020-01-06T00:00:00Z");
+
+//    iq_id_handler_add(id, _http_upload_response_id_handler, NULL, upload);
+    free(id);
+
+    iq_send_stanza(iq);
+    xmpp_stanza_release(iq);
+
+    return;
+}
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 56185843..a247cfc4 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -2635,3 +2635,85 @@ stanza_attach_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *con
 
     return stanza;
 }
+
+xmpp_stanza_t*
+stanza_create_mam_iq(xmpp_ctx_t *ctx, const char *const jid, const char *const startdate)
+{
+    char *id = connection_create_stanza_id();
+    xmpp_stanza_t *iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id);
+    free(id);
+    //xmpp_stanza_set_to(iq, jid);
+
+    xmpp_stanza_t *query = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
+    xmpp_stanza_set_ns(query, STANZA_NS_MAM2);
+
+    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");
+
+    // field FORM_TYPE MAM2
+    xmpp_stanza_t *field_form_type = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(field_form_type, STANZA_NAME_FIELD);
+    xmpp_stanza_set_attribute(field_form_type, STANZA_ATTR_VAR, "FORM_TYPE");
+    xmpp_stanza_set_type(field_form_type, "hidden");
+
+    xmpp_stanza_t *value_mam = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(value_mam, STANZA_NAME_VALUE);
+
+    xmpp_stanza_t *mam_text = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_text(mam_text, STANZA_NS_MAM2);
+    xmpp_stanza_add_child(value_mam, mam_text);
+
+    xmpp_stanza_add_child(field_form_type, value_mam);
+
+    // field 'with'
+    xmpp_stanza_t *field_with = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(field_with, STANZA_NAME_FIELD);
+    xmpp_stanza_set_attribute(field_with, STANZA_ATTR_VAR, "with");
+
+    xmpp_stanza_t *value_with = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(value_with, STANZA_NAME_VALUE);
+
+    xmpp_stanza_t *with_text = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_text(with_text, jid);
+    xmpp_stanza_add_child(value_with, with_text);
+
+    xmpp_stanza_add_child(field_with, value_with);
+
+    // field 'start'
+    xmpp_stanza_t *field_start = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(field_start, STANZA_NAME_FIELD);
+    xmpp_stanza_set_attribute(field_start, STANZA_ATTR_VAR, "start");
+
+    xmpp_stanza_t *value_start = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_name(value_start, STANZA_NAME_VALUE);
+
+    xmpp_stanza_t *date_text = xmpp_stanza_new(ctx);
+    xmpp_stanza_set_text(date_text, startdate);
+    xmpp_stanza_add_child(value_start, date_text);
+
+    xmpp_stanza_add_child(field_start, value_start);
+
+    // add and release
+    xmpp_stanza_add_child(iq, query);
+    xmpp_stanza_add_child(query, x);
+    xmpp_stanza_add_child(x, field_form_type);
+    xmpp_stanza_add_child(x, field_with);
+    xmpp_stanza_add_child(x, field_start);
+
+    xmpp_stanza_release(mam_text);
+    xmpp_stanza_release(with_text);
+    xmpp_stanza_release(date_text);
+    xmpp_stanza_release(value_mam);
+    xmpp_stanza_release(value_with);
+    xmpp_stanza_release(value_start);
+    xmpp_stanza_release(field_form_type);
+    xmpp_stanza_release(field_with);
+    xmpp_stanza_release(field_start);
+    xmpp_stanza_release(x);
+    xmpp_stanza_release(query);
+
+    return iq;
+}
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index ee5c6772..80bebba5 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -202,6 +202,7 @@
 #define STANZA_NS_USER_AVATAR_DATA "urn:xmpp:avatar:data"
 #define STANZA_NS_USER_AVATAR_METADATA "urn:xmpp:avatar:metadata"
 #define STANZA_NS_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0"
+#define STANZA_NS_MAM2 "urn:xmpp:mam:2"
 
 #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
 
@@ -359,4 +360,6 @@ xmpp_stanza_t* stanza_get_child_by_name_and_ns(xmpp_stanza_t * const stanza, con
 
 xmpp_stanza_t* stanza_create_avatar_retrieve_data_request(xmpp_ctx_t *ctx, const char *stanza_id, const char *const item_id, const char *const jid);
 
+xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t *ctx, const char *const jid, const char *const startdate);
+
 #endif
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 4dff46cc..7544189b 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -237,6 +237,7 @@ void iq_autoping_check(void);
 void iq_http_upload_request(HTTPUpload *upload);
 void iq_command_list(const char *const target);
 void iq_command_exec(const char *const target, const char *const command);
+void iq_mam_request(ProfChatWin *win);
 
 EntityCapabilities* caps_lookup(const char *const jid);
 void caps_close(void);