1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Use flags in xmmp/message.c for encryption and trust

This commit is contained in:
Paul Fariello 2019-06-16 22:55:07 +02:00
parent a650ecc67d
commit 3bb3cc625d
6 changed files with 44 additions and 25 deletions

View File

@ -133,7 +133,8 @@ typedef enum {
THEME_BLACK,
THEME_BLACK_BOLD,
THEME_MAGENTA,
THEME_MAGENTA_BOLD
THEME_MAGENTA_BOLD,
THEME_NO_TRUST,
} theme_item_t;
void theme_init(const char *const theme_name);

View File

@ -268,7 +268,7 @@ sv_ev_room_subject(const char *const room, const char *const nick, const char *c
void
sv_ev_room_history(const char *const room_jid, const char *const nick,
GDateTime *timestamp, const char *const message)
GDateTime *timestamp, const char *const message, int flags)
{
ProfMucWin *mucwin = wins_get_muc(room_jid);
if (mucwin) {
@ -290,7 +290,7 @@ sv_ev_room_history(const char *const room_jid, const char *const nick,
}
void
sv_ev_room_message(const char *const room_jid, const char *const nick, const char *const message, const char *const id, gboolean omemo)
sv_ev_room_message(const char *const room_jid, const char *const nick, const char *const message, const char *const id, int flags)
{
ProfMucWin *mucwin = wins_get_muc(room_jid);
if (!mucwin) {
@ -299,7 +299,7 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
char *mynick = muc_nick(mucwin->roomjid);
if (omemo) {
if (flags & MSG_ENC_OMEMO) {
groupchat_log_omemo_msg_in(room_jid, nick, message);
} else {
groupchat_log_msg_in(room_jid, nick, message);
@ -320,8 +320,8 @@ sv_ev_room_message(const char *const room_jid, const char *const nick, const cha
GList *triggers = prefs_message_get_triggers(new_message);
if (omemo) {
mucwin_incoming_msg(mucwin, nick, new_message, id, mentions, triggers, PROF_MSG_OMEMO);
if (flags & MSG_ENC_OMEMO) {
mucwin_incoming_msg(mucwin, nick, new_message, id, mentions, triggers, flags);
} else {
mucwin_incoming_msg(mucwin, nick, new_message, id, mentions, triggers, PROF_MSG_PLAIN);
}

View File

@ -53,13 +53,6 @@
#define NO_COLOUR_FROM 8
#define NO_COLOUR_DATE 16
typedef enum {
PROF_MSG_PLAIN,
PROF_MSG_OTR,
PROF_MSG_PGP,
PROF_MSG_OMEMO
} prof_enc_t;
// core UI
void ui_init(void);
void ui_load_colours(void);

View File

@ -1048,6 +1048,11 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
const char *const from, const char *const message, prof_enc_t enc_mode)
{
char enc_char = '-';
int flags = NO_ME;
if (!trusted) {
flags != NO_TRUST;
}
switch (window->type)
{
@ -1063,11 +1068,11 @@ win_print_incoming(ProfWin *window, GDateTime *timestamp,
} else if (enc_mode == PROF_MSG_OMEMO) {
enc_char = prefs_get_omemo_char();
}
_win_printf(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
_win_printf(window, enc_char, 0, timestamp, flags, THEME_TEXT_THEM, from, "%s", message);
break;
}
case WIN_PRIVATE:
_win_printf(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, from, "%s", message);
_win_printf(window, '-', 0, timestamp, flags, THEME_TEXT_THEM, from, "%s", message);
break;
default:
assert(FALSE);
@ -1384,6 +1389,7 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim
// 3rd bit = 0/1 - eol/no eol
// 4th bit = 0/1 - color from/no color from
// 5th bit = 0/1 - color date/no date
// 6th bit = 0/1 - not trusted/trusted
gboolean me_message = FALSE;
int offset = 0;
int colour = theme_attrs(THEME_ME);
@ -1462,6 +1468,10 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim
}
}
if (flags & NO_TRUST) {
colour = theme_attrs(THEME_NO_TRUST);
}
if (!me_message) {
if (receipt && !receipt->received) {
wbkgdset(window->layout->win, theme_attrs(THEME_RECEIPT_SENT));

View File

@ -696,6 +696,7 @@ static void
_handle_groupchat(xmpp_stanza_t *const stanza)
{
xmpp_ctx_t *ctx = connection_get_ctx();
int flags = 0;
char *message = NULL;
const char *id = xmpp_stanza_get_id(stanza);
@ -748,11 +749,15 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
}
// check omemo encryption
gboolean omemo = FALSE;
gboolean trusted = FALSE;
#ifdef HAVE_OMEMO
gboolean trusted = FALSE;
message = omemo_receive_message(stanza, &trusted);
omemo = message != NULL;
if (message != NULL) {
flags |= MSG_ENC_OMEMO;
if (trusted) {
flags |= MSG_TRUSTED;
}
}
#endif
if (!message) {
@ -766,10 +771,10 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
// determine if the notifications happened whilst offline
GDateTime *timestamp = stanza_get_delay(stanza);
if (timestamp) {
sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message, omemo, trusted);
sv_ev_room_history(jid->barejid, jid->resourcepart, timestamp, message, flags);
g_date_time_unref(timestamp);
} else {
sv_ev_room_message(jid->barejid, jid->resourcepart, message, id, omemo, trusted);
sv_ev_room_message(jid->barejid, jid->resourcepart, message, id, flags);
}
xmpp_free(ctx, message);
@ -873,6 +878,7 @@ static gboolean
_handle_carbons(xmpp_stanza_t *const stanza)
{
char *message_txt = NULL;
int flags = 0;
xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
if (!carbons) {
return FALSE;
@ -907,11 +913,15 @@ _handle_carbons(xmpp_stanza_t *const stanza)
}
// check omemo encryption
gboolean omemo = FALSE;
gboolean trusted = FALSE;
#ifdef HAVE_OMEMO
gboolean trusted = FALSE;
message_txt = omemo_receive_message(message, &trusted);
omemo = message_txt != NULL;
if (message_txt != NULL) {
flags != MSG_ENC_OMEMO;
if (trusted) {
flags |= MSG_TRUSTED;
}
}
#endif
if (!message_txt) {
@ -947,11 +957,11 @@ _handle_carbons(xmpp_stanza_t *const stanza)
// if we are the recipient, treat as standard incoming message
if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) {
sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message, omemo, trusted);
sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message, flags);
// else treat as a sent message
} else {
sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message, omemo, trusted);
sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message, flags);
}
xmpp_ctx_t *ctx = connection_get_ctx();

View File

@ -35,6 +35,11 @@
#ifndef XMPP_MESSAGE_H
#define XMPP_MESSAGE_H
#define PROF_MSG_ENC_OTR 1
#define PROF_MSG_ENC_PGP 2
#define PROF_MSG_ENC_OMEMO 4
#define PROF_MSG_TRUSTED 8
typedef int(*ProfMessageCallback)(xmpp_stanza_t *const stanza, void *const userdata);
typedef void(*ProfMessageFreeCallback)(void *userdata);