Apply URL encoding when username of turn server URL has ':' 79/278979/4
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 28 Jul 2022 15:43:31 +0000 (00:43 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 29 Jul 2022 12:56:43 +0000 (21:56 +0900)
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.3.181
[Issue Type] Bug fix

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

index e7a46f823e4d9acdd0fa5bc4617722dba198b88c..26bd6f6b5430ca04aba27f1ab785decfb30036ff 100644 (file)
@@ -1818,7 +1818,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
index 2cac2da41d0b4858c2843041b860e9b665a10332..ee1f645793d0124b3a4b44f7039e89946079da87 100644 (file)
@@ -813,6 +813,7 @@ webrtc_gst_slot_s* _get_slot_by_id(GHashTable *slots, unsigned int id);
 int _add_no_target_ghostpad_to_slot(webrtc_gst_slot_s *slot, bool is_src, GstPad **new_pad);
 int _set_ghost_pad_target(GstPad *ghost_pad, GstElement *target_element, bool is_src);
 void _generate_dot(GstElement *pipeline, const gchar *name);
+gchar *_check_and_encode_turn_url(const char *url);
 
 #ifdef __cplusplus
 }
index 6a72dfa6576809ef056589a0ebac02908ea937ee..f4b42daea4561d7d817bf89eae53abdf2404e408 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.180
+Version:    0.3.181
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index a1ad751761c2a6ceabe7dcdd8c34f46861ee6364..768dda6d233c47e7a4993cac0ec5501c274b2d34 100644 (file)
@@ -940,6 +940,7 @@ 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;
+       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");
@@ -948,12 +949,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);
 
-       _webrtc->turn_server_urls = g_list_append(_webrtc->turn_server_urls, g_strdup(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, 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;
 }
index 426eb875078d10b76a23feb45fb63b6ad7213677..cbbf2dcb34d8df741e37b296fa0a5ed4a1cb6d5c 100644 (file)
@@ -141,8 +141,20 @@ void _generate_dot(GstElement *pipeline, const gchar *name)
 }
 //LCOV_EXCL_STOP
 
+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;
@@ -162,7 +174,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;