tizen 2.3.1 release
[framework/account/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 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30
31 #include <glib.h>
32 #include <dlog.h>
33
34 #ifdef LOG_TAG
35 #undef LOG_TAG
36 #endif
37
38 #define LOG_TAG "ACCOUNT"
39
40 #define ACCOUNT_VERBOSE(fmt, arg...) \
41                 LOGD(": " fmt "\n", ##arg);
42 #define ACCOUNT_DEBUG(fmt, arg...) \
43                 LOGD(": " fmt "\n", ##arg);
44 #define ACCOUNT_ERROR(fmt, arg...) \
45                 LOGE(": " fmt "\n", ##arg);
46 #define ACCOUNT_FATAL(fmt, arg...) \
47                 LOGF(": " fmt "\n", ##arg);
48 #define ACCOUNT_SLOGD(fmt, arg...) \
49                 SECURE_LOGD(": " fmt "\n", ##arg);
50 #define ACCOUNT_SLOGI(fmt, arg...) \
51                 SECURE_LOGI(": " fmt "\n", ##arg);
52 #define ACCOUNT_SLOGE(fmt, arg...) \
53                 SECURE_LOGE(": " fmt "\n", ##arg);
54
55 #define ACCOUNT_RETURN_VAL(eval, expr, ret_val, X)\
56         if (!(eval)) \
57 {\
58         expr; \
59         return ret_val;\
60 } else {;}
61
62 #define ACCOUNT_SNPRINTF(dest,size,format,arg...)       \
63         do { \
64                         snprintf(dest,size-1,format,##arg); \
65         }while(0)
66         /*      If the same pointer is passed to free twice,    known as a double free. To avoid this, set pointers to
67 NULL after passing      them to free: free(NULL) is safe (it does nothing).
68          */
69
70 #define ACCOUNT_MEMSET(dest,value,size) \
71         do { \
72                         memset(dest,value,size); \
73         }while(0)
74
75 #define ACCOUNT_CATCH_ERROR(eval, expr, error_val, X) \
76         if (!(eval)) \
77 {\
78         expr; \
79         error_code = (error_val);\
80         goto CATCH;\
81 } else {;}
82
83 #define _ACCOUNT_FREE(ptr)      \
84                 if (ptr != NULL) {      \
85                         free(ptr);      \
86                         ptr = NULL; \
87                 }       \
88
89
90 #define _ACCOUNT_GFREE(ptr)     \
91                                 if (ptr != NULL) {      \
92                                         g_free(ptr);    \
93                                         ptr = NULL; \
94                                 }       \
95
96 #define ACCOUNT_DB_NAME "/opt/usr/dbspace/.account.db"
97 #define ACCOUNT_TABLE "account"
98 #define CAPABILITY_TABLE "capability"
99 #define ACCOUNT_CUSTOM_TABLE "account_custom"
100 #define ACCOUNT_TYPE_TABLE "account_type"
101 #define LABEL_TABLE "label"
102 #define PROVIDER_FEATURE_TABLE "provider_feature"
103 #define ACCOUNT_SQLITE_SEQ "sqlite_sequence"
104 #define ACCOUNT_SQL_LEN_MAX     1024
105 #define ACCOUNT_TABLE_TOTAL_COUNT       6
106
107 #define FACEBOOK_PKG_NAME               "com.samsung.facebook"
108 #define EMAIL_PKG_NAME                  "email-setting-efl"
109 #define EXCHANGE_PKG_NAME               "activesync-ui"
110 #define IMS_SERVICE_PKG_NAME            "ims-service"
111 #define SAMSUNGACCOUNTFRONT_PKG_NAME  "com.samsung.samsung-account-front"
112 //#define SAMSUNGACCOUNT_PKG_NAME  "gr47by21a5.SamsungAccount"
113 #define SAMSUNGACCOUNT_PKG_NAME  "com.samsung.samsungaccount"
114 #define CHATON_PKG_NAME                         "xnq5eh9vop.ChatON"
115 #define DROPBOX_PKG_NAME  "com.samsung.dropbox"
116 #define SYNCHRONISE_PKG_NAME "setting-synchronise-efl"
117
118 #define USER_TXT_CNT 5
119 #define USER_INT_CNT 5
120
121
122 /* account uri list */
123 #define ACCOUNT_DATA_SERVICE_PROVIDER                     "http://tizen.org/account/data/service_provider"
124 #define ACCOUNT_OPERATION_SIGNIN_OLD                      "http://tizen.org/account/operation/signin"
125
126 // private account operation type
127 #define ACCOUNT_OPERATION_FMM                             "http://tizen.org/account/operation/fmm"
128 #define ACCOUNT_OPERATION_MYACCOUNT                       "http://tizen.org/account/operation/signin_from_myaccount"
129 // End of private account operation type
130
131 #define ACCOUNT_SUPPORTS_CAPABILITY_POST                  "http://tizen.org/account/capability/post"
132 #define ACCOUNT_SUPPORTS_CAPABILITY_VOIP                  "http://tizen.org/account/capability/voip"
133 #define ACCOUNT_SUPPORTS_CAPABILITY_SAMSUNG_APPS          "http://tizen.org/account/capability/samsungapps"
134 #define ACCOUNT_SUPPORTS_CAPABILITY_TASK                  "http://tizen.org/account/capability/task"
135 #define ACCOUNT_SUPPORTS_CAPABILITY_MOBILE_TRACKER        "http://tizen.org/account/capability/mobiletracker"
136 #define ACCOUNT_SUPPORTS_CAPABILITY_S_NOTE                "http://tizen.org/account/capability/snote"
137 #define ACCOUNT_SUPPORTS_CAPABILITY_GALLERY               "http://tizen.org/account/capability/gallery"
138 #define ACCOUNT_SUPPORTS_CAPABILITY_MEMO                  "http://tizen.org/account/capability/memo"
139 #define ACCOUNT_SUPPORTS_CAPABILITY_CHAT                  "http://tizen.org/account/capability/chat"
140 #define ACCOUNT_SUPPORTS_CAPABILITY_BOOKMARK              "http://tizen.org/account/capability/bookmark"
141 #define ACCOUNT_SUPPORTS_CAPABILITY_SYNCHRONISE           "http://tizen.org/account/capability/synchronise"
142 #define ACCOUNT_SUPPORTS_CAPABILITY_TIZEN_EMAIL           "http://tizen.org/account/capability/tizen_email"
143 #define ACCOUNT_SUPPORTS_CAPABILITY_INTERNET              "http://tizen.org/account/capability/internet"
144 #define ACCOUNT_SUPPORTS_CAPABILITY_DOCOMO_SCHEDULE_MEMO  "http://tizen.org/account/capability/docomo"
145 /* end of account uri list */
146
147 typedef struct _account_s
148 {
149         int                     id;
150         char*           user_name;
151         char*           email_address;
152         char*           display_name;
153         char*           icon_path;
154         char*           source;
155         char*           package_name;
156         char*           access_token;
157         char*           domain_name;            /*< domain name [Ex: google, facebook, twitter, samsung, ...] */
158         int                     auth_type;
159         int             secret;
160         int             sync_support;
161         int                     user_data_int[USER_INT_CNT];
162         char*           user_data_txt[USER_TXT_CNT];
163         GSList*         capablity_list;
164         GList*          account_list;
165         GSList*         custom_list;
166 }account_s;
167
168 typedef struct _capability_s
169 {
170         int id;
171         char* type;
172         int value;
173         char* package_name;
174         char* user_name;
175         int account_id;
176 }account_capability_s;
177
178
179 typedef struct _account_custom_s
180 {
181         int     account_id;
182         char*   app_id;
183         char*   key;
184         char*   value;
185 }account_custom_s;
186
187 typedef struct _account_type_s
188 {
189         int     id;
190         char*   app_id;
191         char*   service_provider_id;
192         char*   icon_path;
193         char*   small_icon_path;
194         bool    multiple_account_support;
195         GSList* label_list;
196         GList*  account_type_list;
197         GSList* provider_feature_list;
198 }account_type_s;
199
200
201 typedef struct _label_s
202 {
203         char* app_id;
204         char* label;
205         char* locale;
206 }label_s;
207
208 typedef struct _provider_feature_s
209 {
210         char* key;
211         char* app_id;
212 }provider_feature_s;
213
214 typedef struct _account_subscribe_s
215 {
216         account_event_cb account_subscription_callback;
217         void* user_data;
218 }account_subscribe_s;
219
220 /**
221  * @brief   Enumarations for account handle fields.
222  */
223
224 typedef enum {
225         ACCOUNT_FIELD_NONE = -1,
226         ACCOUNT_FIELD_ID,
227         ACCOUNT_FIELD_USER_NAME,
228         ACCOUNT_FIELD_EMAIL_ADDRESS,
229         ACCOUNT_FIELD_DISPLAY_NAME,
230         ACCOUNT_FIELD_ICON_PATH,
231         ACCOUNT_FIELD_SOURCE,
232         ACCOUNT_FIELD_PACKAGE_NAME,
233         ACCOUNT_FIELD_ACCESS_TOKEN,
234         ACCOUNT_FIELD_DOMAIN_NAME,
235         ACCOUNT_FIELD_AUTH_TYPE,
236         ACCOUNT_FIELD_SECRET,
237         ACCOUNT_FIELD_SYNC_SUPPORT,
238         ACCOUNT_FIELD_USER_TEXT_0,
239         ACCOUNT_FIELD_USER_TEXT_1,
240         ACCOUNT_FIELD_USER_TEXT_2,
241         ACCOUNT_FIELD_USER_TEXT_3,
242         ACCOUNT_FIELD_USER_TEXT_4,
243         ACCOUNT_FIELD_USER_INT_0,
244         ACCOUNT_FIELD_USER_INT_1,
245         ACCOUNT_FIELD_USER_INT_2,
246         ACCOUNT_FIELD_USER_INT_3,
247         ACCOUNT_FIELD_USER_INT_4,
248         ACCOUNT_DB_FIELD_END,
249 } ACCOUNT_DB_IDX;
250
251 /**
252  * @brief       Enumarations for capability fields.
253  */
254
255 typedef enum {
256         CAPABILITY_FIELD_NONE = -1,
257         CAPABILITY_FIELD_ID,
258         CAPABILITY_FIELD_KEY,
259         CAPABILITY_FIELD_VALUE,
260         CAPABILITY_FIELD_PACKAGE_NAME,
261         CAPABILITY_FIELD_USER_NAME,
262         CAPABILITY_FIELD_ACCOUNT_ID,
263         CAPABILITY_FIELD_END,
264 }CAPABILITY_DB_IDX;
265
266
267 typedef enum {
268         ACCOUNT_CUSTOM_FIELD_NONE = -1,
269         ACCOUNT_CUSTOM_FIELD_ACCOUNT_ID,
270         ACCOUNT_CUSTOM_FIELD_APP_ID,
271         ACCOUNT_CUSTOM_FIELD_KEY,
272         ACCOUNT_CUSTOM_FIELD_VALUE,
273         ACCOUNT_CUSTOM_FIELD_END,
274 }ACCOUNT_CUSTOM_DB_IDX;
275
276 typedef enum {
277         ACCOUNT_TYPE_FIELD_NONE = -1,
278         ACCOUNT_TYPE_FIELD_ID,
279         ACCOUNT_TYPE_FIELD_APP_ID,
280         ACCOUNT_TYPE_FIELD_SERVICE_PROVIDER_ID,
281         ACCOUNT_TYPE_FIELD_ICON_PATH,
282         ACCOUNT_TYPE_FIELD_SMALL_ICON_PATH,
283         ACCOUNT_TYPE_FIELD_MULTIPLE_ACCOUNT_SUPPORT,
284         ACCOUNT_TYPE_FIELD_END,
285 }ACCOUNT_TYPE_DB_IDX;
286
287 typedef enum {
288         LABEL_FIELD_NONE = -1,
289         LABEL_FIELD_APP_ID,
290         LABEL_FIELD_LABEL,
291         LABEL_FIELD_LOCALE,
292         LABEL_FIELD_END,
293 }LABEL_DB_IDX;
294
295 typedef enum {
296         PROVIDER_FEATURE_FIELD_NONE = -1,
297         PROVIDER_FEATURE_FIELD_APP_ID,
298         PROVIDER_FEATURE_FIELD_KEY,
299         PROVIDER_FEATURE_FIELD_END,
300 }PROVIDER_FEATURE_DB_IDX;
301
302 typedef sqlite3_stmt* account_stmt;
303
304 //ACCOUNT_TABLE
305 #define ACCOUNT_SCHEMA  "create table account \n"\
306         "(\n"\
307 "_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
308 "user_name TEXT, "\
309 "email_address TEXT, "\
310 "display_name TEXT, "\
311 "icon_path TEXT, "\
312 "source TEXT, "\
313 "package_name TEXT, "\
314 "access_token TEXT, "\
315 "domain_name TEXT, "\
316 "auth_type INTEGER, "\
317 "secret INTEGER, "\
318 "sync_support INTEGER, "\
319 "txt_custom0 TEXT, "\
320 "txt_custom1 TEXT, "\
321 "txt_custom2 TEXT, "\
322 "txt_custom3 TEXT, "\
323 "txt_custom4 TEXT, "\
324 "int_custom0 INTEGER, "\
325 "int_custom1 INTEGER, "\
326 "int_custom2 INTEGER, "\
327 "int_custom3 INTEGER, "\
328 "int_custom4 INTEGER "\
329 ");"
330
331 //CAPABILITY_TABLE
332 #define CAPABILITY_SCHEMA  "create table capability \n"\
333         "(\n"\
334 "_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
335 "key TEXT, "\
336 "value INTEGER, "\
337 "package_name TEXT, "\
338 "user_name TEXT, "\
339 "account_id INTEGER "\
340 ");"
341
342 //ACCOUNT_CUSTOM_TABLE
343 #define ACCOUNT_CUSTOM_SCHEMA  "create table account_custom \n"\
344         "(\n"\
345 "AccountId INTEGER, "\
346 "AppId TEXT, "\
347 "Key TEXT, "\
348 "Value TEXT "\
349 ");"
350
351 //ACCOUNT_TYPE_TABLE
352 #define ACCOUNT_TYPE_SCHEMA "create table account_type \n"\
353         "(\n"\
354 "_id INTEGER PRIMARY KEY AUTOINCREMENT, "\
355 "AppId TEXT, "\
356 "ServiceProviderId TEXT, "\
357 "IconPath TEXT, "\
358 "SmallIconPath TEXT, "\
359 "MultipleAccountSupport INTEGER "\
360 ");"
361
362 //LABEL_TABLE
363 #define LABEL_SCHEMA "create table label \n"\
364         "(\n"\
365 "AppId TEXT, "\
366 "Label TEXT, "\
367 "Locale TEXT"\
368 ");"
369
370 //PROVIDER_FEATURE_TABLE
371 #define PROVIDER_FEATURE_SCHEMA "create table provider_feature \n"\
372         "(\n"\
373 "app_id TEXT, "\
374 "key TEXT "\
375 ");"
376
377 typedef struct GSList           account_iterator_s;
378
379 #ifdef __cplusplus
380 }
381 #endif
382
383 #endif /* __SLP_ACCOUNT_PRIVATE_TYPES_H__*/