Added pgp checks for message sending

This commit is contained in:
James Booth
2015-06-21 01:48:25 +01:00
parent 6617bb5a2b
commit e45afd5c09
9 changed files with 124 additions and 29 deletions

View File

@@ -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

View File

@@ -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);