|
@@ -41,15 +41,20 @@
|
|
|
MODULE_VERSION
|
|
|
|
|
|
static int async_workers = 1;
|
|
|
+static int async_ms_timer = 0;
|
|
|
|
|
|
static int mod_init(void);
|
|
|
static int child_init(int);
|
|
|
static void mod_destroy(void);
|
|
|
|
|
|
static int w_async_sleep(sip_msg_t *msg, char *sec, char *str2);
|
|
|
+static int w_async_ms_sleep(sip_msg_t *msg, char *sec, char *str2);
|
|
|
static int fixup_async_sleep(void **param, int param_no);
|
|
|
+
|
|
|
static int w_async_route(sip_msg_t *msg, char *rt, char *sec);
|
|
|
+static int w_async_ms_route(sip_msg_t *msg, char *rt, char *sec);
|
|
|
static int fixup_async_route(void **param, int param_no);
|
|
|
+
|
|
|
static int w_async_task_route(sip_msg_t *msg, char *rt, char *p2);
|
|
|
static int fixup_async_task_route(void **param, int param_no);
|
|
|
|
|
@@ -60,8 +65,12 @@ struct tm_binds tmb;
|
|
|
static cmd_export_t cmds[]={
|
|
|
{"async_route", (cmd_function)w_async_route, 2, fixup_async_route,
|
|
|
0, REQUEST_ROUTE|FAILURE_ROUTE},
|
|
|
+ {"async_ms_route", (cmd_function)w_async_ms_route, 2, fixup_async_route,
|
|
|
+ 0, REQUEST_ROUTE|FAILURE_ROUTE},
|
|
|
{"async_sleep", (cmd_function)w_async_sleep, 1, fixup_async_sleep,
|
|
|
0, REQUEST_ROUTE|FAILURE_ROUTE},
|
|
|
+ {"async_ms_sleep", (cmd_function)w_async_ms_sleep, 1, fixup_async_sleep,
|
|
|
+ 0, REQUEST_ROUTE|FAILURE_ROUTE},
|
|
|
{"async_task_route", (cmd_function)w_async_task_route, 1, fixup_async_task_route,
|
|
|
0, REQUEST_ROUTE|FAILURE_ROUTE},
|
|
|
{0, 0, 0, 0, 0, 0}
|
|
@@ -69,6 +78,7 @@ static cmd_export_t cmds[]={
|
|
|
|
|
|
static param_export_t params[]={
|
|
|
{"workers", INT_PARAM, &async_workers},
|
|
|
+ {"ms_timer", INT_PARAM, &async_ms_timer},
|
|
|
{0, 0, 0}
|
|
|
};
|
|
|
|
|
@@ -105,7 +115,17 @@ static int mod_init(void)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- register_basic_timers(async_workers);
|
|
|
+ if(async_ms_timer == 0) {
|
|
|
+ LM_INFO("ms_timer is set to 0. Disabling async_ms_sleep and async_ms_route functions\n");
|
|
|
+ } else {
|
|
|
+ if(async_init_ms_timer_list() < 0) {
|
|
|
+ LM_ERR("cannot initialize internal structure\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ LM_INFO("Enabled async_ms_sleep and async_ms_route functions with resolution of %dms\n", async_ms_timer);
|
|
|
+ }
|
|
|
+
|
|
|
+ register_basic_timers(async_workers + (async_ms_timer > 0));
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -131,6 +151,13 @@ static int child_init(int rank)
|
|
|
return -1; /* error */
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if((async_ms_timer > 0) && fork_basic_utimer(PROC_TIMER, "ASYNC MOD MILLI TIMER SINGLETON", 1 /*socks flag*/,
|
|
|
+ async_mstimer_exec, NULL, 1000 * async_ms_timer /*milliseconds*/)
|
|
|
+ < 0) {
|
|
|
+ LM_ERR("failed to register millisecond timer singleton as process (%d)\n", i);
|
|
|
+ return -1; /* error */
|
|
|
+ }
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -141,6 +168,7 @@ static int child_init(int rank)
|
|
|
static void mod_destroy(void)
|
|
|
{
|
|
|
async_destroy_timer_list();
|
|
|
+ async_destroy_ms_timer_list();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -183,6 +211,46 @@ static int w_async_sleep(sip_msg_t *msg, char *sec, char *str2)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static int w_async_ms_sleep(sip_msg_t *msg, char *sec, char *str2)
|
|
|
+{
|
|
|
+ int s;
|
|
|
+ async_param_t *ap;
|
|
|
+
|
|
|
+ if(msg == NULL)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ if(faked_msg_match(msg)) {
|
|
|
+ LM_ERR("invalid usage for faked message\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(async_workers <= 0) {
|
|
|
+ LM_ERR("no async mod timer workers (modparam missing?)\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ ap = (async_param_t *)sec;
|
|
|
+ if(fixup_get_ivalue(msg, ap->pinterval, &s) != 0) {
|
|
|
+ LM_ERR("no async sleep time value\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if(ap->type == 0) {
|
|
|
+ if(ap->u.paction == NULL || ap->u.paction->next == NULL) {
|
|
|
+ LM_ERR("cannot be executed as last action in a route block\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ if(async_ms_sleep(msg, s, ap->u.paction->next, NULL) < 0)
|
|
|
+ return -1;
|
|
|
+ /* force exit in config */
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return -1;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
@@ -243,6 +311,42 @@ int ki_async_route(sip_msg_t *msg, str *rn, int s)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int ki_async_ms_route(sip_msg_t *msg, str *rn, int s)
|
|
|
+{
|
|
|
+ cfg_action_t *act = NULL;
|
|
|
+ int ri;
|
|
|
+ sr_kemi_eng_t *keng = NULL;
|
|
|
+
|
|
|
+ if(faked_msg_match(msg)) {
|
|
|
+ LM_ERR("invalid usage for faked message\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ keng = sr_kemi_eng_get();
|
|
|
+ if(keng == NULL) {
|
|
|
+ ri = route_lookup(&main_rt, rn->s);
|
|
|
+ if(ri >= 0) {
|
|
|
+ act = main_rt.rlist[ri];
|
|
|
+ if(act == NULL) {
|
|
|
+ LM_ERR("empty action lists in route block [%.*s]\n", rn->len,
|
|
|
+ rn->s);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LM_ERR("route block not found: %.*s\n", rn->len, rn->s);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(async_ms_sleep(msg, s, act, rn) < 0)
|
|
|
+ return -1;
|
|
|
+ /* force exit in config */
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
@@ -271,6 +375,34 @@ static int w_async_route(sip_msg_t *msg, char *rt, char *sec)
|
|
|
return ki_async_route(msg, &rn, s);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static int w_async_ms_route(sip_msg_t *msg, char *rt, char *sec)
|
|
|
+{
|
|
|
+ int s;
|
|
|
+ str rn;
|
|
|
+
|
|
|
+ if(msg == NULL)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ if(async_workers <= 0) {
|
|
|
+ LM_ERR("no async mod timer workers\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fixup_get_svalue(msg, (gparam_t *)rt, &rn) != 0) {
|
|
|
+ LM_ERR("no async route block name\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fixup_get_ivalue(msg, (gparam_t *)sec, &s) != 0) {
|
|
|
+ LM_ERR("no async interval value\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ return ki_async_route(msg, &rn, s);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
*/
|