From 29635e45b1f49e4b00daf91b4fb85cdae39edea7 Mon Sep 17 00:00:00 2001
From: Yalu Zhang <yalu.zhang@iopsys.eu>
Date: Mon, 30 Aug 2021 10:38:29 +0200
Subject: [PATCH] Reformatting voice ubus events

- asterisk.telephony -> voice.line, "line" -> "id"
- asterisk.sip -> voice.sip.client, "line" -> "uri"
- asterisk.mwi -> voice.mwi
---
 channels/chan_brcm.c                  |  4 +--
 res/res_pjsip_outbound_registration.c |  6 ++--
 res/res_pjsip_pubsub.c                | 49 ++++-----------------------
 3 files changed, 11 insertions(+), 48 deletions(-)

diff --git a/channels/chan_brcm.c b/channels/chan_brcm.c
index abeb330f9c..aaeab98a9e 100644
--- a/channels/chan_brcm.c
+++ b/channels/chan_brcm.c
@@ -128,7 +128,7 @@ static int endpt_get_rtp_stats(int line);
 /* Global brcm channel parameters */
 static const char tdesc[] = "Broadcom SLIC Driver";
 static const char config[] = "chan_telephony.conf";
-static const char broadcast_path[] = "asterisk.telephony";
+static const char broadcast_path[] = "voice.line";
 static line_settings line_config[MAX_NUM_LINEID];
 static int current_connection_id = 0;
 static int num_fxs_endpoints = -1;
@@ -468,8 +468,8 @@ static int brcm_send_ubus_event(char *ev_name, int line)
 		return -1;
 	}
 
+	blobmsg_add_u32(&blob, "id", line);
 	blobmsg_add_string(&blob, "event", ev_name);
-	blobmsg_add_u32(&blob, "line", line);
 
 	if (ubus_send_event(ubusctx, broadcast_path, blob.head) != UBUS_STATUS_OK) {
 		ast_log(LOG_NOTICE,"Error sending ubus message %s\n", ev_name);
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index dd70ef4aab..7b0564e806 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -256,7 +256,7 @@ AST_THREADSTORAGE(register_callback_invoked);
 
 /*! \brief Size of the buffer for creating a unique string for the line */
 #define LINE_PARAMETER_SIZE 8
-static const char broadcast_path[] = "asterisk.sip";
+static const char broadcast_path[] = "voice.sip.client";
 
 /*! \brief Various states that an outbound registration may be in */
 enum sip_outbound_registration_status {
@@ -1125,9 +1125,9 @@ static int sip_outbound_registration_send_ubus_event(char *ev_name,int time ,cha
 		return -1;
 	}
 
-	blobmsg_add_string(&blob, "event", ev_name);
+	blobmsg_add_string(&blob, "status", ev_name);
+	blobmsg_add_string(&blob, "uri", client);
 	blobmsg_add_u32(&blob, "expiration", time);
-	blobmsg_add_string(&blob, "line", client);
 
 	if(ubus_send_event(ubusContext, broadcast_path, blob.head) != UBUS_STATUS_OK) {
 		ast_log(LOG_NOTICE,"Error sending ubus message %s\n", ev_name);
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 06183b0f27..3deb955e12 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -226,7 +226,7 @@
  ***/
 
 static struct ubus_context *ubusContext = NULL;
-const char mwi_path[] = "asterisk.mwi";
+static const char mwi_path[] = "voice.mwi";
 static pj_bool_t pubsub_on_rx_request(pjsip_rx_data *rdata);
 
 static struct pjsip_module pubsub_module = {
@@ -238,8 +238,6 @@ static struct pjsip_module pubsub_module = {
 #define MOD_DATA_PERSISTENCE "sub_persistence"
 #define MOD_DATA_MSG "sub_msg"
 
-static const char broadcast_path[] = "asterisk.sip";
-
 static const pj_str_t str_event_name = { "Event", 5 };
 
 /*! \brief Scheduler used for automatically expiring publications */
@@ -563,49 +561,15 @@ static pjsip_evsub_user pubsub_cb = {
  * Initiate ubus connection.
  */
 static void ubus_init(void) {
-       ast_verbose("ubus init\n");
-       ubusContext = ubus_connect(NULL);
+	ast_verbose("ubus init\n");
+	ubusContext = ubus_connect(NULL);
 
-       if(!ubusContext)
-               ast_log(LOG_ERROR, "Failed to connect to ubus.");
+	if(!ubusContext)
+		ast_log(LOG_ERROR, "Failed to connect to ubus.");
 }
 
-static int sip_pubsub_send_ubus_event(char *ev_name,char *endpt,char *messagewaiting,int new_message,int old_message)
+static void send_mwi_event(const char *channeltype, const char *endpoint, const char *mailbox, const char *messages_waiting, int new, int old)
 {
-	struct blob_buf blob;
-	struct ubus_context *ubusctx;
-	int res = 0;
-
-	ubusctx = ubus_connect(NULL);
-	if (!ubusctx) {
-		return -1;
-	}
-
-	memset(&blob, 0, sizeof(blob));
-	if(blob_buf_init(&blob, 0)) {
-		ubus_free(ubusctx);
-		return -1;
-	}
-
-	blobmsg_add_string(&blob, "event", ev_name);
-	blobmsg_add_string(&blob, "endpoint", endpt);
-	blobmsg_add_string(&blob, "message waiting", messagewaiting);
-	blobmsg_add_u32(&blob, "new message", new_message);
-	blobmsg_add_u32(&blob, "old message", old_message);
-
-	if(ubus_send_event(ubusctx, broadcast_path, blob.head) != UBUS_STATUS_OK) {
-		ast_log(LOG_NOTICE,"Error sending ubus message %s\n", ev_name);
-		res = -1;
-	}
-
-	ubus_free(ubusctx);
-	blob_buf_free(&blob);
-
-	return res;
-}
-
-
-static void send_mwi_event(const char *channeltype, const char *endpoint, const char *mailbox, const char *messages_waiting, int new, int old) {
 	struct blob_buf bb;
 
 	ast_log(LOG_DEBUG, "MWI status = %s(%d,%d) \n", mailbox, new, old);
@@ -3777,7 +3741,6 @@ static pj_bool_t pubsub_on_rx_mwi_notify_request(pjsip_rx_data *rdata)
 		if (!ast_strlen_zero(endpoint->incoming_mwi_mailbox) && !ast_strlen_zero(summary.messages_waiting)) {
 			send_mwi_event("PJSIP", endpoint_name, endpoint->incoming_mwi_mailbox, summary.messages_waiting,
 				summary.voice_messages_new, summary.voice_messages_old);
-			sip_pubsub_send_ubus_event("NOTIFY",endpoint_name,summary.messages_waiting,summary.voice_messages_new,summary.voice_messages_old);
 			ast_string_field_set(endpoint, messages_waiting, summary.messages_waiting);
 		}
 
-- 
GitLab