Replaced imsi to subscriber ID 99/151199/2
authorhyunuktak <hyunuk.tak@samsung.com>
Wed, 20 Sep 2017 07:35:35 +0000 (16:35 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Wed, 20 Sep 2017 07:41:32 +0000 (16:41 +0900)
Change-Id: Ie137cb045ab279416b3d3711f0cd55a1fe4543bd
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
15 files changed:
data/traffic_db.sql
include/stc-restriction.h
packaging/stc-manager.spec
src/CMakeLists.txt
src/database/include/stc-db.h
src/database/include/table-restrictions.h
src/database/include/table-statistics.h
src/database/tables/table-restrictions.c
src/database/tables/table-statistics.c
src/monitor/include/stc-default-connection.h
src/monitor/include/stc-monitor.h
src/monitor/stc-default-connection.c
src/monitor/stc-monitor.c
src/stc-restriction.c
src/stc-statistics.c

index 3fae3f6..dd83d65 100644 (file)
@@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS statistics (
   is_roaming INT,
   hw_net_protocol_type INT,
   ifname TEXT,
-  imsi TEXT,
+  subscriber_id TEXT,
   ground INT
 );
 
@@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS restrictions (
   ifname TEXT,
   rst_state INT,
   roaming INT,
-  imsi TEXT NOT NULL,
+  subscriber_id TEXT NOT NULL,
   data_limit BIGINT,
   data_warn_limit BIGINT
 );
index acd4eab..e804e0f 100755 (executable)
@@ -35,7 +35,7 @@ typedef struct {
        int64_t rcv_warning_limit;
        stc_roaming_type_e roaming;
        char *ifname;
-       char *imsi;
+       char *subscriber_id;
 } stc_restriction_s;
 
 /*****************************************************************************
index 3ed74db..7979283 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.32
+Version:    0.0.33
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
@@ -21,6 +21,7 @@ BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(vconf)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(pkgmgr-info)
+BuildRequires:  pkgconfig(openssl)
 
 %if %{?enable_database} == YES
 BuildRequires: pkgconfig(sqlite3)
index 295314b..23fd943 100644 (file)
@@ -8,6 +8,7 @@ SET(REQUIRES_LIST ${REQUIRES_LIST}
        vconf
        capi-system-info
        pkgmgr-info
+       openssl
        )
 
 IF("${ENABLE_DATABASE}" STREQUAL "YES")
index 6f718c3..689cb1f 100755 (executable)
@@ -79,8 +79,8 @@ typedef struct {
 typedef struct {
        uint32_t classid;
        int iftype;
-       /* pointer to telephony's imsi */
-       char *imsi;
+       /* pointer to telephony's subscriber_id */
+       char *subscriber_id;
        char ifname[MAX_IFACE_LENGTH];
 } stc_db_classid_iftype_key;
 
