Add multi-user support.
[platform/core/pim/libaccounts-svc.git] / include / account-private.h
1 /*
2  *  account
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Wonyoung Lee <wy1115.lee@samsung.com>, Sungchan Kim <sungchan81.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __ACCOUNT_PRIVATE_TYPES_H__
23 #define __ACCOUNT_PRIVATE_TYPES_H__
24
25
26 /*#include <glib.h>*/
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31
32 #include <glib.h>
33 #include <dlog.h>
34 #include <tzplatform_config.h>
35
36 #ifdef LOG_TAG
37 #undef LOG_TAG
38 #endif
39
40 #define LOG_TAG "ACCOUNT"
41
42 #define ACCOUNT_VERBOSE(fmt, arg...) \
43                 LOGV(": " fmt "\n", ##arg);
44 #define ACCOUNT_DEBUG(fmt, arg...) \
45                 LOGD(": " fmt "\n", ##arg);
46 #define ACCOUNT_INFO(fmt, arg...) \
47                 LOGI(": " fmt "\n", ##arg);
48 #define ACCOUNT_WARNING(fmt, arg...) \
49                 LOGW(": " fmt "\n", ##arg);
50 #define ACCOUNT_ERROR(fmt, arg...) \
51                 LOGW(": " fmt "\n", ##arg);
52 #define ACCOUNT_FATAL(fmt, arg...) \
53                 LOGF(": " fmt "\n", ##arg);
54
55 #define ACCOUNT_RETURN_VAL(eval, expr, ret_val, X)\
56         if (!(eval)) \
57 {\
58         expr; \
59         if (1)\
60         {ACCOUNT_ERROR X;}\
61         return ret_val;\
62 } else {;}
63
64 #define ACCOUNT_SNPRINTF(dest,size,format,arg...)       \
65         do { \
66                         snprintf(dest,size-1,format,##arg); \
67         }while(0)
68         /*      If the same pointer is passed to free twice,    known as a double free. To avoid this, set pointers to
69 NULL after passing      them to free: free(NULL) is safe (it does nothing).
70          */
71
72 #define ACCOUNT_MEMSET(dest,value,size) \
73         do { \
74                         memset(dest,value,size); \
75         }while(0)
76
77 #define ACCOUNT_CATCH_ERROR(eval, expr, error_val, X) \
78         if (!(eval)) \
79 {\
80         expr; \
81         error_code = (error_val);\
82         if (1)\
83         {ACCOUNT_ERROR X;}\
84         goto CATCH;\
85 } else {;}
86
87 #define _ACCOUNT_FREE(ptr)      \
88                 if (ptr != NULL) {      \
89                         free(ptr);      \
90                         ptr = NULL; \
91                 }       \
92
93
94 #define _ACCOUNT_GFREE(ptr)     \
95                                 if (ptr != NULL) {      \
96                                         g_free(ptr);    \
97                                         ptr = NULL; \
98                                 }       \
99
100 #define ACCOUNT_DB_NAME tzplatform_mkpath(TZ_SYS_DB, ".account.db")
101 #define ACCOUNT_TABLE "account"
102 #define CAPABILITY_TABLE "capability"
103 #define ACCOUNT_CUSTOM_TABLE "account_custom"
104 #define ACCOUNT_TYPE_TABLE "account_type"
105 #define LABEL_TABLE "label"
106 #define PROVIDER_FEATURE_TABLE "provider_feature"
107 #define ACCOUNT_SQLITE_SEQ "sqlite_sequence"
108 #define ACCOUNT_SQL_LEN_MAX     1024
109 #define ACCOUNT_TABLE_TOTAL_COUNT       6
110
111 typedef struct _account_s
112 {
113         int                     id;
114         char*           user_name;
115         char*           email_address;
116         char*           display_name;
117         char*           icon_path;
118         char*           source;
119         char*           package_name;
120         char*           access_token;
121         char*           domain_name;            /*< domain name [Ex: google, facebook, twitter, samsung, ...] */
122         int                     auth_type;
123         int             secret;
124         int             sync_support;
125         int                     user_data_int[USER_INT_CNT];
126         char*           user_data_txt[USER_TXT_CNT];
127         GSList*         capablity_list;
128         GList*          account_list;
129         GSList*         custom_list;
130 }account_s;
131
132 typedef struct _capability_s
133 {
134         int id;
135         char* type;
136         int value;
137         char* package_name;
138         char* user_name;
139         int account_id;
140 }account_capability_s;
141
142
143 typedef struct _account_custom_s
144 {
145         int     account_id;
146         char*   app_id;
147         char*   key;
148         char*   value;
149 }account_custom_s;
150
151 typedef struct _account_type_s
152 {
153         int     id;
154         char*   app_id;
155         char*   service_provider_id;
156         char*   icon_path;
157         char*   small_icon_path;
158         bool    multiple_account_support;
159         GSList* label_list;
160         GList*  account_type_list;
161         GSList* provider_feature_list;
162 }account_type_s;
163
164
165 typedef struct _label_s
166 {
167         char* app_id;
168         char* label;
169         char* locale;
170 }label_s;
171
172 typedef struct _provider_feature_s
173 {
174         char* key;
175         char* app_id;
176 }provider_feature_s;
177
178 typedef struct _account_subscribe_s
179 {
180         account_event_cb account_subscription_callback;
181         void* user_data;
182 }account_subscribe_s;
183
184 /**
185  * @brief   Enumarations for account handle fields.
186  */
187
188 typedef enum {
189         ACCOUNT_FIELD_NONE = -1,
190         ACCOUNT_FIELD_ID,
191         ACCOUNT_FIELD_USER_NAME,
192         ACCOUNT_FIELD_EMAIL_ADDRESS,
193         ACCOUNT_FIELD_DISPLAY_NAME,
194         ACCOUNT_FIELD_ICON_PATH,
195         ACCOUNT_FIELD_SOURCE,
196         ACCOUNT_FIELD_PACKAGE_NAME,
197         ACCOUNT_FIELD_ACCESS_TOKEN,
198         ACCOUNT_FIELD_DOMAIN_NAME,
199         ACCOUNT_FIELD_AUTH_TYPE,
200         ACCOUNT_FIELD_SECRET,
201         ACCOUNT_FIELD_SYNC_SUPPORT,
202         ACCOUNT_FIELD_USER_TEXT_0,
203         ACCOUNT_FIELD_USER_TEXT_1,
204         ACCOUNT_FIELD_USER_TEXT_2,
205         ACCOUNT_FIELD_USER_TEXT_3,
206         ACCOUNT_FIELD_USER_TEXT_4,
207         ACCOUNT_FIELD_USER_INT_0,
208         ACCOUNT_FIELD_USER_INT_1,
209         ACCOUNT_FIELD_USER_INT_2,
210         ACCOUNT_FIELD_USER_INT_3,
211         ACCOUNT_FIELD_USER_INT_4,
212         ACCOUNT_DB_FIELD_END,
213 } ACCOUNT_DB_IDX;
214
215 /**
216  * @brief       Enumarations for capability fields.
217  */
218
219 typedef enum {
220         CAPABILITY_FIELD_NONE = -1,
221         CAPABILITY_FIELD_ID,
222         CAPABILITY_FIELD_KEY,
223         CAPABILITY_FIELD_VALUE,
224         CAPABILITY_FIELD_PACKAGE_NAME,
225         CAPABILITY_FIELD_USER_NAME,
226         CAPABILITY_FIELD_ACCOUNT_ID,
227         CAPABILITY_FIELD_END,
228 }CAPABILITY_DB_IDX;
229
230
231 typedef enum {
232         ACCOUNT_CUSTOM_FIELD_NONE = -1,
233         ACCOUNT_CUSTOM_FIELD_ACCOUNT_ID,
234         ACCOUNT_CUSTOM_FIELD_APP_ID,
235         ACCOUNT_CUSTOM_FIELD_KEY,
236         ACCOUNT_CUSTOM_FIELD_VALUE,
237         ACCOUNT_CUSTOM_FIELD_END,
238 }ACCOUNT_CUSTOM_DB_IDX;
239
240 typedef enum {
241         ACCOUNT_TYPE_FIELD_NONE = -1,
242         ACCOUNT_TYPE_FIELD_ID,
243         ACCOUNT_TYPE_FIELD_APP_ID,
244         ACCOUNT_TYPE_FIELD_SERVICE_PROVIDER_ID,
245         ACCOUNT_TYPE_FIELD_ICON_PATH,
246         ACCOUNT_TYPE_FIELD_SMALL_ICON_PATH,
247         ACCOUNT_TYPE_FIELD_MULTIPLE_ACCOUNT_SUPPORT,
248         ACCOUNT_TYPE_FIELD_END,
249 }ACCOUNT_TYPE_DB_IDX;
250
251 typedef enum {
252         LABEL_FIELD_NONE = -1,
253         LABEL_FIELD_APP_ID,
254         LABEL_FIELD_LABEL,
255         LABEL_FIELD_LOCALE,
256         LABEL_FIELD_END,
257 }LABEL_DB_IDX;
258
259 typedef enum {
260         PROVIDER_FEATURE_FIELD_NONE = -1,
261         PROVIDER_FEATURE_FIELD_APP_ID,
262         PROVIDER_FEATURE_FIELD_KEY,
263         PROVIDER_FEATURE_FIELD_END,
264 }PROVIDER_FEATURE_DB_IDX;
265
266 typedef sqlite3_stmt* account_stmt;
267
268 #define ACCOUNT_SCHEMA  "create table %s \n"\
269         "(\n"\
270 "_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
271 "user_name TEXT, "\
272 "email_address TEXT, "\
273 "display_name TEXT, "\
274 "icon_path TEXT, "\
275 "source TEXT, "\
276 "package_name TEXT, "\
277 "access_token TEXT, "\
278 "domain_name TEXT, "\
279 "auth_type INTEGER, "\
280 "secret INTEGER, "\
281 "sync_support INTEGER, "\
282 "txt_custom0 TEXT, "\
283 "txt_custom1 TEXT, "\
284 "txt_custom2 TEXT, "\
285 "txt_custom3 TEXT, "\
286 "txt_custom4 TEXT, "\
287 "int_custom0 INTEGER, "\
288 "int_custom1 INTEGER, "\
289 "int_custom2 INTEGER, "\
290 "int_custom3 INTEGER, "\
291 "int_custom4 INTEGER "\
292 ");"
293
294 #define CAPABILITY_SCHEMA  "create table %s \n"\
295         "(\n"\
296 "_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
297 "key TEXT, "\
298 "value INTEGER, "\
299 "package_name TEXT, "\
300 "user_name TEXT, "\
301 "account_id INTEGER "\
302 ");"
303
304 #define ACCOUNT_CUSTOM_SCHEMA  "create table %s \n"\
305         "(\n"\
306 "AccountId INTEGER, "\
307 "AppId TEXT, "\
308 "Key TEXT, "\
309 "Value TEXT "\
310 ");"
311
312 #define ACCOUNT_TYPE_SCHEMA "create table %s \n"\
313         "(\n"\
314 "_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
315 "AppId TEXT, "\
316 "ServiceProviderId TEXT, "\
317 "IconPath TEXT, "\
318 "SmallIconPath TEXT, "\
319 "MultipleAccountSupport INTEGER "\
320 ");"
321
322 #define LABEL_SCHEMA "create table %s \n"\
323         "(\n"\
324 "AppId TEXT, "\
325 "Label TEXT, "\
326 "Locale TEXT"\
327 ");"
328
329 #define PROVIDER_FEATURE_SCHEMA "create table %s \n"\
330         "(\n"\
331 "app_id TEXT, "\
332 "key TEXT "\
333 ");"
334
335 typedef struct GSList           account_iterator_s;
336
337 #ifdef __cplusplus
338 }
339 #endif
340
341 #endif /* __SLP_ACCOUNT_PRIVATE_TYPES_H__*/