webrtc_private: Replace private IP with hostname in local ICE candidate 00/286100/4
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 27 Dec 2022 08:25:30 +0000 (17:25 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 4 Jan 2023 03:33:53 +0000 (12:33 +0900)
[Version] 0.3.278
[Issue type] New feature

Change-Id: I351db37c3a1fafec9b63bb10840b145f8eb0fa53
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_dns.c
src/webrtc_private.c

index 08168f3c616975a386c65887db8a5ca38bbbf00d..085905295ced001d5f046a7b6a308c283f063877 100644 (file)
@@ -518,6 +518,8 @@ typedef struct _webrtc_s {
        struct {
                DNSServiceRef client;
                DNSServiceRef client_pa; /* proxy address record */
+               gchar *hostname;
+               gchar *ip;
        } dns;
 
        guint idle_cb_event_source_ids[IDLE_CB_TYPE_NUM];
@@ -850,6 +852,7 @@ void _release_tbm_bo(webrtc_tbm_s *tbm, void *bo);
 /* DNS */
 int _register_dns_service(webrtc_s *webrtc);
 void _unregister_dns_service(webrtc_s *webrtc);
+gchar *_replace_ip_with_hostname(webrtc_s *webrtc, const gchar *candidate);
 
 /* websocket*/
 typedef int (*_websocket_cb)(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
index 3171b93fa8a3344b96103612d594af973665289a..45b21b3ff05dae441e2806cccdd55e33220166ff 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.277
+Version:    0.3.278
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index fc6aa09a0adc201a8942eaf373c5bb2f140ab59a..dc5aefd763279758018753877e06edd757c34e89 100644 (file)
@@ -107,7 +107,7 @@ int _register_dns_service(webrtc_s *webrtc)
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(webrtc->dns.client_pa != NULL, WEBRTC_ERROR_INVALID_OPERATION, "client_pa has been already registered");
-       RET_VAL_IF(webrtc->dns.client != NULL, WEBRTC_ERROR_INVALID_OPERATION, "client_pa has been already registered");
+       RET_VAL_IF(webrtc->dns.client != NULL, WEBRTC_ERROR_INVALID_OPERATION, "client has been already registered");
 
        ip = __get_my_private_ip();
        RET_VAL_IF(ip == NULL, WEBRTC_ERROR_INVALID_OPERATION, "ip is NULL");
@@ -159,7 +159,8 @@ int _register_dns_service(webrtc_s *webrtc)
 
        LOG_INFO("client_pa[%p] client[%p] name[%s] host[%s] ip[%s]", webrtc->dns.client_pa, webrtc->dns.client, DNSS_REGISTER_NAME, host, ip);
 
-       g_free(ip);
+       webrtc->dns.hostname = g_strdup(host);
+       webrtc->dns.ip = ip;
 
        return WEBRTC_ERROR_NONE;
 
@@ -182,11 +183,35 @@ void _unregister_dns_service(webrtc_s *webrtc)
        RET_IF(webrtc->dns.client_pa == NULL, "client_pa is NULL");
        RET_IF(webrtc->dns.client == NULL, "client is NULL");
 
-       LOG_INFO("client_pa[%p] client[%p]", webrtc->dns.client_pa, webrtc->dns.client);
+       LOG_INFO("client_pa[%p] client[%p] hostname[%s]", webrtc->dns.client_pa, webrtc->dns.client, webrtc->dns.hostname);
 
        DNSServiceRefDeallocate(webrtc->dns.client_pa);
        DNSServiceRefDeallocate(webrtc->dns.client);
+       g_free(webrtc->dns.hostname);
+       g_free(webrtc->dns.ip);
        webrtc->dns.client_pa = NULL;
        webrtc->dns.client = NULL;
+       webrtc->dns.hostname = NULL;
+       webrtc->dns.ip = NULL;
+}
+
+gchar *_replace_ip_with_hostname(webrtc_s *webrtc, const gchar *candidate)
+{
+       GString *candidate_str;
+
+       RET_VAL_IF(webrtc == NULL, NULL, "webrtc is NULL");
+       RET_VAL_IF(candidate == NULL, NULL, "candidate is NULL");
+
+       if (!webrtc->ini.general.conceal_private_ip)
+               return NULL;
+
+       RET_VAL_IF(webrtc->dns.hostname == NULL, NULL, "dns.hostname is NULL");
+       RET_VAL_IF(webrtc->dns.ip == NULL, NULL, "dns.ip is NULL");
+
+       candidate_str = g_string_new(candidate);
+       if (g_string_replace(candidate_str, webrtc->dns.ip, webrtc->dns.hostname, 1) > 0)
+               LOG_INFO("%s", candidate_str->str);
+
+       return g_string_free(candidate_str, FALSE);
 }
 //LCOV_EXCL_STOP
index ac88c2aa0e8d9736208566b775292b89521fedc4..93bbdd64446703d71ac18861ee00f7ed09d78b06 100644 (file)
@@ -1124,6 +1124,7 @@ static void __webrtcbin_on_ice_candidate_cb(GstElement *webrtcbin, guint mlinein
 {
        webrtc_s *webrtc = (webrtc_s *)user_data;
        gchar *_candidate;
+       gchar *candidate_with_hostname = NULL;
        char *_param_candidate;
 
        RET_IF(webrtcbin == NULL, "webrtcbin is NULL");
@@ -1132,7 +1133,9 @@ static void __webrtcbin_on_ice_candidate_cb(GstElement *webrtcbin, guint mlinein
 
        LOG_DEBUG("webrtc[%p] mlineindex[%u] candidate[%s]", webrtc, mlineindex, candidate);
 
-       _candidate = __make_ice_candidate_message(mlineindex, candidate);
+       candidate_with_hostname = _replace_ip_with_hostname(webrtc, (const gchar *)candidate);
+       _candidate = __make_ice_candidate_message(mlineindex, candidate_with_hostname ? candidate_with_hostname : candidate);
+       g_free(candidate_with_hostname);
        if (!_candidate)
                return;