mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Encryption modes for sv_ev_incoming_message
This commit is contained in:
parent
03a4aa4408
commit
5669799690
@ -164,13 +164,13 @@ sv_ev_incoming_private_message(const char * const fulljid, char *message)
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_carbon(char *barejid, char *message)
|
||||
sv_ev_outgoing_carbon(char *barejid, char *message)
|
||||
{
|
||||
ui_outgoing_chat_msg_carbon(barejid, message);
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_incoming_message(char *barejid, char *resource, char *message)
|
||||
sv_ev_incoming_carbon(char *barejid, char *resource, char *message)
|
||||
{
|
||||
gboolean new_win = FALSE;
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
@ -180,7 +180,63 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message)
|
||||
new_win = TRUE;
|
||||
}
|
||||
|
||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win);
|
||||
chat_log_msg_in(barejid, message);
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_message)
|
||||
{
|
||||
gboolean new_win = FALSE;
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (!chatwin) {
|
||||
ProfWin *window = wins_new_chat(barejid);
|
||||
chatwin = (ProfChatWin*)window;
|
||||
new_win = TRUE;
|
||||
}
|
||||
|
||||
// OTR suported, PGP supported
|
||||
#ifdef HAVE_LIBOTR
|
||||
#ifdef HAVE_LIBGPGME
|
||||
prof_enc_t enc_mode = chatwin->enc_mode;
|
||||
if (enc_message) {
|
||||
if (enc_mode == PROF_ENC_OTR) {
|
||||
// TODO show error
|
||||
} else { // PROF_ENC_NONE, PROF_ENC_PGP
|
||||
char *decrypted = p_gpg_decrypt(barejid, enc_message);
|
||||
if (decrypted) {
|
||||
ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win);
|
||||
// TODO pgp message logger
|
||||
chat_log_msg_in(barejid, decrypted);
|
||||
chatwin->enc_mode = PROF_ENC_PGP;
|
||||
} else {
|
||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win);
|
||||
chat_log_msg_in(barejid, message);
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (enc_mode == PROF_ENC_PGP) {
|
||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win);
|
||||
chat_log_msg_in(barejid, message);
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
} else {
|
||||
gboolean decrypted = FALSE;
|
||||
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
|
||||
if (otr_res) {
|
||||
ui_incoming_msg(chatwin, resource, otr_res, NULL, new_win);
|
||||
chat_log_otr_msg_in(barejid, otr_res, decrypted);
|
||||
otr_free_message(otr_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// OTR supported, PGP unsupported
|
||||
#ifdef HAVE_LIBOTR
|
||||
#ifndef HAVE_LIBGPGME
|
||||
gboolean decrypted = FALSE;
|
||||
char *otr_res = otr_on_message_recv(barejid, resource, message, &decrypted);
|
||||
if (otr_res) {
|
||||
@ -188,9 +244,43 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message)
|
||||
chat_log_otr_msg_in(barejid, otr_res, decrypted);
|
||||
otr_free_message(otr_res);
|
||||
}
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// OTR unsupported, PGP supported
|
||||
#ifndef HAVE_LIBOTR
|
||||
#ifdef HAVE_LIBGPGME
|
||||
prof_enc_t enc_mode = chatwin->enc_mode;
|
||||
if (enc_message) {
|
||||
char *decrypted = p_gpg_decrypt(jid->barejid, enc_message);
|
||||
if (decrypted) {
|
||||
ui_incoming_msg(chatwin, resource, decrypted, NULL, new_win);
|
||||
// TODO pgp message logger
|
||||
chat_log_msg_in(barejid, decrypted);
|
||||
chatwin->enc_mode = PROF_ENC_PGP;
|
||||
} else {
|
||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win);
|
||||
chat_log_msg_in(barejid, message);
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
}
|
||||
} else {
|
||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win);
|
||||
chat_log_msg_in(barejid, message);
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// OTR unsupported, PGP unsupported
|
||||
#ifndef HAVE_LIBOTR
|
||||
#ifndef HAVE_LIBGPGME
|
||||
ui_incoming_msg(chatwin, resource, message, NULL, new_win);
|
||||
chat_log_msg_in(barejid, message);
|
||||
chatwin->enc_mode = PROF_ENC_NONE;
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ void sv_ev_room_history(const char * const room_jid, const char * const nick,
|
||||
GTimeVal tv_stamp, const char * const message);
|
||||
void sv_ev_room_message(const char * const room_jid, const char * const nick,
|
||||
const char * const message);
|
||||
void sv_ev_incoming_message(char *barejid, char *resource, char *message);
|
||||
void sv_ev_incoming_message(char *barejid, char *resource, char *message, char *enc_message);
|
||||
void sv_ev_incoming_private_message(const char * const fulljid, char *message);
|
||||
void sv_ev_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp);
|
||||
void sv_ev_delayed_private_message(const char * const fulljid, char *message, GTimeVal tv_stamp);
|
||||
@ -75,7 +75,8 @@ void sv_ev_room_occupent_kicked(const char * const room, const char * const nick
|
||||
void sv_ev_room_banned(const char * const room, const char * const actor, const char * const reason);
|
||||
void sv_ev_room_occupent_banned(const char * const room, const char * const nick, const char * const actor,
|
||||
const char * const reason);
|
||||
void sv_ev_carbon(char *barejid, char *message);
|
||||
void sv_ev_outgoing_carbon(char *barejid, char *message);
|
||||
void sv_ev_incoming_carbon(char *barejid, char *resource, char *message);
|
||||
void sv_ev_xmpp_stanza(const char * const msg);
|
||||
void sv_ev_muc_self_online(const char * const room, const char * const nick, gboolean config_required,
|
||||
const char * const role, const char * const affiliation, const char * const actor, const char * const reason,
|
||||
|
@ -705,11 +705,11 @@ _handle_carbons(xmpp_stanza_t * const stanza)
|
||||
if (message) {
|
||||
// if we are the recipient, treat as standard incoming message
|
||||
if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){
|
||||
sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message);
|
||||
sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message);
|
||||
}
|
||||
// else treat as a sent message
|
||||
else{
|
||||
sv_ev_carbon(jid_to->barejid, message);
|
||||
sv_ev_outgoing_carbon(jid_to->barejid, message);
|
||||
}
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
@ -768,23 +768,12 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
|
||||
if (delayed) {
|
||||
sv_ev_delayed_message(jid->barejid, message, tv_stamp);
|
||||
} else {
|
||||
#ifdef HAVE_LIBGPGME
|
||||
gboolean handled = FALSE;
|
||||
char *enc_message = NULL;
|
||||
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_ENCRYPTED);
|
||||
if (x) {
|
||||
char *enc_message = xmpp_stanza_get_text(x);
|
||||
char *decrypted = p_gpg_decrypt(jid->barejid, enc_message);
|
||||
if (decrypted) {
|
||||
sv_ev_incoming_message(jid->barejid, jid->resourcepart, decrypted);
|
||||
handled = TRUE;
|
||||
}
|
||||
enc_message = xmpp_stanza_get_text(x);
|
||||
}
|
||||
if (!handled) {
|
||||
sv_ev_incoming_message(jid->barejid, jid->resourcepart, message);
|
||||
}
|
||||
#else
|
||||
sv_ev_incoming_message(jid->barejid, jid->resourcepart, message);
|
||||
#endif
|
||||
sv_ev_incoming_message(jid->barejid, jid->resourcepart, message, enc_message);
|
||||
}
|
||||
|
||||
_receipt_request_handler(stanza);
|
||||
|
@ -34,4 +34,7 @@ gboolean p_gpg_available(const char * const barejid)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char * p_gpg_decrypt(const char * const barejid, const char * const cipher)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user