Debian Codegraph @

crt/aws-c-common/include/aws/common/xml_parser.h

raw symbols SCIP
1 #ifndef AWS_COMMON_XML_PARSER_H
2 #define AWS_COMMON_XML_PARSER_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 /* WARNING: This is not a public API. It is only intended for use within the aws-c libraries. */
10 #include <aws/common/array_list.h>
11 #include <aws/common/byte_buf.h>
12
13 #include <aws/common/exports.h>
14
15 AWS_PUSH_SANE_WARNING_LEVEL
16
17 struct aws_xml_node;
18
19 struct aws_xml_attribute {
20 struct aws_byte_cursor name;
21 struct aws_byte_cursor value;
22 };
23
24 /**
25 * Callback for when an xml node is encountered in the document. As a user you have a few options:
26 *
27 * 1. fail the parse by returning AWS_OP_ERR (after an error has been raised). This will stop any further parsing.
28 * 2. call aws_xml_node_traverse() on the node to descend into the node with a new callback and user_data.
29 * 3. call aws_xml_node_as_body() to retrieve the contents of the node as text.
30 *
31 * You MUST NOT call both aws_xml_node_traverse() and aws_xml_node_as_body() on the same node.
32 *
33 * return true to continue the parsing operation.
34 */
35 typedef int(aws_xml_parser_on_node_encountered_fn)(struct aws_xml_node *node, void *user_data);
36
37 struct aws_xml_parser_options {
38 /* xml document to parse. */
39 struct aws_byte_cursor doc;
40
41 /* Max node depth used for parsing document. */
42 size_t max_depth;
43
44 /* Callback invoked on the root node */
45 aws_xml_parser_on_node_encountered_fn *on_root_encountered;
46
47 /* User data for callback */
48 void *user_data;
49 };
50
51 AWS_EXTERN_C_BEGIN
52
53 /**
54 * Parse an XML document.
55 * WARNING: This is not a public API. It is only intended for use within the aws-c libraries.
56 */
57 AWS_COMMON_API
58 int aws_xml_parse(struct aws_allocator *allocator, const struct aws_xml_parser_options *options);
59
60 /**
61 * Writes the contents of the body of node into out_body. out_body is an output parameter in this case. Upon success,
62 * out_body will contain the body of the node.
63 */
64 AWS_COMMON_API
65 int aws_xml_node_as_body(struct aws_xml_node *node, struct aws_byte_cursor *out_body);
66
67 /**
68 * Writes the contents of the body of node unescaped into out_body. out_body is an output parameter in this case. Upon
69 * success, out_body will contain the body of the node. out_body must either have space for new data or be resizable.
70 */
71 AWS_COMMON_API
72 int aws_xml_node_as_body_unescaped(
73 struct aws_allocator *allocator,
74 struct aws_xml_node *node,
75 struct aws_byte_buf *out_body);
76
77 /**
78 * Traverse node and invoke on_node_encountered when a nested node is encountered.
79 */
80 AWS_COMMON_API
81 int aws_xml_node_traverse(
82 struct aws_xml_node *node,
83 aws_xml_parser_on_node_encountered_fn *on_node_encountered,
84 void *user_data);
85
86 /*
87 * Get the name of an xml node.
88 */
89 AWS_COMMON_API
90 struct aws_byte_cursor aws_xml_node_get_name(const struct aws_xml_node *node);
91
92 /*
93 * Get the number of attributes for an xml node.
94 */
95 AWS_COMMON_API
96 size_t aws_xml_node_get_num_attributes(const struct aws_xml_node *node);
97
98 /*
99 * Get an attribute for an xml node by its index.
100 */
101 AWS_COMMON_API
102 struct aws_xml_attribute aws_xml_node_get_attribute(const struct aws_xml_node *node, size_t attribute_index);
103
104 /*
105 * Helper that removes escaping within xml strings. ex. replaces &quot; with ".
106 *
107 */
108 AWS_COMMON_API
109 int aws_byte_buf_append_unescaped_xml(
110 struct aws_allocator *allocator,
111 struct aws_byte_cursor data,
112 struct aws_byte_buf *out);
113
114 AWS_EXTERN_C_END
115 AWS_POP_SANE_WARNING_LEVEL
116
117 #endif /* AWS_COMMON_XML_PARSER_H */