summaryrefslogtreecommitdiff
path: root/src/agent/service-adapter
diff options
context:
space:
mode:
Diffstat (limited to 'src/agent/service-adapter')
-rwxr-xr-xsrc/agent/service-adapter/network-binder/na_binder.c142
-rwxr-xr-xsrc/agent/service-adapter/protocol-binder/oma_ds_protocol_binder.c5256
-rwxr-xr-xsrc/agent/service-adapter/sa_command.c1016
-rwxr-xr-xsrc/agent/service-adapter/sa_common_interface.c2812
-rwxr-xr-xsrc/agent/service-adapter/sa_devinf.c1069
-rwxr-xr-xsrc/agent/service-adapter/sa_elements.c834
-rwxr-xr-xsrc/agent/service-adapter/sa_session.c1578
-rwxr-xr-xsrc/agent/service-adapter/sa_util.c177
8 files changed, 12884 insertions, 0 deletions
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 <sync_agent.h>
+
+#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 <glib.h>
+
+#include <sync_agent.h>
+
+#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, &paramname);
+ 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 <stdlib.h>
+
+#include <sync_agent.h>
+
+#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 <sync_agent.h>
+
+#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 <sync_agent.h>
+
+#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 <sync_agent.h>
+
+#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 <sync_agent.h>
+
+#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 <sync_agent.h>
+
+#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;
+}