index fe275e1..d972b87 100755 (executable)
@@ -20,7 +20,7 @@
 typedef struct {
        char *app_id;
        char *ifname;
-       char *imsi;
+       char *subscriber_id;
        stc_iface_type_e iftype;
        stc_restriction_state_e rst_state;
        stc_roaming_type_e roaming;
@@ -41,9 +41,9 @@ stc_error_e table_restrictions_per_app(const gchar *app_id,
                                       void *user_data);
 
 
-stc_error_e table_restrictions_get_restriction_state_imsi(const char *app_id,
+stc_error_e table_restrictions_get_restriction_state_subscriber_id(const char *app_id,
                                                          stc_iface_type_e iftype,
-                                                         const char *imsi_hash,
+                                                         const char *subscriber_id,
                                                          stc_restriction_state_e *state);
 
 stc_error_e table_restrictions_get_restriction_state(const char *app_id,
@@ -54,7 +54,7 @@ stc_error_e table_restrictions_update(table_restrictions_info *info);
 
 stc_error_e table_restrictions_delete(const char *app_id,
                                      const stc_iface_type_e iftype,
-                                     const char *imsi);
+                                     const char *subscriber_id);
 
 stc_error_e table_restrictions_prepare(sqlite3 *db);
 
index 62a5ef6..ec88f5a 100755 (executable)
@@ -20,7 +20,7 @@
 typedef struct {
        char *app_id;
        char *ifname;
-       char *imsi;
+       char *subscriber_id;
        stc_iface_type_e iftype;
        stc_db_tm_interval_s *interval;
        stc_data_counter_s cnt;
@@ -32,7 +32,7 @@ typedef struct {
 typedef struct {
        unsigned char version;
        char *app_id;
-       char *imsi;
+       char *subscriber_id;
        stc_iface_type_e iftype;
        stc_db_tm_interval_s *interval;
        stc_db_connection_period_type connection_state;
index e1e7256..9324887 100755 (executable)
 
 /* DELETE statements */
 #define DELETE_RESTRICTIONS "DELETE FROM restrictions " \
-       " WHERE binpath = ? AND iftype = ? AND imsi = ?"
+       " WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
 
 /* SELECT statements */
 #define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
-       " iftype, rst_state, roaming, ifname, imsi, " \
+       " iftype, rst_state, roaming, ifname, subscriber_id, " \
        " data_warn_limit, restriction_id FROM restrictions"
 
 #define SELECT_RESTRICTIONS_PER_APP "SELECT binpath, data_limit, " \
-       " iftype, rst_state, roaming, ifname, imsi, " \
+       " iftype, rst_state, roaming, ifname, subscriber_id, " \
        " data_warn_limit, restriction_id " \
        " FROM restrictions INDEXED BY restrictions_index " \
        " WHERE binpath = ?"
        " FROM restrictions INDEXED BY restrictions_index " \
        " WHERE binpath = ? AND iftype = ?"
 
-#define SELECT_RESTRICTION_STATE_IMSI "SELECT rst_state " \
+#define SELECT_RESTRICTION_STATE_SUBSCRIBER_ID "SELECT rst_state " \
        " FROM restrictions INDEXED BY restrictions_index " \
-       " WHERE binpath = ? AND iftype = ? AND imsi = ?"
+       " WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
 
 #define SELECT_RESTRICTION_ID "SELECT restriction_id FROM restrictions " \
-       " WHERE binpath = ? AND iftype = ? AND imsi = ? AND " \
+       " WHERE binpath = ? AND iftype = ? AND subscriber_id = ? AND " \
        " rst_state = ? AND roaming = ? AND ifname = ?"
 
 /* UPDATE statement */
 #define UPDATE_NET_RESTRICTIONS "UPDATE restrictions " \
        " SET binpath = ?, data_limit = ?, iftype = ?, rst_state = ?, " \
-       " roaming = ?, ifname = ?, imsi = ?, data_warn_limit = ? " \
+       " roaming = ?, ifname = ?, subscriber_id = ?, data_warn_limit = ? " \
        " WHERE restriction_id = ?"
 
 /* INSERT statement */
 #define INSERT_NET_RESTRICTIONS "INSERT INTO restrictions " \
        " (binpath, data_limit, iftype, rst_state, " \
-       " roaming, ifname, imsi, data_warn_limit) " \
+       " roaming, ifname, subscriber_id, data_warn_limit) " \
        " VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
 
 static void __finalize_delete(void);
@@ -129,7 +129,7 @@ static sqlite3_stmt *delete_restrictions;
 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_state_subscriber_id;
 static sqlite3_stmt *select_restriction_id;
 
 /* REPLACE statements */
@@ -179,7 +179,7 @@ static int __prepare_select(sqlite3 *db)
        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_state_subscriber_id, SELECT_RESTRICTION_STATE_SUBSCRIBER_ID);
        PREPARE_SELECT(select_restriction_id, SELECT_RESTRICTION_ID);
 
        initialized = 1;
@@ -194,7 +194,7 @@ static void __finalize_select(void)
        FINALIZE(select_restriction);
        FINALIZE(select_restriction_per_app);
        FINALIZE(select_restriction_state);
-       FINALIZE(select_restriction_state_imsi);
+       FINALIZE(select_restriction_state_subscriber_id);
        FINALIZE(select_restriction_id);
 
        __STC_LOG_FUNC_EXIT__;
@@ -289,7 +289,7 @@ stc_error_e table_restrictions_per_app(const gchar* app_id,
                                (stc_restriction_state_e)sqlite3_column_int(stmt, 3);
                        data.roaming = sqlite3_column_int(stmt, 4);
                        data.ifname = (char *)sqlite3_column_text(stmt, 5);
-                       data.imsi = (char *)sqlite3_column_text(stmt, 6);
+                       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);
 
@@ -337,7 +337,7 @@ stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restrict
                                (stc_restriction_state_e)sqlite3_column_int(stmt, 3);
                        data.roaming = sqlite3_column_int(stmt, 4);
                        data.ifname = (char *)sqlite3_column_text(stmt, 5);
-                       data.imsi = (char *)sqlite3_column_text(stmt, 6);
+                       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);
 
@@ -359,15 +359,15 @@ stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restrict
        return error_code;
 }
 
-stc_error_e table_restrictions_get_restriction_state_imsi(const char *app_id,
+stc_error_e table_restrictions_get_restriction_state_subscriber_id(const char *app_id,
                                                          stc_iface_type_e iftype,
-                                                         const char *imsi_hash,
+                                                         const char *subscriber_id,
                                                          stc_restriction_state_e *state)
 {
        __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!");
@@ -376,11 +376,11 @@ stc_error_e table_restrictions_get_restriction_state_imsi(const char *app_id,
        }
 
        *state = STC_RESTRICTION_UNKNOWN;
-       sqlite3_reset(select_restriction_state_imsi);
+       sqlite3_reset(select_restriction_state_subscriber_id);
        sqlite3_reset(select_restriction_state);
 
-       if (imsi_hash == NULL) {
-               state_imsi = 0;
+       if (subscriber_id == NULL) {
+               state_subscriber_id = 0;
                DB_ACTION(sqlite3_bind_text(select_restriction_state, 1,
                                            app_id ? app_id : "", -1,
                                            SQLITE_STATIC));
@@ -388,23 +388,23 @@ stc_error_e table_restrictions_get_restriction_state_imsi(const char *app_id,
                                           iftype));
                ret = sqlite3_step(select_restriction_state);
        } 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_state_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_state_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_state_subscriber_id, 3,
+                                           subscriber_id, -1, SQLITE_STATIC));
+               ret = sqlite3_step(select_restriction_state_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)
+                       *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state_subscriber_id, 0);
                else
                        *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state, 0);
                break;
