@rfuchs commented on this pull request.


In src/modules/rtpengine/rtpengine.c:

> +	s_port.len = rtpengine_dtmf_event_sock.s + rtpengine_dtmf_event_sock.len - s_port.s;
+
+	if (s_port.len <= 0 || str2int(&s_port, &port) < 0 || port > 65535) {
+		LM_ERR("failed to initialize dtmf event listener because port is invalid %.*s\n", rtpengine_dtmf_event_sock.len, rtpengine_dtmf_event_sock.s);
+		return;
+	}
+	rtpengine_dtmf_event_sock.len -= s_port.len + 1;
+	trim(&rtpengine_dtmf_event_sock);
+	rtpengine_dtmf_event_sock.s[rtpengine_dtmf_event_sock.len] = '\0';
+
+	memset(&udp_addr, 0, sizeof(udp_addr));
+
+	if (rtpengine_dtmf_event_sock.s[0] == '[') {
+		udp_addr.sin6.sin6_family = AF_INET6;
+		udp_addr.sin6.sin6_port = htons(port);
+		ret = inet_pton(AF_INET, rtpengine_dtmf_event_sock.s, &udp_addr.sin6.sin6_addr);

Must be AF_INET6 here


In src/modules/rtpengine/rtpengine.c:

> +		ret = inet_pton(AF_INET, rtpengine_dtmf_event_sock.s, &udp_addr.sin.sin_addr);
+	}			
+
+	if (ret != 1) {
+		LM_ERR("failed to initialize dtmf event listener because address could not be created for %s\n", rtpengine_dtmf_event_sock.s);
+		return;
+	}
+
+	rtpengine_dtmf_event_fd = socket(udp_addr.s.sa_family, SOCK_DGRAM, 0);
+
+	if(rtpengine_dtmf_event_fd < 0) {
+		LM_ERR("can't create socket\n");
+		return;
+	}
+	
+	if (bind(rtpengine_dtmf_event_fd, (struct sockaddr*)&udp_addr.s, sizeof(udp_addr.s)) < 0) {

sizeof(udp_addr.s) is sizeof(struct sockaddr) which I think may be too small for INET6. sizeof(udp_addr) would be a better option


In src/modules/rtpengine/rtpengine.c:

> +		}
+
+		if (dtmf_event_rt == -1) {
+			LM_NOTICE("nothing to do - nobody is listening!\n");
+			goto end;
+		}
+
+		p = shm_malloc(ret + 1);
+		if (!p) {
+			LM_ERR("could not allocate %d for buffer %.*s\n", ret, ret, buffer);
+			goto end;
+		}
+		memcpy(p, buffer, ret);
+		p[ret] = '\0';		
+
+		if (rtpengine_raise_dtmf_event(p, ret) < 0) {

I think this leaks the p buffer if the return value == 0


In src/modules/rtpengine/rtpengine.c:

> +
+end:	
+	close(rtpengine_dtmf_event_fd);
+}
+
+static int rtpengine_raise_dtmf_event(char *buffer, int len) {
+	srjson_doc_t jdoc;
+	srjson_t *it = NULL;
+	struct sip_msg *fmsg = NULL;
+	struct run_act_ctx ctx;
+	int rtb;	
+
+	LM_DBG("executing event_route[rtpengine:dtmf-event] (%d)\n", dtmf_event_rt);
+	LM_DBG("dispatching buffer: %s\n", buffer);
+
+	srjson_InitDoc(&jdoc, NULL);

jdoc needs to be freed somewhere


In src/modules/rtpengine/rtpengine.c:

> @@ -261,7 +262,7 @@ static int add_rtpp_node_info(
 		void *ptrs, struct rtpp_node *crt_rtpp, struct rtpp_set *rtpp_list);
 static int rtpp_test_ping(struct rtpp_node *node);
 
-static void rtpengine_dtmf_events_loop(int rank);
+static void rtpengine_dtmf_events_loop();

nit: for better standards compliance, be explicit with (void)


In src/modules/rtpengine/rtpengine.c:

> +	}	
+
+	if(rank == PROC_MAIN) {
+		if(rtpengine_dtmf_event_sock.len > 0) {
+			LM_DBG("Register RTPENGINE DTMF WORKER %d\n", mypid);
+			/* fork worker process */
+			mypid = fork_process(PROC_RPC, "RTPENGINE DTMF WORKER", 1);
+			if(mypid < 0) {
+				LM_ERR("failed to fork RTPENGINE DTMF WORKER process %d\n", mypid);
+				return -1;
+			} else if(mypid == 0) {
+				if(cfg_child_init())
+					return -1;
+				/* this will loop forever */
+				rtpengine_dtmf_events_loop();
+			} 

I suppose there should be an exit() at the end here? Although I'm not too familiar with how the Kamailio internals are handling this


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <kamailio/kamailio/pull/3473/review/1475119109@github.com>