about summary refs log tree commit diff stats
path: root/src/event
diff options
context:
space:
mode:
Diffstat (limited to 'src/event')
-rw-r--r--src/event/client_events.c187
-rw-r--r--src/event/server_events.c231
2 files changed, 40 insertions, 378 deletions
diff --git a/src/event/client_events.c b/src/event/client_events.c
index 96098ae0..15261760 100644
--- a/src/event/client_events.c
+++ b/src/event/client_events.c
@@ -131,181 +131,36 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
         replace_id = chatwin->last_msg_id;
     }
 
-// OTR suported, PGP supported, OMEMO unsupported
-#ifdef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    if (chatwin->pgp_send) {
-        char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id);
-        chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id);
-        free(id);
-    } else {
-        gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt, replace_id);
-        if (!handled) {
-            char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
-            chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
-            log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
-            chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
-            free(id);
-        }
-    }
-
-    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
-    free(plugin_msg);
-    return;
-#endif
-#endif
-#endif
-
-// OTR supported, PGP unsupported, OMEMO unsupported
-#ifdef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt, replace_id);
-    if (!handled) {
-        char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
-        chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt);
-        free(id);
-    }
-
-    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
-    free(plugin_msg);
-    return;
-#endif
-#endif
-#endif
-
-// OTR unsupported, PGP supported, OMEMO unsupported
-#ifndef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    if (chatwin->pgp_send) {
-        char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id);
-        chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id);
-        free(id);
-    } else {
-        char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
-        chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
-        free(id);
-    }
-
-    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
-    free(plugin_msg);
-    return;
-#endif
-#endif
-#endif
-
-// OTR unsupported, PGP unsupported, OMEMO supported
-#ifndef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
     if (chatwin->is_omemo) {
-        char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE, replace_id);
-        chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id);
-        free(id);
-    } else {
-        char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
-        chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
-        free(id);
-    }
-
-    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
-    free(plugin_msg);
-    return;
-#endif
-#endif
-#endif
-
-// OTR supported, PGP unsupported, OMEMO supported
-#ifdef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
 #ifdef HAVE_OMEMO
-    if (chatwin->is_omemo) {
         char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE, replace_id);
         chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL);
         log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
         chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id);
         free(id);
-    } else {
-        gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt, replace_id);
-        if (!handled) {
-            char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
-            chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
-            log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
-            chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
-            free(id);
-        }
-    }
-
-    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
-    free(plugin_msg);
-    return;
-#endif
-#endif
 #endif
-
-// OTR unsupported, PGP supported, OMEMO supported
-#ifndef HAVE_LIBOTR
+    } else if (chatwin->is_ox) {
 #ifdef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (chatwin->is_omemo) {
-        char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE, replace_id);
-        chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id);
-        free(id);
-    } else if (chatwin->pgp_send) {
-        char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id);
+        // XEP-0373: OpenPGP for XMPP
+        char *id = message_send_chat_ox(chatwin->barejid, plugin_msg, request_receipt, replace_id);
         chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id);
-        free(id);
-    } else {
-        char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
-        chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
+        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OX);
+        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OX, request_receipt, replace_id);
         free(id);
-    }
-
-    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
-    free(plugin_msg);
-    return;
 #endif
-#endif
-#endif
-
-// OTR supported, PGP supported, OMEMO supported
-#ifdef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (chatwin->is_omemo) {
-        char *id = omemo_on_message_send((ProfWin *)chatwin, plugin_msg, request_receipt, FALSE, replace_id);
-        chat_log_omemo_msg_out(chatwin->barejid, plugin_msg, NULL);
-        log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_OMEMO);
-        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt, replace_id);
-        free(id);
     } else if (chatwin->pgp_send) {
+#ifdef HAVE_LIBGPGME
         char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt, replace_id);
         chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
         log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_PGP);
         chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt, replace_id);
         free(id);
+#endif
     } else {
-        gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt, replace_id);
+        gboolean handled = FALSE;
+#ifdef HAVE_LIBOTR
+         handled = otr_on_message_send(chatwin, plugin_msg, request_receipt, replace_id);
+#endif
         if (!handled) {
             char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
             chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
@@ -318,26 +173,6 @@ cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *
     plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
     free(plugin_msg);
     return;
-#endif
-#endif
-#endif
-
-// OTR unsupported, PGP unsupported, OMEMO unsupported
-#ifndef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
-    chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
-    log_database_add_outgoing_chat(id, chatwin->barejid, plugin_msg, replace_id, PROF_MSG_ENC_NONE);
-    chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_NONE, request_receipt, replace_id);
-    free(id);
-
-    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
-    free(plugin_msg);
-    return;
-#endif
-#endif
-#endif
 }
 
 void
diff --git a/src/event/server_events.c b/src/event/server_events.c
index 44fef42c..137c6cd9 100644
--- a/src/event/server_events.c
+++ b/src/event/server_events.c
@@ -457,49 +457,10 @@ sv_ev_outgoing_carbon(ProfMessage *message)
         log_database_add_incoming(message);
     }
 