@@ -418,7 +418,7 @@ stc_error_e table_restrictions_get_restriction_state_imsi(const char *app_id,
 
 handle_error:
        sqlite3_reset(select_restriction_state);
-       sqlite3_reset(select_restriction_state_imsi);
+       sqlite3_reset(select_restriction_state_subscriber_id);
        return error_code;
 }
 
@@ -428,24 +428,24 @@ stc_error_e table_restrictions_get_restriction_state(const char *app_id,
 {
        __STC_LOG_FUNC_ENTER__;
        __STC_LOG_FUNC_EXIT__;
-       return table_restrictions_get_restriction_state_imsi(app_id, iftype,
+       return table_restrictions_get_restriction_state_subscriber_id(app_id, iftype,
                                                             NULL, state);
 }
 
 stc_error_e table_restrictions_delete(const char *app_id,
                                      const stc_iface_type_e iftype,
-                                     const char *imsi)
+                                     const char *subscriber_id)
 {
        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], subscriber_id [%s]",
+                app_id, iftype, subscriber_id);
 
        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,
+       DB_ACTION(sqlite3_bind_text(stmt, 3, subscriber_id ? subscriber_id : "", -1,
                                    SQLITE_TRANSIENT));
 
        if (sqlite3_step(stmt) != SQLITE_DONE) {
@@ -473,7 +473,7 @@ stc_error_e __get_restriction_id(table_restrictions_info *info)
        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_int(stmt, 4, info->rst_state));
        DB_ACTION(sqlite3_bind_int(stmt, 5, info->roaming));
@@ -523,7 +523,7 @@ stc_error_e table_restrictions_update(table_restrictions_info *info)
        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->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, 8, info->data_warn_limit));
 
index 1b6d288..c14fdb6 100755 (executable)
 /* SELECT statements */
 #define SELECT_FOR_PERIOD "select binpath, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, " \
-       "sum(sent) as sent, imsi, ground, iftype, ifname from statistics " \
+       "sum(sent) as sent, subscriber_id, ground, iftype, ifname from statistics " \
        "where time_stamp between ? and ? " \
-       "group by binpath, is_roaming, imsi order by received desc"
+       "group by binpath, is_roaming, subscriber_id order by received desc"
 
 #define SELECT_FOR_PERIOD_IFACE "select binpath, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, " \
-       "sum(sent) as sent, imsi, ground, iftype, ifname from statistics " \
+       "sum(sent) as sent, subscriber_id, ground, iftype, ifname from statistics " \
        "where time_stamp between ? and ? " \
