<!-- Kamailio Pull Request Template -->
<!-- IMPORTANT: - for detailed contributing guidelines, read: https://github.com/kamailio/kamailio/blob/master/.github/CONTRIBUTING.md - pull requests must be done to master branch, unless they are backports of fixes from master branch to a stable branch - backports to stable branches must be done with 'git cherry-pick -x ...' - code is contributed under BSD for core and main components (tm, sl, auth, tls) - code is contributed GPLv2 or a compatible license for the other components - GPL code is contributed with OpenSSL licensing exception -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [X] Commit message has the format required by CONTRIBUTING guide - [X] Commits are split per component (core, individual modules, libs, utils, ...) - [X] Each component has a single commit (if not, squash them into one commit) - [X] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [ ] Small bug fix (non-breaking change which fixes an issue) - [X] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: <!-- Go over all points below, and after creating the PR, tick the checkboxes that apply --> - [X] PR should be backported to stable branches - [X] Tested changes locally - [ ] Related to issue #XXXX (replace XXXX with an open issue number)
#### Description <!-- Describe your changes in detail --> export functions of ims_charging and ims_diameter_server to kemi You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2704
-- Commit Summary --
* Merge pull request #1 from kamailio/master * ims_charging: export functions to kemi * ims_diameter_server: export functions to kemi
-- File Changes --
M src/modules/ims_charging/ims_charging_mod.c (27) M src/modules/ims_diameter_server/ims_diameter_server.c (21)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2704.patch https://github.com/kamailio/kamailio/pull/2704.diff
Thanks for working on exporting to kemi from various ims related module!
However, the functions exported to the native kamailio.cfg cannot be directly exported to kemi. It has to be split in one where the parameters must be converted to `str*` and `int`, which then calls the function that can be exported to kemi. For example, next is the current `w_ro_ccr_stop()`:
``` static int w_ro_ccr_stop(struct sip_msg *msg, char* c_direction, char* _code, char* _reason) { struct ro_session* ro_session; struct ro_session_entry *ro_session_entry; unsigned int h_entry; str s_code, s_reason; unsigned int code; int dir = 0; /*any side*/
LM_DBG("Inside Ro_CCR_Stop with direction [%s]\n", c_direction); if (strlen(c_direction) == 4) { if (c_direction[0] == 'O' || c_direction[0] == 'o') { dir = RO_ORIG_DIRECTION; } else { dir = RO_TERM_DIRECTION; } } else { LM_ERR("Unknown direction [%s] to terminate\n", c_direction); return RO_RETURN_FALSE; } struct dlg_cell* dlg = dlgb.get_dlg(msg); if (!dlg) { LM_ERR("Unable to find dialog to send CCR STOP record\n"); return RO_RETURN_ERROR; }
if (get_str_fparam(&s_code, msg, (fparam_t*) _code) < 0) { LM_ERR("failed to get code\n"); dlgb.release_dlg(dlg); return RO_RETURN_ERROR; } LM_DBG("Code is [%.*s]\n", s_code.len, s_code.s); if (get_str_fparam(&s_reason, msg, (fparam_t*) _reason) < 0) { LM_ERR("failed to get reason\n"); dlgb.release_dlg(dlg); return RO_RETURN_ERROR; }
if (str2int(&s_code, &code) != 0) { LM_ERR("Bad response code: [%.*s]\n", s_code.len, s_code.s); dlgb.release_dlg(dlg); return RO_RETURN_FALSE; }
// switch (code) { // case 486: // termcode = VS_TERMCODE_BUSYHERE; // break; // case 487: // termcode = VS_TERMCODE_CANCELLED; // break; // case 480: // case 408: // /* subscriber not available */ // termcode = VS_TERMCODE_NOTFOUND; // break; // }
LM_DBG("Sending Stop record with code [%d] and reason [%.*s]\n", code, s_reason.len, s_reason.s);
LM_DBG("Found DLG [%d : %d]\n", dlg->h_id, dlg->h_entry);
ro_session = lookup_ro_session(dlg->h_entry, &dlg->callid, dir, 0); if (ro_session == NULL) { LM_DBG("no ro_session - ignoring\n"); dlgb.release_dlg(dlg); return RO_RETURN_TRUE; } h_entry = ro_session->h_entry; ro_session_entry = &(ro_session_table->entries[h_entry]);
ro_session_lock(ro_session_table, ro_session_entry);
if (ro_session->ccr_sent == 1) { LM_DBG("Ro CCR already sent for session [%.*s]\n", ro_session->ro_session_id.len, ro_session->ro_session_id.s); goto done; } send_ccr_stop_with_param(ro_session, code, &s_reason); //TODO = check the CCR was sent successfully. LM_DBG("Setting Ro session [%.*s] ccr_sent to 1\n", ro_session->ro_session_id.len, ro_session->ro_session_id.s); ro_session->ccr_sent = 1; ro_session->active = -1; // counter_add(ims_charging_cnts_h.active_ro_sessions, -1); done: unref_ro_session(ro_session, 1, 0); ro_session_unlock(ro_session_table, ro_session_entry); dlgb.release_dlg(dlg); return RO_RETURN_TRUE; } ```
It has to be split to:
``` static int ki_ro_ccr_stop(sip_msg_t *msg, str* p_direction, int p_code, str* p_reason) { struct ro_session* ro_session; struct ro_session_entry *ro_session_entry; unsigned int h_entry; str s_reason; unsigned int code; int dir = 0; /*any side*/ char *c_direction;
c_direction = p_direction->s; s_reason = *p_reason; code = (unsigned int)p_code;
LM_DBG("Inside Ro_CCR_Stop with direction [%s]\n", c_direction); if (strlen(c_direction) == 4) { if (c_direction[0] == 'O' || c_direction[0] == 'o') { dir = RO_ORIG_DIRECTION; } else { dir = RO_TERM_DIRECTION; } } else { LM_ERR("Unknown direction [%s] to terminate\n", c_direction); return RO_RETURN_FALSE; } struct dlg_cell* dlg = dlgb.get_dlg(msg); if (!dlg) { LM_ERR("Unable to find dialog to send CCR STOP record\n"); return RO_RETURN_ERROR; }
// switch (code) { // case 486: // termcode = VS_TERMCODE_BUSYHERE; // break; // case 487: // termcode = VS_TERMCODE_CANCELLED; // break; // case 480: // case 408: // /* subscriber not available */ // termcode = VS_TERMCODE_NOTFOUND; // break; // }
LM_DBG("Sending Stop record with code [%d] and reason [%.*s]\n", code, s_reason.len, s_reason.s);
LM_DBG("Found DLG [%d : %d]\n", dlg->h_id, dlg->h_entry);
ro_session = lookup_ro_session(dlg->h_entry, &dlg->callid, dir, 0); if (ro_session == NULL) { LM_DBG("no ro_session - ignoring\n"); dlgb.release_dlg(dlg); return RO_RETURN_TRUE; } h_entry = ro_session->h_entry; ro_session_entry = &(ro_session_table->entries[h_entry]);
ro_session_lock(ro_session_table, ro_session_entry);
if (ro_session->ccr_sent == 1) { LM_DBG("Ro CCR already sent for session [%.*s]\n", ro_session->ro_session_id.len, ro_session->ro_session_id.s); goto done; } send_ccr_stop_with_param(ro_session, code, &s_reason); //TODO = check the CCR was sent successfully. LM_DBG("Setting Ro session [%.*s] ccr_sent to 1\n", ro_session->ro_session_id.len, ro_session->ro_session_id.s); ro_session->ccr_sent = 1; ro_session->active = -1; // counter_add(ims_charging_cnts_h.active_ro_sessions, -1); done: unref_ro_session(ro_session, 1, 0); ro_session_unlock(ro_session_table, ro_session_entry); dlgb.release_dlg(dlg); return RO_RETURN_TRUE; } ```
And:
``` static int w_ro_ccr_stop(struct sip_msg *msg, char* c_direction, char* _code, char* _reason) { str s_direction, s_code, s_reason; int code;
s_direction.s = c_direction; s_direction.len = strlen(c_direction);
if (get_str_fparam(&s_code, msg, (fparam_t*) _code) < 0) { LM_ERR("failed to get code\n"); dlgb.release_dlg(dlg); return RO_RETURN_ERROR; } LM_DBG("Code is [%.*s]\n", s_code.len, s_code.s); if (get_str_fparam(&s_reason, msg, (fparam_t*) _reason) < 0) { LM_ERR("failed to get reason\n"); dlgb.release_dlg(dlg); return RO_RETURN_ERROR; }
if (str2int(&s_code, &code) != 0) { LM_ERR("Bad response code: [%.*s]\n", s_code.len, s_code.s); dlgb.release_dlg(dlg); return RO_RETURN_FALSE; }
return ki_ro_ccr_stop(msg, &s_direction, code, &s_reason); } ```
Then the `w_ro_ccr_stop()` remains exported to kamailio.cfg native scripting and `ki_ro_ccr_stop()` is exported to kemi. You see that `w_ro_ccr_stop()` keeps only the code related to fixing the parameters given by kamailio.cfg interpreter and then calls the `ki_ro_ccr_stop()` which retains more or less the rest of the code from the initial function.
Note that the split of the code done above was done without any checking, aiming to give hints on how should be done, without any compiling or other checking. Optimizations can also be done, by getting rid of the c_direction and s_reason inside ki_ro_ccr_stop() and use the function parameters directly.
Thanks for the explanation, will do it in that way.
@Riccardo-78 pushed 2 commits.
3914b3174774fcebd5b8ec58ba7852a855e907c6 ims_charging: export functions to kemi (+1 squashed commit) f82b72587aed00fe6f8bf99a2b15feeb57518f62 ims_diameter_server: export functions to kemi (+1 squashed commit)
Thanks, merging!
Very important for the future, do not do code formatting in the same commit that changes the behaviour or adds new code, because it is harder to spot what are the actual changes. Code formatting is more than welcome, but has to be done in separate commits.
Merged #2704 into master.