[SR-Users] using a pseudo-variable as a parameter to a module function

Michael Iedema michael at kapsulate.com
Fri Dec 13 23:40:47 CET 2019


Thank you for all of the references, Alex.

I’m still experimenting a bit but have a much better grasp on how things can be done.

Much appreciated.


> On Dec 13, 2019, at 12:47, Alex Balashov <abalashov at evaristesys.com> wrote:
> 
> Hello Michael,
> 
> There are internal API functions which handle pseudovariable
> interpolation in string arguments, e.g. pv_get_spec_value().
> 
> You can see one-off uses of this for example in the fixup functions
> (functions which preliminarily process and validate arguments, often,
> but not always beginning with w_, for "wrapper"). 
> 
> You can see how this works in the 'uac' module, for example:
> 
> https://github.com/kamailio/kamailio/blob/master/src/modules/uac/auth.c#L266
> 
> But in my opinion, the most sensible packaging of this functionality is
> done in the dispatcher module. You'll note that ds_select_*() share a
> wrapper called w_ds_select_addr():
> 
> https://github.com/kamailio/kamailio/blob/master/src/modules/dispatcher/dispatcher.c#L549
> 
> There is this nice macro, proprietary to the dispatcher module, called
> GET_VALUE():
> 
> https://github.com/kamailio/kamailio/blob/master/src/modules/dispatcher/dispatcher.c#L560
> 
> That's defined here:
> 
> https://github.com/kamailio/kamailio/blob/master/src/modules/dispatcher/dispatcher.c#L507
> 
> And it takes advantage of a core API function called get_is_fparam():
> 
> https://github.com/kamailio/kamailio/blob/master/src/core/sr_module.c#L1656
> 
> As you can see, it can evaluate all kinds of interpolated values.
> 
> So, I'd just use that.
> 
> -- Alex
> 
> On Fri, Dec 13, 2019 at 12:10:02PM -0600, Michael Iedema wrote:
> 
>> Hi all,
>> 
>> I’m trying to write a basic Kamailio module from scratch and have run into an area where I’m in need of a couple pointers (pun not intended). :-) I have the module loading correctly and can call a function in my routing script like this:
>> 
>> mymod_getinfo(“5551234”);
>> 
>> This, for now, just triggers a print of the submitted parameter.
>> 
>> What I’d like to do next is have it accept and print the From URI in configuration script like so:
>> 
>> mymod_getinfo(“$fU”);
>> 
>> For now, this prints the string literal of “$fU” and I’m trying to extract the value of the referenced variable and print that. The example module “print” does not involve this concept of pseudo-variables. The skeleton module example in the wiki also does not mention variables.
>> 
>> I’ve looked into other modules to see how it works but they all seem to have a slightly different handling of this task. Can someone point me to an example in the modules which accomplishes this?
>> 
>> What I’ve been searching for is a replace_all function which accepts a string containing pseudo-variables and returns a new string with them all replaced with their corresponding values.
>> 
>> Thanks in advance and apologies if I’ve overlooked a relevant piece of developer documentation or if I’m looking at this incorrectly.
>> 
>> Regards,
>> -Michael
>> 
>> 
>> _______________________________________________
>> Kamailio (SER) - Users Mailing List
>> sr-users at lists.kamailio.org
>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
> 
> -- 
> Alex Balashov | Principal | Evariste Systems LLC
> 
> Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free) 
> Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
> 
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users




More information about the sr-users mailing list