[Devel] Re: [Users] textops from other module

Wolfgang Hottgenroth woho at hottis.de
Sun May 21 14:37:30 CEST 2006


aha, I see. So, does this mean, that the fixup function is called only
once, and does this mean too, the the regex given to textops::subst
needs to be a constant?

I call subst - as I've mentioned - from my own module and call it we a
variable regex, as you see in the snippet below. So, I certainly need to
free what subst_parser has allocated (haven't this done in this snippet
yet). But is it okay to free immediately after the call of subst? Or do
I need to wait until the request was sent out again?

Or won't this work at all?

  string re;
  if (reportDirection == dir_pstnToVoip) {
    re = "/sip.." + currentBan + m_bNumber + "/sip:+" + m_bNumber + "/g";
    MY_DBG("*** Call::mangle: I would preform
s/sip:+BAN+B-Number/sip:+B-Number/g: %s", re.c_str());
  } else {
    re = "/sip.." + m_bNumber + "/sip:+" + currentBan + m_bNumber + "/g";
    MY_DBG("*** Call::mangle: I would preform
s/sip:+B-Number/sip:+BAN+B-Number/g: %s", re.c_str());
  // parameter fixup for subst function, code stolen from module
textops, file textops.c, function fixup_substre
  str subst;
  // const_cast: what shall I do, openser's str is defined like that
  subst.s = const_cast<char*>(re.c_str());
  subst.len = re.length();
  struct subst_expr *se = subst_parser(&subst);
  if (se == NULL)
    THROW(CallException, ec_Call_MangleRegexFailure);

  // get the function to substitute the header
  static const string TEXTOPS_MODULE_NAME = "textops";
  static const string SUBST_CMD_NAME = "subst";
  static const int SUBST_PARAM_CNT = 1;
  static const int SUBST_FLAGS = 0;

  cmd_function substFunc =
  if (substFunc == NULL)
    THROW(CallException, ec_Call_ExportedFuncNotFound);

  // substitute the header
  // cast to char* with respect to the module API
  int res = (*substFunc)(m_sipMsg, (char*)se, NULL);
  if (res <= 0)
    THROW(CallException, ec_Call_ManglingFailure);

Thank you very much,

Daniel-Constantin Mierla wrote:
> On 05/20/06 00:59, Wolfgang Hottgenroth wrote:
>> Hi,
>> I found all that, but I'm a bit scared: in fixup_substre the call of
>> subst_parser seems to allocate some memory for the compiled regex. But I
>> can not see where that is freed.
>> Is there something missing or do I missed something?
> no, it is not freed because it is kept in memory for the whole time
> openser is running. The compilation of the regexp is done once, at
> startup, and then same structure is used all the time subst() is invoked.
> The free is done at openser shut down.
> Cheers,
> Daniel
>> Thanks,
>> Wolfgang
>> Bogdan-Andrei Iancu wrote:
>>> Hi Wolfgang,
>>> even if a module does not export an API, you may access from a
>>> different
>>> module the exported functions by the find_export() function from core.
>>> See how the register module make usage of sl_send_reply() from sl
>>> module.
>>> IMPORTANT: if you use directly an exported function the fixup functions
>>> will not be called so you will have to pass to the functions the
>>> parameters in the fixed format - take a look in the textops module to
>>> see what are the fixing ops.
>>> regards,
>>> bogdan
>>> Wolfgang Hottgenroth wrote:
>>>> Hi,
>>>> I want to perform a textops function, namely subst, over a SIP
>>>> message.
>>>> But I want to do this not from the openser script but from a module
>>>> I'm
>>>> about to implement.
>>>> Unfortunately, the textops module did not provide an API to other
>>>> modules. But I'm wondering whether it is more than simply removing the
>>>> 'static' from the function declaration of the subst_f function in
>>>> textops.c to make this function accessible for other modules.
>>>> Or do I have a chance to set a pseudo-variable or AVP with the
>>>> complete
>>>> regex in one of my own modules functions and perform the subst using
>>>> that pseudo-variable or AVP in the openser script directly after the
>>>> call to my own function?
>>>> Or is the only way to re-implement the subst_f functionality in my own
>>>> module to use it from there?
>>>> Thank you very much,
>>>> Wolfgang
>>>> _______________________________________________
>>>> Users mailing list
>>>> Users at openser.org
>>>> http://openser.org/cgi-bin/mailman/listinfo/users
>> _______________________________________________
>> Devel mailing list
>> Devel at openser.org
>> http://openser.org/cgi-bin/mailman/listinfo/devel

More information about the Devel mailing list