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.
20 #include <libxml/parser.h>
21 #include <libxml/tree.h>
24 #include <sync_agent.h>
27 #include "common/dm_common.h"
28 #include "dm-engine/dl-manager/dd_parser.h"
30 #ifndef OMADM_AGENT_LOG
32 #define LOG_TAG "OMA_DM_DL"
41 DD_NODE_INSTALL_NOTIFY_URI
44 static DD_NODE_TYPE ___get_node_type(unsigned char *node_name);
45 static DM_ERROR __set_value_to_dd_object(xmlNode * a_node, Download_Descriptor ** dd_object);
46 static DM_ERROR _convert_doc_to_dd_object(xmlDocPtr doc, Download_Descriptor ** dd_object);
48 DM_ERROR convert_xml_to_DD_object(const char *dd_xml, unsigned int dd_xml_length, Download_Descriptor ** dd_object)
53 /* parse the in memory document */
56 retvm_if((dd_xml) == NULL, COMMON_ERR_IS_NULL, "dd_xml is NULL!!");
58 if (dd_xml == NULL || dd_xml_length == 0 || *dd_object == NULL) {
59 _DEBUG_INFO("dd_xml == NULL || dd_xml_length == 0 || *dd_object == NULL");
60 ret = COMMON_ERR_IS_NULL;
63 _DEBUG_INFO("xml: %s, size: %d", dd_xml, dd_xml_length);
64 doc = xmlReadMemory(dd_xml, dd_xml_length, 0, 0, 0);
66 _DEBUG_INFO("xmlReadMemory() Fail\n");
67 ret = COMMON_ERR_IS_NULL;
70 /* convert doc to dd_object */
71 ret = _convert_doc_to_dd_object(doc, dd_object);
72 _DEBUG_INFO("convert doc to dd object : %d", ret);
83 static DD_NODE_TYPE ___get_node_type(unsigned char *node_name)
87 _DEBUG_VERBOSE("node_name: %s\n", node_name);
89 if (strcmp((const char *)node_name, "type") == 0) {
91 return DD_NODE_OBJECT_TYPE;
92 } else if (strcmp((const char *)node_name, "description") == 0) {
94 return DD_NODE_DESCRIPTION;
95 } else if (strcmp((const char *)node_name, "objectURI") == 0) {
97 return DD_NODE_OBJECT_URI;
98 } else if (strcmp((const char *)node_name, "size") == 0) {
101 } else if (strcmp((const char *)node_name, "installNotifyURI") == 0) {
103 return DD_NODE_INSTALL_NOTIFY_URI;
107 return DD_NODE_NO_TYPE;
110 static DM_ERROR __set_value_to_dd_object(xmlNode * a_node, Download_Descriptor ** dd_object)
113 DM_ERROR ret = DM_OK;
114 xmlNode *cur_node = 0;
115 DD_NODE_TYPE node_type = DD_NODE_NO_TYPE;
117 retvm_if((a_node) == NULL, COMMON_ERR_IS_NULL, "a_node is NULL!!");
119 unsigned char *content = NULL;
120 for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
121 if (cur_node->type == XML_ELEMENT_NODE) {
122 content = xmlNodeGetContent(cur_node);
124 _DEBUG_VERBOSE("node type: Element, name: %s\n", cur_node->name);
125 _DEBUG_VERBOSE("node type: Element, content: %s\n", content);
127 node_type = ___get_node_type((unsigned char *)(cur_node->name));
129 case DD_NODE_OBJECT_TYPE:
131 if (content != NULL) {
132 (*dd_object)->object_type = strdup((const char *)content);
136 case DD_NODE_DESCRIPTION:
138 if (content != NULL) {
139 (*dd_object)->object_description = strdup((const char *)content);
143 case DD_NODE_OBJECT_URI:
145 #ifdef _DM_BUNDANG_TEST
146 if (content != NULL) {
147 (*dd_object)->object_uri = get_new_uri((char *)content);
150 if (content != NULL) {
151 (*dd_object)->object_uri = strdup((const char *)content);
154 if ((*dd_object)->object_uri != NULL) {
155 _DEBUG_VERBOSE("object_uri = %s\n", (*dd_object)->object_uri);
157 _DEBUG_VERBOSE("object uri null");
163 if (content != NULL) {
164 (*dd_object)->object_size = atoi((const char *)content);
168 case DD_NODE_INSTALL_NOTIFY_URI:
170 #ifdef _DM_BUNDANG_TEST
171 if (content != NULL) {
172 (*dd_object)->install_notify_uri = get_new_uri((char *)content);
175 if (content != NULL) {
176 (*dd_object)->install_notify_uri = strdup((const char *)content);
179 if ((*dd_object)->install_notify_uri != NULL) {
180 _DEBUG_VERBOSE("install_notify_uri = %s\n", (*dd_object)->install_notify_uri);
182 _DEBUG_VERBOSE("install notify uri null");
191 ret = __set_value_to_dd_object(cur_node->children, dd_object);
192 _DEBUG_VERBOSE("set value to dd object : %d", ret);
199 static DM_ERROR _convert_doc_to_dd_object(xmlDocPtr doc, Download_Descriptor ** dd_object)
203 DM_ERROR ret = DM_OK;
205 xmlNode *root_element = 0;
207 /* get the root element node */
208 root_element = xmlDocGetRootElement(doc);
209 if (root_element == NULL) {
211 return COMMON_ERR_IS_NULL;
214 /*DD_NODE_TYPE node_type = DD_NODE_NO_TYPE; */
215 ret = __set_value_to_dd_object(root_element, dd_object);
216 _DEBUG_TRACE("set value dd object : %d", ret);