Use g_autoptr for JsonParser variable 33/289133/1 accepted/tizen/7.0/unified/20230327.042613
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 2 Mar 2023 02:15:05 +0000 (11:15 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 2 Mar 2023 02:31:37 +0000 (11:31 +0900)
[Version] 0.3.290
[Issue type] Refactoring

Change-Id: Iaf7fac85e87150abdfae106827fb84b7c41d001e

packaging/capi-media-webrtc.spec
src/webrtc_private.c
test/webrtc_test_signaling.c

index 184ed3681f2ad7793d25b6f93872dea59d841229..42094c628cdf9ac9a020654f1a59f1baf559905b 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.289
+Version:    0.3.290
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 1e5457dc98e1fab8a8224f33430f372b82a11f2e..c119dc628a26929085dbd1127b1b6f49f3fdfc0b 100644 (file)
@@ -1922,11 +1922,10 @@ int _webrtcbin_create_session_description_async(webrtc_s *webrtc, bool is_offer,
 /* Use g_free() to release the sdp and type parameter. */
 static int __get_sdp_from_description(const char *description, gchar **sdp, gchar **type)
 {
-       int ret = WEBRTC_ERROR_NONE;
+       g_autoptr(JsonParser) parser = NULL;
        JsonNode *root;
        JsonObject *object;
        JsonObject *child;
-       JsonParser *parser;
        const gchar *member_sdp;
        const gchar *member_type;
 
@@ -1940,22 +1939,19 @@ static int __get_sdp_from_description(const char *description, gchar **sdp, gcha
 
        if (!json_parser_load_from_data(parser, description, -1, NULL)) {
                LOG_ERROR("unknown description: %s", description);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        root = json_parser_get_root(parser);
        if (!JSON_NODE_HOLDS_OBJECT(root)) {
                LOG_ERROR("it does not contain a JsonObject: %s", description);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        object = json_node_get_object(root);
        if (!json_object_has_member(object, "sdp")) {
                LOG_ERROR("it does not contain 'sdp' member: %s", description);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        child = json_object_get_object_member(object, "sdp");
@@ -1963,15 +1959,13 @@ static int __get_sdp_from_description(const char *description, gchar **sdp, gcha
        member_type = json_object_get_string_member(child, "type");
        if (!member_type || !(g_str_equal(member_type, "answer") || g_str_equal(member_type, "offer"))) {
                LOG_ERROR("could not find valid type member: %s", description);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        member_sdp = json_object_get_string_member(child, "sdp");
        if (!member_sdp) {
                LOG_ERROR("could not find sdb member: %s", description);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        *type = g_strdup(member_type);
@@ -1979,9 +1973,8 @@ static int __get_sdp_from_description(const char *description, gchar **sdp, gcha
 
        LOG_DEBUG("type: %s", *type);
        LOG_DEBUG("sdp:\n%s", *sdp);
-end:
-       g_object_unref(parser);
-       return ret;
+
+       return WEBRTC_ERROR_NONE;
 }
 
 int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description, bool is_remote)
@@ -2038,11 +2031,10 @@ end:
 /* Use g_free() to release the candidate parameter. */
 static int __get_ice_candidate_from_message(const char *ice_message, gchar **candidate, gint *mlineindex)
 {
-       int ret = WEBRTC_ERROR_NONE;
+       g_autoptr(JsonParser) parser = NULL;
        JsonNode *root;
        JsonObject *object;
        JsonObject *child;
-       JsonParser *parser;
        const gchar *_candidate;
 
        RET_VAL_IF(ice_message == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "ice_message is NULL");
@@ -2055,22 +2047,19 @@ static int __get_ice_candidate_from_message(const char *ice_message, gchar **can
 
        if (!json_parser_load_from_data(parser, ice_message, -1, NULL)) {
                LOG_ERROR("unknown message: %s", ice_message);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        root = json_parser_get_root(parser);
        if (!JSON_NODE_HOLDS_OBJECT(root)) {
                LOG_ERROR("it does not contain a JsonObject: %s", ice_message);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        object = json_node_get_object(root);
        if (!json_object_has_member(object, "ice")) {
                LOG_ERROR("It does not contain 'ice' member: %s", ice_message);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        child = json_object_get_object_member(object, "ice");
@@ -2078,8 +2067,7 @@ static int __get_ice_candidate_from_message(const char *ice_message, gchar **can
        _candidate = json_object_get_string_member(child, "candidate");
        if (!_candidate) {
                LOG_ERROR("Could not find candidate member: %s", ice_message);
-               ret = WEBRTC_ERROR_INVALID_PARAMETER;
-               goto end;
+               return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
        *candidate = g_strdup(_candidate);
@@ -2091,9 +2079,8 @@ static int __get_ice_candidate_from_message(const char *ice_message, gchar **can
 
        LOG_DEBUG("candidate: %s", *candidate);
        LOG_DEBUG("sdpMLineIndex: %d", *mlineindex);
-end:
-       g_object_unref(parser);
-       return ret;
+
+       return WEBRTC_ERROR_NONE;
 }
 
 int _webrtcbin_add_ice_candidate(webrtc_s *webrtc, const char *candidate)
index 7cae3a8bcddb70bab41eb59d9171bcf339e13f5a..eddaf3265317cf9851e65c2c6719aa047744559e 100644 (file)
@@ -212,9 +212,9 @@ static void __auto_configure_release_peer(gchar *peer_id)
 
 static void __handle_json_structured_message(connection_s *conn, const gchar *text)
 {
+       g_autoptr(JsonParser) parser = NULL;
        JsonNode *root;
        JsonObject *object;
-       JsonParser *parser;
 
        RET_IF(!conn, "conn is NULL");
        RET_IF(!text, "text is NULL");
@@ -223,14 +223,12 @@ static void __handle_json_structured_message(connection_s *conn, const gchar *te
 
        if (!json_parser_load_from_data(parser, text, -1, NULL)) {
                g_printerr("unknown message [%s]\n", text);
-               g_object_unref(parser);
                return;
        }
 
        root = json_parser_get_root(parser);
        if (!JSON_NODE_HOLDS_OBJECT(root)) {
                g_printerr("unknown JSON message [%s]\n", text);
-               g_object_unref(parser);
                return;
        }
 
@@ -264,8 +262,6 @@ static void __handle_json_structured_message(connection_s *conn, const gchar *te
        } else {
                g_printerr("neither 'sdp' nor 'ice' member exist in JSON message [%s]\n", text);
        }
-
-       g_object_unref(parser);
 }
 
 static void __auto_configure_handle_room_message(gchar *peer_id, gchar *message)