From 3b5806a16e4fd0a6f292050508790fc0c3f6b36f Mon Sep 17 00:00:00 2001 From: defanor Date: Thu, 11 Feb 2021 20:28:08 +0300 Subject: Group MUC and key management console commands --- src/rexmpp_console.c | 136 ++++++++++++++++++++++++++------------------------- 1 file changed, 70 insertions(+), 66 deletions(-) diff --git a/src/rexmpp_console.c b/src/rexmpp_console.c index 1211129..1e3106b 100644 --- a/src/rexmpp_console.c +++ b/src/rexmpp_console.c @@ -227,14 +227,14 @@ void rexmpp_console_feed (rexmpp_t *s, char *str, ssize_t str_len) { "help\n" "quit\n" "tell \n" - "gtell \n" "signcrypt \n" "sign \n" "crypt \n" - "publish-key \n" - "retract-key \n" - "join [as] \n" - "leave [as] \n" + "key publish \n" + "key retract \n" + "muc join [as] \n" + "muc leave [as] \n" + "muc tell \n" "roster list\n" "roster add \n" "roster delete \n" @@ -253,13 +253,16 @@ void rexmpp_console_feed (rexmpp_t *s, char *str, ssize_t str_len) { return; } - if (! strcmp(word, "publish-key")) { - char *fingerprint = strtok_r(NULL, " ", &words_save_ptr); - rexmpp_openpgp_publish_key(s, fingerprint); - } - if (! strcmp(word, "retract-key")) { - char *fingerprint = strtok_r(NULL, " ", &words_save_ptr); - rexmpp_openpgp_retract_key(s, fingerprint); + if (! strcmp(word, "key")) { + word = strtok_r(NULL, " ", &words_save_ptr); + if (! strcmp(word, "publish")) { + char *fingerprint = strtok_r(NULL, " ", &words_save_ptr); + rexmpp_openpgp_publish_key(s, fingerprint); + } + if (! strcmp(word, "retract")) { + char *fingerprint = strtok_r(NULL, " ", &words_save_ptr); + rexmpp_openpgp_retract_key(s, fingerprint); + } } if (! strcmp(word, "tell")) { @@ -275,19 +278,6 @@ void rexmpp_console_feed (rexmpp_t *s, char *str, ssize_t str_len) { rexmpp_send(s, msg); } - if (! strcmp(word, "gtell")) { - jid_str = strtok_r(NULL, " ", &words_save_ptr); - if (jid_str == NULL || rexmpp_jid_parse(jid_str, &jid)) { - return; - } - msg_text = jid_str + strlen(jid_str) + 1; - xmlNodePtr msg = rexmpp_xml_add_id(s, xmlNewNode(NULL, "message")); - xmlNewProp(msg, "to", jid.full); - xmlNewProp(msg, "type", "groupchat"); - xmlNewTextChild(msg, NULL, "body", msg_text); - rexmpp_send(s, msg); - } - if ((strcmp(word, "signcrypt") == 0) || (strcmp(word, "sign") == 0) || (strcmp(word, "crypt") == 0)) { @@ -328,52 +318,66 @@ void rexmpp_console_feed (rexmpp_t *s, char *str, ssize_t str_len) { rexmpp_send(s, msg); } - if (! strcmp(word, "join")) { - jid_str = strtok_r(NULL, " ", &words_save_ptr); - if (jid_str == NULL || rexmpp_jid_parse(jid_str, &jid)) { - return; - } + if (! strcmp(word, "muc")) { word = strtok_r(NULL, " ", &words_save_ptr); - if (! strcmp(word, "as")) { - word = strtok_r(NULL, " ", &words_save_ptr); - } - if (word == NULL) { - return; - } - char *full_jid = malloc(strlen(jid.bare) + strlen(word) + 2); - snprintf(full_jid, strlen(jid_str) + strlen(word) + 2, "%s/%s", - jid.bare, word); - presence = rexmpp_xml_add_id(s, xmlNewNode(NULL, "presence")); - xmlNewProp(presence, "from", s->assigned_jid.full); - xmlNewProp(presence, "to", full_jid); - xmlNodePtr x = xmlNewNode(NULL, "x"); - xmlNewNs(x, "http://jabber.org/protocol/muc", NULL); - xmlAddChild(presence, x); - rexmpp_send(s, presence); - free(full_jid); - } - - if (! strcmp(word, "leave")) { - jid_str = strtok_r(NULL, " ", &words_save_ptr); - if (jid_str == NULL || rexmpp_jid_parse(jid_str, &jid)) { - return; + if (! strcmp(word, "tell")) { + jid_str = strtok_r(NULL, " ", &words_save_ptr); + if (jid_str == NULL || rexmpp_jid_parse(jid_str, &jid)) { + return; + } + msg_text = jid_str + strlen(jid_str) + 1; + xmlNodePtr msg = rexmpp_xml_add_id(s, xmlNewNode(NULL, "message")); + xmlNewProp(msg, "to", jid.full); + xmlNewProp(msg, "type", "groupchat"); + xmlNewTextChild(msg, NULL, "body", msg_text); + rexmpp_send(s, msg); } - word = strtok_r(NULL, " ", &words_save_ptr); - if (! strcmp(word, "as")) { + if (! strcmp(word, "join")) { + jid_str = strtok_r(NULL, " ", &words_save_ptr); + if (jid_str == NULL || rexmpp_jid_parse(jid_str, &jid)) { + return; + } word = strtok_r(NULL, " ", &words_save_ptr); + if (! strcmp(word, "as")) { + word = strtok_r(NULL, " ", &words_save_ptr); + } + if (word == NULL) { + return; + } + char *full_jid = malloc(strlen(jid.bare) + strlen(word) + 2); + snprintf(full_jid, strlen(jid_str) + strlen(word) + 2, "%s/%s", + jid.bare, word); + presence = rexmpp_xml_add_id(s, xmlNewNode(NULL, "presence")); + xmlNewProp(presence, "from", s->assigned_jid.full); + xmlNewProp(presence, "to", full_jid); + xmlNodePtr x = xmlNewNode(NULL, "x"); + xmlNewNs(x, "http://jabber.org/protocol/muc", NULL); + xmlAddChild(presence, x); + rexmpp_send(s, presence); + free(full_jid); } - if (word == NULL) { - return; + if (! strcmp(word, "leave")) { + jid_str = strtok_r(NULL, " ", &words_save_ptr); + if (jid_str == NULL || rexmpp_jid_parse(jid_str, &jid)) { + return; + } + word = strtok_r(NULL, " ", &words_save_ptr); + if (! strcmp(word, "as")) { + word = strtok_r(NULL, " ", &words_save_ptr); + } + if (word == NULL) { + return; + } + char *full_jid = malloc(strlen(jid.bare) + strlen(word) + 2); + snprintf(full_jid, strlen(jid_str) + strlen(word) + 2, "%s/%s", + jid.bare, word); + presence = rexmpp_xml_add_id(s, xmlNewNode(NULL, "presence")); + xmlNewProp(presence, "from", s->assigned_jid.full); + xmlNewProp(presence, "to", full_jid); + xmlNewProp(presence, "type", "unavailable"); + rexmpp_send(s, presence); + free(full_jid); } - char *full_jid = malloc(strlen(jid.bare) + strlen(word) + 2); - snprintf(full_jid, strlen(jid_str) + strlen(word) + 2, "%s/%s", - jid.bare, word); - presence = rexmpp_xml_add_id(s, xmlNewNode(NULL, "presence")); - xmlNewProp(presence, "from", s->assigned_jid.full); - xmlNewProp(presence, "to", full_jid); - xmlNewProp(presence, "type", "unavailable"); - rexmpp_send(s, presence); - free(full_jid); } if (! strcmp(word, "roster")) { -- cgit v1.2.3