-       "and iftype=? group by binpath, is_roaming, imsi order by received desc"
+       "and iftype=? group by binpath, is_roaming, subscriber_id order by received desc"
 
 #define SELECT_CHUNKS "select binpath, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, " \
-       "sum(sent) as sent, imsi, ground, iftype, ifname, " \
+       "sum(sent) as sent, subscriber_id, ground, iftype, ifname, " \
        "time_stamp - time_stamp % ? as timestamp " \
        "from statistics where time_stamp between ? and ? " \
-       "group by binpath, timestamp, imsi order by timestamp"
+       "group by binpath, timestamp, subscriber_id order by timestamp"
 
 #define SELECT_CHUNKS_IFACE "select binpath, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, " \
-       "sum(sent) as sent, imsi, ground, iftype, ifname, " \
+       "sum(sent) as sent, subscriber_id, ground, iftype, ifname, " \
        "time_stamp - time_stamp % ? as timestamp " \
        "from statistics where time_stamp between ? and ? and iftype=?" \
-       "group by binpath, timestamp, imsi order by timestamp"
+       "group by binpath, timestamp, subscriber_id order by timestamp"
 
 #define SELECT_APP_DETAILS "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground from statistics " \
+       "ifname, subscriber_id, ground from statistics " \
        "where time_stamp between ? and ? and binpath=? " \
-       "group by binpath, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "group by binpath, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming " \
-       "order by time_stamp, binpath, iftype, ifname, imsi, " \
+       "order by time_stamp, binpath, iftype, ifname, subscriber_id, " \
        "hw_net_protocol_type, is_roaming"
 
 #define SELECT_APP_DETAILS_IFACE "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground from statistics " \
+       "ifname, subscriber_id, ground from statistics " \
        "where time_stamp between ? and ? and binpath=? and iftype=?" \
-       "group by hw_net_protocol_type, is_roaming, iftype, ifname, imsi " \
+       "group by hw_net_protocol_type, is_roaming, iftype, ifname, subscriber_id " \
        "order by time_stamp, hw_net_protocol_type, is_roaming, iftype, " \
-       "ifname, imsi"
+       "ifname, subscriber_id"
 
 #define SELECT_CHUNKS_APP "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground, time_stamp - time_stamp % ? as time_stamp " \
+       "ifname, subscriber_id, ground, time_stamp - time_stamp % ? as time_stamp " \
        "from statistics " \
        "group by iftype, ifname, time_stamp, hw_net_protocol_type, is_roaming  " \
        "order by time_stamp, iftype, ifname, hw_net_protocol_type, is_roaming"
 
 #define SELECT_CHUNKS_APP_IFACE "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground, time_stamp - time_stamp % ? as time_stamp " \
+       "ifname, subscriber_id, ground, time_stamp - time_stamp % ? as time_stamp " \
        "from statistics where time_stamp between ? and ? and binpath = ? " \
        "and iftype = ? " \
        "group by time_stamp, hw_net_protocol_type, is_roaming, " \
-       "iftype, ifname, imsi " \
-       "order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "iftype, ifname, subscriber_id " \
+       "order by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming"
 
 #define SELECT_TOTAL "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground from statistics " \
+       "ifname, subscriber_id, ground from statistics " \
        "where (time_stamp between ? and ?) " \
        "and binpath NOT LIKE 'TOTAL_%' " \
-       "group by iftype, ifname, imsi, hw_net_protocol_type, is_roaming " \
-       "order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "group by iftype, ifname, subscriber_id, hw_net_protocol_type, is_roaming " \
+       "order by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming"
 
 #define SELECT_TOTAL_IFACE "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground from statistics " \
+       "ifname, subscriber_id, ground from statistics " \
        "where (time_stamp between ? and ?) and iftype=? " \
        "and binpath NOT LIKE 'TOTAL_%' " \
        "group by hw_net_protocol_type, is_roaming, " \
-       "iftype, ifname, imsi " \
-       "order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "iftype, ifname, subscriber_id " \
+       "order by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming"
 
 #define SELECT_CHUNKS_TOTAL "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground, time_stamp - time_stamp % ? as time_stamp " \
+       "ifname, subscriber_id, ground, time_stamp - time_stamp % ? as time_stamp " \
        "from statistics where time_stamp between ? and ? " \
        "and binpath NOT LIKE 'TOTAL_%' " \
