]> jfr.im git - solanum.git/blobdiff - ircd/hook.c
Add tests for valid_temp_time
[solanum.git] / ircd / hook.c
index e1e72cd6600dfa0eb4588ce8d0af3b4b2cd1cfcc..b77ceb1050fa81090641ff6d4d2c3929f85312e3 100644 (file)
@@ -33,8 +33,6 @@
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id: hook.c 712 2006-02-06 04:42:14Z gxti $
  */
 #include "stdinc.h"
 #include "hook.h"
@@ -44,6 +42,13 @@ hook *hooks;
 
 #define HOOK_INCREMENT 1000
 
+struct hook_entry
+{
+       rb_dlink_node node;
+       hookfn fn;
+       enum hook_priority priority;
+};
+
 int num_hooks = 0;
 int last_hook = 0;
 int max_hooks = HOOK_INCREMENT;
@@ -54,6 +59,7 @@ int h_burst_finished;
 int h_server_introduced;
 int h_server_eob;
 int h_client_exit;
+int h_after_client_exit;
 int h_umode_changed;
 int h_new_local_user;
 int h_new_remote_user;
@@ -64,6 +70,9 @@ int h_privmsg_channel;
 int h_conf_read_start;
 int h_conf_read_end;
 int h_outbound_msgbuf;
+int h_rehash;
+int h_priv_change;
+int h_cap_change;
 
 void
 init_hook(void)
@@ -76,6 +85,7 @@ init_hook(void)
        h_server_introduced = register_hook("server_introduced");
        h_server_eob = register_hook("server_eob");
        h_client_exit = register_hook("client_exit");
+       h_after_client_exit = register_hook("after_client_exit");
        h_umode_changed = register_hook("umode_changed");
        h_new_local_user = register_hook("new_local_user");
        h_new_remote_user = register_hook("new_remote_user");
@@ -86,6 +96,9 @@ init_hook(void)
        h_conf_read_start = register_hook("conf_read_start");
        h_conf_read_end = register_hook("conf_read_end");
        h_outbound_msgbuf = register_hook("outbound_msgbuf");
+       h_rehash = register_hook("rehash");
+       h_priv_change = register_hook("priv_change");
+       h_cap_change = register_hook("cap_change");
 }
 
 /* grow_hooktable()
@@ -172,11 +185,34 @@ register_hook(const char *name)
 void
 add_hook(const char *name, hookfn fn)
 {
+       add_hook_prio(name, fn, HOOK_NORMAL);
+}
+
+/* add_hook_prio()
+ *   Adds a hook with the specified priority
+ */
+void
+add_hook_prio(const char *name, hookfn fn, enum hook_priority priority)
+{
+       rb_dlink_node *ptr;
+       struct hook_entry *entry = rb_malloc(sizeof *entry);
        int i;
 
        i = register_hook(name);
+       entry->fn = fn;
+       entry->priority = priority;
+
+       RB_DLINK_FOREACH(ptr, hooks[i].hooks.head)
+       {
+               struct hook_entry *o = ptr->data;
+               if (entry->priority <= o->priority)
+               {
+                       rb_dlinkAddBefore(ptr, entry, &entry->node, &hooks[i].hooks);
+                       return;
+               }
+       }
 
-       rb_dlinkAddAlloc(fn, &hooks[i].hooks);
+       rb_dlinkAddTail(entry, &entry->node, &hooks[i].hooks);
 }
 
 /* remove_hook()
@@ -185,12 +221,21 @@ add_hook(const char *name, hookfn fn)
 void
 remove_hook(const char *name, hookfn fn)
 {
+       rb_dlink_node *ptr, *scratch;
        int i;
 
        if((i = find_hook(name)) < 0)
                return;
 
-       rb_dlinkFindDestroy(fn, &hooks[i].hooks);
+       RB_DLINK_FOREACH_SAFE(ptr, scratch, hooks[i].hooks.head)
+       {
+               struct hook_entry *entry = ptr->data;
+               if (entry->fn == fn)
+               {
+                       rb_dlinkDelete(ptr, &hooks[i].hooks);
+                       return;
+               }
+       }
 }
 
 /* call_hook()
@@ -199,7 +244,6 @@ remove_hook(const char *name, hookfn fn)
 void
 call_hook(int id, void *arg)
 {
-       hookfn fn;
        rb_dlink_node *ptr;
 
        /* The ID we were passed is the position in the hook table of this
@@ -207,8 +251,8 @@ call_hook(int id, void *arg)
         */
        RB_DLINK_FOREACH(ptr, hooks[id].hooks.head)
        {
-               fn = ptr->data;
-               fn(arg);
+               struct hook_entry *entry = ptr->data;
+               entry->fn(arg);
        }
 }