[sr-dev] Reseting a pseudo-variable for each new request/response

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Oct 7 11:44:59 CEST 2010


On Oct 04, 2010 at 19:38, Iñaki Baz Castillo <ibc at 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



More information about the sr-dev mailing list