Module: kamailio Branch: master Commit: 4160842f809edffe6c09ef0f84ba53fef01cbc6f URL: https://github.com/kamailio/kamailio/commit/4160842f809edffe6c09ef0f84ba53fe...
Author: Yasin CANER caner_yaso@hotmail.com Committer: Yasin CANER caner_yaso@hotmail.com Date: 2019-12-16T06:41:50-05:00
keepalive : added keepalive.get and keepalive.flush rpc commands
added keepalive.get and keepalive.flush rpc commands
---
Modified: src/modules/keepalive/keepalive_rpc.c
---
Diff: https://github.com/kamailio/kamailio/commit/4160842f809edffe6c09ef0f84ba53fe... Patch: https://github.com/kamailio/kamailio/commit/4160842f809edffe6c09ef0f84ba53fe...
---
diff --git a/src/modules/keepalive/keepalive_rpc.c b/src/modules/keepalive/keepalive_rpc.c index a873effdd6..9850b29648 100644 --- a/src/modules/keepalive/keepalive_rpc.c +++ b/src/modules/keepalive/keepalive_rpc.c @@ -44,18 +44,21 @@ static const char *keepalive_rpc_list_doc[2]; static const char *keepalive_rpc_add_doc[2]; static const char *keepalive_rpc_del_doc[2]; - +static const char *keepalive_rpc_get_doc[2]; +static const char *keepalive_rpc_flush_doc[2];
static void keepalive_rpc_list(rpc_t *rpc, void *ctx); static void keepalive_rpc_add(rpc_t *rpc, void *ctx); static void keepalive_rpc_del(rpc_t *rpc, void *ctx); - +static void keepalive_rpc_get(rpc_t *rpc, void *ctx); +static void keepalive_rpc_flush(rpc_t *rpc, void *ctx);
rpc_export_t keepalive_rpc_cmds[] = { {"keepalive.list", keepalive_rpc_list, keepalive_rpc_list_doc, 0}, {"keepalive.add", keepalive_rpc_add, keepalive_rpc_add_doc, 0}, {"keepalive.del", keepalive_rpc_del, keepalive_rpc_del_doc, 0}, - + {"keepalive.get", keepalive_rpc_get, keepalive_rpc_get_doc, 0}, + {"keepalive.flush", keepalive_rpc_flush, keepalive_rpc_flush_doc, 0}, {0, 0, 0, 0} };
@@ -162,3 +165,72 @@ static void keepalive_rpc_del(rpc_t *rpc, void *ctx) } static const char *keepalive_rpc_del_doc[2] = { "deletes destination from keepalive memory. usage: keepalive.del sip:username@domain listname", 0}; + +static void keepalive_rpc_get(rpc_t *rpc, void *ctx) +{ + str sip_adress = {0,0}; + str table_name ={0,0}; + int ret = 0; + ka_dest_t *target=0 , *head =0; + void *sub; + + 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 gets [%.*s]\n", sip_adress.len , sip_adress.s); + + if(sip_adress.len < 1 || table_name.len < 1){ + LM_ERR("parameter is len less than 1 \n"); + rpc->fault(ctx, 500, "parameter is len less than 1"); + return; + } + ka_lock_destination_list(); + + if(ka_find_destination(&sip_adress, &table_name, &target, &head) < 0 ){ + LM_ERR("couldn't get data from list \n" ); + rpc->fault(ctx, 500, "couldn't get data from list"); + ka_unlock_destination_list(); + + return; + } + + if(!target){ + LM_ERR("Target is empty \n" ); + rpc->fault(ctx, 500, "couldn't get data from list"); + ka_unlock_destination_list(); + return; + } + + rpc->add(ctx, "{", &sub); + + rpc->struct_add(sub, "SSd", "uri", &target->uri, "owner", &target->owner,"state", target->state); + + ka_unlock_destination_list(); + + 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; + ka_unlock_destination_list(); + + return; +} +static const char *keepalive_rpc_flush_doc[2] = { + "Flush data from keepalive memory. usage keepalive.flush ", 0};