-       "group by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "group by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming " \
-       "order by time_stamp, iftype, ifname, imsi, hw_net_protocol_type, " \
+       "order by time_stamp, iftype, ifname, subscriber_id, hw_net_protocol_type, " \
        "is_roaming"
 
 #define SELECT_CHUNKS_TOTAL_IFACE "select iftype, hw_net_protocol_type, " \
        "is_roaming, sum(received) as received, sum(sent) as sent, " \
-       "ifname, imsi, ground, time_stamp - time_stamp % ? as time_stamp " \
+       "ifname, subscriber_id, ground, time_stamp - time_stamp % ? as time_stamp " \
        "from statistics where time_stamp between ? and ? " \
        "and iftype = ? " \
        "and binpath NOT LIKE 'TOTAL_%' " \
-       "group by time_stamp, hw_net_protocol_type, is_roaming, iftype, ifname, imsi " \
+       "group by time_stamp, hw_net_protocol_type, is_roaming, iftype, ifname, subscriber_id " \
        "order by time_stamp, hw_net_protocol_type, is_roaming, iftype, " \
-       "ifname, imsi"
+       "ifname, subscriber_id"
 
 /* INSERT statement */
 #define INSERT_VALUES "insert into statistics " \
        "(binpath, received, sent, time_stamp, " \
        "iftype, is_roaming, hw_net_protocol_type, " \
-       "ifname, imsi, ground) " \
+       "ifname, subscriber_id, ground) " \
        "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
 
 static void __finalize_delete(void);
@@ -474,7 +474,7 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul
                        data.roaming = sqlite3_column_int(stmt, 2);
                        data.cnt.in_bytes = sqlite3_column_int64(stmt, 3);
                        data.cnt.out_bytes = sqlite3_column_int64(stmt, 4);
-                       data.imsi = (char *)sqlite3_column_text(stmt, 5);
+                       data.subscriber_id = (char *)sqlite3_column_text(stmt, 5);
                        data.ground = sqlite3_column_int(stmt, 6);
                        data.iftype = sqlite3_column_int(stmt, 7);
                        data.ifname = (char *)sqlite3_column_text(stmt, 8);
