mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Tidied sv_ev_incoming_message
This commit is contained in:
parent
fc60c9fbf1
commit
4b90a53566
@ -191,6 +191,53 @@ sv_ev_incoming_carbon(char *barejid, char *resource, char *message)
|
|||||||
chat_log_msg_in(barejid, message);
|
chat_log_msg_in(barejid, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBGPGME
|
||||||
|
static void
|
||||||
|
_sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, char *enc_message)
|
||||||
|
{
|
||||||
|
char *decrypted = p_gpg_decrypt(enc_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);
|
||||||
|
chat_log_pgp_msg_in(barejid, decrypted);
|
||||||
|
chatwin->enc_mode = PROF_ENC_PGP;
|
||||||
|
p_gpg_free_decrypted(decrypted);
|
||||||
|
} else {
|
||||||
|
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
|
||||||
|
chat_log_msg_in(barejid, message);
|
||||||
|
chatwin->enc_mode = PROF_ENC_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBOTR
|
||||||
|
static void
|
||||||
|
_sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message)
|
||||||
|
{
|
||||||
|
gboolean decrypted = FALSE;
|
||||||
|
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
|
||||||
|
if (otr_res) {
|
||||||
|
if (decrypted && g_strrstr(otr_res, message) == NULL) {
|
||||||
|
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_OTR);
|
||||||
|
} else {
|
||||||
|
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_NONE);
|
||||||
|
}
|
||||||
|
chat_log_otr_msg_in(barejid, otr_res, decrypted);
|
||||||
|
otr_free_message(otr_res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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);
|
||||||
|
chat_log_msg_in(barejid, message);
|
||||||
|
chatwin->enc_mode = PROF_ENC_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_message)
|
sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_message)
|
||||||
{
|
{
|
||||||
@ -205,44 +252,18 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
|
|||||||
// 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 (enc_message) {
|
if (enc_message) {
|
||||||
if (enc_mode == PROF_ENC_OTR) {
|
if (chatwin->enc_mode == PROF_ENC_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
|
||||||
char *decrypted = p_gpg_decrypt(enc_message);
|
_sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, enc_message);
|
||||||
if (decrypted) {
|
|
||||||
if (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);
|
|
||||||
chat_log_pgp_msg_in(barejid, decrypted);
|
|
||||||
chatwin->enc_mode = PROF_ENC_PGP;
|
|
||||||
p_gpg_free_decrypted(decrypted);
|
|
||||||
} else {
|
|
||||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
|
|
||||||
chat_log_msg_in(barejid, message);
|
|
||||||
chatwin->enc_mode = PROF_ENC_NONE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (enc_mode == PROF_ENC_PGP) {
|
if (chatwin->enc_mode == PROF_ENC_PGP) {
|
||||||
win_println((ProfWin*)chatwin, 0, "PGP encryption disabled.");
|
win_println((ProfWin*)chatwin, 0, "PGP encryption disabled.");
|
||||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
|
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message);
|
||||||
chat_log_msg_in(barejid, message);
|
|
||||||
chatwin->enc_mode = PROF_ENC_NONE;
|
|
||||||
} else {
|
} else {
|
||||||
gboolean decrypted = FALSE;
|
_sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message);
|
||||||
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
|
|
||||||
if (otr_res) {
|
|
||||||
if (decrypted && g_strrstr(otr_res, message) == NULL) {
|
|
||||||
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_OTR);
|
|
||||||
} else {
|
|
||||||
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_NONE);
|
|
||||||
}
|
|
||||||
chat_log_otr_msg_in(barejid, otr_res, decrypted);
|
|
||||||
otr_free_message(otr_res);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -252,17 +273,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
|
|||||||
// OTR supported, PGP unsupported
|
// OTR supported, PGP unsupported
|
||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
#ifndef HAVE_LIBGPGME
|
#ifndef HAVE_LIBGPGME
|
||||||
gboolean decrypted = FALSE;
|
_sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message);
|
||||||
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
|
|
||||||
if (otr_res) {
|
|
||||||
if (decrypted && g_strrstr(otr_res, message) == NULL) {
|
|
||||||
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_OTR);
|
|
||||||
} else {
|
|
||||||
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win, PROF_ENC_NONE);
|
|
||||||
}
|
|
||||||
chat_log_otr_msg_in(barejid, otr_res, decrypted);
|
|
||||||
otr_free_message(otr_res);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -271,21 +282,9 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
|
|||||||
#ifndef HAVE_LIBOTR
|
#ifndef HAVE_LIBOTR
|
||||||
#ifdef HAVE_LIBGPGME
|
#ifdef HAVE_LIBGPGME
|
||||||
if (enc_message) {
|
if (enc_message) {
|
||||||
char *decrypted = p_gpg_decrypt(enc_message);
|
_sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, enc_message);
|
||||||
if (decrypted) {
|
|
||||||
ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win, PROF_ENC_PGP);
|
|
||||||
chat_log_pgp_msg_in(barejid, decrypted);
|
|
||||||
chatwin->enc_mode = PROF_ENC_PGP;
|
|
||||||
p_gpg_free_decrypted(decrypted);
|
|
||||||
} else {
|
|
||||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
|
|
||||||
chat_log_msg_in(barejid, message);
|
|
||||||
chatwin->enc_mode = PROF_ENC_NONE;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
|
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message);
|
||||||
chat_log_msg_in(barejid, message);
|
|
||||||
chatwin->enc_mode = PROF_ENC_NONE;
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
@ -294,9 +293,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_m
|
|||||||
// OTR unsupported, PGP unsupported
|
// OTR unsupported, PGP unsupported
|
||||||
#ifndef HAVE_LIBOTR
|
#ifndef HAVE_LIBOTR
|
||||||
#ifndef HAVE_LIBGPGME
|
#ifndef HAVE_LIBGPGME
|
||||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_ENC_NONE);
|
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message);
|
||||||
chat_log_msg_in(barejid, message);
|
|
||||||
chatwin->enc_mode = PROF_ENC_NONE;
|
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user