Module: kamailio Branch: master Commit: 9b5d2b50a51b0fe2379a6ad209d8d94c821c6615 URL: https://github.com/kamailio/kamailio/commit/9b5d2b50a51b0fe2379a6ad209d8d94c...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2017-01-03T12:33:54+01:00
rtpengine: implemented rpc command rtpengine.reload
---
Modified: src/modules/rtpengine/doc/rtpengine_admin.xml Modified: src/modules/rtpengine/rtpengine.c
---
Diff: https://github.com/kamailio/kamailio/commit/9b5d2b50a51b0fe2379a6ad209d8d94c... Patch: https://github.com/kamailio/kamailio/commit/9b5d2b50a51b0fe2379a6ad209d8d94c...
---
diff --git a/src/modules/rtpengine/doc/rtpengine_admin.xml b/src/modules/rtpengine/doc/rtpengine_admin.xml index 4b6ef2c..6325b80 100644 --- a/src/modules/rtpengine/doc/rtpengine_admin.xml +++ b/src/modules/rtpengine/doc/rtpengine_admin.xml @@ -1204,6 +1204,33 @@ start_recording(); </section>
<section> + <title>RPC Commands</title> + + <section id="rtpengine.r.reload"> + <title>rtpengine.reload</title> + <para> + Reloads the database node table content <emphasis>if configured</emphasis>. + Returns specific message related to success, failure and no db_url configured. + </para> + <para> + NOTE: The current behaviour updates the nodes state or creates new ones or + hides old ones, based on the database content. If allow_op modparam is enabled, + the sessions are still allowed to finish for the hidden old nodes. + </para> + <example> + <title> + <function moreinfo="none">rtpengine.reload</function> usage</title> + <programlisting format="linespecific"> +... +$ &kamcmd; rtpengine.reload +... + </programlisting> + </example> + </section> + + </section> + + <section> <title><acronym>MI</acronym> Commands</title> <section id="rtpengine.m.nh_enable_rtpp"> <title><function moreinfo="none">nh_enable_rtpp proxy_url/all 0/1</function></title> diff --git a/src/modules/rtpengine/rtpengine.c b/src/modules/rtpengine/rtpengine.c index 57f3ca9..bd121c0 100644 --- a/src/modules/rtpengine/rtpengine.c +++ b/src/modules/rtpengine/rtpengine.c @@ -75,6 +75,8 @@ #include "../../core/mod_fix.h" #include "../../core/dset.h" #include "../../core/route.h" +#include "../../core/rpc.h" +#include "../../core/rpc_lookup.h" #include "../../modules/tm/tm_load.h" #include "rtpengine.h" #include "rtpengine_funcs.h" @@ -1610,6 +1612,51 @@ mi_reload_rtp_proxy(struct mi_root* cmd_tree, void* param) return root; }
+static void rtpengine_rpc_reload(rpc_t* rpc, void* ctx) +{ + unsigned int current_rtpp_no; + + if (rtpp_db_url.s == NULL) { + // no database + rpc->fault(ctx, 500, "No Database URL"); + return; + } + + if (init_rtpproxy_db() < 0) { + // fail reloading from database + rpc->fault(ctx, 500, "Failed reloading db"); + return; + } + + lock_get(rtpp_no_lock); + current_rtpp_no = *rtpp_no; + lock_release(rtpp_no_lock); + + if (rtpp_socks_size != current_rtpp_no) { + build_rtpp_socks(current_rtpp_no); + } +} + +static const char* rtpengine_rpc_reload_doc[2] = { + "Reload rtpengine proxies.", + 0 +}; + +rpc_export_t rtpengine_rpc[] = { + {"rtpengine.reload", rtpengine_rpc_reload, rtpengine_rpc_reload_doc, 0}, + {0, 0, 0, 0} +}; + +static int rtpengine_rpc_init(void) +{ + if (rpc_register_array(rtpengine_rpc)!=0) + { + LM_ERR("failed to register RPC commands\n"); + return -1; + } + return 0; +} + static int mod_init(void) { @@ -1623,6 +1670,11 @@ mod_init(void) LM_ERR("failed to register MI commands\n"); return -1; } + if(rtpengine_rpc_init()<0) + { + LM_ERR("failed to register RPC commands\n"); + return -1; + }
rtpp_no = (unsigned int*)shm_malloc(sizeof(unsigned int)); if (!rtpp_no) {