about summary refs log tree commit diff stats
path: root/src/event/client_events.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-02-14 22:28:55 +0000
committerJames Booth <boothj5@gmail.com>2016-02-14 22:28:55 +0000
commit41fe8c22b1f8c1cf666d42052cd73d59e40a2ed2 (patch)
tree3b53c1fbc2e5dc8c6daccf7fe7bb9f27d1c9d05a /src/event/client_events.c
parentf887a35c0cd550a3c635630da2bd83bb7400b957 (diff)
downloadprofani-tty-41fe8c22b1f8c1cf666d42052cd73d59e40a2ed2.tar.gz
Added C plugin code from plugins branch
Diffstat (limited to 'src/event/client_events.c')
-rw-r--r--src/event/client_events.c87
1 files changed, 51 insertions, 36 deletions
diff --git a/src/event/client_events.c b/src/event/client_events.c
index 0df4468e..71d1c3c0 100644
--- a/src/event/client_events.c
+++ b/src/event/client_events.c
@@ -32,7 +32,7 @@
  *
  */
 
-#include "config.h"
+#include "prof_config.h"
 
 #include <stdlib.h>
 #include <glib.h>
@@ -43,10 +43,11 @@
 #include "xmpp/xmpp.h"
 #include "roster_list.h"
 #include "chat_session.h"
-#ifdef HAVE_LIBOTR
+#include "plugins/plugins.h"
+#ifdef PROF_HAVE_LIBOTR
 #include "otr/otr.h"
 #endif
-#ifdef HAVE_LIBGPGME
+#ifdef PROF_HAVE_LIBGPGME
 #include "pgp/gpg.h"
 #endif
 
@@ -80,7 +81,7 @@ cl_ev_disconnect(void)
     muc_invites_clear();
     chat_sessions_clear();
     tlscerts_clear_current();
-#ifdef HAVE_LIBGPGME
+#ifdef PROF_HAVE_LIBGPGME
     p_gpg_on_disconnect();
 #endif
 }
@@ -90,7 +91,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char *const m
 {
     char *signed_status = NULL;
 
-#ifdef HAVE_LIBGPGME
+#ifdef PROF_HAVE_LIBGPGME
     char *account_name = jabber_get_account_name();
     ProfAccount *account = accounts_get_account(account_name);
     if (account->pgp_keyid) {
@@ -108,21 +109,22 @@ void
 cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
 {
     chat_state_active(chatwin->state);
+    char *plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg);
 
 // OTR suported, PGP supported
-#ifdef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
+#ifdef PROF_HAVE_LIBOTR
+#ifdef PROF_HAVE_LIBGPGME
     if (chatwin->pgp_send) {
-        char *id = message_send_chat_pgp(chatwin->barejid, msg);
-        chat_log_pgp_msg_out(chatwin->barejid, msg);
-        chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PGP);
+        char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg);
+        chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
+        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP);
         free(id);
     } else {
-        gboolean handled = otr_on_message_send(chatwin, msg);
+        gboolean handled = otr_on_message_send(chatwin, plugin_msg);
         if (!handled) {
-            char *id = message_send_chat(chatwin->barejid, msg);
-            chat_log_msg_out(chatwin->barejid, msg);
-            chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
+            char *id = message_send_chat(chatwin->barejid, plugin_msg);
+            chat_log_msg_out(chatwin->barejid, plugin_msg);
+            chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
             free(id);
         }
     }
@@ -131,13 +133,13 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
 #endif
 
 // OTR supported, PGP unsupported
-#ifdef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-    gboolean handled = otr_on_message_send(chatwin, msg);
+#ifdef PROF_HAVE_LIBOTR
+#ifndef PROF_HAVE_LIBGPGME
+    gboolean handled = otr_on_message_send(chatwin, plugin_msg);
     if (!handled) {
-        char *id = message_send_chat(chatwin->barejid, msg);
-        chat_log_msg_out(chatwin->barejid, msg);
-        chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
+        char *id = message_send_chat(chatwin->barejid, plugin_msg);
+        chat_log_msg_out(chatwin->barejid, plugin_msg);
+        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
         free(id);
     }
     return;
@@ -145,17 +147,17 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
 #endif
 
 // OTR unsupported, PGP supported
-#ifndef HAVE_LIBOTR
-#ifdef HAVE_LIBGPGME
+#ifndef PROF_HAVE_LIBOTR
+#ifdef PROF_HAVE_LIBGPGME
     if (chatwin->pgp_send) {
-        char *id = message_send_chat_pgp(chatwin->barejid, msg);
-        chat_log_pgp_msg_out(chatwin->barejid, msg);
-        chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PGP);
+        char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg);
+        chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
+        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP);
         free(id);
     } else {
-        char *id = message_send_chat(chatwin->barejid, msg);
-        chat_log_msg_out(chatwin->barejid, msg);
-        chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
+        char *id = message_send_chat(chatwin->barejid, plugin_msg);
+        chat_log_msg_out(chatwin->barejid, plugin_msg);
+        chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
         free(id);
     }
     return;
@@ -163,21 +165,29 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg)
 #endif
 
 // OTR unsupported, PGP unsupported
-#ifndef HAVE_LIBOTR
-#ifndef HAVE_LIBGPGME
-    char *id = message_send_chat(chatwin->barejid, msg);
-    chat_log_msg_out(chatwin->barejid, msg);
-    chatwin_outgoing_msg(chatwin, msg, id, PROF_MSG_PLAIN);
+#ifndef PROF_HAVE_LIBOTR
+#ifndef PROF_HAVE_LIBGPGME
+    char *id = message_send_chat(chatwin->barejid, plugin_msg);
+    chat_log_msg_out(chatwin->barejid, plugin_msg);
+    chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN);
     free(id);
     return;
 #endif
 #endif
+
+    plugins_post_chat_message_send(chatwin->barejid, plugin_msg);
+    free(plugin_msg);
 }
 
 void
 cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg)
 {
-    message_send_groupchat(mucwin->roomjid, msg);
+    char *plugin_msg = plugins_pre_room_message_send(mucwin->roomjid, msg);
+
+    message_send_groupchat(mucwin->roomjid, plugin_msg);
+
+    plugins_post_room_message_send(mucwin->roomjid, plugin_msg);
+    free(plugin_msg);
 }
 
 void
@@ -188,7 +198,12 @@ cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg)
     } else if (privwin->room_left) {
         privwin_message_left_room(privwin);
     } else {
-        message_send_private(privwin->fulljid, msg);
-        privwin_outgoing_msg(privwin, msg);
+        char *plugin_msg = plugins_pre_priv_message_send(privwin->fulljid, msg);
+
+        message_send_private(privwin->fulljid, plugin_msg);
+        privwin_outgoing_msg(privwin, plugin_msg);
+
+        plugins_post_priv_message_send(privwin->fulljid, plugin_msg);
+        free(plugin_msg);
     }
 }