mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added pgp checks for message sending
This commit is contained in:
parent
6617bb5a2b
commit
e45afd5c09
@ -4415,7 +4415,7 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
|
||||
|
||||
if (!otr_is_secure(barejid)) {
|
||||
char *otr_query_message = otr_start_query();
|
||||
message_send_chat_encrypted(barejid, otr_query_message);
|
||||
message_send_chat_otr(barejid, otr_query_message);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -4442,7 +4442,7 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
|
||||
}
|
||||
|
||||
char *otr_query_message = otr_start_query();
|
||||
message_send_chat_encrypted(chatwin->barejid, otr_query_message);
|
||||
message_send_chat_otr(chatwin->barejid, otr_query_message);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -88,13 +88,52 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg)
|
||||
chat_state_active(chatwin->state);
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
otr_on_message_send(chatwin, msg);
|
||||
#else
|
||||
if (chatwin->enc_mode == PROF_ENC_NONE || chatwin->enc_mode == PROF_ENC_OTR) {
|
||||
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);
|
||||
free(id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#ifdef HAVE_LIBGPGME
|
||||
if (chatwin->enc_mode == PROF_ENC_PGP) {
|
||||
char *id = message_send_chat_pgp(chatwin->barejid, msg);
|
||||
// TODO pgp message logger
|
||||
chat_log_msg_out(chatwin->barejid, msg);
|
||||
ui_outgoing_chat_msg(chatwin, msg, id);
|
||||
free(id);
|
||||
return;
|
||||
}
|
||||
#endif // HAVE_LIBGPGME
|
||||
|
||||
#else // HAVE_LIBOTR
|
||||
|
||||
#ifdef HAVE_LIBGPGME
|
||||
if (chatwin->enc_mode == PROF_ENC_PGP) {
|
||||
char *id = message_send_chat_pgp(chatwin->barejid, msg);
|
||||
chat_log_msg_out(chatwin->barejid, msg);
|
||||
ui_outgoing_chat_msg(chatwin, msg, id);
|
||||
free(id);
|
||||
return;
|
||||
}
|
||||
|
||||
char *id = message_send_chat(chatwin->barejid, msg);
|
||||
chat_log_msg_out(chatwin->barejid, msg);
|
||||
ui_outgoing_chat_msg(chatwin, msg, id);
|
||||
free(id);
|
||||
#endif
|
||||
return;
|
||||
#else // HAVE_LIBGPGME
|
||||
char *id = message_send_chat(chatwin->barejid, msg);
|
||||
chat_log_msg_out(chatwin->barejid, msg);
|
||||
ui_outgoing_chat_msg(chatwin, msg, id);
|
||||
free(id);
|
||||
return;
|
||||
#endif // HAVE_LIBGPGME
|
||||
|
||||
#endif // HAVE_LIBOTR
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -110,7 +110,7 @@ static void
|
||||
cb_inject_message(void *opdata, const char *accountname,
|
||||
const char *protocol, const char *recipient, const char *message)
|
||||
{
|
||||
message_send_chat_encrypted(recipient, message);
|
||||
message_send_chat_otr(recipient, message);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -294,7 +294,7 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con
|
||||
memmove(whitespace_base, whitespace_base+tag_length, tag_length);
|
||||
char *otr_query_message = otr_start_query();
|
||||
cons_show("OTR Whitespace pattern detected. Attempting to start OTR session...");
|
||||
message_send_chat_encrypted(barejid, otr_query_message);
|
||||
message_send_chat_otr(barejid, otr_query_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,7 +308,7 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con
|
||||
if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) {
|
||||
char *otr_query_message = otr_start_query();
|
||||
cons_show("Attempting to start OTR session...");
|
||||
message_send_chat_encrypted(barejid, otr_query_message);
|
||||
message_send_chat_otr(barejid, otr_query_message);
|
||||
}
|
||||
|
||||
ui_incoming_msg(barejid, resource, decrypted, NULL);
|
||||
@ -316,43 +316,46 @@ otr_on_message_recv(const char * const barejid, const char * const resource, con
|
||||
otr_free_message(decrypted);
|
||||
}
|
||||
|
||||
void
|
||||
gboolean
|
||||
otr_on_message_send(ProfChatWin *chatwin, const char * const message)
|
||||
{
|
||||
char *id = NULL;
|
||||
|
||||
prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid);
|
||||
|
||||
// Send encrypted message
|
||||
if (otr_is_secure(chatwin->barejid)) {
|
||||
char *encrypted = otr_encrypt_message(chatwin->barejid, message);
|
||||
if (encrypted) {
|
||||
id = message_send_chat_encrypted(chatwin->barejid, encrypted);
|
||||
id = message_send_chat_otr(chatwin->barejid, encrypted);
|
||||
chat_log_otr_msg_out(chatwin->barejid, message);
|
||||
ui_outgoing_chat_msg(chatwin, message, id);
|
||||
otr_free_message(encrypted);
|
||||
free(id);
|
||||
return TRUE;
|
||||
} else {
|
||||
ui_win_error_line((ProfWin*)chatwin, "Failed to encrypt and send message.");
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (policy == PROF_OTRPOLICY_ALWAYS) {
|
||||
// show error if not secure and policy always
|
||||
if (policy == PROF_OTRPOLICY_ALWAYS) {
|
||||
ui_win_error_line((ProfWin*)chatwin, "Failed to send message. OTR policy set to: always");
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
} else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
|
||||
// tag and send for policy opportunistic
|
||||
if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
|
||||
char *otr_tagged_msg = otr_tag_message(message);
|
||||
id = message_send_chat_encrypted(chatwin->barejid, otr_tagged_msg);
|
||||
id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg);
|
||||
ui_outgoing_chat_msg(chatwin, message, id);
|
||||
chat_log_msg_out(chatwin->barejid, message);
|
||||
free(otr_tagged_msg);
|
||||
|
||||
} else {
|
||||
id = message_send_chat(chatwin->barejid, message);
|
||||
ui_outgoing_chat_msg(chatwin, message, id);
|
||||
chat_log_msg_out(chatwin->barejid, message);
|
||||
free(id);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
free(id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -59,7 +59,7 @@ void otr_poll(void);
|
||||
void otr_on_connect(ProfAccount *account);
|
||||
|
||||
void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message);
|
||||
void otr_on_message_send(ProfChatWin *chatwin, const char * const message);
|
||||
gboolean otr_on_message_send(ProfChatWin *chatwin, const char * const message);
|
||||
|
||||
void otr_keygen(ProfAccount *account);
|
||||
|
||||
|
@ -103,6 +103,49 @@ message_send_chat(const char * const barejid, const char * const msg)
|
||||
|
||||
char *id = create_unique_id("msg");
|
||||
xmpp_stanza_t *message = NULL;
|
||||
message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
|
||||
|
||||
free(jid);
|
||||
|
||||
if (state) {
|
||||
stanza_attach_state(ctx, message, state);
|
||||
}
|
||||
if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) {
|
||||
stanza_attach_receipt_request(ctx, message);
|
||||
}
|
||||
|
||||
xmpp_send(conn, message);
|
||||
xmpp_stanza_release(message);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
char *
|
||||
message_send_chat_pgp(const char * const barejid, const char * const msg)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
|
||||
ChatSession *session = chat_session_get(barejid);
|
||||
char *state = NULL;
|
||||
char *jid = NULL;
|
||||
if (session) {
|
||||
if (prefs_get_boolean(PREF_STATES) && session->send_states) {
|
||||
state = STANZA_NAME_ACTIVE;
|
||||
}
|
||||
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
||||
jid = strdup(jidp->fulljid);
|
||||
jid_destroy(jidp);
|
||||
|
||||
} else {
|
||||
if (prefs_get_boolean(PREF_STATES)) {
|
||||
state = STANZA_NAME_ACTIVE;
|
||||
}
|
||||
jid = strdup(barejid);
|
||||
}
|
||||
|
||||
char *id = create_unique_id("msg");
|
||||
xmpp_stanza_t *message = NULL;
|
||||
|
||||
#ifdef HAVE_LIBGPGME
|
||||
char *account_name = jabber_get_account_name();
|
||||
@ -137,6 +180,7 @@ message_send_chat(const char * const barejid, const char * const msg)
|
||||
if (state) {
|
||||
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);
|
||||
}
|
||||
@ -148,7 +192,7 @@ message_send_chat(const char * const barejid, const char * const msg)
|
||||
}
|
||||
|
||||
char *
|
||||
message_send_chat_encrypted(const char * const barejid, const char * const msg)
|
||||
message_send_chat_otr(const char * const barejid, const char * const msg)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
|
@ -146,7 +146,8 @@ GList * jabber_get_available_resources(void);
|
||||
|
||||
// message functions
|
||||
char* message_send_chat(const char * const barejid, const char * const msg);
|
||||
char* message_send_chat_encrypted(const char * const barejid, const char * const msg);
|
||||
char* message_send_chat_otr(const char * const barejid, const char * const msg);
|
||||
char* message_send_chat_pgp(const char * const barejid, const char * const msg);
|
||||
void message_send_private(const char * const fulljid, const char * const msg);
|
||||
void message_send_groupchat(const char * const roomjid, const char * const msg);
|
||||
void message_send_groupchat_subject(const char * const roomjid, const char * const subject);
|
||||
|
@ -42,7 +42,10 @@ char* otr_start_query(void)
|
||||
void otr_poll(void) {}
|
||||
void otr_on_connect(ProfAccount *account) {}
|
||||
void otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message) {}
|
||||
void otr_on_message_send(ProfChatWin *chatwin, const char * const message) {}
|
||||
gboolean otr_on_message_send(ProfChatWin *chatwin, const char * const message)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void otr_keygen(ProfAccount *account)
|
||||
{
|
||||
|
@ -576,8 +576,8 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
|
||||
will_return(otr_key_loaded, TRUE);
|
||||
will_return(otr_start_query, query_message);
|
||||
|
||||
expect_string(message_send_chat_encrypted, barejid, recipient);
|
||||
expect_string(message_send_chat_encrypted, msg, query_message);
|
||||
expect_string(message_send_chat_otr, barejid, recipient);
|
||||
expect_string(message_send_chat_otr, msg, query_message);
|
||||
|
||||
gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help);
|
||||
assert_true(result);
|
||||
|
@ -65,13 +65,18 @@ char* message_send_chat(const char * const barejid, const char * const msg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* message_send_chat_encrypted(const char * const barejid, const char * const msg)
|
||||
char* message_send_chat_otr(const char * const barejid, const char * const msg)
|
||||
{
|
||||
check_expected(barejid);
|
||||
check_expected(msg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* message_send_chat_pgp(const char * const barejid, const char * const msg)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void message_send_private(const char * const fulljid, const char * const msg) {}
|
||||
void message_send_groupchat(const char * const roomjid, const char * const msg) {}
|
||||
void message_send_groupchat_subject(const char * const roomjid, const char * const subject) {}
|
||||
|
Loading…
Reference in New Issue
Block a user