1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

First MAM test

Send a request (which we can't handle yet) :-)

Regards https://github.com/profanity-im/profanity/issues/660
This commit is contained in:
Michael Vetter 2020-04-08 16:22:36 +02:00
parent c8233a4a58
commit fe9b520c42
4 changed files with 105 additions and 0 deletions

View File

@ -2499,3 +2499,22 @@ _iq_free_affiliation_list(ProfAffiliationList *affiliation_list)
free(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;
}

View File

@ -2635,3 +2635,85 @@ stanza_attach_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *con
return stanza; 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;
}

View File

@ -202,6 +202,7 @@
#define STANZA_NS_USER_AVATAR_DATA "urn:xmpp:avatar:data" #define STANZA_NS_USER_AVATAR_DATA "urn:xmpp:avatar:data"
#define STANZA_NS_USER_AVATAR_METADATA "urn:xmpp:avatar:metadata" #define STANZA_NS_USER_AVATAR_METADATA "urn:xmpp:avatar:metadata"
#define STANZA_NS_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0" #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" #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_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 #endif

View File

@ -237,6 +237,7 @@ void iq_autoping_check(void);
void iq_http_upload_request(HTTPUpload *upload); void iq_http_upload_request(HTTPUpload *upload);
void iq_command_list(const char *const target); void iq_command_list(const char *const target);
void iq_command_exec(const char *const target, const char *const command); 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); EntityCapabilities* caps_lookup(const char *const jid);
void caps_close(void); void caps_close(void);