3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include "utility/sync_util.h"
22 #include "utility/fw_alloc.h"
24 #include "account/manager.h"
25 #include "account/util_internal.h"
27 #include "data-adapter/agent_handler_manager.h"
28 #include "data-adapter/agent_handler_manager_internal.h"
29 #include "data-adapter/common.h"
30 #include "data-adapter/luid.h"
32 #include "data-adapter/changelog.h"
33 #include "data-adapter/changelog_internal.h"
35 #include "data-adapter/interface_changelog.h"
36 #include "data-adapter/agent.h"
39 #define EXPORT_API __attribute__ ((visibility("default")))
42 #ifndef SYNC_AGENT_LOG
44 #define LOG_TAG "AF_DACI"
47 static pthread_mutex_t change_lock;
49 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)
53 retvm_if(service_item_id == NULL, 0, "service item id is NULL !!");
56 * TODO : 1. Need to Null check parameter
57 * 2. converting type : itemType, folderType
58 * 3. get fw id : accountID, folderID
59 * 4. check whether the item is included
60 * 5. generate item luid
61 * 6. add item & change log
63 if (pthread_mutex_lock(&change_lock)) {
64 _DEBUG_INFO("pthread_mutex_lock error\n");
68 _DEBUG_INFO("Index : %d", index);
69 _DEBUG_INFO("service_accountID : %d", service_account_id);
70 _DEBUG_INFO("service_itemID : %s", service_item_id);
71 _DEBUG_INFO("itemType : %d", item_type);
72 _DEBUG_INFO("service_folderID : %s", service_folder_id);
73 _DEBUG_INFO("folderType : %d", folder_type);
74 _DEBUG_INFO("parent_service_item_id : %s", parent_service_item_id);
76 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
77 sync_agent_da_return_e open_ret = SYNC_AGENT_DA_SUCCESS;
78 char *fw_folder_id = NULL;
79 char *fw_item_id = NULL;
80 char **fw_item_id_list = NULL;
81 sync_agent_da_item_s item;
82 sync_agent_da_item_changelog_s item_changelog;
84 open_ret = sync_agent_open_agent();
85 _DEBUG_INFO("Done Open Agent DB : %d", open_ret);
88 sync_agent_da_return_e daci_res = sync_agent_begin_transaction();
89 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
90 _DEBUG_ERROR("sync_agent_begin_transaction fail");
94 * if folderID value is NULL ==> folderID set NULL
96 if ((service_folder_id != NULL) && !strcmp(service_folder_id, ""))
97 service_folder_id = NULL;
102 int fw_account_id = acc_get_fw_account_id(item_type, service_account_id, index);
103 _DEBUG_INFO("fw_account_id : %d", fw_account_id);
105 if (fw_account_id == -1) {
106 _DEBUG_ERROR("fw account id does not exist");
113 fw_folder_id = da_get_folder_id_by_service_id_wrapper(fw_account_id, item_type, service_folder_id, folder_type);
114 if (fw_folder_id == NULL) {
115 _DEBUG_ERROR("fw folder id does not exist");
120 * check whether the item is included
122 fw_item_id = da_get_item_id_internal(fw_account_id, service_item_id, item_type);
123 if (fw_item_id != NULL) {
124 _DEBUG_ERROR("service_item_id already exists : %s", service_item_id);
131 fw_item_id_list = sync_agent_generate_item_luid(1, 1);
132 if (fw_item_id_list == NULL) {
133 _DEBUG_ERROR("Failed to Generate Item LUID");
137 fw_item_id = fw_item_id_list[0];
138 if (fw_item_id == NULL) {
139 _DEBUG_ERROR("Failed to Generate Item LUID");
144 item.account_id = fw_account_id;
145 item.item_id = fw_item_id;
146 item.folder_id = fw_folder_id;
147 item.data_store_id = item_type;
148 item.service_id = service_item_id;
149 item.parent_service_id = parent_service_item_id;
150 item.access_name = "DACI_ChangeLog";
152 ret = da_add_item_internal(&item, 1);
153 if (ret != SYNC_AGENT_DA_SUCCESS) {
154 _DEBUG_ERROR("Failed to Add Item : %d", ret);
158 // add change log (only for normal item not calendar exdate item)
159 if (parent_service_item_id == NULL) {
160 item_changelog.item_id = fw_item_id;
161 item_changelog.operation_id = 301;
162 item_changelog.status = "SYNC_REQUIRED";
163 item_changelog.access_name = "DACI_ChangeLog";
165 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
166 if (ret != SYNC_AGENT_DA_SUCCESS) {
167 _DEBUG_ERROR("Failed to Add Item changelog : %d", ret);
174 daci_res = sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT);
175 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
176 _DEBUG_ERROR("sync_agent_end_transaction fail");
179 open_ret = sync_agent_close_agent();
180 _DEBUG_INFO("Done Close Agent DB : %d", open_ret);
182 if (fw_folder_id != NULL) {
186 if (fw_item_id != NULL) {
190 if (fw_item_id_list != NULL) {
191 free(fw_item_id_list);
192 fw_item_id_list = NULL;
194 if (pthread_mutex_unlock(&change_lock)) {
195 _DEBUG_ERROR("pthread_mutex_unlock error\n");
204 int da_handle_del_item(int service_account_id, int index, char *service_item_id, int item_type)
208 retvm_if(service_item_id == NULL, 0, "service item id is NULL !!");
211 * TODO : 1. Need to Null check parameter
212 * 2. converting type : itemType
213 * 3. get fw id : accountID
214 * 4. check whether the item is included
215 * 5. check whether the change log is included
216 * 6. add/update/delete item change log
218 _DEBUG_INFO("service_accountID : %d", service_account_id);
219 _DEBUG_INFO("index : %d", index);
220 _DEBUG_INFO("service_itemID : %s", service_item_id);
221 _DEBUG_INFO("itemType : %d", item_type);
223 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
224 sync_agent_da_return_e open_ret = SYNC_AGENT_DA_SUCCESS;
226 char *fw_item_id = NULL;
227 sync_agent_da_item_changelog_s item_changelog;
228 item_changelog.status = NULL;
229 item_changelog.access_name = NULL;
231 open_ret = sync_agent_open_agent();
232 _DEBUG_INFO("Done Open Agent DB : %d", open_ret);
235 sync_agent_da_return_e daci_res = sync_agent_begin_transaction();
236 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
237 _DEBUG_ERROR("sync_agent_begin_transaction fail");
243 int fw_account_id = acc_get_fw_account_id(item_type, service_account_id, index);
244 if (fw_account_id == -1) {
245 _DEBUG_ERROR("fw account id does not exist");
250 * check whether the item is included
252 fw_item_id = da_get_item_id_internal(fw_account_id, service_item_id, item_type);
253 if (fw_item_id != NULL) {
254 _DEBUG_INFO("Item Already Exists : %s", fw_item_id);
256 _DEBUG_ERROR("Item is not existed!!");
260 /* check whether the change log is included */
261 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
262 item_changelog.item_id = fw_item_id;
263 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
265 switch (item_changelog.operation_id) {
268 _DEBUG_INFO("Item Changelog Already Exists : ADD Operation");
269 ret = da_delete_item_by_item_id_internal(fw_item_id);
270 if (ret != SYNC_AGENT_DA_SUCCESS) {
271 _DEBUG_ERROR("Failed to Delete Item : %d", ret);
275 ret = da_delete_item_changelog_by_item_id_internal(fw_account_id, fw_item_id);
276 if (ret != SYNC_AGENT_DA_SUCCESS) {
277 _DEBUG_ERROR("Failed to Delete Item Change Log : %d", ret);
282 case 302: /* UPDATE */
284 _DEBUG_INFO("Item Changelog Already Exists : UPDATE Operation");
285 item_changelog.operation_id = 303;
286 ret = da_set_item_changelog_operation_id_wrapper(fw_account_id, &item_changelog);
287 if (ret != SYNC_AGENT_DA_SUCCESS) {
288 _DEBUG_ERROR("Failed to Delete Item : %d", ret);
293 case 303: /* DELETE */
295 _DEBUG_INFO("Item Changelog Already Exists : DELETE Operation");
304 item_changelog.item_id = fw_item_id;
305 item_changelog.operation_id = 303;
306 item_changelog.status = strdup("SYNC_REQUIRED");
307 item_changelog.access_name = strdup("DACI_ChangeLog");
309 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
310 if (ret != SYNC_AGENT_DA_SUCCESS) {
311 _DEBUG_ERROR("Failed to Add Item Change Log : %d", ret);
318 daci_res = sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT);
319 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
320 _DEBUG_ERROR("sync_agent_end_transaction fail");
322 open_ret = sync_agent_close_agent();
323 _DEBUG_INFO("Done Close Agent DB : %d", open_ret);
325 if (fw_item_id != NULL) {
329 if (item_changelog.status != NULL) {
330 free(item_changelog.status);
331 item_changelog.status = NULL;
333 if (item_changelog.access_name != NULL) {
334 free(item_changelog.access_name);
335 item_changelog.access_name = NULL;
343 int da_handle_update_item(int service_account_id, int index, char *service_item_id, char *parent_service_item_id, int item_type)
347 retvm_if(service_item_id == NULL, 0, "service item id is NULL !!");
350 * TODO : 1. Need to Null check parameter
351 * 2. converting type : itemType
352 * 3. get fw id : accountID
353 * 4. check whether the item is included
354 * 5. check whether the change log is included
355 * 6. add item change log
358 _DEBUG_INFO("service_accountID : %d", service_account_id);
359 _DEBUG_INFO("service_itemID : %s", service_item_id);
360 _DEBUG_INFO("itemType : %d", item_type);
361 _DEBUG_INFO("parent_service_item_id : %s", parent_service_item_id);
363 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
364 sync_agent_da_return_e open_ret = SYNC_AGENT_DA_SUCCESS;
366 char *fw_item_id = NULL;
367 sync_agent_da_item_changelog_s item_changelog;
368 item_changelog.status = NULL;
369 item_changelog.access_name = NULL;
371 open_ret = sync_agent_open_agent();
372 _DEBUG_INFO("Done Open Agent DB : %d", open_ret);
375 sync_agent_da_return_e daci_res = sync_agent_begin_transaction();
376 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
377 _DEBUG_ERROR("sync_agent_begin_transaction fail");
383 int fw_account_id = acc_get_fw_account_id(item_type, service_account_id, index);
384 if (fw_account_id == -1) {
385 _DEBUG_ERROR("fw account id does not exist");
390 * check whether the item is included
392 fw_item_id = da_get_item_id_internal(fw_account_id, service_item_id, item_type);
393 if (fw_item_id != NULL) {
394 _DEBUG_INFO("Item Already Exists : %s", fw_item_id);
396 _DEBUG_ERROR("Item is Not Existed!!");
401 * check whether the change log is included
403 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
404 item_changelog.item_id = fw_item_id;
405 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
407 if (item_changelog.operation_id == 303) { /* DELETE */
408 _DEBUG_ERROR("Already Deleted Item : %s", fw_item_id);
415 item_changelog.item_id = fw_item_id;
416 item_changelog.operation_id = 302;
417 item_changelog.status = strdup("SYNC_REQUIRED");
418 item_changelog.access_name = strdup("DACI_ChangeLog");
420 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
421 if (ret != SYNC_AGENT_DA_SUCCESS) {
422 _DEBUG_ERROR("Failed to Add Item Change Log : %d", ret);
427 // update parent_id (only for Calendar exdate item)
428 if (parent_service_item_id != NULL) {
429 ret = da_update_item_internal(fw_item_id, parent_service_item_id);
430 if (ret != SYNC_AGENT_DA_SUCCESS) {
431 _DEBUG_ERROR("da_update_item_internal failed");
437 _DEBUG_INFO("return_part");
438 daci_res = sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT);
439 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
440 _DEBUG_ERROR("sync_agent_end_transaction fail");
442 open_ret = sync_agent_close_agent();
443 _DEBUG_INFO("Done Close Agent DB : %d", open_ret);
445 if (fw_item_id != NULL) {
449 if (item_changelog.status != NULL) {
450 free(item_changelog.status);
451 item_changelog.status = NULL;
453 if (item_changelog.access_name != NULL) {
454 free(item_changelog.access_name);
455 item_changelog.access_name = NULL;
462 int da_changelog_add_item_internal(sync_agent_da_item_s *item)
466 retvm_if(item == NULL, 0, "fw item id is NULL !!");
469 * TODO : 1. Need to Null check parameter
470 * 2. converting type : itemType
471 * 3. check whether the item is included
472 * 4. generate item luid
473 * 5. add item & change log
475 _DEBUG_INFO("item_id : %s", item->item_id);
476 _DEBUG_INFO("data_store_id : %d", item->data_store_id);
477 _DEBUG_INFO("account_id : %d", item->account_id);
478 _DEBUG_INFO("folder_id : %s", item->folder_id);
479 _DEBUG_INFO("service_id : %s", item->service_id);
480 _DEBUG_INFO("parent_service_id : %s", item->parent_service_id);
482 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
483 sync_agent_da_item_changelog_s item_changelog;
486 item->access_name = "DACI_ChangeLog";
487 ret = da_add_item_internal(item, 1);
488 if (ret != SYNC_AGENT_DA_SUCCESS) {
489 _DEBUG_ERROR("add item failed return : %d", ret);
494 item_changelog.item_id = item->item_id;
495 item_changelog.operation_id = 301;
496 item_changelog.status = "SYNC_REQUIRED";
497 item_changelog.access_name = "DACI_ChangeLog";
499 ret = da_add_item_changelog_wrapper(item->account_id, &item_changelog, 1);
500 if (ret != SYNC_AGENT_DA_SUCCESS) {
501 _DEBUG_ERROR("add item changelog failed return : %d", ret);
510 EXPORT_API sync_agent_da_return_e sync_agent_changelog_add_item_new(sync_agent_da_item_s * sync_agent_item, char **item_id)
514 retvm_if(sync_agent_item == NULL, SYNC_AGENT_DA_ERRORS, "sync_agent_da_item_s is NULL !!");
517 * TODO : 1. Need to Null check parameter
518 * 2. converting type : itemType
519 * 3. check whether the item is included
520 * 4. generate item luid
521 * 5. add item & change log
523 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
524 sync_agent_da_item_changelog_s item_changelog;
527 ret = sync_agent_add_item_new(sync_agent_item, 1, item_id);
528 if (ret != SYNC_AGENT_DA_SUCCESS) {
529 _DEBUG_ERROR("add item failed return : %d", ret);
534 item_changelog.item_id = *item_id;
535 item_changelog.operation_id = 301;
536 item_changelog.status = "SYNC_REQUIRED";
537 item_changelog.access_name = "DACI_ChangeLog";
539 ret = da_add_item_changelog_wrapper(sync_agent_item->account_id, &item_changelog, 1);
540 if (ret != SYNC_AGENT_DA_SUCCESS) {
541 _DEBUG_ERROR("add item changelog failed return : %d", ret);
550 int da_changelog_delete_item_internal(int fw_account_id, char *fw_item_id, int item_type)
554 retvm_if(fw_item_id == NULL, 0, "fw item id is NULL !!");
557 * TODO : 1. Need to Null check parameter
558 * 2. check whether the item is included
559 * 3. check whether the change log is included
560 * 4. add/update/delete item change log
562 _DEBUG_INFO("fw_account_id : %d", fw_account_id);
563 _DEBUG_INFO("fw_item_id : %s", fw_item_id);
564 _DEBUG_INFO("itemType : %d", item_type);
566 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
568 sync_agent_da_item_changelog_s item_changelog;
569 item_changelog.status = NULL;
570 item_changelog.access_name = NULL;
573 * check whether the item is included
575 ret = da_is_exist_item_wrapper(fw_item_id);
577 _DEBUG_INFO("Item already exists : %s", fw_item_id);
579 _DEBUG_ERROR("Item is not existed!!");
584 * check whether the change log is included
586 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
587 item_changelog.item_id = fw_item_id;
588 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
590 switch (item_changelog.operation_id) {
593 _DEBUG_INFO("Item changelog already exists : ADD Operation");
594 ret = da_delete_item_by_item_id_internal(fw_item_id);
595 if (ret != SYNC_AGENT_DA_SUCCESS) {
596 _DEBUG_ERROR("Failed to Delete Item : %d", ret);
600 ret = da_delete_item_changelog_by_item_id_internal(fw_account_id, fw_item_id);
601 if (ret != SYNC_AGENT_DA_SUCCESS) {
602 _DEBUG_ERROR("Failed to Delete Item Change Log : %d", ret);
607 case 302: /* UPDATE */
609 _DEBUG_INFO("Item Changelog Already Exists : UPDATE Operation");
610 item_changelog.operation_id = 303;
611 ret = da_set_item_changelog_operation_id_wrapper(fw_account_id, &item_changelog);
612 if (ret != SYNC_AGENT_DA_SUCCESS) {
613 _DEBUG_ERROR("Failed to Set Item ChangeLog Operation : %d", ret);
618 case 303: /* DELETE */
620 _DEBUG_INFO("Item Changelog Already Exists : DELETE Operation");
628 item_changelog.item_id = fw_item_id;
629 item_changelog.operation_id = 303;
630 item_changelog.status = strdup("SYNC_REQUIRED");
631 item_changelog.access_name = strdup("DACI_ChangeLog");
633 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
634 if (ret != SYNC_AGENT_DA_SUCCESS) {
635 _DEBUG_ERROR("[da_changelog_delete_item_internal] add item change log failed return : %d", ret);
641 if (item_changelog.status != NULL) {
642 free(item_changelog.status);
643 item_changelog.status = NULL;
645 if (item_changelog.access_name != NULL) {
646 free(item_changelog.access_name);
647 item_changelog.access_name = NULL;
655 EXPORT_API sync_agent_da_return_e sync_agent_changelog_delete_item_new(int fw_account_id, char *fw_item_id)
659 retvm_if(fw_item_id == NULL, SYNC_AGENT_DA_ERRORS, "fw item id is NULL !!");
662 * TODO : 1. Need to Null check parameter
663 * 2. check whether the item is included
664 * 3. check whether the change log is included
665 * 4. add/update/delete item change log
667 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
669 sync_agent_da_item_changelog_s item_changelog;
670 item_changelog.status = NULL;
671 item_changelog.access_name = NULL;
674 * check whether the item is included
676 ret = da_is_exist_item_wrapper(fw_item_id);
678 _DEBUG_INFO("Item already exists : %s", fw_item_id);
679 // ret = sync_agent_delete_item_by_item_id(fw_item_id);
680 // if (ret != SYNC_AGENT_DA_SUCCESS) {
681 // _DEBUG_ERROR("sync_agent_delete_item() failed !! : %d", ret);
684 // _DEBUG_INFO("sync_agent_delete_item() success !!");
687 _DEBUG_ERROR("Item is not existed!!");
692 * check whether the change log is included
694 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
695 item_changelog.item_id = fw_item_id;
696 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
698 switch (item_changelog.operation_id) {
701 _DEBUG_INFO("Item changelog already exists : ADD Operation");
702 ret = da_delete_item_by_item_id_internal(fw_item_id);
703 if (ret != SYNC_AGENT_DA_SUCCESS) {
704 _DEBUG_ERROR("Failed to Delete Item : %d", ret);
708 ret = da_delete_item_changelog_by_item_id_internal(fw_account_id, fw_item_id);
709 if (ret != SYNC_AGENT_DA_SUCCESS) {
710 _DEBUG_ERROR("Failed to Delete Item Change Log : %d", ret);
715 case 302: /* UPDATE */
717 _DEBUG_INFO("Item Changelog Already Exists : UPDATE Operation");
718 item_changelog.operation_id = 303;
719 ret = da_set_item_changelog_operation_id_wrapper(fw_account_id, &item_changelog);
720 if (ret != SYNC_AGENT_DA_SUCCESS) {
721 _DEBUG_ERROR("Failed to Set Item ChangeLog Operation : %d", ret);
726 case 303: /* DELETE */
728 _DEBUG_INFO("Item Changelog Already Exists : DELETE Operation");
736 item_changelog.item_id = fw_item_id;
737 item_changelog.operation_id = 303;
738 item_changelog.status = strdup("SYNC_REQUIRED");
739 item_changelog.access_name = strdup("DACI_ChangeLog");
741 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
742 if (ret != SYNC_AGENT_DA_SUCCESS) {
743 _DEBUG_ERROR("[da_changelog_delete_item_internal] add item change log failed return : %d", ret);
749 if (item_changelog.status != NULL) {
750 free(item_changelog.status);
751 item_changelog.status = NULL;
753 if (item_changelog.access_name != NULL) {
754 free(item_changelog.access_name);
755 item_changelog.access_name = NULL;
763 int da_changelog_update_item_internal(int fw_account_id, char *fw_item_id, int item_type)
767 retvm_if(fw_item_id == NULL, 0, "fw item id is NULL !!");
770 * TODO : 1. Need to Null check parameter
771 * 2. converting type : itemType
772 * 3. check whether the item is included
773 * 4. check whether the change log is included
774 * 5. add item change log
777 _DEBUG_INFO("fw_account_id : %d", fw_account_id);
778 _DEBUG_INFO("fw_item_id : %s", fw_item_id);
779 _DEBUG_INFO("itemType : %d", item_type);
781 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
783 sync_agent_da_item_changelog_s item_changelog;
784 item_changelog.status = NULL;
785 item_changelog.access_name = NULL;
788 * check whether the item is included
790 ret = da_is_exist_item_wrapper(fw_item_id);
792 _DEBUG_INFO("Item already exists : %s", fw_item_id);
794 _DEBUG_ERROR("Item is not existed!!");
798 /* check whether the change log is included */
799 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
800 item_changelog.item_id = fw_item_id;
801 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
803 if (item_changelog.operation_id == 303) { /* DELETE */
804 _DEBUG_ERROR("already deleted item");
812 item_changelog.item_id = fw_item_id;
813 item_changelog.operation_id = 302;
814 item_changelog.status = strdup("SYNC_REQUIRED");
815 item_changelog.access_name = strdup("DACI_ChangeLog");
817 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
818 if (ret != SYNC_AGENT_DA_SUCCESS) {
819 _DEBUG_ERROR("Failed to Add Item Change Log : %d", ret);
825 if (item_changelog.status != NULL) {
826 free(item_changelog.status);
827 item_changelog.status = NULL;
829 if (item_changelog.access_name != NULL) {
830 free(item_changelog.access_name);
831 item_changelog.access_name = NULL;
839 EXPORT_API sync_agent_da_return_e sync_agent_changelog_update_item_new(int fw_account_id, char *fw_item_id)
843 retvm_if(fw_item_id == NULL, SYNC_AGENT_DA_ERRORS, "fw item id is NULL !!");
846 * TODO : 1. Need to Null check parameter
847 * 2. converting type : itemType
848 * 3. check whether the item is included
849 * 4. check whether the change log is included
850 * 5. add item change log
852 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
854 sync_agent_da_item_changelog_s item_changelog;
855 item_changelog.status = NULL;
856 item_changelog.access_name = NULL;
859 * check whether the item is included
861 ret = da_is_exist_item_wrapper(fw_item_id);
863 _DEBUG_INFO("Item already exists : %s", fw_item_id);
865 _DEBUG_ERROR("Item is not existed!!");
869 /* check whether the change log is included */
870 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
871 item_changelog.item_id = fw_item_id;
872 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
874 if (item_changelog.operation_id == 303) { /* DELETE */
875 _DEBUG_ERROR("already deleted item");
883 item_changelog.item_id = fw_item_id;
884 item_changelog.operation_id = 302;
885 item_changelog.status = strdup("SYNC_REQUIRED");
886 item_changelog.access_name = strdup("DACI_ChangeLog");
888 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
889 if (ret != SYNC_AGENT_DA_SUCCESS) {
890 _DEBUG_ERROR("Failed to Add Item Change Log : %d", ret);
896 if (item_changelog.status != NULL) {
897 free(item_changelog.status);
898 item_changelog.status = NULL;
900 if (item_changelog.access_name != NULL) {
901 free(item_changelog.access_name);
902 item_changelog.access_name = NULL;
910 int da_handle_del_child_item(char *parent_service_id, char *child_service_id)
913 retvm_if(parent_service_id == NULL, 0, "parent_service_id is NULL!!");
915 sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
916 // If child_service_id is null, it means that all child item should be deleted.
917 if (child_service_id) {
918 _DEBUG_INFO("parent id = %s, child id = %s", parent_service_id, child_service_id);
919 ret = da_delete_child_item_internal(parent_service_id, child_service_id);
920 goto_if(ret != SYNC_AGENT_DA_SUCCESS, "da_delete_child_item_internal() failed");
923 sync_agent_da_return_e open_ret = sync_agent_open_agent();
924 _DEBUG_INFO("Done Open Agent DB : %d", open_ret);
926 sync_agent_da_return_e daci_res = sync_agent_begin_transaction();
927 if (daci_res != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("sync_agent_begin_transaction fail"); }
929 ret = da_delete_all_child_item_internal(parent_service_id);
930 if (ret != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("da_delete_all_child_item_internal() failed"); }
932 daci_res = sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT);
933 if (daci_res != SYNC_AGENT_DA_SUCCESS) { _DEBUG_ERROR("sync_agent_end_transaction fail"); }
935 open_ret = sync_agent_close_agent();
936 _DEBUG_INFO("Done Close Agent DB : %d", open_ret);