/* DELETE statements */
#define DELETE_RESTRICTIONS "DELETE FROM restrictions " \
- "WHERE binpath=? AND iftype=? AND imsi = ?"
+ " WHERE binpath = ? AND iftype = ? AND ifname = ? " \
+ " AND subscriber_id = ? AND roaming = ?"
/* SELECT statements */
-#define SELECT_RESTRICTIONS "SELECT binpath, rcv_limit, " \
- "send_limit, iftype, rst_state, roaming, ifname, imsi, " \
- "rcv_warn_limit, send_warn_limit, restriction_id FROM restrictions"
-
-#define SELECT_RESTRICTIONS_PER_APP "SELECT binpath, rcv_limit, " \
- "send_limit, iftype, rst_state, roaming, ifname, imsi, " \
- "rcv_warn_limit, send_warn_limit, restriction_id " \
- "FROM restrictions INDEXED BY restrictions_index " \
- "WHERE binpath = ?"
-
-#define SELECT_RESTRICTION_STATE "SELECT rst_state " \
- "FROM restrictions INDEXED BY restrictions_index " \
- "WHERE binpath = ? AND iftype = ?"
-
-#define SELECT_RESTRICTION_STATE_IMSI "SELECT rst_state " \
- "FROM restrictions INDEXED BY restrictions_index " \
- "WHERE binpath = ? AND iftype = ? AND imsi = ?"
+#define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
+ " 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, 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_TYPE "SELECT rstn_type " \
+ " FROM restrictions INDEXED BY restrictions_index " \
+ " WHERE binpath = ? AND iftype = ?"
+
+#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 imsi = ? AND send_limit=? " \
- "AND rcv_limit=? AND rcv_warn_limit=? AND send_warn_limit=? " \
- "AND rst_state=? AND roaming=? AND ifname=?"
+ " WHERE binpath = ? AND iftype = ? AND subscriber_id = ? AND " \
+ " roaming = ? AND ifname = ?"
/* UPDATE statement */
#define UPDATE_NET_RESTRICTIONS "UPDATE restrictions " \
- "SET binpath=?, rcv_limit=?, send_limit=?, iftype=?, rst_state=?, " \
- "roaming=?, ifname=?, imsi=?, rcv_warn_limit=?, send_warn_limit=? " \
- "WHERE restriction_id=?"
+ " 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, rcv_limit, send_limit, iftype, rst_state, " \
- "roaming, ifname, imsi, rcv_warn_limit, send_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_imsi;
+static sqlite3_stmt *select_restriction_type;
+static sqlite3_stmt *select_restriction_type_subscriber_id;
static sqlite3_stmt *select_restriction_id;
/* REPLACE statements */
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_DELETE(delete_restrictions, DELETE_RESTRICTIONS);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
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_imsi, SELECT_RESTRICTION_STATE_IMSI);
+ 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_imsi);
+ FINALIZE(select_restriction_type);
+ FINALIZE(select_restriction_type_subscriber_id);
FINALIZE(select_restriction_id);
__STC_LOG_FUNC_EXIT__;
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_UPDATE(update_net_restrictions, UPDATE_NET_RESTRICTIONS);
static int initialized;
if (initialized) {
- __STC_LOG_FUNC_EXIT__;
- return SQLITE_OK;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return SQLITE_OK; //LCOV_EXCL_LINE
}
PREPARE_UPDATE(insert_net_restrictions, INSERT_NET_RESTRICTIONS);
sqlite3_stmt *stmt = select_restriction_per_app;
if (!app_id) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
DB_ACTION(sqlite3_bind_text(stmt, 1, app_id, -1,
break;
case SQLITE_ROW:
data.app_id = (char *)sqlite3_column_text(stmt, 0);
- data.rcv_limit = sqlite3_column_int64(stmt, 1);
- data.send_limit = sqlite3_column_int64(stmt, 2);
- data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 3);
- data.rst_state =
- (stc_restriction_state_e)sqlite3_column_int(stmt, 4);
- data.roaming = sqlite3_column_int(stmt, 5);
- data.ifname = (char *)sqlite3_column_text(stmt, 6);
- data.imsi = (char *)sqlite3_column_text(stmt, 7);
- data.rcv_warn_limit = sqlite3_column_int64(stmt, 8);
- data.send_warn_limit = sqlite3_column_int64(stmt, 9);
- data.restriction_id = sqlite3_column_int64(stmt, 10);
+ data.data_limit = sqlite3_column_int64(stmt, 1);
+ data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
+ 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.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;
+ rc = SQLITE_DONE; //LCOV_EXCL_LINE
break;
case SQLITE_ERROR:
default:
- STC_LOGE("Failed to enumerate restrictions: %s\n",
+ STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- __STC_LOG_FUNC_EXIT__;
- error_code = STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
} while (rc == SQLITE_ROW);
break;
case SQLITE_ROW:
data.app_id = (char *)sqlite3_column_text(stmt, 0);
- data.rcv_limit = sqlite3_column_int64(stmt, 1);
- data.send_limit = sqlite3_column_int64(stmt, 2);
- data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 3);
- data.rst_state =
- (stc_restriction_state_e)sqlite3_column_int(stmt, 4);
- data.roaming = sqlite3_column_int(stmt, 5);
- data.ifname = (char *)sqlite3_column_text(stmt, 6);
- data.imsi = (char *)sqlite3_column_text(stmt, 7);
- data.rcv_warn_limit = sqlite3_column_int64(stmt, 8);
- data.send_warn_limit = sqlite3_column_int64(stmt, 9);
- data.restriction_id = sqlite3_column_int64(stmt, 10);
+ data.data_limit = sqlite3_column_int64(stmt, 1);
+ data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
+ 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.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;
+ rc = SQLITE_DONE; //LCOV_EXCL_LINE
break;
case SQLITE_ERROR:
default:
- STC_LOGE("Failed to enumerate restrictions: %s\n",
+ STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- __STC_LOG_FUNC_EXIT__;
- error_code = STC_ERROR_DB_FAILED;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
} while (rc == SQLITE_ROW);
return error_code;
}
-stc_error_e table_restrictions_get_restriction_state_imsi(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 *imsi_hash,
- stc_restriction_state_e *state)
+ const char *subscriber_id,
+ stc_rstn_type_e *type)
{
__STC_LOG_FUNC_ENTER__;
int error_code = STC_ERROR_NONE;
int ret;
- bool state_imsi = 0;
+ bool state_subscriber_id = 0;
- if (state == NULL) {
- STC_LOGE("Please provide valid argument!");
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_INVALID_PARAMETER;
+ 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_imsi);
- sqlite3_reset(select_restriction_state);
+ *type = STC_RSTN_TYPE_UNKNOWN;
+ sqlite3_reset(select_restriction_type_subscriber_id);
+ sqlite3_reset(select_restriction_type);
- if (imsi_hash == NULL) {
- state_imsi = 0;
- DB_ACTION(sqlite3_bind_text(select_restriction_state, 1,
+ if (subscriber_id == NULL) {
+ state_subscriber_id = 0;
+ 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_imsi = 1;
- DB_ACTION(sqlite3_bind_text(select_restriction_state_imsi, 1,
+ 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_imsi, 2,
+ DB_ACTION(sqlite3_bind_int(select_restriction_type_subscriber_id, 2,
iftype));
- DB_ACTION(sqlite3_bind_text(select_restriction_state_imsi, 3,
- imsi_hash, -1, SQLITE_STATIC));
- ret = sqlite3_step(select_restriction_state_imsi);
+ DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 3,
+ subscriber_id, -1, SQLITE_STATIC));
+ ret = sqlite3_step(select_restriction_type_subscriber_id);
}
switch (ret) {
case SQLITE_DONE:
break;
case SQLITE_ROW:
- if (state_imsi)
- *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state_imsi, 0);
+ if (state_subscriber_id)
+ *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",
- 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;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
}
handle_error:
- sqlite3_reset(select_restriction_state);
- sqlite3_reset(select_restriction_state_imsi);
+ 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_imsi(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 *imsi)
+ 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], imsi [%s]",
- app_id, iftype, imsi);
+ 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, imsi ? imsi : "", -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",
+ STC_LOGE("Failed to remove restrictions by network interface %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- error_code = STC_ERROR_DB_FAILED;
- goto handle_error;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
STC_LOGD("Restriction deleted for app_id [%s]", app_id);
DB_ACTION(sqlite3_bind_text(stmt, 1, info->app_id ? info->app_id : "",
-1, SQLITE_TRANSIENT));
DB_ACTION(sqlite3_bind_int(stmt, 2, info->iftype));
- DB_ACTION(sqlite3_bind_text(stmt, 3, info->imsi ? info->imsi : "",
+ DB_ACTION(sqlite3_bind_text(stmt, 3, info->subscriber_id ? info->subscriber_id : "",
-1, SQLITE_TRANSIENT));
- DB_ACTION(sqlite3_bind_int64(stmt, 4, info->send_limit));
- DB_ACTION(sqlite3_bind_int64(stmt, 5, info->rcv_limit));
- DB_ACTION(sqlite3_bind_int64(stmt, 6, info->rcv_warn_limit));
- DB_ACTION(sqlite3_bind_int64(stmt, 7, info->send_warn_limit));
-
- DB_ACTION(sqlite3_bind_int(stmt, 8, info->rst_state));
- DB_ACTION(sqlite3_bind_int(stmt, 9, info->roaming));
- DB_ACTION(sqlite3_bind_text(stmt, 10, 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);
break;
case SQLITE_ERROR:
default:
- STC_LOGE("Failed to get restriction id: %s\n",
+ STC_LOGE("Failed to get restriction id: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
}
sqlite3_stmt *stmt = insert_net_restrictions;
if (!info) {
- error_code = STC_ERROR_INVALID_PARAMETER;
- goto handle_error;
+ error_code = STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
+ __get_restriction_id(info);
if (info->restriction_id)
stmt = update_net_restrictions;
DB_ACTION(sqlite3_bind_text(stmt, 1, info->app_id ? info->app_id : "",
-1, SQLITE_TRANSIENT));
- DB_ACTION(sqlite3_bind_int64(stmt, 2, info->rcv_limit));
- DB_ACTION(sqlite3_bind_int64(stmt, 3, info->send_limit));
- DB_ACTION(sqlite3_bind_int(stmt, 4, info->iftype));
- DB_ACTION(sqlite3_bind_int(stmt, 5, info->rst_state));
- DB_ACTION(sqlite3_bind_int(stmt, 6, info->roaming));
- DB_ACTION(sqlite3_bind_text(stmt, 7, info->ifname ? info->ifname : "",
+ 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->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, 8, info->imsi ? info->imsi : "",
+ DB_ACTION(sqlite3_bind_text(stmt, 7, info->subscriber_id ? info->subscriber_id : "",
-1, SQLITE_TRANSIENT));
- DB_ACTION(sqlite3_bind_int64(stmt, 9, info->rcv_warn_limit));
- DB_ACTION(sqlite3_bind_int64(stmt, 10, info->send_warn_limit));
+ 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, 11, 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",
+ STC_LOGE("Failed to set network restriction: %s\n", //LCOV_EXCL_LINE
sqlite3_errmsg(stc_db_get_database()));
- error_code = STC_ERROR_DB_FAILED;
- goto handle_error;
+ error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+ goto handle_error; //LCOV_EXCL_LINE
}
if (info->restriction_id) {
stc_error_e error_code = STC_ERROR_NONE;
if (db == NULL) {
- __STC_LOG_FUNC_EXIT__;
- return STC_ERROR_FAIL;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return STC_ERROR_FAIL; //LCOV_EXCL_LINE
}
DB_ACTION(__prepare_delete(db));