From 7380e02d6fb53570f95f00df079cc05f8e9f6acc Mon Sep 17 00:00:00 2001 From: HyungKyu Song Date: Sat, 16 Feb 2013 01:54:49 +0900 Subject: [PATCH] Tizen 2.0 Release --- AUTHORS | 4 + BuildFlags.cmake | 32 + CMakeLists.txt | 25 + LICENSE.APLv2 | 202 + NOTICE | 3 + com.samsung.omadsagent.service | 3 + debian/changelog | 47 + debian/control | 22 + debian/control.slp | 8 + debian/postinst | 45 + debian/rules | 104 + ds-public-plugins.manifest | 5 + include/common/common_define.h | 1191 +++++ include/common/common_define_internal.h | 307 ++ include/common/common_util.h | 187 + include/common/common_vconf.h | 249 + include/common/csc_keys.h | 50 + include/framework/event/oma_ds_event_handler.h | 354 ++ .../event/oma_ds_platform_event_handler.h | 114 + include/framework/san-parser/pm_sanparser.h | 224 + .../framework/task/oma_ds_engine_controller_task.h | 975 ++++ include/service-adapter/network-binder/na_binder.h | 85 + .../protocol-binder/oma_ds_protocol_binder.h | 314 ++ .../oma_ds_protocol_binder_definition.h | 188 + include/service-adapter/sa_command.h | 866 ++++ include/service-adapter/sa_command_internal.h | 102 + include/service-adapter/sa_common_interface.h | 285 ++ include/service-adapter/sa_define.h | 159 + include/service-adapter/sa_devinf.h | 134 + include/service-adapter/sa_devinf_internal.h | 118 + include/service-adapter/sa_elements.h | 893 ++++ include/service-adapter/sa_elements_internal.h | 102 + include/service-adapter/sa_error.h | 124 + include/service-adapter/sa_session.h | 277 ++ include/service-adapter/sa_session_internal.h | 83 + include/service-adapter/sa_util.h | 94 + include/service-engine/se_account.h | 342 ++ include/service-engine/se_common.h | 128 + include/service-engine/se_error.h | 45 + include/service-engine/se_notification.h | 99 + include/service-engine/se_storage.h | 258 + include/service-engine/se_sync.h | 234 + oma-ds | 73 + oma-ds-agent.manifest | 18 + oma-ds-cfg/eventconfig_omads | 12 + oma-ds-cfg/noticonfig_omads | 2 + oma-ds-cfg/omadsUI_fw_config.xml | 13 + oma-ds-cfg/omads_fw_config.xml | 133 + packaging/oma-ds-agent.spec | 117 + src/agent/CMakeLists.txt | 80 + src/agent/common/common_define.c | 750 +++ src/agent/common/common_util.c | 281 ++ src/agent/common/common_vconf.c | 191 + src/agent/framework/event/oma_ds_event_handler.c | 908 ++++ .../event/oma_ds_platform_event_handler.c | 355 ++ src/agent/framework/san-parser/pm_sanparser.c | 633 +++ .../framework/task/oma_ds_engine_controller_task.c | 1137 +++++ src/agent/main/main.c | 395 ++ .../service-adapter/network-binder/na_binder.c | 142 + .../protocol-binder/oma_ds_protocol_binder.c | 5256 ++++++++++++++++++++ src/agent/service-adapter/sa_command.c | 1016 ++++ src/agent/service-adapter/sa_common_interface.c | 2812 +++++++++++ src/agent/service-adapter/sa_devinf.c | 1069 ++++ src/agent/service-adapter/sa_elements.c | 834 ++++ src/agent/service-adapter/sa_session.c | 1578 ++++++ src/agent/service-adapter/sa_util.c | 177 + src/agent/service-engine/se_account.c | 1865 +++++++ src/agent/service-engine/se_notification.c | 133 + src/agent/service-engine/se_storage.c | 1000 ++++ src/agent/service-engine/se_sync.c | 3245 ++++++++++++ src/plugins/CMakeLists.sub | 57 + src/plugins/CMakeLists.txt | 3 + src/plugins/ds-public/CMakeLists.txt | 11 + src/plugins/ds-public/plain-text/CMakeLists.txt | 43 + .../include/in_datastore_info_plain_text.h | 32 + .../ds-public/plain-text/src/plugin_interface.c | 245 + src/plugins/ds-public/vcard/CMakeLists.txt | 42 + .../ds-public/vcard/include/encoding_util.h | 237 + .../vcard/include/in_datastore_info_vcard.h | 156 + src/plugins/ds-public/vcard/include/plugin_spec.h | 65 + src/plugins/ds-public/vcard/src/encoding_util.c | 814 +++ src/plugins/ds-public/vcard/src/plugin_interface.c | 998 ++++ src/plugins/ds-public/xcalllog/CMakeLists.txt | 42 + .../ds-public/xcalllog/include/encoding_util.h | 238 + .../ds-public/xcalllog/include/plugin_spec.h | 33 + src/plugins/ds-public/xcalllog/src/encoding_util.c | 812 +++ .../ds-public/xcalllog/src/plugin_interface.c | 432 ++ test/include/suites/unit_test_sample_suite.h | 25 + test/include/unit_test_common.h | 26 + test/include/unit_test_run.h | 32 + test/include/unit_test_suites.h | 30 + test/src/oma_test_main.c | 24 + test/src/suites/unit_test_sample_suite.c | 63 + test/src/unit_test_run.c | 131 + 94 files changed, 37897 insertions(+) create mode 100755 AUTHORS create mode 100644 BuildFlags.cmake create mode 100644 CMakeLists.txt create mode 100755 LICENSE.APLv2 create mode 100755 NOTICE create mode 100755 com.samsung.omadsagent.service create mode 100644 debian/changelog create mode 100755 debian/control create mode 100644 debian/control.slp create mode 100644 debian/postinst create mode 100755 debian/rules create mode 100644 ds-public-plugins.manifest create mode 100755 include/common/common_define.h create mode 100755 include/common/common_define_internal.h create mode 100755 include/common/common_util.h create mode 100755 include/common/common_vconf.h create mode 100755 include/common/csc_keys.h create mode 100755 include/framework/event/oma_ds_event_handler.h create mode 100755 include/framework/event/oma_ds_platform_event_handler.h create mode 100755 include/framework/san-parser/pm_sanparser.h create mode 100755 include/framework/task/oma_ds_engine_controller_task.h create mode 100755 include/service-adapter/network-binder/na_binder.h create mode 100755 include/service-adapter/protocol-binder/oma_ds_protocol_binder.h create mode 100755 include/service-adapter/protocol-binder/oma_ds_protocol_binder_definition.h create mode 100755 include/service-adapter/sa_command.h create mode 100755 include/service-adapter/sa_command_internal.h create mode 100755 include/service-adapter/sa_common_interface.h create mode 100755 include/service-adapter/sa_define.h create mode 100755 include/service-adapter/sa_devinf.h create mode 100755 include/service-adapter/sa_devinf_internal.h create mode 100755 include/service-adapter/sa_elements.h create mode 100755 include/service-adapter/sa_elements_internal.h create mode 100755 include/service-adapter/sa_error.h create mode 100755 include/service-adapter/sa_session.h create mode 100755 include/service-adapter/sa_session_internal.h create mode 100755 include/service-adapter/sa_util.h create mode 100755 include/service-engine/se_account.h create mode 100755 include/service-engine/se_common.h create mode 100755 include/service-engine/se_error.h create mode 100755 include/service-engine/se_notification.h create mode 100755 include/service-engine/se_storage.h create mode 100755 include/service-engine/se_sync.h create mode 100755 oma-ds create mode 100644 oma-ds-agent.manifest create mode 100644 oma-ds-cfg/eventconfig_omads create mode 100644 oma-ds-cfg/noticonfig_omads create mode 100644 oma-ds-cfg/omadsUI_fw_config.xml create mode 100644 oma-ds-cfg/omads_fw_config.xml create mode 100755 packaging/oma-ds-agent.spec create mode 100755 src/agent/CMakeLists.txt create mode 100755 src/agent/common/common_define.c create mode 100755 src/agent/common/common_util.c create mode 100755 src/agent/common/common_vconf.c create mode 100755 src/agent/framework/event/oma_ds_event_handler.c create mode 100755 src/agent/framework/event/oma_ds_platform_event_handler.c create mode 100755 src/agent/framework/san-parser/pm_sanparser.c create mode 100755 src/agent/framework/task/oma_ds_engine_controller_task.c create mode 100755 src/agent/main/main.c create mode 100755 src/agent/service-adapter/network-binder/na_binder.c create mode 100755 src/agent/service-adapter/protocol-binder/oma_ds_protocol_binder.c create mode 100755 src/agent/service-adapter/sa_command.c create mode 100755 src/agent/service-adapter/sa_common_interface.c create mode 100755 src/agent/service-adapter/sa_devinf.c create mode 100755 src/agent/service-adapter/sa_elements.c create mode 100755 src/agent/service-adapter/sa_session.c create mode 100755 src/agent/service-adapter/sa_util.c create mode 100755 src/agent/service-engine/se_account.c create mode 100755 src/agent/service-engine/se_notification.c create mode 100755 src/agent/service-engine/se_storage.c create mode 100755 src/agent/service-engine/se_sync.c create mode 100644 src/plugins/CMakeLists.sub create mode 100644 src/plugins/CMakeLists.txt create mode 100755 src/plugins/ds-public/CMakeLists.txt create mode 100755 src/plugins/ds-public/plain-text/CMakeLists.txt create mode 100755 src/plugins/ds-public/plain-text/include/in_datastore_info_plain_text.h create mode 100755 src/plugins/ds-public/plain-text/src/plugin_interface.c create mode 100755 src/plugins/ds-public/vcard/CMakeLists.txt create mode 100755 src/plugins/ds-public/vcard/include/encoding_util.h create mode 100755 src/plugins/ds-public/vcard/include/in_datastore_info_vcard.h create mode 100755 src/plugins/ds-public/vcard/include/plugin_spec.h create mode 100755 src/plugins/ds-public/vcard/src/encoding_util.c create mode 100755 src/plugins/ds-public/vcard/src/plugin_interface.c create mode 100755 src/plugins/ds-public/xcalllog/CMakeLists.txt create mode 100755 src/plugins/ds-public/xcalllog/include/encoding_util.h create mode 100755 src/plugins/ds-public/xcalllog/include/plugin_spec.h create mode 100755 src/plugins/ds-public/xcalllog/src/encoding_util.c create mode 100755 src/plugins/ds-public/xcalllog/src/plugin_interface.c create mode 100755 test/include/suites/unit_test_sample_suite.h create mode 100755 test/include/unit_test_common.h create mode 100755 test/include/unit_test_run.h create mode 100755 test/include/unit_test_suites.h create mode 100755 test/src/oma_test_main.c create mode 100755 test/src/suites/unit_test_sample_suite.c create mode 100755 test/src/unit_test_run.c diff --git a/AUTHORS b/AUTHORS new file mode 100755 index 0000000..b5328d5 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,4 @@ +WooJin Yun +JooHark Park +SangHyuk Ko +JunHyung Park diff --git a/BuildFlags.cmake b/BuildFlags.cmake new file mode 100644 index 0000000..8e64bcd --- /dev/null +++ b/BuildFlags.cmake @@ -0,0 +1,32 @@ +# Set default build flags + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF() + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -Werror -Wno-deprecated-declarations") +SET(CMAKE_C_FLAGS_DEBUG "-O0") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed") +SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--as-needed") +SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed") + +MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") +MESSAGE(STATUS "Compile flags: ${CMAKE_C_FLAGS}") +MESSAGE(STATUS "Exe linker flags: ${CMAKE_EXE_LINKER_FLAGS}") +MESSAGE(STATUS "Module linker flags: ${CMAKE_MODULE_LINKER_FLAGS}") +MESSAGE(STATUS "Shared linker flags: ${CMAKE_SHARED_LINKER_FLAGS}") + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + ADD_DEFINITIONS("-DDEBUG") +ENDIF() + +MACRO(get_version _file _ver _ver_maj) + FILE(STRINGS ${_file} __log LIMIT_COUNT 1 REGEX "(.*)") + STRING(REGEX REPLACE ".*\\(\([0-9]+:\)*\([0-9a-zA-Z.]*\).*\\).*" "\\2" __ver ${__log}) + STRING(REGEX REPLACE "^\([0-9]+\)\\..*" "\\1" __ver_maj ${__ver}) + SET(${_ver} ${__ver}) + SET(${_ver_maj} ${__ver_maj}) +ENDMACRO(get_version) + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7ddc553 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +INCLUDE(BuildFlags.cmake) + +SET(CMAKE_SKIP_BUILD_RPATH TRUE) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(PLUGINDIR "${PREFIX}/lib/${PROJECT_NAME}") + +# get library version from debian/changelog +get_version(debian/changelog VERSION VERSION_MAJOR) +MESSAGE(STATUS "Package version is ${VERSION} (major: ${VERSION_MAJOR}) from changelog") + +# pass macro defition to source files +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +ADD_DEFINITIONS("-DPLUGINDIR=\"${PLUGINDIR}\"") + +ADD_DEFINITIONS("-DCOMPONENT_TAG=SYSTEM") +ADD_DEFINITIONS("-DOMADS_AGENT_LOG") +ADD_DEFINITIONS("-DLOG_TAG=\"OMA_DS_AGENT\"") + +# include source files +ADD_SUBDIRECTORY(src/agent) +ADD_SUBDIRECTORY(src/plugins) + diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100755 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/NOTICE b/NOTICE new file mode 100755 index 0000000..ccdad52 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE file for Apache License terms and conditions. diff --git a/com.samsung.omadsagent.service b/com.samsung.omadsagent.service new file mode 100755 index 0000000..15ae0c5 --- /dev/null +++ b/com.samsung.omadsagent.service @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=com.samsung.omadsagent +Exec=/usr/bin/oma-ds-agent diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..d9f499e --- /dev/null +++ b/debian/changelog @@ -0,0 +1,47 @@ +oma-ds-agent (0.1.6) unstable; urgency=low + + * 1. license file update. + * Git: framework/system/oma-ds-agent + * Tag: oma-ds-agent_0.1.6 + + -- Juhaki Park Mon, 21 Jan 2013 22:09:10 +0900 + +oma-ds-agent (0.1.5) unstable; urgency=low + + * 1. Revised for version release + * Git: framework/system/oma-ds-agent + * Tag: oma-ds-agent_0.1.5 + + -- Juhaki Park Thu, 10 Jan 2013 10:06:10 +0900 + +oma-ds-agent (0.1.4) unstable; urgency=low + + * 1. Revised for version release + * Git: framework/system/oma-ds-agent + * Tag: oma-ds-agent_0.1.4 + + -- WooJin Yun Wed, 09 Jan 2013 19:42:10 +0900 + +oma-ds-agent (0.1.3) unstable; urgency=low + + * 1. Fixes for Prevent defects + * Git: framework/system/oma-ds-agent + * Tag: oma-ds-agent_0.1.3 + + -- sanghyuk.ko Wed, 09 Jan 2013 17:31:34 +0900 + +oma-ds-agent (0.1.2) unstable; urgency=low + + * 1. Internal: build error & dependency patch + * Git: framework/system/oma-ds-agent + * Tag: oma-ds-agent_0.1.2 + + -- WooJin Yun Fri, 28 Dec 2012 22:47:52 +0900 + +oma-ds-agent (0.1.1) unstable; urgency=low + + * Initial Update + * Git: framework/system/oma-ds-agent + * Tag: oma-ds-agent_0.1.1 + + -- WooJin Yun Wed, 01 Feb 2012 10:30:16 +0900 diff --git a/debian/control b/debian/control new file mode 100755 index 0000000..5166e62 --- /dev/null +++ b/debian/control @@ -0,0 +1,22 @@ +Source: oma-ds-agent +Section: embedded +Priority: optional +Maintainer: WooJin Yun , Joohark Park , Junhyuk Lee +Uploaders: Joohark Park , Junhyuk Lee +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-agent +Section: embedded +Architecture: any +Priority: optional +Depends: ${shlibs:Depends}, ${misc:Depends}, +Description: OMA Data Synchronization service module + +Package: oma-ds-agent-dbg +Section: debug +Architecture: any +Priority: optional +Depends: ${shlibs:Depends}, ${misc:Depends}, oma-ds-agent (= ${Source-Version}) +Description: OMA Data Synchronization service module (unstripped) + diff --git a/debian/control.slp b/debian/control.slp new file mode 100644 index 0000000..20474e7 --- /dev/null +++ b/debian/control.slp @@ -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 index 0000000..711fa30 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,45 @@ +#!/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 "create oma-ds directory" +if [ ! -d /opt/data/oma-ds ] +then + mkdir /opt/data/oma-ds +fi + +echo "deleting framework db files" +if [ -d /usr/share/sync-agent-framework ] +then + rm -rf /usr/share/sync-agent-framework +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 index 0000000..a28c17d --- /dev/null +++ b/debian/rules @@ -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-agent + -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/S91oma-ds-agent + + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d + ln -s ../init.d/syncmld_mgr $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S91oma-ds-agent + +# 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-agent + 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/ds-public-plugins.manifest b/ds-public-plugins.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/ds-public-plugins.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/include/common/common_define.h b/include/common/common_define.h new file mode 100755 index 0000000..4612b39 --- /dev/null +++ b/include/common/common_define.h @@ -0,0 +1,1191 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 datastore_info_s 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 datastore_info_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +datastore_info_s *create_datastore_info(char *target, char *source); + +/** + * @par Description: API to free list of datastore_info_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] list of datastore_info_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_datastore_infos(GList * datastore_infos); + +/** + * @par Description: API to free datastore_info_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_info_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_datastore_info(datastore_info_s * datastore_info); + +/** + * @par Description: API to set sync type in datastore_info_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_info_s 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_info_sync_type(datastore_info_s * datastore_info, alert_type_e sync_type); + +/** + * @par Description: API to set last anchor in datastore_info_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_info_s 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_datastore_info_last_anchor(datastore_info_s * datastore_info, char *last_anchor); + +/** + * @par Description: API to set next anchor in datastore_info_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_info_s 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_datastore_info_next_anchor(datastore_info_s * datastore_info, char *next_anchor); + +/** + * @par Description: API to set max_obj_size in datastore_info_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_info_s structure + * @param[in] unsigned int, max_obj_size + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_datastore_info_max_obj_size(datastore_info_s * datastore_info, unsigned int max_obj_size); + +/** + * @par Description: API to create changed_item_s 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 changed_item_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +changed_item_s *create_changed_item(change_type_e type, char *luid); + +/** + * @par Description: API to free changed_item_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] changed_item_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_changed_item(changed_item_s * changed_item); + +/** + * @par Description: API to set content type in changed_item_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] changed_item_s 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_changed_item_content_type(changed_item_s * changed_item, char *content_type); + +/** + * @par Description: API to set data in changed_item_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] changed_item_s structure + * @param[in] string type, data + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_changed_item_data(changed_item_s * changed_item, char *data); + +/** + * @par Description: API to set in changed_item_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] changed_item_s 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_changed_item_index_of_datastore(changed_item_s * changed_item, unsigned int indexOfDatastore); + +/** + * @par Description: API to create changed_datastore_s 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 changed_datastore_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +changed_datastore_s *create_changed_datastore(char *source, char *target, int has_number_of_changes, unsigned int number_of_changes); + +/** + * @par Description: API to free list of changed_datastore_s + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] list of changed_datastore_s + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_changed_datastores(GList * changed_datastores); + +/** + * @par Description: API to free changed_datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] changed_datastore_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_changed_datastore(changed_datastore_s * changed_datastore); + +/** + * @par Description: API to set changed_item in changed_datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] changed_datastore_s structure + * @param[in] list of changed_item_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_changed_datastore_changed_item(changed_datastore_s * changed_datastore, GList * changed_item); + +/** + * @par Description: API to add changed_item in changed_datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] changed_datastore_s structure + * @param[in] changed_item_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void add_changed_datastore_changed_item(changed_datastore_s * changed_datastore, changed_item_s * changed_item); + +/** + * @par Description: API to create applied_status_s 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 applied_status_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +applied_status_s *create_applied_status(char *luid, change_type_e change_type, int status); + +/** + * @par Description: API to free list of applied_status_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] list of applied_status_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_applied_statuses(GList * applied_statuses); + +/** + * @par Description: API to free applied_status_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] applied_status_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_applied_status(applied_status_s * applied_status); + +/** + * @par Description: API to create sending_status_s 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 sending_status_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sending_status_s *create_sending_status(char *source, char *target); + +/** + * @par Description: API to free list of sending_status_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] list of sending_status_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_sending_statuses(GList * sending_statuses); + +/** + * @par Description: API to free sending_status_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sending_status_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_sending_status(sending_status_s * sending_status); + +/** + * @par Description: API to add applied_status_s in sending_status_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sending_status_s structure + * @param[in] applied_status_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void add_sending_status_applied_status(sending_status_s * sending_status, applied_status_s * applied_status); + +/** + * @par Description: API to create datastore_s 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_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +datastore_s *create_datastore(char *target, char *source); + +/** + * @par Description: API to set content type infomation in datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_s 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_content_type_info(datastore_s * datastore, int datastore_id, int folder_type_id); + +/** + * @par Description: API to set account information in datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_s 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_s * datastore, char *account_id, char *account_pw); + +/** + * @par Description: API to set client sync type in datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_s 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_s * datastore, alert_type_e sync_type); + +/** + * @par Description: API to set server sync type in datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_s 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_s * datastore, alert_type_e sync_type); + +/** + * @par Description: API to set client anchor in datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_s 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_s * datastore, char *last_anchor, char *next_anchor); + +/** + * @par Description: API to set client anchor in datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_s 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_s * datastore, char *last_anchor, char *next_anchor); + +/** + * @par Description: API to create sync_result_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_s structure + * @param[in] string type, last anchor + * @param[in] string type, next anchor + * @param[out] + * + * @return sync_result_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_result_s *create_sync_result(); + +/** + * @par Description: API to duplicate sync_result_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_result_s structure + * @param[out] + * + * @return sync_result_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_result_s *dup_sync_result(sync_result_s * org_sync_result); + +/** + * @par Description: API to set number of total item in sync_result_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_result_s 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_number_of_change(sync_result_s * sync_result, unsigned int number_of_change); + +/** + * @par Description: API to set number of received item in sync_result_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_result_s 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(sync_result_s * sync_result, unsigned int received_count); + +/** + * @par Description: API to set number of add item in sync_result_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_result_s 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(sync_result_s * sync_result, unsigned int add_cnt); + +/** + * @par Description: API to set number of replace item in sync_result_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_result_s 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(sync_result_s * sync_result, unsigned int replace_cnt); + +/** + * @par Description: API to set number of delete item in sync_result_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_result_s 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(sync_result_s * sync_result, 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] pre_sync_return_obj_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_pre_sync_return_obj(pre_sync_return_obj_s * pre_sync_return_obj); + +/** + * @par Description: API to free sync_obj_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_obj_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_sync_obj(sync_obj_s * sync_obj); + +/** + * @par Description: API to free sync_return_obj_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_return_obj_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_sync_return_obj(sync_return_obj_s * sync_return_obj); + +/** + * @par Description: API to free datastore_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] datastore_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_datastore(datastore_s * datastore); + +/** + * @par Description: API to free sync_category structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_service_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_sync_service(sync_service_s * category); + +#endif /* COMMON_DEFINE_H_ */ diff --git a/include/common/common_define_internal.h b/include/common/common_define_internal.h new file mode 100755 index 0000000..c3078de --- /dev/null +++ b/include/common/common_define_internal.h @@ -0,0 +1,307 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include +#include +#include + +/* #define COMMUNICATION_TYPE SYNC_AGENT_PB_ENCODING_XML */ +#define COMMUNICATION_TYPE SYNC_AGENT_PB_ENCODING_WBXML_12 + +#define TRANSPORT_TYPE 1 /*http */ + /*#define TRANSPORT_TYPE "FW_MOBEX" *//*mobex -> does not support in OMA */ + +#define NETWORK_TIMEOUT 60 + +#define MAXIMUM_ACCOUNT_COUNT 5 + +#define PKG_NAME "oma-ds-agent" +#define DEFINE_PLATFORM 1 +#define LOW_BATTERY_LEVEL 10 + +#define OMA_DS_MSG_PATH "/opt/usr/data/oma-ds/debug_msg" +#define OMA_DS_CSC_CHECK_PATH "/opt/usr/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_XCALLLOG "text/x-calllog" +#define ELEMENT_TEXT_MESSAGE "text/x-vMessage" + +#define DEFINE_ALERT_UNKNOWN_STR "Unknown" +#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_RESUME "Resume" +#define DEFINE_CONFIG_KEY_PROFILE_NAME "Name" +#define DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE "Client_Sync_type" +#define DEFINE_CONFIG_KEY_PROFILE_SERVER_SYNC_TYPE "Server_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_DIVE_SERVER_URL_HTTPS "https://syn.samsungdive.com/sync" +#define DEFINE_DIVE_SERVER_URL_HTTP "http://syn.samsungdive.com/sync" +#define DEFINE_DIVE_SERVER_ID "syn.samsungdive.com" +#define DEFINE_DIVE_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 +} sync_session_result_e; + +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, + ALERT_SUSPEND = 224, + ALERT_RESUME = 225, +} alert_type_e; + +typedef enum { + CHANGE_UNKNOWN = 0, + CHANGE_ADD = 1, + CHANGE_REPLACE = 2, + CHANGE_DELETE = 3 +} change_type_e; + +typedef enum { + TYPE_CONTACT = 0, + TYPE_CALENDAR, + TYPE_MEMO, + TYPE_CALLLOG, + + TYPE_SERVICE_COUNT +} service_type_e; + +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_SUSPEND_FAIL = 209, + COMMON_CANCEL = 300, +} common_error_type_e; + +typedef struct { + sync_session_result_e session_result; + unsigned int number_of_change; + unsigned int received_count; + unsigned int add_count; + unsigned int replace_count; + unsigned int delete_count; +} sync_result_s; + +/** + * @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 */ + alert_type_e client_sync_type; /**< Sync Type(two-way, one-way ...) */ + alert_type_e server_sync_type; /**< Sync Type(two-way, one-way ...) */ + char *last_anchor_client; /**< Last Anchor of datastore for client side */ + char *next_anchor_client; /**< Next Anchor of datastore for client side */ + char *last_anchor_server; /**< Next Anchor of datastore for server side */ + char *next_anchor_server; /**< Next Anchor of datastore for server side */ + sync_result_s *client_sync_result; + sync_result_s *server_sync_result; +} datastore_s; + +typedef struct { + char *target; /**< target(server) URI */ + char *source; /**< source(client) URI */ + alert_type_e sync_type; /**< Sync Type(two-way, one-way ...) */ + char *last_anchor; /**< Last Anchor of datastore for client side */ + char *next_anchor; /**< Next Anchor of datastore for client side */ + unsigned int max_obj_size; +} datastore_info_s; + +/** + @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 *datastore_info; /**< containing datastore_info structure*/ + char *dev_id; +} pre_sync_return_obj_s; + +/** + @brief a changed item(changelog) + + */ +typedef struct { + change_type_e change_type; /**< type of changes (add, replace, delete, copy, move ..) */ + char *luid; /**< luid of item */ + char *content_type; /**< content type of data */ + unsigned int index_of_datastore; + char *data; /**< data */ +} changed_item_s; + +/** + @brief item that are grouped by each Data Store + + */ +typedef struct { + char *source; /**< source(client) URI */ + char *target; /**< target(server) URI */ + int need_sync_command; + unsigned int number_of_changes; + int has_number_of_changes; + + GList *change_item; /**< containing changed_item all type */ + GList *sent_item; /**< containing changed_item */ +} changed_datastore_s; + +/** + @brief result of applied command that from service engine or server + + */ +typedef struct { + change_type_e change_type; /**< change type (add, replace, delete...) */ + char *luid; /**< luid of item */ + int status; /**< status of applied item */ +} applied_status_s; + +typedef struct { + char *source; /**< source(client) URI */ + char *target; /**< target(server) URI */ + GList *items; /**< containing appllied_status struct */ +} sending_status_s; + +/** + @brief second and third parameter of sync function + + */ +typedef struct { + GList *changed_datastore; /**< containing changed_datastore structure when it's in SyncObj it will be command that client send to server */ + GList *sending_status; /**< containing sending_status structure when it's in SyncObj status of add, replace, delete command from server */ +} sync_obj_s; + +typedef struct { + GList *changed_datastore; /**< containing changed_datastore structure when it's in SyncReturnObj command(add, relpace, delete) from server */ + GList *status; /**< containing applied_status structure when it's in SyncReturnObj return to engine(status of add, replace, delete command that client sent to server)*/ +} sync_return_obj_s; + +typedef struct { + service_type_e service_type; + int enabled; + char *src_uri; + char *tgt_uri; + char *id; + char *password; +} sync_service_s; + +typedef struct { + char *name; + char *accept; + char *id; + char *password; + char *auth_type; + char *auth_data; +} resource_cp_s; + +extern datastore_s *datastoreinfo_per_content_type[4]; + +#endif /* COMMON_DEFINE_INTERNAL_H_ */ diff --git a/include/common/common_util.h b/include/common/common_util.h new file mode 100755 index 0000000..ce10a90 --- /dev/null +++ b/include/common/common_util.h @@ -0,0 +1,187 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 + +/** + * @par Description: API to create sync_agent_da_config_s structure + * + * + * @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] sync_agent_da_config_s + * + * @return true on success + * false on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +bool create_config_str(int account_id, char *key, char *value, char *type, char *access_name, sync_agent_da_config_s ** config); + +/** + * @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 account_id, char *key, char *value, char *type, char *access_name); + +/** + * @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 account_id, char *key, int value, char *type, char *access_name); + +/** + * @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 account_id, 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_account_id(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 100755 index 0000000..19cbcd7 --- /dev/null +++ b/include/common/common_vconf.h @@ -0,0 +1,249 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 + +/** + * @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 *base_key, 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 *base_key, 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 *base_key, 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 *base_key, 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/csc_keys.h b/include/common/csc_keys.h new file mode 100755 index 0000000..d34c3a3 --- /dev/null +++ b/include/common/csc_keys.h @@ -0,0 +1,50 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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/SyncML/oma-ds-agent/DS/Accounts/NbDataSync" +#define CSC_VCONF_KEY_SYNCMLDS_NETWORK "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/NetworkName" +#define CSC_VCONF_KEY_SYNCMLDS_VERSION "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/DSVersion" +#define CSC_VCONF_KEY_SYNCMLDS_NAME "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Name" +#define CSC_VCONF_KEY_SYNCMLDS_ADDR "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/AppAddr/Addr" +#define CSC_VCONF_KEY_SYNCMLDS_AUTHNAME "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/AuthInfo/Client/AuthName" +#define CSC_VCONF_KEY_SYNCMLDS_AUTHPWD "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/AuthInfo/Client/AuthPWD" +#define CSC_VCONF_KEY_SYNCMLDS_SYNCTYPE "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/GUI/SyncType" +#define CSC_VCONF_KEY_SYNCMLDS_SYNCMODE "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/GUI/SyncMode" +#define CSC_VCONF_KEY_SYNCMLDS_CONTACTS_ENABLED "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Contacts/Enabled" +#define CSC_VCONF_KEY_SYNCMLDS_CONTACTS_TGTURI "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Contacts/TgtURI" +#define CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHNAME "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Contacts/AuthInfo/Server/AuthName" +#define CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHPWD "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Contacts/AuthInfo/Server/AuthPWD" +#define CSC_VCONF_KEY_SYNCMLDS_CALENDAR_ENABLED "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Calendar/Enabled" +#define CSC_VCONF_KEY_SYNCMLDS_CALENDAR_TGTURI "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Calendar/TgtURI" +#define CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHNAME "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Calendar/AuthInfo/Server/AuthName" +#define CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHPWD "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Calendar/AuthInfo/Server/AuthPWD" +#define CSC_VCONF_KEY_SYNCMLDS_MEMO_ENABLED "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Memo/Enabled" +#define CSC_VCONF_KEY_SYNCMLDS_MEMO_TGTURI "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Memo/TgtURI" +#define CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHNAME "db/SyncML/oma-ds-agent/DS/Accounts/Sync%d/Resource/Memo/AuthInfo/Server/AuthName" +#define CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHPWD "db/SyncML/oma-ds-agent/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 100755 index 0000000..27bf66b --- /dev/null +++ b/include/framework/event/oma_ds_event_handler.h @@ -0,0 +1,354 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include + +/** + * @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(sync_agent_event_data_s * request, sync_agent_event_data_s * 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(sync_agent_event_data_s * request, sync_agent_event_data_s * 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(sync_agent_event_data_s * request, sync_agent_event_data_s * 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_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * 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_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response); + +/** + * @par Description: This API is event callback function for get profile data + * + * + * @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_data_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * 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(sync_agent_event_data_s * request, sync_agent_event_data_s * 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(sync_agent_event_data_s * request, sync_agent_event_data_s * 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(sync_agent_event_data_s * request, sync_agent_event_data_s * response); + +/** + * @par Description: This API is event callback function for request callog 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_calllog_sync_async(sync_agent_event_data_s * request, sync_agent_event_data_s * response); + +/** + * @par Description: This API is event callback function for request reset all data + * + * + * @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_reset_all_data_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response); + +/** + * @par Description: This API is event callback function for request reset all data + * + * + * @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_get_all_profiles_data(sync_agent_event_data_s * request, sync_agent_event_data_s * 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 100755 index 0000000..4305e43 --- /dev/null +++ b/include/framework/event/oma_ds_platform_event_handler.h @@ -0,0 +1,114 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include +#include + +/** + * @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 1 on success + * 0 on fail + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int san_callback_parse(int item_id, void *user_data); + +/** + * @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 scheduler_id, void *data); + +/** + * @par Description: This API is for receive ip push msg from event + * + * Parse ip push msg and request sync + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] data(ip push message) + * + * @return 1 on success + * 0 on fail + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int send_ip_push_sync_msg(char *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 100755 index 0000000..47b5bf5 --- /dev/null +++ b/include/framework/san-parser/pm_sanparser.h @@ -0,0 +1,224 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @PM_SanParser.h + * @version 0.1 + * @brief This file is the header file of interface and defined structure for San Parser + */ + +#ifndef PM_SANPARSER_H_ +#define PM_SANPARSER_H_ + +/* FIXME : When initialize, set "Server_id" at config_tbl.. +#define SMLDS_MOBILEDIT_SERVER (char *)"mobiledit" +#define SMLDS_FUNAMBOL_SERVER (char *)"funambol" +#define SMLDS_O3SIS_SERVER_SAN_IDENTIFIER (char *)"O3SIS SyncML Server" +*/ + +typedef enum { + SAN_UIMODE_UNSPECIFIED = 0, + SAN_UIMODE_BACKGROUND = 1, + SAN_UIMODE_INFORMATIVE = 2, + SAN_UIMODE_USER = 3 +} san_ui_mode_e; + +typedef enum { + SAN_INITIATOR_USER = 0, + SAN_INITIATOR_SERVER = 1 +} san_initiator_e; + +typedef enum { + SAN_SYNC_TYPE_TWO_WAY_BY_SERVER = 206, + SAN_SYNC_TYPE_ONE_WAY_FROM_CLIENT_BY_SERVER = 207, + SAN_SYNC_TYPE_REFRESH_FROM_CLIENT_BY_SERVER = 208, + SAN_SYNC_TYPE_ONE_WAY_FROM_SERVER_BY_SERVER = 209, + SAN_SYNC_TYPE_REFRESH_FROM_SERVER_BY_SERVER = 210, +} san_sync_type_e; + +typedef struct san_cred san_cred_s; +struct san_cred { + char *cred_format; + char *cred_auth; + char *cred_data; +}; + +typedef struct san_content_type san_content_type_s; +struct san_content_type { + unsigned int type; + char *strType; +}; + +typedef struct san_sync_alert san_sync_alert_s; +struct san_sync_alert { + san_sync_type_e sync_type; + char *content_type; + char *server_uri; +}; + +typedef struct san_package san_package_s; +struct san_package { + char *msg_body_without_digest; + unsigned int msg_body_without_digest_length; + char *digest; + unsigned int version; + san_ui_mode_e ui_mode; + san_initiator_e initiator; + unsigned int session_id; + san_cred_s *cred; + char *server_id; + unsigned int cnt_sync_alerts; + san_sync_alert_s *sync_alerts; +}; + +/** + * @par Description: API to parse for SAN version 1.2 + * + * + * @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[out] + * + * @return san_package_s structure on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +san_package_s *san_package_12_parser(const char *msg_body, unsigned int msg_size); + +/** + * @par Description: API to parse for SAN version 1.1 + * + * + * @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[out] + * + * @return san_package_s structure on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +san_package_s *san_package_11_parser(const char *msg_body, unsigned int msg_size); + +/** + * @par Description: API to free san_package_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] san_package_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void sanPackageParserFree(void *point); + +/** + * @par Description: API to print SAN msg for debugging + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] san_package_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void sanPrintMsg(san_package_s * san); + +/** + * @par Description: API to parse ip push message + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] data(ip push message) + * @param[out] san_package_s structure + * @param[out] id + * + * @return 1 on success + * 0 on fail + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int parse_ip_push_msg(char *data, san_package_s ** sanpackage, char **id); + +#endif /* PM_SANPARSER_H_ */ 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 100755 index 0000000..f4b3ccc --- /dev/null +++ b/include/framework/task/oma_ds_engine_controller_task.h @@ -0,0 +1,975 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include + +#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; +}; + +#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 2 +#define EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE "add_profile" +#define EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE 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_GET_PROFILE_DATA 6 +#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_DATA "get_profile_data" +#define EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY 7 +#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY "get_profile_sync_category" +#define EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS 8 +#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_STATISTICS "get_profile_statistics" +#define EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES 9 +#define EC_MSG_TYPE_NAME_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES "reset_synchronizing_profiles" +#define EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST 10 +#define EC_MSG_TYPE_NAME_SYNC_TASK_CANCEL_SYNC_REQUEST "cancel_sync_request" +#define EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP 11 +#define EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE_CP "add_profile_cp" +#define EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE 12 +#define EC_MSG_TYPE_NAME_SYNC_TASK_REFRESH_FROM_SERVICE "refresh_from_service" +#define EC_MSG_TYPE_SYNC_TASK_RESET_ALL_DATA 13 +#define EC_MSG_TYPE_NAME_SYNC_TASK_RESET_ALL_DATA "reset_all_data" +#define EC_MSG_TYPE_SYNC_TASK_GET_ALL_PROFILES_DATA 14 +#define EC_MSG_TYPE_NAME_SYNC_TASK_GET_ALL_PROFILES_DATA "get_all_profiles_data" + +/** + * @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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *make_delete_profile_task(); + +/** + * @par Description: API to create get profile data task + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] + * @param[out] + * + * @return sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *make_get_profile_data_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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *make_get_profile_sync_category_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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *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 sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *make_refresh_from_service_task(); + +/** + * @par Description: API to create cancel network session task + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] + * @param[out] + * + * @return sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *make_cancel_request_task(); + +/** + * @par Description: API to reset all data + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] + * @param[out] + * + * @return sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *make_reset_all_data_task(); + +/** + * @par Description: API to get all profiles data + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] + * @param[out] + * + * @return sync_agent_ec_task_spec_s structure on success + * NYLL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_spec_s *make_get_all_profiles_data_task(); +/** + * @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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e synchronize_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e add_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e edit_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e delete_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e get_profile_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e get_profile_sync_category_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e get_profile_statistics_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e reset_synchronizing_profiles_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array); + +/** + * @par Description: This API is callback function which runs when cancel 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e cancel_sync_request_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array); + +/** + * @par Description: This API is callback function which runs when reset function 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e reset_all_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array); + +/** + * @par Description: This API is callback function which runs when reset function 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e get_all_profiles_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e add_profile_cp_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success + * SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_ec_task_error_e refresh_from_service_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** 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 *request_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 *request_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 *request_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 *request_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 *request_id); + +/** + * @par Description: cancel current sync task(auto configure task or sync task) + * + * if auto configure task is processing, cancel auto configure task + * if sync task is processing, cancel sync task + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] + * @param[out] + * + * @return true on success + * false on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +bool cancel_current_sync_task(); + +#endif /* ENGINE_CONTROLLER_TASK_H_ */ diff --git a/include/service-adapter/network-binder/na_binder.h b/include/service-adapter/network-binder/na_binder.h new file mode 100755 index 0000000..a229bd2 --- /dev/null +++ b/include/service-adapter/network-binder/na_binder.h @@ -0,0 +1,85 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include "service-adapter/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 *acc_type, char *loc_uri, bool is_xml, char *jsession_id, GList ** list); + +/** + * @par Description: API to free sync_agent_na_common_header_info_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_agent_na_common_header_info_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_header_info(sync_agent_na_common_header_info_s * common_header_info); + +#endif /* NA_BINDER_H_ */ diff --git a/include/service-adapter/protocol-binder/oma_ds_protocol_binder.h b/include/service-adapter/protocol-binder/oma_ds_protocol_binder.h new file mode 100755 index 0000000..ab25ad2 --- /dev/null +++ b/include/service-adapter/protocol-binder/oma_ds_protocol_binder.h @@ -0,0 +1,314 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include "service-adapter/protocol-binder/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] sync_agent_pb_protocol_binder_function_set_s structure + * @param[out] + * + * @return sync_agent_pb_error_e type + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_pb_error_e init_oma_ds_1_2_binder_function_set(sync_agent_pb_protocol_binder_function_set_s ** binder_function_set); + +/** + * @par Description: API to free sync_agent_pb_protocol_binder_function_set_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_agent_pb_protocol_binder_function_set_s 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(sync_agent_pb_protocol_binder_function_set_s * binder_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] sync_agent_pb_protocol_binder_info_s structure + * @param[in] enum type, sync_agent_pb_encoding_e(SYNC_AGENT_PB_ENCODING_XML, SYNC_AGENT_PB_ENCODING_WBXML_10, SYNC_AGENT_PB_ENCODING_WBXML_11, SYNC_AGENT_PB_ENCODING_WBXML_12, SYNC_AGENT_PB_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] boolean type, whether use textual public id or not + * @param[in] sync_agent_pb_protocol_binder_function_set_s structure + * @param[out] + * + * @return sync_agent_pb_protocol_binder_info_s on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_pb_protocol_binder_info_s *oma_ds_1_2_binder_init(sync_agent_pb_protocol_binder_info_s * binder, sync_agent_pb_encoding_e enc, bool encode_xml_header, + bool use_strtbl, bool produce_anonymous, bool use_flow_mode, bool text_public_id, sync_agent_pb_protocol_binder_function_set_s * binder_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] sync_agent_pb_protocol_binder_info_s structure + * @param[in] enum type, protocol element + * @param[in] content(structure to append) + * @param[out] + * + * @return SYNC_AGENT_PB_RETURN_OK on success + * others on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_pb_error_e oma_ds_1_2_binder_append(sync_agent_pb_protocol_binder_info_s * binder, oma_ds_protocol_element_e protocol_element, Content_Ptr content); + +/** + * @par Description: API to terminate sync_agent_pb_protocol_binder_info_s structure + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_agent_pb_protocol_binder_info_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void oma_ds_1_2_binder_terminate(sync_agent_pb_protocol_binder_info_s * binder); + +/** + * @par Description: API to get stream + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_agent_pb_protocol_binder_info_s structure + * @param[out] string type, stream from WBXML tree + * @param[out] unsigned int type, size of stream + * + * @return SYNC_AGENT_PB_RETURN_OK on success + * others on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_pb_error_e oma_ds_1_2_binder_get_stream(sync_agent_pb_protocol_binder_info_s * binder, 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] sync_agent_pb_protocol_binder_info_s structure + * @param[out] unsigned int type, size of stream + * + * @return SYNC_AGENT_PB_RETURN_OK on success + * others on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_pb_error_e oma_ds_1_2_binder_get_stream_size(sync_agent_pb_protocol_binder_info_s * binder, 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] sync_agent_pb_protocol_binder_info_s structure + * @param[out] enum type, sync_agent_pb_encoding_e(SYNC_AGENT_PB_ENCODING_XML, SYNC_AGENT_PB_ENCODING_WBXML_10, SYNC_AGENT_PB_ENCODING_WBXML_11, SYNC_AGENT_PB_ENCODING_WBXML_12, SYNC_AGENT_PB_ENCODING_WBXML_13) + * + * @return SYNC_AGENT_PB_RETURN_OK on success + * others on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_pb_error_e oma_ds_1_2_binder_get_encoding(sync_agent_pb_protocol_binder_info_s * binder, sync_agent_pb_encoding_e * 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(SYNC_AGENT_PB_DECODING_XML, SYNC_AGENT_PB_DECODING_WBXML) + * @param[in] user data + * @param[out] sync_agent_pb_protocol_binder_reverse_info_s structure + * + * @return SYNC_AGENT_PB_RETURN_OK on success + * others on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_pb_error_e reverse_oma_ds_1_2_binder_init(char *byte_stream, + unsigned int byte_stream_len, sync_agent_pb_decoding_e dec, sync_agent_pb_protocol_binder_function_set_s * binder_function_set, void *user_data, sync_agent_pb_protocol_binder_reverse_info_s ** binder); + +/** + * @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] sync_agent_pb_protocol_binder_reverse_info_s structure + * @param[out] protocol element + * @param[out] string type, protocol element + * @param[out] parsed contents(defined structure) + * + * @return SYNC_AGENT_PB_RETURN_OK on success + * others on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +sync_agent_pb_error_e reverse_oma_ds_1_2_binder_next(sync_agent_pb_protocol_binder_reverse_info_s * binder, Protocol_Element * protocol_element, char **protocol_element_name, Content_Ptr * content); + +#endif /* OMA_DS_PROTOCOL_BINDER_H_ */ diff --git a/include/service-adapter/protocol-binder/oma_ds_protocol_binder_definition.h b/include/service-adapter/protocol-binder/oma_ds_protocol_binder_definition.h new file mode 100755 index 0000000..a74bde5 --- /dev/null +++ b/include/service-adapter/protocol-binder/oma_ds_protocol_binder_definition.h @@ -0,0 +1,188 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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_ + +#define SYNC_AGENT_INIT_ESTIMATE_DOC_SIZE 20 + +/* SyncML */ +#define ELEMENT_SYNCML "SyncML" + +/* SyncHdr */ +#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_RESPURI "RespURI" +#define ELEMENT_NORESP "NoResp" +#define ELEMENT_CRED "Cred" + +/* SyncBody */ +#define ELEMENT_SYNCBODY "SyncBody" +#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_REPLACE "Replace" +#define ELEMENT_DELETE "Delete" +#define ELEMENT_MAP "Map" +#define ELEMENT_GET "Get" +#define ELEMENT_RESULTS "Results" +#define ELEMENT_STATUS "Status" +#define ELEMENT_CMDID "CmdID" +#define ELEMENT_ITEM "Item" +#define ELEMENT_NUMBEROFCHANGES "NumberOfChanges" +#define ELEMENT_MSGREF "MsgRef" +#define ELEMENT_CMDREF "CmdRef" +#define ELEMENT_TARGETREF "TargetRef" +#define ELEMENT_SOURCEREF "SourceRef" +#define ELEMENT_MAPITEM "MapItem" +#define ELEMENT_MOREDATA "MoreData" +#define ELEMENT_TARGET "Target" +#define ELEMENT_SOURCE "Source" +#define ELEMENT_LOCURI "LocURI" +#define ELEMENT_LOCNAME "LocName" +#define ELEMENT_CHAL "Chal" +#define ELEMENT_B64 "b64" +#define ELEMENT_DATA "Data" + +/* DevInf */ +#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_SHAREDMEM "SharedMem" +#define ELEMENT_MAXMEM "MaxMem" +#define ELEMENT_MAXID "MaxID" +#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" + +/* MetInf */ +#define ELEMENT_META "Meta" +#define ELEMENT_FORMAT "Format" +#define ELEMENT_NEXTNONCE "NextNonce" +#define ELEMENT_TYPE "Type" +#define ELEMENT_SIZE "Size" +#define ELEMENT_MAXMSGSIZE "MaxMsgSize" +#define ELEMENT_MAXOBJSIZE "MaxObjSize" +#define ELEMENT_ANCHOR "Anchor" +#define ELEMENT_LAST "Last" +#define ELEMENT_NEXT "Next" +#define ELEMENT_MEM "Mem" +#define ELEMENT_SHAREDMEM "SharedMem" +#define ELEMENT_FREEMEM "FreeMem" +#define ELEMENT_FREEID "FreeID" + +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_e; + +#endif /* OMA_DS_PROTOCOL_BINDER_DEFINITION_H_ */ diff --git a/include/service-adapter/sa_command.h b/include/service-adapter/sa_command.h new file mode 100755 index 0000000..7ded49f --- /dev/null +++ b/include/service-adapter/sa_command.h @@ -0,0 +1,866 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/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_s structure + * @param[in] enum type, sync type + * @param[in] location_s structure(about source info) + * @param[in] location_s structure(about target info) + * @param[in] string type, last anchor + * @param[in] string type, next anchor + * @param[in] Cred structure + * @param[out] command_s 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_error_type_e create_alert_command(session_s * session, alert_type_e sync_type, location_s * source, location_s * target, char *last_anchor, char *next_anchor, cred_s * cred, command_s ** command); + +/** + * @par Description: API to create get command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[in] location_s structure(about target info) + * @param[in] string type, content type + * @param[out] command_s 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_error_type_e create_get_command(session_s * session, location_s * target, const char *content_type, command_s ** command); + +/** + * @par Description: API to create put command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[in] location_s structure(about source info) + * @param[in] string type, content type + * @param[in] DevInf structure + * @param[out] command_s 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_error_type_e create_put_command(session_s * session, location_s * source, const char *content_type, devinf_s * devinf, command_s ** command); + +/** + * @par Description: API to create results command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[in] location_s structure(about source info) + * @param[in] string type, content type + * @param[in] DevInf structure + * @param[out] command_s 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_error_type_e create_results_command(session_s * session, location_s * source, const char *content_type, devinf_s * devinf, command_s ** command); + +/** + * @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_s structure + * @param[in] location_s structure(about source info) + * @param[in] location_s structure(about target info) + * @param[out] command_s 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_error_type_e create_sync_start_command(session_s * session, location_s * source, location_s * target, command_s ** command); + +/** + * @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_s 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_error_type_e create_sync_end_command(command_s ** command); + +/** + * @par Description: API to create add command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s 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_s 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_error_type_e create_add_command(session_s * session, change_type_e type, char *luid, const char *content_type, char *data, unsigned int size, int more_data, command_s ** command); + +/** + * @par Description: API to create replace command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s 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, more_data(LargeObj) + * @param[out] command_s 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_error_type_e create_replace_command(session_s * session, change_type_e type, char *luid, const char *content_type, const char *data, unsigned int size, int more_data, command_s ** command); + +/** + * @par Description: API to create delete command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[in] enum type, change type + * @param[in] string type, luid of item + * @param[in] string type, content type + * @param[out] command_s 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_error_type_e create_delete_command(session_s * session, change_type_e type, char *luid, const char *content_type, command_s ** command); + +/** + * @par Description: API to create map command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[in] location_s structure(about source info) + * @param[in] location_s structure(about target info) + * @param[out] command_s 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_error_type_e create_map_command(session_s * session, location_s * source, location_s * target, command_s ** command); + +/** + * @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_s * command); + +/** + * @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_s 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_error_type_e increase_command_ref_count(command_s * command); + +/** + * @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_s 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_error_type_e decrease_command_ref_count(command_s * command); + +/** + * @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_error_type_e set_results_command_msg_ref(command_s * command, unsigned int msg_ref); + +/** + * @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_error_type_e set_results_command_cmd_ref(command_s * command, unsigned int cmd_ref); + +/** + * @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] command_s structure + * @param[in] location_s 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_error_type_e set_results_command_target_ref(command_s * command, location_s * location); + +/** + * @par Description: API to set number_of_changes in sync start command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] command_s 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_error_type_e set_sync_start_command_number_of_changes(command_s * command, unsigned int number_of_changes); + +/** + * @par Description: API to set Mem structure in sync start command + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] command_s structure + * @param[in] mem_s 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_error_type_e set_sync_start_command_mem(command_s * command, mem_s * mem); + +/** + * @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] command_s structure + * @param[in] item_s 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_error_type_e set_map_command_item(command_s * mapCommand, item_s * 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_s structure + * @param[in] data (status code) + * @param[in] command_s structure + * @param[in] location_s structure(about source info) + * @param[in] location_s structure(about target info) + * @param[in] command type + * @param[out] status_s 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_error_type_e create_new_status_location(session_s * session, oma_status_type_e data, command_s * command, location_s * source_ref, location_s * target_ref, command_type_e type, status_s ** status); + +/** + * @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_s structure + * @param[in] enum type, data (status code) + * @param[in] command_s structure + * @param[in] enum type, command type + * @param[out] status_s 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_error_type_e create_new_status(session_s * session, oma_status_type_e data, command_s * command, command_type_e type, status_s ** status); + +/** + * @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_s structure(about source info) + * @param[in] location_s structure(about target info) + * @param[in] enum type, command type + * @param[out] status_s 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_error_type_e create_status(oma_status_type_e data, unsigned int cmd_id, unsigned int cmd_ref, unsigned int msg_ref, location_s * source_ref, location_s * target_ref, command_type_e type, status_s ** status); + +/** + * @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_s * 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_status_type_e get_status_code(status_s * 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 command_type_e type + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +command_type_e 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, command_type_e + * @param[out] + * + * @return change_type_e type + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +change_type_e convert_change_type_command_type(command_type_e 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, change_type_e + * @param[out] + * + * @return command_type_e type + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +command_type_e convert_command_type_change_type(change_type_e type); + +/* unused function + * keep for in case + */ +/* +ChangeType convertToChangeType(unsigned int type); +char *convertFromCommandType(CommandType type); +*/ + +#endif /* SA_COMMAND_H_ */ diff --git a/include/service-adapter/sa_command_internal.h b/include/service-adapter/sa_command_internal.h new file mode 100755 index 0000000..707d2e9 --- /dev/null +++ b/include/service-adapter/sa_command_internal.h @@ -0,0 +1,102 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/sa_define.h" +#include "common/common_define.h" + +typedef struct { + alert_type_e type; + anchor_s *anchor; + char *content_type; + unsigned int max_obj_size; +} command_alert_private_s; + +typedef struct { + unsigned int num_changed; + int max_obj_size; + int has_num_changed; + mem_s *mem; +} command_sync_private_s; + +typedef struct { + char *type; + item_s *item; +} command_access_private_s; + +typedef struct { + GList *items; + change_type_e type; +} command_change_private_s; + +typedef struct { + GList *items; +} command_map_private_s; + +typedef struct { + unsigned int msg_ref; + unsigned int cmd_ref; + location_s *target_ref; + char *type; + item_s *item; +} command_results_private_s; + +typedef union { + command_alert_private_s alert; + command_sync_private_s sync; + command_access_private_s access; /*put or get */ + command_change_private_s change; + command_map_private_s map; + command_results_private_s results; +} command_private_u; + +struct command { + int ref_count; + command_type_e type; + unsigned int cmd_id; + unsigned int msg_id; + command_private_u private; + location_s *source; + location_s *target; + cred_s *cred; + int no_resp; +}; + +struct status { + unsigned int cmd_id; + unsigned int msg_ref; + unsigned int cmd_ref; + command_type_e type; + char *data; + location_s *source_ref; + location_s *target_ref; + cred_s *cred; + chal_s *chal; + item_s *item; +}; + +#endif /* SA_COMMAND_INTERNAL_H_ */ diff --git a/include/service-adapter/sa_common_interface.h b/include/service-adapter/sa_common_interface.h new file mode 100755 index 0000000..56d95aa --- /dev/null +++ b/include/service-adapter/sa_common_interface.h @@ -0,0 +1,285 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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] int type, transport Type(obex, FW_HTTP ...) + * @param[in] int type, account id + * @param[in] string type, session id + * @param[in] int type, whether server is fmm server for calllog or not + * @param[out] pre_sync_return_obj_s structure(result from pkg2) + * + * @return common_error_type_e enum value + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int pre_sync(int transport_type, int account_id, char *session_id, int server_flag, void **pre_sync_return_obj); + +/** + * @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] sync_obj_s structure + * @param[in] int type, whether server is fmm server for calllog or not + * @param[out] msg + * @param[out] msg size + * + * @return common_error_type_e enum value + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int generate_msg(void **sync_obj, int server_flag, 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] int 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_error_type_e enum value + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int exchange_msg(int transport_type, char *send_msg, unsigned int send_msg_length, char **recv_msg, unsigned int *recv_msg_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[in] int type, whether or not to end in pkg4 + * @param[out] sync_return_obj_s structure + * @param[out] int type, flag for finsih sync session + * + * @return common_error_type_e enum value + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int process_recv_msg(char *recv_msg, unsigned int recv_msg_length, int only_from_client, void **sync_return_obj, int *is_finish); + +/** + * @par Description: API to free session_s 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, server ip + * @param[in] string type, id + * @param[in] string type, password + * @param[out] GList type, list of auto configure results + * + * @return common_error_type_e 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); + +/** + * @par Description: API to check cancel status + * + * Cancel flag is set and if engine is going to process pkg 5 & 6 + * keep going until finish sync session + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * + * @return 1 means Do cancel + * 0 means Do not cancel + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int check_cancel_status(); + +/** + * @par Description: API to suspend current sync session + * + * Send alert 224 to server and status if there are + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] int type, transport Type(obex, FW_HTTP ...) + * @param[in] int type, account id + * + * @return common_error_type_e enum value + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int suspend_sync(int transport_type, int account_id, int server_flag); + +/** + * @par Description: API to cancel connection during sync session + * + * + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] int type, transport Type(obex, FW_HTTP ...) + * + * @return common_error_type_e enum value + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +int cancel_connection_sync_request(int transport_type); + +#endif /* SA_COMMON_INTERFACE_H_ */ diff --git a/include/service-adapter/sa_define.h b/include/service-adapter/sa_define.h new file mode 100755 index 0000000..254e6ce --- /dev/null +++ b/include/service-adapter/sa_define.h @@ -0,0 +1,159 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include +#include +#include +#include + +#include "service-adapter/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_s; +typedef struct status status_s; +typedef struct command command_s; +typedef struct anchor anchor_s; +typedef struct location location_s; +typedef struct cred cred_s; +typedef struct syncml syncml_s; +typedef struct sync_hdr sync_hdr_s; +typedef struct chal chal_s; +typedef struct devinf devinf_s; +typedef struct devinf_datastore devinf_datastore_s; +typedef struct devinf_content_type devinf_content_type_s; +typedef struct devinf_ct_cap devinf_ct_cap_s; +typedef struct devinf_property devinf_property_s; +typedef struct devinf_prop_param devinf_prop_param_s; +typedef struct filter_cap filter_cap_s; +typedef struct session session_s; +typedef struct command_status command_status_s; +typedef struct mem mem_s; + +typedef enum { + VERSION_UNKNOWN = 0, + VERSION_10 = 1, + VERSION_11 = 2, + VERSION_12 = 3 +} protocol_version_e; + +typedef enum { + PROTOCOL_TYPE_UNKNOWN = 0, + PROTOCOL_TYPE_DS = 1, +} protocol_type_e; + +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 +} command_type_e; + +typedef enum { + AUTH_TYPE_UNKNOWN = 0, + AUTH_TYPE_BASIC = 1, + AUTH_TYPE_MD5 = 2 +} auth_type_e; + +typedef enum { + FORMAT_TYPE_UNKNOWN = 0, + FORMAT_TYPE_BASE64 = 1 +} format_type_e; + +typedef enum { + DEVINF_VERSION_UNKNOWN = 0, + DEVINF_VERSION_10 = 1, + DEVINF_VERSION_11 = 2, + DEVINF_VERSION_12 = 3 +} devinf_version_e; + +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 +} devinf_devtyp_e; + +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 +} devinf_sync_cap_e; + +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, + SYNCML_SUSPEND = 7 +} pkg_status_e; + +typedef enum { + ITEM_UNKNOWN = 0, + ITEM_DATA = 1, + ITEM_DEVINF = 2, +} item_data_type_e; + +#endif /* SA_DEFINE_H_ */ diff --git a/include/service-adapter/sa_devinf.h b/include/service-adapter/sa_devinf.h new file mode 100755 index 0000000..95efc87 --- /dev/null +++ b/include/service-adapter/sa_devinf.h @@ -0,0 +1,134 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/sa_define.h" + +/** + * @par Description: API to create devinf_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[out] devinf_s 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_error_type_e create_devinf(session_s * session, devinf_s ** devinf); + +/** + * @par Description: API to free devinf_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] devinf_s structure + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_devinf(devinf_s * devinf); + +/** + * @par Description: API to set sync cap in devinf_datastore_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] devinf_datastore_s structure + * @param[in] devinf_sync_cap_e 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_sync_cap(devinf_datastore_s * devinf_datastore, devinf_sync_cap_e cap, int supported); + +/** + * @par Description: API to get sync cap from devinf_datastore_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] devinf_datastore_s structure + * @param[in] devinf_sync_cap_e 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_sync_cap(const devinf_datastore_s * devinf_datastore, devinf_sync_cap_e cap); + +/* +DevInfSyncCap convert_devinf_synccap(unsigned int id); +*/ +#endif /* SA_DEVINF_H_ */ diff --git a/include/service-adapter/sa_devinf_internal.h b/include/service-adapter/sa_devinf_internal.h new file mode 100755 index 0000000..f60fd56 --- /dev/null +++ b/include/service-adapter/sa_devinf_internal.h @@ -0,0 +1,118 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/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 { + devinf_version_e version; + + devinf_devtyp_e devtyp; + char *manufacturer; + char *model; + char *oem; + char *software_version; + char *hardware_version; + char *firmware_version; + char *dev_id; + + int supports_utc; + int supports_large_objs; + int supports_number_of_changes; + + GList *datastores; /*containing DevInfDataStore structure */ +}; + +struct devinf_datastore { + int supports_hierarchical_sync; + + char *source_ref; + char *display_name; + unsigned int max_guid_size; + + devinf_content_type_s *rx_pref; + devinf_content_type_s *tx_pref; + + GList *filter_rx; /*need to be considered filter_rx,filterCap */ + GList *filter_cap; + + GList *rx; + GList *tx; + + int shared_mem; + unsigned int max_mem; + unsigned int max_id; + + unsigned int sync_cap; + + GList *ct_caps; /*containing DevInfCTCap structure */ +}; + +struct devinf_content_type { + char *ct_type; + char *verct; +}; + +struct devinf_ct_cap { + devinf_content_type_s *ct; + GList *properties; /*containing DevInfProperty structure */ +}; + +struct devinf_property { + char *prop_name; + char *data_type; + unsigned int max_occur; + unsigned int max_size; +/* unsigned int propSize;*/ + int no_truncate; + char *display_name; + GList *val_enums; /*containing char* */ + GList *prop_params; /*containing DevInfPropParam structure */ +}; + +struct devinf_prop_param { + char *param_name; + char *data_type; + char *display_name; + GList *val_enums; +}; + +struct filter_cap { + char *ct_type; + char *verct; + GList *filter_keyword; + GList *prop_name; +}; + +#endif /* SA_DEVINF_INTERNAL_H_ */ diff --git a/include/service-adapter/sa_elements.h b/include/service-adapter/sa_elements.h new file mode 100755 index 0000000..32b4e41 --- /dev/null +++ b/include/service-adapter/sa_elements.h @@ -0,0 +1,893 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/sa_define.h" + +/** + * @par Description: API to create anchor_s 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_s 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_error_type_e create_anchor(char *last, char *next, anchor_s ** anchor); + +/** + * @par Description: API to set anchor in item_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] item_s structure + * @param[in] anchor_s 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_error_type_e set_item_anchor(item_s * item, anchor_s * anchor); + +/** + * @par Description: API to set last anchor in anchor_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] anchor_s 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_error_type_e set_last_anchor(anchor_s * anchor, char *lastAnchor); + +/** + * @par Description: API to set next anchor in anchor_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] anchor_s 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_error_type_e set_next_anchor(anchor_s * anchor, char *nextAnchor); + +/** + * @par Description: API to free anchor_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] anchor_s 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_s * anchor); + +/** + * @par Description: API to create location_s 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_s 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_error_type_e create_location(char *loc_uri, char *loc_name, location_s ** location); + +/** + * @par Description: API to duplicate location_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] location_s structure + * + * @return location_s structure on success + * NULL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +location_s *dup_location(location_s * location); + +/** + * @par Description: API to get location name from location_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] location_s 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_loc_name(location_s * location); + +/** + * @par Description: API to get location uri from location_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] location_s 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_loc_uri(location_s * location); + +/** + * @par Description: API to free location_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] location_s structure + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_location(location_s * location); + +/** + * @par Description: API to create cred_s 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_s 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_error_type_e create_cred(char *user_name, char *pwd, auth_type_e auth_type, format_type_e format_type, char *data, cred_s ** cred); + +/** + * @par Description: API to create cred_s 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_s structure on success + * NULL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +cred_s *create_cred_with_data(auth_type_e auth_type, char *data); + +/** + * @par Description: API to duplicate cred_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] cred_s structure + * + * @return cred_s structure on success + * NULL on error + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +cred_s *dup_cred(cred_s * cred); + +/** + * @par Description: API to set format type in cred_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] cred_s 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_s * cred, format_type_e format_type); + +/** + * @par Description: API to free cred_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] cred_s structure + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_cred(cred_s * cred); + +/** + * @par Description: API to create syncml_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] sync_hdr_s structure + * @param[in] GList type, list of status_s structure + * @param[in] GList type, list of command_s structure + * @param[in] int type, final flag + * @param[out] syncml_s 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_error_type_e create_syncml(sync_hdr_s * sync_hdr, GList * status, GList * commands, int is_final, syncml_s ** syncml); + +/** + * @par Description: API to free syncml_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] syncml_s structure + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_syncml(syncml_s * syncml); + +/** + * @par Description: API to create sync_hdr_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[out] sync_hdr_s 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_error_type_e create_sync_hdr(session_s * session, sync_hdr_s ** sync_hdr); + +/** + * @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_sync_hdr(sync_hdr_s * sync_hdr); + +/** + * @par Description: API to create item_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] + * @param[out] + * + * @return item_s structure on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +item_s *create_item(); + +/** + * @par Description: API to create item_s 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_s structure on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +item_s *create_item_for_data(const char *data, unsigned int size); + +/** + * @par Description: API to create item_s structure using DevInf + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] devinf_s structure + * @param[out] + * + * @return item_s structure on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +item_s *create_item_for_devinf(devinf_s * devinf); + +/** + * @par Description: API to set location_s(target) structure in item_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] item_s structure + * @param[in] location_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_item_target(item_s * item, location_s * target); + +/** + * @par Description: API to set location_s(source) structure in item_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] item_s structure + * @param[in] location_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_item_source(item_s * item, location_s * source); + +/** + * @par Description: API to free item_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] item_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_item(item_s * item); + +/** + * @par Description: API to duplicate chal_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] chal_s structure + * @param[out] + * + * @return chal_s structure on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +chal_s *dup_chal(chal_s * chal); + +/** + * @par Description: API to free chal_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] chal_s structure + * @param[out] + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_chal(chal_s * 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_s structure + * @param[in] cred_s 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_error_type_e compare_cred(cred_s * hdr_cred, cred_s * session_cred); + +/** + * @par Description: API to convert auth_type_e + * + * @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 + */ +auth_type_e convert_auth_type(char *auth_type); + +/** + * @par Description: API to convert format_type_e + * + * @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 + */ +format_type_e convert_format_type(char *format_type); + +/** + * @par Description: API to create mem_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] + * @param[out] + * + * @return mem_s structure on success + * NULL on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +mem_s *create_mem(); + +/** + * @par Description: API to set shared_mem + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] mem + * @param[in] shared_mem + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_mem_shared_mem(mem_s * mem, int shared_mem); + +/** + * @par Description: API to set free_mem + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] mem + * @param[in] free_mem + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_mem_free_mem(mem_s * mem, unsigned int free_mem); + +/** + * @par Description: API to set free_id + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] mem + * @param[in] free_id + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_mem_free_id(mem_s * mem, unsigned int free_id); + +#endif /* SA_ELEMENTS_H_ */ diff --git a/include/service-adapter/sa_elements_internal.h b/include/service-adapter/sa_elements_internal.h new file mode 100755 index 0000000..842ca1d --- /dev/null +++ b/include/service-adapter/sa_elements_internal.h @@ -0,0 +1,102 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/sa_define.h" + +typedef union { + char *data; + devinf_s *devinf; +} item_data_u; + +struct mem { + int sharedmem; + unsigned int free_mem; + unsigned int free_id; +}; + +struct chal { + format_type_e format; + auth_type_e type; + char *nonce_plain; + unsigned int nonce_length; + char *nonce_b64; +}; + +struct item { + item_data_type_e data_type; + item_data_u private; + location_s *source; + location_s *target; + anchor_s *anchor; + + unsigned int size; /* for data */ + char *content_type; /* for data */ + int more_data; /* for moredata */ +}; + +struct anchor { + char *last_anchor; /**< Last Anchor*/ + char *next_anchor; /**< Next Anchor*/ +}; + +struct location { + char *loc_uri; + char *loc_name; +}; + +struct cred { + format_type_e format; + auth_type_e type; + char *data; + char *user_name; + char *password; +}; + +struct sync_hdr { + char *session_id; + protocol_version_e version; + protocol_type_e protocol; + location_s *source; + location_s *target; + cred_s *cred; + char *response_uri; + int no_response; + unsigned int message_id; + + /*in meta element */ + unsigned int max_msg_size; + unsigned int max_obj_size; +}; + +struct syncml { + sync_hdr_s *hdr; + GList *status; /**< containing Status struct */ + GList *commands; /**< containing Command struct */ + int final; +}; + +#endif /* SA_ELEMENTS_INTERNAL_H_ */ diff --git a/include/service-adapter/sa_error.h b/include/service-adapter/sa_error.h new file mode 100755 index 0000000..fd9d641 --- /dev/null +++ b/include/service-adapter/sa_error.h @@ -0,0 +1,124 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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_status_type_e; + +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_INTERNAL_SUSPEND_FAIL, +} sa_error_type_e; + +#endif /* SA_ERROR_H_ */ diff --git a/include/service-adapter/sa_session.h b/include/service-adapter/sa_session.h new file mode 100755 index 0000000..89efe2b --- /dev/null +++ b/include/service-adapter/sa_session.h @@ -0,0 +1,277 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/sa_define.h" + +/** + * @par Description: API to create session_s structure + * This API can be used to create session_s 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_s 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_error_type_e create_session(protocol_version_e protocol_version, protocol_type_e protocol_type, int account_id, char *sess_id, location_s * source_location, location_s * target_location, session_s ** session); + +/** + * @par Description: API to free session_s structure + * This API can be used to free session_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void free_session(session_s * session); + +/** + * @par Description: API to set cred_s structure in session_s structure + * This API can be used to set cred_s structure in session_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[in] cred_s structure + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_session_cred(session_s * session, cred_s * cred); + +/** + * @par Description: API to set devinf_s structure in session_s structure + * This API can be used to set devinf_s structure in session_s structure + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[in] session_s structure + * @param[in] devinf_s structure + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void set_session_devinf(session_s * session, devinf_s * devInf); + +/** + * @par Description: API to create command_status_s structure + * This API can be used to set devinf_s structure in session_s 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] command_status_s 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_error_type_e create_command_status(unsigned int msg_id, unsigned int cmdID, command_status_s ** command_status); + +/** + * @par Description: API to process sync_hdr_s structure from server + * This API manage responseURI + * set server info in session_s 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_s structure + * @param[in] sync_hdr_s 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_error_type_e receive_header(session_s * session, sync_hdr_s * header); + +/** + * @par Description: API to process list of status_s 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_s structure + * @param[in] GList type, list of status_s structure + * @param[out] GList type, list of applied_status_s 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_error_type_e receive_statuses(session_s * session, GList * receive_status, GList ** return_status); + +/** + * @par Description: API to process list of command_s structure from server + * This API check credential status + * process command_ structure for each type + * create changed_datastore_s 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_s structure + * @param[in] whether auto configure or not + * @param[out] GList type, list of changed_datastore_s 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_error_type_e receive_commands(session_s * session, GList * receive_command, bool auto_config, GList ** return_datastore); + +/** + * @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_s structure + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void reset_cmd_id_session(session_s * session); + +#endif /* SE_SESSION_H_ */ diff --git a/include/service-adapter/sa_session_internal.h b/include/service-adapter/sa_session_internal.h new file mode 100755 index 0000000..56ff46c --- /dev/null +++ b/include/service-adapter/sa_session_internal.h @@ -0,0 +1,83 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/sa_define.h" + +struct session { + protocol_version_e protocol_version; + protocol_type_e protocol_type; + + char *session_id; + unsigned int msg_id; + unsigned int last_recieved_msg_id; + unsigned int cmd_id; + int is_sending_final; + int is_receiving_final; + + GList *status; /*status to return to server */ + GList *temp_status; /*temp status for sync add, replace, delete command(it doesnot have data element value) */ + GList *suspend_status; /* for suspend */ + location_s *target; + location_s *source; + location_s *org_target; + + unsigned int source_max_msg_size; + unsigned int source_max_obj_size; + + unsigned int target_max_msg_size; + unsigned int target_max_obj_size; + + cred_s *cred; /*account info */ + chal_s *chal; /*chal from server */ + + devinf_s *devinf; /*client devinf */ + devinf_s *remote_devinf; /*server devinf */ + + pkg_status_e pkg_status; /*for status */ + + command_s *large_obj_cmd; /*for incomming large Command */ + + GList *map_command; /*containing map command that has sent to server(this is used to for delete map item from mapping table) */ + + GList *alert_command; /*containing alert command that have to send to server */ + + GList *results_command; /*containing results command */ + + command_status_s *large_obj; /*for outgoing large command */ + + int has_opend; + unsigned int naci_session_id; + + int account_id; + char *jsession_id; +}; + +struct command_status { + unsigned int cmd_id; + unsigned int msg_id; +}; +#endif /* SA_SESSION_INTERNAL_H_ */ diff --git a/include/service-adapter/sa_util.h b/include/service-adapter/sa_util.h new file mode 100755 index 0000000..8b07eb7 --- /dev/null +++ b/include/service-adapter/sa_util.h @@ -0,0 +1,94 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-adapter/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 *command); + +/** + * @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_error_type_e create_cred_string(auth_type_e type, const char *user_name, const char *password, const char *nonce, unsigned int nonce_size, char **cred); + +/** + * @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/service-engine/se_account.h b/include/service-engine/se_account.h new file mode 100755 index 0000000..fc6563e --- /dev/null +++ b/include/service-engine/se_account.h @@ -0,0 +1,342 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include +#include "common/common_define.h" + +/** + * @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_dir_name(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_service_s 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 *profile_dir_name, char *profile_name, char *addr, char *id, char *password, char *sync_mode, char *sync_type, char *interval, GList * categories, int *account_id); + +/** + * @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 + */ +bool 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 *profile_name, char *addr, char *id, char *password, GList * categories, int *account_id); + +/** + * @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, 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_dive(int *account_id); + +/** + * @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_service_s 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 account_id, char *profile_name, char *addr, char *id, char *password, char *sync_mode, char *sync_type, 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 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_dive(); + +/** + * @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); + +/** + * @par Description: API to delete all profiles + * This API can be used to delete all profiles + * + * @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_all_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, profile_dir_name(identify profile in UI) + * @param[out] string type, sync_type(determined by server) + * + * @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_dir_name, char **sync_type); + +/** + * @par Description: API to delete all agent default table(except id_provider_tbl, id_page_tbl) + * This API can be used to delete all agent default table + * + * @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_all_agent_default_table(); + +#endif /* SE_ACCOUNT_H_ */ diff --git a/include/service-engine/se_common.h b/include/service-engine/se_common.h new file mode 100755 index 0000000..108acef --- /dev/null +++ b/include/service-engine/se_common.h @@ -0,0 +1,128 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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_ERROR_LOW_BATTERY "LOW_BATTERY" + +#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 +} sync_progress_e; + +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, + ERROR_LOW_BATTERY = 11 +} sync_error_e; + +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 +} sync_progress_status_e; + +typedef enum { + OPERATION_NOOP = 0, + OPERATION_ADD, + OPERATION_DELETE, + OPERATION_MOVE, + OPERATION_COPY, + OPERATION_REPLACE +} operation_type_e; + +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 */ +} command_result_e; + +#endif /* SE_COMMON_H_ */ diff --git a/include/service-engine/se_error.h b/include/service-engine/se_error.h new file mode 100755 index 0000000..6a22139 --- /dev/null +++ b/include/service-engine/se_error.h @@ -0,0 +1,45 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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_INTERNAL_LOW_BATTERY = 12, + SE_INTERNAL_SUSPEND = 13, + +} se_error_type_e; + +#endif /* SE_ERROR_H_ */ diff --git a/include/service-engine/se_notification.h b/include/service-engine/se_notification.h new file mode 100755 index 0000000..4789ba5 --- /dev/null +++ b/include/service-engine/se_notification.h @@ -0,0 +1,99 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include "service-engine/se_error.h" + +/** + * @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, profile dir name(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_error_type_e send_noti_session_process(char *profile, char *progress, char *error, char *sync_type); + +/** + * @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, profile dir name(identify profile in UI) + * @param[in] string type, server sync type + * @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_error_type_e send_noti_process_update(char *profile_dir_name, char *sync_type, char *uri, char *progress_status, char *operation_type, int is_from_server, int total_per_operation, int synced_per_operation, int total_per_db, int synced_per_db); + +#endif /* SE_NOTIFICATION_H_ */ diff --git a/include/service-engine/se_storage.h b/include/service-engine/se_storage.h new file mode 100755 index 0000000..ecf45d6 --- /dev/null +++ b/include/service-engine/se_storage.h @@ -0,0 +1,258 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 "service-engine/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, sync_session_result_e + * @param[in] int type, last sync time + * @param[in] int type, whether or not tn end in pkg4 + * + * @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_error_type_e write_profile_data(int account_id, alert_type_e alert_type, sync_session_result_e sync_session_result, int last_session_time, int only_from_client); + +/** + * @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] sync_result_s 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_error_type_e write_sync_statistics(int account_id, int content_type, bool is_from_server, sync_result_s * sync_result); + +/** + * @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] int type, content type(TYPE_CONTACT, TYPE_CALENDAR, TYPE_MEMO) + * @param[in] int type, last sync time + * @param[in] int type, whether or not to end in pkg4 + * @param[in] sync_result_s structure, client + * @param[in] sync_result_s 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_error_type_e write_sync_resource_info(int account_id, int content_type, int last_session_time, int only_from_client, sync_result_s * client_sync_result, sync_result_s * server_sync_result); + +/** + * @par Description: API to get profile data from config_tbl + * This API can be used to get profile data + * 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 + * @param[out] string type, server ip + * @param[out] string type, id + * @param[out] string type, password + * @param[out] string type, sync mode + * @param[out] string type, sync type + * @param[out] string type, interval + * @param[out] int type, last_session_status + * @param[out] int type, last_session_time + * + * + * @return true on success + * false on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +bool get_profile_data(int account_id, char **profile_name, char **addr, char **id, char **password, char **sync_mode, char **sync_type, char **interval, int *last_session_status, int *last_session_time); + +/** + * @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 account_id, int content_type, int *enabled, char **src_uri, char **tgt_uri, char **id, char **password); + +/** + * @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 account_id, int content_type, char **dbSynced, int *last_session_time, + int *server2client_total, int *server2client_nrofadd, int *server2client_nrofdelete, int *server2client_nrofreplace, + int *client2server_total, int *client2server_nrofadd, int *client2server_nrofdelete, int *client2server_nrofreplace); + +/** + * @par Description: API to get all profiles data from config_tbl + * This API can be used to get all profiles data + * This API is part of API for UI + * + * @par Purpose: + * @par Typical use case: + * @par Method of function operation: + * @par Important notes: + * @param[out] GList, all profiles data + * + * + * @return true on success + * false on error + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +bool get_all_profiles_data(GList ** list); + +#endif /* SE_STORAGE_H_ */ diff --git a/include/service-engine/se_sync.h b/include/service-engine/se_sync.h new file mode 100755 index 0000000..7f63c5c --- /dev/null +++ b/include/service-engine/se_sync.h @@ -0,0 +1,234 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include "common/common_define_internal.h" +#include "service-engine/se_common.h" +#include "framework/san-parser/pm_sanparser.h" +#include "service-engine/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 account_id, char *sync_mode, san_package_s * sanpackage); + +/** + * @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_error_type_e + * @param[out] enum type, sync_progress_e + * @param[out] enum type, sync_error_e + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void convert_common_errorcode(common_error_type_e error_code, sync_progress_e * process, sync_error_e * 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_error_type_e + * @param[out] enum type, sync_progress_e + * @param[out] enum type, sync_error_e + * + * @return + * + * @par Errors: + * + * @pre None. + * @post + * @see + * @remarks None. + * + * @par Sample Code: + * @code + * @endcode + */ +void convert_engine_errorcode(se_error_type_e err, sync_progress_e * process, sync_error_e * 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, profile_dir_name(identify profile in UI) + * @param[in] enum type, sync_progress_e + * @param[in] enum type, sync_error_e + * @param[in] enum type, se_error_type_e sync type + * + * @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_error_type_e session_process(char *profile_dir_name, alert_type_e server_sync_type, sync_progress_e process, sync_error_e 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_error_type_e 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 account_id); + +/** + * @par Description: API to cancel connection during sync session + * + * @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_error_type_e cancel_sync_request(); + +#endif /* SYNCENGINE_H_ */ diff --git a/oma-ds b/oma-ds new file mode 100755 index 0000000..893ebdb --- /dev/null +++ b/oma-ds @@ -0,0 +1,73 @@ +#!/bin/sh + +DESC="OMA DS agent daemon" +NAME=oma-ds-agent +DAEMON=/usr/bin/$NAME +SCRIPTNAME=/etc/init.d/oma-ds + +[ -x "$DAEMON" ] || exit 0 + +do_start() { + PID=`pidof $NAME` + [ -z "$PID" ] || return 1 + $DAEMON + RETVAL=$? + return "$RETVAL" +} + +do_stop() { + PID=`pidof $NAME` + if [ -n "$PID" ]; then + kill $PID + fi + return 0 +} + +prt_res() { + RETVAL=$1 + + case "$RETVAL" in + 0|1) + echo "... done." + RETVAL=0 + ;; + *) + echo "... failed!" + RETVAL=1 + ;; + esac + + return $RETVAL +} + +case "$1" in + start) + echo "Starting $DESC" "$NAME" + if [ -f /opt/usr/data/oma-ds/.oma-ds-agent-enabled ]; then + do_start + prt_res $? + else + echo "don't exist oma-ds-agent enabled file" + prt_res $? + fi + ;; + stop) + echo "Stopping $DESC" "$NAME" + do_stop + prt_res $? + ;; + restart) + echo "Stopping $DESC" "$NAME" + do_stop + prt_res $? + sleep 2 + echo "Starting $DESC" "$NAME" + do_start + prt_res $? + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2 + exit 3 + ;; +esac + diff --git a/oma-ds-agent.manifest b/oma-ds-agent.manifest new file mode 100644 index 0000000..f415759 --- /dev/null +++ b/oma-ds-agent.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + diff --git a/oma-ds-cfg/eventconfig_omads b/oma-ds-cfg/eventconfig_omads new file mode 100644 index 0000000..f8988c5 --- /dev/null +++ b/oma-ds-cfg/eventconfig_omads @@ -0,0 +1,12 @@ +1, 1, 0, 30, addprofile +2, 1, 0, 30, editprofile +3, 1, 0, 30, deleteprofile +4, 1, 0, 30, requestsync +5, 1, 0, 30, cancelsync +6, 1, 0, 30, getprofiledata +7, 1, 0, 30, getprofilesynccategory +8, 1, 0, 30, getprofilestatistics +9, 1, 0, 30, getprofilesdata +10, 1, 0, 30, addprofilecp +11, 1, 0, 30, requestcalllogsync +12, 1, 0, 30, resetalldata \ No newline at end of file diff --git a/oma-ds-cfg/noticonfig_omads b/oma-ds-cfg/noticonfig_omads new file mode 100644 index 0000000..389f69f --- /dev/null +++ b/oma-ds-cfg/noticonfig_omads @@ -0,0 +1,2 @@ +1, 0, 0, 30, sessionprocess +2, 0, 0, 30, processupdate \ No newline at end of file diff --git a/oma-ds-cfg/omadsUI_fw_config.xml b/oma-ds-cfg/omadsUI_fw_config.xml new file mode 100644 index 0000000..f140050 --- /dev/null +++ b/oma-ds-cfg/omadsUI_fw_config.xml @@ -0,0 +1,13 @@ + + + omads_ui + + omads + /usr/share/oma-ds-cfg/eventconfig_omads + 0 + + + omads + /usr/share/oma-ds-cfg/noticonfig_omads + + diff --git a/oma-ds-cfg/omads_fw_config.xml b/oma-ds-cfg/omads_fw_config.xml new file mode 100644 index 0000000..96efbba --- /dev/null +++ b/oma-ds-cfg/omads_fw_config.xml @@ -0,0 +1,133 @@ + + + omads + 1 + + omads + /usr/share/oma-ds-cfg/eventconfig_omads + 1 + + + omads + /usr/share/oma-ds-cfg/noticonfig_omads + + + 5 + + + /opt/dbspace/.omasyncagent.db + + + 1 + 4000000000 + 5 + + + + + 0 + /usr/lib/sync-agent/common-public/libplugin-da-contact.so + SLP Contact Access PlugIn + 1 + 1 + 1 + + + 1 + /usr/lib/sync-agent/common-public/libplugin-da-calendar.so + SLP Calendar Access PlugIn + 2 + 1 + 1 + + + 2 + /usr/lib/sync-agent/common-public/libplugin-da-memo.so + SLP Memo Access PlugIn + 3 + 1 + 1 + + + 3 + /usr/lib/sync-agent/common-public/libplugin-da-call-log.so + SLP Calllog Access PlugIn + 4 + 0 + 0 + + + + + 1 + /usr/lib/sync-agent/ds-public/libplugin-dc-vcard.so + SLP Contact Converter + + + 2 + /usr/lib/sync-agent/common-public/libplugin-dc-vcalendar.so + SLP Calendar Converter + + + 3 + /usr/lib/sync-agent/ds-public/libplugin-dc-plain-text.so + SLP Memo Converter + + + 4 + /usr/lib/sync-agent/ds-public/libplugin-dc-xcalllog.so + SLP Calllog Converter + + + + + 1 + /usr/lib/sync-agent/common-public/libplugin-account.so + SLP Account Accessor + + + + + 1 + /usr/lib/sync-agent/common-public/libplugin-na-http.so + Http Protocol + 1 + + + + + 1 + /usr/lib/sync-agent/common-public/libplugin-di-slp-device.so + SLP Device Accessor + + + + + 1 + /usr/lib/sync-agent/common-public/libplugin-pm-slp-sysnoti-alarm.so + monitoring Alarm Event from SLP Platform + 1 + + + oma-ds-agent + - + + + + + 2 + /usr/lib/sync-agent/common-public/libplugin-pm-slp-sysnoti-network-connection.so + monitoring Network Connection Event from SLP Platform + 1 + - + + + 3 + /usr/lib/sync-agent/common-public/libplugin-pm-slp-sysnoti-wap-push.so + monitoring WAP Push Event from SLP Platform + 1 + - + + + + diff --git a/packaging/oma-ds-agent.spec b/packaging/oma-ds-agent.spec new file mode 100755 index 0000000..1782263 --- /dev/null +++ b/packaging/oma-ds-agent.spec @@ -0,0 +1,117 @@ +Name: oma-ds-agent +Summary: oma-ds-agent daemon for data sync +Version: 0.1.6 +Release: 1 +Group: TO_BE/FILLED_IN +License: Apache License, Version 2.0 +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) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(libwbxml2) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(check) +BuildRequires: pkgconfig(memo) +BuildRequires: pkgconfig(contacts-service2) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(aul) +BuildRequires: expat-devel +BuildRequires: cmake + + +%description +oma-ds-agent daemon (development headers) + +%package -n ds-public-plugins +Summary: DS Public Plugins +Group: TO_BE_FILLED + +%description -n ds-public-plugins +ds public plugins for sync-agent + + +%prep +%setup -q + + +%build +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} +make %{?jobs:-j%jobs} + + +%install +rm -rf %{buildroot} +%make_install + + +%clean +rm -rf %{buildroot} + + +%post +if [ ! -d /opt/dbspace ] +then + mkdir /opt/dbspace +fi +if [ ! -d /etc/rc.d/rc3.d ] +then + mkdir /etc/rc.d/rc3.d +fi +if [ ! -d /etc/rc.d/rc5.d ] +then + mkdir /etc/rc.d/rc5.d +fi + +ln -s /etc/init.d/oma-ds /etc/rc.d/rc3.d/S91oma-ds-agent +ln -s /etc/init.d/oma-ds /etc/rc.d/rc5.d/S91oma-ds-agent + +sqlite3 /opt/dbspace/.omasyncagent.db "PRAGMA journal_mode = PERSIST; create table a(a); drop table a;" > /dev/null + +chmod 600 /opt/dbspace/.omasyncagent.db +chmod 600 /opt/dbspace/.omasyncagent.db-journal + +if [ -f /usr/lib/rpm-plugins/msm.so ] +then + chsmack -a oma-ds-agent::db /opt/dbspace/.omasyncagent.db + chsmack -a oma-ds-agent::db /opt/dbspace/.omasyncagent.db-journal +fi + +#/etc/init.d/oma-ds start + + +%preun +/etc/init.d/oma-ds stop + + +%postun + +rm -f /tmp/agent_fw_event_omads* +rm -f /tmp/agent_fw_noti_reply_omads* + +rm -f /etc/rc.d/rc3.d/S91oma-ds-agent +rm -f /etc/rc.d/rc5.d/S91oma-ds-agent + +rm -f /opt/dbspace/.omasyncagent.db /opt/dbspace/.omasyncagent.db-journal + +rm -rf /usr/share/oma-ds-cfg + + +%files +%manifest oma-ds-agent.manifest +%defattr(-,root,root,-) +/usr/share/dbus-1/services/* +/usr/bin/oma-ds-agent + +/usr/share/oma-ds-cfg/* + +%defattr(700,root,root) +/etc/init.d/oma-ds + +%files -n ds-public-plugins +%manifest ds-public-plugins.manifest +%defattr(-,root,root,-) +/usr/lib/sync-agent/ds-public/* diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt new file mode 100755 index 0000000..64fb834 --- /dev/null +++ b/src/agent/CMakeLists.txt @@ -0,0 +1,80 @@ + +############################################# +# +# Step 1. Set Variable and Build Dependency +# + +# set a name for the entire project +PROJECT(oma-ds) + +# set variables +SET(EXENAME "${PROJECT_NAME}-agent") +SET(BINDIR "${PREFIX}/bin") +SET(OMADS_SRC_DIR "${CMAKE_SOURCE_DIR}/src/agent") +SET(OMADS_COMPONETS "main;common;framework/san-parser;framework/event;framework/task;service-adapter;service-adapter/network-binder;service-adapter/protocol-binder;service-engine") + +# checks for build dependency modules : a pkg-config module for CMake +INCLUDE(FindPkgConfig) +pkg_check_modules(LPKGS REQUIRED + glib-2.0 + libsoup-2.4 + sqlite3 + sync-agent + vconf + libwbxml2 + dlog + aul + dbus-glib-1 + ) + +############################################# +# +# Step 2. Set Compile Environment +# + +# set extra cflags from build dependency +STRING(REPLACE ";" " " EXTRA_CFLAGS "${LPKGS_CFLAGS}") + +# find all source files in a directory. +FOREACH(OMADS_COMPONET ${OMADS_COMPONETS}) + AUX_SOURCE_DIRECTORY(${OMADS_SRC_DIR}/${OMADS_COMPONET} SRCS) +ENDFOREACH(OMADS_COMPONET) + +# add internal include directories to the build. +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/san-parser) + +# add define macros +ADD_DEFINITIONS("-DGLIB_VERSION_MIN_REQUIRED=(2<<16|32<<8) ") + +############################################# +# +# Step 3. Set Link Environment +# + +# add an executable to the project using the specified source files. +ADD_EXECUTABLE(${EXENAME} ${SRCS}) + +# link a target to given libraries. +TARGET_LINK_LIBRARIES(${EXENAME} ${LPKGS_LIBRARIES}) + +# sets additional compiler flags used to build sources within the target. +SET_TARGET_PROPERTIES(${EXENAME} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS}) + +############################################# +# +# Step 4. Install packages +# + +# install executable file +INSTALL(TARGETS ${EXENAME} DESTINATION ${BINDIR}) + +# install oma ds configuration files +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/oma-ds-cfg DESTINATION /usr/share) + +# install oma ds dbus file +INSTALL(FILES ${CMAKE_SOURCE_DIR}/com.samsung.omadsagent.service DESTINATION /usr/share/dbus-1/services) + +# install booting script file +INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/${PROJECT_NAME} DESTINATION /etc/init.d/) + diff --git a/src/agent/common/common_define.c b/src/agent/common/common_define.c new file mode 100755 index 0000000..3954bb4 --- /dev/null +++ b/src/agent/common/common_define.c @@ -0,0 +1,750 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @Common_Define_Internal.c + * @version 0.1 + * @brief This file is the source file of implementation of defined Common structure + */ + +#include + +#include "common/common_define.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +datastore_s *datastoreinfo_per_content_type[4]; + +datastore_info_s *create_datastore_info(char *target, char *source) +{ + _EXTERN_FUNC_ENTER; + + datastore_info_s *datastore_info = (datastore_info_s *) calloc(1, sizeof(datastore_info_s)); + retvm_if(datastore_info == NULL, NULL, "datastore_info is NULL"); + + if (target != NULL) + datastore_info->target = strdup(target); + if (source != NULL) + datastore_info->source = strdup(source); + + _EXTERN_FUNC_EXIT; + + return datastore_info; +} + +void free_datastore_infos(GList * datastore_infos) +{ + _EXTERN_FUNC_ENTER; + retm_if(datastore_infos == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = datastore_infos; iter != NULL; iter = g_list_next(iter)) + free_datastore_info(iter->data); + + g_list_free(datastore_infos); + + _EXTERN_FUNC_EXIT; +} + +void free_datastore_info(datastore_info_s * datastore_info) +{ + _EXTERN_FUNC_ENTER; + retm_if(datastore_info == NULL, "pDatastoreInfo is NULL"); + + if (datastore_info->target != NULL) { + free(datastore_info->target); + datastore_info->target = NULL; + } + + if (datastore_info->source != NULL) { + free(datastore_info->source); + datastore_info->source = NULL; + } + + if (datastore_info->last_anchor != NULL) { + free(datastore_info->last_anchor); + datastore_info->last_anchor = NULL; + } + + if (datastore_info->next_anchor != NULL) { + free(datastore_info->next_anchor); + datastore_info->next_anchor = NULL; + } + + free(datastore_info); + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_info_sync_type(datastore_info_s * datastore_info, alert_type_e sync_type) +{ + _EXTERN_FUNC_ENTER; + if (datastore_info != NULL) + datastore_info->sync_type = sync_type; + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_info_last_anchor(datastore_info_s * datastore_info, char *last_anchor) +{ + _EXTERN_FUNC_ENTER; + if (datastore_info != NULL) { + if (last_anchor != NULL) + datastore_info->last_anchor = strdup(last_anchor); + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_info_next_anchor(datastore_info_s * datastore_info, char *next_anchor) +{ + _EXTERN_FUNC_ENTER; + if (datastore_info != NULL) { + if (next_anchor != NULL) + datastore_info->next_anchor = strdup(next_anchor); + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_info_max_obj_size(datastore_info_s * datastore_info, unsigned int max_obj_size) +{ + _EXTERN_FUNC_ENTER; + if (datastore_info != NULL) + datastore_info->max_obj_size = max_obj_size; + + _EXTERN_FUNC_EXIT; +} + +changed_item_s *create_changed_item(change_type_e type, char *luid) +{ + _EXTERN_FUNC_ENTER; + + changed_item_s *changed_item = (changed_item_s *) calloc(1, sizeof(changed_item_s)); + retvm_if(changed_item == NULL, NULL, "changed_item is NULL"); + + changed_item->change_type = type; + + if (luid != NULL) + changed_item->luid = strdup(luid); + + changed_item->content_type = NULL; + + _EXTERN_FUNC_EXIT; + + return changed_item; +} + +void set_changed_item_content_type(changed_item_s * changed_item, char *content_type) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_item == NULL, "pChangedItem is NULL"); + + if (content_type != NULL) + changed_item->content_type = strdup(content_type); + + _EXTERN_FUNC_EXIT; +} + +void free_changed_item(changed_item_s * changed_item) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_item == NULL, "pChangedItem is NULL"); + + if (changed_item->luid != NULL) { + free(changed_item->luid); + changed_item->luid = NULL; + } + + if (changed_item->content_type != NULL) { + free(changed_item->content_type); + changed_item->content_type = NULL; + } + + if (changed_item->data != NULL) { + free(changed_item->data); + changed_item->data = NULL; + } + + if (changed_item != NULL) + free(changed_item); + + _EXTERN_FUNC_EXIT; +} + +void set_changed_item_data(changed_item_s * changed_item, char *data) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_item == NULL, "pChangedItem is NULL"); + + if (data != NULL) + changed_item->data = strdup(data); + + _EXTERN_FUNC_EXIT; +} + +void set_changed_item_index_of_datastore(changed_item_s * changed_item, unsigned int index_of_datastore) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_item == NULL, "changed_item is NULL"); + + changed_item->index_of_datastore = index_of_datastore; + + _EXTERN_FUNC_EXIT; +} + +changed_datastore_s *create_changed_datastore(char *source, char *target, int has_number_of_changes, unsigned int number_of_changes) +{ + _EXTERN_FUNC_ENTER; + + changed_datastore_s *changed_datastore = (changed_datastore_s *) calloc(1, sizeof(changed_datastore_s)); + retvm_if(changed_datastore == NULL, NULL, "changed_datastore is NULL"); + + if (source != NULL) + changed_datastore->source = strdup(source); + if (target != NULL) + changed_datastore->target = strdup(target); + + changed_datastore->need_sync_command = 1; + changed_datastore->number_of_changes = number_of_changes; + changed_datastore->has_number_of_changes = has_number_of_changes; + + _EXTERN_FUNC_EXIT; + + return changed_datastore; +} + +void free_changed_datastores(GList * changed_datastores) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_datastores == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = changed_datastores; iter != NULL; iter = g_list_next(iter)) + free_changed_datastore(iter->data); + + g_list_free(changed_datastores); + + _EXTERN_FUNC_EXIT; +} + +void free_changed_datastore(changed_datastore_s * changed_datastore) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_datastore == NULL, "pChangedDatastore is NULL"); + + if (changed_datastore->source != NULL) { + free(changed_datastore->source); + changed_datastore->source = NULL; + } + + if (changed_datastore->target != NULL) { + free(changed_datastore->target); + changed_datastore->target = NULL; + } + + GList *iter = NULL; + for (iter = changed_datastore->change_item; iter != NULL; iter = g_list_next(iter)) + free_changed_item(iter->data); + + g_list_free(changed_datastore->change_item); + changed_datastore->change_item = NULL; + + for (iter = changed_datastore->sent_item; iter != NULL; iter = g_list_next(iter)) + free_changed_item(iter->data); + + g_list_free(changed_datastore->sent_item); + changed_datastore->sent_item = NULL; + + if (changed_datastore != NULL) + free(changed_datastore); + + _EXTERN_FUNC_EXIT; +} + +void set_changed_datastore_changed_item(changed_datastore_s * changed_datastore, GList * changed_items) +{ + _EXTERN_FUNC_ENTER; + + if (changed_datastore != NULL) + changed_datastore->change_item = changed_items; + + _EXTERN_FUNC_EXIT; +} + +void add_changed_datastore_changed_item(changed_datastore_s * changed_datastore, changed_item_s * changed_item) +{ + _EXTERN_FUNC_ENTER; + + retm_if(changed_datastore == NULL, "changed_datastore is NULL"); + + changed_datastore->change_item = g_list_append(changed_datastore->change_item, changed_item); + + _EXTERN_FUNC_EXIT; +} + +applied_status_s *create_applied_status(char *luid, change_type_e change_type, int status) +{ + _EXTERN_FUNC_ENTER; + + applied_status_s *applied_status = (applied_status_s *) calloc(1, sizeof(applied_status_s)); + retvm_if(applied_status == NULL, NULL, "appliedStatus is NULL"); + + if (luid != NULL) + applied_status->luid = strdup(luid); + + applied_status->change_type = change_type; + applied_status->status = status; + + _EXTERN_FUNC_EXIT; + + return applied_status; +} + +void free_applied_statuses(GList * applied_statuses) +{ + _EXTERN_FUNC_ENTER; + + retm_if(applied_statuses == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = applied_statuses; iter != NULL; iter = g_list_next(iter)) + free_applied_status(iter->data); + + g_list_free(applied_statuses); + + _EXTERN_FUNC_EXIT; +} + +void free_applied_status(applied_status_s * applied_status) +{ + _EXTERN_FUNC_ENTER; + + retm_if(applied_status == NULL, "List is NULL"); + + if (applied_status->luid != NULL) { + free(applied_status->luid); + applied_status->luid = NULL; + } + + free(applied_status); + + _EXTERN_FUNC_EXIT; +} + +sending_status_s *create_sending_status(char *source, char *target) +{ + _EXTERN_FUNC_ENTER; + + sending_status_s *sending_status = (sending_status_s *) calloc(1, sizeof(sending_status_s)); + retvm_if(sending_status == NULL, NULL, "sending_status is NULL"); + + if (source != NULL) + sending_status->source = strdup(source); + + if (target != NULL) + sending_status->target = strdup(target); + + _EXTERN_FUNC_EXIT; + + return sending_status; +} + +void free_sending_statuses(GList * sending_statuses) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sending_statuses == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = sending_statuses; iter != NULL; iter = g_list_next(iter)) + free_sending_status(iter->data); + + g_list_free(sending_statuses); + + _EXTERN_FUNC_EXIT; +} + +void free_sending_status(sending_status_s * sending_status) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sending_status == NULL, "pSendingStatus is NULL"); + + if (sending_status->source != NULL) { + free(sending_status->source); + sending_status->source = NULL; + } + + if (sending_status->target != NULL) { + free(sending_status->target); + sending_status->target = NULL; + } + + GList *iter = NULL; + for (iter = sending_status->items; iter != NULL; iter = g_list_next(iter)) + free_applied_status(iter->data); + + g_list_free(sending_status->items); + + free(sending_status); + + _EXTERN_FUNC_EXIT; +} + +void add_sending_status_applied_status(sending_status_s * sending_status, applied_status_s * applied_status) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sending_status == NULL, "sending_status is NULL"); + + sending_status->items = g_list_append(sending_status->items, applied_status); + + _EXTERN_FUNC_EXIT; +} + +datastore_s *create_datastore(char *target, char *source) +{ + _EXTERN_FUNC_ENTER; + + datastore_s *datastore = (datastore_s *) calloc(1, sizeof(datastore_s)); + retvm_if(datastore == NULL, NULL, "datastore is NULL"); + + if (target != NULL) + datastore->target = strdup(target); + + if (source != NULL) + datastore->source = strdup(source); + + _EXTERN_FUNC_EXIT; + + return datastore; +} + +void set_datastore_content_type_info(datastore_s * datastore, int datastore_id, int folder_type_id) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) { + datastore->datastore_id = datastore_id; + datastore->folder_type_id = folder_type_id; + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_account_info(datastore_s * datastore, char *account_id, char *account_pw) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) { + if (account_id != NULL) + datastore->id = strdup(account_id); + if (account_pw != NULL) + datastore->pw = strdup(account_pw); + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_client_sync_type(datastore_s * datastore, alert_type_e sync_type) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) + datastore->client_sync_type = sync_type; + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_server_sync_type(datastore_s * datastore, alert_type_e sync_type) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) + datastore->server_sync_type = sync_type; + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_client_anchor(datastore_s * datastore, char *last_anchor, char *next_anchor) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) { + if (last_anchor != NULL) + datastore->last_anchor_client = strdup(last_anchor); + if (next_anchor != NULL) + datastore->next_anchor_client = strdup(next_anchor); + } + + _EXTERN_FUNC_EXIT; +} + +void set_datastore_server_anchor(datastore_s * datastore, char *last_anchor, char *next_anchor) +{ + _EXTERN_FUNC_ENTER; + + if (datastore != NULL) { + if (last_anchor != NULL) + datastore->last_anchor_server = strdup(last_anchor); + if (next_anchor != NULL) + datastore->next_anchor_server = strdup(next_anchor); + } + + _EXTERN_FUNC_EXIT; +} + +sync_result_s *create_sync_result() +{ + _EXTERN_FUNC_ENTER; + + sync_result_s *syncResult = calloc(1, sizeof(sync_result_s)); + retvm_if(syncResult == NULL, NULL, "syncResult is NULL"); + + _EXTERN_FUNC_EXIT; + + return syncResult; +} + +sync_result_s *dup_sync_result(sync_result_s * org_sync_result) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(org_sync_result == NULL, NULL, "orgSyncResult is NULL"); + + sync_result_s *syn_cre_sult = calloc(1, sizeof(sync_result_s)); + retvm_if(syn_cre_sult == NULL, NULL, "syn_cre_sult is NULL"); + + syn_cre_sult->session_result = org_sync_result->session_result; + syn_cre_sult->number_of_change = org_sync_result->number_of_change; + syn_cre_sult->received_count = org_sync_result->received_count; + syn_cre_sult->add_count = org_sync_result->add_count; + syn_cre_sult->replace_count = org_sync_result->replace_count; + syn_cre_sult->delete_count = org_sync_result->delete_count; + + _EXTERN_FUNC_EXIT; + + return syn_cre_sult; + +} + +void set_number_of_change(sync_result_s * sync_result, unsigned int number_of_change) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->number_of_change = number_of_change; + + _EXTERN_FUNC_EXIT; +} + +void add_add_count(sync_result_s * sync_result, unsigned int add_cnt) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->add_count += add_cnt; + + _EXTERN_FUNC_EXIT; +} + +void add_receive_count(sync_result_s * sync_result, unsigned int received_count) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->received_count += received_count; + + _EXTERN_FUNC_EXIT; +} + +void add_replace_count(sync_result_s * sync_result, unsigned int replace_cnt) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->replace_count += replace_cnt; + + _EXTERN_FUNC_EXIT; +} + +void add_delete_count(sync_result_s * sync_result, unsigned int delete_cnt) +{ + _EXTERN_FUNC_ENTER; + + if (sync_result != NULL) + sync_result->delete_count += delete_cnt; + + _EXTERN_FUNC_EXIT; +} + +void free_pre_sync_return_obj(pre_sync_return_obj_s * pre_sync_return_obj) +{ + _EXTERN_FUNC_ENTER; + + retm_if(pre_sync_return_obj == NULL, "pre_sync_return_obj is NULL"); + + GList *iter = NULL; + for (iter = pre_sync_return_obj->datastore_info; iter != NULL; iter = g_list_next(iter)) + free_datastore_info(iter->data); + g_list_free(pre_sync_return_obj->datastore_info); + pre_sync_return_obj->datastore_info = NULL; + + if (pre_sync_return_obj->dev_id != NULL) { + free(pre_sync_return_obj->dev_id); + pre_sync_return_obj->dev_id = NULL; + } + + free(pre_sync_return_obj); + pre_sync_return_obj = NULL; + + _EXTERN_FUNC_EXIT; +} + +void free_sync_obj(sync_obj_s * sync_obj) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sync_obj == NULL, "sync_obj is NULL"); + + GList *iter = NULL; + for (iter = sync_obj->changed_datastore; iter != NULL; iter = g_list_next(iter)) + free_changed_datastore(iter->data); + g_list_free(sync_obj->changed_datastore); + sync_obj->changed_datastore = NULL; + + for (iter = sync_obj->sending_status; iter != NULL; iter = g_list_next(iter)) + free_sending_status(iter->data); + g_list_free(sync_obj->sending_status); + sync_obj->sending_status = NULL; + + free(sync_obj); + sync_obj = NULL; + + _EXTERN_FUNC_EXIT; +} + +void free_sync_return_obj(sync_return_obj_s * sync_return_obj) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sync_return_obj == NULL, "pSyncReturnObj is NULL"); + + GList *iter = NULL; + for (iter = sync_return_obj->changed_datastore; iter != NULL; iter = g_list_next(iter)) + free_changed_datastore(iter->data); + g_list_free(sync_return_obj->changed_datastore); + sync_return_obj->changed_datastore = NULL; + + for (iter = sync_return_obj->status; iter != NULL; iter = g_list_next(iter)) + free_applied_status(iter->data); + g_list_free(sync_return_obj->status); + sync_return_obj->status = NULL; + + free(sync_return_obj); + sync_return_obj = NULL; + + _EXTERN_FUNC_EXIT; +} + +void free_datastore(datastore_s * datastore) +{ + _EXTERN_FUNC_ENTER; + + retm_if(datastore == NULL, "pDatastore is NULL"); + + if (datastore->target != NULL) { + free(datastore->target); + datastore->target = NULL; + } + + if (datastore->source != NULL) { + free(datastore->source); + datastore->source = NULL; + } + + if (datastore->id != NULL) { + free(datastore->id); + datastore->id = NULL; + } + + if (datastore->pw != NULL) { + free(datastore->pw); + datastore->pw = NULL; + } + + if (datastore->last_anchor_client != NULL) { + free(datastore->last_anchor_client); + datastore->last_anchor_client = NULL; + } + + if (datastore->next_anchor_client != NULL) { + free(datastore->next_anchor_client); + datastore->next_anchor_client = NULL; + } + + if (datastore->last_anchor_server != NULL) { + free(datastore->last_anchor_server); + datastore->last_anchor_server = NULL; + } + + if (datastore->next_anchor_server != NULL) { + free(datastore->next_anchor_server); + datastore->next_anchor_server = NULL; + } + + if (datastore->client_sync_result != NULL) + free(datastore->client_sync_result); + + if (datastore->server_sync_result != NULL) + free(datastore->server_sync_result); + + free(datastore); + + _EXTERN_FUNC_EXIT; +} + +void free_sync_service(sync_service_s * category) +{ + _EXTERN_FUNC_ENTER; + + retm_if(category == NULL, "category is NULL"); + + if (category->src_uri != NULL) + free(category->src_uri); + + if (category->tgt_uri != NULL) + free(category->tgt_uri); + + if (category->id != NULL) + free(category->id); + + if (category->password != NULL) + free(category->password); + + _EXTERN_FUNC_EXIT; +} diff --git a/src/agent/common/common_util.c b/src/agent/common/common_util.c new file mode 100755 index 0000000..7c1bb70 --- /dev/null +++ b/src/agent/common/common_util.c @@ -0,0 +1,281 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @Common_Util.c + * @version 0.1 + * @brief This file is the source file of implementation of utility function + */ + +#include + +#include "common/common_util.h" +#include "common/common_define_internal.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +#define MAX_RETRY_COUNT 10 + +bool create_config_str(int account_id, char *key, char *value, char *type, char *access_name, sync_agent_da_config_s ** config) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + + da_err = sync_agent_create_config(config); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_create_config is failed"); + goto error; + } + + (*config)->config_id = account_id; + (*config)->key = strdup(key); + (*config)->value = value != NULL ? strcmp(value, "") == 0 ? NULL : strdup(value) : NULL; + (*config)->type = strdup(type); + (*config)->access_name = strdup(access_name); + + error: + + _EXTERN_FUNC_EXIT; + + if (da_err == SYNC_AGENT_DA_SUCCESS) + return true; + else + return false; + +} + +bool set_config_str(int accountID, char *key, char *value, char *type, char *access_name) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e result; + sync_agent_da_config_s config; + + config.config_id = accountID; + config.key = key; + config.value = value != NULL ? strcmp(value, "") == 0 ? NULL : value : NULL; + config.type = type; + config.access_name = access_name; + + result = sync_agent_update_config(&config); + + _EXTERN_FUNC_EXIT; + + if (result == SYNC_AGENT_DA_SUCCESS) + return true; + else + return false; +} + +bool set_config_int(int accountID, char *key, int value, char *type, char *access_name) +{ + _EXTERN_FUNC_ENTER; + + char *value_str = NULL; + value_str = g_strdup_printf("%u", value); + + sync_agent_da_return_e result; + sync_agent_da_config_s config; + + config.config_id = accountID; + config.key = key; + config.value = value_str; + config.type = type; + config.access_name = access_name; + + result = sync_agent_update_config(&config); + + if (value_str != NULL) + free(value_str); + + _EXTERN_FUNC_EXIT; + + if (result == SYNC_AGENT_DA_SUCCESS) + return true; + else + return false; +} + +bool get_config(int account_id, char *key, char **value) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_da_return_e result = SYNC_AGENT_DA_SUCCESS; + sync_agent_da_config_s *config = NULL; + + *value = NULL; + + result = sync_agent_create_config(&config); + if (result != SYNC_AGENT_DA_SUCCESS) + return false; + + result = sync_agent_get_config(account_id, key, &config); + if (result == SYNC_AGENT_DA_SUCCESS) { + if (config != NULL) { + if (config->value != NULL) { + *value = strdup(config->value); + _DEBUG_INFO("value = %s", *value); + } + } + } 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 = sync_agent_get_config(account_id, key, &config); + if (result == SYNC_AGENT_DA_SUCCESS) { + if (config != NULL) { + if (config->value != NULL) { + *value = strdup(config->value); + _DEBUG_INFO("value = %s", *value); + success = true; + break; + } + } + } + } + if (success == false) { + sync_agent_free_config(config); + _EXTERN_FUNC_EXIT; + return false; + } + } + + sync_agent_free_config(config); + _EXTERN_FUNC_EXIT; + return true; +} + +int get_account_id(char *profile, bool open) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(profile == NULL, -1, "profile is NULL"); + + int accountId = -1; + char *profileDirName = NULL; + bool result; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + GList *account_info_list = NULL; + GList *iter = NULL; + + if (open == false) { + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_agent"); + goto error; + } + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_NONE; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto error; + } + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + fw_account = (sync_agent_fw_account_s *) iter->data; + + if (profileDirName != NULL) + free(profileDirName); + + result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + goto error; + } + + _DEBUG_INFO("profileDirName = %s", profileDirName); + if (profileDirName == NULL) + continue; + + if (strcmp(profile, profileDirName) == 0) { + _DEBUG_INFO("account_list[i] = %d", fw_account->account_id); + accountId = fw_account->account_id; + break; + } + } + + _EXTERN_FUNC_EXIT; + + error: + + sync_agent_free_fw_account_list(account_info_list); + + if (profileDirName != NULL) + free(profileDirName); + + if (open == false) + sync_agent_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/agent/common/common_vconf.c b/src/agent/common/common_vconf.c new file mode 100755 index 0000000..e874d37 --- /dev/null +++ b/src/agent/common/common_vconf.c @@ -0,0 +1,191 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @Common_Util.c + * @version 0.1 + * @brief This file is the source file of implementation of wrapping vconf function + */ + +#include +#include +#include +#include +#include + +#include + +#include "common/common_vconf.h" + +char *get_vconf_str(char *base_key, char *key) +{ + _EXTERN_FUNC_ENTER; + + char path[128]; + char *value = NULL; + + snprintf(path, sizeof(path), "%s%s", base_key, key); + value = vconf_get_str(path); + + if (value != NULL) { + if (strcmp(value, "") == 0) { + + if (value != NULL) + free(value); + + _EXTERN_FUNC_EXIT; + return NULL; + } else { + _EXTERN_FUNC_EXIT; + return value; + } + } else { + _EXTERN_FUNC_EXIT; + return NULL; + } + +} + +char *get_vconf_str_key(char *key) +{ + _EXTERN_FUNC_ENTER; + + char *value = NULL; + value = vconf_get_str(key); + + if (value != NULL) { + if (strcmp(value, "") == 0) { + + if (value != NULL) + free(value); + + _EXTERN_FUNC_EXIT; + return NULL; + } else { + _EXTERN_FUNC_EXIT; + return value; + } + } else { + _EXTERN_FUNC_EXIT; + return NULL; + } +} + +bool get_vconf_int(char *base_key, char *key, int *value) +{ + _EXTERN_FUNC_ENTER; + + char path[128]; + int temp = 0; + int result; + + snprintf(path, sizeof(path), "%s%s", base_key, key); + result = vconf_get_int(path, &temp); + + _EXTERN_FUNC_EXIT; + + if (result == 0) { + *value = temp; + return true; + } else + return false; +} + +bool get_vconf_int_key(char *key, int *value) +{ + _EXTERN_FUNC_ENTER; + + int temp = 0; + int result; + + result = vconf_get_int(key, &temp); + + _EXTERN_FUNC_EXIT; + + if (result == 0) { + *value = temp; + return true; + } else + return false; +} + +bool set_vconf_str(char *base_key, char *key, char *value) +{ + _EXTERN_FUNC_ENTER; + + char path[128]; + int result; + + snprintf(path, sizeof(path), "%s%s", base_key, key); + result = vconf_set_str(path, value); + + _EXTERN_FUNC_EXIT; + + if (result == 0) + return true; + else + return false; +} + +bool set_vconf_str_key(char *key, char *value) +{ + _EXTERN_FUNC_ENTER; + + int result; + result = vconf_set_str(key, value); + + _EXTERN_FUNC_EXIT; + + if (result == 0) + return true; + else + return false; +} + +bool set_vconf_int(char *base_key, char *key, int value) +{ + _EXTERN_FUNC_ENTER; + + char path[128]; + int result; + + snprintf(path, sizeof(path), "%s%s", base_key, key); + result = vconf_set_int(path, value); + + _EXTERN_FUNC_EXIT; + + if (result == 0) + return true; + else + return false; +} + +bool set_vconf_int_key(char *key, int value) +{ + _EXTERN_FUNC_ENTER; + + int result; + + result = vconf_set_int(key, value); + + _EXTERN_FUNC_EXIT; + + if (result == 0) + return true; + else + return false; +} diff --git a/src/agent/framework/event/oma_ds_event_handler.c b/src/agent/framework/event/oma_ds_event_handler.c new file mode 100755 index 0000000..01d5102 --- /dev/null +++ b/src/agent/framework/event/oma_ds_event_handler.c @@ -0,0 +1,908 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @OMA_DS_Event_Handler.c + * @version 0.1 + * @brief This file is the source file of implementation of event callback function(from ui) + */ + +#include +#include +#include + +#include + +#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" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +#define NOTI_KEY "OMADS" + +static void _request_manual_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data); + +static void _request_manual_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data) +{ + _INNER_FUNC_ENTER; + + unsigned int request_msg_id_to_cancel = 0; + get_manual_sync_request_id(&request_msg_id_to_cancel); + + _INNER_FUNC_EXIT; +} + +int event_callback_add_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + char *profile_dir_name = NULL; + char *profile_name = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + char *sync_mode = NULL; + char *sync_type = NULL; + char *interval = NULL; + int category_count; + int result = 0; + int account_id; + + GList *categorys = NULL; + GList *iter = NULL; + + sync_agent_get_event_data_param(request, &profile_dir_name); + sync_agent_get_event_data_param(request, &profile_name); + sync_agent_get_event_data_param(request, &addr); + sync_agent_get_event_data_param(request, &id); + sync_agent_get_event_data_param(request, &password); + sync_agent_get_event_data_param(request, &sync_mode); + sync_agent_get_event_data_param(request, &sync_type); + sync_agent_get_event_data_param(request, &interval); + sync_agent_get_event_data_param(request, &category_count); + + /* + _DEBUG_INFO("request param : %s", profile_dir_name); + _DEBUG_INFO("request param : %s", profile_name); + _DEBUG_INFO("request param : %s", addr); + _DEBUG_INFO("request param : %s", id); + _DEBUG_INFO("request param : %s", password); + _DEBUG_INFO("request param : %s", sync_mode); + _DEBUG_INFO("request param : %s", sync_type); + _DEBUG_INFO("request param : %s", interval); + _DEBUG_INFO("request param : %d", category_count); + */ + + int i = 0; + for (; i < category_count; i++) { + sync_service_s *category = (sync_service_s *) calloc(1, sizeof(sync_service_s)); + if (category == NULL) { + _DEBUG_ERROR("category is NULL !"); + + if (profile_dir_name != NULL) + free(profile_dir_name); + + if (profile_name != NULL) + free(profile_name); + + if (addr != NULL) + free(addr); + + if (id != NULL) + free(id); + + if (password != NULL) + free(password); + + if (sync_mode != NULL) + free(sync_mode); + + if (sync_type != NULL) + free(sync_type); + + if (interval != NULL) + free(interval); + + return 0; + } + + sync_agent_get_event_data_param(request, &(category->service_type)); + sync_agent_get_event_data_param(request, &(category->enabled)); + sync_agent_get_event_data_param(request, &(category->src_uri)); + sync_agent_get_event_data_param(request, &(category->tgt_uri)); + sync_agent_get_event_data_param(request, &(category->id)); + sync_agent_get_event_data_param(request, &(category->password)); + + categorys = g_list_append(categorys, category); + + /* + _DEBUG_INFO("category[i]->content_type : %d", category->content_type); + _DEBUG_INFO("category[i]->enabled : %d", category->enabled); + _DEBUG_INFO("category[i]->srcURI : %s", category->src_uri); + _DEBUG_INFO("category[i]->tgtURI : %s", category->tgt_uri); + _DEBUG_INFO("category[i]->id : %s", category->id); + _DEBUG_INFO("category[i]->password : %s", category->password); + */ + } + + /* send to engine controller */ + void *in_param_value_array[9] = { &profile_dir_name, &profile_name, &addr, &id, &password, &sync_mode, &sync_type, &interval, &categorys }; + int in_param_index_array[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + sync_agent_ec_value_type_e in_param_value_type_array[9] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT + }; + unsigned int request_msg_id = 0; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_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, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &account_id); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &account_id); + + for (iter = categorys; iter != NULL; iter = g_list_next(iter)) { + sync_service_s *category = (sync_service_s *) iter->data; + + if (category != NULL) + free_sync_service(category); + } + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_edit_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + char *profile_dir_name = NULL; + char *profile_name = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + char *sync_mode = NULL; + char *sync_type = NULL; + char *interval = NULL; + int category_count; + int result = 0; + + GList *categorys = NULL; + GList *iter = NULL; + + sync_agent_get_event_data_param(request, &profile_dir_name); + if (profile_dir_name == NULL) { + _DEBUG_ERROR("profile_dir_name is not defined"); + result = 0; + goto error; + } + _DEBUG_INFO("request param : %s", profile_dir_name); + + int account_id = get_account_id(profile_dir_name, false); + + sync_agent_get_event_data_param(request, &profile_name); + sync_agent_get_event_data_param(request, &addr); + sync_agent_get_event_data_param(request, &id); + sync_agent_get_event_data_param(request, &password); + sync_agent_get_event_data_param(request, &sync_mode); + sync_agent_get_event_data_param(request, &sync_type); + sync_agent_get_event_data_param(request, &interval); + sync_agent_get_event_data_param(request, &category_count); + + _DEBUG_INFO("request param : %s", profile_name); + _DEBUG_INFO("request param : %s", addr); + _DEBUG_INFO("request param : %s", id); + _DEBUG_INFO("request param : %s", password); + _DEBUG_INFO("request param : %s", sync_mode); + _DEBUG_INFO("request param : %s", sync_type); + _DEBUG_INFO("request param : %s", interval); + _DEBUG_INFO("request param : %d", category_count); + + int i = 0; + for (; i < category_count; i++) { + sync_service_s *category = (sync_service_s *) calloc(1, sizeof(sync_service_s)); + if (category == NULL) { + _DEBUG_ERROR("category is NULL !"); + + if (profile_dir_name != NULL) + free(profile_dir_name); + + if (profile_name != NULL) + free(profile_name); + + if (addr != NULL) + free(addr); + + if (id != NULL) + free(id); + + if (password != NULL) + free(password); + + if (sync_mode != NULL) + free(sync_mode); + + if (sync_type != NULL) + free(sync_type); + + if (interval != NULL) + free(interval); + + return 0; + } + + sync_agent_get_event_data_param(request, &(category->service_type)); + sync_agent_get_event_data_param(request, &(category->enabled)); + sync_agent_get_event_data_param(request, &(category->src_uri)); + sync_agent_get_event_data_param(request, &(category->tgt_uri)); + sync_agent_get_event_data_param(request, &(category->id)); + sync_agent_get_event_data_param(request, &(category->password)); + + categorys = g_list_append(categorys, category); + + _DEBUG_INFO("category[i]->content_type : %d", category->service_type); + _DEBUG_INFO("category[i]->enabled : %d", category->enabled); + _DEBUG_INFO("category[i]->srcURI : %s", category->src_uri); + _DEBUG_INFO("category[i]->tgtURI : %s", category->tgt_uri); + _DEBUG_INFO("category[i]->id : %s", category->id); + _DEBUG_INFO("category[i]->password : %s", category->password); + } + + /* send to engine controller */ + void *in_param_value_array[9] = { &account_id, &profile_name, &addr, &id, &password, &sync_mode, &sync_type, &interval, &categorys }; + int in_param_index_array[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + sync_agent_ec_value_type_e in_param_value_type_array[9] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT + }; + unsigned int request_msg_id = 0; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_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, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + for (iter = categorys; iter != NULL; iter = g_list_next(iter)) { + sync_service_s *category = (sync_service_s *) iter->data; + + if (category != NULL) + free_sync_service(category); + } + + if (profile_dir_name != NULL) + free(profile_dir_name); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_delete_profile_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + int result = 0; + int count; + sync_agent_get_event_data_param(request, &count); + GList *profiles = NULL; + int *account_id = 0; + + int i; + char *profile = NULL; + for (i = 0; i < count; i++) { + if (profile != NULL) { + free(profile); + profile = NULL; + } + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + _DEBUG_INFO("request param : %s", profile); + + account_id = (int *)calloc(1, sizeof(int)); + if (account_id == NULL) { + _DEBUG_ERROR("account_id is NULL"); + result = 0; + goto error; + } + + *account_id = get_account_id(profile, false); + + profiles = g_list_append(profiles, account_id); + } + + /* send to engine controller */ + void *in_param_value_array[1] = { &profiles }; + int in_param_index_array[1] = { 0 }; + sync_agent_ec_value_type_e in_param_value_type_array[1] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT }; + unsigned int request_msg_id = 0; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_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, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_request_sync_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + char *profile = NULL; + int result = 0; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + _DEBUG_INFO("request param : %s", profile); + + int account_id = get_account_id(profile, false); + char *sync_mode = strdup(DEFINE_SYNC_MODE_MANUAL); + + void *in_param_value_array[3] = { &account_id, &sync_mode, NULL }; + int in_param_index_array[3] = { 0, 1, 2 }; + sync_agent_ec_value_type_e in_param_value_type_array[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT }; + unsigned int request_msg_id = 0; + sync_agent_request_async_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); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_cancel_sync_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + char *profile = NULL; + int result = 0; + bool res; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + + _DEBUG_INFO("request param : %s", profile); + + res = cancel_current_sync_task(); + if (res == true) + result = 1; + else + result = 0; + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_get_profile_data_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + int result = 0; + char *profile = NULL; + char *profile_name = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + char *sync_mode = NULL; + char *sync_type = NULL; + char *interval = NULL; + int last_session_status = 0; + int last_session_time = 0; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + + _DEBUG_INFO("request param : %s", profile); + + int account_id = get_account_id(profile, false); + + int in_param_index_array[1] = { 0 }; + void *in_param_value_array[1] = { &account_id }; + sync_agent_ec_value_type_e in_param_value_type_array[1] = { SYNC_AGENT_EC_VALUE_TYPE_INT }; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + unsigned int request_msg_id = 0; + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_DATA, 0, 1, in_param_index_array, in_param_value_type_array, in_param_value_array, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profile_name); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &sync_mode); + sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &sync_type); + sync_agent_get_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &interval); + sync_agent_get_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_status); + sync_agent_get_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_time); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_name); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)addr); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)id); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)password); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_mode); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_type); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)interval); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_status); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_time); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_get_profile_sync_category_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + char *profile = NULL; + int content_type = 0; + int enabled = 0; + char *srcURI = NULL; + char *tgtURI = NULL; + char *id = NULL; + char *password = NULL; + int result = 0; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + + sync_agent_get_event_data_param(request, &content_type); + + _DEBUG_INFO("request param : %s", profile); + _DEBUG_INFO("request param : %d", content_type); + + int account_id = get_account_id(profile, false); + _DEBUG_INFO(" account_id: %d", account_id); + + int in_param_index_array[2] = { 0, 1 }; + void *in_param_value_array[2] = { &account_id, &content_type }; + sync_agent_ec_value_type_e in_param_value_type_array[2] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_INT }; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + unsigned int request_msg_id = 0; + sync_agent_request_sync_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, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &enabled); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &srcURI); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &tgtURI); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + + /* + _DEBUG_INFO("result = %d", result); + _DEBUG_INFO("enabled = %d", enabled); + _DEBUG_INFO("srcURI = %s", srcURI); + _DEBUG_INFO("tgtURI = %s", tgtURI); + _DEBUG_INFO("id = %s", id); + _DEBUG_INFO("password = %s", password); + */ + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &enabled); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)srcURI); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)tgtURI); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)id); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)password); + + error: + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_get_profile_last_statistics_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + char *profile = NULL; + int content_type = 0; + char *dbSynced = "NO"; + int last_session_time = -1; + int server2Client_Total = 0; + int server2Client_NrOfAdd = 0; + int server2Client_NrOfDelete = 0; + int server2Client_NrOfReplace = 0; + int client2Server_Total = 0; + int client2Server_NrOfAdd = 0; + int client2Server_NrOrDelete = 0; + int client2Server_NrOfReplace = 0; + int result = 0; + + sync_agent_get_event_data_param(request, &profile); + if (profile == NULL) { + _DEBUG_ERROR("profile is not defined"); + result = 0; + goto error; + } + + sync_agent_get_event_data_param(request, &content_type); + + _DEBUG_INFO("request param : %s", profile); + _DEBUG_INFO("request param : %d", content_type); + + int account_id = get_account_id(profile, false); + + int in_param_index_array[2] = { 0, 1 }; + void *in_param_value_array[2] = { &account_id, &content_type }; + sync_agent_ec_value_type_e in_param_value_type_array[2] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_INT }; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + unsigned int request_msg_id = 0; + sync_agent_request_sync_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, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &dbSynced); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &last_session_time); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_Total); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfAdd); + sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfDelete); + sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfReplace); + sync_agent_get_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_Total); + sync_agent_get_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfAdd); + sync_agent_get_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOrDelete); + sync_agent_get_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfReplace); + + /* + _DEBUG_INFO("result = %d", result); + _DEBUG_INFO("dbSynced = %s\n", dbSynced); + _DEBUG_INFO("last_session_time = %d\n", last_session_time); + _DEBUG_INFO("server2Client_Total = %d\n", server2Client_Total); + _DEBUG_INFO("server2Client_NrOfAdd = %d\n", server2Client_NrOfAdd); + _DEBUG_INFO("server2Client_NrOfDelete = %d\n", server2Client_NrOfDelete); + _DEBUG_INFO("server2Client_NrOfReplace = %d\n", server2Client_NrOfReplace); + _DEBUG_INFO("client2Server_Total = %d\n", client2Server_Total); + _DEBUG_INFO("client2Server_NrOfAdd = %d\n", client2Server_NrOfAdd); + _DEBUG_INFO("client2Server_NrOrDelete = %d\n", client2Server_NrOrDelete); + _DEBUG_INFO("client2Server_NrOfReplace = %d\n", client2Server_NrOfReplace); + */ + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)dbSynced); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &last_session_time); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_Total); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfAdd); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfDelete); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &server2Client_NrOfReplace); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_Total); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOfAdd); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOrDelete); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &client2Server_NrOfReplace); + + if (profile != NULL) + free(profile); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_add_profile_cp_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + char *profile_name = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + int category_count; + int result = 0; + int account_id; + + sync_agent_get_event_data_param(request, &profile_name); + sync_agent_get_event_data_param(request, &addr); + sync_agent_get_event_data_param(request, &id); + sync_agent_get_event_data_param(request, &password); + sync_agent_get_event_data_param(request, &category_count); + + /* + _DEBUG_INFO("request param : %s", profile_name); + _DEBUG_INFO("request param : %s", addr); + _DEBUG_INFO("request param : %s", id); + _DEBUG_INFO("request param : %s", password); + _DEBUG_INFO("request param : %d", category_count); + */ + + GList *categorys = NULL; + int i = 0; + for (; i < category_count; i++) { + resource_cp_s *category = (resource_cp_s *) calloc(1, sizeof(resource_cp_s)); + if (category == NULL) { + _DEBUG_ERROR("category is NULL !"); + + if (profile_name != NULL) + free(profile_name); + + if (addr != NULL) + free(addr); + + if (id != NULL) + free(id); + + if (password != NULL) + free(password); + + return 0; + } + + sync_agent_get_event_data_param(request, &(category->name)); + sync_agent_get_event_data_param(request, &(category->accept)); + sync_agent_get_event_data_param(request, &(category->id)); + sync_agent_get_event_data_param(request, &(category->password)); + sync_agent_get_event_data_param(request, &(category->auth_type)); + sync_agent_get_event_data_param(request, &(category->auth_data)); + + categorys = g_list_append(categorys, category); + + /* + _DEBUG_INFO("category[%d]->name : %s", i, category->name); + _DEBUG_INFO("category[%d]->accept : %s", i, category->accept); + _DEBUG_INFO("category[%d]->id : %s", i, category->id); + _DEBUG_INFO("category[%d]->password : %s", i, category->password); + _DEBUG_INFO("category[%d]->authType : %s", i, category->auth_type); + _DEBUG_INFO("category[%d]->authData : %s\n", i, category->auth_data); + */ + } + + /* send to engine controller */ + void *in_param_value_array[5] = { &profile_name, &addr, &id, &password, &categorys }; + int in_param_index_array[5] = { 0, 1, 2, 3, 4 }; + sync_agent_ec_value_type_e in_param_value_type_array[5] = { SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT + }; + unsigned int request_msg_id = 0; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_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, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &account_id); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &account_id); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_request_calllog_sync_async(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + char *data = NULL; + int result = 0; + + sync_agent_get_event_data_param(request, &data); + if (data == NULL) { + _DEBUG_ERROR("data is NULL"); + result = 0; + goto error; + } + _DEBUG_INFO("data = %s", data); + + result = send_ip_push_sync_msg(data); + + error: + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_request_reset_all_data_sync(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + int result; + + /* 1. cancel current sync session */ + cancel_current_sync_task(); + + /* 2. reset all data */ + unsigned int request_msg_id = 0; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + + unsigned int out_param_count; + sync_agent_ec_param_param_s **param_array = NULL; + + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_RESET_ALL_DATA, 0, 0, NULL, NULL, NULL, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + _DEBUG_INFO("result = %d", result); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + + _EXTERN_FUNC_EXIT; + return 0; +} + +int event_callback_request_get_all_profiles_data(sync_agent_event_data_s * request, sync_agent_event_data_s * response) +{ + _EXTERN_FUNC_ENTER; + + int result = 0; + GList *profiles_data = NULL; + GList *profile_iter = NULL; + GList *category_iter = NULL; + + int profile_count = 0; + int category_count = 0; + sync_agent_ds_profile_info *profile_info = NULL; + sync_agent_ds_service_info *category_info = NULL; + + unsigned int out_param_count; + sync_agent_ec_task_error_e task_error = SYNC_AGENT_EC_TASK_ERROR_NOT_YET_RUN; + sync_agent_ec_param_param_s **param_array = NULL; + + unsigned int request_msg_id = 0; + sync_agent_request_sync_task(EC_MSG_TYPE_SYNC_TASK_GET_ALL_PROFILES_DATA, 0, 0, NULL, NULL, NULL, (int *)&request_msg_id, &task_error, &out_param_count, ¶m_array); + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profiles_data); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &result); + _DEBUG_INFO("result = %d", result); + + if (profiles_data != NULL) { + profile_count = g_list_length(profiles_data); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_count); + _DEBUG_INFO("profile_count = %d", profile_count); + + for (profile_iter = profiles_data; profile_iter != NULL; profile_iter = g_list_next(profile_iter)) { + profile_info = (sync_agent_ds_profile_info *) profile_iter->data; + + sync_agent_ds_server_info *server_info = &profile_info->server_info; + sync_agent_ds_sync_info *sync_info = &profile_info->sync_info; + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_dir_name); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_info->profile_name); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->addr); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->id); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)server_info->password); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_mode); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->sync_type); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_info->interval); + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_info->last_sync_status); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &profile_info->last_sync_time); + + _DEBUG_INFO("profile_info->profile_dir_name = %s", profile_info->profile_dir_name); + _DEBUG_INFO("profile_info->profile_name = %s", profile_info->profile_name); + + _DEBUG_INFO("server_info->addr = %s", server_info->addr); + _DEBUG_INFO("server_info->id = %s", server_info->id); + _DEBUG_INFO("server_info->password = %s", server_info->password); + + _DEBUG_INFO("sync_info->sync_mode = %s", sync_info->sync_mode); + _DEBUG_INFO("sync_info->sync_type = %s", sync_info->sync_type); + _DEBUG_INFO("sync_info->interval = %s", sync_info->interval); + + _DEBUG_INFO("profile_info->last_sync_status = %d", profile_info->last_sync_status); + _DEBUG_INFO("profile_info->last_sync_time = %d", profile_info->last_sync_time); + + category_count = g_list_length(profile_info->service_list); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_count); + + _DEBUG_INFO("category_count = %d", category_count); + + for (category_iter = profile_info->service_list; category_iter != NULL; category_iter = g_list_next(category_iter)) { + category_info = (sync_agent_ds_service_info *) category_iter->data; + + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_info->service_type); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &category_info->enabled); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->src_uri); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->tgt_uri); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->id); + sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)category_info->password); + + _DEBUG_INFO("category_info->service_type = %d", category_info->service_type); + _DEBUG_INFO("category_info->enabled = %d", category_info->enabled); + _DEBUG_INFO("category_info->src_uri = %s", category_info->src_uri); + _DEBUG_INFO("category_info->tgt_uri = %s", category_info->tgt_uri); + _DEBUG_INFO("category_info->id = %s", category_info->id); + _DEBUG_INFO("category_info->password = %s", category_info->password); + } + } + } + + _EXTERN_FUNC_EXIT; + return 0; +} diff --git a/src/agent/framework/event/oma_ds_platform_event_handler.c b/src/agent/framework/event/oma_ds_platform_event_handler.c new file mode 100755 index 0000000..ddc3547 --- /dev/null +++ b/src/agent/framework/event/oma_ds_platform_event_handler.c @@ -0,0 +1,355 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 +#include + +#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 "common/common_define_internal.h" +#include "common/common_util.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +static void _request_periodic_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data); + +static void _request_san_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data); + +static void _request_periodic_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data) +{ + _INNER_FUNC_ENTER; + + unsigned int request_msg_id_to_cancel = 0; + get_periodic_sync_request_id(&request_msg_id_to_cancel); + + _INNER_FUNC_EXIT; + +} + +static void _request_san_sync_task_finish_callback(sync_agent_ec_task_error_e task_error, unsigned int out_param_cnt, sync_agent_ec_param_param_s ** out_param_spec_array, void *usr_data) +{ + _INNER_FUNC_ENTER; + + unsigned int request_msg_id_to_cancel = 0; + get_san_sync_request_id(&request_msg_id_to_cancel); + + _INNER_FUNC_EXIT; +} + +int san_callback_parse(int item_id, void *user_data) +{ + _EXTERN_FUNC_ENTER; + san_package_s *pSanPackage = NULL; + int accountID = -1; + char *sync_mode = NULL; + char *server_id = NULL; + bool result; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + GList *account_info_list = NULL; + GList *iter = NULL; + + pmci_san_incoming_s *incoming_data = (pmci_san_incoming_s *) user_data; + + switch (incoming_data->version) { + case 11: + { + pSanPackage = san_package_11_parser(incoming_data->msg_body, incoming_data->msg_size); + } + break; + case 12: + { + pSanPackage = san_package_12_parser(incoming_data->msg_body, incoming_data->msg_size); + } + break; + default: + break; + } + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("da_err = %d", da_err); + goto return_part; + } + + if (pSanPackage == NULL) { + _DEBUG_ERROR("pSanPackage is NULL"); + goto return_part; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_NONE; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto return_part; + } + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + fw_account = (sync_agent_fw_account_s *) iter->data; + result = get_config(fw_account->account_id, 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(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id); + if (result == true) { + /*One device MUST NOT register multi account at same server... */ + if (strcmp(pSanPackage->server_id, server_id) == 0) { + accountID = fw_account->account_id; + break; + } + } else { + _DEBUG_ERROR("failed in get_Config"); + goto return_part; + } + } + } else { + _DEBUG_ERROR("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 }; + sync_agent_ec_value_type_e in_param_type[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT }; + unsigned int request_msg_id = 0; + sync_agent_request_async_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); + + sync_agent_close_agent(); + + if (pSanPackage != NULL) + sanPackageParserFree((void *)pSanPackage); + + _EXTERN_FUNC_EXIT; + return 1; + + return_part: + + sync_agent_free_fw_account_list(account_info_list); + + if (sync_mode != NULL) + free(sync_mode); + + if (server_id != NULL) + free(server_id); + +/* if( incoming_data != NULL){ + if (incoming_data->msg_body != NULL) + free((void *)incoming_data->msg_body); + + free(incoming_data); + }*/ + + if (pSanPackage != NULL) + sanPackageParserFree((void *)pSanPackage); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + return 0; +} + +void send_periodic_sync_msg(int scheduler_id, void *data) +{ + _EXTERN_FUNC_ENTER; + + _DEBUG_INFO("#######Scheduler Send Msg Success!!!!!##########"); + _DEBUG_INFO("schedulerId = %d", scheduler_id); + + int accountId = -1; + int alarmId = 0; + char *alarmId_str = NULL; + bool result; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + GList *account_info_list = NULL; + GList *iter = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_agent"); + goto error; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_NONE; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto error; + } + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + fw_account = (sync_agent_fw_account_s *) iter->data; + if (alarmId_str != NULL) + free(alarmId_str); + + result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &alarmId_str); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + goto error; + } + alarmId = atoi(alarmId_str); + _DEBUG_INFO("alarm id = %d", alarmId); + if (alarmId == scheduler_id) { + _DEBUG_INFO("account_list[i] = %d", fw_account->account_id); + accountId = fw_account->account_id; + break; + } + } + + if (accountId != -1) { + int in_param_index_array[3] = { 0, 1, 2 }; + sync_agent_ec_value_type_e in_param_value_type_array[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT, + SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_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; + sync_agent_request_async_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: + + sync_agent_free_fw_account_list(account_info_list); + + if (alarmId_str != NULL) + free(alarmId_str); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; +} + +int send_ip_push_sync_msg(char *data) +{ + _EXTERN_FUNC_ENTER; + + san_package_s *pSanPackage = NULL; + char *id = NULL; + char *server_id = NULL; + int accountId = -1; + bool result = false; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + GList *account_info_list = NULL; + GList *iter = NULL; + sync_agent_fw_account_s *account_info = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_agent"); + goto error; + } + + result = parse_ip_push_msg(data, &pSanPackage, &id); + if (result != true) { + _DEBUG_ERROR("Failed in parseIPPushMsg"); + goto error; + } + + cancel_current_sync_task(); + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_ACCESS_NAME; + query.access_name = "DIVE"; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + account_info = (sync_agent_fw_account_s *) iter->data; + + _DEBUG_INFO("accountId = %d", account_info->account_id); + result = get_config(account_info->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &server_id); + if (result == true) { + if (strcmp(pSanPackage->server_id, server_id) == 0) { + accountId = account_info->account_id; + break; + } + } else { + _DEBUG_ERROR("failed in get_Config"); + goto error; + } + } + + if (accountId < 0) + goto error; + + 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 }; + sync_agent_ec_value_type_e in_param_value_type_array[3] = { SYNC_AGENT_EC_VALUE_TYPE_INT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT, SYNC_AGENT_EC_VALUE_TYPE_STRUCT }; + unsigned int request_msg_id = 0; + sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_REQUEST, 0, 3, in_param_index_array, in_param_value_type_array, 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); + + sync_agent_free_fw_account_list(account_info_list); + + if (server_id != NULL) + free(server_id); + + if (pSanPackage != NULL) + sanPackageParserFree((void *)pSanPackage); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + return 1; + + error: + + sync_agent_free_fw_account_list(account_info_list); + + if (server_id != NULL) + free(server_id); + + if (pSanPackage != NULL) + sanPackageParserFree((void *)pSanPackage); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + return 0; +} diff --git a/src/agent/framework/san-parser/pm_sanparser.c b/src/agent/framework/san-parser/pm_sanparser.c new file mode 100755 index 0000000..bbb21e7 --- /dev/null +++ b/src/agent/framework/san-parser/pm_sanparser.c @@ -0,0 +1,633 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @PM_SanParser.c + * @version 0.1 + * @brief This file is the source file of implementation of San Parser + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "wbxml/wbxml.h" +#include "wbxml/wbxml_tree.h" +#include "framework/san-parser/pm_sanparser.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +static san_content_type_s contentTypeSupported[] = { + {0x00, NULL}, + {0x03, "text/plain"}, + {0x06, "text/x-vcalendar"}, + {0x07, "text/x-vcard"}, + {0x0305, "text/calendar"}, + {0x0306, "application/vnd.omads-email+xml"}, + {0x0307, "application/vnd.omads-file+xml"}, + {0x0308, "application/vnd.omads-folder+xml"}, + {0x0309, "text/vcard"} +}; + +san_package_s *san_package_12_parser(const char *msg_body, unsigned int msg_size) +{ + _EXTERN_FUNC_ENTER; + + unsigned int idLength = (uint8_t) msg_body[23]; + retvm_if(msg_size < (25 + idLength), NULL, "[sanPackage12Parser] SAN package size is smaller than its minimal size specified in the spec, related to [Header] part."); + + san_package_s *san = (san_package_s *) calloc(1, sizeof(san_package_s)); + retvm_if(san == NULL, NULL, "[sanPackage12Parser] SAN package memory allocation fail. [Container]"); + + /* MSG BODY WITHOUT DIGEST */ + san->msg_body_without_digest = (char *)calloc(msg_size - 16, sizeof(char)); + if (san->msg_body_without_digest == NULL) { + _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [Msg body]"); + goto error; + } + memcpy(san->msg_body_without_digest, msg_body + 16, msg_size - 16); + san->msg_body_without_digest_length = msg_size - 16; + + /* DIGEST */ + san->digest = (char *)calloc(16, sizeof(char)); + if (san->digest == NULL) { + _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [Digest]"); + goto error; + } + memcpy(san->digest, msg_body, 16); + + /* VERSION */ + unsigned int version = ((uint8_t) msg_body[16]) << 2; + version = version | ((uint8_t) msg_body[17]) >> 6; + + if (version != 12) { + _DEBUG_ERROR("[sanPackage12Parser] Not supported SAN version %d.", version); + goto error; + } + san->version = version; + + /* UI MODE */ + san->ui_mode = (((uint8_t) msg_body[17]) & 0x30) >> 4; + + /* INITIATOR */ + san->initiator = (((uint8_t) msg_body[17]) & 0x08) >> 3; + + /* SESSION ID */ +/*san->sessionID = ((uint8_t)msgBody[21]) << 8; + san->sessionID = san->sessionID | (uint8_t)msgBody[22];*/ + san->session_id = atoi(g_strdup_printf("%02X%02X", msg_body[21], msg_body[22])); + _DEBUG_INFO("session id : %d \n", san->session_id); + + /* SERVER ID */ + if (idLength) { + san->server_id = (char *)calloc(idLength + 1, sizeof(char)); + if (san->server_id == NULL) { + _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [Server ID]"); + goto error; + } + memcpy(san->server_id, msg_body + 24, idLength); + } + + san->cnt_sync_alerts = ((uint8_t) msg_body[24 + idLength]) >> 4; + + if (san->cnt_sync_alerts == 0) { + if (msg_size > 24 + idLength + 1) { + _DEBUG_INFO("[sanPackage12Parser] There are remaining bytes at the end of the package. (w/o alerts info)"); + } + + /* If number of sync alerts equals 0, should sync all data store in the client */ + _EXTERN_FUNC_EXIT; + return san; + } + + san->sync_alerts = (san_sync_alert_s *) calloc(san->cnt_sync_alerts, sizeof(san_sync_alert_s)); + if (san->sync_alerts == NULL) { + _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [syncAlerts]"); + goto error; + } + + msg_body += 25 + idLength; + unsigned int alertLength = 25 + idLength; + unsigned int i; + + for (i = 0; i < san->cnt_sync_alerts; i++) { + + idLength = (uint8_t) msg_body[4]; + if (msg_size < (alertLength + 5 + idLength)) { + _DEBUG_ERROR("[sanPackage12Parser] SAN package size is smaller than"); + _DEBUG_ERROR("[sanPackage12Parser] its minimal size specified in the spec, related to [Alerts] part."); + goto error; + } + alertLength = alertLength + 5 + idLength; + + /* SYNC TYPE */ + san_sync_type_e alert_type = (((uint8_t) msg_body[0]) >> 4) + 200; + if (alert_type < 206 || alert_type > 210) { + _DEBUG_ERROR("[sanPackage12Parser] SAN doesn't support the sync type %d.", alert_type); + goto error; + } + + unsigned int contentType = ((uint8_t) msg_body[1]) << 16; + contentType = contentType | ((uint8_t) msg_body[2]) << 8; + contentType = contentType | ((uint8_t) msg_body[3]); + + /* CONTENT TYPE */ + char *alert_ct = NULL; + + int j; + int cnt = (int)sizeof(contentTypeSupported) / sizeof(san_content_type_s); + bool isContentSupported = false; + + for (j = 0; j < cnt; j++) { + if (contentType == contentTypeSupported[j].type) { + alert_ct = contentTypeSupported[j].strType; + isContentSupported = true; + break; + } + } + + if (!isContentSupported) { + _DEBUG_ERROR("[sanPackage12Parser] SAN doesn't support the content type %d.", contentType); + goto error; + } + + /* SERVER URI */ + char *alert_uri = NULL; + + if (idLength) { + alert_uri = (char *)calloc(idLength + 1, sizeof(char)); + if (alert_uri == NULL) { + _DEBUG_ERROR("[sanPackage12Parser] SAN package memory allocation fail. [Server URI]"); + goto error; + } + memcpy(alert_uri, msg_body + 5, idLength); + } + msg_body += 5 + idLength; + + san->sync_alerts[i].sync_type = alert_type; + san->sync_alerts[i].content_type = alert_ct; + san->sync_alerts[i].server_uri = alert_uri; + + } + + if (msg_size > alertLength) { + _DEBUG_INFO("[sanPackage12Parser] There are remaining bytes at the end of the package. (with alerts info)"); + } + + _EXTERN_FUNC_EXIT; + return san; + + error: + + sanPackageParserFree(san); + + _EXTERN_FUNC_EXIT; + return NULL; + +} + +san_package_s *san_package_11_parser(const char *msg_body, unsigned int msg_size) +{ + _EXTERN_FUNC_ENTER; + + san_package_s *san = (san_package_s *) calloc(1, sizeof(san_package_s)); + if (san == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [Container]"); + + _EXTERN_FUNC_EXIT; + return NULL; + } + + WBXMLTree *wbxml_tree = NULL; + WBXMLError wbxml_err = wbxml_tree_from_wbxml((unsigned char *)msg_body, msg_size, WBXML_LANG_UNKNOWN, WBXML_CHARSET_UNKNOWN, &wbxml_tree); + + if (wbxml_err != WBXML_OK) { + _DEBUG_ERROR("[sanPackage11Parser] Libwbxml2 failed to parse WBXML STREAM to WBXML TREE, error code : %s", wbxml_errors_string(wbxml_err)); + goto error; + } + + WBXMLTreeNode *synchdr_node; + if ((synchdr_node = wbxml_tree_node_elt_get_from_name(wbxml_tree->root, "SyncHdr", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [SyncHdr]"); + goto error; + } + WBXMLTreeNode *child_node = NULL; + const char *child_node_name = NULL; + + for (child_node = synchdr_node->children; child_node != NULL; child_node = child_node->next) { + child_node_name = (const char *)wbxml_tag_get_xml_name(child_node->name); + + if ((strcmp(child_node_name, "VerDTD") == 0) || (strcmp(child_node_name, "VerProto") == 0)) { + char *version = NULL; + if (child_node->children != NULL && child_node->children->type == WBXML_TREE_TEXT_NODE && child_node->children->content != NULL) { + + version = (char *)wbxml_buffer_get_cstr(child_node->children->content); + + if (strcmp(version, "1.1") && strcmp(version, "SyncML/1.1")) { + _DEBUG_ERROR("[sanPackage11Parser] Not supported SAN version %s.", version); + goto error; + } + san->version = 11; + } + } else if (strcmp(child_node_name, "SessionID") == 0) { + char *sessionID = NULL; + if (child_node->children != NULL && child_node->children->type == WBXML_TREE_TEXT_NODE && child_node->children->content != NULL) { + + sessionID = (char *)wbxml_buffer_get_cstr(child_node->children->content); + + if (sessionID == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL sessionID detected. sessionID MUST NOT be NULL."); + goto error; + } + san->session_id = atoi(sessionID); + } + } else if (strcmp(child_node_name, "Source") == 0) { + char *serverID = NULL; + unsigned serverIDlen = 0; + WBXMLTreeNode *serverid_node; + if ((serverid_node = wbxml_tree_node_elt_get_from_name(child_node, "LocURI", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [LocURI]"); + goto error; + } + + if (serverid_node->children != NULL && serverid_node->children->type == WBXML_TREE_TEXT_NODE && serverid_node->children->content != NULL) { + + serverID = (char *)wbxml_buffer_get_cstr(serverid_node->children->content); + serverIDlen = wbxml_buffer_len(serverid_node->children->content); + if (serverID == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL serverID detected. serverID MUST NOT be NULL."); + goto error; + } + + san->server_id = (char *)calloc(serverIDlen, sizeof(char)); + if (san->server_id == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [Server ID]"); + goto error; + } + memcpy(san->server_id, serverID, serverIDlen); + } + } else if (strcmp(child_node_name, "Cred") == 0) { + + san->cred = (san_cred_s *) calloc(1, sizeof(san_cred_s)); + if (san->cred == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [cred]"); + goto error; + } + + char *credFormat = NULL; + unsigned credFormatLen = 0; + WBXMLTreeNode *credformat_node; + if ((credformat_node = wbxml_tree_node_elt_get_from_name(child_node, "Format", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Format]"); + goto error; + } + + if (credformat_node->children != NULL && credformat_node->children->type == WBXML_TREE_TEXT_NODE && credformat_node->children->content != NULL) { + + credFormat = (char *)wbxml_buffer_get_cstr(credformat_node->children->content); + credFormatLen = wbxml_buffer_len(credformat_node->children->content); + if (credFormat == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL credFormat detected. credFormat MUST NOT be NULL."); + goto error; + } + + san->cred->cred_format = (char *)calloc(credFormatLen, sizeof(char)); + if (san->cred->cred_format == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [credFormat]"); + goto error; + } + memcpy(san->cred->cred_format, credFormat, credFormatLen); + } + + char *credAuth = NULL; + unsigned credAuthLen = 0; + WBXMLTreeNode *credauth_node; + if ((credauth_node = wbxml_tree_node_elt_get_from_name(child_node, "Type", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Type]"); + goto error; + } + + if (credauth_node->children != NULL && credauth_node->children->type == WBXML_TREE_TEXT_NODE && credauth_node->children->content != NULL) { + + credAuth = (char *)wbxml_buffer_get_cstr(credauth_node->children->content); + credAuthLen = wbxml_buffer_len(credauth_node->children->content); + if (credAuth == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL credAuth detected. credAuth MUST NOT be NULL."); + goto error; + } + + san->cred->cred_auth = (char *)calloc(credAuthLen, sizeof(char)); + if (san->cred->cred_auth == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [credAuth]"); + goto error; + } + memcpy(san->cred->cred_auth, credAuth, credAuthLen); + } + + char *credData = NULL; + unsigned credDataLen = 0; + WBXMLTreeNode *creddata_node; + if ((creddata_node = wbxml_tree_node_elt_get_from_name(child_node, "Data", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Data]"); + goto error; + } + + if (creddata_node->children != NULL && creddata_node->children->type == WBXML_TREE_TEXT_NODE && creddata_node->children->content != NULL) { + + credData = (char *)wbxml_buffer_get_cstr(creddata_node->children->content); + credDataLen = wbxml_buffer_len(creddata_node->children->content); + if (credData == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL credData detected. credData MUST NOT be NULL."); + goto error; + } + + san->cred->cred_data = (char *)calloc(credDataLen, sizeof(char)); + if (san->cred->cred_data == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [credData]"); + goto error; + } + memcpy(san->cred->cred_data, credData, credDataLen); + } + + } + + } + + WBXMLTreeNode *syncbody_node; + if ((syncbody_node = wbxml_tree_node_elt_get_from_name(wbxml_tree->root, "SyncBody", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [SyncBody]"); + goto error; + } + + WBXMLList *alertnode_list = wbxml_tree_node_get_all_children(syncbody_node); + unsigned int alertnode_list_len = wbxml_list_len(alertnode_list); + + child_node = (WBXMLTreeNode *) wbxml_list_get(alertnode_list, alertnode_list_len - 1); + child_node_name = (const char *)wbxml_tag_get_xml_name(child_node->name); + if (strcmp(child_node_name, "Final") == 0) + san->cnt_sync_alerts = alertnode_list_len - 1; + + if (san->cnt_sync_alerts == 0) { + /* If number of sync alerts equals 0, should sync all data store in the client */ + return san; + } else { + san->sync_alerts = (san_sync_alert_s *) calloc(san->cnt_sync_alerts, sizeof(san_sync_alert_s)); + if (san->sync_alerts == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [syncAlerts]"); + goto error; + } + + unsigned int indexNode; + for (indexNode = 0; indexNode < san->cnt_sync_alerts; indexNode++) { + + WBXMLTreeNode *alert_node = (WBXMLTreeNode *) wbxml_list_get(alertnode_list, indexNode); + + char *alertData = NULL; + WBXMLTreeNode *alertdata_node; + if ((alertdata_node = wbxml_tree_node_elt_get_from_name(alert_node, "Data", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Data]"); + goto error; + } + + if (alertdata_node->children != NULL && alertdata_node->children->type == WBXML_TREE_TEXT_NODE && alertdata_node->children->content != NULL) { + + alertData = (char *)wbxml_buffer_get_cstr(alertdata_node->children->content); + if (alertData == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL alertData detected. alertData MUST NOT be NULL."); + goto error; + } + + if (atoi(alertData) < 206 || atoi(alertData) > 210) { + _DEBUG_ERROR("[sanPackage11Parser] SAN doesn't support the sync type %d.", atoi(alertData)); + goto error; + } + + san->sync_alerts[indexNode].sync_type = atoi(alertData); + } + + char *alertURI = NULL; + unsigned alertURIlen = 0; + WBXMLTreeNode *alerturi_node; + if ((alerturi_node = wbxml_tree_node_elt_get_from_name(alert_node, "LocURI", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [LocURI]"); + goto error; + } + + if (alerturi_node->children != NULL && alerturi_node->children->type == WBXML_TREE_TEXT_NODE && alerturi_node->children->content != NULL) { + + alertURI = (char *)wbxml_buffer_get_cstr(alerturi_node->children->content); + alertURIlen = wbxml_buffer_len(alerturi_node->children->content); + if (alertURI == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL alertURI detected. alertURI MUST NOT be NULL."); + goto error; + } + + san->sync_alerts[indexNode].server_uri = (char *)calloc(alertURIlen, sizeof(char)); + if (san->sync_alerts[indexNode].server_uri == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] SAN package memory allocation fail. [serverURI]"); + goto error; + } + memcpy(san->sync_alerts[indexNode].server_uri, alertURI, alertURIlen); + } + + char *alertContentType = NULL; + unsigned alertContentTypeLen = 0; + WBXMLTreeNode *alertcontenttype_node; + if ((alertcontenttype_node = wbxml_tree_node_elt_get_from_name(alert_node, "Type", TRUE)) == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL from wbxml_tree_node_elt_get_from_name. [Type]"); + goto error; + } + + if (alertcontenttype_node->children != NULL && alertcontenttype_node->children->type == WBXML_TREE_TEXT_NODE && alertcontenttype_node->children->content != NULL) { + + alertContentType = (char *)wbxml_buffer_get_cstr(alertcontenttype_node->children->content); + alertContentTypeLen = wbxml_buffer_len(alertcontenttype_node->children->content); + + if (alertContentType == NULL) { + _DEBUG_ERROR("[sanPackage11Parser] NULL alertContentType detected. alertContentType MUST NOT be NULL."); + goto error; + } + + int j; + int cnt = (int)sizeof(contentTypeSupported) / sizeof(san_content_type_s); + bool isContentSupported = false; + + for (j = 0; j < cnt; j++) { + if (contentTypeSupported[j].strType == NULL) + continue; + if (strcmp(alertContentType, contentTypeSupported[j].strType) == 0) { + san->sync_alerts[indexNode].content_type = contentTypeSupported[j].strType; + isContentSupported = true; + break; + } + } + + if (!isContentSupported) { + _DEBUG_ERROR("[sanPackage11Parser] SAN doesn't support the content type %s.", alertContentType); + goto error; + } + } + } + } + + wbxml_tree_destroy(wbxml_tree); + + _EXTERN_FUNC_EXIT; + return san; + + error: + + sanPackageParserFree(san); + + _EXTERN_FUNC_EXIT; + return NULL; + +} + +void sanPackageParserFree(void *point) +{ + _EXTERN_FUNC_ENTER; + + san_package_s *san = (san_package_s *) point; + if (san != NULL) { + if (san->msg_body_without_digest != NULL) + free(san->msg_body_without_digest); + if (san->digest != NULL) + free(san->digest); + if (san->cred != NULL) { + if (san->cred->cred_format != NULL) + free(san->cred->cred_format); + if (san->cred->cred_auth != NULL) + free(san->cred->cred_auth); + if (san->cred->cred_data != NULL) + free(san->cred->cred_data); + free(san->cred); + } + if (san->server_id != NULL) + free(san->server_id); + if (san->sync_alerts != NULL) { + int i; + for (i = 0; i < san->cnt_sync_alerts; i++) { + if (san->sync_alerts[i].server_uri != NULL) { + free(san->sync_alerts[i].server_uri); + } + } + free(san->sync_alerts); + } + free(san); + } + + _EXTERN_FUNC_EXIT; +} + +void sanPrintMsg(san_package_s * san) +{ + _EXTERN_FUNC_ENTER; + + int i; + + _DEBUG_INFO("Printing SAN package ============================\n\n"); + + _DEBUG_INFO("MsgBody without Digest :\n\t"); + for (i = 0; i < san->msg_body_without_digest_length; i++) { + _DEBUG_INFO("%02x ", san->msg_body_without_digest[i]); + if ((i + 1) % 16 == 0) + _DEBUG_INFO("\n\t"); + } + _DEBUG_INFO("\n"); + + _DEBUG_INFO("Digest : %s\n", san->digest); + if (san->cred != NULL) { + if (san->cred->cred_format != NULL) + _DEBUG_INFO("Cred Format : %s\n", san->cred->cred_format); + if (san->cred->cred_auth != NULL) + _DEBUG_INFO("Cred Type : %s\n", san->cred->cred_auth); + if (san->cred->cred_data != NULL) + _DEBUG_INFO("Cred Data : %s\n", san->cred->cred_data); + } + _DEBUG_INFO("Version : %d\n", san->version); + _DEBUG_INFO("UI mode : %d\n", san->ui_mode); + _DEBUG_INFO("Initiator : %d\n", san->initiator); + _DEBUG_INFO("Session ID : %u\n", san->session_id); + _DEBUG_INFO("Server ID : %s\n", san->server_id); + _DEBUG_INFO("No. of Sync : %u\n", san->cnt_sync_alerts); + + for (i = 0; i < san->cnt_sync_alerts; i++) { + _DEBUG_INFO("\n\t=== Sync No. %d ============\n", i + 1); + _DEBUG_INFO("\tSync type : %d\n", san->sync_alerts[i].sync_type); + _DEBUG_INFO("\tContent type : %s\n", san->sync_alerts[i].content_type); + _DEBUG_INFO("\tServer URI : %s\n", san->sync_alerts[i].server_uri); + }; + + _EXTERN_FUNC_EXIT; +} + +int parse_ip_push_msg(char *data, san_package_s ** san_package, char **id) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(data == NULL, 0, "data is NULL"); + + char *pay = NULL; + char *body = NULL; + char *decoded_body = NULL; + unsigned int decoded_size; + + *id = strtok(data, "|"); + pay = strtok(NULL, "|"); + body = strtok(NULL, "|"); + + _DEBUG_INFO("id = %s", *id); + _DEBUG_INFO("pay = %s", pay); + _DEBUG_INFO("after = %s", body); + + decoded_body = (char *)g_base64_decode(body, &decoded_size); + + _DEBUG_INFO("decoded_body = %s", decoded_body); + _DEBUG_INFO("decoded_size = %d", decoded_size); + + *san_package = san_package_12_parser(decoded_body, decoded_size); + + if ((*san_package) != NULL) { + _DEBUG_INFO("serverId = %s", (*san_package)->server_id); + _DEBUG_INFO("sessionID = %d", (*san_package)->session_id); + _DEBUG_INFO("cntSyncAlerts = %d", (*san_package)->cnt_sync_alerts); + int i; + for (i = 0; i < (*san_package)->cnt_sync_alerts; i++) { + _DEBUG_INFO("syncAlerts = %d", (*san_package)->sync_alerts[i].sync_type); + } + } else { + _DEBUG_ERROR("pSanPackage is NULL"); + goto error; + } + + _EXTERN_FUNC_EXIT; + return 1; + + error: + + _EXTERN_FUNC_EXIT; + return 0; +} diff --git a/src/agent/framework/task/oma_ds_engine_controller_task.c b/src/agent/framework/task/oma_ds_engine_controller_task.c new file mode 100755 index 0000000..ba7012d --- /dev/null +++ b/src/agent/framework/task/oma_ds_engine_controller_task.c @@ -0,0 +1,1137 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 + +#include + +#include "framework/task/oma_ds_engine_controller_task.h" +#include "service-engine/se_account.h" +#include "service-engine/se_sync.h" +#include "service-engine/se_storage.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_COMMON" +#endif + +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 _request_msg_info_free(request_msg_info_t * info); +static void *_string_copy_struct(void *string); +static request_msg_info_t *_create_request_msg_info(int sync_type, unsigned int request_id); + +static void __free_resource_cp(resource_cp_s * resource); + +static void _free_sync_categorie_list(void *list) +{ + _INNER_FUNC_ENTER; + retm_if(list == NULL, "list is NULL"); + + GList *categories = (GList *) list; + GList *iter = NULL; + for (iter = categories; iter != NULL; iter = g_list_next(iter)) + free_sync_service(iter->data); + + g_list_free(categories); + _INNER_FUNC_EXIT; +} + +static void _free_delete_profile_list(void *list) +{ + _INNER_FUNC_ENTER; + retm_if(list == NULL, "list is NULL"); + + GList *profiles = (GList *) list; + GList *iter = NULL; + for (iter = profiles; iter != NULL; iter = g_list_next(iter)) + free(iter->data); + + g_list_free(profiles); + _INNER_FUNC_EXIT; +} + +static void _free_resource_cp_list(void *list) +{ + _INNER_FUNC_ENTER; + retm_if(list == NULL, "list is NULL"); + + 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); + _INNER_FUNC_EXIT; +} + +static void __free_resource_cp(resource_cp_s * resource) +{ + _INNER_FUNC_ENTER; + retm_if(resource == NULL, "resource is NULL"); + + 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->auth_type != NULL) + free(resource->auth_type); + + if (resource->auth_data != NULL) + free(resource->auth_data); + + free(resource); + _INNER_FUNC_EXIT; +} + +static request_msg_info_t *_create_request_msg_info(int sync_type, unsigned int request_id) +{ + _INNER_FUNC_ENTER; + request_msg_info_t *pInfo = (request_msg_info_t *) calloc(1, sizeof(request_msg_info_t)); + retvm_if(pInfo == NULL, NULL, "pInfo is NULL"); + + pInfo->sync_type = sync_type; + pInfo->request_id = request_id; + + _INNER_FUNC_EXIT; + return pInfo; +} + +static void _request_msg_info_free(request_msg_info_t * info) +{ + _INNER_FUNC_ENTER; + + if (info != NULL) + free(info); + + _INNER_FUNC_EXIT; +} + +static void *_string_copy_struct(void *string) +{ + _INNER_FUNC_ENTER; + + void *data = NULL; + data = strdup((const char *)string); + + _INNER_FUNC_EXIT; + return data; +} + +sync_agent_ec_task_spec_s *make_synchronize_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("syncMode", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("sanPackage", NULL, sanPackageParserFree, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *param_spec_array[3] = { pParam_spec1, pParam_spec2, pParam_spec3 }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("synchronize", + synchronize_task_process, NULL, NULL, + 3, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + sync_agent_unref_param_spec(pParam_spec2); + sync_agent_unref_param_spec(pParam_spec3); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_add_profile_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("profileDirName", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("profileName", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("addr", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_structure("syncMode", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_structure("syncType", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_structure("interval", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec9 = sync_agent_alloc_param_spec_structure("categories", NULL, _free_sync_categorie_list, + true, false, false, NULL, false, NULL, false, NULL); + + sync_agent_ec_param_spec_s *pParam_spec10 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec11 = sync_agent_alloc_param_spec_int("accountId", false, true, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *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 + }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("add_profile", + add_profile_task_process, NULL, NULL, + 11, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + sync_agent_unref_param_spec(pParam_spec2); + sync_agent_unref_param_spec(pParam_spec3); + sync_agent_unref_param_spec(pParam_spec4); + sync_agent_unref_param_spec(pParam_spec5); + sync_agent_unref_param_spec(pParam_spec6); + sync_agent_unref_param_spec(pParam_spec7); + sync_agent_unref_param_spec(pParam_spec8); + sync_agent_unref_param_spec(pParam_spec9); + sync_agent_unref_param_spec(pParam_spec10); + sync_agent_unref_param_spec(pParam_spec11); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_edit_profile_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("profileName", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("addr", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_structure("syncMode", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_structure("syncType", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_structure("interval", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec9 = sync_agent_alloc_param_spec_structure("categories", NULL, _free_sync_categorie_list, + true, false, false, NULL, false, NULL, false, NULL); + + sync_agent_ec_param_spec_s *pParam_spec10 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *param_spec_array[10] = { pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5, + pParam_spec6, pParam_spec7, pParam_spec8, pParam_spec9, pParam_spec10 + }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("edit_profile", + edit_profile_task_process, NULL, NULL, + 10, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + sync_agent_unref_param_spec(pParam_spec2); + sync_agent_unref_param_spec(pParam_spec3); + sync_agent_unref_param_spec(pParam_spec4); + sync_agent_unref_param_spec(pParam_spec5); + sync_agent_unref_param_spec(pParam_spec6); + sync_agent_unref_param_spec(pParam_spec7); + sync_agent_unref_param_spec(pParam_spec8); + sync_agent_unref_param_spec(pParam_spec9); + sync_agent_unref_param_spec(pParam_spec10); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_delete_profile_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("profiles", NULL, _free_delete_profile_list, + true, false, false, NULL, false, NULL, false, NULL); + + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("delete_profile", + delete_profile_task_process, NULL, NULL, + 2, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + sync_agent_unref_param_spec(pParam_spec2); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_get_profile_data_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("profileName", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("addr", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_structure("syncMode", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_structure("syncType", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec9 = sync_agent_alloc_param_spec_structure("interval", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec10 = sync_agent_alloc_param_spec_int("lastSessionStatus", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec11 = sync_agent_alloc_param_spec_int("lastSessionTime", false, true, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *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 + }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("get_profile_data", + get_profile_data_task_process, NULL, NULL, + 11, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + sync_agent_unref_param_spec(pParam_spec2); + sync_agent_unref_param_spec(pParam_spec3); + sync_agent_unref_param_spec(pParam_spec4); + sync_agent_unref_param_spec(pParam_spec5); + sync_agent_unref_param_spec(pParam_spec6); + sync_agent_unref_param_spec(pParam_spec7); + sync_agent_unref_param_spec(pParam_spec8); + sync_agent_unref_param_spec(pParam_spec9); + sync_agent_unref_param_spec(pParam_spec10); + sync_agent_unref_param_spec(pParam_spec11); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_get_profile_sync_category_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("contentType", true, false, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_int("enabled", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("srcURI", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_structure("tgtURI", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + + sync_agent_ec_param_spec_s *param_spec_array[8] = { pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, + pParam_spec5, pParam_spec6, pParam_spec7, pParam_spec8 + }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("get_profile_sync_category", + get_profile_sync_category_task_process, NULL, NULL, + 8, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + sync_agent_unref_param_spec(pParam_spec2); + sync_agent_unref_param_spec(pParam_spec3); + sync_agent_unref_param_spec(pParam_spec4); + sync_agent_unref_param_spec(pParam_spec5); + sync_agent_unref_param_spec(pParam_spec6); + sync_agent_unref_param_spec(pParam_spec7); + sync_agent_unref_param_spec(pParam_spec8); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_get_profile_statistics_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_int("contentType", true, false, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("dbSynced", _string_copy_struct, free, + false, true, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_int("lastSessionTime", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_int("server2Client_Total", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_int("server2Client_NrOfAdd", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec8 = sync_agent_alloc_param_spec_int("server2Client_NrOfDelete", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec9 = sync_agent_alloc_param_spec_int("server2Client_NrOfReplace", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec10 = sync_agent_alloc_param_spec_int("client2Server_Total", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec11 = sync_agent_alloc_param_spec_int("client2Server_NrOfAdd", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec12 = sync_agent_alloc_param_spec_int("client2Server_NrOfDelete", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec13 = sync_agent_alloc_param_spec_int("client2Server_NrOfReplace", false, true, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *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 + }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("get_profile_statistics", + get_profile_statistics_task_process, NULL, NULL, + 13, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + sync_agent_unref_param_spec(pParam_spec2); + sync_agent_unref_param_spec(pParam_spec3); + sync_agent_unref_param_spec(pParam_spec4); + sync_agent_unref_param_spec(pParam_spec5); + sync_agent_unref_param_spec(pParam_spec6); + sync_agent_unref_param_spec(pParam_spec7); + sync_agent_unref_param_spec(pParam_spec8); + sync_agent_unref_param_spec(pParam_spec9); + sync_agent_unref_param_spec(pParam_spec10); + sync_agent_unref_param_spec(pParam_spec11); + sync_agent_unref_param_spec(pParam_spec12); + sync_agent_unref_param_spec(pParam_spec13); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_reset_synchronizing_profiles_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("reset_synchronizing_profiles", + reset_synchronizing_profiles_task_process, NULL, NULL, + 0, NULL); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_add_profile_cp_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_structure("profileName", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("addr", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec3 = sync_agent_alloc_param_spec_structure("id", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec4 = sync_agent_alloc_param_spec_structure("password", _string_copy_struct, free, + true, false, false, NULL, false, NULL, false, NULL); + sync_agent_ec_param_spec_s *pParam_spec5 = sync_agent_alloc_param_spec_structure("categories", NULL, _free_resource_cp_list, + true, false, false, NULL, false, NULL, false, NULL); + + sync_agent_ec_param_spec_s *pParam_spec6 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec7 = sync_agent_alloc_param_spec_int("accountId", false, true, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *param_spec_array[7] = { pParam_spec1, pParam_spec2, pParam_spec3, pParam_spec4, pParam_spec5, + pParam_spec6, pParam_spec7 + }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("add_profile_cp", + add_profile_cp_task_process, NULL, NULL, + 7, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + sync_agent_unref_param_spec(pParam_spec2); + sync_agent_unref_param_spec(pParam_spec3); + sync_agent_unref_param_spec(pParam_spec4); + sync_agent_unref_param_spec(pParam_spec5); + sync_agent_unref_param_spec(pParam_spec6); + sync_agent_unref_param_spec(pParam_spec7); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_refresh_from_service_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("accountId", true, false, false, 0, 0, false, 0, false, 0, 0); + + sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("refresh_from_service", + refresh_from_service_task_process, NULL, NULL, + 1, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_cancel_request_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("cancel_sync_request", + cancel_sync_request_task_process, NULL, NULL, + 0, NULL); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_reset_all_data_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *param_spec_array[1] = { pParam_spec1 }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("reset_all_data", + reset_all_data_task_process, NULL, NULL, + 1, param_spec_array); + + sync_agent_unref_param_spec(pParam_spec1); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_spec_s *make_get_all_profiles_data_task() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_param_spec_s *pParam_spec1 = sync_agent_alloc_param_spec_int("result", false, true, false, 0, 0, false, 0, false, 0, 0); + sync_agent_ec_param_spec_s *pParam_spec2 = sync_agent_alloc_param_spec_structure("profilesData", NULL, NULL, + false, true, false, NULL, false, NULL, false, NULL); + + sync_agent_ec_param_spec_s *param_spec_array[2] = { pParam_spec1, pParam_spec2 }; + + sync_agent_ec_task_spec_s *pTask_spec = sync_agent_alloc_simple_task_spec("get_all_profiles_data", + get_all_profiles_data_task_process, NULL, NULL, + 2, param_spec_array); + + _EXTERN_FUNC_EXIT; + return pTask_spec; +} + +sync_agent_ec_task_error_e synchronize_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + int accountId = 0; + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId); + retvm_if(accountId < 0, SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED, "account id = %d", accountId); + + char *syncMode = NULL; + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncMode); + + san_package_s *pSanPackage = NULL; + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &pSanPackage); + + _DEBUG_INFO("accountId = %d", accountId); + _DEBUG_INFO("syncMode = %s", syncMode); + + bool result = synchronize(accountId, syncMode, pSanPackage); + if (result == false) + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e add_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_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; + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileDirName); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileName); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncMode); + sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncType); + sync_agent_get_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &interval); + sync_agent_get_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &categories); + + res = add_profile(profileDirName, profileName, addr, id, password, syncMode, syncType, interval, categories, &accountId); + if (res == false) { + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + result = 0; + } else + result = 1; + + sync_agent_set_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_set_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId); + + /*step 2 : start refresh_from_service for added account */ + void *in_param_value_array[1] = { &accountId }; + int in_param_index_array[1] = { 0 }; + sync_agent_ec_value_type_e in_param_value_type_array[1] = { SYNC_AGENT_EC_VALUE_TYPE_INT }; + unsigned int request_msg_id = 0; + sync_agent_request_async_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); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e edit_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_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; + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileName); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + sync_agent_get_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncMode); + sync_agent_get_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncType); + sync_agent_get_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &interval); + sync_agent_get_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &categories); + + res = edit_profile(accountId, profileName, addr, id, password, syncMode, syncType, interval, categories); + if (res == false) { + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + result = 0; + } else + result = 1; + + sync_agent_set_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e delete_profile_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + bool res; + int result; + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + GList *profiles = NULL; + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profiles); + + res = delete_profiles(profiles); + if (res == 0) { + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + result = 0; + } else + result = 1; + + sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + + _EXTERN_FUNC_EXIT; + return err; + +} + +sync_agent_ec_task_error_e get_profile_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + int accountId = 0; + char *profileName = NULL; + char *addr = NULL; + char *id = NULL; + char *password = NULL; + char *syncMode = NULL; + char *syncType = NULL; + char *interval = NULL; + int lastSessionStatus; + int lastSessionTime; + int result; + bool res; + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId); + retvm_if(accountId < 0, SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED, "account id = %d", accountId); + + res = get_profile_data(accountId, &profileName, &addr, &id, &password, &syncMode, &syncType, &interval, &lastSessionStatus, &lastSessionTime); + if (res == false) { + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + result = 0; + } else + result = 1; + + sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_set_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileName); + sync_agent_set_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr); + sync_agent_set_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_set_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + sync_agent_set_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncMode); + sync_agent_set_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &syncType); + sync_agent_set_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &interval); + sync_agent_set_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &lastSessionStatus); + sync_agent_set_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &lastSessionTime); + + _EXTERN_FUNC_EXIT; + return err; + +} + +sync_agent_ec_task_error_e get_profile_sync_category_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + int accountId = 0; + int contentType; + + int enabled = 0; + char *srcURI = NULL; + char *tgtURI = NULL; + char *id = NULL; + char *password = NULL; + bool res; + int result = 0; + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId); + retvm_if(accountId < 0, SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED, "account id = %d", accountId); + + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &contentType); + + res = get_profile_sync_category(accountId, contentType, &enabled, &srcURI, &tgtURI, &id, &password); + if (res == false) { + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + result = 0; + } else + result = 1; + + sync_agent_set_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_set_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &enabled); + sync_agent_set_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &srcURI); + sync_agent_set_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &tgtURI); + sync_agent_set_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_set_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e get_profile_statistics_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + int accountId = 0; + int contentType; + + char *dbSynced = NULL; + int lastSessionTime = -1; + int server2Client_Total = 0; + int server2Client_NrOfAdd = 0; + int server2Client_NrOfDelete = 0; + int server2Client_NrOfReplace = 0; + int client2Server_Total = 0; + int client2Server_NrOfAdd = 0; + int client2Server_NrOfDelete = 0; + int client2Server_NrOfReplace = 0; + + bool res; + int result; + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId); + retvm_if(accountId < 0, SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED, "account id = %d", accountId); + + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_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 = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + result = 0; + } else + result = 1; + + sync_agent_set_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_set_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &dbSynced); + sync_agent_set_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &lastSessionTime); + sync_agent_set_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_Total); + sync_agent_set_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfAdd); + sync_agent_set_param_value(&(param_array[7]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfDelete); + sync_agent_set_param_value(&(param_array[8]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &server2Client_NrOfReplace); + sync_agent_set_param_value(&(param_array[9]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_Total); + sync_agent_set_param_value(&(param_array[10]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfAdd); + sync_agent_set_param_value(&(param_array[11]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfDelete); + sync_agent_set_param_value(&(param_array[12]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &client2Server_NrOfReplace); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e reset_synchronizing_profiles_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + reset_synchronizing_profiles(); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e add_profile_cp_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_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; + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profileName); + sync_agent_get_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &addr); + sync_agent_get_param_value(&(param_array[2]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &id); + sync_agent_get_param_value(&(param_array[3]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &password); + sync_agent_get_param_value(&(param_array[4]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &categories); + + res = add_profile_cp(profileName, addr, id, password, categories, &accountId); + if (res == false) { + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + result = 0; + } else + result = 1; + + sync_agent_set_param_value(&(param_array[5]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_set_param_value(&(param_array[6]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e refresh_from_service_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + int accountId; + bool res; + + sync_agent_get_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &accountId); + + res = refresh_from_service_all(accountId); + if (res == false) + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e cancel_sync_request_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + cancel_sync_request(); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e reset_all_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + int result = 1; + + /* delete all profiles */ + result = delete_all_profiles(); + + /* delete all agent default table */ + result = delete_all_agent_default_table(); + + sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_ec_task_error_e get_all_profiles_data_task_process(unsigned int param_cnt, sync_agent_ec_param_param_s ** param_array) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_ec_task_error_e err = SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS; + + bool res; + int result; + GList *profiles_data = NULL; + + res = get_all_profiles_data(&profiles_data); + + if (res == false) { + err = SYNC_AGENT_EC_TASK_ERROR_RUN_FAILED; + result = 0; + } else + result = 1; + + sync_agent_set_param_value(&(param_array[0]->param_value), SYNC_AGENT_EC_VALUE_TYPE_INT, &result); + sync_agent_set_param_value(&(param_array[1]->param_value), SYNC_AGENT_EC_VALUE_TYPE_STRUCT, &profiles_data); + + _EXTERN_FUNC_EXIT; + return err; + +} + +void insert_request_msg_info(int sync_type, unsigned int request_id) +{ + _EXTERN_FUNC_ENTER; + + sync_request_id_list = g_list_prepend(sync_request_id_list, _create_request_msg_info(sync_type, request_id)); + + _EXTERN_FUNC_EXIT; +} + +void delete_request_msg_info(unsigned int request_id) +{ + _EXTERN_FUNC_ENTER; + + 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); + } + _EXTERN_FUNC_EXIT; +} + +bool get_synchronizing_request_id(unsigned int *pRequest_id) +{ + _EXTERN_FUNC_ENTER; + + 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; + } + } + + _EXTERN_FUNC_EXIT; + return success; +} + +bool get_manual_sync_request_id(unsigned int *pRequest_id) +{ + _EXTERN_FUNC_ENTER; + + 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; + } + } + + _EXTERN_FUNC_EXIT; + return success; +} + +bool get_periodic_sync_request_id(unsigned int *pRequest_id) +{ + _EXTERN_FUNC_ENTER; + + 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; + } + } + + _EXTERN_FUNC_EXIT; + return success; +} + +bool get_san_sync_request_id(unsigned int *pRequest_id) +{ + _EXTERN_FUNC_ENTER; + + 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; + } + } + + _EXTERN_FUNC_EXIT; + return success; +} + +bool get_auto_configure_request_id(unsigned int *pRequest_id) +{ + _EXTERN_FUNC_ENTER; + + 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; + } + } + + _EXTERN_FUNC_EXIT; + return success; +} + +bool cancel_current_sync_task() +{ + _EXTERN_FUNC_ENTER; + + unsigned int request_msg_id_to_cancel = 0; + unsigned int request_msg_id = 0; + bool has_autoconfig = get_auto_configure_request_id(&request_msg_id_to_cancel); + if (has_autoconfig) { + _DEBUG_INFO("has_autoconfig [%d] ", request_msg_id_to_cancel); + sync_agent_cancel_task(request_msg_id_to_cancel); + } else { + bool has_sync = get_synchronizing_request_id(&request_msg_id_to_cancel); + if (has_sync) { + _DEBUG_INFO("has_manual_sync [%d] ", request_msg_id_to_cancel); + sync_agent_cancel_task(request_msg_id_to_cancel); + + /*request network session cancel */ + sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST, 0, 0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id); + } else { + /* nothing to do */ + } + } + + _EXTERN_FUNC_EXIT; + return true; +} diff --git a/src/agent/main/main.c b/src/agent/main/main.c new file mode 100755 index 0000000..b6795de --- /dev/null +++ b/src/agent/main/main.c @@ -0,0 +1,395 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @main.c + * @version 0.1 + * @brief This file is the source file of implementation of main function + */ + +typedef enum { + OMA_DS_ADD_PROFILE = 1, + OMA_DS_EDIT_PROFILE = 2, + OMA_DS_DELETE_PROFILE = 3, + OMA_DS_REQUEST_SYNC = 4, + OMA_DS_CANCEL_SYNC = 5, + OMA_DS_GET_PROFILE_DATA = 6, + OMA_DS_GET_PROFILE_SYNC_CATEGORY = 7, + OMA_DS_GET_PROFILE_SYNC_STATISTICS = 8, + OMA_DS_GET_ALL_PROFILES_DATA = 9, + OMA_DS_ADD_PROFILE_CP = 10, + OMA_DS_REQUEST_CALLLOG_SYNC = 11, + OMA_DS_RESET_ALL_DATA = 12 +} oma_ds_event_e; + +#include +#include +#include +#include + +#include +#include + +#include + +#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/csc_keys.h" +#include "common/common_define_internal.h" +#include "common/common_vconf.h" +#include "service-engine/se_account.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_MAIN" +#endif + +#define MC_SERVICE_OBJECT_PATH "/com/samsung/omadsagent" /* Don't use special character */ +#define MC_SERVICE_DBUS "com.samsung.omadsagent" +#define MC_SERVICE_INTERFACE "com.samsung.omadsagent" + +static DBusConnection *connection = NULL; + +static void _unregistered_path(DBusConnection * connection, void *user_data) +{ + /* connection was finalized */ + _INNER_FUNC_ENTER; + + _INNER_FUNC_EXIT; +} + +static DBusHandlerResult _message_path(DBusConnection * connection, DBusMessage * message, void *user_data) +{ + _INNER_FUNC_ENTER; + if (dbus_message_is_method_call(message, MC_SERVICE_DBUS, "Echo")) { + DBusMessage *reply; + _DEBUG_INFO("Recived the HelloFromSelf message\n"); + + reply = dbus_message_new_method_return(message); + if (reply == NULL) + _DEBUG_ERROR("no memory\n"); + + if (!dbus_connection_send(connection, reply, NULL)) + _DEBUG_ERROR("no memory\n"); + } else if (dbus_message_is_method_call(message, MC_SERVICE_DBUS, "Hello_Agent")) { + _DEBUG_INFO("Hello_Agent"); + } else if (dbus_message_is_method_call(message, MC_SERVICE_DBUS, "Goodbye_Agent")) { + _DEBUG_INFO("Goodbye_Agent"); + _INNER_FUNC_EXIT; + exit(1); + } else { + _DEBUG_INFO("can't match message"); + } + + _INNER_FUNC_EXIT; + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static DBusObjectPathVTable echo_vtable = { + _unregistered_path, + _message_path, + NULL, +}; + +static int _register_dbus_service(void) +{ + _INNER_FUNC_ENTER; + int result; + DBusError error; + void *d; + + dbus_error_init(&error); + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + _DEBUG_ERROR("*** Failed to open connection to activating message bus: %s\n", error.message); + dbus_error_free(&error); + return 1; + } + + if (!dbus_connection_register_object_path(connection, MC_SERVICE_OBJECT_PATH, &echo_vtable, (void *)0xdeadbeef)) { + _DEBUG_ERROR("no memory\n"); + goto failed; + } + + if (!dbus_connection_get_object_path_data(connection, MC_SERVICE_OBJECT_PATH, &d)) { + _DEBUG_ERROR("no memory\n"); + goto failed; + } + + if (d != (void *)0xdeadbeef) { + _DEBUG_ERROR("dbus_connection_get_object_path_data() doesn't seem to work right\n"); + goto failed; + } + + result = dbus_bus_request_name(connection, MC_SERVICE_DBUS, 0, &error); + if (dbus_error_is_set(&error)) { + _DEBUG_ERROR("Error %s\n", error.message); + dbus_error_free(&error); + dbus_connection_unref(connection); + _INNER_FUNC_EXIT; + exit(1); + } + + _INNER_FUNC_EXIT; + return 0; + + failed: + dbus_connection_unref(connection); + _INNER_FUNC_EXIT; + return 1; +} + +//static void __update_csc() +//{ +// _INNER_FUNC_ENTER; +// +// char profile[128]; +// int numberOfProfiles = 0; +// char *contents = "check"; +// +// bool result = get_vconf_Int_key(CSC_VCONF_KEY_SYNCMLDS_NBDATASYNC, &numberOfProfiles); +// if (result == false) { +// _DEBUG_ERROR("failed in get_vconf_Int_key"); +// goto error; +// } +// +// int i; +// for (i = 1; i <= numberOfProfiles; i++) { +// snprintf(profile, sizeof(profile), "Sync%d", i); +// add_profile_csc(i); +// } +// +// sync_agent_write_whole_file(OMA_DS_CSC_CHECK_PATH, contents, strlen(contents), false); +// +//error: +// +// _INNER_FUNC_EXIT; +//} + +static void _request_reset_synchronizing_profiles() +{ + _INNER_FUNC_ENTER; + + unsigned int request_msg_id = 0; + sync_agent_request_async_task(EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES, 0, 0, NULL, NULL, NULL, NULL, NULL, (int *)&request_msg_id); + _INNER_FUNC_EXIT; +} + +static void _check_csc() +{ + _INNER_FUNC_ENTER; + + 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 = sync_agent_is_existing_fs(OMA_DS_CSC_CHECK_PATH); */ + exist = true; + _DEBUG_TRACE("update = %d", exist); + + /* for prevent */ +// if (exist == false) +// __update_csc(); + + _INNER_FUNC_EXIT; +} + +static void _agent_daemon_signal_handler(int signo, siginfo_t * info, void *p_context) +{ + _INNER_FUNC_ENTER; + + switch (signo) { + case SIGTERM: + _DEBUG_TRACE("Got SIGTERM"); + + /* stop gmain loop */ + sync_agent_stop_main_loop(0); + + break; + + default: + break; + } + + _INNER_FUNC_EXIT; +} + +int main() +{ + _EXTERN_FUNC_ENTER; + + struct sigaction sig_act; + + sync_agent_event_error_e error = SYNC_AGENT_EVENT_SUCCESS; + sync_agent_deinit_error_e deinit_error = SYNC_AGENT_DEINIT_SUCCESS; + + if (sync_agent_daemonize() < 0) { + _DEBUG_ERROR("daemonize error"); + return -1; + } + + _register_dbus_service(); + + sync_agent_init_error_e init_error = sync_agent_init("/usr/share/oma-ds-cfg/omads_fw_config.xml"); + if (init_error != SYNC_AGENT_INIT_SUCCESS) { + _DEBUG_ERROR("Failed to sync_agent_init() : %d", init_error); + } else { + _DEBUG_INFO("done init_Framework"); + } + + sync_agent_ec_task_spec_s *pSyncTaskSpec = make_synchronize_task(); + sync_agent_ec_task_spec_s *pAddProfileTaskSpec = make_add_profile_task(); + sync_agent_ec_task_spec_s *pEditProfileTaskSpec = make_edit_profile_task(); + sync_agent_ec_task_spec_s *pDeleteProfileTaskSpec = make_delete_profile_task(); + sync_agent_ec_task_spec_s *pGetProfileDataTaskSpec = make_get_profile_data_task(); + sync_agent_ec_task_spec_s *pGetProfileSyncCategoryTaskSpec = make_get_profile_sync_category_task(); + sync_agent_ec_task_spec_s *pGetProfileStatisticsTaskSpec = make_get_profile_statistics_task(); + sync_agent_ec_task_spec_s *pResetSynchronizingProfilesTaskSpec = make_reset_synchronizing_profiles_task(); + sync_agent_ec_task_spec_s *pAddProfileCPTaskSpec = make_add_profile_cp_task(); + sync_agent_ec_task_spec_s *pRefreshFromServiceTaskSpec = make_refresh_from_service_task(); + sync_agent_ec_task_spec_s *pCancelSyncRequestTaskSpec = make_cancel_request_task(); + sync_agent_ec_task_spec_s *pResetAllDataTaskSpec = make_reset_all_data_task(); + sync_agent_ec_task_spec_s *pGetAllProfilesData = make_get_all_profiles_data_task(); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_REQUEST, EC_MSG_TYPE_NAME_SYNC_TASK_REQUEST, pSyncTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE, EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE, pAddProfileTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_EDIT_PROFILE, EC_MSG_TYPE_NAME_SYNC_TASK_EDIT_PROFILE, pEditProfileTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_DELETE_PROFILE, EC_MSG_TYPE_NAME_SYNC_TASK_DELETE_PROFILE, pDeleteProfileTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_DATA, EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_DATA, pGetProfileDataTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY, EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_SYNC_CATEGORY, pGetProfileSyncCategoryTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_PROFILE_STATISTICS, EC_MSG_TYPE_NAME_SYNC_TASK_GET_PROFILE_STATISTICS, pGetProfileStatisticsTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES, EC_MSG_TYPE_NAME_SYNC_TASK_RESET_SYNCHRONIZING_PROFILES, pResetSynchronizingProfilesTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_ADD_PROFILE_CP, EC_MSG_TYPE_NAME_SYNC_TASK_ADD_PROFILE_CP, pAddProfileCPTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE, EC_MSG_TYPE_NAME_SYNC_TASK_REFRESH_FROM_SERVICE, pRefreshFromServiceTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_CANCEL_SYNC_REQUEST, EC_MSG_TYPE_NAME_SYNC_TASK_CANCEL_SYNC_REQUEST, pCancelSyncRequestTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_RESET_ALL_DATA, EC_MSG_TYPE_NAME_SYNC_TASK_RESET_ALL_DATA, pResetAllDataTaskSpec, NULL); + + sync_agent_register_task_spec(EC_MSG_TYPE_SYNC_TASK_GET_ALL_PROFILES_DATA, EC_MSG_TYPE_NAME_SYNC_TASK_GET_ALL_PROFILES_DATA, pGetAllProfilesData, NULL); + + sync_agent_ec_queuing_rule_spec_s *pQueuing_rule = sync_agent_create_queuing_rule_spec_outline("sync_queueing_rule"); + + sync_agent_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_REFRESH_FROM_SERVICE, pSyncTaskSpec, 0); + + sync_agent_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_REQUEST, pSyncTaskSpec, 0); + + sync_agent_add_progress_blocking_element(pQueuing_rule, EC_MSG_TYPE_SYNC_TASK_RESET_ALL_DATA, pSyncTaskSpec, 0); + + sync_agent_register_async_queuing_rule_spec(pQueuing_rule, NULL, NULL); + + sync_agent_unref_queuing_rule_spec(pQueuing_rule); + + _request_reset_synchronizing_profiles(); /*reset synchronizing flag 0 every account & construct item tbl */ + + error = sync_agent_set_event_callback(OMA_DS_ADD_PROFILE, event_callback_add_profile_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_EDIT_PROFILE, event_callback_edit_profile_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_DELETE_PROFILE, event_callback_delete_profile_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_REQUEST_SYNC, event_callback_request_sync_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_CANCEL_SYNC, event_callback_cancel_sync_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_GET_PROFILE_DATA, event_callback_get_profile_data_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_GET_PROFILE_SYNC_CATEGORY, event_callback_get_profile_sync_category_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_GET_PROFILE_SYNC_STATISTICS, event_callback_get_profile_last_statistics_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_GET_ALL_PROFILES_DATA, event_callback_request_get_all_profiles_data); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_ADD_PROFILE_CP, event_callback_add_profile_cp_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_REQUEST_CALLLOG_SYNC, event_callback_request_calllog_sync_async); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + error = sync_agent_set_event_callback(OMA_DS_RESET_ALL_DATA, event_callback_request_reset_all_data_sync); + if (error != SYNC_AGENT_EVENT_SUCCESS) + _DEBUG_ERROR("failed sync_agent_set_event_callback()"); + + sync_agent_pm_return_e san_err = sync_agnet_register_user_callback(3, NULL, 1, san_callback_parse); + if (san_err != SYNC_AGENT_PM_SUCCESS) + _DEBUG_ERROR("failed in sync_agnet_register_user_callback"); + + sync_agent_pm_return_e scheduler_err = sync_agnet_register_user_callback(1, NULL, 1, send_periodic_sync_msg); + if (scheduler_err != SYNC_AGENT_PM_SUCCESS) + _DEBUG_ERROR("failed in sync_agnet_register_user_callback"); + + /*register profiles from csc */ + _check_csc(); + + /* Block SIGPIPE signal (client may close socket abnormally) */ + signal(SIGPIPE, SIG_IGN); + + /* register signal handler. will be called by kill command */ + sig_act.sa_handler = NULL; + sig_act.sa_sigaction = _agent_daemon_signal_handler; + sig_act.sa_flags = SA_SIGINFO; + sigemptyset(&sig_act.sa_mask); + sigaction(SIGTERM, &sig_act, NULL); + + sync_agent_run_main_loop(0); + + if (connection) { + dbus_connection_unref(connection); + connection = NULL; + } + + deinit_error = sync_agent_deinit(); + if (deinit_error != SYNC_AGENT_DEINIT_SUCCESS) + _DEBUG_ERROR("failed in sync_agent_deinit"); + + _EXTERN_FUNC_EXIT; + + return 0; +} diff --git a/src/agent/service-adapter/network-binder/na_binder.c b/src/agent/service-adapter/network-binder/na_binder.c new file mode 100755 index 0000000..4c9ff49 --- /dev/null +++ b/src/agent/service-adapter/network-binder/na_binder.c @@ -0,0 +1,142 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @NA_Binder.c + * @version 0.1 + * @brief This file is the source file of implementation of header binder function for Network Adapter + */ + +#include + +#include "service-adapter/network-binder/na_binder.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SA" +#endif + +int na_http_header_binder(char *acc_type, char *loc_uri, bool is_xml, char *jsession_id, GList ** list) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(acc_type == NULL, 0, "[NA Header Binder] accType is NULL"); + retvm_if(loc_uri == NULL, 0, "[NA Header Binder] loc_uri is NULL"); + + if (!strcmp(acc_type, "OMA_DS")) { + sync_agent_na_common_header_info_s *method = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(method == NULL, 0, "[NA Header Binder] 'method' malloc fail !!"); + + memset(method, 0x00, sizeof(sync_agent_na_common_header_info_s)); + method->key = "method"; + method->value = "post"; + *list = g_list_append(*list, method); + + sync_agent_na_common_header_info_s *uri = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(uri == NULL, 0, "[NA Header Binder] 'uri' malloc fail !!"); + + memset(uri, 0x00, sizeof(sync_agent_na_common_header_info_s)); + uri->key = "uri"; + uri->value = loc_uri; + *list = g_list_append(*list, uri); + + sync_agent_na_common_header_info_s *cache_control = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(cache_control == NULL, 0, "[NA Header Binder] 'cache_control' malloc fail !!"); + + memset(cache_control, 0x00, sizeof(sync_agent_na_common_header_info_s)); + cache_control->key = "Cache-Control"; + cache_control->value = "no-store, private"; + *list = g_list_append(*list, cache_control); + + sync_agent_na_common_header_info_s *connection = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(connection == NULL, 0, "[NA Header Binder] 'connection' malloc fail !!"); + + memset(connection, 0x00, sizeof(sync_agent_na_common_header_info_s)); + connection->key = "Connection"; + connection->value = "Keep-Alive"; + *list = g_list_append(*list, connection); + + sync_agent_na_common_header_info_s *accept = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(accept == NULL, 0, "[NA Header Binder] 'accept' malloc fail !!"); + + memset(accept, 0x00, sizeof(sync_agent_na_common_header_info_s)); + accept->key = "Accept"; + if (is_xml == true) + accept->value = "application/vnd.syncml+xml"; + else + accept->value = "application/vnd.syncml+wbxml"; + *list = g_list_append(*list, accept); + + sync_agent_na_common_header_info_s *accept_language = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(accept_language == NULL, 0, "[NA Header Binder] 'accept_language' malloc fail !!"); + + memset(accept_language, 0x00, sizeof(sync_agent_na_common_header_info_s)); + accept_language->key = "Accept-Language"; + accept_language->value = "en-US"; + *list = g_list_append(*list, accept_language); + + sync_agent_na_common_header_info_s *accept_charset = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(accept_charset == NULL, 0, "[NA Header Binder] 'accept_charset' malloc fail !!"); + + memset(accept_charset, 0x00, sizeof(sync_agent_na_common_header_info_s)); + accept_charset->key = "Accept-Charset"; + accept_charset->value = "UTF-8"; + *list = g_list_append(*list, accept_charset); + + sync_agent_na_common_header_info_s *content_type = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(content_type == NULL, 0, "[NA Header Binder] 'content_type' malloc fail !!"); + + memset(content_type, 0x00, sizeof(sync_agent_na_common_header_info_s)); + content_type->key = "Content-Type"; + if (is_xml == true) + content_type->value = "application/vnd.syncml+xml"; + else + content_type->value = "application/vnd.syncml+wbxml"; + *list = g_list_append(*list, content_type); + + if (jsession_id != NULL) { + _DEBUG_INFO(" jsessionid : %s\n", jsession_id); + sync_agent_na_common_header_info_s *cookie = (sync_agent_na_common_header_info_s *) malloc(sizeof(sync_agent_na_common_header_info_s)); + retvm_if(cookie == NULL, 0, "[NA Header Binder] 'cookie' malloc fail !!"); + + memset(cookie, 0x00, sizeof(sync_agent_na_common_header_info_s)); + cookie->key = "cookie"; + cookie->value = jsession_id; + *list = g_list_append(*list, cookie); + _DEBUG_INFO(" cookie : %s\n", cookie->value); + } + } + + GList *iter = NULL; + for (iter = *list; iter != NULL; iter = g_list_next(iter)) { + _DEBUG_INFO("[NA_Header_Binder] key : %s, value : %s", ((sync_agent_na_common_header_info_s *) (iter->data))->key, ((sync_agent_na_common_header_info_s *) (iter->data))->value); + } + + _EXTERN_FUNC_EXIT; + return 1; +} + +void free_header_info(sync_agent_na_common_header_info_s * common_header_info) +{ + _EXTERN_FUNC_ENTER; + + retm_if(common_header_info == NULL, "pCommon_header_info is NULL"); + + free(common_header_info); + + _EXTERN_FUNC_EXIT; +} diff --git a/src/agent/service-adapter/protocol-binder/oma_ds_protocol_binder.c b/src/agent/service-adapter/protocol-binder/oma_ds_protocol_binder.c new file mode 100755 index 0000000..b6b14db --- /dev/null +++ b/src/agent/service-adapter/protocol-binder/oma_ds_protocol_binder.c @@ -0,0 +1,5256 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @oma_ds_protocol_binder.c + * @version 0.1 + * @brief This file is the source file of implementation of callback function for Protocol Binder + */ + +#include + +#include + +#include "service-adapter/protocol-binder/oma_ds_protocol_binder.h" +#include "service-adapter/sa_elements_internal.h" +#include "service-adapter/sa_command_internal.h" +#include "service-adapter/sa_devinf_internal.h" +#include "service-adapter/sa_command.h" +#include "service-adapter/sa_elements.h" +#include "service-adapter/sa_devinf.h" +#include "service-adapter/sa_define.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_BINDER" +#endif + +static sync_agent_pb_error_e __append_location_to_wbxml_node(location_s * location, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node); + +static sync_agent_pb_error_e __append_anchor_to_wbxml_node(anchor_s * anchor, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node); + +static sync_agent_pb_error_e __append_devinf_contenttype_to_wbxml_node(devinf_content_type_s * devinf_content_type, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node, char *node); + +static sync_agent_pb_error_e __append_cred_to_wbxml_node(cred_s * cred, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node); + +static sync_agent_pb_error_e _oma_ds_binder_devinf_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_syncml_start_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_header_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_final_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_body_start_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_status_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_alert_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_results_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_put_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_get_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_sync_start_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_sync_end_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_add_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_replace_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_delete_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); +static sync_agent_pb_error_e _oma_ds_binder_map_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node); + +static protocol_version_e __get_oma_ds_protocol_version(char *verdtd); +static devinf_version_e __get_oma_ds_devInf_version(char *verdtd); +static devinf_devtyp_e __get_oma_ds_devInf_device_type(char *dev_type); +static devinf_content_type_s *__get_devinf_contenttype(WBXMLTreeNode * node); +static location_s *_get_location(WBXMLTreeNode * node); +static anchor_s *_get_anchor(WBXMLTreeNode * node); +static cred_s *__get_cred(WBXMLTreeNode * node); +static chal_s *_get_chal(WBXMLTreeNode * node); + +static sync_agent_pb_error_e _oma_ds_binder_devinf_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_header_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_results_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_put_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_get_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_alert_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_sync_end_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_sync_start_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_add_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_replace_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_delete_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_final_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); +static sync_agent_pb_error_e _oma_ds_binder_status_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content); + +/* + 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 sync_agent_pb_function_info_s 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 sync_agent_pb_error_e __append_location_to_wbxml_node(location_s * location, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(location == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "location is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + if (location->loc_uri != NULL) { + WBXMLTreeNode *LocURI = sync_agent_add_child_text_node(binder, + parent_node, ELEMENT_LOCURI, location->loc_uri, strlen(location->loc_uri)); + if (LocURI == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } else { + /* error case */ + } + + if (location->loc_name != NULL) { + WBXMLTreeNode *locName = sync_agent_add_child_text_node(binder, + parent_node, ELEMENT_LOCNAME, location->loc_name, strlen(location->loc_name)); + if (locName == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e __append_anchor_to_wbxml_node(anchor_s * anchor, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(anchor == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "anchor is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, parent_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *anchor_node = sync_agent_add_child_node(binder, meta_node, ELEMENT_ANCHOR); + if (anchor_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (anchor->last_anchor != NULL) { + WBXMLTreeNode *last_node = sync_agent_add_child_text_node(binder, + anchor_node, ELEMENT_LAST, anchor->last_anchor, strlen(anchor->last_anchor)); + if (last_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (anchor->next_anchor != NULL) { + WBXMLTreeNode *next_node = sync_agent_add_child_text_node(binder, + anchor_node, ELEMENT_NEXT, anchor->next_anchor, strlen(anchor->next_anchor)); + if (next_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e __append_devinf_contenttype_to_wbxml_node(devinf_content_type_s * devinf_content_type, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node, char *node) +{ + _INNER_FUNC_ENTER; + + retvm_if(devinf_content_type == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "devinf_content_type is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + WBXMLTreeNode *xnode = sync_agent_add_child_node(binder, parent_node, node); + if (xnode == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cttype_node = sync_agent_add_child_text_node(binder, + xnode, "CTType", devinf_content_type->ct_type, strlen(devinf_content_type->ct_type)); + if (cttype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *verct_node = sync_agent_add_child_text_node(binder, + xnode, "VerCT", devinf_content_type->verct, strlen(devinf_content_type->verct)); + if (verct_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + error: + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e __append_cred_to_wbxml_node(cred_s * cred, sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(cred == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "cred is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* check validity */ + WBXMLTreeNode *cred_node = sync_agent_add_child_node(binder, parent_node, ELEMENT_CRED); + if (cred_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, cred_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *type_node = NULL; + + switch (cred->type) { + case AUTH_TYPE_BASIC: + + if (cred->format == FORMAT_TYPE_BASE64) { + WBXMLTreeNode *format_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_FORMAT, ELEMENT_FORMAT_BASE64, strlen(ELEMENT_FORMAT_BASE64)); + if (format_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + type_node = sync_agent_add_child_text_node(binder, meta_node, ELEMENT_TYPE, ELEMENT_AUTH_BASIC, strlen(ELEMENT_AUTH_BASIC)); + if (type_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (cred->data != NULL) { + WBXMLTreeNode *data_node = sync_agent_add_child_text_node(binder, + cred_node, ELEMENT_DATA, cred->data, strlen(cred->data)); + if (data_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + break; + case AUTH_TYPE_MD5: + + if (cred->format == FORMAT_TYPE_BASE64) { + WBXMLTreeNode *format_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_FORMAT, ELEMENT_FORMAT_BASE64, strlen(ELEMENT_FORMAT_BASE64)); + if (format_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + type_node = sync_agent_add_child_text_node(binder, meta_node, ELEMENT_TYPE, ELEMENT_AUTH_MD5, strlen(ELEMENT_AUTH_MD5)); + if (type_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (cred->data != NULL) { + WBXMLTreeNode *data_node = sync_agent_add_child_text_node(binder, + cred_node, ELEMENT_DATA, cred->data, strlen(cred->data)); + if (data_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + break; + default: + break; + } + + error: + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_devinf_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + item_s *pItem = (item_s *) content; + devinf_s *pDevInf = pItem->private.devinf; + + if (pItem != NULL) { + WBXMLTreeNode *item_node = sync_agent_create_node(binder, ELEMENT_ITEM); + if (item_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, item_node, ELEMENT_SOURCE); + if (source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pItem->source, binder, source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) + goto error; + + WBXMLTreeNode *data_node = sync_agent_add_child_node(binder, item_node, ELEMENT_DATA); + if (data_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + /* devinf language setting */ + sync_agent_switch_protocol(binder, SYNC_AGENT_PB_PROTOCOL_SYNCML_DEVINF12); + WBXMLTree *devinf_tree = sync_agent_create_wbxml_tree(binder); + if (devinf_tree == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + sync_agent_add_wbxml_tree_to_wbxml_node(data_node, devinf_tree); + + /* create root node of devinf tree */ + WBXMLTreeNode *devinf_node = sync_agent_create_node(binder, ELEMENT_DEVINF); + if (devinf_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + sync_agent_set_wbxml_tree_root(devinf_tree, devinf_node); + + WBXMLTreeNode *verDTD_node = NULL; + switch (pDevInf->version) { + case DEVINF_VERSION_UNKNOWN: + verDTD_node = sync_agent_add_child_node(binder, devinf_node, ELEMENT_VERDTD); + break; + case DEVINF_VERSION_10: + verDTD_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_10, strlen(ELEMENT_VERDRD_10)); + break; + case DEVINF_VERSION_11: + verDTD_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_11, strlen(ELEMENT_VERDRD_11)); + break; + case DEVINF_VERSION_12: + verDTD_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_VERDTD, ELEMENT_VERDRD_12, strlen(ELEMENT_VERDRD_12)); + break; + } + + if (verDTD_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *man_node = sync_agent_add_child_text_node(binder, + devinf_node, ELEMENT_MAN, pDevInf->manufacturer, strlen(pDevInf->manufacturer)); + if (man_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *mod_node = sync_agent_add_child_text_node(binder, + devinf_node, ELEMENT_MOD, pDevInf->model, strlen(pDevInf->model)); + if (mod_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pDevInf->oem != NULL) { + WBXMLTreeNode *oem_node = sync_agent_add_child_text_node(binder, + devinf_node, ELEMENT_OEM, pDevInf->oem, strlen(pDevInf->oem)); + if (oem_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + WBXMLTreeNode *FwV_node = sync_agent_add_child_text_node(binder, + devinf_node, ELEMENT_FWV, pDevInf->firmware_version, strlen(pDevInf->firmware_version)); + if (FwV_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *SwV_node = sync_agent_add_child_text_node(binder, + devinf_node, ELEMENT_SWV, pDevInf->software_version, strlen(pDevInf->software_version)); + if (SwV_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *HwV_node = sync_agent_add_child_text_node(binder, + devinf_node, ELEMENT_HWV, pDevInf->hardware_version, strlen(pDevInf->hardware_version)); + if (HwV_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *devID_node = sync_agent_add_child_text_node(binder, + devinf_node, ELEMENT_DEVID, pDevInf->dev_id, strlen(pDevInf->dev_id)); + if (devID_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *devTyp_node = NULL; + switch (pDevInf->devtyp) { + case DEVINF_DEVTYPE_UNKNOWN: + devTyp_node = sync_agent_add_child_node(binder, devinf_node, ELEMENT_DEVTYP); + break; + case DEVINF_DEVTYPE_PAGER: + devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_PAGER, strlen(ELEMENT_PAGER)); + break; + case DEVINF_DEVTYPE_HANDHELD: + devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_HANDHELD, strlen(ELEMENT_HANDHELD)); + break; + case DEVINF_DEVTYPE_PDA: + devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_PDA, strlen(ELEMENT_PDA)); + break; + case DEVINF_DEVTYPE_PHONE: + devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_PHONE, strlen(ELEMENT_PHONE)); + break; + case DEVINF_DEVTYPE_SMARTPHONE: + devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_SMARTPHONE, strlen(ELEMENT_SMARTPHONE)); + break; + case DEVINF_DEVTYPE_SERVER: + devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_SERVER, strlen(ELEMENT_SERVER)); + break; + case DEVINF_DEVTYPE_WORKSTATION: + devTyp_node = sync_agent_add_child_text_node(binder, devinf_node, ELEMENT_DEVTYP, ELEMENT_WORKSTATION, strlen(ELEMENT_WORKSTATION)); + break; + } + + if (devTyp_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pDevInf->supports_utc) { + WBXMLTreeNode *supportUTC_node = sync_agent_add_child_node(binder, + devinf_node, ELEMENT_UTC); + if (supportUTC_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pDevInf->supports_large_objs) { + WBXMLTreeNode *supportLargeObjs_node = sync_agent_add_child_node(binder, + devinf_node, ELEMENT_SUPPORTLARGEOBJS); + if (supportLargeObjs_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pDevInf->supports_number_of_changes) { + WBXMLTreeNode *supportNumberOfChanges_node = sync_agent_add_child_node(binder, + devinf_node, ELEMENT_SUPPORTNUMBEROFCHANGES); + if (supportNumberOfChanges_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + GList *datastoreIter = NULL; + devinf_datastore_s *devInfDataStore = NULL; + for (datastoreIter = pDevInf->datastores; datastoreIter != NULL; datastoreIter = g_list_next(datastoreIter)) { + devInfDataStore = datastoreIter->data; + + WBXMLTreeNode *datastore_node = sync_agent_add_child_node(binder, + devinf_node, ELEMENT_DATASTORE); + if (datastore_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *sourceRef_node = sync_agent_add_child_text_node(binder, + datastore_node, ELEMENT_SOURCEREF, devInfDataStore->source_ref, strlen(devInfDataStore->source_ref)); + if (sourceRef_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (devInfDataStore->display_name != NULL) { + WBXMLTreeNode *displayname_node = sync_agent_add_child_text_node(binder, + datastore_node, ELEMENT_DISPLAYNAME, devInfDataStore->display_name, strlen(devInfDataStore->display_name)); + if (displayname_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (devInfDataStore->max_guid_size) { + char *str_maxguidsize = g_strdup_printf("%u", devInfDataStore->max_guid_size); + if (str_maxguidsize == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *maxguidsize_node = sync_agent_add_child_text_node(binder, + datastore_node, ELEMENT_MAXGUIDSIZE, str_maxguidsize, strlen(str_maxguidsize)); + + if (str_maxguidsize != NULL) + free(str_maxguidsize); + + if (maxguidsize_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + __append_devinf_contenttype_to_wbxml_node(devInfDataStore->rx_pref, binder, datastore_node, ELEMENT_RX_PREF); + if (err != SYNC_AGENT_PB_RETURN_OK) + goto error; + + GList *rxIter = NULL; + devinf_content_type_s *devInfContentType = NULL; + for (rxIter = devInfDataStore->rx; rxIter != NULL; rxIter = g_list_next(rxIter)) { + devInfContentType = rxIter->data; + __append_devinf_contenttype_to_wbxml_node(devInfContentType, binder, datastore_node, ELEMENT_RX); + if (err != SYNC_AGENT_PB_RETURN_OK) + goto error; + } + + __append_devinf_contenttype_to_wbxml_node(devInfDataStore->tx_pref, binder, datastore_node, ELEMENT_TX_PREF); + if (err != SYNC_AGENT_PB_RETURN_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, binder, datastore_node, ELEMENT_TX); + if (err != SYNC_AGENT_PB_RETURN_OK) + goto error; + + } + + GList *ctcapIter = NULL; + devinf_ct_cap_s *devInfCTCap = NULL; + for (ctcapIter = devInfDataStore->ct_caps; ctcapIter != NULL; ctcapIter = g_list_next(ctcapIter)) { + devInfCTCap = ctcapIter->data; + + WBXMLTreeNode *ctcap_node = sync_agent_add_child_node(binder, + datastore_node, ELEMENT_CTCAP); + if (ctcap_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cttype_node = sync_agent_add_child_text_node(binder, + ctcap_node, ELEMENT_CTTYPE, devInfCTCap->ct->ct_type, strlen(devInfCTCap->ct->ct_type)); + if (cttype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *verct_node = sync_agent_add_child_text_node(binder, + ctcap_node, ELEMENT_VERCT, devInfCTCap->ct->verct, strlen(devInfCTCap->ct->verct)); + if (verct_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + /*TODO FieldLevel */ + + GList *propertyIter = NULL; + devinf_property_s *devInfProperty = NULL; + for (propertyIter = devInfCTCap->properties; propertyIter != NULL; propertyIter = g_list_next(propertyIter)) { + devInfProperty = propertyIter->data; + + WBXMLTreeNode *property_node = sync_agent_add_child_node(binder, + ctcap_node, ELEMENT_PROPERTY); + if (property_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *propname_node = sync_agent_add_child_text_node(binder, + property_node, ELEMENT_PROPNAME, devInfProperty->prop_name, strlen(devInfProperty->prop_name)); + if (propname_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (devInfProperty->data_type != NULL) { + WBXMLTreeNode *datatype_node = sync_agent_add_child_text_node(binder, + property_node, ELEMENT_DATATYPE, devInfProperty->data_type, strlen(devInfProperty->data_type)); + if (datatype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (devInfProperty->max_occur) { + char *str_maxoccur = g_strdup_printf("%u", devInfProperty->max_occur); + if (str_maxoccur == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *maxoccur_node = sync_agent_add_child_text_node(binder, + property_node, ELEMENT_MAXOCCUR, str_maxoccur, strlen(str_maxoccur)); + + if (str_maxoccur != NULL) + free(str_maxoccur); + + if (maxoccur_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (devInfProperty->max_size) { + char *str_maxsize = g_strdup_printf("%u", devInfProperty->max_size); + if (str_maxsize == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *maxsize_node = sync_agent_add_child_text_node(binder, + property_node, ELEMENT_MAXSIZE, str_maxsize, strlen(str_maxsize)); + + if (str_maxsize != NULL) + free(str_maxsize); + + if (maxsize_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (devInfProperty->no_truncate) { + WBXMLTreeNode *notruncate_node = sync_agent_add_child_node(binder, + property_node, ELEMENT_NOTRUNCATE); + if (notruncate_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + GList *valenum = NULL; + char *val = NULL; + for (valenum = devInfProperty->val_enums; valenum != NULL; valenum = g_list_next(valenum)) { + val = valenum->data; + WBXMLTreeNode *valenum_node = sync_agent_add_child_text_node(binder, + property_node, ELEMENT_VALENUM, val, strlen(val)); + if (valenum_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (devInfProperty->display_name != NULL) { + WBXMLTreeNode *displayname_node = sync_agent_add_child_text_node(binder, + property_node, ELEMENT_DISPLAYNAME, devInfProperty->display_name, strlen(devInfProperty->display_name)); + if (displayname_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + GList *propparamIter = NULL; + devinf_prop_param_s *devInfPropParam = NULL; + for (propparamIter = devInfProperty->prop_params; propparamIter != NULL; propparamIter = g_list_next(propparamIter)) { + devInfPropParam = propparamIter->data; + + WBXMLTreeNode *propparam_node = sync_agent_add_child_node(binder, + property_node, ELEMENT_PROPPARAM); + if (propparam_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *paramname_node = sync_agent_add_child_text_node(binder, + propparam_node, ELEMENT_PARAMNAME, devInfPropParam->param_name, strlen(devInfPropParam->param_name)); + if (paramname_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (devInfPropParam->data_type != NULL) { + WBXMLTreeNode *datatype_node = sync_agent_add_child_text_node(binder, + propparam_node, ELEMENT_DATATYPE, devInfPropParam->data_type, strlen(devInfPropParam->data_type)); + if (datatype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + valenum = NULL; + val = NULL; + for (valenum = devInfPropParam->val_enums; valenum != NULL; valenum = g_list_next(valenum)) { + val = valenum->data; + WBXMLTreeNode *valenum_node = sync_agent_add_child_text_node(binder, + propparam_node, ELEMENT_VALENUM, val, strlen(val)); + if (valenum_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (devInfPropParam->display_name != NULL) { + WBXMLTreeNode *displayname_node = sync_agent_add_child_text_node(binder, + propparam_node, ELEMENT_DISPLAYNAME, devInfPropParam->display_name, strlen(devInfPropParam->display_name)); + if (displayname_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + } + } + + /* DSMem */ + WBXMLTreeNode *dsmem_node = sync_agent_add_child_node(binder, + datastore_node, ELEMENT_DSMEM); + if (dsmem_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (devInfDataStore->shared_mem) { + WBXMLTreeNode *sharedmem_node = sync_agent_add_child_node(binder, + dsmem_node, ELEMENT_SHAREDMEM); + if (sharedmem_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (devInfDataStore->max_mem) { + char *str_maxmem = g_strdup_printf("%u", devInfDataStore->max_mem); + WBXMLTreeNode *maxmem_node = sync_agent_add_child_text_node(binder, + dsmem_node, ELEMENT_MAXMEM, str_maxmem, strlen(str_maxmem)); + + if (str_maxmem != NULL) + free(str_maxmem); + + if (maxmem_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (devInfDataStore->max_id) { + char *str_maxid = g_strdup_printf("%u", devInfDataStore->max_id); + WBXMLTreeNode *maxid_node = sync_agent_add_child_text_node(binder, + dsmem_node, ELEMENT_MAXID, str_maxid, strlen(str_maxid)); + + if (str_maxid != NULL) + free(str_maxid); + + if (maxid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + /* SupportHierarchicalSync */ + if (devInfDataStore->supports_hierarchical_sync) { + WBXMLTreeNode *supportshierarchicalsync_node = sync_agent_add_child_node(binder, + datastore_node, ELEMENT_SUPPORTHIERARCHICALSYNC); + if (supportshierarchicalsync_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + WBXMLTreeNode *synccap_node = sync_agent_add_child_node(binder, + datastore_node, ELEMENT_SYNCCAP); + if (synccap_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_TWO_WAY)) { + WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder, + synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_1, strlen(ELEMENT_SYNCTYPE_1)); + if (synctype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_SLOW_SYNC)) { + WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder, + synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_2, strlen(ELEMENT_SYNCTYPE_2)); + if (synctype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT)) { + WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder, + synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_3, strlen(ELEMENT_SYNCTYPE_3)); + if (synctype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT)) { + WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder, + synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_4, strlen(ELEMENT_SYNCTYPE_4)); + if (synctype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER)) { + WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder, + synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_5, strlen(ELEMENT_SYNCTYPE_5)); + if (synctype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_SERVER)) { + WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder, + synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_6, strlen(ELEMENT_SYNCTYPE_6)); + if (synctype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + if (get_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC)) { + WBXMLTreeNode *synctype_node = sync_agent_add_child_text_node(binder, + synccap_node, ELEMENT_SYNCTYPE, ELEMENT_SYNCTYPE_7, strlen(ELEMENT_SYNCTYPE_7)); + if (synctype_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + /*TODO filter-rx, filterCap */ + } + sync_agent_undo_switch_protocol(binder); + *wbxml_dom_node = item_node; + } + + error: + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_syncml_start_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + WBXMLTreeNode *syncml_node = sync_agent_create_node(binder, ELEMENT_SYNCML); + if (syncml_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + *wbxml_dom_node = syncml_node; + + error: + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_header_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + sync_hdr_s *pSyncHdr = (sync_hdr_s *) content; + + /* add SyncHdr, VerDTD, VerProto node */ + WBXMLTreeNode *synchdr_node = sync_agent_create_node(binder, ELEMENT_SYNCHDR); + if (synchdr_node == NULL) { + err = SYNC_AGENT_PB_RETURN_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 = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + WBXMLTreeNode *verdtd_node = sync_agent_add_child_text_node(binder, + synchdr_node, verDTD, verDTD_data, strlen(verDTD_data)); + if (verdtd_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *verProto_node = sync_agent_add_child_text_node(binder, + synchdr_node, verProto, verProto_data, strlen(verProto_data)); + if (verProto_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + /* session ID */ + WBXMLTreeNode *sessionID_node = NULL; + if (pSyncHdr->session_id != NULL) + sessionID_node = sync_agent_add_child_text_node(binder, synchdr_node, ELEMENT_SESSIONID, pSyncHdr->session_id, strlen(pSyncHdr->session_id)); + else + sessionID_node = sync_agent_add_child_node(binder, synchdr_node, ELEMENT_SESSIONID); + + if (sessionID_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + /* msgID */ + char *msgID_data = g_strdup_printf("%u", pSyncHdr->message_id); + if (msgID_data == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *msgID_node = sync_agent_add_child_text_node(binder, + synchdr_node, ELEMENT_MSGID, msgID_data, strlen(msgID_data)); + + if (msgID_data != NULL) + free(msgID_data); + + if (msgID_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *target_node = sync_agent_add_child_node(binder, + synchdr_node, ELEMENT_TARGET); + if (target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pSyncHdr->target, binder, target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + + WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, + synchdr_node, ELEMENT_SOURCE); + if (source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pSyncHdr->source, binder, source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + + if (pSyncHdr->response_uri != NULL) { + WBXMLTreeNode *respuri_node = sync_agent_add_child_text_node(binder, + synchdr_node, ELEMENT_RESPURI, pSyncHdr->response_uri, strlen(pSyncHdr->response_uri)); + if (respuri_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pSyncHdr->no_response) { + WBXMLTreeNode *noResponse_node = sync_agent_add_child_node(binder, + synchdr_node, ELEMENT_NORESP); + if (noResponse_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pSyncHdr->cred != NULL) { + err = __append_cred_to_wbxml_node(pSyncHdr->cred, binder, synchdr_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + char *meta = ELEMENT_META; + if (pSyncHdr->max_msg_size != 0 || pSyncHdr->max_obj_size != 0) { + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, + synchdr_node, meta); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + unsigned int maxmsgsize = pSyncHdr->max_msg_size; + unsigned int maxobjsize = pSyncHdr->max_obj_size; + + if (maxmsgsize != 0) { + char *str_maxmsgsize = g_strdup_printf("%u", maxmsgsize); + if (str_maxmsgsize == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *maxmsgsize_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_MAXMSGSIZE, str_maxmsgsize, strlen(str_maxmsgsize)); + if (str_maxmsgsize != NULL) + free(str_maxmsgsize); + + if (maxmsgsize_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (maxobjsize != 0) { + char *str_maxobjsize = g_strdup_printf("%u", maxobjsize); + if (str_maxobjsize == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *maxobjsize_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_MAXOBJSIZE, str_maxobjsize, strlen(str_maxobjsize)); + if (str_maxobjsize != NULL) + free(str_maxobjsize); + + if (maxobjsize_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + + *wbxml_dom_node = synchdr_node; + synchdr_node = NULL; + + error: + + if (synchdr_node != NULL) + sync_agent_destroy_wbxml_node(synchdr_node); + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_final_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + WBXMLTreeNode *final_node = sync_agent_create_node(binder, "Final"); + if (final_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + *wbxml_dom_node = final_node; + + error: + _INNER_FUNC_EXIT; + return err; + +} + +static sync_agent_pb_error_e _oma_ds_binder_body_start_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + WBXMLTreeNode *syncbody_node = sync_agent_create_node(binder, ELEMENT_SYNCBODY); + if (syncbody_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + *wbxml_dom_node = syncbody_node; + + error: + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_status_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + status_s *pStatus = (status_s *) content; + + command_type_e type = pStatus->type; + + char *str_cmdID = NULL; + char *str_msgRef = NULL; + char *str_cmdRef = NULL; + + WBXMLTreeNode *status_node = sync_agent_create_node(binder, ELEMENT_STATUS); + if (status_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + unsigned int cmdID = pStatus->cmd_id; + str_cmdID = g_strdup_printf("%u", cmdID); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + status_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + unsigned int msgRef = pStatus->msg_ref; + str_msgRef = g_strdup_printf("%u", msgRef); + if (str_msgRef == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *msgref_node = sync_agent_add_child_text_node(binder, + status_node, ELEMENT_MSGREF, str_msgRef, strlen(str_msgRef)); + if (msgref_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + unsigned int cmdRef = pStatus->cmd_ref; + str_cmdRef = g_strdup_printf("%u", cmdRef); + if (str_cmdRef == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdref_node = sync_agent_add_child_text_node(binder, + status_node, ELEMENT_CMDREF, str_cmdRef, strlen(str_cmdRef)); + if (cmdref_node == NULL) { + 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 = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + WBXMLTreeNode *command_node = sync_agent_add_child_text_node(binder, + status_node, ELEMENT_CMD, str_command, strlen(str_command)); + if (command_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pStatus->target_ref != NULL) { + WBXMLTreeNode *targetref_node = sync_agent_add_child_text_node(binder, + status_node, ELEMENT_TARGETREF, pStatus->target_ref->loc_uri, strlen(pStatus->target_ref->loc_uri)); + if (targetref_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pStatus->source_ref != NULL) { + WBXMLTreeNode *sourceref_node = sync_agent_add_child_text_node(binder, + status_node, ELEMENT_SOURCEREF, pStatus->source_ref->loc_uri, strlen(pStatus->source_ref->loc_uri)); + if (sourceref_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pStatus->cred != NULL) { + err = __append_cred_to_wbxml_node(pStatus->cred, binder, status_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (pStatus->chal != NULL) { + /*TODO chal */ + } + + WBXMLTreeNode *data_node = sync_agent_add_child_text_node(binder, + status_node, ELEMENT_DATA, pStatus->data, strlen(pStatus->data)); + if (data_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (type == COMMAND_TYPE_ALERT) { + if (pStatus->item != NULL) { + WBXMLTreeNode *item_node = sync_agent_add_child_node(binder, + status_node, ELEMENT_ITEM); + if (item_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *item_data_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_DATA); + if (item_data_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *item_data_Anchor_node = sync_agent_add_child_node(binder, + item_data_node, ELEMENT_ANCHOR); + if (item_data_Anchor_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pStatus->item->anchor != NULL) { + WBXMLTreeNode *item_data_Anchor_Next_node = sync_agent_add_child_text_node(binder, + item_data_Anchor_node, ELEMENT_NEXT, pStatus->item->anchor->next_anchor, + strlen(pStatus->item->anchor->next_anchor)); + + if (item_data_Anchor_Next_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + } + + *wbxml_dom_node = status_node; + status_node = NULL; + + error: + + if (status_node != NULL) + sync_agent_destroy_wbxml_node(status_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + if (str_cmdRef != NULL) + free(str_cmdRef); + + if (str_msgRef != NULL) + free(str_msgRef); + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_alert_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + char *str_cmdID = NULL; + char *str_alert_type = NULL; + + WBXMLTreeNode *alert_node = NULL; + + command_s *pCommand = (command_s *) content; + + command_alert_private_s *pAlert = (command_alert_private_s *) (&(pCommand->private)); + if (pAlert == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + if (pAlert->type == ALERT_UNKNOWN) { + /* error case */ + err = SYNC_AGENT_PB_RETURN_INVALID_INPUT_PARAMETER; + goto error; + } + + alert_node = sync_agent_create_node(binder, ELEMENT_ALERT); + if (alert_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + alert_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->no_resp) { + WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder, + alert_node, ELEMENT_NORESP); + if (noResp_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pCommand->cred != NULL) { + err = __append_cred_to_wbxml_node(pCommand->cred, binder, alert_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + str_alert_type = g_strdup_printf("%u", pAlert->type); + if (str_alert_type == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *data_node = sync_agent_add_child_text_node(binder, + alert_node, ELEMENT_DATA, str_alert_type, strlen(str_alert_type)); + if (data_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + /* item */ + if (pCommand->source != NULL && pCommand->target != NULL) { + WBXMLTreeNode *item_node = sync_agent_add_child_node(binder, + alert_node, ELEMENT_ITEM); + if (item_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *target_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_TARGET); + if (target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pCommand->target, binder, target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + + WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_SOURCE); + if (source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pCommand->source, binder, source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + + if (pAlert->anchor != NULL) { + err = __append_anchor_to_wbxml_node(pAlert->anchor, binder, item_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + } + + *wbxml_dom_node = alert_node; + alert_node = NULL; + + error: + + if (alert_node != NULL) + sync_agent_destroy_wbxml_node(alert_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + if (str_alert_type != NULL) + free(str_alert_type); + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_results_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + char *str_cmdID = NULL; + char *str_cmdRef = NULL; + char *str_msgRef = NULL; + WBXMLTreeNode *results_node = NULL; + + command_s *pCommand = (command_s *) content; + command_results_private_s *pResults = (command_results_private_s *) (&(pCommand->private)); + if (pResults == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + if (pResults->item == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + char *content_type = (pResults->item)->content_type; + if (content_type == NULL) { + /* error case */ + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + results_node = sync_agent_create_node(binder, ELEMENT_RESULTS); + if (results_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID != NULL) { + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + results_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pResults->msg_ref) { + str_msgRef = g_strdup_printf("%u", pResults->msg_ref); + if (str_msgRef == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *msgref_node = sync_agent_add_child_text_node(binder, + results_node, ELEMENT_MSGREF, str_msgRef, strlen(str_msgRef)); + if (msgref_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + str_cmdRef = g_strdup_printf("%u", pResults->cmd_ref); + if (str_cmdRef == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *msgref_node = sync_agent_add_child_text_node(binder, + results_node, ELEMENT_CMDREF, str_cmdRef, strlen(str_cmdRef)); + if (msgref_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (content_type != NULL) { + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, + results_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_TYPE, content_type, strlen(content_type)); + if (type_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pResults->target_ref != NULL) { + WBXMLTreeNode *targetref_node = sync_agent_add_child_text_node(binder, + results_node, ELEMENT_TARGETREF, pResults->target_ref->loc_uri, strlen(pResults->target_ref->loc_uri)); + if (targetref_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + *wbxml_dom_node = results_node; + results_node = NULL; + + error: + + if (results_node != NULL) + sync_agent_destroy_wbxml_node(results_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + if (str_cmdRef != NULL) + free(str_cmdRef); + + if (str_msgRef != NULL) + free(str_msgRef); + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_put_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + char *str_cmdID = NULL; + WBXMLTreeNode *put_node = NULL; + + command_s *pCommand = (command_s *) content; + command_access_private_s *pAccess = (command_access_private_s *) (&(pCommand->private)); + if (pAccess == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + char *content_type = (pAccess->item)->content_type; + if (content_type == NULL) { + /* error case */ + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + put_node = sync_agent_create_node(binder, ELEMENT_PUT); + if (put_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + put_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->no_resp) { + WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder, + put_node, ELEMENT_NORESP); + if (noResp_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pCommand->cred != NULL) { + err = __append_cred_to_wbxml_node(pCommand->cred, binder, put_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (content_type != NULL) { + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, + put_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_TYPE, content_type, strlen(content_type)); + if (type_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + *wbxml_dom_node = put_node; + put_node = NULL; + + error: + + if (put_node != NULL) + sync_agent_destroy_wbxml_node(put_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_get_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + char *str_cmdID = NULL; + WBXMLTreeNode *get_node = NULL; + + command_s *pCommand = (command_s *) content; + command_access_private_s *pAccess = (command_access_private_s *) (&(pCommand->private)); + if (pAccess == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + if (pAccess->item == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + char *content_type = (pAccess->item)->content_type; + if (content_type == NULL) { + /* error case */ + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + get_node = sync_agent_create_node(binder, ELEMENT_GET); + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + get_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->no_resp) { + WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder, + get_node, ELEMENT_NORESP); + if (noResp_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pCommand->cred != NULL) { + err = __append_cred_to_wbxml_node(pCommand->cred, binder, get_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (content_type != NULL) { + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, + get_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_TYPE, content_type, strlen(content_type)); + if (type_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pAccess->item != NULL) { + WBXMLTreeNode *item_node = sync_agent_add_child_node(binder, + get_node, ELEMENT_ITEM); + if (item_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *target_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_TARGET); + if (target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pAccess->item->target, binder, target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + *wbxml_dom_node = get_node; + get_node = NULL; + + error: + + if (get_node != NULL) + sync_agent_destroy_wbxml_node(get_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_sync_start_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + command_s *pCommand = (command_s *) content; + + char *str_cmdID = NULL; + char *numChanged_str = NULL; + char *str_freemem = NULL; + char *str_freeid = NULL; + + WBXMLTreeNode *sync_node = sync_agent_create_node(binder, ELEMENT_SYNC); + if (sync_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + sync_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->no_resp) { + WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder, + sync_node, ELEMENT_NORESP); + if (noResp_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pCommand->cred != NULL) { + err = __append_cred_to_wbxml_node(pCommand->cred, binder, sync_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (pCommand->source != NULL && pCommand->target != NULL) { + WBXMLTreeNode *target_node = sync_agent_add_child_node(binder, + sync_node, ELEMENT_TARGET); + if (target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pCommand->target, binder, target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + + WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, + sync_node, ELEMENT_SOURCE); + if (source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pCommand->source, binder, source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + + } + + /* Mem */ + if (pCommand->private.sync.mem != NULL) { + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, sync_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *mem_node = sync_agent_add_child_node(binder, meta_node, ELEMENT_MEM); + if (mem_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->private.sync.mem->sharedmem) { + WBXMLTreeNode *sharedmem_node = sync_agent_add_child_node(binder, mem_node, ELEMENT_SHAREDMEM); + if (sharedmem_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pCommand->private.sync.mem->free_mem) { + str_freemem = g_strdup_printf("%u", pCommand->private.sync.mem->free_mem); + WBXMLTreeNode *freemem_node = sync_agent_add_child_text_node(binder, + mem_node, ELEMENT_FREEMEM, str_freemem, strlen(str_freemem)); + if (freemem_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pCommand->private.sync.mem->free_id) { + str_freeid = g_strdup_printf("%u", pCommand->private.sync.mem->free_id); + WBXMLTreeNode *freeid_node = sync_agent_add_child_text_node(binder, + mem_node, ELEMENT_FREEID, str_freeid, strlen(str_freeid)); + if (freeid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + + if (pCommand->private.sync.has_num_changed) { + numChanged_str = g_strdup_printf("%u", pCommand->private.sync.num_changed); + if (numChanged_str == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *numberOfChanges_node = sync_agent_add_child_text_node(binder, + sync_node, ELEMENT_NUMBEROFCHANGES, numChanged_str, strlen(numChanged_str)); + if (numberOfChanges_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + *wbxml_dom_node = sync_node; + sync_node = NULL; + + error: + + if (sync_node != NULL) + sync_agent_destroy_wbxml_node(sync_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + if (numChanged_str != NULL) + free(numChanged_str); + + if (str_freemem != NULL) + free(str_freemem); + + _INNER_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_sync_end_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + _EXTERN_FUNC_EXIT; + + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_add_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + char *str_cmdID = NULL; + char *str_size = NULL; + WBXMLTreeNode *add_node = NULL; + + command_s *pCommand = (command_s *) content; + + command_change_private_s *pChange = (command_change_private_s *) (&(pCommand->private)); + if (pChange == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + add_node = sync_agent_create_node(binder, ELEMENT_ADD); + if (add_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + add_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->no_resp) { + WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder, + add_node, ELEMENT_NORESP); + if (noResp_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pCommand->cred != NULL) { + err = __append_cred_to_wbxml_node(pCommand->cred, binder, add_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + GList *Iter = NULL; + item_s *item = NULL; + for (Iter = pChange->items; Iter != NULL; Iter = g_list_next(Iter)) { + item = (Iter->data); + + WBXMLTreeNode *item_node = sync_agent_add_child_node(binder, + add_node, ELEMENT_ITEM); + if (item_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (item->source != NULL) { + WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_SOURCE); + if (source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(item->source, binder, source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (item->target != NULL) { + WBXMLTreeNode *target_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_TARGET); + if (target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(item->target, binder, target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (item->content_type != NULL) { + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_TYPE, item->content_type, strlen(item->content_type)); + if (type_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (item->more_data) { + if (item->size) { + str_size = g_strdup_printf("%u", item->size); + if (str_size == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *size_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_SIZE, str_size, strlen(str_size)); + if (size_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + } + + if (item->data_type == ITEM_DATA) { + if (item->private.data != NULL) { + WBXMLTreeNode *data_node = sync_agent_add_child_cdata_node(binder, + item_node, ELEMENT_DATA, item->private.data, strlen(item->private.data)); + if (data_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + + if (item->more_data) { + WBXMLTreeNode *moredata_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_MOREDATA); + if (moredata_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + + *wbxml_dom_node = add_node; + add_node = NULL; + + error: + + if (add_node != NULL) + sync_agent_destroy_wbxml_node(add_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + if (str_size != NULL) + free(str_size); + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_replace_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + char *str_cmdID = NULL; + char *str_size = NULL; + WBXMLTreeNode *replace_node = NULL; + + command_s *pCommand = (command_s *) content; + + command_change_private_s *pChange = (command_change_private_s *) (&(pCommand->private)); + + if (pChange == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + replace_node = sync_agent_create_node(binder, ELEMENT_REPLACE); + if (replace_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + replace_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->no_resp) { + WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder, + replace_node, ELEMENT_NORESP); + if (noResp_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + if (pCommand->cred != NULL) { + err = __append_cred_to_wbxml_node(pCommand->cred, binder, replace_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + GList *Iter = NULL; + item_s *item = NULL; + for (Iter = pChange->items; Iter != NULL; Iter = g_list_next(Iter)) { + item = (Iter->data); + + WBXMLTreeNode *item_node = sync_agent_add_child_node(binder, + replace_node, ELEMENT_ITEM); + if (item_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (item->source != NULL) { + WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_SOURCE); + if (source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + err = __append_location_to_wbxml_node(item->source, binder, source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (item->target != NULL) { + WBXMLTreeNode *target_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_TARGET); + if (target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + err = __append_location_to_wbxml_node(item->target, binder, target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (item->content_type != NULL) { + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_TYPE, item->content_type, strlen(item->content_type)); + if (type_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (item->more_data) { + if (item->size) { + str_size = g_strdup_printf("%u", item->size); + if (str_size == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *size_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_SIZE, str_size, strlen(str_size)); + if (size_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + } + + if (item->data_type == ITEM_DATA) { + if (item->private.data != NULL) { + WBXMLTreeNode *data_node = sync_agent_add_child_cdata_node(binder, + item_node, ELEMENT_DATA, item->private.data, strlen(item->private.data)); + if (data_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + + if (item->more_data) { + WBXMLTreeNode *moredata_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_MOREDATA); + if (moredata_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + } + + *wbxml_dom_node = replace_node; + replace_node = NULL; + + error: + + if (replace_node != NULL) + sync_agent_destroy_wbxml_node(replace_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + if (str_size != NULL) + free(str_size); + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_delete_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + char *str_cmdID = NULL; + char *str_size = NULL; + WBXMLTreeNode *delete_node = NULL; + + command_s *pCommand = (command_s *) content; + + command_change_private_s *pChange = (command_change_private_s *) (&(pCommand->private)); + if (pChange == NULL) { + err = SYNC_AGENT_PB_RETURN_NOT_DEFINED; + goto error; + } + + delete_node = sync_agent_create_node(binder, ELEMENT_DELETE); + if (delete_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + delete_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->no_resp) { + WBXMLTreeNode *noResp_node = sync_agent_add_child_node(binder, + delete_node, ELEMENT_NORESP); + if (noResp_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + + /*TODO Archive */ + /*TODO sftDel */ + + if (pCommand->cred != NULL) { + err = __append_cred_to_wbxml_node(pCommand->cred, binder, delete_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + GList *Iter = NULL; + item_s *item = NULL; + for (Iter = pCommand->private.change.items; Iter != NULL; Iter = g_list_next(Iter)) { + item = (Iter->data); + + WBXMLTreeNode *item_node = sync_agent_add_child_node(binder, + delete_node, ELEMENT_ITEM); + if (item_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (item->source != NULL) { + WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_SOURCE); + if (source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(item->source, binder, source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (item->target != NULL) { + WBXMLTreeNode *target_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_TARGET); + if (target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(item->target, binder, target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (item->content_type != NULL) { + WBXMLTreeNode *meta_node = sync_agent_add_child_node(binder, + item_node, ELEMENT_META); + if (meta_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *type_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_TYPE, item->content_type, strlen(item->content_type)); + if (type_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (item->size) { + str_size = g_strdup_printf("%u", item->size); + if (str_size == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *size_node = sync_agent_add_child_text_node(binder, + meta_node, ELEMENT_SIZE, str_size, strlen(str_size)); + if (size_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + } + } + } + + *wbxml_dom_node = delete_node; + delete_node = NULL; + + error: + + if (delete_node != NULL) + sync_agent_destroy_wbxml_node(delete_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + if (str_size != NULL) + free(str_size); + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_map_command_converter_function(sync_agent_pb_protocol_binder_info_s * binder, Content_Ptr content, WBXMLTreeNode ** wbxml_dom_node) +{ + _INNER_FUNC_ENTER; + + retvm_if(content == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "content is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + char *str_cmdID = NULL; + + command_s *pCommand = (command_s *) content; + + WBXMLTreeNode *map_node = sync_agent_create_node(binder, ELEMENT_MAP); + if (map_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + str_cmdID = g_strdup_printf("%u", pCommand->cmd_id); + if (str_cmdID == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + WBXMLTreeNode *cmdid_node = sync_agent_add_child_text_node(binder, + map_node, ELEMENT_CMDID, str_cmdID, strlen(str_cmdID)); + if (cmdid_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (pCommand->source != NULL && pCommand->target != NULL) { + WBXMLTreeNode *target_node = sync_agent_add_child_node(binder, + map_node, ELEMENT_TARGET); + if (target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pCommand->target, binder, target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + + WBXMLTreeNode *source_node = sync_agent_add_child_node(binder, + map_node, ELEMENT_SOURCE); + if (source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(pCommand->source, binder, source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + if (pCommand->cred != NULL) { + err = __append_cred_to_wbxml_node(pCommand->cred, binder, map_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + + GList *iter = NULL; + item_s *item = NULL; + for (iter = pCommand->private.map.items; iter != NULL; iter = g_list_next(iter)) { + item = iter->data; + WBXMLTreeNode *mapItem_node = sync_agent_add_child_node(binder, + map_node, ELEMENT_MAPITEM); + if (mapItem_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + if (item->source != NULL && item->target != NULL) { + WBXMLTreeNode *item_target_node = sync_agent_add_child_node(binder, + mapItem_node, ELEMENT_TARGET); + if (item_target_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(item->target, binder, item_target_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + + WBXMLTreeNode *item_source_node = sync_agent_add_child_node(binder, + mapItem_node, ELEMENT_SOURCE); + if (item_source_node == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto error; + } + + err = __append_location_to_wbxml_node(item->source, binder, item_source_node); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto error; + } + } + } + + *wbxml_dom_node = map_node; + map_node = NULL; + + error: + + if (map_node != NULL) + sync_agent_destroy_wbxml_node(map_node); + + if (str_cmdID != NULL) + free(str_cmdID); + + _EXTERN_FUNC_EXIT; + return err; +} + +static protocol_version_e __get_oma_ds_protocol_version(char *verdtd) +{ + _INNER_FUNC_ENTER; + + retvm_if(verdtd == NULL, VERSION_UNKNOWN, "verdtd is NULL"); + + protocol_version_e 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; + } + + _INNER_FUNC_EXIT; + return protocol_version; +} + +static devinf_version_e __get_oma_ds_devInf_version(char *verdtd) +{ + _INNER_FUNC_ENTER; + + retvm_if(verdtd == NULL, DEVINF_VERSION_UNKNOWN, "verdtd is NULL"); + + devinf_version_e 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; + } + + _INNER_FUNC_EXIT; + return devInf_version; +} + +static devinf_devtyp_e __get_oma_ds_devInf_device_type(char *dev_type) +{ + _INNER_FUNC_ENTER; + + retvm_if(dev_type == NULL, DEVINF_DEVTYPE_UNKNOWN, "dev_type is NULL"); + + devinf_devtyp_e device_type = DEVINF_DEVTYPE_UNKNOWN; + if (strcmp(dev_type, ELEMENT_PAGER) == 0) { + device_type = DEVINF_DEVTYPE_PAGER; + } else if (strcmp(dev_type, ELEMENT_HANDHELD) == 0) { + device_type = DEVINF_DEVTYPE_HANDHELD; + } else if (strcmp(dev_type, ELEMENT_PDA) == 0) { + device_type = DEVINF_DEVTYPE_PDA; + } else if (strcmp(dev_type, ELEMENT_PHONE) == 0) { + device_type = DEVINF_DEVTYPE_PHONE; + } else if (strcmp(dev_type, ELEMENT_SMARTPHONE) == 0) { + device_type = DEVINF_DEVTYPE_SMARTPHONE; + } else if (strcmp(dev_type, ELEMENT_SERVER) == 0) { + device_type = DEVINF_DEVTYPE_SERVER; + } else if (strcmp(dev_type, ELEMENT_WORKSTATION) == 0) { + device_type = DEVINF_DEVTYPE_WORKSTATION; + } + + _INNER_FUNC_EXIT; + return device_type; +} + +static devinf_content_type_s *__get_devinf_contenttype(WBXMLTreeNode * node) +{ + _INNER_FUNC_ENTER; + + retvm_if(node == NULL, NULL, "node is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + devinf_content_type_s *devinf_content_type = NULL; + + devinf_content_type = (devinf_content_type_s *) calloc(1, sizeof(devinf_content_type_s)); + if (devinf_content_type == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("devinf_content_type 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; + if (child != 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 = sync_agent_get_text_from_node(child, &ctType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + if (ctType != NULL) + devinf_content_type->ct_type = 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 = sync_agent_get_text_from_node(child, &verCT); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + if (verCT != NULL) + devinf_content_type->verct = strdup(verCT); + } else { + /* error */ + goto return_part; + } + } + } + + _INNER_FUNC_EXIT; + return devinf_content_type; + + return_part: + + /* for prevent */ + if (devinf_content_type != NULL) + free(devinf_content_type); + + _INNER_FUNC_EXIT; + return NULL; + +} + +static location_s *_get_location(WBXMLTreeNode * node) +{ + _INNER_FUNC_ENTER; + + retvm_if(node == NULL, NULL, "node is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + location_s *location = 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; + if (child != NULL) { + first_child_name = (const char *)wbxml_tag_get_xml_name(child->name); + _DEBUG_TRACE("child_name = %s", first_child_name); + if (strcmp(first_child_name, ELEMENT_LOCURI) == 0) { + err = sync_agent_get_text_from_node(child, &locURI); + if (err != SYNC_AGENT_PB_RETURN_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); + _DEBUG_TRACE("child_name = %s", second_child_name); + if (strcmp(second_child_name, ELEMENT_LOCNAME) == 0) { + err = sync_agent_get_text_from_node(child, &locName); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + } else { + /* error */ + goto return_part; + } + } + + sa_error_type_e error = create_location(locURI, locName, &location); + if (error != SA_INTERNAL_OK) { + _DEBUG_ERROR("create_location() failed !, error = %d", error); + goto return_part; + } + } + + _EXTERN_FUNC_EXIT; + return location; + + return_part: + + _EXTERN_FUNC_EXIT; + return NULL; +} + +static anchor_s *_get_anchor(WBXMLTreeNode * node) +{ + _INNER_FUNC_ENTER; + + retvm_if(node == NULL, NULL, "node is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + anchor_s *anchor = 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; + if (child != NULL) { + first_child_name = (const char *)wbxml_tag_get_xml_name(child->name); + _DEBUG_TRACE("child_name = %s", first_child_name); + if (strcmp(first_child_name, ELEMENT_LAST) == 0) { + err = sync_agent_get_text_from_node(child, &lastAnchor); + if (err != SYNC_AGENT_PB_RETURN_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 = sync_agent_get_text_from_node(child, &nextAnchor); + if (err != SYNC_AGENT_PB_RETURN_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); + _DEBUG_TRACE("child_name = %s", second_child_name); + if (strcmp(second_child_name, ELEMENT_NEXT) == 0) { + err = sync_agent_get_text_from_node(child, &nextAnchor); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + } else { + /* error */ + goto return_part; + } + } + + sa_error_type_e error = create_anchor(lastAnchor, nextAnchor, &anchor); + if (error != SA_INTERNAL_OK) { + _DEBUG_ERROR("create_anchor() failed !, error = %d", error); + goto return_part; + } + } + + _EXTERN_FUNC_EXIT; + return anchor; + + return_part: + + _EXTERN_FUNC_EXIT; + return NULL; +} + +static cred_s *__get_cred(WBXMLTreeNode * node) +{ + _INNER_FUNC_ENTER; + + retvm_if(node == NULL, NULL, "node is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + cred_s *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 = sync_agent_get_text_from_node(grand_child, &type); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_VERBOSE("Type = [%s]", type); + } else if (strcmp(grand_child_xml_name, ELEMENT_FORMAT) == 0) { + err = sync_agent_get_text_from_node(grand_child, &format); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_VERBOSE("Type = [%s]", format); + } + } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) { + err = sync_agent_get_text_from_node(child, &data); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_VERBOSE("Data = [%s]", data); + } + + } + + cred = create_cred_with_data(convert_auth_type(type), data); + + format_type_e formatType = FORMAT_TYPE_UNKNOWN; + if (format != NULL) { + if (strcmp(format, ELEMENT_B64) == 0) + formatType = FORMAT_TYPE_BASE64; + } + + set_cred_format_type(cred, formatType); + + _INNER_FUNC_EXIT; + return cred; + + return_part: + + _INNER_FUNC_EXIT; + return NULL; +} + +static chal_s *_get_chal(WBXMLTreeNode * node) +{ + _INNER_FUNC_ENTER; + + retvm_if(node == NULL, NULL, "node is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + chal_s *pChal = (chal_s *) calloc(1, sizeof(chal_s)); + if (pChal == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("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 = sync_agent_get_text_from_node(meta_child, &type); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Type = [%s]", type); + + pChal->type = convert_auth_type(type); + } else if (strcmp(meta_child_xml_name, ELEMENT_FORMAT) == 0) { + char *format = NULL; + err = sync_agent_get_text_from_node(meta_child, &format); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("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 = sync_agent_get_binary_from_node(meta_child, &nextnonce, &nonce_len); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("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 = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + memcpy(pChal->nonce_plain, nextnonce, nonce_len); + pChal->nonce_plain[nonce_len] = '\0'; + } + + pChal->nonce_length = nonce_len; + } + } + + _EXTERN_FUNC_EXIT; + return pChal; + + return_part: + + if (pChal != NULL) + free_chal(pChal); + + _EXTERN_FUNC_EXIT; + return NULL; +} + +static sync_agent_pb_error_e _oma_ds_binder_devinf_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* get data from dom tree */ + devinf_s *pDevInf = (devinf_s *) calloc(1, sizeof(devinf_s)); + if (pDevInf == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("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 = sync_agent_get_text_from_node(child, &verdtd); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("VerDTD = [%s]", verdtd); + + pDevInf->version = __get_oma_ds_devInf_version(verdtd); + } else if (strcmp(child_xml_name, ELEMENT_MAN) == 0) { + char *man = NULL; + err = sync_agent_get_text_from_node(child, &man); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Man = [%s]", man); + if (man != NULL) + pDevInf->manufacturer = strdup(man); + } else if (strcmp(child_xml_name, ELEMENT_MOD) == 0) { + char *mod = NULL; + err = sync_agent_get_text_from_node(child, &mod); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Mod = [%s]", mod); + if (mod != NULL) + pDevInf->model = strdup(mod); + } else if (strcmp(child_xml_name, ELEMENT_OEM) == 0) { + char *oem = NULL; + err = sync_agent_get_text_from_node(child, &oem); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("OEM = [%s]", oem); + if (oem != NULL) + pDevInf->oem = strdup(oem); + } else if (strcmp(child_xml_name, ELEMENT_FWV) == 0) { + char *fwv = NULL; + err = sync_agent_get_text_from_node(child, &fwv); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("FwV = [%s]", fwv); + if (fwv != NULL) + pDevInf->firmware_version = strdup(fwv); + } else if (strcmp(child_xml_name, ELEMENT_SWV) == 0) { + char *swv = NULL; + err = sync_agent_get_text_from_node(child, &swv); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("SwV = [%s]", swv); + if (swv != NULL) + pDevInf->software_version = strdup(swv); + } else if (strcmp(child_xml_name, ELEMENT_HWV) == 0) { + char *hwv = NULL; + err = sync_agent_get_text_from_node(child, &hwv); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("HwV = [%s]", hwv); + if (hwv != NULL) + pDevInf->hardware_version = strdup(hwv); + } else if (strcmp(child_xml_name, ELEMENT_DEVID) == 0) { + char *devID = NULL; + err = sync_agent_get_text_from_node(child, &devID); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("DevID = [%s]", devID); + if (devID != NULL) + pDevInf->dev_id = strdup(devID); + } else if (strcmp(child_xml_name, ELEMENT_DEVTYP) == 0) { + char *devtyp = NULL; + err = sync_agent_get_text_from_node(child, &devtyp); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("DevTyp = [%s]", devtyp); + + pDevInf->devtyp = __get_oma_ds_devInf_device_type(devtyp); + } else if (strcmp(child_xml_name, ELEMENT_UTC) == 0) { + _DEBUG_TRACE("UTC"); + pDevInf->supports_utc = 1; + } else if (strcmp(child_xml_name, ELEMENT_SUPPORTLARGEOBJS) == 0) { + _DEBUG_TRACE("SupportLargeObjs"); + pDevInf->supports_large_objs = 1; + } else if (strcmp(child_xml_name, ELEMENT_SUPPORTNUMBEROFCHANGES) == 0) { + _DEBUG_TRACE("SupportNumberOfChanges"); + pDevInf->supports_number_of_changes = 1; + } else if (strcmp(child_xml_name, ELEMENT_DATASTORE) == 0) { + + devinf_datastore_s *pDevInfDataStore = (devinf_datastore_s *) calloc(1, sizeof(devinf_datastore_s)); + if (pDevInfDataStore == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pDevInfDataStore is null"); + goto return_part; + } + + 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 = sync_agent_get_text_from_node(datastore_child, &sourceref); + if (err != SYNC_AGENT_PB_RETURN_OK) { + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + _DEBUG_TRACE("SourceRef = [%s]", sourceref); + if (sourceref != NULL) + pDevInfDataStore->source_ref = strdup(sourceref); + } else if (strcmp(datastore_child_xml_name, ELEMENT_DISPLAYNAME) == 0) { + char *displayname = NULL; + err = sync_agent_get_text_from_node(datastore_child, &displayname); + if (err != SYNC_AGENT_PB_RETURN_OK) { + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + _DEBUG_TRACE("DisplayName = [%s]", displayname); + if (displayname != NULL) + pDevInfDataStore->display_name = strdup(displayname); + } else if (strcmp(datastore_child_xml_name, ELEMENT_MAXGUIDSIZE) == 0) { + char *maxguidsize = NULL; + err = sync_agent_get_text_from_node(datastore_child, &maxguidsize); + if (err != SYNC_AGENT_PB_RETURN_OK) { + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + _DEBUG_TRACE("MaxGUIDSize = [%s]", maxguidsize); + if (maxguidsize != NULL) + pDevInfDataStore->max_guid_size = atoi(maxguidsize); + } else if (strcmp(datastore_child_xml_name, ELEMENT_RX_PREF) == 0) { + devinf_content_type_s *devinf_content_type = __get_devinf_contenttype(datastore_child); + if (devinf_content_type == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + pDevInfDataStore->rx_pref = devinf_content_type; + } else if (strcmp(datastore_child_xml_name, ELEMENT_RX) == 0) { + devinf_content_type_s *devinf_content_type = __get_devinf_contenttype(datastore_child); + if (devinf_content_type == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + pDevInfDataStore->rx = g_list_append(pDevInfDataStore->rx, devinf_content_type); + } else if (strcmp(datastore_child_xml_name, ELEMENT_TX_PREF) == 0) { + devinf_content_type_s *devinf_content_type = __get_devinf_contenttype(datastore_child); + if (devinf_content_type == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + pDevInfDataStore->tx_pref = devinf_content_type; + } else if (strcmp(datastore_child_xml_name, ELEMENT_TX) == 0) { + devinf_content_type_s *devinf_content_type = __get_devinf_contenttype(datastore_child); + if (devinf_content_type == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + pDevInfDataStore->tx = g_list_append(pDevInfDataStore->tx, devinf_content_type); + } else if (strcmp(datastore_child_xml_name, ELEMENT_CTCAP) == 0) { + + devinf_ct_cap_s *pDevInfCtCap = (devinf_ct_cap_s *) calloc(1, sizeof(devinf_ct_cap_s)); + if (pDevInfCtCap == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pDevInfCtCap is null"); + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + + devinf_content_type_s *devinf_content_type = 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 (devinf_content_type == NULL) { + devinf_content_type = (devinf_content_type_s *) calloc(1, sizeof(devinf_content_type_s)); + if (devinf_content_type == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("devinf_content_type is null"); + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + goto return_part; + } + } + + char *cttype = NULL; + err = sync_agent_get_text_from_node(ctcap_child, &cttype); + if (err != SYNC_AGENT_PB_RETURN_OK) { + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + goto return_part; + } + _DEBUG_TRACE("CTType = [%s]", cttype); + if (cttype != NULL) + devinf_content_type->ct_type = strdup(cttype); + } else if (strcmp(ctcap_child_xml_name, ELEMENT_VERCT) == 0) { + if (devinf_content_type == NULL) { + devinf_content_type = (devinf_content_type_s *) calloc(1, sizeof(devinf_content_type_s)); + if (devinf_content_type == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("devinf_content_type is null"); + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + goto return_part; + } + } + + char *verct = NULL; + err = sync_agent_get_text_from_node(ctcap_child, &verct); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + goto return_part; + } + _DEBUG_TRACE("VerCT = [%s]", verct); + if (verct != NULL) + devinf_content_type->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) { + + devinf_property_s *pDevInfProperty = (devinf_property_s *) calloc(1, sizeof(devinf_property_s)); + if (pDevInfProperty == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pDevInfProperty is null"); + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + goto return_part; + } + + 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 = sync_agent_get_text_from_node(property_child, &propname); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("PropName = [%s]", propname); + if (propname != NULL) + pDevInfProperty->prop_name = strdup(propname); + } else if (strcmp(property_child_xml_name, ELEMENT_DATATYPE) == 0) { + char *datatype = NULL; + err = sync_agent_get_text_from_node(property_child, &datatype); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("DataType = [%s]", datatype); + if (datatype != NULL) + pDevInfProperty->data_type = strdup(datatype); + } else if (strcmp(property_child_xml_name, ELEMENT_MAXOCCUR) == 0) { + char *maxoccur = NULL; + err = sync_agent_get_text_from_node(property_child, &maxoccur); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("MaxOccur = [%s]", maxoccur); + if (maxoccur != NULL) + pDevInfProperty->max_occur = atoi(maxoccur); + } else if (strcmp(property_child_xml_name, ELEMENT_MAXSIZE) == 0) { + char *maxsize = NULL; + err = sync_agent_get_text_from_node(property_child, &maxsize); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("MaxSize = [%s]", maxsize); + if (maxsize != NULL) + pDevInfProperty->max_size = atoi(maxsize); + } else if (strcmp(property_child_xml_name, ELEMENT_NOTRUNCATE) == 0) { + _DEBUG_TRACE("NoTruncate"); + pDevInfProperty->no_truncate = 1; + } else if (strcmp(property_child_xml_name, ELEMENT_VALENUM) == 0) { + char *valenum = NULL; + err = sync_agent_get_text_from_node(property_child, &valenum); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("ValEnum = [%s]", valenum); + if (valenum != NULL) + pDevInfProperty->val_enums = g_list_append(pDevInfProperty->val_enums, strdup(valenum)); + } else if (strcmp(property_child_xml_name, ELEMENT_DISPLAYNAME) == 0) { + char *displayname = NULL; + err = sync_agent_get_text_from_node(property_child, &displayname); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("DisplayName = [%s]", displayname); + if (displayname != NULL) + pDevInfProperty->display_name = strdup(displayname); + } else if (strcmp(property_child_xml_name, ELEMENT_PROPPARAM) == 0) { + + devinf_prop_param_s *pDevInfPropParam = (devinf_prop_param_s *) calloc(1, sizeof(devinf_prop_param_s)); + if (pDevInfPropParam == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pDevInfPropParam is null"); + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + + 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 = sync_agent_get_text_from_node(propparam_child, ¶mname); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("ParamName = [%s]", paramname); + if (paramname != NULL) + pDevInfPropParam->param_name = strdup(paramname); + } else if (strcmp(propparam_child_xml_name, ELEMENT_DATATYPE) == 0) { + char *datatype = NULL; + err = sync_agent_get_text_from_node(propparam_child, &datatype); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("DataType = [%s]", datatype); + if (datatype != NULL) + pDevInfPropParam->data_type = strdup(datatype); + } else if (strcmp(propparam_child_xml_name, ELEMENT_VALENUM) == 0) { + char *valenum = NULL; + err = sync_agent_get_text_from_node(propparam_child, &valenum); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("ValEnum = [%s]", valenum); + if (valenum != NULL) + pDevInfPropParam->val_enums = g_list_append(pDevInfPropParam->val_enums, strdup(valenum)); + } else if (strcmp(propparam_child_xml_name, ELEMENT_DISPLAYNAME) == 0) { + char *displayname = NULL; + err = sync_agent_get_text_from_node(propparam_child, &displayname); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + if (pDevInfCtCap != NULL) + free(pDevInfCtCap); + + if (devinf_content_type != NULL) + free(devinf_content_type); + + if (pDevInfProperty != NULL) + free(pDevInfProperty); + + goto return_part; + } + _DEBUG_TRACE("DisplayName = [%s]", displayname); + if (displayname != NULL) + pDevInfPropParam->display_name = strdup(displayname); + } + } + + pDevInfProperty->prop_params = g_list_append(pDevInfProperty->prop_params, pDevInfPropParam); + } + } + + pDevInfCtCap->properties = g_list_append(pDevInfCtCap->properties, pDevInfProperty); + } + } + pDevInfCtCap->ct = devinf_content_type; + pDevInfDataStore->ct_caps = g_list_append(pDevInfDataStore->ct_caps, pDevInfCtCap); + } else if (strcmp(datastore_child_xml_name, ELEMENT_DSMEM) == 0) { + + /*TODO DSMem */ + } else if (strcmp(datastore_child_xml_name, ELEMENT_SUPPORTHIERARCHICALSYNC) == 0) { + _DEBUG_TRACE("SupportHierarchicalSync"); + pDevInfDataStore->supports_hierarchical_sync = 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 = sync_agent_get_text_from_node(synccap_child, &synctype_str); + if (err != SYNC_AGENT_PB_RETURN_OK) { + + if (pDevInfDataStore != NULL) + free(pDevInfDataStore); + + goto return_part; + } + _DEBUG_TRACE("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_sync_cap(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 == SYNC_AGENT_PB_RETURN_OK) { + *content = pDevInf; + } else { + _DEBUG_ERROR("error"); + free_devinf(pDevInf); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_header_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* get data from dom tree */ + sync_hdr_s *pSyncHdr = (sync_hdr_s *) calloc(1, sizeof(sync_hdr_s)); + if (pSyncHdr == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("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 = sync_agent_get_text_from_node(child, &verdtd); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("VerDTD = [%s]", verdtd); + + pSyncHdr->version = __get_oma_ds_protocol_version(verdtd); + } else if (strcmp(child_xml_name, ELEMENT_SESSIONID) == 0) { + char *sessionID = NULL; + err = sync_agent_get_text_from_node(child, &sessionID); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("SessionID = [%s]", sessionID); + + if (sessionID != NULL) + pSyncHdr->session_id = strdup(sessionID); + else + pSyncHdr->session_id = NULL; + } else if (strcmp(child_xml_name, ELEMENT_MSGID) == 0) { + char *msgID = NULL; + err = sync_agent_get_text_from_node(child, &msgID); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("MsgID = [%s]", msgID); + if (msgID != NULL) + pSyncHdr->message_id = atoi(msgID); + } else if (strcmp(child_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(child); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pSyncHdr->target = pTargetLocation; + } else if (strcmp(child_xml_name, ELEMENT_SOURCE) == 0) { + location_s *pSourceLocation = _get_location(child); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pSyncHdr->source = pSourceLocation; + } else if (strcmp(child_xml_name, ELEMENT_RESPURI) == 0) { + char *resp_uri = NULL; + err = sync_agent_get_text_from_node(child, &resp_uri); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("resp_uri = [%s]", resp_uri); + if (resp_uri != NULL) + pSyncHdr->response_uri = strdup(resp_uri); + } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) { + _DEBUG_TRACE("noResp\n"); + pSyncHdr->no_response = 1; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pSyncHdr->cred = cred; + } else if (strcmp(child_xml_name, ELEMENT_META) == 0) { + + } + } + + return_part: + if (err == SYNC_AGENT_PB_RETURN_OK) { + *content = pSyncHdr; + } else { + _DEBUG_ERROR("error"); + free_sync_hdr(pSyncHdr); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_results_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* get data from dom tree */ + command_s *pResults = (command_s *) calloc(1, sizeof(command_s)); + if (pResults == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pResults is null"); + goto return_part; + } + + pResults->type = COMMAND_TYPE_RESULTS; + pResults->msg_id = pSyncHdr->message_id; + pResults->ref_count = 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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pResults->cmd_id = atoi(cmd_id); + } else if (strcmp(child_xml_name, ELEMENT_MSGREF) == 0) { + char *msg_ref = NULL; + err = sync_agent_get_text_from_node(child, &msg_ref); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("MsgRef = [%s]", msg_ref); + if (msg_ref != NULL) + pResults->private.results.msg_ref = atoi(msg_ref); + } else if (strcmp(child_xml_name, ELEMENT_CMDREF) == 0) { + char *cmd_ref = NULL; + err = sync_agent_get_text_from_node(child, &cmd_ref); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("MsgRef = [%s]", cmd_ref); + if (cmd_ref != NULL) + pResults->private.results.cmd_ref = 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 = sync_agent_get_text_from_node(grandchild, &contentType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("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_s *item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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_s *pSourceLocation = _get_location(grandchild); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pResults->private.results.item->source = pSourceLocation; + } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(grandchild); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_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 == SYNC_AGENT_PB_RETURN_OK) { + *content = pResults; + } else { + _DEBUG_ERROR("error"); + free_command(pResults); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_put_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* get data from dom tree */ + command_s *pPut = (command_s *) calloc(1, sizeof(command_s)); + if (pPut == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pPut is null"); + goto return_part; + } + + pPut->type = COMMAND_TYPE_PUT; + pPut->msg_id = pSyncHdr->message_id; + pPut->ref_count = 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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pPut->cmd_id = atoi(cmd_id); + } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) { + _DEBUG_TRACE("NoResp"); + pPut->no_resp = 1; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pPut->cred = cred; + } 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 = sync_agent_get_text_from_node(grandchild, &contentType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("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_s *item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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_s *pSourceLocation = _get_location(grandchild); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pPut->private.access.item->source = pSourceLocation; + } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(grandchild); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_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 == SYNC_AGENT_PB_RETURN_OK) { + *content = pPut; + } else { + _DEBUG_ERROR("error"); + free_command(pPut); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_get_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* get data from dom tree */ + command_s *pGet = (command_s *) calloc(1, sizeof(command_s)); + if (pGet == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pGet is null"); + goto return_part; + } + + pGet->type = COMMAND_TYPE_GET; + pGet->msg_id = pSyncHdr->message_id; + pGet->ref_count = 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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pGet->cmd_id = atoi(cmd_id); + } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) { + _DEBUG_TRACE("NoResp"); + pGet->no_resp = 1; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pGet->cred = cred; + } 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 = sync_agent_get_text_from_node(grandchild, &contentType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("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_s *item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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_s *pSourceLocation = _get_location(grandchild); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pGet->private.access.item->source = pSourceLocation; + } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(grandchild); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_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 == SYNC_AGENT_PB_RETURN_OK) { + *content = pGet; + } else { + _DEBUG_ERROR("error"); + free_command(pGet); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_alert_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* get data from dom tree */ + command_s *pAlert = (command_s *) calloc(1, sizeof(command_s)); + if (pAlert == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pAlert is null"); + goto return_part; + } + + pAlert->type = COMMAND_TYPE_ALERT; + pAlert->msg_id = pSyncHdr->message_id; + pAlert->ref_count = 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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pAlert->cmd_id = atoi(cmd_id); + } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) { + _DEBUG_TRACE("NoResp"); + pAlert->no_resp = 1; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pAlert->cred = cred; + } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) { + char *data = NULL; + err = sync_agent_get_text_from_node(child, &data); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("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_s *pSourceLocation = _get_location(grandchild); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pAlert->source = pSourceLocation; + } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(grandchild); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_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_s *anchor = _get_anchor(grandgrandchild); + if (anchor == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pAlert->private.alert.anchor = anchor; + } else if (strcmp(grandgrandchild_xml_name, ELEMENT_MAXOBJSIZE) == 0) { + char *maxObjSize = NULL; + err = sync_agent_get_text_from_node(grandgrandchild, &maxObjSize); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("MaxObjSize = [%s]", maxObjSize); + if (maxObjSize != NULL) + pAlert->private.alert.max_obj_size = atoi(maxObjSize); + } + } + } + } + } + } + + return_part: + if (err == SYNC_AGENT_PB_RETURN_OK) { + *content = pAlert; + } else { + _DEBUG_ERROR("error"); + free_command(pAlert); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_sync_end_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* get data from dom tree */ + command_s *pSyncEnd = (command_s *) calloc(1, sizeof(command_s)); + if (pSyncEnd == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pSyncEnd is null"); + goto return_part; + } + + pSyncEnd->type = COMMAND_TYPE_SYNC_END;; + pSyncEnd->msg_id = pSyncHdr->message_id; + pSyncEnd->ref_count = 1; + + return_part: + if (err == SYNC_AGENT_PB_RETURN_OK) { + *content = pSyncEnd; + } else { + _DEBUG_ERROR("error"); + free_command(pSyncEnd); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_sync_start_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + /* get data from dom tree */ + command_s *pSync = (command_s *) calloc(1, sizeof(command_s)); + if (pSync == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pSync is null"); + goto return_part; + } + + pSync->type = COMMAND_TYPE_SYNC_START;; + pSync->msg_id = pSyncHdr->message_id; + pSync->ref_count = 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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pSync->cmd_id = atoi(cmd_id); + } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) { + _DEBUG_TRACE("NoResp"); + pSync->no_resp = 1; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pSync->cred = cred; + } else if (strcmp(child_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(child); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pSync->target = pTargetLocation; + } else if (strcmp(child_xml_name, ELEMENT_SOURCE) == 0) { + location_s *pSourceLocation = _get_location(child); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_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 = sync_agent_get_text_from_node(child, &numOfChanges); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("NumberOfChanges = [%s]", numOfChanges); + + pSync->private.sync.has_num_changed = 1; + if (numOfChanges != NULL) + pSync->private.sync.num_changed = atoi(numOfChanges); + } + } + + return_part: + if (err == SYNC_AGENT_PB_RETURN_OK) { + *content = pSync; + } else { + _DEBUG_ERROR("error"); + free_command(pSync); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_add_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + item_s *item = NULL; + + /* get data from dom tree */ + command_s *pAdd = (command_s *) calloc(1, sizeof(command_s)); + if (pAdd == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pAdd is null"); + goto return_part; + } + + pAdd->type = COMMAND_TYPE_ADD;; + pAdd->msg_id = pSyncHdr->message_id; + pAdd->private.change.type = CHANGE_ADD; + pAdd->ref_count = 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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pAdd->cmd_id = atoi(cmd_id); + } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) { + _DEBUG_TRACE("NoResp"); + pAdd->no_resp = 1; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pAdd->cred = cred; + } else if (strcmp(child_xml_name, ELEMENT_META) == 0) { + WBXMLTreeNode *grandchild = NULL; + + if (item == NULL) { + item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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 = sync_agent_get_text_from_node(grandchild, &contentType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Content Type = [%s]", contentType); + if (contentType != NULL) + item->content_type = strdup(contentType); + } else if (strcmp(grandchild_xml_name, ELEMENT_SIZE) == 0) { + char *size = NULL; + err = sync_agent_get_text_from_node(grandchild, &size); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Size = [%s]", size); + if (size != NULL) + item->size = atoi(size); + } + } + } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) { + + if (item == NULL) { + item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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_s *pSourceLocation = _get_location(grandchild); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + item->source = pSourceLocation; + } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(grandchild); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_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 = sync_agent_get_text_from_node(grandgrandchild, &contentType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Content Type = [%s]", contentType); + if (contentType != NULL) + item->content_type = strdup(contentType); + } else if (strcmp(grandgrandchild_xml_name, ELEMENT_SIZE) == 0) { + char *size = NULL; + err = sync_agent_get_text_from_node(grandgrandchild, &size); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Size = [%s]", size); + if (size != NULL) + item->size = atoi(size); + } + } + } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) { + char *data = NULL; + err = sync_agent_get_text_from_cdata_node(grandchild, &data); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Data = [%s]", data); + if (data != NULL) + item->private.data = strdup(data); + item->data_type = ITEM_DATA; + } else if (strcmp(grandchild_xml_name, ELEMENT_MOREDATA) == 0) { + _DEBUG_TRACE("MoreData"); + item->more_data = 1; + } + } + pAdd->private.change.items = g_list_append(pAdd->private.change.items, item); + item = NULL; + } + } + + return_part: + + if (item != NULL) + free_item(item); + + if (err == SYNC_AGENT_PB_RETURN_OK) { + *content = pAdd; + } else { + _DEBUG_ERROR("error"); + free_command(pAdd); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_replace_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + item_s *item = NULL; + + /* get data from dom tree */ + command_s *pReplace = (command_s *) calloc(1, sizeof(command_s)); + if (pReplace == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pReplace is null"); + goto return_part; + } + + pReplace->type = COMMAND_TYPE_REPLACE;; + pReplace->msg_id = pSyncHdr->message_id; + pReplace->private.change.type = CHANGE_REPLACE; + pReplace->ref_count = 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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pReplace->cmd_id = atoi(cmd_id); + + } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) { + _DEBUG_TRACE("NoResp"); + pReplace->no_resp = 1; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pReplace->cred = cred; + } else if (strcmp(child_xml_name, ELEMENT_META) == 0) { + + if (item == NULL) { + item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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 = sync_agent_get_text_from_node(grandchild, &contentType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Content Type = [%s]", contentType); + if (contentType != NULL) + item->content_type = strdup(contentType); + } else if (strcmp(grandchild_xml_name, ELEMENT_SIZE) == 0) { + char *size = NULL; + err = sync_agent_get_text_from_node(grandchild, &size); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Size = [%s]", size); + if (size != NULL) + item->size = atoi(size); + } + } + } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) { + + if (item == NULL) { + item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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_s *pSourceLocation = _get_location(grandchild); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + item->source = pSourceLocation; + } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(grandchild); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_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 = sync_agent_get_text_from_node(grandgrandchild, &contentType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Content Type = [%s]", contentType); + if (contentType != NULL) + item->content_type = strdup(contentType); + } else if (strcmp(grandgrandchild_xml_name, ELEMENT_SIZE) == 0) { + char *size = NULL; + err = sync_agent_get_text_from_node(grandgrandchild, &size); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Size = [%s]", size); + if (size != NULL) + item->size = atoi(size); + } + } + + } else if (strcmp(grandchild_xml_name, ELEMENT_DATA) == 0) { + char *data = NULL; + err = sync_agent_get_text_from_cdata_node(grandchild, &data); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Data = [%s]", data); + if (data != NULL) + item->private.data = strdup(data); + item->data_type = ITEM_DATA; + } + } + pReplace->private.change.items = g_list_append(pReplace->private.change.items, item); + item = NULL; + } + } + + return_part: + + if (item != NULL) + free_item(item); + + if (err == SYNC_AGENT_PB_RETURN_OK) { + *content = pReplace; + } else { + _DEBUG_ERROR("error"); + free_command(pReplace); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_delete_command_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + retvm_if(reverse_binder == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "reverse_binder is NULL"); + + sync_hdr_s *pSyncHdr = (sync_hdr_s *) sync_agent_get_user_data_from_reverse_protocol_binder(reverse_binder); + retvm_if(pSyncHdr == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "pSyncHdr is NULL"); + + item_s *item = NULL; + + /* get data from dom tree */ + command_s *pDelete = (command_s *) calloc(1, sizeof(command_s)); + if (pDelete == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("pDelete is null"); + goto return_part; + } + + pDelete->type = COMMAND_TYPE_DELETE; + pDelete->msg_id = pSyncHdr->message_id; + pDelete->private.change.type = CHANGE_DELETE; + pDelete->ref_count = 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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pDelete->cmd_id = atoi(cmd_id); + } else if (strcmp(child_xml_name, ELEMENT_NORESP) == 0) { + _DEBUG_TRACE("NoResp"); + pDelete->no_resp = 1; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pDelete->cred = cred; + } else if (strcmp(child_xml_name, ELEMENT_META) == 0) { + WBXMLTreeNode *grandchild = NULL; + + /* create Item */ + if (item == NULL) { + item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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 = sync_agent_get_text_from_node(grandchild, &contentType); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Content Type = [%s]", contentType); + if (contentType != NULL) + item->content_type = strdup(contentType); + } + } + } else if (strcmp(child_xml_name, ELEMENT_ITEM) == 0) { + /* create Item */ + if (item == NULL) { + item = create_item(); + if (item == NULL) { + err = SYNC_AGENT_PB_RETURN_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_s *pSourceLocation = _get_location(grandchild); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + item->source = pSourceLocation; + } else if (strcmp(grandchild_xml_name, ELEMENT_TARGET) == 0) { + location_s *pTargetLocation = _get_location(grandchild); + if (pTargetLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_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); + item = NULL; + } + } + + return_part: + + if (item != NULL) + free_item(item); + + if (err == SYNC_AGENT_PB_RETURN_OK) { + *content = pDelete; + } else { + _DEBUG_ERROR("error"); + free_command(pDelete); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_final_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + int *pFinal = (int *)1; + *content = pFinal; + + _EXTERN_FUNC_EXIT; + return err; +} + +static sync_agent_pb_error_e _oma_ds_binder_status_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * content) +{ + _INNER_FUNC_ENTER; + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_NOT_DEFINED, "wbxml_dom_node is NULL"); + + /* get data from dom tree */ + status_s *pStatus = (status_s *) calloc(1, sizeof(status_s)); + if (pStatus == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + _DEBUG_ERROR("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 = sync_agent_get_text_from_node(child, &cmd_id); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdID = [%s]", cmd_id); + if (cmd_id != NULL) + pStatus->cmd_id = atoi(cmd_id); + } else if (strcmp(child_xml_name, ELEMENT_MSGREF) == 0) { + char *msgref = NULL; + err = sync_agent_get_text_from_node(child, &msgref); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("MsgRef = [%s]", msgref); + if (msgref != NULL) + pStatus->msg_ref = atoi(msgref); + } else if (strcmp(child_xml_name, ELEMENT_CMDREF) == 0) { + char *cmdref = NULL; + err = sync_agent_get_text_from_node(child, &cmdref); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("CmdRef = [%s]", cmdref); + if (cmdref != NULL) + pStatus->cmd_ref = atoi(cmdref); + } else if (strcmp(child_xml_name, ELEMENT_CMD) == 0) { + char *cmd = NULL; + err = sync_agent_get_text_from_node(child, &cmd); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("Cmd = [%s]", cmd); + + pStatus->type = convert_command_type(cmd); + } else if (strcmp(child_xml_name, ELEMENT_TARGETREF) == 0) { + char *targetref = NULL; + location_s *location = NULL; + err = sync_agent_get_text_from_node(child, &targetref); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("TargetRef = [%s]", targetref); + + sa_error_type_e error = create_location(targetref, NULL, &location); + if (error != SA_INTERNAL_OK) { + _DEBUG_ERROR("create_location() failed !, error = %d", error); + goto return_part; + } + pStatus->target_ref = location; + } else if (strcmp(child_xml_name, ELEMENT_SOURCEREF) == 0) { + char *sourceref = NULL; + location_s *location = NULL; + err = sync_agent_get_text_from_node(child, &sourceref); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("SourceRef = [%s]", sourceref); + + sa_error_type_e error = create_location(sourceref, NULL, &location); + if (error != SA_INTERNAL_OK) { + _DEBUG_ERROR("create_location() failed !, error = %d", error); + goto return_part; + } + pStatus->source_ref = location; + } else if (strcmp(child_xml_name, ELEMENT_CRED) == 0) { + _DEBUG_TRACE("Cred\n"); + cred_s *cred = NULL; + cred = __get_cred(child); + if (cred == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pStatus->cred = cred; + } else if (strcmp(child_xml_name, ELEMENT_CHAL) == 0) { + _DEBUG_TRACE("Chal\n"); + chal_s *pChal = NULL; + pChal = _get_chal(child); + if (pChal == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pStatus->chal = pChal; + } else if (strcmp(child_xml_name, ELEMENT_DATA) == 0) { + char *data = NULL; + err = sync_agent_get_text_from_node(child, &data); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + _DEBUG_TRACE("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_s *pSourceLocation = _get_location(grandchild); + if (pSourceLocation == NULL) { + err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY; + goto return_part; + } + pStatus->source_ref = 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 == SYNC_AGENT_PB_RETURN_OK) { + *content = pStatus; + } else { + _DEBUG_ERROR("error"); + free_status(pStatus); + } + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_pb_error_e init_oma_ds_1_2_binder_function_set(sync_agent_pb_protocol_binder_function_set_s ** binder_function_set) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + err = sync_agent_init_binder_function_set(sizeof(oma_ds_binder_function_info) / sizeof(sync_agent_pb_function_info_s), (sync_agent_pb_function_info_s *) oma_ds_binder_function_info, binder_function_set); + + _EXTERN_FUNC_EXIT; + return err; +} + +void free_oma_ds_1_2_binder_function_set(sync_agent_pb_protocol_binder_function_set_s * binder_function_set) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_free_binder_function_set(binder_function_set); + + _EXTERN_FUNC_EXIT; +} + +sync_agent_pb_protocol_binder_info_s *oma_ds_1_2_binder_init(sync_agent_pb_protocol_binder_info_s * binder, sync_agent_pb_encoding_e enc, bool encode_xml_header, + bool use_strtbl, bool produce_anonymous, bool use_flow_mode, bool text_public_id, sync_agent_pb_protocol_binder_function_set_s * binder_function_set) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_pb_protocol_binder_info_s *pOutBinder = NULL; + + pOutBinder = sync_agent_init_protocol_binder(binder, SYNC_AGENT_PB_PROTOCOL_SYNCML_SYNCML12, NULL, enc, encode_xml_header, use_strtbl, produce_anonymous, use_flow_mode, text_public_id, NULL, NULL, binder_function_set); + + if (pOutBinder == NULL) { + goto return_part; + } + + return_part: + + _EXTERN_FUNC_EXIT; + return pOutBinder; +} + +sync_agent_pb_error_e oma_ds_1_2_binder_append(sync_agent_pb_protocol_binder_info_s * binder, oma_ds_protocol_element_e protocol_element, Content_Ptr content) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + err = sync_agent_append_element(binder, protocol_element, content); + + _EXTERN_FUNC_EXIT; + return err; +} + +void oma_ds_1_2_binder_terminate(sync_agent_pb_protocol_binder_info_s * binder) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_destroy_protocol_binder(binder); + + _EXTERN_FUNC_EXIT; +} + +sync_agent_pb_error_e oma_ds_1_2_binder_get_stream(sync_agent_pb_protocol_binder_info_s * binder, char **byte_stream, unsigned int *byte_stream_size) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + err = sync_agent_get_stream_from_protocol_binder(binder, byte_stream, byte_stream_size); + if (err != SYNC_AGENT_PB_RETURN_OK) { + goto return_part; + } + + return_part: + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_pb_error_e oma_ds_1_2_binder_get_stream_size(sync_agent_pb_protocol_binder_info_s * binder, unsigned int *byte_stream_size) +{ + + _EXTERN_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + err = sync_agent_get_stream_size_from_protocol_binder(binder, byte_stream_size); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_pb_error_e oma_ds_1_2_binder_get_encoding(sync_agent_pb_protocol_binder_info_s * binder, sync_agent_pb_encoding_e * enc) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + + err = sync_agent_get_encoding_from_protocol_binder(binder, enc); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_pb_error_e reverse_oma_ds_1_2_binder_init(char *byte_stream, + unsigned int byte_stream_len, sync_agent_pb_decoding_e dec, sync_agent_pb_protocol_binder_function_set_s * binder_function_set, void *user_data, sync_agent_pb_protocol_binder_reverse_info_s ** binder) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_pb_protocol_e protocol = SYNC_AGENT_PB_PROTOCOL_UNKNOWN; + sync_agent_pb_error_e err = sync_agent_init_reverse_protocol_binder(byte_stream, byte_stream_len, dec, + &protocol, binder_function_set, user_data, binder); + + _EXTERN_FUNC_EXIT; + return err; +} + +sync_agent_pb_error_e reverse_oma_ds_1_2_binder_next(sync_agent_pb_protocol_binder_reverse_info_s * pBinder, oma_ds_protocol_element_e * protocol_element, char **protocol_element_name, Content_Ptr * content) +{ + _EXTERN_FUNC_ENTER; + + sync_agent_pb_error_e err = sync_agent_next_element(pBinder, + protocol_element, protocol_element_name, content); + + _EXTERN_FUNC_EXIT; + return err; +} diff --git a/src/agent/service-adapter/sa_command.c b/src/agent/service-adapter/sa_command.c new file mode 100755 index 0000000..7a65503 --- /dev/null +++ b/src/agent/service-adapter/sa_command.c @@ -0,0 +1,1016 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 + +#include + +#include "service-adapter/sa_command.h" +#include "service-adapter/sa_command_internal.h" +#include "service-adapter/sa_elements.h" +#include "service-adapter/sa_elements_internal.h" +#include "service-adapter/sa_session.h" +#include "service-adapter/sa_session_internal.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SA" +#endif + +static command_s *_create_command(session_s * session, command_type_e type); + +static command_s *_create_command(session_s * session, command_type_e type) +{ + _INNER_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (session == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (!type) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command_s *cmd = (command_s *) calloc(1, sizeof(command_s)); + if (cmd == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + cmd->type = type; + cmd->msg_id = session->msg_id; + cmd->cmd_id = session->cmd_id; + cmd->ref_count = 1; + + session->cmd_id++; + + _INNER_FUNC_EXIT; + return cmd; + + error: + _INNER_FUNC_EXIT; + return NULL; +} + +void free_commands(GList * commands) +{ + _EXTERN_FUNC_ENTER; + + retm_if(commands == NULL, "List is NULL"); + + _DEBUG_INFO("start list length is %d", g_list_length(commands)); + + GList *iter = NULL; + command_s *pCommand = NULL; + for (iter = commands; iter != NULL;) { + pCommand = iter->data; + _DEBUG_INFO("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) { + commands = g_list_remove(commands, pCommand); + free_command(pCommand); + } + } + + g_list_free(commands); + + _EXTERN_FUNC_EXIT; + return; +} + +sa_error_type_e create_alert_command(session_s * session, alert_type_e sync_type, location_s * source, location_s * target, char *last_anchor, char *next_anchor, cred_s * cred, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with syncType =%d", sync_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + anchor_s *pAnchor = NULL; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_ALERT); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->target = target; + (*command)->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 (next_anchor != NULL) { + errorType = create_anchor(last_anchor, next_anchor, &pAnchor); + if (errorType != SA_INTERNAL_OK) + goto error; + + (*command)->private.alert.anchor = pAnchor; + pAnchor = NULL; + } + + if (cred != NULL) + (*command)->cred = dup_cred(cred); + + (*command)->private.alert.type = sync_type; + + _EXTERN_FUNC_EXIT; + return errorType; + + error: + + if (pAnchor != NULL) + free_anchor(pAnchor); + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_get_command(session_s * session, location_s * target, const char *content_type, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with content type = %s", content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_GET); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.access.item = create_item(); + if ((*command)->private.access.item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + set_item_target((*command)->private.access.item, target); + + if (content_type != NULL) + (*command)->private.access.item->content_type = strdup(content_type); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_put_command(session_s * session, location_s * source, const char *content_type, devinf_s * devinf, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with content type = %s", content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_PUT); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.access.item = create_item_for_devinf(devinf); + + if ((*command)->private.access.item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + set_item_source((*command)->private.access.item, source); + + if (content_type != NULL) + (*command)->private.access.item->content_type = strdup(content_type); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_results_command(session_s * session, location_s * source, const char *content_type, devinf_s * devinf, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with content type = %s", content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_RESULTS); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.results.item = create_item_for_devinf(devinf); + + if ((*command)->private.results.item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + set_item_source((*command)->private.results.item, source); + + if (content_type != NULL) + (*command)->private.results.item->content_type = strdup(content_type); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_sync_start_command(session_s * session, location_s * source, location_s * target, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_SYNC_START); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->source = source; + (*command)->target = target; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_sync_start_command_number_of_changes(command_s * command, unsigned int number_of_changes) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->private.sync.has_num_changed = 1; + command->private.sync.num_changed = number_of_changes; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_sync_start_command_mem(command_s * command, mem_s * mem) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->private.sync.mem = mem; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; + +} + +sa_error_type_e create_sync_end_command(command_s ** command) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + *command = (command_s *) calloc(1, sizeof(command_s)); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->type = COMMAND_TYPE_SYNC_END; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_add_command(session_s * session, change_type_e type, char *luid, const char *content_type, char *data, unsigned int size, int more_data, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + item_s *temp = NULL; + location_s *pLocation = NULL; + + *command = _create_command(session, COMMAND_TYPE_ADD); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + temp = create_item_for_data(data, size); + if (!temp) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.change.type = type; + if (content_type != NULL) + temp->content_type = strdup(content_type); + temp->more_data = more_data; + + errorType = create_location(luid, NULL, &pLocation); + if (errorType != SA_INTERNAL_OK) + goto error; + + set_item_source(temp, pLocation); + (*command)->private.change.items = g_list_append((*command)->private.change.items, temp); + temp = NULL; + + error: + + if (temp != NULL) + free(temp); + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_replace_command(session_s * session, change_type_e type, char *luid, const char *content_type, const char *data, unsigned int size, int more_data, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + item_s *temp = NULL; + location_s *pLocation = NULL; + + *command = _create_command(session, COMMAND_TYPE_REPLACE); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + temp = create_item_for_data(data, size); + if (!temp) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.change.type = type; + if (content_type != NULL) + temp->content_type = strdup(content_type); + temp->more_data = more_data; + + errorType = create_location(luid, NULL, &pLocation); + if (errorType != SA_INTERNAL_OK) + goto error; + + set_item_source(temp, pLocation); + (*command)->private.change.items = g_list_append((*command)->private.change.items, temp); + temp = NULL; + + error: + + if (temp != NULL) + free(temp); + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_delete_command(session_s * session, change_type_e type, char *luid, const char *content_type, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + item_s *temp = NULL; + location_s *pLocation = NULL; + + *command = _create_command(session, COMMAND_TYPE_DELETE); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + temp = create_item(); + if (temp == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.change.type = type; + + errorType = create_location(luid, NULL, &pLocation); + if (errorType != SA_INTERNAL_OK) + goto error; + + set_item_source(temp, pLocation); + if (content_type != NULL) + temp->content_type = strdup(content_type); + (*command)->private.change.items = g_list_append((*command)->private.change.items, temp); + temp = NULL; + + error: + + if (temp != NULL) + free(temp); + + _EXTERN_FUNC_EXIT; + return errorType; + +} + +sa_error_type_e create_map_command(session_s * session, location_s * source, location_s * target, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_MAP); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->source = source; + (*command)->target = target; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_map_command_item(command_s * map_command, item_s * temp) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (map_command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + map_command->private.map.items = g_list_append(map_command->private.map.items, temp); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e increase_command_ref_count(command_s * command) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->ref_count++; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e decrease_command_ref_count(command_s * command) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->ref_count--; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_results_command_msg_ref(command_s * command, unsigned int msg_ref) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->private.results.msg_ref = msg_ref; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_results_command_cmd_ref(command_s * command, unsigned int cmd_ref) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->private.results.cmd_ref = cmd_ref; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_results_command_target_ref(command_s * command, location_s * location) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + _DEBUG_INFO("start with Command Type =%d\n", command->type); + + command->private.results.target_ref = dup_location(location); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void free_command(command_s * command) +{ + _EXTERN_FUNC_ENTER; + + retm_if(command == NULL, "pCommand is NULL"); + + _DEBUG_INFO("start with Command type is %d", command->type); + + GList *iter = NULL; + + if (command->ref_count > 1) { + _DEBUG_INFO("Command's refCount is %d", command->ref_count); + decrease_command_ref_count(command); + return; + } + + switch (command->type) { + case COMMAND_TYPE_ALERT: + if (command->private.alert.anchor != NULL) { + free_anchor(command->private.alert.anchor); + command->private.alert.anchor = NULL; + } + + if (command->private.alert.content_type != NULL) { + free(command->private.alert.content_type); + command->private.alert.content_type = 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 (command->private.access.type != NULL) { + free(command->private.access.type); + command->private.access.type = NULL; + } + + if (command->private.access.item != NULL) { + free_item(command->private.access.item); + command->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 = command->private.change.items; iter != NULL; iter = g_list_next(iter)) + free_item(iter->data); + break; + case COMMAND_TYPE_MAP: + for (iter = command->private.map.items; iter != NULL; iter = g_list_next(iter)) + free_item(iter->data); + break; + case COMMAND_TYPE_GET: + if (command->private.access.type != NULL) { + free(command->private.access.type); + command->private.access.type = NULL; + } + + if (command->private.access.item != NULL) { + free_item(command->private.access.item); + command->private.access.item = NULL; + } + break; + case COMMAND_TYPE_RESULTS: + if (command->private.results.type != NULL) { + free(command->private.results.type); + command->private.results.type = NULL; + } + + if (command->private.results.item != NULL) { + free_item(command->private.results.item); + command->private.results.item = NULL; + } + + if (command->private.results.target_ref != NULL) { + free_location(command->private.results.target_ref); + command->private.results.target_ref = NULL; + } + + break; + case COMMAND_TYPE_UNKNOWN: + break; + } + + if (command->source != NULL) { + free_location(command->source); + command->source = NULL; + } + + if (command->target != NULL) { + free_location(command->target); + command->target = NULL; + } + + if (command->cred != NULL) { + free_cred(command->cred); + command->cred = NULL; + } + + free(command); + + _EXTERN_FUNC_EXIT; +} + +sa_error_type_e create_new_status_location(session_s * session, oma_status_type_e data, command_s * command, location_s * source_ref, location_s * target_ref, command_type_e type, status_s ** status) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start Errortype %d", data); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + errorType = create_status(data, session->cmd_id, session->last_recieved_msg_id, command->cmd_id, source_ref, target_ref, type, status); + if (errorType != SA_INTERNAL_OK) + goto error; + + session->cmd_id++; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_new_status(session_s * session, oma_status_type_e data, command_s * command, command_type_e type, status_s ** status) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start Errortype %d", data); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + errorType = create_status(data, session->cmd_id, session->last_recieved_msg_id, command->cmd_id, command->source, command->target, type, status); + if (errorType != SA_INTERNAL_OK) + goto error; + + session->cmd_id++; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_status(oma_status_type_e data, unsigned int cmd_id, unsigned int msg_ref, unsigned int cmd_ref, location_s * source_ref, location_s * target_ref, command_type_e type, status_s ** status) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start Errortype %d", data); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + *status = (status_s *) calloc(1, sizeof(status_s)); + if (*status == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*status)->cmd_id = cmd_id; + (*status)->msg_ref = msg_ref; + (*status)->cmd_ref = cmd_ref; + (*status)->type = type; + (*status)->data = g_strdup_printf("%d", data); + + if (source_ref != NULL) + (*status)->source_ref = dup_location(source_ref); + + if (target_ref != NULL) + (*status)->target_ref = dup_location(target_ref); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void free_statuses(GList * statuses) +{ + _EXTERN_FUNC_ENTER; + + retm_if(statuses == NULL, "List is NULL"); + + GList *iter = NULL; + status_s *status = NULL; + _DEBUG_INFO("count : %d", g_list_length(statuses)); + for (iter = statuses; iter != NULL; iter = g_list_next(iter)) { + status = (status_s *) iter->data; + free_status(status); + } + + g_list_free(statuses); + + _EXTERN_FUNC_EXIT; +} + +void free_status(status_s * status) +{ + _EXTERN_FUNC_ENTER; + + retm_if(status == NULL, "pStatus is NULL"); + + if (status->data != NULL) + free(status->data); + + if (status->source_ref != NULL) + free_location(status->source_ref); + + if (status->target_ref != NULL) + free_location(status->target_ref); + + if (status->cred != NULL) + free_cred(status->cred); + + if (status->chal != NULL) + free_chal(status->chal); + + free_item(status->item); + + free(status); + status = NULL; + + _EXTERN_FUNC_EXIT; +} + +oma_status_type_e get_status_code(status_s * status) +{ + _EXTERN_FUNC_ENTER; + + _EXTERN_FUNC_EXIT; + + return atoi(status->data); +} + +command_type_e convert_command_type(char *type) +{ + _EXTERN_FUNC_ENTER; + + command_type_e commandType = COMMAND_TYPE_UNKNOWN; + + retvm_if(type == NULL, commandType, "type is NULL"); + + 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; + } + + _EXTERN_FUNC_EXIT; + return commandType; +} + +change_type_e convert_change_type_command_type(command_type_e type) +{ + _EXTERN_FUNC_ENTER; + + change_type_e 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; + } + + _EXTERN_FUNC_EXIT; + return changeType; +} + +command_type_e convert_command_type_change_type(change_type_e type) +{ + _EXTERN_FUNC_ENTER; + + command_type_e 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; + } + + _EXTERN_FUNC_EXIT; + 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/agent/service-adapter/sa_common_interface.c b/src/agent/service-adapter/sa_common_interface.c new file mode 100755 index 0000000..614aded --- /dev/null +++ b/src/agent/service-adapter/sa_common_interface.c @@ -0,0 +1,2812 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @SA_Common_Interface.c + * @version 0.1 + * @brief This file is the source file of implementation of interface of Service Adapter + */ + +#include + +#include "common/common_vconf.h" +#include "common/common_define.h" +#include "common/common_util.h" +#include "service-adapter/protocol-binder/oma_ds_protocol_binder.h" +#include "service-adapter/network-binder/na_binder.h" +#include "service-adapter/sa_define.h" +#include "service-adapter/sa_common_interface.h" +#include "service-adapter/sa_elements.h" +#include "service-adapter/sa_elements_internal.h" +#include "service-adapter/sa_command.h" +#include "service-adapter/sa_command_internal.h" +#include "service-adapter/sa_session.h" +#include "service-adapter/sa_session_internal.h" +#include "service-adapter/sa_devinf_internal.h" +#include "service-adapter/sa_util.h" +#include "service-adapter/sa_devinf.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SA" +#endif + +session_s *static_session = NULL; + +static sa_error_type_e _create_session(int account_id, char *session_id, bool server_flag, session_s ** session); +static sa_error_type_e _generate_presync_msg(session_s * session, bool server_flag, char **msg, unsigned int *msg_size); +static sa_error_type_e _generate_msg(session_s * session, void **sync_obj, bool server_flag, char **msg, unsigned int *msg_size); +static sa_error_type_e _generate_autoconfigure_msg(char *id, char *pwd, char *target_url, char **msg, unsigned int *msg_size, session_s * session); +static sa_error_type_e _generate_suspend_msg(session_s * session, bool server_flag, char **msg, unsigned int *msg_size); +static sa_error_type_e _exchange_msg(session_s * session, char *acc_type, int transport_type, char *send_msg, unsigned int send_msg_length, char **recv_msg, unsigned int *recv_msg_length); + +static sa_error_type_e _process_recv_msg(session_s * session, char *recv_msg, unsigned int recv_msg_length, int only_from_client, void **sync_return_obj, int *is_finish); +static sa_error_type_e _process_autoconfigure_recv_msg(char *recv_msg, unsigned int recv_msg_length, session_s * session); +static common_error_type_e _convert_error_type(sa_error_type_e error_type); + +static sa_error_type_e __get_account_info(int account_id, char **id, char **pwd, char **server_url, char **next_nonce); +static sa_error_type_e __object_binder(syncml_s * syncml, bool server_flag, char **msg, unsigned int *msg_size); +static sa_error_type_e __reverse_object_binder(syncml_s ** syncml, char *recv_msg, unsigned int recv_msg_length); +static sa_error_type_e __generate_msg_status_map_command(session_s ** session, sync_obj_s ** sync, GList ** commands, GList ** commands_last); +static sa_error_type_e __generate_msg_exist_sending_map_command(sync_agent_pb_protocol_binder_info_s * binder, session_s ** session, GList ** commands, GList ** commands_last); +static sa_error_type_e __generate_msg_changes_command(sync_agent_pb_protocol_binder_info_s * binder, session_s ** session, sync_obj_s ** sync, GList ** commands, GList ** commands_last, bool * is_need_next_msg); +static void __clean_up_sa(session_s * session); +static sa_error_type_e __process_jssion_id(session_s * session, GList * recv_header); +static sa_error_type_e __check_resume_session(session_s * session, bool * resume); + +static sa_error_type_e __get_account_info(int account_id, char **id, char **pwd, char **server_url, char **next_nonce) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + + if (!account_id) { + errorType = SA_INTERNAL_MISCONFIGURATION; + goto error; + } + + acc_err = sync_agent_create_fw_account(&fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_fw_account"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + acc_err = sync_agent_get_fw_account(account_id, &fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_update_fw_account"); + errorType = SA_INTERNAL_ERROR; + goto error; + } + + if (fw_account->email != NULL) + *id = strdup(fw_account->email); + + if (fw_account->password != NULL) + *pwd = strdup(fw_account->password); + + da_err = sync_agent_get_config_list(account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) { + if (config_data->value != NULL) + *server_url = strdup(config_data->value); + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE) == 0) { + if (config_data->value != NULL) + *next_nonce = strdup(config_data->value); + } + } + } + } + + error: + + sync_agent_free_fw_account(fw_account); + + sync_agent_free_config_list(config_list); + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _create_session(int account_id, char *session_id, bool server_flag, session_s ** session) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + char *id = NULL; + char *pwd = NULL; + char *targetUrl = NULL; + char *sourceUrl = NULL; + char *sourceName = NULL; + char *nextNonce = NULL; + chal_s *pTempChal = NULL; + unsigned int sessionID = 0; + + location_s *pSourceLocation = NULL; + location_s *pTargetLocation = NULL; + + if ((*session) != NULL) { + if ((*session)->chal != NULL) { + pTempChal = (*session)->chal; + (*session)->chal = NULL; + } + + if ((*session)->has_opend) + sessionID = (*session)->naci_session_id; + + free_session(*session); + *session = NULL; + } + + sync_agent_dev_return_e err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevID", &sourceUrl); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + _DEBUG_ERROR("failed to get devinfo"); + errorType = SA_INTERNAL_ERROR; + goto error; + } + + errorType = __get_account_info(account_id, &id, &pwd, &targetUrl, &nextNonce); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("faied in __get_accountinfo"); + goto error; + } + + if (server_flag == true) { + sourceName = id; + } + + errorType = create_location(sourceUrl, sourceName, &pSourceLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in create_location"); + goto error; + } + + errorType = create_location(targetUrl, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in create_location"); + goto error; + } + + /* create session info */ + errorType = create_session(VERSION_12, PROTOCOL_TYPE_DS, account_id, session_id, pSourceLocation, pTargetLocation, session); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create session"); + goto error; + } + + if (pTempChal != NULL) { + (*session)->chal = pTempChal; + pTempChal = NULL; + } + + (*session)->naci_session_id = sessionID; + + error: + + if (id != NULL) + free(id); + if (pwd != NULL) + free(pwd); + if (targetUrl != NULL) + free(targetUrl); + if (sourceUrl != NULL) + free(sourceUrl); + if (nextNonce != NULL) + free(nextNonce); + if (pTempChal != NULL) + free_chal(pTempChal); + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _generate_presync_msg(session_s * session, bool server_flag, char **msg, unsigned int *msg_size) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + char *id = NULL; + char *pwd = NULL; + char *targetUrl = NULL; + char *nextNonce = NULL; + char *credData = NULL; + char *decoded_nonce = NULL; + bool resume = false; + char *value = NULL; + alert_type_e alert_type = ALERT_UNKNOWN; + + /*pkg1 always has final tag */ + int isFinal = 1; + + sync_hdr_s *pSyncHdr = NULL; + cred_s *pCred = NULL; + devinf_s *devInfObj = NULL; + syncml_s *syncml = NULL; + + /*case SAN, MUST use sessionid from SAN message.. */ + if (session->session_id == NULL) { + session->session_id = g_strdup_printf("%ld", time(NULL)); + if (session->session_id == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + } + + errorType = __get_account_info(session->account_id, &id, &pwd, &targetUrl, &nextNonce); + if (errorType != SA_INTERNAL_OK) + goto error; + + _DEBUG_TRACE("id = %s", id); + _DEBUG_TRACE("pwd = %s", pwd); + _DEBUG_TRACE("sessionId = %s", session->session_id); + _DEBUG_TRACE("serverUrl = %s", targetUrl); + + /* set pkg status */ + session->pkg_status = SYNCML_PKG_1; + + chal_s *chal = session->chal; + auth_type_e authType; + format_type_e formatType = FORMAT_TYPE_UNKNOWN; + unsigned int nonce_size = 0; + if (chal == NULL) { + _DEBUG_TRACE("CHAL DOES NOT EXIST"); + if (nextNonce != NULL) { + /*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) { + _DEBUG_ERROR("failed to create cred string"); + goto error; + } + + errorType = create_cred(id, pwd, authType, formatType, credData, &pCred); + } else { + _DEBUG_TRACE("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) { + _DEBUG_ERROR("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) { + _DEBUG_ERROR("failed to create cred"); + goto error; + } + + set_session_cred(session, pCred); + pCred = NULL; + + /* create SyncHdr */ + errorType = create_sync_hdr(session, &pSyncHdr); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create synchdr"); + goto error; + } + + /* create devInf */ + errorType = create_devinf(session, &devInfObj); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create devInf"); + goto error; + } + + set_session_devinf(session, devInfObj); + + errorType = __check_resume_session(session, &resume); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in __check_resume_session"); + goto error; + } + + GList *commands = NULL; + GList *commands_last = NULL; + + char *sourceDevInf = NULL; + char *contentType = NULL; + + if (session->protocol_version == VERSION_10) + sourceDevInf = ELEMENT_DEVINF_10; + else if (session->protocol_version == VERSION_11) + sourceDevInf = ELEMENT_DEVINF_11; + else if (session->protocol_version == VERSION_12) + sourceDevInf = ELEMENT_DEVINF_12; + + if (COMMUNICATION_TYPE == SYNC_AGENT_PB_ENCODING_XML) + contentType = ELEMENT_DEVINF_XML; + else + contentType = ELEMENT_DEVINF_WBXML; + + if (resume != true) { + if (server_flag != true) { + /* create Put command */ + command_s *pPutCommand = NULL; + location_s *pLocation = NULL; + + errorType = create_location(sourceDevInf, NULL, &pLocation); + if (errorType != SA_INTERNAL_OK) + goto error; + + errorType = create_put_command(session, pLocation, contentType, devInfObj, &pPutCommand); + if (errorType != SA_INTERNAL_OK) + goto error; + put_into_list(&commands, &commands_last, pPutCommand); + } + } + + /* if it is not dive server */ + if (server_flag != true) { + /* create Get command */ + command_s *pGetCommand = NULL; + location_s *location = NULL; + errorType = create_location(sourceDevInf, NULL, &location); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + errorType = create_get_command(session, location, contentType, &pGetCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create get command"); + goto error; + } + put_into_list(&commands, &commands_last, pGetCommand); + } + + command_s *pAlertCommand = NULL; + location_s *pSourceLocation = NULL; + location_s *pTargetLocation = NULL; + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->client_sync_type) { + errorType = create_location(datastoreinfo_per_content_type[content_type]->source, NULL, &pSourceLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("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) { + _DEBUG_ERROR("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; + } + + _DEBUG_TRACE("datastoreinfo_per_content_type[%d]->id = %d", content_type, datastoreinfo_per_content_type[content_type]->id); + _DEBUG_TRACE("datastoreinfo_per_content_type[%d]->pw = %d", content_type, datastoreinfo_per_content_type[content_type]->pw); + + if (datastoreinfo_per_content_type[content_type]->id != NULL && datastoreinfo_per_content_type[content_type]->pw != NULL) { + + /*FIXME is there a nextNonce for datastore ?? */ + if (nextNonce != NULL) { + /*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) { + _DEBUG_ERROR("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; + } + } + + if (resume == true) + alert_type = ALERT_RESUME; + else + alert_type = datastoreinfo_per_content_type[content_type]->client_sync_type; + + errorType = create_alert_command(session, alert_type, + pSourceLocation, pTargetLocation, datastoreinfo_per_content_type[content_type]->last_anchor_client, datastoreinfo_per_content_type[content_type]->next_anchor_client, pCred, &pAlertCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create alert command"); + goto error; + } + } else + continue; + put_into_list(&commands, &commands_last, pAlertCommand); + } + } + + errorType = create_syncml(pSyncHdr, NULL, commands, isFinal, &syncml); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create syncml"); + goto error; + } + + session->is_sending_final = isFinal; + if (isFinal) + session->pkg_status = SYNCML_PKG_2; + + /* convert Msg */ + errorType = __object_binder(syncml, server_flag, msg, msg_size); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in objectBinder"); + goto error; + } + + /*free generate structure */ + free_syncml(syncml); + + if (id != NULL) + free(id); + if (pwd != NULL) + free(pwd); + if (targetUrl != NULL) + free(targetUrl); + if (nextNonce != NULL) + free(nextNonce); + if (value != NULL) + free(value); + if (pCred != NULL) + free_cred(pCred); + + _INNER_FUNC_EXIT; + return errorType; + + error: + + if (credData != NULL) + free(credData); + + if (id != NULL) + free(id); + if (pwd != NULL) + free(pwd); + if (targetUrl != NULL) + free(targetUrl); + if (nextNonce != NULL) + free(nextNonce); + if (value != NULL) + free(value); + if (syncml != NULL) + free_syncml(syncml); + if (pSyncHdr != NULL) + free_sync_hdr(pSyncHdr); + if (pCred != NULL) + free_cred(pCred); + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _generate_msg(session_s * session, void **sync_obj, bool server_flag, char **msg, unsigned int *msg_size) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + bool isNeedNextMsg = false; + + sync_agent_pb_protocol_binder_function_set_s *binder_function_set = NULL; + sync_agent_pb_protocol_binder_info_s *binder = NULL; + + sync_agent_pb_error_e err = init_oma_ds_1_2_binder_function_set(&binder_function_set); + + if (server_flag != true) + binder = oma_ds_1_2_binder_init(binder, COMMUNICATION_TYPE, false, false, false, true, false, binder_function_set); + else + binder = oma_ds_1_2_binder_init(binder, COMMUNICATION_TYPE, false, true, false, true, true, binder_function_set); + + /* create SyncHdr */ + sync_hdr_s *pSyncHdr = NULL; + errorType = create_sync_hdr(session, &pSyncHdr); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create synchdr"); + goto error; + } + + err = oma_ds_1_2_binder_append(binder, PE_SYNCML_START, NULL); + err = oma_ds_1_2_binder_append(binder, PE_HEADER, pSyncHdr); + err = oma_ds_1_2_binder_append(binder, PE_BODY_START, NULL); + + sync_obj_s **sync = (sync_obj_s **) sync_obj; + 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) { + _DEBUG_ERROR("failed in __generate_msg_status_map_command"); + goto error; + } + + /*append status command */ + GList *status_iter = NULL; + status_s *pStatus = NULL; + for (status_iter = session->status; status_iter != NULL; status_iter = g_list_next(status_iter)) { + pStatus = (status_s *) status_iter->data; + err = oma_ds_1_2_binder_append(binder, PE_STATUS, pStatus); + } + + /*append results command */ + GList *results_iter = NULL; + command_s *pResultsCommand = NULL; + for (results_iter = session->results_command; results_iter != NULL; results_iter = g_list_next(results_iter)) { + pResultsCommand = (command_s *) results_iter->data; + put_into_list(&commands, &commands_last, pResultsCommand); + err = oma_ds_1_2_binder_append(binder, PE_RESULTS_START, pResultsCommand); + + if (pResultsCommand->type == COMMAND_TYPE_RESULTS) { + if (pResultsCommand->private.results.item != NULL) { + if (pResultsCommand->private.results.item->data_type == ITEM_DEVINF) { + err = oma_ds_1_2_binder_append(binder, PE_DEVINF, pResultsCommand->private.results.item); + } + } + + err = oma_ds_1_2_binder_append(binder, PE_RESULTS_END, NULL); + } + } + + /*append map command */ + GList *map_iter = NULL; + command_s *pMapCommand = NULL; + for (map_iter = session->map_command; map_iter != NULL; map_iter = g_list_next(map_iter)) { + pMapCommand = (command_s *) map_iter->data; + err = oma_ds_1_2_binder_append(binder, PE_MAP, pMapCommand); + } + + /* free sendgStatus structure from SE */ + free_sending_statuses((*sync)->sending_status); + (*sync)->sending_status = NULL; + + if (session->pkg_status == SYNCML_PKG_3) { + + errorType = __generate_msg_exist_sending_map_command(binder, &session, &commands, &commands_last); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in __generate_msg_status_map_command"); + goto error; + } + + errorType = __generate_msg_changes_command(binder, &session, sync, &commands, &commands_last, &isNeedNextMsg); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in __generate_msg_status_map_command"); + goto error; + } + + if (!isNeedNextMsg) + isFinal = 1; + } + + if (session->pkg_status == SYNCML_PKG_5 && session->is_receiving_final) + isFinal = 1; + + /*if we have to send alert command(222,223 etc) */ + GList *alert_iter = NULL; + command_s *pAlertCommand = NULL; + for (alert_iter = session->alert_command; 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(binder, PE_ALERT, pAlertCommand); + } + + if (isFinal) + err = oma_ds_1_2_binder_append(binder, PE_FINAL, NULL); + + session->is_sending_final = isFinal; + + err = oma_ds_1_2_binder_append(binder, PE_BODY_END, NULL); + err = oma_ds_1_2_binder_append(binder, PE_SYNCML_END, NULL); + + oma_ds_1_2_binder_get_stream(binder, msg, msg_size); + _DEBUG_TRACE("final msg size = %d", *msg_size); + + /*FIXME for debugging */ + char *xml = NULL; + unsigned int xml_len = 0; + if (COMMUNICATION_TYPE == SYNC_AGENT_PB_ENCODING_XML) + set_xml_to_file(*msg, OMA_DS_MSG_PATH); + else { + err = sync_agent_get_xml_from_protocol_binder(binder, &xml, &xml_len); + if (err == SYNC_AGENT_PB_RETURN_OK) { + set_xml_to_file(xml, OMA_DS_MSG_PATH); + + if (xml != NULL) { + free(xml); + xml = NULL; + } + } + } + + oma_ds_1_2_binder_terminate(binder); + + if (session->pkg_status == SYNCML_PKG_3 && session->is_sending_final) + session->pkg_status = SYNCML_PKG_4; + else if (session->pkg_status == SYNCML_PKG_5 && session->is_sending_final) + session->pkg_status = SYNCML_PKG_6; + + free_sync_hdr(pSyncHdr); + if (session->status != NULL) { + if (session->suspend_status != NULL) { + free_statuses(session->suspend_status); + session->suspend_status = NULL; + } + session->suspend_status = static_session->status; + session->status = NULL; + } + free_commands(commands); + + session->alert_command = NULL; + session->results_command = NULL; + + _INNER_FUNC_EXIT; + return errorType; + + error: + + free_sync_hdr(pSyncHdr); + if (session->status != NULL) { + free_statuses(session->status); + session->status = NULL; + } + free_commands(commands); + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e __generate_msg_status_map_command(session_s ** session, sync_obj_s ** sync, GList ** commands, GList ** commands_last) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + + GList *iter = NULL; + sending_status_s *sendingStatus = NULL; + /* send status of sync, add, replace, delete command */ + for (iter = (*sync)->sending_status; iter != NULL; iter = g_list_next(iter)) { + sendingStatus = (iter->data); + + int needMap = 0; + GList *sendingIter = NULL; + applied_status_s *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_s *status = NULL; + for (statusIter = (*session)->temp_status; 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->source_ref != NULL) { + /*add command */ + sync_agent_da_mapping_s *mapping = NULL; + da_err = sync_agent_create_mapping(&mapping); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_mapping !!"); + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_da_get_mapping_query_s query; + query.account_id = (*session)->account_id; + query.luid = appliedStatus->luid; + + da_err = sync_agent_get_mapping(&query, &mapping); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_mapping !!"); + errorType = SA_INTERNAL_DA_ERROR; + sync_agent_free_mapping(mapping); + goto error; + } + + if (mapping != NULL) { + if (mapping->guid == NULL) { + errorType = SA_INTERNAL_DA_ERROR; + _DEBUG_ERROR("failed to get guid"); + sync_agent_free_mapping(mapping); + goto error; + } + + if (strcmp(mapping->guid, get_location_loc_uri(status->source_ref)) == 0) { + if (status->data != NULL) { + free(status->data); + status->data = NULL; + } + status->data = g_strdup_printf("%d", appliedStatus->status); + /*move to status list from tempStatus */ + (*session)->status = g_list_append((*session)->status, status); + (*session)->temp_status = g_list_remove((*session)->temp_status, status); + + sync_agent_free_mapping(mapping); + + break; + } + + sync_agent_free_mapping(mapping); + + } else { + _DEBUG_ERROR("mapping is NULL !!"); + errorType = SA_INTERNAL_DA_ERROR; + sync_agent_free_mapping(mapping); + goto error; + } + } + + if (status->target_ref != NULL) { + /*replace, delete */ + if (strcmp(appliedStatus->luid, get_location_loc_uri(status->target_ref)) == 0) { + if (status->data != NULL) { + free(status->data); + status->data = NULL; + } + status->data = g_strdup_printf("%d", appliedStatus->status); + /*move to status list from tempStatus */ + (*session)->status = g_list_append((*session)->status, status); + (*session)->temp_status = g_list_remove((*session)->temp_status, status); + break; + } + } + } + } + } + + if (needMap) { + /* create map command */ + command_s *mapCommand = NULL; + location_s *pSourceLocation = NULL; + location_s *pTargetLocation = NULL; + errorType = create_location(sendingStatus->source, NULL, &pSourceLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + errorType = create_location(sendingStatus->target, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + errorType = create_map_command(*session, pSourceLocation, pTargetLocation, &mapCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create map command"); + goto error; + } + + GList *sendingIter = NULL; + applied_status_s *appliedStatus = NULL; + + for (sendingIter = sendingStatus->items; sendingIter != NULL; sendingIter = g_list_next(sendingIter)) { + appliedStatus = (sendingIter->data); + + if (appliedStatus->change_type == CHANGE_ADD) { + + if (appliedStatus->status == ITEM_ADDED) { + item_s *temp = create_item(); + if (temp == NULL) { + _DEBUG_ERROR("failed to create item"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + errorType = create_location(appliedStatus->luid, NULL, &pSourceLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + sync_agent_da_mapping_s *mapping = NULL; + da_err = sync_agent_create_mapping(&mapping); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_mapping !!"); + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_da_get_mapping_query_s query; + query.account_id = (*session)->account_id; + query.luid = appliedStatus->luid; + + da_err = sync_agent_get_mapping(&query, &mapping); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_mapping !!"); + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + if (mapping != NULL) { + if (mapping->guid == NULL) { + errorType = SA_INTERNAL_DA_ERROR; + _DEBUG_ERROR("failed to get guid"); + goto error; + } + errorType = create_location(mapping->guid, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + if (mapping->guid != NULL) { + free(mapping->guid); + mapping->guid = NULL; + } + } else { + _DEBUG_ERROR("mapping is NULL !!"); + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + set_item_source(temp, pSourceLocation); + set_item_target(temp, pTargetLocation); + set_map_command_item(mapCommand, temp); + } else { + sync_agent_da_delete_mapping_query_s query; + query.option = SYNC_AGENT_DA_DELETE_MAPPING_OPTION_LUID; + query.account_id = (*session)->account_id; + query.luid = appliedStatus->luid; + + da_err = sync_agent_delete_mapping(&query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + errorType = SA_INTERNAL_DA_ERROR; + _DEBUG_ERROR("failed in sync_agent_delete_mapping !!"); + goto error; + } + } + } + } + put_into_list(commands, commands_last, mapCommand); + (*session)->map_command = g_list_append((*session)->map_command, mapCommand); + increase_command_ref_count(mapCommand); + } + } + + error: + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e __generate_msg_exist_sending_map_command(sync_agent_pb_protocol_binder_info_s * binder, session_s ** session, GList ** commands, GList ** commands_last) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK; + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + + /*if there is something in the mapping_tbl it have to be sent before sync command */ + int existSendingMap = sync_agent_is_exist_mapping_by_account_id((*session)->account_id); + + if (existSendingMap) { + GList *mapping_list = NULL; + sync_agent_da_get_mapping_list_query_s query; + query.option = SYNC_AGENT_DA_GET_MAPPING_LIST_OPTION_ACCOUNT_ID; + query.account_id = (*session)->account_id; + + ret = sync_agent_get_mapping_list(&query, &mapping_list); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_mapping_list !!"); + errorType = SA_INTERNAL_ERROR; + goto error; + } + + location_s *pSourceLocation = NULL; + location_s *pTargetLocation = NULL; + + bool exist = false; + int content_type; + sync_agent_da_mapping_s *mapping_data = (sync_agent_da_mapping_s *) ((GList *) (g_list_nth(mapping_list, g_list_length(mapping_list) - 1))->data); + int lastItemTypeId = mapping_data->data_store_id; + + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + _DEBUG_VERBOSE("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]->client_sync_type) { + if (lastItemTypeId == 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) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + errorType = create_location(datastoreinfo_per_content_type[content_type]->target, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + exist = true; + break; + } + } + } + } + + if (exist == false) { + _DEBUG_VERBOSE("Mapping data is not equal with any synchronizing datastore id"); + goto error; + } + + /* create map command using first item */ + command_s *mapCommand = NULL; + errorType = create_map_command(*session, pSourceLocation, pTargetLocation, &mapCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create map command"); + goto error; + } + + GList *iter = NULL; + sync_agent_da_mapping_s *iter_data; + for (iter = mapping_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = (sync_agent_da_mapping_s *) (iter->data); + + if (lastItemTypeId != iter_data->data_store_id) { + err = oma_ds_1_2_binder_append(binder, PE_MAP, mapCommand); + put_into_list(commands, commands_last, mapCommand); + (*session)->map_command = g_list_append((*session)->map_command, mapCommand); + increase_command_ref_count(mapCommand); + + bool exist = false; + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->client_sync_type) { + if (lastItemTypeId == 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) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + errorType = create_location(datastoreinfo_per_content_type[content_type]->target, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + exist = true; + break; + } + } + } + } + if (exist == false) { + _DEBUG_ERROR("Mapping data is not equal with any synchronizing datastore id"); + goto error; + } + } + + lastItemTypeId = iter_data->data_store_id; + item_s *temp = create_item(); + if (temp == NULL) { + _DEBUG_ERROR("failed to create item"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + errorType = create_location(iter_data->luid, NULL, &pSourceLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + errorType = create_location(iter_data->guid, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + set_item_source(temp, pSourceLocation); + set_item_target(temp, pTargetLocation); + set_map_command_item(mapCommand, temp); + } + + sync_agent_free_mapping_list(mapping_list); + + err = oma_ds_1_2_binder_append(binder, PE_MAP, mapCommand); + put_into_list(commands, commands_last, mapCommand); + (*session)->map_command = g_list_append((*session)->map_command, mapCommand); + increase_command_ref_count(mapCommand); + } + + error: + + _INNER_FUNC_EXIT; + return errorType; + +} + +static sa_error_type_e __generate_msg_changes_command(sync_agent_pb_protocol_binder_info_s * binder, session_s ** session, sync_obj_s ** sync, GList ** commands, GList ** commands_last, bool * is_need_next_msg) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + sync_agent_da_service_item_s *service_item = NULL; + sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_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_s *syncCommand = NULL; + changed_datastore_s *changedDatastore = NULL; + bool needNextMsg = false; + for (iter = (*sync)->changed_datastore; iter != NULL; iter = g_list_next(iter)) { + changedDatastore = (iter->data); + + if (changedDatastore->need_sync_command) { + /* create sync Command */ + location_s *pSourceLocation = NULL; + location_s *pTargetLocation = NULL; + errorType = create_location(changedDatastore->source, NULL, &pSourceLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + errorType = create_location(changedDatastore->target, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + errorType = create_sync_start_command(*session, pSourceLocation, pTargetLocation, &syncCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create sync start command"); + goto error; + } + + /*set numberOfChanges */ + if (changedDatastore->has_number_of_changes) { + /*if it is first sync command set numberOfChanges */ + set_sync_start_command_number_of_changes(syncCommand, changedDatastore->number_of_changes); + changedDatastore->has_number_of_changes = 0; + } + + /*set Mem */ + /* TODO get current datastore dynamic memory size & recods */ + /* And set Mem structure */ + /*Mem *mem = create_mem(); + set_mem_sharedmem(mem, 1); + set_mem_freemem(mem, 8100); + set_mem_freeid(mem, 81); + set_sync_start_command_mem(syncCommand, mem); */ + + err = oma_ds_1_2_binder_append(binder, PE_SYNC_START, syncCommand); + put_into_list(commands, commands_last, syncCommand); + + GList *itemIter = NULL; + command_s *changeCommand = NULL; + changed_item_s *changedItem = NULL; + oma_ds_protocol_element_e protocol_element = PE_UNDEF; + for (itemIter = changedDatastore->change_item; itemIter != NULL;) { + changedItem = (itemIter->data); + + oma_ds_1_2_binder_get_stream_size(binder, &stream_size); + _DEBUG_VERBOSE("stream_size = %d", stream_size); + _DEBUG_VERBOSE("(*session)->targetMaxMsgSize = %d", (*session)->target_max_msg_size); + + if ((*session)->target_max_msg_size > stream_size) { + /*there is a space for command */ + if (changedItem->change_type == CHANGE_DELETE) { + /* create delete Command */ + errorType = create_delete_command(*session, changedItem->change_type, changedItem->luid, changedItem->content_type, &changeCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create delete command"); + goto error; + } + } else { + int isFirstLargeObj; + if (changedItem->data == NULL) { + char *folderId = NULL; + GList *list = NULL; + sync_agent_da_get_folder_id_list_query_s query; + query.option = SYNC_AGENT_DA_GET_FOLDER_ID_OPTION_FOLDER_TYPE_ID; + query.account_id = (*session)->account_id; + query.item_type_id = datastoreinfo_per_content_type[changedItem->index_of_datastore]->datastore_id; + query.folder_type_id = datastoreinfo_per_content_type[changedItem->index_of_datastore]->folder_type_id; + + da_err = sync_agent_get_folder_id_list(&query, &list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_get_folder_id_list_inferface() failed !!"); + goto error; + } + + if (g_list_length(list) > 0) { + GList *iter = g_list_nth(list, 0); + folderId = (char *)(iter->data); + } else { + _DEBUG_ERROR("failed to get folderId"); + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + _DEBUG_VERBOSE("datastoreinfo_per_content_type[%d]->datastore_id = %d", changedItem->index_of_datastore, datastoreinfo_per_content_type[changedItem->index_of_datastore]->datastore_id); + _DEBUG_VERBOSE("account_id = %d", (*session)->account_id); + _DEBUG_VERBOSE("folderId = %s", folderId); + _DEBUG_VERBOSE("changedItem->luid = %s", changedItem->luid); + + da_err = sync_agent_create_service_item(&service_item); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + errorType = SA_INTERNAL_DA_ERROR; + _DEBUG_ERROR("failed in sync_agent_create_service_item() = %d", da_err); + goto error; + } + + da_err = sync_agent_get_service_item(changedItem->luid, &service_item); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + errorType = SA_INTERNAL_DA_ERROR; + _DEBUG_ERROR("failed in sync_agent_get_service_item() = %d", da_err); + goto error; + } + data = g_strdup((char *)(service_item->data)); + + _DEBUG_VERBOSE("data = %s", data); + sync_agent_free_folder_id_list(list); + if (data == NULL) { + da_err = sync_agent_delete_item(changedItem->luid, 1); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_delete_item !!"); + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + itemIter = g_list_next(itemIter); + changedDatastore->change_item = g_list_remove(changedDatastore->change_item, changedItem); + free_changed_item(changedItem); + continue; + } + + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_service_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); + + _DEBUG_VERBOSE("sizeOfData = %d", sizeOfData); + if ((*session)->target_max_msg_size < stream_size + sizeOfData) { + /*can be LargeObj */ + int availableSize = (*session)->target_max_msg_size - stream_size; + if ((*session)->remote_devinf->supports_large_objs /*&& availableSize > session->targetMaxMsgSize / 50 */ ) { + + /*if server support LargeObj & clearly LargeObj */ + sendingData = calloc(availableSize + 1, sizeof(char)); + if (sendingData == NULL) { + _DEBUG_ERROR("failed to allocate sendingData"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + memcpy(sendingData, data, availableSize); + _DEBUG_VERBOSE("sendingData = %s", sendingData); + _DEBUG_VERBOSE("sendingData size = %d", strlen(sendingData)); + + char *remainingData = calloc(sizeOfData - availableSize + 1, sizeof(char)); + if (remainingData == NULL) { + _DEBUG_ERROR("failed to allocate remainingData"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + memcpy(remainingData, data + availableSize, sizeOfData - availableSize); + _DEBUG_VERBOSE("sizeOfData - availableSize = %d", sizeOfData - availableSize); + _DEBUG_VERBOSE("remainingData = %s", remainingData); + _DEBUG_VERBOSE("remainingData size = %d", strlen(remainingData)); + + if (changedItem->data != NULL) + free(changedItem->data); + + set_changed_item_data(changedItem, remainingData); + free(remainingData); + + command_status_s *pTemp = NULL; + errorType = create_command_status((*session)->msg_id, (*session)->cmd_id, &pTemp); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create pending status"); + goto error; + } + (*session)->large_obj = pTemp; + + if (changedItem->change_type == CHANGE_ADD) { + /* create add Command */ + errorType = create_add_command(*session, changedItem->change_type, changedItem->luid, changedItem->content_type, sendingData, isFirstLargeObj == 1 ? sizeOfData : 0, 1, &changeCommand); + } else if (changedItem->change_type == CHANGE_REPLACE) { + /* create replace Command */ + errorType = create_replace_command(*session, changedItem->change_type, changedItem->luid, + changedItem->content_type, sendingData, isFirstLargeObj == 1 ? sizeOfData : 0, 1, &changeCommand); + } + + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("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->change_type == CHANGE_ADD) { + /* create add Command */ + errorType = create_add_command(*session, changedItem->change_type, changedItem->luid, changedItem->content_type, data, 0, 0, &changeCommand); + } else if (changedItem->change_type == CHANGE_REPLACE) { + /* create replace Command */ + errorType = create_replace_command(*session, changedItem->change_type, changedItem->luid, changedItem->content_type, data, 0, 0, &changeCommand); + } + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("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(binder, protocol_element, changeCommand); + oma_ds_1_2_binder_get_stream_size(binder, &stream_size); + _DEBUG_VERBOSE("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->sent_item = g_list_append(changedDatastore->sent_item, changedItem); + changedDatastore->change_item = g_list_remove(changedDatastore->change_item, changedItem); + } else { + needNextMsg = true; + break; + } + + if (data != NULL) { + free(data); + data = NULL; + } + } + + /* create sync end Command */ + errorType = create_sync_end_command(&syncCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create sync end command"); + goto error; + } + err = oma_ds_1_2_binder_append(binder, PE_SYNC_END, syncCommand); + put_into_list(commands, commands_last, syncCommand); + + if (needNextMsg) + break; + + int chageItemCount = g_list_length(changedDatastore->change_item); + if (chageItemCount == 0) + changedDatastore->need_sync_command = 0; + } + } + + *is_need_next_msg = needNextMsg; + + error: + + if (sendingData != NULL) { + free(sendingData); + sendingData = NULL; + } + + if (data != NULL) { + free(data); + data = NULL; + } + + if (service_item != NULL) { + sync_agent_free_service_item(service_item); + } + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _generate_suspend_msg(session_s * session, bool server_flag, char **msg, unsigned int *msg_size) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + char *id = NULL; + char *pwd = NULL; + char *sourceUrl = NULL; + char *targetUrl = NULL; + char *nextNonce = NULL; + + sync_hdr_s *pSyncHdr = NULL; + syncml_s *syncml = NULL; + + GList *commands = NULL; + GList *commands_last = NULL; + + command_s *pAlertCommand = NULL; + location_s *pSourceLocation = NULL; + location_s *pTargetLocation = NULL; + + /* change pkgstatus tp SYNCML_SUSPEND */ + session->pkg_status = SYNCML_SUSPEND; + + sync_agent_dev_return_e err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevID", &sourceUrl); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + _DEBUG_ERROR("failed to get devinfo"); + errorType = SA_INTERNAL_ERROR; + goto error; + } + + errorType = __get_account_info(session->account_id, &id, &pwd, &targetUrl, &nextNonce); + if (errorType != SA_INTERNAL_OK) + goto error; + + _DEBUG_TRACE("id = %s", id); + _DEBUG_TRACE("pwd = %s", pwd); + _DEBUG_TRACE("clientUrl = %s", sourceUrl); + _DEBUG_TRACE("serverUrl = %s", targetUrl); + _DEBUG_TRACE("nextNonce = %s", nextNonce); + + /* create SyncHdr */ + errorType = create_sync_hdr(session, &pSyncHdr); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create synchdr"); + goto error; + } + +/* Command *pMapCommand = NULL; + GList *iter = NULL; + for (iter = session->mapCommand; iter != NULL; iter = g_list_next(iter)) { + pMapCommand = (Command *)iter->data; + put_into_list(&commands, &commands_last, pMapCommand); + increase_command_refcount(pMapCommand); + }*/ + + errorType = create_location(targetUrl, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("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(sourceUrl, NULL, &pSourceLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("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_alert_command(session, ALERT_SUSPEND, pSourceLocation, pTargetLocation, NULL, NULL, NULL, &pAlertCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create alert command"); + goto error; + } + + put_into_list(&commands, &commands_last, pAlertCommand); + + errorType = create_syncml(pSyncHdr, session->suspend_status, commands, 0, &syncml); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create syncml"); + goto error; + } + + /* convert Msg */ + errorType = __object_binder(syncml, server_flag, msg, msg_size); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in objectBinder"); + goto error; + } + + /*free generate structure */ + free_syncml(syncml); + session->suspend_status = NULL; + + if (id != NULL) + free(id); + if (pwd != NULL) + free(pwd); + if (sourceUrl != NULL) + free(sourceUrl); + if (targetUrl != NULL) + free(targetUrl); + if (nextNonce != NULL) + free(nextNonce); + + _INNER_FUNC_EXIT; + return errorType; + + error: + + if (id != NULL) + free(id); + if (pwd != NULL) + free(pwd); + if (sourceUrl != NULL) + free(sourceUrl); + if (targetUrl != NULL) + free(targetUrl); + if (nextNonce != NULL) + free(nextNonce); + if (syncml != NULL) + free_syncml(syncml); + if (pSyncHdr != NULL) + free_sync_hdr(pSyncHdr); + + session->suspend_status = NULL; + + _INNER_FUNC_EXIT; + return errorType; + +} + +static sa_error_type_e _exchange_msg(session_s * session, char *acc_type, int transport_type, char *send_msg, unsigned int send_msg_length, char **recv_msg, unsigned int *recv_msg_length) +{ + _INNER_FUNC_ENTER; + + sync_agent_na_result_e res = SYNC_AGENT_NA_SUCCESS; + sa_error_type_e errorType = SA_INTERNAL_OK; + bool isXML; + char *targetUri = NULL; + char *jsessionId = NULL; + GList *header_info = NULL; + GList *recv_header = NULL; + + if (session != NULL) { + if (session->target != NULL) + targetUri = session->target->loc_uri; + + if (session->jsession_id != NULL) + jsessionId = session->jsession_id; + } else { + _DEBUG_ERROR("session is NULL !"); + errorType = SA_INTERNAL_ERROR; + goto error; + } + + if (COMMUNICATION_TYPE == SYNC_AGENT_PB_ENCODING_XML) + isXML = true; + else + isXML = false; + + na_http_header_binder(acc_type, targetUri, isXML, jsessionId, &header_info); + res = sync_agent_send_msg( /*acc_info (id, pw, uri, ...), */ + header_info, transport_type, send_msg, send_msg_length, &recv_header, (unsigned char **)recv_msg, recv_msg_length, SYNC_AGENT_NA_SEND_TYPE_SEND_N_RECEIVE, session->naci_session_id); + + if (res != SYNC_AGENT_NA_SUCCESS) { + _DEBUG_ERROR("res = %d", res); + if (res == SYNC_AGENT_NA_SEND_MSG_CANCEL) + errorType = SA_INTERNAL_CANCEL; + else + errorType = SA_INTERNAL_CONNECTION_ERROR; + goto error; + } + + __process_jssion_id(session, recv_header); + + error: + + if (recv_header != NULL) { + GList *iter = NULL; + sync_agent_na_common_header_info_s *iter_data; + for (iter = recv_header; iter != NULL;) { + iter_data = NULL; + iter_data = ((sync_agent_na_common_header_info_s *) (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); + } + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _process_recv_msg(session_s * session, char *recv_msg, unsigned int recv_msg_length, int only_from_client, void **sync_return_obj, int *is_finish) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + reset_cmd_id_session(session); + + syncml_s *syncml = (syncml_s *) calloc(1, sizeof(syncml_s)); + if (syncml == NULL) { + _DEBUG_ERROR("failed to allocate syncml"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + GList *pReturnStatus = NULL; + GList *pReturnDatastore = NULL; + + errorType = __reverse_object_binder(&syncml, recv_msg, recv_msg_length); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in reverseObjectBinder"); + goto error; + } + + /* check receive msg */ + errorType = receive_header(session, syncml->hdr); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in receive_Header"); + goto error; + } + + errorType = receive_statuses(session, syncml->status, &pReturnStatus); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in receive_Statuses"); + goto error; + } + + errorType = receive_commands(session, syncml->commands, false, &pReturnDatastore); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in receive_Commands"); + goto error; + } + + /* do not need to update pkgstatus when suspend */ + if (session->pkg_status == SYNCML_SUSPEND) { + _DEBUG_TRACE("Suspend"); + __clean_up_sa(session); + static_session = NULL; + goto error; + } + + if (syncml->final) { + session->is_sending_final = 0; + session->is_receiving_final = 1; + } else + session->is_receiving_final = 0; + + if (session->pkg_status == SYNCML_PKG_2) { + pre_sync_return_obj_s **pre = (pre_sync_return_obj_s **) sync_return_obj; + + if ((*pre) != NULL) + (*pre)->datastore_info = pReturnDatastore; + + if (session->remote_devinf != NULL) { + if (session->remote_devinf->dev_id != NULL) + (*pre)->dev_id = strdup(session->remote_devinf->dev_id); + } + } else { + sync_return_obj_s **syncReturn = (sync_return_obj_s **) sync_return_obj; + + if ((*syncReturn) != NULL) { + (*syncReturn)->status = pReturnStatus; + (*syncReturn)->changed_datastore = pReturnDatastore; + } + } + + if (session->pkg_status == SYNCML_PKG_2 && session->is_receiving_final) + session->pkg_status = SYNCML_PKG_3; + else if (session->pkg_status == SYNCML_PKG_4 && session->is_receiving_final) { + if (only_from_client) { + *is_finish = 1; + __clean_up_sa(session); + static_session = NULL; + } else + session->pkg_status = SYNCML_PKG_5; + } else if (session->pkg_status == SYNCML_PKG_6 && session->is_receiving_final) { + *is_finish = 1; + __clean_up_sa(session); + static_session = NULL; + } + + error: + + if (syncml != NULL) + free_syncml(syncml); + + _INNER_FUNC_EXIT; + return errorType; + +} + +static sa_error_type_e _generate_autoconfigure_msg(char *id, char *pwd, char *target_url, char **msg, unsigned int *msg_size, session_s * session) +{ + _INNER_FUNC_ENTER; + _DEBUG_TRACE("id = %s, pwd = %s, target_url = %s", id, pwd, target_url); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + int isFinal = 1; + char *credData = NULL; + cred_s *pCred = NULL; + sync_hdr_s *pSyncHdr = NULL; + syncml_s *syncml = 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) { + _DEBUG_ERROR("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) { + _DEBUG_ERROR("failed to create cred"); + goto error; + } + + if (credData != NULL) { + free(credData); + credData = NULL; + } + + set_session_cred(session, pCred); + + errorType = create_sync_hdr(session, &pSyncHdr); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create synchdr"); + goto error; + } + + char *sourceDevInf = NULL; + if (session->protocol_version == VERSION_10) + sourceDevInf = ELEMENT_DEVINF_10; + else if (session->protocol_version == VERSION_11) + sourceDevInf = ELEMENT_DEVINF_11; + else if (session->protocol_version == VERSION_12) + sourceDevInf = ELEMENT_DEVINF_12; + + location_s *pLocation = NULL; + errorType = create_location(sourceDevInf, NULL, &pLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create location"); + goto error; + } + + char *contentType = NULL; + if (COMMUNICATION_TYPE == SYNC_AGENT_PB_ENCODING_XML) + contentType = ELEMENT_DEVINF_XML; + else + contentType = ELEMENT_DEVINF_WBXML; + + /* create Get command */ + command_s *pGetCommand = NULL; + errorType = create_get_command(session, pLocation, contentType, &pGetCommand); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to get command"); + goto error; + } + put_into_list(&commands, &commands_last, pGetCommand); + + errorType = create_syncml(pSyncHdr, NULL, commands, isFinal, &syncml); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to get syncml"); + goto error; + } + + errorType = __object_binder(syncml, false, msg, msg_size); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in objectBinder"); + goto error; + } + + /*free generate structure */ + free_syncml(syncml); + syncml = NULL; + + _INNER_FUNC_EXIT; + return errorType; + + error: + if (pSyncHdr != NULL) + free_sync_hdr(pSyncHdr); + if (pCred != NULL) + free_cred(pCred); + if (credData != NULL) + free(credData); + if (commands != NULL) + free_commands(commands); + if (syncml != NULL) + free(syncml); + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _process_autoconfigure_recv_msg(char *recv_msg, unsigned int recv_msg_length, session_s * session) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + syncml_s *syncml = (syncml_s *) calloc(1, sizeof(syncml_s)); + if (syncml == NULL) { + _DEBUG_ERROR("failed to allocate syncml"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + errorType = __reverse_object_binder(&syncml, recv_msg, recv_msg_length); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in reverseObjectBinder"); + goto error; + } + + /* check receive msg */ + errorType = receive_header(session, syncml->hdr); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in receive_Header"); + goto error; + } + + errorType = receive_statuses(session, syncml->status, NULL); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in receive_Statuses"); + goto error; + } + + errorType = receive_commands(session, syncml->commands, true, NULL); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in receive_Commands"); + goto error; + } + + error: + + if (syncml != NULL) + free_syncml(syncml); + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e __object_binder(syncml_s * syncml, bool server_flag, char **msg, unsigned int *msg_size) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + sync_agent_pb_protocol_binder_function_set_s *binder_function_set = NULL; + + sync_agent_pb_error_e err = init_oma_ds_1_2_binder_function_set(&binder_function_set); + + sync_agent_pb_protocol_binder_info_s *binder = NULL; + char *xml = NULL; + unsigned int xml_len = 0; + + if (server_flag != true) + binder = oma_ds_1_2_binder_init(binder, COMMUNICATION_TYPE, false, false, false, true, false, binder_function_set); + else + binder = oma_ds_1_2_binder_init(binder, COMMUNICATION_TYPE, false, true, false, true, true, binder_function_set); + + err = oma_ds_1_2_binder_append(binder, PE_SYNCML_START, NULL); + err = oma_ds_1_2_binder_append(binder, PE_HEADER, syncml->hdr); + err = oma_ds_1_2_binder_append(binder, PE_BODY_START, NULL); + + GList *status_iter = NULL; + status_s *pStatus = NULL; + for (status_iter = syncml->status; status_iter != NULL; status_iter = g_list_next(status_iter)) { + pStatus = status_iter->data; + err = oma_ds_1_2_binder_append(binder, PE_STATUS, pStatus); + } + + GList *iter = NULL; + command_s *pCommand = NULL; + oma_ds_protocol_element_e protocol_element = PE_UNDEF; + for (iter = syncml->commands; iter != NULL; iter = g_list_next(iter)) { + pCommand = (command_s *) (iter->data); + + command_type_e 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(binder, protocol_element, pCommand); + + if (type == COMMAND_TYPE_RESULTS) { + err = oma_ds_1_2_binder_append(binder, PE_RESULTS_END, NULL); + } + + if (type == COMMAND_TYPE_PUT) { + if (pCommand->private.access.item != NULL) { + if (pCommand->private.access.item->private.devinf != NULL) { + err = oma_ds_1_2_binder_append(binder, PE_DEVINF, pCommand->private.access.item); + } + } + err = oma_ds_1_2_binder_append(binder, PE_PUT_END, NULL); + } + } + + if (syncml->final) { + err = oma_ds_1_2_binder_append(binder, PE_FINAL, NULL); + } + + err = oma_ds_1_2_binder_append(binder, PE_BODY_END, NULL); + err = oma_ds_1_2_binder_append(binder, PE_SYNCML_END, NULL); + + oma_ds_1_2_binder_get_stream(binder, msg, msg_size); + + /*FIXME for debugging */ + if (COMMUNICATION_TYPE == SYNC_AGENT_PB_ENCODING_XML) + set_xml_to_file(*msg, OMA_DS_MSG_PATH); + else { + err = sync_agent_get_xml_from_protocol_binder(binder, &xml, &xml_len); + if (err == SYNC_AGENT_PB_RETURN_OK) { + set_xml_to_file(xml, OMA_DS_MSG_PATH); + + if (xml != NULL) { + free(xml); + xml = NULL; + } + } + } + + oma_ds_1_2_binder_terminate(binder); + + if (err != SYNC_AGENT_PB_RETURN_OK) + errorType = SA_INTERNAL_BINDER_ERROR; + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e __reverse_object_binder(syncml_s ** syncml, char *recv_msg, unsigned int recv_msg_length) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + sync_agent_pb_protocol_binder_function_set_s *binder_function_set = NULL; + + sync_agent_pb_error_e err = init_oma_ds_1_2_binder_function_set(&binder_function_set); + sync_agent_pb_protocol_binder_reverse_info_s *binder = NULL; + char *xml = NULL; + unsigned int xml_len = 0; + + sync_agent_pb_decoding_e dec; + if (COMMUNICATION_TYPE == SYNC_AGENT_PB_ENCODING_XML) + dec = SYNC_AGENT_PB_DECODING_XML; + else + dec = SYNC_AGENT_PB_DECODING_WBXML; + + err = reverse_oma_ds_1_2_binder_init(recv_msg, recv_msg_length, dec, binder_function_set, NULL, &binder); + + if (err != SYNC_AGENT_PB_RETURN_OK) { + errorType = SA_INTERNAL_BINDER_ERROR; + _DEBUG_ERROR("reverse_oma_ds_1_2_binder_init error =%d", err); + return errorType; + } + + /*FIXME for debugging */ + if (COMMUNICATION_TYPE == SYNC_AGENT_PB_ENCODING_XML) + set_xml_to_file(recv_msg, OMA_DS_MSG_PATH); + else { + err = sync_agent_get_xml_from_reverse_protocol_binder(binder, &xml, &xml_len); + if (err == SYNC_AGENT_PB_RETURN_OK) { + set_xml_to_file(xml, OMA_DS_MSG_PATH); + + if (xml != NULL) { + free(xml); + xml = NULL; + } + } + } + + oma_ds_protocol_element_e protocol_element = PE_UNDEF; + char *protocol_element_name = NULL; + Content_Ptr pContent = NULL; + command_s *tempCommandfordevInf = NULL; + while (err == SYNC_AGENT_PB_RETURN_OK) { + protocol_element = PE_UNDEF; + err = reverse_oma_ds_1_2_binder_next(binder, &protocol_element, &protocol_element_name, &pContent); + switch (protocol_element) { + case PE_ADD: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + break; + case PE_ATOMIC_START: + case PE_ATOMIC_END: + case PE_COPY: + case PE_DELETE: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + break; + case PE_EXEC: + case PE_GET: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + break; + case PE_MAP: + case PE_PUT_START: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + tempCommandfordevInf = pContent; + break; + case PE_SEARCH: + case PE_SEQUENCE_START: + case PE_SEQUENCE_END: + case PE_SYNC_START: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + break; + case PE_SYNC_END: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + protocol_element = PE_UNDEF; + break; + case PE_REPLACE: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + break; + case PE_ALERT: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + break; + case PE_RESULTS_START: + (*syncml)->commands = g_list_append((*syncml)->commands, pContent); + tempCommandfordevInf = pContent; + break; + case PE_STATUS: + (*syncml)->status = g_list_append((*syncml)->status, pContent); + protocol_element = PE_UNDEF; + break; + case PE_HEADER: + (*syncml)->hdr = pContent; + sync_agent_set_user_data_in_reverse_protocol_binder(binder, (*syncml)->hdr); + break; + case PE_PUT_GET: + case PE_CMD_GROUP: + case PE_GENERIC: + case PE_FINAL: + (*syncml)->final = (int)pContent; + break; + case PE_DEVINF: + if (tempCommandfordevInf != NULL) { + 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 == SYNC_AGENT_PB_RETURN_HAS_NO_MORE_ELEMENT) { + break; + } + } + + sync_agent_destroy_reverse_protocol_binder(binder); + + free_oma_ds_1_2_binder_function_set(binder_function_set); + + if (err != SYNC_AGENT_PB_RETURN_OK && err != SYNC_AGENT_PB_RETURN_HAS_NO_MORE_ELEMENT) + errorType = SA_INTERNAL_BINDER_ERROR; + + _INNER_FUNC_EXIT; + return errorType; +} + +static common_error_type_e _convert_error_type(sa_error_type_e error_type) +{ + _INNER_FUNC_ENTER; + + common_error_type_e sa_errorType = COMMON_OK; + + if (error_type == SA_INTERNAL_OK) + sa_errorType = COMMON_OK; + else if (error_type == SA_INTERNAL_MISCONFIGURATION) + sa_errorType = COMMON_MISCONFIGURATION; + else if (error_type == SA_INTERNAL_AUTHENTICATION_ERROR) + sa_errorType = COMMON_AUTHENTICATION_ERROR; + else if (error_type == SA_INTERNAL_NOT_FOUND) + sa_errorType = COMMON_NOT_FOUND; + else if (error_type == SA_INTERNAL_NO_MEMORY) + sa_errorType = COMMON_NO_MEMORY; + else if (error_type == SA_INTERNAL_NOT_DEFINED || error_type == SA_INTERNAL_BINDER_ERROR || error_type == SA_INTERNAL_ERROR || error_type == SA_INTERNAL_DA_ERROR) + sa_errorType = COMMON_INTERNAL_ERROR; + else if (error_type == SA_INTERNAL_SERVER_ERROR || error_type == SA_INTERNAL_SERVER_FAILURE) + sa_errorType = COMMON_SERVER_ERROR; + else if (error_type == SA_INTERNAL_CONNECTION_ERROR) + sa_errorType = COMMON_CONNECTION_ERROR; + else if (error_type == SA_INTERNAL_AUTOCONFIG_NOT_SUPPORT_BY_SERVER) + sa_errorType = COMMON_AUTOCONFIG_NOT_SUPPORT_BY_SERVER; + else if (error_type == SA_INTERNAL_CANCEL) + sa_errorType = COMMON_CANCEL; + else if (error_type == SA_INTERNAL_BUSY_SIGNALING) + sa_errorType = COMMON_BUSY_SIGNALING; + else if (error_type == SA_INTERNAL_SUSPEND_FAIL) + sa_errorType = COMMON_SUSPEND_FAIL; + + _INNER_FUNC_EXIT; + 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(session_s * session) +{ + _INNER_FUNC_ENTER; + + if (session != NULL) { + + if (session->has_opend) { + sync_agent_close_connection(TRANSPORT_TYPE, session->naci_session_id); + session->has_opend = 0; + } + + free_session(session); + session = NULL; + } + + _INNER_FUNC_EXIT; +} + +static sa_error_type_e __process_jssion_id(session_s * session, GList * recv_header) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + sync_agent_na_result_e res = SYNC_AGENT_NA_SUCCESS; + + _DEBUG_VERBOSE(" CKECK JSESSION\n"); + char *temp_jsessionid = NULL; + char *real_jsessionid = NULL; + res = sync_agent_get_header_info(1, recv_header, "Set-Cookie", &temp_jsessionid); + if (res == SYNC_AGENT_NA_SUCCESS) { + if (temp_jsessionid != NULL) { + real_jsessionid = strstr(temp_jsessionid, "JSESSIONID"); + if (real_jsessionid != NULL) { + session->jsession_id = strdup(real_jsessionid); + _DEBUG_VERBOSE("session->jsessionId = %s", session->jsession_id); + + } + } + } else + _DEBUG_ERROR("failed in sync_agent_get_header_info = %d", res); + + if (temp_jsessionid != NULL) + free(temp_jsessionid); + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e __check_resume_session(session_s * session, bool * resume) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + char *value = NULL; + bool result; + + result = get_config(session->account_id, DEFINE_CONFIG_KEY_PROFILE_RESUME, &value); + _DEBUG_VERBOSE("resume = %s", value); + if (result == false) { + _DEBUG_ERROR("failed in get_config"); + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + if (strcmp(value, "1") == 0) + *resume = true; + else + *resume = false; + + error: + + if (value != NULL) + free(value); + + _INNER_FUNC_EXIT; + return errorType; + +} + +int pre_sync(int transportType, int account_id, char *session_id, int server_flag, void **pre_sync_return_obj) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + char *msg = NULL; + unsigned int msg_size = 0; + char *recv_msg = NULL; + unsigned int recv_msg_size = 0; + unsigned int naci_session_id; + + /* create session structure */ + errorType = _create_session(account_id, session_id, server_flag, &static_session); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in __create_session"); + goto error; + } + + /* generate preSync Msg */ + errorType = _generate_presync_msg(static_session, server_flag, &msg, &msg_size); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in __generate_presync_msg"); + goto error; + } + + if (!static_session->has_opend) { + sync_agent_na_result_e res = sync_agent_open_connection(transportType, NETWORK_TIMEOUT, &naci_session_id); + if (res != SYNC_AGENT_NA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_connection res = %d", res); + errorType = SA_INTERNAL_CONNECTION_ERROR; + goto error; + } + static_session->naci_session_id = naci_session_id; + static_session->has_opend = 1; + _DEBUG_INFO("naci_session_id = %d", naci_session_id); + } + /* exchange Msg */ + errorType = _exchange_msg(static_session, DEFINE_PROTOCOL_TYPE, transportType, msg, msg_size, &recv_msg, &recv_msg_size); + if (errorType != SA_INTERNAL_OK) + goto error; + + errorType = _process_recv_msg(static_session, recv_msg, recv_msg_size, 0, pre_sync_return_obj, 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) */ + + /* create session structure */ + errorType = _create_session(account_id, session_id, server_flag, &static_session); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in __create_session"); + goto error; + } + + if (msg != NULL) { + free(msg); + msg = NULL; + } + + if (recv_msg != NULL) { + free(recv_msg); + recv_msg = NULL; + } + + errorType = _generate_presync_msg(static_session, server_flag, &msg, &msg_size); + if (errorType != SA_INTERNAL_OK) + goto error; + + errorType = _exchange_msg(static_session, DEFINE_PROTOCOL_TYPE, transportType, msg, msg_size, &recv_msg, &recv_msg_size); + if (errorType != SA_INTERNAL_OK) + goto error; + + errorType = _process_recv_msg(static_session, recv_msg, recv_msg_size, 0, pre_sync_return_obj, NULL); + if (errorType != SA_INTERNAL_OK) + goto error; + } + + error: + + if (msg != NULL) { + free(msg); + msg = NULL; + } + + if (recv_msg != NULL) { + free(recv_msg); + recv_msg = NULL; + } + + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("errorType : %d", errorType); + __clean_up_sa(static_session); + static_session = NULL; + } + + _EXTERN_FUNC_EXIT; + return _convert_error_type(errorType); +} + +int generate_msg(void **syncObj, int server_flag, char **msg, unsigned int *msg_size) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + errorType = _generate_msg(static_session, syncObj, server_flag, msg, msg_size); + if (errorType != SA_INTERNAL_OK) + goto error; + + error: + + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("errorType : %d", errorType); + __clean_up_sa(static_session); + static_session = NULL; + } + + _EXTERN_FUNC_EXIT; + return _convert_error_type(errorType); +} + +int exchange_msg(int transport_type, char *send_msg, unsigned int send_msg_length, char **recv_msg, unsigned int *recv_msg_length) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + errorType = _exchange_msg(static_session, DEFINE_PROTOCOL_TYPE, transport_type, send_msg, send_msg_length, recv_msg, recv_msg_length); + if (errorType != SA_INTERNAL_OK) + goto error; + + error: + + if (errorType != SA_INTERNAL_OK && errorType != SA_INTERNAL_CANCEL) { + _DEBUG_ERROR("errorType : %d", errorType); + __clean_up_sa(static_session); + static_session = NULL; + } + + _EXTERN_FUNC_EXIT; + return _convert_error_type(errorType); +} + +int process_recv_msg(char *recv_msg, unsigned int recv_msg_length, int only_from_client, void **sync_return_obj, int *is_finish) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + errorType = _process_recv_msg(static_session, recv_msg, recv_msg_length, only_from_client, sync_return_obj, is_finish); + if (errorType != SA_INTERNAL_OK) + goto error; + + error: + + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("errorType : %d", errorType); + __clean_up_sa(static_session); + static_session = NULL; + } + + _EXTERN_FUNC_EXIT; + return _convert_error_type(errorType); +} + +void clean_up_sa() +{ + _EXTERN_FUNC_ENTER; + + __clean_up_sa(static_session); + static_session = NULL; + + _EXTERN_FUNC_EXIT; +} + +int auto_configure(char *addr, char *id, char *password, GList ** configure) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + session_s *session = NULL; + + char *sourceUrl = NULL; + char *sessionId = NULL; + + char *msg = NULL; + unsigned int msg_size = 0; + + char *recv_msg = NULL; + unsigned int recv_msg_size = 0; + + bool cancel_flag = false; + unsigned int session_id; + + location_s *pSourceLocation = NULL; + location_s *pTargetLocation = NULL; + + sessionId = g_strdup_printf("%ld", time(NULL)); + if (sessionId == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + sync_agent_dev_return_e err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevID", &sourceUrl); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = SA_INTERNAL_ERROR; + goto error; + } + + errorType = create_location(sourceUrl, NULL, &pSourceLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in create_location"); + goto error; + } + + errorType = create_location(addr, NULL, &pTargetLocation); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in create_location"); + goto error; + } + + errorType = create_session(VERSION_12, PROTOCOL_TYPE_DS, 0, sessionId, pSourceLocation, pTargetLocation, &session); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in create_session"); + goto error; + } + + if (session == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + errorType = _generate_autoconfigure_msg(id, password, addr, &msg, &msg_size, session); + if (errorType != SA_INTERNAL_OK) + goto error; + + if (!session->has_opend) { + sync_agent_na_result_e res = sync_agent_open_connection(TRANSPORT_TYPE, NETWORK_TIMEOUT, &session_id); + if (res != SYNC_AGENT_NA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_connection res = %d", res); + errorType = SA_INTERNAL_CONNECTION_ERROR; + goto error; + } + session->naci_session_id = session_id; + session->has_opend = 1; + _DEBUG_INFO("session_id = %d", session_id); + } + + cancel_flag = sync_agent_check_cancel_flag(); + if (cancel_flag) { + errorType = SA_INTERNAL_CANCEL; + goto error; + } + + /* exchange Msg */ + errorType = _exchange_msg(session, DEFINE_PROTOCOL_TYPE, TRANSPORT_TYPE, msg, msg_size, &recv_msg, &recv_msg_size); + if (errorType != SA_INTERNAL_OK) + goto error; + + cancel_flag = sync_agent_check_cancel_flag(); + if (cancel_flag) { + errorType = SA_INTERNAL_CANCEL; + goto error; + } + + errorType = _process_autoconfigure_recv_msg(recv_msg, recv_msg_size, session); + if (errorType != SA_INTERNAL_OK) + goto error; + + cancel_flag = sync_agent_check_cancel_flag(); + if (cancel_flag) { + errorType = SA_INTERNAL_CANCEL; + goto error; + } + + devinf_s *devInf = session->remote_devinf; + if (devInf != NULL) { + + 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 != NULL) { + _DEBUG_INFO("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 != NULL) { + _DEBUG_INFO("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 != NULL) { + _DEBUG_INFO("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; + devinf_datastore_s *devInfDataStore = NULL; + int exist; + char *candidate; + for (iter = devInf->datastores; iter != NULL; iter = g_list_next(iter)) { + devInfDataStore = iter->data; + exist = 0; + candidate = NULL; + + _DEBUG_INFO("devInfDataStore->sourceref = %s", devInfDataStore->source_ref); + + if (strcmp(devInfDataStore->rx_pref->ct_type, ELEMENT_TEXT_VCARD) == 0 || strcmp(devInfDataStore->rx_pref->ct_type, 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->source_ref) == 0) + exist = 1; + } + if (!exist) { + if (devInfDataStore->source_ref != NULL) + contactCandidate = g_list_append(contactCandidate, strdup(devInfDataStore->source_ref)); + } + + } else if (strcmp(devInfDataStore->rx_pref->ct_type, ELEMENT_TEXT_VCAL) == 0 || strcmp(devInfDataStore->rx_pref->ct_type, ELEMENT_TEXT_ICAL) == 0) { + + for (innerIter = g_list_next(calendarCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) { + candidate = innerIter->data; + + if (strcmp(candidate, devInfDataStore->source_ref) == 0) + exist = 1; + } + if (!exist) { + if (devInfDataStore->source_ref != NULL) + calendarCandidate = g_list_append(calendarCandidate, strdup(devInfDataStore->source_ref)); + } + + } else if (strcmp(devInfDataStore->rx_pref->ct_type, ELEMENT_TEXT_PLAIN) == 0) { + + for (innerIter = g_list_next(memoCandidate); innerIter != NULL; innerIter = g_list_next(innerIter)) { + candidate = innerIter->data; + + if (strcmp(candidate, devInfDataStore->source_ref) == 0) + exist = 1; + } + if (!exist) { + if (devInfDataStore->source_ref != NULL) + memoCandidate = g_list_append(memoCandidate, strdup(devInfDataStore->source_ref)); + } + } + } + + 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; + } + + error: + + /*close network */ + if (session != NULL) { + if (session->has_opend) + sync_agent_close_connection(TRANSPORT_TYPE, session->naci_session_id); + } + + if (msg != NULL) { + free(msg); + msg = NULL; + } + + if (recv_msg != NULL) { + free(recv_msg); + recv_msg = NULL; + } + + if (sessionId != NULL) + free(sessionId); + + if (sourceUrl != NULL) + free(sourceUrl); + + if (session != NULL) { + free_session(session); + session = NULL; + } + + if (errorType != SA_INTERNAL_OK) + _DEBUG_ERROR("errorType =%d", errorType); + + _EXTERN_FUNC_EXIT; + return _convert_error_type(errorType); +} + +int check_cancel_status() +{ + _EXTERN_FUNC_ENTER; + + bool result = false; + retvm_if(static_session == NULL, false, "session is NULL"); + + if (static_session->pkg_status == SYNCML_PKG_5 || static_session->pkg_status == SYNCML_PKG_6) + result = false; + else + result = true; + + _EXTERN_FUNC_EXIT; + + return result; +} + +int suspend_sync(int transport_type, int account_id, int server_flag) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + char *msg = NULL; + unsigned int msg_size = 0; + char *recv_msg = NULL; + unsigned int recv_msg_size = 0; + + /* generate preSync Msg */ + errorType = _generate_suspend_msg(static_session, server_flag, &msg, &msg_size); + if (errorType != SA_INTERNAL_OK) + goto error; + + /* exchange Msg */ + errorType = _exchange_msg(static_session, DEFINE_PROTOCOL_TYPE, transport_type, msg, msg_size, &recv_msg, &recv_msg_size); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("errorType = %d", errorType); + goto error; + } + + errorType = _process_recv_msg(static_session, recv_msg, recv_msg_size, 0, NULL, NULL); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("errorType = %d", errorType); + goto error; + } + + error: + + if (msg != NULL) { + free(msg); + msg = NULL; + } + + if (recv_msg != NULL) { + free(recv_msg); + recv_msg = NULL; + } + + if (errorType != SA_INTERNAL_OK) + _DEBUG_ERROR("errorType =%d", errorType); + + _EXTERN_FUNC_EXIT; + return _convert_error_type(errorType); +} + +int cancel_connection_sync_request(int transport_type) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e err = SA_INTERNAL_OK; + sync_agent_na_result_e res = SYNC_AGENT_NA_SUCCESS; + + if (static_session != NULL) { + _DEBUG_INFO("sessionId = %d", static_session->naci_session_id); + + res = sync_agent_cancel_msg(transport_type, static_session->naci_session_id); + if (res != SYNC_AGENT_NA_SUCCESS) { + _DEBUG_ERROR("res = %d", res); + err = SA_INTERNAL_CONNECTION_ERROR; + goto error; + } + } + + error: + + _EXTERN_FUNC_EXIT; + return _convert_error_type(err); +} diff --git a/src/agent/service-adapter/sa_devinf.c b/src/agent/service-adapter/sa_devinf.c new file mode 100755 index 0000000..d65bad5 --- /dev/null +++ b/src/agent/service-adapter/sa_devinf.c @@ -0,0 +1,1069 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 + +#include "service-adapter/sa_devinf.h" +#include "service-adapter/sa_devinf_internal.h" +#include "service-adapter/sa_session_internal.h" +#include "common/common_define.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SA" +#endif + +static sa_error_type_e _create_devinf_new(char *devid, devinf_devtyp_e devtyp, devinf_s ** devinf); +static sa_error_type_e _create_devinf_contenttype(char *cttype, char *verct, devinf_content_type_s ** devinf_content_type); +static sa_error_type_e _create_devinf_ctcap(devinf_content_type_s * devinf_content_type, devinf_ct_cap_s ** devinf_ctcap); +static sa_error_type_e _create_devinf_property(char *prop_name, devinf_property_s ** devinf_property); +static sa_error_type_e _create_devinf_datastore(char *datastore, devinf_datastore_s ** devinf_datastore); + +static void _free_devinf_datastores(GList * devinf_datastores); +static void __free_devinf_datastore(devinf_datastore_s * devinf_datastore); +static void ___free_devinf_contenttype(devinf_content_type_s * devinf_content_type); +static void ___free_devinf_ctcaps(devinf_ct_cap_s * devinf_ctcap); +static void ___free_devinf_property(devinf_property_s * devinf_property); +static void ___free_devinf_propparam(devinf_prop_param_s * devinf_prop_param); + +static void _set_devinf_version(devinf_s * devinf, devinf_version_e version); +static void _set_devinf_manufacturer(devinf_s * devinf, char *manufacturer); +static void _set_devinf_model(devinf_s * devinf, char *model); +static void _set_devinf_oem(devinf_s * devinf, char *oem); +static void _set_devinf_software_version(devinf_s * devinf, char *software_version); +static void _set_devinf_hardware_version(devinf_s * devinf, char *hardware_version); +static void _set_devinf_firmware_version(devinf_s * devinf, char *firmware_version); +static void _set_devinf_datastore(devinf_s * devinf, devinf_datastore_s * devinf_datastore); +static void _set_devinf_datastore_rxpref(devinf_datastore_s * devinf_datastore, devinf_content_type_s * devinf_content_type); +static void _set_devinf_datastore_txpref(devinf_datastore_s * devinf_datastore, devinf_content_type_s * devinf_content_type); +static void _set_devinf_datastore_ctcap(devinf_datastore_s * devinf_datastore, devinf_ct_cap_s * devinf_ctcap); +static void _set_devinf_datastore_sharedmem(devinf_datastore_s * devinf_datastore, int shared_mem); +static void _set_devinf_datastore_maxmem(devinf_datastore_s * devinf_datastore, unsigned int max_mem); +static void _set_devinf_datastore_maxid(devinf_datastore_s * devinf_datastore, unsigned int max_id); +static void _set_devinf_ctcap_property(devinf_ct_cap_s * devinf_ctcap, devinf_property_s * devinf_property); +static void _set_devinf_property_valenums(devinf_property_s * devinf_property, char *val_enum); +static devinf_devtyp_e _convert_devtyp(char *dev_typ); + +/* unused function + * keep for in case + */ +/* +static ErrorType create_DevInfPropParam(char *paramName, DevInfPropParam **devinfPropParam); +static void set_DevInfDataStoreDisplayname(DevInfDataStore* devinf_datastore, char *displayname); +static void set_DevInfDataStoreRx(DevInfDataStore *devinf_datastore, DevInfContentType *devinf_content_type); +static void set_DevInfDataStoreTx(DevInfDataStore *devinf_datastore, DevInfContentType *devinf_content_type); +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_error_type_e _create_devinf_new(char *devid, devinf_devtyp_e devtyp, devinf_s ** devinf) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (devid == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (!devtyp) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *devinf = (devinf_s *) calloc(1, sizeof(devinf_s)); + if (*devinf == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + if (devid != NULL) + (*devinf)->dev_id = strdup(devid); + (*devinf)->devtyp = devtyp; + + error: + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _create_devinf_contenttype(char *cttype, char *verct, devinf_content_type_s ** devinf_content_type) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (cttype == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (verct == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *devinf_content_type = (devinf_content_type_s *) calloc(1, sizeof(devinf_content_type_s)); + if (*devinf_content_type == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*devinf_content_type)->ct_type = strdup(cttype); + (*devinf_content_type)->verct = strdup(verct); + + error: + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _create_devinf_ctcap(devinf_content_type_s * devinf_content_type, devinf_ct_cap_s ** devinf_ctcap) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (devinf_content_type == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *devinf_ctcap = (devinf_ct_cap_s *) calloc(1, sizeof(devinf_ct_cap_s)); + if (*devinf_ctcap == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*devinf_ctcap)->ct = devinf_content_type; + + error: + + _INNER_FUNC_EXIT; + return errorType; + +} + +static sa_error_type_e _create_devinf_property(char *prop_name, devinf_property_s ** devinf_property) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (prop_name == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *devinf_property = (devinf_property_s *) calloc(1, sizeof(devinf_property_s)); + if (*devinf_property == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*devinf_property)->prop_name = strdup(prop_name); + + error: + + _INNER_FUNC_EXIT; + return errorType; +} + +static sa_error_type_e _create_devinf_datastore(char *datastore, devinf_datastore_s ** devinf_datastore) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (datastore == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *devinf_datastore = (devinf_datastore_s *) calloc(1, sizeof(devinf_datastore_s)); + if (*devinf_datastore == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*devinf_datastore)->source_ref = strdup(datastore); + + error: + + _INNER_FUNC_EXIT; + return errorType; +} + +static void _free_devinf_datastores(GList * devinf_datastores) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_datastores == NULL, "List is NULL"); + + GList *iter = NULL; + for (iter = devinf_datastores; iter != NULL; iter = g_list_next(iter)) + __free_devinf_datastore(iter->data); + + g_list_free(devinf_datastores); + + _INNER_FUNC_EXIT; +} + +static void __free_devinf_datastore(devinf_datastore_s * devinf_datastore) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_datastore == NULL, "devinf_datastore is NULL"); + + if (devinf_datastore->source_ref != NULL) { + free(devinf_datastore->source_ref); + devinf_datastore->source_ref = NULL; + } + + if (devinf_datastore->display_name != NULL) { + free(devinf_datastore->display_name); + devinf_datastore->display_name = NULL; + } + + ___free_devinf_contenttype(devinf_datastore->rx_pref); + devinf_datastore->rx_pref = NULL; + + ___free_devinf_contenttype(devinf_datastore->tx_pref); + devinf_datastore->tx_pref = NULL; + + /*free_FilterRx(filter_rx); */ + /*free_FilterCap(filterCap); */ + + GList *iter = NULL; + for (iter = devinf_datastore->rx; iter != NULL; iter = g_list_next(iter)) + ___free_devinf_contenttype(iter->data); + g_list_free(devinf_datastore->rx); + + for (iter = devinf_datastore->tx; iter != NULL; iter = g_list_next(iter)) + ___free_devinf_contenttype(iter->data); + g_list_free(devinf_datastore->tx); + + for (iter = devinf_datastore->ct_caps; iter != NULL; iter = g_list_next(iter)) + ___free_devinf_ctcaps(iter->data); + g_list_free(devinf_datastore->ct_caps); + + free(devinf_datastore); + + _INNER_FUNC_EXIT; +} + +static void ___free_devinf_contenttype(devinf_content_type_s * devinf_content_type) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_content_type == NULL, "devinf_content_type is NULL"); + + if (devinf_content_type->ct_type != NULL) { + free(devinf_content_type->ct_type); + devinf_content_type->ct_type = NULL; + } + + if (devinf_content_type->verct != NULL) { + free(devinf_content_type->verct); + devinf_content_type->verct = NULL; + } + + free(devinf_content_type); + + _INNER_FUNC_EXIT; +} + +static void ___free_devinf_ctcaps(devinf_ct_cap_s * devinf_ctcap) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_ctcap == NULL, "devinf_ctcap is NULL"); + + ___free_devinf_contenttype(devinf_ctcap->ct); + devinf_ctcap->ct = NULL; + + GList *iter = NULL; + for (iter = devinf_ctcap->properties; iter != NULL; iter = g_list_next(iter)) + ___free_devinf_property(iter->data); + + g_list_free(devinf_ctcap->properties); + + free(devinf_ctcap); + + _INNER_FUNC_EXIT; +} + +static void ___free_devinf_property(devinf_property_s * devinf_property) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_property == NULL, "devinf_property is NULL"); + + if (devinf_property->prop_name != NULL) { + free(devinf_property->prop_name); + devinf_property->prop_name = NULL; + } + + if (devinf_property->data_type != NULL) { + free(devinf_property->data_type); + devinf_property->data_type = NULL; + } + + if (devinf_property->display_name != NULL) { + free(devinf_property->display_name); + devinf_property->display_name = NULL; + } + + GList *iter = NULL; + for (iter = devinf_property->val_enums; iter != NULL; iter = g_list_next(iter)) + free(iter->data); + + g_list_free(devinf_property->val_enums); + + for (iter = devinf_property->prop_params; iter != NULL; iter = g_list_next(iter)) + ___free_devinf_propparam(iter->data); + + g_list_free(devinf_property->prop_params); + + free(devinf_property); + + _INNER_FUNC_EXIT; +} + +static void ___free_devinf_propparam(devinf_prop_param_s * devinf_prop_param) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_prop_param == NULL, "devinfPropParam is NULL"); + + if (devinf_prop_param->param_name != NULL) { + free(devinf_prop_param->param_name); + devinf_prop_param->param_name = NULL; + } + + if (devinf_prop_param->data_type != NULL) { + free(devinf_prop_param->data_type); + devinf_prop_param->data_type = NULL; + } + + if (devinf_prop_param->display_name != NULL) { + free(devinf_prop_param->display_name); + devinf_prop_param->display_name = NULL; + } + + GList *iter = NULL; + for (iter = devinf_prop_param->val_enums; iter != NULL; iter = g_list_next(iter)) + free(iter->data); + + g_list_free(devinf_prop_param->val_enums); + + free(devinf_prop_param); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_version(devinf_s * devinf, devinf_version_e version) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + devinf->version = version; + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_manufacturer(devinf_s * devinf, char *manufacturer) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + if (manufacturer != NULL) + devinf->manufacturer = strdup(manufacturer); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_model(devinf_s * devinf, char *model) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + if (model != NULL) + devinf->model = strdup(model); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_oem(devinf_s * devinf, char *oem) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + if (oem != NULL) + devinf->oem = strdup(oem); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_software_version(devinf_s * devinf, char *software_version) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + if (software_version != NULL) + devinf->software_version = strdup(software_version); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_hardware_version(devinf_s * devinf, char *hardware_version) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + if (hardware_version != NULL) + devinf->hardware_version = strdup(hardware_version); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_firmware_version(devinf_s * devinf, char *firmware_version) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + if (firmware_version != NULL) + devinf->firmware_version = strdup(firmware_version); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_datastore(devinf_s * devinf, devinf_datastore_s * devinf_datastore) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + devinf->datastores = g_list_append(devinf->datastores, devinf_datastore); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_datastore_rxpref(devinf_datastore_s * devinf_datastore, devinf_content_type_s * devinf_content_type) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_datastore == NULL, "devinf_datastore is NULL"); + + devinf_datastore->rx_pref = devinf_content_type; + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_datastore_txpref(devinf_datastore_s * devinf_datastore, devinf_content_type_s * devinf_content_type) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_datastore == NULL, "devinf_datastore is NULL"); + + devinf_datastore->tx_pref = devinf_content_type; + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_datastore_ctcap(devinf_datastore_s * devinf_datastore, devinf_ct_cap_s * devinf_ctcap) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_datastore == NULL, "devinf_datastore is NULL"); + + devinf_datastore->ct_caps = g_list_append(devinf_datastore->ct_caps, devinf_ctcap); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_datastore_sharedmem(devinf_datastore_s * devinf_datastore, int shared_mem) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_datastore == NULL, "devinf_datastore is NULL"); + + devinf_datastore->shared_mem = shared_mem; + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_datastore_maxmem(devinf_datastore_s * devinf_datastore, unsigned int max_mem) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_datastore == NULL, "devinf_datastore is NULL"); + + devinf_datastore->max_mem = max_mem; + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_datastore_maxid(devinf_datastore_s * devinf_datastore, unsigned int max_id) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_datastore == NULL, "devinf_datastore is NULL"); + + devinf_datastore->max_id = max_id; + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_ctcap_property(devinf_ct_cap_s * devinf_ctcap, devinf_property_s * devinf_property) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_ctcap == NULL, "devinfCTCap is NULL"); + + devinf_ctcap->properties = g_list_append(devinf_ctcap->properties, devinf_property); + + _INNER_FUNC_EXIT; +} + +static void _set_devinf_property_valenums(devinf_property_s * devinf_property, char *val_enum) +{ + _INNER_FUNC_ENTER; + + retm_if(devinf_property == NULL, "devinfCTCap is NULL"); + + if (val_enum != NULL) + devinf_property->val_enums = g_list_append(devinf_property->val_enums, strdup(val_enum)); + + _INNER_FUNC_EXIT; +} + +static devinf_devtyp_e _convert_devtyp(char *dev_typ) +{ + _INNER_FUNC_ENTER; + + devinf_devtyp_e devinfDevTyp = DEVINF_DEVTYPE_UNKNOWN; + + if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_PAGER) == 0) + devinfDevTyp = DEVINF_DEVTYPE_PAGER; + else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_HANDHELD) == 0) + devinfDevTyp = DEVINF_DEVTYPE_HANDHELD; + else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_PDA) == 0) + devinfDevTyp = DEVINF_DEVTYPE_PDA; + else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_PHONE) == 0) + devinfDevTyp = DEVINF_DEVTYPE_PHONE; + else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_SMARTPHONE) == 0) + devinfDevTyp = DEVINF_DEVTYPE_SMARTPHONE; + else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_SERVER) == 0) + devinfDevTyp = DEVINF_DEVTYPE_SERVER; + else if (strcmp(dev_typ, DEFINE_DEVICE_TYPE_WORKSTATION) == 0) + devinfDevTyp = DEVINF_DEVTYPE_WORKSTATION; + + _INNER_FUNC_EXIT; + return devinfDevTyp; +} + +sa_error_type_e create_devinf(session_s * session, devinf_s ** devinf) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + sync_agent_dev_return_e err = SYNC_AGENT_DEV_RETURN_SUCCESS; + + char *devID = NULL; + char *devTyp = NULL; + char *man = NULL; + char *model = NULL; + char *oem = NULL; + char *swv = NULL; + char *hwv = NULL; + char *fwv = "1.0"; + + devinf_s *temp_devinf = NULL; + devinf_datastore_s *devInfDataStore = NULL; + devinf_ct_cap_s *devInfCTCap = NULL; + devinf_property_s *devInfProperty = NULL; + + err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevID", &devID); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = SA_INTERNAL_ERROR; + goto error; + } + + err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevTyp", &devTyp); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = SA_INTERNAL_ERROR; + goto error; + } + + devinf_devtyp_e devInfDevTyp = DEVINF_DEVTYPE_UNKNOWN; + if (devTyp != NULL) + devInfDevTyp = _convert_devtyp(devTyp); + + devinf_version_e devInfVersion = DEVINF_VERSION_UNKNOWN; + if (session->protocol_version == VERSION_10) + devInfVersion = DEVINF_VERSION_10; + else if (session->protocol_version == VERSION_11) + devInfVersion = DEVINF_VERSION_11; + else if (session->protocol_version == VERSION_12) + devInfVersion = DEVINF_VERSION_12; + + err = sync_agent_get_devinfo(DEFINE_PLATFORM, "Man", &man); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = SA_INTERNAL_ERROR; + goto error; + } + + err = sync_agent_get_devinfo(DEFINE_PLATFORM, "Mod", &model); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = SA_INTERNAL_ERROR; + goto error; + } + + err = sync_agent_get_devinfo(DEFINE_PLATFORM, "OEM", &oem); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = SA_INTERNAL_ERROR; + goto error; + } + + err = sync_agent_get_devinfo(DEFINE_PLATFORM, "SwV", &swv); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = SA_INTERNAL_ERROR; + goto error; + } + + err = sync_agent_get_devinfo(DEFINE_PLATFORM, "HwV", &hwv); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = SA_INTERNAL_ERROR; + goto error; + } + + /* + err = sync_agent_get_devinfo(DEFINE_PLATFORM, "FwV", &fwv); + if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + errorType = ERROR_INTERNAL_ERROR; + goto error; + } + */ + + _DEBUG_INFO("devID = %s", devID); + _DEBUG_INFO("devTyp = %s", devTyp); + _DEBUG_INFO("man = %s", man); + _DEBUG_INFO("model = %s", model); + _DEBUG_INFO("oem = %s", oem); + _DEBUG_INFO("swv = %s", swv); + _DEBUG_INFO("hwv = %s", hwv); + _DEBUG_INFO("fwv = %s", fwv); + + errorType = _create_devinf_new(devID, devInfDevTyp, &temp_devinf); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create devInf New"); + goto error; + } + + _set_devinf_version(temp_devinf, devInfVersion); + _set_devinf_manufacturer(temp_devinf, man); + _set_devinf_model(temp_devinf, model); + _set_devinf_oem(temp_devinf, oem); + _set_devinf_software_version(temp_devinf, swv); + _set_devinf_hardware_version(temp_devinf, hwv); + _set_devinf_firmware_version(temp_devinf, fwv); + + temp_devinf->supports_large_objs = 1; + temp_devinf->supports_utc = 1; + temp_devinf->supports_number_of_changes = 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_SERVICE_COUNT - 1; content_type++) { + + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->source != NULL) { + errorType = _create_devinf_datastore(datastoreinfo_per_content_type[content_type]->source, &devInfDataStore); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create devInfDataStore"); + goto error; + } + + sync_agent_plugin_object_info_s *datastore = sync_agent_get_obj_info(content_type); + + _DEBUG_INFO("datastore->type = %s", datastore->type); + _DEBUG_INFO("datastore->version = %s", datastore->version); + _DEBUG_INFO("datastore->field_cnt = %d", datastore->field_cnt); + + devinf_content_type_s *devInfContentTypeRxPref = NULL; + errorType = _create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeRxPref); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create devInfContentType"); + goto error; + } + _set_devinf_datastore_rxpref(devInfDataStore, devInfContentTypeRxPref); + + devinf_content_type_s *devInfContentTypeTxPref = NULL; + errorType = _create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeTxPref); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create devInfContentType"); + goto error; + } + _set_devinf_datastore_txpref(devInfDataStore, devInfContentTypeTxPref); + + devinf_content_type_s *devInfContentTypeCTCap = NULL; + errorType = _create_devinf_contenttype(datastore->type, datastore->version, &devInfContentTypeCTCap); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create devInfContentType"); + goto error; + } + + errorType = _create_devinf_ctcap(devInfContentTypeCTCap, &devInfCTCap); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed to create devInfCTCap"); + goto error; + } + + sync_agent_plugin_field_info_s 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) { + _DEBUG_ERROR("failed to create devInfProperty"); + goto error; + } + + sync_agent_plugin_field_info_s 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); + devInfProperty = NULL; + } + + _set_devinf_datastore_ctcap(devInfDataStore, devInfCTCap); + devInfCTCap = NULL; + + /* TODO Get information about static memory for each datastore + * It will be used to fill DSMem and children element(SharedMem, MaxMem, MaxID) */ + /* Set SharedMem */ + _set_devinf_datastore_sharedmem(devInfDataStore, 0); + /* Set MaxMem */ + _set_devinf_datastore_maxmem(devInfDataStore, 0); + /* Set MaxID */ + _set_devinf_datastore_maxid(devInfDataStore, 0); + + set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_TWO_WAY, 1); + set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_SLOW_SYNC, 1); + set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_CLIENT, 1); + set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_CLIENT, 1); + set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_ONE_WAY_FROM_SERVER, 1); + set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_REFRESH_FROM_SERVER, 1); + set_devinf_datastore_sync_cap(devInfDataStore, DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC, 1); + + _set_devinf_datastore(temp_devinf, devInfDataStore); + devInfDataStore = NULL; + + /*free datastore */ + sync_agent_free_obj_info(content_type, datastore); + } + } + } + + *devinf = temp_devinf; + temp_devinf = NULL; + + error: + + if (temp_devinf != NULL) + free(temp_devinf); + + __free_devinf_datastore(devInfDataStore); + ___free_devinf_ctcaps(devInfCTCap); + ___free_devinf_property(devInfProperty); + + if (devID != NULL) + free(devID); + if (devTyp != NULL) + free(devTyp); + if (man != NULL) + free(man); + if (model != NULL) + free(model); + if (oem != NULL) + free(oem); + if (swv != NULL) + free(swv); + if (hwv != NULL) + free(hwv); +/* if (fwv != NULL) + free(fwv);*/ + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void free_devinf(devinf_s * devinf) +{ + _EXTERN_FUNC_ENTER; + + retm_if(devinf == NULL, "devinf is NULL"); + + if (devinf->manufacturer != NULL) { + free(devinf->manufacturer); + devinf->manufacturer = NULL; + } + + if (devinf->model != NULL) { + free(devinf->model); + devinf->model = NULL; + } + + if (devinf->oem != NULL) { + free(devinf->oem); + devinf->oem = NULL; + } + + if (devinf->software_version != NULL) { + free(devinf->software_version); + devinf->software_version = NULL; + } + + if (devinf->hardware_version != NULL) { + free(devinf->hardware_version); + devinf->hardware_version = NULL; + } + + if (devinf->firmware_version != NULL) { + free(devinf->firmware_version); + devinf->firmware_version = NULL; + } + + if (devinf->dev_id != NULL) { + free(devinf->dev_id); + devinf->dev_id = NULL; + } + + _free_devinf_datastores(devinf->datastores); + devinf->datastores = NULL; + + free(devinf); + + _EXTERN_FUNC_EXIT; +} + +void set_devinf_datastore_sync_cap(devinf_datastore_s * devinf_datastore, devinf_sync_cap_e cap, int supported) +{ + _EXTERN_FUNC_ENTER; + + if (supported) + devinf_datastore->sync_cap = devinf_datastore->sync_cap | cap; + else + devinf_datastore->sync_cap = devinf_datastore->sync_cap & ~cap; + + _EXTERN_FUNC_EXIT; +} + +int get_devinf_datastore_sync_cap(const devinf_datastore_s * devinf_datastore, devinf_sync_cap_e cap) +{ + _EXTERN_FUNC_ENTER; + + int data; + data = devinf_datastore->sync_cap & cap ? 1 : 0; + + _EXTERN_FUNC_EXIT; + return data; +} + +devinf_sync_cap_e convert_devinf_synccap(unsigned int id) +{ + _EXTERN_FUNC_ENTER; + + devinf_sync_cap_e 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; + } + + _EXTERN_FUNC_EXIT; + return result; +} + +/* +static ErrorType create_DevInfPropParam(char *paramName, DevInfPropParam **devinfPropParam) +{ + _EXTERN_FUNC_ENTER; + + ErrorType errorType = ERROR_INTERNAL_OK; + + if (!paramName) { + errorType = ERROR_INTERNAL_NOT_DEFINED; + goto error; + } + + *devinfPropParam = (DevInfPropParam *)calloc(1, sizeof(DevInfPropParam)); + if (*devinfPropParam == NULL) { + errorType = ERROR_INTERNAL_NO_MEMORY; + goto error; + } + + (*devinfPropParam)->paramName = strdup(paramName); + +error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +static void set_DevInfDataStoreDisplayname(DevInfDataStore* devinf_datastore, char *displayname) { + + if (!devinf_datastore) + return; + + devinf_datastore->displayname = strdup(displayname); +} + +static void set_DevInfDataStoreRx(DevInfDataStore *devinf_datastore, DevInfContentType *devinf_content_type) { + if (!devinf_datastore) + return; + + devinf_datastore->rx = g_list_append(devinf_datastore->rx, devinf_content_type); +} + +static void set_DevInfDataStoreTx(DevInfDataStore *devinf_datastore, DevInfContentType *devinf_content_type) { + if (!devinf_datastore) + return; + + devinf_datastore->tx = g_list_append(devinf_datastore->tx, devinf_content_type); +} + +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/agent/service-adapter/sa_elements.c b/src/agent/service-adapter/sa_elements.c new file mode 100755 index 0000000..7d64963 --- /dev/null +++ b/src/agent/service-adapter/sa_elements.c @@ -0,0 +1,834 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 + +#include "service-adapter/sa_elements.h" +#include "service-adapter/sa_elements_internal.h" +#include "service-adapter/sa_session_internal.h" +#include "service-adapter/sa_command.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SA" +#endif + +sa_error_type_e create_anchor(char *last, char *next, anchor_s ** anchor) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (next == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *anchor = (anchor_s *) calloc(1, sizeof(anchor_s)); + if (*anchor == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + if (last != NULL) + (*anchor)->last_anchor = strdup(last); + + (*anchor)->next_anchor = strdup(next); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_item_anchor(item_s * item, anchor_s * anchor) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (item == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (anchor == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (item->anchor != NULL) { + free_anchor(item->anchor); + item->anchor = NULL; + } + + anchor_s *temp_anchor = NULL; + errorType = create_anchor(anchor->last_anchor, anchor->next_anchor, &temp_anchor); + if (errorType != SA_INTERNAL_OK) + goto error; + item->anchor = temp_anchor; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_last_anchor(anchor_s * anchor, char *last_anchor) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("lastAnchor = %s\n", last_anchor); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (anchor == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (last_anchor == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + anchor->last_anchor = last_anchor; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_next_anchor(anchor_s * anchor, char *next_anchor) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("nextAnchor = %s\n", next_anchor); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (anchor == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (next_anchor == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + anchor->next_anchor = next_anchor; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void free_anchor(anchor_s * anchor) +{ + _EXTERN_FUNC_ENTER; + + retm_if(anchor == NULL, "anchor is NULL"); + + if (anchor->last_anchor != NULL) { + free(anchor->last_anchor); + anchor->last_anchor = NULL; + } + + if (anchor->next_anchor != NULL) { + free(anchor->next_anchor); + anchor->next_anchor = NULL; + } + + free(anchor); + anchor = NULL; + + _EXTERN_FUNC_EXIT; + return; +} + +sa_error_type_e create_location(char *loc_uri, char *loc_name, location_s ** location) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("locURI = %s, locName = %s\n", loc_uri, loc_name); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (loc_uri == NULL) { + _DEBUG_ERROR("locURI is NULL"); + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *location = (location_s *) calloc(1, sizeof(location_s)); + if (*location == NULL) { + _DEBUG_ERROR("location is NULL"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*location)->loc_uri = strdup(loc_uri); + + if (loc_name != NULL) + (*location)->loc_name = strdup(loc_name); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +location_s *dup_location(location_s * location) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + location_s *temp_location = NULL; + + if (location == NULL) { + _DEBUG_ERROR("location is NULL"); + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + errorType = create_location(location->loc_uri, location->loc_name, &temp_location); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("create_location is failed"); + goto error; + } + + _EXTERN_FUNC_EXIT; + return temp_location; + + error: + + _EXTERN_FUNC_EXIT; + return NULL; + +} + +char *get_location_loc_name(location_s * location) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(location == NULL, NULL, "location is NULL"); + + _EXTERN_FUNC_EXIT; + return location->loc_name; +} + +char *get_location_loc_uri(location_s * location) +{ + _EXTERN_FUNC_ENTER; + retvm_if(location == NULL, NULL, "location is NULL"); + + _EXTERN_FUNC_EXIT; + return location->loc_uri; +} + +void free_location(location_s * loc) +{ + _EXTERN_FUNC_ENTER; + + retm_if(loc == NULL, "loc is NULL"); + + _DEBUG_INFO("loc->locURI = %s", loc->loc_uri); + if (loc->loc_uri != NULL) + free(loc->loc_uri); + + _DEBUG_INFO("loc->locName = %s", loc->loc_name); + if (loc->loc_name != NULL) + free(loc->loc_name); + + free(loc); + loc = NULL; + + _EXTERN_FUNC_EXIT; + return; +} + +sa_error_type_e create_cred(char *user_name, char *pwd, auth_type_e auth_type, format_type_e format_type, char *data, cred_s ** cred) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (user_name == NULL || !strlen(user_name)) { + 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_s *) calloc(1, sizeof(cred_s)); + if (*cred == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*cred)->type = auth_type; + (*cred)->format = format_type; + (*cred)->user_name = strdup(user_name); + (*cred)->password = strdup(pwd); + + (*cred)->data = strdup(data); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; + +} + +void free_cred(cred_s * cred) +{ + _EXTERN_FUNC_ENTER; + + retm_if(cred == NULL, "cred is NULL"); + + if (cred->data != NULL) { + free(cred->data); + cred->data = NULL; + } + + if (cred->user_name != NULL) { + free(cred->user_name); + cred->user_name = NULL; + } + + if (cred->password != NULL) { + free(cred->password); + cred->password = NULL; + } + + free(cred); + cred = NULL; + + _EXTERN_FUNC_EXIT; + return; +} + +void free_chal(chal_s * chal) +{ + _EXTERN_FUNC_ENTER; + + retm_if(chal == NULL, "chal is NULL"); + + if (chal->nonce_plain != NULL) { + free(chal->nonce_plain); + chal->nonce_plain = NULL; + } + + if (chal->nonce_b64 != NULL) { + free(chal->nonce_b64); + chal->nonce_b64 = NULL; + } + + free(chal); + + _EXTERN_FUNC_EXIT; + return; +} + +cred_s *create_cred_with_data(auth_type_e auth_type, char *data) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + cred_s *cred = (cred_s *) calloc(1, sizeof(cred_s)); + if (cred == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + cred->type = auth_type; + if (data != NULL) + cred->data = strdup(data); + + error: + + _EXTERN_FUNC_EXIT; + return cred; + +} + +void set_cred_format_type(cred_s * cred, format_type_e format_type) +{ + _EXTERN_FUNC_ENTER; + + retm_if(cred == NULL, "cred is NULL"); + + cred->format = format_type; + + _EXTERN_FUNC_EXIT; +} + +sa_error_type_e create_syncml(sync_hdr_s * sync_hdr, GList * status, GList * commands, int is_final, syncml_s ** syncml) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (sync_hdr == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *syncml = (syncml_s *) calloc(1, sizeof(syncml_s)); + if (*syncml == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*syncml)->hdr = sync_hdr; + (*syncml)->status = status; + (*syncml)->commands = commands; + (*syncml)->final = is_final; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; + +} + +void free_syncml(syncml_s * syncml) +{ + _EXTERN_FUNC_ENTER; + + retm_if(syncml == NULL, "syncML is NULL"); + + free_sync_hdr(syncml->hdr); + syncml->hdr = NULL; + + free_statuses(syncml->status); + syncml->status = NULL; + + free_commands(syncml->commands); + syncml->commands = NULL; + + free(syncml); + + _EXTERN_FUNC_EXIT; + + return; +} + +sa_error_type_e create_sync_hdr(session_s * session, sync_hdr_s ** sync_hdr) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (!session->protocol_version) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (!session->protocol_type) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (session->source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (session->target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *sync_hdr = (sync_hdr_s *) calloc(1, sizeof(sync_hdr_s)); + if (*sync_hdr == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*sync_hdr)->version = session->protocol_version; + (*sync_hdr)->protocol = session->protocol_type; + (*sync_hdr)->target = dup_location(session->target); + (*sync_hdr)->source = dup_location(session->source); + + if (session->cred != NULL) + (*sync_hdr)->cred = dup_cred(session->cred); + + if (session->session_id != NULL) + (*sync_hdr)->session_id = strdup(session->session_id); /*free */ + + (*sync_hdr)->message_id = ++session->msg_id; + + (*sync_hdr)->max_msg_size = session->source_max_msg_size; + (*sync_hdr)->max_obj_size = session->source_max_obj_size; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void free_sync_hdr(sync_hdr_s * sync_hdr) +{ + _EXTERN_FUNC_ENTER; + + retm_if(sync_hdr == NULL, "sync_hdr is NULL"); + + if (sync_hdr->session_id != NULL) { + free(sync_hdr->session_id); + sync_hdr->session_id = NULL; + } + + if (sync_hdr->response_uri != NULL) { + free(sync_hdr->response_uri); + sync_hdr->response_uri = NULL; + } + + if (sync_hdr->source != NULL) { + free_location(sync_hdr->source); + sync_hdr->source = NULL; + } + + if (sync_hdr->target != NULL) { + free_location(sync_hdr->target); + sync_hdr->target = NULL; + } + + if (sync_hdr->cred != NULL) { + free_cred(sync_hdr->cred); + sync_hdr->cred = NULL; + } + + free(sync_hdr); + + _EXTERN_FUNC_EXIT; + return; +} + +item_s *create_item() +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + item_s *item = (item_s *) calloc(1, sizeof(item_s)); + if (item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + item->data_type = ITEM_UNKNOWN; + + _EXTERN_FUNC_EXIT; + return item; + + error: + + _EXTERN_FUNC_EXIT; + return NULL; +} + +item_s *create_item_for_data(const char *data, unsigned int size) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + item_s *item = create_item(); + if (item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + item->data_type = ITEM_DATA; + if (data != NULL) + item->private.data = strdup(data); + + item->size = size; + + _EXTERN_FUNC_EXIT; + return item; + + error: + + _EXTERN_FUNC_EXIT; + return NULL; +} + +item_s *create_item_for_devinf(devinf_s * devinf) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (devinf == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + item_s *item = create_item(); + if (item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + item->data_type = ITEM_DEVINF; + item->private.devinf = devinf; + + _EXTERN_FUNC_EXIT; + return item; + + error: + + _EXTERN_FUNC_EXIT; + return NULL; +} + +void set_item_target(item_s * item, location_s * target) +{ + _EXTERN_FUNC_ENTER; + if (item != NULL) + item->target = target; + + _EXTERN_FUNC_EXIT; +} + +void set_item_source(item_s * item, location_s * source) +{ + _EXTERN_FUNC_ENTER; + if (item != NULL) + item->source = source; + + _EXTERN_FUNC_EXIT; +} + +void free_item(item_s * item) +{ + _EXTERN_FUNC_ENTER; + + retm_if(item == NULL, "item is NULL"); + + if (item->source != NULL) { + free_location(item->source); + item->source = NULL; + } + + if (item->target != NULL) { + free_location(item->target); + item->target = NULL; + } + + if (item->anchor != NULL) { + free_anchor(item->anchor); + item->anchor = NULL; + } + + switch (item->data_type) { + 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->content_type != NULL) { + free(item->content_type); + item->content_type = NULL; + } + + free(item); + item = NULL; + + _EXTERN_FUNC_EXIT; + return; +} + +chal_s *dup_chal(chal_s * chal) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(chal == NULL, NULL, "chal is NULL"); + + chal_s *temp = (chal_s *) calloc(1, sizeof(chal_s)); + retvm_if(temp == NULL, NULL, "temp is NULL"); + + if (chal->nonce_b64 != NULL) + temp->nonce_b64 = strdup(chal->nonce_b64); + + if (chal->nonce_plain != NULL) + temp->nonce_plain = strdup(chal->nonce_plain); + + temp->type = chal->type; + temp->format = chal->format; + temp->nonce_length = chal->nonce_length; + + _EXTERN_FUNC_EXIT; + return temp; +} + +cred_s *dup_cred(cred_s * cred) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(cred == NULL, NULL, "cred is NULL"); + + cred_s *temp = (cred_s *) calloc(1, sizeof(cred_s)); + retvm_if(temp == NULL, NULL, "temp is NULL"); + + temp->type = cred->type; + temp->format = cred->format; + + if (cred->user_name != NULL) + temp->user_name = strdup(cred->user_name); + + if (cred->password != NULL) + temp->password = strdup(cred->password); + + if (cred->data != NULL) + temp->data = strdup(cred->data); + + _EXTERN_FUNC_EXIT; + return temp; +} + +sa_error_type_e compare_cred(cred_s * hdr_cred, cred_s * session_cred) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (hdr_cred == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (session_cred == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (strcmp(hdr_cred->data, session_cred->data) == 0) + errorType = SA_INTERNAL_OK; + else + errorType = SA_INTERNAL_AUTHENTICATION_ERROR; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +auth_type_e convert_auth_type(char *auth_type) +{ + _EXTERN_FUNC_ENTER; + retvm_if(auth_type == NULL, AUTH_TYPE_UNKNOWN, "authType is NULL"); + + if (!strcmp(auth_type, ELEMENT_AUTH_BASIC)) { + return AUTH_TYPE_BASIC; + } else if (!strcmp(auth_type, ELEMENT_AUTH_MD5)) { + return AUTH_TYPE_MD5; + } + + _EXTERN_FUNC_EXIT; + return AUTH_TYPE_UNKNOWN; +} + +format_type_e convert_format_type(char *format_type) +{ + _EXTERN_FUNC_ENTER; + if (format_type == NULL) + return FORMAT_TYPE_UNKNOWN; + + if (!strcmp(format_type, ELEMENT_FORMAT_BASE64)) { + return FORMAT_TYPE_BASE64; + } + + _EXTERN_FUNC_EXIT; + return FORMAT_TYPE_UNKNOWN; +} + +mem_s *create_mem() +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + mem_s *mem = (mem_s *) calloc(1, sizeof(mem_s)); + if (mem == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + _EXTERN_FUNC_EXIT; + return mem; + + error: + + _EXTERN_FUNC_EXIT; + return NULL; +} + +void set_mem_shared_mem(mem_s * mem, int shared_mem) +{ + _EXTERN_FUNC_ENTER; + + retm_if(mem == NULL, "mem is NULL"); + + mem->sharedmem = shared_mem; + + _EXTERN_FUNC_EXIT; +} + +void set_mem_free_mem(mem_s * mem, unsigned int free_mem) +{ + _EXTERN_FUNC_ENTER; + + retm_if(mem == NULL, "mem is NULL"); + + mem->free_mem = free_mem; + + _EXTERN_FUNC_EXIT; +} + +void set_mem_free_id(mem_s * mem, unsigned int free_id) +{ + _EXTERN_FUNC_ENTER; + + retm_if(mem == NULL, "mem is NULL"); + + mem->free_id = free_id; + + _EXTERN_FUNC_EXIT; +} diff --git a/src/agent/service-adapter/sa_session.c b/src/agent/service-adapter/sa_session.c new file mode 100755 index 0000000..3ff27a1 --- /dev/null +++ b/src/agent/service-adapter/sa_session.c @@ -0,0 +1,1578 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 + */ + +#include + +#include "common/common_util.h" +#include "service-adapter/sa_session.h" +#include "service-adapter/sa_session_internal.h" +#include "service-adapter/sa_elements.h" +#include "service-adapter/sa_elements_internal.h" +#include "service-adapter/sa_command.h" +#include "service-adapter/sa_command_internal.h" +#include "service-adapter/sa_devinf.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SA" +#endif + +static sa_error_type_e _receive_alert_status(session_s * session, status_s * status); +static sa_error_type_e _receive_put_status(session_s * session, status_s * status); +static sa_error_type_e _receive_get_status(session_s * session, status_s * status); +static sa_error_type_e _receive_results_status(session_s * session, status_s * status); +static sa_error_type_e _receive_sync_status(session_s * session, status_s * status); +static sa_error_type_e _receive_changes_status(session_s * session, status_s * status, GList ** return_status); +static sa_error_type_e _receive_map_status(session_s * session, status_s * status); + +static sa_error_type_e _receive_alert_command(session_s * session, command_s * command, GList ** return_datastore); +static sa_error_type_e _receive_put_command(session_s * session, command_s * command); +static sa_error_type_e _receive_get_command(session_s * session, command_s * command); +static sa_error_type_e _receive_results_command(session_s * session, command_s * command); +static sa_error_type_e _receive_sync_command(session_s * session, command_s * command, changed_datastore_s ** changed_datastore); +static sa_error_type_e _receive_changes_command(session_s * session, command_s * command, char **luid_str_list, int *index, changed_datastore_s ** changed_datastore); + +static void __free_pending_status(command_status_s * command_status); +static sa_error_type_e __add_mapping(session_s * session, char *guid, char *luid, int datastore_id); + +static sa_error_type_e _receive_alert_status(session_s * session, status_s * status) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + unsigned int code = get_status_code(status); + _DEBUG_TRACE("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 */ + + } + } + + /* delete mapping when receive 508 status for alert command */ + if (code == ERROR_REQUIRE_REFRESH) { + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + + sync_agent_da_delete_mapping_query_s query; + query.option = SYNC_AGENT_DA_DELETE_MAPPING_OPTION_ACCOUNT_ID; + query.account_id = session->account_id; + + ret = sync_agent_delete_mapping(&query); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_delete_mapping !!"); + } + } + + /* TODO off resume flag if status is not 200 */ + if (session->pkg_status == SYNCML_SUSPEND) { + if (code != 200) { + errorType = SA_INTERNAL_SUSPEND_FAIL; + } + } + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_put_status(session_s * session, status_s * status) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + unsigned int code = get_status_code(status); + _DEBUG_TRACE("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; + } + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_get_status(session_s * session, status_s * status) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + unsigned int code = get_status_code(status); + _DEBUG_TRACE("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; + } + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_results_status(session_s * session, status_s * status) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + unsigned int code = get_status_code(status); + _DEBUG_TRACE("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; + } + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_sync_status(session_s * session, status_s * status) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + unsigned int code = get_status_code(status); + _DEBUG_TRACE("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; + } + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_changes_status(session_s * session, status_s * status, GList ** return_status) +{ + _INNER_FUNC_ENTER; + + _DEBUG_TRACE("cmdID = %d", status->cmd_id); + _DEBUG_TRACE("msgRef = %d", status->msg_ref); + _DEBUG_TRACE("cmdRef = %d", status->cmd_ref); + _DEBUG_TRACE("type = %d", status->type); + _DEBUG_TRACE("data = %s", status->data); + + unsigned int code = get_status_code(status); + _DEBUG_TRACE("code = %d", code); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (session->large_obj != NULL) { + /*LargeObj status it does not need to pass engine */ + command_status_s *largeObj = session->large_obj; + if (largeObj->cmd_id == status->cmd_ref && largeObj->msg_id == status->msg_ref) { + + if (code == CHUNK_ACCEPTED) { + __free_pending_status(largeObj); + session->large_obj = 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->source_ref != NULL) { + applied_status_s *appliedStatus = create_applied_status(get_location_loc_uri(status->source_ref), + convert_change_type_command_type(status->type), code); + if (appliedStatus == NULL) { + _DEBUG_ERROR("failed in create_appliedstatus"); + return SA_INTERNAL_NO_MEMORY; + } + *return_status = g_list_append(*return_status, appliedStatus); + } + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_map_status(session_s * session, status_s * status) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + sync_agent_da_return_e da_err; + + GList *iter = NULL; + command_s *pCommand = NULL; + unsigned int code = 0; + for (iter = session->map_command; iter != NULL; iter = g_list_next(iter)) { + pCommand = iter->data; + + if (pCommand->msg_id == status->msg_ref && pCommand->cmd_id == status->cmd_ref) { + code = get_status_code(status); + _DEBUG_TRACE("code = %d", code); + + if (code == 200) { + GList *itemIter = NULL; + item_s *item = NULL; + for (itemIter = pCommand->private.map.items; itemIter != NULL; itemIter = g_list_next(itemIter)) { + item = itemIter->data; + _DEBUG_TRACE(" LUID = %s has been removed\n", get_location_loc_uri(item->source)); + + sync_agent_da_delete_mapping_query_s query; + query.option = SYNC_AGENT_DA_DELETE_MAPPING_OPTION_LUID; + query.account_id = session->account_id; + query.luid = get_location_loc_uri(item->source); + + da_err = sync_agent_delete_mapping(&query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + errorType = SA_INTERNAL_DA_ERROR; + _DEBUG_ERROR("failed in sync_agent_delete_mapping !!"); + return errorType; + } + } + session->map_command = g_list_remove(session->map_command, 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_s *item = NULL; + for (itemIter = pCommand->private.map.items; itemIter != NULL; itemIter = g_list_next(itemIter)) { + item = itemIter->data; + _DEBUG_TRACE("LUID = %s has been removed\n", get_location_loc_uri(item->source)); + + sync_agent_da_delete_mapping_query_s query; + query.option = SYNC_AGENT_DA_DELETE_MAPPING_OPTION_LUID; + query.account_id = session->account_id; + query.luid = get_location_loc_uri(item->source); + + da_err = sync_agent_delete_mapping(&query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + errorType = SA_INTERNAL_DA_ERROR; + _DEBUG_ERROR("failed in sync_agent_delete_mapping !!"); + return errorType; + } + } + session->map_command = g_list_remove(session->map_command, 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; + /* for prevent */ +// else if (code == ERROR_GENERIC) +// errorType = SA_INTERNAL_SERVER_ERROR; + else + errorType = SA_INTERNAL_ERROR; + } + } + } + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_alert_command(session_s * session, command_s * command, GList ** return_datastore) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + status_s *temp = NULL; + + if (command->source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (command->target == NULL) { + 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 */ + +// 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; +// } +// +// if (command->private.alert.anchor != NULL){ +// set_datastoreinfo_lastanchor(datastore, command->private.alert.anchor->lastAnchor); +// set_datastoreinfo_nextanchor(datastore, command->private.alert.anchor->nextAnchor); +// } +// +// set_datastoreInfo_synctype(datastore, command->private.alert.type); +// 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 == NULL) { +// 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; + + int content_type; + bool is_data_store = false; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) + if (strcmp(get_location_loc_uri(command->target), datastoreinfo_per_content_type[content_type]->source) == 0) { + is_data_store = true; + break; + } + } + + if (is_data_store) { + datastore_info_s *datastore = create_datastore_info(get_location_loc_uri(command->target), get_location_loc_uri(command->source)); + if (datastore == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + if (command->private.alert.anchor != NULL) { + set_datastore_info_last_anchor(datastore, command->private.alert.anchor->last_anchor); + set_datastore_info_next_anchor(datastore, command->private.alert.anchor->next_anchor); + } + + set_datastore_info_sync_type(datastore, command->private.alert.type); + set_datastore_info_max_obj_size(datastore, command->private.alert.max_obj_size); + + *return_datastore = g_list_append(*return_datastore, 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 == NULL) { + 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_loc_uri(command->target), get_location_loc_uri(session->source)) == 0 && strcmp(get_location_loc_uri(command->source), get_location_loc_uri(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; + + _INNER_FUNC_ENTER; + 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); + + _INNER_FUNC_ENTER; + return SA_INTERNAL_NOT_FOUND; + + error: + + if (temp != NULL) + free(temp); + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_put_command(session_s * session, command_s * command) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e 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_s *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 != NULL) { + session->remote_devinf = 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); + + _INNER_FUNC_ENTER; + 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); + + _INNER_FUNC_ENTER; + return SA_INTERNAL_NOT_FOUND; + + error: + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_get_command(session_s * session, command_s * command) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + status_s *temp = NULL; + command_s *pCommand = NULL; + location_s *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->protocol_version == VERSION_10) + sourceDevInf = ELEMENT_DEVINF_10; + else if (session->protocol_version == VERSION_11) + sourceDevInf = ELEMENT_DEVINF_11; + else if (session->protocol_version == 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_msg_ref(pCommand, command->msg_id); + set_results_command_cmd_ref(pCommand, command->cmd_id); + set_results_command_target_ref(pCommand, command->private.access.item->target); + + session->results_command = g_list_append(session->results_command, pCommand); + } else + goto not_found_error; + + _INNER_FUNC_ENTER; + 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); + + _INNER_FUNC_ENTER; + return SA_INTERNAL_NOT_FOUND; + + error: + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_results_command(session_s * session, command_s * command) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + status_s *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 != NULL) { + session->remote_devinf = 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; + + _INNER_FUNC_ENTER; + 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); + + _INNER_FUNC_ENTER; + return SA_INTERNAL_NOT_FOUND; + + error: + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_sync_command(session_s * session, command_s * command, changed_datastore_s ** changed_datastore) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + status_s *temp = NULL; + + retvm_if(command == NULL, SA_INTERNAL_NOT_DEFINED, "command is NULL"); + + retvm_if(command->source == NULL, SA_INTERNAL_NOT_DEFINED, "command->source is NULL"); + retvm_if(command->target == NULL, SA_INTERNAL_NOT_DEFINED, "command->target is NULL"); + + /*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); +// +// _DEBUG_TRACE("hasNumChanged = %d",command->private.sync.hasNumChanged); +// _DEBUG_TRACE("numberOfChanges = %d",command->private.sync.numChanged); +// +// /*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; + + int content_type; + bool exist = false; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) + if (strcmp(get_location_loc_uri(command->target), datastoreinfo_per_content_type[content_type]->source) == 0) { + exist = true; + break; + } + } + + if (!exist) + goto not_found_error; + + 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); + + _DEBUG_TRACE("hasNumChanged = %d", command->private.sync.has_num_changed); + _DEBUG_TRACE("numberOfChanges = %d", command->private.sync.num_changed); + + /*for return to engine */ + changed_datastore_s *pChangedDatastore = create_changed_datastore(get_location_loc_uri(command->source), + get_location_loc_uri(command->target), command->private.sync.has_num_changed, + command->private.sync.has_num_changed ? command->private.sync.num_changed : 0); + if (pChangedDatastore == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } else + *changed_datastore = pChangedDatastore; + + _INNER_FUNC_ENTER; + 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); + + _INNER_FUNC_ENTER; + return SA_INTERNAL_NOT_FOUND; + + error: + + _INNER_FUNC_ENTER; + return errorType; +} + +static sa_error_type_e _receive_changes_command(session_s * session, command_s * command, char **luid_str_list, int *index, changed_datastore_s ** changed_datastore) +{ + _INNER_FUNC_ENTER; + _DEBUG_TRACE("start command type : %d\n", command->private.change.type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + GList *iter = NULL; + changed_item_s *changed = NULL; + char *luid; + change_type_e changeType = command->private.change.type; + for (iter = command->private.change.items; iter != NULL; iter = g_list_next(iter)) { + item_s *changedItem = (iter->data); + + if (changedItem->more_data) { + if (session->large_obj_cmd != NULL) { + /*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_s *pLargeObjcmd = session->large_obj_cmd; + if (pLargeObjcmd->private.change.items != NULL) { + /*moreData item must be last item in item list */ + GList *largeObjItems = session->large_obj_cmd->private.change.items; + GList *largeObjLastItem = g_list_nth(largeObjItems, g_list_length(largeObjItems) - 1); + item_s *item = largeObjLastItem->data; + alert_type_e alertType = ALERT_UNKNOWN; + if (strcmp(get_location_loc_uri(item->source), get_location_loc_uri(changedItem->source)) == 0) { + /*two item's source are equal + append incomming string */ + if (item->private.data != NULL) { + 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_s *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) { + _DEBUG_ERROR("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_s *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) { + _DEBUG_ERROR("failed in create_alert_command"); + goto error; + } + session->alert_command = g_list_append(session->alert_command, pAlertCommand); + } + } else { + /*first chunked item + just buffered it. does not generate LUID, and does not pass to engine */ + oma_status_type_e statusErrorType = ERROR_UNKNOWN; + if (changedItem->size == 0) { + /*size required */ + statusErrorType = ERROR_SIZE_REQUIRED; + } else { + /* size is specified */ + if (changedItem->size > session->source_max_obj_size) { + /*but it is bigger than client maxObjSize */ + statusErrorType = ERROR_REQUESTED_SIZE_TOO_BIG; + } else { + /*chunked item accepted */ + session->large_obj_cmd = command; + increase_command_ref_count(command); + + statusErrorType = CHUNK_ACCEPTED; + + /* create alert command */ + command_s *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) { + _DEBUG_ERROR("failed in create_alert_command"); + goto error; + } + session->alert_command = g_list_append(session->alert_command, pAlertCommand); + } + + status_s *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) { + _DEBUG_ERROR("failed in create_new_status_location"); + goto error; + } + session->status = g_list_append(session->status, temp); + } + } + } else { + if (session->large_obj_cmd != NULL) { + + /*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_s *pLargeObjcmd = session->large_obj_cmd; + if (pLargeObjcmd->private.change.items != NULL) { + /*moreData item must be last item in item list */ + GList *largeObjItems = session->large_obj_cmd->private.change.items; + GList *largeObjLastItem = g_list_nth(largeObjItems, g_list_length(largeObjItems) - 1); + item_s *item = largeObjLastItem->data; + + if (strcmp(get_location_loc_uri(item->source), get_location_loc_uri(changedItem->source)) == 0) { + /* two item's source are equal + append incomming string */ + if (item->private.data != NULL) { + 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) { + _DEBUG_ERROR("item->private.data is null !!"); + goto error; + } + } + + if (item->size == strlen(item->private.data)) { + /*delete pointing from pLargeObjCmd */ + largeObjLastItem->data = NULL; + _DEBUG_TRACE("delete pointing from pLargeObjCmd"); + /*free Item from incomming Cmd */ + free_item(changedItem); + _DEBUG_TRACE("free Item from incomming Cmd"); + /*pointing to Merged item in incomming Cmd */ + iter->data = item; + changedItem = item; + _DEBUG_TRACE("pointing to Merged item in incomming Cmd"); + + free_command(session->large_obj_cmd); + session->large_obj_cmd = NULL; + } else { + status_s *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) { + _DEBUG_ERROR("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_s *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) { + _DEBUG_ERROR("failed in create_alert_command"); + goto error; + } + session->alert_command = g_list_append(session->alert_command, pAlertCommand); + } + } + } + if (changeType == CHANGE_ADD) { + int datastore_id = 0; + if (strcmp(changedItem->content_type, ELEMENT_TEXT_VCARD) == 0 || strcmp(changedItem->content_type, ELEMENT_TEXT_VCARD_30) == 0) + datastore_id = TYPE_CONTACT; + else if (strcmp(changedItem->content_type, ELEMENT_TEXT_VCAL) == 0) + datastore_id = TYPE_CALENDAR; + else if (strcmp(changedItem->content_type, ELEMENT_TEXT_PLAIN) == 0) + datastore_id = TYPE_MEMO; + + luid = luid_str_list[(*index)++]; + if (luid == NULL) { + _DEBUG_ERROR("luid is null"); + errorType = SA_INTERNAL_ERROR; + goto error; + } + + _DEBUG_TRACE("index = %d", *index); + _DEBUG_TRACE("luid = %s", luid); + + errorType = __add_mapping(session, get_location_loc_uri(changedItem->source), luid, datastore_id); + if (errorType != SA_INTERNAL_OK) { + _DEBUG_ERROR("failed in __add_mapping"); + goto error; + } + } else { + luid = get_location_loc_uri(changedItem->target); + if (luid == NULL) { + _DEBUG_ERROR("luid is null"); + errorType = SA_INTERNAL_ERROR; + goto error; + } + } + + changed = create_changed_item(changeType, luid); + if (changed == NULL) { + _DEBUG_ERROR("changed is null"); + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + if (changeType != CHANGE_DELETE) { + set_changed_item_content_type(changed, changedItem->content_type); + set_changed_item_data(changed, changedItem->private.data); + } + + status_s *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) { + _DEBUG_ERROR("failed in create_new_status_location"); + goto error; + } + session->temp_status = g_list_append(session->temp_status, temp); + + (*changed_datastore)->change_item = g_list_append((*changed_datastore)->change_item, changed); + changed = NULL; + } + } + + error: + + if (changed != NULL) + free_changed_item(changed); + + _INNER_FUNC_ENTER; + return errorType; +} + +static void __free_pending_status(command_status_s * command_status) +{ + _INNER_FUNC_ENTER; + + retm_if(command_status == NULL, "pendingStatus is NULL"); + + free(command_status); + command_status = NULL; + + _INNER_FUNC_EXIT; + return; +} + +static sa_error_type_e __add_mapping(session_s * session, char *guid, char *luid, int datastore_id) +{ + _INNER_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_ERRORS; + + sync_agent_da_mapping_s *mapping = NULL; + da_err = sync_agent_create_mapping(&mapping); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_mapping !!"); + goto error; + } + + mapping->account_id = session->account_id; + mapping->data_store_id = datastore_id; + mapping->luid = strdup(luid); + mapping->guid = strdup(guid); + mapping->access_name = strdup("SA"); + + _DEBUG_VERBOSE("account_id = %d", mapping->account_id); + _DEBUG_VERBOSE("data_store_id = %d", mapping->data_store_id); + _DEBUG_VERBOSE("luid = %s", mapping->luid); + _DEBUG_VERBOSE("guid = %s", mapping->guid); + _DEBUG_VERBOSE("access_name = %s", mapping->access_name); + + da_err = sync_agent_add_mapping(mapping); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_add_mapping = %d", da_err); + sync_agent_free_mapping(mapping); + errorType = SA_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_free_mapping(mapping); + + error: + + _INNER_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_session(protocol_version_e protocol_version, protocol_type_e protocol_type, int account_id, char *sess_id, location_s * source_location, location_s * target_location, session_s ** session) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + *session = (session_s *) calloc(1, sizeof(session_s)); + if (*session == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + if (sess_id != NULL) + (*session)->session_id = strdup(sess_id); + + if (source_location != NULL) + (*session)->source = source_location; + + if (target_location != NULL) + (*session)->target = target_location; + + (*session)->protocol_type = protocol_type; + (*session)->protocol_version = protocol_version; + (*session)->account_id = account_id; + + (*session)->msg_id = 0; + (*session)->cmd_id = 1; + + (*session)->source_max_msg_size = OMA_DS_HTTP_DEFAULT_CLIENT_MAX_MSG_SIZE; + (*session)->source_max_obj_size = OMA_DS_HTTP_DEFAULT_CLIENT_MAX_OBJ_SIZE; + + (*session)->target_max_msg_size = 0; + (*session)->target_max_obj_size = 0; + + (*session)->naci_session_id = 0; + (*session)->has_opend = 0; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void free_session(session_s * session) +{ + _EXTERN_FUNC_ENTER; + + retm_if(session == NULL, "session is NULL"); + + if (session->session_id != NULL) { + free(session->session_id); + session->session_id = NULL; + } + + if (session->jsession_id != NULL) { + free(session->jsession_id); + session->jsession_id = NULL; + } + + _DEBUG_INFO("session->status"); + free_statuses(session->status); + session->status = NULL; + + _DEBUG_INFO("session->tempStatus"); + free_statuses(session->temp_status); + session->temp_status = NULL; + + _DEBUG_INFO("session->suspendStatus"); + free_statuses(session->suspend_status); + session->suspend_status = NULL; + + if (session->target != NULL) { + free_location(session->target); + session->target = NULL; + } + + if (session->source != NULL) { + free_location(session->source); + session->source = NULL; + } + + if (session->org_target != NULL) { + free_location(session->org_target); + session->org_target = NULL; + } + + if (session->cred != NULL) { + free_cred(session->cred); + session->cred = NULL; + } + + if (session->chal != NULL) { + free_chal(session->chal); + session->chal = NULL; + } + + if (session->devinf != NULL) { + free_devinf(session->devinf); + session->devinf = NULL; + } + + if (session->remote_devinf != NULL) { + free_devinf(session->remote_devinf); + session->remote_devinf = NULL; + } + + if (session->large_obj_cmd != NULL) { + free_command(session->large_obj_cmd); + session->large_obj_cmd = NULL; + } + + free_commands(session->map_command); + session->map_command = NULL; + + free_commands(session->alert_command); + session->alert_command = NULL; + + free_commands(session->results_command); + session->results_command = NULL; + + if (session->large_obj != NULL) + free(session->large_obj); + + if (session != NULL) + free(session); + + _EXTERN_FUNC_EXIT; + return; +} + +sa_error_type_e create_command_status(unsigned int msg_id, unsigned int cmd_id, command_status_s ** command_status) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + *command_status = (command_status_s *) calloc(1, sizeof(command_status_s)); + if (*command_status == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command_status)->msg_id = msg_id; + (*command_status)->cmd_id = cmd_id; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void set_session_cred(session_s * session, cred_s * cred) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (session == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (cred == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + session->cred = cred; + + error: + + _EXTERN_FUNC_EXIT; + return; + +} + +void set_session_devinf(session_s * session, devinf_s * devinf) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (session == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (devinf == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + session->devinf = devinf; + + error: + + _EXTERN_FUNC_EXIT; + return; + +} + +sa_error_type_e receive_header(session_s * session, sync_hdr_s * header) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + location_s *pLocation = NULL; + + if (session == NULL) { + _DEBUG_ERROR("session is NULL"); + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (header == NULL) { + _DEBUG_ERROR("header is NULL"); + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + if (session->session_id && header->session_id) { + if (strcmp(session->session_id, header->session_id) != 0) { + errorType = SA_INTERNAL_SERVER_ERROR; + goto error; + } + } + + session->last_recieved_msg_id = header->message_id; + + if (0 < header->max_msg_size) + session->target_max_msg_size = header->max_msg_size; + else + session->target_max_msg_size = OMA_DS_HTTP_DEFAULT_SERVER_MAX_MSG_SIZE; + + if (0 < header->max_obj_size) + session->target_max_obj_size = header->max_obj_size; + + if (header->response_uri != NULL) { + if (session->org_target == NULL) { + session->org_target = session->target; + session->target = NULL; + } + + if (session->target != NULL) + free_location(session->target); + + errorType = create_location(header->response_uri, get_location_loc_name(session->org_target), &pLocation); + if (errorType != SA_INTERNAL_OK) + goto error; + session->target = pLocation; + + if (session->target == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + } + + status_s *temp = NULL; + oma_status_type_e statusData = ERROR_UNKNOWN; + if (header->cred != NULL) { + 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->cmd_id++, session->last_recieved_msg_id, 0, header->source, header->target, COMMAND_TYPE_HEADER, &temp); + if (errorType != SA_INTERNAL_OK) + goto error; + + session->status = g_list_append(session->status, temp); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e receive_statuses(session_s * session, GList * receive_status, GList ** return_status) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + GList *statusItem = receive_status; + status_s *status = NULL; + while (statusItem) { + status = statusItem->data; + + if (status->cmd_ref == 0) { + /*status of SyncHdr */ + assert(status->type == COMMAND_TYPE_HEADER); + assert(status->data); + oma_status_type_e statusType = atoi(status->data); + + /* TODO off resume flag if status is 400(bad request) */ + if (session->pkg_status == SYNCML_SUSPEND) { + if (statusType == ERROR_BAD_REQUEST) { + errorType = SA_INTERNAL_SUSPEND_FAIL; + goto error; + } + } + + 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_s *chal = status->chal; + if (chal != NULL) { + /*chal in status have to be stored in config_tbl because it have to be used next sync session */ + _DEBUG_INFO("format type :%d", chal->format); + + char *value; + sync_agent_da_config_s config; + config.config_id = session->account_id; + + if (chal->format == FORMAT_TYPE_BASE64) + value = chal->nonce_b64; + else + value = g_base64_encode((unsigned char *)chal->nonce_plain, chal->nonce_length); + + bool result = set_config_str(session->account_id, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, value, "string", "SA"); + if (result == false) { + errorType = SA_INTERNAL_ERROR; + _DEBUG_ERROR("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 != NULL) { + /*if there is a chal in status duplicate to session + chal have to used when next request is sent */ + if (session->chal != NULL) { + free_chal(session->chal); + session->chal = NULL; + } + session->chal = status->chal; + status->chal = NULL; + } + } + } else if (statusType == ERROR_AUTH_REQUIRED || statusType == ERROR_AUTH_REJECTED) { + if (status->chal != NULL) { + if (session->chal != NULL) { + free_chal(session->chal); + session->chal = NULL; + } + session->chal = status->chal; + status->chal = NULL; + } + 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, return_status); + } + + if (errorType != SA_INTERNAL_OK) + goto error; + } + statusItem = g_list_next(statusItem); + } + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e receive_commands(session_s * session, GList * receive_command, bool auto_config, GList ** return_datastore) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + int item_luid_count = 0; + int index = 0; + int i; + char **luid_str_list = NULL; + changed_datastore_s *changedDatastore = NULL; + + GList *iter = NULL; + command_s *command = NULL; + for (iter = receive_command; 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); + } + + _DEBUG_INFO("item_luid_count = %d", item_luid_count); + + if (item_luid_count > 0) { + luid_str_list = sync_agent_generate_item_luid(1, item_luid_count); + if (luid_str_list == NULL) { + _DEBUG_ERROR("failed in sync_agent_generate_item_luid"); + errorType = SA_INTERNAL_ERROR; + goto error; + } + } + + for (iter = receive_command; iter != NULL; iter = g_list_next(iter)) { + command = iter->data; + + if (auto_config != true || (auto_config == 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, return_datastore); + 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 != NULL) { + if (changedDatastore->has_number_of_changes || g_list_length(changedDatastore->change_item) > 0) { + *return_datastore = g_list_append(*return_datastore, changedDatastore); + changedDatastore = NULL; + } else { + if (changedDatastore != NULL) { + free_changed_datastore(changedDatastore); + changedDatastore = NULL; + } + } + } + } + break; + case COMMAND_TYPE_ADD: + case COMMAND_TYPE_REPLACE: + case COMMAND_TYPE_DELETE: + { + if (command->type != COMMAND_TYPE_ADD || luid_str_list != NULL) { + errorType = _receive_changes_command(session, command, luid_str_list, &index, &changedDatastore); + } else { + _DEBUG_ERROR("luid_str_list is NULL !!"); + errorType = SA_INTERNAL_ERROR; + if (changedDatastore != NULL) { + free_changed_datastore(changedDatastore); + changedDatastore = NULL; + } + goto error; + } + } + break; + } + + if (errorType != SA_INTERNAL_OK) { + if (changedDatastore != NULL) { + free_changed_datastore(changedDatastore); + changedDatastore = NULL; + } + goto error; + } + } + } + + error: + + if (changedDatastore != NULL) + free_changed_datastore(changedDatastore); + + 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); + } + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void reset_cmd_id_session(session_s * session) +{ + _EXTERN_FUNC_ENTER; + + if (session != NULL) + session->cmd_id = 1; + + _EXTERN_FUNC_EXIT; +} diff --git a/src/agent/service-adapter/sa_util.c b/src/agent/service-adapter/sa_util.c new file mode 100755 index 0000000..6538765 --- /dev/null +++ b/src/agent/service-adapter/sa_util.c @@ -0,0 +1,177 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @SA_Util.c + * @version 0.1 + * @brief This file is the source file of implementation of utility function + */ + +#include + +#include "service-adapter/sa_util.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SA" +#endif + +void put_into_list(GList ** commands, GList ** commands_last, void *command) +{ + _EXTERN_FUNC_ENTER; + + GList *temp = NULL; + if (*commands_last == NULL) { + *commands_last = *commands = g_list_append(*commands, command); + } else { + temp = g_list_append(*commands_last, command); + *commands_last = g_list_next(*commands_last); + } + + _EXTERN_FUNC_EXIT; +} + +sa_error_type_e create_cred_string(auth_type_e type, const char *user_name, const char *password, const char *nonce, unsigned int nonce_size, char **cred) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errortype = SA_INTERNAL_OK; + + switch (type) { + case AUTH_TYPE_BASIC: + { + char *plain = g_strjoin(":", user_name, password, NULL); + *cred = g_base64_encode((unsigned char *)plain, strlen(plain)); + if (*cred == 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(":", user_name, password, NULL); + _DEBUG_INFO("username:password = %s", auth); + unsigned char *digest = NULL; + digest = sync_agent_encrypt_cryptograhic_hash(SYNC_AGENT_SA_CRYPTOGRAHIC_HASH_FUNTION_MD5, auth, strlen(auth)); + free(auth); + *cred = g_base64_encode(digest, 16); + free(digest); + if (*cred == NULL) { + errortype = SA_INTERNAL_NO_MEMORY; + goto error; + } + + if (nonce != NULL) { + _DEBUG_INFO("nonce = %s", nonce); + _DEBUG_INFO("nonce_size = %d", nonce_size); + + int auth_size = strlen(*cred) + nonce_size + 1; + auth = (char *)calloc(auth_size + 1, sizeof(char)); + if (auth == NULL) { + _DEBUG_ERROR("auth is NULL"); + errortype = SA_INTERNAL_NO_MEMORY; + goto error; + } + + memcpy(auth, *cred, strlen(*cred)); + auth[strlen(*cred)] = ':'; + memcpy(auth + strlen(*cred) + 1, nonce, nonce_size); + _DEBUG_INFO("base64[md5[username:password]] = %s", *cred); + _DEBUG_INFO("before last base64 encoding = %s", auth); + free(*cred); + + /*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)); + if (digest == NULL) { + _DEBUG_ERROR("digest is NULL"); + errortype = SA_INTERNAL_NO_MEMORY; + goto error; + } + g_checksum_get_digest(pMd5, digest, &temp); + */ + + digest = sync_agent_encrypt_cryptograhic_hash(SYNC_AGENT_SA_CRYPTOGRAHIC_HASH_FUNTION_MD5, auth, auth_size); + _DEBUG_INFO("md5[base64[md5[username:password]]] = %s", digest); + + free(auth); + *cred = g_base64_encode(digest, 16); + free(digest); + _DEBUG_INFO("base64[md5[base64[md5[username:password]]]] = %s", *cred); + if (*cred == NULL) { + errortype = SA_INTERNAL_NO_MEMORY; + goto error; + } + } + break; + case AUTH_TYPE_UNKNOWN: + break; + + } + } + + error: + + _EXTERN_FUNC_EXIT; + return errortype; +} + +void set_xml_to_file(char *xml, const char *path) +{ + _EXTERN_FUNC_ENTER; + + FILE *pFile = NULL; + + if (xml != NULL) + pFile = fopen(path, "a"); + + retm_if(pFile == NULL, "pFile is NULL"); + + fputs("==================================================================================", pFile); + fputs("\n", pFile); + + if (xml != NULL) + fputs(xml, pFile); + + if (xml != NULL) + fclose(pFile); + + _EXTERN_FUNC_EXIT; +} diff --git a/src/agent/service-engine/se_account.c b/src/agent/service-engine/se_account.c new file mode 100755 index 0000000..803f9d3 --- /dev/null +++ b/src/agent/service-engine/se_account.c @@ -0,0 +1,1865 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @SE_Account.c + * @version 0.1 + * @brief This file is the source file of implementation of account in Service Engine + */ + +#include +#include + +#include "common/csc_keys.h" +#include "common/common_vconf.h" +#include "common/common_define.h" +#include "common/common_util.h" +#include "framework/event/oma_ds_platform_event_handler.h" +#include "service-engine/se_account.h" +#include "service-engine/se_error.h" +#include "service-engine/se_common.h" +#include "service-engine/se_notification.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SE" +#endif + +#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"}}, + {{"Contacts", "text/x-vcard"}, {"Calendar", "text/x-vcalendar"}, {"Notes", "text/plain"}} +}; + +static datastore_cp_info predefinedServer[] = { + {"O3SIS SyncML", 0}, + {"Everdroid", 1} +}; + +static se_error_type_e _add_profile(char *addr, char *id, char *password, char *access_name, int *account_id); +static se_error_type_e _set_profile_info(int account_id, char *profile_name, char *sync_mode, char *sync_type, char *interval); +static se_error_type_e _set_profile_category(int account_id, sync_service_s * category); +static se_error_type_e _set_periodic_sync_config(int account_id, char *sync_mode, char *interval); +static se_error_type_e _get_empty_profile_dir_name(char **empty_profile_dir_name); + +static se_error_type_e _set_profile_info_into_config_list(int account_id, char *profile_dir_name, char *addr, char *profile_name, char *sync_mode, char *sync_type, char *interval, char *nonce, char *server_id, GList ** config_list); +static se_error_type_e _set_profile_category_info(int account_id, sync_service_s * category, GList ** config_list); +static se_error_type_e _set_profile_category_info_csc(int account_id, int content_type, int index, GList ** config_list); +static se_error_type_e _set_profile_category_info_cp(int account_id, int content_type, resource_cp_s * category, GList ** config_list); +static se_error_type_e __set_profile_category_info_into_cofnig_list(int account_id, int content_type, int enabled, char *src_uri, char *tgt_uri, char *id, char *password, GList ** config_list); +static se_error_type_e ___append_config_value(int account_id, char *key, char *value, char *type, char *access_name, GList ** list); + +static se_error_type_e _add_profile(char *addr, char *id, char *password, char *access_name, int *account_id) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_acc_error_e account_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + + int account; + char *folderID = NULL; + + account_err = sync_agent_create_fw_account(&fw_account); + if (account_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_create_fw_account is fail"); + err = SE_INTERNAL_ERROR; + goto error; + } + + fw_account->email = strdup(id); + fw_account->password = strdup(password); + fw_account->enable = 1; + fw_account->access_name = strdup(access_name); + + account_err = sync_agent_add_fw_account(fw_account, &account); + if (account_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_add_fw_account is fail"); + err = SE_INTERNAL_ERROR; + goto error; + } + + _DEBUG_TRACE("account_id = %d", account); + + if (account < 0) { + _DEBUG_ERROR("account_id = %d", account); + err = SE_INTERNAL_ERROR; + goto error; + } + + folderID = sync_agent_generate_folder_luid(); + if (folderID == NULL) { + _DEBUG_ERROR("failed in sync_agent_generate_folder_luid"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_da_return_e ret = SYNC_AGENT_DA_ERRORS; + sync_agent_da_folder_s *folder = NULL; + ret = sync_agent_create_folder(&folder); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_create_folder() failed !!"); + goto error; + } + + folder->account_id = account; + folder->folder_id = strdup(folderID); + folder->data_store_id = TYPE_CONTACT; + folder->folder_type_id = 0; /* Default contacts folder */ + folder->parent_folder_id = NULL; + folder->service_id = strdup("0"); + folder->access_name = strdup("EventHandler"); + + char *new_folder_id = NULL; + ret = sync_agent_add_folder(folder, &new_folder_id); + sync_agent_free_folder(folder); + folder = NULL; + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("Agent Add_Folder Failed_In sync_agent_add_account()!"); + _DEBUG_ERROR("[process_Event_Add_Account] Agent Add_Folder Failed_In sync_agent_add_account()!"); + err = SE_INTERNAL_ERROR; + goto error; + } + + _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id); + + if (folderID != NULL) { + free(folderID); + folderID = NULL; + } + + if (new_folder_id != NULL) { + free(new_folder_id); + new_folder_id = NULL; + } + + folderID = sync_agent_generate_folder_luid(); + if (folderID == NULL) { + _DEBUG_ERROR("failed in sync_agent_generate_folder_luid"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + ret = sync_agent_create_folder(&folder); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_create_folder() failed !!"); + goto error; + } + + folder->account_id = account; + folder->folder_id = strdup(folderID); + folder->data_store_id = TYPE_CALENDAR; + folder->folder_type_id = 0; /* Default contacts folder */ + folder->parent_folder_id = NULL; + folder->service_id = strdup("1"); + folder->access_name = strdup("EventHandler"); + + ret = sync_agent_add_folder(folder, &new_folder_id); + sync_agent_free_folder(folder); + folder = NULL; + + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("Agent Add_Folder Failed_In sync_agent_add_account()!"); + _DEBUG_ERROR("[process_Event_Add_Account] Agent Add_Folder Failed_In sync_agent_add_account()!"); + err = SE_INTERNAL_ERROR; + goto error; + } + + _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id); + + if (folderID != NULL) { + free(folderID); + folderID = NULL; + } + + if (new_folder_id != NULL) { + free(new_folder_id); + new_folder_id = NULL; + } + + folderID = sync_agent_generate_folder_luid(); + if (folderID == NULL) { + _DEBUG_ERROR("failed in sync_agent_generate_folder_luid"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + ret = sync_agent_create_folder(&folder); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_create_folder() failed !!"); + goto error; + } + + folder->account_id = account; + folder->folder_id = strdup(folderID); + folder->data_store_id = TYPE_MEMO; + folder->folder_type_id = 0; /* Default contacts folder */ + folder->parent_folder_id = NULL; + folder->service_id = strdup("0"); + folder->access_name = strdup("EventHandler"); + + ret = sync_agent_add_folder(folder, &new_folder_id); + sync_agent_free_folder(folder); + folder = NULL; + + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("Agent Add_Folder Failed_In sync_agent_add_account()!"); + _DEBUG_ERROR("[process_Event_Add_Account] Agent Add_Folder Failed_In sync_agent_add_account()!"); + err = SE_INTERNAL_ERROR; + goto error; + } + + _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id); + + if (folderID != NULL) { + free(folderID); + folderID = NULL; + } + + if (new_folder_id != NULL) { + free(new_folder_id); + new_folder_id = NULL; + } + + /* call log folder ID */ + folderID = sync_agent_generate_folder_luid(); + if (folderID == NULL) { + _DEBUG_ERROR("failed in sync_agent_generate_folder_luid"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + ret = sync_agent_create_folder(&folder); + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_create_folder() failed !!"); + goto error; + } + + folder->account_id = account; + folder->folder_id = strdup(folderID); + folder->data_store_id = TYPE_CALLLOG; + folder->folder_type_id = 0; /* Default contacts folder */ + folder->parent_folder_id = NULL; + folder->service_id = strdup("0"); + folder->access_name = strdup("EventHandler"); + + ret = sync_agent_add_folder(folder, &new_folder_id); + sync_agent_free_folder(folder); + folder = NULL; + + if (ret != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("Agent Add_Folder Failed_In sync_agent_add_account()!"); + _DEBUG_ERROR("[process_Event_Add_Account] Agent Add_Folder Failed_In sync_agent_add_account()!"); + err = SE_INTERNAL_ERROR; + goto error; + } + + _DEBUG_TRACE("[process_Event_Add_Account] Successed Agent Add_Folder in sync_agent_add_account(), added Folder ID : %s", new_folder_id); + + if (folderID != NULL) { + free(folderID); + folderID = NULL; + } + + if (new_folder_id != NULL) { + free(new_folder_id); + new_folder_id = NULL; + } + + *account_id = account; + + error: + + if (folderID != NULL) + free(folderID); + + sync_agent_free_fw_account(fw_account); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _set_profile_info(int account_id, char *profile_name, char *sync_mode, char *sync_type, char *interval) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_NAME, profile_name, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, sync_mode, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, sync_type, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_SYNC_TYPE, sync_type, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _set_profile_category(int account_id, sync_service_s * category) +{ + _INNER_FUNC_ENTER; + + _DEBUG_TRACE("category->content_type : %d", category->service_type); + _DEBUG_TRACE("category->enabled : %d", category->enabled); + _DEBUG_TRACE("category->src_uri : %s", category->src_uri); + _DEBUG_TRACE("category->tgt_uri : %s", category->tgt_uri); + _DEBUG_TRACE("category->id : %s", category->id); + _DEBUG_TRACE("category->password : %s", category->password); + + se_error_type_e 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 (category->service_type == TYPE_CONTACT) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS; + else if (category->service_type == TYPE_CALENDAR) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR; + else if (category->service_type == TYPE_MEMO) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO; + else if (category->service_type == TYPE_CALLLOG) + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG; + + snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET); + snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID); + snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD); + + result = set_config_int(account_id, datastore, category->enabled, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, datastore_source, category->src_uri, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, datastore_target, category->tgt_uri, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, datastore_id, category->id, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, datastore_pw, category->password, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; + +} + +static se_error_type_e _set_periodic_sync_config(int account_id, char *sync_mode, char *interval) +{ + _INNER_FUNC_ENTER; + _DEBUG_TRACE("sync_mode = %s", sync_mode); + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_pm_return_e scheduler_err; + bool result; + char *value = NULL; + int alarm_id = 0; + + pmci_alarm_s *alarm_info = (pmci_alarm_s *) calloc(1, sizeof(pmci_alarm_s)); + if (alarm_info == NULL) { + _DEBUG_ERROR("alarm_info is NULL"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + alarm_id = atoi(value); + + if (alarm_id != 0) { + scheduler_err = sync_agent_remove_service_data(1, alarm_id); + if (scheduler_err != SYNC_AGENT_PM_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_remove_service_data"); + err = SE_INTERNAL_SCHEDULER_ERROR; + goto error; + } + } + + if (strcmp(sync_mode, DEFINE_SYNC_MODE_PERIODIC) == 0 && interval != NULL) { + + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, DEFINE_ALERT_TWO_WAY_STR, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("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(¤t_time); + struct_time = localtime(¤t_time); + if (struct_time == NULL) { + _DEBUG_ERROR("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->is_disposable = 0; + + if (strcmp(interval, "5 minutes") == 0) { + _DEBUG_TRACE("5 minutes"); + alarm_info->repeat_type = REPEAT; + alarm_info->repeat_value = 5 * 60; + } else if (strcmp(interval, "15 minutes") == 0) { + _DEBUG_TRACE("15 minutes"); + alarm_info->repeat_type = REPEAT; + alarm_info->repeat_value = 15 * 60; + } else if (strcmp(interval, "1 hour") == 0) { + _DEBUG_TRACE("1 hour"); + alarm_info->repeat_type = REPEAT; + alarm_info->repeat_value = ((1 * 60) * 60); + } else if (strcmp(interval, "4 hours") == 0) { + _DEBUG_TRACE("4 hours"); + alarm_info->repeat_type = REPEAT; + alarm_info->repeat_value = ((4 * 60) * 60); + } else if (strcmp(interval, "12 hours") == 0) { + _DEBUG_TRACE("12 hours"); + alarm_info->repeat_type = REPEAT; + alarm_info->repeat_value = ((12 * 60) * 60); + } else if (strcmp(interval, "1 day") == 0) { + _DEBUG_TRACE("1 day"); + alarm_info->repeat_type = REPEAT; + alarm_info->repeat_value = ((24 * 60) * 60); + } else if (strcmp(interval, "1 week") == 0) { + _DEBUG_TRACE("1 week"); + alarm_info->repeat_type = REPEAT_WEEKLY; + alarm_info->repeat_value = week[struct_time->tm_wday]; + } + + scheduler_err = sync_agent_add_service_data(1, alarm_info, &alarm_id); + if (scheduler_err != SYNC_AGENT_PM_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_add_service_data"); + err = SE_INTERNAL_SCHEDULER_ERROR; + goto error; + } + _DEBUG_TRACE("alarm_id =%d", alarm_id); + + result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, alarm_id, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("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) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + + 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); + } + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _set_profile_info_into_config_list(int account_id, char *profile_dir_name, char *addr, char *profile_name, char *sync_mode, char *sync_type, char *interval, char *nonce, char *server_id, GList ** config_list) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profile_dir_name, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_NAME, profile_name, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE, sync_mode != NULL ? sync_mode : "Push", "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, sync_type != NULL ? sync_type : "Full", "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_SYNC_TYPE, sync_type != NULL ? sync_type : "Full", "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL, interval != NULL ? interval : "5 minutes", "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_NEXT_NONCE, nonce, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, server_id, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, "-1", "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, "-1", "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, "0", "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, "0", "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, DEFINE_CONFIG_KEY_PROFILE_RESUME, "0", "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in _append_config_value"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _set_profile_category_info(int account_id, sync_service_s * category, GList ** config_list) +{ + _INNER_FUNC_ENTER; + + retvm_if(category == NULL, SE_INTERNAL_NOT_DEFINED, "category is NULL"); + + se_error_type_e err = SE_INTERNAL_OK; + err = __set_profile_category_info_into_cofnig_list(account_id, category->service_type, category->enabled, category->src_uri, category->tgt_uri, category->id, category->password, config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in _set_profile_category_info_into_cofnig_list"); + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _set_profile_category_info_csc(int account_id, int content_type, int index, GList ** config_list) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + char *is_enabled_path = NULL; + char *target_uri_path = NULL; + char *id_path = NULL; + char *pwd_path = NULL; + + char *datastore = NULL; + + int is_enabled = 0; + char *target_uri = NULL; + char *id = NULL; + char *pwd = NULL; + char profile_path[128]; + + char *source_uri = NULL; + + bool result; + + if (content_type == TYPE_CONTACT) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS; + source_uri = DEFINE_SOURCE_CONTACT_URI; + is_enabled_path = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_ENABLED; + target_uri_path = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_TGTURI; + id_path = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHNAME; + pwd_path = CSC_VCONF_KEY_SYNCMLDS_CONTACTS_AUTHPWD; + } else if (content_type == TYPE_CALENDAR) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR; + source_uri = DEFINE_SOURCE_CALENDAR_URI; + is_enabled_path = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_ENABLED; + target_uri_path = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_TGTURI; + id_path = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHNAME; + pwd_path = CSC_VCONF_KEY_SYNCMLDS_CALENDAR_AUTHPWD; + } else if (content_type == TYPE_MEMO) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO; + source_uri = DEFINE_SOURCE_MEMO_URI; + is_enabled_path = CSC_VCONF_KEY_SYNCMLDS_MEMO_ENABLED; + target_uri_path = CSC_VCONF_KEY_SYNCMLDS_MEMO_TGTURI; + id_path = CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHNAME; + pwd_path = CSC_VCONF_KEY_SYNCMLDS_MEMO_AUTHPWD; + } else if (content_type == TYPE_CALLLOG) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG; + source_uri = DEFINE_SOURCE_CALLLOG_URI; + } else { + err = SE_INTERNAL_ERROR; + _DEBUG_ERROR("No content type"); + goto error; + } + + if (content_type != TYPE_CALLLOG) { + snprintf(profile_path, sizeof(profile_path), is_enabled_path, index); + result = get_vconf_int_key(profile_path, &is_enabled); + if (result == false) { + _DEBUG_ERROR("No value in vconf key = %s", profile_path); + goto error; + } + + snprintf(profile_path, sizeof(profile_path), target_uri_path, index); + target_uri = get_vconf_str_key(profile_path); + + snprintf(profile_path, sizeof(profile_path), id_path, index); + id = get_vconf_str_key(profile_path); + + snprintf(profile_path, sizeof(profile_path), pwd_path, index); + pwd = get_vconf_str_key(profile_path); + } + + err = __set_profile_category_info_into_cofnig_list(account_id, content_type, is_enabled, source_uri, target_uri, id, pwd, config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in _set_profile_category_info_into_cofnig_list"); + goto error; + } + + error: + + if (target_uri != NULL) + free(target_uri); + + if (id != NULL) + free(id); + + if (pwd != NULL) + free(pwd); + + _INNER_FUNC_EXIT; + return err; + +} + +static se_error_type_e _set_profile_category_info_cp(int account_id, int content_type, resource_cp_s * category, GList ** config_list) +{ + _INNER_FUNC_ENTER; + + retvm_if(category == NULL, SE_INTERNAL_NOT_DEFINED, "category is NULL"); + + se_error_type_e err = SE_INTERNAL_OK; + char *sourceuri = NULL; + + if (content_type == TYPE_CONTACT) + sourceuri = DEFINE_SOURCE_CONTACT_URI; + else if (content_type == TYPE_CALENDAR) + sourceuri = DEFINE_SOURCE_CALENDAR_URI; + else if (content_type == TYPE_MEMO) + sourceuri = DEFINE_SOURCE_MEMO_URI; + else if (content_type == TYPE_CALLLOG) + sourceuri = DEFINE_SOURCE_CALLLOG_URI; + else { + err = SE_INTERNAL_ERROR; + _DEBUG_ERROR("No content type"); + goto error; + } + + err = __set_profile_category_info_into_cofnig_list(account_id, content_type, 0, sourceuri, category->name, category->id, category->password, config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in _set_profile_category_info_into_cofnig_list"); + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; + +} + +static se_error_type_e __set_profile_category_info_into_cofnig_list(int account_id, int content_type, int enabled, char *src_uri, char *tgt_uri, char *id, char *password, GList ** config_list) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + char *enable = NULL; + + 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 (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; + + snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET); + snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID); + snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD); + + snprintf(datastore_dbSynced, sizeof(datastore_dbSynced), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED); + snprintf(datastore_lastSessionTime, sizeof(datastore_lastSessionTime), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME); + + snprintf(datastore_s2c_Total, sizeof(datastore_s2c_Total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL); + snprintf(datastore_s2c_NrOfAdd, sizeof(datastore_s2c_NrOfAdd), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD); + snprintf(datastore_s2c_NrOfDelete, sizeof(datastore_s2c_NrOfDelete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE); + snprintf(datastore_s2c_NrOfReplace, sizeof(datastore_s2c_NrOfReplace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE); + + snprintf(datastore_c2s_Total, sizeof(datastore_c2s_Total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL); + snprintf(datastore_c2s_NrOfAdd, sizeof(datastore_c2s_NrOfAdd), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD); + snprintf(datastore_c2s_NrOfDelete, sizeof(datastore_c2s_NrOfDelete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE); + snprintf(datastore_c2s_NrOfReplace, sizeof(datastore_c2s_NrOfReplace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE); + + enable = g_strdup_printf("%u", enabled); + result = ___append_config_value(account_id, datastore, enable, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_source, src_uri, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_target, tgt_uri, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_id, id, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_pw, password, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_dbSynced, DEFINE_DBSYNC_NO, "string", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_lastSessionTime, "-1", "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_s2c_Total, 0, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_s2c_NrOfAdd, 0, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_s2c_NrOfDelete, 0, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_s2c_NrOfReplace, 0, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_c2s_Total, 0, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_c2s_NrOfAdd, 0, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_c2s_NrOfDelete, 0, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = ___append_config_value(account_id, datastore_c2s_NrOfReplace, 0, "int", "SE", config_list); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + if (enable != NULL) + free(enable); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e ___append_config_value(int account_id, char *key, char *value, char *type, char *access_name, GList ** list) +{ + _INNER_FUNC_ENTER; + se_error_type_e err = SE_INTERNAL_OK; + + bool result; + + sync_agent_da_config_s *config = NULL; + + result = create_config_str(account_id, key, value, type, access_name, &config); + if (result == false) { + _DEBUG_ERROR("failed in create_config_str"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + if (config != NULL) { + *list = g_list_append(*list, config); + config = NULL; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _get_empty_profile_dir_name(char **empty_profile_dir_name) +{ + _INNER_FUNC_ENTER; + se_error_type_e err = SE_INTERNAL_OK; + + bool result; + char *profileDirName = NULL; + int profile[MAXIMUM_ACCOUNT_COUNT] = { 0 }; + char profileIndex[2]; + int index; + int i; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + GList *account_info_list = NULL; + GList *iter = NULL; + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_NONE; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto error; + } + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + fw_account = (sync_agent_fw_account_s *) iter->data; + + if (profileDirName != NULL) { + free(profileDirName); + profileDirName = NULL; + } + + result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + _DEBUG_TRACE("profile_Dir_name = %s", profileDirName); + if (profileDirName == NULL) + continue; + + strcpy(profileIndex, profileDirName + strlen(profileDirName) - 1); + _DEBUG_TRACE("profileIndex = %s", profileIndex); + + index = atoi(profileIndex); + profile[index - 1] = 1; + } + + for (i = 0; i < MAXIMUM_ACCOUNT_COUNT; i++) { + if (profile[i] != 1) { + *empty_profile_dir_name = g_strdup_printf("Sync%d", i + 1); + break; + } + } + + error: + + sync_agent_free_fw_account_list(account_info_list); + + if (profileDirName != NULL) + free(profileDirName); + + _INNER_FUNC_EXIT; + return err; +} + +bool add_profile(char *profile_dir_name, char *profile_name, char *addr, char *id, char *password, char *sync_mode, char *sync_type, char *interval, GList * categories, int *account_id) +{ + _EXTERN_FUNC_ENTER; + + _DEBUG_INFO("profile_name = %s", profile_name); + _DEBUG_INFO("addr = %s", addr); + _DEBUG_INFO("id = %s", id); + _DEBUG_INFO("password = %s", password); + _DEBUG_INFO("sync_mode = %s", sync_mode); + _DEBUG_INFO("sync_type = %s", sync_type); + _DEBUG_INFO("interval = %s", interval); + + se_error_type_e err = SE_INTERNAL_OK; + int account = -1; + GList *config_list = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + err = _add_profile(addr, id, password, "SE", &account); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in add_Account"); + goto error; + } + + err = _set_profile_info_into_config_list(account, profile_dir_name, addr, profile_name, sync_mode, sync_type, interval, NULL, NULL, &config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in add_Account"); + goto error; + } + + sync_service_s *category = NULL; + GList *iter = NULL; + for (iter = categories; iter != NULL; iter = g_list_next(iter)) { + category = iter->data; + err = _set_profile_category_info(account, category, &config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __set_profile_category"); + goto error; + } + } + + da_err = sync_agent_add_config_list(config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + err = _set_periodic_sync_config(account, sync_mode, interval); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in _set_periodic_sync_config"); + goto error; + } + + *account_id = account; + + error: + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + _DEBUG_INFO("err = %d", err); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool add_profile_csc(int index) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + char profile_path[128]; + char *profile_dir_name = NULL; + char *profile_name = NULL; + char *id = NULL; + char *password = NULL; + char *server_ip = NULL; + char *sync_mode = NULL; + char *sync_type = NULL; + int account_id; + + GList *config_list = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + err = _get_empty_profile_dir_name(&profile_dir_name); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __get_empty_profileDirName"); + goto error; + } + + if (profile_dir_name == NULL) { + _DEBUG_ERROR("Maximum profiles count is %d, no more profile", MAXIMUM_ACCOUNT_COUNT); + err = SE_INTERNAL_ERROR; + goto error; + } + + snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_AUTHNAME, index); + id = get_vconf_str_key(profile_path); + + snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_AUTHPWD, index); + password = get_vconf_str_key(profile_path); + + snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_ADDR, index); + server_ip = get_vconf_str_key(profile_path); + + snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_NAME, index); + profile_name = get_vconf_str_key(profile_path); + + snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_SYNCMODE, index); + sync_mode = get_vconf_str_key(profile_path); + + snprintf(profile_path, sizeof(profile_path), CSC_VCONF_KEY_SYNCMLDS_SYNCTYPE, index); + sync_type = get_vconf_str_key(profile_path); + + _DEBUG_INFO("email = %s", id); + _DEBUG_INFO("password = %s", password); + _DEBUG_INFO("serverIP = %s", server_ip); + _DEBUG_INFO("profileName = %s", profile_name); + _DEBUG_INFO("syncMode = %s", sync_mode); + _DEBUG_INFO("syncType = %s", sync_type); + + err = _add_profile(server_ip, id, password, "SE", &account_id); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in add_Account"); + goto error; + } + + err = _set_profile_info_into_config_list(account_id, profile_dir_name, server_ip, profile_name, sync_mode, sync_type, NULL, NULL, NULL, &config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in add_Account"); + goto error; + } + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + err = _set_profile_category_info_csc(account_id, content_type, index, &config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in set_DatastoreConfig"); + goto error; + } + } + + da_err = sync_agent_add_config_list(config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + if (profile_dir_name != NULL) + free(profile_dir_name); + if (profile_name != NULL) + free(profile_name); + if (id != NULL) + free(id); + if (password != NULL) + free(password); + if (server_ip != NULL) + free(server_ip); + if (sync_mode != NULL) + free(sync_mode); + if (sync_type != NULL) + free(sync_type); + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool add_profile_cp(char *profile_name, char *addr, char *id, char *password, GList * categories, int *account_id) +{ + _EXTERN_FUNC_ENTER; + + _DEBUG_INFO("profilename = %s", profile_name); + _DEBUG_INFO("addr = %s", addr); + _DEBUG_INFO("id = %s", id); + _DEBUG_INFO("password = %s", password); + + se_error_type_e err = SE_INTERNAL_OK; + int account = -1; + + char *profile_dir_name = NULL; + GList *config_list = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + err = _get_empty_profile_dir_name(&profile_dir_name); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __get_empty_profileDirName"); + goto error; + } + + if (profile_dir_name == NULL) { + _DEBUG_ERROR("Maximum profiles count is %d, no more profile", MAXIMUM_ACCOUNT_COUNT); + err = SE_INTERNAL_ERROR; + goto error; + } + + err = _add_profile(addr, id, password, "SE", &account); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in add_Account"); + goto error; + } + + err = _set_profile_info_into_config_list(account, profile_dir_name, addr, profile_name, NULL, NULL, NULL, NULL, NULL, &config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in add_Account"); + goto error; + } + + int i; + int cnt = (int)sizeof(predefinedServer) / sizeof(datastore_cp_info); + _DEBUG_INFO("cnt = %d", cnt); + for (i = 0; i < cnt; i++) { + + _DEBUG_INFO("predefinedServer[%d].serverName = %s", i, predefinedServer[i].serverName); + if (strcmp(predefinedServer[i].serverName, profile_name) == 0) { + + int j; + for (j = 0; j < MAX_DATASTORE_COUNT; j++) { + resource_cp_s *category = NULL; + GList *iter = NULL; + _DEBUG_INFO("categories length = %d", g_list_length(categories)); + for (iter = categories; iter != NULL; iter = g_list_next(iter)) { + category = (resource_cp_s *) iter->data; + _DEBUG_INFO("category->name = %s", category->name); + _DEBUG_INFO("category->accept = %s", category->accept); + + _DEBUG_INFO("predefinedDatastore[i][j][0] = %s", predefinedDatastore[i][j][0]); + _DEBUG_INFO("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_info_cp(account, j, category, &config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __set_profile_category"); + goto error; + } + break; + } + } + } + } + } + } + + da_err = sync_agent_add_config_list(config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + *account_id = account; + + error: + + if (profile_dir_name != NULL) + free(profile_dir_name); + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool add_profile_dive(int *account_id) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_dev_return_e dci_err = SYNC_AGENT_DEV_RETURN_SUCCESS; + char *id = NULL; + char *password = NULL; + char *encoded_nextnonce = NULL; + int account = -1; + + GList *config_list = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + /* FIXME get id from somewhere */ + id = "ss.linux.test@gmail.com"; + + /*get IMEI from Platform */ + dci_err = sync_agent_get_devinfo(DEFINE_PLATFORM, "DevID", &password); + if (dci_err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + _DEBUG_ERROR("failed to get devinfo"); + goto error; + } + + err = _add_profile(DEFINE_DIVE_SERVER_URL_HTTPS, id, password, "DIVE", &account); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in add_Account"); + goto error; + } + + encoded_nextnonce = g_base64_encode((unsigned char *)DEFINE_DIVE_DEFAULT_NEXT_NONCE, strlen(DEFINE_DIVE_DEFAULT_NEXT_NONCE)); + + err = _set_profile_info_into_config_list(account, NULL, DEFINE_DIVE_SERVER_URL_HTTPS, NULL, NULL, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR, NULL, encoded_nextnonce, DEFINE_DIVE_SERVER_ID, &config_list); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in add_Account"); + goto error; + } + + /*set calllog config value */ + __set_profile_category_info_into_cofnig_list(account, TYPE_CALLLOG, 1, DEFINE_SOURCE_CALLLOG_URI, "./CallLog", NULL, NULL, &config_list); + + da_err = sync_agent_add_config_list(config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + *account_id = account; + + error: + + if (password != NULL) + free(password); + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool edit_profile(int account_id, char *profile_name, char *addr, char *id, char *password, char *sync_mode, char *sync_type, char *interval, GList * categories) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + bool result; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + acc_err = sync_agent_create_fw_account(&fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + err = SE_INTERNAL_ERROR; + goto error; + } + + fw_account->account_id = account_id; + fw_account->email = strdup(id); + fw_account->password = strdup(password); + fw_account->enable = 1; + fw_account->access_name = strdup("SE"); + + acc_err = sync_agent_update_fw_account(fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP, addr, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + err = _set_profile_info(account_id, profile_name, sync_mode, sync_type, interval); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __set_profile_info"); + goto error; + } + + err = _set_periodic_sync_config(account_id, sync_mode, interval); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __set_profile_info"); + goto error; + } + + sync_service_s *category = NULL; + GList *iter = NULL; + for (iter = categories; iter != NULL; iter = g_list_next(iter)) { + category = iter->data; + err = _set_profile_category(account_id, category); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __set_profile_category"); + goto error; + } + } + + error: + + sync_agent_free_fw_account(fw_account); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool delete_profiles(GList * profiles) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + int *accountId = 0; + char *value = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_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); + + if (accountId != NULL) { + _DEBUG_INFO("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) { + _DEBUG_ERROR("failed in get_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + alarmId = atoi(value); + if (alarmId != 0) { + sync_agent_pm_return_e scheduler_err = sync_agent_remove_service_data(1, alarmId); + if (scheduler_err != SYNC_AGENT_PM_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_remove_service_data"); + err = SE_INTERNAL_SCHEDULER_ERROR; + goto error; + } + } + sync_agent_delete_fw_account(*accountId); + if (accountId != 0) { + free(accountId); + accountId = 0; + } + } else { + _DEBUG_ERROR("accountId is NULL !"); + } + } + + error: + + if (value != NULL) + free(value); + + if (accountId != NULL) + free(accountId); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool delete_profile_dive() +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + GList *account_info_list = NULL; + GList *iter = NULL; + sync_agent_fw_account_s *account_info = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_agent"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_ACCESS_NAME; + query.access_name = "DIVE"; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + account_info = (sync_agent_fw_account_s *) iter->data; + _DEBUG_INFO("accountId = %d", account_info->account_id); + sync_agent_delete_fw_account(account_info->account_id); + } + + error: + + sync_agent_free_fw_account_list(account_info_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool delete_profile(char *access_name) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + GList *account_info_list = NULL; + GList *iter = NULL; + sync_agent_fw_account_s *account_info = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_agent"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_ACCESS_NAME; + query.access_name = access_name; + + /*delete account */ + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + account_info = (sync_agent_fw_account_s *) iter->data; + _DEBUG_INFO("accountId = %d", account_info->account_id); + sync_agent_delete_fw_account(account_info->account_id); + } + + error: + + sync_agent_free_fw_account_list(account_info_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool delete_all_profiles() +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + GList *account_info_list = NULL; + GList *iter = NULL; + + int alarm_id = 0; + bool result; + char *value = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_NONE; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto error; + } + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + fw_account = (sync_agent_fw_account_s *) iter->data; + + _DEBUG_INFO("accountId = %d", fw_account->account_id); + /*if deleteing Account's sync mode is periodic sync it has to be deleted from schedule_tbl */ + result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_ALARM_ID, &value); + if (result == false) { + _DEBUG_ERROR("failed in get_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + if (value != NULL) { + alarm_id = atoi(value); + if (alarm_id != 0) { + sync_agent_pm_return_e scheduler_err = sync_agent_remove_service_data(1, alarm_id); + if (scheduler_err != SYNC_AGENT_PM_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_remove_service_data"); + err = SE_INTERNAL_SCHEDULER_ERROR; + goto error; + } + } + + free(value); + value = NULL; + + sync_agent_delete_fw_account(fw_account->account_id); + } else { + _DEBUG_ERROR("value is NULL !"); + } + } + + error: + + if (value != NULL) + free(value); + + sync_agent_free_fw_account_list(account_info_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool get_synchronising_profile(char **profile_Dir_name, char **sync_type) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + bool result; + char *value = NULL; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + GList *account_info_list = NULL; + GList *iter = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_NONE; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto error; + } + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + fw_account = (sync_agent_fw_account_s *) iter->data; + + result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, &value); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + if (strcmp(value, "1") == 0) { + result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, profile_Dir_name); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = get_config(fw_account->account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_SYNC_TYPE, sync_type); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + break; + } + + free(value); + value = NULL; + } + + error: + + if (value != NULL) + free(value); + + sync_agent_free_fw_account_list(account_info_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool delete_all_agent_default_table() +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + da_err = sync_agent_empty_all_agent_default_table(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} diff --git a/src/agent/service-engine/se_notification.c b/src/agent/service-engine/se_notification.c new file mode 100755 index 0000000..1fdf1c5 --- /dev/null +++ b/src/agent/service-engine/se_notification.c @@ -0,0 +1,133 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @SE_Notification.c + * @version 0.1 + * @brief This file is the source file of implementation of notify to ui + */ + +#include + +#include + +#include "service-engine/se_notification.h" +#include "service-engine/se_sync.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SE" +#endif + +#define NOTI_KEY "OMADS" +#define OMA_DS_UI_PKG "ug-setting-synchronise-efl" + +se_error_type_e send_noti_session_process(char *profile, char *sync_type, char *progress, char *error) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + int notiType = 1; + sync_agent_event_data_s *noti = NULL; + + if (profile == NULL) { + _DEBUG_ERROR("Not Defined profile"); + err = SE_INTERNAL_NOT_DEFINED; + goto error; + } + + noti = sync_agent_create_noti(notiType); + if (noti == NULL) { + _DEBUG_ERROR("failed to sync_agent_create_noti"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_type); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)progress); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)error); + + sync_agent_event_error_e event_err; + sync_agent_send_noti(NOTI_KEY, noti, NULL, NULL, &event_err); + if (event_err != SYNC_AGENT_EVENT_SUCCESS) { + if (aul_app_is_running(OMA_DS_UI_PKG)) { + _DEBUG_ERROR("failed to sync_agent_send_noti"); + err = SE_INTERNAL_EVENT_ERROR; + goto error; + } + } + + error: + + sync_agent_free_noti(noti); + + _EXTERN_FUNC_EXIT; + return err; +} + +se_error_type_e send_noti_process_update(char *profile_dir_name, char *sync_type, char *uri, char *progress_status, char *operation_type, int is_from_server, int total_per_operation, int synced_per_operation, int total_per_db, int synced_per_db) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + int notiType = 2; + sync_agent_event_data_s *noti = NULL; + + if (profile_dir_name == NULL) { + _DEBUG_ERROR("Not Defined profileDirName"); + err = SE_INTERNAL_NOT_DEFINED; + goto error; + } + + noti = sync_agent_create_noti(notiType); + if (noti == NULL) { + _DEBUG_ERROR("failed to sync_agent_create_noti"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_type); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)uri); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)progress_status); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)operation_type); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &is_from_server); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &total_per_operation); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &synced_per_operation); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &total_per_db); + sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &synced_per_db); + + sync_agent_event_error_e event_err; + sync_agent_send_noti(NOTI_KEY, noti, NULL, NULL, &event_err); + if (event_err != SYNC_AGENT_EVENT_SUCCESS) { + if (aul_app_is_running(OMA_DS_UI_PKG)) { + _DEBUG_ERROR("failed to sync_agent_send_noti"); + err = SE_INTERNAL_EVENT_ERROR; + goto error; + } + } + + error: + + sync_agent_free_noti(noti); + + _EXTERN_FUNC_EXIT; + return err; +} diff --git a/src/agent/service-engine/se_storage.c b/src/agent/service-engine/se_storage.c new file mode 100755 index 0000000..51beeff --- /dev/null +++ b/src/agent/service-engine/se_storage.c @@ -0,0 +1,1000 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @SE_Storage.c + * @version 0.1 + * @brief This file is the source file of implementation of functions which saves and gets sync results + */ + +#include + +#include + +#include "common/common_util.h" +#include "service-engine/se_storage.h" +#include "service-engine/se_common.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SE" +#endif + +static se_error_type_e _write_sync_type(int account_id, alert_type_e alert_type); +static se_error_type_e _write_last_session_values(int account_id, sync_session_result_e sync_session_result, int last_session_time); + +static se_error_type_e _write_sync_type(int account_id, alert_type_e alert_type) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + + char *syncType = NULL; + switch (alert_type) { + 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(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, syncType, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; + +} + +static se_error_type_e _write_last_session_values(int account_id, sync_session_result_e sync_session_result, int last_session_time) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + + result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS, sync_session_result, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME, last_session_time, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +se_error_type_e write_profile_data(int account_id, alert_type_e alert_type, sync_session_result_e sync_session_result, int last_session_time, int only_from_client) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + err = _write_sync_type(account_id, alert_type); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncType"); + goto error; + } + + err = _write_last_session_values(account_id, sync_session_result, last_session_time); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeLastSessionValues"); + goto error; + } + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->client_sync_type) { + err = write_sync_resource_info(account_id, content_type, last_session_time, only_from_client, + datastoreinfo_per_content_type[content_type]->client_sync_result, datastoreinfo_per_content_type[content_type]->server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncResourceInfo"); + goto error; + } + + err = write_sync_statistics(account_id, content_type, true, datastoreinfo_per_content_type[content_type]->server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncStatistics"); + goto error; + } + + err = write_sync_statistics(account_id, content_type, false, datastoreinfo_per_content_type[content_type]->client_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncStatistics"); + goto error; + } + } + } + } + + error: + + _EXTERN_FUNC_EXIT; + return err; +} + +se_error_type_e write_sync_statistics(int account_id, int content_type, bool is_from_server, sync_result_s * sync_result) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e 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 (is_from_server == true) + side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER; + else + side = DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT; + + _DEBUG_INFO("pSyncResult->numberOfChange = %d", sync_result->number_of_change); + _DEBUG_INFO("pSyncResult->add_count = %d", sync_result->add_count); + _DEBUG_INFO("pSyncResult->replace_count = %d", sync_result->replace_count); + _DEBUG_INFO("pSyncResult->delete_count = %d", sync_result->delete_count); + + snprintf(numberOfChangesPath, sizeof(numberOfChangesPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL); + snprintf(addCountPath, sizeof(addCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD); + snprintf(replaceCountPath, sizeof(replaceCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE); + snprintf(deleteCountPath, sizeof(deleteCountPath), "%s_%s_%s", datastore, side, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE); + + result = set_config_int(account_id, numberOfChangesPath, sync_result->number_of_change, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, addCountPath, sync_result->add_count, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, replaceCountPath, sync_result->replace_count, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, deleteCountPath, sync_result->delete_count, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _EXTERN_FUNC_EXIT; + return err; + +} + +se_error_type_e write_sync_resource_info(int account_id, int content_type, int last_session_time, int only_from_client, sync_result_s * client_sync_result, sync_result_s * server_sync_result) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + char *datastore = NULL; + char dbSyncedPath[128]; + char lastSessionTimePath[128]; + + if (client_sync_result == NULL) { + _DEBUG_ERROR("clientSyncResult is NULL"); + err = SE_INTERNAL_NOT_DEFINED; + goto error; + } + + if (server_sync_result == NULL) { + _DEBUG_ERROR("serverSyncResult is NULL"); + err = SE_INTERNAL_NOT_DEFINED; + goto error; + } + + 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; + + _DEBUG_INFO("clientSyncResult->sessionResult = %d", client_sync_result->session_result); + _DEBUG_INFO("serverSyncResult->sessionResult = %d", server_sync_result->session_result); + + char *dbSynced; + if (client_sync_result->session_result == SYNC_SESSION_SUCCEEDED && (server_sync_result->session_result == SYNC_SESSION_SUCCEEDED || only_from_client)) + dbSynced = DEFINE_DBSYNC_SUCCESS; + else if (client_sync_result->session_result == SYNC_SESSION_STOPPED) + dbSynced = DEFINE_DBSYNC_STOP; + else + dbSynced = DEFINE_DBSYNC_FAIL; + + _DEBUG_INFO("dbSynced = %s", dbSynced); + + snprintf(dbSyncedPath, sizeof(dbSyncedPath), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED); + snprintf(lastSessionTimePath, sizeof(lastSessionTimePath), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME); + + result = set_config_str(account_id, dbSyncedPath, dbSynced, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + result = set_config_int(account_id, lastSessionTimePath, last_session_time, "int", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _EXTERN_FUNC_EXIT; + return err; +} + +bool get_profile_data(int account_id, char **profile_name, char **addr, char **id, char **password, char **sync_mode, char **sync_type, char **interval, int *last_session_status, int *last_session_time) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + char *lastSessionStatus_str = NULL; + char *lastSessionTime_str = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + acc_err = sync_agent_create_fw_account(&fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_fw_account"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + acc_err = sync_agent_get_fw_account(account_id, &fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_update_fw_account"); + err = SE_INTERNAL_ERROR; + goto error; + } + + if (fw_account->email != NULL) + *id = strdup(fw_account->email); + + if (fw_account->password != NULL) + *password = strdup(fw_account->password); + + da_err = sync_agent_get_config_list(account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NAME) == 0) { + if (config_data->value != NULL) { + *profile_name = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) { + if (config_data->value != NULL) { + *addr = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE) == 0) { + if (config_data->value != NULL) { + *sync_mode = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) { + if (config_data->value != NULL) { + *sync_type = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL) == 0) { + if (config_data->value != NULL) { + *interval = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS) == 0) { + if (config_data->value != NULL) { + lastSessionStatus_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME) == 0) { + if (config_data->value != NULL) { + lastSessionTime_str = strdup(config_data->value); + continue; + } + } + } + } + } + + if (lastSessionStatus_str != NULL) + *last_session_status = atoi(lastSessionStatus_str); + + if (lastSessionTime_str != NULL) + *last_session_time = atoi(lastSessionTime_str); + + error: + + sync_agent_free_fw_account(fw_account); + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + if (lastSessionStatus_str != NULL) + free(lastSessionStatus_str); + + if (lastSessionTime_str != NULL) + free(lastSessionTime_str); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool get_profile_sync_category(int account_id, int content_type, int *enabled, char **src_uri, char **tgt_uri, char **id, char **password) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + char *datastore = NULL; + char *enabled_str = NULL; + + char datastore_source[128]; + char datastore_target[128]; + char datastore_id[128]; + char datastore_pw[128]; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + 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; + + snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET); + snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID); + snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD); + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + da_err = sync_agent_get_config_list(account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (datastore != NULL) { + if (strcmp(config_data->key, datastore) == 0) { + if (config_data->value != NULL) { + enabled_str = strdup(config_data->value); + continue; + } + } + } else { + _DEBUG_ERROR("datastore is NULL !!"); + err = SE_INTERNAL_ERROR; + goto error; + } + + if (strcmp(config_data->key, datastore_source) == 0) { + if (config_data->value != NULL) { + *src_uri = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_target) == 0) { + if (config_data->value != NULL) { + *tgt_uri = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_id) == 0) { + if (config_data->value != NULL) { + *id = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_pw) == 0) { + if (config_data->value != NULL) { + *password = strdup(config_data->value); + continue; + } + } + } + } + } + + if (enabled_str != NULL) + *enabled = atoi(enabled_str); + + error: + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + if (enabled_str != NULL) + free(enabled_str); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; + +} + +bool get_profile_statistics(int account_id, int content_type, char **db_synced, int *last_session_time, + int *server2client_total, int *server2client_nrofadd, int *server2client_nrofdelete, int *server2client_nrofreplace, + int *client2server_total, int *client2server_nrofadd, int *client2server_nrofdelete, int *client2server_nrofreplace) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + 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; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + 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; + + snprintf(datastore_dbsynced, sizeof(datastore_dbsynced), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_DBSYNCED); + snprintf(datastore_lastsessiontime, sizeof(datastore_lastsessiontime), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_LAST_TIME); + snprintf(datastore_s2c_total, sizeof(datastore_s2c_total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL); + snprintf(datastore_s2c_add, sizeof(datastore_s2c_add), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD); + snprintf(datastore_s2c_delete, sizeof(datastore_s2c_delete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE); + snprintf(datastore_s2c_replace, sizeof(datastore_s2c_replace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_SERVER, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE); + + snprintf(datastore_c2s_total, sizeof(datastore_c2s_total), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_TOTAL); + snprintf(datastore_c2s_add, sizeof(datastore_c2s_add), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFADD); + snprintf(datastore_c2s_delete, sizeof(datastore_c2s_delete), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFDELETE); + snprintf(datastore_c2s_replace, sizeof(datastore_c2s_replace), "%s_%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_CLIENT, DEFINE_CONFIG_KEY_PROFILE_STATISTICS_NROFREPLACE); + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + da_err = sync_agent_get_config_list(account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (strcmp(config_data->key, datastore_dbsynced) == 0) { + if (config_data->value != NULL) { + *db_synced = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_lastsessiontime) == 0) { + if (config_data->value != NULL) { + lastSessionTime_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_s2c_total) == 0) { + if (config_data->value != NULL) { + server2Client_Total_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_s2c_add) == 0) { + if (config_data->value != NULL) { + server2Client_NrOfAdd_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_s2c_delete) == 0) { + if (config_data->value != NULL) { + server2Client_NrOfDelete_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_s2c_replace) == 0) { + if (config_data->value != NULL) { + server2Client_NrOfReplace_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_c2s_total) == 0) { + if (config_data->value != NULL) { + client2Server_Total_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_c2s_add) == 0) { + if (config_data->value != NULL) { + client2Server_NrOfAdd_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_c2s_delete) == 0) { + if (config_data->value != NULL) { + client2Server_NrOfDelete_str = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_c2s_replace) == 0) { + if (config_data->value != NULL) { + client2Server_NrOfReplace_str = strdup(config_data->value); + continue; + } + } + } + } + } + + if (lastSessionTime_str != NULL) + *last_session_time = atoi(lastSessionTime_str); + + if (server2Client_Total_str != NULL) + *server2client_total = atoi(server2Client_Total_str); + + if (server2Client_NrOfAdd_str != NULL) + *server2client_nrofadd = atoi(server2Client_NrOfAdd_str); + + if (server2Client_NrOfDelete_str != NULL) + *server2client_nrofdelete = atoi(server2Client_NrOfDelete_str); + + if (server2Client_NrOfReplace_str != NULL) + *server2client_nrofreplace = atoi(server2Client_NrOfReplace_str); + + if (client2Server_Total_str != NULL) + *client2server_total = atoi(client2Server_Total_str); + + if (client2Server_NrOfAdd_str != NULL) + *client2server_nrofadd = atoi(client2Server_NrOfAdd_str); + + if (client2Server_NrOfDelete_str != NULL) + *client2server_nrofdelete = atoi(client2Server_NrOfDelete_str); + + if (client2Server_NrOfReplace_str != NULL) + *client2server_nrofreplace = atoi(client2Server_NrOfReplace_str); + + error: + + sync_agent_free_config_list(config_list); + + sync_agent_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); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +bool get_all_profiles_data(GList ** list) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + + GList *account_info_list = NULL; + GList *account_iter = NULL; + sync_agent_fw_account_s *fw_account = NULL; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = NULL; + + sync_agent_ds_profile_info *profile_info = NULL; + GList *account_list = NULL; + GList *free_iter = NULL; + + sync_agent_ds_service_info *category_info = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_ACCESS_NAME; + query.access_name = "SE"; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto error; + } + + for (account_iter = account_info_list; account_iter != NULL; account_iter = g_list_next(account_iter)) { + fw_account = (sync_agent_fw_account_s *) account_iter->data; + + profile_info = (sync_agent_ds_profile_info *) calloc(1, sizeof(sync_agent_ds_profile_info)); + if (profile_info == NULL) { + _DEBUG_ERROR("profile_info is NULL"); + goto error; + } + + sync_agent_ds_server_info *server_info = &profile_info->server_info; + sync_agent_ds_sync_info *sync_info = &profile_info->sync_info; + + if (fw_account->email != NULL) + server_info->id = strdup(fw_account->email); + + if (fw_account->password != NULL) + server_info->password = strdup(fw_account->password); + + da_err = sync_agent_get_config_list(fw_account->account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME) == 0) { + if (config_data->value != NULL) { + profile_info->profile_dir_name = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_NAME) == 0) { + if (config_data->value != NULL) { + profile_info->profile_name = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SERVER_IP) == 0) { + if (config_data->value != NULL) { + server_info->addr = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_MODE) == 0) { + if (config_data->value != NULL) { + sync_info->sync_mode = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) { + if (config_data->value != NULL) { + sync_info->sync_type = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_SYNC_INTERVAL) == 0) { + if (config_data->value != NULL) { + sync_info->interval = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_STATUS) == 0) { + if (config_data->value != NULL) { + profile_info->last_sync_status = atoi(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_LAST_SESSION_TIME) == 0) { + if (config_data->value != NULL) { + profile_info->last_sync_time = atoi(config_data->value); + continue; + } + } + } + } + } + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + + category_info = (sync_agent_ds_service_info *) calloc(1, sizeof(sync_agent_ds_service_info)); + if (category_info == NULL) { + _DEBUG_ERROR("category_info is NULL"); + goto error; + } + + char *datastore = NULL; + + char datastore_source[128]; + char datastore_target[128]; + char datastore_id[128]; + char datastore_pw[128]; + + if (content_type == TYPE_CONTACT) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS; + category_info->service_type = SYNC_AGENT_CONTACT; + } else if (content_type == TYPE_CALENDAR) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR; + category_info->service_type = SYNC_AGENT_CALENDAR; + } else if (content_type == TYPE_MEMO) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO; + category_info->service_type = SYNC_AGENT_MEMO; + } else if (content_type == TYPE_CALLLOG) { + datastore = DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG; + category_info->service_type = SYNC_AGENT_CALLLOG; + } + + snprintf(datastore_source, sizeof(datastore_source), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + snprintf(datastore_target, sizeof(datastore_target), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET); + snprintf(datastore_id, sizeof(datastore_id), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID); + snprintf(datastore_pw, sizeof(datastore_pw), "%s_%s", datastore, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD); + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (strcmp(config_data->key, datastore) == 0) { + if (config_data->value != NULL) { + category_info->enabled = atoi(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_source) == 0) { + if (config_data->value != NULL) { + category_info->src_uri = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_target) == 0) { + if (config_data->value != NULL) { + category_info->tgt_uri = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_id) == 0) { + if (config_data->value != NULL) { + category_info->id = strdup(config_data->value); + continue; + } + } + + if (strcmp(config_data->key, datastore_pw) == 0) { + if (config_data->value != NULL) { + category_info->password = strdup(config_data->value); + continue; + } + } + } + } + } + + profile_info->service_list = g_list_append(profile_info->service_list, category_info); + category_info = NULL; + } + + sync_agent_free_config_list(config_list); + config_list = NULL; + + account_list = g_list_append(account_list, profile_info); + profile_info = NULL; + } + + *list = account_list; + account_list = NULL; + + error: + + for (free_iter = account_list; free_iter != NULL; free_iter = g_list_next(free_iter)) { + sync_agent_ds_free_profile_info((ds_profile_h) free_iter->data); + _DEBUG_INFO("free sync_agent_ds_profile_info"); + } + + if (profile_info != NULL) + free(profile_info); + + sync_agent_free_fw_account_list(account_info_list); + + sync_agent_free_config_list(config_list); + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} diff --git a/src/agent/service-engine/se_sync.c b/src/agent/service-engine/se_sync.c new file mode 100755 index 0000000..c946921 --- /dev/null +++ b/src/agent/service-engine/se_sync.c @@ -0,0 +1,3245 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +/** + * @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 + +#include +#include + +#include "service-engine/se_sync.h" +#include "service-engine/se_storage.h" +#include "service-engine/se_common.h" +#include "service-engine/se_notification.h" +#include "service-adapter/sa_common_interface.h" +#include "common/common_util.h" +#include "common/common_define_internal.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SE" +#endif + +static se_error_type_e _session_process(int account_id, alert_type_e server_sync_type, sync_progress_e process, sync_error_e error); +static se_error_type_e __process_update(int account_id, alert_type_e server_sync_type, sync_progress_status_e progress_status, operation_type_e operation_type, int content_type, bool is_from_server, bool need_to_save, sync_result_s * sync_result); +static se_error_type_e _write_sync_data(int account_id, alert_type_e alert_type, sync_session_result_e sync_session_result, int last_session_time, int only_from_client); +static se_error_type_e ___write_sync_resource_info(int account_id, int content_type, int last_session_time, int only_from_client, sync_result_s * client_sync_result, sync_result_s * server_sync_result); + +static se_error_type_e __init_datastore_info_array(int account_id); +static se_error_type_e ___set_datastore_info_array(int account_id, char *config_key, service_type_e content_type); +static se_error_type_e ___generate_datastore_info(int account_id, service_type_e content_type, datastore_s ** datastore); +static se_error_type_e __init_datastore_info(int account_id, service_type_e content_type, datastore_s ** datastore); +static se_error_type_e ___set_datastore_config(int account_id, int content_type, datastore_s ** datastore); +static se_error_type_e __get_sync_type(int account_id, alert_type_e * sync_type); + +static se_error_type_e __on_synchronising_account(int account_id); +static se_error_type_e _off_synchronising_account(int account_id); + +static se_error_type_e __on_resume_flag(int account_id); +static se_error_type_e _off_resume_flag(int account_id); + +static se_error_type_e _assemble_changed_datastores(int account_id, alert_type_e server_sync_type, sync_obj_s ** sync_obj); +static se_error_type_e _prepare_pre_sync(int account_id, char *sync_mode, san_package_s * san_package, alert_type_e * sync_type); +static se_error_type_e __set_config_based_on_sync_mode(int account_id, char *sync_mode, san_package_s * san_package); +static se_error_type_e _execute_pre_sync(int account_id, int session_time, pre_sync_return_obj_s * pre_sync_return_obj, alert_type_e * server_sync_type); +static se_error_type_e __execute_pre_sync_set_server_id(int account_id, char *dev_id); +static se_error_type_e __execute_pre_sync_datastore(int account_id, int session_time, GList * datastore_info, alert_type_e * server_sync_type); +static se_error_type_e _execute_sync(int account_id, alert_type_e client_sync_type, alert_type_e server_sync_type, sync_obj_s ** sync_obj, sync_return_obj_s ** sync_return_obj); +static se_error_type_e __execute_sync_arrange_changelog(int account_id, alert_type_e sync_type, GList * status); +static se_error_type_e __execute_sync_status(int account_id, alert_type_e server_sync_type, sync_obj_s ** sync_obj, sync_return_obj_s ** sync_return_obj); +static se_error_type_e __execute_sync_change(int account_id, alert_type_e server_sync_type, sync_obj_s ** sync_obj, sync_return_obj_s ** sync_return_obj); +static se_error_type_e _update_sync_result(int account_id); + +static command_result_e ___convert_return_status(sync_agent_da_return_e da_err); +static char *__convert_cttype_str(int itemTypeId); +static int ___convert_sync_type_value(char *sync_type_str); +static char *__convert_sync_type_str(alert_type_e sync_type); +static char *___convert_sync_progress_status_str(sync_progress_status_e progress_status); +static char *___convert_operation_type_str(operation_type_e operation_type); +static char *_convert_sync_progress_str(sync_progress_e process); +static char *_convert_sync_error_str(sync_error_e error); +static se_error_type_e _check_low_battery(); +static se_error_type_e _open_services(); +static se_error_type_e _close_services(); + +static inline long myclock() +{ + struct timeval tv; + gettimeofday(&tv, 0); + return (tv.tv_sec * 1000 + tv.tv_usec / 1000); +} + +static se_error_type_e _session_process(int account_id, alert_type_e server_sync_type, sync_progress_e process, sync_error_e error) +{ + _INNER_FUNC_ENTER; + + char *profileDirName = NULL; + se_error_type_e err = SE_INTERNAL_OK; + bool result; + + result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + if (profileDirName != NULL) { + err = session_process(profileDirName, server_sync_type, process, error); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed to send noti"); + goto error; + } + } + + error: + if (profileDirName != NULL) + free(profileDirName); + + _INNER_FUNC_EXIT; + + return err; +} + +static se_error_type_e __process_update(int account_id, alert_type_e server_sync_type, sync_progress_status_e progress_status, operation_type_e operation_type, int content_type, bool is_from_server, bool need_to_save, sync_result_s * sync_result) +{ + _INNER_FUNC_ENTER; + + _DEBUG_VERBOSE("account_id =%d, progress_status = %d, operation_type = %d, content_type = %d, isFromServer = %d, needToSave = %d ", account_id, progress_status, operation_type, content_type, is_from_server, need_to_save); + _DEBUG_VERBOSE("numberOfChange = %d, received_count = %d, syncCount = %d", sync_result->number_of_change, sync_result->received_count, sync_result->add_count + sync_result->replace_count + sync_result->delete_count); + + se_error_type_e err = SE_INTERNAL_OK; + char *profileDirName = NULL; + char *uri = NULL; + char *sync_type = NULL; + char *operation = NULL; + char *progress = NULL; + + bool result; + result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_DIR_NAME, &profileDirName); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + /* do not need to send update noti to ui */ + if (profileDirName == NULL) { + _DEBUG_VERBOSE("profileDirName is NULL"); + goto error; + } + + if (need_to_save == true) { + err = write_sync_statistics(account_id, content_type, is_from_server, sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeSyncStatistics"); + goto error; + } + } + + sync_type = __convert_sync_type_str(server_sync_type); + + progress = ___convert_sync_progress_status_str(progress_status); + + operation = ___convert_operation_type_str(operation_type); + + if (sync_type == NULL || progress == NULL || operation == NULL) { + err = SE_INTERNAL_NOT_DEFINED; + goto error; + } + + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->source != NULL) + uri = strdup(datastoreinfo_per_content_type[content_type]->source); + } + + err = send_noti_process_update(profileDirName, sync_type, uri, progress, operation, is_from_server, 0, 0, sync_result->number_of_change, sync_result->add_count + sync_result->replace_count + sync_result->delete_count); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in send_noti_process_update"); + goto error; + } + + error: + + if (profileDirName != NULL) + free(profileDirName); + + if (uri != NULL) + free(uri); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _write_sync_data(int account_id, alert_type_e alert_type, sync_session_result_e sync_session_result, int last_session_time, int only_from_client) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + err = write_profile_data(account_id, alert_type, sync_session_result, last_session_time, only_from_client); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in writeProfileData"); + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e ___write_sync_resource_info(int account_id, int content_type, int last_session_time, int only_from_client, sync_result_s * client_sync_result, sync_result_s * server_sync_result) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + err = write_sync_resource_info(account_id, content_type, last_session_time, only_from_client, client_sync_result, server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in write_sync_resource_info"); + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __init_datastore_info_array(int account_id) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + err = ___set_datastore_info_array(account_id, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS, TYPE_CONTACT); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in set_datastoreinfo_array"); + goto error; + } + + err = ___set_datastore_info_array(account_id, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR, TYPE_CALENDAR); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in set_datastoreinfo_array"); + goto error; + } + + err = ___set_datastore_info_array(account_id, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO, TYPE_MEMO); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in set_datastoreinfo_array"); + goto error; + } + + err = ___set_datastore_info_array(account_id, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG, TYPE_CALLLOG); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in set_datastoreinfo_array"); + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e ___set_datastore_info_array(int account_id, char *config_key, service_type_e content_type) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + datastore_s *datastore_info = NULL; + bool result; + char *value = NULL; + + result = get_config(account_id, config_key, &value); + if (result == true) { + if (strcmp(value, "1") == 0) { + err = ___generate_datastore_info(account_id, content_type, &datastore_info); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed to create or init datastore_info"); + datastoreinfo_per_content_type[content_type] = NULL; + goto error; + } + datastoreinfo_per_content_type[content_type] = datastore_info; + } + + } else + datastoreinfo_per_content_type[content_type] = NULL; + + error: + + if (value != NULL) + free(value); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e ___generate_datastore_info(int account_id, service_type_e content_type, datastore_s ** datastore) +{ + _INNER_FUNC_ENTER; + _DEBUG_VERBOSE("content_type=[%d]\n", content_type); + + se_error_type_e err = SE_INTERNAL_OK; + char *clientLastAnchor = NULL; + char *clientNextAnchor = NULL; + char *serverLastAnchor = NULL; + + sync_agent_da_return_e da_err = SYNC_AGENT_DA_ERRORS; + + sync_result_s *pSyncResult = NULL; + datastore_s *temp_datastore = NULL; + err = ___set_datastore_config(account_id, content_type, &temp_datastore); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in set_datastore_config"); + goto error; + } + + GList *anchor_list = NULL; + sync_agent_da_get_last_anchor_list_query_s query; + query.option = SYNC_AGENT_DA_GET_LAST_ANCHOR_LIST_OPTION_ITEM_TYPE_ID; + query.account_id = account_id; + query.item_type_id = temp_datastore->datastore_id; + + da_err = sync_agent_get_last_anchor_list(&query, &anchor_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_last_anchor_list !!"); + goto error; + } + + if (g_list_length(anchor_list) > 0) { + GList *last_anchor_info = g_list_nth(anchor_list, g_list_length(anchor_list) - 1); + clientLastAnchor = ((sync_agent_da_last_anchor_s *) (last_anchor_info->data))->last_anchor_client; + serverLastAnchor = ((sync_agent_da_last_anchor_s *) (last_anchor_info->data))->last_anchor_server; + } else { + sync_agent_da_last_anchor_s lastAnchor_daci; + + lastAnchor_daci.account_id = account_id; + lastAnchor_daci.data_store_id = temp_datastore->datastore_id; + lastAnchor_daci.last_anchor_server = NULL; + lastAnchor_daci.last_anchor_client = NULL; + lastAnchor_daci.access_name = "Engine"; + + da_err = sync_agent_add_last_anchor(&lastAnchor_daci); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("da_add_last_anchor_internal is failed %d", da_err); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + + clientNextAnchor = g_strdup_printf("%ld", time(NULL)); + + _DEBUG_VERBOSE("clientLastAnchor = %s\n", clientLastAnchor); + _DEBUG_VERBOSE("serverLastAnchor = %s\n", serverLastAnchor); + _DEBUG_VERBOSE("clientNextAnchor = %s\n", clientNextAnchor); + + /*slow sync if managed anchor info not exist.. (first sync) */ + if (clientLastAnchor == NULL) + set_datastore_client_anchor(temp_datastore, clientNextAnchor, clientNextAnchor); + else + set_datastore_client_anchor(temp_datastore, clientLastAnchor, clientNextAnchor); + + set_datastore_server_anchor(temp_datastore, serverLastAnchor, NULL); + + pSyncResult = create_sync_result(); + if (pSyncResult == NULL) { + _DEBUG_ERROR("create_syncResult is failed"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + temp_datastore->client_sync_result = pSyncResult; + + pSyncResult = create_sync_result(); + if (pSyncResult == NULL) { + _DEBUG_ERROR("create_syncResult is failed"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + temp_datastore->server_sync_result = pSyncResult; + + *datastore = temp_datastore; + temp_datastore = NULL; + + error: + + if (clientNextAnchor != NULL) + free(clientNextAnchor); + + if (temp_datastore != NULL) + free_datastore(temp_datastore); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __init_datastore_info(int account_id, service_type_e content_type, datastore_s ** datastore) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + char *sourceDatastore = NULL; + char key[128]; + datastore_s *temp_datastore = NULL; + sync_result_s *pSyncResult = NULL; + + bool result; + switch (content_type) { + case TYPE_CONTACT: + snprintf(key, sizeof(key), "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CONTACTS, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + break; + case TYPE_CALENDAR: + snprintf(key, sizeof(key), "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALENDAR, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + break; + case TYPE_MEMO: + snprintf(key, sizeof(key), "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_MEMO, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + break; + case TYPE_CALLLOG: + snprintf(key, sizeof(key), "%s_%s", DEFINE_CONFIG_KEY_PROFILE_CATEGORY_CALLLOG, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + break; + default: + _DEBUG_VERBOSE("unknown content type = %d", content_type); + goto error; + } + + _DEBUG_ERROR("content_type = %d", content_type); + _DEBUG_ERROR("key = %s", key); + result = get_config(account_id, key, &sourceDatastore); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + temp_datastore = create_datastore(NULL, sourceDatastore); + if (temp_datastore == NULL) { + _DEBUG_ERROR("failed to create_Datastore"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + pSyncResult = create_sync_result(); + if (pSyncResult == NULL) { + _DEBUG_ERROR("create_syncResult is failed"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + temp_datastore->client_sync_result = pSyncResult; + + pSyncResult = create_sync_result(); + if (pSyncResult == NULL) { + _DEBUG_ERROR("create_syncResult is failed"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + temp_datastore->server_sync_result = pSyncResult; + + *datastore = temp_datastore; + temp_datastore = NULL; + + error: + if (sourceDatastore != NULL) + free(sourceDatastore); + + if (temp_datastore != NULL) + free_datastore(temp_datastore); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e ___set_datastore_config(int account_id, int content_type, datastore_s ** datastore) +{ + _INNER_FUNC_ENTER; + + datastore_s *temp_datastore = NULL; + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + + 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; + + alert_type_e alert_type = ALERT_UNKNOWN; + + GList *config_list = NULL; + GList *iter = NULL; + sync_agent_da_config_s *config_data = 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: + _DEBUG_VERBOSE("unknown content type = %d", content_type); + err = SE_INTERNAL_ERROR; + goto error; + } + + snprintf(sourceDatastore_key, sizeof(sourceDatastore_key), "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_SOURCE); + snprintf(targetDatastore_key, sizeof(targetDatastore_key), "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_TARGET); + snprintf(id_key, sizeof(id_key), "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_ID); + snprintf(pw_key, sizeof(id_key), "%s_%s", contentType, DEFINE_CONFIG_KEY_PROFILE_CATEGORY_PASSWORD); + + da_err = sync_agent_get_config_list(account_id, &config_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + for (iter = config_list; iter != NULL; iter = g_list_next(iter)) { + config_data = (sync_agent_da_config_s *) iter->data; + + if (config_data != NULL) { + if (config_data->key != NULL) { + if (strcmp(config_data->key, sourceDatastore_key) == 0) { + if (config_data->value != NULL) + sourceDatastore = strdup(config_data->value); + } + + if (strcmp(config_data->key, targetDatastore_key) == 0) { + if (config_data->value != NULL) + targetDatastore = strdup(config_data->value); + } + + if (strcmp(config_data->key, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE) == 0) { + if (config_data->value != NULL) + sync_type = strdup(config_data->value); + } + + if (strcmp(config_data->key, id_key) == 0) { + if (config_data->value != NULL) + id = strdup(config_data->value); + } + + if (strcmp(config_data->key, pw_key) == 0) { + if (config_data->value != NULL) + pw = strdup(config_data->value); + } + } + } + } + + if (sync_type != NULL) { + alert_type = ___convert_sync_type_value(sync_type); + } else { + _DEBUG_ERROR("sync_type is NULL !"); + err = SE_INTERNAL_ERROR; + goto error; + } + + _DEBUG_VERBOSE("get_Config result sourceDatastore= %s ", sourceDatastore); + _DEBUG_VERBOSE("get_Config result targetDatastore= %s ", targetDatastore); + _DEBUG_VERBOSE("get_Config result alert_type= %s ", sync_type); + _DEBUG_VERBOSE("get_Config result id= %s ", id); + _DEBUG_VERBOSE("get_Config result pw= %s ", pw); + + temp_datastore = create_datastore(targetDatastore, sourceDatastore); + if (temp_datastore == NULL) { + _DEBUG_ERROR("temp_datastore is NULL"); + err = SE_INTERNAL_ERROR; + goto error; + } + + set_datastore_content_type_info(temp_datastore, content_type, folder_type_id); + set_datastore_account_info(temp_datastore, id, pw); + set_datastore_client_sync_type(temp_datastore, alert_type); + + *datastore = temp_datastore; + temp_datastore = NULL; + + 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); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __get_sync_type(int account_id, alert_type_e * alert_type) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + char *sync_type = NULL; + + bool result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_CLIENT_SYNC_TYPE, &sync_type); + if (result == false) { + _DEBUG_ERROR("failed in get_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + *alert_type = ___convert_sync_type_value(sync_type); + + error: + + if (sync_type != NULL) + free(sync_type); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __on_synchronising_account(int account_id) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + bool result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, "1", "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _off_synchronising_account(int account_id) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + bool result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SYNCHRONISING, "0", "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __on_resume_flag(int account_id) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + bool result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_RESUME, "1", "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _off_resume_flag(int account_id) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + bool result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_RESUME, "0", "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _assemble_changed_datastores(int account_id, alert_type_e server_sync_type, sync_obj_s ** sync_obj) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + changed_datastore_s *pChangedDatastore = NULL; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (!datastoreinfo_per_content_type[content_type]->client_sync_type) + continue; + + if (datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_SLOW_SYNC + || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_REFRESH_FROM_CLIENT || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_REFRESH_FROM_CLIENT_BY_SERVER) { + + if (content_type == TYPE_CALLLOG) { + _DEBUG_TRACE("sync_agent_refresh_item_tbl_from_service for call log"); + sync_agent_refresh_item_tbl_from_service(account_id, datastoreinfo_per_content_type[content_type]->datastore_id); + } + + GList *item_list = NULL; + sync_agent_da_get_item_list_query_s query; + query.option = SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_ACCOUNT_ID; + query.item_type_id = datastoreinfo_per_content_type[content_type]->datastore_id; + + da_err = sync_agent_get_item_list(account_id, &query, &item_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_item_list !!"); + } + + pChangedDatastore = create_changed_datastore(datastoreinfo_per_content_type[content_type]->source, datastoreinfo_per_content_type[content_type]->target, 1, g_list_length(item_list)); + + if (pChangedDatastore == NULL) { + sync_agent_free_item_list(item_list); + _DEBUG_ERROR("failed in create_ChangedDatastore"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + if (g_list_length(item_list) > 0) { + GList *iter = NULL; + sync_agent_da_item_s *iter_data; + for (iter = item_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = (sync_agent_da_item_s *) (iter->data); + if (iter_data != NULL) { + char *cttype = __convert_cttype_str(iter_data->data_store_id); + changed_item_s *pChanged = create_changed_item(CHANGE_ADD, iter_data->item_id); + if (pChanged == NULL) { + sync_agent_free_item_list(item_list); + _DEBUG_ERROR("failed in create_ChangedDatastore"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + set_changed_item_content_type(pChanged, cttype); + set_changed_item_index_of_datastore(pChanged, content_type); + + add_changed_datastore_changed_item(pChangedDatastore, pChanged); + } else { + _DEBUG_ERROR("iter_data is NULL !!"); + sync_agent_free_item_list(item_list); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + } + + sync_agent_free_item_list(item_list); + } + + GList *item_id_list = NULL; + + sync_agent_da_get_item_id_list_query_s item_id_query = {0,}; + item_id_query.option = SYNC_AGENT_DA_GET_ITEM_ID_LIST_OPTION_OPERATION_ID_N_ITEM_TYPE_ID; + item_id_query.account_id = account_id; + item_id_query.item_type_id = datastoreinfo_per_content_type[content_type]->datastore_id; + item_id_query.operation_id = SYNC_AGENT_DA_CHANGE_OPERATION_DELETE; + + da_err = sync_agent_get_item_id_list(&item_id_query, &item_id_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_item_id_list !!"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + GList *item_id_iter = NULL; + char *item_id; + + if (g_list_length(item_id_list) > 0) { + for (item_id_iter = item_id_list; item_id_iter != NULL; item_id_iter = g_list_next(item_id_iter)) { + item_id = NULL; + item_id = (char *)(item_id_iter->data); + + da_err = sync_agent_delete_item(item_id, 1); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_delete_item !!"); + sync_agent_free_item_id_list(item_id_list); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + } + + sync_agent_free_item_id_list(item_id_list); + + /*delete changelog data by account id and datastore id */ + sync_agent_da_delete_changelog_query_s delete_ch_query = {0,}; + delete_ch_query.option = SYNC_AGENT_DA_DELETE_CHANGELOG_OPTION_ITEM_TYPE_ID; + delete_ch_query.item_type_id = datastoreinfo_per_content_type[content_type]->datastore_id; + + da_err = sync_agent_delete_changelog(account_id, &delete_ch_query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_delete_changelog !!"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } else if (datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_TWO_WAY + || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_TWO_WAY_BY_SERVER + || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_ONE_WAY_FROM_CLIENT || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) { + _DEBUG_TRACE("server sync type is ALERT_TYPE [%d]", datastoreinfo_per_content_type[content_type]->server_sync_type); + + /*on resume flag into agent DB */ + err = __on_resume_flag(account_id); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __on_resume_flag"); + goto error; + } + + if (content_type == TYPE_CALLLOG) { + _DEBUG_TRACE("sync_agent_construct_item_tbl_from_service for call log"); + sync_agent_construct_item_tbl_from_service(account_id, content_type); + } + + /*from changelog */ + GList *item_info_list = NULL; + sync_agent_da_get_changelog_list_query_s get_ch_query; + get_ch_query.option = SYNC_AGENT_DA_GET_CHANGELOG_LIST_OPTION_ITEM_TYPE_ID; + get_ch_query.account_id = account_id; + get_ch_query.item_type_id = datastoreinfo_per_content_type[content_type]->datastore_id; + + da_err = sync_agent_get_changelog_list(&get_ch_query, &item_info_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_changelog_list !!"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + pChangedDatastore = create_changed_datastore(datastoreinfo_per_content_type[content_type]->source, datastoreinfo_per_content_type[content_type]->target, 1, g_list_length(item_info_list)); + + if (pChangedDatastore == NULL) { + sync_agent_free_changelog_list(item_info_list); + _DEBUG_ERROR("failed in create_ChangedDatastore"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + /*gathering changelog info */ + if (g_list_length(item_info_list) > 0) { + char *cttype = __convert_cttype_str(datastoreinfo_per_content_type[content_type]->datastore_id); + + GList *item_info_iter = NULL; + sync_agent_da_item_changelog_s *iter_data; + + for (item_info_iter = item_info_list; item_info_iter != NULL; item_info_iter = g_list_next(item_info_iter)) { + iter_data = NULL; + iter_data = (sync_agent_da_item_changelog_s *) (item_info_iter->data); + + if (iter_data != NULL) { + changed_item_s *pChanged = create_changed_item(iter_data->operation_id - 300, iter_data->item_id); + if (pChanged == NULL) { + sync_agent_free_changelog_list(item_info_list); + _DEBUG_ERROR("failed in create_ChangedDatastore"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + set_changed_item_content_type(pChanged, cttype); + set_changed_item_index_of_datastore(pChanged, content_type); + add_changed_datastore_changed_item(pChangedDatastore, pChanged); + } else { + sync_agent_free_changelog_list(item_info_list); + _DEBUG_ERROR("iter_data is NULL !!"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + } + + int *itemTypeIdList = (int *)calloc(1, sizeof(int)); + if (itemTypeIdList == NULL) { + _DEBUG_ERROR("failed in da_set_item_changelog_wait_status_internal"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + itemTypeIdList[0] = datastoreinfo_per_content_type[content_type]->datastore_id; + + sync_agent_da_update_changelog_query_s query; + query.option = SYNC_AGENT_DA_UPDATE_CHANGELOG_OPTION_WAIT_STATUS; + query.folder_id_list = NULL; + query.folder_id_count = 0; + query.item_type_id_list = itemTypeIdList; + query.item_type_id_count = 1; + + da_err = sync_agent_update_changelog(account_id, &query); + + sync_agent_free_changelog_list(item_info_list); + + if (itemTypeIdList != NULL) + free(itemTypeIdList); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_update_changelog !!"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + } else if (datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_ONE_WAY_FROM_SERVER + || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_ONE_WAY_FROM_SERVER_BY_SERVER + || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_REFRESH_FROM_SERVER || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_REFRESH_FROM_SERVER_BY_SERVER) { + + if (datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_ONE_WAY_FROM_SERVER) { + /*on resume flag into agent DB */ + err = __on_resume_flag(account_id); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __on_resume_flag"); + goto error; + } + } + + /*MUST create empty changedDatastore.. */ + pChangedDatastore = create_changed_datastore(datastoreinfo_per_content_type[content_type]->source, datastoreinfo_per_content_type[content_type]->target, 1, 0); + if (pChangedDatastore == NULL) { + _DEBUG_ERROR("pChangedDatastore is NULL"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + if (datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_REFRESH_FROM_SERVER || datastoreinfo_per_content_type[content_type]->server_sync_type == ALERT_REFRESH_FROM_SERVER_BY_SERVER) { + + /*_DEBUG_TRACE("sync_agent_refresh_item_tbl_from_service"); + sync_agent_refresh_item_tbl_from_service(account_id, datastoreinfo_per_content_type[content_type]->plugin_type);*/ + + /* Delete All item (include changelog), before adapting server item data… */ + _DEBUG_TRACE("sync_agent_begin_service = %d", datastoreinfo_per_content_type[content_type]->datastore_id); + sync_agent_begin_service(datastoreinfo_per_content_type[content_type]->datastore_id); + sync_agent_begin_transaction(); + + /*delete service item data */ + sync_agent_da_delete_service_item_query_s query; + query.content_type = datastoreinfo_per_content_type[content_type]->datastore_id; + query.account_id = account_id; + + da_err = sync_agent_query_delete_service_items(&query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + + sync_agent_end_service(datastoreinfo_per_content_type[content_type]->datastore_id, 0); + sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_ROLLBACK); + + _DEBUG_ERROR("failed in sync_agent_query_delete_service_items()"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + _DEBUG_TRACE("da_get_item_by_account_id_internal"); + /*get all item by account id */ + GList *item_list = NULL; + sync_agent_da_get_item_list_query_s get_item_query; + get_item_query.option = SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_ACCOUNT_ID; + get_item_query.item_type_id = datastoreinfo_per_content_type[content_type]->datastore_id; + + da_err = sync_agent_get_item_list(account_id, &get_item_query, &item_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_item_list !!"); + } + _DEBUG_TRACE("item_cnt = %d", g_list_length(item_list)); + + GList *item_iter = NULL; + sync_agent_da_item_s *item_iter_data; + for (item_iter = item_list; item_iter != NULL; item_iter = g_list_next(item_iter)) { + item_iter_data = NULL; + item_iter_data = (sync_agent_da_item_s *) (item_iter->data); + + GList *mapping_list = NULL; + sync_agent_da_get_item_list_query_s mapping_query; + mapping_query.option = SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_SERVICE_ID_MAPPING; + mapping_query.item_id = item_iter_data->item_id; + + da_err = sync_agent_get_item_list(account_id, &mapping_query, &mapping_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_item_list !!"); + } + + _DEBUG_TRACE("acc_cnt = %d", g_list_length(mapping_list)); + + GList *mapping_iter = NULL; + sync_agent_da_item_s *mapping_iter_data; + + for (mapping_iter = mapping_list; mapping_iter != NULL; mapping_iter = g_list_next(mapping_iter)) { + mapping_iter_data = NULL; + mapping_iter_data = (sync_agent_da_item_s *) (mapping_iter->data); + da_err = sync_agent_delete_item(mapping_iter_data->item_id, 1); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_delete_item !!"); + } + } + + sync_agent_free_item_list(mapping_list); + } + + /*delete changelog data by account id and datastore id */ + _DEBUG_TRACE("da_delete_item_changelog_by_item_type_id_internal = %d", datastoreinfo_per_content_type[content_type]->datastore_id); + + sync_agent_da_delete_changelog_query_s delete_ch_query; + delete_ch_query.option = SYNC_AGENT_DA_DELETE_CHANGELOG_OPTION_ITEM_TYPE_ID; + delete_ch_query.item_type_id = datastoreinfo_per_content_type[content_type]->datastore_id; + + da_err = sync_agent_delete_changelog(account_id, &delete_ch_query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + + sync_agent_free_item_list(item_list); + + sync_agent_end_service(datastoreinfo_per_content_type[content_type]->datastore_id, 0); + sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_ROLLBACK); + + _DEBUG_ERROR("failed in sync_agent_delete_changelog !!"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + /*delete item from item_tbl */ + _DEBUG_TRACE("da_delete_item_by_item_type_id_internal = %d", datastoreinfo_per_content_type[content_type]->datastore_id); + sync_agent_da_delete_item_query_s delete_item_query; + delete_item_query.option = SYNC_AGENT_DA_DELETE_ITEM_OPTION_ITEM_TYPE_ID; + delete_item_query.account_id = account_id; + delete_item_query.item_type_id = datastoreinfo_per_content_type[content_type]->datastore_id; + + da_err = sync_agent_query_delete_item(&delete_item_query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + sync_agent_free_item_list(item_list); + + sync_agent_end_service(datastoreinfo_per_content_type[content_type]->datastore_id, 0); + sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_ROLLBACK); + + _DEBUG_ERROR("failed in sync_agent_query_delete_item !!"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + _DEBUG_TRACE("sync_agent_end_service = %d", datastoreinfo_per_content_type[content_type]->datastore_id); + sync_agent_end_service(datastoreinfo_per_content_type[content_type]->datastore_id, 1); + sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT); + sync_agent_free_item_list(item_list); + } + } + if (datastoreinfo_per_content_type[content_type]->client_sync_type) { + (*sync_obj)->changed_datastore = g_list_append((*sync_obj)->changed_datastore, pChangedDatastore); + + /* for prevent */ + if (pChangedDatastore != NULL) { + set_number_of_change(datastoreinfo_per_content_type[content_type]->client_sync_result, pChangedDatastore->number_of_changes); + } else { + _DEBUG_ERROR("pChangedDatastore is NULL !"); + } + + operation_type_e operation_type; + if (datastoreinfo_per_content_type[content_type]->client_sync_result->number_of_change == 0) + operation_type = OPERATION_NOOP; + else + operation_type = OPERATION_ADD; + err = __process_update(account_id, server_sync_type, SYNC_PROGRESS_SUCCESS, operation_type, content_type, false, false, datastoreinfo_per_content_type[content_type]->client_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("Failed in process_update"); + goto error; + } + } + } + } + + _INNER_FUNC_EXIT; + return err; + + error: + + if (pChangedDatastore != NULL) { + free_changed_datastore(pChangedDatastore); + pChangedDatastore = NULL; + } + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _prepare_pre_sync(int account_id, char *sync_mode, san_package_s * san_package, alert_type_e * sync_type) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + /*set synchronising flag into agent DB */ + err = __on_synchronising_account(account_id); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __on_synchronising_account"); + goto error; + } + + /*get sync type */ + err = __get_sync_type(account_id, sync_type); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __get_sync_type"); + goto error; + } + + /*init datastore_info_array */ + err = __init_datastore_info_array(account_id); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __init_datastore_info_array"); + goto error; + } + + /*set config based on sync mode */ + err = __set_config_based_on_sync_mode(account_id, sync_mode, san_package); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __set_config_based_on_sync_mode"); + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __set_config_based_on_sync_mode(int account_id, char *sync_mode, san_package_s * san_package) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + int content_type; + + if (strcmp(sync_mode, DEFINE_SYNC_MODE_PUSH) == 0) { + if (san_package != NULL) { + int count = san_package->cnt_sync_alerts; + _DEBUG_TRACE("count = %d", count); + int i; + for (i = 0; i < count; i++) { + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + + if (datastoreinfo_per_content_type[content_type] != NULL) { + _DEBUG_TRACE("datastoreinfo_per_content_type[content_type]->target = %s", datastoreinfo_per_content_type[content_type]->target); + if (datastoreinfo_per_content_type[content_type]->target == NULL) + continue; + + if (strcmp(san_package->sync_alerts[i].server_uri, datastoreinfo_per_content_type[content_type]->target) == 0) { + datastoreinfo_per_content_type[content_type]->client_sync_type = san_package->sync_alerts[i].sync_type; + _DEBUG_TRACE("san_package->syncAlerts[i].sync_type = %d", san_package->sync_alerts[i].sync_type); + } else + datastoreinfo_per_content_type[content_type]->client_sync_type = ALERT_UNKNOWN; + } + } + } + } + } + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _execute_pre_sync(int account_id, int session_time, pre_sync_return_obj_s * pre_sync_return_obj, alert_type_e * server_sync_type) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + /*if there is no alert command from server check it and goto fail_part */ + if (g_list_length(pre_sync_return_obj->datastore_info) == 0) { + _DEBUG_TRACE("alert command list from server is empty"); + err = SE_INTERNAL_MISCONFIGURATION; + goto error; + } + + err = __execute_pre_sync_set_server_id(account_id, pre_sync_return_obj->dev_id); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __set_server_id"); + goto error; + } + + err = __execute_pre_sync_datastore(account_id, session_time, pre_sync_return_obj->datastore_info, server_sync_type); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __process_datastore"); + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; + +} + +static se_error_type_e __execute_pre_sync_set_server_id(int account_id, char *dev_id) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + bool result; + char *value = NULL; + + if (dev_id != NULL) { + result = get_config(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, &value); + if (result == true) { + if (value != NULL) { + if (strcmp(value, dev_id) == 0) { + /* OK */ + } else { + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, dev_id, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + } else { + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_ID, dev_id, "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + } else { + _DEBUG_ERROR("failed in get_Config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + error: + + if (value != NULL) { + free(value); + value = NULL; + } + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __execute_pre_sync_datastore(int account_id, int session_time, GList * datastore_info, alert_type_e * server_sync_type) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + int result; + + bool changeSyncType = false; + alert_type_e sync_type = ALERT_UNKNOWN; + + int content_type; + GList *serverDatastore_iter = NULL; + datastore_info_s *serverDatastoreInfo = NULL; + bool existInServerDatastore; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + existInServerDatastore = false; + + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->client_sync_type) { + _DEBUG_VERBOSE("datastoreinfo_per_content_type[%d]->client_sync_type = %d", content_type, datastoreinfo_per_content_type[content_type]->client_sync_type); + + for (serverDatastore_iter = datastore_info; 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; + + if (serverDatastoreInfo->next_anchor != NULL) + datastoreinfo_per_content_type[content_type]->next_anchor_server = strdup(serverDatastoreInfo->next_anchor); + + datastoreinfo_per_content_type[content_type]->server_sync_type = serverDatastoreInfo->sync_type; + + if (datastoreinfo_per_content_type[content_type]->client_sync_type != datastoreinfo_per_content_type[content_type]->server_sync_type) { + changeSyncType = true; + sync_type = datastoreinfo_per_content_type[content_type]->server_sync_type; + } + + _DEBUG_VERBOSE("datastoreinfo_per_content_type[%d]->server_sync_type = %d", content_type, datastoreinfo_per_content_type[content_type]->server_sync_type); + + if (datastoreinfo_per_content_type[content_type]->last_anchor_server) { + /*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]->server_sync_type == ALERT_SLOW_SYNC; + } */ + } else { + /* When first synchronize, lastAnchorServer is NULL... + if (datastoreinfo_per_content_type[content_type]->server_sync_type != ALERT_SLOW_SYNC + && datastoreinfo_per_content_type[content_type]->server_sync_type != ALERT_REFRESH_FROM_CLIENT + && datastoreinfo_per_content_type[content_type]->server_sync_type != ALERT_REFRESH_FROM_CLIENT_BY_SERVER + && datastoreinfo_per_content_type[content_type]->server_sync_type != ALERT_REFRESH_FROM_SERVER + && datastoreinfo_per_content_type[content_type]->server_sync_type != ALERT_REFRESH_FROM_SERVER_BY_SERVER) { + _DEBUG_VERBOSE("sync_agent_refresh_item_tbl_from_service"); + sync_agent_refresh_item_tbl_from_service(account_id, 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(account_id, ALERT_UNKNOWN, SYNC_FAILED_DB_CONFIG, OPERATION_NOOP, content_type, false, true, datastoreinfo_per_content_type[content_type]->client_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed to process_update"); + goto error; + } + + err = __process_update(account_id, ALERT_UNKNOWN, SYNC_FAILED_DB_CONFIG, OPERATION_NOOP, content_type, true, true, datastoreinfo_per_content_type[content_type]->server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed to process_update"); + goto error; + } + + /* set fail into result (both client and server) */ + if (datastoreinfo_per_content_type[content_type]->client_sync_result != NULL) + datastoreinfo_per_content_type[content_type]->client_sync_result->session_result = SYNC_SESSION_FAILED; + if (datastoreinfo_per_content_type[content_type]->server_sync_result != NULL) + datastoreinfo_per_content_type[content_type]->server_sync_result->session_result = SYNC_SESSION_FAILED; + + err = ___write_sync_resource_info(account_id, content_type, session_time, 0, datastoreinfo_per_content_type[content_type]->client_sync_result, datastoreinfo_per_content_type[content_type]->server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed to write_SyncResourceInfo"); + goto error; + } + + free_datastore(datastoreinfo_per_content_type[content_type]); + datastoreinfo_per_content_type[content_type] = NULL; + + datastore_s *datastore = NULL; + err = __init_datastore_info(account_id, content_type, &datastore); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed to init_datastore_info"); + goto error; + } + + datastoreinfo_per_content_type[content_type] = datastore; + } + } + } + } + + if (changeSyncType) { + *server_sync_type = sync_type; + result = set_config_str(account_id, DEFINE_CONFIG_KEY_PROFILE_SERVER_SYNC_TYPE, __convert_sync_type_str(sync_type), "string", "SE"); + if (result == false) { + _DEBUG_ERROR("failed in set_config"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _execute_sync(int account_id, alert_type_e client_sync_type, alert_type_e server_sync_type, sync_obj_s ** sync_obj, sync_return_obj_s ** sync_return_obj) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + if (client_sync_type == ALERT_TWO_WAY || client_sync_type == ALERT_TWO_WAY_BY_SERVER || client_sync_type == ALERT_ONE_WAY_FROM_CLIENT || client_sync_type == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) { + + err = __execute_sync_arrange_changelog(account_id, client_sync_type, (*sync_return_obj)->status); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed to process_update"); + goto error; + } + } + + err = __execute_sync_status(account_id, server_sync_type, sync_obj, sync_return_obj); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __execute_sync_status"); + goto error; + } + + err = __execute_sync_change(account_id, server_sync_type, sync_obj, sync_return_obj); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __execute_sync_change"); + goto error; + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __execute_sync_arrange_changelog(int account_id, alert_type_e sync_type, GList * status) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_da_return_e 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) { + _DEBUG_ERROR("Failed to alloc memory"); + err = SE_INTERNAL_NO_MEMORY; + goto error; + } + + GList *appliedStatus_iter = NULL; + applied_status_s *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 */ + if (pAppliedStatus->luid != NULL) + itemIdList[count++] = strdup(pAppliedStatus->luid); + + if (sync_type == ALERT_TWO_WAY || sync_type == ALERT_TWO_WAY_BY_SERVER || sync_type == ALERT_ONE_WAY_FROM_CLIENT || sync_type == ALERT_ONE_WAY_FROM_CLIENT_BY_SERVER) { + + if (pAppliedStatus->change_type == CHANGE_DELETE) { + da_err = sync_agent_delete_item(pAppliedStatus->luid, 0); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in da_delete_item_by_item_id_internal"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + } + break; + } + case 206: + case 420: + break; + case 400: + case 500: + { + sync_agent_da_item_changelog_s *get_changelog = NULL; + da_err = sync_agent_create_changelog(&get_changelog); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_changelog !!"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + da_err = sync_agent_get_changelog(account_id, pAppliedStatus->luid, &get_changelog); + if (da_err == SYNC_AGENT_DA_ERR_NO_DATA) { + _DEBUG_VERBOSE("%s item does not exist in ChangeLog tbl", pAppliedStatus->luid); + sync_agent_free_changelog(get_changelog); + break; + } else if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_changelog !!"); + sync_agent_free_changelog(get_changelog); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + if (get_changelog->status != NULL) { + if (strcmp(get_changelog->status, "SYNC_ERROR") == 0) { + if (pAppliedStatus->luid != NULL) + itemIdList[count++] = strdup(pAppliedStatus->luid); + } else { + sync_agent_da_item_changelog_s *set_changelog = NULL; + + da_err = sync_agent_create_changelog(&set_changelog); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_changelog !!"); + sync_agent_free_changelog(get_changelog); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + set_changelog->item_id = strdup(pAppliedStatus->luid); + set_changelog->status = strdup("SYNC_ERROR"); + set_changelog->access_name = strdup("SE"); + + sync_agent_da_update_changelog_query_s update_ch_query; + update_ch_query.option = SYNC_AGENT_DA_UPDATE_CHANGELOG_OPTION_SYNC_STATUS; + update_ch_query.update_item = set_changelog; + + da_err = sync_agent_update_changelog(account_id, &update_ch_query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_update_changelog !!"); + sync_agent_free_changelog(get_changelog); + sync_agent_free_changelog(set_changelog); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_free_changelog(set_changelog); + } + } + + sync_agent_free_changelog(get_changelog); + break; + } + } + } + + if (list_length >= 1) { + _DEBUG_TRACE("before da_delete_item_changelog_by_item_id_list_internal"); + _DEBUG_TRACE("count = %d", count); + + sync_agent_da_delete_changelog_query_s query; + query.option = SYNC_AGENT_DA_DELETE_CHANGELOG_OPTION_ITEM_ID_LIST; + query.item_id_list = itemIdList; + query.count = count; + + da_err = sync_agent_delete_changelog(account_id, &query); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_delete_changelog !!"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + } + + error: + + /*free itemIdList */ + if (itemIdList != NULL) { + for (i = 0; i < list_length; i++) { + if (itemIdList[i] != NULL) + free(itemIdList[i]); + } + free(itemIdList); + } + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __execute_sync_status(int account_id, alert_type_e server_sync_type, sync_obj_s ** sync_obj, sync_return_obj_s ** sync_return_obj) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + int content_type; + bool existEqualItem; + bool needToSave; + sync_result_s *pClientSyncResult; + GList *changedDatastore_iter = NULL; + changed_datastore_s *pSyncChangedDatastore = NULL; + for (changedDatastore_iter = (*sync_obj)->changed_datastore; changedDatastore_iter != NULL;) { + pSyncChangedDatastore = (changed_datastore_s *) changedDatastore_iter->data; + _DEBUG_VERBOSE("pChangedDatastore = %p", pSyncChangedDatastore); + + int datastoreContentType = 0; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (strcmp(pSyncChangedDatastore->source, datastoreinfo_per_content_type[content_type]->source) == 0) { + datastoreContentType = content_type; + break; + } + } + } + + GList *changedItem_iter = NULL; + changed_item_s *changedItem = NULL; + for (changedItem_iter = pSyncChangedDatastore->sent_item; changedItem_iter != NULL;) { + changedItem = changedItem_iter->data; + + existEqualItem = false; + GList *appliedStatus_iter = NULL; + applied_status_s *pAppliedStatus = NULL; + for (appliedStatus_iter = (*sync_return_obj)->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]->client_sync_result, 1); + + if (pAppliedStatus->status >= 200 && pAppliedStatus->status <= 210) { + switch (changedItem->change_type) { + case CHANGE_ADD: + add_add_count(datastoreinfo_per_content_type[datastoreContentType]->client_sync_result, 1); + break; + case CHANGE_REPLACE: + add_replace_count(datastoreinfo_per_content_type[datastoreContentType]->client_sync_result, 1); + break; + case CHANGE_DELETE: + add_delete_count(datastoreinfo_per_content_type[datastoreContentType]->client_sync_result, 1); + break; + default: + break; + } + } else { + /* if status is not success count it is failed */ + } + + (*sync_return_obj)->status = g_list_remove((*sync_return_obj)->status, pAppliedStatus); + free_applied_status(pAppliedStatus); + pAppliedStatus = NULL; + + changedItem_iter = g_list_next(changedItem_iter); + + pSyncChangedDatastore->sent_item = g_list_remove(pSyncChangedDatastore->sent_item, changedItem); + free_changed_item(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]->client_sync_result; + if (pClientSyncResult->number_of_change == pClientSyncResult->received_count) { + needToSave = true; + + if (datastoreinfo_per_content_type[datastoreContentType]->client_sync_result != NULL) + datastoreinfo_per_content_type[datastoreContentType]->client_sync_result->session_result = SYNC_SESSION_SUCCEEDED; + + /*remove datastore from list and + free current ChangedDatastore it does not need anymore because all item in datastore has been sent and receive status */ + (*sync_obj)->changed_datastore = g_list_remove((*sync_obj)->changed_datastore, pSyncChangedDatastore); + free_changed_datastore(pSyncChangedDatastore); + pSyncChangedDatastore = NULL; + } + + operation_type_e operation_type; + if (datastoreinfo_per_content_type[datastoreContentType]->client_sync_result->number_of_change == 0) + operation_type = OPERATION_NOOP; + else + operation_type = OPERATION_ADD; + err = __process_update(account_id, server_sync_type, SYNC_PROGRESS_SUCCESS, operation_type, datastoreContentType, false, needToSave, datastoreinfo_per_content_type[datastoreContentType]->client_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in process_update"); + goto error; + } + } + + error: + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e __execute_sync_change(int account_id, alert_type_e server_sync_type, sync_obj_s ** sync_obj, sync_return_obj_s ** sync_return_obj) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + sync_agent_da_service_item_s *service_item = NULL; + sync_agent_da_item_s *fw_item = NULL; + int content_type; + GList *f_id_list = NULL; + sync_result_s *tempServerSyncResult = NULL; + + /* process command that from server sended to client(sync, add, replace etc...) */ + changed_datastore_s *pSyncReturnChangedDatastore = NULL; + sending_status_s *sendingStatus = NULL; + GList *iter = NULL; + for (iter = (*sync_return_obj)->changed_datastore; iter != NULL;) { + pSyncReturnChangedDatastore = (changed_datastore_s *) iter->data; + + int datastoreContentType = 0; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (strcmp(pSyncReturnChangedDatastore->target, datastoreinfo_per_content_type[content_type]->source) == 0) { + datastoreContentType = content_type; + break; + } + } + } + + /*noti to UI numberOfChanges from server */ + if (pSyncReturnChangedDatastore->has_number_of_changes) { + set_number_of_change(datastoreinfo_per_content_type[datastoreContentType]->server_sync_result, pSyncReturnChangedDatastore->number_of_changes); + + operation_type_e operation_type; + if (datastoreinfo_per_content_type[datastoreContentType]->server_sync_result->number_of_change == 0) + operation_type = OPERATION_NOOP; + else + operation_type = OPERATION_ADD; + err = __process_update(account_id, server_sync_type, SYNC_PROGRESS_SUCCESS, operation_type, datastoreContentType, true, false, datastoreinfo_per_content_type[datastoreContentType]->server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in process_update"); + goto error; + } + } + + sendingStatus = create_sending_status(pSyncReturnChangedDatastore->target, pSyncReturnChangedDatastore->source); + if (sendingStatus == NULL) { + err = SE_INTERNAL_NO_MEMORY; + _DEBUG_ERROR("failed to alloc memory"); + goto error; + } + + /*get folderId */ + char *folderId = NULL; + sync_agent_da_get_folder_id_list_query_s query; + query.option = SYNC_AGENT_DA_GET_FOLDER_ID_OPTION_FOLDER_TYPE_ID; + query.account_id = account_id; + query.item_type_id = datastoreinfo_per_content_type[datastoreContentType]->datastore_id; + query.folder_type_id = datastoreinfo_per_content_type[datastoreContentType]->folder_type_id; + + da_err = sync_agent_get_folder_id_list(&query, &f_id_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_get_folder_id_list_inferface() failed !!"); + goto error; + } + + if (g_list_length(f_id_list) > 0) { + GList *iter = g_list_nth(f_id_list, 0); + folderId = (char *)(iter->data); + } else { + _DEBUG_ERROR("failed to get folderId"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + int changeItemCount = g_list_length(pSyncReturnChangedDatastore->change_item); + if (changeItemCount > 0) { + /*begin transaction */ + _DEBUG_VERBOSE("sync_agent_begin_service with datastoreContentType = %d", datastoreContentType); +// sync_agent_begin_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id); + sync_agent_begin_transaction(); + + /*back up syncresult structure for rollback case */ + tempServerSyncResult = dup_sync_result(datastoreinfo_per_content_type[datastoreContentType]->server_sync_result); + } + + bool needToSave = false; + sync_result_s *pServerSyncResult = NULL; + GList *changedIter = NULL; + changed_item_s *changedItem = NULL; + applied_status_s *appliedStatus = NULL; + + for (changedIter = pSyncReturnChangedDatastore->change_item; changedIter != NULL; changedIter = g_list_next(changedIter)) { + changedItem = (changedIter->data); + + _DEBUG_VERBOSE("changedItem->changeType : %d", changedItem->change_type); + _DEBUG_VERBOSE("changedItem->luid : %s", changedItem->luid); + _DEBUG_VERBOSE("changedItem->content_type : %s", changedItem->content_type); + _DEBUG_VERBOSE("changedItem->indexOfDatastore : %d", changedItem->index_of_datastore); + _DEBUG_VERBOSE("changedItem->data : %s", changedItem->data); + + add_receive_count(datastoreinfo_per_content_type[datastoreContentType]->server_sync_result, 1); + + bool da_fail = false; + command_result_e returnResult = COMMAND_RESULT_INIT; + switch (changedItem->change_type) { + case CHANGE_ADD: + { + /* add to service DB */ + if (changedItem->data != NULL) { + char *fw_id = NULL; + + da_err = sync_agent_create_service_item(&service_item); + if ((da_err != SYNC_AGENT_DA_SUCCESS) || (service_item == NULL)) { + _DEBUG_ERROR("failed in sync_agent_create_service_item() = %d", da_err); + returnResult = ___convert_return_status(da_err); + da_fail = true; + break; + } + + service_item->item_id = g_strdup(changedItem->luid); + service_item->content_type = datastoreinfo_per_content_type[datastoreContentType]->datastore_id; + service_item->account_id = account_id; + service_item->folder_id = g_strdup(folderId); + service_item->access_name = g_strdup("Engine"); + service_item->data = g_strdup(changedItem->data); + sync_agent_begin_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id); + + da_err = sync_agent_add_service_item(service_item, &fw_id, false); + + sync_agent_end_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 1); + + _DEBUG_VERBOSE("da_err = %d", da_err); + + if (da_err == SYNC_AGENT_DA_SUCCESS) { + int acc_cnt; + bool success = true; + char *service_id = sync_agent_get_service_item_id(fw_id); + + GList *folder_list = NULL; + sync_agent_da_get_folder_list_query_s query; + query.option = SYNC_AGENT_DA_GET_FOLDER_LIST_OPTION_SERVICE_ID_MAPPING; + query.account_id = account_id; + query.folder_id = folderId; + da_err = sync_agent_get_folder_list(&query, &folder_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_get_folder_list() failed !!"); + success = false; + } + + acc_cnt = g_list_length(folder_list); + + _DEBUG_VERBOSE("acc_cnt = %d", acc_cnt); + if (acc_cnt > 0) { + char **fw_item_id_list = sync_agent_generate_item_luid(1, acc_cnt); + char **id_list = (char **)calloc(acc_cnt, sizeof(char *)); + if (id_list == NULL) { + _DEBUG_ERROR("CALLOC failed !!!"); + success = false; + break; + } + + if (fw_item_id_list == NULL) { + _DEBUG_ERROR("failed in sync_agent_generate_item_luid"); + da_err = SYNC_AGENT_DA_ERRORS; + success = false; + } else { + int i = 0; + GList *iter = NULL; + sync_agent_da_folder_s *iter_data; + + for (iter = folder_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = (sync_agent_da_folder_s *) (iter->data); + + da_err = sync_agent_create_item(&fw_item); + if ((da_err != SYNC_AGENT_DA_SUCCESS) || (fw_item == NULL)) { + _DEBUG_ERROR("failed in sync_agent_create_item() = %d", da_err); + success = false; + break; + } + + fw_item->item_id = g_strdup(fw_item_id_list[i]); + fw_item->data_store_id = datastoreinfo_per_content_type[datastoreContentType]->datastore_id; + fw_item->account_id = iter_data->account_id; + fw_item->folder_id = g_strdup(iter_data->folder_id); + fw_item->service_id = g_strdup(service_id); + fw_item->access_name = g_strdup("DACI_ChangeLog"); + + da_err = sync_agent_add_item(fw_item, &(id_list[i]), true); + if (fw_item != NULL) + sync_agent_free_item(fw_item); + free(fw_item_id_list[i]); + free(id_list[i]); + + i++; + + _DEBUG_VERBOSE("da_err = %d", da_err); + + if (da_err != SYNC_AGENT_DA_SUCCESS) { + success = false; + break; + } + } + if (fw_item_id_list != NULL) { + free(fw_item_id_list); + } + if (id_list != NULL) { + free(id_list); + } + } + } + + if (success == true) { + returnResult = COMMAND_RESULT_ADDED; + add_add_count(datastoreinfo_per_content_type[datastoreContentType]->server_sync_result, 1); + } else { + /*this case just fail do rollback and goto fail */ + returnResult = ___convert_return_status(da_err); + da_fail = true; + } + sync_agent_free_folder_list(folder_list); + + if (service_id != NULL) + free(service_id); + + } else if (da_err == SYNC_AGENT_DA_ERR_NOT_SUPPORTED || da_err == SYNC_AGENT_DA_ERR_INVALID_CONTENT || da_err == SYNC_AGENT_DA_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_item != NULL) + sync_agent_free_service_item(service_item); + + if (fw_id != NULL) + free(fw_id); + } else + returnResult = COMMAND_RESULT_COMMAND_FAIL; + + break; + } + case CHANGE_REPLACE: + { + if (changedItem->data != NULL) { + /* update from service DB */ + da_err = sync_agent_create_service_item(&service_item); + if (da_err != SYNC_AGENT_DA_SUCCESS || (service_item == NULL)) { + _DEBUG_ERROR("failed in sync_agent_create_service_item() = %d", da_err); + returnResult = ___convert_return_status(da_err); + da_fail = true; + break; + } + + service_item->item_id = g_strdup(changedItem->luid); + service_item->content_type = datastoreinfo_per_content_type[datastoreContentType]->datastore_id; + service_item->account_id = account_id; + service_item->folder_id = g_strdup(folderId); + service_item->access_name = g_strdup("Engine"); + service_item->data = (const void *)g_strdup(changedItem->data); + + sync_agent_begin_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id); + + da_err = sync_agent_update_service_item(service_item, changedItem->luid, false); + + sync_agent_end_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 1); + + _DEBUG_VERBOSE("da_err = %d", da_err); + if (da_err == SYNC_AGENT_DA_SUCCESS) { + + GList *item_list = NULL; + sync_agent_da_get_item_list_query_s query; + query.option = SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_SERVICE_ID_MAPPING; + query.item_id = changedItem->luid; + + da_err = sync_agent_get_item_list(account_id, &query, &item_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_item_list !!"); + } + + bool success = true; + GList *iter = NULL; + sync_agent_da_item_s *iter_data; + + for (iter = item_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = (sync_agent_da_item_s *) (iter->data); + + da_err = sync_agent_update_item(iter_data->item_id, 1); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + success = false; + break; + } + } + + if (success == true) { + returnResult = COMMAND_RESULT_OK; + add_replace_count(datastoreinfo_per_content_type[datastoreContentType]->server_sync_result, 1); + } else { + /*this case just fail do rollback and goto fail */ + returnResult = ___convert_return_status(da_err); + da_fail = true; + } + + sync_agent_free_item_list(item_list); + } else if (da_err == SYNC_AGENT_DA_ERR_NOT_SUPPORTED || da_err == SYNC_AGENT_DA_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; + } + + if (service_item != NULL) + sync_agent_free_service_item(service_item); + } else + returnResult = COMMAND_RESULT_COMMAND_FAIL; + + break; + } + case CHANGE_DELETE: + { + /* delete from service DB */ + GList *item_list = NULL; + sync_agent_da_get_item_list_query_s query; + query.option = SYNC_AGENT_DA_GET_ITEM_LIST_OPTION_SERVICE_ID_MAPPING; + query.item_id = changedItem->luid; + + da_err = sync_agent_get_item_list(account_id, &query, &item_list); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_item_list !!"); + } + + sync_agent_begin_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id); + + da_err = sync_agent_delete_service_item(changedItem->luid, false); + + sync_agent_end_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 1); + + _DEBUG_VERBOSE("[sync_agent_delete_service_item] result : %d", da_err); + if (da_err == SYNC_AGENT_DA_SUCCESS) { + bool success = true; + GList *iter = NULL; + sync_agent_da_item_s *iter_data; + + for (iter = item_list; iter != NULL; iter = g_list_next(iter)) { + iter_data = NULL; + iter_data = (sync_agent_da_item_s *) (iter->data); + + da_err = sync_agent_delete_item(iter_data->item_id, true); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + success = false; + break; + } + } + + if (success == true) { + returnResult = COMMAND_RESULT_DELETE_WITHOUT_ARCHIVE; + add_delete_count(datastoreinfo_per_content_type[datastoreContentType]->server_sync_result, 1); + } else { + /*this case just fail do rollback and goto fail */ + returnResult = ___convert_return_status(da_err); + da_fail = true; + } + } else if (da_err == SYNC_AGENT_DA_ERR_NO_DATA || da_err == SYNC_AGENT_DA_ERR_SUB_DATA_EXIST || da_err == SYNC_AGENT_DA_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; + } + sync_agent_free_item_list(item_list); + break; + } + default: + break; + } + + if (da_fail == true) { + /*replace syncresult when rollback happened */ + if (datastoreinfo_per_content_type[datastoreContentType]->server_sync_result != NULL) + free(datastoreinfo_per_content_type[datastoreContentType]->server_sync_result); + + datastoreinfo_per_content_type[datastoreContentType]->server_sync_result = tempServerSyncResult; + tempServerSyncResult = NULL; + + _DEBUG_VERBOSE("Transaction_Rollback"); + _DEBUG_VERBOSE("sync_agent_end_service with datastoreContentType = %d", datastoreContentType); +// sync_agent_end_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 0); + sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_ROLLBACK); + + err = SE_INTERNAL_DA_ERROR; + _DEBUG_ERROR("failed in DA"); + goto error; + } + + appliedStatus = create_applied_status(changedItem->luid, changedItem->change_type, returnResult); + if (appliedStatus == NULL) { + _DEBUG_VERBOSE("Transaction_Rollback"); + _DEBUG_VERBOSE("sync_agent_end_service with datastoreContentType = %d", datastoreContentType); +// sync_agent_end_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 0); + sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_ROLLBACK); + + err = SE_INTERNAL_NO_MEMORY; + _DEBUG_ERROR("failed to alloc memory"); + goto error; + } + add_sending_status_applied_status(sendingStatus, appliedStatus); + } + + if (changeItemCount > 0) { + /*end transaction */ + _DEBUG_VERBOSE("sync_agent_end_service with datastoreContentType = %d", datastoreContentType); +// sync_agent_end_service(datastoreinfo_per_content_type[datastoreContentType]->datastore_id, 1); + sync_agent_end_transaction(SYNC_AGENT_DA_TRANSACTION_COMMIT); + } + + /* Do not need to send update event to ui when changeItemCount less than 0 */ + /* send update event about add, delete, replace count during this sync command */ + if (changeItemCount >= 0) { + needToSave = false; + pServerSyncResult = datastoreinfo_per_content_type[datastoreContentType]->server_sync_result; + if (pServerSyncResult->number_of_change == pServerSyncResult->received_count) { + needToSave = true; + + if (datastoreinfo_per_content_type[datastoreContentType]->server_sync_result != NULL) + datastoreinfo_per_content_type[datastoreContentType]->server_sync_result->session_result = SYNC_SESSION_SUCCEEDED; + } + + operation_type_e operation_type; + if (datastoreinfo_per_content_type[datastoreContentType]->server_sync_result->number_of_change == 0) + operation_type = OPERATION_NOOP; + else + operation_type = OPERATION_ADD; + err = __process_update(account_id, server_sync_type, SYNC_PROGRESS_SUCCESS, operation_type, datastoreContentType, true, needToSave, datastoreinfo_per_content_type[datastoreContentType]->server_sync_result); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in process_update"); + goto error; + } + } + + (*sync_obj)->sending_status = g_list_append((*sync_obj)->sending_status, sendingStatus); + sendingStatus = NULL; + + iter = g_list_next(iter); + + (*sync_return_obj)->changed_datastore = g_list_remove((*sync_return_obj)->changed_datastore, pSyncReturnChangedDatastore); + free_changed_datastore(pSyncReturnChangedDatastore); + pSyncReturnChangedDatastore = NULL; + + if (tempServerSyncResult != NULL) { + free(tempServerSyncResult); + tempServerSyncResult = NULL; + } + } + + error: + sync_agent_free_folder_id_list(f_id_list); + + if (tempServerSyncResult != NULL) + free(tempServerSyncResult); + + /* for prevent */ + free_sending_status(sendingStatus); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _update_sync_result(int account_id) +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + int content_type; + + sync_agent_da_last_anchor_s next_anchor_info; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (!datastoreinfo_per_content_type[content_type]->client_sync_type) + continue; + + next_anchor_info.access_name = "Engine"; + next_anchor_info.account_id = account_id; + 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]->next_anchor_client; + next_anchor_info.last_anchor_server = datastoreinfo_per_content_type[content_type]->next_anchor_server; + + da_err = sync_agent_update_last_anchor(&next_anchor_info); + if (da_err != SYNC_AGENT_DA_SUCCESS) + _DEBUG_ERROR("failed in da_set_last_anchor_internal"); + + da_err = sync_agent_set_service_change_point(account_id, datastoreinfo_per_content_type[content_type]->datastore_id); + if (da_err != SYNC_AGENT_DA_SUCCESS) + _DEBUG_ERROR("failed in sync_agent_set_service_change_point"); + } + } + + _INNER_FUNC_EXIT; + return err; +} + +static command_result_e ___convert_return_status(sync_agent_da_return_e da_err) +{ + _INNER_FUNC_ENTER; + + command_result_e returnResult = COMMAND_RESULT_INIT; + switch (da_err) { + case 1: /*SYNC_AGENT_DA_SUCCESS */ + /*never comes this case + break; */ + case -813: /*SYNC_AGENT_DA_ERR_ALREADY_EXIST */ + returnResult = COMMAND_RESULT_ALREADY_EXIST; /*[A] Already exists exception */ + break; + case -815: /*SYNC_AGENT_DA_ERR_MEMORY_FULL *//* oma : 420 (device full exception) */ + returnResult = COMMAND_RESULT_DEVICE_FULL; /*[AR] Device full exception */ + break; + case -820: /*SYNC_AGENT_DA_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: /*SYNC_AGENT_DA_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: /*SYNC_AGENT_DA_ERRORS */ + case -801: /*SYNC_AGENT_DA_NOT_FOUND_PLUG_IN */ + case -802: /*SYNC_AGENT_DA_ERR_OPEN_FAILED */ + case -803: /*SYNC_AGENT_DA_ERR_CLOSE_FAILED */ + case -804: /*SYNC_AGENT_DA_ERR_TRANSACTION_FAILED */ + case -805: /*SYNC_AGENT_DA_ERR_CREATE_TABLE_FAILED */ + case -806: /*SYNC_AGENT_DA_ERR_DROP_TABLE_FAILED */ + case -807: /*SYNC_AGENT_DA_ERR_QUERY_FAILED */ + case -808: /*SYNC_AGENT_DA_ERR_NOT_OPENED */ + case -809: /*SYNC_AGENT_DA_ERR_ACCOUNT_FULL */ + case -810: /*SYNC_AGENT_DA_ERR_DELETE_LAST_ACCOUNT */ + case -811: /*SYNC_AGENT_DA_ERR_PRIMARY_KEY_NOT_UNIQUE */ + case -812: /*SYNC_AGENT_DA_ERR_DB_HANDLER_MGR */ + case -814: /*SYNC_AGENT_DA_ERR_INVALID_CONTENT */ + case -816: /*SYNC_AGENT_DA_ERR_SUB_DATA_EXIST *//* oma : 427 (item not empty) */ + case -817: /*SYNC_AGENT_DA_ERR_LOCKED *//* kies : cannot access */ + case -818: /*SYNC_AGENT_DA_ERR_MORE_DATA */ + case -821: /*SYNC_AGENT_DA_ERR_NOT_EXECUTE *//* kies : ex) sms send command, no network service */ + default: + returnResult = COMMAND_RESULT_COMMAND_FAIL; /*[ARD] Command failed exception */ + break; + } + + _INNER_FUNC_EXIT; + return returnResult; +} + +static char *__convert_cttype_str(int datastore_id) +{ + _INNER_FUNC_ENTER; + + 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; + case TYPE_CALLLOG: + cttype = ELEMENT_TEXT_XCALLLOG; + break; + default: + break; + } + + _INNER_FUNC_EXIT; + return cttype; +} + +static int ___convert_sync_type_value(char *sync_type_str) +{ + _INNER_FUNC_ENTER; + + int sync_type_value; + + if (strcmp(sync_type_str, DEFINE_ALERT_SLOW_SYNC_STR) == 0) + sync_type_value = ALERT_SLOW_SYNC; + else if (strcmp(sync_type_str, DEFINE_ALERT_TWO_WAY_STR) == 0) + sync_type_value = ALERT_TWO_WAY; + else if (strcmp(sync_type_str, DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR) == 0) + sync_type_value = ALERT_ONE_WAY_FROM_CLIENT; + else if (strcmp(sync_type_str, DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR) == 0) + sync_type_value = ALERT_ONE_WAY_FROM_SERVER; + else if (strcmp(sync_type_str, DEFINE_ALERT_REFRESH_FROM_SERVER_STR) == 0) + sync_type_value = ALERT_REFRESH_FROM_SERVER; + else if (strcmp(sync_type_str, DEFINE_ALERT_REFRESH_FROM_CLIENT_STR) == 0) + sync_type_value = ALERT_REFRESH_FROM_CLIENT; + else + sync_type_value = ALERT_UNKNOWN; + + _INNER_FUNC_EXIT; + return sync_type_value; +} + +static char *__convert_sync_type_str(alert_type_e sync_type) +{ + _INNER_FUNC_ENTER; + + char *sync_Type = NULL; + + switch (sync_type) { + case ALERT_TWO_WAY: + sync_Type = DEFINE_ALERT_TWO_WAY_STR; + break; + case ALERT_SLOW_SYNC: + sync_Type = DEFINE_ALERT_SLOW_SYNC_STR; + break; + case ALERT_ONE_WAY_FROM_CLIENT: + sync_Type = DEFINE_ALERT_ONE_WAY_FROM_CLIENT_STR; + break; + case ALERT_REFRESH_FROM_CLIENT: + sync_Type = DEFINE_ALERT_REFRESH_FROM_CLIENT_STR; + break; + case ALERT_ONE_WAY_FROM_SERVER: + sync_Type = DEFINE_ALERT_ONE_WAY_FROM_SERVER_STR; + break; + case ALERT_REFRESH_FROM_SERVER: + sync_Type = DEFINE_ALERT_REFRESH_FROM_SERVER_STR; + break; + default: + sync_Type = DEFINE_ALERT_UNKNOWN_STR; + break; + } + + _INNER_FUNC_EXIT; + return sync_Type; +} + +static char *___convert_sync_progress_status_str(sync_progress_status_e progress_status) +{ + _INNER_FUNC_ENTER; + + char *progress = NULL; + + switch (progress_status) { + 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; + } + + _INNER_FUNC_EXIT; + return progress; +} + +static char *___convert_operation_type_str(operation_type_e operation_type) +{ + _INNER_FUNC_ENTER; + + char *operation = NULL; + + switch (operation_type) { + 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; + } + + _INNER_FUNC_EXIT; + return operation; +} + +static char *_convert_sync_progress_str(sync_progress_e process) +{ + _INNER_FUNC_ENTER; + + char *syncProcess = 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; + } + + _INNER_FUNC_EXIT; + return syncProcess; +} + +static char *_convert_sync_error_str(sync_error_e error) +{ + _INNER_FUNC_ENTER; + + char *syncError = NULL; + + 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; + case ERROR_LOW_BATTERY: + syncError = DEFINE_ERROR_LOW_BATTERY; + break; + default: + break; + } + + _INNER_FUNC_EXIT; + return syncError; +} + +static se_error_type_e _check_low_battery() +{ + _INNER_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_dev_return_e dci_err = SYNC_AGENT_DEV_RETURN_SUCCESS; + char *battery_level = NULL; + int int_battery_level = 0; + + dci_err = sync_agent_get_devinfo(1, "Battery", &battery_level); + if (dci_err != SYNC_AGENT_DEV_RETURN_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_get_devinfo = %d", dci_err); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + _DEBUG_TRACE("battery_level =%s", battery_level); + + if (battery_level != NULL) { + int_battery_level = atoi(battery_level); + + if (int_battery_level < LOW_BATTERY_LEVEL) { + _DEBUG_ERROR("LOW Battery = %d", int_battery_level); + err = SE_INTERNAL_LOW_BATTERY; + goto error; + } + } + + error: + + if (battery_level != NULL) + free(battery_level); + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _open_services() +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (!datastoreinfo_per_content_type[content_type]->client_sync_type) + continue; + + da_err = sync_agent_open_service(content_type); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_open_service(%d) is failed", content_type); + err = SE_INTERNAL_DA_ERROR; + break; + } + } + } + + _INNER_FUNC_EXIT; + return err; +} + +static se_error_type_e _close_services() +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (!datastoreinfo_per_content_type[content_type]->client_sync_type) + continue; + + da_err = sync_agent_close_service(content_type); + if (da_err != SYNC_AGENT_DA_SUCCESS) + _DEBUG_ERROR("sync_agent_close_service(%d) is failed", content_type); + } + } + + _INNER_FUNC_EXIT; + return err; +} + +bool synchronize(int account_id, char *sync_mode, san_package_s * san_package) +{ + _EXTERN_FUNC_ENTER; + + _DEBUG_INFO("accountID = %d", account_id); + _DEBUG_INFO("sync_mode = %s", sync_mode); + + /*FIXME remove msg file */ + int ret_val = remove(OMA_DS_MSG_PATH); + if (ret_val < 0) { + _DEBUG_ERROR("failed in synchronize - remove()"); + } + + /*FIXME time check */ + long t, dt; + t = myclock(); + + se_error_type_e err = SE_INTERNAL_OK; + sync_agent_dev_return_e dci_result = SYNC_AGENT_DEV_RETURN_SUCCESS; + sync_agent_da_return_e da_err = SYNC_AGENT_DA_SUCCESS; + + common_error_type_e errorCode = COMMON_OK; + sync_progress_e process = PROGRESS_NONE; + sync_error_e error = ERROR_NONE; + + alert_type_e client_sync_type = ALERT_UNKNOWN; + alert_type_e server_sync_type = ALERT_UNKNOWN; + int only_from_client = 0; + + int session_time = sync_agent_convert_seconds_to_utc(time(NULL)); /*lastSessionTime for resultView; */ + _DEBUG_INFO("session_time = %d", session_time); + + pre_sync_return_obj_s *pre_sync_return_obj = NULL; + sync_obj_s *sync_obj = NULL; + sync_return_obj_s *sync_return_obj = NULL; + + bool cancel_flag = false; + int content_type; + char *session_id = NULL; + + char *access_name = NULL; + bool server_flag = false; + + char *msg = NULL; + unsigned int msg_size; + char *recvMsg = NULL; + unsigned int recvMsg_size; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + + dci_result = sync_agent_execute_dev_function(DEFINE_PLATFORM, "pm_lock", 3, LCD_OFF, STAY_CUR_STATE, 0); + if (dci_result != SYNC_AGENT_DEV_RETURN_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_execute_dev_function lock = %d", dci_result); + } + + /* low battery check */ + err = _check_low_battery(); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("check_low_battery = %d", err); + goto fail_part; + } + + da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_agent = %d", da_err); + err = SE_INTERNAL_DA_ERROR; + goto fail_part; + } + + /* prepare for sending pre sync */ + err = _prepare_pre_sync(account_id, sync_mode, san_package, &client_sync_type); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __prepare_pre_sync = %d", err); + goto fail_part; + } + + /* check cancel flag */ + cancel_flag = sync_agent_check_cancel_flag(); + if (cancel_flag) { + err = SE_INTERNAL_CANCEL; + _DEBUG_INFO("cancle flag is on"); + goto cancel_part; + } + + pre_sync_return_obj = (pre_sync_return_obj_s *) calloc(1, sizeof(pre_sync_return_obj_s)); + if (pre_sync_return_obj == NULL) { + _DEBUG_ERROR("failed to alloc memory"); + err = SE_INTERNAL_NO_MEMORY; + goto fail_part; + } + + acc_err = sync_agent_create_fw_account(&fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_create_fw_account"); + err = SE_INTERNAL_NO_MEMORY; + goto fail_part; + } + + acc_err = sync_agent_get_fw_account(account_id, &fw_account); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_update_fw_account"); + err = SE_INTERNAL_ERROR; + goto fail_part; + } + + access_name = strdup(fw_account->access_name); + if (strcmp(access_name, "DIVE") == 0) { + server_flag = true; + } + + /*pkg 1 */ + if (strcmp(sync_mode, DEFINE_SYNC_MODE_PUSH) == 0) { + _DEBUG_INFO("sessionID = %d", san_package->session_id); + session_id = g_strdup_printf("%u", san_package->session_id); /*freed in pre_sync */ + errorCode = pre_sync(TRANSPORT_TYPE, account_id, session_id, server_flag, (void **)&pre_sync_return_obj); + } else + errorCode = pre_sync(TRANSPORT_TYPE, account_id, NULL, server_flag, (void **)&pre_sync_return_obj); + + /* check cancel flag */ + cancel_flag = sync_agent_check_cancel_flag(); + if (cancel_flag) { + err = SE_INTERNAL_CANCEL; + _DEBUG_INFO("cancle flag is on"); + goto cancel_part; + } + + _DEBUG_INFO("pre_sync errorCode =[%d]", errorCode); + if (errorCode != COMMON_OK) { + err = SE_INTERNAL_SA_ERROR; + goto fail_part; + } + + /*execute pre_sync return */ + server_sync_type = client_sync_type; + err = _execute_pre_sync(account_id, session_time, pre_sync_return_obj, &server_sync_type); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __process_pre_sync = %d", err); + goto fail_part; + } + + if (server_sync_type == ALERT_REFRESH_FROM_CLIENT || server_sync_type == ALERT_ONE_WAY_FROM_CLIENT) + only_from_client = 1; + + _DEBUG_INFO("client_sync_type = %d", client_sync_type); + _DEBUG_INFO("server_sync_type = %d", server_sync_type); + _DEBUG_INFO("only_from_client = %d", only_from_client); + + _session_process(account_id, server_sync_type, PROGRESS_AUTHENTICATED, ERROR_NONE); + + /* check cancel flag */ + cancel_flag = sync_agent_check_cancel_flag(); + if (cancel_flag) { + err = SE_INTERNAL_CANCEL; + _DEBUG_INFO("cancle flag is on"); + goto cancel_part; + } + + err = _open_services(); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __prepare_pre_sync = %d", err); + goto fail_part; + } + + /* pkg 3 */ + _DEBUG_INFO("pre_sync end pkg3 start"); + sync_obj = (sync_obj_s *) calloc(1, sizeof(sync_obj_s)); + if (sync_obj == NULL) { + _DEBUG_ERROR("failed to alloc memory"); + err = SE_INTERNAL_NO_MEMORY; + goto fail_part; + } + + sync_return_obj = (sync_return_obj_s *) calloc(1, sizeof(sync_return_obj_s)); + if (sync_return_obj == NULL) { + _DEBUG_ERROR("failed to alloc memory"); + err = SE_INTERNAL_NO_MEMORY; + goto fail_part; + } + + err = _assemble_changed_datastores(account_id, server_sync_type, &sync_obj); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __assemble_changeddatastore = %d", err); + goto fail_part; + } + + /* check cancel flag */ + cancel_flag = sync_agent_check_cancel_flag(); + if (cancel_flag) { + err = SE_INTERNAL_CANCEL; + _DEBUG_INFO("cancle flag is on"); + goto cancel_part; + } + + int isFinish = 0; + while (!isFinish) { + + errorCode = generate_msg((void **)&sync_obj, server_flag, &msg, &msg_size); + if (errorCode != COMMON_OK) { + _DEBUG_ERROR("Failed in generate_Msg = %d", errorCode); + err = SE_INTERNAL_SA_ERROR; + goto fail_part; + } + + errorCode = exchange_msg(TRANSPORT_TYPE, msg, msg_size, &recvMsg, &recvMsg_size); + if (errorCode != COMMON_OK) { + _DEBUG_ERROR("Failed in exchange_Msg = %d", errorCode); + if (errorCode == COMMON_CANCEL) { + bool cancel_status = check_cancel_status(); + if (cancel_status) { + err = SE_INTERNAL_SUSPEND; + _DEBUG_INFO("cancle flag is on"); + goto suspend_part; + } + } else { + err = SE_INTERNAL_SA_ERROR; + goto fail_part; + } + } + + /* check cancel flag */ + cancel_flag = sync_agent_check_cancel_flag(); + if (cancel_flag) { + bool cancel_status = check_cancel_status(); + if (cancel_status) { + err = SE_INTERNAL_SUSPEND; + _DEBUG_INFO("cancle flag is on"); + goto suspend_part; + } + } + + errorCode = process_recv_msg(recvMsg, recvMsg_size, only_from_client, (void **)&sync_return_obj, &isFinish); + if (errorCode != COMMON_OK) { + _DEBUG_ERROR("Failed in processRecv_Msg = %d", errorCode); + err = SE_INTERNAL_SA_ERROR; + goto fail_part; + } + + err = _execute_sync(account_id, client_sync_type, server_sync_type, &sync_obj, &sync_return_obj); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __execute_sync = %d", err); + goto fail_part; + } + + free_changed_datastores(sync_return_obj->changed_datastore); + sync_return_obj->changed_datastore = NULL; + + free_applied_statuses(sync_return_obj->status); + sync_return_obj->status = NULL; + + if (msg != NULL) { + free(msg); + msg = NULL; + } + + if (recvMsg != NULL) { + free(recvMsg); + recvMsg = NULL; + } + } + + err = _update_sync_result(account_id); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in __update_anchor = %d", err); + goto fail_part; + } + + _write_sync_data(account_id, client_sync_type, SYNC_SESSION_SUCCEEDED, session_time, only_from_client); + + goto return_part; + + suspend_part: + + errorCode = suspend_sync(TRANSPORT_TYPE, account_id, server_flag); + if (errorCode != COMMON_OK) { + _DEBUG_ERROR("Failed in suspend_sync = %d", errorCode); + err = SE_INTERNAL_SA_ERROR; + if (errorCode == COMMON_SUSPEND_FAIL) + _off_resume_flag(account_id); + + goto fail_part; + } + + cancel_part: + + /*clean up for SA unusual end sync process case */ + clean_up_sa(); + + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->client_sync_type) { + if (datastoreinfo_per_content_type[content_type]->client_sync_result != NULL) + datastoreinfo_per_content_type[content_type]->client_sync_result->session_result = SYNC_SESSION_STOPPED; + + if (datastoreinfo_per_content_type[content_type]->server_sync_result != NULL) + datastoreinfo_per_content_type[content_type]->server_sync_result->session_result = SYNC_SESSION_STOPPED; + + } + } + } + + _write_sync_data(account_id, client_sync_type, SYNC_SESSION_STOPPED, session_time, only_from_client); + + goto return_part; + + fail_part: + + /*clean up for SA unusual end sync process case */ + clean_up_sa(); + + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + if (datastoreinfo_per_content_type[content_type]->client_sync_type) { + if (datastoreinfo_per_content_type[content_type]->client_sync_result != NULL) + datastoreinfo_per_content_type[content_type]->client_sync_result->session_result = SYNC_SESSION_FAILED; + + if (datastoreinfo_per_content_type[content_type]->server_sync_result != NULL) + datastoreinfo_per_content_type[content_type]->server_sync_result->session_result = SYNC_SESSION_FAILED; + } + } + } + + _write_sync_data(account_id, client_sync_type, SYNC_SESSION_FAILED, session_time, only_from_client); + + return_part: + + if (err == SE_INTERNAL_SA_ERROR) + convert_common_errorcode(errorCode, &process, &error); + else + convert_engine_errorcode(err, &process, &error); + + /* off when session finish normal or cancel case(not suspend) */ + if (err != SE_INTERNAL_SUSPEND) + _off_resume_flag(account_id); + + _off_synchronising_account(account_id); + + _session_process(account_id, server_sync_type, process, error); + _DEBUG_INFO("server_sync_type = %d", server_sync_type); + _DEBUG_INFO("process = %d", process); + _DEBUG_INFO("error = %d", error); + + sync_agent_close_agent(); + _close_services(); + + dci_result = sync_agent_execute_dev_function(DEFINE_PLATFORM, "pm_unlock", 2, LCD_OFF, RESET_TIMER); + if (dci_result != SYNC_AGENT_DEV_RETURN_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_execute_dev_function unlock"); + } + + sync_agent_free_fw_account(fw_account); + + if (access_name != NULL) { + free(access_name); + access_name = NULL; + } + + if (msg != NULL) { + free(msg); + msg = NULL; + } + + if (recvMsg != NULL) { + free(recvMsg); + recvMsg = NULL; + } + + if (pre_sync_return_obj != NULL) { + free_pre_sync_return_obj(pre_sync_return_obj); + pre_sync_return_obj = NULL; + } + + if (sync_obj != NULL) { + free_sync_obj(sync_obj); + sync_obj = NULL; + } + + if (sync_return_obj != NULL) { + free_sync_return_obj(sync_return_obj); + sync_return_obj = NULL; + } + + for (content_type = 0; content_type < TYPE_SERVICE_COUNT; content_type++) { + if (datastoreinfo_per_content_type[content_type] != NULL) { + free_datastore(datastoreinfo_per_content_type[content_type]); + datastoreinfo_per_content_type[content_type] = NULL; + } + } + + /*FIXME*/ dt = myclock() - t; + _DEBUG_ERROR("\n=============TOTAL---- % d . % d sec\n", dt / 1000, dt % 1000); + + _EXTERN_FUNC_EXIT; + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +void convert_common_errorcode(common_error_type_e errorCode, sync_progress_e * process, sync_error_e * error) +{ + _EXTERN_FUNC_ENTER; + + switch (errorCode) { + case COMMON_CANCEL: + case COMMON_SUSPEND_FAIL: + 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; + } + + _EXTERN_FUNC_EXIT; +} + +void convert_engine_errorcode(se_error_type_e err, sync_progress_e * process, sync_error_e * error) +{ + _EXTERN_FUNC_ENTER; + + switch (err) { + case SE_INTERNAL_SUSPEND: + case SE_INTERNAL_CANCEL: + case SE_INTERNAL_OK: + *process = PROGRESS_DONE; + *error = ERROR_NONE; + break; + case ERROR_UNKNOWN: + case SE_INTERNAL_SA_ERROR: + case SE_INTERNAL_SCHEDULER_ERROR: + case SE_INTERNAL_ENGINE_CONTROLER_ERROR: + case SE_INTERNAL_EVENT_ERROR: + case SE_INTERNAL_NOT_DEFINED: + 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_DA_ERROR: + *process = PROGRESS_ERROR; + *error = ERROR_DB; + break; + case SE_INTERNAL_MISCONFIGURATION: + *process = PROGRESS_ERROR; + *error = ERROR_SYNCHDR; + break; + case SE_INTERNAL_LOW_BATTERY: + *process = PROGRESS_ERROR; + *error = ERROR_LOW_BATTERY; + break; + } + + _EXTERN_FUNC_EXIT; +} + +se_error_type_e session_process(char *profileDirName, alert_type_e server_sync_type, sync_progress_e process, sync_error_e error) +{ + _EXTERN_FUNC_ENTER; + + _DEBUG_INFO("profileDirName = %s", profileDirName); + _DEBUG_INFO("process = %d", process); + _DEBUG_INFO("error = %d", error); + + se_error_type_e err = SE_INTERNAL_OK; + + char *sync_type = NULL; + char *syncProcess = NULL; + char *syncError = NULL; + + sync_type = __convert_sync_type_str(server_sync_type); + + syncProcess = _convert_sync_progress_str(process); + + syncError = _convert_sync_error_str(error); + + if (sync_type == NULL || syncProcess == NULL || syncError == NULL) { + err = SE_INTERNAL_NOT_DEFINED; + goto error; + } + + err = send_noti_session_process(profileDirName, sync_type, syncProcess, syncError); + if (err != SE_INTERNAL_OK) { + _DEBUG_ERROR("failed in send_noti_session_process"); + goto error; + } + + _EXTERN_FUNC_EXIT; + + error: + + return err; +} + +se_error_type_e reset_synchronizing_profiles() +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + sync_agent_acc_error_e acc_err = SYNC_AGENT_ACC_SUCCESS; + sync_agent_fw_account_s *fw_account = NULL; + GList *account_info_list = NULL; + GList *iter = NULL; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("failed in sync_agent_open_agent"); + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + sync_agent_fw_account_query_s query; + query.query = ACCOUNT_QUERY_BY_NONE; + + acc_err = sync_agent_query_fw_account(&query, &account_info_list); + if (acc_err != SYNC_AGENT_ACC_SUCCESS) { + _DEBUG_ERROR("sync_agent_query_fw_account is failed"); + goto error; + } + + for (iter = account_info_list; iter != NULL; iter = g_list_next(iter)) { + fw_account = (sync_agent_fw_account_s *) iter->data; + + _DEBUG_INFO("account = %d", fw_account->account_id); + _off_synchronising_account(fw_account->account_id); + + _DEBUG_INFO("construct_itemTbl From service start"); + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT - 1; content_type++) { + + da_err = sync_agent_open_service(content_type); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_open_service(%d) is failed ", content_type); + continue; + } + + _DEBUG_INFO("sync_agent_construct_item_tbl_from_service(%d, %d);", fw_account->account_id, content_type); + sync_agent_construct_item_tbl_from_service(fw_account->account_id, content_type); + + da_err = sync_agent_close_service(content_type); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_close_service(%d) is failed ", content_type); + continue; + } + } + + _DEBUG_INFO("construct_itemTbl From service end"); + } + + error: + + sync_agent_close_agent(); + + sync_agent_free_fw_account_list(account_info_list); + + _EXTERN_FUNC_EXIT; + + return err; +} + +bool refresh_from_service_all(int account_id) +{ + _EXTERN_FUNC_ENTER; + + se_error_type_e err = SE_INTERNAL_OK; + + sync_agent_da_return_e da_err = sync_agent_open_agent(); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + err = SE_INTERNAL_DA_ERROR; + goto error; + } + + int content_type; + for (content_type = 0; content_type < TYPE_SERVICE_COUNT - 1; content_type++) { + + da_err = sync_agent_open_service(content_type); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_open_service(%d) is failed ", content_type); + continue; + } + + _DEBUG_INFO("sync_agent_refresh_item_tbl_from_service(%d, %d);", account_id, content_type); + sync_agent_refresh_item_tbl_from_service(account_id, content_type); + + da_err = sync_agent_close_service(content_type); + if (da_err != SYNC_AGENT_DA_SUCCESS) { + _DEBUG_ERROR("sync_agent_close_service(%d) is failed ", content_type); + continue; + } + } + + error: + + sync_agent_close_agent(); + + _EXTERN_FUNC_EXIT; + + if (err != SE_INTERNAL_OK) + return false; + else + return true; +} + +se_error_type_e cancel_sync_request() +{ + _EXTERN_FUNC_ENTER; + se_error_type_e err = SE_INTERNAL_OK; + + cancel_connection_sync_request(TRANSPORT_TYPE); + + _EXTERN_FUNC_EXIT; + + return err; +} diff --git a/src/plugins/CMakeLists.sub b/src/plugins/CMakeLists.sub new file mode 100644 index 0000000..8040b54 --- /dev/null +++ b/src/plugins/CMakeLists.sub @@ -0,0 +1,57 @@ + + +############################################# +# +# Step 1. Set Variable and Build Dependency +# + +# set lib name +SET(LIBNAME "lib${PROJECT_NAME}") +#SET(LIBDIR "${PREFIX}/lib") + +############################################# +# +# Step 2. Set Compile Environment +# + +# set extra cflags from build dependency +STRING(REPLACE ";" " " EXTRA_CFLAGS "${PLUGIN_CFLAGS}") + +# add include directories to the build. +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../../../include) + +# find all source files in a directory. +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS) + +############################################# +# +# Step 3. Set Link Environment +# + +# add a library to the project using the specified source files. +ADD_LIBRARY(${LIBNAME} SHARED ${SRCS}) + +# link a target to given libraries from pkg-config. +TARGET_LINK_LIBRARIES(${LIBNAME} ${PLUGIN_LDFLAGS}) + +# sets additional compiler flags used to build sources within the target. +SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}") + +# override the default target name prefix (such as "lib") +SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "") + +# specify the build version +SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${VERSION}) + +# specify the api version +SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) + +############################################# +# +# Step 4. Install packages +# + +# install library files +INSTALL(TARGETS ${LIBNAME} DESTINATION ${LIBDIR}) + diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt new file mode 100644 index 0000000..b75a100 --- /dev/null +++ b/src/plugins/CMakeLists.txt @@ -0,0 +1,3 @@ +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") + +ADD_SUBDIRECTORY(ds-public) diff --git a/src/plugins/ds-public/CMakeLists.txt b/src/plugins/ds-public/CMakeLists.txt new file mode 100755 index 0000000..63e1c2d --- /dev/null +++ b/src/plugins/ds-public/CMakeLists.txt @@ -0,0 +1,11 @@ + +# set plguin name +SET(PLUGIN_CATEGORY_NAME "ds-public") + +# set plugin install path +SET(LIBDIR "${PREFIX}/lib/sync-agent/${PLUGIN_CATEGORY_NAME}") + +ADD_SUBDIRECTORY(plain-text) +ADD_SUBDIRECTORY(vcard) +ADD_SUBDIRECTORY(xcalllog) + diff --git a/src/plugins/ds-public/plain-text/CMakeLists.txt b/src/plugins/ds-public/plain-text/CMakeLists.txt new file mode 100755 index 0000000..e940e6b --- /dev/null +++ b/src/plugins/ds-public/plain-text/CMakeLists.txt @@ -0,0 +1,43 @@ + +############################################# +# +# Step 1. Set Variable and Build Dependency +# + +# set plguin name +SET(PLUGIN_NAME "dc-plain-text") + +# set a name for the entire project +PROJECT(plugin-${PLUGIN_NAME}) + +# checks for build dependency modules : a pkg-config module for CMake +INCLUDE(FindPkgConfig) +pkg_check_modules(${PLUGIN_NAME} REQUIRED + memo + glib-2.0 + sync-agent + dlog + libwbxml2) + +############################################# +# +# Step 2. Set Compile Environment +# + +# set extra cflags from build dependency +SET(PLUGIN_CFLAGS "${dc-plain-text_CFLAGS}") + +############################################# +# +# Step 3. Set Link Environment +# + +# link a target to given libraries from pkg-config. +SET(PLUGIN_LDFLAGS "${dc-plain-text_LDFLAGS}") + +############################################# +# +# Step 4. Install packages +# + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../CMakeLists.sub) \ No newline at end of file diff --git a/src/plugins/ds-public/plain-text/include/in_datastore_info_plain_text.h b/src/plugins/ds-public/plain-text/include/in_datastore_info_plain_text.h new file mode 100755 index 0000000..7296840 --- /dev/null +++ b/src/plugins/ds-public/plain-text/include/in_datastore_info_plain_text.h @@ -0,0 +1,32 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef IN_DATASTORE_INFO_PLAIN_TEXT_H_ +#define IN_DATASTORE_INFO_PLAIN_TEXT_H_ + +#define PLAIN_TEXT_TYPE "text/plain" +#define PLAIN_TEXT_VERSION "1.0" + +typedef struct plain_text_field_list plain_text_field_list_s; +struct plain_text_field_list { + int field_enum; + char *field_name; +}; + +static plain_text_field_list_s plain_text_field_list[] = { }; + +#endif /* IN_DATASTORE_INFO_PLAIN_TEXT_H_ */ diff --git a/src/plugins/ds-public/plain-text/src/plugin_interface.c b/src/plugins/ds-public/plain-text/src/plugin_interface.c new file mode 100755 index 0000000..2cc32d1 --- /dev/null +++ b/src/plugins/ds-public/plain-text/src/plugin_interface.c @@ -0,0 +1,245 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include +#include +#include + +#include + +#include "in_datastore_info_plain_text.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__ ((visibility("default"))) +#endif + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "PLUGIN_PLAIN_TEXT" +#endif + +static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count); +static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, plain_text_field_list_s * input_list); +/* +static sync_agent_da_return_e __convert_service_error_to_common_error(int err); +*/ + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_data, void **service_data) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "agent_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + struct memo_data *temp_service_data = 0; + char *temp_agent_data = (char *)agent_data; + + /* create item */ + temp_service_data = memo_create_data(); + if (temp_service_data == NULL) { + _DEBUG_INFO("[dc_plain_text_plugIn] memo_create_data() Fail!\n"); + ret = SYNC_AGENT_DA_ERRORS; + *service_data = 0; + } else { + _DEBUG_INFO("[dc_plain_text_plugIn] memo_create_data() Success!\n"); + temp_service_data->content = strdup(temp_agent_data); /* configuration item */ + *service_data = (void *)temp_service_data; + } + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_replace_converter(void *old_service_data, const void *agent_data, void **new_service_data) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(old_service_data == NULL, SYNC_AGENT_DA_ERRORS, "old_service_data is NULL"); + retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "agent_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + struct memo_data *temp_service_data = (struct memo_data *)old_service_data; + char *temp_agent_data = (char *)agent_data; + + /* set item */ + if (temp_service_data->has_doodle == 0) { + free(temp_service_data->content); + temp_service_data->content = strdup(temp_agent_data); + } else if (temp_service_data->comment != NULL) { + free(temp_service_data->comment); + temp_service_data->comment = strdup(temp_agent_data); + } + *new_service_data = (void *)temp_service_data; + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_reverse_converter(void *service_data, void **agent_data) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(service_data == NULL, SYNC_AGENT_DA_ERRORS, "service_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + char *temp_agent_data = 0; + struct memo_data *temp_service_data = (struct memo_data *)service_data; + + /* deep copy */ + if (temp_service_data == NULL) { + _DEBUG_INFO("[dc_plain_text_plugIn] Fail : no data !\n"); + ret = SYNC_AGENT_DA_ERRORS; + *agent_data = 0; + } else if (temp_service_data->has_doodle == 0) { + _DEBUG_INFO("[dc_plain_text_plugIn] Success!\n"); + temp_agent_data = strdup(temp_service_data->content); + *agent_data = (void *)temp_agent_data; + } else if (temp_service_data->comment != NULL) { + _DEBUG_INFO("[dc_plain_text_plugIn] Success!\n"); + temp_agent_data = strdup(temp_service_data->comment); + *agent_data = (void *)temp_agent_data; + } + + /* memory free */ + if (temp_service_data != NULL) + memo_free_data(temp_service_data); + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API void *sync_agent_plugin_alloc_object() +{ + _DEBUG_INFO("[da_memo_plugIn] not implement !!"); + return 0; +} + +EXPORT_API int sync_agent_plugin_free_object(void *in_object) +{ + _DEBUG_INFO("[da_memo_plugIn] not implement !!"); + return 0; +} + +EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *extension_key, void *value) +{ + _DEBUG_INFO("[da_memo_plugIn] not implement !!"); + return 0; +} + +EXPORT_API void *sync_agent_plugin_get_value(void *in_object, int key, char *extension_key) +{ + _DEBUG_INFO("[da_memo_plugIn] not implement !!"); + return 0; +} + +EXPORT_API sync_agent_plugin_object_info_s *sync_agent_plugin_get_obj_info() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_plugin_object_info_s *obj_info = (sync_agent_plugin_object_info_s *) calloc(1, sizeof(sync_agent_plugin_object_info_s)); + if (obj_info == NULL) { + _DEBUG_INFO("CALLOC failed !!!"); + return NULL; + } + + obj_info->type = PLAIN_TEXT_TYPE; + obj_info->version = PLAIN_TEXT_VERSION; + obj_info->field_cnt = sizeof(plain_text_field_list) / sizeof(plain_text_field_list_s); + + if (obj_info->field_cnt > 0) + if (_set_obj_field_info(&(obj_info->field_list), obj_info->field_cnt, plain_text_field_list) == 0) + return NULL; + + _EXTERN_FUNC_EXIT; + return obj_info; +} + +EXPORT_API int sync_agent_plugin_free_obj_info(sync_agent_plugin_object_info_s * obj_info) +{ + _EXTERN_FUNC_ENTER; + + if (obj_info) { + if (obj_info->field_cnt > 0) + if (_free_obj_field_info(obj_info->field_list, obj_info->field_cnt) == 0) + return 0; + + free(obj_info); + } + + _EXTERN_FUNC_EXIT; + return 1; +} + +static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count) +{ + _INNER_FUNC_ENTER; + + int field_count = 0; + sync_agent_plugin_field_info_s *child = NULL; + + if (field_list != NULL) { + for (field_count = 0; field_count < count; field_count++) { + child = field_list + field_count; + if (child->field_child_cnt > 0) + if (_free_obj_field_info(child->field_child_list, child->field_child_cnt) == 0) + return 0; + } + free(field_list); + } + + _INNER_FUNC_EXIT; + return 1; +} + +static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, plain_text_field_list_s * input_list) +{ + _INNER_FUNC_ENTER; + + int field_count = 0; + sync_agent_plugin_field_info_s *child = NULL; + + *field_list = (sync_agent_plugin_field_info_s *) calloc(count, sizeof(sync_agent_plugin_field_info_s)); + if (*field_list == NULL) { + _DEBUG_ERROR("CALLOC failed !!!"); + return 0; + } + + for (field_count = 0; field_count < count; field_count++) { + child = (*field_list) + field_count; + child->field_name = input_list[field_count].field_name; + _DEBUG_TRACE("[%s]", child->field_name); + } + + _INNER_FUNC_EXIT; + return 1; +} + +/* +static sync_agent_da_return_e __convert_service_error_to_common_error(int err) +{ + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + _DEBUG_INFO("[da_memo_plugIn] Error Code : %d\n", err); + + switch (err) { + default: + ret = SYNC_AGENT_DA_ERRORS; + break; + } + + return ret; +} +*/ diff --git a/src/plugins/ds-public/vcard/CMakeLists.txt b/src/plugins/ds-public/vcard/CMakeLists.txt new file mode 100755 index 0000000..bdd1871 --- /dev/null +++ b/src/plugins/ds-public/vcard/CMakeLists.txt @@ -0,0 +1,42 @@ + +############################################# +# +# Step 1. Set Variable and Build Dependency +# + +# set plguin name +SET(PLUGIN_NAME "dc-vcard") + +# set a name for the entire project +PROJECT(plugin-${PLUGIN_NAME}) + +# checks for build dependency modules : a pkg-config module for CMake +INCLUDE(FindPkgConfig) +pkg_check_modules(${PLUGIN_NAME} REQUIRED + contacts-service2 + sync-agent + dlog + libwbxml2) + +############################################# +# +# Step 2. Set Compile Environment +# + +# set extra cflags from build dependency +SET(PLUGIN_CFLAGS "${dc-vcard_CFLAGS}") + +############################################# +# +# Step 3. Set Link Environment +# + +# link a target to given libraries from pkg-config. +SET(PLUGIN_LDFLAGS "${dc-vcard_LDFLAGS}") + +############################################# +# +# Step 4. Install packages +# + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../CMakeLists.sub) \ No newline at end of file diff --git a/src/plugins/ds-public/vcard/include/encoding_util.h b/src/plugins/ds-public/vcard/include/encoding_util.h new file mode 100755 index 0000000..19cdfad --- /dev/null +++ b/src/plugins/ds-public/vcard/include/encoding_util.h @@ -0,0 +1,237 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef ENCODING_UTIL_H_ +#define ENCODING_UTIL_H_ + +#include +#include +#include + +#define QP_SIZE 76 +#define BASE64_SIZE 76 + +typedef enum { + EN_TYPE_NONE = 0, + EN_TYPE_QUOTED_PRINTABLE, + EN_TYPE_BASE64 +} encoding_type_e; + +/* Quoted-Printable +* +* @example code +int main() +{ +char *src = "hello"; +char *encode_src; +int encode_src_len = 0; +char *decode_src; +int decode_src_len = 0; + +int res = encode_qp(src, strlen(src), &encode_src, &encode_src_len); +if (res != 0) +fprintf(stdout, "encode src : %s ( %d ) \n", encode_src, encode_src_len); +else +fprintf(stdout, "%s\n", "encode error !!"); + +res = decode_qp(encode_src, encode_src_len, &decode_src, &decode_src_len); +if (res != 0) +fprintf(stdout, "decode src : %s ( %d ) \n", decode_src, decode_src_len); +else +fprintf(stdout, "%s\n", "decode error !!"); + +return 0; +} + +*/ + +/* +* @brief encode original source ( encoding type : quoted-printable ) +* @param[in] src original source +* @param[in] src_len length of original source +* @param[out] en_src encoded source +* @param[out] en_src_len length of encoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +*/ +int encode_qp(char *src, int src_len, char **en_src, int *en_src_len); + +/* +* @brief decode encoded source ( decoding type : quoted-printable ) +* @param[in] src encoded source +* @param[in] src_len length of encoded source +* @param[out] de_src decoded source ( original source ) +* @param[out] de_src_len length of decoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +*/ +int decode_qp(char *src, int src_len, char **de_src, int *de_src_len); + +/* Base64 +* +* @example code + +int main() +{ +char *src = "hello"; +char *encode_src; +int encode_src_len = 0; +char *decode_src; +int decode_src_len = 0; + +int res = encode_base64(src, strlen(src), &encode_src, &encode_src_len); +if (res != 0) +fprintf(stdout, "encode src : %s ( %d ) \n", encode_src, encode_src_len); +else +fprintf(stdout, "%s\n", "encode error !!"); + +res = decode_base64(encode_src, encode_src_len, &decode_src, &decode_src_len); +if (res != 0) +fprintf(stdout, "decode src : %s ( %d ) \n", decode_src, decode_src_len); +else +fprintf(stdout, "%s\n", "decode error !!"); + +return 0; +} + +*/ + +/* +* @brief encode original source ( encoding type : base64 ) +* @param[in] src original source +* @param[in] src_len length of original source +* @param[out] en_src encoded source +* @param[out] en_src_len length of encoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +*/ +int encode_base64(char *src, int src_len, char **en_src, int *en_src_len); + +/* +* @brief decode encoded source ( decoding type : base64 ) +* @param[in] src encoded source +* @param[in] src_len length of encoded source +* @param[out] de_src decoded source ( original source ) +* @param[out] de_src_len length of decoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +*/ +int decode_base64(char *src, int src_len, char **de_src, int *de_src_len); + +/* +* @brief make the decoding process +* @param[in] src encoded source +* @param[in] src_len length of encoded source +* @param[out] de_src decoded source ( original source ) +* @param[out] de_src_len length of decoded source +* @return operation result +* @retval 1 success +* @retval 0 fail +* +* @example code + +int main() +{ +char *src = "..."; // decoded data +int src_len = strlen(src); +char *decode_src; +int decode_src_len = 0; + +int res = proc_decoding(src, src_len, &decode_src, &decode_src_len); + +if (res != 0) +fprintf(stdout, "decode src : \n%s\n", decode_src); +else +fprintf(stdout, "%s\n", "decode error !!"); + +if (decode_src != NULL) +free(decode_src); + +return 0; +} +*/ +int proc_decoding(const char *src, int src_len, char **de_src, int *de_src_len); + +/* +* @brief encoded value is changed to the decoded value +* @param[in] type encoding type +* @param[in] value encoded value (end of string must be '\0' !!) +* ex) =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 +* @param[in] value_size length of encoded value +* @param[out] decode_str decoded string +* @param[out] decode_str_len length of decoded string +* @return operation result +* @ratval 1 success +* @retval 0 fail +* +* @example code + +int main() +{ +char *data = "..."; // ex) ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8 +encoding_type_e type = find_encoding_type((const char *)data); + +char *value = "..."; // ex) =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 +int value_size = strlen(value); + +int decode_str_len = 0; +char *decode_str = (char*)malloc(sizeof(char)*BUF_SIZE); // BUF_SIZE : user define +if (decode_str == NULL) { +// error process +} +memset(decode_str, 0x00, sizeof(char)*BUF_SIZE); + +int res = decode_value(type, value, data_size, &decode_str, &decode_str_len); + +if (res == 1) { +// success process +if (decode_str != NULL) +free(decode_str); +} else { +// error process +if (decode_str != NULL) +free(decode_str); +} + +return 0; +} +*/ +int decode_value(encoding_type_e type, const char *value, int value_size, char **decode_str, int *decode_str_len); + +/* +* @brief get encoding type for data +* @param[in] data vobject data +* @return encoding type +* @ratval >= 1 success +* @retval 0 fail +*/ +encoding_type_e find_encoding_type(const char *data); + +/* +* @brief check whether to exist this string, "ENCODING=" in the data +* @param[in] data vobject data +* @return operation result +* @retval 1 exist +* @retval 0 not exist +*/ +int check_encoding_data(const char *data); + +#endif /* ENCODING_UTIL_H_ */ diff --git a/src/plugins/ds-public/vcard/include/in_datastore_info_vcard.h b/src/plugins/ds-public/vcard/include/in_datastore_info_vcard.h new file mode 100755 index 0000000..54d1929 --- /dev/null +++ b/src/plugins/ds-public/vcard/include/in_datastore_info_vcard.h @@ -0,0 +1,156 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef IN_DATASTORE_INFO_VCARD_H_ +#define IN_DATASTORE_INFO_VCARD_H_ + +#define VCARD_TYPE "text/x-vcard" +#define VCARD_VERSION "2.1" + +typedef enum { + VCARD_FIELD_BEGIN = 10, + VCARD_FIELD_END, + VCARD_FIELD_VERSION, + VCARD_FIELD_FN, + VCARD_FIELD_N, + VCARD_FIELD_NICKNAME, + VCARD_FIELD_PHOTO, + VCARD_FIELD_BDAY, + VCARD_FIELD_ADR, + VCARD_FIELD_LABEL, + VCARD_FIELD_TEL, + VCARD_FIELD_EMAIL, + VCARD_FIELD_TITLE, + VCARD_FIELD_ROLE, + VCARD_FIELD_ORG, + VCARD_FIELD_NOTE, + VCARD_FIELD_REV, + VCARD_FIELD_UID, + VCARD_FIELD_URL, + VCARD_FIELD_X_ANNIVERSARY, + VCARD_FIELD_X_IRMC_LUID, + +} vcard_field_e; + +typedef enum { + VCARD_FIELD_ADR_DOM = 100, + VCARD_FIELD_ADR_INTL, + VCARD_FIELD_ADR_HOME, + VCARD_FIELD_ADR_WORK, + VCARD_FIELD_ADR_POSTAL, + VCARD_FIELD_ADR_PARCEL, + VCARD_FIELD_ADR_PREF, + +} vcard_field_adr_sub_e; + +typedef enum { + VCARD_FIELD_TEL_HOME = 200, + VCARD_FIELD_TEL_MSG, + VCARD_FIELD_TEL_WORK, + VCARD_FIELD_TEL_VOICE, + VCARD_FIELD_TEL_FAX, + VCARD_FIELD_TEL_CELL, + VCARD_FIELD_TEL_VIDEO, + VCARD_FIELD_TEL_PAGER, + VCARD_FIELD_TEL_BBS, + VCARD_FIELD_TEL_MODEM, + VCARD_FIELD_TEL_CAR, + VCARD_FIELD_TEL_ISDN, + VCARD_FIELD_TEL_PCS, + VCARD_FIELD_TEL_PREF, + +} vcard_field_tel_sub_e; + +typedef enum { + VCARD_FIELD_EMAIL_HOME = 300, + VCARD_FIELD_EMAIL_WORK, + VCARD_FIELD_EMAIL_PREF, + +} vcard_field_email_sub_e; + +typedef struct vcard_field_list vcard_field_list_s; +struct vcard_field_list { + int field_enum; + char *field_name; +}; + +static vcard_field_list_s vcard_field_list[] = { + {VCARD_FIELD_BEGIN, "BEGIN"}, + {VCARD_FIELD_END, "END"}, + {VCARD_FIELD_VERSION, "VERSION"}, + {VCARD_FIELD_FN, "FN"}, + {VCARD_FIELD_N, "N"}, + {VCARD_FIELD_NICKNAME, "NICKNAME"}, + {VCARD_FIELD_PHOTO, "PHOTO"}, + {VCARD_FIELD_BDAY, "BDAY"}, + {VCARD_FIELD_ADR, "ADR"}, + {VCARD_FIELD_LABEL, "LABEL"}, + {VCARD_FIELD_TEL, "TEL"}, + {VCARD_FIELD_EMAIL, "EMAIL"}, + {VCARD_FIELD_TITLE, "TITLE"}, + {VCARD_FIELD_ROLE, "ROLE"}, + {VCARD_FIELD_ORG, "ORG"}, + {VCARD_FIELD_NOTE, "NOTE"}, + {VCARD_FIELD_REV, "REV"}, + {VCARD_FIELD_UID, "UID"}, + {VCARD_FIELD_URL, "URL"}, + {VCARD_FIELD_X_ANNIVERSARY, "X-ANNIVERSARY"}, + {VCARD_FIELD_X_IRMC_LUID, "X-IRMC-LUID"} +}; + +static vcard_field_list_s vcard_field_list_adr[] = { + {VCARD_FIELD_ADR_DOM, "DOM"}, + {VCARD_FIELD_ADR_INTL, "INTL"}, + {VCARD_FIELD_ADR_HOME, "HOME"}, + {VCARD_FIELD_ADR_WORK, "WORK"}, + {VCARD_FIELD_ADR_POSTAL, "POSTAL"}, + {VCARD_FIELD_ADR_PARCEL, "PARCEL"}, + {VCARD_FIELD_ADR_PREF, "PREF"} +}; + +static vcard_field_list_s vcard_field_list_tel[] = { + {VCARD_FIELD_TEL_HOME, "HOME"}, + {VCARD_FIELD_TEL_MSG, "MSG"}, + {VCARD_FIELD_TEL_WORK, "WORK"}, + {VCARD_FIELD_TEL_VOICE, "VOICE"}, + {VCARD_FIELD_TEL_FAX, "FAX"}, + {VCARD_FIELD_TEL_CELL, "CELL"}, + {VCARD_FIELD_TEL_VIDEO, "VIDEO"}, + {VCARD_FIELD_TEL_PAGER, "PAGER"}, + {VCARD_FIELD_TEL_BBS, "BBS"}, + {VCARD_FIELD_TEL_MODEM, "MODEM"}, + {VCARD_FIELD_TEL_CAR, "CAR"}, + {VCARD_FIELD_TEL_ISDN, "ISDN"}, + {VCARD_FIELD_TEL_PCS, "PCS"}, + {VCARD_FIELD_TEL_PREF, "PREF"} +}; + +static vcard_field_list_s vcard_field_list_email[] = { + {VCARD_FIELD_EMAIL_HOME, "HOME"}, + {VCARD_FIELD_EMAIL_WORK, "WORK"}, + {VCARD_FIELD_EMAIL_PREF, "PREF"} +}; + +static vcard_field_list_s vcard_field_list_begin_end[] = { + {-1, "VCARD"} +}; + +static vcard_field_list_s vcard_field_list_version[] = { + {-1, VCARD_VERSION} +}; + +#endif /* IN_DATASTORE_INFO_VCARD_H_ */ diff --git a/src/plugins/ds-public/vcard/include/plugin_spec.h b/src/plugins/ds-public/vcard/include/plugin_spec.h new file mode 100755 index 0000000..e6b1202 --- /dev/null +++ b/src/plugins/ds-public/vcard/include/plugin_spec.h @@ -0,0 +1,65 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef PLUGIN_SPEC_H_ +#define PLUGIN_SPEC_H_ + +typedef enum { + + VCARD_CONTENT_NO_TYPE = 0, + VCARD_CONTENT_EXTENSION = 1, + VCARD_CONTENT_FN = 2, + VCARD_CONTENT_N = 3, + VCARD_CONTENT_NICKNAME = 4, + VCARD_CONTENT_PHOTO = 5, + VCARD_CONTENT_BDAY = 6, + VCARD_CONTENT_ADR = 7, + VCARD_CONTENT_LABEL = 8, + VCARD_CONTENT_TEL = 9, + VCARD_CONTENT_EMAIL = 10, + VCARD_CONTENT_TITLE = 11, + VCARD_CONTENT_ROLE = 12, + VCARD_CONTENT_ORG = 13, + VCARD_CONTENT_NOTE = 14, + VCARD_CONTENT_REV = 15, + VCARD_CONTENT_UID = 16, + VCARD_CONTENT_URL = 17, + VCARD_CONTENT_X_ANNIVERSARY = 18, + VCARD_CONTENT_X_IRMC_LUID = 19, + +/* + VCARD_CONTENT_NAME, + VCARD_CONTENT_PROFILE, + VCARD_CONTENT_SOURCE, + VCARD_CONTENT_MAILER, + VCARD_CONTENT_TZ, + VCARD_CONTENT_GEO, + VCARD_CONTENT_LOGO, + VCARD_CONTENT_AGENT, + VCARD_CONTENT_CATEGORIES, + VCARD_CONTENT_PRODID, + VCARD_CONTENT_SORT-STRING, + VCARD_CONTENT_SOUND, + VCARD_CONTENT_VERSION, + VCARD_CONTENT_CLASS, + VCARD_CONTENT_KEY, + VCARD_CONTENT_X_CHILDREN, +*/ + +} vcard_value_type_e; + +#endif /* PLUGIN_SPEC_H_ */ diff --git a/src/plugins/ds-public/vcard/src/encoding_util.c b/src/plugins/ds-public/vcard/src/encoding_util.c new file mode 100755 index 0000000..bf1d025 --- /dev/null +++ b/src/plugins/ds-public/vcard/src/encoding_util.c @@ -0,0 +1,814 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include +#include + +#include + +#include "encoding_util.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "ENCODING_UTIL" +#endif + +#define TYPE_CHECK_BUF_SIZE 100 /* temporary definition */ +#define TEMP_BUFFER_SIZE 1024 /* temporary definition */ + +/* BASE64 TABLE */ +static char base64_table[65] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', + 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', + 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', + '2', '3', '4', '5', '6', '7', '8', '9', '+', + '/', '=' +}; + +/* Quoted-Printable */ +static char *_dec_to_hex(int dec); +static int _hex_to_dec(char *hex); + +/* Base64 */ +static int _find_base(char ch); + +/* + * Quoted-Printable + */ +int encode_qp(char *src, int src_len, char **en_src, int *en_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + char *en_hex; + int i = 0; + int j = 0; + int size_cnt = 0; + + /*encoded string length is three times longer than existing maximum string length */ + int full_lenth = src_len * 3 + 1 + (int)(src_len * 3 / 76) * 3; + *en_src = (char *)malloc(sizeof(char) * full_lenth); + if (*en_src == NULL) { + _DEBUG_ERROR("[encoding_util] malloc fail !!\n"); + return 0; + } + memset(*en_src, 0x00, src_len * 3 + 1); + + _DEBUG_INFO("[encoding_util] src_len : %d\n", src_len); + for (i = 0; i < src_len; i++) { + /* _DEBUG_INFO("[encoding_util] i : %d\n", i); */ + if (size_cnt >= QP_SIZE - 3) { + size_cnt = 0; + (*en_src)[j++] = 0x0A; + } + + if ((src[i] >= 33 && src[i] <= 126) || (src[i] == 0x0A)) { + if (src[i] == 61) { + en_hex = _dec_to_hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + size_cnt += 3; + } else { + size_cnt++; + (*en_src)[j++] = src[i]; + } + } else if (src[i] == 9 || src[i] == 32) { + if (src[i + 1] == 0x0A || src[i + 1] == '\0') { /* TAB or WhiteSpace */ + en_hex = _dec_to_hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + size_cnt += 3; + } else { + size_cnt++; + (*en_src)[j++] = src[i]; + } + } else { + en_hex = _dec_to_hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + _DEBUG_INFO("[encoding_util] en_src : %s\n", *en_src); + size_cnt += 3; + } + } + + (*en_src)[j] = 0x00; + *en_src_len = size_cnt; + + _EXTERN_FUNC_EXIT; + return 1; +} + +int decode_qp(char *src, int src_len, char **de_src, int *de_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + char hex[3]; + char ch; + int dec = 0; + int is_space = 0; + int i = 0; + int j = 0; + + *de_src = (char *)malloc(sizeof(char) * (src_len + 1)); + if (*de_src == NULL) { + _DEBUG_ERROR("[encoding_util] malloc is fail !!\n"); + return 0; + } + memset(*de_src, 0x00, sizeof(char) * (src_len + 1)); + + while (src[i] != '\0') { + if (src[i] == 0x3D) { /* '=' */ + /* check whiteSpace */ + ch = src[++i]; + + /* '=' skip if next character is a TAB or WhiteSpace */ + while (ch == 0x09 || ch == 0x20) { + is_space = 1; + ch = src[++i]; + + if (is_space == 1) { + is_space = 0; + continue; + } + } + + /* '=' skip if next character is 3D which means '=' (encoding error case ??) */ + while (ch == '3') { + ch = src[++i]; + + if (ch == 'D') { + ch = src[++i]; + continue; + } + } + + /* if next character is LF after '=' do doft line break + * encoded QP string on one line 76 character is allowed + */ + if (ch == 0x0A) { /* LF */ + i++; + continue; + } + + hex[0] = src[i++]; + hex[1] = src[i++]; + hex[2] = '\0'; + + dec = _hex_to_dec(hex); + + /* decoding error */ + if (dec < 0) { + /* when error occur, restore the previous encoding message */ + (*de_src)[j++] = 0x3D; /* '=' */ + (*de_src)[j++] = hex[0]; + (*de_src)[j++] = hex[1]; + } else { + (*de_src)[j++] = dec; + } + } else if (src[i] > 0x7E) { /* encoding error */ + i++; /* ignore that character */ + } else { + (*de_src)[j++] = src[i++]; + } + } + + (*de_src)[j] = '\0'; + *de_src_len = j; + + _EXTERN_FUNC_EXIT; + return 1; +} + +static char *_dec_to_hex(int dec) +{ + _INNER_FUNC_ENTER; + + static char hex[3]; + int i; + int ch; + + for (i = 0; i < 2; i++) { + if (i == 0) { + ch = (dec & 0xF0) >> 4; + } else if (i == 1) { + ch = (dec & 0x0F); + } + + if (ch >= 10) { + hex[i] = 'A' + ch - 10; + } else { + hex[i] = '0' + ch; + } + } + + hex[i] = 0x00; + + _DEBUG_TRACE("[encoding_util] hex : %s\n", hex); + + _INNER_FUNC_EXIT; + return &hex[0]; +} + +static int _hex_to_dec(char *hex) +{ + _INNER_FUNC_ENTER; + + int dec = 0; + int byte; + int i = 0; + + for (i = 0; i < 2; i++) { + if (hex[i] >= '0' && hex[i] <= '9') { + byte = hex[i] - '0'; + } else if (hex[i] >= 'A' && hex[i] <= 'F') { + byte = hex[i] - 'A' + 10; + } else if (hex[i] >= 'a' && hex[i] <= 'f') { + byte = hex[i] - 'a' + 10; + } else { + byte = -1; + } + + if (byte < 0) + return -1; + + dec += (i == 0) ? byte << 4 : byte; + } + + _INNER_FUNC_EXIT; + return dec; +} + +/* + * Base64 + */ +int encode_base64(char *src, int src_len, char **en_src, int *en_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + int i = 0; + int j = 0; + int cnt = 0; + int ch = 0; + int size_cnt = 0; + + *en_src = (char *)malloc(sizeof(char) * (src_len * 2)); + + if (*en_src == NULL) { + _DEBUG_ERROR("[encoding_util] malloc fail !!\n"); + return 0; + } + memset(*en_src, 0x00, src_len * 2); + + while (1) { + switch (cnt++) { + case 0: + { + if (i < src_len) { + ch = (src[i] & 0xFC) >> 2; + } else { + ch = -1; + } + } + break; + + case 1: + { + if (i < src_len) { + if (i + 1 < src_len) { + ch = ((src[i] & 0x03) << 4) | ((src[i + 1] & 0xF0) >> 4); + } else { + ch = ((src[i] & 0x03) << 4); + } + } else { + ch = -1; + } + i++; + break; + } + + case 2: + { + if (i < src_len) { + if (i + 1 < src_len) { + ch = ((src[i] & 0x0F) << 2) | ((src[i] & 0xC0) >> 6); + } else { + ch = ((src[i] & 0x0F) << 2); + } + } else { + ch = -1; + } + i++; + } + break; + + case 3: + { + if (i < src_len) { + ch = (src[i] & 0x3F); + } else { + ch = -1; + } + i++; + cnt = 0; + } + break; + } + + /* + if (ch >= 0 && ch <= 25) { // Upper Case Alphabet + (*en_src)[j++] = 'A' + ch; + } else if (ch >= 26 && ch <= 51) { // Lower Case Alphabet + (*en_src)[j++] = 'a' + ch - 26; + } else if (ch >= 52 && ch <= 61) { // Digit + (*en_src)[j++] = '0' + ch - 52; + } else if (ch == 62) { + (*en_src)[j++] = '+'; + } else if (ch == 63) { + (*en_src)[j++] = '/'; + } else if (ch == -1) { + (*en_src)[j++] = '='; // padding + } + */ + + if ((ch != -1) && (ch >= 0 && ch <= 64)) { + (*en_src)[j++] = base64_table[ch]; + } else { + (*en_src)[j++] = base64_table[64]; /* padding */ + } + + size_cnt++; + + if (j % 4 == 0) { + if (size_cnt == BASE64_SIZE) { + size_cnt = 0; + (*en_src)[j++] = 0x0A; /* soft line break */ + } + + if (i >= src_len) + break; + } + } + + (*en_src)[j] = 0x00; + *en_src_len = j; + + _EXTERN_FUNC_EXIT; + return 1; +} + +int decode_base64(char *src, int src_len, char **de_src, int *de_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + long tmp = 0; /* 4byte (using decoding) */ + int i = 0; + int j = 0; + int cnt = 0; + int pad_cnt = 0; + + /* de_src is enough for the src_len 3/4 size */ + *de_src = (char *)malloc(sizeof(char) * (src_len)); + + if (*de_src == NULL) { + _DEBUG_ERROR("[encoding_util] malloc is fail !!\n"); + return 0; + } + memset(*de_src, 0x00, src_len); + + while (src[i] != '\0') { + /* + if (isupper(src[i])) { + tmp = (tmp << 6) | (src[i] - 'A'); // Upper case : 0 ~ 25 + } else if (islower(src[i])) { + tmp = (tmp << 6) | (src[i] - 'a' + 0x1A); // Lower case : 26(0x1A) ~ 51 + } else if (isdigit(src[i])) { + tmp = (tmp << 6) | (src[i] - '0' + 0x34); // Number : 52(0x34) ~ 61 + } else if (src[i] == '+') { + tmp = (tmp << 6) | 0x3E; // '+' : 62(0x3E) + } else if (src[i] == '/') { + tmp = (tmp << 6) | 0x3F; // '/' : 63(0x3F) + } else if (src[i] == '=') { + pad_cnt++; + tmp = (tmp << 6); // '=' : padding + } else { + tmp = (tmp << 6); // encoding error + f_DEBUG_INFO(stdout, "encoding error !! \n"); + } + */ + + tmp = (tmp << 6) | (_find_base(src[i])); + if (tmp == 64) { + pad_cnt++; + } else if (tmp == -1) { + _DEBUG_ERROR("[encoding_util] encoding error \n"); + } + + if (++cnt >= 4) { + (*de_src)[j++] = (char)((tmp & 0x00FF0000) >> 16); + (*de_src)[j++] = (char)((tmp & 0x0000FF00) >> 8); + (*de_src)[j++] = (char)(tmp & 0x000000FF); + + cnt = 0; + tmp = 0; + + if (src[i + 1] == 0x0A) { /* soft line break */ + i++; + } + } + + i++; + } + + (*de_src)[j - pad_cnt] = '\0'; + *de_src_len = j - pad_cnt; + + _EXTERN_FUNC_EXIT; + return 1; +} + +int proc_decoding(const char *src, int src_len, char **de_src, int *de_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + const char *reg_src = NULL; + reg_src = src; + + _DEBUG_INFO("[encoding_util] << src >> \n%s\n", src); + + *de_src = (char *)malloc(sizeof(char) * (src_len + 1)); + if (*de_src == NULL) { + _DEBUG_INFO("[encoding_util] malloc error !! \n"); + + return 0; + } + memset(*de_src, 0x00, sizeof(char) * (src_len + 1)); + + char colon[] = ":"; + char line_breaker[] = "\r\n"; + char *start_decoding = NULL; + int data_size = 0; + int res = 0; + int de_temp_len = 0; + int len = 0; + + _DEBUG_INFO("src len : %d", src_len); + char *de_temp = (char *)malloc(sizeof(char) * TEMP_BUFFER_SIZE); /* todo : temporary */ + if (de_temp == NULL) { + _DEBUG_ERROR("[encoding_util] malloc error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + return 0; + } + + while ((start_decoding = strstr(src, "ENCODING="))) { + char *colon_loc = strstr(start_decoding, colon); /* find ':''s location */ + char *line_breaker_loc = NULL; + if (colon_loc != NULL) { + line_breaker_loc = strstr(colon_loc, line_breaker); /* find "\r\n"'s location */ + } else { + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + return 0; + } + + /* + * if find "ENCODING=" do strcat data until ":" to de_src + */ + data_size = (colon_loc + 1) - src; /* colon_loc + 1 ==> Until next character of ':' */ + + _DEBUG_INFO("data_size : %d", data_size); + char *temp = (char *)malloc(sizeof(char) * (data_size + 1)); + if (temp == NULL) { + _DEBUG_ERROR("[encoding_util] malloc error !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + memset(temp, 0x00, sizeof(char) * (data_size + 1)); + memcpy(temp, src, data_size); + len = g_strlcat(*de_src, temp, (src_len + 1)); + if (len >= (src_len + 1)) { + _DEBUG_ERROR("*de_src buffer overflow !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + if (temp != NULL) + free(temp); + + return 0; + } + + if (temp != NULL) + free(temp); + + _DEBUG_INFO("[encoding_util] << *de_src >> \n %s\n", *de_src); + + /* + * copy data from ":" until "\r\n"(actual encoding stream) + */ + data_size = line_breaker_loc - colon_loc; /* from ':' until "\r\n" + '\0' */ + char *value = (char *)malloc(sizeof(char) * (data_size + 1)); + if (value == NULL) { + _DEBUG_ERROR("[encoding_util] malloc error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + memset(value, 0x00, sizeof(char) * (data_size + 1)); + memcpy(value, ++colon_loc, data_size); /* from ':' until "\r\n" */ + value[data_size] = '\0'; + _DEBUG_INFO("value : %s, value_len : %d", value, strlen(value)); + + /* + * Get encoding type using data from "ENCODING=" to ":" + */ + char type_check[TYPE_CHECK_BUF_SIZE] = { 0, }; + int type_check_size = colon_loc - start_decoding; + strncpy(type_check, start_decoding, type_check_size); + _DEBUG_INFO("[encoding_util] type check : %s\n", type_check); + encoding_type_e type = find_encoding_type((const char *)type_check); + + /* + * Process decoding by passing the actual value and encoding type to decode_value() + */ + de_temp_len = 0; + memset(de_temp, 0x00, sizeof(char) * TEMP_BUFFER_SIZE); /* todo : temporary */ + res = decode_value(type, value, data_size, &de_temp, &de_temp_len); + + if (res != 1) { + _DEBUG_ERROR("[encoding_util] decode_value error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + if (value != NULL) + free(value); + + return 0; + } + + /* + * Append decoded data to de_src + */ + _DEBUG_INFO("[encoding_util] de_temp : %s\n", de_temp); + len = 0; + len = g_strlcat(*de_src, de_temp, (src_len + 1)); + if (len >= (src_len + 1)) { + _DEBUG_ERROR("*de_src buffer overflow !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + if (value != NULL) + free(value); + + return 0; + } + + /* + * find "ENCODING=" since "\r\n" agina + */ + src = line_breaker_loc; + + if (value != NULL) + free(value); + } + + len = 0; + len = g_strlcat(*de_src, src, (src_len + 1)); + if (len >= (src_len + 1)) { + _DEBUG_ERROR("*de_src buffer overflow !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + + *de_src_len = strlen(*de_src); + _DEBUG_INFO("[encoding_util] changed src : \n%s ( %d ) \n", *de_src, *de_src_len); + + if (de_temp != NULL) + free(de_temp); + + _EXTERN_FUNC_EXIT; + return 1; +} + +int check_encoding_data(const char *data) +{ + _EXTERN_FUNC_ENTER; + + /*if (strstr(data, "ENCODING=") != NULL) { + _DEBUG_INFO("[encoding_util] exist encoding data !! \n"); + return 1; + } else { + _DEBUG_INFO("[encoding_util] not exist encoding data !! \n"); + return 0; + } */ + _EXTERN_FUNC_EXIT; + return 0; +} + +encoding_type_e find_encoding_type(const char *data) +{ + _EXTERN_FUNC_ENTER; + + encoding_type_e type = EN_TYPE_NONE; + if (strstr(data, "QUOTED-PRINTABLE") != NULL) { + _DEBUG_INFO("[encoding_util] type : QP\n"); + type = EN_TYPE_QUOTED_PRINTABLE; + } else if (strstr(data, "BASE64") != NULL) { + _DEBUG_INFO("[encoding_util] type : BASE64\n"); + type = EN_TYPE_BASE64; + } else { + _DEBUG_INFO("[encoding_util] not supported type !! \n"); + } + + _EXTERN_FUNC_EXIT; + return type; +} + +int decode_value(encoding_type_e type, const char *value, int value_size, char **decode_str, int *decode_str_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(value == NULL, 0, "[encoding_util] value is NULL\n"); + + int res = 1; + const char *start_pos = NULL; + const char *cursor = NULL; + int semi_cnt = 0; + int len = 0; + + /* + * ex> value - =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 + */ + cursor = value; + start_pos = value; + + while (*cursor != '\0') { + if ((*cursor != ';') && (*cursor != '\r')) { + cursor++; + continue; + } else if (*cursor == ';') { + semi_cnt++; + } + + int data_size = 0; + data_size = cursor - start_pos; + + if (data_size == 0) { + cursor++; + start_pos++; + } else { + char *temp = (char *)malloc(sizeof(char) * (value_size + 1)); + if (temp == NULL) { + _DEBUG_ERROR("[encoding_util] malloc error !!"); + return 0; + } + memset(temp, 0x00, sizeof(char) * (value_size + 1)); + memcpy(temp, start_pos, data_size); + + _DEBUG_INFO("[encoding_util] temp : %s \n", temp); + + char *decoding = 0; + int decoding_len = 0; + + switch (type) { + case EN_TYPE_QUOTED_PRINTABLE: + res = decode_qp(temp, data_size, &decoding, &decoding_len); + break; + case EN_TYPE_BASE64: + res = decode_base64(temp, data_size, &decoding, &decoding_len); + break; + default: + break; + } + + if (temp != NULL) + free(temp); + + _DEBUG_INFO("[encoding_util] decoding : %s ( %d )\n", decoding, decoding_len); + + if (res != 1) { + _DEBUG_ERROR("[encoding_util] decoding error !! \n"); + + if (decoding != NULL) + free(decoding); + + return 0; + } else { + _DEBUG_INFO("[encoding_util] decoding success !!"); + if (decoding != NULL) { + len = g_strlcat(*decode_str, decoding, TEMP_BUFFER_SIZE); + if (len >= TEMP_BUFFER_SIZE) { + _DEBUG_ERROR("*decode_str buffer overflow !!"); + + if (decoding != NULL) + free(decoding); + + return 0; + } + _DEBUG_INFO("[encoding_util] *decode_str : %s\n", *decode_str); + } else { + _DEBUG_ERROR("[encoding_util] decoding is NULL !!"); + return 0; + } + } + + if (decoding != NULL) + free(decoding); + + cursor++; + start_pos = cursor; + } + + if (semi_cnt > 0) { + int len = strlen(*decode_str); + (*decode_str)[len] = ';'; + _DEBUG_INFO("[encoding_util] *decode_str : %s ( %d )\n", *decode_str, strlen(*decode_str)); + semi_cnt--; + } + } + + *decode_str_len = strlen(*decode_str); + + _DEBUG_INFO("[encoding_util] *decode_str : %s ( %d )\n", *decode_str, *decode_str_len); + + _EXTERN_FUNC_EXIT; + return res; +} + +static int _find_base(char ch) +{ + _EXTERN_FUNC_ENTER; + + int i = 0; + for (i = 0; i < 65; i++) { + if (base64_table[i] == ch) { + _DEBUG_INFO("[encoding_util] End !! \n"); + return i; + } + } + + _EXTERN_FUNC_EXIT; + return -1; +} diff --git a/src/plugins/ds-public/vcard/src/plugin_interface.c b/src/plugins/ds-public/vcard/src/plugin_interface.c new file mode 100755 index 0000000..5131f38 --- /dev/null +++ b/src/plugins/ds-public/vcard/src/plugin_interface.c @@ -0,0 +1,998 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include +#include +#include + +#include + +#include "plugin_spec.h" +#include "in_datastore_info_vcard.h" +#include "encoding_util.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__ ((visibility("default"))) +#endif + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "PLUGIN_VCARD" +#endif + +static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count); +static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, vcard_field_list_s * input_list); +static char *_convert_key_name(int key); + +static int _get_content(const char *value, void *data); + +static sync_agent_da_return_e _convert_service_error_to_common_error(contacts_error_e err); +static char *_contacts_vcard_put_content(const char *vcard_stream, const char *content_type, const char *content_value); +static int _contacts_vcard_get_content(const char *vcard_stream, const char *content_type, int (*fn) (const char *content_value, void *data), void *data); + +static void _contacts_struct_merge(contacts_record_h old, contacts_record_h new); +static void __contacts_struct_property_merge(contacts_record_h old, contacts_record_h new); +static void __contacts_struct_child_property_merge(unsigned int property_id, contacts_record_h old, contacts_record_h new); + +//static void _remove_vcard_field(CTSstruct *contact); +//static void _remove_vcard_gslist_field(gpointer data, gpointer user_data); + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_data, void **service_data) +{ + _EXTERN_FUNC_ENTER; + +// retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] agent_data is NULL"); +// +// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; +// int err = 0; +// CTSstruct *temp_service_data = 0; +// +// /* decoding & convert */ +// _DEBUG_INFO("[dc_vcard_plugIn] agent data : %s\n", agent_data); +// char *de_agent_data; +// int src_len = strlen(agent_data); +// int de_agent_data_len = 0; +// +// if (check_encoding_data(agent_data) == 1) { +// err = proc_decoding(agent_data, src_len, &de_agent_data, &de_agent_data_len); +// if (err == 0) { +// _DEBUG_ERROR("[dc_vcard_plugIn] proc_decoding() Fail!\n"); +// ret = SYNC_AGENT_DA_ERRORS; +// return ret; +// } +// +// err = contacts_svc_get_contact_from_vcard((const void *)de_agent_data, &temp_service_data); +// +// /*memory free */ +// if (de_agent_data != NULL) +// free(de_agent_data); +// } else { +// err = contacts_svc_get_contact_from_vcard(agent_data, &temp_service_data); +// } +// +// if (err < CTS_SUCCESS) { +// _DEBUG_ERROR("[dc_vcard_plugIn] contacts_svc_get_contact_from_vcard() Fail!\n"); +// ret = _convert_service_error_to_common_error(err); +// *service_data = 0; +// } else { +// _DEBUG_INFO("[dc_vcard_plugIn] contacts_svc_get_contact_from_vcard() Success!\n"); +// *service_data = (void *)temp_service_data; +// } + + retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] agent_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_list_h list = NULL; + contacts_record_h record = NULL; + contacts_record_h cloned_record = NULL; + + /* decoding & convert */ + _DEBUG_INFO("[dc_vcard_plugIn] agent data : %s\n", agent_data); + char *de_agent_data; + int src_len = strlen(agent_data); + int de_agent_data_len = 0; + + if (check_encoding_data(agent_data) == 1) { + err = proc_decoding(agent_data, src_len, &de_agent_data, &de_agent_data_len); + if (err == 0) { + _DEBUG_ERROR("[dc_vcard_plugIn] proc_decoding() Fail!\n"); + ret = SYNC_AGENT_DA_ERRORS; + return ret; + } + + err = contacts_vcard_parse_to_contacts(de_agent_data, &list); + + /*memory free */ + if (de_agent_data != NULL) + free(de_agent_data); + } else { + err = contacts_vcard_parse_to_contacts(agent_data, &list); + } + + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_vcard_plugIn] contacts_vcard_parse_to_contacts() Fail!\n"); + ret = _convert_service_error_to_common_error(err); + *service_data = 0; + } else { + _DEBUG_INFO("[dc_vcard_plugIn] contacts_vcard_parse_to_contacts() Success!\n"); + err = contacts_list_get_current_record_p(list, &record); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_vcard_plugIn] contacts_list_get_current_record_p() Fail!\n"); + ret = _convert_service_error_to_common_error(err); + *service_data = 0; + contacts_list_destroy(list, true); + return ret; + } + + err = contacts_record_clone(record, &cloned_record); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_vcard_plugIn] contacts_record_clone() Fail!\n"); + ret = _convert_service_error_to_common_error(err); + *service_data = 0; + contacts_list_destroy(list, true); + return ret; + } + + *service_data = (void *)cloned_record; + contacts_list_destroy(list, true); + } + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_replace_converter(void *old_service_data, const void *agent_data, void **new_service_data) +{ + _EXTERN_FUNC_ENTER; + +// retvm_if(old_service_data == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] old_service_data is NULL"); +// retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] agent_data is NULL"); +// +// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; +// int err = 0; +// CTSstruct *temp_new_service_data = 0; +// CTSstruct *temp_old_service_data = (CTSstruct *)old_service_data; +// +// /* 1. agent_data encoding check +// * 2. decoding +// * 3. copy to new_service_data +// */ +// /* decoding */ +// char *de_agent_data; +// int src_len = strlen(agent_data); +// int de_agent_data_len = 0; +// +// if (check_encoding_data(agent_data) == 1) { +// err = proc_decoding(agent_data, src_len, &de_agent_data, &de_agent_data_len); +// if (err == 0) { +// _DEBUG_ERROR("[dc_vcard_plugIn] proc_decoding() Fail!\n"); +///* ret = SYNC_AGENT_DA_ERRORS; +// return ret;*/ +// err = contacts_svc_get_contact_from_vcard(agent_data, &temp_new_service_data); +// } else { +// _DEBUG_INFO("[dc_vcard_plugIn] proc_decoding() Success l!\n"); +// err = contacts_svc_get_contact_from_vcard((const void *)de_agent_data, &temp_new_service_data); +// +// /*memory free */ +// if (de_agent_data != NULL) +// free(de_agent_data); +// } +// } else { +// err = contacts_svc_get_contact_from_vcard(agent_data, &temp_new_service_data); +// } +// +// if (err < CTS_SUCCESS) { +// _DEBUG_ERROR("[dc_vcard_plugIn] contacts_svc_get_contact_from_vcard() Fail!\n"); +// ret = _convert_service_error_to_common_error(err); +// *new_service_data = 0; +// +// /* memory free */ +// if (temp_old_service_data != NULL) +// contacts_svc_struct_free(temp_old_service_data); +// +// } else { +// _DEBUG_INFO("[dc_vcard_plugIn] contacts_svc_get_contact_from_vcard() Success!\n"); +// _remove_vcard_field(temp_old_service_data); +// err = contacts_svc_struct_merge(temp_old_service_data, temp_new_service_data); +// if (err < CTS_SUCCESS) { +// _DEBUG_ERROR("[dc_vcard_plugIn] contacts_svc_struct_merge() Fail!\n"); +// ret = _convert_service_error_to_common_error(err); +// *new_service_data = 0; +// +// /* memory free */ +// if (temp_old_service_data != NULL) +// contacts_svc_struct_free(temp_old_service_data); +// } else { +// _DEBUG_INFO("[dc_vcard_plugIn] contacts_svc_struct_merge() Success!\n"); +// *new_service_data = (void *)temp_old_service_data; +// } +// } +// +// /* memory free */ +// if (temp_new_service_data != NULL) +// contacts_svc_struct_free(temp_new_service_data); + + retvm_if(old_service_data == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] old_service_data is NULL"); + retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] agent_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_list_h list = NULL; + + contacts_record_h temp_new_service_data = NULL; + contacts_record_h temp_old_service_data = (contacts_record_h) old_service_data; + + /* 1. agent_data encoding check + * 2. decoding + * 3. copy to new_service_data + */ + /* decoding */ + char *de_agent_data; + int src_len = strlen(agent_data); + int de_agent_data_len = 0; + + if (check_encoding_data(agent_data) == 1) { + err = proc_decoding(agent_data, src_len, &de_agent_data, &de_agent_data_len); + if (err == 0) { + _DEBUG_ERROR("[dc_vcard_plugIn] proc_decoding() Fail!\n"); +/* ret = SYNC_AGENT_DA_ERRORS; + return ret;*/ + err = contacts_vcard_parse_to_contacts(agent_data, &list); + } else { + _DEBUG_INFO("[dc_vcard_plugIn] proc_decoding() Success l!\n"); + err = contacts_vcard_parse_to_contacts(de_agent_data, &list); + + /*memory free */ + if (de_agent_data != NULL) + free(de_agent_data); + } + } else { + err = contacts_vcard_parse_to_contacts(agent_data, &list); + } + + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_vcard_plugIn] contacts_vcard_parse_to_contacts() Fail!\n"); + ret = _convert_service_error_to_common_error(err); + *new_service_data = 0; + + } else { + _DEBUG_INFO("[dc_vcard_plugIn] contacts_vcard_parse_to_contacts() Success!\n"); + + err = contacts_list_get_current_record_p(list, &temp_new_service_data); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_vcard_plugIn] contacts_list_get_current_record_p() Fail!\n"); + ret = _convert_service_error_to_common_error(err); + *new_service_data = 0; + goto DACI_FINISH; + } + + _contacts_struct_merge(temp_old_service_data, temp_new_service_data); + + *new_service_data = (void *)temp_old_service_data; + } + + DACI_FINISH: + + contacts_list_destroy(list, true); + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_reverse_converter(void *service_data, void **agent_data) +{ + _EXTERN_FUNC_ENTER; + +// retvm_if(service_data == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] service_data is NULL"); +// +// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; +// int err = 0; +// char *temp_agent_data = 0; +// CTSstruct *temp_service_data = (CTSstruct *)service_data; +// +// /* Reverse_Converter */ +// err = contacts_svc_get_vcard_from_contact(temp_service_data, &temp_agent_data); +// if (err < CTS_SUCCESS) { +// _DEBUG_INFO("[dc_vcard_plugIn] contacts_svc_get_vcard_from_contact() Fail!\n"); +// ret = _convert_service_error_to_common_error(err); +// *agent_data = 0; +// } else { +// _DEBUG_INFO("[dc_vcard_plugIn] contacts_svc_get_vcard_from_contact() Success!\n"); +// *agent_data = (void *)temp_agent_data; +// } +// +// /* memory free */ +// if (temp_service_data != NULL) +// contacts_svc_struct_free(temp_service_data); + + retvm_if(service_data == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] service_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + contacts_error_e err = CONTACTS_ERROR_NONE; + + char *temp_agent_data = 0; + contacts_record_h record = (contacts_record_h) service_data; + + char *display_name = NULL; + int id; + contacts_record_get_str_p(record, _contacts_contact.display_name, &display_name); + contacts_record_get_int(record, _contacts_contact.id, &id); + + _DEBUG_INFO("display_name = %s", display_name); + _DEBUG_INFO("id = %d", id); + + /* Reverse_Converter */ + err = contacts_vcard_make_from_contact(record, &temp_agent_data); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_vcard_plugIn] contacts_vcard_make_from_contact() Fail!\n"); + ret = _convert_service_error_to_common_error(err); + *agent_data = 0; + } else { + _DEBUG_INFO("[dc_vcard_plugIn] contacts_vcard_make_from_contact() Success!\n"); + *agent_data = (void *)temp_agent_data; + _DEBUG_INFO("temp_agent_data = %s", temp_agent_data); + } + + contacts_record_destroy(record, true); + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API void *sync_agent_plugin_alloc_object() +{ + _EXTERN_FUNC_ENTER; + + char *agent_data = "BEGIN:VCARD\r\n\ +VERSION:2.1\r\n\ +END:VCARD"; + + _EXTERN_FUNC_EXIT; + return (void *)agent_data; +} + +EXPORT_API int sync_agent_plugin_free_object(void *in_object) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("[dc_vcard_plugIn] Do nothing\n"); + + return 1; +} + +EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *extension_key, void *value) +{ + _EXTERN_FUNC_ENTER; + + char *new_agent_data = 0; + char *key_name = 0; + + if (key == VCARD_CONTENT_NO_TYPE) + return (void *)new_agent_data; + else if (key == VCARD_CONTENT_EXTENSION) + key_name = extension_key; + else + key_name = _convert_key_name(key); + + new_agent_data = _contacts_vcard_put_content((const char *)in_object, (const char *)key_name, (const char *)value); + + _EXTERN_FUNC_EXIT; + return (void *)new_agent_data; +} + +EXPORT_API void *sync_agent_plugin_get_value(void *in_object, int key, char *extension_key) +{ + _EXTERN_FUNC_ENTER; + + char data[5000] = { 0, }; /* hard coding : size 1000 */ + char *key_name = 0; + int result; + + if (key == VCARD_CONTENT_NO_TYPE) + return 0; + else if (key == VCARD_CONTENT_EXTENSION) + key_name = extension_key; + else + key_name = _convert_key_name(key); + + result = _contacts_vcard_get_content((const char *)in_object, (const char *)key_name, _get_content, data); + if (result == 0) { + _EXTERN_FUNC_EXIT; + return 0; + } + + _EXTERN_FUNC_EXIT; + + if (strlen(data) == 0) + return 0; + else + return strdup(data); +} + +EXPORT_API sync_agent_plugin_object_info_s *sync_agent_plugin_get_obj_info() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_plugin_object_info_s *obj_info = (sync_agent_plugin_object_info_s *) calloc(1, sizeof(sync_agent_plugin_object_info_s)); + if (obj_info == NULL) { + _DEBUG_ERROR("CALLOC failed !!!"); + return NULL; + } + + obj_info->type = VCARD_TYPE; + obj_info->version = VCARD_VERSION; + obj_info->field_cnt = sizeof(vcard_field_list) / sizeof(vcard_field_list_s); + + if (obj_info->field_cnt > 0) + if (_set_obj_field_info(&(obj_info->field_list), obj_info->field_cnt, vcard_field_list) == 0) { + /* for prevent */ + if (obj_info != NULL) + free(obj_info); + + return NULL; + } + + _EXTERN_FUNC_EXIT; + return obj_info; +} + +EXPORT_API int sync_agent_plugin_free_obj_info(sync_agent_plugin_object_info_s * obj_info) +{ + _EXTERN_FUNC_ENTER; + + if (obj_info != NULL) { + if (obj_info->field_cnt > 0) + if (_free_obj_field_info(obj_info->field_list, obj_info->field_cnt) == 0) + return 0; + + free(obj_info); + } + + _EXTERN_FUNC_EXIT; + return 1; +} + +static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count) +{ + _INNER_FUNC_ENTER; + + int field_count = 0; + sync_agent_plugin_field_info_s *child = NULL; + + if (field_list != NULL) { + for (field_count = 0; field_count < count; field_count++) { + child = field_list + field_count; + if (child->field_child_cnt > 0) + if (_free_obj_field_info(child->field_child_list, child->field_child_cnt) == 0) + return 0; + } + free(field_list); + } + + _INNER_FUNC_EXIT; + return 1; +} + +static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, vcard_field_list_s * input_list) +{ + _INNER_FUNC_ENTER; + + int field_count = 0; + sync_agent_plugin_field_info_s *child = NULL; + + *field_list = (sync_agent_plugin_field_info_s *) calloc(count, sizeof(sync_agent_plugin_field_info_s)); + if (*field_list == NULL) { + _DEBUG_ERROR("CALLOC failed !!!"); + return 0; + } + + for (field_count = 0; field_count < count; field_count++) { + child = (*field_list) + field_count; + child->field_name = input_list[field_count].field_name; + _DEBUG_TRACE("[%s]", child->field_name); + + if (input_list[field_count].field_enum == VCARD_FIELD_BEGIN || input_list[field_count].field_enum == VCARD_FIELD_END) { + child->field_child_cnt = sizeof(vcard_field_list_begin_end) / sizeof(vcard_field_list_s); + _DEBUG_TRACE("----------"); + _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_begin_end); + _DEBUG_TRACE("=========="); + } else if (input_list[field_count].field_enum == VCARD_FIELD_VERSION) { + child->field_child_cnt = sizeof(vcard_field_list_version) / sizeof(vcard_field_list_s); + _DEBUG_TRACE("----------"); + _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_version); + _DEBUG_TRACE("=========="); + } else if (input_list[field_count].field_enum == VCARD_FIELD_ADR) { + child->field_child_cnt = sizeof(vcard_field_list_adr) / sizeof(vcard_field_list_s); + _DEBUG_TRACE("----------"); + _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_adr); + _DEBUG_TRACE("=========="); + } else if (input_list[field_count].field_enum == VCARD_FIELD_TEL) { + child->field_child_cnt = sizeof(vcard_field_list_tel) / sizeof(vcard_field_list_s); + _DEBUG_TRACE("----------"); + _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_tel); + _DEBUG_TRACE("=========="); + } else if (input_list[field_count].field_enum == VCARD_FIELD_EMAIL) { + child->field_child_cnt = sizeof(vcard_field_list_email) / sizeof(vcard_field_list_s); + _DEBUG_TRACE("----------"); + _set_obj_field_info(&(child->field_child_list), child->field_child_cnt, vcard_field_list_email); + _DEBUG_TRACE("=========="); + } + } + + _INNER_FUNC_EXIT; + return 1; +} + +static char *_convert_key_name(int key) +{ + _INNER_FUNC_ENTER; + + char *key_name = 0; + + switch (key) { + case VCARD_CONTENT_FN: + key_name = "FN"; + break; + case VCARD_CONTENT_N: + key_name = "N"; + break; + case VCARD_CONTENT_NICKNAME: + key_name = "NICKNAME"; + break; + case VCARD_CONTENT_PHOTO: + key_name = "PHOTO"; + break; + case VCARD_CONTENT_BDAY: + key_name = "BDAY"; + break; + case VCARD_CONTENT_ADR: + key_name = "ADR"; + break; + case VCARD_CONTENT_LABEL: + key_name = "LABEL"; + break; + case VCARD_CONTENT_TEL: + key_name = "TEL"; + break; + case VCARD_CONTENT_EMAIL: + key_name = "EMAIL"; + break; + case VCARD_CONTENT_TITLE: + key_name = "TITLE"; + break; + case VCARD_CONTENT_ROLE: + key_name = "ROLE"; + break; + case VCARD_CONTENT_ORG: + key_name = "ORG"; + break; + case VCARD_CONTENT_NOTE: + key_name = "NOTE"; + break; + case VCARD_CONTENT_REV: + key_name = "REV"; + break; + case VCARD_CONTENT_UID: + key_name = "UID"; + break; + case VCARD_CONTENT_URL: + key_name = "URL"; + break; + case VCARD_CONTENT_X_ANNIVERSARY: + key_name = "X-ANNIVERSARY"; + break; + case VCARD_CONTENT_X_IRMC_LUID: + key_name = "X-IRMC-LUID"; + break; + default: + break; + } + + _INNER_FUNC_EXIT; + return key_name; +} + +static int _get_content(const char *value, void *data) +{ + _INNER_FUNC_ENTER; + + retvm_if(value == NULL, SYNC_AGENT_DA_ERRORS, "[dc_vcard_plugIn] value is NULL"); + + const char *line_breaker = "\r"; + char *colon_loc = 0; + char *line_breaker_loc = 0; + int data_size = 0; + + colon_loc = (char *)value; + line_breaker_loc = strstr(colon_loc, line_breaker); + data_size = line_breaker_loc - colon_loc; + _DEBUG_TRACE("[dc_vcard_plugIn] value : %s", value); + _DEBUG_TRACE("[dc_vcard_plugIn] colon_loc : %s", colon_loc); + _DEBUG_TRACE("[dc_vcard_plugIn] line_breaker_loc : %s", line_breaker_loc); + _DEBUG_TRACE("[dc_vcard_plugIn] data_size : %d", data_size); + + /* hard coding : size 5000 */ + memcpy((char *)data, colon_loc, data_size); + + _INNER_FUNC_EXIT; + return 1; +} + +static sync_agent_da_return_e _convert_service_error_to_common_error(contacts_error_e err) +{ + _INNER_FUNC_ENTER; + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + _DEBUG_TRACE("[da_contact_plugIn] Error Code : %d\n", err); + + switch (err) { + case CONTACTS_ERROR_NONE: + ret = SYNC_AGENT_DA_SUCCESS; + break; + case CONTACTS_ERROR_OUT_OF_MEMORY: + ret = SYNC_AGENT_DA_ERR_MEMORY_FULL; + break; + case CONTACTS_ERROR_INVALID_PARAMETER: + ret = SYNC_AGENT_DA_ERR_INVALID_PARAMETER; + break; + case CONTACTS_ERROR_NO_DATA: + ret = SYNC_AGENT_DA_ERR_NO_DATA; + break; + case CONTACTS_ERROR_DB: + ret = SYNC_AGENT_DA_ERR_SERVICE_DB; + break; + case CONTACTS_ERROR_IPC: + ret = SYNC_AGENT_DA_ERR_SERVICE_IPC; + break; + default: + ret = SYNC_AGENT_DA_ERRORS; + break; + } + + _INNER_FUNC_EXIT; + + return ret; +} + +static char *_contacts_vcard_put_content(const char *vcard_stream, const char *content_type, const char *content_value) +{ + _INNER_FUNC_ENTER; + + int i, org_len, new_len; + char *new_stream, *cur; + const char *end_content = "END:VCARD"; + + retvm_if(NULL == vcard_stream, NULL, "vcard_stream is NULL"); + retvm_if(NULL == content_type, NULL, "content_type is NULL"); + retvm_if(NULL == content_value, NULL, "content_value is NULL"); + + org_len = strlen(vcard_stream); + new_len = org_len + strlen(content_type) + strlen(content_value) + 8; + + new_stream = malloc(new_len); + retvm_if(NULL == new_stream, NULL, "malloc() Failed"); + + memcpy(new_stream, vcard_stream, org_len); + + i = 1; + for (cur = new_stream + new_len - 1; cur; cur--) { + if (end_content[9 - i] == *cur) { + if (9 == i) + break; + i++; + continue; + } else { + i = 1; + } + } + if (9 != i) { + _DEBUG_ERROR("vcard_stream is invalid(%s)", vcard_stream); + free(new_stream); + _INNER_FUNC_EXIT; + return NULL; + } + + cur += snprintf(cur, new_len - (cur - new_stream), "%s:", content_type); + cur = strncpy(cur, content_value, new_len - (cur - new_stream)); + snprintf(cur, new_len - (cur - new_stream), "\r\n%s\r\n", end_content); + + _INNER_FUNC_EXIT; + + return new_stream; +} + +static int _contacts_vcard_get_content(const char *vcard_stream, const char *content_type, int (*fn) (const char *content_value, void *data), void *data) +{ + _INNER_FUNC_ENTER; + + int len, buf_size, type_len; + char *cursor, *found, *value; + + retv_if(NULL == vcard_stream, 0); + retv_if(NULL == content_type, 0); + retv_if(NULL == fn, 0); + + type_len = strlen(content_type); + value = malloc(1024); + retvm_if(NULL == value, 0, "malloc() Failed"); + buf_size = 1024; + + while ((found = strstr(vcard_stream, content_type))) { + if ((found != vcard_stream && '\n' != *(found - 1)) + && ':' != *(found + type_len + 1)) + continue; + + cursor = found; + while (*cursor) { + if ('\r' == *cursor) + cursor++; + if ('\n' == *cursor) { + if (' ' != *(cursor + 1)) + break; + } + + cursor++; + } + len = cursor - found; + if (len < buf_size) + memcpy(value, found, len); + else { + value = realloc(value, len + 1); + if (value) { + buf_size = len + 1; + memcpy(value, found, len); + } else { + vcard_stream = found + type_len; + continue; + } + } + value[len] = '\0'; + if (fn) + if (fn(value + type_len + 1, data)) { + free(value); + _INNER_FUNC_EXIT; + return 0; + } + vcard_stream = found + type_len; + } + + free(value); + + _INNER_FUNC_EXIT; + return 1; +} + +static void _contacts_struct_merge(contacts_record_h old, contacts_record_h new) +{ + _INNER_FUNC_ENTER; + + __contacts_struct_property_merge(old, new); + + __contacts_struct_child_property_merge(_contacts_contact.name, old, new); + __contacts_struct_child_property_merge(_contacts_contact.image, old, new); + __contacts_struct_child_property_merge(_contacts_contact.company, old, new); + __contacts_struct_child_property_merge(_contacts_contact.note, old, new); + __contacts_struct_child_property_merge(_contacts_contact.number, old, new); + __contacts_struct_child_property_merge(_contacts_contact.email, old, new); + __contacts_struct_child_property_merge(_contacts_contact.event, old, new); + __contacts_struct_child_property_merge(_contacts_contact.messenger, old, new); + __contacts_struct_child_property_merge(_contacts_contact.address, old, new); + __contacts_struct_child_property_merge(_contacts_contact.url, old, new); + __contacts_struct_child_property_merge(_contacts_contact.nickname, old, new); + __contacts_struct_child_property_merge(_contacts_contact.profile, old, new); +// __contacts_struct_child_property_merge(_contacts_contact.relationship, old, new); +// __contacts_struct_child_property_merge(_contacts_contact.group_relation, old, new); + __contacts_struct_child_property_merge(_contacts_contact.extension, old, new); + + _INNER_FUNC_EXIT; +} + +static void __contacts_struct_property_merge(contacts_record_h old, contacts_record_h new) +{ + _INNER_FUNC_ENTER; + +// contacts_error_e err = CONTACTS_ERROR_NONE; +// +// char *ringtone_path = NULL; +// char *image_thumbnail_path = NULL; +// char *uid = NULL; +// char *vibration = NULL; +// +// err = contacts_record_get_str_p(new, _contacts_contact.ringtone_path, &ringtone_path); +// if (err != CONTACTS_ERROR_NONE) +// _DEBUG_ERROR("contacts_record_get_str_p(ringtone_path) is failed"); +// +// if (ringtone_path != NULL) { +// _DEBUG_TRACE("ringtone_path = %s", ringtone_path); +// err = contacts_record_set_str(old, _contacts_contact.ringtone_path, ringtone_path); +// if (err != CONTACTS_ERROR_NONE) +// _DEBUG_ERROR("contacts_record_set_str(%s) is failed", ringtone_path); +// } +// +// err = contacts_record_get_str_p(new, _contacts_contact.image_thumbnail_path, &image_thumbnail_path); +// if (err != CONTACTS_ERROR_NONE) +// _DEBUG_ERROR("contacts_record_get_str_p(image_thumbnail_path) is failed"); +// +// if (image_thumbnail_path != NULL) { +// _DEBUG_TRACE("image_thumbnail_path = %s", image_thumbnail_path); +// err = contacts_record_set_str(old, _contacts_contact.image_thumbnail_path, image_thumbnail_path); +// if (err != CONTACTS_ERROR_NONE) +// _DEBUG_ERROR("contacts_record_set_str(%s) is failed", image_thumbnail_path); +// } +// +// err = contacts_record_get_str_p(new, _contacts_contact.uid, &uid); +// if (err != CONTACTS_ERROR_NONE) +// _DEBUG_ERROR("contacts_record_get_str_p(uid) is failed"); +// +// if (uid != NULL) { +// _DEBUG_TRACE("uid = %s", uid); +// err = contacts_record_set_str(old, _contacts_contact.uid, uid); +// if (err != CONTACTS_ERROR_NONE) +// _DEBUG_ERROR("contacts_record_set_str(%s) is failed", uid); +// } +// +// err = contacts_record_get_str_p(new, _contacts_contact.vibration, &vibration); +// if (err != CONTACTS_ERROR_NONE) +// _DEBUG_ERROR("contacts_record_get_str_p(vibration) is failed"); +// +// if (vibration != NULL) { +// _DEBUG_TRACE("vibration = %s", vibration); +// err = contacts_record_set_str(old, _contacts_contact.vibration, vibration); +// if (err != CONTACTS_ERROR_NONE) +// _DEBUG_ERROR("contacts_record_set_str(%s) is failed", vibration); +// } + + contacts_error_e err = CONTACTS_ERROR_NONE; + + char *image_thumbnail_path = NULL; + + err = contacts_record_get_str_p(new, _contacts_contact.image_thumbnail_path, &image_thumbnail_path); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_get_str_p(image_thumbnail_path) is failed"); + + if (image_thumbnail_path != NULL) { + _DEBUG_TRACE("image_thumbnail_path = %s", image_thumbnail_path); + err = contacts_record_set_str(old, _contacts_contact.image_thumbnail_path, image_thumbnail_path); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_set_str(%s) is failed", image_thumbnail_path); + } + + _INNER_FUNC_EXIT; +} + +static void __contacts_struct_child_property_merge(unsigned int property_id, contacts_record_h old, contacts_record_h new) +{ + _INNER_FUNC_ENTER; + + contacts_error_e err = CONTACTS_ERROR_NONE; + + unsigned int old_count = 0; + unsigned int new_count = 0; + + contacts_record_h old_record = NULL; + contacts_record_h new_record = NULL; + contacts_record_h new_cloned_record = NULL; + + _DEBUG_TRACE("property_id = %d", property_id); + + err = contacts_record_get_child_record_count(old, property_id, &old_count); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_get_child_record_count is failed"); + + _DEBUG_TRACE("old_count = %d", old_count); + + int i; + for (i = 0; i < old_count; i++) { + + err = contacts_record_get_child_record_at_p(old, property_id, 0, &old_record); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_get_child_record_at_p is failed"); + + err = contacts_record_remove_child_record(old, property_id, old_record); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_remove_child_record is failed"); + } + + err = contacts_record_get_child_record_count(new, property_id, &new_count); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_get_child_record_count is failed"); + + _DEBUG_TRACE("new_count = %d", new_count); + + for (i = 0; i < new_count; i++) { + + err = contacts_record_get_child_record_at_p(new, property_id, i, &new_record); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_get_child_record_at_p is failed"); + + err = contacts_record_clone(new_record, &new_cloned_record); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_clone is failed"); + + err = contacts_record_add_child_record(old, property_id, new_cloned_record); + if (err != CONTACTS_ERROR_NONE) + _DEBUG_ERROR("contacts_record_add_child_record is failed"); + } + + _INNER_FUNC_EXIT; +} + +//static void _remove_vcard_field(CTSstruct *contact) +//{ +// _INNER_FUNC_ENTER; +// +// GSList *numbers = 0, *email = 0, *event = 0, *postal = 0, *web = 0, *nick = 0; +// CTSvalue *name = 0, *company = 0, *base = 0; +// +// /* free name */ +// contacts_svc_struct_get_value(contact, CTS_CF_NAME_VALUE, &name); +// contacts_svc_value_set_str(name, CTS_NAME_VAL_FIRST_STR, 0); +// contacts_svc_value_set_str(name, CTS_NAME_VAL_LAST_STR, 0); +// contacts_svc_value_set_str(name, CTS_NAME_VAL_ADDITION_STR, 0); +// contacts_svc_value_set_str(name, CTS_NAME_VAL_SUFFIX_STR, 0); +// contacts_svc_value_set_str(name, CTS_NAME_VAL_PREFIX_STR, 0); +// contacts_svc_value_set_str(name, CTS_NAME_VAL_FIRST_STR, 0); +// +// /* free company */ +// contacts_svc_struct_get_value(contact, CTS_VALUE_COMPANY, &company); +// contacts_svc_value_set_str(company, CTS_COMPANY_VAL_NAME_STR, 0); +// contacts_svc_value_set_str(company, CTS_COMPANY_VAL_DEPARTMENT_STR, 0); +// contacts_svc_value_set_str(company, CTS_COMPANY_VAL_JOB_TITLE_STR, 0); +// contacts_svc_value_set_str(company, CTS_COMPANY_VAL_ROLE_STR, 0); +// +// /* free base */ +// contacts_svc_struct_get_value(contact, CTS_CF_BASE_INFO_VALUE, &base); +// contacts_svc_value_set_str(base, CTS_BASE_VAL_IMG_PATH_STR, 0); +// //contacts_svc_value_set_str(base, CTS_BASE_VAL_FULL_IMG_PATH_STR, 0); +// contacts_svc_value_set_str(base, CTS_NOTE_VAL_NOTE_STR, 0); +// +// /* free number */ +// contacts_svc_struct_get_list(contact, CTS_CF_NUMBER_LIST, &numbers); +// g_slist_foreach(numbers, _remove_vcard_gslist_field, (gpointer) CTS_NUM_VAL_DELETE_BOOL); +// +// /* free email */ +// contacts_svc_struct_get_list(contact, CTS_CF_EMAIL_LIST, &email); +// g_slist_foreach(email, _remove_vcard_gslist_field, (gpointer) CTS_EMAIL_VAL_DELETE_BOOL); +// +// /* free event */ +// contacts_svc_struct_get_list(contact, CTS_CF_EVENT_LIST, &event); +// g_slist_foreach(event, _remove_vcard_gslist_field, (gpointer) CTS_EVENT_VAL_DELETE_BOOL); +// +// /* free postal */ +// contacts_svc_struct_get_list(contact, CTS_CF_POSTAL_ADDR_LIST, &postal); +// g_slist_foreach(postal, _remove_vcard_gslist_field, (gpointer) CTS_POSTAL_VAL_DEFAULT_BOOL); +// +// /* free web */ +// contacts_svc_struct_get_list(contact, CTS_CF_WEB_ADDR_LIST, &web); +// g_slist_foreach(web, _remove_vcard_gslist_field, (gpointer) CTS_WEB_VAL_DELETE_BOOL); +// +// /* free nick */ +// contacts_svc_struct_get_list(contact, CTS_CF_NICKNAME_LIST, &nick); +// g_slist_foreach(nick, _remove_vcard_gslist_field, (gpointer) CTS_NICKNAME_VAL_DELETE_BOOL); +// +// _INNER_FUNC_EXIT; +//} +// +//static void _remove_vcard_gslist_field(gpointer data, gpointer user_data) +//{ +// _INNER_FUNC_ENTER; +// +// contacts_svc_value_set_bool((CTSvalue *) data, (int)user_data, 1); +// +// _INNER_FUNC_EXIT; +//} diff --git a/src/plugins/ds-public/xcalllog/CMakeLists.txt b/src/plugins/ds-public/xcalllog/CMakeLists.txt new file mode 100755 index 0000000..9e7305a --- /dev/null +++ b/src/plugins/ds-public/xcalllog/CMakeLists.txt @@ -0,0 +1,42 @@ + +############################################# +# +# Step 1. Set Variable and Build Dependency +# + +# set plguin name +SET(PLUGIN_NAME "dc-xcalllog") + +# set a name for the entire project +PROJECT(plugin-${PLUGIN_NAME}) + +# checks for build dependency modules : a pkg-config module for CMake +INCLUDE(FindPkgConfig) +pkg_check_modules(${PLUGIN_NAME} REQUIRED + contacts-service2 + sync-agent + dlog + libwbxml2) + +############################################# +# +# Step 2. Set Compile Environment +# + +# set extra cflags from build dependency +SET(PLUGIN_CFLAGS "${dc-xcalllog_CFLAGS}") + +############################################# +# +# Step 3. Set Link Environment +# + +# link a target to given libraries from pkg-config. +SET(PLUGIN_LDFLAGS "${dc-xcalllog_LDFLAGS}") + +############################################# +# +# Step 4. Install packages +# + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../CMakeLists.sub) \ No newline at end of file diff --git a/src/plugins/ds-public/xcalllog/include/encoding_util.h b/src/plugins/ds-public/xcalllog/include/encoding_util.h new file mode 100755 index 0000000..f55c5e8 --- /dev/null +++ b/src/plugins/ds-public/xcalllog/include/encoding_util.h @@ -0,0 +1,238 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef ENCODING_UTIL_H_ +#define ENCODING_UTIL_H_ + +#include +#include +#include + +#define QP_SIZE 76 +#define BASE64_SIZE 76 + +typedef enum { + EN_TYPE_NONE = 0, + EN_TYPE_QUOTED_PRINTABLE, + EN_TYPE_BASE64 +} encoding_type_e; + +/* Quoted-Printable + * + * @example code +int main() +{ + char *src = "hello"; + char *encode_src; + int encode_src_len = 0; + char *decode_src; + int decode_src_len = 0; + + int res = encode_qp(src, strlen(src), &encode_src, &encode_src_len); + if (res != 0) + fprintf(stdout, "encode src : %s ( %d ) \n", encode_src, encode_src_len); + else + fprintf(stdout, "%s\n", "encode error !!"); + + res = decode_qp(encode_src, encode_src_len, &decode_src, &decode_src_len); + if (res != 0) + fprintf(stdout, "decode src : %s ( %d ) \n", decode_src, decode_src_len); + else + fprintf(stdout, "%s\n", "decode error !!"); + + return 0; +} + + */ + +/* + * @brief encode original source ( encoding type : quoted-printable ) + * @param[in] src original source + * @param[in] src_len length of original source + * @param[out] en_src encoded source + * @param[out] en_src_len length of encoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int encode_qp(char *src, int src_len, char **en_src, int *en_src_len); + +/* + * @brief decode encoded source ( decoding type : quoted-printable ) + * @param[in] src encoded source + * @param[in] src_len length of encoded source + * @param[out] de_src decoded source ( original source ) + * @param[out] de_src_len length of decoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int decode_qp(char *src, int src_len, char **de_src, int *de_src_len); + +/* Base64 + * + * @example code + + int main() +{ + char *src = "hello"; + char *encode_src; + int encode_src_len = 0; + char *decode_src; + int decode_src_len = 0; + + int res = encode_base64(src, strlen(src), &encode_src, &encode_src_len); + if (res != 0) + fprintf(stdout, "encode src : %s ( %d ) \n", encode_src, encode_src_len); + else + fprintf(stdout, "%s\n", "encode error !!"); + + res = decode_base64(encode_src, encode_src_len, &decode_src, &decode_src_len); + if (res != 0) + fprintf(stdout, "decode src : %s ( %d ) \n", decode_src, decode_src_len); + else + fprintf(stdout, "%s\n", "decode error !!"); + + return 0; +} + + */ + +/* + * @brief encode original source ( encoding type : base64 ) + * @param[in] src original source + * @param[in] src_len length of original source + * @param[out] en_src encoded source + * @param[out] en_src_len length of encoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int encode_base64(char *src, int src_len, char **en_src, int *en_src_len); + +/* + * @brief decode encoded source ( decoding type : base64 ) + * @param[in] src encoded source + * @param[in] src_len length of encoded source + * @param[out] de_src decoded source ( original source ) + * @param[out] de_src_len length of decoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + */ +int decode_base64(char *src, int src_len, char **de_src, int *de_src_len); + +/* + * @brief make the decoding process + * @param[in] src encoded source + * @param[in] src_len length of encoded source + * @param[out] de_src decoded source ( original source ) + * @param[out] de_src_len length of decoded source + * @return operation result + * @retval 1 success + * @retval 0 fail + * + * @example code + +int main() +{ + char *src = "..."; // decoded data + int src_len = strlen(src); + char *decode_src; + int decode_src_len = 0; + + int res = proc_decoding(src, src_len, &decode_src, &decode_src_len); + + if (res != 0) + fprintf(stdout, "decode src : \n%s\n", decode_src); + else + fprintf(stdout, "%s\n", "decode error !!"); + + if (decode_src != NULL) + free(decode_src); + + return 0; +} + */ +int proc_decoding(const char *src, int src_len, char **de_src, int *de_src_len); + +/* + * @brief encoded value is changed to the decoded value + * @param[in] type encoding type + * @param[in] value encoded value (end of string must be '\0' !!) + * ex) =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 + * @param[in] value_size length of encoded value + * @param[out] decode_str decoded string + * @param[out] decode_str_len length of decoded string + * @return operation result + * @ratval 1 success + * @retval 0 fail + * + * @example code + +int main() +{ + char *data = "..."; // ex) ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8 + encoding_type_e type = find_encoding_type((const char *)data); + + char *value = "..."; // ex) =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 + int value_size = strlen(value); + + int decode_str_len = 0; + char *decode_str = (char*)malloc(sizeof(char)*BUF_SIZE); // BUF_SIZE : user define + if (decode_str == NULL) { + // error process + } + memset(decode_str, 0x00, sizeof(char)*BUF_SIZE); + + int res = decode_value(type, value, data_size, &decode_str, &decode_str_len); + + if (res == 1) { + // success process + if (decode_str != NULL) + free(decode_str); + } else { + // error process + if (decode_str != NULL) + free(decode_str); + } + + return 0; +} + */ + +int decode_value(encoding_type_e type, const char *value, int value_size, char **decode_str, int *decode_str_len); + +/* + * @brief get encoding type for data + * @param[in] data vobject data + * @return encoding type + * @ratval >= 1 success + * @retval 0 fail + */ +encoding_type_e find_encoding_type(const char *data); + +/* + * @brief check whether to exist this string, "ENCODING=" in the data + * @param[in] data vobject data + * @return operation result + * @retval 1 exist + * @retval 0 not exist + */ +int check_encoding_data(const char *data); + +#endif /* ENCODING_UTIL_H_ */ diff --git a/src/plugins/ds-public/xcalllog/include/plugin_spec.h b/src/plugins/ds-public/xcalllog/include/plugin_spec.h new file mode 100755 index 0000000..cdc31df --- /dev/null +++ b/src/plugins/ds-public/xcalllog/include/plugin_spec.h @@ -0,0 +1,33 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef PLUGIN_SPEC_H_ +#define PLUGIN_SPEC_H_ + +typedef enum { + + XCALLLOG_CONTENT_NO_TYPE = 0, + XCALLLOG_CONTENT_EXTENSION = 1, + XCALLLOG_CONTENT_FN = 2, + XCALLLOG_CONTENT_X_NUMBER = 3, + XCALLLOG_CONTENT_X_DATE = 4, + XCALLLOG_CONTENT_X_DURATION = 5, + XCALLLOG_CONTENT_X_CALLTYPE = 6, + +} xcallog_value_type_e; + +#endif /* PLUGIN_SPEC_H_ */ diff --git a/src/plugins/ds-public/xcalllog/src/encoding_util.c b/src/plugins/ds-public/xcalllog/src/encoding_util.c new file mode 100755 index 0000000..d7823cb --- /dev/null +++ b/src/plugins/ds-public/xcalllog/src/encoding_util.c @@ -0,0 +1,812 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include +#include + +#include + +#include "encoding_util.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "ENCODING_UTIL" +#endif + +#define TYPE_CHECK_BUF_SIZE 100 /* temporary definition */ +#define TEMP_BUFFER_SIZE 1024 /* temporary definition */ + +/* BASE64 TABLE */ +static char base64_table[65] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', + 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', + 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', + '2', '3', '4', '5', '6', '7', '8', '9', '+', + '/', '=' +}; + +/* Quoted-Printable */ +static char *_dec_to_hex(int dec); +static int _hex_to_dec(char *hex); + +/* Base64 */ +static int _find_base(char ch); + +/* + * Quoted-Printable + */ +int encode_qp(char *src, int src_len, char **en_src, int *en_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + char *en_hex; + int i = 0; + int j = 0; + int size_cnt = 0; + + /*encoded string length is three times longer than existing maximum string length */ + int full_lenth = src_len * 3 + 1 + (int)(src_len * 3 / 76) * 3; + *en_src = (char *)malloc(sizeof(char) * full_lenth); + if (*en_src == NULL) { + _DEBUG_ERROR("[encoding_util] malloc fail !!\n"); + return 0; + } + memset(*en_src, 0x00, src_len * 3 + 1); + + _DEBUG_INFO("[encoding_util] src_len : %d\n", src_len); + for (i = 0; i < src_len; i++) { + /* _DEBUG_INFO("[encoding_util] i : %d\n", i); */ + if (size_cnt >= QP_SIZE - 3) { + size_cnt = 0; + (*en_src)[j++] = 0x0A; + } + + if ((src[i] >= 33 && src[i] <= 126) || (src[i] == 0x0A)) { + if (src[i] == 61) { + en_hex = _dec_to_hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + size_cnt += 3; + } else { + size_cnt++; + (*en_src)[j++] = src[i]; + } + } else if (src[i] == 9 || src[i] == 32) { + if (src[i + 1] == 0x0A || src[i + 1] == '\0') { /* TAB or WhiteSpace */ + en_hex = _dec_to_hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + size_cnt += 3; + } else { + size_cnt++; + (*en_src)[j++] = src[i]; + } + } else { + en_hex = _dec_to_hex(src[i]); + (*en_src)[j++] = 0x3D; /* '=' */ + (*en_src)[j++] = en_hex[0]; + (*en_src)[j++] = en_hex[1]; + _DEBUG_INFO("[encoding_util] en_src : %s\n", *en_src); + size_cnt += 3; + } + } + + (*en_src)[j] = 0x00; + *en_src_len = size_cnt; + + _EXTERN_FUNC_EXIT; + return 1; +} + +int decode_qp(char *src, int src_len, char **de_src, int *de_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + char hex[3]; + char ch; + int dec = 0; + int is_space = 0; + int i = 0; + int j = 0; + + *de_src = (char *)malloc(sizeof(char) * (src_len + 1)); + if (*de_src == NULL) { + _DEBUG_ERROR("[encoding_util] malloc is fail !!\n"); + return 0; + } + memset(*de_src, 0x00, sizeof(char) * (src_len + 1)); + + while (src[i] != '\0') { + if (src[i] == 0x3D) { /* '=' */ + /* check whiteSpace */ + ch = src[++i]; + + /* '=' skip if next character is a TAB or WhiteSpace */ + while (ch == 0x09 || ch == 0x20) { + is_space = 1; + ch = src[++i]; + + if (is_space == 1) { + is_space = 0; + continue; + } + } + + /* '=' skip if next character is 3D which means '=' (encoding error case ??) */ + while (ch == '3') { + ch = src[++i]; + + if (ch == 'D') { + ch = src[++i]; + continue; + } + } + + /* if next character is LF after '=' do doft line break + * encoded QP string on one line 76 character is allowed + */ + if (ch == 0x0A) { /* LF */ + i++; + continue; + } + + hex[0] = src[i++]; + hex[1] = src[i++]; + hex[2] = '\0'; + + dec = _hex_to_dec(hex); + + /* decoding error */ + if (dec < 0) { + /* when error occur, restore the previous encoding message */ + (*de_src)[j++] = 0x3D; /* '=' */ + (*de_src)[j++] = hex[0]; + (*de_src)[j++] = hex[1]; + } else { + (*de_src)[j++] = dec; + } + } else if (src[i] > 0x7E) { /* encoding error */ + i++; /* ignore that character */ + } else { + (*de_src)[j++] = src[i++]; + } + } + + (*de_src)[j] = '\0'; + *de_src_len = j; + + _EXTERN_FUNC_EXIT; + return 1; +} + +static char *_dec_to_hex(int dec) +{ + _INNER_FUNC_ENTER; + + static char hex[3]; + int i; + int ch; + + for (i = 0; i < 2; i++) { + if (i == 0) { + ch = (dec & 0xF0) >> 4; + } else if (i == 1) { + ch = (dec & 0x0F); + } + + if (ch >= 10) { + hex[i] = 'A' + ch - 10; + } else { + hex[i] = '0' + ch; + } + } + + hex[i] = 0x00; + + _DEBUG_TRACE("[encoding_util] hex : %s\n", hex); + + _INNER_FUNC_EXIT; + return &hex[0]; +} + +static int _hex_to_dec(char *hex) +{ + _INNER_FUNC_ENTER; + + int dec = 0; + int byte; + int i = 0; + + for (i = 0; i < 2; i++) { + if (hex[i] >= '0' && hex[i] <= '9') { + byte = hex[i] - '0'; + } else if (hex[i] >= 'A' && hex[i] <= 'F') { + byte = hex[i] - 'A' + 10; + } else if (hex[i] >= 'a' && hex[i] <= 'f') { + byte = hex[i] - 'a' + 10; + } else { + byte = -1; + } + + if (byte < 0) + return -1; + + dec += (i == 0) ? byte << 4 : byte; + } + + _INNER_FUNC_EXIT; + return dec; +} + +/* + * Base64 + */ +int encode_base64(char *src, int src_len, char **en_src, int *en_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + int i = 0; + int j = 0; + int cnt = 0; + int ch = 0; + int size_cnt = 0; + + *en_src = (char *)malloc(sizeof(char) * (src_len * 2)); + + if (*en_src == NULL) { + _DEBUG_ERROR("[encoding_util] malloc fail !!\n"); + return 0; + } + memset(*en_src, 0x00, src_len * 2); + + while (1) { + switch (cnt++) { + case 0: + { + if (i < src_len) { + ch = (src[i] & 0xFC) >> 2; + } else { + ch = -1; + } + } + break; + + case 1: + { + if (i < src_len) { + if (i + 1 < src_len) { + ch = ((src[i] & 0x03) << 4) | ((src[i + 1] & 0xF0) >> 4); + } else { + ch = ((src[i] & 0x03) << 4); + } + } else { + ch = -1; + } + i++; + break; + } + + case 2: + { + if (i < src_len) { + if (i + 1 < src_len) { + ch = ((src[i] & 0x0F) << 2) | ((src[i] & 0xC0) >> 6); + } else { + ch = ((src[i] & 0x0F) << 2); + } + } else { + ch = -1; + } + i++; + } + break; + + case 3: + { + if (i < src_len) { + ch = (src[i] & 0x3F); + } else { + ch = -1; + } + i++; + cnt = 0; + } + break; + } + + /* + if (ch >= 0 && ch <= 25) { // Upper Case Alphabet + (*en_src)[j++] = 'A' + ch; + } else if (ch >= 26 && ch <= 51) { // Lower Case Alphabet + (*en_src)[j++] = 'a' + ch - 26; + } else if (ch >= 52 && ch <= 61) { // Digit + (*en_src)[j++] = '0' + ch - 52; + } else if (ch == 62) { + (*en_src)[j++] = '+'; + } else if (ch == 63) { + (*en_src)[j++] = '/'; + } else if (ch == -1) { + (*en_src)[j++] = '='; // padding + } + */ + + if (ch != -1) { + (*en_src)[j++] = base64_table[ch]; + } else { + (*en_src)[j++] = base64_table[64]; /* padding */ + } + + size_cnt++; + + if (j % 4 == 0) { + if (size_cnt == BASE64_SIZE) { + size_cnt = 0; + (*en_src)[j++] = 0x0A; /* soft line break */ + } + + if (i >= src_len) + break; + } + } + + (*en_src)[j] = 0x00; + *en_src_len = j; + + _EXTERN_FUNC_EXIT; + return 1; +} + +int decode_base64(char *src, int src_len, char **de_src, int *de_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + long tmp = 0; /* 4byte (using decoding) */ + int i = 0; + int j = 0; + int cnt = 0; + int pad_cnt = 0; + + /* de_src is enough for the src_len 3/4 size */ + *de_src = (char *)malloc(sizeof(char) * (src_len)); + + if (*de_src == NULL) { + _DEBUG_ERROR("[encoding_util] malloc is fail !!\n"); + return 0; + } + memset(*de_src, 0x00, src_len); + + while (src[i] != '\0') { + /* + if (isupper(src[i])) { + tmp = (tmp << 6) | (src[i] - 'A'); // Upper case : 0 ~ 25 + } else if (islower(src[i])) { + tmp = (tmp << 6) | (src[i] - 'a' + 0x1A); // Lower case : 26(0x1A) ~ 51 + } else if (isdigit(src[i])) { + tmp = (tmp << 6) | (src[i] - '0' + 0x34); // Number : 52(0x34) ~ 61 + } else if (src[i] == '+') { + tmp = (tmp << 6) | 0x3E; // '+' : 62(0x3E) + } else if (src[i] == '/') { + tmp = (tmp << 6) | 0x3F; // '/' : 63(0x3F) + } else if (src[i] == '=') { + pad_cnt++; + tmp = (tmp << 6); // '=' : padding + } else { + tmp = (tmp << 6); // encoding error + _DEBUG_INFO("encoding error !! \n"); + } + */ + + tmp = (tmp << 6) | (_find_base(src[i])); + if (tmp == 64) { + pad_cnt++; + } else if (tmp == -1) { + _DEBUG_ERROR("[encoding_util] encoding error \n"); + } + + if (++cnt >= 4) { + (*de_src)[j++] = (char)((tmp & 0x00FF0000) >> 16); + (*de_src)[j++] = (char)((tmp & 0x0000FF00) >> 8); + (*de_src)[j++] = (char)(tmp & 0x000000FF); + + cnt = 0; + tmp = 0; + + if (src[i + 1] == 0x0A) { /* soft line break */ + i++; + } + } + + i++; + } + + (*de_src)[j - pad_cnt] = '\0'; + *de_src_len = j - pad_cnt; + + _EXTERN_FUNC_EXIT; + return 1; +} + +int proc_decoding(const char *src, int src_len, char **de_src, int *de_src_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(src == NULL, 0, "[encoding_util] src is NULL\n"); + + const char *reg_src = NULL; + reg_src = src; + + _DEBUG_INFO("[encoding_util] << src >> \n%s\n", src); + + *de_src = (char *)malloc(sizeof(char) * (src_len + 1)); + if (*de_src == NULL) { + _DEBUG_INFO("[encoding_util] malloc error !! \n"); + + return 0; + } + memset(*de_src, 0x00, sizeof(char) * (src_len + 1)); + + char colon[] = ":"; + char line_breaker[] = "\r\n"; + char *start_decoding = NULL; + int data_size = 0; + int res = 0; + int de_temp_len = 0; + int len = 0; + + char *de_temp = (char *)malloc(sizeof(char) * TEMP_BUFFER_SIZE); /* todo : temporary */ + if (de_temp == NULL) { + _DEBUG_ERROR("[encoding_util] malloc error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + return 0; + } + + while ((start_decoding = strstr(src, "ENCODING="))) { + char *colon_loc = strstr(start_decoding, colon); /* find ':''s location */ + char *line_breaker_loc = NULL; + if (colon_loc != NULL) { + line_breaker_loc = strstr(colon_loc, line_breaker); /* find "\r\n"'s location */ + } else { + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + return 0; + } + + /* + * if find "ENCODING=" do strcat data until ":" to de_src + */ + data_size = (colon_loc + 1) - src; /* colon_loc + 1 ==> Until next character of ':' */ + + char *temp = (char *)malloc(sizeof(char) * (data_size + 1)); + if (temp == NULL) { + _DEBUG_ERROR("temp is null"); + if (*de_src != NULL) + free(*de_src); + + /* for prevent */ + if (de_temp != NULL) + free(de_temp); + + return 0; + } + memset(temp, 0x00, sizeof(char) * (data_size + 1)); + memcpy(temp, src, data_size); + + len = g_strlcat(*de_src, temp, (src_len + 1)); + if (len >= (src_len + 1)) { + _DEBUG_ERROR("*de_src buffer overflow !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + if (temp != NULL) + free(temp); + + return 0; + } + + if (temp != NULL) + free(temp); + + _DEBUG_INFO("[encoding_util] << *de_src >> \n %s\n", *de_src); + + /* + * copy data from ":" until "\r\n"(actual encoding stream) + */ + data_size = line_breaker_loc - colon_loc; /* from ':' until "\r\n" + '\0' */ + char *value = (char *)malloc(sizeof(char) * (data_size + 1)); + if (value == NULL) { + _DEBUG_ERROR("[encoding_util] malloc error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + memset(value, 0x00, sizeof(char) * (data_size + 1)); + memcpy(value, ++colon_loc, data_size); /* from ':' until "\r\n" */ + value[data_size] = '\0'; + + /* + * Get encoding type using data from "ENCODING=" to ":" + */ + char type_check[TYPE_CHECK_BUF_SIZE] = { 0, }; + int type_check_size = colon_loc - start_decoding; + strncpy(type_check, start_decoding, type_check_size); + _DEBUG_INFO("[encoding_util] type check : %s\n", type_check); + encoding_type_e type = find_encoding_type((const char *)type_check); + + /* + * Process decoding by passing the actual value and encoding type to decode_value() + */ + de_temp_len = 0; + memset(de_temp, 0x00, sizeof(char) * TEMP_BUFFER_SIZE); /* todo : temporary */ + + res = decode_value(type, value, data_size, &de_temp, &de_temp_len); + + if (res != 1) { + _DEBUG_ERROR("[encoding_util] decode_value error !!\n"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + if (value != NULL) + free(value); + + return 0; + } + + /* + * Append decoded data to de_src + */ + _DEBUG_INFO("[encoding_util] de_temp : %s\n", de_temp); + len = 0; + len = g_strlcat(*de_src, de_temp, (src_len + 1)); + if (len >= (src_len + 1)) { + _DEBUG_ERROR("*de_src buffer overflow !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + if (value != NULL) + free(value); + + return 0; + } + + /* + * find "ENCODING=" since "\r\n" agina + */ + src = line_breaker_loc; + + if (value != NULL) + free(value); + } + + /* Append remain character */ + len = 0; + len = g_strlcat(*de_src, src, (src_len + 1)); + if (len >= (src_len + 1)) { + _DEBUG_ERROR("*de_src buffer overflow !!"); + + if (*de_src != NULL) + free(*de_src); + + if (de_temp != NULL) + free(de_temp); + + return 0; + } + + *de_src_len = strlen(*de_src); + _DEBUG_INFO("[encoding_util] changed src : \n%s ( %d ) \n", *de_src, *de_src_len); + + if (de_temp != NULL) + free(de_temp); + + _EXTERN_FUNC_EXIT; + return 1; +} + +int check_encoding_data(const char *data) +{ + _EXTERN_FUNC_ENTER; + + if (strstr(data, "ENCODING=") != NULL) { + _DEBUG_INFO("[encoding_util] exist encoding data !! \n"); + _EXTERN_FUNC_EXIT; + return 1; + } else { + _DEBUG_INFO("[encoding_util] not exist encoding data !! \n"); + _EXTERN_FUNC_EXIT; + return 0; + } +} + +encoding_type_e find_encoding_type(const char *data) +{ + _EXTERN_FUNC_ENTER; + + encoding_type_e type = EN_TYPE_NONE; + if (strstr(data, "QUOTED-PRINTABLE") != NULL) { + _DEBUG_INFO("[encoding_util] type : QP\n"); + type = EN_TYPE_QUOTED_PRINTABLE; + } else if (strstr(data, "BASE64") != NULL) { + _DEBUG_INFO("[encoding_util] type : BASE64\n"); + type = EN_TYPE_BASE64; + } else { + _DEBUG_INFO("[encoding_util] not supported type !! \n"); + } + + _EXTERN_FUNC_EXIT; + return type; +} + +int decode_value(encoding_type_e type, const char *value, int value_size, char **decode_str, int *decode_str_len) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(value == NULL, 0, "[encoding_util] value is NULL\n"); + + int res = 1; + const char *start_pos = NULL; + const char *cursor = NULL; + int semi_cnt = 0; + int len = 0; + + /* + * ex> value - =EA=B9=80;=EC=B2=A0=EC=88=98;;;\0 + */ + cursor = value; + start_pos = value; + + while (*cursor != '\0') { + if ((*cursor != ';') && (*cursor != '\r')) { + cursor++; + continue; + } else if (*cursor == ';') { + semi_cnt++; + } + + int data_size = 0; + data_size = cursor - start_pos; + + if (data_size == 0) { + cursor++; + start_pos++; + } else { + char *temp = (char *)malloc(sizeof(char) * (value_size + 1)); + if (temp == NULL) { + _DEBUG_ERROR("MALLOC failed !!!"); + res = 0; + return res; + } + memset(temp, 0x00, sizeof(char) * (value_size + 1)); + memcpy(temp, start_pos, data_size); + + _DEBUG_INFO("[encoding_util] temp : %s \n", temp); + + char *decoding = NULL; + int decoding_len = 0; + + switch (type) { + case EN_TYPE_QUOTED_PRINTABLE: + res = decode_qp(temp, data_size, &decoding, &decoding_len); + break; + case EN_TYPE_BASE64: + res = decode_base64(temp, data_size, &decoding, &decoding_len); + break; + default: + break; + } + + if (temp != NULL) + free(temp); + + _DEBUG_INFO("[encoding_util] decoding : %s ( %d )\n", decoding, decoding_len); + + if (res != 1) { + _DEBUG_ERROR("[encoding_util] decoding error !! \n"); + + if (decoding != NULL) + free(decoding); + + res = 0; + return res; + } + + len = g_strlcat(*decode_str, decoding, TEMP_BUFFER_SIZE); + if (len >= TEMP_BUFFER_SIZE) { + _DEBUG_ERROR("*decode_str buffer overflow !!"); + + if (decoding != NULL) + free(decoding); + + res = 0; + return res; + } + + _DEBUG_INFO("[encoding_util] *decode_str : %s\n", *decode_str); + + if (decoding != NULL) + free(decoding); + + cursor++; + start_pos = cursor; + } + + if (semi_cnt > 0) { + int len = strlen(*decode_str); + (*decode_str)[len] = ';'; + _DEBUG_INFO("[encoding_util] *decode_str : %s ( %d )\n", *decode_str, strlen(*decode_str)); + semi_cnt--; + } + } + + *decode_str_len = strlen(*decode_str); + + _DEBUG_INFO("[encoding_util] *decode_str : %s ( %d )\n", *decode_str, *decode_str_len); + + _EXTERN_FUNC_EXIT; + return res; +} + +static int _find_base(char ch) +{ + _EXTERN_FUNC_ENTER; + + int i = 0; + for (i = 0; i < 65; i++) { + if (base64_table[i] == ch) { + _DEBUG_INFO("[encoding_util] End !! \n"); + return i; + } + } + + _EXTERN_FUNC_EXIT; + return -1; +} diff --git a/src/plugins/ds-public/xcalllog/src/plugin_interface.c b/src/plugins/ds-public/xcalllog/src/plugin_interface.c new file mode 100755 index 0000000..3ba4c05 --- /dev/null +++ b/src/plugins/ds-public/xcalllog/src/plugin_interface.c @@ -0,0 +1,432 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include +#include +#include +#include + +#include + +#include "plugin_spec.h" +#include "encoding_util.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__ ((visibility("default"))) +#endif + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "PLUGIN_XCALLLOG" +#endif + +static char *_convert_key_name(int key); +static sync_agent_da_return_e _convert_service_error_to_common_error(contacts_error_e err); + +static char *_convert_calllog_type(int type); +static char *_convert_date(int date); +static sync_agent_da_return_e _get_calllog_name(int contact_id, char **name); + +static char *_calllog_put_content(char *vcard_stream, char *content_type, char *content_value); + +static char *_convert_key_name(int key) +{ + _INNER_FUNC_ENTER; + + char *key_name = 0; + + switch (key) { + case XCALLLOG_CONTENT_FN: + key_name = "FN"; + break; + case XCALLLOG_CONTENT_X_NUMBER: + key_name = "X-NUMBER"; + break; + case XCALLLOG_CONTENT_X_DATE: + key_name = "X-DATE"; + break; + case XCALLLOG_CONTENT_X_DURATION: + key_name = "X-DURATION"; + break; + case XCALLLOG_CONTENT_X_CALLTYPE: + key_name = "X-CALLTYPE"; + break; + default: + break; + } + + _INNER_FUNC_EXIT; + return key_name; +} + +static sync_agent_da_return_e _convert_service_error_to_common_error(contacts_error_e err) +{ + _INNER_FUNC_ENTER; + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + _DEBUG_TRACE("[da_contact_plugIn] Error Code : %d\n", err); + + switch (err) { + case CONTACTS_ERROR_NONE: + ret = SYNC_AGENT_DA_SUCCESS; + break; + case CONTACTS_ERROR_OUT_OF_MEMORY: + ret = SYNC_AGENT_DA_ERR_MEMORY_FULL; + break; + case CONTACTS_ERROR_INVALID_PARAMETER: + ret = SYNC_AGENT_DA_ERR_INVALID_PARAMETER; + break; + case CONTACTS_ERROR_NO_DATA: + ret = SYNC_AGENT_DA_ERR_NO_DATA; + break; + case CONTACTS_ERROR_DB: + ret = SYNC_AGENT_DA_ERR_SERVICE_DB; + break; + case CONTACTS_ERROR_IPC: + ret = SYNC_AGENT_DA_ERR_SERVICE_IPC; + break; + default: + ret = SYNC_AGENT_DA_ERRORS; + break; + } + + _INNER_FUNC_EXIT; + + return ret; +} + +static char *_convert_calllog_type(int type) +{ + _INNER_FUNC_ENTER; + + char *log_type = NULL; + + switch (type) { + case 1: /*CTS_PLOG_TYPE_VOICE_INCOMMING */ + case 3: /*CTS_PLOG_TYPE_VIDEO_INCOMMING */ + log_type = "1"; + break; + case 2: /*CTS_PLOG_TYPE_VOICE_OUTGOING */ + case 4: /*CTS_PLOG_TYPE_VIDEO_OUTGOING */ + log_type = "2"; + break; + case 5: /*CTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN */ + case 6: /*CTS_PLOG_TYPE_VOICE_INCOMMING_SEEN */ + case 7: /*CTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN */ + case 8: /*CTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN */ + log_type = "3"; + break; + } + + _INNER_FUNC_EXIT; + return log_type; +} + +static char *_convert_date(int time) +{ + _INNER_FUNC_ENTER; + + char *date = (char *)calloc(17, sizeof(char)); + if (date == NULL) { + _DEBUG_ERROR("CALLOC failed !!!"); + return NULL; + } + + struct tm *tm = localtime((time_t *) & time); + + memset(date, 0, 17); + + snprintf(date, 17, "%04ld%02d%02dT%02d%02d%02dZ", tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); + + _INNER_FUNC_EXIT; + return date; +} + +static sync_agent_da_return_e _get_calllog_name(int contact_id, char **name) +{ + _INNER_FUNC_ENTER; + +// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; +// cts_error err = 0; +// CTSstruct *item = 0; +// CTSvalue *value = NULL; +// char *first_name = NULL; +// char *last_name = NULL; +// +// if (contact_id != 0) { +// err = contacts_svc_get_contact(contact_id, &item); +// if (err < CTS_SUCCESS) { +// _DEBUG_ERROR("[da_xcalllog_plugIn] contacts_svc_get_contact() Fail!\n"); +// ret = _convert_service_error_to_common_error(err); +// *name = 0; +// } else { +// _DEBUG_TRACE("[da_xcalllog_plugIn] contacts_svc_get_contact() Success!\n"); +// +// contacts_svc_struct_get_value(item, CTS_CF_NAME_VALUE, &value); +// first_name = (char *)contacts_svc_value_get_str(value, CTS_NAME_VAL_FIRST_STR); +// _DEBUG_TRACE("name = %s", first_name); +// +// last_name = (char *)contacts_svc_value_get_str(value, CTS_NAME_VAL_LAST_STR); +// _DEBUG_TRACE("name = %s", last_name); +// *name = g_strdup_printf("%s %s", first_name, last_name); +// } +// } else +// name = 0; + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = NULL; + + if (contact_id != 0) { + err = contacts_db_get_record(_contacts_person_phone_log._uri, contact_id, &record); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[da_xcalllog_plugIn] contacts_db_get_record() Fail!\n"); + ret = _convert_service_error_to_common_error(err); + *name = 0; + } else { + _DEBUG_TRACE("[da_xcalllog_plugIn] contacts_db_get_record() Success!\n"); + + err = contacts_record_get_str(record, _contacts_person_phone_log.display_name, name); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[da_xcalllog_plugIn] contacts_db_get_record() Fail!\n"); + ret = _convert_service_error_to_common_error(err); + *name = 0; + } + } + } else + name = 0; + + _INNER_FUNC_EXIT; + return ret; +} + +static char *_calllog_put_content(char *vcard_stream, char *content_type, char *content_value) +{ + _INNER_FUNC_ENTER; + + retvm_if(vcard_stream == NULL, NULL, "vcard_stream is NULL\n"); + retvm_if(content_type == NULL, NULL, "content_type is NULL\n"); + retvm_if(content_value == NULL, NULL, "content_value is NULL\n"); + + char *new_stream = NULL; + + new_stream = g_strdup_printf("%s%s:%s\r\n", vcard_stream, content_type, content_value); + + _DEBUG_TRACE("old stream =%s", vcard_stream); + _DEBUG_TRACE("new stream =%s", new_stream); + + free(vcard_stream); + + _INNER_FUNC_EXIT; + return new_stream; +} + +EXPORT_API void *sync_agent_plugin_alloc_object() +{ + _EXTERN_FUNC_ENTER; + + char *agent_data = strdup("BEGIN:CALLLOG\r\n\ +"); + + _EXTERN_FUNC_EXIT; + return (void *)agent_data; +} + +EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *extension_key, void *value) +{ + _EXTERN_FUNC_ENTER; + + char *new_agent_data = 0; + char *key_name = 0; + + if (key == XCALLLOG_CONTENT_NO_TYPE) + return (void *)new_agent_data; + else if (key == XCALLLOG_CONTENT_EXTENSION) + key_name = extension_key; + else + key_name = _convert_key_name(key); + + new_agent_data = _calllog_put_content(in_object, key_name, value); + + _EXTERN_FUNC_EXIT; + return (void *)new_agent_data; +} + +EXPORT_API int sync_agent_plugin_free_object(void *in_object) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("[dc_xcalllog_plugIn] Do nothing\n"); + + _EXTERN_FUNC_EXIT; + return 1; +} + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_reverse_converter(void *service_data, void **agent_data) +{ + _EXTERN_FUNC_ENTER; + +// retvm_if(service_data == NULL, SYNC_AGENT_DA_ERRORS, "service_data is NULL"); +// +// sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; +// CTSvalue *plog = (CTSvalue *) service_data; +// +// void *data = NULL; +// char *duration = NULL; +// char *log_type = NULL; +// char *name = NULL; +// char *date = NULL; +// +// /*date */ +// date = _convert_date(contacts_svc_value_get_int(plog, CTS_PLOG_VAL_LOG_TIME_INT)); +// if( date == NULL ) +// return SYNC_AGENT_DA_ERRORS; +// +// /*duration */ +// duration = g_strdup_printf("%d", contacts_svc_value_get_int(plog, CTS_PLOG_VAL_DURATION_INT)); +// +// /* type */ +// log_type = _convert_calllog_type(contacts_svc_value_get_int(plog, CTS_PLOG_VAL_LOG_TYPE_INT)); +// +// /*name */ +// ret = _get_calllog_name(contacts_svc_value_get_int(plog, CTS_PLOG_VAL_RELATED_ID_INT), &name); +// +// /*create default object */ +// data = sync_agent_alloc_object_plugin(); +// +// data = sync_agent_set_value_plugin(data, XCALLLOG_CONTENT_X_NUMBER, NULL, (void *)contacts_svc_value_get_str(plog, CTS_PLOG_VAL_NUMBER_STR)); +// data = sync_agent_set_value_plugin(data, XCALLLOG_CONTENT_X_DATE, NULL, (void *)date); +// data = sync_agent_set_value_plugin(data, XCALLLOG_CONTENT_X_DURATION, NULL, (void *)duration); +// +// if (name != NULL) +// data = sync_agent_set_value_plugin(data, XCALLLOG_CONTENT_FN, NULL, name); +// +// data = sync_agent_set_value_plugin(data, XCALLLOG_CONTENT_X_CALLTYPE, NULL, log_type); +// +// *agent_data = g_strdup_printf("%sEND:CALLLOG", (char *)data); +// +// if (data != NULL) +// free(data); +// +// if (duration != NULL) +// free(duration); +// +// if (name != NULL) +// free(name); +// +// if (date != NULL) { +// free(date); +// } + + retvm_if(service_data == NULL, SYNC_AGENT_DA_ERRORS, "service_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + contacts_error_e err = CONTACTS_ERROR_NONE; + contacts_record_h record = (contacts_record_h) service_data; + + void *data = NULL; + char *duration = NULL; + char *log_type = NULL; + char *name = NULL; + char *date = NULL; + + int log_time; + int temp_duration; + int temp_log_type; + int person_id; + char *number = NULL; + + err = contacts_record_get_int(record, _contacts_phone_log.log_time, &log_time); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_xcalllog_plugIn] contacts_record_get_int is failed"); + ret = _convert_service_error_to_common_error(err); + goto error; + } + + err = contacts_record_get_int(record, _contacts_phone_log.extra_data1, &temp_duration); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_xcalllog_plugIn] contacts_record_get_int is failed"); + ret = _convert_service_error_to_common_error(err); + goto error; + } + + err = contacts_record_get_int(record, _contacts_phone_log.log_type, &temp_log_type); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_xcalllog_plugIn] contacts_record_get_int is failed"); + ret = _convert_service_error_to_common_error(err); + goto error; + } + + err = contacts_record_get_int(record, _contacts_phone_log.person_id, &person_id); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_xcalllog_plugIn] contacts_record_get_int is failed"); + ret = _convert_service_error_to_common_error(err); + goto error; + } + + err = contacts_record_get_str_p(record, _contacts_phone_log.address, &number); + if (err != CONTACTS_ERROR_NONE) { + _DEBUG_ERROR("[dc_xcalllog_plugIn] contacts_record_get_int is failed"); + ret = _convert_service_error_to_common_error(err); + goto error; + } + + /*date */ + date = _convert_date(log_time); + if (date == NULL) + return SYNC_AGENT_DA_ERRORS; + + /*duration */ + duration = g_strdup_printf("%d", temp_duration); + + /* type */ + log_type = _convert_calllog_type(temp_log_type); + + /*name */ + ret = _get_calllog_name(person_id, &name); + + /*create default object */ + data = sync_agent_plugin_alloc_object(); + + data = sync_agent_plugin_set_value(data, XCALLLOG_CONTENT_X_NUMBER, NULL, (void *)number); + data = sync_agent_plugin_set_value(data, XCALLLOG_CONTENT_X_DATE, NULL, (void *)date); + data = sync_agent_plugin_set_value(data, XCALLLOG_CONTENT_X_DURATION, NULL, (void *)duration); + + if (name != NULL) + data = sync_agent_plugin_set_value(data, XCALLLOG_CONTENT_FN, NULL, name); + + data = sync_agent_plugin_set_value(data, XCALLLOG_CONTENT_X_CALLTYPE, NULL, log_type); + + *agent_data = g_strdup_printf("%sEND:CALLLOG", (char *)data); + + error: + + if (data != NULL) + free(data); + + if (duration != NULL) + free(duration); + + if (name != NULL) + free(name); + + if (date != NULL) { + free(date); + } + + _EXTERN_FUNC_EXIT; + return ret; +} diff --git a/test/include/suites/unit_test_sample_suite.h b/test/include/suites/unit_test_sample_suite.h new file mode 100755 index 0000000..1f4d857 --- /dev/null +++ b/test/include/suites/unit_test_sample_suite.h @@ -0,0 +1,25 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#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 100755 index 0000000..6ac25f2 --- /dev/null +++ b/test/include/unit_test_common.h @@ -0,0 +1,26 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef UNIT_TEST_COMMON_H_ +#define UNIT_TEST_COMMON_H_ + +#include +#include +#include +#include + +#endif /* UNIT_TEST_COMMON_H_ */ diff --git a/test/include/unit_test_run.h b/test/include/unit_test_run.h new file mode 100755 index 0000000..3f22e23 --- /dev/null +++ b/test/include/unit_test_run.h @@ -0,0 +1,32 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#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 100755 index 0000000..1897534 --- /dev/null +++ b/test/include/unit_test_suites.h @@ -0,0 +1,30 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#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 100755 index 0000000..894cc37 --- /dev/null +++ b/test/src/oma_test_main.c @@ -0,0 +1,24 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#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 100755 index 0000000..348241e --- /dev/null +++ b/test/src/suites/unit_test_sample_suite.c @@ -0,0 +1,63 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#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 100755 index 0000000..6a07e4c --- /dev/null +++ b/test/src/unit_test_run.c @@ -0,0 +1,131 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#include "unit_test_common.h" +#include "unit_test_run.h" +#include "unit_test_suites.h" +#include +#include +#include + +/* 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, "%s\n", "invalid suite function"); + } + } + } + + /* 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, "%s\n", "Error in call to fork"); + 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, "%s\n", "test finished successfully"); + return 1; /* test finished */ + } else { + fprintf(stderr, "%s\n", "test failed"); + 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; +} -- 2.7.4