From: Sangchul Lee Date: Thu, 2 Mar 2023 02:15:05 +0000 (+0900) Subject: Use g_autoptr for JsonParser variable X-Git-Tag: accepted/tizen/unified/20230303.040337^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c1de2f4fa309b3489221d1f514fec7440d6febbb;p=platform%2Fcore%2Fapi%2Fwebrtc.git Use g_autoptr for JsonParser variable [Version] 0.3.289 [Issue type] Refactoring Change-Id: Iaf7fac85e87150abdfae106827fb84b7c41d001e --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 1afdff7f..184ed368 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.288 +Version: 0.3.289 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 1e5457dc..c119dc62 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -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) diff --git a/test/webrtc_test_signaling.c b/test/webrtc_test_signaling.c index 7cae3a8b..eddaf326 100644 --- a/test/webrtc_test_signaling.c +++ b/test/webrtc_test_signaling.c @@ -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)