On Oct 09, 2010 at 17:25, Juha Heinanen <jh(a)tutpro.com> wrote:
i understood that module functions can now have an
arbitrary number of
string, int and pseudo var arguments, where string arguments can
possibly also contain pseudo variables.
some time ago i asked an example on how this is done, but didn't get any
reply. so i'll try again. for example, allow_trusted function is
now defined like this:
{"allow_trusted", (cmd_function)allow_trusted_2, 2, fixup_pvar_pvar,
fixup_free_pvar_pvar, REQUEST_ROUTE | FAILURE_ROUTE},
how can i add a third argument to the function without needing to define
yet another fixup_pvar_pvar_something?
You cannot use fixup_pvar_pvar for more then 2 parameters. A lot of the
fixup functions check the number of parameters and return error for
more then 2.
However in the case of fixup_pvar_pvar(), you can replace it with
fixup_pvar_all() (and fixup_free_pvar_all).
In your case replacing 2 with 3 and pvar_pvar with pvar_all should work,
e.g.:
{"allow_trusted3", (cmd_function)allow_trusted_2, 3, fixup_pvar_all,
fixup_free_pvar_all, REQUEST_ROUTE | FAILURE_ROUTE},
You can use this way to define functions that accept up to 6 parameters.
If you don't care about pvar arguments in strings (which IMHO should be
slowly obsoleted), then you can write a normal module function that
accepts strings as parameters (uses directly the char* arguments,
without any get_str_fparam(...)) and set the fixups to 0. The core will
take care and convert the arguments to string before calling your
function.
I you want variable number of parameters, the module function
declaration should look like:
{"foov", (cmd_function)foo_var, VAR_PARAM_NO, 0, 0, REQUEST_ROUTE}
static int foo_var(struct sip_msg* msg, int argc, action_u_t argv[])
{
int i;
for (i = 0; i < argc; i++)
do_something(argv[i].u.string);
return 1;
}
If you want to use fixups and variable number of parameters, the fixups
look the same way as normal fixups (fixup(void** param, int param_no)).
For more examples see modules_s/print/print.c (uses the ser modules
interface without free_fixup, but that's the only difference).
Andrei