<!-- 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 --> - [ ] 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 --> added add/del/get/flush rpc commands You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/2177
-- Commit Summary --
* keepalive : added keepalive.add rpc command * keepalive : added keepalive.del rpc command * keepalive : added keepalive.get and keepalive.flush rpc commands
-- File Changes --
M src/modules/keepalive/keepalive_rpc.c (147)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/2177.patch https://github.com/kamailio/kamailio/pull/2177.diff
documentation is missing
@ycaner06 pushed 1 commit.
d79e26fd50b3a28dcfd4c0a938bcc3d0a3fc30b5 keepalive : added doc for add/del/get/flush rpc commands
It can be merged if no one else finds something to be changed.
oej commented on this pull request.
@@ -87,3 +100,137 @@ static void keepalive_rpc_list(rpc_t *rpc, void *ctx)
return; } + +static void keepalive_rpc_add(rpc_t *rpc, void *ctx) +{ + str sip_adress = {0,0}; + str table_name ={0,0}; + int ret = 0; + + ret = rpc->scan(ctx, "SS",&sip_adress,&table_name); + + if (ret < 2) { + LM_ERR("not enough parameters - read so far: %d\n", ret);
When reading the log file, you probably want to add the command name or some context LM_ERR("keepalived.add : not enough parameters - read so far: %d\n", ret);
oej commented on this pull request.
+static void keepalive_rpc_del(rpc_t *rpc, void *ctx) +{ + str sip_adress = {0,0}; + str table_name ={0,0}; + int ret = 0; + + ret = rpc->scan(ctx, "SS",&sip_adress,&table_name); + + if (ret < 2) { + LM_ERR("not enough parameters - read so far: %d\n", ret); + rpc->fault(ctx, 500, "Not enough parameters or wrong format"); + return; + } + + LM_DBG(" keepalive deletes [%.*s]\n", sip_adress.len , sip_adress.s);
s /deletes/delete/
oej commented on this pull request.
- return;
+} +static const char *keepalive_rpc_get_doc[2] = { + "gets destination info data from keepalive memory. usage keepalive.get sip:xx@domain listname", 0}; + + +static void keepalive_rpc_flush(rpc_t *rpc, void *ctx) +{ + ka_dest_t *dest; + LM_DBG("Keepalive flushes \n"); + ka_lock_destination_list(); + + for(dest = ka_destinations_list->first; dest != NULL; dest = dest->next) { + free_destination(dest); + } + ka_destinations_list->first = 0;
Are you sure you want to set it to "0" here? first seems to be of type ka_dest_t * so maybe NULL is better?
miconda commented on this pull request.
- return;
+} +static const char *keepalive_rpc_get_doc[2] = { + "gets destination info data from keepalive memory. usage keepalive.get sip:xx@domain listname", 0}; + + +static void keepalive_rpc_flush(rpc_t *rpc, void *ctx) +{ + ka_dest_t *dest; + LM_DBG("Keepalive flushes \n"); + ka_lock_destination_list(); + + for(dest = ka_destinations_list->first; dest != NULL; dest = dest->next) { + free_destination(dest); + } + ka_destinations_list->first = 0;
There is no strict policy on using `NULL` or `0` for pointers, probably the former is more intuitive for pointers and eventually raise compile warnings if the type is not pointer, but there are many places in the code where `0` is used for this purpose. If someone wants to make it coherent everywhere by using `NULL` instead of `0` for pointers, I am fine with it.
Given that the PR is rather old here, I am going to merge it and fix what was pointed in the other comments.
Merged #2177 into master.
miconda commented on this pull request.
@@ -87,3 +100,137 @@ static void keepalive_rpc_list(rpc_t *rpc, void *ctx)
return; } + +static void keepalive_rpc_add(rpc_t *rpc, void *ctx) +{ + str sip_adress = {0,0}; + str table_name ={0,0}; + int ret = 0; + + ret = rpc->scan(ctx, "SS",&sip_adress,&table_name); + + if (ret < 2) { + LM_ERR("not enough parameters - read so far: %d\n", ret);
I haven't changed this one. The C function name is printed in each log message, being suggestive enough, but if you want to make an update, you can push it to the repo.