1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Split PGP incoming and outgoing message handling

This commit is contained in:
James Booth 2015-08-30 01:32:13 +01:00
parent 1484e94b35
commit b4722632b6
11 changed files with 142 additions and 129 deletions

View File

@ -4355,12 +4355,12 @@ cmd_pgp(ProfWin *window, const char * const command, gchar **args)
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
} }
if (chatwin->enc_mode == PROF_ENC_OTR) { if (chatwin->is_otr) {
ui_current_print_formatted_line('!', 0, "You must end the OTR session to start PGP encryption."); ui_current_print_formatted_line('!', 0, "You must end the OTR session to start PGP encryption.");
return TRUE; return TRUE;
} }
if (chatwin->enc_mode == PROF_ENC_PGP) { if (chatwin->pgp_send) {
ui_current_print_formatted_line('!', 0, "You have already started PGP encryption."); ui_current_print_formatted_line('!', 0, "You have already started PGP encryption.");
return TRUE; return TRUE;
} }
@ -4378,7 +4378,7 @@ cmd_pgp(ProfWin *window, const char * const command, gchar **args)
return TRUE; return TRUE;
} }
chatwin->enc_mode = PROF_ENC_PGP; chatwin->pgp_send = TRUE;
ui_current_print_formatted_line('!', 0, "PGP encyption enabled."); ui_current_print_formatted_line('!', 0, "PGP encyption enabled.");
return TRUE; return TRUE;
} }
@ -4396,12 +4396,12 @@ cmd_pgp(ProfWin *window, const char * const command, gchar **args)
} }
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
if (chatwin->enc_mode != PROF_ENC_PGP) { if (chatwin->pgp_send == FALSE) {
ui_current_print_formatted_line('!', 0, "PGP encryption is not currently enabled."); ui_current_print_formatted_line('!', 0, "PGP encryption is not currently enabled.");
return TRUE; return TRUE;
} }
chatwin->enc_mode = PROF_ENC_NONE; chatwin->pgp_send = FALSE;
ui_current_print_formatted_line('!', 0, "PGP encyption disabled."); ui_current_print_formatted_line('!', 0, "PGP encyption disabled.");
return TRUE; return TRUE;
} }
@ -4527,7 +4527,7 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) { if (chatwin->is_otr == FALSE) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE; return TRUE;
} }
@ -4552,12 +4552,12 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
} }
ui_ev_focus_win((ProfWin*)chatwin); ui_ev_focus_win((ProfWin*)chatwin);
if (chatwin->enc_mode == PROF_ENC_PGP) { if (chatwin->pgp_send) {
ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session."); ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session.");
return TRUE; return TRUE;
} }
if (chatwin->enc_mode == PROF_ENC_OTR) { if (chatwin->is_otr) {
ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
return TRUE; return TRUE;
} }
@ -4586,12 +4586,12 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode == PROF_ENC_PGP) { if (chatwin->pgp_send) {
ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session."); ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session.");
return TRUE; return TRUE;
} }
if (chatwin->enc_mode == PROF_ENC_OTR) { if (chatwin->is_otr) {
ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
return TRUE; return TRUE;
} }
@ -4615,7 +4615,7 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) { if (chatwin->is_otr == FALSE) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE; return TRUE;
} }
@ -4632,7 +4632,7 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) { if (chatwin->is_otr == FALSE) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE; return TRUE;
} }
@ -4649,7 +4649,7 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) { if (chatwin->is_otr == FALSE) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE; return TRUE;
} }
@ -4666,7 +4666,7 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) { if (chatwin->is_otr == FALSE) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE; return TRUE;
} }
@ -4695,7 +4695,7 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) { if (chatwin->is_otr == FALSE) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE; return TRUE;
} }
@ -4711,7 +4711,7 @@ cmd_otr(ProfWin *window, const char * const command, gchar **args)
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) { if (chatwin->is_otr == FALSE) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE; return TRUE;
} }

View File

