2 * Routines to parse XML files using libxml2. This stub
3 * exists so that the library can be loaded on systems that
6 * $Id: xmlstub.c,v 1.2 2002/08/28 21:00:41 jmayer Exp $
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.
32 /* XML Stub routines */
37 * This routine will dynamically load libxml2 and will populate the
38 * XmlStub pointer structure.
40 * On any error, it will return non-zero, and it should be assumed that
41 * the current platform does not have dynamic library support, or does
42 * not have libxml2 installed.
51 if (XmlStubInitialized) {
52 /* Did you ever get the feeling you've been here before? */
55 * This is not thread safe. With threads, we'd need to
56 * synchronize all this so two threads can't initialize at once.
61 /* Check to see if gmodule is supported */
62 if (!g_module_supported()) {
63 g_warning("XMLStub: Modules are not supported. Not initializing XML Stub");
67 /* open the dll. Is this named something different
68 * under windows? Perhaps we should check . . .
70 if ((handle = g_module_open(XML_LIBRARY, G_MODULE_BIND_LAZY)) == NULL) {
71 g_warning("XMLStub: Unable to open module " XML_LIBRARY);
76 * Now that the library is open, copy all our relevant
77 * function pointers and integer pointers into our structure.
79 if (!g_module_symbol(handle, "xmlParseFile", &symbol)) {
80 g_warning("Unable to find \"xmlParseFile\"");
83 XmlStub.xmlParseFile= (xmlDocPtr(*)(const char *))symbol;
85 if (!g_module_symbol(handle, "xmlStrcmp", &symbol)) {
86 g_warning("Unable to find \"xmlStrcmp\"");
89 XmlStub.xmlStrcmp= (int (*)(const xmlChar *, const xmlChar *))symbol;
91 if (!g_module_symbol(handle, "xmlCreatePushParserCtxt", &symbol)) {
92 g_warning("Unable to find \"xmlCreatePushParserCtxt\"");
95 XmlStub.xmlCreatePushParserCtxt=(xmlParserCtxtPtr (*)
96 (xmlSAXHandlerPtr, void *, const char *,
97 int, const char *)) symbol;
99 if (!g_module_symbol(handle, "xmlParseChunk", &symbol)) {
100 g_warning("Unable to find \"xmlParseChunk\"");
103 XmlStub.xmlParseChunk=(int (*)(xmlParserCtxtPtr, const char *, int, int))symbol;
105 if (!g_module_symbol(handle, "xmlFreeParserCtxt", &symbol)) {
106 g_warning("Unable to find \"xmlFreeParserCtxt\"");
109 XmlStub.xmlFreeParserCtxt=(void (*)(xmlParserCtxtPtr))symbol;
111 if (!g_module_symbol(handle, "xmlDocGetRootElement", &symbol)) {
112 g_warning("Unable to find \"xmlDocGetRootElement\"");
115 XmlStub.xmlDocGetRootElement=(xmlNodePtr(*)(xmlDocPtr))symbol;
117 if (!g_module_symbol(handle, "xmlFreeDoc", &symbol)) {
118 g_warning("Unable to find \"xmlFreeDoc\"");
121 XmlStub.xmlFreeDoc=(void (*)(xmlDocPtr))symbol;
123 if (!g_module_symbol(handle, "xmlNodeListGetString", &symbol)) {
124 g_warning("Unable to find \"xmlNodeListGetString\"");
127 XmlStub.xmlNodeListGetString=(char * (*)(xmlDocPtr, xmlNodePtr, int))symbol;
129 if (!g_module_symbol(handle, "xmlGetProp", &symbol)) {
130 g_warning("Unable to find \"xmlGetProp\"");
133 XmlStub.xmlGetProp=(char * (*)(xmlNodePtr, char *))symbol;
135 if (!g_module_symbol(handle, "xmlKeepBlanksDefault", &symbol)) {
136 g_warning("Unable to find \"xmlKeepBlanksDefault\"");
139 XmlStub.xmlKeepBlanksDefault=(int(*)(int))symbol;
141 if (!g_module_symbol(handle, "xmlSubstituteEntitiesDefault", &symbol)) {
142 g_warning("Unable to find \"xmlSubstituteEntitiesDefault\"");
145 XmlStub.xmlSubstituteEntitiesDefault=(int(*)(int))symbol;
147 if (!g_module_symbol(handle, "xmlDoValidityCheckingDefaultValue", &symbol)) {
148 g_warning("Unable to find \"xmlDoValidityCheckingDefaultValue\"");
151 XmlStub.xmlDoValidityCheckingDefaultValue = (int *)symbol;
154 * Return if any of the above functions set our error flag.
155 * A flag was used, instead of returning immediately, so
156 * that *all* unresolved symbols would be printed.
159 g_module_close(handle);
162 /* Set our global so that we don't try to load twice */
163 XmlStubInitialized=1;
165 return 0; /* Success! */