- Fixed the way the module is initialized, causing problems when using destination mod parameter because when invoking this parameter some utilities are not initialized (timers).
<!-- 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 - [x] Small bug fix (non-breaking change which fixes an issue) - [ ] 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 - [x] Related to issue #2476 (replace XXXX with an open issue number)
#### Description <!-- Describe your changes in detail --> Fixed the way the module is initialized, causing problems when using destination mod parameter because when invoking this parameter some utilities are not yet initialized (timers). You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2579
-- Commit Summary --
* keepalive: fix initialization when using destination mod param
-- File Changes --
M src/modules/keepalive/keepalive.h (8) M src/modules/keepalive/keepalive_mod.c (68)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2579.patch https://github.com/kamailio/kamailio/pull/2579.diff
@linuxmaniac commented on this pull request.
- ka_initial_dest_t * new_destination = (ka_initial_dest_t *) shm_malloc(sizeof(ka_initial_dest_t));
+ new_destination->uri.s = shm_malloc(sizeof(char) * strlen(uri)); + new_destination->owner.s = shm_malloc(sizeof(char) * strlen(owner)); + + memcpy(new_destination->uri.s, uri, strlen(uri)); + new_destination->uri.len = strlen(uri); + + memcpy(new_destination->owner.s, owner, strlen(owner)); + new_destination->owner.len = strlen(owner); + + new_destination->next = NULL; + + if (ka_initial_destinations_list == NULL) { + ka_initial_destinations_list = new_destination; + } else { + ka_initial_dest_t *current_position = ka_initial_destinations_list;
current_position has to be defined at the beginning of the function
@linuxmaniac commented on this pull request.
- str owner = str_init("_params");
- LM_DBG("adding destination %.*s\n", dest.len, dest.s); + return 1; +} + +static int ka_add_initial_destinations() { + LM_DBG("ka_add_initial_destinations called \n"); + int res = 1; + + ka_initial_dest_t *current_position = ka_initial_destinations_list; + while ( res > 0 && current_position != NULL) { + res = ka_add_dest(&(current_position->uri), &(current_position->owner), 0, ka_ping_interval, 0, 0, 0); + LM_INFO("Added initial destination Via "destination" parameter <%.*s> \n", current_position->uri.len, current_position->uri.s); + shm_free(current_position->uri.s); + shm_free(current_position->owner.s); + ka_initial_dest_t *old_position = current_position;
old_position has to be defined at the beginning of the function
@NGSegovia commented on this pull request.
- ka_initial_dest_t * new_destination = (ka_initial_dest_t *) shm_malloc(sizeof(ka_initial_dest_t));
+ new_destination->uri.s = shm_malloc(sizeof(char) * strlen(uri)); + new_destination->owner.s = shm_malloc(sizeof(char) * strlen(owner)); + + memcpy(new_destination->uri.s, uri, strlen(uri)); + new_destination->uri.len = strlen(uri); + + memcpy(new_destination->owner.s, owner, strlen(owner)); + new_destination->owner.len = strlen(owner); + + new_destination->next = NULL; + + if (ka_initial_destinations_list == NULL) { + ka_initial_destinations_list = new_destination; + } else { + ka_initial_dest_t *current_position = ka_initial_destinations_list;
Is there any programming style recommendation? I'm sorry to disagree here but some code checkers may complain about that saying "The scope of the variable 'x' can be reduced"
@linuxmaniac commented on this pull request.
- ka_initial_dest_t * new_destination = (ka_initial_dest_t *) shm_malloc(sizeof(ka_initial_dest_t));
+ new_destination->uri.s = shm_malloc(sizeof(char) * strlen(uri)); + new_destination->owner.s = shm_malloc(sizeof(char) * strlen(owner)); + + memcpy(new_destination->uri.s, uri, strlen(uri)); + new_destination->uri.len = strlen(uri); + + memcpy(new_destination->owner.s, owner, strlen(owner)); + new_destination->owner.len = strlen(owner); + + new_destination->next = NULL; + + if (ka_initial_destinations_list == NULL) { + ka_initial_destinations_list = new_destination; + } else { + ka_initial_dest_t *current_position = ka_initial_destinations_list;
Just an example: https://github.com/kamailio/kamailio/commit/daa86b204d3030e2abb2f2459aa34899...
@NGSegovia commented on this pull request.
- ka_initial_dest_t * new_destination = (ka_initial_dest_t *) shm_malloc(sizeof(ka_initial_dest_t));
+ new_destination->uri.s = shm_malloc(sizeof(char) * strlen(uri)); + new_destination->owner.s = shm_malloc(sizeof(char) * strlen(owner)); + + memcpy(new_destination->uri.s, uri, strlen(uri)); + new_destination->uri.len = strlen(uri); + + memcpy(new_destination->owner.s, owner, strlen(owner)); + new_destination->owner.len = strlen(owner); + + new_destination->next = NULL; + + if (ka_initial_destinations_list == NULL) { + ka_initial_destinations_list = new_destination; + } else { + ka_initial_dest_t *current_position = ka_initial_destinations_list;
I still see more cons than pros, but OK. Updating this.
@NGSegovia pushed 1 commit.
871ae263f0547c4a1d7c394d8fded054e0d55818 keepalive: fix initialization when using destination mod param
Regarding the Coding style/C standard requirements, I started a discussion several months ago to see what people/devs consider to be better to use:
* https://lists.kamailio.org/pipermail/sr-users/2020-April/109072.html
Kamailio being used in various embedded devices, with stricter compilers, in terms of declaring variables, they have to be at least at the beginning of the block, although now I also prefer at the beginning of functions, since we guide mainly after C89 (which was the implemented in compilers when project was started in 2000).
On PR, I haven't done any extensive review, but if no other comments, it can be merged.
Regarding the Coding style/C standard requirements, I started a discussion several months ago to see what people/devs consider to be better to use:
Kamailio being used in various embedded devices, with stricter compilers, in terms of declaring variables, they have to be at least at the beginning of the block, although now I also prefer at the beginning of functions, since we guide mainly after C89 (which was the implemented in compilers when project was started in 2000).
On PR, I haven't done any extensive review, but if no other comments, it can be merged.
Cristal clear, thanks for the explanation Daniel!
Merged #2579 into master.