From: Sangchul Lee Date: Tue, 27 Dec 2022 08:25:30 +0000 (+0900) Subject: webrtc_private: Replace private IP with hostname in local ICE candidate X-Git-Tag: accepted/tizen/7.0/unified/20230111.015131~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=94869ca496b980586897f323a0af28a7d6ea9f01;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_private: Replace private IP with hostname in local ICE candidate [Version] 0.3.278 [Issue type] New feature Change-Id: I351db37c3a1fafec9b63bb10840b145f8eb0fa53 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 08168f3c..08590529 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 3171b93f..45b21b3f 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -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 diff --git a/src/webrtc_dns.c b/src/webrtc_dns.c index fc6aa09a..dc5aefd7 100644 --- a/src/webrtc_dns.c +++ b/src/webrtc_dns.c @@ -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 diff --git a/src/webrtc_private.c b/src/webrtc_private.c index ac88c2aa..93bbdd64 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -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;