X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffw-plugins%2Fcommon-public%2Fcall-log%2Fsrc%2Fplugin_interface.c;h=ee8bd53ba2866156b6ecc20653eaa2580b67830e;hb=refs%2Ftags%2Fsubmit%2Ftizen_common%2F20140522.130648;hp=4e9a0e4ff20cbfdc0b6348db45ee974db2f63294;hpb=e39bb48298c5ebcdeddc846cb25ab27c8f193465;p=platform%2Fcore%2Fsystem%2Fsync-agent.git diff --git a/src/fw-plugins/common-public/call-log/src/plugin_interface.c b/src/fw-plugins/common-public/call-log/src/plugin_interface.c index 4e9a0e4..ee8bd53 100755 --- a/src/fw-plugins/common-public/call-log/src/plugin_interface.c +++ b/src/fw-plugins/common-public/call-log/src/plugin_interface.c @@ -27,7 +27,9 @@ #include "plugin/data_connector_interface.h" -#define BACKUP_PATH "/opt/media/Downloads/Kies/.BnR/CallLog.bk" +#include + +#define BACKUP_PATH tzplatform_mkpath(TZ_USER_CONTENT,"Downloads/Kies/.BnR/CallLog.bk") #ifndef EXPORT_API #define EXPORT_API __attribute__ ((visibility("default"))) @@ -277,100 +279,19 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_restore_service_items_from_f { _EXTERN_FUNC_ENTER; - retvm_if(file_path == NULL, SYNC_AGENT_DA_ERRORS, "file_path is NULL. FAIL !!!"); -// -// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; -// int err = 0; -// FILE *file = 0; -// int cur_size = 0; -// CTSvalue *plog = 0; /* plog */ -// -// /* open call log : from file text */ -// file = fopen(BACKUP_PATH, "r"); -// if (file == NULL) { -// _DEBUG_INFO("[da_call_log_plugIn] fopen fail\n"); -// return SYNC_AGENT_DA_ERRORS; -// } -// -// /* delete call log from contact service database */ -// _del_all_calllogs(); -// -// while (1) { -// dc_plog_list_s plog_list; -// char temp_number[100] = { 0 }; -// char temp_extra_data2[1024] = { 0 }; -// -// /* read call log : from file text */ -// 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); -// -// if (cur_size == -1) { -// _DEBUG_INFO("[da_call_log_plugIn] fscanf fail\n"); -// ret = SYNC_AGENT_DA_ERRORS; -// goto DACI_FINISH; -// } -// -// plog = contacts_svc_value_new(CTS_VALUE_PHONELOG); -// if (plog == NULL) { -// _DEBUG_INFO("[da_call_log_plugIn] memory allocation fail\n"); -// ret = SYNC_AGENT_DA_ERRORS; -// goto DACI_FINISH; -// } -// -// /* add call log to contact service database */ -// contacts_svc_value_set_str(plog, CTS_PLOG_VAL_NUMBER_STR, temp_number); -// contacts_svc_value_set_int(plog, CTS_PLOG_VAL_RELATED_ID_INT, plog_list.related_id); -// contacts_svc_value_set_int(plog, CTS_PLOG_VAL_LOG_TIME_INT, plog_list.log_time); -// contacts_svc_value_set_int(plog, CTS_PLOG_VAL_LOG_TYPE_INT, plog_list.log_type); -// contacts_svc_value_set_int(plog, CTS_PLOG_VAL_DURATION_INT, plog_list.extra_data1); -// contacts_svc_value_set_str(plog, CTS_PLOG_VAL_SHORTMSG_STR, temp_extra_data2); -// -// _DEBUG_INFO("plog_list.number : %s\n", temp_number); -// _DEBUG_INFO("plog_list.related_id : %d\n", plog_list.related_id); -// _DEBUG_INFO("plog_list.log_time : %d\n", plog_list.log_time); -// _DEBUG_INFO("plog_list.log_type : %d\n", plog_list.log_type); -// _DEBUG_INFO("plog_list.extra_data1 : %d\n", plog_list.extra_data1); -// _DEBUG_INFO("plog_list.extra_data2 : %s\n", temp_extra_data2); -// -// err = contacts_svc_insert_phonelog(plog); -// if (err < CTS_SUCCESS) { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_insert_phonelog() Fail!\n"); -// ret = SYNC_AGENT_DA_ERRORS; -// goto DACI_FINISH; -// } else { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_insert_phonelog() Success!\n"); -// -// /* memory free */ -// if (plog != NULL) { -// contacts_svc_value_free(plog); -// plog = 0; -// } -// } -// } -// -//DACI_FINISH: -// -// if (file != NULL) { -// fclose(file); -// file = 0; -// } -// -// /* memory free */ -// if (plog != NULL) { -// contacts_svc_value_free(plog); -// plog = 0; -// } + retvm_if(file_path == NULL, SYNC_AGENT_DA_ERRORS, "[da_call_log_plugIn] file_path is NULL. FAIL !!!"); sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; int err = 0; - FILE *file = 0; int cur_size = 0; - contacts_record_h record = NULL; int contact_id = 0; + FILE *file = NULL; + contacts_record_h record = NULL; /* open call log : from file text */ file = fopen(BACKUP_PATH, "r"); if (file == NULL) { - _DEBUG_ERROR("[da_call_log_plugIn] fopen fail\n"); + _DEBUG_ERROR("[da_call_log_plugIn] fopen() fail"); return SYNC_AGENT_DA_ERRORS; } @@ -384,16 +305,15 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_restore_service_items_from_f /* read call log : from file text */ 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); - if (cur_size == -1) { - _DEBUG_ERROR("[da_call_log_plugIn] fscanf fail\n"); - ret = SYNC_AGENT_DA_ERRORS; + _DEBUG_INFO("[da_call_log_plugIn] The end of file"); + ret = SYNC_AGENT_DA_SUCCESS; goto DACI_FINISH; } err = contacts_record_create(_contacts_phone_log._uri, &record); if (err != CONTACTS_ERROR_NONE) { - _DEBUG_ERROR("[da_call_log_plugIn] contacts_record_create Fail\n"); + _DEBUG_ERROR("[da_call_log_plugIn] contacts_record_create() Fail, err[%d]", err); ret = _convert_service_error_to_common_error(err); goto DACI_FINISH; } @@ -406,35 +326,34 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_restore_service_items_from_f contacts_record_set_int(record, _contacts_phone_log.extra_data1, plog_list.extra_data1); contacts_record_set_str(record, _contacts_phone_log.extra_data2, temp_extra_data2); - _DEBUG_INFO("plog_list.number : %s\n", temp_number); - _DEBUG_INFO("plog_list.related_id : %d\n", plog_list.related_id); - _DEBUG_INFO("plog_list.log_time : %d\n", plog_list.log_time); - _DEBUG_INFO("plog_list.log_type : %d\n", plog_list.log_type); - _DEBUG_INFO("plog_list.extra_data1 : %d\n", plog_list.extra_data1); - _DEBUG_INFO("plog_list.extra_data2 : %s\n", temp_extra_data2); + _DEBUG_INFO("[da_contact_plugIn] plog_list.number : [%s]", temp_number); + _DEBUG_INFO("[da_contact_plugIn] plog_list.related_id : [%d]", plog_list.related_id); + _DEBUG_INFO("[da_contact_plugIn] plog_list.log_time : [%d]", plog_list.log_time); + _DEBUG_INFO("[da_contact_plugIn] plog_list.log_type : [%d]", plog_list.log_type); + _DEBUG_INFO("[da_contact_plugIn] plog_list.extra_data1 : [%d]", plog_list.extra_data1); + _DEBUG_INFO("[da_contact_plugIn] plog_list.extra_data2 : [%s]", temp_extra_data2); err = contacts_db_insert_record(record, &contact_id); if (err != CONTACTS_ERROR_NONE) { - _DEBUG_ERROR("[da_contact_plugIn] contacts_db_insert_record() Fail!\n"); + _DEBUG_ERROR("[da_contact_plugIn] contacts_db_insert_record() Fail, err[%d]", err); ret = _convert_service_error_to_common_error(err); goto DACI_FINISH; } else { - _DEBUG_INFO("[da_contact_plugIn] contacts_db_insert_record() Success!\n"); - _DEBUG_INFO("[da_contact_plugIn] contact_id = %d", contact_id); + _DEBUG_INFO("[da_contact_plugIn] contacts_db_insert_record() Success, contact_id = [%d]", contact_id); } } - DACI_FINISH: +DACI_FINISH: + _DEBUG_INFO("[da_contact_plugIn] DACI_FINISH"); contacts_record_destroy(record, true); if (file != NULL) { fclose(file); - file = 0; + file = NULL; } _EXTERN_FUNC_EXIT; - return ret; } @@ -487,42 +406,16 @@ static void _del_all_calllogs(void) { _INNER_FUNC_ENTER; -// CTSiter *iter = 0; -// CTSvalue *plog = 0; /*plog_list */ -// -// contacts_svc_get_list(CTS_LIST_ALL_PLOG, &iter); -// while (CTS_SUCCESS == contacts_svc_iter_next(iter)) { -// -// /* get call log */ -// plog = contacts_svc_iter_get_info(iter); -// if (plog == NULL) -// continue; -// -// int id = contacts_svc_value_get_int(plog, CTS_LIST_PLOG_ID_INT); -// -// /* delete call log */ -// contacts_svc_delete_phonelog(CTS_PLOG_DEL_BY_ID, id); -// _DEBUG_TRACE("[da_call_log_plugIn] id : %d\n", id); -// -// /* memory free */ -// if (plog != NULL) { -// contacts_svc_value_free(plog); -// plog = 0; -// } -// } -// -// /* memory free */ -// if (iter != NULL) { -// contacts_svc_iter_remove(iter); -// iter = 0; -// } - contacts_error_e err = CONTACTS_ERROR_NONE; contacts_list_h list = NULL; err = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, &list); if (err != CONTACTS_ERROR_NONE) { - _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n"); + _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records() fail, err[%d]", err); + err = contacts_list_destroy(list, true); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_destroy() fail, err[%d]", err); + } return; } @@ -533,18 +426,18 @@ static void _del_all_calllogs(void) /* get call log */ err = contacts_list_get_current_record_p(list, &record); if (err != CONTACTS_ERROR_NONE) { - _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n"); + _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_get_current_record_p() fail, err[%d]", err); continue; } int id; err = contacts_record_get_int(record, _contacts_phone_log.id, &id); if (err != CONTACTS_ERROR_NONE) { - _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n"); + _DEBUG_ERROR("[da_call_log_plugIn] contacts_record_get_int() fail, err[%d]", err); continue; } - _DEBUG_TRACE("[da_call_log_plugIn] id : %d\n", id); + _DEBUG_TRACE("[da_call_log_plugIn] id : [%d]", id); /* delete call log */ contacts_db_delete_record(_contacts_phone_log._uri, id); @@ -553,7 +446,10 @@ static void _del_all_calllogs(void) } /* memory free */ - contacts_list_destroy(list, true); + err = contacts_list_destroy(list, true); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_destroy() fail, err[%d]", err); + } _INNER_FUNC_EXIT; } @@ -561,76 +457,10 @@ static void _del_all_calllogs(void) 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) { _EXTERN_FUNC_ENTER; -// -// _DEBUG_INFO("[da_call-log_plugIn] account_id : %d\n", account_id); -// _DEBUG_INFO("[da_call-log_plugIn] folder_id : %s\n", folder_id); -// _DEBUG_INFO("[da_call-log_plugIn] changepoint : %d\n", changepoint); -// -// sync_agent_plugin_item_node_s *root_ptr = 0; -// sync_agent_plugin_item_node_s *cursor_ptr = 0; -// int chagned_count = 0; -// int current_time = time(NULL); -// -// CTSiter *iter = NULL; -// CTSvalue *plog = NULL; /*plog_list */ -// -// char *calllog_id_str = NULL; -// -// int result = contacts_svc_get_list(CTS_LIST_ALL_PLOG, &iter); -// _DEBUG_INFO("result = %d", result); -// while (CTS_SUCCESS == contacts_svc_iter_next(iter)) { -// -// /* get call log */ -// plog = contacts_svc_iter_get_info(iter); -// if (plog == NULL) -// continue; -// -// /*check that item is within 7 days before since at the time */ -// if (current_time - CALLOG_SYNC_PERIODIC <= contacts_svc_value_get_int(plog, CTS_LIST_PLOG_LOG_TIME_INT)) { -// calllog_id_str = g_strdup_printf("%d", contacts_svc_value_get_int(plog, CTS_LIST_PLOG_ID_INT)); -// _DEBUG_INFO("calllog_id_str = %s", calllog_id_str); -// -// if (root_ptr == NULL) { -// root_ptr = (sync_agent_plugin_item_node_s *) calloc(1, sizeof(sync_agent_plugin_item_node_s)); -// if( root_ptr == NULL ) { -// _DEBUG_ERROR("CALLOC failed !!!"); -// return NULL; -// } -// root_ptr->item_id = calllog_id_str; -// root_ptr->next = 0; -// cursor_ptr = root_ptr; -// } else { -// cursor_ptr->next = (sync_agent_plugin_item_node_s *) calloc(1, sizeof(sync_agent_plugin_item_node_s)); -// if( cursor_ptr->next == NULL ) { -// _DEBUG_ERROR("CALLOC failed !!!"); -// return NULL; -// } -// cursor_ptr->next->item_id = calllog_id_str; -// cursor_ptr->next->next = 0; -// cursor_ptr = cursor_ptr->next; -// } -// -// chagned_count++; -// -// /* memory free */ -// if (plog != NULL) { -// contacts_svc_value_free(plog); -// plog = NULL; -// } -// } -// } -// -// if (iter != NULL) { -// contacts_svc_iter_remove(iter); -// iter = 0; -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_iter_remove !! \n"); -// } -// -// *changeCount = chagned_count; - _DEBUG_INFO("[da_call-log_plugIn] account_id : %d\n", account_id); - _DEBUG_INFO("[da_call-log_plugIn] folder_id : %s\n", folder_id); - _DEBUG_INFO("[da_call-log_plugIn] changepoint : %d\n", changepoint); + _DEBUG_INFO("[da_call-log_plugIn] account_id : [%d]", account_id); + _DEBUG_INFO("[da_call-log_plugIn] folder_id : [%s]", folder_id); + _DEBUG_INFO("[da_call-log_plugIn] changepoint : [%d]", changepoint); sync_agent_plugin_item_node_s *root_ptr = 0; sync_agent_plugin_item_node_s *cursor_ptr = 0; @@ -644,19 +474,22 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for err = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, &list); if (err != CONTACTS_ERROR_NONE) { - _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n"); + _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records() fail, err[%d]", err); + err = contacts_list_destroy(list, true); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_destroy() fail, err[%d]", err); + } return NULL; } err = contacts_list_first(list); while (err == CONTACTS_ERROR_NONE) { - contacts_record_h record = NULL; /* get call log */ err = contacts_list_get_current_record_p(list, &record); if (err != CONTACTS_ERROR_NONE) { - _DEBUG_ERROR("[da_call_log_plugIn] contacts_db_get_all_records fail\n"); + _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_get_current_record_p() fail, err[%d]", err); continue; } @@ -669,12 +502,16 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for contacts_record_get_int(record, _contacts_phone_log.id, &calllog_id); calllog_id_str = g_strdup_printf("%d", calllog_id); - _DEBUG_INFO("calllog_id_str = %s", calllog_id_str); + _DEBUG_INFO("[da_call_log_plugIn] Calllog_id_str = [%s]", calllog_id_str); if (root_ptr == NULL) { root_ptr = (sync_agent_plugin_item_node_s *) calloc(1, sizeof(sync_agent_plugin_item_node_s)); if (root_ptr == NULL) { - _DEBUG_ERROR("CALLOC failed !!!"); + _DEBUG_ERROR("[da_call_log_plugIn] Calloc failed, root_ptr is NULL"); + err = contacts_list_destroy(list, true); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_destroy() fail, err[%d]", err); + } return NULL; } root_ptr->item_id = calllog_id_str; @@ -683,7 +520,15 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for } else { cursor_ptr->next = (sync_agent_plugin_item_node_s *) calloc(1, sizeof(sync_agent_plugin_item_node_s)); if (cursor_ptr->next == NULL) { - _DEBUG_ERROR("CALLOC failed !!!"); + _DEBUG_ERROR("[da_call_log_plugIn] Calloc failed, cursor_ptr->next is NULL"); + err = contacts_list_destroy(list, true); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_destroy() fail, err[%d]", err); + } + if (root_ptr != NULL) { + free(root_ptr); + root_ptr = NULL; + } return NULL; } cursor_ptr->next->item_id = calllog_id_str; @@ -697,12 +542,14 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for err = contacts_list_next(list); } - contacts_list_destroy(list, true); + err = contacts_list_destroy(list, true); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[da_call_log_plugIn] contacts_list_destroy() fail, err[%d]", err); + } *changeCount = chagned_count; _EXTERN_FUNC_EXIT; - return root_ptr; }