about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c4
-rw-r--r--src/event/client_events.c45
-rw-r--r--src/otr/otr.c37
-rw-r--r--src/otr/otr.h2
-rw-r--r--src/xmpp/message.c46
-rw-r--r--src/xmpp/xmpp.h3
6 files changed, 112 insertions, 25 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 6717157e..e4d96be6 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -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;
         }
 
diff --git a/src/event/client_events.c b/src/event/client_events.c
index e9a42d32..f1af8331 100644
--- a/src/event/client_events.c
+++ b/src/event/client_events.c
@@ -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
diff --git a/src/otr/otr.c b/src/otr/otr.c
index 1f63c8f9..f2f5833f 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_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
diff --git a/src/otr/otr.h b/src/otr/otr.h
index 3c46ac3d..6a358b52 100644
--- a/src/otr/otr.h
+++ b/src/otr/otr.h
@@ -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);
 
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 417c68ab..255bf39b 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -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();
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 26122d51..575f9ae1 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -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);