@ -195,6 +195,12 @@ str_replace(const char *string, const char *substr,
gboolean gboolean
str_contains_str(const char * const searchstr, const char * const substr) str_contains_str(const char * const searchstr, const char * const substr)
{ {
if (!searchstr) {
return FALSE;
}
if (!substr) {
return FALSE;
}
return g_strrstr(searchstr, substr) != NULL; return g_strrstr(searchstr, substr) != NULL;
} }

View File

@ -91,20 +91,19 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
// OTR suported, PGP supported // OTR suported, PGP supported
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME #ifdef HAVE_LIBGPGME
prof_enc_t enc_mode = chatwin->enc_mode; if (chatwin->pgp_send) {
if (enc_mode == PROF_ENC_NONE || enc_mode == PROF_ENC_OTR) { char *id = message_send_chat_pgp(chatwin->barejid, msg);
chat_log_pgp_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PGP);
free(id);
} else {
gboolean handled = otr_on_message_send(chatwin, msg); gboolean handled = otr_on_message_send(chatwin, msg);
if (!handled) { if (!handled) {
char *id = message_send_chat(chatwin->barejid, msg); char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_NONE); ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN);
free(id); free(id);
} }
} else { // enc_mode = PROF_ENC_PGP
char *id = message_send_chat_pgp(chatwin->barejid, msg);
chat_log_pgp_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_PGP);
free(id);
} }
return; return;
#endif #endif
@ -117,7 +116,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
if (!handled) { if (!handled) {
char *id = message_send_chat(chatwin->barejid, msg); char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_NONE); ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN);
free(id); free(id);
} }
return; return;
@ -127,16 +126,15 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
// OTR unsupported, PGP supported // OTR unsupported, PGP supported
#ifndef HAVE_LIBOTR #ifndef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME #ifdef HAVE_LIBGPGME
prof_enc_t enc_mode = chatwin->enc_mode; if (chatwin->pgp_send) {
if (enc_mode == PROF_ENC_NONE) {
char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_NONE);
free(id);
} else if (enc_mode == PROF_ENC_PGP) {
char *id = message_send_chat_pgp(chatwin->barejid, msg); char *id = message_send_chat_pgp(chatwin->barejid, msg);
chat_log_pgp_msg_out(chatwin->barejid, msg); chat_log_pgp_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_PGP); ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PGP);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN);
free(id); free(id);
} }
return; return;
@ -148,7 +146,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
#ifndef HAVE_LIBGPGME #ifndef HAVE_LIBGPGME
char *id = message_send_chat(chatwin->barejid, msg); char *id = message_send_chat(chatwin->barejid, msg);
chat_log_msg_out(chatwin->barejid, msg); chat_log_msg_out(chatwin->barejid, msg);
ui_outgoing_chat_msg(chatwin, msg, id, PROF_ENC_NONE); ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN);
free(id); free(id);
return; return;
#endif #endif

View File

@ -187,7 +187,7 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message)
new_win = TRUE; new_win = TRUE;
} }
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
} }
@ -197,17 +197,14 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char
{ {
char *decrypted = p_gpg_decrypt(pgp_message); char *decrypted = p_gpg_decrypt(pgp_message);
if (decrypted) { if (decrypted) {
if (chatwin->enc_mode == PROF_ENC_NONE) { ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win, PROF_MSG_PGP);
win_println((ProfWin*)chatwin, 0, "PGP encryption enabled.");
}
ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win, PROF_ENC_PGP);
chat_log_pgp_msg_in(barejid, decrypted); chat_log_pgp_msg_in(barejid, decrypted);
chatwin->enc_mode = PROF_ENC_PGP; chatwin->pgp_recv = TRUE;
p_gpg_free_decrypted(decrypted); p_gpg_free_decrypted(decrypted);
} else { } else {
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
chatwin->enc_mode = PROF_ENC_NONE; chatwin->pgp_recv = FALSE;
} }
} }
#endif #endif
@ -220,23 +217,27 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted); char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
if (otr_res) { if (otr_res) {
if (decrypted) { if (decrypted) {
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_OTR); ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_MSG_OTR);
chatwin->pgp_send = FALSE;
} else { } else {
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_NONE); ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_MSG_PLAIN);
} }
chat_log_otr_msg_in(barejid, otr_res, decrypted); chat_log_otr_msg_in(barejid, otr_res, decrypted);
otr_free_message(otr_res); otr_free_message(otr_res);
chatwin->pgp_recv = FALSE;
} }
} }
#endif #endif
#ifndef HAVE_LIBOTR
static void static void
_sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message) _sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message)
{ {
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE); ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN);
chat_log_msg_in(barejid, message); chat_log_msg_in(barejid, message);
chatwin->enc_mode = PROF_ENC_NONE; chatwin->pgp_recv = FALSE;
} }
#endif
void void
sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message) sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message)
@ -253,18 +254,13 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME #ifdef HAVE_LIBGPGME
if (pgp_message) { if (pgp_message) {
if (chatwin->enc_mode == PROF_ENC_OTR) { if (chatwin->is_otr) {
win_println((ProfWin*)chatwin, 0, "PGP encrypted message received whilst in OTR session."); win_println((ProfWin*)chatwin, 0, "PGP encrypted message received whilst in OTR session.");
} else { // PROF_ENC_NONE, PROF_ENC_PGP } else { // PROF_ENC_NONE, PROF_ENC_PGP
_sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message); _sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message);
} }
} else { } else {
if (chatwin->enc_mode == PROF_ENC_PGP) { _sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message);
win_println((ProfWin*)chatwin, 0, "PGP encryption disabled.");
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message);
} else {
_sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message);
}
} }
return; return;
#endif #endif
@ -316,7 +312,7 @@ sv_ev_delayed_message(char *barejid, char *message, GDateTime *timestamp)
new_win = TRUE; new_win = TRUE;
} }
ui_incoming_msg(chatwin, NULL, message, timestamp, new_win, PROF_ENC_NONE); ui_incoming_msg(chatwin, NULL, message, timestamp, new_win, PROF_MSG_PLAIN);
chat_log_msg_in_delayed(barejid, message, timestamp); chat_log_msg_in_delayed(barejid, message, timestamp);
} }

