miconda commented on this pull request.
+
+ if ((wsc =
wsconn_get(msg->rcv.proto_reserved1)) == NULL) {
+ LM_ERR("$ws_real_src_ip cannot retrieve websocket connection\n");
+ return pv_get_null(msg, param, res);
+ }
+
+ wscid = wsc->id;
+
+ if (wsc->real_src_ip[0] == 0) {
+ wsconn_put(wsc);
+ LM_DBG("$ws_real_src_ip ws_conid %d real_src_ip is not set\n", wscid);
+ return pv_get_null(msg, param, res);
+ }
+
+ LM_DBG("$ws_real_src_ip ws_conid %d wsc->real_src_ip is %s (%d)\n", wscid,
wsc->real_src_ip, (int)strlen(wsc->real_src_ip));
+ len = snprintf(buff, IP_ADDR_MAX_STR_SIZE, "%s", wsc->real_src_ip);
I noticed the use of snprintf(...) for storing just a single string value in another
buffer. Is this chosen for any particular reason instead of strcpy()/strncpy()? Afaik,
functions with variadic parameters tend to be slower.
+ if (wsc->real_src_ip[0] == 0) {
+ wsconn_put(wsc);
+ LM_DBG("$ws_real_src_ip ws_conid %d real_src_ip is not set\n", wscid);
+ return pv_get_null(msg, param, res);
+ }
+
+ LM_DBG("$ws_real_src_ip ws_conid %d wsc->real_src_ip is %s (%d)\n", wscid,
wsc->real_src_ip, (int)strlen(wsc->real_src_ip));
+ len = snprintf(buff, IP_ADDR_MAX_STR_SIZE, "%s", wsc->real_src_ip);
+ buff[len] = 0;
+
+ wsconn_put(wsc);
+
+ ip_str.s = (char *)buff;
+ ip_str.len = strlen(buff);
+ LM_DBG("$ws_real_src_ip ws_conid %d real_src_ip is %s (%d)\n", wscid,
ip_str.s, ip_str.len);
+ return pv_get_strval(msg, param, res, &ip_str);
The need for ip_str variable can be avoided by using pv_get_strzval(msg, param, buf), if I
haven't missed any other use of ip_str.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/1002#pullrequestreview-22717738