diff options
author | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2001-11-01 21:52:44 +0000 |
---|---|---|
committer | guy <guy@f5534014-38df-0310-8fa8-9805f1628bb7> | 2001-11-01 21:52:44 +0000 |
commit | 98856d1875a35a006ca9dc5cc931e8a6c70c8177 (patch) | |
tree | d887bc44e7e8d07cfc681e666b1e805a0f4853b9 /xmlstub.c | |
parent | 2bc36ec4ccad4648f079c7bb93637a6b6f92a058 (diff) |
From David Frascone: duUpdate to Diameter dissector to load the
dictionary as an XML file rather than building it in, and various
Diameter updates.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@4122 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'xmlstub.c')
-rw-r--r-- | xmlstub.c | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/xmlstub.c b/xmlstub.c new file mode 100644 index 0000000000..ffa589cd2e --- /dev/null +++ b/xmlstub.c @@ -0,0 +1,167 @@ +/* xmlstub.c + * Routines to parse XML files using libxml2. This stub + * exists so that the library can be loaded on systems that + * have it. + * + * $Id: xmlstub.c,v 1.1 2001/11/01 21:52:44 guy Exp $ + * + * Copyright (c) 2001 by David Frascone <dave@frascone.com> + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * Copyright 1998-2001 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <glib.h> +#include <gmodule.h> + +/* XML Stub routines */ +#define IN_XMLSTUB +#include "xmlstub.h" + +/* + * This routine will dynamically load libxml2 and will populate the + * XmlStub pointer structure. + * + * On any error, it will return non-zero, and it should be assumed that + * the current platform does not have dynamic library support, or does + * not have libxml2 installed. + */ +int +loadLibXML() +{ + GModule *handle; + gpointer symbol; + int error=FALSE; + + if (XmlStubInitialized) { + /* Did you ever get the feeling you've been here before? */ + + /* + * This is not thread safe. With threads, we'd need to + * synchronize all this so two threads can't initialize at once. + */ + return 0; + } + + /* Check to see if gmodule is supported */ + if (!g_module_supported()) { + g_warning("XMLStub: Modules are not supported. Not initializing XML Stub"); + return (-1); + } + + /* open the dll. Is this named something different + * under windows? Perhaps we should check . . . + */ + if ((handle = g_module_open(XML_LIBRARY, G_MODULE_BIND_LAZY)) == NULL) { + g_warning("XMLStub: Unable to open module " XML_LIBRARY); + return (-1); + } + + /* + * Now that the library is open, copy all our relevant + * function pointers and integer pointers into our structure. + */ + if (!g_module_symbol(handle, "xmlParseFile", &symbol)) { + g_warning("Unable to find \"xmlParseFile\""); + error=TRUE; + } + XmlStub.xmlParseFile= (xmlDocPtr(*)(const char *))symbol; + + if (!g_module_symbol(handle, "xmlStrcmp", &symbol)) { + g_warning("Unable to find \"xmlStrcmp\""); + error=TRUE; + } + XmlStub.xmlStrcmp= (int (*)(const xmlChar *, const xmlChar *))symbol; + + if (!g_module_symbol(handle, "xmlCreatePushParserCtxt", &symbol)) { + g_warning("Unable to find \"xmlCreatePushParserCtxt\""); + error=TRUE; + } + XmlStub.xmlCreatePushParserCtxt=(xmlParserCtxtPtr (*) + (xmlSAXHandlerPtr, void *, const char *, + int, const char *)) symbol; + + if (!g_module_symbol(handle, "xmlParseChunk", &symbol)) { + g_warning("Unable to find \"xmlParseChunk\""); + error=TRUE; + } + XmlStub.xmlParseChunk=(int (*)(xmlParserCtxtPtr, const char *, int, int))symbol; + + if (!g_module_symbol(handle, "xmlFreeParserCtxt", &symbol)) { + g_warning("Unable to find \"xmlFreeParserCtxt\""); + error=TRUE; + } + XmlStub.xmlFreeParserCtxt=(void (*)(xmlParserCtxtPtr))symbol; + + if (!g_module_symbol(handle, "xmlDocGetRootElement", &symbol)) { + g_warning("Unable to find \"xmlDocGetRootElement\""); + error=TRUE; + } + XmlStub.xmlDocGetRootElement=(xmlNodePtr(*)(xmlDocPtr))symbol; + + if (!g_module_symbol(handle, "xmlFreeDoc", &symbol)) { + g_warning("Unable to find \"xmlFreeDoc\""); + error=TRUE; + } + XmlStub.xmlFreeDoc=(void (*)(xmlDocPtr))symbol; + + if (!g_module_symbol(handle, "xmlNodeListGetString", &symbol)) { + g_warning("Unable to find \"xmlNodeListGetString\""); + error=TRUE; + } + XmlStub.xmlNodeListGetString=(char * (*)(xmlDocPtr, xmlNodePtr, int))symbol; + + if (!g_module_symbol(handle, "xmlGetProp", &symbol)) { + g_warning("Unable to find \"xmlGetProp\""); + error=TRUE; + } + XmlStub.xmlGetProp=(char * (*)(xmlNodePtr, char *))symbol; + + if (!g_module_symbol(handle, "xmlKeepBlanksDefault", &symbol)) { + g_warning("Unable to find \"xmlKeepBlanksDefault\""); + error=TRUE; + } + XmlStub.xmlKeepBlanksDefault=(int(*)(int))symbol; + + if (!g_module_symbol(handle, "xmlSubstituteEntitiesDefault", &symbol)) { + g_warning("Unable to find \"xmlSubstituteEntitiesDefault\""); + error=TRUE; + } + XmlStub.xmlSubstituteEntitiesDefault=(int(*)(int))symbol; + + if (!g_module_symbol(handle, "xmlDoValidityCheckingDefaultValue", &symbol)) { + g_warning("Unable to find \"xmlDoValidityCheckingDefaultValue\""); + error=TRUE; + } + XmlStub.xmlDoValidityCheckingDefaultValue = (int *)symbol; + + /* + * Return if any of the above functions set our error flag. + * A flag was used, instead of returning immediately, so + * that *all* unresolved symbols would be printed. + */ + if (error) { + g_module_close(handle); + return (-1); + } + /* Set our global so that we don't try to load twice */ + XmlStubInitialized=1; + + return 0; /* Success! */ + +} /* loadLibXML */ |