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] 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_rule_from_list(stc_h stc, stc_restriction_list_h list_h,
+ stc_restriction_rule_cb rule_cb, void *user_data);
+
+/**
* @brief Sets the restriction list.
* @since_tizen 5.5
* @privlevel platform
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);
-void _stc_restriction_add_list(stc_restriction_list_h list);
-void _stc_restriction_remove_list(stc_restriction_list_h list);
+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);
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_validate_rule(
stc_restriction_rule_h rule);
#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_IPTABLES_COMMIT "CommitIptables"
#define STC_MANAGER_METHOD_IP6TABLES_COMMIT "CommitIp6tables"
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,
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;
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;
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);
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) {
}
break;
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;
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)
{
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)
+{
+ 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;
+ }
+
+ if (_stc_restriction_check_list_validity(list_h) == false) {
+ STC_LOGE("Invalid parameter");
+ 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);
+ if (ret != STC_ERROR_NONE) {
+ STC_LOGE("Failed to request restriction rule from list [%s]",
+ _stc_convert_error_type_to_string(ret));
+ return ret;
+ }
+
+ return STC_ERROR_NONE;
+}
+
EXPORT_API int stc_iptables_commit(stc_h stc, const char *option,
int *err_num, char **err_str)
{
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)
}
}
+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)
{
_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)
{
}
}
+bool _stc_restriction_flush_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;
+ 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;
+ }
+ }
+}
+
void _stc_restriction_add_to_list(stc_restriction_list_h list_h)
{
g_restriction_list = g_slist_append(g_restriction_list, list_h);
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;
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)
+{
+ GVariant *params = NULL;
+ 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_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);
+
+ error = _stc_dbus_invoke_method_nonblock(
+ STC_MANAGER_SERVICE,
+ STC_MANAGER_RESTRICTION_PATH,
+ STC_MANAGER_RESTRICTION_INTERFACE,
+ STC_MANAGER_METHOD_RESTRICTION_LOAD_RULE_FROM_LIST,
+ params,
+ STC_DBUS_REPLY_TIMEOUT,
+ __stc_restriction_load_rule_from_list_reply,
+ list);
+
+ if (error != STC_ERROR_NONE) {
+ STC_LOGE("Failed to invoke dbus method nonblock");
+
+ _stc_event_set_request_table_state(
+ STC_REQUEST_TABLE_RESTRICTION_LOAD_RULE_FROM_LIST, false);
+ return error;
+ }
+
+ return STC_ERROR_NONE;
+}
+
stc_error_e _stc_restriction_validate_rule(
stc_restriction_rule_h rule)