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 |
| 61 | * |
| 62 | * Opens a module/shared library given its name or path |
| 63 | * |
| 64 | * Returns a handle for the module or NULL in case of error |
| 65 | */ |
| 66 | xmlModulePtr |
| 67 | xmlModuleOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 68 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 69 | xmlModulePtr module; |
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 | module = (xmlModulePtr) xmlMalloc(sizeof(xmlModule)); |
| 72 | if (module == NULL) { |
| 73 | xmlModuleErrMemory(NULL, "creating module"); |
| 74 | return (NULL); |
| 75 | } |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 76 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 77 | memset(module, 0, sizeof(xmlModule)); |
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 | module->handle = xmlModulePlatformOpen(name); |
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 | if (module->handle == NULL) { |
| 82 | xmlFree(module); |
| 83 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 84 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
| 85 | name, NULL, 0, 0, "failed to open %s\n", name); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | module->name = xmlStrdup((const xmlChar *) name); |
| 90 | return (module); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * xmlModuleSymbol: |
| 95 | * @module: the module |
| 96 | * @name: the name of the symbol |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 97 | * @symbol: the resulting symbol address |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 98 | * |
| 99 | * Lookup for a symbol address in the given module |
| 100 | * |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 101 | * 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] | 102 | */ |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 103 | int |
| 104 | xmlModuleSymbol(xmlModulePtr module, const char *name, void **symbol) |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 105 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 106 | int rc = -1; |
| 107 | |
| 108 | if ((NULL == module) || (symbol == NULL)) { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 109 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 110 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 111 | NULL, NULL, 0, 0, "null parameter\n"); |
| 112 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 115 | rc = xmlModulePlatformSymbol(module->handle, name, symbol); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 116 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 117 | if (rc == -1) { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 118 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
| 119 | XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 120 | name, NULL, 0, 0, |
| 121 | "failed to find symbol: %s\n", |
| 122 | (name == NULL ? "NULL" : name)); |
| 123 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 126 | return rc; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * xmlModuleClose: |
| 131 | * @module: the module handle |
| 132 | * |
| 133 | * The close operations unload the associated module and free the |
| 134 | * data associated to the module. |
| 135 | * |
| 136 | * Returns 0 in case of success, -1 in case of argument error and -2 |
| 137 | * if the module could not be closed/unloaded. |
| 138 | */ |
| 139 | int |
| 140 | xmlModuleClose(xmlModulePtr module) |
| 141 | { |
| 142 | int rc; |
| 143 | |
| 144 | if (NULL == module) { |
| 145 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 146 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0, |
| 147 | NULL, NULL, 0, 0, "null module pointer\n"); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 148 | return -1; |
| 149 | } |
| 150 | |
| 151 | rc = xmlModulePlatformClose(module->handle); |
| 152 | |
| 153 | if (rc != 0) { |
| 154 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 155 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0, |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 156 | (const char *) module->name, NULL, 0, 0, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 157 | "failed to close: %s\n", module->name); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 158 | return -2; |
| 159 | } |
| 160 | |
| 161 | rc = xmlModuleFree(module); |
| 162 | return (rc); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * xmlModuleFree: |
| 167 | * @module: the module handle |
| 168 | * |
| 169 | * The free operations free the data associated to the module |
| 170 | * but does not unload the associated shared library which may still |
| 171 | * be in use. |
| 172 | * |
| 173 | * Returns 0 in case of success, -1 in case of argument error |
| 174 | */ |
| 175 | int |
| 176 | xmlModuleFree(xmlModulePtr module) |
| 177 | { |
| 178 | if (NULL == module) { |
| 179 | __xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE, |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 180 | XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0, |
| 181 | NULL, NULL, 0, 0, "null module pointer\n"); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | xmlFree(module->name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 186 | xmlFree(module); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 187 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 188 | return (0); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | #ifdef HAVE_DLOPEN |
| 192 | |
| 193 | #include <dlfcn.h> |
| 194 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 195 | /** |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 196 | * xmlModulePlatformOpen: |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 197 | * @name: path to the module |
| 198 | * |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 199 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 200 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 201 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 202 | static void * |
| 203 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 204 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 205 | return dlopen(name, RTLD_GLOBAL | RTLD_NOW); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* |
| 209 | * xmlModulePlatformClose: |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 210 | * @handle: handle to the module |
| 211 | * |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 212 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 213 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 214 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 215 | static int |
| 216 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 217 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 218 | return dlclose(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* |
| 222 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 223 | * http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html |
| 224 | * 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] | 225 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 226 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 227 | static int |
| 228 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 229 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 230 | *symbol = dlsym(handle, name); |
| 231 | if (dlerror() != NULL) { |
| 232 | return -1; |
| 233 | } |
| 234 | return 0; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | #endif /* HAVE_DLOPEN */ |
| 238 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 239 | #ifdef HAVE_SHLLOAD /* HAVE_SHLLOAD */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 240 | |
| 241 | /* |
| 242 | * xmlModulePlatformOpen: |
| 243 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 244 | */ |
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 | static void * |
| 247 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 248 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 249 | return shl_load(name, BIND_IMMEDIATE, 0L); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /* |
| 253 | * xmlModulePlatformClose: |
| 254 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 255 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 256 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 257 | static int |
| 258 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 259 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 260 | return shl_unload(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* |
| 264 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 265 | * http://docs.hp.com/en/B2355-90683/shl_load.3X.html |
| 266 | * 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] | 267 | */ |
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 | static int |
| 270 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 271 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 272 | int rc; |
| 273 | |
| 274 | errno = 0; |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 275 | rc = shl_findsym(handle, name, TYPE_PROCEDURE, symbol); |
| 276 | if ((-1 == rc) && (0 == errno)) { |
| 277 | rc = shl_findsym(handle, name, TYPE_DATA, symbol); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 278 | } |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 279 | return rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | #endif /* HAVE_SHLLOAD */ |
| 283 | |
| 284 | #ifdef _WIN32 |
| 285 | |
| 286 | #include <windows.h> |
| 287 | |
| 288 | /* |
| 289 | * xmlModulePlatformOpen: |
| 290 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 291 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 292 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 293 | static void * |
| 294 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 295 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 296 | return LoadLibrary(name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* |
| 300 | * xmlModulePlatformClose: |
| 301 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 302 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 303 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 304 | static int |
| 305 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 306 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 307 | int rc; |
| 308 | |
| 309 | rc = FreeLibrary(handle); |
| 310 | return (0 == rc); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /* |
| 314 | * xmlModulePlatformSymbol: |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 315 | * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getprocaddress.asp |
| 316 | * 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] | 317 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 318 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 319 | static int |
| 320 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 321 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 322 | *symbol = GetProcAddress(handle, name); |
| 323 | return (NULL == *symbol) ? -1 : 0; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | #endif /* _WIN32 */ |
| 327 | |
| 328 | #ifdef HAVE_BEOS |
| 329 | |
| 330 | #include <kernel/image.h> |
| 331 | |
| 332 | /* |
| 333 | * xmlModulePlatformOpen: |
| 334 | * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html |
| 335 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 336 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 337 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 338 | static void * |
| 339 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 340 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 341 | return (void *) load_add_on(name); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /* |
| 345 | * xmlModulePlatformClose: |
| 346 | * beos api info: http://www.beunited.org/bebook/The%20Kernel%20Kit/Images.html |
| 347 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 348 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 349 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 350 | static int |
| 351 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 352 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 353 | status_t rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 354 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 355 | rc = unload_add_on((image_id) handle); |
| 356 | |
| 357 | if (rc == B_OK) |
| 358 | return 0; |
| 359 | else |
| 360 | return -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /* |
| 364 | * xmlModulePlatformSymbol: |
| 365 | * 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^] | 366 | * 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] | 367 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 368 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 369 | static int |
| 370 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 371 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 372 | status_t rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 373 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 374 | 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] | 375 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 376 | return (rc == B_OK) ? 0 : -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | #endif /* HAVE_BEOS */ |
| 380 | |
| 381 | #ifdef HAVE_OS2 |
| 382 | |
| 383 | #include <os2.h> |
| 384 | |
| 385 | /* |
| 386 | * xmlModulePlatformOpen: |
| 387 | * os2 api info: http://www.edm2.com/os2api/Dos/DosLoadModule.html |
| 388 | * returns a handle on success, and zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 389 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 390 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 391 | static void * |
| 392 | xmlModulePlatformOpen(const char *name) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 393 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 394 | char errbuf[256]; |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 395 | void *handle; |
| 396 | int rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 397 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 398 | rc = DosLoadModule(errbuf, sizeof(errbuf) - 1, name, &handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 399 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 400 | if (rc) |
| 401 | return 0; |
| 402 | else |
| 403 | return (handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* |
| 407 | * xmlModulePlatformClose: |
| 408 | * os2 api info: http://www.edm2.com/os2api/Dos/DosFreeModule.html |
| 409 | * returns 0 on success, and non-zero on error. |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 410 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 411 | |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 412 | static int |
| 413 | xmlModulePlatformClose(void *handle) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 414 | { |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 415 | return DosFreeModule(handle); |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /* |
| 419 | * xmlModulePlatformSymbol: |
| 420 | * os2 api info: http://www.edm2.com/os2api/Dos/DosQueryProcAddr.html |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 421 | * 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] | 422 | */ |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 423 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 424 | static int |
| 425 | xmlModulePlatformSymbol(void *handle, const char *name, void **symbol) |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 426 | { |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 427 | int rc; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 428 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 429 | rc = DosQueryProcAddr(handle, 0, name, symbol); |
Daniel Veillard | f6b71bd | 2005-01-04 17:50:14 +0000 | [diff] [blame] | 430 | |
Daniel Veillard | be076e9 | 2005-01-04 20:18:14 +0000 | [diff] [blame^] | 431 | return (rc == NO_ERROR) ? 0 : -1; |
Daniel Veillard | ce1648b | 2005-01-04 15:10:22 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | #endif /* HAVE_OS2 */ |
| 435 | |
| 436 | #endif /* LIBXML_MODULES_ENABLED */ |