-#ifdef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    if (message->encrypted) {
-        message->plain = p_gpg_decrypt(message->encrypted);
-        if (message->plain) {
-            message->enc = PROF_MSG_ENC_PGP;
-            chatwin_outgoing_carbon(chatwin, message);
-        } else {
-            if (!message->body) {
-                log_error("Couldn't decrypt GPG message and body was empty");
-                return;
-            }
-            message->enc = PROF_MSG_ENC_NONE;
-            message->plain = strdup(message->body);
-            chatwin_outgoing_carbon(chatwin, message);
-        }
-    } else {
-        message->enc = PROF_MSG_ENC_NONE;
-        message->plain = strdup(message->body);
-        chatwin_outgoing_carbon(chatwin, message);
-    }
-    return;
-#endif
-#endif
-
-#ifndef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (message->enc == PROF_MSG_ENC_OMEMO) {
-        chatwin_outgoing_carbon(chatwin, message);
-    } else {
-        message->enc = PROF_MSG_ENC_NONE;
-        message->plain = strdup(message->body);
-        chatwin_outgoing_carbon(chatwin, message);
-    }
-    return;
-#endif
-#endif
-
-#ifdef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
     if (message->enc == PROF_MSG_ENC_OMEMO) {
         chatwin_outgoing_carbon(chatwin, message);
     } else if (message->encrypted) {
+#ifdef HAVE_LIBGPGME
         message->plain = p_gpg_decrypt(message->encrypted);
         if (message->plain) {
             message->enc = PROF_MSG_ENC_PGP;
@@ -513,30 +474,20 @@ sv_ev_outgoing_carbon(ProfMessage *message)
             message->plain = strdup(message->body);
             chatwin_outgoing_carbon(chatwin, message);
         }
+#endif
     } else {
         message->enc = PROF_MSG_ENC_NONE;
         message->plain = strdup(message->body);
         chatwin_outgoing_carbon(chatwin, message);
     }
     return;
-#endif
-#endif
 
-#ifndef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    if (message->body) {
-        message->enc = PROF_MSG_ENC_NONE;
-        message->plain = strdup(message->body);
-        chatwin_outgoing_carbon(chatwin, message);
-    }
-#endif
-#endif
 }
 
-#ifdef HAVE_LIBGPGME
 static void
 _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message, gboolean logit)
 {
+#ifdef HAVE_LIBGPGME
     message->plain = p_gpg_decrypt(message->encrypted);
     if (message->plain) {
         message->enc = PROF_MSG_ENC_PGP;
@@ -562,13 +513,29 @@ _sv_ev_incoming_pgp(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
         chat_log_msg_in(message);
         chatwin->pgp_recv = FALSE;
     }
+#endif
 }
+
+static void
+_sv_ev_incoming_ox(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message, gboolean logit)
+{
+#ifdef HAVE_LIBGPGME
+        //_clean_incoming_message(message);
+        chatwin_incoming_msg(chatwin, message, new_win);
+        log_database_add_incoming(message);
+        if (logit) {
+            chat_log_pgp_msg_in(message);
+        }
+        chatwin->pgp_recv = TRUE;
+        //p_gpg_free_decrypted(message->plain);
+        message->plain = NULL;
 #endif
+}
 
-#ifdef HAVE_LIBOTR
 static void
 _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message)
 {
+#ifdef HAVE_LIBOTR
     gboolean decrypted = FALSE;
     message->plain = otr_on_message_recv(message->from_jid->barejid, message->from_jid->resourcepart, message->body, &decrypted);
     if (message->plain) {
@@ -588,13 +555,13 @@ _sv_ev_incoming_otr(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message
         message->plain = NULL;
         chatwin->pgp_recv = FALSE;
     }
-}
 #endif
+}
 
-#ifdef HAVE_OMEMO
 static void
 _sv_ev_incoming_omemo(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message, gboolean logit)
 {
+#ifdef HAVE_OMEMO
     _clean_incoming_message(message);
     chatwin_incoming_msg(chatwin, message, new_win);
     log_database_add_incoming(message);
@@ -602,8 +569,8 @@ _sv_ev_incoming_omemo(ProfChatWin *chatwin, gboolean new_win, ProfMessage *messa
         chat_log_omemo_msg_in(message);
     }
     chatwin->pgp_recv = FALSE;
-}
 #endif
+}
 
 static void
 _sv_ev_incoming_plain(ProfChatWin *chatwin, gboolean new_win, ProfMessage *message, gboolean logit)
@@ -653,56 +620,9 @@ sv_ev_incoming_message(ProfMessage *message)
 #endif
     }
 
