/* SELECT statements */
#define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
- " iftype, rst_state, 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_state, 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_state " \
+#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_state " \
+#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_state = ? AND roaming = ? AND ifname = ?"
+ " roaming = ? AND ifname = ?"
/* UPDATE statement */
#define UPDATE_NET_RESTRICTIONS "UPDATE restrictions " \
- " SET binpath = ?, data_limit = ?, iftype = ?, rst_state = ?, " \
- " 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_state, " \
- " 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 */
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_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__;
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,
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_state =
- (stc_restriction_state_e)sqlite3_column_int(stmt, 3);
+ 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;
+ 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);
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_state =
- (stc_restriction_state_e)sqlite3_column_int(stmt, 3);
+ 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;
+ 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_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) {
- 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_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",
- 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_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,
SQLITE_TRANSIENT));
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_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_state));
- 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);
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);
-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_state));
+ 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",
+ 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));