[Kamailio-Devel] Porting modules from OpenSER-1.2

Henning Westerholt henning.westerholt at 1und1.de
Fri Nov 7 16:08:26 CET 2008


On Friday 07 November 2008, Daniel Corbe wrote:
> [...]

Hi Daniel,

> 2) There seems to be extra parameters now to functions when they're being
> called from the config file, and I'm not sure why they're there and what
> they're needed for.  I tried to make some sense of it from the cfgutils
> module with no luck.  Take the m_sleep function for example (called with
> sleep() from the config):
>
> static int m_sleep(struct sip_msg *msg, char *time, char *str2);
> People seem to randomly name these extra function parameters:
>
> static int dbg_abort(struct sip_msg* msg, char* foo, char* bar);

This parameter are the interface to the config file, which happens to use 
char* as generic parameter type.

> The reason this is throwing a stone into my shoe is because I'm trying to
> figure out how the usrloc module works.  I am attempting to "cache"
> register requests by sending them upstream and trapping the response.  To
> do this, obviously I need to reimplement the save command, which uses such
> paramaters:
>
>
> int save(struct sip_msg* _m, char* _d, char* _cflags);
>
>
> If I understand this correctly, the paramaters are arbitrary, they're
> always char* (meaning passing ints requires a fixup function).

Yes, if you want to pass a type different from char*, you need to cast it to 
the correct type in fixup.

> Does this mean that I'm always limited to only two parameters per function?
>  Even if I need more or less?

No, you're not limited to this anymore. The carrierroute module for example 
uses up to 5 parameters in some functions.

> Supposing I need to func(param, param, param), would I add an extra char*
> and define the function like:
>
>
> int func(struct sip_msg *m, char *p1, char *p2, char *p3);

This should be work, this is for example from the carrierroute module:

int cr_route(struct sip_msg * _msg, gparam_t *_carrier,
		gparam_t *_domain, gparam_t *_prefix_matching,
		gparam_t *_rewrite_user, enum hash_source _hsrc,
		gparam_t *_dstavp);

Cheers,

Henning



More information about the Devel mailing list