made remote msg hooks more robust
authorMatthew Wiggins <lithium@rubiks.net>
Wed, 19 Jan 2005 22:05:45 +0000 (22:05 +0000)
committerMatthew Wiggins <lithium@rubiks.net>
Wed, 19 Jan 2005 22:05:45 +0000 (22:05 +0000)
include/hooks.h
modules/remotemsg-example.c
src/modules.c
src/s_user.c

index fc68fe3..a22a6cd 100644 (file)
@@ -31,10 +31,16 @@ enum c_hooktype {
                        * Returns int 
                        */
 #ifdef MODULE_HOOK_REMOTEMSG
-   CHOOK_REMOTEMSG,      /* called for privmsg or notice from !MyClient()
-                                          * Params: 5: (aClient *, aClient *,int isnotice,char *dest, char *msgtxt),
+   CHOOK_REM_MSG,        /* called for privmsg or notice from !MyClient()
+                                          * Params: 3: (aClient *, int isnotice, char *msgtxt),
                                           * Returns int
                                           */
+   CHOOK_REM_CHANMSG,  /* called for every privmsg or notice to a channel 
+                                          * Params: 4:  (aClient *source, aChannel *destination, int isnotice, char *msgtxt)
+                                          */
+   CHOOK_REM_USERMSG,  /* called for privmsg or notice to a local client
+                                          * Params: 4: (aClient *source, aClient *destination, int isnotice, char *msgtxt)
+                                          */
 #endif
    CHOOK_CHANMSG,     /* called for every privmsg or notice to a channel
                        * Params: 4: (aClient *source, aChannel *destination, 
index e167150..201e0eb 100644 (file)
 /* gcc -I../include -shared remotemsg-test.c -o /usr/IRCd/modules/test.so  */
 
 int
-hook_rmsg(aClient *serv, aClient *src, int notice, char *dest, char *text)
+hook_both_usermsg(aClient *src, aClient *dest, int notice, char *text)
 {
-       sendto_serv_butone(&me, ":%s NOTICE %s :Hey %s i got your msg to %s [%s]",
-                       me.name, src->name, src->name, dest, text);
+       if (mycmp(dest->name, "god"))
+               return 0;
+
+       if (MyClient(src))
+       {
+               sendto_one(src, ":%s NOTICE %s :Hey %s i got your msg to %s [%s]",
+                       me.name, src->name, src->name, dest->name, text);
+       } 
+       else
+       {
+               sendto_serv_butone(&me, ":%s NOTICE %s :Hey %s i snooped your msg to %s [%s]",
+                       me.name, src->name, src->name, dest->name, text);
+       }
        return 0;
 }
 
 int bircmodule_init(void *self)
 {
-       bircmodule_add_hook(CHOOK_REMOTEMSG, self, hook_rmsg);
+       bircmodule_add_hook(CHOOK_REM_USERMSG, self, hook_both_usermsg);
+       bircmodule_add_hook(CHOOK_USERMSG, self, hook_both_usermsg);
        return 0;
 }
 
index cd579e0..7c9106f 100644 (file)
@@ -3,7 +3,7 @@
  *   Copyright (C) 2003, Lucas Madar
  */
 
-/* $Id: modules.c,v 1.2 2005/01/15 23:35:03 mwiggins Exp $ */
+/* $Id: modules.c,v 1.3 2005/01/19 22:05:45 mwiggins Exp $ */
 
 #include "struct.h"
 #include "common.h"
@@ -475,7 +475,9 @@ static DLink *postaccess_hooks = NULL;
 static DLink *postmotd_hooks = NULL;
 static DLink *msg_hooks = NULL;
 #ifdef MODULE_HOOK_REMOTEMSG
-static DLink *remotemsg_hooks = NULL;
+static DLink *rem_msg_hooks = NULL;
+static DLink *rem_chanmsg_hooks = NULL;
+static DLink *rem_usermsg_hooks = NULL;
 #endif
 static DLink *chanmsg_hooks = NULL;
 static DLink *usermsg_hooks = NULL;
@@ -509,8 +511,12 @@ get_texthooktype(enum c_hooktype hooktype)
         case CHOOK_MSG:
             return "Message";
 #ifdef MODULE_HOOK_REMOTEMSG
-               case CHOOK_REMOTEMSG:
+               case CHOOK_REM_MSG:
                        return "Remote Message";
+               case CHOOK_REM_CHANMSG:
+                       return "Remote Channel Message";
+               case CHOOK_REM_USERMSG:
+                       return "Remote User Message";
 #endif
 
         case CHOOK_CHANMSG:
@@ -564,8 +570,14 @@ get_hooklist(enum c_hooktype hooktype)
             hooklist = &msg_hooks;
             break;
 #ifdef MODULE_HOOK_REMOTEMSG
-               case CHOOK_REMOTEMSG:
-                       hooklist = &remotemsg_hooks;
+               case CHOOK_REM_MSG:
+                       hooklist = &rem_msg_hooks;
+                       break;
+               case CHOOK_REM_USERMSG:
+                       hooklist = &rem_usermsg_hooks;
+                       break;
+               case CHOOK_REM_CHANMSG:
+                       hooklist = &rem_chanmsg_hooks;
                        break;
 #endif
 
@@ -749,22 +761,54 @@ call_hooks(enum c_hooktype hooktype, ...)
                 break;
             }
 #ifdef MODULE_HOOK_REMOTEMSG
