OLD | NEW |
1 /* | 1 /* |
2 * extensions.c: Implemetation of the extensions support | 2 * extensions.c: Implemetation of the extensions support |
3 * | 3 * |
4 * Reference: | 4 * Reference: |
5 * http://www.w3.org/TR/1999/REC-xslt-19991116 | 5 * http://www.w3.org/TR/1999/REC-xslt-19991116 |
6 * | 6 * |
7 * See Copyright for the status of this software. | 7 * See Copyright for the status of this software. |
8 * | 8 * |
9 * daniel@veillard.com | 9 * daniel@veillard.com |
10 */ | 10 */ |
(...skipping 26 matching lines...) Expand all Loading... |
37 #ifndef PATH_MAX | 37 #ifndef PATH_MAX |
38 #define PATH_MAX _MAX_PATH | 38 #define PATH_MAX _MAX_PATH |
39 #endif | 39 #endif |
40 #endif | 40 #endif |
41 | 41 |
42 #ifdef WITH_XSLT_DEBUG | 42 #ifdef WITH_XSLT_DEBUG |
43 #define WITH_XSLT_DEBUG_EXTENSIONS | 43 #define WITH_XSLT_DEBUG_EXTENSIONS |
44 #endif | 44 #endif |
45 | 45 |
46 /************************************************************************ | 46 /************************************************************************ |
47 * » » » » » » » » » * | 47 *» » » » » » » » » * |
48 * » » » Private Types and Globals» » » * | 48 *» » » Private Types and Globals» » » * |
49 * » » » » » » » » » * | 49 *» » » » » » » » » * |
50 ************************************************************************/ | 50 ************************************************************************/ |
51 | 51 |
52 typedef struct _xsltExtDef xsltExtDef; | 52 typedef struct _xsltExtDef xsltExtDef; |
53 typedef xsltExtDef *xsltExtDefPtr; | 53 typedef xsltExtDef *xsltExtDefPtr; |
54 struct _xsltExtDef { | 54 struct _xsltExtDef { |
55 struct _xsltExtDef *next; | 55 struct _xsltExtDef *next; |
56 xmlChar *prefix; | 56 xmlChar *prefix; |
57 xmlChar *URI; | 57 xmlChar *URI; |
58 void *data; | 58 void *data; |
59 }; | 59 }; |
(...skipping 22 matching lines...) Expand all Loading... |
82 }; | 82 }; |
83 | 83 |
84 static xmlHashTablePtr xsltExtensionsHash = NULL; | 84 static xmlHashTablePtr xsltExtensionsHash = NULL; |
85 static xmlHashTablePtr xsltFunctionsHash = NULL; | 85 static xmlHashTablePtr xsltFunctionsHash = NULL; |
86 static xmlHashTablePtr xsltElementsHash = NULL; | 86 static xmlHashTablePtr xsltElementsHash = NULL; |
87 static xmlHashTablePtr xsltTopLevelsHash = NULL; | 87 static xmlHashTablePtr xsltTopLevelsHash = NULL; |
88 static xmlHashTablePtr xsltModuleHash = NULL; | 88 static xmlHashTablePtr xsltModuleHash = NULL; |
89 static xmlMutexPtr xsltExtMutex = NULL; | 89 static xmlMutexPtr xsltExtMutex = NULL; |
90 | 90 |
91 /************************************************************************ | 91 /************************************************************************ |
92 * » » » » » » » » » * | 92 *» » » » » » » » » * |
93 * » » » Type functions »» » » » * | 93 *» » » Type functions» » » » » * |
94 * » » » » » » » » » * | 94 *» » » » » » » » » * |
95 ************************************************************************/ | 95 ************************************************************************/ |
96 | 96 |
97 /** | 97 /** |
98 * xsltNewExtDef: | 98 * xsltNewExtDef: |
99 * @prefix: the extension prefix | 99 * @prefix: the extension prefix |
100 * @URI: the namespace URI | 100 * @URI: the namespace URI |
101 * | 101 * |
102 * Create a new XSLT ExtDef | 102 * Create a new XSLT ExtDef |
103 * | 103 * |
104 * Returns the newly allocated xsltExtDefPtr or NULL in case of error | 104 * Returns the newly allocated xsltExtDefPtr or NULL in case of error |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 #ifndef PATH_MAX | 296 #ifndef PATH_MAX |
297 #define PATH_MAX 4096 | 297 #define PATH_MAX 4096 |
298 #endif | 298 #endif |
299 | 299 |
300 /** | 300 /** |
301 * xsltExtModuleRegisterDynamic: | 301 * xsltExtModuleRegisterDynamic: |
302 * @URI: the function or element namespace URI | 302 * @URI: the function or element namespace URI |
303 * | 303 * |
304 * Dynamically loads an extension plugin when available. | 304 * Dynamically loads an extension plugin when available. |
305 * | 305 * |
306 * The plugin name is derived from the URI by removing the | 306 * The plugin name is derived from the URI by removing the |
307 * initial protocol designation, e.g. "http://", then converting | 307 * initial protocol designation, e.g. "http://", then converting |
308 * the characters ".", "-", "/", and "\" into "_", the removing | 308 * the characters ".", "-", "/", and "\" into "_", the removing |
309 * any trailing "/", then concatenating LIBXML_MODULE_EXTENSION. | 309 * any trailing "/", then concatenating LIBXML_MODULE_EXTENSION. |
310 * | 310 * |
311 * Plugins are loaded from the directory specified by the | 311 * Plugins are loaded from the directory specified by the |
312 * environment variable LIBXSLT_PLUGINS_PATH, or if NULL, | 312 * environment variable LIBXSLT_PLUGINS_PATH, or if NULL, |
313 * by LIBXSLT_DEFAULT_PLUGINS_PATH() which is determined at | 313 * by LIBXSLT_DEFAULT_PLUGINS_PATH() which is determined at |
314 * compile time. | 314 * compile time. |
315 * | 315 * |
316 * Returns 0 if successful, -1 in case of error. | 316 * Returns 0 if successful, -1 in case of error. |
317 */ | 317 */ |
318 | 318 |
319 static int | 319 static int |
320 xsltExtModuleRegisterDynamic(const xmlChar * URI) | 320 xsltExtModuleRegisterDynamic(const xmlChar * URI) |
321 { | 321 { |
322 | 322 |
323 xmlModulePtr m; | 323 xmlModulePtr m; |
324 exsltRegisterFunction regfunc; | 324 exsltRegisterFunction regfunc; |
325 xmlChar *ext_name; | 325 xmlChar *ext_name; |
326 char module_filename[PATH_MAX]; | 326 char module_filename[PATH_MAX]; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 "LIBXSLT_PLUGINS_PATH is %s\n", ext_directory); | 384 "LIBXSLT_PLUGINS_PATH is %s\n", ext_directory); |
385 #endif | 385 #endif |
386 | 386 |
387 /* build the module filename, and confirm the module exists */ | 387 /* build the module filename, and confirm the module exists */ |
388 xmlStrPrintf((xmlChar *) module_filename, sizeof(module_filename), | 388 xmlStrPrintf((xmlChar *) module_filename, sizeof(module_filename), |
389 BAD_CAST "%s/%s%s", | 389 BAD_CAST "%s/%s%s", |
390 ext_directory, ext_name, LIBXML_MODULE_EXTENSION); | 390 ext_directory, ext_name, LIBXML_MODULE_EXTENSION); |
391 | 391 |
392 #ifdef WITH_XSLT_DEBUG_EXTENSIONS | 392 #ifdef WITH_XSLT_DEBUG_EXTENSIONS |
393 xsltGenericDebug(xsltGenericDebugContext, | 393 xsltGenericDebug(xsltGenericDebugContext, |
394 "Attempting to load plugin: %s for URI: %s\n", | 394 "Attempting to load plugin: %s for URI: %s\n", |
395 module_filename, URI); | 395 module_filename, URI); |
396 #endif | 396 #endif |
397 | 397 |
398 if (1 != xmlCheckFilename(module_filename)) { | 398 if (1 != xmlCheckFilename(module_filename)) { |
399 | 399 |
400 #ifdef WITH_XSLT_DEBUG_EXTENSIONS | 400 #ifdef WITH_XSLT_DEBUG_EXTENSIONS |
401 xsltGenericDebug(xsltGenericDebugContext, | 401 xsltGenericDebug(xsltGenericDebugContext, |
402 "xmlCheckFilename failed for plugin: %s\n", module_filename
); | 402 "xmlCheckFilename failed for plugin: %s\n", module_filename
); |
403 #endif | 403 #endif |
404 | 404 |
(...skipping 30 matching lines...) Expand all Loading... |
435 (*regfunc) (); | 435 (*regfunc) (); |
436 | 436 |
437 /* register this module in our hash */ | 437 /* register this module in our hash */ |
438 xmlMutexLock(xsltExtMutex); | 438 xmlMutexLock(xsltExtMutex); |
439 xmlHashAddEntry(xsltModuleHash, URI, (void *) m); | 439 xmlHashAddEntry(xsltModuleHash, URI, (void *) m); |
440 xmlMutexUnlock(xsltExtMutex); | 440 xmlMutexUnlock(xsltExtMutex); |
441 } else { | 441 } else { |
442 | 442 |
443 #ifdef WITH_XSLT_DEBUG_EXTENSIONS | 443 #ifdef WITH_XSLT_DEBUG_EXTENSIONS |
444 xsltGenericDebug(xsltGenericDebugContext, | 444 xsltGenericDebug(xsltGenericDebugContext, |
445 "xmlModuleSymbol failed for plugin: %s, regfunc: %s\n", | 445 "xmlModuleSymbol failed for plugin: %s, regfunc: %s\n", |
446 module_filename, regfunc_name); | 446 module_filename, regfunc_name); |
447 #endif | 447 #endif |
448 | 448 |
449 /* if regfunc not found unload the module immediately */ | 449 /* if regfunc not found unload the module immediately */ |
450 xmlModuleClose(m); | 450 xmlModuleClose(m); |
451 } | 451 } |
452 | 452 |
453 xmlFree(ext_name); | 453 xmlFree(ext_name); |
454 xmlFree(regfunc_name); | 454 xmlFree(regfunc_name); |
455 return (NULL == regfunc) ? -1 : 0; | 455 return (NULL == regfunc) ? -1 : 0; |
456 } | 456 } |
457 #else | 457 #else |
458 static int | 458 static int |
459 xsltExtModuleRegisterDynamic(const xmlChar * URI ATTRIBUTE_UNUSED) | 459 xsltExtModuleRegisterDynamic(const xmlChar * URI ATTRIBUTE_UNUSED) |
460 { | 460 { |
461 return -1; | 461 return -1; |
462 } | 462 } |
463 #endif | 463 #endif |
464 | 464 |
465 /************************************************************************ | 465 /************************************************************************ |
466 * » » » » » » » » » * | 466 *» » » » » » » » » * |
467 * » » The stylesheet extension prefixes handling» » * | 467 *» » The stylesheet extension prefixes handling» » * |
468 * » » » » » » » » » * | 468 *» » » » » » » » » * |
469 ************************************************************************/ | 469 ************************************************************************/ |
470 | 470 |
471 | 471 |
472 /** | 472 /** |
473 * xsltFreeExts: | 473 * xsltFreeExts: |
474 * @style: an XSLT stylesheet | 474 * @style: an XSLT stylesheet |
475 * | 475 * |
476 * Free up the memory used by XSLT extensions in a stylesheet | 476 * Free up the memory used by XSLT extensions in a stylesheet |
477 */ | 477 */ |
478 void | 478 void |
479 xsltFreeExts(xsltStylesheetPtr style) | 479 xsltFreeExts(xsltStylesheetPtr style) |
480 { | 480 { |
481 if (style->nsDefs != NULL) | 481 if (style->nsDefs != NULL) |
482 xsltFreeExtDefList((xsltExtDefPtr) style->nsDefs); | 482 xsltFreeExtDefList((xsltExtDefPtr) style->nsDefs); |
483 } | 483 } |
484 | 484 |
485 /** | 485 /** |
486 * xsltRegisterExtPrefix: | 486 * xsltRegisterExtPrefix: |
487 * @style: an XSLT stylesheet | 487 * @style: an XSLT stylesheet |
488 * @prefix: the prefix used (optional) | 488 * @prefix: the prefix used (optional) |
489 * @URI: the URI associated to the extension | 489 * @URI: the URI associated to the extension |
490 * | 490 * |
491 * Registers an extension namespace | 491 * Registers an extension namespace |
492 * This is called from xslt.c during compile-time. | 492 * This is called from xslt.c during compile-time. |
493 * The given prefix is not needed. | 493 * The given prefix is not needed. |
494 * Called by: | 494 * Called by: |
495 * xsltParseExtElemPrefixes() (new function) | 495 * xsltParseExtElemPrefixes() (new function) |
496 * xsltRegisterExtPrefix() (old function) | 496 * xsltRegisterExtPrefix() (old function) |
497 * | 497 * |
498 * Returns 0 in case of success, 1 if the @URI was already | 498 * Returns 0 in case of success, 1 if the @URI was already |
499 * registered as an extension namespace and | 499 * registered as an extension namespace and |
500 * -1 in case of failure | 500 * -1 in case of failure |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 560 } |
561 if (module != NULL) { | 561 if (module != NULL) { |
562 xsltStyleGetExtData(style, URI); | 562 xsltStyleGetExtData(style, URI); |
563 } | 563 } |
564 } | 564 } |
565 #endif | 565 #endif |
566 return (0); | 566 return (0); |
567 } | 567 } |
568 | 568 |
569 /************************************************************************ | 569 /************************************************************************ |
570 * » » » » » » » » » * | 570 *» » » » » » » » » * |
571 * » » The extensions modules interfaces» » » * | 571 *» » The extensions modules interfaces» » » * |
572 * » » » » » » » » » * | 572 *» » » » » » » » » * |
573 ************************************************************************/ | 573 ************************************************************************/ |
574 | 574 |
575 /** | 575 /** |
576 * xsltRegisterExtFunction: | 576 * xsltRegisterExtFunction: |
577 * @ctxt: an XSLT transformation context | 577 * @ctxt: an XSLT transformation context |
578 * @name: the name of the element | 578 * @name: the name of the element |
579 * @URI: the URI associated to the element | 579 * @URI: the URI associated to the element |
580 * @function: the actual implementation which should be called | 580 * @function: the actual implementation which should be called |
581 * | 581 * |
582 * Registers an extension function | 582 * Registers an extension function |
583 * | 583 * |
584 * Returns 0 in case of success, -1 in case of failure | 584 * Returns 0 in case of success, -1 in case of failure |
585 */ | 585 */ |
586 int | 586 int |
587 xsltRegisterExtFunction(xsltTransformContextPtr ctxt, const xmlChar * name, | 587 xsltRegisterExtFunction(xsltTransformContextPtr ctxt, const xmlChar * name, |
588 const xmlChar * URI, xmlXPathFunction function) | 588 const xmlChar * URI, xmlXPathFunction function) |
589 { | 589 { |
590 int ret; | 590 int ret; |
(...skipping 13 matching lines...) Expand all Loading... |
604 XML_CAST_FPTR(function)); | 604 XML_CAST_FPTR(function)); |
605 | 605 |
606 return(ret); | 606 return(ret); |
607 } | 607 } |
608 | 608 |
609 /** | 609 /** |
610 * xsltRegisterExtElement: | 610 * xsltRegisterExtElement: |
611 * @ctxt: an XSLT transformation context | 611 * @ctxt: an XSLT transformation context |
612 * @name: the name of the element | 612 * @name: the name of the element |
613 * @URI: the URI associated to the element | 613 * @URI: the URI associated to the element |
614 * @function: the actual implementation which should be called | 614 * @function: the actual implementation which should be called |
615 * | 615 * |
616 * Registers an extension element | 616 * Registers an extension element |
617 * | 617 * |
618 * Returns 0 in case of success, -1 in case of failure | 618 * Returns 0 in case of success, -1 in case of failure |
619 */ | 619 */ |
620 int | 620 int |
621 xsltRegisterExtElement(xsltTransformContextPtr ctxt, const xmlChar * name, | 621 xsltRegisterExtElement(xsltTransformContextPtr ctxt, const xmlChar * name, |
622 const xmlChar * URI, xsltTransformFunction function) | 622 const xmlChar * URI, xsltTransformFunction function) |
623 { | 623 { |
624 if ((ctxt == NULL) || (name == NULL) || | 624 if ((ctxt == NULL) || (name == NULL) || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 * Returns the create module-data container | 659 * Returns the create module-data container |
660 * or NULL if such a module was not registered. | 660 * or NULL if such a module was not registered. |
661 */ | 661 */ |
662 static xsltExtDataPtr | 662 static xsltExtDataPtr |
663 xsltStyleInitializeStylesheetModule(xsltStylesheetPtr style, | 663 xsltStyleInitializeStylesheetModule(xsltStylesheetPtr style, |
664 const xmlChar * URI) | 664 const xmlChar * URI) |
665 { | 665 { |
666 xsltExtDataPtr dataContainer; | 666 xsltExtDataPtr dataContainer; |
667 void *userData = NULL; | 667 void *userData = NULL; |
668 xsltExtModulePtr module; | 668 xsltExtModulePtr module; |
669 | 669 |
670 if ((style == NULL) || (URI == NULL))» | 670 if ((style == NULL) || (URI == NULL)) |
671 return(NULL); | 671 return(NULL); |
672 | 672 |
673 if (xsltExtensionsHash == NULL) { | 673 if (xsltExtensionsHash == NULL) { |
674 #ifdef WITH_XSLT_DEBUG_EXTENSIONS | 674 #ifdef WITH_XSLT_DEBUG_EXTENSIONS |
675 xsltGenericDebug(xsltGenericDebugContext, | 675 xsltGenericDebug(xsltGenericDebugContext, |
676 "Not registered extension module: %s\n", URI); | 676 "Not registered extension module: %s\n", URI); |
677 #endif | 677 #endif |
678 return(NULL); | 678 return(NULL); |
679 } | 679 } |
680 | 680 |
(...skipping 28 matching lines...) Expand all Loading... |
709 #endif | 709 #endif |
710 } else { | 710 } else { |
711 #ifdef WITH_XSLT_DEBUG_EXTENSIONS | 711 #ifdef WITH_XSLT_DEBUG_EXTENSIONS |
712 xsltGenericDebug(xsltGenericDebugContext, | 712 xsltGenericDebug(xsltGenericDebugContext, |
713 "Initializing module with callback: %s\n", URI); | 713 "Initializing module with callback: %s\n", URI); |
714 #endif | 714 #endif |
715 /* | 715 /* |
716 * Fire the initialization callback. | 716 * Fire the initialization callback. |
717 */ | 717 */ |
718 userData = module->styleInitFunc(style, URI); | 718 userData = module->styleInitFunc(style, URI); |
719 } | 719 } |
720 /* | 720 /* |
721 * Store the user-data in the context of the given stylesheet. | 721 * Store the user-data in the context of the given stylesheet. |
722 */ | 722 */ |
723 dataContainer = xsltNewExtData(module, userData); | 723 dataContainer = xsltNewExtData(module, userData); |
724 if (dataContainer == NULL) | 724 if (dataContainer == NULL) |
725 return (NULL); | 725 return (NULL); |
726 | 726 |
727 if (xmlHashAddEntry(style->extInfos, URI, | 727 if (xmlHashAddEntry(style->extInfos, URI, |
728 (void *) dataContainer) < 0) | 728 (void *) dataContainer) < 0) |
729 { | 729 { |
730 » xsltTransformError(NULL, style, NULL,» | 730 » xsltTransformError(NULL, style, NULL, |
731 "Failed to register module '%s'.\n", URI); | 731 "Failed to register module '%s'.\n", URI); |
732 style->errors++; | 732 style->errors++; |
733 if (module->styleShutdownFunc) | 733 if (module->styleShutdownFunc) |
734 module->styleShutdownFunc(style, URI, userData); | 734 module->styleShutdownFunc(style, URI, userData); |
735 xsltFreeExtData(dataContainer); | 735 xsltFreeExtData(dataContainer); |
736 return (NULL); | 736 return (NULL); |
737 } | 737 } |
738 | 738 |
739 return(dataContainer); | 739 return(dataContainer); |
740 } | 740 } |
(...skipping 14 matching lines...) Expand all Loading... |
755 void * | 755 void * |
756 xsltStyleGetExtData(xsltStylesheetPtr style, const xmlChar * URI) | 756 xsltStyleGetExtData(xsltStylesheetPtr style, const xmlChar * URI) |
757 { | 757 { |
758 xsltExtDataPtr dataContainer = NULL; | 758 xsltExtDataPtr dataContainer = NULL; |
759 xsltStylesheetPtr tmpStyle; | 759 xsltStylesheetPtr tmpStyle; |
760 | 760 |
761 if ((style == NULL) || (URI == NULL) || | 761 if ((style == NULL) || (URI == NULL) || |
762 (xsltExtensionsHash == NULL)) | 762 (xsltExtensionsHash == NULL)) |
763 return (NULL); | 763 return (NULL); |
764 | 764 |
765 | 765 |
766 #ifdef XSLT_REFACTORED | 766 #ifdef XSLT_REFACTORED |
767 /* | 767 /* |
768 * This is intended for global storage, so only the main | 768 * This is intended for global storage, so only the main |
769 * stylesheet will hold the data. | 769 * stylesheet will hold the data. |
770 */ | 770 */ |
771 tmpStyle = style; | 771 tmpStyle = style; |
772 while (tmpStyle->parent != NULL) | 772 while (tmpStyle->parent != NULL) |
773 tmpStyle = tmpStyle->parent; | 773 tmpStyle = tmpStyle->parent; |
774 if (tmpStyle->extInfos != NULL) { | 774 if (tmpStyle->extInfos != NULL) { |
775 dataContainer = | 775 dataContainer = |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 | 831 |
832 if (style->extInfos != NULL) { | 832 if (style->extInfos != NULL) { |
833 dataContainer = (xsltExtDataPtr) xmlHashLookup(style->extInfos, URI); | 833 dataContainer = (xsltExtDataPtr) xmlHashLookup(style->extInfos, URI); |
834 /* | 834 /* |
835 * The module was already initialized in the context | 835 * The module was already initialized in the context |
836 * of this stylesheet; just return the user-data that | 836 * of this stylesheet; just return the user-data that |
837 * comes with it. | 837 * comes with it. |
838 */ | 838 */ |
839 if (dataContainer) | 839 if (dataContainer) |
840 return(dataContainer->extData); | 840 return(dataContainer->extData); |
841 } | 841 } |
842 | 842 |
843 dataContainer = | 843 dataContainer = |
844 xsltStyleInitializeStylesheetModule(style, URI); | 844 xsltStyleInitializeStylesheetModule(style, URI); |
845 if (dataContainer != NULL) | 845 if (dataContainer != NULL) |
846 return (dataContainer->extData); | 846 return (dataContainer->extData); |
847 return(NULL); | 847 return(NULL); |
848 } | 848 } |
849 #endif | 849 #endif |
850 | 850 |
851 /** | 851 /** |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 xsltGenericDebug(xsltGenericDebugContext, | 1113 xsltGenericDebug(xsltGenericDebugContext, |
1114 "Shutting down module : %s\n", URI); | 1114 "Shutting down module : %s\n", URI); |
1115 #endif | 1115 #endif |
1116 module->styleShutdownFunc(style, URI, data->extData); | 1116 module->styleShutdownFunc(style, URI, data->extData); |
1117 /* | 1117 /* |
1118 * Don't remove the entry from the hash table here, since | 1118 * Don't remove the entry from the hash table here, since |
1119 * this will produce segfaults - this fixes bug #340624. | 1119 * this will produce segfaults - this fixes bug #340624. |
1120 * | 1120 * |
1121 * xmlHashRemoveEntry(style->extInfos, URI, | 1121 * xmlHashRemoveEntry(style->extInfos, URI, |
1122 * (xmlHashDeallocator) xsltFreeExtData); | 1122 * (xmlHashDeallocator) xsltFreeExtData); |
1123 */ | 1123 */ |
1124 } | 1124 } |
1125 | 1125 |
1126 /** | 1126 /** |
1127 * xsltShutdownExts: | 1127 * xsltShutdownExts: |
1128 * @style: an XSLT stylesheet | 1128 * @style: an XSLT stylesheet |
1129 * | 1129 * |
1130 * Shutdown the set of modules loaded | 1130 * Shutdown the set of modules loaded |
1131 */ | 1131 */ |
1132 void | 1132 void |
1133 xsltShutdownExts(xsltStylesheetPtr style) | 1133 xsltShutdownExts(xsltStylesheetPtr style) |
(...skipping 15 matching lines...) Expand all Loading... |
1149 * Check if the given prefix is one of the declared extensions. | 1149 * Check if the given prefix is one of the declared extensions. |
1150 * This is intended to be called only at compile-time. | 1150 * This is intended to be called only at compile-time. |
1151 * Called by: | 1151 * Called by: |
1152 * xsltGetInheritedNsList() (xslt.c) | 1152 * xsltGetInheritedNsList() (xslt.c) |
1153 * xsltParseTemplateContent (xslt.c) | 1153 * xsltParseTemplateContent (xslt.c) |
1154 * | 1154 * |
1155 * Returns 1 if this is an extension, 0 otherwise | 1155 * Returns 1 if this is an extension, 0 otherwise |
1156 */ | 1156 */ |
1157 int | 1157 int |
1158 xsltCheckExtPrefix(xsltStylesheetPtr style, const xmlChar * URI) | 1158 xsltCheckExtPrefix(xsltStylesheetPtr style, const xmlChar * URI) |
1159 { | 1159 { |
1160 #ifdef XSLT_REFACTORED | 1160 #ifdef XSLT_REFACTORED |
1161 if ((style == NULL) || (style->compCtxt == NULL) || | 1161 if ((style == NULL) || (style->compCtxt == NULL) || |
1162 (XSLT_CCTXT(style)->inode == NULL) || | 1162 (XSLT_CCTXT(style)->inode == NULL) || |
1163 (XSLT_CCTXT(style)->inode->extElemNs == NULL)) | 1163 (XSLT_CCTXT(style)->inode->extElemNs == NULL)) |
1164 return (0); | 1164 return (0); |
1165 /* | 1165 /* |
1166 * Lookup the extension namespaces registered | 1166 * Lookup the extension namespaces registered |
1167 * at the current node in the stylesheet's tree. | 1167 * at the current node in the stylesheet's tree. |
1168 */ | 1168 */ |
1169 if (XSLT_CCTXT(style)->inode->extElemNs != NULL) { | 1169 if (XSLT_CCTXT(style)->inode->extElemNs != NULL) { |
1170 int i; | 1170 int i; |
1171 xsltPointerListPtr list = XSLT_CCTXT(style)->inode->extElemNs; | 1171 xsltPointerListPtr list = XSLT_CCTXT(style)->inode->extElemNs; |
1172 | 1172 |
1173 for (i = 0; i < list->number; i++) { | 1173 for (i = 0; i < list->number; i++) { |
1174 if (xmlStrEqual((const xmlChar *) list->items[i], | 1174 if (xmlStrEqual((const xmlChar *) list->items[i], |
1175 URI)) | 1175 URI)) |
1176 { | 1176 { |
1177 return(1); | 1177 return(1); |
1178 » }» | 1178 » } |
1179 } | 1179 } |
1180 } | 1180 } |
1181 #else | 1181 #else |
1182 xsltExtDefPtr cur; | 1182 xsltExtDefPtr cur; |
1183 | 1183 |
1184 if ((style == NULL) || (style->nsDefs == NULL)) | 1184 if ((style == NULL) || (style->nsDefs == NULL)) |
1185 return (0); | 1185 return (0); |
1186 if (URI == NULL) | 1186 if (URI == NULL) |
1187 URI = BAD_CAST "#default"; | 1187 URI = BAD_CAST "#default"; |
1188 cur = (xsltExtDefPtr) style->nsDefs; | 1188 cur = (xsltExtDefPtr) style->nsDefs; |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 * | 1615 * |
1616 * Registers an extension module element. | 1616 * Registers an extension module element. |
1617 * | 1617 * |
1618 * Returns 0 if successful, -1 in case of error. | 1618 * Returns 0 if successful, -1 in case of error. |
1619 */ | 1619 */ |
1620 int | 1620 int |
1621 xsltRegisterExtModuleElement(const xmlChar * name, const xmlChar * URI, | 1621 xsltRegisterExtModuleElement(const xmlChar * name, const xmlChar * URI, |
1622 xsltPreComputeFunction precomp, | 1622 xsltPreComputeFunction precomp, |
1623 xsltTransformFunction transform) | 1623 xsltTransformFunction transform) |
1624 { | 1624 { |
1625 int ret; | 1625 int ret = 0; |
1626 | 1626 |
1627 xsltExtElementPtr ext; | 1627 xsltExtElementPtr ext; |
1628 | 1628 |
1629 if ((name == NULL) || (URI == NULL) || (transform == NULL)) | 1629 if ((name == NULL) || (URI == NULL) || (transform == NULL)) |
1630 return (-1); | 1630 return (-1); |
1631 | 1631 |
1632 if (xsltElementsHash == NULL) | 1632 if (xsltElementsHash == NULL) |
1633 xsltElementsHash = xmlHashCreate(10); | 1633 xsltElementsHash = xmlHashCreate(10); |
1634 if (xsltElementsHash == NULL) | 1634 if (xsltElementsHash == NULL) |
1635 return (-1); | 1635 return (-1); |
1636 | 1636 |
1637 xmlMutexLock(xsltExtMutex); | 1637 xmlMutexLock(xsltExtMutex); |
1638 | 1638 |
1639 ext = xsltNewExtElement(precomp, transform); | 1639 ext = xsltNewExtElement(precomp, transform); |
1640 if (ext == NULL) { | 1640 if (ext == NULL) { |
1641 ret = -1; | 1641 ret = -1; |
1642 goto done; | 1642 goto done; |
1643 } | 1643 } |
1644 | 1644 |
1645 xmlHashUpdateEntry2(xsltElementsHash, name, URI, (void *) ext, | 1645 xmlHashUpdateEntry2(xsltElementsHash, name, URI, (void *) ext, |
1646 (xmlHashDeallocator) xsltFreeExtElement); | 1646 (xmlHashDeallocator) xsltFreeExtElement); |
1647 | 1647 |
1648 done: | 1648 done: |
1649 xmlMutexUnlock(xsltExtMutex); | 1649 xmlMutexUnlock(xsltExtMutex); |
1650 | 1650 |
1651 return (0); | 1651 return (ret); |
1652 } | 1652 } |
1653 | 1653 |
1654 /** | 1654 /** |
1655 * xsltExtElementLookup: | 1655 * xsltExtElementLookup: |
1656 * @ctxt: an XSLT process context | 1656 * @ctxt: an XSLT process context |
1657 * @name: the element name | 1657 * @name: the element name |
1658 * @URI: the element namespace URI | 1658 * @URI: the element namespace URI |
1659 * | 1659 * |
1660 * Looks up an extension element. @ctxt can be NULL to search only in | 1660 * Looks up an extension element. @ctxt can be NULL to search only in |
1661 * module elements. | 1661 * module elements. |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 | 1943 |
1944 if (style != NULL && style->extInfos != NULL) { | 1944 if (style != NULL && style->extInfos != NULL) { |
1945 data = xmlHashLookup(style->extInfos, URI); | 1945 data = xmlHashLookup(style->extInfos, URI); |
1946 if (data != NULL && data->extData != NULL) | 1946 if (data != NULL && data->extData != NULL) |
1947 return data->extData; | 1947 return data->extData; |
1948 } | 1948 } |
1949 return NULL; | 1949 return NULL; |
1950 } | 1950 } |
1951 | 1951 |
1952 /************************************************************************ | 1952 /************************************************************************ |
1953 * » » » » » » » » » * | 1953 *» » » » » » » » » * |
1954 * » » Test module http://xmlsoft.org/XSLT/» » » * | 1954 *» » Test module http://xmlsoft.org/XSLT/» » » * |
1955 * » » » » » » » » » * | 1955 *» » » » » » » » » * |
1956 ************************************************************************/ | 1956 ************************************************************************/ |
1957 | 1957 |
1958 /************************************************************************ | 1958 /************************************************************************ |
1959 * » » » » » » » » » * | 1959 *» » » » » » » » » * |
1960 * » » Test of the extension module API» » » * | 1960 *» » Test of the extension module API» » » * |
1961 * » » » » » » » » » * | 1961 *» » » » » » » » » * |
1962 ************************************************************************/ | 1962 ************************************************************************/ |
1963 | 1963 |
1964 static xmlChar *testData = NULL; | 1964 static xmlChar *testData = NULL; |
1965 static xmlChar *testStyleData = NULL; | 1965 static xmlChar *testStyleData = NULL; |
1966 | 1966 |
1967 /** | 1967 /** |
1968 * xsltExtFunctionTest: | 1968 * xsltExtFunctionTest: |
1969 * @ctxt: the XPath Parser context | 1969 * @ctxt: the XPath Parser context |
1970 * @nargs: the number of arguments | 1970 * @nargs: the number of arguments |
1971 * | 1971 * |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 /* cleanup dynamic module hash */ | 2282 /* cleanup dynamic module hash */ |
2283 if (NULL != xsltModuleHash) { | 2283 if (NULL != xsltModuleHash) { |
2284 xmlHashScan(xsltModuleHash, xsltHashScannerModuleFree, 0); | 2284 xmlHashScan(xsltModuleHash, xsltHashScannerModuleFree, 0); |
2285 xmlHashFree(xsltModuleHash, NULL); | 2285 xmlHashFree(xsltModuleHash, NULL); |
2286 xsltModuleHash = NULL; | 2286 xsltModuleHash = NULL; |
2287 } | 2287 } |
2288 xmlMutexUnlock(xsltExtMutex); | 2288 xmlMutexUnlock(xsltExtMutex); |
2289 | 2289 |
2290 xmlFreeMutex(xsltExtMutex); | 2290 xmlFreeMutex(xsltExtMutex); |
2291 xsltExtMutex = NULL; | 2291 xsltExtMutex = NULL; |
| 2292 xsltFreeLocales(); |
2292 xsltUninit(); | 2293 xsltUninit(); |
2293 } | 2294 } |
2294 | 2295 |
2295 static void | 2296 static void |
2296 xsltDebugDumpExtensionsCallback(void *function ATTRIBUTE_UNUSED, | 2297 xsltDebugDumpExtensionsCallback(void *function ATTRIBUTE_UNUSED, |
2297 FILE * output, const xmlChar * name, | 2298 FILE * output, const xmlChar * name, |
2298 const xmlChar * URI, | 2299 const xmlChar * URI, |
2299 const xmlChar * not_used ATTRIBUTE_UNUSED) | 2300 const xmlChar * not_used ATTRIBUTE_UNUSED) |
2300 { | 2301 { |
2301 if (!name || !URI) | 2302 if (!name || !URI) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2352 else { | 2353 else { |
2353 fprintf(output, "\nRegistered Extension Modules:\n"); | 2354 fprintf(output, "\nRegistered Extension Modules:\n"); |
2354 xmlMutexLock(xsltExtMutex); | 2355 xmlMutexLock(xsltExtMutex); |
2355 xmlHashScanFull(xsltExtensionsHash, | 2356 xmlHashScanFull(xsltExtensionsHash, |
2356 (xmlHashScannerFull) | 2357 (xmlHashScannerFull) |
2357 xsltDebugDumpExtModulesCallback, output); | 2358 xsltDebugDumpExtModulesCallback, output); |
2358 xmlMutexUnlock(xsltExtMutex); | 2359 xmlMutexUnlock(xsltExtMutex); |
2359 } | 2360 } |
2360 | 2361 |
2361 } | 2362 } |
OLD | NEW |