[OpenSIPS-Users] Question: how to return string from module function to config script?

Ovidiu Sas osas at voipembedded.com
Thu Nov 5 02:44:20 EST 2020


Hello Elaine,

See inline!

On Wed, Nov 4, 2020 at 6:39 PM Elaine Huang <u8k.mel at gmail.com> wrote:
>
> Hello Ovidiu,
>
> Thanks for your reply. Reading the linked doc it seemed to me exported functions can only return integers.
That is correct!

> I don't quite get the dialplan dp_translate function, how do I decide what dialplan id to use, and what's a translation rule?
This was just an example to look at. You can read the documentation of
the dialplan module and check the layout of the dialplan table and it
will make sense. There are other functions in other modules that are
using a pseudo variable to populate then on successful execution.

> Should I create my own pseudo variable and store the string there for scripting access? Sorry for all the questions.
You don't need to create your own pseudo variable. The pseudo variable
will be provided by the script/config file to your function as a
parameter and your function will populate it with whatever you want.
Then later on, in the script, you can perform whatever operations you
like to/with that pseudo variable.

>
> Cheers,
> Wenshan
>
> On Sun., 1 Nov. 2020, 11:47 Ovidiu Sas, <osas at voipembedded.com> wrote:
>>
>> Hello Elaine,
>>
>>  A module function in opensips returns and integer.
>> Based on the return value, you can test if the function was successful or not.
>> More details here:
>> https://www.opensips.org/Documentation/Development-Manual#toc37
>> Take a look at the big yellow warning at the end of documentation for the module function for how return codes are interpreted.
>>
>> If you want to return a string, here’s an example:
>> https://opensips.org/html/docs/modules/devel/dialplan.html#func_dp_translate
>> See the out_var parameter.
>>
>> Hope this helps,
>> Ovidiu
>>
>> On Sat, Oct 31, 2020 at 18:57 Elaine Huang <u8k.mel at gmail.com> wrote:
>>>
>>> I'm new to opensips and I'm wondering if it's possible for a module function to return a string instead of integer?
>>>
>>> My wishful thinking is in my config:
>>>
>>> $var(myVar) = myFunc(params...);
>>> # then myVar becomes a string value that I can manipulate, compare, etc
>>>
>>>
>>> If this is not achievable, what's the conventional way to get a string from a module function? Is it pseudo variable that I should use?
>>>
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.opensips.org
>>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>
>> --
>> VoIP Embedded, Inc.
>> http://www.voipembedded.com
>> _______________________________________________
>> Users mailing list
>> Users at lists.opensips.org
>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users



-- 
VoIP Embedded, Inc.
http://www.voipembedded.com



More information about the Users mailing list