mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Add PGP decryption for incoming/outgoing carbons
This commit is contained in:
parent
9d782fa665
commit
6f537c3818
@ -349,7 +349,7 @@ sv_ev_delayed_private_message(const char *const fulljid, char *message, GDateTim
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_outgoing_carbon(char *barejid, char *message)
|
||||
sv_ev_outgoing_carbon(char *barejid, char *message, char *pgp_message)
|
||||
{
|
||||
ProfChatWin *chatwin = wins_get_chat(barejid);
|
||||
if (!chatwin) {
|
||||
@ -358,22 +358,20 @@ sv_ev_outgoing_carbon(char *barejid, char *message)
|
||||
|
||||
chat_state_active(chatwin->state);
|
||||
|
||||
chatwin_outgoing_carbon(chatwin, message);
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_incoming_carbon(char *barejid, char *resource, char *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;
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
if (pgp_message) {
|
||||
char *decrypted = p_gpg_decrypt(pgp_message);
|
||||
if (decrypted) {
|
||||
chatwin_outgoing_carbon(chatwin, decrypted, PROF_MSG_PGP);
|
||||
} else {
|
||||
chatwin_outgoing_carbon(chatwin, message, PROF_MSG_PLAIN);
|
||||
}
|
||||
} else {
|
||||
chatwin_outgoing_carbon(chatwin, message, PROF_MSG_PLAIN);
|
||||
}
|
||||
|
||||
chatwin_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN);
|
||||
chat_log_msg_in(barejid, message, NULL);
|
||||
#else
|
||||
chatwin_outgoing_carbon(chatwin, message, PROF_MSG_PLAIN);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
@ -414,7 +412,6 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PROF_HAVE_LIBOTR
|
||||
static void
|
||||
_sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, GDateTime *timestamp)
|
||||
{
|
||||
@ -422,7 +419,6 @@ _sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, cha
|
||||
chat_log_msg_in(barejid, message, timestamp);
|
||||
chatwin->pgp_recv = FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message, GDateTime *timestamp)
|
||||
@ -484,6 +480,28 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_incoming_carbon(char *barejid, char *resource, char *message, char *pgp_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;
|
||||
}
|
||||
|
||||
#ifdef PROF_HAVE_LIBGPGME
|
||||
if (pgp_message) {
|
||||
_sv_ev_incoming_pgp(chatwin, new_win, barejid, resource, message, pgp_message, NULL);
|
||||
} else {
|
||||
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, NULL);
|
||||
}
|
||||
#else
|
||||
_sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_message_receipt(char *barejid, char *id)
|
||||
{
|
||||
|
@ -73,8 +73,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_outgoing_carbon(char *barejid, char *message);
|
||||
void sv_ev_incoming_carbon(char *barejid, char *resource, char *message);
|
||||
void sv_ev_outgoing_carbon(char *barejid, char *message, char *pgp_message);
|
||||
void sv_ev_incoming_carbon(char *barejid, char *resource, char *message, char *pgp_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,
|
||||
|
@ -312,11 +312,16 @@ chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id,
|
||||
}
|
||||
|
||||
void
|
||||
chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message)
|
||||
chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message, prof_enc_t enc_mode)
|
||||
{
|
||||
assert(chatwin != NULL);
|
||||
|
||||
win_print((ProfWin*)chatwin, '-', 0, NULL, 0, THEME_TEXT_ME, "me", message);
|
||||
char enc_char = '-';
|
||||
if (enc_mode == PROF_MSG_PGP) {
|
||||
enc_char = prefs_get_pgp_char();
|
||||
}
|
||||
|
||||
win_print((ProfWin*)chatwin, enc_char, 0, NULL, 0, THEME_TEXT_ME, "me", message);
|
||||
int num = wins_get_num((ProfWin*)chatwin);
|
||||
status_bar_active(num);
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ void chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, cons
|
||||
void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id);
|
||||
void chatwin_recipient_gone(ProfChatWin *chatwin);
|
||||
void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode);
|
||||
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message);
|
||||
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message, prof_enc_t enc_mode);
|
||||
void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity);
|
||||
void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status);
|
||||
char* chatwin_get_string(ProfChatWin *chatwin);
|
||||
|
@ -191,8 +191,6 @@ message_send_chat_pgp(const char *const barejid, const char *const msg)
|
||||
stanza_attach_state(ctx, message, state);
|
||||
}
|
||||
|
||||
stanza_attach_carbons_private(ctx, message);
|
||||
|
||||
if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) {
|
||||
stanza_attach_receipt_request(ctx, message);
|
||||
}
|
||||
@ -714,17 +712,25 @@ _handle_carbons(xmpp_stanza_t *const stanza)
|
||||
// check for and deal with message
|
||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY);
|
||||
if (body) {
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message) {
|
||||
char *message_txt = xmpp_stanza_get_text(body);
|
||||
if (message_txt) {
|
||||
// check for pgp encrypted message
|
||||
char *enc_message = NULL;
|
||||
xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED);
|
||||
if (x) {
|
||||
enc_message = xmpp_stanza_get_text(x);
|
||||
}
|
||||
|
||||
// if we are the recipient, treat as standard incoming message
|
||||
if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){
|
||||
sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message);
|
||||
}
|
||||
sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message);
|
||||
|
||||
// else treat as a sent message
|
||||
else{
|
||||
sv_ev_outgoing_carbon(jid_to->barejid, message);
|
||||
} else {
|
||||
sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message);
|
||||
}
|
||||
xmpp_free(ctx, message);
|
||||
xmpp_free(ctx, message_txt);
|
||||
xmpp_free(ctx, enc_message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ void ui_disconnected(void) {}
|
||||
void chatwin_recipient_gone(ProfChatWin *chatwin) {}
|
||||
|
||||
void chatwin_outgoing_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode) {}
|
||||
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char * const message) {}
|
||||
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char * const message, prof_enc_t enc_mode) {}
|
||||
void privwin_outgoing_msg(ProfPrivateWin *privwin, const char * const message) {}
|
||||
|
||||
void privwin_occupant_offline(ProfPrivateWin *privwin) {}
|
||||
|
Loading…
Reference in New Issue
Block a user