View File

@ -325,7 +325,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char * const message)
if (encrypted) { if (encrypted) {
id = message_send_chat_otr(chatwin->barejid, encrypted); id = message_send_chat_otr(chatwin->barejid, encrypted);
chat_log_otr_msg_out(chatwin->barejid, message); chat_log_otr_msg_out(chatwin->barejid, message);
ui_outgoing_chat_msg(chatwin, message, id, PROF_ENC_OTR); ui_outgoing_chat_msg(chatwin, message, id, PROF_MSG_OTR);
otr_free_message(encrypted); otr_free_message(encrypted);
free(id); free(id);
return TRUE; return TRUE;
@ -345,7 +345,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char * const message)
if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) { if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
char *otr_tagged_msg = otr_tag_message(message); char *otr_tagged_msg = otr_tag_message(message);
id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg); id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg);
ui_outgoing_chat_msg(chatwin, message, id, PROF_ENC_NONE); ui_outgoing_chat_msg(chatwin, message, id, PROF_MSG_PLAIN);
chat_log_msg_out(chatwin->barejid, message); chat_log_msg_out(chatwin->barejid, message);
free(otr_tagged_msg); free(otr_tagged_msg);
free(id); free(id);

View File

@ -478,7 +478,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
// currently viewing chat window with sender // currently viewing chat window with sender
if (wins_is_current(window)) { 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); title_bar_set_typing(FALSE);
status_bar_active(num); status_bar_active(num);
@ -487,7 +487,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
privatewin->unread++; privatewin->unread++;
status_bar_new(num); status_bar_new(num);
cons_show_incoming_message(display_from, 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)) { if (prefs_get_boolean(PREF_FLASH)) {
flash(); flash();
@ -713,7 +713,7 @@ ui_close_connected_win(int index)
ProfChatWin *chatwin = (ProfChatWin*) window; ProfChatWin *chatwin = (ProfChatWin*) window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
if (chatwin->enc_mode == PROF_ENC_OTR) { if (chatwin->is_otr) {
otr_end_session(chatwin->barejid); otr_end_session(chatwin->barejid);
} }
#endif #endif
@ -895,7 +895,7 @@ ui_gone_secure(const char * const barejid, gboolean trusted)
chatwin = (ProfChatWin*)window; chatwin = (ProfChatWin*)window;
} }
chatwin->enc_mode = PROF_ENC_OTR; chatwin->is_otr = TRUE;
chatwin->otr_is_trusted = trusted; chatwin->otr_is_trusted = trusted;
if (trusted) { if (trusted) {
win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (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); ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin) { if (chatwin) {
chatwin->enc_mode = PROF_ENC_NONE; chatwin->is_otr = FALSE;
chatwin->otr_is_trusted = FALSE; chatwin->otr_is_trusted = FALSE;
ProfWin *window = (ProfWin*)chatwin; ProfWin *window = (ProfWin*)chatwin;
@ -1042,7 +1042,7 @@ ui_trust(const char * const barejid)
{ {
ProfChatWin *chatwin = wins_get_chat(barejid); ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin) { if (chatwin) {
chatwin->enc_mode = PROF_ENC_OTR; chatwin->is_otr = TRUE;
chatwin->otr_is_trusted = TRUE; chatwin->otr_is_trusted = TRUE;
ProfWin *window = (ProfWin*)chatwin; ProfWin *window = (ProfWin*)chatwin;
@ -1058,7 +1058,7 @@ ui_untrust(const char * const barejid)
{ {
ProfChatWin *chatwin = wins_get_chat(barejid); ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin) { if (chatwin) {
chatwin->enc_mode = PROF_ENC_OTR; chatwin->is_otr = TRUE;
chatwin->otr_is_trusted = FALSE; chatwin->otr_is_trusted = FALSE;
ProfWin *window = (ProfWin*)chatwin; 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) ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode)
{ {
char enc_char = '-'; char enc_char = '-';
if (enc_mode == PROF_ENC_OTR) { if (enc_mode == PROF_MSG_OTR) {
enc_char = prefs_get_otr_char(); 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(); enc_char = prefs_get_pgp_char();
} }

View File

@ -250,70 +250,73 @@ _show_privacy(ProfChatWin *chatwin)
int trusted_attrs = theme_attrs(THEME_TITLE_TRUSTED); int trusted_attrs = theme_attrs(THEME_TITLE_TRUSTED);
int untrusted_attrs = theme_attrs(THEME_TITLE_UNTRUSTED); int untrusted_attrs = theme_attrs(THEME_TITLE_UNTRUSTED);
switch (chatwin->enc_mode) { if (chatwin->is_otr) {
case PROF_ENC_NONE: wprintw(win, " ");
if (prefs_get_boolean(PREF_ENC_WARN)) { wattron(win, bracket_attrs);
wprintw(win, " "); wprintw(win, "[");
wattron(win, bracket_attrs); wattroff(win, bracket_attrs);
wprintw(win, "["); wattron(win, encrypted_attrs);
wattroff(win, bracket_attrs); wprintw(win, "OTR");
wattron(win, unencrypted_attrs); wattroff(win, encrypted_attrs);
wprintw(win, "unencrypted"); wattron(win, bracket_attrs);
wattroff(win, unencrypted_attrs); wprintw(win, "]");
wattron(win, bracket_attrs); wattroff(win, bracket_attrs);
wprintw(win, "]"); if (chatwin->otr_is_trusted) {
wattroff(win, bracket_attrs);
}
break;
case PROF_ENC_OTR:
wprintw(win, " "); wprintw(win, " ");
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
wprintw(win, "["); wprintw(win, "[");
wattroff(win, bracket_attrs); wattroff(win, bracket_attrs);
wattron(win, encrypted_attrs); wattron(win, trusted_attrs);
wprintw(win, "OTR"); wprintw(win, "trusted");
wattroff(win, encrypted_attrs); wattroff(win, trusted_attrs);
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
wprintw(win, "]"); wprintw(win, "]");
wattroff(win, bracket_attrs); wattroff(win, bracket_attrs);
if (chatwin->otr_is_trusted) { } else {
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:
wprintw(win, " "); wprintw(win, " ");
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
wprintw(win, "["); wprintw(win, "[");
wattroff(win, bracket_attrs); wattroff(win, bracket_attrs);
wattron(win, encrypted_attrs); wattron(win, untrusted_attrs);
wprintw(win, "PGP"); wprintw(win, "untrusted");
wattroff(win, encrypted_attrs); wattroff(win, untrusted_attrs);
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
wprintw(win, "]"); wprintw(win, "]");
wattroff(win, bracket_attrs); 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);
}
} }
} }

View File

@ -45,6 +45,12 @@
#define NO_COLOUR_FROM 8 #define NO_COLOUR_FROM 8
#define NO_COLOUR_DATE 16 #define NO_COLOUR_DATE 16
typedef enum {
PROF_MSG_PLAIN,
PROF_MSG_OTR,
PROF_MSG_PGP
} prof_enc_t;
// ui startup and control // ui startup and control
void ui_init(void); void ui_init(void);
void ui_load_colours(void); void ui_load_colours(void);

View File

@ -89,12 +89,6 @@ typedef enum {
WIN_XML WIN_XML
} win_type_t; } win_type_t;
typedef enum {
PROF_ENC_NONE,
PROF_ENC_OTR,
PROF_ENC_PGP
} prof_enc_t;
typedef struct prof_win_t { typedef struct prof_win_t {
win_type_t type; win_type_t type;
ProfLayout *layout; ProfLayout *layout;
@ -109,8 +103,10 @@ typedef struct prof_chat_win_t {
char *barejid; char *barejid;
int unread; int unread;
ChatState *state; ChatState *state;
prof_enc_t enc_mode; gboolean is_otr;
gboolean otr_is_trusted; gboolean otr_is_trusted;
gboolean pgp_send;
gboolean pgp_recv;
char *resource_override; char *resource_override;
gboolean history_shown; gboolean history_shown;
unsigned long memcheck; unsigned long memcheck;

View File

@ -135,8 +135,10 @@ win_create_chat(const char * const barejid)
new_win->barejid = strdup(barejid); new_win->barejid = strdup(barejid);
new_win->resource_override = NULL; 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->otr_is_trusted = FALSE;
new_win->pgp_recv = FALSE;
new_win->pgp_send = FALSE;
new_win->history_shown = FALSE; new_win->history_shown = FALSE;
new_win->unread = 0; new_win->unread = 0;
new_win->state = chat_state_new(); new_win->state = chat_state_new();
@ -884,9 +886,9 @@ win_print_incoming_message(ProfWin *window, GDateTime *timestamp,
switch (window->type) switch (window->type)
{ {
case WIN_CHAT: case WIN_CHAT:
if (enc_mode == PROF_ENC_OTR) { if (enc_mode == PROF_MSG_OTR) {
enc_char = prefs_get_otr_char(); 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(); enc_char = prefs_get_pgp_char();
} }
win_print(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message); win_print(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message);

View File

@ -321,6 +321,8 @@ void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state)
ProfChatWin chatwin; ProfChatWin chatwin;
chatwin.window = window; chatwin.window = window;
chatwin.memcheck = PROFCHATWIN_MEMCHECK; chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.pgp_send = FALSE;
chatwin.is_otr = FALSE;
will_return(jabber_get_connection_status, JABBER_CONNECTED); will_return(jabber_get_connection_status, JABBER_CONNECTED);
@ -346,7 +348,8 @@ void cmd_otr_theirfp_shows_fingerprint(void **state)
chatwin.window = window; chatwin.window = window;
chatwin.barejid = recipient; chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK; chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.enc_mode = PROF_ENC_OTR; chatwin.pgp_send = FALSE;
chatwin.is_otr = TRUE;
will_return(jabber_get_connection_status, JABBER_CONNECTED); will_return(jabber_get_connection_status, JABBER_CONNECTED);
@ -404,7 +407,8 @@ void cmd_otr_start_shows_message_when_already_started(void **state)
chatwin.window = window; chatwin.window = window;
chatwin.barejid = recipient; chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK; chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.enc_mode = PROF_ENC_OTR; chatwin.pgp_send = FALSE;
chatwin.is_otr = TRUE;
expect_ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); expect_ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
@ -426,7 +430,8 @@ void cmd_otr_start_shows_message_when_no_key(void **state)
chatwin.window = window; chatwin.window = window;
chatwin.barejid = recipient; chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK; chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.enc_mode = PROF_ENC_NONE; chatwin.pgp_send = FALSE;
chatwin.is_otr = FALSE;
expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
@ -447,7 +452,8 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
chatwin.window = window; chatwin.window = window;
chatwin.barejid = recipient; chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK; chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.enc_mode = PROF_ENC_NONE; chatwin.pgp_send = FALSE;
chatwin.is_otr = FALSE;
will_return(jabber_get_connection_status, JABBER_CONNECTED); will_return(jabber_get_connection_status, JABBER_CONNECTED);
will_return(otr_key_loaded, TRUE); will_return(otr_key_loaded, TRUE);