From: hyunuktak Date: Wed, 20 Feb 2019 01:48:08 +0000 (+0900) Subject: Restriction list management X-Git-Tag: submit/tizen/20190311.084912~5^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F90%2F200190%2F2;p=platform%2Fcore%2Fapi%2Fsmart-traffic-control.git Restriction list management stc_restriction_list_create stc_restriction_list_destroy stc_add_restriction_rule_to_list stc_remove_restriction_rule_from_list stc_foreach_restriction_rule_from_list stc_set_restriction_list stc_unset_restriction_list Change-Id: I5d0f078bc3ac075444dc41a60404ac0f63a4da36 Signed-off-by: hyunuktak --- diff --git a/include/stc_mgr_internal.h b/include/stc_mgr_internal.h index 5c8ac05..c1aef71 100755 --- a/include/stc_mgr_internal.h +++ b/include/stc_mgr_internal.h @@ -88,9 +88,6 @@ extern "C" { typedef stc_callback_ret_e (*stc_restriction_rule_cb)(stc_error_e result, stc_restriction_rule_h rule, void *user_data); -typedef stc_callback_ret_e (*stc_restriction_list_cb)(stc_error_e result, - stc_restriction_list_h list, void *user_data); - typedef void (*stc_threshold_crossed_cb)(stc_restriction_rule_h rule, void *user_data); @@ -490,106 +487,13 @@ int stc_remove_restriction_rule_from_list(stc_restriction_list_h list_h, stc_restriction_rule_h rule_h); /** - * @brief Saves the restriction rules from list. + * @brief Gets the restriction rule from list. * @since_tizen 5.5 * @privlevel platform * @privilege %http://tizen.org/privilege/network.get * - * @param[in] list The restriction list 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_restriction_list_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_restriction_list_create() - * @see stc_add_restriction_rule_to_list() - * @see stc_remove_restriction_rule_from_list() - * @see stc_set_restriction_list() - * @see stc_unset_restriction_list() - */ -int stc_save_restriction_list(stc_restriction_list_h list_h); - -/** - * @brief Loads the restriction list. - * @since_tizen 5.5 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] stc The stc handle - * @param[in] list_cb The callback is called for each restriction list - * @param[in] user_data User data will be passed to the callback function - * - * @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_list_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_restriction_list_create() - * @see stc_add_restriction_rule_to_list() - * @see stc_remove_restriction_rule_from_list() - * @see stc_set_restriction_list() - * @see stc_unset_restriction_list() - */ -int stc_load_restriction_list(stc_h stc, stc_restriction_list_cb list_cb, void *user_data); - -/** - * @brief Loads the restriction rule from list. - * @since_tizen 5.5 - * @privlevel platform - * @privilege %http://tizen.org/privilege/network.get - * - * @param[in] stc The stc handle * @param[in] list_h The restriction list handle - * @param[in] rule_cb The callback is called for each restriction rule + * @param[in] rule_cb The callback is called for each rule from list * @param[in] user_data User data will be passed to the callback function * * @return 0 on success, otherwise a negative error value @@ -622,12 +526,11 @@ int stc_load_restriction_list(stc_h stc, stc_restriction_list_cb list_cb, void * * @see stc_restriction_rule_get_subscriber_id() * @see stc_restriction_rule_get_process_state() * @see stc_restriction_list_create() - * @see stc_add_restriction_rule_to_list() * @see stc_remove_restriction_rule_from_list() * @see stc_set_restriction_list() * @see stc_unset_restriction_list() */ -int stc_load_restriction_rule_from_list(stc_h stc, stc_restriction_list_h list_h, +int stc_foreach_restriction_rule_from_list(stc_restriction_list_h list_h, stc_restriction_rule_cb rule_cb, void *user_data); /** diff --git a/include/stc_rstn_internal.h b/include/stc_rstn_internal.h index 0fc3474..6f124d0 100755 --- a/include/stc_rstn_internal.h +++ b/include/stc_rstn_internal.h @@ -80,17 +80,6 @@ typedef enum { STC_RSTN_TYPE_LAST_ELEM, } stc_restriction_type_e; -/** - * @brief Enumeration for network restriction state. - * @since_tizen 5.5 - */ -typedef enum { - STC_RSTN_STATE_UNKNOWN, - STC_RSTN_STATE_ACTIVATED, - STC_RSTN_STATE_DEACTIVATED, - STC_RSTN_STATE_LAST_ELEM -} stc_restriction_state_e; - /** * @} */ @@ -818,7 +807,7 @@ int stc_restriction_rule_get_subscriber_id(stc_restriction_rule_h rule, char **s * @privilege %http://tizen.org/privilege/network.get * @remarks You must release @a handle using stc_restriction_list_destroy(). * - * @param[in] name The restriction list name + * @param[in] stc The stc handle * @param[out] list The restriction list handle * * @return 0 on success, otherwise a negative error value @@ -836,7 +825,7 @@ int stc_restriction_rule_get_subscriber_id(stc_restriction_rule_h rule, char **s * @see stc_initialize() * @see stc_restriction_list_destroy() */ -int stc_restriction_list_create(const char *name, stc_restriction_list_h *list_h); +int stc_restriction_list_create(stc_h stc, stc_restriction_list_h *list_h); /** * @brief Destroys the restriction list handle. @@ -860,7 +849,6 @@ int stc_restriction_list_create(const char *name, stc_restriction_list_h *list_h * @see stc_restriction_list_create() */ int stc_restriction_list_destroy(stc_restriction_list_h list_h); - /** * @} */ diff --git a/src/include/stc-restriction.h b/src/include/stc-restriction.h index f5d8d8b..6210b85 100755 --- a/src/include/stc-restriction.h +++ b/src/include/stc-restriction.h @@ -80,9 +80,7 @@ typedef struct { } stc_restriction_rule_s; typedef struct { - char name[STC_LIST_NAME_LEN]; GSList *rules; - stc_restriction_state_e state; } stc_restriction_list_s; /***************************************************************************** @@ -101,20 +99,15 @@ bool _stc_restriction_add_rule_to_list(stc_restriction_list_h list, stc_restriction_rule_h rule); bool _stc_restriction_remove_rule_from_list(stc_restriction_list_h list, stc_restriction_rule_h rule); -bool _stc_restriction_flush_rule_from_list(stc_restriction_list_h list_h); +stc_error_e _stc_restriction_foreach_rule_from_list(stc_restriction_list_h list_h, + stc_restriction_rule_cb rule_cb, void *user_data); void _stc_restriction_add_to_list(stc_restriction_list_h list); void _stc_restriction_remove_from_list(stc_restriction_list_h list); bool _stc_restriction_check_list_validity(stc_restriction_list_h list); -void _stc_restriction_add_to_load_list(stc_restriction_list_h list); -void _stc_restriction_remove_from_load_list(stc_restriction_list_h list); -void _stc_restriction_clear_load_list(void); - -stc_error_e _stc_restriction_save_list(stc_restriction_list_h list); -stc_error_e _stc_restriction_load_list(void); -stc_error_e _stc_restriction_load_rule_from_list(stc_restriction_list_h list, - stc_restriction_rule_cb rule_cb, void *user_data); +stc_error_e _stc_restriction_set_list(stc_restriction_list_h list_h); +stc_error_e _stc_restriction_unset_list(stc_restriction_list_h list_h); stc_error_e _stc_restriction_validate_rule( stc_restriction_rule_h rule); diff --git a/src/internal/include/stc-dbus.h b/src/internal/include/stc-dbus.h index bca7ad3..232169d 100755 --- a/src/internal/include/stc-dbus.h +++ b/src/internal/include/stc-dbus.h @@ -73,9 +73,8 @@ extern "C" { #define STC_MANAGER_METHOD_RESTRICTION_GET_ALL "GetAll" #define STC_MANAGER_METHOD_RESTRICTION_UNSET "Unset" -#define STC_MANAGER_METHOD_RESTRICTION_SAVE_LIST "SaveList" -#define STC_MANAGER_METHOD_RESTRICTION_LOAD_LIST "LoadList" -#define STC_MANAGER_METHOD_RESTRICTION_LOAD_RULE_FROM_LIST "LoadRuleFromList" +#define STC_MANAGER_METHOD_RESTRICTION_SET_LIST "SetList" +#define STC_MANAGER_METHOD_RESTRICTION_UNSET_LIST "UnsetList" #define STC_MANAGER_METHOD_IPTABLES_COMMIT "CommitIptables" #define STC_MANAGER_METHOD_IP6TABLES_COMMIT "CommitIp6tables" diff --git a/src/internal/include/stc-event.h b/src/internal/include/stc-event.h index 775fd02..15c6eed 100755 --- a/src/internal/include/stc-event.h +++ b/src/internal/include/stc-event.h @@ -57,8 +57,6 @@ typedef enum { STC_EVENT_STATS_GET_TOTAL_RSP, STC_EVENT_RESTRICTION_GET_RSP, STC_EVENT_RESTRICTION_GET_ALL_RSP, - STC_EVENT_RESTRICTION_LOAD_LIST_RSP, - STC_EVENT_RESTRICTION_LOAD_RULE_FROM_LIST_RSP, STC_EVENT_WARN_THRESHOLD_CROSSED_RSP, STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP, STC_EVENT_PCAP_FIND_ALL_DEVS_RSP, @@ -72,8 +70,6 @@ typedef enum { STC_REQUEST_TABLE_STATS_GET_TOTAL, STC_REQUEST_TABLE_RESTRICTION_GET, STC_REQUEST_TABLE_RESTRICTION_GET_ALL, - STC_REQUEST_TABLE_RESTRICTION_LOAD_LIST, - STC_REQUEST_TABLE_RESTRICTION_LOAD_RULE_FROM_LIST, STC_REQUEST_TABLE_PCAP_FIND_ALL_DEVS, STC_REQUEST_TABLE_LAST_ELEM, } stc_request_table_e; diff --git a/src/internal/include/stc-private.h b/src/internal/include/stc-private.h index a1f1728..7ac0a39 100755 --- a/src/internal/include/stc-private.h +++ b/src/internal/include/stc-private.h @@ -70,12 +70,6 @@ typedef struct { stc_restriction_rule_cb restriction_all_cb; void *restriction_all_user_data; - stc_restriction_list_cb restriction_list_cb; - void *restriction_list_user_data; - - stc_restriction_rule_cb restriction_rule_from_list_cb; - void *restriction_rule_from_list_user_data; - stc_threshold_crossed_cb restriction_crossed_cb; void *restriction_crossed_user_data; stc_threshold_crossed_cb warn_crossed_cb; @@ -148,10 +142,6 @@ void _stc_callback_set_restriction_rule(stc_h stc, stc_restriction_rule_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); -void _stc_callback_set_restriction_list(stc_h stc, - stc_restriction_list_cb user_cb, void *user_data); -void _stc_callback_set_restriction_rule_from_list(stc_h stc, - stc_restriction_list_cb user_cb, void *user_data); void _stc_callback_set_restriction_threshold_crossed(stc_h stc, stc_threshold_crossed_cb user_cb, void *user_data); diff --git a/src/internal/stc-private.c b/src/internal/stc-private.c index 40f38a5..eeeffa3 100755 --- a/src/internal/stc-private.c +++ b/src/internal/stc-private.c @@ -510,52 +510,6 @@ static void __stc_callback_foreach(stc_event_e e, handle->restriction_all_user_data = NULL; } break; - case STC_EVENT_RESTRICTION_LOAD_LIST_RSP: - if (handle->restriction_list_cb) { - if (err == STC_ERROR_NONE) { - if (info_data != NULL) { - for (data = info_data; data; data = data->next) { - stc_restriction_list_h load_list = data->data; - ret = handle->restriction_list_cb(err, - load_list, handle->restriction_list_user_data); - if (ret == STC_CALLBACK_CANCEL) - break; - } - } else { - handle->restriction_all_cb(err, NULL, NULL); - } - } else { - handle->restriction_list_cb(err, NULL, NULL); - } - - handle->restriction_list_cb = NULL; - handle->restriction_list_user_data = NULL; - } - break; - case STC_EVENT_RESTRICTION_LOAD_RULE_FROM_LIST_RSP: - if (handle->restriction_rule_from_list_cb) { - if (err == STC_ERROR_NONE) { - if (info_data != NULL) { - stc_restriction_list_h list_h = (stc_restriction_list_h)info_data; - stc_restriction_list_s *list_data = (stc_restriction_list_s *)list_h; - for (data = list_data->rules; data; data = data->next) { - stc_restriction_rule_h rule_h = data->data; - ret = handle->restriction_rule_from_list_cb(err, - rule_h, handle->restriction_rule_from_list_user_data); - if (ret == STC_CALLBACK_CANCEL) - break; - } - } else { - handle->restriction_rule_from_list_cb(err, NULL, NULL); - } - } else { - handle->restriction_rule_from_list_cb(err, NULL, NULL); - } - - handle->restriction_rule_from_list_cb = NULL; - handle->restriction_rule_from_list_user_data = NULL; - } - break; case STC_EVENT_PCAP_FIND_ALL_DEVS_RSP: if (handle->pcap_info_cb) { if (err == STC_ERROR_NONE) { @@ -637,14 +591,6 @@ static void __stc_event_cb(stc_event_info_s *event_info, void *user_data) } break; //LCOV_EXCL_START - case STC_EVENT_RESTRICTION_LOAD_LIST_RSP: - case STC_EVENT_RESTRICTION_LOAD_RULE_FROM_LIST_RSP: - { - stc_error_e error = event_info->error; - GSList *info_data = (GSList *)event_info->info_data; - __stc_callback_foreach(event_info->event, error, info_data); - } - break; case STC_EVENT_WARN_THRESHOLD_CROSSED_RSP: case STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP: { @@ -774,24 +720,6 @@ void _stc_callback_set_restriction_all_rule(stc_h stc, handle->restriction_all_user_data = user_data; } -void _stc_callback_set_restriction_list(stc_h stc, - stc_restriction_list_cb user_cb, void *user_data) -{ - stc_handle_s *handle = (stc_handle_s *)stc; - - handle->restriction_list_cb = user_cb; - handle->restriction_list_user_data = user_data; -} - -void _stc_callback_set_restriction_rule_from_list(stc_h stc, - stc_restriction_list_cb user_cb, void *user_data) -{ - stc_handle_s *handle = (stc_handle_s *)stc; - - handle->restriction_rule_from_list_cb = user_cb; - handle->restriction_rule_from_list_user_data = user_data; -} - void _stc_callback_set_restriction_threshold_crossed(stc_h stc, stc_threshold_crossed_cb user_cb, void *user_data) { diff --git a/src/stc-manager.c b/src/stc-manager.c index 41d62bf..b9c88fc 100755 --- a/src/stc-manager.c +++ b/src/stc-manager.c @@ -609,10 +609,9 @@ EXPORT_API int stc_remove_restriction_rule_from_list(stc_restriction_list_h list return STC_ERROR_NONE; } -EXPORT_API int stc_save_restriction_list(stc_restriction_list_h list_h) +EXPORT_API int stc_foreach_restriction_rule_from_list(stc_restriction_list_h list_h, + stc_restriction_rule_cb rule_cb, void *user_data) { - int ret = STC_ERROR_NONE; - CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); if (_stc_restriction_check_list_validity(list_h) == false) { @@ -620,18 +619,15 @@ EXPORT_API int stc_save_restriction_list(stc_restriction_list_h list_h) return STC_ERROR_INVALID_PARAMETER; } - ret = _stc_restriction_save_list(list_h); - if (ret != STC_ERROR_NONE) { - STC_LOGE("Failed to save restriction list [%s]", - _stc_convert_error_type_to_string(ret)); - return ret; + if (rule_cb == NULL) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; } - return STC_ERROR_NONE; + return _stc_restriction_foreach_rule_from_list(list_h, rule_cb, user_data); } -EXPORT_API int stc_load_restriction_list(stc_h stc, - stc_restriction_list_cb list_cb, void *user_data) +EXPORT_API int stc_set_restriction_list(stc_h stc, stc_restriction_list_h list_h) { int ret = STC_ERROR_NONE; @@ -642,16 +638,14 @@ EXPORT_API int stc_load_restriction_list(stc_h stc, return STC_ERROR_INVALID_PARAMETER; } - if (list_cb == NULL) { + if (_stc_restriction_check_list_validity(list_h) == false) { STC_LOGE("Invalid parameter"); return STC_ERROR_INVALID_PARAMETER; } - _stc_callback_set_restriction_list(stc, list_cb, user_data); - - ret = _stc_restriction_load_list(); + ret = _stc_restriction_set_list(list_h); if (ret != STC_ERROR_NONE) { - STC_LOGE("Failed to request restriction list [%s]", + STC_LOGE("Failed to set restriction [%s]", _stc_convert_error_type_to_string(ret)); return ret; } @@ -659,8 +653,7 @@ EXPORT_API int stc_load_restriction_list(stc_h stc, return STC_ERROR_NONE; } -EXPORT_API int stc_load_restriction_rule_from_list(stc_h stc, stc_restriction_list_h list_h, - stc_restriction_rule_cb rule_cb, void *user_data) +EXPORT_API int stc_unset_restriction_list(stc_h stc, stc_restriction_list_h list_h) { int ret = STC_ERROR_NONE; @@ -676,16 +669,9 @@ EXPORT_API int stc_load_restriction_rule_from_list(stc_h stc, stc_restriction_li return STC_ERROR_INVALID_PARAMETER; } - if (rule_cb == NULL) { - STC_LOGE("Invalid parameter"); - return STC_ERROR_INVALID_PARAMETER; - } - - _stc_callback_set_restriction_rule_from_list(stc, rule_cb, user_data); - - ret = _stc_restriction_load_rule_from_list(list_h, rule_cb, user_data); + ret = _stc_restriction_unset_list(list_h); if (ret != STC_ERROR_NONE) { - STC_LOGE("Failed to request restriction rule from list [%s]", + STC_LOGE("Failed to unset restriction [%s]", _stc_convert_error_type_to_string(ret)); return ret; } diff --git a/src/stc-restriction.c b/src/stc-restriction.c index 2720325..0a9ae31 100755 --- a/src/stc-restriction.c +++ b/src/stc-restriction.c @@ -59,7 +59,6 @@ static GSList *g_restriction_rule = NULL; static GSList *g_restriction_list = NULL; -static GSList *g_restriction_load_list = NULL; /***************************************************************************** * Local Functions Definition @@ -87,12 +86,9 @@ static void __stc_restriction_deinit_rule(stc_restriction_rule_h rule) g_free(rule); } -static void __stc_restriction_init_list(stc_restriction_list_s *list, - const char *name) +static void __stc_restriction_init_list(stc_restriction_list_s *list) { - g_strlcpy(list->name, name, STC_LIST_NAME_LEN); list->rules = NULL; - list->state = STC_RSTN_STATE_DEACTIVATED; } static void __stc_restriction_deinit_list(stc_restriction_list_h list_h) @@ -102,14 +98,6 @@ static void __stc_restriction_deinit_list(stc_restriction_list_h list_h) g_free(list_h); } -static void __stc_restriction_flush_rule(gpointer data, gpointer user_data) -{ - stc_restriction_rule_h rule = (stc_restriction_rule_h)data; - - _stc_restriction_remove_rule(rule); - __stc_restriction_deinit_rule(rule); -} - static void __stc_restriction_rule_make_params( stc_restriction_rule_h rule, GVariant **params) @@ -189,7 +177,7 @@ static void __stc_restriction_get_type_make_params( restriction_rule->app_id, restriction_rule->iface_type); } -static void __stc_restriction_load_list_make_params(gpointer data, +static void __stc_restriction_list_make_params(gpointer data, gpointer user_data) { stc_restriction_rule_s *rule = (stc_restriction_rule_s *)data; @@ -256,18 +244,10 @@ static void __stc_restriction_list_foreach(stc_restriction_list_h list_h, if (find) { stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - g_slist_foreach(list_data->rules, __stc_restriction_load_list_make_params, builder); + g_slist_foreach(list_data->rules, __stc_restriction_list_make_params, builder); } } -static void __stc_restriction_load_rule_from_list_params( - stc_restriction_list_h list, GVariant **params) -{ - stc_restriction_list_s *restriction_list = list; - - *params = g_variant_new("(s)", restriction_list->name); -} - static void __stc_restriction_extract_rule_cb(const char *key, GVariant *value, void *user_data) { @@ -326,27 +306,6 @@ static void __stc_restriction_extract_rule_cb(const char *key, } -static void __stc_restriction_extract_list_cb(const char *key, - GVariant *value, void *user_data) -{ - stc_restriction_list_s *restriction_list = - (stc_restriction_list_s *)user_data; - - if (restriction_list == NULL) - return; - - if (!g_strcmp0(key, STC_RESTRICTION_LIST_NAME)) { - const char *name = g_variant_get_string(value, NULL); - if (name != NULL) - g_strlcpy(restriction_list->name, name, STC_LIST_NAME_LEN); - - } else if (!g_strcmp0(key, STC_RESTRICTION_LIST_STATE)) { - restriction_list->state = g_variant_get_uint16(value); - - } - -} - static void __stc_restriction_print_rule(stc_restriction_rule_s *rule) { STC_LOGD(STC_HR_SINGLE); @@ -385,159 +344,6 @@ static void __stc_restriction_print_rule(stc_restriction_rule_s *rule) STC_LOGD(STC_HR_SINGLE); } -static void __stc_restriction_print_list(stc_restriction_list_s *list) -{ - STC_LOGD(STC_HR_SINGLE); - - STC_LOGD("Name: [%s]", list->name); - STC_LOGD("State: [%u]", list->state); - - STC_LOGD(STC_HR_SINGLE); -} - -bool __stc_restriction_check_list_validity(stc_restriction_list_h list_h) -{ - if (!list_h) - return false; - - if (g_slist_find(g_restriction_list, list_h)) - return true; - - return false; -} - -static void __stc_restriction_load_list_reply( - GObject *source_object, GAsyncResult *res, gpointer user_data) -{ - GDBusConnection *conn = NULL; - GError *dbus_error = NULL; - GVariant *dbus_data = NULL; - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - stc_error_e dbus_result = STC_ERROR_NONE; - stc_error_e error = STC_ERROR_NONE; - stc_restriction_list_s *restriction_list = NULL; - stc_event_info_s event_data = { 0, }; - - conn = G_DBUS_CONNECTION(source_object); - dbus_data = g_dbus_connection_call_finish(conn, res, &dbus_error); - if (dbus_error != NULL) { - error = _stc_convert_error_string_to_enum(dbus_error->message); - g_error_free(dbus_error); - } - - if (_stc_event_get_request_table_state(STC_REQUEST_TABLE_RESTRICTION_LOAD_LIST)) - _stc_event_set_request_table_state(STC_REQUEST_TABLE_RESTRICTION_LOAD_LIST, false); - - if (error == STC_ERROR_NONE) { - g_variant_get(dbus_data, "(iaa{sv})", &dbus_result, &iter); - - _stc_restriction_clear_load_list(); - - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - restriction_list = g_try_malloc0(sizeof(stc_restriction_list_s)); - if (restriction_list) { - _stc_dbus_dictionary_foreach(iter_row, - __stc_restriction_extract_list_cb, restriction_list); - - __stc_restriction_print_list(restriction_list); - - _stc_restriction_add_to_load_list(restriction_list); - } - g_variant_iter_free(iter_row); - } - g_variant_iter_free(iter); - - event_data.event = STC_EVENT_RESTRICTION_LOAD_LIST_RSP; - event_data.info_data = g_restriction_load_list; - event_data.datalength = 0; - event_data.error = dbus_result; - } else { - STC_LOGE("Load restriction list response error [%s]", - _stc_convert_error_type_to_string(error)); - - event_data.event = STC_EVENT_RESTRICTION_LOAD_LIST_RSP; - event_data.info_data = NULL; - event_data.datalength = 0; - event_data.error = error; - } - - _stc_event_add_client_idle_cb(&event_data, user_data); -} - -static void __stc_restriction_load_rule_from_list_reply( - GObject *source_object, GAsyncResult *res, gpointer user_data) -{ - GDBusConnection *conn = NULL; - GError *dbus_error = NULL; - GVariant *dbus_data = NULL; - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - stc_error_e dbus_result = STC_ERROR_NONE; - stc_error_e error = STC_ERROR_NONE; - stc_restriction_rule_s *restriction_rule = NULL; - stc_event_info_s event_data = { 0, }; - stc_restriction_list_h list_h = (stc_restriction_list_h)user_data; - - conn = G_DBUS_CONNECTION(source_object); - dbus_data = g_dbus_connection_call_finish(conn, res, &dbus_error); - if (dbus_error != NULL) { - error = _stc_convert_error_string_to_enum(dbus_error->message); - g_error_free(dbus_error); - } - - if (_stc_event_get_request_table_state(STC_REQUEST_TABLE_RESTRICTION_LOAD_RULE_FROM_LIST)) - _stc_event_set_request_table_state(STC_REQUEST_TABLE_RESTRICTION_LOAD_RULE_FROM_LIST, false); - - if (error == STC_ERROR_NONE) { - g_variant_get(dbus_data, "(iaa{sv})", &dbus_result, &iter); - - _stc_restriction_flush_rule_from_list(list_h); - - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - restriction_rule = g_try_malloc0(sizeof(stc_restriction_rule_s)); - if (restriction_rule) { - _stc_dbus_dictionary_foreach(iter_row, - __stc_restriction_extract_rule_cb, restriction_rule); - - __stc_restriction_print_rule(restriction_rule); - - _stc_restriction_add_rule(restriction_rule); - _stc_restriction_add_rule_to_list(list_h, restriction_rule); - } - g_variant_iter_free(iter_row); - } - g_variant_iter_free(iter); - - event_data.event = STC_EVENT_RESTRICTION_LOAD_RULE_FROM_LIST_RSP; - event_data.info_data = list_h; - event_data.datalength = 0; - event_data.error = dbus_result; - } else { - STC_LOGE("Load restriction rule from list response error [%s]", - _stc_convert_error_type_to_string(error)); - - event_data.event = STC_EVENT_RESTRICTION_LOAD_RULE_FROM_LIST_RSP; - event_data.info_data = NULL; - event_data.datalength = 0; - event_data.error = error; - } - - _stc_event_add_client_idle_cb(&event_data, user_data); -} - -static void __stc_restriction_load_rule_from_list(stc_restriction_list_h list_h) -{ - stc_event_info_s event_data = { 0, }; - - event_data.event = STC_EVENT_RESTRICTION_LOAD_RULE_FROM_LIST_RSP; - event_data.info_data = list_h; - event_data.datalength = 0; - event_data.error = STC_ERROR_NONE; - - _stc_event_add_client_idle_cb(&event_data, NULL); -} - static void __stc_restriction_get_per_app_id_reply( GObject *source_object, GAsyncResult *res, gpointer user_data) { @@ -751,64 +557,60 @@ bool _stc_restriction_check_rule_validity(stc_restriction_rule_h rule) } bool _stc_restriction_add_rule_to_list(stc_restriction_list_h list_h, - stc_restriction_rule_h rule) + stc_restriction_rule_h rule_h) { GSList *find = g_slist_find(g_restriction_list, list_h); if (find) { stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - list_data->rules = g_slist_append(list_data->rules, rule); + list_data->rules = g_slist_append(list_data->rules, rule_h); return true; - } else { - find = g_slist_find(g_restriction_load_list, list_h); - if (find) { - stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - list_data->rules = g_slist_append(list_data->rules, rule); - return true; - } else { - return false; - } } + + return false; } bool _stc_restriction_remove_rule_from_list(stc_restriction_list_h list_h, - stc_restriction_rule_h rule) + stc_restriction_rule_h rule_h) { GSList *find = g_slist_find(g_restriction_list, list_h); if (find) { stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - list_data->rules = g_slist_remove(list_data->rules, rule); + list_data->rules = g_slist_remove(list_data->rules, rule_h); return true; - } else { - find = g_slist_find(g_restriction_load_list, list_h); - if (find) { - stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - list_data->rules = g_slist_remove(list_data->rules, rule); - return true; - } else { - return false; - } } + + return false; } -bool _stc_restriction_flush_rule_from_list(stc_restriction_list_h list_h) +stc_error_e _stc_restriction_foreach_rule_from_list(stc_restriction_list_h list_h, + stc_restriction_rule_cb rule_cb, void *user_data) { - GSList *find = g_slist_find(g_restriction_list, list_h); - if (find) { - stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - g_slist_foreach(list_data->rules, __stc_restriction_flush_rule, NULL); - list_data->rules = NULL; - return true; - } else { - find = g_slist_find(g_restriction_load_list, list_h); - if (find) { - stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - g_slist_foreach(list_data->rules, __stc_restriction_flush_rule, NULL); - list_data->rules = NULL; - return true; - } else { - return false; - } + int rv; + GSList *list; + GSList *find; + + find = g_slist_find(g_restriction_list, list_h); + if (!find) { + STC_LOGD("There is no restriction list"); + return STC_ERROR_INVALID_PARAMETER; + } + + stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; + if (g_slist_length(list_data->rules) == 0) { + STC_LOGD("There is no restriction rule from list"); + return STC_ERROR_NONE; + } + + for (list = list_data->rules; list; list = list->next) { + stc_restriction_rule_s *rule_data = (stc_restriction_rule_s *)list->data; + STC_LOGD("AppID[%s] ifname[%s] subid[%s] roaming[%u]", rule_data->app_id, + rule_data->iface_name, rule_data->subscriber_id, rule_data->roaming_type); + rv = rule_cb(STC_ERROR_NONE, (stc_restriction_rule_h)rule_data, user_data); + if (rv == false) + break; } + + return STC_ERROR_NONE; } void _stc_restriction_add_to_list(stc_restriction_list_h list_h) @@ -829,78 +631,28 @@ bool _stc_restriction_check_list_validity(stc_restriction_list_h list_h) if (g_slist_find(g_restriction_list, list_h)) return true; - else if (g_slist_find(g_restriction_load_list, list_h)) - return true; return false; } -bool _stc_restriction_check_rule_from_list(stc_restriction_list_h list_h) -{ - GSList *find = g_slist_find(g_restriction_list, list_h); - if (find) { - stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - if (list_data->rules) - return true; - else - return false; - } else { - find = g_slist_find(g_restriction_load_list, list_h); - if (find) { - stc_restriction_list_s *list_data = (stc_restriction_list_s *)find->data; - if (list_data->rules) - return true; - else - return false; - } else { - return false; - } - } -} - -GSList * _stc_restriction_get_load_list_handle(void) -{ - return g_restriction_load_list; -} - -void _stc_restriction_add_to_load_list(stc_restriction_list_h list_h) -{ - g_restriction_load_list = g_slist_append(g_restriction_load_list, list_h); -} - -void _stc_restriction_remove_from_load_list(stc_restriction_list_h list_h) -{ - g_restriction_load_list = g_slist_remove(g_restriction_load_list, list_h); - __stc_restriction_deinit_list(list_h); -} - -void _stc_restriction_clear_load_list(void) -{ - if (g_restriction_load_list) { - g_slist_free_full(g_restriction_load_list, __stc_restriction_deinit_list); - g_restriction_load_list = NULL; - } -} - -stc_error_e _stc_restriction_save_list(stc_restriction_list_h list_h) +stc_error_e _stc_restriction_set_list(stc_restriction_list_h list_h) { GVariant *message = NULL; GVariant *params = NULL; GVariantBuilder *builder = NULL; stc_error_e error = STC_ERROR_NONE; int result = 0; - stc_restriction_list_s *list_data = (stc_restriction_list_s *)list_h; builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")); __stc_restriction_list_foreach(list_h, builder); - params = g_variant_new("(saa{sv})", list_data->name, builder); + params = g_variant_new("(aa{sv})", builder); g_variant_builder_unref(builder); message = _stc_dbus_invoke_method( STC_MANAGER_SERVICE, STC_MANAGER_RESTRICTION_PATH, STC_MANAGER_RESTRICTION_INTERFACE, - STC_MANAGER_METHOD_RESTRICTION_SAVE_LIST, + STC_MANAGER_METHOD_RESTRICTION_SET_LIST, params, &error); @@ -908,93 +660,39 @@ stc_error_e _stc_restriction_save_list(stc_restriction_list_h list_h) error, "Failed to invoke dbus method"); g_variant_get(message, "(i)", &result); - STC_LOGI("Successfully save restriction list [%d]", result); + STC_LOGI("Successfully set restriction list [%d]", result); g_variant_unref(message); return STC_ERROR_NONE; } -stc_error_e _stc_restriction_load_list(void) -{ - stc_error_e error = STC_ERROR_NONE; - - STC_RETURN_VAL_IF(_stc_event_get_ref_count() < 1, - STC_ERROR_NOT_INITIALIZED, - "Event callback is not registered"); - - STC_RETURN_VAL_IF( - _stc_event_get_request_table_state( - STC_REQUEST_TABLE_RESTRICTION_LOAD_LIST), - STC_ERROR_IN_PROGRESS, - "Request in progress"); - - _stc_event_set_request_table_state( - STC_REQUEST_TABLE_RESTRICTION_LOAD_LIST, true); - - error = _stc_dbus_invoke_method_nonblock( - STC_MANAGER_SERVICE, - STC_MANAGER_RESTRICTION_PATH, - STC_MANAGER_RESTRICTION_INTERFACE, - STC_MANAGER_METHOD_RESTRICTION_LOAD_LIST, - NULL, - STC_DBUS_REPLY_TIMEOUT, - __stc_restriction_load_list_reply, - NULL); - - if (error != STC_ERROR_NONE) { - STC_LOGE("Failed to invoke dbus method nonblock"); - - _stc_event_set_request_table_state( - STC_REQUEST_TABLE_RESTRICTION_LOAD_LIST, false); - return error; - } - - return STC_ERROR_NONE; -} - -stc_error_e _stc_restriction_load_rule_from_list(stc_restriction_list_h list, - stc_restriction_rule_cb rule_cb, void *user_data) +stc_error_e _stc_restriction_unset_list(stc_restriction_list_h list_h) { + GVariant *message = NULL; GVariant *params = NULL; + GVariantBuilder *builder = NULL; stc_error_e error = STC_ERROR_NONE; + int result = 0; - STC_RETURN_VAL_IF(_stc_event_get_ref_count() < 1, - STC_ERROR_NOT_INITIALIZED, - "Event callback is not registered"); - - STC_RETURN_VAL_IF( - _stc_event_get_request_table_state( - STC_REQUEST_TABLE_RESTRICTION_LOAD_RULE_FROM_LIST), - STC_ERROR_IN_PROGRESS, - "Request in progress"); - - if (_stc_restriction_check_rule_from_list(list) == true) { - __stc_restriction_load_rule_from_list(list); - return STC_ERROR_NONE; - } - - _stc_event_set_request_table_state( - STC_REQUEST_TABLE_RESTRICTION_LOAD_RULE_FROM_LIST, true); - - __stc_restriction_load_rule_from_list_params(list, ¶ms); + builder = g_variant_builder_new(G_VARIANT_TYPE("aa{sv}")); + __stc_restriction_list_foreach(list_h, builder); + params = g_variant_new("(aa{sv})", builder); + g_variant_builder_unref(builder); - error = _stc_dbus_invoke_method_nonblock( + message = _stc_dbus_invoke_method( STC_MANAGER_SERVICE, STC_MANAGER_RESTRICTION_PATH, STC_MANAGER_RESTRICTION_INTERFACE, - STC_MANAGER_METHOD_RESTRICTION_LOAD_RULE_FROM_LIST, + STC_MANAGER_METHOD_RESTRICTION_UNSET_LIST, params, - STC_DBUS_REPLY_TIMEOUT, - __stc_restriction_load_rule_from_list_reply, - list); + &error); - if (error != STC_ERROR_NONE) { - STC_LOGE("Failed to invoke dbus method nonblock"); + STC_RETURN_VAL_IF(message == NULL, + error, "Failed to invoke dbus method"); - _stc_event_set_request_table_state( - STC_REQUEST_TABLE_RESTRICTION_LOAD_RULE_FROM_LIST, false); - return error; - } + g_variant_get(message, "(i)", &result); + STC_LOGI("Successfully unset restriction list [%d]", result); + g_variant_unref(message); return STC_ERROR_NONE; } @@ -2000,12 +1698,17 @@ EXPORT_API int stc_restriction_rule_get_subscriber_id(stc_restriction_rule_h rul return STC_ERROR_NONE; } -EXPORT_API int stc_restriction_list_create(const char *name, +EXPORT_API int stc_restriction_list_create(stc_h stc, stc_restriction_list_h *list_h) { CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - if (list_h == NULL || name == NULL) { + if (!(_stc_handle_check_validity(stc))) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; + } + + if (list_h == NULL) { STC_LOGE("Invalid parameter"); return STC_ERROR_INVALID_PARAMETER; } @@ -2017,11 +1720,11 @@ EXPORT_API int stc_restriction_list_create(const char *name, return STC_ERROR_OUT_OF_MEMORY; } - __stc_restriction_init_list(restriction_list, name); + __stc_restriction_init_list(restriction_list); _stc_restriction_add_to_list((stc_restriction_list_h)restriction_list); *list_h = (stc_restriction_list_h)restriction_list; - STC_LOGI("Restriction list successfully created [%s]", name); + STC_LOGI("Restriction list successfully created"); return STC_ERROR_NONE; } @@ -2030,7 +1733,7 @@ EXPORT_API int stc_restriction_list_destroy(stc_restriction_list_h list_h) { CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - if (__stc_restriction_check_list_validity(list_h) == false) { + if (_stc_restriction_check_list_validity(list_h) == false) { STC_LOGE("Invalid parameter"); return STC_ERROR_INVALID_PARAMETER; } diff --git a/test/restriction.c b/test/restriction.c index 2adca92..bc0636a 100755 --- a/test/restriction.c +++ b/test/restriction.c @@ -55,8 +55,12 @@ static char g_daily_limit[MENU_DATA_SIZE] = "-1"; static char g_month_start_date[MENU_DATA_SIZE] = "1"; static char g_rstn_type[MENU_DATA_SIZE] = "1"; +static char g_rstn_rule_index[MENU_DATA_SIZE] = "0"; + extern stc_h g_stc; -static stc_restriction_rule_h g_restriction_rule = NULL; +static stc_restriction_rule_h g_restriction_rule_h = NULL; +static stc_restriction_list_h g_restriction_list_h = NULL; +static int g_restriction_rule_index = 0; static stc_callback_ret_e __test_stc_restriction_rule_cb( stc_error_e result, stc_restriction_rule_h rule, void *user_data) @@ -82,6 +86,7 @@ static stc_callback_ret_e __test_stc_restriction_rule_cb( stc_roaming_type_e roaming; msg(HR_SINGLE); + msg("Index: " LOG_CYAN "[%d]" LOG_END, g_restriction_rule_index++); ret = stc_restriction_rule_get_app_id(rule, &app_id); if (ret == STC_ERROR_NONE) @@ -140,6 +145,27 @@ static stc_callback_ret_e __test_stc_restriction_rule_cb( return STC_CALLBACK_CONTINUE; } +static stc_callback_ret_e __test_stc_restriction_remove_rule_cb( + stc_error_e result, stc_restriction_rule_h rule, void *user_data) +{ + int ret = STC_ERROR_NONE; + int *rule_index = (int *)user_data; + + if (g_restriction_rule_index != *rule_index) { + g_restriction_rule_index++; + return STC_CALLBACK_CONTINUE; + } + + ret = stc_remove_restriction_rule_from_list(g_restriction_list_h, rule); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to remove restriction rule from list" LOG_END); + else + msg("Fail to remove restriction rule from list " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + return STC_CALLBACK_CANCEL; +} + static void __test_stc_warn_threshold_crossed_cb(stc_restriction_rule_h rule, void *user_data) { @@ -188,7 +214,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) stc_restriction_type_e type = (int)strtol(g_rstn_type, NULL, 10); int ret = STC_ERROR_NONE; - ret = stc_restriction_rule_set_app_id(g_restriction_rule, g_app_id); + ret = stc_restriction_rule_set_app_id(g_restriction_rule_h, g_app_id); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to set application ID" LOG_END); else { @@ -198,7 +224,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } if (iface_type > STC_IFACE_UNKNOWN && iface_type <= STC_IFACE_ALL) { - ret = stc_restriction_rule_set_iface_type(g_restriction_rule, iface_type); + ret = stc_restriction_rule_set_iface_type(g_restriction_rule_h, iface_type); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to set interface type" LOG_END); else { @@ -208,7 +234,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } } - ret = stc_restriction_rule_set_iface_name(g_restriction_rule, g_iface_name); + ret = stc_restriction_rule_set_iface_name(g_restriction_rule_h, g_iface_name); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to set interface name" LOG_END); else { @@ -218,7 +244,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } if (roaming <= STC_ROAMING_ENABLED) { - ret = stc_restriction_rule_set_roaming_type(g_restriction_rule, roaming); + ret = stc_restriction_rule_set_roaming_type(g_restriction_rule_h, roaming); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to set roaming type" LOG_END); else { @@ -228,7 +254,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } } - ret = stc_restriction_rule_set_subscriber_id(g_restriction_rule, g_subscriber_id); + ret = stc_restriction_rule_set_subscriber_id(g_restriction_rule_h, g_subscriber_id); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to set subscriber ID" LOG_END); else { @@ -238,7 +264,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } if (data_limit >= 0 && data_limit < G_MAXINT64) { - ret = stc_restriction_rule_set_limit(g_restriction_rule, + ret = stc_restriction_rule_set_limit(g_restriction_rule_h, data_limit); if (ret == STC_ERROR_NONE) { msg(LOG_GREEN "Success to set limit" LOG_END); @@ -250,7 +276,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } if (data_warn_limit >= 0 && data_warn_limit < G_MAXINT64) { - ret = stc_restriction_rule_set_warning_limit(g_restriction_rule, + ret = stc_restriction_rule_set_warning_limit(g_restriction_rule_h, data_warn_limit); if (ret == STC_ERROR_NONE) { msg(LOG_GREEN "Success to set warning limit" LOG_END); @@ -262,7 +288,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } if (monthly_limit >= 0 && monthly_limit < G_MAXINT64) { - ret = stc_restriction_rule_set_monthly_limit(g_restriction_rule, + ret = stc_restriction_rule_set_monthly_limit(g_restriction_rule_h, monthly_limit); if (ret == STC_ERROR_NONE) { msg(LOG_GREEN "Success to set monthly limit" LOG_END); @@ -274,7 +300,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } if (weekly_limit >= 0 && weekly_limit < G_MAXINT64) { - ret = stc_restriction_rule_set_weekly_limit(g_restriction_rule, + ret = stc_restriction_rule_set_weekly_limit(g_restriction_rule_h, weekly_limit); if (ret == STC_ERROR_NONE) { msg(LOG_GREEN "Success to set weekly limit" LOG_END); @@ -286,7 +312,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } if (daily_limit >= 0 && daily_limit < G_MAXINT64) { - ret = stc_restriction_rule_set_daily_limit(g_restriction_rule, + ret = stc_restriction_rule_set_daily_limit(g_restriction_rule_h, daily_limit); if (ret == STC_ERROR_NONE) { msg(LOG_GREEN "Success to set daily limit" LOG_END); @@ -298,7 +324,7 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) } if (month_start_date >= 0 && month_start_date < 32) { - ret = stc_restriction_rule_set_month_start_date(g_restriction_rule, + ret = stc_restriction_rule_set_month_start_date(g_restriction_rule_h, month_start_date); if (ret == STC_ERROR_NONE) { msg(LOG_GREEN "Success to set month start date" LOG_END); @@ -310,7 +336,7 @@ 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); + ret = stc_restriction_rule_set_type(g_restriction_rule_h, type); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to set type" LOG_END); else { @@ -322,67 +348,67 @@ static int __test_stc_set_restriction_rule(MManager *mm, struct menu_data *menu) msg(HR_SINGLE); - ret = stc_restriction_rule_get_app_id(g_restriction_rule, &app_id); + ret = stc_restriction_rule_get_app_id(g_restriction_rule_h, &app_id); if (ret == STC_ERROR_NONE) { msg("App_id: " LOG_CYAN "[%s]" LOG_END, app_id); g_free(app_id); } - ret = stc_restriction_rule_get_subscriber_id(g_restriction_rule, &subscriber_id); + ret = stc_restriction_rule_get_subscriber_id(g_restriction_rule_h, &subscriber_id); if (ret == STC_ERROR_NONE) { msg("Sub_id: " LOG_CYAN "[%s]" LOG_END, subscriber_id); g_free(subscriber_id); } - ret = stc_restriction_rule_get_iface_type(g_restriction_rule, &iface_type); + ret = stc_restriction_rule_get_iface_type(g_restriction_rule_h, &iface_type); if (ret == STC_ERROR_NONE) msg("Iftype: " LOG_CYAN "[%s]" LOG_END, test_stc_convert_iface_type_to_string(iface_type)); - ret = stc_restriction_rule_get_iface_name(g_restriction_rule, &iface_name); + ret = stc_restriction_rule_get_iface_name(g_restriction_rule_h, &iface_name); if (ret == STC_ERROR_NONE) { msg("Ifname: " LOG_CYAN "[%s]" LOG_END, iface_name); g_free(iface_name); } - ret = stc_restriction_rule_get_roaming_type(g_restriction_rule, &roaming); + ret = stc_restriction_rule_get_roaming_type(g_restriction_rule_h, &roaming); if (ret == STC_ERROR_NONE) msg("Roaming: " LOG_CYAN "[%s]" LOG_END, test_stc_convert_roaming_to_string(roaming)); - ret = stc_restriction_rule_get_type(g_restriction_rule, &type); + ret = stc_restriction_rule_get_type(g_restriction_rule_h, &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); + ret = stc_restriction_rule_get_limit(g_restriction_rule_h, &data_limit); if (ret == STC_ERROR_NONE) msg("Data limit: " LOG_CYAN "[%lld]" LOG_END, data_limit); data_warn_limit = 0; - ret = stc_restriction_rule_get_warning_limit(g_restriction_rule, + ret = stc_restriction_rule_get_warning_limit(g_restriction_rule_h, &data_warn_limit); if (ret == STC_ERROR_NONE) msg("Warn limit: " LOG_CYAN "[%lld]" LOG_END, data_warn_limit); monthly_limit = 0; - ret = stc_restriction_rule_get_monthly_limit(g_restriction_rule, &monthly_limit); + ret = stc_restriction_rule_get_monthly_limit(g_restriction_rule_h, &monthly_limit); if (ret == STC_ERROR_NONE) msg("Monthly limit: " LOG_CYAN "[%lld]" LOG_END, monthly_limit); weekly_limit = 0; - ret = stc_restriction_rule_get_weekly_limit(g_restriction_rule, &weekly_limit); + ret = stc_restriction_rule_get_weekly_limit(g_restriction_rule_h, &weekly_limit); if (ret == STC_ERROR_NONE) msg("Weekly limit: " LOG_CYAN "[%lld]" LOG_END, weekly_limit); daily_limit = 0; - ret = stc_restriction_rule_get_daily_limit(g_restriction_rule, &daily_limit); + ret = stc_restriction_rule_get_daily_limit(g_restriction_rule_h, &daily_limit); if (ret == STC_ERROR_NONE) msg("Daily limit: " LOG_CYAN "[%lld]" LOG_END, daily_limit); month_start_date = 0; - ret = stc_restriction_rule_get_month_start_date(g_restriction_rule, &month_start_date); + ret = stc_restriction_rule_get_month_start_date(g_restriction_rule_h, &month_start_date); if (ret == STC_ERROR_NONE) msg("Month start date: " LOG_CYAN "[%d]" LOG_END, month_start_date); @@ -395,7 +421,7 @@ static int __test_stc_restriction_set(MManager *mm, struct menu_data *menu) { int ret = STC_ERROR_NONE; - ret = stc_set_restriction(g_stc, g_restriction_rule); + ret = stc_set_restriction(g_stc, g_restriction_rule_h); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to set restriction" LOG_END); @@ -410,8 +436,10 @@ static int __test_stc_restriction_get(MManager *mm, struct menu_data *menu) { int ret = STC_ERROR_NONE; + g_restriction_rule_index = 0; + ret = stc_get_restriction(g_stc, - g_restriction_rule, + g_restriction_rule_h, __test_stc_restriction_rule_cb, NULL); @@ -428,8 +456,10 @@ static int __test_stc_restriction_get_all(MManager *mm, struct menu_data *menu) { int ret = STC_ERROR_NONE; + g_restriction_rule_index = 0; + ret = stc_foreach_restriction(g_stc, - g_restriction_rule, + g_restriction_rule_h, __test_stc_restriction_rule_cb, NULL); @@ -447,7 +477,7 @@ static int __test_stc_restriction_get_type(MManager *mm, struct menu_data *menu) int ret = STC_ERROR_NONE; stc_restriction_type_e rstn_type; - ret = stc_get_restriction_type(g_stc, g_restriction_rule, &rstn_type); + ret = stc_get_restriction_type(g_stc, g_restriction_rule_h, &rstn_type); if (ret == STC_ERROR_NONE) { msg("Restriction type " LOG_CYAN "[%s]" LOG_END, @@ -465,7 +495,7 @@ static int __test_stc_restriction_unset(MManager *mm, struct menu_data *menu) int ret = STC_ERROR_NONE; ret = stc_unset_restriction(g_stc, - g_restriction_rule); + g_restriction_rule_h); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to unset restriction" LOG_END); @@ -478,7 +508,7 @@ static int __test_stc_restriction_unset(MManager *mm, struct menu_data *menu) int test_stc_restriction_rule_create(void) { - int ret = stc_restriction_rule_create(g_stc, &g_restriction_rule); + int ret = stc_restriction_rule_create(g_stc, &g_restriction_rule_h); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to create restriction rule" LOG_END); @@ -493,8 +523,8 @@ int test_stc_restriction_rule_destroy(void) { int ret = STC_ERROR_NONE; - if (g_restriction_rule) { - ret = stc_restriction_rule_destroy(g_restriction_rule); + if (g_restriction_rule_h) { + ret = stc_restriction_rule_destroy(g_restriction_rule_h); if (ret == STC_ERROR_NONE) msg(LOG_GREEN "Success to destroy restriction rule" LOG_END); @@ -506,6 +536,37 @@ int test_stc_restriction_rule_destroy(void) return ret; } +int test_stc_restriction_list_create(void) +{ + int ret = stc_restriction_list_create(g_stc, &g_restriction_list_h); + + if (ret == STC_ERROR_NONE) { + msg(LOG_GREEN "Success to create restriction list" LOG_END); + } else { + msg("Fail to create restriction rule " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + } + + return ret; +} + +int test_stc_restriction_list_destroy(void) +{ + int ret = STC_ERROR_NONE; + + if (g_restriction_list_h) { + ret = stc_restriction_list_destroy(g_restriction_list_h); + + if (ret == STC_ERROR_NONE) { + msg(LOG_GREEN "Success to destroy restriction list" LOG_END); + } else + msg("Fail to destroy restriction list " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + } + + return ret; +} + int test_stc_restriction_register_cb(void) { int ret = stc_set_warn_threshold_crossed_cb(g_stc, @@ -550,7 +611,312 @@ int test_stc_restriction_unregister_cb(void) return ret; } -static struct menu_data menu_restriction_rule[] = { +static int __test_stc_restriction_list_add_rule(MManager *mm, struct menu_data *menu) +{ + stc_iface_type_e iface_type = (int)strtol(g_iface_type, NULL, 10); + stc_roaming_type_e roaming = (int)strtol(g_roaming, NULL, 10); + long long int data_limit = (long long int)strtol(g_data_limit, NULL, 10); + long long int data_warn_limit = (long long int)strtol(g_data_warn_limit, NULL, 10); + long long int monthly_limit = (long long int)strtol(g_monthly_limit, NULL, 10); + long long int weekly_limit = (long long int)strtol(g_weekly_limit, NULL, 10); + long long int daily_limit = (long long int)strtol(g_daily_limit, NULL, 10); + int month_start_date = (int)strtol(g_month_start_date, NULL, 10); + char *app_id = NULL; + char *subscriber_id = NULL; + char *iface_name = NULL; + stc_restriction_type_e type = (int)strtol(g_rstn_type, NULL, 10); + int ret = STC_ERROR_NONE; + stc_restriction_rule_h rule_h = NULL; + + ret = stc_restriction_rule_create(g_stc, &rule_h); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to create restriction rule" LOG_END); + else { + msg("Fail to create restriction rule " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + + ret = stc_restriction_rule_set_app_id(rule_h, g_app_id); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to set application ID" LOG_END); + else { + msg("Fail to set application ID " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + + if (iface_type > STC_IFACE_UNKNOWN && iface_type <= STC_IFACE_ALL) { + ret = stc_restriction_rule_set_iface_type(rule_h, iface_type); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to set interface type" LOG_END); + else { + msg("Fail to set interface type " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + + ret = stc_restriction_rule_set_iface_name(rule_h, g_iface_name); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to set interface name" LOG_END); + else { + msg("Fail to set interface name " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + + if (roaming <= STC_ROAMING_ENABLED) { + ret = stc_restriction_rule_set_roaming_type(rule_h, roaming); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to set roaming type" LOG_END); + else { + msg("Fail to set roaming type " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + + ret = stc_restriction_rule_set_subscriber_id(rule_h, g_subscriber_id); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to set subscriber ID" LOG_END); + else { + msg("Fail to set subscriber ID " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + + if (data_limit >= 0 && data_limit < G_MAXINT64) { + ret = stc_restriction_rule_set_limit(rule_h, + data_limit); + if (ret == STC_ERROR_NONE) { + msg(LOG_GREEN "Success to set limit" LOG_END); + } else { + msg("Fail to set limit " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + + if (data_warn_limit >= 0 && data_warn_limit < G_MAXINT64) { + ret = stc_restriction_rule_set_warning_limit(rule_h, + data_warn_limit); + if (ret == STC_ERROR_NONE) { + msg(LOG_GREEN "Success to set warning limit" LOG_END); + } else { + msg("Fail to set warning limit " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + + if (monthly_limit >= 0 && monthly_limit < G_MAXINT64) { + ret = stc_restriction_rule_set_monthly_limit(rule_h, + monthly_limit); + if (ret == STC_ERROR_NONE) { + msg(LOG_GREEN "Success to set monthly limit" LOG_END); + } else { + msg("Fail to set monthly limit " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + + if (weekly_limit >= 0 && weekly_limit < G_MAXINT64) { + ret = stc_restriction_rule_set_weekly_limit(rule_h, + weekly_limit); + if (ret == STC_ERROR_NONE) { + msg(LOG_GREEN "Success to set weekly limit" LOG_END); + } else { + msg("Fail to set weekly limit " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + + if (daily_limit >= 0 && daily_limit < G_MAXINT64) { + ret = stc_restriction_rule_set_daily_limit(rule_h, + daily_limit); + if (ret == STC_ERROR_NONE) { + msg(LOG_GREEN "Success to set daily limit" LOG_END); + } else { + msg("Fail to set daily limit " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + + if (month_start_date >= 0 && month_start_date < 32) { + ret = stc_restriction_rule_set_month_start_date(rule_h, + month_start_date); + if (ret == STC_ERROR_NONE) { + msg(LOG_GREEN "Success to set month start date" LOG_END); + } else { + msg("Fail to set month start date " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + return ret; + } + } + + if (type > STC_RSTN_TYPE_UNKNOWN && type < STC_RSTN_TYPE_LAST_ELEM) { + ret = stc_restriction_rule_set_type(rule_h, 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; + } + } + + ret = stc_add_restriction_rule_to_list(g_restriction_list_h, rule_h); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to add rule to list" LOG_END); + else { + msg("Fail to add rule to list " 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(rule_h, &app_id); + if (ret == STC_ERROR_NONE) { + msg("App_id: " LOG_CYAN "[%s]" LOG_END, app_id); + g_free(app_id); + } + + ret = stc_restriction_rule_get_subscriber_id(rule_h, &subscriber_id); + if (ret == STC_ERROR_NONE) { + msg("Sub_id: " LOG_CYAN "[%s]" LOG_END, subscriber_id); + g_free(subscriber_id); + } + + ret = stc_restriction_rule_get_iface_type(rule_h, &iface_type); + if (ret == STC_ERROR_NONE) + msg("Iftype: " LOG_CYAN "[%s]" LOG_END, + test_stc_convert_iface_type_to_string(iface_type)); + + ret = stc_restriction_rule_get_iface_name(rule_h, &iface_name); + if (ret == STC_ERROR_NONE) { + msg("Ifname: " LOG_CYAN "[%s]" LOG_END, iface_name); + g_free(iface_name); + } + + ret = stc_restriction_rule_get_roaming_type(rule_h, &roaming); + if (ret == STC_ERROR_NONE) + msg("Roaming: " LOG_CYAN "[%s]" LOG_END, + test_stc_convert_roaming_to_string(roaming)); + + ret = stc_restriction_rule_get_type(rule_h, &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(rule_h, &data_limit); + if (ret == STC_ERROR_NONE) + msg("Data limit: " LOG_CYAN "[%lld]" LOG_END, data_limit); + + data_warn_limit = 0; + ret = stc_restriction_rule_get_warning_limit(rule_h, + &data_warn_limit); + if (ret == STC_ERROR_NONE) + msg("Warn limit: " LOG_CYAN "[%lld]" LOG_END, data_warn_limit); + + monthly_limit = 0; + ret = stc_restriction_rule_get_monthly_limit(rule_h, &monthly_limit); + if (ret == STC_ERROR_NONE) + msg("Monthly limit: " LOG_CYAN "[%lld]" LOG_END, monthly_limit); + + weekly_limit = 0; + ret = stc_restriction_rule_get_weekly_limit(rule_h, &weekly_limit); + if (ret == STC_ERROR_NONE) + msg("Weekly limit: " LOG_CYAN "[%lld]" LOG_END, weekly_limit); + + daily_limit = 0; + ret = stc_restriction_rule_get_daily_limit(rule_h, &daily_limit); + if (ret == STC_ERROR_NONE) + msg("Daily limit: " LOG_CYAN "[%lld]" LOG_END, daily_limit); + + month_start_date = 0; + ret = stc_restriction_rule_get_month_start_date(rule_h, &month_start_date); + if (ret == STC_ERROR_NONE) + msg("Month start date: " LOG_CYAN "[%d]" LOG_END, month_start_date); + + msg(HR_SINGLE); + + return STC_ERROR_NONE; +} + +static int __test_stc_restriction_list_remove_rule(MManager *mm, struct menu_data *menu) +{ + int ret = STC_ERROR_NONE; + int rule_index = (unsigned int)strtol(g_rstn_rule_index, NULL, 10); + + g_restriction_rule_index = 0; + + ret = stc_foreach_restriction_rule_from_list(g_restriction_list_h, + __test_stc_restriction_remove_rule_cb, &rule_index); + + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to get all restriction rule from list" LOG_END); + else + msg("Fail to get all restriction rule from list " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + return ret; +} + +static int __test_stc_restriction_list_get_all_rule(MManager *mm, struct menu_data *menu) +{ + int ret = STC_ERROR_NONE; + + g_restriction_rule_index = 0; + + ret = stc_foreach_restriction_rule_from_list(g_restriction_list_h, + __test_stc_restriction_rule_cb, NULL); + + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to get all restriction rule from list" LOG_END); + else + msg("Fail to get all restriction rule from list " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + return ret; +} + +static int __test_stc_restriction_list_set(MManager *mm, struct menu_data *menu) +{ + int ret = STC_ERROR_NONE; + + ret = stc_set_restriction_list(g_stc, g_restriction_list_h); + + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to set restriction list" LOG_END); + else + msg("Fail to set restriction list " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + return ret; +} + +static int __test_stc_restriction_list_unset(MManager *mm, struct menu_data *menu) +{ + int ret = STC_ERROR_NONE; + + ret = stc_unset_restriction_list(g_stc, g_restriction_list_h); + + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to unset restriction list" LOG_END); + else + msg("Fail to unset restriction list " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + return ret; +} + +static struct menu_data menu_restriction_rule_info[] = { { "1", "Application ID", NULL, NULL, g_app_id}, { "2", "Subscriber ID", NULL, NULL, g_subscriber_id}, { "3", "Interface type(1.Tel/2.Wifi/3.Wired/4.BT/5.All)", NULL, NULL, g_iface_type}, @@ -567,8 +933,8 @@ static struct menu_data menu_restriction_rule[] = { { NULL, NULL, }, }; -struct menu_data menu_restriction[] = { - { "1", LOG_LIGHTMAGENTA "[Set]" LOG_END " restriction rule", menu_restriction_rule, NULL, NULL}, +static struct menu_data menu_restriction_rule[] = { + { "1", LOG_LIGHTMAGENTA "[Set]" LOG_END " restriction rule", menu_restriction_rule_info, NULL, NULL}, { "2", LOG_LIGHTBLUE "[Get]" LOG_END " restriction", NULL, __test_stc_restriction_get, NULL}, { "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}, @@ -576,3 +942,41 @@ struct menu_data menu_restriction[] = { { "6", LOG_LIGHTMAGENTA "[Unset]" LOG_END " restriction", NULL, __test_stc_restriction_unset, NULL}, { NULL, NULL, }, }; + +static struct menu_data menu_restriction_list_add_rule[] = { + { "1", "Application ID", NULL, NULL, g_app_id}, + { "2", "Subscriber ID", NULL, NULL, g_subscriber_id}, + { "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(0.Disable/1.Enable)", NULL, NULL, g_roaming}, + { "6", "Type(1.Accept/2.Drop)", NULL, NULL, g_rstn_type}, + { "7", "Data limit", NULL, NULL, g_data_limit}, + { "8", "Warn limit", NULL, NULL, g_data_warn_limit}, + { "9", "Monthly limit", NULL, NULL, g_monthly_limit}, + { "10", "Weekly limit", NULL, NULL, g_weekly_limit}, + { "11", "Daily limit", NULL, NULL, g_daily_limit}, + { "12", "Month start date", NULL, NULL, g_month_start_date}, + { "a", LOG_LIGHTBLUE "[Add]" LOG_END, NULL, __test_stc_restriction_list_add_rule, NULL}, + { NULL, NULL, }, +}; + +static struct menu_data menu_restriction_list_remove_rule[] = { + { "1", "Rule index", NULL, NULL, g_rstn_rule_index}, + { "r", LOG_LIGHTBLUE "[Remove]" LOG_END, NULL, __test_stc_restriction_list_remove_rule, NULL}, + { NULL, NULL, }, +}; + +static struct menu_data menu_restriction_list[] = { + { "1", LOG_LIGHTBLUE "[Add]" LOG_END " rule to list", menu_restriction_list_add_rule, NULL, NULL}, + { "2", LOG_LIGHTMAGENTA "[Remove]" LOG_END " rule from list", menu_restriction_list_remove_rule, __test_stc_restriction_list_get_all_rule, NULL}, + { "3", LOG_LIGHTBLUE "[GetAll]" LOG_END " rule from list", NULL, __test_stc_restriction_list_get_all_rule, NULL}, + { "4", LOG_LIGHTMAGENTA "[Set]" LOG_END " list", NULL, __test_stc_restriction_list_set, NULL}, + { "5", LOG_LIGHTBLUE "[Unset]" LOG_END " list", NULL, __test_stc_restriction_list_unset, NULL}, + { NULL, NULL, }, +}; + +struct menu_data menu_restriction[] = { + { "1", LOG_LIGHTBLUE "[List]" LOG_END " restriction", menu_restriction_list, NULL, NULL}, + { "2", LOG_LIGHTBLUE "[Rule]" LOG_END " restriction", menu_restriction_rule, NULL, NULL}, + { NULL, NULL, }, +}; diff --git a/test/restriction.h b/test/restriction.h index 7991997..88cc188 100755 --- a/test/restriction.h +++ b/test/restriction.h @@ -33,6 +33,8 @@ *****************************************************************************/ int test_stc_restriction_rule_create(void); int test_stc_restriction_rule_destroy(void); +int test_stc_restriction_list_create(void); +int test_stc_restriction_list_destroy(void); int test_stc_restriction_register_cb(void); int test_stc_restriction_unregister_cb(void); diff --git a/test/stc_test.c b/test/stc_test.c index dae1b37..71d1694 100755 --- a/test/stc_test.c +++ b/test/stc_test.c @@ -371,6 +371,7 @@ static int __test_stc_initialize(MManager *mm, struct menu_data *menu) test_stc_reset_rule_create(); test_stc_stats_rule_create(); test_stc_restriction_rule_create(); + test_stc_restriction_list_create(); test_stc_restriction_register_cb(); test_stc_pcap_create(); @@ -386,6 +387,7 @@ static int __test_stc_deinitialize(void) test_stc_reset_rule_destroy(); test_stc_stats_rule_destroy(); test_stc_restriction_rule_destroy(); + test_stc_restriction_list_destroy(); test_stc_restriction_unregister_cb(); test_stc_pcap_destroy();