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