/* DELETE statements */
#define DELETE_RESTRICTIONS "DELETE FROM restrictions " \
- " WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
+ " WHERE binpath = ? AND iftype = ? AND ifname = ? " \
+ " AND subscriber_id = ? AND roaming = ?"
/* SELECT statements */
#define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
- " iftype, rst_type, roaming, ifname, subscriber_id, " \
- " data_warn_limit, restriction_id FROM restrictions"
+ " iftype, rstn_type, roaming, ifname, subscriber_id, " \
+ " data_warn_limit, monthly_limit, weekly_limit, daily_limit, month_start_date, " \
+ " restriction_id FROM restrictions"
#define SELECT_RESTRICTIONS_PER_APP "SELECT binpath, data_limit, " \
- " iftype, rst_type, roaming, ifname, subscriber_id, " \
- " data_warn_limit, restriction_id " \
+ " iftype, rstn_type, roaming, ifname, subscriber_id, " \
+ " data_warn_limit, monthly_limit, weekly_limit, daily_limit, month_start_date, " \
+ " restriction_id " \
" FROM restrictions INDEXED BY restrictions_index " \
" WHERE binpath = ?"
-#define SELECT_RESTRICTION_STATE "SELECT rst_type " \
+#define SELECT_RESTRICTION_TYPE "SELECT rstn_type " \
" FROM restrictions INDEXED BY restrictions_index " \
" WHERE binpath = ? AND iftype = ?"
-#define SELECT_RESTRICTION_STATE_SUBSCRIBER_ID "SELECT rst_type " \
+#define SELECT_RESTRICTION_TYPE_SUBSCRIBER_ID "SELECT rstn_type " \
" FROM restrictions INDEXED BY restrictions_index " \
" WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
#define SELECT_RESTRICTION_ID "SELECT restriction_id FROM restrictions " \
" WHERE binpath = ? AND iftype = ? AND subscriber_id = ? AND " \
- " rst_type = ? AND roaming = ? AND ifname = ?"
+ " roaming = ? AND ifname = ?"
/* UPDATE statement */
#define UPDATE_NET_RESTRICTIONS "UPDATE restrictions " \
- " SET binpath = ?, data_limit = ?, iftype = ?, rst_type = ?, " \
- " roaming = ?, ifname = ?, subscriber_id = ?, data_warn_limit = ? " \
+ " SET binpath = ?, data_limit = ?, iftype = ?, rstn_type = ?, " \
+ " roaming = ?, ifname = ?, subscriber_id = ?, data_warn_limit = ?, " \
+ " monthly_limit = ?, weekly_limit = ?, daily_limit = ? " \
" WHERE restriction_id = ?"
/* INSERT statement */
#define INSERT_NET_RESTRICTIONS "INSERT INTO restrictions " \
- " (binpath, data_limit, iftype, rst_type, " \
- " roaming, ifname, subscriber_id, data_warn_limit) " \
- " VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
+ " (binpath, data_limit, iftype, rstn_type, " \
+ " roaming, ifname, subscriber_id, data_warn_limit, " \
+ " monthly_limit, weekly_limit, daily_limit, month_start_date) " \
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
static void __finalize_delete(void);
/* SELECT statements */
static sqlite3_stmt *select_restriction;
static sqlite3_stmt *select_restriction_per_app;
-static sqlite3_stmt *select_restriction_state;
-static sqlite3_stmt *select_restriction_state_subscriber_id;
+static sqlite3_stmt *select_restriction_type;
+static sqlite3_stmt *select_restriction_type_subscriber_id;
static sqlite3_stmt *select_restriction_id;
/* REPLACE statements */
PREPARE_SELECT(select_restriction, SELECT_RESTRICTIONS);
PREPARE_SELECT(select_restriction_per_app, SELECT_RESTRICTIONS_PER_APP);
- PREPARE_SELECT(select_restriction_state, SELECT_RESTRICTION_STATE);
- PREPARE_SELECT(select_restriction_state_subscriber_id, SELECT_RESTRICTION_STATE_SUBSCRIBER_ID);
+ PREPARE_SELECT(select_restriction_type, SELECT_RESTRICTION_TYPE);
+ PREPARE_SELECT(select_restriction_type_subscriber_id, SELECT_RESTRICTION_TYPE_SUBSCRIBER_ID);
PREPARE_SELECT(select_restriction_id, SELECT_RESTRICTION_ID);
initialized = 1;
FINALIZE(select_restriction);
FINALIZE(select_restriction_per_app);
- FINALIZE(select_restriction_state);
- FINALIZE(select_restriction_state_subscriber_id);
+ FINALIZE(select_restriction_type);
+ FINALIZE(select_restriction_type_subscriber_id);
FINALIZE(select_restriction_id);
__STC_LOG_FUNC_EXIT__;
data.app_id = (char *)sqlite3_column_text(stmt, 0);
data.data_limit = sqlite3_column_int64(stmt, 1);
data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
- data.rst_type =
+ data.rstn_type =
(stc_rstn_type_e)sqlite3_column_int(stmt, 3);
data.roaming = sqlite3_column_int(stmt, 4);
data.ifname = (char *)sqlite3_column_text(stmt, 5);
data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
data.data_warn_limit = sqlite3_column_int64(stmt, 7);
- data.restriction_id = sqlite3_column_int64(stmt, 8);
+ data.monthly_limit = sqlite3_column_int64(stmt, 8);
+ data.weekly_limit = sqlite3_column_int64(stmt, 9);
+ data.daily_limit = sqlite3_column_int64(stmt, 10);
+ data.restriction_id = sqlite3_column_int64(stmt, 11);
if (restriction_cb(&data, user_data) == STC_CANCEL)
rc = SQLITE_DONE; //LCOV_EXCL_LINE
data.app_id = (char *)sqlite3_column_text(stmt, 0);
data.data_limit = sqlite3_column_int64(stmt, 1);
data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
- data.rst_type =
+ data.rstn_type =
(stc_rstn_type_e)sqlite3_column_int(stmt, 3);
data.roaming = sqlite3_column_int(stmt, 4);
data.ifname = (char *)sqlite3_column_text(stmt, 5);
data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
data.data_warn_limit = sqlite3_column_int64(stmt, 7);
- data.restriction_id = sqlite3_column_int64(stmt, 8);
+ data.monthly_limit = sqlite3_column_int64(stmt, 8);
+ data.weekly_limit = sqlite3_column_int64(stmt, 9);
+ data.daily_limit = sqlite3_column_int64(stmt, 10);
+ data.month_start_date = sqlite3_column_int(stmt, 11);
+ data.restriction_id = sqlite3_column_int64(stmt, 12);
if (restriction_cb(&data, user_data) == STC_CANCEL)
rc = SQLITE_DONE; //LCOV_EXCL_LINE
return error_code;
}
-stc_error_e table_restrictions_get_restriction_state_subscriber_id(const char *app_id,
+stc_error_e table_restrictions_get_restriction_type_subscriber_id(const char *app_id,
stc_iface_type_e iftype,
const char *subscriber_id,
- stc_restriction_state_e *state)
+ stc_rstn_type_e *type)
{
__STC_LOG_FUNC_ENTER__;
int error_code = STC_ERROR_NONE;
int ret;
bool state_subscriber_id = 0;
- if (state == NULL) {
+ if (type == NULL) {
STC_LOGE("Please provide valid argument!"); //LCOV_EXCL_LINE
__STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
- *state = STC_RESTRICTION_UNKNOWN;
- sqlite3_reset(select_restriction_state_subscriber_id);
- sqlite3_reset(select_restriction_state);
+ *type = STC_RSTN_TYPE_UNKNOWN;
+ sqlite3_reset(select_restriction_type_subscriber_id);
+ sqlite3_reset(select_restriction_type);
if (subscriber_id == NULL) {
state_subscriber_id = 0;
- DB_ACTION(sqlite3_bind_text(select_restriction_state, 1,
+ DB_ACTION(sqlite3_bind_text(select_restriction_type, 1,
app_id ? app_id : "", -1,
SQLITE_STATIC));
- DB_ACTION(sqlite3_bind_int(select_restriction_state, 2,
+ DB_ACTION(sqlite3_bind_int(select_restriction_type, 2,
iftype));
- ret = sqlite3_step(select_restriction_state);
+ ret = sqlite3_step(select_restriction_type);
} else {
state_subscriber_id = 1;
- DB_ACTION(sqlite3_bind_text(select_restriction_state_subscriber_id, 1,
+ DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 1,
app_id ? app_id : "", -1,
SQLITE_STATIC));
- DB_ACTION(sqlite3_bind_int(select_restriction_state_subscriber_id, 2,
+ DB_ACTION(sqlite3_bind_int(select_restriction_type_subscriber_id, 2,
iftype));
- DB_ACTION(sqlite3_bind_text(select_restriction_state_subscriber_id, 3,
+ DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 3,
subscriber_id, -1, SQLITE_STATIC));
- ret = sqlite3_step(select_restriction_state_subscriber_id);
+ ret = sqlite3_step(select_restriction_type_subscriber_id);
}
switch (ret) {
break;
case SQLITE_ROW:
if (state_subscriber_id)
- *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state_subscriber_id, 0);
+ *type = (stc_rstn_type_e)sqlite3_column_int(select_restriction_type_subscriber_id, 0);
else
- *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state, 0);
+ *type = (stc_rstn_type_e)sqlite3_column_int(select_restriction_type, 0);
break;
case SQLITE_ERROR:
default:
- STC_LOGE("Can't perform sql query: %s \n%s", //LCOV_EXCL_LINE
- SELECT_RESTRICTION_STATE,
+ STC_LOGE("Can't perform sql query: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
handle_error:
- sqlite3_reset(select_restriction_state);
- sqlite3_reset(select_restriction_state_subscriber_id);
+ sqlite3_reset(select_restriction_type);
+ sqlite3_reset(select_restriction_type_subscriber_id);
return error_code;
}
-stc_error_e table_restrictions_get_restriction_state(const char *app_id,
+stc_error_e table_restrictions_get_restriction_type(const char *app_id,
stc_iface_type_e iftype,
- stc_restriction_state_e *state)
+ stc_rstn_type_e *type)
{
__STC_LOG_FUNC_ENTER__;
__STC_LOG_FUNC_EXIT__;
- return table_restrictions_get_restriction_state_subscriber_id(app_id, iftype,
- NULL, state);
+ return table_restrictions_get_restriction_type_subscriber_id(app_id, iftype,
+ NULL, type);
}
stc_error_e table_restrictions_delete(const char *app_id,
const stc_iface_type_e iftype,
- const char *subscriber_id)
+ const char *ifname,
+ const char *subscriber_id,
+ const stc_roaming_type_e roaming)
{
stc_error_e error_code = STC_ERROR_NONE;
sqlite3_stmt *stmt = delete_restrictions;
- STC_LOGD("app_id [%s], iftype [%d], subscriber_id [%s]",
- app_id, iftype, subscriber_id);
+ STC_LOGD("app_id[%s] iftype[%d] ifname[%s] subscriber_id[%s] roaming[%d]",
+ app_id, iftype, ifname, subscriber_id, roaming);
DB_ACTION(sqlite3_bind_text(stmt, 1, app_id ? app_id : "",
-1, SQLITE_TRANSIENT));
DB_ACTION(sqlite3_bind_int(stmt, 2, iftype));
- DB_ACTION(sqlite3_bind_text(stmt, 3, subscriber_id ? subscriber_id : "", -1,
- SQLITE_TRANSIENT));
+ DB_ACTION(sqlite3_bind_text(stmt, 3, ifname ? ifname : "",
+ -1, SQLITE_TRANSIENT));
+ DB_ACTION(sqlite3_bind_text(stmt, 4, subscriber_id ? subscriber_id : "",
+ -1, SQLITE_TRANSIENT));
+ DB_ACTION(sqlite3_bind_int(stmt, 5, roaming));
if (sqlite3_step(stmt) != SQLITE_DONE) {
STC_LOGE("Failed to remove restrictions by network interface %s\n", //LCOV_EXCL_LINE
DB_ACTION(sqlite3_bind_int(stmt, 2, info->iftype));
DB_ACTION(sqlite3_bind_text(stmt, 3, info->subscriber_id ? info->subscriber_id : "",
-1, SQLITE_TRANSIENT));
- DB_ACTION(sqlite3_bind_int(stmt, 4, info->rst_type));
- DB_ACTION(sqlite3_bind_int(stmt, 5, info->roaming));
- DB_ACTION(sqlite3_bind_text(stmt, 6, info->ifname ? info->ifname : "",
+ DB_ACTION(sqlite3_bind_int(stmt, 4, info->roaming));
+ DB_ACTION(sqlite3_bind_text(stmt, 5, info->ifname ? info->ifname : "",
-1, SQLITE_TRANSIENT));
rc = sqlite3_step(stmt);
-1, SQLITE_TRANSIENT));
DB_ACTION(sqlite3_bind_int64(stmt, 2, info->data_limit));
DB_ACTION(sqlite3_bind_int(stmt, 3, info->iftype));
- DB_ACTION(sqlite3_bind_int(stmt, 4, info->rst_type));
+ DB_ACTION(sqlite3_bind_int(stmt, 4, info->rstn_type));
DB_ACTION(sqlite3_bind_int(stmt, 5, info->roaming));
DB_ACTION(sqlite3_bind_text(stmt, 6, info->ifname ? info->ifname : "",
-1, SQLITE_TRANSIENT));
DB_ACTION(sqlite3_bind_text(stmt, 7, info->subscriber_id ? info->subscriber_id : "",
-1, SQLITE_TRANSIENT));
DB_ACTION(sqlite3_bind_int64(stmt, 8, info->data_warn_limit));
+ DB_ACTION(sqlite3_bind_int64(stmt, 9, info->monthly_limit));
+ DB_ACTION(sqlite3_bind_int64(stmt, 10, info->weekly_limit));
+ DB_ACTION(sqlite3_bind_int64(stmt, 11, info->daily_limit));
if (info->restriction_id)
- DB_ACTION(sqlite3_bind_int64(stmt, 9, info->restriction_id));
+ DB_ACTION(sqlite3_bind_int64(stmt, 12, info->restriction_id));
+ else
+ DB_ACTION(sqlite3_bind_int64(stmt, 12, info->month_start_date));
if (sqlite3_step(stmt) != SQLITE_DONE) {
STC_LOGE("Failed to set network restriction: %s\n", //LCOV_EXCL_LINE