2013-01-28 19:21:04 -05:00
|
|
|
/*
|
2013-02-02 14:47:41 -05:00
|
|
|
* message.c
|
2019-11-13 06:11:05 -05:00
|
|
|
* vim: expandtab:ts=4:sts=4:sw=4
|
2013-01-28 19:21:04 -05:00
|
|
|
*
|
2019-01-22 05:31:45 -05:00
|
|
|
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
2022-05-09 09:43:33 -04:00
|
|
|
* Copyright (C) 2019 - 2022 Michael Vetter <jubalh@iodoru.org>
|
2013-01-28 19:21:04 -05:00
|
|
|
*
|
|
|
|
* This file is part of Profanity.
|
|
|
|
*
|
|
|
|
* Profanity is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Profanity is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-07-23 20:14:49 -04:00
|
|
|
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
2013-01-28 19:21:04 -05:00
|
|
|
*
|
2014-08-24 15:57:39 -04:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link the code of portions of this program with the OpenSSL library under
|
|
|
|
* certain conditions as described in each individual source file, and
|
|
|
|
* distribute linked combinations including the two.
|
|
|
|
*
|
|
|
|
* You must obey the GNU General Public License in all respects for all of the
|
|
|
|
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
|
|
|
* may extend this exception to your version of the file(s), but you are not
|
|
|
|
* obligated to do so. If you do not wish to do so, delete this exception
|
|
|
|
* statement from your version. If you delete this exception statement from all
|
|
|
|
* source files in the program, then also delete it here.
|
|
|
|
*
|
2013-01-28 19:21:04 -05:00
|
|
|
*/
|
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#include "config.h"
|
2015-09-21 16:40:04 -04:00
|
|
|
|
2013-01-28 19:37:50 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-01-28 19:21:04 -05:00
|
|
|
#include <strophe.h>
|
|
|
|
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "profanity.h"
|
|
|
|
#include "log.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "config/preferences.h"
|
2015-04-19 11:54:16 -04:00
|
|
|
#include "event/server_events.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "pgp/gpg.h"
|
2022-06-29 02:58:38 -04:00
|
|
|
#include "pgp/ox.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "plugins/plugins.h"
|
|
|
|
#include "ui/ui.h"
|
2019-02-26 13:53:06 -05:00
|
|
|
#include "ui/window_list.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "xmpp/chat_session.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "xmpp/muc.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "xmpp/session.h"
|
|
|
|
#include "xmpp/message.h"
|
2013-05-19 18:35:02 -04:00
|
|
|
#include "xmpp/roster.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "xmpp/roster_list.h"
|
2013-02-02 15:55:58 -05:00
|
|
|
#include "xmpp/stanza.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "xmpp/connection.h"
|
2013-02-02 15:55:58 -05:00
|
|
|
#include "xmpp/xmpp.h"
|
2021-03-17 11:16:59 -04:00
|
|
|
#include "xmpp/form.h"
|
2022-05-25 15:49:45 -04:00
|
|
|
#include "xmpp/iq.h"
|
2013-01-28 19:21:04 -05:00
|
|
|
|
2019-02-26 13:53:06 -05:00
|
|
|
#ifdef HAVE_OMEMO
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "xmpp/omemo.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "omemo/omemo.h"
|
2019-02-26 13:53:06 -05:00
|
|
|
#endif
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
typedef struct p_message_handle_t
|
|
|
|
{
|
2019-02-22 05:16:42 -05:00
|
|
|
ProfMessageCallback func;
|
|
|
|
ProfMessageFreeCallback free_func;
|
2020-07-07 08:18:57 -04:00
|
|
|
void* userdata;
|
2019-02-22 05:16:42 -05:00
|
|
|
} ProfMessageHandler;
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
static int _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata);
|
|
|
|
static void _handle_error(xmpp_stanza_t* const stanza);
|
|
|
|
static void _handle_groupchat(xmpp_stanza_t* const stanza);
|
|
|
|
static void _handle_muc_user(xmpp_stanza_t* const stanza);
|
|
|
|
static void _handle_muc_private_message(xmpp_stanza_t* const stanza);
|
|
|
|
static void _handle_conference(xmpp_stanza_t* const stanza);
|
|
|
|
static void _handle_captcha(xmpp_stanza_t* const stanza);
|
|
|
|
static void _handle_receipt_received(xmpp_stanza_t* const stanza);
|
2021-07-01 12:08:40 -04:00
|
|
|
static void _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, const char* result_id, GDateTime* timestamp);
|
2020-07-07 08:18:57 -04:00
|
|
|
static void _handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_mam);
|
|
|
|
static xmpp_stanza_t* _handle_carbons(xmpp_stanza_t* const stanza);
|
|
|
|
static void _send_message_stanza(xmpp_stanza_t* const stanza);
|
|
|
|
static gboolean _handle_mam(xmpp_stanza_t* const stanza);
|
|
|
|
static void _handle_pubsub(xmpp_stanza_t* const stanza, xmpp_stanza_t* const event);
|
2021-03-17 11:16:59 -04:00
|
|
|
static gboolean _handle_form(xmpp_stanza_t* const stanza);
|
2021-06-09 14:14:57 -04:00
|
|
|
static gboolean _handle_jingle_message(xmpp_stanza_t* const stanza);
|
2021-07-01 12:02:03 -04:00
|
|
|
static gboolean _should_ignore_based_on_silence(xmpp_stanza_t* const stanza);
|
2016-03-27 20:25:48 -04:00
|
|
|
|
2020-06-30 05:10:27 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2022-05-04 08:26:26 -04:00
|
|
|
static xmpp_stanza_t* _ox_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const text);
|
2020-06-30 05:10:27 -04:00
|
|
|
#endif // HAVE_LIBGPGME
|
2020-06-21 03:43:42 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
static GHashTable* pubsub_event_handlers;
|
2019-02-22 05:16:42 -05:00
|
|
|
|
2020-07-02 11:53:28 -04:00
|
|
|
static gboolean
|
2020-07-07 08:18:57 -04:00
|
|
|
_handled_by_plugin(xmpp_stanza_t* const stanza)
|
2016-03-27 20:25:48 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* text;
|
2016-03-27 20:25:48 -04:00
|
|
|
size_t text_size;
|
2020-07-02 11:53:28 -04:00
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
xmpp_stanza_to_text(stanza, &text, &text_size);
|
|
|
|
gboolean cont = plugins_on_message_stanza_receive(text);
|
2020-07-02 11:53:28 -04:00
|
|
|
xmpp_free(connection_get_ctx(), text);
|
|
|
|
|
|
|
|
return !cont;
|
|
|
|
}
|
|
|
|
|
2020-07-03 06:02:41 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_headline(xmpp_stanza_t* const stanza)
|
2020-07-03 06:02:41 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
2020-07-03 06:02:41 -04:00
|
|
|
if (body) {
|
2021-07-01 12:08:40 -04:00
|
|
|
char* text = xmpp_stanza_get_text(body);
|
2020-07-03 06:02:41 -04:00
|
|
|
if (text) {
|
|
|
|
cons_show("Headline: %s", text);
|
2021-03-25 10:43:57 -04:00
|
|
|
xmpp_free(connection_get_ctx(), text);
|
2020-07-03 06:02:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 10:17:18 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_chat_states(xmpp_stanza_t* const stanza, Jid* const jid)
|
2020-07-03 10:17:18 -04:00
|
|
|
{
|
|
|
|
gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL;
|
|
|
|
gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL;
|
|
|
|
gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL;
|
|
|
|
gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL;
|
|
|
|
if (gone) {
|
|
|
|
sv_ev_gone(jid->barejid, jid->resourcepart);
|
|
|
|
} else if (typing) {
|
|
|
|
sv_ev_typing(jid->barejid, jid->resourcepart);
|
|
|
|
} else if (paused) {
|
|
|
|
sv_ev_paused(jid->barejid, jid->resourcepart);
|
|
|
|
} else if (inactive) {
|
|
|
|
sv_ev_inactive(jid->barejid, jid->resourcepart);
|
|
|
|
} else if (stanza_contains_chat_state(stanza)) {
|
|
|
|
sv_ev_activity(jid->barejid, jid->resourcepart, TRUE);
|
|
|
|
} else {
|
|
|
|
sv_ev_activity(jid->barejid, jid->resourcepart, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 11:53:28 -04:00
|
|
|
static int
|
2020-07-07 08:18:57 -04:00
|
|
|
_message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata)
|
2020-07-02 11:53:28 -04:00
|
|
|
{
|
|
|
|
log_debug("Message stanza handler fired");
|
|
|
|
|
|
|
|
if (_handled_by_plugin(stanza)) {
|
2016-03-27 20:25:48 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-07-02 11:15:42 -04:00
|
|
|
// type according to RFC 6121
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* type = xmpp_stanza_get_type(stanza);
|
2016-03-27 20:25:48 -04:00
|
|
|
|
2021-03-25 06:34:14 -04:00
|
|
|
if (type && g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
|
2016-03-27 20:25:48 -04:00
|
|
|
_handle_error(stanza);
|
2021-03-25 06:34:14 -04:00
|
|
|
} else if (type && g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0) {
|
2020-07-02 11:15:42 -04:00
|
|
|
// XEP-0045: Multi-User Chat
|
2016-03-27 20:25:48 -04:00
|
|
|
_handle_groupchat(stanza);
|
2021-10-16 02:43:55 -04:00
|
|
|
|
2021-03-25 06:34:14 -04:00
|
|
|
} else if (type && g_strcmp0(type, STANZA_TYPE_HEADLINE) == 0) {
|
2021-10-16 02:43:55 -04:00
|
|
|
xmpp_stanza_t* event = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB_EVENT);
|
2022-02-18 12:59:32 -05:00
|
|
|
// TODO: do we want to handle all pubsub here or should additionally check for STANZA_NS_MOOD?
|
2021-10-16 02:43:55 -04:00
|
|
|
if (event) {
|
|
|
|
_handle_pubsub(stanza, event);
|
|
|
|
return 1;
|
2021-12-06 07:44:04 -05:00
|
|
|
} else {
|
|
|
|
_handle_headline(stanza);
|
2021-10-16 02:43:55 -04:00
|
|
|
}
|
2021-05-14 10:12:38 -04:00
|
|
|
} else if (type == NULL || g_strcmp0(type, STANZA_TYPE_CHAT) == 0 || g_strcmp0(type, STANZA_TYPE_NORMAL) == 0) {
|
2020-07-02 11:40:58 -04:00
|
|
|
// type: chat, normal (==NULL)
|
2020-07-02 11:15:42 -04:00
|
|
|
|
2021-07-01 12:02:03 -04:00
|
|
|
// ignore all messages from JIDs that are not in roster, if 'silence' is set
|
|
|
|
if (_should_ignore_based_on_silence(stanza)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-06-09 14:14:57 -04:00
|
|
|
// XEP-0353: Jingle Message Initiation
|
|
|
|
if (_handle_jingle_message(stanza)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-03-17 11:16:59 -04:00
|
|
|
// XEP-0045: Multi-User Chat 8.6 Voice Requests
|
|
|
|
if (_handle_form(stanza)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-07-02 11:47:07 -04:00
|
|
|
// XEP-0313: Message Archive Management
|
|
|
|
if (_handle_mam(stanza)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-07-02 11:15:42 -04:00
|
|
|
// XEP-0045: Multi-User Chat - invites - presence
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
2020-07-02 11:15:42 -04:00
|
|
|
if (mucuser) {
|
|
|
|
_handle_muc_user(stanza);
|
|
|
|
}
|
2016-03-27 20:25:48 -04:00
|
|
|
|
2020-07-02 11:15:42 -04:00
|
|
|
// XEP-0249: Direct MUC Invitations
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
|
2020-07-02 11:15:42 -04:00
|
|
|
if (conference) {
|
|
|
|
_handle_conference(stanza);
|
2020-07-02 11:28:48 -04:00
|
|
|
return 1;
|
2020-07-02 11:15:42 -04:00
|
|
|
}
|
2016-03-27 20:25:48 -04:00
|
|
|
|
2020-07-02 11:15:42 -04:00
|
|
|
// XEP-0158: CAPTCHA Forms
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA);
|
2020-07-02 11:15:42 -04:00
|
|
|
if (captcha) {
|
|
|
|
_handle_captcha(stanza);
|
2020-07-02 11:28:48 -04:00
|
|
|
return 1;
|
2020-07-02 11:15:42 -04:00
|
|
|
}
|
2016-03-27 20:25:48 -04:00
|
|
|
|
2020-07-02 11:15:42 -04:00
|
|
|
// XEP-0184: Message Delivery Receipts
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);
|
2020-07-02 11:15:42 -04:00
|
|
|
if (receipts) {
|
|
|
|
_handle_receipt_received(stanza);
|
|
|
|
}
|
2016-03-27 20:25:48 -04:00
|
|
|
|
2020-07-02 11:15:42 -04:00
|
|
|
// XEP-0060: Publish-Subscribe
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* event = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB_EVENT);
|
2020-07-02 11:15:42 -04:00
|
|
|
if (event) {
|
|
|
|
_handle_pubsub(stanza, event);
|
2020-07-02 11:28:48 -04:00
|
|
|
return 1;
|
2020-07-02 11:15:42 -04:00
|
|
|
}
|
2016-03-27 20:25:48 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* msg_stanza = stanza;
|
2020-07-03 11:29:13 -04:00
|
|
|
gboolean is_carbon = FALSE;
|
|
|
|
|
|
|
|
// XEP-0280: Message Carbons
|
2021-11-25 08:45:45 -05:00
|
|
|
// Only allow `<sent xmlns='urn:xmpp:carbons:2'>` and `<received xmlns='urn:xmpp:carbons:2'>` carbons
|
|
|
|
// Thus ignoring `<private xmlns="urn:xmpp:carbons:2"/>`
|
|
|
|
xmpp_stanza_t* carbons = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_SENT, STANZA_NS_CARBONS);
|
|
|
|
if (!carbons) {
|
|
|
|
carbons = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_RECEIVED, STANZA_NS_CARBONS);
|
|
|
|
}
|
|
|
|
|
2020-07-03 11:29:13 -04:00
|
|
|
if (carbons) {
|
2020-07-03 11:55:15 -04:00
|
|
|
|
|
|
|
// carbon must come from ourselves
|
2020-07-07 08:18:57 -04:00
|
|
|
char* mybarejid = connection_get_barejid();
|
|
|
|
const char* const stanza_from = xmpp_stanza_get_from(stanza);
|
2020-07-03 11:55:15 -04:00
|
|
|
|
2021-03-25 10:26:16 -04:00
|
|
|
if (stanza_from) {
|
|
|
|
if (g_strcmp0(mybarejid, stanza_from) != 0) {
|
|
|
|
log_warning("Invalid carbon received, from: %s", stanza_from);
|
|
|
|
msg_stanza = NULL;
|
|
|
|
} else {
|
|
|
|
is_carbon = TRUE;
|
|
|
|
// returns NULL if it was a carbon that was invalid, so that we dont parse later
|
|
|
|
msg_stanza = _handle_carbons(carbons);
|
|
|
|
}
|
2020-07-03 11:55:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(mybarejid);
|
2020-07-03 11:29:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (msg_stanza) {
|
2021-02-04 15:13:31 -05:00
|
|
|
_handle_chat(msg_stanza, FALSE, is_carbon, NULL, NULL);
|
2020-07-03 11:29:13 -04:00
|
|
|
}
|
2020-07-02 11:40:58 -04:00
|
|
|
} else {
|
2020-07-02 11:47:07 -04:00
|
|
|
// none of the allowed types
|
2020-07-07 08:18:57 -04:00
|
|
|
char* text;
|
2020-07-02 11:47:07 -04:00
|
|
|
size_t text_size;
|
|
|
|
|
|
|
|
xmpp_stanza_to_text(stanza, &text, &text_size);
|
|
|
|
log_info("Received <message> with invalid 'type': %s", text);
|
|
|
|
|
|
|
|
xmpp_free(connection_get_ctx(), text);
|
2019-02-22 05:16:42 -05:00
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
return 1;
|
|
|
|
}
|
2013-01-28 19:37:50 -05:00
|
|
|
|
2021-03-17 11:16:59 -04:00
|
|
|
void
|
|
|
|
message_muc_submit_voice_approve(ProfConfWin* confwin)
|
|
|
|
{
|
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
xmpp_stanza_t* message = stanza_create_approve_voice(ctx, NULL, confwin->roomjid, NULL, confwin->form);
|
|
|
|
|
|
|
|
_send_message_stanza(message);
|
|
|
|
xmpp_stanza_release(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_handle_form(xmpp_stanza_t* const stanza)
|
|
|
|
{
|
|
|
|
xmpp_stanza_t* result = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_X, STANZA_NS_DATA);
|
|
|
|
if (!result) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* const stanza_from = xmpp_stanza_get_from(stanza);
|
2021-03-25 10:27:59 -04:00
|
|
|
if (!stanza_from) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-03-17 11:16:59 -04:00
|
|
|
|
|
|
|
DataForm* form = form_create(result);
|
|
|
|
ProfConfWin* confwin = (ProfConfWin*)wins_new_config(stanza_from, form, message_muc_submit_voice_approve, NULL, NULL);
|
|
|
|
confwin_handle_configuration(confwin, form);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-01-28 19:45:03 -05:00
|
|
|
void
|
2016-05-02 17:34:26 -04:00
|
|
|
message_handlers_init(void)
|
2013-01-28 19:45:03 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_conn_t* const conn = connection_get_conn();
|
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
2016-03-27 20:25:48 -04:00
|
|
|
xmpp_handler_add(conn, _message_handler, NULL, STANZA_NAME_MESSAGE, NULL, ctx);
|
2019-02-22 05:16:42 -05:00
|
|
|
|
|
|
|
if (pubsub_event_handlers) {
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(pubsub_event_handlers);
|
|
|
|
GList* curr = keys;
|
2019-02-22 05:16:42 -05:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessageHandler* handler = g_hash_table_lookup(pubsub_event_handlers, curr->data);
|
2019-02-22 05:16:42 -05:00
|
|
|
if (handler->free_func && handler->userdata) {
|
|
|
|
handler->free_func(handler->userdata);
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
g_list_free(keys);
|
|
|
|
g_hash_table_destroy(pubsub_event_handlers);
|
|
|
|
}
|
|
|
|
|
2019-04-01 07:42:24 -04:00
|
|
|
pubsub_event_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
|
2019-02-22 05:16:42 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessage*
|
2019-06-17 00:23:40 -04:00
|
|
|
message_init(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessage* message = malloc(sizeof(ProfMessage));
|
2019-06-17 00:23:40 -04:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
message->from_jid = NULL;
|
|
|
|
message->to_jid = NULL;
|
2019-06-17 00:23:40 -04:00
|
|
|
message->id = NULL;
|
2019-10-31 08:45:44 -04:00
|
|
|
message->originid = NULL;
|
2020-07-23 08:21:27 -04:00
|
|
|
message->stanzaid = NULL;
|
2020-02-10 07:19:54 -05:00
|
|
|
message->replace_id = NULL;
|
2019-06-17 00:23:40 -04:00
|
|
|
message->body = NULL;
|
|
|
|
message->encrypted = NULL;
|
|
|
|
message->plain = NULL;
|
2020-03-27 19:04:41 -04:00
|
|
|
message->enc = PROF_MSG_ENC_NONE;
|
2019-06-17 00:23:40 -04:00
|
|
|
message->timestamp = NULL;
|
2019-06-21 07:47:26 -04:00
|
|
|
message->trusted = true;
|
2020-04-06 12:37:39 -04:00
|
|
|
message->type = PROF_MSG_TYPE_UNINITIALIZED;
|
2019-06-17 00:23:40 -04:00
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
message_free(ProfMessage* message)
|
2019-06-17 00:23:40 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* ctx = connection_get_ctx();
|
2020-04-11 11:11:53 -04:00
|
|
|
if (message->from_jid) {
|
|
|
|
jid_destroy(message->from_jid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->to_jid) {
|
|
|
|
jid_destroy(message->to_jid);
|
2019-06-17 00:23:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (message->id) {
|
|
|
|
xmpp_free(ctx, message->id);
|
|
|
|
}
|
|
|
|
|
2019-10-31 08:45:44 -04:00
|
|
|
if (message->originid) {
|
|
|
|
xmpp_free(ctx, message->originid);
|
|
|
|
}
|
|
|
|
|
2020-07-23 08:21:27 -04:00
|
|
|
if (message->stanzaid) {
|
|
|
|
xmpp_free(ctx, message->stanzaid);
|
|
|
|
}
|
|
|
|
|
2020-02-10 07:19:54 -05:00
|
|
|
if (message->replace_id) {
|
|
|
|
xmpp_free(ctx, message->replace_id);
|
|
|
|
}
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
if (message->body) {
|
|
|
|
xmpp_free(ctx, message->body);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->encrypted) {
|
|
|
|
xmpp_free(ctx, message->encrypted);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->plain) {
|
|
|
|
free(message->plain);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->timestamp) {
|
|
|
|
g_date_time_unref(message->timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(message);
|
|
|
|
}
|
|
|
|
|
2019-06-19 17:49:04 -04:00
|
|
|
void
|
|
|
|
message_handlers_clear(void)
|
|
|
|
{
|
|
|
|
if (pubsub_event_handlers) {
|
|
|
|
g_hash_table_remove_all(pubsub_event_handlers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 05:16:42 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
message_pubsub_event_handler_add(const char* const node, ProfMessageCallback func, ProfMessageFreeCallback free_func, void* userdata)
|
2019-02-22 05:16:42 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessageHandler* handler = malloc(sizeof(ProfMessageHandler));
|
2019-02-22 05:16:42 -05:00
|
|
|
handler->func = func;
|
|
|
|
handler->free_func = free_func;
|
|
|
|
handler->userdata = userdata;
|
|
|
|
|
|
|
|
g_hash_table_insert(pubsub_event_handlers, strdup(node), handler);
|
2013-01-28 19:45:03 -05:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:14:23 -04:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_chat(const char* const barejid, const char* const msg, const char* const oob_url, gboolean request_receipt, const char* const replace_id)
|
2015-06-21 12:11:23 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
2015-06-21 12:11:23 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* state = chat_session_get_state(barejid);
|
|
|
|
char* jid = chat_session_get_jid(barejid);
|
|
|
|
char* id = connection_create_stanza_id();
|
2015-06-20 20:48:25 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
2016-08-20 13:51:19 -04:00
|
|
|
xmpp_message_set_body(message, msg);
|
2015-06-20 20:48:25 -04:00
|
|
|
free(jid);
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
stanza_attach_state(ctx, message, state);
|
|
|
|
}
|
2015-06-21 12:11:23 -04:00
|
|
|
|
2016-04-11 14:13:18 -04:00
|
|
|
if (oob_url) {
|
|
|
|
stanza_attach_x_oob_url(ctx, message, oob_url);
|
|
|
|
}
|
|
|
|
|
2016-08-18 17:51:06 -04:00
|
|
|
if (request_receipt) {
|
2015-06-20 20:48:25 -04:00
|
|
|
stanza_attach_receipt_request(ctx, message);
|
|
|
|
}
|
|
|
|
|
2020-02-10 10:17:01 -05:00
|
|
|
if (replace_id) {
|
|
|
|
stanza_attach_correction(ctx, message, replace_id);
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(message);
|
2015-06-20 20:48:25 -04:00
|
|
|
xmpp_stanza_release(message);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:14:23 -04:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean request_receipt, const char* const replace_id)
|
2015-06-20 20:48:25 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
2015-06-20 20:48:25 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* state = chat_session_get_state(barejid);
|
|
|
|
char* jid = chat_session_get_jid(barejid);
|
|
|
|
char* id = connection_create_stanza_id();
|
2015-03-24 19:34:24 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* message = NULL;
|
2016-03-31 16:05:02 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2020-07-07 08:18:57 -04:00
|
|
|
char* account_name = session_get_account_name();
|
|
|
|
ProfAccount* account = accounts_get_account(account_name);
|
2015-03-24 19:34:24 -04:00
|
|
|
if (account->pgp_keyid) {
|
2020-07-07 08:18:57 -04:00
|
|
|
Jid* jidp = jid_create(jid);
|
|
|
|
char* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid);
|
2015-03-24 19:34:24 -04:00
|
|
|
if (encrypted) {
|
2016-08-20 13:51:19 -04:00
|
|
|
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
2019-02-20 04:48:28 -05:00
|
|
|
xmpp_message_set_body(message, "This message is encrypted (XEP-0027).");
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* x = xmpp_stanza_new(ctx);
|
2015-03-24 19:34:24 -04:00
|
|
|
xmpp_stanza_set_name(x, STANZA_NAME_X);
|
|
|
|
xmpp_stanza_set_ns(x, STANZA_NS_ENCRYPTED);
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* enc_st = xmpp_stanza_new(ctx);
|
2015-03-24 19:34:24 -04:00
|
|
|
xmpp_stanza_set_text(enc_st, encrypted);
|
|
|
|
xmpp_stanza_add_child(x, enc_st);
|
|
|
|
xmpp_stanza_release(enc_st);
|
|
|
|
xmpp_stanza_add_child(message, x);
|
|
|
|
xmpp_stanza_release(x);
|
|
|
|
free(encrypted);
|
|
|
|
} else {
|
2016-08-20 13:51:19 -04:00
|
|
|
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
|
|
|
xmpp_message_set_body(message, msg);
|
2015-03-24 19:34:24 -04:00
|
|
|
}
|
2015-06-24 15:53:04 -04:00
|
|
|
jid_destroy(jidp);
|
2015-04-05 11:03:50 -04:00
|
|
|
} else {
|
2016-08-20 13:51:19 -04:00
|
|
|
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
|
|
|
xmpp_message_set_body(message, msg);
|
2015-03-24 19:34:24 -04:00
|
|
|
}
|
2015-08-10 20:00:23 -04:00
|
|
|
account_free(account);
|
2015-03-24 19:34:24 -04:00
|
|
|
#else
|
2020-06-21 03:43:42 -04:00
|
|
|
// ?
|
2016-08-20 13:51:19 -04:00
|
|
|
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
|
|
|
xmpp_message_set_body(message, msg);
|
2015-03-24 19:34:24 -04:00
|
|
|
#endif
|
2015-03-11 19:18:28 -04:00
|
|
|
free(jid);
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
stanza_attach_state(ctx, message, state);
|
|
|
|
}
|
2015-06-21 12:11:23 -04:00
|
|
|
|
2016-08-18 17:51:06 -04:00
|
|
|
if (request_receipt) {
|
2015-03-11 19:18:28 -04:00
|
|
|
stanza_attach_receipt_request(ctx, message);
|
2015-03-10 17:16:34 -04:00
|
|
|
}
|
|
|
|
|
2020-02-12 02:54:12 -05:00
|
|
|
if (replace_id) {
|
|
|
|
stanza_attach_correction(ctx, message, replace_id);
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(message);
|
2015-03-10 17:16:34 -04:00
|
|
|
xmpp_stanza_release(message);
|
2015-03-11 19:47:11 -04:00
|
|
|
|
|
|
|
return id;
|
2015-03-10 17:16:34 -04:00
|
|
|
}
|
|
|
|
|
2020-06-21 03:43:42 -04:00
|
|
|
// XEP-0373: OpenPGP for XMPP
|
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_chat_ox(const char* const barejid, const char* const msg, gboolean request_receipt, const char* const replace_id)
|
2020-06-21 03:43:42 -04:00
|
|
|
{
|
2020-06-30 05:10:27 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
2020-06-21 03:43:42 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* state = chat_session_get_state(barejid);
|
|
|
|
char* jid = chat_session_get_jid(barejid);
|
|
|
|
char* id = connection_create_stanza_id();
|
2020-06-21 03:43:42 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* message = NULL;
|
|
|
|
Jid* jidp = jid_create(jid);
|
2020-06-21 03:43:42 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* account_name = session_get_account_name();
|
|
|
|
ProfAccount* account = accounts_get_account(account_name);
|
2020-06-21 03:43:42 -04:00
|
|
|
|
|
|
|
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
|
|
|
xmpp_message_set_body(message, "This message is encrypted (XEP-0373: OpenPGP for XMPP).");
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* openpgp = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_name(openpgp, STANZA_NAME_OPENPGP);
|
|
|
|
xmpp_stanza_set_ns(openpgp, STANZA_NS_OPENPGP_0);
|
|
|
|
|
2022-05-04 08:26:26 -04:00
|
|
|
xmpp_stanza_t* signcrypt = _ox_openpgp_signcrypt(ctx, barejid, msg);
|
2020-06-21 03:43:42 -04:00
|
|
|
char* c;
|
|
|
|
size_t s;
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_to_text(signcrypt, &c, &s);
|
2020-06-21 03:43:42 -04:00
|
|
|
char* signcrypt_e = p_ox_gpg_signcrypt(account->jid, barejid, c);
|
2020-07-07 08:18:57 -04:00
|
|
|
if (signcrypt_e == NULL) {
|
2022-06-29 07:26:15 -04:00
|
|
|
cons_show("Unable to send OX message. Check log file and profanity-ox-setup man page for details.");
|
2020-07-07 08:18:57 -04:00
|
|
|
log_error("Message not signcrypted.");
|
|
|
|
return NULL;
|
2020-06-21 03:43:42 -04:00
|
|
|
}
|
|
|
|
// BASE64_OPENPGP_MESSAGE
|
|
|
|
xmpp_stanza_t* base64_openpgp_message = xmpp_stanza_new(ctx);
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_set_text(base64_openpgp_message, signcrypt_e);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_add_child(openpgp, base64_openpgp_message);
|
|
|
|
xmpp_stanza_add_child(message, openpgp);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_to_text(message, &c, &s);
|
2020-06-21 03:43:42 -04:00
|
|
|
|
|
|
|
account_free(account);
|
|
|
|
jid_destroy(jidp);
|
|
|
|
free(jid);
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
stanza_attach_state(ctx, message, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request_receipt) {
|
|
|
|
stanza_attach_receipt_request(ctx, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (replace_id) {
|
|
|
|
stanza_attach_correction(ctx, message, replace_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
_send_message_stanza(message);
|
|
|
|
xmpp_stanza_release(message);
|
|
|
|
|
|
|
|
return id;
|
2020-06-30 05:10:27 -04:00
|
|
|
#endif // HAVE_LIBGPGME
|
|
|
|
return NULL;
|
2020-06-21 03:43:42 -04:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:14:23 -04:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_chat_otr(const char* const barejid, const char* const msg, gboolean request_receipt, const char* const replace_id)
|
2015-03-10 17:16:34 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
2015-03-10 17:16:34 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* state = chat_session_get_state(barejid);
|
|
|
|
char* jid = chat_session_get_jid(barejid);
|
|
|
|
char* id = connection_create_stanza_id();
|
2015-06-21 12:11:23 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, barejid, id);
|
2016-08-20 13:51:19 -04:00
|
|
|
xmpp_message_set_body(message, msg);
|
|
|
|
|
2015-03-11 19:18:28 -04:00
|
|
|
free(jid);
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
stanza_attach_state(ctx, message, state);
|
|
|
|
}
|
2015-06-21 12:11:23 -04:00
|
|
|
|
2015-03-11 19:18:28 -04:00
|
|
|
stanza_attach_carbons_private(ctx, message);
|
2015-07-01 10:04:54 -04:00
|
|
|
stanza_attach_hints_no_copy(ctx, message);
|
|
|
|
stanza_attach_hints_no_store(ctx, message);
|
2015-06-21 12:11:23 -04:00
|
|
|
|
2016-08-18 17:51:06 -04:00
|
|
|
if (request_receipt) {
|
2015-03-11 19:18:28 -04:00
|
|
|
stanza_attach_receipt_request(ctx, message);
|
2013-01-28 19:21:04 -05:00
|
|
|
}
|
|
|
|
|
2020-02-12 02:54:12 -05:00
|
|
|
if (replace_id) {
|
|
|
|
stanza_attach_correction(ctx, message, replace_id);
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(message);
|
2013-01-28 19:21:04 -05:00
|
|
|
xmpp_stanza_release(message);
|
2015-03-11 19:47:11 -04:00
|
|
|
|
|
|
|
return id;
|
2013-01-28 19:21:04 -05:00
|
|
|
}
|
2013-01-28 19:37:50 -05:00
|
|
|
|
2019-02-26 13:53:06 -05:00
|
|
|
#ifdef HAVE_OMEMO
|
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_chat_omemo(const char* const jid, uint32_t sid, GList* keys,
|
|
|
|
const unsigned char* const iv, size_t iv_len,
|
|
|
|
const unsigned char* const ciphertext, size_t ciphertext_len,
|
|
|
|
gboolean request_receipt, gboolean muc, const char* const replace_id)
|
2019-02-26 13:53:06 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* state = chat_session_get_state(jid);
|
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
char* id;
|
|
|
|
xmpp_stanza_t* message;
|
2019-03-18 01:31:19 -04:00
|
|
|
if (muc) {
|
2019-10-17 09:40:40 -04:00
|
|
|
id = connection_create_stanza_id();
|
2019-03-18 01:31:19 -04:00
|
|
|
message = xmpp_message_new(ctx, STANZA_TYPE_GROUPCHAT, jid, id);
|
2019-04-01 13:19:39 -04:00
|
|
|
stanza_attach_origin_id(ctx, message, id);
|
2019-03-18 01:31:19 -04:00
|
|
|
} else {
|
2019-10-17 09:40:40 -04:00
|
|
|
id = connection_create_stanza_id();
|
2019-03-18 01:31:19 -04:00
|
|
|
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
|
|
|
|
}
|
2019-02-26 13:53:06 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* encrypted = xmpp_stanza_new(ctx);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_name(encrypted, "encrypted");
|
|
|
|
xmpp_stanza_set_ns(encrypted, STANZA_NS_OMEMO);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* header = xmpp_stanza_new(ctx);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_name(header, "header");
|
2020-07-07 08:18:57 -04:00
|
|
|
char* sid_text = g_strdup_printf("%d", sid);
|
2021-05-28 11:45:15 -04:00
|
|
|
log_debug("[OMEMO] Sending from device sid %s", sid_text);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_attribute(header, "sid", sid_text);
|
|
|
|
g_free(sid_text);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* key_iter;
|
2019-02-26 13:53:06 -05:00
|
|
|
for (key_iter = keys; key_iter != NULL; key_iter = key_iter->next) {
|
2020-07-07 08:18:57 -04:00
|
|
|
omemo_key_t* key = (omemo_key_t*)key_iter->data;
|
2019-02-26 13:53:06 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* key_stanza = xmpp_stanza_new(ctx);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_name(key_stanza, "key");
|
2020-07-07 08:18:57 -04:00
|
|
|
char* rid = g_strdup_printf("%d", key->device_id);
|
2021-07-01 12:08:40 -04:00
|
|
|
log_debug("[OMEMO] Sending to device rid %s", rid == NULL ? "NULL" : rid);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_attribute(key_stanza, "rid", rid);
|
|
|
|
g_free(rid);
|
|
|
|
if (key->prekey) {
|
|
|
|
xmpp_stanza_set_attribute(key_stanza, "prekey", "true");
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* key_raw = g_base64_encode(key->data, key->length);
|
|
|
|
xmpp_stanza_t* key_text = xmpp_stanza_new(ctx);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_text(key_text, key_raw);
|
|
|
|
g_free(key_raw);
|
|
|
|
|
|
|
|
xmpp_stanza_add_child(key_stanza, key_text);
|
|
|
|
xmpp_stanza_add_child(header, key_stanza);
|
|
|
|
xmpp_stanza_release(key_text);
|
|
|
|
xmpp_stanza_release(key_stanza);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* iv_stanza = xmpp_stanza_new(ctx);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_name(iv_stanza, "iv");
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* iv_raw = g_base64_encode(iv, iv_len);
|
|
|
|
xmpp_stanza_t* iv_text = xmpp_stanza_new(ctx);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_text(iv_text, iv_raw);
|
|
|
|
g_free(iv_raw);
|
|
|
|
|
|
|
|
xmpp_stanza_add_child(iv_stanza, iv_text);
|
|
|
|
xmpp_stanza_add_child(header, iv_stanza);
|
|
|
|
xmpp_stanza_release(iv_text);
|
|
|
|
xmpp_stanza_release(iv_stanza);
|
|
|
|
|
|
|
|
xmpp_stanza_add_child(encrypted, header);
|
|
|
|
xmpp_stanza_release(header);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* payload = xmpp_stanza_new(ctx);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_name(payload, "payload");
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* ciphertext_raw = g_base64_encode(ciphertext, ciphertext_len);
|
|
|
|
xmpp_stanza_t* payload_text = xmpp_stanza_new(ctx);
|
2019-02-26 13:53:06 -05:00
|
|
|
xmpp_stanza_set_text(payload_text, ciphertext_raw);
|
|
|
|
g_free(ciphertext_raw);
|
|
|
|
|
|
|
|
xmpp_stanza_add_child(payload, payload_text);
|
|
|
|
xmpp_stanza_add_child(encrypted, payload);
|
|
|
|
xmpp_stanza_release(payload_text);
|
|
|
|
xmpp_stanza_release(payload);
|
|
|
|
|
|
|
|
xmpp_stanza_add_child(message, encrypted);
|
|
|
|
xmpp_stanza_release(encrypted);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* body = xmpp_stanza_new(ctx);
|
2019-02-28 13:27:03 -05:00
|
|
|
xmpp_stanza_set_name(body, "body");
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* body_text = xmpp_stanza_new(ctx);
|
2019-02-28 13:27:03 -05:00
|
|
|
xmpp_stanza_set_text(body_text, "You received a message encrypted with OMEMO but your client doesn't support OMEMO.");
|
|
|
|
xmpp_stanza_add_child(body, body_text);
|
|
|
|
xmpp_stanza_release(body_text);
|
|
|
|
xmpp_stanza_add_child(message, body);
|
2019-03-21 19:03:16 -04:00
|
|
|
xmpp_stanza_release(body);
|
2019-02-28 13:27:03 -05:00
|
|
|
|
2019-02-28 13:42:10 -05:00
|
|
|
if (state) {
|
|
|
|
stanza_attach_state(ctx, message, state);
|
|
|
|
}
|
|
|
|
|
2019-03-13 12:59:31 -04:00
|
|
|
stanza_attach_hints_store(ctx, message);
|
|
|
|
|
2019-02-26 13:53:06 -05:00
|
|
|
if (request_receipt) {
|
|
|
|
stanza_attach_receipt_request(ctx, message);
|
|
|
|
}
|
|
|
|
|
2020-02-12 02:54:12 -05:00
|
|
|
if (replace_id) {
|
|
|
|
stanza_attach_correction(ctx, message, replace_id);
|
|
|
|
}
|
|
|
|
|
2019-02-26 13:53:06 -05:00
|
|
|
_send_message_stanza(message);
|
|
|
|
xmpp_stanza_release(message);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-03-27 20:16:31 -04:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_private(const char* const fulljid, const char* const msg, const char* const oob_url)
|
2013-01-28 19:37:50 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
char* id = connection_create_stanza_id();
|
2016-08-20 13:51:19 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, fulljid, id);
|
2016-08-20 13:51:19 -04:00
|
|
|
xmpp_message_set_body(message, msg);
|
|
|
|
|
2016-04-11 14:13:18 -04:00
|
|
|
if (oob_url) {
|
|
|
|
stanza_attach_x_oob_url(ctx, message, oob_url);
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(message);
|
2013-05-04 21:31:04 -04:00
|
|
|
xmpp_stanza_release(message);
|
2020-03-27 20:16:31 -04:00
|
|
|
|
|
|
|
return id;
|
2013-05-04 21:31:04 -04:00
|
|
|
}
|
|
|
|
|
2019-04-01 13:19:39 -04:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_groupchat(const char* const roomjid, const char* const msg, const char* const oob_url, const char* const replace_id)
|
2014-10-04 22:05:46 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
char* id = connection_create_stanza_id();
|
2016-08-20 13:51:19 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* message = xmpp_message_new(ctx, STANZA_TYPE_GROUPCHAT, roomjid, id);
|
2019-04-01 13:19:39 -04:00
|
|
|
stanza_attach_origin_id(ctx, message, id);
|
2016-08-20 13:51:19 -04:00
|
|
|
xmpp_message_set_body(message, msg);
|
|
|
|
|
2016-04-11 14:13:18 -04:00
|
|
|
if (oob_url) {
|
|
|
|
stanza_attach_x_oob_url(ctx, message, oob_url);
|
|
|
|
}
|
|
|
|
|
2020-02-12 08:06:00 -05:00
|
|
|
if (replace_id) {
|
|
|
|
stanza_attach_correction(ctx, message, replace_id);
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(message);
|
2014-10-04 22:05:46 -04:00
|
|
|
xmpp_stanza_release(message);
|
2019-04-01 13:19:39 -04:00
|
|
|
|
|
|
|
return id;
|
2014-10-04 22:05:46 -04:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_groupchat_subject(const char* const roomjid, const char* const subject)
|
2014-12-19 19:52:35 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
xmpp_stanza_t* message = stanza_create_room_subject_message(ctx, roomjid, subject);
|
2014-12-19 19:52:35 -05:00
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(message);
|
2014-12-19 19:52:35 -05:00
|
|
|
xmpp_stanza_release(message);
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_invite(const char* const roomjid, const char* const contact,
|
|
|
|
const char* const reason)
|
2013-04-20 15:18:13 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
xmpp_stanza_t* stanza;
|
2015-03-28 18:51:41 -04:00
|
|
|
|
|
|
|
muc_member_type_t member_type = muc_member_type(roomjid);
|
|
|
|
if (member_type == MUC_MEMBER_TYPE_PUBLIC) {
|
|
|
|
log_debug("Sending direct invite to %s, for %s", contact, roomjid);
|
2020-07-07 08:18:57 -04:00
|
|
|
char* password = muc_password(roomjid);
|
2015-03-28 21:46:59 -04:00
|
|
|
stanza = stanza_create_invite(ctx, roomjid, contact, reason, password);
|
2015-03-28 18:51:41 -04:00
|
|
|
} else {
|
|
|
|
log_debug("Sending mediated invite to %s, for %s", contact, roomjid);
|
|
|
|
stanza = stanza_create_mediated_invite(ctx, roomjid, contact, reason);
|
|
|
|
}
|
2013-04-20 15:18:13 -04:00
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(stanza);
|
2013-04-20 15:18:13 -04:00
|
|
|
xmpp_stanza_release(stanza);
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_composing(const char* const jid)
|
2013-01-28 19:37:50 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
2013-01-28 19:37:50 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_COMPOSING);
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(stanza);
|
2013-01-28 19:37:50 -05:00
|
|
|
xmpp_stanza_release(stanza);
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_paused(const char* const jid)
|
2013-01-28 19:37:50 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
xmpp_stanza_t* stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_PAUSED);
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(stanza);
|
2013-01-28 19:37:50 -05:00
|
|
|
xmpp_stanza_release(stanza);
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_inactive(const char* const jid)
|
2013-01-28 19:37:50 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
xmpp_stanza_t* stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_INACTIVE);
|
2013-01-28 19:37:50 -05:00
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(stanza);
|
2013-01-28 19:37:50 -05:00
|
|
|
xmpp_stanza_release(stanza);
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:13:42 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
message_send_gone(const char* const jid)
|
2013-01-28 19:37:50 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
xmpp_stanza_t* stanza = stanza_create_chat_state(ctx, jid, STANZA_NAME_GONE);
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(stanza);
|
2013-01-28 19:37:50 -05:00
|
|
|
xmpp_stanza_release(stanza);
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_error(xmpp_stanza_t* const stanza)
|
2014-01-26 13:30:34 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* id = xmpp_stanza_get_id(stanza);
|
|
|
|
const char* jid = xmpp_stanza_get_from(stanza);
|
|
|
|
xmpp_stanza_t* error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
|
|
|
|
const char* type = NULL;
|
2015-05-02 18:40:14 -04:00
|
|
|
if (error_stanza) {
|
2016-08-20 13:16:51 -04:00
|
|
|
type = xmpp_stanza_get_type(error_stanza);
|
2014-01-27 17:35:04 -05:00
|
|
|
}
|
2014-01-27 17:09:16 -05:00
|
|
|
|
|
|
|
// stanza_get_error never returns NULL
|
2020-07-07 08:18:57 -04:00
|
|
|
char* err_msg = stanza_get_error_message(stanza);
|
2014-01-26 17:50:22 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
GString* log_msg = g_string_new("message stanza error received");
|
2015-05-02 18:40:14 -04:00
|
|
|
if (id) {
|
2014-01-27 17:35:04 -05:00
|
|
|
g_string_append(log_msg, " id=");
|
2014-01-26 17:50:22 -05:00
|
|
|
g_string_append(log_msg, id);
|
|
|
|
}
|
2015-05-02 18:40:14 -04:00
|
|
|
if (jid) {
|
2014-01-27 17:35:04 -05:00
|
|
|
g_string_append(log_msg, " from=");
|
2014-12-28 20:17:59 -05:00
|
|
|
g_string_append(log_msg, jid);
|
2014-01-26 13:30:34 -05:00
|
|
|
}
|
2015-05-02 18:40:14 -04:00
|
|
|
if (type) {
|
2014-01-27 17:35:04 -05:00
|
|
|
g_string_append(log_msg, " type=");
|
|
|
|
g_string_append(log_msg, type);
|
|
|
|
}
|
|
|
|
g_string_append(log_msg, " error=");
|
2014-01-26 17:50:22 -05:00
|
|
|
g_string_append(log_msg, err_msg);
|
2014-01-27 17:09:16 -05:00
|
|
|
|
2014-01-26 17:50:22 -05:00
|
|
|
log_info(log_msg->str);
|
|
|
|
|
|
|
|
g_string_free(log_msg, TRUE);
|
2014-01-26 13:30:34 -05:00
|
|
|
|
2015-04-30 19:55:40 -04:00
|
|
|
if (!jid) {
|
|
|
|
ui_handle_error(err_msg);
|
|
|
|
} else {
|
2020-10-30 10:09:40 -04:00
|
|
|
if (type && (strcmp(type, "cancel") == 0)) {
|
|
|
|
Jid* jidp = jid_create(jid);
|
2021-03-25 11:50:10 -04:00
|
|
|
if (jidp) {
|
|
|
|
chat_session_remove(jidp->barejid);
|
|
|
|
jid_destroy(jidp);
|
|
|
|
}
|
2020-10-30 10:09:40 -04:00
|
|
|
}
|
2015-04-30 19:55:40 -04:00
|
|
|
ui_handle_recipient_error(jid, err_msg);
|
|
|
|
}
|
2014-01-26 13:30:34 -05:00
|
|
|
|
2014-01-27 17:35:04 -05:00
|
|
|
free(err_msg);
|
2014-01-26 13:30:34 -05:00
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_muc_user(xmpp_stanza_t* const stanza)
|
2013-03-24 17:46:00 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* ctx = connection_get_ctx();
|
|
|
|
xmpp_stanza_t* xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
|
|
|
const char* room = xmpp_stanza_get_from(stanza);
|
2013-03-24 17:46:00 -04:00
|
|
|
|
2021-03-25 06:38:22 -04:00
|
|
|
if (!xns_muc_user) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-02 18:40:14 -04:00
|
|
|
if (!room) {
|
2013-03-24 17:46:00 -04:00
|
|
|
log_warning("Message received with no from attribute, ignoring");
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2013-03-24 17:46:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XEP-0045
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* invite = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_INVITE);
|
2015-05-02 18:40:14 -04:00
|
|
|
if (!invite) {
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2015-05-02 18:40:14 -04:00
|
|
|
}
|
2013-03-24 17:46:00 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* invitor_jid = xmpp_stanza_get_from(invite);
|
2015-05-02 18:40:14 -04:00
|
|
|
if (!invitor_jid) {
|
|
|
|
log_warning("Chat room invite received with no from attribute");
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2015-05-02 18:40:14 -04:00
|
|
|
}
|
2013-03-24 17:46:00 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
Jid* jidp = jid_create(invitor_jid);
|
2015-05-02 18:40:14 -04:00
|
|
|
if (!jidp) {
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2015-05-02 18:40:14 -04:00
|
|
|
}
|
2020-07-07 08:18:57 -04:00
|
|
|
char* invitor = jidp->barejid;
|
2013-03-24 17:46:00 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* reason = NULL;
|
|
|
|
xmpp_stanza_t* reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON);
|
2015-05-02 18:40:14 -04:00
|
|
|
if (reason_st) {
|
|
|
|
reason = xmpp_stanza_get_text(reason_st);
|
|
|
|
}
|
2015-03-28 22:16:41 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* password = NULL;
|
|
|
|
xmpp_stanza_t* password_st = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_PASSWORD);
|
2015-05-02 18:40:14 -04:00
|
|
|
if (password_st) {
|
|
|
|
password = xmpp_stanza_get_text(password_st);
|
|
|
|
}
|
|
|
|
|
|
|
|
sv_ev_room_invite(INVITE_MEDIATED, invitor, room, reason, password);
|
|
|
|
jid_destroy(jidp);
|
|
|
|
if (reason) {
|
|
|
|
xmpp_free(ctx, reason);
|
|
|
|
}
|
|
|
|
if (password) {
|
|
|
|
xmpp_free(ctx, password);
|
2014-01-25 16:20:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_conference(xmpp_stanza_t* const stanza)
|
2014-01-25 16:20:56 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
|
2014-01-25 16:20:56 -05:00
|
|
|
|
2021-03-25 06:43:42 -04:00
|
|
|
if (xns_conference) {
|
2021-03-25 10:33:30 -04:00
|
|
|
// XEP-0249
|
|
|
|
const char* room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID);
|
|
|
|
if (!room) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-24 17:46:00 -04:00
|
|
|
|
2021-03-25 06:43:42 -04:00
|
|
|
const char* from = xmpp_stanza_get_from(stanza);
|
|
|
|
if (!from) {
|
|
|
|
log_warning("Message received with no from attribute, ignoring");
|
|
|
|
return;
|
|
|
|
}
|
2013-03-24 17:46:00 -04:00
|
|
|
|
2021-03-25 06:43:42 -04:00
|
|
|
Jid* jidp = jid_create(from);
|
|
|
|
if (!jidp) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-24 17:46:00 -04:00
|
|
|
|
2021-03-25 06:43:42 -04:00
|
|
|
// reason and password are both optional
|
|
|
|
const char* reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON);
|
|
|
|
const char* password = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_PASSWORD);
|
|
|
|
|
|
|
|
sv_ev_room_invite(INVITE_DIRECT, jidp->barejid, room, reason, password);
|
|
|
|
jid_destroy(jidp);
|
|
|
|
}
|
2014-01-25 16:20:56 -05:00
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_captcha(xmpp_stanza_t* const stanza)
|
2014-01-25 16:20:56 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* ctx = connection_get_ctx();
|
|
|
|
const char* from = xmpp_stanza_get_from(stanza);
|
2014-01-25 16:20:56 -05:00
|
|
|
|
2015-05-02 18:40:14 -04:00
|
|
|
if (!from) {
|
2014-01-25 16:20:56 -05:00
|
|
|
log_warning("Message received with no from attribute, ignoring");
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2014-01-25 16:20:56 -05:00
|
|
|
}
|
2013-06-09 09:05:37 -04:00
|
|
|
|
|
|
|
// XEP-0158
|
2020-07-07 08:18:57 -04:00
|
|
|
char* message = xmpp_message_get_body(stanza);
|
2015-05-02 19:35:31 -04:00
|
|
|
if (!message) {
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2013-03-24 17:46:00 -04:00
|
|
|
}
|
|
|
|
|
2015-05-02 19:35:31 -04:00
|
|
|
sv_ev_room_broadcast(from, message);
|
|
|
|
xmpp_free(ctx, message);
|
2013-03-24 17:46:00 -04:00
|
|
|
}
|
|
|
|
|
2022-05-25 15:49:45 -04:00
|
|
|
// Handle changes to muc configuration
|
|
|
|
static int
|
|
|
|
_room_config_handler(xmpp_stanza_t* const stanza, void* const userdata)
|
|
|
|
{
|
|
|
|
const char* from = xmpp_stanza_get_from(stanza);
|
|
|
|
xmpp_stanza_t* query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
|
|
|
EntityCapabilities* capabilities = stanza_create_caps_from_query_element(query);
|
|
|
|
|
|
|
|
// Update window name
|
|
|
|
ProfMucWin* win = wins_get_muc(from);
|
|
|
|
if (win != NULL) {
|
|
|
|
free(win->room_name);
|
|
|
|
win->room_name = strdup(capabilities->identity->name);
|
|
|
|
|
|
|
|
// Update features
|
|
|
|
muc_set_features(from, capabilities->features);
|
|
|
|
}
|
|
|
|
caps_destroy(capabilities);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_groupchat(xmpp_stanza_t* const stanza)
|
2013-01-28 19:37:50 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* ctx = connection_get_ctx();
|
2019-04-01 13:19:39 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* room_jid = xmpp_stanza_get_from(stanza);
|
2021-07-01 12:08:40 -04:00
|
|
|
if (!room_jid) {
|
2021-03-25 10:36:17 -04:00
|
|
|
return;
|
|
|
|
}
|
2020-07-07 08:18:57 -04:00
|
|
|
Jid* from_jid = jid_create(room_jid);
|
2021-07-01 12:08:40 -04:00
|
|
|
if (!from_jid) {
|
2021-03-25 10:36:17 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-28 19:37:50 -05:00
|
|
|
|
2014-04-12 22:11:46 -04:00
|
|
|
// handle room subject
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT);
|
2015-05-02 18:40:14 -04:00
|
|
|
if (subject) {
|
2021-03-25 06:51:42 -04:00
|
|
|
// subject_text is optional, can be NULL
|
|
|
|
char* subject_text = xmpp_stanza_get_text(subject);
|
2020-04-11 11:11:53 -04:00
|
|
|
sv_ev_room_subject(from_jid->barejid, from_jid->resourcepart, subject_text);
|
2019-06-17 00:23:40 -04:00
|
|
|
xmpp_free(ctx, subject_text);
|
2014-04-12 22:11:46 -04:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
jid_destroy(from_jid);
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2014-04-12 22:11:46 -04:00
|
|
|
}
|
|
|
|
|
2013-01-28 19:37:50 -05:00
|
|
|
// handle room broadcasts
|
2020-04-11 11:11:53 -04:00
|
|
|
if (!from_jid->resourcepart) {
|
2020-07-07 08:18:57 -04:00
|
|
|
char* broadcast;
|
2019-06-17 00:23:40 -04:00
|
|
|
broadcast = xmpp_message_get_body(stanza);
|
|
|
|
if (!broadcast) {
|
2022-05-25 15:49:45 -04:00
|
|
|
xmpp_stanza_t* x = xmpp_stanza_get_child_by_name(stanza, "x");
|
|
|
|
|
|
|
|
if (x) {
|
|
|
|
xmpp_stanza_t* status = xmpp_stanza_get_child_by_name(x, "status");
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
const char* code = xmpp_stanza_get_attribute(status, "code");
|
|
|
|
|
|
|
|
if (code) {
|
|
|
|
// If configuration change notification send disco info to get updated info of the muc
|
|
|
|
char* disqo_info_id = connection_create_stanza_id();
|
|
|
|
xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, disqo_info_id, room_jid, NULL);
|
|
|
|
iq_id_handler_add(disqo_info_id, _room_config_handler, NULL, NULL);
|
|
|
|
free(disqo_info_id);
|
|
|
|
iq_send_stanza(iq);
|
|
|
|
xmpp_stanza_release(iq);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
jid_destroy(from_jid);
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2015-05-02 19:35:31 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
sv_ev_room_broadcast(room_jid, broadcast);
|
|
|
|
xmpp_free(ctx, broadcast);
|
2015-05-02 19:35:31 -04:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
jid_destroy(from_jid);
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2014-04-12 22:11:46 -04:00
|
|
|
}
|
2013-01-28 19:37:50 -05:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
if (!jid_is_valid_room_form(from_jid)) {
|
|
|
|
log_error("Invalid room JID: %s", from_jid->str);
|
|
|
|
jid_destroy(from_jid);
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2013-01-28 19:37:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// room not active in profanity
|
2020-04-11 11:11:53 -04:00
|
|
|
if (!muc_active(from_jid->barejid)) {
|
|
|
|
log_error("Message received for inactive chat room: %s", from_jid->str);
|
|
|
|
jid_destroy(from_jid);
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2013-01-28 19:37:50 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessage* message = message_init();
|
2020-04-11 11:11:53 -04:00
|
|
|
message->from_jid = from_jid;
|
2020-04-06 12:37:39 -04:00
|
|
|
message->type = PROF_MSG_TYPE_MUC;
|
2020-02-12 06:56:34 -05:00
|
|
|
|
2021-03-25 06:51:42 -04:00
|
|
|
const char* id = xmpp_stanza_get_id(stanza);
|
2019-06-21 07:02:11 -04:00
|
|
|
if (id) {
|
|
|
|
message->id = strdup(id);
|
|
|
|
}
|
2020-02-12 06:56:34 -05:00
|
|
|
|
2021-03-25 12:07:41 -04:00
|
|
|
char* stanzaid = NULL;
|
|
|
|
xmpp_stanza_t* stanzaidst = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_STANZA_ID, STANZA_NS_STABLE_ID);
|
|
|
|
if (stanzaidst) {
|
|
|
|
stanzaid = (char*)xmpp_stanza_get_attribute(stanzaidst, STANZA_ATTR_ID);
|
|
|
|
if (stanzaid) {
|
|
|
|
message->stanzaid = strdup(stanzaid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-25 06:51:42 -04:00
|
|
|
xmpp_stanza_t* origin = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_ORIGIN_ID, STANZA_NS_STABLE_ID);
|
|
|
|
if (origin) {
|
|
|
|
char* originid = (char*)xmpp_stanza_get_attribute(origin, STANZA_ATTR_ID);
|
|
|
|
if (originid) {
|
|
|
|
message->originid = strdup(originid);
|
|
|
|
}
|
2019-10-31 08:45:44 -04:00
|
|
|
}
|
2019-06-17 00:23:40 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* replace_id_stanza = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_LAST_MESSAGE_CORRECTION);
|
2020-02-12 06:56:34 -05:00
|
|
|
if (replace_id_stanza) {
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* replace_id = xmpp_stanza_get_id(replace_id_stanza);
|
2020-02-12 06:56:34 -05:00
|
|
|
if (replace_id) {
|
|
|
|
message->replace_id = strdup(replace_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-21 06:34:19 -04:00
|
|
|
message->body = xmpp_message_get_body(stanza);
|
|
|
|
|
2019-03-18 14:50:28 -04:00
|
|
|
// check omemo encryption
|
2019-03-14 15:45:47 -04:00
|
|
|
#ifdef HAVE_OMEMO
|
2019-06-17 00:23:40 -04:00
|
|
|
message->plain = omemo_receive_message(stanza, &message->trusted);
|
|
|
|
if (message->plain != NULL) {
|
|
|
|
message->enc = PROF_MSG_ENC_OMEMO;
|
2019-06-16 16:55:07 -04:00
|
|
|
}
|
2019-03-14 15:45:47 -04:00
|
|
|
#endif
|
|
|
|
|
2019-06-21 06:34:19 -04:00
|
|
|
if (!message->plain && !message->body) {
|
2021-06-03 13:55:13 -04:00
|
|
|
log_info("Message received without body for room: %s", from_jid->str);
|
2019-06-21 06:34:19 -04:00
|
|
|
goto out;
|
|
|
|
} else if (!message->plain) {
|
|
|
|
message->plain = strdup(message->body);
|
|
|
|
}
|
2015-05-02 19:35:31 -04:00
|
|
|
|
2020-01-30 05:46:19 -05:00
|
|
|
// determine if the notifications happened whilst offline (MUC history)
|
2020-04-11 11:11:53 -04:00
|
|
|
message->timestamp = stanza_get_delay_from(stanza, from_jid->barejid);
|
2019-11-12 08:47:57 -05:00
|
|
|
if (message->timestamp == NULL) {
|
|
|
|
// checking the domainpart is a workaround for some prosody versions (gh#1190)
|
2020-04-11 11:11:53 -04:00
|
|
|
message->timestamp = stanza_get_delay_from(stanza, from_jid->domainpart);
|
2019-11-12 08:47:57 -05:00
|
|
|
}
|
|
|
|
|
2020-02-25 10:33:28 -05:00
|
|
|
bool is_muc_history = FALSE;
|
2020-02-25 09:24:53 -05:00
|
|
|
if (message->timestamp != NULL) {
|
|
|
|
is_muc_history = TRUE;
|
|
|
|
g_date_time_unref(message->timestamp);
|
|
|
|
message->timestamp = NULL;
|
|
|
|
}
|
2020-01-30 05:46:19 -05:00
|
|
|
|
|
|
|
// we want to display the oldest delay
|
|
|
|
message->timestamp = stanza_get_oldest_delay(stanza);
|
|
|
|
|
2020-03-09 07:22:36 -04:00
|
|
|
// now this has nothing to do with MUC history
|
|
|
|
// it's just setting the time to the received time so upon displaying we can use this time
|
|
|
|
// for example in win_println_incoming_muc_msg()
|
|
|
|
if (!message->timestamp) {
|
|
|
|
message->timestamp = g_date_time_new_now_local();
|
|
|
|
}
|
|
|
|
|
2020-01-30 05:46:19 -05:00
|
|
|
if (is_muc_history) {
|
2019-06-17 00:23:40 -04:00
|
|
|
sv_ev_room_history(message);
|
2015-05-02 19:35:31 -04:00
|
|
|
} else {
|
2019-06-17 00:23:40 -04:00
|
|
|
sv_ev_room_message(message);
|
2013-01-28 19:37:50 -05:00
|
|
|
}
|
|
|
|
|
2019-06-21 06:34:19 -04:00
|
|
|
out:
|
2019-06-17 00:23:40 -04:00
|
|
|
message_free(message);
|
2013-01-28 19:37:50 -05:00
|
|
|
}
|
|
|
|
|
2020-07-02 09:21:54 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_message_send_receipt(const char* const fulljid, const char* const message_id)
|
2015-03-11 19:18:28 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
2016-08-20 14:08:13 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* id = connection_create_stanza_id();
|
|
|
|
xmpp_stanza_t* message = xmpp_message_new(ctx, NULL, fulljid, id);
|
2015-08-09 18:08:36 -04:00
|
|
|
free(id);
|
2015-03-11 19:18:28 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* receipt = xmpp_stanza_new(ctx);
|
2015-03-11 19:18:28 -04:00
|
|
|
xmpp_stanza_set_name(receipt, "received");
|
|
|
|
xmpp_stanza_set_ns(receipt, STANZA_NS_RECEIPTS);
|
2016-08-20 13:16:51 -04:00
|
|
|
xmpp_stanza_set_id(receipt, message_id);
|
2015-03-11 19:18:28 -04:00
|
|
|
|
|
|
|
xmpp_stanza_add_child(message, receipt);
|
|
|
|
xmpp_stanza_release(receipt);
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
_send_message_stanza(message);
|
2015-03-11 19:18:28 -04:00
|
|
|
xmpp_stanza_release(message);
|
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_receipt_received(xmpp_stanza_t* const stanza)
|
2015-05-02 19:05:47 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* receipt = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);
|
2021-03-25 06:54:59 -04:00
|
|
|
if (receipt) {
|
|
|
|
const char* name = xmpp_stanza_get_name(receipt);
|
2021-03-25 10:37:54 -04:00
|
|
|
if ((name == NULL) || (g_strcmp0(name, "received") != 0)) {
|
2021-03-25 06:54:59 -04:00
|
|
|
return;
|
|
|
|
}
|
2015-05-02 19:05:47 -04:00
|
|
|
|
2021-03-25 06:54:59 -04:00
|
|
|
const char* id = xmpp_stanza_get_id(receipt);
|
|
|
|
if (!id) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-02 19:05:47 -04:00
|
|
|
|
2021-03-25 06:54:59 -04:00
|
|
|
const char* fulljid = xmpp_stanza_get_from(stanza);
|
|
|
|
if (!fulljid) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-02 19:05:47 -04:00
|
|
|
|
2021-03-25 06:54:59 -04:00
|
|
|
Jid* jidp = jid_create(fulljid);
|
2021-07-01 12:08:40 -04:00
|
|
|
if (!jidp) {
|
2021-03-25 10:37:54 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-25 06:54:59 -04:00
|
|
|
sv_ev_message_receipt(jidp->barejid, id);
|
|
|
|
jid_destroy(jidp);
|
|
|
|
}
|
2015-05-02 19:05:47 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 09:21:54 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_receipt_request_handler(xmpp_stanza_t* const stanza)
|
2015-05-02 20:48:12 -04:00
|
|
|
{
|
|
|
|
if (!prefs_get_boolean(PREF_RECEIPTS_SEND)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* id = xmpp_stanza_get_id(stanza);
|
2015-05-02 20:48:12 -04:00
|
|
|
if (!id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);
|
2015-05-02 20:48:12 -04:00
|
|
|
if (!receipts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* receipts_name = xmpp_stanza_get_name(receipts);
|
2021-03-25 10:38:48 -04:00
|
|
|
if ((receipts_name == NULL) || (g_strcmp0(receipts_name, "request") != 0)) {
|
2015-05-02 20:48:12 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
const gchar* from = xmpp_stanza_get_from(stanza);
|
2021-03-25 06:56:38 -04:00
|
|
|
if (from) {
|
|
|
|
Jid* jid = jid_create(from);
|
|
|
|
if (jid) {
|
|
|
|
_message_send_receipt(jid->fulljid, id);
|
|
|
|
jid_destroy(jid);
|
|
|
|
}
|
|
|
|
}
|
2015-05-02 20:48:12 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_muc_private_message(xmpp_stanza_t* const stanza)
|
2015-05-02 20:25:33 -04:00
|
|
|
{
|
2019-06-17 00:23:40 -04:00
|
|
|
// standard chat message, use jid without resource
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessage* message = message_init();
|
2020-04-06 12:37:39 -04:00
|
|
|
message->type = PROF_MSG_TYPE_MUCPM;
|
2019-06-17 00:23:40 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
const gchar* from = xmpp_stanza_get_from(stanza);
|
2021-03-25 10:03:35 -04:00
|
|
|
if (!from) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
message->from_jid = jid_create(from);
|
2021-03-25 10:03:35 -04:00
|
|
|
if (!message->from_jid) {
|
|
|
|
goto out;
|
|
|
|
}
|
2019-06-17 00:23:40 -04:00
|
|
|
|
2020-02-12 07:07:52 -05:00
|
|
|
// message stanza id
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* id = xmpp_stanza_get_id(stanza);
|
2020-02-12 07:07:52 -05:00
|
|
|
if (id) {
|
|
|
|
message->id = strdup(id);
|
|
|
|
}
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
// check omemo encryption
|
|
|
|
#ifdef HAVE_OMEMO
|
|
|
|
message->plain = omemo_receive_message(stanza, &message->trusted);
|
|
|
|
if (message->plain != NULL) {
|
|
|
|
message->enc = PROF_MSG_ENC_OMEMO;
|
2015-05-02 20:25:33 -04:00
|
|
|
}
|
2019-06-17 00:23:40 -04:00
|
|
|
#endif
|
|
|
|
|
2019-07-04 07:02:22 -04:00
|
|
|
message->timestamp = stanza_get_delay(stanza);
|
|
|
|
message->body = xmpp_message_get_body(stanza);
|
|
|
|
|
2019-07-03 09:16:19 -04:00
|
|
|
if (!message->plain && !message->body) {
|
2021-06-03 13:55:13 -04:00
|
|
|
log_info("Message received without body from: %s", message->from_jid->str);
|
2019-07-03 09:16:19 -04:00
|
|
|
goto out;
|
|
|
|
} else if (!message->plain) {
|
|
|
|
message->plain = strdup(message->body);
|
|
|
|
}
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
if (message->timestamp) {
|
|
|
|
sv_ev_delayed_private_message(message);
|
2015-05-02 20:25:33 -04:00
|
|
|
} else {
|
2020-03-19 08:38:17 -04:00
|
|
|
message->timestamp = g_date_time_new_now_local();
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
sv_ev_incoming_private_message(message);
|
2015-05-02 20:25:33 -04:00
|
|
|
}
|
|
|
|
|
2019-07-03 09:27:31 -04:00
|
|
|
out:
|
2019-06-17 00:23:40 -04:00
|
|
|
message_free(message);
|
2015-05-02 20:25:33 -04:00
|
|
|
}
|
|
|
|
|
2020-07-03 11:29:13 -04:00
|
|
|
static xmpp_stanza_t*
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_carbons(xmpp_stanza_t* const stanza)
|
2015-05-04 16:31:05 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* name = xmpp_stanza_get_name(stanza);
|
2016-08-20 16:37:20 -04:00
|
|
|
if (!name) {
|
|
|
|
log_error("Unable to retrieve stanza name for Carbon");
|
2020-07-03 11:29:13 -04:00
|
|
|
return NULL;
|
2016-08-20 16:37:20 -04:00
|
|
|
}
|
|
|
|
|
2020-07-03 11:29:13 -04:00
|
|
|
/* TODO: private shouldn't arrive at the client, should it?
|
2016-08-28 12:27:26 -04:00
|
|
|
if (g_strcmp0(name, "private") == 0) {
|
|
|
|
log_info("Carbon received with private element.");
|
|
|
|
}
|
2020-07-03 11:29:13 -04:00
|
|
|
*/
|
2016-08-28 12:27:26 -04:00
|
|
|
|
2021-11-25 08:45:45 -05:00
|
|
|
if ((g_strcmp0(name, STANZA_NAME_RECEIVED) != 0) && (g_strcmp0(name, STANZA_NAME_SENT) != 0)) {
|
2016-08-20 16:37:20 -04:00
|
|
|
log_warning("Carbon received with unrecognised stanza name: %s", name);
|
2020-07-03 11:29:13 -04:00
|
|
|
return NULL;
|
2016-08-20 16:37:20 -04:00
|
|
|
}
|
2015-05-04 16:31:05 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* forwarded = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_FORWARD);
|
2016-08-20 16:37:20 -04:00
|
|
|
if (!forwarded) {
|
|
|
|
log_warning("Carbon received with no forwarded element");
|
2020-07-03 11:29:13 -04:00
|
|
|
return NULL;
|
2016-08-20 16:37:20 -04:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* message_stanza = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE);
|
2019-06-17 00:23:40 -04:00
|
|
|
if (!message_stanza) {
|
2016-08-20 16:37:20 -04:00
|
|
|
log_warning("Carbon received with no message element");
|
2020-07-03 11:29:13 -04:00
|
|
|
return NULL;
|
2016-08-20 16:37:20 -04:00
|
|
|
}
|
2015-05-04 16:31:05 -04:00
|
|
|
|
2022-05-29 09:57:02 -04:00
|
|
|
// Eliminate duplicate messages in chat with oneself when another client is sending a message
|
|
|
|
char* bare_from = xmpp_jid_bare(connection_get_ctx(), xmpp_stanza_get_from(message_stanza));
|
|
|
|
if (g_strcmp0(bare_from, xmpp_stanza_get_to(message_stanza)) == 0) {
|
|
|
|
free(bare_from);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
free(bare_from);
|
|
|
|
|
2020-07-03 11:29:13 -04:00
|
|
|
return message_stanza;
|
2015-05-04 16:31:05 -04:00
|
|
|
}
|
|
|
|
|
2016-03-27 20:25:48 -04:00
|
|
|
static void
|
2021-07-01 12:08:40 -04:00
|
|
|
_handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, const char* result_id, GDateTime* timestamp)
|
2013-01-28 19:37:50 -05:00
|
|
|
{
|
2015-08-01 20:12:54 -04:00
|
|
|
// some clients send the mucuser namespace with private messages
|
|
|
|
// if the namespace exists, and the stanza contains a body element, assume its a private message
|
|
|
|
// otherwise exit the handler
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
|
|
|
xmpp_stanza_t* body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
2015-08-01 20:12:54 -04:00
|
|
|
if (mucuser && body == NULL) {
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2015-01-04 12:54:56 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
const gchar* from = xmpp_stanza_get_from(stanza);
|
2020-04-08 11:20:35 -04:00
|
|
|
if (!from) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-07 08:18:57 -04:00
|
|
|
Jid* jid = jid_create(from);
|
2021-03-25 10:07:09 -04:00
|
|
|
if (!jid) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-28 19:37:50 -05:00
|
|
|
|
|
|
|
// private message from chat room use full jid (room/nick)
|
2014-10-17 19:07:48 -04:00
|
|
|
if (muc_active(jid->barejid)) {
|
2020-02-12 07:14:19 -05:00
|
|
|
_handle_muc_private_message(stanza);
|
2015-06-24 15:53:04 -04:00
|
|
|
jid_destroy(jid);
|
2016-03-27 20:25:48 -04:00
|
|
|
return;
|
2015-05-02 20:25:33 -04:00
|
|
|
}
|
2013-01-28 19:37:50 -05:00
|
|
|
|
2015-05-04 16:18:53 -04:00
|
|
|
// standard chat message, use jid without resource
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessage* message = message_init();
|
2020-07-03 10:26:33 -04:00
|
|
|
message->is_mam = is_mam;
|
2020-07-03 11:29:13 -04:00
|
|
|
message->from_jid = jid;
|
2020-08-06 17:47:45 -04:00
|
|
|
const gchar* to = xmpp_stanza_get_to(stanza);
|
|
|
|
if (to) {
|
|
|
|
message->to_jid = jid_create(to);
|
|
|
|
} else if (is_carbon) {
|
|
|
|
// happens when receive a carbon of a self sent message
|
|
|
|
// really? maybe some servers do this, but it's not required.
|
|
|
|
message->to_jid = jid_create(from);
|
2020-07-03 11:29:13 -04:00
|
|
|
}
|
2020-07-03 10:26:33 -04:00
|
|
|
|
|
|
|
if (mucuser) {
|
|
|
|
message->type = PROF_MSG_TYPE_MUCPM;
|
|
|
|
} else {
|
|
|
|
message->type = PROF_MSG_TYPE_CHAT;
|
|
|
|
}
|
2020-04-11 17:56:01 -04:00
|
|
|
|
2020-02-10 07:19:54 -05:00
|
|
|
// message stanza id
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* id = xmpp_stanza_get_id(stanza);
|
2020-02-10 07:19:54 -05:00
|
|
|
if (id) {
|
|
|
|
message->id = strdup(id);
|
|
|
|
}
|
|
|
|
|
2020-07-23 08:21:27 -04:00
|
|
|
if (is_mam) {
|
|
|
|
// MAM has XEP-0359 stanza-id as <result id="">
|
|
|
|
if (result_id) {
|
|
|
|
message->stanzaid = strdup(result_id);
|
|
|
|
} else {
|
|
|
|
log_warning("MAM received with no result id");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// live messages use XEP-0359 <stanza-id>
|
|
|
|
char* stanzaid = NULL;
|
2020-09-30 13:34:00 -04:00
|
|
|
xmpp_stanza_t* stanzaidst = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_STANZA_ID, STANZA_NS_STABLE_ID);
|
2020-07-23 08:21:27 -04:00
|
|
|
if (stanzaidst) {
|
|
|
|
stanzaid = (char*)xmpp_stanza_get_attribute(stanzaidst, STANZA_ATTR_ID);
|
|
|
|
if (stanzaid) {
|
|
|
|
message->stanzaid = strdup(stanzaid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 10:26:33 -04:00
|
|
|
// replace id for XEP-0308: Last Message Correction
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* replace_id_stanza = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_LAST_MESSAGE_CORRECTION);
|
2020-02-10 07:19:54 -05:00
|
|
|
if (replace_id_stanza) {
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* replace_id = xmpp_stanza_get_id(replace_id_stanza);
|
2020-02-10 07:19:54 -05:00
|
|
|
if (replace_id) {
|
|
|
|
message->replace_id = strdup(replace_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 15:13:31 -05:00
|
|
|
if (timestamp) {
|
|
|
|
// timestamp provided outside like in a <forwarded> by MAM
|
|
|
|
message->timestamp = timestamp;
|
|
|
|
} else {
|
|
|
|
// timestamp in the message stanza or use time of receival (now)
|
|
|
|
message->timestamp = stanza_get_delay(stanza);
|
|
|
|
if (!message->timestamp) {
|
|
|
|
message->timestamp = g_date_time_new_now_local();
|
|
|
|
}
|
2020-03-19 08:38:17 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
if (body) {
|
|
|
|
message->body = xmpp_stanza_get_text(body);
|
2019-02-28 21:50:23 -05:00
|
|
|
}
|
2015-05-02 20:25:33 -04:00
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
#ifdef HAVE_OMEMO
|
2020-07-03 10:26:33 -04:00
|
|
|
// check omemo encryption
|
2019-06-17 00:23:40 -04:00
|
|
|
message->plain = omemo_receive_message(stanza, &message->trusted);
|
|
|
|
if (message->plain != NULL) {
|
|
|
|
message->enc = PROF_MSG_ENC_OMEMO;
|
|
|
|
}
|
|
|
|
#endif
|
2013-01-28 19:37:50 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* encrypted = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED);
|
2019-06-17 00:23:40 -04:00
|
|
|
if (encrypted) {
|
|
|
|
message->encrypted = xmpp_stanza_get_text(encrypted);
|
|
|
|
}
|
2019-02-28 21:50:23 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* ox = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_OPENPGP_0);
|
2020-07-03 10:26:33 -04:00
|
|
|
if (ox) {
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_ox_chat(stanza, message, FALSE);
|
2020-06-21 03:43:42 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
if (message->plain || message->body || message->encrypted) {
|
2020-07-03 11:29:13 -04:00
|
|
|
if (is_carbon) {
|
2020-07-07 08:18:57 -04:00
|
|
|
char* mybarejid = connection_get_barejid();
|
2020-07-03 11:29:13 -04:00
|
|
|
|
|
|
|
// if we are the recipient, treat as standard incoming message
|
2020-07-03 12:04:07 -04:00
|
|
|
if (g_strcmp0(mybarejid, message->to_jid->barejid) == 0) {
|
2020-07-03 11:29:13 -04:00
|
|
|
sv_ev_incoming_carbon(message);
|
|
|
|
// else treat as a sent message
|
|
|
|
} else {
|
|
|
|
sv_ev_outgoing_carbon(message);
|
|
|
|
}
|
2019-06-17 00:23:40 -04:00
|
|
|
|
2020-07-03 11:29:13 -04:00
|
|
|
free(mybarejid);
|
|
|
|
} else {
|
|
|
|
sv_ev_incoming_message(message);
|
|
|
|
_receipt_request_handler(stanza);
|
|
|
|
}
|
2015-05-02 20:25:33 -04:00
|
|
|
}
|
2015-01-11 15:20:17 -05:00
|
|
|
|
2020-07-03 10:17:18 -04:00
|
|
|
// 0085 works only with resource
|
2020-05-21 06:24:03 -04:00
|
|
|
if (jid->resourcepart) {
|
2022-04-27 11:00:30 -04:00
|
|
|
// XEP-0085: Chat Stase Notifications
|
2020-07-03 10:17:18 -04:00
|
|
|
_handle_chat_states(stanza, jid);
|
2013-01-28 19:37:50 -05:00
|
|
|
}
|
2015-05-02 20:25:33 -04:00
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
message_free(message);
|
2015-02-23 04:47:54 -05:00
|
|
|
}
|
2022-04-27 11:00:30 -04:00
|
|
|
|
2020-07-02 09:20:17 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_ox_chat(xmpp_stanza_t* const stanza, ProfMessage* message, gboolean is_mam)
|
2020-07-02 09:20:17 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
message->enc = PROF_MSG_ENC_OX;
|
2020-07-03 10:26:33 -04:00
|
|
|
|
2020-06-30 05:10:27 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2020-09-30 13:34:00 -04:00
|
|
|
xmpp_stanza_t* ox = xmpp_stanza_get_child_by_name_and_ns(stanza, "openpgp", STANZA_NS_OPENPGP_0);
|
2021-07-01 12:08:40 -04:00
|
|
|
if (ox) {
|
2022-05-04 10:01:03 -04:00
|
|
|
gchar* decrypted = p_ox_gpg_decrypt(xmpp_stanza_get_text(ox));
|
|
|
|
if (decrypted) {
|
|
|
|
xmpp_stanza_t* decrypted_stanza = xmpp_stanza_new_from_string(connection_get_ctx(), decrypted);
|
|
|
|
if (decrypted_stanza) {
|
|
|
|
xmpp_stanza_t* p = xmpp_stanza_get_child_by_name(decrypted_stanza, "payload");
|
2021-07-01 12:08:40 -04:00
|
|
|
if (!p) {
|
2021-06-28 15:28:58 -04:00
|
|
|
log_warning("OX Stanza - no Payload");
|
|
|
|
return;
|
|
|
|
}
|
2021-07-01 12:08:40 -04:00
|
|
|
xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(p, "body");
|
|
|
|
if (!b) {
|
2022-04-27 11:00:30 -04:00
|
|
|
log_debug("OX Stanza - no body");
|
2021-06-28 15:28:58 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
message->plain = xmpp_stanza_get_text(b);
|
|
|
|
message->encrypted = xmpp_stanza_get_text(ox);
|
|
|
|
} else {
|
2022-05-04 10:01:03 -04:00
|
|
|
cons_show("Unable to decrypt OX message (XEP-0373: OpenPGP for XMPP)");
|
2021-06-28 15:28:58 -04:00
|
|
|
log_warning("OX Stanza text to stanza failed");
|
2021-03-25 10:20:53 -04:00
|
|
|
}
|
2021-06-29 14:25:50 -04:00
|
|
|
} else {
|
2022-05-04 10:01:03 -04:00
|
|
|
// get alternative text from message body
|
|
|
|
xmpp_stanza_t* b = xmpp_stanza_get_child_by_name(stanza, "body");
|
|
|
|
if (b) {
|
|
|
|
message->plain = xmpp_stanza_get_text(b);
|
|
|
|
}
|
2021-03-25 10:20:53 -04:00
|
|
|
}
|
2021-06-28 15:28:58 -04:00
|
|
|
} else {
|
|
|
|
log_warning("OX Stanza without openpgp stanza");
|
2020-06-21 03:43:42 -04:00
|
|
|
}
|
2020-06-30 05:10:27 -04:00
|
|
|
#endif // HAVE_LIBGPGME
|
2020-06-21 03:43:42 -04:00
|
|
|
}
|
|
|
|
|
2020-04-08 11:51:10 -04:00
|
|
|
static gboolean
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_mam(xmpp_stanza_t* const stanza)
|
2020-04-08 11:51:10 -04:00
|
|
|
{
|
2020-09-30 13:34:00 -04:00
|
|
|
xmpp_stanza_t* result = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_RESULT, STANZA_NS_MAM2);
|
2020-04-08 11:51:10 -04:00
|
|
|
if (!result) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* forwarded = xmpp_stanza_get_child_by_ns(result, STANZA_NS_FORWARD);
|
2020-04-08 11:51:10 -04:00
|
|
|
if (!forwarded) {
|
|
|
|
log_warning("MAM received with no forwarded element");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-07-23 08:21:27 -04:00
|
|
|
// <result xmlns='urn:xmpp:mam:2' queryid='f27' id='5d398-28273-f7382'>
|
|
|
|
// same as <stanza-id> from XEP-0359 for live messages
|
|
|
|
const char* result_id = xmpp_stanza_get_id(result);
|
|
|
|
|
2021-07-01 12:08:40 -04:00
|
|
|
GDateTime* timestamp = stanza_get_delay_from(forwarded, NULL);
|
2021-02-04 15:13:31 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* message_stanza = xmpp_stanza_get_child_by_ns(forwarded, "jabber:client");
|
2021-02-04 15:13:31 -05:00
|
|
|
|
|
|
|
_handle_chat(message_stanza, TRUE, FALSE, result_id, timestamp);
|
2020-04-08 11:51:10 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-07-02 10:48:57 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_handle_pubsub(xmpp_stanza_t* const stanza, xmpp_stanza_t* const event)
|
|
|
|
{
|
|
|
|
xmpp_stanza_t* child = xmpp_stanza_get_children(event);
|
2020-07-02 10:48:57 -04:00
|
|
|
if (child) {
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* node = xmpp_stanza_get_attribute(child, STANZA_ATTR_NODE);
|
2020-07-02 10:48:57 -04:00
|
|
|
if (node) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMessageHandler* handler = g_hash_table_lookup(pubsub_event_handlers, node);
|
2020-07-02 10:48:57 -04:00
|
|
|
if (handler) {
|
|
|
|
int keep = handler->func(stanza, handler->userdata);
|
|
|
|
if (!keep) {
|
|
|
|
g_hash_table_remove(pubsub_event_handlers, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-26 11:50:16 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_send_message_stanza(xmpp_stanza_t* const stanza)
|
2016-03-26 11:50:16 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* text;
|
2016-03-26 11:50:16 -04:00
|
|
|
size_t text_size;
|
|
|
|
xmpp_stanza_to_text(stanza, &text, &text_size);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_conn_t* conn = connection_get_conn();
|
|
|
|
char* plugin_text = plugins_on_message_stanza_send(text);
|
2016-03-26 11:50:16 -04:00
|
|
|
if (plugin_text) {
|
2016-03-26 12:44:02 -04:00
|
|
|
xmpp_send_raw_string(conn, "%s", plugin_text);
|
2016-05-01 18:41:57 -04:00
|
|
|
free(plugin_text);
|
2016-03-26 11:50:16 -04:00
|
|
|
} else {
|
2016-03-26 12:44:02 -04:00
|
|
|
xmpp_send_raw_string(conn, "%s", text);
|
2016-03-26 11:50:16 -04:00
|
|
|
}
|
2016-05-01 19:40:16 -04:00
|
|
|
xmpp_free(connection_get_ctx(), text);
|
2016-03-26 11:50:16 -04:00
|
|
|
}
|
2019-10-18 08:50:25 -04:00
|
|
|
|
2019-10-31 08:45:44 -04:00
|
|
|
/* ckeckOID = true: check origin-id
|
|
|
|
* checkOID = false: check regular id
|
|
|
|
*/
|
2019-10-18 10:12:26 -04:00
|
|
|
bool
|
2020-07-07 08:18:57 -04:00
|
|
|
message_is_sent_by_us(const ProfMessage* const message, bool checkOID)
|
|
|
|
{
|
2019-10-18 10:12:26 -04:00
|
|
|
bool ret = FALSE;
|
|
|
|
|
2019-10-18 08:50:25 -04:00
|
|
|
// we check the </origin-id> for this we calculate a hash into it so we can detect
|
|
|
|
// whether this client sent it. See connection_create_stanza_id()
|
2019-10-31 08:45:44 -04:00
|
|
|
if (message) {
|
2020-07-07 08:18:57 -04:00
|
|
|
char* tmp_id = NULL;
|
2019-10-31 08:45:44 -04:00
|
|
|
|
|
|
|
if (checkOID && message->originid != NULL) {
|
|
|
|
tmp_id = message->originid;
|
|
|
|
} else if (!checkOID && message->id != NULL) {
|
|
|
|
tmp_id = message->id;
|
|
|
|
}
|
2019-10-18 08:50:25 -04:00
|
|
|
|
2019-10-31 08:45:44 -04:00
|
|
|
if (tmp_id != NULL) {
|
2021-04-14 16:47:58 -04:00
|
|
|
gsize tmp_len = strlen(tmp_id);
|
2019-10-18 10:12:26 -04:00
|
|
|
|
2021-04-14 16:47:58 -04:00
|
|
|
// our client sents at CON_RAND_ID_LEN + identifier
|
|
|
|
if (tmp_len > CON_RAND_ID_LEN) {
|
|
|
|
char* uuid = g_strndup(tmp_id, CON_RAND_ID_LEN);
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* prof_identifier = connection_get_profanity_identifier();
|
2019-10-18 10:12:26 -04:00
|
|
|
|
2021-04-14 16:47:58 -04:00
|
|
|
gchar* hmac = g_compute_hmac_for_string(G_CHECKSUM_SHA1,
|
2020-07-07 08:18:57 -04:00
|
|
|
(guchar*)prof_identifier, strlen(prof_identifier),
|
|
|
|
uuid, strlen(uuid));
|
2019-10-19 02:18:37 -04:00
|
|
|
|
2021-04-14 16:47:58 -04:00
|
|
|
if (g_strcmp0(&tmp_id[CON_RAND_ID_LEN], hmac) == 0) {
|
2019-10-31 08:45:44 -04:00
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(uuid);
|
|
|
|
g_free(hmac);
|
|
|
|
}
|
2019-10-18 08:50:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
return ret;
|
2019-10-18 08:50:25 -04:00
|
|
|
}
|
2020-06-21 03:43:42 -04:00
|
|
|
|
2020-06-30 05:10:27 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2020-07-02 09:21:54 -04:00
|
|
|
static xmpp_stanza_t*
|
2022-05-04 08:26:26 -04:00
|
|
|
_ox_openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const text)
|
2020-07-02 09:20:17 -04:00
|
|
|
{
|
|
|
|
time_t now = time(NULL);
|
|
|
|
struct tm* tm = localtime(&now);
|
|
|
|
char buf[255];
|
|
|
|
strftime(buf, sizeof(buf), "%FT%T%z", tm);
|
|
|
|
|
2022-04-30 16:10:21 -04:00
|
|
|
// build rpad
|
|
|
|
int randnr = (rand() % 100) + 1;
|
|
|
|
char rpad_data[randnr];
|
|
|
|
for (int i = 0; i < randnr; i++) {
|
|
|
|
int rchar = (rand() % 52) + 65;
|
|
|
|
rpad_data[i] = rchar;
|
2020-06-21 03:43:42 -04:00
|
|
|
}
|
2020-07-07 08:18:57 -04:00
|
|
|
rpad_data[randnr - 1] = '\0';
|
2020-06-21 03:43:42 -04:00
|
|
|
|
|
|
|
// signcrypt
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* signcrypt = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_name(signcrypt, "signcrypt");
|
|
|
|
xmpp_stanza_set_ns(signcrypt, "urn:xmpp:openpgp:0");
|
|
|
|
// to
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* s_to = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_name(s_to, "to");
|
|
|
|
xmpp_stanza_set_attribute(s_to, "jid", to);
|
|
|
|
// time
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* time = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_name(time, "time");
|
|
|
|
xmpp_stanza_set_attribute(time, "stamp", buf);
|
|
|
|
xmpp_stanza_set_name(time, "time");
|
|
|
|
// rpad
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* rpad = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_name(rpad, "rpad");
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* rpad_text = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_text(rpad_text, rpad_data);
|
|
|
|
// payload
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* payload = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_name(payload, "payload");
|
|
|
|
// body
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* body = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_name(body, "body");
|
|
|
|
xmpp_stanza_set_ns(body, "jabber:client");
|
|
|
|
// text
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_t* body_text = xmpp_stanza_new(ctx);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_set_text(body_text, text);
|
2020-07-07 08:18:57 -04:00
|
|
|
xmpp_stanza_add_child(signcrypt, s_to);
|
|
|
|
xmpp_stanza_add_child(signcrypt, time);
|
|
|
|
xmpp_stanza_add_child(signcrypt, rpad);
|
|
|
|
xmpp_stanza_add_child(rpad, rpad_text);
|
|
|
|
xmpp_stanza_add_child(signcrypt, payload);
|
2020-06-21 03:43:42 -04:00
|
|
|
xmpp_stanza_add_child(payload, body);
|
|
|
|
xmpp_stanza_add_child(body, body_text);
|
|
|
|
|
|
|
|
xmpp_stanza_release(body_text);
|
|
|
|
xmpp_stanza_release(body);
|
|
|
|
xmpp_stanza_release(rpad_text);
|
|
|
|
xmpp_stanza_release(rpad);
|
|
|
|
xmpp_stanza_release(time);
|
|
|
|
xmpp_stanza_release(s_to);
|
|
|
|
|
|
|
|
return signcrypt;
|
|
|
|
}
|
2020-06-30 05:10:27 -04:00
|
|
|
#endif // HAVE_LIBGPGME
|
2021-03-12 06:55:19 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
message_request_voice(const char* const roomjid)
|
|
|
|
{
|
|
|
|
xmpp_ctx_t* const ctx = connection_get_ctx();
|
|
|
|
xmpp_stanza_t* stanza = stanza_request_voice(ctx, roomjid);
|
|
|
|
|
|
|
|
log_debug("Requesting voice in %s", roomjid);
|
|
|
|
|
|
|
|
_send_message_stanza(stanza);
|
|
|
|
xmpp_stanza_release(stanza);
|
|
|
|
}
|
2021-06-09 14:14:57 -04:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_handle_jingle_message(xmpp_stanza_t* const stanza)
|
|
|
|
{
|
|
|
|
xmpp_stanza_t* propose = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_PROPOSE, STANZA_NS_JINGLE_MESSAGE);
|
|
|
|
|
|
|
|
if (propose) {
|
|
|
|
xmpp_stanza_t* description = xmpp_stanza_get_child_by_ns(propose, STANZA_NS_JINGLE_RTP);
|
|
|
|
if (description) {
|
|
|
|
const char* const from = xmpp_stanza_get_from(stanza);
|
|
|
|
cons_show("Ring ring: %s is trying to call you", from);
|
|
|
|
cons_alert(NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-07-01 12:02:03 -04:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_should_ignore_based_on_silence(xmpp_stanza_t* const stanza)
|
|
|
|
{
|
|
|
|
if (prefs_get_boolean(PREF_SILENCE_NON_ROSTER)) {
|
|
|
|
const char* const from = xmpp_stanza_get_from(stanza);
|
|
|
|
Jid* from_jid = jid_create(from);
|
|
|
|
PContact contact = roster_get_contact(from_jid->barejid);
|
|
|
|
jid_destroy(from_jid);
|
|
|
|
if (!contact) {
|
|
|
|
log_debug("[Silence] Ignoring message from: %s", from);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|