From: hyunuktak Date: Wed, 2 May 2018 08:02:48 +0000 (+0900) Subject: Replaced some APIs X-Git-Tag: submit/tizen/20180503.122906~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afe86592ab4baf4ce30376bbbe84bc762e2c8e6a;p=platform%2Fcore%2Fapi%2Fsmart-traffic-control.git Replaced some APIs Combine rule with info for restriction Add get/set API for restriction type Remove exclude restriction API Change-Id: I79c91a0128008d8c2ad3b20a70d745f1afae684b Signed-off-by: hyunuktak --- diff --git a/include/stc_internal.h b/include/stc_internal.h index 8ac3a9f..eadc119 100755 --- a/include/stc_internal.h +++ b/include/stc_internal.h @@ -87,12 +87,6 @@ typedef void *stc_firewall_rule_h; */ typedef void *stc_restriction_rule_h; -/** - * @brief The restriction information handle. - * @since_tizen 4.0 - */ -typedef void *stc_restriction_info_h; - /** * @} */ @@ -221,32 +215,32 @@ typedef enum { */ /** - * @brief Called for enumerate restriction information. - * @since_tizen 4.0 + * @brief Called for enumerate restriction rule. + * @since_tizen 5.0 * * @param[in] result The result - * @param[in] info The restriction information handle + * @param[in] rule The restriction rule handle * @param[in] user_data The user data passed from the callback registration function * @return @c STC_CALLBACK_CONTINUE to continue with the next iteration of the loop, * otherwise @c STC_CALLBACK_CANCEL to break out of the loop * * @pre stc_get_restriction() will invoke this callback. * @pre stc_foreach_restriction() will invoke this callback. - * @see stc_restriction_info_get_app_id() - * @see stc_restriction_info_get_iface_name() - * @see stc_restriction_info_get_subscriber_id() - * @see stc_restriction_info_get_type() - * @see stc_restriction_info_get_iface_type() - * @see stc_restriction_info_get_limit() - * @see stc_restriction_info_get_warning_limit() - * @see stc_restriction_info_get_roaming_type() + * @see stc_restriction_rule_get_app_id() + * @see stc_restriction_rule_get_iface_name() + * @see stc_restriction_rule_get_subscriber_id() + * @see stc_restriction_rule_get_type() + * @see stc_restriction_rule_get_iface_type() + * @see stc_restriction_rule_get_limit() + * @see stc_restriction_rule_get_warning_limit() + * @see stc_restriction_rule_get_roaming_type() * @see stc_get_restriction() * @see stc_foreach_restriction() */ -typedef stc_callback_ret_e (*stc_restriction_info_cb)(stc_error_e result, - stc_restriction_info_h info, void *user_data); +typedef stc_callback_ret_e (*stc_restriction_rule_cb)(stc_error_e result, + stc_restriction_rule_h rule, void *user_data); -typedef void (*stc_threshold_crossed_cb)(stc_restriction_info_h info, +typedef void (*stc_threshold_crossed_cb)(stc_restriction_rule_h rule, void *user_data); /** @@ -319,7 +313,7 @@ typedef stc_callback_ret_e (*stc_firewall_rule_info_cb)(stc_firewall_rule_h info */ /** - * @brief Resets stats information.. + * @brief Resets stats information. * @since_tizen 4.0 * @privlevel platform * @privilege %http://tizen.org/privilege/network.get @@ -398,58 +392,9 @@ int stc_reset_stats(stc_h stc, stc_reset_rule_h rule); * @see stc_foreach_restriction() * @see stc_get_restriction_type() * @see stc_unset_restriction() - * @see stc_exclude_restriction() */ int stc_set_restriction(stc_h stc, stc_restriction_rule_h rule); -/** - * @brief Excludes the application from network restriction. - * @details Excluded application will be granted to - * internet access, in case of whole network restriction. - * @since_tizen 4.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] stc The stc handle - * @param[in] rule The restriction rule handle - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_h - * @see #stc_restriction_rule_h - * @see stc_initialize() - * @see stc_restriction_rule_create() - * @see stc_restriction_rule_destroy() - * @see stc_restriction_rule_set_app_id() - * @see stc_restriction_rule_set_iface_name() - * @see stc_restriction_rule_set_iface_type() - * @see stc_restriction_rule_set_limit() - * @see stc_restriction_rule_set_warning_limit() - * @see stc_restriction_rule_set_roaming_type() - * @see stc_restriction_rule_set_subscriber_id() - * @see stc_restriction_rule_get_app_id() - * @see stc_restriction_rule_get_iface_type() - * @see stc_restriction_rule_get_limit() - * @see stc_restriction_rule_get_warning_limit() - * @see stc_restriction_rule_get_roaming_type() - * @see stc_restriction_rule_get_subscriber_id() - * @see stc_restriction_rule_get_process_state() - * @see stc_set_restriction() - * @see stc_get_restriction() - * @see stc_foreach_restriction() - * @see stc_get_restriction_type() - * @see stc_unset_restriction() - */ -int stc_exclude_restriction(stc_h stc, stc_restriction_rule_h rule); - /** * @brief Unsets the existing restriction for application. * @details Unsets the existing restriction for application. @@ -494,12 +439,11 @@ int stc_exclude_restriction(stc_h stc, stc_restriction_rule_h rule); * @see stc_get_restriction() * @see stc_foreach_restriction() * @see stc_get_restriction_type() - * @see stc_exclude_restriction() */ int stc_unset_restriction(stc_h stc, stc_restriction_rule_h rule); /** - * @brief Gets the restriction information per application. + * @brief Gets the restriction rule per application. * @details The callback is called for each application that applied restriction. * @since_tizen 4.0 * @privlevel platform @@ -507,7 +451,7 @@ int stc_unset_restriction(stc_h stc, stc_restriction_rule_h rule); * * @param[in] stc The stc handle * @param[in] rule The restriction rule handle - * @param[in] info_cb The callback is called for each application + * @param[in] rule_cb The callback is called for each application * that applied restriction in interface specified * @param[in] user_data User data will be passed to the callback function * @@ -540,15 +484,14 @@ int stc_unset_restriction(stc_h stc, stc_restriction_rule_h rule); * @see stc_restriction_rule_get_roaming_type() * @see stc_restriction_rule_get_subscriber_id() * @see stc_restriction_rule_get_process_state() - * @see stc_restriction_info_cb() + * @see stc_restriction_rule_cb() * @see stc_set_restriction() * @see stc_foreach_restriction() * @see stc_get_restriction_type() * @see stc_unset_restriction() - * @see stc_exclude_restriction() */ int stc_get_restriction(stc_h stc, stc_restriction_rule_h rule, - stc_restriction_info_cb info_cb, void *user_data); + stc_restriction_rule_cb rule_cb, void *user_data); int stc_set_restriction_threshold_crossed_cb(stc_h stc, stc_threshold_crossed_cb crossed_cb, void *user_data); @@ -561,7 +504,7 @@ int stc_set_warn_threshold_crossed_cb(stc_h stc, int stc_unset_warn_threshold_crossed_cb(stc_h stc); /** - * @brief Gets the restriction information of all application. + * @brief Gets the restriction rule of all application. * @details The callback is called for each application that applied restriction. * @since_tizen 4.0 * @privlevel platform @@ -569,7 +512,7 @@ int stc_unset_warn_threshold_crossed_cb(stc_h stc); * * @param[in] stc The stc handle * @param[in] rule The restriction rule handle - * @param[in] info_cb The callback is called for each application + * @param[in] rule_cb The callback is called for each application * that applied restriction in interface specified * @param[in] user_data User data will be passed to the callback function * @@ -602,18 +545,17 @@ int stc_unset_warn_threshold_crossed_cb(stc_h stc); * @see stc_restriction_rule_get_roaming_type() * @see stc_restriction_rule_get_subscriber_id() * @see stc_restriction_rule_get_process_state() - * @see stc_restriction_info_cb() + * @see stc_restriction_rule_cb() * @see stc_set_restriction() * @see stc_get_restriction() * @see stc_get_restriction_type() * @see stc_unset_restriction() - * @see stc_exclude_restriction() */ int stc_foreach_restriction(stc_h stc, stc_restriction_rule_h rule, - stc_restriction_info_cb info_cb, void *user_data); + stc_restriction_rule_cb rule_cb, void *user_data); /** - * @brief Gets the restriction type information. + * @brief Gets the restriction type. * @since_tizen 4.0 * @privlevel platform * @privilege %http://tizen.org/privilege/network.get @@ -656,7 +598,6 @@ int stc_foreach_restriction(stc_h stc, stc_restriction_rule_h rule, * @see stc_get_restriction() * @see stc_foreach_restriction() * @see stc_unset_restriction() - * @see stc_exclude_restriction() */ int stc_get_restriction_type(stc_h stc, stc_restriction_rule_h rule, stc_restriction_type_e *type); @@ -1078,6 +1019,34 @@ int stc_restriction_rule_set_iface_name( stc_restriction_rule_h rule, int stc_restriction_rule_set_iface_type(stc_restriction_rule_h rule, stc_iface_type_e iface_type); +/** + * @brief Sets the type for restriction rule. + * @since_tizen 5.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/network.get + * + * @param[in] rule The restriction rule handle + * @param[in] type The restriction type + * + * @return 0 on success, otherwise a negative error value + * @retval #STC_ERROR_NONE Successful + * @retval #STC_ERROR_OPERATION_FAILED General error + * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STC_ERROR_INVALID_OPERATION Invalid operation + * @retval #STC_ERROR_NOT_INITIALIZED Not initialized + * @retval #STC_ERROR_NOT_SUPPORTED Not supported + * @retval #STC_ERROR_PERMISSION_DENIED Permission denied + * + * @see #stc_restriction_rule_h + * @see #stc_restriction_type_e + * @see stc_restriction_rule_create() + * @see stc_restriction_rule_destroy() + * @see stc_restriction_rule_get_type() + */ +int stc_restriction_rule_set_type(stc_restriction_rule_h rule, + stc_restriction_type_e type); + /** * @brief Sets the limit for restriction rule. * @since_tizen 4.0 @@ -1268,6 +1237,34 @@ int stc_restriction_rule_get_iface_name(stc_restriction_rule_h rule, int stc_restriction_rule_get_iface_type(stc_restriction_rule_h rule, stc_iface_type_e *iface_type); +/** + * @brief Gets the type for restriction rule. + * @since_tizen 5.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/network.get + * + * @param[in] rule The restriction rule handle + * @param[out] type The restriction type + * + * @return 0 on success, otherwise a negative error value + * @retval #STC_ERROR_NONE Successful + * @retval #STC_ERROR_OPERATION_FAILED General error + * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STC_ERROR_INVALID_OPERATION Invalid operation + * @retval #STC_ERROR_NOT_INITIALIZED Not initialized + * @retval #STC_ERROR_NOT_SUPPORTED Not supported + * @retval #STC_ERROR_PERMISSION_DENIED Permission denied + * + * @see #stc_restriction_rule_h + * @see #stc_restriction_type_e + * @see stc_restriction_rule_create() + * @see stc_restriction_rule_destroy() + * @see stc_restriction_rule_set_type() + */ +int stc_restriction_rule_get_type(stc_restriction_rule_h rule, + stc_restriction_type_e *type); + /** * @brief Gets the limit for restriction rule. * @since_tizen 4.0 @@ -1399,208 +1396,6 @@ int stc_restriction_rule_get_subscriber_id(stc_restriction_rule_h rule, char **s */ int stc_stats_info_get_subscriber_id(stc_stats_info_h info, char **subscriber_id); -/** - * @brief Gets the application ID for restriction information. - * @since_tizen 4.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] info The restriction information handle - * @param[out] app_id The application ID - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_restriction_info_h - * @see stc_restriction_info_cb() - */ -int stc_restriction_info_get_app_id(stc_restriction_info_h info, char **app_id); - -/** - * @brief Gets the interface name for restriction information. - * @since_tizen 4.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] info The restriction information handle - * @param[out] iface_name The interface name - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_restriction_info_h - * @see stc_restriction_info_cb() - */ -int stc_restriction_info_get_iface_name(stc_restriction_info_h info, - char **iface_name); - -/** - * @brief Gets the subscriber ID for restriction information. - * @since_tizen 4.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] info The restriction information handle - * @param[out] subscriber_id The subscriber ID - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_restriction_info_h - * @see stc_restriction_info_cb() - */ -int stc_restriction_info_get_subscriber_id(stc_restriction_info_h info, char **subscriber_id); - -/** - * @brief Gets the restriction type for restriction information. - * @since_tizen 5.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] info The restriction information handle - * @param[out] type The restriction type - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_restriction_info_h - * @see #stc_restriction_type_e - * @see stc_restriction_info_cb() - */ -int stc_restriction_info_get_type(stc_restriction_info_h info, - stc_restriction_type_e *type); - - -/** - * @brief Gets the interface type for restriction information. - * @since_tizen 4.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] info The restriction information handle - * @param[out] iface_type The interface type - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_restriction_info_h - * @see #stc_iface_type_e - * @see stc_restriction_info_cb() - */ -int stc_restriction_info_get_iface_type(stc_restriction_info_h info, - stc_iface_type_e *iface_type); - -/** - * @brief Gets the limit for restriction information. - * @since_tizen 4.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] info The restriction information handle - * @param[out] data_limit The data limit - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_restriction_info_h - * @see stc_restriction_info_cb() - */ -int stc_restriction_info_get_limit(stc_restriction_info_h info, - int64_t *data_limit); - -/** - * @brief Gets the warning limit for restriction information. - * @since_tizen 4.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] info The restriction information handle - * @param[out] data_warn_limit The data warning limit - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_restriction_info_h - * @see stc_restriction_info_cb() - */ -int stc_restriction_info_get_warning_limit(stc_restriction_info_h info, - int64_t *data_warn_limit); - -/** - * @brief Gets the roaming type for restriction information. - * @since_tizen 4.0 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] info The restriction information handle - * @param[out] roaming The roaming type - * - * @return 0 on success, otherwise a negative error value - * @retval #STC_ERROR_NONE Successful - * @retval #STC_ERROR_OPERATION_FAILED General error - * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory - * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #STC_ERROR_INVALID_OPERATION Invalid operation - * @retval #STC_ERROR_NOT_INITIALIZED Not initialized - * @retval #STC_ERROR_NOT_SUPPORTED Not supported - * @retval #STC_ERROR_PERMISSION_DENIED Permission denied - * - * @see #stc_restriction_info_h - * @see #stc_roaming_type_e - * @see stc_restriction_info_cb() - */ -int stc_restriction_info_get_roaming_type(stc_restriction_info_h info, - stc_roaming_type_e *roaming_type); - /** * @} */ diff --git a/packaging/capi-network-stc.spec b/packaging/capi-network-stc.spec index a5db18a..68ff603 100755 --- a/packaging/capi-network-stc.spec +++ b/packaging/capi-network-stc.spec @@ -1,6 +1,6 @@ Name: capi-network-stc Summary: A Smart Traffic Control (STC) libraries in Native API -Version: 0.0.26 +Version: 0.0.27 Release: 1 Group: Network & Connectivity/API License: Apache-2.0 diff --git a/src/include/stc-info.h b/src/include/stc-info.h index 54cbc5c..846e566 100755 --- a/src/include/stc-info.h +++ b/src/include/stc-info.h @@ -63,15 +63,6 @@ extern "C" { #define STC_STATS_INFO_PROTOCOL_TYPE "hw_net_protocol_type" #define STC_STATS_INFO_PROCESS_STATE "ground" -#define STC_RESTRICTION_INFO_APP_ID "app_id" -#define STC_RESTRICTION_INFO_IFTYPE "iftype" -#define STC_RESTRICTION_INFO_IFNAME "ifname" -#define STC_RESTRICTION_INFO_DATA_LIMIT "data_limit" -#define STC_RESTRICTION_INFO_DATA_WARN_LIMIT "data_warn_limit" -#define STC_RESTRICTION_INFO_RSTN_TYPE "type" -#define STC_RESTRICTION_INFO_ROAMING "roaming" -#define STC_RESTRICTION_INFO_SUBSCRIBER_ID "subscriber_id" - typedef struct { int64_t incoming_bytes; /** next) { - stc_restriction_info_h info = data->data; + stc_restriction_rule_h rule = data->data; ret = handle->restriction_cb(err, - info, handle->restriction_user_data); + rule, handle->restriction_user_data); if (ret == STC_CALLBACK_CANCEL) break; @@ -481,9 +481,9 @@ static void __stc_callback_foreach(stc_event_e e, if (err == STC_ERROR_NONE) { if (info_data != NULL) { for (data = info_data; data; data = data->next) { - stc_restriction_info_h info = data->data; + stc_restriction_rule_h rule = data->data; ret = handle->restriction_all_cb(err, - info, handle->restriction_all_user_data); + rule, handle->restriction_all_user_data); if (ret == STC_CALLBACK_CANCEL) break; @@ -516,12 +516,12 @@ static void __stc_signal_callback(stc_event_e e, void *info_data) switch (e) { case STC_EVENT_WARN_THRESHOLD_CROSSED_RSP: if (handle->warn_crossed_cb) - handle->warn_crossed_cb((stc_restriction_info_h)info_data, + handle->warn_crossed_cb((stc_restriction_rule_h)info_data, handle->warn_crossed_user_data); break; case STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP: if (handle->restriction_crossed_cb) - handle->restriction_crossed_cb((stc_restriction_info_h)info_data, + handle->restriction_crossed_cb((stc_restriction_rule_h)info_data, handle->restriction_crossed_user_data); break; default: @@ -661,8 +661,8 @@ void _stc_callback_set_stats_total_info(stc_h stc, } //LCOV_EXCL_START -void _stc_callback_set_restriction_info(stc_h stc, - stc_restriction_info_cb user_cb, void *user_data) +void _stc_callback_set_restriction_rule(stc_h stc, + stc_restriction_rule_cb user_cb, void *user_data) { stc_handle_s *handle = (stc_handle_s *)stc; @@ -670,8 +670,8 @@ void _stc_callback_set_restriction_info(stc_h stc, handle->restriction_user_data = user_data; } -void _stc_callback_set_restriction_all_info(stc_h stc, - stc_restriction_info_cb user_cb, void *user_data) +void _stc_callback_set_restriction_all_rule(stc_h stc, + stc_restriction_rule_cb user_cb, void *user_data) { stc_handle_s *handle = (stc_handle_s *)stc; diff --git a/src/internal/stc-signal.c b/src/internal/stc-signal.c index c1c34ae..480f89b 100755 --- a/src/internal/stc-signal.c +++ b/src/internal/stc-signal.c @@ -46,6 +46,7 @@ #include "stc-util.h" #include "stc-event.h" #include "stc-info.h" +#include "stc-restriction.h" #include "stc-signal.h" @@ -77,17 +78,17 @@ static void __stc_handle_warn_threshold_crossed(GVariant *param) const char *app_id = NULL; stc_iface_type_e iftype = STC_IFACE_UNKNOWN; stc_event_info_s event_data = { 0, }; - stc_restriction_info_s *info = NULL; + stc_restriction_rule_s *rule = NULL; g_variant_get(param, "(&si)", &app_id, iftype); - info = g_try_malloc0(sizeof(stc_restriction_info_s)); - if (info != NULL) { - g_strlcpy(info->app_id, app_id, STC_APP_ID_LEN); - info->iface_type = iftype; + rule = g_try_malloc0(sizeof(stc_restriction_rule_s)); + if (rule != NULL) { + g_strlcpy(rule->app_id, app_id, STC_APP_ID_LEN); + rule->iface_type = iftype; event_data.event = STC_EVENT_WARN_THRESHOLD_CROSSED_RSP; - event_data.info_data = (stc_restriction_info_h)info; + event_data.info_data = (stc_restriction_rule_h)rule; _stc_event_add_client_idle_cb(&event_data, NULL); } @@ -98,17 +99,17 @@ static void __stc_handle_restriction_threshold_crossed(GVariant *param) const char *app_id = NULL; stc_iface_type_e iftype = STC_IFACE_UNKNOWN; stc_event_info_s event_data = { 0, }; - stc_restriction_info_s *info = NULL; + stc_restriction_rule_s *rule = NULL; g_variant_get(param, "(&si)", &app_id, iftype); - info = g_try_malloc0(sizeof(stc_restriction_info_s)); - if (info != NULL) { - g_strlcpy(info->app_id, app_id, STC_APP_ID_LEN); - info->iface_type = iftype; + rule = g_try_malloc0(sizeof(stc_restriction_rule_s)); + if (rule != NULL) { + g_strlcpy(rule->app_id, app_id, STC_APP_ID_LEN); + rule->iface_type = iftype; event_data.event = STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP; - event_data.info_data = (stc_restriction_info_h)info; + event_data.info_data = (stc_restriction_rule_h)rule; _stc_event_add_client_idle_cb(&event_data, NULL); } diff --git a/src/stc-info.c b/src/stc-info.c index 26c5bda..73285f3 100755 --- a/src/stc-info.c +++ b/src/stc-info.c @@ -254,173 +254,3 @@ EXPORT_API int stc_stats_info_get_process_state(stc_stats_info_h info, return STC_ERROR_NONE; } - -//LCOV_EXCL_START -EXPORT_API int stc_restriction_info_get_app_id(stc_restriction_info_h info, char **app_id) -{ - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (info == NULL || app_id == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)info; - - *app_id = g_strdup(restriction_info->app_id); - if (*app_id == NULL) - return STC_ERROR_OUT_OF_MEMORY; - - STC_LOGI("App id [%s]", *app_id); - - return STC_ERROR_NONE; -} - -EXPORT_API int stc_restriction_info_get_iface_name(stc_restriction_info_h info, - char **iface_name) -{ - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (info == NULL || iface_name == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)info; - - *iface_name = g_strdup(restriction_info->iface_name); - if (*iface_name == NULL) - return STC_ERROR_OUT_OF_MEMORY; - - STC_LOGI("Ifname [%s]", *iface_name); - - return STC_ERROR_NONE; -} - -EXPORT_API int stc_restriction_info_get_subscriber_id(stc_restriction_info_h info, - char **subscriber_id) -{ - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (info == NULL || subscriber_id == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)info; - - *subscriber_id = g_strdup(restriction_info->subscriber_id); - if (*subscriber_id == NULL) - return STC_ERROR_OUT_OF_MEMORY; - - STC_LOGI("Subscriber ID [%s]", *subscriber_id); - - return STC_ERROR_NONE; -} - -EXPORT_API int stc_restriction_info_get_type(stc_restriction_info_h info, - stc_restriction_type_e *type) -{ - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (info == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)info; - - *type = restriction_info->rstn_type; - - STC_LOGI("Type [%s]", - _stc_convert_rstn_type_to_string(*type)); - - return STC_ERROR_NONE; -} - -EXPORT_API int stc_restriction_info_get_iface_type(stc_restriction_info_h info, - stc_iface_type_e *iface_type) -{ - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (info == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)info; - - *iface_type = restriction_info->iface_type; - - STC_LOGI("Iftype [%s]", - _stc_convert_iface_type_to_string(*iface_type)); - - return STC_ERROR_NONE; -} - -EXPORT_API int stc_restriction_info_get_limit(stc_restriction_info_h info, - int64_t *data_limit) -{ - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (info == NULL || data_limit == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)info; - - *data_limit = restriction_info->data_limit; - - STC_LOGI("Data limit [%lld] bytes", *data_limit); - - return STC_ERROR_NONE; -} - -EXPORT_API int stc_restriction_info_get_warning_limit(stc_restriction_info_h info, - int64_t *data_warn_limit) -{ - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (info == NULL || data_warn_limit == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)info; - - *data_warn_limit = restriction_info->data_warn_limit; - - STC_LOGI("Data warn limit [%lld] bytes", *data_warn_limit); - - return STC_ERROR_NONE; -} - -EXPORT_API int stc_restriction_info_get_roaming_type(stc_restriction_info_h info, - stc_roaming_type_e *roaming_type) -{ - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (info == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)info; - - *roaming_type = restriction_info->roaming_type; - - STC_LOGI("Roaming type [%s]", - _stc_convert_roaming_to_string(*roaming_type)); - - return STC_ERROR_NONE; -} -//LCOV_EXCL_STOP diff --git a/src/stc-manager.c b/src/stc-manager.c index c7a0564..cf09e88 100755 --- a/src/stc-manager.c +++ b/src/stc-manager.c @@ -258,7 +258,7 @@ EXPORT_API int stc_set_restriction(stc_h stc, return STC_ERROR_INVALID_PARAMETER; } - ret = _stc_restriction_validate_rule(rule, STC_RSTN_TYPE_SET); + ret = _stc_restriction_validate_rule(rule); if (ret != STC_ERROR_NONE) { STC_LOGE("Invalid restriction rule [%s]", _stc_convert_error_type_to_string(ret)); @@ -275,34 +275,6 @@ EXPORT_API int stc_set_restriction(stc_h stc, return STC_ERROR_NONE; } -EXPORT_API int stc_exclude_restriction(stc_h stc, stc_restriction_rule_h rule) -{ - int ret = STC_ERROR_NONE; - - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - - if (!(_stc_handle_check_validity(stc))) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - ret = _stc_restriction_validate_rule(rule, STC_RSTN_TYPE_EXCLUDE); - if (ret != STC_ERROR_NONE) { - STC_LOGE("Invalid restriction rule [%s]", - _stc_convert_error_type_to_string(ret)); - return ret; - } - - ret = _stc_restriction_exclude(rule); - if (ret != STC_ERROR_NONE) { - STC_LOGE("Failed to exclude restriction [%s]", - _stc_convert_error_type_to_string(ret)); - return ret; - } - - return STC_ERROR_NONE; -} - EXPORT_API int stc_unset_restriction(stc_h stc, stc_restriction_rule_h rule) { int ret = STC_ERROR_NONE; @@ -314,7 +286,7 @@ EXPORT_API int stc_unset_restriction(stc_h stc, stc_restriction_rule_h rule) return STC_ERROR_INVALID_PARAMETER; } - ret = _stc_restriction_validate_rule(rule, STC_RSTN_TYPE_UNSET); + ret = _stc_restriction_validate_rule(rule); if (ret != STC_ERROR_NONE) { STC_LOGE("Invalid restriction rule [%s]", _stc_convert_error_type_to_string(ret)); @@ -332,7 +304,7 @@ EXPORT_API int stc_unset_restriction(stc_h stc, stc_restriction_rule_h rule) } EXPORT_API int stc_get_restriction(stc_h stc, stc_restriction_rule_h rule, - stc_restriction_info_cb info_cb, void *user_data) + stc_restriction_rule_cb rule_cb, void *user_data) { int ret = STC_ERROR_NONE; @@ -343,7 +315,7 @@ EXPORT_API int stc_get_restriction(stc_h stc, stc_restriction_rule_h rule, return STC_ERROR_INVALID_PARAMETER; } - if (info_cb == NULL) { + if (rule_cb == NULL) { STC_LOGE("Invalid parameter"); return STC_ERROR_INVALID_PARAMETER; } @@ -355,12 +327,12 @@ EXPORT_API int stc_get_restriction(stc_h stc, stc_restriction_rule_h rule, return ret; } - _stc_callback_set_restriction_info(stc, - info_cb, user_data); + _stc_callback_set_restriction_rule(stc, + rule_cb, user_data); ret = _stc_restriction_get(rule); if (ret != STC_ERROR_NONE) { - STC_LOGE("Failed to request restriction info [%s]", + STC_LOGE("Failed to request restriction rule [%s]", _stc_convert_error_type_to_string(ret)); return ret; } @@ -437,7 +409,7 @@ EXPORT_API int stc_unset_warn_threshold_crossed_cb(stc_h stc) } EXPORT_API int stc_foreach_restriction(stc_h stc, stc_restriction_rule_h rule, - stc_restriction_info_cb info_cb, void *user_data) + stc_restriction_rule_cb rule_cb, void *user_data) { int ret = STC_ERROR_NONE; @@ -448,7 +420,7 @@ EXPORT_API int stc_foreach_restriction(stc_h stc, stc_restriction_rule_h rule, return STC_ERROR_INVALID_PARAMETER; } - if (info_cb == NULL) { + if (rule_cb == NULL) { STC_LOGE("Invalid parameter"); return STC_ERROR_INVALID_PARAMETER; } @@ -460,12 +432,12 @@ EXPORT_API int stc_foreach_restriction(stc_h stc, stc_restriction_rule_h rule, return ret; } - _stc_callback_set_restriction_all_info(stc, - info_cb, user_data); + _stc_callback_set_restriction_all_rule(stc, + rule_cb, user_data); ret = _stc_restriction_get_all(rule); if (ret != STC_ERROR_NONE) { - STC_LOGE("Failed to request restriction all info [%s]", + STC_LOGE("Failed to request restriction all rule [%s]", _stc_convert_error_type_to_string(ret)); return ret; } diff --git a/src/stc-restriction.c b/src/stc-restriction.c index 1c77a85..b6056ae 100755 --- a/src/stc-restriction.c +++ b/src/stc-restriction.c @@ -47,7 +47,6 @@ #include "stc-util.h" #include "stc-event.h" -#include "stc-info.h" #include "stc-restriction.h" /***************************************************************************** @@ -109,6 +108,10 @@ static void __stc_restriction_rule_make_params( STC_RESTRICTION_RULE_SUBSCRIBER_ID, g_variant_new_string(restriction_rule->subscriber_id)); + g_variant_builder_add(builder, "{sv}", + STC_RESTRICTION_RULE_RSTN_TYPE, + g_variant_new_uint16(restriction_rule->rstn_type)); + g_variant_builder_add(builder, "{sv}", STC_RESTRICTION_RULE_DATA_LIMIT, g_variant_new_int64(restriction_rule->data_limit)); @@ -139,74 +142,74 @@ static void __stc_restriction_get_type_make_params( restriction_rule->app_id, restriction_rule->iface_type); } -static void __stc_restriction_extract_info_cb(const char *key, +static void __stc_restriction_extract_rule_cb(const char *key, GVariant *value, void *user_data) { - stc_restriction_info_s *restriction_info = - (stc_restriction_info_s *)user_data; + stc_restriction_rule_s *restriction_rule = + (stc_restriction_rule_s *)user_data; - if (restriction_info == NULL) + if (restriction_rule == NULL) return; - if (!g_strcmp0(key, STC_RESTRICTION_INFO_APP_ID)) { + if (!g_strcmp0(key, STC_RESTRICTION_RULE_APP_ID)) { const char *app_id = g_variant_get_string(value, NULL); if (app_id != NULL) - g_strlcpy(restriction_info->app_id, app_id, STC_APP_ID_LEN); + g_strlcpy(restriction_rule->app_id, app_id, STC_APP_ID_LEN); - } else if (!g_strcmp0(key, STC_RESTRICTION_INFO_IFNAME)) { + } else if (!g_strcmp0(key, STC_RESTRICTION_RULE_IFNAME)) { const char *iface_name = g_variant_get_string(value, NULL); if (iface_name != NULL) - g_strlcpy(restriction_info->iface_name, iface_name, STC_IFNAME_LEN); + g_strlcpy(restriction_rule->iface_name, iface_name, STC_IFNAME_LEN); - } else if (!g_strcmp0(key, STC_RESTRICTION_INFO_SUBSCRIBER_ID)) { + } else if (!g_strcmp0(key, STC_RESTRICTION_RULE_SUBSCRIBER_ID)) { const char *subscriber_id = g_variant_get_string(value, NULL); if (subscriber_id != NULL) - g_strlcpy(restriction_info->subscriber_id, subscriber_id, STC_SUBSCRIBER_ID_LEN); + g_strlcpy(restriction_rule->subscriber_id, subscriber_id, STC_SUBSCRIBER_ID_LEN); - } else if (!g_strcmp0(key, STC_RESTRICTION_INFO_IFTYPE)) { - restriction_info->iface_type = + } else if (!g_strcmp0(key, STC_RESTRICTION_RULE_IFTYPE)) { + restriction_rule->iface_type = (stc_iface_type_e)g_variant_get_uint16(value); - } else if (!g_strcmp0(key, STC_RESTRICTION_INFO_RSTN_TYPE)) { - restriction_info->rstn_type = + } else if (!g_strcmp0(key, STC_RESTRICTION_RULE_RSTN_TYPE)) { + restriction_rule->rstn_type = (stc_restriction_type_e)g_variant_get_uint16(value); - } else if (!g_strcmp0(key, STC_RESTRICTION_INFO_DATA_LIMIT)) { - restriction_info->data_limit = g_variant_get_int64(value); + } else if (!g_strcmp0(key, STC_RESTRICTION_RULE_DATA_LIMIT)) { + restriction_rule->data_limit = g_variant_get_int64(value); - } else if (!g_strcmp0(key, STC_RESTRICTION_INFO_DATA_WARN_LIMIT)) { - restriction_info->data_warn_limit = g_variant_get_int64(value); + } else if (!g_strcmp0(key, STC_RESTRICTION_RULE_DATA_WARN_LIMIT)) { + restriction_rule->data_warn_limit = g_variant_get_int64(value); - } else if (!g_strcmp0(key, STC_RESTRICTION_INFO_ROAMING)) { - restriction_info->roaming_type = + } else if (!g_strcmp0(key, STC_RESTRICTION_RULE_ROAMING)) { + restriction_rule->roaming_type = (stc_roaming_type_e)g_variant_get_uint16(value); } } -static void __stc_restriction_print_info( - stc_restriction_info_s *info) +static void __stc_restriction_print_rule( + stc_restriction_rule_s *rule) { STC_LOGD(STC_HR_SINGLE); - STC_LOGD("App_id: [%s]", (info->app_id[0] != '\0') ? info->app_id : "NULL"); - STC_LOGD("Ifname: [%s]", (info->iface_name[0] != '\0') ? info->iface_name : "NULL"); + STC_LOGD("App_id: [%s]", (rule->app_id[0] != '\0') ? rule->app_id : "NULL"); + STC_LOGD("Ifname: [%s]", (rule->iface_name[0] != '\0') ? rule->iface_name : "NULL"); - if (info->iface_type != STC_IFACE_UNKNOWN) - STC_LOGD("Iftype: [%s]", _stc_convert_iface_type_to_string(info->iface_type)); + if (rule->iface_type != STC_IFACE_UNKNOWN) + STC_LOGD("Iftype: [%s]", _stc_convert_iface_type_to_string(rule->iface_type)); - if (info->subscriber_id[0] != '\0') - STC_LOGD("Sub_id: [%s]", info->subscriber_id); + if (rule->subscriber_id[0] != '\0') + STC_LOGD("Sub_id: [%s]", rule->subscriber_id); - if (info->roaming_type != STC_ROAMING_UNKNOWN) - STC_LOGD("Roaming: [%s]", _stc_convert_roaming_to_string(info->roaming_type)); + if (rule->roaming_type != STC_ROAMING_UNKNOWN) + STC_LOGD("Roaming: [%s]", _stc_convert_roaming_to_string(rule->roaming_type)); - if (info->rstn_type != STC_RSTN_TYPE_UNKNOWN) - STC_LOGD("Type: [%s]", _stc_convert_rstn_type_to_string(info->rstn_type)); + if (rule->rstn_type != STC_RSTN_TYPE_UNKNOWN) + STC_LOGD("Type: [%s]", _stc_convert_rstn_type_to_string(rule->rstn_type)); - STC_LOGD("Limit: [%lld] bytes", info->data_limit); - STC_LOGD("Warning: [%lld] bytes", info->data_warn_limit); + STC_LOGD("Limit: [%lld] bytes", rule->data_limit); + STC_LOGD("Warning: [%lld] bytes", rule->data_warn_limit); STC_LOGD(STC_HR_SINGLE); } @@ -220,7 +223,7 @@ static void __stc_restriction_get_per_app_id_reply( GVariantIter *iter = NULL; stc_error_e dbus_result = STC_ERROR_NONE; stc_error_e error = STC_ERROR_NONE; - stc_restriction_info_s *restriction_info = NULL; + stc_restriction_rule_s *restriction_rule = NULL; GSList *restriction_list = NULL; stc_event_info_s event_data = { 0, }; @@ -238,16 +241,16 @@ static void __stc_restriction_get_per_app_id_reply( g_variant_get(dbus_data, "(ia{sv})", &dbus_result, &iter); if (iter != NULL) { - restriction_info = g_try_malloc0( - sizeof(stc_restriction_info_s)); + restriction_rule = g_try_malloc0( + sizeof(stc_restriction_rule_s)); _stc_dbus_dictionary_foreach(iter, - __stc_restriction_extract_info_cb, restriction_info); + __stc_restriction_extract_rule_cb, restriction_rule); - __stc_restriction_print_info(restriction_info); + __stc_restriction_print_rule(restriction_rule); restriction_list = g_slist_append(restriction_list, - (stc_restriction_info_s *)restriction_info); + (stc_restriction_rule_s *)restriction_rule); g_variant_iter_free(iter); } @@ -279,7 +282,7 @@ static void __stc_restriction_get_all_reply( GVariantIter *iter_row = NULL; stc_error_e dbus_result = STC_ERROR_NONE; stc_error_e error = STC_ERROR_NONE; - stc_restriction_info_s *restriction_info = NULL; + stc_restriction_rule_s *restriction_rule = NULL; GSList *restriction_list = NULL; stc_event_info_s event_data = { 0, }; @@ -297,16 +300,16 @@ static void __stc_restriction_get_all_reply( g_variant_get(dbus_data, "(iaa{sv})", &dbus_result, &iter); while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - restriction_info = g_try_malloc0( - sizeof(stc_restriction_info_s)); + restriction_rule = g_try_malloc0( + sizeof(stc_restriction_rule_s)); _stc_dbus_dictionary_foreach(iter_row, - __stc_restriction_extract_info_cb, restriction_info); + __stc_restriction_extract_rule_cb, restriction_rule); - __stc_restriction_print_info(restriction_info); + __stc_restriction_print_rule(restriction_rule); restriction_list = g_slist_append(restriction_list, - (stc_restriction_info_s *)restriction_info); + (stc_restriction_rule_s *)restriction_rule); g_variant_iter_free(iter_row); } @@ -403,7 +406,7 @@ stc_error_e __stc_restriction_get_all( } stc_error_e _stc_restriction_validate_rule( - stc_restriction_rule_h rule, stc_rstn_type_e rstn_type) + stc_restriction_rule_h rule) { stc_restriction_rule_s *restriction_rule = rule; @@ -412,8 +415,8 @@ stc_error_e _stc_restriction_validate_rule( STC_ERROR_INVALID_PARAMETER, "Restriction rule should be set"); - STC_RETURN_VAL_IF(rstn_type <= STC_RSTN_TYPE_UNDEF || - rstn_type >= STC_RSTN_TYPE_MAX_VALUE, + STC_RETURN_VAL_IF(restriction_rule->rstn_type < STC_RSTN_TYPE_UNKNOWN || + restriction_rule->rstn_type >= STC_RSTN_TYPE_LAST_ELEM, STC_ERROR_INVALID_PARAMETER, "Invalid restriction type"); @@ -427,7 +430,7 @@ stc_error_e _stc_restriction_validate_rule( "Invalid restriction network interface type [%s]", _stc_convert_iface_type_to_string(restriction_rule->iface_type)); - if (rstn_type == STC_RSTN_TYPE_SET) { + if (restriction_rule->rstn_type == STC_RSTN_TYPE_DROP) { STC_RETURN_VAL_IF(restriction_rule->data_limit < 0, STC_ERROR_INVALID_PARAMETER, "Invalid tx limit [%lld] bytes", @@ -664,34 +667,6 @@ stc_error_e _stc_restriction_set( return STC_ERROR_NONE; } -stc_error_e _stc_restriction_exclude( - stc_restriction_rule_h rule) -{ - GVariant *message = NULL; - GVariant *params = NULL; - stc_error_e error = STC_ERROR_NONE; - int result = 0; - - __stc_restriction_rule_make_params(rule, ¶ms); - - message = _stc_dbus_invoke_method( - STC_MANAGER_SERVICE, - STC_MANAGER_RESTRICTION_PATH, - STC_MANAGER_RESTRICTION_INTERFACE, - STC_MANAGER_METHOD_RESTRICTION_EXCLUDE, - params, - &error); - - STC_RETURN_VAL_IF(message == NULL, - error, "Failed to invoke dbus method"); - - g_variant_get(message, "(i)", &result); - STC_LOGI("Successfully exclude restriction [%d]", result); - g_variant_unref(message); - - return STC_ERROR_NONE; -} - stc_error_e _stc_restriction_unset( stc_restriction_rule_h rule) { @@ -893,6 +868,36 @@ EXPORT_API int stc_restriction_rule_set_iface_type(stc_restriction_rule_h rule, return STC_ERROR_NONE; } +EXPORT_API int stc_restriction_rule_set_type(stc_restriction_rule_h rule, + stc_restriction_type_e type) +{ + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); + + if (rule == NULL) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; + } + + stc_restriction_rule_s *restriction_rule = + (stc_restriction_rule_s *)rule; + + switch (type) { + case STC_RSTN_TYPE_UNKNOWN: + case STC_RSTN_TYPE_ACCEPT: + case STC_RSTN_TYPE_DROP: + restriction_rule->rstn_type = type; + break; + default: + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; + } + + STC_LOGI("Type [%s]", + _stc_convert_rstn_type_to_string(restriction_rule->rstn_type)); + + return STC_ERROR_NONE; +} + EXPORT_API int stc_restriction_rule_set_limit(stc_restriction_rule_h rule, int64_t data_limit) { @@ -1050,6 +1055,26 @@ EXPORT_API int stc_restriction_rule_get_iface_type(stc_restriction_rule_h rule, return STC_ERROR_NONE; } +EXPORT_API int stc_restriction_rule_get_type(stc_restriction_rule_h rule, + stc_restriction_type_e *type) +{ + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); + + if (rule == NULL) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; + } + + stc_restriction_rule_s *restriction_rule = + (stc_restriction_rule_s *)rule; + + *type = restriction_rule->rstn_type; + + STC_LOGI("Type [%s]", _stc_convert_rstn_type_to_string(*type)); + + return STC_ERROR_NONE; +} + EXPORT_API int stc_restriction_rule_get_limit(stc_restriction_rule_h rule, int64_t *data_limit) { diff --git a/test/restriction.c b/test/restriction.c index 2f3e4b5..4678fc2 100755 --- a/test/restriction.c +++ b/test/restriction.c @@ -49,15 +49,16 @@ static char g_roaming[MENU_DATA_SIZE] = "0"; static char g_subscriber_id[MENU_DATA_SIZE] = ""; static char g_data_limit[MENU_DATA_SIZE] = "0"; static char g_data_warn_limit[MENU_DATA_SIZE] = "0"; +static char g_type[MENU_DATA_SIZE] = "1"; extern stc_h g_stc; static stc_restriction_rule_h g_restriction_rule = NULL; -static stc_callback_ret_e __test_stc_restriction_info_cb( - stc_error_e result, stc_restriction_info_h info, void *user_data) +static stc_callback_ret_e __test_stc_restriction_rule_cb( + stc_error_e result, stc_restriction_rule_h rule, void *user_data) { if (result != STC_ERROR_NONE) { - msg("Response restriction info error " LOG_RED "[%s]" LOG_END, + msg("Response restriction rule error " LOG_RED "[%s]" LOG_END, test_stc_convert_error_type_to_string(result)); return STC_CALLBACK_CANCEL; } @@ -74,35 +75,35 @@ static stc_callback_ret_e __test_stc_restriction_info_cb( msg(HR_SINGLE); - ret = stc_restriction_info_get_app_id(info, &app_id); + ret = stc_restriction_rule_get_app_id(rule, &app_id); if (ret == STC_ERROR_NONE) msg("App_id: " LOG_CYAN "[%s]" LOG_END, app_id); - ret = stc_restriction_info_get_iface_name(info, &iface_name); + ret = stc_restriction_rule_get_iface_name(rule, &iface_name); if (ret == STC_ERROR_NONE) msg("Ifname: [%s]", iface_name); - ret = stc_restriction_info_get_subscriber_id(info, &subscriber_id); + ret = stc_restriction_rule_get_subscriber_id(rule, &subscriber_id); if (ret == STC_ERROR_NONE) msg("Sub_id: [%s]", subscriber_id); - ret = stc_restriction_info_get_type(info, &rstn_type); + ret = stc_restriction_rule_get_type(rule, &rstn_type); if (ret == STC_ERROR_NONE) msg("Type: [%s]", test_stc_convert_rstn_type_to_string(rstn_type)); - ret = stc_restriction_info_get_iface_type(info, &iface_type); + ret = stc_restriction_rule_get_iface_type(rule, &iface_type); if (ret == STC_ERROR_NONE) msg("Iftype: [%s]", test_stc_convert_iface_type_to_string(iface_type)); - ret = stc_restriction_info_get_roaming_type(info, &roaming); + ret = stc_restriction_rule_get_roaming_type(rule, &roaming); if (ret == STC_ERROR_NONE) msg("Roaming: [%s]", test_stc_convert_roaming_to_string(roaming)); - ret = stc_restriction_info_get_limit(info, &data_limit); + ret = stc_restriction_rule_get_limit(rule, &data_limit); if (ret == STC_ERROR_NONE) msg("Data_limit: [%lld]", data_limit); - ret = stc_restriction_info_get_warning_limit(info, &data_warn_limit); + ret = stc_restriction_rule_get_warning_limit(rule, &data_warn_limit); if (ret == STC_ERROR_NONE) msg("Data_warn_limit: [%lld]", data_warn_limit); @@ -115,7 +116,7 @@ static stc_callback_ret_e __test_stc_restriction_info_cb( return STC_CALLBACK_CONTINUE; } -static void __test_stc_warn_threshold_crossed_cb(stc_restriction_info_h info, +static void __test_stc_warn_threshold_crossed_cb(stc_restriction_rule_h rule, void *user_data) { int ret = STC_ERROR_NONE; @@ -123,7 +124,7 @@ static void __test_stc_warn_threshold_crossed_cb(stc_restriction_info_h info, msg(HR_SINGLE); - ret = stc_restriction_info_get_app_id(info, &app_id); + ret = stc_restriction_rule_get_app_id(rule, &app_id); if (ret == STC_ERROR_NONE) msg("Warn threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, app_id); @@ -131,7 +132,7 @@ static void __test_stc_warn_threshold_crossed_cb(stc_restriction_info_h info, msg(HR_SINGLE); } -static void __test_stc_restriction_threshold_crossed_cb(stc_restriction_info_h info, +static void __test_stc_restriction_threshold_crossed_cb(stc_restriction_rule_h rule, void *user_data) { int ret = STC_ERROR_NONE; @@ -139,7 +140,7 @@ static void __test_stc_restriction_threshold_crossed_cb(stc_restriction_info_h i msg(HR_SINGLE); - ret = stc_restriction_info_get_app_id(info, &app_id); + ret = stc_restriction_rule_get_app_id(rule, &app_id); if (ret == STC_ERROR_NONE) msg("Restriction threshold crossed app_id: " LOG_CYAN "[%s]" LOG_END, app_id); @@ -156,6 +157,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) char *app_id = NULL; char *subscriber_id = NULL; char *iface_name = NULL; + stc_restriction_type_e type = (int)strtol(g_type, NULL, 10); int ret = STC_ERROR_NONE; ret = stc_restriction_rule_set_app_id(g_restriction_rule, g_app_id); @@ -231,6 +233,17 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } } + if (type > STC_RSTN_TYPE_UNKNOWN && type < STC_RSTN_TYPE_LAST_ELEM) { + ret = stc_restriction_rule_set_type(g_restriction_rule, type); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to set type" LOG_END); + else { + msg("Fail to set type " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + msg(HR_SINGLE); ret = stc_restriction_rule_get_app_id(g_restriction_rule, &app_id); @@ -261,6 +274,11 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) msg("Roaming: " LOG_CYAN "[%s]" LOG_END, test_stc_convert_roaming_to_string(roaming)); + ret = stc_restriction_rule_get_type(g_restriction_rule, &type); + if (ret == STC_ERROR_NONE) + msg("Type: " LOG_CYAN "[%s]" LOG_END, + test_stc_convert_rstn_type_to_string(type)); + data_limit = 0; ret = stc_restriction_rule_get_limit(g_restriction_rule, &data_limit); if (ret == STC_ERROR_NONE) @@ -298,13 +316,13 @@ static int __test_stc_restriction_get(MManager *mm, struct menu_data *menu) ret = stc_get_restriction(g_stc, g_restriction_rule, - __test_stc_restriction_info_cb, + __test_stc_restriction_rule_cb, NULL); if (ret == STC_ERROR_NONE) - msg(LOG_GREEN "Success to request restriction info" LOG_END); + msg(LOG_GREEN "Success to request restriction rule" LOG_END); else - msg("Fail to request restriction info " LOG_RED "[%s]" LOG_END, + msg("Fail to request restriction rule " LOG_RED "[%s]" LOG_END, test_stc_convert_error_type_to_string(ret)); return ret; @@ -316,13 +334,13 @@ static int __test_stc_restriction_get_all(MManager *mm, struct menu_data *menu) ret = stc_foreach_restriction(g_stc, g_restriction_rule, - __test_stc_restriction_info_cb, + __test_stc_restriction_rule_cb, NULL); if (ret == STC_ERROR_NONE) - msg(LOG_GREEN "Success to request restriction all info" LOG_END); + msg(LOG_GREEN "Success to request restriction all rule" LOG_END); else - msg("Fail to request restriction all info " LOG_RED "[%s]" LOG_END, + msg("Fail to request restriction all rule " LOG_RED "[%s]" LOG_END, test_stc_convert_error_type_to_string(ret)); return ret; @@ -362,21 +380,6 @@ static int __test_stc_restriction_unset(MManager *mm, struct menu_data *menu) return ret; } -static int __test_stc_restriction_exclude(MManager *mm, struct menu_data *menu) -{ - int ret = STC_ERROR_NONE; - - ret = stc_exclude_restriction(g_stc, g_restriction_rule); - - if (ret == STC_ERROR_NONE) - msg(LOG_GREEN "Success to exclude restriction" LOG_END); - else - msg("Fail to exclude restriction " LOG_RED "[%s]" LOG_END, - test_stc_convert_error_type_to_string(ret)); - - return ret; -} - int test_stc_restriction_rule_create(void) { int ret = stc_restriction_rule_create(g_stc, &g_restriction_rule); @@ -457,8 +460,9 @@ static struct menu_data menu_restriction_rule[] = { { "3", "Interface type(1.Tel/2.Wifi/3.Wired/4.BT/5.All)", NULL, NULL, g_iface_type}, { "4", "Interface name", NULL, NULL, g_iface_name}, { "5", "Roaming(1.Enable/2.Disable)", NULL, NULL, g_roaming}, - { "6", "Data limit", NULL, NULL, g_data_limit}, - { "7", "Data warn limit", NULL, NULL, g_data_warn_limit}, + { "6", "Type(1.Accept/2.Drop)", NULL, NULL, g_type}, + { "7", "Data limit", NULL, NULL, g_data_limit}, + { "8", "Data warn limit", NULL, NULL, g_data_warn_limit}, { "s", LOG_LIGHTMAGENTA "[Set]" LOG_END, NULL, __test_stc_set_restriction_rule, NULL}, { NULL, NULL, }, }; @@ -469,7 +473,6 @@ struct menu_data menu_restriction[] = { { "3", LOG_LIGHTBLUE "[Get]" LOG_END " all restrictions", NULL, __test_stc_restriction_get_all, NULL}, { "4", LOG_LIGHTBLUE "[Get]" LOG_END " restriction type", NULL, __test_stc_restriction_get_type, NULL}, { "5", LOG_LIGHTMAGENTA "[Set]" LOG_END " restriction", NULL, __test_stc_restriction_set, NULL}, - { "6", LOG_LIGHTMAGENTA "[Remove]" LOG_END " restriction", NULL, __test_stc_restriction_unset, NULL}, - { "7", LOG_LIGHTMAGENTA "[Exlcude]" LOG_END " restriction", NULL, __test_stc_restriction_exclude, NULL}, + { "6", LOG_LIGHTMAGENTA "[Unset]" LOG_END " restriction", NULL, __test_stc_restriction_unset, NULL}, { NULL, NULL, }, };