How to pass a pseudo-variable, AVP or string to a function

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to pass a pseudo-variable, AVP or string to a function

Iñaki Baz Castillo
Hi, could some developer show me how to use a pseudo-variable, AVP or
string as a parameter for a module function?
I'm reading the code of many functions receiving one parameter
(string, pv or AVP) and all of them are different.

I just want to get the string value (so ended in '\0') passed as
parameter to the function in the opensips config file.  Any tip
please? Thanks.

--
Iñaki Baz Castillo
<[hidden email]>
_______________________________________________
Devel mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: How to pass a pseudo-variable, AVP or string to a function

Iñaki Baz Castillo
2008/12/27 Iñaki Baz Castillo <[hidden email]>:
> Hi, could some developer show me how to use a pseudo-variable, AVP or
> string as a parameter for a module function?
> I'm reading the code of many functions receiving one parameter
> (string, pv or AVP) and all of them are different.
>
> I just want to get the string value (so ended in '\0') passed as
> parameter to the function in the opensips config file.  Any tip
> please? Thanks.

Well, I think I've already got it by copying some functions of "rr" module:

int my_function(struct sip_msg *msg, char *key, char *foo)
{
        str s;

        if (pv_printf_s(msg, (pv_elem_t*)key, &s)<0) {
                LM_ERR("failed to print the format\n");
                return -1;
        }

        # do something with s.s
}

static int it_list_fixup(void** param, int param_no)
{
        pv_elem_t *model;
        str s;
        if(*param)
        {
                s.s = (char*)(*param); s.len = strlen(s.s);
                if(pv_parse_format(&s, &model)<0)
                {
                        LM_ERR("wrong format[%s]\n",(char*)(*param));
                        return E_UNSPEC;
                }
                *param = (void*)model;
        }
        return 0;
}


--
Iñaki Baz Castillo
<[hidden email]>
_______________________________________________
Devel mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: How to pass a pseudo-variable, AVP or string to a function

Bogdan-Andrei Iancu
Hi Iñaki,

Everything is clear, or do you still need some help :) ?

Regards,
Bogdan

Iñaki Baz Castillo wrote:

> 2008/12/27 Iñaki Baz Castillo <[hidden email]>:
>  
>> Hi, could some developer show me how to use a pseudo-variable, AVP or
>> string as a parameter for a module function?
>> I'm reading the code of many functions receiving one parameter
>> (string, pv or AVP) and all of them are different.
>>
>> I just want to get the string value (so ended in '\0') passed as
>> parameter to the function in the opensips config file.  Any tip
>> please? Thanks.
>>    
>
> Well, I think I've already got it by copying some functions of "rr" module:
>
> int my_function(struct sip_msg *msg, char *key, char *foo)
> {
> str s;
>
> if (pv_printf_s(msg, (pv_elem_t*)key, &s)<0) {
> LM_ERR("failed to print the format\n");
> return -1;
> }
>
> # do something with s.s
> }
>
> static int it_list_fixup(void** param, int param_no)
> {
> pv_elem_t *model;
> str s;
> if(*param)
> {
> s.s = (char*)(*param); s.len = strlen(s.s);
> if(pv_parse_format(&s, &model)<0)
> {
> LM_ERR("wrong format[%s]\n",(char*)(*param));
> return E_UNSPEC;
> }
> *param = (void*)model;
> }
> return 0;
> }
>
>
>  


_______________________________________________
Devel mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
Reply | Threaded
Open this post in threaded view
|

Re: How to pass a pseudo-variable, AVP or string to a function

Iñaki Baz Castillo
2009/1/9 Bogdan-Andrei Iancu <[hidden email]>:
> Hi Iñaki,
>
> Everything is clear, or do you still need some help :) ?

It's clear now. In fact I'm using now a mod_fix function :)

--
Iñaki Baz Castillo
<[hidden email]>
_______________________________________________
Devel mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel