Split PGP incoming and outgoing message handling
This commit is contained in:
@@ -478,7 +478,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
|
||||
|
||||
// currently viewing chat window with sender
|
||||
if (wins_is_current(window)) {
|
||||
win_print_incoming_message(window, timestamp, display_from, message, PROF_ENC_NONE);
|
||||
win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN);
|
||||
title_bar_set_typing(FALSE);
|
||||
status_bar_active(num);
|
||||
|
||||
@@ -487,7 +487,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
|
||||
privatewin->unread++;
|
||||
status_bar_new(num);
|
||||
cons_show_incoming_message(display_from, num);
|
||||
win_print_incoming_message(window, timestamp, display_from, message, PROF_ENC_NONE);
|
||||
win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN);
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH)) {
|
||||
flash();
|
||||
@@ -713,7 +713,7 @@ ui_close_connected_win(int index)
|
||||
ProfChatWin *chatwin = (ProfChatWin*) window;
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
#ifdef HAVE_LIBOTR
|
||||
if (chatwin->enc_mode == PROF_ENC_OTR) {
|
||||
if (chatwin->is_otr) {
|
||||
otr_end_session(chatwin->barejid);
|
||||
}
|
||||
#endif
|
||||
@@ -895,7 +895,7 @@ ui_gone_secure(const char * const barejid, gboolean trusted)
|
||||
chatwin = (ProfChatWin*)window;
|
||||
}
|
||||
|
||||
chatwin->enc_mode = PROF_ENC_OTR;
|
||||
chatwin->is_otr = TRUE;
|
||||
chatwin->otr_is_trusted = trusted;
|
||||
if (trusted) {
|
||||
win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted).");
|
||||
@@ -923,7 +923,7 @@ ui_gone_insecure(const char * const barejid)
|
||||
{
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin) {
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
chatwin->is_otr = FALSE;
|
||||
chatwin->otr_is_trusted = FALSE;
|
||||
|
||||
ProfWin *window = (ProfWin*)chatwin;
|
||||
@@ -1042,7 +1042,7 @@ ui_trust(const char * const barejid)
|
||||
{
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin) {
|
||||
chatwin->enc_mode = PROF_ENC_OTR;
|
||||
chatwin->is_otr = TRUE;
|
||||
chatwin->otr_is_trusted = TRUE;
|
||||
|
||||
ProfWin *window = (ProfWin*)chatwin;
|
||||
@@ -1058,7 +1058,7 @@ ui_untrust(const char * const barejid)
|
||||
{
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (chatwin) {
|
||||
chatwin->enc_mode = PROF_ENC_OTR;
|
||||
chatwin->is_otr = TRUE;
|
||||
chatwin->otr_is_trusted = FALSE;
|
||||
|
||||
ProfWin *window = (ProfWin*)chatwin;
|
||||
@@ -1290,9 +1290,9 @@ void
|
||||
ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode)
|
||||
{
|
||||
char enc_char = '-';
|
||||
if (enc_mode == PROF_ENC_OTR) {
|
||||
if (enc_mode == PROF_MSG_OTR) {
|
||||
enc_char = prefs_get_otr_char();
|
||||
} else if (enc_mode == PROF_ENC_PGP) {
|
||||
} else if (enc_mode == PROF_MSG_PGP) {
|
||||
enc_char = prefs_get_pgp_char();
|
||||
}
|
||||
|
||||
|
||||
@@ -250,70 +250,73 @@ _show_privacy(ProfChatWin *chatwin)
|
||||
int trusted_attrs = theme_attrs(THEME_TITLE_TRUSTED);
|
||||
int untrusted_attrs = theme_attrs(THEME_TITLE_UNTRUSTED);
|
||||
|
||||
switch (chatwin->enc_mode) {
|
||||
case PROF_ENC_NONE:
|
||||
if (prefs_get_boolean(PREF_ENC_WARN)) {
|
||||
wprintw(win, " ");
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "[");
|
||||
wattroff(win, bracket_attrs);
|
||||
wattron(win, unencrypted_attrs);
|
||||
wprintw(win, "unencrypted");
|
||||
wattroff(win, unencrypted_attrs);
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "]");
|
||||
wattroff(win, bracket_attrs);
|
||||
}
|
||||
break;
|
||||
|
||||
case PROF_ENC_OTR:
|
||||
if (chatwin->is_otr) {
|
||||
wprintw(win, " ");
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "[");
|
||||
wattroff(win, bracket_attrs);
|
||||
wattron(win, encrypted_attrs);
|
||||
wprintw(win, "OTR");
|
||||
wattroff(win, encrypted_attrs);
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "]");
|
||||
wattroff(win, bracket_attrs);
|
||||
if (chatwin->otr_is_trusted) {
|
||||
wprintw(win, " ");
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "[");
|
||||
wattroff(win, bracket_attrs);
|
||||
wattron(win, encrypted_attrs);
|
||||
wprintw(win, "OTR");
|
||||
wattroff(win, encrypted_attrs);
|
||||
wattron(win, trusted_attrs);
|
||||
wprintw(win, "trusted");
|
||||
wattroff(win, trusted_attrs);
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "]");
|
||||
wattroff(win, bracket_attrs);
|
||||
if (chatwin->otr_is_trusted) {
|
||||
wprintw(win, " ");
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "[");
|
||||
wattroff(win, bracket_attrs);
|
||||
wattron(win, trusted_attrs);
|
||||
wprintw(win, "trusted");
|
||||
wattroff(win, trusted_attrs);
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "]");
|
||||
wattroff(win, bracket_attrs);
|
||||
} else {
|
||||
wprintw(win, " ");
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "[");
|
||||
wattroff(win, bracket_attrs);
|
||||
wattron(win, untrusted_attrs);
|
||||
wprintw(win, "untrusted");
|
||||
wattroff(win, untrusted_attrs);
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "]");
|
||||
wattroff(win, bracket_attrs);
|
||||
}
|
||||
break;
|
||||
|
||||
case PROF_ENC_PGP:
|
||||
} else {
|
||||
wprintw(win, " ");
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "[");
|
||||
wattroff(win, bracket_attrs);
|
||||
wattron(win, encrypted_attrs);
|
||||
wprintw(win, "PGP");
|
||||
wattroff(win, encrypted_attrs);
|
||||
wattron(win, untrusted_attrs);
|
||||
wprintw(win, "untrusted");
|
||||
wattroff(win, untrusted_attrs);
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "]");
|
||||
wattroff(win, bracket_attrs);
|
||||
break;
|
||||
}
|
||||
} else if (chatwin->pgp_send || chatwin->pgp_recv) {
|
||||
GString *pgpmsg = g_string_new("PGP ");
|
||||
if (chatwin->pgp_send && !chatwin->pgp_recv) {
|
||||
g_string_append(pgpmsg, "send");
|
||||
} else if (!chatwin->pgp_send && chatwin->pgp_recv) {
|
||||
g_string_append(pgpmsg, "recv");
|
||||
} else {
|
||||
g_string_append(pgpmsg, "send/recv");
|
||||
}
|
||||
wprintw(win, " ");
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "[");
|
||||
wattroff(win, bracket_attrs);
|
||||
wattron(win, encrypted_attrs);
|
||||
wprintw(win, pgpmsg->str);
|
||||
wattroff(win, encrypted_attrs);
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "]");
|
||||
wattroff(win, bracket_attrs);
|
||||
g_string_free(pgpmsg, TRUE);
|
||||
} else {
|
||||
if (prefs_get_boolean(PREF_ENC_WARN)) {
|
||||
wprintw(win, " ");
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "[");
|
||||
wattroff(win, bracket_attrs);
|
||||
wattron(win, unencrypted_attrs);
|
||||
wprintw(win, "unencrypted");
|
||||
wattroff(win, unencrypted_attrs);
|
||||
wattron(win, bracket_attrs);
|
||||
wprintw(win, "]");
|
||||
wattroff(win, bracket_attrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,12 @@
|
||||
#define NO_COLOUR_FROM 8
|
||||
#define NO_COLOUR_DATE 16
|
||||
|
||||
typedef enum {
|
||||
PROF_MSG_PLAIN,
|
||||
PROF_MSG_OTR,
|
||||
PROF_MSG_PGP
|
||||
} prof_enc_t;
|
||||
|
||||
// ui startup and control
|
||||
void ui_init(void);
|
||||
void ui_load_colours(void);
|
||||
|
||||
@@ -89,12 +89,6 @@ typedef enum {
|
||||
WIN_XML
|
||||
} win_type_t;
|
||||
|
||||
typedef enum {
|
||||
PROF_ENC_NONE,
|
||||
PROF_ENC_OTR,
|
||||
PROF_ENC_PGP
|
||||
} prof_enc_t;
|
||||
|
||||
typedef struct prof_win_t {
|
||||
win_type_t type;
|
||||
ProfLayout *layout;
|
||||
@@ -109,8 +103,10 @@ typedef struct prof_chat_win_t {
|
||||
char *barejid;
|
||||
int unread;
|
||||
ChatState *state;
|
||||
prof_enc_t enc_mode;
|
||||
gboolean is_otr;
|
||||
gboolean otr_is_trusted;
|
||||
gboolean pgp_send;
|
||||
gboolean pgp_recv;
|
||||
char *resource_override;
|
||||
gboolean history_shown;
|
||||
unsigned long memcheck;
|
||||
|
||||
@@ -135,8 +135,10 @@ win_create_chat(const char * const barejid)
|
||||
|
||||
new_win->barejid = strdup(barejid);
|
||||
new_win->resource_override = NULL;
|
||||
new_win->enc_mode = PROF_ENC_NONE;
|
||||
new_win->is_otr = FALSE;
|
||||
new_win->otr_is_trusted = FALSE;
|
||||
new_win->pgp_recv = FALSE;
|
||||
new_win->pgp_send = FALSE;
|
||||
new_win->history_shown = FALSE;
|
||||
new_win->unread = 0;
|
||||
new_win->state = chat_state_new();
|
||||
@@ -884,9 +886,9 @@ win_print_incoming_message(ProfWin *window, GDateTime *timestamp,
|
||||
switch (window->type)
|
||||
{
|
||||
case WIN_CHAT:
|
||||
if (enc_mode == PROF_ENC_OTR) {
|
||||
if (enc_mode == PROF_MSG_OTR) {
|
||||
enc_char = prefs_get_otr_char();
|
||||
} else if (enc_mode == PROF_ENC_PGP) {
|
||||
} else if (enc_mode == PROF_MSG_PGP) {
|
||||
enc_char = prefs_get_pgp_char();
|
||||
}
|
||||
win_print(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message);
|
||||
|
||||
Reference in New Issue
Block a user