Hi, in a module I'm writting I export a script function which gives value to a new pseudo-variable. This pv is stored in a global variable into each worker process.
I don't know how to solve this issue:
- A request is handled by worker-1. - The script calls to the module function so the pv is filled (it's value is stored in a global str within the process). - Later in the script I can access to $new_pv (it reads the global str in the pv_get_new_pv() function). - The request processing ends (i.e: t_relay). - After some time the same worker-1 receives a new request. - If the script reads $new_pv (without calling the module function before) it will get the value generated during the previous SIP request.
Of course the script configuration shouldn't try to read $new_pv without calling first to the exported function, but anyhow this could happen (due to a bad script file). Is there an ellegant way to avoid this? This is, I would like that when a process receives a request (or a response) $new_pv gets automatically reseted (to NULL), prior to executing the script logic. In this way accessing to $new_pv without calling the module function would return an empty value.
Is it possible? how do other modules handle this case?
Thanks a lot.
On Oct 04, 2010 at 19:38, Iñaki Baz Castillo ibc@aliax.net wrote:
Hi, in a module I'm writting I export a script function which gives value to a new pseudo-variable. This pv is stored in a global variable into each worker process.
I don't know how to solve this issue:
- A request is handled by worker-1.
- The script calls to the module function so the pv is filled (it's
value is stored in a global str within the process).
- Later in the script I can access to $new_pv (it reads the global str
in the pv_get_new_pv() function).
- The request processing ends (i.e: t_relay).
- After some time the same worker-1 receives a new request.
- If the script reads $new_pv (without calling the module function
before) it will get the value generated during the previous SIP request.
Of course the script configuration shouldn't try to read $new_pv without calling first to the exported function, but anyhow this could happen (due to a bad script file). Is there an ellegant way to avoid this? This is, I would like that when a process receives a request (or a response) $new_pv gets automatically reseted (to NULL), prior to executing the script logic. In this way accessing to $new_pv without calling the module function would return an empty value.
Is it possible? how do other modules handle this case?
register_script_cb(callback, flags, callback_param)
where flags are a combination of POST_SCRIPT_CB or PRE_SCRIPT_CB and REQUEST_CB (request route), FAILURE_CB (failure route), ONREPLY_CB, BRANCH_CB, and ONSEND_CB. There are 3 more ERROR_CB, LOCAL_CB and EVENT_CB, but they are not used for now.
E.g. (from tm): /* register post-script clean-up function */ if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQUEST_CB, 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register POST request " "callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQUEST_CB , 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register PRE request " "callback\n"); return -1; }
Andrei
2010/10/7 Andrei Pelinescu-Onciul andrei@iptel.org:
register_script_cb(callback, flags, callback_param)
where flags are a combination of POST_SCRIPT_CB or PRE_SCRIPT_CB and REQUEST_CB (request route), FAILURE_CB (failure route), ONREPLY_CB, BRANCH_CB, and ONSEND_CB. There are 3 more ERROR_CB, LOCAL_CB and EVENT_CB, but they are not used for now.
E.g. (from tm): /* register post-script clean-up function */ if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQUEST_CB, 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register POST request " "callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQUEST_CB , 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register PRE request " "callback\n"); return -1; }
Great!
In my case the exported function can be invoked from any kind of route, and I don't want PV's to be cleaned when entering in branch_route so I expect that the callback should look as follows:
register_script_cb( clean_pvs, POST_SCRIPT_CB|REQUEST_CB|FAILURE_CB|ONREPLY_CB , 0 )
This is, I don't need to add BRANCH_CB or ONSEND_CB as I just want the PV to be cleaned after terminating the request/response process. branch_route and onsend_route run over the same process as request_route (or failure_route) so I don't need to include them, am I right?
Thanks a lot.
On Oct 07, 2010 at 12:53, Iñaki Baz Castillo ibc@aliax.net wrote:
2010/10/7 Andrei Pelinescu-Onciul andrei@iptel.org:
register_script_cb(callback, flags, callback_param)
where flags are a combination of POST_SCRIPT_CB or PRE_SCRIPT_CB and REQUEST_CB (request route), FAILURE_CB (failure route), ONREPLY_CB, BRANCH_CB, and ONSEND_CB. There are 3 more ERROR_CB, LOCAL_CB and EVENT_CB, but they are not used for now.
E.g. (from tm): /* register post-script clean-up function */ if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQUEST_CB, 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register POST request " "callback\n"); return -1; } if (register_script_cb( script_init, PRE_SCRIPT_CB|REQUEST_CB , 0)<0 ) { LOG(L_ERR,"ERROR:tm:mod_init: failed to register PRE request " "callback\n"); return -1; }
Great!
In my case the exported function can be invoked from any kind of route, and I don't want PV's to be cleaned when entering in branch_route so I expect that the callback should look as follows:
register_script_cb( clean_pvs, POST_SCRIPT_CB|REQUEST_CB|FAILURE_CB|ONREPLY_CB , 0 )
This is, I don't need to add BRANCH_CB or ONSEND_CB as I just want the PV to be cleaned after terminating the request/response process. branch_route and onsend_route run over the same process as request_route (or failure_route) so I don't need to include them, am I right?
Yes, you are.
Andrei