mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge branch 'master' into pgp
This commit is contained in:
commit
43189b1ab4
@ -62,44 +62,14 @@ client_connect_account(ProfAccount *account)
|
||||
void
|
||||
client_send_msg(const char * const barejid, const char * const msg)
|
||||
{
|
||||
char *id = NULL;
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
prof_otrpolicy_t policy = otr_get_policy(barejid);
|
||||
|
||||
if (otr_is_secure(barejid)) {
|
||||
char *encrypted = otr_encrypt_message(barejid, msg);
|
||||
if (encrypted != NULL) {
|
||||
id = message_send_chat_encrypted(barejid, encrypted);
|
||||
chat_log_otr_msg_out(barejid, msg);
|
||||
ui_outgoing_chat_msg(barejid, msg, id);
|
||||
otr_free_message(encrypted);
|
||||
} else {
|
||||
cons_show_error("Failed to encrypt and send message.");
|
||||
}
|
||||
|
||||
} else if (policy == PROF_OTRPOLICY_ALWAYS) {
|
||||
cons_show_error("Failed to send message. Please check OTR policy");
|
||||
|
||||
} else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
|
||||
char *otr_tagged_msg = otr_tag_message(msg);
|
||||
id = message_send_chat_encrypted(barejid, otr_tagged_msg);
|
||||
ui_outgoing_chat_msg(barejid, msg, id);
|
||||
chat_log_msg_out(barejid, msg);
|
||||
free(otr_tagged_msg);
|
||||
|
||||
} else {
|
||||
id = message_send_chat(barejid, msg);
|
||||
ui_outgoing_chat_msg(barejid, msg, id);
|
||||
chat_log_msg_out(barejid, msg);
|
||||
}
|
||||
otr_on_message_send(barejid, msg);
|
||||
#else
|
||||
id = message_send_chat(barejid, msg);
|
||||
char *id = message_send_chat(barejid, msg);
|
||||
chat_log_msg_out(barejid, msg);
|
||||
ui_outgoing_chat_msg(barejid, msg, id);
|
||||
#endif
|
||||
|
||||
free(id);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -46,7 +46,6 @@
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
#include "otr/otr.h"
|
||||
#include <libotr/proto.h>
|
||||
#endif
|
||||
|
||||
#include "ui/ui.h"
|
||||
@ -321,45 +320,7 @@ void
|
||||
srv_incoming_message(char *barejid, char *resource, char *message)
|
||||
{
|
||||
#ifdef HAVE_LIBOTR
|
||||
gboolean was_decrypted = FALSE;
|
||||
char *newmessage;
|
||||
|
||||
prof_otrpolicy_t policy = otr_get_policy(barejid);
|
||||
char *whitespace_base = strstr(message,OTRL_MESSAGE_TAG_BASE);
|
||||
|
||||
//check for OTR whitespace (opportunistic or always)
|
||||
if (policy == PROF_OTRPOLICY_OPPORTUNISTIC || policy == PROF_OTRPOLICY_ALWAYS) {
|
||||
if (whitespace_base) {
|
||||
if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) {
|
||||
// Remove whitespace pattern for proper display in UI
|
||||
// Handle both BASE+TAGV1/2(16+8) and BASE+TAGV1+TAGV2(16+8+8)
|
||||
int tag_length = 24;
|
||||
if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) {
|
||||
tag_length = 32;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
newmessage = otr_decrypt_message(barejid, message, &was_decrypted);
|
||||
|
||||
// internal OTR message
|
||||
if (newmessage == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ui_incoming_msg(barejid, resource, newmessage, NULL);
|
||||
chat_log_otr_msg_in(barejid, newmessage, was_decrypted);
|
||||
otr_free_message(newmessage);
|
||||
otr_on_message_recv(barejid, resource, message);
|
||||
#else
|
||||
ui_incoming_msg(barejid, resource, message, NULL);
|
||||
chat_log_msg_in(barejid, message);
|
||||
|
@ -269,6 +269,87 @@ otr_on_connect(ProfAccount *account)
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
otr_on_message_recv(const char * const barejid, const char * const resource, const char * const message)
|
||||
{
|
||||
gboolean was_decrypted = FALSE;
|
||||
char *decrypted;
|
||||
|
||||
prof_otrpolicy_t policy = otr_get_policy(barejid);
|
||||
char *whitespace_base = strstr(message, OTRL_MESSAGE_TAG_BASE);
|
||||
|
||||
//check for OTR whitespace (opportunistic or always)
|
||||
if (policy == PROF_OTRPOLICY_OPPORTUNISTIC || policy == PROF_OTRPOLICY_ALWAYS) {
|
||||
if (whitespace_base) {
|
||||
if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) {
|
||||
// Remove whitespace pattern for proper display in UI
|
||||
// Handle both BASE+TAGV1/2(16+8) and BASE+TAGV1+TAGV2(16+8+8)
|
||||
int tag_length = 24;
|
||||
if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) {
|
||||
tag_length = 32;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
decrypted = otr_decrypt_message(barejid, message, &was_decrypted);
|
||||
|
||||
// internal OTR message
|
||||
if (decrypted == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ui_incoming_msg(barejid, resource, decrypted, NULL);
|
||||
chat_log_otr_msg_in(barejid, decrypted, was_decrypted);
|
||||
otr_free_message(decrypted);
|
||||
}
|
||||
|
||||
void
|
||||
otr_on_message_send(const char * const barejid, const char * const message)
|
||||
{
|
||||
char *id = NULL;
|
||||
|
||||
prof_otrpolicy_t policy = otr_get_policy(barejid);
|
||||
|
||||
if (otr_is_secure(barejid)) {
|
||||
char *encrypted = otr_encrypt_message(barejid, message);
|
||||
if (encrypted != NULL) {
|
||||
id = message_send_chat_encrypted(barejid, encrypted);
|
||||
chat_log_otr_msg_out(barejid, message);
|
||||
ui_outgoing_chat_msg(barejid, message, id);
|
||||
otr_free_message(encrypted);
|
||||
} else {
|
||||
cons_show_error("Failed to encrypt and send message.");
|
||||
}
|
||||
|
||||
} else if (policy == PROF_OTRPOLICY_ALWAYS) {
|
||||
cons_show_error("Failed to send message. Please check OTR policy");
|
||||
|
||||
} else if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
|
||||
char *otr_tagged_msg = otr_tag_message(message);
|
||||
id = message_send_chat_encrypted(barejid, otr_tagged_msg);
|
||||
ui_outgoing_chat_msg(barejid, message, id);
|
||||
chat_log_msg_out(barejid, message);
|
||||
free(otr_tagged_msg);
|
||||
|
||||
} else {
|
||||
id = message_send_chat(barejid, message);
|
||||
ui_outgoing_chat_msg(barejid, message, id);
|
||||
chat_log_msg_out(barejid, message);
|
||||
}
|
||||
|
||||
free(id);
|
||||
}
|
||||
|
||||
void
|
||||
otr_keygen(ProfAccount *account)
|
||||
{
|
||||
|
@ -56,6 +56,10 @@ char* otr_libotr_version(void);
|
||||
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(const char * const barejid, const char * const message);
|
||||
|
||||
void otr_keygen(ProfAccount *account);
|
||||
|
||||
char* otr_tag_message(const char * const msg);
|
||||
|
@ -41,6 +41,8 @@ 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(const char * const barejid, const char * const message) {}
|
||||
|
||||
void otr_keygen(ProfAccount *account)
|
||||
{
|
||||
@ -53,7 +55,7 @@ gboolean otr_key_loaded(void)
|
||||
}
|
||||
|
||||
char* otr_tag_message(const char * const msg)
|
||||
{
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user