diff --git a/channel.cpp b/channel.cpp index 483d2a3..008d70c 100644 --- a/channel.cpp +++ b/channel.cpp @@ -329,7 +329,7 @@ struct t_channel *channel__new(struct t_account *account, new_channel->omemo.bundle_requests = weechat_hashtable_new(64, WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_POINTER, NULL, NULL); new_channel->pgp.enabled = 1; - new_channel->pgp.id = NULL; + new_channel->pgp.ids = new std::remove_pointerpgp.ids)>::type; new_channel->otr.enabled = 0; new_channel->topic.value = NULL; @@ -846,8 +846,11 @@ void channel__free(struct t_account *account, free(channel->id); if (channel->name) free(channel->name); - if (channel->pgp.id) - free(channel->pgp.id); + if (channel->pgp.ids) + { + delete channel->pgp.ids; + channel->pgp.ids = nullptr; + } if (channel->topic.value) free(channel->topic.value); if (channel->topic.creator) @@ -1164,14 +1167,14 @@ int channel__send_message(struct t_account *account, struct t_channel *channel, channel__set_transport(channel, CHANNEL_TRANSPORT_OMEMO, 0); } - else if (channel->pgp.enabled && channel->pgp.id) + else if (channel->pgp.enabled && channel->pgp.ids) { xmpp_stanza_t *message__x = xmpp_stanza_new(account->context); xmpp_stanza_set_name(message__x, "x"); xmpp_stanza_set_ns(message__x, "jabber:x:encrypted"); xmpp_stanza_t *message__x__text = xmpp_stanza_new(account->context); - char *ciphertext = pgp__encrypt(channel->buffer, account->pgp, account_pgp_keyid(account), channel->pgp.id, body); + char *ciphertext = pgp__encrypt(channel->buffer, account->pgp, account_pgp_keyid(account), std::vector(channel->pgp.ids->begin(), channel->pgp.ids->end()), body); if (ciphertext) xmpp_stanza_set_text(message__x__text, ciphertext); else @@ -1238,7 +1241,7 @@ int channel__send_message(struct t_account *account, struct t_channel *channel, const char *, int ret, const char *out, const char *err) { auto task = static_cast(pointer); if (!task) return WEECHAT_RC_ERROR; - + if (ret == 0) { const std::string_view prefix = "content-type: "; diff --git a/channel.hh b/channel.hh index 3819d24..a9b6799 100644 --- a/channel.hh +++ b/channel.hh @@ -5,6 +5,8 @@ #pragma once #include +#include +#include #define CHANNEL_MEMBERS_SPEAKING_LIMIT 128 @@ -73,7 +75,7 @@ struct t_channel } omemo; struct { int enabled; - char *id; + std::unordered_set *ids; } pgp; struct { int enabled; diff --git a/command.cpp b/command.cpp index e8e769d..34392fa 100644 --- a/command.cpp +++ b/command.cpp @@ -833,7 +833,7 @@ int command__pgp(const void *pointer, void *data, { keyid = argv_eol[1]; - ptr_channel->pgp.id = strdup(keyid); + ptr_channel->pgp.ids->emplace(keyid); } ptr_channel->omemo.enabled = 0; ptr_channel->pgp.enabled = 1; diff --git a/connection.cpp b/connection.cpp index 686dc78..7b99cd8 100644 --- a/connection.cpp +++ b/connection.cpp @@ -220,7 +220,7 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void { user->profile.pgp_id = pgp__verify(channel->buffer, account->pgp, signature->data()); if (channel->type != CHANNEL_TYPE_MUC) - channel->pgp.id = user->profile.pgp_id; + channel->pgp.ids->emplace(user->profile.pgp_id); } if (weechat_strcasecmp(role.data(), "none") == 0) @@ -253,7 +253,7 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void { user->profile.pgp_id = pgp__verify(channel->buffer, account->pgp, signature->data()); if (channel->type != CHANNEL_TYPE_MUC) - channel->pgp.id = user->profile.pgp_id; + channel->pgp.ids->emplace(user->profile.pgp_id); } if (user->profile.role) diff --git a/pgp.cpp b/pgp.cpp index 4c2ca98..c55e383 100644 --- a/pgp.cpp +++ b/pgp.cpp @@ -76,7 +76,7 @@ void pgp__free(struct t_pgp *pgp) } } -char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, const char *target, const char *message) +char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, std::vector&& targets, const char *message) { std::string encrypted; gpgme_key_t keys[3] = {NULL,NULL,NULL}; @@ -99,9 +99,12 @@ char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *s } /* Encrypt data. */ - err = gpgme_get_key(pgp->gpgme, target, &keys[0], false); - if (err) { - goto encrypt_finish; + for (const std::string& target : targets) + { + err = gpgme_get_key(pgp->gpgme, target.data(), &keys[0], false); + if (err) { + goto encrypt_finish; + } } err = gpgme_get_key(pgp->gpgme, source, &keys[1], false); if (err) { diff --git a/pgp.hh b/pgp.hh index 7b4faff..fbcb276 100644 --- a/pgp.hh +++ b/pgp.hh @@ -5,6 +5,7 @@ #pragma once #include +#include extern const char *PGP_ADVICE; @@ -20,7 +21,7 @@ void pgp__free(struct t_pgp *pgp); char *pgp__decrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *ciphertext); -char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, const char *target, const char *message); +char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, std::vector&& target, const char *message); char *pgp__verify(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *certificate);