@@ -557,7 +557,7 @@ stc_error_e table_statistics_per_app(const char *app_id,
                        data.cnt.in_bytes = sqlite3_column_int64(stmt, 3);
                        data.cnt.out_bytes = sqlite3_column_int64(stmt, 4);
                        data.ifname = (char *)sqlite3_column_text(stmt, 5);
-                       data.imsi = (char *)sqlite3_column_text(stmt, 6);
+                       data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
                        data.ground = sqlite3_column_int(stmt, 7);
 
                        if (rule->granularity) {
@@ -611,7 +611,7 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
        DB_ACTION(sqlite3_bind_text(stmt, 8, stat_key->ifname, -1,
                                    SQLITE_STATIC));
        DB_ACTION(sqlite3_bind_text(stmt, 9,
-                                   stat_key->imsi ? stat_key->imsi : "" , -1,
+                                   stat_key->subscriber_id ? stat_key->subscriber_id : "" , -1,
                                    SQLITE_STATIC));
        DB_ACTION(sqlite3_bind_int(stmt, 10, (int)stat->ground));
 
index b3326de..230671b 100755 (executable)
@@ -23,6 +23,7 @@
 #include "stc-manager-util.h"
 
 #define IMSI_LENGTH 16
+#define SHA256_DIGEST_LENGTH 32
 
 /**
  * @brief default connection information will be fetched from net-config
@@ -39,7 +40,7 @@ typedef struct {
        gboolean roaming;
 
        /* only present when default profile is cellular */
-       char imsi[IMSI_LENGTH];
+       char subscriber_id[SHA256_DIGEST_LENGTH * 2 + 1];
 
        /* hardware network protocol type */
        stc_hw_net_protocol_type_e hw_net_protocol_type;
index ffb64c0..74a05b4 100755 (executable)
@@ -71,7 +71,7 @@ typedef struct {
 typedef struct {
        gchar *app_id;
        gchar *ifname;
-       gchar *imsi;
+       gchar *subscriber_id;
        stc_iface_type_e iftype;
        stc_roaming_type_e roaming;
 } stc_rstn_key_s;
index e524970..aa8e1e6 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 #include <vconf/vconf.h>
+#include <openssl/sha.h>
 
 #include "stc-monitor.h"
 #include "stc-manager-gdbus.h"
@@ -76,11 +77,26 @@ static int __telephony_get_current_sim(void)
        return current_sim;
 }
 
-static void __telephony_get_modem_imsi(GDBusConnection *connection,
+static void __make_imsi_to_subscriber_id(char *imsi)
+{
+       int i = 0;
+       SHA256_CTX ctx;
+       unsigned char md[SHA256_DIGEST_LENGTH];
+
+       SHA256_Init(&ctx);
+       SHA256_Update(&ctx, imsi, strlen(imsi));
+       SHA256_Final(md, &ctx);
+
+       for (i = 0; i < SHA256_DIGEST_LENGTH; ++i)
+               snprintf(g_default_connection.subscriber_id + (i * 2), 3, "%02x", md[i]);
+}
+
+static void __telephony_get_modem_subscriber_id(GDBusConnection *connection,
                                       const char *default_modem_name)
 {
        GVariant *message = NULL;
        char tel_path[MAX_PATH_LENGTH];
+       char imsi[IMSI_LENGTH];
        const char *plmn = NULL;
        int plmn_len = 0;
        const char *msin = NULL;
@@ -110,14 +126,15 @@ static void __telephony_get_modem_imsi(GDBusConnection *connection,
                goto done;
        }
 
-       snprintf(g_default_connection.imsi, IMSI_LENGTH, "%s%s", plmn, msin);
+       snprintf(imsi, IMSI_LENGTH, "%s%s", plmn, msin);
+       __make_imsi_to_subscriber_id(imsi);
 
 done:
        g_variant_unref(message);
        return;
 }
 
-static void __telephony_update_default_modem_imsi(GDBusConnection *connection)
+static void __telephony_update_default_modem_subscriber_id(GDBusConnection *connection)
 {
        GVariant *message = NULL;
        GVariantIter *iter = NULL;
@@ -153,7 +170,7 @@ static void __telephony_update_default_modem_imsi(GDBusConnection *connection)
                current_sim--;
        }
 
-       __telephony_get_modem_imsi(connection, default_modem_name);
+       __telephony_get_modem_subscriber_id(connection, default_modem_name);
 
        FREE(default_modem_name);
        g_variant_iter_free(iter);
@@ -169,7 +186,7 @@ static void __print_default_connection_info(void)
        STC_LOGI("ifname  [%s]", g_default_connection.ifname);
        STC_LOGI("roaming [%u]", g_default_connection.roaming ? TRUE : FALSE);
        if (g_default_connection.type == STC_IFACE_DATACALL)
-               STC_LOGI("imsi    [%s]", g_default_connection.imsi);
+               STC_LOGI("sub_id  [%s]", g_default_connection.subscriber_id);
        STC_LOGI("==================================================");
 }
 
@@ -378,7 +395,7 @@ static stc_error_e __get_default_profile(GDBusConnection *connection)
 
        if (__is_cellular_profile(g_default_connection.path)) {
                g_default_connection.type = STC_IFACE_DATACALL;
-               __telephony_update_default_modem_imsi(connection);
+               __telephony_update_default_modem_subscriber_id(connection);
        } else if (__is_wifi_profile(g_default_connection.path)) {
                g_default_connection.type = STC_IFACE_WIFI;
        } else if (__is_ethernet_profile(g_default_connection.path)) {
index ed8af13..734620b 100755 (executable)
@@ -248,7 +248,7 @@ static int __rstns_tree_key_compare(gconstpointer a, gconstpointer b,
        if (ret != 0)
                return ret;
 
-       ret = g_strcmp0(key_a->imsi, key_b->imsi);
+       ret = g_strcmp0(key_a->subscriber_id, key_b->subscriber_id);
        if (ret != 0)
                return ret;
 
@@ -272,7 +272,7 @@ static void __rstns_tree_key_free(gpointer data)
 
        FREE(key->app_id);
        FREE(key->ifname);
-       FREE(key->imsi);
+       FREE(key->subscriber_id);
        FREE(key);
 }
 
@@ -456,14 +456,14 @@ static void __print_rstn(stc_rstn_key_s *rstn_key, stc_rstn_value_s *rstn_value)
                 "limit [ (%lld) bytes], "
                 "warn_limit [ (%lld) bytes], "
                 "counter [ (%lld) bytes], "
-                "roaming [%d], imsi [%s]",
+                "roaming [%d], subscriber_id [%s]",
                 rstn_value->restriction_id,
                 rstn_key->app_id, rstn_value->classid , rstn_key->ifname,
                 rstn_key->iftype, rstn_value->rst_state,
                 rstn_value->data_limit,
                 rstn_value->data_warn_limit,
                 rstn_value->data_counter,
-                rstn_key->roaming, rstn_key->imsi);
+                rstn_key->roaming, rstn_key->subscriber_id);
 }
 
 static void __process_restriction(enum traffic_restriction_type rst_type,
@@ -880,9 +880,9 @@ static gboolean __update_app_statistics(gpointer key, gpointer value,
        stat_key.iftype = default_connection->type;
 
        if (STC_IFACE_DATACALL == stat_key.iftype)
-               stat_key.imsi = g_strdup(default_connection->imsi);
+               stat_key.subscriber_id = g_strdup(default_connection->subscriber_id);
        else
-               stat_key.imsi = g_strdup("noneimsi");
+               stat_key.subscriber_id = g_strdup("none_subid");
 
        g_strlcpy(stat_key.ifname, default_connection->ifname,
                  MAX_IFACE_LENGTH);
@@ -899,7 +899,7 @@ static gboolean __update_app_statistics(gpointer key, gpointer value,
        app_value->counter.in_bytes = 0;
 
        FREE(stat.app_id);
-       FREE(stat_key.imsi);
+       FREE(stat_key.subscriber_id);
 
        return FALSE;
 }
@@ -1298,7 +1298,7 @@ static stc_error_e __rstn_tree_add(stc_rstn_key_s *key,
 
                rstn_key->app_id = g_strdup(key->app_id);
                rstn_key->ifname = g_strdup(key->ifname);
-               rstn_key->imsi = g_strdup(key->imsi);
+               rstn_key->subscriber_id = g_strdup(key->subscriber_id);
                rstn_key->iftype = key->iftype;
                rstn_key->roaming = key->roaming;
 
@@ -1335,7 +1335,7 @@ static stc_cb_ret_e __insert_restriction_cb(const table_restrictions_info *info,
 
        key.app_id = g_strdup(info->app_id);
        key.ifname = g_strdup(info->ifname);
-       key.imsi = g_strdup(info->imsi);
+       key.subscriber_id = g_strdup(info->subscriber_id);
        key.iftype = info->iftype;
        key.roaming = info->roaming;
 
@@ -1355,7 +1355,7 @@ static stc_cb_ret_e __insert_restriction_cb(const table_restrictions_info *info,
 
        FREE(key.app_id);
        FREE(key.ifname);
-       FREE(key.imsi);
+       FREE(key.subscriber_id);
        return ret;
 }
 
@@ -1510,11 +1510,13 @@ static void __excn_hash_foreach_print(gpointer key, gpointer value,
                process_name, exe_type);
 }
 
+#if 0
 static void __excn_hash_printall(void)
 {
        g_hash_table_foreach(g_system->excns_hash,
                __excn_hash_foreach_print, NULL);
 }
+#endif
 
 static gboolean __remove_exception_app(gpointer key, gpointer value,
                                        gpointer data)
@@ -1880,7 +1882,7 @@ stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info)
 
        key.app_id = g_strdup(info->app_id);
        key.ifname = g_strdup(info->ifname);
-       key.imsi = g_strdup(info->imsi);
+       key.subscriber_id = g_strdup(info->subscriber_id);
        key.iftype = info->iftype;
        key.roaming = info->roaming;
 
@@ -1905,7 +1907,7 @@ stc_error_e stc_monitor_rstns_tree_add(const table_restrictions_info *info)
 
        FREE(key.app_id);
        FREE(key.ifname);
-       FREE(key.imsi);
+       FREE(key.subscriber_id);
        return ret;
 }
 
@@ -1916,7 +1918,7 @@ stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info)
        stc_rstn_key_s key = {
                .app_id = g_strdup(info->app_id),
                .ifname = g_strdup(info->ifname),
-               .imsi = g_strdup(info->imsi),
+               .subscriber_id = g_strdup(info->subscriber_id),
                .iftype = info->iftype,
                .roaming = info->roaming,
        };
