mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Send private carbons element with message when encrypted
This commit is contained in:
parent
3c1e8c4e15
commit
2ff6873cf1
@ -1928,7 +1928,7 @@ _cmd_execute_default(const char * inp)
|
|||||||
if (otr_is_secure(chatwin->barejid)) {
|
if (otr_is_secure(chatwin->barejid)) {
|
||||||
char *encrypted = otr_encrypt_message(chatwin->barejid, inp);
|
char *encrypted = otr_encrypt_message(chatwin->barejid, inp);
|
||||||
if (encrypted != NULL) {
|
if (encrypted != NULL) {
|
||||||
message_send_chat(chatwin->barejid, encrypted);
|
message_send_chat_encrypted(chatwin->barejid, encrypted);
|
||||||
otr_free_message(encrypted);
|
otr_free_message(encrypted);
|
||||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||||
const char *jid = jabber_get_fulljid();
|
const char *jid = jabber_get_fulljid();
|
||||||
|
@ -1265,7 +1265,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
if (otr_is_secure(barejid)) {
|
if (otr_is_secure(barejid)) {
|
||||||
char *encrypted = otr_encrypt_message(barejid, msg);
|
char *encrypted = otr_encrypt_message(barejid, msg);
|
||||||
if (encrypted != NULL) {
|
if (encrypted != NULL) {
|
||||||
message_send_chat(barejid, encrypted);
|
message_send_chat_encrypted(barejid, encrypted);
|
||||||
otr_free_message(encrypted);
|
otr_free_message(encrypted);
|
||||||
ui_outgoing_chat_msg("me", barejid, msg);
|
ui_outgoing_chat_msg("me", barejid, msg);
|
||||||
|
|
||||||
@ -1294,7 +1294,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
GString *otr_message = g_string_new(msg);
|
GString *otr_message = g_string_new(msg);
|
||||||
g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE);
|
g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE);
|
||||||
g_string_append(otr_message, OTRL_MESSAGE_TAG_V2);
|
g_string_append(otr_message, OTRL_MESSAGE_TAG_V2);
|
||||||
message_send_chat(barejid, otr_message->str);
|
message_send_chat_encrypted(barejid, otr_message->str);
|
||||||
|
|
||||||
g_string_free(otr_message, TRUE);
|
g_string_free(otr_message, TRUE);
|
||||||
} else {
|
} else {
|
||||||
@ -3073,7 +3073,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
|
|||||||
if (otr_is_secure(chatwin->barejid)) {
|
if (otr_is_secure(chatwin->barejid)) {
|
||||||
char *encrypted = otr_encrypt_message(chatwin->barejid, tiny);
|
char *encrypted = otr_encrypt_message(chatwin->barejid, tiny);
|
||||||
if (encrypted != NULL) {
|
if (encrypted != NULL) {
|
||||||
message_send_chat(chatwin->barejid, encrypted);
|
message_send_chat_encrypted(chatwin->barejid, encrypted);
|
||||||
otr_free_message(encrypted);
|
otr_free_message(encrypted);
|
||||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||||
const char *jid = jabber_get_fulljid();
|
const char *jid = jabber_get_fulljid();
|
||||||
@ -4080,7 +4080,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
|||||||
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
|
||||||
} else if (!otr_is_secure(barejid)) {
|
} else if (!otr_is_secure(barejid)) {
|
||||||
char *otr_query_message = otr_start_query();
|
char *otr_query_message = otr_start_query();
|
||||||
message_send_chat(barejid, otr_query_message);
|
message_send_chat_encrypted(barejid, otr_query_message);
|
||||||
} else {
|
} else {
|
||||||
ui_gone_secure(barejid, otr_is_trusted(barejid));
|
ui_gone_secure(barejid, otr_is_trusted(barejid));
|
||||||
}
|
}
|
||||||
@ -4098,7 +4098,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
|||||||
} else {
|
} else {
|
||||||
ProfChatWin *chatwin = ui_get_current_chat();
|
ProfChatWin *chatwin = ui_get_current_chat();
|
||||||
char *otr_query_message = otr_start_query();
|
char *otr_query_message = otr_start_query();
|
||||||
message_send_chat(chatwin->barejid, otr_query_message);
|
message_send_chat_encrypted(chatwin->barejid, otr_query_message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ static void
|
|||||||
cb_inject_message(void *opdata, const char *accountname,
|
cb_inject_message(void *opdata, const char *accountname,
|
||||||
const char *protocol, const char *recipient, const char *message)
|
const char *protocol, const char *recipient, const char *message)
|
||||||
{
|
{
|
||||||
message_send_chat(recipient, message);
|
message_send_chat_encrypted(recipient, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -336,7 +336,7 @@ handle_incoming_message(char *barejid, char *resource, char *message)
|
|||||||
memmove(whitespace_base, whitespace_base+tag_length, tag_length);
|
memmove(whitespace_base, whitespace_base+tag_length, tag_length);
|
||||||
char *otr_query_message = otr_start_query();
|
char *otr_query_message = otr_start_query();
|
||||||
cons_show("OTR Whitespace pattern detected. Attempting to start OTR session...");
|
cons_show("OTR Whitespace pattern detected. Attempting to start OTR session...");
|
||||||
message_send_chat(barejid, otr_query_message);
|
message_send_chat_encrypted(barejid, otr_query_message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ handle_incoming_message(char *barejid, char *resource, char *message)
|
|||||||
if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) {
|
if (policy == PROF_OTRPOLICY_ALWAYS && !was_decrypted && !whitespace_base) {
|
||||||
char *otr_query_message = otr_start_query();
|
char *otr_query_message = otr_start_query();
|
||||||
cons_show("Attempting to start OTR session...");
|
cons_show("Attempting to start OTR session...");
|
||||||
message_send_chat(barejid, otr_query_message);
|
message_send_chat_encrypted(barejid, otr_query_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_incoming_msg(barejid, resource, newmessage, NULL);
|
ui_incoming_msg(barejid, resource, newmessage, NULL);
|
||||||
|
@ -93,14 +93,42 @@ message_send_chat(const char * const barejid, const char * const msg)
|
|||||||
state = STANZA_NAME_ACTIVE;
|
state = STANZA_NAME_ACTIVE;
|
||||||
}
|
}
|
||||||
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource);
|
||||||
message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state);
|
message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state, false);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
} else {
|
} else {
|
||||||
char *state = NULL;
|
char *state = NULL;
|
||||||
if (prefs_get_boolean(PREF_STATES)) {
|
if (prefs_get_boolean(PREF_STATES)) {
|
||||||
state = STANZA_NAME_ACTIVE;
|
state = STANZA_NAME_ACTIVE;
|
||||||
}
|
}
|
||||||
message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state);
|
message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_send(conn, message);
|
||||||
|
xmpp_stanza_release(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
message_send_chat_encrypted(const char * const barejid, const char * const msg)
|
||||||
|
{
|
||||||
|
xmpp_stanza_t *message;
|
||||||
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
|
|
||||||
|
ChatSession *session = chat_session_get(barejid);
|
||||||
|
if (session) {
|
||||||
|
char *state = NULL;
|
||||||
|
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);
|
||||||
|
message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state, true);
|
||||||
|
jid_destroy(jidp);
|
||||||
|
} else {
|
||||||
|
char *state = NULL;
|
||||||
|
if (prefs_get_boolean(PREF_STATES)) {
|
||||||
|
state = STANZA_NAME_ACTIVE;
|
||||||
|
}
|
||||||
|
message = stanza_create_message(ctx, barejid, STANZA_TYPE_CHAT, msg, state, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
xmpp_send(conn, message);
|
xmpp_send(conn, message);
|
||||||
@ -112,7 +140,7 @@ message_send_private(const char * const fulljid, const char * const msg)
|
|||||||
{
|
{
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *message = stanza_create_message(ctx, fulljid, STANZA_TYPE_CHAT, msg, NULL);
|
xmpp_stanza_t *message = stanza_create_message(ctx, fulljid, STANZA_TYPE_CHAT, msg, NULL, false);
|
||||||
|
|
||||||
xmpp_send(conn, message);
|
xmpp_send(conn, message);
|
||||||
xmpp_stanza_release(message);
|
xmpp_stanza_release(message);
|
||||||
@ -123,7 +151,7 @@ message_send_groupchat(const char * const roomjid, const char * const msg)
|
|||||||
{
|
{
|
||||||
xmpp_conn_t * const conn = connection_get_conn();
|
xmpp_conn_t * const conn = connection_get_conn();
|
||||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *message = stanza_create_message(ctx, roomjid, STANZA_TYPE_GROUPCHAT, msg, NULL);
|
xmpp_stanza_t *message = stanza_create_message(ctx, roomjid, STANZA_TYPE_GROUPCHAT, msg, NULL, false);
|
||||||
|
|
||||||
xmpp_send(conn, message);
|
xmpp_send(conn, message);
|
||||||
xmpp_stanza_release(message);
|
xmpp_stanza_release(message);
|
||||||
@ -424,7 +452,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if carbon message
|
// check if carbon message
|
||||||
xmpp_stanza_t *received = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
|
xmpp_stanza_t *received = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
|
||||||
if(received != NULL){
|
if(received != NULL){
|
||||||
xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(received, STANZA_NS_FORWARD);
|
xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(received, STANZA_NS_FORWARD);
|
||||||
xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE);
|
xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE);
|
||||||
@ -434,7 +462,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO);
|
gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO);
|
||||||
gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM);
|
gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM);
|
||||||
|
|
||||||
// happens when receive a carbon of a self sent message
|
// happens when receive a carbon of a self sent message
|
||||||
if(to == NULL) {
|
if(to == NULL) {
|
||||||
to = from;
|
to = from;
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char * const room, con
|
|||||||
xmpp_stanza_t *
|
xmpp_stanza_t *
|
||||||
stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
|
stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
|
||||||
const char * const type, const char * const message,
|
const char * const type, const char * const message,
|
||||||
const char * const state)
|
const char * const state, gboolean encrypted)
|
||||||
{
|
{
|
||||||
xmpp_stanza_t *msg, *body, *text;
|
xmpp_stanza_t *msg, *body, *text;
|
||||||
|
|
||||||
@ -314,6 +314,14 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
|
|||||||
xmpp_stanza_release(chat_state);
|
xmpp_stanza_release(chat_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (encrypted) {
|
||||||
|
xmpp_stanza_t *private_carbon = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(private_carbon, "private");
|
||||||
|
xmpp_stanza_set_ns(private_carbon, STANZA_NS_CARBONS);
|
||||||
|
xmpp_stanza_add_child(msg, private_carbon);
|
||||||
|
xmpp_stanza_release(private_carbon);
|
||||||
|
}
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ xmpp_stanza_t* stanza_create_chat_state(xmpp_ctx_t *ctx,
|
|||||||
|
|
||||||
xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx,
|
xmpp_stanza_t* stanza_create_message(xmpp_ctx_t *ctx,
|
||||||
const char * const recipient, const char * const type,
|
const char * const recipient, const char * const type,
|
||||||
const char * const message, const char * const state);
|
const char * const message, const char * const state, gboolean encrypted);
|
||||||
|
|
||||||
xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
|
xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
|
||||||
const char * const full_room_jid, const char * const passwd);
|
const char * const full_room_jid, const char * const passwd);
|
||||||
|
@ -146,6 +146,7 @@ GList * jabber_get_available_resources(void);
|
|||||||
|
|
||||||
// message functions
|
// message functions
|
||||||
void message_send_chat(const char * const barejid, const char * const msg);
|
void message_send_chat(const char * const barejid, const char * const msg);
|
||||||
|
void message_send_chat_encrypted(const char * const barejid, const char * const msg);
|
||||||
void message_send_private(const char * const fulljid, 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(const char * const roomjid, const char * const msg);
|
||||||
void message_send_groupchat_subject(const char * const roomjid, const char * const subject);
|
void message_send_groupchat_subject(const char * const roomjid, const char * const subject);
|
||||||
|
@ -551,8 +551,8 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
|
|||||||
will_return(otr_key_loaded, TRUE);
|
will_return(otr_key_loaded, TRUE);
|
||||||
will_return(otr_start_query, query_message);
|
will_return(otr_start_query, query_message);
|
||||||
|
|
||||||
expect_string(message_send_chat, barejid, chatwin->barejid);
|
expect_string(message_send_chat_encrypted, barejid, chatwin->barejid);
|
||||||
expect_string(message_send_chat, msg, query_message);
|
expect_string(message_send_chat_encrypted, msg, query_message);
|
||||||
|
|
||||||
gboolean result = cmd_otr(args, *help);
|
gboolean result = cmd_otr(args, *help);
|
||||||
assert_true(result);
|
assert_true(result);
|
||||||
|
@ -64,6 +64,12 @@ void message_send_chat(const char * const barejid, const char * const msg)
|
|||||||
check_expected(msg);
|
check_expected(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void message_send_chat_encrypted(const char * const barejid, const char * const msg)
|
||||||
|
{
|
||||||
|
check_expected(barejid);
|
||||||
|
check_expected(msg);
|
||||||
|
}
|
||||||
|
|
||||||
void message_send_private(const char * const fulljid, 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(const char * const roomjid, const char * const msg) {}
|
||||||
void message_send_groupchat_subject(const char * const roomjid, const char * const subject) {}
|
void message_send_groupchat_subject(const char * const roomjid, const char * const subject) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user