Debian Codegraph @

src/common/xml_iterate.c

raw symbols SCIP
1 /*
2 * Copyright 2013 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
21 #include <config.h>cxx . . $ `<file>/build/config.h`/
22 #endif
23
24 #include <string.h>
25 #include <libxml/parser.h>
26 #include "debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
27 #include "xml_iterate.h"cxx . . $ `<file>/src/common/xml_iterate.h`/
28 #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/
29
30
31 static int xml_element_dfs_callbackcxx . . $ xml_element_dfs_callback(4bb74f95d1f92f95).(xmlNodecxx . . $ xmlNode# **node, xml_iterate_callbackcxx . . $ xml_iterate_callback# user_fn, void *user_data)
32 {
33 int result = user_fn(node, user_data);
34 if (result == 1)
35 return result;
36 xmlNodecxx . . $ xmlNode# *child = (*node)->childrencxx . . $ _xmlNode#children.;
37 while (child != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
38 int res = xml_element_dfs_callbackcxx . . $ xml_element_dfs_callback(4bb74f95d1f92f95).(&child, user_fn, user_data);
39 if (res == 1)
40 return res;
41 if (result == 0)
42 result = res;
43 child = child->nextcxx . . $ _xmlNode#next.;
44 }
45 return result;
46 }
47
48 int xml_iterate_dfscxx . . $ xml_iterate_dfs(63334c2cd85278c8).(const char *input_text, char **output_text, xml_iterate_callbackcxx . . $ xml_iterate_callback# user_fn, void *user_data)
49 {
50 char *input_document = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
51 xmlDocPtrcxx . . $ xmlDocPtr# doc = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
52 xmlNodecxx . . $ xmlNode# *root = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
53 int res = 0;
54
55 if (user_fn == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
56 return 1;
57
58 input_document = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("<x xmlns='http://www.w3.org/1999/xhtml'>%s</x>", input_text);
59 if ((doc = xmlParseMemorycxx . . $ xmlParseMemory(48704c96f88d9177).(input_document, strlencxx . . $ strlen(751346f8406fd082).(input_document))) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
60 dWcxx . . $ `src/common/debug_priv.h:62:9`!("Could not xmlParseMemory: '%s'", input_document);
61 freecxx . . $ free(5d22bdacc48458e8).(input_document);
62 return 1;
63 }
64 if ((root = xmlDocGetRootElementcxx . . $ xmlDocGetRootElement(53aa9a676bd496f2).(doc)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
65 dWcxx . . $ `src/common/debug_priv.h:62:9`!("Could not xmlDocGetRootElement: '%s'", input_document);
66 xmlFreeDoccxx . . $ xmlFreeDoc(42de24d0ab3f771).(doc);
67 freecxx . . $ free(5d22bdacc48458e8).(input_document);
68 return 1;
69 }
70 freecxx . . $ free(5d22bdacc48458e8).(input_document);
71
72 res = xml_element_dfs_callbackcxx . . $ xml_element_dfs_callback(4bb74f95d1f92f95).(&root, user_fn, user_data);
73 if (output_text != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
74 // We cannot simply xmlDumpMemory, because we need to skip the upper <x/> element.
75 if ((root = xmlDocGetRootElementcxx . . $ xmlDocGetRootElement(53aa9a676bd496f2).(doc)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
76 dWcxx . . $ `src/common/debug_priv.h:62:9`!("Could not get xmlDocGetRootElement of result document.");
77 xmlFreeDoccxx . . $ xmlFreeDoc(42de24d0ab3f771).(doc);
78 return 1;
79 }
80 xmlBuffercxx . . $ xmlBuffer# *buff = xmlBufferCreatecxx . . $ xmlBufferCreate(690ac0a6f5d6455a).();
81 xmlNodecxx . . $ xmlNode# *child = root->childrencxx . . $ _xmlNode#children.;
82 while (child != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
83 int size = xmlNodeDumpcxx . . $ xmlNodeDump(c5c0619fc6533a80).(buff, doc, child, 0, 0);
84 if (size < 0) {
85 dEcxx . . $ `src/common/debug_priv.h:63:9`!("xmlNodeDump failed!");
86 }
87 else if (size == 0) {
88 dDcxx . . $ `src/common/debug_priv.h:64:9`!("xmlNodeDump returned zero.");
89 }
90
91 child = child->nextcxx . . $ _xmlNode#next.;
92 }
93 /* Sadly, we cannot use xmlBufferDetach since we want to support older libxml. */
94 *output_text = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).((const char *) xmlBufferContentcxx . . $ xmlBufferContent(aa2c827beb941ccb).(buff));
95 xmlBufferFreecxx . . $ xmlBufferFree(fdbd5d1662c5530e).(buff);
96 }
97 xmlFreeDoccxx . . $ xmlFreeDoc(42de24d0ab3f771).(doc);
98 return res;
99 }