[OpenSER-Devel] Request for comment: module interface extension

Dan Pascu dan at ag-projects.com
Tue Dec 18 13:55:18 UTC 2007


On Tuesday 18 December 2007, Henning Westerholt wrote:
> On Tuesday 18 December 2007, Dan Pascu wrote:
> Hello Dan,
>
> Ah, now i understand.. :-) It hard to get the _exact_ structure of a
> interface without any example code or implementation.
>
> I was not aware that this is possible within the C language and
> stdargs.h. I begin to like this.. ;-)

It gets even better. After I first proposed to use the ellipsis notation I 
just realized it is not necessary unless one wants to write a single 
function to handle multiple signatures at the same time, in which case it 
needs it and it also needs to use varargs. However if one keeps defining 
multiple functions for each function signature as we do now, the ellipsis 
can be avoided. Even more the functions can have signatures that declare 
parameters exactly how they are, not as char* like it is now. This is 
possible since the args are already converted to the type the function 
expects by the fixup functions. Consider this example:

function(struct sip_msg *msg)
{
  // function with no args. process msg
}

function(struct sip_msg *msg, char *uri, int flags)
{
   // function with a char* arg and an int arg.
   // typecasting second arg like flags = (int)(long)arg2 is no
   // longer necessary as it was when 2nd arg was char*

   // process uri according to flags
}

All we need is to typecast these functions to cmd_function in the 
cmd_export_t structure.

-- 
Dan



More information about the Devel mailing list