From 194b0f1fef6c99ea6304f077b32170416d993448 Mon Sep 17 00:00:00 2001 From: Stefan Date: Sat, 29 Jul 2023 16:53:15 +0200 Subject: [PATCH] New Command: Delete OMEMO device list With new new comamnd delete-device-list (mode omemo), the PEP node eu.siacs.conversations.axolotl.devicelist will be delete. --- doc/xmppc.1 | 20 ++++++++++++---- doc/xmppc.1.adoc | 3 ++- src/main.c | 1 + src/mode/omemo.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/doc/xmppc.1 b/doc/xmppc.1 index 217e66d..14f172c 100644 --- a/doc/xmppc.1 +++ b/doc/xmppc.1 @@ -1,13 +1,13 @@ '\" t .\" Title: xmppc .\" Author: [see the "AUTHOR" section] -.\" Generator: DocBook XSL Stylesheets v1.79.1 -.\" Date: 05/16/2020 +.\" Generator: DocBook XSL Stylesheets vsnapshot +.\" Date: 07/29/2023 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "XMPPC" "1" "05/16/2020" "\ \&" "\ \&" +.TH "XMPPC" "1" "07/29/2023" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -149,6 +149,18 @@ OMEMO Mode (XEP\-0384) \fBlist\fR \- List the device IDs and fingerprints .RE +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} +\fBdelete\-device\-list\fR +\- Deletes the OMEMO device list +.RE .RE .PP \fB\-m openpgp\fR @@ -352,7 +364,7 @@ See https://codeberg\&.org/Anoxinon_e\&.V\&./xmppc/issues .sp -1 .IP \(bu 2.3 .\} -DebXWoody (OpenPGP: A602F76893F138B4A8EFDDD5C2DC916F35751C24) +DebXWoody .RE .SH "RESOURCES" .sp diff --git a/doc/xmppc.1.adoc b/doc/xmppc.1.adoc index 44ffebf..d2dfa04 100644 --- a/doc/xmppc.1.adoc +++ b/doc/xmppc.1.adoc @@ -71,6 +71,7 @@ PGP Mode (XEP-0027) OMEMO Mode (XEP-0384) * *list* - List the device IDs and fingerprints +* *delete-device-list* - Deletes the OMEMO device list *-m openpgp*:: openpgp mode (XEP-0373) @@ -146,7 +147,7 @@ See AUTHOR ------ -* DebXWoody (OpenPGP: A602F76893F138B4A8EFDDD5C2DC916F35751C24) +* DebXWoody RESOURCES --------- diff --git a/src/main.c b/src/main.c index 1cd7283..780e81c 100644 --- a/src/main.c +++ b/src/main.c @@ -560,6 +560,7 @@ static void _show_help() { printf("\n"); printf(" -m --mode omemo xmppc omemo mode (XEP-0384)\n"); printf(" list List the device IDs and fingerprints\n"); + printf(" delete-device-list Delete OMEMO device list\n"); printf("\n"); printf(" -m --mode openpgp xmppc openpgp mode (XEP-0373)\n"); printf(" signcrypt Sending pgp signed and encrypted message to jid\n"); diff --git a/src/mode/omemo.c b/src/mode/omemo.c index 646540f..c11d2c0 100644 --- a/src/mode/omemo.c +++ b/src/mode/omemo.c @@ -52,12 +52,24 @@ static void _omemo_device_list_query(xmppc_t *xmppc); static int _omemo_device_list_reply(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); +static void _omemo_delete_device_list_query(xmppc_t *xmppc); +static int _omemo_delete_device_list_reply(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, + void *const userdata); + static void _omemo_bundles_query(xmppc_t *xmppc, const char* deviceid); static int _omemo_bundles_reply(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); -void omemo_execute_command(xmppc_t *xmppc, int agrc, char *argv[]) { - _omemo_device_list_query(xmppc); +void omemo_execute_command(xmppc_t *xmppc, int argc, char *argv[]) { + if(argc > 0) { + if(strcmp("list", argv[0]) == 0) { + _omemo_device_list_query(xmppc); + } else if(strcmp("delete-device-list", argv[0]) == 0) { + _omemo_delete_device_list_query(xmppc); + } else { + logError(xmppc, "Unbekanner Befehl: %s\n", argv[0]); + } + } } void _omemo_device_list_query(xmppc_t *xmppc) { @@ -184,4 +196,49 @@ int _omemo_bundles_reply(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, return 0; } +/** + + + + + +**/ +static void _omemo_delete_device_list_query(xmppc_t *xmppc) { + xmpp_conn_t *conn = xmppc->conn; + xmpp_stanza_t *iq, *query, *item; + char* id = xmpp_uuid_gen(xmppc->ctx); + iq = xmpp_iq_new(xmpp_conn_get_context(conn), "set", id); + const char *jid = xmpp_conn_get_jid(conn); + xmpp_stanza_set_from(iq, jid); + xmpp_stanza_set_to(iq, jid); + query = xmpp_stanza_new(xmpp_conn_get_context(conn)); + xmpp_stanza_set_name(query, "pubsub"); + xmpp_stanza_set_ns(query, "http://jabber.org/protocol/pubsub#owner"); + xmpp_stanza_add_child(iq, query); + item = xmpp_stanza_new(xmpp_conn_get_context(conn)); + xmpp_stanza_set_name(item, "delete"); + xmpp_stanza_set_attribute(item, "node", + "eu.siacs.conversations.axolotl.devicelist"); + xmpp_stanza_add_child(query, item); + xmpp_stanza_release(query); + xmpp_stanza_release(item); + xmpp_id_handler_add(conn, _omemo_delete_device_list_reply , id, xmppc); + xmpp_send(conn, iq); +} +int _omemo_delete_device_list_reply(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, + void *const userdata) { + xmppc_t *xmppc = (xmppc_t *)userdata; + + if(strcmp(xmpp_stanza_get_type(stanza), "error") == 0) { + printf("Fehler\n"); + return 0; + } + printf("Done\n"); + xmpp_disconnect(xmppc->conn); + xmpp_stop(xmppc->ctx); + return 0; +}