4e9a0e4ff20cbfdc0b6348db45ee974db2f63294
[platform/core/system/sync-agent.git] / src / fw-plugins / common-public / call-log / src / plugin_interface.c
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <glib.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <contacts.h>
23 #include <time.h>
24
25 /* for log */
26 #include "utility/sync_util.h"
27
28 #include "plugin/data_connector_interface.h"
29
30 #define BACKUP_PATH "/opt/media/Downloads/Kies/.BnR/CallLog.bk"
31
32 #ifndef EXPORT_API
33 #define EXPORT_API __attribute__ ((visibility("default")))
34 #endif
35
36 #ifndef SYNC_AGENT_LOG
37 #undef LOG_TAG
38 #define LOG_TAG "PLUGIN_DA_CALL_LOG"
39 #endif
40
41 #define CALLOG_SYNC_PERIODIC 60*60*24*8 /*8days */
42
43 /* call log Internal Struct */
44 typedef struct {
45         int v_type:16;
46         bool embedded;
47         bool img_loaded;
48         int id;
49         int num_type;
50         char *first;
51         char *last;
52         char *display;
53         const char *number;
54         char *img_path;
55         int log_time;
56         int log_type;
57         int extra_data1;        /* duration, message_id */
58         const char *extra_data2;        /*short message */
59         int related_id;         /* contact id */
60 } dc_plog_list_s;
61
62 static void _del_all_calllogs(void);
63
64 static sync_agent_da_return_e _convert_service_error_to_common_error(contacts_error_e err);
65
66 EXPORT_API sync_agent_da_return_e sync_agent_plugin_open_service(void)
67 {
68         _EXTERN_FUNC_ENTER;
69
70         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
71         contacts_error_e err = contacts_connect2();
72         if (err != CONTACTS_ERROR_NONE) {
73                 _DEBUG_ERROR("[da_calllog_plugIn] in calllog Fail!\n");
74                 ret = _convert_service_error_to_common_error(err);
75         } else {
76                 _DEBUG_INFO("[da_calllog_plugIn] in calllog Success!\n");
77         }
78
79         _EXTERN_FUNC_EXIT;
80
81         return ret;
82 }
83
84 EXPORT_API sync_agent_da_return_e sync_agent_plugin_close_service(void)
85 {
86         _EXTERN_FUNC_ENTER;
87
88         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
89         contacts_error_e err = contacts_disconnect2();
90         if (err != CONTACTS_ERROR_NONE) {
91                 _DEBUG_ERROR("[da_calllog_plugIn] in calllog Fail!\n");
92                 ret = _convert_service_error_to_common_error(err);
93         } else {
94                 _DEBUG_INFO("[da_calllog_plugIn] in calllog Success!\n");
95         }
96
97         _EXTERN_FUNC_EXIT;
98
99         return ret;
100 }
101
102 EXPORT_API int *sync_agent_plugin_get_account_id_list(int *count)
103 {
104         _EXTERN_FUNC_ENTER;
105
106         _DEBUG_INFO("[da_calllog_plugIn] calllog Start !!");
107         int *account_id_list = (int *)calloc(1, sizeof(int));
108         if (account_id_list == NULL) {
109                 _DEBUG_ERROR("CALLOC failed !!!");
110                 return NULL;
111         }
112         account_id_list[0] = -1;
113         *count = 1;
114
115         _DEBUG_INFO("[da_calllog_plugIn] calllog End !!");
116
117         _EXTERN_FUNC_EXIT;
118
119         return account_id_list;
120 }
121
122 EXPORT_API sync_agent_da_return_e sync_agent_plugin_backup_service_items_to_file(int account_ID, char **file_path)
123 {
124         _EXTERN_FUNC_ENTER;
125
126 //      sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
127 //      FILE *file = 0;
128 //      int cur_size = 0;
129 //      CTSiter *iter = 0;
130 //      CTSvalue *plog = 0;     /*plog_list */
131 //
132 //      file = fopen(BACKUP_PATH, "w");
133 //      if (file == NULL) {
134 //              _DEBUG_INFO("[da_call_log_plugIn] fopen fail\n");
135 //              return SYNC_AGENT_DA_ERRORS;
136 //      }
137 //
138 //      contacts_svc_get_list(CTS_LIST_ALL_PLOG, &iter);
139 //      while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
140 //              dc_plog_list_s plog_list;
141 //
142 //              /* get call log */
143 //              plog = contacts_svc_iter_get_info(iter);
144 //              if (plog == NULL)
145 //                      continue;
146 //
147 //              plog_list.number = contacts_svc_value_get_str(plog, CTS_LIST_PLOG_NUMBER_STR);
148 //              plog_list.log_time = contacts_svc_value_get_int(plog, CTS_LIST_PLOG_LOG_TIME_INT);
149 //              plog_list.log_type = contacts_svc_value_get_int(plog, CTS_LIST_PLOG_LOG_TYPE_INT);
150 //              plog_list.extra_data1 = contacts_svc_value_get_int(plog, CTS_LIST_PLOG_DURATION_INT);
151 //              plog_list.extra_data2 = contacts_svc_value_get_str(plog, CTS_LIST_PLOG_SHORTMSG_STR);
152 //              plog_list.related_id = contacts_svc_value_get_int(plog, CTS_LIST_PLOG_RELATED_ID_INT);
153 //
154 //              _DEBUG_INFO("plog_list.number : %s\n", plog_list.number);
155 //              _DEBUG_INFO("plog_list.related_id : %d\n", plog_list.related_id);
156 //              _DEBUG_INFO("plog_list.log_time : %d\n", plog_list.log_time);
157 //              _DEBUG_INFO("plog_list.log_type : %d\n", plog_list.log_type);
158 //              _DEBUG_INFO("plog_list.extra_data1 : %d\n", plog_list.extra_data1);
159 //              _DEBUG_INFO("plog_list.extra_data2 : %s\n", plog_list.extra_data2);
160 //
161 //              /* save call log : to file text */
162 //              cur_size = fprintf(file, "%s %d %d %d %d %s ", plog_list.number, plog_list.related_id, plog_list.log_time, plog_list.log_type, plog_list.extra_data1, plog_list.extra_data2);
163 //
164 //              if (cur_size == -1) {
165 //                      _DEBUG_INFO("[da_call_log_plugIn] fprintf fail\n");
166 //                      ret = SYNC_AGENT_DA_ERRORS;
167 //                      goto DACI_FINISH;
168 //              }
169 //
170 //              /* memory free */
171 //              if (plog != NULL) {
172 //                      contacts_svc_value_free(plog);
173 //                      plog = 0;
174 //              }
175 //      }
176 //
177 //DACI_FINISH:
178 //
179 //      if (file != NULL) {
180 //              fclose(file);
181 //              file = 0;
182 //      }
183 //
184 //      /* memory free */
185 //      if (plog != NULL) {
186 //              contacts_svc_value_free(plog);
187 //              plog = 0;
188 //      }
189 //
190 //      if (iter != NULL) {
191 //              contacts_svc_iter_remove(iter);
192 //              iter = 0;
193 //      }
194 //
195 //      *file_path = strdup(BACKUP_PATH);
196
197         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
198         FILE *file = 0;
199         int cur_size = 0;
200
201         contacts_error_e err = CONTACTS_ERROR_NONE;
202         contacts_list_h list = NULL;
203
204         char *number = NULL;
205         int related_id;
206         int log_time;
207         int log_type;
208         int duration;
209         char *short_msg = NULL;
210
211         file = fopen(BACKUP_PATH, "w");
212         if (file == NULL) {
213                 _DEBUG_ERROR("[da_call_log_plugIn] fopen fail\n");
214                 return SYNC_AGENT_DA_ERRORS;
215         }
216
217         err = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, &list);
218         if (err != CONTACTS_ERROR_NONE) {
219                 _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n");
220                 ret = _convert_service_error_to_common_error(err);
221                 goto DACI_FINISH;
222         }
223
224         err = contacts_list_first(list);
225         while (err == CONTACTS_ERROR_NONE) {
226                 contacts_record_h record = NULL;
227
228                 /* get call log */
229                 err = contacts_list_get_current_record_p(list, &record);
230                 if (err != CONTACTS_ERROR_NONE) {
231                         _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_get_current_record_p fail\n");
232                         continue;
233                 }
234
235                 contacts_record_get_str_p(record, _contacts_phone_log.address, &number);
236                 contacts_record_get_int(record, _contacts_phone_log.person_id, &related_id);
237                 contacts_record_get_int(record, _contacts_phone_log.log_time, &log_time);
238                 contacts_record_get_int(record, _contacts_phone_log.log_type, &log_type);
239                 contacts_record_get_int(record, _contacts_phone_log.extra_data1, &duration);
240                 contacts_record_get_str_p(record, _contacts_phone_log.extra_data2, &short_msg);
241
242                 _DEBUG_INFO("plog_list.number : %s\n", number);
243                 _DEBUG_INFO("plog_list.related_id : %d\n", related_id);
244                 _DEBUG_INFO("plog_list.log_time : %d\n", log_time);
245                 _DEBUG_INFO("plog_list.log_type : %d\n", log_type);
246                 _DEBUG_INFO("plog_list.extra_data1 : %d\n", duration);
247                 _DEBUG_INFO("plog_list.extra_data2 : %s\n", short_msg);
248
249                 /* save call log : to file text */
250                 cur_size = fprintf(file, "%s %d %d %d %d %s ", number, related_id, log_time, log_type, duration, short_msg);
251                 if (cur_size == -1) {
252                         _DEBUG_ERROR("[da_call_log_plugIn] fprintf fail\n");
253                         ret = SYNC_AGENT_DA_ERRORS;
254                         goto DACI_FINISH;
255                 }
256
257                 err = contacts_list_next(list);
258         }
259
260  DACI_FINISH:
261
262         if (file != NULL) {
263                 fclose(file);
264                 file = 0;
265         }
266
267         contacts_list_destroy(list, true);
268
269         *file_path = strdup(BACKUP_PATH);
270
271         _EXTERN_FUNC_EXIT;
272
273         return ret;
274 }
275
276 EXPORT_API sync_agent_da_return_e sync_agent_plugin_restore_service_items_from_file(int account_ID, const char *file_path)
277 {
278         _EXTERN_FUNC_ENTER;
279
280         retvm_if(file_path == NULL, SYNC_AGENT_DA_ERRORS, "file_path is NULL. FAIL !!!");
281 //
282 //      sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
283 //      int err = 0;
284 //      FILE *file = 0;
285 //      int cur_size = 0;
286 //      CTSvalue *plog = 0;     /* plog */
287 //
288 //      /* open call log : from file text */
289 //      file = fopen(BACKUP_PATH, "r");
290 //      if (file == NULL) {
291 //              _DEBUG_INFO("[da_call_log_plugIn] fopen fail\n");
292 //              return SYNC_AGENT_DA_ERRORS;
293 //      }
294 //
295 //      /* delete call log from contact service database */
296 //      _del_all_calllogs();
297 //
298 //      while (1) {
299 //              dc_plog_list_s plog_list;
300 //              char temp_number[100] = { 0 };
301 //              char temp_extra_data2[1024] = { 0 };
302 //
303 //              /* read call log : from file text */
304 //              cur_size = fscanf(file, "%100s %d %d %d %d %1024s ", temp_number, &(plog_list.related_id), &(plog_list.log_time), &(plog_list.log_type), &(plog_list.extra_data1), temp_extra_data2);
305 //
306 //              if (cur_size == -1) {
307 //                      _DEBUG_INFO("[da_call_log_plugIn] fscanf fail\n");
308 //                      ret = SYNC_AGENT_DA_ERRORS;
309 //                      goto DACI_FINISH;
310 //              }
311 //
312 //              plog = contacts_svc_value_new(CTS_VALUE_PHONELOG);
313 //              if (plog == NULL) {
314 //                      _DEBUG_INFO("[da_call_log_plugIn] memory allocation fail\n");
315 //                      ret = SYNC_AGENT_DA_ERRORS;
316 //                      goto DACI_FINISH;
317 //              }
318 //
319 //              /* add call log to contact service database */
320 //              contacts_svc_value_set_str(plog, CTS_PLOG_VAL_NUMBER_STR, temp_number);
321 //              contacts_svc_value_set_int(plog, CTS_PLOG_VAL_RELATED_ID_INT, plog_list.related_id);
322 //              contacts_svc_value_set_int(plog, CTS_PLOG_VAL_LOG_TIME_INT, plog_list.log_time);
323 //              contacts_svc_value_set_int(plog, CTS_PLOG_VAL_LOG_TYPE_INT, plog_list.log_type);
324 //              contacts_svc_value_set_int(plog, CTS_PLOG_VAL_DURATION_INT, plog_list.extra_data1);
325 //              contacts_svc_value_set_str(plog, CTS_PLOG_VAL_SHORTMSG_STR, temp_extra_data2);
326 //
327 //              _DEBUG_INFO("plog_list.number : %s\n", temp_number);
328 //              _DEBUG_INFO("plog_list.related_id : %d\n", plog_list.related_id);
329 //              _DEBUG_INFO("plog_list.log_time : %d\n", plog_list.log_time);
330 //              _DEBUG_INFO("plog_list.log_type : %d\n", plog_list.log_type);
331 //              _DEBUG_INFO("plog_list.extra_data1 : %d\n", plog_list.extra_data1);
332 //              _DEBUG_INFO("plog_list.extra_data2 : %s\n", temp_extra_data2);
333 //
334 //              err = contacts_svc_insert_phonelog(plog);
335 //              if (err < CTS_SUCCESS) {
336 //                      _DEBUG_INFO("[da_contact_plugIn] contacts_svc_insert_phonelog() Fail!\n");
337 //                      ret = SYNC_AGENT_DA_ERRORS;
338 //                      goto DACI_FINISH;
339 //              } else {
340 //                      _DEBUG_INFO("[da_contact_plugIn] contacts_svc_insert_phonelog() Success!\n");
341 //
342 //                      /* memory free */
343 //                      if (plog != NULL) {
344 //                              contacts_svc_value_free(plog);
345 //                              plog = 0;
346 //                      }
347 //              }
348 //      }
349 //
350 //DACI_FINISH:
351 //
352 //      if (file != NULL) {
353 //              fclose(file);
354 //              file = 0;
355 //      }
356 //
357 //      /* memory free */
358 //      if (plog != NULL) {
359 //              contacts_svc_value_free(plog);
360 //              plog = 0;
361 //      }
362
363         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
364         int err = 0;
365         FILE *file = 0;
366         int cur_size = 0;
367         contacts_record_h record = NULL;
368         int contact_id = 0;
369
370         /* open call log : from file text */
371         file = fopen(BACKUP_PATH, "r");
372         if (file == NULL) {
373                 _DEBUG_ERROR("[da_call_log_plugIn] fopen fail\n");
374                 return SYNC_AGENT_DA_ERRORS;
375         }
376
377         /* delete call log from contact service database */
378         _del_all_calllogs();
379
380         while (1) {
381                 dc_plog_list_s plog_list;
382                 char temp_number[100] = { 0 };
383                 char temp_extra_data2[1024] = { 0 };
384
385                 /* read call log : from file text */
386                 cur_size = fscanf(file, "%100s %d %d %d %d %1024s ", temp_number, &(plog_list.related_id), &(plog_list.log_time), &(plog_list.log_type), &(plog_list.extra_data1), temp_extra_data2);
387
388                 if (cur_size == -1) {
389                         _DEBUG_ERROR("[da_call_log_plugIn] fscanf fail\n");
390                         ret = SYNC_AGENT_DA_ERRORS;
391                         goto DACI_FINISH;
392                 }
393
394                 err = contacts_record_create(_contacts_phone_log._uri, &record);
395                 if (err != CONTACTS_ERROR_NONE) {
396                         _DEBUG_ERROR("[da_call_log_plugIn] contacts_record_create Fail\n");
397                         ret = _convert_service_error_to_common_error(err);
398                         goto DACI_FINISH;
399                 }
400
401                 /* add call log to contact service database */
402                 contacts_record_set_str(record, _contacts_phone_log.address, temp_number);
403                 contacts_record_set_int(record, _contacts_phone_log.person_id, plog_list.related_id);
404                 contacts_record_set_int(record, _contacts_phone_log.log_time, plog_list.log_time);
405                 contacts_record_set_int(record, _contacts_phone_log.log_type, plog_list.log_type);
406                 contacts_record_set_int(record, _contacts_phone_log.extra_data1, plog_list.extra_data1);
407                 contacts_record_set_str(record, _contacts_phone_log.extra_data2, temp_extra_data2);
408
409                 _DEBUG_INFO("plog_list.number : %s\n", temp_number);
410                 _DEBUG_INFO("plog_list.related_id : %d\n", plog_list.related_id);
411                 _DEBUG_INFO("plog_list.log_time : %d\n", plog_list.log_time);
412                 _DEBUG_INFO("plog_list.log_type : %d\n", plog_list.log_type);
413                 _DEBUG_INFO("plog_list.extra_data1 : %d\n", plog_list.extra_data1);
414                 _DEBUG_INFO("plog_list.extra_data2 : %s\n", temp_extra_data2);
415
416                 err = contacts_db_insert_record(record, &contact_id);
417                 if (err != CONTACTS_ERROR_NONE) {
418                         _DEBUG_ERROR("[da_contact_plugIn] contacts_db_insert_record() Fail!\n");
419                         ret = _convert_service_error_to_common_error(err);
420                         goto DACI_FINISH;
421                 } else {
422                         _DEBUG_INFO("[da_contact_plugIn] contacts_db_insert_record() Success!\n");
423                         _DEBUG_INFO("[da_contact_plugIn] contact_id = %d", contact_id);
424                 }
425         }
426
427  DACI_FINISH:
428
429         contacts_record_destroy(record, true);
430
431         if (file != NULL) {
432                 fclose(file);
433                 file = 0;
434         }
435
436         _EXTERN_FUNC_EXIT;
437
438         return ret;
439 }
440
441 EXPORT_API sync_agent_da_return_e sync_agent_plugin_get_item(int account_id, char *folder_id, char *item_id, void **data)
442 {
443         _EXTERN_FUNC_ENTER;
444
445         retvm_if(item_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "item_id is NULL. FAIL !!!");
446
447 //      sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
448 //      cts_error err = 0;
449 //      CTSvalue *item = 0;
450 //
451 //      /* get item */
452 //      int colllog_id = atoi(item_id);
453 //      _DEBUG_INFO("[da_call-log_plugIn] colllog_id : %d\n", colllog_id);
454 //      err = contacts_svc_get_phonelog(colllog_id, &item);
455 //      if (err < CTS_SUCCESS) {
456 //              _DEBUG_INFO("[da_call-log_plugIn] contacts_svc_get_phonelog() Fail!\n");
457 //              ret = _convert_service_error_to_common_error(err);
458 //              *data = 0;
459 //      } else {
460 //              _DEBUG_INFO("[da_call-log_plugIn] contacts_svc_get_phonelog() Success!\n");
461 //              *data = (void *)item;
462 //      }
463
464         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
465         int err = 0;
466         contacts_record_h record = NULL;
467
468         /* get item */
469         int colllog_id = atoi(item_id);
470         _DEBUG_INFO("[da_call-log_plugIn] colllog_id : %d\n", colllog_id);
471         err = contacts_db_get_record(_contacts_phone_log._uri, colllog_id, &record);
472         if (err != CONTACTS_ERROR_NONE) {
473                 _DEBUG_ERROR("[da_call-log_plugIn] contacts_db_get_record() Fail!\n");
474                 ret = _convert_service_error_to_common_error(err);
475                 *data = 0;
476         } else {
477                 _DEBUG_INFO("[da_call-log_plugIn] contacts_db_get_record() Success!\n");
478                 *data = (void *)record;
479         }
480
481         _EXTERN_FUNC_EXIT;
482
483         return ret;
484 }
485
486 static void _del_all_calllogs(void)
487 {
488         _INNER_FUNC_ENTER;
489
490 //      CTSiter *iter = 0;
491 //      CTSvalue *plog = 0;     /*plog_list */
492 //
493 //      contacts_svc_get_list(CTS_LIST_ALL_PLOG, &iter);
494 //      while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
495 //
496 //              /* get call log */
497 //              plog = contacts_svc_iter_get_info(iter);
498 //              if (plog == NULL)
499 //                      continue;
500 //
501 //              int id = contacts_svc_value_get_int(plog, CTS_LIST_PLOG_ID_INT);
502 //
503 //              /* delete call log */
504 //              contacts_svc_delete_phonelog(CTS_PLOG_DEL_BY_ID, id);
505 //              _DEBUG_TRACE("[da_call_log_plugIn] id : %d\n", id);
506 //
507 //              /* memory free */
508 //              if (plog != NULL) {
509 //                      contacts_svc_value_free(plog);
510 //                      plog = 0;
511 //              }
512 //      }
513 //
514 //      /* memory free */
515 //      if (iter != NULL) {
516 //              contacts_svc_iter_remove(iter);
517 //              iter = 0;
518 //      }
519
520         contacts_error_e err = CONTACTS_ERROR_NONE;
521         contacts_list_h list = NULL;
522
523         err = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, &list);
524         if (err != CONTACTS_ERROR_NONE) {
525                 _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n");
526                 return;
527         }
528
529         err = contacts_list_first(list);
530         while (err == CONTACTS_ERROR_NONE) {
531                 contacts_record_h record = NULL;
532
533                 /* get call log */
534                 err = contacts_list_get_current_record_p(list, &record);
535                 if (err != CONTACTS_ERROR_NONE) {
536                         _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n");
537                         continue;
538                 }
539
540                 int id;
541                 err = contacts_record_get_int(record, _contacts_phone_log.id, &id);
542                 if (err != CONTACTS_ERROR_NONE) {
543                         _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n");
544                         continue;
545                 }
546
547                 _DEBUG_TRACE("[da_call_log_plugIn] id : %d\n", id);
548
549                 /* delete call log */
550                 contacts_db_delete_record(_contacts_phone_log._uri, id);
551
552                 err = contacts_list_next(list);
553         }
554
555         /* memory free */
556         contacts_list_destroy(list, true);
557
558         _INNER_FUNC_EXIT;
559 }
560
561 EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for_folder_add(int account_id, const char *folder_id, int changepoint, int *changeCount)
562 {
563         _EXTERN_FUNC_ENTER;
564 //
565 //      _DEBUG_INFO("[da_call-log_plugIn] account_id : %d\n", account_id);
566 //      _DEBUG_INFO("[da_call-log_plugIn] folder_id : %s\n", folder_id);
567 //      _DEBUG_INFO("[da_call-log_plugIn] changepoint : %d\n", changepoint);
568 //
569 //      sync_agent_plugin_item_node_s *root_ptr = 0;
570 //      sync_agent_plugin_item_node_s *cursor_ptr = 0;
571 //      int chagned_count = 0;
572 //      int current_time = time(NULL);
573 //
574 //      CTSiter *iter = NULL;
575 //      CTSvalue *plog = NULL;  /*plog_list */
576 //
577 //      char *calllog_id_str = NULL;
578 //
579 //      int result = contacts_svc_get_list(CTS_LIST_ALL_PLOG, &iter);
580 //      _DEBUG_INFO("result = %d", result);
581 //      while (CTS_SUCCESS == contacts_svc_iter_next(iter)) {
582 //
583 //              /* get call log */
584 //              plog = contacts_svc_iter_get_info(iter);
585 //              if (plog == NULL)
586 //                      continue;
587 //
588 //              /*check that item is within 7 days before since at the time */
589 //              if (current_time - CALLOG_SYNC_PERIODIC <= contacts_svc_value_get_int(plog, CTS_LIST_PLOG_LOG_TIME_INT)) {
590 //                      calllog_id_str = g_strdup_printf("%d", contacts_svc_value_get_int(plog, CTS_LIST_PLOG_ID_INT));
591 //                      _DEBUG_INFO("calllog_id_str = %s", calllog_id_str);
592 //
593 //                      if (root_ptr == NULL) {
594 //                              root_ptr = (sync_agent_plugin_item_node_s *) calloc(1, sizeof(sync_agent_plugin_item_node_s));
595 //                              if( root_ptr == NULL ) {
596 //                                      _DEBUG_ERROR("CALLOC failed !!!");
597 //                                      return NULL;
598 //                              }
599 //                              root_ptr->item_id = calllog_id_str;
600 //                              root_ptr->next = 0;
601 //                              cursor_ptr = root_ptr;
602 //                      } else {
603 //                              cursor_ptr->next = (sync_agent_plugin_item_node_s *) calloc(1, sizeof(sync_agent_plugin_item_node_s));
604 //                              if( cursor_ptr->next == NULL ) {
605 //                                      _DEBUG_ERROR("CALLOC failed !!!");
606 //                                      return NULL;
607 //                              }
608 //                              cursor_ptr->next->item_id = calllog_id_str;
609 //                              cursor_ptr->next->next = 0;
610 //                              cursor_ptr = cursor_ptr->next;
611 //                      }
612 //
613 //                      chagned_count++;
614 //
615 //                      /* memory free */
616 //                      if (plog != NULL) {
617 //                              contacts_svc_value_free(plog);
618 //                              plog = NULL;
619 //                      }
620 //              }
621 //      }
622 //
623 //      if (iter != NULL) {
624 //              contacts_svc_iter_remove(iter);
625 //              iter = 0;
626 //              _DEBUG_INFO("[da_contact_plugIn] contacts_svc_iter_remove !! \n");
627 //      }
628 //
629 //      *changeCount = chagned_count;
630
631         _DEBUG_INFO("[da_call-log_plugIn] account_id : %d\n", account_id);
632         _DEBUG_INFO("[da_call-log_plugIn] folder_id : %s\n", folder_id);
633         _DEBUG_INFO("[da_call-log_plugIn] changepoint : %d\n", changepoint);
634
635         sync_agent_plugin_item_node_s *root_ptr = 0;
636         sync_agent_plugin_item_node_s *cursor_ptr = 0;
637         int chagned_count = 0;
638         int current_time = time(NULL);
639
640         char *calllog_id_str = NULL;
641
642         contacts_error_e err = CONTACTS_ERROR_NONE;
643         contacts_list_h list = NULL;
644
645         err = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, &list);
646         if (err != CONTACTS_ERROR_NONE) {
647                 _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n");
648                 return NULL;
649         }
650
651         err = contacts_list_first(list);
652         while (err == CONTACTS_ERROR_NONE) {
653
654                 contacts_record_h record = NULL;
655
656                 /* get call log */
657                 err = contacts_list_get_current_record_p(list, &record);
658                 if (err != CONTACTS_ERROR_NONE) {
659                         _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n");
660                         continue;
661                 }
662
663                 /*check that item is within 7 days before since at the time */
664                 int log_time;
665                 contacts_record_get_int(record, _contacts_phone_log.log_time, &log_time);
666
667                 if (current_time - CALLOG_SYNC_PERIODIC <= log_time) {
668                         int calllog_id;
669                         contacts_record_get_int(record, _contacts_phone_log.id, &calllog_id);
670
671                         calllog_id_str = g_strdup_printf("%d", calllog_id);
672                         _DEBUG_INFO("calllog_id_str = %s", calllog_id_str);
673
674                         if (root_ptr == NULL) {
675                                 root_ptr = (sync_agent_plugin_item_node_s *) calloc(1, sizeof(sync_agent_plugin_item_node_s));
676                                 if (root_ptr == NULL) {
677                                         _DEBUG_ERROR("CALLOC failed !!!");
678                                         return NULL;
679                                 }
680                                 root_ptr->item_id = calllog_id_str;
681                                 root_ptr->next = 0;
682                                 cursor_ptr = root_ptr;
683                         } else {
684                                 cursor_ptr->next = (sync_agent_plugin_item_node_s *) calloc(1, sizeof(sync_agent_plugin_item_node_s));
685                                 if (cursor_ptr->next == NULL) {
686                                         _DEBUG_ERROR("CALLOC failed !!!");
687                                         return NULL;
688                                 }
689                                 cursor_ptr->next->item_id = calllog_id_str;
690                                 cursor_ptr->next->next = 0;
691                                 cursor_ptr = cursor_ptr->next;
692                         }
693
694                         chagned_count++;
695                 }
696
697                 err = contacts_list_next(list);
698         }
699
700         contacts_list_destroy(list, true);
701
702         *changeCount = chagned_count;
703
704         _EXTERN_FUNC_EXIT;
705
706         return root_ptr;
707 }
708
709 EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for_folder_update(int account_id, const char *folder_id, int change_point, int *change_count)
710 {
711         _EXTERN_FUNC_ENTER;
712
713         _DEBUG_INFO("[da_call-log_plugIn] account_id : %d\n", account_id);
714         _DEBUG_INFO("[da_call-log_plugIn] folder_id : %s\n", folder_id);
715         _DEBUG_INFO("[da_call-log_plugIn] changepoint : %d\n", change_point);
716
717         *change_count = 0;
718
719         _EXTERN_FUNC_EXIT;
720
721         return NULL;
722 }
723
724 EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for_folder_delete(int account_id, const char *folder_id, int change_point, int *change_count)
725 {
726         _EXTERN_FUNC_ENTER;
727
728         _DEBUG_INFO("\n[da_contact_plugIn] account_id : %d\n", account_id);
729         _DEBUG_INFO("[da_contact_plugIn] folder_id : %s\n", folder_id);
730         _DEBUG_INFO("[da_contact_plugIn] changepoint : %d\n", change_point);
731
732         *change_count = 0;
733
734         _EXTERN_FUNC_EXIT;
735
736         return NULL;
737 }
738
739 static sync_agent_da_return_e _convert_service_error_to_common_error(contacts_error_e err)
740 {
741         _INNER_FUNC_ENTER;
742
743         sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
744         _DEBUG_TRACE("[da_contact_plugIn] Error Code : %d\n", err);
745
746         switch (err) {
747         case CONTACTS_ERROR_NONE:
748                 ret = SYNC_AGENT_DA_SUCCESS;
749                 break;
750         case CONTACTS_ERROR_OUT_OF_MEMORY:
751                 ret = SYNC_AGENT_DA_ERR_MEMORY_FULL;
752                 break;
753         case CONTACTS_ERROR_INVALID_PARAMETER:
754                 ret = SYNC_AGENT_DA_ERR_INVALID_PARAMETER;
755                 break;
756         case CONTACTS_ERROR_NO_DATA:
757                 ret = SYNC_AGENT_DA_ERR_NO_DATA;
758                 break;
759         case CONTACTS_ERROR_DB:
760                 ret = SYNC_AGENT_DA_ERR_SERVICE_DB;
761                 break;
762         case CONTACTS_ERROR_IPC:
763                 ret = SYNC_AGENT_DA_ERR_SERVICE_IPC;
764                 break;
765         default:
766                 ret = SYNC_AGENT_DA_ERRORS;
767                 break;
768         }
769
770         _INNER_FUNC_EXIT;
771
772         return ret;
773 }
774
775 EXPORT_API int sync_agent_plugin_get_last_change_point(void)
776 {
777         _EXTERN_FUNC_ENTER;
778
779 //      contacts_svc_begin_trans();
780 //      int contact_version = contacts_svc_end_trans(1);
781
782         int contact_version;
783         contacts_db_get_current_version(&contact_version);
784
785         _EXTERN_FUNC_EXIT;
786
787         return contact_version;
788 }