Selaa lähdekoodia

rtpengine: Add kamctl nh_reload_rtpp

Fifo command to allow reload from database node table.
Updates the state of the nodes or creates new ones; does not delete
the old nodes, not present anymore in the database.
Updated doku.
Stefan Mititelu 9 vuotta sitten
vanhempi
commit
d884698c91
2 muutettua tiedostoa jossa 68 lisäystä ja 2 poistoa
  1. 24 0
      modules/rtpengine/doc/rtpengine_admin.xml
  2. 44 2
      modules/rtpengine/rtpengine.c

+ 24 - 0
modules/rtpengine/doc/rtpengine_admin.xml

@@ -1231,6 +1231,30 @@ $ &ctltool; fifo nh_ping_rtpp all
 			</example>
 		</section>
 
+
+	    <section id="rtpengine.m.nh_reload_rtpp">
+			<title><function moreinfo="none">nh_reload_rtpp</function></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,
+				based on the database content. Old nodes are not deleted if they are deleted
+				from database. This may require locking on the global nodes list.
+			</para>
+			<example>
+			<title>
+				<function moreinfo="none">nh_reload_rtpp</function> usage</title>
+			<programlisting format="linespecific">
+...
+$ &ctltool; fifo nh_reload_rtpp
+...
+			</programlisting>
+			</example>
+		</section>
+
+
 	    <section id="rtpengine.m.nh_show_hash_total">
 			<title><function moreinfo="none">nh_show_hash_total</function></title>
 			<para>

+ 44 - 2
modules/rtpengine/rtpengine.c

@@ -107,7 +107,14 @@ MODULE_VERSION
 #define MI_SHOW_RTP_PROXIES			"nh_show_rtpp"
 #define MI_PING_RTP_PROXY           "nh_ping_rtpp"
 #define MI_SHOW_HASH_TOTAL          "nh_show_hash_total"
-
+#define MI_RELOAD_RTP_PROXY           "nh_reload_rtpp"
+
+#define MI_DB_NOT_FOUND		"RTP database not found"
+#define MI_DB_NOT_FOUND_LEN	(sizeof(MI_DB_NOT_FOUND)-1)
+#define MI_DB_ERR		"Error reloading from RTP database"
+#define MI_DB_ERR_LEN	(sizeof(MI_DB_ERR)-1)
+#define MI_DB_OK		"Success reloading from RTP database"
+#define MI_DB_OK_LEN	(sizeof(MI_DB_OK)-1)
 #define MI_RTP_PROXY_NOT_FOUND		"RTP proxy not found"
 #define MI_RTP_PROXY_NOT_FOUND_LEN	(sizeof(MI_RTP_PROXY_NOT_FOUND)-1)
 #define MI_PING_DISABLED			"NATping disabled from script"
@@ -222,6 +229,7 @@ static struct mi_root* mi_enable_rtp_proxy(struct mi_root* cmd_tree, void* param
 static struct mi_root* mi_show_rtp_proxy(struct mi_root* cmd_tree, void* param);
 static struct mi_root* mi_ping_rtp_proxy(struct mi_root* cmd_tree, void* param);
 static struct mi_root* mi_show_hash_total(struct mi_root* cmd_tree, void* param);
+static struct mi_root* mi_reload_rtp_proxy(struct mi_root* cmd_tree, void* param);
 
 
 static int rtpengine_disable_tout = 60;
@@ -357,7 +365,8 @@ static mi_export_t mi_cmds[] = {
 	{MI_ENABLE_RTP_PROXY,     mi_enable_rtp_proxy,  0,  0,  0},
 	{MI_SHOW_RTP_PROXIES,     mi_show_rtp_proxy,    0,  0,  0},
 	{MI_PING_RTP_PROXY,       mi_ping_rtp_proxy,    0,  0,  0},
-	{MI_SHOW_HASH_TOTAL,      mi_show_hash_total,    0,  0,  0},
+	{MI_SHOW_HASH_TOTAL,      mi_show_hash_total,   0,  0,  0},
+	{MI_RELOAD_RTP_PROXY,     mi_reload_rtp_proxy,  0,  0,  0},
 	{ 0, 0, 0, 0, 0}
 };
 
@@ -1374,6 +1383,39 @@ error:
 	return init_mi_tree(404, MI_HASH_ENTRIES_FAIL, MI_HASH_ENTRIES_FAIL_LEN);
 }
 
+static struct mi_root*
+mi_reload_rtp_proxy(struct mi_root* cmd_tree, void* param)
+{
+	struct mi_root *root = NULL;
+
+	if (rtpp_db_url.s == NULL) {
+		// no database
+		root = init_mi_tree(404, MI_DB_NOT_FOUND, MI_DB_NOT_FOUND_LEN);
+		if (!root) {
+			LM_ERR("the MI tree cannot be initialized!\n");
+			return 0;
+		}
+	} else {
+                if (init_rtpproxy_db() < 0) {
+			// fail reloading from database
+			root = init_mi_tree(404, MI_DB_ERR, MI_DB_ERR_LEN);
+			if (!root) {
+				LM_ERR("the MI tree cannot be initialized!\n");
+				return 0;
+			}
+                } else {
+			// success reloading from database
+			root = init_mi_tree(200, MI_DB_OK, MI_DB_OK_LEN);
+			if (!root) {
+				LM_ERR("the MI tree cannot be initialized!\n");
+				return 0;
+			}
+		}
+	}
+
+	return root;
+}
+
 
 static int
 mod_init(void)