Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 1 | /* |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 2 | * xmlmodule.c : basic API for dynamic module loading added 2.6.17 |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
| 6 | * joelwreed@comcast.net |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 7 | * |
| 8 | * http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #define IN_LIBXML |
| 12 | #include "libxml.h" |
| 13 | |
| 14 | #include <string.h> |
| 15 | #include <libxml/xmlmemory.h> |
| 16 | #include <libxml/xmlerror.h> |
| 17 | #include <libxml/xmlmodule.h> |
| 18 | #include <libxml/globals.h> |
| 19 | |
| 20 | #ifdef LIBXML_MODULES_ENABLED |
| 21 | |
| 22 | struct _xmlModule { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 23 | unsigned char *name; |
| 24 | void *handle; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 27 | static void *xmlModulePlatformOpen(const char *name); |
| 28 | static int xmlModulePlatformClose(void *handle); |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 29 | static int xmlModulePlatformSymbol(void *handle, const char *name, void **result); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 30 | |
| 31 | /************************************************************************ |
| 32 | * * |
| 33 | * module memory error handler * |
| 34 | * * |
| 35 | ************************************************************************/ |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 36 | |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 37 | /** |
| 38 | * xmlModuleErrMemory: |
| 39 | * @extra: extra information |
| 40 | * |
| 41 | * Handle an out of memory condition |
| 42 | */ |
| 43 | static void |
| 44 | xmlModuleErrMemory(xmlModulePtr module, const char *extra) |
| 45 | { |
| 46 | const char *name = NULL; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 47 | |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 48 | if (module != NULL) { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 49 | name = (const char *) module->name; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 53 | XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra, |
| 54 | name, NULL, 0, 0, |
| 55 | "Memory allocation failed : %s\n", extra); |
| 56 | } |
| 57 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 58 | /** |
| 59 | * xmlModuleOpen: |
| 60 | * @name: the module name |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 61 | * @options: a set of xmlModuleOption |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 62 | * |
| 63 | * Opens a module/shared library given its name or path |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 64 | * TODO: options are not yet implemented. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 65 | * |
| 66 | * Returns a handle for the module or NULL in case of error |
| 67 | */ |
| 68 | xmlModulePtr |
Daniel Veillard | 48df961 | 2005-01-04 21:50:05 +0000 | [diff] [blame] | 69 | xmlModuleOpen(const char *name, int options ATTRIBUTE_UNUSED) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 70 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 71 | xmlModulePtr module; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 72 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 73 | module = (xmlModulePtr) xmlMalloc(sizeof(xmlModule)); |
| 74 | if (module == NULL) { |
| 75 | xmlModuleErrMemory(NULL, "creating module"); |
| 76 | return (NULL); |
| 77 | } |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 78 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 79 | memset(module, 0, sizeof(xmlModule)); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 80 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 81 | module->handle = xmlModulePlatformOpen(name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 82 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 83 | if (module->handle == NULL) { |
| 84 | xmlFree(module); |
| 85 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 86 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
| 87 | name, NULL, 0, 0, "failed to open %s\n", name); |
Daniel Veillard | 24505b0 | 2005-07-28 23:49:35 +0000 | [diff] [blame] | 88 | return(NULL); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | module->name = xmlStrdup((const xmlChar *) name); |
| 92 | return (module); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * xmlModuleSymbol: |
| 97 | * @module: the module |
| 98 | * @name: the name of the symbol |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 99 | * @symbol: the resulting symbol address |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 100 | * |
| 101 | * Lookup for a symbol address in the given module |
| 102 | * |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 103 | * Returns 0 if the symbol was found, or -1 in case of error |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 104 | */ |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 105 | int |
| 106 | xmlModuleSymbol(xmlModulePtr module, const char *name, void **symbol) |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 107 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 108 | int rc = -1; |
| 109 | |
| 110 | if ((NULL == module) || (symbol == NULL)) { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 111 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 112 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 113 | NULL, NULL, 0, 0, "null parameter\n"); |
| 114 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 117 | rc = xmlModulePlatformSymbol(module->handle, name, symbol); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 118 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 119 | if (rc == -1) { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 120 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 121 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 122 | name, NULL, 0, 0, |
| 123 | "failed to find symbol: %s\n", |
| 124 | (name == NULL ? "NULL" : name)); |
| 125 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 128 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /** |
| 132 | * xmlModuleClose: |
| 133 | * @module: the module handle |
| 134 | * |
| 135 | * The close operations unload the associated module and free the |
| 136 | * data associated to the module. |
| 137 | * |
| 138 | * Returns 0 in case of success, -1 in case of argument error and -2 |
| 139 | * if the module could not be closed/unloaded. |
| 140 | */ |
| 141 | int |
| 142 | xmlModuleClose(xmlModulePtr module) |
| 143 | { |
| 144 | int rc; |
| 145 | |
| 146 | if (NULL == module) { |
| 147 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 148 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0, |
| 149 | NULL, NULL, 0, 0, "null module pointer\n"); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | rc = xmlModulePlatformClose(module->handle); |
| 154 | |
| 155 | if (rc != 0) { |
| 156 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 157 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 158 | (const char *) module->name, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 159 | "failed to close: %s\n", module->name); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 160 | return -2; |
| 161 | } |
| 162 | |
| 163 | rc = xmlModuleFree(module); |
| 164 | return (rc); |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * xmlModuleFree: |
| 169 | * @module: the module handle |
| 170 | * |
| 171 | * The free operations free the data associated to the module |
| 172 | * but does not unload the associated shared library which may still |
| 173 | * be in use. |
| 174 | * |
| 175 | * Returns 0 in case of success, -1 in case of argument error |
| 176 | */ |
| 177 | int |
| 178 | xmlModuleFree(xmlModulePtr module) |
| 179 | { |
| 180 | if (NULL == module) { |
| 181 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | 24505b0 | 2005-07-28 23:49:35 +0000 | [diff] [blame] | 182 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, NULL, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 183 | NULL, NULL, 0, 0, "null module pointer\n"); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 184 | return -1; |
| 185 | } |
| 186 | |
| 187 | xmlFree(module->name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 188 | xmlFree(module); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 189 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 190 | return (0); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Daniel Veillard | 643fb5d | 2008-02-08 10:49:46 +0000 | [diff] [blame] | 193 | #if defined(HAVE_DLOPEN) && !defined(_WIN32) |
Daniel Veillard | dcd9390 | 2005-01-13 11:25:15 +0000 | [diff] [blame] | 194 | #ifdef HAVE_DLFCN_H |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 195 | #include <dlfcn.h> |
Daniel Veillard | dcd9390 | 2005-01-13 11:25:15 +0000 | [diff] [blame] | 196 | #endif |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 197 | |
Daniel Veillard | 9b693b4 | 2005-10-28 14:54:17 +0000 | [diff] [blame] | 198 | #ifndef RTLD_GLOBAL /* For Tru64 UNIX 4.0 */ |
| 199 | #define RTLD_GLOBAL 0 |
| 200 | #endif |
| 201 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 202 | /** |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 203 | * xmlModulePlatformOpen: |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 204 | * @name: path to the module |
| 205 | * |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 206 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 207 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 208 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 209 | static void * |
| 210 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 211 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 212 | return dlopen(name, RTLD_GLOBAL | RTLD_NOW); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /* |
| 216 | * xmlModulePlatformClose: |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 217 | * @handle: handle to the module |
| 218 | * |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 219 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 220 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 221 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 222 | static int |
| 223 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 224 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 225 | return dlclose(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* |
| 229 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 230 | * http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html |
| 231 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 232 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 233 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 234 | static int |
| 235 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 236 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 237 | *symbol = dlsym(handle, name); |
| 238 | if (dlerror() != NULL) { |
| 239 | return -1; |
| 240 | } |
| 241 | return 0; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Daniel Veillard | ff4c185 | 2005-03-10 10:37:28 +0000 | [diff] [blame] | 244 | #else /* ! HAVE_DLOPEN */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 245 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 246 | #ifdef HAVE_SHLLOAD /* HAVE_SHLLOAD */ |
Daniel Veillard | dcd9390 | 2005-01-13 11:25:15 +0000 | [diff] [blame] | 247 | #ifdef HAVE_DL_H |
| 248 | #include <dl.h> |
| 249 | #endif |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 250 | /* |
| 251 | * xmlModulePlatformOpen: |
| 252 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 253 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 254 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 255 | static void * |
| 256 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 257 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 258 | return shl_load(name, BIND_IMMEDIATE, 0L); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* |
| 262 | * xmlModulePlatformClose: |
| 263 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 264 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 265 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 266 | static int |
| 267 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 268 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 269 | return shl_unload(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* |
| 273 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 274 | * http://docs.hp.com/en/B2355-90683/shl_load.3X.html |
| 275 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 276 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 277 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 278 | static int |
| 279 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 280 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 281 | int rc; |
| 282 | |
| 283 | errno = 0; |
Daniel Veillard | 9b693b4 | 2005-10-28 14:54:17 +0000 | [diff] [blame] | 284 | rc = shl_findsym(&handle, name, TYPE_UNDEFINED, symbol); |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 285 | return rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | #endif /* HAVE_SHLLOAD */ |
Daniel Veillard | ff4c185 | 2005-03-10 10:37:28 +0000 | [diff] [blame] | 289 | #endif /* ! HAVE_DLOPEN */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 290 | |
| 291 | #ifdef _WIN32 |
| 292 | |
| 293 | #include <windows.h> |
| 294 | |
| 295 | /* |
| 296 | * xmlModulePlatformOpen: |
| 297 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 298 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 299 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 300 | static void * |
| 301 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 302 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 303 | return LoadLibrary(name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* |
| 307 | * xmlModulePlatformClose: |
| 308 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 309 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 310 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 311 | static int |
| 312 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 313 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 314 | int rc; |
| 315 | |
| 316 | rc = FreeLibrary(handle); |
| 317 | return (0 == rc); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /* |
| 321 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 322 | * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getprocaddress.asp |
| 323 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 324 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 325 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 326 | static int |
| 327 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 328 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 329 | *symbol = GetProcAddress(handle, name); |
| 330 | return (NULL == *symbol) ? -1 : 0; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | #endif /* _WIN32 */ |
| 334 | |
| 335 | #ifdef HAVE_BEOS |
| 336 | |
| 337 | #include <kernel/image.h> |
| 338 | |
| 339 | /* |
| 340 | * xmlModulePlatformOpen: |
| 341 | * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html |
| 342 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 343 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 344 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 345 | static void * |
| 346 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 347 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 348 | return (void *) load_add_on(name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* |
| 352 | * xmlModulePlatformClose: |
| 353 | * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html |
| 354 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 355 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 356 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 357 | static int |
| 358 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 359 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 360 | status_t rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 361 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 362 | rc = unload_add_on((image_id) handle); |
| 363 | |
| 364 | if (rc == B_OK) |
| 365 | return 0; |
| 366 | else |
| 367 | return -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | /* |
| 371 | * xmlModulePlatformSymbol: |
| 372 | * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 373 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 374 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 375 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 376 | static int |
| 377 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 378 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 379 | status_t rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 380 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 381 | rc = get_image_symbol((image_id) handle, name, B_SYMBOL_TYPE_ANY, symbol); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 382 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 383 | return (rc == B_OK) ? 0 : -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | #endif /* HAVE_BEOS */ |
| 387 | |
| 388 | #ifdef HAVE_OS2 |
| 389 | |
| 390 | #include <os2.h> |
| 391 | |
| 392 | /* |
| 393 | * xmlModulePlatformOpen: |
| 394 | * os2 api info: http://www.edm2.com/os2api/Dos/DosLoadModule.html |
| 395 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 396 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 397 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 398 | static void * |
| 399 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 400 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 401 | char errbuf[256]; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 402 | void *handle; |
| 403 | int rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 404 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 405 | rc = DosLoadModule(errbuf, sizeof(errbuf) - 1, name, &handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 406 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 407 | if (rc) |
| 408 | return 0; |
| 409 | else |
| 410 | return (handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* |
| 414 | * xmlModulePlatformClose: |
| 415 | * os2 api info: http://www.edm2.com/os2api/Dos/DosFreeModule.html |
| 416 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 417 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 418 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 419 | static int |
| 420 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 421 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 422 | return DosFreeModule(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /* |
| 426 | * xmlModulePlatformSymbol: |
| 427 | * os2 api info: http://www.edm2.com/os2api/Dos/DosQueryProcAddr.html |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 428 | * returns 0 on success and the loaded symbol in result, and -1 on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 429 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 430 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 431 | static int |
| 432 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 433 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 434 | int rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 435 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 436 | rc = DosQueryProcAddr(handle, 0, name, symbol); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 437 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame] | 438 | return (rc == NO_ERROR) ? 0 : -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | #endif /* HAVE_OS2 */ |
| 442 | |
Daniel Veillard | 5d4644e | 2005-04-01 13:11:58 +0000 | [diff] [blame] | 443 | #define bottom_xmlmodule |
| 444 | #include "elfgcchack.h" |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 445 | #endif /* LIBXML_MODULES_ENABLED */ |