From d37847e8590de9a0814943da9a013cad7aa26de5 Mon Sep 17 00:00:00 2001 From: defanor Date: Mon, 30 Nov 2020 23:18:34 +0300 Subject: Add "leave" and "gtell" console commands --- src/rexmpp_console.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/rexmpp_console.c b/src/rexmpp_console.c index 7dbaf61..85a6f8a 100644 --- a/src/rexmpp_console.c +++ b/src/rexmpp_console.c @@ -212,9 +212,11 @@ void rexmpp_console_feed (rexmpp_t *s, char *str, ssize_t str_len) { "help\n" "quit\n" "tell \n" + "gtell \n" "signcrypt \n" "publish-key \n" "join [as] \n" + "leave [as] \n" "roster list\n" "roster add \n" "roster delete \n" @@ -251,6 +253,19 @@ 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")) { jid_str = strtok_r(NULL, " ", &words_save_ptr); if (jid_str == NULL || rexmpp_jid_parse(jid_str, &jid)) { @@ -304,6 +319,30 @@ void rexmpp_console_feed (rexmpp_t *s, char *str, ssize_t str_len) { 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; + } + 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); } if (! strcmp(word, "roster")) { -- cgit v1.2.3