2 * Routines to parse XML files using libxml2. This stub
3 * exists so that the library can be loaded on systems that
8 * Copyright (c) 2001 by David Frascone <dave@frascone.com>
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998-2001 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/report_err.h>
33 /* XML Stub routines */
38 * This routine will dynamically load libxml2 and will populate the
39 * XmlStub pointer structure.
41 * On any error, it will return non-zero, and it should be assumed that
42 * the current platform does not have dynamic library support, or does
43 * not have libxml2 installed.
52 if (XmlStubInitialized) {
53 /* Did you ever get the feeling you've been here before? */
56 * This is not thread safe. With threads, we'd need to
57 * synchronize all this so two threads can't initialize at once.
62 /* Check to see if gmodule is supported */
63 if (!g_module_supported()) {
64 g_warning("XMLStub: Modules are not supported. Not initializing XML Stub");
68 /* open the dll. Is this named something different
69 * under windows? Perhaps we should check . . .
71 if ((handle = g_module_open(XML_LIBRARY, G_MODULE_BIND_LAZY)) == NULL) {
72 report_failure("XMLStub: Unable to open module " XML_LIBRARY );
77 * Now that the library is open, copy all our relevant
78 * function pointers and integer pointers into our structure.
80 if (!g_module_symbol(handle, "xmlParseFile", &symbol)) {
81 g_warning("Unable to find \"xmlParseFile\"");
84 XmlStub.xmlParseFile= (xmlDocPtr(*)(const char *))symbol;
86 if (!g_module_symbol(handle, "xmlStrcmp", &symbol)) {
87 g_warning("Unable to find \"xmlStrcmp\"");
90 XmlStub.xmlStrcmp= (int (*)(const xmlChar *, const xmlChar *))symbol;
92 if (!g_module_symbol(handle, "xmlCreatePushParserCtxt", &symbol)) {
93 g_warning("Unable to find \"xmlCreatePushParserCtxt\"");
96 XmlStub.xmlCreatePushParserCtxt=(xmlParserCtxtPtr (*)
97 (xmlSAXHandlerPtr, void *, const char *,
98 int, const char *)) symbol;
100 if (!g_module_symbol(handle, "xmlParseChunk", &symbol)) {
101 g_warning("Unable to find \"xmlParseChunk\"");
104 XmlStub.xmlParseChunk=(int (*)(xmlParserCtxtPtr, const char *, int, int))symbol;
106 if (!g_module_symbol(handle, "xmlFreeParserCtxt", &symbol)) {
107 g_warning("Unable to find \"xmlFreeParserCtxt\"");
110 XmlStub.xmlFreeParserCtxt=(void (*)(xmlParserCtxtPtr))symbol;
112 if (!g_module_symbol(handle, "xmlDocGetRootElement", &symbol)) {
113 g_warning("Unable to find \"xmlDocGetRootElement\"");
116 XmlStub.xmlDocGetRootElement=(xmlNodePtr(*)(xmlDocPtr))symbol;
118 if (!g_module_symbol(handle, "xmlFreeDoc", &symbol)) {
119 g_warning("Unable to find \"xmlFreeDoc\"");
122 XmlStub.xmlFreeDoc=(void (*)(xmlDocPtr))symbol;
124 if (!g_module_symbol(handle, "xmlNodeListGetString", &symbol)) {
125 g_warning("Unable to find \"xmlNodeListGetString\"");
128 XmlStub.xmlNodeListGetString=(char * (*)(xmlDocPtr, xmlNodePtr, int))symbol;
130 if (!g_module_symbol(handle, "xmlGetProp", &symbol)) {
131 g_warning("Unable to find \"xmlGetProp\"");
134 XmlStub.xmlGetProp=(char * (*)(xmlNodePtr, char *))symbol;
136 if (!g_module_symbol(handle, "xmlKeepBlanksDefault", &symbol)) {
137 g_warning("Unable to find \"xmlKeepBlanksDefault\"");
140 XmlStub.xmlKeepBlanksDefault=(int(*)(int))symbol;
142 if (!g_module_symbol(handle, "xmlSubstituteEntitiesDefault", &symbol)) {
143 g_warning("Unable to find \"xmlSubstituteEntitiesDefault\"");
146 XmlStub.xmlSubstituteEntitiesDefault=(int(*)(int))symbol;
148 #ifdef ETHEREAL_XML_DO_VALIDITY_CHECKING
149 if (!g_module_symbol(handle, "xmlDoValidityCheckingDefaultValue", &symbol)) {
150 g_warning("Unable to find \"xmlDoValidityCheckingDefaultValue\"");
153 XmlStub.xmlDoValidityCheckingDefaultValue = (int *)symbol;
157 * Return if any of the above functions set our error flag.
158 * A flag was used, instead of returning immediately, so
159 * that *all* unresolved symbols would be printed.
162 g_module_close(handle);
165 /* Set our global so that we don't try to load twice */
166 XmlStubInitialized=1;
168 return 0; /* Success! */