2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
|
|
|
|
* hook.c - code for dealing with the hook system
|
|
|
|
*
|
2016-09-23 01:59:22 +02:00
|
|
|
* ~~~~~~~~
|
2007-01-25 07:40:21 +01:00
|
|
|
* This code is basically a slow leaking array. Events are simply just a
|
|
|
|
* position in this array. When hooks are added, events will be created if
|
|
|
|
* they dont exist - this means modules with hooks can be loaded in any
|
|
|
|
* order, and events are preserved through module reloads.
|
2016-09-23 01:59:22 +02:00
|
|
|
* ~~~~~~~~~ left the comment but the code is gone. --jzk
|
2007-01-25 07:40:21 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2005 Lee Hardy <lee -at- leeh.co.uk>
|
|
|
|
* Copyright (C) 2004-2005 ircd-ratbox development team
|
2016-09-23 01:59:22 +02:00
|
|
|
* Copyright (C) 2016 Charybdis Development Team
|
|
|
|
* Copyright (C) 2016 Jason Volk <jason@zemos.net>
|
2007-01-25 07:40:21 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* 1.Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2.Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3.The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
namespace ircd {
|
2016-09-23 01:59:22 +02:00
|
|
|
namespace hook {
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace hook
|
|
|
|
} // namespace ircd
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
bool
|
|
|
|
hook::happens_before(const std::string &a_name,
|
|
|
|
const relationship &a_happens,
|
|
|
|
const std::string &b_name,
|
|
|
|
const relationship &b_happens)
|
|
|
|
{
|
|
|
|
// Explicit request by b that a happens before
|
|
|
|
if(b_happens.first == a_name)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Explicit request by a that b happens before
|
|
|
|
if(a_happens.first == b_name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Explicit request by b that a happens after
|
|
|
|
if(b_happens.second == a_name)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Explicit request by a that b happens after
|
|
|
|
if(a_happens.second == b_name)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// a happens before everything and b has at least something before it
|
|
|
|
if(a_happens.first.empty() && !b_happens.first.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// b happens before everything and a has at least something before it
|
|
|
|
if(b_happens.first.empty() && !a_happens.first.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// a happens after everything and b has at least something after it
|
|
|
|
if(a_happens.second.empty() && !b_happens.second.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// b happens after everything and a has at least something after it
|
|
|
|
if(b_happens.second.empty() && !a_happens.second.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
//TODO: ???
|
|
|
|
// both have the same before requirement
|
|
|
|
if(a_happens.first == b_happens.first)
|
|
|
|
return a_happens.second < b_happens.second;
|
|
|
|
|
|
|
|
//TODO: ???
|
|
|
|
// both have the same after requirement
|
|
|
|
if(a_happens.second == b_happens.second)
|
|
|
|
return a_happens.first < b_happens.first;
|
|
|
|
|
|
|
|
//TODO: ???
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2016-08-13 05:05:54 +02:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
hook *hooks;
|
|
|
|
|
|
|
|
#define HOOK_INCREMENT 1000
|
|
|
|
|
|
|
|
int num_hooks = 0;
|
|
|
|
int last_hook = 0;
|
|
|
|
int max_hooks = HOOK_INCREMENT;
|
|
|
|
|
|
|
|
int h_burst_client;
|
|
|
|
int h_burst_channel;
|
|
|
|
int h_burst_finished;
|
|
|
|
int h_server_introduced;
|
|
|
|
int h_server_eob;
|
|
|
|
int h_client_exit;
|
2008-04-20 15:20:10 +02:00
|
|
|
int h_umode_changed;
|
2007-01-25 07:40:21 +01:00
|
|
|
int h_new_local_user;
|
|
|
|
int h_new_remote_user;
|
|
|
|
int h_introduce_client;
|
2009-04-20 16:20:11 +02:00
|
|
|
int h_can_kick;
|
2012-04-01 04:20:02 +02:00
|
|
|
int h_privmsg_user;
|
|
|
|
int h_privmsg_channel;
|
2012-05-21 22:22:07 +02:00
|
|
|
int h_conf_read_start;
|
|
|
|
int h_conf_read_end;
|
2016-02-20 22:49:41 +01:00
|
|
|
int h_outbound_msgbuf;
|
2016-04-06 12:43:54 +02:00
|
|
|
int h_rehash;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
init_hook(void)
|
|
|
|
{
|
2016-07-13 07:17:21 +02:00
|
|
|
hooks = (hook *)rb_malloc(sizeof(hook) * HOOK_INCREMENT);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
h_burst_client = register_hook("burst_client");
|
|
|
|
h_burst_channel = register_hook("burst_channel");
|
|
|
|
h_burst_finished = register_hook("burst_finished");
|
|
|
|
h_server_introduced = register_hook("server_introduced");
|
|
|
|
h_server_eob = register_hook("server_eob");
|
|
|
|
h_client_exit = register_hook("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");
|
|
|
|
h_introduce_client = register_hook("introduce_client");
|
2009-04-20 16:20:11 +02:00
|
|
|
h_can_kick = register_hook("can_kick");
|
2012-04-01 04:20:02 +02:00
|
|
|
h_privmsg_user = register_hook("privmsg_user");
|
|
|
|
h_privmsg_channel = register_hook("privmsg_channel");
|
2012-05-21 22:22:07 +02:00
|
|
|
h_conf_read_start = register_hook("conf_read_start");
|
|
|
|
h_conf_read_end = register_hook("conf_read_end");
|
2016-02-20 22:49:41 +01:00
|
|
|
h_outbound_msgbuf = register_hook("outbound_msgbuf");
|
2016-04-06 12:43:54 +02:00
|
|
|
h_rehash = register_hook("rehash");
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2016-09-23 01:59:22 +02:00
|
|
|
*/
|