From 44cc673a0fa72374b443f1a4b7633d12d44c0716 Mon Sep 17 00:00:00 2001 From: JooHark Park Date: Mon, 15 Apr 2013 13:45:55 +0900 Subject: [PATCH] [Internal: merge sync-agent] ===================================== [Problem] - [Cause] - [Solution] - merge sync-agent ===================================== Change-Id: Iff7dd0a9b17f73ab5562e99060ac86c0dbfaa18d --- debian/changelog | 132 ++- include/data-adapter/interface_item.h | 29 +- include/data-adapter/interface_service_item.h | 378 +++++- include/plugin/data_connector_interface.h | 234 ++++ include/plugin/data_connector_resource.h | 29 +- include/utility/fw_compress.h | 31 + include/utility/sync_util.h | 7 + packaging/sync-agent.spec | 5 +- src/framework/account/service.c | 4 +- src/framework/data-adapter/agent.c | 230 +++- src/framework/data-adapter/agent.h | 46 +- src/framework/data-adapter/agent_handler_manager.c | 54 +- .../data-adapter/agent_handler_manager_internal.h | 32 +- src/framework/data-adapter/agent_manager.c | 43 +- src/framework/data-adapter/changelog.c | 166 ++- src/framework/data-adapter/changelog.h | 3 +- src/framework/data-adapter/changelog_internal.h | 17 +- src/framework/data-adapter/common.c | 1 + src/framework/data-adapter/interface_folder.c | 7 - src/framework/data-adapter/interface_item.c | 66 +- .../data-adapter/interface_service_item.c | 408 ++++++- src/framework/device-manager/mo_accessor.c | 33 +- src/framework/engine-controller/interface.c | 18 +- .../engine-controller/queuing_rule_spec.c | 9 +- src/framework/event/config.c | 4 + src/framework/event/data_accessor.c | 5 + src/framework/event/handler.c | 70 +- src/framework/event/oma_dm_api_common_internal.h | 6 +- src/framework/event/oma_dm_noti_api.c | 3 +- src/framework/event/oma_ds_api.c | 3 +- src/framework/event/ui_api.c | 50 +- src/framework/event/util.c | 3 +- src/framework/fsapi/operation.c | 10 + src/framework/initialization/interface.c | 2 + src/framework/network-access/interface.c | 10 +- src/framework/plugin/data_connector_plugin.c | 246 +++- src/framework/plugin/data_connector_plugin.h | 242 +++- src/framework/utility/fw_compress.c | 147 +++ src/framework/utility/fw_mainloop.c | 9 +- .../common-public/account/src/plugin_interface.c | 2 +- .../common-public/calendar/src/plugin_interface.c | 1243 ++++++++++++-------- .../common-public/call-log/src/plugin_interface.c | 271 +---- .../common-public/contact/src/plugin_interface.c | 191 +-- .../common-public/http/src/plugin_interface.c | 2 +- .../common-public/memo/src/plugin_interface.c | 19 +- .../slp-device/include/slp_device_info.h | 2 + .../common-public/slp-device/src/slp_device_info.c | 2 + .../slp-sysnoti-alarm/src/plugin_interface.c | 1 + .../slp-sysnoti-wap-push/src/plugin_interface.c | 4 + .../common-public/task/src/plugin_interface.c | 649 +++++----- .../vcalendar-task/include/vcalendar_string_util.h | 42 +- .../vcalendar-task/src/plugin_interface.c | 475 +++----- .../vcalendar-task/src/vcalendar_string_util.c | 379 +++--- .../vcalendar/include/vcalendar_string_util.h | 34 +- .../common-public/vcalendar/src/plugin_interface.c | 763 ++++-------- .../vcalendar/src/vcalendar_string_util.c | 666 +++++------ 56 files changed, 4444 insertions(+), 3093 deletions(-) diff --git a/debian/changelog b/debian/changelog index d7bb964..912472e 100755 --- a/debian/changelog +++ b/debian/changelog @@ -1,56 +1,138 @@ +sync-agent (0.1.87) unstable; urgency=low + + * 1. PLM P130412-7652 : oma-dm-agent BS patch. + * Git: magnolia/framework/system/sync-agent + * Tag: sync-agent_0.1.87 + + -- Taehwan Gil Sun, 14 Apr 2013 13:49:44 +0900 + +sync-agent (0.1.86) unstable; urgency=low + + * 1. PLM P130408-0763 : W0 rrule patch. + * 2. PLM P130408-0729 : calendar_book.id patch. + * 3. PLM P130408-0745 : CALENDAR_ALARM_TIME_UNIT_SPECIFIC setting value patch. + * 4. PLM P130408-0777 : GMT-based timezone value patch. + * 5. adding enum - FOTA update result popup. + * Git: magnolia/framework/system/sync-agent + * Tag: sync-agent_0.1.86 + + -- Juhaki Park Fri, 12 Apr 2013 14:17:59 +0900 + +sync-agent (0.1.85) unstable; urgency=low + + * 1. updated exdate sync > delete another date > DB is not updated + * 2. Stack area is broken. (PLM:P130404-5476) + * Git: magnolia/framework/system/sync-agent + * Tag: sync-agent_0.1.85 + + -- sanghyukko Fri, 05 Apr 2013 22:25:59 +0900 + +sync-agent (0.1.84) unstable; urgency=low + + * 1. Prevent 44317 fix. + * 2. Add an Exception handle for Exdate item. + * 3. Prevent 32978 fix. + * 4. Prevent 41907 fix. + * 5. When launching oma-ds-agent, daemon status check. + * 6. network status checking patch for GCF. + * Git: magnolia/framework/system/sync-agent + * Tag: sync-agent_0.1.84 + + -- Juhaki Park Thu, 4 Apr 2013 20:31:53 +0900 + +sync-agent (0.1.83) unstable; urgency=low + + * 1. A new API that goto_if() API is added + * 2. Add sim contact sync funtion(Add, Update, Delete) + * 3. Removing deleted Exdate item when the updated exdate item is created + * 4. Apply requirements of Calendar Svc + * 5. delta.tar decompress for FOTA update-agent + * Git: magnolia/framework/system/sync-agent + * Tag: sync-agent_0.1.83 + + -- WooJin Yun Fri, 29 Mar 2013 17:51:53 +0900 + sync-agent (0.1.82) unstable; urgency=low - * 1. debug log add - * 2. remove log, daemon check api added - * Git: framework/system/sync-agent + * 1. Adding a new DB field for Calendar Exdate Sync + * - Adding a 'parent_service_id' field to DB + * - Adding a function for updating 'parent_service_id' of the parent item. + * - Apply when the parent item is deleted, it's child items also to be deleted + * - Adding a function to get child item id list by using its parent item id + * - Adding an exception handle for exdate items when calendar DB is changed + * - Apply to include exdate items when calendar/count and calendar/load + * 2. When profile gets, input param changed. + * 3. Add Sim contact sync funtion + * Git: magnolia/framework/system/sync-agent * Tag: sync-agent_0.1.82 - -- sanghyukko Mon, 01 Apr 2013 14:57:49 +0900 + -- WooJin Yun Wed, 20 Mar 2013 19:37:20 +0900 sync-agent (0.1.81) unstable; urgency=low - * 1. When profile gets, input param changed - * Git: framework/system/sync-agent + * 1. Add Calendar Exdate Sync + - apply EXDATE:DELETE about calendar/load + - apply EXDATE:UPDATE about calendar/sync/load + * 2. Fix PLM Defect : P130309-1516 + * - Task write sync is not operated from Mobile to KIES at PC + * 3. Fix PLM Defect : P130309-1516 + * - Calendar Sync is not operated + * Git: magnolia/framework/system/sync-agent * Tag: sync-agent_0.1.81 - -- sanghyukko Wed, 20 Mar 2013 17:45:24 +0900 + -- WooJin Yun Thu, 14 Mar 2013 15:46:29 +0900 sync-agent (0.1.80) unstable; urgency=low - * 1. when profile info gets, return value changed. - * Git: framework/system/sync-agent + * 1. Fix prevent defect (8EA). + * 2. Task load vcalendar is changed. + * 3. When profile info gets, return value changed. + * 4. Calendar Exdate(UPDATE) Sync : fix some exdate items loss problems + * 5. Add Function for count of EXDATE items + * Git: magnolia/framework/system/sync-agent * Tag: sync-agent_0.1.80 - -- sanghyuk.ko Fri, 08 Mar 2013 09:39:45 +0900 + -- WooJin Yun Thu, 07 Mar 2013 21:38:21 +0900 -sync-agent (0.1.79) precise; urgency=low +sync-agent (0.1.79) unstable; urgency=low - * 1. sync_interval enum type added - * Git: framework/system/sync-agent + * 1. Fixed for prevent. (3EA) + * 2. Add FOTA polling fucntion + * 3. Fixed for prevent. (6EA) + * 4. sync_interval enum type added + * Git: magnolia/framework/system/sync-agent * Tag: sync-agent_0.1.79 - -- sanghyukko Thu, 28 Feb 2013 17:09:45 +0900 + -- WooJin Yun Thu, 28 Feb 2013 16:32:28 +0900 sync-agent (0.1.78) unstable; urgency=low - * 1. profile_dir_name create automatically. - * 2. sync_mode, sync_type src_uri enum type added - * Git: framework/system/sync-agent + * 1. Fixed that profile_dir_name create automatically + * 2. Fixed for prevent. (13EA) + * 3. sync_agent.pc file updated + * 4. sync_mode, sync_type src_uri enum type added + * 5. Calendar Exdate(UPDATE) Sync + * Git: magnolia/framework/system/sync-agent * Tag: sync-agent_0.1.78 - -- sanghyukko Tue, 26 Feb 2013 17:16:02 +0900 + -- sanghyukko Tue, 26 Feb 2013 19:55:32 +0900 sync-agent (0.1.77) unstable; urgency=low - * 1. tizen_2.0 code merge - * 2. Private code merge - * 3. sync_agent patch for emulator - * 4. g_type_init add - * 5. oma-ds-client test_server_info change(orange) - * Git: framework/system/sync-agent + * 1. Calendar Exdate(Delete) Import Sync + * 2. Added oma_ds_agent launch/kill at sync-agent + * 3. Adjust Contact Bulk API(Update) + * 4. Calendar Exdate(Delete) Sync + * 5. Fix prevent issues (3EA) + * 6. Fix prevent issue (1EA) + * 7. g_type_init added. + * 8. Fixed prevent issues. (14 EA) + * 9. Calendar Exdate(UPDATE) Sync + * 10. sync_agent rsa merge patch + * Git: magnolia/framework/system/sync-agent * Tag: sync-agent_0.1.77 - -- sanghyukko Thu, 21 Feb 2013 14:34:49 +0900 + -- WooJin Yun Thu, 21 Feb 2013 16:16:34 +0900 sync-agent (0.1.76) unstable; urgency=low diff --git a/include/data-adapter/interface_item.h b/include/data-adapter/interface_item.h index f027074..15e2bb9 100755 --- a/include/data-adapter/interface_item.h +++ b/include/data-adapter/interface_item.h @@ -37,17 +37,13 @@ extern "C" { * @brief Structure of framework item instance */ typedef struct { - char *item_id; - /**< F/W item id */ - int data_store_id; - /**< service data connector pluIn's ID described in F/W config file */ - int account_id; - /**< F/W account id */ - char *folder_id;/**< F/W folder id */ - char *service_id; - /**< service item id */ - char *access_name; - /**< name of accessor */ + char *item_id; /**< F/W item id */ + int data_store_id; /**< service data connector pluIn's ID described in F/W config file */ + int account_id; /**< F/W account id */ + char *folder_id; /**< F/W folder id */ + char *service_id; /**< service item id */ + char *parent_service_id; /**< parent F/W item id for exdate items => normal item : NULL / exdate parent item : -1 / exdate child item : parent service id */ + char *access_name; /**< name of accessor */ } sync_agent_da_item_s; /** @@ -560,6 +556,17 @@ extern "C" { sync_agent_da_return_e sync_agent_get_item_count(int data_store_id, int *item_count); /** + * @brief get updated exdate item id list in item table where service type + * @param[in] fw_id item's framework id + * @param[in] list list as returned updated exdate item_id list + * @return sync_agent_da_return_e + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval error value fail + + */ + sync_agent_da_return_e sync_agent_get_updated_exdate_item_id_list(char *fw_id, GList ** list); + +/** * @} */ diff --git a/include/data-adapter/interface_service_item.h b/include/data-adapter/interface_service_item.h index 54ac575..d9f7d86 100755 --- a/include/data-adapter/interface_service_item.h +++ b/include/data-adapter/interface_service_item.h @@ -37,11 +37,12 @@ extern "C" { * @brief Structure of framework service item instance */ typedef struct { - char *item_id; /** service item id */ + char *item_id; /** service item id */ int content_type; /** content type of service item */ - int account_id; /** service account id */ + int account_id; /** service account id */ char *folder_id; /** service folder id to which service item mapped to */ - char *access_name; /** name of accessor */ + char *parent_id; /** parent service id to which service item mapped to */ + char *access_name; /** name of accessor */ const void *data; /** void pointer type of service data */ } sync_agent_da_service_item_s; @@ -364,6 +365,50 @@ if (ret != SYNC_AGENT_DA_SUCCESS) { */ sync_agent_da_return_e sync_agent_update_service_bulk_item(sync_agent_da_service_item_s *service_item, char **item_id, bool update_changelog); + /** + * @brief Update calendar exdate:updated item on framework db + * @par Usage: + * @code + + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + sync_agent_da_service_item_s *service_item = NULL; + + ret = sync_agent_get_service_item(item_id, &service_item); + if (ret != SYNC_AGENT_DA_SUCCESS) { + ... + } + + ... + + ret = sync_agent_add_updated_exdate_item(service_item, &item_id, true); + if (ret != SYNC_AGENT_DA_SUCCESS) { + ... + } + + * @endcode + * @param[in] service_item sync_agent_da_service_item_s type of framework service item instance to update into framework db + * @param[in] parent_id id of framework parent service item instance desired to update + * @param[in] child_id id of framework child service item instance desired to update + * @param[in] update_changelog option specifying whether use of changelog for sync history + * @return operation result + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval error_value fail + */ + sync_agent_da_return_e sync_agent_add_updated_exdate_item(sync_agent_da_service_item_s * service_item, char *parent_id, char *child_id, bool update_changelog); + /** + * @brief Update calendar exdate:updated parent item + * @par Usage: + * @code + + sync_agent_construct_exdate_parent_item(service_item); + + * @endcode + * @param[in] service_item parent servic item id + * @return void + */ + void sync_agent_construct_exdate_parent_item(int content_type, char *parent_service_id); + + /** * @brief Delete framework service item instance from frameowrk db * @par Usage: @@ -391,14 +436,16 @@ if (ret != SYNC_AGENT_DA_SUCCESS) { * @code sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; +int count -ret = sync_agent_delete_service_bulk_item(item_id, true); +ret = sync_agent_delete_service_bulk_item(item_id, count, true); if (ret != SYNC_AGENT_DA_SUCCESS) { ... } * @endcode * @param[in] item_id id of framework service item instance desired to delete +* @param[in] count count of id * @param[in] update_changelog option specifying whether use of changelog for sync history * @return operation result * @retval SYNC_AGENT_DA_SUCCESS success @@ -524,6 +571,42 @@ if (ret != SYNC_AGENT_DA_SUCCESS) { int sync_agent_get_used_service_item_count(int content_type); /** + * @brief Get calendar exdate item count + * @par Usage: + * @code + int count = 0; + + count = sync_agent_get_deleted_exdate_item_count(FW_CALENDAR); + if (count == 0) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + int sync_agent_get_deleted_exdate_item_count(int content_type); + +/** + * @brief Get calendar exdate item count + * @par Usage: + * @code + +sync_agent_is_exist_exdate_item(FW_CALENDAR, fw_parent_id, child_vcalendar) + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + sync_agent_da_return_e sync_agent_is_exist_exdate_item(int content_type, const char *fw_parent_id, const char *child_vcalendar); + +/** * @brief Get item used count for folder * @par Usage: * @code @@ -632,6 +715,293 @@ if (ret != SYNC_AGENT_DA_SUCCESS) { char *sync_agent_get_service_folder_id(char *folder_id); /** + * @brief Get max name length of sim contact + * @par Usage: + * @code + + int length = 0; + + length = sync_agent_get_sim_contact_info_max_name_length(FW_CONTACT_SIM); + if (length == 0) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + int sync_agent_get_sim_contact_info_max_name_length(int content_type); + +/** + * @brief Get max number length of sim contact + * @par Usage: + * @code + + int length = 0; + + length = sync_agent_get_sim_contact_info_max_number_length(FW_CONTACT_SIM); + if (length == 0) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + int sync_agent_get_sim_contact_info_max_number_length(int content_type); + +/** + * @brief Get max email length of sim contact + * @par Usage: + * @code + + int length = 0; + + length = sync_agent_get_sim_contact_info_max_email_length(FW_CONTACT_SIM); + if (length == 0) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + int sync_agent_get_sim_contact_info_max_email_length(int content_type); + +/** + * @brief Get empty count of sim contact + * @par Usage: + * @code + + int count = 0; + + count = sync_agent_get_sim_contact_empty_count(FW_CONTACT_SIM); + if (count == 0) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + int sync_agent_get_sim_contact_empty_count(int content_type); + +/** + * @brief Get empty number count of sim contact + * @par Usage: + * @code + + int count = 0; + + count = sync_agent_get_sim_contact_number_empty_count(FW_CONTACT_SIM); + if (count == 0) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + int sync_agent_get_sim_contact_empty_number_count(int content_type); + +/** + * @brief Get empty email count of sim contact + * @par Usage: + * @code + + int count = 0; + + count = sync_agent_get_sim_contact_email_empty_count(FW_CONTACT_SIM); + if (count == 0) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + int sync_agent_get_sim_contact_empty_email_count(int content_type); + +/** + * @brief Get addressbook ID of sim contact + * @par Usage: + * @code + + int addressbook_id = 0; + + addressbook_id = sync_agent_get_sim_contact_adressbook_id(FW_CONTACT_SIM); + if (addressbook_id == 0) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @return operation result + * @retval current item count success + * @retval error value fail + */ + int sync_agent_get_sim_contact_addressbook_id(int content_type); + +/** + * @brief Get item ID of sim contact + * @par Usage: + * @code + + GList *item_id = NULL; + ... + + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + int sim_addressbook_id = 0; + + ret = sync_agent_get_sim_contact_item_id(FW_CONTACT_SIM, sim_addressbook_id, &item_id); + if (ret == SYNC_AGENT_DA_ERRORS) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @param[in] addressbook_id addressbook id of sim contact + * @param[out] item_id item id list of sim contacts + * @return operation result + * @retval current item count success + * @retval error value fail + */ + sync_agent_da_return_e sync_agent_get_sim_contact_item_id(int content_type, int sim_addressbook_id, GList **item_id); + +/** + * @brief Get item ID of sim contact + * @par Usage: + * @code + + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + char *data = NULL; + int item_id; + + ret = sync_agent_get_sim_contact_item(FW_CONTACT_SIM, item_id, &data); + if (ret == SYNC_AGENT_DA_ERRORS) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @param[in] item_id item id of sim contact + * @param[out] content_type data of sim contact + * @return operation result + * @retval current item count success + * @retval error value fail + */ + sync_agent_da_return_e sync_agent_get_sim_contact_item(int content_type, int item_id, char **data); + +/** + * @brief Add sim contact + * @par Usage: + * @code + + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + char *data; + int sim_addressbook_id; + int *item_id = NULL; + + ret = sync_agent_delete_sim_contact_item(FW_CONTACT_SIM, sim_addressbook_id, &item_id, data); + if (ret == SYNC_AGENT_DA_ERRORS) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @param[in] addressbook_id addressbook id of sim contact + * @param[out] item_id item id of sim contact + * @param[in] content_type data of sim contact + * @return operation result + * @retval current item count success + * @retval error value fail + */ + sync_agent_da_return_e sync_agent_add_sim_contact_item(int content_type, int sim_addressbook_id, int **item_id, char *data); + +/** + * @brief Delete sim contact + * @par Usage: + * @code + + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + char *data; + int item_id; + + ret = sync_agent_delete_sim_contact_item(FW_CONTACT_SIM, item_id, data); + if (ret == SYNC_AGENT_DA_ERRORS) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @param[in] item_id item id of sim contact + * @param[in] content_type data of sim contact + * @return operation result + * @retval current item count success + * @retval error value fail + */ + sync_agent_da_return_e sync_agent_write_sim_contact_item(int content_type, int item_id, char *data); + + +/** + * @brief Delete sim contact + * @par Usage: + * @code + + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + int item_id; + + ret = sync_agent_delete_sim_contact_item(FW_CONTACT_SIM, item_id); + if (ret == SYNC_AGENT_DA_ERRORS) { + ... + } else { + ... + } + + * @endcode + * @param[in] content_type service type - service data connector plug-in's ID described in F/W config file + * @param[in] item_id item id of sim contact + * @return operation result + * @retval current item count success + * @retval error value fail + */ + sync_agent_da_return_e sync_agent_delete_sim_contact_item(int content_type, int item_id); + +/** * @} */ diff --git a/include/plugin/data_connector_interface.h b/include/plugin/data_connector_interface.h index 7390903..57a15cc 100755 --- a/include/plugin/data_connector_interface.h +++ b/include/plugin/data_connector_interface.h @@ -311,6 +311,44 @@ extern "C" { int sync_agent_plugin_get_used_item_count(void); /** + * API to get exdate item count for EXDATE TYPE data of calendar + * + * @return current_item_count on success, negative value on error + * + * @par Since: + * + * + * @see sync_agent_plugin_get_deleted_exdate_item_count() + * + */ + int sync_agent_plugin_get_deleted_exdate_item_count(void); + +/** + * API to get exdate item count for EXDATE TYPE data of calendar + * + * @return current_item_count on success, negative value on error + * + * @par Since: + * + * + * @see sync_agent_plugin_is_exist_exdate_item() + * + */ + sync_agent_da_return_e sync_agent_plugin_is_exist_exdate_item(const char *fw_parent_id, const char *child_vcalendar); + +/** + * API to update the exdate parent item data of calendar + * + * @return void + * + * + * @see sync_agent_plugin_construct_exdate_parent_item() + * + */ + void sync_agent_plugin_construct_exdate_parent_item(char *parent_service_id); + + +/** * API to get item used count for folder * * @param[in] account_id service account id @@ -522,6 +560,19 @@ extern "C" { void sync_agent_plugin_set_callback_get_account_id_list(sync_agent_get_account_id_list_cb_plugin callback); /** + * API to set callback function to handle child item delete from storage + * + * @param[in] callback callback function - this function is provided from sync-agent-framework + * + * @par Since: + * + * + * @see data_connector_resource.h + * + */ + void sync_agent_plugin_set_callback_delete_child_item(sync_agent_del_child_item_cb_plugin callback); + +/** * API to get max item count per folder * * @param[in] folder_type folder type provided plugin @@ -602,6 +653,189 @@ extern "C" { int sync_agent_plugin_get_is_support_feature(int feature); /** + * API to get max name length of sim card + * + * @return max name length or default value + * + * @par Since: + * + * + * @see sync_agent_plugin_get_info_sim_contact_max_name_length() + * + */ + +int sync_agent_plugin_get_info_sim_contact_max_name_length(void); + +/** + * API to get max number length of sim card + * + * @return max number length or default value + * + * @par Since: + * + * + * @see sync_agent_plugin_get_info_sim_contact_max_name_length() + * + */ + +int sync_agent_plugin_get_info_sim_contact_max_number_length(void); + +/** + * API to get max email length of sim card + * + * @return max email length or default value + * + * @par Since: + * + * + * @see sync_agent_plugin_get_info_sim_contact_max_name_length() + * + */ + +int sync_agent_plugin_get_info_sim_contact_max_email_length(void); + +/** + * API to get empty count of sim card + * + * @return get empty count + * + * @par Since: + * + * + * @see sync_agent_plugin_get_sim_contact_empty_count() + * + */ + +int sync_agent_plugin_get_info_sim_contact_empty_count(void); + +/** + * API to get empty number count of sim card + * + * @return get empty number count + * + * @par Since: + * + * + * @see sync_agent_plugin_get_sim_contact_empty_number_count() + * + */ + +int sync_agent_plugin_get_info_sim_contact_empty_number_count(void); + +/** + * API to get empty email count of sim card + * + * @return get empty email count + * + * @par Since: + * + * + * @see sync_agent_plugin_get_sim_contact_empty_email_count() + * + */ + +int sync_agent_plugin_get_info_sim_contact_empty_email_count(void); + +/** + * API to get addressbook ID of sim card + * + * @return get addressbook ID + * + * @par Since: + * + * + * @see sync_agent_plugin_get_info_sim_contact_addressbook_id() + * + */ + +int sync_agent_plugin_get_info_sim_contact_addressbook_id(void); + +/** + * API to get contact item ID of sim card + * + * @param[in] addressbook id of sim contact + * @param[out] contact item ID of sim card + * + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + * + * @par Since: + * + * + * @see sync_agent_plugin_get_info_sim_contact_item_id() + * + */ + +sync_agent_da_return_e sync_agent_plugin_get_info_sim_contact_item_id(int sim_addressbook_id, GList **item_id); + +/** + * API to get contact item ID of sim card + * + * @param[in] contact item ID of sim card + * @param[out] data of sim contact + * + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + * + * @par Since: + * + * + * @see sync_agent_plugin_get_info_sim_contact_item() + * + */ + +sync_agent_da_return_e sync_agent_plugin_get_info_sim_contact_item(int item_id, char **data); + +/** + * API to delete sim contact + * + * @param[in] contact addressbook ID of sim card + * @param[out] contact item ID of sim card + * @param[in] data of sim contact + * + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + * + * @par Since: + * + * + * @see sync_agent_plugin_add_sim_contact_item() + * + */ + +sync_agent_da_return_e sync_agent_plugin_add_sim_contact_item(int sim_addressbook_id, int **item_id, char *data); + +/** + * API to delete sim contact + * + * @param[in] sim contact id + * @param[in] sim contact data + * + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + * + * @par Since: + * + * + * @see sync_agent_plugin_write_sim_contact_item() + * + */ + +sync_agent_da_return_e sync_agent_plugin_write_sim_contact_item(int item_id, char *data); + +/** + * API to delete sim contact + * + * @param[in] sim contact ID + * + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + * + * @par Since: + * + * + * @see sync_agent_plugin_delete_sim_contact_item() + * + */ + +sync_agent_da_return_e sync_agent_plugin_delete_sim_contact_item(int item_id); + +/** * @} */ #ifdef __cplusplus diff --git a/include/plugin/data_connector_resource.h b/include/plugin/data_connector_resource.h index ffb76de..ec9f969 100755 --- a/include/plugin/data_connector_resource.h +++ b/include/plugin/data_connector_resource.h @@ -37,10 +37,9 @@ extern "C" { * Structure of Item ID Node - Linked List */ struct sync_agent_plugin_item_node_s { - char *item_id; - /**< item id */ - struct sync_agent_plugin_item_node_s *next; - /**< next pointer */ + char *item_id; /**< item id */ + char *parent_item_id; /**< parent item id for exdate items*/ + struct sync_agent_plugin_item_node_s *next; /**< next pointer */ }; typedef struct sync_agent_plugin_item_node_s sync_agent_plugin_item_node_s; @@ -51,6 +50,7 @@ extern "C" { * @param[in] account_id service account id * @param[in] index possible mapping one service account with multiple sync-agent-framework account, so need index of sync-agent-framework account. * @param[in] item_id service item id + * @param[in] parent_id parent service item id * @param[in] item_type service type - service data connector plugin's id described in sync-agent-framework config xml file * @param[in] folder_id service folder id * @param[in] folder_type folder type defined in data-connector plugin @@ -63,7 +63,7 @@ extern "C" { * @see sync_agent_plugin_set_callback_add_item(sync_agent_add_item_cb_plugin) * */ - typedef int (*sync_agent_add_item_cb_plugin) (int account_id, int index, char *item_id, int item_type, char *folder_id, int folder_type); + typedef int (*sync_agent_add_item_cb_plugin) (int account_id, int index, char *item_id, char *parent_id, int item_type, char *folder_id, int folder_type); /** * Function which is called at some plugin (calendar, contact, memo) when existing item is deleted to the service @@ -83,12 +83,14 @@ extern "C" { */ typedef int (*sync_agent_del_item_cb_plugin) (int account_id, int index, char *item_id, int item_type); + /** * Function which is called at some plugin (calendar, contact, memo) when existing item is updated to the service * * @param[in] account_id service account id * @param[in] index possible mapping one service account with multiple sync-agent-framework account, so need index of sync-agent-framework account. * @param[in] item_id service item id + * @param[in] parent_id parent service item id * @param[in] item_type service type - service data connector plugin's id described in sync-agent-framework config xml file * * @return 1 on success, 0 on error @@ -99,7 +101,7 @@ extern "C" { * @see sync_agent_plugin_set_callback_update_item(sync_agent_update_item_cb_plugin) * */ - typedef int (*sync_agent_update_item_cb_plugin) (int account_id, int index, char *item_id, int item_type); + typedef int (*sync_agent_update_item_cb_plugin) (int account_id, int index, char *item_id, char *parent_id, int item_type); /** * Function which is called at some plugin (calendar, contact, memo) when need service account id list concerned of service_type @@ -118,6 +120,21 @@ extern "C" { typedef int *(*sync_agent_get_account_id_list_cb_plugin) (int service_type, int *cnt); /** + * Function which is called at calendar when existing child item is deleted to the service + * + * @param[in] parent_id parent_service_id + * + * @return 1 on success, 0 on error + * + * @par Since: + * + * + * @see sync_agent_plugin_set_callback_delete_child_item(sync_agent_del_child_item_cb_plugin) + * + */ + typedef int (*sync_agent_del_child_item_cb_plugin) (char *parent_id, char *child_id); + +/** * @} */ diff --git a/include/utility/fw_compress.h b/include/utility/fw_compress.h index b600cf7..62cb0c0 100755 --- a/include/utility/fw_compress.h +++ b/include/utility/fw_compress.h @@ -115,6 +115,37 @@ extern "C" { sync_agent_util_compress_result_e sync_agent_uncompress(sync_agent_util_compress_type_e type, const char *input_file_path, const char *output_direcory_path); /** + * API to decompress compressed file in specific format + * + * @par Usage: + * @code + sync_agent_util_compress_type_e type = SYNC_AGENT_UTIL_COMPRESS_TYPE_TAR; + char *input_path = NULL; + char *output_path = NULL; + ... + result = sync_agent_ua_uncompress(type, input_path, output_path); + if (result != SYNC_AGENT_UTIL_COMPRESS_SUCCESS) { + // error handling + ... + } + * + * @endcode + * + * @param[in] type type of compress in sync_agent_util_compress_type_e type of value + * @param[in] input_file_path compressed file path to decompress + * @param[in] output_direcory_path path to Update-Agent put decompressed folder + * + * @return SYNC_AGENT_UTIL_COMPRESS_SUCCESS on success, SYNC_AGENT_UTIL_COMPRESS_FAIL on error + * + * @par Since: + * + * + * @see sync_agent_ua_uncompress(sync_agent_util_compress_type_e, const char *, const char *) + * + */ + sync_agent_util_compress_result_e sync_agent_ua_uncompress(sync_agent_util_compress_type_e type, const char *input_file_path, const char *output_direcory_path); + +/** * @} */ diff --git a/include/utility/sync_util.h b/include/utility/sync_util.h index 48f9b54..9057a18 100755 --- a/include/utility/sync_util.h +++ b/include/utility/sync_util.h @@ -109,6 +109,13 @@ extern "C" { return (ret); \ } \ } while (0) +#define goto_if(expr, fmt, arg...) \ + do { \ + if (expr) { \ + _DEBUG_ERROR(fmt, ##arg); \ + goto return_part; \ + } \ + } while (0) /** * API to daemonize client agent diff --git a/packaging/sync-agent.spec b/packaging/sync-agent.spec index 50570c0..72546cc 100755 --- a/packaging/sync-agent.spec +++ b/packaging/sync-agent.spec @@ -1,6 +1,6 @@ Name: sync-agent Summary: Sync agent FW Library -Version: 0.1.82 +Version: 0.1.87 Release: 1 Group: TO_BE/FILLED_IN License: Apache License, Version 2.0 @@ -37,6 +37,7 @@ BuildRequires: pkgconfig(syspopup-caller) BuildRequires: pkgconfig(capi-network-connection) BuildRequires: pkgconfig(capi-network-serial) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(appsvc) BuildRequires: pkgconfig(dlog) BuildRequires: libgcrypt-devel BuildRequires: cmake @@ -57,7 +58,6 @@ Requires: %{name} = %{version}-%{release} %description devel Development files for %{name} - #%package -n common-private-plugins #Summary: Common Private Plugins #Group: TO_BE_FILLED @@ -65,7 +65,6 @@ Development files for %{name} #%description -n common-private-plugins #common private plugins for sync-agent - %package -n common-public-plugins Summary: Common Public Plugins Group: TO_BE_FILLED diff --git a/src/framework/account/service.c b/src/framework/account/service.c index 740d7f8..3cbcdf7 100755 --- a/src/framework/account/service.c +++ b/src/framework/account/service.c @@ -238,9 +238,9 @@ EXPORT_API void sync_agent_free_service_account_info(sync_agent_service_account_ if (account_info != NULL) { if (account_info->email != NULL) free(account_info->email); - + account_info->email = NULL; free(account_info); + account_info = NULL; } - _EXTERN_FUNC_EXIT; } diff --git a/src/framework/data-adapter/agent.c b/src/framework/data-adapter/agent.c index 9f494dd..e018931 100755 --- a/src/framework/data-adapter/agent.c +++ b/src/framework/data-adapter/agent.c @@ -82,7 +82,7 @@ static char *g_daci_create_table[] = { "create table item_tbl" "(" "item_id varchar(64) not null," - "data_store_id integer not null," "account_id integer not null," "folder_id varchar(64) not null," "service_id varchar(20) not null," "last_update date not null default current_timestamp," "access_name varchar(64) not null," + "data_store_id integer not null," "account_id integer not null," "folder_id varchar(64) not null," "service_id varchar(20) not null," "parent_service_id varchar(64) default null," "last_update date not null default current_timestamp," "access_name varchar(64) not null," "constraint item_tbl_pk primary key(item_id)," "constraint item_tbl_account_id_fk foreign key(account_id) references account_tbl(account_id)," "constraint itme_tbl_folder_id_fk foreign key(folder_id) references folder_tbl(folder_id)," "constraint item_tbl_uk unique(data_store_id, account_id, service_id)" ");", @@ -1391,7 +1391,7 @@ sync_agent_da_return_e da_add_item(SYNC_AGENT_DA_HANDLER * daci_handler, sync_ag return SYNC_AGENT_DA_ERR_PRIMARY_KEY_NOT_UNIQUE; } - char *query = "insert into item_tbl (item_id, data_store_id, account_id, folder_id, service_id, access_name) values (?, ?, ?, ?, ?, ?)"; + char *query = "insert into item_tbl (item_id, data_store_id, account_id, folder_id, service_id, parent_service_id, access_name) values (?, ?, ?, ?, ?, ?, ?)"; stmt = __query_prepare(daci_handler, query, strlen(query)); if (stmt == NULL) { @@ -1404,7 +1404,8 @@ sync_agent_da_return_e da_add_item(SYNC_AGENT_DA_HANDLER * daci_handler, sync_ag _stmt_bind_int(daci_handler, stmt, 3, item[i].account_id); __stmt_bind_text(daci_handler, stmt, 4, item[i].folder_id); __stmt_bind_text(daci_handler, stmt, 5, item[i].service_id); - __stmt_bind_text(daci_handler, stmt, 6, item[i].access_name); + __stmt_bind_text(daci_handler, stmt, 6, item[i].parent_service_id); + __stmt_bind_text(daci_handler, stmt, 7, item[i].access_name); ret = __stmt_write_step(daci_handler, stmt); if ((ret != SYNC_AGENT_DA_ERR_MORE_DATA) && (ret != SYNC_AGENT_DA_SUCCESS)) { @@ -1415,9 +1416,40 @@ sync_agent_da_return_e da_add_item(SYNC_AGENT_DA_HANDLER * daci_handler, sync_ag } __stmt_finalize(daci_handler, stmt); - _EXTERN_FUNC_EXIT; + return ret; +} + +sync_agent_da_return_e da_update_item(SYNC_AGENT_DA_HANDLER * daci_handler, char *fw_id, char *parent_id) +{ + _EXTERN_FUNC_ENTER; + retvm_if(daci_handler == NULL, SYNC_AGENT_DA_ERRORS, "SYNC_AGENT_DA_HANDLER is NULL !!"); + retvm_if(fw_id == NULL, SYNC_AGENT_DA_ERRORS, "fw_id is NULL !!"); + retvm_if(parent_id == NULL, SYNC_AGENT_DA_ERRORS, "parent_id is NULL !!"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + daci_stmt stmt = 0; + char query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = {0,}; + + snprintf(query, sizeof(query), "update item_tbl set parent_service_id = %s where item_id = %s", parent_id, fw_id); + _DEBUG_INFO("query = %s", query); + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == NULL) { + _DEBUG_ERROR("stmt is null"); + ret = SYNC_AGENT_DA_ERR_QUERY_FAILED; + goto return_part; + } + + ret = __stmt_write_step(daci_handler, stmt); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("__stmt_write_step() failed !!"); + goto return_part; + } + __stmt_finalize(daci_handler, stmt); +return_part: + _DEBUG_INFO("return_part"); + _EXTERN_FUNC_EXIT; return ret; } @@ -1440,7 +1472,7 @@ sync_agent_da_return_e da_add_item_new(SYNC_AGENT_DA_HANDLER * daci_handler, syn } } - char *query = "insert into item_tbl (item_id, data_store_id, account_id, folder_id, service_id, access_name) values (?, ?, ?, ?, ?, ?)"; + char *query = "insert into item_tbl (item_id, data_store_id, account_id, folder_id, service_id, parent_service_id, access_name) values (?, ?, ?, ?, ?, ?, ?)"; stmt = __query_prepare(daci_handler, query, strlen(query)); if (stmt == NULL) { @@ -1474,7 +1506,8 @@ sync_agent_da_return_e da_add_item_new(SYNC_AGENT_DA_HANDLER * daci_handler, syn _stmt_bind_int(daci_handler, stmt, 3, item[i].account_id); __stmt_bind_text(daci_handler, stmt, 4, item[i].folder_id); __stmt_bind_text(daci_handler, stmt, 5, item[i].service_id); - __stmt_bind_text(daci_handler, stmt, 6, item[i].access_name); + __stmt_bind_text(daci_handler, stmt, 6, item[i].parent_service_id); + __stmt_bind_text(daci_handler, stmt, 7, item[i].access_name); ret = __stmt_write_step(daci_handler, stmt); if ((ret != SYNC_AGENT_DA_ERR_MORE_DATA) && (ret != SYNC_AGENT_DA_SUCCESS)) { @@ -1501,20 +1534,44 @@ sync_agent_da_return_e da_delete_item_by_Item_id(SYNC_AGENT_DA_HANDLER * daci_ha sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; daci_stmt stmt = 0; char query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = {0,}; + char *service_id = NULL; - snprintf(query, sizeof(query), "delete from item_tbl where item_id = %s", itemId); - //for test - //_DEBUG_INFO("query = [%s]", query); + snprintf(query, sizeof(query), "select service_id from item_tbl where item_id = %s", itemId); + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == NULL) { + _DEBUG_ERROR("stmt is null"); + return SYNC_AGENT_DA_ERR_QUERY_FAILED; + } + if (_stmt_read_step(daci_handler, stmt) == SYNC_AGENT_DA_ERR_MORE_DATA) + service_id = _stmt_column_text(stmt, 0); + _DEBUG_INFO("[da_delete_item_by_Item_id] service_id = %s", service_id); + __stmt_finalize(daci_handler, stmt); + SYNC_AGENT_DA_MEMORY_SET(query); + + snprintf(query, sizeof(query), "delete from item_tbl where parent_service_id = %s", service_id); stmt = __query_prepare(daci_handler, query, strlen(query)); - if (stmt == NULL) + if (stmt == NULL) { + _DEBUG_ERROR("stmt is null"); return SYNC_AGENT_DA_ERR_QUERY_FAILED; + } + _DEBUG_INFO("[da_delete_item_by_Item_id] before __stmt_write_step()"); ret = __stmt_write_step(daci_handler, stmt); __stmt_finalize(daci_handler, stmt); + SYNC_AGENT_DA_MEMORY_SET(query); - _EXTERN_FUNC_EXIT; + snprintf(query, sizeof(query), "delete from item_tbl where item_id = %s", itemId); + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == NULL) { + _DEBUG_ERROR("stmt is null"); + return SYNC_AGENT_DA_ERR_QUERY_FAILED; + } + + ret = __stmt_write_step(daci_handler, stmt); + __stmt_finalize(daci_handler, stmt); + _EXTERN_FUNC_EXIT; return ret; } @@ -1554,21 +1611,81 @@ sync_agent_da_return_e da_delete_item_by_item_type_id(SYNC_AGENT_DA_HANDLER * da } sync_agent_free_memory_item_info(item_info, count); - _EXTERN_FUNC_EXIT; - return __stmt_finalize(daci_handler, stmt); DACI_FINISH: - sync_agent_free_memory_item_info(item_info, count); - if (stmt != NULL) __stmt_finalize(daci_handler, stmt); - return SYNC_AGENT_DA_ERR_QUERY_FAILED; } + +sync_agent_da_return_e da_delete_all_child_item(SYNC_AGENT_DA_HANDLER * daci_handler, char *parent_service_id) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(daci_handler == NULL, SYNC_AGENT_DA_ERRORS, "SYNC_AGENT_DA_HANDLER is NULL !!"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + daci_stmt stmt = 0; + char query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = {0,}; + + snprintf(query, sizeof(query), "delete from item_tbl where parent_service_id = %s", parent_service_id); + _DEBUG_INFO("query = %s", query); + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == NULL) { + _DEBUG_ERROR("stmt is null"); + ret = SYNC_AGENT_DA_ERRORS; + goto return_part; + } + + ret = __stmt_write_step(daci_handler, stmt); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("__stmt_write_step failed"); + goto return_part; + } + __stmt_finalize(daci_handler, stmt); + + return_part: + _EXTERN_FUNC_EXIT; + return ret; +} + +sync_agent_da_return_e da_delete_child_item(SYNC_AGENT_DA_HANDLER * daci_handler, char *parent_service_id, char *child_service_id) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(daci_handler == NULL, SYNC_AGENT_DA_ERRORS, "SYNC_AGENT_DA_HANDLER is NULL !!"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + daci_stmt stmt = 0; + char query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = {0,}; + + snprintf(query, sizeof(query), "delete from item_tbl where parent_service_id = %s and service_id = %s", parent_service_id, child_service_id); + _DEBUG_INFO("query = %s", query); + + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt == NULL) { + _DEBUG_ERROR("stmt is null"); + ret = SYNC_AGENT_DA_ERRORS; + goto return_part; + } + + ret = __stmt_write_step(daci_handler, stmt); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("__stmt_write_step failed"); + goto return_part; + } + __stmt_finalize(daci_handler, stmt); + + return_part: + _EXTERN_FUNC_EXIT; + return ret; +} + sync_agent_da_return_e da_delete_item_by_item_type_id_new(SYNC_AGENT_DA_HANDLER * daci_handler, int account_id, int item_type_id) { _EXTERN_FUNC_ENTER; @@ -1664,9 +1781,7 @@ char *da_get_item_item_id(SYNC_AGENT_DA_HANDLER * daci_handler, int account_id, __stmt_finalize(daci_handler, stmt); } - _EXTERN_FUNC_EXIT; - return item_id; } @@ -1755,7 +1870,8 @@ sync_agent_da_item_s *da_get_item(SYNC_AGENT_DA_HANDLER * daci_handler, char *it item->account_id = __stmt_column_int(stmt, 2); item->folder_id = _stmt_column_text(stmt, 3); item->service_id = _stmt_column_text(stmt, 4); - item->access_name = _stmt_column_text(stmt, 6); + item->parent_service_id = _stmt_column_text(stmt, 5); + item->access_name = _stmt_column_text(stmt, 7); } __stmt_finalize(daci_handler, stmt); } @@ -1788,7 +1904,8 @@ sync_agent_da_return_e da_get_item_new(SYNC_AGENT_DA_HANDLER * daci_handler, cha (*sync_agent_item)->account_id = __stmt_column_int(stmt, 2); (*sync_agent_item)->folder_id = _stmt_column_text(stmt, 3); (*sync_agent_item)->service_id = _stmt_column_text(stmt, 4); - (*sync_agent_item)->access_name = _stmt_column_text(stmt, 6); + (*sync_agent_item)->parent_service_id = _stmt_column_text(stmt, 5); + (*sync_agent_item)->access_name = _stmt_column_text(stmt, 7); } __stmt_finalize(daci_handler, stmt); } @@ -1998,7 +2115,7 @@ sync_agent_da_item_s *da_get_item_by_account_id(SYNC_AGENT_DA_HANDLER * daci_han char *new_table = 0; int row_count = 0; int col_count = 0; - int index = 6; + int index = 7; int i = 0; char g_daci_query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = { 0, }; @@ -2006,9 +2123,8 @@ sync_agent_da_item_s *da_get_item_by_account_id(SYNC_AGENT_DA_HANDLER * daci_han if (new_table == NULL) return item; -// snprintf(g_daci_query, sizeof(g_daci_query), "select item_id, data_store_id, account_id, folder_id, service_id, access_name from item_tbl where account_id = %d and data_store_id = %d", accountId, itemTypeId); snprintf(g_daci_query, sizeof(g_daci_query), - "select item.item_id, item.data_store_id, item.account_id, item.folder_id, item.service_id, item.access_name " "from item_tbl as item " "left join %s as changelog " "using (item_id) " + "select item.item_id, item.data_store_id, item.account_id, item.folder_id, item.service_id, item.parent_service_id, item.access_name " "from item_tbl as item " "left join %s as changelog " "using (item_id) " "where item.account_id = %d and item.data_store_id = %d and (changelog.operation_id is null or changelog.operation_id != 303)", new_table, account_id, itemTypeId); _DEBUG_INFO("g_daci_query = %s", g_daci_query); @@ -2033,6 +2149,8 @@ sync_agent_da_item_s *da_get_item_by_account_id(SYNC_AGENT_DA_HANDLER * daci_han index++; item[i].service_id = SYNC_AGENT_DA_STRDUP(result[index]); index++; + item[i].parent_service_id = SYNC_AGENT_DA_STRDUP(result[index]); + index++; item[i].access_name = SYNC_AGENT_DA_STRDUP(result[index]); index++; } @@ -2062,7 +2180,7 @@ sync_agent_da_return_e da_get_item_by_account_id_new(SYNC_AGENT_DA_HANDLER * dac char *new_table = 0; int row_count = 0; int col_count = 0; - int index = 6; + int index = 7; int i = 0; char g_daci_query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = { 0, }; @@ -2072,7 +2190,7 @@ sync_agent_da_return_e da_get_item_by_account_id_new(SYNC_AGENT_DA_HANDLER * dac // snprintf(g_daci_query, sizeof(g_daci_query), "select item_id, data_store_id, account_id, folder_id, service_id, access_name from item_tbl where account_id = %d and data_store_id = %d", accountId, itemTypeId); snprintf(g_daci_query, sizeof(g_daci_query), - "select item.item_id, item.data_store_id, item.account_id, item.folder_id, item.service_id, item.access_name " "from item_tbl as item " "left join %s as changelog " "using (item_id) " + "select item.item_id, item.data_store_id, item.account_id, item.folder_id, item.service_id, item.parent_service_id, item.access_name " "from item_tbl as item " "left join %s as changelog " "using (item_id) " "where item.account_id = %d and item.data_store_id = %d and (changelog.operation_id is null or changelog.operation_id != 303)", new_table, account_id, item_type_id); _DEBUG_INFO("g_daci_query = %s", g_daci_query); @@ -2097,6 +2215,8 @@ sync_agent_da_return_e da_get_item_by_account_id_new(SYNC_AGENT_DA_HANDLER * dac index++; item->service_id = SYNC_AGENT_DA_STRDUP(result[index]); index++; + item->parent_service_id = SYNC_AGENT_DA_STRDUP(result[index]); + index++; item->access_name = SYNC_AGENT_DA_STRDUP(result[index]); index++; @@ -2693,11 +2813,9 @@ sync_agent_da_return_e da_get_item_id_list_by_operation_id_new(SYNC_AGENT_DA_HAN if (result != NULL) { __free_table(result); } - /* memory free */ - SYNC_AGENT_DA_MEMORY_FREE(new_table); + SYNC_AGENT_DA_MEMORY_FREE(new_table); _EXTERN_FUNC_EXIT; - return ret; } @@ -4614,6 +4732,62 @@ sync_agent_da_return_e da_get_item_count_by_datastore_id(SYNC_AGENT_DA_HANDLER * return SYNC_AGENT_DA_SUCCESS; } +sync_agent_da_return_e da_get_updated_exdate_item_id_list(SYNC_AGENT_DA_HANDLER *daci_handler, char *fw_id, GList ** list) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(daci_handler == NULL, SYNC_AGENT_DA_ERRORS, "SYNC_AGENT_DA_HANDLER is NULL !!"); + retvm_if(fw_id == NULL, SYNC_AGENT_DA_ERRORS, "fw_id is NULL !!"); + + char **result = 0; + char *parent_service_id = NULL; + char *item_id; + char query[SYNC_AGENT_DA_MAX_QUERY_LENGTH] = {0, }; + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + int row_count = 0; + int col_count = 0; + int index = 1; + int i = 0; + daci_stmt stmt = 0; + + snprintf(query, sizeof(query), "select service_id from item_tbl where item_id = %s", fw_id); + _DEBUG_INFO("query : %s", query); + stmt = __query_prepare(daci_handler, query, strlen(query)); + if (stmt != NULL) { + ret = _stmt_read_step(daci_handler, stmt); + if (ret == SYNC_AGENT_DA_ERR_MORE_DATA) + parent_service_id = _stmt_column_text(stmt, 0); + else { + _DEBUG_ERROR("_stmt_read_step() failed"); + __stmt_finalize(daci_handler, stmt); + goto return_part; + } + __stmt_finalize(daci_handler, stmt); + } + SYNC_AGENT_DA_MEMORY_SET(query); + + snprintf(query, sizeof(query), "select item_id from item_tbl where parent_service_id = \'%s\'", parent_service_id); + _DEBUG_INFO("query : %s", query); + + ret = _get_table(daci_handler, query, &result, &row_count, &col_count); + if ((ret == SYNC_AGENT_DA_SUCCESS) && (row_count != 0) && (result != 0)) { + for (i = 0; i < row_count; i++) { + item_id = NULL; + item_id = SYNC_AGENT_DA_STRDUP(result[index]); + index++; + *list = g_list_append(*list, item_id); + } + } + + if (result != NULL) { + __free_table(result); + } + +return_part: + _EXTERN_FUNC_EXIT; + return ret; +} + int _busy_handler(void *pData, int count) { diff --git a/src/framework/data-adapter/agent.h b/src/framework/data-adapter/agent.h index e894b88..21dae19 100755 --- a/src/framework/data-adapter/agent.h +++ b/src/framework/data-adapter/agent.h @@ -384,7 +384,7 @@ int da_is_exist_folder(SYNC_AGENT_DA_HANDLER * daci_handler, int account_id, cha */ /** - * @brief Insert item into item_tbl - currently unused function + * @brief Insert item into item_tbl * @param[in] daci_handler sqlite3 handler pointer about thread * @param[in] item array of item info * @param[in] count count of item info @@ -396,6 +396,17 @@ sync_agent_da_return_e da_add_item(SYNC_AGENT_DA_HANDLER * daci_handler, sync_ag /** * @brief Insert item into item_tbl + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] fw_id framework id + * @param[in] parent_id parent service id of fw_id item + * @return Operation result + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval negative value error + */ +sync_agent_da_return_e da_update_item(SYNC_AGENT_DA_HANDLER * daci_handler, char *fw_id, char *parent_id); + +/** + * @brief Insert item into item_tbl * @param[in] daci_handler sqlite3 handler pointer about thread * @param[in] item array of item info * @param[in] count count of item info @@ -428,6 +439,27 @@ sync_agent_da_return_e da_delete_item_by_Item_id(SYNC_AGENT_DA_HANDLER * daci_ha sync_agent_da_return_e da_delete_item_by_item_type_id(SYNC_AGENT_DA_HANDLER * daci_handler, int account_id, int item_type_id); /** + * @brief Delete child item from item_tbl by parent service id + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] parent_service_id parent service id + * @return Operation result + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval negative value error + */ +sync_agent_da_return_e da_delete_all_child_item(SYNC_AGENT_DA_HANDLER * daci_handler, char *parent_service_id); + +/** + * @brief Delete child item from item_tbl by parent service id + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] parent_service_id parent service id + * @return Operation result + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval negative value error + */ +sync_agent_da_return_e da_delete_child_item(SYNC_AGENT_DA_HANDLER * daci_handler, char *parent_service_id, char *child_service_id); + + +/** * @brief Delete item from item_tbl by account id and item type id * @param[in] daci_handler sqlite3 handler pointer about thread * @param[in] account_id account id @@ -1313,6 +1345,18 @@ sync_agent_da_return_e da_update_id_page(SYNC_AGENT_DA_HANDLER * daci_handler, s * @retval error value fail */ sync_agent_da_return_e da_get_item_count_by_datastore_id(SYNC_AGENT_DA_HANDLER *daci_handler, int data_store_id, int fw_account_id, int *item_count); + +/* + * @brief get updated_exdate_item count with parent item's framework id + * @param[in] daci_handler sqlite3 handler pointer about thread + * @param[in] fw_id framework id of the parent item + * @param[in] list list as returned updated exdate item_id list + * @return sync_agent_da_return_e + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval error value fail + */ +sync_agent_da_return_e da_get_updated_exdate_item_id_list(SYNC_AGENT_DA_HANDLER *daci_handler, char *fw_id, GList ** list); + /* * ============================================================================================================================= * Testing diff --git a/src/framework/data-adapter/agent_handler_manager.c b/src/framework/data-adapter/agent_handler_manager.c index 3c3ddf7..b37dde4 100755 --- a/src/framework/data-adapter/agent_handler_manager.c +++ b/src/framework/data-adapter/agent_handler_manager.c @@ -526,6 +526,23 @@ sync_agent_da_return_e da_add_item_internal(sync_agent_da_item_s * item, int cou return da_add_item(daci_handler, item, count); } +sync_agent_da_return_e da_update_item_internal(char *fw_id, char *parent_id) +{ + _EXTERN_FUNC_ENTER; + retvm_if(fw_id == NULL, SYNC_AGENT_DA_ERRORS, "fw_id is NULL !!"); + retvm_if(parent_id == NULL, SYNC_AGENT_DA_ERRORS, "parent_id is NULL !!"); + + SYNC_AGENT_DA_HANDLER *daci_handler = da_get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID); + if (daci_handler == NULL) { + _DEBUG_ERROR("[%s] no handler for key\n", __func__); + return SYNC_AGENT_DA_ERR_DB_HANDLER_MGR; + } + + _EXTERN_FUNC_EXIT; + return da_update_item(daci_handler, fw_id, parent_id); +} + + sync_agent_da_return_e sync_agent_add_item_new(sync_agent_da_item_s * item, int count, char **item_id) { _EXTERN_FUNC_ENTER; @@ -575,6 +592,35 @@ sync_agent_da_return_e da_delete_item_by_item_type_id_internal(int account_id, i return da_delete_item_by_item_type_id(daci_handler, account_id, item_type_id); } +sync_agent_da_return_e da_delete_all_child_item_internal(char *parent_service_id) +{ + _EXTERN_FUNC_ENTER; + + SYNC_AGENT_DA_HANDLER *daci_handler = da_get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID); + if (daci_handler == NULL) { + _DEBUG_ERROR("[%s] no handler for key\n", __func__); + return SYNC_AGENT_DA_ERR_DB_HANDLER_MGR; + } + + _EXTERN_FUNC_EXIT; + return da_delete_all_child_item(daci_handler, parent_service_id); +} + +sync_agent_da_return_e da_delete_child_item_internal(char *parent_service_id, char *child_service_id) +{ + _EXTERN_FUNC_ENTER; + + SYNC_AGENT_DA_HANDLER *daci_handler = da_get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID); + if (daci_handler == NULL) { + _DEBUG_ERROR("[%s] no handler for key\n", __func__); + return SYNC_AGENT_DA_ERR_DB_HANDLER_MGR; + } + + _EXTERN_FUNC_EXIT; + return da_delete_child_item(daci_handler, parent_service_id, child_service_id); +} + + sync_agent_da_return_e da_delete_item_and_changelog_by_item_type_id_internal(int account_id, int item_type_id) { _EXTERN_FUNC_ENTER; @@ -1373,12 +1419,16 @@ sync_agent_da_return_e da_add_agent_handler(unsigned int key, SYNC_AGENT_DA_HAND /* For test log */ __print_agentDBHashTableLog(); #endif + pthread_mutex_unlock(agent_db_handler_mgr->daci_handlerTable_mutex); + _EXTERN_FUNC_EXIT; + return ret; addagentHandler: pthread_mutex_unlock(agent_db_handler_mgr->daci_handlerTable_mutex); - + if(key_copy != NULL) { + free(key_copy); + } _EXTERN_FUNC_EXIT; - return ret; } diff --git a/src/framework/data-adapter/agent_handler_manager_internal.h b/src/framework/data-adapter/agent_handler_manager_internal.h index f9e2d3c..f908c0c 100755 --- a/src/framework/data-adapter/agent_handler_manager_internal.h +++ b/src/framework/data-adapter/agent_handler_manager_internal.h @@ -368,7 +368,7 @@ sync_agent_da_id_list_s *da_get_folder_id_list_by_item_type_id_internal(int acco sync_agent_da_folder_s *da_get_item_mapping_service_id_by_folder_id_internal(int account_id, char *folder_id, int *count); /** - * @brief Insert item into item_tbl - currently unused function + * @brief Insert item into item_tbl * @param[in] item array of item info * @param[in] count count of item info * @return Operation result @@ -378,6 +378,16 @@ sync_agent_da_folder_s *da_get_item_mapping_service_id_by_folder_id_internal(int sync_agent_da_return_e da_add_item_internal(sync_agent_da_item_s * item, int count); /** + * @brief Update item into item_tbl + * @param[in] fw_id framework id + * @param[in] parent_id parent service id of fw_id item + * @return Operation result + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval negative value error + */ +sync_agent_da_return_e da_update_item_internal(char *fw_id, char *parent_id); + +/** * @brief Insert item into item_tbl * @param[in] item array of item info * @param[in] count count of item info @@ -408,6 +418,26 @@ sync_agent_da_return_e da_delete_item_by_item_id_internal(char *item_id); sync_agent_da_return_e da_delete_item_by_item_type_id_internal(int account_id, int item_type_id); /** + * @brief Delete child item from item_tbl by parent service id + * @param[in] parent_service_id parent service id + * @return Operation result + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval negative value error + */ +sync_agent_da_return_e da_delete_all_child_item_internal(char *parent_service_id); + +/** + * @brief Delete child item from item_tbl by parent service id + * @param[in] parent_service_id parent service id + * @return Operation result + * @retval SYNC_AGENT_DA_SUCCESS success + * @retval negative value error + */ +sync_agent_da_return_e da_delete_child_item_internal(char *parent_service_id, char *child_service_id); + + + +/** * @brief Delete item from item_tbl by account id and item type id and row that checked delete from changelog tbl * @param[in] account_id account id * @param[in] item_type_id item type id diff --git a/src/framework/data-adapter/agent_manager.c b/src/framework/data-adapter/agent_manager.c index 6c4ac22..6f80b02 100755 --- a/src/framework/data-adapter/agent_manager.c +++ b/src/framework/data-adapter/agent_manager.c @@ -219,8 +219,8 @@ EXPORT_API sync_agent_da_return_e sync_agent_refresh_item_tbl_from_service(int f /* * insert item table */ - plugin_get_changed_item_for_folder_add_cb func_get_changed_item_for_folder_add = plugin_get_function_get_chaned_item_for_folder_add(service_type); - plugin_get_changed_item_for_folder_update_cb func_get_changed_item_for_folder_update = plugin_get_function_get_chaned_item_for_folder_update(service_type); + plugin_get_changed_item_for_folder_add_cb func_get_changed_item_for_folder_add = plugin_get_function_get_changed_item_for_folder_add(service_type); + plugin_get_changed_item_for_folder_update_cb func_get_changed_item_for_folder_update = plugin_get_function_get_changed_item_for_folder_update(service_type); int service_account_id = acc_get_service_account_id(service_type, fw_account_id); _DEBUG_INFO("service_account_id : %d", service_account_id); @@ -268,6 +268,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_refresh_item_tbl_from_service(int f item.folder_id = fw_folder_id_list[i]; item.data_store_id = service_type; item.service_id = cursor_ptr->item_id; + item.parent_service_id = cursor_ptr->parent_item_id; item.access_name = "DACI"; sync_agent_da_return_e ret = da_add_item_internal(&item, 1); @@ -278,6 +279,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_refresh_item_tbl_from_service(int f sync_agent_plugin_item_node_s *temp = cursor_ptr; cursor_ptr = cursor_ptr->next; free(temp->item_id); + free(temp->parent_item_id); free(temp); if (fw_item_id_list[y] != NULL) { @@ -308,6 +310,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_refresh_item_tbl_from_service(int f item.folder_id = fw_folder_id_list[i]; item.data_store_id = service_type; item.service_id = cursor_ptr->item_id; + item.parent_service_id = cursor_ptr->parent_item_id; item.access_name = "DACI"; sync_agent_da_return_e ret = da_add_item_internal(&item, 1); @@ -318,6 +321,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_refresh_item_tbl_from_service(int f sync_agent_plugin_item_node_s *temp = cursor_ptr; cursor_ptr = cursor_ptr->next; free(temp->item_id); + free(temp->parent_item_id); free(temp); if (fw_item_id_list[y] != NULL) { @@ -368,7 +372,7 @@ sync_agent_da_return_e da_refresh_changelog_tbl_from_service(int fw_account_id, /* * Construct Item & changelog table */ - plugin_get_changed_item_for_folder_add_cb func_get_changed_item_for_folder_add = plugin_get_function_get_chaned_item_for_folder_add(service_type); + plugin_get_changed_item_for_folder_add_cb func_get_changed_item_for_folder_add = plugin_get_function_get_changed_item_for_folder_add(service_type); int service_account_id = acc_get_service_account_id(service_type, fw_account_id); _DEBUG_INFO("service_account_id : %d", service_account_id); @@ -407,11 +411,18 @@ sync_agent_da_return_e da_refresh_changelog_tbl_from_service(int fw_account_id, if (fw_item_id_list != NULL) { int k = 0; for (; k < item_cnt; k++) { + sync_agent_da_item_s item; char *service_item_id = cursor_ptr->item_id; _DEBUG_INFO("service_item_id[%d] : %s", k, service_item_id); _DEBUG_INFO("fw_item_id : %s", fw_item_id_list[k]); - da_changelog_add_item_internal(fw_account_id, fw_item_id_list[k], cursor_ptr->item_id, service_type, fw_folder_id_list[i]); + item.item_id = fw_item_id_list[k]; + item.data_store_id = service_type; + item.account_id = fw_account_id; + item.folder_id = fw_folder_id_list[i]; + item.service_id = cursor_ptr->item_id; + item.parent_service_id = cursor_ptr->parent_item_id; + da_changelog_add_item_internal(&item); sync_agent_plugin_item_node_s *temp = cursor_ptr; cursor_ptr = cursor_ptr->next; @@ -508,9 +519,9 @@ sync_agent_da_return_e _construct_change_log_tbl_from_service(int fw_account_id, int fw_change_point = _get_serivce_change_point(fw_account_id, service_type); _DEBUG_TRACE("fw_last_change_point : %d", fw_change_point); - plugin_get_changed_item_for_folder_add_cb func_get_changed_item_for_folder_add = plugin_get_function_get_chaned_item_for_folder_add(service_type); - plugin_get_changed_item_for_folder_delete_cb func_get_changed_item_for_folder_del = plugin_get_function_get_chaned_item_for_folder_delete(service_type); - plugin_get_changed_item_for_folder_update_cb func_get_changed_item_for_folder_update = plugin_get_function_get_chaned_item_for_folder_update(service_type); + plugin_get_changed_item_for_folder_add_cb func_get_changed_item_for_folder_add = plugin_get_function_get_changed_item_for_folder_add(service_type); + plugin_get_changed_item_for_folder_delete_cb func_get_changed_item_for_folder_del = plugin_get_function_get_changed_item_for_folder_delete(service_type); + plugin_get_changed_item_for_folder_update_cb func_get_changed_item_for_folder_update = plugin_get_function_get_changed_item_for_folder_update(service_type); /* * todo Get fw_folder_id list in the service @@ -553,7 +564,14 @@ sync_agent_da_return_e _construct_change_log_tbl_from_service(int fw_account_id, int y = 0; if (fw_item_id_list != NULL) { for (; y < added_item_cnt; y++) { - da_changelog_add_item_internal(fw_account_id, fw_item_id_list[y], cursor_ptr->item_id, service_type, fw_folder_id_list[i]); + sync_agent_da_item_s item; + item.item_id = fw_item_id_list[y]; + item.data_store_id = service_type; + item.account_id = fw_account_id; + item.folder_id = fw_folder_id_list[i]; + item.service_id = cursor_ptr->item_id; + item.parent_service_id = cursor_ptr->parent_item_id; + da_changelog_add_item_internal(&item); sync_agent_plugin_item_node_s *temp = cursor_ptr; cursor_ptr = cursor_ptr->next; free(temp->item_id); @@ -610,7 +628,14 @@ sync_agent_da_return_e _construct_change_log_tbl_from_service(int fw_account_id, char *fw_item_id = da_get_item_id_internal(fw_account_id, cursor_ptr->item_id, service_type); if (fw_item_id == NULL) { - da_changelog_add_item_internal(fw_account_id, fw_item_id_list[y], cursor_ptr->item_id, service_type, fw_folder_id_list[i]); + sync_agent_da_item_s item; + item.item_id = fw_item_id_list[y]; + item.data_store_id = service_type; + item.account_id = fw_account_id; + item.folder_id = fw_folder_id_list[i]; + item.service_id = cursor_ptr->item_id; + item.parent_service_id = cursor_ptr->parent_item_id; + da_changelog_add_item_internal(&item); } else { da_changelog_update_item_internal(fw_account_id, fw_item_id, service_type); } diff --git a/src/framework/data-adapter/changelog.c b/src/framework/data-adapter/changelog.c index 52494e0..a4855b2 100755 --- a/src/framework/data-adapter/changelog.c +++ b/src/framework/data-adapter/changelog.c @@ -46,7 +46,7 @@ static pthread_mutex_t change_lock; -int da_handle_add_item(int service_account_id, int index, char *service_item_id, int item_type, char *service_folder_id, int folder_type) +int da_handle_add_item(int service_account_id, int index, char *service_item_id, char *parent_service_item_id, int item_type, char *service_folder_id, int folder_type) { _EXTERN_FUNC_ENTER; @@ -71,6 +71,7 @@ int da_handle_add_item(int service_account_id, int index, char *service_item_id, _DEBUG_INFO("itemType : %d", item_type); _DEBUG_INFO("service_folderID : %s", service_folder_id); _DEBUG_INFO("folderType : %d", folder_type); + _DEBUG_INFO("parent_service_item_id : %s", parent_service_item_id); sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; sync_agent_da_return_e open_ret = SYNC_AGENT_DA_SUCCESS; @@ -139,14 +140,13 @@ int da_handle_add_item(int service_account_id, int index, char *service_item_id, goto DACI_FINISH; } - /* - * add item - */ + // add item item.account_id = fw_account_id; item.item_id = fw_item_id; item.folder_id = fw_folder_id; item.data_store_id = item_type; item.service_id = service_item_id; + item.parent_service_id = parent_service_item_id; item.access_name = "DACI_ChangeLog"; ret = da_add_item_internal(&item, 1); @@ -155,18 +155,18 @@ int da_handle_add_item(int service_account_id, int index, char *service_item_id, goto DACI_FINISH; } - /* - * add change log - */ - item_changelog.item_id = fw_item_id; - item_changelog.operation_id = 301; - item_changelog.status = "SYNC_REQUIRED"; - item_changelog.access_name = "DACI_ChangeLog"; + // add change log (only for normal item not calendar exdate item) + if (parent_service_item_id == NULL) { + item_changelog.item_id = fw_item_id; + item_changelog.operation_id = 301; + item_changelog.status = "SYNC_REQUIRED"; + item_changelog.access_name = "DACI_ChangeLog"; - ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1); - if (ret != SYNC_AGENT_DA_SUCCESS) { - _DEBUG_ERROR("Failed to Add Item changelog : %d", ret); - goto DACI_FINISH; + ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("Failed to Add Item changelog : %d", ret); + goto DACI_FINISH; + } } DACI_FINISH: @@ -340,7 +340,7 @@ int da_handle_del_item(int service_account_id, int index, char *service_item_id, return ret; } -int da_handle_update_item(int service_account_id, int index, char *service_item_id, int item_type) +int da_handle_update_item(int service_account_id, int index, char *service_item_id, char *parent_service_item_id, int item_type) { _EXTERN_FUNC_ENTER; @@ -358,6 +358,7 @@ int da_handle_update_item(int service_account_id, int index, char *service_item_ _DEBUG_INFO("service_accountID : %d", service_account_id); _DEBUG_INFO("service_itemID : %s", service_item_id); _DEBUG_INFO("itemType : %d", item_type); + _DEBUG_INFO("parent_service_item_id : %s", parent_service_item_id); sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; sync_agent_da_return_e open_ret = SYNC_AGENT_DA_SUCCESS; @@ -423,8 +424,17 @@ int da_handle_update_item(int service_account_id, int index, char *service_item_ } } + // update parent_id (only for Calendar exdate item) + if (parent_service_item_id != NULL) { + ret = da_update_item_internal(fw_item_id, parent_service_item_id); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("da_update_item_internal failed"); + goto DACI_FINISH; + } + } + DACI_FINISH: - /*open test */ + _DEBUG_INFO("return_part"); daci_res = sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT); if (daci_res != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("sync_agent_end_transaction fail"); @@ -446,17 +456,14 @@ int da_handle_update_item(int service_account_id, int index, char *service_item_ } _EXTERN_FUNC_EXIT; - return ret; } -int da_changelog_add_item_internal(int fw_account_id, char *fw_item_id, char *service_item_id, int item_type, char *fw_folder_id) +int da_changelog_add_item_internal(sync_agent_da_item_s *item) { _EXTERN_FUNC_ENTER; - retvm_if(fw_item_id == NULL, 0, "fw item id is NULL !!"); - retvm_if(service_item_id == NULL, 0, "service item id is NULL !!"); - retvm_if(fw_folder_id == NULL, 0, "fw folder id is NULL !!"); + retvm_if(item == NULL, 0, "fw item id is NULL !!"); /* * TODO : 1. Need to Null check parameter @@ -465,68 +472,38 @@ int da_changelog_add_item_internal(int fw_account_id, char *fw_item_id, char *se * 4. generate item luid * 5. add item & change log */ - _DEBUG_INFO("fw_account_id : %d", fw_account_id); - _DEBUG_INFO("fw_item_id : %s", fw_item_id); - _DEBUG_INFO("service_item_id : %s", service_item_id); - _DEBUG_INFO("itemType : %d", item_type); - _DEBUG_INFO("fw_folder_id : %s", fw_folder_id); + _DEBUG_INFO("item_id : %s", item->item_id); + _DEBUG_INFO("data_store_id : %d", item->data_store_id); + _DEBUG_INFO("account_id : %d", item->account_id); + _DEBUG_INFO("folder_id : %s", item->folder_id); + _DEBUG_INFO("service_id : %s", item->service_id); + _DEBUG_INFO("parent_service_id : %s", item->parent_service_id); sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; - - sync_agent_da_item_s item; sync_agent_da_item_changelog_s item_changelog; - /* - * check whether the item is included - */ - - /* - char *item_id = sync_agent_get_item_id(fw_account_id, service_item_id, itemType); - if (item_id != NULL) { - _DEBUG_ERROR("Item already exists : %s", item_id); - goto DACI_FINISH; - } - */ - - /* - * add item - */ - item.account_id = fw_account_id; - item.item_id = fw_item_id; - item.folder_id = fw_folder_id; - item.data_store_id = item_type; - item.service_id = service_item_id; - item.access_name = "DACI_ChangeLog"; - - ret = da_add_item_internal(&item, 1); + // add item + item->access_name = "DACI_ChangeLog"; + ret = da_add_item_internal(item, 1); if (ret != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("add item failed return : %d", ret); goto DACI_FINISH; } - /* - * add change log - */ - item_changelog.item_id = fw_item_id; + // add change log + item_changelog.item_id = item->item_id; item_changelog.operation_id = 301; item_changelog.status = "SYNC_REQUIRED"; item_changelog.access_name = "DACI_ChangeLog"; - ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1); + ret = da_add_item_changelog_wrapper(item->account_id, &item_changelog, 1); if (ret != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("add item changelog failed return : %d", ret); goto DACI_FINISH; } DACI_FINISH: - /* - if (item_id != NULL) { - free(item_id); - } - */ - _EXTERN_FUNC_EXIT; - return ret; } @@ -546,30 +523,14 @@ EXPORT_API sync_agent_da_return_e sync_agent_changelog_add_item_new(sync_agent_d sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; sync_agent_da_item_changelog_s item_changelog; - /* - * check whether the item is included - */ - - /* - char *item_id = sync_agent_get_item_id(fw_account_id, service_item_id, itemType); - if (item_id != NULL) { - _DEBUG_ERROR("Item already exists : %s", item_id); - goto DACI_FINISH; - } - */ - - /* - * add item - */ + // 1. add item ret = sync_agent_add_item_new(sync_agent_item, 1, item_id); if (ret != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("add item failed return : %d", ret); goto DACI_FINISH; } - /* - * add change log - */ + // 2. add change log item_changelog.item_id = *item_id; item_changelog.operation_id = 301; item_changelog.status = "SYNC_REQUIRED"; @@ -582,14 +543,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_changelog_add_item_new(sync_agent_d } DACI_FINISH: - /* - if (item_id != NULL) { - free(item_id); - } - */ - _EXTERN_FUNC_EXIT; - return ret; } @@ -952,3 +906,37 @@ EXPORT_API sync_agent_da_return_e sync_agent_changelog_update_item_new(int fw_ac return ret; } + +int da_handle_del_child_item(char *parent_service_id, char *child_service_id) +{ + _EXTERN_FUNC_ENTER; + retvm_if(parent_service_id == NULL, 0, "parent_service_id is NULL!!"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + // If child_service_id is null, it means that all child item should be deleted. + if (child_service_id) { + _DEBUG_INFO("parent id = %s, child id = %s", parent_service_id, child_service_id); + ret = da_delete_child_item_internal(parent_service_id, child_service_id); + goto_if(ret != SYNC_AGENT_DA_SUCCESS, "da_delete_child_item_internal() failed"); + } + else { + sync_agent_da_return_e open_ret = sync_agent_open_agent(); + _DEBUG_INFO("Done Open Agent DB : %d", open_ret); + + sync_agent_da_return_e daci_res = sync_agent_begin_transaction(); + if (daci_res != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("sync_agent_begin_transaction fail"); } + + ret = da_delete_all_child_item_internal(parent_service_id); + if (ret != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("da_delete_all_child_item_internal() failed"); } + + daci_res = sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT); + if (daci_res != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("sync_agent_end_transaction fail"); } + + open_ret = sync_agent_close_agent(); + _DEBUG_INFO("Done Close Agent DB : %d", open_ret); + } + +return_part: + _EXTERN_FUNC_EXIT; + return ret; +} diff --git a/src/framework/data-adapter/changelog.h b/src/framework/data-adapter/changelog.h index 154b2b6..803c04d 100755 --- a/src/framework/data-adapter/changelog.h +++ b/src/framework/data-adapter/changelog.h @@ -45,7 +45,8 @@ extern "C" { * @param[in] fw_folder_id sync-agent-framework folder id * @return 1 on success, otherwise a negative error value */ - int da_changelog_add_item_internal(int fw_account_id, char *fw_item_id, char *service_item_id, int item_type, char *fw_folder_id); +int da_changelog_add_item_internal(sync_agent_da_item_s *item); + /** * @brief Handling added item to service storage, update sync-agent-framework item & change log table diff --git a/src/framework/data-adapter/changelog_internal.h b/src/framework/data-adapter/changelog_internal.h index c5dfd58..e916ee0 100755 --- a/src/framework/data-adapter/changelog_internal.h +++ b/src/framework/data-adapter/changelog_internal.h @@ -32,14 +32,15 @@ * @remarks This function is called when the new item is added to the service storage. data connector plugin developer use this function. * @param[in] service_account_id service account id * @param[in] index possible mapping one service account with multiple sync-agent-framework account, so need index of sync-agent-framework account. - * @param[in] service_item_id added service item id + * @param[in] service_item_id added service item id + * @param[in] parent_service_item_id parent service id of the added service item id (only Calendar exdate item) * @param[in] item_type service type - service data connector plugin's id described in sync-agent-framework config file * @param[in] service_folder_id service folder id * @param[in] folder_type folder type defined in data connector plugin * @return 1 on success, otherwise a negative error value. * @see sync_agent_changelog_add_item() */ -int da_handle_add_item(int service_account_id, int index, char *service_item_id, int item_type, char *service_folder_id, int folder_type); +int da_handle_add_item(int service_account_id, int index, char *service_item_id, char *parent_service_item_id, int item_type, char *service_folder_id, int folder_type); /** * @brief Handling deleted item from service storage, update sync-agent-framework item & change log table @@ -59,11 +60,21 @@ int da_handle_del_item(int service_account_id, int index, char *service_item_id, * @param[in] service_account_id service account id * @param[in] index possible mapping one service account with multiple sync-agent-framework account, so need index of sync-agent-framework account * @param[in] service_item_id added service item id + * @param[in] parent_service_item_id parent service id of the added service item id (only Calendar exdate item) * @param[in] item_type service type - service data connector pluIn's ID described in F/W config file * @return 1 on success, otherwise a negative error value. * @see sync_agent_changelog_update_item() */ -int da_handle_update_item(int service_account_id, int index, char *service_item_id, int item_type); +int da_handle_update_item(int service_account_id, int index, char *service_item_id, char *parent_service_item_id, int item_type); + +/** + * @brief Handling delete child item from service storage, update sync-agent-framework item & change log table + * @remarks This function is called when the item is deleted from the service storage. data connector plugin developer use this function. + * @param[in] parent_id parent service id + * @return 1 on success, otherwise a negative error value. + * @see sync_agent_changelog_delete_item() + */ +int da_handle_del_child_item(char *parent_service_id, char *child_service_id); /** * @} diff --git a/src/framework/data-adapter/common.c b/src/framework/data-adapter/common.c index f7e303b..1ce1847 100755 --- a/src/framework/data-adapter/common.c +++ b/src/framework/data-adapter/common.c @@ -62,6 +62,7 @@ void sync_agent_free_memory_item(sync_agent_da_item_s * item, int count) SYNC_AGENT_DA_MEMORY_FREE(item[i].item_id); SYNC_AGENT_DA_MEMORY_FREE(item[i].folder_id); SYNC_AGENT_DA_MEMORY_FREE(item[i].service_id); + SYNC_AGENT_DA_MEMORY_FREE(item[i].parent_service_id); SYNC_AGENT_DA_MEMORY_FREE(item[i].access_name); } SYNC_AGENT_DA_MEMORY_FREE(item); diff --git a/src/framework/data-adapter/interface_folder.c b/src/framework/data-adapter/interface_folder.c index 8c5dd24..bfd7ea2 100755 --- a/src/framework/data-adapter/interface_folder.c +++ b/src/framework/data-adapter/interface_folder.c @@ -188,9 +188,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_folder(sync_agent_da_folder_s _DEBUG_ERROR("sync_agent_folder is NULL !!"); return SYNC_AGENT_DA_ERRORS; } - _EXTERN_FUNC_EXIT; - return SYNC_AGENT_DA_SUCCESS; } @@ -225,7 +223,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_folder_list(GList * list) } _EXTERN_FUNC_EXIT; - return ret; } @@ -239,9 +236,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_folder_id(char *folder_id) _DEBUG_ERROR("folder id is NULL !!"); return SYNC_AGENT_DA_ERRORS;; } - _EXTERN_FUNC_EXIT; - return SYNC_AGENT_DA_SUCCESS; } @@ -274,8 +269,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_folder_id_list(GList * list) _DEBUG_ERROR("list is NULL !!"); return SYNC_AGENT_DA_ERRORS; } - _EXTERN_FUNC_EXIT; - return ret; } diff --git a/src/framework/data-adapter/interface_item.c b/src/framework/data-adapter/interface_item.c index a615c3f..5fc308c 100755 --- a/src/framework/data-adapter/interface_item.c +++ b/src/framework/data-adapter/interface_item.c @@ -47,50 +47,28 @@ EXPORT_API sync_agent_da_return_e sync_agent_create_item(sync_agent_da_item_s ** } _EXTERN_FUNC_EXIT; - return SYNC_AGENT_DA_SUCCESS; } EXPORT_API sync_agent_da_return_e sync_agent_add_item(sync_agent_da_item_s * sync_agent_item, char **item_id, int use_changelog) { _EXTERN_FUNC_ENTER; - retvm_if(sync_agent_item == NULL, SYNC_AGENT_DA_ERRORS, "sync_agent_da_item_s is NULL !!"); sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; - -// item_id = (char **) calloc(count, sizeof(char *)); -// if (item_id == NULL) { -// _DEBUG_ERROR("calloc failed !!"); -// } -// -// for (i; i < count; i++) { -// if (use_changelog == 1) { -// ret = sync_agent_changelog_add_item_new(sync_agent_item, item_id); -// } else { -// ret = sync_agent_add_item_new(sync_agent_item, count, item_id); -// } -// -// if (ret != SYNC_AGENT_DA_SUCCESS) { -// _DEBUG_ERROR("add item failed !!"); -// return ret; -// } -// } - if (use_changelog == 1) { ret = sync_agent_changelog_add_item_new(sync_agent_item, item_id); if (ret != SYNC_AGENT_DA_SUCCESS) { - _DEBUG_ERROR("da_changelog_add_item_internal() failed !!"); + _DEBUG_ERROR("sync_agent_changelog_add_item_new() failed !!"); } } else { ret = sync_agent_add_item_new(sync_agent_item, 1, item_id); if (ret != SYNC_AGENT_DA_SUCCESS) { - _DEBUG_ERROR("da_add_item_internal() failed !!"); + _DEBUG_ERROR("sync_agent_add_item_new() failed !!"); } } _EXTERN_FUNC_EXIT; - return ret; } @@ -105,12 +83,12 @@ EXPORT_API sync_agent_da_return_e sync_agent_add_bulk_item(sync_agent_da_item_s if (use_changelog == 1) { ret = sync_agent_changelog_add_item_new(sync_agent_item, item_id); if (ret != SYNC_AGENT_DA_SUCCESS) { - _DEBUG_ERROR("da_changelog_add_item_internal() failed !!"); + _DEBUG_ERROR("sync_agent_changelog_add_item_new() failed !!"); } } else { ret = sync_agent_add_item_new(sync_agent_item, 1, item_id); if (ret != SYNC_AGENT_DA_SUCCESS) { - _DEBUG_ERROR("da_add_item_internal() failed !!"); + _DEBUG_ERROR("sync_agent_add_item_new() failed !!"); } } @@ -451,24 +429,31 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_item(sync_agent_da_item_s * sy if (sync_agent_item != NULL) { if (sync_agent_item->item_id != NULL) free(sync_agent_item->item_id); + sync_agent_item->item_id = NULL; if (sync_agent_item->folder_id != NULL) free(sync_agent_item->folder_id); + sync_agent_item->folder_id = NULL; if (sync_agent_item->service_id != NULL) free(sync_agent_item->service_id); + sync_agent_item->service_id = NULL; + + if (sync_agent_item->parent_service_id != NULL) + free(sync_agent_item->parent_service_id); + sync_agent_item->parent_service_id = NULL; if (sync_agent_item->access_name != NULL) free(sync_agent_item->access_name); + sync_agent_item->access_name = NULL; free(sync_agent_item); + sync_agent_item = NULL; } else { _DEBUG_ERROR("sync_agent_item is NULL !!"); return SYNC_AGENT_DA_ERRORS; } - _EXTERN_FUNC_EXIT; - return SYNC_AGENT_DA_SUCCESS; } @@ -501,9 +486,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_item_list(GList * list) _DEBUG_ERROR("list is NULL !!"); return SYNC_AGENT_DA_ERRORS; } - _EXTERN_FUNC_EXIT; - return ret; } @@ -513,13 +496,13 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_item_id(char *item_id) if (item_id != NULL) { free(item_id); + item_id = NULL; } else { _DEBUG_ERROR("item id is NULL !!"); return SYNC_AGENT_DA_ERRORS;; } _EXTERN_FUNC_EXIT; - return SYNC_AGENT_DA_SUCCESS; } @@ -546,17 +529,15 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_item_id_list(GList * list) return ret; } } - g_list_free(list); } else { _DEBUG_INFO("list is NULL !!"); return ret; } - _EXTERN_FUNC_EXIT; - return ret; } + EXPORT_API sync_agent_da_return_e sync_agent_get_item_count(int data_store_id, int *item_count) { _EXTERN_FUNC_ENTER; @@ -608,3 +589,20 @@ return_part: _EXTERN_FUNC_EXIT; return ret; } + +EXPORT_API sync_agent_da_return_e sync_agent_get_updated_exdate_item_id_list(char *fw_id, GList ** list) +{ + _EXTERN_FUNC_ENTER; + retvm_if(fw_id == NULL, SYNC_AGENT_DA_ERRORS, "fw_id is NULL !!"); + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + + SYNC_AGENT_DA_HANDLER *daci_handler = da_get_agent_handler(SYNC_AGENT_DA_GET_THREAD_ID); + goto_if(daci_handler == NULL, "daci_handler is null"); + + ret = da_get_updated_exdate_item_id_list(daci_handler, fw_id, list); + goto_if(ret != SYNC_AGENT_DA_SUCCESS, "da_get_updated_exdate_item_id_list() failed, ret = [%d]", ret); + +return_part: + _EXTERN_FUNC_EXIT; + return ret; +} diff --git a/src/framework/data-adapter/interface_service_item.c b/src/framework/data-adapter/interface_service_item.c index 4a77f83..3e7152c 100755 --- a/src/framework/data-adapter/interface_service_item.c +++ b/src/framework/data-adapter/interface_service_item.c @@ -139,7 +139,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_create_service_item(sync_agent_da_s } _EXTERN_FUNC_EXIT; - return SYNC_AGENT_DA_SUCCESS; } @@ -165,24 +164,27 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_service_item(sync_agent_da_ser if (service_item != NULL) { if (service_item->item_id != NULL) free(service_item->item_id); - + service_item->item_id = NULL; + if (service_item->parent_id != NULL) + free(service_item->parent_id); + service_item->parent_id = NULL; if (service_item->folder_id != NULL) free(service_item->folder_id); - + service_item->folder_id = NULL; if (service_item->access_name != NULL) free(service_item->access_name); - + service_item->access_name = NULL; if (service_item->data != NULL) free((void *)(service_item->data)); - + service_item->data = NULL; free(service_item); + service_item = NULL; } else { _DEBUG_ERROR("service_item is NULL !!"); return SYNC_AGENT_DA_ERRORS; } _EXTERN_FUNC_EXIT; - return SYNC_AGENT_DA_SUCCESS; } @@ -202,9 +204,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_free_service_folder(sync_agent_da_s _DEBUG_ERROR("service_folder is NULL !!"); return SYNC_AGENT_DA_ERRORS; } - _EXTERN_FUNC_EXIT; - return SYNC_AGENT_DA_SUCCESS; } @@ -274,6 +274,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_add_service_item(sync_agent_da_serv fw_item->item_id = g_strdup(service_item->item_id); fw_item->folder_id = g_strdup(service_item->folder_id); fw_item->service_id = g_strdup(service_item_id); + fw_item->parent_service_id = g_strdup(service_item->parent_id); fw_item->access_name = g_strdup(service_item->access_name); ret = sync_agent_add_item(fw_item, item_id, update_changelog); @@ -340,21 +341,9 @@ EXPORT_API sync_agent_da_return_e sync_agent_add_service_bulk_item(sync_agent_da } /**************** phase 1 : vcard -> ctsvc struct **********************/ -/* - //for test - _DEBUG_INFO(" glist[0] = [%s]", (char *)g_list_nth_data((GList *)service_item->data, 0)); - _DEBUG_INFO(" glist[1] = [%s]", (char *)g_list_nth_data((GList *)service_item->data, 1)); - _DEBUG_INFO(" glist[%d] = [%s]", g_list_length((GList *)service_item->data)-1, (char *)g_list_nth_data((GList *)service_item->data, g_list_length((GList *)service_item->data)-1)); -*/ count = g_list_length((GList *)service_item->data); _DEBUG_INFO(" count of vcard list = [%d]", count); -/* - //for test - for (index = 0; index < count; ++index) { - _DEBUG_INFO(" item id[%d] = [%s]", index, item_id[index]); - } -*/ GList *service_data_list = NULL; for (index = 0; index < count; ++index) { da_ret = func_converter((char *)g_list_nth_data((GList *)service_item->data, index), &service_data); @@ -383,13 +372,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_add_service_bulk_item(sync_agent_da } else { _DEBUG_INFO("added service item id size = [%d]", service_item_id_count); } -/* - //for test - int i = 0; - for (i = 0; i < service_item_id_count; i++) { - _DEBUG_INFO("service_item_id[%d] = [%d]", i, service_item_id[i]); - } -*/ + /**************** phase 4 : inserted contact DB -> insert kies DB **********************/ for (index = 0; index < service_item_id_count; ++index) { da_ret = sync_agent_create_item(&fw_item); @@ -409,6 +392,8 @@ EXPORT_API sync_agent_da_return_e sync_agent_add_service_bulk_item(sync_agent_da memset(service_item_id_tmp, 0, 10); snprintf(service_item_id_tmp, 10, "%d", service_item_id[index]); fw_item->service_id = g_strdup(service_item_id_tmp); + fw_item->parent_service_id = g_strdup(service_item->parent_id); + _DEBUG_INFO("fw_item->parent_service_id = %s", fw_item->parent_service_id); fw_item->access_name = g_strdup(service_item->access_name); //for test //_DEBUG_INFO("fw_item->service_id[%d] = [%s], item_id[%d] = [%s], fw_item->item_id = [%s]", index, fw_item->service_id, index, item_id[index], fw_item->item_id); @@ -438,7 +423,6 @@ DACI_FINISH: if (da_ret != SYNC_AGENT_DA_SUCCESS) { *item_id = NULL; } - if (fw_item != NULL) { da_ret = sync_agent_free_item(fw_item); if (da_ret != SYNC_AGENT_DA_SUCCESS) { @@ -446,17 +430,14 @@ DACI_FINISH: } fw_item = NULL; } - if (service_item_id != NULL) { free(service_item_id); service_item_id = NULL; } - if (service_folder_id != NULL) { free(service_folder_id); service_folder_id = NULL; } - _EXTERN_FUNC_EXIT; return da_ret; } @@ -650,6 +631,87 @@ DACI_FINISH: return ret; } +EXPORT_API sync_agent_da_return_e sync_agent_add_updated_exdate_item(sync_agent_da_service_item_s * service_item, char *parent_id, char *child_id, bool update_changelog) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(service_item == NULL, SYNC_AGENT_DA_ERRORS, "sync_agent_da_service_item_s is NULL !!"); + retvm_if(parent_id == NULL, SYNC_AGENT_DA_ERRORS, "parent_id is NULL !!"); + + _DEBUG_INFO("account_id : %d", service_item->account_id); + _DEBUG_INFO("folder_id : %s", service_item->folder_id); + _DEBUG_INFO("parent_id : %s", parent_id); + _DEBUG_INFO("child_id : %s", child_id); + _DEBUG_INFO("service_item->item_id : %s", service_item->item_id); + _DEBUG_INFO("data : %s", (char *)service_item->data); + + char *service_folder_id = NULL; + char *service_parent_item_id = NULL; + void *service_data = NULL; + void *new_service_data = NULL; + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + int service_account_id = 0; + plugin_get_item_cb func_get_item; + plugin_replace_converter_cb func_replace_converter; + + service_account_id = acc_get_service_account_id(service_item->content_type, service_item->account_id); + _DEBUG_INFO("service_acount_id : %d", service_account_id); + service_folder_id = sync_agent_get_service_folder_id(service_item->folder_id); + _DEBUG_INFO("service_folder_id : %s", service_folder_id); + service_parent_item_id = sync_agent_get_service_item_id(parent_id); + _DEBUG_INFO("service_parent_item_id : %s", service_parent_item_id); + + /* 4. call plugIn dataconnector */ + func_get_item = plugin_get_function_get_item(service_item->content_type); + if (func_get_item == NULL) { + _DEBUG_ERROR("%d", __LINE__); + ret = SYNC_AGENT_DA_NOT_FOUND_PLUG_IN; + goto return_part; + } + + ret = func_get_item(service_account_id, service_folder_id, service_parent_item_id, &service_data); + goto_if(ret != SYNC_AGENT_DA_SUCCESS, "func_get_item() failed, ret = [%d]", ret); + + /* 5. checking whether the item exist or not*/ + ret = sync_agent_is_exist_exdate_item(service_item->content_type, service_parent_item_id, (char *)service_item->data); + if (ret == SYNC_AGENT_DA_ERR_ALREADY_EXIST) { + _DEBUG_INFO("SYNC_AGENT_DA_ERR_ALREADY_EXIST"); + ret = SYNC_AGENT_DA_SUCCESS; + goto return_part; + } + + /* 6. call plugIn dataconverter */ + int converter_plugIn_id = plugin_get_data_converter_plugin_id(service_item->content_type); + func_replace_converter = plugin_get_function_replace_converter(converter_plugIn_id); + if (func_replace_converter == NULL) { + _DEBUG_ERROR("%d", __LINE__); + ret = SYNC_AGENT_DA_NOT_FOUND_PLUG_IN; + goto return_part; + } + + ret = func_replace_converter(service_data, service_item->data, &new_service_data); + goto_if(ret != SYNC_AGENT_DA_SUCCESS, "func_replace_converter() failed, ret = [%d]", ret); + + + //////////////////////////////////////// construct the parent item //////////////////////////////// + // All child item of parent item whose has original_event_id as service_id field should be deleted before callback_add_item() + // Requesting by Calendar Svc Team (2013-03-26 tw123.kim & iamjs.kim) + sync_agent_construct_exdate_parent_item(service_item->content_type, service_parent_item_id); + +return_part: + _DEBUG_INFO("return_part"); + if (service_folder_id != NULL){ + free(service_folder_id); + service_folder_id = NULL; + } + if (new_service_data != NULL){ + free(new_service_data); + new_service_data = NULL; + } + _EXTERN_FUNC_EXIT; + return ret; +} + EXPORT_API sync_agent_da_return_e sync_agent_delete_service_item(char *item_id, bool update_changelog) { _EXTERN_FUNC_ENTER; @@ -748,13 +810,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_delete_service_bulk_item(char **ite _DEBUG_ERROR("sync_agent_create_item() fail, da_Ret[%d]", da_ret); goto DACI_FINISH; } -/* - da_ret = sync_agent_get_item(*item_id, &fw_item); - if (da_ret != SYNC_AGENT_DA_SUCCESS) { - _DEBUG_ERROR("sync_agent_get_item() fail, da_ret[%d]", da_ret); - goto DACI_FINISH; - } -*/ + da_ret = sync_agent_get_item_data_store_id(*item_id, &fw_item); if (da_ret != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("sync_agent_get_item_data_store_id() fail, da_ret[%d]", da_ret); @@ -764,11 +820,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_delete_service_bulk_item(char **ite memset(service_item_id, 0, count); for (index = 0; index < count; ++index) { service_item_id_tmp = sync_agent_get_service_item_id(item_id[index]); - //for test - //_DEBUG_INFO("service_item_id_tmp = [%s]", service_item_id_tmp); service_item_id[index] = atoi(service_item_id_tmp); - //for test - //_DEBUG_INFO("item_id[%d] = [%s], service_item_id[%d] = [%d]", index, item_id[index], index, service_item_id[index]); } func_del_bulk_item = plugin_get_function_del_bulk_item(fw_item->data_store_id); @@ -817,23 +869,12 @@ EXPORT_API sync_agent_da_return_e sync_agent_query_delete_service_items(sync_age sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; int service_account_id = 0; -/* char **folder_id_list = NULL; - int folder_id_list_cnt = 0; - char *service_item_id = NULL;*/ plugin_delete_all_items_cb func_del_all_items; /* 1. get service account id */ service_account_id = acc_get_service_account_id(query->content_type, query->account_id); _DEBUG_INFO("[sync_agent_query_delete_service_items] service_acount_id : %d", service_account_id); -/* //2. get folder id list for account id - folder_id_list = DACI_Get_Folder_Folder_Id_List_By_Account_Id(account_id, &folder_id_list_cnt); - _DEBUG_INFO("[sync_agent_query_delete_service_items] folder_id_list_cnt : %d", folder_id_list_cnt); - - //3. get service item id - service_item_id = sync_agent_get_service_item_id(item_id); - _DEBUG_INFO("[sync_agent_query_delete_service_items] service_item_id : %s", service_item_id);*/ - /* 2. call plugIn dataconnector */ func_del_all_items = plugin_get_function_del_all_items(query->content_type); @@ -846,15 +887,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_query_delete_service_items(sync_age _DEBUG_INFO("[sync_agent_query_delete_service_items] success func_del_all_items()\n"); } - /* memory free */ -/* if (service_folder_id !=NULL) - free(service_folder_id); - - if (service_item_id != NULL) - free(service_item_id);*/ - _EXTERN_FUNC_EXIT; - return ret; } @@ -867,6 +900,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_get_service_item(char *item_id, syn sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; sync_agent_da_item_s *fw_item = NULL; int service_account_id = 0; + int parent_id = -1; char *service_folder_id = NULL; char *service_item_id = NULL; void *service_data = NULL; @@ -934,20 +968,29 @@ EXPORT_API sync_agent_da_return_e sync_agent_get_service_item(char *item_id, syn (*service_item)->folder_id = g_strdup(fw_item->folder_id); (*service_item)->access_name = g_strdup(fw_item->access_name); - DACI_FINISH: + // in case of exdate item (only Calendar), The framework id of it's parent should be alloc to service_item->parent_id + if (fw_item->parent_service_id != NULL) { + parent_id = atoi(fw_item->parent_service_id); + _DEBUG_INFO("parent_id = %d", parent_id); + if (parent_id >= 0) + (*service_item)->parent_id = da_get_item_id_internal((*service_item)->account_id, fw_item->parent_service_id, (*service_item)->content_type); + } + +DACI_FINISH: - /* memory free */ if (fw_item != NULL) sync_agent_free_item(fw_item); + fw_item = NULL; if (service_folder_id != NULL) free(service_folder_id); + service_folder_id = NULL; if (service_item_id != NULL) free(service_item_id); + service_item_id = NULL; _EXTERN_FUNC_EXIT; - return ret; } @@ -1068,6 +1111,54 @@ EXPORT_API int sync_agent_get_used_service_item_count(int content_type) return used_count; } +EXPORT_API int sync_agent_get_deleted_exdate_item_count(int content_type) +{ + _EXTERN_FUNC_ENTER; + + plugin_get_deleted_exdate_item_count func_get_used_count = plugin_get_function_get_deleted_exdate_item_count(content_type); + retvm_if(func_get_used_count == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_get_deleted_exdate_item_count !!"); + + /* 1. call plugIn dataconnector */ + int used_count = func_get_used_count(); + if (used_count <= -1) { + _DEBUG_INFO("[sync_agent_get_deleted_exdate_item_count] failed pFunc_Get_Used_Count()\n"); + } else { + _DEBUG_INFO("[sync_agent_get_deleted_exdate_item_count] success pFunc_Get_Used_Count() : %d\n", used_count); + } + + _EXTERN_FUNC_EXIT; + return used_count; +} + +EXPORT_API void sync_agent_construct_exdate_parent_item(int content_type, char *parent_service_id) +{ + _EXTERN_FUNC_ENTER; + retm_if(parent_service_id == NULL, "parent_service_id is NULL !!"); + + plugin_construct_exdate_parent_item func_construct_exdate_parent_item = plugin_function_construct_exdate_parent_item(content_type); + goto_if(func_construct_exdate_parent_item == NULL, "cannot get plugin_construct_exdate_parent_item !!"); + func_construct_exdate_parent_item(parent_service_id); + +return_part: + _EXTERN_FUNC_EXIT; + return; +} + + +EXPORT_API sync_agent_da_return_e sync_agent_is_exist_exdate_item(int content_type, const char *fw_parent_id, const char *child_vcalendar) +{ + _EXTERN_FUNC_ENTER; + + plugin_is_exist_exdate_item func_is_exist_exdate_item = plugin_function_is_exist_exdate_item(content_type); + retvm_if(func_is_exist_exdate_item == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_is_exist_exdate_item !!"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + ret = func_is_exist_exdate_item(fw_parent_id, child_vcalendar); + + _EXTERN_FUNC_EXIT; + return ret; +} + EXPORT_API int sync_agent_get_used_service_item_count_for_folder(int content_type, int account_id, char *folder_id) { _EXTERN_FUNC_ENTER; @@ -1216,3 +1307,192 @@ EXPORT_API char *sync_agent_get_service_folder_id(char *folder_id) return da_get_folder_service_id(daci_handler, folder_id); } + +EXPORT_API int sync_agent_get_sim_contact_info_max_name_length(int content_type) +{ + _EXTERN_FUNC_ENTER; + + plugin_get_info_sim_contact_max_name_length_cb func_get_info_sim_contact_max_name_length = plugin_get_function_get_info_sim_contact_max_name_length(content_type); + retvm_if(func_get_info_sim_contact_max_name_length == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_get_info_sim_contact_max_name_length_cb !!"); + + int maxNameLength = func_get_info_sim_contact_max_name_length(); + + _EXTERN_FUNC_EXIT; + return maxNameLength; +} + +EXPORT_API int sync_agent_get_sim_contact_info_max_number_length(int content_type) +{ + _EXTERN_FUNC_ENTER; + + plugin_get_info_sim_contact_max_number_length_cb func_get_info_sim_contact_max_number_length = plugin_get_function_get_info_sim_contact_max_number_length(content_type); + retvm_if(func_get_info_sim_contact_max_number_length == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_get_info_sim_contact_max_number_length_cb !!"); + + int maxNumberLength = func_get_info_sim_contact_max_number_length(); + + _EXTERN_FUNC_EXIT; + return maxNumberLength; +} + +EXPORT_API int sync_agent_get_sim_contact_info_max_email_length(int content_type) +{ + _EXTERN_FUNC_ENTER; + + plugin_get_info_sim_contact_max_email_length_cb func_get_info_sim_contact_max_email_length = plugin_get_function_get_info_sim_contact_max_email_length(content_type); + retvm_if(func_get_info_sim_contact_max_email_length == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_get_info_sim_contact_max_email_length_cb !!"); + + int maxEmailLength = func_get_info_sim_contact_max_email_length(); + + _EXTERN_FUNC_EXIT; + return maxEmailLength; +} + +EXPORT_API int sync_agent_get_sim_contact_empty_count(int content_type) +{ + _EXTERN_FUNC_ENTER; + + plugin_get_info_sim_contact_empty_count_cb func_get_info_sim_contact_empty_count = plugin_get_function_get_info_sim_contact_empty_count(content_type); + retvm_if(func_get_info_sim_contact_empty_count == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_get_info_sim_contact_empty_count_cb !!"); + + int emptyCount = func_get_info_sim_contact_empty_count(); + + _EXTERN_FUNC_EXIT; + return emptyCount; +} + +EXPORT_API int sync_agent_get_sim_contact_empty_number_count(int content_type) +{ + _EXTERN_FUNC_ENTER; + + plugin_get_info_sim_contact_empty_number_count_cb func_get_info_sim_contact_empty_number_count = plugin_get_function_get_info_sim_contact_empty_number_count(content_type); + retvm_if(func_get_info_sim_contact_empty_number_count == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_get_info_sim_contact_empty_number_count_cb !!"); + + int emptyNumberCount = func_get_info_sim_contact_empty_number_count(); + + _EXTERN_FUNC_EXIT; + return emptyNumberCount; +} + +EXPORT_API int sync_agent_get_sim_contact_empty_email_count(int content_type) +{ + _EXTERN_FUNC_ENTER; + + plugin_get_info_sim_contact_empty_email_count_cb func_get_info_sim_contact_empty_email_count = plugin_get_function_get_info_sim_contact_empty_email_count(content_type); + retvm_if(func_get_info_sim_contact_empty_email_count == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_get_info_sim_contact_empty_email_count_cb !!"); + + int emptyEmailCount = func_get_info_sim_contact_empty_email_count(); + + _EXTERN_FUNC_EXIT; + return emptyEmailCount; +} + +EXPORT_API int sync_agent_get_sim_contact_addressbook_id(int content_type) +{ + _EXTERN_FUNC_ENTER; + + plugin_get_info_sim_contact_addressbook_id_cb func_get_info_sim_contact_addressbook_id = plugin_get_function_get_info_sim_contact_addressbook_id(content_type); + retvm_if(func_get_info_sim_contact_addressbook_id == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get plugin_get_info_sim_contact_addressbook_id !!"); + + int simContactAddressbookId = func_get_info_sim_contact_addressbook_id(); + + _EXTERN_FUNC_EXIT; + return simContactAddressbookId; +} + +EXPORT_API sync_agent_da_return_e sync_agent_get_sim_contact_item_id(int content_type, int sim_addressbook_id, GList **item_id) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e da_ret = SYNC_AGENT_DA_SUCCESS; + + plugin_get_info_sim_contact_item_id_cb func_get_info_sim_contact_item_id = plugin_get_function_get_info_sim_contact_item_id(content_type); + retvm_if(func_get_info_sim_contact_item_id == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get func_get_info_sim_contact_item_id !!"); + + GList *item_id_list = NULL; + da_ret = func_get_info_sim_contact_item_id(sim_addressbook_id, &item_id_list); + if (da_ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("func_get_info_sim_contact_item_id() fail, da_ret[%d]", da_ret); + } + *item_id = item_id_list; + + _EXTERN_FUNC_EXIT; + return da_ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_get_sim_contact_item(int content_type, int item_id, char **data) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e da_ret = SYNC_AGENT_DA_SUCCESS; + + plugin_get_info_sim_contact_item_cb func_get_info_sim_contact_item = plugin_get_function_get_info_sim_contact_item(content_type); + retvm_if(func_get_info_sim_contact_item == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get func_get_info_sim_contact_item !!"); + + char *item_data = NULL; + da_ret = func_get_info_sim_contact_item(item_id, &item_data); + if (da_ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("func_get_info_sim_contact_item() fail, da_ret[%d]", da_ret); + } + *data = item_data; + + _EXTERN_FUNC_EXIT; + return da_ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_add_sim_contact_item(int content_type, int sim_addressbook_id, int **item_id, char *data) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e da_ret = SYNC_AGENT_DA_SUCCESS; + + plugin_add_sim_contact_item_cb func_add_sim_contact_item = plugin_get_function_add_sim_contact_item(content_type); + retvm_if(func_add_sim_contact_item == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get func_add_sim_contact_item !!"); + + int *item_id_tmp = NULL; + da_ret = func_add_sim_contact_item(sim_addressbook_id, &item_id_tmp, data); + if (da_ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("func_add_sim_contact_item() fail, da_ret[%d]", da_ret); + } + + *item_id = item_id_tmp; + + _EXTERN_FUNC_EXIT; + return da_ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_write_sim_contact_item(int content_type, int item_id, char *data) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e da_ret = SYNC_AGENT_DA_SUCCESS; + + plugin_write_sim_contact_item_cb func_write_sim_contact_item = plugin_get_function_write_sim_contact_item(content_type); + retvm_if(func_write_sim_contact_item == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get func_write_sim_contact_item !!"); + + da_ret = func_write_sim_contact_item(item_id, data); + if (da_ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("func_write_sim_contact_item() fail, da_ret[%d]", da_ret); + } + + _EXTERN_FUNC_EXIT; + return da_ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_delete_sim_contact_item(int content_type, int item_id) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e da_ret = SYNC_AGENT_DA_SUCCESS; + + plugin_delete_sim_contact_item_cb func_delete_sim_contact_item = plugin_get_function_delete_sim_contact_item(content_type); + retvm_if(func_delete_sim_contact_item == NULL, SYNC_AGENT_DA_NOT_FOUND_PLUG_IN, "cannot get func_delete_sim_contact_item !!"); + + da_ret = func_delete_sim_contact_item(item_id); + if (da_ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("func_delete_sim_contact_item() fail, da_ret[%d]", da_ret); + } + + _EXTERN_FUNC_EXIT; + return da_ret; +} + diff --git a/src/framework/device-manager/mo_accessor.c b/src/framework/device-manager/mo_accessor.c index 40ba573..49766de 100755 --- a/src/framework/device-manager/mo_accessor.c +++ b/src/framework/device-manager/mo_accessor.c @@ -880,6 +880,9 @@ EXPORT_API sync_agent_dm_mo_error_e sync_agent_get_descendant_mo_tree(sync_agent sync_agent_dm_mo_error_e err_code = dm_get_mo(mo_path, root_node, option); _DEBUG_INFO("mo_path : %s", mo_path); + if(err_code == SYNC_AGENT_DM_MO_FAIL) { + return err_code; + } /* * Recursive Call */ @@ -903,6 +906,11 @@ sync_agent_dm_mo_error_e dm_get_mo(const char *mo_path, sync_agent_dm_mo_node_s sync_agent_dm_mo_error_e err_code = dm_mo_get_node_wraper(mo_path, mo_node); if (err_code != SYNC_AGENT_DM_MO_SUCCESS) { _DEBUG_ERROR("Failed to dm_mo_get_node_wraper : [%d]", err_code); + if( err_code == SYNC_AGENT_DM_MO_FAIL) { + if( *mo_node != NULL ) { + sync_agent_free_mo_item(*mo_node); + } + } return err_code; } @@ -1236,6 +1244,9 @@ sync_agent_dm_mo_error_e dm_get_acl_value(const char *mo_full_path, sync_agent_d err_code = dm_mo_get_node_from_id_wraper(iter->parent_id, &mo_parent_node); if (err_code != SYNC_AGENT_DM_MO_SUCCESS) { _DEBUG_ERROR("Failed to dm_mo_get_parent mo: [%d]", err_code); + if(mo_parent_node != NULL) { + free(mo_parent_node); + } return SYNC_AGENT_DM_MO_FAIL; } int parent_id = -1; @@ -1314,7 +1325,6 @@ EXPORT_API sync_agent_dm_mo_error_e sync_agent_check_acl_value(const char *mo_fu char *mo_acl_value = NULL; int isSearch_value = 0; int isExist_all = 0; - char *mo_server_id = NULL; int server_id_length = 0; char *ptr_sev_id = NULL; @@ -1377,6 +1387,7 @@ EXPORT_API sync_agent_dm_mo_error_e sync_agent_check_acl_value(const char *mo_fu /* search acl command and server_id */ char *ptr_cmd = strstr(mo_acl_value, command_str); while (ptr_cmd != NULL) { + char *mo_server_id = NULL; _DEBUG_INFO("########## Operation Start ###########"); _DEBUG_INFO("ptr_cmd = %s\n", ptr_cmd); @@ -1408,6 +1419,12 @@ EXPORT_API sync_agent_dm_mo_error_e sync_agent_check_acl_value(const char *mo_fu if (strcmp(mo_server_id, server_id) == 0) { _DEBUG_INFO("====> Search ACL Server_id"); isSearch_value = 2; + + if (mo_server_id != NULL) { + free(mo_server_id); + mo_server_id = NULL; + } + break; } else if (strcmp(mo_server_id, "*") == 0) { _DEBUG_INFO("Exist All Format"); @@ -1415,10 +1432,11 @@ EXPORT_API sync_agent_dm_mo_error_e sync_agent_check_acl_value(const char *mo_fu } /* prepare next value check */ - if (ptr_sev_id != NULL) + if (ptr_sev_id != NULL) { ptr_cmd = strstr(ptr_sev_id, command_str); - else + } else { ptr_cmd = NULL; + } if (mo_server_id != NULL) { free(mo_server_id); @@ -1428,10 +1446,6 @@ EXPORT_API sync_agent_dm_mo_error_e sync_agent_check_acl_value(const char *mo_fu } } - if (mo_server_id != NULL) { - free(mo_server_id); - mo_server_id = NULL; - } if (mo_node != NULL) dm_free_mo(mo_node, 1); @@ -1469,11 +1483,6 @@ EXPORT_API sync_agent_dm_mo_error_e sync_agent_check_acl_value(const char *mo_fu dm_free_mo(mo_node, 1); } - if (mo_server_id != NULL) { - free(mo_server_id); - mo_server_id = NULL; - } - _EXTERN_FUNC_EXIT; return err_code; } diff --git a/src/framework/engine-controller/interface.c b/src/framework/engine-controller/interface.c index e4a24ca..4a2f22e 100755 --- a/src/framework/engine-controller/interface.c +++ b/src/framework/engine-controller/interface.c @@ -557,7 +557,14 @@ void ec_run_engine_controller(ec_engine_controller_t * engine_controller) retm_if(engine_controller == NULL, "ec_engine_controller_t is NULL !!"); - pthread_create(&(engine_controller->thread_id), NULL, (ec_thread_start_routine_cb) _engine_controller_logic, (void *)engine_controller); + int status_thread_create = 0; + status_thread_create = pthread_create(&(engine_controller->thread_id), NULL, (ec_thread_start_routine_cb) _engine_controller_logic, (void *)engine_controller); + if(status_thread_create != 0) { + _DEBUG_WARNING("pthread_create [%d]", status_thread_create ); + _EXTERN_FUNC_EXIT; + return; + } + pthread_detach(engine_controller->thread_id); _EXTERN_FUNC_EXIT; @@ -653,7 +660,14 @@ void ec_run_engine_controller_receiver(ec_engine_controller_receiver_t * engine_ retm_if(engine_controller_receiver == NULL, "ec_engine_controller_receiver_t is NULL !!"); /* TODO */ - pthread_create(&(engine_controller_receiver->thread_id), NULL, (ec_thread_start_routine_cb) _engine_controller_receiver_logic, (void *)engine_controller_receiver); + int status_thread_create = 0; + status_thread_create = pthread_create(&(engine_controller_receiver->thread_id), NULL, (ec_thread_start_routine_cb) _engine_controller_receiver_logic, (void *)engine_controller_receiver); + if(status_thread_create != 0) { + _DEBUG_WARNING("pthread_create [%d]", status_thread_create ); + _EXTERN_FUNC_EXIT; + return; + } + pthread_detach(engine_controller_receiver->thread_id); _EXTERN_FUNC_EXIT; diff --git a/src/framework/engine-controller/queuing_rule_spec.c b/src/framework/engine-controller/queuing_rule_spec.c index 39736e9..0dda7f4 100755 --- a/src/framework/engine-controller/queuing_rule_spec.c +++ b/src/framework/engine-controller/queuing_rule_spec.c @@ -673,6 +673,7 @@ EXPORT_API sync_agent_ec_error_e sync_agent_add_progress_blocking_element(sync_a /* sync_agent_ec_boolean is_dynamic, sync_agent_ec_int dynamic_case, sync_agent_ec_int child_index */ sync_agent_ec_error_e ec_error = SYNC_AGENT_EC_OK; sync_agent_ec_boolean new_entity = false; + ec_progress_blocking_entity_t *entity = NULL; va_list ap; va_start(ap, child_depth); @@ -689,7 +690,7 @@ EXPORT_API sync_agent_ec_error_e sync_agent_add_progress_blocking_element(sync_a va_start(ap, child_depth); /* find progress blocking entity */ - ec_progress_blocking_entity_t *entity = _queuing_rule_spec_get_progress_blocking_entity(rule, root_task_spec_id); + entity = _queuing_rule_spec_get_progress_blocking_entity(rule, root_task_spec_id); if (entity == NULL) { entity = ec_progress_blocking_entity_new(root_task_spec_id, rule); if (entity == NULL) { @@ -716,6 +717,12 @@ EXPORT_API sync_agent_ec_error_e sync_agent_add_progress_blocking_element(sync_a } return_part: + if (new_entity) { + if(entity != NULL) { + ec_progress_blocking_entity_free(entity); + } + } + _EXTERN_FUNC_EXIT; return ec_error; diff --git a/src/framework/event/config.c b/src/framework/event/config.c index 81154b4..5ede5cd 100755 --- a/src/framework/event/config.c +++ b/src/framework/event/config.c @@ -90,6 +90,8 @@ sync_agent_event_error_e event_set_event_spec_from_config_file(const char *event if (fp != NULL) fclose(fp); return SYNC_AGENT_EVENT_FAIL; + } else { + memset(event_spec, 0, sizeof(event_spec_s)); } char description[1000]; @@ -195,6 +197,8 @@ sync_agent_event_error_e event_set_noti_spec_from_config_file(const char *noti_k _DEBUG_ERROR("CALLOC failed !!!"); free(noti_spec_bag); return SYNC_AGENT_EVENT_FAIL; + } else { + memset(noti_spec, 0, sizeof(noti_spec_s)); } char description[1000] = { 0, }; diff --git a/src/framework/event/data_accessor.c b/src/framework/event/data_accessor.c index e082868..584bb13 100755 --- a/src/framework/event/data_accessor.c +++ b/src/framework/event/data_accessor.c @@ -146,11 +146,16 @@ EXPORT_API void sync_agent_get_event_data_param_int(sync_agent_event_data_s * it if (type == SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER) { /* get data */ memcpy(data, iter->data, sizeof(int)); + _DEBUG_INFO("sync_agent_get_event_data_param_int - data: [%d]",*data); iter->data += sizeof(int); } else if (type == SYNC_AGENT_EVENT_PARAM_TYPE_STRING) { _DEBUG_ERROR("Recommended : using sync_agent_get_event_data_param_str api"); } + _DEBUG_INFO("sync_agent_get_event_data_param_int - iter->event_num: [%d]", iter->event_num); + _DEBUG_INFO("sync_agent_get_event_data_param_int - *(iter->size): [ox%x]", *(iter->size)); + _DEBUG_INFO("sync_agent_get_event_data_param_int - *(iter->data): [0x%x]", *(iter->data)); + /* setting for next */ *(iter->size) -= 1; diff --git a/src/framework/event/handler.c b/src/framework/event/handler.c index 947b676..dcb3a5d 100755 --- a/src/framework/event/handler.c +++ b/src/framework/event/handler.c @@ -61,7 +61,13 @@ EXPORT_API sync_agent_event_error_e sync_agent_run_event_handler(unsigned long i _DEBUG_INFO("sync_agent_run_event_handler() start\n"); - pthread_create(&event_handler_thread_id, 0, _event_listener, 0); + int status_thread_create = 0; + status_thread_create = pthread_create(&event_handler_thread_id, 0, _event_listener, 0); + if(status_thread_create != 0) { + _DEBUG_WARNING("pthread_create [%d]", status_thread_create ); + _EXTERN_FUNC_EXIT; + return SYNC_AGENT_EVENT_FAIL; + } *thread_id = event_handler_thread_id; @@ -220,7 +226,7 @@ static void *_event_listener(void *arg) signal(SIGPIPE, SIG_IGN); - int client_sockfd; + int client_sockfd = -1; int state; socklen_t client_len; struct sockaddr_un clientaddr, serveraddr; @@ -243,6 +249,7 @@ static void *_event_listener(void *arg) } client_len = sizeof(clientaddr); + _DEBUG_INFO("_event_listener - client_len: [%d]",client_len); if ((_event_server_socket_id = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { return NULL; } @@ -281,44 +288,64 @@ static void *_event_listener(void *arg) while (1) { _DEBUG_TRACE("In EventHandler loop=\n"); - char inbuf[EVENT_MAX_STREAM_SIZE + 1]; - char outbuf[EVENT_MAX_STREAM_SIZE + 1]; + char * inbuf = NULL; + char * outbuf = NULL; + inbuf = (char*)malloc(sizeof(char)*(EVENT_MAX_STREAM_SIZE + 1)); + if(inbuf == NULL) { + _DEBUG_ERROR("inbuf malloc failed!!"); + goto error; + } + + outbuf= (char*)malloc(sizeof(char)*(EVENT_MAX_STREAM_SIZE + 1)); + if(outbuf == NULL) { + _DEBUG_ERROR("outbuf malloc failed!!"); + goto error; + } + memset(inbuf, 0x00, EVENT_MAX_STREAM_SIZE + 1); memset(outbuf, 0x00, EVENT_MAX_STREAM_SIZE + 1); sync_agent_event_data_s request; sync_agent_event_data_s response; + request.data = inbuf; response.data = outbuf; event_init_event_data_iter(&request); event_init_event_data_iter(&response); client_sockfd = accept(_event_server_socket_id, (struct sockaddr *)&clientaddr, &client_len); + if (client_sockfd < 0) { _DEBUG_ERROR("socket accept() failed !!"); - return NULL; + goto error; } _DEBUG_TRACE("accept() was called\n"); + _DEBUG_INFO("_event_listener - client_sockfd: [%d]",client_sockfd); result = read(client_sockfd, (void *)inbuf, EVENT_MAX_STREAM_SIZE); if (result <= 0 || result > EVENT_MAX_STREAM_SIZE) { _DEBUG_ERROR("read failed !!"); - close(client_sockfd); - return NULL; + goto error; } - if (strlen(inbuf) <= 0 || strlen(inbuf) > EVENT_MAX_STREAM_SIZE) { - _DEBUG_ERROR("socket data read : size OUT OF BOUND !!"); - close(client_sockfd); - return NULL; +/* + _DEBUG_INFO("read result [%d]", result); + + int print_i = 0; + for( print_i = 0; print_i < result ; print_i++) + { + _DEBUG_INFO(" 0x%x ", inbuf[print_i]); } + _DEBUG_INFO("request.event_num [%d]", request.event_num); + _DEBUG_INFO("request.size [ox%x]", *(request.size)); + _DEBUG_INFO("request.data [0x%x]", *(request.data)); +*/ int event_num; sync_agent_get_event_data_param_int(&request, &event_num); _DEBUG_TRACE("Received Event Number : %d\n", event_num); __dispatch_event(event_num, &request, &response); - /* - * need synchronous response case - */ + + // need synchronous response case event_type_e event_type = event_get_event_type(event_num); if (event_type == EVENT_TYPE_NEED_RESPONSE) { if (event_get_event_data_element_size(&response) > 0) { @@ -330,7 +357,20 @@ static void *_event_listener(void *arg) } } - close(client_sockfd); + error: + + if (inbuf) { + free(inbuf); + inbuf = NULL; + } + + if (outbuf) { + free(outbuf); + outbuf = NULL; + } + + if (client_sockfd >= 0 ) + close(client_sockfd); } _INNER_FUNC_EXIT; diff --git a/src/framework/event/oma_dm_api_common_internal.h b/src/framework/event/oma_dm_api_common_internal.h index ea88d9d..406d428 100755 --- a/src/framework/event/oma_dm_api_common_internal.h +++ b/src/framework/event/oma_dm_api_common_internal.h @@ -71,8 +71,8 @@ extern "C" { NOTI_DOWNLOAD_INFO, /* Fumo UI Util Noti */ - NOTI_ENGINE_START, - NOTI_ENGINE_FAIL = 5, + NOTI_ENGINE_START = 4, + NOTI_ENGINE_FAIL, NOTI_WIFI_ONLY_DOWNLOAD_FAIL, NOTI_MEMORY_FULL, NOTI_OVER_BIG_SIZE, @@ -85,6 +85,8 @@ extern "C" { NOTI_ALERT_SINGLE_CHOICE, NOTI_ALERT_MULTIPLE_CHOICE, + NOTI_POLL_INTERACTION = 15, + NOTI_UPDATE_RESULT, NOTI_NUM } sync_agent_dm_noti_e; diff --git a/src/framework/event/oma_dm_noti_api.c b/src/framework/event/oma_dm_noti_api.c index eb84d6e..928b9d2 100755 --- a/src/framework/event/oma_dm_noti_api.c +++ b/src/framework/event/oma_dm_noti_api.c @@ -58,7 +58,8 @@ typedef enum { PUSH_NOT_SPECIFIED = 0, PUSH_BACKGROUND, PUSH_INFORMATIVE, - PUSH_INTERACTION + PUSH_INTERACTION, + POLL_INTERACTION } sync_agent_dm_push_type; EXPORT_API sync_agent_dm_error_e sync_agent_dm_push_init() diff --git a/src/framework/event/oma_ds_api.c b/src/framework/event/oma_ds_api.c index 951f3b5..92323e9 100755 --- a/src/framework/event/oma_ds_api.c +++ b/src/framework/event/oma_ds_api.c @@ -541,7 +541,7 @@ EXPORT_API sync_agent_ds_error_e sync_agent_ds_init() sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS; sync_agent_init_error_e init_error = SYNC_AGENT_INIT_SUCCESS; int ret = -1; - int pid = -1; + int pid = -1; _DEBUG_INFO("before sysman_get_pid"); pid = sysman_get_pid("/usr/bin/oma-ds-agent"); @@ -1693,7 +1693,6 @@ EXPORT_API sync_agent_ds_error_e sync_agent_ds_deinit() sync_agent_ds_error_e result = SYNC_AGENT_DS_SUCCESS; sync_agent_deinit_error_e deinit = SYNC_AGENT_DEINIT_SUCCESS; - int ret = -1; ret = _kill_omads_agent(); diff --git a/src/framework/event/ui_api.c b/src/framework/event/ui_api.c index 2db133f..cebdae1 100755 --- a/src/framework/event/ui_api.c +++ b/src/framework/event/ui_api.c @@ -51,6 +51,7 @@ static int inotify_fd; static int inotify_wd; static int gsource_id; +static int creat_notify_fd = -1; static gboolean _agent_noti_listener(GIOChannel * p_src, GIOCondition cond, gpointer p_data); @@ -237,8 +238,8 @@ EXPORT_API sync_agent_event_error_e sync_agent_run_noti_listener(const char *not _DEBUG_TRACE("%s file is not exist !!"); } - int fd = creat(communication_path, S_IRWXU | S_IRWXG | S_IRWXO); - if (fd < 0) { + creat_notify_fd = creat(communication_path, S_IRWXU | S_IRWXG | S_IRWXO); + if (creat_notify_fd < 0) { _DEBUG_ERROR("creat() failed !!"); return SYNC_AGENT_EVENT_FAIL; } else { @@ -249,33 +250,38 @@ EXPORT_API sync_agent_event_error_e sync_agent_run_noti_listener(const char *not inotify_fd = inotify_init(); if (inotify_fd == -1) { _DEBUG_ERROR("inotify_init() failed !!"); - return SYNC_AGENT_EVENT_FAIL; + goto error; + //return SYNC_AGENT_EVENT_FAIL; } /* change file's attribute */ result = fcntl(inotify_fd, F_SETFD, FD_CLOEXEC); if (result == -1) { _DEBUG_ERROR("fcntl() failed !!"); - return SYNC_AGENT_EVENT_FAIL; + goto error; + //return SYNC_AGENT_EVENT_FAIL; } result = fcntl(inotify_fd, F_SETFL, O_NONBLOCK); if (result == -1) { _DEBUG_ERROR("fcntl() failed !!"); - return SYNC_AGENT_EVENT_FAIL; + goto error; + //return SYNC_AGENT_EVENT_FAIL; } /* add a watch to an initialized inotify instance */ inotify_wd = inotify_add_watch(inotify_fd, communication_path, IN_CLOSE_WRITE); if (inotify_wd == -1) { _DEBUG_ERROR("inotify_add_watch() failed !!"); - return SYNC_AGENT_EVENT_FAIL; + goto error; + //return SYNC_AGENT_EVENT_FAIL; } /* create a new GIOChannel given a file descriptor */ gio_channel = g_io_channel_unix_new(inotify_fd); if (gio_channel == NULL) { _DEBUG_ERROR("g_io_channel_unix_new() failed !!"); - return SYNC_AGENT_EVENT_FAIL; + goto error; + //return SYNC_AGENT_EVENT_FAIL; } /* turn on nonblocking mode */ @@ -296,11 +302,41 @@ EXPORT_API sync_agent_event_error_e sync_agent_run_noti_listener(const char *not _EXTERN_FUNC_EXIT; return SYNC_AGENT_EVENT_SUCCESS; + +error: // prevent 32978 + if (creat_notify_fd < 0) { + _DEBUG_INFO("creat_notify_fd < 0 "); + } else { + _DEBUG_INFO("creat_notify_fd >= 0 : close(creat_notify_fd)"); + close(creat_notify_fd); + creat_notify_fd = -1; + } + + if (sync_agent_is_existing_fs(communication_path)) { + _DEBUG_TRACE("%s file is exist !!"); + if (unlink(communication_path) == -1) { + _DEBUG_ERROR("unlink failed ( %s ), ERROR NUM [%d] !!", communication_path, errno); + _EXTERN_FUNC_EXIT; + return SYNC_AGENT_EVENT_FAIL; + } else { + _DEBUG_TRACE("unlink success !!"); + } + } + + _EXTERN_FUNC_EXIT; + return SYNC_AGENT_EVENT_FAIL; } EXPORT_API sync_agent_event_error_e sync_agent_stop_noti_listener() { _EXTERN_FUNC_ENTER; + if (creat_notify_fd < 0) { + _DEBUG_INFO("creat_notify_fd < 0 "); + } else { + _DEBUG_INFO("creat_notify_fd >= 0 : close(creat_notify_fd)"); + close(creat_notify_fd); + creat_notify_fd = -1; + } inotify_rm_watch(inotify_fd, inotify_wd); close(inotify_fd); diff --git a/src/framework/event/util.c b/src/framework/event/util.c index 687c255..ce96b47 100755 --- a/src/framework/event/util.c +++ b/src/framework/event/util.c @@ -32,8 +32,9 @@ void event_init_event_data_iter(sync_agent_event_data_s * event) retm_if(event == NULL, "sync_agent_event_data_s is NULL !!"); event->size = event->data; + _DEBUG_INFO("event_init_event_data_iter - event->size :[%x]",event->size); event->data = event->data + 1; - + _DEBUG_INFO("event_init_event_data_iter - event->data :[%x]",event->data); _EXTERN_FUNC_EXIT; } diff --git a/src/framework/fsapi/operation.c b/src/framework/fsapi/operation.c index 046b98b..0bdb036 100755 --- a/src/framework/fsapi/operation.c +++ b/src/framework/fsapi/operation.c @@ -1058,6 +1058,7 @@ int fs_file_md5_hashkey(const char *file_path, unsigned char **hash_key) ret = sync_agent_read_file(file_path, &required_contents, FS_BUFFER_SIZE, &read_file_size, &isFinal); if (ret != 1) { _DEBUG_ERROR("sync_agent_read_file() Fail\n"); + ret = 0; goto return_part; } @@ -1083,8 +1084,17 @@ int fs_file_md5_hashkey(const char *file_path, unsigned char **hash_key) sync_agent_free_file(&required_contents); _EXTERN_FUNC_EXIT; + return ret; return_part: + if (real_md5_word != NULL) { + free(real_md5_word); + real_md5_word = NULL; + } + _DEBUG_INFO("Free Part"); + sync_agent_free_file(&required_contents); + + _EXTERN_FUNC_EXIT; return ret; } diff --git a/src/framework/initialization/interface.c b/src/framework/initialization/interface.c index c209077..5693d5d 100755 --- a/src/framework/initialization/interface.c +++ b/src/framework/initialization/interface.c @@ -100,6 +100,7 @@ EXPORT_API sync_agent_init_error_e sync_agent_init(const char *init_config_path) if (plugIn_dc_repository[i].handle_change_noti) { plugin_set_callback_add_item_cb func_point_set_callback_add_item = plugin_get_function_set_callback_add_item(plugIn_id); plugin_set_callback_delete_item_cb func_point_set_callback_delete_item = plugin_get_function_set_callback_delete_item(plugIn_id); + plugin_set_callback_delete_child_item_cb func_point_set_callback_delete_child_item = plugin_get_function_set_callback_delete_child_item(plugIn_id); plugin_set_callback_update_item_cb func_point_set_callback_update_item = plugin_get_function_data_connector_set_callback_update_item(plugIn_id); plugin_set_callback_get_account_id_list_cb func_point_set_callback_get_account_id_list = plugin_get_function_set_callback_get_account_id_list(plugIn_id); plugin_start_listening_change_noti_cb func_point_start_listening_change_noti = plugin_get_function_start_listening_change_noti(plugIn_id); @@ -113,6 +114,7 @@ EXPORT_API sync_agent_init_error_e sync_agent_init(const char *init_config_path) } func_point_set_callback_add_item(da_handle_add_item); func_point_set_callback_delete_item(da_handle_del_item); + func_point_set_callback_delete_child_item(da_handle_del_child_item); func_point_set_callback_update_item(da_handle_update_item); func_point_set_callback_get_account_id_list(acc_get_service_account_id_list); diff --git a/src/framework/network-access/interface.c b/src/framework/network-access/interface.c index 298b002..b01e86e 100755 --- a/src/framework/network-access/interface.c +++ b/src/framework/network-access/interface.c @@ -70,6 +70,7 @@ EXPORT_API sync_agent_na_result_e sync_agent_open_connection(int na_plugin_id, i sync_agent_na_result_e res = SYNC_AGENT_NA_SUCCESS; void *session = NULL; + _DEBUG_INFO("na_plugin_id [%d]", na_plugin_id); int err = na_create_session_info(&session); if (err != 1) { @@ -220,6 +221,7 @@ EXPORT_API sync_agent_na_result_e sync_agent_send_msg(GList * header_info, int n void *session = NULL; void *msg = NULL; int try_again_cnt = 0; + _DEBUG_INFO("na_plugin_id [%d]", na_plugin_id); /* check current network status */ if (plugin_use_network(na_plugin_id) == 1) { @@ -667,15 +669,19 @@ sync_agent_na_result_e na_download_data(GList * header_info, int na_plugin_id, u backup_send_head_info_list = g_list_append(backup_send_head_info_list, header_item_info); } else { _DEBUG_ERROR("key is NULL !!"); - header_item_info->key = NULL; - header_item_info->value = NULL; + //header_item_info->key = NULL; + //header_item_info->value = NULL; + free(header_item_info); + header_item_info = NULL; } /*backup_send_head_info_list = g_list_append(backup_send_head_info_list, header_item_info); */ + /* if (header_item_info->key != NULL) { if (strcmp(header_item_info->key, "Range") == 0) _DEBUG_INFO("[Before] key : %s, value : %s", header_item_info->key, header_item_info->value); } + */ } /* send_msg */ diff --git a/src/framework/plugin/data_connector_plugin.c b/src/framework/plugin/data_connector_plugin.c index 5577723..e758778 100755 --- a/src/framework/plugin/data_connector_plugin.c +++ b/src/framework/plugin/data_connector_plugin.c @@ -57,6 +57,9 @@ plugin_data_connector_func_set_s plugin_get_data_connector_func_set(void *plugin func_set.func_get_folder = dlsym(plugin_handle, "sync_agent_plugin_get_folder"); func_set.func_execute = dlsym(plugin_handle, "sync_agent_plugin_execute"); func_set.func_get_used_item_cnt = dlsym(plugin_handle, "sync_agent_plugin_get_used_item_count"); + func_set.func_get_deleted_exdate_item_cnt = dlsym(plugin_handle, "sync_agent_plugin_get_deleted_exdate_item_count"); + func_set.func_is_exist_exdate_item = dlsym(plugin_handle, "sync_agent_plugin_is_exist_exdate_item"); + func_set.func_construct_exdate_parent_item = dlsym(plugin_handle, "sync_agent_plugin_construct_exdate_parent_item"); func_set.func_get_used_cnt_for_folder = dlsym(plugin_handle, "sync_agent_plugin_get_used_item_count_for_folder"); func_set.func_get_folder_id_list = dlsym(plugin_handle, "sync_agent_plugin_get_folder_id_list"); func_set.func_get_account_id_list = dlsym(plugin_handle, "sync_agent_plugin_get_account_id_list"); @@ -69,6 +72,7 @@ plugin_data_connector_func_set_s plugin_get_data_connector_func_set(void *plugin func_set.func_start_listening_change_noti = dlsym(plugin_handle, "sync_agent_plugin_start_listening_change_noti"); func_set.func_set_callback_add_item = dlsym(plugin_handle, "sync_agent_plugin_set_callback_add_item"); func_set.func_set_callback_delete_item = dlsym(plugin_handle, "sync_agent_plugin_set_callback_delete_item"); + func_set.func_set_callback_delete_child_item = dlsym(plugin_handle, "sync_agent_plugin_set_callback_delete_child_item"); func_set.func_set_callback_update_item = dlsym(plugin_handle, "sync_agent_plugin_set_callback_update_item"); func_set.func_set_callback_get_account_id_list = dlsym(plugin_handle, "sync_agent_plugin_set_callback_get_account_id_list"); func_set.func_get_max_item_count = dlsym(plugin_handle, "sync_agent_plugin_get_max_item_count"); @@ -76,9 +80,20 @@ plugin_data_connector_func_set_s plugin_get_data_connector_func_set(void *plugin func_set.func_get_max_field_count = dlsym(plugin_handle, "sync_agent_plugin_get_max_field_count"); func_set.func_get_field_value = dlsym(plugin_handle, "sync_agent_plugin_get_field_value"); func_set.func_get_is_support_feature = dlsym(plugin_handle, "sync_agent_plugin_get_is_support_feature"); + func_set.func_get_info_sim_contact_max_name_length = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_max_name_length"); + func_set.func_get_info_sim_contact_max_number_length = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_max_number_length"); + func_set.func_get_info_sim_contact_max_email_length = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_max_email_length"); + func_set.func_get_info_sim_contact_empty_count = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_empty_count"); + func_set.func_get_info_sim_contact_empty_number_count = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_empty_number_count"); + func_set.func_get_info_sim_contact_empty_email_count = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_empty_email_count"); + func_set.func_get_info_sim_contact_addressbook_id = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_addressbook_id"); + func_set.func_get_info_sim_contact_item_id = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_item_id"); + func_set.func_get_info_sim_contact_item = dlsym(plugin_handle, "sync_agent_plugin_get_info_sim_contact_item"); + func_set.func_add_sim_contact_item = dlsym(plugin_handle, "sync_agent_plugin_add_sim_contact_item"); + func_set.func_write_sim_contact_item = dlsym(plugin_handle, "sync_agent_plugin_write_sim_contact_item"); + func_set.func_delete_sim_contact_item = dlsym(plugin_handle, "sync_agent_plugin_delete_sim_contact_item"); _EXTERN_FUNC_EXIT; - return func_set; } @@ -403,6 +418,47 @@ plugin_get_used_item_count_cb plugin_get_function_get_used_item_count(int plugin } +plugin_get_deleted_exdate_item_count plugin_get_function_get_deleted_exdate_item_count(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + return plugin_repository[index].func_set.func_get_deleted_exdate_item_cnt; +} + +plugin_is_exist_exdate_item plugin_function_is_exist_exdate_item(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_is_exist_exdate_item; +} + +plugin_construct_exdate_parent_item plugin_function_construct_exdate_parent_item(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_construct_exdate_parent_item; +} + plugin_get_used_count_for_folder_cb plugin_get_function_get_used_count_for_folder(int plugin_id) { _EXTERN_FUNC_ENTER; @@ -474,7 +530,7 @@ plugin_restore_service_items_from_file_cb plugin_get_function_restore_service_it return plugin_repository[index].func_set.func_restore_service_items_from_file; } -plugin_get_changed_item_for_folder_add_cb plugin_get_function_get_chaned_item_for_folder_add(int plugin_id) +plugin_get_changed_item_for_folder_add_cb plugin_get_function_get_changed_item_for_folder_add(int plugin_id) { _EXTERN_FUNC_ENTER; @@ -488,7 +544,7 @@ plugin_get_changed_item_for_folder_add_cb plugin_get_function_get_chaned_item_fo return plugin_repository[index].func_set.func_get_chaned_item_for_folder_add; } -plugin_get_changed_item_for_folder_delete_cb plugin_get_function_get_chaned_item_for_folder_delete(int plugin_id) +plugin_get_changed_item_for_folder_delete_cb plugin_get_function_get_changed_item_for_folder_delete(int plugin_id) { _EXTERN_FUNC_ENTER; @@ -502,7 +558,7 @@ plugin_get_changed_item_for_folder_delete_cb plugin_get_function_get_chaned_item return plugin_repository[index].func_set.func_get_chaned_item_for_folder_delete; } -plugin_get_changed_item_for_folder_update_cb plugin_get_function_get_chaned_item_for_folder_update(int plugin_id) +plugin_get_changed_item_for_folder_update_cb plugin_get_function_get_changed_item_for_folder_update(int plugin_id) { _EXTERN_FUNC_ENTER; @@ -600,6 +656,20 @@ plugin_set_callback_get_account_id_list_cb plugin_get_function_set_callback_get_ return plugin_repository[index].func_set.func_set_callback_get_account_id_list; } +plugin_set_callback_delete_child_item_cb plugin_get_function_set_callback_delete_child_item(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_set_callback_delete_child_item; +} + plugin_get_max_item_count_cb plugin_get_function_get_max_item_count(int plugin_id) { _EXTERN_FUNC_ENTER; @@ -670,6 +740,174 @@ plugin_get_is_support_feature_cb plugin_get_function_get_is_support_feature(int return plugin_repository[index].func_set.func_get_is_support_feature; } +plugin_get_info_sim_contact_max_name_length_cb plugin_get_function_get_info_sim_contact_max_name_length(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_max_name_length; +} + +plugin_get_info_sim_contact_max_number_length_cb plugin_get_function_get_info_sim_contact_max_number_length(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_max_number_length; +} + +plugin_get_info_sim_contact_max_email_length_cb plugin_get_function_get_info_sim_contact_max_email_length(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_max_email_length; +} + +plugin_get_info_sim_contact_empty_count_cb plugin_get_function_get_info_sim_contact_empty_count(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_empty_count; +} + +plugin_get_info_sim_contact_empty_number_count_cb plugin_get_function_get_info_sim_contact_empty_number_count(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_empty_number_count; +} + +plugin_get_info_sim_contact_empty_email_count_cb plugin_get_function_get_info_sim_contact_empty_email_count(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_empty_email_count; +} + +plugin_get_info_sim_contact_addressbook_id_cb plugin_get_function_get_info_sim_contact_addressbook_id(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_addressbook_id; +} + +plugin_get_info_sim_contact_item_id_cb plugin_get_function_get_info_sim_contact_item_id(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_item_id; +} + +plugin_get_info_sim_contact_item_cb plugin_get_function_get_info_sim_contact_item(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_get_info_sim_contact_item; +} + +plugin_add_sim_contact_item_cb plugin_get_function_add_sim_contact_item(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_add_sim_contact_item; +} + +plugin_write_sim_contact_item_cb plugin_get_function_write_sim_contact_item(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_write_sim_contact_item; +} + +plugin_delete_sim_contact_item_cb plugin_get_function_delete_sim_contact_item(int plugin_id) +{ + _EXTERN_FUNC_ENTER; + + int index = _find_data_connector_plugin(plugin_id); + if (index == -1) { + return NULL; + } + + _EXTERN_FUNC_EXIT; + + return plugin_repository[index].func_set.func_delete_sim_contact_item; +} + static int _find_data_connector_plugin(int plugin_id) { _INNER_FUNC_ENTER; diff --git a/src/framework/plugin/data_connector_plugin.h b/src/framework/plugin/data_connector_plugin.h index b27bbb3..21bdec4 100755 --- a/src/framework/plugin/data_connector_plugin.h +++ b/src/framework/plugin/data_connector_plugin.h @@ -20,6 +20,8 @@ #include "error.h" #include "struct.h" +#include + #include "plugin/data_connector_resource.h" #include "data-adapter/error.h" @@ -179,6 +181,25 @@ typedef sync_agent_da_return_e(*plugin_execute_cb) (int account_id, const char * typedef int (*plugin_get_used_item_count_cb) (void); /** + * @brief Prototype of plugin function for getting item used count + * @return calendar exdate_item_count on success, negative value on error + */ +typedef int (*plugin_get_deleted_exdate_item_count) (void); + +/** + * @brief Prototype of plugin function for checking whether exdate item exist + * @return calendar exdate_item_count on success, negative value on error + */ +typedef int (*plugin_is_exist_exdate_item) (const char *fw_parent_id, const char *child_vcalendar); + +/** + * @brief Prototype of plugin function for updating the exdate parent item + * @return void + */ +typedef void (*plugin_construct_exdate_parent_item) (char *parent_service_id); + + +/** * @brief Prototype of plugin function for getting item used count for folder * @param[in] account_id service account id * @param[in] folder_id service folder id @@ -284,6 +305,13 @@ typedef void (*plugin_set_callback_update_item_cb) (sync_agent_update_item_cb_pl */ typedef void (*plugin_set_callback_get_account_id_list_cb) (sync_agent_get_account_id_list_cb_plugin callback); +/** + * @brief Prototype of plugin function for setting callback function to handle child item delete from storage + * @param[in] callback callback function - this function is provided from sync-agent-framework + */ +typedef void (*plugin_set_callback_delete_child_item_cb) (sync_agent_del_child_item_cb_plugin callback); + + /********************* Get Meta Info ******************/ /** @@ -328,6 +356,83 @@ typedef int (*plugin_get_field_value_cb) (int field_name, int child_field_name, typedef int (*plugin_get_is_support_feature_cb) (int feature); /** + * @brief Prototype of plugin function for get max name length of sim contact + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef int (*plugin_get_info_sim_contact_max_name_length_cb) (void); + +/** + * @brief Prototype of plugin function for get max number length of sim contact + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef int (*plugin_get_info_sim_contact_max_number_length_cb) (void); + +/** + * @brief Prototype of plugin function for get max email length of sim contact + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef int (*plugin_get_info_sim_contact_max_email_length_cb) (void); + +/** + * @brief Prototype of plugin function for get empty count of sim contact + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef int (*plugin_get_info_sim_contact_empty_count_cb) (void); + +/** + * @brief Prototype of plugin function for get empty number count of sim contact + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef int (*plugin_get_info_sim_contact_empty_number_count_cb) (void); + +/** + * @brief Prototype of plugin function for get empty email count of sim contact + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef int (*plugin_get_info_sim_contact_empty_email_count_cb) (void); + +/** + * @brief Prototype of plugin function for get addressbook id of sim contact + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef int (*plugin_get_info_sim_contact_addressbook_id_cb) (void); + +/** + * @brief Prototype of plugin function for get item id of sim contact + * @param[out] item id of sim contact provided data-connector plugin + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef sync_agent_da_return_e(*plugin_get_info_sim_contact_item_id_cb) (int sim_addressbook_id, GList **item_id); + +/** + * @brief Prototype of plugin function for get data of sim contact + * @param[out] item id of sim contact provided data-connector plugin + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef sync_agent_da_return_e(*plugin_get_info_sim_contact_item_cb) (int item_id, char **data); + +/** + * @brief Prototype of plugin function for add sim contact + * @param[out] item id of sim contact provided data-connector plugin + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef sync_agent_da_return_e(*plugin_add_sim_contact_item_cb) (int sim_addressbook_id, int **item_id, char *data); + +/** + * @brief Prototype of plugin function for write sim contact + * @param[out] item id of sim contact provided data-connector plugin + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef sync_agent_da_return_e(*plugin_write_sim_contact_item_cb) (int item_id, char *data); + +/** + * @brief Prototype of plugin function for delete sim contact + * @param[out] item id of sim contact provided data-connector plugin + * @return SYNC_AGENT_DA_SUCCESS on success, otherwise error + */ +typedef sync_agent_da_return_e(*plugin_delete_sim_contact_item_cb) (int item_id); + +/** * @brief Structure for data-connector plugin function pointer set */ typedef struct { @@ -348,10 +453,12 @@ typedef struct { plugin_get_folder_cb func_get_folder; /**< function pointer of plugin_get_folder_cb */ plugin_execute_cb func_execute; /**< function pointer of plugin_execute_cb */ plugin_get_used_item_count_cb func_get_used_item_cnt; /**< function pointer of plugin_get_used_item_count_cb */ + plugin_get_deleted_exdate_item_count func_get_deleted_exdate_item_cnt; /**< function pointer of plugin_get_deleted_exdate_item_count_cb */ + plugin_is_exist_exdate_item func_is_exist_exdate_item; /**< function pointer of plugin_is_exist_exdate_item */ + plugin_construct_exdate_parent_item func_construct_exdate_parent_item; /**< function pointer of plugin_construct_exdate_parent_item */ plugin_get_used_count_for_folder_cb func_get_used_cnt_for_folder; /**< function pointer of plugin_get_used_count_for_folder_cb */ plugin_backup_service_items_to_file_cb func_backup_service_items_to_file; /**< function pointer of plugin_backup_service_items_to_file_cb */ plugin_restore_service_items_from_file_cb func_restore_service_items_from_file; /**< function pointer of plugin_restore_service_items_from_file_cb */ - plugin_get_folder_id_list_cb func_get_folder_id_list; /**< function pointer of plugin_get_folder_id_list_cb */ plugin_get_account_id_list_cb func_get_account_id_list; /**< function pointer of plugin_get_account_id_list_cb */ plugin_get_changed_item_for_folder_add_cb func_get_chaned_item_for_folder_add; /**< function pointer of plugin_get_changed_item_for_folder_add_cb */ @@ -361,6 +468,7 @@ typedef struct { plugin_start_listening_change_noti_cb func_start_listening_change_noti; /**< function pointer of plugin_start_listening_change_noti_cb */ plugin_set_callback_add_item_cb func_set_callback_add_item; /**< function pointer of plugin_set_callback_add_item_cb */ plugin_set_callback_delete_item_cb func_set_callback_delete_item; /**< function pointer of plugin_set_callback_delete_item_cb */ + plugin_set_callback_delete_child_item_cb func_set_callback_delete_child_item; /**< function pointer of plugin_set_callback_delete_item_cb */ plugin_set_callback_update_item_cb func_set_callback_update_item; /**< function pointer of plugin_set_callback_update_item_cb */ plugin_set_callback_get_account_id_list_cb func_set_callback_get_account_id_list; /**< function pointer of plugin_set_callback_get_account_id_list_cb */ plugin_get_max_item_count_cb func_get_max_item_count; /**< function pointer of plugin_get_max_item_count_cb */ @@ -368,6 +476,18 @@ typedef struct { plugin_get_max_field_count_cb func_get_max_field_count; /**< function pointer of plugin_get_max_field_count_cb */ plugin_get_field_value_cb func_get_field_value; /**< function pointer of plugin_get_field_value_cb */ plugin_get_is_support_feature_cb func_get_is_support_feature; /**< function pointer of plugin_get_is_support_feature_cb */ + plugin_get_info_sim_contact_max_name_length_cb func_get_info_sim_contact_max_name_length; /**< function pointer of plugin_get_info_sim_contact_max_name_length_cb */ + plugin_get_info_sim_contact_max_number_length_cb func_get_info_sim_contact_max_number_length; /**< function pointer of plugin_get_info_sim_contact_max_number_length_cb */ + plugin_get_info_sim_contact_max_email_length_cb func_get_info_sim_contact_max_email_length; /**< function pointer of plugin_get_info_sim_contact_max_email_length_cb */ + plugin_get_info_sim_contact_empty_count_cb func_get_info_sim_contact_empty_count; /**< function pointer of plugin_get_info_sim_contact_empty_count_cb */ + plugin_get_info_sim_contact_empty_number_count_cb func_get_info_sim_contact_empty_number_count; /**< function pointer of plugin_get_info_sim_contact_empty_number_count_cb */ + plugin_get_info_sim_contact_empty_email_count_cb func_get_info_sim_contact_empty_email_count; /**< function pointer of plugin_get_info_sim_contact_empty_email_count_cb */ + plugin_get_info_sim_contact_addressbook_id_cb func_get_info_sim_contact_addressbook_id; /**< function pointer of plugin_get_info_sim_contact_addressbook_id_cb */ + plugin_get_info_sim_contact_item_id_cb func_get_info_sim_contact_item_id; /**< function pointer of plugin_get_info_sim_contact_item_id_cb */ + plugin_get_info_sim_contact_item_cb func_get_info_sim_contact_item; /**< function pointer of plugin_get_info_sim_contact_item_cb */ + plugin_add_sim_contact_item_cb func_add_sim_contact_item; /**< function pointer of plugin_add_sim_contact_item_cb */ + plugin_write_sim_contact_item_cb func_write_sim_contact_item; /**< function pointer of plugin_write_sim_contact_item_cb */ + plugin_delete_sim_contact_item_cb func_delete_sim_contact_item; /**< function pointer of plugin_delete_sim_contact_item_cb */ } plugin_data_connector_func_set_s; /** @@ -542,6 +662,28 @@ plugin_execute_cb plugin_get_function_execute(int plugin_id); plugin_get_used_item_count_cb plugin_get_function_get_used_item_count(int plugin_id); /** + * @brief Get function pointer of plugin_get_deleted_exdate_item_count_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_deleted_exdate_item_count_cb on success, NULL on error + */ +plugin_get_deleted_exdate_item_count plugin_get_function_get_deleted_exdate_item_count(int plugin_id); + +/** + * @brief Get function pointer of plugin_function_is_exist_exdate_item + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_function_is_exist_exdate_item on success, NULL on error + */ +plugin_is_exist_exdate_item plugin_function_is_exist_exdate_item(int plugin_id); + +/** + * @brief Get function pointer of plugin_function_construct_exdate_parent_item + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_function_construct_exdate_parent_item on success, NULL on error + */ +plugin_construct_exdate_parent_item plugin_function_construct_exdate_parent_item(int plugin_id); + + +/** * @brief Get function pointer of plugin_get_used_count_for_folder_cb * @param[in] plugin_id data-connector plugin id * @return function pointer of plugin_get_used_count_for_folder_cb on success, NULL on error @@ -581,21 +723,21 @@ plugin_restore_service_items_from_file_cb plugin_get_function_restore_service_it * @param[in] plugin_id data-connector plugin id * @return function pointer of plugin_get_changed_item_for_folder_add_cb on success, NULL on error */ -plugin_get_changed_item_for_folder_add_cb plugin_get_function_get_chaned_item_for_folder_add(int plugin_id); +plugin_get_changed_item_for_folder_add_cb plugin_get_function_get_changed_item_for_folder_add(int plugin_id); /** * @brief Get function pointer of plugin_get_changed_item_for_folder_delete_cb * @param[in] plugin_id data-connector plugin id * @return function pointer of plugin_get_changed_item_for_folder_delete_cb on success, NULL on error */ -plugin_get_changed_item_for_folder_delete_cb plugin_get_function_get_chaned_item_for_folder_delete(int plugin_id); +plugin_get_changed_item_for_folder_delete_cb plugin_get_function_get_changed_item_for_folder_delete(int plugin_id); /** * @brief Get function pointer of plugin_get_changed_item_for_folder_update_cb * @param[in] plugin_id data-connector plugin id * @return function pointer of plugin_get_changed_item_for_folder_update_cb on success, NULL on error */ -plugin_get_changed_item_for_folder_update_cb plugin_get_function_get_chaned_item_for_folder_update(int plugin_id); +plugin_get_changed_item_for_folder_update_cb plugin_get_function_get_changed_item_for_folder_update(int plugin_id); /** * @brief Get function pointer of plugin_get_last_change_point_cb @@ -626,6 +768,14 @@ plugin_set_callback_add_item_cb plugin_get_function_set_callback_add_item(int pl plugin_set_callback_delete_item_cb plugin_get_function_set_callback_delete_item(int plugin_id); /** + * @brief Get function pointer of plugin_set_callback_delete_child_item_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_set_callback_delete_child_item_cb on success, NULL on error + */ +plugin_set_callback_delete_child_item_cb plugin_get_function_set_callback_delete_child_item(int plugin_id); + + +/** * @brief Get function pointer of plugin_set_callback_update_item_cb * @param[in] plugin_id data-connector plugin id * @return function pointer of plugin_set_callback_update_item_cb on success, NULL on error @@ -675,6 +825,90 @@ plugin_get_field_value_cb plugin_get_function_get_field_value(int plugin_id); plugin_get_is_support_feature_cb plugin_get_function_get_is_support_feature(int plugin_id); /** + * @brief Get function pointer of plugin_get_info_sim_contact_max_name_length_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_max_name_length_cb on success, NULL on error + */ +plugin_get_info_sim_contact_max_name_length_cb plugin_get_function_get_info_sim_contact_max_name_length(int plugin_id); + +/** + * @brief Get function pointer of plugin_get_info_sim_contact_max_number_length_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_max_number_length_cb on success, NULL on error + */ +plugin_get_info_sim_contact_max_number_length_cb plugin_get_function_get_info_sim_contact_max_number_length(int plugin_id); + +/** + * @brief Get function pointer of plugin_get_info_sim_contact_max_email_length_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_max_email_length_cb on success, NULL on error + */ +plugin_get_info_sim_contact_max_email_length_cb plugin_get_function_get_info_sim_contact_max_email_length(int plugin_id); + +/** + * @brief Get function pointer of plugin_get_info_sim_contact_empty_count_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_empty_count_cb on success, NULL on error + */ +plugin_get_info_sim_contact_empty_count_cb plugin_get_function_get_info_sim_contact_empty_count(int plugin_id); + +/** + * @brief Get function pointer of plugin_get_info_sim_contact_empty_number_count_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_empty_number_count_cb on success, NULL on error + */ +plugin_get_info_sim_contact_empty_number_count_cb plugin_get_function_get_info_sim_contact_empty_number_count(int plugin_id); + +/** + * @brief Get function pointer of plugin_get_info_sim_contact_empty_email_count_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_empty_email_count_cb on success, NULL on error + */ +plugin_get_info_sim_contact_empty_email_count_cb plugin_get_function_get_info_sim_contact_empty_email_count(int plugin_id); + +/** + * @brief Get function pointer of plugin_get_info_sim_contact_addressbook_id_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_addressbook_id_cb on success, NULL on error + */ +plugin_get_info_sim_contact_addressbook_id_cb plugin_get_function_get_info_sim_contact_addressbook_id(int plugin_id); + +/** + * @brief Get function pointer of plugin_get_info_sim_contact_item_id_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_item_id_cb on success, NULL on error + */ +plugin_get_info_sim_contact_item_id_cb plugin_get_function_get_info_sim_contact_item_id(int plugin_id); + +/** + * @brief Get function pointer of plugin_get_info_sim_contact_item_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_get_info_sim_contact_item_cb on success, NULL on error + */ +plugin_get_info_sim_contact_item_cb plugin_get_function_get_info_sim_contact_item(int plugin_id); + +/** + * @brief Get function pointer of plugin_add_sim_contact_item_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_add_sim_contact_item_cb on success, NULL on error + */ +plugin_add_sim_contact_item_cb plugin_get_function_add_sim_contact_item(int plugin_id); + +/** + * @brief Get function pointer of plugin_write_sim_contact_item_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_write_sim_contact_item_cb on success, NULL on error + */ +plugin_write_sim_contact_item_cb plugin_get_function_write_sim_contact_item(int plugin_id); + +/** + * @brief Get function pointer of plugin_delete_sim_contact_item_cb + * @param[in] plugin_id data-connector plugin id + * @return function pointer of plugin_delete_sim_contact_item_cb on success, NULL on error + */ +plugin_delete_sim_contact_item_cb plugin_get_function_delete_sim_contact_item(int plugin_id); + +/** * @} */ diff --git a/src/framework/utility/fw_compress.c b/src/framework/utility/fw_compress.c index e5d8db3..cddaae5 100755 --- a/src/framework/utility/fw_compress.c +++ b/src/framework/utility/fw_compress.c @@ -202,3 +202,150 @@ EXPORT_API sync_agent_util_compress_result_e sync_agent_uncompress(sync_agent_ut return SYNC_AGENT_UTIL_COMPRESS_FAIL; } + + +EXPORT_API sync_agent_util_compress_result_e sync_agent_ua_uncompress(sync_agent_util_compress_type_e type, const char *input_file_path, const char *output_direcory_path) +{ + _EXTERN_FUNC_ENTER; + + if (input_file_path == NULL || output_direcory_path == NULL) { + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + } + + if (!sync_agent_is_existing_fs(input_file_path)) { + _DEBUG_ERROR("tar input file not existing !!"); + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + } + + char *command = NULL; + + switch (type) { + case SYNC_AGENT_UTIL_COMPRESS_TYPE_TAR: + { + int command_len = strlen("tar xvfp ") + strlen(input_file_path) + strlen(" -C ") + strlen(output_direcory_path) +strlen(" delta.ua")+ 1; + int len = 0; + command = (char *)calloc(command_len, sizeof(char)); + if (command == NULL) + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + + len = g_strlcat(command, "tar xvfp ", command_len); + len = g_strlcat(command, input_file_path, command_len); + len = g_strlcat(command, " -C ", command_len); + len = g_strlcat(command, output_direcory_path, command_len); + len = g_strlcat(command, " delta.ua", command_len); + + if (len >= command_len) { + _DEBUG_ERROR("command buffer overflow !!"); + free(command); + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + } + + int pid = fork(); + if (pid == -1) { + _DEBUG_ERROR("Fork failed to create a process"); + free(command); + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + } else if (pid == 0) { + char *argv[4]; + + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = command; + argv[3] = 0; + + execv("/bin/sh", argv); + + abort(); + } + + int status = 0; + do { + if (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) { + free(command); + //_EXTERN_FUNC_EXIT; + //return SYNC_AGENT_UTIL_COMPRESS_SUCCESS; + _DEBUG_INFO("dalta.ua command success!!"); + goto TAR_MV_EXECUTE; + } else { + free(command); + //return SYNC_AGENT_UTIL_COMPRESS_FAIL; + _DEBUG_INFO("dalta.ua command failed!!"); + goto TAR_MV_EXECUTE; + } + } + } while (1); + } + break; + case SYNC_AGENT_UTIL_COMPRESS_TYPE_ZIP: + { + /* + * Not yet support + */ + } + break; + default: + _DEBUG_ERROR("Not support compress type!!"); + break; + } + + _EXTERN_FUNC_EXIT; + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + + +TAR_MV_EXECUTE: + { + int command_len = strlen("mv ") + strlen(input_file_path) + strlen(" ") + strlen(output_direcory_path) +strlen("/delta.tar")+ 1; + int len = 0; + command = (char *)calloc(command_len, sizeof(char)); + if (command == NULL) + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + + len = g_strlcat(command, "mv ", command_len); + len = g_strlcat(command, input_file_path, command_len); + len = g_strlcat(command, " ", command_len); + len = g_strlcat(command, output_direcory_path, command_len); + len = g_strlcat(command, "/delta.tar", command_len); + + if (len >= command_len) { + _DEBUG_ERROR("command buffer overflow !!"); + free(command); + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + } + + int pid = fork(); + if (pid == -1) { + _DEBUG_ERROR("Fork failed to create a process"); + free(command); + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + } else if (pid == 0) { + char *argv[4]; + + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = command; + argv[3] = 0; + + execv("/bin/sh", argv); + + abort(); + } + + int status = 0; + do { + if (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) { + free(command); + _EXTERN_FUNC_EXIT; + return SYNC_AGENT_UTIL_COMPRESS_SUCCESS; + } else { + free(command); + return SYNC_AGENT_UTIL_COMPRESS_FAIL; + } + } + } while (1); + } + + _EXTERN_FUNC_EXIT; + return SYNC_AGENT_UTIL_COMPRESS_FAIL; +} diff --git a/src/framework/utility/fw_mainloop.c b/src/framework/utility/fw_mainloop.c index 4072888..f0d9d01 100755 --- a/src/framework/utility/fw_mainloop.c +++ b/src/framework/utility/fw_mainloop.c @@ -74,7 +74,14 @@ EXPORT_API void sync_agent_run_main_loop(int use_thread) pthread_cond_init(&loop_cond, NULL); /* TODO : error handling if return value is not 0, fail logic */ pthread_mutex_lock(&loop_mutex); - pthread_create(&main_loop_thread_id, 0, _main_loop_rutine, 0); + int status_thread_create = 0; + status_thread_create = pthread_create(&main_loop_thread_id, 0, _main_loop_rutine, 0); + if(status_thread_create != 0) { + _DEBUG_WARNING("pthread_create [%d]", status_thread_create ); + pthread_mutex_unlock(&loop_mutex); + _EXTERN_FUNC_EXIT; + return; + } do { pthread_cond_wait(&loop_cond, &loop_mutex); } while (loop == NULL); diff --git a/src/fw-plugins/common-public/account/src/plugin_interface.c b/src/fw-plugins/common-public/account/src/plugin_interface.c index 850e660..1ad7b18 100755 --- a/src/fw-plugins/common-public/account/src/plugin_interface.c +++ b/src/fw-plugins/common-public/account/src/plugin_interface.c @@ -59,7 +59,7 @@ #define FW_CALENDAR 1 #define FW_MEMO 2 #define FW_CONTENT_COUNT 3 -#define FW_TASK 11 +#define FW_TASK 10 #define MAX_ACCOUNT_COUNT 20 static const char *agent_name = 0; diff --git a/src/fw-plugins/common-public/calendar/src/plugin_interface.c b/src/fw-plugins/common-public/calendar/src/plugin_interface.c index 79824ad..1506439 100755 --- a/src/fw-plugins/common-public/calendar/src/plugin_interface.c +++ b/src/fw-plugins/common-public/calendar/src/plugin_interface.c @@ -42,66 +42,45 @@ #endif #define FW_CALENDAR 1 /* plugIn-Id */ +#define EXTYPE_UPDATE_KEYWORD "X-EXTYPE:2" static sync_agent_util_async_queue_s *queue; - static int latest_calendar_version = 0; - static pthread_mutex_t lockx; - static int is_noti_from_me = 0; - static int is_storage_changed = 0; static sync_agent_add_item_cb_plugin callback_add_item; - static sync_agent_del_item_cb_plugin callback_del_item; - static sync_agent_update_item_cb_plugin callback_update_item; - static sync_agent_get_account_id_list_cb_plugin callback_get_account_id_list; +static sync_agent_del_child_item_cb_plugin callback_delete_child_item; static void _set_is_noti_from_me(int set_flag); - static int __get_is_noti_from_me(void); - +static char * _get_value_by_token(const char *src, const char *token, const char *end_of_token); static void _process_calendar_change(const char *view_uri, void *user_data); - static void *_rutine_calendar_change(void *); - static sync_agent_da_return_e _convert_service_error_to_common_error(int err); - static bool _get_account_id(account_h account, void *user_data); - -static bool __is_calendar_id(/*account_capability_type_e*/const char* capability_type, account_capability_state_e capability_value, void *user_data); - +static bool __is_calendar_id(const char* capability_type, account_capability_state_e capability_value, void *user_data); static sync_agent_da_return_e _get_service_folder_list_by_account_id(int account_id, calendar_list_h * item_list, int *count); - -static int _get_exdate_count(calendar_query_h query); - - +static int _get_deleted_exdate_item_count(calendar_query_h query); +static int _add_updated_exdate_item(int service_account_id, int index, char *parent_service_item_id, char *service_folder_id); +static sync_agent_da_return_e _process_exdate_item(calendar_record_h calendar_record); static sync_agent_da_return_e _get_service_event_list_by_folder_id(int folder_id, calendar_list_h * item_list, int *count); -//static void _calendar_db_result_cb(int error, void *user_data); - typedef struct account_id { int account_id; struct account_id *next; } account_id_s; -//static void _calendar_db_result_cb(int error, void *user_data) -//{ -// _INNER_FUNC_ENTER; -// _DEBUG_TRACE("error = %d", error); -// _INNER_FUNC_EXIT; -//} - static sync_agent_da_return_e _get_service_event_list_by_folder_id(int folder_id, calendar_list_h * item_list, int *count) { _INNER_FUNC_ENTER; sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - int service_ret = 0; + int service_ret = CALENDAR_ERROR_NONE; unsigned int ids[1]; calendar_query_h query = NULL; @@ -110,68 +89,41 @@ static sync_agent_da_return_e _get_service_event_list_by_folder_id(int folder_id // start pre condition service_ret = calendar_query_create(_calendar_event._uri, &query); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_query_create Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_create() Fail!: err[%d]", service_ret); + service_ret = calendar_filter_create(_calendar_event._uri, &filter); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_filter_create Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_create() Fail!: err[%d]", service_ret); + service_ret = calendar_filter_add_int(filter, _calendar_event.calendar_book_id, CALENDAR_MATCH_EQUAL, folder_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_filter_add_int Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_add_int() Fail!: err[%d]", service_ret); // end pre condition service_ret = calendar_query_set_filter(query, filter); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_query_set_filter Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_set_filter() Fail!: err[%d]", service_ret); ids[0] = _calendar_event.id; service_ret = calendar_query_set_projection(query, ids, 1); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_query_set_projection Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_set_projection() Fail!: err[%d]", service_ret); service_ret = calendar_db_get_records_with_query(query, 0, 0, &list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_db_get_records_with_query Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_db_get_records_with_query() Fail!: err[%d]", service_ret); + service_ret = calendar_list_get_count(list, count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_get_count() Fail!: err[%d]", service_ret); + _DEBUG_INFO("count(%d)", *count); service_ret = calendar_list_first(list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_first() Fail!: err[%d]", service_ret); - DACI_FINISH: + return_part: + ret = _convert_service_error_to_common_error(service_ret); calendar_filter_destroy(filter); calendar_query_destroy(query); *item_list = list; - return ret; _INNER_FUNC_EXIT; + return ret; } static sync_agent_da_return_e _get_service_folder_list_by_account_id(int account_id, calendar_list_h * item_list, int *count) @@ -188,71 +140,43 @@ static sync_agent_da_return_e _get_service_folder_list_by_account_id(int account // start pre condition service_ret = calendar_query_create(_calendar_book._uri, &query); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_query_create Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_create() Fail!: err[%d]", service_ret); + service_ret = calendar_filter_create(_calendar_book._uri, &filter); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_filter_create Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_create() Fail!: err[%d]", service_ret); + service_ret = calendar_filter_add_int(filter, _calendar_book.account_id, CALENDAR_MATCH_EQUAL, account_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_filter_add_int Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_add_int() Fail!: err[%d]", service_ret); // end pre condition service_ret = calendar_query_set_filter(query, filter); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_query_set_filter Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_set_filter() Fail!: err[%d]", service_ret); ids[0] = _calendar_book.id; service_ret = calendar_query_set_projection(query, ids, 1); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_query_set_projection Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_set_projection() Fail!: err[%d]", service_ret); service_ret = calendar_db_get_records_with_query(query, 0, 0, &list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_db_get_records_with_query Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_db_get_records_with_query() Fail!: err[%d]", service_ret); + service_ret = calendar_list_get_count(list, count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_get_count() Fail!: err[%d]", service_ret); _DEBUG_INFO("count(%d)", *count); service_ret = calendar_list_first(list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_first() Fail!: err[%d]", service_ret); - DACI_FINISH: + return_part: + ret = _convert_service_error_to_common_error(service_ret); calendar_filter_destroy(filter); calendar_query_destroy(query); *item_list = list; - return ret; _INNER_FUNC_EXIT; + return ret; } -static int _get_exdate_count(calendar_query_h query) +static int _get_deleted_exdate_item_count(calendar_query_h query) { _EXTERN_FUNC_ENTER; retvm_if(query == NULL, 0, "query is NULL"); @@ -260,50 +184,33 @@ static int _get_exdate_count(calendar_query_h query) calendar_filter_h filter = NULL; calendar_list_h list = NULL; calendar_record_h calendar_record = NULL; - int parent_count = 0; int exdate_count = 0; - int ret = CALENDAR_ERROR_NONE; + int service_ret = CALENDAR_ERROR_NONE; - ret = calendar_db_get_records_with_query(query, 0, 0, &list); - if (ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_db_get_records_with_query() failed"); - goto return_part; - } - ret = calendar_list_get_count(list, &parent_count); - if (ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_get_count() failed"); - goto return_part; - } - _DEBUG_INFO("parent_count = %d", parent_count); - ret = calendar_list_first(list); - if (ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_first() failed"); - goto return_part; - } + service_ret = calendar_db_get_records_with_query(query, 0, 0, &list); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_db_get_records_with_query() Fail!: err[%d]", service_ret); + + service_ret = calendar_list_first(list); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_first() Fail!: err[%d]", service_ret); int index = 0; do { - ret = calendar_list_get_current_record_p(list, &calendar_record); - if (ret != CALENDAR_ERROR_NONE || calendar_record == NULL) { + service_ret = calendar_list_get_current_record_p(list, &calendar_record); + if (service_ret != CALENDAR_ERROR_NONE || calendar_record == NULL) { _DEBUG_ERROR("calendar_list_get_current_record_p() failed"); continue; } char *exdate = NULL; - ret = calendar_record_get_str(calendar_record, _calendar_event.exdate, &exdate); - if (ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_str() failed"); - goto return_part; - } + service_ret = calendar_record_get_str(calendar_record, _calendar_event.exdate, &exdate); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_get_str() Fail!: err[%d]", service_ret); + _DEBUG_INFO("index = %d, exdate = %s", index, exdate); index++; gchar **array_exdate = g_strsplit(exdate, ",", -1); - if (array_exdate == NULL) { - _DEBUG_ERROR("g_strsplit failed"); - goto return_part; - } + goto_if(array_exdate == NULL, "array_exdate is NULL"); int array_length = 0; array_length = g_strv_length(array_exdate); @@ -318,8 +225,7 @@ static int _get_exdate_count(calendar_query_h query) } while (calendar_list_next(list) != CALENDAR_ERROR_NO_DATA); return_part: - _DEBUG_INFO("return_part"); - _DEBUG_INFO("exdate_count = %d", exdate_count); + _DEBUG_INFO("total exdate_count = %d", exdate_count); calendar_list_destroy(list, false); calendar_filter_destroy(filter); _EXTERN_FUNC_EXIT; @@ -332,16 +238,15 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_open_service(void) sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; int err = calendar_connect(); - //int err = calendar_connect_on_thread(); + if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_connect Fail!\n"); + _DEBUG_ERROR("[calendar] calendar_connect Fail!\n"); ret = _convert_service_error_to_common_error(err); } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_connect Success!\n"); + _DEBUG_INFO("[calendar] calendar_connect Success!\n"); } _EXTERN_FUNC_EXIT; - return ret; } @@ -351,16 +256,15 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_close_service(void) sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; int err = calendar_disconnect(); - //int err = calendar_disconnect_on_thread(); + if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_disconnect Fail!\n"); + _DEBUG_ERROR("[calendar] calendar_disconnect Fail!\n"); ret = _convert_service_error_to_common_error(err); } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_disconnect Success!\n"); + _DEBUG_INFO("[calendar] calendar_disconnect Success!\n"); } _EXTERN_FUNC_EXIT; - return ret; } @@ -369,13 +273,10 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_begin_transaction(void) _EXTERN_FUNC_ENTER; sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - - _DEBUG_INFO("[da_calendar_plugIn] not anymore need to transaction"); - + _DEBUG_INFO("[calendar] not anymore need to transaction"); _set_is_noti_from_me(1); _EXTERN_FUNC_EXIT; - return ret; } @@ -383,16 +284,16 @@ EXPORT_API int sync_agent_plugin_end_transaction(int is_success) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_calendar_plugIn] SLP Calendar Service is not supported Rollback Operation!\n"); + _DEBUG_INFO("[calendar] SLP Calendar Service is not supported Rollback Operation!\n"); sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - _DEBUG_INFO("[da_calendar_plugIn] in calendar Success!\n"); + _DEBUG_INFO("[calendar] in calendar Success!\n"); if (is_storage_changed == 0) { _DEBUG_INFO("calendar storaged was not Changed!!"); _set_is_noti_from_me(0); } is_storage_changed = 0; - _DEBUG_INFO("[da_calendar_plugIn] not anymore need to transaction, is_success : [%d]", is_success); + _DEBUG_INFO("[calendar] not anymore need to transaction, is_success : [%d]", is_success); _EXTERN_FUNC_EXIT; return ret; @@ -412,7 +313,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_item(int account_id, cha int un_type = 0; memcpy(&un_type, item, 4); int int_folder_id = atoi(folder_id); - _DEBUG_INFO("[da_calendar_plugIn] calendar type %d, in %d, folder id [%d]", un_type, item, int_folder_id); + _DEBUG_INFO("[calendar] calendar type %d, in %d, folder id [%d]", un_type, item, int_folder_id); /* setting folder id */ service_ret = calendar_record_set_int(item, _calendar_event.calendar_book_id, int_folder_id); @@ -421,7 +322,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_item(int account_id, cha ret = SYNC_AGENT_DA_ERRORS; goto DACI_FINISH; } - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_struct_set_int(folder %d) return [%d]!\n", atoi(folder_id), service_ret); + _DEBUG_INFO("[calendar] calendar_svc_struct_set_int(folder %d) return [%d]!\n", atoi(folder_id), service_ret); /* add item */ int slp_cal_info_id = 0; @@ -432,23 +333,18 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_item(int account_id, cha *item_id = 0; goto DACI_FINISH; } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_insert() Success!"); + _DEBUG_INFO("[calendar] calendar_svc_insert() Success!"); _DEBUG_INFO("calendar_svc_insert() Success!: id = %d", slp_cal_info_id); *item_id = g_strdup_printf("%d", slp_cal_info_id); is_storage_changed = 1; } DACI_FINISH: - /* memory free */ -// if (item != NULL){ service_ret = calendar_record_destroy(item, false); if (service_ret != CALENDAR_ERROR_NONE) { _DEBUG_ERROR("calendar_record_destroy() Fail! : err = %d", service_ret); } item = NULL; -// } - _EXTERN_FUNC_EXIT; - return ret; } @@ -458,38 +354,38 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_update_item(int account_id, retvm_if(folder_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "folder_id is NULL. FAIL !!!"); retvm_if(item_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "item_id is NULL. FAIL !!!"); + retvm_if(data == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "data is NULL. FAIL !!!"); - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - int err = 0; calendar_record_h item = (calendar_record_h) data; + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + int service_ret = CALENDAR_ERROR_NONE; int int_folder_id = atoi(folder_id); - int service_ret = calendar_record_set_int(item, _calendar_event.calendar_book_id, int_folder_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_int() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; + // exception handler for EXDATE item + if(_process_exdate_item(item) == SYNC_AGENT_DA_ERR_ITEM_READ_ONLY) { + _DEBUG_INFO("this is a updated exdate item. it should be not done calendar_db_update_record(). so just return."); + goto return_part; } - err = calendar_db_update_record(item); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_svc_update() Fail!\n"); - ret = _convert_service_error_to_common_error(err); - } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_update() Success!"); - is_storage_changed = 1; - } + service_ret = calendar_record_set_int(item, _calendar_event.calendar_book_id, int_folder_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_set_int() Fail!: err[%d]", service_ret); - DACI_FINISH: + service_ret = calendar_db_update_record(item); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_db_update_record() Fail!: err[%d]", service_ret); + + _DEBUG_INFO("[calendar] calendar_svc_update() Success!"); + is_storage_changed = 1; + +return_part: + ret = _convert_service_error_to_common_error(service_ret); if (item != NULL) { - calendar_record_destroy(item, false); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_destroy() Fail! : err = %d", err); + service_ret = calendar_record_destroy(item, false); + if (service_ret != CALENDAR_ERROR_NONE) { + _DEBUG_ERROR("calendar_record_destroy() Fail! : service_ret = %d", service_ret); } item = NULL; } _EXTERN_FUNC_EXIT; - return ret; } @@ -504,10 +400,10 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_item(int account_id, int err = calendar_db_delete_record(_calendar_event._uri, atoi(item_id)); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_delete() Fail!"); + _DEBUG_INFO("[calendar] calendar_svc_delete() Fail!"); ret = _convert_service_error_to_common_error(err); } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_delete() Success!"); + _DEBUG_INFO("[calendar] calendar_svc_delete() Success!"); is_storage_changed = 1; } @@ -531,20 +427,25 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_all_items(int account int item_id = 0; calendar_list_h event_list = NULL; + /* get folder id list for account id */ folder_id_list = sync_agent_plugin_get_folder_id_list(account_id, &folder_id_list_cnt, &folder_type_list); if (folder_id_list == NULL || folder_id_list_cnt == 0) { - _DEBUG_INFO("[da_calendar_plugIn] folder id list cnt : %d", folder_id_list_cnt); + _DEBUG_INFO("[calendar] folder id list cnt : %d", folder_id_list_cnt); if (folder_type_list != NULL) { cfree(folder_type_list); folder_type_list = NULL; } + if (folder_id_list != NULL) { + free(folder_id_list); + folder_id_list = NULL; + } return SYNC_AGENT_DA_ERR_NO_DATA; } int folder_iter = 0; for (; folder_iter < folder_id_list_cnt; folder_iter++) { int int_folder_id = atoi(folder_id_list[folder_iter]); - _DEBUG_INFO("[da_calendar_plugIn] folder id : %d\n", int_folder_id); + _DEBUG_INFO("[calendar] folder id : %d\n", int_folder_id); int event_count = 0; ret = _get_service_event_list_by_folder_id(int_folder_id, &event_list, &event_count); if (ret != SYNC_AGENT_DA_SUCCESS) { @@ -573,25 +474,25 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_all_items(int account event = NULL; service_ret = calendar_list_get_current_record_p(event_list, &event); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_list_get_current_record_p Fail!\n"); + _DEBUG_ERROR("[calendar] in calendar_list_get_current_record_p Fail!\n"); ret = _convert_service_error_to_common_error(service_ret); continue; } service_ret = calendar_record_get_int(event, _calendar_event.id, &item_id); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_record_get_int Fail!\n"); + _DEBUG_ERROR("[calendar] in calendar_record_get_int Fail!\n"); ret = _convert_service_error_to_common_error(service_ret); continue; } - _DEBUG_INFO("[da_calendar_plugIn] item id : %d\n", item_id); + _DEBUG_INFO("[calendar] item id : %d\n", item_id); err = calendar_db_delete_record(_calendar_event._uri, item_id); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_svc_delete(%d) Fail!\n", item_id); + _DEBUG_ERROR("[calendar] calendar_svc_delete(%d) Fail!\n", item_id); ret = _convert_service_error_to_common_error(err); goto DACI_FINISH; } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_delete(%d) Success!\n", item_id); + _DEBUG_INFO("[calendar] calendar_svc_delete(%d) Success!\n", item_id); is_storage_changed = 1; } @@ -619,11 +520,11 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_all_items(int account for (cnt = 0; cnt < folder_id_list_cnt; cnt++) { if (folder_id_list[cnt] != NULL) { free(folder_id_list[cnt]); - _DEBUG_INFO("[da_calendar_plugIn] folder id free !! \n"); + _DEBUG_INFO("[calendar] folder id free !! \n"); } } cfree(folder_id_list); - _DEBUG_INFO("[da_calendar_plugIn] folder id list free !! \n"); + _DEBUG_INFO("[calendar] folder id list free !! \n"); } if (folder_type_list != NULL) { cfree(folder_type_list); @@ -631,7 +532,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_all_items(int account } _EXTERN_FUNC_EXIT; - return ret; } @@ -648,11 +548,11 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_get_item(int account_id, cha /* get item */ err = calendar_db_get_record(_calendar_event._uri, atoi(item_id), &item); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_calendar_plugIn] calendar_db_get_record() Fail!\n"); + _DEBUG_INFO("[calendar] calendar_db_get_record() Fail!\n"); ret = _convert_service_error_to_common_error(err); *data = 0; } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_get() Success!\n"); + _DEBUG_INFO("[calendar] calendar_svc_get() Success!\n"); *data = (void *)item; } @@ -668,52 +568,45 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_folder(int account_id, c retvm_if(folder_name == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "folder_name is NULL. FAIL !!!"); sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - int err = 0; + int service_ret = CALENDAR_ERROR_NONE; calendar_record_h folder = 0; /* new service struct */ calendar_record_create(_calendar_book._uri, &folder); if (folder == NULL) { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_struct_new() Fail!\n"); + _DEBUG_INFO("[calendar] calendar_svc_struct_new() Fail!\n"); *folder_id = 0; return SYNC_AGENT_DA_ERRORS; } /* setting folder data */ - int cal_ret = calendar_record_set_int(folder, _calendar_book.account_id, account_id); - if (cal_ret != CALENDAR_ERROR_NONE) { - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } - cal_ret = calendar_record_set_int(folder, _calendar_book.visibility, 1); - if (cal_ret != CALENDAR_ERROR_NONE) { - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } - cal_ret = calendar_record_set_str(folder, _calendar_book.name, folder_name); - if (cal_ret != CALENDAR_ERROR_NONE) { - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + service_ret = calendar_record_set_int(folder, _calendar_book.account_id, account_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_set_int() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_int(folder, _calendar_book.visibility, 1); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_set_int() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(folder, _calendar_book.name, folder_name); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_set_str() Fail!: err[%d]", service_ret); /* add folder */ int service_folder_item_id = 0; - cal_ret = calendar_db_insert_record(folder, &service_folder_item_id); - if (cal_ret != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_insert() Fail!\n"); - ret = _convert_service_error_to_common_error(cal_ret); + service_ret = calendar_db_insert_record(folder, &service_folder_item_id); + if (service_ret != CALENDAR_ERROR_NONE) { + _DEBUG_INFO("[calendar] calendar_svc_insert() Fail!\n"); *folder_id = 0; } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_insert() Success!"); + _DEBUG_INFO("[calendar] calendar_svc_insert() Success!"); *folder_id = g_strdup_printf("%d", service_folder_item_id); is_storage_changed = 1; } - DACI_FINISH: - /* memory free */ + +return_part: + ret = _convert_service_error_to_common_error(service_ret); if (folder != NULL) { calendar_record_destroy(folder, false); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_destroy() Fail! : err = %d", err); + if (service_ret != CALENDAR_ERROR_NONE) { + _DEBUG_ERROR("calendar_record_destroy() Fail! : service_ret = %d", service_ret); } folder = NULL; } @@ -734,10 +627,10 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_folder(int account_id /* delete folder */ err = calendar_db_delete_record(_calendar_book._uri, atoi(folder_id)); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_calendar_plugIn] calendar_db_delete_record() Fail, err[%d]", err); + _DEBUG_INFO("[calendar] calendar_db_delete_record() Fail, err[%d]", err); ret = _convert_service_error_to_common_error(err); } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_delete() Success!\n"); + _DEBUG_INFO("[calendar] calendar_svc_delete() Success!\n"); calendar_db_clean_after_sync(atoi(folder_id), 0); is_storage_changed = 1; } @@ -756,24 +649,33 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_get_folder(int account_id, c sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; int err = 0; calendar_record_h folder = 0; + int task_folder_id = atoi(folder_id); + _DEBUG_INFO("[calendar] task_folder_id : %d\n", task_folder_id); - /* get item */ - int calendar_folder_id = atoi(folder_id); - _DEBUG_INFO("[da_calendar_plugIn] calendar_folder_id : %d\n", calendar_folder_id); - err = calendar_db_get_record(_calendar_book._uri, calendar_folder_id, &folder); + err = calendar_db_get_record(_calendar_book._uri, task_folder_id, &folder); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_contact_plugIn] contacts_svc_get_addressbook() Fail!\n"); + _DEBUG_INFO("[calendar] contacts_svc_get_addressbook() Fail!\n"); ret = _convert_service_error_to_common_error(err); *out_folder_name = 0; *out_folder_type = -1; - } else { - _DEBUG_INFO("[da_contact_plugIn] contacts_svc_get_addressbook() Success!\n"); + goto return_part; + } + + _DEBUG_INFO("[calendar] contacts_svc_get_addressbook() Success!\n"); + + *out_folder_name = 0; + err = calendar_record_get_str(folder, _calendar_book.name, out_folder_name); + if (err != CALENDAR_ERROR_NONE) { + _DEBUG_INFO("[calendar] calendar_record_get_str() Fail!\n"); + ret = _convert_service_error_to_common_error(err); *out_folder_name = 0; - calendar_record_get_str(folder, _calendar_book.name, out_folder_name); - *out_folder_type = DEFAULT_CALENDAR_FOLDER; + *out_folder_type = -1; + goto return_part; } - /* memory free */ + *out_folder_type = DEFAULT_CALENDAR_FOLDER; + +return_part: if (folder != NULL) { calendar_record_destroy(folder, false); if (err != CALENDAR_ERROR_NONE) { @@ -782,7 +684,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_get_folder(int account_id, c folder = NULL; } _EXTERN_FUNC_EXIT; - return ret; } @@ -790,7 +691,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_execute(int account_ID, cons { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_calendar_plugIn] service is not supported execute. \n"); + _DEBUG_INFO("[calendar] service is not supported execute. \n"); *result = 0; _EXTERN_FUNC_EXIT; @@ -802,64 +703,148 @@ EXPORT_API int sync_agent_plugin_get_used_item_count() { _EXTERN_FUNC_ENTER; + int used_cnt = 0; + int deleted_exdate_count = 0; + + int err = calendar_db_get_count(_calendar_event._uri, &used_cnt); + if (err != CALENDAR_ERROR_NONE) { + _DEBUG_INFO("[calendar] calendar_db_get_count() Fail\n"); + } else { + _DEBUG_INFO("[calendar] used_count = %d\n", used_cnt); + deleted_exdate_count = sync_agent_plugin_get_deleted_exdate_item_count(); + used_cnt += deleted_exdate_count; + } + + _DEBUG_INFO("[calendar] used_count = %d\n", used_cnt); + _EXTERN_FUNC_EXIT; + return used_cnt; +} + +EXPORT_API int sync_agent_plugin_get_deleted_exdate_item_count() +{ + _EXTERN_FUNC_ENTER; + calendar_filter_h filter = NULL; calendar_query_h query = NULL; - int used_cnt = 0; int exdate_parent_count = 0; int deleted_exdate_count = 0; - int err = CALENDAR_ERROR_NONE; + int service_ret = CALENDAR_ERROR_NONE; - err = calendar_db_get_count(_calendar_event._uri, &used_cnt); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_db_get_count() Fail"); - goto return_part; - } + // check exdate count + service_ret = calendar_query_create(_calendar_event._uri, &query); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_create() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_calendar_plugIn] used_count = %d\n", used_cnt); + service_ret = calendar_filter_create(_calendar_event._uri, &filter); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_create() Fail!: err[%d]", service_ret); - // check exdate count - err = calendar_query_create(_calendar_event._uri, &query); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_query_create() Fail"); - goto return_part; - } - err = calendar_filter_create(_calendar_event._uri, &filter); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_filter_create() Fail"); - goto return_part; - } - err = calendar_filter_add_str(filter, _calendar_event.exdate, CALENDAR_MATCH_EXISTS, ""); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_filter_add_str() Fail"); - goto return_part; - } - err = calendar_query_set_filter(query, filter); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_query_set_filter() Fail"); - goto return_part; - } - err = calendar_db_get_count_with_query(query, &exdate_parent_count); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_db_get_count_with_query() Fail"); - goto return_part; - } + service_ret = calendar_filter_add_str(filter, _calendar_event.exdate, CALENDAR_MATCH_EXISTS, ""); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_add_str() Fail!: err[%d]", service_ret); - _DEBUG_INFO("exdate_parent_count = %d\n", exdate_parent_count); + service_ret = calendar_query_set_filter(query, filter); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_set_filter() Fail!: err[%d]", service_ret); + + service_ret = calendar_db_get_count_with_query(query, &exdate_parent_count); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_db_get_count_with_query() Fail!: err[%d]", service_ret); + _DEBUG_INFO("exdate_parent_count = %d\n", exdate_parent_count); // if exdate:delete exist, get deleted exdate count if (exdate_parent_count > 0) { - deleted_exdate_count = _get_exdate_count(query); + deleted_exdate_count = _get_deleted_exdate_item_count(query); _DEBUG_INFO("deleted_exdate_count = %d\n", deleted_exdate_count); - used_cnt += deleted_exdate_count; } return_part: - _DEBUG_INFO("used_cnt = %d", used_cnt); calendar_filter_destroy(filter); calendar_query_destroy(query); _EXTERN_FUNC_EXIT; - return used_cnt; + return deleted_exdate_count; +} + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_is_exist_exdate_item(const char *fw_parent_id, const char *child_vcalendar) +{ + _EXTERN_FUNC_ENTER; + retvm_if(fw_parent_id == NULL, SYNC_AGENT_DA_ERRORS, "fw_parent_id is NULL. FAIL !!!"); + retvm_if(child_vcalendar == NULL, SYNC_AGENT_DA_ERRORS, "child_vcalendar is NULL. FAIL !!!"); + _DEBUG_INFO("fw_parent_id = %s", fw_parent_id); + + const char *updated_exdate_token = "\r\nX-EXTYPE:2\r\nEXDATE:"; + const char *exdate_token = "EXDATE:"; + char *temp = NULL; + char *updated_exdate = NULL; + int ret = SYNC_AGENT_DA_ERRORS; + int service_ret = CALENDAR_ERROR_NONE; + calendar_filter_h filter = NULL; + calendar_query_h query = NULL; + + temp = strstr(child_vcalendar, updated_exdate_token); + goto_if(temp == NULL, "this vcalendar has not exdate data"); + + updated_exdate = _get_value_by_token(temp + strlen(updated_exdate_token) - strlen(exdate_token), exdate_token, "\r\n"); + _DEBUG_INFO("updated_exdate = %s", updated_exdate); + goto_if(updated_exdate == NULL, "updated_exdate is null"); + + int matched_count = 0; + service_ret = calendar_query_create(_calendar_event._uri, &query); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_create() Fail!: err[%d]", service_ret); + + service_ret = calendar_filter_create(_calendar_event._uri, &filter); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_create() Fail!: err[%d]", service_ret); + + service_ret = calendar_filter_add_str(filter, _calendar_event.recurrence_id, CALENDAR_MATCH_EXACTLY, updated_exdate); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_add_str() Fail!: err[%d]", service_ret); + + ret = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_add_operator() Fail!: err[%d]", service_ret); + + service_ret = calendar_filter_add_int(filter, _calendar_event.original_event_id, CALENDAR_MATCH_EQUAL, atoi(fw_parent_id)); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_filter_add_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_query_set_filter(query, filter); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_query_set_filter() Fail!: err[%d]", service_ret); + + service_ret = calendar_db_get_count_with_query(query, &matched_count); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_db_get_count_with_query() Fail!: err[%d]", service_ret); + _DEBUG_INFO("matched_count = %d", matched_count); + + if (matched_count > 0) { + _DEBUG_INFO("this item already exist"); + ret = SYNC_AGENT_DA_ERR_ALREADY_EXIST; + goto return_part; + } + _DEBUG_INFO("this item is not exist. it's a new item."); + ret = SYNC_AGENT_DA_SUCCESS; + +return_part: + if(updated_exdate) { + free(updated_exdate); + updated_exdate = NULL; + } + calendar_filter_destroy(filter); + calendar_query_destroy(query); + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API void sync_agent_plugin_construct_exdate_parent_item(char *parent_service_id) +{ + _EXTERN_FUNC_ENTER; + retm_if(parent_service_id == NULL, "parent_service_id is NULL. FAIL !!!"); + _DEBUG_INFO("parent_service_id = %s", parent_service_id); + + calendar_record_h item = 0; + int service_ret = CALENDAR_ERROR_NONE; + + service_ret = calendar_db_get_record(_calendar_event._uri, atoi(parent_service_id), &item); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[claendar] calendar_db_get_record() Fail!: err[%d]", service_ret); + + service_ret = calendar_db_update_record(item); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_db_update_record() Fail!: err[%d]", service_ret); + _DEBUG_INFO("[calendar] calendar_svc_update() Success!"); + +return_part: + _EXTERN_FUNC_EXIT; + return; } EXPORT_API int sync_agent_plugin_get_used_item_count_for_folder(int account_id, char *folder_id) @@ -868,22 +853,22 @@ EXPORT_API int sync_agent_plugin_get_used_item_count_for_folder(int account_id, retvm_if(folder_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "folder_id is NULL. FAIL !!!"); - int ret = 0; - calendar_filter_h filter = NULL; calendar_query_h query = NULL; - ret = calendar_query_create(_calendar_event._uri, &query); - ret = calendar_filter_create(_calendar_event._uri, &filter); - ret = calendar_filter_add_int(filter, _calendar_event.calendar_book_id, CALENDAR_MATCH_EQUAL, atoi(folder_id)); - ret = calendar_query_set_filter(query, filter); + int service_ret = CALENDAR_ERROR_NONE; + + service_ret = calendar_query_create(_calendar_event._uri, &query); + service_ret = calendar_filter_create(_calendar_event._uri, &filter); + service_ret = calendar_filter_add_int(filter, _calendar_event.calendar_book_id, CALENDAR_MATCH_EQUAL, atoi(folder_id)); + service_ret = calendar_query_set_filter(query, filter); int used_cnt = 0; - ret = calendar_db_get_count_with_query(query, &used_cnt); - if (ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] calendar_db_get_count() Fail\n"); + service_ret = calendar_db_get_count_with_query(query, &used_cnt); + if (service_ret != CALENDAR_ERROR_NONE) { + _DEBUG_ERROR("[calendar] calendar_db_get_count() Fail\n"); } else { - _DEBUG_INFO("[da_calendar_plugIn] calendar_db_get_count() Success\n"); - _DEBUG_INFO("[da_calendar_plugIn] used_count = %d\n", used_cnt); + _DEBUG_INFO("[calendar] calendar_db_get_count() Success\n"); + _DEBUG_INFO("[calendar] used_count = %d\n", used_cnt); } if (filter != NULL) @@ -892,7 +877,6 @@ EXPORT_API int sync_agent_plugin_get_used_item_count_for_folder(int account_id, calendar_query_destroy(query); _EXTERN_FUNC_EXIT; - return used_cnt; } @@ -900,10 +884,9 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold { _EXTERN_FUNC_ENTER; - char **folder_id_list = 0; + char **folder_id_list = NULL; int count = 0; calendar_list_h service_folder_list = 0; - calendar_record_h folder = NULL; int err = 0; int i = 0; *folder_count = 0; @@ -913,31 +896,15 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold err = _get_service_folder_list_by_account_id(account_id, &service_folder_list, &count); if (err != SYNC_AGENT_DA_SUCCESS || count == 0) { _DEBUG_ERROR("_get_service_folder_list_by_account_id failed !!!"); - - if (service_folder_list != NULL) { - err = calendar_list_destroy(service_folder_list, true); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_destroy() Fail! : err = %d", err); - } - service_folder_list = NULL; - } - - _EXTERN_FUNC_EXIT; - return NULL; + folder_id_list = NULL; + goto return_part; } + if (count > 0) { folder_id_list = (char **)calloc(count, sizeof(char *)); if (folder_id_list == NULL) { _DEBUG_ERROR("CALLOC failed !!!"); - if (service_folder_list != NULL) { - err = calendar_list_destroy(service_folder_list, true); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_destroy() Fail! : err = %d", err); - } - service_folder_list = NULL; - } - _EXTERN_FUNC_EXIT; - return NULL; + goto return_part; } *folder_type_list = (int *)calloc(count, sizeof(int)); if (*folder_type_list == NULL) { @@ -946,45 +913,33 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold free(folder_id_list); folder_id_list = NULL; } - if (service_folder_list != NULL) { - err = calendar_list_destroy(service_folder_list, true); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_destroy() Fail! : err = %d", err); - } - service_folder_list = NULL; - } - _EXTERN_FUNC_EXIT; - return NULL; + goto return_part; } - /* find */ do { - /* get */ - err = calendar_list_get_current_record_p(service_folder_list, &folder); - if ((err != CALENDAR_ERROR_NONE) && (folder == NULL)) { - _DEBUG_ERROR("calendar_list_get_current_record_p() Fail! : err = %d", err); + int int_folder_id = 0; + calendar_record_h event = NULL; + err = calendar_record_create(_calendar_event._uri, &event); + if ((err != CALENDAR_ERROR_NONE) && (event == NULL)) { + _DEBUG_ERROR("calendar_record_create() Fail! : err = %d", err); + break; + } + + err = calendar_record_get_int(event, _calendar_event.calendar_book_id, &int_folder_id); + if (err != CALENDAR_ERROR_NONE) { + _DEBUG_ERROR("calendar_record_get_int() Fail! : err = %d", err); break; } - /* check */ - int int_folder_id = 0; - err = calendar_record_get_int(folder, _calendar_book.id, &int_folder_id); folder_id_list[i] = g_strdup_printf("%d", int_folder_id); (*folder_type_list)[i] = DEFAULT_CALENDAR_FOLDER; i++; *folder_count = i; - -// if (folder != NULL){ -// calendar_record_destroy(folder, false); -// if (err != CALENDAR_ERROR_NONE) { -// _DEBUG_ERROR("calendar_record_destroy() Fail! : err = %d", err); -// } -// folder = NULL; -// } - } while (calendar_list_next(service_folder_list) != CALENDAR_ERROR_NO_DATA); } - /* memory free */ + +return_part: + _DEBUG_INFO("return_part"); if (service_folder_list != NULL) { err = calendar_list_destroy(service_folder_list, true); if (err != CALENDAR_ERROR_NONE) { @@ -993,7 +948,6 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold service_folder_list = NULL; } _EXTERN_FUNC_EXIT; - return folder_id_list; } @@ -1001,7 +955,7 @@ EXPORT_API int *sync_agent_plugin_get_account_id_list(int *count) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_calendar_plugIn] start!!\n"); + _DEBUG_INFO("[calendar] start!!\n"); int error_code = account_connect(); @@ -1048,7 +1002,7 @@ EXPORT_API int *sync_agent_plugin_get_account_id_list(int *count) error_code = account_disconnect(); - _DEBUG_INFO("[da_calendar_plugIn] end!!\n"); + _DEBUG_INFO("[calendar] end!!\n"); _EXTERN_FUNC_EXIT; @@ -1059,14 +1013,14 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_calendar_plugIn] account_id : %d\n", account_id); - _DEBUG_INFO("[da_calendar_plugIn] folder_id : %s\n", folder_id); - _DEBUG_INFO("[da_calendar_plugIn] changepoint : %d\n", changepoint); - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + _DEBUG_INFO("[calendar] account_id : %d\n", account_id); + _DEBUG_INFO("[calendar] folder_id : %s\n", folder_id); + _DEBUG_INFO("[calendar] changepoint : %d\n", changepoint); + int calendarTimeStamp = changepoint; int current_change_point = 0; int temp_folder_id = atoi(folder_id); - int service_ret = 0; + int service_ret = CALENDAR_ERROR_NONE; sync_agent_plugin_item_node_s *root_ptr = 0; sync_agent_plugin_item_node_s *cursor_ptr = 0; @@ -1076,45 +1030,29 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for calendar_record_h changed_event = NULL; service_ret = calendar_db_get_changes_by_version(_calendar_event._uri, temp_folder_id, calendarTimeStamp, &service_changed_list, ¤t_change_point); - _DEBUG_INFO("[da_calendar_plugIn] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); - if ((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL)) { - _DEBUG_ERROR("calendar_db_get_changes_by_version() Fail! : err = %d", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + _DEBUG_INFO("[calendar] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); + goto_if((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL), "[calendar] calendar_db_get_changes_by_version() Fail!: err[%d]", service_ret); int list_count = 0; service_ret = calendar_list_get_count(service_changed_list, &list_count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_get_count() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_calendar_plugIn] in calendar_list_get_count [%d]!", list_count); + _DEBUG_INFO("[calendar] in calendar_list_get_count [%d]!", list_count); if (list_count <= 0) { -// ret =SYNC_AGENT_DA_ERR_NO_DATA; - goto DACI_FINISH; + goto return_part; } -// service_ret = calendar_svc_iter_next(iter); + service_ret = calendar_list_first(service_changed_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_first() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_first() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_calendar_plugIn] calendar_svc_iter_next service_ret : %d\n", service_ret); + _DEBUG_INFO("[calendar] calendar_svc_iter_next service_ret : %d\n", service_ret); do { _DEBUG_INFO("while start"); service_ret = calendar_list_get_current_record_p(service_changed_list, &changed_event); - if ((service_ret != CALENDAR_ERROR_NONE) && (changed_event == NULL)) { - _DEBUG_ERROR("calendar_list_get_current_record_p() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) && (changed_event == NULL), "[calendar] calendar_list_get_current_record_p() Fail!: err[%d]", service_ret); + int type = 0; service_ret = calendar_record_get_int(changed_event, _calendar_updated_info.modified_status, &type); if (service_ret != CALENDAR_ERROR_NONE) { @@ -1122,7 +1060,7 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for break; } - _DEBUG_INFO("[da_calendar_plugIn] type is [%d]", type); + _DEBUG_INFO("[calendar] type is [%d]", type); if (type == CALENDAR_EVENT_MODIFIED_STATUS_INSERTED) { int calendar_id = 0; service_ret = calendar_record_get_int(changed_event, _calendar_updated_info.id, &calendar_id); @@ -1130,14 +1068,18 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for _DEBUG_ERROR("calendar_record_get_int() Fail!: err = %d", service_ret); break; } - _DEBUG_INFO("[da_calendar_plugIn] calendar id is [%d]", calendar_id); + _DEBUG_INFO("[calendar] calendar id is [%d]", calendar_id); char *calendar_id_str = g_strdup_printf("%d", calendar_id); - _DEBUG_INFO("[da_calendar_plugIn] CALS_UPDATED_TYPE_INSERTED : [%s]\n", calendar_id_str); + _DEBUG_INFO("[calendar] CALS_UPDATED_TYPE_INSERTED : [%s]\n", calendar_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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } return NULL; } root_ptr->item_id = calendar_id_str; @@ -1147,6 +1089,14 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for 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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } + if (root_ptr) { + free(root_ptr); + root_ptr = NULL; + } return NULL; } cursor_ptr->next->item_id = calendar_id_str; @@ -1157,14 +1107,9 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for chagned_count++; } - - /*if list can successfully free child than dont need this free */ -// if (changed_event != NULL) -// calendar_record_destroy(changed_event, true); } while (calendar_list_next(service_changed_list) != CALENDAR_ERROR_NO_DATA); - DACI_FINISH: - + return_part: if (service_changed_list != NULL) { calendar_list_destroy(service_changed_list, true); service_changed_list = NULL; @@ -1173,7 +1118,6 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for *changeCount = chagned_count; _EXTERN_FUNC_EXIT; - return root_ptr; } @@ -1181,14 +1125,14 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_calendar_plugIn] account_id : %d\n", account_id); - _DEBUG_INFO("[da_calendar_plugIn] folder_id : %s\n", folder_id); - _DEBUG_INFO("[da_calendar_plugIn] changepoint : %d\n", change_point); + _DEBUG_INFO("[calendar] account_id : %d\n", account_id); + _DEBUG_INFO("[calendar] folder_id : %s\n", folder_id); + _DEBUG_INFO("[calendar] changepoint : %d\n", change_point); int current_change_point = 0; int calendar_time_stamp = change_point; int temp_folder_id = atoi(folder_id); - int service_ret = 0; - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + int service_ret = CALENDAR_ERROR_NONE; + sync_agent_plugin_item_node_s *root_ptr = 0; sync_agent_plugin_item_node_s *cursor_ptr = 0; int chagned_count = 0; @@ -1197,42 +1141,25 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for calendar_record_h changed_event = NULL; service_ret = calendar_db_get_changes_by_version(_calendar_event._uri, temp_folder_id, calendar_time_stamp, &service_changed_list, ¤t_change_point); - _DEBUG_INFO("[da_calendar_plugIn] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); - if ((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL)) { - _DEBUG_ERROR("calendar_db_get_changes_by_version() Fail! : err = %d", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + _DEBUG_INFO("[calendar] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); + goto_if((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL), "[calendar] calendar_db_get_changes_by_version() Fail!: err[%d]", service_ret); int list_count = 0; service_ret = calendar_list_get_count(service_changed_list, &list_count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_get_count() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_calendar_plugIn] in calendar_list_get_count [%d]!", list_count); + _DEBUG_INFO("[calendar] in calendar_list_get_count [%d]!", list_count); if (list_count <= 0) { - goto DACI_FINISH; + goto return_part; } service_ret = calendar_list_first(service_changed_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_first() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } - _DEBUG_INFO("[da_calendar_plugIn] service_ret : %d\n", service_ret); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_first() Fail!: err[%d]", service_ret); do { service_ret = calendar_list_get_current_record_p(service_changed_list, &changed_event); - if ((service_ret != CALENDAR_ERROR_NONE) && (changed_event == NULL)) { - _DEBUG_ERROR("calendar_list_get_current_record_p() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) && (changed_event == NULL), "[calendar] calendar_list_get_current_record_p() Fail!: err[%d]", service_ret); int type = 0; service_ret = calendar_record_get_int(changed_event, _calendar_updated_info.modified_status, &type); @@ -1248,12 +1175,16 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for break; } char *calendar_id_str = g_strdup_printf("%d", calendar_id); - _DEBUG_INFO("[da_calendar_plugIn] CALS_UPDATED_TYPE_DELETED : [%s]\n", calendar_id_str); + _DEBUG_INFO("[calendar] CALS_UPDATED_TYPE_DELETED : [%s]\n", calendar_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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } return NULL; } root_ptr->item_id = calendar_id_str; @@ -1263,6 +1194,14 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for 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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } + if (root_ptr) { + free(root_ptr); + root_ptr = NULL; + } return NULL; } cursor_ptr->next->item_id = calendar_id_str; @@ -1272,23 +1211,15 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for chagned_count++; } - - /*if list can successfully free child than dont need this free */ -// if (changed_event != NULL) -// calendar_record_destroy(changed_event, true); } while (calendar_list_next(service_changed_list) != CALENDAR_ERROR_NO_DATA); - DACI_FINISH: - + return_part: if (service_changed_list != NULL) { calendar_list_destroy(service_changed_list, true); service_changed_list = NULL; } - *change_count = chagned_count; - _EXTERN_FUNC_EXIT; - return root_ptr; } @@ -1296,58 +1227,43 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("\n[da_calendar_plugIn] account_id : %d\n", account_id); - _DEBUG_INFO("[da_calendar_plugIn] folder_id : %s\n", folder_id); - _DEBUG_INFO("[da_calendar_plugIn] changepoint : %d\n", change_point); - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + _DEBUG_INFO("\n[calendar] account_id : %d\n", account_id); + _DEBUG_INFO("[calendar] folder_id : %s\n", folder_id); + _DEBUG_INFO("[calendar] changepoint : %d\n", change_point); + int calendar_time_stamp = change_point; int temp_folder_id = atoi(folder_id); - int service_ret = 0; + int service_ret = CALENDAR_ERROR_NONE; calendar_list_h service_changed_list = 0; calendar_record_h changed_event = NULL; - sync_agent_plugin_item_node_s *root_ptr = 0; - sync_agent_plugin_item_node_s *cursor_ptr = 0; + sync_agent_plugin_item_node_s *root_ptr = NULL; + sync_agent_plugin_item_node_s *cursor_ptr = NULL; int chagned_count = 0; int current_change_point = 0; service_ret = calendar_db_get_changes_by_version(_calendar_event._uri, temp_folder_id, calendar_time_stamp, &service_changed_list, ¤t_change_point); - _DEBUG_INFO("[da_calendar_plugIn] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); - if ((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL)) { - _DEBUG_ERROR("calendar_db_get_changes_by_version() Fail! : err = %d", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + _DEBUG_INFO("[calendar] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); + goto_if((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL), "[calendar] calendar_db_get_changes_by_version() Fail!: err[%d]", service_ret); int list_count = 0; service_ret = calendar_list_get_count(service_changed_list, &list_count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_calendar_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_list_get_count() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_calendar_plugIn] in calendar_list_get_count [%d]!", list_count); + _DEBUG_INFO("[calendar] in calendar_list_get_count [%d]!", list_count); if (list_count <= 0) { - goto DACI_FINISH; + goto return_part; } service_ret = calendar_list_first(service_changed_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_first() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_get_child_record_count() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_calendar_plugIn] service_ret : %d\n", service_ret); + _DEBUG_INFO("[calendar] service_ret : %d\n", service_ret); do { service_ret = calendar_list_get_current_record_p(service_changed_list, &changed_event); - if ((service_ret != CALENDAR_ERROR_NONE) && (changed_event == NULL)) { - _DEBUG_ERROR("calendar_list_get_current_record_p() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) && (changed_event == NULL), "[calendar] calendar_record_get_child_record_count() Fail!: err[%d]", service_ret); + int type = 0; service_ret = calendar_record_get_int(changed_event, _calendar_updated_info.modified_status, &type); if (service_ret != CALENDAR_ERROR_NONE) { @@ -1363,47 +1279,113 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for break; } char *calendar_id_str = g_strdup_printf("%d", calendar_id); - _DEBUG_INFO("[da_calendar_plugIn] CALS_UPDATED_TYPE_MODIFIED : [%s]\n", calendar_id_str); + _DEBUG_INFO("[calendar] CALS_UPDATED_TYPE_MODIFIED : [%s]\n", calendar_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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } return NULL; } root_ptr->item_id = calendar_id_str; - root_ptr->next = 0; + root_ptr->next = NULL; 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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } + if (root_ptr) { + free(root_ptr); + root_ptr = NULL; + } return NULL; } cursor_ptr->next->item_id = calendar_id_str; - cursor_ptr->next->next = 0; + cursor_ptr->next->next = NULL; cursor_ptr = cursor_ptr->next; } - chagned_count++; - } + // end of normal calendar - /*if list can successfully free child than dont need this free */ -// if (changed_event != NULL) -// calendar_record_destroy(changed_event, true); - } while (calendar_list_next(service_changed_list) != CALENDAR_ERROR_NO_DATA); + // Check whether this calendar have updated exdate child + calendar_record_h cal_record = NULL; + unsigned int updated_exdate_count = 0; + service_ret = calendar_db_get_record(_calendar_event._uri, calendar_id, &cal_record); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_db_get_record() Fail!: err[%d]", service_ret); - DACI_FINISH: + service_ret = calendar_record_get_child_record_count(cal_record, _calendar_event.exception, &updated_exdate_count); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_get_child_record_count() Fail!: err[%d]", service_ret); + _DEBUG_INFO("updated_exdate_count(%d)", updated_exdate_count); + + if (updated_exdate_count > 0) { + cursor_ptr->parent_item_id = g_strdup("-1"); // parent_item_id of the parent item should be set to "-1" + } + int index = 0; + for (index = 0; index < updated_exdate_count; index++) { + calendar_record_h updated_exdate_record = NULL; + int child_service_id = 0; + int original_event_id = 0; + char *recurrence_id = NULL; + + service_ret = calendar_record_get_child_record_at_p(cal_record, _calendar_event.exception, index, &updated_exdate_record); + goto_if(service_ret != CALENDAR_ERROR_NONE || updated_exdate_record == NULL, "[calendar] calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_int(updated_exdate_record, _calendar_event.id, &child_service_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_get_int() Fail!: err[%d]", service_ret); + _DEBUG_INFO("child_service_id = %d", child_service_id); + + service_ret = calendar_record_get_int(updated_exdate_record, _calendar_event.original_event_id, &original_event_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_get_int() Fail!: err[%d]", service_ret); + _DEBUG_INFO("original_event_id = %d", original_event_id); + + service_ret = calendar_record_get_str(updated_exdate_record, _calendar_event.recurrence_id, &recurrence_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[calendar] calendar_record_get_str() Fail!: err[%d]", service_ret); + _DEBUG_INFO("recurrence_id = %s", recurrence_id); + + service_ret = calendar_record_set_str(updated_exdate_record, _calendar_event.exdate, NULL); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret); + + if (original_event_id >= 0 && recurrence_id != NULL && strlen(recurrence_id) > 0) { + 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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } + if (root_ptr) { + free(root_ptr); + root_ptr = NULL; + } + return NULL; + } + cursor_ptr->next->item_id = g_strdup_printf("%d", child_service_id); + cursor_ptr->next->parent_item_id = g_strdup_printf("%d", original_event_id); + cursor_ptr->next->next = NULL; + cursor_ptr = cursor_ptr->next; + chagned_count++; + } + } + // end of child calendar + } + } while (calendar_list_next(service_changed_list) != CALENDAR_ERROR_NO_DATA); + + return_part: if (service_changed_list != NULL) { calendar_list_destroy(service_changed_list, true); service_changed_list = NULL; } - *change_count = chagned_count; - _EXTERN_FUNC_EXIT; - return root_ptr; } @@ -1477,6 +1459,13 @@ EXPORT_API void sync_agent_plugin_set_callback_get_account_id_list(sync_agent_ge _EXTERN_FUNC_EXIT; } +EXPORT_API void sync_agent_plugin_set_callback_delete_child_item(sync_agent_del_child_item_cb_plugin callback) +{ + _EXTERN_FUNC_ENTER; + callback_delete_child_item = callback; + _EXTERN_FUNC_EXIT; +} + EXPORT_API int sync_agent_plugin_get_max_item_count(int folder_type) { _EXTERN_FUNC_ENTER; @@ -1648,13 +1637,13 @@ static void _set_is_noti_from_me(int set_flag) _INNER_FUNC_ENTER; if (pthread_mutex_lock(&lockx)) { - _DEBUG_ERROR("[da_calendar_plugIn] pthread_mutex_lock error"); + _DEBUG_ERROR("[calendar] pthread_mutex_lock error"); } is_noti_from_me = set_flag; if (pthread_mutex_unlock(&lockx)) { - _DEBUG_ERROR("[da_calendar_plugIn] pthread_mutex_unlock error"); + _DEBUG_ERROR("[calendar] pthread_mutex_unlock error"); } _INNER_FUNC_EXIT; @@ -1669,16 +1658,49 @@ static int __get_is_noti_from_me(void) return is_noti_from_me; } -void _process_calendar_change(const char *view_uri, void *user_data) +static char * _get_value_by_token(const char *src, const char *token, const char *end_of_token) { _INNER_FUNC_ENTER; + if (src == NULL || strlen(src) <= 0) { + _DEBUG_ERROR("src is null"); + return NULL; + } - _DEBUG_TRACE("[da_calendar_plugIn] detected calendar storage changed\n"); + char *token_loc = NULL; + char *str_output = NULL; + + if ((token_loc = strstr(src, token)) != NULL) { + char *str_temp = strstr(token_loc, end_of_token); + if (str_temp != NULL) { + int ret_str_length = strlen(token_loc) - strlen(token) - strlen(str_temp); + if (ret_str_length <= 0) { + _DEBUG_ERROR("token_loc = %s", token_loc); + _DEBUG_ERROR("token = %s", token); + _DEBUG_ERROR("str_temp = %s", str_temp); + _DEBUG_ERROR("ret_str_length(%d) <= 0", ret_str_length); + goto return_part; + } + str_output = (char *)calloc(ret_str_length, sizeof(char)); + goto_if(str_output == NULL, "str_output is NULL"); + + memcpy(str_output, token_loc + strlen(token), ret_str_length); + } + } + +return_part: + _INNER_FUNC_EXIT; + return str_output; +} + +void _process_calendar_change(const char *view_uri, void *user_data) +{ + _INNER_FUNC_ENTER; + _DEBUG_TRACE("[calendar] detected calendar storage changed\n"); int from_Me = __get_is_noti_from_me(); if (from_Me == 1) { _set_is_noti_from_me(0); - _DEBUG_TRACE("[da_calendar_plugIn] This noti is from Me!! so will be ignored!!\n"); + _DEBUG_TRACE("[calendar] This noti is from Me!! so will be ignored!!\n"); return; } @@ -1694,6 +1716,12 @@ void _process_calendar_change(const char *view_uri, void *user_data) if (sync_agent_async_queue_length(queue) < 1) { sync_agent_send_msg_async_queue(queue, (void *)calendarVersion); _DEBUG_INFO("fw_async_queue_length = %d", sync_agent_async_queue_length(queue)); + } else { + _DEBUG_INFO("send_msg_failed... sync_agent_async_queue_length(queue) >= 1"); + if(calendarVersion != NULL) { + free(calendarVersion); + calendarVersion = NULL; + } } _INNER_FUNC_EXIT; @@ -1703,7 +1731,7 @@ static void *_rutine_calendar_change(void *data) { _INNER_FUNC_ENTER; - _DEBUG_TRACE("[da_calendar_plugIn] Start __rutine_Calendar_Change (create thread)\n"); + _DEBUG_TRACE("[calendar] Start __rutine_Calendar_Change (create thread)\n"); /* * Create Queue @@ -1737,8 +1765,8 @@ static void *_rutine_calendar_change(void *data) int i = 0; for (; i < account_list_count; i++) { int calendar_account_id = account_list[i]; - _DEBUG_TRACE("[da_calendar_plugIn] calendar_account_id : %d, count : %d\n", calendar_account_id, account_list_count); - _DEBUG_TRACE("[da_calendar_plugIn] Before calendar_svc_event_get_changes : %d\n", calendar_version); + _DEBUG_TRACE("[calendar] calendar_account_id : %d, count : %d\n", calendar_account_id, account_list_count); + _DEBUG_TRACE("[calendar] Before calendar_svc_event_get_changes : %d\n", calendar_version); /*get folder id */ int folder_list_count = 0; @@ -1747,7 +1775,7 @@ static void *_rutine_calendar_change(void *data) _DEBUG_ERROR("calendar_list_get_count() Fail! : err = %d", service_ret); break; } - _DEBUG_TRACE("[da_calendar_plugIn] folder_list_count : %d", folder_list_count); + _DEBUG_TRACE("[calendar] folder_list_count : %d", folder_list_count); do { @@ -1817,46 +1845,48 @@ static void *_rutine_calendar_change(void *data) switch (type) { case CALENDAR_EVENT_MODIFIED_STATUS_INSERTED: { + _DEBUG_INFO("[calendar] Calendar Inserted!\n"); char calendar_folder_id_str[12]; snprintf(calendar_folder_id_str, sizeof(calendar_folder_id_str), "%d", calendar_folder_id); - _DEBUG_TRACE("[da_calendar_plugIn] Calendar Inserted!\n"); - _DEBUG_TRACE("[da_calendar_plugIn] calendar folder id : %s\n", calendar_folder_id_str); - int result = callback_add_item(account_list[i], i, calendar_id_str, FW_CALENDAR, calendar_folder_id_str, 0); + _DEBUG_INFO("[calendar] calendar folder id : %s\n", calendar_folder_id_str); + int result = callback_add_item(account_list[i], i, calendar_id_str, NULL, FW_CALENDAR, calendar_folder_id_str, 0); if (!result) - _DEBUG_TRACE("[da_calendar_plugIn] Failed to call SA_EH_Add_Item() \n"); - else - _DEBUG_TRACE("[da_calendar_plugIn] Success to call SA_EH_Add_Item() \n"); - + _DEBUG_ERROR("[calendar] Failed to call SA_EH_Add_Item() \n"); } break; case CALENDAR_EVENT_MODIFIED_STATUS_UPDATED: { - _DEBUG_TRACE("[da_calendar_plugIn] Calendar Updated!\n"); - int result = callback_update_item(account_list[i], i, calendar_id_str, FW_CALENDAR); + _DEBUG_INFO("[calendar] Calendar Updated!\n"); + char *parend_id = NULL; + int exdate_count = 0; + char calendar_folder_id_str[12]; + + snprintf(calendar_folder_id_str, sizeof(calendar_folder_id_str), "%d", calendar_folder_id); + _DEBUG_INFO("[calendar] calendar folder id : %s\n", calendar_folder_id_str); + + exdate_count = _add_updated_exdate_item(account_list[i], i, calendar_id_str, calendar_folder_id_str); + if (exdate_count > 0) { + parend_id = g_strdup("-1"); + } + + int result = callback_update_item(account_list[i], i, calendar_id_str, parend_id, FW_CALENDAR); if (!result) - _DEBUG_TRACE("[da_calendar_plugIn] Failed to call callback_del_item() \n"); + _DEBUG_ERROR("[calendar] Failed to call callback_update_item() \n"); } break; case CALENDAR_EVENT_MODIFIED_STATUS_DELETED: { - _DEBUG_TRACE("[da_calendar_plugIn] Calendar Deleted!\n"); + _DEBUG_INFO("[calendar] Calendar Deleted!\n"); int result = callback_del_item(account_list[i], i, calendar_id_str, FW_CALENDAR); if (!result) - _DEBUG_TRACE("[da_calendar_plugIn] Failed to call callback_del_item() \n"); + _DEBUG_ERROR("[calendar] Failed to call callback_del_item() \n"); } break; default: - _DEBUG_TRACE("[da_calendar_plugIn] cached Another Calendar Change Noti!\n"); + _DEBUG_INFO("[calendar] cached Another Calendar Change Noti!\n"); break; } - - /*if list can successfully free child than dont need this free */ -// if (row_event != NULL){ -// calendar_record_destroy(row_event, true); -// row_event = NULL; -// } - } while (calendar_list_next(record_list) != CALENDAR_ERROR_NO_DATA); if (record_list != NULL) { @@ -1866,13 +1896,7 @@ static void *_rutine_calendar_change(void *data) } record_list = NULL; } - /*if list can successfully free child than dont need this free */ -// if (folder != NULL){ -// calendar_record_destroy(folder, true); -// folder = NULL; -// } - - } while (calendar_list_next(folder_list) != CALENDAR_ERROR_NO_DATA); /*folder iter list */ + } while (calendar_list_next(folder_list) != CALENDAR_ERROR_NO_DATA); _DEBUG_TRACE("folder list free"); if (folder_list != NULL) { @@ -1882,22 +1906,16 @@ static void *_rutine_calendar_change(void *data) } folder_list = NULL; } - - } /*account loop for */ + } _DEBUG_TRACE("account list free"); if (account_list != NULL) { free(account_list); } + } - } /*while (1) */ - - // close calendar service sync_agent_plugin_close_service(); - - _DEBUG_TRACE("[da_calendar_plugIn] End __rutine_Calendar_Change (create thread)\n"); - + _DEBUG_TRACE("[calendar] End __rutine_Calendar_Change (create thread)\n"); _INNER_FUNC_EXIT; - return 0; } @@ -1906,9 +1924,13 @@ static sync_agent_da_return_e _convert_service_error_to_common_error(int err) _INNER_FUNC_ENTER; sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - _DEBUG_TRACE("[da_calendar_plugIn] Error Code : %d\n", err); + _DEBUG_TRACE("[calendar] Error Code : %d\n", err); switch (err) { + case CALENDAR_ERROR_NONE: + ret = SYNC_AGENT_DA_SUCCESS; + break; + case CALENDAR_ERROR_INVALID_PARAMETER: /* -4 */ ret = SYNC_AGENT_DA_ERR_INVALID_CONTENT; break; @@ -1919,7 +1941,6 @@ static sync_agent_da_return_e _convert_service_error_to_common_error(int err) } _INNER_FUNC_EXIT; - return ret; } @@ -1973,13 +1994,12 @@ static bool _get_account_id(account_h account, void *user_data) return has_contact; } -static bool __is_calendar_id(/*account_capability_type_e*/const char* capability_type, account_capability_state_e capability_value, void *user_data) +static bool __is_calendar_id(const char* capability_type, account_capability_state_e capability_value, void *user_data) { _INNER_FUNC_ENTER; retvm_if(capability_type == NULL, FALSE, "capability_type is NULL !!"); bool *has_contact = user_data; - //if (capability_type == ACCOUNT_CAPABILITY_CALENDAR) { if (strncmp(capability_type, ACCOUNT_SUPPORTS_CAPABILITY_CALENDAR, strlen(capability_type)) == 0) { *has_contact = TRUE; _INNER_FUNC_EXIT; @@ -1988,3 +2008,190 @@ static bool __is_calendar_id(/*account_capability_type_e*/const char* capability _INNER_FUNC_EXIT; return TRUE; } + +static int _add_updated_exdate_item(int service_account_id, int index, char *parent_service_item_id, char *service_folder_id) +{ + _EXTERN_FUNC_ENTER; + retvm_if(parent_service_item_id == NULL, 0, "parent_service_item_id is NULL !!"); + + // Check whether this calendar have updated exdate child + calendar_record_h cal_record = NULL; + unsigned int exception_count = 0; + int result = 0; + int service_ret = 0; + int updated_exdate_count = 0; + + service_ret = calendar_db_get_record(_calendar_event._uri, atoi(parent_service_item_id), &cal_record); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_db_get_record() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_child_record_count(cal_record, _calendar_event.exception, &exception_count); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() Fail!: err[%d]", service_ret); + + _DEBUG_INFO("exception_count = %d, parent_service_item_id = %s", exception_count, parent_service_item_id); + goto_if(exception_count <= 0, "exception_count <= 0"); + + // All child item of parent item whose has original_event_id as service_id field should be deleted before callback_add_item() + // Requesting by Calendar Svc Team (2013-03-26 tw123.kim & iamjs.kim) + result = callback_delete_child_item(parent_service_item_id, NULL); + if (!result) + _DEBUG_ERROR("Failed to call callback_delete_child_item() \n"); + + int exdate_index = 0; + for (exdate_index = 0; exdate_index < exception_count; exdate_index++) { + calendar_record_h updated_exdate_record = NULL; + int child_service_id = 0; + int original_event_id = 0; + char *recurrence_id = NULL; + + service_ret = calendar_record_get_child_record_at_p(cal_record, _calendar_event.exception, exdate_index, &updated_exdate_record); + goto_if(service_ret != CALENDAR_ERROR_NONE || updated_exdate_record == NULL, "calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_int(updated_exdate_record, _calendar_event.id, &child_service_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_int() Fail!: err[%d]", service_ret); + + char *child_id = g_strdup_printf("%d", child_service_id); + _DEBUG_INFO("child_id = %s", child_id); + + service_ret = calendar_record_get_int(updated_exdate_record, _calendar_event.original_event_id, &original_event_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_int() Fail!: err[%d]", service_ret); + _DEBUG_INFO("original_event_id = %d", original_event_id); + + service_ret = calendar_record_get_str(updated_exdate_record, _calendar_event.recurrence_id, &recurrence_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_str() Fail!: err[%d]", service_ret); + _DEBUG_INFO("recurrence_id = %s", recurrence_id); + + service_ret = calendar_record_set_str(updated_exdate_record, _calendar_event.exdate, NULL); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret); + + if (original_event_id >= 0 && recurrence_id != NULL && strlen(recurrence_id) > 0) { + char *parent_id = strdup(parent_service_item_id); + result = callback_add_item(service_account_id, index, child_id, parent_id, FW_CALENDAR, service_folder_id, 0); + if (!result) + _DEBUG_ERROR("Failed to call SA_EH_Add_Item() \n"); + else { + _DEBUG_INFO("Success to call SA_EH_Add_Item() \n"); + updated_exdate_count++; + } + } + } + +return_part: + _DEBUG_INFO("updated_exdate_count = %d", updated_exdate_count); + _INNER_FUNC_EXIT; + return updated_exdate_count; +} + +static sync_agent_da_return_e _process_exdate_item(calendar_record_h calendar_record) +{ + _INNER_FUNC_ENTER; + retvm_if(calendar_record == NULL, SYNC_AGENT_DA_ERRORS, "calendar_record is NULL !!"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + int service_ret = CALENDAR_ERROR_NONE; + gchar **array_delete_exdate = NULL; + GList *matched_item_list = NULL; + + // case 1 : updated exdate item doesn't need to calendar_db_update_record(), so just return this API + char *check_exdate_update = NULL; + service_ret = calendar_record_get_str(calendar_record, _calendar_event.recurrence_id, &check_exdate_update); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_str() Fail!: err[%d]", service_ret); + + if (check_exdate_update != NULL && g_strcmp0(check_exdate_update, EXTYPE_UPDATE_KEYWORD) == 0) { + // this is a updated exdate item. it should be not done calendar_db_update_record(). so just return + ret = SYNC_AGENT_DA_ERR_ITEM_READ_ONLY; + goto return_part; + } + + // case 2 : the parent item which has updated exdate items, it should be got DB changing callback function + unsigned int exception_count = 0; + service_ret = calendar_record_get_child_record_count(calendar_record, _calendar_event.exception, &exception_count); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() Fail!: err[%d]", service_ret); + _DEBUG_INFO("exception_count(%d)", exception_count); + + if (exception_count <= 0) { + _DEBUG_INFO("this record has not updated exdate item. so just return"); + goto return_part; + } + + _DEBUG_INFO("this is a parent item of updated exdate items. it should be got DB changing callback function"); + _set_is_noti_from_me(0); + + // case 3 : updated exdate items which exist at the same date of deleted exdate items, should be deleted + // 3-1 : get the deleted exdate items + char *exdate = NULL; + service_ret = calendar_record_get_str(calendar_record, _calendar_event.exdate, &exdate); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_str() Fail!: err[%d]", service_ret); + + _DEBUG_INFO("exdate = %s", exdate); + if (exdate == NULL) { + goto return_part; + } + + array_delete_exdate = g_strsplit(exdate, ",", -1); + goto_if(array_delete_exdate == NULL, "array_delete_exdate is NULL"); + + // 3-2 : get the updated exdate items, After that check whether same date exist, or not. + int updated_index = 0; + for (updated_index = 0; updated_index < exception_count; updated_index++) { + calendar_record_h updated_exdate_record = NULL; + char *recurrence_id = NULL; + int deleted_index = 0; + + service_ret = calendar_record_get_child_record_at_p(calendar_record, _calendar_event.exception, updated_index, &updated_exdate_record); + goto_if(service_ret != CALENDAR_ERROR_NONE || updated_exdate_record == NULL, "calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_str(updated_exdate_record, _calendar_event.recurrence_id, &recurrence_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_str() Fail!: err[%d]", service_ret); + _DEBUG_INFO("updated_index = %d, recurrence_id = %s", updated_index, recurrence_id); + + for (deleted_index = 0; array_delete_exdate[deleted_index] != NULL; deleted_index++) { + _DEBUG_INFO("one_exdate = %s, deleted_index = %d", array_delete_exdate[deleted_index], deleted_index); + if (strcmp(recurrence_id, array_delete_exdate[deleted_index]) == 0) { + _DEBUG_INFO("matched date = %s", array_delete_exdate[deleted_index]); + matched_item_list = g_list_append(matched_item_list, updated_exdate_record); + } + } + } + + // 3-3 : delete the matched items + int parent_service_item_id = 0; + service_ret = calendar_record_get_int(calendar_record, _calendar_event.id, &parent_service_item_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_int() Fail!: err[%d]", service_ret); + + char *parent_id = g_strdup_printf("%d", parent_service_item_id); + _DEBUG_INFO("parent_service_item_id = %s", parent_id); + + int matched_count = g_list_length(matched_item_list); + _DEBUG_INFO("matched_count = %d", matched_count); + + int matched_index = 0; + for (matched_index = 0; matched_index < matched_count; matched_index++) { + calendar_record_h record = (calendar_record_h)g_list_nth_data(matched_item_list, matched_index); + int child_service_id = 0; + + service_ret = calendar_record_remove_child_record(calendar_record, _calendar_event.exception, record); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_remove_child_record() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_int(record, _calendar_event.id, &child_service_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_int() Fail!: err[%d]", service_ret); + + char *child_id = g_strdup_printf("%d", child_service_id); + _DEBUG_INFO("child_id for deleting = %s, index = %d", child_id, matched_index); + + ret = callback_delete_child_item(parent_id, child_id); + if (!ret) + _DEBUG_ERROR("Failed to call callback_delete_child_item() \n"); + } + +return_part: + if(array_delete_exdate) { + g_strfreev(array_delete_exdate); + array_delete_exdate = NULL; + } + if(matched_item_list) { + g_list_free(matched_item_list); + matched_item_list = NULL; + } + _INNER_FUNC_EXIT; + return ret; +} 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 4246fd0..d69f798 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 @@ -277,100 +277,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 +303,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 +324,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 +404,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 +424,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 +444,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 +455,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 +472,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 +500,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 +518,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 +540,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; } diff --git a/src/fw-plugins/common-public/contact/src/plugin_interface.c b/src/fw-plugins/common-public/contact/src/plugin_interface.c index edfbd8e..c9c7afc 100755 --- a/src/fw-plugins/common-public/contact/src/plugin_interface.c +++ b/src/fw-plugins/common-public/contact/src/plugin_interface.c @@ -64,6 +64,8 @@ static sync_agent_update_item_cb_plugin callback_update_item; static sync_agent_get_account_id_list_cb_plugin callback_get_account_id_list; +static sync_agent_del_child_item_cb_plugin callback_delete_child_item; + static void _set_is_noti_from_me(int set_flag); static int _get_is_noti_from_me(void); @@ -90,16 +92,8 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_open_service(void) { _EXTERN_FUNC_ENTER; -// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; -// int err = contacts_svc_connect(); -// if (err < CTS_SUCCESS) { -// _DEBUG_INFO("[da_contact_plugIn] in contact Fail!\n"); -// ret = _convert_service_error_to_common_error(err); -// } else { -// _DEBUG_INFO("[da_contact_plugIn] in contact Success!\n"); -// } - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + contacts_error_e err = contacts_connect2(); if (err != CONTACTS_ERROR_NONE) { _DEBUG_ERROR("[da_contact_plugIn] in contact Fail!\n"); @@ -109,7 +103,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_open_service(void) } _EXTERN_FUNC_EXIT; - return ret; } @@ -117,16 +110,8 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_close_service(void) { _EXTERN_FUNC_ENTER; -// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; -// int err = contacts_svc_disconnect(); -// if (err < CTS_SUCCESS) { -// _DEBUG_INFO("[da_contact_plugIn] in contact Fail!\n"); -// ret = _convert_service_error_to_common_error(err); -// } else { -// _DEBUG_INFO("[da_contact_plugIn] in contact Success!\n"); -// } - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + contacts_error_e err = contacts_disconnect2(); if (err != CONTACTS_ERROR_NONE) { _DEBUG_ERROR("[da_contact_plugIn] in contact Fail!\n"); @@ -136,7 +121,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_close_service(void) } _EXTERN_FUNC_EXIT; - return ret; } @@ -194,28 +178,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_item(int account_id, cha { _EXTERN_FUNC_ENTER; -// retvm_if(folder_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "item_id is NULL. FAIL !!!"); -// -// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; -// int err = 0; -// CTSstruct *item = (CTSstruct *)data; -// -// /* add item */ -// err = contacts_svc_insert_contact(atoi(folder_id), (CTSstruct *)item); -// if (err < CTS_SUCCESS) { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_insert_contact() Fail!\n"); -// ret = _convert_service_error_to_common_error(err); -// *item_id = 0; -// } else { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_insert_contact() Success!\n"); -// *item_id = g_strdup_printf("%d", err); -// is_storage_changed = 1; -// } -// -// /* memory free */ -// if (item != NULL) -// contacts_svc_struct_free(item); - retvm_if(folder_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "item_id is NULL. FAIL !!!"); sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; @@ -255,7 +217,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_item(int account_id, cha contacts_record_destroy(record, true); _EXTERN_FUNC_EXIT; - return ret; } @@ -712,25 +673,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_get_item(int account_id, cha { _EXTERN_FUNC_ENTER; -// retvm_if(item_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "item_id is NULL. FAIL !!!"); -// -// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; -// int err = 0; -// CTSstruct *item = 0; -// -// /* get item */ -// int contact_id = atoi(item_id); -// _DEBUG_INFO("[da_contact_plugIn] contact_id : %d\n", contact_id); -// err = contacts_svc_get_contact(contact_id, &item); -// if (err < CTS_SUCCESS) { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_get_contact() Fail!\n"); -// ret = _convert_service_error_to_common_error(err); -// *data = 0; -// } else { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_get_contact() Success!\n"); -// *data = (void *)item; -// } - retvm_if(item_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "item_id is NULL. FAIL !!!"); sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; @@ -863,19 +805,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_folder(int account_id retvm_if(folder_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "folder_id is NULL. FAIL !!!"); -// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; -// int err = 0; -// -// /* delete folder */ -// err = contacts_svc_delete_addressbook(atoi(folder_id)); -// if (err < CTS_SUCCESS) { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_delete_addressbook(%s) Fail!\n", folder_id); -// ret = _convert_service_error_to_common_error(err); -// } else { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_delete_addressbook(%s) Success!\n", folder_id); -// is_storage_changed = 1; -// } - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; contacts_error_e err = CONTACTS_ERROR_NONE; @@ -978,19 +907,6 @@ EXPORT_API int sync_agent_plugin_get_used_item_count(void) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_contact_plugIn] Start\n"); - -// int ret = SYNC_AGENT_DA_SUCCESS; -// int used_cnt = contacts_svc_count(CTS_GET_ALL_CONTACT); -// if (used_cnt < 0) { -// _DEBUG_INFO("[da_contact_plugIn] contact_svc_count() Fail\n"); -// ret = _convert_service_error_to_common_error(used_cnt); -// } else { -// _DEBUG_INFO("[da_contact_plugIn] contact_svc_count() Success\n"); -// _DEBUG_INFO("[da_contact_plugIn] used_count = %d\n", used_cnt); -// ret = used_cnt; -// } - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; contacts_error_e err = CONTACTS_ERROR_NONE; int used_cnt = 0; @@ -1015,19 +931,6 @@ EXPORT_API int sync_agent_plugin_get_used_item_count_for_folder(int account_id, retvm_if(folder_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "folder_id is NULL. FAIL !!!"); - _DEBUG_INFO("[da_contact_plugIn] Start\n"); - -// int ret = SYNC_AGENT_DA_SUCCESS; -// int used_cnt = contacts_svc_count_with_int(CTS_GET_COUNT_CONTACTS_IN_ADDRESSBOOK, atoi(folder_id)); -// if (used_cnt < 0) { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_count_with_int(%s) Fail\n", folder_id); -// ret = _convert_service_error_to_common_error(used_cnt); -// } else { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_count_with_int(%s) Success\n", folder_id); -// _DEBUG_INFO("[da_contact_plugIn] used_count = %d\n", used_cnt); -// ret = used_cnt; -// } - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; contacts_error_e err = CONTACTS_ERROR_NONE; int used_cnt = 0; @@ -1086,71 +989,6 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold { _EXTERN_FUNC_ENTER; -// char **folder_id_list = 0; -// *folder_count = 0; -// CTSiter *iter_addressbook = 0; -// CTSvalue *addressbook = 0; -// -// if (account_id == -1) { -// folder_id_list = (char **)calloc(1, sizeof(char *)); -// if( folder_id_list == NULL ) { -// _DEBUG_ERROR("CALLOC failed !!!"); -// return NULL; -// } -// *folder_type_list = (int *)calloc(1, sizeof(int)); -// if( *folder_type_list == NULL ) { -// _DEBUG_ERROR("CALLOC failed !!!"); -// return NULL; -// } -// -// folder_id_list[0] = "0"; -// *folder_count = 1; -// (*folder_type_list)[0] = DEFAULT_CONTACT_FOLDER; -// -// return folder_id_list; -// } -// -// folder_id_list = (char **)calloc(50, sizeof(char *)); -// if( folder_id_list == NULL ) { -// _DEBUG_ERROR("CALLOC failed !!!"); -// return NULL; -// } -// *folder_type_list = (int *)calloc(50, sizeof(int)); -// if( *folder_type_list == NULL ) { -// _DEBUG_ERROR("CALLOC failed !!!"); -// return NULL; -// } -// -// int err = contacts_svc_get_list_with_int(CTS_LIST_ADDRESSBOOKS_OF_ACCOUNT_ID, account_id, &iter_addressbook); -// err = contacts_svc_iter_next(iter_addressbook); -// while (err == CTS_SUCCESS) { -// addressbook = contacts_svc_iter_get_info(iter_addressbook); -// if (addressbook != NULL) { -// int addressbook_id = 0; -// addressbook_id = contacts_svc_value_get_int(addressbook, CTS_LIST_ADDRESSBOOK_ID_INT); -// char *str_addressbook_id = g_strdup_printf("%d", addressbook_id); -// _DEBUG_INFO("[da_contact_plugIn] addressbook_id : %d\n", addressbook_id); -// -// folder_id_list[*folder_count] = str_addressbook_id; -// (*folder_type_list)[*folder_count] = DEFAULT_CONTACT_FOLDER; -// *folder_count = *folder_count + 1; -// -// if (addressbook != NULL) -// contacts_svc_value_free(addressbook); -// -// err = contacts_svc_iter_next(iter_addressbook); -// } else { -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_iter_get_info() Fail!\n"); -// break; -// } -// } -// -// /* memory free */ -// if (iter_addressbook != NULL) { -// contacts_svc_iter_remove(iter_addressbook); -// _DEBUG_INFO("[da_contact_plugIn] contacts_svc_iter_remove !! \n"); -// } - char **folder_id_list = 0; *folder_count = 0; @@ -1772,14 +1610,10 @@ EXPORT_API int sync_agent_plugin_get_last_change_point(void) { _EXTERN_FUNC_ENTER; -// contacts_svc_begin_trans(); -// int contactVersion = contacts_svc_end_trans(1); - int contactVersion; contacts_db_get_current_version(&contactVersion); _EXTERN_FUNC_EXIT; - return contactVersion; } @@ -1848,6 +1682,13 @@ EXPORT_API void sync_agent_plugin_set_callback_get_account_id_list(sync_agent_ge _EXTERN_FUNC_EXIT; } +EXPORT_API void sync_agent_plugin_set_callback_delete_child_item(sync_agent_del_child_item_cb_plugin callback) +{ + _EXTERN_FUNC_ENTER; + callback_delete_child_item = callback; + _EXTERN_FUNC_EXIT; +} + EXPORT_API int sync_agent_plugin_get_max_item_count(int folder_type) { _EXTERN_FUNC_ENTER; @@ -2108,6 +1949,12 @@ static void _process_contact_change(const char *view_uri, void *user_data) if (sync_agent_async_queue_length(queue) < 1) { sync_agent_send_msg_async_queue(queue, (void *)contactVersion); _DEBUG_TRACE("fw_async_queue_length = %d", sync_agent_async_queue_length(queue)); + } else { + _DEBUG_INFO("send_msg_failed... sync_agent_async_queue_length(queue) >= 1"); + if(contactVersion != NULL) { + free(contactVersion); + contactVersion = NULL; + } } _INNER_FUNC_EXIT; @@ -2393,7 +2240,7 @@ static void *_rutine_contact_change(void *data) { _DEBUG_TRACE("[da_contact_plugIn] CTS_OPERATION_INSERTED\n"); - int result = callback_add_item(accountList[i], i, contact_id_str, FW_CONTACT, str_addressbook_id, 0); + int result = callback_add_item(accountList[i], i, contact_id_str, NULL, FW_CONTACT, str_addressbook_id, 0); _DEBUG_TRACE("[da_contact_plugIn] ===1\n"); if (!result) _DEBUG_ERROR("[da_contact_plugIn] Failed to call callback_add_item() \n"); @@ -2404,7 +2251,7 @@ static void *_rutine_contact_change(void *data) _DEBUG_TRACE("[da_contact_plugIn] CTS_OPERATION_UPDATED\n"); _DEBUG_TRACE("[da_contact_plugIn] contact_id : %s\n", contact_id_str); - int result = callback_update_item(accountList[i], i, contact_id_str, FW_CONTACT); + int result = callback_update_item(accountList[i], i, contact_id_str, NULL, FW_CONTACT); if (!result) _DEBUG_ERROR("[da_contact_plugIn] Failed to call callback_update_item() \n"); } diff --git a/src/fw-plugins/common-public/http/src/plugin_interface.c b/src/fw-plugins/common-public/http/src/plugin_interface.c index 28a85f0..c123a70 100755 --- a/src/fw-plugins/common-public/http/src/plugin_interface.c +++ b/src/fw-plugins/common-public/http/src/plugin_interface.c @@ -700,7 +700,7 @@ EXPORT_API int sync_agent_plugin_send_message(void *session, void **header_bindi case LIBCURL_HTTP_POST: curl_easy_setopt(curl, CURLOPT_POST, 1L); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, send_msg_length); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, send_msg); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void*)send_msg); break; case LIBCURL_HTTP_PUT: curl_easy_setopt(curl, CURLOPT_PUT, 1L); diff --git a/src/fw-plugins/common-public/memo/src/plugin_interface.c b/src/fw-plugins/common-public/memo/src/plugin_interface.c index 13643b4..8fa7056 100755 --- a/src/fw-plugins/common-public/memo/src/plugin_interface.c +++ b/src/fw-plugins/common-public/memo/src/plugin_interface.c @@ -56,6 +56,8 @@ static sync_agent_update_item_cb_plugin callback_update_item; static sync_agent_get_account_id_list_cb_plugin callback_get_accountidlist; +static sync_agent_del_child_item_cb_plugin callback_delete_child_item; + static void _free_item_node(sync_agent_plugin_item_node_s * node); static void _set_is_noti_from_me(int set_flag); @@ -739,6 +741,13 @@ EXPORT_API void sync_agent_plugin_set_callback_get_account_id_list(sync_agent_ge _EXTERN_FUNC_EXIT; } +EXPORT_API void sync_agent_plugin_set_callback_delete_child_item(sync_agent_del_child_item_cb_plugin callback) +{ + _EXTERN_FUNC_ENTER; + callback_delete_child_item = callback; + _EXTERN_FUNC_EXIT; +} + /********************************** static function *******************************************/ static void _free_item_node(sync_agent_plugin_item_node_s * node) @@ -797,7 +806,11 @@ void _process_memo_change(void *data) } pthread_t thread_process_change_id; - pthread_create(&thread_process_change_id, 0, __rutine_memo_change, 0); + int status_thread_create = 0; + status_thread_create = pthread_create(&thread_process_change_id, 0, __rutine_memo_change, 0); + if(status_thread_create != 0) { + _DEBUG_WARNING("pthread_create [%d]", status_thread_create ); + } _INNER_FUNC_EXIT; } @@ -840,7 +853,7 @@ static void *__rutine_memo_change(void *data) { /* memo service is not supported folder */ _DEBUG_VERBOSE("[da_memo_plugIn] MEMO_OPERATION_ADD\n"); - result = callback_add_item(accountList[i], i, str_item_id, FW_MEMO, "0", 0); + result = callback_add_item(accountList[i], i, str_item_id, NULL, FW_MEMO, "0", 0); if (!result) { _DEBUG_ERROR("[da_memo_plugIn] Failed to call callback_add_item() \n"); goto DACI_FINISH; @@ -850,7 +863,7 @@ static void *__rutine_memo_change(void *data) case MEMO_OPERATION_UPDATE: { _DEBUG_VERBOSE("[da_memo_plugIn] MEMO_OPERATION_UPDATE\n"); - result = callback_update_item(accountList[i], i, str_item_id, FW_MEMO); + result = callback_update_item(accountList[i], i, str_item_id, NULL, FW_MEMO); if (!result) { _DEBUG_ERROR("[da_memo_plugIn] Failed to call callback_update_item() \n"); goto DACI_FINISH; diff --git a/src/fw-plugins/common-public/slp-device/include/slp_device_info.h b/src/fw-plugins/common-public/slp-device/include/slp_device_info.h index c092e0d..850d8ca 100755 --- a/src/fw-plugins/common-public/slp-device/include/slp_device_info.h +++ b/src/fw-plugins/common-public/slp-device/include/slp_device_info.h @@ -18,6 +18,8 @@ #ifndef SAMSUNG_DEVICE_INFO_H_ #define SAMSUNG_DEVICE_INFO_H_ +#define DEF_DEVDETAIL_FWV "db/SyncML/oma-dm-service/DevDetail/FwV" + char *slp_device_info_get_software_version(); char *slp_device_info_get_hardware_version(); char *slp_device_info_get_modem_version(); diff --git a/src/fw-plugins/common-public/slp-device/src/slp_device_info.c b/src/fw-plugins/common-public/slp-device/src/slp_device_info.c index 159f0d4..2a75965 100755 --- a/src/fw-plugins/common-public/slp-device/src/slp_device_info.c +++ b/src/fw-plugins/common-public/slp-device/src/slp_device_info.c @@ -446,6 +446,8 @@ char *slp_device_info_get_firmware_version() free(firmware_ver); _DEBUG_INFO("firmware_version [%s]\n", firmware_version); + vconf_set_str(DEF_DEVDETAIL_FWV, firmware_version); + _EXTERN_FUNC_EXIT; return firmware_version; diff --git a/src/fw-plugins/common-public/slp-sysnoti-alarm/src/plugin_interface.c b/src/fw-plugins/common-public/slp-sysnoti-alarm/src/plugin_interface.c index 39bbe9f..b68535f 100755 --- a/src/fw-plugins/common-public/slp-sysnoti-alarm/src/plugin_interface.c +++ b/src/fw-plugins/common-public/slp-sysnoti-alarm/src/plugin_interface.c @@ -107,6 +107,7 @@ EXPORT_API sync_agent_pm_return_e sync_agent_plugin_add_service_data(void *add_d pmci_alarm_s *temp_add_data = (pmci_alarm_s *) add_data; + _DEBUG_INFO("temp_add_data start_alarm_time[%s], repeat_type[%d], repeat_value[%d], is_disposable[%d]", temp_add_data->start_alarm_time, temp_add_data->repeat_type, temp_add_data->repeat_value, temp_add_data->is_disposable); int appsync_alarm = 0; diff --git a/src/fw-plugins/common-public/slp-sysnoti-wap-push/src/plugin_interface.c b/src/fw-plugins/common-public/slp-sysnoti-wap-push/src/plugin_interface.c index e95a981..ba59872 100755 --- a/src/fw-plugins/common-public/slp-sysnoti-wap-push/src/plugin_interface.c +++ b/src/fw-plugins/common-public/slp-sysnoti-wap-push/src/plugin_interface.c @@ -629,6 +629,10 @@ void ___operation_syncml_msg_cb(msg_handle_t handle, int msg_id, int ext_id, voi registered_wap_push_operation_cb(0, (void *)san_operation); } else { _DEBUG_ERROR("not registered registered_wap_push_operation_cb !!"); + if(san_operation != NULL) { + free(san_operation); + san_operation = NULL; + } } _INNER_FUNC_EXIT; diff --git a/src/fw-plugins/common-public/task/src/plugin_interface.c b/src/fw-plugins/common-public/task/src/plugin_interface.c index 26ebab0..3e41588 100755 --- a/src/fw-plugins/common-public/task/src/plugin_interface.c +++ b/src/fw-plugins/common-public/task/src/plugin_interface.c @@ -41,7 +41,7 @@ #define LOG_TAG "PLUGIN_DA_TASK" #endif -#define FW_TASK 11 +#define FW_TASK 10 static sync_agent_util_async_queue_s *queue; @@ -61,6 +61,8 @@ static sync_agent_update_item_cb_plugin callback_update_item; static sync_agent_get_account_id_list_cb_plugin callback_get_account_id_list; +static sync_agent_del_child_item_cb_plugin callback_delete_child_item; + static void _set_is_noti_from_me(int set_flag); static int __get_is_noti_from_me(void); @@ -89,77 +91,47 @@ static sync_agent_da_return_e _get_service_event_list_by_folder_id(int folder_id _INNER_FUNC_ENTER; sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - int service_ret = 0; + int service_ret = CALENDAR_ERROR_NONE; unsigned int ids[1]; calendar_query_h query = NULL; calendar_filter_h filter = NULL; calendar_list_h list = NULL; - // start pre condition service_ret = calendar_query_create(_calendar_todo._uri, &query); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_query_create Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_query_create() Fail!: err[%d]", service_ret); + service_ret = calendar_filter_create(_calendar_todo._uri, &filter); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_filter_create Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_filter_create() Fail!: err[%d]", service_ret); + service_ret = calendar_filter_add_int(filter, _calendar_todo.calendar_book_id, CALENDAR_MATCH_EQUAL, folder_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_filter_add_int Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } - // end pre condition + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_filter_add_int() Fail!: err[%d]", service_ret); service_ret = calendar_query_set_filter(query, filter); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_query_set_filter Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_query_set_filter() Fail!: err[%d]", service_ret); ids[0] = _calendar_todo.id; service_ret = calendar_query_set_projection(query, ids, 1); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_query_set_projection Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_query_set_projection() Fail!: err[%d]", service_ret); service_ret = calendar_db_get_records_with_query(query, 0, 0, &list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_db_get_records_with_query Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_db_get_records_with_query() Fail!: err[%d]", service_ret); + service_ret = calendar_list_get_count(list, count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_get_count() Fail!: err[%d]", service_ret); _DEBUG_INFO("count(%d)", *count); service_ret = calendar_list_first(list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_first() Fail!: err[%d]", service_ret); - DACI_FINISH: + return_part: + ret = _convert_service_error_to_common_error(service_ret); calendar_filter_destroy(filter); calendar_query_destroy(query); *item_list = list; - return ret; _INNER_FUNC_EXIT; + return ret; } static sync_agent_da_return_e _get_service_folder_list_by_account_id(int account_id, calendar_list_h * item_list, int *count) @@ -174,70 +146,40 @@ static sync_agent_da_return_e _get_service_folder_list_by_account_id(int account calendar_filter_h filter = NULL; calendar_list_h list = NULL; - // start pre condition service_ret = calendar_query_create(_calendar_book._uri, &query); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_query_create Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_query_create() Fail!: err[%d]", service_ret); + service_ret = calendar_filter_create(_calendar_book._uri, &filter); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_filter_create Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_filter_create() Fail!: err[%d]", service_ret); + service_ret = calendar_filter_add_int(filter, _calendar_book.account_id, CALENDAR_MATCH_EQUAL, account_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_filter_add_int Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } - // end pre condition + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_filter_add_int() Fail!: err[%d]", service_ret); service_ret = calendar_query_set_filter(query, filter); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_query_set_filter Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_query_set_filter() Fail!: err[%d]", service_ret); ids[0] = _calendar_book.id; service_ret = calendar_query_set_projection(query, ids, 1); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_query_set_projection Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_query_set_projection() Fail!: err[%d]", service_ret); service_ret = calendar_db_get_records_with_query(query, 0, 0, &list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_db_get_records_with_query Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_db_get_records_with_query() Fail!: err[%d]", service_ret); + service_ret = calendar_list_get_count(list, count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_get_count() Fail!: err[%d]", service_ret); _DEBUG_INFO("count(%d)", *count); service_ret = calendar_list_first(list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_first() Fail!: err[%d]", service_ret); - DACI_FINISH: + return_part: + ret = _convert_service_error_to_common_error(service_ret); calendar_filter_destroy(filter); calendar_query_destroy(query); *item_list = list; - return ret; _INNER_FUNC_EXIT; + return ret; } EXPORT_API sync_agent_da_return_e sync_agent_plugin_open_service(void) @@ -245,17 +187,16 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_open_service(void) _EXTERN_FUNC_ENTER; sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - //int err = calendar_connect_on_thread(); int err = calendar_connect(); + if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] calendar_connect Fail!\n"); + _DEBUG_ERROR("[task] calendar_connect Fail!\n"); ret = _convert_service_error_to_common_error(err); } else { - _DEBUG_INFO("[da_task_plugIn] calendar_connect Success!\n"); + _DEBUG_INFO("[task] calendar_connect Success!\n"); } _EXTERN_FUNC_EXIT; - return ret; } @@ -265,16 +206,15 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_close_service(void) sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; int err = calendar_disconnect(); - //int err = calendar_disconnect_on_thread(); + if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] calendar_disconnect Fail!\n"); + _DEBUG_ERROR("[task] calendar_disconnect Fail!\n"); ret = _convert_service_error_to_common_error(err); } else { - _DEBUG_INFO("[da_task_plugIn] calendar_disconnect Success!\n"); + _DEBUG_INFO("[task] calendar_disconnect Success!\n"); } _EXTERN_FUNC_EXIT; - return ret; } @@ -314,7 +254,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_item(int account_id, cha int un_type = 0; memcpy(&un_type, item, 4); int int_folder_id = atoi(folder_id); - _DEBUG_INFO("[da_task_plugIn] calendar type %d, in %d, folder id [%d]", un_type, item, int_folder_id); + _DEBUG_INFO("[task] calendar type %d, in %d, folder id [%d]", un_type, item, int_folder_id); /* setting folder id */ service_ret = calendar_record_set_int(item, _calendar_todo.calendar_book_id, int_folder_id); @@ -323,7 +263,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_item(int account_id, cha ret = SYNC_AGENT_DA_ERRORS; goto DACI_FINISH; } - _DEBUG_INFO("[da_task_plugIn] calendar_svc_struct_set_int(folder %d) return [%d]!\n", atoi(folder_id), service_ret); + _DEBUG_INFO("[task] calendar_svc_struct_set_int(folder %d) return [%d]!\n", atoi(folder_id), service_ret); /* add item */ int slp_cal_info_id = 0; @@ -334,7 +274,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_item(int account_id, cha *item_id = 0; goto DACI_FINISH; } else { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_insert() Success!"); + _DEBUG_INFO("[task] calendar_svc_insert() Success!"); _DEBUG_INFO("calendar_svc_insert() Success!: id = %d", slp_cal_info_id); *item_id = g_strdup_printf("%d", slp_cal_info_id); is_storage_changed = 1; @@ -356,41 +296,31 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_update_item(int account_id, retvm_if(folder_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "folder_id is NULL. FAIL !!!"); retvm_if(item_id == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "item_id is NULL. FAIL !!!"); - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - int err = 0; calendar_record_h item = (calendar_record_h) data; + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + int service_ret = CALENDAR_ERROR_NONE; int int_folder_id = atoi(folder_id); - /* setting folder id */ - int service_ret = calendar_record_set_int(item, _calendar_todo.calendar_book_id, int_folder_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_int() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + service_ret = calendar_record_set_int(item, _calendar_todo.calendar_book_id, int_folder_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_record_set_int() Fail!: err[%d]", service_ret); /* update item */ - err = calendar_db_update_record(item); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] calendar_svc_update() Fail!\n"); - ret = _convert_service_error_to_common_error(err); - } else { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_update() Success!"); - is_storage_changed = 1; - } + service_ret = calendar_db_update_record(item); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_db_update_record() Fail!: err[%d]", service_ret); - /* memory free */ - DACI_FINISH: - /* memory free */ + _DEBUG_INFO("[task] calendar_svc_update() Success!"); + is_storage_changed = 1; + + return_part: + ret = _convert_service_error_to_common_error(service_ret); if (item != NULL) { - calendar_record_destroy(item, false); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_destroy() Fail! : err = %d", err); + service_ret = calendar_record_destroy(item, false); + if (service_ret != CALENDAR_ERROR_NONE) { + _DEBUG_ERROR("calendar_record_destroy() Fail! : service_ret = %d", service_ret); } item = NULL; } _EXTERN_FUNC_EXIT; - return ret; } @@ -405,10 +335,10 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_item(int account_id, int err = calendar_db_delete_record(_calendar_todo._uri, atoi(item_id)); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_delete() Fail!"); + _DEBUG_INFO("[task] calendar_svc_delete() Fail!"); ret = _convert_service_error_to_common_error(err); } else { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_delete() Success!"); + _DEBUG_INFO("[task] calendar_svc_delete() Success!"); is_storage_changed = 1; } @@ -435,18 +365,22 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_all_items(int account /* get folder id list for account id */ folder_id_list = sync_agent_plugin_get_folder_id_list(account_id, &folder_id_list_cnt, &folder_type_list); if (folder_id_list == NULL || folder_id_list_cnt == 0) { - _DEBUG_INFO("[da_task_plugIn] folder id list cnt : %d", folder_id_list_cnt); + _DEBUG_INFO("[task] folder id list cnt : %d", folder_id_list_cnt); if (folder_type_list != NULL) { cfree(folder_type_list); folder_type_list = NULL; } + if (folder_id_list != NULL) { + free(folder_id_list); + folder_id_list = NULL; + } return SYNC_AGENT_DA_ERR_NO_DATA; } int folder_iter = 0; for (; folder_iter < folder_id_list_cnt; folder_iter++) { int int_folder_id = atoi(folder_id_list[folder_iter]); - _DEBUG_INFO("[da_task_plugIn] folder id : %d\n", int_folder_id); + _DEBUG_INFO("[task] folder id : %d\n", int_folder_id); int event_count = 0; ret = _get_service_event_list_by_folder_id(int_folder_id, &event_list, &event_count); if (ret != SYNC_AGENT_DA_SUCCESS) { @@ -475,25 +409,25 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_all_items(int account event = NULL; service_ret = calendar_list_get_current_record_p(event_list, &event); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_list_get_current_record_p Fail!\n"); + _DEBUG_ERROR("[task] in calendar_list_get_current_record_p Fail!\n"); ret = _convert_service_error_to_common_error(service_ret); continue; } service_ret = calendar_record_get_int(event, _calendar_todo.id, &item_id); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_record_get_int Fail!\n"); + _DEBUG_ERROR("[task] in calendar_record_get_int Fail!\n"); ret = _convert_service_error_to_common_error(service_ret); continue; } - _DEBUG_INFO("[da_task_plugIn] item id : %d\n", item_id); + _DEBUG_INFO("[task] item id : %d\n", item_id); err = calendar_db_delete_record(_calendar_todo._uri, item_id); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] calendar_svc_delete(%d) Fail!\n", item_id); + _DEBUG_ERROR("[task] calendar_svc_delete(%d) Fail!\n", item_id); ret = _convert_service_error_to_common_error(err); goto DACI_FINISH; } else { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_delete(%d) Success!\n", item_id); + _DEBUG_INFO("[task] calendar_svc_delete(%d) Success!\n", item_id); is_storage_changed = 1; } @@ -521,11 +455,11 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_all_items(int account for (cnt = 0; cnt < folder_id_list_cnt; cnt++) { if (folder_id_list[cnt] != NULL) { free(folder_id_list[cnt]); - _DEBUG_INFO("[da_task_plugIn] folder id free !! \n"); + _DEBUG_INFO("[task] folder id free !! \n"); } } cfree(folder_id_list); - _DEBUG_INFO("[da_task_plugIn] folder id list free !! \n"); + _DEBUG_INFO("[task] folder id list free !! \n"); } if (folder_type_list != NULL) { cfree(folder_type_list); @@ -549,11 +483,11 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_get_item(int account_id, cha /* get item */ err = calendar_db_get_record(_calendar_todo._uri, atoi(item_id), &item); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_task_plugIn] calendar_db_get_record() Fail!\n"); + _DEBUG_INFO("[task] calendar_db_get_record() Fail!\n"); ret = _convert_service_error_to_common_error(err); *data = 0; } else { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_get() Success!\n"); + _DEBUG_INFO("[task] calendar_svc_get() Success!\n"); *data = (void *)item; } @@ -569,52 +503,45 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_add_folder(int account_id, c retvm_if(folder_name == NULL, SYNC_AGENT_DA_ERR_INVALID_CONTENT, "folder_name is NULL. FAIL !!!"); sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - int err = 0; + int service_ret = CALENDAR_ERROR_NONE; calendar_record_h folder = 0; /* new service struct */ calendar_record_create(_calendar_book._uri, &folder); if (folder == NULL) { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_struct_new() Fail!\n"); + _DEBUG_INFO("[task] calendar_svc_struct_new() Fail!\n"); *folder_id = 0; return SYNC_AGENT_DA_ERRORS; } /* setting folder data */ - int cal_ret = calendar_record_set_int(folder, _calendar_book.account_id, account_id); - if (cal_ret != CALENDAR_ERROR_NONE) { - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } - cal_ret = calendar_record_set_int(folder, _calendar_book.visibility, 1); - if (cal_ret != CALENDAR_ERROR_NONE) { - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } - cal_ret = calendar_record_set_str(folder, _calendar_book.name, folder_name); - if (cal_ret != CALENDAR_ERROR_NONE) { - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + service_ret = calendar_record_set_int(folder, _calendar_book.account_id, account_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_record_set_int() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_int(folder, _calendar_book.visibility, 1); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_record_set_int() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(folder, _calendar_book.name, folder_name); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_record_set_str() Fail!: err[%d]", service_ret); /* add folder */ int service_folder_item_id = 0; - cal_ret = calendar_db_insert_record(folder, &service_folder_item_id); - if (cal_ret != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_insert() Fail!\n"); - ret = _convert_service_error_to_common_error(cal_ret); + service_ret = calendar_db_insert_record(folder, &service_folder_item_id); + if (service_ret != CALENDAR_ERROR_NONE) { + _DEBUG_INFO("[task] calendar_svc_insert() Fail!\n"); *folder_id = 0; } else { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_insert() Success!"); + _DEBUG_INFO("[task] calendar_svc_insert() Success!"); *folder_id = g_strdup_printf("%d", service_folder_item_id); is_storage_changed = 1; } - DACI_FINISH: - /* memory free */ + + return_part: + ret = _convert_service_error_to_common_error(service_ret); if (folder != NULL) { calendar_record_destroy(folder, false); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_destroy() Fail! : err = %d", err); + if (service_ret != CALENDAR_ERROR_NONE) { + _DEBUG_ERROR("calendar_record_destroy() Fail! : service_ret = %d", service_ret); } folder = NULL; } @@ -635,10 +562,10 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_delete_folder(int account_id /* delete folder */ err = calendar_db_delete_record(_calendar_book._uri, atoi(folder_id)); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_task_plugIn] calendar_db_delete_record() Fail, err[%d]", err); + _DEBUG_INFO("[task] calendar_db_delete_record() Fail, err[%d]", err); ret = _convert_service_error_to_common_error(err); } else { - _DEBUG_INFO("[da_task_plugIn] calendar_svc_delete() Success!"); + _DEBUG_INFO("[task] calendar_svc_delete() Success!"); calendar_db_clean_after_sync(atoi(folder_id), 0); is_storage_changed = 1; } @@ -657,24 +584,33 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_get_folder(int account_id, c sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; int err = 0; calendar_record_h folder = 0; - - /* get item */ int task_folder_id = atoi(folder_id); - _DEBUG_INFO("[da_task_plugIn] task_folder_id : %d\n", task_folder_id); + _DEBUG_INFO("[task] task_folder_id : %d\n", task_folder_id); + err = calendar_db_get_record(_calendar_book._uri, task_folder_id, &folder); if (err != CALENDAR_ERROR_NONE) { - _DEBUG_INFO("[da_contact_plugIn] contacts_svc_get_addressbook() Fail!\n"); + _DEBUG_INFO("[task] contacts_svc_get_addressbook() Fail!\n"); ret = _convert_service_error_to_common_error(err); *out_folder_name = 0; *out_folder_type = -1; - } else { - _DEBUG_INFO("[da_contact_plugIn] contacts_svc_get_addressbook() Success!\n"); + goto return_part; + } + + _DEBUG_INFO("[task] contacts_svc_get_addressbook() Success!\n"); + + *out_folder_name = 0; + err = calendar_record_get_str(folder, _calendar_book.name, out_folder_name); + if (err != CALENDAR_ERROR_NONE) { + _DEBUG_INFO("[task] calendar_record_get_str() Fail!\n"); + ret = _convert_service_error_to_common_error(err); *out_folder_name = 0; - calendar_record_get_str(folder, _calendar_book.name, out_folder_name); - *out_folder_type = DEFAULT_CALENDAR_FOLDER; + *out_folder_type = -1; + goto return_part; } - /* memory free */ + *out_folder_type = DEFAULT_CALENDAR_FOLDER; + +return_part: if (folder != NULL) { calendar_record_destroy(folder, false); if (err != CALENDAR_ERROR_NONE) { @@ -683,7 +619,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_get_folder(int account_id, c folder = NULL; } _EXTERN_FUNC_EXIT; - return ret; } @@ -691,7 +626,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_execute(int account_ID, cons { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_task_plugIn] service is not supported execute. \n"); + _DEBUG_INFO("[task] service is not supported execute. \n"); *result = 0; _EXTERN_FUNC_EXIT; @@ -740,10 +675,10 @@ EXPORT_API int sync_agent_plugin_get_used_item_count_for_folder(int account_id, int used_cnt = 0; ret = calendar_db_get_count_with_query(query, &used_cnt); if (ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] calendar_db_get_count() Fail\n"); + _DEBUG_ERROR("[task] calendar_db_get_count() Fail\n"); } else { - _DEBUG_INFO("[da_task_plugIn] calendar_db_get_count() Success\n"); - _DEBUG_INFO("[da_task_plugIn] used_count = %d\n", used_cnt); + _DEBUG_INFO("[task] calendar_db_get_count() Success\n"); + _DEBUG_INFO("[task] used_count = %d\n", used_cnt); } if (filter != NULL) @@ -752,7 +687,6 @@ EXPORT_API int sync_agent_plugin_get_used_item_count_for_folder(int account_id, calendar_query_destroy(query); _EXTERN_FUNC_EXIT; - return used_cnt; } @@ -763,7 +697,6 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold char **folder_id_list = NULL; int count = 0; calendar_list_h service_folder_list = 0; - calendar_record_h folder = NULL; int err = 0; int i = 0; *folder_count = 0; @@ -773,20 +706,15 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold err = _get_service_folder_list_by_account_id(account_id, &service_folder_list, &count); if (err != SYNC_AGENT_DA_SUCCESS || count == 0) { _DEBUG_ERROR("_get_service_folder_list_by_account_id failed !!!"); - return NULL; + folder_id_list = NULL; + goto return_part; } + if (count > 0) { folder_id_list = (char **)calloc(count, sizeof(char *)); if (folder_id_list == NULL) { _DEBUG_ERROR("CALLOC failed !!!"); - if (service_folder_list != NULL) { - err = calendar_list_destroy(service_folder_list, true); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_destroy() Fail! : err = %d", err); - } - service_folder_list = NULL; - } - return NULL; + goto return_part; } *folder_type_list = (int *)calloc(count, sizeof(int)); if (*folder_type_list == NULL) { @@ -795,43 +723,33 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold free(folder_id_list); folder_id_list = NULL; } - if (service_folder_list != NULL) { - err = calendar_list_destroy(service_folder_list, true); - if (err != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_destroy() Fail! : err = %d", err); - } - service_folder_list = NULL; - } - return NULL; + goto return_part; } - /* find */ do { - /* get */ - err = calendar_list_get_current_record_p(service_folder_list, &folder); - if ((err != CALENDAR_ERROR_NONE) && (folder == NULL)) { - _DEBUG_ERROR("calendar_list_get_current_record_p() Fail! : err = %d", err); + int int_folder_id = 0; + calendar_record_h todo = NULL; + err = calendar_record_create(_calendar_todo._uri, &todo); + if ((err != CALENDAR_ERROR_NONE) && (todo == NULL)) { + _DEBUG_ERROR("calendar_record_create() Fail! : err = %d", err); + break; + } + + err = calendar_record_get_int(todo, _calendar_todo.calendar_book_id, &int_folder_id); + if (err != CALENDAR_ERROR_NONE) { + _DEBUG_ERROR("calendar_record_get_int() Fail! : err = %d", err); break; } - /* check */ - int int_folder_id = 0; - err = calendar_record_get_int(folder, _calendar_book.id, &int_folder_id); folder_id_list[i] = g_strdup_printf("%d", int_folder_id); (*folder_type_list)[i] = DEFAULT_CALENDAR_FOLDER; i++; *folder_count = i; - -// if (folder != NULL){ -// calendar_record_destroy(folder, false); -// if (err != CALENDAR_ERROR_NONE) { -// _DEBUG_ERROR("calendar_record_destroy() Fail! : err = %d", err); -// } -// folder = NULL; -// } - } while (calendar_list_next(service_folder_list) != CALENDAR_ERROR_NO_DATA); } + +return_part: + _DEBUG_INFO("return_part"); if (service_folder_list != NULL) { err = calendar_list_destroy(service_folder_list, true); if (err != CALENDAR_ERROR_NONE) { @@ -840,7 +758,6 @@ EXPORT_API char **sync_agent_plugin_get_folder_id_list(int account_id, int *fold service_folder_list = NULL; } _EXTERN_FUNC_EXIT; - return folder_id_list; } @@ -848,7 +765,7 @@ EXPORT_API int *sync_agent_plugin_get_account_id_list(int *count) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_task_plugIn] start!!\n"); + _DEBUG_INFO("[task] start!!\n"); int error_code = account_connect(); @@ -894,7 +811,7 @@ EXPORT_API int *sync_agent_plugin_get_account_id_list(int *count) error_code = account_disconnect(); - _DEBUG_INFO("[da_task_plugIn] end!!\n"); + _DEBUG_INFO("[task] end!!\n"); _EXTERN_FUNC_EXIT; @@ -905,14 +822,13 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_task_plugIn] account_id : %d\n", account_id); - _DEBUG_INFO("[da_task_plugIn] folder_id : %s\n", folder_id); - _DEBUG_INFO("[da_task_plugIn] changepoint : %d\n", changepoint); - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + _DEBUG_INFO("[task] account_id : %d\n", account_id); + _DEBUG_INFO("[task] folder_id : %s\n", folder_id); + _DEBUG_INFO("[task] changepoint : %d\n", changepoint); int taskTimeStamp = changepoint; int current_change_point = 0; int temp_folder_id = atoi(folder_id); - int service_ret = 0; + int service_ret = CALENDAR_ERROR_NONE; sync_agent_plugin_item_node_s *root_ptr = 0; sync_agent_plugin_item_node_s *cursor_ptr = 0; @@ -922,45 +838,27 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for calendar_record_h changed_task = NULL; service_ret = calendar_db_get_changes_by_version(_calendar_todo._uri, temp_folder_id, taskTimeStamp, &service_changed_list, ¤t_change_point); - _DEBUG_INFO("[da_task_plugIn] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); - if ((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL)) { - _DEBUG_ERROR("calendar_db_get_changes_by_version() Fail! : err = %d", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + _DEBUG_INFO("[task] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); + goto_if((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL), "[task] calendar_db_get_changes_by_version() Fail!: err[%d]", service_ret); int list_count = 0; service_ret = calendar_list_get_count(service_changed_list, &list_count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_get_count() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_task_plugIn] in calendar_list_get_count [%d]!", list_count); + _DEBUG_INFO("[task] in calendar_list_get_count [%d]!", list_count); if (list_count <= 0) { -// ret =SYNC_AGENT_DA_ERR_NO_DATA; - goto DACI_FINISH; - } -// service_ret = calendar_svc_iter_next(iter); - service_ret = calendar_list_first(service_changed_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_first() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; + goto return_part; } - _DEBUG_INFO("[da_task_plugIn] calendar_svc_iter_next service_ret : %d\n", service_ret); + service_ret = calendar_list_first(service_changed_list); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_first() Fail!: err[%d]", service_ret); do { _DEBUG_INFO("while start"); service_ret = calendar_list_get_current_record_p(service_changed_list, &changed_task); - if ((service_ret != CALENDAR_ERROR_NONE) && (changed_task == NULL)) { - _DEBUG_ERROR("calendar_list_get_current_record_p() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) && (changed_task == NULL), "[task] calendar_list_get_current_record_p() Fail!: err[%d]", service_ret); + int type = 0; service_ret = calendar_record_get_int(changed_task, _calendar_updated_info.modified_status, &type); if (service_ret != CALENDAR_ERROR_NONE) { @@ -968,7 +866,7 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for break; } - _DEBUG_INFO("[da_task_plugIn] type is [%d]", type); + _DEBUG_INFO("[task] type is [%d]", type); if (type == CALENDAR_EVENT_MODIFIED_STATUS_INSERTED) { int task_id = 0; service_ret = calendar_record_get_int(changed_task, _calendar_updated_info.id, &task_id); @@ -976,14 +874,18 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for _DEBUG_ERROR("calendar_record_get_int() Fail!: err = %d", service_ret); break; } - _DEBUG_INFO("[da_task_plugIn] calendar id is [%d]", task_id); + _DEBUG_INFO("[task] calendar id is [%d]", task_id); char *task_id_str = g_strdup_printf("%d", task_id); - _DEBUG_INFO("[da_task_plugIn] CALS_UPDATED_TYPE_INSERTED : [%s]\n", task_id_str); + _DEBUG_INFO("[task] CALS_UPDATED_TYPE_INSERTED : [%s]\n", task_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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } return NULL; } root_ptr->item_id = task_id_str; @@ -993,6 +895,14 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for 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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } + if (root_ptr) { + free(root_ptr); + root_ptr = NULL; + } return NULL; } cursor_ptr->next->item_id = task_id_str; @@ -1003,14 +913,9 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for chagned_count++; } - - /*if list can successfully free child than dont need this free */ -// if (changed_task != NULL) -// calendar_record_destroy(changed_task, true); } while (calendar_list_next(service_changed_list) != CALENDAR_ERROR_NO_DATA); - DACI_FINISH: - + return_part: if (service_changed_list != NULL) { calendar_list_destroy(service_changed_list, true); service_changed_list = NULL; @@ -1019,7 +924,6 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for *changeCount = chagned_count; _EXTERN_FUNC_EXIT; - return root_ptr; } @@ -1027,14 +931,14 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[da_task_plugIn] account_id : %d\n", account_id); - _DEBUG_INFO("[da_task_plugIn] folder_id : %s\n", folder_id); - _DEBUG_INFO("[da_task_plugIn] changepoint : %d\n", change_point); + _DEBUG_INFO("[task] account_id : %d\n", account_id); + _DEBUG_INFO("[task] folder_id : %s\n", folder_id); + _DEBUG_INFO("[task] changepoint : %d\n", change_point); int current_change_point = 0; int task_time_stamp = change_point; int temp_folder_id = atoi(folder_id); - int service_ret = 0; - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + int service_ret = CALENDAR_ERROR_NONE; + sync_agent_plugin_item_node_s *root_ptr = 0; sync_agent_plugin_item_node_s *cursor_ptr = 0; int chagned_count = 0; @@ -1043,42 +947,25 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for calendar_record_h changed_task = NULL; service_ret = calendar_db_get_changes_by_version(_calendar_todo._uri, temp_folder_id, task_time_stamp, &service_changed_list, ¤t_change_point); - _DEBUG_INFO("[da_task_plugIn] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); - if ((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL)) { - _DEBUG_ERROR("calendar_db_get_changes_by_version() Fail! : err = %d", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + _DEBUG_INFO("[task] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); + goto_if((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL), "[task] calendar_db_get_changes_by_version() Fail!: err[%d]", service_ret); int list_count = 0; service_ret = calendar_list_get_count(service_changed_list, &list_count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_get_count() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_task_plugIn] in calendar_list_get_count [%d]!", list_count); + _DEBUG_INFO("[task] in calendar_list_get_count [%d]!", list_count); if (list_count <= 0) { - goto DACI_FINISH; + goto return_part; } service_ret = calendar_list_first(service_changed_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_first() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } - _DEBUG_INFO("[da_task_plugIn] service_ret : %d\n", service_ret); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_first() Fail!: err[%d]", service_ret); do { service_ret = calendar_list_get_current_record_p(service_changed_list, &changed_task); - if ((service_ret != CALENDAR_ERROR_NONE) && (changed_task == NULL)) { - _DEBUG_ERROR("calendar_list_get_current_record_p() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) && (changed_task == NULL), "[task] calendar_list_get_current_record_p() Fail!: err[%d]", service_ret); int type = 0; service_ret = calendar_record_get_int(changed_task, _calendar_updated_info.modified_status, &type); @@ -1094,12 +981,16 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for break; } char *task_id_str = g_strdup_printf("%d", task_id); - _DEBUG_INFO("[da_task_plugIn] CALS_UPDATED_TYPE_DELETED : [%s]\n", task_id_str); + _DEBUG_INFO("[task] CALS_UPDATED_TYPE_DELETED : [%s]\n", task_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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } return NULL; } root_ptr->item_id = task_id_str; @@ -1109,6 +1000,14 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for 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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } + if (root_ptr) { + free(root_ptr); + root_ptr = NULL; + } return NULL; } cursor_ptr->next->item_id = task_id_str; @@ -1118,23 +1017,15 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for chagned_count++; } - - /*if list can successfully free child than dont need this free */ -// if (changed_task != NULL) -// calendar_record_destroy(changed_task, true); } while (calendar_list_next(service_changed_list) != CALENDAR_ERROR_NO_DATA); - DACI_FINISH: - + return_part: if (service_changed_list != NULL) { calendar_list_destroy(service_changed_list, true); service_changed_list = NULL; } - *change_count = chagned_count; - _EXTERN_FUNC_EXIT; - return root_ptr; } @@ -1142,58 +1033,41 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("\n[da_task_plugIn] account_id : %d\n", account_id); - _DEBUG_INFO("[da_task_plugIn] folder_id : %s\n", folder_id); - _DEBUG_INFO("[da_task_plugIn] changepoint : %d\n", change_point); - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + _DEBUG_INFO("\n[task] account_id : %d\n", account_id); + _DEBUG_INFO("[task] folder_id : %s\n", folder_id); + _DEBUG_INFO("[task] changepoint : %d\n", change_point); + int task_time_stamp = change_point; int temp_folder_id = atoi(folder_id); - int service_ret = 0; + int service_ret = CALENDAR_ERROR_NONE; calendar_list_h service_changed_list = 0; calendar_record_h changed_task = NULL; - sync_agent_plugin_item_node_s *root_ptr = 0; - sync_agent_plugin_item_node_s *cursor_ptr = 0; + sync_agent_plugin_item_node_s *root_ptr = NULL; + sync_agent_plugin_item_node_s *cursor_ptr = NULL; int chagned_count = 0; int current_change_point = 0; service_ret = calendar_db_get_changes_by_version(_calendar_todo._uri, temp_folder_id, task_time_stamp, &service_changed_list, ¤t_change_point); - _DEBUG_INFO("[da_task_plugIn] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); - if ((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL)) { - _DEBUG_ERROR("calendar_db_get_changes_by_version() Fail! : err = %d", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + _DEBUG_INFO("[task] calendar_db_get_changes_by_version service_ret : %d, input folder id [%d], current change point [%d]", service_ret, temp_folder_id, current_change_point); + goto_if((service_ret != CALENDAR_ERROR_NONE) && (service_changed_list == NULL), "[task] calendar_db_get_changes_by_version() Fail!: err[%d]", service_ret); int list_count = 0; service_ret = calendar_list_get_count(service_changed_list, &list_count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[da_task_plugIn] in calendar_list_get_count Fail!\n"); - ret = _convert_service_error_to_common_error(service_ret); - goto DACI_FINISH; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_get_count() Fail!: err[%d]", service_ret); - _DEBUG_INFO("[da_task_plugIn] in calendar_list_get_count [%d]!", list_count); + _DEBUG_INFO("[task] in calendar_list_get_count [%d]!", list_count); if (list_count <= 0) { - goto DACI_FINISH; + goto return_part; } service_ret = calendar_list_first(service_changed_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_first() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } - - _DEBUG_INFO("[da_task_plugIn] service_ret : %d\n", service_ret); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[task] calendar_list_first() Fail!: err[%d]", service_ret); do { service_ret = calendar_list_get_current_record_p(service_changed_list, &changed_task); - if ((service_ret != CALENDAR_ERROR_NONE) && (changed_task == NULL)) { - _DEBUG_ERROR("calendar_list_get_current_record_p() Fail! : err = %d", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto DACI_FINISH; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) && (changed_task == NULL), "[task] calendar_list_get_current_record_p() Fail!: err[%d]", service_ret); + int type = 0; service_ret = calendar_record_get_int(changed_task, _calendar_updated_info.modified_status, &type); if (service_ret != CALENDAR_ERROR_NONE) { @@ -1209,47 +1083,51 @@ EXPORT_API sync_agent_plugin_item_node_s *sync_agent_plugin_get_changed_item_for break; } char *task_id_str = g_strdup_printf("%d", task_id); - _DEBUG_INFO("[da_task_plugIn] CALS_UPDATED_TYPE_MODIFIED : [%s]\n", task_id_str); + _DEBUG_INFO("[task] CALS_UPDATED_TYPE_MODIFIED : [%s]\n", task_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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } return NULL; } root_ptr->item_id = task_id_str; - root_ptr->next = 0; + root_ptr->next = NULL; 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 !!!"); + if (service_changed_list != NULL) { + calendar_list_destroy(service_changed_list, true); + service_changed_list = NULL; + } + if (root_ptr) { + free(root_ptr); + root_ptr = NULL; + } return NULL; } cursor_ptr->next->item_id = task_id_str; - cursor_ptr->next->next = 0; + cursor_ptr->next->next = NULL; cursor_ptr = cursor_ptr->next; } chagned_count++; } - - /*if list can successfully free child than dont need this free */ -// if (changed_task != NULL) -// calendar_record_destroy(changed_task, true); } while (calendar_list_next(service_changed_list) != CALENDAR_ERROR_NO_DATA); - DACI_FINISH: - + return_part: if (service_changed_list != NULL) { calendar_list_destroy(service_changed_list, true); service_changed_list = NULL; } - *change_count = chagned_count; - _EXTERN_FUNC_EXIT; - return root_ptr; } @@ -1323,6 +1201,13 @@ EXPORT_API void sync_agent_plugin_set_callback_get_account_id_list(sync_agent_ge _EXTERN_FUNC_EXIT; } +EXPORT_API void sync_agent_plugin_set_callback_delete_child_item(sync_agent_del_child_item_cb_plugin callback) +{ + _EXTERN_FUNC_ENTER; + callback_delete_child_item = callback; + _EXTERN_FUNC_EXIT; +} + EXPORT_API int sync_agent_plugin_get_max_item_count(int folder_type) { _EXTERN_FUNC_ENTER; @@ -1492,13 +1377,13 @@ static void _set_is_noti_from_me(int set_flag) _INNER_FUNC_ENTER; if (pthread_mutex_lock(&lockx)) { - _DEBUG_ERROR("[da_task_plugIn] pthread_mutex_lock error"); + _DEBUG_ERROR("[task] pthread_mutex_lock error"); } is_noti_from_me = set_flag; if (pthread_mutex_unlock(&lockx)) { - _DEBUG_ERROR("[da_task_plugIn] pthread_mutex_unlock error"); + _DEBUG_ERROR("[task] pthread_mutex_unlock error"); } _INNER_FUNC_EXIT; @@ -1517,12 +1402,12 @@ void _process_task_change(const char *view_uri, void *user_data) { _INNER_FUNC_ENTER; - _DEBUG_TRACE("[da_task_plugIn] detected task storage changed\n"); + _DEBUG_TRACE("[task] detected task storage changed\n"); int from_Me = __get_is_noti_from_me(); if (from_Me == 1) { _set_is_noti_from_me(0); - _DEBUG_TRACE("[da_task_plugIn] This noti is from Me!! so will be ignored!!\n"); + _DEBUG_TRACE("[task] This noti is from Me!! so will be ignored!!\n"); return; } @@ -1538,6 +1423,12 @@ void _process_task_change(const char *view_uri, void *user_data) if (sync_agent_async_queue_length(queue) < 1) { sync_agent_send_msg_async_queue(queue, (void *)taskVersion); _DEBUG_INFO("fw_async_queue_length = %d", sync_agent_async_queue_length(queue)); + } else { + _DEBUG_INFO("send_msg_failed... sync_agent_async_queue_length(queue) >= 1"); + if(taskVersion != NULL) { + free(taskVersion); + taskVersion = NULL; + } } _INNER_FUNC_EXIT; @@ -1547,7 +1438,7 @@ static void *_rutine_task_change(void *data) { _INNER_FUNC_ENTER; - _DEBUG_TRACE("[da_task_plugIn] Start __rutine_task_Change (create thread)\n"); + _DEBUG_TRACE("[task] Start __rutine_task_Change (create thread)\n"); /* * Create Queue @@ -1581,8 +1472,8 @@ static void *_rutine_task_change(void *data) int i = 0; for (; i < account_list_count; i++) { int task_account_id = account_list[i]; - _DEBUG_TRACE("[da_task_plugIn] task_account_id : %d, count : %d\n", task_account_id, account_list_count); - _DEBUG_TRACE("[da_task_plugIn] Before calendar_svc_event_get_changes : %d\n", task_version); + _DEBUG_TRACE("[task] task_account_id : %d, count : %d\n", task_account_id, account_list_count); + _DEBUG_TRACE("[task] Before calendar_svc_event_get_changes : %d\n", task_version); /*get folder id */ int folder_list_count = 0; @@ -1591,7 +1482,7 @@ static void *_rutine_task_change(void *data) _DEBUG_ERROR("calendar_list_get_count() Fail! : err = %d", service_ret); break; } - _DEBUG_TRACE("[da_task_plugIn] folder_list_count : %d", folder_list_count); + _DEBUG_TRACE("[task] folder_list_count : %d", folder_list_count); do { @@ -1664,43 +1555,36 @@ static void *_rutine_task_change(void *data) char task_folder_id_str[12]; snprintf(task_folder_id_str, sizeof(task_folder_id_str), "%d", task_folder_id); - _DEBUG_TRACE("[da_task_plugIn] task Inserted!\n"); - _DEBUG_TRACE("[da_task_plugIn] task folder id : %s\n", task_folder_id_str); - int result = callback_add_item(account_list[i], i, task_id_str, FW_TASK, task_folder_id_str, 0); + _DEBUG_TRACE("[task] task Inserted!\n"); + _DEBUG_TRACE("[task] task folder id : %s\n", task_folder_id_str); + int result = callback_add_item(account_list[i], i, task_id_str, NULL, FW_TASK, task_folder_id_str, 0); if (!result) - _DEBUG_TRACE("[da_task_plugIn] Failed to call SA_EH_Add_Item() \n"); + _DEBUG_TRACE("[task] Failed to call SA_EH_Add_Item() \n"); else - _DEBUG_TRACE("[da_task_plugIn] Success to call SA_EH_Add_Item() \n"); + _DEBUG_TRACE("[task] Success to call SA_EH_Add_Item() \n"); } break; case CALENDAR_EVENT_MODIFIED_STATUS_UPDATED: { - _DEBUG_TRACE("[da_task_plugIn] task Updated!\n"); - int result = callback_update_item(account_list[i], i, task_id_str, FW_TASK); + _DEBUG_TRACE("[task] task Updated!\n"); + int result = callback_update_item(account_list[i], i, task_id_str, NULL, FW_TASK); if (!result) - _DEBUG_TRACE("[da_task_plugIn] Failed to call callback_del_item() \n"); + _DEBUG_TRACE("[task] Failed to call callback_del_item() \n"); } break; case CALENDAR_EVENT_MODIFIED_STATUS_DELETED: { - _DEBUG_TRACE("[da_task_plugIn] task Deleted!\n"); + _DEBUG_TRACE("[task] task Deleted!\n"); int result = callback_del_item(account_list[i], i, task_id_str, FW_TASK); if (!result) - _DEBUG_TRACE("[da_task_plugIn] Failed to call callback_del_item() \n"); + _DEBUG_TRACE("[task] Failed to call callback_del_item() \n"); } break; default: - _DEBUG_TRACE("[da_task_plugIn] cached Another task Change Noti!\n"); + _DEBUG_TRACE("[task] cached Another task Change Noti!\n"); break; } - - /*if list can successfully free child than dont need this free */ -// if (row_event != NULL){ -// calendar_record_destroy(row_event, true); -// row_event = NULL; -// } - } while (calendar_list_next(record_list) != CALENDAR_ERROR_NO_DATA); if (record_list != NULL) { @@ -1710,13 +1594,7 @@ static void *_rutine_task_change(void *data) } record_list = NULL; } - /*if list can successfully free child than dont need this free */ -// if (folder != NULL){ -// calendar_record_destroy(folder, true); -// folder = NULL; -// } - - } while (calendar_list_next(folder_list) != CALENDAR_ERROR_NO_DATA); /*folder iter list */ + } while (calendar_list_next(folder_list) != CALENDAR_ERROR_NO_DATA); _DEBUG_TRACE("folder list free"); if (folder_list != NULL) { @@ -1727,21 +1605,17 @@ static void *_rutine_task_change(void *data) folder_list = NULL; } - } /*account loop for */ + } _DEBUG_TRACE("account list free"); if (account_list != NULL) { free(account_list); } - } /*while (1) */ + } - // close calendar service sync_agent_plugin_close_service(); - - _DEBUG_TRACE("[da_task_plugIn] End __rutine_task_Change (create thread)\n"); - + _DEBUG_TRACE("[task] End __rutine_task_Change (create thread)\n"); _INNER_FUNC_EXIT; - return 0; } @@ -1750,9 +1624,13 @@ static sync_agent_da_return_e _convert_service_error_to_common_error(int err) _INNER_FUNC_ENTER; sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - _DEBUG_TRACE("[da_task_plugIn] Error Code : %d\n", err); + _DEBUG_TRACE("[task] Error Code : %d\n", err); switch (err) { + case CALENDAR_ERROR_NONE: + ret = SYNC_AGENT_DA_SUCCESS; + break; + case CALENDAR_ERROR_INVALID_PARAMETER: /* -4 */ ret = SYNC_AGENT_DA_ERR_INVALID_CONTENT; break; @@ -1763,7 +1641,6 @@ static sync_agent_da_return_e _convert_service_error_to_common_error(int err) } _INNER_FUNC_EXIT; - return ret; } diff --git a/src/fw-plugins/common-public/vcalendar-task/include/vcalendar_string_util.h b/src/fw-plugins/common-public/vcalendar-task/include/vcalendar_string_util.h index 8441d1e..ecb30f1 100755 --- a/src/fw-plugins/common-public/vcalendar-task/include/vcalendar_string_util.h +++ b/src/fw-plugins/common-public/vcalendar-task/include/vcalendar_string_util.h @@ -33,16 +33,16 @@ #include "utility/sync_util.h" -typedef enum cal_date_type { - CALENDAR_DATE_TYPE_ONTIME = 0, - CALENDAR_DATE_TYPE_YEAR, - CALENDAR_DATE_TYPE_MONTH, - CALENDAR_DATE_TYPE_WEEK, - CALENDAR_DATE_TYPE_DAY, - CALENDAR_DATE_TYPE_HOUR, - CALENDAR_DATE_TYPE_MINUTE, - CALENDAR_DATE_TYPE_SECOND, -} calendar_date_type_e; +typedef enum task_date_type { + TASK_DATE_TYPE_ONTIME = 0, + TASK_DATE_TYPE_YEAR, + TASK_DATE_TYPE_MONTH, + TASK_DATE_TYPE_WEEK, + TASK_DATE_TYPE_DAY, + TASK_DATE_TYPE_HOUR, + TASK_DATE_TYPE_MINUTE, + TASK_DATE_TYPE_SECOND, +} task_date_type_e; #define RRULE_KEYWORD "\r\nRRULE:" #define RRULE_KEYWORD_FREQ_DAILY "\r\nRRULE:FREQ=DAILY" @@ -55,18 +55,26 @@ typedef enum cal_date_type { #define RRULE_KEYWORD_BYMONTHDAY "BYMONTHDAY=" #define RRULE_KEYWORD_UNTIL "UNTIL=" #define RRULE_KEYWORD_COUNT "COUNT=" -#define DTSTART_KEYWORD "\r\nDTSTART" +#define DTSTART_KEYWORD "\r\nDTSTART:" #define DTEND_KEYWORD "\r\nDTEND" #define BEGIN_ALARM_KEYWORD "\r\nBEGIN:VALARM" +#define AALARM_KEYWORD "\r\nAALARM:" #define END_VTODO_KEYWORD "\r\nEND:VTODO\r\n" #define DUEDATE_KEYWORD "\r\nDUE:" -#define MAX_RRULE_DATE_KEYWORD "20361231T000000Z" +#define MAX_RRULE_DATE_KEYWORD "20361231T" #define MAX_DUE_DATE_KEYWORD "\r\nDUE:20381231T000000Z\r\n" // refer to calendar info (min ~ max date) +#define MAX_MOBEX_DTSTART_KEYWORD "\r\nDTSTART:20370101T090000Z" +#define MAX_CALENDAR_DTSTART_KEYWORD "\r\nDTSTART:20381231T000000Z" +#define WEEKDAY_RRULE_ORIGIN_KEYWORD "\r\nRRULE:W0 " +#define WEEKDAY_RRULE_CONVERTED_KEYWORD "\r\nRRULE:W1 MO TU WE TH FR " +#define TIMEZONE_GMT "Etc/GMT" #define CALENDAR_IMAGE_KEYWORD_SNOTE "snote" // refer to Cal-svc.h (calendar\include) #define CALENDAR_IMAGE_KEYWORD_PHOTO "photo" // refer to Cal-svc.h (calendar\include) -#define IMAGE_KEYWORD_PREFIX_SNOTE "\r\nX-SS-ATTACH-SNOTE;" -#define IMAGE_KEYWORD_PREFIX_PHOTO "\r\nX-SS-ATTACH-IMAGE;" +#define IMAGE_KEYWORD_PREFIX_SNOTE "X-SS-ATTACH-SNOTE;" +#define IMAGE_KEYWORD_PREFIX_PHOTO "X-SS-ATTACH-IMAGE;" +#define CR_IMAGE_KEYWORD_PREFIX_SNOTE "\r\nX-SS-ATTACH-SNOTE;" +#define CR_IMAGE_KEYWORD_PREFIX_PHOTO "\r\nX-SS-ATTACH-IMAGE;" #define IMAGE_KEYWORD_BEGIN_PATH "PATH=3D" #define IMAGE_KEYWORD_END_PATH "=3bDATE=3D\r\n" @@ -78,11 +86,13 @@ typedef enum cal_date_type { char * get_value_by_token(const char *src, const char *token, const char *end_of_token); char * replace_string(char *origin, const char *src, const char *dest); -char * remove_timezone(char *origin); +long long int get_unix_time(char *str_time); +void set_timezone(const char *origin, calendar_record_h cal_record); +void process_no_due_date(const char *origin, calendar_record_h cal_record); void insert_allday_data(const char *origin, calendar_record_h calendar_record); char * has_image_import(const char *origin); char * has_image_export(calendar_record_h cal_record); -char * replace_max_rrule_data(char *origin); +char * replace_rrule_data(char *origin); char * replace_image_data(char *origin, char *image_path); char * replace_priority_data(char *origin, bool is_phone_to_kies); diff --git a/src/fw-plugins/common-public/vcalendar-task/src/plugin_interface.c b/src/fw-plugins/common-public/vcalendar-task/src/plugin_interface.c index 182d7e6..b9f3c93 100755 --- a/src/fw-plugins/common-public/vcalendar-task/src/plugin_interface.c +++ b/src/fw-plugins/common-public/vcalendar-task/src/plugin_interface.c @@ -62,7 +62,6 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_ // 1. priority converting : it should be excuted before calendar_vcalendar_parse_to_calendar if (strstr(temp_agent_data, "\r\nPRIORITY:") != NULL) { - _DEBUG_INFO("priority is founed"); temp = strdup(temp_agent_data); temp = replace_priority_data(temp, false); temp_agent_data = temp; @@ -71,43 +70,34 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_ // 2. if the vcalendar has until : NONE rrule, then max rrule should be converted : it should be excuted before calendar_vcalendar_parse_to_calendar if (strstr(temp_agent_data, RRULE_KEYWORD) != NULL) { temp = strdup(temp_agent_data); - temp_agent_data = replace_max_rrule_data(temp); + temp_agent_data = replace_rrule_data(temp); temp = NULL; } service_ret = calendar_vcalendar_parse_to_calendar(temp_agent_data, &calendar_list); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret); ret = _convert_service_error_to_common_error(service_ret); *service_data = NULL; } if (calendar_list == NULL) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_vcalendar_parse_to_calendar() -> temp_service_data is null, err[%d] !!", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_vcalendar_parse_to_calendar() -> temp_service_data is null, err[%d] !!", service_ret); ret = SYNC_AGENT_DA_ERRORS; goto return_part; } service_ret = calendar_list_first(calendar_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_list_first() Fail! : err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_list_first() Fail!: err[%d]", service_ret); do { char *uri = NULL; service_ret = calendar_list_get_current_record_p(calendar_list, &temp_service_data); - if ((service_ret != CALENDAR_ERROR_NONE) || (temp_service_data == NULL)) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_list_get_current_record_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) || (temp_service_data == NULL), "[vcalendar-task] calendar_list_get_current_record_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_uri_p(temp_service_data, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_uri_p() Fail!: err[%d]", service_ret); if (!strncmp(uri, _calendar_todo._uri, strlen(_calendar_todo._uri))) { _DEBUG_INFO("this is todo"); @@ -123,106 +113,48 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_ } while(calendar_list_next(calendar_list) != CALENDAR_ERROR_NO_DATA); // 1. timezone setting : it should be excuted after calendar_vcalendar_parse_to_calendar - service_ret = calendar_record_set_str(temp_service_data, _calendar_todo.start_tzid, "Asia/Seoul"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - /*i think when set return fail then going throw input schedule */ - } - - service_ret = calendar_record_set_str(temp_service_data, _calendar_todo.due_tzid, "Asia/Seoul"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - /*i think when set return fail then going throw input schedule */ - } + set_timezone(temp_agent_data, temp_service_data); // 2. "no due date" setting : it should be excuted after calendar_vcalendar_parse_to_calendar - if (strstr((char *)temp_agent_data, MAX_DUE_DATE_KEYWORD) != NULL) { - _DEBUG_INFO("no due date setting"); - - calendar_time_s cal_time_end = { 0, }; - service_ret = calendar_record_get_caltime(temp_service_data, _calendar_todo.due_time, &cal_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } - - cal_time_end.type = CALENDAR_TIME_UTIME; - cal_time_end.time.utime = CALENDAR_TODO_NO_DUE_DATE; - service_ret = calendar_record_set_caltime(temp_service_data, _calendar_todo.due_time, cal_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } - } + process_no_due_date(temp_agent_data, temp_service_data); // 3. add image info : it should be excuted after calendar_vcalendar_parse_to_calendar if( image_path != NULL ) { _DEBUG_INFO("image is founded. %s", image_path); - - ///////////////////////////////////// S Note temporary code //////////////////////////// + ///////////////////////////////////// S Note //////////////////////////// if (strstr(image_path, "=\r\n") != NULL) { - temp_image_path = get_value_by_token(image_path, "/opt/usr/apps/com.samsung.smemo/data/", "=\r\n"); + temp_image_path = get_value_by_token(image_path, SNOTE_MEMORY_ORIGIN, "=\r\n"); _DEBUG_INFO("temp_image_path = %s", temp_image_path); - token = (char *)calloc(1000, sizeof(char)); - if (token == NULL) { - _DEBUG_ERROR("token calloc() is failed"); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } - - snprintf(token, 1000, "%s=\r\n", temp_image_path); - _DEBUG_INFO("token = %s", token); + token = g_strdup_printf("%s=\r\n", temp_image_path); + goto_if(token == NULL, "token is NULL"); temp = get_value_by_token(image_path, token, ".png"); - if (image_path) { free(image_path); image_path = NULL; } - image_path = (char *)calloc(1000, sizeof(char)); - if (image_path == NULL) { - _DEBUG_ERROR("image_path is null"); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } - - snprintf(image_path, 1000, "/opt/usr/apps/com.samsung.smemo/data/%s%s.png", temp_image_path, temp); + image_path = g_strdup_printf("%s%s%s.png", SNOTE_MEMORY_ORIGIN, temp_image_path, temp); + goto_if(image_path == NULL, "image_path is NULL"); _DEBUG_INFO("image_path = %s", image_path); } - ///////////////////////////////////// S Note temporary code //////////////////////////// + ///////////////////////////////////// S Note //////////////////////////// calendar_record_h image_record = NULL; - service_ret = calendar_record_create(_calendar_extended_property._uri, &image_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_create() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(image_record, _calendar_extended_property.key, CALENDAR_IMAGE_KEYWORD_PHOTO); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(image_record, _calendar_extended_property.value, image_path); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail!: err[%d]", service_ret); service_ret = calendar_record_add_child_record(temp_service_data, _calendar_todo.extended, image_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_add_child_record() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_add_child_record() Fail!: err[%d]", service_ret); } *service_data = (void *)temp_service_data; - _DEBUG_INFO("calendar_vcalendar_parse_to_calendar() Success!\n"); return_part: _DEBUG_INFO("return part"); @@ -251,6 +183,7 @@ return_part: temp = NULL; } + ret = _convert_service_error_to_common_error(service_ret); _EXTERN_FUNC_EXIT; return ret; } @@ -267,89 +200,52 @@ sync_agent_da_return_e _vtodo_merge_new_to_old(calendar_record_h old_service_dat /*priority */ int priority = 0; service_ret = calendar_record_get_int(new_service_data, _calendar_todo.priority, &priority); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - _DEBUG_INFO("priority= %d", priority); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_int(old_service_data, _calendar_todo.priority, priority); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_int() Fail!: err[%d]", service_ret); /*description */ char *description = 0; service_ret = calendar_record_get_str_p(new_service_data, _calendar_todo.description, &description); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - _DEBUG_INFO("description = %s", description); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_str_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(old_service_data, _calendar_todo.description, description); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail!: err[%d]", service_ret); /*start time */ calendar_time_s task_time_start = { 0, }; service_ret = calendar_record_get_caltime(new_service_data, _calendar_todo.start_time, &task_time_start); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_caltime() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_caltime() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_caltime(old_service_data, _calendar_todo.start_time, task_time_start); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_caltime() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_caltime() Fail!: err[%d]", service_ret); /*end time */ calendar_time_s task_time_end = { 0, }; service_ret = calendar_record_get_caltime(new_service_data, _calendar_todo.due_time, &task_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_caltime() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_caltime() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_caltime(old_service_data, _calendar_todo.due_time, task_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_caltime() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_caltime() Fail!: err[%d]", service_ret); /* summary */ char *summary = 0; service_ret = calendar_record_get_str_p(new_service_data, _calendar_todo.summary, &summary); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_str_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(old_service_data, _calendar_todo.summary, summary); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail!: err[%d]", service_ret); /* location */ char *location = 0; service_ret = calendar_record_get_str_p(new_service_data, _calendar_todo.location, &location); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_str_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(old_service_data, _calendar_todo.location, location); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail!: err[%d]", service_ret); +#if 0 /* rrule */ int num; char *text = NULL; @@ -357,168 +253,169 @@ sync_agent_da_return_e _vtodo_merge_new_to_old(calendar_record_h old_service_dat service_ret = calendar_record_get_int(new_service_data, _calendar_todo.freq, &num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(freq) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_int(freq) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_int(old_service_data, _calendar_todo.freq, num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(freq) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_int(freq) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_int(new_service_data, _calendar_todo.range_type, &num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(range_type) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_int(range_type) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_int(old_service_data, _calendar_todo.range_type, num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(range_type) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_int(range_type) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_caltime(new_service_data, _calendar_todo.until_time, &caltime); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_caltime(until_time) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_caltime(until_time) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_caltime(old_service_data, _calendar_todo.until_time, caltime); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_caltime(until_time) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_caltime(until_time) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_int(new_service_data, _calendar_todo.count, &num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(count) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_int(count) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_int(old_service_data, _calendar_todo.count, num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(count) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_int(count) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_int(new_service_data, _calendar_todo.interval, &num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(interval) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_int(interval) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_int(old_service_data, _calendar_todo.interval, num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(interval) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_int(interval) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.bysecond, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(bysecond) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(bysecond) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.bysecond, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(bysecond) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(bysecond) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byminute, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byminute) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(byminute) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byminute, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byminute) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(byminute) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byhour, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byhour) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(byhour) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byhour, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byhour) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(byhour) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byday, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byday) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(byday) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byday, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byday) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(byday) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.bymonthday, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(bymonthday) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(bymonthday) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.bymonthday, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(bymonthday) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(bymonthday) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byyearday, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byyearday) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(byyearday) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byyearday, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byyearday) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(byyearday) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.byweekno, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(byweekno) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(byweekno) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.byweekno, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(byweekno) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(byweekno) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.bymonth, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(bymonth) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(bymonth) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.bymonth, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(bymonth) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(bymonth) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_str(new_service_data, _calendar_todo.bysetpos, &text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(bysetpos) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_str(bysetpos) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_str(old_service_data, _calendar_todo.bysetpos, text); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(bysetpos) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_str(bysetpos) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_get_int(new_service_data, _calendar_todo.wkst, &num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(wkst) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_get_int(wkst) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_int(old_service_data, _calendar_todo.wkst, num); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(wkst) Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_int(wkst) Fail! err[%d]\n", service_ret); return SYNC_AGENT_DA_ERRORS; } +#endif /* alarm */ calendar_record_h new_alarm_record = NULL; @@ -533,149 +430,91 @@ sync_agent_da_return_e _vtodo_merge_new_to_old(calendar_record_h old_service_dat description = NULL; service_ret = calendar_record_get_int(new_service_data, _calendar_todo.has_alarm, &new_data_has_alarm); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(has_alarm) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_int() Fail!: err[%d]", service_ret); _DEBUG_INFO("new_data_has_alarm = %d", new_data_has_alarm); service_ret = calendar_record_get_int(old_service_data, _calendar_todo.has_alarm, &old_data_has_alarm); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(has_alarm) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_int() Fail!: err[%d]", service_ret); _DEBUG_INFO("old_data_has_alarm = %d", old_data_has_alarm); if (new_data_has_alarm == 0 && old_data_has_alarm == 1) { _DEBUG_INFO("alarm record shoud be deleted"); service_ret = calendar_record_get_child_record_at_p(old_service_data, _calendar_todo.calendar_alarm, 0, &old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_child_record_at_p() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_remove_child_record(old_service_data, _calendar_todo.calendar_alarm, old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_remove_child_record() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_remove_child_record() Fail!: err[%d]", service_ret); } else if (new_data_has_alarm == 1) { service_ret = calendar_record_get_child_record_at_p(new_service_data, _calendar_todo.calendar_alarm, 0, &new_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_child_record_at_p(_calendar_todo.calendar_alarm) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.type, &type); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(type) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_lli(new_alarm_record, _calendar_alarm.time, &alarm_time.time.utime); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(time) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_lli() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.tick, &tick); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(tick) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.tick_unit, &tick_unit); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(tick_unit) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_str(new_alarm_record, _calendar_alarm.description, &description); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str(description) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_str() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.alarm_id, &alarm_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_int(alarm_id) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_int() Fail!: err[%d]", service_ret); if (old_data_has_alarm == 0) { _DEBUG_INFO("alarm record should be created"); service_ret = calendar_record_create(_calendar_alarm._uri, &old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_create Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_create() Fail!: err[%d]", service_ret); } else if (old_data_has_alarm == 1) { _DEBUG_INFO("alarm record should be overwrited"); service_ret = calendar_record_get_child_record_at_p(old_service_data, _calendar_todo.calendar_alarm, 0, &old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_child_record_at_p(_calendar_alarm._uri) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); } else { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] this is an error. new_data_has_alarm = %d, old_data_has_alarm = %d", new_data_has_alarm, old_data_has_alarm); + _DEBUG_ERROR("[vcalendar-task] this is an error. new_data_has_alarm = %d, old_data_has_alarm = %d", new_data_has_alarm, old_data_has_alarm); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.type, type); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(type) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_lli(old_alarm_record, _calendar_alarm.time, alarm_time.time.utime); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_lli(time) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_lli() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.tick, tick); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(tick) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.tick_unit, tick_unit); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(tick_unit) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(old_alarm_record, _calendar_alarm.description, description); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_str(description) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.alarm_id, alarm_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int(alarm_id) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_int() Fail!: err[%d]", service_ret); if (old_data_has_alarm == 0) { _DEBUG_INFO("alarm record should be created - add child rocord(alarm)"); service_ret = calendar_record_add_child_record(old_service_data, _calendar_todo.calendar_alarm, old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_child_record_at_p(_calendar_alarm._uri) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_add_child_record() Fail!: err[%d]", service_ret); } } /* image is not supported Outlook sync. So, image field should be not merged (2013/01/14 concept) */ - +return_part: + ret = _convert_service_error_to_common_error(service_ret); + _DEBUG_INFO("ret = %d", ret); _EXTERN_FUNC_EXIT; return ret; } @@ -705,87 +544,60 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_replace_converter(void *old_ // 1. if the vcalendar has until : NONE rrule, then max rrule should be converted : it should be excuted before calendar_vcalendar_parse_to_calendar if (strstr(temp_agent_data, RRULE_KEYWORD) != NULL) { temp = strdup(temp_agent_data); - temp_agent_data = replace_max_rrule_data(temp); + temp_agent_data = replace_rrule_data(temp); temp = NULL; } // 2. priority converting : it should be excuted before calendar_vcalendar_parse_to_calendar if (strstr(temp_agent_data, "\r\nPRIORITY:") != NULL) { - _DEBUG_INFO("priority is founed"); temp = strdup(temp_agent_data); temp = replace_priority_data(temp, false); temp_agent_data = temp; } - _DEBUG_INFO("temp_agent_data= %s", temp_agent_data); service_ret = calendar_vcalendar_parse_to_calendar(temp_agent_data, &calendar_list); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret); *new_service_data = NULL; goto return_part; } - _DEBUG_INFO("[dc_vcalendar-task_plugIn] calendar_vcalendar_parse_to_calendar() success!\n"); service_ret = calendar_list_first(calendar_list); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_child_record_count() Fail!: err[%d]", service_ret); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_list_first() Fail! : err[%d]", service_ret); + _DEBUG_ERROR("[vcalendar-task] calendar_list_first() Fail! : err[%d]", service_ret); goto return_part; } - int count = 0; - calendar_list_get_count(calendar_list, &count); - _DEBUG_INFO("count = %d", count); do { char *uri = NULL; char *key = NULL; service_ret = calendar_list_get_current_record_p(calendar_list, &temp_new_service_data); - if ((service_ret != CALENDAR_ERROR_NONE) || (temp_new_service_data == NULL)) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_list_get_current_record_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) || (temp_new_service_data == NULL), "[vcalendar-task] calendar_list_get_current_record_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_uri_p(temp_new_service_data, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_uri_p() Fail!: err[%d]", service_ret); _DEBUG_INFO("temp_new_service_data URI = %s", uri); if (!strncmp(uri, _calendar_todo._uri, strlen(_calendar_todo._uri))) { _DEBUG_INFO("this is todo"); ret = _vtodo_merge_new_to_old(temp_old_service_data, temp_new_service_data); if (ret != SYNC_AGENT_DA_SUCCESS) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_set_int() Fail! err[%d]\n", ret); + _DEBUG_ERROR("[vcalendar-task] calendar_record_set_int() Fail! err[%d]\n", ret); } - // 1. "no due date" setting : it should be excuted after calendar_vcalendar_parse_to_calendar - if (strstr((char *)temp_agent_data, MAX_DUE_DATE_KEYWORD) != NULL) { - _DEBUG_INFO("no due date setting"); - - calendar_time_s cal_time_end = { 0, }; - service_ret = calendar_record_get_caltime(temp_old_service_data, _calendar_todo.due_time, &cal_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } - - cal_time_end.type = CALENDAR_TIME_UTIME; - cal_time_end.time.utime = CALENDAR_TODO_NO_DUE_DATE; - service_ret = calendar_record_set_caltime(temp_old_service_data, _calendar_todo.due_time, cal_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } - } + // 1. timezone setting : it should be excuted after calendar_vcalendar_parse_to_calendar + set_timezone(temp_agent_data, temp_old_service_data); + + // 2. "no due date" setting : it should be excuted after calendar_vcalendar_parse_to_calendar + process_no_due_date(temp_agent_data, temp_old_service_data); } else if (!strncmp(uri, _calendar_extended_property._uri, strlen(_calendar_extended_property._uri))) { _DEBUG_INFO("this is extended"); ret = calendar_record_get_str(temp_new_service_data, _calendar_extended_property.key, &key); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_str() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_str() Fail!: err[%d]", service_ret); + _DEBUG_INFO("key = %s", key); if (strncmp(key, "VERSION", strlen("VERSION"))) { _DEBUG_INFO("this is extended, not VCALENDAR:VERSION extend"); @@ -825,87 +637,64 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_reverse_converter(void *serv _DEBUG_INFO("converter start"); service_ret = calendar_list_create(&list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_list_create() Fail!: err[%d]", service_ret); // 1. extended vcalendar version : it should be excuted before calendar_vcalendar_make_from_records service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_version); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_create() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(extended_version, _calendar_extended_property.key, "VERSION"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(extended_version, _calendar_extended_property.value, ":1.0"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail!: err[%d]", service_ret); service_ret = calendar_list_add(list, extended_version); - if (service_ret != CALENDAR_ERROR_NONE || list == NULL) { - _DEBUG_ERROR("calendar_list_add() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE || list == NULL, "[vcalendar-task] calendar_list_add() Fail!: err[%d]", service_ret); service_ret = calendar_list_add(list, temp_service_data); - if (service_ret != CALENDAR_ERROR_NONE || list == NULL) { - _DEBUG_ERROR("calendar_list_add() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE || list == NULL, "[vcalendar-task] calendar_list_add() Fail!: err[%d]", service_ret); service_ret = calendar_vcalendar_make_from_records(list, &temp_agent_data); _DEBUG_INFO("temp_agent_data = %s", temp_agent_data); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_vcalendar_make_from_records() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto return_part; - } - - // 1. remove 'timezone' : after calendar_vcalendar_make_from_records - temp_agent_data = remove_timezone(temp_agent_data); - _DEBUG_INFO("temp_agent_data = %s", temp_agent_data); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_vcalendar_make_from_records() Fail!: err[%d]", service_ret); - // 2. image converting : it should be excuted after calendar_vcalendar_make_from_records + // 1. image converting : it should be excuted after calendar_vcalendar_make_from_records char *image_path = has_image_export(image_item); if( image_path != NULL ) { - _DEBUG_INFO("image is founded."); temp_agent_data = replace_image_data(temp_agent_data, image_path); } - // 3. task priority converting : it should be excuted after calendar_vcalendar_make_from_records + // 2. task priority converting : it should be excuted after calendar_vcalendar_make_from_records if (strstr(temp_agent_data, "\r\nPRIORITY:") != NULL) { - _DEBUG_INFO("priority is founed"); temp_agent_data = replace_priority_data(temp_agent_data, true); } + // originally, "NO DUE DATE" vtodo has not "DUE:xxxxxx", but exceptively DUE should be added for alarm time setting at Kies + // 3. DUE converting : it should be excuted after calendar_vcalendar_make_from_records + if (strstr(temp_agent_data, DUEDATE_KEYWORD) == NULL) { + temp_agent_data = replace_string(temp_agent_data, END_VTODO_KEYWORD, "\r\nDUE:20370101T090000\r\nEND:VTODO\r\n"); + } + // originally, vtodo has not DTSTART, but exceptively DTSTART should be added for alarm time setting at Kies // 4. DTSTART converting : it should be excuted after calendar_vcalendar_make_from_records - if (strstr(temp_agent_data, END_VTODO_KEYWORD) != NULL) { - temp_agent_data = replace_string(temp_agent_data, END_VTODO_KEYWORD, "\r\nDTSTART:20370101T090000\r\nEND:VTODO\r\n"); + if (strstr(temp_agent_data, MAX_CALENDAR_DTSTART_KEYWORD) != NULL) { + temp_agent_data = replace_string(temp_agent_data, MAX_CALENDAR_DTSTART_KEYWORD, MAX_MOBEX_DTSTART_KEYWORD); } - // originally, "NO DUE DATE" vtodo has not "DUE:xxxxxx", but exceptively DUE should be added for alarm time setting at Kies - // 5. DUE converting : it should be excuted after calendar_vcalendar_make_from_records - if (strstr(temp_agent_data, DUEDATE_KEYWORD) == NULL) { - temp_agent_data = replace_string(temp_agent_data, END_VTODO_KEYWORD, "\r\nDUE:20370101T090000\r\nEND:VTODO\r\n"); + // originally, vtodo has not DTSTART, but exceptively DTSTART should be added for alarm time setting at Kies + // 5. DTSTART insertconverting : it should be excuted after calendar_vcalendar_make_from_records + if (strstr(temp_agent_data, DTSTART_KEYWORD) == NULL) { + char *temp = g_strdup_printf("%s%s", MAX_MOBEX_DTSTART_KEYWORD, DUEDATE_KEYWORD); + if (temp != NULL) + temp_agent_data = replace_string(temp_agent_data, DUEDATE_KEYWORD, temp); } return_part: _DEBUG_INFO("return_part"); + ret = _convert_service_error_to_common_error(service_ret); + _DEBUG_INFO("ret = %d", ret); + *agent_data = (void *)temp_agent_data; if (list != NULL) { @@ -923,7 +712,7 @@ return_part: EXPORT_API void *sync_agent_plugin_alloc_object() { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[dc_vcalendar-task_plugIn] not implement !!"); + _DEBUG_INFO("[vcalendar-task] not implement !!"); _EXTERN_FUNC_EXIT; return 0; } @@ -931,7 +720,7 @@ EXPORT_API void *sync_agent_plugin_alloc_object() EXPORT_API int sync_agent_plugin_free_object(void *in_object) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[dc_vcalendar-task_plugIn] not implement !!"); + _DEBUG_INFO("[vcalendar-task] not implement !!"); _EXTERN_FUNC_EXIT; return 0; } @@ -939,7 +728,7 @@ EXPORT_API int sync_agent_plugin_free_object(void *in_object) EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *extension_key, void *value) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[dc_vcalendar-task_plugIn] not implement !!"); + _DEBUG_INFO("[vcalendar-task] not implement !!"); _EXTERN_FUNC_EXIT; return 0; @@ -948,7 +737,7 @@ EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *ext EXPORT_API void *sync_agent_plugin_get_value(void *in_object, int key, char *extension_key) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[dc_vcalendar-task_plugIn] not implement !!"); + _DEBUG_INFO("[vcalendar-task] not implement !!"); _EXTERN_FUNC_EXIT; return 0; } diff --git a/src/fw-plugins/common-public/vcalendar-task/src/vcalendar_string_util.c b/src/fw-plugins/common-public/vcalendar-task/src/vcalendar_string_util.c index 2409b39..1d89ed1 100755 --- a/src/fw-plugins/common-public/vcalendar-task/src/vcalendar_string_util.c +++ b/src/fw-plugins/common-public/vcalendar-task/src/vcalendar_string_util.c @@ -40,7 +40,7 @@ static char * _replace_rrule_data(char *origin) char *str_interval = NULL; char *str_period_until = NULL; char *str_period_count = NULL; - calendar_date_type_e cal_type = CALENDAR_DATE_TYPE_ONTIME; + task_date_type_e cal_type = TASK_DATE_TYPE_ONTIME; if ((freq_loc = strstr(origin, RRULE_KEYWORD_FREQ_WEEKLY)) != NULL) { _DEBUG_INFO("this is weekly data"); @@ -249,7 +249,7 @@ static char * _replace_alarm_data(char *origin) char *str_trigger = NULL; char *str_customized_trigger = NULL; char *str_interval = NULL; - calendar_date_type_e cal_type = CALENDAR_DATE_TYPE_ONTIME; + task_date_type_e cal_type = CALENDAR_DATE_TYPE_ONTIME; if ((freq_loc = strstr(origin, BEGIN_ALARM_KEYWORD)) == NULL) { _DEBUG_ERROR("there is not trigger data"); @@ -291,7 +291,7 @@ static char * _replace_alarm_data(char *origin) snprintf(str_new_alarm, 30, "AALARM:%s\r\n", str_customized_trigger); _DEBUG_INFO("str_new_alarm = %s", str_new_alarm); - char *new_agent_data = _replace_string(origin, str_origin_alarm, str_new_alarm); + char *new_agent_data = replace_string(origin, str_origin_alarm, str_new_alarm); origin = NULL; origin = new_agent_data; goto return_part; @@ -305,18 +305,17 @@ static char * _replace_alarm_data(char *origin) } char *temp_alarm = NULL; - char *temp_alarm2 = NULL; if((temp_alarm = strstr(str_trigger, "P0W")) != NULL) { cal_type = CALENDAR_DATE_TYPE_ONTIME; interval = 0; } else if((temp_alarm = strstr(str_trigger, "PT")) != NULL) { - if((temp_alarm2 = strstr(temp_alarm, "H")) != NULL) { + if(strstr(temp_alarm, "H") != NULL) { cal_type = CALENDAR_DATE_TYPE_HOUR; str_interval = _get_value_by_token(str_trigger, "PT", "H"); interval = atoi(str_interval); } - else if((temp_alarm2 = strstr(temp_alarm, "M")) != NULL) { + else if(strstr(temp_alarm, "M") != NULL) { cal_type = CALENDAR_DATE_TYPE_MINUTE; str_interval = _get_value_by_token(str_trigger, "PT", "M"); interval = atoi(str_interval); @@ -327,12 +326,12 @@ static char * _replace_alarm_data(char *origin) } } else if((temp_alarm = strstr(str_trigger, "P")) != NULL) { - if((temp_alarm2 = strstr(temp_alarm, "D")) != NULL) { + if(strstr(temp_alarm, "D") != NULL) { cal_type = CALENDAR_DATE_TYPE_DAY; str_interval = _get_value_by_token(str_trigger, "P", "D"); interval = atoi(str_interval); } - else if((temp_alarm2 = strstr(temp_alarm, "W")) != NULL) { + else if(strstr(temp_alarm, "W") != NULL) { cal_type = CALENDAR_DATE_TYPE_WEEK; str_interval = _get_value_by_token(str_trigger, "P", "W"); interval = atoi(str_interval); @@ -356,7 +355,7 @@ static char * _replace_alarm_data(char *origin) _DEBUG_INFO("str_new_alarm = %s", str_new_alarm); _DEBUG_INFO("str_origin_alarm = %s", str_origin_alarm); - char *new_agent_data = _replace_string(origin, str_origin_alarm, str_new_alarm); + char *new_agent_data = replace_string(origin, str_origin_alarm, str_new_alarm); origin = NULL; origin = new_agent_data; @@ -518,6 +517,69 @@ return_part: #endif +// example) str_time = "20130124T000000Z" = 2013 01 24 T 00 00 00 Z +long long int get_unix_time(char *str_time) +{ + _INNER_FUNC_ENTER; + retvm_if(str_time == NULL, 0, "str_time is NULL"); + _DEBUG_INFO("str_time = %s", str_time); + + UCalendar *ucal = NULL; + char str_year[5] = {0,}; + char str_month[3] = {0,}; + char str_date[3] = {0,}; + char str_hour[3] = {0,}; + char str_minute[3] = {0,}; + char str_second[3] = {0,}; + + strncpy(str_year, str_time, 4); + strncpy(str_month, str_time + 4, 2); + strncpy(str_date, str_time + 4 + 2, 2); + strncpy(str_hour, str_time + 4 + 2 + 2 + 1, 2); + strncpy(str_minute, str_time + 4 + 2 + 2 + 1 + 2, 2); + strncpy(str_second, str_time + 4 + 2 + 2 + 1 + 2 + 2, 2); + + int year = atoi(str_year); + int month = atoi(str_month); + int date = atoi(str_date); + int hour = atoi(str_hour); + int minute = atoi(str_minute); + int second = atoi(str_second); + long long int date_time = 0; + + UErrorCode status = U_ZERO_ERROR; + UChar *tz_id = NULL; + tz_id = (UChar*)calloc(strlen("Etc/GMT") + 1, sizeof(UChar)); // GMT-0 base time setting + + if (tz_id) { + ucal = ucal_open(tz_id, u_strlen(tz_id), uloc_getDefault(), UCAL_TRADITIONAL, &status); + u_uastrcpy(tz_id, "Etc/GMT"); + } + else { + ucal = ucal_open(0, -1, uloc_getDefault(), UCAL_TRADITIONAL, &status); + } + goto_if(U_FAILURE(status), "ucal_open failed (%s)", u_errorName(status)); + + ucal_setAttribute(ucal, UCAL_LENIENT, 1); + ucal_setDateTime(ucal, year, month - 1, date, hour, minute, second, &status); + date_time = (ucal_getMillis(ucal, &status)/1000); + //_DEBUG_INFO("date_time = %lld", date_time); + +return_part: + _DEBUG_INFO("return_part"); + if(ucal) { + ucal_close(ucal); + ucal = NULL; + } + if(tz_id) { + free(tz_id); + tz_id = NULL; + } + _INNER_FUNC_EXIT; + return date_time; +} + + char * get_value_by_token(const char *src, const char *token, const char *end_of_token) { _INNER_FUNC_ENTER; @@ -532,18 +594,17 @@ char * get_value_by_token(const char *src, const char *token, const char *end_of if ((token_loc = strstr(src, token)) != NULL) { char *str_temp = strstr(token_loc, end_of_token); if (str_temp != NULL) { - _DEBUG_INFO("token = %s", token); - _DEBUG_INFO("str_temp = %s", str_temp); int ret_str_length = strlen(token_loc) - strlen(token) - strlen(str_temp); if (ret_str_length <= 0) { + _DEBUG_ERROR("token_loc = %s", token_loc); + _DEBUG_ERROR("token = %s", token); + _DEBUG_ERROR("str_temp = %s", str_temp); _DEBUG_ERROR("ret_str_length(%d) <= 0", ret_str_length); goto return_part; } str_output = (char *)calloc(ret_str_length, sizeof(char)); - if (str_output == NULL) { - _DEBUG_ERROR("calloc failed"); - goto return_part; - } + goto_if(str_output == NULL, "str_output is NULL"); + memcpy(str_output, token_loc + strlen(token), ret_str_length); } } @@ -561,14 +622,9 @@ char * replace_string(char *origin, const char *src, const char *dest) retvm_if((src == NULL || strlen(src) <= 0), NULL, "src is NULL"); retvm_if((dest == NULL || strlen(dest) <= 0), NULL, "dest is NULL"); - _DEBUG_INFO("origin = %s", origin); - _DEBUG_INFO("src = %s", src); - _DEBUG_INFO("dest = %s", dest); - char *str_top = NULL; - if ((str_top = strstr(origin, src)) == NULL) { - _DEBUG_INFO("%s is not founed", src); + _DEBUG_ERROR("%s is not founed", src); return origin; } @@ -577,6 +633,9 @@ char * replace_string(char *origin, const char *src, const char *dest) int down_length = strlen(origin) - top_length - strlen(src); int new_str_length = top_length + middle_length + down_length + 1; if (new_str_length <= 0) { + _DEBUG_ERROR("top_length = %d", top_length); + _DEBUG_ERROR("middle_length = %d", middle_length); + _DEBUG_ERROR("down_length = %d", down_length); _DEBUG_ERROR("new_str_length(%d) <= 0", new_str_length); return origin; } @@ -601,145 +660,93 @@ char * replace_string(char *origin, const char *src, const char *dest) return new_str; } -char * remove_timezone(char *origin) +// PLM(P130408-0777) : In case of DTSTART / DTEND with zulu time ('Z'), GMT timezone should be set. +EXPORT_API void set_timezone(const char *origin, calendar_record_h cal_record) { _INNER_FUNC_ENTER; - retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL"); - - _DEBUG_INFO("origin = %s", origin); + retm_if(origin == NULL, "origin is NULL"); + retm_if(cal_record == NULL, "cal_record is NULL"); - char *str_timezone = NULL; - char *str_temp = NULL; + int service_ret = CALENDAR_ERROR_NONE; + char *temp = NULL; + char *str_start = NULL; - if ((str_temp = strstr(origin, "\r\nDTSTART;TZID=")) != NULL) { - _DEBUG_INFO("str_temp = %s", str_temp); - str_timezone = get_value_by_token(str_temp, "\r\nDTSTART", ":"); - _DEBUG_INFO("str_timezone = %s", str_timezone); - strcat(str_timezone, ":"); - _DEBUG_INFO("str_timezone = %s", str_timezone); - origin = replace_string(origin, str_timezone, ":"); + temp = strstr(origin, DTSTART_KEYWORD); + goto_if(temp == NULL, "origin has not DTSTART. origin = %s", origin); - if (str_timezone) - free(str_timezone); - str_timezone = NULL; - } + str_start = get_value_by_token(temp + 2, "DTSTART:", "\r\n"); + goto_if(str_start == NULL, "str_start is NULL"); + goto_if(str_start == NULL, "str_start is NULL. temp = %s", temp); - if ((str_temp = strstr(origin, "\r\nDUE;TZID=")) != NULL) { - _DEBUG_INFO("str_temp = %s", str_temp); - str_timezone = get_value_by_token(str_temp, "\r\nDUE", ":"); - _DEBUG_INFO("str_timezone = %s", str_timezone); - strcat(str_timezone, ":"); - _DEBUG_INFO("str_timezone = %s", str_timezone); - origin = replace_string(origin, str_timezone, ":"); + if (strstr(str_start, "Z") != NULL) { + _DEBUG_INFO("GMT timezone setting"); + service_ret = calendar_record_set_str(cal_record, _calendar_todo.start_tzid, TIMEZONE_GMT); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail! : err[%d]", service_ret); - if (str_timezone) - free(str_timezone); - str_timezone = NULL; + service_ret = calendar_record_set_str(cal_record, _calendar_todo.due_tzid, TIMEZONE_GMT); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_str() Fail! : err[%d]", service_ret); } - _DEBUG_INFO("origin = %s", origin); +return_part: + if (str_start) { + free(str_start); + str_start = NULL; + } _INNER_FUNC_EXIT; - return origin; + return; } -void insert_allday_data(const char *origin, calendar_record_h calendar_record) +EXPORT_API void process_no_due_date(const char *origin, calendar_record_h cal_record) { _INNER_FUNC_ENTER; - retm_if((origin == NULL || strlen(origin) <= 0), "origin is NULL"); - retm_if(calendar_record == NULL, "calendar_record is NULL"); + retm_if(origin == NULL, "origin is NULL"); + retm_if(cal_record == NULL, "cal_record is NULL"); int service_ret = CALENDAR_ERROR_NONE; - char *uri = NULL; - service_ret = calendar_record_get_uri_p(calendar_record, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; - } + if (strstr((char *)origin, MAX_DUE_DATE_KEYWORD) != NULL) { + _DEBUG_INFO("no due date setting"); - if (strncmp(uri, _calendar_todo._uri, strlen(_calendar_todo._uri))) { - _DEBUG_ERROR("this is not todo"); - goto return_part; - } + calendar_time_s cal_time_end = { 0, }; + service_ret = calendar_record_get_caltime(cal_record, _calendar_todo.due_time, &cal_time_end); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_caltime() Fail!: err[%d]", service_ret); - calendar_time_s cal_time_start = { 0, }; - calendar_time_s cal_time_end = { 0, }; - int year = 0; - int month = 0; - int day = 0; + cal_time_end.type = CALENDAR_TIME_UTIME; + cal_time_end.time.utime = CALENDAR_TODO_NO_DUE_DATE; + service_ret = calendar_record_set_caltime(cal_record, _calendar_todo.due_time, cal_time_end); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_caltime() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_caltime(calendar_record, _calendar_todo.start_time, &cal_time_start); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret); - goto return_part; - } + int has_alarm = 0; + service_ret = calendar_record_get_int(cal_record, _calendar_todo.has_alarm, &has_alarm); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_int() Fail!: err[%d]", service_ret); - char *start_date_loc = NULL; - if ((start_date_loc = strstr(origin, DTSTART_KEYWORD)) == NULL) { - _DEBUG_ERROR("start_date_loc is null"); - goto return_part; - } + if (has_alarm == 1) { + char *start_date_loc = NULL; + if ((start_date_loc = strstr(origin, AALARM_KEYWORD)) != NULL) { + calendar_record_h new_alarm_record = NULL; + long long int utime = 0; + char *str_alarm = NULL; - char str_year_start[5] = {0,}; - char str_month_start[3] = {0,}; - char str_date_start[3] = {0,}; + str_alarm = get_value_by_token(start_date_loc+2, "AALARM:", "\r\n"); + utime = get_unix_time(str_alarm); + if (str_alarm) { + free(str_alarm); + str_alarm = NULL; + } - /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */ - strncpy(str_year_start, start_date_loc + strlen(DTSTART_KEYWORD), 4); - strncpy(str_month_start, start_date_loc + strlen(DTSTART_KEYWORD) + 4, 2); - strncpy(str_date_start, start_date_loc + strlen(DTSTART_KEYWORD) + 4 + 2, 2); - - year = atoi(str_year_start); - month = atoi(str_month_start); - day = atoi(str_date_start); - - _DEBUG_INFO("start time : year = %d, month = %d, day = %d", year, month, day); - cal_time_start.type = CALENDAR_TIME_LOCALTIME; - cal_time_start.time.date.year = year; - cal_time_start.time.date.month = month; - cal_time_start.time.date.mday = day; - - service_ret = calendar_record_set_caltime(calendar_record, _calendar_todo.start_time, cal_time_start); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret); - goto return_part; - } - - service_ret = calendar_record_get_caltime(calendar_record, _calendar_todo.due_time, &cal_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret); - goto return_part; - } + service_ret = calendar_record_get_child_record_at_p(cal_record, _calendar_todo.calendar_alarm, 0, &new_alarm_record); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); - char *end_date_loc = NULL; - if ((end_date_loc = strstr(origin, DTEND_KEYWORD)) == NULL) { - _DEBUG_ERROR("end_date_loc is null"); - goto return_part; - } + service_ret = calendar_record_set_int(new_alarm_record, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_int() Fail!: err[%d]", service_ret); - char str_year_end[5] = {0,}; - char str_month_end[3] = {0,}; - char str_date_end[3] = {0,}; + service_ret = calendar_record_set_int(new_alarm_record, _calendar_alarm.type, CALENDAR_TIME_UTIME); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_int() Fail!: err[%d]", service_ret); - /* example) 20130124T000000Z\r\n = 2013 01 24 T 00 00 00 Z \r\n */ - strncpy(str_year_end, end_date_loc + strlen(DTEND_KEYWORD), 4); - strncpy(str_month_end, end_date_loc + strlen(DTEND_KEYWORD) + 4, 2); - strncpy(str_date_end, end_date_loc + strlen(DTEND_KEYWORD) + 4 + 2, 2); - - year = atoi(str_year_end); - month = atoi(str_month_end); - day = atoi(str_date_end); - - _DEBUG_INFO("end time : year = %d, month = %d, day = %d", year, month, day); - cal_time_end.type = CALENDAR_TIME_LOCALTIME; - cal_time_end.time.date.year = year; - cal_time_end.time.date.month = month; - cal_time_end.time.date.mday = day; - - service_ret = calendar_record_set_caltime(calendar_record, _calendar_todo.due_time, cal_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret); - goto return_part; + service_ret = calendar_record_set_lli(new_alarm_record, _calendar_alarm.time, utime); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar-task] calendar_record_set_lli() Fail!: err[%d]", service_ret); + } + } } return_part: @@ -747,19 +754,22 @@ return_part: return; } + EXPORT_API char * has_image_import(const char *origin) { _INNER_FUNC_ENTER; char *temp_image_path = NULL; char *image_path = NULL; + _DEBUG_INFO("origin = %s", origin); - if (strstr(origin, IMAGE_KEYWORD_PREFIX_PHOTO) == NULL && strstr(origin, IMAGE_KEYWORD_PREFIX_SNOTE) == NULL) { + if (strstr(origin, CR_IMAGE_KEYWORD_PREFIX_PHOTO) == NULL && strstr(origin, CR_IMAGE_KEYWORD_PREFIX_SNOTE) == NULL) { _DEBUG_INFO("this calendar has not an image"); goto return_part; } temp_image_path = get_value_by_token(origin, IMAGE_KEYWORD_BEGIN_PATH, IMAGE_KEYWORD_END_PATH); + goto_if(temp_image_path == NULL, "temp_image_path is NULL"); if (strstr(temp_image_path, INTERNAL_MEMORY_CONVERTED) != NULL) { image_path = replace_string(temp_image_path, INTERNAL_MEMORY_CONVERTED, INTERNAL_MEMORY_ORIGIN); @@ -785,6 +795,7 @@ return_part: EXPORT_API char * has_image_export(calendar_record_h cal_record) { _INNER_FUNC_ENTER; + retvm_if(cal_record == NULL, NULL, "cal_record is NULL"); calendar_record_h image_record = NULL; unsigned int child_record_count = 0; @@ -795,40 +806,23 @@ EXPORT_API char * has_image_export(calendar_record_h cal_record) char *uri = NULL; service_ret = calendar_record_get_uri_p(cal_record, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_uri_p() Fail!: err[%d]", service_ret); _DEBUG_INFO("uri = %s", uri); - _DEBUG_INFO("_calendar_todo.uri = %s", _calendar_todo._uri); service_ret = calendar_record_get_child_record_count(cal_record, _calendar_todo.extended, &child_record_count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_child_record_count() Fail: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() Fail!: err[%d]", service_ret); for (i = 0; i < child_record_count; i++) { service_ret = calendar_record_get_child_record_at_p(cal_record, _calendar_todo.extended, i, &image_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_child_record_at_p() Fail: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_str_p(image_record, _calendar_extended_property.key, &image_key); - if (service_ret != CALENDAR_ERROR_NONE || image_key == NULL || strlen(image_key) <= 0) { - _DEBUG_ERROR("calendar_record_get_str_p is failed(%d)", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE || image_key == NULL || strlen(image_key) <= 0, "calendar_record_get_str_p() Fail!: err[%d]", service_ret); if (strcmp(image_key, CALENDAR_IMAGE_KEYWORD_SNOTE) == 0 || strcmp(image_key, CALENDAR_IMAGE_KEYWORD_PHOTO) == 0) { _DEBUG_INFO("image is founded. image_key = %s", image_key); service_ret = calendar_record_get_str(image_record, _calendar_extended_property.value, &image_path); - if (service_ret != CALENDAR_ERROR_NONE || image_path == NULL || strlen(image_path) <= 0) { - _DEBUG_ERROR("calendar_record_get_str_p is failed(%d)", service_ret); - image_path = NULL; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE || image_path == NULL || strlen(image_path) <= 0, "calendar_record_get_str is failed(%d)", service_ret); _DEBUG_INFO("image_path = %s", image_path); continue; } @@ -839,7 +833,7 @@ return_part: return image_path; } -char * replace_max_rrule_data(char *origin) +char * replace_rrule_data(char *origin) { _INNER_FUNC_ENTER; retvm_if(origin == NULL, origin, "origin is NULL."); @@ -849,17 +843,25 @@ char * replace_max_rrule_data(char *origin) char *str_old_rrule = NULL; char *str_new_rrule = NULL; - if ((temp = strstr(origin, RRULE_KEYWORD)) == NULL) { + temp = strstr(origin, RRULE_KEYWORD); + if (temp == NULL) { _DEBUG_INFO("this vcalendar hasn't rrule data"); goto return_part; } - str_old_rrule = get_value_by_token(temp+2, "RRULE:", "\r\n");// '2' means strlen("\r\n") - if (str_old_rrule == NULL) { - _DEBUG_ERROR("str_old_rrule is null"); + // case 1 : weekdays rrule converting + if (strstr(origin, WEEKDAY_RRULE_ORIGIN_KEYWORD) != NULL) { + _DEBUG_INFO("this vcalendar has WEEKDAYS rrule data"); + + origin = replace_string(origin, WEEKDAY_RRULE_ORIGIN_KEYWORD, WEEKDAY_RRULE_CONVERTED_KEYWORD); + _DEBUG_INFO("AFTER origin = %s", origin); goto return_part; } + // case 2 : max rrule converting + str_old_rrule = get_value_by_token(temp+2, "RRULE:", "\r\n");// '2' means strlen("\r\n") + goto_if(str_old_rrule == NULL, "str_old_rrule is null"); + if (strstr(str_old_rrule, MAX_RRULE_DATE_KEYWORD) == NULL) { _DEBUG_INFO("this vcalendar has rrule data, But it's not until=NONE rrule"); goto return_part; @@ -867,19 +869,13 @@ char * replace_max_rrule_data(char *origin) _DEBUG_INFO("this vcalendar has until=NONE rrule"); temp_rrule = get_value_by_token(temp, RRULE_KEYWORD, MAX_RRULE_DATE_KEYWORD); - if (temp_rrule == NULL) { - _DEBUG_ERROR("temp_rrule is null"); - goto return_part; - } - - str_new_rrule = (char *)calloc(strlen(temp_rrule)+2, sizeof(char)); - if (str_new_rrule == NULL) { - _DEBUG_ERROR("str_new_rrule calloc failed"); - goto return_part; - } + goto_if(temp_rrule == NULL, "temp_rrule is null"); // every eternal rrule data must have '#0' at the end of string (Calendar-Svc recommend) - snprintf(str_new_rrule, strlen(temp_rrule)+2, "%s#0", temp_rrule); + str_new_rrule = g_strdup_printf("%s#0", temp_rrule); + goto_if(str_new_rrule == NULL, "str_new_rrule is null"); + _DEBUG_INFO("str_new_rrule = %s", str_new_rrule); + origin = replace_string(origin, str_old_rrule, str_new_rrule); return_part: @@ -891,8 +887,11 @@ return_part: free(str_new_rrule); str_new_rrule = NULL; } + if(temp_rrule) { + free(temp_rrule); + temp_rrule = NULL; + } _INNER_FUNC_EXIT; - _DEBUG_INFO("origin = %s", origin); return origin; } @@ -902,48 +901,32 @@ char * replace_image_data(char *origin, char *image_path) retvm_if(origin == NULL, origin, "origin is NULL."); retvm_if(image_path == NULL, origin, "image_path is NULL."); - int image_path_length = 500; char *str_temp_image_info = NULL; char *str_image_info = NULL; char *str_image_tag = NULL; - _DEBUG_INFO("origin = %s", origin); - _DEBUG_INFO("image_path = %s", image_path); - if (strstr(image_path, INTERNAL_MEMORY_ORIGIN) != NULL) { str_temp_image_info = replace_string(image_path, INTERNAL_MEMORY_ORIGIN, INTERNAL_MEMORY_CONVERTED); - str_image_tag = strdup("X-SS-ATTACH-IMAGE"); + str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO); } else if (strstr(image_path, EXTERNAL_MEMORY_ORIGIN) != NULL) { str_temp_image_info = replace_string(image_path, EXTERNAL_MEMORY_ORIGIN, EXTERNAL_MEMORY_CONVERTED); - str_image_tag = strdup("X-SS-ATTACH-IMAGE"); + str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO); } else if (strstr(image_path, SNOTE_MEMORY_ORIGIN) != NULL) { str_temp_image_info = strdup(image_path); - //str_image_tag = strdup("X-SS-ATTACH-SNOTE"); - str_image_tag = strdup("X-SS-ATTACH-IMAGE"); + //str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_SNOTE); + str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO); } else { _DEBUG_ERROR("there is an error. image_path = %s", image_path); goto return_part; } - if (strstr(origin, END_VTODO_KEYWORD) == NULL) { - _DEBUG_ERROR("this data is wrong format. origin = %s", origin); - goto return_part; - } - - if (image_path_length <= 0) { - _DEBUG_ERROR("image_path_length(%d) <= 0", image_path_length); - goto return_part; - } - str_image_info = (char *)calloc(image_path_length, sizeof(char)); - if (str_image_info == NULL) { - _DEBUG_ERROR("str_image_info calloc failed"); - goto return_part; - } + goto_if(strstr(origin, END_VTODO_KEYWORD) == NULL, "this data is wrong format. origin = %s", origin); - snprintf(str_image_info, image_path_length, "\r\n%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:NAME=3Dnull=3BPATH=3D%s=3BDATE=3D%s", str_image_tag, str_temp_image_info, END_VTODO_KEYWORD); + str_image_info = g_strdup_printf("\r\n%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:NAME=3Dnull=3BPATH=3D%s=3BDATE=3D%s", str_image_tag, str_temp_image_info, END_VTODO_KEYWORD); + goto_if(str_image_info == NULL, "str_image_info is null"); char *new_agent_data = replace_string(origin, END_VTODO_KEYWORD, str_image_info); origin = NULL; @@ -965,7 +948,6 @@ return_part: } _INNER_FUNC_EXIT; - _DEBUG_INFO("origin = %s", origin); return origin; } @@ -1019,7 +1001,6 @@ char * replace_priority_data(char *origin, bool is_phone_to_kies) return_part: _INNER_FUNC_EXIT; - _DEBUG_INFO("origin = %s", origin); return origin; } diff --git a/src/fw-plugins/common-public/vcalendar/include/vcalendar_string_util.h b/src/fw-plugins/common-public/vcalendar/include/vcalendar_string_util.h index 3c394ae..dfca727 100755 --- a/src/fw-plugins/common-public/vcalendar/include/vcalendar_string_util.h +++ b/src/fw-plugins/common-public/vcalendar/include/vcalendar_string_util.h @@ -48,7 +48,9 @@ typedef enum cal_date_type { typedef enum cal_exdate_type { CALENDAR_EXDATE_TYPE_NONE = 0, CALENDAR_EXDATE_TYPE_DELETED, - CALENDAR_EXDATE_TYPE_UPDATED, + CALENDAR_EXDATE_TYPE_UPDATED_PARENT, + CALENDAR_EXDATE_TYPE_UPDATED_CHILD, + CALENDAR_EXDATE_TYPE_MAX, } calendar_exdate_type_e; typedef struct sync_agent_calendar_exdate_s sync_agent_calendar_exdate_t; @@ -70,24 +72,32 @@ struct sync_agent_calendar_exdate_s { #define RRULE_KEYWORD_BYMONTHDAY "BYMONTHDAY=" #define RRULE_KEYWORD_UNTIL "UNTIL=" #define RRULE_KEYWORD_COUNT "COUNT=" -#define DTSTART_KEYWORD "\r\nDTSTART" -#define DTEND_KEYWORD "\r\nDTEND" +#define DTSTART_KEYWORD "\r\nDTSTART:" +#define DTEND_KEYWORD "\r\nDTEND:" #define BEGIN_ALARM_KEYWORD "\r\nBEGIN:VALARM" #define AALARM_KEYWORD "\r\nAALARM" #define END_VEVENT_KEYWORD "\r\nEND:VEVENT\r\n" #define SUMMARY_KEYWORD "\r\nSUMMARY:" -#define MAX_RRULE_DATE_KEYWORD "20361231T000000Z" -#define MAX_DUE_DATE_KEYWORD "\r\nDUE:20381231T000000Z\r\n" // refer to calendar info (min ~ max date) +#define MAX_RRULE_DATE_KEYWORD "20361231T" +#define WEEKDAY_RRULE_ORIGIN_KEYWORD "\r\nRRULE:W0 " +#define WEEKDAY_RRULE_CONVERTED_KEYWORD "\r\nRRULE:W1 MO TU WE TH FR " +#define TIMEZONE_GMT "Etc/GMT" + +#define EXTYPE_UID_KEYWORD "\r\nUID:" #define EXTYPE_DELETE_KEYWORD "X-EXTYPE:1" #define EXTYPE_UPDATE_KEYWORD "X-EXTYPE:2" #define CR_EXTYPE_DELETE_KEYWORD "\r\nX-EXTYPE:1" // carrige return + EXTYPE_DELETE_KEYWORD +#define CR_EXTYPE_UPDATE_KEYWORD "\r\nX-EXTYPE:2" // carrige return + EXTYPE_UPDATE_KEYWORD #define IMPORT_EXTYPE_DELETE_KEYWORD "\r\nX-EXTYPE:1\r\nEXDATE:" +#define IMPORT_EXTYPE_UPDATE_KEYWORD "\r\nX-EXTYPE:2\r\nEXDATE:" #define EXDATE_KEYWORD "\r\nEXDATE:" #define CALENDAR_IMAGE_KEYWORD_SNOTE "snote" // refer to Cal-svc.h (calendar\include) #define CALENDAR_IMAGE_KEYWORD_PHOTO "photo" // refer to Cal-svc.h (calendar\include) -#define IMAGE_KEYWORD_PREFIX_SNOTE "\r\nX-SS-ATTACH-SNOTE;" -#define IMAGE_KEYWORD_PREFIX_PHOTO "\r\nX-SS-ATTACH-IMAGE;" +#define IMAGE_KEYWORD_PREFIX_SNOTE "X-SS-ATTACH-SNOTE;" +#define IMAGE_KEYWORD_PREFIX_PHOTO "X-SS-ATTACH-IMAGE;" +#define CR_IMAGE_KEYWORD_PREFIX_SNOTE "\r\nX-SS-ATTACH-SNOTE;" +#define CR_IMAGE_KEYWORD_PREFIX_PHOTO "\r\nX-SS-ATTACH-IMAGE;" #define IMAGE_KEYWORD_BEGIN_PATH "PATH=3D" #define IMAGE_KEYWORD_END_PATH "=3bDATE=3D\r\n" @@ -102,14 +112,16 @@ struct sync_agent_calendar_exdate_s { char * get_value_by_token(const char *src, const char *token, const char *end_of_token); char * replace_string(char *origin, const char *src, const char *dest); -char * remove_timezone(char *origin); -char * insert_exdate_data(const char *origin, sync_agent_calendar_exdate_t *exdate_struct, int index); +void set_timezone(const char *origin, calendar_record_h cal_record); +char * remove_uid(char *origin); +char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_struct, int index); void insert_allday_data(const char *origin, calendar_record_h calendar_record); char * has_image_import(const char *origin); char * has_image_export(calendar_record_h cal_record); void get_exdate_data(calendar_record_h cal_record, sync_agent_calendar_exdate_t *exdate_struct); -char * replace_max_rrule_data(char *origin); +char * replace_rrule_data(char *origin); char * replace_image_data(char *origin, char *image_path); -sync_agent_da_return_e replace_exdate_data(const char *origin, calendar_record_h calendar_record); +void replace_deleted_exdate_data(const char *origin, calendar_record_h parent_record); +int replace_updated_exdate_data(const char *origin, calendar_record_h parent_record); #endif /* IN_VCALENDAR_STRING_UTIL_H_ */ diff --git a/src/fw-plugins/common-public/vcalendar/src/plugin_interface.c b/src/fw-plugins/common-public/vcalendar/src/plugin_interface.c index 9fa5bf3..bed35d3 100755 --- a/src/fw-plugins/common-public/vcalendar/src/plugin_interface.c +++ b/src/fw-plugins/common-public/vcalendar/src/plugin_interface.c @@ -50,55 +50,55 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_ calendar_list_h calendar_list = NULL; calendar_record_h temp_service_data = NULL; + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + int service_ret = CALENDAR_ERROR_NONE; const char *temp_agent_data = (const char *)agent_data; char *image_path = has_image_import(temp_agent_data); char *temp_image_path = NULL; char *token = NULL; char *temp = NULL; - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - int service_ret = CALENDAR_ERROR_NONE; - _DEBUG_INFO("temp_agent_data= %s", temp_agent_data); + + _DEBUG_INFO("temp_agent_data = %s", temp_agent_data); // 1. if the vcalendar has until : NONE rrule, then max rrule should be converted : it should be excuted before calendar_vcalendar_parse_to_calendar if (strstr(temp_agent_data, RRULE_KEYWORD) != NULL) { temp = strdup(temp_agent_data); - temp_agent_data = replace_max_rrule_data(temp); + temp_agent_data = replace_rrule_data(temp); temp = NULL; } + // 2. if the vcalendar has UID, remove it : it should be excuted before calendar_vcalendar_parse_to_calendar + if (strstr(temp_agent_data, EXTYPE_UID_KEYWORD) != NULL) { + temp = strdup(temp_agent_data); + temp_agent_data = remove_uid(temp); + temp = NULL; + _DEBUG_INFO("after remove_uid(), temp_agent_data = %s", temp_agent_data); + } + service_ret = calendar_vcalendar_parse_to_calendar(temp_agent_data, &calendar_list); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret); ret = _convert_service_error_to_common_error(service_ret); *service_data = NULL; } if (calendar_list == NULL) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_vcalendar_parse_to_calendar() -> temp_service_data is null, err[%d] !!", service_ret); + _DEBUG_ERROR("[vcalendar] calendar_vcalendar_parse_to_calendar() -> temp_service_data is null, err[%d] !!", service_ret); ret = SYNC_AGENT_DA_ERRORS; goto return_part; } service_ret = calendar_list_first(calendar_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_list_first() Fail! : err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_list_first() Fail! : err[%d]", service_ret); do { char *uri = NULL; service_ret = calendar_list_get_current_record_p(calendar_list, &temp_service_data); - if ((service_ret != CALENDAR_ERROR_NONE) || (temp_service_data == NULL)) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_list_get_current_record_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) || (temp_service_data == NULL), "[vcalendar] calendar_list_get_current_record_p() Fail! : err[%d]", service_ret); service_ret = calendar_record_get_uri_p(temp_service_data, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); if (!strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri))) { _DEBUG_INFO("this is event"); @@ -114,19 +114,7 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_ } while(calendar_list_next(calendar_list) != CALENDAR_ERROR_NO_DATA); // 1. timezone setting : it should be excuted after calendar_vcalendar_parse_to_calendar - service_ret = calendar_record_set_str(temp_service_data, _calendar_event.start_tzid, "Asia/Seoul"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - /*i think when set return fail then going throw input schedule */ - } - - service_ret = calendar_record_set_str(temp_service_data, _calendar_event.end_tzid, "Asia/Seoul"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - /*i think when set return fail then going throw input schedule */ - } + set_timezone(temp_agent_data, temp_service_data); // 2. "all day" setting : it should be excuted after calendar_vcalendar_parse_to_calendar if (strstr((char *)agent_data, "\r\nX-ALLDAY:SET") != NULL) { @@ -136,69 +124,40 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_ // 3. add image info : it should be excuted after calendar_vcalendar_parse_to_calendar if( image_path != NULL ) { _DEBUG_INFO("image is founded. %s", image_path); - - ///////////////////////////////////// S Note temporary code //////////////////////////// + ///////////////////////////////////// S Note //////////////////////////// if (strstr(image_path, "=\r\n") != NULL) { - temp_image_path = get_value_by_token(image_path, "/opt/usr/apps/com.samsung.smemo/data/", "=\r\n"); + temp_image_path = get_value_by_token(image_path, SNOTE_MEMORY_ORIGIN, "=\r\n"); _DEBUG_INFO("temp_image_path = %s", temp_image_path); - token = (char *)calloc(1000, sizeof(char)); - if (token == NULL) { - _DEBUG_ERROR("token calloc() is failed"); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } - - snprintf(token, 1000, "%s=\r\n", temp_image_path); - _DEBUG_INFO("token = %s", token); + token = g_strdup_printf("%s=\r\n", temp_image_path); + goto_if(token == NULL, "token is NULL"); temp = get_value_by_token(image_path, token, ".png"); - if (image_path) { free(image_path); image_path = NULL; } - image_path = (char *)calloc(1000, sizeof(char)); - if (image_path == NULL) { - _DEBUG_ERROR("image_path is null"); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } - - snprintf(image_path, 1000, "/opt/usr/apps/com.samsung.smemo/data/%s%s.png", temp_image_path, temp); + image_path = g_strdup_printf("%s%s%s.png", SNOTE_MEMORY_ORIGIN, temp_image_path, temp); + goto_if(image_path == NULL, "image_path is NULL"); _DEBUG_INFO("image_path = %s", image_path); } - ///////////////////////////////////// S Note temporary code //////////////////////////// + ///////////////////////////////////// S Note //////////////////////////// calendar_record_h image_record = NULL; - service_ret = calendar_record_create(_calendar_extended_property._uri, &image_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_create() Fail! : err[%d]", service_ret); service_ret = calendar_record_set_str(image_record, _calendar_extended_property.key, CALENDAR_IMAGE_KEYWORD_PHOTO); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail! : err[%d]", service_ret); service_ret = calendar_record_set_str(image_record, _calendar_extended_property.value, image_path); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail! : err[%d]", service_ret); service_ret = calendar_record_add_child_record(temp_service_data, _calendar_event.extended, image_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_add_child_record() Fail! err[%d]\n", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_add_child_record() Fail! : err[%d]", service_ret); } *service_data = (void *)temp_service_data; - _DEBUG_INFO("calendar_vcalendar_parse_to_calendar() Success!\n"); return_part: _DEBUG_INFO("return part"); @@ -227,6 +186,7 @@ return_part: temp = NULL; } + ret = _convert_service_error_to_common_error(service_ret); _EXTERN_FUNC_EXIT; return ret; } @@ -243,72 +203,42 @@ sync_agent_da_return_e _vevent_merge_new_to_old(calendar_record_h old_service_da /*description */ char *description = NULL; service_ret = calendar_record_get_str_p(new_service_data, _calendar_event.description, &description); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(old_service_data, _calendar_event.description, description); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); /* start time */ calendar_time_s cal_time_st = { 0, }; service_ret = calendar_record_get_caltime(new_service_data, _calendar_event.start_time, &cal_time_st); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_caltime() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_caltime() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_caltime(old_service_data, _calendar_event.start_time, cal_time_st); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_caltime() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_caltime() Fail!: err[%d]", service_ret); /* end time */ calendar_time_s cal_time_ed = { 0, }; service_ret = calendar_record_get_caltime(new_service_data, _calendar_event.end_time, &cal_time_ed); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_caltime() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_caltime() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_caltime(old_service_data, _calendar_event.end_time, cal_time_ed); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_caltime() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_caltime() Fail!: err[%d]", service_ret); /* summary */ char *summary = 0; service_ret = calendar_record_get_str_p(new_service_data, _calendar_event.summary, &summary); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(old_service_data, _calendar_event.summary, summary); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); /* location */ char *location = 0; service_ret = calendar_record_get_str_p(new_service_data, _calendar_event.location, &location); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str_p() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(old_service_data, _calendar_event.location, location); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); /* rrule */ int num = 0; @@ -316,168 +246,98 @@ sync_agent_da_return_e _vevent_merge_new_to_old(calendar_record_h old_service_da calendar_time_s caltime = {0}; service_ret = calendar_record_get_int(new_service_data, _calendar_event.freq, &num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(freq) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); + _DEBUG_INFO("new freq = %d", num); + service_ret = calendar_record_set_int(old_service_data, _calendar_event.freq, num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(freq) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_int(new_service_data, _calendar_event.range_type, &num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(range_type) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_int(old_service_data, _calendar_event.range_type, num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(range_type) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + // in case of 'no rrule', below codes should be not executed + if (num != CALENDAR_RECURRENCE_NONE) { + _DEBUG_INFO("rrule should be overwrite"); + service_ret = calendar_record_get_int(new_service_data, _calendar_event.range_type, &num); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_caltime(new_service_data, _calendar_event.until_time, &caltime); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_caltime(until_time) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_caltime(old_service_data, _calendar_event.until_time, caltime); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_caltime(until_time) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_set_int(old_service_data, _calendar_event.range_type, num); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_int(new_service_data, _calendar_event.count, &num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(count) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_int(old_service_data, _calendar_event.count, num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(count) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_get_caltime(new_service_data, _calendar_event.until_time, &caltime); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_caltime() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_int(new_service_data, _calendar_event.interval, &num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(interval) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_int(old_service_data, _calendar_event.interval, num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(interval) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_set_caltime(old_service_data, _calendar_event.until_time, caltime); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_caltime() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.bysecond, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(bysecond) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.bysecond, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(bysecond) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_get_int(new_service_data, _calendar_event.count, &num); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.byminute, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(byminute) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.byminute, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(byminute) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_set_int(old_service_data, _calendar_event.count, num); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.byhour, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(byhour) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.byhour, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(byhour) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_get_int(new_service_data, _calendar_event.interval, &num); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.byday, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(byday) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.byday, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(byday) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_set_int(old_service_data, _calendar_event.interval, num); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.bymonthday, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(bymonthday) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.bymonthday, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(bymonthday) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_get_str(new_service_data, _calendar_event.bysecond, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.byyearday, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(byyearday) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.byyearday, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(byyearday) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_set_str(old_service_data, _calendar_event.bysecond, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.byweekno, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(byweekno) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.byweekno, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(byweekno) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_get_str(new_service_data, _calendar_event.byminute, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.bymonth, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(bymonth) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.bymonth, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(bymonth) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_set_str(old_service_data, _calendar_event.byminute, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_str(new_service_data, _calendar_event.bysetpos, &text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(bysetpos) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_str(old_service_data, _calendar_event.bysetpos, text); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(bysetpos) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + service_ret = calendar_record_get_str(new_service_data, _calendar_event.byhour, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); - service_ret = calendar_record_get_int(new_service_data, _calendar_event.wkst, &num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(wkst) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } - service_ret = calendar_record_set_int(old_service_data, _calendar_event.wkst, num); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(wkst) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; + service_ret = calendar_record_set_str(old_service_data, _calendar_event.byhour, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_str(new_service_data, _calendar_event.byday, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(old_service_data, _calendar_event.byday, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_str(new_service_data, _calendar_event.bymonthday, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(old_service_data, _calendar_event.bymonthday, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_str(new_service_data, _calendar_event.byyearday, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(old_service_data, _calendar_event.byyearday, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_str(new_service_data, _calendar_event.byweekno, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(old_service_data, _calendar_event.byweekno, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_str(new_service_data, _calendar_event.bymonth, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(old_service_data, _calendar_event.bymonth, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_str(new_service_data, _calendar_event.bysetpos, &text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(old_service_data, _calendar_event.bysetpos, text); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_int(new_service_data, _calendar_event.wkst, &num); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_int(old_service_data, _calendar_event.wkst, num); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); } /* alarm */ @@ -493,149 +353,89 @@ sync_agent_da_return_e _vevent_merge_new_to_old(calendar_record_h old_service_da description = NULL; service_ret = calendar_record_get_int(new_service_data, _calendar_event.has_alarm, &new_data_has_alarm); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(has_alarm) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); _DEBUG_INFO("new_data_has_alarm = %d", new_data_has_alarm); service_ret = calendar_record_get_int(old_service_data, _calendar_event.has_alarm, &old_data_has_alarm); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(has_alarm) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); _DEBUG_INFO("old_data_has_alarm = %d", old_data_has_alarm); if (new_data_has_alarm == 0 && old_data_has_alarm == 1) { _DEBUG_INFO("alarm record shoud be deleted"); service_ret = calendar_record_get_child_record_at_p(old_service_data, _calendar_event.calendar_alarm, 0, &old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_child_record_at_p() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_remove_child_record(old_service_data, _calendar_event.calendar_alarm, old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_remove_child_record() Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_remove_child_record() Fail!: err[%d]", service_ret); } else if (new_data_has_alarm == 1) { service_ret = calendar_record_get_child_record_at_p(new_service_data, _calendar_event.calendar_alarm, 0, &new_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_child_record_at_p(_calendar_event.calendar_alarm) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.type, &type); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(type) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_lli(new_alarm_record, _calendar_alarm.time, &alarm_time.time.utime); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_lli(time) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_lli() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.tick, &tick); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(tick) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.tick_unit, &tick_unit); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(tick_unit) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_str(new_alarm_record, _calendar_alarm.description, &description); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str(description) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_int(new_alarm_record, _calendar_alarm.alarm_id, &alarm_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_int(alarm_id) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_int() Fail!: err[%d]", service_ret); if (old_data_has_alarm == 0) { _DEBUG_INFO("alarm record should be created"); - service_ret = calendar_record_create(_calendar_alarm._uri, &old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_create Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_create() Fail!: err[%d]", service_ret); } else if (old_data_has_alarm == 1) { _DEBUG_INFO("alarm record should be overwrited"); - service_ret = calendar_record_get_child_record_at_p(old_service_data, _calendar_event.calendar_alarm, 0, &old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_child_record_at_p(_calendar_alarm._uri) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); } else { - _DEBUG_ERROR("[dc_vcalendar_plugIn] this is an error. new_data_has_alarm = %d, old_data_has_alarm = %d", new_data_has_alarm, old_data_has_alarm); + _DEBUG_ERROR("[vcalendar] this is an error. new_data_has_alarm = %d, old_data_has_alarm = %d", new_data_has_alarm, old_data_has_alarm); return SYNC_AGENT_DA_ERRORS; } service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.type, type); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(type) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_lli(old_alarm_record, _calendar_alarm.time, alarm_time.time.utime); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_lli(time) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_lli() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.tick, tick); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(tick) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.tick_unit, tick_unit); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(tick_unit) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(old_alarm_record, _calendar_alarm.description, description); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_str(description) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_int(old_alarm_record, _calendar_alarm.alarm_id, alarm_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int(alarm_id) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_int() Fail!: err[%d]", service_ret); if (old_data_has_alarm == 0) { _DEBUG_INFO("alarm record should be created - add child rocord(alarm)"); service_ret = calendar_record_add_child_record(old_service_data, _calendar_event.calendar_alarm, old_alarm_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_add_child_record(calendar_alarm) Fail! err[%d]\n", service_ret); - return SYNC_AGENT_DA_ERRORS; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_add_child_record() Fail!: err[%d]", service_ret); } } /* image is not supported Outlook sync. So, image field should be not merged (2013/01/14 concept) */ - +return_part: + ret = _convert_service_error_to_common_error(service_ret); + _DEBUG_INFO("ret = %d", ret); _EXTERN_FUNC_EXIT; return ret; } @@ -663,61 +463,55 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_replace_converter(void *old_ _DEBUG_INFO("temp_agent_data = %s", temp_agent_data); - // 1. if the vcalendar has IMPORT_EXTYPE_DELETE_KEYWORD, then this vcalendar has an EXDATE data : it should be excuted before calendar_vcalendar_parse_to_calendar - // in case of 'exdate', exdate set to parent event and 'RETURN' this API + // 1. if the vcalendar has EXTYPE, then this vcalendar has an EXDATE data : it should be excuted before calendar_vcalendar_parse_to_calendar if (strstr(temp_agent_data, IMPORT_EXTYPE_DELETE_KEYWORD) != NULL) { - if (replace_exdate_data(temp_agent_data, temp_old_service_data) == SYNC_AGENT_DA_SUCCESS) { - _DEBUG_INFO("replace_exdate_data() success"); - *new_service_data = temp_old_service_data; - goto return_part; - } + replace_deleted_exdate_data(temp_agent_data, temp_old_service_data); + _DEBUG_INFO("after replace_deleted_exdate_data(), it should be returned from this API"); + *new_service_data = temp_old_service_data; + goto return_part; } - // 2. if the vcalendar has until : NONE rrule, then max rrule should be converted : it should be excuted before calendar_vcalendar_parse_to_calendar + // 2. if the vcalendar has UID, remove it : it should be excuted before calendar_vcalendar_parse_to_calendar + if (strstr(temp_agent_data, EXTYPE_UID_KEYWORD) != NULL) { + temp = strdup(temp_agent_data); + temp_agent_data = remove_uid(temp); + temp = NULL; + _DEBUG_INFO("after remove_uid(), temp_agent_data = %s", temp_agent_data); + } + + // 3. if the vcalendar has until : NONE rrule, then max rrule should be converted : it should be excuted before calendar_vcalendar_parse_to_calendar if (strstr(temp_agent_data, RRULE_KEYWORD) != NULL) { temp = strdup(temp_agent_data); - temp_agent_data = replace_max_rrule_data(temp); + temp_agent_data = replace_rrule_data(temp); temp = NULL; } service_ret = calendar_vcalendar_parse_to_calendar(temp_agent_data, &calendar_list); if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret); + _DEBUG_ERROR("[vcalendar] calendar_vcalendar_parse_to_calendar() Fail! err[%d]\n", service_ret); *new_service_data = NULL; goto return_part; } service_ret = calendar_list_first(calendar_list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_list_first() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_list_first() Fail!: err[%d]", service_ret); - int count = 0; - calendar_list_get_count(calendar_list, &count); - _DEBUG_INFO("count = %d", count); do { char *uri = NULL; char *key = NULL; service_ret = calendar_list_get_current_record_p(calendar_list, &temp_new_service_data); - if ((service_ret != CALENDAR_ERROR_NONE) || (temp_new_service_data == NULL)) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_list_get_current_record_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if((service_ret != CALENDAR_ERROR_NONE) || (temp_new_service_data == NULL), "[vcalendar] calendar_list_get_current_record_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_uri_p(temp_new_service_data, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_uri_p() Fail!: err[%d]", service_ret); _DEBUG_INFO("temp_new_service_data URI = %s", uri); if (!strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri))) { _DEBUG_INFO("this is event"); ret = _vevent_merge_new_to_old(temp_old_service_data, temp_new_service_data); if (ret != SYNC_AGENT_DA_SUCCESS) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_set_int() Fail! err[%d]\n", ret); + _DEBUG_ERROR("[vcalendar] calendar_record_set_int() Fail! err[%d]\n", ret); } // 1. "all day" setting : it should be excuted after calendar_vcalendar_parse_to_calendar @@ -727,18 +521,31 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_replace_converter(void *old_ } else if (!strncmp(uri, _calendar_extended_property._uri, strlen(_calendar_extended_property._uri))) { _DEBUG_INFO("this is extended"); - ret = calendar_record_get_str(temp_new_service_data, _calendar_extended_property.key, &key); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_str() Fail! : err[%d]", service_ret); - goto return_part; - } + service_ret = calendar_record_get_str(temp_new_service_data, _calendar_extended_property.key, &key); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); _DEBUG_INFO("key = %s", key); + if (strncmp(key, "VERSION", strlen("VERSION"))) { _DEBUG_INFO("this is extended, not VCALENDAR:VERSION extend"); calendar_record_add_child_record(temp_old_service_data, _calendar_event.extended, temp_new_service_data); } } } while(calendar_list_next(calendar_list) != CALENDAR_ERROR_NO_DATA); + + // 1. timezone setting : it should be excuted after calendar_vcalendar_parse_to_calendar + set_timezone(temp_agent_data, temp_old_service_data); + + // 2. if the vcalendar has EXTYPE, then this vcalendar has an EXDATE data : it should be excuted after calendar_vcalendar_parse_to_calendar + // exdate update should be done after _vevent_merge_new_to_old because it's changed things apply to the temp_old_service_data + if (strstr(temp_agent_data, IMPORT_EXTYPE_UPDATE_KEYWORD) != NULL) { + int child_service_id = replace_updated_exdate_data(temp_agent_data, temp_old_service_data); + if ( child_service_id != -1) { + _DEBUG_INFO("replace_updated_exdate_data() success. in case of success, it should be returned from this API"); + *new_service_data = g_strdup_printf("%d", child_service_id); + goto return_part; + } + } + *new_service_data = temp_old_service_data; return_part: @@ -777,213 +584,145 @@ EXPORT_API sync_agent_da_return_e sync_agent_plugin_reverse_converter(void *serv _DEBUG_INFO("converter start"); service_ret = calendar_record_get_caltime(item, _calendar_event.start_time, &cal_start_time); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_caltime() Fail!: err[%d]", service_ret); // 1. "all day" setting : it should be excuted before calendar_vcalendar_make_from_records if (cal_start_time.type == CALENDAR_TIME_LOCALTIME) { calendar_record_h extended_allday = NULL; service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_allday); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_create() Fail!: err[%d]", service_ret); + service_ret = calendar_record_set_str(extended_allday, _calendar_extended_property.key, "X-ALLDAY"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + service_ret = calendar_record_set_str(extended_allday, _calendar_extended_property.value, ":SET"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); + service_ret = calendar_record_add_child_record(temp_service_data, _calendar_event.extended, extended_allday); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_add_child_record() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_add_child_record() Fail!: err[%d]", service_ret); } // 2. "EXTYPE" setting, '1' means deleted, '2' means updated : it should be excuted before calendar_vcalendar_make_from_records exdate_struct = (sync_agent_calendar_exdate_t *)calloc(1, sizeof(sync_agent_calendar_exdate_t)); - if (exdate_struct == NULL) { - _DEBUG_ERROR("exdate_struct calloc fail"); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(exdate_struct == NULL, "exdate_struct is NULL"); + get_exdate_data(temp_service_data, exdate_struct); // 3. extended vcalendar version : it should be excuted before calendar_vcalendar_make_from_records service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_version); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_create() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(extended_version, _calendar_extended_property.key, "VERSION"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); service_ret = calendar_record_set_str(extended_version, _calendar_extended_property.value, ":1.0"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail!: err[%d]", service_ret); service_ret = calendar_list_create(&list); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_list_create() Fail!: err[%d]", service_ret); + service_ret = calendar_list_add(list, extended_version); - if (service_ret != CALENDAR_ERROR_NONE || list == NULL) { - _DEBUG_ERROR("calendar_list_add() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_list_add() Fail!: err[%d]", service_ret); service_ret = calendar_list_add(list, temp_service_data); - if (service_ret != CALENDAR_ERROR_NONE || list == NULL) { - _DEBUG_ERROR("calendar_list_add() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_list_add() Fail!: err[%d]", service_ret); char *exdate = NULL; service_ret = calendar_record_get_str(temp_service_data, _calendar_event.exdate, &exdate); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret); - goto return_part; - } - _DEBUG_INFO("exdate = %s", exdate); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_get_str() Fail!: err[%d]", service_ret); service_ret = calendar_vcalendar_make_from_records(list, &temp_agent_data); _DEBUG_INFO("temp_agent_data = %s", temp_agent_data); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_vcalendar_make_from_records() Fail!: err[%d]", service_ret); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_vcalendar_make_from_records() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); - goto return_part; - } - - // 1. remove 'timezone' : after calendar_vcalendar_make_from_records - _DEBUG_INFO("temp_agent_data = %s", temp_agent_data); - temp_agent_data = remove_timezone(temp_agent_data); - _DEBUG_INFO("temp_agent_data = %s", temp_agent_data); - - // 2. image converting : after calendar_vcalendar_make_from_records + // 1. image converting : after calendar_vcalendar_make_from_records char *image_path = has_image_export(image_item); if (image_path != NULL) { - _DEBUG_INFO("image is founded."); temp_agent_data = replace_image_data(temp_agent_data, image_path); } - // 3. exdate converting : after calendar_vcalendar_make_from_records + // 2. exdate converting : after calendar_vcalendar_make_from_records char *new_temp_agent_data = NULL; - if (exdate_struct->exdate_type != CALENDAR_EXDATE_TYPE_NONE) { + if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_DELETED) { int index=0; int exdate_count = exdate_struct->exdate_count; - _DEBUG_INFO("exdate_count = %d", exdate_count); + _DEBUG_INFO("deleted exdate_count = %d", exdate_count); + // 2-1. create child event based on parent event vcalendar agent_copied_str = strdup(temp_agent_data); for (index=0; indexexdate_type == CALENDAR_EXDATE_TYPE_UPDATED_PARENT) { + _DEBUG_INFO("CALENDAR_EXDATE_TYPE_UPDATED_PARENT start"); + if (strstr(temp_agent_data, CR_EXTYPE_UPDATE_KEYWORD) != NULL) { + temp_agent_data = replace_string(temp_agent_data, CR_EXTYPE_UPDATE_KEYWORD, "\r\nUID:000000000000000000000000000000000000000000000000"); + } + } + else if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_UPDATED_CHILD) { + _DEBUG_INFO("CALENDAR_EXDATE_TYPE_UPDATED_CHILD start"); + temp_agent_data = insert_exdate_data(temp_agent_data, exdate_struct, 0); + if (strstr(temp_agent_data, CR_EXTYPE_UPDATE_KEYWORD) != NULL) { + temp_agent_data = replace_string(temp_agent_data, CR_EXTYPE_UPDATE_KEYWORD, "\r\nUID:000000000000000000000000000000000000000000000000\r\nX-EXTYPE:2"); } - - _DEBUG_INFO("aaaaaaaaaaaaa temp_agent_data = %s", temp_agent_data); } return_part: _DEBUG_INFO("return_part"); + ret = _convert_service_error_to_common_error(service_ret); + _DEBUG_INFO("ret = %d", ret); + *agent_data = (void *)temp_agent_data; - if (list != NULL) { - service_ret = calendar_list_destroy(list, true); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_destroy() Fail!: err[%d]", service_ret); - ret = _convert_service_error_to_common_error(service_ret); + if (list != NULL) + calendar_list_destroy(list, true); + if (exdate_struct) { + if (exdate_struct->exdate_list) { + g_list_free(exdate_struct->exdate_list); + exdate_struct->exdate_list = NULL; } + free(exdate_struct); + exdate_struct = NULL; } - if (exdate_struct->exdate_list) { - g_list_free(exdate_struct->exdate_list); - exdate_struct->exdate_list = NULL; - } + _DEBUG_INFO("agent_data = %s", *agent_data); _EXTERN_FUNC_EXIT; return ret; @@ -992,7 +731,7 @@ return_part: EXPORT_API void *sync_agent_plugin_alloc_object() { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[dc_vcalendar_plugIn] not implement !!"); + _DEBUG_INFO("[vcalendar] not implement !!"); _EXTERN_FUNC_EXIT; return 0; } @@ -1000,7 +739,7 @@ EXPORT_API void *sync_agent_plugin_alloc_object() EXPORT_API int sync_agent_plugin_free_object(void *in_object) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[dc_vcalendar_plugIn] not implement !!"); + _DEBUG_INFO("[vcalendar] not implement !!"); _EXTERN_FUNC_EXIT; return 0; } @@ -1008,7 +747,7 @@ EXPORT_API int sync_agent_plugin_free_object(void *in_object) EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *extension_key, void *value) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[dc_vcalendar_plugIn] not implement !!"); + _DEBUG_INFO("[vcalendar] not implement !!"); _EXTERN_FUNC_EXIT; return 0; } @@ -1016,7 +755,7 @@ EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *ext EXPORT_API void *sync_agent_plugin_get_value(void *in_object, int key, char *extension_key) { _EXTERN_FUNC_ENTER; - _DEBUG_INFO("[dc_vcalendar_plugIn] not implement !!"); + _DEBUG_INFO("[vcalendar] not implement !!"); _EXTERN_FUNC_EXIT; return 0; } diff --git a/src/fw-plugins/common-public/vcalendar/src/vcalendar_string_util.c b/src/fw-plugins/common-public/vcalendar/src/vcalendar_string_util.c index cea8dce..e03e98a 100755 --- a/src/fw-plugins/common-public/vcalendar/src/vcalendar_string_util.c +++ b/src/fw-plugins/common-public/vcalendar/src/vcalendar_string_util.c @@ -23,6 +23,7 @@ #define EXPORT_API __attribute__ ((visibility("default"))) #endif + #if 0 // usage / rrule converting if (strstr(temp_agent_data, "\r\nRRULE:") != NULL) { @@ -293,7 +294,7 @@ static char * _replace_alarm_data(char *origin) snprintf(str_new_alarm, 30, "AALARM:%s\r\n", str_customized_trigger); _DEBUG_INFO("str_new_alarm = %s", str_new_alarm); - char *new_agent_data = _replace_string(origin, str_origin_alarm, str_new_alarm); + char *new_agent_data = replace_string(origin, str_origin_alarm, str_new_alarm); origin = NULL; origin = new_agent_data; goto return_part; @@ -307,18 +308,17 @@ static char * _replace_alarm_data(char *origin) } char *temp_alarm = NULL; - char *temp_alarm2 = NULL; if((temp_alarm = strstr(str_trigger, "P0W")) != NULL) { cal_type = CALENDAR_DATE_TYPE_ONTIME; interval = 0; } else if((temp_alarm = strstr(str_trigger, "PT")) != NULL) { - if((temp_alarm2 = strstr(temp_alarm, "H")) != NULL) { + if(strstr(temp_alarm, "H") != NULL) { cal_type = CALENDAR_DATE_TYPE_HOUR; str_interval = _get_value_by_token(str_trigger, "PT", "H"); interval = atoi(str_interval); } - else if((temp_alarm2 = strstr(temp_alarm, "M")) != NULL) { + else if(strstr(temp_alarm, "M") != NULL) { cal_type = CALENDAR_DATE_TYPE_MINUTE; str_interval = _get_value_by_token(str_trigger, "PT", "M"); interval = atoi(str_interval); @@ -329,12 +329,12 @@ static char * _replace_alarm_data(char *origin) } } else if((temp_alarm = strstr(str_trigger, "P")) != NULL) { - if((temp_alarm2 = strstr(temp_alarm, "D")) != NULL) { + if(strstr(temp_alarm, "D") != NULL) { cal_type = CALENDAR_DATE_TYPE_DAY; str_interval = _get_value_by_token(str_trigger, "P", "D"); interval = atoi(str_interval); } - else if((temp_alarm2 = strstr(temp_alarm, "W")) != NULL) { + else if(strstr(temp_alarm, "W") != NULL) { cal_type = CALENDAR_DATE_TYPE_WEEK; str_interval = _get_value_by_token(str_trigger, "P", "W"); interval = atoi(str_interval); @@ -358,7 +358,7 @@ static char * _replace_alarm_data(char *origin) _DEBUG_INFO("str_new_alarm = %s", str_new_alarm); _DEBUG_INFO("str_origin_alarm = %s", str_origin_alarm); - char *new_agent_data = _replace_string(origin, str_origin_alarm, str_new_alarm); + char *new_agent_data = replace_string(origin, str_origin_alarm, str_new_alarm); origin = NULL; origin = new_agent_data; @@ -534,19 +534,17 @@ char * get_value_by_token(const char *src, const char *token, const char *end_of if ((token_loc = strstr(src, token)) != NULL) { char *str_temp = strstr(token_loc, end_of_token); if (str_temp != NULL) { - _DEBUG_INFO("token_loc = %s", token_loc); - _DEBUG_INFO("token = %s", token); - _DEBUG_INFO("str_temp = %s", str_temp); int ret_str_length = strlen(token_loc) - strlen(token) - strlen(str_temp); if (ret_str_length <= 0) { + _DEBUG_ERROR("token_loc = %s", token_loc); + _DEBUG_ERROR("token = %s", token); + _DEBUG_ERROR("str_temp = %s", str_temp); _DEBUG_ERROR("ret_str_length(%d) <= 0", ret_str_length); goto return_part; } str_output = (char *)calloc(ret_str_length, sizeof(char)); - if (str_output == NULL) { - _DEBUG_ERROR("calloc failed"); - goto return_part; - } + goto_if(str_output == NULL, "str_output is NULL"); + memcpy(str_output, token_loc + strlen(token), ret_str_length); } } @@ -564,14 +562,9 @@ char * replace_string(char *origin, const char *src, const char *dest) retvm_if((src == NULL || strlen(src) <= 0), NULL, "src is NULL"); retvm_if((dest == NULL || strlen(dest) <= 0), NULL, "dest is NULL"); - _DEBUG_INFO("origin = %s", origin); - _DEBUG_INFO("src = %s", src); - _DEBUG_INFO("dest = %s", dest); - char *str_top = NULL; - if ((str_top = strstr(origin, src)) == NULL) { - _DEBUG_INFO("%s is not founed", src); + _DEBUG_ERROR("%s is not founed", src); return origin; } @@ -580,6 +573,9 @@ char * replace_string(char *origin, const char *src, const char *dest) int down_length = strlen(origin) - top_length - strlen(src); int new_str_length = top_length + middle_length + down_length + 1; if (new_str_length <= 0) { + _DEBUG_ERROR("top_length = %d", top_length); + _DEBUG_ERROR("middle_length = %d", middle_length); + _DEBUG_ERROR("down_length = %d", down_length); _DEBUG_ERROR("new_str_length(%d) <= 0", new_str_length); return origin; } @@ -604,48 +600,79 @@ char * replace_string(char *origin, const char *src, const char *dest) return new_str; } -char * remove_timezone(char *origin) +// PLM(P130408-0777) : In case of DTSTART / DTEND with zulu time ('Z'), GMT timezone should be set. +EXPORT_API void set_timezone(const char *origin, calendar_record_h cal_record) { _INNER_FUNC_ENTER; - retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL"); + retm_if(origin == NULL, "origin is NULL"); + retm_if(cal_record == NULL, "cal_record is NULL"); - _DEBUG_INFO("origin = %s", origin); + int service_ret = CALENDAR_ERROR_NONE; + char *temp = NULL; + char *str_start = NULL; - char *str_timezone = NULL; - char *str_temp = NULL; + temp = strstr(origin, DTSTART_KEYWORD); + goto_if(temp == NULL, "origin has not DTSTART. origin = %s", origin); - if ((str_temp = strstr(origin, "\r\nDTSTART;TZID=")) != NULL) { - _DEBUG_INFO("str_temp = %s", str_temp); - str_timezone = get_value_by_token(str_temp, "\r\nDTSTART", ":"); - _DEBUG_INFO("str_timezone = %s", str_timezone); - strcat(str_timezone, ":"); - _DEBUG_INFO("str_timezone = %s", str_timezone); - origin = replace_string(origin, str_timezone, ":"); + str_start = get_value_by_token(temp + 2, "DTSTART:", "\r\n"); + goto_if(str_start == NULL, "str_start is NULL. temp = %s", temp); - if (str_timezone) - free(str_timezone); - str_timezone = NULL; - } + if (strstr(str_start, "Z") != NULL) { + _DEBUG_INFO("GMT timezone setting"); + service_ret = calendar_record_set_str(cal_record, _calendar_event.start_tzid, TIMEZONE_GMT); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail! : err[%d]", service_ret); - if ((str_temp = strstr(origin, "\r\nDTEND;TZID=")) != NULL) { - _DEBUG_INFO("str_temp = %s", str_temp); - str_timezone = get_value_by_token(str_temp, "\r\nDTEND", ":"); - _DEBUG_INFO("str_timezone = %s", str_timezone); - strcat(str_timezone, ":"); - _DEBUG_INFO("str_timezone = %s", str_timezone); - origin = replace_string(origin, str_timezone, ":"); + service_ret = calendar_record_set_str(cal_record, _calendar_event.end_tzid, TIMEZONE_GMT); + goto_if(service_ret != CALENDAR_ERROR_NONE, "[vcalendar] calendar_record_set_str() Fail! : err[%d]", service_ret); + } - if (str_timezone) - free(str_timezone); - str_timezone = NULL; +return_part: + if (str_start) { + free(str_start); + str_start = NULL; } + _INNER_FUNC_EXIT; + return; +} + +char * remove_uid(char *origin) +{ + _INNER_FUNC_ENTER; + retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL"); _DEBUG_INFO("origin = %s", origin); + + char *str_uid = NULL; + char *str_uid_temp = NULL; + char *temp = NULL; + + if ((temp = strstr(origin, EXTYPE_UID_KEYWORD)) == NULL) { + _DEBUG_ERROR("origin has not UID string"); + goto return_part; + } + + str_uid = get_value_by_token(temp+2, "UID:", "\r\n"); + goto_if(str_uid == NULL, "str_uid is NULL"); + + str_uid_temp = g_strdup_printf("%s%s\r\n", EXTYPE_UID_KEYWORD, str_uid); + goto_if(str_uid_temp == NULL, "str_uid_temp is NULL"); + + origin = replace_string(origin, str_uid_temp, "\r\n"); + +return_part: + if (str_uid) { + free(str_uid); + str_uid = NULL; + } + if (str_uid_temp) { + free(str_uid_temp); + str_uid_temp = NULL; + } _INNER_FUNC_EXIT; return origin; } -char * insert_exdate_data(const char *origin, sync_agent_calendar_exdate_t *exdate_struct, int index) +char * insert_exdate_data(char *origin, sync_agent_calendar_exdate_t *exdate_struct, int index) { _INNER_FUNC_ENTER; retvm_if((origin == NULL || strlen(origin) <= 0), NULL, "origin is NULL"); @@ -657,9 +684,9 @@ char * insert_exdate_data(const char *origin, sync_agent_calendar_exdate_t *exda // 1. copy from parent vcalendar string char *str_child_vcalendar = strdup((char *)(origin)); - if (exdate_struct->exdate_type != CALENDAR_EXDATE_TYPE_DELETED && exdate_struct->exdate_type != CALENDAR_EXDATE_TYPE_UPDATED) { - _DEBUG_ERROR("exdate_type(%d) is wrong", exdate_struct->exdate_type); - goto return_part; + if (exdate_struct->exdate_type <= CALENDAR_EXDATE_TYPE_NONE && exdate_struct->exdate_type >= CALENDAR_EXDATE_TYPE_MAX) { + _DEBUG_ERROR("exdate_type(%d) is wrong type", exdate_struct->exdate_type); + goto return_part_free; } _DEBUG_INFO("origin = %s", origin); @@ -667,50 +694,40 @@ char * insert_exdate_data(const char *origin, sync_agent_calendar_exdate_t *exda if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_DELETED) { _DEBUG_INFO("delete"); + // 2. remove SUMMARY / RRULE / ALARM / EXDATE // 2-1. remove 'SUMMARY' if ((old_str = strstr(str_child_vcalendar, SUMMARY_KEYWORD)) != NULL) { _DEBUG_INFO("summary keyword"); - _DEBUG_INFO("old_str = %s", old_str); if ((new_str = strstr(old_str+2, "\r\n")) != NULL) { - _DEBUG_INFO("new_str = %s", new_str); str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } } // 2-2. remove 'RRULE' if ((old_str = strstr(str_child_vcalendar, RRULE_KEYWORD)) != NULL) { _DEBUG_INFO("rrule keyword"); - _DEBUG_INFO("old_str = %s", old_str); if ((new_str = strstr(old_str+2, "\r\n")) != NULL) { - _DEBUG_INFO("new_str = %s", new_str); str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } } // 2-3. remove 'ALARM' if ((old_str = strstr(str_child_vcalendar, AALARM_KEYWORD)) != NULL) { _DEBUG_INFO("alarm keyword"); - _DEBUG_INFO("old_str = %s", old_str); if ((new_str = strstr(old_str+2, "\r\n")) != NULL) { - _DEBUG_INFO("new_str = %s", new_str); str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } } // 2-4. remove 'EXDATE' array if ((old_str = strstr(str_child_vcalendar, EXDATE_KEYWORD)) != NULL) { _DEBUG_INFO("exdate keyword"); - _DEBUG_INFO("old_str = %s", old_str); if ((new_str = strstr(old_str+2, "\r\nX-EXTYPE:1")) != NULL) { - _DEBUG_INFO("new_str = %s", new_str); str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } } + _DEBUG_INFO("after 2nd phase str_child_vcalendar = %s", str_child_vcalendar); // 3. change DTSTART / DTEND // example ) DTSTART:20130125T000000Z / DTEND:20130125T003000Z / EXDATE:20130201T000000Z => DTSTART:20130201T000000Z / DTEND:20130201T003000Z @@ -718,222 +735,132 @@ char * insert_exdate_data(const char *origin, sync_agent_calendar_exdate_t *exda char *temp = NULL; if ((temp = strstr(str_child_vcalendar, DTSTART_KEYWORD)) != NULL) { _DEBUG_INFO("start keyword"); - _DEBUG_INFO("temp = %s", temp ); old_str = get_value_by_token(temp + 2, "DTSTART:", "\r\n");// '2' means strlen("\r\n") if (old_str == NULL) { _DEBUG_ERROR("old_str is null"); - goto return_part; + goto return_part_free; } - _DEBUG_INFO("old_str = %s", old_str); new_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index); if (new_str == NULL) { _DEBUG_ERROR("new_str is NULL"); - goto return_part; + goto return_part_free; } - _DEBUG_INFO("new_str = %s", new_str); str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); + if (old_str) { + free(old_str); + old_str = NULL; + } } // 3-2. change DTEND : DTEND = date of EXDATE + time of origin DTEND temp = NULL; if ((temp = strstr(str_child_vcalendar, DTEND_KEYWORD)) != NULL) { _DEBUG_INFO("end keyword"); - _DEBUG_INFO("temp = %s", temp ); old_str = get_value_by_token(temp + 2, "DTEND:", "\r\n");// '2' means strlen("\r\n") if (old_str == NULL) { _DEBUG_ERROR("old_str is null"); - goto return_part; + goto return_part_free; } - _DEBUG_INFO("old_str = %s", old_str); char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index); if (exdate_str == NULL) { _DEBUG_ERROR("exdate_str is NULL"); - goto return_part; + goto return_part_free; } _DEBUG_INFO("exdate_str = %s", exdate_str); new_str = (char *)calloc(strlen(exdate_str), sizeof(char)); if (new_str == NULL) { _DEBUG_ERROR("new_str calloc failed"); - goto return_part; + goto return_part_free; } memcpy(new_str, exdate_str, 8); memcpy(new_str + 8, old_str + 8, 8); - _DEBUG_INFO("new_str = %s", new_str); str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); + if (old_str) { + free(old_str); + old_str = NULL; + } if (new_str) { free(new_str); new_str = NULL; } - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } + _DEBUG_INFO("after 3rd phase str_child_vcalendar = %s", str_child_vcalendar); // 4. insert EXDATE - if ((temp = strstr(str_child_vcalendar, END_VEVENT_KEYWORD)) != NULL) { + if (strstr(str_child_vcalendar, END_VEVENT_KEYWORD) != NULL) { _DEBUG_INFO("EXTYPE keyword"); - _DEBUG_INFO("temp = %s", temp); + char *str_end_vevent = "\r\nEND:VEVENT"; char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index); if (exdate_str == NULL) { _DEBUG_ERROR("exdate_str is NULL"); - goto return_part; + goto return_part_free; } - _DEBUG_INFO("exdate_str = %s", exdate_str); - new_str = (char *)calloc(100, sizeof(char)); + new_str = g_strdup_printf("%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent); if (new_str == NULL) { - _DEBUG_ERROR("new_str calloc failed"); - goto return_part; + _DEBUG_ERROR("new_str is null"); + goto return_part_free; } - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); - char *str_end_vevent = "\r\nEND:VEVENT"; - snprintf(new_str, 100, "%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent); - _DEBUG_INFO("new_str = %s", new_str); + str_child_vcalendar = replace_string(str_child_vcalendar, str_end_vevent, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); if (new_str) { free(new_str); new_str = NULL; } - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } - if ((temp = strstr(str_child_vcalendar, EXTYPE_DELETE_KEYWORD)) != NULL) { + if (strstr(str_child_vcalendar, EXTYPE_DELETE_KEYWORD) != NULL) { str_child_vcalendar = replace_string(str_child_vcalendar, EXTYPE_DELETE_KEYWORD, "UID:000000000000000000000000000000000000000000000000\r\nX-EXTYPE:1"); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } + goto return_part_free; } - else if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_UPDATED) { - _DEBUG_INFO("update"); - // 2. remove RRULE / EXDATE - // 2-1. remove 'RRULE' + else if (exdate_struct->exdate_type == CALENDAR_EXDATE_TYPE_UPDATED_CHILD) { + _DEBUG_INFO("update child"); + + // 2. remove 'RRULE' if ((old_str = strstr(str_child_vcalendar, RRULE_KEYWORD)) != NULL) { _DEBUG_INFO("rrule keyword"); - _DEBUG_INFO("old_str = %s", old_str); - if ((new_str = strstr(old_str+2, "\r\n")) != NULL) { - _DEBUG_INFO("new_str = %s", new_str); - str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); - } - } - - // 2-2. remove 'EXDATE' array - if ((old_str = strstr(str_child_vcalendar, EXDATE_KEYWORD)) != NULL) { - _DEBUG_INFO("exdate keyword"); - _DEBUG_INFO("old_str = %s", old_str); if ((new_str = strstr(old_str+2, "\r\n")) != NULL) { - _DEBUG_INFO("new_str = %s", new_str); str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); - } - } - - // 3. change DTSTART / DTEND - // example ) DTSTART:20130125T000000Z / DTEND:20130125T003000Z / EXDATE:20130201T000000Z => DTSTART:20130201T000000Z / DTEND:20130201T003000Z - // 3-1. change DTSTART : DTSTART = EXDATE - char *temp = NULL; - if ((temp = strstr(str_child_vcalendar, DTSTART_KEYWORD)) != NULL) { - _DEBUG_INFO("start keyword"); - _DEBUG_INFO("temp = %s", temp ); - - old_str = get_value_by_token(temp + 2, "DTSTART:", "\r\n");// '2' means strlen("\r\n") - if (old_str == NULL) { - _DEBUG_ERROR("old_str is null"); - goto return_part; } - _DEBUG_INFO("old_str = %s", old_str); - new_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index); - if (new_str == NULL) { - _DEBUG_ERROR("new_str is NULL"); - goto return_part; - } - _DEBUG_INFO("new_str = %s", new_str); - str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } - // 3-2. change DTEND : DTEND = date of EXDATE + time of origin DTEND - temp = NULL; - if ((temp = strstr(str_child_vcalendar, DTEND_KEYWORD)) != NULL) { - _DEBUG_INFO("end keyword"); - _DEBUG_INFO("temp = %s", temp ); - - old_str = get_value_by_token(temp + 2, "DTEND:", "\r\n");// '2' means strlen("\r\n") - if (old_str == NULL) { - _DEBUG_ERROR("old_str is null"); - goto return_part; - } - _DEBUG_INFO("old_str = %s", old_str); - char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index); - if (exdate_str == NULL) { - _DEBUG_ERROR("exdate_str is NULL"); - goto return_part; - } - _DEBUG_INFO("exdate_str = %s", exdate_str); - new_str = (char *)calloc(strlen(exdate_str), sizeof(char)); - if (new_str == NULL) { - _DEBUG_ERROR("new_str calloc failed"); - goto return_part; - } - - memcpy(new_str, exdate_str, 8); - memcpy(new_str + 8, old_str + 8, 8); - _DEBUG_INFO("new_str = %s", new_str); - str_child_vcalendar = replace_string(str_child_vcalendar, old_str, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); - if (new_str) { - free(new_str); - new_str = NULL; - } - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); - } - - // 4. insert EXDATE - if ((temp = strstr(str_child_vcalendar, END_VEVENT_KEYWORD)) != NULL) { + // 3. insert EXDATE + if (strstr(str_child_vcalendar, END_VEVENT_KEYWORD) != NULL) { _DEBUG_INFO("EXTYPE keyword"); - _DEBUG_INFO("temp = %s", temp); + char *str_end_vevent = "\r\nEND:VEVENT"; char *exdate_str = (char*)g_list_nth_data(exdate_struct->exdate_list, index); - if (exdate_str == NULL) { - _DEBUG_ERROR("exdate_str is NULL"); - goto return_part; - } + goto_if(exdate_str == NULL, "exdate_str is NULL"); _DEBUG_INFO("exdate_str = %s", exdate_str); - new_str = (char *)calloc(100, sizeof(char)); - if (new_str == NULL) { - _DEBUG_ERROR("new_str calloc failed"); - goto return_part; - } - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); - char *str_end_vevent = "\r\nEND:VEVENT"; - snprintf(new_str, 100, "%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent); - _DEBUG_INFO("new_str = %s", new_str); + new_str = g_strdup_printf("%s%s%s", EXDATE_KEYWORD, exdate_str, str_end_vevent); + goto_if(new_str == NULL, "new_str is NULL"); + str_child_vcalendar = replace_string(str_child_vcalendar, str_end_vevent, new_str); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); if (new_str) { free(new_str); new_str = NULL; } - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); - } - - if ((temp = strstr(str_child_vcalendar, EXTYPE_UPDATE_KEYWORD)) != NULL) { - str_child_vcalendar = replace_string(str_child_vcalendar, EXTYPE_UPDATE_KEYWORD, "UID:000000000000000000000000000000000000000000000000\r\nX-EXTYPE:2"); - _DEBUG_INFO("str_child_vcalendar = %s", str_child_vcalendar); } } - else { - _DEBUG_INFO("cal_exdate_type(%d) is wrong type", exdate_struct->exdate_type); - } return_part: + _DEBUG_INFO("last str_child_vcalendar = %s", str_child_vcalendar); _INNER_FUNC_EXIT; + return str_child_vcalendar; + +return_part_free: _DEBUG_INFO("last str_child_vcalendar = %s", str_child_vcalendar); + if (old_str) { + free(old_str); + old_str = NULL; + } + _INNER_FUNC_EXIT; return str_child_vcalendar; } @@ -947,10 +874,7 @@ void insert_allday_data(const char *origin, calendar_record_h calendar_record) char *uri = NULL; service_ret = calendar_record_get_uri_p(calendar_record, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_uri_p() Fail!: err[%d]", service_ret); if (strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri))) { _DEBUG_ERROR("this is not event"); @@ -964,10 +888,7 @@ void insert_allday_data(const char *origin, calendar_record_h calendar_record) int day = 0; service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.start_time, &cal_time_start); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() Fail!: err[%d]", service_ret); char *start_date_loc = NULL; if ((start_date_loc = strstr(origin, DTSTART_KEYWORD)) == NULL) { @@ -995,16 +916,10 @@ void insert_allday_data(const char *origin, calendar_record_h calendar_record) cal_time_start.time.date.mday = day; service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.start_time, cal_time_start); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_caltime(calendar_record, _calendar_event.end_time, &cal_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_caltime() Fail: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_caltime() Fail!: err[%d]", service_ret); char *end_date_loc = NULL; if ((end_date_loc = strstr(origin, DTEND_KEYWORD)) == NULL) { @@ -1032,10 +947,7 @@ void insert_allday_data(const char *origin, calendar_record_h calendar_record) cal_time_end.time.date.mday = day; service_ret = calendar_record_set_caltime(calendar_record, _calendar_event.end_time, cal_time_end); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_caltime() Fail: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_caltime() Fail!: err[%d]", service_ret); return_part: _INNER_FUNC_EXIT; @@ -1048,13 +960,15 @@ EXPORT_API char * has_image_import(const char *origin) char *temp_image_path = NULL; char *image_path = NULL; + _DEBUG_INFO("origin = %s", origin); - if (strstr(origin, IMAGE_KEYWORD_PREFIX_PHOTO) == NULL && strstr(origin, IMAGE_KEYWORD_PREFIX_SNOTE) == NULL) { + if (strstr(origin, CR_IMAGE_KEYWORD_PREFIX_PHOTO) == NULL && strstr(origin, CR_IMAGE_KEYWORD_PREFIX_SNOTE) == NULL) { _DEBUG_INFO("this calendar has not an image"); goto return_part; } temp_image_path = get_value_by_token(origin, IMAGE_KEYWORD_BEGIN_PATH, IMAGE_KEYWORD_END_PATH); + goto_if(temp_image_path == NULL, "temp_image_path is NULL"); if (strstr(temp_image_path, INTERNAL_MEMORY_CONVERTED) != NULL) { image_path = replace_string(temp_image_path, INTERNAL_MEMORY_CONVERTED, INTERNAL_MEMORY_ORIGIN); @@ -1091,40 +1005,24 @@ EXPORT_API char * has_image_export(calendar_record_h cal_record) char *uri = NULL; service_ret = calendar_record_get_uri_p(cal_record, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar-task_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_uri_p() Fail!: err[%d]", service_ret); + _DEBUG_INFO("uri = %s", uri); - _DEBUG_INFO("_calendar_event.uri = %s", _calendar_event._uri); service_ret = calendar_record_get_child_record_count(cal_record, _calendar_event.extended, &child_record_count); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_child_record_count() Fail: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() Fail!: err[%d]", service_ret); for (i = 0; i < child_record_count; i++) { service_ret = calendar_record_get_child_record_at_p(cal_record, _calendar_event.extended, i, &image_record); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_get_child_record_at_p() Fail: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_at_p() Fail!: err[%d]", service_ret); service_ret = calendar_record_get_str_p(image_record, _calendar_extended_property.key, &image_key); - if (service_ret != CALENDAR_ERROR_NONE || image_key == NULL || strlen(image_key) <= 0) { - _DEBUG_ERROR("calendar_record_get_str_p is failed(%d)", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE || image_key == NULL || strlen(image_key) <= 0, "calendar_record_get_str_p() Fail!: err[%d]", service_ret); if (strcmp(image_key, CALENDAR_IMAGE_KEYWORD_SNOTE) == 0 || strcmp(image_key, CALENDAR_IMAGE_KEYWORD_PHOTO) == 0) { _DEBUG_INFO("image is founded. image_key = %s", image_key); service_ret = calendar_record_get_str(image_record, _calendar_extended_property.value, &image_path); - if (service_ret != CALENDAR_ERROR_NONE || image_path == NULL || strlen(image_path) <= 0) { - _DEBUG_ERROR("calendar_record_get_str_p is failed(%d)", service_ret); - image_path = NULL; - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE || image_path == NULL || strlen(image_path) <= 0, "calendar_record_get_str() Fail!: err[%d]", service_ret); _DEBUG_INFO("image_path = %s", image_path); continue; } @@ -1143,60 +1041,52 @@ void get_exdate_data(calendar_record_h cal_record, sync_agent_calendar_exdate_t retm_if(exdate_struct == NULL, "exdate_struct is NULL"); calendar_record_h extended_exdate = NULL; - char *exdate = NULL; - char *recurrence_id = NULL; int service_ret = CALENDAR_ERROR_NONE; int original_event_id = 0; + char *exdate = NULL; + char *recurrence_id = NULL; exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_NONE; + exdate_struct->exdate_count = 0; + exdate_struct->exdate_list = NULL; + service_ret = calendar_record_get_int(cal_record, _calendar_event.original_event_id, &original_event_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_int() Fail!: err[%d]", service_ret); + _DEBUG_INFO("original_event_id = %d", original_event_id); - char *uri = NULL; - service_ret = calendar_record_get_uri_p(cal_record, &uri); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("[dc_vcalendar_plugIn] calendar_record_get_uri_p() Fail! : err[%d]", service_ret); - goto return_part; + service_ret = calendar_record_get_str(cal_record, _calendar_event.recurrence_id, &recurrence_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_str() Fail!: err[%d]", service_ret); + _DEBUG_INFO("recurrence_id = %s", recurrence_id); + + if (original_event_id >= 0 && recurrence_id != NULL && strlen(recurrence_id) > 0) { + service_ret = calendar_record_set_str(cal_record, _calendar_event.exdate, NULL); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret); } - _DEBUG_INFO("uri = %s", uri); // 1. delete : if 'exdate' value is exist, there are deleted item. service_ret = calendar_record_get_str(cal_record, _calendar_event.exdate, &exdate); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_str() Fail!: err[%d]", service_ret); _DEBUG_INFO("exdate = %s", exdate); if (exdate != NULL && strlen(exdate) > 0) { _DEBUG_INFO("EXTYPE:DELETE setting start"); service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_exdate); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_create() Fail!: err[%d]", service_ret); + service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.key, "X-EXTYPE"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret); + service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.value, ":1"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret); + service_ret = calendar_record_add_child_record(cal_record, _calendar_event.extended, extended_exdate); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_add_child_record() Fail!: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() Fail!: err[%d]", service_ret); exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_DELETED; char *str_exdate_loc = NULL; int exdate_count = 0; int exdate_loc = 0; while (exdate_loc < strlen(exdate)) { - _DEBUG_INFO("111111111111 exdate_loc = %d", exdate_loc); - _DEBUG_INFO("111111111111 strlen(exdate) = %d", strlen(exdate)); int one_exdate_length = 0; if ((str_exdate_loc = strstr(exdate + exdate_loc, ",")) != NULL) { one_exdate_length = strlen(exdate) - strlen(str_exdate_loc) - (exdate_count*(DATE_TIME_LENGTH+1)); @@ -1219,57 +1109,54 @@ void get_exdate_data(calendar_record_h cal_record, sync_agent_calendar_exdate_t exdate_struct->exdate_list = g_list_append(exdate_struct->exdate_list, str_one_exdate); exdate_count++; _DEBUG_INFO("str_one_exdate = %s", str_one_exdate); - _DEBUG_INFO("one_exdate_length = %d", one_exdate_length); - _DEBUG_INFO("exdate_loc = %d", exdate_loc); - _DEBUG_INFO("exdate_count = %d\n\n", exdate_count); } - _DEBUG_INFO("exdate_loc = %d", exdate_loc); _DEBUG_INFO("exdate_count = %d", exdate_count); exdate_struct->exdate_count = exdate_count; _DEBUG_INFO("EXTYPE:DELETE setting end"); + goto return_part; } - _DEBUG_INFO("222222222"); // 2. update : if 'origianl_event_id' and 'recurrence_id' value are exist, there are updated item. - service_ret = calendar_record_get_int(cal_record, _calendar_event.original_event_id, &original_event_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret); - goto return_part; - } - _DEBUG_INFO("original_event_id = %d", original_event_id); + if (original_event_id < 0 && recurrence_id == NULL ) { + unsigned int count = 0; + service_ret = calendar_record_get_child_record_count(cal_record, _calendar_event.exception, &count); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_child_record_count() Fail! err[%d]\n", service_ret); + if (count <=0) { + _DEBUG_INFO("this is a normal calendar"); + goto return_part; + } - service_ret = calendar_record_get_str(cal_record, _calendar_event.recurrence_id, &recurrence_id); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_list_create() Fail!: err[%d]", service_ret); - goto return_part; - } - _DEBUG_INFO("recurrence_id = %s", recurrence_id); + _DEBUG_INFO("parent EXTYPE:UPDATE setting start"); + exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_UPDATED_PARENT; + service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_exdate); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_create() Fail! err[%d]\n", service_ret); - if (original_event_id > 0 && recurrence_id != NULL && strlen(recurrence_id) > 0) { - _DEBUG_INFO("EXTYPE:UPDATE setting start"); + service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.key, "X-EXTYPE"); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret); + + service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.value, ":2"); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret); + + service_ret = calendar_record_add_child_record(cal_record, _calendar_event.extended, extended_exdate); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() Fail! err[%d]\n", service_ret); + } + else if (original_event_id >= 0 && recurrence_id != NULL && strlen(recurrence_id) > 0) { + _DEBUG_INFO("child EXTYPE:UPDATE setting start"); + exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_UPDATED_CHILD; + exdate_struct->exdate_list = g_list_append(exdate_struct->exdate_list, recurrence_id); + exdate_struct->exdate_count = 1; service_ret = calendar_record_create(_calendar_extended_property._uri, &extended_exdate); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_create() Fail!: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_create() Fail!: err[%d]", service_ret); + service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.key, "X-EXTYPE"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret); + service_ret = calendar_record_set_str(extended_exdate, _calendar_extended_property.value, ":2"); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail!: err[%d]", service_ret); - goto return_part; - } + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret); + service_ret = calendar_record_add_child_record(cal_record, _calendar_event.extended, extended_exdate); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_add_child_record() Fail!: err[%d]", service_ret); - goto return_part; - } - exdate_struct->exdate_type = CALENDAR_EXDATE_TYPE_UPDATED; - _DEBUG_INFO("EXTYPE:UPDATE setting end"); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_add_child_record() Fail! err[%d]\n", service_ret); } return_part: @@ -1277,7 +1164,7 @@ return_part: return; } -char * replace_max_rrule_data(char *origin) +char * replace_rrule_data(char *origin) { _INNER_FUNC_ENTER; retvm_if(origin == NULL, origin, "origin is NULL."); @@ -1287,17 +1174,25 @@ char * replace_max_rrule_data(char *origin) char *str_old_rrule = NULL; char *str_new_rrule = NULL; - if ((temp = strstr(origin, RRULE_KEYWORD)) == NULL) { + temp = strstr(origin, RRULE_KEYWORD); + if (temp == NULL) { _DEBUG_INFO("this vcalendar hasn't rrule data"); goto return_part; } - str_old_rrule = get_value_by_token(temp + 2, "RRULE:", "\r\n");// '2' means strlen("\r\n") - if (str_old_rrule == NULL) { - _DEBUG_ERROR("str_old_rrule is null"); + // case 1 : weekdays rrule converting + if (strstr(origin, WEEKDAY_RRULE_ORIGIN_KEYWORD) != NULL) { + _DEBUG_INFO("this vcalendar has WEEKDAYS rrule data"); + + origin = replace_string(origin, WEEKDAY_RRULE_ORIGIN_KEYWORD, WEEKDAY_RRULE_CONVERTED_KEYWORD); + _DEBUG_INFO("AFTER origin = %s", origin); goto return_part; } + // case 2 : max rrule converting + str_old_rrule = get_value_by_token(temp + 2, "RRULE:", "\r\n");// '2' means strlen("\r\n") + goto_if(str_old_rrule == NULL, "str_old_rrule is null"); + if (strstr(str_old_rrule, MAX_RRULE_DATE_KEYWORD) == NULL) { _DEBUG_INFO("this vcalendar has rrule data, But it's not until=NONE rrule"); goto return_part; @@ -1305,19 +1200,13 @@ char * replace_max_rrule_data(char *origin) _DEBUG_INFO("this vcalendar has until=NONE rrule"); temp_rrule = get_value_by_token(temp, RRULE_KEYWORD, MAX_RRULE_DATE_KEYWORD); - if (temp_rrule == NULL) { - _DEBUG_ERROR("temp_rrule is null"); - goto return_part; - } - - str_new_rrule = (char *)calloc(strlen(temp_rrule) + 2, sizeof(char)); - if (str_new_rrule == NULL) { - _DEBUG_ERROR("str_new_rrule calloc failed"); - goto return_part; - } + goto_if(temp_rrule == NULL, "temp_rrule is null"); // every eternal rrule data must have '#0' at the end of string (Calendar-Svc recommend) - snprintf(str_new_rrule, strlen(temp_rrule) + 2, "%s#0", temp_rrule); + str_new_rrule = g_strdup_printf("%s#0", temp_rrule); + goto_if(str_new_rrule == NULL, "str_new_rrule is null"); + _DEBUG_INFO("str_new_rrule = %s", str_new_rrule); + origin = replace_string(origin, str_old_rrule, str_new_rrule); return_part: @@ -1334,7 +1223,6 @@ return_part: temp_rrule = NULL; } _INNER_FUNC_EXIT; - _DEBUG_INFO("origin = %s", origin); return origin; } @@ -1344,48 +1232,32 @@ char * replace_image_data(char *origin, char *image_path) retvm_if(origin == NULL, origin, "origin is NULL."); retvm_if(image_path == NULL, origin, "image_path is NULL."); - int image_path_length = 500; char *str_temp_image_info = NULL; char *str_image_info = NULL; char *str_image_tag = NULL; - _DEBUG_INFO("origin = %s", origin); - _DEBUG_INFO("image_path = %s", image_path); - if (strstr(image_path, INTERNAL_MEMORY_ORIGIN) != NULL) { str_temp_image_info = replace_string(image_path, INTERNAL_MEMORY_ORIGIN, INTERNAL_MEMORY_CONVERTED); - str_image_tag = strdup("X-SS-ATTACH-IMAGE"); + str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO); } else if (strstr(image_path, EXTERNAL_MEMORY_ORIGIN) != NULL) { str_temp_image_info = replace_string(image_path, EXTERNAL_MEMORY_ORIGIN, EXTERNAL_MEMORY_CONVERTED); - str_image_tag = strdup("X-SS-ATTACH-IMAGE"); + str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO); } else if (strstr(image_path, SNOTE_MEMORY_ORIGIN) != NULL) { str_temp_image_info = strdup(image_path); - //str_image_tag = strdup("X-SS-ATTACH-SNOTE"); - str_image_tag = strdup("X-SS-ATTACH-IMAGE"); + //str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_SNOTE); + str_image_tag = strdup(IMAGE_KEYWORD_PREFIX_PHOTO); } else { _DEBUG_ERROR("there is an error. image_path = %s", image_path); goto return_part; } - if (strstr(origin, END_VEVENT_KEYWORD) == NULL) { - _DEBUG_ERROR("this data is wrong format. origin = %s", origin); - goto return_part; - } - - if (image_path_length <= 0) { - _DEBUG_ERROR("image_path_length(%d) <= 0", image_path_length); - goto return_part; - } - str_image_info = (char *)calloc(image_path_length, sizeof(char)); - if (str_image_info == NULL) { - _DEBUG_ERROR("str_image_info calloc failed"); - goto return_part; - } + goto_if(strstr(origin, END_VEVENT_KEYWORD) == NULL, "this data is wrong format. origin = %s", origin); - snprintf(str_image_info, image_path_length, "\r\n%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:NAME=3Dnull=3BPATH=3D%s=3BDATE=3D%s", str_image_tag, str_temp_image_info, END_VEVENT_KEYWORD); + str_image_info = g_strdup_printf("\r\n%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:NAME=3Dnull=3BPATH=3D%s=3BDATE=3D%s", str_image_tag, str_temp_image_info, END_VEVENT_KEYWORD); + goto_if(str_image_info == NULL, "str_image_info is null"); char *new_agent_data = replace_string(origin, END_VEVENT_KEYWORD, str_image_info); origin = NULL; @@ -1407,16 +1279,15 @@ return_part: } _INNER_FUNC_EXIT; - _DEBUG_INFO("origin = %s", origin); return origin; } -// exdate string format like as "20130211T000000Z,20130211T000000Z,20130211T000000Z" -sync_agent_da_return_e replace_exdate_data(const char *origin, calendar_record_h calendar_record) +// exdate string format like as "20130211T000000Z,20130212T000000Z,20130213T000000Z" +void replace_deleted_exdate_data(const char *origin, calendar_record_h parent_record) { _INNER_FUNC_ENTER; - retvm_if(origin == NULL, SYNC_AGENT_DA_ERRORS, "origin is NULL."); - retvm_if(calendar_record == NULL, SYNC_AGENT_DA_ERRORS, "calendar_record is NULL"); + retm_if(origin == NULL, "origin is NULL."); + retm_if(parent_record == NULL, "parent_record is NULL"); char *str_exdata_loc = NULL; char *old_exdate_str = NULL; @@ -1424,37 +1295,32 @@ sync_agent_da_return_e replace_exdate_data(const char *origin, calendar_record_h char *new_one_exdate_str = NULL; int exdate_length = 0; int service_ret = CALENDAR_ERROR_NONE; - sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; - if ((str_exdata_loc = strstr(origin, IMPORT_EXTYPE_DELETE_KEYWORD)) == NULL) { - _DEBUG_ERROR("this vcalendar has not exdate data"); - ret = SYNC_AGENT_DA_ERRORS; - goto return_part; - } + str_exdata_loc = strstr(origin, IMPORT_EXTYPE_DELETE_KEYWORD); + goto_if(str_exdata_loc == NULL, "this vcalendar has not exdate data"); new_one_exdate_str = get_value_by_token(str_exdata_loc + 2, "EXDATE:", "\r\n"); _DEBUG_INFO("new_one_exdate_str = %s", new_one_exdate_str); - service_ret = calendar_record_get_str(calendar_record, _calendar_event.exdate, &old_exdate_str); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret); - goto return_part; - } + service_ret = calendar_record_get_str(parent_record, _calendar_event.exdate, &old_exdate_str); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret); _DEBUG_INFO("old_exdate_str = %s", old_exdate_str); int old_exdate_str_length = 0; - if (old_exdate_str == NULL) + if (old_exdate_str == NULL) { old_exdate_str_length = 0; - else + } + else { old_exdate_str_length = strlen(old_exdate_str); + if (strstr(old_exdate_str, new_one_exdate_str) != NULL) { + _DEBUG_ERROR("new_one_exdate_str is already exist in old_exdate_str"); + goto return_part; + } + } exdate_length = old_exdate_str_length + strlen(new_one_exdate_str) + 2; - _DEBUG_INFO("exdate_length = %d", exdate_length); new_exdate_str = (char *)calloc(exdate_length, sizeof(char)); - if (new_exdate_str == NULL) { - _DEBUG_ERROR("new_exdate_str calloc failed"); - goto return_part; - } + goto_if(new_exdate_str == NULL, "new_exdate_str calloc failed, exdate_length = %d", exdate_length); if (old_exdate_str == NULL) snprintf(new_exdate_str, exdate_length, "%s", new_one_exdate_str); @@ -1462,12 +1328,8 @@ sync_agent_da_return_e replace_exdate_data(const char *origin, calendar_record_h snprintf(new_exdate_str, exdate_length, "%s,%s", old_exdate_str, new_one_exdate_str); _DEBUG_INFO("new_exdate_str = %s", new_exdate_str); - - service_ret = calendar_record_set_str(calendar_record, _calendar_event.exdate, new_exdate_str); - if (service_ret != CALENDAR_ERROR_NONE) { - _DEBUG_ERROR("calendar_record_set_str() Fail! err[%d]\n", service_ret); - goto return_part; - } + service_ret = calendar_record_set_str(parent_record, _calendar_event.exdate, new_exdate_str); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail! err[%d]\n", service_ret); return_part: if(new_one_exdate_str) { @@ -1479,5 +1341,61 @@ return_part: new_exdate_str = NULL; } _INNER_FUNC_EXIT; + return; +} + +int replace_updated_exdate_data(const char *origin, calendar_record_h parent_record) +{ + _INNER_FUNC_ENTER; + retvm_if(origin == NULL, -1, "origin is NULL."); + retvm_if(parent_record == NULL, -1, "parent_record is NULL"); + + calendar_record_h child_record = NULL; + char *str_exdata_loc = NULL; + char *new_one_exdate_str = NULL; + int parent_service_id = 0; + int child_service_id = 0; + int service_ret = CALENDAR_ERROR_NONE; + int ret = -1; + + str_exdata_loc = strstr(origin, IMPORT_EXTYPE_UPDATE_KEYWORD); + goto_if(str_exdata_loc == NULL, "this vcalendar has not exdate data"); + + new_one_exdate_str = get_value_by_token(str_exdata_loc + 2, "EXDATE:", "\r\n"); + _DEBUG_INFO("new_one_exdate_str = %s", new_one_exdate_str); + + service_ret = calendar_record_clone(parent_record, &child_record); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_clone() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_get_int(parent_record, _calendar_event.id, &parent_service_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_get_int() Fail!: err[%d]", service_ret); + _DEBUG_INFO("parent_service_id = %d", parent_service_id); + + service_ret = calendar_record_set_int(child_record, _calendar_event.original_event_id, parent_service_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_int() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(child_record, _calendar_event.recurrence_id, new_one_exdate_str); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_set_str(child_record, _calendar_event.exdate, NULL); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_set_str() Fail!: err[%d]", service_ret); + + service_ret = calendar_db_insert_record(child_record, &child_service_id); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_db_insert_record() Fail!: err[%d]", service_ret); + + service_ret = calendar_record_destroy(child_record, true); + goto_if(service_ret != CALENDAR_ERROR_NONE, "calendar_record_destroy() Fail!: err[%d]", service_ret); + _DEBUG_INFO("child_service_id = %d", child_service_id); + + ret = child_service_id; + +return_part: + if(new_one_exdate_str) { + free(new_one_exdate_str); + new_one_exdate_str = NULL; + } + if (service_ret != CALENDAR_ERROR_NONE) + ret = -1; + _INNER_FUNC_EXIT; return ret; } -- 2.7.4