Module: sip-router Branch: master Commit: a18160c8f5979464bd808af4c1f565b428d2e9ac URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a18160c8...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Tue May 19 19:44:00 2009 +0300
htable: execute event_route[htable:mod-init] if idefined
- the module will execute the event route just after modules have been initialized - a typical use case could be the initialization of some values in hash tables - example:
modparam("htable", "htable", "a=>size=4;")
event_route[htable:mod-init] { $sht(a=>calls-to::10.10.10.10) = 0; $sht(a=>max-calls-to::10.10.10.10) = 100; $sht(a=>calls-to::10.10.10.11) = 0; $sht(a=>max-calls-to::10.10.10.11) = 10; }
route { if(is_method("INVITE") && !has_totag()) { switch($rd) { case "10.10.10.10": lock("calls-to::10.10.10.10"); $sht(a=>calls-to::10.10.10.10) = $sht(a=>calls-to::10.10.10.10) + 1; unlock("calls-to::10.10.10.10"); if($sht(a=>calls-to::10.10.10.10)>$sht(a=>max-calls-to::10.10.10.10)) { sl_send_reply("500", "To many calls to .10"); exit; } break; case "10.10.10.11": ... break; } } }
---
modules_k/htable/htable.c | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/modules_k/htable/htable.c b/modules_k/htable/htable.c index 4dc7f4e..bf5cbcf 100644 --- a/modules_k/htable/htable.c +++ b/modules_k/htable/htable.c @@ -30,8 +30,10 @@
#include "../../sr_module.h" #include "../../timer.h" +#include "../../route.h" #include "../../dprint.h" #include "../../lib/kmi/mi.h" +#include "../../lib/kcore/faked_msg.h"
#include "../../pvar.h" #include "ht_api.h" @@ -46,6 +48,7 @@ int ht_timer_interval = 20; /** module functions */ static int ht_print(struct sip_msg*, char*, char*); static int mod_init(void); +static int child_init(int rank); void destroy(void);
static int fixup_ht_rm(void** param, int param_no); @@ -115,7 +118,7 @@ struct module_exports exports= { mod_init, /* module initialization function */ 0, (destroy_function) destroy, - 0 /* per-child init function */ + child_init /* per-child init function */ };
/** @@ -157,6 +160,30 @@ static int mod_init(void) return -1; } } + return 0; +} + + +static int child_init(int rank) +{ + struct sip_msg *fmsg; + int rtb, rt; + + LM_DBG("rank is (%d)\n", rank); + if (rank!=PROC_INIT) + return 0; + + rt = route_get(&event_rt, "htable:mod-init"); + if(rt>=0) { + LM_DBG("executing event_route[htable:mod-init] (%d)\n", rt); + if(faked_msg_init()<0) + return -1; + fmsg = faked_msg_next(); + rtb = route_type; + set_route_type(REQUEST_ROUTE); + run_top_route(event_rt.rlist[rt], fmsg); + set_route_type(rtb); + }
return 0; }