upload tizen1.0 source
authorKim Kibum <kb0929.kim@samsung.com>
Sun, 29 Apr 2012 08:01:43 +0000 (17:01 +0900)
committerKim Kibum <kb0929.kim@samsung.com>
Sun, 29 Apr 2012 08:01:43 +0000 (17:01 +0900)
95 files changed:
CMakeLists.src [new file with mode: 0755]
CMakeLists.sub [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
Common/Common_Define.c [new file with mode: 0644]
Common/Common_Util.c [new file with mode: 0644]
Common/Common_Vconf.c [new file with mode: 0644]
Framework/Event/OMA_DS_Event_Handler.c [new file with mode: 0644]
Framework/Event/OMA_DS_Platform_Event_Handler.c [new file with mode: 0644]
Framework/SAN_parser/PM_SanParser.c [new file with mode: 0644]
Framework/Task/OMA_DS_Engine_Controller_Task.c [new file with mode: 0644]
ServiceAdapter/NetworkBinder/NA_Binder.c [new file with mode: 0644]
ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.c [new file with mode: 0644]
ServiceAdapter/SA_Command.c [new file with mode: 0644]
ServiceAdapter/SA_Common_Interface.c [new file with mode: 0644]
ServiceAdapter/SA_DevInf.c [new file with mode: 0644]
ServiceAdapter/SA_Elements.c [new file with mode: 0644]
ServiceAdapter/SA_Session.c [new file with mode: 0644]
ServiceAdapter/SA_Util.c [new file with mode: 0644]
ServiceEngine/SE_Account.c [new file with mode: 0644]
ServiceEngine/SE_AutoConfig.c [new file with mode: 0644]
ServiceEngine/SE_Notification.c [new file with mode: 0644]
ServiceEngine/SE_Storage.c [new file with mode: 0644]
ServiceEngine/SE_Sync.c [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/control.slp [new file with mode: 0644]
debian/postinst [new file with mode: 0644]
debian/rules [new file with mode: 0755]
eventconfig_omads [new file with mode: 0644]
include/Common/Common_Define.h [new file with mode: 0644]
include/Common/Common_Define_Internal.h [new file with mode: 0644]
include/Common/Common_Util.h [new file with mode: 0644]
include/Common/Common_Vconf.h [new file with mode: 0644]
include/Common/CscKeys.h [new file with mode: 0644]
include/Framework/Event/OMA_DS_Event_Handler.h [new file with mode: 0644]
include/Framework/Event/OMA_DS_Platform_Event_Handler.h [new file with mode: 0644]
include/Framework/SAN_parser/PM_SanParser.h [new file with mode: 0644]
include/Framework/Task/OMA_DS_Engine_Controller_Task.h [new file with mode: 0644]
include/ServiceAdapter/NetworkBinder/NA_Binder.h [new file with mode: 0644]
include/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.h [new file with mode: 0644]
include/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder_definition.h [new file with mode: 0644]
include/ServiceAdapter/SA_Command.h [new file with mode: 0644]
include/ServiceAdapter/SA_Command_Internal.h [new file with mode: 0644]
include/ServiceAdapter/SA_Common_Interface.h [new file with mode: 0644]
include/ServiceAdapter/SA_Define.h [new file with mode: 0644]
include/ServiceAdapter/SA_DevInf.h [new file with mode: 0644]
include/ServiceAdapter/SA_DevInf_Internal.h [new file with mode: 0644]
include/ServiceAdapter/SA_Elements.h [new file with mode: 0644]
include/ServiceAdapter/SA_Elements_Internal.h [new file with mode: 0644]
include/ServiceAdapter/SA_Error.h [new file with mode: 0644]
include/ServiceAdapter/SA_Session.h [new file with mode: 0644]
include/ServiceAdapter/SA_Session_Internal.h [new file with mode: 0644]
include/ServiceAdapter/SA_Util.h [new file with mode: 0644]
include/ServiceEngine/SE_Account.h [new file with mode: 0644]
include/ServiceEngine/SE_AutoConfig.h [new file with mode: 0644]
include/ServiceEngine/SE_Common.h [new file with mode: 0644]
include/ServiceEngine/SE_Error.h [new file with mode: 0644]
include/ServiceEngine/SE_Notification.h [new file with mode: 0644]
include/ServiceEngine/SE_Storage.h [new file with mode: 0644]
include/ServiceEngine/SE_Sync.h [new file with mode: 0644]
main/main.c [new file with mode: 0644]
noticonfig_omads [new file with mode: 0644]
omadsUI_fw_config.xml [new file with mode: 0644]
omads_fw_config.xml [new file with mode: 0755]
packaging/oma-ds-service.spec [new file with mode: 0644]
rmUnavailables [new file with mode: 0755]
src/Common/Common_Define.c [new file with mode: 0644]
src/Common/Common_Util.c [new file with mode: 0644]
src/Common/Common_Vconf.c [new file with mode: 0644]
src/Framework/Event/OMA_DS_Event_Handler.c [new file with mode: 0644]
src/Framework/Event/OMA_DS_Platform_Event_Handler.c [new file with mode: 0644]
src/Framework/SAN_parser/PM_SanParser.c [new file with mode: 0644]
src/Framework/Task/OMA_DS_Engine_Controller_Task.c [new file with mode: 0644]
src/ServiceAdapter/NetworkBinder/NA_Binder.c [new file with mode: 0644]
src/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.c [new file with mode: 0644]
src/ServiceAdapter/SA_Command.c [new file with mode: 0644]
src/ServiceAdapter/SA_Common_Interface.c [new file with mode: 0644]
src/ServiceAdapter/SA_DevInf.c [new file with mode: 0644]
src/ServiceAdapter/SA_Elements.c [new file with mode: 0644]
src/ServiceAdapter/SA_Session.c [new file with mode: 0644]
src/ServiceAdapter/SA_Util.c [new file with mode: 0644]
src/ServiceEngine/SE_Account.c [new file with mode: 0644]
src/ServiceEngine/SE_AutoConfig.c [new file with mode: 0644]
src/ServiceEngine/SE_Notification.c [new file with mode: 0644]
src/ServiceEngine/SE_Storage.c [new file with mode: 0644]
src/ServiceEngine/SE_Sync.c [new file with mode: 0644]
src/main/main.c [new file with mode: 0644]
syncmld_mgr [new file with mode: 0755]
test/include/suites/unit_test_sample_suite.h [new file with mode: 0644]
test/include/unit_test_common.h [new file with mode: 0644]
test/include/unit_test_run.h [new file with mode: 0644]
test/include/unit_test_suites.h [new file with mode: 0644]
test/src/oma_test_main.c [new file with mode: 0644]
test/src/suites/unit_test_sample_suite.c [new file with mode: 0644]
test/src/unit_test_run.c [new file with mode: 0644]

diff --git a/CMakeLists.src b/CMakeLists.src
new file mode 100755 (executable)
index 0000000..38894c9
--- /dev/null
@@ -0,0 +1,18 @@
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/main FRAME_SRCS)
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Common SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Framework/SAN_parser SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Framework/Event SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/Framework/Task SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/ServiceAdapter/NetworkBinder SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/ServiceAdapter/ProtocolBinder SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/ServiceAdapter SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src/ServiceEngine SRCS)
+
+#test sources (only included when Debug mode)
+if (CMAKE_BUILD_TYPE MATCHES "Debug")
+       
+
+       AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/test/src TEST_SRCS)
+       AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/test/src/suites TEST_SRCS)
+endif (CMAKE_BUILD_TYPE MATCHES "Debug")
\ No newline at end of file
diff --git a/CMakeLists.sub b/CMakeLists.sub
new file mode 100644 (file)
index 0000000..a9332ae
--- /dev/null
@@ -0,0 +1,47 @@
+#################################################################################
+#    THIS FILE IS CREATED AUTOMATICALLY. DO NOT DELETE OR MODIFY THIS FILE.
+#################################################################################
+
+INCLUDE(CMakeLists.src)
+
+## PROJECT NAME
+PROJECT(oma-ds-service C)
+
+## PACKAGE CONFIG
+## SET(SLP_PKGCONFIG_LIST "libwbxml2 check glib-2.0 libsoup-2.4")
+SET(SLP_PKGCONFIG_LIST "glib-2.0 libsoup-2.4 sqlite3 sync-agent-framework vconf libwbxml2")
+
+if (CMAKE_BUILD_TYPE MATCHES "Debug")
+       SET(SLP_PKGCONFIG_LIST "${SLP_PKGCONFIG_LIST} check")
+endif (CMAKE_BUILD_TYPE MATCHES "Debug")
+
+## INCLUDES
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/SAN_parser)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
+
+if (CMAKE_BUILD_TYPE MATCHES "Debug")
+       INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/test/include)
+endif (CMAKE_BUILD_TYPE MATCHES "Debug")
+
+## DEFINITIONS
+ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"")
+
+## LIBRARY PATH
+SET(SLP_LD_PATH_FLAGS "")
+
+## LIBRARY
+SET(SLP_LD_FLAGS "-lexpat")
+
+## DEBUG
+SET(SLP_DEBUG_FLAGS "-g")
+
+## OPTIMIZATION
+SET(SLP_OPT_FLAGS "-O0")
+
+## COMPILER FLAGS
+SET(SLP_COMPILER_FLAGS "")
+
+## LINKER FLAGS
+SET(SLP_LINKER_FLAGS "")
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4690cce
--- /dev/null
@@ -0,0 +1,53 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET(CMAKE_BUILD_TYPE "Debug")
+#SET(CMAKE_BUILD_TYPE "Release")
+SET(OMA_TEST "oma-test")
+SET(OMA_CONFIG_DIR "/opt/data/oma-ds/")
+
+# INCLUDE SUB CMAKELIST FILE
+INCLUDE(CMakeLists.sub)
+
+SET(RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/res")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED ${SLP_PKGCONFIG_LIST})
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}")
+SET(CMAKE_CXX_FLAGS "${SLP_DEBUG_FLAGS} ${SLP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${SLP_COMPILER_FLAGS}")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${FRAME_SRCS} ${SRCS})
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS})
+
+if (CMAKE_BUILD_TYPE MATCHES "Debug")
+       ADD_EXECUTABLE(${OMA_TEST} ${TEST_SRCS} ${SRCS})
+       TARGET_LINK_LIBRARIES(${OMA_TEST} ${pkgs_LDFLAGS} ${SLP_LD_PATH_FLAGS} ${SLP_LD_FLAGS} ${SLP_LINKER_FLAGS})
+endif (CMAKE_BUILD_TYPE MATCHES "Debug")
+
+# INSTALL
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/omads_fw_config.xml DESTINATION ${OMA_CONFIG_DIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/omadsUI_fw_config.xml DESTINATION ${OMA_CONFIG_DIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/eventconfig_omads DESTINATION ${OMA_CONFIG_DIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/noticonfig_omads DESTINATION ${OMA_CONFIG_DIR})
+
+if (CMAKE_BUILD_TYPE MATCHES "Debug")
+       INSTALL(TARGETS ${OMA_TEST} DESTINATION bin)
+endif (CMAKE_BUILD_TYPE MATCHES "Debug")
+
+# INSTALL(DIRECTORY ${RESOURCE_DIR}/icon DESTINATION share)
+# INSTALL(DIRECTORY ${RESOURCE_DIR}/data DESTINATION share)
+
+# INCLUDE LAYOUT DIRECTORY
+# ADD_SUBDIRECTORY(layout)
+
+# INCLUDE LOCALE DIRECTORY
+#ADD_SUBDIRECTORY(res/locale)
+
+# COPY ALL FILES THE FOLDER LIBS TO THE FOLDER USR OF TARGET DEVICE
+#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib DESTINATION /usr)
diff --git a/Common/Common_Define.c b/Common/Common_Define.c
new file mode 100644 (file)
index 0000000..68a0420
--- /dev/null
@@ -0,0 +1,732 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Define_Internal.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of defined Common structure
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Define.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+
+Datastore *datastoreinfo_per_content_type[4];
+AlertType syncType;
+
+DatastoreInfo *create_datastoreinfo(char *target, char *source)
+{
+       FW_LOGV("start");
+
+       DatastoreInfo *datastoreInfo = (DatastoreInfo *)calloc(1, sizeof(DatastoreInfo));
+       if (datastoreInfo == NULL) {
+               FW_LOGV("datastoreInfo is NULL");
+               return NULL;
+       }
+
+       if (target != NULL)
+               datastoreInfo->target = strdup(target);
+       if (source != NULL)
+               datastoreInfo->source = strdup(source);
+
+       FW_LOGV("end");
+
+       return datastoreInfo;
+}
+
+void free_datastoreinfos(GList *pDatastoreInfos)
+{
+       FW_LOGV("start");
+
+       if (!pDatastoreInfos) {
+               FW_LOGV("List is null");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pDatastoreInfos; iter != NULL; iter = g_list_next(iter))
+               free_datastoreinfo(iter->data);
+
+       g_list_free(pDatastoreInfos);
+
+       FW_LOGV("end");
+}
+
+void free_datastoreinfo(DatastoreInfo *pDatastoreInfo)
+{
+       FW_LOGV("start");
+
+       if (!pDatastoreInfo) {
+               FW_LOGV("pDatastoreInfo is NULL");
+               return;
+       }
+
+       if (pDatastoreInfo->target) {
+               free(pDatastoreInfo->target);
+               pDatastoreInfo->target = NULL;
+       }
+
+       if (pDatastoreInfo->source) {
+               free(pDatastoreInfo->source);
+               pDatastoreInfo->source = NULL;
+       }
+
+       if (pDatastoreInfo->lastAnchor) {
+               free(pDatastoreInfo->lastAnchor);
+               pDatastoreInfo->lastAnchor = NULL;
+       }
+
+       if (pDatastoreInfo->nextAnchor) {
+               free(pDatastoreInfo->nextAnchor);
+               pDatastoreInfo->nextAnchor = NULL;
+       }
+
+       free(pDatastoreInfo);
+
+       FW_LOGV("end");
+}
+
+void set_datastoreInfo_synctype(DatastoreInfo *datastoreInfo, AlertType syncType)
+{
+       if (0 < syncType)
+               datastoreInfo->syncType = syncType;
+}
+
+void set_datastoreinfo_lastanchor(DatastoreInfo *datastoreInfo, char *lastAnchor)
+{
+       if (lastAnchor)
+               datastoreInfo->lastAnchor = strdup(lastAnchor);
+}
+
+void set_datastoreinfo_nextanchor(DatastoreInfo *datastoreInfo, char *nextAnchor)
+{
+       if (nextAnchor)
+               datastoreInfo->nextAnchor = strdup(nextAnchor);
+}
+
+void set_datastoreinfo_maxobjsize(DatastoreInfo *datastoreInfo, unsigned int maxObjSize)
+{
+       if (maxObjSize)
+               datastoreInfo->maxObjSize = maxObjSize;
+}
+
+ChangedItem *create_changeditem(ChangeType type, char *luid)
+{
+       FW_LOGV("start");
+       ChangedItem *changedItem = (ChangedItem *)calloc(1, sizeof(ChangedItem));
+       if (changedItem == NULL) {
+               FW_LOGV("changedItem is NULL");
+               return NULL;
+       }
+
+       changedItem->changeType = type;
+
+       if (luid != NULL)
+               changedItem->luid = strdup(luid);
+
+       changedItem->content_type = NULL;
+
+       FW_LOGV("end");
+
+       return changedItem;
+}
+
+void set_changeditem_contenttype(ChangedItem *pChangedItem, char *content_type)
+{
+       FW_LOGV("start content_type = %s", content_type);
+
+       if (!pChangedItem) {
+               FW_LOGV("pChangedItem is NULL");
+               return;
+       }
+
+       if (content_type != NULL)
+               pChangedItem->content_type = strdup(content_type);
+}
+
+void free_changeditem(ChangedItem *pChangedItem)
+{
+       FW_LOGV("start");
+
+       if (!pChangedItem) {
+               FW_LOGV("pChangedItem is NULL");
+               return;
+       }
+
+       if (pChangedItem->luid) {
+               free(pChangedItem->luid);
+               pChangedItem->luid = NULL;
+       }
+
+       if (pChangedItem->content_type) {
+               free(pChangedItem->content_type);
+               pChangedItem->content_type = NULL;
+       }
+
+       if (pChangedItem->data) {
+               free(pChangedItem->data);
+               pChangedItem->data = NULL;
+       }
+
+       if (pChangedItem)
+               free(pChangedItem);
+
+       FW_LOGV("end");
+}
+
+void set_changeditem_data(ChangedItem *changedItem, char *data)
+{
+       if (!changedItem) {
+               FW_LOGV("changedItem is NULL");
+               return;
+       }
+
+       if (data != NULL)
+               changedItem->data = strdup(data);
+}
+
+void set_changedItem_indexofdatastore(ChangedItem *changedItem, unsigned int indexOfDatastore)
+{
+       if (!changedItem) {
+               FW_LOGV("changedItem is NULL");
+               return;
+       }
+
+       changedItem->indexOfDatastore = indexOfDatastore;
+}
+
+ChangedDatastore *create_changeddatastore(char *source, char *target, int hasNumberOfChanges, unsigned int numberOfChanges)
+{
+       FW_LOGV("start");
+
+       ChangedDatastore *changedDatastore = (ChangedDatastore *)calloc(1, sizeof(ChangedDatastore));
+
+       if (changedDatastore == NULL) {
+               FW_LOGV("changedDatastore is NULL");
+               return NULL;
+       }
+
+       if (source != NULL)
+               changedDatastore->source = strdup(source);
+       if (target != NULL)
+               changedDatastore->target = strdup(target);
+
+       changedDatastore->needSyncCommand = 1;
+       changedDatastore->numberOfChanges = numberOfChanges;
+       changedDatastore->hasNumberOfChanges = hasNumberOfChanges;
+
+       FW_LOGV("end");
+
+       return changedDatastore;
+}
+
+void free_changeddatastores(GList *pChangedDatastores)
+{
+       FW_LOGV("start");
+
+       if (!pChangedDatastores) {
+               FW_LOGV("List is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pChangedDatastores; iter != NULL; iter = g_list_next(iter))
+               free_changeddatastore(iter->data);
+
+       g_list_free(pChangedDatastores);
+
+       FW_LOGV("end");
+}
+
+void free_changeddatastore(ChangedDatastore *pChangedDatastore)
+{
+       FW_LOGV("pChangedDatastore = %p", pChangedDatastore);
+       FW_LOGV("start");
+
+       if (!pChangedDatastore) {
+               FW_LOGV("pChangedDatastore is NULL");
+               return;
+       }
+
+       if (pChangedDatastore->source) {
+               free(pChangedDatastore->source);
+               pChangedDatastore->source = NULL;
+       }
+
+       if (pChangedDatastore->target) {
+               free(pChangedDatastore->target);
+               pChangedDatastore->target = NULL;
+       }
+
+       GList *iter = NULL;
+       for (iter = pChangedDatastore->changeItem; iter != NULL; iter = g_list_next(iter))
+               free_changeditem(iter->data);
+
+       g_list_free(pChangedDatastore->changeItem);
+       pChangedDatastore->changeItem = NULL;
+
+       for (iter = pChangedDatastore->sentItem; iter != NULL; iter = g_list_next(iter))
+               free_changeditem(iter->data);
+
+       g_list_free(pChangedDatastore->sentItem);
+       pChangedDatastore->sentItem = NULL;
+
+       if (pChangedDatastore)
+               free(pChangedDatastore);
+
+       FW_LOGV("end");
+}
+
+void set_changeddatastore_changeditem(ChangedDatastore *changedDatastore, GList *changeItem)
+{
+       if (changedDatastore)
+               changedDatastore->changeItem = changeItem;
+}
+
+void add_changeddatastore_changeditem(ChangedDatastore *changedDatastore, ChangedItem *changedItem)
+{
+       if (!changedDatastore) {
+               FW_LOGV("changedDatastore is NULL");
+               return;
+       }
+
+       changedDatastore->changeItem = g_list_append(changedDatastore->changeItem, changedItem);
+}
+
+AppliedStatus *create_appliedstatus(char *luid, ChangeType changeType, int status)
+{
+       FW_LOGV("start");
+
+       AppliedStatus *appliedStatus = (AppliedStatus *)calloc(1, sizeof(AppliedStatus));
+       if (appliedStatus == NULL) {
+               FW_LOGV("appliedStatus is NULL");
+               return NULL;
+       }
+
+       if (luid != NULL)
+               appliedStatus->luid = strdup(luid);
+
+       appliedStatus->changeType = changeType;
+       appliedStatus->status = status;
+
+       FW_LOGV("end");
+
+       return appliedStatus;
+}
+
+void free_appliedstatuses(GList *pAppliedStatuses)
+{
+       FW_LOGV("start");
+
+       if (!pAppliedStatuses) {
+               FW_LOGV("List is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pAppliedStatuses; iter != NULL; iter = g_list_next(iter))
+               free_appliedstatus(iter->data);
+
+       g_list_free(pAppliedStatuses);
+
+       FW_LOGV("start");
+}
+
+void free_appliedstatus(AppliedStatus *pAppliedStatus)
+{
+       FW_LOGV("start");
+
+       if (!pAppliedStatus) {
+               FW_LOGV("pAppliedStatus is NULL");
+               return;
+       }
+
+       if (pAppliedStatus->luid) {
+               free(pAppliedStatus->luid);
+               pAppliedStatus->luid = NULL;
+       }
+
+       free(pAppliedStatus);
+
+       FW_LOGV("end");
+}
+
+SendingStatus *create_sendingstatus(char *source, char *target)
+{
+       FW_LOGV("start");
+
+       SendingStatus *sendingStatus = (SendingStatus *)calloc(1, sizeof(SendingStatus));
+       if (sendingStatus == NULL) {
+               FW_LOGV("sendingStatus is NULL");
+               return NULL;
+       }
+
+       if (source != NULL)
+               sendingStatus->source = strdup(source);
+
+       if (target != NULL)
+               sendingStatus->target = strdup(target);
+
+       FW_LOGV("end");
+
+       return sendingStatus;
+}
+
+void free_sendingstatuses(GList *pSendingStatuses)
+{
+       FW_LOGV("start");
+
+       if (!pSendingStatuses) {
+               FW_LOGV("List is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pSendingStatuses; iter != NULL; iter = g_list_next(iter))
+               free_sendingstatus(iter->data);
+
+       g_list_free(pSendingStatuses);
+
+       FW_LOGV("end");
+}
+
+void free_sendingstatus(SendingStatus *pSendingStatus)
+{
+       FW_LOGV("start");
+
+       if (!pSendingStatus) {
+               FW_LOGV("pAppliedStatus is NULL");
+               return;
+       }
+
+       if (pSendingStatus->source) {
+               free(pSendingStatus->source);
+               pSendingStatus->source = NULL;
+       }
+
+       if (pSendingStatus->target) {
+               free(pSendingStatus->target);
+               pSendingStatus->target = NULL;
+       }
+
+       GList *iter = NULL;
+       for (iter = pSendingStatus->items; iter != NULL; iter = g_list_next(iter))
+               free_appliedstatus(iter->data);
+
+       g_list_free(pSendingStatus->items);
+
+       free(pSendingStatus);
+
+       FW_LOGV("end");
+}
+void add_sendingstatus_appliedstatus(SendingStatus *sendingStatus, AppliedStatus *appliedStatus)
+{
+       if (!sendingStatus) {
+               FW_LOGV("sendingStatus is NULL");
+               return;
+       }
+
+       sendingStatus->items = g_list_append(sendingStatus->items, appliedStatus);
+}
+
+Datastore *create_datastore(char *target, char *source)
+{
+       FW_LOGV("start");
+
+       Datastore *datastore = (Datastore *)calloc(1, sizeof(Datastore));
+       if (datastore == NULL) {
+               FW_LOGV("datastore is NULL");
+               return NULL;
+       }
+
+       if (target)
+               datastore->target = strdup(target);
+
+       if (source)
+               datastore->source = strdup(source);
+
+       FW_LOGV("end");
+
+       return datastore;
+}
+
+void set_datastore_contenttype_info(Datastore *datastore, int datastore_id, int folder_type_id)
+{
+       if (datastore_id)
+               datastore->datastore_id = datastore_id;
+       if (folder_type_id)
+               datastore->folder_type_id = folder_type_id;
+}
+
+void set_datastore_account_info(Datastore *datastore, char *account_id, char *account_pw)
+{
+       if (account_id)
+               datastore->id = strdup(account_id);
+       if (account_pw)
+               datastore->pw = strdup(account_pw);
+}
+
+void set_datastore_client_sync_type(Datastore *datastore, AlertType syncType)
+{
+       if (syncType)
+               datastore->clientSyncType = syncType ;
+}
+
+void set_datastore_server_sync_type(Datastore *datastore, AlertType syncType)
+{
+       if (syncType)
+               datastore->serverSyncType = syncType ;
+}
+
+void set_datastore_client_anchor(Datastore *datastore, char *lastAnchor, char *nextAnchor)
+{
+       if (lastAnchor)
+               datastore->lastAnchorClient = strdup(lastAnchor);
+       if (nextAnchor)
+               datastore->nextAnchorClient = strdup(nextAnchor);
+}
+
+void set_datastore_server_anchor(Datastore *datastore, char *lastAnchor, char *nextAnchor)
+{
+       if (lastAnchor)
+               datastore->lastAnchorServer = strdup(lastAnchor);
+       if (nextAnchor)
+               datastore->nextAnchorServer = strdup(nextAnchor);
+}
+
+SyncResult *create_sync_result()
+{
+       FW_LOGV("start");
+
+       SyncResult *syncResult = calloc(1, sizeof(SyncResult));
+       if (syncResult == NULL) {
+               FW_LOGV("syncResult is NULL");
+               return NULL;
+       }
+
+       FW_LOGV("end");
+
+       return syncResult;
+}
+
+SyncResult *dup_syncresult(SyncResult *orgSyncResult)
+{
+       FW_LOGV("start");
+
+       SyncResult *syncResult = calloc(1, sizeof(SyncResult));
+       if (syncResult == NULL) {
+               FW_LOGV("syncResult is NULL");
+               return NULL;
+       }
+
+       syncResult->sessionResult = orgSyncResult->sessionResult;
+       syncResult->numberOfChange = orgSyncResult->numberOfChange;
+       syncResult->received_count = orgSyncResult->received_count;
+       syncResult->add_count = orgSyncResult->add_count;
+       syncResult->replace_count = orgSyncResult->replace_count;
+       syncResult->delete_count = orgSyncResult->delete_count;
+
+       FW_LOGV("end");
+
+       return syncResult;
+
+}
+
+void set_numberofchange(SyncResult *syncResult, unsigned int numberOfChange)
+{
+       if (syncResult)
+               syncResult->numberOfChange = numberOfChange;
+}
+
+void add_add_count(SyncResult *syncResult, unsigned int add_cnt)
+{
+       if (syncResult)
+               syncResult->add_count += add_cnt;
+}
+
+void add_receive_count(SyncResult *syncResult, unsigned int received_count)
+{
+       if (syncResult)
+               syncResult->received_count += received_count;
+}
+
+void add_replace_count(SyncResult *syncResult, unsigned int replace_cnt)
+{
+       if (syncResult)
+               syncResult->replace_count += replace_cnt;
+}
+
+void add_delete_count(SyncResult *syncResult, unsigned int delete_cnt)
+{
+       if (syncResult)
+               syncResult->delete_count += delete_cnt;
+}
+
+void free_presyncreturnobj(PreSyncReturnObj *pPreSyncReturnObj)
+{
+       FW_LOGV("start");
+
+       if (pPreSyncReturnObj == NULL) {
+               FW_LOGV("pPreSyncReturnObj is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pPreSyncReturnObj->datastoreInfo; iter != NULL; iter = g_list_next(iter))
+               free_datastoreinfo(iter->data);
+       g_list_free(pPreSyncReturnObj->datastoreInfo);
+       pPreSyncReturnObj->datastoreInfo = NULL;
+
+       if (pPreSyncReturnObj->devID != NULL) {
+               free(pPreSyncReturnObj->devID);
+               pPreSyncReturnObj->devID = NULL;
+       }
+
+       free(pPreSyncReturnObj);
+       pPreSyncReturnObj = NULL;
+
+       FW_LOGV("end");
+}
+
+void free_syncobj(SyncObj *pSyncObj)
+{
+       FW_LOGV("start");
+
+       if (pSyncObj == NULL) {
+               FW_LOGV("pSyncObj is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pSyncObj->changedDatastore; iter != NULL; iter = g_list_next(iter))
+               free_changeddatastore(iter->data);
+       g_list_free(pSyncObj->changedDatastore);
+       pSyncObj->changedDatastore = NULL;
+
+       for (iter = pSyncObj->sendingStatus; iter != NULL; iter = g_list_next(iter))
+               free_sendingstatus(iter->data);
+       g_list_free(pSyncObj->sendingStatus);
+       pSyncObj->sendingStatus = NULL;
+
+       free(pSyncObj);
+       pSyncObj = NULL;
+
+       FW_LOGV("end");
+}
+
+void free_syncreturnobj(SyncReturnObj *pSyncReturnObj)
+{
+       FW_LOGV("start");
+
+       if (pSyncReturnObj == NULL) {
+               FW_LOGV("pSyncReturnObj is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pSyncReturnObj->changedDatastore; iter != NULL; iter = g_list_next(iter))
+               free_changeddatastore(iter->data);
+       g_list_free(pSyncReturnObj->changedDatastore);
+       pSyncReturnObj->changedDatastore = NULL;
+
+       for (iter = pSyncReturnObj->status; iter != NULL; iter = g_list_next(iter))
+               free_appliedstatus(iter->data);
+       g_list_free(pSyncReturnObj->status);
+       pSyncReturnObj->status = NULL;
+
+       free(pSyncReturnObj);
+       pSyncReturnObj = NULL;
+
+       FW_LOGV("end");
+}
+
+void free_datastore(Datastore *pDatastore)
+{
+       FW_LOGV("start");
+
+       if (pDatastore == NULL)
+               return;
+
+       if (pDatastore->target != NULL) {
+               free(pDatastore->target);
+               pDatastore->target = NULL;
+       }
+
+       if (pDatastore->source != NULL) {
+               free(pDatastore->source);
+               pDatastore->source = NULL;
+       }
+
+       if (pDatastore->id != NULL) {
+               free(pDatastore->id);
+               pDatastore->id = NULL;
+       }
+
+       if (pDatastore->pw != NULL) {
+               free(pDatastore->pw);
+               pDatastore->pw = NULL;
+       }
+
+       if (pDatastore->lastAnchorClient != NULL) {
+               free(pDatastore->lastAnchorClient);
+               pDatastore->lastAnchorClient = NULL;
+       }
+
+       if (pDatastore->nextAnchorClient != NULL) {
+               free(pDatastore->nextAnchorClient);
+               pDatastore->nextAnchorClient = NULL;
+       }
+
+       if (pDatastore->lastAnchorServer != NULL) {
+               free(pDatastore->lastAnchorServer);
+               pDatastore->lastAnchorServer = NULL;
+       }
+
+       if (pDatastore->nextAnchorServer != NULL) {
+               free(pDatastore->nextAnchorServer);
+               pDatastore->nextAnchorServer = NULL;
+       }
+
+       if (pDatastore->clientSyncResult != NULL)
+               free(pDatastore->clientSyncResult);
+
+       if (pDatastore->serverSyncResult != NULL)
+               free(pDatastore->serverSyncResult);
+
+       free(pDatastore);
+
+       FW_LOGV("end");
+}
diff --git a/Common/Common_Util.c b/Common/Common_Util.c
new file mode 100644 (file)
index 0000000..1ab5315
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Util.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of utility function
+ */
+
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Util.h"
+#include "Common/Common_Define_Internal.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+#define MAX_RETRY_COUNT 10
+
+bool set_config_str(int accountID, char *key, char *value, char * type, char *accessName)
+{
+       DACI_RETURN result;
+       daci_config config;
+       config.config_id = accountID;
+       config.key = key;
+       config.value = value;
+       config.type = type;
+       config.access_name = accessName;
+
+       result = DACI_Update_Config(&config, 1);
+
+       if (result == DACI_SUCCESS)
+               return true;
+       else
+               return false;
+}
+
+
+bool set_config_int(int accountID, char *key, int value, char * type, char *accessName)
+{
+       char *value_str = NULL;
+       value_str = g_strdup_printf("%u", value);
+
+       DACI_RETURN result;
+       daci_config config;
+       config.config_id = accountID;
+       config.key = key;
+       config.value = value_str;
+       config.type = type;
+       config.access_name = accessName;
+
+       result = DACI_Update_Config(&config, 1);
+
+       if (value_str != NULL)
+               free(value_str);
+
+       if (result == DACI_SUCCESS)
+               return true;
+       else
+               return false;
+}
+
+
+
+bool get_config(int accountId, char *key, char **value)
+{
+       DACI_RETURN result;
+       daci_config daci;
+       daci.config_id = accountId;
+
+       daci.key = key;
+       result = DACI_Get_Config_By_Key(&daci);
+
+       if (result == DACI_SUCCESS) {
+               *value = daci.value;
+               if (daci.type != NULL)
+                       free(daci.type);
+               return true;
+       } else {
+               /* FIXME  temporary solution
+                * Try MAX_RETRY_COUNT when fail to get_config
+                * */
+               int i;
+               bool success = false;
+               for (i = 0; i < MAX_RETRY_COUNT; i++){
+                       result =DACI_Get_Config_By_Key(&daci);
+                       if(result == DACI_SUCCESS){
+                               *value = daci.value;
+                               if (daci.type != NULL)
+                                       free(daci.type);
+                               success = true;
+                               break;
+                       }
+               }
+               if(success == false)
+                       return false;
+               else
+                       return true;
+       }
+}
+
+int get_accountid(char *profile, bool open)
+{
+       FW_LOGV("start");
+       int accountId = -1;
+       char *profileDirName = NULL;
+       int *account_list = 0;
+       int account_list_count = 0;
+       bool result;
+
+       if (open == false) {
+               DACI_RETURN da_err = DACI_Open_Agent();
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("failed in DACI_Open_Agent");
+                       goto error;
+               }
+       }
+
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+
+       int i;
+       for (i = 0; i < account_list_count; i++) {
+               if (profileDirName != NULL)
+                       free(profileDirName);
+
+               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
+               if (result == false) {
+                       FW_LOGE("failed in get_Config");
+                       goto error;
+               }
+
+               FW_LOGV("profileDirName = %s", profileDirName);
+               if(profileDirName == NULL )
+                       continue;
+
+               if (strcmp(profile, profileDirName) == 0) {
+                       FW_LOGV("account_list[i] = %d", account_list[i]);
+                       accountId = account_list[i];
+                       break;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       if (profileDirName)
+               free(profileDirName);
+
+       if (open == false)
+               DACI_Close_Agent();
+
+       return accountId;
+}
+
+/*int convert_synctype_value(char *syncType_str)
+{
+       int syncType_value;
+
+       if (strcmp(syncType_str, DEFINE_ALERT_SLOW_SYNC_STR) ==0)
+               syncType_value = ALERT_SLOW_SYNC ;
+       else if (strcmp(syncType_str, DEFINE_ALERT_TWO_WAY_STR) ==0)
+               syncType_value = ALERT_TWO_WAY ;
+       else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) ==0)
+               syncType_value =  ALERT_ONE_WAY_FROM_CLIENT;
+       else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) ==0)
+               syncType_value = ALERT_ONE_WAY_FROM_SERVER;
+       else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_SERVER_STR) ==0)
+               syncType_value = ALERT_REFRESH_FROM_SERVER;
+       else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) ==0)
+               syncType_value = ALERT_REFRESH_FROM_CLIENT;
+       else
+               syncType_value = ALERT_UNKNOWN;
+
+       return syncType_value;
+}*/
+
+/*char *convert_synctype_str(char *syncType_value)
+{
+       char *syncType_str = NULL;
+
+       if (strcmp(syncType_value, DEFINE_ALERT_SLOW_SYNC_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_SLOW_SYNC_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_TWO_WAY_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_TWO_WAY_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_REFRESH_FROM_SERVER_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_REFRESH_FROM_SERVER_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_REFRESH_FROM_CLIENT_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR;
+       else
+               syncType_str = DEFINE_ALERT_SLOW_SYNC_STR;
+
+       return syncType_str;
+}*/
diff --git a/Common/Common_Vconf.c b/Common/Common_Vconf.c
new file mode 100644 (file)
index 0000000..f514091
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Util.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of wrapping vconf function
+ */
+
+#include <vconf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <string.h>
+#include "Common/Common_Vconf.h"
+
+
+char *get_vconf_str(char *baseKey, char *key)
+{
+       char path[128];
+       char *value = NULL;
+
+       sprintf(path, "%s%s", baseKey, key);
+       value = vconf_get_str(path);
+
+       if (value != NULL) {
+               if (strcmp(value, "") == 0) {
+
+                       if (value != NULL)
+                               free(value);
+
+                       return NULL;
+               } else
+                       return value;
+       } else{
+               return NULL;
+       }
+
+}
+
+char *get_vconf_str_key(char *key)
+{
+       char *value = NULL;
+       value = vconf_get_str(key);
+
+       if (value != NULL) {
+               if (strcmp(value, "") == 0) {
+
+                       if (value != NULL)
+                               free(value);
+
+                       return NULL;
+               } else
+                       return value;
+       } else{
+               return NULL;
+       }
+}
+
+bool get_vconf_int(char *baseKey, char *key, int *value)
+{
+       char path[128];
+       int temp = 0;
+       int result;
+
+       sprintf(path, "%s%s", baseKey, key);
+       result = vconf_get_int(path, &temp);
+
+       if (result == 0) {
+               *value = temp;
+               return true;
+       } else
+               return false;
+}
+
+bool get_vconf_Int_key(char *key, int *value)
+{
+       int temp = 0;
+       int result;
+
+       result = vconf_get_int(key, &temp);
+
+       if (result == 0) {
+               *value = temp;
+               return true;
+       } else
+               return false;
+}
+
+bool set_vconf_str(char *baseKey, char *key, char *value)
+{
+       char path[128];
+       int result;
+
+       sprintf(path, "%s%s", baseKey, key);
+       result = vconf_set_str(path, value);
+
+       if (result == 0)
+               return true;
+       else
+               return false;
+}
+
+
+bool set_vconf_str_key(char *key, char *value)
+{
+       int result;
+       result = vconf_set_str(key, value);
+
+       if (result == 0)
+               return true;
+       else
+               return false;
+}
+
+bool set_vconf_int(char *baseKey, char *key, int value)
+{
+       char path[128];
+       int result;
+
+       sprintf(path, "%s%s", baseKey, key);
+       result = vconf_set_int(path, value);
+
+       if (result == 0)
+               return true;
+       else
+               return false;
+}
+
+bool set_vconf_int_key(char *key, int value)
+{
+       int result;
+
+       result = vconf_set_int(key, value);
+
+       if (result == 0)
+               return true;
+       else
+               return false;
+}
diff --git a/Framework/Event/OMA_DS_Event_Handler.c b/Framework/Event/OMA_DS_Event_Handler.c
new file mode 100644 (file)
index 0000000..1dfc45a
--- /dev/null
@@ -0,0 +1,1028 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Event_Handler.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of event callback function(from ui)
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+#include "Framework/Event/OMA_DS_Event_Handler.h"
+#include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
+#include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
+#include "Common/Common_Define.h"
+#include "Common/Common_Vconf.h"
+#include "Common/Common_Util.h"
+#include "agent-framework/Utility/fw_log.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+
+static void __request_manual_sync_task_finish_callback(task_error_t task_error,
+                                                                                                               unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
+
+static void __auto_configure_task_finish_callback(task_error_t task_error,
+                                                                                                               unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
+
+
+static void __request_manual_sync_task_finish_callback(task_error_t task_error,
+                                                                                                                       unsigned int out_param_cnt,
+                                                                                                                       param_t **out_param_spec_array,
+                                                                                                                       void *usr_data)
+{
+       unsigned int request_msg_id_to_cancel = 0;
+       get_manual_sync_request_id(&request_msg_id_to_cancel);
+}
+
+static void __auto_configure_task_finish_callback(task_error_t task_error,
+                                                                                                                       unsigned int out_param_cnt,
+                                                                                                                       param_t **out_param_spec_array,
+                                                                                                                       void *usr_data)
+{
+       unsigned int request_msg_id_to_cancel = 0;
+       get_auto_configure_request_id(&request_msg_id_to_cancel);
+}
+
+/*TODO have to be removed after removing vconf*/
+int event_callback_add_account(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       int result;
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       /* send to engine controller */
+       void *in_param_value_array[1] = {&profile};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_ACCOUNT, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       append_eventdata_param(response, INTEGER, &result);
+
+       FW_LOGV("end");
+
+error:
+
+       return 0;
+}
+
+/*TODO have to be removed after removing vconf*/
+int event_callback_edit_account(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       int result;
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       /* send to engine controller */
+       void *in_param_value_array[1] = {&profile};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_EDIT_ACCOUNT, 0,
+                                                                                                                               1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       append_eventdata_param(response, INTEGER, &result);
+
+       FW_LOGV("end");
+
+error:
+
+       return 0;
+}
+
+/*TODO have to be removed after removing vconf*/
+int event_callback_auto_configure(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       FW_LOGV("request param : %s", profile);
+
+       void *in_param_value_array[1] = {&profile};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_AUTOCONFIGURE, 0,
+                                                                                                                               1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               __auto_configure_task_finish_callback, NULL, (int *)&request_msg_id);
+
+       insert_request_msg_info(SYNC_MODE_AUTOCONFIG, request_msg_id);
+
+       FW_LOGV("end");
+
+error:
+
+       return 0;
+}
+
+int event_callback_add_profile_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profileDirName = NULL;
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       int category_count;
+       int result;
+       int accountId;
+
+       get_eventdata_param(request, &profileDirName);
+       get_eventdata_param(request, &profileName);
+       get_eventdata_param(request, &addr);
+       get_eventdata_param(request, &id);
+       get_eventdata_param(request, &password);
+       get_eventdata_param(request, &syncMode);
+       get_eventdata_param(request, &syncType);
+       get_eventdata_param(request, &interval);
+       get_eventdata_param(request, &category_count);
+
+       /*
+       FW_LOGV("request param : %s", profileDirName);
+       FW_LOGV("request param : %s", profileName);
+       FW_LOGV("request param : %s", addr);
+       FW_LOGV("request param : %s", id);
+       FW_LOGV("request param : %s", password);
+       FW_LOGV("request param : %s", syncMode);
+       FW_LOGV("request param : %s", syncType);
+       FW_LOGV("request param : %s", interval);
+       FW_LOGV("request param : %d", category_count);
+       */
+
+       GList *categorys = NULL;
+       sync_category *category = (sync_category *)calloc(1, sizeof(sync_category));
+
+       int i = 0;
+       for (; i < category_count ; i++) {
+               get_eventdata_param(request, &(category->enabled));
+               get_eventdata_param(request, &(category->srcURI));
+               get_eventdata_param(request, &(category->tgtURI));
+               get_eventdata_param(request, &(category->id));
+               get_eventdata_param(request, &(category->password));
+
+               categorys = g_list_append(categorys, category);
+
+               /*
+               FW_LOGV("category[i]->enabled : %d", category->enabled);
+               FW_LOGV("category[i]->srcURI : %s", category->srcURI);
+               FW_LOGV("category[i]->tgtURI : %s", category->tgtURI);
+               FW_LOGV("category[i]->id : %s", category->id);
+               FW_LOGV("category[i]->password : %s", category->password);
+               */
+       }
+
+       /* send to engine controller */
+       void *in_param_value_array[9] = {&profileDirName, &profileName, &addr, &id, &password, &syncMode, &syncType, &interval, &categorys};
+       int in_param_index_array[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
+       ECValueType in_param_value_type_array[9] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE, 0,
+                                                                                                                       9, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, INTEGER, &accountId);
+
+
+       FW_LOGV("end");
+
+       return 0;
+}
+
+int event_callback_edit_profile_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profileDirName = NULL;
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       int category_count;
+       int result;
+
+       get_eventdata_param(request, &profileDirName);
+
+       if (!profileDirName) {
+               FW_LOGE("profileDirName is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profileDirName);
+
+       int accountId =  get_accountid(profileDirName, false);
+
+       get_eventdata_param(request, &profileName);
+       get_eventdata_param(request, &addr);
+       get_eventdata_param(request, &id);
+       get_eventdata_param(request, &password);
+       get_eventdata_param(request, &syncMode);
+       get_eventdata_param(request, &syncType);
+       get_eventdata_param(request, &interval);
+       get_eventdata_param(request, &category_count);
+
+       /*
+       FW_LOGV("request param : %s", profileName);
+       FW_LOGV("request param : %s", addr);
+       FW_LOGV("request param : %s", id);
+       FW_LOGV("request param : %s", password);
+       FW_LOGV("request param : %s", syncMode);
+       FW_LOGV("request param : %s", syncType);
+       FW_LOGV("request param : %s", interval);
+       FW_LOGV("request param : %d", category_count);
+       */
+
+       GList *categorys = NULL;
+       sync_category *category = (sync_category *)calloc(1, sizeof(sync_category));
+
+       int i = 0;
+       for (; i < category_count ; i++) {
+               get_eventdata_param(request, &(category->enabled));
+               get_eventdata_param(request, &(category->srcURI));
+               get_eventdata_param(request, &(category->tgtURI));
+               get_eventdata_param(request, &(category->id));
+               get_eventdata_param(request, &(category->password));
+
+               categorys = g_list_append(categorys, category);
+
+               /*
+               FW_LOGV("category[i]->enabled : %d", category->enabled);
+               FW_LOGV("category[i]->srcURI : %s", category->srcURI);
+               FW_LOGV("category[i]->tgtURI : %s", category->tgtURI);
+               FW_LOGV("category[i]->id : %s", category->id);
+               FW_LOGV("category[i]->password : %s", category->password);
+               */
+       }
+
+       /* send to engine controller */
+       void *in_param_value_array[9] = {&accountId, &profileName, &addr, &id, &password, &syncMode, &syncType, &interval, &categorys};
+       int in_param_index_array[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
+       ECValueType in_param_value_type_array[9] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE, 0,
+                                                                                                                       9, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       append_eventdata_param(response, INTEGER, &result);
+
+       FW_LOGV("end");
+
+error:
+
+       return 0;
+}
+
+int event_callback_delete_profile_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       int result;
+       int count;
+       get_eventdata_param(request, &count);
+       GList *profiles = NULL;
+       int *accountId = 0;
+
+       int i;
+       char *profile = NULL;
+       for (i = 0; i < count; i++) {
+               if (profile != NULL) {
+                       free(profile);
+                       profile = NULL;
+               }
+
+               get_eventdata_param(request, &profile);
+               if (!profile) {
+                       FW_LOGE("profile is not defined");
+                       goto error;
+               }
+               FW_LOGV("request param : %s", profile);
+
+               accountId = (int *)calloc(1, sizeof(int));
+               *accountId = get_accountid(profile, false);
+
+               profiles = g_list_append(profiles, accountId);
+       }
+
+       /* send to engine controller */
+       void *in_param_value_array[1] = {&profiles};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE, 0,
+                                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       append_eventdata_param(response, INTEGER, &result);
+
+       FW_LOGV("end");
+
+error:
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_request_sync_async(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+       char *syncMode = strdup(DEFINE_SYNC_MODE_MANUAL);
+
+       void *in_param_value_array[3] = {&accountId, &syncMode, NULL};
+       int in_param_index_array[3] = {0, 1, 2};
+       ECValueType in_param_value_type_array[3] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
+                                                                                                                               3, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               __request_manual_sync_task_finish_callback, NULL, (int *)&request_msg_id);
+
+       insert_request_msg_info(SYNC_MODE_MANUAL, request_msg_id);
+
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_auto_configure_async(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profileDirName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+
+       get_eventdata_param(request, &profileDirName);
+       get_eventdata_param(request, &addr);
+       get_eventdata_param(request, &id);
+       get_eventdata_param(request, &password);
+
+       /*
+       FW_LOGV("request param : %s", profileDirName);
+       FW_LOGV("request param : %s", addr);
+       FW_LOGV("request param : %s", id);
+       FW_LOGV("request param : %s", password);
+       */
+
+       void *in_param_value_array[4] = {&profileDirName, &addr, &id, &password};
+       int in_param_index_array[4] = {0, 1, 2, 3};
+       ECValueType in_param_value_type_array[4] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_AUTO_CONFIGURE, 0,
+                                                                                                                               4, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               __auto_configure_task_finish_callback, NULL, (int *)&request_msg_id);
+
+       insert_request_msg_info(SYNC_MODE_AUTOCONFIG, request_msg_id);
+
+       FW_LOGV("end");
+
+       return 0;
+}
+
+int event_callback_cancel_sync_async(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       FW_LOGV("request param : %s", profile);
+
+       unsigned int request_msg_id_to_cancel =  0;
+       bool has_autoconfig = get_auto_configure_request_id(&request_msg_id_to_cancel);
+       if (has_autoconfig) {
+               FW_LOGV("has_autoconfig [%d] ", request_msg_id_to_cancel);
+               engine_controller_cancel_task(request_msg_id_to_cancel);
+       } else{
+               bool has_sync = get_synchronizing_request_id(&request_msg_id_to_cancel);
+               if (has_sync) {
+                       FW_LOGV("has_manual_sync [%d] ", request_msg_id_to_cancel);
+                       engine_controller_cancel_task(request_msg_id_to_cancel);
+
+                       /*request network session cancel*/
+                       /*engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST, 0,
+                                                                                                                               0, NULL, NULL, NULL, NULL, NULL, &request_msg_id);*/
+               } else {
+                       /* nothing to do */
+               }
+       }
+
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_query_sync_status_async(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_SYNCSTATUS, 0,
+                                                                                                                       0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id);
+
+       FW_LOGV("end");
+       return 0;
+}
+
+int event_callback_get_profile_name_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       char *profileName = NULL;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[1] = {0};
+       void *in_param_value_array[1] = {&accountId};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_NAME, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("profileName = %s", profileName);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, STRING, (void *)profileName);
+
+
+       FW_LOGV("end");
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_server_info_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[1] = {0};
+       void *in_param_value_array[1] = {&accountId};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SERVER_INFO, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("addr = %s", addr);
+       FW_LOGV("id = %s", id);
+       FW_LOGV("password = %s", password);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, STRING, (void *)addr);
+       append_eventdata_param(response, STRING, (void *)id);
+       append_eventdata_param(response, STRING, (void *)password);
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_sync_mode_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[1] = {0};
+       void *in_param_value_array[1] = {&accountId};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_MODE, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("syncMode = %s", syncMode);
+       FW_LOGV("syncType = %s", syncType);
+       FW_LOGV("interval = %s", interval);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, STRING, (void *)syncMode);
+       append_eventdata_param(response, STRING, (void *)syncType);
+       append_eventdata_param(response, STRING, (void *)interval);
+
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_sync_category_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       int content_type;
+       int enabled;
+       char *srcURI = NULL;
+       char *tgtURI = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       get_eventdata_param(request, &content_type);
+
+       FW_LOGV("request param : %s", profile);
+       FW_LOGV("request param : %d", content_type);
+
+       int accountId =  get_accountid(profile, false);
+       FW_LOGV(" accountId: %d", accountId);
+
+       int in_param_index_array[2] = {0, 1};
+       void *in_param_value_array[2] = {&accountId, &content_type};
+       ECValueType in_param_value_type_array[2] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY, 0,
+                                                                                                                       2, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &enabled);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &srcURI);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &tgtURI);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("enabled = %d", enabled);
+       FW_LOGV("srcURI = %s", srcURI);
+       FW_LOGV("tgtURI = %s", tgtURI);
+       FW_LOGV("id = %s", id);
+       FW_LOGV("password = %s", password);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, INTEGER, &enabled);
+       append_eventdata_param(response, STRING, (void *)srcURI);
+       append_eventdata_param(response, STRING, (void *)tgtURI);
+       append_eventdata_param(response, STRING, (void *)id);
+       append_eventdata_param(response, STRING, (void *)password);
+
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_last_session_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       int result;
+       int lastSessionStatus;
+       int lastSessionTime;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[1] = {0};
+       void *in_param_value_array[1] = {&accountId};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_LAST_SESSION, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &lastSessionStatus);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("lastSessionStatus = %d", lastSessionStatus);
+       FW_LOGV("lastSessionTime = %d", lastSessionTime);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, INTEGER, &lastSessionStatus);
+       append_eventdata_param(response, INTEGER, &lastSessionTime);
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_last_statistics_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profile = NULL;
+       int content_type;
+       char *dbSynced = NULL;
+       int lastSessionTime;
+       int server2Client_Total;
+       int server2Client_NrOfAdd;
+       int server2Client_NrOfDelete;
+       int server2Client_NrOfReplace;
+       int client2Server_Total;
+       int client2Server_NrOfAdd;
+       int client2Server_NrOrDelete;
+       int client2Server_NrOfReplace;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       get_eventdata_param(request, &content_type);
+
+       FW_LOGV("request param : %s", profile);
+       FW_LOGV("request param : %d", content_type);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[2] = {0, 1};
+       void *in_param_value_array[2] = {&accountId, &content_type};
+       ECValueType in_param_value_type_array[2] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS, 0,
+                                                                                                                       2, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &dbSynced);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_INT, &server2Client_Total);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfAdd);
+       param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfDelete);
+       param_value_get_value(&(param_array[6]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfReplace);
+       param_value_get_value(&(param_array[7]->param_value), EC_VALUE_TYPE_INT, &client2Server_Total);
+       param_value_get_value(&(param_array[8]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfAdd);
+       param_value_get_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOrDelete);
+       param_value_get_value(&(param_array[10]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfReplace);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("dbSynced = %s\n", dbSynced);
+       FW_LOGV("lastSessionTime = %d\n", lastSessionTime);
+       FW_LOGV("server2Client_Total = %d\n", server2Client_Total);
+       FW_LOGV("server2Client_NrOfAdd = %d\n", server2Client_NrOfAdd);
+       FW_LOGV("server2Client_NrOfDelete = %d\n", server2Client_NrOfDelete);
+       FW_LOGV("server2Client_NrOfReplace = %d\n", server2Client_NrOfReplace);
+       FW_LOGV("client2Server_Total = %d\n", client2Server_Total);
+       FW_LOGV("client2Server_NrOfAdd = %d\n", client2Server_NrOfAdd);
+       FW_LOGV("client2Server_NrOrDelete = %d\n", client2Server_NrOrDelete);
+       FW_LOGV("client2Server_NrOfReplace = %d\n", client2Server_NrOfReplace);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, STRING, (void *)dbSynced);
+       append_eventdata_param(response, INTEGER, &lastSessionTime);
+       append_eventdata_param(response, INTEGER, &server2Client_Total);
+       append_eventdata_param(response, INTEGER, &server2Client_NrOfAdd);
+       append_eventdata_param(response, INTEGER, &server2Client_NrOfDelete);
+       append_eventdata_param(response, INTEGER, &server2Client_NrOfReplace);
+       append_eventdata_param(response, INTEGER, &client2Server_Total);
+       append_eventdata_param(response, INTEGER, &client2Server_NrOfAdd);
+       append_eventdata_param(response, INTEGER, &client2Server_NrOrDelete);
+       append_eventdata_param(response, INTEGER, &client2Server_NrOfReplace);
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+
+int event_callback_add_profile_cp_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       int category_count;
+       int result;
+       int accountId;
+
+       get_eventdata_param(request, &profileName);
+       get_eventdata_param(request, &addr);
+       get_eventdata_param(request, &id);
+       get_eventdata_param(request, &password);
+       get_eventdata_param(request, &category_count);
+
+       /*
+       FW_LOGV("request param : %s", profileName);
+       FW_LOGV("request param : %s", addr);
+       FW_LOGV("request param : %s", id);
+       FW_LOGV("request param : %s", password);
+       FW_LOGV("request param : %d", category_count);
+       */
+
+       GList *categorys = NULL;
+       int i = 0;
+       for (; i < category_count ; i++) {
+               resource_cp *category = (resource_cp *)calloc(1, sizeof(resource_cp));
+
+               get_eventdata_param(request, &(category->name));
+               get_eventdata_param(request, &(category->accept));
+               get_eventdata_param(request, &(category->id));
+               get_eventdata_param(request, &(category->password));
+               get_eventdata_param(request, &(category->authType));
+               get_eventdata_param(request, &(category->authData));
+
+               categorys = g_list_append(categorys, category);
+
+               /*
+               FW_LOGV("category[%d]->name : %s", i, category->name);
+               FW_LOGV("category[%d]->accept : %s", i, category->accept);
+               FW_LOGV("category[%d]->id : %s", i, category->id);
+               FW_LOGV("category[%d]->password : %s", i, category->password);
+               FW_LOGV("category[%d]->authType : %s", i, category->authType);
+               FW_LOGV("category[%d]->authData : %s\n", i, category->authData);
+               */
+       }
+
+       /* send to engine controller */
+       void *in_param_value_array[5] = {&profileName, &addr, &id, &password, &categorys};
+       int in_param_index_array[5] = {0, 1, 2, 3, 4};
+       ECValueType in_param_value_type_array[5] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP, 0,
+                                                                                                                       5, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, INTEGER, &accountId);
+
+
+       FW_LOGV("end");
+
+       return 0;
+}
diff --git a/Framework/Event/OMA_DS_Platform_Event_Handler.c b/Framework/Event/OMA_DS_Platform_Event_Handler.c
new file mode 100644 (file)
index 0000000..eab720c
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Platform_Event_Handler.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of event callback function(from platform)
+ */
+
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
+#include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
+#include "Framework/SAN_parser/PM_SanParser.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Define_Internal.h"
+#include "Common/Common_Util.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+
+static void __request_periodic_sync_task_finish_callback(task_error_t task_error,
+                                                                                       unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
+
+static void __request_san_sync_task_finish_callback(task_error_t task_error,
+                                                                                       unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
+
+static void __request_periodic_sync_task_finish_callback(task_error_t task_error,
+                                                                                                                       unsigned int out_param_cnt,
+                                                                                                                       param_t **out_param_spec_array,
+                                                                                                                       void *usr_data)
+{
+       unsigned int request_msg_id_to_cancel = 0;
+       get_periodic_sync_request_id(&request_msg_id_to_cancel);
+
+}
+
+static void __request_san_sync_task_finish_callback(task_error_t task_error,
+                                                                                                                       unsigned int out_param_cnt,
+                                                                                                                       param_t **out_param_spec_array,
+                                                                                                                       void *usr_data)
+{
+       unsigned int request_msg_id_to_cancel = 0;
+       get_san_sync_request_id(&request_msg_id_to_cancel);
+}
+
+int SAN_callback_parse(const char *msgBody, unsigned int msgSize, int version)
+{
+       FW_LOGV("start");
+       SanPackage  *pSanPackage = NULL;
+       int accountID = -1;
+       char *sync_mode = NULL;
+       char *server_id = NULL;
+       int *account_list = 0;
+
+       switch (version) {
+       case 11:
+       {
+               pSanPackage = sanPackage11Parser(msgBody, msgSize) ;
+       }
+               break;
+       case 12:
+       {
+               pSanPackage = sanPackage12Parser(msgBody, msgSize) ;
+       }
+               break;
+       default:
+               break;
+       }
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS)
+               return 0;
+
+       if (!pSanPackage)
+               goto return_part;
+
+
+       int account_list_count = 0;
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+       bool result;
+
+       int i;
+       for (i = 0 ; i < account_list_count ; i++) {
+               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, &sync_mode);
+               if (result == true) {
+                       /*One device MUST NOT register multi account at same server...*/
+                       if (strcmp(sync_mode, DEFINE_SYNC_MODE_PUSH) == 0) {
+                               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id);
+                               if (result == true) {
+                                       /*One device MUST NOT register multi account at same server...*/
+                                       if (strcmp(pSanPackage->serverID, server_id) == 0) {
+                                               accountID = account_list[i];
+                                               break;
+                                       }
+                               } else{
+                                       FW_LOGE("failed in get_Config");
+                                       goto return_part;
+                               }
+                       }
+               } else{
+                       FW_LOGE("failed in get_Config");
+                       goto return_part;
+               }
+
+       }
+
+       if (accountID < 0)
+               goto return_part;
+
+       char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH) ;
+
+       void *in_param_value_array[3] = {&accountID, &syncMode, &pSanPackage};
+       int in_param_index_array[3] = {0, 1, 2};
+       ECValueType in_param_type[3] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
+                                                                                                                       3, in_param_index_array, in_param_type, in_param_value_array,
+                                                                                                                       __request_san_sync_task_finish_callback, NULL,
+                                                                                                                       (int *)&request_msg_id);
+
+       insert_request_msg_info(SYNC_MODE_SAN, request_msg_id);
+
+return_part:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       if (sync_mode)
+               free(sync_mode);
+
+       if (server_id)
+               free(server_id);
+
+       DACI_Close_Agent();
+
+       FW_LOGV("end");
+       return 0;
+}
+
+void send_periodic_sync_msg(int schedulerId, void *data)
+{
+       FW_LOGV("#######Scheduler Send Msg Success!!!!!##########");
+       FW_LOGV("schedulerId = %d", schedulerId);
+
+       int *account_list = 0;
+       int account_list_count = 0;
+       int accountId = -1;
+       int alarmId = 0;
+       char *alarmId_str = NULL;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Open_Agent");
+               goto error;
+       }
+
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+
+       FW_LOGV("account_list_count = %d", account_list_count);
+
+       int i;
+       for (i = 0; i < account_list_count; i++) {
+               if (alarmId_str != NULL)
+                       free(alarmId_str);
+
+               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &alarmId_str);
+               if (result == false) {
+                       FW_LOGE("failed in get_Config");
+                       goto error;
+               }
+               alarmId = atoi(alarmId_str);
+               FW_LOGV("alarm id = %d", alarmId);
+               if (alarmId == schedulerId) {
+                       FW_LOGV("account_list[i] = %d", account_list[i]);
+                       accountId = account_list[i];
+                       break;
+               }
+       }
+
+       if (accountId != -1) {
+               int in_param_index_array[3] = {0, 1, 2};
+               ECValueType in_param_value_type_array[3] = {EC_VALUE_TYPE_INT,
+                                                                                       EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+               char *syncMode = strdup(DEFINE_SYNC_MODE_PERIODIC);
+
+               void *in_param_value_array[3] = {&accountId, &syncMode, NULL};
+
+               unsigned int request_msg_id = 0;
+               engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
+                                                                                                                                       3, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                                       __request_periodic_sync_task_finish_callback, NULL,
+                                                                                                                                       (int *)&request_msg_id);
+
+               insert_request_msg_info(SYNC_MODE_PERIODIC, request_msg_id);
+       }
+
+error:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       if (alarmId_str != NULL)
+               free(alarmId_str);
+
+       DACI_Close_Agent();
+}
diff --git a/Framework/SAN_parser/PM_SanParser.c b/Framework/SAN_parser/PM_SanParser.c
new file mode 100644 (file)
index 0000000..6684369
--- /dev/null
@@ -0,0 +1,628 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+\r
+\r
+/*\r
+ * For any sort of issue you concern as to this software,\r
+ * you may use following point of contact.\r
+ * All resources contributed on this software\r
+ * are orinigally written by S-Core Inc., a member of Samsung Group.\r
+ *\r
+ * SeongWon Shim <seongwon.shim@samsung.com>\r
+ */\r
+\r
+/**\r
+ *   @PM_SanParser.c\r
+ *   @version                                                                  0.1\r
+ *   @brief                                                                            This file is the source file of implementation of San Parser\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <stdbool.h>\r
+#include <string.h>\r
+#include <inttypes.h>\r
+#include <glib.h>\r
+#include "wbxml/wbxml.h"\r
+#include "wbxml/wbxml_tree.h"\r
+\r
+#include "Framework/SAN_parser/PM_SanParser.h"\r
+#include "agent-framework/Utility/fw_log.h"\r
+\r
+#define LOG_TAG        "OMA_DS_COMMON"\r
+\r
+static SanContentType contentTypeSupported[] = {\r
+       {0x00,          NULL},\r
+       {0x03,          "text/plain"},\r
+       {0x06,          "text/x-vcalendar"},\r
+       {0x07,          "text/x-vcard"},\r
+       {0x0305,        "text/calendar"},\r
+       {0x0306,        "application/vnd.omads-email+xml"},\r
+       {0x0307,        "application/vnd.omads-file+xml"},\r
+       {0x0308,        "application/vnd.omads-folder+xml"},\r
+       {0x0309,        "text/vcard"}\r
+};\r
+\r
+SanPackage *sanPackage12Parser(const char *msgBody, unsigned int msgSize)\r
+{\r
+       unsigned int idLength = (uint8_t)msgBody[23];\r
+       if (msgSize < (25 + idLength)) {\r
+               FW_LOGV("[sanPackage12Parser] SAN package size is smaller than");\r
+               FW_LOGV("[sanPackage12Parser] its minimal size specified in the spec, related to [Header] part.");\r
+               return NULL;\r
+       }\r
+       \r
+       SanPackage *san = (SanPackage *)calloc(1, sizeof(SanPackage));\r
+       if (!san) {\r
+               FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Container]");\r
+               return NULL;\r
+       }\r
+\r
+       /* MSG BODY WITHOUT DIGEST*/\r
+       san->msgBodyWithoutDigest = (char *)calloc(msgSize - 16, sizeof(char));\r
+       if (!san->msgBodyWithoutDigest) {\r
+               FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Msg body]");\r
+               goto error;\r
+       }\r
+       memcpy(san->msgBodyWithoutDigest, msgBody + 16, msgSize - 16);\r
+       san->msgBodyWithoutDigestLength = msgSize - 16;\r
+       \r
+       /* DIGEST*/\r
+       san->digest = (char *)calloc(16, sizeof(char));\r
+       if (!san->digest) {\r
+               FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Digest]");\r
+               goto error;\r
+       }\r
+       memcpy(san->digest, msgBody, 16);\r
+       \r
+       /* VERSION*/\r
+       unsigned int version = ((uint8_t)msgBody[16]) << 2;\r
+       version = version | ((uint8_t)msgBody[17]) >> 6;\r
+\r
+       if (version != 12) {\r
+               FW_LOGV("[sanPackage12Parser] Not supported SAN version %d.", version);\r
+               goto error;\r
+       }\r
+       san->version  = version;\r
+       \r
+       /* UI MODE*/\r
+       san->uiMode = (((uint8_t)msgBody[17]) & 0x30) >> 4;\r
+       \r
+       /* INITIATOR*/\r
+       san->initiator = (((uint8_t)msgBody[17]) & 0x08) >> 3;\r
+\r
+       /* SESSION ID*/\r
+/*san->sessionID = ((uint8_t)msgBody[21]) << 8;\r
+       san->sessionID = san->sessionID | (uint8_t)msgBody[22];*/\r
+       san->sessionID = atoi(g_strdup_printf("%02X%02X", msgBody[21], msgBody[22]));\r
+       FW_LOGV("session id : %d \n", san->sessionID);\r
+       \r
+       /* SERVER ID*/\r
+       if (idLength) {\r
+               san->serverID = (char *)calloc(idLength + 1, sizeof(char));\r
+               if (!san->serverID) {\r
+                       FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Server ID]");\r
+                       goto error;\r
+               }\r
+               memcpy(san->serverID, msgBody + 24, idLength);\r
+       }\r
+       \r
+       san->cntSyncAlerts = ((uint8_t)msgBody[24 + idLength]) >> 4;\r
+\r
+       if (san->cntSyncAlerts == 0) {\r
+               if (msgSize > 24 + idLength + 1) {\r
+                       FW_LOGV("[sanPackage12Parser] There are remaining bytes at the end of the package. (w/o alerts info)");\r
+               }\r
+\r
+               /* If number of sync alerts equals 0, should sync all data store in the client*/\r
+               return san;\r
+       }\r
+\r
+       san->syncAlerts = (SanSyncAlert *)calloc(san->cntSyncAlerts, sizeof(SanSyncAlert));\r
+\r
+       msgBody += 25 + idLength;\r
+       unsigned int alertLength = 25 + idLength;\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < san->cntSyncAlerts; i++) {\r
+               \r
+               idLength = (uint8_t)msgBody[4];\r
+               if (msgSize < (alertLength + 5 + idLength)) {\r
+                       FW_LOGV("[sanPackage12Parser] SAN package size is smaller than");\r
+                       FW_LOGV("[sanPackage12Parser] its minimal size specified in the spec, related to [Alerts] part.");\r
+                       goto error;\r
+               }\r
+               alertLength = alertLength + 5 + idLength;\r
+               \r
+               /* SYNC TYPE*/\r
+               SanSyncType alert_type = (((uint8_t)msgBody[0]) >> 4) + 200;\r
+               if (alert_type < 206 || alert_type > 210) {\r
+                       FW_LOGV("[sanPackage12Parser] SAN doesn't support the sync type %d.", alert_type);\r
+                       goto error;\r
+               }\r
+               \r
+               unsigned int contentType = ((uint8_t)msgBody[1]) << 16;\r
+               contentType = contentType | ((uint8_t)msgBody[2]) << 8;\r
+               contentType = contentType | ((uint8_t)msgBody[3]);\r
+               \r
+               /* CONTENT TYPE*/\r
+               char *alert_ct = NULL;\r
+\r
+               int j;\r
+               int cnt = (int)sizeof(contentTypeSupported)/sizeof(SanContentType);\r
+               bool isContentSupported = false;\r
+               \r
+               for (j = 0 ; j < cnt ; j++) {\r
+                       if (contentType == contentTypeSupported[j].type) {\r
+                               alert_ct = contentTypeSupported[j].strType;\r
+                               isContentSupported = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (!isContentSupported) {\r
+                       FW_LOGV("[sanPackage12Parser] SAN doesn't support the content type %d.", contentType);\r
+                       goto error;\r
+               }\r
+               \r
+               /* SERVER URI*/\r
+               char *alert_uri = NULL;\r
+               \r
+               if (idLength) {\r
+                       alert_uri = (char *)calloc(idLength + 1, sizeof(char));\r
+                       if (!alert_uri) {\r
+                               FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Server URI]");\r
+                               goto error;\r
+                       }\r
+                       memcpy(alert_uri, msgBody + 5, idLength);\r
+               }\r
+               msgBody += 5 + idLength;\r
+\r
+               san->syncAlerts[i].syncType = alert_type;\r
+               san->syncAlerts[i].contentType = alert_ct;\r
+               san->syncAlerts[i].serverURI = alert_uri;\r
+\r
+       }\r
+\r
+       if (msgSize > alertLength) {\r
+               FW_LOGV("[sanPackage12Parser] There are remaining bytes at the end of the package. (with alerts info)");\r
+       }\r
+\r
+       return san;\r
+\r
+error:\r
+       sanPackageParserFree(san);\r
+       return NULL;\r
+       \r
+}\r
+\r
+WBXMLTreeNode *__get_node_elt_from_name(WBXMLTreeNode *node, const char *name, WB_BOOL recurs)\r
+{\r
+       WBXMLTreeNode *current_node = NULL;\r
+       WBXMLTreeNode *recurs_node = NULL;\r
+\r
+       if ((node == NULL) || (name == NULL))\r
+               return NULL;\r
+\r
+       /* Let's go through the tree */\r
+       current_node = node;\r
+\r
+       while (current_node != NULL) {\r
+               /* Is this a normal node? */\r
+               if (current_node->type == WBXML_TREE_ELEMENT_NODE) {\r
+                       /* Is this the Node we searched ? */\r
+                       if (WBXML_STRCMP(wbxml_tag_get_xml_name(current_node->name), name) == 0) {\r
+                               return current_node;\r
+                       }\r
+\r
+                       /* Sould we start a recursive search? */\r
+                       if (recurs && current_node->children) {\r
+                               recurs_node = __get_node_elt_from_name(current_node->children, name, TRUE);\r
+                               /* Is this the Node we searched ? */\r
+                               if (recurs_node) {\r
+                                       return recurs_node;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               /* Go to next Sibbling Node */\r
+               current_node = current_node->next;\r
+       }\r
+\r
+       /* A node with the specified name could not be found. */\r
+       return NULL;\r
+}\r
+\r
+SanPackage *sanPackage11Parser(const char *msgBody, unsigned int msgSize)\r
+{\r
+       SanPackage *san = (SanPackage *)calloc(1, sizeof(SanPackage));\r
+       if (!san) {\r
+               FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [Container]");\r
+               return NULL;\r
+       }\r
+\r
+       WBXMLTree *wbxml_tree = NULL;\r
+       WBXMLError wbxml_err = wbxml_tree_from_wbxml((unsigned char *)msgBody, msgSize, WBXML_LANG_UNKNOWN, WBXML_CHARSET_UNKNOWN, &wbxml_tree);\r
+\r
+       if (wbxml_err != WBXML_OK) {\r
+               FW_LOGV("[sanPackage11Parser] Libwbxml2 failed to parse WBXML STREAM to WBXML TREE, error code : %s", wbxml_errors_string(wbxml_err));\r
+               goto error;\r
+       }\r
+\r
+       WBXMLTreeNode *synchdr_node;\r
+       if ((synchdr_node = __get_node_elt_from_name(wbxml_tree->root, "SyncHdr", TRUE)) == NULL) {\r
+               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [SyncHdr]");\r
+               goto error;\r
+       }\r
+       WBXMLTreeNode *child_node = NULL;\r
+       const char *child_node_name = NULL;\r
+\r
+       for (child_node = synchdr_node->children ; child_node != NULL ; child_node = child_node->next) {\r
+               child_node_name = (const char *)wbxml_tag_get_xml_name(child_node->name);\r
+\r
+               if ((strcmp(child_node_name, "VerDTD") == 0) || (strcmp(child_node_name, "VerProto") == 0)) {\r
+                       char *version = NULL;\r
+                       if (child_node->children != NULL &&\r
+                               child_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               child_node->children->content != NULL) {\r
+\r
+                               version = (char *)wbxml_buffer_get_cstr(child_node->children->content);\r
+\r
+                               if (strcmp(version, "1.1") && strcmp(version, "SyncML/1.1")) {\r
+                                       FW_LOGV("[sanPackage11Parser] Not supported SAN version %s.", version);\r
+                                       goto error;\r
+                               }\r
+                               san->version = 11;\r
+                       }\r
+               } else if (strcmp(child_node_name, "SessionID") == 0) {\r
+                       char *sessionID = NULL;\r
+                       if (child_node->children != NULL &&\r
+                               child_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               child_node->children->content != NULL) {\r
+\r
+                               sessionID = (char *)wbxml_buffer_get_cstr(child_node->children->content);\r
+\r
+                               if (!sessionID) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL sessionID detected. sessionID MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+                               san->sessionID = atoi(sessionID);\r
+                       }\r
+               } else if (strcmp(child_node_name, "Source") == 0) {\r
+                       char *serverID = NULL;\r
+                       unsigned serverIDlen = 0;\r
+                       WBXMLTreeNode *serverid_node;\r
+                       if ((serverid_node = __get_node_elt_from_name(child_node, "LocURI", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [LocURI]");\r
+                               goto error;\r
+                       }\r
+\r
+                       if (serverid_node->children != NULL &&\r
+                               serverid_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               serverid_node->children->content != NULL) {\r
+               \r
+                               serverID = (char *)wbxml_buffer_get_cstr(serverid_node->children->content);\r
+                               serverIDlen = wbxml_buffer_len(serverid_node->children->content);\r
+                               if (!serverID) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL serverID detected. serverID MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+\r
+                               san->serverID = (char *)calloc(serverIDlen, sizeof(char));\r
+                               if (!san->serverID) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [Server ID]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->serverID, serverID, serverIDlen);\r
+                       }\r
+               } else if (strcmp(child_node_name, "Cred") == 0) {\r
+\r
+                       san->cred = (SanCred *)calloc(1, sizeof(SanCred));\r
+                       \r
+                       char *credFormat = NULL;\r
+                       unsigned credFormatLen = 0;\r
+                       WBXMLTreeNode *credformat_node;\r
+                       if ((credformat_node = __get_node_elt_from_name(child_node, "Format", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Format]");\r
+                               goto error;\r
+                       }\r
+\r
+                       if (credformat_node->children != NULL &&\r
+                               credformat_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               credformat_node->children->content != NULL) {\r
+               \r
+                               credFormat = (char *)wbxml_buffer_get_cstr(credformat_node->children->content);\r
+                               credFormatLen = wbxml_buffer_len(credformat_node->children->content);\r
+                               if (!credFormat) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL credFormat detected. credFormat MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+               \r
+                               san->cred->credFormat = (char *)calloc(credFormatLen, sizeof(char));\r
+                               if (!san->cred->credFormat) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [credFormat]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->cred->credFormat, credFormat, credFormatLen);\r
+                       }\r
+\r
+                       char *credAuth = NULL;\r
+                       unsigned credAuthLen = 0;\r
+                       WBXMLTreeNode *credauth_node;\r
+                       if ((credauth_node = __get_node_elt_from_name(child_node, "Type", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Type]");\r
+                               goto error;\r
+                       }\r
+\r
+                       if (credauth_node->children != NULL &&\r
+                               credauth_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               credauth_node->children->content != NULL) {\r
+               \r
+                               credAuth = (char *)wbxml_buffer_get_cstr(credauth_node->children->content);\r
+                               credAuthLen = wbxml_buffer_len(credauth_node->children->content);\r
+                               if (!credAuth) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL credAuth detected. credAuth MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+               \r
+                               san->cred->credAuth = (char *)calloc(credAuthLen, sizeof(char));\r
+                               if (!san->cred->credAuth) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [credAuth]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->cred->credAuth, credAuth, credAuthLen);\r
+                       }\r
+\r
+                       char *credData = NULL;\r
+                       unsigned credDataLen = 0;\r
+                       WBXMLTreeNode *creddata_node;\r
+                       if ((creddata_node = __get_node_elt_from_name(child_node, "Data", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Data]");\r
+                               goto error;\r
+                       }\r
+\r
+                       if (creddata_node->children != NULL &&\r
+                               creddata_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               creddata_node->children->content != NULL) {\r
+               \r
+                               credData = (char *)wbxml_buffer_get_cstr(creddata_node->children->content);\r
+                               credDataLen = wbxml_buffer_len(creddata_node->children->content);\r
+                               if (!credData) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL credData detected. credData MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+               \r
+                               san->cred->credData = (char *)calloc(credDataLen, sizeof(char));\r
+                               if (!san->cred->credData) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [credData]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->cred->credData, credData, credDataLen);\r
+                       }\r
+\r
+               }\r
+\r
+       }\r
+\r
+       WBXMLTreeNode *syncbody_node;\r
+       if ((syncbody_node = __get_node_elt_from_name(wbxml_tree->root, "SyncBody", TRUE)) == NULL) {\r
+               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [SyncBody]");\r
+               goto error;\r
+       }\r
+       \r
+       WBXMLList *alertnode_list = wbxml_tree_node_get_all_children(syncbody_node);\r
+       unsigned int alertnode_list_len = wbxml_list_len(alertnode_list);\r
+\r
+       child_node = (WBXMLTreeNode *)wbxml_list_get(alertnode_list, alertnode_list_len - 1);\r
+       child_node_name = (const char *)wbxml_tag_get_xml_name(child_node->name);\r
+       if (strcmp(child_node_name, "Final") == 0)\r
+               san->cntSyncAlerts = alertnode_list_len - 1;\r
+\r
+       if (san->cntSyncAlerts == 0) {\r
+               /* If number of sync alerts equals 0, should sync all data store in the client*/\r
+               return san;\r
+       } else {\r
+               san->syncAlerts = (SanSyncAlert *)calloc(san->cntSyncAlerts, sizeof(SanSyncAlert));\r
+\r
+               unsigned int indexNode;\r
+               for (indexNode = 0; indexNode < san->cntSyncAlerts; indexNode++) {\r
+\r
+                       WBXMLTreeNode* alert_node = (WBXMLTreeNode *)wbxml_list_get(alertnode_list, indexNode);\r
+\r
+                       char *alertData = NULL;\r
+                       WBXMLTreeNode *alertdata_node;\r
+                       if ((alertdata_node = __get_node_elt_from_name(alert_node, "Data", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Data]");\r
+                               goto error;\r
+                       }\r
+                       \r
+                       if (alertdata_node->children != NULL &&\r
+                               alertdata_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               alertdata_node->children->content != NULL) {\r
+                       \r
+                               alertData = (char *)wbxml_buffer_get_cstr(alertdata_node->children->content);\r
+                               if (!alertData) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL alertData detected. alertData MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+\r
+                               if (atoi(alertData) < 206 || atoi(alertData) > 210) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN doesn't support the sync type %d.", atoi(alertData));\r
+                                       goto error;\r
+                               }\r
+\r
+                               san->syncAlerts[indexNode].syncType = atoi(alertData);\r
+                       }\r
+\r
+                       char *alertURI = NULL;\r
+                       unsigned alertURIlen = 0;\r
+                       WBXMLTreeNode *alerturi_node;\r
+                       if ((alerturi_node = __get_node_elt_from_name(alert_node, "LocURI", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [LocURI]");\r
+                               goto error;\r
+                       }\r
+                       \r
+                       if (alerturi_node->children != NULL &&\r
+                               alerturi_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               alerturi_node->children->content != NULL) {\r
+\r
+                               alertURI = (char *)wbxml_buffer_get_cstr(alerturi_node->children->content);\r
+                               alertURIlen = wbxml_buffer_len(alerturi_node->children->content);\r
+                               if (!alertURI) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL alertURI detected. alertURI MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+\r
+                               san->syncAlerts[indexNode].serverURI = (char *)calloc(alertURIlen, sizeof(char));\r
+                               if (!san->syncAlerts[indexNode].serverURI) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [serverURI]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->syncAlerts[indexNode].serverURI, alertURI, alertURIlen);\r
+                       }\r
+\r
+                       char *alertContentType = NULL;\r
+                       unsigned alertContentTypeLen = 0;\r
+                       WBXMLTreeNode *alertcontenttype_node;\r
+                       if ((alertcontenttype_node = __get_node_elt_from_name(alert_node, "Type", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Type]");\r
+                               goto error;\r
+                       }\r
+                       \r
+                       if (alertcontenttype_node->children != NULL &&\r
+                               alertcontenttype_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               alertcontenttype_node->children->content != NULL) {\r
+\r
+                               alertContentType = (char *)wbxml_buffer_get_cstr(alertcontenttype_node->children->content);\r
+                               alertContentTypeLen = wbxml_buffer_len(alertcontenttype_node->children->content);\r
+\r
+                               if (!alertContentType) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL alertContentType detected. alertContentType MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+\r
+                               int j;\r
+                               int cnt = (int)sizeof(contentTypeSupported)/sizeof(SanContentType);\r
+                               bool isContentSupported = false;\r
+\r
+                               for (j = 0 ; j < cnt ; j++) {\r
+                                       if (contentTypeSupported[j].strType == NULL)\r
+                                               continue;\r
+                                       if (strcmp(alertContentType, contentTypeSupported[j].strType) == 0) {\r
+                                               san->syncAlerts[indexNode].contentType = contentTypeSupported[j].strType;\r
+                                               isContentSupported = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               \r
+                               if (!isContentSupported) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN doesn't support the content type %s.", alertContentType);\r
+                                       goto error;\r
+                               }\r
+                       }\r
+               }       \r
+       }\r
+       \r
+       return san;\r
+\r
+       wbxml_tree_destroy(wbxml_tree);\r
+\r
+error:\r
+       sanPackageParserFree(san);\r
+       return NULL;\r
+       \r
+\r
+}\r
+\r
+void sanPackageParserFree(void *point)\r
+{\r
+       SanPackage *san = (SanPackage *)point;\r
+       if (san) {\r
+               if (san->msgBodyWithoutDigest)\r
+                       free(san->msgBodyWithoutDigest);\r
+               if (san->digest)\r
+                       free(san->digest);\r
+               if (san->cred) {\r
+                       if (san->cred->credFormat)\r
+                               free(san->cred->credFormat);\r
+                       if (san->cred->credAuth)\r
+                               free(san->cred->credAuth);\r
+                       if (san->cred->credData)\r
+                               free(san->cred->credData);\r
+                       free(san->cred);\r
+               }\r
+               if (san->serverID)\r
+                       free(san->serverID);\r
+               if (san->syncAlerts) {\r
+                       int i;\r
+                       for (i = 0 ; i < san->cntSyncAlerts ; i++) {\r
+                               if (san->syncAlerts[i].serverURI) {\r
+                                       free(san->syncAlerts[i].serverURI);\r
+                               }\r
+                       }\r
+                       free(san->syncAlerts);\r
+               }\r
+               free(san);\r
+       }\r
+}\r
+\r
+void sanPrintMsg(SanPackage *san)\r
+{\r
+       int i;\r
+\r
+       FW_LOGV("Printing SAN package ============================\n\n");\r
+\r
+       FW_LOGV("MsgBody without Digest :\n\t");\r
+       for (i = 0 ; i < san->msgBodyWithoutDigestLength ; i++) {\r
+               printf("%02x ", san->msgBodyWithoutDigest[i]);\r
+               if ((i + 1) % 16 == 0) printf("\n\t");\r
+       }\r
+       FW_LOGV("\n");\r
+\r
+       FW_LOGV("Digest : %s\n", san->digest);\r
+       if (san->cred) {\r
+               if (san->cred->credFormat)\r
+                       printf("Cred Format : %s\n", san->cred->credFormat);\r
+               if (san->cred->credAuth)\r
+                       printf("Cred Type : %s\n", san->cred->credAuth);\r
+               if (san->cred->credData)\r
+                       printf("Cred Data : %s\n", san->cred->credData);\r
+       }\r
+       FW_LOGV("Version : %d\n", san->version);\r
+       FW_LOGV("UI mode : %d\n", san->uiMode);\r
+       FW_LOGV("Initiator : %d\n", san->initiator);\r
+       FW_LOGV("Session ID : %u\n", san->sessionID);\r
+       FW_LOGV("Server ID : %s\n", san->serverID);\r
+       FW_LOGV("No. of Sync : %u\n", san->cntSyncAlerts);\r
+\r
+       for (i = 0 ; i < san->cntSyncAlerts ; i++) {\r
+               FW_LOGV("\n\t=== Sync No. %d ============\n", i+1);\r
+               FW_LOGV("\tSync type : %d\n", san->syncAlerts[i].syncType);\r
+               FW_LOGV("\tContent type : %s\n", san->syncAlerts[i].contentType);\r
+               FW_LOGV("\tServer URI : %s\n", san->syncAlerts[i].serverURI);\r
+       };\r
+\r
+}\r
+\r
diff --git a/Framework/Task/OMA_DS_Engine_Controller_Task.c b/Framework/Task/OMA_DS_Engine_Controller_Task.c
new file mode 100644 (file)
index 0000000..afe9749
--- /dev/null
@@ -0,0 +1,1324 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Engine_Controller_Task.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of make and register task to Engine Controller
+ */
+
+
+#include <string.h>
+#include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
+
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceEngine/SE_Account.h"
+#include "ServiceEngine/SE_AutoConfig.h"
+#include "ServiceEngine/SE_Sync.h"
+#include "ServiceEngine/SE_Storage.h"
+#include "ServiceEngine/SE_Notification.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+
+static GList *sync_request_id_list = NULL;
+
+static void __free_sync_categorie_list(void *list);
+static void __free_delete_profile_list(void *list);
+static void __free_resource_cp_list(void *list);
+
+static void __free_sync_category(sync_category *category);
+static void __free_resource_cp(resource_cp *resource);
+static request_msg_info_t *__create_request_msg_info(int sync_type, unsigned int request_id);
+static void __request_msg_info_free(request_msg_info_t *pInfo);
+
+static void *__string_copy_struct(void *string);
+
+
+
+static void __free_sync_categorie_list(void *list)
+{
+       GList *categories = (GList *)list;
+       GList *iter = NULL;
+       for (iter = categories; iter != NULL; iter = g_list_next(iter))
+               __free_sync_category(iter->data);
+
+
+       g_list_free(categories);
+}
+
+static void __free_delete_profile_list(void *list)
+{
+       GList *profiles = (GList *)list;
+       GList *iter = NULL;
+       for (iter = profiles; iter != NULL; iter = g_list_next(iter))
+               free(iter->data);
+
+       g_list_free(profiles);
+}
+
+static void __free_resource_cp_list(void *list)
+{
+       GList *profiles = (GList *)list;
+       GList *iter = NULL;
+       for (iter = profiles; iter != NULL; iter = g_list_next(iter))
+               __free_resource_cp(iter->data);
+
+       g_list_free(profiles);
+}
+
+static void __free_sync_category(sync_category *category)
+{
+       if (category->srcURI != NULL)
+               free(category->srcURI);
+
+       if (category->tgtURI != NULL)
+               free(category->tgtURI);
+
+       if (category->id != NULL)
+               free(category->id);
+
+       if (category->password != NULL)
+               free(category->password);
+
+       free(category);
+}
+
+static void __free_resource_cp(resource_cp *resource)
+{
+       if (resource->name != NULL)
+               free(resource->name);
+
+       if (resource->accept != NULL)
+               free(resource->accept);
+
+       if (resource->id != NULL)
+               free(resource->id);
+
+       if (resource->password != NULL)
+               free(resource->password);
+
+       if (resource->authType != NULL)
+               free(resource->authType);
+
+       if (resource->authData != NULL)
+               free(resource->authData);
+
+       free(resource);
+}
+
+static request_msg_info_t *__create_request_msg_info(int sync_type, unsigned int request_id)
+{
+       request_msg_info_t *pInfo = (request_msg_info_t *) calloc(1, sizeof(request_msg_info_t));
+       if (pInfo == NULL) {
+               return NULL;
+       }
+
+       pInfo->sync_type = sync_type;
+       pInfo->request_id = request_id;
+
+       return pInfo;
+}
+
+static void __request_msg_info_free(request_msg_info_t *pInfo)
+{
+       if (pInfo != NULL) {
+               free(pInfo);
+       }
+}
+
+static void *__string_copy_struct(void *string)
+{
+       return strdup((const char *)string);
+}
+
+
+
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_add_account_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profile", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[2] = {pParam_spec1, pParam_spec2};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("add_account",
+                                                                                       add_account_task_process, NULL, NULL,
+                                                                                       2, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+
+       return pTask_spec;
+}
+
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_edit_account_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profile", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[2] = {pParam_spec1, pParam_spec2};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("edit_account",
+                                                                                       edit_account_task_process, NULL, NULL,
+                                                                                       2, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+
+       return pTask_spec;
+}
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_autoconfigure_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profile", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *param_spec_array[1] = {pParam_spec1};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("auto_configure",
+                                                                                       autoconfigure_task_process, NULL, NULL,
+                                                                                       1, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_synchronize_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_structure("syncMode", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("sanPackage", NULL, sanPackageParserFree,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *param_spec_array[3] = {pParam_spec1, pParam_spec2, pParam_spec3};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("synchronize",
+                                                                                       synchronize_task_process, NULL, NULL,
+                                                                                       3, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_add_profile_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profileDirName", __string_copy_struct, free,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec2 = param_spec_structure("profileName", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec6 = param_spec_structure("syncMode", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec7 = param_spec_structure("syncType", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec8 = param_spec_structure("interval", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec9 = param_spec_structure("categories", NULL, __free_sync_categorie_list,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec10 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec11 = param_spec_int("accountId", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[11] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+                       pParam_spec6, pParam_spec7, pParam_spec8, pParam_spec9, pParam_spec10, pParam_spec11};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("add_profile",
+                                                                                       add_profile_task_process, NULL, NULL,
+                                                                                       11, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+       param_spec_unref(pParam_spec8);
+       param_spec_unref(pParam_spec9);
+       param_spec_unref(pParam_spec10);
+       param_spec_unref(pParam_spec11);
+
+       return pTask_spec;
+}
+
+
+task_spec_t *make_edit_profile_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_structure("profileName", __string_copy_struct, free,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec6 = param_spec_structure("syncMode", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec7 = param_spec_structure("syncType", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec8 = param_spec_structure("interval", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec9 = param_spec_structure("categories", NULL, __free_sync_categorie_list,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec10 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[10] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+                       pParam_spec6, pParam_spec7, pParam_spec8, pParam_spec9, pParam_spec10};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("edit_profile",
+                                                                                       edit_profile_task_process, NULL, NULL,
+                                                                                       10, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+       param_spec_unref(pParam_spec8);
+       param_spec_unref(pParam_spec9);
+       param_spec_unref(pParam_spec10);
+
+       return pTask_spec;
+}
+
+
+task_spec_t *make_delete_profile_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profiles", NULL, __free_delete_profile_list,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[2] = {pParam_spec1, pParam_spec2};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("delete_profile",
+                                                                                       delete_profile_task_process, NULL, NULL,
+                                                                                       2, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+
+       return pTask_spec;
+}
+
+
+task_spec_t *make_auto_configure_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profileDirName", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec2 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *param_spec_array[4] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("auto_configure",
+                                                                                       auto_configure_task_process, NULL, NULL,
+                                                                                       4, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+
+       return pTask_spec;
+}
+
+
+task_spec_t *make_sync_status_task()
+{
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("sync_status",
+                                                                                       sync_status_task_process, NULL, NULL,
+                                                                                       0, NULL);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_name_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec3 = param_spec_structure("profileName", __string_copy_struct, free,
+                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *param_spec_array[3] = {pParam_spec1, pParam_spec2, pParam_spec3};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_name",
+                                                                                       get_profile_name_task_process, NULL, NULL,
+                                                                                       3, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_server_info_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec3 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+
+       param_spec *param_spec_array[5] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_server_info",
+                                                                                       get_profile_server_info_task_process, NULL, NULL,
+                                                                                       5, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_sync_mode_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec3 = param_spec_structure("syncMode", __string_copy_struct, free,
+                                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("syncType", __string_copy_struct, free,
+                                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("interval", __string_copy_struct, free,
+                                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+
+       param_spec *param_spec_array[5] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_sync_mode",
+                                                                                       get_profile_sync_mode_task_process, NULL, NULL,
+                                                                                       5, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_sync_category_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("contentType", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *pParam_spec3 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec4 = param_spec_int("enabled", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec5 = param_spec_structure("srcURI", __string_copy_struct, free,
+                                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec6 = param_spec_structure("tgtURI", __string_copy_struct, free,
+                                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec7 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec8 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+
+       param_spec *param_spec_array[8] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4,
+                       pParam_spec5, pParam_spec6, pParam_spec7, pParam_spec8};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_sync_category",
+                                                                                       get_profile_sync_category_task_process, NULL, NULL,
+                                                                                       8, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+       param_spec_unref(pParam_spec8);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_last_session_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec3 = param_spec_int("lastSessionStatus", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec4 = param_spec_int("lastSessionTime", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *param_spec_array[4] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4 };
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_last_session",
+                                                                                       get_profile_last_session_task_process, NULL, NULL,
+                                                                                       4, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_statistics_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("contentType", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *pParam_spec3 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec4 = param_spec_structure("dbSynced", __string_copy_struct, free,
+                                                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_int("lastSessionTime", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec6 = param_spec_int("server2Client_Total", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec7 = param_spec_int("server2Client_NrOfAdd", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec8 = param_spec_int("server2Client_NrOfDelete", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec9 = param_spec_int("server2Client_NrOfReplace", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec10 = param_spec_int("client2Server_Total", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec11 = param_spec_int("client2Server_NrOfAdd", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec12 = param_spec_int("client2Server_NrOfDelete", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec13 = param_spec_int("client2Server_NrOfReplace", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[13] = {pParam_spec1, pParam_spec2, pParam_spec3,
+                       pParam_spec4, pParam_spec5, pParam_spec6, pParam_spec7, pParam_spec8,
+                       pParam_spec9, pParam_spec10, pParam_spec11, pParam_spec12, pParam_spec13};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_statistics",
+                                                                                       get_profile_statistics_task_process, NULL, NULL,
+                                                                                       13, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+       param_spec_unref(pParam_spec8);
+       param_spec_unref(pParam_spec9);
+       param_spec_unref(pParam_spec10);
+       param_spec_unref(pParam_spec11);
+       param_spec_unref(pParam_spec12);
+       param_spec_unref(pParam_spec13);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_reset_synchronizing_profiles_task()
+{
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("reset_synchronizing_profiles",
+                                                                                       reset_synchronizing_profiles_task_process, NULL, NULL,
+                                                                                       0, NULL);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_add_profile_cp_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profileName", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec2 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("categories", NULL, __free_resource_cp_list,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec6 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec7 = param_spec_int("accountId", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[7] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+                       pParam_spec6, pParam_spec7};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("add_profile_cp",
+                                                                                       add_profile_cp_task_process, NULL, NULL,
+                                                                                       7, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_refresh_from_service_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[1] = {pParam_spec1};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("refresh_from_service",
+                                                                                       refresh_from_service_task_process, NULL, NULL,
+                                                                                       1, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+
+       return pTask_spec;
+}
+
+
+/*FIXME cancel request to NA */
+/*task_spec_t *make_cancel_sync_request()
+{
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("cancel_sync_request",
+                                                                                       cancel_sync_request_task_process, NULL, NULL,
+                                                                                       0, NULL);
+
+       return pTask_spec;
+}*/
+
+/*TODO have to be removed after removing vconf*/
+task_error_t add_account_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       /* step 1 : process add account */
+       char *profile = NULL;
+       int accountId;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profile);
+
+       int result = update_all_config(profile, true, &accountId);
+       if (result == 0)
+               err = TASK_ERROR_RUN_FAILED;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       /*step 2 : start refresh_from_service for added account */
+       void *in_param_value_array[1] = {&accountId};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE, 0,
+                                                                                                                               1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               NULL, NULL, (int *)&request_msg_id);
+
+       FW_LOGV("end");
+       return err;
+}
+
+/*TODO have to be removed after removing vconf*/
+task_error_t edit_account_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profile = NULL;
+       int accountId;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profile);
+
+       int result = update_all_config(profile, false, &accountId);
+       if (result == 0)
+               err = TASK_ERROR_RUN_FAILED;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       FW_LOGV("end");
+       return err;
+}
+
+/*TODO have to be removed after removing vconf*/
+task_error_t autoconfigure_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profile = NULL;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profile);
+
+       bool result = autoconfigure_from_vconf(profile);
+       if (result == false)
+               err = TASK_ERROR_RUN_FAILED;
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t synchronize_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       char *syncMode = NULL;
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+
+       SanPackage *pSanPackage = NULL;
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &pSanPackage);
+
+       FW_LOGV("accountId = %d",  accountId);
+       FW_LOGV("syncMode = %s", syncMode);
+
+       bool result = synchronize(accountId, syncMode, pSanPackage);
+       if (result == false)
+               err = TASK_ERROR_RUN_FAILED;
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t add_profile_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profileDirName = NULL;
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       GList *categories = NULL;
+       int accountId;
+
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profileDirName);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+       param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+       param_value_get_value(&(param_array[6]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
+       param_value_get_value(&(param_array[7]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
+       param_value_get_value(&(param_array[8]->param_value), EC_VALUE_TYPE_STRUCT, &categories);
+
+       res =  add_profile(profileDirName, profileName, addr, id, password, syncMode, syncType, interval, categories, &accountId);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[10]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t edit_profile_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId;
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       GList *categories = NULL;
+
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+       param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+       param_value_get_value(&(param_array[6]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
+       param_value_get_value(&(param_array[7]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
+       param_value_get_value(&(param_array[8]->param_value), EC_VALUE_TYPE_STRUCT, &categories);
+
+       res =  edit_profile(accountId, profileName, addr, id, password, syncMode, syncType, interval, categories);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t delete_profile_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       bool res;
+       int result;
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       GList *profiles = NULL;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profiles);
+
+       res = delete_profile(profiles);
+       if (res == 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       FW_LOGV("end");
+       return err;
+
+}
+
+task_error_t auto_configure_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profildDirName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profildDirName);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       bool result = autoconfigure(profildDirName, addr, id, password);
+       if (result == false)
+               err = TASK_ERROR_RUN_FAILED;
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t sync_status_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profileDirName = NULL;
+
+       get_synchronising_profile(&profileDirName);
+
+       FW_LOGV("profileDirName = %s", profileDirName);
+       send_noti_sync_status(profileDirName);
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t get_profile_name_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       char *profileName = NULL;
+       int result;
+       bool res;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       res = get_profile_name(accountId, &profileName);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_server_info_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       res = get_profile_server_info(accountId, &addr, &id, &password);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_set_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_sync_mode_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       res =  get_profile_sync_mode(accountId, &syncMode, &syncType, &interval);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
+       param_value_set_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_sync_category_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       int contentType;
+
+       int enabled;
+       char *srcURI = NULL;
+       char *tgtURI = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &contentType);
+
+
+       res = get_profile_sync_category(accountId, contentType, &enabled, &srcURI, &tgtURI, &id, &password);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_INT, &enabled);
+       param_value_set_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &srcURI);
+       param_value_set_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &tgtURI);
+       param_value_set_value(&(param_array[6]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_set_value(&(param_array[7]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_last_session_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       int lastSessionStatus;
+       int lastSessionTime;
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       res = get_last_session_info(accountId, &lastSessionStatus, &lastSessionTime);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &lastSessionStatus);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_statistics_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       int contentType;
+
+       char *dbSynced = NULL;
+       int lastSessionTime;
+       int server2Client_Total;
+       int server2Client_NrOfAdd;
+       int server2Client_NrOfDelete;
+       int server2Client_NrOfReplace;
+       int client2Server_Total;
+       int client2Server_NrOfAdd;
+       int client2Server_NrOfDelete;
+       int client2Server_NrOfReplace;
+
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &contentType);
+
+
+       res =  get_profile_statistics(accountId, contentType, &dbSynced, &lastSessionTime,
+                       &server2Client_Total, &server2Client_NrOfAdd, &server2Client_NrOfDelete, &server2Client_NrOfReplace,
+                       &client2Server_Total, &client2Server_NrOfAdd, &client2Server_NrOfDelete, &client2Server_NrOfReplace);
+
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &dbSynced);
+       param_value_set_value(&(param_array[4]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
+       param_value_set_value(&(param_array[5]->param_value), EC_VALUE_TYPE_INT, &server2Client_Total);
+       param_value_set_value(&(param_array[6]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfAdd);
+       param_value_set_value(&(param_array[7]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfDelete);
+       param_value_set_value(&(param_array[8]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfReplace);
+       param_value_set_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &client2Server_Total);
+       param_value_set_value(&(param_array[10]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfAdd);
+       param_value_set_value(&(param_array[11]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfDelete);
+       param_value_set_value(&(param_array[12]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfReplace);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t reset_synchronizing_profiles_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       reset_synchronizing_profiles();
+
+       FW_LOGV("end");
+       return err;
+}
+
+/*FIXME cancel request to NA */
+/*task_error_t cancel_sync_request_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       cancel_sync_request();
+
+       FW_LOGV("end");
+       return err;
+}*/
+
+task_error_t add_profile_cp_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       GList *categories = NULL;
+       int accountId;
+
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &categories);
+
+       res =  add_profile_cp(profileName, addr, id, password, categories, &accountId);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[5]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[6]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       FW_LOGV("end");
+       return err;
+}
+
+
+task_error_t refresh_from_service_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId;
+       bool res;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       res =  refresh_from_service_all(accountId);
+       if (res == false)
+               err = TASK_ERROR_RUN_FAILED;
+
+       FW_LOGV("end");
+       return err;
+}
+
+void insert_request_msg_info(int sync_type, unsigned int request_id)
+{
+       sync_request_id_list = g_list_prepend(sync_request_id_list, __create_request_msg_info(sync_type, request_id));
+}
+
+void delete_request_msg_info(unsigned int request_id)
+{
+       GList *iter = NULL;
+       request_msg_info_t *pMsg_info = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->request_id == request_id) {
+                       sync_request_id_list = g_list_remove_link(sync_request_id_list, iter);
+                       break;
+               }
+       }
+
+       if (iter != NULL) {
+               __request_msg_info_free(iter->data);
+               g_list_free_1(iter);
+       }
+}
+
+bool get_synchronizing_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_MANUAL || pMsg_info->sync_type == SYNC_MODE_PERIODIC  || pMsg_info->sync_type == SYNC_MODE_SAN) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+                       break;
+               }
+       }
+
+       return success;
+}
+
+bool get_manual_sync_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_MANUAL) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+                       break;
+               }
+       }
+
+       return success;
+}
+
+bool get_periodic_sync_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_PERIODIC) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+                       break;
+               }
+       }
+
+       return success;
+}
+
+bool get_san_sync_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_SAN) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+                       break;
+               }
+       }
+
+       return success;
+}
+
+bool get_auto_configure_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_AUTOCONFIG) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+                       break;
+               }
+       }
+
+       return success;
+}
+
diff --git a/ServiceAdapter/NetworkBinder/NA_Binder.c b/ServiceAdapter/NetworkBinder/NA_Binder.c
new file mode 100644 (file)
index 0000000..cbd6cae
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @NA_Binder.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of header binder function for Network Adapter
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceAdapter/NetworkBinder/NA_Binder.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+int NA_http_header_binder(char *accType, char *loc_uri, bool isXML, GList **list)
+{
+       FW_LOGV("[NA Header Binder] start!!");
+
+       if (!strcmp(accType, "OMA_DS")) {
+               common_header_info *method = (common_header_info *)malloc(sizeof(common_header_info));
+               if (method == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'method' malloc fail !!");
+                       return 0;
+               }
+               memset(method, 0x00, sizeof(common_header_info));
+               method->key = "method";
+               method->value = "post";
+               *list = g_list_append(*list, method);
+
+               common_header_info *uri = (common_header_info *)malloc(sizeof(common_header_info));
+               if (uri == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'uri' malloc fail !!");
+                       return 0;
+               }
+               memset(uri, 0x00, sizeof(common_header_info));
+               uri->key = "uri";
+               uri->value = loc_uri;
+               *list = g_list_append(*list, uri);
+
+               common_header_info *cache_control = (common_header_info *)malloc(sizeof(common_header_info));
+               if (cache_control == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'cache_control' malloc fail !!");
+                       return 0;
+               }
+               memset(cache_control, 0x00, sizeof(common_header_info));
+               cache_control->key = "Cache-Control";
+               cache_control->value = "no-store, private";
+               *list = g_list_append(*list, cache_control);
+
+               common_header_info *connection = (common_header_info *)malloc(sizeof(common_header_info));
+               if (connection == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'connection' malloc fail !!");
+                       return 0;
+               }
+               memset(connection, 0x00, sizeof(common_header_info));
+               connection->key = "Connection";
+               connection->value = "Keep-Alive";
+               *list = g_list_append(*list, connection);
+
+               common_header_info *accept = (common_header_info *)malloc(sizeof(common_header_info));
+               if (accept == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'accept' malloc fail !!");
+                       return 0;
+               }
+               memset(accept, 0x00, sizeof(common_header_info));
+               accept->key = "Accept";
+               if (isXML == true)
+                       accept->value = "application/vnd.syncml+xml";
+               else
+                       accept->value = "application/vnd.syncml+wbxml";
+               *list = g_list_append(*list, accept);
+
+               common_header_info *accept_language = (common_header_info *)malloc(sizeof(common_header_info));
+               if (accept_language == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'accept_language' malloc fail !!");
+                       return 0;
+               }
+               memset(accept_language, 0x00, sizeof(common_header_info));
+               accept_language->key = "Accept-Language";
+               accept_language->value = "en-US";
+               *list = g_list_append(*list, accept_language);
+
+               common_header_info *accept_charset = (common_header_info *)malloc(sizeof(common_header_info));
+               if (accept_charset == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'accept_charset' malloc fail !!");
+                       return 0;
+               }
+               memset(accept_charset, 0x00, sizeof(common_header_info));
+               accept_charset->key = "Accept-Charset";
+               accept_charset->value = "UTF-8";
+               *list = g_list_append(*list, accept_charset);
+
+               common_header_info *content_type = (common_header_info *)malloc(sizeof(common_header_info));
+               if (content_type == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'content_type' malloc fail !!");
+                       return 0;
+               }
+               memset(content_type, 0x00, sizeof(common_header_info));
+               content_type->key = "Content-Type";
+               if (isXML == true)
+                       content_type->value = "application/vnd.syncml+xml";
+               else
+                       content_type->value = "application/vnd.syncml+wbxml";
+               *list = g_list_append(*list, content_type);
+
+       }
+
+       GList *iter = NULL;
+       for (iter = *list; iter != NULL; iter = g_list_next(iter)) {
+               FW_LOGV("[NA_Header_Binder] key : %s, value : %s", ((common_header_info *)(iter->data))->key, ((common_header_info *)(iter->data))->value);
+       }
+
+       FW_LOGV("end");
+
+       return 1;
+}
+
+void free_header_info(common_header_info *pCommon_header_info)
+{
+       if (pCommon_header_info == NULL)
+               return;
+
+       free(pCommon_header_info);
+}
diff --git a/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.c b/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.c
new file mode 100644 (file)
index 0000000..d75ae99
--- /dev/null
@@ -0,0 +1,4856 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @oma_ds_protocol_binder.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of callback function for Protocol Binder
+ */
+
+#include <glib.h>
+#include <assert.h>    /* TODO : replace this line to fw_assert.h */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/NetworkAssistant/protocol_binder/protocol_binder_util.h"
+#include "ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Command_Internal.h"
+#include "ServiceAdapter/SA_DevInf_Internal.h"
+#include "ServiceAdapter/SA_Command.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_DevInf.h"
+#include "ServiceAdapter/SA_Define.h"
+
+#define LOG_TAG        "OMA_DS_BINDER"
+
+static PROTOCOL_BINDER_ERROR __append_location_to_wbxml_node(Location *pLocation,
+               protocol_binder *pBinder,       WBXMLTreeNode *parent_node);
+
+static PROTOCOL_BINDER_ERROR __append_anchor_to_wbxml_node(Anchor *pAnchor,
+               protocol_binder *pBinder, WBXMLTreeNode *parent_node);
+
+static PROTOCOL_BINDER_ERROR __append_devinf_contenttype_to_wbxml_node(DevInfContentType *pDevInfContentType,
+               protocol_binder *pBinder, WBXMLTreeNode *parent_node, char *node);
+
+static PROTOCOL_BINDER_ERROR __append_cred_to_wbxml_node(Cred *pCred,  protocol_binder *pBinder, WBXMLTreeNode *parent_node) ;
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_devinf_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_syncml_start_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_header_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_final_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_body_start_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_status_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_alert_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_results_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_put_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_get_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_start_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_end_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_add_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_replace_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_delete_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_map_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+
+static ProtocolVersion __get_oma_ds_protocol_version(char *verdtd);
+static DevInfVersion __get_oma_ds_devInf_version(char *verdtd);
+static DevInfDevTyp __get_oma_ds_devInf_device_type(char *devType);
+static DevInfContentType *__get_devinf_contenttype(WBXMLTreeNode *node);
+static Location *_get_location(WBXMLTreeNode *node);
+static Anchor *_get_anchor(WBXMLTreeNode *node);
+static Cred *__get_cred(WBXMLTreeNode *node);
+static Chal *_get_chal(WBXMLTreeNode *node);
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_devinf_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_header_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_results_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_put_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_get_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_alert_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_end_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_start_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_add_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_replace_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_delete_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_final_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_status_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+
+
+/*
+       PE_ADD,
+    PE_DELETE,
+    PE_REPLACE,
+    PE_ALERT,
+    PE_GET,
+    PE_MAP,
+    PE_PUT,
+    PE_RESULTS,
+    PE_STATUS,
+    PE_SYNC_START,
+    PE_SYNC_END,
+    PE_HEADER,
+    PE_FINAL
+
+    PE_COPY,
+    PE_EXEC,
+    PE_SEARCH,
+    PE_SEQUENCE_START,
+    PE_SEQUENCE_END,
+    PE_ATOMIC_START,
+    PE_ATOMIC_END,
+    PE_PUT_GET,
+    PE_CMD_GROUP,
+    PE_GENERIC,
+ */
+const Binder_function_info oma_ds_binder_function_info[] = {
+               { PE_SYNCML_START,              "SyncML",                       __oma_ds_binder_syncml_start_converter_function,                                NULL,                                                                                                                                                                                   false},
+               { PE_SYNCML_END,                "/SyncML",              NULL,                                                                                                                                                           NULL,                                                                                                                                                                                   false},
+               { PE_HEADER,                            "SyncHdr",                      __oma_ds_binder_header_converter_function,                                              __oma_ds_binder_header_reverse_converter_function,                                              true},
+               { PE_BODY_START,                        "SyncBody",             __oma_ds_binder_body_start_converter_function,                                  NULL,                                                                                                                                                                                   false},
+               { PE_BODY_END,                  "/SyncBody",            NULL,                                                                                                                                                           NULL,                                                                                                                                                                                   false},
+               { PE_FINAL,                                     "Final",                                __oma_ds_binder_final_converter_function,                                                       __oma_ds_binder_final_reverse_converter_function,                                                       true},
+               { PE_ALERT,                                     "Alert",                                __oma_ds_binder_alert_command_converter_function,                       __oma_ds_binder_alert_command_reverse_converter_function,                       true},
+               { PE_STATUS,                                    "Status",                       __oma_ds_binder_status_converter_function,                                              __oma_ds_binder_status_reverse_converter_function,                                              true},
+               { PE_RESULTS_START,     "Results",                      __oma_ds_binder_results_command_converter_function,             __oma_ds_binder_results_command_reverse_converter_function,             false},
+               { PE_RESULTS_END,               "/Results",             NULL,                                                                                                                                                           NULL,                                                                                                                                                                                   false},
+               { PE_PUT_START,                 "Put",                          __oma_ds_binder_put_command_converter_function,                 __oma_ds_binder_put_command_reverse_converter_function,                 false},
+               { PE_PUT_END,                           "/Put",                         NULL,                                                                                                                                                           NULL,                                                                                                                                                                                   false},
+               { PE_GET,                                               "Get",                          __oma_ds_binder_get_command_converter_function,                 __oma_ds_binder_get_command_reverse_converter_function,                 true},
+               { PE_SYNC_START,                        "Sync",                         __oma_ds_binder_sync_start_command_converter_function,  __oma_ds_binder_sync_start_command_reverse_converter_function,  false},
+               { PE_SYNC_END,                  "/Sync",                        __oma_ds_binder_sync_end_command_converter_function,    __oma_ds_binder_sync_end_command_reverse_converter_function,    false},
+               { PE_ADD,                                               "Add",                          __oma_ds_binder_add_command_converter_function,                 __oma_ds_binder_add_command_reverse_converter_function,                 true},
+               { PE_REPLACE,                           "Replace",                      __oma_ds_binder_replace_command_converter_function,             __oma_ds_binder_replace_command_reverse_converter_function,             true},
+               { PE_DELETE,                                    "Delete",                       __oma_ds_binder_delete_command_converter_function,              __oma_ds_binder_delete_command_reverse_converter_function,              true},
+               { PE_MAP,                                               "Map",                          __oma_ds_binder_map_command_converter_function,                 NULL,                                                                                                                                                                                   true},
+               { PE_DEVINF,                                    "DevInf",                       __oma_ds_binder_devinf_converter_function,                                              __oma_ds_binder_devinf_reverse_converter_function,                                              true}
+};
+
+
+
+static PROTOCOL_BINDER_ERROR __append_location_to_wbxml_node(Location *pLocation,
+                                                                                                                       protocol_binder *pBinder,
+                                                                                                                       WBXMLTreeNode *parent_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       if (pLocation->locURI != NULL) {
+               WBXMLTreeNode *LocURI = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               parent_node, ELEMENT_LOCURI, pLocation->locURI, strlen(pLocation->locURI));
+               if (LocURI == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       } else {
+               /* error case */
+       }
+
+       if (pLocation->locName != NULL) {
+               WBXMLTreeNode *locName = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                       parent_node, ELEMENT_LOCNAME, pLocation->locName, strlen(pLocation->locName));
+               if (locName == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __append_anchor_to_wbxml_node(Anchor *pAnchor,
+                                                                                                                       protocol_binder *pBinder,
+                                                                                                                       WBXMLTreeNode *parent_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder, parent_node, ELEMENT_META);
+       if (meta_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *anchor_node = add_child_wbxml_node_using_xml_name(pBinder, meta_node, ELEMENT_ANCHOR);
+       if (anchor_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pAnchor->lastAnchor) {
+               WBXMLTreeNode *last_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               anchor_node, ELEMENT_LAST, pAnchor->lastAnchor, strlen(pAnchor->lastAnchor));
+               if (last_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pAnchor->nextAnchor) {
+               WBXMLTreeNode *next_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               anchor_node, ELEMENT_NEXT, pAnchor->nextAnchor, strlen(pAnchor->nextAnchor));
+               if (next_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __append_devinf_contenttype_to_wbxml_node(DevInfContentType *pDevInfContentType,
+                                                                                                                       protocol_binder *pBinder,
+                                                                                                                       WBXMLTreeNode *parent_node,
+                                                                                                                       char *node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       WBXMLTreeNode *xnode = add_child_wbxml_node_using_xml_name(pBinder, parent_node, node);
+       if (xnode == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cttype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       xnode, "CTType", pDevInfContentType->cttype, strlen(pDevInfContentType->cttype));
+       if (cttype_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *verct_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       xnode, "VerCT", pDevInfContentType->verct, strlen(pDevInfContentType->verct));
+       if (verct_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __append_cred_to_wbxml_node(Cred *pCred,
+                                                                                                                       protocol_binder *pBinder,
+                                                                                                                       WBXMLTreeNode *parent_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /* check validity */
+       WBXMLTreeNode *cred_node = add_child_wbxml_node_using_xml_name(pBinder, parent_node, ELEMENT_CRED);
+       if (cred_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder, cred_node, ELEMENT_META);
+       if (meta_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+
+       WBXMLTreeNode *type_node = NULL;
+
+       switch (pCred->type) {
+       case AUTH_TYPE_BASIC:
+
+               if (pCred->format == FORMAT_TYPE_BASE64) {
+                       WBXMLTreeNode *format_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_FORMAT,  ELEMENT_FORMAT_BASE64, strlen(ELEMENT_FORMAT_BASE64));
+                       if (format_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, ELEMENT_AUTH_BASIC, strlen(ELEMENT_AUTH_BASIC));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (pCred->data) {
+                       WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       cred_node, ELEMENT_DATA,  pCred->data, strlen(pCred->data));
+                       if (data_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+               break;
+       case AUTH_TYPE_MD5:
+
+               if (pCred->format == FORMAT_TYPE_BASE64) {
+                       WBXMLTreeNode *format_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_FORMAT, ELEMENT_FORMAT_BASE64, strlen(ELEMENT_FORMAT_BASE64));
+                       if (format_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, ELEMENT_AUTH_MD5, strlen(ELEMENT_AUTH_MD5));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (pCred->data) {
+                       WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       cred_node, ELEMENT_DATA,  pCred->data, strlen(pCred->data));
+                       if (data_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+               break;
+       default:
+               break;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_devinf_converter_function(protocol_binder *pBinder,
+                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Item *pItem = (Item *)pContent;
+       DevInf *pDevInf = pItem->private.devInf;
+
+       if (pItem) {
+               WBXMLTreeNode *item_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder, item_node, ELEMENT_SOURCE);
+               if (source_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pItem->source, pBinder, source_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+               WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name(pBinder, item_node, ELEMENT_DATA);
+               if (data_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               /* devinf language setting */
+               switch_protocol(pBinder, PROTOCOL_SYNCML_DEVINF12);
+               WBXMLTree *devinf_tree = create_wbxml_tree(pBinder);
+               if (devinf_tree == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               add_wbxml_tree_to_wbxml_node(data_node, devinf_tree);
+
+               /* create root node of devinf tree*/
+               WBXMLTreeNode *devinf_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_DEVINF);
+               if (devinf_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               set_wbxml_tree_root(devinf_tree, devinf_node);
+
+               WBXMLTreeNode *verDTD_node = NULL;
+               switch (pDevInf->version) {
+               case DEVINF_VERSION_UNKNOWN:
+                       verDTD_node = add_child_wbxml_node_using_xml_name(pBinder, devinf_node, ELEMENT_VERDTD);
+                       break;
+               case DEVINF_VERSION_10:
+                       verDTD_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_10, strlen(ELEMENT_VERDRD_10));
+                       break;
+               case DEVINF_VERSION_11:
+                       verDTD_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_11, strlen(ELEMENT_VERDRD_11));
+                       break;
+               case DEVINF_VERSION_12:
+                       verDTD_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_12, strlen(ELEMENT_VERDRD_12));
+                       break;
+               }
+
+               if (verDTD_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *man_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_MAN, pDevInf->manufacturer, strlen(pDevInf->manufacturer));
+               if (man_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *mod_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_MOD, pDevInf->model, strlen(pDevInf->model));
+               if (mod_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+
+               if (pDevInf->oem) {
+                       WBXMLTreeNode *oem_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_OEM, pDevInf->oem, strlen(pDevInf->oem));
+                       if (oem_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               WBXMLTreeNode *FwV_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_FWV, pDevInf->firmwareVersion, strlen(pDevInf->firmwareVersion));
+               if (FwV_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *SwV_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_SWV, pDevInf->softwareVersion, strlen(pDevInf->softwareVersion));
+               if (SwV_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *HwV_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_HWV, pDevInf->hardwareVersion, strlen(pDevInf->hardwareVersion));
+               if (HwV_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *devID_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_DEVID, pDevInf->devid, strlen(pDevInf->devid));
+               if (devID_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *devTyp_node = NULL;
+               switch (pDevInf->devtyp) {
+               case DEVINF_DEVTYPE_UNKNOWN:
+                       devTyp_node = add_child_wbxml_node_using_xml_name(pBinder, devinf_node, ELEMENT_DEVTYP);
+                       break;
+               case DEVINF_DEVTYPE_PAGER:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_PAGER, strlen(ELEMENT_PAGER));
+                       break;
+               case DEVINF_DEVTYPE_HANDHELD:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_HANDHELD, strlen(ELEMENT_HANDHELD));
+                       break;
+               case DEVINF_DEVTYPE_PDA:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_PDA, strlen(ELEMENT_PDA));
+                       break;
+               case DEVINF_DEVTYPE_PHONE:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_PHONE, strlen(ELEMENT_PHONE));
+                       break;
+               case DEVINF_DEVTYPE_SMARTPHONE:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_SMARTPHONE, strlen(ELEMENT_SMARTPHONE));
+                       break;
+               case DEVINF_DEVTYPE_SERVER:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_SERVER, strlen(ELEMENT_SERVER));
+                       break;
+               case DEVINF_DEVTYPE_WORKSTATION:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_WORKSTATION, strlen(ELEMENT_WORKSTATION));
+                       break;
+               }
+
+               if (devTyp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (pDevInf->supportsUTC) {
+                       WBXMLTreeNode *supportUTC_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       devinf_node, ELEMENT_UTC);
+                       if (supportUTC_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               if (pDevInf->supportsLargeObjs) {
+                       WBXMLTreeNode *supportLargeObjs_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       devinf_node, ELEMENT_SUPPORTLARGEOBJS);
+                       if (supportLargeObjs_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               if (pDevInf->supportsNumberOfChanges) {
+                       WBXMLTreeNode *supportNumberOfChanges_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       devinf_node, ELEMENT_SUPPORTNUMBEROFCHANGES);
+                       if (supportNumberOfChanges_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               GList *datastoreIter = NULL;
+               DevInfDataStore *devInfDataStore = NULL;
+               for (datastoreIter = pDevInf->datastores; datastoreIter != NULL; datastoreIter = g_list_next(datastoreIter)) {
+                       devInfDataStore = datastoreIter->data;
+
+                       WBXMLTreeNode *datastore_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       devinf_node, ELEMENT_DATASTORE);
+                       if (datastore_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *sourceRef_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       datastore_node, ELEMENT_SOURCEREF, devInfDataStore->sourceref, strlen(devInfDataStore->sourceref));
+                       if (sourceRef_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (devInfDataStore->displayname) {
+                               WBXMLTreeNode *displayname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               datastore_node, ELEMENT_DISPLAYNAME, devInfDataStore->displayname, strlen(devInfDataStore->displayname));
+                               if (displayname_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+
+                       if (devInfDataStore->maxGUIDSize) {
+                               char *str_maxguidsize = g_strdup_printf("%u", devInfDataStore->maxGUIDSize);
+                               if (str_maxguidsize == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               WBXMLTreeNode *maxguidsize_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               datastore_node, ELEMENT_MAXGUIDSIZE, str_maxguidsize, strlen(str_maxguidsize));
+
+                               if (str_maxguidsize != NULL)
+                                       free(str_maxguidsize);
+
+                               if (maxguidsize_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+
+                       __append_devinf_contenttype_to_wbxml_node(devInfDataStore->rxPref, pBinder,
+                                       datastore_node, ELEMENT_RX_PREF);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+
+                       GList *rxIter = NULL;
+                       DevInfContentType *devInfContentType = NULL;
+                       for (rxIter = devInfDataStore->rx; rxIter != NULL; rxIter = g_list_next(rxIter)) {
+                               devInfContentType = rxIter->data;
+                               __append_devinf_contenttype_to_wbxml_node(devInfContentType, pBinder,
+                                               datastore_node, ELEMENT_RX);
+                               if (err != PROTOCOL_BINDER_OK)
+                                       goto error;
+                       }
+
+                       __append_devinf_contenttype_to_wbxml_node(devInfDataStore->txPref, pBinder,
+                                       datastore_node, ELEMENT_TX_PREF);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+
+                       GList *txIter = NULL;
+                       for (txIter = devInfDataStore->tx; txIter != NULL; txIter = g_list_next(txIter)) {
+                               devInfContentType = txIter->data;
+                               __append_devinf_contenttype_to_wbxml_node(devInfContentType, pBinder,
+                                               datastore_node, ELEMENT_TX);
+                               if (err != PROTOCOL_BINDER_OK)
+                                       goto error;
+
+                       }
+
+                       GList *ctcapIter = NULL;
+                       DevInfCTCap *devInfCTCap = NULL;
+                       for (ctcapIter = devInfDataStore->ctcaps; ctcapIter != NULL;  ctcapIter = g_list_next(ctcapIter)) {
+                               devInfCTCap = ctcapIter->data;
+
+                               WBXMLTreeNode *ctcap_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                               datastore_node, ELEMENT_CTCAP);
+                               if (ctcap_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               WBXMLTreeNode *cttype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               ctcap_node, ELEMENT_CTTYPE, devInfCTCap->ct->cttype, strlen(devInfCTCap->ct->cttype));
+                               if (cttype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               WBXMLTreeNode *verct_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               ctcap_node, ELEMENT_VERCT, devInfCTCap->ct->verct, strlen(devInfCTCap->ct->verct));
+                               if (verct_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               /*TODO FieldLevel*/
+
+                               GList *propertyIter = NULL;
+                               DevInfProperty *devInfProperty = NULL;
+                               for (propertyIter = devInfCTCap->properties; propertyIter != NULL; propertyIter = g_list_next(propertyIter)) {
+                                       devInfProperty = propertyIter->data;
+
+                                       WBXMLTreeNode *property_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                                       ctcap_node, ELEMENT_PROPERTY);
+                                       if (property_node == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+
+                                       WBXMLTreeNode *propname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                       property_node, ELEMENT_PROPNAME, devInfProperty->propName, strlen(devInfProperty->propName));
+                                       if (propname_node == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+
+                                       if (devInfProperty->dataType) {
+                                               WBXMLTreeNode *datatype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_DATATYPE, devInfProperty->dataType, strlen(devInfProperty->dataType));
+                                               if (datatype_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       if (devInfProperty->maxOccur) {
+                                               char *str_maxoccur = g_strdup_printf("%u", devInfProperty->maxOccur);
+                                               if (str_maxoccur == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               WBXMLTreeNode *maxoccur_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_MAXOCCUR, str_maxoccur, strlen(str_maxoccur));
+
+                                               if (str_maxoccur != NULL)
+                                                       free(str_maxoccur);
+
+                                               if (maxoccur_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       if (devInfProperty->maxSize) {
+                                               char *str_maxsize = g_strdup_printf("%u", devInfProperty->maxSize);
+                                               if (str_maxsize == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               WBXMLTreeNode *maxsize_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_MAXSIZE, str_maxsize, strlen(str_maxsize));
+
+                                               if (str_maxsize != NULL)
+                                                       free(str_maxsize);
+
+                                               if (maxsize_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       if (devInfProperty->noTruncate) {
+                                               WBXMLTreeNode *notruncate_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                                               property_node, ELEMENT_NOTRUNCATE);
+                                               if (notruncate_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       GList *valenum = NULL;
+                                       char *val = NULL;
+                                       for (valenum = devInfProperty->valEnums; valenum != NULL; valenum = g_list_next(valenum)) {
+                                               val = valenum->data;
+                                               WBXMLTreeNode *valenum_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_VALENUM, val, strlen(val));
+                                               if (valenum_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       if (devInfProperty->displayName) {
+                                               WBXMLTreeNode *displayname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_DISPLAYNAME, devInfProperty->displayName, strlen(devInfProperty->displayName));
+                                               if (displayname_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       GList *propparamIter = NULL;
+                                       DevInfPropParam *devInfPropParam = NULL;
+                                       for (propparamIter = devInfProperty->propParams; propparamIter != NULL; propparamIter = g_list_next(propparamIter)) {
+                                               devInfPropParam = propparamIter->data;
+
+                                               WBXMLTreeNode *propparam_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                                               property_node, ELEMENT_PROPPARAM);
+                                               if (propparam_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               WBXMLTreeNode *paramname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               propparam_node, ELEMENT_PARAMNAME, devInfPropParam->paramName, strlen(devInfPropParam->paramName));
+                                               if (paramname_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               if (devInfPropParam->dataType) {
+                                                       WBXMLTreeNode *datatype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                                       propparam_node, ELEMENT_DATATYPE, devInfPropParam->dataType, strlen(devInfPropParam->dataType));
+                                                       if (datatype_node == NULL) {
+                                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                               goto error;
+                                                       }
+                                               }
+
+                                               valenum = NULL;
+                                               val = NULL;
+                                               for (valenum = devInfPropParam->valEnums; valenum != NULL; valenum = g_list_next(valenum)) {
+                                                       val = valenum->data;
+                                                       WBXMLTreeNode *valenum_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                                       propparam_node, ELEMENT_VALENUM, val, strlen(val));
+                                                       if (valenum_node == NULL) {
+                                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                               goto error;
+                                                       }
+                                               }
+
+                                               if (devInfPropParam->displayName) {
+                                                       WBXMLTreeNode *displayname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                                       propparam_node, ELEMENT_DISPLAYNAME, devInfPropParam->displayName, strlen(devInfPropParam->displayName));
+                                                       if (displayname_node == NULL) {
+                                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                               goto error;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+                       /*TODO DSMem*/
+
+                       if (devInfDataStore->supportsHierarchicalSync) {
+                               WBXMLTreeNode *supportshierarchicalsync_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                               datastore_node, ELEMENT_SUPPORTHIERARCHICALSYNC);
+                               if (supportshierarchicalsync_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+
+                       WBXMLTreeNode *synccap_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       datastore_node, ELEMENT_SYNCCAP);
+                       if (synccap_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_TWO_WAY)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_1, strlen(ELEMENT_SYNCTYPE_1));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_SLOW_SYNC)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_2, strlen(ELEMENT_SYNCTYPE_2));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_3, strlen(ELEMENT_SYNCTYPE_3));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_4, strlen(ELEMENT_SYNCTYPE_4));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_5, strlen(ELEMENT_SYNCTYPE_5));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_SERVER)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_6, strlen(ELEMENT_SYNCTYPE_6));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_7, strlen(ELEMENT_SYNCTYPE_7));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       /*TODO filter-rx, filterCap*/
+               }
+               undo_switch_protocol(pBinder);
+               *ppWbxml_dom_node =  item_node;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_syncml_start_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       WBXMLTreeNode *syncml_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_SYNCML);
+       if (syncml_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       *ppWbxml_dom_node = syncml_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_header_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       SyncHdr *pSyncHdr = (SyncHdr *)pContent;
+
+       /* add SyncHdr, VerDTD, VerProto node */
+       WBXMLTreeNode *synchdr_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_SYNCHDR);
+       if (synchdr_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+
+       char *verDTD = ELEMENT_VERDTD;
+       char *verProto = ELEMENT_VERPROTO;
+
+       char *verDTD_data = NULL;
+       char *verProto_data = NULL;
+       if (pSyncHdr->version == VERSION_10) {
+               verDTD_data = ELEMENT_VERDRD_10;
+               verProto_data = ELEMENT_VERPROTO_10;
+       } else if (pSyncHdr->version == VERSION_11) {
+               verDTD_data = ELEMENT_VERDRD_11;
+               verProto_data = ELEMENT_VERPROTO_11;
+       } else if (pSyncHdr->version == VERSION_12) {
+               verDTD_data = ELEMENT_VERDRD_12;
+               verProto_data = ELEMENT_VERPROTO_12;
+       }
+
+       if (verDTD_data == NULL || verProto_data  == NULL) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *verdtd_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       synchdr_node, verDTD, verDTD_data, strlen(verDTD_data));
+       if (verdtd_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *verProto_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       synchdr_node, verProto, verProto_data, strlen(verProto_data));
+       if (verProto_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       /* session ID */
+       WBXMLTreeNode *sessionID_node = NULL;
+       if (pSyncHdr->sessionID != NULL)
+               sessionID_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               synchdr_node, ELEMENT_SESSIONID, pSyncHdr->sessionID, strlen(pSyncHdr->sessionID));
+       else
+               sessionID_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               synchdr_node, ELEMENT_SESSIONID);
+
+       if (sessionID_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       /* msgID */
+       char *msgID_data = g_strdup_printf("%u", pSyncHdr->messageID);
+       if (msgID_data == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *msgID_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       synchdr_node, ELEMENT_MSGID, msgID_data, strlen(msgID_data));
+
+       if (msgID_data != NULL)
+               free(msgID_data);
+
+       if (msgID_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                       synchdr_node, ELEMENT_TARGET);
+       if (target_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       err = __append_location_to_wbxml_node(pSyncHdr->target, pBinder, target_node);
+       if (err != PROTOCOL_BINDER_OK)
+               goto error;
+
+
+       WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                       synchdr_node, ELEMENT_SOURCE);
+       if (source_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       err = __append_location_to_wbxml_node(pSyncHdr->source, pBinder, source_node);
+       if (err != PROTOCOL_BINDER_OK)
+               goto error;
+
+
+       if (pSyncHdr->responseURI) {
+               WBXMLTreeNode *respuri_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               synchdr_node, ELEMENT_RESPURI, pSyncHdr->responseURI, strlen(pSyncHdr->responseURI));
+               if (respuri_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+
+       if (pSyncHdr->noResponse) {
+               WBXMLTreeNode *noResponse_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               synchdr_node, ELEMENT_NORESP);
+               if (noResponse_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+
+       if (pSyncHdr->cred) {
+               err = __append_cred_to_wbxml_node(pSyncHdr->cred, pBinder, synchdr_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+
+       char *meta = ELEMENT_META;
+       if (pSyncHdr->maxmsgsize != 0 || pSyncHdr->maxobjsize != 0) {
+               WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               synchdr_node, meta);
+               if (meta_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               unsigned int maxmsgsize = pSyncHdr->maxmsgsize;
+               unsigned int maxobjsize = pSyncHdr->maxobjsize;
+
+
+               if (maxmsgsize != 0) {
+                       char *str_maxmsgsize = g_strdup_printf("%u", maxmsgsize);
+                       if (str_maxmsgsize == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *maxmsgsize_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_MAXMSGSIZE, str_maxmsgsize, strlen(str_maxmsgsize));
+                       if (str_maxmsgsize != NULL)
+                               free(str_maxmsgsize);
+
+                       if (maxmsgsize_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               if (maxobjsize != 0) {
+                       char *str_maxobjsize = g_strdup_printf("%u", maxobjsize);
+                       if (str_maxobjsize == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *maxobjsize_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_MAXOBJSIZE, str_maxobjsize, strlen(str_maxobjsize));
+                       if (str_maxobjsize != NULL)
+                               free(str_maxobjsize);
+
+                       if (maxobjsize_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+       }
+
+       *ppWbxml_dom_node = synchdr_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_final_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                                                                               Content_Ptr pContent,
+                                                                                                                                                                                                                               WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       WBXMLTreeNode *final_node = create_wbxml_node_using_xml_name(pBinder, "Final");
+       if (final_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       *ppWbxml_dom_node = final_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error :%d", err);
+       return err;
+
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_body_start_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       WBXMLTreeNode *syncbody_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_SYNCBODY);
+       if (syncbody_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       *ppWbxml_dom_node = syncbody_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_status_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Status *pStatus = (Status *)pContent;
+       assert(pStatus != NULL);
+
+       CommandType type = pStatus->type;
+
+       char *str_cmdID = NULL;
+       char *str_msgRef = NULL;
+       char *str_cmdRef = NULL;
+
+       WBXMLTreeNode *status_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_STATUS);
+       if (status_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       unsigned int cmdID = pStatus->cmdID;
+       str_cmdID = g_strdup_printf("%u", cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       unsigned int msgRef = pStatus->msgRef;
+       str_msgRef = g_strdup_printf("%u", msgRef);
+       if (str_msgRef == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *msgref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_MSGREF, str_msgRef, strlen(str_msgRef));
+       if (msgref_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       unsigned int cmdRef = pStatus->cmdRef;
+       str_cmdRef = g_strdup_printf("%u", cmdRef);
+       if (str_cmdRef == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_CMDREF, str_cmdRef, strlen(str_cmdRef));
+       if (cmdref_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       char *str_command = NULL;
+       switch (type) {
+       case COMMAND_TYPE_ALERT:
+               {
+                       str_command = ELEMENT_ALERT;
+               }
+               break;
+       case COMMAND_TYPE_SYNC_START:
+               {
+                       str_command = ELEMENT_SYNC;
+               }
+               break;
+       case COMMAND_TYPE_PUT:
+               {
+                       str_command = ELEMENT_PUT;
+               }
+               break;
+       case COMMAND_TYPE_HEADER:
+               {
+                       str_command = ELEMENT_SYNCHDR;
+               }
+               break;
+       case COMMAND_TYPE_ADD:
+               {
+                       str_command = ELEMENT_ADD;
+               }
+               break;
+       case COMMAND_TYPE_REPLACE:
+               {
+                       str_command = ELEMENT_REPLACE;
+               }
+               break;
+       case COMMAND_TYPE_DELETE:
+               {
+                       str_command = ELEMENT_DELETE;
+               }
+               break;
+       case COMMAND_TYPE_MAP:
+               {
+                       str_command = ELEMENT_MAP;
+               }
+               break;
+       case COMMAND_TYPE_GET:
+               {
+                       str_command = ELEMENT_GET;
+               }
+               break;
+       case COMMAND_TYPE_RESULTS:
+               {
+                       str_command = ELEMENT_RESULTS;
+               }
+               break;
+       default:
+               break;
+       }
+
+       if (str_command == NULL) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *command_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_CMD, str_command, strlen(str_command));
+       if (command_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pStatus->targetRef) {
+               WBXMLTreeNode *targetref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               status_node, ELEMENT_TARGETREF, pStatus->targetRef->locURI, strlen(pStatus->targetRef->locURI));
+               if (targetref_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pStatus->sourceRef) {
+               WBXMLTreeNode *sourceref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               status_node, ELEMENT_SOURCEREF, pStatus->sourceRef->locURI, strlen(pStatus->sourceRef->locURI));
+               if (sourceref_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pStatus->cred) {
+               err = __append_cred_to_wbxml_node(pStatus->cred, pBinder, status_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       if (pStatus->chal) {
+                       /*TODO chal*/
+       }
+
+       WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_DATA, pStatus->data, strlen(pStatus->data));
+       if (data_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (type == COMMAND_TYPE_ALERT) {
+               if (pStatus->item) {
+                       WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       status_node, ELEMENT_ITEM);
+                       if (item_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *item_data_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_DATA);
+                       if (item_data_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *item_data_Anchor_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_data_node, ELEMENT_ANCHOR);
+                       if (item_data_Anchor_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (pStatus->item->anchor) {
+                               WBXMLTreeNode *item_data_Anchor_Next_node =
+                                               add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               item_data_Anchor_node, ELEMENT_NEXT, pStatus->item->anchor->nextAnchor,
+                                                               strlen(pStatus->item->anchor->nextAnchor));
+
+                               if (item_data_Anchor_Next_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_cmdRef != NULL)
+               free(str_cmdRef);
+
+       if (str_msgRef != NULL)
+               free(str_msgRef);
+
+       *ppWbxml_dom_node = status_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_cmdRef != NULL)
+               free(str_cmdRef);
+
+       if (str_msgRef != NULL)
+               free(str_msgRef);
+
+       FW_LOGE("error :%d", err);
+       return err;
+
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_alert_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+
+       CommandAlertPrivate *pAlert = (CommandAlertPrivate *)(&(pCommand->private));
+
+       char *str_cmdID = NULL;
+       char *str_alert_type  = NULL;
+
+       if (!pAlert) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       if (pAlert->type == ALERT_UNKNOWN) {
+               /* error case */
+               err = PROTOCOL_BINDER_INVALID_INPUT_PARAMETER;
+               goto error;
+       }
+
+       WBXMLTreeNode *alert_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_ALERT);
+       if (alert_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       alert_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               alert_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, alert_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       str_alert_type = g_strdup_printf("%u",  pAlert->type);
+       if (str_alert_type == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       alert_node, ELEMENT_DATA, str_alert_type, strlen(str_alert_type));
+       if (data_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       /* item */
+       if (pCommand->source != NULL && pCommand->target != NULL) {
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               alert_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               item_node, ELEMENT_TARGET);
+               if (target_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->target, pBinder, target_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+
+               WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               item_node, ELEMENT_SOURCE);
+               if (source_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->source, pBinder, source_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+
+               if (pAlert->anchor != NULL) {
+                       err = __append_anchor_to_wbxml_node(pAlert->anchor, pBinder, item_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_alert_type != NULL)
+               free(str_alert_type);
+
+       *ppWbxml_dom_node = alert_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_alert_type != NULL)
+               free(str_alert_type);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_results_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+       CommandResultsPrivate *pResults = (CommandResultsPrivate *)(&(pCommand->private));
+
+       char *str_cmdID = NULL;
+       char *str_cmdRef  = NULL;
+       char *str_msgRef = NULL;
+
+       if (!pResults) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       if (pResults->item == NULL) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       char *content_type = (pResults->item)->contenttype;
+       if (!content_type) {
+               /* error case */
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+
+       WBXMLTreeNode *results_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_RESULTS);
+       if (results_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID != NULL) {
+               WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               results_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+               if (cmdid_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+
+       if (pResults->msgRef) {
+               str_msgRef = g_strdup_printf("%u", pResults->msgRef);
+               if (str_msgRef == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *msgref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               results_node, ELEMENT_MSGREF, str_msgRef, strlen(str_msgRef));
+               if (msgref_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       str_cmdRef = g_strdup_printf("%u", pResults->cmdRef);
+       if (str_cmdRef == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *msgref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       results_node, ELEMENT_CMDREF, str_cmdRef, strlen(str_cmdRef));
+       if (msgref_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (content_type) {
+               WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               results_node, ELEMENT_META);
+               if (meta_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *type_node  = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pResults->targetRef) {
+               WBXMLTreeNode *targetref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               results_node, ELEMENT_TARGETREF, pResults->targetRef->locURI, strlen(pResults->targetRef->locURI));
+               if (targetref_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_cmdRef != NULL)
+               free(str_cmdRef);
+
+       if (str_msgRef != NULL)
+               free(str_msgRef);
+
+       *ppWbxml_dom_node = results_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_cmdRef != NULL)
+               free(str_cmdRef);
+
+       if (str_msgRef != NULL)
+               free(str_msgRef);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_put_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+       CommandAccessPrivate *pAccess = (CommandAccessPrivate *)(&(pCommand->private));
+       char *str_cmdID = NULL;
+
+       if (!pAccess) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       char *content_type = (pAccess->item)->contenttype;
+       if (!content_type) {
+               /* error case */
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *put_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_PUT);
+       if (put_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       put_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               put_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, put_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       if (content_type) {
+               WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               put_node, ELEMENT_META);
+               if (meta_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       *ppWbxml_dom_node = put_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_get_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+       CommandAccessPrivate *pAccess = (CommandAccessPrivate *)(&(pCommand->private));
+       char *str_cmdID = NULL;
+
+       if (!pAccess) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!pAccess->item) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       char *content_type = (pAccess->item)->contenttype;
+
+       if (!content_type) {
+               /* error case */
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *get_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_GET);
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       get_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               get_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, get_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       if (content_type) {
+               WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               get_node, ELEMENT_META);
+               if (meta_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pAccess->item) {
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               get_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               item_node, ELEMENT_TARGET);
+               if (target_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pAccess->item->target, pBinder, target_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       *ppWbxml_dom_node = get_node;
+
+       if (str_cmdID)
+               free(str_cmdID);
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       if (str_cmdID)
+               free(str_cmdID);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_start_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+
+       char *str_cmdID = NULL;
+       char *numChanged_str  = NULL;
+
+       WBXMLTreeNode *sync_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_SYNC);
+       if (sync_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       sync_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               sync_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, sync_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       if (pCommand->source != NULL && pCommand->target != NULL) {
+               WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               sync_node, ELEMENT_TARGET);
+               if (target_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->target, pBinder, target_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+
+               WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               sync_node, ELEMENT_SOURCE);
+               if (source_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->source, pBinder, source_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+       }
+
+       if (pCommand->private.sync.hasNumChanged) {
+               numChanged_str = g_strdup_printf("%u", pCommand->private.sync.numChanged);
+               if (numChanged_str == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *numberOfChanges_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               sync_node, ELEMENT_NUMBEROFCHANGES, numChanged_str, strlen(numChanged_str));
+               if (numberOfChanges_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (numChanged_str != NULL)
+               free(numChanged_str);
+
+       *ppWbxml_dom_node = sync_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (numChanged_str != NULL)
+               free(numChanged_str);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_end_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_add_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       char *str_cmdID = NULL;
+       char *str_size = NULL;
+
+       Command *pCommand = (Command *)pContent;
+
+       CommandChangePrivate *pChange = (CommandChangePrivate *)(&(pCommand->private));
+
+       if (!pChange) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode  *add_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_ADD);
+       if (add_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       add_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               add_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, add_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       GList *Iter = NULL;
+       Item *item = NULL;
+       for (Iter = pChange->items; Iter != NULL; Iter = g_list_next(Iter)) {
+               item =  (Iter->data);
+
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               add_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (item->source != NULL) {
+                       WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_SOURCE);
+                       if (source_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->source, pBinder, source_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->target != NULL) {
+                       WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_TARGET);
+                       if (target_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->target, pBinder, target_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+               }
+
+               if (item->contenttype) {
+                       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_META);
+                       if (meta_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_TYPE, item->contenttype, strlen(item->contenttype));
+                       if (type_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (item->moreData) {
+                               if (item->size) {
+                                       str_size = g_strdup_printf("%u", item->size);
+                                       if (str_size == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+
+                                       WBXMLTreeNode *size_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                       meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
+                                       if (size_node == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+                               }
+                       }
+               }
+
+               if (item->dataType == ITEM_DATA) {
+                       if (item->private.data) {
+                               WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_cdata(pBinder,
+                                               item_node, ELEMENT_DATA, item->private.data, strlen(item->private.data));
+                               if (data_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+               }
+
+               if (item->moreData) {
+                       WBXMLTreeNode *moredata_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_MOREDATA);
+                       if (moredata_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       *ppWbxml_dom_node = add_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_replace_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       char *str_cmdID = NULL;
+       char *str_size = NULL;
+
+       Command *pCommand = (Command *)pContent;
+
+       CommandChangePrivate *pChange = (CommandChangePrivate *)(&(pCommand->private));
+
+       if (!pChange) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *replace_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_REPLACE);
+       if (replace_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       replace_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               replace_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, replace_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       GList *Iter = NULL;
+       Item *item = NULL;
+       for (Iter = pChange->items; Iter != NULL; Iter = g_list_next(Iter)) {
+               item =  (Iter->data);
+
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               replace_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (item->source != NULL) {
+                       WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_SOURCE);
+                       if (source_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+                       err = __append_location_to_wbxml_node(item->source, pBinder, source_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->target != NULL) {
+                       WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_TARGET);
+                       if (target_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+                       err = __append_location_to_wbxml_node(item->target, pBinder, target_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->contenttype) {
+                       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_META);
+                       if (meta_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_TYPE, item->contenttype, strlen(item->contenttype));
+                       if (type_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (item->moreData) {
+                               if (item->size) {
+                                       str_size = g_strdup_printf("%u", item->size);
+                                       if (str_size == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+
+                                       WBXMLTreeNode *size_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                       meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
+                                       if (size_node == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+                               }
+                       }
+               }
+
+               if (item->dataType == ITEM_DATA) {
+                       if (item->private.data) {
+                               WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_cdata(pBinder,
+                                               item_node, ELEMENT_DATA, item->private.data, strlen(item->private.data));
+                               if (data_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+               }
+
+               if (item->moreData) {
+                       WBXMLTreeNode *moredata_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_MOREDATA);
+                       if (moredata_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       *ppWbxml_dom_node = replace_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_delete_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       char *str_cmdID = NULL;
+       char *str_size = NULL;
+
+       Command *pCommand = (Command *)pContent;
+
+       CommandChangePrivate *pChange = (CommandChangePrivate *)(&(pCommand->private));
+
+       if (!pChange) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *delete_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_DELETE);
+       if (delete_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       delete_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               delete_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       /*TODO Archive*/
+       /*TODO sftDel*/
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, delete_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       GList *Iter = NULL;
+       Item *item = NULL;
+       for (Iter = pCommand->private.change.items; Iter != NULL; Iter = g_list_next(Iter)) {
+               item =  (Iter->data);
+
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               delete_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (item->source != NULL) {
+                       WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_SOURCE);
+                       if (source_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->source, pBinder, source_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->target != NULL) {
+                       WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_TARGET);
+                       if (target_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->target, pBinder, target_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->contenttype) {
+                       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_META);
+                       if (meta_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_TYPE, item->contenttype, strlen(item->contenttype));
+                       if (type_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (item->size) {
+                               str_size = g_strdup_printf("%u", item->size);
+                               if (str_size == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               WBXMLTreeNode *size_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
+                               if (size_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       *ppWbxml_dom_node = delete_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_map_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       char *str_cmdID = NULL;
+
+       Command *pCommand = (Command *)pContent;
+
+       WBXMLTreeNode *map_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_MAP);
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       map_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->source != NULL && pCommand->target != NULL) {
+               WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               map_node, ELEMENT_TARGET);
+               if (target_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->target, pBinder, target_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+
+               WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               map_node, ELEMENT_SOURCE);
+               if (source_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->source, pBinder, source_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, map_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       GList *iter = NULL;
+       Item *item = NULL;
+       for (iter = pCommand->private.map.items; iter != NULL; iter = g_list_next(iter)) {
+               item = iter->data;
+               WBXMLTreeNode *mapItem_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               map_node, ELEMENT_MAPITEM);
+               if (mapItem_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (item->source != NULL && item->target != NULL) {
+                       WBXMLTreeNode *item_target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       mapItem_node, ELEMENT_TARGET);
+                       if (item_target_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->target, pBinder, item_target_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+
+                       WBXMLTreeNode *item_source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       mapItem_node, ELEMENT_SOURCE);
+                       if (item_source_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->source, pBinder, item_source_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       *ppWbxml_dom_node = map_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static ProtocolVersion __get_oma_ds_protocol_version(char *verdtd)
+{
+       ProtocolVersion protocol_version = VERSION_UNKNOWN;
+       if (strcmp(verdtd, ELEMENT_VERDRD_12) == 0) {
+               protocol_version = VERSION_12;
+       } else if (strcmp(verdtd, ELEMENT_VERDRD_11) == 0) {
+               protocol_version = VERSION_11;
+       } else if (strcmp(verdtd, ELEMENT_VERDRD_10) == 0) {
+               protocol_version = VERSION_10;
+       }
+
+       return protocol_version;
+}
+
+static DevInfVersion __get_oma_ds_devInf_version(char *verdtd)
+{
+       DevInfVersion devInf_version = DEVINF_VERSION_UNKNOWN;
+       if (strcmp(verdtd, ELEMENT_VERDRD_12) == 0) {
+               devInf_version = DEVINF_VERSION_12;
+       } else if (strcmp(verdtd, ELEMENT_VERDRD_11) == 0) {
+               devInf_version = DEVINF_VERSION_11;
+       } else if (strcmp(verdtd, ELEMENT_VERDRD_10) == 0) {
+               devInf_version = DEVINF_VERSION_10;
+       }
+
+       return devInf_version;
+}
+
+static DevInfDevTyp __get_oma_ds_devInf_device_type(char *devType)
+{
+       DevInfDevTyp device_type = DEVINF_DEVTYPE_UNKNOWN;
+       if (strcmp(devType, ELEMENT_PAGER) == 0) {
+               device_type = DEVINF_DEVTYPE_PAGER;
+       } else if (strcmp(devType, ELEMENT_HANDHELD) == 0) {
+               device_type = DEVINF_DEVTYPE_HANDHELD;
+       } else if (strcmp(devType, ELEMENT_PDA) == 0) {
+               device_type = DEVINF_DEVTYPE_PDA;
+       } else if (strcmp(devType, ELEMENT_PHONE) == 0) {
+               device_type = DEVINF_DEVTYPE_PHONE;
+       } else if (strcmp(devType, ELEMENT_SMARTPHONE) == 0) {
+               device_type = DEVINF_DEVTYPE_SMARTPHONE;
+       } else if (strcmp(devType, ELEMENT_SERVER) == 0) {
+               device_type = DEVINF_DEVTYPE_SERVER;
+       } else if (strcmp(devType, ELEMENT_WORKSTATION) == 0) {
+               device_type = DEVINF_DEVTYPE_WORKSTATION;
+       }
+
+       return device_type;
+}
+
+static DevInfContentType *__get_devinf_contenttype(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       DevInfContentType *pDevInfContentType = (DevInfContentType *)calloc(1, sizeof(DevInfContentType));
+       if (pDevInfContentType == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pDevInfContentType is null");
+               goto return_part;
+       }
+
+       /* get first child */
+       WBXMLTreeNode *child = node->children;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       const char *first_child_name = NULL;
+       first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+       if (strcmp(first_child_name, ELEMENT_CTTYPE) == 0) {
+               char *ctType = NULL;
+               err = get_text_pointer_from_wbxml_node(child, &ctType);
+               if (err != PROTOCOL_BINDER_OK) {
+                       goto return_part;
+               }
+               if (ctType != NULL)
+                       pDevInfContentType->cttype = strdup(ctType);
+       } else {
+               /* error */
+               goto return_part;
+       }
+
+       /* get second child  */
+       child = child->next;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       if (child != NULL) {
+               const char *second_child_name = NULL;
+               second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+               if (strcmp(second_child_name, ELEMENT_VERCT) == 0) {
+                       char *verCT = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &verCT);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       if (verCT != NULL)
+                               pDevInfContentType->verct = strdup(verCT);
+               } else {
+                       /* error */
+                       goto return_part;
+               }
+       }
+
+       FW_LOGV("end");
+       return pDevInfContentType;
+
+return_part:
+       FW_LOGE("error : %d", err);
+       return NULL;
+
+}
+
+static Location *_get_location(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       Location *pLocation = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       char *locURI = NULL;
+       char *locName = NULL;
+
+       /* get first child : required LocURI */
+       child = node->children;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       const char *first_child_name = NULL;
+       first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+       FW_LOGV("child_name = %s", first_child_name);
+       if (strcmp(first_child_name, ELEMENT_LOCURI) == 0) {
+               err = get_text_pointer_from_wbxml_node(child, &locURI);
+               if (err != PROTOCOL_BINDER_OK) {
+                       goto return_part;
+               }
+       } else {
+               /* error */
+               goto return_part;
+       }
+
+       /* get second child : optional LocName */
+       child = child->next;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       if (child != NULL) {
+               const char *second_child_name = NULL;
+               second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+               FW_LOGV("child_name = %s", second_child_name);
+               if (strcmp(second_child_name, ELEMENT_LOCNAME) == 0) {
+                       err = get_text_pointer_from_wbxml_node(child, &locName);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+               } else {
+                       /* error */
+                       goto return_part;
+               }
+       }
+
+       create_location(locURI, locName, &pLocation);
+
+       FW_LOGV("end");
+       return pLocation;
+
+return_part:
+       FW_LOGE("error : %d", err);
+       free_location(pLocation);
+       return NULL;
+}
+
+static Anchor *_get_anchor(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       Anchor *pAnchor = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       char *lastAnchor = NULL;
+       char *nextAnchor = NULL;
+       /* get first child : optional lastAnchor */
+       child = node->children;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       const char *first_child_name = NULL;
+
+       first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+       FW_LOGV("child_name = %s", first_child_name);
+       if (strcmp(first_child_name, ELEMENT_LAST) == 0) {
+               err = get_text_pointer_from_wbxml_node(child, &lastAnchor);
+               if (err != PROTOCOL_BINDER_OK) {
+                       goto return_part;
+               }
+               child = child->next;
+               for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+       } else if (strcmp(first_child_name, ELEMENT_NEXT) == 0) {
+               err = get_text_pointer_from_wbxml_node(child, &nextAnchor);
+               if (err != PROTOCOL_BINDER_OK) {
+                       goto return_part;
+               }
+               child = NULL;
+       }
+
+       /* get second child : required nextAnchor */
+       if (child != NULL) {
+               const char *second_child_name = NULL;
+               second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+               FW_LOGV("child_name = %s", second_child_name);
+               if (strcmp(second_child_name, ELEMENT_NEXT) == 0) {
+                       err = get_text_pointer_from_wbxml_node(child, &nextAnchor);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+               } else {
+                       /* error */
+                       goto return_part;
+               }
+       }
+
+       create_anchor(lastAnchor, nextAnchor, &pAnchor);
+
+       FW_LOGV("end");
+       return pAnchor;
+
+return_part:
+       FW_LOGE("error : %d", err);
+       free_anchor(pAnchor);
+       return NULL;
+}
+
+static Cred *__get_cred(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       Cred *cred = NULL;
+
+       char *data = NULL;
+       char *type = NULL;
+       char *format = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       WBXMLTreeNode *grand_child = child->children;
+
+                       const char *grand_child_xml_name = NULL;
+                       grand_child_xml_name = (const char *)wbxml_tag_get_xml_name(grand_child->name);
+
+                       if (strcmp(grand_child_xml_name, ELEMENT_TYPE) == 0) {
+                               err = get_text_pointer_from_wbxml_node(grand_child, &type);
+                               if (err != PROTOCOL_BINDER_OK) {
+                                       goto return_part;
+                               }
+                               FW_LOGV("Type = [%s]" , type);
+                       } else if (strcmp(grand_child_xml_name, ELEMENT_FORMAT) == 0) {
+                               err = get_text_pointer_from_wbxml_node(grand_child, &format);
+                               if (err != PROTOCOL_BINDER_OK) {
+                                       goto return_part;
+                               }
+                               FW_LOGV("Type = [%s]" , format);
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
+                       err = get_text_pointer_from_wbxml_node(child, &data);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Data = [%s]" , data);
+               }
+
+       }
+
+       cred = create_cred_with_data(convert_auth_type(type), data);
+
+       FormatType formatType = FORMAT_TYPE_UNKNOWN;
+       if (strcmp(format, ELEMENT_B64) == 0)
+               formatType = FORMAT_TYPE_BASE64;
+
+       set_cred_format_type(cred, formatType);
+
+       FW_LOGV("end");
+       return cred;
+
+return_part:
+       FW_LOGE("error");
+       free_cred(cred);
+       return NULL;
+}
+
+static Chal *_get_chal(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Chal *pChal = (Chal *)calloc(1, sizeof(Chal));
+       if (pChal == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pChal is null");
+               goto return_part;
+       }
+
+       WBXMLTreeNode *chal_child = node->children;
+
+       WBXMLTreeNode *meta_child = NULL;
+
+       for (meta_child = chal_child->children; meta_child != NULL; meta_child = meta_child->next) {
+               if (meta_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *meta_child_xml_name = NULL;
+               meta_child_xml_name = (const char *)wbxml_tag_get_xml_name(meta_child->name);
+
+               if (strcmp(meta_child_xml_name, ELEMENT_TYPE) == 0) {
+                       char *type = NULL;
+                       err = get_text_pointer_from_wbxml_node(meta_child, &type);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Type = [%s]" , type);
+
+                       pChal->type = convert_auth_type(type);
+               } else if (strcmp(meta_child_xml_name, ELEMENT_FORMAT) == 0) {
+                       char *format = NULL;
+                       err = get_text_pointer_from_wbxml_node(meta_child, &format);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Format = [%s]" , format);
+
+                       pChal->format = convert_format_type(format);
+               } else if (strcmp(meta_child_xml_name, ELEMENT_NEXTNONCE) == 0) {
+                       char *nextnonce = NULL;
+                       unsigned int nonce_len = 0;
+                       err = get_binary_pointer_from_wbxml_node(meta_child, &nextnonce, &nonce_len);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("NextNonce = [%s]" , nextnonce);
+                       if (pChal->format == FORMAT_TYPE_BASE64) {
+                               if (nextnonce != NULL)
+                                       pChal->nonce_b64 = strdup(nextnonce);
+                       } else{
+                               pChal->nonce_plain = (char *) malloc(nonce_len+1);
+                               if (pChal->nonce_plain == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto return_part;
+                               }
+                               memcpy(pChal->nonce_plain, nextnonce, nonce_len);
+                               pChal->nonce_plain[nonce_len] = '\0';
+                       }
+
+                       pChal->nonce_length = nonce_len;
+               }
+       }
+
+       FW_LOGV("end");
+       return pChal;
+
+return_part:
+       FW_LOGE("error");
+       free_chal(pChal);
+       return NULL;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_devinf_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /* get data from dom tree */
+       DevInf *pDevInf = (DevInf *)calloc(1, sizeof(DevInf));
+       if (pDevInf == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pDevInf is null");
+               goto return_part;
+       }
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_VERDTD) == 0) {
+                       char *verdtd = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &verdtd);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("VerDTD = [%s]" , verdtd);
+
+                       pDevInf->version = __get_oma_ds_devInf_version(verdtd);
+               } else if (strcmp(child_xml_name, ELEMENT_MAN) == 0) {
+                       char *man = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &man);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Man = [%s]" , man);
+                       if (man != NULL)
+                               pDevInf->manufacturer = strdup(man);
+               } else if (strcmp(child_xml_name, ELEMENT_MOD) == 0) {
+                       char *mod = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &mod);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Mod = [%s]" , mod);
+                       if (mod != NULL)
+                               pDevInf->model = strdup(mod);
+               } else if (strcmp(child_xml_name, ELEMENT_OEM) == 0) {
+                       char *oem = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &oem);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("OEM = [%s]" , oem);
+                       if (oem != NULL)
+                               pDevInf->oem = strdup(oem);
+               } else if (strcmp(child_xml_name, ELEMENT_FWV) == 0) {
+                       char *fwv = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &fwv);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("FwV = [%s]" , fwv);
+                       if (fwv != NULL)
+                               pDevInf->firmwareVersion = strdup(fwv);
+               } else if (strcmp(child_xml_name, ELEMENT_SWV) == 0) {
+                       char *swv = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &swv);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("SwV = [%s]" , swv);
+                       if (swv != NULL)
+                               pDevInf->softwareVersion = strdup(swv);
+               } else if (strcmp(child_xml_name, ELEMENT_HWV) == 0) {
+                       char *hwv = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &hwv);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("HwV = [%s]" , hwv);
+                       if (hwv != NULL)
+                               pDevInf->hardwareVersion = strdup(hwv);
+               } else if (strcmp(child_xml_name, ELEMENT_DEVID) == 0) {
+                       char *devID = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &devID);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("DevID = [%s]" , devID);
+                       if (devID != NULL)
+                               pDevInf->devid = strdup(devID);
+               } else if (strcmp(child_xml_name, ELEMENT_DEVTYP) == 0) {
+                       char *devtyp = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &devtyp);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("DevTyp = [%s]" , devtyp);
+
+                       pDevInf->devtyp = __get_oma_ds_devInf_device_type(devtyp);
+               } else if (strcmp(child_xml_name, ELEMENT_UTC) == 0) {
+                       FW_LOGV("UTC");
+                       pDevInf->supportsUTC = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_SUPPORTLARGEOBJS) == 0) {
+                       FW_LOGV("SupportLargeObjs");
+                       pDevInf->supportsLargeObjs = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_SUPPORTNUMBEROFCHANGES) == 0) {
+                       FW_LOGV("SupportNumberOfChanges");
+                       pDevInf->supportsNumberOfChanges = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_DATASTORE) == 0) {
+
+                       DevInfDataStore *pDevInfDataStore = (DevInfDataStore *)calloc(1, sizeof(DevInfDataStore));
+
+                       WBXMLTreeNode *datastore_child = NULL;
+
+                       for (datastore_child = child->children; datastore_child != NULL; datastore_child = datastore_child->next) {
+                               if (datastore_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *datastore_child_xml_name = NULL;
+                               datastore_child_xml_name = (const char *)wbxml_tag_get_xml_name(datastore_child->name);
+
+                               if (strcmp(datastore_child_xml_name, ELEMENT_SOURCEREF) == 0) {
+                                       char *sourceref = NULL;
+                                       err = get_text_pointer_from_wbxml_node(datastore_child, &sourceref);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("SourceRef = [%s]" , sourceref);
+                                       if (sourceref != NULL)
+                                               pDevInfDataStore->sourceref = strdup(sourceref);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
+                                       char *displayname = NULL;
+                                       err = get_text_pointer_from_wbxml_node(datastore_child, &displayname);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("DisplayName = [%s]" , displayname);
+                                       if (displayname != NULL)
+                                               pDevInfDataStore->displayname = strdup(displayname);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_MAXGUIDSIZE) == 0) {
+                                       char *maxguidsize = NULL;
+                                       err = get_text_pointer_from_wbxml_node(datastore_child, &maxguidsize);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("MaxGUIDSize = [%s]" , maxguidsize);
+                                       if (maxguidsize != NULL)
+                                               pDevInfDataStore->maxGUIDSize = atoi(maxguidsize);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_RX_PREF) == 0) {
+                                       DevInfContentType *pDevInfContentType = __get_devinf_contenttype(datastore_child);
+                                       if (pDevInfContentType == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pDevInfDataStore->rxPref = pDevInfContentType;
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_RX) == 0) {
+                                       DevInfContentType *pDevInfContentType = __get_devinf_contenttype(datastore_child);
+                                       if (pDevInfContentType == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pDevInfDataStore->rx = g_list_append(pDevInfDataStore->rx, pDevInfContentType);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_TX_PREF) == 0) {
+                                       DevInfContentType *pDevInfContentType = __get_devinf_contenttype(datastore_child);
+                                       if (pDevInfContentType == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pDevInfDataStore->txPref = pDevInfContentType;
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_TX) == 0) {
+                                       DevInfContentType *pDevInfContentType = __get_devinf_contenttype(datastore_child);
+                                       if (pDevInfContentType == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pDevInfDataStore->tx = g_list_append(pDevInfDataStore->tx, pDevInfContentType);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_CTCAP) == 0) {
+
+                                       DevInfCTCap *pDevInfCtCap = (DevInfCTCap *)calloc(1, sizeof(DevInfCTCap));
+
+                                       DevInfContentType *pDevInfContentType = NULL;
+                                       WBXMLTreeNode *ctcap_child = NULL;
+
+                                       for (ctcap_child = datastore_child->children; ctcap_child != NULL; ctcap_child = ctcap_child->next) {
+                                               if (ctcap_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *ctcap_child_xml_name = NULL;
+                                               ctcap_child_xml_name = (const char *)wbxml_tag_get_xml_name(ctcap_child->name);
+
+                                               if (strcmp(ctcap_child_xml_name, ELEMENT_CTTYPE) == 0) {
+                                                       if (pDevInfContentType == NULL)
+                                                               pDevInfContentType = (DevInfContentType *)calloc(1, sizeof(DevInfContentType));
+
+                                                       char *cttype = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(ctcap_child, &cttype);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("CTType = [%s]" , cttype);
+                                                       if (cttype != NULL)
+                                                               pDevInfContentType->cttype = strdup(cttype);
+                                               } else if (strcmp(ctcap_child_xml_name, ELEMENT_VERCT) == 0) {
+                                                       if (pDevInfContentType == NULL)
+                                                               pDevInfContentType = (DevInfContentType *)calloc(1, sizeof(DevInfContentType));
+
+                                                       char *verct = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(ctcap_child, &verct);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("VerCT = [%s]" , verct);
+                                                       if (verct != NULL)
+                                                               pDevInfContentType->verct = strdup(verct);
+                                               } else if (strcmp(ctcap_child_xml_name, ELEMENT_FIELDLEVEL) == 0) {
+                                                       /*TODO fieldlevel*/
+
+                                               } else if (strcmp(ctcap_child_xml_name, ELEMENT_PROPERTY) == 0) {
+
+                                                       DevInfProperty *pDevInfProperty = (DevInfProperty *)calloc(1, sizeof(DevInfProperty));
+
+                                                       WBXMLTreeNode *property_child = NULL;
+                                                       for (property_child = ctcap_child->children; property_child != NULL; property_child = property_child->next) {
+                                                               if (property_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                                               const char *property_child_xml_name = NULL;
+                                                               property_child_xml_name = (const char *)wbxml_tag_get_xml_name(property_child->name);
+
+                                                               if (strcmp(property_child_xml_name, ELEMENT_PROPNAME) == 0) {
+                                                                       char *propname = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &propname);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("PropName = [%s]" , propname);
+                                                                       if (propname != NULL)
+                                                                               pDevInfProperty->propName = strdup(propname);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_DATATYPE) == 0) {
+                                                                       char *datatype = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &datatype);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("DataType = [%s]" , datatype);
+                                                                       if (datatype != NULL)
+                                                                               pDevInfProperty->dataType = strdup(datatype);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_MAXOCCUR) == 0) {
+                                                                       char *maxoccur = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &maxoccur);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("MaxOccur = [%s]" , maxoccur);
+                                                                       if (maxoccur != NULL)
+                                                                               pDevInfProperty->maxOccur = atoi(maxoccur);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_MAXSIZE) == 0) {
+                                                                       char *maxsize = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &maxsize);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("MaxSize = [%s]" , maxsize);
+                                                                       if (maxsize != NULL)
+                                                                               pDevInfProperty->maxSize = atoi(maxsize);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_NOTRUNCATE) == 0) {
+                                                                       FW_LOGV("NoTruncate");
+                                                                       pDevInfProperty->noTruncate = 1;
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_VALENUM) == 0) {
+                                                                       char *valenum = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &valenum);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("ValEnum = [%s]" , valenum);
+                                                                       pDevInfProperty->valEnums = g_list_append(pDevInfProperty->valEnums, strdup(valenum));
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
+                                                                       char *displayname = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &displayname);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("DisplayName = [%s]" , displayname);
+                                                                       if (displayname != NULL)
+                                                                               pDevInfProperty->displayName = strdup(displayname);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_PROPPARAM) == 0) {
+
+                                                                       DevInfPropParam *pDevInfPropParam = (DevInfPropParam *)calloc(1, sizeof(DevInfPropParam));
+
+                                                                       WBXMLTreeNode *propparam_child = NULL;
+
+                                                                       for (propparam_child = property_child->children; propparam_child != NULL; propparam_child = propparam_child->next) {
+                                                                               if (propparam_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                                                               const char *propparam_child_xml_name = NULL;
+                                                                               propparam_child_xml_name = (const char *)wbxml_tag_get_xml_name(propparam_child->name);
+
+                                                                               if (strcmp(propparam_child_xml_name, ELEMENT_PARAMNAME) == 0) {
+                                                                                       char *paramname = NULL;
+                                                                                       err = get_text_pointer_from_wbxml_node(propparam_child, &paramname);
+                                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                                               goto return_part;
+                                                                                       }
+                                                                                       FW_LOGV("ParamName = [%s]" , paramname);
+                                                                                       if (paramname != NULL)
+                                                                                               pDevInfPropParam->paramName = strdup(paramname);
+                                                                               } else if (strcmp(propparam_child_xml_name, ELEMENT_DATATYPE) == 0) {
+                                                                                       char *datatype = NULL;
+                                                                                       err = get_text_pointer_from_wbxml_node(propparam_child, &datatype);
+                                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                                               goto return_part;
+                                                                                       }
+                                                                                       FW_LOGV("DataType = [%s]" , datatype);
+                                                                                       if (datatype != NULL)
+                                                                                               pDevInfPropParam->dataType = strdup(datatype);
+                                                                               } else if (strcmp(propparam_child_xml_name, ELEMENT_VALENUM) == 0) {
+                                                                                       char *valenum = NULL;
+                                                                                       err = get_text_pointer_from_wbxml_node(propparam_child, &valenum);
+                                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                                               goto return_part;
+                                                                                       }
+                                                                                       FW_LOGV("ValEnum = [%s]" , valenum);
+                                                                                       if (valenum != NULL)
+                                                                                               pDevInfPropParam->valEnums = g_list_append(pDevInfPropParam->valEnums, strdup(valenum));
+                                                                               } else if (strcmp(propparam_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
+                                                                                       char *displayname = NULL;
+                                                                                       err = get_text_pointer_from_wbxml_node(propparam_child, &displayname);
+                                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                                               goto return_part;
+                                                                                       }
+                                                                                       FW_LOGV("DisplayName = [%s]" , displayname);
+                                                                                       if (displayname != NULL)
+                                                                                               pDevInfPropParam->displayName = strdup(displayname);
+                                                                               }
+                                                                       }
+
+                                                                       pDevInfProperty->propParams = g_list_append(pDevInfProperty->propParams, pDevInfPropParam);
+                                                               }
+                                                       }
+
+                                                       pDevInfCtCap->properties = g_list_append(pDevInfCtCap->properties, pDevInfProperty);
+                                               }
+                                       }
+                                       pDevInfCtCap->ct = pDevInfContentType;
+                                       pDevInfDataStore->ctcaps = g_list_append(pDevInfDataStore->ctcaps, pDevInfCtCap);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_DSMEM) == 0) {
+
+                                       /*TODO DSMem*/
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_SUPPORTHIERARCHICALSYNC) == 0) {
+                                       FW_LOGV("SupportHierarchicalSync");
+                                       pDevInfDataStore->supportsHierarchicalSync = 1;
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_SYNCCAP) == 0) {
+
+                                       WBXMLTreeNode *synccap_child = NULL;
+
+                                       for (synccap_child = datastore_child->children; synccap_child != NULL; synccap_child = synccap_child->next) {
+                                               if (synccap_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *synccap_child_xml_name = NULL;
+                                               synccap_child_xml_name = (const char *)wbxml_tag_get_xml_name(synccap_child->name);
+
+                                               if (strcmp(synccap_child_xml_name, ELEMENT_SYNCTYPE) == 0) {
+                                                       char *synctype_str = NULL;
+                                                       unsigned int synctype = 0;
+                                                       err = get_text_pointer_from_wbxml_node(synccap_child, &synctype_str);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("SyncType = [%s]" , synctype_str);
+                                                       if (synctype_str != NULL) {
+                                                               synctype = atoi(synctype_str);
+                                                               synctype = 1 << (synctype - 1);
+                                                       }
+                                                       /*DevInfSyncCap synccap = convert_devinf_synccap(synctype);*/
+                                                       set_devInf_datastore_synccap(pDevInfDataStore, synctype, 1);
+                                               }
+                                       }
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_FILTER_RX) == 0) {
+                                               /*TODO filter-rx*/
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_FILTERCAP) == 0) {
+                                               /*TODO filtercap*/
+                               }
+                       }
+                       pDevInf->datastores = g_list_append(pDevInf->datastores, pDevInfDataStore);
+               }
+       }
+
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pDevInf;
+       } else{
+               FW_LOGE("error");
+               free_devinf(pDevInf);
+       }
+
+       return err;
+}
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_header_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /* get data from dom tree */
+       SyncHdr *pSyncHdr = (SyncHdr *)calloc(1, sizeof(SyncHdr));
+       if (pSyncHdr == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pSyncHdr is null");
+               goto return_part;
+       }
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_VERDTD) == 0) {
+                       char *verdtd = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &verdtd);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("VerDTD = [%s]" , verdtd);
+
+                       pSyncHdr->version = __get_oma_ds_protocol_version(verdtd);
+               } else if (strcmp(child_xml_name, ELEMENT_SESSIONID) == 0) {
+                       char *sessionID = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &sessionID);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("SessionID = [%s]" , sessionID);
+
+                       if (sessionID)
+                               pSyncHdr->sessionID = strdup(sessionID);
+                       else
+                               pSyncHdr->sessionID = NULL;
+               } else if (strcmp(child_xml_name, ELEMENT_MSGID) == 0) {
+                       char *msgID = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &msgID);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("MsgID = [%s]" , msgID);
+                       if (msgID != NULL)
+                               pSyncHdr->messageID = atoi(msgID);
+               } else if (strcmp(child_xml_name, ELEMENT_TARGET) == 0) {
+                       Location *pTargetLocation = _get_location(child);
+                       if (pTargetLocation == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSyncHdr->target = pTargetLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_SOURCE) == 0) {
+                       Location *pSourceLocation = _get_location(child);
+                       if (pSourceLocation == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSyncHdr->source = pSourceLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_RESPURI) == 0) {
+                       char *resp_uri = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &resp_uri);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("resp_uri = [%s]" , resp_uri);
+                       if (resp_uri != NULL)
+                               pSyncHdr->responseURI = strdup(resp_uri);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("noResp\n");
+                       pSyncHdr->noResponse = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSyncHdr->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pSyncHdr;
+       } else{
+               FW_LOGE("error");
+               free_synchdr(pSyncHdr);
+       }
+
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_results_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pResults = (Command *)calloc(1, sizeof(Command));
+       if (pResults == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pResults is null");
+               goto return_part;
+       }
+
+       pResults->type = COMMAND_TYPE_RESULTS;
+       pResults->msgID = pSyncHdr->messageID;
+       pResults->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pResults->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_MSGREF) == 0) {
+                       char *msg_ref = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &msg_ref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("MsgRef = [%s]" , msg_ref);
+                       if (msg_ref != NULL)
+                               pResults->private.results.msgRef = atoi(msg_ref);
+               } else if (strcmp(child_xml_name, ELEMENT_CMDREF) == 0) {
+                       char *cmd_ref = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_ref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("MsgRef = [%s]" , cmd_ref);
+                       if (cmd_ref != NULL)
+                               pResults->private.results.cmdRef = atoi(cmd_ref);
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+
+                       WBXMLTreeNode *grandchild = NULL;
+
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               pResults->private.results.type = strdup(contentType);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_TARGETREF) == 0) {
+               /*TODO targetRef*/
+               } else if (strcmp(child_xml_name, ELEMENT_SOURCEREF) == 0) {
+               /*TODO sourceRef*/
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       /*create item in results command */
+                       Item *item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pResults->private.results.item = item;
+
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pResults->private.results.item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pResults->private.results.item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       /* TODO data*/
+                               }
+                       }
+               }
+       }
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pResults;
+       } else{
+               FW_LOGE("error");
+               free_command(pResults);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_put_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pPut = (Command *)calloc(1, sizeof(Command));
+       if (pPut == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pPut is null");
+               goto return_part;
+       }
+
+       pPut->type = COMMAND_TYPE_PUT;
+       pPut->msgID = pSyncHdr->messageID;
+       pPut->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pPut->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pPut->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pPut->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               pPut->private.access.type = strdup(contentType);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       /*create item in put command */
+                       Item *item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pPut->private.access.item = item;
+
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pPut->private.access.item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pPut->private.access.item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       /* TODO data*/
+                               }
+                       }
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pPut;
+       } else{
+               FW_LOGE("error");
+               free_command(pPut);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_get_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pGet = (Command *)calloc(1, sizeof(Command));
+       if (pGet == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pGet is null");
+               goto return_part;
+       }
+
+       pGet->type = COMMAND_TYPE_GET;
+       pGet->msgID = pSyncHdr->messageID;
+       pGet->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pGet->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pGet->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pGet->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               pGet->private.access.type = strdup(contentType);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       /*create item in put command */
+                       Item *item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pGet->private.access.item = item;
+
+                       WBXMLTreeNode *grandchild = NULL;
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pGet->private.access.item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pGet->private.access.item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       /* TODO data*/
+                               }
+                       }
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pGet;
+       } else{
+               FW_LOGE("error");
+               free_command(pGet);
+       }
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_alert_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pAlert = (Command *)calloc(1, sizeof(Command));
+       if (pAlert == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pAlert is null");
+               goto return_part;
+       }
+
+       pAlert->type = COMMAND_TYPE_ALERT;
+       pAlert->msgID = pSyncHdr->messageID;
+       pAlert->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pAlert->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pAlert->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pAlert->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
+                       char *data = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &data);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Data = [%s]" , data);
+                       if (data != NULL)
+                               pAlert->private.alert.type = atoi(data);
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pAlert->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pAlert->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
+
+                                       WBXMLTreeNode *grandgrandchild = NULL;
+                                       for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
+                                               if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *grandgrandchild_xml_name = NULL;
+                                               grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
+
+                                               if (strcmp(grandgrandchild_xml_name, ELEMENT_ANCHOR) == 0) {
+                                                       Anchor *pAnchor = _get_anchor(grandgrandchild);
+                                                       if (pAnchor == NULL) {
+                                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                               goto return_part;
+                                                       }
+                                                       pAlert->private.alert.anchor = pAnchor;
+                                               } else if (strcmp(grandgrandchild_xml_name, ELEMENT_MAXOBJSIZE) == 0) {
+                                                       char *maxObjSize = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &maxObjSize);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("MaxObjSize = [%s]" , maxObjSize);
+                                                       if (maxObjSize != NULL)
+                                                               pAlert->private.alert.maxObjSize = atoi(maxObjSize);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pAlert;
+       } else{
+               FW_LOGE("error");
+               free_command(pAlert);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_end_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pSyncEnd = (Command *)calloc(1, sizeof(Command));
+       if (pSyncEnd == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pSyncEnd is null");
+               goto return_part;
+       }
+
+       pSyncEnd->type = COMMAND_TYPE_SYNC_END;;
+       pSyncEnd->msgID = pSyncHdr->messageID;
+       pSyncEnd->refCount = 1;
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pSyncEnd;
+       } else{
+               FW_LOGE("error");
+               free_command(pSyncEnd);
+       }
+       return err;
+}
+
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_start_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pSync = (Command *)calloc(1, sizeof(Command));
+       if (pSync == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pSync is null");
+               goto return_part;
+       }
+
+       pSync->type = COMMAND_TYPE_SYNC_START;;
+       pSync->msgID = pSyncHdr->messageID;
+       pSync->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pSync->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pSync->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSync->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_TARGET) == 0) {
+                       Location *pTargetLocation = _get_location(child);
+                       if (pTargetLocation == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSync->target = pTargetLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_SOURCE) == 0) {
+                       Location *pSourceLocation = _get_location(child);
+                       if (pSourceLocation == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSync->source = pSourceLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       /*TODO meta*/
+               } else if (strcmp(child_xml_name, ELEMENT_NUMBEROFCHANGES) == 0) {
+                       char *numOfChanges = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &numOfChanges);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("NumberOfChanges = [%s]" , numOfChanges);
+
+                       pSync->private.sync.hasNumChanged = 1;
+                       if (numOfChanges != NULL)
+                               pSync->private.sync.numChanged = atoi(numOfChanges);
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pSync;
+       } else{
+               FW_LOGE("error");
+               free_command(pSync);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_add_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pAdd = (Command *)calloc(1, sizeof(Command));
+       if (pAdd == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pAdd is null");
+               goto return_part;
+       }
+
+       pAdd->type = COMMAND_TYPE_ADD;;
+       pAdd->msgID = pSyncHdr->messageID;
+       pAdd->private.change.type = CHANGE_ADD;
+       pAdd->refCount = 1;
+
+       Item *item = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pAdd->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pAdd->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pAdd->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+
+                       item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               item->contenttype = strdup(contentType);
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_SIZE) == 0) {
+                                       char *size = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &size);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Size = [%s]" , size);
+                                       if (size != NULL)
+                                               item->size = atoi(size);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+
+                       if (!item) {
+                               item =  create_item();
+                               if (item == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto return_part;
+                               }
+                       }
+
+                       WBXMLTreeNode *grandchild = NULL;
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
+                                       WBXMLTreeNode *grandgrandchild = NULL;
+
+                                       for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
+                                               if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *grandgrandchild_xml_name = NULL;
+                                               grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
+
+                                               if (strcmp(grandgrandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                                       char *contentType = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &contentType);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                                       if (contentType != NULL)
+                                                               item->contenttype = strdup(contentType);
+                                               } else if (strcmp(grandgrandchild_xml_name, ELEMENT_SIZE) == 0) {
+                                                       char *size = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &size);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("Size = [%s]" , size);
+                                                       if (size != NULL)
+                                                               item->size = atoi(size);
+                                               }
+                                       }
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       char *data = NULL;
+                                       err = get_text_pointer_from_wbxml_cdata_node(grandchild, &data);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Data = [%s]" , data);
+                                       if (data != NULL)
+                                               item->private.data = strdup(data);
+                                       item->dataType = ITEM_DATA;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_MOREDATA) == 0) {
+                                       FW_LOGV("MoreData");
+                                       item->moreData = 1;
+                               }
+                       }
+                       pAdd->private.change.items = g_list_append(pAdd->private.change.items, item);
+                       item = NULL;
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pAdd;
+       } else{
+               FW_LOGE("error");
+               free_command(pAdd);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_replace_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pReplace = (Command *)calloc(1, sizeof(Command));
+       if (pReplace == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pReplace is null");
+               goto return_part;
+       }
+
+       pReplace->type = COMMAND_TYPE_REPLACE;;
+       pReplace->msgID = pSyncHdr->messageID;
+       pReplace->private.change.type = CHANGE_REPLACE;
+       pReplace->refCount  = 1;
+
+       Item *item = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pReplace->cmdID = atoi(cmd_id);
+
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pReplace->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pReplace->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+
+                       item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       WBXMLTreeNode *grandchild = NULL;
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               item->contenttype = strdup(contentType);
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_SIZE) == 0) {
+                                       char *size = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &size);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Size = [%s]" , size);
+                                       if (size != NULL)
+                                               item->size = atoi(size);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+
+                       if (!item) {
+                               item =  create_item();
+                               if (item == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto return_part;
+                               }
+                       }
+
+                       WBXMLTreeNode *grandchild = NULL;
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
+                                       WBXMLTreeNode *grandgrandchild = NULL;
+
+                                       for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
+                                               if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *grandgrandchild_xml_name = NULL;
+                                               grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
+
+                                               if (strcmp(grandgrandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                                       char *contentType = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &contentType);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                                       if (contentType != NULL)
+                                                               item->contenttype = strdup(contentType);
+                                               } else if (strcmp(grandgrandchild_xml_name, ELEMENT_SIZE) == 0) {
+                                                       char *size = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &size);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("Size = [%s]" , size);
+                                                       if (size != NULL)
+                                                               item->size = atoi(size);
+                                               }
+                                       }
+
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       char *data = NULL;
+                                       err = get_text_pointer_from_wbxml_cdata_node(grandchild, &data);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Data = [%s]" , data);
+                                       if (data != NULL)
+                                               item->private.data = strdup(data);
+                                       item->dataType = ITEM_DATA;
+                               }
+                       }
+                       pReplace->private.change.items = g_list_append(pReplace->private.change.items, item);
+                       item = NULL;
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pReplace;
+       } else{
+               FW_LOGE("error");
+               free_command(pReplace);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_delete_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pDelete = (Command *)calloc(1, sizeof(Command));
+       if (pDelete == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pDelete is null");
+               goto return_part;
+       }
+
+       pDelete->type = COMMAND_TYPE_DELETE;
+       pDelete->msgID = pSyncHdr->messageID;
+       pDelete->private.change.type = CHANGE_DELETE;
+       pDelete->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               Item *item = NULL;
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pDelete->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pDelete->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pDelete->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+
+                       /* create Item */
+                       item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               item->contenttype = strdup(contentType);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       /* create Item */
+                       if (!item) {
+                               item = create_item();
+                               if (item == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto return_part;
+                               }
+                       }
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
+
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+
+                               }
+                       }
+                       pDelete->private.change.items = g_list_append(pDelete->private.change.items, item);
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pDelete;
+       } else{
+               FW_LOGE("error");
+               free_command(pDelete);
+       }
+       return err;
+}
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_final_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       int *pFinal = (int *)1;
+       *pContent = pFinal;
+
+       FW_LOGV("end");
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_status_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /* get data from dom tree */
+       Status *pStatus = (Status *)calloc(1, sizeof(Status));
+       if (pStatus == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pStatus is null");
+               goto return_part;
+       }
+
+       WBXMLTreeNode *child = NULL;
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pStatus->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_MSGREF) == 0) {
+                       char *msgref = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &msgref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("MsgRef = [%s]" , msgref);
+                       if (msgref != NULL)
+                               pStatus->msgRef = atoi(msgref);
+               } else if (strcmp(child_xml_name, ELEMENT_CMDREF) == 0) {
+                       char *cmdref = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmdref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdRef = [%s]" , cmdref);
+                       if (cmdref != NULL)
+                               pStatus->cmdRef = atoi(cmdref);
+               } else if (strcmp(child_xml_name, ELEMENT_CMD) == 0) {
+                       char *cmd = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Cmd = [%s]" , cmd);
+
+                       pStatus->type = convert_command_type(cmd);
+               } else if (strcmp(child_xml_name, ELEMENT_TARGETREF) == 0) {
+                       char *targetref = NULL;
+                       Location *pLocation = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &targetref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("TargetRef = [%s]" , targetref);
+
+                       create_location(targetref, NULL, &pLocation);
+                       pStatus->targetRef = pLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_SOURCEREF) == 0) {
+                       char *sourceref = NULL;
+                       Location *pLocation = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &sourceref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("SourceRef = [%s]" , sourceref);
+
+                       create_location(sourceref, NULL, &pLocation);
+                       pStatus->sourceRef = pLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pStatus->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_CHAL) == 0) {
+                       FW_LOGV("Chal\n");
+                       Chal *pChal = NULL;
+                       pChal = _get_chal(child);
+                       if (pChal == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pStatus->chal = pChal;
+               } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
+                       char *data = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &data);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Data = [%s]\n" , data);
+                       if (data != NULL)
+                               pStatus->data = strdup(data);
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pStatus->sourceRef =  pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       /* need ? */
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       /* need ?*/
+                               }
+                       }
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pStatus;
+       } else{
+               FW_LOGE("error");
+               free_status(pStatus);
+       }
+       return err;
+}
+
+PROTOCOL_BINDER_ERROR init_oma_ds_1_2_binder_function_set(Binder_function_set **pBinder_function_set)
+{
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       err = init_binder_function_set(sizeof(oma_ds_binder_function_info)/sizeof(Binder_function_info),
+                                                                       (Binder_function_info*)oma_ds_binder_function_info,
+                                                                       pBinder_function_set);
+
+       return err;
+}
+
+void free_oma_ds_1_2_binder_function_set(Binder_function_set *pBinder_function_set)
+{
+       free_binder_function_set(pBinder_function_set);
+}
+
+protocol_binder *oma_ds_1_2_binder_init(protocol_binder *pBinder, Encoding enc, bool encode_xml_header,
+                                                                                       bool use_strtbl, bool produce_anonymous, bool use_flow_mode,
+                                                                                       Binder_function_set *pBinder_function_set)
+{
+       protocol_binder *pOutBinder = NULL;
+
+       pOutBinder = protocol_binder_init(pBinder, PROTOCOL_SYNCML_SYNCML12, NULL, enc,
+                                                               encode_xml_header, use_strtbl, produce_anonymous, use_flow_mode, NULL, NULL,
+                                                               pBinder_function_set);
+
+       if (pOutBinder == NULL) {
+               goto return_part;
+       }
+
+return_part:
+       return pOutBinder;
+}
+
+
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_append(protocol_binder *pBinder,
+                                                                                               OMA_DS_Protocol_Element protocol_element,
+                                                                                               Content_Ptr pContent)
+{
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       err = protocol_binder_append(pBinder, protocol_element, pContent);
+
+       return err;
+}
+
+
+void oma_ds_1_2_binder_terminate(protocol_binder *pBinder)
+{
+       protocol_binder_terminate(pBinder);
+}
+
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_stream(protocol_binder *pBinder,
+                                                                                                       char **byte_stream,
+                                                                                                       unsigned int *byte_stream_size)
+{
+       PROTOCOL_BINDER_ERROR err =  PROTOCOL_BINDER_OK;
+
+       err = protocol_binder_get_stream(pBinder, byte_stream, byte_stream_size);
+       if (err != PROTOCOL_BINDER_OK) {
+               goto return_part;
+       }
+
+return_part:
+       return err;
+}
+
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_stream_size(protocol_binder *pBinder, unsigned int *byte_stream_size)
+{
+       PROTOCOL_BINDER_ERROR err =  PROTOCOL_BINDER_OK;
+
+       err = protocol_binder_get_stream_size(pBinder, byte_stream_size);
+       return err;
+}
+
+
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_encoding(protocol_binder *pBinder, Encoding *enc)
+{
+       PROTOCOL_BINDER_ERROR err =  PROTOCOL_BINDER_OK;
+
+       err = protocol_binder_get_encoding(pBinder, enc);
+       return err;
+}
+
+PROTOCOL_BINDER_ERROR reverse_oma_ds_1_2_binder_init(char *byte_stream,
+                                                                                                       unsigned int byte_stream_len,
+                                                                                                       Decoding dec,
+                                                                                                       Binder_function_set *pBinder_function_set,
+                                                                                                       void *user_data,
+                                                                                                       Reverse_protocol_binder **ppBinder)
+{
+       Protocol protocol = PROTOCOL_UNKNOWN;
+       PROTOCOL_BINDER_ERROR err = reverse_protocol_binder_init(byte_stream, byte_stream_len, dec,
+                                                                                       &protocol, pBinder_function_set, user_data, ppBinder);
+
+       return err;
+}
+
+PROTOCOL_BINDER_ERROR reverse_oma_ds_1_2_binder_next(Reverse_protocol_binder *pBinder,
+                                                                                               OMA_DS_Protocol_Element *protocol_element,
+                                                                                               char **protocol_element_name,
+                                                                                               Content_Ptr *pContent)
+{
+       PROTOCOL_BINDER_ERROR err = reverse_protocol_binder_next(pBinder,
+                                                                               protocol_element, protocol_element_name, pContent);
+       return err;
+}
diff --git a/ServiceAdapter/SA_Command.c b/ServiceAdapter/SA_Command.c
new file mode 100644 (file)
index 0000000..a10d25f
--- /dev/null
@@ -0,0 +1,1040 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Command.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions for command structure which is used in Service Adapter
+ */
+
+#include <stdlib.h>
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceAdapter/SA_Command.h"
+#include "ServiceAdapter/SA_Command_Internal.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Session.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+static Command *__create_command(Session *session, CommandType type);
+
+
+static Command *__create_command(Session *session, CommandType type)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!session) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!type) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       Command *cmd = (Command *) calloc(1, sizeof(Command));
+       if (!cmd) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+
+       cmd->type = type;
+       cmd->msgID = session->msgID;
+       cmd->cmdID = session->cmdID;
+       cmd->refCount = 1;
+
+       session->cmdID++;
+
+       FW_LOGV("end");
+
+       return cmd;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return NULL;
+}
+
+void free_commands(GList *commands)
+{
+       FW_LOGV("start list length is %d", g_list_length(commands));
+
+       if (!commands) {
+               FW_LOGV("List is NULL");
+               return;
+       }
+
+
+       GList *iter = NULL;
+       Command *pCommand = NULL;
+       for (iter = commands; iter != NULL;) {
+               pCommand = iter->data;
+               FW_LOGV("command list length is %d command type is %d\n", g_list_length(commands), pCommand->type);
+
+               iter = g_list_next(iter);
+               if (pCommand->type != COMMAND_TYPE_UNKNOWN) {
+                       free_command(pCommand);
+                       commands = g_list_remove(commands, pCommand);
+               }
+       }
+
+
+       g_list_free(commands);
+
+       FW_LOGV("end");
+
+       return;
+}
+
+SA_ErrorType create_alert_command(Session *session, AlertType  syncType, Location *source, Location *target,
+                                                                                                               char *lastAnchor, char *nextAnchor, Cred *pCred, Command **pCommand)
+{
+       FW_LOGV("start with syncType =%d", syncType);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Anchor *pAnchor = NULL;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_ALERT);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->target = target;
+       (*pCommand)->source = source;
+
+       /*TODO  check that sync Type is ALERT_NEXT_MESSAGE(does not need last and next anchor)*/
+       /*TODO  check that sync Type is  ALERT_SLOW_SYNC(does not need last anchor)*/
+
+       if (nextAnchor) {
+               errorType = create_anchor(lastAnchor, nextAnchor , &pAnchor);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               (*pCommand)->private.alert.anchor = pAnchor;
+               pAnchor = NULL;
+       }
+
+       if (pCred != NULL)
+               (*pCommand)->cred = dup_cred(pCred);
+
+       (*pCommand)->private.alert.type = syncType;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+
+       if (pAnchor != NULL)
+               free_anchor(pAnchor);
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_get_command(Session *session, Location* target, const char *contenttype, Command **pCommand)
+{
+       FW_LOGV("start with content type = %s", contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_GET);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.access.item = create_item();
+       if ((*pCommand)->private.access.item == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       set_item_target((*pCommand)->private.access.item, target);
+
+       if (contenttype != NULL)
+               (*pCommand)->private.access.item->contenttype = strdup(contenttype);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+
+SA_ErrorType create_put_command(Session *session, Location *source,  const char *contenttype,
+                                                                                                       DevInf *devInf , Command **pCommand)
+{
+       FW_LOGV("start with content type = %s", contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_PUT);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.access.item = create_item_for_devinf(devInf);
+
+       if ((*pCommand)->private.access.item == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       set_item_source((*pCommand)->private.access.item, source);
+
+       if (contenttype != NULL)
+               (*pCommand)->private.access.item->contenttype = strdup(contenttype);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+
+SA_ErrorType create_results_command(Session *session, Location *source,  const char *contenttype,
+                                                                                                                       DevInf *devInf , Command **pCommand)
+{
+       FW_LOGV("start with content type = %s", contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_RESULTS);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.results.item = create_item_for_devinf(devInf);
+
+       if ((*pCommand)->private.results.item == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       set_item_source((*pCommand)->private.results.item, source);
+
+       if (contenttype != NULL)
+               (*pCommand)->private.results.item->contenttype = strdup(contenttype);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_sync_start_command(Session *session, Location *source, Location *target,  Command **pCommand)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_SYNC_START);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->source = source;
+       (*pCommand)->target = target;
+
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_sync_start_command_numberofchanges(Command *pCommand, unsigned int numberOfChanges)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (pCommand == NULL) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->private.sync.hasNumChanged = 1;
+       pCommand->private.sync.numChanged = numberOfChanges;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_sync_end_command(Command **pCommand)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       *pCommand = (Command *) calloc(1, sizeof(Command));
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->type = COMMAND_TYPE_SYNC_END;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+
+SA_ErrorType create_add_command(Session *session, ChangeType type, char *luid, const char *contenttype,
+                                                                                                               char *data, unsigned int size , int  moreData, Command **pCommand)
+{
+       FW_LOGV("start with ChangeType = %d content type = %s", type, contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Item *temp = NULL;
+       Location *pLocation = NULL;
+
+       *pCommand = __create_command(session, COMMAND_TYPE_ADD);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       temp = create_item_for_data(data, size);
+       if (!temp) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.change.type = type;
+       if (contenttype != NULL)
+               temp->contenttype = strdup(contenttype);
+       temp->moreData = moreData;
+
+       errorType = create_location(luid, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       set_item_source(temp, pLocation);
+       (*pCommand)->private.change.items = g_list_append((*pCommand)->private.change.items, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_replace_command(Session *session,  ChangeType type, char *luid, const char *contenttype,
+                                                                                                                       const char *data,  unsigned int size, int moreData,  Command **pCommand)
+{
+       FW_LOGV("start with ChangeType = %d content type = %s", type, contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Item *temp = NULL;
+       Location *pLocation = NULL;
+
+       *pCommand = __create_command(session, COMMAND_TYPE_REPLACE);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       temp = create_item_for_data(data, size);
+       if (!temp) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.change.type = type;
+       if (contenttype != NULL)
+               temp->contenttype = strdup(contenttype);
+       temp->moreData = moreData;
+
+       errorType = create_location(luid, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       set_item_source(temp, pLocation);
+       (*pCommand)->private.change.items = g_list_append((*pCommand)->private.change.items, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_delete_command(Session *session, ChangeType type, char *luid, const char *contenttype, Command **pCommand)
+{
+       FW_LOGV("start with ChangeType = %d content type = %s", type, contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Item *temp = NULL;
+       Location *pLocation = NULL;
+
+       *pCommand = __create_command(session, COMMAND_TYPE_DELETE);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       temp = create_item();
+       if (!temp) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.change.type = type;
+
+       errorType = create_location(luid, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       set_item_source(temp, pLocation);
+       if (contenttype != NULL)
+               temp->contenttype = strdup(contenttype);
+       (*pCommand)->private.change.items = g_list_append((*pCommand)->private.change.items, temp);
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+
+}
+
+SA_ErrorType create_map_command(Session *session, Location *source, Location *target, Command **pCommand)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_MAP);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->source = source;
+       (*pCommand)->target = target;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_map_command_item(Command *mapCommand, Item *temp)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!mapCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       mapCommand->private.map.items = g_list_append(mapCommand->private.map.items, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType increase_command_refcount(Command *pCommand)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->refCount++;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType decrease_command_refcount(Command *pCommand)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->refCount--;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_results_command_msgref(Command *pCommand, unsigned int msgRef)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->private.results.msgRef = msgRef;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_results_command_cmdref(Command *pCommand, unsigned int cmdRef)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->private.results.cmdRef = cmdRef;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_results_command_targetref(Command *pCommand, Location *pLocation)
+{
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       FW_LOGV("start with Command Type =%d\n", pCommand->type);
+
+       pCommand->private.results.targetRef = dup_location(pLocation);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+void free_command(Command *pCommand)
+{
+       if (!pCommand)
+               return;
+
+       FW_LOGV("start with  Command type is %d", pCommand->type);
+
+       GList *iter = NULL;
+
+       if (pCommand->refCount > 1) {
+               FW_LOGV("Command's refCount is %d", pCommand->refCount);
+               decrease_command_refcount(pCommand);
+               return;
+       }
+
+
+       switch (pCommand->type) {
+               case COMMAND_TYPE_ALERT:
+                       if (pCommand->private.alert.anchor) {
+                               free_anchor(pCommand->private.alert.anchor);
+                               pCommand->private.alert.anchor = NULL;
+                       }
+
+                       if (pCommand->private.alert.contentType) {
+                               free(pCommand->private.alert.contentType);
+                               pCommand->private.alert.contentType = NULL;
+                       }
+                       break;
+               case COMMAND_TYPE_SYNC_START:
+                       /*nothing to free*/
+                       break;
+               case COMMAND_TYPE_SYNC_END:
+                       /*nothing to free*/
+                       break;
+               case COMMAND_TYPE_PUT:
+                       if (pCommand->private.access.type) {
+                               free(pCommand->private.access.type);
+                               pCommand->private.access.type = NULL;
+                       }
+
+                       if (pCommand->private.access.item) {
+                               free_item(pCommand->private.access.item);
+                               pCommand->private.access.item = NULL;
+                       }
+                       break;
+               case COMMAND_TYPE_HEADER:
+                       /*COMMAND_TYPE_HEADER doesnot come here*/
+                       break;
+               case COMMAND_TYPE_ADD:
+               case COMMAND_TYPE_REPLACE:
+               case COMMAND_TYPE_DELETE:
+                       for (iter = pCommand->private.change.items; iter != NULL; iter = g_list_next(iter))
+                               free_item(iter->data);
+                       break;
+               case COMMAND_TYPE_MAP:
+                       for (iter = pCommand->private.map.items; iter != NULL; iter = g_list_next(iter))
+                               free_item(iter->data);
+                       break;
+               case COMMAND_TYPE_GET:
+                       if (pCommand->private.access.type) {
+                               free(pCommand->private.access.type);
+                               pCommand->private.access.type = NULL;
+                       }
+
+                       if (pCommand->private.access.item) {
+                               free_item(pCommand->private.access.item);
+                               pCommand->private.access.item = NULL;
+                       }
+                       break;
+               case COMMAND_TYPE_RESULTS:
+                       if (pCommand->private.results.type) {
+                               free(pCommand->private.results.type);
+                               pCommand->private.results.type = NULL;
+                       }
+
+                       if (pCommand->private.results.item) {
+                               free_item(pCommand->private.results.item);
+                               pCommand->private.results.item = NULL;
+                       }
+
+                       if (pCommand->private.results.targetRef) {
+                               free_location(pCommand->private.results.targetRef);
+                               pCommand->private.results.targetRef = NULL;
+                       }
+
+                       break;
+               case COMMAND_TYPE_UNKNOWN:
+                       break;
+       }
+
+       if (pCommand->source) {
+               free_location(pCommand->source);
+               pCommand->source = NULL;
+       }
+
+       if (pCommand->target) {
+               free_location(pCommand->target);
+               pCommand->target = NULL;
+       }
+
+       if (pCommand->cred) {
+               free_cred(pCommand->cred);
+               pCommand->cred = NULL;
+       }
+
+       free(pCommand);
+
+       FW_LOGV("end");
+}
+
+SA_ErrorType create_new_status_location(Session *session, OMA_StatusType data, Command *command,
+                                                                               Location *sourceref, Location *targetref, CommandType type, Status **pStatus)
+{
+       FW_LOGV("start Errortype %d", data);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       errorType = create_status(data, session->cmdID, session->lastRecievedMsgID,
+                                                                                       command->cmdID, sourceref, targetref, type, pStatus);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->cmdID++;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_new_status(Session *session, OMA_StatusType data, Command *command,
+                                                                                                       CommandType type, Status **pStatus)
+{
+       FW_LOGV("start Errortype %d", data);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       errorType = create_status(data, session->cmdID, session->lastRecievedMsgID, command->cmdID,
+                                                                                       command->source, command->target, type, pStatus);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->cmdID++;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_status(OMA_StatusType data,  unsigned int cmdID, unsigned int msgref , unsigned int cmdref,
+                                                                                       Location *sourceref, Location *targetref, CommandType type, Status **pStatus)
+{
+       FW_LOGV("start Errortype %d", data);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       *pStatus = (Status *)calloc(1, sizeof(Status));
+       if (*pStatus == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pStatus)->cmdID = cmdID;
+       (*pStatus)->msgRef = msgref;
+       (*pStatus)->cmdRef = cmdref;
+       (*pStatus)->type = type;
+
+       if (data)
+               (*pStatus)->data = g_strdup_printf("%i", data);
+
+       if (sourceref)
+               (*pStatus)->sourceRef = dup_location(sourceref);
+
+       if (targetref)
+               (*pStatus)->targetRef = dup_location(targetref);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+void free_statuses(GList *status)
+{
+       FW_LOGV("start");
+
+       if (!status) {
+               FW_LOGV("List is null");
+               return;
+       }
+
+       GList *iter = NULL;
+       FW_LOGV("count : %d", g_list_length(status));
+       for (iter = status; iter != NULL; iter = g_list_next(iter))
+               free_status(iter->data);
+
+       g_list_free(status);
+
+       FW_LOGV("end");
+}
+
+void free_status(Status *pStatus)
+{
+       FW_LOGV("start");
+
+       if (!pStatus)
+               return;
+
+       if (pStatus->data)
+               free(pStatus->data);
+
+       if (pStatus->sourceRef)
+               free_location(pStatus->sourceRef);
+
+       if (pStatus->targetRef)
+               free_location(pStatus->targetRef);
+
+       if (pStatus->cred)
+               free_cred(pStatus->cred);
+
+       if (pStatus->chal)
+               free_chal(pStatus->chal);
+
+       free_item(pStatus->item);
+
+       free(pStatus);
+       pStatus = NULL;
+
+       FW_LOGV("end");
+}
+
+OMA_StatusType get_status_code(Status *status)
+{
+       return atoi(status->data);
+}
+
+CommandType convert_command_type(char *type)
+{
+       CommandType commandType = COMMAND_TYPE_UNKNOWN;
+       if (!type)
+               return commandType;
+
+       if (!strcmp(type, "Alert")) {
+               commandType = COMMAND_TYPE_ALERT;
+       } else if (!strcmp(type, "Sync")) {
+               commandType = COMMAND_TYPE_SYNC_START;
+       } else if (!strcmp(type, "Put")) {
+               commandType = COMMAND_TYPE_PUT;
+       } else if (!strcmp(type, "SyncHdr")) {
+               commandType = COMMAND_TYPE_HEADER;
+       } else if (!strcmp(type, "Add")) {
+               commandType = COMMAND_TYPE_ADD;
+       } else if (!strcmp(type, "Replace")) {
+               commandType = COMMAND_TYPE_REPLACE;
+       } else if (!strcmp(type, "Map")) {
+               commandType = COMMAND_TYPE_MAP;
+       } else if (!strcmp(type, "Delete")) {
+               commandType = COMMAND_TYPE_DELETE;
+       } else if (!strcmp(type, "Results")) {
+               commandType = COMMAND_TYPE_RESULTS;
+       } else if (!strcmp(type, "Get")) {
+               commandType = COMMAND_TYPE_GET;
+       }
+
+       return commandType;
+}
+
+ChangeType convert_change_type_command_type(CommandType type)
+{
+       ChangeType changeType = CHANGE_UNKNOWN;
+       switch (type) {
+       case COMMAND_TYPE_UNKNOWN:
+       case COMMAND_TYPE_ALERT:
+       case COMMAND_TYPE_SYNC_START:
+       case COMMAND_TYPE_SYNC_END:
+       case COMMAND_TYPE_PUT:
+       case COMMAND_TYPE_HEADER:
+       case COMMAND_TYPE_MAP:
+       case COMMAND_TYPE_GET:
+       case COMMAND_TYPE_RESULTS:
+               /*never comes these commands*/
+               break;
+       case COMMAND_TYPE_ADD:
+               changeType = CHANGE_ADD;
+               break;
+       case COMMAND_TYPE_REPLACE:
+               changeType = CHANGE_REPLACE;
+               break;
+       case COMMAND_TYPE_DELETE:
+               changeType = CHANGE_DELETE;
+               break;
+
+       }
+       return changeType;
+}
+
+CommandType convert_command_type_change_type(ChangeType type)
+{
+       CommandType commandType = COMMAND_TYPE_UNKNOWN;
+
+       switch (type) {
+       case CHANGE_UNKNOWN:
+               commandType = COMMAND_TYPE_UNKNOWN;
+               break;
+       case CHANGE_ADD:
+               commandType = COMMAND_TYPE_ADD;
+               break;
+       case CHANGE_REPLACE:
+               commandType = COMMAND_TYPE_REPLACE;
+               break;
+       case CHANGE_DELETE:
+               commandType = COMMAND_TYPE_DELETE;
+               break;
+       }
+
+       return commandType;
+
+}
+/*
+ChangeType convertToChangeType(unsigned int type) {
+
+       ChangeType changeType=CHANGE_UNKNOWN;
+       switch (type) {
+       case 1:
+               changeType = CHANGE_ADD;
+               break;
+       case 2:
+               changeType = CHANGE_REPLACE;
+               break;
+       case 3:
+               changeType = CHANGE_DELETE;
+               break;
+       }
+
+       return changeType;
+}
+
+
+char *convertFromCommandType(CommandType type) {
+       char *commandType=NULL;
+
+       switch (type) {
+       case COMMAND_TYPE_ALERT:
+               commandType = "Alert";
+               break;
+       case COMMAND_TYPE_SYNC_START:
+       case COMMAND_TYPE_SYNC_END:
+               commandType = "Sync";
+               break;
+       case COMMAND_TYPE_PUT:
+               commandType = "Put";
+               break;
+       case COMMAND_TYPE_HEADER:
+               commandType = "SyncHdr";
+               break;
+       case COMMAND_TYPE_ADD:
+               commandType = "Add";
+               break;
+       case COMMAND_TYPE_REPLACE:
+               commandType = "Replace";
+               break;
+       case COMMAND_TYPE_MAP:
+               commandType = "Map";
+               break;
+       case COMMAND_TYPE_DELETE:
+               commandType = "Delete";
+               break;
+       case COMMAND_TYPE_RESULTS:
+               commandType = "Results";
+               break;
+       case COMMAND_TYPE_GET:
+               commandType = "Get";
+               break;
+       default:
+               commandType="UNKNOWN";
+       }
+       return commandType;
+}
+*/
diff --git a/ServiceAdapter/SA_Common_Interface.c b/ServiceAdapter/SA_Common_Interface.c
new file mode 100644 (file)
index 0000000..b335c85
--- /dev/null
@@ -0,0 +1,2680 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Common_Interface.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of interface of Service Adapter
+ */
+
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/DACI/DACI_Service.h"
+#include "agent-framework/NetworkAccess/NACI.h"
+#include "agent-framework/EngineController/task_process.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/Device/EXT_DCI_DevInfo.h"
+#include "Common/Common_Vconf.h"
+#include "Common/Common_Define.h"
+#include "Common/Common_Util.h"
+#include "ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.h"
+#include "ServiceAdapter/NetworkBinder/NA_Binder.h"
+#include "ServiceAdapter/SA_Define.h"
+#include "ServiceAdapter/SA_Common_Interface.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Command.h"
+#include "ServiceAdapter/SA_Command_Internal.h"
+#include "ServiceAdapter/SA_Session.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+#include "ServiceAdapter/SA_DevInf_Internal.h"
+#include "ServiceAdapter/SA_Util.h"
+#include "ServiceAdapter/SA_DevInf.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+Session *session = NULL;
+
+static SA_ErrorType __get_accountinfo(int accountId, char **id, char **pwd, char **serverUrl, char **nextNonce);
+static SA_ErrorType __object_binder(SyncML *pSyncML, char **msg, unsigned int *msg_size);
+static SA_ErrorType __reverse_object_binder(SyncML **pSyncML, char *recv_msg, unsigned int recv_msg_length);
+static SA_ErrorType __generate_presync_msg(int accountId, char *sessionId,  char **msg, unsigned int *msg_size);
+static SA_ErrorType __generate_msg(void **syncObj, char **msg , unsigned int *msg_size);
+static SA_ErrorType __generate_msg_status_map_command(Session **pSession, SyncObj **syncObj,
+                                                                                                                                                                                       GList **commands, GList **commands_last);
+static SA_ErrorType __generate_msg_exist_sending_map_command(protocol_binder *pBinder, Session **pSession,
+                                                                                                                                                                                                               GList **commands, GList **commands_last);
+static SA_ErrorType __generate_msg_changes_command(protocol_binder *pBinder, Session **pSession, SyncObj **sync,
+                                                                                                                                                                       GList **commands, GList **commands_last, bool *isNeedNextMsg);
+static SA_ErrorType __generate_autoconfigure_msg(char *id, char *pwd, char *targetUrl, char **msg,
+                                                                                                                                                               unsigned int *msg_size, Session *pSession);
+static SA_ErrorType __exchange_msg(char *accType, int transportType, char *targetUri, unsigned int session_id,
+                                                                                                               GList *header_info, char *sendMsg, unsigned int sendMsg_length, GList **recv_header,
+                                                                                                               char **recvMsg, unsigned int *recvMsg_length);
+static SA_ErrorType __process_recv_msg(char *recvMsg, unsigned int recvMsg_length, void **syncReturnObj, int *isFinish);
+static SA_ErrorType __process_autoconfigure_recv_msg(char *recvMsg, unsigned int recvMsg_length, Session *pSession);
+static Common_ErrorType __convert_error_type(SA_ErrorType errorType);
+static void __clean_up_SA();
+
+static SA_ErrorType __get_accountinfo(int accountId, char **id, char **pwd, char **serverUrl, char **nextNonce)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       char *value = NULL;
+       bool result;
+
+       if (!accountId) {
+               errorType = SA_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       *id = DACI_Get_Account_Email_Address(accountId);
+       if (*id == NULL) {
+               errorType = SA_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       *pwd = DACI_Get_Account_Password(accountId);
+       if (*pwd == NULL) {
+               errorType = SA_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       result = get_config(accountId,  DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, &value);
+       if (result == true)
+               *serverUrl = value;
+       else{
+               FW_LOGE("failed in get_Config");
+               errorType = SA_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       if (*serverUrl == NULL) {
+               errorType = SA_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       result = get_config(accountId,  DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, &value);
+       if (result == true)
+               *nextNonce = value;
+       else{
+               FW_LOGE("failed in get_Config");
+               errorType = SA_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __generate_presync_msg(int accountId, char *sessionId,  char **msg, unsigned int *msg_size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       char *id = NULL;
+       char *pwd = NULL;
+       char *sourceUrl = NULL;
+       char *targetUrl = NULL;
+       char *nextNonce = NULL;
+       char *credData = NULL;
+       char *decoded_nonce = NULL;
+
+       /*pkg1  always has final tag*/
+       int isFinal = 1;
+
+       SyncHdr *pSyncHdr = NULL;
+       Cred *pCred = NULL;
+       DevInf *devInfObj = NULL;
+       SyncML *pSyncML = NULL;
+
+       /*case SAN, MUST use sessionid from SAN message..*/
+       if (!sessionId) {
+               sessionId = g_strdup_printf("%ld", time(NULL));
+               if (sessionId == NULL) {
+                       errorType = SA_INTERNAL_NO_MEMORY;
+                       goto error;
+               }
+       }
+
+       DCI_RETURN err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &sourceUrl);
+       if (err != DCI_SUCCESS) {
+               FW_LOGE("failed to get devinfo");
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       errorType = __get_accountinfo(accountId, &id, &pwd, &targetUrl, &nextNonce);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("id = %s", id);
+       FW_LOGV("pwd = %s",  pwd);
+       FW_LOGV("sessionId = %s", sessionId);
+       FW_LOGV("sourceUrl = %s", sourceUrl);
+       FW_LOGV("serverUrl = %s", targetUrl);
+
+       Chal *pTempChal = NULL;
+       if (session != NULL) {
+               if (session->chal != NULL)
+                       pTempChal = dup_chal(session->chal);
+
+               free_session(session);
+               session = NULL;
+       }
+
+       /* create session info */
+       errorType = create_session(VERSION_12, PROTOCOL_TYPE_DS, accountId, sessionId, sourceUrl, targetUrl, &session);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create session");
+               goto error;
+       }
+
+       if (pTempChal != NULL) {
+               session->chal = pTempChal;
+               pTempChal = NULL;
+       }
+
+       /* set pkg status */
+       session->pkgStatus = SYNCML_PKG_1;
+
+       Chal *chal = session->chal;
+       AuthType authType;
+       FormatType formatType = FORMAT_TYPE_UNKNOWN;
+       unsigned int nonce_size = 0;
+       if (!chal) {
+               FW_LOGV("CHAL DOES NOT EXIST");
+               if (nextNonce) {
+                       /*server sent nonce info in previous sync session*/
+                       authType = AUTH_TYPE_MD5;
+                       decoded_nonce = (char *)g_base64_decode(nextNonce, &nonce_size);
+                       formatType = FORMAT_TYPE_BASE64;
+               } else{
+                       authType = AUTH_TYPE_BASIC;
+                       formatType = FORMAT_TYPE_BASE64;
+               }
+
+               errorType = create_cred_string(authType,  id, pwd, decoded_nonce, nonce_size, &credData);
+
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed to create cred string");
+                       goto error;
+               }
+
+               errorType = create_cred(id, pwd, authType, formatType, credData,  &pCred);
+       } else{
+               FW_LOGV("CHAL DOES  EXIST");
+               if (chal->type == AUTH_TYPE_MD5) {
+                       if (chal->format == FORMAT_TYPE_BASE64)
+                               decoded_nonce = (char *)g_base64_decode(chal->nonce_b64, &nonce_size);
+                       else{
+                               if (chal->nonce_plain != NULL) {
+                                       decoded_nonce = strdup(chal->nonce_plain);
+                                       nonce_size = chal->nonce_length;
+                               }
+                       }
+               }
+
+               errorType = create_cred_string(chal->type, id, pwd, decoded_nonce, nonce_size, &credData);
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed to create cred string");
+                       goto error;
+               }
+
+               errorType = create_cred(id, pwd, chal->type, FORMAT_TYPE_BASE64, credData , &pCred);
+       }
+
+       if (credData != NULL) {
+               free(credData);
+               credData = NULL;
+       }
+
+       if (decoded_nonce != NULL) {
+               free(decoded_nonce);
+               decoded_nonce = NULL;
+       }
+
+       if (nextNonce != NULL) {
+               free(nextNonce);
+               nextNonce = NULL;
+       }
+       nonce_size = 0;
+
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create cred");
+               goto error;
+       }
+
+       set_session_cred(session, pCred);
+       pCred = NULL;
+
+       /* create SyncHdr */
+       errorType = create_synchdr(session , &pSyncHdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create synchdr");
+               goto error;
+       }
+
+       /* create devInf */
+       errorType = create_devinf(session, &devInfObj);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create devInf");
+               goto error;
+       }
+
+       set_session_devinf(session, devInfObj);
+       devInfObj = NULL;
+
+       GList *commands = NULL;
+       GList *commands_last = NULL;
+
+       char *sourceDevInf = NULL;
+       if (session->protocolVersion == VERSION_10)
+               sourceDevInf = ELEMENT_DEVINF_10;
+       else if (session->protocolVersion == VERSION_11)
+               sourceDevInf = ELEMENT_DEVINF_11;
+       else if (session->protocolVersion == VERSION_12)
+               sourceDevInf = ELEMENT_DEVINF_12;
+
+
+       /* create Put command */
+       /*
+       Command *pPutCommand = NULL;
+       Location *pLocation = NULL;
+
+       errorType = create_Location(sourceDevInf, NULL, &pLocation);
+       if (errorType != ERROR_INTERNAL_OK)
+               goto error;
+
+       errorType = create_Put_Command(session, pLocation, ELEMENT_DEVINF_XML, devInfObj , &pPutCommand);
+       if (errorType !=ERROR_INTERNAL_OK)
+               goto error;
+       putIntoList(&commands, &commands_last, pPutCommand);
+       */
+
+
+       /* create Get command */
+       Command *pGetCommand = NULL;
+       Location *pLocation = NULL;
+       errorType = create_location(sourceDevInf, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create location");
+               goto error;
+       }
+
+       char *contentType = NULL;
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               contentType = ELEMENT_DEVINF_XML;
+       else
+               contentType = ELEMENT_DEVINF_WBXML;
+
+       errorType = create_get_command(session, pLocation, contentType, &pGetCommand);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create get command");
+               goto error;
+       }
+       put_into_list(&commands, &commands_last, pGetCommand);
+
+       Command *pAlertCommand = NULL;
+       Location *pSourceLocation = NULL;
+       Location *pTargetLocation = NULL;
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
+                       errorType = create_location(datastoreinfo_per_content_type[content_type]->source, NULL, &pSourceLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+
+                               /* change errorType because locURI is required so need to return SA_INTERNAL_MISCONFIGURATION error
+                                       when SA_INTERNAL_NOT_DEFINED error case*/
+                               if (errorType == SA_INTERNAL_NOT_DEFINED)
+                                       errorType = SA_INTERNAL_MISCONFIGURATION;
+
+                               goto error;
+                       }
+
+                       errorType = create_location(datastoreinfo_per_content_type[content_type]->target, NULL, &pTargetLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+
+                               /* change errorType because locURI is required so need to return SA_INTERNAL_MISCONFIGURATION error
+                                       when SA_INTERNAL_NOT_DEFINED error case*/
+                               if (errorType == SA_INTERNAL_NOT_DEFINED)
+                                       errorType = SA_INTERNAL_MISCONFIGURATION;
+                               goto error;
+                       }
+
+                       if (datastoreinfo_per_content_type[content_type]->id && datastoreinfo_per_content_type[content_type]->pw) {
+
+                               /*FIXME is there a nextNonce for datastore ??*/
+                               if (nextNonce) {
+                                       /*server sent nonce info in previous sync session*/
+                                       authType = AUTH_TYPE_MD5;
+                                       decoded_nonce = (char *)g_base64_decode(nextNonce, &nonce_size);
+                               } else{
+                                       authType = AUTH_TYPE_BASIC;
+                                       formatType = FORMAT_TYPE_BASE64;
+                               }
+
+                               errorType = create_cred_string(authType,  datastoreinfo_per_content_type[content_type]->id,
+                                                                                       datastoreinfo_per_content_type[content_type]->pw, decoded_nonce, nonce_size, &credData);
+                               if (errorType != SA_INTERNAL_OK) {
+                                       FW_LOGE("failed to create cred string");
+                                       goto error;
+                               }
+
+                               errorType = create_cred(id, pwd, authType, FORMAT_TYPE_BASE64, credData,  &pCred);
+
+                               if (credData != NULL) {
+                                       free(credData);
+                                       credData = NULL;
+                               }
+                       }
+
+                       errorType = create_alert_command(session, datastoreinfo_per_content_type[content_type]->clientSyncType,
+                                                                               pSourceLocation, pTargetLocation, datastoreinfo_per_content_type[content_type]->lastAnchorClient,
+                                                                               datastoreinfo_per_content_type[content_type]->nextAnchorClient, pCred, &pAlertCommand);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create alert command");
+                               goto error;
+                       }
+               } else
+                       continue;
+               put_into_list(&commands, &commands_last, pAlertCommand);
+       }
+
+
+       errorType = create_syncml(pSyncHdr, NULL, commands, isFinal, &pSyncML);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create syncml");
+               goto error;
+       }
+
+       session->isSendingfinal = isFinal;
+       if (isFinal)
+               session->pkgStatus = SYNCML_PKG_2;
+
+       /* convert Msg */
+       errorType = __object_binder(pSyncML, msg, msg_size);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in objectBinder");
+               goto error;
+       }
+
+       /*free generate structure*/
+       free_syncml(pSyncML);
+
+       if (id)
+               free(id);
+       if (pwd)
+               free(pwd);
+       if (sessionId)
+               free(sessionId);
+       if (sourceUrl)
+               free(sourceUrl);
+       if (targetUrl)
+               free(targetUrl);
+       if (nextNonce)
+               free(nextNonce);
+       if (pCred != NULL)
+               free_cred(pCred);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+
+       if (credData != NULL)
+               free(credData);
+
+       if (id)
+               free(id);
+       if (pwd)
+               free(pwd);
+       if (sessionId)
+               free(sessionId);
+       if (sourceUrl)
+               free(sourceUrl);
+       if (targetUrl)
+               free(targetUrl);
+       if (nextNonce)
+               free(nextNonce);
+       if (pSyncML)
+               free_syncml(pSyncML);
+       if (pSyncHdr)
+               free_synchdr(pSyncHdr);
+       if (pCred)
+               free_cred(pCred);
+
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __generate_msg(void **syncObj, char **msg , unsigned int *msg_size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       bool isNeedNextMsg = false;
+
+       Binder_function_set *pBinder_function_set = NULL;
+
+       PROTOCOL_BINDER_ERROR err = init_oma_ds_1_2_binder_function_set(&pBinder_function_set);
+
+       protocol_binder *pBinder = NULL;
+       pBinder = oma_ds_1_2_binder_init(pBinder, COMMUNICATION_TYPE, false, false, false, true, pBinder_function_set);
+
+       /* create SyncHdr */
+       SyncHdr *pSyncHdr = NULL;
+       errorType = create_synchdr(session , &pSyncHdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create synchdr");
+               goto error;
+       }
+
+       err = oma_ds_1_2_binder_append(pBinder, PE_SYNCML_START, NULL);
+       err = oma_ds_1_2_binder_append(pBinder, PE_HEADER, pSyncHdr);
+       err = oma_ds_1_2_binder_append(pBinder, PE_BODY_START, NULL);
+
+       SyncObj **sync = (SyncObj **)syncObj;
+       GList *commands = NULL;
+       GList *commands_last = NULL;
+       int isFinal = 0;
+
+       errorType = __generate_msg_status_map_command(&session, sync, &commands, &commands_last);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in __generate_msg_status_map_command");
+               goto error;
+       }
+
+       /*append status command*/
+       GList *status_iter = NULL;
+       Status *pStatus = NULL;
+       for (status_iter = session->status; status_iter != NULL; status_iter = g_list_next(status_iter)) {
+               pStatus = (Status *)status_iter->data;
+               err = oma_ds_1_2_binder_append(pBinder, PE_STATUS, pStatus);
+       }
+
+       /*append results command*/
+       GList *results_iter = NULL;
+       Command *pResultsCommand = NULL;
+       for (results_iter = session->resultsCommand; results_iter != NULL; results_iter = g_list_next(results_iter)) {
+               pResultsCommand = (Command *)results_iter->data;
+               put_into_list(&commands, &commands_last, pResultsCommand);
+               err = oma_ds_1_2_binder_append(pBinder, PE_RESULTS_START, pResultsCommand);
+
+               if (pResultsCommand->type == COMMAND_TYPE_RESULTS) {
+                       if (pResultsCommand->private.results.item) {
+                               if (pResultsCommand->private.results.item->dataType == ITEM_DEVINF) {
+                                       err = oma_ds_1_2_binder_append(pBinder, PE_DEVINF, pResultsCommand->private.results.item);
+                               }
+                       }
+
+                       err = oma_ds_1_2_binder_append(pBinder, PE_RESULTS_END, NULL);
+               }
+       }
+
+       /*append map command*/
+       GList *map_iter = NULL;
+       Command *pMapCommand = NULL;
+       for (map_iter = session->mapCommand; map_iter != NULL; map_iter = g_list_next(map_iter)) {
+               pMapCommand = (Command *)map_iter->data;
+               err = oma_ds_1_2_binder_append(pBinder, PE_MAP, pMapCommand);
+       }
+
+       /* free sendgStatus structure from SE*/
+       free_sendingstatuses((*sync)->sendingStatus);
+       (*sync)->sendingStatus = NULL;
+
+       if (session->pkgStatus == SYNCML_PKG_3) {
+
+               errorType = __generate_msg_exist_sending_map_command(pBinder, &session, &commands, &commands_last);
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed in __generate_msg_status_map_command");
+                       goto error;
+               }
+
+               errorType = __generate_msg_changes_command(pBinder, &session, sync, &commands, &commands_last, &isNeedNextMsg);
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed in __generate_msg_status_map_command");
+                       goto error;
+               }
+
+               if (!isNeedNextMsg)
+                       isFinal = 1;
+       }
+
+       if (session->pkgStatus == SYNCML_PKG_5 && session->isReceivingFinal)
+               isFinal = 1;
+
+       /*if we have to send alert command(222,223 etc)*/
+       GList *alert_iter = NULL;
+       Command *pAlertCommand = NULL;
+       for (alert_iter = session->alertCommand; alert_iter != NULL; alert_iter = g_list_next(alert_iter)) {
+               pAlertCommand = alert_iter->data;
+               put_into_list(&commands, &commands_last, pAlertCommand);
+               err = oma_ds_1_2_binder_append(pBinder, PE_ALERT, pAlertCommand);
+       }
+
+       if (isFinal)
+               err = oma_ds_1_2_binder_append(pBinder, PE_FINAL, NULL);
+
+       session->isSendingfinal = isFinal;
+
+       err = oma_ds_1_2_binder_append(pBinder, PE_BODY_END, NULL);
+       err = oma_ds_1_2_binder_append(pBinder, PE_SYNCML_END, NULL);
+
+       oma_ds_1_2_binder_get_stream(pBinder, msg, msg_size);
+       FW_LOGV("final msg size = %d",   *msg_size);
+
+       /*FIXME for debugging*/
+       char *xml = NULL;
+       unsigned int xml_len = 0;
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               set_xml_to_file(*msg, OMA_DS_MSG_PATH);
+       else{
+               err = protocol_binder_get_xml_for_debugging(pBinder, &xml, &xml_len);
+               if (err == PROTOCOL_BINDER_OK) {
+                       set_xml_to_file(xml, OMA_DS_MSG_PATH);
+
+                       if (xml != NULL) {
+                               free(xml);
+                               xml = NULL;
+                       }
+               }
+       }
+
+       oma_ds_1_2_binder_terminate(pBinder);
+
+       if (session->pkgStatus == SYNCML_PKG_3 && session->isSendingfinal)
+               session->pkgStatus = SYNCML_PKG_4;
+       else if (session->pkgStatus == SYNCML_PKG_5 && session->isSendingfinal)
+               session->pkgStatus = SYNCML_PKG_6;
+
+       free_synchdr(pSyncHdr);
+       if (session->status != NULL) {
+               free_statuses(session->status);
+               session->status = NULL;
+       }
+       free_commands(commands);
+
+       session->status = NULL;
+       session->alertCommand = NULL;
+       session->resultsCommand = NULL;
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+
+       free_synchdr(pSyncHdr);
+       if (session->status != NULL) {
+               free_statuses(session->status);
+               session->status = NULL;
+       }
+       free_commands(commands);
+
+       return errorType;
+}
+
+static SA_ErrorType __generate_msg_status_map_command(Session **pSession, SyncObj **sync, GList **commands, GList **commands_last)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       DACI_RETURN da_err  = DACI_SUCCESS;
+
+       GList *iter = NULL;
+       SendingStatus *sendingStatus = NULL;
+       /* send status of sync, add, replace, delete command */
+       for (iter = (*sync)->sendingStatus; iter != NULL; iter = g_list_next(iter)) {
+               sendingStatus = (iter->data);
+
+               int needMap = 0;
+               GList *sendingIter = NULL;
+               AppliedStatus *appliedStatus = NULL;
+               for (sendingIter = sendingStatus->items; sendingIter != NULL; sendingIter = g_list_next(sendingIter)) {
+                       appliedStatus = (sendingIter->data);
+
+                       /* set data in status of add, replace, delete command */
+                       GList *statusIter = NULL;
+                       Status *status = NULL;
+                       for (statusIter = (*pSession)->tempStatus; statusIter != NULL; statusIter = g_list_next(statusIter)) {
+                               status = statusIter->data;
+
+                               if (status->type == COMMAND_TYPE_ADD ||
+                                               status->type == COMMAND_TYPE_REPLACE ||
+                                               status->type == COMMAND_TYPE_DELETE) {
+
+                                       /* if there is a status for add command it have to be checked
+                                       because map command has to be generated
+                                       otherwise replace, delete command doesnot need to generate map command*/
+                                       if (status->type == COMMAND_TYPE_ADD)
+                                               needMap = 1;
+
+                                       if (status->sourceRef) {
+                                               /*add command*/
+                                               char *guid = NULL;
+                                               guid = DACI_Get_Mapping_Guid((*pSession)->accountId,  appliedStatus->luid);
+                                               if (guid == NULL) {
+                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                       FW_LOGE("failed to get guid");
+                                                       goto error;
+                                               }
+                                               if (strcmp(guid, get_location_locuri(status->sourceRef)) == 0) {
+                                                       status->data = g_strdup_printf("%i", appliedStatus->status);
+                                                       /*move to status list from tempStatus*/
+                                                       (*pSession)->status = g_list_append((*pSession)->status, status);
+                                                       (*pSession)->tempStatus = g_list_remove((*pSession)->tempStatus, status);
+
+                                                       if (guid) {
+                                                               free(guid);
+                                                               guid = NULL;
+                                                       }
+
+                                                       break;
+                                               }
+
+                                               if (guid) {
+                                                       free(guid);
+                                                       guid = NULL;
+                                               }
+                                       }
+
+                                       if (status->targetRef) {
+                                               /*replace, delete*/
+                                               if (strcmp(appliedStatus->luid, get_location_locuri(status->targetRef)) == 0) {
+                                                       status->data = g_strdup_printf("%i", appliedStatus->status);
+                                                       /*move to status list from tempStatus*/
+                                                       (*pSession)->status = g_list_append((*pSession)->status, status);
+                                                       (*pSession)->tempStatus = g_list_remove((*pSession)->tempStatus, status);
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               if (needMap) {
+                       /* create map command */
+                       Command *mapCommand = NULL;
+                       Location *pSourceLocation = NULL;
+                       Location *pTargetLocation = NULL;
+                       errorType = create_location(sendingStatus->source, NULL, &pSourceLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_location(sendingStatus->target, NULL, &pTargetLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_map_command(*pSession, pSourceLocation, pTargetLocation, &mapCommand);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create map command");
+                               goto error;
+                       }
+
+                       GList *sendingIter = NULL;
+                       AppliedStatus *appliedStatus = NULL;
+
+                       for (sendingIter = sendingStatus->items; sendingIter != NULL; sendingIter = g_list_next(sendingIter)) {
+                               appliedStatus = (sendingIter->data);
+
+                               if (appliedStatus->changeType == CHANGE_ADD) {
+
+                                       if (appliedStatus->status == ITEM_ADDED) {
+                                               Item *temp = create_item();
+                                               if (!temp) {
+                                                       FW_LOGE("failed to create item");
+                                                       errorType = SA_INTERNAL_NO_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               errorType = create_location(appliedStatus->luid, NULL, &pSourceLocation);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed to create location");
+                                                       goto error;
+                                               }
+
+                                               char *guid = NULL;
+                                               guid = DACI_Get_Mapping_Guid((*pSession)->accountId,  appliedStatus->luid);
+                                               if (guid == NULL) {
+                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                       FW_LOGE("failed to get guid");
+                                                       goto error;
+                                               }
+                                               errorType = create_location(guid, NULL, &pTargetLocation);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed to create location");
+                                                       goto error;
+                                               }
+
+                                               if (guid) {
+                                                       free(guid);
+                                                       guid = NULL;
+                                               }
+
+                                               set_item_source(temp, pSourceLocation);
+                                               set_item_target(temp, pTargetLocation);
+                                               set_map_command_item(mapCommand, temp);
+                                       } else{
+                                               da_err = DACI_Delete_Mapping_By_Luid((*pSession)->accountId,  appliedStatus->luid);
+                                               if (da_err != DACI_SUCCESS) {
+                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                       FW_LOGE("failed in DACI_Delete_Mapping_By_Luid");
+                                                       goto error;
+                                               }
+                                       }
+                               }
+                       }
+                       put_into_list(commands, commands_last, mapCommand);
+                       (*pSession)->mapCommand = g_list_append((*pSession)->mapCommand, mapCommand);
+                       increase_command_refcount(mapCommand);
+               }
+       }
+
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __generate_msg_exist_sending_map_command(protocol_binder *pBinder, Session **pSession,
+                                                                                                                                                                                                               GList **commands, GList **commands_last)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /*if there is something in the mapping_tbl it have to be sent before sync command*/
+       int existSendingMap = DACI_IsExist_Mapping_By_Account_Id(session->accountId);
+
+       if (existSendingMap) {
+               int count = 0;
+               daci_mapping *pDaci_mapping = DACI_Get_Mapping_By_Account_Id((*pSession)->accountId, &count);
+               FW_LOGV("count = %d", count);
+
+               Location *pSourceLocation = NULL;
+               Location *pTargetLocation = NULL;
+
+               bool exist = false;
+               int content_type;
+               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+                       FW_LOGV("datastoreinfo_per_content_type[%d]->datastore_id = %d", content_type, datastoreinfo_per_content_type[content_type]->datastore_id);
+
+                       if(datastoreinfo_per_content_type[content_type]->clientSyncType){
+                               if (pDaci_mapping[0].data_store_id == datastoreinfo_per_content_type[content_type]->datastore_id) {
+                                       errorType = create_location(datastoreinfo_per_content_type[content_type]->source, NULL, &pSourceLocation);
+                                       if (errorType != SA_INTERNAL_OK) {
+                                               FW_LOGE("failed to create location");
+                                               goto error;
+                                       }
+
+                                       errorType = create_location(datastoreinfo_per_content_type[content_type]->target, NULL , &pTargetLocation);
+                                       if (errorType != SA_INTERNAL_OK) {
+                                               FW_LOGE("failed to create location");
+                                               goto error;
+                                       }
+
+                                       exist = true;
+                                       break;
+                               }
+                       }
+               }
+
+               if (exist == false) {
+                       FW_LOGV("Mapping data is not equal with any synchronizing datastore id");
+                       goto error;
+               }
+
+               /* create map command using first item */
+               Command *mapCommand = NULL;
+               errorType = create_map_command(*pSession, pSourceLocation, pTargetLocation, &mapCommand);
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed to create map command");
+                       goto error;
+               }
+
+               int lastItemTypeId = pDaci_mapping[0].data_store_id;
+               int i;
+               for (i = 0; i < count; i++) {
+                       if (lastItemTypeId != pDaci_mapping[i].data_store_id) {
+                               err = oma_ds_1_2_binder_append(pBinder, PE_MAP, mapCommand);
+                               put_into_list(commands, commands_last, mapCommand);
+                               (*pSession)->mapCommand = g_list_append((*pSession)->mapCommand, mapCommand);
+                               increase_command_refcount(mapCommand);
+
+                               bool exist = false;
+                               int content_type;
+                               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+
+                                       if(datastoreinfo_per_content_type[content_type]->clientSyncType){
+                                               if (pDaci_mapping[0].data_store_id == datastoreinfo_per_content_type[content_type]->datastore_id) {
+                                                       errorType = create_location(datastoreinfo_per_content_type[content_type]->source, NULL, &pSourceLocation);
+                                                       if (errorType != SA_INTERNAL_OK) {
+                                                               FW_LOGE("failed to create location");
+                                                               goto error;
+                                                       }
+
+                                                       errorType = create_location(datastoreinfo_per_content_type[content_type]->target, NULL , &pTargetLocation);
+                                                       if (errorType != SA_INTERNAL_OK) {
+                                                               FW_LOGE("failed to create location");
+                                                               goto error;
+                                                       }
+
+                                                       exist = true;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               if (exist == false) {
+                                       FW_LOGE("Mapping data is not equal with any synchronizing datastore id");
+                                       goto error;
+                               }
+                       }
+                       lastItemTypeId = pDaci_mapping[i].data_store_id;
+                       Item *temp = create_item();
+                       if (!temp) {
+                               FW_LOGE("failed to create item");
+                               errorType = SA_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+                       errorType = create_location(pDaci_mapping[i].luid, NULL, &pSourceLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_location(pDaci_mapping[i].guid, NULL, &pTargetLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       set_item_source(temp, pSourceLocation);
+                       set_item_target(temp, pTargetLocation);
+                       set_map_command_item(mapCommand, temp);
+               }
+
+               DACI_Free_Memory_Mapping(pDaci_mapping, count);
+
+               err = oma_ds_1_2_binder_append(pBinder, PE_MAP, mapCommand);
+               put_into_list(commands, commands_last, mapCommand);
+               (*pSession)->mapCommand = g_list_append((*pSession)->mapCommand, mapCommand);
+               increase_command_refcount(mapCommand);
+       }
+
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+
+}
+
+static SA_ErrorType __generate_msg_changes_command(protocol_binder *pBinder, Session **pSession, SyncObj **sync,
+                                                                                                                                                                       GList **commands, GList **commands_last, bool *isNeedNextMsg)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       DACI_RETURN da_err  = DACI_SUCCESS;
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       unsigned int stream_size = 0;
+
+       char *data = NULL;      /*have to be freed*/
+       char *sendingData = NULL;
+
+       /* generate sync , add, replace, delete command when there is a item in ChangedDatastore */
+       GList *iter = NULL;
+       Command *syncCommand = NULL;
+       ChangedDatastore *changedDatastore = NULL;
+       bool needNextMsg = false;
+       for (iter = (*sync)->changedDatastore; iter != NULL; iter = g_list_next(iter)) {
+               changedDatastore = (iter->data);
+
+               if (changedDatastore->needSyncCommand) {
+                       /* create sync Command */
+                       Location *pSourceLocation = NULL;
+                       Location *pTargetLocation = NULL;
+                       errorType = create_location(changedDatastore->source, NULL, &pSourceLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_location(changedDatastore->target, NULL, &pTargetLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_sync_start_command(*pSession, pSourceLocation, pTargetLocation, &syncCommand);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create sync start command");
+                               goto error;
+                       }
+
+                       /*set numberOfChanges */
+                       if (changedDatastore->hasNumberOfChanges) {
+                               /*if it is first sync command set numberOfChanges*/
+                               set_sync_start_command_numberofchanges(syncCommand, changedDatastore->numberOfChanges);
+                               changedDatastore->hasNumberOfChanges = 0;
+                       }
+
+                       err = oma_ds_1_2_binder_append(pBinder, PE_SYNC_START, syncCommand);
+                       put_into_list(commands, commands_last, syncCommand);
+
+                       GList *itemIter = NULL;
+                       Command *changeCommand = NULL;
+                       ChangedItem *changedItem = NULL;
+                       OMA_DS_Protocol_Element protocol_element = PE_UNDEF;
+                       for (itemIter = changedDatastore->changeItem; itemIter != NULL;) {
+                               changedItem = (itemIter->data);
+
+                               oma_ds_1_2_binder_get_stream_size(pBinder, &stream_size);
+                               FW_LOGV("stream_size = %d",  stream_size);
+                               FW_LOGV("(*pSession)->targetMaxMsgSize = %d",  (*pSession)->targetMaxMsgSize);
+
+                               if ((*pSession)->targetMaxMsgSize > stream_size) {
+                                       /*there is a space for command*/
+                                       if (changedItem->changeType == CHANGE_DELETE) {
+                                               /* create delete Command */
+                                               errorType = create_delete_command(*pSession, changedItem->changeType, changedItem->luid, changedItem->content_type, &changeCommand);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed to create delete command");
+                                                       goto error;
+                                               }
+                                       } else{
+                                               int isFirstLargeObj ;
+                                               if (changedItem->data == NULL) {
+                                                       char *folderId = NULL;
+                                                       daci_id_list *folder_id_list = DACI_Get_Folder_Folder_Id_By_Folder_Type_Id((*pSession)->accountId,
+                                                                                                                                                                       datastoreinfo_per_content_type[changedItem->indexOfDatastore]->datastore_id,
+                                                                                                                                                                       datastoreinfo_per_content_type[changedItem->indexOfDatastore]->folder_type_id);
+                                                       if (folder_id_list != NULL) {
+                                                               if(folder_id_list->count > 0)
+                                                                       folderId = folder_id_list->id[0];
+                                                               else{
+                                                                       FW_LOGE("failed to get folderId");
+                                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                                       goto error;
+                                                               }
+                                                       }else{
+                                                               FW_LOGE("failed in DACI_Get_Folder_Folder_Id_By_Folder_Type_Id");
+                                                               errorType = SA_INTERNAL_DA_ERROR;
+                                                               goto error;
+                                                       }
+
+                                                       FW_LOGV("datastoreinfo_per_content_type[%d]->datastore_id = %d", changedItem->indexOfDatastore,
+                                                                       datastoreinfo_per_content_type[changedItem->indexOfDatastore]->datastore_id);
+                                                       FW_LOGV("accountId = %d", (*pSession)->accountId);
+                                                       FW_LOGV("folderId = %s", folderId);
+                                                       FW_LOGV("changedItem->luid = %s", changedItem->luid);
+
+                                                       da_err = DACI_Service_Get_Item(datastoreinfo_per_content_type[changedItem->indexOfDatastore]->datastore_id,
+                                                                                                               (*pSession)->accountId, folderId, changedItem->luid, (void **)&data);
+
+                                                       FW_LOGV("data = %s", data);
+                                                       DACI_Free_Memory_Id_List(folder_id_list);
+                                                       if (data == NULL) {
+                                                               /*if data is NULL(delete item since get change_log or drawing memo)
+                                                               delete that item from changelog_tbl, item_tbl*/
+                                                               da_err =  DACI_Delete_Item_By_Item_Id(changedItem->luid);
+                                                               if (da_err != DACI_SUCCESS) {
+                                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                                       FW_LOGE("failed in DACI_Delete_Item_By_Item_Id = %d", da_err);
+                                                                       goto error;
+                                                               }
+
+                                                               da_err = DACI_Delete_Item_Changelog_By_Item_Id((*pSession)->accountId, changedItem->luid);
+                                                               if (da_err != DACI_SUCCESS) {
+                                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                                       FW_LOGE("failed in DACI_Delete_Item_Changelog_By_Item_Id = %d", da_err);
+                                                                       goto error;
+                                                               }
+                                                               itemIter  = g_list_next(itemIter);
+                                                               changedDatastore->changeItem = g_list_remove(changedDatastore->changeItem, changedItem);
+                                                               free_changeditem(changedItem);
+                                                               continue;
+                                                       }
+
+                                                       if (da_err != DACI_SUCCESS) {
+                                                               FW_LOGE("failed in DACI_Service_Get_Item =%d", da_err);
+                                                               errorType = SA_INTERNAL_DA_ERROR;
+                                                               goto error;
+                                                       }
+
+                                                       isFirstLargeObj = 1;
+                                               } else{
+                                                       data = changedItem->data;
+                                                       changedItem->data = NULL;
+                                                       isFirstLargeObj = 0;
+                                               }
+
+                                               unsigned int sizeOfData = 0;
+                                               if (data != NULL)
+                                                       sizeOfData = strlen(data);
+
+                                               FW_LOGV("sizeOfData = %d", sizeOfData);
+                                               if ((*pSession)->targetMaxMsgSize < stream_size + sizeOfData) {
+                                                       /*can be LargeObj*/
+                                                       int availableSize = (*pSession)->targetMaxMsgSize - stream_size;
+                                                       if ((*pSession)->remoteDevInf->supportsLargeObjs /*&& availableSize > session->targetMaxMsgSize / 50*/) {
+
+                                                               /*if server support LargeObj & clearly LargeObj*/
+                                                               sendingData = calloc(availableSize + 1, sizeof(char));
+                                                               if (sendingData == NULL) {
+                                                                       FW_LOGE("failed to allocate sendingData");
+                                                                       errorType = SA_INTERNAL_NO_MEMORY;
+                                                                       goto error;
+                                                               }
+                                                               memcpy(sendingData, data, availableSize);
+                                                               FW_LOGV("sendingData = %s",  sendingData);
+                                                               FW_LOGV("sendingData size = %d", strlen(sendingData));
+
+                                                               char *remainingData = calloc(sizeOfData - availableSize + 1, sizeof(char));
+                                                               if (remainingData == NULL) {
+                                                                       FW_LOGE("failed to allocate remainingData");
+                                                                       errorType = SA_INTERNAL_NO_MEMORY;
+                                                                       goto error;
+                                                               }
+                                                               memcpy(remainingData, data+availableSize, sizeOfData - availableSize);
+                                                               FW_LOGV("sizeOfData - availableSize  = %d",  sizeOfData - availableSize);
+                                                               FW_LOGV("remainingData = %s", remainingData);
+                                                               FW_LOGV("remainingData size = %d",  strlen(remainingData));
+
+                                                               if (changedItem->data)
+                                                                       free(changedItem->data);
+
+                                                               set_changeditem_data(changedItem, remainingData);
+                                                               free(remainingData);
+
+                                                               PendingStatus *pTemp = NULL;
+                                                               errorType = create_pending_status((*pSession)->msgID, (*pSession)->cmdID, &pTemp);
+                                                               if (errorType != SA_INTERNAL_OK) {
+                                                                       FW_LOGE("failed to create pending status");
+                                                                       goto error;
+                                                               }
+                                                               (*pSession)->largeObj =  pTemp;
+
+                                                               if (changedItem->changeType == CHANGE_ADD) {
+                                                                       /* create add Command */
+                                                                       errorType = create_add_command(*pSession, changedItem->changeType, changedItem->luid,
+                                                                                               changedItem->content_type, sendingData, isFirstLargeObj == 1 ? sizeOfData : 0,  1 , &changeCommand);
+                                                               } else if (changedItem->changeType == CHANGE_REPLACE) {
+                                                                       /* create replace Command */
+                                                                       errorType = create_replace_command(*pSession, changedItem->changeType, changedItem->luid,
+                                                                                       changedItem->content_type, sendingData, isFirstLargeObj == 1 ? sizeOfData : 0,  1 , &changeCommand);
+                                                               }
+
+                                                               if (errorType != SA_INTERNAL_OK) {
+                                                                       FW_LOGE("failed to create add(replace) command");
+                                                                       goto error;
+                                                               }
+
+                                                               if (sendingData != NULL) {
+                                                                       free(sendingData);
+                                                                       sendingData = NULL;
+                                                               }
+                                                       } else{
+                                                               needNextMsg = true;
+                                                               break;
+                                                       }
+                                               } else {
+                                                       /*can append more commnad*/
+                                                       if (changedItem->changeType == CHANGE_ADD) {
+                                                               /* create add Command */
+                                                               errorType = create_add_command(*pSession, changedItem->changeType,
+                                                                               changedItem->luid, changedItem->content_type, data, 0, 0 , &changeCommand);
+                                                       } else if (changedItem->changeType == CHANGE_REPLACE) {
+                                                               /* create replace Command */
+                                                               errorType = create_replace_command(*pSession, changedItem->changeType,
+                                                                               changedItem->luid, changedItem->content_type, data, 0, 0 , &changeCommand);
+                                                       }
+                                                       if (errorType != SA_INTERNAL_OK) {
+                                                               FW_LOGE("failed to create add(replace) command");
+                                                               goto error;
+                                                       }
+                                               }
+                                       }
+                               } else{
+                                       needNextMsg = true;
+                                       break;
+                               }
+
+                               if (changeCommand->type == COMMAND_TYPE_ADD)
+                                       protocol_element = PE_ADD;
+                               else if (changeCommand->type == COMMAND_TYPE_REPLACE)
+                                       protocol_element = PE_REPLACE;
+                               else if (changeCommand->type == COMMAND_TYPE_DELETE)
+                                       protocol_element = PE_DELETE;
+
+
+                               err = oma_ds_1_2_binder_append(pBinder, protocol_element, changeCommand);
+                               oma_ds_1_2_binder_get_stream_size(pBinder, &stream_size);
+                               FW_LOGV("stream size after Changes Command= %d",  stream_size);
+                               put_into_list(commands, commands_last, changeCommand);
+
+                               if (changedItem->data == NULL) {
+                                       itemIter  = g_list_next(itemIter);
+                                       changedDatastore->sentItem = g_list_append(changedDatastore->sentItem, changedItem);
+                                       changedDatastore->changeItem = g_list_remove(changedDatastore->changeItem, changedItem);
+                               } else{
+                                       needNextMsg = true;
+                                       break;
+                               }
+
+                               if (data) {
+                                       free(data);
+                                       data = NULL;
+                               }
+                       }
+
+                       /* create sync end Command */
+                       errorType = create_sync_end_command(&syncCommand);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create sync end command");
+                               goto error;
+                       }
+                       err = oma_ds_1_2_binder_append(pBinder, PE_SYNC_END, syncCommand);
+                       put_into_list(commands, commands_last, syncCommand);
+
+                       if (needNextMsg)
+                               break;
+
+                       int chageItemCount = g_list_length(changedDatastore->changeItem);
+                       if (chageItemCount == 0)
+                               changedDatastore->needSyncCommand = 0;
+               }
+       }
+
+       if (data) {
+               free(data);
+               data = NULL;
+       }
+
+       *isNeedNextMsg = needNextMsg;
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+
+       if (sendingData != NULL) {
+               free(sendingData);
+               sendingData = NULL;
+       }
+
+       if (data != NULL) {
+               free(data);
+               data = NULL;
+       }
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __exchange_msg(char *accType, int transportType, char *targetUri , unsigned int session_id,
+                       GList *header_info, char *sendMsg, unsigned int sendMsg_length, GList **recv_header, char **recvMsg, unsigned int *recvMsg_length)
+{
+       FW_LOGV("start");
+       NACI_RESULT res = NACI_SUCCESS;
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       bool isXML;
+
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               isXML = true;
+       else
+               isXML = false;
+
+       NA_http_header_binder(accType, targetUri, isXML, &header_info);
+       res = NACI_Send_Msg(/*acc_info (id, pw, uri, ...),*/
+                               header_info,
+                               transportType,
+                               sendMsg,
+                               sendMsg_length,
+                               recv_header,
+                               (unsigned char **)recvMsg,
+                               recvMsg_length,
+                               SEND_N_RECEIVE,
+                               session_id);
+
+       if (res != NACI_SUCCESS) {
+               FW_LOGE("res = %d", res);
+               errorType = SA_INTERNAL_CONNECTION_ERROR;
+               goto error;
+       }
+
+       if (sendMsg)
+               free(sendMsg);
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error = %d", errorType);
+
+       if (sendMsg)
+               free(sendMsg);
+
+       return errorType;
+}
+
+
+static SA_ErrorType __process_recv_msg(char *recvMsg, unsigned int recvMsg_length, void **syncReturnObj, int *isFinish)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       reset_cmdID_session(session);
+
+       SyncML* pSyncML = (SyncML *)calloc(1, sizeof(SyncML));
+       if (pSyncML == NULL) {
+               FW_LOGE("failed to allocate pSyncML");
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       GList *pReturnStatus = NULL;
+       GList *pReturnDatastore = NULL;
+
+       errorType = __reverse_object_binder(&pSyncML, recvMsg, recvMsg_length);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in reverseObjectBinder");
+               goto error;
+       }
+
+       /* check receive msg */
+       errorType = receive_header(session, pSyncML->hdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Header");
+               goto error;
+       }
+
+       errorType = receive_statuses(session, pSyncML->status, &pReturnStatus);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Statuses");
+               goto error;
+       }
+
+       errorType = receive_commands(session, pSyncML->commands, false, &pReturnDatastore);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Commands");
+               goto error;
+       }
+
+       if (pSyncML->final) {
+               session->isSendingfinal = 0;
+               session->isReceivingFinal = 1;
+       } else
+               session->isReceivingFinal = 0;
+
+       if (session->pkgStatus == SYNCML_PKG_2) {
+               PreSyncReturnObj ** pre = (PreSyncReturnObj **)syncReturnObj;
+               (*pre)->datastoreInfo = pReturnDatastore;
+
+               if (session->remoteDevInf) {
+                       if (session->remoteDevInf->devid != NULL)
+                               (*pre)->devID = strdup(session->remoteDevInf->devid);
+               }
+
+       } else {
+               SyncReturnObj **syncReturn = (SyncReturnObj **)syncReturnObj;
+               (*syncReturn)->status = pReturnStatus;
+               (*syncReturn)->changedDatastore = pReturnDatastore;
+       }
+
+       if (session->pkgStatus == SYNCML_PKG_2 && session->isReceivingFinal)
+               session->pkgStatus = SYNCML_PKG_3;
+       else if (session->pkgStatus == SYNCML_PKG_4 && session->isReceivingFinal) {
+               if (syncType == ALERT_REFRESH_FROM_CLIENT || syncType == ALERT_ONE_WAY_FROM_CLIENT) {
+                       *isFinish = 1;
+                       __clean_up_SA();
+               } else
+                       session->pkgStatus = SYNCML_PKG_5;
+       } else if (session->pkgStatus == SYNCML_PKG_6 && session->isReceivingFinal) {
+               *isFinish = 1;
+               __clean_up_SA();
+       }
+
+       if (recvMsg)
+               free(recvMsg);
+       if (pSyncML)
+               free_syncml(pSyncML);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+
+       if (recvMsg)
+               free(recvMsg);
+       if (pSyncML)
+               free_syncml(pSyncML);
+
+       return errorType;
+
+}
+
+static SA_ErrorType __generate_autoconfigure_msg(char *id, char *pwd, char *targetUrl, char **msg, unsigned int *msg_size, Session *pSession)
+{
+       FW_LOGV("start");
+       FW_LOGV("id = %s, pwd = %s, targetUrl = %s", id, pwd, targetUrl);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       int isFinal = 1;
+       char *credData = NULL;
+       Cred *pCred = NULL;
+       SyncHdr *pSyncHdr = NULL;
+       SyncML *pSyncML = NULL;
+
+       GList *commands = NULL;
+       GList *commands_last = NULL;
+
+       errorType = create_cred_string(AUTH_TYPE_BASIC,  id, pwd, NULL, 0, &credData);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create cred string");
+               goto error;
+       }
+
+       errorType = create_cred(id, pwd, AUTH_TYPE_BASIC, FORMAT_TYPE_BASE64, credData,  &pCred);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create cred");
+               goto error;
+       }
+
+       if (credData != NULL) {
+               free(credData);
+               credData = NULL;
+       }
+
+       set_session_cred(pSession, pCred);
+
+       errorType = create_synchdr(pSession , &pSyncHdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create synchdr");
+               goto error;
+       }
+
+       char *sourceDevInf = NULL;
+       if (pSession->protocolVersion == VERSION_10)
+               sourceDevInf = ELEMENT_DEVINF_10;
+       else if (pSession->protocolVersion == VERSION_11)
+               sourceDevInf = ELEMENT_DEVINF_11;
+       else if (pSession->protocolVersion == VERSION_12)
+               sourceDevInf = ELEMENT_DEVINF_12;
+
+       Location *pLocation  = NULL;
+       errorType = create_location(sourceDevInf, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create location");
+               goto error;
+       }
+
+       char *contentType = NULL;
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               contentType = ELEMENT_DEVINF_XML;
+       else
+               contentType = ELEMENT_DEVINF_WBXML;
+
+       /* create Get command */
+       Command *pGetCommand = NULL;
+       errorType = create_get_command(pSession, pLocation, contentType, &pGetCommand);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to get command");
+               goto error;
+       }
+       put_into_list(&commands, &commands_last, pGetCommand);
+
+
+       errorType = create_syncml(pSyncHdr, NULL, commands, isFinal, &pSyncML);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to get syncml");
+               goto error;
+       }
+
+       errorType = __object_binder(pSyncML, msg, msg_size);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in objectBinder");
+               goto error;
+       }
+
+       /*free generate structure*/
+       free_syncml(pSyncML);
+       pSyncML = NULL;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       if (pSyncHdr)
+               free_synchdr(pSyncHdr);
+       if (pCred)
+               free_cred(pCred);
+       if (credData != NULL)
+               free(credData);
+       if (commands)
+               free_commands(commands);
+       if (pSyncML)
+               free(pSyncML);
+
+       FW_LOGE("error : %d", errorType);
+
+       return errorType;
+}
+
+static SA_ErrorType __process_autoconfigure_recv_msg(char *recvMsg, unsigned int recvMsg_length, Session *pSession)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       SyncML* pSyncML = (SyncML *)calloc(1, sizeof(SyncML));
+       if (pSyncML == NULL) {
+               FW_LOGE("failed to allocate pSyncML");
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       errorType = __reverse_object_binder(&pSyncML, recvMsg, recvMsg_length);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in reverseObjectBinder");
+               goto error;
+       }
+
+       /* check receive msg */
+       errorType = receive_header(pSession, pSyncML->hdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Header");
+               goto error;
+       }
+
+       errorType = receive_statuses(pSession, pSyncML->status, NULL);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Statuses");
+               goto error;
+       }
+
+       errorType = receive_commands(pSession,  pSyncML->commands, true, NULL);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Commands");
+               goto error;
+       }
+
+       if (recvMsg)
+               free(recvMsg);
+       if (pSyncML != NULL)
+               free_syncml(pSyncML);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+
+       if (recvMsg)
+               free(recvMsg);
+       if (pSyncML)
+               free_syncml(pSyncML);
+       return errorType;
+}
+
+static SA_ErrorType __object_binder(SyncML *pSyncML, char **msg, unsigned int *msg_size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Binder_function_set *pBinder_function_set = NULL;
+
+       PROTOCOL_BINDER_ERROR err = init_oma_ds_1_2_binder_function_set(&pBinder_function_set);
+
+       protocol_binder *pBinder = NULL;
+       char *xml = NULL;
+       unsigned int xml_len = 0;
+
+       pBinder = oma_ds_1_2_binder_init(pBinder, COMMUNICATION_TYPE, false, false, false, true, pBinder_function_set);
+
+       err = oma_ds_1_2_binder_append(pBinder, PE_SYNCML_START, NULL);
+       err = oma_ds_1_2_binder_append(pBinder, PE_HEADER, pSyncML->hdr);
+       err = oma_ds_1_2_binder_append(pBinder, PE_BODY_START, NULL);
+
+       GList *status_iter = NULL;
+       Status *pStatus = NULL;
+       for (status_iter = pSyncML->status; status_iter != NULL; status_iter = g_list_next(status_iter)) {
+               pStatus = status_iter->data;
+               err = oma_ds_1_2_binder_append(pBinder, PE_STATUS, pStatus);
+       }
+
+       GList *iter = NULL;
+       Command *pCommand = NULL;
+       OMA_DS_Protocol_Element protocol_element = PE_UNDEF;
+       for (iter = pSyncML->commands; iter != NULL; iter = g_list_next(iter)) {
+               pCommand = (Command *)(iter->data);
+
+               CommandType type = pCommand->type;
+               switch (type) {
+               case COMMAND_TYPE_UNKNOWN:
+                       protocol_element = PE_UNDEF;
+                       break;
+               case COMMAND_TYPE_ALERT:
+                       protocol_element = PE_ALERT;
+                       break;
+               case COMMAND_TYPE_SYNC_START:
+                       protocol_element = PE_SYNC_START;
+                       break;
+               case COMMAND_TYPE_SYNC_END:
+                       protocol_element = PE_SYNC_END;
+                       break;
+               case COMMAND_TYPE_PUT:
+                       protocol_element = PE_PUT_START;
+                       break;
+               case COMMAND_TYPE_ADD:
+                       protocol_element = PE_ADD;
+                       break;
+               case COMMAND_TYPE_REPLACE:
+                       protocol_element = PE_REPLACE;
+                       break;
+               case COMMAND_TYPE_DELETE:
+                       protocol_element = PE_DELETE;
+                       break;
+               case COMMAND_TYPE_MAP:
+                       protocol_element = PE_MAP;
+                       break;
+               case COMMAND_TYPE_GET:
+                       protocol_element = PE_GET;
+                       break;
+               case COMMAND_TYPE_RESULTS:
+                       protocol_element = PE_RESULTS_START;
+                       break;
+               case COMMAND_TYPE_HEADER:
+                       protocol_element = PE_HEADER;
+                       break;
+               }
+               err = oma_ds_1_2_binder_append(pBinder, protocol_element, pCommand);
+
+               if (type == COMMAND_TYPE_RESULTS) {
+                       err = oma_ds_1_2_binder_append(pBinder, PE_RESULTS_END, NULL);
+               }
+
+               if (type == COMMAND_TYPE_PUT) {
+                       if (pCommand->private.access.item) {
+                               if (pCommand->private.access.item->private.devInf) {
+                                       err = oma_ds_1_2_binder_append(pBinder, PE_DEVINF, pCommand->private.access.item);
+                               }
+                       }
+                       err = oma_ds_1_2_binder_append(pBinder, PE_PUT_END, NULL);
+               }
+       }
+
+       if (pSyncML->final) {
+               err = oma_ds_1_2_binder_append(pBinder, PE_FINAL, NULL);
+       }
+
+       err = oma_ds_1_2_binder_append(pBinder, PE_BODY_END, NULL);
+       err = oma_ds_1_2_binder_append(pBinder, PE_SYNCML_END, NULL);
+
+       oma_ds_1_2_binder_get_stream(pBinder, msg, msg_size);
+
+       /*FIXME for debugging*/
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               set_xml_to_file(*msg, OMA_DS_MSG_PATH);
+       else{
+               err = protocol_binder_get_xml_for_debugging(pBinder, &xml, &xml_len);
+               if (err == PROTOCOL_BINDER_OK) {
+                       set_xml_to_file(xml, OMA_DS_MSG_PATH);
+
+                       if (xml != NULL) {
+                               free(xml);
+                               xml = NULL;
+                       }
+               }
+       }
+
+       oma_ds_1_2_binder_terminate(pBinder);
+
+       if (err != PROTOCOL_BINDER_OK)
+               errorType = SA_INTERNAL_BINDER_ERROR;
+
+       FW_LOGV("end");
+
+       return errorType;
+}
+
+static SA_ErrorType __reverse_object_binder(SyncML **pSyncML, char *recv_msg, unsigned int recv_msg_length)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Binder_function_set *pBinder_function_set = NULL;
+
+       PROTOCOL_BINDER_ERROR err = init_oma_ds_1_2_binder_function_set(&pBinder_function_set);
+       Reverse_protocol_binder *pBinder = NULL;
+       char *xml = NULL;
+       unsigned int xml_len = 0;
+
+       Decoding dec;
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               dec = DECODING_XML;
+       else
+               dec = DECODING_WBXML;
+
+       err = reverse_oma_ds_1_2_binder_init(recv_msg, recv_msg_length,
+                                                                                       dec, pBinder_function_set, NULL, &pBinder);
+
+       if (err != PROTOCOL_BINDER_OK) {
+               errorType = SA_INTERNAL_BINDER_ERROR;
+               FW_LOGE("reverse_oma_ds_1_2_binder_init error =%d", err);
+               return errorType;
+       }
+
+
+       /*FIXME for debugging*/
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               set_xml_to_file(recv_msg, OMA_DS_MSG_PATH);
+       else{
+               err = reverse_protocol_binder_get_xml_for_debugging(pBinder, &xml, &xml_len);
+               if (err == PROTOCOL_BINDER_OK) {
+                       set_xml_to_file(xml, OMA_DS_MSG_PATH);
+
+                       if (xml != NULL) {
+                               free(xml);
+                               xml = NULL;
+                       }
+               }
+       }
+
+
+       OMA_DS_Protocol_Element protocol_element = PE_UNDEF;
+       char *protocol_element_name = NULL;
+       Content_Ptr pContent = NULL;
+       Command *tempCommandfordevInf = NULL;
+       while (err == PROTOCOL_BINDER_OK) {
+               protocol_element = PE_UNDEF;
+               err = reverse_oma_ds_1_2_binder_next(pBinder, &protocol_element, &protocol_element_name, &pContent);
+               switch (protocol_element) {
+                       case PE_ADD:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_ATOMIC_START:
+                       case PE_ATOMIC_END:
+                       case PE_COPY:
+                       case PE_DELETE:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_EXEC:
+                       case PE_GET:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_MAP:
+                       case PE_PUT_START:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               tempCommandfordevInf = pContent;
+                               break;
+                       case PE_SEARCH:
+                       case PE_SEQUENCE_START:
+                       case PE_SEQUENCE_END:
+                       case PE_SYNC_START:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_SYNC_END:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               protocol_element = PE_UNDEF;
+                               break;
+                       case PE_REPLACE:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_ALERT:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_RESULTS_START:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               tempCommandfordevInf = pContent;
+                               break;
+                       case PE_STATUS:
+                               (*pSyncML)->status = g_list_append((*pSyncML)->status, pContent);
+                               protocol_element = PE_UNDEF;
+                               break;
+                       case PE_HEADER:
+                               (*pSyncML)->hdr = pContent;
+                               reverse_protocol_binder_set_user_data(pBinder, (*pSyncML)->hdr);
+                               break;
+                       case PE_PUT_GET:
+                       case PE_CMD_GROUP:
+                       case PE_GENERIC:
+                       case PE_FINAL:
+                               (*pSyncML)->final = (int)pContent;
+                               break;
+                       case PE_DEVINF:
+                               if (tempCommandfordevInf) {
+                                       tempCommandfordevInf->private.results.item->private.devInf = pContent;
+                                       tempCommandfordevInf = NULL;
+                               }
+                               break;
+                       default:
+                               break;
+               }
+
+               if (protocol_element_name != NULL) {
+                       free(protocol_element_name);
+                       protocol_element_name = NULL;
+               }
+
+               if (err == PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT) {
+                       break;
+               }
+       }
+
+       reverse_protocol_binder_terminate(pBinder);
+
+       free_oma_ds_1_2_binder_function_set(pBinder_function_set);
+
+       if (err != PROTOCOL_BINDER_OK && err != PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT)
+               errorType = SA_INTERNAL_BINDER_ERROR;
+
+       return errorType;
+}
+
+static Common_ErrorType __convert_error_type(SA_ErrorType errorType)
+{
+       Common_ErrorType sa_errorType = COMMON_OK;
+
+       if (errorType == SA_INTERNAL_OK)
+               sa_errorType = COMMON_OK;
+       else if (errorType == SA_INTERNAL_MISCONFIGURATION)
+               sa_errorType = COMMON_MISCONFIGURATION;
+       else if (errorType == SA_INTERNAL_AUTHENTICATION_ERROR)
+               sa_errorType = COMMON_AUTHENTICATION_ERROR;
+       else if (errorType == SA_INTERNAL_NOT_FOUND)
+               sa_errorType = COMMON_NOT_FOUND;
+       else if (errorType == SA_INTERNAL_NO_MEMORY)
+               sa_errorType = COMMON_NO_MEMORY;
+       else if (errorType == SA_INTERNAL_NOT_DEFINED || errorType == SA_INTERNAL_BINDER_ERROR  ||
+                       errorType == SA_INTERNAL_ERROR || errorType == SA_INTERNAL_DA_ERROR)
+               sa_errorType = COMMON_INTERNAL_ERROR;
+       else if (errorType == SA_INTERNAL_SERVER_ERROR || errorType == SA_INTERNAL_SERVER_FAILURE)
+               sa_errorType = COMMON_SERVER_ERROR;
+       else if (errorType == SA_INTERNAL_CONNECTION_ERROR)
+               sa_errorType = COMMON_CONNECTION_ERROR;
+       else if (errorType == SA_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER)
+               sa_errorType = COMMON_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+       else if (errorType ==  SA_INTERNAL_CANCEL)
+               sa_errorType = COMMON_CANCEL;
+       else if (errorType ==  SA_INTERNAL_BUSY_SIGNALING)
+               sa_errorType = COMMON_BUSY_SIGNALING;
+
+
+       return sa_errorType;
+
+       /*from processRecvMsg
+       401 ->ERROR_AUTH_REJECTED :wrong password(header, datastore)
+       407 -> ERROR_AUTH_REQUIRED : try one more request and if failed again return ERROR_AUTH_REQUIRED(header, datastore)
+       404 -> ERROR_NOT_FOUND -> no datastore (important -> have to be noted to user)
+
+       1500 -> ERROR_INTERNAL_OK : processRecvMsg has been completed without any error
+
+       1513 -> ERROR_INTERNAL_NOT_DEFINED
+       1512 -> ERROR_INTERNAL_NO_MEMORY
+       1503 -> ERROR_INTERNAL_BINDER_ERROR
+
+       500 -> ERROR_GENERIC (our problem -> do not ever never receive this error)
+       511 ->ERROR_SERVER_FAILURE(our problem -> do not ever never receive this error)
+
+        can be return to engine value
+       from generatePreSyncMsg
+       1506 -> ERROR_INTERNAL_MISCONFIGURATION : need configure infomation
+       1500 -> ERROR_INTERNAL_OK : generatePreSyncMsg has been completed without any error
+       1512 -> ERROR_INTERNAL_NO_MEMORY : failed to allocate memory
+       1513 -> ERROR_INTERNAL_NOT_DEFINED : something is not defined that must have
+       1503 -> ERROR_INTERNAL_BINDER_ERROR     : binder error
+
+
+       from exchangeMsg
+
+       from processRecvMsg
+       401 ->ERROR_AUTH_REJECTED :wrong password(header, datastore)
+       407 -> ERROR_AUTH_REQUIRED : try one more request and if failed again return ERROR_AUTH_REQUIRED(header, datastore)
+       404 -> ERROR_NOT_FOUND -> no datastore (important -> have to be noted to user)
+
+       1500 -> ERROR_INTERNAL_OK : processRecvMsg has been completed without any error
+
+       1513 -> ERROR_INTERNAL_NOT_DEFINED
+       1512 -> ERROR_INTERNAL_NO_MEMORY
+       1503 -> ERROR_INTERNAL_BINDER_ERROR
+
+       500 -> ERROR_GENERIC (our problem -> do not ever never receive this error)
+       511 ->ERROR_SERVER_FAILURE(our problem -> do not ever never receive this error)*/
+
+}
+
+static void __clean_up_SA()
+{
+       FW_LOGV("start");
+
+       if (session != NULL) {
+
+               if (session->hasOpend) {
+                       NACI_Close_Connection(TRANSPORT_TYPE, session->NACI_sessionID);
+                       session->hasOpend = 0;
+               }
+
+               free_session(session);
+               session = NULL;
+       }
+
+       FW_LOGV("end");
+}
+
+int pre_sync(int transportType, int accountId, char *sessionId,  void **preSyncReturnObj)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       char *msg = NULL;
+       unsigned int msg_size = 0;
+       GList *recv_header = NULL;
+       GList *header_info = NULL;
+       char *recv_msg = NULL;
+       unsigned int recv_msg_size = 0;
+       unsigned int session_id;
+
+       /* generate preSync Msg */
+       errorType =  __generate_presync_msg(accountId, sessionId, &msg, &msg_size);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+       if (!session->hasOpend) {
+               NACI_RESULT res = NACI_Open_Connection(transportType, NETWORK_TIMEOUT, &session_id);
+               if (res != NACI_SUCCESS) {
+                       FW_LOGE("failed in NACI_Open_Connection res = %d", res);
+                       errorType = SA_INTERNAL_CONNECTION_ERROR;
+                       goto error;
+               }
+               session->NACI_sessionID = session_id;
+               session->hasOpend = 1;
+               FW_LOGV("session_id = %d", session_id);
+       }
+       /* exchange Msg */
+       errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, transportType, session->target->locURI,
+                       session->NACI_sessionID, header_info,  msg, msg_size, &recv_header, &recv_msg, &recv_msg_size);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       errorType = __process_recv_msg(recv_msg, recv_msg_size, preSyncReturnObj, NULL);
+       if (errorType == SA_INTERNAL_AUTHENTICATION_ERROR) {
+               /*when errortype is ERROR_AUTH_REQUIRED try request using chal just one more time
+               it can be only happend when server required MD5 authentication(we send basic authentication every time by default)*/
+               errorType =  __generate_presync_msg(accountId, sessionId, &msg, &msg_size);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               if (header_info != NULL) {
+                       GList *iter = NULL;
+                       for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                               free_header_info(iter->data);
+                       g_list_free(header_info);
+                       header_info = NULL;
+               }
+
+               if (recv_header != NULL) {
+                       GList *iter = NULL;
+                       common_header_info *iter_data;
+                       for (iter = recv_header; iter != NULL;) {
+                               iter_data = NULL;
+                               iter_data = ((common_header_info *)(iter->data));
+
+                               iter = g_list_next(iter);
+                               recv_header = g_list_remove(recv_header, iter_data);
+
+                               if (iter_data->key != NULL)
+                                       free(iter_data->key);
+                               if (iter_data->value != NULL)
+                                       free(iter_data->value);
+                               free(iter_data);
+                       }
+                       g_list_free(recv_header);
+               }
+
+               errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, transportType, session->target->locURI,
+                               session->NACI_sessionID, header_info, msg, msg_size, &recv_header, &recv_msg, &recv_msg_size);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               errorType = __process_recv_msg(recv_msg, recv_msg_size, preSyncReturnObj, NULL);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+       if (header_info != NULL) {
+               GList *iter = NULL;
+               for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                       free_header_info(iter->data);
+               g_list_free(header_info);
+               header_info = NULL;
+       }
+
+       if (recv_header != NULL) {
+               GList *iter = NULL;
+               common_header_info *iter_data;
+               for (iter = recv_header; iter != NULL;) {
+                       iter_data = NULL;
+                       iter_data = ((common_header_info *)(iter->data));
+
+                       iter = g_list_next(iter);
+                       recv_header = g_list_remove(recv_header, iter_data);
+
+                       if (iter_data->key != NULL)
+                               free(iter_data->key);
+                       if (iter_data->value != NULL)
+                               free(iter_data->value);
+                       free(iter_data);
+               }
+               g_list_free(recv_header);
+       }
+
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("errorType : %d", errorType);
+               __clean_up_SA();
+       }
+
+       return __convert_error_type(errorType);
+}
+
+int generate_msg(void **syncObj, char **msg, unsigned int *msg_size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       errorType = __generate_msg(syncObj, msg, msg_size);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("end");
+
+error:
+
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("errorType : %d", errorType);
+               __clean_up_SA();
+       }
+
+       return __convert_error_type(errorType);
+}
+
+int exchange_msg(int transportType, char *sendMsg, unsigned int sendMsg_length, char **recvMsg, unsigned int *recvMsg_length)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       GList *header_info = NULL;
+       GList *recv_header = NULL;
+
+       errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, transportType, session->target->locURI,
+                       session->NACI_sessionID, header_info, sendMsg, sendMsg_length, &recv_header, recvMsg, recvMsg_length);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("end");
+
+error:
+
+       if (header_info != NULL) {
+               GList *iter = NULL;
+               for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                       free_header_info(iter->data);
+               g_list_free(header_info);
+               header_info = NULL;
+       }
+
+       if (recv_header != NULL) {
+               GList *iter = NULL;
+               common_header_info *iter_data;
+               for (iter = recv_header; iter != NULL;) {
+                       iter_data = NULL;
+                       iter_data = ((common_header_info *)(iter->data));
+
+                       iter = g_list_next(iter);
+                       recv_header = g_list_remove(recv_header, iter_data);
+
+                       if (iter_data->key != NULL)
+                               free(iter_data->key);
+                       if (iter_data->value != NULL)
+                               free(iter_data->value);
+                       free(iter_data);
+               }
+               g_list_free(recv_header);
+       }
+
+        if (errorType != SA_INTERNAL_OK) {
+                FW_LOGE("errorType : %d", errorType);
+                __clean_up_SA();
+        }
+
+        return __convert_error_type(errorType);
+}
+
+int process_recv_msg(char *recvMsg, unsigned int recvMsg_length, void **syncReturnObj, int *isFinish)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       errorType = __process_recv_msg(recvMsg, recvMsg_length, syncReturnObj, isFinish);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("end");
+
+error:
+
+        if (errorType != SA_INTERNAL_OK) {
+                FW_LOGE("errorType : %d", errorType);
+                __clean_up_SA();
+        }
+
+        return __convert_error_type(errorType);
+}
+
+void clean_up_SA()
+{
+       FW_LOGV("start");
+
+       __clean_up_SA();
+
+       FW_LOGV("end");
+}
+
+int auto_configure_from_vconf(char *id, char *pwd, char *targetUrl, char *profilePath, GList **configure)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Session *pSession = NULL;
+
+       char *sourceUrl = NULL;
+       char *sessionId = NULL;
+
+       char *msg = NULL;
+       unsigned int msg_size = 0;
+
+       GList *header_info = NULL;
+       GList *recv_header = NULL;
+       char *recv_msg = NULL;
+       unsigned int recv_msg_size = 0;
+
+       bool cancel_flag = false;
+       unsigned int session_id;
+
+       sessionId = g_strdup_printf("%ld", time(NULL));
+       if (sessionId == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       DCI_RETURN err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &sourceUrl);
+       if (err != DCI_SUCCESS) {
+               FW_LOGV("failed in DCI_Get_DevInfo");
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       errorType = create_session(VERSION_12, PROTOCOL_TYPE_DS, 0, sessionId, sourceUrl, targetUrl, &pSession);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       if (pSession == NULL) {
+               FW_LOGV("failed to create session");
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       errorType = __generate_autoconfigure_msg(id, pwd, targetUrl, &msg, &msg_size , pSession);
+       if (errorType != SA_INTERNAL_OK){
+               FW_LOGV("failed in __generate_autoconfigure_msg");
+               goto error;
+       }
+
+       if (!pSession->hasOpend) {
+               NACI_RESULT res = NACI_Open_Connection(TRANSPORT_TYPE, NETWORK_TIMEOUT, &session_id);
+               if (res != NACI_SUCCESS) {
+                       FW_LOGE("failed in NACI_Open_Connection res = %d", res);
+                       errorType = SA_INTERNAL_CONNECTION_ERROR;
+                       goto error;
+               }
+               pSession->NACI_sessionID = session_id;
+               pSession->hasOpend = 1;
+               FW_LOGV("session_id = %d", session_id);
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       /* exchange Msg */
+       errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, TRANSPORT_TYPE, pSession->target->locURI,
+                       pSession->NACI_sessionID, header_info, msg, msg_size, &recv_header, &recv_msg, &recv_msg_size);
+       if (errorType != SA_INTERNAL_OK){
+               FW_LOGV("failed in __exchange_msg");
+               goto error;
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       errorType = __process_autoconfigure_recv_msg(recv_msg, recv_msg_size, pSession);
+       if (errorType != SA_INTERNAL_OK){
+               FW_LOGV("failed in __process_autoconfigure_recv_msg");
+               goto error;
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       DevInf *devInf = pSession->remoteDevInf;
+       if (devInf) {
+
+               GList *tempConfigure = NULL;
+
+               GList *contactCandidate = NULL;
+               GList *calendarCandidate = NULL;
+               GList *memoCandidate = NULL;
+
+               /*set inputted name by user*/
+               contactCandidate = g_list_append(contactCandidate, strdup(DEFINE_SOURCE_CONTACT_URI));
+               char *target = NULL;
+               target = get_vconf_str(profilePath, DS_SETTING_CONTACT_TGTURI);
+               if (target) {
+                       FW_LOGV("Contacts target =%s",  target);
+                       if (strcmp(target, "") != 0)
+                               contactCandidate = g_list_append(contactCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+
+               calendarCandidate = g_list_append(calendarCandidate, strdup(DEFINE_SOURCE_CALENDAR_URI));
+               target = get_vconf_str(profilePath, DS_SETTING_CALENDAR_TGTURI);
+               if (target) {
+                       FW_LOGV("Organizer target =%s", target);
+                       if (strcmp(target, "") != 0)
+                               calendarCandidate = g_list_append(calendarCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+
+               memoCandidate = g_list_append(memoCandidate, strdup(DEFINE_SOURCE_MEMO_URI));
+               target = get_vconf_str(profilePath, DS_SETTING_MEMO_TGTURI);
+               if (target) {
+                       FW_LOGV("Memo target =%s", target);
+                       if (strcmp(target, "") != 0)
+                               memoCandidate = g_list_append(memoCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+
+               GList *iter = NULL;
+               GList *innerIter = NULL;
+               DevInfDataStore *devInfDataStore = NULL;
+               int exist;
+               char *candidate;
+               for (iter = devInf->datastores; iter != NULL; iter = g_list_next(iter)) {
+                       devInfDataStore = iter->data;
+                       exist = 0;
+                       candidate = NULL;
+
+                       FW_LOGV("devInfDataStore->sourceref = %s", devInfDataStore->sourceref);
+
+                       if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCARD) == 0 ||
+                                       strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCARD_30) == 0) {
+
+                               for (innerIter = g_list_next(contactCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       contactCandidate = g_list_append(contactCandidate, strdup(devInfDataStore->sourceref));
+
+                       } else if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCAL) == 0 ||
+                                       strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_ICAL) == 0) {
+
+                               for (innerIter = g_list_next(calendarCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       calendarCandidate = g_list_append(calendarCandidate, strdup(devInfDataStore->sourceref));
+
+                       } else if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_PLAIN) == 0) {
+
+                               for (innerIter = g_list_next(memoCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       memoCandidate = g_list_append(memoCandidate, strdup(devInfDataStore->sourceref));
+                       }
+               }
+
+               tempConfigure = g_list_append(tempConfigure, contactCandidate);
+               tempConfigure = g_list_append(tempConfigure, calendarCandidate);
+               tempConfigure = g_list_append(tempConfigure, memoCandidate);
+
+               *configure = tempConfigure;
+
+//             *congifure = g_list_append(*congifure, contactCandidate);
+//             *congifure = g_list_append(*congifure, calendarCandidate);
+//             *congifure = g_list_append(*congifure, memoCandidate);
+
+       } else{
+               errorType = SA_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       /*close network*/
+       if (pSession != NULL) {
+               if (pSession->hasOpend)
+                       NACI_Close_Connection(TRANSPORT_TYPE, pSession->NACI_sessionID);
+       }
+
+       if (header_info != NULL) {
+               GList *iter = NULL;
+               for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                       free_header_info(iter->data);
+               g_list_free(header_info);
+               header_info = NULL;
+       }
+
+       if (recv_header != NULL) {
+               GList *iter = NULL;
+               common_header_info *iter_data;
+               for (iter = recv_header; iter != NULL;) {
+                       iter_data = NULL;
+                       iter_data = ((common_header_info *)(iter->data));
+
+                       iter = g_list_next(iter);
+                       recv_header = g_list_remove(recv_header, iter_data);
+
+                       if (iter_data->key != NULL)
+                               free(iter_data->key);
+                       if (iter_data->value != NULL)
+                               free(iter_data->value);
+                       free(iter_data);
+               }
+               g_list_free(recv_header);
+       }
+
+       if (sessionId)
+               free(sessionId);
+
+       if (sourceUrl)
+               free(sourceUrl);
+
+       if (pSession) {
+               free_session(pSession);
+               pSession = NULL;
+       }
+
+       if (errorType != SA_INTERNAL_OK)
+               FW_LOGE("errorType =%d", errorType);
+
+       return __convert_error_type(errorType);
+}
+
+
+int auto_configure(char *addr, char *id, char *password, GList **configure)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Session *pSession = NULL;
+
+       char *sourceUrl = NULL;
+       char *sessionId = NULL;
+
+       char *msg = NULL;
+       unsigned int msg_size = 0;
+
+       GList *header_info = NULL;
+       GList *recv_header = NULL;
+       char *recv_msg = NULL;
+       unsigned int recv_msg_size = 0;
+
+       bool cancel_flag = false;
+       unsigned int session_id;
+
+       sessionId = g_strdup_printf("%ld", time(NULL));
+       if (sessionId == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       DCI_RETURN err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &sourceUrl);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       errorType = create_session(VERSION_12, PROTOCOL_TYPE_DS, 0, sessionId, sourceUrl, addr, &pSession);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       if (pSession == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       errorType = __generate_autoconfigure_msg(id, password, addr, &msg, &msg_size , pSession);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       if (!pSession->hasOpend) {
+               NACI_RESULT res = NACI_Open_Connection(TRANSPORT_TYPE, NETWORK_TIMEOUT, &session_id);
+               if (res != NACI_SUCCESS) {
+                       FW_LOGE("failed in NACI_Open_Connection res = %d", res);
+                       errorType = SA_INTERNAL_CONNECTION_ERROR;
+                       goto error;
+               }
+               pSession->NACI_sessionID = session_id;
+               pSession->hasOpend = 1;
+               FW_LOGV("session_id = %d", session_id);
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       /* exchange Msg */
+       errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, TRANSPORT_TYPE, pSession->target->locURI,
+                       pSession->NACI_sessionID, header_info, msg, msg_size, &recv_header, &recv_msg, &recv_msg_size);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       errorType = __process_autoconfigure_recv_msg(recv_msg, recv_msg_size, pSession);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       DevInf *devInf = pSession->remoteDevInf;
+       if (devInf) {
+
+               GList *tempConfigure = NULL;
+
+               GList *contactCandidate = NULL;
+               GList *calendarCandidate = NULL;
+               GList *memoCandidate = NULL;
+
+               /*set inputted name by user*/
+               contactCandidate = g_list_append(contactCandidate, strdup(DEFINE_SOURCE_CONTACT_URI));
+               /*
+               char *target = NULL;
+               target= get_vconf_str(profilePath, DS_SETTING_CONTACT_TGTURI);
+               if (target) {
+                       FW_LOGV("Contacts target =%s",  target);
+                       if (strcmp(target, "") !=0)
+                               contactCandidate = g_list_append(contactCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+               */
+
+               calendarCandidate = g_list_append(calendarCandidate, strdup(DEFINE_SOURCE_CALENDAR_URI));
+               /*
+               target = get_vconf_str(profilePath, DS_SETTING_CALENDAR_TGTURI);
+               if (target) {
+                       FW_LOGV("Organizer target =%s", target);
+                       if (strcmp(target, "") !=0)
+                               calendarCandidate = g_list_append(calendarCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+               */
+
+               memoCandidate = g_list_append(memoCandidate, strdup(DEFINE_SOURCE_MEMO_URI));
+               /*
+               target = get_vconf_str(profilePath, DS_SETTING_MEMO_TGTURI);
+               if (target) {
+                       FW_LOGV("Memo target =%s", target);
+                       if (strcmp(target, "") !=0)
+                               memoCandidate = g_list_append(memoCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+               */
+
+               GList *iter = NULL;
+               GList *innerIter = NULL;
+               DevInfDataStore *devInfDataStore = NULL;
+               int exist;
+               char *candidate;
+               for (iter = devInf->datastores; iter != NULL; iter = g_list_next(iter)) {
+                       devInfDataStore = iter->data;
+                       exist = 0;
+                       candidate = NULL;
+
+                       FW_LOGV("devInfDataStore->sourceref = %s", devInfDataStore->sourceref);
+
+                       if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCARD) == 0 ||
+                                       strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCARD_30) == 0) {
+
+                               for (innerIter = g_list_next(contactCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       contactCandidate = g_list_append(contactCandidate, strdup(devInfDataStore->sourceref));
+
+                       } else if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCAL) == 0 ||
+                                       strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_ICAL) == 0) {
+
+                               for (innerIter = g_list_next(calendarCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       calendarCandidate = g_list_append(calendarCandidate, strdup(devInfDataStore->sourceref));
+
+                       } else if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_PLAIN) == 0) {
+
+                               for (innerIter = g_list_next(memoCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       memoCandidate = g_list_append(memoCandidate, strdup(devInfDataStore->sourceref));
+                       }
+               }
+
+               tempConfigure = g_list_append(tempConfigure, contactCandidate);
+               tempConfigure = g_list_append(tempConfigure, calendarCandidate);
+               tempConfigure = g_list_append(tempConfigure, memoCandidate);
+
+               *configure = tempConfigure;
+
+
+//             *congifure = g_list_append(*congifure, contactCandidate);
+//             *congifure = g_list_append(*congifure, calendarCandidate);
+//             *congifure = g_list_append(*congifure, memoCandidate);
+
+       } else{
+               errorType = SA_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       /*close network*/
+        if (pSession != NULL) {
+                if (pSession->hasOpend)
+                        NACI_Close_Connection(TRANSPORT_TYPE, pSession->NACI_sessionID);
+        }
+
+        if (header_info != NULL) {
+                GList *iter = NULL;
+                for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                        free_header_info(iter->data);
+                g_list_free(header_info);
+                header_info = NULL;
+        }
+
+       if (recv_header != NULL) {
+               GList *iter = NULL;
+               common_header_info *iter_data;
+               for (iter = recv_header; iter != NULL;) {
+                       iter_data = NULL;
+                       iter_data = ((common_header_info *)(iter->data));
+
+                       iter = g_list_next(iter);
+                       recv_header = g_list_remove(recv_header, iter_data);
+
+                       if (iter_data->key != NULL)
+                               free(iter_data->key);
+                       if (iter_data->value != NULL)
+                               free(iter_data->value);
+                       free(iter_data);
+               }
+               g_list_free(recv_header);
+       }
+
+       if (sessionId)
+               free(sessionId);
+
+       if (sourceUrl)
+               free(sourceUrl);
+
+       if (pSession) {
+               free_session(pSession);
+               pSession = NULL;
+       }
+
+       if (errorType != SA_INTERNAL_OK)
+               FW_LOGE("errorType =%d", errorType);
+
+       return __convert_error_type(errorType);
+}
+
+/*FIXME cancel request to NA */
+/*int cancel_connection_sync_request(char *transportType)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType err = SA_INTERNAL_OK;
+       NACI_RESULT res = NACI_SUCCESS;
+
+       FW_LOGV("sessionId = %d", session->NACI_sessionID);
+
+       res =  NACI_Cancel_Msg(transportType, session->NACI_sessionID);
+       if (res != NACI_SUCCESS) {
+               FW_LOGE("res = %d", res);
+               err = SA_INTERNAL_CONNECTION_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return __convert_error_type(err);
+}*/
diff --git a/ServiceAdapter/SA_DevInf.c b/ServiceAdapter/SA_DevInf.c
new file mode 100644 (file)
index 0000000..6a39b64
--- /dev/null
@@ -0,0 +1,1023 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_DevInf.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions for device information structure which is used in Service Adapter
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/Device/EXT_DCI_DevInfo.h"
+#include "agent-framework/DACI/EXT_DACI_Converter.h"
+#include "ServiceAdapter/SA_DevInf.h"
+#include "ServiceAdapter/SA_DevInf_Internal.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+#include "Common/Common_Define.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+static SA_ErrorType __create_devinf_new(char *devid, DevInfDevTyp devtyp, DevInf **pDevInf);
+static SA_ErrorType __create_devinf_contenttype(char *cttype, char *verct, DevInfContentType **pDevInfContentType);
+static SA_ErrorType __create_devinf_ctcap(DevInfContentType *devInfContentType, DevInfCTCap **pDevInfCTCap);
+static SA_ErrorType __create_devinf_property(char *propName, DevInfProperty **pDevInfProperty);
+
+static SA_ErrorType create_devinf_datastore(char *dataStore, DevInfDataStore **pDevInfDataStore);
+static void __free_devinf_datastores(GList *devInfDatastores);
+static void __free_devinf_datastore(DevInfDataStore *pDevInfDataStore);
+static void __free_devinf_contenttype(DevInfContentType *pDevInfContentType);
+static void __free_devinf_ctcaps(DevInfCTCap *pDevInfCTCap);
+static void __free_devinf_property(DevInfProperty *pDevInfProperty);
+static void __free_devinf_propparam(DevInfPropParam *pDevInfPropParam);
+static void __set_devinf_version(DevInf *devInf, DevInfVersion version);
+static void __set_devinf_manufacturer(DevInf *devInf, char *manufacturer);
+static void __set_devinf_model(DevInf *devInf, char *model);
+static void __set_devinf_oem(DevInf *devInf, char *oem);
+static void __set_devinf_software_version(DevInf *devInf, char *softwareVersion);
+static void __set_devinf_hardware_version(DevInf *devInf, char *hardwareVersion);
+static void __set_devinf_firmware_version(DevInf *devInf, char *firmwareVersion);
+static void __set_devinf_datastore(DevInf *devInf, DevInfDataStore *devInfDataStore);
+static void __set_devinf_datastore_rxpref(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType);
+static void __set_devinf_datastore_txpref(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType);
+static void __set_devinf_datastore_ctcap(DevInfDataStore *devInfDataStore, DevInfCTCap *devInfCTCap);
+static void __set_devinf_ctcap_property(DevInfCTCap *devInfCTCap, DevInfProperty *devInfProperty);
+static void __set_devInf_property_valenums(DevInfProperty *devInfProperty, char*valEnum);
+static DevInfDevTyp __convert_devtyp(char *devTyp);
+
+/* unused function
+ *  keep for in case
+ */
+/*
+static ErrorType create_DevInfPropParam(char *paramName, DevInfPropParam **pDevInfPropParam);
+static void set_DevInfDataStoreDisplayname(DevInfDataStore* devInfDataStore, char *displayname);
+static void set_DevInfDataStoreRx(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType);
+static void set_DevInfDataStoreTx(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType);
+static void set_DevInfPropertyDataType(DevInfProperty *devInfProperty, char *dataType);
+static void set_DevInfPropertyMaxOccur(DevInfProperty *devInfProperty, unsigned int maxOccur);
+static void set_DevInfPropertyMaxSize(DevInfProperty *devInfProperty, unsigned int maxSize);
+static void set_DevInfPropertyNoTruncate(DevInfProperty *devInfProperty, int noTruncate);
+static void set_DevInfPropertyDisplayName(DevInfProperty *devInfProperty, char *displayName);
+static void set_DevInfPropertyPropParam(DevInfProperty *devInfProperty, DevInfPropParam *devInfPropParam);
+static void set_DevInfPropParamDataType(DevInfPropParam *devInfPropParam, char *dataType);
+static void set_DevInfPropParamDisplayName(DevInfPropParam *devInfPropParam, char *displayName);
+static void set_DevInfPropParamValEnums(DevInfPropParam *devInfPropParam, char *valEnum);
+*/
+
+static SA_ErrorType __create_devinf_new(char *devid, DevInfDevTyp devtyp, DevInf **pDevInf)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!devid) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!devtyp) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInf = (DevInf *)calloc(1, sizeof(DevInf));
+       if (*pDevInf == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       if (devid != NULL)
+               (*pDevInf)->devid = strdup(devid);
+       (*pDevInf)->devtyp = devtyp;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __create_devinf_contenttype(char *cttype, char *verct, DevInfContentType **pDevInfContentType)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!cttype) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!verct) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfContentType = (DevInfContentType *)calloc(1, sizeof(DevInfContentType));
+       if (*pDevInfContentType == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfContentType)->cttype = strdup(cttype);
+       (*pDevInfContentType)->verct = strdup(verct);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __create_devinf_ctcap(DevInfContentType *devInfContentType, DevInfCTCap **pDevInfCTCap)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!devInfContentType) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfCTCap = (DevInfCTCap *)calloc(1, sizeof(DevInfCTCap));
+       if (*pDevInfCTCap == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfCTCap)->ct = devInfContentType;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+
+}
+
+static SA_ErrorType __create_devinf_property(char *propName, DevInfProperty **pDevInfProperty)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!propName) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfProperty = (DevInfProperty *)calloc(1, sizeof(DevInfProperty));
+       if (*pDevInfProperty == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfProperty)->propName = strdup(propName);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType create_devinf_datastore(char *dataStore, DevInfDataStore **pDevInfDataStore)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!dataStore) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfDataStore = (DevInfDataStore *)calloc(1, sizeof(DevInfDataStore));
+       if (*pDevInfDataStore == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfDataStore)->sourceref = strdup(dataStore);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static void __free_devinf_datastores(GList *devInfDatastores)
+{
+       FW_LOGV("start");
+
+       if (!devInfDatastores)
+               return;
+
+       GList *iter = NULL;
+       for (iter = devInfDatastores; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_datastore(iter->data);
+
+       g_list_free(devInfDatastores);
+
+       FW_LOGV("end");
+}
+
+static void __free_devinf_datastore(DevInfDataStore *pDevInfDataStore)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfDataStore)
+               return;
+
+       if (pDevInfDataStore->sourceref) {
+               free(pDevInfDataStore->sourceref);
+               pDevInfDataStore->sourceref = NULL;
+       }
+
+       if (pDevInfDataStore->displayname) {
+               free(pDevInfDataStore->displayname);
+               pDevInfDataStore->displayname = NULL;
+       }
+
+       __free_devinf_contenttype(pDevInfDataStore->rxPref);
+       pDevInfDataStore->rxPref = NULL;
+
+       __free_devinf_contenttype(pDevInfDataStore->txPref);
+       pDevInfDataStore->txPref = NULL;
+
+       /*free_FilterRx(filter_rx);*/
+       /*free_FilterCap(filterCap);*/
+
+       GList *iter = NULL;
+       for (iter = pDevInfDataStore->rx; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_contenttype(iter->data);
+       g_list_free(pDevInfDataStore->rx);
+
+       for (iter = pDevInfDataStore->tx; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_contenttype(iter->data);
+       g_list_free(pDevInfDataStore->tx);
+
+       for (iter = pDevInfDataStore->ctcaps; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_ctcaps(iter->data);
+       g_list_free(pDevInfDataStore->ctcaps);
+
+       free(pDevInfDataStore);
+
+       FW_LOGV("end");
+
+}
+
+static void __free_devinf_contenttype(DevInfContentType *pDevInfContentType)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfContentType)
+               return;
+
+       if (pDevInfContentType->cttype) {
+               free(pDevInfContentType->cttype);
+               pDevInfContentType->cttype = NULL;
+       }
+
+       if (pDevInfContentType->verct) {
+               free(pDevInfContentType->verct);
+               pDevInfContentType->verct = NULL;
+       }
+
+       free(pDevInfContentType);
+
+       FW_LOGV("end");
+}
+
+static void __free_devinf_ctcaps(DevInfCTCap *pDevInfCTCap)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfCTCap)
+               return;
+
+       __free_devinf_contenttype(pDevInfCTCap->ct);
+       pDevInfCTCap->ct = NULL;
+
+       GList *iter = NULL;
+       for (iter = pDevInfCTCap->properties; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_property(iter->data);
+
+       g_list_free(pDevInfCTCap->properties);
+
+       free(pDevInfCTCap);
+
+       FW_LOGV("end");
+
+}
+
+static void __free_devinf_property(DevInfProperty *pDevInfProperty)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfProperty)
+               return;
+
+       if (pDevInfProperty->propName) {
+               free(pDevInfProperty->propName);
+               pDevInfProperty->propName = NULL;
+       }
+
+       if (pDevInfProperty->dataType) {
+               free(pDevInfProperty->dataType);
+               pDevInfProperty->dataType = NULL;
+       }
+
+       if (pDevInfProperty->displayName) {
+               free(pDevInfProperty->displayName);
+               pDevInfProperty->displayName = NULL;
+       }
+
+       GList *iter = NULL;
+       for (iter = pDevInfProperty->valEnums; iter != NULL; iter = g_list_next(iter))
+               free(iter->data);
+
+       g_list_free(pDevInfProperty->valEnums);
+
+
+       for (iter = pDevInfProperty->propParams; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_propparam(iter->data);
+
+       g_list_free(pDevInfProperty->propParams);
+
+       free(pDevInfProperty);
+
+       FW_LOGV("end");
+}
+
+static void __free_devinf_propparam(DevInfPropParam *pDevInfPropParam)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfPropParam)
+               return;
+
+       if (pDevInfPropParam->paramName) {
+               free(pDevInfPropParam->paramName);
+               pDevInfPropParam->paramName = NULL;
+       }
+
+       if (pDevInfPropParam->dataType) {
+               free(pDevInfPropParam->dataType);
+               pDevInfPropParam->dataType = NULL;
+       }
+
+       if (pDevInfPropParam->displayName) {
+               free(pDevInfPropParam->displayName);
+               pDevInfPropParam->displayName = NULL;
+       }
+
+       GList *iter = NULL;
+       for (iter = pDevInfPropParam->valEnums; iter != NULL; iter = g_list_next(iter))
+               free(iter->data);
+
+       g_list_free(pDevInfPropParam->valEnums);
+
+       free(pDevInfPropParam);
+
+       FW_LOGV("end");
+
+}
+
+static void __set_devinf_version(DevInf *devInf, DevInfVersion version)
+{
+       if (!devInf)
+               return;
+
+       devInf->version = version;
+}
+
+static void __set_devinf_manufacturer(DevInf *devInf, char *manufacturer)
+{
+       if (!devInf)
+               return;
+
+       if (manufacturer != NULL)
+               devInf->manufacturer = strdup(manufacturer);
+}
+
+static void __set_devinf_model(DevInf *devInf, char *model)
+{
+       if (!devInf)
+               return;
+
+       if (model != NULL)
+               devInf->model = strdup(model);
+}
+
+static void __set_devinf_oem(DevInf *devInf, char *oem)
+{
+       if (!devInf)
+               return;
+
+       if (oem != NULL)
+               devInf->oem = strdup(oem);
+}
+
+static void __set_devinf_software_version(DevInf *devInf, char *softwareVersion)
+{
+       if (!devInf)
+               return;
+
+       if (softwareVersion != NULL)
+               devInf->softwareVersion = strdup(softwareVersion);
+}
+
+static void __set_devinf_hardware_version(DevInf *devInf, char *hardwareVersion)
+{
+       if (!devInf)
+               return;
+
+       if (hardwareVersion != NULL)
+               devInf->hardwareVersion = strdup(hardwareVersion);
+}
+
+static void __set_devinf_firmware_version(DevInf *devInf, char *firmwareVersion)
+{
+       if (!devInf)
+               return;
+
+       if (firmwareVersion != NULL)
+               devInf->firmwareVersion = strdup(firmwareVersion);
+}
+
+static void __set_devinf_datastore(DevInf *devInf, DevInfDataStore *devInfDataStore)
+{
+       if (!devInf)
+               return;
+
+       devInf->datastores = g_list_append(devInf->datastores, devInfDataStore);
+}
+
+static void __set_devinf_datastore_rxpref(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType)
+{
+       if (!devInfDataStore)
+               return;
+
+       devInfDataStore->rxPref = devInfContentType;
+}
+
+static void __set_devinf_datastore_txpref(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType)
+{
+       if (!devInfDataStore)
+               return;
+
+       devInfDataStore->txPref = devInfContentType;
+}
+
+static void __set_devinf_datastore_ctcap(DevInfDataStore *devInfDataStore, DevInfCTCap *devInfCTCap)
+{
+       if (!devInfDataStore)
+               return;
+
+       devInfDataStore->ctcaps = g_list_append(devInfDataStore->ctcaps, devInfCTCap);
+}
+
+static void __set_devinf_ctcap_property(DevInfCTCap *devInfCTCap, DevInfProperty *devInfProperty)
+{
+       if (!devInfCTCap)
+               return;
+
+       devInfCTCap->properties = g_list_append(devInfCTCap->properties, devInfProperty);
+}
+
+static void __set_devInf_property_valenums(DevInfProperty *devInfProperty, char*valEnum)
+{
+       if (!devInfProperty)
+               return;
+
+       if (valEnum != NULL)
+               devInfProperty->valEnums = g_list_append(devInfProperty->valEnums, strdup(valEnum));
+}
+
+static DevInfDevTyp __convert_devtyp(char *devTyp)
+{
+       DevInfDevTyp devInfDevTyp = DEVINF_DEVTYPE_UNKNOWN;
+
+       if (strcmp(devTyp, DEFINE_DEVICE_TYPE_PAGER) == 0)
+               devInfDevTyp = DEVINF_DEVTYPE_PAGER;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_HANDHELD) == 0)
+               devInfDevTyp = DEVINF_DEVTYPE_HANDHELD;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_PDA) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_PDA;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_PHONE) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_PHONE;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_SMARTPHONE) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_SMARTPHONE;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_SERVER) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_SERVER;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_WORKSTATION) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_WORKSTATION;
+
+       return devInfDevTyp;
+}
+
+SA_ErrorType create_devinf(Session *session, DevInf **pDevInf)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       DCI_RETURN err = DCI_SUCCESS;
+
+       char *devID = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &devID);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *devTyp = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevTyp", &devTyp);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       DevInfDevTyp  devInfDevTyp = DEVINF_DEVTYPE_UNKNOWN;
+       if (devTyp != NULL)
+               devInfDevTyp = __convert_devtyp(devTyp);
+
+       DevInfVersion devInfVersion = DEVINF_VERSION_UNKNOWN;
+       if (session->protocolVersion == VERSION_10)
+               devInfVersion = DEVINF_VERSION_10;
+       else if (session->protocolVersion == VERSION_11)
+               devInfVersion = DEVINF_VERSION_11;
+       else if (session->protocolVersion == VERSION_12)
+               devInfVersion = DEVINF_VERSION_12;
+
+       char *man = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "Man", &man);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *model = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "Mod", &model);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *oem = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "OEM", &oem);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *swv = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "SwV", &swv);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *hwv = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "HwV", &hwv);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *fwv = "1.0";
+       /*
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "FwV", &fwv);
+       if (err != DCI_SUCCESS) {
+               errorType = ERROR_INTERNAL_ERROR;
+               goto error;
+       }
+       */
+
+       FW_LOGV("devID = %s",  devID);
+       FW_LOGV("devTyp = %s", devTyp);
+       FW_LOGV("man = %s",  man);
+       FW_LOGV("model = %s", model);
+       FW_LOGV("oem = %s", oem);
+       FW_LOGV("swv = %s", swv);
+       FW_LOGV("hwv = %s",  hwv);
+       FW_LOGV("fwv = %s",  fwv);
+
+       DevInf *pTempDevInf = NULL;
+       errorType = __create_devinf_new(devID, devInfDevTyp, &pTempDevInf);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create devInf New");
+               goto error;
+       }
+
+       __set_devinf_version(pTempDevInf, devInfVersion);
+       __set_devinf_manufacturer(pTempDevInf, man);
+       __set_devinf_model(pTempDevInf, model);
+       __set_devinf_oem(pTempDevInf, oem);
+       __set_devinf_software_version(pTempDevInf, swv);
+       __set_devinf_hardware_version(pTempDevInf, hwv);
+       __set_devinf_firmware_version(pTempDevInf, fwv);
+
+       pTempDevInf->supportsLargeObjs = 1;
+       pTempDevInf->supportsUTC = 1;
+       pTempDevInf->supportsNumberOfChanges = 1;
+
+       /*TODO Implements call log datastore's datastore for device info */
+       /* TYPE_CONTENT_COUNT -1 -> not include calllog datastore */
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT - 1; content_type++) {
+
+               if (datastoreinfo_per_content_type[content_type]->source != NULL) {
+                       DevInfDataStore *devInfDataStore = NULL;
+                       errorType = create_devinf_datastore(datastoreinfo_per_content_type[content_type]->source, &devInfDataStore);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfDataStore");
+                               goto error;
+                       }
+
+                       Object_Info *datastore = T_DACI_Get_Obj_Info(content_type);
+
+                       FW_LOGV("datastore->type = %s",  datastore->type);
+                       FW_LOGV("datastore->version = %s",  datastore->version);
+                       FW_LOGV("datastore->field_cnt = %d",  datastore->field_cnt);
+
+                       DevInfContentType *devInfContentTypeRxPref = NULL;
+                       errorType = __create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeRxPref);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfContentType");
+                               goto error;
+                       }
+                       __set_devinf_datastore_rxpref(devInfDataStore, devInfContentTypeRxPref);
+
+                       DevInfContentType *devInfContentTypeTxPref = NULL;
+                       errorType = __create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeTxPref);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfContentType");
+                               goto error;
+                       }
+                       __set_devinf_datastore_txpref(devInfDataStore, devInfContentTypeTxPref);
+
+                       DevInfContentType *devInfContentTypeCTCap = NULL;
+                       errorType = __create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeCTCap);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfContentType");
+                               goto error;
+                       }
+
+                       DevInfCTCap *devInfCTCap = NULL;
+                       errorType = __create_devinf_ctcap(devInfContentTypeCTCap , &devInfCTCap);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfCTCap");
+                               goto error;
+                       }
+
+                       DevInfProperty *devInfProperty = NULL;
+                       Field_Info field_list;
+                       int i;
+                       for (i = 0; i < datastore->field_cnt; i++) {
+                               field_list = datastore->field_list[i];
+                               errorType = __create_devinf_property(field_list.field_name, &devInfProperty);
+                               if (errorType != SA_INTERNAL_OK) {
+                                       FW_LOGE("failed to create devInfProperty");
+                                       goto error;
+                               }
+
+                               Field_Info children_field_list;
+                               int j;
+                               for (j = 0; j < field_list.field_child_cnt; j++) {
+                                       children_field_list = field_list.field_child_list[j];
+                                       __set_devInf_property_valenums(devInfProperty, children_field_list.field_name);
+                               }
+                               __set_devinf_ctcap_property(devInfCTCap, devInfProperty);
+                       }
+
+                       __set_devinf_datastore_ctcap(devInfDataStore, devInfCTCap);
+
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_TWO_WAY, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_SLOW_SYNC, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_SERVER, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC, 1);
+
+                       __set_devinf_datastore(pTempDevInf, devInfDataStore);
+
+                       /*free datastore*/
+                       T_DACI_Free_Obj_Info(content_type, datastore);
+               }
+       }
+
+       if (devID)
+               free(devID);
+       if (devTyp)
+               free(devTyp);
+       if (man)
+               free(man);
+       if (model)
+               free(model);
+       if (oem)
+               free(oem);
+       if (swv)
+               free(swv);
+       if (hwv)
+               free(hwv);
+/*     if (fwv)
+               free(fwv);*/
+
+       *pDevInf = pTempDevInf;
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+
+       if (devID)
+               free(devID);
+       if (devTyp)
+               free(devTyp);
+       if (man)
+               free(man);
+       if (model)
+               free(model);
+       if (oem)
+               free(oem);
+       if (swv)
+               free(swv);
+       if (hwv)
+               free(hwv);
+/*     if (fwv)
+               free(fwv);*/
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+void free_devinf(DevInf *devInf)
+{
+       FW_LOGV("start");
+       if (!devInf)
+               return;
+
+       if (devInf->manufacturer) {
+               free(devInf->manufacturer);
+               devInf->manufacturer = NULL;
+       }
+
+       if (devInf->model) {
+               free(devInf->model);
+               devInf->model = NULL;
+       }
+
+       if (devInf->oem) {
+               free(devInf->oem);
+               devInf->oem = NULL;
+       }
+
+
+       if (devInf->softwareVersion) {
+               free(devInf->softwareVersion);
+               devInf->softwareVersion = NULL;
+       }
+
+
+       if (devInf->hardwareVersion) {
+               free(devInf->hardwareVersion);
+               devInf->hardwareVersion = NULL;
+       }
+
+
+       if (devInf->firmwareVersion) {
+               free(devInf->firmwareVersion);
+               devInf->firmwareVersion = NULL;
+       }
+
+
+       if (devInf->devid) {
+               free(devInf->devid);
+               devInf->devid = NULL;
+       }
+
+       __free_devinf_datastores(devInf->datastores);
+       devInf->datastores = NULL;
+
+       free(devInf);
+
+       FW_LOGV("end");
+}
+
+void set_devInf_datastore_synccap(DevInfDataStore *devInfDataStore, DevInfSyncCap cap, int supported)
+{
+       if (supported)
+               devInfDataStore->synccap = devInfDataStore->synccap | cap;
+       else
+               devInfDataStore->synccap = devInfDataStore->synccap & ~cap;
+}
+
+int get_devinf_datastore_synccap(const DevInfDataStore *devInfDataStore, DevInfSyncCap cap)
+{
+       return devInfDataStore->synccap & cap ? 1 : 0;
+}
+
+DevInfSyncCap convert_devinf_synccap(unsigned int id)
+{
+       DevInfSyncCap result = DEVINF_SYNCTYPE_UNKNOWN;
+
+       switch (id) {
+               case DEVINF_SYNCTYPE_TWO_WAY:
+                       result = DEVINF_SYNCTYPE_TWO_WAY;
+                       break;
+               case DEVINF_SYNCTYPE_SLOW_SYNC:
+                       result = DEVINF_SYNCTYPE_SLOW_SYNC;
+                       break;
+               case DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT:
+                       result = DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT;
+                       break;
+               case DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT:
+                       result = DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT;
+                       break;
+               case DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER:
+                       result = DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER;
+                       break;
+               case DEVINF_SYNCTYPE_REFRESH_FROM_SERVER:
+                       result = DEVINF_SYNCTYPE_REFRESH_FROM_SERVER;
+                       break;
+               case DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC:
+                       result = DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC;
+                       break;
+               default:
+                       return DEVINF_SYNCTYPE_UNKNOWN;
+                       break;
+       }
+       return result;
+}
+
+
+/*
+static ErrorType create_DevInfPropParam(char *paramName, DevInfPropParam **pDevInfPropParam)
+{
+       FW_LOGV("start");
+
+       ErrorType errorType = ERROR_INTERNAL_OK;
+
+       if (!paramName) {
+               errorType = ERROR_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfPropParam = (DevInfPropParam *)calloc(1, sizeof(DevInfPropParam));
+       if (*pDevInfPropParam == NULL) {
+               errorType = ERROR_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfPropParam)->paramName = strdup(paramName);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+
+static void set_DevInfDataStoreDisplayname(DevInfDataStore* devInfDataStore, char *displayname) {
+
+       if (!devInfDataStore)
+               return;
+
+       devInfDataStore->displayname = strdup(displayname);
+}
+
+static void set_DevInfDataStoreRx(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType) {
+       if (!devInfDataStore)
+                       return;
+
+       devInfDataStore->rx = g_list_append(devInfDataStore->rx, devInfContentType);
+}
+
+static void set_DevInfDataStoreTx(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType) {
+       if (!devInfDataStore)
+                       return;
+
+       devInfDataStore->tx = g_list_append(devInfDataStore->tx, devInfContentType);
+}
+
+
+static void set_DevInfPropertyDataType(DevInfProperty *devInfProperty, char *dataType) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->dataType = strdup(dataType);
+}
+
+static void set_DevInfPropertyMaxOccur(DevInfProperty *devInfProperty, unsigned int maxOccur) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->maxOccur = maxOccur;
+}
+
+static void set_DevInfPropertyMaxSize(DevInfProperty *devInfProperty, unsigned int maxSize) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->maxSize = maxSize;
+}
+
+static void set_DevInfPropertyNoTruncate(DevInfProperty *devInfProperty, int noTruncate) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->noTruncate = noTruncate;
+}
+
+static void set_DevInfPropertyDisplayName(DevInfProperty *devInfProperty, char *displayName) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->displayName = strdup(displayName);
+}
+
+static void set_DevInfPropertyPropParam(DevInfProperty *devInfProperty, DevInfPropParam *devInfPropParam) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->propParams = g_list_append(devInfProperty->propParams, devInfPropParam);
+}
+
+static void set_DevInfPropParamDataType(DevInfPropParam *devInfPropParam, char *dataType) {
+
+       if (!devInfPropParam)
+               return;
+
+       devInfPropParam->dataType = strdup(dataType);
+}
+
+static void set_DevInfPropParamDisplayName(DevInfPropParam *devInfPropParam, char *displayName) {
+
+       if (!devInfPropParam)
+               return;
+
+       devInfPropParam->displayName = strdup(displayName);
+}
+
+static void set_DevInfPropParamValEnums(DevInfPropParam *devInfPropParam, char *valEnum) {
+
+       if (!devInfPropParam)
+               return;
+
+       devInfPropParam->valEnums = g_list_append(devInfPropParam->valEnums, strdup(valEnum));
+ }
+*/
diff --git a/ServiceAdapter/SA_Elements.c b/ServiceAdapter/SA_Elements.c
new file mode 100644 (file)
index 0000000..4121313
--- /dev/null
@@ -0,0 +1,819 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Elements.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions for structures which is used in Service Adapter
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+#include "ServiceAdapter/SA_Command.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+SA_ErrorType create_anchor(char *last, char *next, Anchor **pAnchor)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!next) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pAnchor = (Anchor *)calloc(1, sizeof(Anchor));
+       if (*pAnchor == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       if (last)
+               (*pAnchor)->lastAnchor = strdup(last);
+
+       (*pAnchor)->nextAnchor = strdup(next);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_item_anchor(Item *item, Anchor *anchor)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!item) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!anchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (item->anchor) {
+               free_anchor(item->anchor);
+               item->anchor = NULL;
+       }
+
+       Anchor *pAnchor = NULL;
+       errorType = create_anchor(anchor->lastAnchor, anchor->nextAnchor, &pAnchor);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+       item->anchor = pAnchor;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_last_anchor(Anchor *anchor, char *lastAnchor)
+{
+       FW_LOGV("start with lastAnchor = %s\n", lastAnchor);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!anchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (lastAnchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       anchor->lastAnchor = lastAnchor;
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_next_anchor(Anchor *anchor, char *nextAnchor)
+{
+       FW_LOGV("start with nextAnchor = %s\n", nextAnchor);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!anchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (nextAnchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       anchor->nextAnchor = nextAnchor;
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+void free_anchor(Anchor *pAnchor)
+{
+       FW_LOGV("start");
+
+       if (!pAnchor)
+               return;
+
+       if (pAnchor->lastAnchor) {
+               free(pAnchor->lastAnchor);
+               pAnchor->lastAnchor = NULL;
+       }
+
+       if (pAnchor->nextAnchor) {
+               free(pAnchor->nextAnchor);
+               pAnchor->nextAnchor = NULL;
+       }
+
+       free(pAnchor);
+       pAnchor = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+SA_ErrorType create_location(char *locURI, char *locName, Location **pLocation)
+{
+       FW_LOGV("start with locURI = %s, locName = %s\n", locURI, locName);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!locURI) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pLocation = (Location *) calloc(1, sizeof(Location));
+       /*              calloc된 *pLocation에 대한 null check로 변경
+        *              2011.09.28 seokgil kang
+        */
+       if (!(*pLocation)) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pLocation)->locURI = strdup(locURI);
+
+       if (locName)
+               (*pLocation)->locName = strdup(locName);
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+Location *dup_location(Location* pLocation)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pLocation) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       Location *location = NULL;
+       errorType = create_location(pLocation->locURI, pLocation->locName, &location);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("end");
+
+       return location;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+
+}
+
+char  *get_location_locname(Location *location)
+{
+       if (!location)
+               return NULL;
+
+       return location->locName;
+}
+
+char *get_location_locuri(Location *location)
+{
+       if (!location)
+               return NULL;
+
+       return location->locURI;
+}
+
+void free_location(Location *loc)
+{
+       FW_LOGV("start");
+
+       if (!loc)
+               return;
+
+       FW_LOGV("loc->locURI = %s", loc->locURI);
+       if (loc->locURI)
+               free(loc->locURI);
+
+       FW_LOGV("loc->locName = %s", loc->locName);
+       if (loc->locName)
+               free(loc->locName);
+
+       free(loc);
+       loc = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+SA_ErrorType create_cred(char *userName, char *pwd, AuthType authType, FormatType formatType , char *data, Cred **cred)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (userName ==  NULL || !strlen(userName)) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+       if (pwd ==  NULL || !strlen(pwd)) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+       if (data == NULL) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *cred = (Cred *)calloc(1, sizeof(Cred));
+       if (*cred == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*cred)->type = authType;
+       (*cred)->format = formatType;
+       (*cred)->username = strdup(userName);
+       (*cred)->password = strdup(pwd);
+
+       (*cred)->data = strdup(data);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+
+}
+
+void free_cred(Cred *cred)
+{
+       FW_LOGV("start");
+
+       if (!cred)
+               return;
+
+       if (cred->data) {
+               free(cred->data);
+               cred->data = NULL;
+       }
+
+       if (cred->username) {
+               free(cred->username);
+               cred->username = NULL;
+       }
+
+       if (cred->password) {
+               free(cred->password);
+               cred->password = NULL;
+       }
+
+       free(cred);
+       cred = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+void free_chal(Chal *chal)
+{
+       FW_LOGV("start");
+
+       if (!chal)
+               return;
+
+       if (chal->nonce_plain) {
+               free(chal->nonce_plain);
+               chal->nonce_plain = NULL;
+       }
+
+       if (chal->nonce_b64) {
+               free(chal->nonce_b64);
+               chal->nonce_b64 = NULL;
+       }
+
+       free(chal);
+
+       FW_LOGV("end");
+
+       return;
+}
+
+Cred *create_cred_with_data(AuthType authType, char *data)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Cred *cred = (Cred *)calloc(1, sizeof(Cred));
+       if (!cred) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       cred->type = authType;
+       if (data != NULL)
+               cred->data = strdup(data);
+
+       FW_LOGV("end");
+
+       return cred;
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+
+}
+
+void set_cred_format_type(Cred *cred, FormatType formatType)
+{
+       if (!cred)
+               return;
+
+       cred->format = formatType;
+}
+
+SA_ErrorType create_syncml(SyncHdr *syncHdr, GList *status, GList *commands, int isFinal , SyncML **pSyncML)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!syncHdr) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pSyncML = (SyncML *) calloc(1, sizeof(SyncML));
+
+       if (*pSyncML == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pSyncML)->hdr = syncHdr ;
+       (*pSyncML)->status = status;
+       (*pSyncML)->commands = commands;
+       (*pSyncML)->final = isFinal;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+
+}
+
+void free_syncml(SyncML *syncML)
+{
+       FW_LOGV("start");
+
+       if (!syncML)
+               return;
+
+       free_synchdr(syncML->hdr);
+       syncML->hdr = NULL;
+
+       free_statuses(syncML->status);
+       syncML->status = NULL;
+
+       free_commands(syncML->commands);
+       syncML->commands = NULL;
+
+       free(syncML);
+
+       FW_LOGV("end");
+
+       return;
+}
+
+SA_ErrorType create_synchdr(Session *session , SyncHdr **pSyncHdr)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!session->protocolVersion) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!session->protocolType) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!session->source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!session->target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pSyncHdr = (SyncHdr *)calloc(1, sizeof(SyncHdr));
+
+       if (*pSyncHdr == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pSyncHdr)->version =  session->protocolVersion;
+       (*pSyncHdr)->protocol = session->protocolType;
+       (*pSyncHdr)->target = dup_location(session->target);
+       (*pSyncHdr)->source = dup_location(session->source);
+
+       if (session->cred)
+               (*pSyncHdr)->cred  = dup_cred(session->cred);
+
+       if (session->sessionID)
+               (*pSyncHdr)->sessionID = strdup(session->sessionID);            /*free*/
+
+       (*pSyncHdr)->messageID = ++session->msgID;
+
+       (*pSyncHdr)->maxmsgsize = session->sourceMaxMsgSize;
+       (*pSyncHdr)->maxobjsize = session->sourceMaxObjSize;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+void free_synchdr(SyncHdr *syncHdr)
+{
+       FW_LOGV("start");
+
+       if (!syncHdr)
+               return;
+
+       if (syncHdr->sessionID) {
+               free(syncHdr->sessionID);
+               syncHdr->sessionID = NULL;
+       }
+
+       if (syncHdr->responseURI) {
+               free(syncHdr->responseURI);
+               syncHdr->responseURI = NULL;
+       }
+
+       if (syncHdr->source) {
+               free_location(syncHdr->source);
+               syncHdr->source = NULL;
+       }
+
+       if (syncHdr->target) {
+               free_location(syncHdr->target);
+               syncHdr->target = NULL;
+       }
+
+       if (syncHdr->cred) {
+               free_cred(syncHdr->cred);
+               syncHdr->cred = NULL;
+       }
+
+       free(syncHdr);
+
+       FW_LOGV("end");
+
+       return;
+}
+
+Item *create_item()
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Item *item = (Item *)calloc(1, sizeof(Item));
+       if (!item) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       item->dataType = ITEM_UNKNOWN;
+       FW_LOGV("end");
+
+       return item;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+}
+
+Item *create_item_for_data(const char *data, unsigned int size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Item *item = create_item();
+       if (!item) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       item->dataType = ITEM_DATA;
+       if (data != NULL)
+               item->private.data = strdup(data);
+
+       item->size = size;
+
+       FW_LOGV("end");
+
+       return item;
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+}
+
+Item *create_item_for_devinf(DevInf *devInf)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!devInf) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       Item *item = create_item();
+       if (!item) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       item->dataType = ITEM_DEVINF;
+       item->private.devInf = devInf;
+
+       FW_LOGV("end");
+
+       return item;
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+}
+
+void set_item_target(Item *item, Location *target)
+{
+       if (item)
+               item->target = target;
+}
+
+void set_item_source(Item *item, Location *source)
+{
+       if (item)
+               item->source = source;
+}
+
+void free_item(Item *item)
+{
+       FW_LOGV("start");
+
+       if (!item)
+               return;
+
+       if (item->source) {
+               free_location(item->source);
+               item->source = NULL;
+       }
+
+       if (item->target) {
+               free_location(item->target);
+               item->target = NULL;
+       }
+
+       if (item->anchor) {
+               free_anchor(item->anchor);
+               item->anchor = NULL;
+       }
+
+       switch (item->dataType) {
+       case ITEM_DATA:
+               free(item->private.data);
+               break;
+       case ITEM_DEVINF:
+               /*devinf is pointed from session. so doesnot need to free here*/
+               item->private.devInf = NULL;
+               break;
+       case ITEM_UNKNOWN:
+               /*noting to free*/
+               break;
+       }
+
+       if (item->contenttype) {
+               free(item->contenttype);
+               item->contenttype = NULL;
+       }
+
+       free(item);
+       item = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+Chal *dup_chal(Chal *pChal)
+{
+       FW_LOGV("start");
+
+       if (!pChal) {
+               FW_LOGV("pChal is null");
+               return NULL;
+       }
+
+       Chal *temp = (Chal *)calloc(1, sizeof(Chal));
+
+       if (pChal->type)
+               temp->type = pChal->type;
+
+       if (pChal->format)
+               temp->format = pChal->format;
+
+       if (pChal->nonce_b64)
+               temp->nonce_b64 = strdup(pChal->nonce_b64);
+
+       if (pChal->nonce_length)
+               temp->nonce_length = pChal->nonce_length;
+
+       if (pChal->nonce_plain)
+               temp->nonce_plain = strdup(pChal->nonce_plain);
+
+       FW_LOGV("end");
+
+       return temp;
+}
+
+Cred *dup_cred(Cred *pCred)
+{
+       FW_LOGV("start");
+
+       if (!pCred) {
+               FW_LOGV("pCred is null");
+               return NULL;
+       }
+
+       Cred *temp = (Cred *)calloc(1, sizeof(Cred));
+
+       if (pCred->type)
+               temp->type = pCred->type;
+
+       if (pCred->format)
+               temp->format = pCred->format;
+
+       if (pCred->username)
+               temp->username = strdup(pCred->username);
+
+       if (pCred->password)
+               temp->password = strdup(pCred->password);
+
+       if (pCred->data)
+               temp->data = strdup(pCred->data);
+
+       FW_LOGV("end");
+
+       return temp;
+}
+
+SA_ErrorType compare_cred(Cred *hdrCred, Cred *sessionCred)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!hdrCred) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!sessionCred) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (strcmp(hdrCred->data, sessionCred->data) == 0)
+               errorType = SA_INTERNAL_OK;
+       else
+               errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+AuthType convert_auth_type(char *authType)
+{
+       if (!authType)
+               return AUTH_TYPE_UNKNOWN;
+
+       if (!strcmp(authType, ELEMENT_AUTH_BASIC)) {
+               return AUTH_TYPE_BASIC;
+       } else if (!strcmp(authType, ELEMENT_AUTH_MD5)) {
+               return AUTH_TYPE_MD5;
+       }
+
+       return AUTH_TYPE_UNKNOWN;
+}
+
+FormatType convert_format_type(char *formatType)
+{
+       if (!formatType)
+               return FORMAT_TYPE_UNKNOWN;
+
+       if (!strcmp(formatType, ELEMENT_FORMAT_BASE64)) {
+               return FORMAT_TYPE_BASE64;
+       }
+
+       return FORMAT_TYPE_UNKNOWN;
+}
diff --git a/ServiceAdapter/SA_Session.c b/ServiceAdapter/SA_Session.c
new file mode 100644 (file)
index 0000000..f40da33
--- /dev/null
@@ -0,0 +1,1442 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Session.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions for Session structure which is used in Service Adapter and processing receive command & status
+ */
+
+/*FIXME temporary*/
+#include "agent-framework/SyncAgent_Info.h"
+
+#include "agent-framework/DACI/DACI_Luid.h"
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Util.h"
+#include "ServiceAdapter/SA_Session.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Command.h"
+#include "ServiceAdapter/SA_Command_Internal.h"
+#include "ServiceAdapter/SA_DevInf.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+static SA_ErrorType __receive_alert_status(Session *session, Status *status);
+static SA_ErrorType __receive_put_status(Session *session, Status *status);
+static SA_ErrorType __receive_get_status(Session *session, Status *status);
+static SA_ErrorType __receive_results_status(Session *session, Status *status);
+static SA_ErrorType __receive_sync_status(Session *session, Status *status);
+static SA_ErrorType __receive_changes_status(Session *session, Status *status, GList **returnStatus);
+static SA_ErrorType __receive_map_status(Session *session, Status *status);
+
+static SA_ErrorType __receive_alert_command(Session *session, Command *command, GList **returnDatastore);
+static SA_ErrorType __receive_put_command(Session *session, Command *command);
+static SA_ErrorType __receive_get_command(Session *session, Command *command);
+static SA_ErrorType __receive_results_command(Session *session, Command *command);
+static SA_ErrorType __receive_sync_command(Session *session, Command *command, ChangedDatastore **changedDatastore);
+static SA_ErrorType __receive_changes_command(Session *session, Command *command,
+                                                               char **luid_str_list, int *index, ChangedDatastore **changedDatastore);
+
+static void __free_pending_status(PendingStatus *pendingStatus);
+static SA_ErrorType __add_mapping(Session *session, char *guid, char *luid, int datastore_id);
+
+
+static SA_ErrorType __receive_alert_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400 && code != ERROR_REQUIRE_REFRESH) {
+               /*401   unauthorized
+               407     Authentication required
+               405     command not allowed
+               406     optional feature not supported
+               500     command failed
+               412     Incomplete command
+               415 unsupported media type or format
+               404 not found ->it have to be considered
+               TODO error handling it's error~!!!!!*/
+
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_COMMAND_NOT_ALLOWED || code == ERROR_UNSUPPORTED_FEATURE || code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else if (code == ERROR_NOT_FOUND) {
+                       /*do not need to return errorType when code is ERROR_NOT_FOUND*/
+
+               }
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_put_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400) {
+               /*TODO error handling it's error~!!!!!
+               401 unauthorized
+               407 authentication required
+               411 size required
+               413 request entity too large
+               416 requested size too big
+               415 unspported media type or format
+               420 device full
+               500 command failed*/
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else
+                       errorType = SA_INTERNAL_ERROR;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_get_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400) {
+               /*TODO error handling it's error~!!!!!
+               401 unauthorized
+               407 authentication required
+               404 not found
+               413 request entity too large
+               415 unspported media type or format
+               500 command failed*/
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_NOT_FOUND)
+                       errorType = SA_INTERNAL_NOT_FOUND;
+               else if (code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else
+                       errorType = SA_INTERNAL_ERROR;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_results_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400) {
+               /*TODO error handling it's error~!!!!!
+               401 unauthorized
+               407 authentication required
+               404 not found
+               413 request entity too large
+               415 unspported media type or format
+               500 command failed*/
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_NOT_FOUND)
+                       errorType = SA_INTERNAL_NOT_FOUND;
+               else if (code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else
+                       errorType = SA_INTERNAL_ERROR;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_sync_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400 && code != ERROR_REQUIRE_REFRESH) {
+               /*TODO error handling it's error~!!!!!
+               401 unauthorized
+               407 authentication required
+               403 forbidden
+               404 not found
+               405 command not allowed
+               508 refresh required
+               500 command failed*/
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_NOT_FOUND)
+                       errorType = SA_INTERNAL_NOT_FOUND;
+               else if (code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else
+                       errorType = SA_INTERNAL_ERROR;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_changes_status(Session *session, Status *status, GList **returnStatus)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("cmdID = %d", status->cmdID);
+       FW_LOGV("msgRef = %d", status->msgRef);
+       FW_LOGV("cmdRef = %d", status->cmdRef);
+       FW_LOGV("type = %d", status->type);
+       FW_LOGV("data = %s", status->data);
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (session->largeObj) {
+               /*LargeObj status it does not need to pass engine*/
+               PendingStatus *largeObj = session->largeObj;
+               if (largeObj->cmdID == status->cmdRef && largeObj->msgID == status->msgRef) {
+
+                       if (code == CHUNK_ACCEPTED) {
+                               __free_pending_status(largeObj);
+                               session->largeObj = NULL;
+                               return errorType;
+                       } else if (code == ERROR_REQUESTED_SIZE_TOO_BIG) {
+                               /*TODO error handling for large obj
+                               can not send this item*/
+                       } else if (code == ERROR_SIZE_REQUIRED) {
+
+                       }
+               }
+       }
+
+       /*pass to engine*/
+       if (status->sourceRef) {
+               AppliedStatus *appliedStatus = create_appliedstatus(get_location_locuri(status->sourceRef),
+                                                                                                                       convert_change_type_command_type(status->type) , code);
+               if (appliedStatus == NULL) {
+                       FW_LOGE("failed in create_appliedstatus");
+                       return SA_INTERNAL_NO_MEMORY;
+               }
+               *returnStatus = g_list_append(*returnStatus, appliedStatus);
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_map_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       DACI_RETURN da_err ;
+
+       GList *iter = NULL;
+       Command *pCommand = NULL;
+       unsigned int code = 0;
+       for (iter = session->mapCommand;  iter != NULL; iter = g_list_next(iter)) {
+               pCommand = iter->data;
+
+               if (pCommand->msgID == status->msgRef && pCommand->cmdID == status->cmdRef) {
+                       code = get_status_code(status);
+                       FW_LOGV("code = %d", code);
+
+                       if (code == 200) {
+                               GList *itemIter = NULL;
+                               Item *item = NULL;
+                               for (itemIter = pCommand->private.map.items; itemIter != NULL; itemIter = g_list_next(itemIter)) {
+                                       item = itemIter->data;
+                                       FW_LOGV(" LUID  = %s has been removed\n", get_location_locuri(item->source));
+                                       da_err = DACI_Delete_Mapping_By_Luid(session->accountId,  get_location_locuri(item->source));
+                                       if (da_err != DACI_SUCCESS) {
+                                               errorType = SA_INTERNAL_DA_ERROR;
+                                               FW_LOGE("failed in DACI_Delete_Mapping_By_Luid");
+                                               return errorType;
+                                       }
+                               }
+                               session->mapCommand  = g_list_remove(session->mapCommand , pCommand);
+                               free_command(pCommand);
+                               break;
+                       } else if (code >= 400) {
+                               /*401 unauthorized
+                               407 authentication required
+                               420 device full
+                               510 data store failure
+                               500 command failed*/
+
+                               if (code >= 500) {
+                                       /*map command has failed so delete failed map command from session->mapCpmmand*/
+                                       GList *itemIter = NULL;
+                                       Item *item = NULL;
+                                       for (itemIter = pCommand->private.map.items; itemIter != NULL; itemIter = g_list_next(itemIter)) {
+                                               item = itemIter->data;
+                                               FW_LOGV("LUID  = %s has been removed\n", get_location_locuri(item->source));
+                                               da_err = DACI_Delete_Mapping_By_Luid(session->accountId,  get_location_locuri(item->source));
+                                               if (da_err != DACI_SUCCESS) {
+                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                       FW_LOGE("failed in DACI_Delete_Mapping_By_Luid");
+                                                       return errorType;
+                                               }
+                                       }
+                                       session->mapCommand  = g_list_remove(session->mapCommand , pCommand);
+                                       free_command(pCommand);
+                                       break;
+                               }
+                               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+                               else if (code == ERROR_NOT_FOUND)
+                                       errorType = SA_INTERNAL_NOT_FOUND;
+                               else if (code == ERROR_GENERIC)
+                                       errorType = SA_INTERNAL_SERVER_ERROR;
+                               else
+                                       errorType = SA_INTERNAL_ERROR;
+                       }
+               }
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_alert_command(Session *session, Command *command, GList **returnDatastore)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!command->source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!command->target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+       /*401   unauthorized
+       407     Authentication required
+       405     command not allowed
+       406     optional feature not supported
+       500     command failed
+       412     Incomplete command
+       415 unsupported media type or format*/
+
+       Status *temp = NULL;
+       if (strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CONTACT]->source)  == 0 ||
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CALENDAR]->source)  == 0 ||
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_MEMO]->source)  == 0 ||
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CALLLOG]->source)  == 0) {
+
+               DatastoreInfo *datastore = create_datastoreinfo(get_location_locuri(command->target), get_location_locuri(command->source));
+               if (datastore == NULL) {
+                       errorType = SA_INTERNAL_NO_MEMORY;
+                       goto error;
+               }
+               set_datastoreInfo_synctype(datastore, command->private.alert.type);
+               set_datastoreinfo_lastanchor(datastore, command->private.alert.anchor->lastAnchor);
+               set_datastoreinfo_nextanchor(datastore, command->private.alert.anchor->nextAnchor);
+               set_datastoreinfo_maxobjsize(datastore, command->private.alert.maxObjSize);
+
+               *returnDatastore = g_list_append(*returnDatastore, datastore);
+
+               errorType = create_new_status(session, NO_ERROR, command,  COMMAND_TYPE_ALERT , &temp);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               temp->item = create_item();
+               if (!(temp->item)) {
+                       errorType = SA_INTERNAL_NO_MEMORY;
+                       goto error;
+               }
+               set_item_anchor(temp->item,  command->private.alert.anchor);
+               session->status = g_list_append(session->status, temp);
+
+       } else if (strcmp(get_location_locuri(command->target), get_location_locuri(session->source)) == 0 &&
+                       strcmp(get_location_locuri(command->source), get_location_locuri(session->target)) == 0) {
+
+               errorType = create_new_status(session, NO_ERROR, command,  COMMAND_TYPE_ALERT , &temp);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               session->status = g_list_append(session->status, temp);
+       } else
+               goto not_found_error;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_ALERT , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __receive_put_command(Session *session, Command *command)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       /*401 unauthorized
+       407 authentication required
+       411 size required
+       413 request entity too large
+       416 requested size too big
+       415 unspported media type or format
+       420 device full
+       500 command failed*/
+
+       Status *temp = NULL;
+
+       if (strcmp(command->private.access.type , ELEMENT_DEVINF_XML) == 0 ||
+                       strcmp(command->private.access.type , ELEMENT_DEVINF_WBXML) == 0) {
+               /*if it is devinf*/
+               if (command->private.access.item) {
+                       session->remoteDevInf = command->private.access.item->private.devInf;
+               }
+               errorType = create_new_status(session, NO_ERROR,  command,  COMMAND_TYPE_PUT, &temp);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+       } else
+               goto not_found_error;
+
+
+
+       session->status = g_list_append(session->status, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_PUT , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __receive_get_command(Session *session, Command *command)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Status *temp = NULL;
+       Command *pCommand = NULL;
+       Location *pLocation = NULL;
+
+       if (strcmp(command->private.access.type , ELEMENT_DEVINF_XML) == 0 ||
+                       strcmp(command->private.access.type , ELEMENT_DEVINF_WBXML) == 0) {
+
+               errorType = create_new_status(session, NO_ERROR,  command,  COMMAND_TYPE_GET, &temp);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               session->status = g_list_append(session->status, temp);
+
+               char *sourceDevInf = NULL;
+               if (session->protocolVersion == VERSION_10)
+                       sourceDevInf = ELEMENT_DEVINF_10;
+               else if (session->protocolVersion == VERSION_11)
+                       sourceDevInf = ELEMENT_DEVINF_11;
+               else if (session->protocolVersion == VERSION_12)
+                       sourceDevInf = ELEMENT_DEVINF_12;
+
+               errorType = create_location(sourceDevInf, NULL, &pLocation);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               errorType = create_results_command(session, pLocation, ELEMENT_DEVINF_XML, session->devInf, &pCommand);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               set_results_command_msgref(pCommand, command->msgID);
+               set_results_command_cmdref(pCommand, command->cmdID);
+               set_results_command_targetref(pCommand, command->private.access.item->target);
+
+               session->resultsCommand = g_list_append(session->resultsCommand, pCommand);
+       } else
+               goto not_found_error;
+
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_GET , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __receive_results_command(Session *session, Command *command)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Status *temp = NULL;
+
+       if (strcmp(command->private.results.type , ELEMENT_DEVINF_XML) == 0 ||
+                       strcmp(command->private.results.type , ELEMENT_DEVINF_WBXML) == 0) {
+               /*if it is devinf*/
+               if (command->private.results.item) {
+                       session->remoteDevInf = command->private.results.item->private.devInf;
+
+                       errorType = create_new_status(session, NO_ERROR,  command,  COMMAND_TYPE_RESULTS, &temp);
+                       if (errorType != SA_INTERNAL_OK)
+                               goto error;
+
+                       session->status = g_list_append(session->status, temp);
+               }
+       } else
+               goto not_found_error;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_RESULTS , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType  __receive_sync_command(Session *session, Command *command, ChangedDatastore **changedDatastore)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!command->source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               return errorType;
+       }
+
+       if (!command->target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               return errorType;
+       }
+
+       /*TODO
+       need to check that if target has not exist in client
+       it's a error(return status)
+       and return Datastore index
+
+       401 unauthorized
+       407 authentication required
+       403 forbidden
+       404 not founc
+       405 command not allowed
+       508 refresh required
+       500 command failed
+
+       TODO compare with alert command(?)*/
+
+       if (strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CONTACT]->source)  != 0 &&
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CALENDAR]->source)  != 0 &&
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_MEMO]->source)  != 0 &&
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CALLLOG]->source)  != 0)
+               goto not_found_error;
+
+       Status *temp = NULL;
+       errorType = create_new_status(session, NO_ERROR, command,  COMMAND_TYPE_SYNC_START , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+
+       /*for return to engine*/
+       ChangedDatastore *pChangedDatastore = create_changeddatastore(get_location_locuri(command->source),
+                                                                                                                                       get_location_locuri(command->target), command->private.sync.hasNumChanged,
+                                                                                                                                       command->private.sync.hasNumChanged ? command->private.sync.numChanged : 0);
+       if (pChangedDatastore == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       } else
+               *changedDatastore = pChangedDatastore;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_SYNC_START , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __receive_changes_command(Session *session, Command *command, char **luid_str_list,
+                                                                                                                                                       int *index, ChangedDatastore **changedDatastore)
+{
+       FW_LOGV("start command type :  %d\n",  command->private.change.type);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       GList *iter = NULL;
+       ChangedItem *changed = NULL;
+       char *luid;
+       ChangeType changeType = command->private.change.type;
+       for (iter = command->private.change.items; iter != NULL; iter = g_list_next(iter)) {
+               Item *changedItem = (iter->data);
+
+               if (changedItem->moreData) {
+                       if (session->pLargeObjCmd) {
+                               /*if there is a chunked item before...
+                               it's not firest chunked item.... data have to be merged(check source location)
+                               there will be another chunked item*/
+
+                               Command *pLargeObjcmd = session->pLargeObjCmd;
+                               if (pLargeObjcmd->private.change.items) {
+                                       /*moreData item must be last item in item list*/
+                                       GList *largeObjItems = session->pLargeObjCmd->private.change.items;
+                                       GList *largeObjLastItem = g_list_nth(largeObjItems, g_list_length(largeObjItems) - 1);
+                                       Item *item = largeObjLastItem->data;
+                                       AlertType alertType = ALERT_UNKNOWN;
+                                       if (strcmp(get_location_locuri(item->source), get_location_locuri(changedItem->source)) == 0) {
+                                               /*two item's source are equal
+                                               append incomming string*/
+                                               if (item->private.data) {
+                                                       char *tmp = g_strdup_printf("%s%s", item->private.data, changedItem->private.data);
+                                                       free(item->private.data);
+                                                       item->private.data = tmp;
+                                               } else {
+                                                       item->private.data = strdup(changedItem->private.data);
+                                               }
+                                               Status *temp = NULL;
+                                               errorType = create_new_status_location(session, CHUNK_ACCEPTED, command, changedItem->source,
+                                                                                                                               changedItem->target, convert_command_type_change_type(changeType), &temp);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed in create_new_status_location");
+                                                       goto error;
+                                               }
+                                               session->status = g_list_append(session->status, temp);
+                                               alertType = ALERT_NEXT_MESSAGE;
+                                       } else{
+                                               /* it's a new data object or command but this command also have a moreData*/
+                                               alertType = ALERT_NO_END_OF_DATA;
+                                       }
+                                       /* create alert command*/
+                                       Command *pAlertCommand = NULL;
+                                       errorType = create_alert_command(session, alertType, dup_location(session->source), dup_location(session->target),
+                                                                                                                                               NULL, NULL, NULL,  &pAlertCommand);
+                                       if (errorType != SA_INTERNAL_OK) {
+                                               FW_LOGE("failed in create_alert_command");
+                                               goto error;
+                                       }
+                                       session->alertCommand = g_list_append(session->alertCommand, pAlertCommand);
+                               }
+                       } else{
+                               /*first chunked item
+                               just buffered it. does not generate LUID, and does not pass to engine*/
+                               OMA_StatusType statusErrorType = ERROR_UNKNOWN;
+                               if (changedItem->size == 0) {
+                                       /*size required*/
+                                       statusErrorType = ERROR_SIZE_REQUIRED;
+                               } else{
+                                       /* size is specified*/
+                                       if (changedItem->size > session->sourceMaxObjSize) {
+                                               /*but it is bigger than client maxObjSize*/
+                                               statusErrorType = ERROR_REQUESTED_SIZE_TOO_BIG;
+                                       } else{
+                                               /*chunked item accepted*/
+                                               session->pLargeObjCmd = command;
+                                               increase_command_refcount(command);
+
+                                               statusErrorType = CHUNK_ACCEPTED;
+
+                                               /* create alert command*/
+                                               Command *pAlertCommand = NULL;
+                                               errorType = create_alert_command(session, ALERT_NEXT_MESSAGE,
+                                                                                                                                                       dup_location(session->source), dup_location(session->target),
+                                                                                                                                                       NULL, NULL,  NULL,  &pAlertCommand);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed in create_alert_command");
+                                                       goto error;
+                                               }
+                                               session->alertCommand = g_list_append(session->alertCommand, pAlertCommand);
+                                       }
+
+                                       Status *temp = NULL;
+                                       errorType = create_new_status_location(session, statusErrorType, command, changedItem->source, changedItem->target,
+                                                                                                                                                               convert_command_type_change_type(changeType) , &temp);
+                                       if (errorType != SA_INTERNAL_OK) {
+                                               FW_LOGE("failed in create_new_status_location");
+                                               goto error;
+                                       }
+                                       session->status = g_list_append(session->status, temp);
+                               }
+                       }
+               } else{
+                       if (session->pLargeObjCmd) {
+
+                               /*if there is a chunked item before...
+                                it's not firest chunked item.... data have to be merged(check source location)
+                                there will be no more chunked item. this command have to be pass to engine*/
+
+                               Command *pLargeObjcmd = session->pLargeObjCmd;
+                               if (pLargeObjcmd->private.change.items) {
+                                       /*moreData item must be last item in item list*/
+                                       GList *largeObjItems = session->pLargeObjCmd->private.change.items;
+                                       GList *largeObjLastItem = g_list_nth(largeObjItems, g_list_length(largeObjItems) - 1);
+                                       Item *item = largeObjLastItem->data;
+
+                                       if (strcmp(get_location_locuri(item->source), get_location_locuri(changedItem->source)) == 0) {
+                                               /* two item's source are equal
+                                               append incomming string*/
+                                               if (item->private.data) {
+                                                       char *tmp = g_strdup_printf("%s%s", item->private.data, changedItem->private.data);
+                                                       free(item->private.data);
+                                                       item->private.data = tmp;
+                                               } else {
+                                                       item->private.data = strdup(changedItem->private.data);
+
+                                                       if (item->private.data == NULL) {
+                                                               FW_LOGE("item->private.data is null !!");
+                                                               goto error;
+                                                       }
+                                               }
+
+                                               if (item->size == strlen(item->private.data)) {
+                                                       /*delete pointing from pLargeObjCmd*/
+                                                       largeObjLastItem->data = NULL;
+                                                       FW_LOGV("delete pointing from pLargeObjCmd");
+                                                       /*free Item from incomming Cmd*/
+                                                       free_item(changedItem);
+                                                       FW_LOGV("free Item from incomming Cmd");
+                                                       /*pointing to Merged item in incomming Cmd*/
+                                                       iter->data = item;
+                                                       changedItem = item;
+                                                       FW_LOGV("pointing to Merged item in incomming Cmd");
+
+                                                       free_command(session->pLargeObjCmd);
+                                                       session->pLargeObjCmd = NULL;
+                                               } else{
+                                                       Status *temp = NULL;
+                                                       errorType = create_new_status_location(session, ERROR_SIZE_MISMATCH, command,
+                                                                                                                                                               changedItem->source, changedItem->target,
+                                                                                                                                                               convert_command_type_change_type(changeType), &temp);
+                                                       if (errorType != SA_INTERNAL_OK) {
+                                                               FW_LOGE("failed in create_new_status_location");
+                                                               goto error;
+                                                       }
+                                                       session->status = g_list_append(session->status, temp);
+                                               }
+                                       } else{
+                                               /* it's a new data object or command send 223
+                                                create alert command*/
+                                               Command *pAlertCommand = NULL;
+                                               errorType = create_alert_command(session, ALERT_NO_END_OF_DATA,
+                                                                                                                                       dup_location(session->source), dup_location(session->target),
+                                                                                                                                       NULL, NULL,  NULL, &pAlertCommand);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed in create_alert_command");
+                                                       goto error;
+                                               }
+                                               session->alertCommand = g_list_append(session->alertCommand, pAlertCommand);
+                                       }
+                               }
+                       }
+                       if (changeType == CHANGE_ADD) {
+                               int datastore_id = 0;
+                               if (strcmp(changedItem->contenttype, ELEMENT_TEXT_VCARD) == 0 ||
+                                               strcmp(changedItem->contenttype, ELEMENT_TEXT_VCARD_30) == 0)
+                                       datastore_id = TYPE_CONTACT;
+                               else if (strcmp(changedItem->contenttype, ELEMENT_TEXT_VCAL) == 0)
+                                       datastore_id = TYPE_CALENDAR;
+                               else if (strcmp(changedItem->contenttype, ELEMENT_TEXT_PLAIN) == 0)
+                                       datastore_id = TYPE_MEMO;
+
+                               luid = luid_str_list[(*index)++];
+                               if (luid == NULL) {
+                                       FW_LOGE("luid is null");
+                                       errorType = SA_INTERNAL_ERROR;
+                                       goto error;
+                               }
+
+                               FW_LOGV("index = %d", *index);
+                               FW_LOGV("luid = %s", luid);
+
+                               errorType = __add_mapping(session, get_location_locuri(changedItem->source), luid, datastore_id);
+                               if (errorType != SA_INTERNAL_OK) {
+                                       FW_LOGE("failed in __add_mapping");
+                                       goto error;
+                               }
+                       } else{
+                               luid = get_location_locuri(changedItem->target);
+                               if (luid == NULL) {
+                                       FW_LOGE("luid is null");
+                                       errorType = SA_INTERNAL_ERROR;
+                                       goto error;
+                               }
+                       }
+
+                       changed = create_changeditem(changeType, luid);
+                       if (changed == NULL) {
+                               FW_LOGE("changed is null");
+                               errorType = SA_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       if (changeType != CHANGE_DELETE) {
+                               set_changeditem_contenttype(changed, changedItem->contenttype);
+                               set_changeditem_data(changed, changedItem->private.data);
+                       }
+
+                       Status *temp = NULL;
+                       errorType = create_new_status_location(session, ERROR_UNKNOWN, command,
+                                                                                                                                       changedItem->source, changedItem->target,
+                                                                                                                                       convert_command_type_change_type(changeType), &temp);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed in create_new_status_location");
+                               goto error;
+                       }
+                       session->tempStatus = g_list_append(session->tempStatus, temp);
+
+                       (*changedDatastore)->changeItem = g_list_append((*changedDatastore)->changeItem, changed);
+               }
+       }
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static void __free_pending_status(PendingStatus *pendingStatus)
+{
+       FW_LOGV("start");
+
+       if (!pendingStatus)
+               return;
+
+       free(pendingStatus);
+       pendingStatus = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+static SA_ErrorType __add_mapping(Session *session, char *guid, char *luid, int datastore_id)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       daci_mapping mapping;
+       mapping.account_id = session->accountId;
+       mapping.data_store_id = datastore_id;
+       mapping.luid =  luid;
+       mapping.guid = guid;
+       mapping.access_name = "SA";
+
+       DACI_RETURN da_err  = DACI_Add_Mapping(&mapping);
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Add_Mapping = %d", da_err);
+               errorType = SA_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_session(ProtocolVersion protocolVersion, ProtocolType protocolType, int accountId,
+                                                                                       char *sessID,  char *source, char *target, Session** pSession)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Location *pSourceLocation  = NULL;
+       Location *pTargetLocation = NULL;
+
+       *pSession = (Session *) calloc(1, sizeof(Session));
+
+       if ((*pSession) == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       errorType = create_location(source, NULL, &pSourceLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       errorType = create_location(target, NULL, &pTargetLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       (*pSession)->protocolType = protocolType;
+       (*pSession)->protocolVersion  = protocolVersion;
+       (*pSession)->accountId = accountId;
+       (*pSession)->sessionID = strdup(sessID);
+       (*pSession)->msgID = 0;
+       (*pSession)->source = pSourceLocation;
+       (*pSession)->target = pTargetLocation;
+       (*pSession)->cmdID = 1;
+
+       (*pSession)->sourceMaxMsgSize = OMA_DS_HTTP_DEFAULT_CLIENT_MAX_MSG_SIZE;
+       (*pSession)->sourceMaxObjSize = OMA_DS_HTTP_DEFAULT_CLIENT_MAX_OBJ_SIZE;
+
+       (*pSession)->targetMaxMsgSize = 0;
+       (*pSession)->targetMaxObjSize = 0;
+
+       (*pSession)->NACI_sessionID = 0;
+       (*pSession)->hasOpend = 0;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+void free_session(Session *session)
+{
+       FW_LOGV("start");
+
+       if (!session)
+               return;
+
+       if (session->sessionID) {
+               free(session->sessionID);
+               session->sessionID = NULL;
+       }
+
+       free_statuses(session->status);
+       session->status = NULL;
+
+       free_statuses(session->tempStatus);
+       session->status = NULL;
+
+       if (session->target) {
+               free_location(session->target);
+               session->target = NULL;
+       }
+
+       if (session->source) {
+               free_location(session->source);
+               session->source = NULL;
+       }
+
+       if (session->orgTarget) {
+               free_location(session->orgTarget);
+               session->orgTarget = NULL;
+       }
+
+       if (session->cred) {
+               free_cred(session->cred);
+               session->cred = NULL;
+       }
+
+       if (session->chal) {
+               free_chal(session->chal);
+               session->chal = NULL;
+       }
+
+       if (session->devInf) {
+               free_devinf(session->devInf);
+               session->devInf = NULL;
+       }
+
+       if (session->remoteDevInf) {
+               free_devinf(session->remoteDevInf);
+               session->remoteDevInf = NULL;
+       }
+
+       if (session->pLargeObjCmd) {
+               free_command(session->pLargeObjCmd);
+               session->pLargeObjCmd = NULL;
+       }
+
+       free_commands(session->resultsCommand);
+       session->resultsCommand = NULL;
+
+       free_commands(session->mapCommand);
+       session->mapCommand = NULL;
+
+       if (session)
+               free(session);
+
+       FW_LOGV("end");
+
+       return;
+
+}
+
+SA_ErrorType create_pending_status(unsigned int msgID, unsigned int cmdID, PendingStatus **pPendingStatus)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       *pPendingStatus = (PendingStatus *)calloc(1, sizeof(PendingStatus));
+
+       if (*pPendingStatus == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pPendingStatus)->msgID = msgID;
+       (*pPendingStatus)->cmdID = cmdID;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+void set_session_cred(Session *session, Cred *cred)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!session) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!cred) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       session->cred = cred;
+
+       FW_LOGV("end");
+       return;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return;
+
+}
+
+void set_session_devinf(Session *session, DevInf *devInf)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!session) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!devInf) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       session->devInf = devInf;
+
+       FW_LOGV("end");
+       return ;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return ;
+
+}
+
+SA_ErrorType receive_header(Session *session, SyncHdr *header)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Location *pLocation = NULL;
+
+       if (!session) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!header) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+       if (session->sessionID && header->sessionID) {
+               if (strcmp(session->sessionID, header->sessionID) != 0) {
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+                       goto error;
+               }
+       }
+
+       session->lastRecievedMsgID = header->messageID;
+
+       if (0 < header->maxmsgsize)
+               session->targetMaxMsgSize = header->maxmsgsize;
+       else
+               session->targetMaxMsgSize = OMA_DS_HTTP_DEFAULT_SERVER_MAX_MSG_SIZE;
+
+       if (0 < header->maxobjsize)
+               session->targetMaxObjSize = header->maxobjsize;
+
+       if (header->responseURI) {
+               if (!session->orgTarget) {
+                       session->orgTarget = session->target;
+                       session->target = NULL;
+               }
+
+               if (session->target)
+                       free_location(session->target);
+
+               errorType = create_location(header->responseURI, get_location_locname(session->orgTarget), &pLocation);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+               session->target = pLocation;
+
+               if (!session->target) {
+                       errorType = SA_INTERNAL_NO_MEMORY;
+                       goto error;
+               }
+       }
+
+       Status *temp = NULL;
+       OMA_StatusType statusData = ERROR_UNKNOWN;
+       if (header->cred) {
+               errorType = compare_cred(header->cred, session->cred);
+               if (errorType == SA_INTERNAL_OK)
+                       statusData = AUTH_ACCEPTED;
+               else if (errorType == SA_INTERNAL_AUTHENTICATION_ERROR) {
+                       statusData = ERROR_AUTH_REJECTED;
+               } else
+                       goto error;
+       } else{
+               statusData = NO_ERROR;
+       }
+
+       errorType = create_status(statusData, session->cmdID++, session->lastRecievedMsgID, 0,
+                                                                               header->source, header->target,  COMMAND_TYPE_HEADER, &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType receive_statuses(Session *session, GList *receiveStatus, GList **returnStatus)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       GList *statusItem = receiveStatus;
+       Status *status = NULL;
+       while (statusItem) {
+               status = statusItem->data;
+
+               if (status->cmdRef == 0) {
+                       /*status of SyncHdr*/
+                       assert(status->type == COMMAND_TYPE_HEADER);
+                       assert(status->data);
+                       OMA_StatusType statusType = atoi(status->data);
+
+                       if (statusType == AUTH_ACCEPTED) {
+                               /*212
+                               when auth type is AUTH_TYPE_BASIC does not need to send cred in syncHdr in same session
+                               when auth type is AUTH_TYPE_MD5 the next nonce in Chal MUST used for the digest when the next sync session is started.*/
+                               if (session->cred->type == AUTH_TYPE_MD5) {
+                                       Chal *chal = status->chal;
+                                       if (chal) {
+                                               /*chal in status have to be stored in config_tbl because it have to be used next sync session*/
+                                               FW_LOGV("format type :%d", chal->format);
+
+                                               char *value;
+                                               daci_config config;
+                                               config.config_id = session->accountId;
+
+                                               if (chal->format == FORMAT_TYPE_BASE64)
+                                                       value = chal->nonce_b64;
+                                               else
+                                                       value = g_base64_encode((const unsigned char *)chal->nonce_plain, chal->nonce_length);
+
+                                               bool result = set_config_str(session->accountId, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, value, "string", "SA");
+                                               if (result == false) {
+                                                       errorType = SA_INTERNAL_ERROR;
+                                                       FW_LOGE("failed in set_Config");
+                                                       goto error;
+                                               }
+                                       }
+                               } else if (session->cred->type == AUTH_TYPE_BASIC) {
+                                       /*do not need cred anymore
+                                       but we just send it again*/
+                               }
+                       } else if (statusType == NO_ERROR) {
+                               /*200
+                                when auth type is AUTH_TYPE_BASIC sam credentials must be sent within the next request
+                                when auth type is AUTH_TYPE_MD5  The next nonce in Chal MUST used when the next request is sent*/
+                               if (session->cred->type == AUTH_TYPE_MD5) {
+                                       /*if auth type is AUTH_TYPE_MD5*/
+                                       if (status->chal) {
+                                               /*if there is a chal in status duplicate to session
+                                               chal have to used when next request is sent*/
+                                               session->chal = dup_chal(status->chal);
+                                       }
+                               }
+                       } else if (statusType == ERROR_AUTH_REQUIRED || statusType == ERROR_AUTH_REJECTED) {
+                               if (status->chal)
+                                       session->chal = dup_chal(status->chal);
+                               errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+                               goto error;
+                       } else if (statusType == ERROR_SERVER_FAILURE) {
+                               errorType = SA_INTERNAL_SERVER_FAILURE;
+                               goto error;
+                       } else if (statusType == IN_PROGRESS) {
+                               /*busy signaling*/
+                               errorType = SA_INTERNAL_BUSY_SIGNALING;
+                               goto error;
+                       }
+               } else{
+                       /*status except status of SyncHdr*/
+                       if (status->type == COMMAND_TYPE_ALERT) {
+                               errorType = __receive_alert_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_PUT) {
+                               errorType = __receive_put_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_GET) {
+                               errorType = __receive_get_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_RESULTS) {
+                               errorType = __receive_results_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_SYNC_START) {
+                               errorType = __receive_sync_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_MAP) {
+                               errorType = __receive_map_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_ADD ||
+                                       status->type == COMMAND_TYPE_REPLACE ||
+                                       status->type == COMMAND_TYPE_DELETE) {
+                               errorType = __receive_changes_status(session, status, returnStatus);
+                       }
+
+                       if (errorType != SA_INTERNAL_OK)
+                               goto error;
+               }
+               statusItem = g_list_next(statusItem);
+       }
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE(" error, Error Type %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType receive_commands(Session *session, GList *receiveCommand, bool autoConfig, GList **returnDatastore)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       int item_luid_count = 0;
+       int index = 0;
+       int i;
+       char **luid_str_list = NULL;
+
+       GList *iter = NULL;
+       Command *command = NULL;
+       for (iter = receiveCommand; iter != NULL; iter = g_list_next(iter)) {
+               command = iter->data;
+
+               if (command->type == COMMAND_TYPE_ADD)
+                       item_luid_count += g_list_length(command->private.change.items);
+       }
+
+       FW_LOGV("item_luid_count = %d", item_luid_count);
+
+       if (item_luid_count > 0) {
+               luid_str_list = DACI_Generate_Item_Luid(1, item_luid_count);
+               if (luid_str_list == NULL) {
+                       FW_LOGE("failed in DACI_Generate_Item_Luid");
+                       errorType = SA_INTERNAL_ERROR;
+                       goto error;
+               }
+       }
+
+       ChangedDatastore *changedDatastore = NULL;
+       for (iter = receiveCommand; iter != NULL; iter = g_list_next(iter)) {
+               command = iter->data;
+
+               if (autoConfig != true || (autoConfig == true && command->type == COMMAND_TYPE_RESULTS)) {
+                       switch (command->type) {
+                       case COMMAND_TYPE_UNKNOWN:
+                       case COMMAND_TYPE_HEADER:
+                       case COMMAND_TYPE_MAP:
+                               /*never receive theses commands*/
+                               break;
+                       case COMMAND_TYPE_ALERT:
+                               errorType = __receive_alert_command(session, command, returnDatastore);
+                               break;
+                       case COMMAND_TYPE_PUT:
+                               errorType = __receive_put_command(session, command);
+                               break;
+                       case COMMAND_TYPE_GET:
+                                       errorType = __receive_get_command(session, command);
+                               break;
+                       case COMMAND_TYPE_RESULTS:
+                               errorType = __receive_results_command(session, command);
+                               break;
+                       case COMMAND_TYPE_SYNC_START:
+                               errorType = __receive_sync_command(session, command, &changedDatastore);
+                               break;
+                       case COMMAND_TYPE_SYNC_END:
+                               if (changedDatastore) {
+                                       *returnDatastore = g_list_append(*returnDatastore, changedDatastore);
+                                       changedDatastore = NULL;
+                               }
+                               break;
+                       case COMMAND_TYPE_ADD:
+                       case COMMAND_TYPE_REPLACE:
+                       case COMMAND_TYPE_DELETE:
+                               errorType = __receive_changes_command(session, command, luid_str_list, &index, &changedDatastore);
+                               break;
+                       }
+
+                       if (errorType != SA_INTERNAL_OK)
+                               goto error;
+               }
+       }
+
+       if (luid_str_list != NULL) {
+               /*free luid_str_list*/
+               for (i = 0; i < item_luid_count; i++)
+                       free(luid_str_list[i]);
+
+               free(luid_str_list);
+       }
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+
+       if (luid_str_list != NULL) {
+               /*free luid_str_list*/
+               for (i = 0; i < item_luid_count; i++)
+                       free(luid_str_list[i]);
+
+               free(luid_str_list);
+       }
+
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+void reset_cmdID_session(Session *session)
+{
+       if (session)
+               session->cmdID = 1;
+}
diff --git a/ServiceAdapter/SA_Util.c b/ServiceAdapter/SA_Util.c
new file mode 100644 (file)
index 0000000..10e9c19
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Util.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of utility function
+ */
+
+#include "agent-framework/securityAssistant/EXT_SA_Encryption_Decryption.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceAdapter/SA_Util.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+void put_into_list(GList **commands, GList **commands_last, void *pCommand)
+{
+       GList *temp = NULL;
+       if (*commands_last == NULL) {
+               *commands_last = *commands = g_list_append(*commands, pCommand);
+       } else {
+               temp = g_list_append(*commands_last, pCommand);
+               *commands_last = g_list_next(*commands_last);
+       }
+}
+
+SA_ErrorType create_cred_string(AuthType type,  const char *username,  const char *password,
+                                                                                                       const char *nonce, unsigned int nonce_size, char **pCred)
+{
+       FW_LOGV("start");
+       SA_ErrorType errortype = SA_INTERNAL_OK;
+
+       switch (type) {
+               case AUTH_TYPE_BASIC:
+               {
+                       char *plain = g_strjoin(":", username, password, NULL);
+                       *pCred = g_base64_encode((unsigned char *) plain, strlen(plain));
+                       if (*pCred == NULL) {
+                               free(plain);
+                               errortype = SA_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+                       free(plain);
+
+                       break;
+               }
+               case AUTH_TYPE_MD5:
+               {
+                       /* How does syncml:auth-md5 works?
+                        *
+                        * base64(
+                        *        md5(
+                        *            base64(
+                        *                   md5(
+                        *                       username + ":" + password
+                        *                     )
+                        *                 ) +
+                        *            ":" + nonce
+                        *          )
+                        *      )
+                        */
+
+                       /* Let's determine the string for the comparison. */
+                       char *auth = g_strjoin(":", username, password, NULL);
+                       FW_LOGV("username:password = %s", auth);
+                       unsigned char *digest = NULL;
+                       digest = SA_Get_Encryption_Value(SA_ENCRYPTION_MD5, auth, strlen(auth));
+                       free(auth);
+                       *pCred = g_base64_encode(digest, 16);
+                       free(digest);
+                       if (*pCred == NULL) {
+                               errortype = SA_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       if (nonce != NULL) {
+                               FW_LOGV("nonce = %s", nonce);
+                               FW_LOGV("nonce_size = %d", nonce_size);
+
+                               int auth_size = strlen(*pCred) + nonce_size + 1;
+                               auth = (char *)calloc(auth_size + 1, sizeof(char));
+                               memcpy(auth, *pCred, strlen(*pCred));
+                               auth[strlen(*pCred)] = ':';
+                               memcpy(auth + strlen(*pCred) + 1, nonce, nonce_size);
+                               FW_LOGV("base64[md5[username:password]] = %s", *pCred);
+                               FW_LOGV("before last base64 encoding = %s", auth);
+                               free(*pCred);
+
+                               /*MD5GetDigest (auth, strlen(auth), digest);*/
+
+                               /*
+                               GChecksum* pMd5 = g_checksum_new(G_CHECKSUM_MD5);
+                               g_checksum_update(pMd5, auth, auth_size);
+                               gsize temp = 16;
+                               digest = (unsigned char*)calloc(16, sizeof(unsigned char));
+                               g_checksum_get_digest(pMd5, digest, &temp);
+                               */
+
+                               digest = SA_Get_Encryption_Value(SA_ENCRYPTION_MD5, auth, auth_size);
+                               FW_LOGV("md5[base64[md5[username:password]]] = %s", digest);
+
+                               free(auth);
+                               *pCred = g_base64_encode(digest, 16);
+                               free(digest);
+                               FW_LOGV("base64[md5[base64[md5[username:password]]]] = %s", *pCred);
+                               if (*pCred == NULL) {
+                                       errortype = SA_INTERNAL_NO_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       break;
+               case AUTH_TYPE_UNKNOWN:
+                       break;
+
+               }
+       }
+
+       FW_LOGV("end");
+       return errortype;
+
+error:
+       FW_LOGE("error : %d", errortype);
+       return errortype;
+}
+
+void  set_xml_to_file(char *xml, const char *path)
+{
+       FILE *pFile = NULL;
+
+       if (xml != NULL)
+               pFile = fopen(path, "a");
+
+       if (pFile == NULL)
+               return;
+
+       fputs("==================================================================================", pFile);
+       fputs("\n", pFile);
+
+       if (xml != NULL)
+               fputs(xml, pFile);
+
+       if (xml != NULL)
+               fclose(pFile);
+}
diff --git a/ServiceEngine/SE_Account.c b/ServiceEngine/SE_Account.c
new file mode 100644 (file)
index 0000000..6395bc8
--- /dev/null
@@ -0,0 +1,1847 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Account.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of account in Service Engine
+ */
+
+#include "Common/CscKeys.h"
+#include "Common/Common_Vconf.h"
+#include "Common/Common_Define.h"
+#include "Common/Common_Util.h"
+#include "ServiceEngine/SE_Account.h"
+#include "ServiceEngine/SE_Error.h"
+#include "ServiceEngine/SE_Common.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/DACI/DACI_Luid.h"
+#include "agent-framework/Account/Account_Mgr.h"
+#include "agent-framework/PlatformMonitor/EXT_PMCI_Struct.h"
+#include "agent-framework/PlatformMonitor/EXT_PMCI.h"
+#include "agent-framework/Device/EXT_DCI_DevInfo.h"
+#include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
+
+#define LOG_TAG        "OMA_DS_SE"
+
+#define MAX_DATASTORE_COUNT 3
+
+typedef struct {
+       char *serverName;
+       int index;
+} datastore_cp_info;
+
+
+static char *predefinedDatastore[][MAX_DATASTORE_COUNT][2] = {
+               { {"contacts", "text/x-vcard"}, {"calendar", "text/x-vcalendar"}, {"notes", "text/plain"} }
+};
+
+static datastore_cp_info predefinedServer[] = {
+               {"O3SIS SyncML", 0}
+};
+
+/* TODO have to remove after removing vconf*/
+static SE_ErrorType __set_datastore_config_from_vconf(int accountID, char *profilePath, int content_type);
+
+static SE_ErrorType __set_datastore_config_from_csc(int accountID, int index, int content_type);
+static SE_ErrorType __add_profile(char *addr,  char *id, char *password, char *access_name, int *accountID);
+static SE_ErrorType __set_profile_info(int accountId, char *profileName, char *syncMode, char *syncType, char *interval);
+static SE_ErrorType __set_profile_category(int accountId, int contentType, sync_category *category);
+static SE_ErrorType __set_profile_category_cp(int accountId, int contentType, resource_cp *category);
+static SE_ErrorType __set_periodic_sync_config(int account_id, char *syncMode, char *interval);
+static SE_ErrorType __set_config_default_value(int accountID);
+static SE_ErrorType __set_datastore_config_default_value(int accountID, int content_type);
+
+/* TODO have to remove after removing vconf*/
+static SE_ErrorType __set_datastore_config_from_vconf(int accountID, char *profilePath, int content_type)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char *isEnabledPath = NULL;
+       char *targeturiPath = NULL;
+       char *sourceuriPath = NULL;
+       char *IDPath = NULL;
+       char *PWDPath = NULL;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_source[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       int isEnabled = 0;
+       char *targeturi = NULL;
+       char *sourceuri = NULL;
+       char *ID = NULL;
+       char *PWD = NULL;
+
+       bool result;
+
+       if (content_type == TYPE_CONTACT) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+               isEnabledPath =  DS_SETTING_CONTACT_ENABLED;
+               targeturiPath =  DS_SETTING_CONTACT_TGTURI;
+               sourceuriPath = DS_SETTING_CONTACT_SRCURI;
+               IDPath =   DS_SETTING_CONTACT_AUTHNAME;
+               PWDPath =  DS_SETTING_CONTACT_AUTHPWD;
+       } else if (content_type == TYPE_CALENDAR) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+               isEnabledPath =  DS_SETTING_CALENDAR_ENABLED;
+               targeturiPath =  DS_SETTING_CALENDAR_TGTURI;
+               sourceuriPath =  DS_SETTING_CALENDAR_SRCURI;
+               IDPath =   DS_SETTING_CALENDAR_AUTHNAME;
+               PWDPath =   DS_SETTING_CALENDAR_AUTHPWD;
+       } else if (content_type == TYPE_MEMO) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+               isEnabledPath = DS_SETTING_MEMO_ENABLED;
+               targeturiPath =  DS_SETTING_MEMO_TGTURI;
+               sourceuriPath =  DS_SETTING_MEMO_SRCURI;
+               IDPath =   DS_SETTING_MEMO_AUTHNAME;
+               PWDPath =   DS_SETTING_MEMO_AUTHPWD;
+       }
+
+       result = get_vconf_int(profilePath, isEnabledPath, &isEnabled);
+       if (result == false) {
+               FW_LOGE("failed in get_Vconf_int");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+        }
+
+       targeturi = get_vconf_str(profilePath, targeturiPath);
+       sourceuri = get_vconf_str(profilePath, sourceuriPath);
+       ID = get_vconf_str(profilePath, IDPath);
+       PWD = get_vconf_str(profilePath, PWDPath);
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       if (isEnabled) {
+               result = set_config_str(accountID, datastore, "1", "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               result = set_config_str(accountID, datastore_target, targeturi, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               result = set_config_str(accountID, datastore_id, ID, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               result = set_config_str(accountID, datastore_pw, PWD, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+       } else{
+               result = set_config_str(accountID, datastore, "0", "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+
+       result = set_config_str(accountID, datastore_source, sourceuri, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (targeturi)
+               free(targeturi);
+       if (sourceuri)
+               free(sourceuri);
+       if (ID)
+               free(ID);
+       if (PWD)
+               free(PWD);
+
+       return err;
+}
+
+
+static SE_ErrorType __set_datastore_config_from_csc(int accountID, int index, int content_type)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char *isEnabledPath = NULL;
+       char *targeturiPath = NULL;
+       char *IDPath = NULL;
+       char *PWDPath = NULL;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_source[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       int isEnabled = 0;
+       char *targeturi = NULL;
+       char *ID = NULL;
+       char *PWD = NULL;
+       char profilePath[128];
+
+       char *sourceuri = NULL;
+
+       bool result;
+
+       if (content_type == TYPE_CONTACT) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+               sourceuri = DEFINE_SOURCE_CONTACT_URI;
+               isEnabledPath =  CSC_VCONF_KEY_SYNCMLDS_CONTACTS_ENABLED;
+               targeturiPath =  CSC_VCONF_KEY_SYNCMLDS_CONTACTS_TGTURI;
+               IDPath =   CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHNAME;
+               PWDPath =  CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHPWD;
+       } else if (content_type == TYPE_CALENDAR) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+               sourceuri = DEFINE_SOURCE_CALENDAR_URI;
+               isEnabledPath =  CSC_VCONF_KEY_SYNCMLDS_CALENDAR_ENABLED;
+               targeturiPath =  CSC_VCONF_KEY_SYNCMLDS_CALENDAR_TGTURI;
+               IDPath =   CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHNAME;
+               PWDPath =   CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHPWD;
+       } else if (content_type == TYPE_MEMO) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+               sourceuri = DEFINE_SOURCE_MEMO_URI;
+               isEnabledPath = CSC_VCONF_KEY_SYNCMLDS_MEMO_ENABLED;
+               targeturiPath =  CSC_VCONF_KEY_SYNCMLDS_MEMO_TGTURI;
+               IDPath =   CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHNAME;
+               PWDPath =   CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHPWD;
+       } else{
+               err = SE_INTERNAL_ERROR;
+               FW_LOGE("No content type");
+               goto error;
+       }
+
+       sprintf(profilePath, isEnabledPath, index);
+       result = get_vconf_Int_key(profilePath, &isEnabled);
+       if (result == false) {
+               FW_LOGE("No value in vconf key = %s", profilePath);
+               goto error;
+       }
+
+       sprintf(profilePath, targeturiPath, index);
+       targeturi = get_vconf_str_key(profilePath);
+
+       sprintf(profilePath, IDPath, index);
+       ID = get_vconf_str_key(profilePath);
+
+       sprintf(profilePath, PWDPath, index);
+       PWD = get_vconf_str_key(profilePath);
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       if (isEnabled) {
+               result = set_config_str(accountID, datastore, "1", "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+               result = set_config_str(accountID, datastore_target, targeturi, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+               result = set_config_str(accountID, datastore_id, ID, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+               result = set_config_str(accountID, datastore_pw, PWD, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+       } else{
+               result = set_config_str(accountID, datastore, "0", "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+       result = set_config_str(accountID, datastore_source, sourceuri, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (targeturi)
+               free(targeturi);
+       if (ID)
+               free(ID);
+       if (PWD)
+               free(PWD);
+
+       return err;
+}
+
+static SE_ErrorType __add_profile(char *addr,  char *id, char *password, char *access_name, int *accountID)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       int account = addAccount(id, password, addr, NULL, 0, 0, access_name);
+       char *folderID = NULL;
+
+       FW_LOGV("accountID = %d", account);
+
+       if (account < 0) {
+               FW_LOGE("accountID = %d", account);
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       folderID = DACI_Generate_Folder_Luid();
+       if (folderID == NULL) {
+               FW_LOGE("failed in DACI_Generate_Folder_Luid");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       daci_folder folder;
+       folder.account_id = account;
+       folder.folder_id = folderID;
+       folder.data_store_id = TYPE_CONTACT;
+       folder.folder_type_id = 0; /* Default contacts folder */
+       folder.parent_folder_id = 0;
+       folder.service_id = "0";
+       folder.access_name = "EventHandler";
+       DACI_RETURN ret = DACI_Add_Folder(&folder, 1);
+       if (ret != DACI_SUCCESS) {
+               FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
+               FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
+
+       if (folderID != NULL) {
+               free(folderID);
+               folderID = NULL;
+       }
+
+       folderID = DACI_Generate_Folder_Luid();
+       if (folderID == NULL) {
+               FW_LOGE("failed in DACI_Generate_Folder_Luid");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       folder.account_id = account;
+       folder.folder_id = folderID;
+       folder.data_store_id = TYPE_CALENDAR;
+       folder.folder_type_id = 0; /* Default calendars folder */
+       folder.parent_folder_id = 0;
+       folder.service_id = "1";
+       folder.access_name = "EventHandler";
+       ret = DACI_Add_Folder(&folder, 1);
+       if (ret != DACI_SUCCESS) {
+               FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
+               FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
+
+       if (folderID != NULL) {
+               free(folderID);
+               folderID = NULL;
+       }
+
+       /* TODO : add default memo folder (Hard cording) */
+       folderID = DACI_Generate_Folder_Luid();
+       if (folderID == NULL) {
+               FW_LOGE("failed in DACI_Generate_Folder_Luid");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       folder.account_id = account;
+       folder.folder_id = folderID;
+       folder.data_store_id = TYPE_MEMO;
+       folder.folder_type_id = 0; /* Default notes folder */
+       folder.parent_folder_id = 0;
+       folder.service_id = "0";
+       folder.access_name = "EventHandler";
+       ret = DACI_Add_Folder(&folder, 1);
+       if (ret != DACI_SUCCESS) {
+               FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
+               FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
+
+       if (folderID != NULL) {
+               free(folderID);
+               folderID = NULL;
+       }
+
+       /* call log folder ID */
+       folderID = DACI_Generate_Folder_Luid();
+       if (folderID == NULL) {
+               FW_LOGE("failed in DACI_Generate_Folder_Luid");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       folder.account_id = account;
+       folder.folder_id = folderID;
+       folder.data_store_id = TYPE_CALLLOG;
+       folder.folder_type_id = 0; /* Default call log folder */
+       folder.parent_folder_id = 0;
+       folder.service_id = "0";
+       folder.access_name = "EventHandler";
+       ret = DACI_Add_Folder(&folder, 1);
+       if (ret != DACI_SUCCESS) {
+               FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
+               FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
+
+       if (folderID != NULL) {
+               free(folderID);
+               folderID = NULL;
+       }
+
+       *accountID = account;
+
+       FW_LOGV("end");
+
+error:
+
+       if (folderID != NULL)
+               free(folderID);
+
+       return err;
+}
+
+
+static SE_ErrorType __set_profile_info(int accountId, char *profileName, char *syncMode, char *syncType, char *interval)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , syncType, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+
+static SE_ErrorType __set_profile_category(int accountId, int contentType, sync_category *category)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("category->enabled : %d", category->enabled);
+       FW_LOGV("category->srcURI : %s", category->srcURI);
+       FW_LOGV("category->tgtURI : %s", category->tgtURI);
+       FW_LOGV("category->id : %s", category->id);
+       FW_LOGV("category->password : %s", category->password);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_source[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (contentType == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+
+       result = set_config_int(accountId, datastore, category->enabled, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_source, category->srcURI, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_target, category->tgtURI, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_id, category->id, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_pw, category->password, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+       return err;
+
+}
+
+static SE_ErrorType __set_profile_category_cp(int accountId, int contentType, resource_cp *category)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("category->srcURI : %s", category->name);
+       FW_LOGV("category->id : %s", category->id);
+       FW_LOGV("category->password : %s", category->password);
+       FW_LOGV("category->authType : %s", category->authType);
+       FW_LOGV("category->authData : %s", category->authData);
+       FW_LOGV("category->tgtURI : %s", category->accept);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       result = set_config_str(accountId, datastore_target, category->name, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_id, category->id, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_pw, category->password, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+       return err;
+
+}
+
+static SE_ErrorType __set_periodic_sync_config(int account_id, char *syncMode, char *interval)
+{
+       FW_LOGV("start");
+       FW_LOGV("syncMode = %s", syncMode);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       PMCI_RETURN scheduler_err;
+       bool result;
+       char *value = NULL;
+       int alarm_id = 0;
+
+       pmci_alarm_t *alarm_info = (pmci_alarm_t *)calloc(1, sizeof(pmci_alarm_t));
+
+       result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       alarm_id = atoi(value);
+
+       if (alarm_id != 0) {
+               scheduler_err = PMCI_Remove_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarm_id);
+               if (scheduler_err != PMCI_SUCCESS) {
+                       FW_LOGE("failed in PMCI_Remove_Item_To_Specific_Type");
+                       err = SE_INTERNAL_SCHEDULER_ERROR;
+                       goto error;
+               }
+       }
+
+       if (strcmp(syncMode , DEFINE_SYNC_MODE_PERIODIC) == 0 && interval != NULL) {
+
+               result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , DEFINE_ALERT_TWO_WAY_STR, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+                int week[] = {DAY_SUN, DAY_MON, DAY_TUE, DAY_WED, DAY_THU, DAY_FRI, DAY_SAT};
+                time_t current_time;
+                struct tm *struct_time;
+                time(&current_time);
+                struct_time = localtime(&current_time);
+                if (struct_time == NULL) {
+                        FW_LOGE("struct_time is NULL");
+                        err = SE_INTERNAL_ERROR;;
+                       goto error;
+                }
+
+                alarm_info->start_alarm_time = g_strdup_printf("%.2d-%.2d-%.2dT%.2d:%.2d:%.2dZ",
+                   struct_time->tm_year+1900,
+                   struct_time->tm_mon+1,
+                   struct_time->tm_mday,
+                   struct_time->tm_hour,
+                   struct_time->tm_min,
+                   struct_time->tm_sec);
+                alarm_info->isDisposable = 0;
+
+               if (strcmp(interval, "5 minutes") == 0) {
+                       FW_LOGV("5 minutes");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = 5*60;
+               } else if (strcmp(interval, "15 minutes") == 0) {
+                       FW_LOGV("15 minutes");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = 15*60;
+               } else if (strcmp(interval, "1 hour") == 0) {
+                       FW_LOGV("1 hour");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = ((1*60)*60);
+               } else if (strcmp(interval, "4 hours") == 0) {
+                       FW_LOGV("4 hours");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = ((4*60)*60);
+               } else if (strcmp(interval, "12 hours") == 0) {
+                       FW_LOGV("12 hours");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = ((12*60)*60);
+               } else if (strcmp(interval, "1 day") == 0) {
+                       FW_LOGV("1 day");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = ((24*60)*60);
+               } else if (strcmp(interval, "1 week") == 0) {
+                       FW_LOGV("1 week");
+                       alarm_info->repeat_type = REPEAT_WEEKLY;
+                       alarm_info->repeat_value = week[struct_time->tm_wday];
+               }
+
+               scheduler_err = PMCI_Add_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarm_info, &alarm_id);
+               if (scheduler_err != PMCI_SUCCESS) {
+                       FW_LOGE("failed in PMCI_Add_Item_To_Specific_Type");
+                       err = SE_INTERNAL_SCHEDULER_ERROR;
+                       goto error;
+               }
+               FW_LOGV("alarm_id =%d", alarm_id);
+
+               result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, alarm_id, "int", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+       } else{
+               result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (value != NULL)
+               free(value);
+
+       if (alarm_info != NULL) {
+               if (alarm_info->start_alarm_time != NULL)
+                       free(alarm_info->start_alarm_time);
+
+               free(alarm_info);
+       }
+
+       return err;
+}
+
+
+static SE_ErrorType __set_config_default_value(int accountID)
+{
+       FW_LOGV("start");
+       SE_ErrorType  err = SE_INTERNAL_OK;
+
+       bool result;
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, "Push", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , "Full", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, "5 minutes", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, "-1", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, "-1", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               err = __set_datastore_config_default_value(accountID, content_type);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in set_DatastoreConfig");
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+error:
+
+       return err;
+}
+
+static SE_ErrorType __set_datastore_config_default_value(int accountID, int contentType)
+{
+       FW_LOGV("start");
+       SE_ErrorType  err = SE_INTERNAL_OK;
+
+       bool result;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_source[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       char datastore_dbSynced[128];
+       char datastore_lastSessionTime[128];
+       char datastore_s2c_Total[128];
+       char datastore_s2c_NrOfAdd[128];
+       char datastore_s2c_NrOfDelete[128];
+       char datastore_s2c_NrOfReplace[128];
+       char datastore_c2s_Total[128];
+       char datastore_c2s_NrOfAdd[128];
+       char datastore_c2s_NrOfDelete[128];
+       char datastore_c2s_NrOfReplace[128];
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if(contentType == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       sprintf(datastore_dbSynced, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
+       sprintf(datastore_lastSessionTime, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
+
+       sprintf(datastore_s2c_Total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(datastore_s2c_NrOfAdd, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(datastore_s2c_NrOfDelete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+       sprintf(datastore_s2c_NrOfReplace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+
+       sprintf(datastore_c2s_Total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(datastore_c2s_NrOfAdd, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(datastore_c2s_NrOfDelete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+       sprintf(datastore_c2s_NrOfReplace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+
+
+       result = set_config_str(accountID, datastore, "0", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_source, datastore, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_target, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_id, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_pw, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_dbSynced, DEFINE_DBSYNC_NO, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_lastSessionTime, "-1", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_s2c_Total, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_s2c_NrOfAdd, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_s2c_NrOfDelete, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_s2c_NrOfReplace, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_c2s_Total, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_c2s_NrOfAdd, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_c2s_NrOfDelete, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_c2s_NrOfReplace, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       FW_LOGV("end");
+
+error:
+       return err;
+}
+
+/*TODO have to be removed after removing vconf*/
+int update_all_config(char *profile,  bool isAdd, int *accountId)
+{
+       FW_LOGV("profile = %s", profile);
+
+       SE_ErrorType  err = SE_INTERNAL_OK;
+       char profilePath[128];
+       char *profileName = NULL;
+       char *email = NULL;
+       char *password = NULL;
+       char *serverIP = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       bool result;
+
+       if (profile == NULL) {
+               FW_LOGE("profile is NULL");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, "%s/%s", DS_SETTINGS_PATH, profile);
+
+       email = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHNAME);
+       password = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHPWD);
+       serverIP = get_vconf_str(profilePath, DS_SETTING_ADDR);
+
+       FW_LOGV("email = %s", email);
+       FW_LOGV("password = %s", password);
+       FW_LOGV("serverIP = %s", serverIP);
+
+       int accountID;
+       if (isAdd == true) {
+               err = __add_profile(serverIP, email, password , "UI", &accountID);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in add_Account");
+                       goto error;
+               }
+
+               err = __set_config_default_value(accountID);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in add_Account");
+                       goto error;
+               }
+
+               result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profile, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+       } else{
+               accountID = get_accountid(profile, true);
+
+               FW_LOGV("accountID = %d", accountID);
+
+               da_err = DACI_Set_Account_Email_Address(accountID, email, "SE");
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("failed in DACI_Set_Account_Email_Address = %d", da_err);
+                       err = SE_INTERNAL_ERROR;
+                       goto error;
+               }
+
+               da_err = DACI_Set_Account_Password(accountID, password, "SE");
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("failed in DACI_Set_Account_Email_Address = %d", da_err);
+                       err = SE_INTERNAL_ERROR;
+                       goto error;
+               }
+       }
+
+       profileName = get_vconf_str(profilePath, DS_SETTING_NAME);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, serverIP, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       syncMode = get_vconf_str(profilePath, DS_SETTING_SYNCMODE);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       syncType =  get_vconf_str(profilePath, DS_SETTING_SYNCTYPE);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       interval = get_vconf_str(profilePath, DS_SETTING_INTERVAL);
+       FW_LOGV("interval %s ", interval);
+
+       err = __set_periodic_sync_config(accountID, syncMode, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_periodic_sync_config");
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT - 1; content_type++) {
+               err = __set_datastore_config_from_vconf(accountID, profilePath, content_type);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in set_DatastoreConfig");
+                       goto error;
+               }
+       }
+
+       *accountId = accountID;
+
+       FW_LOGV("end");
+
+error:
+
+       if (profileName)
+               free(profileName);
+       if (email)
+               free(email);
+       if (password)
+               free(password);
+       if (serverIP)
+               free(serverIP);
+       if (syncMode)
+               free(syncMode);
+       if (syncType)
+               free(syncType);
+       if (interval)
+               free(interval);
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return 0;
+       else
+               return 1;
+}
+
+
+int add_profile_csc(int index)
+{
+       SE_ErrorType  err = SE_INTERNAL_OK;
+       char profilePath[128];
+       char profileDirName[128];
+       char *profileName = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *serverIP = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_ADDR, index);
+       serverIP =  get_vconf_str_key(profilePath);
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_AUTHNAME, index);
+       id = get_vconf_str_key(profilePath);
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_AUTHPWD, index);
+       password = get_vconf_str_key(profilePath);
+
+       FW_LOGV("email = %s", id);
+       FW_LOGV("password = %s", password);
+       FW_LOGV("serverIP = %s", serverIP);
+
+       int accountID;
+       err = __add_profile(serverIP, id, password , "CSC", &accountID);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       err = __set_config_default_value(accountID);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_config_default_value");
+               goto error;
+       }
+
+       /*set profile dir name in config table*/
+       sprintf(profileDirName, "Sync%d", index);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, serverIP, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_NAME, index);
+       profileName = get_vconf_str_key(profilePath);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_SYNCMODE, index);
+       syncMode = get_vconf_str_key(profilePath);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_SYNCTYPE, index);
+       syncType =  get_vconf_str_key(profilePath);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT - 1; content_type++) {
+               err = __set_datastore_config_from_csc(accountID, index, content_type);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in set_DatastoreConfig");
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (profileName)
+               free(profileName);
+       if (id)
+               free(id);
+       if (password)
+               free(password);
+       if (serverIP)
+               free(serverIP);
+       if (syncMode)
+               free(syncMode);
+       if (syncType)
+               free(syncType);
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return 0;
+       else
+               return 1;
+}
+
+bool add_profile_cp(char *profileName, char *addr, char *id, char *password, GList *categories, int *accountId)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("profileName = %s", profileName);
+       FW_LOGV("addr = %s", addr);
+       FW_LOGV("id = %s", id);
+       FW_LOGV("password = %s", password);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       int account = -1;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       err = __add_profile(addr, id, password, "CP", &account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       err = __set_config_default_value(account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       int i;
+       int cnt = (int) sizeof(predefinedServer) / sizeof(datastore_cp_info);
+       FW_LOGV("cnt = %d", cnt);
+       for (i = 0; i < cnt; i++) {
+
+               FW_LOGV("predefinedServer[%d].serverName = %s", i, predefinedServer[i].serverName);
+               if (strcmp(predefinedServer[i].serverName, profileName) == 0) {
+
+                       int j;
+                       for (j = 0; j < MAX_DATASTORE_COUNT; j++) {
+                               resource_cp *category = NULL;
+                               GList *iter = NULL;
+                               FW_LOGV("categories length = %d", g_list_length(categories));
+                               for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
+                                       category = (resource_cp *)iter->data;
+                                       FW_LOGV("category->name = %s", category->name);
+                                       FW_LOGV("category->accept = %s", category->accept);
+
+                                       FW_LOGV("predefinedDatastore[i][j][0] = %s", predefinedDatastore[i][j][0]);
+                                       FW_LOGV("predefinedDatastore[i][j][1] = %s", predefinedDatastore[i][j][1]);
+
+                                       if (predefinedDatastore[i][j][0] != NULL && category->name != NULL &&
+                                                       predefinedDatastore[i][j][1] != NULL && category->accept != NULL) {
+
+                                               if (strcasecmp(predefinedDatastore[i][j][0] , category->name) == 0 &&
+                                                       strcmp(predefinedDatastore[i][j][1], category->accept) == 0) {
+
+                                                       err = __set_profile_category_cp(account, j, category);
+                                                       if (err  != SE_INTERNAL_OK) {
+                                                               FW_LOGE("failed in __set_profile_category");
+                                                               goto error;
+                                                       }
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       *accountId = account;
+
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool add_profile(char *profileDirName, char *profileName, char *addr, char *id, char *password, char *syncMode, char *syncType, char *interval, GList *categories, int *accountId)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("profileName = %s", profileName);
+       FW_LOGV("addr = %s", addr);
+       FW_LOGV("id = %s", id);
+       FW_LOGV("password = %s", password);
+       FW_LOGV("syncMode = %s", syncMode);
+       FW_LOGV("syncType = %s", syncType);
+       FW_LOGV("interval = %s", interval);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       int account = -1;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       err = __add_profile(addr, id, password, "UI", &account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       err = __set_config_default_value(account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       err = __set_profile_info(account, profileName, syncMode, syncType, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_info");
+               goto error;
+       }
+
+       err = __set_periodic_sync_config(account, syncMode, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_info");
+               goto error;
+       }
+
+       sync_category *category = NULL;
+       GList *iter = NULL;
+       int contentType = 0;
+       for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
+               category = iter->data;
+               err = __set_profile_category(account, contentType, category);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in __set_profile_category");
+                       goto error;
+               }
+               contentType++;
+       }
+
+       *accountId = account;
+
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool edit_profile(int accountId, char *profileName, char *addr, char *id, char *password, char *syncMode, char *syncType, char *interval, GList *categories)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       da_err = DACI_Set_Account_Email_Address(accountId, id, "SE");
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Set_Account_Email_Address");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+
+       da_err = DACI_Set_Account_Password(accountId, password, "SE");
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Set_Account_Email_Address");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       err = __set_profile_info(accountId, profileName, syncMode, syncType, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_info");
+               goto error;
+       }
+
+       err = __set_periodic_sync_config(accountId, syncMode, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_info");
+               goto error;
+       }
+
+       sync_category *category = NULL;
+       GList *iter = NULL;
+       int contentType = 0;
+       for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
+               category = iter->data;
+               err = __set_profile_category(accountId, contentType, category);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in __set_profile_category");
+                       goto error;
+               }
+               contentType++;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool delete_profile(GList *profiles)
+{
+       FW_LOGV("start");
+       SE_ErrorType  err = SE_INTERNAL_OK;
+       char *profileName = NULL;
+       int *accountId = 0;
+       char *value = NULL;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       GList *iter = NULL;
+       int alarmId = 0;
+
+       bool result;
+       for (iter = profiles; iter != NULL; iter = g_list_next(iter)) {
+               accountId = (int *)(iter->data);
+
+               FW_LOGV("accountId = %d", *accountId);
+               /*if deleteing Account's sync mode is periodic sync it has to be deleted from schedule_tbl*/
+               result = get_config(*accountId, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
+               if (result == false) {
+                       FW_LOGE("failed in get_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+               alarmId = atoi(value);
+               if (alarmId != 0) {
+                       PMCI_RETURN scheduler_err = PMCI_Remove_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarmId);
+                       if (scheduler_err != PMCI_SUCCESS) {
+                               FW_LOGE("failed in PMCI_Remove_Item_To_Specific_Type");
+                               err = SE_INTERNAL_SCHEDULER_ERROR;
+                               goto error;
+                       }
+               }
+               deleteAccount(*accountId);
+               if(accountId != 0){
+                       free(accountId);
+                       accountId = 0;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (profileName)
+               free(profileName);
+
+       if (value)
+               free(value);
+
+       if(accountId != NULL)
+               free(accountId);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_synchronising_profile(char **profileDirName)
+{
+       FW_LOGV("start ");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       bool result;
+       char *value = NULL;
+       int *account_list = 0;
+       int account_list_count = 0;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+
+       int i;
+       for (i = 0; i < account_list_count; i++) {
+               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, &value);
+               if (result == false) {
+                       FW_LOGE("failed in set_Config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               if (strcmp(value, "1") == 0) {
+                       result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName);
+                       if (result == false) {
+                               FW_LOGE("failed in get_Config");
+                               err = SE_INTERNAL_DA_ERROR;
+                               goto error;
+                       }
+                       break;
+               }
+
+               free(value);
+               value = NULL;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       if (value != NULL)
+               free(value);
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+
+bool add_profile_calllog(int *accountId)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       DCI_RETURN dci_err = DCI_SUCCESS;
+       bool result;
+       sync_category *category = NULL;
+       char *id = NULL;
+       char *password  = NULL;
+       int account = -1;
+
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       /* FIXME  get id from somewhere */
+       /*get IMEI from Platform */
+       id = "pcwds@samsung.com";
+
+       dci_err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &password);
+       if (dci_err != DCI_SUCCESS) {
+               FW_LOGE("failed to get devinfo");
+               goto error;
+       }
+
+       err = __add_profile(DEFINE_CALLLOG_SERVER_URL_HTTPS, id, password, "CALLLOG", &account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       err = __set_config_default_value(account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, DEFINE_CALLLOG_SERVER_URL_HTTPS, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, DEFINE_CALLLOG_DEFAULT_NEXT_NONCE, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       category = (sync_category *)calloc(1, sizeof(sync_category));
+
+       category->enabled = 1;
+       category->srcURI = DEFINE_SOURCE_CALLLOG_URI;
+       category->tgtURI = "./CallLog";
+
+       err = __set_profile_category(account, TYPE_CALLLOG, category);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_category");
+               goto error;
+       }
+
+       *accountId = account;
+
+       FW_LOGV("end");
+
+error:
+
+       if(category != NULL)
+               free(category);
+
+       if(password != NULL)
+               free(password);
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool delete_profile_calllog()
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       /*delete account */
+
+
+       FW_LOGV("end");
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
diff --git a/ServiceEngine/SE_AutoConfig.c b/ServiceEngine/SE_AutoConfig.c
new file mode 100644 (file)
index 0000000..d28af79
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_AutoConfig.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of auto configure in Service Engine
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceEngine/SE_AutoConfig.h"
+#include "ServiceEngine/SE_Common.h"
+#include "ServiceEngine/SE_Error.h"
+#include "ServiceEngine/SE_Sync.h"
+#include "ServiceEngine/SE_Notification.h"
+#include "Common/Common_Vconf.h"
+#include "Common/Common_Define.h"
+#include "ServiceAdapter/SA_Common_Interface.h"
+
+#define LOG_TAG        "OMA_DS_SE"
+
+bool autoconfigure_from_vconf(char *profile)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char profilePath[128];
+       char *email = NULL;
+       char *password = NULL;
+       char *serverIP = NULL;
+
+       SyncProgress process = PROGRESS_NONE;
+       SyncError error = ERROR_NONE ;
+
+       if (!profile) {
+               FW_LOGE("Not Defined profile");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto free;
+       }
+
+       sprintf(profilePath, "%s/%s", DS_SETTINGS_PATH, profile);
+
+       email = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHNAME);
+       if (email == NULL) {
+               FW_LOGE("email is NULL");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       password = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHPWD);
+       if (password == NULL) {
+               FW_LOGE("password is NULL");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       serverIP = get_vconf_str(profilePath, DS_SETTING_ADDR);
+       if (serverIP == NULL) {
+               FW_LOGE("serverIP is NULL");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       GList *configure = NULL;
+       Common_ErrorType common_err = auto_configure_from_vconf(email, password, serverIP, profilePath, &configure);
+
+       if (common_err != COMMON_CANCEL) {
+
+               convert_common_errorcode(common_err, &process, &error);
+
+               if (common_err == COMMON_OK) {
+                       err = send_noti_auto_configure(profile, configure);
+                       if (err  != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in send_noti_auto_configure");
+                               goto error;
+                       }
+               } else
+                       err = SE_INTERNAL_SA_ERROR;
+
+               err = session_process(profile, process, error);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in send_noti_auto_configure");
+                       goto error;
+               }
+       } else
+               err = SE_INTERNAL_CANCEL;
+
+       FW_LOGV("end");
+
+       goto free;
+
+error:
+
+       convert_engine_errorcode(err, &process, &error);
+       session_process(profile, process, error);
+
+free:
+
+       if (email)
+               free(email);
+       if (password)
+               free(password);
+       if (serverIP)
+               free(serverIP);
+
+       GList *iter = NULL;
+       GList *inIter = NULL;
+       for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
+
+               inIter = iter->data;
+               for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter))
+                       free(inIter->data);
+               g_list_free(inIter);
+       }
+
+       g_list_free(configure);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool autoconfigure(char *profildDirName, char *addr, char *id, char *password)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       SyncProgress process = PROGRESS_NONE;
+       SyncError error = ERROR_NONE ;
+
+       GList *configure = NULL;
+       GList *iter = NULL;
+       GList *inIter = NULL;
+
+       Common_ErrorType common_err = auto_configure(addr, id, password, &configure);
+
+       if (common_err != COMMON_CANCEL) {
+
+               convert_common_errorcode(common_err, &process, &error);
+
+               if (common_err == COMMON_OK) {
+                       err = send_noti_auto_configure(profildDirName, configure);
+                       if (err  != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in send_noti_auto_configure");
+                               goto error;
+                       }
+               } else
+                       err = SE_INTERNAL_SA_ERROR;
+
+               err = session_process(profildDirName, process, error);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in send_noti_auto_configure");
+                       goto error;
+               }
+       } else
+               err = SE_INTERNAL_CANCEL;
+
+       FW_LOGV("end");
+
+       goto free;
+
+error:
+
+       convert_engine_errorcode(err, &process, &error);
+       session_process(profildDirName, process, error);
+
+free:
+
+       for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
+
+               inIter = iter->data;
+               for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter))
+                       free(inIter->data);
+               g_list_free(inIter);
+       }
+
+       g_list_free(configure);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
diff --git a/ServiceEngine/SE_Notification.c b/ServiceEngine/SE_Notification.c
new file mode 100644 (file)
index 0000000..6ef78a7
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Notification.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of notify to ui
+ */
+
+#include "agent-framework/Event/Event_Handler.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceEngine/SE_Notification.h"
+#include "ServiceEngine/SE_Sync.h"
+
+#define LOG_TAG        "OMA_DS_SE"
+
+#define NOTI_KEY       "OMADS"
+
+SE_ErrorType send_noti_auto_configure(char *profileDirName, GList *configure)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       if (!profileDirName) {
+               FW_LOGE("Not Defined profileDirName");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       int notiType = 1;
+       Event_Data *noti = create_Noti(notiType);
+       if (noti == NULL) {
+               FW_LOGE("failed to create_Noti");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       append_eventdata_param(noti, STRING, (void *)profileDirName);
+
+       GList *iter = NULL;
+       GList *inIter = NULL;
+       char *config = NULL;
+       int count;
+       for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
+
+               inIter = iter->data;
+               count = g_list_length(inIter);
+               FW_LOGV("count =%d", count);
+               append_eventdata_param(noti, INTEGER, &count);
+
+               for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter)) {
+                       config = inIter->data;
+                       FW_LOGV("config = %s", config);
+                       append_eventdata_param(noti, STRING, (void *)config);
+               }
+       }
+
+       EVENT_ERROR event_err;
+       send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
+
+       if (event_err != EVENT_SUCCESS) {
+               FW_LOGE("failed to send_Noti");
+               err = SE_INTERNAL_EVENT_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+SE_ErrorType send_noti_sync_status(char *profileDirName)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       int notiType = 2;
+       Event_Data *noti = create_Noti(notiType);
+       if (noti == NULL) {
+               FW_LOGE("failed to create_Noti");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       FW_LOGV("synchronising profile is : %s", profileDirName);
+
+       append_eventdata_param(noti, STRING, (void *)profileDirName);
+
+       EVENT_ERROR event_err;
+       send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
+
+       if (event_err != EVENT_SUCCESS) {
+               FW_LOGE("failed to send_Noti");
+               err = SE_INTERNAL_EVENT_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+SE_ErrorType send_noti_session_process(char *profile, char *progress, char *error)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       if (!profile) {
+               FW_LOGE("Not Defined profile");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       int notiType = 3;
+       Event_Data *noti = create_Noti(notiType);
+       if (noti == NULL) {
+               FW_LOGE("failed to create_Noti");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       append_eventdata_param(noti, STRING, (void *)profile);
+       append_eventdata_param(noti, STRING, (void *)progress);
+       append_eventdata_param(noti, STRING, (void *)error);
+
+       EVENT_ERROR event_err;
+       send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
+
+       if (event_err != EVENT_SUCCESS) {
+               FW_LOGE("failed to send_Noti");
+               err = SE_INTERNAL_EVENT_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+SE_ErrorType send_noti_process_update(char *profileDirName, char *uri, char *progressStatus,
+                                                                                               char *operationType, int isFromServer, int totalPerOperation,
+                                                                                               int syncedPerOperation, int totalPerDb, int syncedPerDb)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       if (!profileDirName) {
+               FW_LOGE("Not Defined profileDirName");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       int notiType = 4;
+       Event_Data *noti = create_Noti(notiType);
+       if (noti == NULL) {
+               FW_LOGE("failed to create_Noti");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       append_eventdata_param(noti, STRING, (void *)profileDirName);
+       append_eventdata_param(noti, STRING, (void *)uri);
+       append_eventdata_param(noti, STRING, (void *)progressStatus);
+       append_eventdata_param(noti, STRING, (void *)operationType);
+       append_eventdata_param(noti, INTEGER, &isFromServer);
+       append_eventdata_param(noti, INTEGER, &totalPerOperation);
+       append_eventdata_param(noti, INTEGER, &syncedPerOperation);
+       append_eventdata_param(noti, INTEGER, &totalPerDb);
+       append_eventdata_param(noti, INTEGER, &syncedPerDb);
+
+       EVENT_ERROR event_err;
+       send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
+
+       if (event_err != EVENT_SUCCESS) {
+               FW_LOGE("failed to send_Noti");
+               err = SE_INTERNAL_EVENT_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
diff --git a/ServiceEngine/SE_Storage.c b/ServiceEngine/SE_Storage.c
new file mode 100644 (file)
index 0000000..5d350b1
--- /dev/null
@@ -0,0 +1,746 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Storage.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions which saves and gets sync results
+ */
+
+#include "stdlib.h"
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Util.h"
+#include "ServiceEngine/SE_Storage.h"
+#include "ServiceEngine/SE_Common.h"
+
+#define LOG_TAG        "OMA_DS_SE"
+
+static SE_ErrorType __write_sync_type(int accountId, AlertType alertType);
+static SE_ErrorType __write_last_session_values(int accountId, SyncSessionResult syncSessionResult, int lastSessionTime);
+
+static SE_ErrorType __write_sync_type(int accountId, AlertType alertType)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       char *syncType = NULL;
+       switch (alertType) {
+       case ALERT_SLOW_SYNC:
+               syncType = DEFINE_ALERT_SLOW_SYNC_STR;
+               break;
+       case ALERT_TWO_WAY:
+               syncType = DEFINE_ALERT_TWO_WAY_STR;
+               break;
+       case ALERT_ONE_WAY_FROM_CLIENT:
+               syncType = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR;
+               break;
+       case ALERT_ONE_WAY_FROM_SERVER:
+               syncType = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR;
+               break;
+       case ALERT_REFRESH_FROM_SERVER:
+               syncType = DEFINE_ALERT_REFRESH_FROM_SERVER_STR;
+               break;
+       case ALERT_REFRESH_FROM_CLIENT:
+               syncType = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR;
+               break;
+       default:
+               break;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+
+}
+
+static SE_ErrorType __write_last_session_values(int accountId, SyncSessionResult syncSessionResult, int lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       result = set_config_int(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, syncSessionResult, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, lastSessionTime, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;;
+}
+
+SE_ErrorType write_profile_data(int accountId, AlertType alertType, SyncSessionResult syncSessionResult, int lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       err = __write_sync_type(accountId, alertType);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in writeSyncType");
+               goto error;
+       }
+
+       err = __write_last_session_values(accountId, syncSessionResult, lastSessionTime);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in writeLastSessionValues");
+               goto error;
+       }
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
+                       err = write_sync_resource_info(accountId, alertType, content_type , lastSessionTime,
+                                       datastoreinfo_per_content_type[content_type]->clientSyncResult, datastoreinfo_per_content_type[content_type]->serverSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in writeSyncResourceInfo");
+                               goto error;
+                       }
+
+                       err = write_sync_statistics(accountId, content_type, false, datastoreinfo_per_content_type[content_type]->clientSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in writeSyncStatistics");
+                               goto error;
+                       }
+
+                       err = write_sync_statistics(accountId, content_type, true, datastoreinfo_per_content_type[content_type]->serverSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in writeSyncStatistics");
+                               goto error;
+                       }
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+       return err;
+}
+
+SE_ErrorType write_sync_statistics(int accountId, int content_type, bool isFromServer, SyncResult *pSyncResult)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       bool result;
+       char *datastore = NULL;
+       char *side = NULL;
+       char numberOfChangesPath[128];
+       char addCountPath[128];
+       char replaceCountPath[128];
+       char deleteCountPath[128];
+
+       if (content_type == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (content_type == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (content_type == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (content_type == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       if (isFromServer == true)
+               side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER;
+       else
+               side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT;
+
+       FW_LOGV("pSyncResult->numberOfChange = %d", pSyncResult->numberOfChange);
+       FW_LOGV("pSyncResult->add_count = %d", pSyncResult->add_count);
+       FW_LOGV("pSyncResult->replace_count = %d", pSyncResult->replace_count);
+       FW_LOGV("pSyncResult->delete_count = %d", pSyncResult->delete_count);
+
+       sprintf(numberOfChangesPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(addCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(replaceCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+       sprintf(deleteCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+
+       result = set_config_int(accountId, numberOfChangesPath, pSyncResult->numberOfChange, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, addCountPath, pSyncResult->add_count, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, replaceCountPath, pSyncResult->replace_count, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, deleteCountPath, pSyncResult->delete_count, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+
+}
+
+SE_ErrorType write_sync_resource_info(int accountId, AlertType alertType, int content_type , int lastSessionTime,
+                                                                                                                       SyncResult *clientSyncResult, SyncResult *serverSyncResult)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *datastore = NULL;
+       char dbSyncedPath[128];
+       char lastSessionTimePath[128];
+
+       if (content_type == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (content_type == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (content_type == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (content_type == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       FW_LOGV("clientSyncResult->sessionResult = %d", clientSyncResult->sessionResult);
+       FW_LOGV("serverSyncResult->sessionResult = %d", serverSyncResult->sessionResult);
+
+       char *dbSynced;
+       if (clientSyncResult->sessionResult == SYNC_SESSION_SUCCEEDED  &&
+                       (serverSyncResult->sessionResult == SYNC_SESSION_SUCCEEDED ||  alertType == ALERT_ONE_WAY_FROM_CLIENT || alertType == ALERT_REFRESH_FROM_CLIENT))
+               dbSynced = DEFINE_DBSYNC_SUCCESS;
+       else if (clientSyncResult->sessionResult == SYNC_SESSION_STOPPED)
+               dbSynced = DEFINE_DBSYNC_STOP;
+       else
+               dbSynced = DEFINE_DBSYNC_FAIL;
+
+       FW_LOGV("dbSynced = %s", dbSynced);
+
+       sprintf(dbSyncedPath, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
+       sprintf(lastSessionTimePath, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
+
+       result = set_config_str(accountId, dbSyncedPath, dbSynced, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, lastSessionTimePath, lastSessionTime, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+bool get_profile_name(int accountId, char **profileName)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_profile_server_info(int accountId, char **addr, char **id, char **password)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       *id = DACI_Get_Account_Email_Address(accountId);
+       if (*id == NULL) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       *password = DACI_Get_Account_Password(accountId);
+       if (*password == NULL) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_profile_sync_mode(int accountId, char **syncMode, char **syncType, char **interval)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *tempSyncType = NULL;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (tempSyncType != NULL)
+               free(tempSyncType);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_profile_sync_category(int accountId, int contentType, int *enabled, char **srcURI, char **tgtURI, char **id, char **password)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *datastore = NULL;
+       char *enabled_str = NULL;
+
+       char datastore_source[128];
+       char datastore_target[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (contentType == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       result = get_config(accountId, datastore, &enabled_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *enabled = atoi(enabled_str);
+
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       result = get_config(accountId, datastore_source, srcURI);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, datastore_target, tgtURI);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, datastore_id, id);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, datastore_pw, password);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (enabled_str != NULL)
+               free(enabled_str);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+
+}
+
+bool get_last_session_info(int accountId, int *lastSessionStatus, int *lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *lastSessionStatus_str = NULL;
+       char *lastSessionTime_str = NULL;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, &lastSessionStatus_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, &lastSessionTime_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       *lastSessionStatus = atoi(lastSessionStatus_str);
+       *lastSessionTime = atoi(lastSessionTime_str);
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (lastSessionStatus_str != NULL)
+               free(lastSessionStatus_str);
+
+       if (lastSessionTime_str != NULL)
+               free(lastSessionTime_str);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_profile_statistics(int accountId, int contentType, char **dbSynced, int *lastSessionTime,
+               int *server2Client_Total, int *server2Client_NrOfAdd, int *server2Client_NrOfDelete, int *server2Client_NrOfReplace,
+               int *client2Server_Total, int *client2Server_NrOfAdd, int *client2Server_NrOfDelete, int *client2Server_NrOfReplace)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       char *datastore = NULL;
+       char datastore_dbsynced[128];
+       char datastore_lastsessiontime[128];
+       char datastore_s2c_total[128];
+       char datastore_s2c_add[128];
+       char datastore_s2c_replace[128];
+       char datastore_s2c_delete[128];
+       char datastore_c2s_total[128];
+       char datastore_c2s_add[128];
+       char datastore_c2s_replace[128];
+       char datastore_c2s_delete[128];
+
+       char *lastSessionTime_str = NULL;
+       char *server2Client_Total_str = NULL;
+       char *server2Client_NrOfAdd_str = NULL;
+       char *server2Client_NrOfDelete_str = NULL;
+       char *server2Client_NrOfReplace_str = NULL;
+       char *client2Server_Total_str = NULL;
+       char *client2Server_NrOfAdd_str = NULL;
+       char *client2Server_NrOfDelete_str = NULL;
+       char *client2Server_NrOfReplace_str = NULL;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (contentType == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       sprintf(datastore_dbsynced, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
+       sprintf(datastore_lastsessiontime, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
+       sprintf(datastore_s2c_total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(datastore_s2c_add, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(datastore_s2c_delete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+       sprintf(datastore_s2c_replace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+
+
+       sprintf(datastore_c2s_total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(datastore_c2s_add, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(datastore_c2s_delete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+       sprintf(datastore_c2s_replace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+
+       result = get_config(accountId, datastore_dbsynced, dbSynced);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, datastore_lastsessiontime, &lastSessionTime_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *lastSessionTime = atoi(lastSessionTime_str);
+
+       result = get_config(accountId, datastore_s2c_total, &server2Client_Total_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *server2Client_Total = atoi(server2Client_Total_str);
+
+       result = get_config(accountId, datastore_s2c_add, &server2Client_NrOfAdd_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *server2Client_NrOfAdd = atoi(server2Client_NrOfAdd_str);
+
+       result = get_config(accountId, datastore_s2c_delete, &server2Client_NrOfDelete_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *server2Client_NrOfDelete = atoi(server2Client_NrOfDelete_str);
+
+       result = get_config(accountId, datastore_s2c_replace, &server2Client_NrOfReplace_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *server2Client_NrOfReplace = atoi(server2Client_NrOfReplace_str);
+
+       result = get_config(accountId, datastore_c2s_total, &client2Server_Total_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *client2Server_Total = atoi(client2Server_Total_str);
+
+       result = get_config(accountId, datastore_c2s_add, &client2Server_NrOfAdd_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *client2Server_NrOfAdd = atoi(client2Server_NrOfAdd_str);
+
+       result = get_config(accountId, datastore_c2s_delete, &client2Server_NrOfDelete_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *client2Server_NrOfDelete = atoi(client2Server_NrOfDelete_str);
+
+       result = get_config(accountId, datastore_c2s_replace, &client2Server_NrOfReplace_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *client2Server_NrOfReplace = atoi(client2Server_NrOfReplace_str);
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (lastSessionTime_str != NULL)
+               free(lastSessionTime_str);
+
+       if (server2Client_Total_str != NULL)
+               free(server2Client_Total_str);
+
+       if (server2Client_NrOfAdd_str != NULL)
+               free(server2Client_NrOfAdd_str);
+
+       if (server2Client_NrOfDelete_str != NULL)
+               free(server2Client_NrOfDelete_str);
+
+       if (server2Client_NrOfReplace_str != NULL)
+               free(server2Client_NrOfReplace_str);
+
+       if (client2Server_Total_str != NULL)
+               free(client2Server_Total_str);
+
+       if (client2Server_NrOfAdd_str != NULL)
+               free(client2Server_NrOfAdd_str);
+
+       if (client2Server_NrOfDelete_str != NULL)
+               free(client2Server_NrOfDelete_str);
+
+       if (client2Server_NrOfReplace_str != NULL)
+               free(client2Server_NrOfReplace_str);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
diff --git a/ServiceEngine/SE_Sync.c b/ServiceEngine/SE_Sync.c
new file mode 100644 (file)
index 0000000..7ca7eb3
--- /dev/null
@@ -0,0 +1,2567 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Sync.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions which process sync request, auto configure etc..
+ */
+
+
+#include <sys/time.h>
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/DACI/DACI_Agent_Mgr.h"
+#include "agent-framework/DACI/DACI_Service.h"
+#include "agent-framework/DACI/DACI_Luid.h"
+#include "agent-framework/DACI/DACI_ChangeLog.h"
+#include "agent-framework/SyncAgent_Info.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/EngineController/task_process.h"
+#include "agent-framework/Utility/fw_time.h"
+#include "agent-framework/Device/EXT_DCI_DevExecutor.h"
+#include "ServiceEngine/SE_Sync.h"
+#include "ServiceEngine/SE_Storage.h"
+#include "ServiceEngine/SE_Common.h"
+#include "ServiceEngine/SE_Notification.h"
+#include "ServiceAdapter/SA_Common_Interface.h"
+#include "Common/Common_Util.h"
+#include "Common/Common_Define_Internal.h"
+
+
+#define LOG_TAG        "OMA_DS_SE"
+
+static SE_ErrorType __session_process(int accountId, SyncProgress process, SyncError error);
+static SE_ErrorType __process_update(int accountId, SyncProgressStatus progressStatus,
+               OperationType operationType, int content_type, bool isFromServer, bool needToSave, SyncResult *syncResult);
+static SE_ErrorType __write_sync_data(int accountId, AlertType alertType, SyncSessionResult syncSessionResult, int lastSessionTime);
+static SE_ErrorType __write_sync_resource_info(int accountId,  AlertType alertType, int content_type, int lastSessionTime);
+
+static SE_ErrorType __init_datastore_info_array(int accountId);
+static SE_ErrorType __set_datastore_info_array(int accountId, char *config_key, CONTENT_TYPE content_type);
+static SE_ErrorType __generate_datastore_info(int accountId,  CONTENT_TYPE content_type, Datastore **pDatastore);
+static SE_ErrorType __init_datastore_info(int accountId,  CONTENT_TYPE content_type, Datastore **pDatastore);
+static SE_ErrorType __set_datastore_config(int accountId, int content_type, Datastore **pDatastore);
+
+static SE_ErrorType __on_synchronising_account(int accountId);
+static SE_ErrorType __off_synchronising_account(int accountId);
+
+static SE_ErrorType __assemble_changeddatastores(int accountId, SyncObj **pSyncObj);
+static SE_ErrorType __prepare_pre_sync(int accountId, char *syncMode, SanPackage *pSanPackage);
+static SE_ErrorType __set_config_based_on_syncMode(int accountId, char *syncMode, SanPackage *pSanPackage);
+static SE_ErrorType __execute_pre_sync(int accountId, PreSyncReturnObj *pPreSyncReturnObj, int sessionTime);
+static SE_ErrorType __execute_pre_sync_set_server_id(int accountId, char *devID);
+static SE_ErrorType __execute_pre_sync_datastore(int accountId, GList *datastoreInfo, int sessionTime);
+static SE_ErrorType __execute_sync(int accountId, SyncObj **pSyncObj, SyncReturnObj **SyncReturnObj);
+static SE_ErrorType __execute_sync_arrange_changelog(int accountId, GList *status);
+static SE_ErrorType __execute_sync_status(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj);
+static SE_ErrorType __execute_sync_change(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj);
+static SE_ErrorType __update_sync_result(int accountId);
+
+static CommandResult __convert_return_status(DACI_RETURN da_err);
+static char *__convert_cttype(int itemTypeId);
+static int __convert_synctype_value(char *syncType_str);
+
+static inline long myclock()
+{
+       struct timeval tv;
+       gettimeofday(&tv, 0);
+       return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
+}
+
+static SE_ErrorType __session_process(int accountId, SyncProgress process, SyncError error)
+{
+       FW_LOGV("start");
+
+       char *profileDirName = NULL;
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       if (profileDirName != NULL ){
+               err = session_process(profileDirName, process, error);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed to send noti");
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+       if (profileDirName)
+               free(profileDirName);
+
+       return err;
+}
+
+static SE_ErrorType __process_update(int accountId, SyncProgressStatus progressStatus,
+               OperationType operationType, int content_type, bool isFromServer, bool needToSave, SyncResult *syncResult)
+{
+       FW_LOGV("start with accountId =%d, progressStatus = %d, operationType = %d, content_type = %d, isFromServer = %d, needToSave = %d ",
+                                       accountId, progressStatus, operationType, content_type, isFromServer, needToSave);
+       FW_LOGV("numberOfChange = %d, received_count = %d,  syncCount = %d" ,
+                       syncResult->numberOfChange, syncResult->received_count, syncResult->add_count + syncResult->replace_count + syncResult->delete_count);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       char *profileDirName = NULL;
+       char *profile = NULL;
+       char *progressStatus_str = NULL;
+       char *operationType_str = NULL;
+       char *uri = NULL;
+
+       bool result;
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       /* do not need to send update noti to ui */
+       if(profileDirName == NULL){
+               FW_LOGV("profileDirName is NULL");
+               goto error;
+       }
+
+       if (needToSave == true) {
+               err = write_sync_statistics(accountId, content_type, isFromServer, syncResult);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in writeSyncStatistics");
+                       goto error;
+               }
+
+               syncResult->sessionResult = SYNC_SESSION_SUCCEEDED;
+       }
+
+       char *progress = NULL;
+       switch (progressStatus) {
+       case SYNC_PROGRESS_NONE:
+               progress = DEFINE_PROGRESS_NONE;
+               break;
+       case SYNC_PROGRESS_SUCCESS:
+               progress = DEFINE_PROGRESS_SUCCESS;
+               break;
+       case SYNC_FAILED_DB:
+               progress = DEFINE_FAILED_DB;
+               break;
+       case SYNC_FAILED_DB_FORBIDDEN:
+               progress = DEFINE_FAILED_DB_FORBIDDEN;
+               break;
+       case SYNC_FAILED_DB_ITEM:
+               progress = DEFINE_FAILED_DB_ITEM;
+               break;
+       case SYNC_FAILED_DB_CONFIG:
+               progress = DEFINE_FAILED_DB_CONFIG;
+               break;
+       case SYNC_FAILED_DB_DEVICEFULL:
+               progress = DEFINE_FAILED_DB_DEVICEFULL;
+               break;
+       default:
+               break;
+       }
+
+       char *operation = NULL;
+       switch (operationType) {
+       case OPERATION_NOOP:
+               operation = DEFINE_NOOP;
+               break;
+       case OPERATION_ADD:
+               operation = DEFINE_ADD;
+               break;
+       case OPERATION_DELETE:
+               operation = DEFINE_DELETE;
+               break;
+       case OPERATION_MOVE:
+               operation = DEFINE_MOVE;
+               break;
+       case OPERATION_COPY:
+               operation = DEFINE_COPY;
+               break;
+       case OPERATION_REPLACE:
+               operation = DEFINE_REPLACE;
+               break;
+       default:
+               break;
+       }
+
+       if (progress == NULL || operation == NULL) {
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (profileDirName != NULL)
+               profile = strdup(profileDirName);
+
+       progressStatus_str = strdup(progress);
+       operationType_str = strdup(operation);
+
+       if (datastoreinfo_per_content_type[content_type]->source != NULL)
+               uri = strdup(datastoreinfo_per_content_type[content_type]->source);
+
+       err = send_noti_process_update(profile, uri , progressStatus_str, operationType_str,
+                       isFromServer, 0, 0, syncResult->numberOfChange,
+                       syncResult->add_count + syncResult->replace_count + syncResult->delete_count);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in send_noti_process_update");
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (profileDirName != NULL)
+               free(profileDirName);
+
+       if (profile != NULL)
+               free(profile);
+
+       if (progressStatus_str != NULL)
+               free(progressStatus_str);
+
+       if (operationType_str != NULL)
+               free(operationType_str);
+
+       if (uri != NULL)
+               free(uri);
+
+       return err;
+}
+
+static SE_ErrorType __write_sync_data(int accountId, AlertType alertType, SyncSessionResult syncSessionResult, int lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       err = write_profile_data(accountId, alertType, syncSessionResult,  lastSessionTime);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in writeProfileData");
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+
+static SE_ErrorType __write_sync_resource_info(int accountId,  AlertType alertType, int content_type , int lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       err = write_sync_resource_info(accountId, alertType, content_type , lastSessionTime,
+                       datastoreinfo_per_content_type[content_type]->clientSyncResult, datastoreinfo_per_content_type[content_type]->serverSyncResult);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in write_sync_resource_info");
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+static SE_ErrorType __init_datastore_info_array(int accountId)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       err = __set_datastore_info_array(accountId, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS, TYPE_CONTACT);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastoreinfo_array");
+               goto error;
+       }
+
+       err = __set_datastore_info_array(accountId, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR, TYPE_CALENDAR);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastoreinfo_array");
+               goto error;
+       }
+
+       err = __set_datastore_info_array(accountId, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO, TYPE_MEMO);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastoreinfo_array");
+               goto error;
+       }
+
+       err = __set_datastore_info_array(accountId, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG, TYPE_CALLLOG);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastoreinfo_array");
+               goto error;
+       }
+
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+static SE_ErrorType __set_datastore_info_array(int accountId, char *config_key, CONTENT_TYPE content_type)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       Datastore *pDatastoreInfo = NULL;
+       bool result;
+       char *value = NULL;
+
+       result = get_config(accountId, config_key, &value);
+       if (result == true) {
+               if (strcmp(value, "1") == 0)
+                       err = __generate_datastore_info(accountId, content_type, &pDatastoreInfo);
+               else
+                       err = __init_datastore_info(accountId, content_type, &pDatastoreInfo);
+       } else
+               err = __init_datastore_info(accountId, content_type , &pDatastoreInfo);
+
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed to create or init datastore_info");
+               goto error;
+       }
+
+       datastoreinfo_per_content_type[content_type] = pDatastoreInfo;
+
+       FW_LOGV("end");
+
+error:
+
+       if (value)
+               free(value);
+
+       return err;
+}
+
+static SE_ErrorType __generate_datastore_info(int accountId,  CONTENT_TYPE content_type , Datastore **pDatastore)
+{
+       FW_LOGV("start content_type=[%d]\n",  content_type);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       char *clientLastAnchor = NULL;
+       char *clientNextAnchor = NULL;
+       char *serverLastAnchor = NULL;
+
+       daci_last_anchor *last_anchor_info  = NULL;
+       DACI_RETURN da_err;
+
+       SyncResult *pSyncResult = NULL;
+       Datastore *datastore = NULL;
+       err = __set_datastore_config(accountId, content_type, &datastore);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastore_config");
+               goto error;
+       }
+
+       /* Must get anchor per datastore for synchronization (contact, calendar, memo)
+        *              daci_last_anchor *DACI_Get_Last_Anchor_By_Account_Id(int account_id, int *count);
+        * */
+       int count = 0;
+       last_anchor_info = DACI_Get_Last_Anchor_By_Item_Type_Id(accountId, datastore->datastore_id, &count);
+
+       if (last_anchor_info != NULL) {
+               clientLastAnchor = last_anchor_info[0].last_anchor_client;
+               serverLastAnchor = last_anchor_info[0].last_anchor_server;
+       } else{
+               daci_last_anchor lastAnchor_daci;
+
+               lastAnchor_daci.account_id = accountId;
+               lastAnchor_daci.data_store_id = datastore->datastore_id;
+               lastAnchor_daci.last_anchor_server = NULL;
+               lastAnchor_daci.last_anchor_client = NULL;
+               lastAnchor_daci.access_name = "Engine";
+
+               da_err = DACI_Add_Last_Anchor(&lastAnchor_daci);
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("DACI_Add_Last_Anchor is failed %d", da_err);
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+
+       clientNextAnchor = g_strdup_printf("%ld", time(NULL));
+
+       FW_LOGV("clientLastAnchor = %s\n",  clientLastAnchor);
+       FW_LOGV("serverLastAnchor = %s\n",  serverLastAnchor);
+       FW_LOGV("clientNextAnchor = %s\n",  clientNextAnchor);
+
+       /*slow sync if managed anchor info not exist.. (first sync)*/
+       if (clientLastAnchor == NULL)
+               set_datastore_client_anchor(datastore, clientNextAnchor, clientNextAnchor);
+       else
+               set_datastore_client_anchor(datastore, clientLastAnchor, clientNextAnchor);
+
+       set_datastore_server_anchor(datastore, serverLastAnchor, NULL);
+
+       pSyncResult = create_sync_result();
+       if (pSyncResult == NULL) {
+               FW_LOGE("create_syncResult is failed");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+       datastore->clientSyncResult = pSyncResult;
+
+       pSyncResult = create_sync_result();
+       if (pSyncResult == NULL) {
+               FW_LOGE("create_syncResult is failed");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+       datastore->serverSyncResult  = pSyncResult;
+
+       *pDatastore = datastore;
+
+       FW_LOGV("end");
+
+error:
+
+       if (clientNextAnchor  != NULL)
+               free(clientNextAnchor);
+
+       if (last_anchor_info != NULL)
+               DACI_Free_Memory_Last_Anchor(last_anchor_info, count);
+
+       if (err != SE_INTERNAL_OK) {
+               if (datastore != NULL) {
+                       free_datastore(datastore);
+                       datastore = NULL;
+               }
+       }
+
+       return err;
+}
+
+static SE_ErrorType __init_datastore_info(int accountId,  CONTENT_TYPE content_type ,  Datastore **pDatastore)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       char *sourceDatastore = NULL;
+       char key[128];
+       Datastore *datastore = NULL;
+       SyncResult *pSyncResult = NULL;
+
+       bool result;
+       switch (content_type) {
+               case TYPE_CONTACT:
+                       sprintf(key, "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+                       break;
+               case TYPE_CALENDAR:
+                       sprintf(key, "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+                       break;
+               case TYPE_MEMO:
+                       sprintf(key, "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+                       break;
+               case TYPE_CALLLOG:
+                       sprintf(key, "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+                       break;
+               default:
+                       FW_LOGV("unknown content type = %d", content_type);
+                       goto error;
+       }
+
+       result = get_config(accountId, key, &sourceDatastore);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       datastore = create_datastore(NULL, sourceDatastore);
+       if (datastore == NULL) {
+               FW_LOGE("failed to create_Datastore");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       pSyncResult = create_sync_result();
+       if (pSyncResult == NULL) {
+               FW_LOGE("create_syncResult is failed");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+       datastore->clientSyncResult = pSyncResult;
+
+       pSyncResult = create_sync_result();
+       if (pSyncResult == NULL) {
+               FW_LOGE("create_syncResult is failed");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+       datastore->serverSyncResult  = pSyncResult;
+
+       *pDatastore = datastore;
+
+       FW_LOGV("end");
+
+error:
+       if (sourceDatastore != NULL)
+               free(sourceDatastore);
+
+       if (err != SE_INTERNAL_OK) {
+               if (datastore != NULL) {
+                       free_datastore(datastore);
+                       datastore = NULL;
+               }
+       }
+
+       return err;
+}
+
+static SE_ErrorType __set_datastore_config(int accountId, int content_type, Datastore **pDatastore)
+{
+       FW_LOGV("start");
+
+       Datastore *datastore = NULL;
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char *contentType = NULL;
+
+       char sourceDatastore_key[128];
+       char targetDatastore_key[128];
+       char id_key[128];
+       char pw_key[128];
+
+       char *sourceDatastore = NULL;
+       char *targetDatastore = NULL;
+       char *sync_type = NULL;
+       char *id = NULL;
+       char *pw = NULL;
+
+       int folder_type_id = 0;
+       switch (content_type) {
+               case TYPE_CONTACT:
+               {
+                       folder_type_id = 0;
+                       contentType = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+               }
+                       break;
+               case TYPE_CALENDAR:
+               {
+                       folder_type_id = 0;
+                       contentType = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+               }
+                       break;
+               case TYPE_MEMO:
+               {
+                       folder_type_id = 0;
+                       contentType = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+               }
+                       break;
+               case TYPE_CALLLOG:
+               {
+                       folder_type_id = 0;
+                       contentType = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+               }
+                       break;
+               default:
+                       FW_LOGV("unknown content type = %d", content_type);
+                       err = SE_INTERNAL_ERROR;
+                       goto error;
+       }
+
+       sprintf(sourceDatastore_key, "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(targetDatastore_key, "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(id_key, "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(pw_key, "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       bool result;
+       result = get_config(accountId, sourceDatastore_key, &sourceDatastore);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, targetDatastore_key, &targetDatastore);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, &sync_type);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       syncType = __convert_synctype_value(sync_type);
+
+       result = get_config(accountId, id_key, &id);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, pw_key, &pw);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("get_Config result  sourceDatastore= %s ",  sourceDatastore);
+       FW_LOGV("get_Config result  targetDatastore= %s ",  targetDatastore);
+       FW_LOGV("get_Config result  alertType= %s ",  sync_type);
+       FW_LOGV("get_Config result  id= %s ",  id);
+       FW_LOGV("get_Config result  pw= %s ",  pw);
+
+       datastore = create_datastore(targetDatastore, sourceDatastore);
+       if (datastore == NULL) {
+               FW_LOGE("datastore is NULL");
+               goto error;
+       }
+
+       set_datastore_contenttype_info(datastore, content_type, folder_type_id);
+       set_datastore_account_info(datastore, id, pw);
+       set_datastore_client_sync_type(datastore, syncType);
+
+       *pDatastore = datastore;
+
+       FW_LOGV("End");
+
+error:
+
+       if (sourceDatastore != NULL)
+               free(sourceDatastore);
+
+       if (targetDatastore != NULL)
+               free(targetDatastore);
+
+       if (sync_type != NULL)
+               free(sync_type);
+
+       if (id != NULL)
+               free(id);
+
+       if (pw != NULL)
+               free(pw);
+
+       if (err != SE_INTERNAL_OK) {
+               if (datastore != NULL) {
+                       free_datastore(datastore);
+                       datastore = NULL;
+               }
+       }
+
+       return err;
+}
+
+static SE_ErrorType __on_synchronising_account(int accountId)
+{
+       FW_LOGV("start ");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       bool result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, "1", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end ");
+       return err;
+
+error:
+
+       FW_LOGE("Error :%d ", err);
+       return err;
+}
+
+static SE_ErrorType __off_synchronising_account(int accountId)
+{
+       FW_LOGV("start ");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       bool result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, "0", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end ");
+       return err;
+
+error:
+
+       FW_LOGE("Error :%d ", err);
+       return err;
+}
+
+static SE_ErrorType __assemble_changeddatastores(int accountId, SyncObj **pSyncObj)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       ChangedDatastore *pChangedDatastore = NULL;
+       DACI_RETURN da_err = DACI_SUCCESS;
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++)       {
+               int count = 0;
+               if (!datastoreinfo_per_content_type[content_type]->clientSyncType) continue;
+
+               if (datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_SLOW_SYNC
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_CLIENT
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_CLIENT_BY_SERVER) {
+
+                       if( content_type == TYPE_CALLLOG ){
+                               FW_LOGV("refresh_Item_Tbl_From_Service for call log");
+                               refresh_Item_Tbl_From_Service(accountId, datastoreinfo_per_content_type[content_type]->datastore_id);
+                       }
+
+                       /*all item using accountId*/
+                       daci_item *pDaci_item = DACI_Get_item_By_Account_Id(accountId, datastoreinfo_per_content_type[content_type]->datastore_id, &count);
+
+                       pChangedDatastore = create_changeddatastore(datastoreinfo_per_content_type[content_type]->source,
+                                                                                                                                               datastoreinfo_per_content_type[content_type]->target, 1 , count);
+                       if (pChangedDatastore == NULL) {
+                               DACI_Free_Memory_Item(pDaci_item, count);
+                               FW_LOGE("failed in create_ChangedDatastore");
+                               err = SE_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       if (count > 0) {
+                               int i;
+                               for (i = 0; i < count; i++) {
+                                       char *cttype = __convert_cttype(pDaci_item[i].data_store_id);
+                                       ChangedItem *pChanged = create_changeditem(CHANGE_ADD, pDaci_item[i].item_id);
+                                       if (pChanged == NULL) {
+
+                                               DACI_Free_Memory_Item(pDaci_item, count);
+                                               FW_LOGE("failed in create_ChangedDatastore");
+                                               err = SE_INTERNAL_NO_MEMORY;
+                                               goto error;
+                                       }
+
+                                       set_changeditem_contenttype(pChanged, cttype);
+                                       set_changedItem_indexofdatastore(pChanged, content_type);
+
+                                       add_changeddatastore_changeditem(pChangedDatastore, pChanged);
+                               }
+
+                               DACI_Free_Memory_Item(pDaci_item, count);
+                       }
+               } else if (datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_TWO_WAY
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_TWO_WAY_BY_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_ONE_WAY_FROM_CLIENT
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) {
+                       FW_LOGV("server sync type is ALERT_TYPE [%d]",   datastoreinfo_per_content_type[content_type]->serverSyncType);
+
+                       /*from changelog*/
+                       daci_item_info *pDaci_item_info = DACI_Get_Item_Info_By_Item_Type_Id(accountId,
+                                                                                                               datastoreinfo_per_content_type[content_type]->datastore_id, &count);
+
+                       pChangedDatastore = create_changeddatastore(datastoreinfo_per_content_type[content_type]->source,
+                                                                                                               datastoreinfo_per_content_type[content_type]->target, 1, count);
+                       if (pChangedDatastore == NULL) {
+                               DACI_Free_Memory_Item_Info(pDaci_item_info, count);
+                               FW_LOGE("failed in create_ChangedDatastore");
+                               err = SE_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       /*gathering changelog info*/
+                       if (count > 0) {
+                               /*begin agent db transaction*/
+                               DACI_Begin_Transaction();
+
+                               char *cttype = __convert_cttype(datastoreinfo_per_content_type[content_type]->datastore_id);
+
+                               int i;
+                               for (i = 0; i < count; i++) {
+                                       ChangedItem *pChanged = create_changeditem(pDaci_item_info[i].operationId - 300, pDaci_item_info[i].itemId);
+                                       if (pChanged == NULL) {
+                                               DACI_Free_Memory_Item_Info(pDaci_item_info, count);
+                                               DACI_End_Transaction(TRANSACTION_ROLLBACK);
+                                               FW_LOGE("failed in create_ChangedDatastore");
+                                               err = SE_INTERNAL_NO_MEMORY;
+                                               goto error;
+                                       }
+
+                                       set_changeditem_contenttype(pChanged, cttype);
+                                       set_changedItem_indexofdatastore(pChanged, content_type);
+                                       add_changeddatastore_changeditem(pChangedDatastore, pChanged);
+                               }
+
+                               int *itemTypeIdList = (int *)calloc(1, sizeof(int));
+                               itemTypeIdList[0] = datastoreinfo_per_content_type[content_type]->datastore_id;
+
+                               da_err = DACI_Set_Item_Changelog_Wait_Status(accountId, NULL, 0, itemTypeIdList, 1);
+                               DACI_Free_Memory_Item_Info(pDaci_item_info, count);
+                               if (itemTypeIdList != NULL)
+                                       free(itemTypeIdList);
+                               if (da_err != DACI_SUCCESS) {
+                                       DACI_End_Transaction(TRANSACTION_ROLLBACK);
+                                       FW_LOGE("failed in DACI_Set_Item_Changelog_Wait_Status");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               DACI_End_Transaction(TRANSACTION_COMMIT);
+                       }
+               } else if (datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_ONE_WAY_FROM_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_ONE_WAY_FROM_SERVER_BY_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_SERVER_BY_SERVER) {
+                       /*MUST create empty changedDatastore..*/
+                       pChangedDatastore = create_changeddatastore(datastoreinfo_per_content_type[content_type]->source,
+                                                                                                                                                       datastoreinfo_per_content_type[content_type]->target, 1, 0);
+                       if (pChangedDatastore == NULL) {
+                               FW_LOGE("pChangedDatastore is NULL");
+                               err = SE_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       if (datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_SERVER_BY_SERVER) {
+
+                               /*FW_LOGV("refresh_Item_Tbl_From_Service");
+                               refresh_Item_Tbl_From_Service(accountId, datastoreinfo_per_content_type[content_type]->plugin_type);*/
+
+                               /*  Delete All item (include changelog), before adapting server item data…*/
+                               FW_LOGV("DACI_Service_Begin = %d", datastoreinfo_per_content_type[content_type]->datastore_id);
+                               DACI_Service_Begin(datastoreinfo_per_content_type[content_type]->datastore_id);
+                               DACI_Begin_Transaction();
+
+                               /*delete service item data*/
+                               da_err = DACI_Service_Delete_All_Items(datastoreinfo_per_content_type[content_type]->datastore_id, accountId);
+                               if (da_err != DACI_SUCCESS) {
+
+                                       DACI_Service_End(datastoreinfo_per_content_type[content_type]->datastore_id, 0);
+                                       DACI_End_Transaction(TRANSACTION_ROLLBACK);
+
+                                       FW_LOGE("failed in DACI_Service_Delete_All_Items");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               int item_cnt;
+                               FW_LOGV("DACI_Get_item_By_Account_Id");
+                               /*get all item by account id*/
+                               daci_item *pDaci_item = DACI_Get_item_By_Account_Id(accountId, datastoreinfo_per_content_type[content_type]->datastore_id, &item_cnt);
+                               FW_LOGV("item_cnt = %d", item_cnt);
+
+                               int j;
+                               int acc_cnt;
+                               for (j = 0; j < item_cnt ; j++) {
+                                       daci_item *pDaci_item_from_other_account = DACI_Get_item_Mapping_Service_Id(accountId, pDaci_item[j].item_id, &acc_cnt);
+                                       FW_LOGV("acc_cnt = %d", acc_cnt);
+
+                                       int i;
+                                       for (i = 0; i < acc_cnt; i++)
+                                               ChangeLog_Delete_Item(pDaci_item_from_other_account[i].account_id, pDaci_item_from_other_account[i].item_id,
+                                                                                                                                                                                                                       datastoreinfo_per_content_type[content_type]->datastore_id);
+
+                                       DACI_Free_Memory_Item(pDaci_item_from_other_account, acc_cnt);
+                               }
+
+                               /*delete item from item_tbl*/
+                               FW_LOGV("DACI_Delete_Item_By_Item_Type_Id = %d", datastoreinfo_per_content_type[content_type]->datastore_id);
+                               da_err = DACI_Delete_Item_By_Item_Type_Id(accountId, datastoreinfo_per_content_type[content_type]->datastore_id);
+                               if (da_err != DACI_SUCCESS) {
+
+                                       DACI_Free_Memory_Item(pDaci_item, item_cnt);
+
+                                       DACI_Service_End(datastoreinfo_per_content_type[content_type]->datastore_id, 0);
+                                       DACI_End_Transaction(TRANSACTION_ROLLBACK);
+
+                                       FW_LOGE("failed in DACI_Delete_Item_By_Item_Type_Id");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               /*delete changelog data bu account id*/
+                               FW_LOGV("DACI_Delete_Item_Changelog_By_Item_Type_Id = %d", datastoreinfo_per_content_type[content_type]->datastore_id);
+                               da_err = DACI_Delete_Item_Changelog_By_Item_Type_Id(accountId, datastoreinfo_per_content_type[content_type]->datastore_id);
+                               if (da_err != DACI_SUCCESS) {
+
+                                       DACI_Free_Memory_Item(pDaci_item, item_cnt);
+
+                                       DACI_Service_End(datastoreinfo_per_content_type[content_type]->datastore_id, 0);
+                                       DACI_End_Transaction(TRANSACTION_ROLLBACK);
+
+                                       FW_LOGE("failed in DACI_Delete_Item_Changelog_By_Item_Type_Id");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               FW_LOGV("DACI_Service_End = %d", datastoreinfo_per_content_type[content_type]->datastore_id);
+                               DACI_Service_End(datastoreinfo_per_content_type[content_type]->datastore_id, 1);
+                               DACI_End_Transaction(TRANSACTION_COMMIT);
+
+                               DACI_Free_Memory_Item(pDaci_item, item_cnt);
+                       }
+               }
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
+                       (*pSyncObj)->changedDatastore =  g_list_append((*pSyncObj)->changedDatastore, pChangedDatastore);
+
+                       set_numberofchange(datastoreinfo_per_content_type[content_type]->clientSyncResult, pChangedDatastore->numberOfChanges);
+
+                       OperationType operationType;
+                       if (datastoreinfo_per_content_type[content_type]->clientSyncResult->numberOfChange == 0)
+                               operationType = OPERATION_NOOP;
+                       else
+                               operationType = OPERATION_ADD;
+                       err = __process_update(accountId,  SYNC_PROGRESS_SUCCESS, operationType, content_type, false, false,
+                                                                                                                                                               datastoreinfo_per_content_type[content_type]->clientSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("Failed in process_update");
+                               goto error;
+                       }
+               }
+       }
+
+       FW_LOGV("end");
+
+       return err;
+
+error:
+
+       if (pChangedDatastore != NULL) {
+               free_changeddatastore(pChangedDatastore);
+               pChangedDatastore = NULL;
+       }
+
+       return err;
+}
+
+static SE_ErrorType __prepare_pre_sync(int accountId, char *syncMode, SanPackage *pSanPackage)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       /*set synchronising flag into agent DB*/
+       err =  __on_synchronising_account(accountId);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_synchronising_account");
+               goto error;
+       }
+
+       /*init datastore_info_array*/
+       err = __init_datastore_info_array(accountId);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in init_datastoreInfo_array");
+               goto error;
+       }
+
+       /*set config based on sync mode*/
+       err = __set_config_based_on_syncMode(accountId, syncMode, pSanPackage);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_synchronising_account");
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+static SE_ErrorType __set_config_based_on_syncMode(int accountId, char *syncMode, SanPackage *pSanPackage)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       int content_type;
+       bool result;
+
+       if (strcmp(syncMode, DEFINE_SYNC_MODE_MANUAL) != 0) {
+               char *profileDirName = NULL;
+
+               result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
+               if (result == false) {
+                       FW_LOGE("failed in get_Config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               if (profileDirName != NULL) {
+                       err = send_noti_sync_status(profileDirName);
+                       if (profileDirName != NULL)
+                               free(profileDirName);
+
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in send_noti_sync_status");
+                               goto error;
+                       }
+               }
+       }
+
+       if (strcmp(syncMode, DEFINE_SYNC_MODE_PUSH) == 0) {
+               if (pSanPackage != NULL) {
+                       int count = pSanPackage->cntSyncAlerts;
+                       FW_LOGV("count = %d", count);
+                       int i;
+                       for (i = 0 ; i < count ; i++) {
+                               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+
+                                       if (datastoreinfo_per_content_type[content_type]->target == NULL) continue;
+
+                                       if (strcmp(pSanPackage->syncAlerts[i].serverURI, datastoreinfo_per_content_type[content_type]->target) == 0) {
+                                               datastoreinfo_per_content_type[content_type]->clientSyncType = pSanPackage->syncAlerts[i].syncType;
+                                               FW_LOGV("pSanPackage->syncAlerts[i].syncType = %d", pSanPackage->syncAlerts[i].syncType);
+                                       } else
+                                               datastoreinfo_per_content_type[content_type]->clientSyncType = ALERT_UNKNOWN;
+
+                               }
+                       }
+               }
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+
+static SE_ErrorType  __execute_pre_sync(int accountId, PreSyncReturnObj *pPreSyncReturnObj, int sessionTime)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       /*if there is no alert command from server check it and goto fail_part*/
+       if (g_list_length(pPreSyncReturnObj->datastoreInfo) == 0) {
+               FW_LOGV("alert command list from server is empty");
+               err = SE_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       err = __execute_pre_sync_set_server_id(accountId, pPreSyncReturnObj->devID);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_server_id");
+               goto error;
+       }
+
+       err = __execute_pre_sync_datastore(accountId, pPreSyncReturnObj->datastoreInfo, sessionTime);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __process_datastore");
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+
+}
+
+/*FIXME : set Server_id for SAN*/
+static SE_ErrorType __execute_pre_sync_set_server_id(int accountId, char *devID)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *value = NULL;
+       result =  get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &value);
+       if (result == true) {
+               if (value != NULL) {
+                       if (strcmp(value, devID) == 0) {
+                               /* OK*/
+                       } else{
+                               result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, devID, "string", "SE");
+                               if (result == false) {
+                                       FW_LOGE("failed in set_Config");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+                       }
+               } else{
+                       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, devID, "string", "SE");
+                       if (result == false) {
+                               FW_LOGE("failed in set_Config");
+                               err = SE_INTERNAL_DA_ERROR;
+                               goto error;
+                       }
+               }
+       } else{
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+error:
+
+       if (value != NULL) {
+               free(value);
+               value = NULL;
+       }
+       FW_LOGV("end");
+
+       return err;
+}
+
+static SE_ErrorType __execute_pre_sync_datastore(int accountId, GList *datastoreInfo, int sessionTime)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       int content_type;
+       GList *serverDatastore_iter = NULL;
+       DatastoreInfo *serverDatastoreInfo = NULL;
+       bool existInServerDatastore;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               existInServerDatastore =  false;
+
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
+
+                       for (serverDatastore_iter = datastoreInfo; serverDatastore_iter != NULL;  serverDatastore_iter = g_list_next(serverDatastore_iter)) {
+                                       serverDatastoreInfo = serverDatastore_iter->data;
+
+                               if (strcmp(serverDatastoreInfo->source, datastoreinfo_per_content_type[content_type]->target) == 0) {
+                                       existInServerDatastore = true;
+
+                                       datastoreinfo_per_content_type[content_type]->serverSyncType = serverDatastoreInfo->syncType;
+                                       datastoreinfo_per_content_type[content_type]->nextAnchorServer = strdup(serverDatastoreInfo->nextAnchor);
+
+                                       if (datastoreinfo_per_content_type[content_type]->lastAnchorServer) {
+                                               /*if (strcmp(datastoreinfo_per_content_type[content_type]->lastAnchorServer, serverDatastoreInfo->lastAnchor) != 0) {
+                                                       free(datastoreinfo_per_content_type[content_type]->lastAnchorServer);
+                                                       datastoreinfo_per_content_type[content_type]->lastAnchorServer = NULL;
+                                                       datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_SLOW_SYNC;
+                                               }*/
+                                       } else{
+                                               /* When first synchronize, lastAnchorServer is NULL...
+                                               if (datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_SLOW_SYNC
+                                                                       && datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_REFRESH_FROM_CLIENT
+                                                                       && datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_REFRESH_FROM_CLIENT_BY_SERVER
+                                                                       && datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_REFRESH_FROM_SERVER
+                                                                       && datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_REFRESH_FROM_SERVER_BY_SERVER) {
+                                                       FW_LOGV("refresh_Item_Tbl_From_Service");
+                                                       refresh_Item_Tbl_From_Service(accountId, datastoreinfo_per_content_type[content_type]->plugin_type);
+                                               }*/
+                                       }
+                                       break;
+                               }
+                       }
+
+                       if (!existInServerDatastore) {
+                               /* datastore config is wrong this datastore is not going to contain sync process from now*/
+                               err = __process_update(accountId,  SYNC_FAILED_DB_CONFIG, OPERATION_NOOP, content_type, false, true,
+                                                                                                               datastoreinfo_per_content_type[content_type]->clientSyncResult);
+                               if (err != SE_INTERNAL_OK) {
+                                       FW_LOGE("failed to process_update");
+                                       goto error;
+                               }
+
+                               err = __process_update(accountId,  SYNC_FAILED_DB_CONFIG, OPERATION_NOOP, content_type, true, true,
+                                                                                                               datastoreinfo_per_content_type[content_type]->serverSyncResult);
+                               if (err != SE_INTERNAL_OK) {
+                                       FW_LOGE("failed to process_update");
+                                       goto error;
+                               }
+
+                               datastoreinfo_per_content_type[content_type]->clientSyncResult->sessionResult = SYNC_SESSION_FAILED;
+                               err = __write_sync_resource_info(accountId, syncType, content_type , sessionTime);
+                               if (err != SE_INTERNAL_OK) {
+                                       FW_LOGE("failed to write_SyncResourceInfo");
+                                       goto error;
+                               }
+
+                               free_datastore(datastoreinfo_per_content_type[content_type]);
+                               datastoreinfo_per_content_type[content_type] = NULL;
+
+                               Datastore *pDatastore = NULL;
+                               err = __init_datastore_info(accountId, content_type, &pDatastore);
+                               if (err != SE_INTERNAL_OK) {
+                                       FW_LOGE("failed to init_datastore_info");
+                                       goto error;
+                               }
+
+                               datastoreinfo_per_content_type[content_type] = pDatastore;
+                       }
+               }
+       }
+
+error:
+       FW_LOGV("end");
+
+       return err;
+}
+
+static SE_ErrorType __execute_sync(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       if (syncType == ALERT_TWO_WAY || syncType == ALERT_TWO_WAY_BY_SERVER ||
+                       syncType == ALERT_ONE_WAY_FROM_CLIENT || syncType == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) {
+
+               err = __execute_sync_arrange_changelog(accountId , (*pSyncReturnObj)->status);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed to process_update");
+                       goto error;
+               }
+       }
+
+       err = __execute_sync_status(accountId, pSyncObj, pSyncReturnObj);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __execute_sync_status");
+               goto error;
+       }
+
+       err = __execute_sync_change(accountId, pSyncObj, pSyncReturnObj);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __execute_sync_status");
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+static SE_ErrorType __execute_sync_arrange_changelog(int accountId, GList *status)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       DACI_RETURN da_err;
+
+       int i = 0;
+       int count = 0;
+       int list_length = g_list_length(status);
+       char **itemIdList = (char **)calloc(list_length, sizeof(char *));
+       if (itemIdList == NULL) {
+               FW_LOGE("Failed to alloc memory");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       GList *appliedStatus_iter = NULL;
+       AppliedStatus *pAppliedStatus = NULL;
+       for (appliedStatus_iter = status; appliedStatus_iter != NULL; appliedStatus_iter = g_list_next(appliedStatus_iter)) {
+               pAppliedStatus = appliedStatus_iter->data;
+
+               switch (pAppliedStatus->status) {
+                       case 200:
+                       case 201:
+                       case 202:
+                       case 203:
+                       case 204:
+                       case 205:
+                       case 207:
+                       case 208:
+                       case 209:
+                       case 210:
+                       case 211:
+                       {
+                               /*clean up change log*/
+                               itemIdList[count++] = strdup(pAppliedStatus->luid);
+
+                               if (syncType == ALERT_TWO_WAY || syncType == ALERT_TWO_WAY_BY_SERVER ||
+                                               syncType == ALERT_ONE_WAY_FROM_CLIENT || syncType == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) {
+
+                                       if (pAppliedStatus->changeType == CHANGE_DELETE) {
+                                               da_err = DACI_Delete_Item_By_Item_Id(pAppliedStatus->luid);
+                                               if (da_err != DACI_SUCCESS) {
+                                                       FW_LOGE("failed in DACI_Delete_Item_By_Item_Id");
+                                                       err = SE_INTERNAL_DA_ERROR;
+                                                       goto error;
+                                               }
+                                       }
+                               }
+                               break;
+                       }
+                       case 206:
+                       case 420:
+                               break;
+                       case 400:
+                       case 500:
+                       {
+                               daci_item_changelog get_changelog;
+                               get_changelog.item_id = pAppliedStatus->luid;
+
+                               da_err = DACI_Get_Item_Changelog_By_Item_Id(accountId, &get_changelog);
+
+                               if (da_err == DACI_ERR_NO_DATA) {
+                                       FW_LOGV("%s item does not exist in ChangeLog tbl", pAppliedStatus->luid);
+                                       break;
+                               } else if (da_err != DACI_SUCCESS) {
+
+                                       FW_LOGE("failed in DACI_Get_Item_Changelog_By_Item_Id");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               if (get_changelog.status != NULL) {
+                                       if (strcmp(get_changelog.status, "SYNC_ERROR") == 0)
+                                               itemIdList[count++] = strdup(pAppliedStatus->luid);
+                                       else{
+                                               daci_item_changelog set_changelog;
+
+                                               set_changelog.item_id = pAppliedStatus->luid;
+                                               set_changelog.status = "SYNC_ERROR";
+                                               set_changelog.access_name = "SE";
+
+
+                                               da_err =  DACI_Set_Item_Changelog_Sync_Status(accountId, &set_changelog);
+
+                                               if (get_changelog.status != NULL)
+                                                       free(get_changelog.status);
+
+                                               if (get_changelog.access_name != NULL)
+                                                       free(get_changelog.access_name);
+                                               if (da_err != DACI_SUCCESS) {
+                                                       FW_LOGE("failed in DACI_Delete_Item_By_Item_Id");
+                                                       err = SE_INTERNAL_DA_ERROR;
+                                                       goto error;
+                                               }
+                                       }
+                               }
+                               break;
+                       }
+               }
+       }
+
+       if (list_length >= 1) {
+               FW_LOGV("before DACI_Delete_Item_Changelog_By_Item_Id_List");
+               FW_LOGV("count = %d",  count);
+               da_err = DACI_Delete_Item_Changelog_By_Item_Id_List(accountId, itemIdList, count);
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("failed in DACI_Delete_Item_Changelog_By_Item_Id_List");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       /*free itemIdList*/
+       if (itemIdList != NULL) {
+               for (i = 0; i < list_length; i++) {
+                       if (itemIdList[i])
+                               free(itemIdList[i]);
+               }
+               free(itemIdList);
+       }
+
+       return err;
+}
+
+static SE_ErrorType __execute_sync_status(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       int content_type;
+       bool existEqualItem;
+       bool needToSave;
+       SyncResult *pClientSyncResult;
+       GList *changedDatastore_iter = NULL;
+       ChangedDatastore *pSyncChangedDatastore = NULL;
+       for (changedDatastore_iter = (*pSyncObj)->changedDatastore; changedDatastore_iter != NULL;) {
+               pSyncChangedDatastore = (ChangedDatastore *)changedDatastore_iter->data;
+               FW_LOGV("pChangedDatastore = %p", pSyncChangedDatastore);
+
+               int datastoreContentType = 0;
+               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+                       if (strcmp(pSyncChangedDatastore->source, datastoreinfo_per_content_type[content_type]->source) == 0) {
+                               datastoreContentType = content_type;
+                               break;
+                       }
+               }
+
+               GList *changedItem_iter = NULL;
+               ChangedItem *changedItem = NULL;
+               for (changedItem_iter = pSyncChangedDatastore->sentItem; changedItem_iter != NULL;) {
+                       changedItem = changedItem_iter->data;
+
+                       existEqualItem = false;
+                       GList *appliedStatus_iter = NULL;
+                       AppliedStatus *pAppliedStatus = NULL;
+                       for (appliedStatus_iter = (*pSyncReturnObj)->status; appliedStatus_iter != NULL; appliedStatus_iter = g_list_next(appliedStatus_iter)) {
+                               pAppliedStatus = appliedStatus_iter->data;
+
+                               if (strcmp(pAppliedStatus->luid, changedItem->luid) == 0) {
+                                       add_receive_count(datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult, 1);
+
+                                       if (pAppliedStatus->status >= 200  && pAppliedStatus->status <= 211) {
+                                               switch (changedItem->changeType) {
+                                               case CHANGE_ADD:
+                                                       add_add_count(datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult, 1);
+                                                       break;
+                                               case CHANGE_REPLACE:
+                                                       add_replace_count(datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult, 1);
+                                                       break;
+                                               case CHANGE_DELETE:
+                                                       add_delete_count(datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult, 1);
+                                                       break;
+                                               default:
+                                                       break;
+                                               }
+                                       } else{
+                                               /* if status is not success count it is failed*/
+                                       }
+
+                                       (*pSyncReturnObj)->status = g_list_remove((*pSyncReturnObj)->status, pAppliedStatus);
+                                       free_appliedstatus(pAppliedStatus);
+                                       pAppliedStatus = NULL;
+
+                                       changedItem_iter = g_list_next(changedItem_iter);
+
+                                       pSyncChangedDatastore->sentItem = g_list_remove(pSyncChangedDatastore->sentItem, changedItem);
+                                       free_changeditem(changedItem);
+                                       changedItem = NULL;
+
+                                       existEqualItem = true;
+                                       break;
+                               }
+                       }
+                       if (existEqualItem == false)
+                               changedItem_iter = g_list_next(changedItem_iter);
+               }
+
+               changedDatastore_iter =  g_list_next(changedDatastore_iter);
+
+               needToSave = false;
+               pClientSyncResult = datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult;
+               if (pClientSyncResult->numberOfChange == pClientSyncResult->received_count) {
+                       needToSave = true;
+                       /*remove datastore from list and
+                       free current ChangedDatastore it does not need anymore because all item in datastore has been sent and receive status*/
+                        (*pSyncObj)->changedDatastore = g_list_remove((*pSyncObj)->changedDatastore, pSyncChangedDatastore);
+                       free_changeddatastore(pSyncChangedDatastore);
+                       pSyncChangedDatastore = NULL;
+               }
+
+               OperationType operationType;
+               if (datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult->numberOfChange == 0)
+                       operationType = OPERATION_NOOP;
+               else
+                       operationType = OPERATION_ADD;
+               err = __process_update(accountId, SYNC_PROGRESS_SUCCESS, operationType, datastoreContentType, false,  needToSave,
+                                                                                       datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in process_update");
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+static SE_ErrorType __execute_sync_change(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       DACI_RETURN da_err = DACI_SUCCESS;
+       int content_type;
+
+       /* process command that from server sended to client(sync, add, replace etc...)*/
+       ChangedDatastore *pSyncReturnChangedDatastore = NULL;
+       SendingStatus *sendingStatus = NULL;
+       GList *iter = NULL;
+       for (iter = (*pSyncReturnObj)->changedDatastore; iter != NULL;) {
+               pSyncReturnChangedDatastore = (ChangedDatastore *)iter->data;
+
+               int datastoreContentType = 0;
+               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+                       if (strcmp(pSyncReturnChangedDatastore->target, datastoreinfo_per_content_type[content_type]->source) == 0) {
+                               datastoreContentType = content_type;
+                               break;
+                       }
+               }
+
+               /*noti to UI numberOfChanges from server*/
+               if (pSyncReturnChangedDatastore->hasNumberOfChanges) {
+                       set_numberofchange(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, pSyncReturnChangedDatastore->numberOfChanges);
+
+                       OperationType operationType;
+                       if (datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult->numberOfChange == 0)
+                               operationType = OPERATION_NOOP;
+                       else
+                               operationType = OPERATION_ADD;
+                       err = __process_update(accountId,  SYNC_PROGRESS_SUCCESS, operationType, datastoreContentType, true, false,
+                                                                                               datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in process_update");
+                               goto error;
+                       }
+               }
+
+               sendingStatus = create_sendingstatus(pSyncReturnChangedDatastore->target, pSyncReturnChangedDatastore->source);
+               if (sendingStatus == NULL) {
+                       err = SE_INTERNAL_NO_MEMORY;
+                       FW_LOGE("failed to alloc memory");
+                       goto error;
+               }
+
+               SyncResult *tempServerSyncResult = NULL;
+               int changeItemCount = g_list_length(pSyncReturnChangedDatastore->changeItem);
+               if (changeItemCount > 0) {
+                       /*begin transaction*/
+                       FW_LOGV("DACI_Service_Begin with datastoreContentType = %d", datastoreContentType);
+                       DACI_Service_Begin(datastoreinfo_per_content_type[datastoreContentType]->datastore_id);
+                       DACI_Begin_Transaction();
+
+                       /*back up syncresult structure for rollback case*/
+                       tempServerSyncResult = dup_syncresult(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult);
+               }
+
+               /*get folderId*/
+               char *folderId = NULL;
+               daci_id_list *folder_id_list = DACI_Get_Folder_Folder_Id_By_Folder_Type_Id(accountId,
+                                                                                                               datastoreinfo_per_content_type[datastoreContentType]->datastore_id,
+                                                                                                               datastoreinfo_per_content_type[datastoreContentType]->folder_type_id);
+               if (folder_id_list != NULL) {
+                       folderId = folder_id_list->id[0];
+               }
+
+               bool needToSave = false;
+               SyncResult *pServerSyncResult = NULL;
+               GList *changedIter = NULL;
+               ChangedItem *changedItem = NULL;
+               AppliedStatus *appliedStatus = NULL;
+
+               for (changedIter = pSyncReturnChangedDatastore->changeItem; changedIter != NULL; changedIter = g_list_next(changedIter)) {
+                       changedItem = (changedIter->data);
+
+                       FW_LOGV("changedItem->changeType : %d", changedItem->changeType);
+                       FW_LOGV("changedItem->luid : %s", changedItem->luid);
+                       FW_LOGV("changedItem->content_type : %s", changedItem->content_type);
+                       FW_LOGV("changedItem->indexOfDatastore : %d", changedItem->indexOfDatastore);
+                       FW_LOGV("changedItem->data : %s", changedItem->data);
+
+                       add_receive_count(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, 1);
+
+                       bool da_fail = false;
+                       CommandResult returnResult = COMMAND_RESULT_INIT;
+                       switch (changedItem->changeType) {
+                               case CHANGE_ADD:
+                               {
+                                       /* add to service DB*/
+                                       if (changedItem->data != NULL) {
+                                               char *service_id = NULL;
+                                               da_err = DACI_Service_Add_Item(datastoreinfo_per_content_type[datastoreContentType]->datastore_id,
+                                                                                                                                                       accountId, folderId, (const void *)(changedItem->data), &service_id);
+                                               FW_LOGV("da_err = %d", da_err);
+
+                                               if (da_err == DACI_SUCCESS) {
+
+                                                       daci_item daci_item_s;
+                                                       daci_item_s.account_id = accountId;
+                                                       daci_item_s.item_id = changedItem->luid;
+                                                       daci_item_s.folder_id = folderId;
+                                                       daci_item_s.data_store_id = datastoreinfo_per_content_type[datastoreContentType]->datastore_id;
+                                                       daci_item_s.service_id = service_id;
+                                                       daci_item_s.access_name = "Engine";
+
+                                                       da_err = DACI_Add_Item(&daci_item_s, 1);
+                                                       FW_LOGV("da_err = %d", da_err);
+                                                       if (da_err == DACI_SUCCESS) {
+                                                               int acc_cnt;
+                                                               daci_folder *pDaci_folder = DACI_Get_Folder_Mapping_Service_Id(accountId, folderId,  &acc_cnt);
+                                                               FW_LOGV("acc_cnt = %d", acc_cnt);
+
+                                                               int i;
+                                                               bool success = true;
+
+                                                               char **fw_item_id_list = DACI_Generate_Item_Luid(1, acc_cnt);
+                                                               for (i = 0; i < acc_cnt; i++) {
+                                                                       da_err = ChangeLog_Add_Item(pDaci_folder[i].account_id, fw_item_id_list[i], service_id,
+                                                                                               datastoreinfo_per_content_type[content_type]->datastore_id, pDaci_folder[i].folder_id);
+                                                                       free(fw_item_id_list[i]);
+
+                                                                       FW_LOGV("da_err = %d", da_err);
+
+                                                                       if (da_err != DACI_SUCCESS) {
+                                                                               success = false;
+                                                                               break;
+                                                                       }
+                                                               }
+                                                               if (fw_item_id_list != NULL) {
+                                                                       free(fw_item_id_list);
+                                                               }
+
+                                                               if (success == true) {
+                                                                       returnResult = COMMAND_RESULT_ADDED;
+                                                                       add_add_count(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, 1);
+                                                               } else{
+                                                                       /*this case just fail do rollback and goto fail*/
+                                                                       returnResult = __convert_return_status(da_err);
+                                                                       da_fail = true;
+                                                               }
+                                                               DACI_Free_Memory_Folder(pDaci_folder, acc_cnt);
+                                                       } else{
+                                                               /*this case just fail do rollback and goto fail*/
+                                                               returnResult = __convert_return_status(da_err);
+                                                               da_fail = true;
+                                                       }
+                                               } else  if (da_err ==  DACI_ERR_NOT_SUPPORTED || da_err == DACI_ERR_INVALID_CONTENT || da_err == DACI_ERR_ALREADY_EXIST) {
+                                                       /*just return error to server*/
+                                                       returnResult = __convert_return_status(da_err);
+                                               } else{
+                                                       /*this case just fail do rollback and goto fail*/
+                                                       returnResult = __convert_return_status(da_err);
+                                                       da_fail = true;
+                                               }
+
+                                               if (service_id != NULL)
+                                                       free(service_id);
+                                       } else
+                                               returnResult = COMMAND_RESULT_COMMAND_FAIL;
+
+                                       break;
+                               }
+                               case CHANGE_REPLACE:
+                               {
+                                       if (changedItem->data != NULL) {
+                                               /* update from service DB*/
+                                               da_err =  DACI_Service_Update_Item(datastoreinfo_per_content_type[datastoreContentType]->datastore_id,
+                                                                                                                                               accountId, folderId, changedItem->luid, (const void *)(changedItem->data));
+                                               FW_LOGV("da_err = %d", da_err);
+                                               if (da_err == DACI_SUCCESS) {
+
+                                                       int acc_cnt;
+                                                       daci_item *pDaci_item_from_other_account = DACI_Get_item_Mapping_Service_Id(accountId, changedItem->luid, &acc_cnt);
+
+                                                       int i;
+                                                       bool success = true;
+                                                       for (i = 0; i < acc_cnt; i++) {
+                                                               da_err = ChangeLog_Update_Item(pDaci_item_from_other_account[i].account_id, pDaci_item_from_other_account[i].item_id,
+                                                                                                                                                       datastoreinfo_per_content_type[content_type]->datastore_id);
+                                                               if (da_err != DACI_SUCCESS) {
+                                                                       success = false;
+                                                                       break;
+                                                               }
+                                                       }
+
+                                                       if (success == true) {
+                                                               returnResult = COMMAND_RESULT_OK;
+                                                               add_replace_count(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, 1);
+                                                       } else{
+                                                               /*this case just fail do rollback and goto fail*/
+                                                               returnResult = __convert_return_status(da_err);
+                                                               da_fail = true;
+                                                       }
+                                                       DACI_Free_Memory_Item(pDaci_item_from_other_account, acc_cnt);
+                                               } else if (da_err ==  DACI_ERR_NOT_SUPPORTED || da_err == DACI_ERR_INVALID_CONTENT) {
+                                                       /*just return error to server*/
+                                                       returnResult = __convert_return_status(da_err);
+                                               } else{
+                                                       /*this case just fail do rollback and goto fail*/
+                                                       returnResult = __convert_return_status(da_err);
+                                                       da_fail = true;
+                                               }
+                                       } else
+                                               returnResult = COMMAND_RESULT_COMMAND_FAIL;
+
+                                       break;
+                               }
+                               case CHANGE_DELETE:
+                               {
+                                       /* delete from service DB*/
+                                       da_err =  DACI_Service_Delete_Item(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, accountId, folderId, changedItem->luid);
+                                       FW_LOGV("[DACI_Service_Delete_Item] result : %d", da_err);
+                                       if (da_err == DACI_SUCCESS) {
+                                               int acc_cnt;
+                                               daci_item *pDaci_item_from_other_account = DACI_Get_item_Mapping_Service_Id(accountId, changedItem->luid, &acc_cnt);
+
+                                               int i;
+                                               bool success = true;
+                                               for (i = 0; i < acc_cnt; i++) {
+                                                       da_err = ChangeLog_Delete_Item(pDaci_item_from_other_account[i].account_id, pDaci_item_from_other_account[i].item_id,
+                                                                                                                                               datastoreinfo_per_content_type[content_type]->datastore_id);
+                                                       if (da_err != DACI_SUCCESS) {
+                                                               success = false;
+                                                               break;
+                                                       }
+                                               }
+
+                                               DACI_Free_Memory_Item(pDaci_item_from_other_account, acc_cnt);
+                                               if (success == true) {
+                                                       da_err =  DACI_Delete_Item_By_Item_Id(changedItem->luid);
+                                                       if (da_err == DACI_SUCCESS) {
+                                                               returnResult = COMMAND_RESULT_DELETE_WITHOUT_ARCHIVE;
+                                                               add_delete_count(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, 1);
+                                                       } else {
+                                                               /*this case just fail do rollback and goto fail*/
+                                                               returnResult = __convert_return_status(da_err);
+                                                               da_fail = true;
+                                                       }
+                                               } else {
+                                                       /*this case just fail do rollback and goto fail*/
+                                                       returnResult = __convert_return_status(da_err);
+                                                       da_fail = true;
+                                               }
+                                       } else if (da_err == DACI_ERR_NO_DATA || da_err == DACI_ERR_SUB_DATA_EXIST || da_err == DACI_ERR_INVALID_CONTENT) {
+                                               /*just return error to server*/
+                                               returnResult = __convert_return_status(da_err);
+                                       } else {
+                                               /*this case just fail do rollback and goto fail*/
+                                               returnResult = __convert_return_status(da_err);
+                                               da_fail = true;
+                                       }
+
+                                       break;
+                               }
+                               default:
+                                       break;
+                       }
+
+                       if (da_fail == true) {
+
+                               if (folderId != NULL)
+                                       free(folderId);
+
+                               /*replace syncresult when rollback happened*/
+                               if (datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult != NULL)
+                                       free(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult);
+
+                               datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult = tempServerSyncResult;
+
+                               FW_LOGV("Transaction_Rollback");
+                               FW_LOGV("DACI_Service_End with datastoreContentType = %d", datastoreContentType);
+                               DACI_Service_End(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 0);
+                               DACI_End_Transaction(TRANSACTION_ROLLBACK);
+
+                               err = SE_INTERNAL_DA_ERROR;
+                               FW_LOGE("failed in DA");
+                               goto error;
+                       }
+
+                       appliedStatus = create_appliedstatus(changedItem->luid, changedItem->changeType, returnResult);
+                       if (appliedStatus == NULL) {
+                               err = SE_INTERNAL_NO_MEMORY;
+                               FW_LOGE("failed to alloc memory");
+                               goto error;
+                       }
+                       add_sendingstatus_appliedstatus(sendingStatus, appliedStatus);
+               }
+
+               if (folderId != NULL)
+                       free(folderId);
+
+               if (changeItemCount > 0) {
+
+                       if (tempServerSyncResult != NULL)
+                               free(tempServerSyncResult);
+
+                       /*end transaction*/
+                       FW_LOGV("DACI_Service_End with datastoreContentType = %d", datastoreContentType);
+                       DACI_Service_End(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 1);
+                       DACI_End_Transaction(TRANSACTION_COMMIT);
+               }
+
+               needToSave = false;
+               pServerSyncResult = datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult;
+               if (pServerSyncResult->numberOfChange == pServerSyncResult->received_count)
+                       needToSave = true;
+
+               OperationType operationType;
+               if (datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult->numberOfChange == 0)
+                       operationType = OPERATION_NOOP;
+               else
+                       operationType = OPERATION_ADD;
+               err = __process_update(accountId, SYNC_PROGRESS_SUCCESS, operationType, datastoreContentType, true, needToSave,
+                                                                                               datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in process_update");
+                       goto error;
+               }
+
+               (*pSyncObj)->sendingStatus = g_list_append((*pSyncObj)->sendingStatus, sendingStatus);
+
+               iter = g_list_next(iter);
+
+               (*pSyncReturnObj)->changedDatastore = g_list_remove((*pSyncReturnObj)->changedDatastore, pSyncReturnChangedDatastore);
+               free_changeddatastore(pSyncReturnChangedDatastore);
+               pSyncReturnChangedDatastore = NULL;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+static SE_ErrorType __update_sync_result(int accountId)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       DACI_RETURN da_err = DACI_SUCCESS;
+       int content_type;
+
+       daci_last_anchor next_anchor_info;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (!datastoreinfo_per_content_type[content_type]->clientSyncType) continue;
+
+               next_anchor_info.access_name = "Engine";
+               next_anchor_info.account_id = accountId;
+               next_anchor_info.data_store_id = datastoreinfo_per_content_type[content_type]->datastore_id;
+               next_anchor_info.last_anchor_client = datastoreinfo_per_content_type[content_type]->nextAnchorClient;
+               next_anchor_info.last_anchor_server = datastoreinfo_per_content_type[content_type]->nextAnchorServer;
+
+               da_err = DACI_Set_Last_Anchor(&next_anchor_info);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in DACI_Set_Last_Anchor");
+
+               da_err =  set_ChangePoint_Service(accountId, datastoreinfo_per_content_type[content_type]->datastore_id);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in set_ChangePoint_Service");
+
+       }
+
+       FW_LOGV("end");
+       return err;
+}
+
+static CommandResult __convert_return_status(DACI_RETURN da_err)
+{
+       CommandResult returnResult = COMMAND_RESULT_INIT;
+       switch (da_err) {
+       case 1: /*DACI_SUCCESS*/
+               /*never comes this case
+               break;*/
+       case -813: /*DACI_ERR_ALREADY_EXIST*/
+               returnResult = COMMAND_RESULT_ALREADY_EXIST;            /*[A] Already exists exception*/
+               break;
+       case -815: /*DACI_ERR_MEMORY_FULL*/              /* oma : 420 (device full exception) */
+               returnResult = COMMAND_RESULT_DEVICE_FULL;                      /*[AR] Device full exception*/
+               break;
+       case -820: /*DACI_ERR_NOT_SUPPORTED*/            /* oma : 415 (unsupported media type or format exception) */
+               returnResult = COMMAND_RESULT_UNSUPPORTED_TYPE; /*[AR] Unsupported media type or format exception*/
+               break;
+       case -819: /*DACI_ERR_NO_DATA*/                  /* kies : not found, oma : 211 (item not deleted exception) */
+               returnResult = COMMAND_RESULT_NOT_EXIST;                        /*[D] Item not deleted exception*/
+               break;
+       case -800: /*DACI_ERRORS*/
+       case -801: /*DACI_NOT_FOUND_PLUG_IN*/
+       case -802: /*DACI_ERR_OPEN_FAILED*/
+       case -803: /*DACI_ERR_CLOSE_FAILED*/
+       case -804: /*DACI_ERR_TRANSACTION_FAILED*/
+       case -805: /*DACI_ERR_CREATE_TABLE_FAILED*/
+       case -806: /*DACI_ERR_DROP_TABLE_FAILED*/
+       case -807: /*DACI_ERR_QUERY_FAILED*/
+       case -808: /*DACI_ERR_NOT_OPENED*/
+       case -809: /*DACI_ERR_ACCOUNT_FULL*/
+       case -810: /*DACI_ERR_DELETE_LAST_ACCOUNT*/
+       case -811: /*DACI_ERR_PRIMARY_KEY_NOT_UNIQUE*/
+       case -812: /*DACI_ERR_DB_HANDLER_MGR*/
+       case -814: /*DACI_ERR_INVALID_CONTENT*/
+       case -816: /*DACI_ERR_SUB_DATA_EXIST*/                   /* oma : 427 (item not empty) */
+       case -817: /*DACI_ERR_LOCKED*/                /* kies : cannot access */
+       case -818: /*DACI_ERR_MORE_DATA*/
+       case -821:/*DACI_ERR_NOT_EXECUTE*/              /* kies : ex) sms send command, no network service */
+       default:
+               returnResult = COMMAND_RESULT_COMMAND_FAIL;     /*[ARD] Command failed exception*/
+               break;
+       }
+
+       return returnResult;
+}
+
+static char *__convert_cttype(int datastore_id)
+{
+       char *cttype = NULL;
+       /*FIXME : check type and version (contact : vCard2.1 , calendar : vCalendar 1.0 , memo : plain text) of real item data..*/
+       switch (datastore_id) {
+       case TYPE_CONTACT: /*contact (vCard2.1)*/
+               cttype = ELEMENT_TEXT_VCARD;
+               break;
+       case TYPE_CALENDAR: /*calendar (vCalendar2.0)*/
+               cttype = ELEMENT_TEXT_VCAL;
+               break;
+       case TYPE_MEMO: /*note(Memo)*/
+               cttype = ELEMENT_TEXT_PLAIN;
+               break;
+       default:
+               break;
+       }
+
+       return cttype;
+}
+
+static int __convert_synctype_value(char *syncType_str)
+{
+       int syncType_value;
+
+       if (strcmp(syncType_str, DEFINE_ALERT_SLOW_SYNC_STR) == 0)
+               syncType_value = ALERT_SLOW_SYNC ;
+       else if (strcmp(syncType_str, DEFINE_ALERT_TWO_WAY_STR) == 0)
+               syncType_value = ALERT_TWO_WAY ;
+       else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) == 0)
+               syncType_value =  ALERT_ONE_WAY_FROM_CLIENT;
+       else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) == 0)
+               syncType_value = ALERT_ONE_WAY_FROM_SERVER;
+       else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_SERVER_STR) == 0)
+               syncType_value = ALERT_REFRESH_FROM_SERVER;
+       else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) == 0)
+               syncType_value = ALERT_REFRESH_FROM_CLIENT;
+       else
+               syncType_value = ALERT_UNKNOWN;
+
+       return syncType_value;
+}
+
+bool synchronize(int accountId, char *syncMode, SanPackage *pSanPackage)
+{
+       FW_LOGV("accountID = %d", accountId);
+       FW_LOGV("syncMode = %s", syncMode);
+
+       /*FIXME*/
+       remove(OMA_DS_MSG_PATH);
+
+       /*FIXME*/
+       long t, dt;
+       t = myclock();
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       Common_ErrorType errorCode = COMMON_OK;
+       SyncProgress process = PROGRESS_NONE;
+       SyncError error = ERROR_NONE;
+
+       int sessionTime = FW_Convert_Seconds_To_UTC(time(NULL));                /*lastSessionTime for resultView;*/
+       FW_LOGV("sessionTime = %d", sessionTime);
+
+       PreSyncReturnObj *pPreSyncReturnObj = NULL;
+       SyncObj *pSyncObj = NULL;
+       SyncReturnObj *pSyncReturnObj = NULL;
+
+       bool cancel_flag = false;
+       int content_type;
+       char *session_id = NULL;
+       DCI_RETURN dci_result = DCI_SUCCESS;
+       DACI_RETURN da_err = DACI_SUCCESS;
+
+       dci_result =  DCI_PM_Lock_State(DEFINE_PLATFORM, LCD_OFF , STAY_CUR_STATE, 0);
+       if (dci_result != DCI_SUCCESS) {
+               FW_LOGE("failed in DCI_PM_Lock_State");
+       }
+
+       da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Open_Agent");
+               err = SE_INTERNAL_DA_ERROR;
+               goto fail_part;
+       }
+
+       /*prepare for sending pre sync*/
+       err = __prepare_pre_sync(accountId, syncMode, pSanPackage);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __prepare_pre_sync");
+               goto fail_part;
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               err = SE_INTERNAL_CANCEL;
+               goto cancel_part;
+       }
+
+       pPreSyncReturnObj = (PreSyncReturnObj *)calloc(1, sizeof(PreSyncReturnObj));
+       if (pPreSyncReturnObj == NULL) {
+               FW_LOGE("failed to alloc memory");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto fail_part;
+       }
+
+       /*pkg 1 */
+       if (strcmp(syncMode, DEFINE_SYNC_MODE_PUSH) == 0) {
+               session_id = g_strdup_printf("%u", pSanPackage->sessionID);             /*freed in pre_sync*/
+               errorCode = pre_sync(TRANSPORT_TYPE, accountId, session_id, (void **)&pPreSyncReturnObj);
+       } else
+               errorCode = pre_sync(TRANSPORT_TYPE, accountId, NULL, (void **)&pPreSyncReturnObj);
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               err = SE_INTERNAL_CANCEL;
+               goto cancel_part;
+       }
+
+       FW_LOGV("pre_sync errorCode =[%d]",  errorCode);
+       if (errorCode != COMMON_OK) {
+               err = SE_INTERNAL_SA_ERROR;
+               goto fail_part;
+       }
+
+       /*execute pre_sync return*/
+       err = __execute_pre_sync(accountId, pPreSyncReturnObj, sessionTime);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __process_pre_sync");
+               goto fail_part;
+       }
+
+       __session_process(accountId, PROGRESS_AUTHENTICATED, ERROR_NONE);
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               err = SE_INTERNAL_CANCEL;
+               goto cancel_part;
+       }
+
+       /* pkg 3 */
+       FW_LOGV("pre_sync end pkg3 start");
+       char *msg = NULL;
+       unsigned int msg_size;
+       char *recvMsg = NULL;
+       unsigned  int recvMsg_size;
+
+       pSyncObj = (SyncObj *)calloc(1, sizeof(SyncObj));
+       if (pSyncObj == NULL) {
+               FW_LOGE("failed to alloc memory");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto fail_part;
+       }
+
+       pSyncReturnObj = (SyncReturnObj *)calloc(1, sizeof(SyncReturnObj));
+       if (pSyncReturnObj == NULL) {
+               FW_LOGE("failed to alloc memory");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto fail_part;
+       }
+
+       err = __assemble_changeddatastores(accountId, &pSyncObj);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __assemble_changeddatastore");
+               goto fail_part;
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               err = SE_INTERNAL_CANCEL;
+               goto cancel_part;
+       }
+
+       int isFinish = 0;
+       while (!isFinish) {
+
+               errorCode = generate_msg((void **)&pSyncObj, &msg, &msg_size);
+               if (errorCode != COMMON_OK) {
+                       FW_LOGE("Failed in generate_Msg");
+                       err = SE_INTERNAL_SA_ERROR;
+                       goto fail_part;
+               }
+
+               cancel_flag = task_process_check_cancel_flag();
+               if (cancel_flag) {
+                       err = SE_INTERNAL_CANCEL;
+                       goto cancel_part;
+               }
+
+               errorCode = exchange_msg(TRANSPORT_TYPE,  msg, msg_size,  &recvMsg, &recvMsg_size);
+               if (errorCode != COMMON_OK) {
+                       FW_LOGE("Failed in exchange_Msg");
+                       err = SE_INTERNAL_SA_ERROR;
+                       goto fail_part;
+               }
+
+               cancel_flag = task_process_check_cancel_flag();
+               if (cancel_flag) {
+                       err = SE_INTERNAL_CANCEL;
+                       goto cancel_part;
+               }
+
+               errorCode = process_recv_msg(recvMsg, recvMsg_size, (void **)&pSyncReturnObj, &isFinish);
+               if (errorCode != COMMON_OK) {
+                       FW_LOGE("Failed in processRecv_Msg");
+                       err = SE_INTERNAL_SA_ERROR;
+                       goto fail_part;
+               }
+
+               cancel_flag = task_process_check_cancel_flag();
+               if (cancel_flag) {
+                       err = SE_INTERNAL_CANCEL;
+                       goto cancel_part;
+               }
+
+               err = __execute_sync(accountId, &pSyncObj, &pSyncReturnObj);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in __execute_sync");
+                       goto fail_part;
+               }
+
+               free_changeddatastores(pSyncReturnObj->changedDatastore);
+               pSyncReturnObj->changedDatastore = NULL;
+
+               free_appliedstatuses(pSyncReturnObj->status);
+               pSyncReturnObj->status = NULL;
+
+               cancel_flag = task_process_check_cancel_flag();
+               if (cancel_flag) {
+                       err = SE_INTERNAL_CANCEL;
+                       goto cancel_part;
+               }
+       }
+
+       err = __update_sync_result(accountId);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __update_anchor");
+               goto fail_part;
+       }
+
+       __write_sync_data(accountId, syncType, SYNC_SESSION_SUCCEEDED, sessionTime);
+
+       goto return_part;
+
+cancel_part:
+
+       /*clean up for SA unusual end sync process case*/
+       clean_up_SA();
+
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType)
+                       datastoreinfo_per_content_type[content_type]->clientSyncResult->sessionResult = SYNC_SESSION_STOPPED;
+       }
+
+       __write_sync_data(accountId, syncType, SYNC_SESSION_STOPPED, sessionTime);
+
+       goto return_part;
+
+fail_part:
+
+       /*clean up for SA unusual end sync process case*/
+       clean_up_SA();
+
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType)
+                       datastoreinfo_per_content_type[content_type]->clientSyncResult->sessionResult = SYNC_SESSION_FAILED;
+       }
+
+       __write_sync_data(accountId, syncType, SYNC_SESSION_FAILED, sessionTime);
+
+return_part:
+
+       if (err == SE_INTERNAL_SA_ERROR)
+               convert_common_errorcode(errorCode, &process, &error);
+       else
+               convert_engine_errorcode(err, &process, &error);
+
+        __off_synchronising_account(accountId);
+
+       __session_process(accountId, process, error);
+       FW_LOGV("process = %d", process);
+       FW_LOGV("error = %d", error);
+
+       DACI_Close_Agent();
+
+       dci_result =  DCI_PM_Unlock_State(DEFINE_PLATFORM, LCD_OFF , RESET_TIMER);
+       if (dci_result != DCI_SUCCESS) {
+               FW_LOGE("failed in DCI_PM_Unlock_State");
+       }
+
+       if (pPreSyncReturnObj != NULL) {
+               free_presyncreturnobj(pPreSyncReturnObj);
+               pPreSyncReturnObj = NULL;
+       }
+
+       if (pSyncObj != NULL) {
+               free_syncobj(pSyncObj);
+               pSyncObj = NULL;
+       }
+
+       if (pSyncReturnObj != NULL) {
+               free_syncreturnobj(pSyncReturnObj);
+               pSyncReturnObj = NULL;
+       }
+
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               free_datastore(datastoreinfo_per_content_type[content_type]);
+               datastoreinfo_per_content_type[content_type] = NULL;
+       }
+
+       /*FIXME*/
+       dt = myclock()-t;
+       FW_LOGE("\n=============TOTAL---- % d . % d sec\n", dt / 1000, dt % 1000);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+void convert_common_errorcode(Common_ErrorType errorCode, SyncProgress *process, SyncError *error)
+{
+       switch (errorCode) {
+       case COMMON_OK:                 /*ERROR_INTERNAL_OK*/
+       {
+               /* Do nothing : Error None
+               * pre_sync : PROGRESS_AUTHENTICATED
+               * sync end : PROGRESS_DONE
+                                               process = PROGRESS_AUTHENTICATED;
+                                               process = PROGRESS_DONE;
+               */
+               *process = PROGRESS_DONE;
+               *error = ERROR_NONE;
+       }
+               break;
+       case COMMON_MISCONFIGURATION:                                   /*ERROR_INTERNAL_MISCONFIGURATION : need configure infomation (account_id, id, pw, server_url...)*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_SYNCHDR;
+       }
+               break;
+       case COMMON_AUTHENTICATION_ERROR: /*ERROR_AUTH_REQUIRED, ERROR_AUTH_REJECTED*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_AUTHENTICATE;
+       }
+               break;
+       case COMMON_NOT_FOUND:                                          /*ERROR_NOT_FOUND (ERROR_INTERNAL ??)*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_SYNCHDR;
+       }
+               break;
+       case COMMON_NO_MEMORY:                                  /*ERROR_INTERNAL_NO_MEMORY*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_MEMORY_FULL;
+       }
+               break;
+       case COMMON_INTERNAL_ERROR:                             /*ERROR_INTERNAL_NOT_DEFINED || ERROR_INTERNAL_BINDER_ERROR*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+       }
+               break;
+       case COMMON_SERVER_ERROR:                                       /*ERROR_GENERIC || ERROR_SERVER_FAILURE*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_SERVER;
+       }
+               break;
+       case COMMON_CONNECTION_ERROR:                   /*ERROR_INTERNAL_CONNECTION_ERROR*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_CONNECTION;
+       }
+               break;
+       case COMMON_AUTOCONFIG_NOT_SUPPORT_BY_SERVER:                           /*ERROR_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+       }
+               break;
+       default:
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;                                                /*?? unknown error*/
+       }
+               break;
+       }
+}
+
+void convert_engine_errorcode(SE_ErrorType err, SyncProgress *process, SyncError *error)
+{
+       switch (err) {
+       case ERROR_UNKNOWN:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_CANCEL:
+       case SE_INTERNAL_OK:
+               *process = PROGRESS_DONE;
+               *error = ERROR_NONE;
+               break;
+       case SE_INTERNAL_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_NO_MEMORY:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_MEMORY_FULL;
+               break;
+       case SE_INTERNAL_NOT_DEFINED:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_DA_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_DB;
+               break;
+       case SE_INTERNAL_EVENT_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_ENGINE_CONTROLER_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_SCHEDULER_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_SA_ERROR:
+               break;
+       case SE_INTERNAL_MISCONFIGURATION:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_SYNCHDR;
+               break;
+       }
+}
+
+SE_ErrorType session_process(char *profileDirName, SyncProgress process, SyncError error)
+{
+       FW_LOGV("start ");
+       FW_LOGV("profileDirName = %s", profileDirName);
+       FW_LOGV("process = %d", process);
+       FW_LOGV("error = %d", error);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char *syncProcess = NULL;
+       char *syncError = NULL;
+       char *profile = NULL;
+       char *syncProcess_str = NULL;
+       char *syncError_str = NULL;
+
+       switch (process) {
+       case PROGRESS_NONE:
+               syncProcess = DEFINE_SYNC_PROGRESS_NONE;
+               break;
+       case PROGRESS_INIT:
+               syncProcess = DEFINE_SYNC_INIT;
+               break;
+       case PROGRESS_CONNECTING:
+               syncProcess = DEFINE_SYNC_CONNECTING;
+               break;
+       case PROGRESS_AUTHENTICATED:
+               syncProcess = DEFINE_SYNC_AUTHENTICATED;
+               break;
+       case PROGRESS_DONE:
+               syncProcess = DEFINE_SYNC_DONE;
+               break;
+       case PROGRESS_ERROR:
+               syncProcess = DEFINE_SYNC_ERROR;
+               break;
+       default:
+               break;
+       }
+
+       switch (error) {
+       case ERROR_NONE:
+               syncError = DEFINE_ERROR_NONE;
+               break;
+       case ERROR_CONNECTION:
+               syncError = DEFINE_ERROR_CONNECTION;
+               break;
+       case ERROR_SYNCHDR:
+               syncError = DEFINE_ERROR_SYNCHDR;
+               break;
+       case ERROR_INTERNAL:
+               syncError = DEFINE_ERROR_INTERNAL;
+               break;
+       case ERROR_SUSPENDED:
+               syncError = DEFINE_ERROR_SUSPENDED;
+               break;
+       case ERROR_DB:
+               syncError = DEFINE_ERROR_DB;
+               break;
+       case ERROR_ABORT:
+               syncError = DEFINE_ERROR_ABORT;
+               break;
+       case ERROR_SERVER:
+               syncError = DEFINE_ERROR_SERVER;
+               break;
+       case ERROR_MEMORY_FULL:
+               syncError = DEFINE_ERROR_MEMORY_FULL;
+               break;
+       case ERROR_AUTHENTICATE:
+               syncError = DEFINE_ERROR_AUTHENTICATE;
+               break;
+       case ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER:
+               syncError = DEFINE_ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+               break;
+       default:
+               break;
+       }
+
+       if (syncProcess == NULL || syncError == NULL) {
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (profileDirName != NULL )
+               profile = strdup(profileDirName);
+
+       if (syncProcess != NULL )
+               syncProcess_str = strdup(syncProcess);
+
+       if (syncError != NULL )
+               syncError_str = strdup(syncError);
+
+       err = send_noti_session_process(profile, syncProcess_str, syncError_str);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in send_noti_session_process");
+               goto error;
+       }
+
+
+       FW_LOGV("end");
+
+error:
+       if (profile)
+               free(profile);
+       if (syncProcess_str)
+               free(syncProcess_str);
+       if (syncError_str)
+               free(syncError_str);
+
+       return err;
+}
+
+SE_ErrorType reset_synchronizing_profiles()
+{
+       FW_LOGV("start");
+       int *account_list = 0;
+       int account_list_count = 0;
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Open_Agent");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+       FW_LOGV("account_list_count = %d", account_list_count);
+
+       int i;
+       for (i = 0; i < account_list_count; i++) {
+               FW_LOGV("account = %d", account_list[i]);
+               __off_synchronising_account(account_list[i]);
+
+               FW_LOGV("construct_itemTbl From service start");
+
+               /*construct_itemTbl From service*/
+               da_err = construct_ItemTbl_From_Service(account_list[i], TYPE_CONTACT);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in construct_ItemTbl_From_Service(TYPE_CONTACT)");
+
+               da_err = construct_ItemTbl_From_Service(account_list[i], TYPE_CALENDAR);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in construct_ItemTbl_From_Service(TYPE_CALENDAR)");
+
+               da_err = construct_ItemTbl_From_Service(account_list[i], TYPE_MEMO);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in construct_ItemTbl_From_Service(TYPE_MEMO)");
+
+               FW_LOGV("construct_itemTbl From service end");
+       }
+
+       DACI_Close_Agent();
+       FW_LOGV("end");
+
+error:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       return err;
+}
+
+bool refresh_from_service_all(int accountId)
+{
+       FW_LOGV("start");
+       SE_ErrorType  err = SE_INTERNAL_OK;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("refresh_Item_Tbl_From_Service(%d, %d);", accountId, TYPE_CONTACT);
+       refresh_Item_Tbl_From_Service(accountId, TYPE_CONTACT);
+
+       FW_LOGV("refresh_Item_Tbl_From_Service(%d, %d);", accountId, FW_CALENDAR);
+       refresh_Item_Tbl_From_Service(accountId, TYPE_CALENDAR);
+
+       FW_LOGV("refresh_Item_Tbl_From_Service(%d, %d);", accountId, FW_MEMO);
+       refresh_Item_Tbl_From_Service(accountId, TYPE_MEMO);
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+/*FIXME cancel request to NA */
+/*SE_ErrorType cancel_sync_request()
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       cancel_connection_sync_request(TRANSPORT_TYPE);
+
+       FW_LOGV("end");
+
+       return err;
+}*/
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..8dd5c15
--- /dev/null
@@ -0,0 +1,24 @@
+oma-ds-service (0.1.11) unstable; urgency=low
+
+  * bug fixed & pkg upload
+  * Git: hidden/pkgs/o/oma-ds-service
+  * Tag: oma-ds-service_0.1.11
+
+ -- Junhyuk Lee <junhyuk7.lee@samsung.com>  Thu, 22 Mar 2012 20:51:11 +0900
+
+oma-ds-service (0.1.10) unstable; urgency=low
+
+  * bug fixed & pkg upload
+  * Git: shared/pkgs/o/oma-ds-service
+  * Tag: oma-ds-service_0.1.10
+
+ -- Junhyuk Lee <junhyuk7.lee@samsung.com>  Wed, 21 Mar 2012 16:35:21 +0900
+
+ma-ds-service (0.1.9) unstable; urgency=low
+
+  * pkg upload init 
+  * Git: shared/pkgs/o/oma-ds-service
+  * Tag: oma-ds-service_0.1.9
+
+ -- Junhyuk Lee <junhyuk7.lee@samsung.com>  Thu, 15 Mar 2012 17:06:33 +0900
+
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..3417b1d
--- /dev/null
@@ -0,0 +1,22 @@
+Source: oma-ds-service
+Section: embedded
+Priority: optional
+Maintainer: Joohark Park <juhaki.park@samsung.com>, Junhyuk Lee <junhyuk7.lee@samsung.com>
+Uploaders: Joohark Park <juhaki.park@samsung.com>, Junhyuk Lee <junhyuk7.lee@samsung.com>
+Build-Depends: debhelper (>= 5), libglib2.0-dev, sqlite3, libsoup2.4-dev, libsqlite3-dev, check, libvconf-dev, libexpat1-dev, libsync-agent-framework-dev, libwbxml2-dev
+Standards-Version: 0.1.1
+
+Package: oma-ds-service
+Section: embedded
+Architecture: any
+Priority: optional
+Depends: ${shlibs:Depends}, ${misc:Depends}, 
+Description: OMA Data Synchronization service module
+
+Package: oma-ds-service-dbg
+Section: debug
+Architecture: any
+Priority: optional
+Depends: ${shlibs:Depends}, ${misc:Depends}, oma-ds-service (= ${Source-Version})
+Description: OMA Data Synchronization service module (unstripped)
+
diff --git a/debian/control.slp b/debian/control.slp
new file mode 100644 (file)
index 0000000..20474e7
--- /dev/null
@@ -0,0 +1,8 @@
+#Mon Nov 08 05:13:18 KST 2010
+Privileges=
+AppInstallPath=/usr
+UserUninstall=yes
+IdealScreen=480x800,46x71
+Version=1.0.0
+
+
diff --git a/debian/postinst b/debian/postinst
new file mode 100644 (file)
index 0000000..1cbf17f
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+echo ""
+echo ""
+echo "*********************************************************************************"
+echo "                 post install script run..."
+echo "*********************************************************************************"
+echo "executing oma agent unit test binary."
+
+OMA_TEST_BIN="/usr/bin/oma-test"
+if [ ! -e "$OMA_TEST_BIN" ]
+then 
+       echo "  oma-agent test binary missing. (check debian package is in release mode)"
+else
+
+       echo ""
+       echo ""
+       echo "*********************************************************************************"
+       echo "                  oma agent unit test run..."
+       echo "*********************************************************************************"
+       echo ""
+       $OMA_TEST_BIN
+fi
+echo "deleting vconf value"
+if [ -d /opt/var/kdb/db/syncml-service/DS/Accounts ]
+then
+        rm -rf /opt/var/kdb/db/syncml-service/DS/Accounts
+fi
+
+if [ -d /opt/var/kdb/db/Apps/AgentFramework ]
+then
+        rm -rf /opt/var/kdb/db/Apps/AgentFramework
+fi
+
+echo "deleting db files"
+if [ -f /opt/dbspace/.omasyncagent.db ]
+then
+        rm -rf /opt/dbspace/.omasyncagent.db
+fi
+
+if [ -f /opt/dbspace/.omasyncagent.db-journal ]
+then
+        rm -rf /opt/dbspace/.omasyncagent.db-journal
+fi
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..ad0ae22
--- /dev/null
@@ -0,0 +1,104 @@
+#!/usr/bin/make -f
+
+## DO NOT MODIFY THIS AREA : BEGIN
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+# $(PKGDIR) is a package build directory to create a final .deb package .
+include debian/control.slp
+
+PKGDIR = debian/PKG
+ifneq (,$(filter ide,$(DEB_BUILD_OPTIONS)))
+DESTDIR = .
+else
+DESTDIR = ..
+endif
+CONTROLFILE = debian/control.slp
+CONTROLFILE_SRC = debian/control
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+else
+       CFLAGS += -O2
+endif
+
+build: pre-build configure
+       # Add here commands to compile the package.
+       $(MAKE)
+
+configure: 
+       cmake . -DCMAKE_INSTALL_PREFIX=${AppInstallPath} -DCMAKE_PROJECT=${Source}
+       rm -rf CMakeFiles/CompilerIdC*
+#      sed 's/^Package:.*$$/Package: $(Package)/' $(CONTROLFILE_SRC) > $(CONTROLFILE_SRC).tmp ; mv -f $(CONTROLFILE_SRC).tmp $(CONTROLFILE_SRC)
+
+clean: 
+       # Add here commands to clean up before the build process.
+       # debian clean
+       -$(MAKE) clean
+
+       -find . -name "CMakeFiles" -exec rm -rf {} \;
+       -find . -name "CMakeCache.txt" -exec rm -rf {} \;
+       -find . -name "Makefile" -exec rm -rf {} \;
+       -find . -name "cmake_install.cmake" -exec rm -rf {} \;
+       -find . -name "install_manifest.txt" -exec rm -rf {} \;
+       -find . -name "*.pc" -exec rm -rf {} \;
+       -find . -name "*.so" -exec rm -rf {} \;
+
+       -rm -rf ./oma-ds-service
+       -rm -rf ./oma-test
+       
+       -rm -rf $(PKGDIR)
+
+       dh_clean
+
+install: build pre-install
+       rm -rf $(PKGDIR)
+       mkdir $(PKGDIR)
+
+       # Add here commands to install the package into $(PKGDIR).
+       $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+       mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/init.d
+       install -c $(CURDIR)/syncmld_mgr $(CURDIR)/debian/tmp/etc/rc.d/init.d
+
+       mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc3.d
+       ln -s ../init.d/syncmld_mgr $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/S90Syncmld
+
+       mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d
+       ln -s ../init.d/syncmld_mgr $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S90Syncmld
+
+# Build architecture-dependent files here.
+binary: install pre-binary
+       dh_testdir
+       dh_testroot
+       dh_installchangelogs
+       dh_installdocs
+       dh_installexamples
+       dh_install --sourcedir=debian/tmp
+       dh_link
+       dh_strip --dbg-package=oma-ds-service
+       dh_compress
+       dh_fixperms
+       dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+.PHONY: build clean install binary 
+## DO NOT MODIFY THIS AREA : END
+
+## DO NOT MODIFY OR DELETE TARGET.
+pre-build:
+       # Add here commands to execute before the build process.
+
+pre-install:
+       # Add here commands to execute before installing the binaries into $(PKGDIR).
+
+pre-binary:
+       # Add here commands to execute before creating a package.
+
diff --git a/eventconfig_omads b/eventconfig_omads
new file mode 100644 (file)
index 0000000..1672a9a
--- /dev/null
@@ -0,0 +1,14 @@
+1, 1, 0, 30, addprofile
+2, 0, 0, 30, requestsync
+3, 1, 0, 30, editprofile
+4, 1, 0, 30, deleteprofile
+5, 0, 0, 30, autoconfigure
+6, 0, 0, 30, cancelsync
+7, 0, 0, 30, querysyncstatus
+8, 1, 0, 30, getprofilename
+9, 1, 0, 30, getprofileserverinfo
+10, 1, 0, 30, getprofilesyncmode
+11, 1, 0, 30, getprofilesynccategory
+12, 1, 0, 30, getprofilelastsession
+13, 1, 0, 30, getprofilestatistics
+14, 1, 0, 30, addprofilecp
\ No newline at end of file
diff --git a/include/Common/Common_Define.h b/include/Common/Common_Define.h
new file mode 100644 (file)
index 0000000..a77b4a5
--- /dev/null
@@ -0,0 +1,1189 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Define.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface for common structure
+ */
+
+#ifndef COMMON_DEFINE_H_
+#define COMMON_DEFINE_H_
+
+#include "Common_Define_Internal.h"
+
+/**
+ * @par Description: API to create DatastoreInfo structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, target uri
+ * @param[in]          string type, source uri
+ * @param[out]         Status structure
+ *
+ * @return                             DatastoreInfo on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+DatastoreInfo *create_datastoreinfo(char *target, char *source);
+
+
+/**
+ * @par Description: API to free list of DatastoreInfo structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          list of DatastoreInfo structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_datastoreinfos(GList *pDatastoreInfos);
+
+
+/**
+ * @par Description: API to free DatastoreInfo structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DatastoreInfo structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_datastoreinfo(DatastoreInfo *pDatastoreInfo);
+
+/**
+ * @par Description: API to set sync type in DatastoreInfo structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DatastoreInfo structure
+ * @param[in]          enum type, sync type
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastoreInfo_synctype(DatastoreInfo *datastoreInfo, AlertType syncType);
+
+/**
+ * @par Description: API to set last anchor in DatastoreInfo structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DatastoreInfo structure
+ * @param[in]          string type, last anchor
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastoreinfo_lastanchor(DatastoreInfo *datastoreInfo, char *lastAnchor);
+
+/**
+ * @par Description: API to set next anchor in DatastoreInfo structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DatastoreInfo structure
+ * @param[in]          string type, next anchor
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastoreinfo_nextanchor(DatastoreInfo *datastoreInfo, char *nextAnchor);
+
+/**
+ * @par Description: API to set maxobjsize in DatastoreInfo structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DatastoreInfo structure
+ * @param[in]          unsigned int, maxobjsize
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastoreinfo_maxobjsize(DatastoreInfo *datastoreInfo, unsigned int maxObjSize);
+
+/**
+ * @par Description: API to create ChangedItem structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, change type of item
+ * @param[in]          string type, luid of item
+ * @param[out]
+ *
+ * @return                             ChangedItem on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+ChangedItem *create_changeditem(ChangeType type, char *luid);
+
+/**
+ * @par Description: API to free ChangedItem structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          ChangedItem structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_changeditem(ChangedItem *pChangedItem);
+
+
+/**
+ * @par Description: API to set content type in ChangedItem structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          ChangedItem structure
+ * @param[in]          string type, content type
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_changeditem_contenttype(ChangedItem *pChangedItem, char *content_type);
+
+/**
+ * @par Description: API to set data in ChangedItem structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          ChangedItem structure
+ * @param[in]          string type, data
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_changeditem_data(ChangedItem *changedItem, char *data);
+
+/**
+ * @par Description: API to set in ChangedItem structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          ChangedItem structure
+ * @param[in]          datastore index(0=contacts, 1=calendar, 2= memo)
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_changedItem_indexofdatastore(ChangedItem *changedItem, unsigned int indexOfDatastore);
+
+/**
+ * @par Description: API to create ChangedDatastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, source uri
+ * @param[in]          string type, target uri
+ * @param[in]          int type, has numberOfChanges or not
+ * @param[in]          unsigned int type, if numberOfChanges is true set count else set zero
+ * @param[out]
+ *
+ * @return                             ChangedDatastore on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+ChangedDatastore *create_changeddatastore(char *source, char *target, int hasNumberOfChanges, unsigned int numberOfChanges);
+
+/**
+ * @par Description: API to free list of ChangedDatastore
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          list of ChangedDatastore
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_changeddatastores(GList *pChangedDatastores);
+
+/**
+ * @par Description: API to free ChangedDatastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          ChangedDatastore structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_changeddatastore(ChangedDatastore *pChangedDatastore);
+
+/**
+ * @par Description: API to set changedItem in ChangedDatastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          ChangedDatastore structure
+ * @param[in]          list of ChangedItem structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_changeddatastore_changeditem(ChangedDatastore *changedDatastore, GList *changedItem);
+
+/**
+ * @par Description: API to add changedItem in ChangedDatastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          ChangedDatastore structure
+ * @param[in]          ChangedItem structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void add_changeddatastore_changeditem(ChangedDatastore *changedDatastore, ChangedItem *changedItem);
+
+/**
+ * @par Description: API to create AppliedStatus structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, luid of item
+ * @param[in]          enum type, change type( CHANGE_ADD , CHANGE_REPLACE , CHANGE_DELETE)
+ * @param[in]          int type, status code(200....)
+ * @param[out]
+ *
+ * @return                             AppliedStatus on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+AppliedStatus *create_appliedstatus(char *luid, ChangeType changeType, int status);
+
+/**
+ * @par Description: API to free list of AppliedStatus structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          list of AppliedStatus structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_appliedstatuses(GList *pAppliedStatuses);
+
+/**
+ * @par Description: API to free AppliedStatus structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          AppliedStatus structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_appliedstatus(AppliedStatus *pAppliedStatus);
+
+/**
+ * @par Description: API to create SendingStatus structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          source uri
+ * @param[in]          target uri
+ * @param[out]
+ *
+ * @return                             SendingStatus on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SendingStatus *create_sendingstatus(char *source, char *target);
+
+/**
+ * @par Description: API to free list of SendingStatus structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          list of SendingStatus structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_sendingstatuses(GList *pSendingStatuses);
+
+/**
+ * @par Description: API to free SendingStatus structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SendingStatus structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_sendingstatus(SendingStatus *pSendingStatus);
+
+/**
+ * @par Description: API to add AppliedStatus in SendingStatus structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SendingStatus structure
+ * @param[in]          AppliedStatus structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void add_sendingstatus_appliedstatus(SendingStatus *sendingStatus, AppliedStatus *appliedStatus);
+
+/**
+ * @par Description: API to create Datastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, target uri
+ * @param[in]          string type, source uri
+ * @param[out]
+ *
+ * @return                             Datastore on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+Datastore *create_datastore(char *target, char *source);
+
+/**
+ * @par Description: API to set content type infomation in Datastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Datastore structure
+ * @param[in]          int type, datastore_id(TYPE_CONTACT, TYPE_CALENDAR, TYPE_MEMO)
+ * @param[in]          int type, folder_type_id(9, 8, 10)
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastore_contenttype_info(Datastore *datastore, int datastore_id, int folder_type_id);
+
+/**
+ * @par Description: API to set account information in Datastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Datastore structure
+ * @param[in]          string type, account_id
+ * @param[in]          string type, account_pw
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastore_account_info(Datastore *datastore, char *account_id, char *account_pw);
+
+/**
+ * @par Description: API to set client sync type in Datastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Datastore structure
+ * @param[in]          enum type, sync type
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastore_client_sync_type(Datastore *datastore, AlertType syncType);
+
+/**
+ * @par Description: API to set server sync type in Datastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Datastore structure
+ * @param[in]          enum type, sync type
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastore_server_sync_type(Datastore *datastore, AlertType syncType);
+
+
+/**
+ * @par Description: API to set client anchor in Datastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Datastore structure
+ * @param[in]          string type, last anchor
+ * @param[in]          string type, next anchor
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastore_client_anchor(Datastore *datastore, char *lastAnchor, char *nextAnchor);
+
+/**
+ * @par Description: API to set client anchor in Datastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Datastore structure
+ * @param[in]          string type, last anchor
+ * @param[in]          string type, next anchor
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_datastore_server_anchor(Datastore *datastore, char *lastAnchor, char *nextAnchor);
+
+/**
+ * @par Description: API to create SyncResult structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Datastore structure
+ * @param[in]          string type, last anchor
+ * @param[in]          string type, next anchor
+ * @param[out]
+ *
+ * @return                             SyncResult on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SyncResult *create_sync_result();
+
+/**
+ * @par Description: API to duplicate SyncResult structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncResult structure
+ * @param[out]
+ *
+ * @return                             SyncResult on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SyncResult *dup_syncresult(SyncResult *orgSyncResult);
+
+/**
+ * @par Description: API to set number of total item in SyncResult structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncResult structure
+ * @param[in]          number of total item
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_numberofchange(SyncResult *syncResult, unsigned int numberOfChange);
+
+/**
+ * @par Description: API to set number of received item in SyncResult structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncResult structure
+ * @param[in]          number of received item
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void add_receive_count(SyncResult *syncResult, unsigned int received_count);
+
+/**
+ * @par Description: API to set number of add item in SyncResult structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncResult structure
+ * @param[in]          number of add item
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void add_add_count(SyncResult *syncResult, unsigned int add_cnt);
+
+/**
+ * @par Description: API to set number of replace item in SyncResult structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncResult structure
+ * @param[in]          number of replace item
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void add_replace_count(SyncResult *syncResult, unsigned int replace_cnt);
+
+/**
+ * @par Description: API to set number of delete item in SyncResult structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncResult structure
+ * @param[in]          number of delete item
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void add_delete_count(SyncResult *syncResult, unsigned int delete_cnt);
+
+/**
+ * @par Description: API to free PreSyncReturnObj structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          PreSyncReturnObj structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_presyncreturnobj(PreSyncReturnObj *pPreSyncReturnObj);
+
+/**
+ * @par Description: API to free SyncObj structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncObj structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_syncobj(SyncObj *pSyncObj);
+
+/**
+ * @par Description: API to free SyncReturnObj structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncReturnObj structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_syncreturnobj(SyncReturnObj *pSyncReturnObj);
+
+/**
+ * @par Description: API to free Datastore structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Datastore structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_datastore(Datastore *pDatastore);
+
+
+#endif /* COMMON_DEFINE_H_ */
diff --git a/include/Common/Common_Define_Internal.h b/include/Common/Common_Define_Internal.h
new file mode 100644 (file)
index 0000000..1b832de
--- /dev/null
@@ -0,0 +1,324 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Define_Internal.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of defined common structure for using between SE and SA
+ */
+
+#ifndef COMMON_DEFINE_INTERNAL_H_
+#define COMMON_DEFINE_INTERNAL_H_
+
+
+#include <malloc.h>
+#include <stdio.h>
+#include <glib.h>
+#include <string.h>
+
+/*#define COMMUNICATION_TYPE ENCODING_XML*/
+#define COMMUNICATION_TYPE ENCODING_WBXML_12
+
+#define TRANSPORT_TYPE 1       /*http*/
+/*#define TRANSPORT_TYPE "FW_MOBEX"*/  /*mobex -> does not support in OMA*/
+
+#define NETWORK_TIMEOUT 30
+
+#define PKG_NAME "oma-ds-service"
+#define DEFINE_PLATFORM 1
+
+#define OMA_DS_MSG_PATH "/tmp/Msg"
+#define OMA_DS_CSC_CHECK_PATH "/opt/data/oma-ds/csc_check"
+
+#define ELEMENT_TEXT_VCARD "text/x-vcard"
+#define ELEMENT_TEXT_VCARD_30 "text/vcard"
+#define ELEMENT_TEXT_VCAL "text/x-vcalendar"
+#define ELEMENT_TEXT_ICAL "text/calendar"
+#define ELEMENT_TEXT_PLAIN "text/plain"
+#define ELEMENT_TEXT_MESSAGE "text/x-vMessage"
+
+#define DEFINE_ALERT_SLOW_SYNC_STR "Full"
+#define DEFINE_ALERT_TWO_WAY_STR "Update both"
+#define DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR "Update to server"
+#define DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR "Update to phone"
+#define DEFINE_ALERT_REFRESH_FROM_SERVER_STR "Refresh from server"
+#define DEFINE_ALERT_REFRESH_FROM_CLIENT_STR "Refresh from phone"
+
+#define DEFINE_ALERT_SLOW_SYNC_VALUE "201"
+#define DEFINE_ALERT_TWO_WAY_VALUE "200"
+#define DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE "202"
+#define DEFINE_ALERT_ONE_WAY_FROM_SERVER_VALUE "204"
+#define DEFINE_ALERT_REFRESH_FROM_SERVER_VALUE "205"
+#define DEFINE_ALERT_REFRESH_FROM_CLIENT_VALUE "203"
+
+
+#define DEFINE_CONFIG_KEY_PROFILE_SERVER_ID                                                    "Server_id"
+#define DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE                                            "Sync_mode"
+#define DEFINE_CONFIG_KEY_PROFILE_SERVER_IP                                                    "Server_ip"
+#define DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE                                           "Next_nonce"
+#define DEFINE_CONFIG_KEY_PROFILE_DIR_NAME                                                     "Dir_name"
+#define DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING                                        "Synchronising"
+#define DEFINE_CONFIG_KEY_PROFILE_NAME                                                                 "Name"
+#define DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE                                                    "Sync_type"
+#define DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL                                        "Sync_interval"
+#define DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS                    "Contacts"
+#define DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR                    "Organizer"
+#define DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO                                "Memo"
+#define DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG                     "CallLog"
+#define DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE                              "source"
+#define DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET                              "target"
+#define DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID                                          "id"
+#define DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD                    "password"
+#define DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS          "Last_session_status"
+#define DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME                    "Last_session_time"
+#define DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED                  "dbSynced"
+#define DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME                 "last_session_time"
+#define DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL                             "numberOfChanges"
+#define DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD                   "add_count"
+#define DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE                "delete_count"
+#define DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE       "replace_count"
+#define DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER                            "server"
+#define DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT                            "client"
+#define DEFINE_CONFIG_KEY_PROFILE_ALARM_ID                                                     "Alarm_id"
+
+#define DEFINE_SYNC_MODE_MANUAL "Manual"
+#define DEFINE_SYNC_MODE_PUSH "Push"
+#define DEFINE_SYNC_MODE_PERIODIC "Periodic"
+
+#define DEFINE_SOURCE_CONTACT_URI "Contacts"
+#define DEFINE_SOURCE_CALENDAR_URI "Organizer"
+#define DEFINE_SOURCE_MEMO_URI "Memo"
+#define DEFINE_SOURCE_CALLLOG_URI "CallLog"
+
+#define DEFINE_CALLLOG_SERVER_URL_HTTPS "https://www.xxxxx.com/sync"
+#define DEFINE_CALLLOG_SERVER_URL_HTTP "http://www.xxxxx.com/sync"
+#define DEFINE_CALLLOG_DEFAULT_NEXT_NONCE "pcwds"
+
+typedef enum {
+       SYNC_SESSION_NOT_SYNCED_YET = -1,
+       SYNC_SESSION_FAILED = 0,
+       SYNC_SESSION_SUCCEEDED = 1,
+       SYNC_SESSION_STOPPED = 2,
+       SYNC_SESSION_SYNCHRONIZING = 3
+} SyncSessionResult;
+
+typedef enum  {
+       ALERT_UNKNOWN = 0,
+       ALERT_DISPLAY = 100,
+       ALERT_TWO_WAY = 200,
+       ALERT_SLOW_SYNC = 201,
+       ALERT_ONE_WAY_FROM_CLIENT = 202,
+       ALERT_REFRESH_FROM_CLIENT = 203,
+       ALERT_ONE_WAY_FROM_SERVER = 204,
+       ALERT_REFRESH_FROM_SERVER = 205,
+       ALERT_TWO_WAY_BY_SERVER = 206,
+       ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER = 207,
+       ALERT_REFRESH_FROM_CLIENT_BY_SERVER = 208,
+       ALERT_ONE_WAY_FROM_SERVER_BY_SERVER = 209,
+       ALERT_REFRESH_FROM_SERVER_BY_SERVER = 210,
+       ALERT_RESULT = 221,
+       ALERT_NEXT_MESSAGE = 222,
+       ALERT_NO_END_OF_DATA = 223
+} AlertType;
+
+typedef enum {
+       CHANGE_UNKNOWN = 0,
+       CHANGE_ADD = 1,
+       CHANGE_REPLACE = 2,
+       CHANGE_DELETE = 3
+} ChangeType;
+
+typedef enum {
+       TYPE_CONTACT = 0,
+       TYPE_CALENDAR,
+       TYPE_MEMO,
+       TYPE_CALLLOG,
+
+       TYPE_CONTENT_COUNT
+} CONTENT_TYPE;
+
+typedef enum {
+       COMMON_INIT = 0,
+       COMMON_OK = 100,
+       COMMON_MISCONFIGURATION = 200,
+       COMMON_AUTHENTICATION_ERROR = 201,
+       COMMON_NOT_FOUND = 202,
+       COMMON_NO_MEMORY = 203,
+       COMMON_INTERNAL_ERROR = 204,
+       COMMON_SERVER_ERROR = 205,
+       COMMON_CONNECTION_ERROR = 206,
+       COMMON_AUTOCONFIG_NOT_SUPPORT_BY_SERVER = 207,
+       COMMON_BUSY_SIGNALING = 208,
+       COMMON_CANCEL = 300,
+} Common_ErrorType;
+
+
+typedef struct {
+       SyncSessionResult sessionResult;
+       unsigned int numberOfChange;
+       unsigned int received_count;
+       unsigned int add_count;
+       unsigned int replace_count;
+       unsigned int delete_count;
+} SyncResult;
+
+
+/**
+ * @brief Data Store information
+ * relevant information about Data Store\n
+ *
+ */
+typedef struct {
+       int datastore_id;                                                                               /**< plugin_type : TYPE_CONTACT, TYPE_CALENDAR, TYPE_MEMO, TYPE_CALL_LOG */
+       int folder_type_id;                                                                     /**< folder type id 0 */
+       char *target;                                                                                   /**< target(server) URI */
+       char *source;                                                                           /**< source(client) URI */
+       char *id;                                                                                               /**< account id */
+       char *pw;                                                                                               /**< account pw */
+       AlertType clientSyncType;                                               /**< Sync Type(two-way, one-way ...) */
+       AlertType serverSyncType;                                               /**< Sync Type(two-way, one-way ...) */
+       char *lastAnchorClient;                                                 /**< Last Anchor of datastore for clientside */
+       char *nextAnchorClient;                                                 /**< Next Anchor of datastore for clientside */
+       char *lastAnchorServer;                                                 /**< Next Anchor of datastore for serverside */
+       char *nextAnchorServer;                                                 /**< Next Anchor of datastore for serverside */
+       SyncResult *clientSyncResult;
+       SyncResult *serverSyncResult;
+} Datastore;
+
+
+typedef struct {
+       char *target;                                                                                   /**< target(server) URI */
+       char *source;                                                                           /**< source(client) URI */
+       AlertType syncType;                                             /**< Sync Type(two-way, one-way ...) */
+       char *lastAnchor;                                                       /**< Last Anchor of datastore for clientside */
+       char *nextAnchor;                                                       /**< Next Anchor of datastore for clientside */
+       unsigned int maxObjSize;
+} DatastoreInfo;
+
+/**
+   @brief Third parameter of pre_sync function
+
+   Output data from pre_sync function\n
+   Data that need to be passed to Service Engine from Service Adapter result of pkg2
+
+ */
+typedef struct {
+       GList *datastoreInfo;                   /**< containing DatastoreInfo structure*/
+       char *devID;
+} PreSyncReturnObj;
+
+
+/**
+   @brief a changed item(changelog)
+
+ */
+typedef struct {
+       ChangeType changeType;                                  /**<  type of changes (add, replace, delete, copy, move ..) */
+       char *luid;                                                                                     /**< luid of item */
+       char *content_type;                                                     /**< content type of data */
+       unsigned int indexOfDatastore;
+       char *data;                                                                             /**< data  */
+} ChangedItem;
+
+
+/**
+   @brief item that are grouped by each Data Store
+
+ */
+typedef struct {
+       char *source;                                                                   /**< source(client) URI */
+       char *target;                                                                           /**< target(server) URI */
+       int needSyncCommand;
+       unsigned int numberOfChanges;
+       int hasNumberOfChanges;
+
+       GList *changeItem;                      /**<  containing ChangedItem  all type */
+       GList *sentItem;                                /**<  containing ChangedItem  */
+} ChangedDatastore;
+
+
+
+/**
+   @brief result of applied command that from service engine or server
+
+ */
+typedef struct {
+       ChangeType changeType;                  /**< change type (add, replace, delete...) */
+       char *luid;                                                                     /**< luid of item */
+       int status;                                                                     /**< status of applied item */
+} AppliedStatus;
+
+typedef struct {
+       char *source;                                           /**< source(client) URI */
+       char *target;                                                   /**< target(server) URI */
+       GList *items;                                                   /**< containing ApplliedStatus struct */
+} SendingStatus;
+
+/**
+   @brief second and third parameter of sync function
+
+ */
+typedef struct {
+       GList *changedDatastore;                                        /**< containing ChangedDatastore structure when it's in SyncObj it will be command that client send to server */
+       GList *sendingStatus;                                           /**<  containing SendingStatus structure when it's in SyncObj status of add, replace, delete command from server */
+} SyncObj;
+
+typedef struct {
+       GList *changedDatastore;                                        /**< containing ChangedDatastore structure when it's in SyncReturnObj command(add, relpace, delete) from server */
+       GList *status;                                                                  /**<  containing AppliedStatus structure when it's in SyncReturnObj return to engine(status of add, replace, delete command that client sent to server)*/
+} SyncReturnObj;
+
+typedef struct {
+       int enabled;
+       char *srcURI;
+       char *tgtURI;
+       char *id;
+       char *password;
+} sync_category;
+
+typedef struct {
+       char *name;
+       char *accept;
+       char *id;
+       char *password;
+       char *authType;
+       char *authData;
+} resource_cp;
+
+extern Datastore *datastoreinfo_per_content_type[4];
+extern AlertType syncType;
+
+#endif /* COMMON_DEFINE_INTERNAL_H_ */
diff --git a/include/Common/Common_Util.h b/include/Common/Common_Util.h
new file mode 100644 (file)
index 0000000..55db001
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Util.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface for utility function
+ */
+
+#ifndef COMMON_UTIL_H_
+#define COMMON_UTIL_H_
+
+#include <stdbool.h>
+
+/**
+ * @par Description: API to set value into config_tbl(key, value)
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          string type, key
+ * @param[in]          string type, value(char *)
+ * @param[in]          string type, type of value(string, int)
+ * @param[in]          string type, name of access(SE, SA...)
+ * @param[out]
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool set_config_str(int accountID, char *key, char *value, char * type, char *accessName);
+
+/**
+ * @par Description: API to set value into config_tbl(key, value)
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          string type, key
+ * @param[in]          int type, value(int)
+ * @param[in]          string type, type of value(string, int)
+ * @param[in]          string type, name of access(SE, SA...)
+ * @param[out]
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool set_config_int(int accountID, char *key, int value, char * type, char *accessName);
+
+/**
+ * @par Description: API to get value from config_tbl(key, value)
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          string type, key
+ * @param[out]         string type, value
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_config(int accountId, char *key, char **value);
+
+/**
+ * @par Description: API to get account ID from profileDirName(Sync1...)
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(Sync1, Sync2...)
+ * @param[in]          boolean type, already open agent db or not
+ * @param[out]
+ *
+ * @return                             account ID      (more than 1)    on success
+ *                                                     -1 on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int get_accountid(char *profile, bool open);
+
+
+/**
+ *  @brief                             convert sync type(UI-> Engine)
+ *  @param[in]         sync type(Full, Update both, Update to server, Update to phone, Refresh from server, Refresh from phone)
+ *  @return                    char *
+ *  @retval                            value of sync type                              Success
+ *                                                     NULL                                                            Error
+ */
+/*int convert_synctype_value(char *syncType_str);*/
+/*char *convert_synctype_str(char *syncType_value);*/
+#endif /* COMMON_UTIL_H_ */
diff --git a/include/Common/Common_Vconf.h b/include/Common/Common_Vconf.h
new file mode 100644 (file)
index 0000000..5eb4ee7
--- /dev/null
@@ -0,0 +1,381 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Vconf.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of defined vconf value
+ */
+
+#ifndef COMMON_VCONF_H_
+#define COMMON_VCONF_H_
+
+#include <stdbool.h>
+
+/*TODO have to be removed after removing vconf*/
+/*! Here are some global macros representing Settings Paths for AS/DS/DM*/
+#define AS_SETTINGS_PATH "db/Apps/ActiveSync-service"
+#define DS_SETTINGS_DEFAULT_PATH "db/syncml-service/DS"
+#define DS_SETTINGS_PATH DS_SETTINGS_DEFAULT_PATH"/Accounts"
+#define DM_SETTINGS_PATH "db/syncml-service/DM"
+
+/* Vconf key names for SyncML DS profile setting.*/
+#define DS_SETTING_CONTACT_CHANGETIME   "/Contact/ChangeTime"           /*int*/
+#define DS_SETTING_CALENDAR_CHANGETIME  "/Calendar/ChangeTime"          /*int*/
+#define DS_SETTING_MEMO_CHANGETIME      "/Note/ChangeTime"              /*int*/
+#ifdef FILE_SYNC
+#define DS_SETTING_FILE_CHANGETIME      "/File/ChangeTime"              /*int*/
+#endif
+/* Keys for each profile */
+#define DS_SETTING_NAME                 "/Name"                         /*string*/
+#define DS_SETTING_ADDRTYPE             "/AppAddr/AddrType"             /*int*/
+#define DS_SETTING_ADDR                 "/AppAddr/Addr"                 /*string*/
+#define DS_SETTING_PORTNBR              "/AppAddr/PortNbr"              /*int*/
+#define DS_SETTING_CLIENT_AUTHNONCE     "/AuthInfo/Client/AuthNonce"    /*string*/
+#define DS_SETTING_CLIENT_AUTHTYPE      "/AuthInfo/Client/AuthType"     /*int*/
+#define DS_SETTING_CLIENT_AUTHPWD       "/AuthInfo/Client/AuthPWD"      /*string*/
+#define DS_SETTING_CLIENT_AUTHNAME      "/AuthInfo/Client/AuthName"     /*string*/
+#define DS_SETTING_LASTSESSIONTIME      "/GUI/LastSessionTime"          /*int*/
+#define DS_SETTING_LASTSESSIONSTATUS    "/GUI/LastSessionStatus"        /*int*/
+#define DS_SETTING_SYNCMODE             "/GUI/SyncMode"                 /*string*/
+#define DS_SETTING_INTERVAL             "/GUI/Interval"                 /*string*/
+#define DS_SETTING_SYNCTYPE             "/GUI/SyncType"                 /*string*/
+#define DS_SETTING_AUTOSYNC_BEGINTIME   "/GUI/AutoSync/BeginTime"       /*int*/
+/* Keys for each resource type */
+/* Contact */
+#define DS_SETTING_CONTACT_ENABLED          "/Resource/Contacts/Enabled"                                /*int*/
+#define DS_SETTING_CONTACT_TGTURI           "/Resource/Contacts/TgtURI"                                 /*string*/
+#define DS_SETTING_CONTACT_SRCURI           "/Resource/Contacts/SrcURI"                                 /*string*/
+#define DS_SETTING_CONTACT_MEMSYNC          "/Resource/Contacts/MemSync"                                /*string*/
+#define DS_SETTING_CONTACT_MEMSYNCBACKUP    "/Resource/Contacts/MemSync_backup"                         /*string*/
+#define DS_SETTING_CONTACT_AUTHNONCE        "/Resource/Contacts/AuthInfo/Client/AuthNonce"              /*string*/
+#define DS_SETTING_CONTACT_AUTHTYPE         "/Resource/Contacts/AuthInfo/Client/AuthType"               /*int*/
+#define DS_SETTING_CONTACT_AUTHPWD          "/Resource/Contacts/AuthInfo/Client/AuthPWD"                /*string*/
+#define DS_SETTING_CONTACT_AUTHNAME         "/Resource/Contacts/AuthInfo/Client/AuthName"               /*string*/
+#define DS_SETTING_CONTACT_DBSYNCED         "/Resource/Contacts/Statistics/DBSynced"                    /*string*/
+#define DS_SETTING_CONTACT_LASTANCHOR       "/Resource/Contacts/Statistics/LastAnchor"                  /*string*/
+#define DS_SETTING_CONTACT_LASTSESSIONTIME  "/Resource/Contacts/Statistics/LastSessionTime"             /*int*/
+#define DS_SETTING_CONTACT_C2S_TOTAL        "/Resource/Contacts/Statistics/Client2Server_Total"         /*int*/
+#define DS_SETTING_CONTACT_S2C_TOTAL        "/Resource/Contacts/Statistics/Server2Client_Total"         /*int*/
+#define DS_SETTING_CONTACT_C2S_REPLACE      "/Resource/Contacts/Statistics/Client2Server_NrOfReplace"   /*int*/
+#define DS_SETTING_CONTACT_S2C_REPLACE      "/Resource/Contacts/Statistics/Server2Client_NrOfReplace"   /*int*/
+#define DS_SETTING_CONTACT_C2S_ADD          "/Resource/Contacts/Statistics/Client2Server_NrOfAdd"       /*int*/
+#define DS_SETTING_CONTACT_S2C_ADD          "/Resource/Contacts/Statistics/Server2Client_NrOfAdd"       /*int*/
+#define DS_SETTING_CONTACT_S2C_DELETE       "/Resource/Contacts/Statistics/Server2Client_NrOfDelete"    /*int*/
+#define DS_SETTING_CONTACT_C2S_DELETE       "/Resource/Contacts/Statistics/Client2Server_NrOfDelete"    /*int*/
+/* Calendar */
+#define DS_SETTING_CALENDAR_ENABLED         "/Resource/Organizer/Enabled"                               /*int*/
+#define DS_SETTING_CALENDAR_TGTURI          "/Resource/Organizer/TgtURI"                                /*string*/
+#define DS_SETTING_CALENDAR_SRCURI          "/Resource/Organizer/SrcURI"                                /*string*/
+#define DS_SETTING_CALENDAR_AUTHNONCE       "/Resource/Organizer/AuthInfo/Client/AuthNonce"             /*string*/
+#define DS_SETTING_CALENDAR_AUTHTYPE        "/Resource/Organizer/AuthInfo/Client/AuthType"              /*int*/
+#define DS_SETTING_CALENDAR_AUTHPWD         "/Resource/Organizer/AuthInfo/Client/AuthPWD"               /*string*/
+#define DS_SETTING_CALENDAR_AUTHNAME        "/Resource/Organizer/AuthInfo/Client/AuthName"              /*string*/
+#define DS_SETTING_CALENDAR_DBSYNCED        "/Resource/Organizer/Statistics/DBSynced"                   /*string*/
+#define DS_SETTING_CALENDAR_LASTANCHOR      "/Resource/Organizer/Statistics/LastAnchor"                 /*string*/
+#define DS_SETTING_CALENDAR_LASTSESSIONTIME "/Resource/Organizer/Statistics/LastSessionTime"            /*int*/
+#define DS_SETTING_CALENDAR_C2S_TOTAL       "/Resource/Organizer/Statistics/Client2Server_Total"        /*int*/
+#define DS_SETTING_CALENDAR_S2C_TOTAL       "/Resource/Organizer/Statistics/Server2Client_Total"        /*int*/
+#define DS_SETTING_CALENDAR_C2S_REPLACE     "/Resource/Organizer/Statistics/Client2Server_NrOfReplace"  /*int*/
+#define DS_SETTING_CALENDAR_S2C_REPLACE     "/Resource/Organizer/Statistics/Server2Client_NrOfReplace"  /*int*/
+#define DS_SETTING_CALENDAR_C2S_ADD         "/Resource/Organizer/Statistics/Client2Server_NrOfAdd"      /*int*/
+#define DS_SETTING_CALENDAR_S2C_ADD         "/Resource/Organizer/Statistics/Server2Client_NrOfAdd"      /*int*/
+#define DS_SETTING_CALENDAR_S2C_DELETE      "/Resource/Organizer/Statistics/Server2Client_NrOfDelete"   /*int*/
+#define DS_SETTING_CALENDAR_C2S_DELETE      "/Resource/Organizer/Statistics/Client2Server_NrOfDelete"   /*int*/
+/* Memo */
+#define DS_SETTING_MEMO_ENABLED             "/Resource/Memo/Enabled"                                    /*int*/
+#define DS_SETTING_MEMO_TGTURI              "/Resource/Memo/TgtURI"                                     /*string*/
+#define DS_SETTING_MEMO_SRCURI              "/Resource/Memo/SrcURI"                                     /*string*/
+#define DS_SETTING_MEMO_AUTHNONCE           "/Resource/Memo/AuthInfo/Client/AuthNonce"                  /*string*/
+#define DS_SETTING_MEMO_AUTHTYPE            "/Resource/Memo/AuthInfo/Client/AuthType"                   /*int*/
+#define DS_SETTING_MEMO_AUTHPWD             "/Resource/Memo/AuthInfo/Client/AuthPWD"                    /*string*/
+#define DS_SETTING_MEMO_AUTHNAME            "/Resource/Memo/AuthInfo/Client/AuthName"                   /*string*/
+#define DS_SETTING_MEMO_DBSYNCED            "/Resource/Memo/Statistics/DBSynced"                        /*string*/
+#define DS_SETTING_MEMO_LASTANCHOR          "/Resource/Memo/Statistics/LastAnchor"                      /*string*/
+#define DS_SETTING_MEMO_LASTSESSIONTIME     "/Resource/Memo/Statistics/LastSessionTime"                 /*int*/
+#define DS_SETTING_MEMO_C2S_TOTAL           "/Resource/Memo/Statistics/Client2Server_Total"             /*int*/
+#define DS_SETTING_MEMO_S2C_TOTAL           "/Resource/Memo/Statistics/Server2Client_Total"             /*int*/
+#define DS_SETTING_MEMO_C2S_REPLACE         "/Resource/Memo/Statistics/Client2Server_NrOfReplace"       /*int*/
+#define DS_SETTING_MEMO_S2C_REPLACE         "/Resource/Memo/Statistics/Server2Client_NrOfReplace"       /*int*/
+#define DS_SETTING_MEMO_C2S_ADD             "/Resource/Memo/Statistics/Client2Server_NrOfAdd"           /*int*/
+#define DS_SETTING_MEMO_S2C_ADD             "/Resource/Memo/Statistics/Server2Client_NrOfAdd"           /*int*/
+#define DS_SETTING_MEMO_S2C_DELETE          "/Resource/Memo/Statistics/Server2Client_NrOfDelete"        /*int*/
+#define DS_SETTING_MEMO_C2S_DELETE          "/Resource/Memo/Statistics/Client2Server_NrOfDelete"        /*int*/
+#ifdef FILE_SYNC
+#define DS_SETTING_FILE_ENABLED             "/Resource/File/Enabled"                                    /*int*/
+#define DS_SETTING_FILE_TGTURI              "/Resource/File/TgtURI"                                     /*string*/
+#define DS_SETTING_FILE_SRCURI              "/Resource/File/SrcURI"                                     /*string*/
+#define DS_SETTING_FILE_AUTHNONCE           "/Resource/File/AuthInfo/Client/AuthNonce"                  /*string*/
+#define DS_SETTING_FILE_AUTHTYPE            "/Resource/File/AuthInfo/Client/AuthType"                   /*int*/
+#define DS_SETTING_FILE_AUTHPWD             "/Resource/File/AuthInfo/Client/AuthPWD"                    /*string*/
+#define DS_SETTING_FILE_AUTHNAME            "/Resource/File/AuthInfo/Client/AuthName"                   /*string*/
+#define DS_SETTING_FILE_DBSYNCED            "/Resource/File/Statistics/DBSynced"                        /*string*/
+#define DS_SETTING_FILE_LASTANCHOR          "/Resource/File/Statistics/LastAnchor"                      /*string*/
+#define DS_SETTING_FILE_LASTSESSIONTIME     "/Resource/File/Statistics/LastSessionTime"                 /*int*/
+#define DS_SETTING_FILE_C2S_TOTAL           "/Resource/File/Statistics/Client2Server_Total"             /*int*/
+#define DS_SETTING_FILE_S2C_TOTAL           "/Resource/File/Statistics/Server2Client_Total"             /*int*/
+#define DS_SETTING_FILE_C2S_REPLACE         "/Resource/File/Statistics/Client2Server_NrOfReplace"       /*int*/
+#define DS_SETTING_FILE_S2C_REPLACE         "/Resource/File/Statistics/Server2Client_NrOfReplace"       /*int*/
+#define DS_SETTING_FILE_C2S_ADD             "/Resource/File/Statistics/Client2Server_NrOfAdd"           /*int*/
+#define DS_SETTING_FILE_S2C_ADD             "/Resource/File/Statistics/Server2Client_NrOfAdd"           /*int*/
+#define DS_SETTING_FILE_S2C_DELETE          "/Resource/File/Statistics/Server2Client_NrOfDelete"        /*int*/
+#define DS_SETTING_FILE_C2S_DELETE          "/Resource/File/Statistics/Client2Server_NrOfDelete"        /*int*/
+#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * @par Description: API to get value(char*) from vconf
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, base key
+ * @param[in]          string type, key
+ * @param[out]
+ *
+ * @return                             value on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+char *get_vconf_str(char *baseKey, char *key);
+
+/**
+ * @par Description: API to get value(char*) from vconf
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, key
+ * @param[out]
+ *
+ * @return                             value on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+char *get_vconf_str_key(char *key);
+
+/**
+ * @par Description: API to get value(int) from vconf
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, base key
+ * @param[in]          string type, key
+ * @param[out]         int type, value
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_vconf_int(char *baseKey, char *key, int *value);
+
+
+/**
+ * @par Description: API to get value(int) from vconf
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, key
+ * @param[out]         int type, value
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_vconf_Int_key(char *key, int *value);
+
+
+/**
+ * @par Description: API to set value(char*) into vconf
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, basekey
+ * @param[in]          string type, key
+ * @param[in]          string type, value
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool set_vconf_str(char *baseKey, char *key, char *value);
+
+/**
+ * @par Description: API to set value(char*) into vconf
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, key
+ * @param[in]          string type, value
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool set_vconf_str_key(char *key, char *value);
+
+/**
+ * @par Description: API to set value(int) into vconf
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, basekey
+ * @param[in]          string type, key
+ * @param[in]          int type, value
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool set_vconf_int(char *baseKey, char *key, int value);
+
+/**
+ * @par Description: API to set value(int) into vconf
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, key
+ * @param[in]          int type, value
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool set_vconf_int_key(char *key, int value);
+
+#endif /* COMMON_VCONF_H_ */
diff --git a/include/Common/CscKeys.h b/include/Common/CscKeys.h
new file mode 100644 (file)
index 0000000..115ec66
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @CscKeys.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of define for CSC keys
+ */
+
+#ifndef CSCKEYS_H_
+#define CSCKEYS_H_
+
+
+/* SyncML DS */
+ #define CSC_VCONF_KEY_SYNCMLDS_NBDATASYNC             "db/Apps/syncml-service/DS/Accounts/NbDataSync"
+#define CSC_VCONF_KEY_SYNCMLDS_NETWORK                 "db/Apps/syncml-service/DS/Accounts/Sync%d/NetworkName"
+#define CSC_VCONF_KEY_SYNCMLDS_VERSION                 "db/Apps/syncml-service/DS/Accounts/Sync%d/DSVersion"
+#define CSC_VCONF_KEY_SYNCMLDS_NAME                 "db/Apps/syncml-service/DS/Accounts/Sync%d/Name"
+#define CSC_VCONF_KEY_SYNCMLDS_ADDR                        "db/Apps/syncml-service/DS/Accounts/Sync%d/AppAddr/Addr"
+#define CSC_VCONF_KEY_SYNCMLDS_AUTHNAME                        "db/Apps/syncml-service/DS/Accounts/Sync%d/AuthInfo/Client/AuthName"
+#define CSC_VCONF_KEY_SYNCMLDS_AUTHPWD                         "db/Apps/syncml-service/DS/Accounts/Sync%d/AuthInfo/Client/AuthPWD"
+#define CSC_VCONF_KEY_SYNCMLDS_SYNCTYPE             "db/Apps/syncml-service/DS/Accounts/Sync%d/GUI/SyncType"
+#define CSC_VCONF_KEY_SYNCMLDS_SYNCMODE             "db/Apps/syncml-service/DS/Accounts/Sync%d/GUI/SyncMode"
+#define CSC_VCONF_KEY_SYNCMLDS_CONTACTS_ENABLED                "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Contacts/Enabled"
+#define CSC_VCONF_KEY_SYNCMLDS_CONTACTS_TGTURI         "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Contacts/TgtURI"
+#define CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHNAME       "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Contacts/AuthInfo/Server/AuthName"
+#define CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHPWD                "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Contacts/AuthInfo/Server/AuthPWD"
+#define CSC_VCONF_KEY_SYNCMLDS_CALENDAR_ENABLED                "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Calendar/Enabled"
+#define CSC_VCONF_KEY_SYNCMLDS_CALENDAR_TGTURI         "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Calendar/TgtURI"
+#define CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHNAME       "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Calendar/AuthInfo/Server/AuthName"
+#define CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHPWD                "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Calendar/AuthInfo/Server/AuthPWD"
+#define CSC_VCONF_KEY_SYNCMLDS_MEMO_ENABLED                            "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Memo/Enabled"
+#define CSC_VCONF_KEY_SYNCMLDS_MEMO_TGTURI                 "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Memo/TgtURI"
+#define CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHNAME           "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Memo/AuthInfo/Server/AuthName"
+#define CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHPWD                "db/Apps/syncml-service/DS/Accounts/Sync%d/Resource/Memo/AuthInfo/Server/AuthPWD"
+
+
+
+#endif /* CSCKEYS_H_ */
diff --git a/include/Framework/Event/OMA_DS_Event_Handler.h b/include/Framework/Event/OMA_DS_Event_Handler.h
new file mode 100644 (file)
index 0000000..fb7df7a
--- /dev/null
@@ -0,0 +1,511 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Event_Handler.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface for event callback function(from UI)
+ */
+
+#ifndef OMA_DS_EVENT_HANDLER_H_
+#define OMA_DS_EVENT_HANDLER_H_
+
+#include <stdio.h>
+#include "agent-framework/Event/Event_Handler.h"
+
+/**
+ * @par Description: This API is event callback function for add account
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+int event_callback_add_account(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for edit account
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+int event_callback_edit_account(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for auto configure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+int event_callback_auto_configure(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for add profile
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_add_profile_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for edit profile
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_edit_profile_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for delete profile
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_delete_profile_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for request sync
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_request_sync_async(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for auto configure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_auto_configure_async(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for cancel sync
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_cancel_sync_async(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for query sync status
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_query_sync_status_async(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for getting profile name
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_get_profile_name_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for getting profile server information
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_get_profile_server_info_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for getting profile sync mode
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_get_profile_sync_mode_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for getting profile sync category
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_get_profile_sync_category_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for last session information
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_get_profile_last_session_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for last statistics
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_get_profile_last_statistics_sync(Event_Data *request, Event_Data *response);
+
+/**
+ * @par Description: This API is event callback function for add profile for CP
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          buffer for incomming parameter
+ * @param[in]          buffer for outgoing parameter
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int event_callback_add_profile_cp_sync(Event_Data *request, Event_Data *response);
+
+#endif /* OMA_DS_EVENT_HANDLER_H_ */
diff --git a/include/Framework/Event/OMA_DS_Platform_Event_Handler.h b/include/Framework/Event/OMA_DS_Platform_Event_Handler.h
new file mode 100644 (file)
index 0000000..a759564
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Platform_Event_Handler.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface for event callback function(platform monitor)
+ */
+
+#ifndef OMA_DS_PLATFORM_EVENT_HANDLER_H_
+#define OMA_DS_PLATFORM_EVENT_HANDLER_H_
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+/**
+ * @par Description: API to parse callback function for SAN
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, msg body
+ * @param[in]          unsigned int type, size of msg
+ * @param[in]          int type, version
+ * @param[out]
+ *
+ * @return                             0 on success
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int SAN_callback_parse(const char *msgBody, unsigned int msgSize, int version);
+
+/**
+ * @par Description: This API is callback function for scheduler
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          scheduler Id
+ * @param[in]          user data
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void send_periodic_sync_msg(int schedulerId, void *data);
+
+#endif /* OMA_DS_PLATFORM_EVENT_HANDLER_H_ */
diff --git a/include/Framework/SAN_parser/PM_SanParser.h b/include/Framework/SAN_parser/PM_SanParser.h
new file mode 100644 (file)
index 0000000..eccf696
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+\r
+\r
+/*\r
+ * For any sort of issue you concern as to this software,\r
+ * you may use following point of contact.\r
+ * All resources contributed on this software\r
+ * are orinigally written by S-Core Inc., a member of Samsung Group.\r
+ *\r
+ * SeongWon Shim <seongwon.shim@samsung.com>\r
+ */\r
+\r
+/**\r
+ *   @PM_SanParser.h\r
+ *   @version                                                                  0.1\r
+ *   @brief                                                                            This file is the header file of interface and defined structure for San Parser\r
+ */\r
+\r
+#ifndef PM_SANPARSER_H_\r
+#define PM_SANPARSER_H_\r
+\r
+/* FIXME : When initialize, set "Server_id" at config_tbl..\r
+#define SMLDS_MOBILEDIT_SERVER                                                         (char *)"mobiledit"\r
+#define SMLDS_FUNAMBOL_SERVER                                                          (char *)"funambol"\r
+#define SMLDS_O3SIS_SERVER_SAN_IDENTIFIER              (char *)"O3SIS SyncML Server"\r
+*/\r
+\r
+typedef enum {\r
+       SAN_UIMODE_UNSPECIFIED  = 0,\r
+       SAN_UIMODE_BACKGROUND   = 1,\r
+       SAN_UIMODE_INFORMATIVE  = 2,\r
+       SAN_UIMODE_USER                 = 3\r
+} SanUIMode;\r
+\r
+typedef enum {\r
+       SAN_INITIATOR_USER              = 0,\r
+       SAN_INITIATOR_SERVER    = 1\r
+} SanInitiator;\r
+\r
+typedef enum {\r
+       SAN_SYNC_TYPE_TWO_WAY_BY_SERVER                         = 206,\r
+       SAN_SYNC_TYPE_ONE_WAY_FROM_CLIENT_BY_SERVER     = 207,\r
+       SAN_SYNC_TYPE_REFRESH_FROM_CLIENT_BY_SERVER     = 208,\r
+       SAN_SYNC_TYPE_ONE_WAY_FROM_SERVER_BY_SERVER     = 209,\r
+       SAN_SYNC_TYPE_REFRESH_FROM_SERVER_BY_SERVER     = 210,\r
+} SanSyncType;\r
+\r
+typedef struct SanCred SanCred;\r
+struct SanCred {\r
+       char *credFormat;\r
+       char *credAuth;\r
+       char *credData;\r
+};\r
+\r
+typedef struct SanContentType SanContentType;\r
+struct SanContentType {\r
+       unsigned int type;\r
+       char *strType;\r
+};\r
+\r
+typedef struct SanSyncAlert SanSyncAlert;\r
+struct SanSyncAlert {\r
+       SanSyncType syncType;\r
+       char *contentType;\r
+       char *serverURI;\r
+};\r
+\r
+typedef struct SanPackage SanPackage;\r
+struct SanPackage {\r
+       char *msgBodyWithoutDigest;\r
+       unsigned int msgBodyWithoutDigestLength;\r
+       char *digest;\r
+       unsigned int version;\r
+       SanUIMode uiMode;\r
+       SanInitiator initiator;\r
+       unsigned int sessionID;\r
+       SanCred *cred;\r
+       char *serverID;\r
+       unsigned int cntSyncAlerts;\r
+       SanSyncAlert *syncAlerts;\r
+};\r
+\r
+/**\r
+ * @par Description: API to parse for SAN version 1.2\r
+ *\r
+ *\r
+ * @par Purpose:\r
+ * @par Typical use case:\r
+ * @par Method of function operation:\r
+ * @par Important notes:\r
+ * @param[in]          string type, msg body\r
+ * @param[in]          unsigned int type, size of msg\r
+ * @param[out]\r
+ *\r
+ * @return                             SanPackage structure on success\r
+ *                                                     NULL on error\r
+ *\r
+ * @par Errors:\r
+ *\r
+ * @pre None.\r
+ * @post\r
+ * @see\r
+ * @remarks None.\r
+ *\r
+ * @par Sample Code:\r
+ * @code\r
+ * @endcode\r
+ */\r
+SanPackage *sanPackage12Parser(const char *msgBody, unsigned int msgSize);\r
+\r
+/**\r
+ * @par Description: API to parse for SAN version 1.1\r
+ *\r
+ *\r
+ * @par Purpose:\r
+ * @par Typical use case:\r
+ * @par Method of function operation:\r
+ * @par Important notes:\r
+ * @param[in]          string type, msg body\r
+ * @param[in]          unsigned int type, size of msg\r
+ * @param[out]\r
+ *\r
+ * @return                             SanPackage structure on success\r
+ *                                                     NULL on error\r
+ *\r
+ * @par Errors:\r
+ *\r
+ * @pre None.\r
+ * @post\r
+ * @see\r
+ * @remarks None.\r
+ *\r
+ * @par Sample Code:\r
+ * @code\r
+ * @endcode\r
+ */\r
+SanPackage *sanPackage11Parser(const char *msgBody, unsigned int msgSize);\r
+\r
+/**\r
+ * @par Description: API to free SanPackage structure\r
+ *\r
+ *\r
+ * @par Purpose:\r
+ * @par Typical use case:\r
+ * @par Method of function operation:\r
+ * @par Important notes:\r
+ * @param[in]          SanPackage structure\r
+ * @param[out]\r
+ *\r
+ * @return\r
+ *\r
+ * @par Errors:\r
+ *\r
+ * @pre None.\r
+ * @post\r
+ * @see\r
+ * @remarks None.\r
+ *\r
+ * @par Sample Code:\r
+ * @code\r
+ * @endcode\r
+ */\r
+void sanPackageParserFree(void *point);\r
+\r
+/**\r
+ * @par Description: API to print SAN msg for debugging\r
+ *\r
+ *\r
+ * @par Purpose:\r
+ * @par Typical use case:\r
+ * @par Method of function operation:\r
+ * @par Important notes:\r
+ * @param[in]          SanPackage structure\r
+ * @param[out]\r
+ *\r
+ * @return\r
+ *\r
+ * @par Errors:\r
+ *\r
+ * @pre None.\r
+ * @post\r
+ * @see\r
+ * @remarks None.\r
+ *\r
+ * @par Sample Code:\r
+ * @code\r
+ * @endcode\r
+ */\r
+void sanPrintMsg(SanPackage *san);\r
+\r
+#endif /* PM_SANPARSER_H_ */\r
+\r
diff --git a/include/Framework/Task/OMA_DS_Engine_Controller_Task.h b/include/Framework/Task/OMA_DS_Engine_Controller_Task.h
new file mode 100644 (file)
index 0000000..d85fbd9
--- /dev/null
@@ -0,0 +1,1280 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Engine_Controller_Task.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of registration function for using Engine Controller
+ */
+
+#ifndef ENGINE_CONTROLLER_TASK_H_
+#define ENGINE_CONTROLLER_TASK_H_
+
+#include <stdio.h>
+#include "agent-framework/EngineController/engine_controller.h"
+#include "agent-framework/EngineController/task_spec.h"
+#include "agent-framework/EngineController/queuing_rule_spec.h"
+
+
+#define SYNC_MODE_MANUAL               0
+#define SYNC_MODE_PERIODIC             1
+#define SYNC_MODE_SAN                          2
+#define SYNC_MODE_AUTOCONFIG   3
+
+typedef struct request_msg_info_s request_msg_info_t;
+struct request_msg_info_s {
+       int sync_type;
+       unsigned int request_id;
+};
+
+/*TODO have to be removed after removing vconf*/
+#define EC_MSG_TYPE_SYNC_TASK_ADD_ACCOUNT      2
+#define EC_MSG_TYPE_NAME_SYNC_TASK_ADD_ACCOUNT "add_account"
+#define EC_MSG_TYPE_SYNC_TASK_EDIT_ACCOUNT     3
+#define EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_ACCOUNT        "edit_account"
+#define EC_MSG_TYPE_SYNC_TASK_AUTOCONFIGURE            6
+#define EC_MSG_TYPE_NAME_SYNC_TASK_AUTOCONFIGURE               "auto_configure"
+
+
+
+#define EC_MSG_TYPE_SYNC_TASK_REQUEST          1
+#define EC_MSG_TYPE_NAME_SYNC_TASK_REQUEST     "sync_request"
+#define EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE      15                                      /*2*/
+#define EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE                 "add_profile"
+#define EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE     16                              /*3*/
+#define EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_PROFILE                "edit_profile"
+#define EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE   4
+#define EC_MSG_TYPE_NAME_SYNC_TASK_DELETE_PROFILE      "delete_profile"
+#define EC_MSG_TYPE_SAN_TASK_REQUEST                                   5
+#define EC_MSG_TYPE_NAME_SAN_TASK_REQUEST              "SAN_request"
+#define EC_MSG_TYPE_SYNC_TASK_AUTO_CONFIGURE           17              /*6*/
+#define EC_MSG_TYPE_NAME_SYNC_TASK_AUTO_CONFIGURE              "auto_configure"
+#define EC_MSG_TYPE_SYNC_TASK_SYNCSTATUS                       7
+#define EC_MSG_TYPE_NAME_SYNC_TASK_SYNCSTATUS                          "sync_status"
+#define EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_NAME                 8
+#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_NAME            "get_profile_name"
+#define EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SERVER_INFO                  9
+#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SERVER_INFO             "get_profile_server_info"
+#define EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_MODE                    10
+#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_MODE               "get_profile_sync_mode"
+#define EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY                11
+#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY   "get_profile_sync_category"
+#define EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_LAST_SESSION                 12
+#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_LAST_SESSION                            "get_profile_last_session"
+#define EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS                   13
+#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_STATISTICS                              "get_profile_statistics"
+#define EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES                     14
+#define EC_MSG_TYPE_NAME_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES                "reset_synchronizing_profiles"
+
+#define EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP                   19
+#define EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE_CP              "add_profile_cp"
+
+#define EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE                     20
+#define EC_MSG_TYPE_NAME_SYNC_TASK_REFRESH_FROM_SERVICE        "refresh_from_service"
+
+
+/*FIXME cancel request to NA */
+/*
+#define EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST              18
+#define EC_MSG_TYPE_NAME_SYNC_TASK_CANCEL_SYNC_REQUEST         "cancel_sync_request"
+*/
+
+/**
+ * @par Description: API to create add account task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_add_account_task();
+
+/**
+ * @par Description: API to create edit account task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_edit_account_task();
+
+/**
+ * @par Description: API to create auto configure task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_autoconfigure_task();
+
+/**
+ * @par Description: API to create synchronize task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_synchronize_task();
+
+
+/**
+ * @par Description: API to create synchronize task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_add_profile_task();
+
+
+/**
+ * @par Description: API to create edit profile task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_edit_profile_task();
+
+/**
+ * @par Description: API to create delete profiles task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_delete_profile_task();
+
+/**
+ * @par Description: API to create auto configure task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_auto_configure_task();
+
+/**
+ * @par Description: API to create sync status task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_sync_status_task();
+
+
+/**
+ * @par Description: API to create get profile name task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_get_profile_name_task();
+
+/**
+ * @par Description: API to create get profile server information task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_get_profile_server_info_task();
+
+/**
+ * @par Description: API to create get profile sync mode task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_get_profile_sync_mode_task();
+
+
+/**
+ * @par Description: API to create get profile sync category task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_get_profile_sync_category_task();
+
+
+/**
+ * @par Description: API to create get profile last session task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_get_profile_last_session_task();
+
+/**
+ * @par Description: API to create get profile last statistics task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_get_profile_statistics_task();
+
+/**
+ * @par Description: API to create reset synchronizing profiles task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_reset_synchronizing_profiles_task();
+
+/**
+ * @par Description: API to create reset synchronizing profiles task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_add_profile_cp_task();
+
+
+/**
+ * @par Description: API to create reset refresh_from_service task
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                             task_spec_t structure    on success
+ *                                                     NYLL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_spec_t *make_refresh_from_service_task();
+
+
+
+/*FIXME cancel request to NA */
+/*task_spec_t *make_cancel_sync_request();*/
+
+
+/**
+ * @par Description: This API is callback function which runs when add account task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+task_error_t add_account_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when edit account task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+task_error_t edit_account_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when auto configure task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+task_error_t autoconfigure_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when synchronize task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t synchronize_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when add profile task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t add_profile_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when edit profile task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t edit_profile_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when delete profiles task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t delete_profile_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when auto configure task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t auto_configure_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when sync status task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t sync_status_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when get profile name task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t get_profile_name_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when get profile server information task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t get_profile_server_info_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when get profile sync mode task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t get_profile_sync_mode_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when get profile sync category task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t get_profile_sync_category_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when get profile last session task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t get_profile_last_session_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when get profile last statistics task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t get_profile_statistics_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: This API is callback function which runs when reset synchronizing profiles task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t reset_synchronizing_profiles_task_process(unsigned int param_cnt, param_t **param_array);
+
+/*FIXME cancel request to NA */
+/*task_error_t cancel_sync_request_task_process(unsigned int param_cnt, param_t **param_array);*/
+
+/**
+ * @par Description: This API is callback function which runs when add profile for cp task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t add_profile_cp_task_process(unsigned int param_cnt, param_t **param_array);
+
+
+
+/**
+ * @par Description: This API is callback function which runs when refresh_from_service task is requested
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, parameter count
+ * @param[in]          array of parameters
+ * @param[out]
+ *
+ * @return                             TASK_ERROR_RUN_SUCCESS on success
+ *                                                     TASK_ERROR_RUN_FAILED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+task_error_t refresh_from_service_task_process(unsigned int param_cnt, param_t **param_array);
+
+/**
+ * @par Description: API to insert request_msg_info_t structure into list
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          sync_type(SYNC_MODE_MANUAL, SYNC_MODE_PERIODIC, SYNC_MODE_SAN, SYNC_MODE_AUTOCONFIG)
+ * @param[in]          request id
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void insert_request_msg_info(int sync_type, unsigned int request_id);
+
+/**
+ * @par Description: API to delete request_msg_info_t structure from list
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          request id
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void delete_request_msg_info(unsigned int request_id);
+
+/**
+ * @par Description: API to get synchronizing request id and delete request_msg_info_t structure from list
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]         request id
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_synchronizing_request_id(unsigned int *pRequest_id);
+
+/**
+ * @par Description: API to get manual sync request id and delete request_msg_info_t structure from list
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]         request id
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_manual_sync_request_id(unsigned int *pRequest_id);
+
+/**
+ * @par Description: API to get periodic sync request id and delete request_msg_info_t structure from list
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]         request id
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_periodic_sync_request_id(unsigned int *pRequest_id);
+
+/**
+ * @par Description: API to get SAN sync request id and delete request_msg_info_t structure from list
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]         request id
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_san_sync_request_id(unsigned int *pRequest_id);
+
+/**
+ * @par Description: API to get auto configure sync request id and delete request_msg_info_t structure from list
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]         request id
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_auto_configure_request_id(unsigned int *pRequest_id);
+
+#endif /* ENGINE_CONTROLLER_TASK_H_ */
diff --git a/include/ServiceAdapter/NetworkBinder/NA_Binder.h b/include/ServiceAdapter/NetworkBinder/NA_Binder.h
new file mode 100644 (file)
index 0000000..063a985
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @NA_Binder.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of NA Binder
+ */
+
+
+#ifndef NA_BINDER_H_
+#define NA_BINDER_H_
+
+#include "agent-framework/NetworkAccess/NA_External.h"
+#include "ServiceAdapter/SA_Define.h"
+
+/**
+ * @par Description: API to header binding for HTTP protocol
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, access type(http, obex...)
+ * @param[in]          string type, target uri
+ * @param[in]          boolean type, xml or wbxml
+ * @param[out]         GList type, list of header info
+ *
+ * @return                             1 on success
+ *                                                     0 on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int NA_http_header_binder(char *accType, char *loc_uri, bool isXML, GList **list);
+
+/**
+ * @par Description: API to free common_header_info structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          common_header_info structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_header_info(common_header_info *pCommon_header_info);
+
+
+#endif /* NA_BINDER_H_ */
diff --git a/include/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.h b/include/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.h
new file mode 100644 (file)
index 0000000..c5c1fc3
--- /dev/null
@@ -0,0 +1,342 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @oma_ds_protocol_binder.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of protocol binder
+ */
+
+#ifndef OMA_DS_PROTOCOL_BINDER_H_
+#define OMA_DS_PROTOCOL_BINDER_H_
+
+#include "agent-framework/NetworkAssistant/protocol_binder/protocol_binder_common.h"
+#include "ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder_definition.h"
+
+/**
+ * @par Description: API to Initialize protocol binder function set
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Binder_function_set structure
+ * @param[out]
+ *
+ * @return                             PROTOCOL_BINDER_ERROR type
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+PROTOCOL_BINDER_ERROR init_oma_ds_1_2_binder_function_set(Binder_function_set **pBinder_function_set);
+
+/**
+ * @par Description: API to free Binder_function_set structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Binder_function_set structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_oma_ds_1_2_binder_function_set(Binder_function_set *pBinder_function_set);
+
+/**
+ * @par Description: API to Initialize protocol binder
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          protocol_binder structure
+ * @param[in]          enum type, Encoding(ENCODING_XML, ENCODING_WBXML_10, ENCODING_WBXML_11, ENCODING_WBXML_12, ENCODING_WBXML_13)
+ * @param[in]          boolean type, whether encode xml header or not
+ * @param[in]          boolean type, whether use string table or not
+ * @param[in]          boolean type, whether protocol is anonymous or not
+ * @param[in]          boolean type, whether use flow mode or not
+ * @param[in]          Binder_function_set structure
+ * @param[out]
+ *
+ * @return                             protocol_binder on success
+ *                                                     NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+protocol_binder *oma_ds_1_2_binder_init(protocol_binder *pBinder, Encoding enc, bool encode_xml_header,
+                                               bool use_strtbl, bool produce_anonymous, bool use_flow_mode, Binder_function_set *pBinder_function_set);
+
+/**
+ * @par Description: API to append specific element to WBXML tree
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          protocol_binder structure
+ * @param[in]          enum type, protocol element
+ * @param[in]          content(structure to append)
+ * @param[out]
+ *
+ * @return                             PROTOCOL_BINDER_OK on success
+ *                                                     others on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_append(protocol_binder *pBinder, OMA_DS_Protocol_Element protocol_element, Content_Ptr pContent);
+
+
+/**
+ * @par Description: API to terminate protocol_binder structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          protocol_binder structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void oma_ds_1_2_binder_terminate(protocol_binder *pBinder);
+
+/**
+ * @par Description: API to get stream
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          protocol_binder structure
+ * @param[out]         string type, stream from WBXML tree
+ * @param[out]         unsigned int type, size of stream
+ *
+ * @return                             PROTOCOL_BINDER_OK on success
+ *                                                     others on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_stream(protocol_binder *pBinder,  char **byte_stream, unsigned int *byte_stream_size);
+
+/**
+ * @par Description: API to get stream size
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          protocol_binder structure
+ * @param[out]         unsigned int type, size of stream
+ *
+ * @return                             PROTOCOL_BINDER_OK on success
+ *                                                     others on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_stream_size(protocol_binder *pBinder, unsigned int *byte_stream_size);
+
+/**
+ * @par Description: API to get encoding type
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          protocol_binder structure
+ * @param[out]         enum type, Encoding(ENCODING_XML, ENCODING_WBXML_10, ENCODING_WBXML_11, ENCODING_WBXML_12, ENCODING_WBXML_13)
+ *
+ * @return                             PROTOCOL_BINDER_OK on success
+ *                                                     others on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_encoding(protocol_binder *pBinder, Encoding *enc);
+
+/**
+ * @par Description: API to Initialize reverse protocol binder
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, WBXML stream to parse
+ * @param[in]          unsigned int type, size of stream
+ * @param[in]          enum type, decoding(DECODING_XML, DECODING_WBXML)
+ * @param[in]          user data
+ * @param[out]         Reverse_protocol_binder structure
+ *
+ * @return                             PROTOCOL_BINDER_OK on success
+ *                                                     others on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+PROTOCOL_BINDER_ERROR reverse_oma_ds_1_2_binder_init(char *byte_stream,
+                                                                                                       unsigned int byte_stream_len,
+                                                                                                       Decoding dec,
+                                                                                                       Binder_function_set *pBinder_function_set,
+                                                                                                       void *user_data,
+                                                                                                       Reverse_protocol_binder **ppBinder);
+
+
+/**
+ * @par Description: API to parse and get next contents
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Reverse_protocol_binder structure
+ * @param[out]         protocol element
+ * @param[out]         string type, protocol element
+ * @param[out]         parsed contents(defined structure)
+ *
+ * @return                             PROTOCOL_BINDER_OK on success
+ *                                                     others on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+PROTOCOL_BINDER_ERROR reverse_oma_ds_1_2_binder_next(Reverse_protocol_binder *pBinder,
+                                                                                               Protocol_Element *protocol_element,
+                                                                                               char **protocol_element_name,
+                                                                                               Content_Ptr *pContent);
+
+
+#endif /* OMA_DS_PROTOCOL_BINDER_H_ */
diff --git a/include/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder_definition.h b/include/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder_definition.h
new file mode 100644 (file)
index 0000000..566ac35
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @oma_ds_protocol_binder_definition.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file for protocol binder definition
+ */
+
+#ifndef OMA_DS_PROTOCOL_BINDER_DEFINITION_H_
+#define OMA_DS_PROTOCOL_BINDER_DEFINITION_H_
+
+#include "agent-framework/NetworkAssistant/protocol_binder/protocol_binder_definition.h"
+
+#define INIT_ESTIMATE_DOC_SIZE 20
+
+#define ELEMENT_SYNCHDR "SyncHdr"
+#define ELEMENT_VERDTD "VerDTD"
+#define ELEMENT_VERDRD_10 "1.0"
+#define ELEMENT_VERDRD_11 "1.1"
+#define ELEMENT_VERDRD_12 "1.2"
+#define ELEMENT_VERPROTO "VerProto"
+#define ELEMENT_VERPROTO_10 "SyncML/1.0"
+#define ELEMENT_VERPROTO_11 "SyncML/1.1"
+#define ELEMENT_VERPROTO_12 "SyncML/1.2"
+#define ELEMENT_SESSIONID "SessionID"
+#define ELEMENT_MSGID "MsgID"
+#define ELEMENT_TARGET "Target"
+#define ELEMENT_SOURCE "Source"
+#define ELEMENT_LOCURI "LocURI"
+#define ELEMENT_LOCNAME "LocName"
+#define ELEMENT_RESPURI "RespURI"
+#define ELEMENT_NORESP "NoResp"
+#define ELEMENT_CRED "Cred"
+#define ELEMENT_CHAL "Chal"
+#define ELEMENT_META "Meta"
+#define ELEMENT_FORMAT "Format"
+#define ELEMENT_B64 "b64"
+#define ELEMENT_NEXTNONCE "NextNonce"
+#define ELEMENT_TYPE "Type"
+#define ELEMENT_DATA "Data"
+#define ELEMENT_MAXMSGSIZE "MaxMsgSize"
+#define ELEMENT_MAXOBJSIZE "MaxObjSize"
+#define ELEMENT_SYNCBODY "SyncBody"
+#define ELEMENT_CMDID "CmdID"
+#define ELEMENT_ITEM "Item"
+#define ELEMENT_SIZE "Size"
+#define ELEMENT_NUMBEROFCHANGES "NumberOfChanges"
+#define ELEMENT_STATUS "Status"
+#define ELEMENT_MSGREF "MsgRef"
+#define ELEMENT_CMDREF "CmdRef"
+#define ELEMENT_CMD "Cmd"
+#define ELEMENT_ADD "Add"
+#define ELEMENT_REPLACE "Replace"
+#define ELEMENT_ALERT "Alert"
+#define ELEMENT_SYNC "Sync"
+#define ELEMENT_PUT "Put"
+#define ELEMENT_SYNCML  "SyncML"
+#define ELEMENT_SYNCHDR "SyncHdr"
+#define ELEMENT_SYNCBODY "SyncBody"
+#define ELEMENT_REPLACE "Replace"
+#define ELEMENT_DELETE "Delete"
+#define ELEMENT_MAP "Map"
+#define ELEMENT_GET "Get"
+#define ELEMENT_RESULTS "Results"
+#define ELEMENT_TARGETREF "TargetRef"
+#define ELEMENT_SOURCEREF "SourceRef"
+#define ELEMENT_ANCHOR "Anchor"
+#define ELEMENT_LAST "Last"
+#define ELEMENT_NEXT "Next"
+#define ELEMENT_MAPITEM "MapItem"
+#define ELEMENT_MOREDATA "MoreData"
+#define ELEMENT_DEVINF "DevInf"
+#define ELEMENT_MAN "Man"
+#define ELEMENT_MOD "Mod"
+#define ELEMENT_OEM "OEM"
+#define ELEMENT_FWV "FwV"
+#define ELEMENT_SWV "SwV"
+#define ELEMENT_HWV "HwV"
+#define ELEMENT_DEVID "DevID"
+#define ELEMENT_DEVTYP "DevTyp"
+#define ELEMENT_PAGER "Pager"
+#define ELEMENT_HANDHELD "handheld"
+#define ELEMENT_PDA "pda"
+#define ELEMENT_PHONE "phone"
+#define ELEMENT_SMARTPHONE "smartphone"
+#define ELEMENT_SERVER "server"
+#define ELEMENT_WORKSTATION "workstation"
+#define ELEMENT_UTC "UTC"
+#define ELEMENT_SUPPORTLARGEOBJS "SupportLargeObjs"
+#define ELEMENT_SUPPORTNUMBEROFCHANGES "SupportNumberOfChanges"
+#define ELEMENT_DATASTORE "DataStore"
+#define ELEMENT_DISPLAYNAME "DisplayName"
+#define ELEMENT_MAXGUIDSIZE "MaxGUIDSize"
+#define ELEMENT_RX_PREF "Rx-Pref"
+#define ELEMENT_RX "Rx"
+#define ELEMENT_TX_PREF "Tx-Pref"
+#define ELEMENT_TX "Tx"
+#define ELEMENT_CTCAP "CTCap"
+#define ELEMENT_CTTYPE "CTType"
+#define ELEMENT_VERCT "VerCT"
+#define ELEMENT_FIELDLEVEL "FieldLevel"
+#define ELEMENT_PROPERTY "Property"
+#define ELEMENT_PROPNAME "PropName"
+#define ELEMENT_DATATYPE "DataType"
+#define ELEMENT_MAXOCCUR "MaxOccur"
+#define ELEMENT_MAXSIZE "MaxSize"
+#define ELEMENT_NOTRUNCATE "NoTruncate"
+#define ELEMENT_VALENUM "ValEnum"
+#define ELEMENT_DISPLAYNAME "DisplayName"
+#define ELEMENT_PROPPARAM "PropParam"
+#define ELEMENT_PARAMNAME "ParamName"
+#define ELEMENT_DSMEM "DSMem"
+#define ELEMENT_SUPPORTHIERARCHICALSYNC "SupportHierarchicalSync"
+#define ELEMENT_SYNCCAP "SyncCap"
+#define ELEMENT_SYNCTYPE "SyncType"
+#define ELEMENT_SYNCTYPE_1 "1"
+#define ELEMENT_SYNCTYPE_2 "2"
+#define ELEMENT_SYNCTYPE_3 "3"
+#define ELEMENT_SYNCTYPE_4 "4"
+#define ELEMENT_SYNCTYPE_5 "5"
+#define ELEMENT_SYNCTYPE_6 "6"
+#define ELEMENT_SYNCTYPE_7 "7"
+#define ELEMENT_FILTER_RX "Filter-Rx"
+#define ELEMENT_FILTERCAP "FilterCap"
+
+
+
+
+typedef enum {
+       PE_UNDEF = 0,
+       PE_ERROR,
+       PE_ADD,
+       PE_ALERT,
+       PE_ATOMIC_START,
+       PE_ATOMIC_END,
+       PE_COPY,
+       PE_DELETE,
+       PE_EXEC,
+       PE_GET,
+       PE_MAP,
+       PE_PUT_START,
+       PE_PUT_END,
+       PE_RESULTS_START,
+       PE_RESULTS_END,
+       PE_SEARCH,
+       PE_SEQUENCE_START,
+       PE_SEQUENCE_END,
+       PE_STATUS,
+       PE_SYNC_START,
+       PE_SYNC_END,
+       PE_REPLACE,
+       PE_HEADER,
+       PE_PUT_GET,
+       PE_CMD_GROUP,
+       PE_GENERIC,
+       PE_FINAL,
+       PE_DEVINF       ,
+       PE_SYNCML_START,
+       PE_SYNCML_END,
+       PE_BODY_START,
+       PE_BODY_END
+} OMA_DS_Protocol_Element;
+
+#endif /* OMA_DS_PROTOCOL_BINDER_DEFINITION_H_ */
diff --git a/include/ServiceAdapter/SA_Command.h b/include/ServiceAdapter/SA_Command.h
new file mode 100644 (file)
index 0000000..cd33644
--- /dev/null
@@ -0,0 +1,864 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Commandl.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of Command structure
+ */
+
+#ifndef SA_COMMAND_H_
+#define SA_COMMAND_H_
+
+#include "ServiceAdapter/SA_Define.h"
+#include "Common/Common_Define.h"
+
+
+/**
+ * @par Description: API to create alert command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          enum type, sync type
+ * @param[in]          Location structure(about source info)
+ * @param[in]          Location structure(about target info)
+ * @param[in]          string type, last anchor
+ * @param[in]          string type, next anchor
+ * @param[in]          Cred structure
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_alert_command(Session *session, AlertType  syncType, Location *source, Location *target,
+               char *lastAnchor, char *nextAnchor, Cred *pCred, Command **pCommand);
+
+/**
+ * @par Description: API to create get command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          Location structure(about target info)
+ * @param[in]          string type, content type
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_get_command(Session *session, Location* target, const char *contenttype, Command **pCommand);
+
+/**
+ * @par Description: API to create put command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          Location structure(about source info)
+ * @param[in]          string type, content type
+ * @param[in]          DevInf structure
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_put_command(Session *session, Location *source,  const char *contenttype,  DevInf *devInf , Command **pCommand);
+
+/**
+ * @par Description: API to create results command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          Location structure(about source info)
+ * @param[in]          string type, content type
+ * @param[in]          DevInf structure
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_results_command(Session *session, Location *source, const char *contenttype, DevInf *devInf, Command **pCommand);
+
+/**
+ * @par Description: API to create sync start command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          Location structure(about source info)
+ * @param[in]          Location structure(about target info)
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_sync_start_command(Session *session, Location *source, Location *target, Command **pCommand);
+
+/**
+ * @par Description: API to create sync end command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_sync_end_command(Command **pCommand);
+
+/**
+ * @par Description: API to create add command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          enum type, change type
+ * @param[in]          string type, luid of item
+ * @param[in]          string type, content type
+ * @param[in]          string type, data(vobject)
+ * @param[in]          unsigned int type, size of data
+ * @param[in]          int type, moreData(LargeObj)
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_add_command(Session *session, ChangeType type, char *luid, const char *contenttype,
+               char *data, unsigned int size,  int  moreData, Command **pCommand);
+
+/**
+ * @par Description: API to create replace command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          enum type, change type
+ * @param[in]          string type, luid of item
+ * @param[in]          string type, content type
+ * @param[in]          string type, data(vobject)
+ * @param[in]          unsigned int type, size of data
+ * @param[in]          int type, moreData(LargeObj)
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_replace_command(Session *session,  ChangeType type, char *luid, const char *contenttype,
+               const char *data,  unsigned int size, int moreData,  Command **pCommand);
+
+/**
+ * @par Description: API to create delete command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          enum type, change type
+ * @param[in]          string type, luid of item
+ * @param[in]          string type, content type
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_delete_command(Session *session, ChangeType type, char *luid, const char *contenttype, Command **pCommand);
+
+/**
+ * @par Description: API to create map command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          Location structure(about source info)
+ * @param[in]          Location structure(about target info)
+ * @param[out]         Command structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_map_command(Session *session, Location *source, Location *target, Command **pCommand);
+
+/**
+ * @par Description: API to free list of command structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          list of command structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_commands(GList *commands);
+
+/**
+ * @par Description: API to free command structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          command structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_command(Command *pCommand);
+
+/**
+ * @par Description: API to increase reference count of command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Command structure
+ * @param[out]
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType increase_command_refcount(Command *pCommand);
+
+/**
+ * @par Description: API to decrease reference count of command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Command structure
+ * @param[out]
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType decrease_command_refcount(Command *pCommand);
+
+/**
+ * @par Description: API to set msgRef in results command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Commnad structure
+ * @param[in]          unsigned int type, msg reference
+ * @param[out]
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType set_results_command_msgref(Command *pCommand, unsigned int msgRef);
+
+/**
+ * @par Description: API to set cmdRef in results command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Commnad structure
+ * @param[in]          unsigned int, cmd reference
+ * @param[out]
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType set_results_command_cmdref(Command *pCommand, unsigned int cmdRef);
+
+/**
+ * @par Description: API to set targetRef in results command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Commnad structure
+ * @param[in]          Location structure(target info)
+ * @param[out]
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType set_results_command_targetref(Command *pCommand, Location *pLocation);
+
+/**
+ * @par Description: API to set numberofchanges in sync start command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Commnad structure
+ * @param[in]          unsigned int type, number of changes
+ * @param[out]
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType set_sync_start_command_numberofchanges(Command *pCommand, unsigned int numberOfChanges);
+
+/**
+ * @par Description: API to set item in map command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Commnad structure
+ * @param[in]          item structure
+ * @param[out]
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType set_map_command_item(Command *mapCommand, Item *temp);
+
+/**
+ * @par Description: API to create status command with locatiion structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          data (status code)
+ * @param[in]          command structure
+ * @param[in]          Location structure(about source info)
+ * @param[in]          Location structure(about target info)
+ * @param[in]          command type
+ * @param[out]         Status structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_new_status_location(Session *session, OMA_StatusType data, Command *command,
+               Location *sourceref, Location *targetref, CommandType type, Status **pStatus);
+
+/**
+ * @par Description: API to create create status command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          enum type, data (status code)
+ * @param[in]          command structure
+ * @param[in]          enum type, command type
+ * @param[out]         Status structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_new_status(Session *session, OMA_StatusType data, Command *command, CommandType type, Status **pStatus);
+
+/**
+ * @par Description: API to create status command
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, data (status code)
+ * @param[in]          unsigned int type, cmd ID
+ * @param[in]          unsigned int type, cmd reference
+ * @param[in]          unsigned int type, msg reference
+ * @param[in]          Location structure(about source info)
+ * @param[in]          Location structure(about target info)
+ * @param[in]          enum type, command type
+ * @param[out]         Status structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_status(OMA_StatusType data, unsigned int cmdID, unsigned int cmdref, unsigned int msgref,
+               Location *sourceref, Location *targetref, CommandType type, Status **pStatus);
+
+/**
+ * @par Description: API to free list of Status structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          list of Status structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_statuses(GList *status);
+
+/**
+ * @par Description: API to free Status structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Status structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void   free_status(Status *status);
+
+/**
+ * @par Description: API to get status code from Status structure
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Status structure
+ * @param[out]
+ *
+ * @return                             OMA_StatusType type
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+OMA_StatusType get_status_code(Status *status);
+
+/**
+ * @par Description: API to convert to command type from char*
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          char* (Alert, Sync, Put, SyncHdr, Add, Replace, Map, Delete, Results, Get)
+ * @param[out]
+ *
+ * @return                             CommandType type
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+CommandType convert_command_type(char *type);
+
+/**
+ * @par Description: API to convert to change type from command type
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, CommandType
+ * @param[out]
+ *
+ * @return                             ChangeType type
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+ChangeType convert_change_type_command_type(CommandType type);
+
+/**
+ * @par Description: API to convert to command type from change type
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, ChangeType
+ * @param[out]
+ *
+ * @return                             CommandType type
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+CommandType convert_command_type_change_type(ChangeType type);
+
+
+/* unused function
+ * keep for  in case
+ */
+/*
+ChangeType convertToChangeType(unsigned int type);
+char *convertFromCommandType(CommandType type);
+*/
+
+#endif /* SA_COMMAND_H_ */
diff --git a/include/ServiceAdapter/SA_Command_Internal.h b/include/ServiceAdapter/SA_Command_Internal.h
new file mode 100644 (file)
index 0000000..b224539
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Command_Internal.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file that structure which is available in SA is defined
+ *                                                                                                     Command (Alert, Results, Sync, Put, Get, Map, Add, Replace, Delete)
+ *                                                                                                     Status
+ */
+
+#ifndef SA_COMMAND_INTERNAL_H_
+#define SA_COMMAND_INTERNAL_H_
+
+#include "ServiceAdapter/SA_Define.h"
+#include "Common/Common_Define.h"
+
+typedef struct CommandAlertPrivate {
+       AlertType type;
+       Anchor *anchor;
+       char *contentType;
+       unsigned int maxObjSize;
+} CommandAlertPrivate;
+
+typedef struct CommandSyncPrivate {
+       unsigned int numChanged;
+       int maxObjSize;
+       int hasNumChanged;
+} CommandSyncPrivate;
+
+typedef struct CommandAccessPrivate {
+       char *type;
+       Item *item;
+} CommandAccessPrivate;
+
+typedef struct CommandChangePrivate {
+       GList *items;
+       ChangeType type;
+} CommandChangePrivate;
+
+typedef struct CommandMapPrivate {
+       GList *items;
+} CommandMapPrivate;
+
+typedef struct CommandResultsPrivate {
+       unsigned int msgRef;
+       unsigned int cmdRef;
+       Location *targetRef;
+       char *type;
+       Item *item;
+} CommandResultsPrivate;
+
+typedef union CommandPrivate {
+       CommandAlertPrivate alert;
+       CommandSyncPrivate sync;
+       CommandAccessPrivate access;            /*put or get*/
+       CommandChangePrivate change;
+       CommandMapPrivate map;
+       CommandResultsPrivate results;
+} CommandPrivate;
+
+struct  Command {
+       int refCount;
+       CommandType type;
+       unsigned int cmdID;
+       unsigned int msgID;
+       CommandPrivate private;
+       Location *source;
+       Location *target;
+       Cred *cred;
+       int noResp;
+} ;
+
+struct Status {
+       unsigned int cmdID;
+       unsigned int msgRef;
+       unsigned int cmdRef;
+       CommandType type;
+       char *data;
+       Location *sourceRef;
+       Location *targetRef;
+       Cred *cred;
+       Chal *chal;
+       Item *item;
+};
+
+#endif /* SA_COMMAND_INTERNAL_H_ */
diff --git a/include/ServiceAdapter/SA_Common_Interface.h b/include/ServiceAdapter/SA_Common_Interface.h
new file mode 100644 (file)
index 0000000..3b1c229
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Common_Interface.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of SA
+ *                                                                                                     called by SE
+ */
+
+#ifndef SA_COMMON_INTERFACE_H_
+#define SA_COMMON_INTERFACE_H_
+
+
+/**
+ * @par Description: API to process pre-action that has to be befor sync service
+ *
+ *  Exchage Pkg1 and Pkg2 with server
+ *  Get Device Information
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, transport Type(obex, FW_HTTP ...)
+ * @param[in]          int type, account id
+ * @param[in]          string type, session id
+ * @param[out]         PreSyncReturnObj structure(result from pkg2)
+ *
+ * @return                     Common_ErrorType enum value
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int pre_sync(int transportType, int accountId, char *sessionId,  void **preSyncReturnObj);
+
+/**
+ * @par Description: API to generate protocol specific msg
+ *
+ *  Generate MSg which be considered maxMsgSize and maxObjSize
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncObj structure
+ * @param[out]         msg
+ * @param[out]         msg size
+ *
+ * @return                     Common_ErrorType enum value
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int generate_msg(void **syncObj, char **msg, unsigned int *msg_size);
+
+/**
+ * @par Description: API to exchange protocol specific msg with server
+ *
+ *  Exchange protocol specific msg(request and response) using  header binding information with server
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, transport protocol type(http, obex etc)
+ * @param[in]          string type, msg to send
+ * @param[in]          unsigned int type, msg size
+ * @param[out]         string type, receive msg
+ * @param[out]         unsigned int type, receive msg size
+ *
+ * @return                     Common_ErrorType enum value
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int exchange_msg(int transportType,  char *sendMsg, unsigned int sendMsg_length,  char **recvMsg, unsigned int *recvMsg_length);
+
+/**
+ * @par Description: API to process response msg from server
+ *
+ *  Process response msg from server and convert to obj that return to Service Engine
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, recive msg from server
+ * @param[in]          unsigned int type, receive msg size
+ * @param[out]         SyncReturnObj structure
+ * @param[out]         int type, flag for finsih sync session
+ *
+ * @return                     Common_ErrorType enum value
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int process_recv_msg(char *recvMsg, unsigned int recvMsg_length, void **syncReturnObj, int *isFinish);
+
+
+/**
+ * @par Description: API to free session structure and close connection
+ *
+ *  This API for case that error or cancel occur in ServiceEngine so need to clean up resource which using in ServiceAdapter
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void clean_up_SA();
+
+/**
+ * @par Description: API to process auto configure function
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, id
+ * @param[in]          string type, password
+ * @param[in]          string type, target uri
+ * @param[in]          string type, profile path for getting value from vconf
+ * @param[out]         GList type, list of auto configure results
+ *
+ * @return                             Common_ErrorType enum value
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int auto_configure_from_vconf(char *id, char *pwd, char *targetUrl, char *profilePath, GList **congifure);
+
+/**
+ * @par Description: API to process auto configure function
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, server ip
+ * @param[in]          string type, id
+ * @param[in]          string type, password
+ * @param[out]         GList type, list of auto configure results
+ *
+ * @return                             Common_ErrorType enum value
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int auto_configure(char *addr, char *id, char *password, GList **congifure);
+
+
+/*FIXME cancel request to NA */
+/*int cancel_connection_sync_request(int transportType);*/
+
+#endif /* SA_COMMON_INTERFACE_H_ */
diff --git a/include/ServiceAdapter/SA_Define.h b/include/ServiceAdapter/SA_Define.h
new file mode 100644 (file)
index 0000000..d16cd6e
--- /dev/null
@@ -0,0 +1,180 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Define.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of defined structure and enumeration used in SA
+ */
+
+#ifndef SA_DEFINE_H_
+#define SA_DEFINE_H_
+
+#include <malloc.h>
+#include <glib.h>
+#include <assert.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "ServiceAdapter/SA_Error.h"
+
+#define DEFINE_PROTOCOL_TYPE "OMA_DS"
+
+
+
+#define ELEMENT_DEVINF_10 "./devinf10"
+#define ELEMENT_DEVINF_11 "./devinf11"
+#define ELEMENT_DEVINF_12 "./devinf12"
+
+#define ELEMENT_DEVINF_XML "application/vnd.syncml-devinf+xml"
+#define ELEMENT_DEVINF_WBXML "application/vnd.syncml-devinf+wbxml"
+#define ELEMENT_WBXML "application/vnd.syncml+wbxml"
+#define ELEMENT_XML "application/vnd.syncml+xml"
+
+#define ELEMENT_AUTH_BASIC "syncml:auth-basic"
+#define ELEMENT_AUTH_MD5 "syncml:auth-md5"
+#define ELEMENT_FORMAT_BASE64 "b64"
+
+#define OMA_DS_HTTP_DEFAULT_CLIENT_MAX_MSG_SIZE 1024*12
+#define OMA_DS_HTTP_DEFAULT_CLIENT_MAX_OBJ_SIZE 1024*1024
+
+/*#define OMA_DS_HTTP_DEFAULT_SERVER_MAX_MSG_SIZE 61440*/
+#define OMA_DS_HTTP_DEFAULT_SERVER_MAX_MSG_SIZE 1024*5
+
+typedef struct Item Item;
+typedef struct Status Status;
+typedef struct Command Command;
+typedef struct Anchor Anchor;
+typedef struct Location Location;
+typedef struct Cred Cred;
+typedef struct SyncML SyncML;
+typedef struct SyncHdr SyncHdr;
+typedef struct Chal Chal;
+typedef struct DevInf DevInf;
+typedef struct DevInfDataStore DevInfDataStore;
+typedef struct DevInfContentType DevInfContentType;
+typedef struct DevInfCTCap DevInfCTCap;
+typedef struct DevInfProperty DevInfProperty;
+typedef struct DevInfPropParam DevInfPropParam;
+typedef struct FilterCap FilterCap;
+typedef struct Session Session;
+typedef struct PendingStatus PendingStatus;
+
+
+typedef enum {
+       VERSION_UNKNOWN = 0,
+       VERSION_10 = 1,
+       VERSION_11 = 2,
+       VERSION_12 = 3
+} ProtocolVersion;
+
+typedef enum {
+       PROTOCOL_TYPE_UNKNOWN = 0,
+       PROTOCOL_TYPE_DS = 1,
+} ProtocolType;
+
+typedef enum {
+       COMMAND_TYPE_UNKNOWN = 0,
+       COMMAND_TYPE_ALERT = 1,
+       COMMAND_TYPE_SYNC_START = 2,
+       COMMAND_TYPE_SYNC_END = 3,
+       COMMAND_TYPE_PUT = 4,
+       COMMAND_TYPE_HEADER = 5,
+       COMMAND_TYPE_ADD = 6,
+       COMMAND_TYPE_REPLACE = 7,
+       COMMAND_TYPE_DELETE = 8,
+       COMMAND_TYPE_MAP = 9,
+       COMMAND_TYPE_GET = 10,
+       COMMAND_TYPE_RESULTS = 11
+} CommandType;
+
+
+typedef enum {
+       AUTH_TYPE_UNKNOWN = 0,
+       AUTH_TYPE_BASIC = 1,
+       AUTH_TYPE_MD5 = 2
+} AuthType;
+
+typedef enum {
+       FORMAT_TYPE_UNKNOWN = 0,
+       FORMAT_TYPE_BASE64 = 1
+} FormatType;
+
+typedef enum  {
+       DEVINF_VERSION_UNKNOWN = 0,
+       DEVINF_VERSION_10 = 1,
+       DEVINF_VERSION_11 = 2,
+       DEVINF_VERSION_12 = 3
+} DevInfVersion;
+
+typedef enum {
+       DEVINF_DEVTYPE_UNKNOWN,
+       DEVINF_DEVTYPE_PAGER,
+       DEVINF_DEVTYPE_HANDHELD,
+       DEVINF_DEVTYPE_PDA,
+       DEVINF_DEVTYPE_PHONE,
+       DEVINF_DEVTYPE_SMARTPHONE,
+       DEVINF_DEVTYPE_SERVER,
+       DEVINF_DEVTYPE_WORKSTATION
+} DevInfDevTyp;
+
+typedef enum {
+       DEVINF_SYNCTYPE_UNKNOWN = 0,
+       DEVINF_SYNCTYPE_TWO_WAY = 1,
+       DEVINF_SYNCTYPE_SLOW_SYNC = 1 << 1,
+       DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT = 1 << 2,
+       DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT = 1 << 3,
+       DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER = 1 << 4,
+       DEVINF_SYNCTYPE_REFRESH_FROM_SERVER = 1 << 5,
+       DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC = 1 << 6
+} DevInfSyncCap;
+
+typedef enum {
+       SYNCML_PKG_1 = 1,
+       SYNCML_PKG_2 = 2,
+       SYNCML_PKG_3 = 3,
+       SYNCML_PKG_4 = 4,
+       SYNCML_PKG_5 = 5,
+       SYNCML_PKG_6 = 6
+} PkgStatus;
+
+typedef enum {
+       ITEM_UNKNOWN = 0,
+       ITEM_DATA = 1,
+       ITEM_DEVINF = 2,
+} ItemDataType;
+
+#endif /* SA_DEFINE_H_ */
diff --git a/include/ServiceAdapter/SA_DevInf.h b/include/ServiceAdapter/SA_DevInf.h
new file mode 100644 (file)
index 0000000..59d4182
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_DevInf.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of DevInf structure
+ */
+
+#ifndef SA_DEVINF_H_
+#define SA_DEVINF_H_
+
+#include "ServiceAdapter/SA_Define.h"
+
+/**
+ * @par Description: API to create DevInf structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[out]         DevInf  structure
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_INTERNAL_ERROR, ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_devinf(Session *session, DevInf **pDevInf);
+
+/**
+ * @par Description: API to free DevInf structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DevInf  structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_devinf(DevInf *devInf);
+
+/**
+ * @par Description: API to set sync cap in DevInfDataStore structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DevInfDataStore structure
+ * @param[in]          DevInf sync type
+ * @param[in]          whether support or not
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_devInf_datastore_synccap(DevInfDataStore *devInfDataStore, DevInfSyncCap cap, int supported);
+
+
+/**
+ * @par Description: API to get sync cap from DevInfDataStore structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DevInfDataStore structure
+ * @param[in]          DevInf sync type
+ *
+ * @return                             True on success
+ *                                                     False on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int get_devinf_datastore_synccap(const DevInfDataStore *devInfDataStore, DevInfSyncCap cap);
+
+/*
+DevInfSyncCap convert_devinf_synccap(unsigned int id);
+*/
+#endif /* SA_DEVINF_H_ */
diff --git a/include/ServiceAdapter/SA_DevInf_Internal.h b/include/ServiceAdapter/SA_DevInf_Internal.h
new file mode 100644 (file)
index 0000000..2d978f2
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_DevInf_Internal.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file that structure which is available in SA is defined
+ *                                                                                                     about device information(DevInf)
+ */
+
+#ifndef SA_DEVINF_INTERNAL_H_
+#define SA_DEVINF_INTERNAL_H_
+
+#include "ServiceAdapter/SA_Define.h"
+
+#define DEFINE_DEVICE_TYPE_PAGER "pager"
+#define DEFINE_DEVICE_TYPE_HANDHELD "handheld"
+#define DEFINE_DEVICE_TYPE_PDA "pda"
+#define DEFINE_DEVICE_TYPE_PHONE "phone"
+#define DEFINE_DEVICE_TYPE_SMARTPHONE "smartphone"
+#define DEFINE_DEVICE_TYPE_SERVER "server"
+#define DEFINE_DEVICE_TYPE_WORKSTATION "workstation"
+
+struct DevInf {
+       DevInfVersion version;
+
+       DevInfDevTyp devtyp;
+       char *manufacturer;
+       char *model;
+       char *oem;
+       char *softwareVersion;
+       char *hardwareVersion;
+       char *firmwareVersion;
+       char *devid;
+
+       int supportsUTC;
+       int supportsLargeObjs;
+       int supportsNumberOfChanges;
+
+       GList *datastores;                                                      /*containing DevInfDataStore structure*/
+};
+
+struct DevInfDataStore {
+       int supportsHierarchicalSync;
+
+       char *sourceref;
+       char *displayname;
+       unsigned int maxGUIDSize;
+
+       DevInfContentType *rxPref;
+       DevInfContentType *txPref;
+
+       GList *filter_rx;                       /*need to be considered filter_rx,filterCap*/
+       GList *filterCap;
+
+       GList *rx;
+       GList *tx;
+
+       int sharedMem;
+       unsigned int maxid;
+       unsigned int maxmem;
+
+       unsigned int synccap;
+
+       GList *ctcaps;                                                          /*containing DevInfCTCap structure*/
+};
+
+struct DevInfContentType {
+       char *cttype;
+       char *verct;
+};
+
+struct DevInfCTCap {
+       DevInfContentType *ct;
+       GList *properties;                                      /*containing DevInfProperty structure*/
+};
+
+struct DevInfProperty {
+       char *propName;
+       char *dataType;
+       unsigned int maxOccur;
+       unsigned int maxSize;
+/*     unsigned int propSize;*/
+       int noTruncate;
+       char *displayName;
+       GList *valEnums;                                        /*containing char* */
+       GList *propParams;                              /*containing DevInfPropParam structure*/
+};
+
+struct DevInfPropParam {
+       char *paramName;
+       char *dataType;
+       char *displayName;
+       GList *valEnums;
+};
+
+struct FilterCap {
+       char *cttype;
+       char *verct;
+       GList *filterKeyword;
+       GList *propName;
+};
+
+#endif /* SA_DEVINF_INTERNAL_H_ */
diff --git a/include/ServiceAdapter/SA_Elements.h b/include/ServiceAdapter/SA_Elements.h
new file mode 100644 (file)
index 0000000..9a391cc
--- /dev/null
@@ -0,0 +1,811 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Elements.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of elements structure
+ */
+
+#ifndef SA_ELEMENTS_H_
+#define SA_ELEMENTS_H_
+
+#include "ServiceAdapter/SA_Define.h"
+
+/**
+ * @par Description: API to create Anchor structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, last anchor
+ * @param[in]          string type, next anchor
+ * @param[out]         Anchor structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_anchor(char *last, char *next, Anchor **pAnchor);
+
+/**
+ * @par Description: API to set anchor in Item structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Item structure
+ * @param[in]          Anchor structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED, ERROR_INTERNAL_NO_MEMORY on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType set_item_anchor(Item *item, Anchor *anchor);
+
+/**
+ * @par Description: API to set last anchor in Anchor structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Anchor structure
+ * @param[in]          string type, last anchor
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType set_last_anchor(Anchor *anchor, char *lastAnchor);
+
+/**
+ * @par Description: API to set next anchor in Anchor structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Anchor structure
+ * @param[in]          string type, next anchor
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType set_next_anchor(Anchor *anchor, char *nextAnchor);
+
+/**
+ * @par Description: API to free Anchor structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Anchor structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NOT_DEFINED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_anchor(Anchor *pAnchor);
+
+/**
+ * @par Description: API to create Location structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, location uri
+ * @param[in]          string type, location name
+ * @param[out]         Location structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY, ERROR_INTERNAL_NOT_DEFINED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_location(char *locURI, char *locName, Location **pLocation);
+
+/**
+ * @par Description: API to duplicate Location structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Location structure
+ *
+ * @return                             Location structure                              on success
+ *                                                     NULL                                                            on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+Location *dup_location(Location* pLocation);
+
+/**
+ * @par Description: API to get location name from Location structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Location structure
+ *
+ * @return                             location name                                   on success
+ *                                                     NULL                                                            on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+char *get_location_locname(Location *location);
+
+/**
+ * @par Description: API to get location uri from Location structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Location structure
+ *
+ * @return                             location uri                                                    on success
+ *                                                     NULL                                                            on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+char *get_location_locuri(Location *location);
+
+/**
+ * @par Description: API to free Location structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Location structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_location(Location *loc);
+
+/**
+ * @par Description: API to create Cred structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, ID
+ * @param[in]          string type, password
+ * @param[in]          enum type, authentication type(basic, md5..)
+ * @param[in]          enum type, format type(base64..)
+ * @param[in]          string type, credential
+ * @param[out]         Cred structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY, ERROR_INTERNAL_NOT_DEFINED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_cred(char *userName, char *pwd, AuthType authType, FormatType formatType , char *data,  Cred **cred);
+
+/**
+ * @par Description: API to create Cred structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, authentication type(basic, md5..)
+ * @param[in]          credential
+ *
+ * @return                             Cred structure on success
+ *                                                     NULL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+Cred *create_cred_with_data(AuthType authType, char *data);
+
+/**
+ * @par Description: API to duplicate Cred structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Cred structure
+ *
+ * @return                             Cred structure on success
+ *                                                     NULL on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+Cred *dup_cred(Cred *pCred);
+
+/**
+ * @par Description: API to set format type in Cred structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Cred structure
+ * @param[in]          format type(base64..)
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_cred_format_type(Cred *cred, FormatType formatType);
+
+/**
+ * @par Description: API to free Cred structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Cred structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_cred(Cred *cred);
+
+/**
+ * @par Description: API to create SyncML structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncHdr structure
+ * @param[in]          GList type, list of Status structure
+ * @param[in]          GList type, list of Command structure
+ * @param[in]          int type, final flag
+ * @param[out]         SyncML structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY, ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_syncml(SyncHdr *syncHdr, GList *status, GList *commands, int isFinal , SyncML **pSyncML);
+
+/**
+ * @par Description: API to free SyncML structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncML structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_syncml(SyncML *syncML);
+
+/**
+ * @par Description: API to create SyncHdr structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          session structure
+ * @param[out]         SyncHdr structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY, ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_synchdr(Session *session , SyncHdr **pSyncHdr);
+
+/**
+ * @par Description: API to free SyncHdr structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          SyncHdr structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_synchdr(SyncHdr *syncHdr);
+
+/**
+ * @par Description: API to create Item structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]
+ * @param[out]
+ *
+ * @return                     Item structure on success
+ *                                             NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+Item *create_item();
+
+/**
+ * @par Description: API to create Item structure using data
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          data
+ * @param[in]          size of data
+ * @param[out]
+ *
+ * @return                     Item structure on success
+ *                                             NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+Item *create_item_for_data(const char *data, unsigned int size);
+
+/**
+ * @par Description: API to create Item structure using DevInf
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          DevInf structure
+ * @param[out]
+ *
+ * @return                     Item structure on success
+ *                                             NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+Item *create_item_for_devinf(DevInf *devInf);
+
+/**
+ * @par Description: API to set Location(target) structure in Item structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Item structure
+ * @param[in]          Location structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_item_target(Item *item, Location *target);
+
+/**
+ * @par Description: API to set Location(source) structure in Item structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Item structure
+ * @param[in]          Location structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_item_source(Item *item, Location *source);
+
+/**
+ * @par Description: API to free Item structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Item structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_item(Item *item);
+
+/**
+ * @par Description: API to duplicate Chal structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Chal structure
+ * @param[out]
+ *
+ * @return                     Chal structure on success
+ *                                             NULL on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+Chal *dup_chal(Chal *pChal);
+
+/**
+ * @par Description: API to free Chal structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Chal structure
+ * @param[out]
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_chal(Chal *chal);
+
+/**
+ * @par Description: API to compare server credential with local credential
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Cred structure
+ * @param[in]          Cred structure
+ * @param[out]
+ *
+ * @return                     ERROR_INTERNAL_OK on success
+ *                                             ERROR_AUTH_REJECTED, ERROR_INTERNAL_NOT_DEFINED on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType compare_cred(Cred *hdrCred, Cred *sessionCred);
+
+/**
+ * @par Description: API to convert AuthType
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, auth type
+ * @param[out]
+ *
+ * @return                     AUTH_TYPE_MD5, AUTH_TYPE_BASIC on success
+ *                                             AUTH_TYPE_UNKNOWN on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+AuthType convert_auth_type(char *authType);
+
+/**
+ * @par Description: API to convert FormatType
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, format type
+ * @param[out]
+ *
+ * @return                     FORMAT_TYPE_BASE64 on success
+ *                                             FORMAT_TYPE_UNKNOWN on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+FormatType convert_format_type(char *formatType);
+
+#endif /* SA_ELEMENTS_H_ */
diff --git a/include/ServiceAdapter/SA_Elements_Internal.h b/include/ServiceAdapter/SA_Elements_Internal.h
new file mode 100644 (file)
index 0000000..e9220ca
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Elements_Internal.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file that structure which is available in SA is defined
+ *                                                                                                     SyncHdr, SyncML, Cred, Chal, Item, Anchor, Location
+ */
+
+#ifndef SA_ELEMENTS_INTERNAL_H_
+#define SA_ELEMENTS_INTERNAL_H_
+
+#include "ServiceAdapter/SA_Define.h"
+
+typedef union ItemData {
+       char *data;
+       DevInf *devInf;
+} ItemData;
+
+struct  Chal {
+       FormatType format;
+       AuthType type;
+       char *nonce_plain;
+       unsigned int nonce_length;
+       char *nonce_b64;
+};
+
+struct  Item {
+       ItemDataType dataType;
+       ItemData private;
+       Location *source;
+       Location *target;
+       Anchor *anchor;
+
+       unsigned int size;              /* for data*/
+       char *contenttype;              /* for data*/
+       int moreData;                           /* for moredata*/
+};
+
+struct Anchor {
+       char *lastAnchor;                       /**< Last Anchor*/
+       char *nextAnchor;                       /**< Next Anchor*/
+};
+
+struct Location {
+       char *locURI;
+       char *locName;
+} ;
+
+struct  Cred {
+       FormatType format;
+       AuthType type;
+       char *data;
+       char *username;
+       char *password;
+} ;
+
+struct  SyncHdr {
+       char *sessionID;
+       ProtocolVersion version;
+       ProtocolType protocol;
+       Location *source;
+       Location *target;
+       Cred *cred;
+       char *responseURI;
+       int noResponse;
+       unsigned int messageID;
+
+       /*in meta element*/
+       unsigned int maxmsgsize;
+       unsigned int maxobjsize;
+} ;
+
+struct  SyncML {
+        SyncHdr *hdr;
+        GList *status;                 /**< containing  Status struct */
+        GList *commands;               /**< containing  Command struct */
+        int final;
+};
+
+
+#endif /* SA_ELEMENTS_INTERNAL_H_ */
diff --git a/include/ServiceAdapter/SA_Error.h b/include/ServiceAdapter/SA_Error.h
new file mode 100644 (file)
index 0000000..35ae7ee
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Error.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of Error is defined
+ */
+
+
+#ifndef SA_ERROR_H_
+#define SA_ERROR_H_
+
+typedef enum {
+       ERROR_UNKNOWN = 0,
+
+       /* Informational */
+       IN_PROGRESS = 101,
+
+       /* OK code */
+       /** No error */
+       NO_ERROR = 200,
+       /** Requested item was added */
+       ITEM_ADDED = 201,
+       /** Accepted for processing */
+       PROCESSING_ACCEPTED = 202,
+       /** Non-authoritative response */
+       NON_AUTHORITATIVE = 203,
+       /** No content */
+       NO_CONTENT = 204,
+       /** Reset content */
+       RESET_CONTENT = 205,
+       /** Partial content */
+       PARTIAL_CONTENT = 206,
+       /** Conflict resolved with merge */
+       CONFLICT_MERGE = 207,
+       /** Conflict resolved with client win */
+       CONFLICT_CLIENT_WIN = 208,
+       /** Conflict resolved with duplicate */
+       CONFLICT_DUPLICATE = 209,
+       /** Deleted without archiving */
+       DELETE_NO_ARCHIVE = 210,
+       /** Item not deleted (not found) */
+       DELETE_NOT_FOUND = 211,
+       /** Authentication accepted */
+       AUTH_ACCEPTED = 212,
+       /** Chunked item accepted */
+       CHUNK_ACCEPTED = 213,
+       /** Operation cancelled */
+       OPERATION_CANCELLED = 214,
+       /** Not executed */
+       NOT_EXECUTED = 215,
+       /** Atomic rollback ok */
+       ATOMIC_ROLLBACK_OK = 216,
+
+       /* Retry error */
+       ERROR_MULTIPLE_CHOICES = 300,
+       ERROR_MOVED_PERMANENTLY = 301,
+       ERROR_FOUND_RETRY = 302,
+       ERROR_SEE_OTHER_RETRY = 303,
+       ERROR_NOT_MODIFIED = 304,
+       ERROR_USE_PROXY = 305,
+
+       /* Errors */
+       ERROR_BAD_REQUEST = 400,                /* Bad Request*/
+       ERROR_AUTH_REJECTED = 401,              /* Unauthorized, Invalid Credentials*/
+       ERROR_PAYMENT_NEEDED = 402,             /* Payment need*/
+       ERROR_FORBIDDEN = 403,          /* Forbidden*/
+       ERROR_NOT_FOUND = 404,          /* Not found*/
+       ERROR_COMMAND_NOT_ALLOWED = 405,        /* Command not allowed*/
+       ERROR_UNSUPPORTED_FEATURE = 406,        /* Optional feature unsupported*/
+       ERROR_AUTH_REQUIRED = 407,              /* Authentication required, Missing Credentials*/
+       ERROR_SIZE_REQUIRED = 411,
+       ERROR_REQUESTED_SIZE_TOO_BIG = 416,
+       ERROR_RETRY_LATER = 417,                /* Retry later*/
+       ERROR_ALREADY_EXISTS = 418,             /* Put or Add failed because item already exists*/
+       ERROR_SIZE_MISMATCH = 424,              /* Size mismatch*/
+
+       /* Standard errors */
+       ERROR_GENERIC = 500,
+       ERROR_NOT_IMPLEMENTED = 501,
+       ERROR_SERVICE_UNAVAILABLE = 503,
+       ERROR_REQUIRE_REFRESH = 508,
+       ERROR_SERVER_FAILURE = 511,
+
+} OMA_StatusType;
+
+typedef enum {
+
+       /* Internal errors - never ever send this via SyncML */
+       SA_ERROR_UNKNOWN = 0,
+       SA_INTERNAL_OK = 1,
+       SA_INTERNAL_ERROR,
+       SA_INTERNAL_BINDER_ERROR ,
+       SA_INTERNAL_TIMEOUT ,
+       SA_INTERNAL_NOT_FOUND ,
+       SA_INTERNAL_MISCONFIGURATION ,
+       SA_INTERNAL_NO_MEMORY ,
+       SA_INTERNAL_NOT_DEFINED ,
+       SA_INTERNAL_CONNECTION_ERROR ,
+       SA_INTERNAL_DA_ERROR ,
+       SA_INTERNAL_CANCEL ,
+       SA_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER ,
+       SA_INTERNAL_BUSY_SIGNALING ,
+       SA_INTERNAL_SERVER_FAILURE ,
+       SA_INTERNAL_SERVER_ERROR ,
+       SA_INTERNAL_AUTHENTICATION_ERROR  ,
+} SA_ErrorType;
+
+
+#endif /* SA_ERROR_H_ */
diff --git a/include/ServiceAdapter/SA_Session.h b/include/ServiceAdapter/SA_Session.h
new file mode 100644 (file)
index 0000000..461797c
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Session.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of Session structure
+ */
+
+#ifndef SA_SESSION_H_
+#define SA_SESSION_H_
+
+#include "ServiceAdapter/SA_Define.h"
+
+/**
+ * @par Description: API to create Session structure
+ * This API can be used to create Session structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, protocol version(VERSION_UNKNOWN, VERSION_10, VERSION_11, VERSION_12);
+ * @param[in]          enum type, protocol type(PROTOCOL_TYPE_UNKNOWN, PROTOCOL_TYPE_DS)
+ * @param[in]          int type, account id
+ * @param[in]          int type, session id
+ * @param[in]          string type, source uri(server ip)
+ * @param[in]          string type, target uri(client identifer)
+ * @param[out]         Session structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_session(ProtocolVersion protocolVersion, ProtocolType protocolType,
+                               int accountId, char *sessID,  char *source, char *target, Session **pSession);
+
+/**
+ * @par Description: API to free Session structure
+ * This API can be used to free Session structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void free_session(Session *session);
+
+/**
+ * @par Description: API to set Cred structure in Session structure
+ * This API can be used to set Cred structure in Session structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          Cred structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_session_cred(Session *session, Cred *cred);
+
+/**
+ * @par Description: API to set DevInf structure in Session structure
+ * This API can be used to set DevInf structure in Session structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ * @param[in]          DevInf structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void set_session_devinf(Session *session, DevInf *devInf);
+
+/**
+ * @par Description: API to create PendingStatus structure
+ * This API can be used to set DevInf structure in Session structure
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          unsigned int type, msg id
+ * @param[in]          unsigned int type, cmd id
+ * @param[out]         PendingStatus structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_pending_status(unsigned int msgID, unsigned int cmdID, PendingStatus **pPendingStatus);
+
+/**
+ * @par Description: API to process SyncHdr structure from server
+ * This API manage responseURI
+ *                             set server info in Session structure
+ *                             check header credential
+ *                             create Status structure for header
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          session structure
+ * @param[in]          SyncHdr structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType receive_header(Session *session, SyncHdr *header);
+
+/**
+ * @par Description: API to process list of Status structure from server
+ * This API check credential status
+ *                             process Status structure for each type
+ *                             create AppliedStatus structure for passing to ServiceEngine
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          session structure
+ * @param[in]          GList type, list of Status structure
+ * @param[out]         GList type, list of AppliedStatus structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_ERROR, ERROR_SERVER_FAILURE, ERROR_INTERNAL_BUSY_SIGNALING on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType receive_statuses(Session *session, GList *receiveStatus, GList **returnStatus);
+
+/**
+ * @par Description: API to process list of Command structure from server
+ * This API check credential status
+ *                             process Command structure for each type
+ *                             create ChangedDatastore structure for passing to ServiceEngine
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          session structure
+ * @param[in]          GList type, list of Command structure
+ * @param[in]          whether auto configure or not
+ * @param[out]         GList type, list of ChangedDatastore structure
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_ERROR, ERROR_INTERNAL_NO_MEMORY, ERROR_INTERNAL_NOT_DEFINED on error
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType receive_commands(Session *session, GList *receiveCommand, bool autoConfig, GList **returnDatastore);
+
+
+/**
+ * @par Description: API to reset cmd id(1) in session
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          Session structure
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void reset_cmdID_session(Session *session);
+
+
+#endif /* SE_SESSION_H_ */
diff --git a/include/ServiceAdapter/SA_Session_Internal.h b/include/ServiceAdapter/SA_Session_Internal.h
new file mode 100644 (file)
index 0000000..c0b17fb
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Session_Internal.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of session structure is defined
+ *                                                                                                     Session, PendingStatus
+ */
+
+#ifndef SA_SESSION_INTERNAL_H_
+#define SA_SESSION_INTERNAL_H_
+
+#include "ServiceAdapter/SA_Define.h"
+
+struct Session {
+       ProtocolVersion protocolVersion;
+       ProtocolType protocolType;
+
+       char *sessionID;
+       unsigned int msgID;
+       unsigned int lastRecievedMsgID;
+       unsigned int cmdID ;
+       int isSendingfinal;
+       int isReceivingFinal;
+
+       GList *status;                                                                  /*status to return to server*/
+       GList *tempStatus;                                                      /*temp status for sync add, replace, delete command(it doesnot have data element value)*/
+       Location *target;
+       Location *source;
+       Location *orgTarget;
+
+       unsigned int sourceMaxMsgSize;
+       unsigned int sourceMaxObjSize;
+
+       unsigned int targetMaxMsgSize;
+       unsigned int targetMaxObjSize;
+
+       Cred *cred;                                                                             /*account info*/
+       Chal *chal;                                                                             /*chal from server*/
+
+       DevInf *devInf;                                                                 /*client devinf*/
+       DevInf *remoteDevInf;                                           /*server devinf*/
+
+       PkgStatus pkgStatus;                                                    /*for status*/
+
+       Command *pLargeObjCmd;                                  /*for incomming large Command*/
+
+       GList *mapCommand       ;                                               /*containing map command that has sent to server(this is used to for delete map item from mapping table)*/
+
+       GList *alertCommand;                                            /*containing alert command that have to send to server*/
+
+       GList *resultsCommand;                                  /*containing results command*/
+
+       PendingStatus *largeObj;                                /*for outgoing large command*/
+
+
+       int hasOpend;
+       unsigned int NACI_sessionID;
+
+       int accountId;
+
+};
+
+
+struct PendingStatus {
+       unsigned int cmdID;
+       unsigned int msgID;
+};
+#endif /* SA_SESSION_INTERNAL_H_ */
diff --git a/include/ServiceAdapter/SA_Util.h b/include/ServiceAdapter/SA_Util.h
new file mode 100644 (file)
index 0000000..ce1be25
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Util.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface for utility function in SA
+ */
+
+#ifndef SA_UTIL_H_
+#define SA_UTIL_H_
+
+#include "ServiceAdapter/SA_Define.h"
+
+/**
+ * @par Description: API to put command into GList
+ * This API can be used to put structure into GList
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          GList type, first index of list
+ * @param[in]          GList type, last index of list
+ * @param[in]          void pointer type, structure to put in the list
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void put_into_list(GList **commands, GList **commands_last, void *pCommand);
+
+
+/**
+ * @par Description: API to create credential string
+ * This API can be used to create credential string
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, type of authentication(AUTH_TYPE_BASIC , AUTH_TYPE_MD5...)
+ * @param[in]          string type, id
+ * @param[in]          string type, password
+ * @param[in]          string type, nonce
+ * @param[in]          unsigned int type, size of nonce
+ * @param[out]         string type, credential
+ *
+ * @return                             ERROR_INTERNAL_OK on success
+ *                                                     ERROR_INTERNAL_NO_MEMORY on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SA_ErrorType create_cred_string(AuthType type,  const char *username,  const char *password,
+               const char *nonce, unsigned int nonce_size, char **pCred);
+
+/**
+ *  @brief                             write xml to file(for debugging)
+ *  @param[in]         string to write
+ *  @param[in]         path
+ */
+void  set_xml_to_file(char *xml, const char *path);
+
+
+#endif /* SA_UTIL_H_ */
diff --git a/include/ServiceEngine/SE_Account.h b/include/ServiceEngine/SE_Account.h
new file mode 100644 (file)
index 0000000..c2c8374
--- /dev/null
@@ -0,0 +1,346 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Account.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of account
+ */
+
+#ifndef SE_ACCOUNT_H_
+#define SE_ACCOUNT_H_
+
+#include <glib.h>
+#include <stdbool.h>
+#include "Common/Common_Define.h"
+
+/**
+ * @par Description: API to add or edit profile
+ * This API can be used to add or edit profile from vconf
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(identify profile in UI)
+ * @param[in]          int type, whether add or edit
+ *
+ * @return                             1 on success
+ *                                                     0 on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+int update_all_config(char *profile,  bool isAdd, int *accountId);
+
+/**
+ * @par Description: API to add profile from csc
+ * This API can be used to add profile from csc(vconf)
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, index of profile
+ *
+ * @return                             1 on success
+ *                                                     0 on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+int add_profile_csc(int index);
+
+/**
+ * @par Description: API to add profile API
+ * This API can be used to add profile
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profile name
+ * @param[in]          string type, server ip
+ * @param[in]          string type, id
+ * @param[in]          string type, password
+ * @param[in]          GList type, list of resource_cp structure
+ * @param[out]         int type, account id
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool add_profile_cp(char *profileName, char *addr, char *id, char *password, GList *categories, int *accountId);
+
+
+/**
+ * @par Description: API to add profile API
+ * This API can be used to add profile
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(identify profile in UI)
+ * @param[in]          string type, profile name
+ * @param[in]          string type, server ip
+ * @param[in]          string type, id
+ * @param[in]          string type, password
+ * @param[in]          string type, sync mode
+ * @param[in]          string type, sync type
+ * @param[in]          string type, interval(for periodic)
+ * @param[in]          GList type, list of sync_category structure
+ * @param[out]         int type, account id
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool add_profile(char *profileDirName, char *profileName, char *addr, char *id,
+               char *password, char *syncMode, char *syncType,
+               char *interval, GList *categories, int *accountId);
+
+/**
+ * @par Description: API to edit profile API
+ * This API can be used to edit profile
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          string type, profile name
+ * @param[in]          string type, server ip
+ * @param[in]          string type, id
+ * @param[in]          string type, password
+ * @param[in]          string type, sync mode
+ * @param[in]          string type, sync type
+ * @param[in]          string type, interval(for periodic)
+ * @param[in]          GList type, list of sync_category structure
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool edit_profile(int accountId, char *profileName, char *addr, char *id,
+               char *password, char *syncMode, char *syncType, char *interval, GList *categories);
+
+
+/**
+ * @par Description: API to delete profile API
+ * This API can be used to delete profile
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          GList type, list of account id
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool delete_profiles(GList *profiles);
+
+/**
+ * @par Description: API to get profile directory name of synchronizing account
+ * This API can be used to get profile directory name
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[out]         string type, profileDirName(identify profile in UI)
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_synchronising_profile(char **profile);
+
+
+/**
+ * @par Description: API to add profile for call log sync
+ * This API can be used to add profile
+ * This API is part of API for call log sync
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[out]         int type, accountId
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool add_profile_calllog(int *accountId);
+
+
+/**
+ * @par Description: API to delete profile for call log sync
+ * This API can be used to delete profile
+ * This API is part of API for call log sync
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool delete_profile_calllog();
+
+
+/**
+ * @par Description: API to delete profile
+ * This API can be used to delete profile
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool delete_profile(char *access_name);
+
+#endif /* SE_ACCOUNT_H_ */
diff --git a/include/ServiceEngine/SE_AutoConfig.h b/include/ServiceEngine/SE_AutoConfig.h
new file mode 100644 (file)
index 0000000..2e1089d
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_AutoConfig.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of Auto Configuration
+ */
+
+#ifndef SE_AUTOCONFIG_H_
+#define SE_AUTOCONFIG_H_
+
+#include <stdbool.h>
+#include <glib.h>
+#include <stdlib.h>
+
+/**
+ * @par Description: API to process auto configure
+ * This API can be used to process auto configure using inputed information by UI
+ * This API uses Notification API which for notifying auto configure result to UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(identify profile in UI)
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+/*TODO have to be removed after removing vconf*/
+bool autoconfigure_from_vconf(char *profile);
+
+/**
+ * @par Description: API to process auto configure
+ * This API can be used to process auto configure using inputed information by UI
+ * This API uses Notification API which for notifying auto configure result to UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(identify profile in UI)
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+int main()
+{
+       bool ret = 0;
+       ret = autoconfigure(profildDirName, addr, id, password);
+       if (ret == true)
+       {
+               //synchronization success
+       }
+       else
+       {
+               //synchronization fail
+       }
+
+       return 0;
+}
+ * @endcode
+ */
+bool autoconfigure(char *profildDirName, char *addr, char *id, char *password);
+
+#endif /* SE_AUTOCONFIG_H_ */
diff --git a/include/ServiceEngine/SE_Common.h b/include/ServiceEngine/SE_Common.h
new file mode 100644 (file)
index 0000000..af6def1
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Common.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of enumeration and define used in SE
+ */
+
+#ifndef SE_COMMON_H_
+#define SE_COMMON_H_
+
+#define DEFINE_SYNC_PROGRESS_NONE "PROGRESS_NONE"
+#define DEFINE_SYNC_INIT "INIT"
+#define DEFINE_SYNC_CONNECTING "CONNECTING"
+#define DEFINE_SYNC_AUTHENTICATED "AUTHENTICATED"
+#define DEFINE_SYNC_DONE "DONE"
+#define DEFINE_SYNC_ERROR "ERROR"
+
+#define DEFINE_ERROR_NONE "ERROR_NONE"
+#define DEFINE_ERROR_CONNECTION "CONNECTION"
+#define DEFINE_ERROR_SYNCHDR "SYNCHDR"
+#define DEFINE_ERROR_INTERNAL "INTERNAL"
+#define DEFINE_ERROR_SUSPENDED "SUSPENDED"
+#define DEFINE_ERROR_DB "DB"
+#define DEFINE_ERROR_ABORT "ABORT"
+#define DEFINE_ERROR_SERVER "SERVER"
+#define DEFINE_ERROR_MEMORY_FULL "MEMORY_FULL"
+#define DEFINE_ERROR_AUTHENTICATE "AUTHENTICATE"
+#define DEFINE_ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER "AUTOCONFIG_NOT_SUPPORT_BY_SERVER"
+
+#define        DEFINE_PROGRESS_NONE "PROGRESS_NONE"
+#define DEFINE_PROGRESS_SUCCESS "PROGRESS_SUCCESS"
+#define DEFINE_FAILED_DB "FAILED_DB"
+#define DEFINE_FAILED_DB_FORBIDDEN "FAILED_DB_FORBIDDEN"
+#define        DEFINE_FAILED_DB_ITEM "FAILED_DB_ITEM"
+#define        DEFINE_FAILED_DB_CONFIG "FAILED_DB_CONFIG"
+#define        DEFINE_FAILED_DB_DEVICEFULL "FAILED_DB_DEVICEFULL"
+
+#define DEFINE_NOOP "NOOP"
+#define        DEFINE_ADD "ADD"
+#define        DEFINE_DELETE "DELETE"
+#define        DEFINE_MOVE "MOVE"
+#define        DEFINE_COPY "COPY"
+#define        DEFINE_REPLACE "REPLACE"
+
+#define DEFINE_DBSYNC_SUCCESS "success"
+#define DEFINE_DBSYNC_STOP "stop"
+#define DEFINE_DBSYNC_FAIL "fail"
+#define DEFINE_DBSYNC_NO "No"
+
+typedef enum {
+       PROGRESS_NONE = 0,
+       PROGRESS_INIT = 1,
+       PROGRESS_CONNECTING = 2,
+       PROGRESS_AUTHENTICATED = 3,
+       PROGRESS_DONE = 4,
+       PROGRESS_ERROR = 5
+} SyncProgress;
+
+typedef enum {
+       ERROR_NONE = 0,
+       ERROR_CONNECTION = 1,
+       ERROR_SYNCHDR = 2,
+       ERROR_INTERNAL = 3,
+       ERROR_SUSPENDED = 4,
+       ERROR_DB = 5,
+       ERROR_ABORT = 6,
+       ERROR_SERVER = 7,
+       ERROR_MEMORY_FULL = 8,
+       ERROR_AUTHENTICATE = 9,
+       ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER = 10
+} SyncError;
+
+typedef enum {
+       SYNC_PROGRESS_NONE = 0,
+       SYNC_PROGRESS_SUCCESS,
+       SYNC_FAILED_DB,
+       SYNC_FAILED_DB_FORBIDDEN,
+       SYNC_FAILED_DB_ITEM,
+       SYNC_FAILED_DB_CONFIG,
+       SYNC_FAILED_DB_DEVICEFULL
+} SyncProgressStatus;
+
+typedef enum {
+       OPERATION_NOOP = 0,
+       OPERATION_ADD,
+       OPERATION_DELETE,
+       OPERATION_MOVE,
+       OPERATION_COPY,
+       OPERATION_REPLACE
+} OperationType;
+
+typedef enum {
+       COMMAND_RESULT_INIT                                                                                             = 0,
+       COMMAND_RESULT_OK                                                                                                       = 200,  /*[R] OK exception*/
+       COMMAND_RESULT_ADDED                                                                                    = 201,  /*[AR] Item added exception*/
+       COMMAND_RESULT_DELETE_PARTIAL                                                           = 206,  /*[D] Partial content exception condition*/
+       COMMAND_RESULT_DELETE_WITHOUT_ARCHIVE                           = 210,  /*[D] Delete without archive exception*/
+       COMMAND_RESULT_NOT_EXIST                                                                                = 211,  /*[D] Item not deleted exception*/
+       COMMAND_RESULT_UNAUTHRIZED                                                              = 401,  /*[ARD] Unauthorized exception*/
+       COMMAND_RESULT_AUTHENTICATION_REQUIRED                  = 407,  /*[ARD] Authentication required exception*/
+       COMMAND_RESULT_INCOMPLETE                                                                       = 412,  /*[D] Incomplete command exception*/
+       COMMAND_RESULT_UNSUPPORTED_TYPE                                         = 415,  /*[A] Unsupported media type or format exception*/
+       COMMAND_RESULT_ALREADY_EXIST                                                            = 418,  /*[A] Already exists exception*/
+       COMMAND_RESULT_DEVICE_FULL                                                                      = 420,  /*[AR] Device full exception*/
+       COMMAND_RESULT_PARTIAL_REPLACE_NOT_ACCEPTED     = 426,  /*[R] Partial item not accepted*/
+       COMMAND_RESULT_NOT_EMPTY                                                                        = 427,  /*[D] Item not empty*/
+       COMMAND_RESULT_COMMAND_FAIL                                                             = 500   /*[ARD] Command failed exception*/
+} CommandResult;
+
+
+#endif /* SE_COMMON_H_ */
diff --git a/include/ServiceEngine/SE_Error.h b/include/ServiceEngine/SE_Error.h
new file mode 100644 (file)
index 0000000..53cddd7
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Error.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of Error is defined
+ */
+
+#ifndef SE_ERROR_H_
+#define SE_ERROR_H_
+
+typedef enum {
+       ERROR_UNKNOWN = 0,
+       SE_INTERNAL_OK = 1,
+       SE_INTERNAL_ERROR = 2,
+       SE_INTERNAL_NO_MEMORY  = 3,
+       SE_INTERNAL_NOT_DEFINED = 4,
+       SE_INTERNAL_DA_ERROR = 5,
+       SE_INTERNAL_EVENT_ERROR = 6,
+       SE_INTERNAL_ENGINE_CONTROLER_ERROR = 7,
+       SE_INTERNAL_SCHEDULER_ERROR = 8,
+       SE_INTERNAL_SA_ERROR = 9,
+       SE_INTERNAL_MISCONFIGURATION = 10,
+       SE_INTERNAL_CANCEL = 11,
+
+} SE_ErrorType;
+
+#endif /* SE_ERROR_H_ */
diff --git a/include/ServiceEngine/SE_Notification.h b/include/ServiceEngine/SE_Notification.h
new file mode 100644 (file)
index 0000000..a4bbf26
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Notification.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of notification to UI
+ */
+
+#ifndef SE_NOTIFICATION_H_
+#define SE_NOTIFICATION_H_
+
+#include <glib.h>
+#include "ServiceEngine/SE_Error.h"
+
+/**
+ * @par Description: API to notify auto configure results to UI
+ * This API can be used to notify auto configure results(list of candidate of datastore name)
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(identify profile in UI)
+ * @param[in]          GList type, double pointer
+ *
+ * @return                             SE_INTERNAL_OK on success
+ *                                                     SE_INTERNAL_NOT_DEFINED, SE_INTERNAL_NO_MEMORY, SE_INTERNAL_EVENT_ERROR on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType send_noti_auto_configure(char *profileDirName, GList *configure);
+
+/**
+ * @par Description: API to notify sync status to UI
+ * This API can be used to notify sync status
+ * If there is a any profile which is synchronizing pass syncDirName, but not any profiles pass NULL
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(identify profile in UI)
+ *
+ * @return                             SE_INTERNAL_OK on success
+ *                                                     SE_INTERNAL_NO_MEMORY, SE_INTERNAL_EVENT_ERROR on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType send_noti_sync_status(char *profileDirName);
+
+/**
+ * @par Description: API to notify session process to UI
+ * This API can be used to notify session process
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(identify profile in UI)
+ * @param[in]          string type, progress(DEFINE_SYNC_PROGRESS_NONE,
+ *                                                                     DEFINE_SYNC_INIT, DEFINE_SYNC_CONNECTING, DEFINE_SYNC_AUTHENTICATED,
+ *                                                                     DEFINE_SYNC_DONE, DEFINE_SYNC_ERROR)
+ * @param[in]          string type, error(DEFINE_ERROR_NONE, DEFINE_ERROR_CONNECTION, DEFINE_ERROR_SYNCHDR,
+ *                                                                     DEFINE_ERROR_INTERNAL, DEFINE_ERROR_SUSPENDED, DEFINE_ERROR_DB, DEFINE_ERROR_ABORT,
+ *                                                                     DEFINE_ERROR_SERVER, DEFINE_ERROR_MEMORY_FULL, DEFINE_ERROR_AUTHENTICATE,
+ *                                                                     DEFINE_ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER)
+ *
+ * @return                             SE_INTERNAL_OK on success
+ *                                                     SE_INTERNAL_NOT_DEFINED, SE_INTERNAL_NO_MEMORY, SE_INTERNAL_EVENT_ERROR on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType send_noti_session_process(char *profileDirName, char *progress, char *error);
+
+/**
+ * @par Description: API to notify process update to UI
+ * This API can be used to notify process update
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, profileDirName(identify profile in UI)
+ * @param[in]          string type, datastore name
+ * @param[in]          string type, progressStatus(DEFINE_PROGRESS_NONE, DEFINE_PROGRESS_SUCCESS, DEFINE_FAILED_DB,
+ *                                                                     DEFINE_FAILED_DB_FORBIDDEN, DEFINE_FAILED_DB_ITEM, DEFINE_FAILED_DB_CONFIG, DEFINE_FAILED_DB_DEVICEFULL)
+ * @param[in]          string type, operationType(DEFINE_NOOP, DEFINE_ADD, DEFINE_DELETE, DEFINE_MOVE, DEFINE_COPY, DEFINE_REPLACE)
+ * @param[in]          int type, whether from server or from client
+ * @param[in]          int type, total number per operation
+ * @param[in]          int type, synced item number per operation
+ * @param[in]          int type, total number per db
+ * @param[in]          int type, synced item number per db
+ *
+ * @return                             SE_INTERNAL_OK on success
+ *                                                     SE_INTERNAL_NOT_DEFINED, SE_INTERNAL_NO_MEMORY, SE_INTERNAL_EVENT_ERROR on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType send_noti_process_update(char *profileDirName, char *uri, char *progressStatus,
+               char *operationType, int isFromServer, int totalPerOperation, int syncedPerOperation, int totalPerDb, int syncedPerDb);
+
+#endif /* SE_NOTIFICATION_H_ */
diff --git a/include/ServiceEngine/SE_Storage.h b/include/ServiceEngine/SE_Storage.h
new file mode 100644 (file)
index 0000000..7d5c7b0
--- /dev/null
@@ -0,0 +1,336 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Storage.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface which saves and gets sync results
+ */
+
+#ifndef SE_STORAGE_H_
+#define SE_STORAGE_H_
+
+
+#include "Common/Common_Define.h"
+#include "ServiceEngine/SE_Error.h"
+
+/**
+ * @par Description: API to save sync type, sync result , last sync time(each datastore)
+ * This API can be used to save sync type, sync result , last sync time at the end of synchronization process
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          enum type, AlertType
+ * @param[in]          enum type, SyncSessionResult
+ * @param[in]          int time, last sync time
+ *
+ * @return                             SE_INTERNAL_OK on success
+ *                                                     SE_INTERNAL_DA_ERROR on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType write_profile_data(int accountId, AlertType alertType, SyncSessionResult syncSessionResult, int lastSessionTime);
+
+
+/**
+ * @par Description: API to save sync statistics(each datastore)
+ * This API can be used to save statistics at the end of synchronization process
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          int type, content type(TYPE_CONTACT,  TYPE_CALENDAR, TYPE_MEMO)
+ * @param[in]          bool type whether from server or from client
+ * @param[in]          SyncResult structure
+ *
+ * @return                             SE_INTERNAL_OK on success
+ *                                                     SE_INTERNAL_DA_ERROR on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType write_sync_statistics(int accountId, int content_type, bool isFromServer, SyncResult *pSyncResult);
+
+
+/**
+ * @par Description: API to save sync result(each datastore)
+ * This API can be used to save sync result at the end of synchronization process
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          enum type, AlertType
+ * @param[in]          int type, content type(TYPE_CONTACT,  TYPE_CALENDAR, TYPE_MEMO)
+ * @param[in]          int type, last sync time
+ * @param[in]          SyncResult structure, client
+ * @param[in]          SyncResult structure, server
+ *
+ * @return                             SE_INTERNAL_OK on success
+ *                                                     SE_INTERNAL_DA_ERROR on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType write_sync_resource_info(int accountId, AlertType alertType,
+               int content_type , int lastSessionTime, SyncResult *clientSyncResult, SyncResult *serverSyncResult);
+
+
+/**
+ * @par Description: API to get profile name from config_tbl
+ * This API can be used to get profile name
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[out]         string type, profile name
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_profile_name(int accountId, char **profileName);
+
+/**
+ * @par Description: API to get profile server information(server ip, id, password) from config_tbl
+ * This API can be used to get server ip, id, password
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[out]         string type, server ip
+ * @param[out]         string type, id
+ * @param[out]         string type, password
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_profile_server_info(int accountId, char **addr, char **id, char **password);
+
+/**
+ * @par Description: API to get profile sync mode, type, interval from config_tbl
+ * This API can be used to get sync mode, sync type, interval
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[out]         string type, sync mode
+ * @param[out]         string type, sync type
+ * @param[out]         string type, interval
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_profile_sync_mode(int accountId, char **syncMode, char **syncType, char **interval);
+
+/**
+ * @par Description: API to get profile datastore information(enable, source uri, target uri, id, password) from config_tbl
+ * This API can be used to get enable, source uri, target uri, id, password
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          int type, content type(TYPE_CONTACT,  TYPE_CALENDAR, TYPE_MEMO)
+ * @param[out]         string type, enabled
+ * @param[out]         string type, source uri
+ * @param[out]         string type, target uri
+ * @param[out]         string type, id
+ * @param[out]         string type, password
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_profile_sync_category(int accountId, int contentType,
+               int *enabled, char **srcURI, char **tgtURI, char **id, char **password);
+
+/**
+ * @par Description: API to get profile sync results(sync status, sync time) from config_tbl
+ * This API can be used to get profile sync results(sync status, sync time)
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[out]         int type, lastSessionStatus
+ * @param[out]         int type, lastSessionTime
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_last_session_info(int accountId, int *lastSessionStatus, int *lastSessionTime);
+
+
+/**
+ * @par Description: API to get profile sync statistics for each content type from config_tbl
+ * This API can be used to get profile sync statistics for each content type
+ * This API is part of API for UI
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          int type, content type(TYPE_CONTACT,  TYPE_CALENDAR, TYPE_MEMO)
+ * @param[out]         string type, sync result(success, fail, stop)
+ * @param[out]         int type, sync time
+ * @param[out]         int type, total items(server to client)
+ * @param[out]         int type, add items(server to client)
+ * @param[out]         int type, delete items(server to client)
+ * @param[out]         int type, replace items(server to client)
+ * @param[out]         int type, total items(client to server)
+ * @param[out]         int type, add items(client to server)
+ * @param[out]         int type, delete items(client to server)
+ * @param[out]         int type, replace items(client to server)
+ *
+ * @return                             true on success
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool get_profile_statistics(int accountId, int contentType, char **dbSynced, int *lastSessionTime,
+               int *server2Client_Total, int *server2Client_NrOfAdd, int *server2Client_NrOfDelete, int *server2Client_NrOfReplace,
+               int *client2Server_Total, int *client2Server_NrOfAdd, int *client2Server_NrOfDelete, int *client2Server_NrOfReplace);
+
+
+#endif /* SE_STORAGE_H_ */
diff --git a/include/ServiceEngine/SE_Sync.h b/include/ServiceEngine/SE_Sync.h
new file mode 100644 (file)
index 0000000..45f5e44
--- /dev/null
@@ -0,0 +1,237 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Sync.h
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the header file of interface of Service Engine
+ */
+
+#ifndef SYNCENGINE_H_
+#define SYNCENGINE_H_
+
+#include <stdbool.h>
+#include "Common/Common_Define_Internal.h"
+#include "ServiceEngine/SE_Common.h"
+#include "Framework/SAN_parser/PM_SanParser.h"
+#include "ServiceEngine/SE_Error.h"
+
+/**
+ * @par Description: API to process synchronization request
+ * This API can be used to process synchronization by predefined profile information
+ * This API uses Notification and Storage API which for notifying synchronization status to UI and saving sync results to Agent DB
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ * @param[in]          string type, sync mode(manual, push(SAN), periodic)
+ * @param[in]          SanPackage structure, only for SAN sync mode
+
+ * @return                             true on success, false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+int main()
+{
+       bool ret = 0;
+       ret = synchronize(accountId, syncMode, pSanPackage);
+       if (ret == true)
+       {
+               //synchronization success
+       }
+       else
+       {
+               //synchronization fail
+       }
+
+       return 0;
+}
+ * @endcode
+ */
+bool synchronize(int accountId, char *syncMode, SanPackage *pSanPackage);
+
+
+/**
+ * @par Description: API to convert SyncProgress and SyncError from common error code
+ * This API can be used to convert string to be used to notify to UI for sync results
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, Common_ErrorType
+ * @param[out]         enum type, SyncProgress
+ * @param[out]         enum type, SyncError
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void convert_common_errorcode(Common_ErrorType errorCode, SyncProgress *process, SyncError *error);
+
+
+/**
+ * @par Description: API to convert SyncProgress and SyncError from engine error code
+ * This API can be used to convert string to be used to notify to UI for sync results
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          enum type, SE_ErrorType
+ * @param[out]         enum type, SyncProgress
+ * @param[out]         enum type, SyncError
+ *
+ * @return
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+void convert_engine_errorcode(SE_ErrorType err, SyncProgress *process, SyncError *error);
+
+
+/**
+ * @par Description: API to notify sync results for specific profile to UI
+ * This API can be used to notify sync results(SyncProgress, SyncError) to UI
+ * This API uses Notification which for notification module to send data using IPC
+ *
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          string type, syncDirName(identify profile in UI)
+ * @param[in]          enum type, SyncProgress
+ * @param[in]          enum type, SyncError
+ *
+ * @return                     SE_INTERNAL_OK on success
+ *                                             SE_INTERNAL_NOT_DEFINED, SE_INTERNAL_NO_MEMORY, SE_INTERNAL_EVENT_ERROR  on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType session_process(char *profileDirName, SyncProgress process, SyncError error);
+
+
+/**
+ * @par Description: API to reset all synchronizing profiles(off) & construct item_tbl from service for in case
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ *
+ * @return                     SE_INTERNAL_OK on success
+ *                                             SE_INTERNAL_DA_ERROR  on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+SE_ErrorType reset_synchronizing_profiles();
+
+
+/**
+ * @par Description: API to refresh from service for all contents type
+ *
+ * @par Purpose:
+ * @par Typical use case:
+ * @par Method of function operation:
+ * @par Important notes:
+ * @param[in]          int type, account id
+ *
+ * @return                             true on success,
+ *                                                     false on error
+ *
+ * @par Errors:
+ *
+ * @pre None.
+ * @post
+ * @see
+ * @remarks None.
+ *
+ * @par Sample Code:
+ * @code
+ * @endcode
+ */
+bool refresh_from_service_all(int accountId);
+
+
+/*FIXME cancel request to NA */
+/*SE_ErrorType cancel_sync_request();*/
+
+#endif /* SYNCENGINE_H_ */
diff --git a/main/main.c b/main/main.c
new file mode 100644 (file)
index 0000000..2763557
--- /dev/null
@@ -0,0 +1,342 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @main.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of main function
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "agent-framework/Initialization/initialize.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/PlatformMonitor/EXT_PMCI_Struct.h"
+#include "agent-framework/PlatformMonitor/EXT_PMCI.h"
+#include "agent-framework/FSAPI/FSAPI_operation.h"
+#include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
+#include "Framework/Event/OMA_DS_Event_Handler.h"
+#include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
+#include "Common/CscKeys.h"
+#include "Common/Common_Define_Internal.h"
+#include "Common/Common_Vconf.h"
+#include "ServiceEngine/SE_Account.h"
+
+#define LOG_TAG        "OMA_DS_MAIN"
+
+static void __request_reset_synchronizing_profiles();
+static void __check_csc();
+static void __update_csc();
+
+int main()
+{
+       FW_LOGV("start");
+
+       EVENT_ERROR error  = EVENT_SUCCESS;
+
+       INIT_ERROR init_error = Init_Framework("/opt/data/oma-ds/omads_fw_config.xml");
+       if (init_error != INIT_SUCCESS) {
+               FW_LOGE("Failed to Init_Framework() : %d", init_error);
+       } else {
+               FW_LOGV("done init_Framework");
+       }
+
+       /*TODO have to be removed after removing vconf*/
+       task_spec_t *pAddAccountTaskSpec = make_add_account_task();
+       task_spec_t *pEditAccountTaskSpec = make_edit_account_task();
+       /*task_spec_t *pDeleteAccountTaskSpec = make_delete_account_task();*/
+       task_spec_t *pAutoConfTaskSpec = make_autoconfigure_task();
+
+
+       task_spec_t *pSyncTaskSpec = make_synchronize_task();
+       /*task_spec_t *pAddProfileTaskSpec = make_add_profile_task();*/
+       /*task_spec_t *pEditProfileTaskSpec = make_edit_profile_task();*/
+       task_spec_t *pDeleteProfileTaskSpec = make_delete_profile_task();
+       /*task_spec_t *pAutoConfTaskSpec = make_auto_configure_task();*/
+       task_spec_t *pSyncStatusTaskSpec = make_sync_status_task();
+       task_spec_t *pGetProfileNameTaskSpec = make_get_profile_name_task();
+       task_spec_t *pGetProfileServerInfoTaskSpec = make_get_profile_server_info_task();
+       task_spec_t *pGetProfileSyncModeTaskSpec = make_get_profile_sync_mode_task();
+       task_spec_t *pGetProfileSyncCategoryTaskSpec = make_get_profile_sync_category_task();
+       task_spec_t *pGetProfileLastSessionTaskSpec = make_get_profile_last_session_task();
+       task_spec_t *pGetProfileStatisticsTaskSpec = make_get_profile_statistics_task();
+       task_spec_t *pResetSynchronizingProfilesTaskSpec = make_reset_synchronizing_profiles_task();
+       task_spec_t *pAddProfileCPTaskSpec = make_add_profile_cp_task();
+       task_spec_t *pRefreshFromServiceTaskSpec = make_refresh_from_service_task();
+
+       /*FIXME cancel request to NA */
+       /*task_spec_t *pCancelSyncRequestTaskSpec = make_cancel_sync_request();*/
+
+
+
+       /*TODO have to be removed after removing vconf*/
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_ACCOUNT,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_ADD_ACCOUNT,
+                                                                                                               pAddAccountTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_EDIT_ACCOUNT,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_ACCOUNT,
+                                                                                                               pEditAccountTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_AUTOCONFIGURE,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_AUTOCONFIGURE,
+                                                                                                                       pAutoConfTaskSpec, NULL);
+/*******************************************************/
+
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_REQUEST,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_REQUEST,
+                                                                                                                       pSyncTaskSpec, NULL);
+
+       /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE,
+                                                                                                               pAddProfileTaskSpec, NULL);*/
+
+       /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_PROFILE,
+                                                                                                               pEditProfileTaskSpec, NULL);*/
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_DELETE_PROFILE,
+                                                                                                               pDeleteProfileTaskSpec, NULL);
+
+
+       /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_AUTO_CONFIGURE,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_AUTO_CONFIGURE,
+                                                                                                                       pAutoConfTaskSpec, NULL);*/
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_SYNCSTATUS,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_SYNCSTATUS,
+                                                                                                                       pSyncStatusTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_NAME,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_NAME,
+                                                                                                                       pGetProfileNameTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SERVER_INFO,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SERVER_INFO,
+                                                                                                                       pGetProfileServerInfoTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_MODE,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_MODE,
+                                                                                                                       pGetProfileSyncModeTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY,
+                                                                                                                       pGetProfileSyncCategoryTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_LAST_SESSION,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_LAST_SESSION,
+                                                                                                                       pGetProfileLastSessionTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_STATISTICS,
+                                                                                                                       pGetProfileStatisticsTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES,
+                                                                                                                       pResetSynchronizingProfilesTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE_CP,
+                                                                                                                       pAddProfileCPTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_REFRESH_FROM_SERVICE,
+                                                                                                                       pRefreshFromServiceTaskSpec, NULL);
+
+       /*FIXME cancel request to NA */
+       /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_CANCEL_SYNC_REQUEST,
+                                                                                                                       pCancelSyncRequestTaskSpec, NULL);*/
+
+       queuing_rule_spec_t *pQueuing_rule = queuing_rule_spec_create_queuing_rule_spec_outline("sync_queueing_rule");
+
+       queuing_rule_spec_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE,
+                                                                                                                                                                       pSyncTaskSpec, 0);
+
+       queuing_rule_spec_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_REQUEST,
+                                                                                                                                                               pSyncTaskSpec, 0);
+
+       engine_controller_async_register_queuing_rule_spec(pQueuing_rule, NULL, NULL);
+
+       queuing_rule_spec_unref(pQueuing_rule);
+
+       __request_reset_synchronizing_profiles();                       /*reset synchronizing flag 0 every account & construct item tbl*/
+
+       /*TODO have to be removed after removing vconf*/
+       error = set_EventCallback(1,  event_callback_add_account);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(3,  event_callback_edit_account);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(5,  event_callback_auto_configure);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+/************************************************/
+
+
+
+       /*error = set_EventCallback(1,  event_callback_add_profile_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");*/
+
+       error = set_EventCallback(2,  event_callback_request_sync_async);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       /*error = set_EventCallback(3,  event_callback_edit_profile_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");*/
+
+       error = set_EventCallback(4,  event_callback_delete_profile_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       /*error = set_EventCallback(5,  event_callback_auto_configure_async);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");*/
+
+       error = set_EventCallback(6,  event_callback_cancel_sync_async);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(7,  event_callback_query_sync_status_async);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(8,  event_callback_get_profile_name_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(9,  event_callback_get_profile_server_info_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(10,  event_callback_get_profile_sync_mode_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(11,  event_callback_get_profile_sync_category_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(12,  event_callback_get_profile_last_session_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(13,  event_callback_get_profile_last_statistics_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(14,  event_callback_add_profile_cp_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       PMCI_RETURN san_err = PMCI_Init_Specific_Type(DEFINE_PLATFORM, SAN, PKG_NAME, NULL, 1, SAN_callback_parse);
+       if (san_err != PMCI_SUCCESS)
+               FW_LOGE("failed in PMCI_Init_Specific_Type");
+
+       PMCI_RETURN scheduler_err = PMCI_Init_Specific_Type(DEFINE_PLATFORM, ALARM, PKG_NAME, NULL, 1, send_periodic_sync_msg);
+       if (scheduler_err != PMCI_SUCCESS)
+               FW_LOGE("failed in PMCI_Init_Specific_Type");
+
+       /*register profiles from csc*/
+       __check_csc();
+
+       while (1) {
+               sleep(1);
+       }
+       return 0;
+}
+
+static void __request_reset_synchronizing_profiles()
+{
+       FW_LOGV("start");
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES, 0,
+                                                                                                                       0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id);
+       FW_LOGV("end");
+}
+static void __check_csc()
+{
+       FW_LOGV("start");
+
+       bool exist = false;
+
+       /*FIXME(temporary do not process csc for ui reason)
+       check csc_check file is existed
+       if false do csc update
+       if true check csc xml file has been changed*/
+
+       /*exist = FSAPI_isExisting(OMA_DS_CSC_CHECK_PATH);*/
+       exist = true;
+       FW_LOGV("update = %d", exist);
+
+       if (exist == false)
+               __update_csc();
+
+       FW_LOGV("end");
+}
+
+static void __update_csc()
+{
+       FW_LOGV("start");
+
+       char profile[128];
+       int numberOfProfiles = 0;
+       char *contents = "check";
+
+       bool result = get_vconf_Int_key(CSC_VCONF_KEY_SYNCMLDS_NBDATASYNC, &numberOfProfiles);
+       if (result == false) {
+               FW_LOGE("failed in get_vconf_Int_key");
+               goto error;
+       }
+
+       int i;
+       for (i = 1; i <= numberOfProfiles; i++) {
+               sprintf(profile, "Sync%d", i);
+               add_profile_csc(i);
+       }
+
+       FSAPI_fileWriteWhole(OMA_DS_CSC_CHECK_PATH, contents, sizeof(contents), false);
+
+error:
+
+       FW_LOGV("end");
+}
diff --git a/noticonfig_omads b/noticonfig_omads
new file mode 100644 (file)
index 0000000..15ef874
--- /dev/null
@@ -0,0 +1,4 @@
+1, 0, 0, 30, autoconfig
+2, 0, 0, 30, syncstatus
+3, 0, 0, 30, sessionprocess
+4, 0, 0, 30, processupdate
diff --git a/omadsUI_fw_config.xml b/omadsUI_fw_config.xml
new file mode 100644 (file)
index 0000000..88faa00
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml  version="1.0" encoding="UTF-8" ?>\r
+<INIT>\r
+       <Agent-Key>OMADS_UI</Agent-Key>\r
+       <Event>\r
+               <Event-Key>OMADS</Event-Key>\r
+               <Event-Config>/opt/data/oma-ds/eventconfig_omads</Event-Config>\r
+               <RunEventHandler>0</RunEventHandler>\r
+       </Event>\r
+       <Noti>\r
+               <Noti-Key>OMADS</Noti-Key>\r
+               <Noti-Config>/opt/data/oma-ds/noticonfig_omads</Noti-Config>\r
+       </Noti>\r
+</INIT>\r
diff --git a/omads_fw_config.xml b/omads_fw_config.xml
new file mode 100755 (executable)
index 0000000..f2e23a1
--- /dev/null
@@ -0,0 +1,106 @@
+<?xml  version="1.0" encoding="UTF-8" ?>\r
+<INIT>\r
+       <Agent-Key>OMADS</Agent-Key>\r
+       <MainLoop>1</MainLoop>\r
+       <Event>\r
+               <Event-Key>OMADS</Event-Key>\r
+               <Event-Config>/opt/data/oma-ds/eventconfig_omads</Event-Config>\r
+               <RunEventHandler>1</RunEventHandler>\r
+       </Event>\r
+       <Noti>\r
+               <Noti-Key>OMADS</Noti-Key>\r
+               <Noti-Config>/opt/data/oma-ds/noticonfig_omads</Noti-Config>\r
+       </Noti>\r
+       <EngineController>\r
+               <Max-Thread>5</Max-Thread>\r
+       </EngineController>\r
+       <FrameworkDB use="1">\r
+               <Path>/opt/dbspace/.omasyncagent.db</Path>\r
+       </FrameworkDB>\r
+       <ID-Provider>\r
+               <Code>1</Code>\r
+               <MaxID>500000</MaxID>\r
+               <PageSize>5</PageSize>\r
+       </ID-Provider>\r
+       <PlugIn-Mgr>\r
+               <Domain name="DataConnector" count="3">\r
+                       <Plug-In>\r
+                               <ID>0</ID>\r
+                               <Path>/usr/lib/libplugin-da-contact.so</Path>\r
+                               <Description>SLP Contact Access PlugIn</Description>\r
+                               <DataConverter-PlugIn>1</DataConverter-PlugIn>\r
+                               <Handle-ChangeNoti>1</Handle-ChangeNoti>\r
+                               <Use-MainLoop>1</Use-MainLoop>\r
+                       </Plug-In>\r
+                       <Plug-In>\r
+                               <ID>1</ID>\r
+                               <Path>/usr/lib/libplugin-da-calendar.so</Path>\r
+                               <Description>SLP Calendar Access PlugIn</Description>\r
+                               <DataConverter-PlugIn>2</DataConverter-PlugIn>\r
+                               <Handle-ChangeNoti>1</Handle-ChangeNoti>\r
+                               <Use-MainLoop>1</Use-MainLoop>\r
+                       </Plug-In>\r
+                       <Plug-In>\r
+                               <ID>2</ID>\r
+                               <Path>/usr/lib/libplugin-da-memo.so</Path>\r
+                               <Description>SLP Memo Access PlugIn</Description>\r
+                               <DataConverter-PlugIn>3</DataConverter-PlugIn>\r
+                               <Handle-ChangeNoti>1</Handle-ChangeNoti>\r
+                               <Use-MainLoop>1</Use-MainLoop>\r
+                       </Plug-In>\r
+               </Domain>\r
+               <Domain name="DataConverter" count="3">\r
+                       <Plug-In>\r
+                               <ID>1</ID>\r
+                               <Path>/usr/lib/libplugin-dc-vcard.so</Path>\r
+                               <Description>SLP Contact Converter</Description>\r
+                       </Plug-In>\r
+                       <Plug-In>\r
+                               <ID>2</ID>\r
+                               <Path>/usr/lib/libplugin-dc-vcalendar.so</Path>\r
+                               <Description>SLP Calendar Converter</Description>\r
+                       </Plug-In>\r
+                       <Plug-In>\r
+                               <ID>3</ID>\r
+                               <Path>/usr/lib/libplugin-dc-plain-text.so</Path>\r
+                               <Description>SLP Memo Converter</Description>\r
+                       </Plug-In>\r
+               </Domain>\r
+               <Domain name="Account" count="1">\r
+                       <Plug-In>\r
+                               <ID>1</ID>\r
+                               <Path>/usr/lib/libplugin-account.so</Path>\r
+                               <Description>SLP Account Accessor</Description>\r
+                       </Plug-In>\r
+               </Domain>\r
+               <Domain name="NetworkAccess" count="1">\r
+                       <Plug-In>\r
+                               <ID>1</ID>\r
+                               <Path>/usr/lib/libplugin-na-http.so</Path>\r
+                               <Description>Http Protocol</Description>\r
+                               <UseNetwork>1</UseNetwork>\r
+                       </Plug-In>\r
+               </Domain>\r
+               <Domain name="DeviceInfo" count="1">    \r
+                       <Plug-In>\r
+                               <ID>1</ID>\r
+                               <Path>/usr/lib/libplugin-di-slp-device.so</Path>\r
+                               <Description>SLP Device Accessor</Description>\r
+                       </Plug-In>\r
+               </Domain>\r
+               <Domain name="PlatformMonitor" count="1">\r
+                       <Plug-In>\r
+                               <ID>1</ID>\r
+                               <Path>/usr/lib/libplugin-pm-slp-sysnoti.so</Path>\r
+                               <Description>monitoring Event from SLP Platform</Description>\r
+                       </Plug-In>\r
+               </Domain>\r
+       </PlugIn-Mgr>\r
+       <PlatformMonitor use_mainloop="1">\r
+               <NetworkStat use="1" mainloop="1"/>\r
+               <SAN use="1" mainloop="1"/>\r
+               <ALARM use="1" mainloop="1">\r
+                       <Pkg-Name>oma-ds-service</Pkg-Name>\r
+               </ALARM>\r
+       </PlatformMonitor>\r
+</INIT>\r
diff --git a/packaging/oma-ds-service.spec b/packaging/oma-ds-service.spec
new file mode 100644 (file)
index 0000000..8f3a97b
--- /dev/null
@@ -0,0 +1,88 @@
+Name:       oma-ds-service
+Summary:    oma-ds-service
+Version:    0.1.11
+Release:    1
+Group:      TO_BE/FILLED_IN
+License:    Samsung Proprietary License
+Source0:    %{name}-%{version}.tar.gz
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(libsoup-2.4)
+BuildRequires:  pkgconfig(sqlite3)
+BuildRequires:  pkgconfig(sync-agent-framework)
+BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(libwbxml2)
+BuildRequires:  pkgconfig(check)
+BuildRequires:  expat-devel
+BuildRequires:  cmake
+
+Requires(post): /sbin/ldconfig  
+Requires(postun): /sbin/ldconfig  
+
+
+%description
+oma-ds-service daemon (development headers)
+
+
+#%package devel
+#Summary:    Development files for %{name}
+#Group:      Development/Libraries
+#Requires:   %{name} = %{version}-%{release}
+#%description devel
+#Development files for %{name}
+
+%prep
+%setup -q
+
+
+%build
+cmake . -DCMAKE_INSTALL_PREFIX=/usr
+
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+mkdir -p %{buildroot}%{_sysconfdir}/rc.d/init.d    
+mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc3.d    
+mkdir -p %{buildroot}%{_sysconfdir}/rc.d/rc5.d    
+mv syncmld_mgr %{buildroot}%{_sysconfdir}/rc.d/init.d/syncmld_mgr    
+  
+ln -s %{_sysconfdir}/rc.d/init.d/syncmld_mgr %{buildroot}%{_sysconfdir}/rc.d/rc3.d/S90Syncmld  
+ln -s %{_sysconfdir}/rc.d/init.d/syncmld_mgr %{buildroot}%{_sysconfdir}/rc.d/rc5.d/S90Syncmld  
+
+mkdir -p %{buildroot}/opt/data/oma-ds  
+mv eventconfig_omads %{buildroot}/opt/data/oma-ds/  
+mv noticonfig_omads %{buildroot}/opt/data/oma-ds/  
+mv omadsUI_fw_config.xml %{buildroot}/opt/data/oma-ds/  
+mv omads_fw_config.xml %{buildroot}/opt/data/oma-ds/
+
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
+%files
+%defattr(-,root,root,-)
+%{_bindir}/*
+#/opt/data/eventconfig_omads
+#/opt/data/noticonfig_omads
+/opt/data/oma-ds/eventconfig_omads  
+/opt/data/oma-ds/noticonfig_omads  
+/opt/data/oma-ds/omadsUI_fw_config.xml  
+/opt/data/oma-ds/omads_fw_config.xml  
+
+
+%defattr(700,root,root)    
+%{_sysconfdir}/rc.d/init.d/syncmld_mgr    
+  
+#%files devel
+#%defattr(-,root,root,-)
+#%{_includedir}/agent-framework/*
+#%{_libdir}/*.so
+#%{_libdir}/pkgconfig/oma-ds-service.pc
+
+%defattr(755,root,root)      
+%{_sysconfdir}/rc.d/rc3.d/S90Syncmld       
+%{_sysconfdir}/rc.d/rc5.d/S90Syncmld  
diff --git a/rmUnavailables b/rmUnavailables
new file mode 100755 (executable)
index 0000000..dba4bbb
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+find . -name CMakeFiles -exec rm -rf {} \;
+find . -name CMakeCache.txt -exec rm -rf {} \;
+find . -name Makefile -exec rm -rf {} \;
+find . -name cmake_install.cmake -exec rm -rf {} \;
+find . -name install_manifest.txt -exec rm -rf {} \;
+
+rm -rf ./oma-ds-service
+rm -rf ./oma-test
+
+rm -rf ./debian/PKG
+rm -rf ./debian/oma-ds-service
+rm -rf ./debian/oma-ds-service-dbg
+rm -rf ./debian/tmp
+rm -rf ./debian/files
+rm -rf ./debian/*.log
+rm -rf ./debian/*.debhelper
+rm -rf ./debian/*.substvars
+rm -rf ./debian/substvars
+
+rm -rf ../oma-ds-service-dbg_0.1.11_armel.deb
+rm -rf ../oma-ds-service_0.1.11_armel.deb
+rm -rf ../oma-ds-service_0.1.11_armel.changes
diff --git a/src/Common/Common_Define.c b/src/Common/Common_Define.c
new file mode 100644 (file)
index 0000000..68a0420
--- /dev/null
@@ -0,0 +1,732 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Define_Internal.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of defined Common structure
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Define.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+
+Datastore *datastoreinfo_per_content_type[4];
+AlertType syncType;
+
+DatastoreInfo *create_datastoreinfo(char *target, char *source)
+{
+       FW_LOGV("start");
+
+       DatastoreInfo *datastoreInfo = (DatastoreInfo *)calloc(1, sizeof(DatastoreInfo));
+       if (datastoreInfo == NULL) {
+               FW_LOGV("datastoreInfo is NULL");
+               return NULL;
+       }
+
+       if (target != NULL)
+               datastoreInfo->target = strdup(target);
+       if (source != NULL)
+               datastoreInfo->source = strdup(source);
+
+       FW_LOGV("end");
+
+       return datastoreInfo;
+}
+
+void free_datastoreinfos(GList *pDatastoreInfos)
+{
+       FW_LOGV("start");
+
+       if (!pDatastoreInfos) {
+               FW_LOGV("List is null");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pDatastoreInfos; iter != NULL; iter = g_list_next(iter))
+               free_datastoreinfo(iter->data);
+
+       g_list_free(pDatastoreInfos);
+
+       FW_LOGV("end");
+}
+
+void free_datastoreinfo(DatastoreInfo *pDatastoreInfo)
+{
+       FW_LOGV("start");
+
+       if (!pDatastoreInfo) {
+               FW_LOGV("pDatastoreInfo is NULL");
+               return;
+       }
+
+       if (pDatastoreInfo->target) {
+               free(pDatastoreInfo->target);
+               pDatastoreInfo->target = NULL;
+       }
+
+       if (pDatastoreInfo->source) {
+               free(pDatastoreInfo->source);
+               pDatastoreInfo->source = NULL;
+       }
+
+       if (pDatastoreInfo->lastAnchor) {
+               free(pDatastoreInfo->lastAnchor);
+               pDatastoreInfo->lastAnchor = NULL;
+       }
+
+       if (pDatastoreInfo->nextAnchor) {
+               free(pDatastoreInfo->nextAnchor);
+               pDatastoreInfo->nextAnchor = NULL;
+       }
+
+       free(pDatastoreInfo);
+
+       FW_LOGV("end");
+}
+
+void set_datastoreInfo_synctype(DatastoreInfo *datastoreInfo, AlertType syncType)
+{
+       if (0 < syncType)
+               datastoreInfo->syncType = syncType;
+}
+
+void set_datastoreinfo_lastanchor(DatastoreInfo *datastoreInfo, char *lastAnchor)
+{
+       if (lastAnchor)
+               datastoreInfo->lastAnchor = strdup(lastAnchor);
+}
+
+void set_datastoreinfo_nextanchor(DatastoreInfo *datastoreInfo, char *nextAnchor)
+{
+       if (nextAnchor)
+               datastoreInfo->nextAnchor = strdup(nextAnchor);
+}
+
+void set_datastoreinfo_maxobjsize(DatastoreInfo *datastoreInfo, unsigned int maxObjSize)
+{
+       if (maxObjSize)
+               datastoreInfo->maxObjSize = maxObjSize;
+}
+
+ChangedItem *create_changeditem(ChangeType type, char *luid)
+{
+       FW_LOGV("start");
+       ChangedItem *changedItem = (ChangedItem *)calloc(1, sizeof(ChangedItem));
+       if (changedItem == NULL) {
+               FW_LOGV("changedItem is NULL");
+               return NULL;
+       }
+
+       changedItem->changeType = type;
+
+       if (luid != NULL)
+               changedItem->luid = strdup(luid);
+
+       changedItem->content_type = NULL;
+
+       FW_LOGV("end");
+
+       return changedItem;
+}
+
+void set_changeditem_contenttype(ChangedItem *pChangedItem, char *content_type)
+{
+       FW_LOGV("start content_type = %s", content_type);
+
+       if (!pChangedItem) {
+               FW_LOGV("pChangedItem is NULL");
+               return;
+       }
+
+       if (content_type != NULL)
+               pChangedItem->content_type = strdup(content_type);
+}
+
+void free_changeditem(ChangedItem *pChangedItem)
+{
+       FW_LOGV("start");
+
+       if (!pChangedItem) {
+               FW_LOGV("pChangedItem is NULL");
+               return;
+       }
+
+       if (pChangedItem->luid) {
+               free(pChangedItem->luid);
+               pChangedItem->luid = NULL;
+       }
+
+       if (pChangedItem->content_type) {
+               free(pChangedItem->content_type);
+               pChangedItem->content_type = NULL;
+       }
+
+       if (pChangedItem->data) {
+               free(pChangedItem->data);
+               pChangedItem->data = NULL;
+       }
+
+       if (pChangedItem)
+               free(pChangedItem);
+
+       FW_LOGV("end");
+}
+
+void set_changeditem_data(ChangedItem *changedItem, char *data)
+{
+       if (!changedItem) {
+               FW_LOGV("changedItem is NULL");
+               return;
+       }
+
+       if (data != NULL)
+               changedItem->data = strdup(data);
+}
+
+void set_changedItem_indexofdatastore(ChangedItem *changedItem, unsigned int indexOfDatastore)
+{
+       if (!changedItem) {
+               FW_LOGV("changedItem is NULL");
+               return;
+       }
+
+       changedItem->indexOfDatastore = indexOfDatastore;
+}
+
+ChangedDatastore *create_changeddatastore(char *source, char *target, int hasNumberOfChanges, unsigned int numberOfChanges)
+{
+       FW_LOGV("start");
+
+       ChangedDatastore *changedDatastore = (ChangedDatastore *)calloc(1, sizeof(ChangedDatastore));
+
+       if (changedDatastore == NULL) {
+               FW_LOGV("changedDatastore is NULL");
+               return NULL;
+       }
+
+       if (source != NULL)
+               changedDatastore->source = strdup(source);
+       if (target != NULL)
+               changedDatastore->target = strdup(target);
+
+       changedDatastore->needSyncCommand = 1;
+       changedDatastore->numberOfChanges = numberOfChanges;
+       changedDatastore->hasNumberOfChanges = hasNumberOfChanges;
+
+       FW_LOGV("end");
+
+       return changedDatastore;
+}
+
+void free_changeddatastores(GList *pChangedDatastores)
+{
+       FW_LOGV("start");
+
+       if (!pChangedDatastores) {
+               FW_LOGV("List is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pChangedDatastores; iter != NULL; iter = g_list_next(iter))
+               free_changeddatastore(iter->data);
+
+       g_list_free(pChangedDatastores);
+
+       FW_LOGV("end");
+}
+
+void free_changeddatastore(ChangedDatastore *pChangedDatastore)
+{
+       FW_LOGV("pChangedDatastore = %p", pChangedDatastore);
+       FW_LOGV("start");
+
+       if (!pChangedDatastore) {
+               FW_LOGV("pChangedDatastore is NULL");
+               return;
+       }
+
+       if (pChangedDatastore->source) {
+               free(pChangedDatastore->source);
+               pChangedDatastore->source = NULL;
+       }
+
+       if (pChangedDatastore->target) {
+               free(pChangedDatastore->target);
+               pChangedDatastore->target = NULL;
+       }
+
+       GList *iter = NULL;
+       for (iter = pChangedDatastore->changeItem; iter != NULL; iter = g_list_next(iter))
+               free_changeditem(iter->data);
+
+       g_list_free(pChangedDatastore->changeItem);
+       pChangedDatastore->changeItem = NULL;
+
+       for (iter = pChangedDatastore->sentItem; iter != NULL; iter = g_list_next(iter))
+               free_changeditem(iter->data);
+
+       g_list_free(pChangedDatastore->sentItem);
+       pChangedDatastore->sentItem = NULL;
+
+       if (pChangedDatastore)
+               free(pChangedDatastore);
+
+       FW_LOGV("end");
+}
+
+void set_changeddatastore_changeditem(ChangedDatastore *changedDatastore, GList *changeItem)
+{
+       if (changedDatastore)
+               changedDatastore->changeItem = changeItem;
+}
+
+void add_changeddatastore_changeditem(ChangedDatastore *changedDatastore, ChangedItem *changedItem)
+{
+       if (!changedDatastore) {
+               FW_LOGV("changedDatastore is NULL");
+               return;
+       }
+
+       changedDatastore->changeItem = g_list_append(changedDatastore->changeItem, changedItem);
+}
+
+AppliedStatus *create_appliedstatus(char *luid, ChangeType changeType, int status)
+{
+       FW_LOGV("start");
+
+       AppliedStatus *appliedStatus = (AppliedStatus *)calloc(1, sizeof(AppliedStatus));
+       if (appliedStatus == NULL) {
+               FW_LOGV("appliedStatus is NULL");
+               return NULL;
+       }
+
+       if (luid != NULL)
+               appliedStatus->luid = strdup(luid);
+
+       appliedStatus->changeType = changeType;
+       appliedStatus->status = status;
+
+       FW_LOGV("end");
+
+       return appliedStatus;
+}
+
+void free_appliedstatuses(GList *pAppliedStatuses)
+{
+       FW_LOGV("start");
+
+       if (!pAppliedStatuses) {
+               FW_LOGV("List is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pAppliedStatuses; iter != NULL; iter = g_list_next(iter))
+               free_appliedstatus(iter->data);
+
+       g_list_free(pAppliedStatuses);
+
+       FW_LOGV("start");
+}
+
+void free_appliedstatus(AppliedStatus *pAppliedStatus)
+{
+       FW_LOGV("start");
+
+       if (!pAppliedStatus) {
+               FW_LOGV("pAppliedStatus is NULL");
+               return;
+       }
+
+       if (pAppliedStatus->luid) {
+               free(pAppliedStatus->luid);
+               pAppliedStatus->luid = NULL;
+       }
+
+       free(pAppliedStatus);
+
+       FW_LOGV("end");
+}
+
+SendingStatus *create_sendingstatus(char *source, char *target)
+{
+       FW_LOGV("start");
+
+       SendingStatus *sendingStatus = (SendingStatus *)calloc(1, sizeof(SendingStatus));
+       if (sendingStatus == NULL) {
+               FW_LOGV("sendingStatus is NULL");
+               return NULL;
+       }
+
+       if (source != NULL)
+               sendingStatus->source = strdup(source);
+
+       if (target != NULL)
+               sendingStatus->target = strdup(target);
+
+       FW_LOGV("end");
+
+       return sendingStatus;
+}
+
+void free_sendingstatuses(GList *pSendingStatuses)
+{
+       FW_LOGV("start");
+
+       if (!pSendingStatuses) {
+               FW_LOGV("List is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pSendingStatuses; iter != NULL; iter = g_list_next(iter))
+               free_sendingstatus(iter->data);
+
+       g_list_free(pSendingStatuses);
+
+       FW_LOGV("end");
+}
+
+void free_sendingstatus(SendingStatus *pSendingStatus)
+{
+       FW_LOGV("start");
+
+       if (!pSendingStatus) {
+               FW_LOGV("pAppliedStatus is NULL");
+               return;
+       }
+
+       if (pSendingStatus->source) {
+               free(pSendingStatus->source);
+               pSendingStatus->source = NULL;
+       }
+
+       if (pSendingStatus->target) {
+               free(pSendingStatus->target);
+               pSendingStatus->target = NULL;
+       }
+
+       GList *iter = NULL;
+       for (iter = pSendingStatus->items; iter != NULL; iter = g_list_next(iter))
+               free_appliedstatus(iter->data);
+
+       g_list_free(pSendingStatus->items);
+
+       free(pSendingStatus);
+
+       FW_LOGV("end");
+}
+void add_sendingstatus_appliedstatus(SendingStatus *sendingStatus, AppliedStatus *appliedStatus)
+{
+       if (!sendingStatus) {
+               FW_LOGV("sendingStatus is NULL");
+               return;
+       }
+
+       sendingStatus->items = g_list_append(sendingStatus->items, appliedStatus);
+}
+
+Datastore *create_datastore(char *target, char *source)
+{
+       FW_LOGV("start");
+
+       Datastore *datastore = (Datastore *)calloc(1, sizeof(Datastore));
+       if (datastore == NULL) {
+               FW_LOGV("datastore is NULL");
+               return NULL;
+       }
+
+       if (target)
+               datastore->target = strdup(target);
+
+       if (source)
+               datastore->source = strdup(source);
+
+       FW_LOGV("end");
+
+       return datastore;
+}
+
+void set_datastore_contenttype_info(Datastore *datastore, int datastore_id, int folder_type_id)
+{
+       if (datastore_id)
+               datastore->datastore_id = datastore_id;
+       if (folder_type_id)
+               datastore->folder_type_id = folder_type_id;
+}
+
+void set_datastore_account_info(Datastore *datastore, char *account_id, char *account_pw)
+{
+       if (account_id)
+               datastore->id = strdup(account_id);
+       if (account_pw)
+               datastore->pw = strdup(account_pw);
+}
+
+void set_datastore_client_sync_type(Datastore *datastore, AlertType syncType)
+{
+       if (syncType)
+               datastore->clientSyncType = syncType ;
+}
+
+void set_datastore_server_sync_type(Datastore *datastore, AlertType syncType)
+{
+       if (syncType)
+               datastore->serverSyncType = syncType ;
+}
+
+void set_datastore_client_anchor(Datastore *datastore, char *lastAnchor, char *nextAnchor)
+{
+       if (lastAnchor)
+               datastore->lastAnchorClient = strdup(lastAnchor);
+       if (nextAnchor)
+               datastore->nextAnchorClient = strdup(nextAnchor);
+}
+
+void set_datastore_server_anchor(Datastore *datastore, char *lastAnchor, char *nextAnchor)
+{
+       if (lastAnchor)
+               datastore->lastAnchorServer = strdup(lastAnchor);
+       if (nextAnchor)
+               datastore->nextAnchorServer = strdup(nextAnchor);
+}
+
+SyncResult *create_sync_result()
+{
+       FW_LOGV("start");
+
+       SyncResult *syncResult = calloc(1, sizeof(SyncResult));
+       if (syncResult == NULL) {
+               FW_LOGV("syncResult is NULL");
+               return NULL;
+       }
+
+       FW_LOGV("end");
+
+       return syncResult;
+}
+
+SyncResult *dup_syncresult(SyncResult *orgSyncResult)
+{
+       FW_LOGV("start");
+
+       SyncResult *syncResult = calloc(1, sizeof(SyncResult));
+       if (syncResult == NULL) {
+               FW_LOGV("syncResult is NULL");
+               return NULL;
+       }
+
+       syncResult->sessionResult = orgSyncResult->sessionResult;
+       syncResult->numberOfChange = orgSyncResult->numberOfChange;
+       syncResult->received_count = orgSyncResult->received_count;
+       syncResult->add_count = orgSyncResult->add_count;
+       syncResult->replace_count = orgSyncResult->replace_count;
+       syncResult->delete_count = orgSyncResult->delete_count;
+
+       FW_LOGV("end");
+
+       return syncResult;
+
+}
+
+void set_numberofchange(SyncResult *syncResult, unsigned int numberOfChange)
+{
+       if (syncResult)
+               syncResult->numberOfChange = numberOfChange;
+}
+
+void add_add_count(SyncResult *syncResult, unsigned int add_cnt)
+{
+       if (syncResult)
+               syncResult->add_count += add_cnt;
+}
+
+void add_receive_count(SyncResult *syncResult, unsigned int received_count)
+{
+       if (syncResult)
+               syncResult->received_count += received_count;
+}
+
+void add_replace_count(SyncResult *syncResult, unsigned int replace_cnt)
+{
+       if (syncResult)
+               syncResult->replace_count += replace_cnt;
+}
+
+void add_delete_count(SyncResult *syncResult, unsigned int delete_cnt)
+{
+       if (syncResult)
+               syncResult->delete_count += delete_cnt;
+}
+
+void free_presyncreturnobj(PreSyncReturnObj *pPreSyncReturnObj)
+{
+       FW_LOGV("start");
+
+       if (pPreSyncReturnObj == NULL) {
+               FW_LOGV("pPreSyncReturnObj is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pPreSyncReturnObj->datastoreInfo; iter != NULL; iter = g_list_next(iter))
+               free_datastoreinfo(iter->data);
+       g_list_free(pPreSyncReturnObj->datastoreInfo);
+       pPreSyncReturnObj->datastoreInfo = NULL;
+
+       if (pPreSyncReturnObj->devID != NULL) {
+               free(pPreSyncReturnObj->devID);
+               pPreSyncReturnObj->devID = NULL;
+       }
+
+       free(pPreSyncReturnObj);
+       pPreSyncReturnObj = NULL;
+
+       FW_LOGV("end");
+}
+
+void free_syncobj(SyncObj *pSyncObj)
+{
+       FW_LOGV("start");
+
+       if (pSyncObj == NULL) {
+               FW_LOGV("pSyncObj is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pSyncObj->changedDatastore; iter != NULL; iter = g_list_next(iter))
+               free_changeddatastore(iter->data);
+       g_list_free(pSyncObj->changedDatastore);
+       pSyncObj->changedDatastore = NULL;
+
+       for (iter = pSyncObj->sendingStatus; iter != NULL; iter = g_list_next(iter))
+               free_sendingstatus(iter->data);
+       g_list_free(pSyncObj->sendingStatus);
+       pSyncObj->sendingStatus = NULL;
+
+       free(pSyncObj);
+       pSyncObj = NULL;
+
+       FW_LOGV("end");
+}
+
+void free_syncreturnobj(SyncReturnObj *pSyncReturnObj)
+{
+       FW_LOGV("start");
+
+       if (pSyncReturnObj == NULL) {
+               FW_LOGV("pSyncReturnObj is NULL");
+               return;
+       }
+
+       GList *iter = NULL;
+       for (iter = pSyncReturnObj->changedDatastore; iter != NULL; iter = g_list_next(iter))
+               free_changeddatastore(iter->data);
+       g_list_free(pSyncReturnObj->changedDatastore);
+       pSyncReturnObj->changedDatastore = NULL;
+
+       for (iter = pSyncReturnObj->status; iter != NULL; iter = g_list_next(iter))
+               free_appliedstatus(iter->data);
+       g_list_free(pSyncReturnObj->status);
+       pSyncReturnObj->status = NULL;
+
+       free(pSyncReturnObj);
+       pSyncReturnObj = NULL;
+
+       FW_LOGV("end");
+}
+
+void free_datastore(Datastore *pDatastore)
+{
+       FW_LOGV("start");
+
+       if (pDatastore == NULL)
+               return;
+
+       if (pDatastore->target != NULL) {
+               free(pDatastore->target);
+               pDatastore->target = NULL;
+       }
+
+       if (pDatastore->source != NULL) {
+               free(pDatastore->source);
+               pDatastore->source = NULL;
+       }
+
+       if (pDatastore->id != NULL) {
+               free(pDatastore->id);
+               pDatastore->id = NULL;
+       }
+
+       if (pDatastore->pw != NULL) {
+               free(pDatastore->pw);
+               pDatastore->pw = NULL;
+       }
+
+       if (pDatastore->lastAnchorClient != NULL) {
+               free(pDatastore->lastAnchorClient);
+               pDatastore->lastAnchorClient = NULL;
+       }
+
+       if (pDatastore->nextAnchorClient != NULL) {
+               free(pDatastore->nextAnchorClient);
+               pDatastore->nextAnchorClient = NULL;
+       }
+
+       if (pDatastore->lastAnchorServer != NULL) {
+               free(pDatastore->lastAnchorServer);
+               pDatastore->lastAnchorServer = NULL;
+       }
+
+       if (pDatastore->nextAnchorServer != NULL) {
+               free(pDatastore->nextAnchorServer);
+               pDatastore->nextAnchorServer = NULL;
+       }
+
+       if (pDatastore->clientSyncResult != NULL)
+               free(pDatastore->clientSyncResult);
+
+       if (pDatastore->serverSyncResult != NULL)
+               free(pDatastore->serverSyncResult);
+
+       free(pDatastore);
+
+       FW_LOGV("end");
+}
diff --git a/src/Common/Common_Util.c b/src/Common/Common_Util.c
new file mode 100644 (file)
index 0000000..1ab5315
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Util.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of utility function
+ */
+
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Util.h"
+#include "Common/Common_Define_Internal.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+#define MAX_RETRY_COUNT 10
+
+bool set_config_str(int accountID, char *key, char *value, char * type, char *accessName)
+{
+       DACI_RETURN result;
+       daci_config config;
+       config.config_id = accountID;
+       config.key = key;
+       config.value = value;
+       config.type = type;
+       config.access_name = accessName;
+
+       result = DACI_Update_Config(&config, 1);
+
+       if (result == DACI_SUCCESS)
+               return true;
+       else
+               return false;
+}
+
+
+bool set_config_int(int accountID, char *key, int value, char * type, char *accessName)
+{
+       char *value_str = NULL;
+       value_str = g_strdup_printf("%u", value);
+
+       DACI_RETURN result;
+       daci_config config;
+       config.config_id = accountID;
+       config.key = key;
+       config.value = value_str;
+       config.type = type;
+       config.access_name = accessName;
+
+       result = DACI_Update_Config(&config, 1);
+
+       if (value_str != NULL)
+               free(value_str);
+
+       if (result == DACI_SUCCESS)
+               return true;
+       else
+               return false;
+}
+
+
+
+bool get_config(int accountId, char *key, char **value)
+{
+       DACI_RETURN result;
+       daci_config daci;
+       daci.config_id = accountId;
+
+       daci.key = key;
+       result = DACI_Get_Config_By_Key(&daci);
+
+       if (result == DACI_SUCCESS) {
+               *value = daci.value;
+               if (daci.type != NULL)
+                       free(daci.type);
+               return true;
+       } else {
+               /* FIXME  temporary solution
+                * Try MAX_RETRY_COUNT when fail to get_config
+                * */
+               int i;
+               bool success = false;
+               for (i = 0; i < MAX_RETRY_COUNT; i++){
+                       result =DACI_Get_Config_By_Key(&daci);
+                       if(result == DACI_SUCCESS){
+                               *value = daci.value;
+                               if (daci.type != NULL)
+                                       free(daci.type);
+                               success = true;
+                               break;
+                       }
+               }
+               if(success == false)
+                       return false;
+               else
+                       return true;
+       }
+}
+
+int get_accountid(char *profile, bool open)
+{
+       FW_LOGV("start");
+       int accountId = -1;
+       char *profileDirName = NULL;
+       int *account_list = 0;
+       int account_list_count = 0;
+       bool result;
+
+       if (open == false) {
+               DACI_RETURN da_err = DACI_Open_Agent();
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("failed in DACI_Open_Agent");
+                       goto error;
+               }
+       }
+
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+
+       int i;
+       for (i = 0; i < account_list_count; i++) {
+               if (profileDirName != NULL)
+                       free(profileDirName);
+
+               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
+               if (result == false) {
+                       FW_LOGE("failed in get_Config");
+                       goto error;
+               }
+
+               FW_LOGV("profileDirName = %s", profileDirName);
+               if(profileDirName == NULL )
+                       continue;
+
+               if (strcmp(profile, profileDirName) == 0) {
+                       FW_LOGV("account_list[i] = %d", account_list[i]);
+                       accountId = account_list[i];
+                       break;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       if (profileDirName)
+               free(profileDirName);
+
+       if (open == false)
+               DACI_Close_Agent();
+
+       return accountId;
+}
+
+/*int convert_synctype_value(char *syncType_str)
+{
+       int syncType_value;
+
+       if (strcmp(syncType_str, DEFINE_ALERT_SLOW_SYNC_STR) ==0)
+               syncType_value = ALERT_SLOW_SYNC ;
+       else if (strcmp(syncType_str, DEFINE_ALERT_TWO_WAY_STR) ==0)
+               syncType_value = ALERT_TWO_WAY ;
+       else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) ==0)
+               syncType_value =  ALERT_ONE_WAY_FROM_CLIENT;
+       else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) ==0)
+               syncType_value = ALERT_ONE_WAY_FROM_SERVER;
+       else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_SERVER_STR) ==0)
+               syncType_value = ALERT_REFRESH_FROM_SERVER;
+       else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) ==0)
+               syncType_value = ALERT_REFRESH_FROM_CLIENT;
+       else
+               syncType_value = ALERT_UNKNOWN;
+
+       return syncType_value;
+}*/
+
+/*char *convert_synctype_str(char *syncType_value)
+{
+       char *syncType_str = NULL;
+
+       if (strcmp(syncType_value, DEFINE_ALERT_SLOW_SYNC_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_SLOW_SYNC_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_TWO_WAY_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_TWO_WAY_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_REFRESH_FROM_SERVER_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_REFRESH_FROM_SERVER_STR;
+       else if (strcmp(syncType_value, DEFINE_ALERT_REFRESH_FROM_CLIENT_VALUE) ==0)
+               syncType_str = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR;
+       else
+               syncType_str = DEFINE_ALERT_SLOW_SYNC_STR;
+
+       return syncType_str;
+}*/
diff --git a/src/Common/Common_Vconf.c b/src/Common/Common_Vconf.c
new file mode 100644 (file)
index 0000000..f514091
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @Common_Util.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of wrapping vconf function
+ */
+
+#include <vconf.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <string.h>
+#include "Common/Common_Vconf.h"
+
+
+char *get_vconf_str(char *baseKey, char *key)
+{
+       char path[128];
+       char *value = NULL;
+
+       sprintf(path, "%s%s", baseKey, key);
+       value = vconf_get_str(path);
+
+       if (value != NULL) {
+               if (strcmp(value, "") == 0) {
+
+                       if (value != NULL)
+                               free(value);
+
+                       return NULL;
+               } else
+                       return value;
+       } else{
+               return NULL;
+       }
+
+}
+
+char *get_vconf_str_key(char *key)
+{
+       char *value = NULL;
+       value = vconf_get_str(key);
+
+       if (value != NULL) {
+               if (strcmp(value, "") == 0) {
+
+                       if (value != NULL)
+                               free(value);
+
+                       return NULL;
+               } else
+                       return value;
+       } else{
+               return NULL;
+       }
+}
+
+bool get_vconf_int(char *baseKey, char *key, int *value)
+{
+       char path[128];
+       int temp = 0;
+       int result;
+
+       sprintf(path, "%s%s", baseKey, key);
+       result = vconf_get_int(path, &temp);
+
+       if (result == 0) {
+               *value = temp;
+               return true;
+       } else
+               return false;
+}
+
+bool get_vconf_Int_key(char *key, int *value)
+{
+       int temp = 0;
+       int result;
+
+       result = vconf_get_int(key, &temp);
+
+       if (result == 0) {
+               *value = temp;
+               return true;
+       } else
+               return false;
+}
+
+bool set_vconf_str(char *baseKey, char *key, char *value)
+{
+       char path[128];
+       int result;
+
+       sprintf(path, "%s%s", baseKey, key);
+       result = vconf_set_str(path, value);
+
+       if (result == 0)
+               return true;
+       else
+               return false;
+}
+
+
+bool set_vconf_str_key(char *key, char *value)
+{
+       int result;
+       result = vconf_set_str(key, value);
+
+       if (result == 0)
+               return true;
+       else
+               return false;
+}
+
+bool set_vconf_int(char *baseKey, char *key, int value)
+{
+       char path[128];
+       int result;
+
+       sprintf(path, "%s%s", baseKey, key);
+       result = vconf_set_int(path, value);
+
+       if (result == 0)
+               return true;
+       else
+               return false;
+}
+
+bool set_vconf_int_key(char *key, int value)
+{
+       int result;
+
+       result = vconf_set_int(key, value);
+
+       if (result == 0)
+               return true;
+       else
+               return false;
+}
diff --git a/src/Framework/Event/OMA_DS_Event_Handler.c b/src/Framework/Event/OMA_DS_Event_Handler.c
new file mode 100644 (file)
index 0000000..1dfc45a
--- /dev/null
@@ -0,0 +1,1028 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Event_Handler.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of event callback function(from ui)
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+#include "Framework/Event/OMA_DS_Event_Handler.h"
+#include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
+#include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
+#include "Common/Common_Define.h"
+#include "Common/Common_Vconf.h"
+#include "Common/Common_Util.h"
+#include "agent-framework/Utility/fw_log.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+
+static void __request_manual_sync_task_finish_callback(task_error_t task_error,
+                                                                                                               unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
+
+static void __auto_configure_task_finish_callback(task_error_t task_error,
+                                                                                                               unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
+
+
+static void __request_manual_sync_task_finish_callback(task_error_t task_error,
+                                                                                                                       unsigned int out_param_cnt,
+                                                                                                                       param_t **out_param_spec_array,
+                                                                                                                       void *usr_data)
+{
+       unsigned int request_msg_id_to_cancel = 0;
+       get_manual_sync_request_id(&request_msg_id_to_cancel);
+}
+
+static void __auto_configure_task_finish_callback(task_error_t task_error,
+                                                                                                                       unsigned int out_param_cnt,
+                                                                                                                       param_t **out_param_spec_array,
+                                                                                                                       void *usr_data)
+{
+       unsigned int request_msg_id_to_cancel = 0;
+       get_auto_configure_request_id(&request_msg_id_to_cancel);
+}
+
+/*TODO have to be removed after removing vconf*/
+int event_callback_add_account(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       int result;
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       /* send to engine controller */
+       void *in_param_value_array[1] = {&profile};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_ACCOUNT, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       append_eventdata_param(response, INTEGER, &result);
+
+       FW_LOGV("end");
+
+error:
+
+       return 0;
+}
+
+/*TODO have to be removed after removing vconf*/
+int event_callback_edit_account(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       int result;
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       /* send to engine controller */
+       void *in_param_value_array[1] = {&profile};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_EDIT_ACCOUNT, 0,
+                                                                                                                               1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       append_eventdata_param(response, INTEGER, &result);
+
+       FW_LOGV("end");
+
+error:
+
+       return 0;
+}
+
+/*TODO have to be removed after removing vconf*/
+int event_callback_auto_configure(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       FW_LOGV("request param : %s", profile);
+
+       void *in_param_value_array[1] = {&profile};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_AUTOCONFIGURE, 0,
+                                                                                                                               1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               __auto_configure_task_finish_callback, NULL, (int *)&request_msg_id);
+
+       insert_request_msg_info(SYNC_MODE_AUTOCONFIG, request_msg_id);
+
+       FW_LOGV("end");
+
+error:
+
+       return 0;
+}
+
+int event_callback_add_profile_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profileDirName = NULL;
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       int category_count;
+       int result;
+       int accountId;
+
+       get_eventdata_param(request, &profileDirName);
+       get_eventdata_param(request, &profileName);
+       get_eventdata_param(request, &addr);
+       get_eventdata_param(request, &id);
+       get_eventdata_param(request, &password);
+       get_eventdata_param(request, &syncMode);
+       get_eventdata_param(request, &syncType);
+       get_eventdata_param(request, &interval);
+       get_eventdata_param(request, &category_count);
+
+       /*
+       FW_LOGV("request param : %s", profileDirName);
+       FW_LOGV("request param : %s", profileName);
+       FW_LOGV("request param : %s", addr);
+       FW_LOGV("request param : %s", id);
+       FW_LOGV("request param : %s", password);
+       FW_LOGV("request param : %s", syncMode);
+       FW_LOGV("request param : %s", syncType);
+       FW_LOGV("request param : %s", interval);
+       FW_LOGV("request param : %d", category_count);
+       */
+
+       GList *categorys = NULL;
+       sync_category *category = (sync_category *)calloc(1, sizeof(sync_category));
+
+       int i = 0;
+       for (; i < category_count ; i++) {
+               get_eventdata_param(request, &(category->enabled));
+               get_eventdata_param(request, &(category->srcURI));
+               get_eventdata_param(request, &(category->tgtURI));
+               get_eventdata_param(request, &(category->id));
+               get_eventdata_param(request, &(category->password));
+
+               categorys = g_list_append(categorys, category);
+
+               /*
+               FW_LOGV("category[i]->enabled : %d", category->enabled);
+               FW_LOGV("category[i]->srcURI : %s", category->srcURI);
+               FW_LOGV("category[i]->tgtURI : %s", category->tgtURI);
+               FW_LOGV("category[i]->id : %s", category->id);
+               FW_LOGV("category[i]->password : %s", category->password);
+               */
+       }
+
+       /* send to engine controller */
+       void *in_param_value_array[9] = {&profileDirName, &profileName, &addr, &id, &password, &syncMode, &syncType, &interval, &categorys};
+       int in_param_index_array[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
+       ECValueType in_param_value_type_array[9] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE, 0,
+                                                                                                                       9, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, INTEGER, &accountId);
+
+
+       FW_LOGV("end");
+
+       return 0;
+}
+
+int event_callback_edit_profile_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profileDirName = NULL;
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       int category_count;
+       int result;
+
+       get_eventdata_param(request, &profileDirName);
+
+       if (!profileDirName) {
+               FW_LOGE("profileDirName is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profileDirName);
+
+       int accountId =  get_accountid(profileDirName, false);
+
+       get_eventdata_param(request, &profileName);
+       get_eventdata_param(request, &addr);
+       get_eventdata_param(request, &id);
+       get_eventdata_param(request, &password);
+       get_eventdata_param(request, &syncMode);
+       get_eventdata_param(request, &syncType);
+       get_eventdata_param(request, &interval);
+       get_eventdata_param(request, &category_count);
+
+       /*
+       FW_LOGV("request param : %s", profileName);
+       FW_LOGV("request param : %s", addr);
+       FW_LOGV("request param : %s", id);
+       FW_LOGV("request param : %s", password);
+       FW_LOGV("request param : %s", syncMode);
+       FW_LOGV("request param : %s", syncType);
+       FW_LOGV("request param : %s", interval);
+       FW_LOGV("request param : %d", category_count);
+       */
+
+       GList *categorys = NULL;
+       sync_category *category = (sync_category *)calloc(1, sizeof(sync_category));
+
+       int i = 0;
+       for (; i < category_count ; i++) {
+               get_eventdata_param(request, &(category->enabled));
+               get_eventdata_param(request, &(category->srcURI));
+               get_eventdata_param(request, &(category->tgtURI));
+               get_eventdata_param(request, &(category->id));
+               get_eventdata_param(request, &(category->password));
+
+               categorys = g_list_append(categorys, category);
+
+               /*
+               FW_LOGV("category[i]->enabled : %d", category->enabled);
+               FW_LOGV("category[i]->srcURI : %s", category->srcURI);
+               FW_LOGV("category[i]->tgtURI : %s", category->tgtURI);
+               FW_LOGV("category[i]->id : %s", category->id);
+               FW_LOGV("category[i]->password : %s", category->password);
+               */
+       }
+
+       /* send to engine controller */
+       void *in_param_value_array[9] = {&accountId, &profileName, &addr, &id, &password, &syncMode, &syncType, &interval, &categorys};
+       int in_param_index_array[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
+       ECValueType in_param_value_type_array[9] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE, 0,
+                                                                                                                       9, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       append_eventdata_param(response, INTEGER, &result);
+
+       FW_LOGV("end");
+
+error:
+
+       return 0;
+}
+
+int event_callback_delete_profile_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       int result;
+       int count;
+       get_eventdata_param(request, &count);
+       GList *profiles = NULL;
+       int *accountId = 0;
+
+       int i;
+       char *profile = NULL;
+       for (i = 0; i < count; i++) {
+               if (profile != NULL) {
+                       free(profile);
+                       profile = NULL;
+               }
+
+               get_eventdata_param(request, &profile);
+               if (!profile) {
+                       FW_LOGE("profile is not defined");
+                       goto error;
+               }
+               FW_LOGV("request param : %s", profile);
+
+               accountId = (int *)calloc(1, sizeof(int));
+               *accountId = get_accountid(profile, false);
+
+               profiles = g_list_append(profiles, accountId);
+       }
+
+       /* send to engine controller */
+       void *in_param_value_array[1] = {&profiles};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE, 0,
+                                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       append_eventdata_param(response, INTEGER, &result);
+
+       FW_LOGV("end");
+
+error:
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_request_sync_async(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+       char *syncMode = strdup(DEFINE_SYNC_MODE_MANUAL);
+
+       void *in_param_value_array[3] = {&accountId, &syncMode, NULL};
+       int in_param_index_array[3] = {0, 1, 2};
+       ECValueType in_param_value_type_array[3] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
+                                                                                                                               3, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               __request_manual_sync_task_finish_callback, NULL, (int *)&request_msg_id);
+
+       insert_request_msg_info(SYNC_MODE_MANUAL, request_msg_id);
+
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_auto_configure_async(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profileDirName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+
+       get_eventdata_param(request, &profileDirName);
+       get_eventdata_param(request, &addr);
+       get_eventdata_param(request, &id);
+       get_eventdata_param(request, &password);
+
+       /*
+       FW_LOGV("request param : %s", profileDirName);
+       FW_LOGV("request param : %s", addr);
+       FW_LOGV("request param : %s", id);
+       FW_LOGV("request param : %s", password);
+       */
+
+       void *in_param_value_array[4] = {&profileDirName, &addr, &id, &password};
+       int in_param_index_array[4] = {0, 1, 2, 3};
+       ECValueType in_param_value_type_array[4] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_AUTO_CONFIGURE, 0,
+                                                                                                                               4, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               __auto_configure_task_finish_callback, NULL, (int *)&request_msg_id);
+
+       insert_request_msg_info(SYNC_MODE_AUTOCONFIG, request_msg_id);
+
+       FW_LOGV("end");
+
+       return 0;
+}
+
+int event_callback_cancel_sync_async(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       get_eventdata_param(request, &profile);
+
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       FW_LOGV("request param : %s", profile);
+
+       unsigned int request_msg_id_to_cancel =  0;
+       bool has_autoconfig = get_auto_configure_request_id(&request_msg_id_to_cancel);
+       if (has_autoconfig) {
+               FW_LOGV("has_autoconfig [%d] ", request_msg_id_to_cancel);
+               engine_controller_cancel_task(request_msg_id_to_cancel);
+       } else{
+               bool has_sync = get_synchronizing_request_id(&request_msg_id_to_cancel);
+               if (has_sync) {
+                       FW_LOGV("has_manual_sync [%d] ", request_msg_id_to_cancel);
+                       engine_controller_cancel_task(request_msg_id_to_cancel);
+
+                       /*request network session cancel*/
+                       /*engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST, 0,
+                                                                                                                               0, NULL, NULL, NULL, NULL, NULL, &request_msg_id);*/
+               } else {
+                       /* nothing to do */
+               }
+       }
+
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_query_sync_status_async(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_SYNCSTATUS, 0,
+                                                                                                                       0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id);
+
+       FW_LOGV("end");
+       return 0;
+}
+
+int event_callback_get_profile_name_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       char *profileName = NULL;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[1] = {0};
+       void *in_param_value_array[1] = {&accountId};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_NAME, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("profileName = %s", profileName);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, STRING, (void *)profileName);
+
+
+       FW_LOGV("end");
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_server_info_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[1] = {0};
+       void *in_param_value_array[1] = {&accountId};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SERVER_INFO, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("addr = %s", addr);
+       FW_LOGV("id = %s", id);
+       FW_LOGV("password = %s", password);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, STRING, (void *)addr);
+       append_eventdata_param(response, STRING, (void *)id);
+       append_eventdata_param(response, STRING, (void *)password);
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_sync_mode_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[1] = {0};
+       void *in_param_value_array[1] = {&accountId};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_MODE, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("syncMode = %s", syncMode);
+       FW_LOGV("syncType = %s", syncType);
+       FW_LOGV("interval = %s", interval);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, STRING, (void *)syncMode);
+       append_eventdata_param(response, STRING, (void *)syncType);
+       append_eventdata_param(response, STRING, (void *)interval);
+
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_sync_category_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       int content_type;
+       int enabled;
+       char *srcURI = NULL;
+       char *tgtURI = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       get_eventdata_param(request, &content_type);
+
+       FW_LOGV("request param : %s", profile);
+       FW_LOGV("request param : %d", content_type);
+
+       int accountId =  get_accountid(profile, false);
+       FW_LOGV(" accountId: %d", accountId);
+
+       int in_param_index_array[2] = {0, 1};
+       void *in_param_value_array[2] = {&accountId, &content_type};
+       ECValueType in_param_value_type_array[2] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY, 0,
+                                                                                                                       2, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &enabled);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &srcURI);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &tgtURI);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("enabled = %d", enabled);
+       FW_LOGV("srcURI = %s", srcURI);
+       FW_LOGV("tgtURI = %s", tgtURI);
+       FW_LOGV("id = %s", id);
+       FW_LOGV("password = %s", password);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, INTEGER, &enabled);
+       append_eventdata_param(response, STRING, (void *)srcURI);
+       append_eventdata_param(response, STRING, (void *)tgtURI);
+       append_eventdata_param(response, STRING, (void *)id);
+       append_eventdata_param(response, STRING, (void *)password);
+
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_last_session_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+       char *profile = NULL;
+       int result;
+       int lastSessionStatus;
+       int lastSessionTime;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+       FW_LOGV("request param : %s", profile);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[1] = {0};
+       void *in_param_value_array[1] = {&accountId};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_LAST_SESSION, 0,
+                                                                                                                       1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &lastSessionStatus);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("lastSessionStatus = %d", lastSessionStatus);
+       FW_LOGV("lastSessionTime = %d", lastSessionTime);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, INTEGER, &lastSessionStatus);
+       append_eventdata_param(response, INTEGER, &lastSessionTime);
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+int event_callback_get_profile_last_statistics_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profile = NULL;
+       int content_type;
+       char *dbSynced = NULL;
+       int lastSessionTime;
+       int server2Client_Total;
+       int server2Client_NrOfAdd;
+       int server2Client_NrOfDelete;
+       int server2Client_NrOfReplace;
+       int client2Server_Total;
+       int client2Server_NrOfAdd;
+       int client2Server_NrOrDelete;
+       int client2Server_NrOfReplace;
+       int result;
+
+       get_eventdata_param(request, &profile);
+       if (!profile) {
+               FW_LOGE("profile is not defined");
+               goto error;
+       }
+
+       get_eventdata_param(request, &content_type);
+
+       FW_LOGV("request param : %s", profile);
+       FW_LOGV("request param : %d", content_type);
+
+       int accountId =  get_accountid(profile, false);
+
+       int in_param_index_array[2] = {0, 1};
+       void *in_param_value_array[2] = {&accountId, &content_type};
+       ECValueType in_param_value_type_array[2] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_INT};
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+
+       unsigned int request_msg_id = 0;
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS, 0,
+                                                                                                                       2, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &dbSynced);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_INT, &server2Client_Total);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfAdd);
+       param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfDelete);
+       param_value_get_value(&(param_array[6]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfReplace);
+       param_value_get_value(&(param_array[7]->param_value), EC_VALUE_TYPE_INT, &client2Server_Total);
+       param_value_get_value(&(param_array[8]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfAdd);
+       param_value_get_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOrDelete);
+       param_value_get_value(&(param_array[10]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfReplace);
+
+       /*
+       FW_LOGV("result = %d", result);
+       FW_LOGV("dbSynced = %s\n", dbSynced);
+       FW_LOGV("lastSessionTime = %d\n", lastSessionTime);
+       FW_LOGV("server2Client_Total = %d\n", server2Client_Total);
+       FW_LOGV("server2Client_NrOfAdd = %d\n", server2Client_NrOfAdd);
+       FW_LOGV("server2Client_NrOfDelete = %d\n", server2Client_NrOfDelete);
+       FW_LOGV("server2Client_NrOfReplace = %d\n", server2Client_NrOfReplace);
+       FW_LOGV("client2Server_Total = %d\n", client2Server_Total);
+       FW_LOGV("client2Server_NrOfAdd = %d\n", client2Server_NrOfAdd);
+       FW_LOGV("client2Server_NrOrDelete = %d\n", client2Server_NrOrDelete);
+       FW_LOGV("client2Server_NrOfReplace = %d\n", client2Server_NrOfReplace);
+       */
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, STRING, (void *)dbSynced);
+       append_eventdata_param(response, INTEGER, &lastSessionTime);
+       append_eventdata_param(response, INTEGER, &server2Client_Total);
+       append_eventdata_param(response, INTEGER, &server2Client_NrOfAdd);
+       append_eventdata_param(response, INTEGER, &server2Client_NrOfDelete);
+       append_eventdata_param(response, INTEGER, &server2Client_NrOfReplace);
+       append_eventdata_param(response, INTEGER, &client2Server_Total);
+       append_eventdata_param(response, INTEGER, &client2Server_NrOfAdd);
+       append_eventdata_param(response, INTEGER, &client2Server_NrOrDelete);
+       append_eventdata_param(response, INTEGER, &client2Server_NrOfReplace);
+
+       FW_LOGV("end");
+
+error:
+
+       if (profile != NULL)
+               free(profile);
+
+       return 0;
+}
+
+
+int event_callback_add_profile_cp_sync(Event_Data *request, Event_Data *response)
+{
+       FW_LOGV("start");
+
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       int category_count;
+       int result;
+       int accountId;
+
+       get_eventdata_param(request, &profileName);
+       get_eventdata_param(request, &addr);
+       get_eventdata_param(request, &id);
+       get_eventdata_param(request, &password);
+       get_eventdata_param(request, &category_count);
+
+       /*
+       FW_LOGV("request param : %s", profileName);
+       FW_LOGV("request param : %s", addr);
+       FW_LOGV("request param : %s", id);
+       FW_LOGV("request param : %s", password);
+       FW_LOGV("request param : %d", category_count);
+       */
+
+       GList *categorys = NULL;
+       int i = 0;
+       for (; i < category_count ; i++) {
+               resource_cp *category = (resource_cp *)calloc(1, sizeof(resource_cp));
+
+               get_eventdata_param(request, &(category->name));
+               get_eventdata_param(request, &(category->accept));
+               get_eventdata_param(request, &(category->id));
+               get_eventdata_param(request, &(category->password));
+               get_eventdata_param(request, &(category->authType));
+               get_eventdata_param(request, &(category->authData));
+
+               categorys = g_list_append(categorys, category);
+
+               /*
+               FW_LOGV("category[%d]->name : %s", i, category->name);
+               FW_LOGV("category[%d]->accept : %s", i, category->accept);
+               FW_LOGV("category[%d]->id : %s", i, category->id);
+               FW_LOGV("category[%d]->password : %s", i, category->password);
+               FW_LOGV("category[%d]->authType : %s", i, category->authType);
+               FW_LOGV("category[%d]->authData : %s\n", i, category->authData);
+               */
+       }
+
+       /* send to engine controller */
+       void *in_param_value_array[5] = {&profileName, &addr, &id, &password, &categorys};
+       int in_param_index_array[5] = {0, 1, 2, 3, 4};
+       ECValueType in_param_value_type_array[5] = {EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT,
+                                                                               EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+
+       unsigned int out_param_count;
+       task_error_t task_error = TASK_ERROR_NOT_YET_RUN;
+       param_t **param_array = NULL;
+
+       engine_controller_sync_request_task(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP, 0,
+                                                                                                                       5, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                       (int *)&request_msg_id, &task_error, &out_param_count, &param_array);
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       append_eventdata_param(response, INTEGER, &result);
+       append_eventdata_param(response, INTEGER, &accountId);
+
+
+       FW_LOGV("end");
+
+       return 0;
+}
diff --git a/src/Framework/Event/OMA_DS_Platform_Event_Handler.c b/src/Framework/Event/OMA_DS_Platform_Event_Handler.c
new file mode 100644 (file)
index 0000000..04ff532
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Platform_Event_Handler.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of event callback function(from platform)
+ */
+
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
+#include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
+#include "Framework/SAN_parser/PM_SanParser.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Define_Internal.h"
+#include "Common/Common_Util.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+
+static void __request_periodic_sync_task_finish_callback(task_error_t task_error,
+                                                                                       unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
+
+static void __request_san_sync_task_finish_callback(task_error_t task_error,
+                                                                                       unsigned int out_param_cnt, param_t **out_param_spec_array, void *usr_data);
+
+static void __request_periodic_sync_task_finish_callback(task_error_t task_error,
+                                                                                                                       unsigned int out_param_cnt,
+                                                                                                                       param_t **out_param_spec_array,
+                                                                                                                       void *usr_data)
+{
+       unsigned int request_msg_id_to_cancel = 0;
+       get_periodic_sync_request_id(&request_msg_id_to_cancel);
+
+}
+
+static void __request_san_sync_task_finish_callback(task_error_t task_error,
+                                                                                                                       unsigned int out_param_cnt,
+                                                                                                                       param_t **out_param_spec_array,
+                                                                                                                       void *usr_data)
+{
+       unsigned int request_msg_id_to_cancel = 0;
+       get_san_sync_request_id(&request_msg_id_to_cancel);
+}
+
+int SAN_callback_parse(const char *msgBody, unsigned int msgSize, int version)
+{
+       FW_LOGV("start");
+       SanPackage  *pSanPackage = NULL;
+       int accountID = -1;
+       char *sync_mode = NULL;
+       char *server_id = NULL;
+       int *account_list = 0;
+
+       switch (version) {
+       case 11:
+       {
+               pSanPackage = sanPackage11Parser(msgBody, msgSize) ;
+       }
+               break;
+       case 12:
+       {
+               pSanPackage = sanPackage12Parser(msgBody, msgSize) ;
+       }
+               break;
+       default:
+               break;
+       }
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS)
+               return 0;
+
+       if (!pSanPackage)
+               goto return_part;
+
+
+       int account_list_count = 0;
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+       bool result;
+
+       int i;
+       for (i = 0 ; i < account_list_count ; i++) {
+               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, &sync_mode);
+               if (result == true) {
+                       /*One device MUST NOT register multi account at same server...*/
+                       if (strcmp(sync_mode, DEFINE_SYNC_MODE_PUSH) == 0) {
+                               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id);
+                               if (result == true) {
+                                       /*One device MUST NOT register multi account at same server...*/
+                                       if (strcmp(pSanPackage->serverID, server_id) == 0) {
+                                               accountID = account_list[i];
+                                               break;
+                                       }
+                               } else{
+                                       FW_LOGE("failed in get_Config");
+                                       goto return_part;
+                               }
+                       }
+               } else{
+                       FW_LOGE("failed in get_Config");
+                       goto return_part;
+               }
+
+       }
+
+       if (accountID < 0)
+               goto return_part;
+
+       char *syncMode = strdup(DEFINE_SYNC_MODE_PUSH) ;
+
+       void *in_param_value_array[3] = {&accountID, &syncMode, &pSanPackage};
+       int in_param_index_array[3] = {0, 1, 2};
+       ECValueType in_param_type[3] = {EC_VALUE_TYPE_INT, EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
+                                                                                                                       3, in_param_index_array, in_param_type, in_param_value_array,
+                                                                                                                       __request_san_sync_task_finish_callback, NULL,
+                                                                                                                       (int *)&request_msg_id);
+
+       insert_request_msg_info(SYNC_MODE_SAN, request_msg_id);
+
+       return 1;
+
+return_part:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       if (sync_mode)
+               free(sync_mode);
+
+       if (server_id)
+               free(server_id);
+
+       DACI_Close_Agent();
+
+       FW_LOGV("end");
+       return 0;
+}
+
+void send_periodic_sync_msg(int schedulerId, void *data)
+{
+       FW_LOGV("#######Scheduler Send Msg Success!!!!!##########");
+       FW_LOGV("schedulerId = %d", schedulerId);
+
+       int *account_list = 0;
+       int account_list_count = 0;
+       int accountId = -1;
+       int alarmId = 0;
+       char *alarmId_str = NULL;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Open_Agent");
+               goto error;
+       }
+
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+
+       FW_LOGV("account_list_count = %d", account_list_count);
+
+       int i;
+       for (i = 0; i < account_list_count; i++) {
+               if (alarmId_str != NULL)
+                       free(alarmId_str);
+
+               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &alarmId_str);
+               if (result == false) {
+                       FW_LOGE("failed in get_Config");
+                       goto error;
+               }
+               alarmId = atoi(alarmId_str);
+               FW_LOGV("alarm id = %d", alarmId);
+               if (alarmId == schedulerId) {
+                       FW_LOGV("account_list[i] = %d", account_list[i]);
+                       accountId = account_list[i];
+                       break;
+               }
+       }
+
+       if (accountId != -1) {
+               int in_param_index_array[3] = {0, 1, 2};
+               ECValueType in_param_value_type_array[3] = {EC_VALUE_TYPE_INT,
+                                                                                       EC_VALUE_TYPE_STRUCT, EC_VALUE_TYPE_STRUCT};
+               char *syncMode = strdup(DEFINE_SYNC_MODE_PERIODIC);
+
+               void *in_param_value_array[3] = {&accountId, &syncMode, NULL};
+
+               unsigned int request_msg_id = 0;
+               engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0,
+                                                                                                                                       3, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                                       __request_periodic_sync_task_finish_callback, NULL,
+                                                                                                                                       (int *)&request_msg_id);
+
+               insert_request_msg_info(SYNC_MODE_PERIODIC, request_msg_id);
+       }
+
+error:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       if (alarmId_str != NULL)
+               free(alarmId_str);
+
+       DACI_Close_Agent();
+}
diff --git a/src/Framework/SAN_parser/PM_SanParser.c b/src/Framework/SAN_parser/PM_SanParser.c
new file mode 100644 (file)
index 0000000..6684369
--- /dev/null
@@ -0,0 +1,628 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+\r
+\r
+/*\r
+ * For any sort of issue you concern as to this software,\r
+ * you may use following point of contact.\r
+ * All resources contributed on this software\r
+ * are orinigally written by S-Core Inc., a member of Samsung Group.\r
+ *\r
+ * SeongWon Shim <seongwon.shim@samsung.com>\r
+ */\r
+\r
+/**\r
+ *   @PM_SanParser.c\r
+ *   @version                                                                  0.1\r
+ *   @brief                                                                            This file is the source file of implementation of San Parser\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <stdbool.h>\r
+#include <string.h>\r
+#include <inttypes.h>\r
+#include <glib.h>\r
+#include "wbxml/wbxml.h"\r
+#include "wbxml/wbxml_tree.h"\r
+\r
+#include "Framework/SAN_parser/PM_SanParser.h"\r
+#include "agent-framework/Utility/fw_log.h"\r
+\r
+#define LOG_TAG        "OMA_DS_COMMON"\r
+\r
+static SanContentType contentTypeSupported[] = {\r
+       {0x00,          NULL},\r
+       {0x03,          "text/plain"},\r
+       {0x06,          "text/x-vcalendar"},\r
+       {0x07,          "text/x-vcard"},\r
+       {0x0305,        "text/calendar"},\r
+       {0x0306,        "application/vnd.omads-email+xml"},\r
+       {0x0307,        "application/vnd.omads-file+xml"},\r
+       {0x0308,        "application/vnd.omads-folder+xml"},\r
+       {0x0309,        "text/vcard"}\r
+};\r
+\r
+SanPackage *sanPackage12Parser(const char *msgBody, unsigned int msgSize)\r
+{\r
+       unsigned int idLength = (uint8_t)msgBody[23];\r
+       if (msgSize < (25 + idLength)) {\r
+               FW_LOGV("[sanPackage12Parser] SAN package size is smaller than");\r
+               FW_LOGV("[sanPackage12Parser] its minimal size specified in the spec, related to [Header] part.");\r
+               return NULL;\r
+       }\r
+       \r
+       SanPackage *san = (SanPackage *)calloc(1, sizeof(SanPackage));\r
+       if (!san) {\r
+               FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Container]");\r
+               return NULL;\r
+       }\r
+\r
+       /* MSG BODY WITHOUT DIGEST*/\r
+       san->msgBodyWithoutDigest = (char *)calloc(msgSize - 16, sizeof(char));\r
+       if (!san->msgBodyWithoutDigest) {\r
+               FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Msg body]");\r
+               goto error;\r
+       }\r
+       memcpy(san->msgBodyWithoutDigest, msgBody + 16, msgSize - 16);\r
+       san->msgBodyWithoutDigestLength = msgSize - 16;\r
+       \r
+       /* DIGEST*/\r
+       san->digest = (char *)calloc(16, sizeof(char));\r
+       if (!san->digest) {\r
+               FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Digest]");\r
+               goto error;\r
+       }\r
+       memcpy(san->digest, msgBody, 16);\r
+       \r
+       /* VERSION*/\r
+       unsigned int version = ((uint8_t)msgBody[16]) << 2;\r
+       version = version | ((uint8_t)msgBody[17]) >> 6;\r
+\r
+       if (version != 12) {\r
+               FW_LOGV("[sanPackage12Parser] Not supported SAN version %d.", version);\r
+               goto error;\r
+       }\r
+       san->version  = version;\r
+       \r
+       /* UI MODE*/\r
+       san->uiMode = (((uint8_t)msgBody[17]) & 0x30) >> 4;\r
+       \r
+       /* INITIATOR*/\r
+       san->initiator = (((uint8_t)msgBody[17]) & 0x08) >> 3;\r
+\r
+       /* SESSION ID*/\r
+/*san->sessionID = ((uint8_t)msgBody[21]) << 8;\r
+       san->sessionID = san->sessionID | (uint8_t)msgBody[22];*/\r
+       san->sessionID = atoi(g_strdup_printf("%02X%02X", msgBody[21], msgBody[22]));\r
+       FW_LOGV("session id : %d \n", san->sessionID);\r
+       \r
+       /* SERVER ID*/\r
+       if (idLength) {\r
+               san->serverID = (char *)calloc(idLength + 1, sizeof(char));\r
+               if (!san->serverID) {\r
+                       FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Server ID]");\r
+                       goto error;\r
+               }\r
+               memcpy(san->serverID, msgBody + 24, idLength);\r
+       }\r
+       \r
+       san->cntSyncAlerts = ((uint8_t)msgBody[24 + idLength]) >> 4;\r
+\r
+       if (san->cntSyncAlerts == 0) {\r
+               if (msgSize > 24 + idLength + 1) {\r
+                       FW_LOGV("[sanPackage12Parser] There are remaining bytes at the end of the package. (w/o alerts info)");\r
+               }\r
+\r
+               /* If number of sync alerts equals 0, should sync all data store in the client*/\r
+               return san;\r
+       }\r
+\r
+       san->syncAlerts = (SanSyncAlert *)calloc(san->cntSyncAlerts, sizeof(SanSyncAlert));\r
+\r
+       msgBody += 25 + idLength;\r
+       unsigned int alertLength = 25 + idLength;\r
+       unsigned int i;\r
+\r
+       for (i = 0; i < san->cntSyncAlerts; i++) {\r
+               \r
+               idLength = (uint8_t)msgBody[4];\r
+               if (msgSize < (alertLength + 5 + idLength)) {\r
+                       FW_LOGV("[sanPackage12Parser] SAN package size is smaller than");\r
+                       FW_LOGV("[sanPackage12Parser] its minimal size specified in the spec, related to [Alerts] part.");\r
+                       goto error;\r
+               }\r
+               alertLength = alertLength + 5 + idLength;\r
+               \r
+               /* SYNC TYPE*/\r
+               SanSyncType alert_type = (((uint8_t)msgBody[0]) >> 4) + 200;\r
+               if (alert_type < 206 || alert_type > 210) {\r
+                       FW_LOGV("[sanPackage12Parser] SAN doesn't support the sync type %d.", alert_type);\r
+                       goto error;\r
+               }\r
+               \r
+               unsigned int contentType = ((uint8_t)msgBody[1]) << 16;\r
+               contentType = contentType | ((uint8_t)msgBody[2]) << 8;\r
+               contentType = contentType | ((uint8_t)msgBody[3]);\r
+               \r
+               /* CONTENT TYPE*/\r
+               char *alert_ct = NULL;\r
+\r
+               int j;\r
+               int cnt = (int)sizeof(contentTypeSupported)/sizeof(SanContentType);\r
+               bool isContentSupported = false;\r
+               \r
+               for (j = 0 ; j < cnt ; j++) {\r
+                       if (contentType == contentTypeSupported[j].type) {\r
+                               alert_ct = contentTypeSupported[j].strType;\r
+                               isContentSupported = true;\r
+                               break;\r
+                       }\r
+               }\r
+\r
+               if (!isContentSupported) {\r
+                       FW_LOGV("[sanPackage12Parser] SAN doesn't support the content type %d.", contentType);\r
+                       goto error;\r
+               }\r
+               \r
+               /* SERVER URI*/\r
+               char *alert_uri = NULL;\r
+               \r
+               if (idLength) {\r
+                       alert_uri = (char *)calloc(idLength + 1, sizeof(char));\r
+                       if (!alert_uri) {\r
+                               FW_LOGV("[sanPackage12Parser] SAN package memory allocation fail. [Server URI]");\r
+                               goto error;\r
+                       }\r
+                       memcpy(alert_uri, msgBody + 5, idLength);\r
+               }\r
+               msgBody += 5 + idLength;\r
+\r
+               san->syncAlerts[i].syncType = alert_type;\r
+               san->syncAlerts[i].contentType = alert_ct;\r
+               san->syncAlerts[i].serverURI = alert_uri;\r
+\r
+       }\r
+\r
+       if (msgSize > alertLength) {\r
+               FW_LOGV("[sanPackage12Parser] There are remaining bytes at the end of the package. (with alerts info)");\r
+       }\r
+\r
+       return san;\r
+\r
+error:\r
+       sanPackageParserFree(san);\r
+       return NULL;\r
+       \r
+}\r
+\r
+WBXMLTreeNode *__get_node_elt_from_name(WBXMLTreeNode *node, const char *name, WB_BOOL recurs)\r
+{\r
+       WBXMLTreeNode *current_node = NULL;\r
+       WBXMLTreeNode *recurs_node = NULL;\r
+\r
+       if ((node == NULL) || (name == NULL))\r
+               return NULL;\r
+\r
+       /* Let's go through the tree */\r
+       current_node = node;\r
+\r
+       while (current_node != NULL) {\r
+               /* Is this a normal node? */\r
+               if (current_node->type == WBXML_TREE_ELEMENT_NODE) {\r
+                       /* Is this the Node we searched ? */\r
+                       if (WBXML_STRCMP(wbxml_tag_get_xml_name(current_node->name), name) == 0) {\r
+                               return current_node;\r
+                       }\r
+\r
+                       /* Sould we start a recursive search? */\r
+                       if (recurs && current_node->children) {\r
+                               recurs_node = __get_node_elt_from_name(current_node->children, name, TRUE);\r
+                               /* Is this the Node we searched ? */\r
+                               if (recurs_node) {\r
+                                       return recurs_node;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               /* Go to next Sibbling Node */\r
+               current_node = current_node->next;\r
+       }\r
+\r
+       /* A node with the specified name could not be found. */\r
+       return NULL;\r
+}\r
+\r
+SanPackage *sanPackage11Parser(const char *msgBody, unsigned int msgSize)\r
+{\r
+       SanPackage *san = (SanPackage *)calloc(1, sizeof(SanPackage));\r
+       if (!san) {\r
+               FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [Container]");\r
+               return NULL;\r
+       }\r
+\r
+       WBXMLTree *wbxml_tree = NULL;\r
+       WBXMLError wbxml_err = wbxml_tree_from_wbxml((unsigned char *)msgBody, msgSize, WBXML_LANG_UNKNOWN, WBXML_CHARSET_UNKNOWN, &wbxml_tree);\r
+\r
+       if (wbxml_err != WBXML_OK) {\r
+               FW_LOGV("[sanPackage11Parser] Libwbxml2 failed to parse WBXML STREAM to WBXML TREE, error code : %s", wbxml_errors_string(wbxml_err));\r
+               goto error;\r
+       }\r
+\r
+       WBXMLTreeNode *synchdr_node;\r
+       if ((synchdr_node = __get_node_elt_from_name(wbxml_tree->root, "SyncHdr", TRUE)) == NULL) {\r
+               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [SyncHdr]");\r
+               goto error;\r
+       }\r
+       WBXMLTreeNode *child_node = NULL;\r
+       const char *child_node_name = NULL;\r
+\r
+       for (child_node = synchdr_node->children ; child_node != NULL ; child_node = child_node->next) {\r
+               child_node_name = (const char *)wbxml_tag_get_xml_name(child_node->name);\r
+\r
+               if ((strcmp(child_node_name, "VerDTD") == 0) || (strcmp(child_node_name, "VerProto") == 0)) {\r
+                       char *version = NULL;\r
+                       if (child_node->children != NULL &&\r
+                               child_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               child_node->children->content != NULL) {\r
+\r
+                               version = (char *)wbxml_buffer_get_cstr(child_node->children->content);\r
+\r
+                               if (strcmp(version, "1.1") && strcmp(version, "SyncML/1.1")) {\r
+                                       FW_LOGV("[sanPackage11Parser] Not supported SAN version %s.", version);\r
+                                       goto error;\r
+                               }\r
+                               san->version = 11;\r
+                       }\r
+               } else if (strcmp(child_node_name, "SessionID") == 0) {\r
+                       char *sessionID = NULL;\r
+                       if (child_node->children != NULL &&\r
+                               child_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               child_node->children->content != NULL) {\r
+\r
+                               sessionID = (char *)wbxml_buffer_get_cstr(child_node->children->content);\r
+\r
+                               if (!sessionID) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL sessionID detected. sessionID MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+                               san->sessionID = atoi(sessionID);\r
+                       }\r
+               } else if (strcmp(child_node_name, "Source") == 0) {\r
+                       char *serverID = NULL;\r
+                       unsigned serverIDlen = 0;\r
+                       WBXMLTreeNode *serverid_node;\r
+                       if ((serverid_node = __get_node_elt_from_name(child_node, "LocURI", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [LocURI]");\r
+                               goto error;\r
+                       }\r
+\r
+                       if (serverid_node->children != NULL &&\r
+                               serverid_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               serverid_node->children->content != NULL) {\r
+               \r
+                               serverID = (char *)wbxml_buffer_get_cstr(serverid_node->children->content);\r
+                               serverIDlen = wbxml_buffer_len(serverid_node->children->content);\r
+                               if (!serverID) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL serverID detected. serverID MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+\r
+                               san->serverID = (char *)calloc(serverIDlen, sizeof(char));\r
+                               if (!san->serverID) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [Server ID]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->serverID, serverID, serverIDlen);\r
+                       }\r
+               } else if (strcmp(child_node_name, "Cred") == 0) {\r
+\r
+                       san->cred = (SanCred *)calloc(1, sizeof(SanCred));\r
+                       \r
+                       char *credFormat = NULL;\r
+                       unsigned credFormatLen = 0;\r
+                       WBXMLTreeNode *credformat_node;\r
+                       if ((credformat_node = __get_node_elt_from_name(child_node, "Format", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Format]");\r
+                               goto error;\r
+                       }\r
+\r
+                       if (credformat_node->children != NULL &&\r
+                               credformat_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               credformat_node->children->content != NULL) {\r
+               \r
+                               credFormat = (char *)wbxml_buffer_get_cstr(credformat_node->children->content);\r
+                               credFormatLen = wbxml_buffer_len(credformat_node->children->content);\r
+                               if (!credFormat) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL credFormat detected. credFormat MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+               \r
+                               san->cred->credFormat = (char *)calloc(credFormatLen, sizeof(char));\r
+                               if (!san->cred->credFormat) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [credFormat]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->cred->credFormat, credFormat, credFormatLen);\r
+                       }\r
+\r
+                       char *credAuth = NULL;\r
+                       unsigned credAuthLen = 0;\r
+                       WBXMLTreeNode *credauth_node;\r
+                       if ((credauth_node = __get_node_elt_from_name(child_node, "Type", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Type]");\r
+                               goto error;\r
+                       }\r
+\r
+                       if (credauth_node->children != NULL &&\r
+                               credauth_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               credauth_node->children->content != NULL) {\r
+               \r
+                               credAuth = (char *)wbxml_buffer_get_cstr(credauth_node->children->content);\r
+                               credAuthLen = wbxml_buffer_len(credauth_node->children->content);\r
+                               if (!credAuth) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL credAuth detected. credAuth MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+               \r
+                               san->cred->credAuth = (char *)calloc(credAuthLen, sizeof(char));\r
+                               if (!san->cred->credAuth) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [credAuth]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->cred->credAuth, credAuth, credAuthLen);\r
+                       }\r
+\r
+                       char *credData = NULL;\r
+                       unsigned credDataLen = 0;\r
+                       WBXMLTreeNode *creddata_node;\r
+                       if ((creddata_node = __get_node_elt_from_name(child_node, "Data", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Data]");\r
+                               goto error;\r
+                       }\r
+\r
+                       if (creddata_node->children != NULL &&\r
+                               creddata_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               creddata_node->children->content != NULL) {\r
+               \r
+                               credData = (char *)wbxml_buffer_get_cstr(creddata_node->children->content);\r
+                               credDataLen = wbxml_buffer_len(creddata_node->children->content);\r
+                               if (!credData) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL credData detected. credData MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+               \r
+                               san->cred->credData = (char *)calloc(credDataLen, sizeof(char));\r
+                               if (!san->cred->credData) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [credData]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->cred->credData, credData, credDataLen);\r
+                       }\r
+\r
+               }\r
+\r
+       }\r
+\r
+       WBXMLTreeNode *syncbody_node;\r
+       if ((syncbody_node = __get_node_elt_from_name(wbxml_tree->root, "SyncBody", TRUE)) == NULL) {\r
+               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [SyncBody]");\r
+               goto error;\r
+       }\r
+       \r
+       WBXMLList *alertnode_list = wbxml_tree_node_get_all_children(syncbody_node);\r
+       unsigned int alertnode_list_len = wbxml_list_len(alertnode_list);\r
+\r
+       child_node = (WBXMLTreeNode *)wbxml_list_get(alertnode_list, alertnode_list_len - 1);\r
+       child_node_name = (const char *)wbxml_tag_get_xml_name(child_node->name);\r
+       if (strcmp(child_node_name, "Final") == 0)\r
+               san->cntSyncAlerts = alertnode_list_len - 1;\r
+\r
+       if (san->cntSyncAlerts == 0) {\r
+               /* If number of sync alerts equals 0, should sync all data store in the client*/\r
+               return san;\r
+       } else {\r
+               san->syncAlerts = (SanSyncAlert *)calloc(san->cntSyncAlerts, sizeof(SanSyncAlert));\r
+\r
+               unsigned int indexNode;\r
+               for (indexNode = 0; indexNode < san->cntSyncAlerts; indexNode++) {\r
+\r
+                       WBXMLTreeNode* alert_node = (WBXMLTreeNode *)wbxml_list_get(alertnode_list, indexNode);\r
+\r
+                       char *alertData = NULL;\r
+                       WBXMLTreeNode *alertdata_node;\r
+                       if ((alertdata_node = __get_node_elt_from_name(alert_node, "Data", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Data]");\r
+                               goto error;\r
+                       }\r
+                       \r
+                       if (alertdata_node->children != NULL &&\r
+                               alertdata_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               alertdata_node->children->content != NULL) {\r
+                       \r
+                               alertData = (char *)wbxml_buffer_get_cstr(alertdata_node->children->content);\r
+                               if (!alertData) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL alertData detected. alertData MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+\r
+                               if (atoi(alertData) < 206 || atoi(alertData) > 210) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN doesn't support the sync type %d.", atoi(alertData));\r
+                                       goto error;\r
+                               }\r
+\r
+                               san->syncAlerts[indexNode].syncType = atoi(alertData);\r
+                       }\r
+\r
+                       char *alertURI = NULL;\r
+                       unsigned alertURIlen = 0;\r
+                       WBXMLTreeNode *alerturi_node;\r
+                       if ((alerturi_node = __get_node_elt_from_name(alert_node, "LocURI", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [LocURI]");\r
+                               goto error;\r
+                       }\r
+                       \r
+                       if (alerturi_node->children != NULL &&\r
+                               alerturi_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               alerturi_node->children->content != NULL) {\r
+\r
+                               alertURI = (char *)wbxml_buffer_get_cstr(alerturi_node->children->content);\r
+                               alertURIlen = wbxml_buffer_len(alerturi_node->children->content);\r
+                               if (!alertURI) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL alertURI detected. alertURI MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+\r
+                               san->syncAlerts[indexNode].serverURI = (char *)calloc(alertURIlen, sizeof(char));\r
+                               if (!san->syncAlerts[indexNode].serverURI) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN package memory allocation fail. [serverURI]");\r
+                                       goto error;\r
+                               }\r
+                               memcpy(san->syncAlerts[indexNode].serverURI, alertURI, alertURIlen);\r
+                       }\r
+\r
+                       char *alertContentType = NULL;\r
+                       unsigned alertContentTypeLen = 0;\r
+                       WBXMLTreeNode *alertcontenttype_node;\r
+                       if ((alertcontenttype_node = __get_node_elt_from_name(alert_node, "Type", TRUE)) == NULL) {\r
+                               FW_LOGV("[sanPackage11Parser] NULL from __get_node_elt_from_name. [Type]");\r
+                               goto error;\r
+                       }\r
+                       \r
+                       if (alertcontenttype_node->children != NULL &&\r
+                               alertcontenttype_node->children->type == WBXML_TREE_TEXT_NODE &&\r
+                               alertcontenttype_node->children->content != NULL) {\r
+\r
+                               alertContentType = (char *)wbxml_buffer_get_cstr(alertcontenttype_node->children->content);\r
+                               alertContentTypeLen = wbxml_buffer_len(alertcontenttype_node->children->content);\r
+\r
+                               if (!alertContentType) {\r
+                                       FW_LOGV("[sanPackage11Parser] NULL alertContentType detected. alertContentType MUST NOT be NULL.");\r
+                                       goto error;\r
+                               }\r
+\r
+                               int j;\r
+                               int cnt = (int)sizeof(contentTypeSupported)/sizeof(SanContentType);\r
+                               bool isContentSupported = false;\r
+\r
+                               for (j = 0 ; j < cnt ; j++) {\r
+                                       if (contentTypeSupported[j].strType == NULL)\r
+                                               continue;\r
+                                       if (strcmp(alertContentType, contentTypeSupported[j].strType) == 0) {\r
+                                               san->syncAlerts[indexNode].contentType = contentTypeSupported[j].strType;\r
+                                               isContentSupported = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               \r
+                               if (!isContentSupported) {\r
+                                       FW_LOGV("[sanPackage11Parser] SAN doesn't support the content type %s.", alertContentType);\r
+                                       goto error;\r
+                               }\r
+                       }\r
+               }       \r
+       }\r
+       \r
+       return san;\r
+\r
+       wbxml_tree_destroy(wbxml_tree);\r
+\r
+error:\r
+       sanPackageParserFree(san);\r
+       return NULL;\r
+       \r
+\r
+}\r
+\r
+void sanPackageParserFree(void *point)\r
+{\r
+       SanPackage *san = (SanPackage *)point;\r
+       if (san) {\r
+               if (san->msgBodyWithoutDigest)\r
+                       free(san->msgBodyWithoutDigest);\r
+               if (san->digest)\r
+                       free(san->digest);\r
+               if (san->cred) {\r
+                       if (san->cred->credFormat)\r
+                               free(san->cred->credFormat);\r
+                       if (san->cred->credAuth)\r
+                               free(san->cred->credAuth);\r
+                       if (san->cred->credData)\r
+                               free(san->cred->credData);\r
+                       free(san->cred);\r
+               }\r
+               if (san->serverID)\r
+                       free(san->serverID);\r
+               if (san->syncAlerts) {\r
+                       int i;\r
+                       for (i = 0 ; i < san->cntSyncAlerts ; i++) {\r
+                               if (san->syncAlerts[i].serverURI) {\r
+                                       free(san->syncAlerts[i].serverURI);\r
+                               }\r
+                       }\r
+                       free(san->syncAlerts);\r
+               }\r
+               free(san);\r
+       }\r
+}\r
+\r
+void sanPrintMsg(SanPackage *san)\r
+{\r
+       int i;\r
+\r
+       FW_LOGV("Printing SAN package ============================\n\n");\r
+\r
+       FW_LOGV("MsgBody without Digest :\n\t");\r
+       for (i = 0 ; i < san->msgBodyWithoutDigestLength ; i++) {\r
+               printf("%02x ", san->msgBodyWithoutDigest[i]);\r
+               if ((i + 1) % 16 == 0) printf("\n\t");\r
+       }\r
+       FW_LOGV("\n");\r
+\r
+       FW_LOGV("Digest : %s\n", san->digest);\r
+       if (san->cred) {\r
+               if (san->cred->credFormat)\r
+                       printf("Cred Format : %s\n", san->cred->credFormat);\r
+               if (san->cred->credAuth)\r
+                       printf("Cred Type : %s\n", san->cred->credAuth);\r
+               if (san->cred->credData)\r
+                       printf("Cred Data : %s\n", san->cred->credData);\r
+       }\r
+       FW_LOGV("Version : %d\n", san->version);\r
+       FW_LOGV("UI mode : %d\n", san->uiMode);\r
+       FW_LOGV("Initiator : %d\n", san->initiator);\r
+       FW_LOGV("Session ID : %u\n", san->sessionID);\r
+       FW_LOGV("Server ID : %s\n", san->serverID);\r
+       FW_LOGV("No. of Sync : %u\n", san->cntSyncAlerts);\r
+\r
+       for (i = 0 ; i < san->cntSyncAlerts ; i++) {\r
+               FW_LOGV("\n\t=== Sync No. %d ============\n", i+1);\r
+               FW_LOGV("\tSync type : %d\n", san->syncAlerts[i].syncType);\r
+               FW_LOGV("\tContent type : %s\n", san->syncAlerts[i].contentType);\r
+               FW_LOGV("\tServer URI : %s\n", san->syncAlerts[i].serverURI);\r
+       };\r
+\r
+}\r
+\r
diff --git a/src/Framework/Task/OMA_DS_Engine_Controller_Task.c b/src/Framework/Task/OMA_DS_Engine_Controller_Task.c
new file mode 100644 (file)
index 0000000..25ea88f
--- /dev/null
@@ -0,0 +1,1324 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @OMA_DS_Engine_Controller_Task.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of make and register task to Engine Controller
+ */
+
+
+#include <string.h>
+#include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
+
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceEngine/SE_Account.h"
+#include "ServiceEngine/SE_AutoConfig.h"
+#include "ServiceEngine/SE_Sync.h"
+#include "ServiceEngine/SE_Storage.h"
+#include "ServiceEngine/SE_Notification.h"
+
+#define LOG_TAG        "OMA_DS_COMMON"
+
+static GList *sync_request_id_list = NULL;
+
+static void __free_sync_categorie_list(void *list);
+static void __free_delete_profile_list(void *list);
+static void __free_resource_cp_list(void *list);
+
+static void __free_sync_category(sync_category *category);
+static void __free_resource_cp(resource_cp *resource);
+static request_msg_info_t *__create_request_msg_info(int sync_type, unsigned int request_id);
+static void __request_msg_info_free(request_msg_info_t *pInfo);
+
+static void *__string_copy_struct(void *string);
+
+
+
+static void __free_sync_categorie_list(void *list)
+{
+       GList *categories = (GList *)list;
+       GList *iter = NULL;
+       for (iter = categories; iter != NULL; iter = g_list_next(iter))
+               __free_sync_category(iter->data);
+
+
+       g_list_free(categories);
+}
+
+static void __free_delete_profile_list(void *list)
+{
+       GList *profiles = (GList *)list;
+       GList *iter = NULL;
+       for (iter = profiles; iter != NULL; iter = g_list_next(iter))
+               free(iter->data);
+
+       g_list_free(profiles);
+}
+
+static void __free_resource_cp_list(void *list)
+{
+       GList *profiles = (GList *)list;
+       GList *iter = NULL;
+       for (iter = profiles; iter != NULL; iter = g_list_next(iter))
+               __free_resource_cp(iter->data);
+
+       g_list_free(profiles);
+}
+
+static void __free_sync_category(sync_category *category)
+{
+       if (category->srcURI != NULL)
+               free(category->srcURI);
+
+       if (category->tgtURI != NULL)
+               free(category->tgtURI);
+
+       if (category->id != NULL)
+               free(category->id);
+
+       if (category->password != NULL)
+               free(category->password);
+
+       free(category);
+}
+
+static void __free_resource_cp(resource_cp *resource)
+{
+       if (resource->name != NULL)
+               free(resource->name);
+
+       if (resource->accept != NULL)
+               free(resource->accept);
+
+       if (resource->id != NULL)
+               free(resource->id);
+
+       if (resource->password != NULL)
+               free(resource->password);
+
+       if (resource->authType != NULL)
+               free(resource->authType);
+
+       if (resource->authData != NULL)
+               free(resource->authData);
+
+       free(resource);
+}
+
+static request_msg_info_t *__create_request_msg_info(int sync_type, unsigned int request_id)
+{
+       request_msg_info_t *pInfo = (request_msg_info_t *) calloc(1, sizeof(request_msg_info_t));
+       if (pInfo == NULL) {
+               return NULL;
+       }
+
+       pInfo->sync_type = sync_type;
+       pInfo->request_id = request_id;
+
+       return pInfo;
+}
+
+static void __request_msg_info_free(request_msg_info_t *pInfo)
+{
+       if (pInfo != NULL) {
+               free(pInfo);
+       }
+}
+
+static void *__string_copy_struct(void *string)
+{
+       return strdup((const char *)string);
+}
+
+
+
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_add_account_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profile", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[2] = {pParam_spec1, pParam_spec2};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("add_account",
+                                                                                       add_account_task_process, NULL, NULL,
+                                                                                       2, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+
+       return pTask_spec;
+}
+
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_edit_account_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profile", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[2] = {pParam_spec1, pParam_spec2};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("edit_account",
+                                                                                       edit_account_task_process, NULL, NULL,
+                                                                                       2, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+
+       return pTask_spec;
+}
+/*TODO have to be removed after removing vconf*/
+task_spec_t *make_autoconfigure_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profile", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *param_spec_array[1] = {pParam_spec1};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("auto_configure",
+                                                                                       autoconfigure_task_process, NULL, NULL,
+                                                                                       1, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_synchronize_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_structure("syncMode", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("sanPackage", NULL, sanPackageParserFree,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *param_spec_array[3] = {pParam_spec1, pParam_spec2, pParam_spec3};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("synchronize",
+                                                                                       synchronize_task_process, NULL, NULL,
+                                                                                       3, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_add_profile_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profileDirName", __string_copy_struct, free,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec2 = param_spec_structure("profileName", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec6 = param_spec_structure("syncMode", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec7 = param_spec_structure("syncType", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec8 = param_spec_structure("interval", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec9 = param_spec_structure("categories", NULL, __free_sync_categorie_list,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec10 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec11 = param_spec_int("accountId", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[11] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+                       pParam_spec6, pParam_spec7, pParam_spec8, pParam_spec9, pParam_spec10, pParam_spec11};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("add_profile",
+                                                                                       add_profile_task_process, NULL, NULL,
+                                                                                       11, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+       param_spec_unref(pParam_spec8);
+       param_spec_unref(pParam_spec9);
+       param_spec_unref(pParam_spec10);
+       param_spec_unref(pParam_spec11);
+
+       return pTask_spec;
+}
+
+
+task_spec_t *make_edit_profile_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_structure("profileName", __string_copy_struct, free,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec6 = param_spec_structure("syncMode", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec7 = param_spec_structure("syncType", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec8 = param_spec_structure("interval", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec9 = param_spec_structure("categories", NULL, __free_sync_categorie_list,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec10 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[10] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+                       pParam_spec6, pParam_spec7, pParam_spec8, pParam_spec9, pParam_spec10};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("edit_profile",
+                                                                                       edit_profile_task_process, NULL, NULL,
+                                                                                       10, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+       param_spec_unref(pParam_spec8);
+       param_spec_unref(pParam_spec9);
+       param_spec_unref(pParam_spec10);
+
+       return pTask_spec;
+}
+
+
+task_spec_t *make_delete_profile_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profiles", NULL, __free_delete_profile_list,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[2] = {pParam_spec1, pParam_spec2};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("delete_profile",
+                                                                                       delete_profile_task_process, NULL, NULL,
+                                                                                       2, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+
+       return pTask_spec;
+}
+
+
+task_spec_t *make_auto_configure_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profileDirName", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec2 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *param_spec_array[4] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("auto_configure",
+                                                                                       auto_configure_task_process, NULL, NULL,
+                                                                                       4, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+
+       return pTask_spec;
+}
+
+
+task_spec_t *make_sync_status_task()
+{
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("sync_status",
+                                                                                       sync_status_task_process, NULL, NULL,
+                                                                                       0, NULL);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_name_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec3 = param_spec_structure("profileName", __string_copy_struct, free,
+                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *param_spec_array[3] = {pParam_spec1, pParam_spec2, pParam_spec3};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_name",
+                                                                                       get_profile_name_task_process, NULL, NULL,
+                                                                                       3, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_server_info_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec3 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+
+       param_spec *param_spec_array[5] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_server_info",
+                                                                                       get_profile_server_info_task_process, NULL, NULL,
+                                                                                       5, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_sync_mode_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec3 = param_spec_structure("syncMode", __string_copy_struct, free,
+                                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("syncType", __string_copy_struct, free,
+                                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("interval", __string_copy_struct, free,
+                                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+
+       param_spec *param_spec_array[5] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_sync_mode",
+                                                                                       get_profile_sync_mode_task_process, NULL, NULL,
+                                                                                       5, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_sync_category_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("contentType", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *pParam_spec3 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec4 = param_spec_int("enabled", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec5 = param_spec_structure("srcURI", __string_copy_struct, free,
+                                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec6 = param_spec_structure("tgtURI", __string_copy_struct, free,
+                                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec7 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec8 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                                                       false, true, false, NULL, false, NULL, false, NULL);
+
+       param_spec *param_spec_array[8] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4,
+                       pParam_spec5, pParam_spec6, pParam_spec7, pParam_spec8};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_sync_category",
+                                                                                       get_profile_sync_category_task_process, NULL, NULL,
+                                                                                       8, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+       param_spec_unref(pParam_spec8);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_last_session_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *pParam_spec2 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec3 = param_spec_int("lastSessionStatus", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec4 = param_spec_int("lastSessionTime", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *param_spec_array[4] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4 };
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_last_session",
+                                                                                       get_profile_last_session_task_process, NULL, NULL,
+                                                                                       4, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_get_profile_statistics_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec2 = param_spec_int("contentType", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *pParam_spec3 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec4 = param_spec_structure("dbSynced", __string_copy_struct, free,
+                                                                                                                                               false, true, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_int("lastSessionTime", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec6 = param_spec_int("server2Client_Total", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec7 = param_spec_int("server2Client_NrOfAdd", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec8 = param_spec_int("server2Client_NrOfDelete", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec9 = param_spec_int("server2Client_NrOfReplace", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec10 = param_spec_int("client2Server_Total", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec11 = param_spec_int("client2Server_NrOfAdd", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec12 = param_spec_int("client2Server_NrOfDelete", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec13 = param_spec_int("client2Server_NrOfReplace", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[13] = {pParam_spec1, pParam_spec2, pParam_spec3,
+                       pParam_spec4, pParam_spec5, pParam_spec6, pParam_spec7, pParam_spec8,
+                       pParam_spec9, pParam_spec10, pParam_spec11, pParam_spec12, pParam_spec13};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("get_profile_statistics",
+                                                                                       get_profile_statistics_task_process, NULL, NULL,
+                                                                                       13, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+       param_spec_unref(pParam_spec8);
+       param_spec_unref(pParam_spec9);
+       param_spec_unref(pParam_spec10);
+       param_spec_unref(pParam_spec11);
+       param_spec_unref(pParam_spec12);
+       param_spec_unref(pParam_spec13);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_reset_synchronizing_profiles_task()
+{
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("reset_synchronizing_profiles",
+                                                                                       reset_synchronizing_profiles_task_process, NULL, NULL,
+                                                                                       0, NULL);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_add_profile_cp_task()
+{
+       param_spec *pParam_spec1 = param_spec_structure("profileName", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec2 = param_spec_structure("addr", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec3 = param_spec_structure("id", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec4 = param_spec_structure("password", __string_copy_struct, free,
+                                                                                                       true, false, false, NULL, false, NULL, false, NULL);
+       param_spec *pParam_spec5 = param_spec_structure("categories", NULL, __free_resource_cp_list,
+                                                                                                               true, false, false, NULL, false, NULL, false, NULL);
+
+       param_spec *pParam_spec6 = param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0);
+       param_spec *pParam_spec7 = param_spec_int("accountId", false, true, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[7] = {pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5,
+                       pParam_spec6, pParam_spec7};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("add_profile_cp",
+                                                                                       add_profile_cp_task_process, NULL, NULL,
+                                                                                       7, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+       param_spec_unref(pParam_spec2);
+       param_spec_unref(pParam_spec3);
+       param_spec_unref(pParam_spec4);
+       param_spec_unref(pParam_spec5);
+       param_spec_unref(pParam_spec6);
+       param_spec_unref(pParam_spec7);
+
+       return pTask_spec;
+}
+
+task_spec_t *make_refresh_from_service_task()
+{
+       param_spec *pParam_spec1 = param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0);
+
+       param_spec *param_spec_array[1] = {pParam_spec1};
+
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("refresh_from_service",
+                                                                                       refresh_from_service_task_process, NULL, NULL,
+                                                                                       1, param_spec_array);
+
+       param_spec_unref(pParam_spec1);
+
+       return pTask_spec;
+}
+
+
+/*FIXME cancel request to NA */
+/*task_spec_t *make_cancel_sync_request()
+{
+       task_spec_t *pTask_spec = task_spec_alloc_simple_task_spec("cancel_sync_request",
+                                                                                       cancel_sync_request_task_process, NULL, NULL,
+                                                                                       0, NULL);
+
+       return pTask_spec;
+}*/
+
+/*TODO have to be removed after removing vconf*/
+task_error_t add_account_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       /* step 1 : process add account */
+       char *profile = NULL;
+       int accountId;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profile);
+
+       int result = update_all_config(profile, true, &accountId);
+       if (result == 0)
+               err = TASK_ERROR_RUN_FAILED;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       /*step 2 : start refresh_from_service for added account */
+       void *in_param_value_array[1] = {&accountId};
+       int in_param_index_array[1] = {0};
+       ECValueType in_param_value_type_array[1] = {EC_VALUE_TYPE_INT};
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE, 0,
+                                                                                                                               1, in_param_index_array, in_param_value_type_array, in_param_value_array,
+                                                                                                                               NULL, NULL, (int *)&request_msg_id);
+
+       FW_LOGV("end");
+       return err;
+}
+
+/*TODO have to be removed after removing vconf*/
+task_error_t edit_account_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profile = NULL;
+       int accountId;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profile);
+
+       int result = update_all_config(profile, false, &accountId);
+       if (result == 0)
+               err = TASK_ERROR_RUN_FAILED;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       FW_LOGV("end");
+       return err;
+}
+
+/*TODO have to be removed after removing vconf*/
+task_error_t autoconfigure_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profile = NULL;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profile);
+
+       bool result = autoconfigure_from_vconf(profile);
+       if (result == false)
+               err = TASK_ERROR_RUN_FAILED;
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t synchronize_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       char *syncMode = NULL;
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+
+       SanPackage *pSanPackage = NULL;
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &pSanPackage);
+
+       FW_LOGV("accountId = %d",  accountId);
+       FW_LOGV("syncMode = %s", syncMode);
+
+       bool result = synchronize(accountId, syncMode, pSanPackage);
+       if (result == false)
+               err = TASK_ERROR_RUN_FAILED;
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t add_profile_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profileDirName = NULL;
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       GList *categories = NULL;
+       int accountId;
+
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profileDirName);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+       param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+       param_value_get_value(&(param_array[6]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
+       param_value_get_value(&(param_array[7]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
+       param_value_get_value(&(param_array[8]->param_value), EC_VALUE_TYPE_STRUCT, &categories);
+
+       res =  add_profile(profileDirName, profileName, addr, id, password, syncMode, syncType, interval, categories, &accountId);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[10]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t edit_profile_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId;
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       GList *categories = NULL;
+
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+       param_value_get_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+       param_value_get_value(&(param_array[6]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
+       param_value_get_value(&(param_array[7]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
+       param_value_get_value(&(param_array[8]->param_value), EC_VALUE_TYPE_STRUCT, &categories);
+
+       res =  edit_profile(accountId, profileName, addr, id, password, syncMode, syncType, interval, categories);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t delete_profile_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       bool res;
+       int result;
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       GList *profiles = NULL;
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profiles);
+
+       res = delete_profiles(profiles);
+       if (res == 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+
+       FW_LOGV("end");
+       return err;
+
+}
+
+task_error_t auto_configure_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profildDirName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profildDirName);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       bool result = autoconfigure(profildDirName, addr, id, password);
+       if (result == false)
+               err = TASK_ERROR_RUN_FAILED;
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t sync_status_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profileDirName = NULL;
+
+       get_synchronising_profile(&profileDirName);
+
+       FW_LOGV("profileDirName = %s", profileDirName);
+       send_noti_sync_status(profileDirName);
+
+       FW_LOGV("end");
+       return err;
+}
+
+task_error_t get_profile_name_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       char *profileName = NULL;
+       int result;
+       bool res;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       res = get_profile_name(accountId, &profileName);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_server_info_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       res = get_profile_server_info(accountId, &addr, &id, &password);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_set_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_sync_mode_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       res =  get_profile_sync_mode(accountId, &syncMode, &syncType, &interval);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &syncMode);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &syncType);
+       param_value_set_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &interval);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_sync_category_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       int contentType;
+
+       int enabled;
+       char *srcURI = NULL;
+       char *tgtURI = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &contentType);
+
+
+       res = get_profile_sync_category(accountId, contentType, &enabled, &srcURI, &tgtURI, &id, &password);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_INT, &enabled);
+       param_value_set_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &srcURI);
+       param_value_set_value(&(param_array[5]->param_value), EC_VALUE_TYPE_STRUCT, &tgtURI);
+       param_value_set_value(&(param_array[6]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_set_value(&(param_array[7]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_last_session_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       int lastSessionStatus;
+       int lastSessionTime;
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       res = get_last_session_info(accountId, &lastSessionStatus, &lastSessionTime);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &lastSessionStatus);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t get_profile_statistics_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId = 0;
+       int contentType;
+
+       char *dbSynced = NULL;
+       int lastSessionTime;
+       int server2Client_Total;
+       int server2Client_NrOfAdd;
+       int server2Client_NrOfDelete;
+       int server2Client_NrOfReplace;
+       int client2Server_Total;
+       int client2Server_NrOfAdd;
+       int client2Server_NrOfDelete;
+       int client2Server_NrOfReplace;
+
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+       if (accountId < 0) {
+               err = TASK_ERROR_RUN_FAILED;
+               return err;
+       }
+
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_INT, &contentType);
+
+
+       res =  get_profile_statistics(accountId, contentType, &dbSynced, &lastSessionTime,
+                       &server2Client_Total, &server2Client_NrOfAdd, &server2Client_NrOfDelete, &server2Client_NrOfReplace,
+                       &client2Server_Total, &client2Server_NrOfAdd, &client2Server_NrOfDelete, &client2Server_NrOfReplace);
+
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[2]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &dbSynced);
+       param_value_set_value(&(param_array[4]->param_value), EC_VALUE_TYPE_INT, &lastSessionTime);
+       param_value_set_value(&(param_array[5]->param_value), EC_VALUE_TYPE_INT, &server2Client_Total);
+       param_value_set_value(&(param_array[6]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfAdd);
+       param_value_set_value(&(param_array[7]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfDelete);
+       param_value_set_value(&(param_array[8]->param_value), EC_VALUE_TYPE_INT, &server2Client_NrOfReplace);
+       param_value_set_value(&(param_array[9]->param_value), EC_VALUE_TYPE_INT, &client2Server_Total);
+       param_value_set_value(&(param_array[10]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfAdd);
+       param_value_set_value(&(param_array[11]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfDelete);
+       param_value_set_value(&(param_array[12]->param_value), EC_VALUE_TYPE_INT, &client2Server_NrOfReplace);
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+task_error_t reset_synchronizing_profiles_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       reset_synchronizing_profiles();
+
+       FW_LOGV("end");
+       return err;
+}
+
+/*FIXME cancel request to NA */
+/*task_error_t cancel_sync_request_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       cancel_sync_request();
+
+       FW_LOGV("end");
+       return err;
+}*/
+
+task_error_t add_profile_cp_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       char *profileName = NULL;
+       char *addr = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       GList *categories = NULL;
+       int accountId;
+
+       bool res;
+       int result;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_STRUCT, &profileName);
+       param_value_get_value(&(param_array[1]->param_value), EC_VALUE_TYPE_STRUCT, &addr);
+       param_value_get_value(&(param_array[2]->param_value), EC_VALUE_TYPE_STRUCT, &id);
+       param_value_get_value(&(param_array[3]->param_value), EC_VALUE_TYPE_STRUCT, &password);
+       param_value_get_value(&(param_array[4]->param_value), EC_VALUE_TYPE_STRUCT, &categories);
+
+       res =  add_profile_cp(profileName, addr, id, password, categories, &accountId);
+       if (res == false) {
+               err = TASK_ERROR_RUN_FAILED;
+               result = 0;
+       } else
+               result = 1;
+
+       param_value_set_value(&(param_array[5]->param_value), EC_VALUE_TYPE_INT, &result);
+       param_value_set_value(&(param_array[6]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       FW_LOGV("end");
+       return err;
+}
+
+
+task_error_t refresh_from_service_task_process(unsigned int param_cnt, param_t **param_array)
+{
+       FW_LOGV("start");
+       task_error_t err = TASK_ERROR_RUN_SUCCESS;
+
+       int accountId;
+       bool res;
+
+       param_value_get_value(&(param_array[0]->param_value), EC_VALUE_TYPE_INT, &accountId);
+
+       res =  refresh_from_service_all(accountId);
+       if (res == false)
+               err = TASK_ERROR_RUN_FAILED;
+
+       FW_LOGV("end");
+       return err;
+}
+
+void insert_request_msg_info(int sync_type, unsigned int request_id)
+{
+       sync_request_id_list = g_list_prepend(sync_request_id_list, __create_request_msg_info(sync_type, request_id));
+}
+
+void delete_request_msg_info(unsigned int request_id)
+{
+       GList *iter = NULL;
+       request_msg_info_t *pMsg_info = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->request_id == request_id) {
+                       sync_request_id_list = g_list_remove_link(sync_request_id_list, iter);
+                       break;
+               }
+       }
+
+       if (iter != NULL) {
+               __request_msg_info_free(iter->data);
+               g_list_free_1(iter);
+       }
+}
+
+bool get_synchronizing_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_MANUAL || pMsg_info->sync_type == SYNC_MODE_PERIODIC  || pMsg_info->sync_type == SYNC_MODE_SAN) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+                       break;
+               }
+       }
+
+       return success;
+}
+
+bool get_manual_sync_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_MANUAL) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+                       break;
+               }
+       }
+
+       return success;
+}
+
+bool get_periodic_sync_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_PERIODIC) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+                       break;
+               }
+       }
+
+       return success;
+}
+
+bool get_san_sync_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_SAN) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+                       break;
+               }
+       }
+
+       return success;
+}
+
+bool get_auto_configure_request_id(unsigned int *pRequest_id)
+{
+       bool success = false;
+       request_msg_info_t *pMsg_info = NULL;
+       GList *iter = NULL;
+
+       for (iter = sync_request_id_list; iter != NULL; iter = g_list_next(iter)) {
+               pMsg_info = iter->data;
+
+               if (pMsg_info->sync_type == SYNC_MODE_AUTOCONFIG) {
+                       success = true;
+                       *pRequest_id = pMsg_info->request_id;
+
+                       __request_msg_info_free(pMsg_info);
+                       sync_request_id_list = g_list_delete_link(sync_request_id_list, iter);
+
+                       break;
+               }
+       }
+
+       return success;
+}
+
diff --git a/src/ServiceAdapter/NetworkBinder/NA_Binder.c b/src/ServiceAdapter/NetworkBinder/NA_Binder.c
new file mode 100644 (file)
index 0000000..cbd6cae
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @NA_Binder.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of header binder function for Network Adapter
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceAdapter/NetworkBinder/NA_Binder.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+int NA_http_header_binder(char *accType, char *loc_uri, bool isXML, GList **list)
+{
+       FW_LOGV("[NA Header Binder] start!!");
+
+       if (!strcmp(accType, "OMA_DS")) {
+               common_header_info *method = (common_header_info *)malloc(sizeof(common_header_info));
+               if (method == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'method' malloc fail !!");
+                       return 0;
+               }
+               memset(method, 0x00, sizeof(common_header_info));
+               method->key = "method";
+               method->value = "post";
+               *list = g_list_append(*list, method);
+
+               common_header_info *uri = (common_header_info *)malloc(sizeof(common_header_info));
+               if (uri == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'uri' malloc fail !!");
+                       return 0;
+               }
+               memset(uri, 0x00, sizeof(common_header_info));
+               uri->key = "uri";
+               uri->value = loc_uri;
+               *list = g_list_append(*list, uri);
+
+               common_header_info *cache_control = (common_header_info *)malloc(sizeof(common_header_info));
+               if (cache_control == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'cache_control' malloc fail !!");
+                       return 0;
+               }
+               memset(cache_control, 0x00, sizeof(common_header_info));
+               cache_control->key = "Cache-Control";
+               cache_control->value = "no-store, private";
+               *list = g_list_append(*list, cache_control);
+
+               common_header_info *connection = (common_header_info *)malloc(sizeof(common_header_info));
+               if (connection == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'connection' malloc fail !!");
+                       return 0;
+               }
+               memset(connection, 0x00, sizeof(common_header_info));
+               connection->key = "Connection";
+               connection->value = "Keep-Alive";
+               *list = g_list_append(*list, connection);
+
+               common_header_info *accept = (common_header_info *)malloc(sizeof(common_header_info));
+               if (accept == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'accept' malloc fail !!");
+                       return 0;
+               }
+               memset(accept, 0x00, sizeof(common_header_info));
+               accept->key = "Accept";
+               if (isXML == true)
+                       accept->value = "application/vnd.syncml+xml";
+               else
+                       accept->value = "application/vnd.syncml+wbxml";
+               *list = g_list_append(*list, accept);
+
+               common_header_info *accept_language = (common_header_info *)malloc(sizeof(common_header_info));
+               if (accept_language == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'accept_language' malloc fail !!");
+                       return 0;
+               }
+               memset(accept_language, 0x00, sizeof(common_header_info));
+               accept_language->key = "Accept-Language";
+               accept_language->value = "en-US";
+               *list = g_list_append(*list, accept_language);
+
+               common_header_info *accept_charset = (common_header_info *)malloc(sizeof(common_header_info));
+               if (accept_charset == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'accept_charset' malloc fail !!");
+                       return 0;
+               }
+               memset(accept_charset, 0x00, sizeof(common_header_info));
+               accept_charset->key = "Accept-Charset";
+               accept_charset->value = "UTF-8";
+               *list = g_list_append(*list, accept_charset);
+
+               common_header_info *content_type = (common_header_info *)malloc(sizeof(common_header_info));
+               if (content_type == 0x00) {
+                       FW_LOGE("[NA Header Binder] 'content_type' malloc fail !!");
+                       return 0;
+               }
+               memset(content_type, 0x00, sizeof(common_header_info));
+               content_type->key = "Content-Type";
+               if (isXML == true)
+                       content_type->value = "application/vnd.syncml+xml";
+               else
+                       content_type->value = "application/vnd.syncml+wbxml";
+               *list = g_list_append(*list, content_type);
+
+       }
+
+       GList *iter = NULL;
+       for (iter = *list; iter != NULL; iter = g_list_next(iter)) {
+               FW_LOGV("[NA_Header_Binder] key : %s, value : %s", ((common_header_info *)(iter->data))->key, ((common_header_info *)(iter->data))->value);
+       }
+
+       FW_LOGV("end");
+
+       return 1;
+}
+
+void free_header_info(common_header_info *pCommon_header_info)
+{
+       if (pCommon_header_info == NULL)
+               return;
+
+       free(pCommon_header_info);
+}
diff --git a/src/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.c b/src/ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.c
new file mode 100644 (file)
index 0000000..d75ae99
--- /dev/null
@@ -0,0 +1,4856 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @oma_ds_protocol_binder.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of callback function for Protocol Binder
+ */
+
+#include <glib.h>
+#include <assert.h>    /* TODO : replace this line to fw_assert.h */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/NetworkAssistant/protocol_binder/protocol_binder_util.h"
+#include "ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Command_Internal.h"
+#include "ServiceAdapter/SA_DevInf_Internal.h"
+#include "ServiceAdapter/SA_Command.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_DevInf.h"
+#include "ServiceAdapter/SA_Define.h"
+
+#define LOG_TAG        "OMA_DS_BINDER"
+
+static PROTOCOL_BINDER_ERROR __append_location_to_wbxml_node(Location *pLocation,
+               protocol_binder *pBinder,       WBXMLTreeNode *parent_node);
+
+static PROTOCOL_BINDER_ERROR __append_anchor_to_wbxml_node(Anchor *pAnchor,
+               protocol_binder *pBinder, WBXMLTreeNode *parent_node);
+
+static PROTOCOL_BINDER_ERROR __append_devinf_contenttype_to_wbxml_node(DevInfContentType *pDevInfContentType,
+               protocol_binder *pBinder, WBXMLTreeNode *parent_node, char *node);
+
+static PROTOCOL_BINDER_ERROR __append_cred_to_wbxml_node(Cred *pCred,  protocol_binder *pBinder, WBXMLTreeNode *parent_node) ;
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_devinf_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_syncml_start_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_header_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_final_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_body_start_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_status_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_alert_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_results_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_put_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_get_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_start_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_end_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_add_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_replace_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_delete_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_map_command_converter_function(protocol_binder *pBinder,
+                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node);
+
+static ProtocolVersion __get_oma_ds_protocol_version(char *verdtd);
+static DevInfVersion __get_oma_ds_devInf_version(char *verdtd);
+static DevInfDevTyp __get_oma_ds_devInf_device_type(char *devType);
+static DevInfContentType *__get_devinf_contenttype(WBXMLTreeNode *node);
+static Location *_get_location(WBXMLTreeNode *node);
+static Anchor *_get_anchor(WBXMLTreeNode *node);
+static Cred *__get_cred(WBXMLTreeNode *node);
+static Chal *_get_chal(WBXMLTreeNode *node);
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_devinf_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_header_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_results_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_put_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_get_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_alert_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_end_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_start_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_add_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_replace_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_delete_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_final_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_status_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                               WBXMLTreeNode *wbxml_dom_node, Content_Ptr *pContent);
+
+
+/*
+       PE_ADD,
+    PE_DELETE,
+    PE_REPLACE,
+    PE_ALERT,
+    PE_GET,
+    PE_MAP,
+    PE_PUT,
+    PE_RESULTS,
+    PE_STATUS,
+    PE_SYNC_START,
+    PE_SYNC_END,
+    PE_HEADER,
+    PE_FINAL
+
+    PE_COPY,
+    PE_EXEC,
+    PE_SEARCH,
+    PE_SEQUENCE_START,
+    PE_SEQUENCE_END,
+    PE_ATOMIC_START,
+    PE_ATOMIC_END,
+    PE_PUT_GET,
+    PE_CMD_GROUP,
+    PE_GENERIC,
+ */
+const Binder_function_info oma_ds_binder_function_info[] = {
+               { PE_SYNCML_START,              "SyncML",                       __oma_ds_binder_syncml_start_converter_function,                                NULL,                                                                                                                                                                                   false},
+               { PE_SYNCML_END,                "/SyncML",              NULL,                                                                                                                                                           NULL,                                                                                                                                                                                   false},
+               { PE_HEADER,                            "SyncHdr",                      __oma_ds_binder_header_converter_function,                                              __oma_ds_binder_header_reverse_converter_function,                                              true},
+               { PE_BODY_START,                        "SyncBody",             __oma_ds_binder_body_start_converter_function,                                  NULL,                                                                                                                                                                                   false},
+               { PE_BODY_END,                  "/SyncBody",            NULL,                                                                                                                                                           NULL,                                                                                                                                                                                   false},
+               { PE_FINAL,                                     "Final",                                __oma_ds_binder_final_converter_function,                                                       __oma_ds_binder_final_reverse_converter_function,                                                       true},
+               { PE_ALERT,                                     "Alert",                                __oma_ds_binder_alert_command_converter_function,                       __oma_ds_binder_alert_command_reverse_converter_function,                       true},
+               { PE_STATUS,                                    "Status",                       __oma_ds_binder_status_converter_function,                                              __oma_ds_binder_status_reverse_converter_function,                                              true},
+               { PE_RESULTS_START,     "Results",                      __oma_ds_binder_results_command_converter_function,             __oma_ds_binder_results_command_reverse_converter_function,             false},
+               { PE_RESULTS_END,               "/Results",             NULL,                                                                                                                                                           NULL,                                                                                                                                                                                   false},
+               { PE_PUT_START,                 "Put",                          __oma_ds_binder_put_command_converter_function,                 __oma_ds_binder_put_command_reverse_converter_function,                 false},
+               { PE_PUT_END,                           "/Put",                         NULL,                                                                                                                                                           NULL,                                                                                                                                                                                   false},
+               { PE_GET,                                               "Get",                          __oma_ds_binder_get_command_converter_function,                 __oma_ds_binder_get_command_reverse_converter_function,                 true},
+               { PE_SYNC_START,                        "Sync",                         __oma_ds_binder_sync_start_command_converter_function,  __oma_ds_binder_sync_start_command_reverse_converter_function,  false},
+               { PE_SYNC_END,                  "/Sync",                        __oma_ds_binder_sync_end_command_converter_function,    __oma_ds_binder_sync_end_command_reverse_converter_function,    false},
+               { PE_ADD,                                               "Add",                          __oma_ds_binder_add_command_converter_function,                 __oma_ds_binder_add_command_reverse_converter_function,                 true},
+               { PE_REPLACE,                           "Replace",                      __oma_ds_binder_replace_command_converter_function,             __oma_ds_binder_replace_command_reverse_converter_function,             true},
+               { PE_DELETE,                                    "Delete",                       __oma_ds_binder_delete_command_converter_function,              __oma_ds_binder_delete_command_reverse_converter_function,              true},
+               { PE_MAP,                                               "Map",                          __oma_ds_binder_map_command_converter_function,                 NULL,                                                                                                                                                                                   true},
+               { PE_DEVINF,                                    "DevInf",                       __oma_ds_binder_devinf_converter_function,                                              __oma_ds_binder_devinf_reverse_converter_function,                                              true}
+};
+
+
+
+static PROTOCOL_BINDER_ERROR __append_location_to_wbxml_node(Location *pLocation,
+                                                                                                                       protocol_binder *pBinder,
+                                                                                                                       WBXMLTreeNode *parent_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       if (pLocation->locURI != NULL) {
+               WBXMLTreeNode *LocURI = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               parent_node, ELEMENT_LOCURI, pLocation->locURI, strlen(pLocation->locURI));
+               if (LocURI == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       } else {
+               /* error case */
+       }
+
+       if (pLocation->locName != NULL) {
+               WBXMLTreeNode *locName = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                       parent_node, ELEMENT_LOCNAME, pLocation->locName, strlen(pLocation->locName));
+               if (locName == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __append_anchor_to_wbxml_node(Anchor *pAnchor,
+                                                                                                                       protocol_binder *pBinder,
+                                                                                                                       WBXMLTreeNode *parent_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder, parent_node, ELEMENT_META);
+       if (meta_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *anchor_node = add_child_wbxml_node_using_xml_name(pBinder, meta_node, ELEMENT_ANCHOR);
+       if (anchor_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pAnchor->lastAnchor) {
+               WBXMLTreeNode *last_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               anchor_node, ELEMENT_LAST, pAnchor->lastAnchor, strlen(pAnchor->lastAnchor));
+               if (last_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pAnchor->nextAnchor) {
+               WBXMLTreeNode *next_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               anchor_node, ELEMENT_NEXT, pAnchor->nextAnchor, strlen(pAnchor->nextAnchor));
+               if (next_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __append_devinf_contenttype_to_wbxml_node(DevInfContentType *pDevInfContentType,
+                                                                                                                       protocol_binder *pBinder,
+                                                                                                                       WBXMLTreeNode *parent_node,
+                                                                                                                       char *node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       WBXMLTreeNode *xnode = add_child_wbxml_node_using_xml_name(pBinder, parent_node, node);
+       if (xnode == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cttype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       xnode, "CTType", pDevInfContentType->cttype, strlen(pDevInfContentType->cttype));
+       if (cttype_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *verct_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       xnode, "VerCT", pDevInfContentType->verct, strlen(pDevInfContentType->verct));
+       if (verct_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __append_cred_to_wbxml_node(Cred *pCred,
+                                                                                                                       protocol_binder *pBinder,
+                                                                                                                       WBXMLTreeNode *parent_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /* check validity */
+       WBXMLTreeNode *cred_node = add_child_wbxml_node_using_xml_name(pBinder, parent_node, ELEMENT_CRED);
+       if (cred_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder, cred_node, ELEMENT_META);
+       if (meta_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+
+       WBXMLTreeNode *type_node = NULL;
+
+       switch (pCred->type) {
+       case AUTH_TYPE_BASIC:
+
+               if (pCred->format == FORMAT_TYPE_BASE64) {
+                       WBXMLTreeNode *format_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_FORMAT,  ELEMENT_FORMAT_BASE64, strlen(ELEMENT_FORMAT_BASE64));
+                       if (format_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, ELEMENT_AUTH_BASIC, strlen(ELEMENT_AUTH_BASIC));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (pCred->data) {
+                       WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       cred_node, ELEMENT_DATA,  pCred->data, strlen(pCred->data));
+                       if (data_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+               break;
+       case AUTH_TYPE_MD5:
+
+               if (pCred->format == FORMAT_TYPE_BASE64) {
+                       WBXMLTreeNode *format_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_FORMAT, ELEMENT_FORMAT_BASE64, strlen(ELEMENT_FORMAT_BASE64));
+                       if (format_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, ELEMENT_AUTH_MD5, strlen(ELEMENT_AUTH_MD5));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (pCred->data) {
+                       WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       cred_node, ELEMENT_DATA,  pCred->data, strlen(pCred->data));
+                       if (data_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+               break;
+       default:
+               break;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_devinf_converter_function(protocol_binder *pBinder,
+                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Item *pItem = (Item *)pContent;
+       DevInf *pDevInf = pItem->private.devInf;
+
+       if (pItem) {
+               WBXMLTreeNode *item_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder, item_node, ELEMENT_SOURCE);
+               if (source_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pItem->source, pBinder, source_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+               WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name(pBinder, item_node, ELEMENT_DATA);
+               if (data_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               /* devinf language setting */
+               switch_protocol(pBinder, PROTOCOL_SYNCML_DEVINF12);
+               WBXMLTree *devinf_tree = create_wbxml_tree(pBinder);
+               if (devinf_tree == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               add_wbxml_tree_to_wbxml_node(data_node, devinf_tree);
+
+               /* create root node of devinf tree*/
+               WBXMLTreeNode *devinf_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_DEVINF);
+               if (devinf_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               set_wbxml_tree_root(devinf_tree, devinf_node);
+
+               WBXMLTreeNode *verDTD_node = NULL;
+               switch (pDevInf->version) {
+               case DEVINF_VERSION_UNKNOWN:
+                       verDTD_node = add_child_wbxml_node_using_xml_name(pBinder, devinf_node, ELEMENT_VERDTD);
+                       break;
+               case DEVINF_VERSION_10:
+                       verDTD_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_10, strlen(ELEMENT_VERDRD_10));
+                       break;
+               case DEVINF_VERSION_11:
+                       verDTD_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_11, strlen(ELEMENT_VERDRD_11));
+                       break;
+               case DEVINF_VERSION_12:
+                       verDTD_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_12, strlen(ELEMENT_VERDRD_12));
+                       break;
+               }
+
+               if (verDTD_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *man_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_MAN, pDevInf->manufacturer, strlen(pDevInf->manufacturer));
+               if (man_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *mod_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_MOD, pDevInf->model, strlen(pDevInf->model));
+               if (mod_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+
+               if (pDevInf->oem) {
+                       WBXMLTreeNode *oem_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_OEM, pDevInf->oem, strlen(pDevInf->oem));
+                       if (oem_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               WBXMLTreeNode *FwV_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_FWV, pDevInf->firmwareVersion, strlen(pDevInf->firmwareVersion));
+               if (FwV_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *SwV_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_SWV, pDevInf->softwareVersion, strlen(pDevInf->softwareVersion));
+               if (SwV_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *HwV_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_HWV, pDevInf->hardwareVersion, strlen(pDevInf->hardwareVersion));
+               if (HwV_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *devID_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               devinf_node, ELEMENT_DEVID, pDevInf->devid, strlen(pDevInf->devid));
+               if (devID_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *devTyp_node = NULL;
+               switch (pDevInf->devtyp) {
+               case DEVINF_DEVTYPE_UNKNOWN:
+                       devTyp_node = add_child_wbxml_node_using_xml_name(pBinder, devinf_node, ELEMENT_DEVTYP);
+                       break;
+               case DEVINF_DEVTYPE_PAGER:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_PAGER, strlen(ELEMENT_PAGER));
+                       break;
+               case DEVINF_DEVTYPE_HANDHELD:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_HANDHELD, strlen(ELEMENT_HANDHELD));
+                       break;
+               case DEVINF_DEVTYPE_PDA:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_PDA, strlen(ELEMENT_PDA));
+                       break;
+               case DEVINF_DEVTYPE_PHONE:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_PHONE, strlen(ELEMENT_PHONE));
+                       break;
+               case DEVINF_DEVTYPE_SMARTPHONE:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_SMARTPHONE, strlen(ELEMENT_SMARTPHONE));
+                       break;
+               case DEVINF_DEVTYPE_SERVER:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_SERVER, strlen(ELEMENT_SERVER));
+                       break;
+               case DEVINF_DEVTYPE_WORKSTATION:
+                       devTyp_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       devinf_node, ELEMENT_DEVTYP, ELEMENT_WORKSTATION, strlen(ELEMENT_WORKSTATION));
+                       break;
+               }
+
+               if (devTyp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (pDevInf->supportsUTC) {
+                       WBXMLTreeNode *supportUTC_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       devinf_node, ELEMENT_UTC);
+                       if (supportUTC_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               if (pDevInf->supportsLargeObjs) {
+                       WBXMLTreeNode *supportLargeObjs_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       devinf_node, ELEMENT_SUPPORTLARGEOBJS);
+                       if (supportLargeObjs_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               if (pDevInf->supportsNumberOfChanges) {
+                       WBXMLTreeNode *supportNumberOfChanges_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       devinf_node, ELEMENT_SUPPORTNUMBEROFCHANGES);
+                       if (supportNumberOfChanges_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               GList *datastoreIter = NULL;
+               DevInfDataStore *devInfDataStore = NULL;
+               for (datastoreIter = pDevInf->datastores; datastoreIter != NULL; datastoreIter = g_list_next(datastoreIter)) {
+                       devInfDataStore = datastoreIter->data;
+
+                       WBXMLTreeNode *datastore_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       devinf_node, ELEMENT_DATASTORE);
+                       if (datastore_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *sourceRef_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       datastore_node, ELEMENT_SOURCEREF, devInfDataStore->sourceref, strlen(devInfDataStore->sourceref));
+                       if (sourceRef_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (devInfDataStore->displayname) {
+                               WBXMLTreeNode *displayname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               datastore_node, ELEMENT_DISPLAYNAME, devInfDataStore->displayname, strlen(devInfDataStore->displayname));
+                               if (displayname_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+
+                       if (devInfDataStore->maxGUIDSize) {
+                               char *str_maxguidsize = g_strdup_printf("%u", devInfDataStore->maxGUIDSize);
+                               if (str_maxguidsize == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               WBXMLTreeNode *maxguidsize_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               datastore_node, ELEMENT_MAXGUIDSIZE, str_maxguidsize, strlen(str_maxguidsize));
+
+                               if (str_maxguidsize != NULL)
+                                       free(str_maxguidsize);
+
+                               if (maxguidsize_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+
+                       __append_devinf_contenttype_to_wbxml_node(devInfDataStore->rxPref, pBinder,
+                                       datastore_node, ELEMENT_RX_PREF);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+
+                       GList *rxIter = NULL;
+                       DevInfContentType *devInfContentType = NULL;
+                       for (rxIter = devInfDataStore->rx; rxIter != NULL; rxIter = g_list_next(rxIter)) {
+                               devInfContentType = rxIter->data;
+                               __append_devinf_contenttype_to_wbxml_node(devInfContentType, pBinder,
+                                               datastore_node, ELEMENT_RX);
+                               if (err != PROTOCOL_BINDER_OK)
+                                       goto error;
+                       }
+
+                       __append_devinf_contenttype_to_wbxml_node(devInfDataStore->txPref, pBinder,
+                                       datastore_node, ELEMENT_TX_PREF);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+
+                       GList *txIter = NULL;
+                       for (txIter = devInfDataStore->tx; txIter != NULL; txIter = g_list_next(txIter)) {
+                               devInfContentType = txIter->data;
+                               __append_devinf_contenttype_to_wbxml_node(devInfContentType, pBinder,
+                                               datastore_node, ELEMENT_TX);
+                               if (err != PROTOCOL_BINDER_OK)
+                                       goto error;
+
+                       }
+
+                       GList *ctcapIter = NULL;
+                       DevInfCTCap *devInfCTCap = NULL;
+                       for (ctcapIter = devInfDataStore->ctcaps; ctcapIter != NULL;  ctcapIter = g_list_next(ctcapIter)) {
+                               devInfCTCap = ctcapIter->data;
+
+                               WBXMLTreeNode *ctcap_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                               datastore_node, ELEMENT_CTCAP);
+                               if (ctcap_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               WBXMLTreeNode *cttype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               ctcap_node, ELEMENT_CTTYPE, devInfCTCap->ct->cttype, strlen(devInfCTCap->ct->cttype));
+                               if (cttype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               WBXMLTreeNode *verct_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               ctcap_node, ELEMENT_VERCT, devInfCTCap->ct->verct, strlen(devInfCTCap->ct->verct));
+                               if (verct_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               /*TODO FieldLevel*/
+
+                               GList *propertyIter = NULL;
+                               DevInfProperty *devInfProperty = NULL;
+                               for (propertyIter = devInfCTCap->properties; propertyIter != NULL; propertyIter = g_list_next(propertyIter)) {
+                                       devInfProperty = propertyIter->data;
+
+                                       WBXMLTreeNode *property_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                                       ctcap_node, ELEMENT_PROPERTY);
+                                       if (property_node == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+
+                                       WBXMLTreeNode *propname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                       property_node, ELEMENT_PROPNAME, devInfProperty->propName, strlen(devInfProperty->propName));
+                                       if (propname_node == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+
+                                       if (devInfProperty->dataType) {
+                                               WBXMLTreeNode *datatype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_DATATYPE, devInfProperty->dataType, strlen(devInfProperty->dataType));
+                                               if (datatype_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       if (devInfProperty->maxOccur) {
+                                               char *str_maxoccur = g_strdup_printf("%u", devInfProperty->maxOccur);
+                                               if (str_maxoccur == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               WBXMLTreeNode *maxoccur_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_MAXOCCUR, str_maxoccur, strlen(str_maxoccur));
+
+                                               if (str_maxoccur != NULL)
+                                                       free(str_maxoccur);
+
+                                               if (maxoccur_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       if (devInfProperty->maxSize) {
+                                               char *str_maxsize = g_strdup_printf("%u", devInfProperty->maxSize);
+                                               if (str_maxsize == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               WBXMLTreeNode *maxsize_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_MAXSIZE, str_maxsize, strlen(str_maxsize));
+
+                                               if (str_maxsize != NULL)
+                                                       free(str_maxsize);
+
+                                               if (maxsize_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       if (devInfProperty->noTruncate) {
+                                               WBXMLTreeNode *notruncate_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                                               property_node, ELEMENT_NOTRUNCATE);
+                                               if (notruncate_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       GList *valenum = NULL;
+                                       char *val = NULL;
+                                       for (valenum = devInfProperty->valEnums; valenum != NULL; valenum = g_list_next(valenum)) {
+                                               val = valenum->data;
+                                               WBXMLTreeNode *valenum_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_VALENUM, val, strlen(val));
+                                               if (valenum_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       if (devInfProperty->displayName) {
+                                               WBXMLTreeNode *displayname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               property_node, ELEMENT_DISPLAYNAME, devInfProperty->displayName, strlen(devInfProperty->displayName));
+                                               if (displayname_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+                                       }
+
+                                       GList *propparamIter = NULL;
+                                       DevInfPropParam *devInfPropParam = NULL;
+                                       for (propparamIter = devInfProperty->propParams; propparamIter != NULL; propparamIter = g_list_next(propparamIter)) {
+                                               devInfPropParam = propparamIter->data;
+
+                                               WBXMLTreeNode *propparam_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                                               property_node, ELEMENT_PROPPARAM);
+                                               if (propparam_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               WBXMLTreeNode *paramname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               propparam_node, ELEMENT_PARAMNAME, devInfPropParam->paramName, strlen(devInfPropParam->paramName));
+                                               if (paramname_node == NULL) {
+                                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               if (devInfPropParam->dataType) {
+                                                       WBXMLTreeNode *datatype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                                       propparam_node, ELEMENT_DATATYPE, devInfPropParam->dataType, strlen(devInfPropParam->dataType));
+                                                       if (datatype_node == NULL) {
+                                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                               goto error;
+                                                       }
+                                               }
+
+                                               valenum = NULL;
+                                               val = NULL;
+                                               for (valenum = devInfPropParam->valEnums; valenum != NULL; valenum = g_list_next(valenum)) {
+                                                       val = valenum->data;
+                                                       WBXMLTreeNode *valenum_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                                       propparam_node, ELEMENT_VALENUM, val, strlen(val));
+                                                       if (valenum_node == NULL) {
+                                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                               goto error;
+                                                       }
+                                               }
+
+                                               if (devInfPropParam->displayName) {
+                                                       WBXMLTreeNode *displayname_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                                       propparam_node, ELEMENT_DISPLAYNAME, devInfPropParam->displayName, strlen(devInfPropParam->displayName));
+                                                       if (displayname_node == NULL) {
+                                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                               goto error;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+                       /*TODO DSMem*/
+
+                       if (devInfDataStore->supportsHierarchicalSync) {
+                               WBXMLTreeNode *supportshierarchicalsync_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                               datastore_node, ELEMENT_SUPPORTHIERARCHICALSYNC);
+                               if (supportshierarchicalsync_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+
+                       WBXMLTreeNode *synccap_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       datastore_node, ELEMENT_SYNCCAP);
+                       if (synccap_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_TWO_WAY)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_1, strlen(ELEMENT_SYNCTYPE_1));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_SLOW_SYNC)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_2, strlen(ELEMENT_SYNCTYPE_2));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_3, strlen(ELEMENT_SYNCTYPE_3));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_4, strlen(ELEMENT_SYNCTYPE_4));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_5, strlen(ELEMENT_SYNCTYPE_5));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_SERVER)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_6, strlen(ELEMENT_SYNCTYPE_6));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       if (get_devinf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC)) {
+                               WBXMLTreeNode *synctype_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_7, strlen(ELEMENT_SYNCTYPE_7));
+                               if (synctype_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       /*TODO filter-rx, filterCap*/
+               }
+               undo_switch_protocol(pBinder);
+               *ppWbxml_dom_node =  item_node;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error : %d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_syncml_start_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       WBXMLTreeNode *syncml_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_SYNCML);
+       if (syncml_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       *ppWbxml_dom_node = syncml_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_header_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       SyncHdr *pSyncHdr = (SyncHdr *)pContent;
+
+       /* add SyncHdr, VerDTD, VerProto node */
+       WBXMLTreeNode *synchdr_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_SYNCHDR);
+       if (synchdr_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+
+       char *verDTD = ELEMENT_VERDTD;
+       char *verProto = ELEMENT_VERPROTO;
+
+       char *verDTD_data = NULL;
+       char *verProto_data = NULL;
+       if (pSyncHdr->version == VERSION_10) {
+               verDTD_data = ELEMENT_VERDRD_10;
+               verProto_data = ELEMENT_VERPROTO_10;
+       } else if (pSyncHdr->version == VERSION_11) {
+               verDTD_data = ELEMENT_VERDRD_11;
+               verProto_data = ELEMENT_VERPROTO_11;
+       } else if (pSyncHdr->version == VERSION_12) {
+               verDTD_data = ELEMENT_VERDRD_12;
+               verProto_data = ELEMENT_VERPROTO_12;
+       }
+
+       if (verDTD_data == NULL || verProto_data  == NULL) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *verdtd_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       synchdr_node, verDTD, verDTD_data, strlen(verDTD_data));
+       if (verdtd_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *verProto_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       synchdr_node, verProto, verProto_data, strlen(verProto_data));
+       if (verProto_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       /* session ID */
+       WBXMLTreeNode *sessionID_node = NULL;
+       if (pSyncHdr->sessionID != NULL)
+               sessionID_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               synchdr_node, ELEMENT_SESSIONID, pSyncHdr->sessionID, strlen(pSyncHdr->sessionID));
+       else
+               sessionID_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               synchdr_node, ELEMENT_SESSIONID);
+
+       if (sessionID_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       /* msgID */
+       char *msgID_data = g_strdup_printf("%u", pSyncHdr->messageID);
+       if (msgID_data == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *msgID_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       synchdr_node, ELEMENT_MSGID, msgID_data, strlen(msgID_data));
+
+       if (msgID_data != NULL)
+               free(msgID_data);
+
+       if (msgID_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                       synchdr_node, ELEMENT_TARGET);
+       if (target_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       err = __append_location_to_wbxml_node(pSyncHdr->target, pBinder, target_node);
+       if (err != PROTOCOL_BINDER_OK)
+               goto error;
+
+
+       WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                       synchdr_node, ELEMENT_SOURCE);
+       if (source_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       err = __append_location_to_wbxml_node(pSyncHdr->source, pBinder, source_node);
+       if (err != PROTOCOL_BINDER_OK)
+               goto error;
+
+
+       if (pSyncHdr->responseURI) {
+               WBXMLTreeNode *respuri_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               synchdr_node, ELEMENT_RESPURI, pSyncHdr->responseURI, strlen(pSyncHdr->responseURI));
+               if (respuri_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+
+       if (pSyncHdr->noResponse) {
+               WBXMLTreeNode *noResponse_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               synchdr_node, ELEMENT_NORESP);
+               if (noResponse_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+
+       if (pSyncHdr->cred) {
+               err = __append_cred_to_wbxml_node(pSyncHdr->cred, pBinder, synchdr_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+
+       char *meta = ELEMENT_META;
+       if (pSyncHdr->maxmsgsize != 0 || pSyncHdr->maxobjsize != 0) {
+               WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               synchdr_node, meta);
+               if (meta_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               unsigned int maxmsgsize = pSyncHdr->maxmsgsize;
+               unsigned int maxobjsize = pSyncHdr->maxobjsize;
+
+
+               if (maxmsgsize != 0) {
+                       char *str_maxmsgsize = g_strdup_printf("%u", maxmsgsize);
+                       if (str_maxmsgsize == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *maxmsgsize_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_MAXMSGSIZE, str_maxmsgsize, strlen(str_maxmsgsize));
+                       if (str_maxmsgsize != NULL)
+                               free(str_maxmsgsize);
+
+                       if (maxmsgsize_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+               if (maxobjsize != 0) {
+                       char *str_maxobjsize = g_strdup_printf("%u", maxobjsize);
+                       if (str_maxobjsize == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *maxobjsize_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_MAXOBJSIZE, str_maxobjsize, strlen(str_maxobjsize));
+                       if (str_maxobjsize != NULL)
+                               free(str_maxobjsize);
+
+                       if (maxobjsize_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+       }
+
+       *ppWbxml_dom_node = synchdr_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_final_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                                                                               Content_Ptr pContent,
+                                                                                                                                                                                                                               WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       WBXMLTreeNode *final_node = create_wbxml_node_using_xml_name(pBinder, "Final");
+       if (final_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       *ppWbxml_dom_node = final_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error :%d", err);
+       return err;
+
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_body_start_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       WBXMLTreeNode *syncbody_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_SYNCBODY);
+       if (syncbody_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       *ppWbxml_dom_node = syncbody_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_status_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Status *pStatus = (Status *)pContent;
+       assert(pStatus != NULL);
+
+       CommandType type = pStatus->type;
+
+       char *str_cmdID = NULL;
+       char *str_msgRef = NULL;
+       char *str_cmdRef = NULL;
+
+       WBXMLTreeNode *status_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_STATUS);
+       if (status_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       unsigned int cmdID = pStatus->cmdID;
+       str_cmdID = g_strdup_printf("%u", cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       unsigned int msgRef = pStatus->msgRef;
+       str_msgRef = g_strdup_printf("%u", msgRef);
+       if (str_msgRef == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *msgref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_MSGREF, str_msgRef, strlen(str_msgRef));
+       if (msgref_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       unsigned int cmdRef = pStatus->cmdRef;
+       str_cmdRef = g_strdup_printf("%u", cmdRef);
+       if (str_cmdRef == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_CMDREF, str_cmdRef, strlen(str_cmdRef));
+       if (cmdref_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       char *str_command = NULL;
+       switch (type) {
+       case COMMAND_TYPE_ALERT:
+               {
+                       str_command = ELEMENT_ALERT;
+               }
+               break;
+       case COMMAND_TYPE_SYNC_START:
+               {
+                       str_command = ELEMENT_SYNC;
+               }
+               break;
+       case COMMAND_TYPE_PUT:
+               {
+                       str_command = ELEMENT_PUT;
+               }
+               break;
+       case COMMAND_TYPE_HEADER:
+               {
+                       str_command = ELEMENT_SYNCHDR;
+               }
+               break;
+       case COMMAND_TYPE_ADD:
+               {
+                       str_command = ELEMENT_ADD;
+               }
+               break;
+       case COMMAND_TYPE_REPLACE:
+               {
+                       str_command = ELEMENT_REPLACE;
+               }
+               break;
+       case COMMAND_TYPE_DELETE:
+               {
+                       str_command = ELEMENT_DELETE;
+               }
+               break;
+       case COMMAND_TYPE_MAP:
+               {
+                       str_command = ELEMENT_MAP;
+               }
+               break;
+       case COMMAND_TYPE_GET:
+               {
+                       str_command = ELEMENT_GET;
+               }
+               break;
+       case COMMAND_TYPE_RESULTS:
+               {
+                       str_command = ELEMENT_RESULTS;
+               }
+               break;
+       default:
+               break;
+       }
+
+       if (str_command == NULL) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *command_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_CMD, str_command, strlen(str_command));
+       if (command_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pStatus->targetRef) {
+               WBXMLTreeNode *targetref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               status_node, ELEMENT_TARGETREF, pStatus->targetRef->locURI, strlen(pStatus->targetRef->locURI));
+               if (targetref_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pStatus->sourceRef) {
+               WBXMLTreeNode *sourceref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               status_node, ELEMENT_SOURCEREF, pStatus->sourceRef->locURI, strlen(pStatus->sourceRef->locURI));
+               if (sourceref_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pStatus->cred) {
+               err = __append_cred_to_wbxml_node(pStatus->cred, pBinder, status_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       if (pStatus->chal) {
+                       /*TODO chal*/
+       }
+
+       WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       status_node, ELEMENT_DATA, pStatus->data, strlen(pStatus->data));
+       if (data_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (type == COMMAND_TYPE_ALERT) {
+               if (pStatus->item) {
+                       WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       status_node, ELEMENT_ITEM);
+                       if (item_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *item_data_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_DATA);
+                       if (item_data_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *item_data_Anchor_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_data_node, ELEMENT_ANCHOR);
+                       if (item_data_Anchor_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (pStatus->item->anchor) {
+                               WBXMLTreeNode *item_data_Anchor_Next_node =
+                                               add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                               item_data_Anchor_node, ELEMENT_NEXT, pStatus->item->anchor->nextAnchor,
+                                                               strlen(pStatus->item->anchor->nextAnchor));
+
+                               if (item_data_Anchor_Next_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_cmdRef != NULL)
+               free(str_cmdRef);
+
+       if (str_msgRef != NULL)
+               free(str_msgRef);
+
+       *ppWbxml_dom_node = status_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_cmdRef != NULL)
+               free(str_cmdRef);
+
+       if (str_msgRef != NULL)
+               free(str_msgRef);
+
+       FW_LOGE("error :%d", err);
+       return err;
+
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_alert_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+
+       CommandAlertPrivate *pAlert = (CommandAlertPrivate *)(&(pCommand->private));
+
+       char *str_cmdID = NULL;
+       char *str_alert_type  = NULL;
+
+       if (!pAlert) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       if (pAlert->type == ALERT_UNKNOWN) {
+               /* error case */
+               err = PROTOCOL_BINDER_INVALID_INPUT_PARAMETER;
+               goto error;
+       }
+
+       WBXMLTreeNode *alert_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_ALERT);
+       if (alert_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       alert_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               alert_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, alert_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       str_alert_type = g_strdup_printf("%u",  pAlert->type);
+       if (str_alert_type == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       alert_node, ELEMENT_DATA, str_alert_type, strlen(str_alert_type));
+       if (data_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       /* item */
+       if (pCommand->source != NULL && pCommand->target != NULL) {
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               alert_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               item_node, ELEMENT_TARGET);
+               if (target_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->target, pBinder, target_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+
+               WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               item_node, ELEMENT_SOURCE);
+               if (source_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->source, pBinder, source_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+
+               if (pAlert->anchor != NULL) {
+                       err = __append_anchor_to_wbxml_node(pAlert->anchor, pBinder, item_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_alert_type != NULL)
+               free(str_alert_type);
+
+       *ppWbxml_dom_node = alert_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_alert_type != NULL)
+               free(str_alert_type);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_results_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+       CommandResultsPrivate *pResults = (CommandResultsPrivate *)(&(pCommand->private));
+
+       char *str_cmdID = NULL;
+       char *str_cmdRef  = NULL;
+       char *str_msgRef = NULL;
+
+       if (!pResults) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       if (pResults->item == NULL) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       char *content_type = (pResults->item)->contenttype;
+       if (!content_type) {
+               /* error case */
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+
+       WBXMLTreeNode *results_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_RESULTS);
+       if (results_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID != NULL) {
+               WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               results_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+               if (cmdid_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+
+       if (pResults->msgRef) {
+               str_msgRef = g_strdup_printf("%u", pResults->msgRef);
+               if (str_msgRef == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *msgref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               results_node, ELEMENT_MSGREF, str_msgRef, strlen(str_msgRef));
+               if (msgref_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       str_cmdRef = g_strdup_printf("%u", pResults->cmdRef);
+       if (str_cmdRef == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *msgref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       results_node, ELEMENT_CMDREF, str_cmdRef, strlen(str_cmdRef));
+       if (msgref_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (content_type) {
+               WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               results_node, ELEMENT_META);
+               if (meta_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *type_node  = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pResults->targetRef) {
+               WBXMLTreeNode *targetref_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               results_node, ELEMENT_TARGETREF, pResults->targetRef->locURI, strlen(pResults->targetRef->locURI));
+               if (targetref_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_cmdRef != NULL)
+               free(str_cmdRef);
+
+       if (str_msgRef != NULL)
+               free(str_msgRef);
+
+       *ppWbxml_dom_node = results_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_cmdRef != NULL)
+               free(str_cmdRef);
+
+       if (str_msgRef != NULL)
+               free(str_msgRef);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_put_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+       CommandAccessPrivate *pAccess = (CommandAccessPrivate *)(&(pCommand->private));
+       char *str_cmdID = NULL;
+
+       if (!pAccess) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       char *content_type = (pAccess->item)->contenttype;
+       if (!content_type) {
+               /* error case */
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *put_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_PUT);
+       if (put_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       put_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               put_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, put_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       if (content_type) {
+               WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               put_node, ELEMENT_META);
+               if (meta_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       *ppWbxml_dom_node = put_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_get_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+       CommandAccessPrivate *pAccess = (CommandAccessPrivate *)(&(pCommand->private));
+       char *str_cmdID = NULL;
+
+       if (!pAccess) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!pAccess->item) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       char *content_type = (pAccess->item)->contenttype;
+
+       if (!content_type) {
+               /* error case */
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *get_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_GET);
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       get_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               get_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, get_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       if (content_type) {
+               WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               get_node, ELEMENT_META);
+               if (meta_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               meta_node, ELEMENT_TYPE, content_type, strlen(content_type));
+               if (type_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pAccess->item) {
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               get_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               item_node, ELEMENT_TARGET);
+               if (target_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pAccess->item->target, pBinder, target_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       *ppWbxml_dom_node = get_node;
+
+       if (str_cmdID)
+               free(str_cmdID);
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       if (str_cmdID)
+               free(str_cmdID);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_start_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Command *pCommand = (Command *)pContent;
+
+       char *str_cmdID = NULL;
+       char *numChanged_str  = NULL;
+
+       WBXMLTreeNode *sync_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_SYNC);
+       if (sync_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       sync_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               sync_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, sync_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       if (pCommand->source != NULL && pCommand->target != NULL) {
+               WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               sync_node, ELEMENT_TARGET);
+               if (target_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->target, pBinder, target_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+
+               WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               sync_node, ELEMENT_SOURCE);
+               if (source_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->source, pBinder, source_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+       }
+
+       if (pCommand->private.sync.hasNumChanged) {
+               numChanged_str = g_strdup_printf("%u", pCommand->private.sync.numChanged);
+               if (numChanged_str == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               WBXMLTreeNode *numberOfChanges_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                               sync_node, ELEMENT_NUMBEROFCHANGES, numChanged_str, strlen(numChanged_str));
+               if (numberOfChanges_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (numChanged_str != NULL)
+               free(numChanged_str);
+
+       *ppWbxml_dom_node = sync_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (numChanged_str != NULL)
+               free(numChanged_str);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_end_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       FW_LOGV("end");
+
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_add_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       char *str_cmdID = NULL;
+       char *str_size = NULL;
+
+       Command *pCommand = (Command *)pContent;
+
+       CommandChangePrivate *pChange = (CommandChangePrivate *)(&(pCommand->private));
+
+       if (!pChange) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode  *add_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_ADD);
+       if (add_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       add_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               add_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, add_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       GList *Iter = NULL;
+       Item *item = NULL;
+       for (Iter = pChange->items; Iter != NULL; Iter = g_list_next(Iter)) {
+               item =  (Iter->data);
+
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               add_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (item->source != NULL) {
+                       WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_SOURCE);
+                       if (source_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->source, pBinder, source_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->target != NULL) {
+                       WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_TARGET);
+                       if (target_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->target, pBinder, target_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+               }
+
+               if (item->contenttype) {
+                       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_META);
+                       if (meta_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_TYPE, item->contenttype, strlen(item->contenttype));
+                       if (type_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (item->moreData) {
+                               if (item->size) {
+                                       str_size = g_strdup_printf("%u", item->size);
+                                       if (str_size == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+
+                                       WBXMLTreeNode *size_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                       meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
+                                       if (size_node == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+                               }
+                       }
+               }
+
+               if (item->dataType == ITEM_DATA) {
+                       if (item->private.data) {
+                               WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_cdata(pBinder,
+                                               item_node, ELEMENT_DATA, item->private.data, strlen(item->private.data));
+                               if (data_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+               }
+
+               if (item->moreData) {
+                       WBXMLTreeNode *moredata_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_MOREDATA);
+                       if (moredata_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       *ppWbxml_dom_node = add_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_replace_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                               Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       char *str_cmdID = NULL;
+       char *str_size = NULL;
+
+       Command *pCommand = (Command *)pContent;
+
+       CommandChangePrivate *pChange = (CommandChangePrivate *)(&(pCommand->private));
+
+       if (!pChange) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *replace_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_REPLACE);
+       if (replace_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       replace_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               replace_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, replace_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       GList *Iter = NULL;
+       Item *item = NULL;
+       for (Iter = pChange->items; Iter != NULL; Iter = g_list_next(Iter)) {
+               item =  (Iter->data);
+
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               replace_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (item->source != NULL) {
+                       WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_SOURCE);
+                       if (source_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+                       err = __append_location_to_wbxml_node(item->source, pBinder, source_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->target != NULL) {
+                       WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_TARGET);
+                       if (target_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+                       err = __append_location_to_wbxml_node(item->target, pBinder, target_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->contenttype) {
+                       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_META);
+                       if (meta_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_TYPE, item->contenttype, strlen(item->contenttype));
+                       if (type_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (item->moreData) {
+                               if (item->size) {
+                                       str_size = g_strdup_printf("%u", item->size);
+                                       if (str_size == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+
+                                       WBXMLTreeNode *size_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                                       meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
+                                       if (size_node == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto error;
+                                       }
+                               }
+                       }
+               }
+
+               if (item->dataType == ITEM_DATA) {
+                       if (item->private.data) {
+                               WBXMLTreeNode *data_node = add_child_wbxml_node_using_xml_name_with_cdata(pBinder,
+                                               item_node, ELEMENT_DATA, item->private.data, strlen(item->private.data));
+                               if (data_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+               }
+
+               if (item->moreData) {
+                       WBXMLTreeNode *moredata_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_MOREDATA);
+                       if (moredata_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+               }
+
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       *ppWbxml_dom_node = replace_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_delete_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       char *str_cmdID = NULL;
+       char *str_size = NULL;
+
+       Command *pCommand = (Command *)pContent;
+
+       CommandChangePrivate *pChange = (CommandChangePrivate *)(&(pCommand->private));
+
+       if (!pChange) {
+               err = PROTOCOL_BINDER_NOT_DEFINED;
+               goto error;
+       }
+
+       WBXMLTreeNode *delete_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_DELETE);
+       if (delete_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       delete_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->noResp) {
+               WBXMLTreeNode *noResp_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               delete_node, ELEMENT_NORESP);
+               if (noResp_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+       }
+
+       /*TODO Archive*/
+       /*TODO sftDel*/
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, delete_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       GList *Iter = NULL;
+       Item *item = NULL;
+       for (Iter = pCommand->private.change.items; Iter != NULL; Iter = g_list_next(Iter)) {
+               item =  (Iter->data);
+
+               WBXMLTreeNode *item_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               delete_node, ELEMENT_ITEM);
+               if (item_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (item->source != NULL) {
+                       WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_SOURCE);
+                       if (source_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->source, pBinder, source_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->target != NULL) {
+                       WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_TARGET);
+                       if (target_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->target, pBinder, target_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+
+               if (item->contenttype) {
+                       WBXMLTreeNode *meta_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       item_node, ELEMENT_META);
+                       if (meta_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       WBXMLTreeNode *type_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                       meta_node, ELEMENT_TYPE, item->contenttype, strlen(item->contenttype));
+                       if (type_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       if (item->size) {
+                               str_size = g_strdup_printf("%u", item->size);
+                               if (str_size == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+
+                               WBXMLTreeNode *size_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                                               meta_node, ELEMENT_SIZE, str_size, strlen(str_size));
+                               if (size_node == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto error;
+                               }
+                       }
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       *ppWbxml_dom_node = delete_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       if (str_size != NULL)
+               free(str_size);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_map_command_converter_function(protocol_binder *pBinder,
+                                                                                                                                                       Content_Ptr pContent, WBXMLTreeNode **ppWbxml_dom_node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       char *str_cmdID = NULL;
+
+       Command *pCommand = (Command *)pContent;
+
+       WBXMLTreeNode *map_node = create_wbxml_node_using_xml_name(pBinder, ELEMENT_MAP);
+
+       str_cmdID = g_strdup_printf("%u", pCommand->cmdID);
+       if (str_cmdID == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       WBXMLTreeNode *cmdid_node = add_child_wbxml_node_using_xml_name_with_text(pBinder,
+                       map_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID));
+       if (cmdid_node == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               goto error;
+       }
+
+       if (pCommand->source != NULL && pCommand->target != NULL) {
+               WBXMLTreeNode *target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               map_node, ELEMENT_TARGET);
+               if (target_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->target, pBinder, target_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+
+               WBXMLTreeNode *source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               map_node, ELEMENT_SOURCE);
+               if (source_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               err = __append_location_to_wbxml_node(pCommand->source, pBinder, source_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+
+       }
+
+       if (pCommand->cred) {
+               err = __append_cred_to_wbxml_node(pCommand->cred, pBinder, map_node);
+               if (err != PROTOCOL_BINDER_OK)
+                       goto error;
+       }
+
+       GList *iter = NULL;
+       Item *item = NULL;
+       for (iter = pCommand->private.map.items; iter != NULL; iter = g_list_next(iter)) {
+               item = iter->data;
+               WBXMLTreeNode *mapItem_node = add_child_wbxml_node_using_xml_name(pBinder,
+                               map_node, ELEMENT_MAPITEM);
+               if (mapItem_node == NULL) {
+                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                       goto error;
+               }
+
+               if (item->source != NULL && item->target != NULL) {
+                       WBXMLTreeNode *item_target_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       mapItem_node, ELEMENT_TARGET);
+                       if (item_target_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->target, pBinder, item_target_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+
+                       WBXMLTreeNode *item_source_node = add_child_wbxml_node_using_xml_name(pBinder,
+                                       mapItem_node, ELEMENT_SOURCE);
+                       if (item_source_node == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto error;
+                       }
+
+                       err = __append_location_to_wbxml_node(item->source, pBinder, item_source_node);
+                       if (err != PROTOCOL_BINDER_OK)
+                               goto error;
+
+               }
+       }
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       *ppWbxml_dom_node = map_node;
+
+       FW_LOGV("end");
+       return err;
+
+error:
+
+       if (str_cmdID != NULL)
+               free(str_cmdID);
+
+       FW_LOGE("error :%d", err);
+       return err;
+}
+
+static ProtocolVersion __get_oma_ds_protocol_version(char *verdtd)
+{
+       ProtocolVersion protocol_version = VERSION_UNKNOWN;
+       if (strcmp(verdtd, ELEMENT_VERDRD_12) == 0) {
+               protocol_version = VERSION_12;
+       } else if (strcmp(verdtd, ELEMENT_VERDRD_11) == 0) {
+               protocol_version = VERSION_11;
+       } else if (strcmp(verdtd, ELEMENT_VERDRD_10) == 0) {
+               protocol_version = VERSION_10;
+       }
+
+       return protocol_version;
+}
+
+static DevInfVersion __get_oma_ds_devInf_version(char *verdtd)
+{
+       DevInfVersion devInf_version = DEVINF_VERSION_UNKNOWN;
+       if (strcmp(verdtd, ELEMENT_VERDRD_12) == 0) {
+               devInf_version = DEVINF_VERSION_12;
+       } else if (strcmp(verdtd, ELEMENT_VERDRD_11) == 0) {
+               devInf_version = DEVINF_VERSION_11;
+       } else if (strcmp(verdtd, ELEMENT_VERDRD_10) == 0) {
+               devInf_version = DEVINF_VERSION_10;
+       }
+
+       return devInf_version;
+}
+
+static DevInfDevTyp __get_oma_ds_devInf_device_type(char *devType)
+{
+       DevInfDevTyp device_type = DEVINF_DEVTYPE_UNKNOWN;
+       if (strcmp(devType, ELEMENT_PAGER) == 0) {
+               device_type = DEVINF_DEVTYPE_PAGER;
+       } else if (strcmp(devType, ELEMENT_HANDHELD) == 0) {
+               device_type = DEVINF_DEVTYPE_HANDHELD;
+       } else if (strcmp(devType, ELEMENT_PDA) == 0) {
+               device_type = DEVINF_DEVTYPE_PDA;
+       } else if (strcmp(devType, ELEMENT_PHONE) == 0) {
+               device_type = DEVINF_DEVTYPE_PHONE;
+       } else if (strcmp(devType, ELEMENT_SMARTPHONE) == 0) {
+               device_type = DEVINF_DEVTYPE_SMARTPHONE;
+       } else if (strcmp(devType, ELEMENT_SERVER) == 0) {
+               device_type = DEVINF_DEVTYPE_SERVER;
+       } else if (strcmp(devType, ELEMENT_WORKSTATION) == 0) {
+               device_type = DEVINF_DEVTYPE_WORKSTATION;
+       }
+
+       return device_type;
+}
+
+static DevInfContentType *__get_devinf_contenttype(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       DevInfContentType *pDevInfContentType = (DevInfContentType *)calloc(1, sizeof(DevInfContentType));
+       if (pDevInfContentType == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pDevInfContentType is null");
+               goto return_part;
+       }
+
+       /* get first child */
+       WBXMLTreeNode *child = node->children;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       const char *first_child_name = NULL;
+       first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+       if (strcmp(first_child_name, ELEMENT_CTTYPE) == 0) {
+               char *ctType = NULL;
+               err = get_text_pointer_from_wbxml_node(child, &ctType);
+               if (err != PROTOCOL_BINDER_OK) {
+                       goto return_part;
+               }
+               if (ctType != NULL)
+                       pDevInfContentType->cttype = strdup(ctType);
+       } else {
+               /* error */
+               goto return_part;
+       }
+
+       /* get second child  */
+       child = child->next;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       if (child != NULL) {
+               const char *second_child_name = NULL;
+               second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+               if (strcmp(second_child_name, ELEMENT_VERCT) == 0) {
+                       char *verCT = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &verCT);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       if (verCT != NULL)
+                               pDevInfContentType->verct = strdup(verCT);
+               } else {
+                       /* error */
+                       goto return_part;
+               }
+       }
+
+       FW_LOGV("end");
+       return pDevInfContentType;
+
+return_part:
+       FW_LOGE("error : %d", err);
+       return NULL;
+
+}
+
+static Location *_get_location(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       Location *pLocation = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       char *locURI = NULL;
+       char *locName = NULL;
+
+       /* get first child : required LocURI */
+       child = node->children;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       const char *first_child_name = NULL;
+       first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+       FW_LOGV("child_name = %s", first_child_name);
+       if (strcmp(first_child_name, ELEMENT_LOCURI) == 0) {
+               err = get_text_pointer_from_wbxml_node(child, &locURI);
+               if (err != PROTOCOL_BINDER_OK) {
+                       goto return_part;
+               }
+       } else {
+               /* error */
+               goto return_part;
+       }
+
+       /* get second child : optional LocName */
+       child = child->next;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       if (child != NULL) {
+               const char *second_child_name = NULL;
+               second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+               FW_LOGV("child_name = %s", second_child_name);
+               if (strcmp(second_child_name, ELEMENT_LOCNAME) == 0) {
+                       err = get_text_pointer_from_wbxml_node(child, &locName);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+               } else {
+                       /* error */
+                       goto return_part;
+               }
+       }
+
+       create_location(locURI, locName, &pLocation);
+
+       FW_LOGV("end");
+       return pLocation;
+
+return_part:
+       FW_LOGE("error : %d", err);
+       free_location(pLocation);
+       return NULL;
+}
+
+static Anchor *_get_anchor(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       Anchor *pAnchor = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       char *lastAnchor = NULL;
+       char *nextAnchor = NULL;
+       /* get first child : optional lastAnchor */
+       child = node->children;
+       for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+
+       const char *first_child_name = NULL;
+
+       first_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+       FW_LOGV("child_name = %s", first_child_name);
+       if (strcmp(first_child_name, ELEMENT_LAST) == 0) {
+               err = get_text_pointer_from_wbxml_node(child, &lastAnchor);
+               if (err != PROTOCOL_BINDER_OK) {
+                       goto return_part;
+               }
+               child = child->next;
+               for (; child != NULL && child->type != WBXML_TREE_ELEMENT_NODE; child = child->next) {}
+       } else if (strcmp(first_child_name, ELEMENT_NEXT) == 0) {
+               err = get_text_pointer_from_wbxml_node(child, &nextAnchor);
+               if (err != PROTOCOL_BINDER_OK) {
+                       goto return_part;
+               }
+               child = NULL;
+       }
+
+       /* get second child : required nextAnchor */
+       if (child != NULL) {
+               const char *second_child_name = NULL;
+               second_child_name = (const char *)wbxml_tag_get_xml_name(child->name);
+               FW_LOGV("child_name = %s", second_child_name);
+               if (strcmp(second_child_name, ELEMENT_NEXT) == 0) {
+                       err = get_text_pointer_from_wbxml_node(child, &nextAnchor);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+               } else {
+                       /* error */
+                       goto return_part;
+               }
+       }
+
+       create_anchor(lastAnchor, nextAnchor, &pAnchor);
+
+       FW_LOGV("end");
+       return pAnchor;
+
+return_part:
+       FW_LOGE("error : %d", err);
+       free_anchor(pAnchor);
+       return NULL;
+}
+
+static Cred *__get_cred(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       Cred *cred = NULL;
+
+       char *data = NULL;
+       char *type = NULL;
+       char *format = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       WBXMLTreeNode *grand_child = child->children;
+
+                       const char *grand_child_xml_name = NULL;
+                       grand_child_xml_name = (const char *)wbxml_tag_get_xml_name(grand_child->name);
+
+                       if (strcmp(grand_child_xml_name, ELEMENT_TYPE) == 0) {
+                               err = get_text_pointer_from_wbxml_node(grand_child, &type);
+                               if (err != PROTOCOL_BINDER_OK) {
+                                       goto return_part;
+                               }
+                               FW_LOGV("Type = [%s]" , type);
+                       } else if (strcmp(grand_child_xml_name, ELEMENT_FORMAT) == 0) {
+                               err = get_text_pointer_from_wbxml_node(grand_child, &format);
+                               if (err != PROTOCOL_BINDER_OK) {
+                                       goto return_part;
+                               }
+                               FW_LOGV("Type = [%s]" , format);
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
+                       err = get_text_pointer_from_wbxml_node(child, &data);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Data = [%s]" , data);
+               }
+
+       }
+
+       cred = create_cred_with_data(convert_auth_type(type), data);
+
+       FormatType formatType = FORMAT_TYPE_UNKNOWN;
+       if (strcmp(format, ELEMENT_B64) == 0)
+               formatType = FORMAT_TYPE_BASE64;
+
+       set_cred_format_type(cred, formatType);
+
+       FW_LOGV("end");
+       return cred;
+
+return_part:
+       FW_LOGE("error");
+       free_cred(cred);
+       return NULL;
+}
+
+static Chal *_get_chal(WBXMLTreeNode *node)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       Chal *pChal = (Chal *)calloc(1, sizeof(Chal));
+       if (pChal == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pChal is null");
+               goto return_part;
+       }
+
+       WBXMLTreeNode *chal_child = node->children;
+
+       WBXMLTreeNode *meta_child = NULL;
+
+       for (meta_child = chal_child->children; meta_child != NULL; meta_child = meta_child->next) {
+               if (meta_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *meta_child_xml_name = NULL;
+               meta_child_xml_name = (const char *)wbxml_tag_get_xml_name(meta_child->name);
+
+               if (strcmp(meta_child_xml_name, ELEMENT_TYPE) == 0) {
+                       char *type = NULL;
+                       err = get_text_pointer_from_wbxml_node(meta_child, &type);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Type = [%s]" , type);
+
+                       pChal->type = convert_auth_type(type);
+               } else if (strcmp(meta_child_xml_name, ELEMENT_FORMAT) == 0) {
+                       char *format = NULL;
+                       err = get_text_pointer_from_wbxml_node(meta_child, &format);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Format = [%s]" , format);
+
+                       pChal->format = convert_format_type(format);
+               } else if (strcmp(meta_child_xml_name, ELEMENT_NEXTNONCE) == 0) {
+                       char *nextnonce = NULL;
+                       unsigned int nonce_len = 0;
+                       err = get_binary_pointer_from_wbxml_node(meta_child, &nextnonce, &nonce_len);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("NextNonce = [%s]" , nextnonce);
+                       if (pChal->format == FORMAT_TYPE_BASE64) {
+                               if (nextnonce != NULL)
+                                       pChal->nonce_b64 = strdup(nextnonce);
+                       } else{
+                               pChal->nonce_plain = (char *) malloc(nonce_len+1);
+                               if (pChal->nonce_plain == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto return_part;
+                               }
+                               memcpy(pChal->nonce_plain, nextnonce, nonce_len);
+                               pChal->nonce_plain[nonce_len] = '\0';
+                       }
+
+                       pChal->nonce_length = nonce_len;
+               }
+       }
+
+       FW_LOGV("end");
+       return pChal;
+
+return_part:
+       FW_LOGE("error");
+       free_chal(pChal);
+       return NULL;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_devinf_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /* get data from dom tree */
+       DevInf *pDevInf = (DevInf *)calloc(1, sizeof(DevInf));
+       if (pDevInf == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pDevInf is null");
+               goto return_part;
+       }
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_VERDTD) == 0) {
+                       char *verdtd = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &verdtd);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("VerDTD = [%s]" , verdtd);
+
+                       pDevInf->version = __get_oma_ds_devInf_version(verdtd);
+               } else if (strcmp(child_xml_name, ELEMENT_MAN) == 0) {
+                       char *man = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &man);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Man = [%s]" , man);
+                       if (man != NULL)
+                               pDevInf->manufacturer = strdup(man);
+               } else if (strcmp(child_xml_name, ELEMENT_MOD) == 0) {
+                       char *mod = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &mod);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Mod = [%s]" , mod);
+                       if (mod != NULL)
+                               pDevInf->model = strdup(mod);
+               } else if (strcmp(child_xml_name, ELEMENT_OEM) == 0) {
+                       char *oem = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &oem);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("OEM = [%s]" , oem);
+                       if (oem != NULL)
+                               pDevInf->oem = strdup(oem);
+               } else if (strcmp(child_xml_name, ELEMENT_FWV) == 0) {
+                       char *fwv = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &fwv);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("FwV = [%s]" , fwv);
+                       if (fwv != NULL)
+                               pDevInf->firmwareVersion = strdup(fwv);
+               } else if (strcmp(child_xml_name, ELEMENT_SWV) == 0) {
+                       char *swv = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &swv);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("SwV = [%s]" , swv);
+                       if (swv != NULL)
+                               pDevInf->softwareVersion = strdup(swv);
+               } else if (strcmp(child_xml_name, ELEMENT_HWV) == 0) {
+                       char *hwv = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &hwv);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("HwV = [%s]" , hwv);
+                       if (hwv != NULL)
+                               pDevInf->hardwareVersion = strdup(hwv);
+               } else if (strcmp(child_xml_name, ELEMENT_DEVID) == 0) {
+                       char *devID = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &devID);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("DevID = [%s]" , devID);
+                       if (devID != NULL)
+                               pDevInf->devid = strdup(devID);
+               } else if (strcmp(child_xml_name, ELEMENT_DEVTYP) == 0) {
+                       char *devtyp = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &devtyp);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("DevTyp = [%s]" , devtyp);
+
+                       pDevInf->devtyp = __get_oma_ds_devInf_device_type(devtyp);
+               } else if (strcmp(child_xml_name, ELEMENT_UTC) == 0) {
+                       FW_LOGV("UTC");
+                       pDevInf->supportsUTC = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_SUPPORTLARGEOBJS) == 0) {
+                       FW_LOGV("SupportLargeObjs");
+                       pDevInf->supportsLargeObjs = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_SUPPORTNUMBEROFCHANGES) == 0) {
+                       FW_LOGV("SupportNumberOfChanges");
+                       pDevInf->supportsNumberOfChanges = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_DATASTORE) == 0) {
+
+                       DevInfDataStore *pDevInfDataStore = (DevInfDataStore *)calloc(1, sizeof(DevInfDataStore));
+
+                       WBXMLTreeNode *datastore_child = NULL;
+
+                       for (datastore_child = child->children; datastore_child != NULL; datastore_child = datastore_child->next) {
+                               if (datastore_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *datastore_child_xml_name = NULL;
+                               datastore_child_xml_name = (const char *)wbxml_tag_get_xml_name(datastore_child->name);
+
+                               if (strcmp(datastore_child_xml_name, ELEMENT_SOURCEREF) == 0) {
+                                       char *sourceref = NULL;
+                                       err = get_text_pointer_from_wbxml_node(datastore_child, &sourceref);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("SourceRef = [%s]" , sourceref);
+                                       if (sourceref != NULL)
+                                               pDevInfDataStore->sourceref = strdup(sourceref);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
+                                       char *displayname = NULL;
+                                       err = get_text_pointer_from_wbxml_node(datastore_child, &displayname);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("DisplayName = [%s]" , displayname);
+                                       if (displayname != NULL)
+                                               pDevInfDataStore->displayname = strdup(displayname);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_MAXGUIDSIZE) == 0) {
+                                       char *maxguidsize = NULL;
+                                       err = get_text_pointer_from_wbxml_node(datastore_child, &maxguidsize);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("MaxGUIDSize = [%s]" , maxguidsize);
+                                       if (maxguidsize != NULL)
+                                               pDevInfDataStore->maxGUIDSize = atoi(maxguidsize);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_RX_PREF) == 0) {
+                                       DevInfContentType *pDevInfContentType = __get_devinf_contenttype(datastore_child);
+                                       if (pDevInfContentType == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pDevInfDataStore->rxPref = pDevInfContentType;
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_RX) == 0) {
+                                       DevInfContentType *pDevInfContentType = __get_devinf_contenttype(datastore_child);
+                                       if (pDevInfContentType == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pDevInfDataStore->rx = g_list_append(pDevInfDataStore->rx, pDevInfContentType);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_TX_PREF) == 0) {
+                                       DevInfContentType *pDevInfContentType = __get_devinf_contenttype(datastore_child);
+                                       if (pDevInfContentType == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pDevInfDataStore->txPref = pDevInfContentType;
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_TX) == 0) {
+                                       DevInfContentType *pDevInfContentType = __get_devinf_contenttype(datastore_child);
+                                       if (pDevInfContentType == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pDevInfDataStore->tx = g_list_append(pDevInfDataStore->tx, pDevInfContentType);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_CTCAP) == 0) {
+
+                                       DevInfCTCap *pDevInfCtCap = (DevInfCTCap *)calloc(1, sizeof(DevInfCTCap));
+
+                                       DevInfContentType *pDevInfContentType = NULL;
+                                       WBXMLTreeNode *ctcap_child = NULL;
+
+                                       for (ctcap_child = datastore_child->children; ctcap_child != NULL; ctcap_child = ctcap_child->next) {
+                                               if (ctcap_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *ctcap_child_xml_name = NULL;
+                                               ctcap_child_xml_name = (const char *)wbxml_tag_get_xml_name(ctcap_child->name);
+
+                                               if (strcmp(ctcap_child_xml_name, ELEMENT_CTTYPE) == 0) {
+                                                       if (pDevInfContentType == NULL)
+                                                               pDevInfContentType = (DevInfContentType *)calloc(1, sizeof(DevInfContentType));
+
+                                                       char *cttype = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(ctcap_child, &cttype);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("CTType = [%s]" , cttype);
+                                                       if (cttype != NULL)
+                                                               pDevInfContentType->cttype = strdup(cttype);
+                                               } else if (strcmp(ctcap_child_xml_name, ELEMENT_VERCT) == 0) {
+                                                       if (pDevInfContentType == NULL)
+                                                               pDevInfContentType = (DevInfContentType *)calloc(1, sizeof(DevInfContentType));
+
+                                                       char *verct = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(ctcap_child, &verct);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("VerCT = [%s]" , verct);
+                                                       if (verct != NULL)
+                                                               pDevInfContentType->verct = strdup(verct);
+                                               } else if (strcmp(ctcap_child_xml_name, ELEMENT_FIELDLEVEL) == 0) {
+                                                       /*TODO fieldlevel*/
+
+                                               } else if (strcmp(ctcap_child_xml_name, ELEMENT_PROPERTY) == 0) {
+
+                                                       DevInfProperty *pDevInfProperty = (DevInfProperty *)calloc(1, sizeof(DevInfProperty));
+
+                                                       WBXMLTreeNode *property_child = NULL;
+                                                       for (property_child = ctcap_child->children; property_child != NULL; property_child = property_child->next) {
+                                                               if (property_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                                               const char *property_child_xml_name = NULL;
+                                                               property_child_xml_name = (const char *)wbxml_tag_get_xml_name(property_child->name);
+
+                                                               if (strcmp(property_child_xml_name, ELEMENT_PROPNAME) == 0) {
+                                                                       char *propname = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &propname);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("PropName = [%s]" , propname);
+                                                                       if (propname != NULL)
+                                                                               pDevInfProperty->propName = strdup(propname);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_DATATYPE) == 0) {
+                                                                       char *datatype = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &datatype);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("DataType = [%s]" , datatype);
+                                                                       if (datatype != NULL)
+                                                                               pDevInfProperty->dataType = strdup(datatype);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_MAXOCCUR) == 0) {
+                                                                       char *maxoccur = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &maxoccur);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("MaxOccur = [%s]" , maxoccur);
+                                                                       if (maxoccur != NULL)
+                                                                               pDevInfProperty->maxOccur = atoi(maxoccur);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_MAXSIZE) == 0) {
+                                                                       char *maxsize = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &maxsize);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("MaxSize = [%s]" , maxsize);
+                                                                       if (maxsize != NULL)
+                                                                               pDevInfProperty->maxSize = atoi(maxsize);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_NOTRUNCATE) == 0) {
+                                                                       FW_LOGV("NoTruncate");
+                                                                       pDevInfProperty->noTruncate = 1;
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_VALENUM) == 0) {
+                                                                       char *valenum = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &valenum);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("ValEnum = [%s]" , valenum);
+                                                                       pDevInfProperty->valEnums = g_list_append(pDevInfProperty->valEnums, strdup(valenum));
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
+                                                                       char *displayname = NULL;
+                                                                       err = get_text_pointer_from_wbxml_node(property_child, &displayname);
+                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                               goto return_part;
+                                                                       }
+                                                                       FW_LOGV("DisplayName = [%s]" , displayname);
+                                                                       if (displayname != NULL)
+                                                                               pDevInfProperty->displayName = strdup(displayname);
+                                                               } else if (strcmp(property_child_xml_name, ELEMENT_PROPPARAM) == 0) {
+
+                                                                       DevInfPropParam *pDevInfPropParam = (DevInfPropParam *)calloc(1, sizeof(DevInfPropParam));
+
+                                                                       WBXMLTreeNode *propparam_child = NULL;
+
+                                                                       for (propparam_child = property_child->children; propparam_child != NULL; propparam_child = propparam_child->next) {
+                                                                               if (propparam_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                                                               const char *propparam_child_xml_name = NULL;
+                                                                               propparam_child_xml_name = (const char *)wbxml_tag_get_xml_name(propparam_child->name);
+
+                                                                               if (strcmp(propparam_child_xml_name, ELEMENT_PARAMNAME) == 0) {
+                                                                                       char *paramname = NULL;
+                                                                                       err = get_text_pointer_from_wbxml_node(propparam_child, &paramname);
+                                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                                               goto return_part;
+                                                                                       }
+                                                                                       FW_LOGV("ParamName = [%s]" , paramname);
+                                                                                       if (paramname != NULL)
+                                                                                               pDevInfPropParam->paramName = strdup(paramname);
+                                                                               } else if (strcmp(propparam_child_xml_name, ELEMENT_DATATYPE) == 0) {
+                                                                                       char *datatype = NULL;
+                                                                                       err = get_text_pointer_from_wbxml_node(propparam_child, &datatype);
+                                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                                               goto return_part;
+                                                                                       }
+                                                                                       FW_LOGV("DataType = [%s]" , datatype);
+                                                                                       if (datatype != NULL)
+                                                                                               pDevInfPropParam->dataType = strdup(datatype);
+                                                                               } else if (strcmp(propparam_child_xml_name, ELEMENT_VALENUM) == 0) {
+                                                                                       char *valenum = NULL;
+                                                                                       err = get_text_pointer_from_wbxml_node(propparam_child, &valenum);
+                                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                                               goto return_part;
+                                                                                       }
+                                                                                       FW_LOGV("ValEnum = [%s]" , valenum);
+                                                                                       if (valenum != NULL)
+                                                                                               pDevInfPropParam->valEnums = g_list_append(pDevInfPropParam->valEnums, strdup(valenum));
+                                                                               } else if (strcmp(propparam_child_xml_name, ELEMENT_DISPLAYNAME) == 0) {
+                                                                                       char *displayname = NULL;
+                                                                                       err = get_text_pointer_from_wbxml_node(propparam_child, &displayname);
+                                                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                                                               goto return_part;
+                                                                                       }
+                                                                                       FW_LOGV("DisplayName = [%s]" , displayname);
+                                                                                       if (displayname != NULL)
+                                                                                               pDevInfPropParam->displayName = strdup(displayname);
+                                                                               }
+                                                                       }
+
+                                                                       pDevInfProperty->propParams = g_list_append(pDevInfProperty->propParams, pDevInfPropParam);
+                                                               }
+                                                       }
+
+                                                       pDevInfCtCap->properties = g_list_append(pDevInfCtCap->properties, pDevInfProperty);
+                                               }
+                                       }
+                                       pDevInfCtCap->ct = pDevInfContentType;
+                                       pDevInfDataStore->ctcaps = g_list_append(pDevInfDataStore->ctcaps, pDevInfCtCap);
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_DSMEM) == 0) {
+
+                                       /*TODO DSMem*/
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_SUPPORTHIERARCHICALSYNC) == 0) {
+                                       FW_LOGV("SupportHierarchicalSync");
+                                       pDevInfDataStore->supportsHierarchicalSync = 1;
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_SYNCCAP) == 0) {
+
+                                       WBXMLTreeNode *synccap_child = NULL;
+
+                                       for (synccap_child = datastore_child->children; synccap_child != NULL; synccap_child = synccap_child->next) {
+                                               if (synccap_child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *synccap_child_xml_name = NULL;
+                                               synccap_child_xml_name = (const char *)wbxml_tag_get_xml_name(synccap_child->name);
+
+                                               if (strcmp(synccap_child_xml_name, ELEMENT_SYNCTYPE) == 0) {
+                                                       char *synctype_str = NULL;
+                                                       unsigned int synctype = 0;
+                                                       err = get_text_pointer_from_wbxml_node(synccap_child, &synctype_str);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("SyncType = [%s]" , synctype_str);
+                                                       if (synctype_str != NULL) {
+                                                               synctype = atoi(synctype_str);
+                                                               synctype = 1 << (synctype - 1);
+                                                       }
+                                                       /*DevInfSyncCap synccap = convert_devinf_synccap(synctype);*/
+                                                       set_devInf_datastore_synccap(pDevInfDataStore, synctype, 1);
+                                               }
+                                       }
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_FILTER_RX) == 0) {
+                                               /*TODO filter-rx*/
+                               } else if (strcmp(datastore_child_xml_name, ELEMENT_FILTERCAP) == 0) {
+                                               /*TODO filtercap*/
+                               }
+                       }
+                       pDevInf->datastores = g_list_append(pDevInf->datastores, pDevInfDataStore);
+               }
+       }
+
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pDevInf;
+       } else{
+               FW_LOGE("error");
+               free_devinf(pDevInf);
+       }
+
+       return err;
+}
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_header_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /* get data from dom tree */
+       SyncHdr *pSyncHdr = (SyncHdr *)calloc(1, sizeof(SyncHdr));
+       if (pSyncHdr == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pSyncHdr is null");
+               goto return_part;
+       }
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_VERDTD) == 0) {
+                       char *verdtd = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &verdtd);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("VerDTD = [%s]" , verdtd);
+
+                       pSyncHdr->version = __get_oma_ds_protocol_version(verdtd);
+               } else if (strcmp(child_xml_name, ELEMENT_SESSIONID) == 0) {
+                       char *sessionID = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &sessionID);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("SessionID = [%s]" , sessionID);
+
+                       if (sessionID)
+                               pSyncHdr->sessionID = strdup(sessionID);
+                       else
+                               pSyncHdr->sessionID = NULL;
+               } else if (strcmp(child_xml_name, ELEMENT_MSGID) == 0) {
+                       char *msgID = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &msgID);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("MsgID = [%s]" , msgID);
+                       if (msgID != NULL)
+                               pSyncHdr->messageID = atoi(msgID);
+               } else if (strcmp(child_xml_name, ELEMENT_TARGET) == 0) {
+                       Location *pTargetLocation = _get_location(child);
+                       if (pTargetLocation == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSyncHdr->target = pTargetLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_SOURCE) == 0) {
+                       Location *pSourceLocation = _get_location(child);
+                       if (pSourceLocation == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSyncHdr->source = pSourceLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_RESPURI) == 0) {
+                       char *resp_uri = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &resp_uri);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("resp_uri = [%s]" , resp_uri);
+                       if (resp_uri != NULL)
+                               pSyncHdr->responseURI = strdup(resp_uri);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("noResp\n");
+                       pSyncHdr->noResponse = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSyncHdr->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pSyncHdr;
+       } else{
+               FW_LOGE("error");
+               free_synchdr(pSyncHdr);
+       }
+
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_results_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pResults = (Command *)calloc(1, sizeof(Command));
+       if (pResults == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pResults is null");
+               goto return_part;
+       }
+
+       pResults->type = COMMAND_TYPE_RESULTS;
+       pResults->msgID = pSyncHdr->messageID;
+       pResults->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pResults->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_MSGREF) == 0) {
+                       char *msg_ref = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &msg_ref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("MsgRef = [%s]" , msg_ref);
+                       if (msg_ref != NULL)
+                               pResults->private.results.msgRef = atoi(msg_ref);
+               } else if (strcmp(child_xml_name, ELEMENT_CMDREF) == 0) {
+                       char *cmd_ref = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_ref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("MsgRef = [%s]" , cmd_ref);
+                       if (cmd_ref != NULL)
+                               pResults->private.results.cmdRef = atoi(cmd_ref);
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+
+                       WBXMLTreeNode *grandchild = NULL;
+
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               pResults->private.results.type = strdup(contentType);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_TARGETREF) == 0) {
+               /*TODO targetRef*/
+               } else if (strcmp(child_xml_name, ELEMENT_SOURCEREF) == 0) {
+               /*TODO sourceRef*/
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       /*create item in results command */
+                       Item *item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pResults->private.results.item = item;
+
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pResults->private.results.item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pResults->private.results.item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       /* TODO data*/
+                               }
+                       }
+               }
+       }
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pResults;
+       } else{
+               FW_LOGE("error");
+               free_command(pResults);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_put_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pPut = (Command *)calloc(1, sizeof(Command));
+       if (pPut == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pPut is null");
+               goto return_part;
+       }
+
+       pPut->type = COMMAND_TYPE_PUT;
+       pPut->msgID = pSyncHdr->messageID;
+       pPut->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pPut->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pPut->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pPut->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               pPut->private.access.type = strdup(contentType);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       /*create item in put command */
+                       Item *item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pPut->private.access.item = item;
+
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pPut->private.access.item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pPut->private.access.item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       /* TODO data*/
+                               }
+                       }
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pPut;
+       } else{
+               FW_LOGE("error");
+               free_command(pPut);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_get_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pGet = (Command *)calloc(1, sizeof(Command));
+       if (pGet == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pGet is null");
+               goto return_part;
+       }
+
+       pGet->type = COMMAND_TYPE_GET;
+       pGet->msgID = pSyncHdr->messageID;
+       pGet->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pGet->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pGet->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pGet->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               pGet->private.access.type = strdup(contentType);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       /*create item in put command */
+                       Item *item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pGet->private.access.item = item;
+
+                       WBXMLTreeNode *grandchild = NULL;
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pGet->private.access.item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pGet->private.access.item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       /* TODO data*/
+                               }
+                       }
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pGet;
+       } else{
+               FW_LOGE("error");
+               free_command(pGet);
+       }
+       return err;
+}
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_alert_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pAlert = (Command *)calloc(1, sizeof(Command));
+       if (pAlert == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pAlert is null");
+               goto return_part;
+       }
+
+       pAlert->type = COMMAND_TYPE_ALERT;
+       pAlert->msgID = pSyncHdr->messageID;
+       pAlert->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pAlert->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pAlert->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pAlert->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
+                       char *data = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &data);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Data = [%s]" , data);
+                       if (data != NULL)
+                               pAlert->private.alert.type = atoi(data);
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pAlert->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pAlert->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
+
+                                       WBXMLTreeNode *grandgrandchild = NULL;
+                                       for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
+                                               if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *grandgrandchild_xml_name = NULL;
+                                               grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
+
+                                               if (strcmp(grandgrandchild_xml_name, ELEMENT_ANCHOR) == 0) {
+                                                       Anchor *pAnchor = _get_anchor(grandgrandchild);
+                                                       if (pAnchor == NULL) {
+                                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                                               goto return_part;
+                                                       }
+                                                       pAlert->private.alert.anchor = pAnchor;
+                                               } else if (strcmp(grandgrandchild_xml_name, ELEMENT_MAXOBJSIZE) == 0) {
+                                                       char *maxObjSize = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &maxObjSize);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("MaxObjSize = [%s]" , maxObjSize);
+                                                       if (maxObjSize != NULL)
+                                                               pAlert->private.alert.maxObjSize = atoi(maxObjSize);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pAlert;
+       } else{
+               FW_LOGE("error");
+               free_command(pAlert);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_end_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pSyncEnd = (Command *)calloc(1, sizeof(Command));
+       if (pSyncEnd == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pSyncEnd is null");
+               goto return_part;
+       }
+
+       pSyncEnd->type = COMMAND_TYPE_SYNC_END;;
+       pSyncEnd->msgID = pSyncHdr->messageID;
+       pSyncEnd->refCount = 1;
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pSyncEnd;
+       } else{
+               FW_LOGE("error");
+               free_command(pSyncEnd);
+       }
+       return err;
+}
+
+
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_sync_start_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pSync = (Command *)calloc(1, sizeof(Command));
+       if (pSync == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pSync is null");
+               goto return_part;
+       }
+
+       pSync->type = COMMAND_TYPE_SYNC_START;;
+       pSync->msgID = pSyncHdr->messageID;
+       pSync->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pSync->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pSync->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSync->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_TARGET) == 0) {
+                       Location *pTargetLocation = _get_location(child);
+                       if (pTargetLocation == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSync->target = pTargetLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_SOURCE) == 0) {
+                       Location *pSourceLocation = _get_location(child);
+                       if (pSourceLocation == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pSync->source = pSourceLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       /*TODO meta*/
+               } else if (strcmp(child_xml_name, ELEMENT_NUMBEROFCHANGES) == 0) {
+                       char *numOfChanges = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &numOfChanges);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("NumberOfChanges = [%s]" , numOfChanges);
+
+                       pSync->private.sync.hasNumChanged = 1;
+                       if (numOfChanges != NULL)
+                               pSync->private.sync.numChanged = atoi(numOfChanges);
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pSync;
+       } else{
+               FW_LOGE("error");
+               free_command(pSync);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_add_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pAdd = (Command *)calloc(1, sizeof(Command));
+       if (pAdd == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pAdd is null");
+               goto return_part;
+       }
+
+       pAdd->type = COMMAND_TYPE_ADD;;
+       pAdd->msgID = pSyncHdr->messageID;
+       pAdd->private.change.type = CHANGE_ADD;
+       pAdd->refCount = 1;
+
+       Item *item = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pAdd->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pAdd->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pAdd->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+
+                       item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               item->contenttype = strdup(contentType);
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_SIZE) == 0) {
+                                       char *size = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &size);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Size = [%s]" , size);
+                                       if (size != NULL)
+                                               item->size = atoi(size);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+
+                       if (!item) {
+                               item =  create_item();
+                               if (item == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto return_part;
+                               }
+                       }
+
+                       WBXMLTreeNode *grandchild = NULL;
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
+                                       WBXMLTreeNode *grandgrandchild = NULL;
+
+                                       for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
+                                               if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *grandgrandchild_xml_name = NULL;
+                                               grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
+
+                                               if (strcmp(grandgrandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                                       char *contentType = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &contentType);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                                       if (contentType != NULL)
+                                                               item->contenttype = strdup(contentType);
+                                               } else if (strcmp(grandgrandchild_xml_name, ELEMENT_SIZE) == 0) {
+                                                       char *size = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &size);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("Size = [%s]" , size);
+                                                       if (size != NULL)
+                                                               item->size = atoi(size);
+                                               }
+                                       }
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       char *data = NULL;
+                                       err = get_text_pointer_from_wbxml_cdata_node(grandchild, &data);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Data = [%s]" , data);
+                                       if (data != NULL)
+                                               item->private.data = strdup(data);
+                                       item->dataType = ITEM_DATA;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_MOREDATA) == 0) {
+                                       FW_LOGV("MoreData");
+                                       item->moreData = 1;
+                               }
+                       }
+                       pAdd->private.change.items = g_list_append(pAdd->private.change.items, item);
+                       item = NULL;
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pAdd;
+       } else{
+               FW_LOGE("error");
+               free_command(pAdd);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_replace_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pReplace = (Command *)calloc(1, sizeof(Command));
+       if (pReplace == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pReplace is null");
+               goto return_part;
+       }
+
+       pReplace->type = COMMAND_TYPE_REPLACE;;
+       pReplace->msgID = pSyncHdr->messageID;
+       pReplace->private.change.type = CHANGE_REPLACE;
+       pReplace->refCount  = 1;
+
+       Item *item = NULL;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pReplace->cmdID = atoi(cmd_id);
+
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pReplace->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pReplace->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+
+                       item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       WBXMLTreeNode *grandchild = NULL;
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               item->contenttype = strdup(contentType);
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_SIZE) == 0) {
+                                       char *size = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &size);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Size = [%s]" , size);
+                                       if (size != NULL)
+                                               item->size = atoi(size);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+
+                       if (!item) {
+                               item =  create_item();
+                               if (item == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto return_part;
+                               }
+                       }
+
+                       WBXMLTreeNode *grandchild = NULL;
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
+                                       WBXMLTreeNode *grandgrandchild = NULL;
+
+                                       for (grandgrandchild = grandchild->children; grandgrandchild != NULL; grandgrandchild = grandgrandchild->next) {
+                                               if (grandgrandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                                               const char *grandgrandchild_xml_name = NULL;
+                                               grandgrandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandgrandchild->name);
+
+                                               if (strcmp(grandgrandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                                       char *contentType = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &contentType);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                                       if (contentType != NULL)
+                                                               item->contenttype = strdup(contentType);
+                                               } else if (strcmp(grandgrandchild_xml_name, ELEMENT_SIZE) == 0) {
+                                                       char *size = NULL;
+                                                       err = get_text_pointer_from_wbxml_node(grandgrandchild, &size);
+                                                       if (err != PROTOCOL_BINDER_OK) {
+                                                               goto return_part;
+                                                       }
+                                                       FW_LOGV("Size = [%s]" , size);
+                                                       if (size != NULL)
+                                                               item->size = atoi(size);
+                                               }
+                                       }
+
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       char *data = NULL;
+                                       err = get_text_pointer_from_wbxml_cdata_node(grandchild, &data);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Data = [%s]" , data);
+                                       if (data != NULL)
+                                               item->private.data = strdup(data);
+                                       item->dataType = ITEM_DATA;
+                               }
+                       }
+                       pReplace->private.change.items = g_list_append(pReplace->private.change.items, item);
+                       item = NULL;
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pReplace;
+       } else{
+               FW_LOGE("error");
+               free_command(pReplace);
+       }
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_delete_command_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       SyncHdr *pSyncHdr = (SyncHdr *)reverse_protocol_binder_get_user_data(pReverse_binder);
+
+       /* get data from dom tree */
+       Command *pDelete = (Command *)calloc(1, sizeof(Command));
+       if (pDelete == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pDelete is null");
+               goto return_part;
+       }
+
+       pDelete->type = COMMAND_TYPE_DELETE;
+       pDelete->msgID = pSyncHdr->messageID;
+       pDelete->private.change.type = CHANGE_DELETE;
+       pDelete->refCount = 1;
+
+       WBXMLTreeNode *child = NULL;
+
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               Item *item = NULL;
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pDelete->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) {
+                       FW_LOGV("NoResp");
+                       pDelete->noResp = 1;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pDelete->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_META) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+
+                       /* create Item */
+                       item = create_item();
+                       if (item == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_TYPE) == 0) {
+                                       char *contentType = NULL;
+                                       err = get_text_pointer_from_wbxml_node(grandchild, &contentType);
+                                       if (err != PROTOCOL_BINDER_OK) {
+                                               goto return_part;
+                                       }
+                                       FW_LOGV("Content Type = [%s]" , contentType);
+                                       if (contentType != NULL)
+                                               item->contenttype = strdup(contentType);
+                               }
+                       }
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       /* create Item */
+                       if (!item) {
+                               item = create_item();
+                               if (item == NULL) {
+                                       err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                       goto return_part;
+                               }
+                       }
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->source = pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       Location *pTargetLocation = _get_location(grandchild);
+                                       if (pTargetLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       item->target = pTargetLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_META) == 0) {
+
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+
+                               }
+                       }
+                       pDelete->private.change.items = g_list_append(pDelete->private.change.items, item);
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pDelete;
+       } else{
+               FW_LOGE("error");
+               free_command(pDelete);
+       }
+       return err;
+}
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_final_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       int *pFinal = (int *)1;
+       *pContent = pFinal;
+
+       FW_LOGV("end");
+       return err;
+}
+
+static PROTOCOL_BINDER_ERROR __oma_ds_binder_status_reverse_converter_function(Reverse_protocol_binder *pReverse_binder,
+                                                                                                                                                       WBXMLTreeNode *wbxml_dom_node,
+                                                                                                                                                       Content_Ptr *pContent)
+{
+       FW_LOGV("start");
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /* get data from dom tree */
+       Status *pStatus = (Status *)calloc(1, sizeof(Status));
+       if (pStatus == NULL) {
+               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+               FW_LOGE("pStatus is null");
+               goto return_part;
+       }
+
+       WBXMLTreeNode *child = NULL;
+       for (child = wbxml_dom_node->children; child != NULL; child = child->next) {
+               if (child->type != WBXML_TREE_ELEMENT_NODE) continue;
+               const char *child_xml_name = NULL;
+               child_xml_name = (const char *)wbxml_tag_get_xml_name(child->name);
+
+               if (strcmp(child_xml_name, ELEMENT_CMDID) == 0) {
+                       char *cmd_id = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd_id);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdID = [%s]" , cmd_id);
+                       if (cmd_id != NULL)
+                               pStatus->cmdID = atoi(cmd_id);
+               } else if (strcmp(child_xml_name, ELEMENT_MSGREF) == 0) {
+                       char *msgref = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &msgref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("MsgRef = [%s]" , msgref);
+                       if (msgref != NULL)
+                               pStatus->msgRef = atoi(msgref);
+               } else if (strcmp(child_xml_name, ELEMENT_CMDREF) == 0) {
+                       char *cmdref = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmdref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("CmdRef = [%s]" , cmdref);
+                       if (cmdref != NULL)
+                               pStatus->cmdRef = atoi(cmdref);
+               } else if (strcmp(child_xml_name, ELEMENT_CMD) == 0) {
+                       char *cmd = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &cmd);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Cmd = [%s]" , cmd);
+
+                       pStatus->type = convert_command_type(cmd);
+               } else if (strcmp(child_xml_name, ELEMENT_TARGETREF) == 0) {
+                       char *targetref = NULL;
+                       Location *pLocation = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &targetref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("TargetRef = [%s]" , targetref);
+
+                       create_location(targetref, NULL, &pLocation);
+                       pStatus->targetRef = pLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_SOURCEREF) == 0) {
+                       char *sourceref = NULL;
+                       Location *pLocation = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &sourceref);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("SourceRef = [%s]" , sourceref);
+
+                       create_location(sourceref, NULL, &pLocation);
+                       pStatus->sourceRef = pLocation;
+               } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) {
+                       FW_LOGV("Cred\n");
+                       Cred *pCred = NULL;
+                       pCred = __get_cred(child);
+                       if (pCred == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pStatus->cred = pCred;
+               } else if (strcmp(child_xml_name, ELEMENT_CHAL) == 0) {
+                       FW_LOGV("Chal\n");
+                       Chal *pChal = NULL;
+                       pChal = _get_chal(child);
+                       if (pChal == NULL) {
+                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                               goto return_part;
+                       }
+                       pStatus->chal = pChal;
+               } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) {
+                       char *data = NULL;
+                       err = get_text_pointer_from_wbxml_node(child, &data);
+                       if (err != PROTOCOL_BINDER_OK) {
+                               goto return_part;
+                       }
+                       FW_LOGV("Data = [%s]\n" , data);
+                       if (data != NULL)
+                               pStatus->data = strdup(data);
+               } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) {
+                       WBXMLTreeNode *grandchild = NULL;
+
+                       for (grandchild = child->children; grandchild != NULL; grandchild = grandchild->next) {
+                               if (grandchild->type != WBXML_TREE_ELEMENT_NODE) continue;
+
+                               const char *grandchild_xml_name = NULL;
+                               grandchild_xml_name = (const char *)wbxml_tag_get_xml_name(grandchild->name);
+
+                               if (strcmp(grandchild_xml_name, ELEMENT_SOURCE) == 0) {
+                                       Location *pSourceLocation = _get_location(grandchild);
+                                       if (pSourceLocation == NULL) {
+                                               err = PROTOCOL_BINDER_OUT_OF_MEMORY;
+                                               goto return_part;
+                                       }
+                                       pStatus->sourceRef =  pSourceLocation;
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) {
+                                       /* need ? */
+                               } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) {
+                                       /* need ?*/
+                               }
+                       }
+               }
+       }
+
+return_part:
+       if (err == PROTOCOL_BINDER_OK) {
+               FW_LOGV("end");
+               *pContent = pStatus;
+       } else{
+               FW_LOGE("error");
+               free_status(pStatus);
+       }
+       return err;
+}
+
+PROTOCOL_BINDER_ERROR init_oma_ds_1_2_binder_function_set(Binder_function_set **pBinder_function_set)
+{
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       err = init_binder_function_set(sizeof(oma_ds_binder_function_info)/sizeof(Binder_function_info),
+                                                                       (Binder_function_info*)oma_ds_binder_function_info,
+                                                                       pBinder_function_set);
+
+       return err;
+}
+
+void free_oma_ds_1_2_binder_function_set(Binder_function_set *pBinder_function_set)
+{
+       free_binder_function_set(pBinder_function_set);
+}
+
+protocol_binder *oma_ds_1_2_binder_init(protocol_binder *pBinder, Encoding enc, bool encode_xml_header,
+                                                                                       bool use_strtbl, bool produce_anonymous, bool use_flow_mode,
+                                                                                       Binder_function_set *pBinder_function_set)
+{
+       protocol_binder *pOutBinder = NULL;
+
+       pOutBinder = protocol_binder_init(pBinder, PROTOCOL_SYNCML_SYNCML12, NULL, enc,
+                                                               encode_xml_header, use_strtbl, produce_anonymous, use_flow_mode, NULL, NULL,
+                                                               pBinder_function_set);
+
+       if (pOutBinder == NULL) {
+               goto return_part;
+       }
+
+return_part:
+       return pOutBinder;
+}
+
+
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_append(protocol_binder *pBinder,
+                                                                                               OMA_DS_Protocol_Element protocol_element,
+                                                                                               Content_Ptr pContent)
+{
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       err = protocol_binder_append(pBinder, protocol_element, pContent);
+
+       return err;
+}
+
+
+void oma_ds_1_2_binder_terminate(protocol_binder *pBinder)
+{
+       protocol_binder_terminate(pBinder);
+}
+
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_stream(protocol_binder *pBinder,
+                                                                                                       char **byte_stream,
+                                                                                                       unsigned int *byte_stream_size)
+{
+       PROTOCOL_BINDER_ERROR err =  PROTOCOL_BINDER_OK;
+
+       err = protocol_binder_get_stream(pBinder, byte_stream, byte_stream_size);
+       if (err != PROTOCOL_BINDER_OK) {
+               goto return_part;
+       }
+
+return_part:
+       return err;
+}
+
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_stream_size(protocol_binder *pBinder, unsigned int *byte_stream_size)
+{
+       PROTOCOL_BINDER_ERROR err =  PROTOCOL_BINDER_OK;
+
+       err = protocol_binder_get_stream_size(pBinder, byte_stream_size);
+       return err;
+}
+
+
+PROTOCOL_BINDER_ERROR oma_ds_1_2_binder_get_encoding(protocol_binder *pBinder, Encoding *enc)
+{
+       PROTOCOL_BINDER_ERROR err =  PROTOCOL_BINDER_OK;
+
+       err = protocol_binder_get_encoding(pBinder, enc);
+       return err;
+}
+
+PROTOCOL_BINDER_ERROR reverse_oma_ds_1_2_binder_init(char *byte_stream,
+                                                                                                       unsigned int byte_stream_len,
+                                                                                                       Decoding dec,
+                                                                                                       Binder_function_set *pBinder_function_set,
+                                                                                                       void *user_data,
+                                                                                                       Reverse_protocol_binder **ppBinder)
+{
+       Protocol protocol = PROTOCOL_UNKNOWN;
+       PROTOCOL_BINDER_ERROR err = reverse_protocol_binder_init(byte_stream, byte_stream_len, dec,
+                                                                                       &protocol, pBinder_function_set, user_data, ppBinder);
+
+       return err;
+}
+
+PROTOCOL_BINDER_ERROR reverse_oma_ds_1_2_binder_next(Reverse_protocol_binder *pBinder,
+                                                                                               OMA_DS_Protocol_Element *protocol_element,
+                                                                                               char **protocol_element_name,
+                                                                                               Content_Ptr *pContent)
+{
+       PROTOCOL_BINDER_ERROR err = reverse_protocol_binder_next(pBinder,
+                                                                               protocol_element, protocol_element_name, pContent);
+       return err;
+}
diff --git a/src/ServiceAdapter/SA_Command.c b/src/ServiceAdapter/SA_Command.c
new file mode 100644 (file)
index 0000000..a10d25f
--- /dev/null
@@ -0,0 +1,1040 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Command.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions for command structure which is used in Service Adapter
+ */
+
+#include <stdlib.h>
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceAdapter/SA_Command.h"
+#include "ServiceAdapter/SA_Command_Internal.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Session.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+static Command *__create_command(Session *session, CommandType type);
+
+
+static Command *__create_command(Session *session, CommandType type)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!session) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!type) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       Command *cmd = (Command *) calloc(1, sizeof(Command));
+       if (!cmd) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+
+       cmd->type = type;
+       cmd->msgID = session->msgID;
+       cmd->cmdID = session->cmdID;
+       cmd->refCount = 1;
+
+       session->cmdID++;
+
+       FW_LOGV("end");
+
+       return cmd;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return NULL;
+}
+
+void free_commands(GList *commands)
+{
+       FW_LOGV("start list length is %d", g_list_length(commands));
+
+       if (!commands) {
+               FW_LOGV("List is NULL");
+               return;
+       }
+
+
+       GList *iter = NULL;
+       Command *pCommand = NULL;
+       for (iter = commands; iter != NULL;) {
+               pCommand = iter->data;
+               FW_LOGV("command list length is %d command type is %d\n", g_list_length(commands), pCommand->type);
+
+               iter = g_list_next(iter);
+               if (pCommand->type != COMMAND_TYPE_UNKNOWN) {
+                       free_command(pCommand);
+                       commands = g_list_remove(commands, pCommand);
+               }
+       }
+
+
+       g_list_free(commands);
+
+       FW_LOGV("end");
+
+       return;
+}
+
+SA_ErrorType create_alert_command(Session *session, AlertType  syncType, Location *source, Location *target,
+                                                                                                               char *lastAnchor, char *nextAnchor, Cred *pCred, Command **pCommand)
+{
+       FW_LOGV("start with syncType =%d", syncType);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Anchor *pAnchor = NULL;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_ALERT);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->target = target;
+       (*pCommand)->source = source;
+
+       /*TODO  check that sync Type is ALERT_NEXT_MESSAGE(does not need last and next anchor)*/
+       /*TODO  check that sync Type is  ALERT_SLOW_SYNC(does not need last anchor)*/
+
+       if (nextAnchor) {
+               errorType = create_anchor(lastAnchor, nextAnchor , &pAnchor);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               (*pCommand)->private.alert.anchor = pAnchor;
+               pAnchor = NULL;
+       }
+
+       if (pCred != NULL)
+               (*pCommand)->cred = dup_cred(pCred);
+
+       (*pCommand)->private.alert.type = syncType;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+
+       if (pAnchor != NULL)
+               free_anchor(pAnchor);
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_get_command(Session *session, Location* target, const char *contenttype, Command **pCommand)
+{
+       FW_LOGV("start with content type = %s", contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_GET);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.access.item = create_item();
+       if ((*pCommand)->private.access.item == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       set_item_target((*pCommand)->private.access.item, target);
+
+       if (contenttype != NULL)
+               (*pCommand)->private.access.item->contenttype = strdup(contenttype);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+
+SA_ErrorType create_put_command(Session *session, Location *source,  const char *contenttype,
+                                                                                                       DevInf *devInf , Command **pCommand)
+{
+       FW_LOGV("start with content type = %s", contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_PUT);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.access.item = create_item_for_devinf(devInf);
+
+       if ((*pCommand)->private.access.item == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       set_item_source((*pCommand)->private.access.item, source);
+
+       if (contenttype != NULL)
+               (*pCommand)->private.access.item->contenttype = strdup(contenttype);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+
+SA_ErrorType create_results_command(Session *session, Location *source,  const char *contenttype,
+                                                                                                                       DevInf *devInf , Command **pCommand)
+{
+       FW_LOGV("start with content type = %s", contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_RESULTS);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.results.item = create_item_for_devinf(devInf);
+
+       if ((*pCommand)->private.results.item == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       set_item_source((*pCommand)->private.results.item, source);
+
+       if (contenttype != NULL)
+               (*pCommand)->private.results.item->contenttype = strdup(contenttype);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_sync_start_command(Session *session, Location *source, Location *target,  Command **pCommand)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_SYNC_START);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->source = source;
+       (*pCommand)->target = target;
+
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_sync_start_command_numberofchanges(Command *pCommand, unsigned int numberOfChanges)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (pCommand == NULL) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->private.sync.hasNumChanged = 1;
+       pCommand->private.sync.numChanged = numberOfChanges;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_sync_end_command(Command **pCommand)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       *pCommand = (Command *) calloc(1, sizeof(Command));
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->type = COMMAND_TYPE_SYNC_END;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+
+SA_ErrorType create_add_command(Session *session, ChangeType type, char *luid, const char *contenttype,
+                                                                                                               char *data, unsigned int size , int  moreData, Command **pCommand)
+{
+       FW_LOGV("start with ChangeType = %d content type = %s", type, contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Item *temp = NULL;
+       Location *pLocation = NULL;
+
+       *pCommand = __create_command(session, COMMAND_TYPE_ADD);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       temp = create_item_for_data(data, size);
+       if (!temp) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.change.type = type;
+       if (contenttype != NULL)
+               temp->contenttype = strdup(contenttype);
+       temp->moreData = moreData;
+
+       errorType = create_location(luid, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       set_item_source(temp, pLocation);
+       (*pCommand)->private.change.items = g_list_append((*pCommand)->private.change.items, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_replace_command(Session *session,  ChangeType type, char *luid, const char *contenttype,
+                                                                                                                       const char *data,  unsigned int size, int moreData,  Command **pCommand)
+{
+       FW_LOGV("start with ChangeType = %d content type = %s", type, contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Item *temp = NULL;
+       Location *pLocation = NULL;
+
+       *pCommand = __create_command(session, COMMAND_TYPE_REPLACE);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       temp = create_item_for_data(data, size);
+       if (!temp) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.change.type = type;
+       if (contenttype != NULL)
+               temp->contenttype = strdup(contenttype);
+       temp->moreData = moreData;
+
+       errorType = create_location(luid, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       set_item_source(temp, pLocation);
+       (*pCommand)->private.change.items = g_list_append((*pCommand)->private.change.items, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_delete_command(Session *session, ChangeType type, char *luid, const char *contenttype, Command **pCommand)
+{
+       FW_LOGV("start with ChangeType = %d content type = %s", type, contenttype);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Item *temp = NULL;
+       Location *pLocation = NULL;
+
+       *pCommand = __create_command(session, COMMAND_TYPE_DELETE);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       temp = create_item();
+       if (!temp) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->private.change.type = type;
+
+       errorType = create_location(luid, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       set_item_source(temp, pLocation);
+       if (contenttype != NULL)
+               temp->contenttype = strdup(contenttype);
+       (*pCommand)->private.change.items = g_list_append((*pCommand)->private.change.items, temp);
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+
+}
+
+SA_ErrorType create_map_command(Session *session, Location *source, Location *target, Command **pCommand)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pCommand = __create_command(session, COMMAND_TYPE_MAP);
+       if (*pCommand == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pCommand)->source = source;
+       (*pCommand)->target = target;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_map_command_item(Command *mapCommand, Item *temp)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!mapCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       mapCommand->private.map.items = g_list_append(mapCommand->private.map.items, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType increase_command_refcount(Command *pCommand)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->refCount++;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType decrease_command_refcount(Command *pCommand)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->refCount--;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_results_command_msgref(Command *pCommand, unsigned int msgRef)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->private.results.msgRef = msgRef;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_results_command_cmdref(Command *pCommand, unsigned int cmdRef)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       pCommand->private.results.cmdRef = cmdRef;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_results_command_targetref(Command *pCommand, Location *pLocation)
+{
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pCommand) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       FW_LOGV("start with Command Type =%d\n", pCommand->type);
+
+       pCommand->private.results.targetRef = dup_location(pLocation);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("errorType = %d", errorType);
+       return errorType;
+}
+
+void free_command(Command *pCommand)
+{
+       if (!pCommand)
+               return;
+
+       FW_LOGV("start with  Command type is %d", pCommand->type);
+
+       GList *iter = NULL;
+
+       if (pCommand->refCount > 1) {
+               FW_LOGV("Command's refCount is %d", pCommand->refCount);
+               decrease_command_refcount(pCommand);
+               return;
+       }
+
+
+       switch (pCommand->type) {
+               case COMMAND_TYPE_ALERT:
+                       if (pCommand->private.alert.anchor) {
+                               free_anchor(pCommand->private.alert.anchor);
+                               pCommand->private.alert.anchor = NULL;
+                       }
+
+                       if (pCommand->private.alert.contentType) {
+                               free(pCommand->private.alert.contentType);
+                               pCommand->private.alert.contentType = NULL;
+                       }
+                       break;
+               case COMMAND_TYPE_SYNC_START:
+                       /*nothing to free*/
+                       break;
+               case COMMAND_TYPE_SYNC_END:
+                       /*nothing to free*/
+                       break;
+               case COMMAND_TYPE_PUT:
+                       if (pCommand->private.access.type) {
+                               free(pCommand->private.access.type);
+                               pCommand->private.access.type = NULL;
+                       }
+
+                       if (pCommand->private.access.item) {
+                               free_item(pCommand->private.access.item);
+                               pCommand->private.access.item = NULL;
+                       }
+                       break;
+               case COMMAND_TYPE_HEADER:
+                       /*COMMAND_TYPE_HEADER doesnot come here*/
+                       break;
+               case COMMAND_TYPE_ADD:
+               case COMMAND_TYPE_REPLACE:
+               case COMMAND_TYPE_DELETE:
+                       for (iter = pCommand->private.change.items; iter != NULL; iter = g_list_next(iter))
+                               free_item(iter->data);
+                       break;
+               case COMMAND_TYPE_MAP:
+                       for (iter = pCommand->private.map.items; iter != NULL; iter = g_list_next(iter))
+                               free_item(iter->data);
+                       break;
+               case COMMAND_TYPE_GET:
+                       if (pCommand->private.access.type) {
+                               free(pCommand->private.access.type);
+                               pCommand->private.access.type = NULL;
+                       }
+
+                       if (pCommand->private.access.item) {
+                               free_item(pCommand->private.access.item);
+                               pCommand->private.access.item = NULL;
+                       }
+                       break;
+               case COMMAND_TYPE_RESULTS:
+                       if (pCommand->private.results.type) {
+                               free(pCommand->private.results.type);
+                               pCommand->private.results.type = NULL;
+                       }
+
+                       if (pCommand->private.results.item) {
+                               free_item(pCommand->private.results.item);
+                               pCommand->private.results.item = NULL;
+                       }
+
+                       if (pCommand->private.results.targetRef) {
+                               free_location(pCommand->private.results.targetRef);
+                               pCommand->private.results.targetRef = NULL;
+                       }
+
+                       break;
+               case COMMAND_TYPE_UNKNOWN:
+                       break;
+       }
+
+       if (pCommand->source) {
+               free_location(pCommand->source);
+               pCommand->source = NULL;
+       }
+
+       if (pCommand->target) {
+               free_location(pCommand->target);
+               pCommand->target = NULL;
+       }
+
+       if (pCommand->cred) {
+               free_cred(pCommand->cred);
+               pCommand->cred = NULL;
+       }
+
+       free(pCommand);
+
+       FW_LOGV("end");
+}
+
+SA_ErrorType create_new_status_location(Session *session, OMA_StatusType data, Command *command,
+                                                                               Location *sourceref, Location *targetref, CommandType type, Status **pStatus)
+{
+       FW_LOGV("start Errortype %d", data);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       errorType = create_status(data, session->cmdID, session->lastRecievedMsgID,
+                                                                                       command->cmdID, sourceref, targetref, type, pStatus);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->cmdID++;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_new_status(Session *session, OMA_StatusType data, Command *command,
+                                                                                                       CommandType type, Status **pStatus)
+{
+       FW_LOGV("start Errortype %d", data);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       errorType = create_status(data, session->cmdID, session->lastRecievedMsgID, command->cmdID,
+                                                                                       command->source, command->target, type, pStatus);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->cmdID++;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_status(OMA_StatusType data,  unsigned int cmdID, unsigned int msgref , unsigned int cmdref,
+                                                                                       Location *sourceref, Location *targetref, CommandType type, Status **pStatus)
+{
+       FW_LOGV("start Errortype %d", data);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       *pStatus = (Status *)calloc(1, sizeof(Status));
+       if (*pStatus == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pStatus)->cmdID = cmdID;
+       (*pStatus)->msgRef = msgref;
+       (*pStatus)->cmdRef = cmdref;
+       (*pStatus)->type = type;
+
+       if (data)
+               (*pStatus)->data = g_strdup_printf("%i", data);
+
+       if (sourceref)
+               (*pStatus)->sourceRef = dup_location(sourceref);
+
+       if (targetref)
+               (*pStatus)->targetRef = dup_location(targetref);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+void free_statuses(GList *status)
+{
+       FW_LOGV("start");
+
+       if (!status) {
+               FW_LOGV("List is null");
+               return;
+       }
+
+       GList *iter = NULL;
+       FW_LOGV("count : %d", g_list_length(status));
+       for (iter = status; iter != NULL; iter = g_list_next(iter))
+               free_status(iter->data);
+
+       g_list_free(status);
+
+       FW_LOGV("end");
+}
+
+void free_status(Status *pStatus)
+{
+       FW_LOGV("start");
+
+       if (!pStatus)
+               return;
+
+       if (pStatus->data)
+               free(pStatus->data);
+
+       if (pStatus->sourceRef)
+               free_location(pStatus->sourceRef);
+
+       if (pStatus->targetRef)
+               free_location(pStatus->targetRef);
+
+       if (pStatus->cred)
+               free_cred(pStatus->cred);
+
+       if (pStatus->chal)
+               free_chal(pStatus->chal);
+
+       free_item(pStatus->item);
+
+       free(pStatus);
+       pStatus = NULL;
+
+       FW_LOGV("end");
+}
+
+OMA_StatusType get_status_code(Status *status)
+{
+       return atoi(status->data);
+}
+
+CommandType convert_command_type(char *type)
+{
+       CommandType commandType = COMMAND_TYPE_UNKNOWN;
+       if (!type)
+               return commandType;
+
+       if (!strcmp(type, "Alert")) {
+               commandType = COMMAND_TYPE_ALERT;
+       } else if (!strcmp(type, "Sync")) {
+               commandType = COMMAND_TYPE_SYNC_START;
+       } else if (!strcmp(type, "Put")) {
+               commandType = COMMAND_TYPE_PUT;
+       } else if (!strcmp(type, "SyncHdr")) {
+               commandType = COMMAND_TYPE_HEADER;
+       } else if (!strcmp(type, "Add")) {
+               commandType = COMMAND_TYPE_ADD;
+       } else if (!strcmp(type, "Replace")) {
+               commandType = COMMAND_TYPE_REPLACE;
+       } else if (!strcmp(type, "Map")) {
+               commandType = COMMAND_TYPE_MAP;
+       } else if (!strcmp(type, "Delete")) {
+               commandType = COMMAND_TYPE_DELETE;
+       } else if (!strcmp(type, "Results")) {
+               commandType = COMMAND_TYPE_RESULTS;
+       } else if (!strcmp(type, "Get")) {
+               commandType = COMMAND_TYPE_GET;
+       }
+
+       return commandType;
+}
+
+ChangeType convert_change_type_command_type(CommandType type)
+{
+       ChangeType changeType = CHANGE_UNKNOWN;
+       switch (type) {
+       case COMMAND_TYPE_UNKNOWN:
+       case COMMAND_TYPE_ALERT:
+       case COMMAND_TYPE_SYNC_START:
+       case COMMAND_TYPE_SYNC_END:
+       case COMMAND_TYPE_PUT:
+       case COMMAND_TYPE_HEADER:
+       case COMMAND_TYPE_MAP:
+       case COMMAND_TYPE_GET:
+       case COMMAND_TYPE_RESULTS:
+               /*never comes these commands*/
+               break;
+       case COMMAND_TYPE_ADD:
+               changeType = CHANGE_ADD;
+               break;
+       case COMMAND_TYPE_REPLACE:
+               changeType = CHANGE_REPLACE;
+               break;
+       case COMMAND_TYPE_DELETE:
+               changeType = CHANGE_DELETE;
+               break;
+
+       }
+       return changeType;
+}
+
+CommandType convert_command_type_change_type(ChangeType type)
+{
+       CommandType commandType = COMMAND_TYPE_UNKNOWN;
+
+       switch (type) {
+       case CHANGE_UNKNOWN:
+               commandType = COMMAND_TYPE_UNKNOWN;
+               break;
+       case CHANGE_ADD:
+               commandType = COMMAND_TYPE_ADD;
+               break;
+       case CHANGE_REPLACE:
+               commandType = COMMAND_TYPE_REPLACE;
+               break;
+       case CHANGE_DELETE:
+               commandType = COMMAND_TYPE_DELETE;
+               break;
+       }
+
+       return commandType;
+
+}
+/*
+ChangeType convertToChangeType(unsigned int type) {
+
+       ChangeType changeType=CHANGE_UNKNOWN;
+       switch (type) {
+       case 1:
+               changeType = CHANGE_ADD;
+               break;
+       case 2:
+               changeType = CHANGE_REPLACE;
+               break;
+       case 3:
+               changeType = CHANGE_DELETE;
+               break;
+       }
+
+       return changeType;
+}
+
+
+char *convertFromCommandType(CommandType type) {
+       char *commandType=NULL;
+
+       switch (type) {
+       case COMMAND_TYPE_ALERT:
+               commandType = "Alert";
+               break;
+       case COMMAND_TYPE_SYNC_START:
+       case COMMAND_TYPE_SYNC_END:
+               commandType = "Sync";
+               break;
+       case COMMAND_TYPE_PUT:
+               commandType = "Put";
+               break;
+       case COMMAND_TYPE_HEADER:
+               commandType = "SyncHdr";
+               break;
+       case COMMAND_TYPE_ADD:
+               commandType = "Add";
+               break;
+       case COMMAND_TYPE_REPLACE:
+               commandType = "Replace";
+               break;
+       case COMMAND_TYPE_MAP:
+               commandType = "Map";
+               break;
+       case COMMAND_TYPE_DELETE:
+               commandType = "Delete";
+               break;
+       case COMMAND_TYPE_RESULTS:
+               commandType = "Results";
+               break;
+       case COMMAND_TYPE_GET:
+               commandType = "Get";
+               break;
+       default:
+               commandType="UNKNOWN";
+       }
+       return commandType;
+}
+*/
diff --git a/src/ServiceAdapter/SA_Common_Interface.c b/src/ServiceAdapter/SA_Common_Interface.c
new file mode 100644 (file)
index 0000000..b335c85
--- /dev/null
@@ -0,0 +1,2680 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Common_Interface.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of interface of Service Adapter
+ */
+
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/DACI/DACI_Service.h"
+#include "agent-framework/NetworkAccess/NACI.h"
+#include "agent-framework/EngineController/task_process.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/Device/EXT_DCI_DevInfo.h"
+#include "Common/Common_Vconf.h"
+#include "Common/Common_Define.h"
+#include "Common/Common_Util.h"
+#include "ServiceAdapter/ProtocolBinder/oma_ds_protocol_binder.h"
+#include "ServiceAdapter/NetworkBinder/NA_Binder.h"
+#include "ServiceAdapter/SA_Define.h"
+#include "ServiceAdapter/SA_Common_Interface.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Command.h"
+#include "ServiceAdapter/SA_Command_Internal.h"
+#include "ServiceAdapter/SA_Session.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+#include "ServiceAdapter/SA_DevInf_Internal.h"
+#include "ServiceAdapter/SA_Util.h"
+#include "ServiceAdapter/SA_DevInf.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+Session *session = NULL;
+
+static SA_ErrorType __get_accountinfo(int accountId, char **id, char **pwd, char **serverUrl, char **nextNonce);
+static SA_ErrorType __object_binder(SyncML *pSyncML, char **msg, unsigned int *msg_size);
+static SA_ErrorType __reverse_object_binder(SyncML **pSyncML, char *recv_msg, unsigned int recv_msg_length);
+static SA_ErrorType __generate_presync_msg(int accountId, char *sessionId,  char **msg, unsigned int *msg_size);
+static SA_ErrorType __generate_msg(void **syncObj, char **msg , unsigned int *msg_size);
+static SA_ErrorType __generate_msg_status_map_command(Session **pSession, SyncObj **syncObj,
+                                                                                                                                                                                       GList **commands, GList **commands_last);
+static SA_ErrorType __generate_msg_exist_sending_map_command(protocol_binder *pBinder, Session **pSession,
+                                                                                                                                                                                                               GList **commands, GList **commands_last);
+static SA_ErrorType __generate_msg_changes_command(protocol_binder *pBinder, Session **pSession, SyncObj **sync,
+                                                                                                                                                                       GList **commands, GList **commands_last, bool *isNeedNextMsg);
+static SA_ErrorType __generate_autoconfigure_msg(char *id, char *pwd, char *targetUrl, char **msg,
+                                                                                                                                                               unsigned int *msg_size, Session *pSession);
+static SA_ErrorType __exchange_msg(char *accType, int transportType, char *targetUri, unsigned int session_id,
+                                                                                                               GList *header_info, char *sendMsg, unsigned int sendMsg_length, GList **recv_header,
+                                                                                                               char **recvMsg, unsigned int *recvMsg_length);
+static SA_ErrorType __process_recv_msg(char *recvMsg, unsigned int recvMsg_length, void **syncReturnObj, int *isFinish);
+static SA_ErrorType __process_autoconfigure_recv_msg(char *recvMsg, unsigned int recvMsg_length, Session *pSession);
+static Common_ErrorType __convert_error_type(SA_ErrorType errorType);
+static void __clean_up_SA();
+
+static SA_ErrorType __get_accountinfo(int accountId, char **id, char **pwd, char **serverUrl, char **nextNonce)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       char *value = NULL;
+       bool result;
+
+       if (!accountId) {
+               errorType = SA_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       *id = DACI_Get_Account_Email_Address(accountId);
+       if (*id == NULL) {
+               errorType = SA_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       *pwd = DACI_Get_Account_Password(accountId);
+       if (*pwd == NULL) {
+               errorType = SA_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       result = get_config(accountId,  DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, &value);
+       if (result == true)
+               *serverUrl = value;
+       else{
+               FW_LOGE("failed in get_Config");
+               errorType = SA_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       if (*serverUrl == NULL) {
+               errorType = SA_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       result = get_config(accountId,  DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, &value);
+       if (result == true)
+               *nextNonce = value;
+       else{
+               FW_LOGE("failed in get_Config");
+               errorType = SA_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __generate_presync_msg(int accountId, char *sessionId,  char **msg, unsigned int *msg_size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       char *id = NULL;
+       char *pwd = NULL;
+       char *sourceUrl = NULL;
+       char *targetUrl = NULL;
+       char *nextNonce = NULL;
+       char *credData = NULL;
+       char *decoded_nonce = NULL;
+
+       /*pkg1  always has final tag*/
+       int isFinal = 1;
+
+       SyncHdr *pSyncHdr = NULL;
+       Cred *pCred = NULL;
+       DevInf *devInfObj = NULL;
+       SyncML *pSyncML = NULL;
+
+       /*case SAN, MUST use sessionid from SAN message..*/
+       if (!sessionId) {
+               sessionId = g_strdup_printf("%ld", time(NULL));
+               if (sessionId == NULL) {
+                       errorType = SA_INTERNAL_NO_MEMORY;
+                       goto error;
+               }
+       }
+
+       DCI_RETURN err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &sourceUrl);
+       if (err != DCI_SUCCESS) {
+               FW_LOGE("failed to get devinfo");
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       errorType = __get_accountinfo(accountId, &id, &pwd, &targetUrl, &nextNonce);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("id = %s", id);
+       FW_LOGV("pwd = %s",  pwd);
+       FW_LOGV("sessionId = %s", sessionId);
+       FW_LOGV("sourceUrl = %s", sourceUrl);
+       FW_LOGV("serverUrl = %s", targetUrl);
+
+       Chal *pTempChal = NULL;
+       if (session != NULL) {
+               if (session->chal != NULL)
+                       pTempChal = dup_chal(session->chal);
+
+               free_session(session);
+               session = NULL;
+       }
+
+       /* create session info */
+       errorType = create_session(VERSION_12, PROTOCOL_TYPE_DS, accountId, sessionId, sourceUrl, targetUrl, &session);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create session");
+               goto error;
+       }
+
+       if (pTempChal != NULL) {
+               session->chal = pTempChal;
+               pTempChal = NULL;
+       }
+
+       /* set pkg status */
+       session->pkgStatus = SYNCML_PKG_1;
+
+       Chal *chal = session->chal;
+       AuthType authType;
+       FormatType formatType = FORMAT_TYPE_UNKNOWN;
+       unsigned int nonce_size = 0;
+       if (!chal) {
+               FW_LOGV("CHAL DOES NOT EXIST");
+               if (nextNonce) {
+                       /*server sent nonce info in previous sync session*/
+                       authType = AUTH_TYPE_MD5;
+                       decoded_nonce = (char *)g_base64_decode(nextNonce, &nonce_size);
+                       formatType = FORMAT_TYPE_BASE64;
+               } else{
+                       authType = AUTH_TYPE_BASIC;
+                       formatType = FORMAT_TYPE_BASE64;
+               }
+
+               errorType = create_cred_string(authType,  id, pwd, decoded_nonce, nonce_size, &credData);
+
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed to create cred string");
+                       goto error;
+               }
+
+               errorType = create_cred(id, pwd, authType, formatType, credData,  &pCred);
+       } else{
+               FW_LOGV("CHAL DOES  EXIST");
+               if (chal->type == AUTH_TYPE_MD5) {
+                       if (chal->format == FORMAT_TYPE_BASE64)
+                               decoded_nonce = (char *)g_base64_decode(chal->nonce_b64, &nonce_size);
+                       else{
+                               if (chal->nonce_plain != NULL) {
+                                       decoded_nonce = strdup(chal->nonce_plain);
+                                       nonce_size = chal->nonce_length;
+                               }
+                       }
+               }
+
+               errorType = create_cred_string(chal->type, id, pwd, decoded_nonce, nonce_size, &credData);
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed to create cred string");
+                       goto error;
+               }
+
+               errorType = create_cred(id, pwd, chal->type, FORMAT_TYPE_BASE64, credData , &pCred);
+       }
+
+       if (credData != NULL) {
+               free(credData);
+               credData = NULL;
+       }
+
+       if (decoded_nonce != NULL) {
+               free(decoded_nonce);
+               decoded_nonce = NULL;
+       }
+
+       if (nextNonce != NULL) {
+               free(nextNonce);
+               nextNonce = NULL;
+       }
+       nonce_size = 0;
+
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create cred");
+               goto error;
+       }
+
+       set_session_cred(session, pCred);
+       pCred = NULL;
+
+       /* create SyncHdr */
+       errorType = create_synchdr(session , &pSyncHdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create synchdr");
+               goto error;
+       }
+
+       /* create devInf */
+       errorType = create_devinf(session, &devInfObj);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create devInf");
+               goto error;
+       }
+
+       set_session_devinf(session, devInfObj);
+       devInfObj = NULL;
+
+       GList *commands = NULL;
+       GList *commands_last = NULL;
+
+       char *sourceDevInf = NULL;
+       if (session->protocolVersion == VERSION_10)
+               sourceDevInf = ELEMENT_DEVINF_10;
+       else if (session->protocolVersion == VERSION_11)
+               sourceDevInf = ELEMENT_DEVINF_11;
+       else if (session->protocolVersion == VERSION_12)
+               sourceDevInf = ELEMENT_DEVINF_12;
+
+
+       /* create Put command */
+       /*
+       Command *pPutCommand = NULL;
+       Location *pLocation = NULL;
+
+       errorType = create_Location(sourceDevInf, NULL, &pLocation);
+       if (errorType != ERROR_INTERNAL_OK)
+               goto error;
+
+       errorType = create_Put_Command(session, pLocation, ELEMENT_DEVINF_XML, devInfObj , &pPutCommand);
+       if (errorType !=ERROR_INTERNAL_OK)
+               goto error;
+       putIntoList(&commands, &commands_last, pPutCommand);
+       */
+
+
+       /* create Get command */
+       Command *pGetCommand = NULL;
+       Location *pLocation = NULL;
+       errorType = create_location(sourceDevInf, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create location");
+               goto error;
+       }
+
+       char *contentType = NULL;
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               contentType = ELEMENT_DEVINF_XML;
+       else
+               contentType = ELEMENT_DEVINF_WBXML;
+
+       errorType = create_get_command(session, pLocation, contentType, &pGetCommand);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create get command");
+               goto error;
+       }
+       put_into_list(&commands, &commands_last, pGetCommand);
+
+       Command *pAlertCommand = NULL;
+       Location *pSourceLocation = NULL;
+       Location *pTargetLocation = NULL;
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
+                       errorType = create_location(datastoreinfo_per_content_type[content_type]->source, NULL, &pSourceLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+
+                               /* change errorType because locURI is required so need to return SA_INTERNAL_MISCONFIGURATION error
+                                       when SA_INTERNAL_NOT_DEFINED error case*/
+                               if (errorType == SA_INTERNAL_NOT_DEFINED)
+                                       errorType = SA_INTERNAL_MISCONFIGURATION;
+
+                               goto error;
+                       }
+
+                       errorType = create_location(datastoreinfo_per_content_type[content_type]->target, NULL, &pTargetLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+
+                               /* change errorType because locURI is required so need to return SA_INTERNAL_MISCONFIGURATION error
+                                       when SA_INTERNAL_NOT_DEFINED error case*/
+                               if (errorType == SA_INTERNAL_NOT_DEFINED)
+                                       errorType = SA_INTERNAL_MISCONFIGURATION;
+                               goto error;
+                       }
+
+                       if (datastoreinfo_per_content_type[content_type]->id && datastoreinfo_per_content_type[content_type]->pw) {
+
+                               /*FIXME is there a nextNonce for datastore ??*/
+                               if (nextNonce) {
+                                       /*server sent nonce info in previous sync session*/
+                                       authType = AUTH_TYPE_MD5;
+                                       decoded_nonce = (char *)g_base64_decode(nextNonce, &nonce_size);
+                               } else{
+                                       authType = AUTH_TYPE_BASIC;
+                                       formatType = FORMAT_TYPE_BASE64;
+                               }
+
+                               errorType = create_cred_string(authType,  datastoreinfo_per_content_type[content_type]->id,
+                                                                                       datastoreinfo_per_content_type[content_type]->pw, decoded_nonce, nonce_size, &credData);
+                               if (errorType != SA_INTERNAL_OK) {
+                                       FW_LOGE("failed to create cred string");
+                                       goto error;
+                               }
+
+                               errorType = create_cred(id, pwd, authType, FORMAT_TYPE_BASE64, credData,  &pCred);
+
+                               if (credData != NULL) {
+                                       free(credData);
+                                       credData = NULL;
+                               }
+                       }
+
+                       errorType = create_alert_command(session, datastoreinfo_per_content_type[content_type]->clientSyncType,
+                                                                               pSourceLocation, pTargetLocation, datastoreinfo_per_content_type[content_type]->lastAnchorClient,
+                                                                               datastoreinfo_per_content_type[content_type]->nextAnchorClient, pCred, &pAlertCommand);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create alert command");
+                               goto error;
+                       }
+               } else
+                       continue;
+               put_into_list(&commands, &commands_last, pAlertCommand);
+       }
+
+
+       errorType = create_syncml(pSyncHdr, NULL, commands, isFinal, &pSyncML);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create syncml");
+               goto error;
+       }
+
+       session->isSendingfinal = isFinal;
+       if (isFinal)
+               session->pkgStatus = SYNCML_PKG_2;
+
+       /* convert Msg */
+       errorType = __object_binder(pSyncML, msg, msg_size);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in objectBinder");
+               goto error;
+       }
+
+       /*free generate structure*/
+       free_syncml(pSyncML);
+
+       if (id)
+               free(id);
+       if (pwd)
+               free(pwd);
+       if (sessionId)
+               free(sessionId);
+       if (sourceUrl)
+               free(sourceUrl);
+       if (targetUrl)
+               free(targetUrl);
+       if (nextNonce)
+               free(nextNonce);
+       if (pCred != NULL)
+               free_cred(pCred);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+
+       if (credData != NULL)
+               free(credData);
+
+       if (id)
+               free(id);
+       if (pwd)
+               free(pwd);
+       if (sessionId)
+               free(sessionId);
+       if (sourceUrl)
+               free(sourceUrl);
+       if (targetUrl)
+               free(targetUrl);
+       if (nextNonce)
+               free(nextNonce);
+       if (pSyncML)
+               free_syncml(pSyncML);
+       if (pSyncHdr)
+               free_synchdr(pSyncHdr);
+       if (pCred)
+               free_cred(pCred);
+
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __generate_msg(void **syncObj, char **msg , unsigned int *msg_size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       bool isNeedNextMsg = false;
+
+       Binder_function_set *pBinder_function_set = NULL;
+
+       PROTOCOL_BINDER_ERROR err = init_oma_ds_1_2_binder_function_set(&pBinder_function_set);
+
+       protocol_binder *pBinder = NULL;
+       pBinder = oma_ds_1_2_binder_init(pBinder, COMMUNICATION_TYPE, false, false, false, true, pBinder_function_set);
+
+       /* create SyncHdr */
+       SyncHdr *pSyncHdr = NULL;
+       errorType = create_synchdr(session , &pSyncHdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create synchdr");
+               goto error;
+       }
+
+       err = oma_ds_1_2_binder_append(pBinder, PE_SYNCML_START, NULL);
+       err = oma_ds_1_2_binder_append(pBinder, PE_HEADER, pSyncHdr);
+       err = oma_ds_1_2_binder_append(pBinder, PE_BODY_START, NULL);
+
+       SyncObj **sync = (SyncObj **)syncObj;
+       GList *commands = NULL;
+       GList *commands_last = NULL;
+       int isFinal = 0;
+
+       errorType = __generate_msg_status_map_command(&session, sync, &commands, &commands_last);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in __generate_msg_status_map_command");
+               goto error;
+       }
+
+       /*append status command*/
+       GList *status_iter = NULL;
+       Status *pStatus = NULL;
+       for (status_iter = session->status; status_iter != NULL; status_iter = g_list_next(status_iter)) {
+               pStatus = (Status *)status_iter->data;
+               err = oma_ds_1_2_binder_append(pBinder, PE_STATUS, pStatus);
+       }
+
+       /*append results command*/
+       GList *results_iter = NULL;
+       Command *pResultsCommand = NULL;
+       for (results_iter = session->resultsCommand; results_iter != NULL; results_iter = g_list_next(results_iter)) {
+               pResultsCommand = (Command *)results_iter->data;
+               put_into_list(&commands, &commands_last, pResultsCommand);
+               err = oma_ds_1_2_binder_append(pBinder, PE_RESULTS_START, pResultsCommand);
+
+               if (pResultsCommand->type == COMMAND_TYPE_RESULTS) {
+                       if (pResultsCommand->private.results.item) {
+                               if (pResultsCommand->private.results.item->dataType == ITEM_DEVINF) {
+                                       err = oma_ds_1_2_binder_append(pBinder, PE_DEVINF, pResultsCommand->private.results.item);
+                               }
+                       }
+
+                       err = oma_ds_1_2_binder_append(pBinder, PE_RESULTS_END, NULL);
+               }
+       }
+
+       /*append map command*/
+       GList *map_iter = NULL;
+       Command *pMapCommand = NULL;
+       for (map_iter = session->mapCommand; map_iter != NULL; map_iter = g_list_next(map_iter)) {
+               pMapCommand = (Command *)map_iter->data;
+               err = oma_ds_1_2_binder_append(pBinder, PE_MAP, pMapCommand);
+       }
+
+       /* free sendgStatus structure from SE*/
+       free_sendingstatuses((*sync)->sendingStatus);
+       (*sync)->sendingStatus = NULL;
+
+       if (session->pkgStatus == SYNCML_PKG_3) {
+
+               errorType = __generate_msg_exist_sending_map_command(pBinder, &session, &commands, &commands_last);
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed in __generate_msg_status_map_command");
+                       goto error;
+               }
+
+               errorType = __generate_msg_changes_command(pBinder, &session, sync, &commands, &commands_last, &isNeedNextMsg);
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed in __generate_msg_status_map_command");
+                       goto error;
+               }
+
+               if (!isNeedNextMsg)
+                       isFinal = 1;
+       }
+
+       if (session->pkgStatus == SYNCML_PKG_5 && session->isReceivingFinal)
+               isFinal = 1;
+
+       /*if we have to send alert command(222,223 etc)*/
+       GList *alert_iter = NULL;
+       Command *pAlertCommand = NULL;
+       for (alert_iter = session->alertCommand; alert_iter != NULL; alert_iter = g_list_next(alert_iter)) {
+               pAlertCommand = alert_iter->data;
+               put_into_list(&commands, &commands_last, pAlertCommand);
+               err = oma_ds_1_2_binder_append(pBinder, PE_ALERT, pAlertCommand);
+       }
+
+       if (isFinal)
+               err = oma_ds_1_2_binder_append(pBinder, PE_FINAL, NULL);
+
+       session->isSendingfinal = isFinal;
+
+       err = oma_ds_1_2_binder_append(pBinder, PE_BODY_END, NULL);
+       err = oma_ds_1_2_binder_append(pBinder, PE_SYNCML_END, NULL);
+
+       oma_ds_1_2_binder_get_stream(pBinder, msg, msg_size);
+       FW_LOGV("final msg size = %d",   *msg_size);
+
+       /*FIXME for debugging*/
+       char *xml = NULL;
+       unsigned int xml_len = 0;
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               set_xml_to_file(*msg, OMA_DS_MSG_PATH);
+       else{
+               err = protocol_binder_get_xml_for_debugging(pBinder, &xml, &xml_len);
+               if (err == PROTOCOL_BINDER_OK) {
+                       set_xml_to_file(xml, OMA_DS_MSG_PATH);
+
+                       if (xml != NULL) {
+                               free(xml);
+                               xml = NULL;
+                       }
+               }
+       }
+
+       oma_ds_1_2_binder_terminate(pBinder);
+
+       if (session->pkgStatus == SYNCML_PKG_3 && session->isSendingfinal)
+               session->pkgStatus = SYNCML_PKG_4;
+       else if (session->pkgStatus == SYNCML_PKG_5 && session->isSendingfinal)
+               session->pkgStatus = SYNCML_PKG_6;
+
+       free_synchdr(pSyncHdr);
+       if (session->status != NULL) {
+               free_statuses(session->status);
+               session->status = NULL;
+       }
+       free_commands(commands);
+
+       session->status = NULL;
+       session->alertCommand = NULL;
+       session->resultsCommand = NULL;
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+
+       free_synchdr(pSyncHdr);
+       if (session->status != NULL) {
+               free_statuses(session->status);
+               session->status = NULL;
+       }
+       free_commands(commands);
+
+       return errorType;
+}
+
+static SA_ErrorType __generate_msg_status_map_command(Session **pSession, SyncObj **sync, GList **commands, GList **commands_last)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       DACI_RETURN da_err  = DACI_SUCCESS;
+
+       GList *iter = NULL;
+       SendingStatus *sendingStatus = NULL;
+       /* send status of sync, add, replace, delete command */
+       for (iter = (*sync)->sendingStatus; iter != NULL; iter = g_list_next(iter)) {
+               sendingStatus = (iter->data);
+
+               int needMap = 0;
+               GList *sendingIter = NULL;
+               AppliedStatus *appliedStatus = NULL;
+               for (sendingIter = sendingStatus->items; sendingIter != NULL; sendingIter = g_list_next(sendingIter)) {
+                       appliedStatus = (sendingIter->data);
+
+                       /* set data in status of add, replace, delete command */
+                       GList *statusIter = NULL;
+                       Status *status = NULL;
+                       for (statusIter = (*pSession)->tempStatus; statusIter != NULL; statusIter = g_list_next(statusIter)) {
+                               status = statusIter->data;
+
+                               if (status->type == COMMAND_TYPE_ADD ||
+                                               status->type == COMMAND_TYPE_REPLACE ||
+                                               status->type == COMMAND_TYPE_DELETE) {
+
+                                       /* if there is a status for add command it have to be checked
+                                       because map command has to be generated
+                                       otherwise replace, delete command doesnot need to generate map command*/
+                                       if (status->type == COMMAND_TYPE_ADD)
+                                               needMap = 1;
+
+                                       if (status->sourceRef) {
+                                               /*add command*/
+                                               char *guid = NULL;
+                                               guid = DACI_Get_Mapping_Guid((*pSession)->accountId,  appliedStatus->luid);
+                                               if (guid == NULL) {
+                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                       FW_LOGE("failed to get guid");
+                                                       goto error;
+                                               }
+                                               if (strcmp(guid, get_location_locuri(status->sourceRef)) == 0) {
+                                                       status->data = g_strdup_printf("%i", appliedStatus->status);
+                                                       /*move to status list from tempStatus*/
+                                                       (*pSession)->status = g_list_append((*pSession)->status, status);
+                                                       (*pSession)->tempStatus = g_list_remove((*pSession)->tempStatus, status);
+
+                                                       if (guid) {
+                                                               free(guid);
+                                                               guid = NULL;
+                                                       }
+
+                                                       break;
+                                               }
+
+                                               if (guid) {
+                                                       free(guid);
+                                                       guid = NULL;
+                                               }
+                                       }
+
+                                       if (status->targetRef) {
+                                               /*replace, delete*/
+                                               if (strcmp(appliedStatus->luid, get_location_locuri(status->targetRef)) == 0) {
+                                                       status->data = g_strdup_printf("%i", appliedStatus->status);
+                                                       /*move to status list from tempStatus*/
+                                                       (*pSession)->status = g_list_append((*pSession)->status, status);
+                                                       (*pSession)->tempStatus = g_list_remove((*pSession)->tempStatus, status);
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               if (needMap) {
+                       /* create map command */
+                       Command *mapCommand = NULL;
+                       Location *pSourceLocation = NULL;
+                       Location *pTargetLocation = NULL;
+                       errorType = create_location(sendingStatus->source, NULL, &pSourceLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_location(sendingStatus->target, NULL, &pTargetLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_map_command(*pSession, pSourceLocation, pTargetLocation, &mapCommand);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create map command");
+                               goto error;
+                       }
+
+                       GList *sendingIter = NULL;
+                       AppliedStatus *appliedStatus = NULL;
+
+                       for (sendingIter = sendingStatus->items; sendingIter != NULL; sendingIter = g_list_next(sendingIter)) {
+                               appliedStatus = (sendingIter->data);
+
+                               if (appliedStatus->changeType == CHANGE_ADD) {
+
+                                       if (appliedStatus->status == ITEM_ADDED) {
+                                               Item *temp = create_item();
+                                               if (!temp) {
+                                                       FW_LOGE("failed to create item");
+                                                       errorType = SA_INTERNAL_NO_MEMORY;
+                                                       goto error;
+                                               }
+
+                                               errorType = create_location(appliedStatus->luid, NULL, &pSourceLocation);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed to create location");
+                                                       goto error;
+                                               }
+
+                                               char *guid = NULL;
+                                               guid = DACI_Get_Mapping_Guid((*pSession)->accountId,  appliedStatus->luid);
+                                               if (guid == NULL) {
+                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                       FW_LOGE("failed to get guid");
+                                                       goto error;
+                                               }
+                                               errorType = create_location(guid, NULL, &pTargetLocation);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed to create location");
+                                                       goto error;
+                                               }
+
+                                               if (guid) {
+                                                       free(guid);
+                                                       guid = NULL;
+                                               }
+
+                                               set_item_source(temp, pSourceLocation);
+                                               set_item_target(temp, pTargetLocation);
+                                               set_map_command_item(mapCommand, temp);
+                                       } else{
+                                               da_err = DACI_Delete_Mapping_By_Luid((*pSession)->accountId,  appliedStatus->luid);
+                                               if (da_err != DACI_SUCCESS) {
+                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                       FW_LOGE("failed in DACI_Delete_Mapping_By_Luid");
+                                                       goto error;
+                                               }
+                                       }
+                               }
+                       }
+                       put_into_list(commands, commands_last, mapCommand);
+                       (*pSession)->mapCommand = g_list_append((*pSession)->mapCommand, mapCommand);
+                       increase_command_refcount(mapCommand);
+               }
+       }
+
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __generate_msg_exist_sending_map_command(protocol_binder *pBinder, Session **pSession,
+                                                                                                                                                                                                               GList **commands, GList **commands_last)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+
+       /*if there is something in the mapping_tbl it have to be sent before sync command*/
+       int existSendingMap = DACI_IsExist_Mapping_By_Account_Id(session->accountId);
+
+       if (existSendingMap) {
+               int count = 0;
+               daci_mapping *pDaci_mapping = DACI_Get_Mapping_By_Account_Id((*pSession)->accountId, &count);
+               FW_LOGV("count = %d", count);
+
+               Location *pSourceLocation = NULL;
+               Location *pTargetLocation = NULL;
+
+               bool exist = false;
+               int content_type;
+               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+                       FW_LOGV("datastoreinfo_per_content_type[%d]->datastore_id = %d", content_type, datastoreinfo_per_content_type[content_type]->datastore_id);
+
+                       if(datastoreinfo_per_content_type[content_type]->clientSyncType){
+                               if (pDaci_mapping[0].data_store_id == datastoreinfo_per_content_type[content_type]->datastore_id) {
+                                       errorType = create_location(datastoreinfo_per_content_type[content_type]->source, NULL, &pSourceLocation);
+                                       if (errorType != SA_INTERNAL_OK) {
+                                               FW_LOGE("failed to create location");
+                                               goto error;
+                                       }
+
+                                       errorType = create_location(datastoreinfo_per_content_type[content_type]->target, NULL , &pTargetLocation);
+                                       if (errorType != SA_INTERNAL_OK) {
+                                               FW_LOGE("failed to create location");
+                                               goto error;
+                                       }
+
+                                       exist = true;
+                                       break;
+                               }
+                       }
+               }
+
+               if (exist == false) {
+                       FW_LOGV("Mapping data is not equal with any synchronizing datastore id");
+                       goto error;
+               }
+
+               /* create map command using first item */
+               Command *mapCommand = NULL;
+               errorType = create_map_command(*pSession, pSourceLocation, pTargetLocation, &mapCommand);
+               if (errorType != SA_INTERNAL_OK) {
+                       FW_LOGE("failed to create map command");
+                       goto error;
+               }
+
+               int lastItemTypeId = pDaci_mapping[0].data_store_id;
+               int i;
+               for (i = 0; i < count; i++) {
+                       if (lastItemTypeId != pDaci_mapping[i].data_store_id) {
+                               err = oma_ds_1_2_binder_append(pBinder, PE_MAP, mapCommand);
+                               put_into_list(commands, commands_last, mapCommand);
+                               (*pSession)->mapCommand = g_list_append((*pSession)->mapCommand, mapCommand);
+                               increase_command_refcount(mapCommand);
+
+                               bool exist = false;
+                               int content_type;
+                               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+
+                                       if(datastoreinfo_per_content_type[content_type]->clientSyncType){
+                                               if (pDaci_mapping[0].data_store_id == datastoreinfo_per_content_type[content_type]->datastore_id) {
+                                                       errorType = create_location(datastoreinfo_per_content_type[content_type]->source, NULL, &pSourceLocation);
+                                                       if (errorType != SA_INTERNAL_OK) {
+                                                               FW_LOGE("failed to create location");
+                                                               goto error;
+                                                       }
+
+                                                       errorType = create_location(datastoreinfo_per_content_type[content_type]->target, NULL , &pTargetLocation);
+                                                       if (errorType != SA_INTERNAL_OK) {
+                                                               FW_LOGE("failed to create location");
+                                                               goto error;
+                                                       }
+
+                                                       exist = true;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               if (exist == false) {
+                                       FW_LOGE("Mapping data is not equal with any synchronizing datastore id");
+                                       goto error;
+                               }
+                       }
+                       lastItemTypeId = pDaci_mapping[i].data_store_id;
+                       Item *temp = create_item();
+                       if (!temp) {
+                               FW_LOGE("failed to create item");
+                               errorType = SA_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+                       errorType = create_location(pDaci_mapping[i].luid, NULL, &pSourceLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_location(pDaci_mapping[i].guid, NULL, &pTargetLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       set_item_source(temp, pSourceLocation);
+                       set_item_target(temp, pTargetLocation);
+                       set_map_command_item(mapCommand, temp);
+               }
+
+               DACI_Free_Memory_Mapping(pDaci_mapping, count);
+
+               err = oma_ds_1_2_binder_append(pBinder, PE_MAP, mapCommand);
+               put_into_list(commands, commands_last, mapCommand);
+               (*pSession)->mapCommand = g_list_append((*pSession)->mapCommand, mapCommand);
+               increase_command_refcount(mapCommand);
+       }
+
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+
+}
+
+static SA_ErrorType __generate_msg_changes_command(protocol_binder *pBinder, Session **pSession, SyncObj **sync,
+                                                                                                                                                                       GList **commands, GList **commands_last, bool *isNeedNextMsg)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       DACI_RETURN da_err  = DACI_SUCCESS;
+       PROTOCOL_BINDER_ERROR err = PROTOCOL_BINDER_OK;
+       unsigned int stream_size = 0;
+
+       char *data = NULL;      /*have to be freed*/
+       char *sendingData = NULL;
+
+       /* generate sync , add, replace, delete command when there is a item in ChangedDatastore */
+       GList *iter = NULL;
+       Command *syncCommand = NULL;
+       ChangedDatastore *changedDatastore = NULL;
+       bool needNextMsg = false;
+       for (iter = (*sync)->changedDatastore; iter != NULL; iter = g_list_next(iter)) {
+               changedDatastore = (iter->data);
+
+               if (changedDatastore->needSyncCommand) {
+                       /* create sync Command */
+                       Location *pSourceLocation = NULL;
+                       Location *pTargetLocation = NULL;
+                       errorType = create_location(changedDatastore->source, NULL, &pSourceLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_location(changedDatastore->target, NULL, &pTargetLocation);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create location");
+                               goto error;
+                       }
+
+                       errorType = create_sync_start_command(*pSession, pSourceLocation, pTargetLocation, &syncCommand);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create sync start command");
+                               goto error;
+                       }
+
+                       /*set numberOfChanges */
+                       if (changedDatastore->hasNumberOfChanges) {
+                               /*if it is first sync command set numberOfChanges*/
+                               set_sync_start_command_numberofchanges(syncCommand, changedDatastore->numberOfChanges);
+                               changedDatastore->hasNumberOfChanges = 0;
+                       }
+
+                       err = oma_ds_1_2_binder_append(pBinder, PE_SYNC_START, syncCommand);
+                       put_into_list(commands, commands_last, syncCommand);
+
+                       GList *itemIter = NULL;
+                       Command *changeCommand = NULL;
+                       ChangedItem *changedItem = NULL;
+                       OMA_DS_Protocol_Element protocol_element = PE_UNDEF;
+                       for (itemIter = changedDatastore->changeItem; itemIter != NULL;) {
+                               changedItem = (itemIter->data);
+
+                               oma_ds_1_2_binder_get_stream_size(pBinder, &stream_size);
+                               FW_LOGV("stream_size = %d",  stream_size);
+                               FW_LOGV("(*pSession)->targetMaxMsgSize = %d",  (*pSession)->targetMaxMsgSize);
+
+                               if ((*pSession)->targetMaxMsgSize > stream_size) {
+                                       /*there is a space for command*/
+                                       if (changedItem->changeType == CHANGE_DELETE) {
+                                               /* create delete Command */
+                                               errorType = create_delete_command(*pSession, changedItem->changeType, changedItem->luid, changedItem->content_type, &changeCommand);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed to create delete command");
+                                                       goto error;
+                                               }
+                                       } else{
+                                               int isFirstLargeObj ;
+                                               if (changedItem->data == NULL) {
+                                                       char *folderId = NULL;
+                                                       daci_id_list *folder_id_list = DACI_Get_Folder_Folder_Id_By_Folder_Type_Id((*pSession)->accountId,
+                                                                                                                                                                       datastoreinfo_per_content_type[changedItem->indexOfDatastore]->datastore_id,
+                                                                                                                                                                       datastoreinfo_per_content_type[changedItem->indexOfDatastore]->folder_type_id);
+                                                       if (folder_id_list != NULL) {
+                                                               if(folder_id_list->count > 0)
+                                                                       folderId = folder_id_list->id[0];
+                                                               else{
+                                                                       FW_LOGE("failed to get folderId");
+                                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                                       goto error;
+                                                               }
+                                                       }else{
+                                                               FW_LOGE("failed in DACI_Get_Folder_Folder_Id_By_Folder_Type_Id");
+                                                               errorType = SA_INTERNAL_DA_ERROR;
+                                                               goto error;
+                                                       }
+
+                                                       FW_LOGV("datastoreinfo_per_content_type[%d]->datastore_id = %d", changedItem->indexOfDatastore,
+                                                                       datastoreinfo_per_content_type[changedItem->indexOfDatastore]->datastore_id);
+                                                       FW_LOGV("accountId = %d", (*pSession)->accountId);
+                                                       FW_LOGV("folderId = %s", folderId);
+                                                       FW_LOGV("changedItem->luid = %s", changedItem->luid);
+
+                                                       da_err = DACI_Service_Get_Item(datastoreinfo_per_content_type[changedItem->indexOfDatastore]->datastore_id,
+                                                                                                               (*pSession)->accountId, folderId, changedItem->luid, (void **)&data);
+
+                                                       FW_LOGV("data = %s", data);
+                                                       DACI_Free_Memory_Id_List(folder_id_list);
+                                                       if (data == NULL) {
+                                                               /*if data is NULL(delete item since get change_log or drawing memo)
+                                                               delete that item from changelog_tbl, item_tbl*/
+                                                               da_err =  DACI_Delete_Item_By_Item_Id(changedItem->luid);
+                                                               if (da_err != DACI_SUCCESS) {
+                                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                                       FW_LOGE("failed in DACI_Delete_Item_By_Item_Id = %d", da_err);
+                                                                       goto error;
+                                                               }
+
+                                                               da_err = DACI_Delete_Item_Changelog_By_Item_Id((*pSession)->accountId, changedItem->luid);
+                                                               if (da_err != DACI_SUCCESS) {
+                                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                                       FW_LOGE("failed in DACI_Delete_Item_Changelog_By_Item_Id = %d", da_err);
+                                                                       goto error;
+                                                               }
+                                                               itemIter  = g_list_next(itemIter);
+                                                               changedDatastore->changeItem = g_list_remove(changedDatastore->changeItem, changedItem);
+                                                               free_changeditem(changedItem);
+                                                               continue;
+                                                       }
+
+                                                       if (da_err != DACI_SUCCESS) {
+                                                               FW_LOGE("failed in DACI_Service_Get_Item =%d", da_err);
+                                                               errorType = SA_INTERNAL_DA_ERROR;
+                                                               goto error;
+                                                       }
+
+                                                       isFirstLargeObj = 1;
+                                               } else{
+                                                       data = changedItem->data;
+                                                       changedItem->data = NULL;
+                                                       isFirstLargeObj = 0;
+                                               }
+
+                                               unsigned int sizeOfData = 0;
+                                               if (data != NULL)
+                                                       sizeOfData = strlen(data);
+
+                                               FW_LOGV("sizeOfData = %d", sizeOfData);
+                                               if ((*pSession)->targetMaxMsgSize < stream_size + sizeOfData) {
+                                                       /*can be LargeObj*/
+                                                       int availableSize = (*pSession)->targetMaxMsgSize - stream_size;
+                                                       if ((*pSession)->remoteDevInf->supportsLargeObjs /*&& availableSize > session->targetMaxMsgSize / 50*/) {
+
+                                                               /*if server support LargeObj & clearly LargeObj*/
+                                                               sendingData = calloc(availableSize + 1, sizeof(char));
+                                                               if (sendingData == NULL) {
+                                                                       FW_LOGE("failed to allocate sendingData");
+                                                                       errorType = SA_INTERNAL_NO_MEMORY;
+                                                                       goto error;
+                                                               }
+                                                               memcpy(sendingData, data, availableSize);
+                                                               FW_LOGV("sendingData = %s",  sendingData);
+                                                               FW_LOGV("sendingData size = %d", strlen(sendingData));
+
+                                                               char *remainingData = calloc(sizeOfData - availableSize + 1, sizeof(char));
+                                                               if (remainingData == NULL) {
+                                                                       FW_LOGE("failed to allocate remainingData");
+                                                                       errorType = SA_INTERNAL_NO_MEMORY;
+                                                                       goto error;
+                                                               }
+                                                               memcpy(remainingData, data+availableSize, sizeOfData - availableSize);
+                                                               FW_LOGV("sizeOfData - availableSize  = %d",  sizeOfData - availableSize);
+                                                               FW_LOGV("remainingData = %s", remainingData);
+                                                               FW_LOGV("remainingData size = %d",  strlen(remainingData));
+
+                                                               if (changedItem->data)
+                                                                       free(changedItem->data);
+
+                                                               set_changeditem_data(changedItem, remainingData);
+                                                               free(remainingData);
+
+                                                               PendingStatus *pTemp = NULL;
+                                                               errorType = create_pending_status((*pSession)->msgID, (*pSession)->cmdID, &pTemp);
+                                                               if (errorType != SA_INTERNAL_OK) {
+                                                                       FW_LOGE("failed to create pending status");
+                                                                       goto error;
+                                                               }
+                                                               (*pSession)->largeObj =  pTemp;
+
+                                                               if (changedItem->changeType == CHANGE_ADD) {
+                                                                       /* create add Command */
+                                                                       errorType = create_add_command(*pSession, changedItem->changeType, changedItem->luid,
+                                                                                               changedItem->content_type, sendingData, isFirstLargeObj == 1 ? sizeOfData : 0,  1 , &changeCommand);
+                                                               } else if (changedItem->changeType == CHANGE_REPLACE) {
+                                                                       /* create replace Command */
+                                                                       errorType = create_replace_command(*pSession, changedItem->changeType, changedItem->luid,
+                                                                                       changedItem->content_type, sendingData, isFirstLargeObj == 1 ? sizeOfData : 0,  1 , &changeCommand);
+                                                               }
+
+                                                               if (errorType != SA_INTERNAL_OK) {
+                                                                       FW_LOGE("failed to create add(replace) command");
+                                                                       goto error;
+                                                               }
+
+                                                               if (sendingData != NULL) {
+                                                                       free(sendingData);
+                                                                       sendingData = NULL;
+                                                               }
+                                                       } else{
+                                                               needNextMsg = true;
+                                                               break;
+                                                       }
+                                               } else {
+                                                       /*can append more commnad*/
+                                                       if (changedItem->changeType == CHANGE_ADD) {
+                                                               /* create add Command */
+                                                               errorType = create_add_command(*pSession, changedItem->changeType,
+                                                                               changedItem->luid, changedItem->content_type, data, 0, 0 , &changeCommand);
+                                                       } else if (changedItem->changeType == CHANGE_REPLACE) {
+                                                               /* create replace Command */
+                                                               errorType = create_replace_command(*pSession, changedItem->changeType,
+                                                                               changedItem->luid, changedItem->content_type, data, 0, 0 , &changeCommand);
+                                                       }
+                                                       if (errorType != SA_INTERNAL_OK) {
+                                                               FW_LOGE("failed to create add(replace) command");
+                                                               goto error;
+                                                       }
+                                               }
+                                       }
+                               } else{
+                                       needNextMsg = true;
+                                       break;
+                               }
+
+                               if (changeCommand->type == COMMAND_TYPE_ADD)
+                                       protocol_element = PE_ADD;
+                               else if (changeCommand->type == COMMAND_TYPE_REPLACE)
+                                       protocol_element = PE_REPLACE;
+                               else if (changeCommand->type == COMMAND_TYPE_DELETE)
+                                       protocol_element = PE_DELETE;
+
+
+                               err = oma_ds_1_2_binder_append(pBinder, protocol_element, changeCommand);
+                               oma_ds_1_2_binder_get_stream_size(pBinder, &stream_size);
+                               FW_LOGV("stream size after Changes Command= %d",  stream_size);
+                               put_into_list(commands, commands_last, changeCommand);
+
+                               if (changedItem->data == NULL) {
+                                       itemIter  = g_list_next(itemIter);
+                                       changedDatastore->sentItem = g_list_append(changedDatastore->sentItem, changedItem);
+                                       changedDatastore->changeItem = g_list_remove(changedDatastore->changeItem, changedItem);
+                               } else{
+                                       needNextMsg = true;
+                                       break;
+                               }
+
+                               if (data) {
+                                       free(data);
+                                       data = NULL;
+                               }
+                       }
+
+                       /* create sync end Command */
+                       errorType = create_sync_end_command(&syncCommand);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create sync end command");
+                               goto error;
+                       }
+                       err = oma_ds_1_2_binder_append(pBinder, PE_SYNC_END, syncCommand);
+                       put_into_list(commands, commands_last, syncCommand);
+
+                       if (needNextMsg)
+                               break;
+
+                       int chageItemCount = g_list_length(changedDatastore->changeItem);
+                       if (chageItemCount == 0)
+                               changedDatastore->needSyncCommand = 0;
+               }
+       }
+
+       if (data) {
+               free(data);
+               data = NULL;
+       }
+
+       *isNeedNextMsg = needNextMsg;
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+
+       if (sendingData != NULL) {
+               free(sendingData);
+               sendingData = NULL;
+       }
+
+       if (data != NULL) {
+               free(data);
+               data = NULL;
+       }
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __exchange_msg(char *accType, int transportType, char *targetUri , unsigned int session_id,
+                       GList *header_info, char *sendMsg, unsigned int sendMsg_length, GList **recv_header, char **recvMsg, unsigned int *recvMsg_length)
+{
+       FW_LOGV("start");
+       NACI_RESULT res = NACI_SUCCESS;
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       bool isXML;
+
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               isXML = true;
+       else
+               isXML = false;
+
+       NA_http_header_binder(accType, targetUri, isXML, &header_info);
+       res = NACI_Send_Msg(/*acc_info (id, pw, uri, ...),*/
+                               header_info,
+                               transportType,
+                               sendMsg,
+                               sendMsg_length,
+                               recv_header,
+                               (unsigned char **)recvMsg,
+                               recvMsg_length,
+                               SEND_N_RECEIVE,
+                               session_id);
+
+       if (res != NACI_SUCCESS) {
+               FW_LOGE("res = %d", res);
+               errorType = SA_INTERNAL_CONNECTION_ERROR;
+               goto error;
+       }
+
+       if (sendMsg)
+               free(sendMsg);
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error = %d", errorType);
+
+       if (sendMsg)
+               free(sendMsg);
+
+       return errorType;
+}
+
+
+static SA_ErrorType __process_recv_msg(char *recvMsg, unsigned int recvMsg_length, void **syncReturnObj, int *isFinish)
+{
+       FW_LOGV("start");
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       reset_cmdID_session(session);
+
+       SyncML* pSyncML = (SyncML *)calloc(1, sizeof(SyncML));
+       if (pSyncML == NULL) {
+               FW_LOGE("failed to allocate pSyncML");
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       GList *pReturnStatus = NULL;
+       GList *pReturnDatastore = NULL;
+
+       errorType = __reverse_object_binder(&pSyncML, recvMsg, recvMsg_length);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in reverseObjectBinder");
+               goto error;
+       }
+
+       /* check receive msg */
+       errorType = receive_header(session, pSyncML->hdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Header");
+               goto error;
+       }
+
+       errorType = receive_statuses(session, pSyncML->status, &pReturnStatus);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Statuses");
+               goto error;
+       }
+
+       errorType = receive_commands(session, pSyncML->commands, false, &pReturnDatastore);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Commands");
+               goto error;
+       }
+
+       if (pSyncML->final) {
+               session->isSendingfinal = 0;
+               session->isReceivingFinal = 1;
+       } else
+               session->isReceivingFinal = 0;
+
+       if (session->pkgStatus == SYNCML_PKG_2) {
+               PreSyncReturnObj ** pre = (PreSyncReturnObj **)syncReturnObj;
+               (*pre)->datastoreInfo = pReturnDatastore;
+
+               if (session->remoteDevInf) {
+                       if (session->remoteDevInf->devid != NULL)
+                               (*pre)->devID = strdup(session->remoteDevInf->devid);
+               }
+
+       } else {
+               SyncReturnObj **syncReturn = (SyncReturnObj **)syncReturnObj;
+               (*syncReturn)->status = pReturnStatus;
+               (*syncReturn)->changedDatastore = pReturnDatastore;
+       }
+
+       if (session->pkgStatus == SYNCML_PKG_2 && session->isReceivingFinal)
+               session->pkgStatus = SYNCML_PKG_3;
+       else if (session->pkgStatus == SYNCML_PKG_4 && session->isReceivingFinal) {
+               if (syncType == ALERT_REFRESH_FROM_CLIENT || syncType == ALERT_ONE_WAY_FROM_CLIENT) {
+                       *isFinish = 1;
+                       __clean_up_SA();
+               } else
+                       session->pkgStatus = SYNCML_PKG_5;
+       } else if (session->pkgStatus == SYNCML_PKG_6 && session->isReceivingFinal) {
+               *isFinish = 1;
+               __clean_up_SA();
+       }
+
+       if (recvMsg)
+               free(recvMsg);
+       if (pSyncML)
+               free_syncml(pSyncML);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+
+       if (recvMsg)
+               free(recvMsg);
+       if (pSyncML)
+               free_syncml(pSyncML);
+
+       return errorType;
+
+}
+
+static SA_ErrorType __generate_autoconfigure_msg(char *id, char *pwd, char *targetUrl, char **msg, unsigned int *msg_size, Session *pSession)
+{
+       FW_LOGV("start");
+       FW_LOGV("id = %s, pwd = %s, targetUrl = %s", id, pwd, targetUrl);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       int isFinal = 1;
+       char *credData = NULL;
+       Cred *pCred = NULL;
+       SyncHdr *pSyncHdr = NULL;
+       SyncML *pSyncML = NULL;
+
+       GList *commands = NULL;
+       GList *commands_last = NULL;
+
+       errorType = create_cred_string(AUTH_TYPE_BASIC,  id, pwd, NULL, 0, &credData);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create cred string");
+               goto error;
+       }
+
+       errorType = create_cred(id, pwd, AUTH_TYPE_BASIC, FORMAT_TYPE_BASE64, credData,  &pCred);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create cred");
+               goto error;
+       }
+
+       if (credData != NULL) {
+               free(credData);
+               credData = NULL;
+       }
+
+       set_session_cred(pSession, pCred);
+
+       errorType = create_synchdr(pSession , &pSyncHdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create synchdr");
+               goto error;
+       }
+
+       char *sourceDevInf = NULL;
+       if (pSession->protocolVersion == VERSION_10)
+               sourceDevInf = ELEMENT_DEVINF_10;
+       else if (pSession->protocolVersion == VERSION_11)
+               sourceDevInf = ELEMENT_DEVINF_11;
+       else if (pSession->protocolVersion == VERSION_12)
+               sourceDevInf = ELEMENT_DEVINF_12;
+
+       Location *pLocation  = NULL;
+       errorType = create_location(sourceDevInf, NULL, &pLocation);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create location");
+               goto error;
+       }
+
+       char *contentType = NULL;
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               contentType = ELEMENT_DEVINF_XML;
+       else
+               contentType = ELEMENT_DEVINF_WBXML;
+
+       /* create Get command */
+       Command *pGetCommand = NULL;
+       errorType = create_get_command(pSession, pLocation, contentType, &pGetCommand);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to get command");
+               goto error;
+       }
+       put_into_list(&commands, &commands_last, pGetCommand);
+
+
+       errorType = create_syncml(pSyncHdr, NULL, commands, isFinal, &pSyncML);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to get syncml");
+               goto error;
+       }
+
+       errorType = __object_binder(pSyncML, msg, msg_size);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in objectBinder");
+               goto error;
+       }
+
+       /*free generate structure*/
+       free_syncml(pSyncML);
+       pSyncML = NULL;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       if (pSyncHdr)
+               free_synchdr(pSyncHdr);
+       if (pCred)
+               free_cred(pCred);
+       if (credData != NULL)
+               free(credData);
+       if (commands)
+               free_commands(commands);
+       if (pSyncML)
+               free(pSyncML);
+
+       FW_LOGE("error : %d", errorType);
+
+       return errorType;
+}
+
+static SA_ErrorType __process_autoconfigure_recv_msg(char *recvMsg, unsigned int recvMsg_length, Session *pSession)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       SyncML* pSyncML = (SyncML *)calloc(1, sizeof(SyncML));
+       if (pSyncML == NULL) {
+               FW_LOGE("failed to allocate pSyncML");
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       errorType = __reverse_object_binder(&pSyncML, recvMsg, recvMsg_length);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in reverseObjectBinder");
+               goto error;
+       }
+
+       /* check receive msg */
+       errorType = receive_header(pSession, pSyncML->hdr);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Header");
+               goto error;
+       }
+
+       errorType = receive_statuses(pSession, pSyncML->status, NULL);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Statuses");
+               goto error;
+       }
+
+       errorType = receive_commands(pSession,  pSyncML->commands, true, NULL);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed in receive_Commands");
+               goto error;
+       }
+
+       if (recvMsg)
+               free(recvMsg);
+       if (pSyncML != NULL)
+               free_syncml(pSyncML);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+
+       if (recvMsg)
+               free(recvMsg);
+       if (pSyncML)
+               free_syncml(pSyncML);
+       return errorType;
+}
+
+static SA_ErrorType __object_binder(SyncML *pSyncML, char **msg, unsigned int *msg_size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Binder_function_set *pBinder_function_set = NULL;
+
+       PROTOCOL_BINDER_ERROR err = init_oma_ds_1_2_binder_function_set(&pBinder_function_set);
+
+       protocol_binder *pBinder = NULL;
+       char *xml = NULL;
+       unsigned int xml_len = 0;
+
+       pBinder = oma_ds_1_2_binder_init(pBinder, COMMUNICATION_TYPE, false, false, false, true, pBinder_function_set);
+
+       err = oma_ds_1_2_binder_append(pBinder, PE_SYNCML_START, NULL);
+       err = oma_ds_1_2_binder_append(pBinder, PE_HEADER, pSyncML->hdr);
+       err = oma_ds_1_2_binder_append(pBinder, PE_BODY_START, NULL);
+
+       GList *status_iter = NULL;
+       Status *pStatus = NULL;
+       for (status_iter = pSyncML->status; status_iter != NULL; status_iter = g_list_next(status_iter)) {
+               pStatus = status_iter->data;
+               err = oma_ds_1_2_binder_append(pBinder, PE_STATUS, pStatus);
+       }
+
+       GList *iter = NULL;
+       Command *pCommand = NULL;
+       OMA_DS_Protocol_Element protocol_element = PE_UNDEF;
+       for (iter = pSyncML->commands; iter != NULL; iter = g_list_next(iter)) {
+               pCommand = (Command *)(iter->data);
+
+               CommandType type = pCommand->type;
+               switch (type) {
+               case COMMAND_TYPE_UNKNOWN:
+                       protocol_element = PE_UNDEF;
+                       break;
+               case COMMAND_TYPE_ALERT:
+                       protocol_element = PE_ALERT;
+                       break;
+               case COMMAND_TYPE_SYNC_START:
+                       protocol_element = PE_SYNC_START;
+                       break;
+               case COMMAND_TYPE_SYNC_END:
+                       protocol_element = PE_SYNC_END;
+                       break;
+               case COMMAND_TYPE_PUT:
+                       protocol_element = PE_PUT_START;
+                       break;
+               case COMMAND_TYPE_ADD:
+                       protocol_element = PE_ADD;
+                       break;
+               case COMMAND_TYPE_REPLACE:
+                       protocol_element = PE_REPLACE;
+                       break;
+               case COMMAND_TYPE_DELETE:
+                       protocol_element = PE_DELETE;
+                       break;
+               case COMMAND_TYPE_MAP:
+                       protocol_element = PE_MAP;
+                       break;
+               case COMMAND_TYPE_GET:
+                       protocol_element = PE_GET;
+                       break;
+               case COMMAND_TYPE_RESULTS:
+                       protocol_element = PE_RESULTS_START;
+                       break;
+               case COMMAND_TYPE_HEADER:
+                       protocol_element = PE_HEADER;
+                       break;
+               }
+               err = oma_ds_1_2_binder_append(pBinder, protocol_element, pCommand);
+
+               if (type == COMMAND_TYPE_RESULTS) {
+                       err = oma_ds_1_2_binder_append(pBinder, PE_RESULTS_END, NULL);
+               }
+
+               if (type == COMMAND_TYPE_PUT) {
+                       if (pCommand->private.access.item) {
+                               if (pCommand->private.access.item->private.devInf) {
+                                       err = oma_ds_1_2_binder_append(pBinder, PE_DEVINF, pCommand->private.access.item);
+                               }
+                       }
+                       err = oma_ds_1_2_binder_append(pBinder, PE_PUT_END, NULL);
+               }
+       }
+
+       if (pSyncML->final) {
+               err = oma_ds_1_2_binder_append(pBinder, PE_FINAL, NULL);
+       }
+
+       err = oma_ds_1_2_binder_append(pBinder, PE_BODY_END, NULL);
+       err = oma_ds_1_2_binder_append(pBinder, PE_SYNCML_END, NULL);
+
+       oma_ds_1_2_binder_get_stream(pBinder, msg, msg_size);
+
+       /*FIXME for debugging*/
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               set_xml_to_file(*msg, OMA_DS_MSG_PATH);
+       else{
+               err = protocol_binder_get_xml_for_debugging(pBinder, &xml, &xml_len);
+               if (err == PROTOCOL_BINDER_OK) {
+                       set_xml_to_file(xml, OMA_DS_MSG_PATH);
+
+                       if (xml != NULL) {
+                               free(xml);
+                               xml = NULL;
+                       }
+               }
+       }
+
+       oma_ds_1_2_binder_terminate(pBinder);
+
+       if (err != PROTOCOL_BINDER_OK)
+               errorType = SA_INTERNAL_BINDER_ERROR;
+
+       FW_LOGV("end");
+
+       return errorType;
+}
+
+static SA_ErrorType __reverse_object_binder(SyncML **pSyncML, char *recv_msg, unsigned int recv_msg_length)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Binder_function_set *pBinder_function_set = NULL;
+
+       PROTOCOL_BINDER_ERROR err = init_oma_ds_1_2_binder_function_set(&pBinder_function_set);
+       Reverse_protocol_binder *pBinder = NULL;
+       char *xml = NULL;
+       unsigned int xml_len = 0;
+
+       Decoding dec;
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               dec = DECODING_XML;
+       else
+               dec = DECODING_WBXML;
+
+       err = reverse_oma_ds_1_2_binder_init(recv_msg, recv_msg_length,
+                                                                                       dec, pBinder_function_set, NULL, &pBinder);
+
+       if (err != PROTOCOL_BINDER_OK) {
+               errorType = SA_INTERNAL_BINDER_ERROR;
+               FW_LOGE("reverse_oma_ds_1_2_binder_init error =%d", err);
+               return errorType;
+       }
+
+
+       /*FIXME for debugging*/
+       if (COMMUNICATION_TYPE == ENCODING_XML)
+               set_xml_to_file(recv_msg, OMA_DS_MSG_PATH);
+       else{
+               err = reverse_protocol_binder_get_xml_for_debugging(pBinder, &xml, &xml_len);
+               if (err == PROTOCOL_BINDER_OK) {
+                       set_xml_to_file(xml, OMA_DS_MSG_PATH);
+
+                       if (xml != NULL) {
+                               free(xml);
+                               xml = NULL;
+                       }
+               }
+       }
+
+
+       OMA_DS_Protocol_Element protocol_element = PE_UNDEF;
+       char *protocol_element_name = NULL;
+       Content_Ptr pContent = NULL;
+       Command *tempCommandfordevInf = NULL;
+       while (err == PROTOCOL_BINDER_OK) {
+               protocol_element = PE_UNDEF;
+               err = reverse_oma_ds_1_2_binder_next(pBinder, &protocol_element, &protocol_element_name, &pContent);
+               switch (protocol_element) {
+                       case PE_ADD:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_ATOMIC_START:
+                       case PE_ATOMIC_END:
+                       case PE_COPY:
+                       case PE_DELETE:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_EXEC:
+                       case PE_GET:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_MAP:
+                       case PE_PUT_START:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               tempCommandfordevInf = pContent;
+                               break;
+                       case PE_SEARCH:
+                       case PE_SEQUENCE_START:
+                       case PE_SEQUENCE_END:
+                       case PE_SYNC_START:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_SYNC_END:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               protocol_element = PE_UNDEF;
+                               break;
+                       case PE_REPLACE:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_ALERT:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               break;
+                       case PE_RESULTS_START:
+                               (*pSyncML)->commands = g_list_append((*pSyncML)->commands, pContent);
+                               tempCommandfordevInf = pContent;
+                               break;
+                       case PE_STATUS:
+                               (*pSyncML)->status = g_list_append((*pSyncML)->status, pContent);
+                               protocol_element = PE_UNDEF;
+                               break;
+                       case PE_HEADER:
+                               (*pSyncML)->hdr = pContent;
+                               reverse_protocol_binder_set_user_data(pBinder, (*pSyncML)->hdr);
+                               break;
+                       case PE_PUT_GET:
+                       case PE_CMD_GROUP:
+                       case PE_GENERIC:
+                       case PE_FINAL:
+                               (*pSyncML)->final = (int)pContent;
+                               break;
+                       case PE_DEVINF:
+                               if (tempCommandfordevInf) {
+                                       tempCommandfordevInf->private.results.item->private.devInf = pContent;
+                                       tempCommandfordevInf = NULL;
+                               }
+                               break;
+                       default:
+                               break;
+               }
+
+               if (protocol_element_name != NULL) {
+                       free(protocol_element_name);
+                       protocol_element_name = NULL;
+               }
+
+               if (err == PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT) {
+                       break;
+               }
+       }
+
+       reverse_protocol_binder_terminate(pBinder);
+
+       free_oma_ds_1_2_binder_function_set(pBinder_function_set);
+
+       if (err != PROTOCOL_BINDER_OK && err != PROTOCOL_BINDER_HAS_NO_MORE_ELEMENT)
+               errorType = SA_INTERNAL_BINDER_ERROR;
+
+       return errorType;
+}
+
+static Common_ErrorType __convert_error_type(SA_ErrorType errorType)
+{
+       Common_ErrorType sa_errorType = COMMON_OK;
+
+       if (errorType == SA_INTERNAL_OK)
+               sa_errorType = COMMON_OK;
+       else if (errorType == SA_INTERNAL_MISCONFIGURATION)
+               sa_errorType = COMMON_MISCONFIGURATION;
+       else if (errorType == SA_INTERNAL_AUTHENTICATION_ERROR)
+               sa_errorType = COMMON_AUTHENTICATION_ERROR;
+       else if (errorType == SA_INTERNAL_NOT_FOUND)
+               sa_errorType = COMMON_NOT_FOUND;
+       else if (errorType == SA_INTERNAL_NO_MEMORY)
+               sa_errorType = COMMON_NO_MEMORY;
+       else if (errorType == SA_INTERNAL_NOT_DEFINED || errorType == SA_INTERNAL_BINDER_ERROR  ||
+                       errorType == SA_INTERNAL_ERROR || errorType == SA_INTERNAL_DA_ERROR)
+               sa_errorType = COMMON_INTERNAL_ERROR;
+       else if (errorType == SA_INTERNAL_SERVER_ERROR || errorType == SA_INTERNAL_SERVER_FAILURE)
+               sa_errorType = COMMON_SERVER_ERROR;
+       else if (errorType == SA_INTERNAL_CONNECTION_ERROR)
+               sa_errorType = COMMON_CONNECTION_ERROR;
+       else if (errorType == SA_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER)
+               sa_errorType = COMMON_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+       else if (errorType ==  SA_INTERNAL_CANCEL)
+               sa_errorType = COMMON_CANCEL;
+       else if (errorType ==  SA_INTERNAL_BUSY_SIGNALING)
+               sa_errorType = COMMON_BUSY_SIGNALING;
+
+
+       return sa_errorType;
+
+       /*from processRecvMsg
+       401 ->ERROR_AUTH_REJECTED :wrong password(header, datastore)
+       407 -> ERROR_AUTH_REQUIRED : try one more request and if failed again return ERROR_AUTH_REQUIRED(header, datastore)
+       404 -> ERROR_NOT_FOUND -> no datastore (important -> have to be noted to user)
+
+       1500 -> ERROR_INTERNAL_OK : processRecvMsg has been completed without any error
+
+       1513 -> ERROR_INTERNAL_NOT_DEFINED
+       1512 -> ERROR_INTERNAL_NO_MEMORY
+       1503 -> ERROR_INTERNAL_BINDER_ERROR
+
+       500 -> ERROR_GENERIC (our problem -> do not ever never receive this error)
+       511 ->ERROR_SERVER_FAILURE(our problem -> do not ever never receive this error)
+
+        can be return to engine value
+       from generatePreSyncMsg
+       1506 -> ERROR_INTERNAL_MISCONFIGURATION : need configure infomation
+       1500 -> ERROR_INTERNAL_OK : generatePreSyncMsg has been completed without any error
+       1512 -> ERROR_INTERNAL_NO_MEMORY : failed to allocate memory
+       1513 -> ERROR_INTERNAL_NOT_DEFINED : something is not defined that must have
+       1503 -> ERROR_INTERNAL_BINDER_ERROR     : binder error
+
+
+       from exchangeMsg
+
+       from processRecvMsg
+       401 ->ERROR_AUTH_REJECTED :wrong password(header, datastore)
+       407 -> ERROR_AUTH_REQUIRED : try one more request and if failed again return ERROR_AUTH_REQUIRED(header, datastore)
+       404 -> ERROR_NOT_FOUND -> no datastore (important -> have to be noted to user)
+
+       1500 -> ERROR_INTERNAL_OK : processRecvMsg has been completed without any error
+
+       1513 -> ERROR_INTERNAL_NOT_DEFINED
+       1512 -> ERROR_INTERNAL_NO_MEMORY
+       1503 -> ERROR_INTERNAL_BINDER_ERROR
+
+       500 -> ERROR_GENERIC (our problem -> do not ever never receive this error)
+       511 ->ERROR_SERVER_FAILURE(our problem -> do not ever never receive this error)*/
+
+}
+
+static void __clean_up_SA()
+{
+       FW_LOGV("start");
+
+       if (session != NULL) {
+
+               if (session->hasOpend) {
+                       NACI_Close_Connection(TRANSPORT_TYPE, session->NACI_sessionID);
+                       session->hasOpend = 0;
+               }
+
+               free_session(session);
+               session = NULL;
+       }
+
+       FW_LOGV("end");
+}
+
+int pre_sync(int transportType, int accountId, char *sessionId,  void **preSyncReturnObj)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       char *msg = NULL;
+       unsigned int msg_size = 0;
+       GList *recv_header = NULL;
+       GList *header_info = NULL;
+       char *recv_msg = NULL;
+       unsigned int recv_msg_size = 0;
+       unsigned int session_id;
+
+       /* generate preSync Msg */
+       errorType =  __generate_presync_msg(accountId, sessionId, &msg, &msg_size);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+       if (!session->hasOpend) {
+               NACI_RESULT res = NACI_Open_Connection(transportType, NETWORK_TIMEOUT, &session_id);
+               if (res != NACI_SUCCESS) {
+                       FW_LOGE("failed in NACI_Open_Connection res = %d", res);
+                       errorType = SA_INTERNAL_CONNECTION_ERROR;
+                       goto error;
+               }
+               session->NACI_sessionID = session_id;
+               session->hasOpend = 1;
+               FW_LOGV("session_id = %d", session_id);
+       }
+       /* exchange Msg */
+       errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, transportType, session->target->locURI,
+                       session->NACI_sessionID, header_info,  msg, msg_size, &recv_header, &recv_msg, &recv_msg_size);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       errorType = __process_recv_msg(recv_msg, recv_msg_size, preSyncReturnObj, NULL);
+       if (errorType == SA_INTERNAL_AUTHENTICATION_ERROR) {
+               /*when errortype is ERROR_AUTH_REQUIRED try request using chal just one more time
+               it can be only happend when server required MD5 authentication(we send basic authentication every time by default)*/
+               errorType =  __generate_presync_msg(accountId, sessionId, &msg, &msg_size);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               if (header_info != NULL) {
+                       GList *iter = NULL;
+                       for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                               free_header_info(iter->data);
+                       g_list_free(header_info);
+                       header_info = NULL;
+               }
+
+               if (recv_header != NULL) {
+                       GList *iter = NULL;
+                       common_header_info *iter_data;
+                       for (iter = recv_header; iter != NULL;) {
+                               iter_data = NULL;
+                               iter_data = ((common_header_info *)(iter->data));
+
+                               iter = g_list_next(iter);
+                               recv_header = g_list_remove(recv_header, iter_data);
+
+                               if (iter_data->key != NULL)
+                                       free(iter_data->key);
+                               if (iter_data->value != NULL)
+                                       free(iter_data->value);
+                               free(iter_data);
+                       }
+                       g_list_free(recv_header);
+               }
+
+               errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, transportType, session->target->locURI,
+                               session->NACI_sessionID, header_info, msg, msg_size, &recv_header, &recv_msg, &recv_msg_size);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               errorType = __process_recv_msg(recv_msg, recv_msg_size, preSyncReturnObj, NULL);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+       if (header_info != NULL) {
+               GList *iter = NULL;
+               for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                       free_header_info(iter->data);
+               g_list_free(header_info);
+               header_info = NULL;
+       }
+
+       if (recv_header != NULL) {
+               GList *iter = NULL;
+               common_header_info *iter_data;
+               for (iter = recv_header; iter != NULL;) {
+                       iter_data = NULL;
+                       iter_data = ((common_header_info *)(iter->data));
+
+                       iter = g_list_next(iter);
+                       recv_header = g_list_remove(recv_header, iter_data);
+
+                       if (iter_data->key != NULL)
+                               free(iter_data->key);
+                       if (iter_data->value != NULL)
+                               free(iter_data->value);
+                       free(iter_data);
+               }
+               g_list_free(recv_header);
+       }
+
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("errorType : %d", errorType);
+               __clean_up_SA();
+       }
+
+       return __convert_error_type(errorType);
+}
+
+int generate_msg(void **syncObj, char **msg, unsigned int *msg_size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       errorType = __generate_msg(syncObj, msg, msg_size);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("end");
+
+error:
+
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("errorType : %d", errorType);
+               __clean_up_SA();
+       }
+
+       return __convert_error_type(errorType);
+}
+
+int exchange_msg(int transportType, char *sendMsg, unsigned int sendMsg_length, char **recvMsg, unsigned int *recvMsg_length)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       GList *header_info = NULL;
+       GList *recv_header = NULL;
+
+       errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, transportType, session->target->locURI,
+                       session->NACI_sessionID, header_info, sendMsg, sendMsg_length, &recv_header, recvMsg, recvMsg_length);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("end");
+
+error:
+
+       if (header_info != NULL) {
+               GList *iter = NULL;
+               for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                       free_header_info(iter->data);
+               g_list_free(header_info);
+               header_info = NULL;
+       }
+
+       if (recv_header != NULL) {
+               GList *iter = NULL;
+               common_header_info *iter_data;
+               for (iter = recv_header; iter != NULL;) {
+                       iter_data = NULL;
+                       iter_data = ((common_header_info *)(iter->data));
+
+                       iter = g_list_next(iter);
+                       recv_header = g_list_remove(recv_header, iter_data);
+
+                       if (iter_data->key != NULL)
+                               free(iter_data->key);
+                       if (iter_data->value != NULL)
+                               free(iter_data->value);
+                       free(iter_data);
+               }
+               g_list_free(recv_header);
+       }
+
+        if (errorType != SA_INTERNAL_OK) {
+                FW_LOGE("errorType : %d", errorType);
+                __clean_up_SA();
+        }
+
+        return __convert_error_type(errorType);
+}
+
+int process_recv_msg(char *recvMsg, unsigned int recvMsg_length, void **syncReturnObj, int *isFinish)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       errorType = __process_recv_msg(recvMsg, recvMsg_length, syncReturnObj, isFinish);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("end");
+
+error:
+
+        if (errorType != SA_INTERNAL_OK) {
+                FW_LOGE("errorType : %d", errorType);
+                __clean_up_SA();
+        }
+
+        return __convert_error_type(errorType);
+}
+
+void clean_up_SA()
+{
+       FW_LOGV("start");
+
+       __clean_up_SA();
+
+       FW_LOGV("end");
+}
+
+int auto_configure_from_vconf(char *id, char *pwd, char *targetUrl, char *profilePath, GList **configure)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Session *pSession = NULL;
+
+       char *sourceUrl = NULL;
+       char *sessionId = NULL;
+
+       char *msg = NULL;
+       unsigned int msg_size = 0;
+
+       GList *header_info = NULL;
+       GList *recv_header = NULL;
+       char *recv_msg = NULL;
+       unsigned int recv_msg_size = 0;
+
+       bool cancel_flag = false;
+       unsigned int session_id;
+
+       sessionId = g_strdup_printf("%ld", time(NULL));
+       if (sessionId == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       DCI_RETURN err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &sourceUrl);
+       if (err != DCI_SUCCESS) {
+               FW_LOGV("failed in DCI_Get_DevInfo");
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       errorType = create_session(VERSION_12, PROTOCOL_TYPE_DS, 0, sessionId, sourceUrl, targetUrl, &pSession);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       if (pSession == NULL) {
+               FW_LOGV("failed to create session");
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       errorType = __generate_autoconfigure_msg(id, pwd, targetUrl, &msg, &msg_size , pSession);
+       if (errorType != SA_INTERNAL_OK){
+               FW_LOGV("failed in __generate_autoconfigure_msg");
+               goto error;
+       }
+
+       if (!pSession->hasOpend) {
+               NACI_RESULT res = NACI_Open_Connection(TRANSPORT_TYPE, NETWORK_TIMEOUT, &session_id);
+               if (res != NACI_SUCCESS) {
+                       FW_LOGE("failed in NACI_Open_Connection res = %d", res);
+                       errorType = SA_INTERNAL_CONNECTION_ERROR;
+                       goto error;
+               }
+               pSession->NACI_sessionID = session_id;
+               pSession->hasOpend = 1;
+               FW_LOGV("session_id = %d", session_id);
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       /* exchange Msg */
+       errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, TRANSPORT_TYPE, pSession->target->locURI,
+                       pSession->NACI_sessionID, header_info, msg, msg_size, &recv_header, &recv_msg, &recv_msg_size);
+       if (errorType != SA_INTERNAL_OK){
+               FW_LOGV("failed in __exchange_msg");
+               goto error;
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       errorType = __process_autoconfigure_recv_msg(recv_msg, recv_msg_size, pSession);
+       if (errorType != SA_INTERNAL_OK){
+               FW_LOGV("failed in __process_autoconfigure_recv_msg");
+               goto error;
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       DevInf *devInf = pSession->remoteDevInf;
+       if (devInf) {
+
+               GList *tempConfigure = NULL;
+
+               GList *contactCandidate = NULL;
+               GList *calendarCandidate = NULL;
+               GList *memoCandidate = NULL;
+
+               /*set inputted name by user*/
+               contactCandidate = g_list_append(contactCandidate, strdup(DEFINE_SOURCE_CONTACT_URI));
+               char *target = NULL;
+               target = get_vconf_str(profilePath, DS_SETTING_CONTACT_TGTURI);
+               if (target) {
+                       FW_LOGV("Contacts target =%s",  target);
+                       if (strcmp(target, "") != 0)
+                               contactCandidate = g_list_append(contactCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+
+               calendarCandidate = g_list_append(calendarCandidate, strdup(DEFINE_SOURCE_CALENDAR_URI));
+               target = get_vconf_str(profilePath, DS_SETTING_CALENDAR_TGTURI);
+               if (target) {
+                       FW_LOGV("Organizer target =%s", target);
+                       if (strcmp(target, "") != 0)
+                               calendarCandidate = g_list_append(calendarCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+
+               memoCandidate = g_list_append(memoCandidate, strdup(DEFINE_SOURCE_MEMO_URI));
+               target = get_vconf_str(profilePath, DS_SETTING_MEMO_TGTURI);
+               if (target) {
+                       FW_LOGV("Memo target =%s", target);
+                       if (strcmp(target, "") != 0)
+                               memoCandidate = g_list_append(memoCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+
+               GList *iter = NULL;
+               GList *innerIter = NULL;
+               DevInfDataStore *devInfDataStore = NULL;
+               int exist;
+               char *candidate;
+               for (iter = devInf->datastores; iter != NULL; iter = g_list_next(iter)) {
+                       devInfDataStore = iter->data;
+                       exist = 0;
+                       candidate = NULL;
+
+                       FW_LOGV("devInfDataStore->sourceref = %s", devInfDataStore->sourceref);
+
+                       if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCARD) == 0 ||
+                                       strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCARD_30) == 0) {
+
+                               for (innerIter = g_list_next(contactCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       contactCandidate = g_list_append(contactCandidate, strdup(devInfDataStore->sourceref));
+
+                       } else if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCAL) == 0 ||
+                                       strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_ICAL) == 0) {
+
+                               for (innerIter = g_list_next(calendarCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       calendarCandidate = g_list_append(calendarCandidate, strdup(devInfDataStore->sourceref));
+
+                       } else if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_PLAIN) == 0) {
+
+                               for (innerIter = g_list_next(memoCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       memoCandidate = g_list_append(memoCandidate, strdup(devInfDataStore->sourceref));
+                       }
+               }
+
+               tempConfigure = g_list_append(tempConfigure, contactCandidate);
+               tempConfigure = g_list_append(tempConfigure, calendarCandidate);
+               tempConfigure = g_list_append(tempConfigure, memoCandidate);
+
+               *configure = tempConfigure;
+
+//             *congifure = g_list_append(*congifure, contactCandidate);
+//             *congifure = g_list_append(*congifure, calendarCandidate);
+//             *congifure = g_list_append(*congifure, memoCandidate);
+
+       } else{
+               errorType = SA_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       /*close network*/
+       if (pSession != NULL) {
+               if (pSession->hasOpend)
+                       NACI_Close_Connection(TRANSPORT_TYPE, pSession->NACI_sessionID);
+       }
+
+       if (header_info != NULL) {
+               GList *iter = NULL;
+               for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                       free_header_info(iter->data);
+               g_list_free(header_info);
+               header_info = NULL;
+       }
+
+       if (recv_header != NULL) {
+               GList *iter = NULL;
+               common_header_info *iter_data;
+               for (iter = recv_header; iter != NULL;) {
+                       iter_data = NULL;
+                       iter_data = ((common_header_info *)(iter->data));
+
+                       iter = g_list_next(iter);
+                       recv_header = g_list_remove(recv_header, iter_data);
+
+                       if (iter_data->key != NULL)
+                               free(iter_data->key);
+                       if (iter_data->value != NULL)
+                               free(iter_data->value);
+                       free(iter_data);
+               }
+               g_list_free(recv_header);
+       }
+
+       if (sessionId)
+               free(sessionId);
+
+       if (sourceUrl)
+               free(sourceUrl);
+
+       if (pSession) {
+               free_session(pSession);
+               pSession = NULL;
+       }
+
+       if (errorType != SA_INTERNAL_OK)
+               FW_LOGE("errorType =%d", errorType);
+
+       return __convert_error_type(errorType);
+}
+
+
+int auto_configure(char *addr, char *id, char *password, GList **configure)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Session *pSession = NULL;
+
+       char *sourceUrl = NULL;
+       char *sessionId = NULL;
+
+       char *msg = NULL;
+       unsigned int msg_size = 0;
+
+       GList *header_info = NULL;
+       GList *recv_header = NULL;
+       char *recv_msg = NULL;
+       unsigned int recv_msg_size = 0;
+
+       bool cancel_flag = false;
+       unsigned int session_id;
+
+       sessionId = g_strdup_printf("%ld", time(NULL));
+       if (sessionId == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       DCI_RETURN err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &sourceUrl);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       errorType = create_session(VERSION_12, PROTOCOL_TYPE_DS, 0, sessionId, sourceUrl, addr, &pSession);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       if (pSession == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       errorType = __generate_autoconfigure_msg(id, password, addr, &msg, &msg_size , pSession);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       if (!pSession->hasOpend) {
+               NACI_RESULT res = NACI_Open_Connection(TRANSPORT_TYPE, NETWORK_TIMEOUT, &session_id);
+               if (res != NACI_SUCCESS) {
+                       FW_LOGE("failed in NACI_Open_Connection res = %d", res);
+                       errorType = SA_INTERNAL_CONNECTION_ERROR;
+                       goto error;
+               }
+               pSession->NACI_sessionID = session_id;
+               pSession->hasOpend = 1;
+               FW_LOGV("session_id = %d", session_id);
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       /* exchange Msg */
+       errorType = __exchange_msg(DEFINE_PROTOCOL_TYPE, TRANSPORT_TYPE, pSession->target->locURI,
+                       pSession->NACI_sessionID, header_info, msg, msg_size, &recv_header, &recv_msg, &recv_msg_size);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       errorType = __process_autoconfigure_recv_msg(recv_msg, recv_msg_size, pSession);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               errorType = SA_INTERNAL_CANCEL;
+               goto error;
+       }
+
+       DevInf *devInf = pSession->remoteDevInf;
+       if (devInf) {
+
+               GList *tempConfigure = NULL;
+
+               GList *contactCandidate = NULL;
+               GList *calendarCandidate = NULL;
+               GList *memoCandidate = NULL;
+
+               /*set inputted name by user*/
+               contactCandidate = g_list_append(contactCandidate, strdup(DEFINE_SOURCE_CONTACT_URI));
+               /*
+               char *target = NULL;
+               target= get_vconf_str(profilePath, DS_SETTING_CONTACT_TGTURI);
+               if (target) {
+                       FW_LOGV("Contacts target =%s",  target);
+                       if (strcmp(target, "") !=0)
+                               contactCandidate = g_list_append(contactCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+               */
+
+               calendarCandidate = g_list_append(calendarCandidate, strdup(DEFINE_SOURCE_CALENDAR_URI));
+               /*
+               target = get_vconf_str(profilePath, DS_SETTING_CALENDAR_TGTURI);
+               if (target) {
+                       FW_LOGV("Organizer target =%s", target);
+                       if (strcmp(target, "") !=0)
+                               calendarCandidate = g_list_append(calendarCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+               */
+
+               memoCandidate = g_list_append(memoCandidate, strdup(DEFINE_SOURCE_MEMO_URI));
+               /*
+               target = get_vconf_str(profilePath, DS_SETTING_MEMO_TGTURI);
+               if (target) {
+                       FW_LOGV("Memo target =%s", target);
+                       if (strcmp(target, "") !=0)
+                               memoCandidate = g_list_append(memoCandidate, strdup(target));
+
+                       free(target);
+                       target = NULL;
+               }
+               */
+
+               GList *iter = NULL;
+               GList *innerIter = NULL;
+               DevInfDataStore *devInfDataStore = NULL;
+               int exist;
+               char *candidate;
+               for (iter = devInf->datastores; iter != NULL; iter = g_list_next(iter)) {
+                       devInfDataStore = iter->data;
+                       exist = 0;
+                       candidate = NULL;
+
+                       FW_LOGV("devInfDataStore->sourceref = %s", devInfDataStore->sourceref);
+
+                       if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCARD) == 0 ||
+                                       strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCARD_30) == 0) {
+
+                               for (innerIter = g_list_next(contactCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       contactCandidate = g_list_append(contactCandidate, strdup(devInfDataStore->sourceref));
+
+                       } else if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_VCAL) == 0 ||
+                                       strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_ICAL) == 0) {
+
+                               for (innerIter = g_list_next(calendarCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       calendarCandidate = g_list_append(calendarCandidate, strdup(devInfDataStore->sourceref));
+
+                       } else if (strcmp(devInfDataStore->rxPref->cttype, ELEMENT_TEXT_PLAIN) == 0) {
+
+                               for (innerIter = g_list_next(memoCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) {
+                                       candidate = innerIter->data;
+
+                                       if (strcmp(candidate, devInfDataStore->sourceref) == 0)
+                                               exist = 1;
+                               }
+                               if (!exist)
+                                       memoCandidate = g_list_append(memoCandidate, strdup(devInfDataStore->sourceref));
+                       }
+               }
+
+               tempConfigure = g_list_append(tempConfigure, contactCandidate);
+               tempConfigure = g_list_append(tempConfigure, calendarCandidate);
+               tempConfigure = g_list_append(tempConfigure, memoCandidate);
+
+               *configure = tempConfigure;
+
+
+//             *congifure = g_list_append(*congifure, contactCandidate);
+//             *congifure = g_list_append(*congifure, calendarCandidate);
+//             *congifure = g_list_append(*congifure, memoCandidate);
+
+       } else{
+               errorType = SA_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       /*close network*/
+        if (pSession != NULL) {
+                if (pSession->hasOpend)
+                        NACI_Close_Connection(TRANSPORT_TYPE, pSession->NACI_sessionID);
+        }
+
+        if (header_info != NULL) {
+                GList *iter = NULL;
+                for (iter = header_info; iter != NULL; iter = g_list_next(iter))
+                        free_header_info(iter->data);
+                g_list_free(header_info);
+                header_info = NULL;
+        }
+
+       if (recv_header != NULL) {
+               GList *iter = NULL;
+               common_header_info *iter_data;
+               for (iter = recv_header; iter != NULL;) {
+                       iter_data = NULL;
+                       iter_data = ((common_header_info *)(iter->data));
+
+                       iter = g_list_next(iter);
+                       recv_header = g_list_remove(recv_header, iter_data);
+
+                       if (iter_data->key != NULL)
+                               free(iter_data->key);
+                       if (iter_data->value != NULL)
+                               free(iter_data->value);
+                       free(iter_data);
+               }
+               g_list_free(recv_header);
+       }
+
+       if (sessionId)
+               free(sessionId);
+
+       if (sourceUrl)
+               free(sourceUrl);
+
+       if (pSession) {
+               free_session(pSession);
+               pSession = NULL;
+       }
+
+       if (errorType != SA_INTERNAL_OK)
+               FW_LOGE("errorType =%d", errorType);
+
+       return __convert_error_type(errorType);
+}
+
+/*FIXME cancel request to NA */
+/*int cancel_connection_sync_request(char *transportType)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType err = SA_INTERNAL_OK;
+       NACI_RESULT res = NACI_SUCCESS;
+
+       FW_LOGV("sessionId = %d", session->NACI_sessionID);
+
+       res =  NACI_Cancel_Msg(transportType, session->NACI_sessionID);
+       if (res != NACI_SUCCESS) {
+               FW_LOGE("res = %d", res);
+               err = SA_INTERNAL_CONNECTION_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return __convert_error_type(err);
+}*/
diff --git a/src/ServiceAdapter/SA_DevInf.c b/src/ServiceAdapter/SA_DevInf.c
new file mode 100644 (file)
index 0000000..6a39b64
--- /dev/null
@@ -0,0 +1,1023 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_DevInf.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions for device information structure which is used in Service Adapter
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/Device/EXT_DCI_DevInfo.h"
+#include "agent-framework/DACI/EXT_DACI_Converter.h"
+#include "ServiceAdapter/SA_DevInf.h"
+#include "ServiceAdapter/SA_DevInf_Internal.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+#include "Common/Common_Define.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+static SA_ErrorType __create_devinf_new(char *devid, DevInfDevTyp devtyp, DevInf **pDevInf);
+static SA_ErrorType __create_devinf_contenttype(char *cttype, char *verct, DevInfContentType **pDevInfContentType);
+static SA_ErrorType __create_devinf_ctcap(DevInfContentType *devInfContentType, DevInfCTCap **pDevInfCTCap);
+static SA_ErrorType __create_devinf_property(char *propName, DevInfProperty **pDevInfProperty);
+
+static SA_ErrorType create_devinf_datastore(char *dataStore, DevInfDataStore **pDevInfDataStore);
+static void __free_devinf_datastores(GList *devInfDatastores);
+static void __free_devinf_datastore(DevInfDataStore *pDevInfDataStore);
+static void __free_devinf_contenttype(DevInfContentType *pDevInfContentType);
+static void __free_devinf_ctcaps(DevInfCTCap *pDevInfCTCap);
+static void __free_devinf_property(DevInfProperty *pDevInfProperty);
+static void __free_devinf_propparam(DevInfPropParam *pDevInfPropParam);
+static void __set_devinf_version(DevInf *devInf, DevInfVersion version);
+static void __set_devinf_manufacturer(DevInf *devInf, char *manufacturer);
+static void __set_devinf_model(DevInf *devInf, char *model);
+static void __set_devinf_oem(DevInf *devInf, char *oem);
+static void __set_devinf_software_version(DevInf *devInf, char *softwareVersion);
+static void __set_devinf_hardware_version(DevInf *devInf, char *hardwareVersion);
+static void __set_devinf_firmware_version(DevInf *devInf, char *firmwareVersion);
+static void __set_devinf_datastore(DevInf *devInf, DevInfDataStore *devInfDataStore);
+static void __set_devinf_datastore_rxpref(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType);
+static void __set_devinf_datastore_txpref(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType);
+static void __set_devinf_datastore_ctcap(DevInfDataStore *devInfDataStore, DevInfCTCap *devInfCTCap);
+static void __set_devinf_ctcap_property(DevInfCTCap *devInfCTCap, DevInfProperty *devInfProperty);
+static void __set_devInf_property_valenums(DevInfProperty *devInfProperty, char*valEnum);
+static DevInfDevTyp __convert_devtyp(char *devTyp);
+
+/* unused function
+ *  keep for in case
+ */
+/*
+static ErrorType create_DevInfPropParam(char *paramName, DevInfPropParam **pDevInfPropParam);
+static void set_DevInfDataStoreDisplayname(DevInfDataStore* devInfDataStore, char *displayname);
+static void set_DevInfDataStoreRx(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType);
+static void set_DevInfDataStoreTx(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType);
+static void set_DevInfPropertyDataType(DevInfProperty *devInfProperty, char *dataType);
+static void set_DevInfPropertyMaxOccur(DevInfProperty *devInfProperty, unsigned int maxOccur);
+static void set_DevInfPropertyMaxSize(DevInfProperty *devInfProperty, unsigned int maxSize);
+static void set_DevInfPropertyNoTruncate(DevInfProperty *devInfProperty, int noTruncate);
+static void set_DevInfPropertyDisplayName(DevInfProperty *devInfProperty, char *displayName);
+static void set_DevInfPropertyPropParam(DevInfProperty *devInfProperty, DevInfPropParam *devInfPropParam);
+static void set_DevInfPropParamDataType(DevInfPropParam *devInfPropParam, char *dataType);
+static void set_DevInfPropParamDisplayName(DevInfPropParam *devInfPropParam, char *displayName);
+static void set_DevInfPropParamValEnums(DevInfPropParam *devInfPropParam, char *valEnum);
+*/
+
+static SA_ErrorType __create_devinf_new(char *devid, DevInfDevTyp devtyp, DevInf **pDevInf)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!devid) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!devtyp) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInf = (DevInf *)calloc(1, sizeof(DevInf));
+       if (*pDevInf == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       if (devid != NULL)
+               (*pDevInf)->devid = strdup(devid);
+       (*pDevInf)->devtyp = devtyp;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __create_devinf_contenttype(char *cttype, char *verct, DevInfContentType **pDevInfContentType)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!cttype) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!verct) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfContentType = (DevInfContentType *)calloc(1, sizeof(DevInfContentType));
+       if (*pDevInfContentType == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfContentType)->cttype = strdup(cttype);
+       (*pDevInfContentType)->verct = strdup(verct);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __create_devinf_ctcap(DevInfContentType *devInfContentType, DevInfCTCap **pDevInfCTCap)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!devInfContentType) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfCTCap = (DevInfCTCap *)calloc(1, sizeof(DevInfCTCap));
+       if (*pDevInfCTCap == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfCTCap)->ct = devInfContentType;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+
+}
+
+static SA_ErrorType __create_devinf_property(char *propName, DevInfProperty **pDevInfProperty)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!propName) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfProperty = (DevInfProperty *)calloc(1, sizeof(DevInfProperty));
+       if (*pDevInfProperty == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfProperty)->propName = strdup(propName);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType create_devinf_datastore(char *dataStore, DevInfDataStore **pDevInfDataStore)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!dataStore) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfDataStore = (DevInfDataStore *)calloc(1, sizeof(DevInfDataStore));
+       if (*pDevInfDataStore == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfDataStore)->sourceref = strdup(dataStore);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+static void __free_devinf_datastores(GList *devInfDatastores)
+{
+       FW_LOGV("start");
+
+       if (!devInfDatastores)
+               return;
+
+       GList *iter = NULL;
+       for (iter = devInfDatastores; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_datastore(iter->data);
+
+       g_list_free(devInfDatastores);
+
+       FW_LOGV("end");
+}
+
+static void __free_devinf_datastore(DevInfDataStore *pDevInfDataStore)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfDataStore)
+               return;
+
+       if (pDevInfDataStore->sourceref) {
+               free(pDevInfDataStore->sourceref);
+               pDevInfDataStore->sourceref = NULL;
+       }
+
+       if (pDevInfDataStore->displayname) {
+               free(pDevInfDataStore->displayname);
+               pDevInfDataStore->displayname = NULL;
+       }
+
+       __free_devinf_contenttype(pDevInfDataStore->rxPref);
+       pDevInfDataStore->rxPref = NULL;
+
+       __free_devinf_contenttype(pDevInfDataStore->txPref);
+       pDevInfDataStore->txPref = NULL;
+
+       /*free_FilterRx(filter_rx);*/
+       /*free_FilterCap(filterCap);*/
+
+       GList *iter = NULL;
+       for (iter = pDevInfDataStore->rx; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_contenttype(iter->data);
+       g_list_free(pDevInfDataStore->rx);
+
+       for (iter = pDevInfDataStore->tx; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_contenttype(iter->data);
+       g_list_free(pDevInfDataStore->tx);
+
+       for (iter = pDevInfDataStore->ctcaps; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_ctcaps(iter->data);
+       g_list_free(pDevInfDataStore->ctcaps);
+
+       free(pDevInfDataStore);
+
+       FW_LOGV("end");
+
+}
+
+static void __free_devinf_contenttype(DevInfContentType *pDevInfContentType)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfContentType)
+               return;
+
+       if (pDevInfContentType->cttype) {
+               free(pDevInfContentType->cttype);
+               pDevInfContentType->cttype = NULL;
+       }
+
+       if (pDevInfContentType->verct) {
+               free(pDevInfContentType->verct);
+               pDevInfContentType->verct = NULL;
+       }
+
+       free(pDevInfContentType);
+
+       FW_LOGV("end");
+}
+
+static void __free_devinf_ctcaps(DevInfCTCap *pDevInfCTCap)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfCTCap)
+               return;
+
+       __free_devinf_contenttype(pDevInfCTCap->ct);
+       pDevInfCTCap->ct = NULL;
+
+       GList *iter = NULL;
+       for (iter = pDevInfCTCap->properties; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_property(iter->data);
+
+       g_list_free(pDevInfCTCap->properties);
+
+       free(pDevInfCTCap);
+
+       FW_LOGV("end");
+
+}
+
+static void __free_devinf_property(DevInfProperty *pDevInfProperty)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfProperty)
+               return;
+
+       if (pDevInfProperty->propName) {
+               free(pDevInfProperty->propName);
+               pDevInfProperty->propName = NULL;
+       }
+
+       if (pDevInfProperty->dataType) {
+               free(pDevInfProperty->dataType);
+               pDevInfProperty->dataType = NULL;
+       }
+
+       if (pDevInfProperty->displayName) {
+               free(pDevInfProperty->displayName);
+               pDevInfProperty->displayName = NULL;
+       }
+
+       GList *iter = NULL;
+       for (iter = pDevInfProperty->valEnums; iter != NULL; iter = g_list_next(iter))
+               free(iter->data);
+
+       g_list_free(pDevInfProperty->valEnums);
+
+
+       for (iter = pDevInfProperty->propParams; iter != NULL; iter = g_list_next(iter))
+               __free_devinf_propparam(iter->data);
+
+       g_list_free(pDevInfProperty->propParams);
+
+       free(pDevInfProperty);
+
+       FW_LOGV("end");
+}
+
+static void __free_devinf_propparam(DevInfPropParam *pDevInfPropParam)
+{
+       FW_LOGV("start");
+
+       if (!pDevInfPropParam)
+               return;
+
+       if (pDevInfPropParam->paramName) {
+               free(pDevInfPropParam->paramName);
+               pDevInfPropParam->paramName = NULL;
+       }
+
+       if (pDevInfPropParam->dataType) {
+               free(pDevInfPropParam->dataType);
+               pDevInfPropParam->dataType = NULL;
+       }
+
+       if (pDevInfPropParam->displayName) {
+               free(pDevInfPropParam->displayName);
+               pDevInfPropParam->displayName = NULL;
+       }
+
+       GList *iter = NULL;
+       for (iter = pDevInfPropParam->valEnums; iter != NULL; iter = g_list_next(iter))
+               free(iter->data);
+
+       g_list_free(pDevInfPropParam->valEnums);
+
+       free(pDevInfPropParam);
+
+       FW_LOGV("end");
+
+}
+
+static void __set_devinf_version(DevInf *devInf, DevInfVersion version)
+{
+       if (!devInf)
+               return;
+
+       devInf->version = version;
+}
+
+static void __set_devinf_manufacturer(DevInf *devInf, char *manufacturer)
+{
+       if (!devInf)
+               return;
+
+       if (manufacturer != NULL)
+               devInf->manufacturer = strdup(manufacturer);
+}
+
+static void __set_devinf_model(DevInf *devInf, char *model)
+{
+       if (!devInf)
+               return;
+
+       if (model != NULL)
+               devInf->model = strdup(model);
+}
+
+static void __set_devinf_oem(DevInf *devInf, char *oem)
+{
+       if (!devInf)
+               return;
+
+       if (oem != NULL)
+               devInf->oem = strdup(oem);
+}
+
+static void __set_devinf_software_version(DevInf *devInf, char *softwareVersion)
+{
+       if (!devInf)
+               return;
+
+       if (softwareVersion != NULL)
+               devInf->softwareVersion = strdup(softwareVersion);
+}
+
+static void __set_devinf_hardware_version(DevInf *devInf, char *hardwareVersion)
+{
+       if (!devInf)
+               return;
+
+       if (hardwareVersion != NULL)
+               devInf->hardwareVersion = strdup(hardwareVersion);
+}
+
+static void __set_devinf_firmware_version(DevInf *devInf, char *firmwareVersion)
+{
+       if (!devInf)
+               return;
+
+       if (firmwareVersion != NULL)
+               devInf->firmwareVersion = strdup(firmwareVersion);
+}
+
+static void __set_devinf_datastore(DevInf *devInf, DevInfDataStore *devInfDataStore)
+{
+       if (!devInf)
+               return;
+
+       devInf->datastores = g_list_append(devInf->datastores, devInfDataStore);
+}
+
+static void __set_devinf_datastore_rxpref(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType)
+{
+       if (!devInfDataStore)
+               return;
+
+       devInfDataStore->rxPref = devInfContentType;
+}
+
+static void __set_devinf_datastore_txpref(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType)
+{
+       if (!devInfDataStore)
+               return;
+
+       devInfDataStore->txPref = devInfContentType;
+}
+
+static void __set_devinf_datastore_ctcap(DevInfDataStore *devInfDataStore, DevInfCTCap *devInfCTCap)
+{
+       if (!devInfDataStore)
+               return;
+
+       devInfDataStore->ctcaps = g_list_append(devInfDataStore->ctcaps, devInfCTCap);
+}
+
+static void __set_devinf_ctcap_property(DevInfCTCap *devInfCTCap, DevInfProperty *devInfProperty)
+{
+       if (!devInfCTCap)
+               return;
+
+       devInfCTCap->properties = g_list_append(devInfCTCap->properties, devInfProperty);
+}
+
+static void __set_devInf_property_valenums(DevInfProperty *devInfProperty, char*valEnum)
+{
+       if (!devInfProperty)
+               return;
+
+       if (valEnum != NULL)
+               devInfProperty->valEnums = g_list_append(devInfProperty->valEnums, strdup(valEnum));
+}
+
+static DevInfDevTyp __convert_devtyp(char *devTyp)
+{
+       DevInfDevTyp devInfDevTyp = DEVINF_DEVTYPE_UNKNOWN;
+
+       if (strcmp(devTyp, DEFINE_DEVICE_TYPE_PAGER) == 0)
+               devInfDevTyp = DEVINF_DEVTYPE_PAGER;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_HANDHELD) == 0)
+               devInfDevTyp = DEVINF_DEVTYPE_HANDHELD;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_PDA) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_PDA;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_PHONE) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_PHONE;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_SMARTPHONE) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_SMARTPHONE;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_SERVER) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_SERVER;
+       else if (strcmp(devTyp, DEFINE_DEVICE_TYPE_WORKSTATION) == 0)
+                       devInfDevTyp = DEVINF_DEVTYPE_WORKSTATION;
+
+       return devInfDevTyp;
+}
+
+SA_ErrorType create_devinf(Session *session, DevInf **pDevInf)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       DCI_RETURN err = DCI_SUCCESS;
+
+       char *devID = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &devID);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *devTyp = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevTyp", &devTyp);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       DevInfDevTyp  devInfDevTyp = DEVINF_DEVTYPE_UNKNOWN;
+       if (devTyp != NULL)
+               devInfDevTyp = __convert_devtyp(devTyp);
+
+       DevInfVersion devInfVersion = DEVINF_VERSION_UNKNOWN;
+       if (session->protocolVersion == VERSION_10)
+               devInfVersion = DEVINF_VERSION_10;
+       else if (session->protocolVersion == VERSION_11)
+               devInfVersion = DEVINF_VERSION_11;
+       else if (session->protocolVersion == VERSION_12)
+               devInfVersion = DEVINF_VERSION_12;
+
+       char *man = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "Man", &man);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *model = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "Mod", &model);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *oem = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "OEM", &oem);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *swv = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "SwV", &swv);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *hwv = NULL;
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "HwV", &hwv);
+       if (err != DCI_SUCCESS) {
+               errorType = SA_INTERNAL_ERROR;
+               goto error;
+       }
+
+       char *fwv = "1.0";
+       /*
+       err = DCI_Get_DevInfo(DEFINE_PLATFORM, "FwV", &fwv);
+       if (err != DCI_SUCCESS) {
+               errorType = ERROR_INTERNAL_ERROR;
+               goto error;
+       }
+       */
+
+       FW_LOGV("devID = %s",  devID);
+       FW_LOGV("devTyp = %s", devTyp);
+       FW_LOGV("man = %s",  man);
+       FW_LOGV("model = %s", model);
+       FW_LOGV("oem = %s", oem);
+       FW_LOGV("swv = %s", swv);
+       FW_LOGV("hwv = %s",  hwv);
+       FW_LOGV("fwv = %s",  fwv);
+
+       DevInf *pTempDevInf = NULL;
+       errorType = __create_devinf_new(devID, devInfDevTyp, &pTempDevInf);
+       if (errorType != SA_INTERNAL_OK) {
+               FW_LOGE("failed to create devInf New");
+               goto error;
+       }
+
+       __set_devinf_version(pTempDevInf, devInfVersion);
+       __set_devinf_manufacturer(pTempDevInf, man);
+       __set_devinf_model(pTempDevInf, model);
+       __set_devinf_oem(pTempDevInf, oem);
+       __set_devinf_software_version(pTempDevInf, swv);
+       __set_devinf_hardware_version(pTempDevInf, hwv);
+       __set_devinf_firmware_version(pTempDevInf, fwv);
+
+       pTempDevInf->supportsLargeObjs = 1;
+       pTempDevInf->supportsUTC = 1;
+       pTempDevInf->supportsNumberOfChanges = 1;
+
+       /*TODO Implements call log datastore's datastore for device info */
+       /* TYPE_CONTENT_COUNT -1 -> not include calllog datastore */
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT - 1; content_type++) {
+
+               if (datastoreinfo_per_content_type[content_type]->source != NULL) {
+                       DevInfDataStore *devInfDataStore = NULL;
+                       errorType = create_devinf_datastore(datastoreinfo_per_content_type[content_type]->source, &devInfDataStore);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfDataStore");
+                               goto error;
+                       }
+
+                       Object_Info *datastore = T_DACI_Get_Obj_Info(content_type);
+
+                       FW_LOGV("datastore->type = %s",  datastore->type);
+                       FW_LOGV("datastore->version = %s",  datastore->version);
+                       FW_LOGV("datastore->field_cnt = %d",  datastore->field_cnt);
+
+                       DevInfContentType *devInfContentTypeRxPref = NULL;
+                       errorType = __create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeRxPref);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfContentType");
+                               goto error;
+                       }
+                       __set_devinf_datastore_rxpref(devInfDataStore, devInfContentTypeRxPref);
+
+                       DevInfContentType *devInfContentTypeTxPref = NULL;
+                       errorType = __create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeTxPref);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfContentType");
+                               goto error;
+                       }
+                       __set_devinf_datastore_txpref(devInfDataStore, devInfContentTypeTxPref);
+
+                       DevInfContentType *devInfContentTypeCTCap = NULL;
+                       errorType = __create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeCTCap);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfContentType");
+                               goto error;
+                       }
+
+                       DevInfCTCap *devInfCTCap = NULL;
+                       errorType = __create_devinf_ctcap(devInfContentTypeCTCap , &devInfCTCap);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed to create devInfCTCap");
+                               goto error;
+                       }
+
+                       DevInfProperty *devInfProperty = NULL;
+                       Field_Info field_list;
+                       int i;
+                       for (i = 0; i < datastore->field_cnt; i++) {
+                               field_list = datastore->field_list[i];
+                               errorType = __create_devinf_property(field_list.field_name, &devInfProperty);
+                               if (errorType != SA_INTERNAL_OK) {
+                                       FW_LOGE("failed to create devInfProperty");
+                                       goto error;
+                               }
+
+                               Field_Info children_field_list;
+                               int j;
+                               for (j = 0; j < field_list.field_child_cnt; j++) {
+                                       children_field_list = field_list.field_child_list[j];
+                                       __set_devInf_property_valenums(devInfProperty, children_field_list.field_name);
+                               }
+                               __set_devinf_ctcap_property(devInfCTCap, devInfProperty);
+                       }
+
+                       __set_devinf_datastore_ctcap(devInfDataStore, devInfCTCap);
+
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_TWO_WAY, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_SLOW_SYNC, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_SERVER, 1);
+                       set_devInf_datastore_synccap(devInfDataStore, DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC, 1);
+
+                       __set_devinf_datastore(pTempDevInf, devInfDataStore);
+
+                       /*free datastore*/
+                       T_DACI_Free_Obj_Info(content_type, datastore);
+               }
+       }
+
+       if (devID)
+               free(devID);
+       if (devTyp)
+               free(devTyp);
+       if (man)
+               free(man);
+       if (model)
+               free(model);
+       if (oem)
+               free(oem);
+       if (swv)
+               free(swv);
+       if (hwv)
+               free(hwv);
+/*     if (fwv)
+               free(fwv);*/
+
+       *pDevInf = pTempDevInf;
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+
+       if (devID)
+               free(devID);
+       if (devTyp)
+               free(devTyp);
+       if (man)
+               free(man);
+       if (model)
+               free(model);
+       if (oem)
+               free(oem);
+       if (swv)
+               free(swv);
+       if (hwv)
+               free(hwv);
+/*     if (fwv)
+               free(fwv);*/
+
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+void free_devinf(DevInf *devInf)
+{
+       FW_LOGV("start");
+       if (!devInf)
+               return;
+
+       if (devInf->manufacturer) {
+               free(devInf->manufacturer);
+               devInf->manufacturer = NULL;
+       }
+
+       if (devInf->model) {
+               free(devInf->model);
+               devInf->model = NULL;
+       }
+
+       if (devInf->oem) {
+               free(devInf->oem);
+               devInf->oem = NULL;
+       }
+
+
+       if (devInf->softwareVersion) {
+               free(devInf->softwareVersion);
+               devInf->softwareVersion = NULL;
+       }
+
+
+       if (devInf->hardwareVersion) {
+               free(devInf->hardwareVersion);
+               devInf->hardwareVersion = NULL;
+       }
+
+
+       if (devInf->firmwareVersion) {
+               free(devInf->firmwareVersion);
+               devInf->firmwareVersion = NULL;
+       }
+
+
+       if (devInf->devid) {
+               free(devInf->devid);
+               devInf->devid = NULL;
+       }
+
+       __free_devinf_datastores(devInf->datastores);
+       devInf->datastores = NULL;
+
+       free(devInf);
+
+       FW_LOGV("end");
+}
+
+void set_devInf_datastore_synccap(DevInfDataStore *devInfDataStore, DevInfSyncCap cap, int supported)
+{
+       if (supported)
+               devInfDataStore->synccap = devInfDataStore->synccap | cap;
+       else
+               devInfDataStore->synccap = devInfDataStore->synccap & ~cap;
+}
+
+int get_devinf_datastore_synccap(const DevInfDataStore *devInfDataStore, DevInfSyncCap cap)
+{
+       return devInfDataStore->synccap & cap ? 1 : 0;
+}
+
+DevInfSyncCap convert_devinf_synccap(unsigned int id)
+{
+       DevInfSyncCap result = DEVINF_SYNCTYPE_UNKNOWN;
+
+       switch (id) {
+               case DEVINF_SYNCTYPE_TWO_WAY:
+                       result = DEVINF_SYNCTYPE_TWO_WAY;
+                       break;
+               case DEVINF_SYNCTYPE_SLOW_SYNC:
+                       result = DEVINF_SYNCTYPE_SLOW_SYNC;
+                       break;
+               case DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT:
+                       result = DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT;
+                       break;
+               case DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT:
+                       result = DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT;
+                       break;
+               case DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER:
+                       result = DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER;
+                       break;
+               case DEVINF_SYNCTYPE_REFRESH_FROM_SERVER:
+                       result = DEVINF_SYNCTYPE_REFRESH_FROM_SERVER;
+                       break;
+               case DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC:
+                       result = DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC;
+                       break;
+               default:
+                       return DEVINF_SYNCTYPE_UNKNOWN;
+                       break;
+       }
+       return result;
+}
+
+
+/*
+static ErrorType create_DevInfPropParam(char *paramName, DevInfPropParam **pDevInfPropParam)
+{
+       FW_LOGV("start");
+
+       ErrorType errorType = ERROR_INTERNAL_OK;
+
+       if (!paramName) {
+               errorType = ERROR_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pDevInfPropParam = (DevInfPropParam *)calloc(1, sizeof(DevInfPropParam));
+       if (*pDevInfPropParam == NULL) {
+               errorType = ERROR_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pDevInfPropParam)->paramName = strdup(paramName);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error : %d", errorType);
+       return errorType;
+}
+
+
+static void set_DevInfDataStoreDisplayname(DevInfDataStore* devInfDataStore, char *displayname) {
+
+       if (!devInfDataStore)
+               return;
+
+       devInfDataStore->displayname = strdup(displayname);
+}
+
+static void set_DevInfDataStoreRx(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType) {
+       if (!devInfDataStore)
+                       return;
+
+       devInfDataStore->rx = g_list_append(devInfDataStore->rx, devInfContentType);
+}
+
+static void set_DevInfDataStoreTx(DevInfDataStore *devInfDataStore, DevInfContentType *devInfContentType) {
+       if (!devInfDataStore)
+                       return;
+
+       devInfDataStore->tx = g_list_append(devInfDataStore->tx, devInfContentType);
+}
+
+
+static void set_DevInfPropertyDataType(DevInfProperty *devInfProperty, char *dataType) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->dataType = strdup(dataType);
+}
+
+static void set_DevInfPropertyMaxOccur(DevInfProperty *devInfProperty, unsigned int maxOccur) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->maxOccur = maxOccur;
+}
+
+static void set_DevInfPropertyMaxSize(DevInfProperty *devInfProperty, unsigned int maxSize) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->maxSize = maxSize;
+}
+
+static void set_DevInfPropertyNoTruncate(DevInfProperty *devInfProperty, int noTruncate) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->noTruncate = noTruncate;
+}
+
+static void set_DevInfPropertyDisplayName(DevInfProperty *devInfProperty, char *displayName) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->displayName = strdup(displayName);
+}
+
+static void set_DevInfPropertyPropParam(DevInfProperty *devInfProperty, DevInfPropParam *devInfPropParam) {
+
+       if (!devInfProperty)
+               return;
+
+       devInfProperty->propParams = g_list_append(devInfProperty->propParams, devInfPropParam);
+}
+
+static void set_DevInfPropParamDataType(DevInfPropParam *devInfPropParam, char *dataType) {
+
+       if (!devInfPropParam)
+               return;
+
+       devInfPropParam->dataType = strdup(dataType);
+}
+
+static void set_DevInfPropParamDisplayName(DevInfPropParam *devInfPropParam, char *displayName) {
+
+       if (!devInfPropParam)
+               return;
+
+       devInfPropParam->displayName = strdup(displayName);
+}
+
+static void set_DevInfPropParamValEnums(DevInfPropParam *devInfPropParam, char *valEnum) {
+
+       if (!devInfPropParam)
+               return;
+
+       devInfPropParam->valEnums = g_list_append(devInfPropParam->valEnums, strdup(valEnum));
+ }
+*/
diff --git a/src/ServiceAdapter/SA_Elements.c b/src/ServiceAdapter/SA_Elements.c
new file mode 100644 (file)
index 0000000..4121313
--- /dev/null
@@ -0,0 +1,819 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Elements.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions for structures which is used in Service Adapter
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+#include "ServiceAdapter/SA_Command.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+SA_ErrorType create_anchor(char *last, char *next, Anchor **pAnchor)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!next) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pAnchor = (Anchor *)calloc(1, sizeof(Anchor));
+       if (*pAnchor == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       if (last)
+               (*pAnchor)->lastAnchor = strdup(last);
+
+       (*pAnchor)->nextAnchor = strdup(next);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_item_anchor(Item *item, Anchor *anchor)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!item) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!anchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (item->anchor) {
+               free_anchor(item->anchor);
+               item->anchor = NULL;
+       }
+
+       Anchor *pAnchor = NULL;
+       errorType = create_anchor(anchor->lastAnchor, anchor->nextAnchor, &pAnchor);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+       item->anchor = pAnchor;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_last_anchor(Anchor *anchor, char *lastAnchor)
+{
+       FW_LOGV("start with lastAnchor = %s\n", lastAnchor);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!anchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (lastAnchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       anchor->lastAnchor = lastAnchor;
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+SA_ErrorType set_next_anchor(Anchor *anchor, char *nextAnchor)
+{
+       FW_LOGV("start with nextAnchor = %s\n", nextAnchor);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!anchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (nextAnchor) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       anchor->nextAnchor = nextAnchor;
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+void free_anchor(Anchor *pAnchor)
+{
+       FW_LOGV("start");
+
+       if (!pAnchor)
+               return;
+
+       if (pAnchor->lastAnchor) {
+               free(pAnchor->lastAnchor);
+               pAnchor->lastAnchor = NULL;
+       }
+
+       if (pAnchor->nextAnchor) {
+               free(pAnchor->nextAnchor);
+               pAnchor->nextAnchor = NULL;
+       }
+
+       free(pAnchor);
+       pAnchor = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+SA_ErrorType create_location(char *locURI, char *locName, Location **pLocation)
+{
+       FW_LOGV("start with locURI = %s, locName = %s\n", locURI, locName);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!locURI) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pLocation = (Location *) calloc(1, sizeof(Location));
+       /*              calloc된 *pLocation에 대한 null check로 변경
+        *              2011.09.28 seokgil kang
+        */
+       if (!(*pLocation)) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pLocation)->locURI = strdup(locURI);
+
+       if (locName)
+               (*pLocation)->locName = strdup(locName);
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+Location *dup_location(Location* pLocation)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!pLocation) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       Location *location = NULL;
+       errorType = create_location(pLocation->locURI, pLocation->locName, &location);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       FW_LOGV("end");
+
+       return location;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+
+}
+
+char  *get_location_locname(Location *location)
+{
+       if (!location)
+               return NULL;
+
+       return location->locName;
+}
+
+char *get_location_locuri(Location *location)
+{
+       if (!location)
+               return NULL;
+
+       return location->locURI;
+}
+
+void free_location(Location *loc)
+{
+       FW_LOGV("start");
+
+       if (!loc)
+               return;
+
+       FW_LOGV("loc->locURI = %s", loc->locURI);
+       if (loc->locURI)
+               free(loc->locURI);
+
+       FW_LOGV("loc->locName = %s", loc->locName);
+       if (loc->locName)
+               free(loc->locName);
+
+       free(loc);
+       loc = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+SA_ErrorType create_cred(char *userName, char *pwd, AuthType authType, FormatType formatType , char *data, Cred **cred)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (userName ==  NULL || !strlen(userName)) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+       if (pwd ==  NULL || !strlen(pwd)) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+       if (data == NULL) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *cred = (Cred *)calloc(1, sizeof(Cred));
+       if (*cred == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*cred)->type = authType;
+       (*cred)->format = formatType;
+       (*cred)->username = strdup(userName);
+       (*cred)->password = strdup(pwd);
+
+       (*cred)->data = strdup(data);
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+
+}
+
+void free_cred(Cred *cred)
+{
+       FW_LOGV("start");
+
+       if (!cred)
+               return;
+
+       if (cred->data) {
+               free(cred->data);
+               cred->data = NULL;
+       }
+
+       if (cred->username) {
+               free(cred->username);
+               cred->username = NULL;
+       }
+
+       if (cred->password) {
+               free(cred->password);
+               cred->password = NULL;
+       }
+
+       free(cred);
+       cred = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+void free_chal(Chal *chal)
+{
+       FW_LOGV("start");
+
+       if (!chal)
+               return;
+
+       if (chal->nonce_plain) {
+               free(chal->nonce_plain);
+               chal->nonce_plain = NULL;
+       }
+
+       if (chal->nonce_b64) {
+               free(chal->nonce_b64);
+               chal->nonce_b64 = NULL;
+       }
+
+       free(chal);
+
+       FW_LOGV("end");
+
+       return;
+}
+
+Cred *create_cred_with_data(AuthType authType, char *data)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Cred *cred = (Cred *)calloc(1, sizeof(Cred));
+       if (!cred) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       cred->type = authType;
+       if (data != NULL)
+               cred->data = strdup(data);
+
+       FW_LOGV("end");
+
+       return cred;
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+
+}
+
+void set_cred_format_type(Cred *cred, FormatType formatType)
+{
+       if (!cred)
+               return;
+
+       cred->format = formatType;
+}
+
+SA_ErrorType create_syncml(SyncHdr *syncHdr, GList *status, GList *commands, int isFinal , SyncML **pSyncML)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!syncHdr) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pSyncML = (SyncML *) calloc(1, sizeof(SyncML));
+
+       if (*pSyncML == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pSyncML)->hdr = syncHdr ;
+       (*pSyncML)->status = status;
+       (*pSyncML)->commands = commands;
+       (*pSyncML)->final = isFinal;
+
+       FW_LOGV("end");
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+
+}
+
+void free_syncml(SyncML *syncML)
+{
+       FW_LOGV("start");
+
+       if (!syncML)
+               return;
+
+       free_synchdr(syncML->hdr);
+       syncML->hdr = NULL;
+
+       free_statuses(syncML->status);
+       syncML->status = NULL;
+
+       free_commands(syncML->commands);
+       syncML->commands = NULL;
+
+       free(syncML);
+
+       FW_LOGV("end");
+
+       return;
+}
+
+SA_ErrorType create_synchdr(Session *session , SyncHdr **pSyncHdr)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!session->protocolVersion) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!session->protocolType) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!session->source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!session->target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       *pSyncHdr = (SyncHdr *)calloc(1, sizeof(SyncHdr));
+
+       if (*pSyncHdr == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pSyncHdr)->version =  session->protocolVersion;
+       (*pSyncHdr)->protocol = session->protocolType;
+       (*pSyncHdr)->target = dup_location(session->target);
+       (*pSyncHdr)->source = dup_location(session->source);
+
+       if (session->cred)
+               (*pSyncHdr)->cred  = dup_cred(session->cred);
+
+       if (session->sessionID)
+               (*pSyncHdr)->sessionID = strdup(session->sessionID);            /*free*/
+
+       (*pSyncHdr)->messageID = ++session->msgID;
+
+       (*pSyncHdr)->maxmsgsize = session->sourceMaxMsgSize;
+       (*pSyncHdr)->maxobjsize = session->sourceMaxObjSize;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+void free_synchdr(SyncHdr *syncHdr)
+{
+       FW_LOGV("start");
+
+       if (!syncHdr)
+               return;
+
+       if (syncHdr->sessionID) {
+               free(syncHdr->sessionID);
+               syncHdr->sessionID = NULL;
+       }
+
+       if (syncHdr->responseURI) {
+               free(syncHdr->responseURI);
+               syncHdr->responseURI = NULL;
+       }
+
+       if (syncHdr->source) {
+               free_location(syncHdr->source);
+               syncHdr->source = NULL;
+       }
+
+       if (syncHdr->target) {
+               free_location(syncHdr->target);
+               syncHdr->target = NULL;
+       }
+
+       if (syncHdr->cred) {
+               free_cred(syncHdr->cred);
+               syncHdr->cred = NULL;
+       }
+
+       free(syncHdr);
+
+       FW_LOGV("end");
+
+       return;
+}
+
+Item *create_item()
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Item *item = (Item *)calloc(1, sizeof(Item));
+       if (!item) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       item->dataType = ITEM_UNKNOWN;
+       FW_LOGV("end");
+
+       return item;
+
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+}
+
+Item *create_item_for_data(const char *data, unsigned int size)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Item *item = create_item();
+       if (!item) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       item->dataType = ITEM_DATA;
+       if (data != NULL)
+               item->private.data = strdup(data);
+
+       item->size = size;
+
+       FW_LOGV("end");
+
+       return item;
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+}
+
+Item *create_item_for_devinf(DevInf *devInf)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!devInf) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       Item *item = create_item();
+       if (!item) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       item->dataType = ITEM_DEVINF;
+       item->private.devInf = devInf;
+
+       FW_LOGV("end");
+
+       return item;
+error:
+       FW_LOGE("error :%d", errorType);
+       return NULL;
+}
+
+void set_item_target(Item *item, Location *target)
+{
+       if (item)
+               item->target = target;
+}
+
+void set_item_source(Item *item, Location *source)
+{
+       if (item)
+               item->source = source;
+}
+
+void free_item(Item *item)
+{
+       FW_LOGV("start");
+
+       if (!item)
+               return;
+
+       if (item->source) {
+               free_location(item->source);
+               item->source = NULL;
+       }
+
+       if (item->target) {
+               free_location(item->target);
+               item->target = NULL;
+       }
+
+       if (item->anchor) {
+               free_anchor(item->anchor);
+               item->anchor = NULL;
+       }
+
+       switch (item->dataType) {
+       case ITEM_DATA:
+               free(item->private.data);
+               break;
+       case ITEM_DEVINF:
+               /*devinf is pointed from session. so doesnot need to free here*/
+               item->private.devInf = NULL;
+               break;
+       case ITEM_UNKNOWN:
+               /*noting to free*/
+               break;
+       }
+
+       if (item->contenttype) {
+               free(item->contenttype);
+               item->contenttype = NULL;
+       }
+
+       free(item);
+       item = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+Chal *dup_chal(Chal *pChal)
+{
+       FW_LOGV("start");
+
+       if (!pChal) {
+               FW_LOGV("pChal is null");
+               return NULL;
+       }
+
+       Chal *temp = (Chal *)calloc(1, sizeof(Chal));
+
+       if (pChal->type)
+               temp->type = pChal->type;
+
+       if (pChal->format)
+               temp->format = pChal->format;
+
+       if (pChal->nonce_b64)
+               temp->nonce_b64 = strdup(pChal->nonce_b64);
+
+       if (pChal->nonce_length)
+               temp->nonce_length = pChal->nonce_length;
+
+       if (pChal->nonce_plain)
+               temp->nonce_plain = strdup(pChal->nonce_plain);
+
+       FW_LOGV("end");
+
+       return temp;
+}
+
+Cred *dup_cred(Cred *pCred)
+{
+       FW_LOGV("start");
+
+       if (!pCred) {
+               FW_LOGV("pCred is null");
+               return NULL;
+       }
+
+       Cred *temp = (Cred *)calloc(1, sizeof(Cred));
+
+       if (pCred->type)
+               temp->type = pCred->type;
+
+       if (pCred->format)
+               temp->format = pCred->format;
+
+       if (pCred->username)
+               temp->username = strdup(pCred->username);
+
+       if (pCred->password)
+               temp->password = strdup(pCred->password);
+
+       if (pCred->data)
+               temp->data = strdup(pCred->data);
+
+       FW_LOGV("end");
+
+       return temp;
+}
+
+SA_ErrorType compare_cred(Cred *hdrCred, Cred *sessionCred)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!hdrCred) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!sessionCred) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (strcmp(hdrCred->data, sessionCred->data) == 0)
+               errorType = SA_INTERNAL_OK;
+       else
+               errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+
+       return errorType;
+error:
+       FW_LOGE("error :%d", errorType);
+       return errorType;
+}
+
+AuthType convert_auth_type(char *authType)
+{
+       if (!authType)
+               return AUTH_TYPE_UNKNOWN;
+
+       if (!strcmp(authType, ELEMENT_AUTH_BASIC)) {
+               return AUTH_TYPE_BASIC;
+       } else if (!strcmp(authType, ELEMENT_AUTH_MD5)) {
+               return AUTH_TYPE_MD5;
+       }
+
+       return AUTH_TYPE_UNKNOWN;
+}
+
+FormatType convert_format_type(char *formatType)
+{
+       if (!formatType)
+               return FORMAT_TYPE_UNKNOWN;
+
+       if (!strcmp(formatType, ELEMENT_FORMAT_BASE64)) {
+               return FORMAT_TYPE_BASE64;
+       }
+
+       return FORMAT_TYPE_UNKNOWN;
+}
diff --git a/src/ServiceAdapter/SA_Session.c b/src/ServiceAdapter/SA_Session.c
new file mode 100644 (file)
index 0000000..f40da33
--- /dev/null
@@ -0,0 +1,1442 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Session.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions for Session structure which is used in Service Adapter and processing receive command & status
+ */
+
+/*FIXME temporary*/
+#include "agent-framework/SyncAgent_Info.h"
+
+#include "agent-framework/DACI/DACI_Luid.h"
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Util.h"
+#include "ServiceAdapter/SA_Session.h"
+#include "ServiceAdapter/SA_Session_Internal.h"
+#include "ServiceAdapter/SA_Elements.h"
+#include "ServiceAdapter/SA_Elements_Internal.h"
+#include "ServiceAdapter/SA_Command.h"
+#include "ServiceAdapter/SA_Command_Internal.h"
+#include "ServiceAdapter/SA_DevInf.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+static SA_ErrorType __receive_alert_status(Session *session, Status *status);
+static SA_ErrorType __receive_put_status(Session *session, Status *status);
+static SA_ErrorType __receive_get_status(Session *session, Status *status);
+static SA_ErrorType __receive_results_status(Session *session, Status *status);
+static SA_ErrorType __receive_sync_status(Session *session, Status *status);
+static SA_ErrorType __receive_changes_status(Session *session, Status *status, GList **returnStatus);
+static SA_ErrorType __receive_map_status(Session *session, Status *status);
+
+static SA_ErrorType __receive_alert_command(Session *session, Command *command, GList **returnDatastore);
+static SA_ErrorType __receive_put_command(Session *session, Command *command);
+static SA_ErrorType __receive_get_command(Session *session, Command *command);
+static SA_ErrorType __receive_results_command(Session *session, Command *command);
+static SA_ErrorType __receive_sync_command(Session *session, Command *command, ChangedDatastore **changedDatastore);
+static SA_ErrorType __receive_changes_command(Session *session, Command *command,
+                                                               char **luid_str_list, int *index, ChangedDatastore **changedDatastore);
+
+static void __free_pending_status(PendingStatus *pendingStatus);
+static SA_ErrorType __add_mapping(Session *session, char *guid, char *luid, int datastore_id);
+
+
+static SA_ErrorType __receive_alert_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400 && code != ERROR_REQUIRE_REFRESH) {
+               /*401   unauthorized
+               407     Authentication required
+               405     command not allowed
+               406     optional feature not supported
+               500     command failed
+               412     Incomplete command
+               415 unsupported media type or format
+               404 not found ->it have to be considered
+               TODO error handling it's error~!!!!!*/
+
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_COMMAND_NOT_ALLOWED || code == ERROR_UNSUPPORTED_FEATURE || code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else if (code == ERROR_NOT_FOUND) {
+                       /*do not need to return errorType when code is ERROR_NOT_FOUND*/
+
+               }
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_put_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400) {
+               /*TODO error handling it's error~!!!!!
+               401 unauthorized
+               407 authentication required
+               411 size required
+               413 request entity too large
+               416 requested size too big
+               415 unspported media type or format
+               420 device full
+               500 command failed*/
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else
+                       errorType = SA_INTERNAL_ERROR;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_get_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400) {
+               /*TODO error handling it's error~!!!!!
+               401 unauthorized
+               407 authentication required
+               404 not found
+               413 request entity too large
+               415 unspported media type or format
+               500 command failed*/
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_NOT_FOUND)
+                       errorType = SA_INTERNAL_NOT_FOUND;
+               else if (code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else
+                       errorType = SA_INTERNAL_ERROR;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_results_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400) {
+               /*TODO error handling it's error~!!!!!
+               401 unauthorized
+               407 authentication required
+               404 not found
+               413 request entity too large
+               415 unspported media type or format
+               500 command failed*/
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_NOT_FOUND)
+                       errorType = SA_INTERNAL_NOT_FOUND;
+               else if (code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else
+                       errorType = SA_INTERNAL_ERROR;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_sync_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       if (code >= 400 && code != ERROR_REQUIRE_REFRESH) {
+               /*TODO error handling it's error~!!!!!
+               401 unauthorized
+               407 authentication required
+               403 forbidden
+               404 not found
+               405 command not allowed
+               508 refresh required
+               500 command failed*/
+               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+               else if (code == ERROR_NOT_FOUND)
+                       errorType = SA_INTERNAL_NOT_FOUND;
+               else if (code == ERROR_GENERIC)
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+               else
+                       errorType = SA_INTERNAL_ERROR;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_changes_status(Session *session, Status *status, GList **returnStatus)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("cmdID = %d", status->cmdID);
+       FW_LOGV("msgRef = %d", status->msgRef);
+       FW_LOGV("cmdRef = %d", status->cmdRef);
+       FW_LOGV("type = %d", status->type);
+       FW_LOGV("data = %s", status->data);
+
+       unsigned int code = get_status_code(status);
+       FW_LOGV("code = %d", code);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (session->largeObj) {
+               /*LargeObj status it does not need to pass engine*/
+               PendingStatus *largeObj = session->largeObj;
+               if (largeObj->cmdID == status->cmdRef && largeObj->msgID == status->msgRef) {
+
+                       if (code == CHUNK_ACCEPTED) {
+                               __free_pending_status(largeObj);
+                               session->largeObj = NULL;
+                               return errorType;
+                       } else if (code == ERROR_REQUESTED_SIZE_TOO_BIG) {
+                               /*TODO error handling for large obj
+                               can not send this item*/
+                       } else if (code == ERROR_SIZE_REQUIRED) {
+
+                       }
+               }
+       }
+
+       /*pass to engine*/
+       if (status->sourceRef) {
+               AppliedStatus *appliedStatus = create_appliedstatus(get_location_locuri(status->sourceRef),
+                                                                                                                       convert_change_type_command_type(status->type) , code);
+               if (appliedStatus == NULL) {
+                       FW_LOGE("failed in create_appliedstatus");
+                       return SA_INTERNAL_NO_MEMORY;
+               }
+               *returnStatus = g_list_append(*returnStatus, appliedStatus);
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_map_status(Session *session, Status *status)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       DACI_RETURN da_err ;
+
+       GList *iter = NULL;
+       Command *pCommand = NULL;
+       unsigned int code = 0;
+       for (iter = session->mapCommand;  iter != NULL; iter = g_list_next(iter)) {
+               pCommand = iter->data;
+
+               if (pCommand->msgID == status->msgRef && pCommand->cmdID == status->cmdRef) {
+                       code = get_status_code(status);
+                       FW_LOGV("code = %d", code);
+
+                       if (code == 200) {
+                               GList *itemIter = NULL;
+                               Item *item = NULL;
+                               for (itemIter = pCommand->private.map.items; itemIter != NULL; itemIter = g_list_next(itemIter)) {
+                                       item = itemIter->data;
+                                       FW_LOGV(" LUID  = %s has been removed\n", get_location_locuri(item->source));
+                                       da_err = DACI_Delete_Mapping_By_Luid(session->accountId,  get_location_locuri(item->source));
+                                       if (da_err != DACI_SUCCESS) {
+                                               errorType = SA_INTERNAL_DA_ERROR;
+                                               FW_LOGE("failed in DACI_Delete_Mapping_By_Luid");
+                                               return errorType;
+                                       }
+                               }
+                               session->mapCommand  = g_list_remove(session->mapCommand , pCommand);
+                               free_command(pCommand);
+                               break;
+                       } else if (code >= 400) {
+                               /*401 unauthorized
+                               407 authentication required
+                               420 device full
+                               510 data store failure
+                               500 command failed*/
+
+                               if (code >= 500) {
+                                       /*map command has failed so delete failed map command from session->mapCpmmand*/
+                                       GList *itemIter = NULL;
+                                       Item *item = NULL;
+                                       for (itemIter = pCommand->private.map.items; itemIter != NULL; itemIter = g_list_next(itemIter)) {
+                                               item = itemIter->data;
+                                               FW_LOGV("LUID  = %s has been removed\n", get_location_locuri(item->source));
+                                               da_err = DACI_Delete_Mapping_By_Luid(session->accountId,  get_location_locuri(item->source));
+                                               if (da_err != DACI_SUCCESS) {
+                                                       errorType = SA_INTERNAL_DA_ERROR;
+                                                       FW_LOGE("failed in DACI_Delete_Mapping_By_Luid");
+                                                       return errorType;
+                                               }
+                                       }
+                                       session->mapCommand  = g_list_remove(session->mapCommand , pCommand);
+                                       free_command(pCommand);
+                                       break;
+                               }
+                               if (code == ERROR_AUTH_REJECTED || code == ERROR_AUTH_REQUIRED)
+                                       errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+                               else if (code == ERROR_NOT_FOUND)
+                                       errorType = SA_INTERNAL_NOT_FOUND;
+                               else if (code == ERROR_GENERIC)
+                                       errorType = SA_INTERNAL_SERVER_ERROR;
+                               else
+                                       errorType = SA_INTERNAL_ERROR;
+                       }
+               }
+       }
+
+       FW_LOGV("end");
+       return errorType;
+}
+
+static SA_ErrorType __receive_alert_command(Session *session, Command *command, GList **returnDatastore)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!command->source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!command->target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+       /*401   unauthorized
+       407     Authentication required
+       405     command not allowed
+       406     optional feature not supported
+       500     command failed
+       412     Incomplete command
+       415 unsupported media type or format*/
+
+       Status *temp = NULL;
+       if (strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CONTACT]->source)  == 0 ||
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CALENDAR]->source)  == 0 ||
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_MEMO]->source)  == 0 ||
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CALLLOG]->source)  == 0) {
+
+               DatastoreInfo *datastore = create_datastoreinfo(get_location_locuri(command->target), get_location_locuri(command->source));
+               if (datastore == NULL) {
+                       errorType = SA_INTERNAL_NO_MEMORY;
+                       goto error;
+               }
+               set_datastoreInfo_synctype(datastore, command->private.alert.type);
+               set_datastoreinfo_lastanchor(datastore, command->private.alert.anchor->lastAnchor);
+               set_datastoreinfo_nextanchor(datastore, command->private.alert.anchor->nextAnchor);
+               set_datastoreinfo_maxobjsize(datastore, command->private.alert.maxObjSize);
+
+               *returnDatastore = g_list_append(*returnDatastore, datastore);
+
+               errorType = create_new_status(session, NO_ERROR, command,  COMMAND_TYPE_ALERT , &temp);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               temp->item = create_item();
+               if (!(temp->item)) {
+                       errorType = SA_INTERNAL_NO_MEMORY;
+                       goto error;
+               }
+               set_item_anchor(temp->item,  command->private.alert.anchor);
+               session->status = g_list_append(session->status, temp);
+
+       } else if (strcmp(get_location_locuri(command->target), get_location_locuri(session->source)) == 0 &&
+                       strcmp(get_location_locuri(command->source), get_location_locuri(session->target)) == 0) {
+
+               errorType = create_new_status(session, NO_ERROR, command,  COMMAND_TYPE_ALERT , &temp);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               session->status = g_list_append(session->status, temp);
+       } else
+               goto not_found_error;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_ALERT , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __receive_put_command(Session *session, Command *command)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       /*401 unauthorized
+       407 authentication required
+       411 size required
+       413 request entity too large
+       416 requested size too big
+       415 unspported media type or format
+       420 device full
+       500 command failed*/
+
+       Status *temp = NULL;
+
+       if (strcmp(command->private.access.type , ELEMENT_DEVINF_XML) == 0 ||
+                       strcmp(command->private.access.type , ELEMENT_DEVINF_WBXML) == 0) {
+               /*if it is devinf*/
+               if (command->private.access.item) {
+                       session->remoteDevInf = command->private.access.item->private.devInf;
+               }
+               errorType = create_new_status(session, NO_ERROR,  command,  COMMAND_TYPE_PUT, &temp);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+       } else
+               goto not_found_error;
+
+
+
+       session->status = g_list_append(session->status, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_PUT , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __receive_get_command(Session *session, Command *command)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Status *temp = NULL;
+       Command *pCommand = NULL;
+       Location *pLocation = NULL;
+
+       if (strcmp(command->private.access.type , ELEMENT_DEVINF_XML) == 0 ||
+                       strcmp(command->private.access.type , ELEMENT_DEVINF_WBXML) == 0) {
+
+               errorType = create_new_status(session, NO_ERROR,  command,  COMMAND_TYPE_GET, &temp);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               session->status = g_list_append(session->status, temp);
+
+               char *sourceDevInf = NULL;
+               if (session->protocolVersion == VERSION_10)
+                       sourceDevInf = ELEMENT_DEVINF_10;
+               else if (session->protocolVersion == VERSION_11)
+                       sourceDevInf = ELEMENT_DEVINF_11;
+               else if (session->protocolVersion == VERSION_12)
+                       sourceDevInf = ELEMENT_DEVINF_12;
+
+               errorType = create_location(sourceDevInf, NULL, &pLocation);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               errorType = create_results_command(session, pLocation, ELEMENT_DEVINF_XML, session->devInf, &pCommand);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+
+               set_results_command_msgref(pCommand, command->msgID);
+               set_results_command_cmdref(pCommand, command->cmdID);
+               set_results_command_targetref(pCommand, command->private.access.item->target);
+
+               session->resultsCommand = g_list_append(session->resultsCommand, pCommand);
+       } else
+               goto not_found_error;
+
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_GET , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __receive_results_command(Session *session, Command *command)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       Status *temp = NULL;
+
+       if (strcmp(command->private.results.type , ELEMENT_DEVINF_XML) == 0 ||
+                       strcmp(command->private.results.type , ELEMENT_DEVINF_WBXML) == 0) {
+               /*if it is devinf*/
+               if (command->private.results.item) {
+                       session->remoteDevInf = command->private.results.item->private.devInf;
+
+                       errorType = create_new_status(session, NO_ERROR,  command,  COMMAND_TYPE_RESULTS, &temp);
+                       if (errorType != SA_INTERNAL_OK)
+                               goto error;
+
+                       session->status = g_list_append(session->status, temp);
+               }
+       } else
+               goto not_found_error;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_RESULTS , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType  __receive_sync_command(Session *session, Command *command, ChangedDatastore **changedDatastore)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!command->source) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               return errorType;
+       }
+
+       if (!command->target) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               return errorType;
+       }
+
+       /*TODO
+       need to check that if target has not exist in client
+       it's a error(return status)
+       and return Datastore index
+
+       401 unauthorized
+       407 authentication required
+       403 forbidden
+       404 not founc
+       405 command not allowed
+       508 refresh required
+       500 command failed
+
+       TODO compare with alert command(?)*/
+
+       if (strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CONTACT]->source)  != 0 &&
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CALENDAR]->source)  != 0 &&
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_MEMO]->source)  != 0 &&
+                       strcmp(get_location_locuri(command->target), datastoreinfo_per_content_type[TYPE_CALLLOG]->source)  != 0)
+               goto not_found_error;
+
+       Status *temp = NULL;
+       errorType = create_new_status(session, NO_ERROR, command,  COMMAND_TYPE_SYNC_START , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+
+       /*for return to engine*/
+       ChangedDatastore *pChangedDatastore = create_changeddatastore(get_location_locuri(command->source),
+                                                                                                                                       get_location_locuri(command->target), command->private.sync.hasNumChanged,
+                                                                                                                                       command->private.sync.hasNumChanged ? command->private.sync.numChanged : 0);
+       if (pChangedDatastore == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       } else
+               *changedDatastore = pChangedDatastore;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+not_found_error:
+       errorType = create_new_status(session, ERROR_NOT_FOUND, command,  COMMAND_TYPE_SYNC_START , &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+       return SA_INTERNAL_NOT_FOUND;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static SA_ErrorType __receive_changes_command(Session *session, Command *command, char **luid_str_list,
+                                                                                                                                                       int *index, ChangedDatastore **changedDatastore)
+{
+       FW_LOGV("start command type :  %d\n",  command->private.change.type);
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       GList *iter = NULL;
+       ChangedItem *changed = NULL;
+       char *luid;
+       ChangeType changeType = command->private.change.type;
+       for (iter = command->private.change.items; iter != NULL; iter = g_list_next(iter)) {
+               Item *changedItem = (iter->data);
+
+               if (changedItem->moreData) {
+                       if (session->pLargeObjCmd) {
+                               /*if there is a chunked item before...
+                               it's not firest chunked item.... data have to be merged(check source location)
+                               there will be another chunked item*/
+
+                               Command *pLargeObjcmd = session->pLargeObjCmd;
+                               if (pLargeObjcmd->private.change.items) {
+                                       /*moreData item must be last item in item list*/
+                                       GList *largeObjItems = session->pLargeObjCmd->private.change.items;
+                                       GList *largeObjLastItem = g_list_nth(largeObjItems, g_list_length(largeObjItems) - 1);
+                                       Item *item = largeObjLastItem->data;
+                                       AlertType alertType = ALERT_UNKNOWN;
+                                       if (strcmp(get_location_locuri(item->source), get_location_locuri(changedItem->source)) == 0) {
+                                               /*two item's source are equal
+                                               append incomming string*/
+                                               if (item->private.data) {
+                                                       char *tmp = g_strdup_printf("%s%s", item->private.data, changedItem->private.data);
+                                                       free(item->private.data);
+                                                       item->private.data = tmp;
+                                               } else {
+                                                       item->private.data = strdup(changedItem->private.data);
+                                               }
+                                               Status *temp = NULL;
+                                               errorType = create_new_status_location(session, CHUNK_ACCEPTED, command, changedItem->source,
+                                                                                                                               changedItem->target, convert_command_type_change_type(changeType), &temp);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed in create_new_status_location");
+                                                       goto error;
+                                               }
+                                               session->status = g_list_append(session->status, temp);
+                                               alertType = ALERT_NEXT_MESSAGE;
+                                       } else{
+                                               /* it's a new data object or command but this command also have a moreData*/
+                                               alertType = ALERT_NO_END_OF_DATA;
+                                       }
+                                       /* create alert command*/
+                                       Command *pAlertCommand = NULL;
+                                       errorType = create_alert_command(session, alertType, dup_location(session->source), dup_location(session->target),
+                                                                                                                                               NULL, NULL, NULL,  &pAlertCommand);
+                                       if (errorType != SA_INTERNAL_OK) {
+                                               FW_LOGE("failed in create_alert_command");
+                                               goto error;
+                                       }
+                                       session->alertCommand = g_list_append(session->alertCommand, pAlertCommand);
+                               }
+                       } else{
+                               /*first chunked item
+                               just buffered it. does not generate LUID, and does not pass to engine*/
+                               OMA_StatusType statusErrorType = ERROR_UNKNOWN;
+                               if (changedItem->size == 0) {
+                                       /*size required*/
+                                       statusErrorType = ERROR_SIZE_REQUIRED;
+                               } else{
+                                       /* size is specified*/
+                                       if (changedItem->size > session->sourceMaxObjSize) {
+                                               /*but it is bigger than client maxObjSize*/
+                                               statusErrorType = ERROR_REQUESTED_SIZE_TOO_BIG;
+                                       } else{
+                                               /*chunked item accepted*/
+                                               session->pLargeObjCmd = command;
+                                               increase_command_refcount(command);
+
+                                               statusErrorType = CHUNK_ACCEPTED;
+
+                                               /* create alert command*/
+                                               Command *pAlertCommand = NULL;
+                                               errorType = create_alert_command(session, ALERT_NEXT_MESSAGE,
+                                                                                                                                                       dup_location(session->source), dup_location(session->target),
+                                                                                                                                                       NULL, NULL,  NULL,  &pAlertCommand);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed in create_alert_command");
+                                                       goto error;
+                                               }
+                                               session->alertCommand = g_list_append(session->alertCommand, pAlertCommand);
+                                       }
+
+                                       Status *temp = NULL;
+                                       errorType = create_new_status_location(session, statusErrorType, command, changedItem->source, changedItem->target,
+                                                                                                                                                               convert_command_type_change_type(changeType) , &temp);
+                                       if (errorType != SA_INTERNAL_OK) {
+                                               FW_LOGE("failed in create_new_status_location");
+                                               goto error;
+                                       }
+                                       session->status = g_list_append(session->status, temp);
+                               }
+                       }
+               } else{
+                       if (session->pLargeObjCmd) {
+
+                               /*if there is a chunked item before...
+                                it's not firest chunked item.... data have to be merged(check source location)
+                                there will be no more chunked item. this command have to be pass to engine*/
+
+                               Command *pLargeObjcmd = session->pLargeObjCmd;
+                               if (pLargeObjcmd->private.change.items) {
+                                       /*moreData item must be last item in item list*/
+                                       GList *largeObjItems = session->pLargeObjCmd->private.change.items;
+                                       GList *largeObjLastItem = g_list_nth(largeObjItems, g_list_length(largeObjItems) - 1);
+                                       Item *item = largeObjLastItem->data;
+
+                                       if (strcmp(get_location_locuri(item->source), get_location_locuri(changedItem->source)) == 0) {
+                                               /* two item's source are equal
+                                               append incomming string*/
+                                               if (item->private.data) {
+                                                       char *tmp = g_strdup_printf("%s%s", item->private.data, changedItem->private.data);
+                                                       free(item->private.data);
+                                                       item->private.data = tmp;
+                                               } else {
+                                                       item->private.data = strdup(changedItem->private.data);
+
+                                                       if (item->private.data == NULL) {
+                                                               FW_LOGE("item->private.data is null !!");
+                                                               goto error;
+                                                       }
+                                               }
+
+                                               if (item->size == strlen(item->private.data)) {
+                                                       /*delete pointing from pLargeObjCmd*/
+                                                       largeObjLastItem->data = NULL;
+                                                       FW_LOGV("delete pointing from pLargeObjCmd");
+                                                       /*free Item from incomming Cmd*/
+                                                       free_item(changedItem);
+                                                       FW_LOGV("free Item from incomming Cmd");
+                                                       /*pointing to Merged item in incomming Cmd*/
+                                                       iter->data = item;
+                                                       changedItem = item;
+                                                       FW_LOGV("pointing to Merged item in incomming Cmd");
+
+                                                       free_command(session->pLargeObjCmd);
+                                                       session->pLargeObjCmd = NULL;
+                                               } else{
+                                                       Status *temp = NULL;
+                                                       errorType = create_new_status_location(session, ERROR_SIZE_MISMATCH, command,
+                                                                                                                                                               changedItem->source, changedItem->target,
+                                                                                                                                                               convert_command_type_change_type(changeType), &temp);
+                                                       if (errorType != SA_INTERNAL_OK) {
+                                                               FW_LOGE("failed in create_new_status_location");
+                                                               goto error;
+                                                       }
+                                                       session->status = g_list_append(session->status, temp);
+                                               }
+                                       } else{
+                                               /* it's a new data object or command send 223
+                                                create alert command*/
+                                               Command *pAlertCommand = NULL;
+                                               errorType = create_alert_command(session, ALERT_NO_END_OF_DATA,
+                                                                                                                                       dup_location(session->source), dup_location(session->target),
+                                                                                                                                       NULL, NULL,  NULL, &pAlertCommand);
+                                               if (errorType != SA_INTERNAL_OK) {
+                                                       FW_LOGE("failed in create_alert_command");
+                                                       goto error;
+                                               }
+                                               session->alertCommand = g_list_append(session->alertCommand, pAlertCommand);
+                                       }
+                               }
+                       }
+                       if (changeType == CHANGE_ADD) {
+                               int datastore_id = 0;
+                               if (strcmp(changedItem->contenttype, ELEMENT_TEXT_VCARD) == 0 ||
+                                               strcmp(changedItem->contenttype, ELEMENT_TEXT_VCARD_30) == 0)
+                                       datastore_id = TYPE_CONTACT;
+                               else if (strcmp(changedItem->contenttype, ELEMENT_TEXT_VCAL) == 0)
+                                       datastore_id = TYPE_CALENDAR;
+                               else if (strcmp(changedItem->contenttype, ELEMENT_TEXT_PLAIN) == 0)
+                                       datastore_id = TYPE_MEMO;
+
+                               luid = luid_str_list[(*index)++];
+                               if (luid == NULL) {
+                                       FW_LOGE("luid is null");
+                                       errorType = SA_INTERNAL_ERROR;
+                                       goto error;
+                               }
+
+                               FW_LOGV("index = %d", *index);
+                               FW_LOGV("luid = %s", luid);
+
+                               errorType = __add_mapping(session, get_location_locuri(changedItem->source), luid, datastore_id);
+                               if (errorType != SA_INTERNAL_OK) {
+                                       FW_LOGE("failed in __add_mapping");
+                                       goto error;
+                               }
+                       } else{
+                               luid = get_location_locuri(changedItem->target);
+                               if (luid == NULL) {
+                                       FW_LOGE("luid is null");
+                                       errorType = SA_INTERNAL_ERROR;
+                                       goto error;
+                               }
+                       }
+
+                       changed = create_changeditem(changeType, luid);
+                       if (changed == NULL) {
+                               FW_LOGE("changed is null");
+                               errorType = SA_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       if (changeType != CHANGE_DELETE) {
+                               set_changeditem_contenttype(changed, changedItem->contenttype);
+                               set_changeditem_data(changed, changedItem->private.data);
+                       }
+
+                       Status *temp = NULL;
+                       errorType = create_new_status_location(session, ERROR_UNKNOWN, command,
+                                                                                                                                       changedItem->source, changedItem->target,
+                                                                                                                                       convert_command_type_change_type(changeType), &temp);
+                       if (errorType != SA_INTERNAL_OK) {
+                               FW_LOGE("failed in create_new_status_location");
+                               goto error;
+                       }
+                       session->tempStatus = g_list_append(session->tempStatus, temp);
+
+                       (*changedDatastore)->changeItem = g_list_append((*changedDatastore)->changeItem, changed);
+               }
+       }
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+static void __free_pending_status(PendingStatus *pendingStatus)
+{
+       FW_LOGV("start");
+
+       if (!pendingStatus)
+               return;
+
+       free(pendingStatus);
+       pendingStatus = NULL;
+
+       FW_LOGV("end");
+
+       return;
+}
+
+static SA_ErrorType __add_mapping(Session *session, char *guid, char *luid, int datastore_id)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       daci_mapping mapping;
+       mapping.account_id = session->accountId;
+       mapping.data_store_id = datastore_id;
+       mapping.luid =  luid;
+       mapping.guid = guid;
+       mapping.access_name = "SA";
+
+       DACI_RETURN da_err  = DACI_Add_Mapping(&mapping);
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Add_Mapping = %d", da_err);
+               errorType = SA_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return errorType;
+
+error:
+
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType create_session(ProtocolVersion protocolVersion, ProtocolType protocolType, int accountId,
+                                                                                       char *sessID,  char *source, char *target, Session** pSession)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Location *pSourceLocation  = NULL;
+       Location *pTargetLocation = NULL;
+
+       *pSession = (Session *) calloc(1, sizeof(Session));
+
+       if ((*pSession) == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       errorType = create_location(source, NULL, &pSourceLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       errorType = create_location(target, NULL, &pTargetLocation);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       (*pSession)->protocolType = protocolType;
+       (*pSession)->protocolVersion  = protocolVersion;
+       (*pSession)->accountId = accountId;
+       (*pSession)->sessionID = strdup(sessID);
+       (*pSession)->msgID = 0;
+       (*pSession)->source = pSourceLocation;
+       (*pSession)->target = pTargetLocation;
+       (*pSession)->cmdID = 1;
+
+       (*pSession)->sourceMaxMsgSize = OMA_DS_HTTP_DEFAULT_CLIENT_MAX_MSG_SIZE;
+       (*pSession)->sourceMaxObjSize = OMA_DS_HTTP_DEFAULT_CLIENT_MAX_OBJ_SIZE;
+
+       (*pSession)->targetMaxMsgSize = 0;
+       (*pSession)->targetMaxObjSize = 0;
+
+       (*pSession)->NACI_sessionID = 0;
+       (*pSession)->hasOpend = 0;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+void free_session(Session *session)
+{
+       FW_LOGV("start");
+
+       if (!session)
+               return;
+
+       if (session->sessionID) {
+               free(session->sessionID);
+               session->sessionID = NULL;
+       }
+
+       free_statuses(session->status);
+       session->status = NULL;
+
+       free_statuses(session->tempStatus);
+       session->status = NULL;
+
+       if (session->target) {
+               free_location(session->target);
+               session->target = NULL;
+       }
+
+       if (session->source) {
+               free_location(session->source);
+               session->source = NULL;
+       }
+
+       if (session->orgTarget) {
+               free_location(session->orgTarget);
+               session->orgTarget = NULL;
+       }
+
+       if (session->cred) {
+               free_cred(session->cred);
+               session->cred = NULL;
+       }
+
+       if (session->chal) {
+               free_chal(session->chal);
+               session->chal = NULL;
+       }
+
+       if (session->devInf) {
+               free_devinf(session->devInf);
+               session->devInf = NULL;
+       }
+
+       if (session->remoteDevInf) {
+               free_devinf(session->remoteDevInf);
+               session->remoteDevInf = NULL;
+       }
+
+       if (session->pLargeObjCmd) {
+               free_command(session->pLargeObjCmd);
+               session->pLargeObjCmd = NULL;
+       }
+
+       free_commands(session->resultsCommand);
+       session->resultsCommand = NULL;
+
+       free_commands(session->mapCommand);
+       session->mapCommand = NULL;
+
+       if (session)
+               free(session);
+
+       FW_LOGV("end");
+
+       return;
+
+}
+
+SA_ErrorType create_pending_status(unsigned int msgID, unsigned int cmdID, PendingStatus **pPendingStatus)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       *pPendingStatus = (PendingStatus *)calloc(1, sizeof(PendingStatus));
+
+       if (*pPendingStatus == NULL) {
+               errorType = SA_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       (*pPendingStatus)->msgID = msgID;
+       (*pPendingStatus)->cmdID = cmdID;
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+void set_session_cred(Session *session, Cred *cred)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!session) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!cred) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       session->cred = cred;
+
+       FW_LOGV("end");
+       return;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return;
+
+}
+
+void set_session_devinf(Session *session, DevInf *devInf)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       if (!session) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!devInf) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       session->devInf = devInf;
+
+       FW_LOGV("end");
+       return ;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return ;
+
+}
+
+SA_ErrorType receive_header(Session *session, SyncHdr *header)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       Location *pLocation = NULL;
+
+       if (!session) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (!header) {
+               errorType = SA_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+       if (session->sessionID && header->sessionID) {
+               if (strcmp(session->sessionID, header->sessionID) != 0) {
+                       errorType = SA_INTERNAL_SERVER_ERROR;
+                       goto error;
+               }
+       }
+
+       session->lastRecievedMsgID = header->messageID;
+
+       if (0 < header->maxmsgsize)
+               session->targetMaxMsgSize = header->maxmsgsize;
+       else
+               session->targetMaxMsgSize = OMA_DS_HTTP_DEFAULT_SERVER_MAX_MSG_SIZE;
+
+       if (0 < header->maxobjsize)
+               session->targetMaxObjSize = header->maxobjsize;
+
+       if (header->responseURI) {
+               if (!session->orgTarget) {
+                       session->orgTarget = session->target;
+                       session->target = NULL;
+               }
+
+               if (session->target)
+                       free_location(session->target);
+
+               errorType = create_location(header->responseURI, get_location_locname(session->orgTarget), &pLocation);
+               if (errorType != SA_INTERNAL_OK)
+                       goto error;
+               session->target = pLocation;
+
+               if (!session->target) {
+                       errorType = SA_INTERNAL_NO_MEMORY;
+                       goto error;
+               }
+       }
+
+       Status *temp = NULL;
+       OMA_StatusType statusData = ERROR_UNKNOWN;
+       if (header->cred) {
+               errorType = compare_cred(header->cred, session->cred);
+               if (errorType == SA_INTERNAL_OK)
+                       statusData = AUTH_ACCEPTED;
+               else if (errorType == SA_INTERNAL_AUTHENTICATION_ERROR) {
+                       statusData = ERROR_AUTH_REJECTED;
+               } else
+                       goto error;
+       } else{
+               statusData = NO_ERROR;
+       }
+
+       errorType = create_status(statusData, session->cmdID++, session->lastRecievedMsgID, 0,
+                                                                               header->source, header->target,  COMMAND_TYPE_HEADER, &temp);
+       if (errorType != SA_INTERNAL_OK)
+               goto error;
+
+       session->status = g_list_append(session->status, temp);
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType receive_statuses(Session *session, GList *receiveStatus, GList **returnStatus)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+
+       GList *statusItem = receiveStatus;
+       Status *status = NULL;
+       while (statusItem) {
+               status = statusItem->data;
+
+               if (status->cmdRef == 0) {
+                       /*status of SyncHdr*/
+                       assert(status->type == COMMAND_TYPE_HEADER);
+                       assert(status->data);
+                       OMA_StatusType statusType = atoi(status->data);
+
+                       if (statusType == AUTH_ACCEPTED) {
+                               /*212
+                               when auth type is AUTH_TYPE_BASIC does not need to send cred in syncHdr in same session
+                               when auth type is AUTH_TYPE_MD5 the next nonce in Chal MUST used for the digest when the next sync session is started.*/
+                               if (session->cred->type == AUTH_TYPE_MD5) {
+                                       Chal *chal = status->chal;
+                                       if (chal) {
+                                               /*chal in status have to be stored in config_tbl because it have to be used next sync session*/
+                                               FW_LOGV("format type :%d", chal->format);
+
+                                               char *value;
+                                               daci_config config;
+                                               config.config_id = session->accountId;
+
+                                               if (chal->format == FORMAT_TYPE_BASE64)
+                                                       value = chal->nonce_b64;
+                                               else
+                                                       value = g_base64_encode((const unsigned char *)chal->nonce_plain, chal->nonce_length);
+
+                                               bool result = set_config_str(session->accountId, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, value, "string", "SA");
+                                               if (result == false) {
+                                                       errorType = SA_INTERNAL_ERROR;
+                                                       FW_LOGE("failed in set_Config");
+                                                       goto error;
+                                               }
+                                       }
+                               } else if (session->cred->type == AUTH_TYPE_BASIC) {
+                                       /*do not need cred anymore
+                                       but we just send it again*/
+                               }
+                       } else if (statusType == NO_ERROR) {
+                               /*200
+                                when auth type is AUTH_TYPE_BASIC sam credentials must be sent within the next request
+                                when auth type is AUTH_TYPE_MD5  The next nonce in Chal MUST used when the next request is sent*/
+                               if (session->cred->type == AUTH_TYPE_MD5) {
+                                       /*if auth type is AUTH_TYPE_MD5*/
+                                       if (status->chal) {
+                                               /*if there is a chal in status duplicate to session
+                                               chal have to used when next request is sent*/
+                                               session->chal = dup_chal(status->chal);
+                                       }
+                               }
+                       } else if (statusType == ERROR_AUTH_REQUIRED || statusType == ERROR_AUTH_REJECTED) {
+                               if (status->chal)
+                                       session->chal = dup_chal(status->chal);
+                               errorType = SA_INTERNAL_AUTHENTICATION_ERROR;
+                               goto error;
+                       } else if (statusType == ERROR_SERVER_FAILURE) {
+                               errorType = SA_INTERNAL_SERVER_FAILURE;
+                               goto error;
+                       } else if (statusType == IN_PROGRESS) {
+                               /*busy signaling*/
+                               errorType = SA_INTERNAL_BUSY_SIGNALING;
+                               goto error;
+                       }
+               } else{
+                       /*status except status of SyncHdr*/
+                       if (status->type == COMMAND_TYPE_ALERT) {
+                               errorType = __receive_alert_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_PUT) {
+                               errorType = __receive_put_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_GET) {
+                               errorType = __receive_get_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_RESULTS) {
+                               errorType = __receive_results_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_SYNC_START) {
+                               errorType = __receive_sync_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_MAP) {
+                               errorType = __receive_map_status(session, status);
+                       } else if (status->type == COMMAND_TYPE_ADD ||
+                                       status->type == COMMAND_TYPE_REPLACE ||
+                                       status->type == COMMAND_TYPE_DELETE) {
+                               errorType = __receive_changes_status(session, status, returnStatus);
+                       }
+
+                       if (errorType != SA_INTERNAL_OK)
+                               goto error;
+               }
+               statusItem = g_list_next(statusItem);
+       }
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+       FW_LOGE(" error, Error Type %d", errorType);
+       return errorType;
+}
+
+SA_ErrorType receive_commands(Session *session, GList *receiveCommand, bool autoConfig, GList **returnDatastore)
+{
+       FW_LOGV("start");
+
+       SA_ErrorType errorType = SA_INTERNAL_OK;
+       int item_luid_count = 0;
+       int index = 0;
+       int i;
+       char **luid_str_list = NULL;
+
+       GList *iter = NULL;
+       Command *command = NULL;
+       for (iter = receiveCommand; iter != NULL; iter = g_list_next(iter)) {
+               command = iter->data;
+
+               if (command->type == COMMAND_TYPE_ADD)
+                       item_luid_count += g_list_length(command->private.change.items);
+       }
+
+       FW_LOGV("item_luid_count = %d", item_luid_count);
+
+       if (item_luid_count > 0) {
+               luid_str_list = DACI_Generate_Item_Luid(1, item_luid_count);
+               if (luid_str_list == NULL) {
+                       FW_LOGE("failed in DACI_Generate_Item_Luid");
+                       errorType = SA_INTERNAL_ERROR;
+                       goto error;
+               }
+       }
+
+       ChangedDatastore *changedDatastore = NULL;
+       for (iter = receiveCommand; iter != NULL; iter = g_list_next(iter)) {
+               command = iter->data;
+
+               if (autoConfig != true || (autoConfig == true && command->type == COMMAND_TYPE_RESULTS)) {
+                       switch (command->type) {
+                       case COMMAND_TYPE_UNKNOWN:
+                       case COMMAND_TYPE_HEADER:
+                       case COMMAND_TYPE_MAP:
+                               /*never receive theses commands*/
+                               break;
+                       case COMMAND_TYPE_ALERT:
+                               errorType = __receive_alert_command(session, command, returnDatastore);
+                               break;
+                       case COMMAND_TYPE_PUT:
+                               errorType = __receive_put_command(session, command);
+                               break;
+                       case COMMAND_TYPE_GET:
+                                       errorType = __receive_get_command(session, command);
+                               break;
+                       case COMMAND_TYPE_RESULTS:
+                               errorType = __receive_results_command(session, command);
+                               break;
+                       case COMMAND_TYPE_SYNC_START:
+                               errorType = __receive_sync_command(session, command, &changedDatastore);
+                               break;
+                       case COMMAND_TYPE_SYNC_END:
+                               if (changedDatastore) {
+                                       *returnDatastore = g_list_append(*returnDatastore, changedDatastore);
+                                       changedDatastore = NULL;
+                               }
+                               break;
+                       case COMMAND_TYPE_ADD:
+                       case COMMAND_TYPE_REPLACE:
+                       case COMMAND_TYPE_DELETE:
+                               errorType = __receive_changes_command(session, command, luid_str_list, &index, &changedDatastore);
+                               break;
+                       }
+
+                       if (errorType != SA_INTERNAL_OK)
+                               goto error;
+               }
+       }
+
+       if (luid_str_list != NULL) {
+               /*free luid_str_list*/
+               for (i = 0; i < item_luid_count; i++)
+                       free(luid_str_list[i]);
+
+               free(luid_str_list);
+       }
+
+       FW_LOGV("end");
+
+       return errorType;
+
+error:
+
+       if (luid_str_list != NULL) {
+               /*free luid_str_list*/
+               for (i = 0; i < item_luid_count; i++)
+                       free(luid_str_list[i]);
+
+               free(luid_str_list);
+       }
+
+       FW_LOGE("error: %d", errorType);
+       return errorType;
+}
+
+void reset_cmdID_session(Session *session)
+{
+       if (session)
+               session->cmdID = 1;
+}
diff --git a/src/ServiceAdapter/SA_Util.c b/src/ServiceAdapter/SA_Util.c
new file mode 100644 (file)
index 0000000..10e9c19
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SA_Util.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of utility function
+ */
+
+#include "agent-framework/securityAssistant/EXT_SA_Encryption_Decryption.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceAdapter/SA_Util.h"
+
+#define LOG_TAG        "OMA_DS_SA"
+
+void put_into_list(GList **commands, GList **commands_last, void *pCommand)
+{
+       GList *temp = NULL;
+       if (*commands_last == NULL) {
+               *commands_last = *commands = g_list_append(*commands, pCommand);
+       } else {
+               temp = g_list_append(*commands_last, pCommand);
+               *commands_last = g_list_next(*commands_last);
+       }
+}
+
+SA_ErrorType create_cred_string(AuthType type,  const char *username,  const char *password,
+                                                                                                       const char *nonce, unsigned int nonce_size, char **pCred)
+{
+       FW_LOGV("start");
+       SA_ErrorType errortype = SA_INTERNAL_OK;
+
+       switch (type) {
+               case AUTH_TYPE_BASIC:
+               {
+                       char *plain = g_strjoin(":", username, password, NULL);
+                       *pCred = g_base64_encode((unsigned char *) plain, strlen(plain));
+                       if (*pCred == NULL) {
+                               free(plain);
+                               errortype = SA_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+                       free(plain);
+
+                       break;
+               }
+               case AUTH_TYPE_MD5:
+               {
+                       /* How does syncml:auth-md5 works?
+                        *
+                        * base64(
+                        *        md5(
+                        *            base64(
+                        *                   md5(
+                        *                       username + ":" + password
+                        *                     )
+                        *                 ) +
+                        *            ":" + nonce
+                        *          )
+                        *      )
+                        */
+
+                       /* Let's determine the string for the comparison. */
+                       char *auth = g_strjoin(":", username, password, NULL);
+                       FW_LOGV("username:password = %s", auth);
+                       unsigned char *digest = NULL;
+                       digest = SA_Get_Encryption_Value(SA_ENCRYPTION_MD5, auth, strlen(auth));
+                       free(auth);
+                       *pCred = g_base64_encode(digest, 16);
+                       free(digest);
+                       if (*pCred == NULL) {
+                               errortype = SA_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       if (nonce != NULL) {
+                               FW_LOGV("nonce = %s", nonce);
+                               FW_LOGV("nonce_size = %d", nonce_size);
+
+                               int auth_size = strlen(*pCred) + nonce_size + 1;
+                               auth = (char *)calloc(auth_size + 1, sizeof(char));
+                               memcpy(auth, *pCred, strlen(*pCred));
+                               auth[strlen(*pCred)] = ':';
+                               memcpy(auth + strlen(*pCred) + 1, nonce, nonce_size);
+                               FW_LOGV("base64[md5[username:password]] = %s", *pCred);
+                               FW_LOGV("before last base64 encoding = %s", auth);
+                               free(*pCred);
+
+                               /*MD5GetDigest (auth, strlen(auth), digest);*/
+
+                               /*
+                               GChecksum* pMd5 = g_checksum_new(G_CHECKSUM_MD5);
+                               g_checksum_update(pMd5, auth, auth_size);
+                               gsize temp = 16;
+                               digest = (unsigned char*)calloc(16, sizeof(unsigned char));
+                               g_checksum_get_digest(pMd5, digest, &temp);
+                               */
+
+                               digest = SA_Get_Encryption_Value(SA_ENCRYPTION_MD5, auth, auth_size);
+                               FW_LOGV("md5[base64[md5[username:password]]] = %s", digest);
+
+                               free(auth);
+                               *pCred = g_base64_encode(digest, 16);
+                               free(digest);
+                               FW_LOGV("base64[md5[base64[md5[username:password]]]] = %s", *pCred);
+                               if (*pCred == NULL) {
+                                       errortype = SA_INTERNAL_NO_MEMORY;
+                                       goto error;
+                               }
+                       }
+                       break;
+               case AUTH_TYPE_UNKNOWN:
+                       break;
+
+               }
+       }
+
+       FW_LOGV("end");
+       return errortype;
+
+error:
+       FW_LOGE("error : %d", errortype);
+       return errortype;
+}
+
+void  set_xml_to_file(char *xml, const char *path)
+{
+       FILE *pFile = NULL;
+
+       if (xml != NULL)
+               pFile = fopen(path, "a");
+
+       if (pFile == NULL)
+               return;
+
+       fputs("==================================================================================", pFile);
+       fputs("\n", pFile);
+
+       if (xml != NULL)
+               fputs(xml, pFile);
+
+       if (xml != NULL)
+               fclose(pFile);
+}
diff --git a/src/ServiceEngine/SE_Account.c b/src/ServiceEngine/SE_Account.c
new file mode 100644 (file)
index 0000000..13c306e
--- /dev/null
@@ -0,0 +1,1908 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Account.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of account in Service Engine
+ */
+
+#include "Common/CscKeys.h"
+#include "Common/Common_Vconf.h"
+#include "Common/Common_Define.h"
+#include "Common/Common_Util.h"
+#include "ServiceEngine/SE_Account.h"
+#include "ServiceEngine/SE_Error.h"
+#include "ServiceEngine/SE_Common.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/DACI/DACI_Luid.h"
+#include "agent-framework/Account/Account_Mgr.h"
+#include "agent-framework/PlatformMonitor/EXT_PMCI_Struct.h"
+#include "agent-framework/PlatformMonitor/EXT_PMCI.h"
+#include "agent-framework/Device/EXT_DCI_DevInfo.h"
+#include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
+
+#define LOG_TAG        "OMA_DS_SE"
+
+#define MAX_DATASTORE_COUNT 3
+
+typedef struct {
+       char *serverName;
+       int index;
+} datastore_cp_info;
+
+
+static char *predefinedDatastore[][MAX_DATASTORE_COUNT][2] = {
+               { {"contacts", "text/x-vcard"}, {"calendar", "text/x-vcalendar"}, {"notes", "text/plain"} }
+};
+
+static datastore_cp_info predefinedServer[] = {
+               {"O3SIS SyncML", 0}
+};
+
+/* TODO have to remove after removing vconf*/
+static SE_ErrorType __set_datastore_config_from_vconf(int accountID, char *profilePath, int content_type);
+
+static SE_ErrorType __set_datastore_config_from_csc(int accountID, int index, int content_type);
+static SE_ErrorType __add_profile(char *addr, char *id, char *password, char *access_name, int *accountID);
+static SE_ErrorType __set_profile_info(int accountId, char *profileName, char *syncMode, char *syncType, char *interval);
+static SE_ErrorType __set_profile_category(int accountId, int contentType, sync_category *category);
+static SE_ErrorType __set_profile_category_cp(int accountId, int contentType, resource_cp *category);
+static SE_ErrorType __set_periodic_sync_config(int account_id, char *syncMode, char *interval);
+static SE_ErrorType __set_config_default_value(int accountID);
+static SE_ErrorType __set_datastore_config_default_value(int accountID, int content_type);
+
+/* TODO have to remove after removing vconf*/
+static SE_ErrorType __set_datastore_config_from_vconf(int accountID, char *profilePath, int content_type)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char *isEnabledPath = NULL;
+       char *targeturiPath = NULL;
+       char *sourceuriPath = NULL;
+       char *IDPath = NULL;
+       char *PWDPath = NULL;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_source[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       int isEnabled = 0;
+       char *targeturi = NULL;
+       char *sourceuri = NULL;
+       char *ID = NULL;
+       char *PWD = NULL;
+
+       bool result;
+
+       if (content_type == TYPE_CONTACT) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+               isEnabledPath =  DS_SETTING_CONTACT_ENABLED;
+               targeturiPath =  DS_SETTING_CONTACT_TGTURI;
+               sourceuriPath = DS_SETTING_CONTACT_SRCURI;
+               IDPath =   DS_SETTING_CONTACT_AUTHNAME;
+               PWDPath =  DS_SETTING_CONTACT_AUTHPWD;
+       } else if (content_type == TYPE_CALENDAR) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+               isEnabledPath =  DS_SETTING_CALENDAR_ENABLED;
+               targeturiPath =  DS_SETTING_CALENDAR_TGTURI;
+               sourceuriPath =  DS_SETTING_CALENDAR_SRCURI;
+               IDPath =   DS_SETTING_CALENDAR_AUTHNAME;
+               PWDPath =   DS_SETTING_CALENDAR_AUTHPWD;
+       } else if (content_type == TYPE_MEMO) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+               isEnabledPath = DS_SETTING_MEMO_ENABLED;
+               targeturiPath =  DS_SETTING_MEMO_TGTURI;
+               sourceuriPath =  DS_SETTING_MEMO_SRCURI;
+               IDPath =   DS_SETTING_MEMO_AUTHNAME;
+               PWDPath =   DS_SETTING_MEMO_AUTHPWD;
+       }
+
+       result = get_vconf_int(profilePath, isEnabledPath, &isEnabled);
+       if (result == false) {
+               FW_LOGE("failed in get_Vconf_int");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+        }
+
+       targeturi = get_vconf_str(profilePath, targeturiPath);
+       sourceuri = get_vconf_str(profilePath, sourceuriPath);
+       ID = get_vconf_str(profilePath, IDPath);
+       PWD = get_vconf_str(profilePath, PWDPath);
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       if (isEnabled) {
+               result = set_config_str(accountID, datastore, "1", "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               result = set_config_str(accountID, datastore_target, targeturi, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               result = set_config_str(accountID, datastore_id, ID, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               result = set_config_str(accountID, datastore_pw, PWD, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+       } else{
+               result = set_config_str(accountID, datastore, "0", "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+
+       result = set_config_str(accountID, datastore_source, sourceuri, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (targeturi)
+               free(targeturi);
+       if (sourceuri)
+               free(sourceuri);
+       if (ID)
+               free(ID);
+       if (PWD)
+               free(PWD);
+
+       return err;
+}
+
+
+static SE_ErrorType __set_datastore_config_from_csc(int accountID, int index, int content_type)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char *isEnabledPath = NULL;
+       char *targeturiPath = NULL;
+       char *IDPath = NULL;
+       char *PWDPath = NULL;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_source[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       int isEnabled = 0;
+       char *targeturi = NULL;
+       char *ID = NULL;
+       char *PWD = NULL;
+       char profilePath[128];
+
+       char *sourceuri = NULL;
+
+       bool result;
+
+       if (content_type == TYPE_CONTACT) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+               sourceuri = DEFINE_SOURCE_CONTACT_URI;
+               isEnabledPath =  CSC_VCONF_KEY_SYNCMLDS_CONTACTS_ENABLED;
+               targeturiPath =  CSC_VCONF_KEY_SYNCMLDS_CONTACTS_TGTURI;
+               IDPath =   CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHNAME;
+               PWDPath =  CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHPWD;
+       } else if (content_type == TYPE_CALENDAR) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+               sourceuri = DEFINE_SOURCE_CALENDAR_URI;
+               isEnabledPath =  CSC_VCONF_KEY_SYNCMLDS_CALENDAR_ENABLED;
+               targeturiPath =  CSC_VCONF_KEY_SYNCMLDS_CALENDAR_TGTURI;
+               IDPath =   CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHNAME;
+               PWDPath =   CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHPWD;
+       } else if (content_type == TYPE_MEMO) {
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+               sourceuri = DEFINE_SOURCE_MEMO_URI;
+               isEnabledPath = CSC_VCONF_KEY_SYNCMLDS_MEMO_ENABLED;
+               targeturiPath =  CSC_VCONF_KEY_SYNCMLDS_MEMO_TGTURI;
+               IDPath =   CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHNAME;
+               PWDPath =   CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHPWD;
+       } else{
+               err = SE_INTERNAL_ERROR;
+               FW_LOGE("No content type");
+               goto error;
+       }
+
+       sprintf(profilePath, isEnabledPath, index);
+       result = get_vconf_Int_key(profilePath, &isEnabled);
+       if (result == false) {
+               FW_LOGE("No value in vconf key = %s", profilePath);
+               goto error;
+       }
+
+       sprintf(profilePath, targeturiPath, index);
+       targeturi = get_vconf_str_key(profilePath);
+
+       sprintf(profilePath, IDPath, index);
+       ID = get_vconf_str_key(profilePath);
+
+       sprintf(profilePath, PWDPath, index);
+       PWD = get_vconf_str_key(profilePath);
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       if (isEnabled) {
+               result = set_config_str(accountID, datastore, "1", "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+               result = set_config_str(accountID, datastore_target, targeturi, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+               result = set_config_str(accountID, datastore_id, ID, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+               result = set_config_str(accountID, datastore_pw, PWD, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+       } else{
+               result = set_config_str(accountID, datastore, "0", "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+       result = set_config_str(accountID, datastore_source, sourceuri, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (targeturi)
+               free(targeturi);
+       if (ID)
+               free(ID);
+       if (PWD)
+               free(PWD);
+
+       return err;
+}
+
+static SE_ErrorType __add_profile(char *addr, char *id, char *password, char *access_name, int *accountID)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       int account = addAccount(id, password, addr, NULL, 0, 0, access_name);
+       char *folderID = NULL;
+
+       FW_LOGV("accountID = %d", account);
+
+       if (account < 0) {
+               FW_LOGE("accountID = %d", account);
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       folderID = DACI_Generate_Folder_Luid();
+       if (folderID == NULL) {
+               FW_LOGE("failed in DACI_Generate_Folder_Luid");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       daci_folder folder;
+       folder.account_id = account;
+       folder.folder_id = folderID;
+       folder.data_store_id = TYPE_CONTACT;
+       folder.folder_type_id = 0; /* Default contacts folder */
+       folder.parent_folder_id = 0;
+       folder.service_id = "0";
+       folder.access_name = "EventHandler";
+       DACI_RETURN ret = DACI_Add_Folder(&folder, 1);
+       if (ret != DACI_SUCCESS) {
+               FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
+               FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
+
+       if (folderID != NULL) {
+               free(folderID);
+               folderID = NULL;
+       }
+
+       folderID = DACI_Generate_Folder_Luid();
+       if (folderID == NULL) {
+               FW_LOGE("failed in DACI_Generate_Folder_Luid");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       folder.account_id = account;
+       folder.folder_id = folderID;
+       folder.data_store_id = TYPE_CALENDAR;
+       folder.folder_type_id = 0; /* Default calendars folder */
+       folder.parent_folder_id = 0;
+       folder.service_id = "1";
+       folder.access_name = "EventHandler";
+       ret = DACI_Add_Folder(&folder, 1);
+       if (ret != DACI_SUCCESS) {
+               FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
+               FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
+
+       if (folderID != NULL) {
+               free(folderID);
+               folderID = NULL;
+       }
+
+       /* TODO : add default memo folder (Hard cording) */
+       folderID = DACI_Generate_Folder_Luid();
+       if (folderID == NULL) {
+               FW_LOGE("failed in DACI_Generate_Folder_Luid");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       folder.account_id = account;
+       folder.folder_id = folderID;
+       folder.data_store_id = TYPE_MEMO;
+       folder.folder_type_id = 0; /* Default notes folder */
+       folder.parent_folder_id = 0;
+       folder.service_id = "0";
+       folder.access_name = "EventHandler";
+       ret = DACI_Add_Folder(&folder, 1);
+       if (ret != DACI_SUCCESS) {
+               FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
+               FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
+
+       if (folderID != NULL) {
+               free(folderID);
+               folderID = NULL;
+       }
+
+       /* call log folder ID */
+       folderID = DACI_Generate_Folder_Luid();
+       if (folderID == NULL) {
+               FW_LOGE("failed in DACI_Generate_Folder_Luid");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       folder.account_id = account;
+       folder.folder_id = folderID;
+       folder.data_store_id = TYPE_CALLLOG;
+       folder.folder_type_id = 0; /* Default call log folder */
+       folder.parent_folder_id = 0;
+       folder.service_id = "0";
+       folder.access_name = "EventHandler";
+       ret = DACI_Add_Folder(&folder, 1);
+       if (ret != DACI_SUCCESS) {
+               FW_LOGE("Agent Add_Folder Failed_In addAccount()!");
+               FW_LOGE("[process_Event_Add_Account] Agent Add_Folder Failed_In addAccount()!");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("[process_Event_Add_Account] Successed Agent Add_Folder in addAccount(), added Folder ID : %s", folder.folder_id);
+
+       if (folderID != NULL) {
+               free(folderID);
+               folderID = NULL;
+       }
+
+       *accountID = account;
+
+       FW_LOGV("end");
+
+error:
+
+       if (folderID != NULL)
+               free(folderID);
+
+       return err;
+}
+
+
+static SE_ErrorType __set_profile_info(int accountId, char *profileName, char *syncMode, char *syncType, char *interval)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , syncType, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+
+static SE_ErrorType __set_profile_category(int accountId, int contentType, sync_category *category)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("category->enabled : %d", category->enabled);
+       FW_LOGV("category->srcURI : %s", category->srcURI);
+       FW_LOGV("category->tgtURI : %s", category->tgtURI);
+       FW_LOGV("category->id : %s", category->id);
+       FW_LOGV("category->password : %s", category->password);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_source[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (contentType == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+
+       result = set_config_int(accountId, datastore, category->enabled, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_source, category->srcURI, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_target, category->tgtURI, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_id, category->id, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_pw, category->password, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+       return err;
+
+}
+
+static SE_ErrorType __set_profile_category_cp(int accountId, int contentType, resource_cp *category)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("category->srcURI : %s", category->name);
+       FW_LOGV("category->id : %s", category->id);
+       FW_LOGV("category->password : %s", category->password);
+       FW_LOGV("category->authType : %s", category->authType);
+       FW_LOGV("category->authData : %s", category->authData);
+       FW_LOGV("category->tgtURI : %s", category->accept);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       result = set_config_str(accountId, datastore_target, category->name, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_id, category->id, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, datastore_pw, category->password, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+       return err;
+
+}
+
+static SE_ErrorType __set_periodic_sync_config(int account_id, char *syncMode, char *interval)
+{
+       FW_LOGV("start");
+       FW_LOGV("syncMode = %s", syncMode);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       PMCI_RETURN scheduler_err;
+       bool result;
+       char *value = NULL;
+       int alarm_id = 0;
+
+       pmci_alarm_t *alarm_info = (pmci_alarm_t *)calloc(1, sizeof(pmci_alarm_t));
+
+       result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       alarm_id = atoi(value);
+
+       if (alarm_id != 0) {
+               scheduler_err = PMCI_Remove_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarm_id);
+               if (scheduler_err != PMCI_SUCCESS) {
+                       FW_LOGE("failed in PMCI_Remove_Item_To_Specific_Type");
+                       err = SE_INTERNAL_SCHEDULER_ERROR;
+                       goto error;
+               }
+       }
+
+       if (strcmp(syncMode , DEFINE_SYNC_MODE_PERIODIC) == 0 && interval != NULL) {
+
+               result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , DEFINE_ALERT_TWO_WAY_STR, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+                int week[] = {DAY_SUN, DAY_MON, DAY_TUE, DAY_WED, DAY_THU, DAY_FRI, DAY_SAT};
+                time_t current_time;
+                struct tm *struct_time;
+                time(&current_time);
+                struct_time = localtime(&current_time);
+                if (struct_time == NULL) {
+                        FW_LOGE("struct_time is NULL");
+                        err = SE_INTERNAL_ERROR;;
+                       goto error;
+                }
+
+                alarm_info->start_alarm_time = g_strdup_printf("%.2d-%.2d-%.2dT%.2d:%.2d:%.2dZ",
+                   struct_time->tm_year+1900,
+                   struct_time->tm_mon+1,
+                   struct_time->tm_mday,
+                   struct_time->tm_hour,
+                   struct_time->tm_min,
+                   struct_time->tm_sec);
+                alarm_info->isDisposable = 0;
+
+               if (strcmp(interval, "5 minutes") == 0) {
+                       FW_LOGV("5 minutes");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = 5*60;
+               } else if (strcmp(interval, "15 minutes") == 0) {
+                       FW_LOGV("15 minutes");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = 15*60;
+               } else if (strcmp(interval, "1 hour") == 0) {
+                       FW_LOGV("1 hour");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = ((1*60)*60);
+               } else if (strcmp(interval, "4 hours") == 0) {
+                       FW_LOGV("4 hours");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = ((4*60)*60);
+               } else if (strcmp(interval, "12 hours") == 0) {
+                       FW_LOGV("12 hours");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = ((12*60)*60);
+               } else if (strcmp(interval, "1 day") == 0) {
+                       FW_LOGV("1 day");
+                       alarm_info->repeat_type = REPEAT;
+                       alarm_info->repeat_value = ((24*60)*60);
+               } else if (strcmp(interval, "1 week") == 0) {
+                       FW_LOGV("1 week");
+                       alarm_info->repeat_type = REPEAT_WEEKLY;
+                       alarm_info->repeat_value = week[struct_time->tm_wday];
+               }
+
+               scheduler_err = PMCI_Add_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarm_info, &alarm_id);
+               if (scheduler_err != PMCI_SUCCESS) {
+                       FW_LOGE("failed in PMCI_Add_Item_To_Specific_Type");
+                       err = SE_INTERNAL_SCHEDULER_ERROR;
+                       goto error;
+               }
+               FW_LOGV("alarm_id =%d", alarm_id);
+
+               result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, alarm_id, "int", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+       } else{
+               result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (value != NULL)
+               free(value);
+
+       if (alarm_info != NULL) {
+               if (alarm_info->start_alarm_time != NULL)
+                       free(alarm_info->start_alarm_time);
+
+               free(alarm_info);
+       }
+
+       return err;
+}
+
+
+static SE_ErrorType __set_config_default_value(int accountID)
+{
+       FW_LOGV("start");
+       SE_ErrorType  err = SE_INTERNAL_OK;
+
+       bool result;
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, "Push", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE , "Full", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, "5 minutes", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, "-1", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, "-1", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               err = __set_datastore_config_default_value(accountID, content_type);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in set_DatastoreConfig");
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+error:
+
+       return err;
+}
+
+static SE_ErrorType __set_datastore_config_default_value(int accountID, int contentType)
+{
+       FW_LOGV("start");
+       SE_ErrorType  err = SE_INTERNAL_OK;
+
+       bool result;
+
+       char *datastore = NULL;
+       char datastore_target[128];
+       char datastore_source[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       char datastore_dbSynced[128];
+       char datastore_lastSessionTime[128];
+       char datastore_s2c_Total[128];
+       char datastore_s2c_NrOfAdd[128];
+       char datastore_s2c_NrOfDelete[128];
+       char datastore_s2c_NrOfReplace[128];
+       char datastore_c2s_Total[128];
+       char datastore_c2s_NrOfAdd[128];
+       char datastore_c2s_NrOfDelete[128];
+       char datastore_c2s_NrOfReplace[128];
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if(contentType == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       sprintf(datastore_dbSynced, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
+       sprintf(datastore_lastSessionTime, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
+
+       sprintf(datastore_s2c_Total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(datastore_s2c_NrOfAdd, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(datastore_s2c_NrOfDelete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+       sprintf(datastore_s2c_NrOfReplace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+
+       sprintf(datastore_c2s_Total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(datastore_c2s_NrOfAdd, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(datastore_c2s_NrOfDelete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+       sprintf(datastore_c2s_NrOfReplace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+
+
+       result = set_config_str(accountID, datastore, "0", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_source, datastore, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_target, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_id, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_pw, NULL, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_dbSynced, DEFINE_DBSYNC_NO, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, datastore_lastSessionTime, "-1", "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_s2c_Total, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_s2c_NrOfAdd, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_s2c_NrOfDelete, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_s2c_NrOfReplace, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_c2s_Total, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_c2s_NrOfAdd, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_c2s_NrOfDelete, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountID, datastore_c2s_NrOfReplace, 0, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       FW_LOGV("end");
+
+error:
+       return err;
+}
+
+/*TODO have to be removed after removing vconf*/
+int update_all_config(char *profile,  bool isAdd, int *accountId)
+{
+       FW_LOGV("profile = %s", profile);
+
+       SE_ErrorType  err = SE_INTERNAL_OK;
+       char profilePath[128];
+       char *profileName = NULL;
+       char *email = NULL;
+       char *password = NULL;
+       char *serverIP = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       char *interval = NULL;
+       bool result;
+
+       if (profile == NULL) {
+               FW_LOGE("profile is NULL");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, "%s/%s", DS_SETTINGS_PATH, profile);
+
+       email = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHNAME);
+       password = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHPWD);
+       serverIP = get_vconf_str(profilePath, DS_SETTING_ADDR);
+
+       FW_LOGV("email = %s", email);
+       FW_LOGV("password = %s", password);
+       FW_LOGV("serverIP = %s", serverIP);
+
+       int accountID;
+       if (isAdd == true) {
+               err = __add_profile(serverIP, email, password , "UI", &accountID);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in add_Account");
+                       goto error;
+               }
+
+               err = __set_config_default_value(accountID);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in add_Account");
+                       goto error;
+               }
+
+               result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profile, "string", "SE");
+               if (result == false) {
+                       FW_LOGE("failed in set_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+       } else{
+               accountID = get_accountid(profile, true);
+
+               FW_LOGV("accountID = %d", accountID);
+
+               da_err = DACI_Set_Account_Email_Address(accountID, email, "SE");
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("failed in DACI_Set_Account_Email_Address = %d", da_err);
+                       err = SE_INTERNAL_ERROR;
+                       goto error;
+               }
+
+               da_err = DACI_Set_Account_Password(accountID, password, "SE");
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("failed in DACI_Set_Account_Email_Address = %d", da_err);
+                       err = SE_INTERNAL_ERROR;
+                       goto error;
+               }
+       }
+
+       profileName = get_vconf_str(profilePath, DS_SETTING_NAME);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, serverIP, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       syncMode = get_vconf_str(profilePath, DS_SETTING_SYNCMODE);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       syncType =  get_vconf_str(profilePath, DS_SETTING_SYNCTYPE);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       interval = get_vconf_str(profilePath, DS_SETTING_INTERVAL);
+       FW_LOGV("interval %s ", interval);
+
+       err = __set_periodic_sync_config(accountID, syncMode, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_periodic_sync_config");
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT - 1; content_type++) {
+               err = __set_datastore_config_from_vconf(accountID, profilePath, content_type);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in set_DatastoreConfig");
+                       goto error;
+               }
+       }
+
+       *accountId = accountID;
+
+       FW_LOGV("end");
+
+error:
+
+       if (profileName)
+               free(profileName);
+       if (email)
+               free(email);
+       if (password)
+               free(password);
+       if (serverIP)
+               free(serverIP);
+       if (syncMode)
+               free(syncMode);
+       if (syncType)
+               free(syncType);
+       if (interval)
+               free(interval);
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return 0;
+       else
+               return 1;
+}
+
+
+int add_profile_csc(int index)
+{
+       SE_ErrorType  err = SE_INTERNAL_OK;
+       char profilePath[128];
+       char profileDirName[128];
+       char *profileName = NULL;
+       char *id = NULL;
+       char *password = NULL;
+       char *serverIP = NULL;
+       char *syncMode = NULL;
+       char *syncType = NULL;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_ADDR, index);
+       serverIP =  get_vconf_str_key(profilePath);
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_AUTHNAME, index);
+       id = get_vconf_str_key(profilePath);
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_AUTHPWD, index);
+       password = get_vconf_str_key(profilePath);
+
+       FW_LOGV("email = %s", id);
+       FW_LOGV("password = %s", password);
+       FW_LOGV("serverIP = %s", serverIP);
+
+       int accountID;
+       err = __add_profile(serverIP, id, password , "CSC", &accountID);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       err = __set_config_default_value(accountID);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_config_default_value");
+               goto error;
+       }
+
+       /*set profile dir name in config table*/
+       sprintf(profileDirName, "Sync%d", index);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, serverIP, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_NAME, index);
+       profileName = get_vconf_str_key(profilePath);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_SYNCMODE, index);
+       syncMode = get_vconf_str_key(profilePath);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       sprintf(profilePath, CSC_VCONF_KEY_SYNCMLDS_SYNCTYPE, index);
+       syncType =  get_vconf_str_key(profilePath);
+       result = set_config_str(accountID, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT - 1; content_type++) {
+               err = __set_datastore_config_from_csc(accountID, index, content_type);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in set_DatastoreConfig");
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (profileName)
+               free(profileName);
+       if (id)
+               free(id);
+       if (password)
+               free(password);
+       if (serverIP)
+               free(serverIP);
+       if (syncMode)
+               free(syncMode);
+       if (syncType)
+               free(syncType);
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return 0;
+       else
+               return 1;
+}
+
+bool add_profile_cp(char *profileName, char *addr, char *id, char *password, GList *categories, int *accountId)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("profileName = %s", profileName);
+       FW_LOGV("addr = %s", addr);
+       FW_LOGV("id = %s", id);
+       FW_LOGV("password = %s", password);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       int account = -1;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       err = __add_profile(addr, id, password, "CP", &account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       err = __set_config_default_value(account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       int i;
+       int cnt = (int) sizeof(predefinedServer) / sizeof(datastore_cp_info);
+       FW_LOGV("cnt = %d", cnt);
+       for (i = 0; i < cnt; i++) {
+
+               FW_LOGV("predefinedServer[%d].serverName = %s", i, predefinedServer[i].serverName);
+               if (strcmp(predefinedServer[i].serverName, profileName) == 0) {
+
+                       int j;
+                       for (j = 0; j < MAX_DATASTORE_COUNT; j++) {
+                               resource_cp *category = NULL;
+                               GList *iter = NULL;
+                               FW_LOGV("categories length = %d", g_list_length(categories));
+                               for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
+                                       category = (resource_cp *)iter->data;
+                                       FW_LOGV("category->name = %s", category->name);
+                                       FW_LOGV("category->accept = %s", category->accept);
+
+                                       FW_LOGV("predefinedDatastore[i][j][0] = %s", predefinedDatastore[i][j][0]);
+                                       FW_LOGV("predefinedDatastore[i][j][1] = %s", predefinedDatastore[i][j][1]);
+
+                                       if (predefinedDatastore[i][j][0] != NULL && category->name != NULL &&
+                                                       predefinedDatastore[i][j][1] != NULL && category->accept != NULL) {
+
+                                               if (strcasecmp(predefinedDatastore[i][j][0] , category->name) == 0 &&
+                                                       strcmp(predefinedDatastore[i][j][1], category->accept) == 0) {
+
+                                                       err = __set_profile_category_cp(account, j, category);
+                                                       if (err  != SE_INTERNAL_OK) {
+                                                               FW_LOGE("failed in __set_profile_category");
+                                                               goto error;
+                                                       }
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       *accountId = account;
+
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool add_profile(char *profileDirName, char *profileName, char *addr, char *id, char *password, char *syncMode, char *syncType, char *interval, GList *categories, int *accountId)
+{
+       FW_LOGV("start");
+
+       FW_LOGV("profileName = %s", profileName);
+       FW_LOGV("addr = %s", addr);
+       FW_LOGV("id = %s", id);
+       FW_LOGV("password = %s", password);
+       FW_LOGV("syncMode = %s", syncMode);
+       FW_LOGV("syncType = %s", syncType);
+       FW_LOGV("interval = %s", interval);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       int account = -1;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       err = __add_profile(addr, id, password, "UI", &account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       err = __set_config_default_value(account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       err = __set_profile_info(account, profileName, syncMode, syncType, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_info");
+               goto error;
+       }
+
+       err = __set_periodic_sync_config(account, syncMode, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_info");
+               goto error;
+       }
+
+       sync_category *category = NULL;
+       GList *iter = NULL;
+       int contentType = 0;
+       for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
+               category = iter->data;
+               err = __set_profile_category(account, contentType, category);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in __set_profile_category");
+                       goto error;
+               }
+               contentType++;
+       }
+
+       *accountId = account;
+
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool edit_profile(int accountId, char *profileName, char *addr, char *id, char *password, char *syncMode, char *syncType, char *interval, GList *categories)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       da_err = DACI_Set_Account_Email_Address(accountId, id, "SE");
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Set_Account_Email_Address");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+
+       da_err = DACI_Set_Account_Password(accountId, password, "SE");
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Set_Account_Email_Address");
+               err = SE_INTERNAL_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       err = __set_profile_info(accountId, profileName, syncMode, syncType, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_info");
+               goto error;
+       }
+
+       err = __set_periodic_sync_config(accountId, syncMode, interval);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_info");
+               goto error;
+       }
+
+       sync_category *category = NULL;
+       GList *iter = NULL;
+       int contentType = 0;
+       for (iter = categories; iter != NULL; iter = g_list_next(iter)) {
+               category = iter->data;
+               err = __set_profile_category(accountId, contentType, category);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in __set_profile_category");
+                       goto error;
+               }
+               contentType++;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool delete_profiles(GList *profiles)
+{
+       FW_LOGV("start");
+       SE_ErrorType  err = SE_INTERNAL_OK;
+       char *profileName = NULL;
+       int *accountId = 0;
+       char *value = NULL;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       GList *iter = NULL;
+       int alarmId = 0;
+
+       bool result;
+       for (iter = profiles; iter != NULL; iter = g_list_next(iter)) {
+               accountId = (int *)(iter->data);
+
+               FW_LOGV("accountId = %d", *accountId);
+               /*if deleteing Account's sync mode is periodic sync it has to be deleted from schedule_tbl*/
+               result = get_config(*accountId, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value);
+               if (result == false) {
+                       FW_LOGE("failed in get_config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+               alarmId = atoi(value);
+               if (alarmId != 0) {
+                       PMCI_RETURN scheduler_err = PMCI_Remove_Item_To_Specific_Type(DEFINE_PLATFORM, ALARM, alarmId);
+                       if (scheduler_err != PMCI_SUCCESS) {
+                               FW_LOGE("failed in PMCI_Remove_Item_To_Specific_Type");
+                               err = SE_INTERNAL_SCHEDULER_ERROR;
+                               goto error;
+                       }
+               }
+               deleteAccount(*accountId);
+               if(accountId != 0){
+                       free(accountId);
+                       accountId = 0;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (profileName)
+               free(profileName);
+
+       if (value)
+               free(value);
+
+       if(accountId != NULL)
+               free(accountId);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_synchronising_profile(char **profileDirName)
+{
+       FW_LOGV("start ");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       bool result;
+       char *value = NULL;
+       int *account_list = 0;
+       int account_list_count = 0;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+
+       int i;
+       for (i = 0; i < account_list_count; i++) {
+               result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, &value);
+               if (result == false) {
+                       FW_LOGE("failed in set_Config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               if (strcmp(value, "1") == 0) {
+                       result = get_config(account_list[i], DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profileDirName);
+                       if (result == false) {
+                               FW_LOGE("failed in get_Config");
+                               err = SE_INTERNAL_DA_ERROR;
+                               goto error;
+                       }
+                       break;
+               }
+
+               free(value);
+               value = NULL;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       if (value != NULL)
+               free(value);
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+
+bool add_profile_calllog(int *accountId)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       DCI_RETURN dci_err = DCI_SUCCESS;
+       bool result;
+       sync_category *category = NULL;
+       char *id = NULL;
+       char *password  = NULL;
+       int account = -1;
+
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       /* FIXME  get id from somewhere */
+       /*get IMEI from Platform */
+       id = "pcwds@samsung.com";
+
+       dci_err = DCI_Get_DevInfo(DEFINE_PLATFORM, "DevID", &password);
+       if (dci_err != DCI_SUCCESS) {
+               FW_LOGE("failed to get devinfo");
+               goto error;
+       }
+
+       err = __add_profile(DEFINE_CALLLOG_SERVER_URL_HTTPS, id, password, "CALLLOG", &account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       err = __set_config_default_value(account);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in add_Account");
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, DEFINE_CALLLOG_SERVER_URL_HTTPS, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_str(account, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, DEFINE_CALLLOG_DEFAULT_NEXT_NONCE, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       category = (sync_category *)calloc(1, sizeof(sync_category));
+
+       category->enabled = 1;
+       category->srcURI = DEFINE_SOURCE_CALLLOG_URI;
+       category->tgtURI = "./CallLog";
+
+       err = __set_profile_category(account, TYPE_CALLLOG, category);
+       if (err  != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_profile_category");
+               goto error;
+       }
+
+       *accountId = account;
+
+       FW_LOGV("end");
+
+error:
+
+       if(category != NULL)
+               free(category);
+
+       if(password != NULL)
+               free(password);
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool delete_profile_calllog()
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       int count;
+       int *accountid_list = 0;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Open_Agent");
+               goto error;
+       }
+
+       /*delete account */
+       accountid_list = DACI_Get_Account_Id_List_By_Access_Name("CALLLOG", &count);
+       FW_LOGV("count = %d", count);
+
+       int i;
+       for (i = 0; i <count; i++){
+               FW_LOGV("accountId = %d", accountid_list[i]);
+               deleteAccount(accountid_list[i]);
+       }
+
+       DACI_Close_Agent();
+
+       FW_LOGV("end");
+
+error:
+
+       if (accountid_list != NULL)
+               free(accountid_list);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool delete_profile(char *access_name)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       int count;
+       int *accountid_list = 0;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Open_Agent");
+               goto error;
+       }
+
+       /*delete account */
+       accountid_list = DACI_Get_Account_Id_List_By_Access_Name(access_name, &count);
+       FW_LOGV("count = %d", count);
+
+       int i;
+       for (i = 0; i <count; i++){
+               FW_LOGV("accountId = %d", accountid_list[i]);
+               deleteAccount(accountid_list[i]);
+       }
+
+       DACI_Close_Agent();
+
+       FW_LOGV("end");
+
+error:
+
+       if (accountid_list != NULL)
+               free(accountid_list);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
diff --git a/src/ServiceEngine/SE_AutoConfig.c b/src/ServiceEngine/SE_AutoConfig.c
new file mode 100644 (file)
index 0000000..d28af79
--- /dev/null
@@ -0,0 +1,218 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_AutoConfig.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of auto configure in Service Engine
+ */
+
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceEngine/SE_AutoConfig.h"
+#include "ServiceEngine/SE_Common.h"
+#include "ServiceEngine/SE_Error.h"
+#include "ServiceEngine/SE_Sync.h"
+#include "ServiceEngine/SE_Notification.h"
+#include "Common/Common_Vconf.h"
+#include "Common/Common_Define.h"
+#include "ServiceAdapter/SA_Common_Interface.h"
+
+#define LOG_TAG        "OMA_DS_SE"
+
+bool autoconfigure_from_vconf(char *profile)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char profilePath[128];
+       char *email = NULL;
+       char *password = NULL;
+       char *serverIP = NULL;
+
+       SyncProgress process = PROGRESS_NONE;
+       SyncError error = ERROR_NONE ;
+
+       if (!profile) {
+               FW_LOGE("Not Defined profile");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto free;
+       }
+
+       sprintf(profilePath, "%s/%s", DS_SETTINGS_PATH, profile);
+
+       email = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHNAME);
+       if (email == NULL) {
+               FW_LOGE("email is NULL");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       password = get_vconf_str(profilePath, DS_SETTING_CLIENT_AUTHPWD);
+       if (password == NULL) {
+               FW_LOGE("password is NULL");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       serverIP = get_vconf_str(profilePath, DS_SETTING_ADDR);
+       if (serverIP == NULL) {
+               FW_LOGE("serverIP is NULL");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       GList *configure = NULL;
+       Common_ErrorType common_err = auto_configure_from_vconf(email, password, serverIP, profilePath, &configure);
+
+       if (common_err != COMMON_CANCEL) {
+
+               convert_common_errorcode(common_err, &process, &error);
+
+               if (common_err == COMMON_OK) {
+                       err = send_noti_auto_configure(profile, configure);
+                       if (err  != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in send_noti_auto_configure");
+                               goto error;
+                       }
+               } else
+                       err = SE_INTERNAL_SA_ERROR;
+
+               err = session_process(profile, process, error);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in send_noti_auto_configure");
+                       goto error;
+               }
+       } else
+               err = SE_INTERNAL_CANCEL;
+
+       FW_LOGV("end");
+
+       goto free;
+
+error:
+
+       convert_engine_errorcode(err, &process, &error);
+       session_process(profile, process, error);
+
+free:
+
+       if (email)
+               free(email);
+       if (password)
+               free(password);
+       if (serverIP)
+               free(serverIP);
+
+       GList *iter = NULL;
+       GList *inIter = NULL;
+       for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
+
+               inIter = iter->data;
+               for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter))
+                       free(inIter->data);
+               g_list_free(inIter);
+       }
+
+       g_list_free(configure);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool autoconfigure(char *profildDirName, char *addr, char *id, char *password)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       SyncProgress process = PROGRESS_NONE;
+       SyncError error = ERROR_NONE ;
+
+       GList *configure = NULL;
+       GList *iter = NULL;
+       GList *inIter = NULL;
+
+       Common_ErrorType common_err = auto_configure(addr, id, password, &configure);
+
+       if (common_err != COMMON_CANCEL) {
+
+               convert_common_errorcode(common_err, &process, &error);
+
+               if (common_err == COMMON_OK) {
+                       err = send_noti_auto_configure(profildDirName, configure);
+                       if (err  != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in send_noti_auto_configure");
+                               goto error;
+                       }
+               } else
+                       err = SE_INTERNAL_SA_ERROR;
+
+               err = session_process(profildDirName, process, error);
+               if (err  != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in send_noti_auto_configure");
+                       goto error;
+               }
+       } else
+               err = SE_INTERNAL_CANCEL;
+
+       FW_LOGV("end");
+
+       goto free;
+
+error:
+
+       convert_engine_errorcode(err, &process, &error);
+       session_process(profildDirName, process, error);
+
+free:
+
+       for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
+
+               inIter = iter->data;
+               for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter))
+                       free(inIter->data);
+               g_list_free(inIter);
+       }
+
+       g_list_free(configure);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
diff --git a/src/ServiceEngine/SE_Notification.c b/src/ServiceEngine/SE_Notification.c
new file mode 100644 (file)
index 0000000..6ef78a7
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Notification.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of notify to ui
+ */
+
+#include "agent-framework/Event/Event_Handler.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "ServiceEngine/SE_Notification.h"
+#include "ServiceEngine/SE_Sync.h"
+
+#define LOG_TAG        "OMA_DS_SE"
+
+#define NOTI_KEY       "OMADS"
+
+SE_ErrorType send_noti_auto_configure(char *profileDirName, GList *configure)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       if (!profileDirName) {
+               FW_LOGE("Not Defined profileDirName");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       int notiType = 1;
+       Event_Data *noti = create_Noti(notiType);
+       if (noti == NULL) {
+               FW_LOGE("failed to create_Noti");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       append_eventdata_param(noti, STRING, (void *)profileDirName);
+
+       GList *iter = NULL;
+       GList *inIter = NULL;
+       char *config = NULL;
+       int count;
+       for (iter = configure; iter != NULL; iter = g_list_next(iter)) {
+
+               inIter = iter->data;
+               count = g_list_length(inIter);
+               FW_LOGV("count =%d", count);
+               append_eventdata_param(noti, INTEGER, &count);
+
+               for (inIter = iter->data; inIter != NULL; inIter = g_list_next(inIter)) {
+                       config = inIter->data;
+                       FW_LOGV("config = %s", config);
+                       append_eventdata_param(noti, STRING, (void *)config);
+               }
+       }
+
+       EVENT_ERROR event_err;
+       send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
+
+       if (event_err != EVENT_SUCCESS) {
+               FW_LOGE("failed to send_Noti");
+               err = SE_INTERNAL_EVENT_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+SE_ErrorType send_noti_sync_status(char *profileDirName)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       int notiType = 2;
+       Event_Data *noti = create_Noti(notiType);
+       if (noti == NULL) {
+               FW_LOGE("failed to create_Noti");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       FW_LOGV("synchronising profile is : %s", profileDirName);
+
+       append_eventdata_param(noti, STRING, (void *)profileDirName);
+
+       EVENT_ERROR event_err;
+       send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
+
+       if (event_err != EVENT_SUCCESS) {
+               FW_LOGE("failed to send_Noti");
+               err = SE_INTERNAL_EVENT_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+SE_ErrorType send_noti_session_process(char *profile, char *progress, char *error)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       if (!profile) {
+               FW_LOGE("Not Defined profile");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       int notiType = 3;
+       Event_Data *noti = create_Noti(notiType);
+       if (noti == NULL) {
+               FW_LOGE("failed to create_Noti");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       append_eventdata_param(noti, STRING, (void *)profile);
+       append_eventdata_param(noti, STRING, (void *)progress);
+       append_eventdata_param(noti, STRING, (void *)error);
+
+       EVENT_ERROR event_err;
+       send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
+
+       if (event_err != EVENT_SUCCESS) {
+               FW_LOGE("failed to send_Noti");
+               err = SE_INTERNAL_EVENT_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+SE_ErrorType send_noti_process_update(char *profileDirName, char *uri, char *progressStatus,
+                                                                                               char *operationType, int isFromServer, int totalPerOperation,
+                                                                                               int syncedPerOperation, int totalPerDb, int syncedPerDb)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       if (!profileDirName) {
+               FW_LOGE("Not Defined profileDirName");
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       int notiType = 4;
+       Event_Data *noti = create_Noti(notiType);
+       if (noti == NULL) {
+               FW_LOGE("failed to create_Noti");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       append_eventdata_param(noti, STRING, (void *)profileDirName);
+       append_eventdata_param(noti, STRING, (void *)uri);
+       append_eventdata_param(noti, STRING, (void *)progressStatus);
+       append_eventdata_param(noti, STRING, (void *)operationType);
+       append_eventdata_param(noti, INTEGER, &isFromServer);
+       append_eventdata_param(noti, INTEGER, &totalPerOperation);
+       append_eventdata_param(noti, INTEGER, &syncedPerOperation);
+       append_eventdata_param(noti, INTEGER, &totalPerDb);
+       append_eventdata_param(noti, INTEGER, &syncedPerDb);
+
+       EVENT_ERROR event_err;
+       send_Noti(NOTI_KEY, noti, NULL, NULL, &event_err);
+
+       if (event_err != EVENT_SUCCESS) {
+               FW_LOGE("failed to send_Noti");
+               err = SE_INTERNAL_EVENT_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
diff --git a/src/ServiceEngine/SE_Storage.c b/src/ServiceEngine/SE_Storage.c
new file mode 100644 (file)
index 0000000..5d350b1
--- /dev/null
@@ -0,0 +1,746 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Storage.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions which saves and gets sync results
+ */
+
+#include "stdlib.h"
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "Common/Common_Util.h"
+#include "ServiceEngine/SE_Storage.h"
+#include "ServiceEngine/SE_Common.h"
+
+#define LOG_TAG        "OMA_DS_SE"
+
+static SE_ErrorType __write_sync_type(int accountId, AlertType alertType);
+static SE_ErrorType __write_last_session_values(int accountId, SyncSessionResult syncSessionResult, int lastSessionTime);
+
+static SE_ErrorType __write_sync_type(int accountId, AlertType alertType)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       char *syncType = NULL;
+       switch (alertType) {
+       case ALERT_SLOW_SYNC:
+               syncType = DEFINE_ALERT_SLOW_SYNC_STR;
+               break;
+       case ALERT_TWO_WAY:
+               syncType = DEFINE_ALERT_TWO_WAY_STR;
+               break;
+       case ALERT_ONE_WAY_FROM_CLIENT:
+               syncType = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR;
+               break;
+       case ALERT_ONE_WAY_FROM_SERVER:
+               syncType = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR;
+               break;
+       case ALERT_REFRESH_FROM_SERVER:
+               syncType = DEFINE_ALERT_REFRESH_FROM_SERVER_STR;
+               break;
+       case ALERT_REFRESH_FROM_CLIENT:
+               syncType = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR;
+               break;
+       default:
+               break;
+       }
+
+       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+
+}
+
+static SE_ErrorType __write_last_session_values(int accountId, SyncSessionResult syncSessionResult, int lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       result = set_config_int(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, syncSessionResult, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, lastSessionTime, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;;
+}
+
+SE_ErrorType write_profile_data(int accountId, AlertType alertType, SyncSessionResult syncSessionResult, int lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       err = __write_sync_type(accountId, alertType);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in writeSyncType");
+               goto error;
+       }
+
+       err = __write_last_session_values(accountId, syncSessionResult, lastSessionTime);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in writeLastSessionValues");
+               goto error;
+       }
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
+                       err = write_sync_resource_info(accountId, alertType, content_type , lastSessionTime,
+                                       datastoreinfo_per_content_type[content_type]->clientSyncResult, datastoreinfo_per_content_type[content_type]->serverSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in writeSyncResourceInfo");
+                               goto error;
+                       }
+
+                       err = write_sync_statistics(accountId, content_type, false, datastoreinfo_per_content_type[content_type]->clientSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in writeSyncStatistics");
+                               goto error;
+                       }
+
+                       err = write_sync_statistics(accountId, content_type, true, datastoreinfo_per_content_type[content_type]->serverSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in writeSyncStatistics");
+                               goto error;
+                       }
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+       return err;
+}
+
+SE_ErrorType write_sync_statistics(int accountId, int content_type, bool isFromServer, SyncResult *pSyncResult)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       bool result;
+       char *datastore = NULL;
+       char *side = NULL;
+       char numberOfChangesPath[128];
+       char addCountPath[128];
+       char replaceCountPath[128];
+       char deleteCountPath[128];
+
+       if (content_type == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (content_type == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (content_type == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (content_type == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       if (isFromServer == true)
+               side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER;
+       else
+               side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT;
+
+       FW_LOGV("pSyncResult->numberOfChange = %d", pSyncResult->numberOfChange);
+       FW_LOGV("pSyncResult->add_count = %d", pSyncResult->add_count);
+       FW_LOGV("pSyncResult->replace_count = %d", pSyncResult->replace_count);
+       FW_LOGV("pSyncResult->delete_count = %d", pSyncResult->delete_count);
+
+       sprintf(numberOfChangesPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(addCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(replaceCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+       sprintf(deleteCountPath, "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+
+       result = set_config_int(accountId, numberOfChangesPath, pSyncResult->numberOfChange, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, addCountPath, pSyncResult->add_count, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, replaceCountPath, pSyncResult->replace_count, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, deleteCountPath, pSyncResult->delete_count, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+
+}
+
+SE_ErrorType write_sync_resource_info(int accountId, AlertType alertType, int content_type , int lastSessionTime,
+                                                                                                                       SyncResult *clientSyncResult, SyncResult *serverSyncResult)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *datastore = NULL;
+       char dbSyncedPath[128];
+       char lastSessionTimePath[128];
+
+       if (content_type == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (content_type == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (content_type == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (content_type == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       FW_LOGV("clientSyncResult->sessionResult = %d", clientSyncResult->sessionResult);
+       FW_LOGV("serverSyncResult->sessionResult = %d", serverSyncResult->sessionResult);
+
+       char *dbSynced;
+       if (clientSyncResult->sessionResult == SYNC_SESSION_SUCCEEDED  &&
+                       (serverSyncResult->sessionResult == SYNC_SESSION_SUCCEEDED ||  alertType == ALERT_ONE_WAY_FROM_CLIENT || alertType == ALERT_REFRESH_FROM_CLIENT))
+               dbSynced = DEFINE_DBSYNC_SUCCESS;
+       else if (clientSyncResult->sessionResult == SYNC_SESSION_STOPPED)
+               dbSynced = DEFINE_DBSYNC_STOP;
+       else
+               dbSynced = DEFINE_DBSYNC_FAIL;
+
+       FW_LOGV("dbSynced = %s", dbSynced);
+
+       sprintf(dbSyncedPath, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
+       sprintf(lastSessionTimePath, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
+
+       result = set_config_str(accountId, dbSyncedPath, dbSynced, "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = set_config_int(accountId, lastSessionTimePath, lastSessionTime, "int", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+bool get_profile_name(int accountId, char **profileName)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_NAME, profileName);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_profile_server_info(int accountId, char **addr, char **id, char **password)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       *id = DACI_Get_Account_Email_Address(accountId);
+       if (*id == NULL) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       *password = DACI_Get_Account_Password(accountId);
+       if (*password == NULL) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_profile_sync_mode(int accountId, char **syncMode, char **syncType, char **interval)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *tempSyncType = NULL;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, syncMode);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, syncType);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (tempSyncType != NULL)
+               free(tempSyncType);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_profile_sync_category(int accountId, int contentType, int *enabled, char **srcURI, char **tgtURI, char **id, char **password)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *datastore = NULL;
+       char *enabled_str = NULL;
+
+       char datastore_source[128];
+       char datastore_target[128];
+       char datastore_id[128];
+       char datastore_pw[128];
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (contentType == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       result = get_config(accountId, datastore, &enabled_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *enabled = atoi(enabled_str);
+
+       sprintf(datastore_source, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(datastore_target, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(datastore_id, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(datastore_pw, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       result = get_config(accountId, datastore_source, srcURI);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, datastore_target, tgtURI);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, datastore_id, id);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, datastore_pw, password);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (enabled_str != NULL)
+               free(enabled_str);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+
+}
+
+bool get_last_session_info(int accountId, int *lastSessionStatus, int *lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *lastSessionStatus_str = NULL;
+       char *lastSessionTime_str = NULL;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, &lastSessionStatus_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, &lastSessionTime_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       *lastSessionStatus = atoi(lastSessionStatus_str);
+       *lastSessionTime = atoi(lastSessionTime_str);
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (lastSessionStatus_str != NULL)
+               free(lastSessionStatus_str);
+
+       if (lastSessionTime_str != NULL)
+               free(lastSessionTime_str);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+bool get_profile_statistics(int accountId, int contentType, char **dbSynced, int *lastSessionTime,
+               int *server2Client_Total, int *server2Client_NrOfAdd, int *server2Client_NrOfDelete, int *server2Client_NrOfReplace,
+               int *client2Server_Total, int *client2Server_NrOfAdd, int *client2Server_NrOfDelete, int *client2Server_NrOfReplace)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       char *datastore = NULL;
+       char datastore_dbsynced[128];
+       char datastore_lastsessiontime[128];
+       char datastore_s2c_total[128];
+       char datastore_s2c_add[128];
+       char datastore_s2c_replace[128];
+       char datastore_s2c_delete[128];
+       char datastore_c2s_total[128];
+       char datastore_c2s_add[128];
+       char datastore_c2s_replace[128];
+       char datastore_c2s_delete[128];
+
+       char *lastSessionTime_str = NULL;
+       char *server2Client_Total_str = NULL;
+       char *server2Client_NrOfAdd_str = NULL;
+       char *server2Client_NrOfDelete_str = NULL;
+       char *server2Client_NrOfReplace_str = NULL;
+       char *client2Server_Total_str = NULL;
+       char *client2Server_NrOfAdd_str = NULL;
+       char *client2Server_NrOfDelete_str = NULL;
+       char *client2Server_NrOfReplace_str = NULL;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       if (contentType == TYPE_CONTACT)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+       else if (contentType == TYPE_CALENDAR)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+       else if (contentType == TYPE_MEMO)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+       else if (contentType == TYPE_CALLLOG)
+               datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+
+       sprintf(datastore_dbsynced, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED);
+       sprintf(datastore_lastsessiontime, "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME);
+       sprintf(datastore_s2c_total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(datastore_s2c_add, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(datastore_s2c_delete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+       sprintf(datastore_s2c_replace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+
+
+       sprintf(datastore_c2s_total, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL);
+       sprintf(datastore_c2s_add, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD);
+       sprintf(datastore_c2s_delete, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE);
+       sprintf(datastore_c2s_replace, "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE);
+
+       result = get_config(accountId, datastore_dbsynced, dbSynced);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, datastore_lastsessiontime, &lastSessionTime_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *lastSessionTime = atoi(lastSessionTime_str);
+
+       result = get_config(accountId, datastore_s2c_total, &server2Client_Total_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *server2Client_Total = atoi(server2Client_Total_str);
+
+       result = get_config(accountId, datastore_s2c_add, &server2Client_NrOfAdd_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *server2Client_NrOfAdd = atoi(server2Client_NrOfAdd_str);
+
+       result = get_config(accountId, datastore_s2c_delete, &server2Client_NrOfDelete_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *server2Client_NrOfDelete = atoi(server2Client_NrOfDelete_str);
+
+       result = get_config(accountId, datastore_s2c_replace, &server2Client_NrOfReplace_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *server2Client_NrOfReplace = atoi(server2Client_NrOfReplace_str);
+
+       result = get_config(accountId, datastore_c2s_total, &client2Server_Total_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *client2Server_Total = atoi(client2Server_Total_str);
+
+       result = get_config(accountId, datastore_c2s_add, &client2Server_NrOfAdd_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *client2Server_NrOfAdd = atoi(client2Server_NrOfAdd_str);
+
+       result = get_config(accountId, datastore_c2s_delete, &client2Server_NrOfDelete_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *client2Server_NrOfDelete = atoi(client2Server_NrOfDelete_str);
+
+       result = get_config(accountId, datastore_c2s_replace, &client2Server_NrOfReplace_str);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+       *client2Server_NrOfReplace = atoi(client2Server_NrOfReplace_str);
+
+       FW_LOGV("end");
+
+error:
+
+       DACI_Close_Agent();
+
+       if (lastSessionTime_str != NULL)
+               free(lastSessionTime_str);
+
+       if (server2Client_Total_str != NULL)
+               free(server2Client_Total_str);
+
+       if (server2Client_NrOfAdd_str != NULL)
+               free(server2Client_NrOfAdd_str);
+
+       if (server2Client_NrOfDelete_str != NULL)
+               free(server2Client_NrOfDelete_str);
+
+       if (server2Client_NrOfReplace_str != NULL)
+               free(server2Client_NrOfReplace_str);
+
+       if (client2Server_Total_str != NULL)
+               free(client2Server_Total_str);
+
+       if (client2Server_NrOfAdd_str != NULL)
+               free(client2Server_NrOfAdd_str);
+
+       if (client2Server_NrOfDelete_str != NULL)
+               free(client2Server_NrOfDelete_str);
+
+       if (client2Server_NrOfReplace_str != NULL)
+               free(client2Server_NrOfReplace_str);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
diff --git a/src/ServiceEngine/SE_Sync.c b/src/ServiceEngine/SE_Sync.c
new file mode 100644 (file)
index 0000000..7ca7eb3
--- /dev/null
@@ -0,0 +1,2567 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @SE_Sync.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of functions which process sync request, auto configure etc..
+ */
+
+
+#include <sys/time.h>
+#include "agent-framework/DACI/DACI_Agent_Handler_Manager.h"
+#include "agent-framework/DACI/DACI_Agent_Mgr.h"
+#include "agent-framework/DACI/DACI_Service.h"
+#include "agent-framework/DACI/DACI_Luid.h"
+#include "agent-framework/DACI/DACI_ChangeLog.h"
+#include "agent-framework/SyncAgent_Info.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/EngineController/task_process.h"
+#include "agent-framework/Utility/fw_time.h"
+#include "agent-framework/Device/EXT_DCI_DevExecutor.h"
+#include "ServiceEngine/SE_Sync.h"
+#include "ServiceEngine/SE_Storage.h"
+#include "ServiceEngine/SE_Common.h"
+#include "ServiceEngine/SE_Notification.h"
+#include "ServiceAdapter/SA_Common_Interface.h"
+#include "Common/Common_Util.h"
+#include "Common/Common_Define_Internal.h"
+
+
+#define LOG_TAG        "OMA_DS_SE"
+
+static SE_ErrorType __session_process(int accountId, SyncProgress process, SyncError error);
+static SE_ErrorType __process_update(int accountId, SyncProgressStatus progressStatus,
+               OperationType operationType, int content_type, bool isFromServer, bool needToSave, SyncResult *syncResult);
+static SE_ErrorType __write_sync_data(int accountId, AlertType alertType, SyncSessionResult syncSessionResult, int lastSessionTime);
+static SE_ErrorType __write_sync_resource_info(int accountId,  AlertType alertType, int content_type, int lastSessionTime);
+
+static SE_ErrorType __init_datastore_info_array(int accountId);
+static SE_ErrorType __set_datastore_info_array(int accountId, char *config_key, CONTENT_TYPE content_type);
+static SE_ErrorType __generate_datastore_info(int accountId,  CONTENT_TYPE content_type, Datastore **pDatastore);
+static SE_ErrorType __init_datastore_info(int accountId,  CONTENT_TYPE content_type, Datastore **pDatastore);
+static SE_ErrorType __set_datastore_config(int accountId, int content_type, Datastore **pDatastore);
+
+static SE_ErrorType __on_synchronising_account(int accountId);
+static SE_ErrorType __off_synchronising_account(int accountId);
+
+static SE_ErrorType __assemble_changeddatastores(int accountId, SyncObj **pSyncObj);
+static SE_ErrorType __prepare_pre_sync(int accountId, char *syncMode, SanPackage *pSanPackage);
+static SE_ErrorType __set_config_based_on_syncMode(int accountId, char *syncMode, SanPackage *pSanPackage);
+static SE_ErrorType __execute_pre_sync(int accountId, PreSyncReturnObj *pPreSyncReturnObj, int sessionTime);
+static SE_ErrorType __execute_pre_sync_set_server_id(int accountId, char *devID);
+static SE_ErrorType __execute_pre_sync_datastore(int accountId, GList *datastoreInfo, int sessionTime);
+static SE_ErrorType __execute_sync(int accountId, SyncObj **pSyncObj, SyncReturnObj **SyncReturnObj);
+static SE_ErrorType __execute_sync_arrange_changelog(int accountId, GList *status);
+static SE_ErrorType __execute_sync_status(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj);
+static SE_ErrorType __execute_sync_change(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj);
+static SE_ErrorType __update_sync_result(int accountId);
+
+static CommandResult __convert_return_status(DACI_RETURN da_err);
+static char *__convert_cttype(int itemTypeId);
+static int __convert_synctype_value(char *syncType_str);
+
+static inline long myclock()
+{
+       struct timeval tv;
+       gettimeofday(&tv, 0);
+       return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
+}
+
+static SE_ErrorType __session_process(int accountId, SyncProgress process, SyncError error)
+{
+       FW_LOGV("start");
+
+       char *profileDirName = NULL;
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       if (profileDirName != NULL ){
+               err = session_process(profileDirName, process, error);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed to send noti");
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+       if (profileDirName)
+               free(profileDirName);
+
+       return err;
+}
+
+static SE_ErrorType __process_update(int accountId, SyncProgressStatus progressStatus,
+               OperationType operationType, int content_type, bool isFromServer, bool needToSave, SyncResult *syncResult)
+{
+       FW_LOGV("start with accountId =%d, progressStatus = %d, operationType = %d, content_type = %d, isFromServer = %d, needToSave = %d ",
+                                       accountId, progressStatus, operationType, content_type, isFromServer, needToSave);
+       FW_LOGV("numberOfChange = %d, received_count = %d,  syncCount = %d" ,
+                       syncResult->numberOfChange, syncResult->received_count, syncResult->add_count + syncResult->replace_count + syncResult->delete_count);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       char *profileDirName = NULL;
+       char *profile = NULL;
+       char *progressStatus_str = NULL;
+       char *operationType_str = NULL;
+       char *uri = NULL;
+
+       bool result;
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       /* do not need to send update noti to ui */
+       if(profileDirName == NULL){
+               FW_LOGV("profileDirName is NULL");
+               goto error;
+       }
+
+       if (needToSave == true) {
+               err = write_sync_statistics(accountId, content_type, isFromServer, syncResult);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in writeSyncStatistics");
+                       goto error;
+               }
+
+               syncResult->sessionResult = SYNC_SESSION_SUCCEEDED;
+       }
+
+       char *progress = NULL;
+       switch (progressStatus) {
+       case SYNC_PROGRESS_NONE:
+               progress = DEFINE_PROGRESS_NONE;
+               break;
+       case SYNC_PROGRESS_SUCCESS:
+               progress = DEFINE_PROGRESS_SUCCESS;
+               break;
+       case SYNC_FAILED_DB:
+               progress = DEFINE_FAILED_DB;
+               break;
+       case SYNC_FAILED_DB_FORBIDDEN:
+               progress = DEFINE_FAILED_DB_FORBIDDEN;
+               break;
+       case SYNC_FAILED_DB_ITEM:
+               progress = DEFINE_FAILED_DB_ITEM;
+               break;
+       case SYNC_FAILED_DB_CONFIG:
+               progress = DEFINE_FAILED_DB_CONFIG;
+               break;
+       case SYNC_FAILED_DB_DEVICEFULL:
+               progress = DEFINE_FAILED_DB_DEVICEFULL;
+               break;
+       default:
+               break;
+       }
+
+       char *operation = NULL;
+       switch (operationType) {
+       case OPERATION_NOOP:
+               operation = DEFINE_NOOP;
+               break;
+       case OPERATION_ADD:
+               operation = DEFINE_ADD;
+               break;
+       case OPERATION_DELETE:
+               operation = DEFINE_DELETE;
+               break;
+       case OPERATION_MOVE:
+               operation = DEFINE_MOVE;
+               break;
+       case OPERATION_COPY:
+               operation = DEFINE_COPY;
+               break;
+       case OPERATION_REPLACE:
+               operation = DEFINE_REPLACE;
+               break;
+       default:
+               break;
+       }
+
+       if (progress == NULL || operation == NULL) {
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (profileDirName != NULL)
+               profile = strdup(profileDirName);
+
+       progressStatus_str = strdup(progress);
+       operationType_str = strdup(operation);
+
+       if (datastoreinfo_per_content_type[content_type]->source != NULL)
+               uri = strdup(datastoreinfo_per_content_type[content_type]->source);
+
+       err = send_noti_process_update(profile, uri , progressStatus_str, operationType_str,
+                       isFromServer, 0, 0, syncResult->numberOfChange,
+                       syncResult->add_count + syncResult->replace_count + syncResult->delete_count);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in send_noti_process_update");
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       if (profileDirName != NULL)
+               free(profileDirName);
+
+       if (profile != NULL)
+               free(profile);
+
+       if (progressStatus_str != NULL)
+               free(progressStatus_str);
+
+       if (operationType_str != NULL)
+               free(operationType_str);
+
+       if (uri != NULL)
+               free(uri);
+
+       return err;
+}
+
+static SE_ErrorType __write_sync_data(int accountId, AlertType alertType, SyncSessionResult syncSessionResult, int lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       err = write_profile_data(accountId, alertType, syncSessionResult,  lastSessionTime);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in writeProfileData");
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+
+static SE_ErrorType __write_sync_resource_info(int accountId,  AlertType alertType, int content_type , int lastSessionTime)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       err = write_sync_resource_info(accountId, alertType, content_type , lastSessionTime,
+                       datastoreinfo_per_content_type[content_type]->clientSyncResult, datastoreinfo_per_content_type[content_type]->serverSyncResult);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in write_sync_resource_info");
+               goto error;
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+static SE_ErrorType __init_datastore_info_array(int accountId)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       err = __set_datastore_info_array(accountId, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS, TYPE_CONTACT);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastoreinfo_array");
+               goto error;
+       }
+
+       err = __set_datastore_info_array(accountId, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR, TYPE_CALENDAR);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastoreinfo_array");
+               goto error;
+       }
+
+       err = __set_datastore_info_array(accountId, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO, TYPE_MEMO);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastoreinfo_array");
+               goto error;
+       }
+
+       err = __set_datastore_info_array(accountId, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG, TYPE_CALLLOG);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastoreinfo_array");
+               goto error;
+       }
+
+
+       FW_LOGV("end");
+
+error:
+
+       return err;
+}
+
+static SE_ErrorType __set_datastore_info_array(int accountId, char *config_key, CONTENT_TYPE content_type)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       Datastore *pDatastoreInfo = NULL;
+       bool result;
+       char *value = NULL;
+
+       result = get_config(accountId, config_key, &value);
+       if (result == true) {
+               if (strcmp(value, "1") == 0)
+                       err = __generate_datastore_info(accountId, content_type, &pDatastoreInfo);
+               else
+                       err = __init_datastore_info(accountId, content_type, &pDatastoreInfo);
+       } else
+               err = __init_datastore_info(accountId, content_type , &pDatastoreInfo);
+
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed to create or init datastore_info");
+               goto error;
+       }
+
+       datastoreinfo_per_content_type[content_type] = pDatastoreInfo;
+
+       FW_LOGV("end");
+
+error:
+
+       if (value)
+               free(value);
+
+       return err;
+}
+
+static SE_ErrorType __generate_datastore_info(int accountId,  CONTENT_TYPE content_type , Datastore **pDatastore)
+{
+       FW_LOGV("start content_type=[%d]\n",  content_type);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       char *clientLastAnchor = NULL;
+       char *clientNextAnchor = NULL;
+       char *serverLastAnchor = NULL;
+
+       daci_last_anchor *last_anchor_info  = NULL;
+       DACI_RETURN da_err;
+
+       SyncResult *pSyncResult = NULL;
+       Datastore *datastore = NULL;
+       err = __set_datastore_config(accountId, content_type, &datastore);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_datastore_config");
+               goto error;
+       }
+
+       /* Must get anchor per datastore for synchronization (contact, calendar, memo)
+        *              daci_last_anchor *DACI_Get_Last_Anchor_By_Account_Id(int account_id, int *count);
+        * */
+       int count = 0;
+       last_anchor_info = DACI_Get_Last_Anchor_By_Item_Type_Id(accountId, datastore->datastore_id, &count);
+
+       if (last_anchor_info != NULL) {
+               clientLastAnchor = last_anchor_info[0].last_anchor_client;
+               serverLastAnchor = last_anchor_info[0].last_anchor_server;
+       } else{
+               daci_last_anchor lastAnchor_daci;
+
+               lastAnchor_daci.account_id = accountId;
+               lastAnchor_daci.data_store_id = datastore->datastore_id;
+               lastAnchor_daci.last_anchor_server = NULL;
+               lastAnchor_daci.last_anchor_client = NULL;
+               lastAnchor_daci.access_name = "Engine";
+
+               da_err = DACI_Add_Last_Anchor(&lastAnchor_daci);
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("DACI_Add_Last_Anchor is failed %d", da_err);
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+
+       clientNextAnchor = g_strdup_printf("%ld", time(NULL));
+
+       FW_LOGV("clientLastAnchor = %s\n",  clientLastAnchor);
+       FW_LOGV("serverLastAnchor = %s\n",  serverLastAnchor);
+       FW_LOGV("clientNextAnchor = %s\n",  clientNextAnchor);
+
+       /*slow sync if managed anchor info not exist.. (first sync)*/
+       if (clientLastAnchor == NULL)
+               set_datastore_client_anchor(datastore, clientNextAnchor, clientNextAnchor);
+       else
+               set_datastore_client_anchor(datastore, clientLastAnchor, clientNextAnchor);
+
+       set_datastore_server_anchor(datastore, serverLastAnchor, NULL);
+
+       pSyncResult = create_sync_result();
+       if (pSyncResult == NULL) {
+               FW_LOGE("create_syncResult is failed");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+       datastore->clientSyncResult = pSyncResult;
+
+       pSyncResult = create_sync_result();
+       if (pSyncResult == NULL) {
+               FW_LOGE("create_syncResult is failed");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+       datastore->serverSyncResult  = pSyncResult;
+
+       *pDatastore = datastore;
+
+       FW_LOGV("end");
+
+error:
+
+       if (clientNextAnchor  != NULL)
+               free(clientNextAnchor);
+
+       if (last_anchor_info != NULL)
+               DACI_Free_Memory_Last_Anchor(last_anchor_info, count);
+
+       if (err != SE_INTERNAL_OK) {
+               if (datastore != NULL) {
+                       free_datastore(datastore);
+                       datastore = NULL;
+               }
+       }
+
+       return err;
+}
+
+static SE_ErrorType __init_datastore_info(int accountId,  CONTENT_TYPE content_type ,  Datastore **pDatastore)
+{
+       FW_LOGV("start");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       char *sourceDatastore = NULL;
+       char key[128];
+       Datastore *datastore = NULL;
+       SyncResult *pSyncResult = NULL;
+
+       bool result;
+       switch (content_type) {
+               case TYPE_CONTACT:
+                       sprintf(key, "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+                       break;
+               case TYPE_CALENDAR:
+                       sprintf(key, "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+                       break;
+               case TYPE_MEMO:
+                       sprintf(key, "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+                       break;
+               case TYPE_CALLLOG:
+                       sprintf(key, "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+                       break;
+               default:
+                       FW_LOGV("unknown content type = %d", content_type);
+                       goto error;
+       }
+
+       result = get_config(accountId, key, &sourceDatastore);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       datastore = create_datastore(NULL, sourceDatastore);
+       if (datastore == NULL) {
+               FW_LOGE("failed to create_Datastore");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       pSyncResult = create_sync_result();
+       if (pSyncResult == NULL) {
+               FW_LOGE("create_syncResult is failed");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+       datastore->clientSyncResult = pSyncResult;
+
+       pSyncResult = create_sync_result();
+       if (pSyncResult == NULL) {
+               FW_LOGE("create_syncResult is failed");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+       datastore->serverSyncResult  = pSyncResult;
+
+       *pDatastore = datastore;
+
+       FW_LOGV("end");
+
+error:
+       if (sourceDatastore != NULL)
+               free(sourceDatastore);
+
+       if (err != SE_INTERNAL_OK) {
+               if (datastore != NULL) {
+                       free_datastore(datastore);
+                       datastore = NULL;
+               }
+       }
+
+       return err;
+}
+
+static SE_ErrorType __set_datastore_config(int accountId, int content_type, Datastore **pDatastore)
+{
+       FW_LOGV("start");
+
+       Datastore *datastore = NULL;
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char *contentType = NULL;
+
+       char sourceDatastore_key[128];
+       char targetDatastore_key[128];
+       char id_key[128];
+       char pw_key[128];
+
+       char *sourceDatastore = NULL;
+       char *targetDatastore = NULL;
+       char *sync_type = NULL;
+       char *id = NULL;
+       char *pw = NULL;
+
+       int folder_type_id = 0;
+       switch (content_type) {
+               case TYPE_CONTACT:
+               {
+                       folder_type_id = 0;
+                       contentType = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS;
+               }
+                       break;
+               case TYPE_CALENDAR:
+               {
+                       folder_type_id = 0;
+                       contentType = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR;
+               }
+                       break;
+               case TYPE_MEMO:
+               {
+                       folder_type_id = 0;
+                       contentType = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO;
+               }
+                       break;
+               case TYPE_CALLLOG:
+               {
+                       folder_type_id = 0;
+                       contentType = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG;
+               }
+                       break;
+               default:
+                       FW_LOGV("unknown content type = %d", content_type);
+                       err = SE_INTERNAL_ERROR;
+                       goto error;
+       }
+
+       sprintf(sourceDatastore_key, "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE);
+       sprintf(targetDatastore_key, "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET);
+       sprintf(id_key, "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID);
+       sprintf(pw_key, "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD);
+
+       bool result;
+       result = get_config(accountId, sourceDatastore_key, &sourceDatastore);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, targetDatastore_key, &targetDatastore);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNC_TYPE, &sync_type);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       syncType = __convert_synctype_value(sync_type);
+
+       result = get_config(accountId, id_key, &id);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       result = get_config(accountId, pw_key, &pw);
+       if (result == false) {
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("get_Config result  sourceDatastore= %s ",  sourceDatastore);
+       FW_LOGV("get_Config result  targetDatastore= %s ",  targetDatastore);
+       FW_LOGV("get_Config result  alertType= %s ",  sync_type);
+       FW_LOGV("get_Config result  id= %s ",  id);
+       FW_LOGV("get_Config result  pw= %s ",  pw);
+
+       datastore = create_datastore(targetDatastore, sourceDatastore);
+       if (datastore == NULL) {
+               FW_LOGE("datastore is NULL");
+               goto error;
+       }
+
+       set_datastore_contenttype_info(datastore, content_type, folder_type_id);
+       set_datastore_account_info(datastore, id, pw);
+       set_datastore_client_sync_type(datastore, syncType);
+
+       *pDatastore = datastore;
+
+       FW_LOGV("End");
+
+error:
+
+       if (sourceDatastore != NULL)
+               free(sourceDatastore);
+
+       if (targetDatastore != NULL)
+               free(targetDatastore);
+
+       if (sync_type != NULL)
+               free(sync_type);
+
+       if (id != NULL)
+               free(id);
+
+       if (pw != NULL)
+               free(pw);
+
+       if (err != SE_INTERNAL_OK) {
+               if (datastore != NULL) {
+                       free_datastore(datastore);
+                       datastore = NULL;
+               }
+       }
+
+       return err;
+}
+
+static SE_ErrorType __on_synchronising_account(int accountId)
+{
+       FW_LOGV("start ");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       bool result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, "1", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end ");
+       return err;
+
+error:
+
+       FW_LOGE("Error :%d ", err);
+       return err;
+}
+
+static SE_ErrorType __off_synchronising_account(int accountId)
+{
+       FW_LOGV("start ");
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       bool result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, "0", "string", "SE");
+       if (result == false) {
+               FW_LOGE("failed in set_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("end ");
+       return err;
+
+error:
+
+       FW_LOGE("Error :%d ", err);
+       return err;
+}
+
+static SE_ErrorType __assemble_changeddatastores(int accountId, SyncObj **pSyncObj)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       ChangedDatastore *pChangedDatastore = NULL;
+       DACI_RETURN da_err = DACI_SUCCESS;
+
+       int content_type;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++)       {
+               int count = 0;
+               if (!datastoreinfo_per_content_type[content_type]->clientSyncType) continue;
+
+               if (datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_SLOW_SYNC
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_CLIENT
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_CLIENT_BY_SERVER) {
+
+                       if( content_type == TYPE_CALLLOG ){
+                               FW_LOGV("refresh_Item_Tbl_From_Service for call log");
+                               refresh_Item_Tbl_From_Service(accountId, datastoreinfo_per_content_type[content_type]->datastore_id);
+                       }
+
+                       /*all item using accountId*/
+                       daci_item *pDaci_item = DACI_Get_item_By_Account_Id(accountId, datastoreinfo_per_content_type[content_type]->datastore_id, &count);
+
+                       pChangedDatastore = create_changeddatastore(datastoreinfo_per_content_type[content_type]->source,
+                                                                                                                                               datastoreinfo_per_content_type[content_type]->target, 1 , count);
+                       if (pChangedDatastore == NULL) {
+                               DACI_Free_Memory_Item(pDaci_item, count);
+                               FW_LOGE("failed in create_ChangedDatastore");
+                               err = SE_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       if (count > 0) {
+                               int i;
+                               for (i = 0; i < count; i++) {
+                                       char *cttype = __convert_cttype(pDaci_item[i].data_store_id);
+                                       ChangedItem *pChanged = create_changeditem(CHANGE_ADD, pDaci_item[i].item_id);
+                                       if (pChanged == NULL) {
+
+                                               DACI_Free_Memory_Item(pDaci_item, count);
+                                               FW_LOGE("failed in create_ChangedDatastore");
+                                               err = SE_INTERNAL_NO_MEMORY;
+                                               goto error;
+                                       }
+
+                                       set_changeditem_contenttype(pChanged, cttype);
+                                       set_changedItem_indexofdatastore(pChanged, content_type);
+
+                                       add_changeddatastore_changeditem(pChangedDatastore, pChanged);
+                               }
+
+                               DACI_Free_Memory_Item(pDaci_item, count);
+                       }
+               } else if (datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_TWO_WAY
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_TWO_WAY_BY_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_ONE_WAY_FROM_CLIENT
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) {
+                       FW_LOGV("server sync type is ALERT_TYPE [%d]",   datastoreinfo_per_content_type[content_type]->serverSyncType);
+
+                       /*from changelog*/
+                       daci_item_info *pDaci_item_info = DACI_Get_Item_Info_By_Item_Type_Id(accountId,
+                                                                                                               datastoreinfo_per_content_type[content_type]->datastore_id, &count);
+
+                       pChangedDatastore = create_changeddatastore(datastoreinfo_per_content_type[content_type]->source,
+                                                                                                               datastoreinfo_per_content_type[content_type]->target, 1, count);
+                       if (pChangedDatastore == NULL) {
+                               DACI_Free_Memory_Item_Info(pDaci_item_info, count);
+                               FW_LOGE("failed in create_ChangedDatastore");
+                               err = SE_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       /*gathering changelog info*/
+                       if (count > 0) {
+                               /*begin agent db transaction*/
+                               DACI_Begin_Transaction();
+
+                               char *cttype = __convert_cttype(datastoreinfo_per_content_type[content_type]->datastore_id);
+
+                               int i;
+                               for (i = 0; i < count; i++) {
+                                       ChangedItem *pChanged = create_changeditem(pDaci_item_info[i].operationId - 300, pDaci_item_info[i].itemId);
+                                       if (pChanged == NULL) {
+                                               DACI_Free_Memory_Item_Info(pDaci_item_info, count);
+                                               DACI_End_Transaction(TRANSACTION_ROLLBACK);
+                                               FW_LOGE("failed in create_ChangedDatastore");
+                                               err = SE_INTERNAL_NO_MEMORY;
+                                               goto error;
+                                       }
+
+                                       set_changeditem_contenttype(pChanged, cttype);
+                                       set_changedItem_indexofdatastore(pChanged, content_type);
+                                       add_changeddatastore_changeditem(pChangedDatastore, pChanged);
+                               }
+
+                               int *itemTypeIdList = (int *)calloc(1, sizeof(int));
+                               itemTypeIdList[0] = datastoreinfo_per_content_type[content_type]->datastore_id;
+
+                               da_err = DACI_Set_Item_Changelog_Wait_Status(accountId, NULL, 0, itemTypeIdList, 1);
+                               DACI_Free_Memory_Item_Info(pDaci_item_info, count);
+                               if (itemTypeIdList != NULL)
+                                       free(itemTypeIdList);
+                               if (da_err != DACI_SUCCESS) {
+                                       DACI_End_Transaction(TRANSACTION_ROLLBACK);
+                                       FW_LOGE("failed in DACI_Set_Item_Changelog_Wait_Status");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               DACI_End_Transaction(TRANSACTION_COMMIT);
+                       }
+               } else if (datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_ONE_WAY_FROM_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_ONE_WAY_FROM_SERVER_BY_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_SERVER_BY_SERVER) {
+                       /*MUST create empty changedDatastore..*/
+                       pChangedDatastore = create_changeddatastore(datastoreinfo_per_content_type[content_type]->source,
+                                                                                                                                                       datastoreinfo_per_content_type[content_type]->target, 1, 0);
+                       if (pChangedDatastore == NULL) {
+                               FW_LOGE("pChangedDatastore is NULL");
+                               err = SE_INTERNAL_NO_MEMORY;
+                               goto error;
+                       }
+
+                       if (datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_SERVER
+                               || datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_REFRESH_FROM_SERVER_BY_SERVER) {
+
+                               /*FW_LOGV("refresh_Item_Tbl_From_Service");
+                               refresh_Item_Tbl_From_Service(accountId, datastoreinfo_per_content_type[content_type]->plugin_type);*/
+
+                               /*  Delete All item (include changelog), before adapting server item data…*/
+                               FW_LOGV("DACI_Service_Begin = %d", datastoreinfo_per_content_type[content_type]->datastore_id);
+                               DACI_Service_Begin(datastoreinfo_per_content_type[content_type]->datastore_id);
+                               DACI_Begin_Transaction();
+
+                               /*delete service item data*/
+                               da_err = DACI_Service_Delete_All_Items(datastoreinfo_per_content_type[content_type]->datastore_id, accountId);
+                               if (da_err != DACI_SUCCESS) {
+
+                                       DACI_Service_End(datastoreinfo_per_content_type[content_type]->datastore_id, 0);
+                                       DACI_End_Transaction(TRANSACTION_ROLLBACK);
+
+                                       FW_LOGE("failed in DACI_Service_Delete_All_Items");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               int item_cnt;
+                               FW_LOGV("DACI_Get_item_By_Account_Id");
+                               /*get all item by account id*/
+                               daci_item *pDaci_item = DACI_Get_item_By_Account_Id(accountId, datastoreinfo_per_content_type[content_type]->datastore_id, &item_cnt);
+                               FW_LOGV("item_cnt = %d", item_cnt);
+
+                               int j;
+                               int acc_cnt;
+                               for (j = 0; j < item_cnt ; j++) {
+                                       daci_item *pDaci_item_from_other_account = DACI_Get_item_Mapping_Service_Id(accountId, pDaci_item[j].item_id, &acc_cnt);
+                                       FW_LOGV("acc_cnt = %d", acc_cnt);
+
+                                       int i;
+                                       for (i = 0; i < acc_cnt; i++)
+                                               ChangeLog_Delete_Item(pDaci_item_from_other_account[i].account_id, pDaci_item_from_other_account[i].item_id,
+                                                                                                                                                                                                                       datastoreinfo_per_content_type[content_type]->datastore_id);
+
+                                       DACI_Free_Memory_Item(pDaci_item_from_other_account, acc_cnt);
+                               }
+
+                               /*delete item from item_tbl*/
+                               FW_LOGV("DACI_Delete_Item_By_Item_Type_Id = %d", datastoreinfo_per_content_type[content_type]->datastore_id);
+                               da_err = DACI_Delete_Item_By_Item_Type_Id(accountId, datastoreinfo_per_content_type[content_type]->datastore_id);
+                               if (da_err != DACI_SUCCESS) {
+
+                                       DACI_Free_Memory_Item(pDaci_item, item_cnt);
+
+                                       DACI_Service_End(datastoreinfo_per_content_type[content_type]->datastore_id, 0);
+                                       DACI_End_Transaction(TRANSACTION_ROLLBACK);
+
+                                       FW_LOGE("failed in DACI_Delete_Item_By_Item_Type_Id");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               /*delete changelog data bu account id*/
+                               FW_LOGV("DACI_Delete_Item_Changelog_By_Item_Type_Id = %d", datastoreinfo_per_content_type[content_type]->datastore_id);
+                               da_err = DACI_Delete_Item_Changelog_By_Item_Type_Id(accountId, datastoreinfo_per_content_type[content_type]->datastore_id);
+                               if (da_err != DACI_SUCCESS) {
+
+                                       DACI_Free_Memory_Item(pDaci_item, item_cnt);
+
+                                       DACI_Service_End(datastoreinfo_per_content_type[content_type]->datastore_id, 0);
+                                       DACI_End_Transaction(TRANSACTION_ROLLBACK);
+
+                                       FW_LOGE("failed in DACI_Delete_Item_Changelog_By_Item_Type_Id");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               FW_LOGV("DACI_Service_End = %d", datastoreinfo_per_content_type[content_type]->datastore_id);
+                               DACI_Service_End(datastoreinfo_per_content_type[content_type]->datastore_id, 1);
+                               DACI_End_Transaction(TRANSACTION_COMMIT);
+
+                               DACI_Free_Memory_Item(pDaci_item, item_cnt);
+                       }
+               }
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
+                       (*pSyncObj)->changedDatastore =  g_list_append((*pSyncObj)->changedDatastore, pChangedDatastore);
+
+                       set_numberofchange(datastoreinfo_per_content_type[content_type]->clientSyncResult, pChangedDatastore->numberOfChanges);
+
+                       OperationType operationType;
+                       if (datastoreinfo_per_content_type[content_type]->clientSyncResult->numberOfChange == 0)
+                               operationType = OPERATION_NOOP;
+                       else
+                               operationType = OPERATION_ADD;
+                       err = __process_update(accountId,  SYNC_PROGRESS_SUCCESS, operationType, content_type, false, false,
+                                                                                                                                                               datastoreinfo_per_content_type[content_type]->clientSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("Failed in process_update");
+                               goto error;
+                       }
+               }
+       }
+
+       FW_LOGV("end");
+
+       return err;
+
+error:
+
+       if (pChangedDatastore != NULL) {
+               free_changeddatastore(pChangedDatastore);
+               pChangedDatastore = NULL;
+       }
+
+       return err;
+}
+
+static SE_ErrorType __prepare_pre_sync(int accountId, char *syncMode, SanPackage *pSanPackage)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       /*set synchronising flag into agent DB*/
+       err =  __on_synchronising_account(accountId);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_synchronising_account");
+               goto error;
+       }
+
+       /*init datastore_info_array*/
+       err = __init_datastore_info_array(accountId);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in init_datastoreInfo_array");
+               goto error;
+       }
+
+       /*set config based on sync mode*/
+       err = __set_config_based_on_syncMode(accountId, syncMode, pSanPackage);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in set_synchronising_account");
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+static SE_ErrorType __set_config_based_on_syncMode(int accountId, char *syncMode, SanPackage *pSanPackage)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       int content_type;
+       bool result;
+
+       if (strcmp(syncMode, DEFINE_SYNC_MODE_MANUAL) != 0) {
+               char *profileDirName = NULL;
+
+               result = get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName);
+               if (result == false) {
+                       FW_LOGE("failed in get_Config");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+
+               if (profileDirName != NULL) {
+                       err = send_noti_sync_status(profileDirName);
+                       if (profileDirName != NULL)
+                               free(profileDirName);
+
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in send_noti_sync_status");
+                               goto error;
+                       }
+               }
+       }
+
+       if (strcmp(syncMode, DEFINE_SYNC_MODE_PUSH) == 0) {
+               if (pSanPackage != NULL) {
+                       int count = pSanPackage->cntSyncAlerts;
+                       FW_LOGV("count = %d", count);
+                       int i;
+                       for (i = 0 ; i < count ; i++) {
+                               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+
+                                       if (datastoreinfo_per_content_type[content_type]->target == NULL) continue;
+
+                                       if (strcmp(pSanPackage->syncAlerts[i].serverURI, datastoreinfo_per_content_type[content_type]->target) == 0) {
+                                               datastoreinfo_per_content_type[content_type]->clientSyncType = pSanPackage->syncAlerts[i].syncType;
+                                               FW_LOGV("pSanPackage->syncAlerts[i].syncType = %d", pSanPackage->syncAlerts[i].syncType);
+                                       } else
+                                               datastoreinfo_per_content_type[content_type]->clientSyncType = ALERT_UNKNOWN;
+
+                               }
+                       }
+               }
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+
+static SE_ErrorType  __execute_pre_sync(int accountId, PreSyncReturnObj *pPreSyncReturnObj, int sessionTime)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       /*if there is no alert command from server check it and goto fail_part*/
+       if (g_list_length(pPreSyncReturnObj->datastoreInfo) == 0) {
+               FW_LOGV("alert command list from server is empty");
+               err = SE_INTERNAL_MISCONFIGURATION;
+               goto error;
+       }
+
+       err = __execute_pre_sync_set_server_id(accountId, pPreSyncReturnObj->devID);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __set_server_id");
+               goto error;
+       }
+
+       err = __execute_pre_sync_datastore(accountId, pPreSyncReturnObj->datastoreInfo, sessionTime);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __process_datastore");
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+
+}
+
+/*FIXME : set Server_id for SAN*/
+static SE_ErrorType __execute_pre_sync_set_server_id(int accountId, char *devID)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       bool result;
+       char *value = NULL;
+       result =  get_config(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &value);
+       if (result == true) {
+               if (value != NULL) {
+                       if (strcmp(value, devID) == 0) {
+                               /* OK*/
+                       } else{
+                               result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, devID, "string", "SE");
+                               if (result == false) {
+                                       FW_LOGE("failed in set_Config");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+                       }
+               } else{
+                       result = set_config_str(accountId, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, devID, "string", "SE");
+                       if (result == false) {
+                               FW_LOGE("failed in set_Config");
+                               err = SE_INTERNAL_DA_ERROR;
+                               goto error;
+                       }
+               }
+       } else{
+               FW_LOGE("failed in get_Config");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+error:
+
+       if (value != NULL) {
+               free(value);
+               value = NULL;
+       }
+       FW_LOGV("end");
+
+       return err;
+}
+
+static SE_ErrorType __execute_pre_sync_datastore(int accountId, GList *datastoreInfo, int sessionTime)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       int content_type;
+       GList *serverDatastore_iter = NULL;
+       DatastoreInfo *serverDatastoreInfo = NULL;
+       bool existInServerDatastore;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               existInServerDatastore =  false;
+
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType) {
+
+                       for (serverDatastore_iter = datastoreInfo; serverDatastore_iter != NULL;  serverDatastore_iter = g_list_next(serverDatastore_iter)) {
+                                       serverDatastoreInfo = serverDatastore_iter->data;
+
+                               if (strcmp(serverDatastoreInfo->source, datastoreinfo_per_content_type[content_type]->target) == 0) {
+                                       existInServerDatastore = true;
+
+                                       datastoreinfo_per_content_type[content_type]->serverSyncType = serverDatastoreInfo->syncType;
+                                       datastoreinfo_per_content_type[content_type]->nextAnchorServer = strdup(serverDatastoreInfo->nextAnchor);
+
+                                       if (datastoreinfo_per_content_type[content_type]->lastAnchorServer) {
+                                               /*if (strcmp(datastoreinfo_per_content_type[content_type]->lastAnchorServer, serverDatastoreInfo->lastAnchor) != 0) {
+                                                       free(datastoreinfo_per_content_type[content_type]->lastAnchorServer);
+                                                       datastoreinfo_per_content_type[content_type]->lastAnchorServer = NULL;
+                                                       datastoreinfo_per_content_type[content_type]->serverSyncType == ALERT_SLOW_SYNC;
+                                               }*/
+                                       } else{
+                                               /* When first synchronize, lastAnchorServer is NULL...
+                                               if (datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_SLOW_SYNC
+                                                                       && datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_REFRESH_FROM_CLIENT
+                                                                       && datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_REFRESH_FROM_CLIENT_BY_SERVER
+                                                                       && datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_REFRESH_FROM_SERVER
+                                                                       && datastoreinfo_per_content_type[content_type]->serverSyncType != ALERT_REFRESH_FROM_SERVER_BY_SERVER) {
+                                                       FW_LOGV("refresh_Item_Tbl_From_Service");
+                                                       refresh_Item_Tbl_From_Service(accountId, datastoreinfo_per_content_type[content_type]->plugin_type);
+                                               }*/
+                                       }
+                                       break;
+                               }
+                       }
+
+                       if (!existInServerDatastore) {
+                               /* datastore config is wrong this datastore is not going to contain sync process from now*/
+                               err = __process_update(accountId,  SYNC_FAILED_DB_CONFIG, OPERATION_NOOP, content_type, false, true,
+                                                                                                               datastoreinfo_per_content_type[content_type]->clientSyncResult);
+                               if (err != SE_INTERNAL_OK) {
+                                       FW_LOGE("failed to process_update");
+                                       goto error;
+                               }
+
+                               err = __process_update(accountId,  SYNC_FAILED_DB_CONFIG, OPERATION_NOOP, content_type, true, true,
+                                                                                                               datastoreinfo_per_content_type[content_type]->serverSyncResult);
+                               if (err != SE_INTERNAL_OK) {
+                                       FW_LOGE("failed to process_update");
+                                       goto error;
+                               }
+
+                               datastoreinfo_per_content_type[content_type]->clientSyncResult->sessionResult = SYNC_SESSION_FAILED;
+                               err = __write_sync_resource_info(accountId, syncType, content_type , sessionTime);
+                               if (err != SE_INTERNAL_OK) {
+                                       FW_LOGE("failed to write_SyncResourceInfo");
+                                       goto error;
+                               }
+
+                               free_datastore(datastoreinfo_per_content_type[content_type]);
+                               datastoreinfo_per_content_type[content_type] = NULL;
+
+                               Datastore *pDatastore = NULL;
+                               err = __init_datastore_info(accountId, content_type, &pDatastore);
+                               if (err != SE_INTERNAL_OK) {
+                                       FW_LOGE("failed to init_datastore_info");
+                                       goto error;
+                               }
+
+                               datastoreinfo_per_content_type[content_type] = pDatastore;
+                       }
+               }
+       }
+
+error:
+       FW_LOGV("end");
+
+       return err;
+}
+
+static SE_ErrorType __execute_sync(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       if (syncType == ALERT_TWO_WAY || syncType == ALERT_TWO_WAY_BY_SERVER ||
+                       syncType == ALERT_ONE_WAY_FROM_CLIENT || syncType == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) {
+
+               err = __execute_sync_arrange_changelog(accountId , (*pSyncReturnObj)->status);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed to process_update");
+                       goto error;
+               }
+       }
+
+       err = __execute_sync_status(accountId, pSyncObj, pSyncReturnObj);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __execute_sync_status");
+               goto error;
+       }
+
+       err = __execute_sync_change(accountId, pSyncObj, pSyncReturnObj);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __execute_sync_status");
+               goto error;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+static SE_ErrorType __execute_sync_arrange_changelog(int accountId, GList *status)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       DACI_RETURN da_err;
+
+       int i = 0;
+       int count = 0;
+       int list_length = g_list_length(status);
+       char **itemIdList = (char **)calloc(list_length, sizeof(char *));
+       if (itemIdList == NULL) {
+               FW_LOGE("Failed to alloc memory");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto error;
+       }
+
+       GList *appliedStatus_iter = NULL;
+       AppliedStatus *pAppliedStatus = NULL;
+       for (appliedStatus_iter = status; appliedStatus_iter != NULL; appliedStatus_iter = g_list_next(appliedStatus_iter)) {
+               pAppliedStatus = appliedStatus_iter->data;
+
+               switch (pAppliedStatus->status) {
+                       case 200:
+                       case 201:
+                       case 202:
+                       case 203:
+                       case 204:
+                       case 205:
+                       case 207:
+                       case 208:
+                       case 209:
+                       case 210:
+                       case 211:
+                       {
+                               /*clean up change log*/
+                               itemIdList[count++] = strdup(pAppliedStatus->luid);
+
+                               if (syncType == ALERT_TWO_WAY || syncType == ALERT_TWO_WAY_BY_SERVER ||
+                                               syncType == ALERT_ONE_WAY_FROM_CLIENT || syncType == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) {
+
+                                       if (pAppliedStatus->changeType == CHANGE_DELETE) {
+                                               da_err = DACI_Delete_Item_By_Item_Id(pAppliedStatus->luid);
+                                               if (da_err != DACI_SUCCESS) {
+                                                       FW_LOGE("failed in DACI_Delete_Item_By_Item_Id");
+                                                       err = SE_INTERNAL_DA_ERROR;
+                                                       goto error;
+                                               }
+                                       }
+                               }
+                               break;
+                       }
+                       case 206:
+                       case 420:
+                               break;
+                       case 400:
+                       case 500:
+                       {
+                               daci_item_changelog get_changelog;
+                               get_changelog.item_id = pAppliedStatus->luid;
+
+                               da_err = DACI_Get_Item_Changelog_By_Item_Id(accountId, &get_changelog);
+
+                               if (da_err == DACI_ERR_NO_DATA) {
+                                       FW_LOGV("%s item does not exist in ChangeLog tbl", pAppliedStatus->luid);
+                                       break;
+                               } else if (da_err != DACI_SUCCESS) {
+
+                                       FW_LOGE("failed in DACI_Get_Item_Changelog_By_Item_Id");
+                                       err = SE_INTERNAL_DA_ERROR;
+                                       goto error;
+                               }
+
+                               if (get_changelog.status != NULL) {
+                                       if (strcmp(get_changelog.status, "SYNC_ERROR") == 0)
+                                               itemIdList[count++] = strdup(pAppliedStatus->luid);
+                                       else{
+                                               daci_item_changelog set_changelog;
+
+                                               set_changelog.item_id = pAppliedStatus->luid;
+                                               set_changelog.status = "SYNC_ERROR";
+                                               set_changelog.access_name = "SE";
+
+
+                                               da_err =  DACI_Set_Item_Changelog_Sync_Status(accountId, &set_changelog);
+
+                                               if (get_changelog.status != NULL)
+                                                       free(get_changelog.status);
+
+                                               if (get_changelog.access_name != NULL)
+                                                       free(get_changelog.access_name);
+                                               if (da_err != DACI_SUCCESS) {
+                                                       FW_LOGE("failed in DACI_Delete_Item_By_Item_Id");
+                                                       err = SE_INTERNAL_DA_ERROR;
+                                                       goto error;
+                                               }
+                                       }
+                               }
+                               break;
+                       }
+               }
+       }
+
+       if (list_length >= 1) {
+               FW_LOGV("before DACI_Delete_Item_Changelog_By_Item_Id_List");
+               FW_LOGV("count = %d",  count);
+               da_err = DACI_Delete_Item_Changelog_By_Item_Id_List(accountId, itemIdList, count);
+               if (da_err != DACI_SUCCESS) {
+                       FW_LOGE("failed in DACI_Delete_Item_Changelog_By_Item_Id_List");
+                       err = SE_INTERNAL_DA_ERROR;
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+
+error:
+
+       /*free itemIdList*/
+       if (itemIdList != NULL) {
+               for (i = 0; i < list_length; i++) {
+                       if (itemIdList[i])
+                               free(itemIdList[i]);
+               }
+               free(itemIdList);
+       }
+
+       return err;
+}
+
+static SE_ErrorType __execute_sync_status(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       int content_type;
+       bool existEqualItem;
+       bool needToSave;
+       SyncResult *pClientSyncResult;
+       GList *changedDatastore_iter = NULL;
+       ChangedDatastore *pSyncChangedDatastore = NULL;
+       for (changedDatastore_iter = (*pSyncObj)->changedDatastore; changedDatastore_iter != NULL;) {
+               pSyncChangedDatastore = (ChangedDatastore *)changedDatastore_iter->data;
+               FW_LOGV("pChangedDatastore = %p", pSyncChangedDatastore);
+
+               int datastoreContentType = 0;
+               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+                       if (strcmp(pSyncChangedDatastore->source, datastoreinfo_per_content_type[content_type]->source) == 0) {
+                               datastoreContentType = content_type;
+                               break;
+                       }
+               }
+
+               GList *changedItem_iter = NULL;
+               ChangedItem *changedItem = NULL;
+               for (changedItem_iter = pSyncChangedDatastore->sentItem; changedItem_iter != NULL;) {
+                       changedItem = changedItem_iter->data;
+
+                       existEqualItem = false;
+                       GList *appliedStatus_iter = NULL;
+                       AppliedStatus *pAppliedStatus = NULL;
+                       for (appliedStatus_iter = (*pSyncReturnObj)->status; appliedStatus_iter != NULL; appliedStatus_iter = g_list_next(appliedStatus_iter)) {
+                               pAppliedStatus = appliedStatus_iter->data;
+
+                               if (strcmp(pAppliedStatus->luid, changedItem->luid) == 0) {
+                                       add_receive_count(datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult, 1);
+
+                                       if (pAppliedStatus->status >= 200  && pAppliedStatus->status <= 211) {
+                                               switch (changedItem->changeType) {
+                                               case CHANGE_ADD:
+                                                       add_add_count(datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult, 1);
+                                                       break;
+                                               case CHANGE_REPLACE:
+                                                       add_replace_count(datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult, 1);
+                                                       break;
+                                               case CHANGE_DELETE:
+                                                       add_delete_count(datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult, 1);
+                                                       break;
+                                               default:
+                                                       break;
+                                               }
+                                       } else{
+                                               /* if status is not success count it is failed*/
+                                       }
+
+                                       (*pSyncReturnObj)->status = g_list_remove((*pSyncReturnObj)->status, pAppliedStatus);
+                                       free_appliedstatus(pAppliedStatus);
+                                       pAppliedStatus = NULL;
+
+                                       changedItem_iter = g_list_next(changedItem_iter);
+
+                                       pSyncChangedDatastore->sentItem = g_list_remove(pSyncChangedDatastore->sentItem, changedItem);
+                                       free_changeditem(changedItem);
+                                       changedItem = NULL;
+
+                                       existEqualItem = true;
+                                       break;
+                               }
+                       }
+                       if (existEqualItem == false)
+                               changedItem_iter = g_list_next(changedItem_iter);
+               }
+
+               changedDatastore_iter =  g_list_next(changedDatastore_iter);
+
+               needToSave = false;
+               pClientSyncResult = datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult;
+               if (pClientSyncResult->numberOfChange == pClientSyncResult->received_count) {
+                       needToSave = true;
+                       /*remove datastore from list and
+                       free current ChangedDatastore it does not need anymore because all item in datastore has been sent and receive status*/
+                        (*pSyncObj)->changedDatastore = g_list_remove((*pSyncObj)->changedDatastore, pSyncChangedDatastore);
+                       free_changeddatastore(pSyncChangedDatastore);
+                       pSyncChangedDatastore = NULL;
+               }
+
+               OperationType operationType;
+               if (datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult->numberOfChange == 0)
+                       operationType = OPERATION_NOOP;
+               else
+                       operationType = OPERATION_ADD;
+               err = __process_update(accountId, SYNC_PROGRESS_SUCCESS, operationType, datastoreContentType, false,  needToSave,
+                                                                                       datastoreinfo_per_content_type[datastoreContentType]->clientSyncResult);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in process_update");
+                       goto error;
+               }
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+static SE_ErrorType __execute_sync_change(int accountId, SyncObj **pSyncObj, SyncReturnObj **pSyncReturnObj)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       DACI_RETURN da_err = DACI_SUCCESS;
+       int content_type;
+
+       /* process command that from server sended to client(sync, add, replace etc...)*/
+       ChangedDatastore *pSyncReturnChangedDatastore = NULL;
+       SendingStatus *sendingStatus = NULL;
+       GList *iter = NULL;
+       for (iter = (*pSyncReturnObj)->changedDatastore; iter != NULL;) {
+               pSyncReturnChangedDatastore = (ChangedDatastore *)iter->data;
+
+               int datastoreContentType = 0;
+               for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+                       if (strcmp(pSyncReturnChangedDatastore->target, datastoreinfo_per_content_type[content_type]->source) == 0) {
+                               datastoreContentType = content_type;
+                               break;
+                       }
+               }
+
+               /*noti to UI numberOfChanges from server*/
+               if (pSyncReturnChangedDatastore->hasNumberOfChanges) {
+                       set_numberofchange(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, pSyncReturnChangedDatastore->numberOfChanges);
+
+                       OperationType operationType;
+                       if (datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult->numberOfChange == 0)
+                               operationType = OPERATION_NOOP;
+                       else
+                               operationType = OPERATION_ADD;
+                       err = __process_update(accountId,  SYNC_PROGRESS_SUCCESS, operationType, datastoreContentType, true, false,
+                                                                                               datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult);
+                       if (err != SE_INTERNAL_OK) {
+                               FW_LOGE("failed in process_update");
+                               goto error;
+                       }
+               }
+
+               sendingStatus = create_sendingstatus(pSyncReturnChangedDatastore->target, pSyncReturnChangedDatastore->source);
+               if (sendingStatus == NULL) {
+                       err = SE_INTERNAL_NO_MEMORY;
+                       FW_LOGE("failed to alloc memory");
+                       goto error;
+               }
+
+               SyncResult *tempServerSyncResult = NULL;
+               int changeItemCount = g_list_length(pSyncReturnChangedDatastore->changeItem);
+               if (changeItemCount > 0) {
+                       /*begin transaction*/
+                       FW_LOGV("DACI_Service_Begin with datastoreContentType = %d", datastoreContentType);
+                       DACI_Service_Begin(datastoreinfo_per_content_type[datastoreContentType]->datastore_id);
+                       DACI_Begin_Transaction();
+
+                       /*back up syncresult structure for rollback case*/
+                       tempServerSyncResult = dup_syncresult(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult);
+               }
+
+               /*get folderId*/
+               char *folderId = NULL;
+               daci_id_list *folder_id_list = DACI_Get_Folder_Folder_Id_By_Folder_Type_Id(accountId,
+                                                                                                               datastoreinfo_per_content_type[datastoreContentType]->datastore_id,
+                                                                                                               datastoreinfo_per_content_type[datastoreContentType]->folder_type_id);
+               if (folder_id_list != NULL) {
+                       folderId = folder_id_list->id[0];
+               }
+
+               bool needToSave = false;
+               SyncResult *pServerSyncResult = NULL;
+               GList *changedIter = NULL;
+               ChangedItem *changedItem = NULL;
+               AppliedStatus *appliedStatus = NULL;
+
+               for (changedIter = pSyncReturnChangedDatastore->changeItem; changedIter != NULL; changedIter = g_list_next(changedIter)) {
+                       changedItem = (changedIter->data);
+
+                       FW_LOGV("changedItem->changeType : %d", changedItem->changeType);
+                       FW_LOGV("changedItem->luid : %s", changedItem->luid);
+                       FW_LOGV("changedItem->content_type : %s", changedItem->content_type);
+                       FW_LOGV("changedItem->indexOfDatastore : %d", changedItem->indexOfDatastore);
+                       FW_LOGV("changedItem->data : %s", changedItem->data);
+
+                       add_receive_count(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, 1);
+
+                       bool da_fail = false;
+                       CommandResult returnResult = COMMAND_RESULT_INIT;
+                       switch (changedItem->changeType) {
+                               case CHANGE_ADD:
+                               {
+                                       /* add to service DB*/
+                                       if (changedItem->data != NULL) {
+                                               char *service_id = NULL;
+                                               da_err = DACI_Service_Add_Item(datastoreinfo_per_content_type[datastoreContentType]->datastore_id,
+                                                                                                                                                       accountId, folderId, (const void *)(changedItem->data), &service_id);
+                                               FW_LOGV("da_err = %d", da_err);
+
+                                               if (da_err == DACI_SUCCESS) {
+
+                                                       daci_item daci_item_s;
+                                                       daci_item_s.account_id = accountId;
+                                                       daci_item_s.item_id = changedItem->luid;
+                                                       daci_item_s.folder_id = folderId;
+                                                       daci_item_s.data_store_id = datastoreinfo_per_content_type[datastoreContentType]->datastore_id;
+                                                       daci_item_s.service_id = service_id;
+                                                       daci_item_s.access_name = "Engine";
+
+                                                       da_err = DACI_Add_Item(&daci_item_s, 1);
+                                                       FW_LOGV("da_err = %d", da_err);
+                                                       if (da_err == DACI_SUCCESS) {
+                                                               int acc_cnt;
+                                                               daci_folder *pDaci_folder = DACI_Get_Folder_Mapping_Service_Id(accountId, folderId,  &acc_cnt);
+                                                               FW_LOGV("acc_cnt = %d", acc_cnt);
+
+                                                               int i;
+                                                               bool success = true;
+
+                                                               char **fw_item_id_list = DACI_Generate_Item_Luid(1, acc_cnt);
+                                                               for (i = 0; i < acc_cnt; i++) {
+                                                                       da_err = ChangeLog_Add_Item(pDaci_folder[i].account_id, fw_item_id_list[i], service_id,
+                                                                                               datastoreinfo_per_content_type[content_type]->datastore_id, pDaci_folder[i].folder_id);
+                                                                       free(fw_item_id_list[i]);
+
+                                                                       FW_LOGV("da_err = %d", da_err);
+
+                                                                       if (da_err != DACI_SUCCESS) {
+                                                                               success = false;
+                                                                               break;
+                                                                       }
+                                                               }
+                                                               if (fw_item_id_list != NULL) {
+                                                                       free(fw_item_id_list);
+                                                               }
+
+                                                               if (success == true) {
+                                                                       returnResult = COMMAND_RESULT_ADDED;
+                                                                       add_add_count(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, 1);
+                                                               } else{
+                                                                       /*this case just fail do rollback and goto fail*/
+                                                                       returnResult = __convert_return_status(da_err);
+                                                                       da_fail = true;
+                                                               }
+                                                               DACI_Free_Memory_Folder(pDaci_folder, acc_cnt);
+                                                       } else{
+                                                               /*this case just fail do rollback and goto fail*/
+                                                               returnResult = __convert_return_status(da_err);
+                                                               da_fail = true;
+                                                       }
+                                               } else  if (da_err ==  DACI_ERR_NOT_SUPPORTED || da_err == DACI_ERR_INVALID_CONTENT || da_err == DACI_ERR_ALREADY_EXIST) {
+                                                       /*just return error to server*/
+                                                       returnResult = __convert_return_status(da_err);
+                                               } else{
+                                                       /*this case just fail do rollback and goto fail*/
+                                                       returnResult = __convert_return_status(da_err);
+                                                       da_fail = true;
+                                               }
+
+                                               if (service_id != NULL)
+                                                       free(service_id);
+                                       } else
+                                               returnResult = COMMAND_RESULT_COMMAND_FAIL;
+
+                                       break;
+                               }
+                               case CHANGE_REPLACE:
+                               {
+                                       if (changedItem->data != NULL) {
+                                               /* update from service DB*/
+                                               da_err =  DACI_Service_Update_Item(datastoreinfo_per_content_type[datastoreContentType]->datastore_id,
+                                                                                                                                               accountId, folderId, changedItem->luid, (const void *)(changedItem->data));
+                                               FW_LOGV("da_err = %d", da_err);
+                                               if (da_err == DACI_SUCCESS) {
+
+                                                       int acc_cnt;
+                                                       daci_item *pDaci_item_from_other_account = DACI_Get_item_Mapping_Service_Id(accountId, changedItem->luid, &acc_cnt);
+
+                                                       int i;
+                                                       bool success = true;
+                                                       for (i = 0; i < acc_cnt; i++) {
+                                                               da_err = ChangeLog_Update_Item(pDaci_item_from_other_account[i].account_id, pDaci_item_from_other_account[i].item_id,
+                                                                                                                                                       datastoreinfo_per_content_type[content_type]->datastore_id);
+                                                               if (da_err != DACI_SUCCESS) {
+                                                                       success = false;
+                                                                       break;
+                                                               }
+                                                       }
+
+                                                       if (success == true) {
+                                                               returnResult = COMMAND_RESULT_OK;
+                                                               add_replace_count(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, 1);
+                                                       } else{
+                                                               /*this case just fail do rollback and goto fail*/
+                                                               returnResult = __convert_return_status(da_err);
+                                                               da_fail = true;
+                                                       }
+                                                       DACI_Free_Memory_Item(pDaci_item_from_other_account, acc_cnt);
+                                               } else if (da_err ==  DACI_ERR_NOT_SUPPORTED || da_err == DACI_ERR_INVALID_CONTENT) {
+                                                       /*just return error to server*/
+                                                       returnResult = __convert_return_status(da_err);
+                                               } else{
+                                                       /*this case just fail do rollback and goto fail*/
+                                                       returnResult = __convert_return_status(da_err);
+                                                       da_fail = true;
+                                               }
+                                       } else
+                                               returnResult = COMMAND_RESULT_COMMAND_FAIL;
+
+                                       break;
+                               }
+                               case CHANGE_DELETE:
+                               {
+                                       /* delete from service DB*/
+                                       da_err =  DACI_Service_Delete_Item(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, accountId, folderId, changedItem->luid);
+                                       FW_LOGV("[DACI_Service_Delete_Item] result : %d", da_err);
+                                       if (da_err == DACI_SUCCESS) {
+                                               int acc_cnt;
+                                               daci_item *pDaci_item_from_other_account = DACI_Get_item_Mapping_Service_Id(accountId, changedItem->luid, &acc_cnt);
+
+                                               int i;
+                                               bool success = true;
+                                               for (i = 0; i < acc_cnt; i++) {
+                                                       da_err = ChangeLog_Delete_Item(pDaci_item_from_other_account[i].account_id, pDaci_item_from_other_account[i].item_id,
+                                                                                                                                               datastoreinfo_per_content_type[content_type]->datastore_id);
+                                                       if (da_err != DACI_SUCCESS) {
+                                                               success = false;
+                                                               break;
+                                                       }
+                                               }
+
+                                               DACI_Free_Memory_Item(pDaci_item_from_other_account, acc_cnt);
+                                               if (success == true) {
+                                                       da_err =  DACI_Delete_Item_By_Item_Id(changedItem->luid);
+                                                       if (da_err == DACI_SUCCESS) {
+                                                               returnResult = COMMAND_RESULT_DELETE_WITHOUT_ARCHIVE;
+                                                               add_delete_count(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult, 1);
+                                                       } else {
+                                                               /*this case just fail do rollback and goto fail*/
+                                                               returnResult = __convert_return_status(da_err);
+                                                               da_fail = true;
+                                                       }
+                                               } else {
+                                                       /*this case just fail do rollback and goto fail*/
+                                                       returnResult = __convert_return_status(da_err);
+                                                       da_fail = true;
+                                               }
+                                       } else if (da_err == DACI_ERR_NO_DATA || da_err == DACI_ERR_SUB_DATA_EXIST || da_err == DACI_ERR_INVALID_CONTENT) {
+                                               /*just return error to server*/
+                                               returnResult = __convert_return_status(da_err);
+                                       } else {
+                                               /*this case just fail do rollback and goto fail*/
+                                               returnResult = __convert_return_status(da_err);
+                                               da_fail = true;
+                                       }
+
+                                       break;
+                               }
+                               default:
+                                       break;
+                       }
+
+                       if (da_fail == true) {
+
+                               if (folderId != NULL)
+                                       free(folderId);
+
+                               /*replace syncresult when rollback happened*/
+                               if (datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult != NULL)
+                                       free(datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult);
+
+                               datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult = tempServerSyncResult;
+
+                               FW_LOGV("Transaction_Rollback");
+                               FW_LOGV("DACI_Service_End with datastoreContentType = %d", datastoreContentType);
+                               DACI_Service_End(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 0);
+                               DACI_End_Transaction(TRANSACTION_ROLLBACK);
+
+                               err = SE_INTERNAL_DA_ERROR;
+                               FW_LOGE("failed in DA");
+                               goto error;
+                       }
+
+                       appliedStatus = create_appliedstatus(changedItem->luid, changedItem->changeType, returnResult);
+                       if (appliedStatus == NULL) {
+                               err = SE_INTERNAL_NO_MEMORY;
+                               FW_LOGE("failed to alloc memory");
+                               goto error;
+                       }
+                       add_sendingstatus_appliedstatus(sendingStatus, appliedStatus);
+               }
+
+               if (folderId != NULL)
+                       free(folderId);
+
+               if (changeItemCount > 0) {
+
+                       if (tempServerSyncResult != NULL)
+                               free(tempServerSyncResult);
+
+                       /*end transaction*/
+                       FW_LOGV("DACI_Service_End with datastoreContentType = %d", datastoreContentType);
+                       DACI_Service_End(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 1);
+                       DACI_End_Transaction(TRANSACTION_COMMIT);
+               }
+
+               needToSave = false;
+               pServerSyncResult = datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult;
+               if (pServerSyncResult->numberOfChange == pServerSyncResult->received_count)
+                       needToSave = true;
+
+               OperationType operationType;
+               if (datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult->numberOfChange == 0)
+                       operationType = OPERATION_NOOP;
+               else
+                       operationType = OPERATION_ADD;
+               err = __process_update(accountId, SYNC_PROGRESS_SUCCESS, operationType, datastoreContentType, true, needToSave,
+                                                                                               datastoreinfo_per_content_type[datastoreContentType]->serverSyncResult);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in process_update");
+                       goto error;
+               }
+
+               (*pSyncObj)->sendingStatus = g_list_append((*pSyncObj)->sendingStatus, sendingStatus);
+
+               iter = g_list_next(iter);
+
+               (*pSyncReturnObj)->changedDatastore = g_list_remove((*pSyncReturnObj)->changedDatastore, pSyncReturnChangedDatastore);
+               free_changeddatastore(pSyncReturnChangedDatastore);
+               pSyncReturnChangedDatastore = NULL;
+       }
+
+       FW_LOGV("end");
+       return err;
+
+error:
+       FW_LOGE("err = %d", err);
+       return err;
+}
+
+static SE_ErrorType __update_sync_result(int accountId)
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+       DACI_RETURN da_err = DACI_SUCCESS;
+       int content_type;
+
+       daci_last_anchor next_anchor_info;
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (!datastoreinfo_per_content_type[content_type]->clientSyncType) continue;
+
+               next_anchor_info.access_name = "Engine";
+               next_anchor_info.account_id = accountId;
+               next_anchor_info.data_store_id = datastoreinfo_per_content_type[content_type]->datastore_id;
+               next_anchor_info.last_anchor_client = datastoreinfo_per_content_type[content_type]->nextAnchorClient;
+               next_anchor_info.last_anchor_server = datastoreinfo_per_content_type[content_type]->nextAnchorServer;
+
+               da_err = DACI_Set_Last_Anchor(&next_anchor_info);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in DACI_Set_Last_Anchor");
+
+               da_err =  set_ChangePoint_Service(accountId, datastoreinfo_per_content_type[content_type]->datastore_id);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in set_ChangePoint_Service");
+
+       }
+
+       FW_LOGV("end");
+       return err;
+}
+
+static CommandResult __convert_return_status(DACI_RETURN da_err)
+{
+       CommandResult returnResult = COMMAND_RESULT_INIT;
+       switch (da_err) {
+       case 1: /*DACI_SUCCESS*/
+               /*never comes this case
+               break;*/
+       case -813: /*DACI_ERR_ALREADY_EXIST*/
+               returnResult = COMMAND_RESULT_ALREADY_EXIST;            /*[A] Already exists exception*/
+               break;
+       case -815: /*DACI_ERR_MEMORY_FULL*/              /* oma : 420 (device full exception) */
+               returnResult = COMMAND_RESULT_DEVICE_FULL;                      /*[AR] Device full exception*/
+               break;
+       case -820: /*DACI_ERR_NOT_SUPPORTED*/            /* oma : 415 (unsupported media type or format exception) */
+               returnResult = COMMAND_RESULT_UNSUPPORTED_TYPE; /*[AR] Unsupported media type or format exception*/
+               break;
+       case -819: /*DACI_ERR_NO_DATA*/                  /* kies : not found, oma : 211 (item not deleted exception) */
+               returnResult = COMMAND_RESULT_NOT_EXIST;                        /*[D] Item not deleted exception*/
+               break;
+       case -800: /*DACI_ERRORS*/
+       case -801: /*DACI_NOT_FOUND_PLUG_IN*/
+       case -802: /*DACI_ERR_OPEN_FAILED*/
+       case -803: /*DACI_ERR_CLOSE_FAILED*/
+       case -804: /*DACI_ERR_TRANSACTION_FAILED*/
+       case -805: /*DACI_ERR_CREATE_TABLE_FAILED*/
+       case -806: /*DACI_ERR_DROP_TABLE_FAILED*/
+       case -807: /*DACI_ERR_QUERY_FAILED*/
+       case -808: /*DACI_ERR_NOT_OPENED*/
+       case -809: /*DACI_ERR_ACCOUNT_FULL*/
+       case -810: /*DACI_ERR_DELETE_LAST_ACCOUNT*/
+       case -811: /*DACI_ERR_PRIMARY_KEY_NOT_UNIQUE*/
+       case -812: /*DACI_ERR_DB_HANDLER_MGR*/
+       case -814: /*DACI_ERR_INVALID_CONTENT*/
+       case -816: /*DACI_ERR_SUB_DATA_EXIST*/                   /* oma : 427 (item not empty) */
+       case -817: /*DACI_ERR_LOCKED*/                /* kies : cannot access */
+       case -818: /*DACI_ERR_MORE_DATA*/
+       case -821:/*DACI_ERR_NOT_EXECUTE*/              /* kies : ex) sms send command, no network service */
+       default:
+               returnResult = COMMAND_RESULT_COMMAND_FAIL;     /*[ARD] Command failed exception*/
+               break;
+       }
+
+       return returnResult;
+}
+
+static char *__convert_cttype(int datastore_id)
+{
+       char *cttype = NULL;
+       /*FIXME : check type and version (contact : vCard2.1 , calendar : vCalendar 1.0 , memo : plain text) of real item data..*/
+       switch (datastore_id) {
+       case TYPE_CONTACT: /*contact (vCard2.1)*/
+               cttype = ELEMENT_TEXT_VCARD;
+               break;
+       case TYPE_CALENDAR: /*calendar (vCalendar2.0)*/
+               cttype = ELEMENT_TEXT_VCAL;
+               break;
+       case TYPE_MEMO: /*note(Memo)*/
+               cttype = ELEMENT_TEXT_PLAIN;
+               break;
+       default:
+               break;
+       }
+
+       return cttype;
+}
+
+static int __convert_synctype_value(char *syncType_str)
+{
+       int syncType_value;
+
+       if (strcmp(syncType_str, DEFINE_ALERT_SLOW_SYNC_STR) == 0)
+               syncType_value = ALERT_SLOW_SYNC ;
+       else if (strcmp(syncType_str, DEFINE_ALERT_TWO_WAY_STR) == 0)
+               syncType_value = ALERT_TWO_WAY ;
+       else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) == 0)
+               syncType_value =  ALERT_ONE_WAY_FROM_CLIENT;
+       else if (strcmp(syncType_str, DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) == 0)
+               syncType_value = ALERT_ONE_WAY_FROM_SERVER;
+       else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_SERVER_STR) == 0)
+               syncType_value = ALERT_REFRESH_FROM_SERVER;
+       else if (strcmp(syncType_str, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) == 0)
+               syncType_value = ALERT_REFRESH_FROM_CLIENT;
+       else
+               syncType_value = ALERT_UNKNOWN;
+
+       return syncType_value;
+}
+
+bool synchronize(int accountId, char *syncMode, SanPackage *pSanPackage)
+{
+       FW_LOGV("accountID = %d", accountId);
+       FW_LOGV("syncMode = %s", syncMode);
+
+       /*FIXME*/
+       remove(OMA_DS_MSG_PATH);
+
+       /*FIXME*/
+       long t, dt;
+       t = myclock();
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+       Common_ErrorType errorCode = COMMON_OK;
+       SyncProgress process = PROGRESS_NONE;
+       SyncError error = ERROR_NONE;
+
+       int sessionTime = FW_Convert_Seconds_To_UTC(time(NULL));                /*lastSessionTime for resultView;*/
+       FW_LOGV("sessionTime = %d", sessionTime);
+
+       PreSyncReturnObj *pPreSyncReturnObj = NULL;
+       SyncObj *pSyncObj = NULL;
+       SyncReturnObj *pSyncReturnObj = NULL;
+
+       bool cancel_flag = false;
+       int content_type;
+       char *session_id = NULL;
+       DCI_RETURN dci_result = DCI_SUCCESS;
+       DACI_RETURN da_err = DACI_SUCCESS;
+
+       dci_result =  DCI_PM_Lock_State(DEFINE_PLATFORM, LCD_OFF , STAY_CUR_STATE, 0);
+       if (dci_result != DCI_SUCCESS) {
+               FW_LOGE("failed in DCI_PM_Lock_State");
+       }
+
+       da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Open_Agent");
+               err = SE_INTERNAL_DA_ERROR;
+               goto fail_part;
+       }
+
+       /*prepare for sending pre sync*/
+       err = __prepare_pre_sync(accountId, syncMode, pSanPackage);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __prepare_pre_sync");
+               goto fail_part;
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               err = SE_INTERNAL_CANCEL;
+               goto cancel_part;
+       }
+
+       pPreSyncReturnObj = (PreSyncReturnObj *)calloc(1, sizeof(PreSyncReturnObj));
+       if (pPreSyncReturnObj == NULL) {
+               FW_LOGE("failed to alloc memory");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto fail_part;
+       }
+
+       /*pkg 1 */
+       if (strcmp(syncMode, DEFINE_SYNC_MODE_PUSH) == 0) {
+               session_id = g_strdup_printf("%u", pSanPackage->sessionID);             /*freed in pre_sync*/
+               errorCode = pre_sync(TRANSPORT_TYPE, accountId, session_id, (void **)&pPreSyncReturnObj);
+       } else
+               errorCode = pre_sync(TRANSPORT_TYPE, accountId, NULL, (void **)&pPreSyncReturnObj);
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               err = SE_INTERNAL_CANCEL;
+               goto cancel_part;
+       }
+
+       FW_LOGV("pre_sync errorCode =[%d]",  errorCode);
+       if (errorCode != COMMON_OK) {
+               err = SE_INTERNAL_SA_ERROR;
+               goto fail_part;
+       }
+
+       /*execute pre_sync return*/
+       err = __execute_pre_sync(accountId, pPreSyncReturnObj, sessionTime);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __process_pre_sync");
+               goto fail_part;
+       }
+
+       __session_process(accountId, PROGRESS_AUTHENTICATED, ERROR_NONE);
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               err = SE_INTERNAL_CANCEL;
+               goto cancel_part;
+       }
+
+       /* pkg 3 */
+       FW_LOGV("pre_sync end pkg3 start");
+       char *msg = NULL;
+       unsigned int msg_size;
+       char *recvMsg = NULL;
+       unsigned  int recvMsg_size;
+
+       pSyncObj = (SyncObj *)calloc(1, sizeof(SyncObj));
+       if (pSyncObj == NULL) {
+               FW_LOGE("failed to alloc memory");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto fail_part;
+       }
+
+       pSyncReturnObj = (SyncReturnObj *)calloc(1, sizeof(SyncReturnObj));
+       if (pSyncReturnObj == NULL) {
+               FW_LOGE("failed to alloc memory");
+               err = SE_INTERNAL_NO_MEMORY;
+               goto fail_part;
+       }
+
+       err = __assemble_changeddatastores(accountId, &pSyncObj);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __assemble_changeddatastore");
+               goto fail_part;
+       }
+
+       cancel_flag = task_process_check_cancel_flag();
+       if (cancel_flag) {
+               err = SE_INTERNAL_CANCEL;
+               goto cancel_part;
+       }
+
+       int isFinish = 0;
+       while (!isFinish) {
+
+               errorCode = generate_msg((void **)&pSyncObj, &msg, &msg_size);
+               if (errorCode != COMMON_OK) {
+                       FW_LOGE("Failed in generate_Msg");
+                       err = SE_INTERNAL_SA_ERROR;
+                       goto fail_part;
+               }
+
+               cancel_flag = task_process_check_cancel_flag();
+               if (cancel_flag) {
+                       err = SE_INTERNAL_CANCEL;
+                       goto cancel_part;
+               }
+
+               errorCode = exchange_msg(TRANSPORT_TYPE,  msg, msg_size,  &recvMsg, &recvMsg_size);
+               if (errorCode != COMMON_OK) {
+                       FW_LOGE("Failed in exchange_Msg");
+                       err = SE_INTERNAL_SA_ERROR;
+                       goto fail_part;
+               }
+
+               cancel_flag = task_process_check_cancel_flag();
+               if (cancel_flag) {
+                       err = SE_INTERNAL_CANCEL;
+                       goto cancel_part;
+               }
+
+               errorCode = process_recv_msg(recvMsg, recvMsg_size, (void **)&pSyncReturnObj, &isFinish);
+               if (errorCode != COMMON_OK) {
+                       FW_LOGE("Failed in processRecv_Msg");
+                       err = SE_INTERNAL_SA_ERROR;
+                       goto fail_part;
+               }
+
+               cancel_flag = task_process_check_cancel_flag();
+               if (cancel_flag) {
+                       err = SE_INTERNAL_CANCEL;
+                       goto cancel_part;
+               }
+
+               err = __execute_sync(accountId, &pSyncObj, &pSyncReturnObj);
+               if (err != SE_INTERNAL_OK) {
+                       FW_LOGE("failed in __execute_sync");
+                       goto fail_part;
+               }
+
+               free_changeddatastores(pSyncReturnObj->changedDatastore);
+               pSyncReturnObj->changedDatastore = NULL;
+
+               free_appliedstatuses(pSyncReturnObj->status);
+               pSyncReturnObj->status = NULL;
+
+               cancel_flag = task_process_check_cancel_flag();
+               if (cancel_flag) {
+                       err = SE_INTERNAL_CANCEL;
+                       goto cancel_part;
+               }
+       }
+
+       err = __update_sync_result(accountId);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in __update_anchor");
+               goto fail_part;
+       }
+
+       __write_sync_data(accountId, syncType, SYNC_SESSION_SUCCEEDED, sessionTime);
+
+       goto return_part;
+
+cancel_part:
+
+       /*clean up for SA unusual end sync process case*/
+       clean_up_SA();
+
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType)
+                       datastoreinfo_per_content_type[content_type]->clientSyncResult->sessionResult = SYNC_SESSION_STOPPED;
+       }
+
+       __write_sync_data(accountId, syncType, SYNC_SESSION_STOPPED, sessionTime);
+
+       goto return_part;
+
+fail_part:
+
+       /*clean up for SA unusual end sync process case*/
+       clean_up_SA();
+
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               if (datastoreinfo_per_content_type[content_type]->clientSyncType)
+                       datastoreinfo_per_content_type[content_type]->clientSyncResult->sessionResult = SYNC_SESSION_FAILED;
+       }
+
+       __write_sync_data(accountId, syncType, SYNC_SESSION_FAILED, sessionTime);
+
+return_part:
+
+       if (err == SE_INTERNAL_SA_ERROR)
+               convert_common_errorcode(errorCode, &process, &error);
+       else
+               convert_engine_errorcode(err, &process, &error);
+
+        __off_synchronising_account(accountId);
+
+       __session_process(accountId, process, error);
+       FW_LOGV("process = %d", process);
+       FW_LOGV("error = %d", error);
+
+       DACI_Close_Agent();
+
+       dci_result =  DCI_PM_Unlock_State(DEFINE_PLATFORM, LCD_OFF , RESET_TIMER);
+       if (dci_result != DCI_SUCCESS) {
+               FW_LOGE("failed in DCI_PM_Unlock_State");
+       }
+
+       if (pPreSyncReturnObj != NULL) {
+               free_presyncreturnobj(pPreSyncReturnObj);
+               pPreSyncReturnObj = NULL;
+       }
+
+       if (pSyncObj != NULL) {
+               free_syncobj(pSyncObj);
+               pSyncObj = NULL;
+       }
+
+       if (pSyncReturnObj != NULL) {
+               free_syncreturnobj(pSyncReturnObj);
+               pSyncReturnObj = NULL;
+       }
+
+       for (content_type = 0; content_type < TYPE_CONTENT_COUNT; content_type++) {
+               free_datastore(datastoreinfo_per_content_type[content_type]);
+               datastoreinfo_per_content_type[content_type] = NULL;
+       }
+
+       /*FIXME*/
+       dt = myclock()-t;
+       FW_LOGE("\n=============TOTAL---- % d . % d sec\n", dt / 1000, dt % 1000);
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+void convert_common_errorcode(Common_ErrorType errorCode, SyncProgress *process, SyncError *error)
+{
+       switch (errorCode) {
+       case COMMON_OK:                 /*ERROR_INTERNAL_OK*/
+       {
+               /* Do nothing : Error None
+               * pre_sync : PROGRESS_AUTHENTICATED
+               * sync end : PROGRESS_DONE
+                                               process = PROGRESS_AUTHENTICATED;
+                                               process = PROGRESS_DONE;
+               */
+               *process = PROGRESS_DONE;
+               *error = ERROR_NONE;
+       }
+               break;
+       case COMMON_MISCONFIGURATION:                                   /*ERROR_INTERNAL_MISCONFIGURATION : need configure infomation (account_id, id, pw, server_url...)*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_SYNCHDR;
+       }
+               break;
+       case COMMON_AUTHENTICATION_ERROR: /*ERROR_AUTH_REQUIRED, ERROR_AUTH_REJECTED*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_AUTHENTICATE;
+       }
+               break;
+       case COMMON_NOT_FOUND:                                          /*ERROR_NOT_FOUND (ERROR_INTERNAL ??)*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_SYNCHDR;
+       }
+               break;
+       case COMMON_NO_MEMORY:                                  /*ERROR_INTERNAL_NO_MEMORY*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_MEMORY_FULL;
+       }
+               break;
+       case COMMON_INTERNAL_ERROR:                             /*ERROR_INTERNAL_NOT_DEFINED || ERROR_INTERNAL_BINDER_ERROR*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+       }
+               break;
+       case COMMON_SERVER_ERROR:                                       /*ERROR_GENERIC || ERROR_SERVER_FAILURE*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_SERVER;
+       }
+               break;
+       case COMMON_CONNECTION_ERROR:                   /*ERROR_INTERNAL_CONNECTION_ERROR*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_CONNECTION;
+       }
+               break;
+       case COMMON_AUTOCONFIG_NOT_SUPPORT_BY_SERVER:                           /*ERROR_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER*/
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+       }
+               break;
+       default:
+       {
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;                                                /*?? unknown error*/
+       }
+               break;
+       }
+}
+
+void convert_engine_errorcode(SE_ErrorType err, SyncProgress *process, SyncError *error)
+{
+       switch (err) {
+       case ERROR_UNKNOWN:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_CANCEL:
+       case SE_INTERNAL_OK:
+               *process = PROGRESS_DONE;
+               *error = ERROR_NONE;
+               break;
+       case SE_INTERNAL_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_NO_MEMORY:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_MEMORY_FULL;
+               break;
+       case SE_INTERNAL_NOT_DEFINED:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_DA_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_DB;
+               break;
+       case SE_INTERNAL_EVENT_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_ENGINE_CONTROLER_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_SCHEDULER_ERROR:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_INTERNAL;
+               break;
+       case SE_INTERNAL_SA_ERROR:
+               break;
+       case SE_INTERNAL_MISCONFIGURATION:
+               *process = PROGRESS_ERROR;
+               *error = ERROR_SYNCHDR;
+               break;
+       }
+}
+
+SE_ErrorType session_process(char *profileDirName, SyncProgress process, SyncError error)
+{
+       FW_LOGV("start ");
+       FW_LOGV("profileDirName = %s", profileDirName);
+       FW_LOGV("process = %d", process);
+       FW_LOGV("error = %d", error);
+
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       char *syncProcess = NULL;
+       char *syncError = NULL;
+       char *profile = NULL;
+       char *syncProcess_str = NULL;
+       char *syncError_str = NULL;
+
+       switch (process) {
+       case PROGRESS_NONE:
+               syncProcess = DEFINE_SYNC_PROGRESS_NONE;
+               break;
+       case PROGRESS_INIT:
+               syncProcess = DEFINE_SYNC_INIT;
+               break;
+       case PROGRESS_CONNECTING:
+               syncProcess = DEFINE_SYNC_CONNECTING;
+               break;
+       case PROGRESS_AUTHENTICATED:
+               syncProcess = DEFINE_SYNC_AUTHENTICATED;
+               break;
+       case PROGRESS_DONE:
+               syncProcess = DEFINE_SYNC_DONE;
+               break;
+       case PROGRESS_ERROR:
+               syncProcess = DEFINE_SYNC_ERROR;
+               break;
+       default:
+               break;
+       }
+
+       switch (error) {
+       case ERROR_NONE:
+               syncError = DEFINE_ERROR_NONE;
+               break;
+       case ERROR_CONNECTION:
+               syncError = DEFINE_ERROR_CONNECTION;
+               break;
+       case ERROR_SYNCHDR:
+               syncError = DEFINE_ERROR_SYNCHDR;
+               break;
+       case ERROR_INTERNAL:
+               syncError = DEFINE_ERROR_INTERNAL;
+               break;
+       case ERROR_SUSPENDED:
+               syncError = DEFINE_ERROR_SUSPENDED;
+               break;
+       case ERROR_DB:
+               syncError = DEFINE_ERROR_DB;
+               break;
+       case ERROR_ABORT:
+               syncError = DEFINE_ERROR_ABORT;
+               break;
+       case ERROR_SERVER:
+               syncError = DEFINE_ERROR_SERVER;
+               break;
+       case ERROR_MEMORY_FULL:
+               syncError = DEFINE_ERROR_MEMORY_FULL;
+               break;
+       case ERROR_AUTHENTICATE:
+               syncError = DEFINE_ERROR_AUTHENTICATE;
+               break;
+       case ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER:
+               syncError = DEFINE_ERROR_AUTOCONFIG_NOT_SUPPORT_BY_SERVER;
+               break;
+       default:
+               break;
+       }
+
+       if (syncProcess == NULL || syncError == NULL) {
+               err = SE_INTERNAL_NOT_DEFINED;
+               goto error;
+       }
+
+       if (profileDirName != NULL )
+               profile = strdup(profileDirName);
+
+       if (syncProcess != NULL )
+               syncProcess_str = strdup(syncProcess);
+
+       if (syncError != NULL )
+               syncError_str = strdup(syncError);
+
+       err = send_noti_session_process(profile, syncProcess_str, syncError_str);
+       if (err != SE_INTERNAL_OK) {
+               FW_LOGE("failed in send_noti_session_process");
+               goto error;
+       }
+
+
+       FW_LOGV("end");
+
+error:
+       if (profile)
+               free(profile);
+       if (syncProcess_str)
+               free(syncProcess_str);
+       if (syncError_str)
+               free(syncError_str);
+
+       return err;
+}
+
+SE_ErrorType reset_synchronizing_profiles()
+{
+       FW_LOGV("start");
+       int *account_list = 0;
+       int account_list_count = 0;
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               FW_LOGE("failed in DACI_Open_Agent");
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       account_list = DACI_Get_Account_Account_Id_List(&account_list_count);
+       FW_LOGV("account_list_count = %d", account_list_count);
+
+       int i;
+       for (i = 0; i < account_list_count; i++) {
+               FW_LOGV("account = %d", account_list[i]);
+               __off_synchronising_account(account_list[i]);
+
+               FW_LOGV("construct_itemTbl From service start");
+
+               /*construct_itemTbl From service*/
+               da_err = construct_ItemTbl_From_Service(account_list[i], TYPE_CONTACT);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in construct_ItemTbl_From_Service(TYPE_CONTACT)");
+
+               da_err = construct_ItemTbl_From_Service(account_list[i], TYPE_CALENDAR);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in construct_ItemTbl_From_Service(TYPE_CALENDAR)");
+
+               da_err = construct_ItemTbl_From_Service(account_list[i], TYPE_MEMO);
+               if (da_err != DACI_SUCCESS)
+                       FW_LOGE("failed in construct_ItemTbl_From_Service(TYPE_MEMO)");
+
+               FW_LOGV("construct_itemTbl From service end");
+       }
+
+       DACI_Close_Agent();
+       FW_LOGV("end");
+
+error:
+
+       if (account_list_count > 0)
+               free(account_list);
+
+       return err;
+}
+
+bool refresh_from_service_all(int accountId)
+{
+       FW_LOGV("start");
+       SE_ErrorType  err = SE_INTERNAL_OK;
+
+       DACI_RETURN da_err = DACI_Open_Agent();
+       if (da_err != DACI_SUCCESS) {
+               err = SE_INTERNAL_DA_ERROR;
+               goto error;
+       }
+
+       FW_LOGV("refresh_Item_Tbl_From_Service(%d, %d);", accountId, TYPE_CONTACT);
+       refresh_Item_Tbl_From_Service(accountId, TYPE_CONTACT);
+
+       FW_LOGV("refresh_Item_Tbl_From_Service(%d, %d);", accountId, FW_CALENDAR);
+       refresh_Item_Tbl_From_Service(accountId, TYPE_CALENDAR);
+
+       FW_LOGV("refresh_Item_Tbl_From_Service(%d, %d);", accountId, FW_MEMO);
+       refresh_Item_Tbl_From_Service(accountId, TYPE_MEMO);
+
+error:
+
+       DACI_Close_Agent();
+
+       if (err != SE_INTERNAL_OK)
+               return false;
+       else
+               return true;
+}
+
+/*FIXME cancel request to NA */
+/*SE_ErrorType cancel_sync_request()
+{
+       FW_LOGV("start");
+       SE_ErrorType err = SE_INTERNAL_OK;
+
+       cancel_connection_sync_request(TRANSPORT_TYPE);
+
+       FW_LOGV("end");
+
+       return err;
+}*/
diff --git a/src/main/main.c b/src/main/main.c
new file mode 100644 (file)
index 0000000..dcae259
--- /dev/null
@@ -0,0 +1,343 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/**
+ *   @main.c
+ *   @version                                                                  0.1
+ *   @brief                                                                            This file is the source file of implementation of main function
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "agent-framework/Initialization/initialize.h"
+#include "agent-framework/Utility/fw_log.h"
+#include "agent-framework/PlatformMonitor/EXT_PMCI_Struct.h"
+#include "agent-framework/PlatformMonitor/EXT_PMCI.h"
+#include "agent-framework/FSAPI/FSAPI_operation.h"
+#include "Framework/Event/OMA_DS_Platform_Event_Handler.h"
+#include "Framework/Event/OMA_DS_Event_Handler.h"
+#include "Framework/Task/OMA_DS_Engine_Controller_Task.h"
+#include "Common/CscKeys.h"
+#include "Common/Common_Define_Internal.h"
+#include "Common/Common_Vconf.h"
+#include "ServiceEngine/SE_Account.h"
+
+#define LOG_TAG        "OMA_DS_MAIN"
+
+static void __request_reset_synchronizing_profiles();
+static void __check_csc();
+static void __update_csc();
+
+int main()
+{
+       FW_LOGV("start");
+
+       EVENT_ERROR error  = EVENT_SUCCESS;
+
+       INIT_ERROR init_error = Init_Framework("/opt/data/oma-ds/omads_fw_config.xml");
+       if (init_error != INIT_SUCCESS) {
+               FW_LOGE("Failed to Init_Framework() : %d", init_error);
+       } else {
+               FW_LOGV("done init_Framework");
+       }
+
+       /*TODO have to be removed after removing vconf*/
+       task_spec_t *pAddAccountTaskSpec = make_add_account_task();
+       task_spec_t *pEditAccountTaskSpec = make_edit_account_task();
+       /*task_spec_t *pDeleteAccountTaskSpec = make_delete_account_task();*/
+       task_spec_t *pAutoConfTaskSpec = make_autoconfigure_task();
+
+
+       task_spec_t *pSyncTaskSpec = make_synchronize_task();
+       /*task_spec_t *pAddProfileTaskSpec = make_add_profile_task();*/
+       /*task_spec_t *pEditProfileTaskSpec = make_edit_profile_task();*/
+       task_spec_t *pDeleteProfileTaskSpec = make_delete_profile_task();
+       /*task_spec_t *pAutoConfTaskSpec = make_auto_configure_task();*/
+       task_spec_t *pSyncStatusTaskSpec = make_sync_status_task();
+       task_spec_t *pGetProfileNameTaskSpec = make_get_profile_name_task();
+       task_spec_t *pGetProfileServerInfoTaskSpec = make_get_profile_server_info_task();
+       task_spec_t *pGetProfileSyncModeTaskSpec = make_get_profile_sync_mode_task();
+       task_spec_t *pGetProfileSyncCategoryTaskSpec = make_get_profile_sync_category_task();
+       task_spec_t *pGetProfileLastSessionTaskSpec = make_get_profile_last_session_task();
+       task_spec_t *pGetProfileStatisticsTaskSpec = make_get_profile_statistics_task();
+       task_spec_t *pResetSynchronizingProfilesTaskSpec = make_reset_synchronizing_profiles_task();
+       task_spec_t *pAddProfileCPTaskSpec = make_add_profile_cp_task();
+       task_spec_t *pRefreshFromServiceTaskSpec = make_refresh_from_service_task();
+
+       /*FIXME cancel request to NA */
+       /*task_spec_t *pCancelSyncRequestTaskSpec = make_cancel_sync_request();*/
+
+
+
+       /*TODO have to be removed after removing vconf*/
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_ACCOUNT,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_ADD_ACCOUNT,
+                                                                                                               pAddAccountTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_EDIT_ACCOUNT,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_ACCOUNT,
+                                                                                                               pEditAccountTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_AUTOCONFIGURE,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_AUTOCONFIGURE,
+                                                                                                                       pAutoConfTaskSpec, NULL);
+/*******************************************************/
+
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_REQUEST,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_REQUEST,
+                                                                                                                       pSyncTaskSpec, NULL);
+
+       /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE,
+                                                                                                               pAddProfileTaskSpec, NULL);*/
+
+       /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_PROFILE,
+                                                                                                               pEditProfileTaskSpec, NULL);*/
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_DELETE_PROFILE,
+                                                                                                               pDeleteProfileTaskSpec, NULL);
+
+
+       /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_AUTO_CONFIGURE,
+                                                                                                               EC_MSG_TYPE_NAME_SYNC_TASK_AUTO_CONFIGURE,
+                                                                                                                       pAutoConfTaskSpec, NULL);*/
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_SYNCSTATUS,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_SYNCSTATUS,
+                                                                                                                       pSyncStatusTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_NAME,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_NAME,
+                                                                                                                       pGetProfileNameTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SERVER_INFO,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SERVER_INFO,
+                                                                                                                       pGetProfileServerInfoTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_MODE,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_MODE,
+                                                                                                                       pGetProfileSyncModeTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY,
+                                                                                                                       pGetProfileSyncCategoryTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_LAST_SESSION,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_LAST_SESSION,
+                                                                                                                       pGetProfileLastSessionTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_STATISTICS,
+                                                                                                                       pGetProfileStatisticsTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES,
+                                                                                                                       pResetSynchronizingProfilesTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE_CP,
+                                                                                                                       pAddProfileCPTaskSpec, NULL);
+
+       engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_REFRESH_FROM_SERVICE,
+                                                                                                                       pRefreshFromServiceTaskSpec, NULL);
+
+       /*FIXME cancel request to NA */
+       /*engine_controller_register_task_spec(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST,
+                                                                                                                       EC_MSG_TYPE_NAME_SYNC_TASK_CANCEL_SYNC_REQUEST,
+                                                                                                                       pCancelSyncRequestTaskSpec, NULL);*/
+
+       queuing_rule_spec_t *pQueuing_rule = queuing_rule_spec_create_queuing_rule_spec_outline("sync_queueing_rule");
+
+       queuing_rule_spec_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE,
+                                                                                                                                                                       pSyncTaskSpec, 0);
+
+       queuing_rule_spec_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_REQUEST,
+                                                                                                                                                               pSyncTaskSpec, 0);
+
+       engine_controller_async_register_queuing_rule_spec(pQueuing_rule, NULL, NULL);
+
+       queuing_rule_spec_unref(pQueuing_rule);
+
+       __request_reset_synchronizing_profiles();                       /*reset synchronizing flag 0 every account & construct item tbl*/
+
+       /*TODO have to be removed after removing vconf*/
+       error = set_EventCallback(1,  event_callback_add_account);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(3,  event_callback_edit_account);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(5,  event_callback_auto_configure);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+/************************************************/
+
+
+
+       /*error = set_EventCallback(1,  event_callback_add_profile_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");*/
+
+       error = set_EventCallback(2,  event_callback_request_sync_async);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       /*error = set_EventCallback(3,  event_callback_edit_profile_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");*/
+
+       error = set_EventCallback(4,  event_callback_delete_profile_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       /*error = set_EventCallback(5,  event_callback_auto_configure_async);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");*/
+
+       error = set_EventCallback(6,  event_callback_cancel_sync_async);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(7,  event_callback_query_sync_status_async);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(8,  event_callback_get_profile_name_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(9,  event_callback_get_profile_server_info_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(10,  event_callback_get_profile_sync_mode_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(11,  event_callback_get_profile_sync_category_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(12,  event_callback_get_profile_last_session_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(13,  event_callback_get_profile_last_statistics_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       error = set_EventCallback(14,  event_callback_add_profile_cp_sync);
+       if (error != EVENT_SUCCESS)
+               FW_LOGE("failed set_EventCallback()");
+
+       PMCI_RETURN san_err = PMCI_Init_Specific_Type(DEFINE_PLATFORM, SAN, PKG_NAME, NULL, 1, SAN_callback_parse);
+       if (san_err != PMCI_SUCCESS)
+               FW_LOGE("failed in PMCI_Init_Specific_Type");
+
+       PMCI_RETURN scheduler_err = PMCI_Init_Specific_Type(DEFINE_PLATFORM, ALARM, PKG_NAME, NULL, 1, send_periodic_sync_msg);
+       if (scheduler_err != PMCI_SUCCESS)
+               FW_LOGE("failed in PMCI_Init_Specific_Type");
+
+       /*register profiles from csc*/
+       __check_csc();
+
+       while (1) {
+               sleep(1);
+       }
+       return 0;
+}
+
+static void __request_reset_synchronizing_profiles()
+{
+       FW_LOGV("start");
+       unsigned int request_msg_id = 0;
+       engine_controller_async_request_task(EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES, 0,
+                                                                                                                       0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id);
+       FW_LOGV("end");
+}
+static void __check_csc()
+{
+       FW_LOGV("start");
+
+       bool exist = false;
+
+       /*FIXME(temporary do not process csc for ui reason)
+       check csc_check file is existed
+       if false do csc update
+       if true check csc xml file has been changed*/
+
+       /*exist = FSAPI_isExisting(OMA_DS_CSC_CHECK_PATH);*/
+       exist = true;
+       FW_LOGV("update = %d", exist);
+
+       if (exist == false)
+               __update_csc();
+
+       FW_LOGV("end");
+}
+
+static void __update_csc()
+{
+       FW_LOGV("start");
+
+       char profile[128];
+       int numberOfProfiles = 0;
+       char *contents = "check";
+
+       bool result = get_vconf_Int_key(CSC_VCONF_KEY_SYNCMLDS_NBDATASYNC, &numberOfProfiles);
+       if (result == false) {
+               FW_LOGE("failed in get_vconf_Int_key");
+               goto error;
+       }
+
+       int i;
+       for (i = 1; i <= numberOfProfiles; i++) {
+               sprintf(profile, "Sync%d", i);
+               add_profile_csc(i);
+       }
+
+       FSAPI_fileWriteWhole(OMA_DS_CSC_CHECK_PATH, contents, sizeof(contents), false);
+
+error:
+
+       FW_LOGV("end");
+}
diff --git a/syncmld_mgr b/syncmld_mgr
new file mode 100755 (executable)
index 0000000..8581dac
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+## A script for running syncmld in booting time.
+## Maintained by JooHark Park (juhaki.park@samsung.com) ByongUk Lee (byonguk.lee@samsung.com)
+
+do_start () {
+       echo "[rc.d] running syncmld script"
+       /usr/bin/oma-ds-service &
+}
+
+case "$1" in
+       start)
+               do_start
+               ;;
+       *)
+               echo "Usage: $0 start"
+               exit 1
+esac
+
+exit 0
diff --git a/test/include/suites/unit_test_sample_suite.h b/test/include/suites/unit_test_sample_suite.h
new file mode 100644 (file)
index 0000000..4aff5a6
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * This software is the confidential and proprietary information of
+ * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not disclose
+ * such Confidential Information and shall use it only in accordance with the
+ * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
+ * SAMSUNG make no representations or warranties about the suitability of the
+ * software, either express or implied, including but not limited to the
+ * implied warranties of merchantability, fitness for a particular purpose, or
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by
+ * licensee as a result of using, modifying or distributing this software or
+ * its derivatives.
+ */
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/*
+ * unit_test_sample_suite.h
+ *
+ *  Created on: 2011. 7. 28.
+ *      Author: yangjoo.suh
+ */
+
+#ifndef UNIT_TEST_SUITE_H_
+#define UNIT_TEST_SUITE_H_
+
+#include "unit_test_common.h"
+
+Suite *sample_suite(void);
+
+#endif /* UNIT_TEST_SUITE_H_ */
diff --git a/test/include/unit_test_common.h b/test/include/unit_test_common.h
new file mode 100644 (file)
index 0000000..b4f7767
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * This software is the confidential and proprietary information of
+ * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not disclose
+ * such Confidential Information and shall use it only in accordance with the
+ * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
+ * SAMSUNG make no representations or warranties about the suitability of the
+ * software, either express or implied, including but not limited to the
+ * implied warranties of merchantability, fitness for a particular purpose, or
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by
+ * licensee as a result of using, modifying or distributing this software or
+ * its derivatives.
+ */
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/*
+ * unit_test_common.h
+ *
+ *  Created on: 2011. 7. 28.
+ *      Author: yangjoo.suh
+ */
+
+#ifndef UNIT_TEST_COMMON_H_
+#define UNIT_TEST_COMMON_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <check.h>
+
+#endif /* UNIT_TEST_COMMON_H_ */
diff --git a/test/include/unit_test_run.h b/test/include/unit_test_run.h
new file mode 100644 (file)
index 0000000..eab5c6d
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * This software is the confidential and proprietary information of
+ * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not disclose
+ * such Confidential Information and shall use it only in accordance with the
+ * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
+ * SAMSUNG make no representations or warranties about the suitability of the
+ * software, either express or implied, including but not limited to the
+ * implied warranties of merchantability, fitness for a particular purpose, or
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by
+ * licensee as a result of using, modifying or distributing this software or
+ * its derivatives.
+ */
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/*
+ * unit_test.h
+ *
+ *  Created on: 2011. 3. 29.
+ *      Author: yangjoo
+ */
+
+#ifndef UNIT_TEST_H_
+#define UNIT_TEST_H_
+
+#include "unit_test_common.h"
+
+typedef enum run_unit_test_mode run_unit_test_mode_t;
+enum run_unit_test_mode {
+       FUNCTION_MODE,  /* unit test runs just like function */
+                                                               /* good for debugging */
+       FORK_MODE
+};
+
+int unit_test_run(run_unit_test_mode_t mode);
+
+#endif /* UNIT_TEST_H_ */
diff --git a/test/include/unit_test_suites.h b/test/include/unit_test_suites.h
new file mode 100644 (file)
index 0000000..f7e5c35
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * This software is the confidential and proprietary information of
+ * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not disclose
+ * such Confidential Information and shall use it only in accordance with the
+ * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
+ * SAMSUNG make no representations or warranties about the suitability of the
+ * software, either express or implied, including but not limited to the
+ * implied warranties of merchantability, fitness for a particular purpose, or
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by
+ * licensee as a result of using, modifying or distributing this software or
+ * its derivatives.
+ */
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/*
+ * unit_test_suites.h
+ *
+ *  Created on: 2011. 7. 28.
+ *      Author: yangjoo.suh
+ */
+
+#ifndef UNIT_TEST_SUITES_H_
+#define UNIT_TEST_SUITES_H_
+
+#include "unit_test_common.h"
+#include "suites/unit_test_sample_suite.h"
+
+/* define here suites to be tested */
+typedef Suite *(*SUITE_FUNCTION) (void);
+static SUITE_FUNCTION suiteFunctions[] = {
+               sample_suite
+};
+
+#endif /* UNIT_TEST_SUITES_H_ */
diff --git a/test/src/oma_test_main.c b/test/src/oma_test_main.c
new file mode 100644 (file)
index 0000000..6ce00f7
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * This software is the confidential and proprietary information of
+ * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not disclose
+ * such Confidential Information and shall use it only in accordance with the
+ * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
+ * SAMSUNG make no representations or warranties about the suitability of the
+ * software, either express or implied, including but not limited to the
+ * implied warranties of merchantability, fitness for a particular purpose, or
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by
+ * licensee as a result of using, modifying or distributing this software or
+ * its derivatives.
+ */
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/*
+ * oma_test_main.c
+ *
+ *  Created on: 2011. 7. 28.
+ *      Author: yangjoo.suh
+ */
+
+#include "unit_test_run.h"
+
+int main(void)
+{
+       int test_success = unit_test_run(FUNCTION_MODE);
+       return test_success;
+}
diff --git a/test/src/suites/unit_test_sample_suite.c b/test/src/suites/unit_test_sample_suite.c
new file mode 100644 (file)
index 0000000..ed58c19
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * This software is the confidential and proprietary information of
+ * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not disclose
+ * such Confidential Information and shall use it only in accordance with the
+ * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
+ * SAMSUNG make no representations or warranties about the suitability of the
+ * software, either express or implied, including but not limited to the
+ * implied warranties of merchantability, fitness for a particular purpose, or
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by
+ * licensee as a result of using, modifying or distributing this software or
+ * its derivatives.
+ */
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/*
+ * unit_test_sample_suite.c
+ *
+ *  Created on: 2011. 3. 29.
+ *      Author: yangjoo.suh
+ */
+
+#include "unit_test_common.h"
+#include "suites/unit_test_sample_suite.h"
+
+START_TEST(sample_test1)
+{
+       fail_unless(2 != 1, "2 != 1 failed");
+       fail_unless(3 != 1, "3 != 1 failed");
+}
+END_TEST
+
+START_TEST(sample_test2)
+{
+  /* unit test code */
+       fail_unless(10 != 5, "10 != 5 failed");
+}
+END_TEST
+
+Suite *sample_suite(void)
+{
+       /* create test suite */
+       Suite *s = suite_create("Sample");
+
+       /* test case create and add in suite*/
+       {
+               TCase *tcase = tcase_create("SampleTestCase");
+               /* TODO : explain following lines */
+       /*  tcase_add_unchecked_fixture (tcase, setup, teardown);*/
+       /*  tcase_add_checked_fixture (tcase, setup, teardown);*/
+
+               tcase_add_test(tcase, sample_test1);
+               tcase_add_test(tcase, sample_test2);
+               /* TODO : explain following lines */
+               tcase_set_timeout(tcase, 1);
+
+               suite_add_tcase(s, tcase);
+       }
+
+       /* create another test case and add to test suite just like above code */
+       {
+               TCase *tc_core2 = tcase_create("Sample2");
+               tcase_add_test(tc_core2, sample_test1);
+               tcase_add_test(tc_core2, sample_test2);
+               tcase_set_timeout(tc_core2, 1);
+               suite_add_tcase(s, tc_core2);
+       }
+
+       return s;
+}
diff --git a/test/src/unit_test_run.c b/test/src/unit_test_run.c
new file mode 100644 (file)
index 0000000..4e1b543
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * oma-ds-service
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * PROPRIETARY/CONFIDENTIAL
+ *
+ * Contact: JuHak Park <juhaki.park@samsung.com>,
+ *          JuneHyuk Lee <junhyuk7.lee@samsung.com>,
+ *          SunBong Ha <sunbong.ha@samsung.com>
+ *
+ * This software is the confidential and proprietary information of
+ * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not disclose
+ * such Confidential Information and shall use it only in accordance with the
+ * terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
+ * SAMSUNG make no representations or warranties about the suitability of the
+ * software, either express or implied, including but not limited to the
+ * implied warranties of merchantability, fitness for a particular purpose, or
+ * non-infringement. SAMSUNG shall not be liable for any damages suffered by
+ * licensee as a result of using, modifying or distributing this software or
+ * its derivatives.
+ */
+
+/*
+ * For any sort of issue you concern as to this software,
+ * you may use following point of contact.
+ * All resources contributed on this software
+ * are orinigally written by S-Core Inc., a member of Samsung Group.
+ *
+ * SeongWon Shim <seongwon.shim@samsung.com>
+ */
+
+/*
+ * unit_test_run.c
+ *
+ *  Created on: 2011. 3. 29.
+ *      Author: yangjoo.suh
+ */
+
+#include "unit_test_common.h"
+#include "unit_test_run.h"
+#include "unit_test_suites.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+
+/* introduction to unit test using check by yangsuh
+  * SRunner : runner of all test which belong to added suites
+  *    Suite : container of test cases(TCase)
+  *            TCase : container of tests
+  *                    test : container of many asserts
+  *
+  * SRunner has fork_status option. I will set this option to CK_FORK which means
+  * not stopping until all test finished.
+  * (Of course, when error like SIGSEGV occurs or test failed, current test will be stopped
+  * and goes to next test)
+  */
+
+typedef enum fork_status fork_status_t;
+int unit_test_main(fork_status_t fork_status)
+{
+       SRunner *sr = NULL;
+
+       /* srunner build up by defined test suites */
+       int suite_count = sizeof(suiteFunctions)/sizeof(SUITE_FUNCTION);
+       fprintf(stderr, "total test suites number = %d\n", suite_count);
+
+       if (suite_count == 0) {
+               return 0;       /* nothing to do */
+       } else {        /* suite_count > 0 */
+               SUITE_FUNCTION suite_func = NULL;
+
+               int i = 0;
+               for (i = 0; i < suite_count; i++) {
+                       suite_func = suiteFunctions[i];
+                       Suite *s = suite_func();
+                       if (s != NULL) {
+                               if (i == 0) {
+                                       sr = srunner_create(s);
+                               } else if (i > 0 && i < suite_count) {
+                                       srunner_add_suite(sr, s);
+                               }
+                       } else {
+                               fprintf(stderr, "invalid suite function\n");
+                       }
+               }
+       }
+
+       /* srunner setting */
+       srunner_set_log(sr, "/tmp/test.log");           /* set log file */
+       srunner_set_fork_status(sr, fork_status);        /* set fork status of Runner */
+
+       srunner_run_all(sr, CK_VERBOSE);                        /* set print mode to verbose */
+       srunner_free(sr);
+
+       return 0;
+}
+
+/* TODO : return handling */
+static inline int unit_test_run_fork_mode()
+{
+       pid_t pid_w;
+       pid_t pid;
+       int status = 0;
+
+       pid = fork();
+       if (pid == -1)
+               fprintf(stderr, "Error in call to fork\n");
+       if (pid == 0) {
+               /* child process : run unit_test_main */
+               unit_test_main(CK_FORK);
+               exit(EXIT_SUCCESS);
+       } else {
+               /* parent process */
+               fprintf(stderr, "test process pid = %d", pid);
+               pid_w = waitpid(pid, &status, 0);
+
+               if (pid_w == pid) {
+                       fprintf(stderr, "test finished successfully\n");
+                       return 1;       /* test finished */
+               } else {
+                       fprintf(stderr, "test failed\n");
+                       return 0;       /* test error */
+               }
+       }
+
+       return status;
+}
+
+/* running as main function will be need during debugging */
+/* TODO : return handling */
+static inline int unit_test_run_function_mode()
+{
+       return unit_test_main(CK_NOFORK);
+}
+
+int unit_test_run(run_unit_test_mode_t mode)
+{
+       int success = 1;                /* success */
+
+       switch (mode) {
+       case FORK_MODE:
+               success = unit_test_run_fork_mode();
+               break;
+       case FUNCTION_MODE:
+               success = unit_test_run_function_mode();
+               break;
+       default:
+               break;
+       }
+
+       return success;
+}