upload tizen1.0 source
[pkgs/o/oma-ds-service.git] / ServiceEngine / SE_Storage.c
1 /*
2  * oma-ds-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JuHak Park <juhaki.park@samsung.com>,
7  *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
8  *          SunBong Ha <sunbong.ha@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24
25
26
27 /*
28  * For any sort of issue you concern as to this software,
29  * you may use following point of contact.
30  * All resources contributed on this software
31  * are orinigally written by S-Core Inc., a member of Samsung Group.
32  *
33  * SeongWon Shim <seongwon.shim@samsung.com>
34  */
35
36 /**
37  *   @SE_Storage.c
38  *   @version                                                                   0.1
39  *   @brief                                                                             This file is the source file of implementation of functions which saves and gets sync results
40  */
41
42 #include "stdlib.h"
43 #include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
44 #include "agent-framework/Utility/fw_log.h"
45 #include "Common/Common_Util.h"
46 #include "ServiceEngine/SE_Storage.h"
47 #include "ServiceEngine/SE_Common.h"
48
49 #define LOG_TAG "OMA_DS_SE"
50
51 static SE_ErrorType __write_sync_type(int accountId, AlertType alertType);
52 static SE_ErrorType __write_last_session_values(int accountId, SyncSessionResult syncSessionResult, int lastSessionTime);
53
54 static SE_ErrorType __write_sync_type(int accountId, AlertType alertType)
55 {
56         FW_LOGV("start");
57
58         SE_ErrorType err = SE_INTERNAL_OK;
59         bool result;
60
61         char *syncType = NULL;
62         switch (alertType) {
63         case ALERT_SLOW_SYNC:
64                 syncType = DEFINE_ALERT_SLOW_SYNC_STR;
65                 break;
66         case ALERT_TWO_WAY:
67                 syncType = DEFINE_ALERT_TWO_WAY_STR;
68                 break;
69         case ALERT_ONE_WAY_FROM_CLIENT:
70                 syncType = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR;
71                 break;
72         case ALERT_ONE_WAY_FROM_SERVER:
73                 syncType = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR;
74                 break;
75         case ALERT_REFRESH_FROM_SERVER:
76                 syncType = DEFINE_ALERT_REFRESH_FROM_SERVER_STR;
77                 break;
78         case ALERT_REFRESH_FROM_CLIENT:
79                 syncType = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR;
80                 break;
81         default:
82                 break;
83         }
84
85         result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
86         if (result == false) {
87                 FW_LOGE("failed in set_Config");
88                 err = SE_INTERNAL_DA_ERROR;
89                 goto error;
90         }
91
92
93         FW_LOGV("end");
94
95 error:
96
97         return err;
98
99 }
100
101 static SE_ErrorType __write_last_session_values(int accountId, SyncSessionResult syncSessionResult, int lastSessionTime)
102 {
103         FW_LOGV("start");
104
105         SE_ErrorType err = SE_INTERNAL_OK;
106         bool result;
107
108         result = set_config_int(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, syncSessionResult, "int", "SE");
109         if (result == false) {
110                 FW_LOGE("failed in set_config");
111                 err = SE_INTERNAL_DA_ERROR;
112                 goto error;
113         }
114
115         result = set_config_int(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, lastSessionTime, "int", "SE");
116         if (result == false) {
117                 FW_LOGE("failed in set_config");
118                 err = SE_INTERNAL_DA_ERROR;
119                 goto error;
120         }
121
122         FW_LOGV("end");
123
124 error:
125
126         return err;;
127 }
128
129 SE_ErrorType write_profile_data(int accountId, AlertType alertType, SyncSessionResult syncSessionResult, int lastSessionTime)
130 {
131         FW_LOGV("start");
132
133         SE_ErrorType err = SE_INTERNAL_OK;
134
135         err = __write_sync_type(accountId, alertType);
136         if (err != SE_INTERNAL_OK) {
137                 FW_LOGE("failed in writeSyncType");
138                 goto error;
139         }
140
141         err = __write_last_session_values(accountId, syncSessionResult, lastSessionTime);
142         if (err != SE_INTERNAL_OK) {
143                 FW_LOGE("failed in writeLastSessionValues");
144                 goto error;
145         }
146
147         int content_type;
148         for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
149                 if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
150                         err = write_sync_resource_info(accountId, alertType, content_type , lastSessionTime,
151                                         datastoreinfo_per_content_type[content_type]->clientSyncResult, datastoreinfo_per_content_type[content_type]->serverSyncResult);
152                         if (err != SE_INTERNAL_OK) {
153                                 FW_LOGE("failed in writeSyncResourceInfo");
154                                 goto error;
155                         }
156
157                         err = write_sync_statistics(accountId, content_type, false, datastoreinfo_per_content_type[content_type]->clientSyncResult);
158                         if (err != SE_INTERNAL_OK) {
159                                 FW_LOGE("failed in writeSyncStatistics");
160                                 goto error;
161                         }
162
163                         err = write_sync_statistics(accountId, content_type, true, datastoreinfo_per_content_type[content_type]->serverSyncResult);
164                         if (err != SE_INTERNAL_OK) {
165                                 FW_LOGE("failed in writeSyncStatistics");
166                                 goto error;
167                         }
168                 }
169         }
170
171         FW_LOGV("end");
172
173 error:
174         return err;
175 }
176
177 SE_ErrorType write_sync_statistics(int accountId, int content_type, bool isFromServer, SyncResult *pSyncResult)
178 {
179         FW_LOGV("start");
180
181         SE_ErrorType err = SE_INTERNAL_OK;
182
183         bool result;
184         char *datastore = NULL;
185         char *side = NULL;
186         char numberOfChangesPath[128];
187         char addCountPath[128];
188         char replaceCountPath[128];
189         char deleteCountPath[128];
190
191         if (content_type == TYPE_CONTACT)
192                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
193         else if (content_type == TYPE_CALENDAR)
194                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
195         else if (content_type == TYPE_MEMO)
196                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
197         else if (content_type == TYPE_CALLLOG)
198                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
199
200         if (isFromServer == true)
201                 side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER;
202         else
203                 side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT;
204
205         FW_LOGV("pSyncResult->numberOfChange = %d", pSyncResult->numberOfChange);
206         FW_LOGV("pSyncResult->add_count = %d", pSyncResult->add_count);
207         FW_LOGV("pSyncResult->replace_count = %d", pSyncResult->replace_count);
208         FW_LOGV("pSyncResult->delete_count = %d", pSyncResult->delete_count);
209
210         sprintf(numberOfChangesPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
211         sprintf(addCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
212         sprintf(replaceCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
213         sprintf(deleteCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
214
215         result = set_config_int(accountId, numberOfChangesPath, pSyncResult->numberOfChange, "int", "SE");
216         if (result == false) {
217                 FW_LOGE("failed in set_config");
218                 err = SE_INTERNAL_DA_ERROR;
219                 goto error;
220         }
221
222         result = set_config_int(accountId, addCountPath, pSyncResult->add_count, "int", "SE");
223         if (result == false) {
224                 FW_LOGE("failed in set_config");
225                 err = SE_INTERNAL_DA_ERROR;
226                 goto error;
227         }
228
229         result = set_config_int(accountId, replaceCountPath, pSyncResult->replace_count, "int", "SE");
230         if (result == false) {
231                 FW_LOGE("failed in set_config");
232                 err = SE_INTERNAL_DA_ERROR;
233                 goto error;
234         }
235
236         result = set_config_int(accountId, deleteCountPath, pSyncResult->delete_count, "int", "SE");
237         if (result == false) {
238                 FW_LOGE("failed in set_config");
239                 err = SE_INTERNAL_DA_ERROR;
240                 goto error;
241         }
242
243         FW_LOGV("end");
244
245 error:
246
247         return err;
248
249 }
250
251 SE_ErrorType write_sync_resource_info(int accountId, AlertType alertType, int content_type , int lastSessionTime,
252                                                                                                                         SyncResult *clientSyncResult, SyncResult *serverSyncResult)
253 {
254         FW_LOGV("start");
255
256         SE_ErrorType err = SE_INTERNAL_OK;
257         bool result;
258         char *datastore = NULL;
259         char dbSyncedPath[128];
260         char lastSessionTimePath[128];
261
262         if (content_type == TYPE_CONTACT)
263                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
264         else if (content_type == TYPE_CALENDAR)
265                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
266         else if (content_type == TYPE_MEMO)
267                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
268         else if (content_type == TYPE_CALLLOG)
269                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
270
271         FW_LOGV("clientSyncResult->sessionResult = %d", clientSyncResult->sessionResult);
272         FW_LOGV("serverSyncResult->sessionResult = %d", serverSyncResult->sessionResult);
273
274         char *dbSynced;
275         if (clientSyncResult->sessionResult == SYNC_SESSION_SUCCEEDED  &&
276                         (serverSyncResult->sessionResult == SYNC_SESSION_SUCCEEDED ||  alertType == ALERT_ONE_WAY_FROM_CLIENT || alertType == ALERT_REFRESH_FROM_CLIENT))
277                 dbSynced = DEFINE_DBSYNC_SUCCESS;
278         else if (clientSyncResult->sessionResult == SYNC_SESSION_STOPPED)
279                 dbSynced = DEFINE_DBSYNC_STOP;
280         else
281                 dbSynced = DEFINE_DBSYNC_FAIL;
282
283         FW_LOGV("dbSynced = %s", dbSynced);
284
285         sprintf(dbSyncedPath, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
286         sprintf(lastSessionTimePath, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
287
288         result = set_config_str(accountId, dbSyncedPath, dbSynced, "string", "SE");
289         if (result == false) {
290                 FW_LOGE("failed in set_config");
291                 err = SE_INTERNAL_DA_ERROR;
292                 goto error;
293         }
294
295         result = set_config_int(accountId, lastSessionTimePath, lastSessionTime, "int", "SE");
296         if (result == false) {
297                 FW_LOGE("failed in set_config");
298                 err = SE_INTERNAL_DA_ERROR;
299                 goto error;
300         }
301
302         FW_LOGV("end");
303
304 error:
305
306         return err;
307 }
308
309 bool get_profile_name(int accountId, char **profileName)
310 {
311         FW_LOGV("start");
312
313         SE_ErrorType err = SE_INTERNAL_OK;
314         bool result;
315
316         DACI_RETURN da_err = DACI_Open_Agent();
317         if (da_err != DACI_SUCCESS) {
318                 err = SE_INTERNAL_DA_ERROR;
319                 goto error;
320         }
321
322         result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName);
323         if (result == false) {
324                 FW_LOGE("failed in get_Config");
325                 err = SE_INTERNAL_DA_ERROR;
326                 goto error;
327         }
328
329         FW_LOGV("end");
330
331 error:
332
333         DACI_Close_Agent();
334
335         if (err != SE_INTERNAL_OK)
336                 return false;
337         else
338                 return true;
339 }
340
341 bool get_profile_server_info(int accountId, char **addr, char **id, char **password)
342 {
343         FW_LOGV("start");
344
345         SE_ErrorType err = SE_INTERNAL_OK;
346         bool result;
347
348         DACI_RETURN da_err = DACI_Open_Agent();
349         if (da_err != DACI_SUCCESS) {
350                 err = SE_INTERNAL_DA_ERROR;
351                 goto error;
352         }
353
354         result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr);
355         if (result == false) {
356                 FW_LOGE("failed in get_Config");
357                 err = SE_INTERNAL_DA_ERROR;
358                 goto error;
359         }
360
361         *id = DACI_Get_Account_Email_Address(accountId);
362         if (*id == NULL) {
363                 err = SE_INTERNAL_DA_ERROR;
364                 goto error;
365         }
366
367         *password = DACI_Get_Account_Password(accountId);
368         if (*password == NULL) {
369                 err = SE_INTERNAL_DA_ERROR;
370                 goto error;
371         }
372
373         FW_LOGV("end");
374
375 error:
376
377         DACI_Close_Agent();
378
379         if (err != SE_INTERNAL_OK)
380                 return false;
381         else
382                 return true;
383 }
384
385 bool get_profile_sync_mode(int accountId, char **syncMode, char **syncType, char **interval)
386 {
387         FW_LOGV("start");
388
389         SE_ErrorType err = SE_INTERNAL_OK;
390         bool result;
391         char *tempSyncType = NULL;
392
393         DACI_RETURN da_err = DACI_Open_Agent();
394         if (da_err != DACI_SUCCESS) {
395                 err = SE_INTERNAL_DA_ERROR;
396                 goto error;
397         }
398
399         result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode);
400         if (result == false) {
401                 FW_LOGE("failed in get_Config");
402                 err = SE_INTERNAL_DA_ERROR;
403                 goto error;
404         }
405
406         result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType);
407         if (result == false) {
408                 FW_LOGE("failed in get_Config");
409                 err = SE_INTERNAL_DA_ERROR;
410                 goto error;
411         }
412
413         result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval);
414         if (result == false) {
415                 FW_LOGE("failed in get_Config");
416                 err = SE_INTERNAL_DA_ERROR;
417                 goto error;
418         }
419
420         FW_LOGV("end");
421
422 error:
423
424         DACI_Close_Agent();
425
426         if (tempSyncType != NULL)
427                 free(tempSyncType);
428
429         if (err != SE_INTERNAL_OK)
430                 return false;
431         else
432                 return true;
433 }
434
435 bool get_profile_sync_category(int accountId, int contentType, int *enabled, char **srcURI, char **tgtURI, char **id, char **password)
436 {
437         FW_LOGV("start");
438
439         SE_ErrorType err = SE_INTERNAL_OK;
440         bool result;
441         char *datastore = NULL;
442         char *enabled_str = NULL;
443
444         char datastore_source[128];
445         char datastore_target[128];
446         char datastore_id[128];
447         char datastore_pw[128];
448
449         DACI_RETURN da_err = DACI_Open_Agent();
450         if (da_err != DACI_SUCCESS) {
451                 err = SE_INTERNAL_DA_ERROR;
452                 goto error;
453         }
454
455         if (contentType == TYPE_CONTACT)
456                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
457         else if (contentType == TYPE_CALENDAR)
458                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
459         else if (contentType == TYPE_MEMO)
460                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
461         else if (contentType == TYPE_CALLLOG)
462                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
463
464         result = get_config(accountId, datastore, &enabled_str);
465         if (result == false) {
466                 FW_LOGE("failed in get_Config");
467                 err = SE_INTERNAL_DA_ERROR;
468                 goto error;
469         }
470         *enabled = atoi(enabled_str);
471
472         sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
473         sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
474         sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
475         sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
476
477         result = get_config(accountId, datastore_source, srcURI);
478         if (result == false) {
479                 FW_LOGE("failed in get_Config");
480                 err = SE_INTERNAL_DA_ERROR;
481                 goto error;
482         }
483
484         result = get_config(accountId, datastore_target, tgtURI);
485         if (result == false) {
486                 FW_LOGE("failed in get_Config");
487                 err = SE_INTERNAL_DA_ERROR;
488                 goto error;
489         }
490
491         result = get_config(accountId, datastore_id, id);
492         if (result == false) {
493                 FW_LOGE("failed in get_Config");
494                 err = SE_INTERNAL_DA_ERROR;
495                 goto error;
496         }
497
498         result = get_config(accountId, datastore_pw, password);
499         if (result == false) {
500                 FW_LOGE("failed in get_Config");
501                 err = SE_INTERNAL_DA_ERROR;
502                 goto error;
503         }
504
505         FW_LOGV("end");
506
507 error:
508
509         DACI_Close_Agent();
510
511         if (enabled_str != NULL)
512                 free(enabled_str);
513
514         if (err != SE_INTERNAL_OK)
515                 return false;
516         else
517                 return true;
518
519 }
520
521 bool get_last_session_info(int accountId, int *lastSessionStatus, int *lastSessionTime)
522 {
523         FW_LOGV("start");
524
525         SE_ErrorType err = SE_INTERNAL_OK;
526         bool result;
527         char *lastSessionStatus_str = NULL;
528         char *lastSessionTime_str = NULL;
529
530         DACI_RETURN da_err = DACI_Open_Agent();
531         if (da_err != DACI_SUCCESS) {
532                 err = SE_INTERNAL_DA_ERROR;
533                 goto error;
534         }
535
536         result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, &lastSessionStatus_str);
537         if (result == false) {
538                 FW_LOGE("failed in get_Config");
539                 err = SE_INTERNAL_DA_ERROR;
540                 goto error;
541         }
542
543         result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, &lastSessionTime_str);
544         if (result == false) {
545                 FW_LOGE("failed in get_Config");
546                 err = SE_INTERNAL_DA_ERROR;
547                 goto error;
548         }
549
550         *lastSessionStatus = atoi(lastSessionStatus_str);
551         *lastSessionTime = atoi(lastSessionTime_str);
552
553         FW_LOGV("end");
554
555 error:
556
557         DACI_Close_Agent();
558
559         if (lastSessionStatus_str != NULL)
560                 free(lastSessionStatus_str);
561
562         if (lastSessionTime_str != NULL)
563                 free(lastSessionTime_str);
564
565         if (err != SE_INTERNAL_OK)
566                 return false;
567         else
568                 return true;
569 }
570
571 bool get_profile_statistics(int accountId, int contentType, char **dbSynced, int *lastSessionTime,
572                 int *server2Client_Total, int *server2Client_NrOfAdd, int *server2Client_NrOfDelete, int *server2Client_NrOfReplace,
573                 int *client2Server_Total, int *client2Server_NrOfAdd, int *client2Server_NrOfDelete, int *client2Server_NrOfReplace)
574 {
575         FW_LOGV("start");
576
577         SE_ErrorType err = SE_INTERNAL_OK;
578         bool result;
579
580         char *datastore = NULL;
581         char datastore_dbsynced[128];
582         char datastore_lastsessiontime[128];
583         char datastore_s2c_total[128];
584         char datastore_s2c_add[128];
585         char datastore_s2c_replace[128];
586         char datastore_s2c_delete[128];
587         char datastore_c2s_total[128];
588         char datastore_c2s_add[128];
589         char datastore_c2s_replace[128];
590         char datastore_c2s_delete[128];
591
592         char *lastSessionTime_str = NULL;
593         char *server2Client_Total_str = NULL;
594         char *server2Client_NrOfAdd_str = NULL;
595         char *server2Client_NrOfDelete_str = NULL;
596         char *server2Client_NrOfReplace_str = NULL;
597         char *client2Server_Total_str = NULL;
598         char *client2Server_NrOfAdd_str = NULL;
599         char *client2Server_NrOfDelete_str = NULL;
600         char *client2Server_NrOfReplace_str = NULL;
601
602         DACI_RETURN da_err = DACI_Open_Agent();
603         if (da_err != DACI_SUCCESS) {
604                 err = SE_INTERNAL_DA_ERROR;
605                 goto error;
606         }
607
608         if (contentType == TYPE_CONTACT)
609                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
610         else if (contentType == TYPE_CALENDAR)
611                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
612         else if (contentType == TYPE_MEMO)
613                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
614         else if (contentType == TYPE_CALLLOG)
615                 datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
616
617         sprintf(datastore_dbsynced, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
618         sprintf(datastore_lastsessiontime, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
619         sprintf(datastore_s2c_total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
620         sprintf(datastore_s2c_add, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
621         sprintf(datastore_s2c_delete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
622         sprintf(datastore_s2c_replace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
623
624
625         sprintf(datastore_c2s_total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
626         sprintf(datastore_c2s_add, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
627         sprintf(datastore_c2s_delete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
628         sprintf(datastore_c2s_replace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
629
630         result = get_config(accountId, datastore_dbsynced, dbSynced);
631         if (result == false) {
632                 FW_LOGE("failed in get_Config");
633                 err = SE_INTERNAL_DA_ERROR;
634                 goto error;
635         }
636
637         result = get_config(accountId, datastore_lastsessiontime, &lastSessionTime_str);
638         if (result == false) {
639                 FW_LOGE("failed in get_Config");
640                 err = SE_INTERNAL_DA_ERROR;
641                 goto error;
642         }
643         *lastSessionTime = atoi(lastSessionTime_str);
644
645         result = get_config(accountId, datastore_s2c_total, &server2Client_Total_str);
646         if (result == false) {
647                 FW_LOGE("failed in get_Config");
648                 err = SE_INTERNAL_DA_ERROR;
649                 goto error;
650         }
651         *server2Client_Total = atoi(server2Client_Total_str);
652
653         result = get_config(accountId, datastore_s2c_add, &server2Client_NrOfAdd_str);
654         if (result == false) {
655                 FW_LOGE("failed in get_Config");
656                 err = SE_INTERNAL_DA_ERROR;
657                 goto error;
658         }
659         *server2Client_NrOfAdd = atoi(server2Client_NrOfAdd_str);
660
661         result = get_config(accountId, datastore_s2c_delete, &server2Client_NrOfDelete_str);
662         if (result == false) {
663                 FW_LOGE("failed in get_Config");
664                 err = SE_INTERNAL_DA_ERROR;
665                 goto error;
666         }
667         *server2Client_NrOfDelete = atoi(server2Client_NrOfDelete_str);
668
669         result = get_config(accountId, datastore_s2c_replace, &server2Client_NrOfReplace_str);
670         if (result == false) {
671                 FW_LOGE("failed in get_Config");
672                 err = SE_INTERNAL_DA_ERROR;
673                 goto error;
674         }
675         *server2Client_NrOfReplace = atoi(server2Client_NrOfReplace_str);
676
677         result = get_config(accountId, datastore_c2s_total, &client2Server_Total_str);
678         if (result == false) {
679                 FW_LOGE("failed in get_Config");
680                 err = SE_INTERNAL_DA_ERROR;
681                 goto error;
682         }
683         *client2Server_Total = atoi(client2Server_Total_str);
684
685         result = get_config(accountId, datastore_c2s_add, &client2Server_NrOfAdd_str);
686         if (result == false) {
687                 FW_LOGE("failed in get_Config");
688                 err = SE_INTERNAL_DA_ERROR;
689                 goto error;
690         }
691         *client2Server_NrOfAdd = atoi(client2Server_NrOfAdd_str);
692
693         result = get_config(accountId, datastore_c2s_delete, &client2Server_NrOfDelete_str);
694         if (result == false) {
695                 FW_LOGE("failed in get_Config");
696                 err = SE_INTERNAL_DA_ERROR;
697                 goto error;
698         }
699         *client2Server_NrOfDelete = atoi(client2Server_NrOfDelete_str);
700
701         result = get_config(accountId, datastore_c2s_replace, &client2Server_NrOfReplace_str);
702         if (result == false) {
703                 FW_LOGE("failed in get_Config");
704                 err = SE_INTERNAL_DA_ERROR;
705                 goto error;
706         }
707         *client2Server_NrOfReplace = atoi(client2Server_NrOfReplace_str);
708
709         FW_LOGV("end");
710
711 error:
712
713         DACI_Close_Agent();
714
715         if (lastSessionTime_str != NULL)
716                 free(lastSessionTime_str);
717
718         if (server2Client_Total_str != NULL)
719                 free(server2Client_Total_str);
720
721         if (server2Client_NrOfAdd_str != NULL)
722                 free(server2Client_NrOfAdd_str);
723
724         if (server2Client_NrOfDelete_str != NULL)
725                 free(server2Client_NrOfDelete_str);
726
727         if (server2Client_NrOfReplace_str != NULL)
728                 free(server2Client_NrOfReplace_str);
729
730         if (client2Server_Total_str != NULL)
731                 free(client2Server_Total_str);
732
733         if (client2Server_NrOfAdd_str != NULL)
734                 free(client2Server_NrOfAdd_str);
735
736         if (client2Server_NrOfDelete_str != NULL)
737                 free(client2Server_NrOfDelete_str);
738
739         if (client2Server_NrOfReplace_str != NULL)
740                 free(client2Server_NrOfReplace_str);
741
742         if (err != SE_INTERNAL_OK)
743                 return false;
744         else
745                 return true;
746 }