3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <wbxml/wbxml.h>
20 #include "utility/sync_util.h"
22 #include "protocol-binder/interface.h"
23 #include "device-manager/mo_accessor_internal.h"
24 #include "device-manager/mo_accessor.h"
26 #include "device-manager/mo_tnds_processor.h"
28 #ifndef SYNC_AGENT_LOG
30 #define LOG_TAG "AF_MO"
34 sync_agent_dm_tnds_action_e tnds_action;
35 sync_agent_dm_mo_type_e mo_type;
37 } dm_tnds_binder_data_s;
39 static WBXMLTreeNode *__construct_TNDS_NODE(sync_agent_dm_mo_node_s * mo_node, sync_agent_pb_protocol_binder_info_s * pBinder, WBXMLTreeNode * ppWbxml_parent_node);
40 static WBXMLTreeNode *__recursive_contruct_TNDS(sync_agent_dm_mo_node_s * mo_parent_node, sync_agent_pb_protocol_binder_info_s * pBinder, WBXMLTreeNode * ppWbxml_parent_node);
41 static void __recursive_contruct_MO_TABLE(sync_agent_dm_tnds_action_e tnds_action, sync_agent_dm_mo_type_e mo_type, char *mo_parent_path, WBXMLTreeNode * pWbxml_dom_node);
43 static sync_agent_pb_error_e _mgmttree_start_converter_function(sync_agent_pb_protocol_binder_info_s * pBinder, Content_Ptr pContent, WBXMLTreeNode ** ppWbxml_dom_node);
44 static sync_agent_pb_error_e _verdtd_converter_function(sync_agent_pb_protocol_binder_info_s * pBinder, Content_Ptr pContent, WBXMLTreeNode ** ppWbxml_dom_node);
45 static sync_agent_pb_error_e _node_start_converter_function(sync_agent_pb_protocol_binder_info_s * pBinder, Content_Ptr pContent, WBXMLTreeNode ** ppWbxml_dom_node);
46 static sync_agent_pb_error_e _node_start_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * pReverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * pContent);
48 const sync_agent_pb_function_info_s tnds_binder_function_info[] = {
49 {DM_TNDS_TAG_MGMTTREE_START, "MgmtTree", _mgmttree_start_converter_function, NULL, false},
50 {DM_TNDS_TAG_MGMTTREE_END, "/MgmtTree", NULL, NULL, false},
51 {DM_TNDS_TAG_VERDTD, "VerDTD", _verdtd_converter_function, NULL, true},
52 {DM_TNDS_TAG_NODE_START, "Node", _node_start_converter_function, _node_start_reverse_converter_function, false},
53 {DM_TNDS_TAG_NODE_END, "/Node", NULL, NULL, false}
56 sync_agent_dm_mo_error_e dm_get_tnds_from_db(sync_agent_dm_tnds_type_e tnds_type, sync_agent_dm_mo_node_s * root_node, char **output_tnds, unsigned int *byte_size)
60 retvm_if(root_node == NULL, SYNC_AGENT_DM_MO_FAIL, "sync_agent_dm_mo_node_s is NULL !!");
62 sync_agent_dm_mo_error_e mo_error = SYNC_AGENT_DM_MO_SUCCESS;
64 sync_agent_pb_protocol_binder_function_set_s *pBinder_function_set = NULL;
65 sync_agent_pb_error_e pb_error = sync_agent_init_binder_function_set(sizeof(tnds_binder_function_info) / sizeof(sync_agent_pb_function_info_s),
66 (sync_agent_pb_function_info_s *) tnds_binder_function_info, &pBinder_function_set);
68 if (pb_error != SYNC_AGENT_PB_RETURN_OK) {
69 _DEBUG_ERROR("Failed to sync_agent_init_binder_function_set()");
70 return SYNC_AGENT_DM_MO_FAIL;
73 /* protocol binder initialization */
74 sync_agent_pb_protocol_binder_info_s *pBinder = NULL;
76 case SYNC_AGENT_DM_MO_TNDS_TYPE_XML:
78 pBinder = sync_agent_init_protocol_binder(NULL, SYNC_AGENT_PB_PROTOCOL_SYNCML_DMDDF12, NULL, SYNC_AGENT_PB_ENCODING_XML, false, false, false, false, false, NULL, NULL, pBinder_function_set);
81 case SYNC_AGENT_DM_MO_TNDS_TYPE_WBXML:
83 pBinder = sync_agent_init_protocol_binder(NULL, SYNC_AGENT_PB_PROTOCOL_SYNCML_DMDDF12, NULL, SYNC_AGENT_PB_ENCODING_WBXML_13, false, false, false, false, false, NULL, NULL, pBinder_function_set);
87 _DEBUG_ERROR("TNDS TYPE [%d], Framework could not support!!", tnds_type);
91 pb_error = sync_agent_append_element(pBinder, DM_TNDS_TAG_MGMTTREE_START, NULL);
93 pb_error = sync_agent_append_element(pBinder, DM_TNDS_TAG_VERDTD, NULL);
95 pb_error = sync_agent_append_element(pBinder, DM_TNDS_TAG_NODE_START, root_node);
96 pb_error = sync_agent_append_element(pBinder, DM_TNDS_TAG_NODE_END, NULL);
98 pb_error = sync_agent_append_element(pBinder, DM_TNDS_TAG_MGMTTREE_END, NULL);
100 pb_error = sync_agent_get_stream_from_protocol_binder(pBinder, output_tnds, byte_size);
103 unsigned int xml_size = 0;
104 pb_error = sync_agent_get_xml_from_protocol_binder(pBinder, &xml, &xml_size);
106 fprintf(stderr, "xmlsize = %d, xml =\n%s\n", xml_size, xml);
108 sync_agent_destroy_protocol_binder(pBinder);
115 sync_agent_dm_mo_error_e dm_insert_tnds_to_db(sync_agent_dm_tnds_action_e tnds_action, sync_agent_dm_tnds_type_e tnds_type, sync_agent_dm_mo_type_e mo_type, const char *mo_full_path, char *input_stream, unsigned int byte_size)
119 retvm_if(mo_full_path == NULL, SYNC_AGENT_DM_MO_FAIL, "mo_full_path is NULL !!");
121 sync_agent_pb_protocol_binder_function_set_s *pBinder_function_set = NULL;
122 sync_agent_pb_error_e pb_error = sync_agent_init_binder_function_set(sizeof(tnds_binder_function_info) / sizeof(sync_agent_pb_function_info_s),
123 (sync_agent_pb_function_info_s *) tnds_binder_function_info, &pBinder_function_set);
125 if (pb_error != SYNC_AGENT_PB_RETURN_OK) {
126 _DEBUG_ERROR("Failed to sync_agent_init_binder_function_set()");
127 return SYNC_AGENT_DM_MO_FAIL;
131 * reverse protocol binder initialization
133 sync_agent_pb_protocol_e protocol = SYNC_AGENT_PB_PROTOCOL_UNKNOWN;
134 sync_agent_pb_protocol_binder_reverse_info_s *pBinder = NULL;
135 dm_tnds_binder_data_s binder_data;
136 binder_data.tnds_action = tnds_action;
137 binder_data.mo_full_path = (char *)mo_full_path;
138 binder_data.mo_type = mo_type;
141 case SYNC_AGENT_DM_MO_TNDS_TYPE_XML:
143 pb_error = sync_agent_init_reverse_protocol_binder(input_stream, byte_size, SYNC_AGENT_PB_DECODING_XML, &protocol, pBinder_function_set, &binder_data, &pBinder);
146 case SYNC_AGENT_DM_MO_TNDS_TYPE_WBXML:
148 pb_error = sync_agent_init_reverse_protocol_binder(input_stream, byte_size, SYNC_AGENT_PB_DECODING_WBXML, &protocol, pBinder_function_set, NULL, &pBinder);
152 _DEBUG_ERROR("TNDS TYPE [%d], Framework could not support!!", tnds_type);
156 if (pb_error != SYNC_AGENT_PB_RETURN_OK) {
157 _DEBUG_ERROR("Failed to sync_agent_init_reverse_protocol_binder()");
158 sync_agent_destroy_reverse_protocol_binder(pBinder);
159 return SYNC_AGENT_DM_MO_FAIL;
162 if (protocol != SYNC_AGENT_PB_PROTOCOL_SYNCML_DMDDF12) {
163 _DEBUG_ERROR("Failed to sync_agent_init_reverse_protocol_binder()");
164 sync_agent_destroy_reverse_protocol_binder(pBinder);
165 return SYNC_AGENT_DM_MO_FAIL;
168 Protocol_Element protocol_element;
169 char *protocol_element_name = NULL;
170 Content_Ptr content = NULL;
172 pb_error = sync_agent_next_element(pBinder, &protocol_element, &protocol_element_name, &content);
174 sync_agent_destroy_reverse_protocol_binder(pBinder);
176 if (pb_error != SYNC_AGENT_PB_RETURN_OK) {
177 _DEBUG_ERROR("Failed to sync_agent_next_element()");
178 sync_agent_destroy_reverse_protocol_binder(pBinder);
179 return SYNC_AGENT_DM_MO_FAIL;
184 return SYNC_AGENT_DM_MO_SUCCESS;
187 /**************************************** Impl static function *******************************************/
189 static WBXMLTreeNode *__construct_TNDS_NODE(sync_agent_dm_mo_node_s * mo_node, sync_agent_pb_protocol_binder_info_s * pBinder, WBXMLTreeNode * ppWbxml_parent_node)
193 retvm_if(mo_node == NULL, NULL, "sync_agent_dm_mo_node_s is NULL !!");
194 retvm_if(pBinder == NULL, NULL, "sync_agent_pb_protocol_binder_info_s is NULL !!");
196 WBXMLTreeNode *node_node = NULL;
198 if (ppWbxml_parent_node == NULL) {
199 node_node = sync_agent_create_node(pBinder, DM_TNDS_ELEMENT_NODE);
201 node_node = sync_agent_add_child_node(pBinder, ppWbxml_parent_node, DM_TNDS_ELEMENT_NODE);
204 if (node_node == NULL) {
208 sync_agent_add_child_text_node(pBinder, node_node, DM_TNDS_ELEMENT_NODENAME, mo_node->name, strlen(mo_node->name));
210 WBXMLTreeNode *rtproperties_node = sync_agent_add_child_node(pBinder, node_node, DM_TNDS_ELEMENT_RTPROPERTIES);
212 sync_agent_dm_mo_runtime_property_s *runtime_property = mo_node->runtime_property;
213 if (runtime_property != NULL) {
215 if (runtime_property->acl != NULL) {
216 acl_len = strlen(runtime_property->acl);
218 sync_agent_add_child_text_node(pBinder, rtproperties_node, DM_TNDS_ELEMENT_ACL, runtime_property->acl, acl_len);
220 WBXMLTreeNode *format_node = sync_agent_add_child_node(pBinder, rtproperties_node, DM_TNDS_ELEMENT_FORMAT);
221 switch (runtime_property->format) {
222 case SYNC_AGENT_DM_MO_FORMAT_B64:
223 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_B64);
225 case SYNC_AGENT_DM_MO_FORMAT_BIN:
226 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_BIN);
228 case SYNC_AGENT_DM_MO_FORMAT_BOOL:
229 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_BOOL);
231 case SYNC_AGENT_DM_MO_FORMAT_CHR:
232 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_CHR);
234 case SYNC_AGENT_DM_MO_FORMAT_INT:
235 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_INT);
237 case SYNC_AGENT_DM_MO_FORMAT_NODE:
238 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_NODE);
240 case SYNC_AGENT_DM_MO_FORMAT_NULL:
241 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_NULL);
243 case SYNC_AGENT_DM_MO_FORMAT_XML:
244 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_XML);
246 case SYNC_AGENT_DM_MO_FORMAT_DATE:
247 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_DATE);
249 case SYNC_AGENT_DM_MO_FORMAT_TIME:
250 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_TIME);
252 case SYNC_AGENT_DM_MO_FORMAT_FLOAT:
253 sync_agent_add_child_node(pBinder, format_node, DM_TNDS_ELEMENT_FORMAT_FLOAT);
260 if (runtime_property->title != NULL) {
261 title_len = strlen(runtime_property->title);
263 sync_agent_add_child_text_node(pBinder, rtproperties_node, DM_TNDS_ELEMENT_TITLE, runtime_property->title, title_len);
266 if (runtime_property->tStamp != NULL) {
267 tstamp_len = strlen(runtime_property->tStamp);
269 sync_agent_add_child_text_node(pBinder, rtproperties_node, DM_TNDS_ELEMENT_TSTAMP, runtime_property->tStamp, tstamp_len);
271 WBXMLTreeNode *type_node = sync_agent_add_child_node(pBinder, rtproperties_node, DM_TNDS_ELEMENT_TYPE);
273 if (runtime_property->type_value != NULL) {
274 value_len = strlen(runtime_property->type_value);
276 switch (runtime_property->type) {
277 case SYNC_AGENT_DM_MO_DF_TYPE_MIME:
278 sync_agent_add_child_text_node(pBinder, type_node, DM_TNDS_ELEMENT_TYPE_MIME, runtime_property->type_value, value_len);
280 case SYNC_AGENT_DM_MO_DF_TYPE_DDFNAME:
281 sync_agent_add_child_text_node(pBinder, type_node, DM_TNDS_ELEMENT_TYPE_DDFNAME, runtime_property->type_value, value_len);
288 if (runtime_property->verNo != NULL) {
289 verno_len = strlen(runtime_property->verNo);
291 sync_agent_add_child_text_node(pBinder, rtproperties_node, DM_TNDS_ELEMENT_VERNO, runtime_property->verNo, verno_len);
294 if (mo_node->type == SYNC_AGENT_DM_MO_NODE_LEAF) {
296 if (mo_node->value != NULL) {
297 value_len = strlen(mo_node->value);
299 sync_agent_add_child_text_node(pBinder, node_node, DM_TNDS_ELEMENT_VALUE, mo_node->value, value_len);
307 static WBXMLTreeNode *__recursive_contruct_TNDS(sync_agent_dm_mo_node_s * mo_parent_node, sync_agent_pb_protocol_binder_info_s * pBinder, WBXMLTreeNode * ppWbxml_parent_node)
311 retvm_if(mo_parent_node == NULL, NULL, "sync_agent_dm_mo_node_s is NULL !!");
312 retvm_if(pBinder == NULL, NULL, "sync_agent_pb_protocol_binder_info_s is NULL !!");
315 _DEBUG_VERBOSE("%d", mo_parent_node->child_node_cnt);
316 _DEBUG_VERBOSE("%s", mo_parent_node->name);
318 for (; i < mo_parent_node->child_node_cnt; i++) {
319 sync_agent_dm_mo_node_s *mo_node = &(mo_parent_node->child_node_list[i]);
320 _DEBUG_VERBOSE("[%d] mo_node->name : %s", i, mo_node->name);
322 WBXMLTreeNode *node_node = __construct_TNDS_NODE(mo_node, pBinder, ppWbxml_parent_node);
324 __recursive_contruct_TNDS(mo_node, pBinder, node_node);
332 static void __recursive_contruct_MO_TABLE(sync_agent_dm_tnds_action_e tnds_action, sync_agent_dm_mo_type_e mo_type, char *mo_parent_path, WBXMLTreeNode * wbxml_dom_node)
336 retm_if(mo_parent_path == NULL, "mo_parent_path is NULL !!");
337 retm_if(wbxml_dom_node == NULL, "WBXMLTreeNode is NULL !!");
339 WBXMLTreeNode *pCursor = wbxml_dom_node->children;
340 int hasChildNode = 0;
341 sync_agent_dm_mo_node_s mo_node;
342 sync_agent_dm_mo_runtime_property_s mo_runtime_property;
343 memset(&mo_node, 0x00, sizeof(sync_agent_dm_mo_node_s));
344 memset(&mo_runtime_property, 0x00, sizeof(sync_agent_dm_mo_runtime_property_s));
345 mo_node.runtime_property = &mo_runtime_property;
347 while (pCursor != NULL) {
348 if (pCursor->type == WBXML_TREE_ELEMENT_NODE) {
349 const char *tag_name = (const char *)wbxml_tag_get_xml_name(pCursor->name);
350 if (!strcmp(tag_name, DM_TNDS_ELEMENT_NODENAME)) {
351 char *node_name = NULL;
352 sync_agent_pb_error_e err_code = sync_agent_get_text_from_node(pCursor, &node_name);
353 if (err_code != SYNC_AGENT_PB_RETURN_OK) {
354 _DEBUG_ERROR("Failed to call sync_agent_get_text_from_node()");
357 mo_node.name = node_name;
359 * full_path = mo_parent_path + "/" + node_name
361 int full_path_length = strlen(mo_parent_path) + strlen("/") + strlen(node_name) + 1;
362 mo_node.full_path = (char *)calloc(full_path_length, sizeof(char));
364 if (mo_node.full_path != NULL) {
365 snprintf(mo_node.full_path, full_path_length, "%s/%s", mo_parent_path, node_name);
366 _DEBUG_VERBOSE("node_name : %s, full_path : %s", node_name, mo_node.full_path);
368 } else if (!strcmp(tag_name, DM_TNDS_ELEMENT_VALUE)) {
369 char *node_value = NULL;
370 sync_agent_pb_error_e err_code = sync_agent_get_text_from_node(pCursor, &node_value);
371 if (err_code != SYNC_AGENT_PB_RETURN_OK) {
372 _DEBUG_ERROR("Failed to call sync_agent_get_text_from_node()");
374 _DEBUG_VERBOSE("node_value : %s", node_value);
375 mo_node.value = node_value;
376 } else if (!strcmp(tag_name, DM_TNDS_ELEMENT_RTPROPERTIES)) {
377 sync_agent_pb_error_e err_code = SYNC_AGENT_PB_RETURN_OK;
378 WBXMLTreeNode *pCursor_rtproperties = pCursor->children;
379 while (pCursor_rtproperties != NULL) {
380 if (pCursor_rtproperties->type == WBXML_TREE_ELEMENT_NODE) {
381 const char *rtproperties_tag_name = (const char *)wbxml_tag_get_xml_name(pCursor_rtproperties->name);
382 if (!strcmp(rtproperties_tag_name, DM_TNDS_ELEMENT_ACL)) {
383 err_code = sync_agent_get_text_from_node(pCursor_rtproperties, &(mo_node.runtime_property->acl));
384 if (err_code != SYNC_AGENT_PB_RETURN_OK) {
385 _DEBUG_ERROR("Failed to call sync_agent_get_text_from_node()");
387 } else if (!strcmp(rtproperties_tag_name, DM_TNDS_ELEMENT_FORMAT)) {
388 WBXMLTreeNode *pCursor_format = pCursor_rtproperties->children;
389 while (pCursor_format != NULL) {
390 if (pCursor_format->type == WBXML_TREE_ELEMENT_NODE) {
391 const char *format_tag_name = (const char *)wbxml_tag_get_xml_name(pCursor_format->name);
392 if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_B64)) {
393 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_B64;
394 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_BIN)) {
395 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_BIN;
396 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_BOOL)) {
397 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_BOOL;
398 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_CHR)) {
399 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_CHR;
400 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_INT)) {
401 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_INT;
402 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_NODE)) {
403 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_NODE;
404 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_NULL)) {
405 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_NULL;
406 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_XML)) {
407 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_XML;
408 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_DATE)) {
409 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_DATE;
410 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_TIME)) {
411 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_TIME;
412 } else if (!strcmp(format_tag_name, DM_TNDS_ELEMENT_FORMAT_FLOAT)) {
413 mo_node.runtime_property->format = SYNC_AGENT_DM_MO_FORMAT_FLOAT;
417 pCursor_format = pCursor_format->next;
419 } else if (!strcmp(rtproperties_tag_name, DM_TNDS_ELEMENT_TITLE)) {
420 err_code = sync_agent_get_text_from_node(pCursor_rtproperties, &(mo_node.runtime_property->title));
421 if (err_code != SYNC_AGENT_PB_RETURN_OK) {
422 _DEBUG_ERROR("Failed to call sync_agent_get_text_from_node()");
424 } else if (!strcmp(rtproperties_tag_name, DM_TNDS_ELEMENT_TSTAMP)) {
425 err_code = sync_agent_get_text_from_node(pCursor_rtproperties, &(mo_node.runtime_property->tStamp));
426 if (err_code != SYNC_AGENT_PB_RETURN_OK) {
427 _DEBUG_ERROR("Failed to call sync_agent_get_text_from_node()");
429 } else if (!strcmp(rtproperties_tag_name, DM_TNDS_ELEMENT_TYPE)) {
430 WBXMLTreeNode *pCursor_type = pCursor_rtproperties->children;
431 while (pCursor_type != NULL) {
432 if (pCursor_type->type == WBXML_TREE_ELEMENT_NODE) {
433 const char *type_tag_name = (const char *)wbxml_tag_get_xml_name(pCursor_type->name);
434 if (!strcmp(type_tag_name, DM_TNDS_ELEMENT_TYPE_DDFNAME)) {
435 mo_node.runtime_property->type = SYNC_AGENT_DM_MO_DF_TYPE_DDFNAME;
436 } else if (!strcmp(type_tag_name, DM_TNDS_ELEMENT_TYPE_MIME)) {
437 mo_node.runtime_property->type = SYNC_AGENT_DM_MO_DF_TYPE_MIME;
439 err_code = sync_agent_get_text_from_node(pCursor_type, &(mo_node.runtime_property->type_value));
440 if (err_code != SYNC_AGENT_PB_RETURN_OK) {
441 _DEBUG_ERROR("Failed to call sync_agent_get_text_from_node()");
446 pCursor_type = pCursor_type->next;
448 } else if (!strcmp(rtproperties_tag_name, DM_TNDS_ELEMENT_VERNO)) {
449 err_code = sync_agent_get_text_from_node(pCursor_rtproperties, &(mo_node.runtime_property->verNo));
450 if (err_code != SYNC_AGENT_PB_RETURN_OK) {
451 _DEBUG_ERROR("Failed to call sync_agent_get_text_from_node()");
456 pCursor_rtproperties = pCursor_rtproperties->next;
458 } else if (!strcmp(tag_name, DM_TNDS_ELEMENT_NODE)) {
462 pCursor = pCursor->next;
465 mo_node.framework_property = NULL;
468 * Process sync_agent_dm_mo_node_s
470 sync_agent_begin_transaction_mo();
473 mo_node.type = SYNC_AGENT_DM_MO_NODE_INTERIOR;
475 mo_node.type = SYNC_AGENT_DM_MO_NODE_LEAF;
478 switch (tnds_action) {
479 case SYNC_AGENT_DM_MO_TNDS_ACTION_ADD:
481 sync_agent_dm_mo_error_e mo_err = dm_add_mo(mo_type, mo_node.full_path, &mo_node);
482 if (mo_err != SYNC_AGENT_DM_MO_SUCCESS) {
483 _DEBUG_ERROR("Failed to call sync_agent_add_mo(%d, %s)", mo_type, mo_node.full_path);
487 case SYNC_AGENT_DM_MO_TNDS_ACTION_REPLACE:
489 sync_agent_dm_mo_error_e mo_err = dm_update_mo(mo_type, &mo_node);
490 if (mo_err != SYNC_AGENT_DM_MO_SUCCESS) {
491 _DEBUG_ERROR("Failed to call sync_agent_update_mo(%d, %s)", mo_type, mo_node.full_path);
497 sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
500 * Process Child Nodes recursively
502 if (hasChildNode != 0) {
503 pCursor = wbxml_dom_node->children;
504 while (pCursor != NULL) {
505 if (pCursor->type == WBXML_TREE_ELEMENT_NODE) {
506 const char *tag_name = (const char *)wbxml_tag_get_xml_name(pCursor->name);
507 if (!strcmp(tag_name, DM_TNDS_ELEMENT_NODE)) {
508 __recursive_contruct_MO_TABLE(tnds_action, mo_type, mo_node.full_path, pCursor);
512 pCursor = pCursor->next;
516 if (mo_node.full_path != NULL) {
517 free(mo_node.full_path);
523 static sync_agent_pb_error_e _mgmttree_start_converter_function(sync_agent_pb_protocol_binder_info_s * pBinder, Content_Ptr pContent, WBXMLTreeNode ** ppWbxml_dom_node)
527 retvm_if(pBinder == NULL, SYNC_AGENT_PB_RETURN_UNKNOWN_ERROR, "sync_agent_pb_protocol_binder_info_s is NULL !!");
529 sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
530 WBXMLTreeNode *mgmttree_node = sync_agent_create_node(pBinder, DM_TNDS_ELEMENT_MGMTTREE);
531 if (mgmttree_node == NULL) {
532 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
536 *ppWbxml_dom_node = mgmttree_node;
543 _DEBUG_ERROR("error :%d", err);
547 static sync_agent_pb_error_e _verdtd_converter_function(sync_agent_pb_protocol_binder_info_s * pBinder, Content_Ptr pContent, WBXMLTreeNode ** ppWbxml_dom_node)
551 retvm_if(pBinder == NULL, SYNC_AGENT_PB_RETURN_UNKNOWN_ERROR, "sync_agent_pb_protocol_binder_info_s is NULL !!");
553 sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
554 const char *verdtd = "1.2"; /* todo HardCoding */
555 WBXMLTreeNode *verdtd_node = sync_agent_create_text_node(pBinder, DM_TNDS_ELEMENT_VERDTD, verdtd, strlen(verdtd));
556 if (verdtd_node == NULL) {
557 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
561 *ppWbxml_dom_node = verdtd_node;
568 _DEBUG_ERROR("error :%d", err);
572 static sync_agent_pb_error_e _node_start_converter_function(sync_agent_pb_protocol_binder_info_s * pBinder, Content_Ptr pContent, WBXMLTreeNode ** ppWbxml_dom_node)
576 retvm_if(pBinder == NULL, SYNC_AGENT_PB_RETURN_UNKNOWN_ERROR, "sync_agent_pb_protocol_binder_info_s is NULL !!");
578 sync_agent_pb_error_e err = SYNC_AGENT_PB_RETURN_OK;
580 sync_agent_dm_mo_node_s *root_mo_node = (sync_agent_dm_mo_node_s *) pContent;
582 WBXMLTreeNode *root_node_node = __construct_TNDS_NODE(root_mo_node, pBinder, 0);
583 if (root_node_node == NULL) {
584 err = SYNC_AGENT_PB_RETURN_OUT_OF_MEMORY;
588 __recursive_contruct_TNDS(root_mo_node, pBinder, root_node_node);
590 *ppWbxml_dom_node = root_node_node;
597 _DEBUG_ERROR("error :%d", err);
601 static sync_agent_pb_error_e _node_start_reverse_converter_function(sync_agent_pb_protocol_binder_reverse_info_s * pReverse_binder, WBXMLTreeNode * wbxml_dom_node, Content_Ptr * pContent)
605 retvm_if(pReverse_binder == NULL, SYNC_AGENT_PB_RETURN_UNKNOWN_ERROR, "sync_agent_pb_protocol_binder_reverse_info_s is NULL !!");
606 retvm_if(wbxml_dom_node == NULL, SYNC_AGENT_PB_RETURN_UNKNOWN_ERROR, "WBXMLTreeNode is NULL !!");
608 dm_tnds_binder_data_s *binder_data = (dm_tnds_binder_data_s *) sync_agent_get_user_data_from_reverse_protocol_binder(pReverse_binder);
610 __recursive_contruct_MO_TABLE(binder_data->tnds_action, binder_data->mo_type, binder_data->mo_full_path, wbxml_dom_node);
614 return SYNC_AGENT_PB_RETURN_OK;