-               case CHOOK_REMOTEMSG:
+               case CHOOK_REM_MSG:
                        {
                                aClient *acptr = va_arg(vl, aClient *);
-                               aClient *asptr = va_arg(vl, aClient *);
                                int aint = va_arg(vl, int);
-                               char *destptr = va_arg(vl, char *);
                                char *txtptr = va_arg(vl, char *);
-                               for (lp = remotemsg_hooks; lp; lp = lp->next)
+                               for (lp = rem_msg_hooks; lp; lp = lp->next)
                                {
-                                       int (*rfunc) (aClient *, aClient *, int, char *, char *) =
+                                       int (*rfunc) (aClient *, int, char *) =
                                                ((aHook*)lp->value.cp)->funcptr;
-                                       if ((ret = (*rfunc)(acptr, asptr, aint, destptr, txtptr)) == FLUSH_BUFFER)
+                                       if ((ret = (*rfunc)(acptr, aint, txtptr)) == FLUSH_BUFFER)
                                                break;
                                }
                                break;
                        }
+        case CHOOK_REM_CHANMSG:
+            {
+                aClient *acptr = va_arg(vl, aClient *);
+                aChannel *chptr = va_arg(vl, aChannel *);
+                int aint = va_arg(vl, int);
+                char *txtptr = va_arg(vl, char *);
+
+                for(lp = rem_chanmsg_hooks; lp; lp = lp->next)
+                {
+                    int (*rfunc) (aClient *, aChannel *, int, char *) =
+                                  ((aHook *)lp->value.cp)->funcptr;
+                    if((ret = (*rfunc)(acptr, chptr, aint, txtptr)) 
+                                    == FLUSH_BUFFER)
+                        break;
+                }
+                break;
+            }
+        case CHOOK_REM_USERMSG:
+            {
+                aClient *acptr = va_arg(vl, aClient *);
+                aClient *dcptr = va_arg(vl, aClient *);
+                int aint = va_arg(vl, int);
+                char *txtptr = va_arg(vl, char *);
+
+                for(lp = rem_usermsg_hooks; lp; lp = lp->next)
+                {
+                    int (*rfunc) (aClient *, aClient *, int, char *) =
+                                 ((aHook *)lp->value.cp)->funcptr;
+                    if((ret = (*rfunc)(acptr, dcptr, aint, txtptr))
+                                    == FLUSH_BUFFER)
+                        break;
+                }
+                break;
+            }
 #endif
 
         case CHOOK_CHANMSG:
index a1129eb..b2acfa5 100644 (file)
@@ -21,7 +21,7 @@
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-/* $Id: s_user.c,v 1.9 2005/01/15 23:35:03 mwiggins Exp $ */
+/* $Id: s_user.c,v 1.10 2005/01/19 22:05:45 mwiggins Exp $ */
 
 #include "struct.h"
 #include "common.h"
@@ -1541,7 +1541,7 @@ m_message(aClient *cptr, aClient *sptr, int parc, char *parv[], int notice)
 #ifdef MODULE_HOOK_REMOTEMSG
        else
        {
-               if(call_hooks(CHOOK_REMOTEMSG, cptr, sptr, notice, parv[1], parv[2]) == FLUSH_BUFFER)
+               if(call_hooks(CHOOK_REM_MSG, sptr, notice, parv[2]) == FLUSH_BUFFER)
                        return FLUSH_BUFFER;
        }
 #endif
@@ -1564,9 +1564,19 @@ m_message(aClient *cptr, aClient *sptr, int parc, char *parv[], int notice)
         ischan = IsChannelName(nick);
         if (ischan && (chptr = find_channel(nick,NullChn))) 
         {
-            if(ismine && call_hooks(CHOOK_CHANMSG, sptr, chptr, 
+            if(ismine) 
+                       {
+                               if (call_hooks(CHOOK_CHANMSG, sptr, chptr, 
                         notice, parv[2]) == FLUSH_BUFFER)
-                return FLUSH_BUFFER;
+                                       return FLUSH_BUFFER;
+                       }
+#ifdef MODULE_HOOK_REMOTEMSG
+                       else
+                       {
+                               if (call_hooks(CHOOK_REM_CHANMSG, sptr, chptr, notice, parv[2]) == FLUSH_BUFFER)
+                                       return FLUSH_BUFFER;
+                       }
+#endif
 
             if (!notice)
                 switch(check_for_ctcp(parv[2], NULL))
@@ -1617,9 +1627,19 @@ m_message(aClient *cptr, aClient *sptr, int parc, char *parv[], int notice)
                         return FLUSH_BUFFER;
                     continue;
                 }
-                if(ismine && call_hooks(CHOOK_USERMSG, sptr, acptr, notice, 
+                if(ismine)
+                               {
+                                       if (call_hooks(CHOOK_USERMSG, sptr, acptr, notice, 
                                parv[2]) == FLUSH_BUFFER)
-                    return FLUSH_BUFFER;
+                                               return FLUSH_BUFFER;
+                               }
+#ifdef MODULE_HOOK_REMOTEMSG
+                               else
+                               {
+                                       if (call_hooks(CHOOK_REM_USERMSG, sptr, acptr, notice, parv[2]) == FLUSH_BUFFER)
+                                               return FLUSH_BUFFER;
+                               }
+#endif
 
 
                 if (!IsClient(acptr))