From: Sangchul Lee Date: Thu, 28 Jul 2022 15:43:31 +0000 (+0900) Subject: Apply URL encoding when username of turn server URL has ':' X-Git-Tag: submit/tizen_6.5/20220808.130858~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66e9339261378a7ef2298d63d2c452a4b6251b33;p=platform%2Fcore%2Fapi%2Fwebrtc.git Apply URL encoding when username of turn server URL has ':' The form of URL should be turn(s)://username:password@host:port. If the username has ':', for example '1221435:someidstring', this could not be applied properly inside of webrtcbin. In this case, this patch fixes it with using URL encoding to avoid this situation. [Version] 0.2.179 [Issue Type] Bug fix Change-Id: Icd30fdbea39469526abde8016745fc291bf2d4a5 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc.h b/include/webrtc.h index 2d0ebef2..e5f9695b 100644 --- a/include/webrtc.h +++ b/include/webrtc.h @@ -1341,7 +1341,7 @@ int webrtc_get_stun_server(webrtc_h webrtc, char **stun_server); * @since_tizen 6.5 * @remarks Regarding TURN, refer to the RFC7065(https://tools.ietf.org/html/rfc7065). * @param[in] webrtc WebRTC handle - * @param[in] turn_server The TURN server URL of the form turn(s)://username:password\@host:port + * @param[in] turn_server The TURN server URL of the form turn(s)://username:password@host:port * @return @c 0 on success, * otherwise a negative error value * @retval #WEBRTC_ERROR_NONE Successful diff --git a/include/webrtc_private.h b/include/webrtc_private.h index b3b38623..b094c9de 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -685,6 +685,7 @@ int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description int _webrtcbin_add_ice_candidate(webrtc_s *webrtc, const char *candidate); void _webrtcbin_on_data_channel_cb(GstElement *webrtcbin, GObject *data_channel, gpointer user_data); bool _webrtcbin_have_remote_offer(webrtc_s *webrtc); +gchar *_check_and_encode_turn_url(const char *url); void _init_data_channels(webrtc_s *webrtc); void _destroy_data_channels(webrtc_s *webrtc); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index bb514530..204ee88d 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.2.178 +Version: 0.2.179 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index 4f829ab9..0f692413 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -895,7 +895,8 @@ int webrtc_add_turn_server(webrtc_h webrtc, const char *turn_server) { gboolean ret = FALSE; g_autoptr(GMutexLocker) locker = NULL; - webrtc_s *_webrtc = (webrtc_s*)webrtc; + webrtc_s *_webrtc = (webrtc_s *)webrtc; + gchar *turn_url; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(turn_server == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "turn_server is NULL"); @@ -904,12 +905,18 @@ int webrtc_add_turn_server(webrtc_h webrtc, const char *turn_server) RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE"); - g_signal_emit_by_name(G_OBJECT(_webrtc->gst.webrtcbin), "add-turn-server", turn_server, &ret); - RET_VAL_IF(!ret, WEBRTC_ERROR_INVALID_PARAMETER, "invalid turn server url (%s)", turn_server); + turn_url = _check_and_encode_turn_url(turn_server); + + g_signal_emit_by_name(G_OBJECT(_webrtc->gst.webrtcbin), "add-turn-server", turn_url, &ret); + if (!ret) { + LOG_ERROR("invalid turn server url (%s)", turn_url); + g_free(turn_url); + return WEBRTC_ERROR_INVALID_PARAMETER; + } - _webrtc->turn_server_urls = g_list_append(_webrtc->turn_server_urls, g_strdup(turn_server)); + _webrtc->turn_server_urls = g_list_append(_webrtc->turn_server_urls, turn_url); - LOG_INFO("webrtc[%p] turn_server[%s]", webrtc, turn_server); + LOG_INFO("webrtc[%p] turn_server[%s]", webrtc, turn_url); return WEBRTC_ERROR_NONE; } diff --git a/src/webrtc_private.c b/src/webrtc_private.c index fdf7e757..36455dfd 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -140,8 +140,20 @@ void _generate_dot(GstElement *pipeline, const gchar *name) g_free(dot_name); } +gchar *_check_and_encode_turn_url(const char *url) +{ + g_auto(GStrv) str_arr = g_strsplit(url, "@", 2); + g_auto(GStrv) str_arr2 = g_strsplit(str_arr[0], ":", 0); + + if (g_strv_length(str_arr2) > 3) /* NOTE: assume id has ':' character */ + return g_strdup_printf("%s:%s%s%s:%s@%s", + str_arr2[0], str_arr2[1], "%3A", str_arr2[2], str_arr2[3], str_arr[1]); + + return g_strdup(url); +} + /* Use g_free() to release the return value. */ -static gchar* __get_string_from_json_object(JsonObject *object) +static gchar *__get_string_from_json_object(JsonObject *object) { JsonNode *root; JsonGenerator *generator; @@ -161,7 +173,7 @@ static gchar* __get_string_from_json_object(JsonObject *object) } /* Use g_free() to release the return value. */ -static gchar* __make_sdp_message(GstWebRTCSessionDescription *desc) +static gchar *__make_sdp_message(GstWebRTCSessionDescription *desc) { gchar *text; JsonObject *msg, *sdp;