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, 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);
75 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
76 sync_agent_da_return_e open_ret = SYNC_AGENT_DA_SUCCESS;
77 char *fw_folder_id = NULL;
78 char *fw_item_id = NULL;
79 char **fw_item_id_list = NULL;
80 sync_agent_da_item_s item;
81 sync_agent_da_item_changelog_s item_changelog;
83 open_ret = sync_agent_open_agent();
84 _DEBUG_INFO("Done Open Agent DB : %d", open_ret);
87 sync_agent_da_return_e daci_res = sync_agent_begin_transaction();
88 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
89 _DEBUG_ERROR("sync_agent_begin_transaction fail");
93 * if folderID value is NULL ==> folderID set NULL
95 if ((service_folder_id != NULL) && !strcmp(service_folder_id, ""))
96 service_folder_id = NULL;
101 int fw_account_id = acc_get_fw_account_id(item_type, service_account_id, index);
102 _DEBUG_INFO("fw_account_id : %d", fw_account_id);
104 if (fw_account_id == -1) {
105 _DEBUG_ERROR("fw account id does not exist");
112 fw_folder_id = da_get_folder_id_by_service_id_wrapper(fw_account_id, item_type, service_folder_id, folder_type);
113 if (fw_folder_id == NULL) {
114 _DEBUG_ERROR("fw folder id does not exist");
119 * check whether the item is included
121 fw_item_id = da_get_item_id_internal(fw_account_id, service_item_id, item_type);
122 if (fw_item_id != NULL) {
123 _DEBUG_ERROR("service_item_id already exists : %s", service_item_id);
130 fw_item_id_list = sync_agent_generate_item_luid(1, 1);
131 if (fw_item_id_list == NULL) {
132 _DEBUG_ERROR("Failed to Generate Item LUID");
136 fw_item_id = fw_item_id_list[0];
137 if (fw_item_id == NULL) {
138 _DEBUG_ERROR("Failed to Generate Item LUID");
145 item.account_id = fw_account_id;
146 item.item_id = fw_item_id;
147 item.folder_id = fw_folder_id;
148 item.data_store_id = item_type;
149 item.service_id = 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);
161 item_changelog.item_id = fw_item_id;
162 item_changelog.operation_id = 301;
163 item_changelog.status = "SYNC_REQUIRED";
164 item_changelog.access_name = "DACI_ChangeLog";
166 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
167 if (ret != SYNC_AGENT_DA_SUCCESS) {
168 _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, 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);
362 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
363 sync_agent_da_return_e open_ret = SYNC_AGENT_DA_SUCCESS;
365 char *fw_item_id = NULL;
366 sync_agent_da_item_changelog_s item_changelog;
367 item_changelog.status = NULL;
368 item_changelog.access_name = NULL;
370 open_ret = sync_agent_open_agent();
371 _DEBUG_INFO("Done Open Agent DB : %d", open_ret);
374 sync_agent_da_return_e daci_res = sync_agent_begin_transaction();
375 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
376 _DEBUG_ERROR("sync_agent_begin_transaction fail");
382 int fw_account_id = acc_get_fw_account_id(item_type, service_account_id, index);
383 if (fw_account_id == -1) {
384 _DEBUG_ERROR("fw account id does not exist");
389 * check whether the item is included
391 fw_item_id = da_get_item_id_internal(fw_account_id, service_item_id, item_type);
392 if (fw_item_id != NULL) {
393 _DEBUG_INFO("Item Already Exists : %s", fw_item_id);
395 _DEBUG_ERROR("Item is Not Existed!!");
400 * check whether the change log is included
402 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
403 item_changelog.item_id = fw_item_id;
404 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
406 if (item_changelog.operation_id == 303) { /* DELETE */
407 _DEBUG_ERROR("Already Deleted Item : %s", fw_item_id);
414 item_changelog.item_id = fw_item_id;
415 item_changelog.operation_id = 302;
416 item_changelog.status = strdup("SYNC_REQUIRED");
417 item_changelog.access_name = strdup("DACI_ChangeLog");
419 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
420 if (ret != SYNC_AGENT_DA_SUCCESS) {
421 _DEBUG_ERROR("Failed to Add Item Change Log : %d", ret);
428 daci_res = sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT);
429 if (daci_res != SYNC_AGENT_DA_SUCCESS) {
430 _DEBUG_ERROR("sync_agent_end_transaction fail");
432 open_ret = sync_agent_close_agent();
433 _DEBUG_INFO("Done Close Agent DB : %d", open_ret);
435 if (fw_item_id != NULL) {
439 if (item_changelog.status != NULL) {
440 free(item_changelog.status);
441 item_changelog.status = NULL;
443 if (item_changelog.access_name != NULL) {
444 free(item_changelog.access_name);
445 item_changelog.access_name = NULL;
453 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)
457 retvm_if(fw_item_id == NULL, 0, "fw item id is NULL !!");
458 retvm_if(service_item_id == NULL, 0, "service item id is NULL !!");
459 retvm_if(fw_folder_id == NULL, 0, "fw folder id is NULL !!");
462 * TODO : 1. Need to Null check parameter
463 * 2. converting type : itemType
464 * 3. check whether the item is included
465 * 4. generate item luid
466 * 5. add item & change log
468 _DEBUG_INFO("fw_account_id : %d", fw_account_id);
469 _DEBUG_INFO("fw_item_id : %s", fw_item_id);
470 _DEBUG_INFO("service_item_id : %s", service_item_id);
471 _DEBUG_INFO("itemType : %d", item_type);
472 _DEBUG_INFO("fw_folder_id : %s", fw_folder_id);
474 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
476 sync_agent_da_item_s item;
477 sync_agent_da_item_changelog_s item_changelog;
480 * check whether the item is included
484 char *item_id = sync_agent_get_item_id(fw_account_id, service_item_id, itemType);
485 if (item_id != NULL) {
486 _DEBUG_ERROR("Item already exists : %s", item_id);
494 item.account_id = fw_account_id;
495 item.item_id = fw_item_id;
496 item.folder_id = fw_folder_id;
497 item.data_store_id = item_type;
498 item.service_id = service_item_id;
499 item.access_name = "DACI_ChangeLog";
501 ret = da_add_item_internal(&item, 1);
502 if (ret != SYNC_AGENT_DA_SUCCESS) {
503 _DEBUG_ERROR("add item failed return : %d", ret);
510 item_changelog.item_id = fw_item_id;
511 item_changelog.operation_id = 301;
512 item_changelog.status = "SYNC_REQUIRED";
513 item_changelog.access_name = "DACI_ChangeLog";
515 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
516 if (ret != SYNC_AGENT_DA_SUCCESS) {
517 _DEBUG_ERROR("add item changelog failed return : %d", ret);
523 if (item_id != NULL) {
533 EXPORT_API sync_agent_da_return_e sync_agent_changelog_add_item_new(sync_agent_da_item_s * sync_agent_item, char **item_id)
537 retvm_if(sync_agent_item == NULL, SYNC_AGENT_DA_ERRORS, "sync_agent_da_item_s is NULL !!");
540 * TODO : 1. Need to Null check parameter
541 * 2. converting type : itemType
542 * 3. check whether the item is included
543 * 4. generate item luid
544 * 5. add item & change log
546 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
547 sync_agent_da_item_changelog_s item_changelog;
550 * check whether the item is included
554 char *item_id = sync_agent_get_item_id(fw_account_id, service_item_id, itemType);
555 if (item_id != NULL) {
556 _DEBUG_ERROR("Item already exists : %s", item_id);
564 ret = sync_agent_add_item_new(sync_agent_item, 1, item_id);
565 if (ret != SYNC_AGENT_DA_SUCCESS) {
566 _DEBUG_ERROR("add item failed return : %d", ret);
573 item_changelog.item_id = *item_id;
574 item_changelog.operation_id = 301;
575 item_changelog.status = "SYNC_REQUIRED";
576 item_changelog.access_name = "DACI_ChangeLog";
578 ret = da_add_item_changelog_wrapper(sync_agent_item->account_id, &item_changelog, 1);
579 if (ret != SYNC_AGENT_DA_SUCCESS) {
580 _DEBUG_ERROR("add item changelog failed return : %d", ret);
586 if (item_id != NULL) {
596 int da_changelog_delete_item_internal(int fw_account_id, char *fw_item_id, int item_type)
600 retvm_if(fw_item_id == NULL, 0, "fw item id is NULL !!");
603 * TODO : 1. Need to Null check parameter
604 * 2. check whether the item is included
605 * 3. check whether the change log is included
606 * 4. add/update/delete item change log
608 _DEBUG_INFO("fw_account_id : %d", fw_account_id);
609 _DEBUG_INFO("fw_item_id : %s", fw_item_id);
610 _DEBUG_INFO("itemType : %d", item_type);
612 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
614 sync_agent_da_item_changelog_s item_changelog;
615 item_changelog.status = NULL;
616 item_changelog.access_name = NULL;
619 * check whether the item is included
621 ret = da_is_exist_item_wrapper(fw_item_id);
623 _DEBUG_INFO("Item already exists : %s", fw_item_id);
625 _DEBUG_ERROR("Item is not existed!!");
630 * check whether the change log is included
632 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
633 item_changelog.item_id = fw_item_id;
634 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
636 switch (item_changelog.operation_id) {
639 _DEBUG_INFO("Item changelog already exists : ADD Operation");
640 ret = da_delete_item_by_item_id_internal(fw_item_id);
641 if (ret != SYNC_AGENT_DA_SUCCESS) {
642 _DEBUG_ERROR("Failed to Delete Item : %d", ret);
646 ret = da_delete_item_changelog_by_item_id_internal(fw_account_id, fw_item_id);
647 if (ret != SYNC_AGENT_DA_SUCCESS) {
648 _DEBUG_ERROR("Failed to Delete Item Change Log : %d", ret);
653 case 302: /* UPDATE */
655 _DEBUG_INFO("Item Changelog Already Exists : UPDATE Operation");
656 item_changelog.operation_id = 303;
657 ret = da_set_item_changelog_operation_id_wrapper(fw_account_id, &item_changelog);
658 if (ret != SYNC_AGENT_DA_SUCCESS) {
659 _DEBUG_ERROR("Failed to Set Item ChangeLog Operation : %d", ret);
664 case 303: /* DELETE */
666 _DEBUG_INFO("Item Changelog Already Exists : DELETE Operation");
674 item_changelog.item_id = fw_item_id;
675 item_changelog.operation_id = 303;
676 item_changelog.status = strdup("SYNC_REQUIRED");
677 item_changelog.access_name = strdup("DACI_ChangeLog");
679 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
680 if (ret != SYNC_AGENT_DA_SUCCESS) {
681 _DEBUG_ERROR("[da_changelog_delete_item_internal] add item change log failed return : %d", ret);
687 if (item_changelog.status != NULL) {
688 free(item_changelog.status);
689 item_changelog.status = NULL;
691 if (item_changelog.access_name != NULL) {
692 free(item_changelog.access_name);
693 item_changelog.access_name = NULL;
701 EXPORT_API sync_agent_da_return_e sync_agent_changelog_delete_item_new(int fw_account_id, char *fw_item_id)
705 retvm_if(fw_item_id == NULL, SYNC_AGENT_DA_ERRORS, "fw item id is NULL !!");
708 * TODO : 1. Need to Null check parameter
709 * 2. check whether the item is included
710 * 3. check whether the change log is included
711 * 4. add/update/delete item change log
713 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
715 sync_agent_da_item_changelog_s item_changelog;
716 item_changelog.status = NULL;
717 item_changelog.access_name = NULL;
720 * check whether the item is included
722 ret = da_is_exist_item_wrapper(fw_item_id);
724 _DEBUG_INFO("Item already exists : %s", fw_item_id);
725 // ret = sync_agent_delete_item_by_item_id(fw_item_id);
726 // if (ret != SYNC_AGENT_DA_SUCCESS) {
727 // _DEBUG_ERROR("sync_agent_delete_item() failed !! : %d", ret);
730 // _DEBUG_INFO("sync_agent_delete_item() success !!");
733 _DEBUG_ERROR("Item is not existed!!");
738 * check whether the change log is included
740 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
741 item_changelog.item_id = fw_item_id;
742 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
744 switch (item_changelog.operation_id) {
747 _DEBUG_INFO("Item changelog already exists : ADD Operation");
748 ret = da_delete_item_by_item_id_internal(fw_item_id);
749 if (ret != SYNC_AGENT_DA_SUCCESS) {
750 _DEBUG_ERROR("Failed to Delete Item : %d", ret);
754 ret = da_delete_item_changelog_by_item_id_internal(fw_account_id, fw_item_id);
755 if (ret != SYNC_AGENT_DA_SUCCESS) {
756 _DEBUG_ERROR("Failed to Delete Item Change Log : %d", ret);
761 case 302: /* UPDATE */
763 _DEBUG_INFO("Item Changelog Already Exists : UPDATE Operation");
764 item_changelog.operation_id = 303;
765 ret = da_set_item_changelog_operation_id_wrapper(fw_account_id, &item_changelog);
766 if (ret != SYNC_AGENT_DA_SUCCESS) {
767 _DEBUG_ERROR("Failed to Set Item ChangeLog Operation : %d", ret);
772 case 303: /* DELETE */
774 _DEBUG_INFO("Item Changelog Already Exists : DELETE Operation");
782 item_changelog.item_id = fw_item_id;
783 item_changelog.operation_id = 303;
784 item_changelog.status = strdup("SYNC_REQUIRED");
785 item_changelog.access_name = strdup("DACI_ChangeLog");
787 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
788 if (ret != SYNC_AGENT_DA_SUCCESS) {
789 _DEBUG_ERROR("[da_changelog_delete_item_internal] add item change log failed return : %d", ret);
795 if (item_changelog.status != NULL) {
796 free(item_changelog.status);
797 item_changelog.status = NULL;
799 if (item_changelog.access_name != NULL) {
800 free(item_changelog.access_name);
801 item_changelog.access_name = NULL;
809 int da_changelog_update_item_internal(int fw_account_id, char *fw_item_id, int item_type)
813 retvm_if(fw_item_id == NULL, 0, "fw item id is NULL !!");
816 * TODO : 1. Need to Null check parameter
817 * 2. converting type : itemType
818 * 3. check whether the item is included
819 * 4. check whether the change log is included
820 * 5. add item change log
823 _DEBUG_INFO("fw_account_id : %d", fw_account_id);
824 _DEBUG_INFO("fw_item_id : %s", fw_item_id);
825 _DEBUG_INFO("itemType : %d", item_type);
827 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
829 sync_agent_da_item_changelog_s item_changelog;
830 item_changelog.status = NULL;
831 item_changelog.access_name = NULL;
834 * check whether the item is included
836 ret = da_is_exist_item_wrapper(fw_item_id);
838 _DEBUG_INFO("Item already exists : %s", fw_item_id);
840 _DEBUG_ERROR("Item is not existed!!");
844 /* check whether the change log is included */
845 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
846 item_changelog.item_id = fw_item_id;
847 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
849 if (item_changelog.operation_id == 303) { /* DELETE */
850 _DEBUG_ERROR("already deleted item");
858 item_changelog.item_id = fw_item_id;
859 item_changelog.operation_id = 302;
860 item_changelog.status = strdup("SYNC_REQUIRED");
861 item_changelog.access_name = strdup("DACI_ChangeLog");
863 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
864 if (ret != SYNC_AGENT_DA_SUCCESS) {
865 _DEBUG_ERROR("Failed to Add Item Change Log : %d", ret);
871 if (item_changelog.status != NULL) {
872 free(item_changelog.status);
873 item_changelog.status = NULL;
875 if (item_changelog.access_name != NULL) {
876 free(item_changelog.access_name);
877 item_changelog.access_name = NULL;
885 EXPORT_API sync_agent_da_return_e sync_agent_changelog_update_item_new(int fw_account_id, char *fw_item_id)
889 retvm_if(fw_item_id == NULL, SYNC_AGENT_DA_ERRORS, "fw item id is NULL !!");
892 * TODO : 1. Need to Null check parameter
893 * 2. converting type : itemType
894 * 3. check whether the item is included
895 * 4. check whether the change log is included
896 * 5. add item change log
898 sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS;
900 sync_agent_da_item_changelog_s item_changelog;
901 item_changelog.status = NULL;
902 item_changelog.access_name = NULL;
905 * check whether the item is included
907 ret = da_is_exist_item_wrapper(fw_item_id);
909 _DEBUG_INFO("Item already exists : %s", fw_item_id);
911 _DEBUG_ERROR("Item is not existed!!");
915 /* check whether the change log is included */
916 if (da_is_exist_item_changelog_wrapper(fw_account_id, fw_item_id)) {
917 item_changelog.item_id = fw_item_id;
918 sync_agent_get_item_changelog_by_item_id(fw_account_id, &item_changelog);
920 if (item_changelog.operation_id == 303) { /* DELETE */
921 _DEBUG_ERROR("already deleted item");
929 item_changelog.item_id = fw_item_id;
930 item_changelog.operation_id = 302;
931 item_changelog.status = strdup("SYNC_REQUIRED");
932 item_changelog.access_name = strdup("DACI_ChangeLog");
934 ret = da_add_item_changelog_wrapper(fw_account_id, &item_changelog, 1);
935 if (ret != SYNC_AGENT_DA_SUCCESS) {
936 _DEBUG_ERROR("Failed to Add Item Change Log : %d", ret);
942 if (item_changelog.status != NULL) {
943 free(item_changelog.status);
944 item_changelog.status = NULL;
946 if (item_changelog.access_name != NULL) {
947 free(item_changelog.access_name);
948 item_changelog.access_name = NULL;