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 #ifndef UTIL_INTERNAL_H_
19 #define UTIL_INTERNAL_H_
21 #include "protocol-binder/util.h"
24 * @file util_internal.h
25 * @brief Provides protocol-binder utility operation set
28 /** @addtogroup protocol_binder
33 * @brief XML document adjusting
34 * @remarks Remove XML header from XML msg
35 * @param[in] xml Pointer of XML message
36 * @param[in] xml_len Length of XML
37 * @return Length of XML after remove header
39 unsigned int pb_remove_xml_header(char *xml, unsigned int xml_len);
41 /* wbxml related part */
43 * @brief Validate protocol
44 * @remarks Validate that protocol is supported by portocol binder
45 * @param[in] protocol Enum value that means specific protocol
46 * @return True on success, False on fail
48 bool pb_validate_protocol(sync_agent_pb_protocol_e protocol);
51 * @brief Get WBXMLLanguage enum value
52 * @remarks Convert to WBXMLLanguage from Protocol
53 * @param[in] protocol Enum value that means specific protocol
54 * @return WBXMLLanguage enum value on success
56 WBXMLLanguage pb_get_wbxml_language(sync_agent_pb_protocol_e protocol);
59 * @brief Get Protocol enum value
60 * @remarks Convert to Protocol from WBXMLLanguage
61 * @param[in] wbxml_lang WBXMLLanguage enum value
62 * @return Protocol enum value on success
64 sync_agent_pb_protocol_e pb_get_protocol_from_wbxml_lang(WBXMLLanguage wbxml_lang);
67 * @brief Get WBXMLVersion enum value
68 * @remarks Convert to WBXMLVersion from sync_agent_pb_encoding_e
69 * @param[in] enc WBXMLVersion enum value
70 * @return WBXMLVersion enum value on success
72 WBXMLVersion pb_get_wbxml_version(sync_agent_pb_encoding_e enc);
75 * @brief Get WBXML tree from WBXML byte stream
76 * @remarks Parse WBXML byte stream and build WBXMLTree
77 * @param[in] byte_stream Byte stream of WBXML message
78 * @param[in] byte_stream_len Length of WBXML message
79 * @param[in] wbxml_lang WBXMLLanguage enum value
80 * @param[out] wbxml_tree WBXMLTree
81 * @return 0 on success, otherwise a negative error value.
82 * @retval SYNC_AGENT_PB_RETURN_OK Successful
83 * @retval SYNC_AGENT_PB_RETURN_WBXML_PARSE_FAIL Parse failed
85 sync_agent_pb_error_e pb_get_wbxml_tree_from_wbxml(char *byte_stream, int byte_stream_len, WBXMLLanguage wbxml_lang, WBXMLTree ** wbxml_tree);
88 * @brief Get WBXML tree from XML byte stream
89 * @remarks Parse WBXML byte stream and build WBXMLTree using libwbxml library
90 * @param[in] byte_stream Byte stream of XML message
91 * @param[in] byte_stream_len Length of XML message
92 * @param[in] wbxml_lang WBXMLLanguage enum value
93 * @param[out] wbxml_tree WBXMLTree
94 * @return 0 on success, otherwise a negative error value.
95 * @retval SYNC_AGENT_PB_RETURN_OK Successful
96 * @retval SYNC_AGENT_PB_RETURN_WBXML_PARSE_FAIL Parse failed
98 sync_agent_pb_error_e pb_get_wbxml_tree_from_xml(char *byte_stream, int byte_stream_len, WBXMLLanguage wbxml_lang, WBXMLTree ** wbxml_tree);
101 * @brief Get next WBXMLTreeNode from current WBXMLTreeNode
102 * @remarks if current WBXMLTreeNode's type is
103 * WBXML_TREE_TREE_NODE(WBXMLTree has a subtree as a tree node),
104 * use this API to get next WBXMLTreeNode of subtree
105 * @param[in] node Current WBXMLTreeNode
106 * @param[out] first_visit Whether first visit for this tree node or not
107 * @return WBXMLTreeNode on success
109 WBXMLTreeNode *pb_get_next_node_of_tree_node(WBXMLTreeNode * node, bool * first_visit);
112 * @brief Get next WBXMLTreeNode from current WBXMLTreeNode
113 * @remarks if current WBXMLTreeNode's type is not WBXML_TREE_TREE_NODE,
114 * use this API to get next WBXMLTreeNode of current WBXMLTreeNode
115 * @param[in] node Current WBXMLTreeNode
116 * @param[out] first_visit Whether first visit for this tree node or not
117 * @return WBXMLTreeNode on success
119 WBXMLTreeNode *pb_get_next_node_of_element_node(WBXMLTreeNode * node, bool * first_visit);
122 * @brief Get WBXMLLangEntry of subtree
123 * @param[in] reverse_binder sync_agent_pb_protocol_binder_reverse_info_s
124 * @return WBXMLLangEntry on success
126 const WBXMLLangEntry *pb_get_current_subtree_lang(sync_agent_pb_protocol_binder_reverse_info_s * reverse_binder);
129 * @brief whether node has a same type as inputted type
130 * @param[in] node WBXMLTreeNode
131 * @param[in] type WBXMLTreeNodeType
132 * @return true is node has a type which is inputted, false is not
134 bool pb_has_wbxml_node_same_type(WBXMLTreeNode * node, WBXMLTreeNodeType type);
137 * @brief print XML from current WBXMLTree
138 * @param[in] tree WBXMLTree
140 void pb_print_wbxml_dom_in_xml(const WBXMLTree * tree);
143 * @brief Create WBXMLTreeNode using XML element name with unsigned int content, and add WBXMLTreeNode to parent node as a child node
144 * @param[in] binder sync_agent_pb_protocol_binder_info_s
145 * @param[in] parent_node Parent node
146 * @param[in] xml_name XML element name
147 * @param[in] num Content
148 * @return WBXMLTreeNode on success, NULL on fail
150 WBXMLTreeNode *sync_agent_add_child_wbxml_node_using_xml_name_with_unsigned_int(const sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node, const char *xml_name, const unsigned int num);
153 * @brief Create WBXMLTreeNode using XML element name and XML name space with unsigned int content, and add WBXMLTreeNode to parent node as a child node
154 * @param[in] binder sync_agent_pb_protocol_binder_info_s
155 * @param[in] parent_node Parent node
156 * @param[in] xml_name XML element name
157 * @param[in] name_space XML name space
158 * @param[in] num Content
159 * @return WBXMLTreeNode on success, NULL on fail
161 WBXMLTreeNode *sync_agent_add_child_wbxml_node_using_xml_name_and_namespace_with_unsigned_int(const sync_agent_pb_protocol_binder_info_s * binder, WBXMLTreeNode * parent_node, const char *xml_name, const char *name_space, const unsigned int num);
164 * @brief Add WBXMLTreeNode to parent node as a child node
165 * @param[in] parent Parent node
166 * @param[in] child Child node
167 * @return WBXMLTreeNode on success, NULL on fail
169 bool sync_agent_wbxml_node_add_child_node(WBXMLTreeNode * parent, WBXMLTreeNode * child);
172 * @brief Get pointer of binary content from WBXMLTreeNode(cdata node)
173 * @param[in] element_node WBXMLTreeNode
174 * @param[out] binary_pointer Pointer of binary content
175 * @param[out] binary_size Size of binary content
176 * @return 0 on success, otherwise a negative error value.
177 * @retval SYNC_AGENT_PB_RETURN_OK Successful
178 * @retval SYNC_AGENT_PB_RETURN_UTIL_NO_BINARY_VALUE Invalid parameter(element_node)
180 sync_agent_pb_error_e sync_agent_get_binary_pointer_from_wbxml_cdata_node(WBXMLTreeNode * element_node, char **binary_pointer, unsigned int *binary_size);
186 #endif /* UTIL_INTERNAL_H_ */