@rfuchs commented on this pull request.


> +     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

> +             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

> +             }
+
+               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

> +
+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

> @@ -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)`

> +     }       
+
+       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 or view it on GitHub:
https://github.com/kamailio/kamailio/pull/3473#pullrequestreview-1475119109
You are receiving this because you are subscribed to this thread.

Message ID: <kamailio/kamailio/pull/3473/review/[email protected]>
_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to [email protected]

Reply via email to