1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-10-27 20:30:13 -04:00

Add PGP decryption for incoming/outgoing carbons

This commit is contained in:
James Booth 2016-03-22 00:20:29 +00:00
parent 9d782fa665
commit 6f537c3818
6 changed files with 62 additions and 33 deletions

View File

@ -349,7 +349,7 @@ sv_ev_delayed_private_message(const char *const fulljid, char *message, GDateTim
} }
void 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); ProfChatWin *chatwin = wins_get_chat(barejid);
if (!chatwin) { if (!chatwin) {
@ -358,22 +358,20 @@ sv_ev_outgoing_carbon(char *barejid, char *message)
chat_state_active(chatwin->state); chat_state_active(chatwin->state);
chatwin_outgoing_carbon(chatwin, message); #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 {
void chatwin_outgoing_carbon(chatwin, message, PROF_MSG_PLAIN);
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;
} }
#else
chatwin_incoming_msg(chatwin, resource, message, NULL, new_win, PROF_MSG_PLAIN); chatwin_outgoing_carbon(chatwin, message, PROF_MSG_PLAIN);
chat_log_msg_in(barejid, message, NULL); #endif
} }
#ifdef PROF_HAVE_LIBGPGME #ifdef PROF_HAVE_LIBGPGME
@ -414,7 +412,6 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, char *barejid, char
} }
#endif #endif
#ifndef PROF_HAVE_LIBOTR
static void static void
_sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, char *barejid, char *resource, char *message, GDateTime *timestamp) _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); chat_log_msg_in(barejid, message, timestamp);
chatwin->pgp_recv = FALSE; chatwin->pgp_recv = FALSE;
} }
#endif
void void
sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_message, GDateTime *timestamp) 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 #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 void
sv_ev_message_receipt(char *barejid, char *id) sv_ev_message_receipt(char *barejid, char *id)
{ {

View File

@ -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_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, void sv_ev_room_occupent_banned(const char *const room, const char *const nick, const char *const actor,
const char *const reason); const char *const reason);
void sv_ev_outgoing_carbon(char *barejid, 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); 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_xmpp_stanza(const char *const msg);
void sv_ev_muc_self_online(const char *const room, const char *const nick, gboolean config_required, 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, const char *const role, const char *const affiliation, const char *const actor, const char *const reason,

View File

@ -312,11 +312,16 @@ chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id,
} }
void 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); 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); int num = wins_get_num((ProfWin*)chatwin);
status_bar_active(num); status_bar_active(num);
} }

View File

@ -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_receipt_received(ProfChatWin *chatwin, const char *const id);
void chatwin_recipient_gone(ProfChatWin *chatwin); 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_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_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity);
void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status); void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status);
char* chatwin_get_string(ProfChatWin *chatwin); char* chatwin_get_string(ProfChatWin *chatwin);

View File

@ -191,8 +191,6 @@ message_send_chat_pgp(const char *const barejid, const char *const msg)
stanza_attach_state(ctx, message, state); stanza_attach_state(ctx, message, state);
} }
stanza_attach_carbons_private(ctx, message);
if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) { if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) {
stanza_attach_receipt_request(ctx, message); stanza_attach_receipt_request(ctx, message);
} }
@ -714,17 +712,25 @@ _handle_carbons(xmpp_stanza_t *const stanza)
// check for and deal with message // check for and deal with message
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY); xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY);
if (body) { if (body) {
char *message = xmpp_stanza_get_text(body); char *message_txt = xmpp_stanza_get_text(body);
if (message) { 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 we are the recipient, treat as standard incoming message
if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){ 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 treat as a sent message
else{ } else {
sv_ev_outgoing_carbon(jid_to->barejid, message); 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);
} }
} }

View File

@ -165,7 +165,7 @@ void ui_disconnected(void) {}
void chatwin_recipient_gone(ProfChatWin *chatwin) {} 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_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_outgoing_msg(ProfPrivateWin *privwin, const char * const message) {}
void privwin_occupant_offline(ProfPrivateWin *privwin) {} void privwin_occupant_offline(ProfPrivateWin *privwin) {}