Split PGP incoming and outgoing message handling
This commit is contained in:
@@ -91,20 +91,19 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
|
||||
// OTR suported, PGP supported
|
||||
#ifdef HAVE_LIBOTR
|
||||
#ifdef HAVE_LIBGPGME
|
||||
prof_enc_t enc_mode = chatwin->enc_mode;
|
||||
if (enc_mode == PROF_ENC_NONE || enc_mode == PROF_ENC_OTR) {
|
||||
if (chatwin->pgp_send) {
|
||||
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);
|
||||
if (!handled) {
|
||||
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);
|
||||
ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN);
|
||||
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;
|
||||
#endif
|
||||
@@ -117,7 +116,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
|
||||
if (!handled) {
|
||||
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);
|
||||
ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN);
|
||||
free(id);
|
||||
}
|
||||
return;
|
||||
@@ -127,16 +126,15 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
|
||||
// OTR unsupported, PGP supported
|
||||
#ifndef HAVE_LIBOTR
|
||||
#ifdef HAVE_LIBGPGME
|
||||
prof_enc_t enc_mode = chatwin->enc_mode;
|
||||
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) {
|
||||
if (chatwin->pgp_send) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
return;
|
||||
@@ -148,7 +146,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
|
||||
#ifndef HAVE_LIBGPGME
|
||||
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);
|
||||
ui_outgoing_chat_msg(chatwin, msg, id, PROF_MSG_PLAIN);
|
||||
free(id);
|
||||
return;
|
||||
#endif
|
||||
|
||||
@@ -187,7 +187,7 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -197,17 +197,14 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char
|
||||
{
|
||||
char *decrypted = p_gpg_decrypt(pgp_message);
|
||||
if (decrypted) {
|
||||
if (chatwin->enc_mode == PROF_ENC_NONE) {
|
||||
win_println((ProfWin*)chatwin, 0, "PGP encryption enabled.");
|
||||
}
|
||||
ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win, PROF_ENC_PGP);
|
||||
ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win, PROF_MSG_PGP);
|
||||
chat_log_pgp_msg_in(barejid, decrypted);
|
||||
chatwin->enc_mode = PROF_ENC_PGP;
|
||||
chatwin->pgp_recv = TRUE;
|
||||
p_gpg_free_decrypted(decrypted);
|
||||
} 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);
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
chatwin->pgp_recv = FALSE;
|
||||
}
|
||||
}
|
||||
#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);
|
||||
if (otr_res) {
|
||||
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 {
|
||||
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);
|
||||
otr_free_message(otr_res);
|
||||
chatwin->pgp_recv = FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LIBOTR
|
||||
static void
|
||||
_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);
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
chatwin->pgp_recv = FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
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_LIBGPGME
|
||||
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.");
|
||||
} else { // PROF_ENC_NONE, PROF_ENC_PGP
|
||||
_sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message);
|
||||
}
|
||||
} else {
|
||||
if (chatwin->enc_mode == PROF_ENC_PGP) {
|
||||
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);
|
||||
}
|
||||
_sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message);
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
@@ -316,7 +312,7 @@ sv_ev_delayed_message(char *barejid, char *message, GDateTime *timestamp)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user