2014-01-05 15:52:45 -05:00
|
|
|
/*
|
|
|
|
* server_events.c
|
2019-11-13 06:11:05 -05:00
|
|
|
* vim: expandtab:ts=4:sts=4:sw=4
|
2014-01-05 15:52:45 -05:00
|
|
|
*
|
2019-01-22 05:31:45 -05:00
|
|
|
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
2021-01-08 10:36:30 -05:00
|
|
|
* Copyright (C) 2019 - 2021 Michael Vetter <jubalh@iodoru.org>
|
2014-01-05 15:52:45 -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/>.
|
2014-01-05 15:52:45 -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.
|
|
|
|
*
|
2014-01-05 15:52:45 -05:00
|
|
|
*/
|
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#include "config.h"
|
2015-10-31 19:38:08 -04:00
|
|
|
|
2020-07-07 03:43:28 -04:00
|
|
|
#include <string.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2014-01-05 16:48:04 -05:00
|
|
|
|
2021-03-11 16:40:19 -05:00
|
|
|
#include "config/accounts.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "profanity.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "database.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "config/preferences.h"
|
|
|
|
#include "config/tlscerts.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "config/account.h"
|
|
|
|
#include "config/scripts.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "event/client_events.h"
|
2019-05-19 16:22:58 -04:00
|
|
|
#include "event/common.h"
|
2016-02-14 17:28:55 -05:00
|
|
|
#include "plugins/plugins.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "ui/window_list.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "tools/bookmark_ignore.h"
|
|
|
|
#include "xmpp/xmpp.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "xmpp/muc.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "xmpp/chat_session.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "xmpp/roster_list.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "xmpp/avatar.h"
|
2014-01-19 12:51:32 -05:00
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#ifdef HAVE_LIBOTR
|
2014-02-12 17:19:21 -05:00
|
|
|
#include "otr/otr.h"
|
2014-01-11 21:15:16 -05:00
|
|
|
#endif
|
2016-07-24 10:43:51 -04:00
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2015-05-07 17:22:28 -04:00
|
|
|
#include "pgp/gpg.h"
|
|
|
|
#endif
|
2014-01-05 15:52:45 -05:00
|
|
|
|
2019-03-01 12:41:20 -05:00
|
|
|
#ifdef HAVE_OMEMO
|
|
|
|
#include "omemo/omemo.h"
|
|
|
|
#endif
|
|
|
|
|
2014-04-06 16:35:17 -04:00
|
|
|
#include "ui/ui.h"
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
static void _clean_incoming_message(ProfMessage* message);
|
|
|
|
static void _sv_ev_incoming_plain(ProfChatWin* chatwin, gboolean new_win, ProfMessage* message, gboolean logit);
|
2019-11-12 08:12:10 -05:00
|
|
|
|
2014-01-05 15:58:19 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_login_account_success(char* account_name, gboolean secured)
|
2014-01-05 15:58:19 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfAccount* account = accounts_get_account(account_name);
|
2014-04-07 15:41:06 -04:00
|
|
|
|
2020-05-24 07:31:24 -04:00
|
|
|
bookmark_ignore_on_connect(account->jid);
|
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#ifdef HAVE_LIBOTR
|
2014-01-11 10:48:22 -05:00
|
|
|
otr_on_connect(account);
|
2014-01-11 21:15:16 -05:00
|
|
|
#endif
|
2014-01-05 15:58:19 -05:00
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2015-06-23 18:29:10 -04:00
|
|
|
p_gpg_on_connect(account->jid);
|
|
|
|
#endif
|
|
|
|
|
2019-03-01 12:41:20 -05:00
|
|
|
#ifdef HAVE_OMEMO
|
|
|
|
omemo_on_connect(account);
|
|
|
|
#endif
|
|
|
|
|
2020-03-23 07:18:25 -04:00
|
|
|
log_database_init(account);
|
|
|
|
|
2019-12-18 04:14:46 -05:00
|
|
|
avatar_pep_subscribe();
|
|
|
|
|
2015-10-13 19:23:12 -04:00
|
|
|
ui_handle_login_account_success(account, secured);
|
2014-04-07 15:41:06 -04:00
|
|
|
|
2019-06-10 17:18:43 -04:00
|
|
|
// attempt to rejoin all rooms
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* rooms = muc_rooms();
|
|
|
|
GList* curr = rooms;
|
2015-05-04 17:51:15 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
char* password = muc_password(curr->data);
|
|
|
|
char* nick = muc_nick(curr->data);
|
2019-06-10 17:18:43 -04:00
|
|
|
presence_join_room(curr->data, nick, password);
|
2014-04-23 17:19:14 -04:00
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
2016-07-25 18:11:41 -04:00
|
|
|
g_list_free(rooms);
|
2014-04-23 17:19:14 -04:00
|
|
|
|
2014-04-07 15:41:06 -04:00
|
|
|
log_info("%s logged in successfully", account->jid);
|
2015-10-14 20:19:24 -04:00
|
|
|
|
2019-06-05 03:33:10 -04:00
|
|
|
// if we have been connected before
|
2020-07-07 08:18:57 -04:00
|
|
|
if (ev_was_connected_already()) {
|
2019-06-05 03:33:10 -04:00
|
|
|
cons_show("Connection re-established.");
|
|
|
|
wins_reestablished_connection();
|
|
|
|
}
|
|
|
|
|
2019-07-03 03:19:24 -04:00
|
|
|
ev_inc_connection_counter();
|
2019-06-05 03:33:10 -04:00
|
|
|
|
2015-10-14 20:19:24 -04:00
|
|
|
if (account->startscript) {
|
|
|
|
scripts_exec(account->startscript);
|
|
|
|
}
|
|
|
|
|
2014-01-22 17:22:01 -05:00
|
|
|
account_free(account);
|
2014-11-19 19:32:33 -05:00
|
|
|
}
|
2014-11-10 18:23:02 -05:00
|
|
|
|
2014-11-19 19:32:33 -05:00
|
|
|
void
|
2015-04-28 18:38:56 -04:00
|
|
|
sv_ev_roster_received(void)
|
2014-11-19 19:32:33 -05:00
|
|
|
{
|
2020-06-02 08:24:37 -04:00
|
|
|
roster_process_pending_presence();
|
|
|
|
|
2014-11-10 18:23:02 -05:00
|
|
|
if (prefs_get_boolean(PREF_ROSTER)) {
|
|
|
|
ui_show_roster();
|
|
|
|
}
|
2015-12-14 18:53:35 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* account_name = session_get_account_name();
|
2015-12-14 19:38:16 -05:00
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2015-12-14 19:38:16 -05:00
|
|
|
// check pgp key valid if specified
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfAccount* account = accounts_get_account(account_name);
|
2015-12-14 19:38:16 -05:00
|
|
|
if (account && account->pgp_keyid) {
|
2020-07-07 08:18:57 -04:00
|
|
|
char* err_str = NULL;
|
2015-12-14 19:38:16 -05:00
|
|
|
if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) {
|
2015-12-19 17:55:33 -05:00
|
|
|
cons_show_error("Invalid PGP key ID specified: %s, %s", account->pgp_keyid, err_str);
|
2015-12-14 19:38:16 -05:00
|
|
|
}
|
|
|
|
free(err_str);
|
2019-02-20 06:03:23 -05:00
|
|
|
|
2020-05-23 01:05:39 -04:00
|
|
|
// Redraw the screen after entry of the PGP secret key, but not init
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* win = wins_get_current();
|
|
|
|
char* theme = prefs_get_string(PREF_THEME);
|
2019-02-20 06:03:23 -05:00
|
|
|
win_clear(win);
|
|
|
|
theme_init(theme);
|
2020-07-02 05:31:54 -04:00
|
|
|
g_free(theme);
|
2019-02-20 06:03:23 -05:00
|
|
|
ui_resize();
|
|
|
|
ui_show_roster();
|
2015-12-14 19:38:16 -05:00
|
|
|
}
|
2016-02-13 20:49:57 -05:00
|
|
|
account_free(account);
|
2015-12-21 05:53:41 -05:00
|
|
|
#endif
|
2015-12-14 18:53:35 -05:00
|
|
|
|
|
|
|
// send initial presence
|
2015-12-14 19:38:16 -05:00
|
|
|
resource_presence_t conn_presence = accounts_get_login_presence(account_name);
|
2020-07-07 08:18:57 -04:00
|
|
|
char* last_activity_str = accounts_get_last_activity(account_name);
|
2021-03-11 16:40:19 -05:00
|
|
|
char* status_message = accounts_get_login_status(account_name);
|
2021-07-17 11:12:42 -04:00
|
|
|
int diff_secs = 0;
|
2015-12-14 18:53:35 -05:00
|
|
|
|
2021-07-17 11:12:42 -04:00
|
|
|
if (prefs_get_boolean(PREF_LASTACTIVITY) && last_activity_str) {
|
2015-12-14 18:53:35 -05:00
|
|
|
GTimeVal lasttv;
|
2020-07-07 08:18:57 -04:00
|
|
|
GDateTime* nowdt = g_date_time_new_now_utc();
|
2015-12-14 18:53:35 -05:00
|
|
|
gboolean res = g_time_val_from_iso8601(last_activity_str, &lasttv);
|
2019-08-02 09:52:49 -04:00
|
|
|
|
2015-12-14 18:53:35 -05:00
|
|
|
if (res) {
|
2020-07-07 08:18:57 -04:00
|
|
|
GDateTime* lastdt = g_date_time_new_from_timeval_utc(&lasttv);
|
2015-12-14 18:53:35 -05:00
|
|
|
GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt);
|
2019-08-02 09:52:49 -04:00
|
|
|
|
2021-07-17 11:12:42 -04:00
|
|
|
diff_secs = (diff_micros / 1000) / 1000;
|
2015-12-14 18:53:35 -05:00
|
|
|
g_date_time_unref(lastdt);
|
|
|
|
}
|
|
|
|
g_date_time_unref(nowdt);
|
|
|
|
}
|
2021-07-17 11:12:42 -04:00
|
|
|
connection_set_presence_msg(status_message);
|
|
|
|
cl_ev_presence_send(conn_presence, diff_secs);
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2021-07-17 11:11:32 -04:00
|
|
|
g_free(status_message);
|
|
|
|
g_free(last_activity_str);
|
2019-08-02 09:52:49 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
const char* fulljid = connection_get_fulljid();
|
2016-02-14 17:28:55 -05:00
|
|
|
plugins_on_connect(account_name, fulljid);
|
2014-01-05 15:58:19 -05:00
|
|
|
}
|
|
|
|
|
2019-04-08 13:09:25 -04:00
|
|
|
void
|
|
|
|
sv_ev_connection_features_received(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_OMEMO
|
|
|
|
omemo_publish_crypto_materials();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-01-05 16:04:30 -05:00
|
|
|
void
|
2015-04-28 18:38:56 -04:00
|
|
|
sv_ev_lost_connection(void)
|
2014-01-05 16:04:30 -05:00
|
|
|
{
|
|
|
|
cons_show_error("Lost connection.");
|
2016-01-03 12:23:36 -05:00
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#ifdef HAVE_LIBOTR
|
2020-07-07 08:18:57 -04:00
|
|
|
GSList* recipients = wins_get_chat_recipients();
|
|
|
|
GSList* curr = recipients;
|
2016-01-07 19:22:17 -05:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
char* barejid = curr->data;
|
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2016-01-07 19:22:17 -05:00
|
|
|
if (chatwin && otr_is_secure(barejid)) {
|
|
|
|
chatwin_otr_unsecured(chatwin);
|
|
|
|
otr_end_session(barejid);
|
|
|
|
}
|
|
|
|
curr = g_slist_next(curr);
|
|
|
|
}
|
|
|
|
if (recipients) {
|
|
|
|
g_slist_free(recipients);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-19 16:22:58 -04:00
|
|
|
ev_disconnect_cleanup();
|
2014-01-05 16:04:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-28 18:38:56 -04:00
|
|
|
sv_ev_failed_login(void)
|
2014-01-05 16:04:30 -05:00
|
|
|
{
|
|
|
|
cons_show_error("Login failed.");
|
|
|
|
log_info("Login failed");
|
2015-11-09 18:31:21 -05:00
|
|
|
tlscerts_clear_current();
|
2014-01-05 16:04:30 -05:00
|
|
|
}
|
|
|
|
|
2014-01-05 16:33:12 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_room_invite(jabber_invite_t invite_type, const char* const invitor, const char* const room,
|
|
|
|
const char* const reason, const char* const password)
|
2014-01-05 16:33:12 -05:00
|
|
|
{
|
2014-09-28 17:09:20 -04:00
|
|
|
if (!muc_active(room) && !muc_invites_contain(room)) {
|
2014-01-05 16:33:12 -05:00
|
|
|
cons_show_room_invite(invitor, room, reason);
|
2015-03-28 22:16:41 -04:00
|
|
|
muc_invites_add(room, password);
|
2014-01-05 16:33:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_room_broadcast(const char* const room_jid, const char* const message)
|
2014-01-05 16:33:12 -05:00
|
|
|
{
|
2014-09-28 17:09:20 -04:00
|
|
|
if (muc_roster_complete(room_jid)) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(room_jid);
|
2015-11-01 19:36:25 -05:00
|
|
|
if (mucwin) {
|
|
|
|
mucwin_broadcast(mucwin, message);
|
|
|
|
}
|
2014-05-05 15:13:22 -04:00
|
|
|
} else {
|
2014-09-28 17:09:20 -04:00
|
|
|
muc_pending_broadcasts_add(room_jid, message);
|
2014-05-05 15:13:22 -04:00
|
|
|
}
|
2014-01-05 16:33:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_room_subject(const char* const room, const char* const nick, const char* const subject)
|
2014-01-05 16:33:12 -05:00
|
|
|
{
|
2014-10-04 22:05:46 -04:00
|
|
|
muc_set_subject(room, subject);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(room);
|
2019-07-03 03:19:24 -04:00
|
|
|
if (mucwin && muc_roster_complete(room) && ev_is_first_connect()) {
|
2015-11-01 19:29:35 -05:00
|
|
|
mucwin_subject(mucwin, nick, subject);
|
2014-05-05 15:13:22 -04:00
|
|
|
}
|
2014-01-05 16:33:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_room_history(ProfMessage* message)
|
2014-01-05 16:33:12 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(message->from_jid->barejid);
|
2015-11-01 19:19:46 -05:00
|
|
|
if (mucwin) {
|
2019-06-05 03:56:00 -04:00
|
|
|
// if this is the first successful connection
|
2019-07-03 03:19:24 -04:00
|
|
|
if (ev_is_first_connect()) {
|
2019-06-05 03:56:00 -04:00
|
|
|
// save timestamp of last received muc message
|
|
|
|
// so we dont display, if there was no activity in channel, once we reconnect
|
2019-06-11 00:35:03 -04:00
|
|
|
if (mucwin->last_msg_timestamp) {
|
|
|
|
g_date_time_unref(mucwin->last_msg_timestamp);
|
2019-06-05 03:56:00 -04:00
|
|
|
}
|
2020-07-07 08:18:57 -04:00
|
|
|
mucwin->last_msg_timestamp = g_date_time_new_now_local();
|
2019-06-05 03:33:10 -04:00
|
|
|
}
|
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
gboolean younger = g_date_time_compare(mucwin->last_msg_timestamp, message->timestamp) < 0 ? TRUE : FALSE;
|
2020-07-07 08:18:57 -04:00
|
|
|
if (ev_is_first_connect() || younger) {
|
2020-02-19 10:57:37 -05:00
|
|
|
mucwin_history(mucwin, message);
|
2019-06-05 03:56:00 -04:00
|
|
|
}
|
2015-11-01 19:19:46 -05:00
|
|
|
}
|
2014-01-05 16:33:12 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
static void
|
|
|
|
_log_muc(ProfMessage* message)
|
2019-10-18 05:59:39 -04:00
|
|
|
{
|
|
|
|
if (message->enc == PROF_MSG_ENC_OMEMO) {
|
2020-04-11 11:11:53 -04:00
|
|
|
groupchat_log_omemo_msg_in(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
2019-10-18 05:59:39 -04:00
|
|
|
} else {
|
2020-04-11 11:11:53 -04:00
|
|
|
groupchat_log_msg_in(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
2019-10-18 05:59:39 -04:00
|
|
|
}
|
2020-04-06 12:55:20 -04:00
|
|
|
log_database_add_incoming(message);
|
2019-10-18 05:59:39 -04:00
|
|
|
}
|
|
|
|
|
2014-01-05 16:33:12 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_room_message(ProfMessage* message)
|
2014-01-05 16:33:12 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(message->from_jid->barejid);
|
2015-12-19 19:54:17 -05:00
|
|
|
if (!mucwin) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* mynick = muc_nick(mucwin->roomjid);
|
2019-03-18 14:50:28 -04:00
|
|
|
|
2019-10-19 17:24:33 -04:00
|
|
|
// only log message not coming from this client (but maybe same account, different client)
|
|
|
|
// our messages are logged when outgoing
|
2020-04-11 11:11:53 -04:00
|
|
|
if (!(g_strcmp0(mynick, message->from_jid->resourcepart) == 0 && message_is_sent_by_us(message, TRUE))) {
|
2019-10-18 05:59:39 -04:00
|
|
|
_log_muc(message);
|
2019-03-18 14:50:28 -04:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
char* old_plain = message->plain;
|
2020-04-11 11:11:53 -04:00
|
|
|
message->plain = plugins_pre_room_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
2016-01-24 18:06:22 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
GSList* mentions = get_mentions(prefs_get_boolean(PREF_NOTIFY_MENTION_WHOLE_WORD), prefs_get_boolean(PREF_NOTIFY_MENTION_CASE_SENSITIVE), message->plain, mynick);
|
2016-04-06 20:01:27 -04:00
|
|
|
gboolean mention = g_slist_length(mentions) > 0;
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* triggers = prefs_message_get_triggers(message->plain);
|
2016-01-24 18:06:22 -05:00
|
|
|
|
2019-11-12 08:12:10 -05:00
|
|
|
_clean_incoming_message(message);
|
2020-02-21 12:46:09 -05:00
|
|
|
mucwin_incoming_msg(mucwin, message, mentions, triggers, TRUE);
|
2015-12-19 19:54:17 -05:00
|
|
|
|
2016-04-06 20:14:12 -04:00
|
|
|
g_slist_free(mentions);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = (ProfWin*)mucwin;
|
2015-12-19 19:54:17 -05:00
|
|
|
int num = wins_get_num(window);
|
2016-02-03 20:24:37 -05:00
|
|
|
gboolean is_current = FALSE;
|
2015-12-19 19:54:17 -05:00
|
|
|
|
|
|
|
// currently in groupchat window
|
|
|
|
if (wins_is_current(window)) {
|
2016-02-03 20:24:37 -05:00
|
|
|
is_current = TRUE;
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_active(num, WIN_MUC, mucwin->roomjid);
|
2015-12-19 19:54:17 -05:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
if ((g_strcmp0(mynick, message->from_jid->resourcepart) != 0) && (prefs_get_boolean(PREF_BEEP))) {
|
2016-02-03 20:24:37 -05:00
|
|
|
beep();
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
// not currently on groupchat window
|
2015-12-19 19:54:17 -05:00
|
|
|
} else {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_new(num, WIN_MUC, mucwin->roomjid);
|
2016-01-24 18:47:17 -05:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
if ((g_strcmp0(mynick, message->from_jid->resourcepart) != 0) && (prefs_get_boolean(PREF_FLASH))) {
|
2015-12-19 19:54:17 -05:00
|
|
|
flash();
|
|
|
|
}
|
|
|
|
|
2020-07-09 10:11:06 -04:00
|
|
|
cons_show_incoming_room_message(message->from_jid->resourcepart, mucwin->roomjid, num, mention, triggers, mucwin->unread, window);
|
2016-02-03 20:24:37 -05:00
|
|
|
|
2015-12-19 19:54:17 -05:00
|
|
|
mucwin->unread++;
|
2016-01-24 19:19:26 -05:00
|
|
|
|
|
|
|
if (mention) {
|
|
|
|
mucwin->unread_mentions = TRUE;
|
|
|
|
}
|
|
|
|
if (triggers) {
|
|
|
|
mucwin->unread_triggers = TRUE;
|
|
|
|
}
|
2015-12-19 19:54:17 -05:00
|
|
|
}
|
|
|
|
|
2019-06-05 03:33:10 -04:00
|
|
|
// save timestamp of last received muc message
|
2019-06-11 00:35:03 -04:00
|
|
|
if (mucwin->last_msg_timestamp) {
|
|
|
|
g_date_time_unref(mucwin->last_msg_timestamp);
|
2019-06-05 03:33:10 -04:00
|
|
|
}
|
2020-07-07 08:18:57 -04:00
|
|
|
mucwin->last_msg_timestamp = g_date_time_new_now_local();
|
2019-06-05 03:33:10 -04:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
if (prefs_do_room_notify(is_current, mucwin->roomjid, mynick, message->from_jid->resourcepart, message->plain, mention, triggers != NULL)) {
|
2020-07-07 08:18:57 -04:00
|
|
|
Jid* jidp = jid_create(mucwin->roomjid);
|
2021-03-25 11:47:35 -04:00
|
|
|
if (jidp) {
|
|
|
|
notify_room_message(message->from_jid->resourcepart, jidp->localpart, num, message->plain);
|
|
|
|
jid_destroy(jidp);
|
|
|
|
}
|
2016-02-03 20:24:37 -05:00
|
|
|
}
|
|
|
|
|
2016-01-24 18:47:17 -05:00
|
|
|
if (triggers) {
|
|
|
|
g_list_free_full(triggers, free);
|
|
|
|
}
|
|
|
|
|
2016-01-01 21:41:51 -05:00
|
|
|
rosterwin_roster();
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
plugins_post_room_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
2019-06-17 00:23:40 -04:00
|
|
|
free(message->plain);
|
|
|
|
message->plain = old_plain;
|
2014-01-05 16:33:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_incoming_private_message(ProfMessage* message)
|
2014-12-10 17:23:33 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* old_plain = message->plain;
|
2020-04-11 11:11:53 -04:00
|
|
|
message->plain = plugins_pre_priv_message_display(message->from_jid->fulljid, message->plain);
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPrivateWin* privatewin = wins_get_private(message->from_jid->fulljid);
|
2015-11-08 17:01:51 -05:00
|
|
|
if (privatewin == NULL) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = wins_new_private(message->from_jid->fulljid);
|
2015-11-08 17:01:51 -05:00
|
|
|
privatewin = (ProfPrivateWin*)window;
|
|
|
|
}
|
2019-11-12 08:12:10 -05:00
|
|
|
|
|
|
|
_clean_incoming_message(message);
|
2019-06-17 00:23:40 -04:00
|
|
|
privwin_incoming_msg(privatewin, message);
|
2020-04-08 06:21:07 -04:00
|
|
|
log_database_add_incoming(message);
|
2019-10-28 18:36:42 -04:00
|
|
|
chat_log_msg_in(message);
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
plugins_post_priv_message_display(message->from_jid->fulljid, message->plain);
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
free(message->plain);
|
|
|
|
message->plain = old_plain;
|
2016-01-23 19:33:24 -05:00
|
|
|
rosterwin_roster();
|
2015-11-08 17:01:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_delayed_private_message(ProfMessage* message)
|
2015-11-08 17:01:51 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
char* old_plain = message->plain;
|
2020-04-11 11:11:53 -04:00
|
|
|
message->plain = plugins_pre_priv_message_display(message->from_jid->fulljid, message->plain);
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPrivateWin* privatewin = wins_get_private(message->from_jid->fulljid);
|
2015-11-08 17:01:51 -05:00
|
|
|
if (privatewin == NULL) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = wins_new_private(message->from_jid->fulljid);
|
2015-11-08 17:01:51 -05:00
|
|
|
privatewin = (ProfPrivateWin*)window;
|
|
|
|
}
|
2019-11-12 08:12:10 -05:00
|
|
|
|
|
|
|
_clean_incoming_message(message);
|
2019-06-17 00:23:40 -04:00
|
|
|
privwin_incoming_msg(privatewin, message);
|
2019-10-29 05:52:11 -04:00
|
|
|
chat_log_msg_in(message);
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2020-04-11 11:11:53 -04:00
|
|
|
plugins_post_priv_message_display(message->from_jid->fulljid, message->plain);
|
2016-02-14 17:28:55 -05:00
|
|
|
|
2019-06-17 00:23:40 -04:00
|
|
|
free(message->plain);
|
|
|
|
message->plain = old_plain;
|
2014-12-10 17:23:33 -05:00
|
|
|
}
|
|
|
|
|
2015-02-02 05:10:05 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
sv_ev_outgoing_carbon(ProfMessage* message)
|
2015-03-14 19:10:51 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(message->to_jid->barejid);
|
2015-10-27 19:25:18 -04:00
|
|
|
if (!chatwin) {
|
2020-05-27 16:06:04 -04:00
|
|
|
chatwin = chatwin_new(message->to_jid->barejid);
|
2015-10-27 19:25:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
chat_state_active(chatwin->state);
|
|
|
|
|
2019-06-21 07:49:17 -04:00
|
|
|
if (message->enc == PROF_MSG_ENC_OMEMO) {
|
|
|
|
chatwin_outgoing_carbon(chatwin, message);
|
|
|
|
} else if (message->encrypted) {
|
2020-06-14 06:12:29 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2019-06-21 07:49:17 -04:00
|
|
|
message->plain = p_gpg_decrypt(message->encrypted);
|
|
|
|
if (message->plain) {
|
|
|
|
message->enc = PROF_MSG_ENC_PGP;
|
|
|
|
chatwin_outgoing_carbon(chatwin, message);
|
2019-03-27 08:37:09 -04:00
|
|
|
} else {
|
2019-06-21 07:49:17 -04:00
|
|
|
if (!message->body) {
|
|
|
|
log_error("Couldn't decrypt GPG message and body was empty");
|
|
|
|
return;
|
|
|
|
}
|
2020-03-27 19:04:41 -04:00
|
|
|
message->enc = PROF_MSG_ENC_NONE;
|
2019-06-21 07:49:17 -04:00
|
|
|
message->plain = strdup(message->body);
|
|
|
|
chatwin_outgoing_carbon(chatwin, message);
|
2019-03-27 08:37:09 -04:00
|
|
|
}
|
2020-06-14 06:12:29 -04:00
|
|
|
#endif
|
2019-03-27 08:37:09 -04:00
|
|
|
} else {
|
2020-03-27 19:04:41 -04:00
|
|
|
message->enc = PROF_MSG_ENC_NONE;
|
2019-06-21 07:49:17 -04:00
|
|
|
message->plain = strdup(message->body);
|
|
|
|
chatwin_outgoing_carbon(chatwin, message);
|
2019-03-27 08:37:09 -04:00
|
|
|
}
|
2020-12-08 06:26:36 -05:00
|
|
|
|
|
|
|
if (message->plain) {
|
|
|
|
if (message->type == PROF_MSG_TYPE_MUCPM) {
|
|
|
|
// MUC PM, should have resource (nick) in filename
|
|
|
|
chat_log_msg_out(message->to_jid->barejid, message->plain, message->from_jid->resourcepart);
|
|
|
|
} else {
|
|
|
|
chat_log_msg_out(message->to_jid->barejid, message->plain, NULL);
|
|
|
|
}
|
|
|
|
log_database_add_incoming(message);
|
|
|
|
}
|
2019-03-27 08:37:09 -04:00
|
|
|
return;
|
2015-06-21 15:08:46 -04:00
|
|
|
}
|
|
|
|
|
2015-08-26 18:15:10 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_sv_ev_incoming_pgp(ProfChatWin* chatwin, gboolean new_win, ProfMessage* message, gboolean logit)
|
2015-08-26 18:15:10 -04:00
|
|
|
{
|
2020-06-14 06:12:29 -04:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2019-06-17 00:23:40 -04:00
|
|
|
message->plain = p_gpg_decrypt(message->encrypted);
|
|
|
|
if (message->plain) {
|
|
|
|
message->enc = PROF_MSG_ENC_PGP;
|
2019-11-12 08:12:10 -05:00
|
|
|
_clean_incoming_message(message);
|
2019-06-17 00:23:40 -04:00
|
|
|
chatwin_incoming_msg(chatwin, message, new_win);
|
2020-04-08 06:21:07 -04:00
|
|
|
log_database_add_incoming(message);
|
2019-10-29 06:46:01 -04:00
|
|
|
if (logit) {
|
|
|
|
chat_log_pgp_msg_in(message);
|
|
|
|
}
|
2015-08-29 20:32:13 -04:00
|
|
|
chatwin->pgp_recv = TRUE;
|
2019-06-17 00:23:40 -04:00
|
|
|
p_gpg_free_decrypted(message->plain);
|
|
|
|
message->plain = NULL;
|
2015-08-26 18:15:10 -04:00
|
|
|
} else {
|
2019-06-21 07:49:17 -04:00
|
|
|
if (!message->body) {
|
|
|
|
log_error("Couldn't decrypt GPG message and body was empty");
|
|
|
|
return;
|
|
|
|
}
|
2020-03-27 19:04:41 -04:00
|
|
|
message->enc = PROF_MSG_ENC_NONE;
|
2019-06-21 07:49:17 -04:00
|
|
|
message->plain = strdup(message->body);
|
2019-11-12 08:12:10 -05:00
|
|
|
_clean_incoming_message(message);
|
2019-06-17 00:23:40 -04:00
|
|
|
chatwin_incoming_msg(chatwin, message, new_win);
|
2020-04-08 06:21:07 -04:00
|
|
|
log_database_add_incoming(message);
|
2019-06-17 00:23:40 -04:00
|
|
|
chat_log_msg_in(message);
|
2015-08-29 20:32:13 -04:00
|
|
|
chatwin->pgp_recv = FALSE;
|
2015-08-26 18:15:10 -04:00
|
|
|
}
|
|
|
|
#endif
|
2020-06-14 06:12:29 -04:00
|
|
|
}
|
2015-08-26 18:15:10 -04:00
|
|
|
|
2020-06-21 03:43:42 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_sv_ev_incoming_ox(ProfChatWin* chatwin, gboolean new_win, ProfMessage* message, gboolean logit)
|
2020-06-21 03:43:42 -04:00
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBGPGME
|
2020-07-07 08:18:57 -04:00
|
|
|
//_clean_incoming_message(message);
|
|
|
|
chatwin_incoming_msg(chatwin, message, new_win);
|
|
|
|
log_database_add_incoming(message);
|
|
|
|
if (logit) {
|
|
|
|
chat_log_pgp_msg_in(message);
|
|
|
|
}
|
|
|
|
chatwin->pgp_recv = TRUE;
|
|
|
|
//p_gpg_free_decrypted(message->plain);
|
|
|
|
message->plain = NULL;
|
2020-06-21 03:43:42 -04:00
|
|
|
#endif
|
2020-06-30 05:10:27 -04:00
|
|
|
}
|
2020-06-21 03:43:42 -04:00
|
|
|
|
2015-08-26 18:15:10 -04:00
|
|
|
static void
|
2020-07-07 08:18:57 -04:00
|
|
|
_sv_ev_incoming_otr(ProfChatWin* chatwin, gboolean new_win, ProfMessage* message)
|
2015-08-26 18:15:10 -04:00
|
|
|
{
|
2020-06-14 06:12:29 -04:00
|
|
|
#ifdef HAVE_LIBOTR
|
2015-08-26 18:15:10 -04:00
|
|
|
gboolean decrypted = FALSE;
|
2020-04-11 11:11:53 -04:00
|
|
|
message->plain = otr_on_message_recv(message->from_jid->barejid, message->from_jid->resourcepart, message->body, &decrypted);
|
2019-06-17 00:23:40 -04:00
|
|
|
if (message->plain) {
|
2015-08-26 19:37:48 -04:00
|
|
|
if (decrypted) {
|
2019-06-17 00:23:40 -04:00
|
|
|
message->enc = PROF_MSG_ENC_OTR;
|
2015-08-29 20:32:13 -04:00
|
|
|
chatwin->pgp_send = FALSE;
|
2015-08-26 18:15:10 -04:00
|
|
|
} else {
|
2020-03-27 19:04:41 -04:00
|
|
|
message->enc = PROF_MSG_ENC_NONE;
|
2015-08-26 18:15:10 -04:00
|
|
|
}
|
2019-06-17 00:23:40 -04:00
|
|
|
|
2019-11-12 08:12:10 -05:00
|
|
|
_clean_incoming_message(message);
|
2019-06-17 00:23:40 -04:00
|
|
|
chatwin_incoming_msg(chatwin, message, new_win);
|
|