Prepare database queries during PrivilegeDb singleton init
[platform/core/security/security-manager.git] / src / common / include / privilege_db.h
index 34a4ed1..1df7723 100644 (file)
@@ -52,6 +52,7 @@ enum class QueryType {
     EPkgIdExists,
     EGetPkgId,
     EGetPrivilegeGroups,
+    EGetUserApps,
 };
 
 class PrivilegeDb {
@@ -77,9 +78,24 @@ private:
         { QueryType::EPkgIdExists, "SELECT * FROM pkg WHERE name=?" },
         { QueryType::EGetPkgId, " SELECT pkg_name FROM app_pkg_view WHERE app_name = ?" },
         { QueryType::EGetPrivilegeGroups, " SELECT name FROM privilege_group_view WHERE privilege_name = ?" },
+        { QueryType::EGetUserApps, "SELECT name FROM app WHERE uid=?" },
     };
 
     /**
+     * Container for initialized DataCommands, prepared for binding.
+     */
+    std::vector<DB::SqlConnection::DataCommandAutoPtr> m_commands;
+
+    /**
+     * Fills empty m_commands map with sql commands prepared for binding.
+     *
+     * Because the "sqlite3_prepare_v2" function takes many cpu cycles, the PrivilegeDb
+     * is optimized to call it only once for one query type.
+     * Designed to be used in the singleton contructor.
+     */
+    void initDataCommands();
+
+    /**
      * Check if pkgId is already registered in database
      *
      * @param pkgId - package identifier
@@ -197,6 +213,16 @@ public:
     void GetPrivilegeGroups(const std::string &privilege,
         std::vector<std::string> &grp_names);
 
+    /**
+     * Retrieve list of apps assigned to user
+     *
+     * @param uid - user identifier
+     * @param[out] apps - list of apps assigned to user,
+     *                    this parameter do not need to be empty, but
+     *                    it is being overwritten during function call.
+     * @exception DB::SqlConnection::Exception::InternalError on internal error
+     */
+    void GetUserApps(uid_t uid, std::vector<std::string> &apps);
 };
 
 } //namespace SecurityManager