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

Handle window creation for incoming and outgoing OTR sessions

This commit is contained in:
James Booth 2014-01-11 21:44:24 +00:00
parent 5a7eba518d
commit f35e485bd4
6 changed files with 53 additions and 8 deletions

View File

@ -1141,7 +1141,7 @@ cmd_execute_default(const char * const inp)
ui_current_print_line("You are not currently connected.");
} else {
#ifdef HAVE_LIBOTR
if (ui_current_win_is_otr()) {
if (otr_is_secure(recipient)) {
char *encrypted = otr_encrypt_message(recipient, inp);
if (encrypted != NULL) {
message_send(encrypted, recipient);

View File

@ -919,7 +919,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
}
if (msg != NULL) {
#ifdef HAVE_LIBOTR
if (ui_current_win_is_otr()) {
if (otr_is_secure(usr_jid)) {
char *encrypted = otr_encrypt_message(usr_jid, msg);
if (encrypted != NULL) {
message_send(encrypted, usr_jid);
@ -2341,12 +2341,8 @@ cmd_otr(gchar **args, struct cmd_help_t help)
if (!otr_key_loaded()) {
ui_current_print_line("You have not generated or loaded a private key, use '/otr gen'");
} else {
ui_current_print_line("Starting OTR session");
char *recipient = ui_current_recipient();
message_send("?OTR?", recipient);
ui_current_set_otr(TRUE);
// refresh to show OTR in titlebar
ui_switch_win(ui_current_win_index());
}
}
return TRUE;

View File

@ -120,6 +120,7 @@ static void
cb_gone_secure(void *opdata, ConnContext *context)
{
// cons_debug("cb_gone_secure");
ui_gone_secure(context->username);
}
static void
@ -332,6 +333,23 @@ otr_key_loaded(void)
return data_loaded;
}
gboolean
otr_is_secure(const char * const recipient)
{
ConnContext *context = otrl_context_find(user_state, recipient, jid, "xmpp",
0, NULL, NULL, NULL);
if (context == NULL) {
return FALSE;
}
if (context->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
return FALSE;
} else {
return TRUE;
}
}
char *
otr_get_my_fingerprint(void)
{
@ -343,7 +361,7 @@ otr_get_my_fingerprint(void)
}
char *
otr_get_their_fingerprint(char *recipient)
otr_get_their_fingerprint(const char * const recipient)
{
ConnContext *context = otrl_context_find(user_state, recipient, jid, "xmpp",
0, NULL, NULL, NULL);

View File

@ -30,9 +30,10 @@ void otr_on_connect(ProfAccount *account);
void otr_keygen(ProfAccount *account);
gboolean otr_key_loaded(void);
gboolean otr_is_secure(const char * const recipient);
char * otr_get_my_fingerprint(void);
char * otr_get_their_fingerprint(char *recipient);
char * otr_get_their_fingerprint(const char * const recipient);
char * otr_encrypt_message(const char * const to, const char * const message);
char * otr_decrypt_message(const char * const from, const char * const message);

View File

@ -48,6 +48,7 @@
#include "jid.h"
#include "log.h"
#include "muc.h"
#include "otr.h"
#include "ui/ui.h"
#include "ui/window.h"
#include "ui/windows.h"
@ -245,6 +246,11 @@ _ui_incoming_msg(const char * const from, const char * const message,
ProfWin *window = wins_get_by_recipient(from);
if (window == NULL) {
window = wins_new(from, win_type);
#ifdef HAVE_LIBOTR
if (otr_is_secure(from)) {
window->is_otr = TRUE;
}
#endif
win_created = TRUE;
}
@ -581,6 +587,23 @@ _ui_next_win(void)
wins_refresh_current();
}
static void
_ui_gone_secure(char *recipient)
{
ProfWin *window = wins_get_by_recipient(recipient);
if (window != NULL) {
window->is_otr = TRUE;
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
title_bar_set_recipient(recipient_str->str);
g_string_free(recipient_str, TRUE);
title_bar_draw();
wins_refresh_current();
}
}
}
static void
_ui_previous_win(void)
{
@ -966,6 +989,11 @@ _ui_outgoing_msg(const char * const from, const char * const to,
window = wins_new(to, WIN_PRIVATE);
} else {
window = wins_new(to, WIN_CHAT);
#ifdef HAVE_LIBOTR
if (otr_is_secure(to)) {
window->is_otr = TRUE;
}
#endif
}
jid_destroy(jid);
@ -1634,4 +1662,5 @@ ui_init_module(void)
ui_ask_password = _ui_ask_password;
ui_current_win_is_otr = _ui_current_win_is_otr;
ui_current_set_otr = _ui_current_set_otr;
ui_gone_secure = _ui_gone_secure;
}

View File

@ -61,6 +61,7 @@ void (*ui_handle_special_keys)(const wint_t * const ch, const char * const inp,
void (*ui_switch_win)(const int i);
void (*ui_next_win)(void);
void (*ui_previous_win)(void);
void (*ui_gone_secure)(char *recipient);
unsigned long (*ui_get_idle_time)(void);
void (*ui_reset_idle_time)(void);
void (*ui_new_chat_win)(const char * const to);