[Devel] module coding question, are optional arguments set to null by default?

Bogdan-Andrei Iancu bogdan at voice-system.ro
Thu Nov 10 20:17:32 CET 2005


Hi Ron,

if you want to have same function but with different no of params, you 
have to exported twice, for each no params:
   

static cmd_export_t commands[] = {
	{"route_fubar",   fubar,   1,  0, REQUEST_ROUTE },
	{"route_fubar",   fubar,   0,  0, REQUEST_ROUTE },
	{0, 0, 0, 0, 0}
};


the param no is used to lookup the functions!
The unused params are set to zero.

regards,
bogdan

Ron Winacott wrote:

>Hello all,
>	I have a question about the module C function arguments. After you map the 
>route function to the module C function, the C function has three arguments, 
>the struct sip_msg* msg, char* str1 and char* str2. 
>
>So my question is, if the routing function is called without passing any 
>arguments will str1 and str2 be NULL or are they pointing at "junk on the 
>stack"?
>
>I would like to create a function that has an optional flag that may or may 
>not be passed as str1 and the code would look something like:
>
>module:
>static cmd_export_t commands[] = {
>	{"route_fubar",   fubar,   1,  0, REQUEST_ROUTE },
>	{0, 0, 0, 0, 0}
>};
>
>static int
>fubar(struct sip_msg* msg, char* str1, char* str2) {
>	if (str1) {
>		do_optional_stuff()
>	}
>	...
>}
>
>ser.cfg :
>if (method=="INVITE") {
>	fubar("flag");
>}
>else {
>	fubar();
>}
>
>Thanks
>	ronw.
>
>  
>




More information about the Devel mailing list