-// OTR suported, PGP supported, OMEMO unsupported
-#ifdef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    if (message->encrypted) {
-        if (chatwin->is_otr) {
-            win_println((ProfWin*)chatwin, THEME_DEFAULT, "-", "PGP encrypted message received whilst in OTR session.");
-        } else {
-            _sv_ev_incoming_pgp(chatwin, new_win, message, TRUE);
-        }
-    } else {
-        _sv_ev_incoming_otr(chatwin, new_win, message);
-    }
-    rosterwin_roster();
-    return;
-#endif
-#endif
-#endif
-
-// OTR supported, PGP unsupported, OMEMO unsupported
-#ifdef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    _sv_ev_incoming_otr(chatwin, new_win, message);
-    rosterwin_roster();
-    return;
-#endif
-#endif
-#endif
-
-// OTR unsupported, PGP supported, OMEMO unsupported
-#ifndef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    if (message->encrypted) {
-        _sv_ev_incoming_pgp(chatwin, new_win, message, TRUE);
-    } else {
-        _sv_ev_incoming_plain(chatwin, new_win, message, TRUE);
-    }
-    rosterwin_roster();
-    return;
-#endif
-#endif
-#endif
-
-// OTR suported, PGP supported, OMEMO supported
-#ifdef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (message->encrypted) {
+    if( message->enc == PROF_MSG_ENC_OX) {
+	 _sv_ev_incoming_ox(chatwin, new_win, message, TRUE);
+    } else if (message->encrypted) {
         if (chatwin->is_otr) {
             win_println((ProfWin*)chatwin, THEME_DEFAULT, "-", "PGP encrypted message received whilst in OTR session.");
         } else {
@@ -715,67 +635,7 @@ sv_ev_incoming_message(ProfMessage *message)
     }
     rosterwin_roster();
     return;
-#endif
-#endif
-#endif
-
-// OTR supported, PGP unsupported, OMEMO supported
-#ifdef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (message->enc == PROF_MSG_ENC_OMEMO) {
-        _sv_ev_incoming_omemo(chatwin, new_win, message, TRUE);
-    } else {
-        _sv_ev_incoming_otr(chatwin, new_win, message);
-    }
-    rosterwin_roster();
-    return;
-#endif
-#endif
-#endif
-
-// OTR unsupported, PGP supported, OMEMO supported
-#ifndef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (message->encrypted) {
-        _sv_ev_incoming_pgp(chatwin, new_win, message, TRUE);
-    } else if (message->enc == PROF_MSG_ENC_OMEMO) {
-        _sv_ev_incoming_omemo(chatwin, new_win, message, TRUE);
-    } else {
-        _sv_ev_incoming_plain(chatwin, new_win, message, TRUE);
-    }
-    rosterwin_roster();
-    return;
-#endif
-#endif
-#endif
-
-// OTR unsupported, PGP unsupported, OMEMO supported
-#ifndef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (message->enc == PROF_MSG_ENC_OMEMO) {
-        _sv_ev_incoming_omemo(chatwin, new_win, message, TRUE);
-    } else {
-        _sv_ev_incoming_plain(chatwin, new_win, message, TRUE);
-    }
-    rosterwin_roster();
-    return;
-#endif
-#endif
-#endif
 
-// OTR unsupported, PGP unsupported, OMEMO unsupported
-#ifndef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    _sv_ev_incoming_plain(chatwin, new_win, message, TRUE);
-    rosterwin_roster();
-    return;
-#endif
-#endif
-#endif
 }
 
 void
@@ -796,21 +656,9 @@ sv_ev_incoming_carbon(ProfMessage *message)
 #endif
     }
 
-#ifdef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    if (message->encrypted) {
-        _sv_ev_incoming_pgp(chatwin, new_win, message, FALSE);
-    } else {
-        _sv_ev_incoming_plain(chatwin, new_win, message, FALSE);
-    }
-    rosterwin_roster();
-    return;
-#endif
-#endif
-
-#ifdef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (message->encrypted) {
+    if (message->enc == PROF_MSG_ENC_OX) {
+        _sv_ev_incoming_ox(chatwin, new_win, message, FALSE);
+    } else if (message->encrypted) {
         _sv_ev_incoming_pgp(chatwin, new_win, message, FALSE);
     } else if (message->enc == PROF_MSG_ENC_OMEMO) {
         _sv_ev_incoming_omemo(chatwin, new_win, message, FALSE);
@@ -819,28 +667,7 @@ sv_ev_incoming_carbon(ProfMessage *message)
     }
     rosterwin_roster();
     return;
-#endif
-#endif
-
-#ifndef HAVE_LIBGPGME
-#ifdef HAVE_OMEMO
-    if (message->enc == PROF_MSG_ENC_OMEMO) {
-        _sv_ev_incoming_omemo(chatwin, new_win, message, FALSE);
-    } else {
-        _sv_ev_incoming_plain(chatwin, new_win, message, FALSE);
-    }
-    rosterwin_roster();
-    return;
-#endif
-#endif
 
-#ifndef HAVE_LIBGPGME
-#ifndef HAVE_OMEMO
-    _sv_ev_incoming_plain(chatwin, new_win, message, FALSE);
-    rosterwin_roster();
-    return;
-#endif
-#endif
 }
 
 void