1 /**
2  * @file mega/account.h
3  * @brief Classes for manipulating Account data
4  *
5  * (c) 2013-2014 by Mega Limited, Auckland, New Zealand
6  *
7  * This file is part of the MEGA SDK - Client Access Engine.
8  *
9  * Applications using the MEGA API must present a valid application key
10  * and comply with the the rules set forth in the Terms of Service.
11  *
12  * The MEGA SDK is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * @copyright Simplified (2-clause) BSD License.
17  *
18  * You should have received a copy of the license along with this
19  * program.
20  */
21 
22 #ifndef MEGA_ACCOUNT_H
23 #define MEGA_ACCOUNT_H 1
24 
25 
26 namespace mega {
27 // account details/history
28 struct MEGA_API AccountBalance
29 {
30     double amount;
31     char currency[4];
32 };
33 
34 struct MEGA_API AccountSession
35 {
36     m_time_t timestamp, mru;
37     string useragent;
38     string ip;
39     char country[3];
40     int current;
41     handle id;
42     int alive;
43 };
44 
45 struct MEGA_API AccountPurchase
46 {
47     m_time_t timestamp;
48     char handle[12];
49     char currency[4];
50     double amount;
51     int method;
52 };
53 
54 struct MEGA_API AccountTransaction
55 {
56     m_time_t timestamp;
57     char handle[12];
58     char currency[4];
59     double delta;
60 };
61 
62 
63 // subtree's total storage footprint (excluding the root folder itself)
64 struct MEGA_API NodeStorage
65 {
66     m_off_t bytes;
67     uint32_t files;
68     uint32_t folders;
69     m_off_t version_bytes;
70     uint32_t version_files;
71 };
72 
73 typedef map<handle, NodeStorage> handlestorage_map;
74 
75 struct MEGA_API AccountDetails
76 {
77     // subscription information (summarized)
78     int pro_level = 0;
79     char subscription_type = 'O';
80     char subscription_cycle[4];
81     m_time_t subscription_renew = 0;
82     string subscription_method;
83 
84     m_time_t pro_until = 0;
85 
86     // quota related to the session account
87     m_off_t storage_used = 0;
88     m_off_t storage_max = 0;
89 
90     // Own user transfer
91     m_off_t transfer_max = 0;
92     m_off_t transfer_own_used = 0;
93     m_off_t transfer_srv_used = 0;  // 3rd party served quota to other users
94 
95     // ratio of your PRO transfer quota that is able to be served to 3rd party
96     double srv_ratio = 0;
97 
98     // storage used for all relevant nodes (root nodes, incoming shares)
99     handlestorage_map storage;
100 
101     // Free IP-based transfer quota related:
102     m_time_t transfer_hist_starttime = 0;   // transfer history start timestamp
103     m_time_t transfer_hist_interval = 3600; // timespan that a single transfer window record covers
104     vector<m_off_t> transfer_hist;          // transfer window - oldest to newest, bytes consumed per time interval
105     bool transfer_hist_valid = true;        // transfer hist valid for overquota accounts
106 
107     // Reserved transfer quota for ongoing transfers (currently ignored by clients)
108     m_off_t transfer_reserved = 0;      // free IP-based
109     m_off_t transfer_srv_reserved = 0;  // 3rd party
110     m_off_t transfer_own_reserved = 0;  // own account
111 
112     vector<AccountBalance> balances;
113     vector<AccountSession> sessions;
114     vector<AccountPurchase> purchases;
115     vector<AccountTransaction> transactions;
116 };
117 
118 // award classes with the award values the class is supposed to get
119 struct MEGA_API Achievement
120 {
121     m_off_t storage;
122     m_off_t transfer;
123     int expire;    // in days
124 };
125 
126 // awarded to the user
127 struct MEGA_API Award
128 {
129     achievement_class_id achievement_class;
130     int award_id;   // not unique, do not use it as key
131     m_time_t ts;
132     m_time_t expire;    // not compulsory, some awards don't expire
133     // int c;  --> always 0, will be removed (obsolete)
134 
135     // for invites only
136     vector<string> emails_invited;    // successfully invited user's emails
137     // int csu;  --> always 0, will be removed (obsolete)
138 };
139 
140 // reward the user has achieved and can see
141 struct MEGA_API Reward
142 {
143     int award_id;
144     m_off_t storage;
145     m_off_t transfer;
146     int expire;    // in days
147 };
148 
149 struct MEGA_API AchievementsDetails
150 {
151     m_off_t permanent_size;   // permanent base storage value
152     achievements_map achievements; // map<class_id, Achievement>
153     vector<Award> awards;
154     vector<Reward> rewards;
155 };
156 } // namespace
157 
158 #endif
159