I am bit lost on how the code execution flow works for KEMI. My understanding was that all KEMI methods are exported by `sr_kemi_t` structure array, which specifies exported function names, their internal implementation function name and its arguments either as string `SR_KEMIP_STR` or integer `SR_KEMIP_INT`.
Each exported function (e.g. `cr_route`) calls internal implementation function (e.g. `ki_cr_route5`), which then checks arguments and then either do the actual implementation or calls up a wrapper function (e.g. `w_cr_do_route`) which does some formatting on input arguments (e.g. `cr_route_fixup`) and then pass it to an existing implementation (e.g. `cr_do_route`). The output arguments control flow is in the opposite direction. Also since there is no free fixup in existing implementation of `cmd_export_t`, so I didn't created or called-in any for KEMI.
``` static cmd_export_t cmds[]={ {"cr_user_carrier", (cmd_function)cr_load_user_carrier, 3, cr_load_user_carrier_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE }, {"cr_route", (cmd_function)cr_route5, 5, cr_route_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE }, {"cr_route", (cmd_function)cr_route, 6, cr_route_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE }, {"cr_nofallback_route",(cmd_function)cr_nofallback_route5, 5, cr_route_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE }, {"cr_nofallback_route",(cmd_function)cr_nofallback_route, 6, cr_route_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE }, {"cr_next_domain", (cmd_function)cr_load_next_domain, 6, cr_load_next_domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE }, {0, 0, 0, 0, 0, 0} }; ```
On the python side, my example just shows that whatever we pass as argument (whether `$fU` or `KSR.kx.get_fuser()` or `"any-string-value"`), the module function will accept and take care of it (i.e. fetch the actual string value internally), this is already tested in my lab environment.
However, @miconda has suggested the completely different approach. Can you please point me to any existing howto or explain a bit more on how to write KEMI implementation of an existing module function? The example you provide at,
https://github.com/kamailio/kamailio/blob/master/src/modules/posops/posops_m...
is very confusing and does not give any hints on how the flow actually works.
Thank you.