about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/command.c2
-rw-r--r--src/command/commands.c10
-rw-r--r--src/otr/otr.c2
-rw-r--r--src/server_events.c4
-rw-r--r--src/xmpp/message.c40
-rw-r--r--src/xmpp/stanza.c10
-rw-r--r--src/xmpp/stanza.h2
-rw-r--r--src/xmpp/xmpp.h1
-rw-r--r--tests/test_cmd_otr.c4
-rw-r--r--tests/xmpp/stub_xmpp.c6
10 files changed, 62 insertions, 19 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 6502af75..6a5603ee 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -1928,7 +1928,7 @@ _cmd_execute_default(const char * inp)
                 if (otr_is_secure(chatwin->barejid)) {
                     char *encrypted = otr_encrypt_message(chatwin->barejid, inp);
                     if (encrypted != NULL) {
-                        message_send_chat(chatwin->barejid, encrypted);
+                        message_send_chat_encrypted(chatwin->barejid, encrypted);
                         otr_free_message(encrypted);
                         if (prefs_get_boolean(PREF_CHLOG)) {
                             const char *jid = jabber_get_fulljid();
diff --git a/src/command/commands.c b/src/command/commands.c
index 8c93b065..2ca749fb 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1265,7 +1265,7 @@ cmd_msg(gchar **args, struct cmd_help_t help)
             if (otr_is_secure(barejid)) {
                 char *encrypted = otr_encrypt_message(barejid, msg);
                 if (encrypted != NULL) {
-                    message_send_chat(barejid, encrypted);
+                    message_send_chat_encrypted(barejid, encrypted);
                     otr_free_message(encrypted);
                     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);
                     g_string_append(otr_message, OTRL_MESSAGE_TAG_BASE);
                     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);
                 } else {
@@ -3073,7 +3073,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help)
                 if (otr_is_secure(chatwin->barejid)) {
                     char *encrypted = otr_encrypt_message(chatwin->barejid, tiny);
                     if (encrypted != NULL) {
-                        message_send_chat(chatwin->barejid, encrypted);
+                        message_send_chat_encrypted(chatwin->barejid, encrypted);
                         otr_free_message(encrypted);
                         if (prefs_get_boolean(PREF_CHLOG)) {
                             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'");
                 } else if (!otr_is_secure(barejid)) {
                     char *otr_query_message = otr_start_query();
-                    message_send_chat(barejid, otr_query_message);
+                    message_send_chat_encrypted(barejid, otr_query_message);
                 } else {
                     ui_gone_secure(barejid, otr_is_trusted(barejid));
                 }
@@ -4098,7 +4098,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
                 } else {
                     ProfChatWin *chatwin = ui_get_current_chat();
                     char *otr_query_message = otr_start_query();
-                    message_send_chat(chatwin->barejid, otr_query_message);
+                    message_send_chat_encrypted(chatwin->barejid, otr_query_message);
                 }
             }
         }
diff --git a/src/otr/otr.c b/src/otr/otr.c
index 7c500e71..d0515e97 100644
--- a/src/otr/otr.c
+++ b/src/otr/otr.c
@@ -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(recipient, message);
+    message_send_chat_encrypted(recipient, message);
 }
 
 static void
diff --git a/src/server_events.c b/src/server_events.c
index e5602b87..b0a9b1e3 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -336,7 +336,7 @@ handle_incoming_message(char *barejid, char *resource, char *message)
                 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(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) {
         char *otr_query_message = otr_start_query();
         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);
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index df6afed6..ab7f52cd 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -93,14 +93,42 @@ message_send_chat(const char * const barejid, const char * const msg)
             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);
+        message = stanza_create_message(ctx, jidp->fulljid, STANZA_TYPE_CHAT, msg, state, false);
         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);
+        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);
@@ -112,7 +140,7 @@ message_send_private(const char * const fulljid, const char * const msg)
 {
     xmpp_conn_t * const conn = connection_get_conn();
     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_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_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_stanza_release(message);
@@ -424,7 +452,7 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     }
 
     // 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){
         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);
@@ -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 *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) {
             to = from;
         }
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 9b1431a9..e849ac97 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -284,7 +284,7 @@ stanza_create_room_subject_message(xmpp_ctx_t *ctx, const char * const room, con
 xmpp_stanza_t *
 stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
     const char * const type, const char * const message,
-    const char * const state)
+    const char * const state, gboolean encrypted)
 {
     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);
     }
 
+    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;
 }
 
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 4291e1fd..365bed86 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -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,
     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,
     const char * const full_room_jid, const char * const passwd);
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 724e11c4..e8e79ee9 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -146,6 +146,7 @@ GList * jabber_get_available_resources(void);
 
 // message functions
 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_groupchat(const char * const roomjid, const char * const msg);
 void message_send_groupchat_subject(const char * const roomjid, const char * const subject);
diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c
index c6c6f7cf..dae17947 100644
--- a/tests/test_cmd_otr.c
+++ b/tests/test_cmd_otr.c
@@ -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_start_query, query_message);
 
-    expect_string(message_send_chat, barejid, chatwin->barejid);
-    expect_string(message_send_chat, msg, query_message);
+    expect_string(message_send_chat_encrypted, barejid, chatwin->barejid);
+    expect_string(message_send_chat_encrypted, msg, query_message);
 
     gboolean result = cmd_otr(args, *help);
     assert_true(result);
diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c
index dc9a258e..9ca0c2d4 100644
--- a/tests/xmpp/stub_xmpp.c
+++ b/tests/xmpp/stub_xmpp.c
@@ -64,6 +64,12 @@ void message_send_chat(const char * const barejid, const char * const 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_groupchat(const char * const roomjid, const char * const msg) {}
 void message_send_groupchat_subject(const char * const roomjid, const char * const subject) {}
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103