[OpenSER-Devel] Accessing exported functions from another module

Ardjan Zwartjes a.zwartjes at telecats.nl
Thu Jul 10 14:56:31 CEST 2008


Hi all,

I'm currently developing some OpenSER modules and regularly encounter
situations where I wan't to do things which are already implemented in
the textops (or other) module(s). Unfortunately the textops module
doesn't export an API like the TM module to access these functions. Now
since I'd prefer to keep the existing modules the way they are (so I
don't want to change the textops module) I see two solutions to access
these functions:

1. Copy the code I need from the textops module to my own module.
Personally I don't like this solution since duplicating code is almost
never a good idea.
2. Try to access the functions through the module itself.

In order to achieve option 2 I'm trying to to use "find_cmd_export_t" to
find functions like append_hf and remove_hf. After some trial and error
I came up with the following sequence of steps to call these functions:

- I get a cmd_export_t* by calling find_cmd_export_t (lets call this
variable to_cmd_export_t).
- I fix the params by calling to_cmd_export_t->fixup(msg,params,1);
- I call the function with
to_cmd_export_t->function(msg,params[0],NULL);
- I free the params with to_cmd_export_t->free_fixup(params,1);

Now this doesn't work perfectly, if for instance I use this to call
append_hf of the textops module I can see that the header is added, but
sometimes the value is overwritten with other data in the final message.
So I assume that I'm freeing something that shouldn't be freed,
unfortunately I got lost in the code while trying to figure out what to
free and what not. 

So this is my question: Can anybody explain how to call exported
functions from the textop modules without memory leaks or problems as
described above? 

In the (not so unlikely) case that what I'm trying to here is an
unintended, ugly and stupid abuse of the find_cmd_export_t function ;)
I'm very interested if there are other ways to add/remove/change headers
in a module developer friendly way and/or how to call functions normally
called from the script.

Anyway, thanks in advance for all the information you can provide.

Kind regards,
Ardjan Zwartjes.



More information about the Devel mailing list