From: hj kim Date: Wed, 5 Jun 2019 02:47:10 +0000 (+0900) Subject: Add APIs to check parameter range X-Git-Tag: submit/tizen/20190605.070245~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=87b2c1a3712a687a593d562974577506d26bb78d;p=platform%2Fcore%2Fapi%2Fmedia-controller.git Add APIs to check parameter range Change-Id: I6c1abd56f738bf35b5209574bee3548063107472 --- diff --git a/include/media_controller_private.h b/include/media_controller_private.h index 30015af..3c48602 100644 --- a/include/media_controller_private.h +++ b/include/media_controller_private.h @@ -398,6 +398,8 @@ int mc_util_set_command_available(mc_priv_type_e priv_type, const char *name, co int mc_util_get_command_available(mc_priv_type_e priv_type, const char *name, const char *command_type, const char *command); char *mc_util_generate_uuid(void); int mc_util_bundle_to_string(bundle *bundle_data, char **str_data); +gboolean _mc_util_is_valid_playback_action(mc_playback_action_e action); +gboolean _mc_util_is_valid_subscription_type(const mc_subscription_type_e subscription_type); /* for d-bus IPC */ int mc_ipc_get_dbus_connection(GDBusConnection **conn, int *dref_count); diff --git a/src/media_controller_client.c b/src/media_controller_client.c index cfb7c6f..980dae1 100644 --- a/src/media_controller_client.c +++ b/src/media_controller_client.c @@ -741,7 +741,7 @@ int mc_client_subscribe(mc_client_h client, const mc_subscription_type_e subscri mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); mc_retvm_if(!MC_STRING_VALID(server_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid server_name"); - mc_retvm_if(((subscription_type < MC_SUBSCRIPTION_TYPE_SERVER_STATE) || (subscription_type > MC_SUBSCRIPTION_TYPE_REPEAT_ABILITY)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type [%d]", subscription_type); + mc_retvm_if(!_mc_util_is_valid_subscription_type(subscription_type) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type"); mc_retvm_if(mc_client->updated_cb[subscription_type].callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback"); ret = mc_ipc_unregister_listener(&mc_client->listeners, MC_DBUS_UPDATE_INTERFACE, cb_event[subscription_type].signal_name); @@ -764,7 +764,7 @@ int mc_client_unsubscribe(mc_client_h client, const mc_subscription_type_e subsc mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); mc_retvm_if(!MC_STRING_VALID(server_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid server_name"); - mc_retvm_if(((subscription_type < MC_SUBSCRIPTION_TYPE_SERVER_STATE) || (subscription_type > MC_SUBSCRIPTION_TYPE_REPEAT_ABILITY)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type [%d]", subscription_type); + mc_retvm_if(!_mc_util_is_valid_subscription_type(subscription_type) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type"); mc_retvm_if(mc_client->updated_cb[subscription_type].callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid callback. No list to unsubscribe [%d]", subscription_type); mc_retvm_if(mc_client->updated_cb[subscription_type].filter_list == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid filter_list. No list to unsubscribe [%d]", subscription_type); @@ -785,7 +785,7 @@ int mc_client_foreach_server_subscribed(mc_client_h client, const mc_subscriptio mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); mc_retvm_if(callback == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "callback is NULL"); - mc_retvm_if(((subscription_type < MC_SUBSCRIPTION_TYPE_SERVER_STATE) || (subscription_type > MC_SUBSCRIPTION_TYPE_REPEAT_ABILITY)) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type [%d]", subscription_type); + mc_retvm_if(!_mc_util_is_valid_subscription_type(subscription_type) , MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid subscription_type"); filter_list = mc_client->updated_cb[subscription_type].filter_list; mc_retvm_if(filter_list == NULL, MEDIA_CONTROLLER_ERROR_NONE, "No filter list for the subscription_type [%d]", subscription_type); @@ -1036,7 +1036,7 @@ int mc_client_send_playback_action_cmd(mc_client_h client, const char *server_na mc_retvm_if(mc_client == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL"); mc_retvm_if(!MC_STRING_VALID(server_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid server_name"); - mc_retvm_if(((action < MC_PLAYBACK_ACTION_PLAY) || (action > MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid action"); + mc_retvm_if(!_mc_util_is_valid_playback_action(action), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid action"); message = g_strdup_printf("%s%s%d", mc_client->client_name, MC_STRING_DELIMITER, action); mc_retvm_if(message == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail making message [%d]", ret); @@ -1117,7 +1117,7 @@ int mc_client_send_playlist_cmd(mc_client_h client, const char *server_name, con mc_retvm_if(!MC_STRING_VALID(server_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid server_name"); mc_retvm_if(!MC_STRING_VALID(playlist_name), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid playlist_name"); mc_retvm_if(!MC_STRING_VALID(index), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid index"); - mc_retvm_if(((action < MC_PLAYBACK_ACTION_PLAY) || (action > MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid action"); + mc_retvm_if(!_mc_util_is_valid_playback_action(action), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid action"); message = g_strdup_printf("%s%s%s%s%s%s%d%s%llu", mc_client->client_name, MC_STRING_DELIMITER, playlist_name, MC_STRING_DELIMITER, index, MC_STRING_DELIMITER, action, MC_STRING_DELIMITER, position); mc_retvm_if(message == NULL, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "fail making message [%d]", ret); diff --git a/src/media_controller_metadata.c b/src/media_controller_metadata.c index 5b046d2..474ec3e 100755 --- a/src/media_controller_metadata.c +++ b/src/media_controller_metadata.c @@ -286,7 +286,7 @@ int mc_playback_action_is_supported(mc_playback_ability_h ability, mc_playback_a media_controller_ability_s *mc_ability = (media_controller_ability_s *)ability; mc_retvm_if(mc_ability == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "ability is NULL"); - mc_retvm_if(((action < MC_PLAYBACK_ACTION_PLAY) || (action > MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "action is invalid"); + mc_retvm_if(!_mc_util_is_valid_playback_action(action), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid action"); mc_retvm_if(supported == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "supported is NULL"); mc_secure_debug("IsDecided: %d", MC_BIT64_IS_TRUE(mc_ability->decided, (PLAYBACK_ACTION_ABILITY + action))); diff --git a/src/media_controller_server.c b/src/media_controller_server.c index bd71939..f1b3a38 100644 --- a/src/media_controller_server.c +++ b/src/media_controller_server.c @@ -1129,7 +1129,7 @@ static int __mc_server_update_ability(mc_server_h server, int support_item, mc_a int mc_server_set_playback_ability(mc_server_h server, mc_playback_action_e action, mc_ability_support_e support) { - mc_retvm_if(((action < MC_PLAYBACK_ACTION_PLAY) || (action > MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "action is invalid [%d]", action); + mc_retvm_if(!_mc_util_is_valid_playback_action(action), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid action"); return __mc_server_update_ability(server, PLAYBACK_ACTION_ABILITY + action, support, FALSE); } diff --git a/src/media_controller_util.c b/src/media_controller_util.c index fe4fc43..a440397 100644 --- a/src/media_controller_util.c +++ b/src/media_controller_util.c @@ -220,3 +220,23 @@ int mc_util_bundle_to_string(bundle *bundle_data, char **str_data) return ret; } + +gboolean _mc_util_is_valid_playback_action(mc_playback_action_e action) +{ + if ((action < MC_PLAYBACK_ACTION_PLAY) || (action > MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE)) { + mc_error("Invalid action [%d]", action); + return FALSE; + } + + return TRUE; +} + +gboolean _mc_util_is_valid_subscription_type(const mc_subscription_type_e subscription_type) +{ + if ((subscription_type < MC_SUBSCRIPTION_TYPE_SERVER_STATE) || (subscription_type > MC_SUBSCRIPTION_TYPE_REPEAT_ABILITY)) { + mc_error("Invalid subscription_type [%d]", subscription_type); + return FALSE; + } + + return TRUE; +}