@@ -1931,7 +1933,7 @@ stc_error_e stc_monitor_rstns_tree_remove(const table_restrictions_info *info)
 
        FREE(key.app_id);
        FREE(key.ifname);
-       FREE(key.imsi);
+       FREE(key.subscriber_id);
        return ret;
 }
 
index 8550e41..ab3d350 100755 (executable)
@@ -47,7 +47,7 @@ void __initialize_rstn_rule(table_restrictions_info *rule)
        rule->data_limit = 0;
        rule->data_warn_limit = 0;
        rule->roaming = STC_ROAMING_DISABLE;
-       rule->imsi = NULL;
+       rule->subscriber_id = NULL;
 }
 
 gboolean __validate_rstn_rule(table_restrictions_info *rule,
@@ -76,7 +76,7 @@ gboolean __validate_rstn_rule(table_restrictions_info *rule,
                return FALSE;
        }
 
-       if (rule->imsi == NULL) {
+       if (rule->subscriber_id == NULL) {
                __STC_LOG_FUNC_EXIT__;
                return FALSE;
        }
@@ -121,8 +121,8 @@ void __stc_restriction_app_info_builder_add(GVariantBuilder *builder,
        g_variant_builder_add(builder, "{sv}", "roaming",
                              g_variant_new_uint16(info->roaming));
 
-       g_variant_builder_add(builder, "{sv}", "imsi",
-                             g_variant_new_string(info->imsi));
+       g_variant_builder_add(builder, "{sv}", "subscriber_id",
+                             g_variant_new_string(info->subscriber_id));
 
        __STC_LOG_FUNC_EXIT__;
 }
@@ -206,11 +206,11 @@ static void __stc_extract_restriction_rule(const char *key, GVariant *value,
                rule->roaming = g_variant_get_uint16(value);
                STC_LOGD("roaming: [%u]", rule->roaming);
 
-       } else if (!g_strcmp0(key, "imsi")) {
+       } else if (!g_strcmp0(key, "subscriber_id")) {
                guint str_length;
                const gchar *str = g_variant_get_string(value, &str_length);
-               rule->imsi = g_strdup(str);
-               STC_LOGD("imsi: [%s]", rule->imsi);
+               rule->subscriber_id = g_strdup(str);
+               STC_LOGD("subscriber_id: [%s]", rule->subscriber_id);
 
        } else {
                STC_LOGD("Unknown select rule");
@@ -322,7 +322,7 @@ gboolean handle_restriction_unset(StcRestriction *object,
                return TRUE;
        }
 
-       table_restrictions_delete(rule.app_id, rule.iftype, rule.imsi);
+       table_restrictions_delete(rule.app_id, rule.iftype, rule.subscriber_id);
        /* remove restriction rule from runtime structure */
        stc_monitor_rstns_tree_remove(&rule);
 
index b20e3bb..fd4544d 100755 (executable)
@@ -113,10 +113,10 @@ void __stc_extract_reset_rule(const char *key, GVariant *value,
                rule->app_id = g_variant_dup_string(value, &len);
                STC_LOGD("app_id: [%s]", rule->app_id);
 
-       } else if (!g_strcmp0(key, "imsi")) {
+       } else if (!g_strcmp0(key, "subscriber_id")) {
                gsize len = 0;
-               rule->imsi = g_variant_dup_string(value, &len);
-               STC_LOGD("imsi: [%s]", rule->imsi);
+               rule->subscriber_id = g_variant_dup_string(value, &len);
+               STC_LOGD("subscriber_id: [%s]", rule->subscriber_id);
 
        } else if (!g_strcmp0(key, "iftype")) {
                rule->iftype = g_variant_get_uint16(value);
@@ -175,8 +175,8 @@ void __stc_statistics_app_info_builder_add(GVariantBuilder *builder,
                g_variant_builder_add(builder, "{sv}", "ifname",
                                      g_variant_new_string(info->ifname));
 
-       g_variant_builder_add(builder, "{sv}", "imsi",
-                             g_variant_new_string(info->imsi));
+       g_variant_builder_add(builder, "{sv}", "subscriber_id",
+                             g_variant_new_string(info->subscriber_id));
 
        g_variant_builder_add(builder, "{sv}", "iftype",
                              g_variant_new_uint16(info->iftype));
@@ -412,7 +412,7 @@ gboolean handle_statistics_reset(StcStatistics *object,
 
 handle_error:
        FREE(rule.app_id);
-       FREE(rule.imsi);
+       FREE(rule.subscriber_id);
        FREE(rule.interval);
        __STC_LOG_FUNC_EXIT__;
        return TRUE;