From 5b2ad5c7c3fbdadb856b32b1cf8ad8ecb913ba63 Mon Sep 17 00:00:00 2001 From: Yasin CANER Date: Mon, 16 Dec 2019 06:35:55 -0500 Subject: [PATCH 1/4] keepalive : added keepalive.add rpc command added keepalive.add rpc command --- src/modules/keepalive/keepalive_rpc.c | 36 +++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/modules/keepalive/keepalive_rpc.c b/src/modules/keepalive/keepalive_rpc.c index 8efe0fb1173..88de7bae04e 100644 --- a/src/modules/keepalive/keepalive_rpc.c +++ b/src/modules/keepalive/keepalive_rpc.c @@ -42,10 +42,14 @@ #include "api.h" static const char *keepalive_rpc_list_doc[2]; +static const char *keepalive_rpc_add_doc[2]; + static void keepalive_rpc_list(rpc_t *rpc, void *ctx); +static void keepalive_rpc_add(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}, {0, 0, 0, 0} }; @@ -87,3 +91,35 @@ 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); + rpc->fault(ctx, 500, "Not enough parameters or wrong format"); + return; + } + + LM_DBG(" keepalive adds [%.*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; + } + + if(ka_add_dest(&sip_adress,&table_name,0,0,0) < 0 ){ + LM_ERR("couldn't add data to list \n" ); + rpc->fault(ctx, 500, "couldn't add data to list"); + return; + } + + return; +} +static const char *keepalive_rpc_add_doc[2] = { + "adds new destination to keepalive memory. usage keepalive.add sip:username@domain listname", 0}; From 844c680fbe6740f5eef9bee83ebefa36934142d7 Mon Sep 17 00:00:00 2001 From: Yasin CANER Date: Mon, 16 Dec 2019 06:38:05 -0500 Subject: [PATCH 2/4] keepalive : added keepalive.del rpc command added keepalive.del rpc command --- src/modules/keepalive/keepalive_rpc.c | 41 ++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/modules/keepalive/keepalive_rpc.c b/src/modules/keepalive/keepalive_rpc.c index 88de7bae04e..a873effdd6b 100644 --- a/src/modules/keepalive/keepalive_rpc.c +++ b/src/modules/keepalive/keepalive_rpc.c @@ -43,13 +43,19 @@ 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 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); + 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}, + {0, 0, 0, 0} }; @@ -122,4 +128,37 @@ static void keepalive_rpc_add(rpc_t *rpc, void *ctx) return; } static const char *keepalive_rpc_add_doc[2] = { - "adds new destination to keepalive memory. usage keepalive.add sip:username@domain listname", 0}; + "adds new destination to keepalive memory. usage: keepalive.add sip:username@domain listname", 0}; + +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); + + 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; + } + + if(ka_del_destination(&sip_adress,&table_name) < 0 ){ + LM_ERR("couldn't delete data from list \n" ); + rpc->fault(ctx, 500, "couldn't delete data from list"); + return; + } + + return; +} +static const char *keepalive_rpc_del_doc[2] = { + "deletes destination from keepalive memory. usage: keepalive.del sip:username@domain listname", 0}; From 4160842f809edffe6c09ef0f84ba53fef01cbc6f Mon Sep 17 00:00:00 2001 From: Yasin CANER Date: Mon, 16 Dec 2019 06:41:50 -0500 Subject: [PATCH 3/4] keepalive : added keepalive.get and keepalive.flush rpc commands added keepalive.get and keepalive.flush rpc commands --- src/modules/keepalive/keepalive_rpc.c | 78 +++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/src/modules/keepalive/keepalive_rpc.c b/src/modules/keepalive/keepalive_rpc.c index a873effdd6b..9850b296482 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}; From d79e26fd50b3a28dcfd4c0a938bcc3d0a3fc30b5 Mon Sep 17 00:00:00 2001 From: Yasin CANER Date: Mon, 16 Dec 2019 16:49:02 +0300 Subject: [PATCH 4/4] keepalive : added doc for add/del/get/flush rpc commands added doc for add/del/get/flush rpc commands --- src/modules/keepalive/doc/keepalive_admin.xml | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/modules/keepalive/doc/keepalive_admin.xml b/src/modules/keepalive/doc/keepalive_admin.xml index 4fcd0a18ae8..5db99eee4a1 100644 --- a/src/modules/keepalive/doc/keepalive_admin.xml +++ b/src/modules/keepalive/doc/keepalive_admin.xml @@ -245,7 +245,71 @@ ka_del_destination("sip:192.168.1.10:5060;transport=tcp"); keepalive.list - + +
+ <function>keepalive.add</function> + + Adds destination in memory. + + + Name: keepalive.add + + Parameters: sip_uri listname + + <function>keepalive.add</function> RPC example + + keepalive.add sip:username@domain listname + + +
+
+ <function>keepalive.del</function> + + Deletes destination in memory. + + + Name: keepalive.del + + Parameters: sip_uri listname + + <function>keepalive.del</function> RPC example + + keepalive.del sip:username@domain listname + + +
+
+ <function>keepalive.get</function> + + Gets destination in memory. + + + Name: keepalive.get + + Parameters: sip_uri listname + + <function>keepalive.get</function> RPC example + + keepalive.get sip:username@domain listname + + +
+
+ <function>keepalive.flush</function> + + Deletes all destinations in memory. + + + Name: keepalive.flush + + Parameters: + + <function>keepalive.flush</function> RPC example + + keepalive.flush + + +