Add packaging for database::handle
[platform/core/security/vist.git] / interface-draft.md
1 # Programming interface for client
2
3 ---
4
5 # #1. Execute query
6 ## Check smack table schema
7 ### 'smack' table
8 | name | type |
9 |---|---|
10 | subject_label | TEXT |
11 | object_label | TEXT |
12 | access_type | TEXT |
13 | permission | TEXT |
14
15 ## Use OsqueryManager to get smack information
16 ```cpp
17   using namespace osquerypp;
18   
19   // 1. Write query as std::string
20   std::string query = "SELECT subject_label, object_label FROM smack WHERE access_type = 'read'";
21    
22   // 2. Load OsqueryManager
23   auto manager = OsqueryManager::Load();
24    
25   // 3. Execute query by using OsqueryManager
26   auto rows = OsqueryManager::executeQuery(query);
27    
28   // 4. Get result
29   for (const auto& row : rows) {
30       std::string slabel = row["subject_label"];
31       std::string olabel = row["object_label];
32   }
33 ```
34
35 # #2. Subscribe event table
36 ## Check smack_deny_events table schema
37 - The name of the event table ends with *_events.
38 ### 'smack_deny_events' table
39 | name | type |
40 |---|---|
41 | action | TEXT |
42 | subject_label | TEXT |
43 | object_label | TEXT |
44 | access_type | TEXT |
45 | permission | TEXT |
46 | requested | TEXT |
47 | pid | INTEGER |
48
49 ## Use OsqueryManager to subscribe smack-deny-events
50 ```cpp
51   using namespace osquerypp;
52   
53   // 1. Write callback function
54   auto  onDeny = [&](const EventContext& ec, const Row& row)
55     {
56       // get data of event table
57       std::cout << row["action"] << std::endl;
58       std::cout << row["permission"] << std::endl;
59       std::cout << row["subject_label"] << std::endl;
60       std::cout << row["object_label"] << std::endl;
61     }
62     
63   // 2. Load OsqueryManager
64   auto manager = OsqueryManager::Load();
65    
66   // 3. Register callback with event_table by using OsqueryManager
67   OsqueryManager::subscribe("smack_deny_events", onDeny);
68 ```