├── THIS_VERSION_IS_1.1.45 ├── distfiles ├── download.url ├── libxslt-1.1.45.tar.xz ├── libxslt-1.1.45-import.lst └── libxslt-1.1.45-import.md5 ├── libxslt ├── transformInternals.h ├── preproc.h ├── attributes.h ├── xsltlocale.h ├── win32config.h ├── keys.h ├── xsltexports.h ├── libxslt.h ├── extra.h ├── namespaces.h ├── imports.h ├── functions.h ├── numbersInternals.h ├── pattern.h ├── xslt.h ├── templates.h ├── documents.h ├── security.h ├── variables.h ├── xsltconfig.h ├── extra.c ├── transform.h ├── triodef.h ├── extensions.h ├── trio.h ├── xsltutils.h ├── attrvt.c ├── imports.c ├── documents.c └── security.c ├── win32 ├── rcVersion.h ├── libxslt.rc └── libexslt.rc ├── README.libxslt.md ├── .gitignore ├── libexslt ├── libexslt.h ├── exslt.c ├── exsltexports.h ├── exsltconfig.h ├── common.c ├── exslt.h ├── sets.c ├── dynamic.c └── saxon.c ├── INSTALL ├── README.md ├── AUTHORS ├── Copyright ├── TODO ├── FEATURES └── xsltproc └── testThreads.c /THIS_VERSION_IS_1.1.45: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /distfiles/download.url: -------------------------------------------------------------------------------- 1 | https://download.gnome.org/sources/libxslt/1.1/libxslt-1.1.45.tar.xz 2 | -------------------------------------------------------------------------------- /distfiles/libxslt-1.1.45.tar.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kiyolee/libxslt-win-build/HEAD/distfiles/libxslt-1.1.45.tar.xz -------------------------------------------------------------------------------- /libxslt/transformInternals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: set of internal interfaces for the XSLT engine transformation part. 3 | * 4 | * Copy: See Copyright for the status of this software. 5 | * 6 | * Author: David Kilzer 7 | */ 8 | 9 | void xsltCleanupSourceDoc(xmlDocPtr doc); 10 | -------------------------------------------------------------------------------- /win32/rcVersion.h: -------------------------------------------------------------------------------- 1 | #define LIBXSLT_MAJOR_VERSION 1 2 | #define LIBXSLT_MINOR_VERSION 1 3 | #define LIBXSLT_MICRO_VERSION 45 4 | #define LIBXSLT_DOTTED_VERSION "1.1.45" 5 | 6 | #define LIBEXSLT_MAJOR_VERSION 0 7 | #define LIBEXSLT_MINOR_VERSION 8 8 | #define LIBEXSLT_MICRO_VERSION 25 9 | #define LIBEXSLT_DOTTED_VERSION "0.8.25" 10 | -------------------------------------------------------------------------------- /README.libxslt.md: -------------------------------------------------------------------------------- 1 | # libxslt 2 | 3 | libxslt is an XSLT processor based on libxml2. 4 | 5 | Official releases can be downloaded from 6 | 7 | 8 | The git repository is hosted on GNOME's GitLab server: 9 | 10 | 11 | Bugs should be reported at 12 | 13 | 14 | Documentation is available at 15 | 16 | 17 | The build system is similar to libxml2. Refer to libxml2's README for 18 | build instructions. 19 | 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.VC.db 2 | *.log 3 | *.opensdf 4 | *.sdf 5 | *~ 6 | /build-*/*/ARM/Debug 7 | /build-*/*/ARM/Release 8 | /build-*/*/ARM64/Debug 9 | /build-*/*/ARM64/Release 10 | /build-*/*/Debug 11 | /build-*/*/Release 12 | /build-*/*/x64/Debug 13 | /build-*/*/x64/Release 14 | /build-*/ARM/Debug 15 | /build-*/ARM/Release 16 | /build-*/ARM64/Debug 17 | /build-*/ARM64/Release 18 | /build-*/Debug 19 | /build-*/Release 20 | /build-*/tests/*/ARM/Debug 21 | /build-*/tests/*/ARM/Release 22 | /build-*/tests/*/ARM64/Debug 23 | /build-*/tests/*/ARM64/Release 24 | /build-*/tests/*/Debug 25 | /build-*/tests/*/Release 26 | /build-*/tests/*/x64/Debug 27 | /build-*/tests/*/x64/Release 28 | /build-*/x64/Debug 29 | /build-*/x64/Release 30 | -------------------------------------------------------------------------------- /libexslt/libexslt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libexslt.h: internal header only used during the compilation of libexslt 3 | * 4 | * See COPYRIGHT for the status of this software 5 | * 6 | * Author: daniel@veillard.com 7 | */ 8 | 9 | #ifndef __XSLT_LIBEXSLT_H__ 10 | #define __XSLT_LIBEXSLT_H__ 11 | 12 | #if defined(_WIN32) && !defined (__MINGW32__) 13 | #include 14 | #else 15 | #include "config.h" 16 | #endif 17 | 18 | #include 19 | #include 20 | 21 | #if !defined LIBEXSLT_PUBLIC 22 | #if (defined (__CYGWIN__) || defined _MSC_VER) && !defined IN_LIBEXSLT && !defined LIBEXSLT_STATIC 23 | #define LIBEXSLT_PUBLIC __declspec(dllimport) 24 | #else 25 | #define LIBEXSLT_PUBLIC 26 | #endif 27 | #endif 28 | 29 | #ifdef __GNUC__ 30 | #define ATTRIBUTE_UNUSED __attribute__((unused)) 31 | #else 32 | #define ATTRIBUTE_UNUSED 33 | #endif 34 | 35 | #endif /* ! __XSLT_LIBEXSLT_H__ */ 36 | -------------------------------------------------------------------------------- /libexslt/exslt.c: -------------------------------------------------------------------------------- 1 | #define IN_LIBEXSLT 2 | #include "libexslt/libexslt.h" 3 | 4 | #include 5 | 6 | #include 7 | #include "exslt.h" 8 | 9 | const char *exsltLibraryVersion = LIBEXSLT_VERSION_STRING 10 | LIBEXSLT_VERSION_EXTRA; 11 | const int exsltLibexsltVersion = LIBEXSLT_VERSION; 12 | const int exsltLibxsltVersion = LIBXSLT_VERSION; 13 | const int exsltLibxmlVersion = LIBXML_VERSION; 14 | 15 | /** 16 | * exsltRegisterAll: 17 | * 18 | * Registers all available EXSLT extensions 19 | */ 20 | void 21 | exsltRegisterAll (void) { 22 | xsltInitGlobals(); 23 | exsltCommonRegister(); 24 | #ifdef EXSLT_CRYPTO_ENABLED 25 | exsltCryptoRegister(); 26 | #endif 27 | exsltMathRegister(); 28 | exsltSetsRegister(); 29 | exsltFuncRegister(); 30 | exsltStrRegister(); 31 | exsltDateRegister(); 32 | exsltSaxonRegister(); 33 | exsltDynRegister(); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /libxslt/preproc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: precomputing stylesheets 3 | * Description: this is the compilation phase, where most of the 4 | * stylesheet is "compiled" into faster to use data. 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Daniel Veillard 9 | */ 10 | 11 | #ifndef __XML_XSLT_PRECOMP_H__ 12 | #define __XML_XSLT_PRECOMP_H__ 13 | 14 | #include 15 | #include "xsltexports.h" 16 | #include "xsltInternals.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /* 23 | * Interfaces 24 | */ 25 | XSLTPUBVAR const xmlChar *xsltExtMarker; 26 | 27 | XSLTPUBFUN xsltElemPreCompPtr XSLTCALL 28 | xsltDocumentComp (xsltStylesheetPtr style, 29 | xmlNodePtr inst, 30 | xsltTransformFunction function); 31 | 32 | XSLTPUBFUN void XSLTCALL 33 | xsltStylePreCompute (xsltStylesheetPtr style, 34 | xmlNodePtr inst); 35 | XSLTPUBFUN void XSLTCALL 36 | xsltFreeStylePreComps (xsltStylesheetPtr style); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* __XML_XSLT_PRECOMP_H__ */ 43 | 44 | -------------------------------------------------------------------------------- /libxslt/attributes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the XSLT attribute handling 3 | * Description: this module handles the specificities of attribute 4 | * and attribute groups processing. 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Daniel Veillard 9 | */ 10 | 11 | #ifndef __XML_XSLT_ATTRIBUTES_H__ 12 | #define __XML_XSLT_ATTRIBUTES_H__ 13 | 14 | #include 15 | #include "xsltexports.h" 16 | #include "xsltInternals.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | XSLTPUBFUN void XSLTCALL 23 | xsltParseStylesheetAttributeSet (xsltStylesheetPtr style, 24 | xmlNodePtr cur); 25 | XSLTPUBFUN void XSLTCALL 26 | xsltFreeAttributeSetsHashes (xsltStylesheetPtr style); 27 | XSLTPUBFUN void XSLTCALL 28 | xsltApplyAttributeSet (xsltTransformContextPtr ctxt, 29 | xmlNodePtr node, 30 | xmlNodePtr inst, 31 | const xmlChar *attributes); 32 | XSLTPUBFUN void XSLTCALL 33 | xsltResolveStylesheetAttributeSet(xsltStylesheetPtr style); 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* __XML_XSLT_ATTRIBUTES_H__ */ 39 | 40 | -------------------------------------------------------------------------------- /libxslt/xsltlocale.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: Locale handling 3 | * Description: Interfaces for locale handling. Needed for language dependent 4 | * sorting. 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Nick Wellnhofer 9 | */ 10 | 11 | #ifndef __XML_XSLTLOCALE_H__ 12 | #define __XML_XSLTLOCALE_H__ 13 | 14 | #include 15 | #include "xsltexports.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | XSLTPUBFUN void * XSLTCALL 22 | xsltNewLocale (const xmlChar *langName, 23 | int lowerFirst); 24 | XSLTPUBFUN void XSLTCALL 25 | xsltFreeLocale (void *locale); 26 | XSLTPUBFUN xmlChar * XSLTCALL 27 | xsltStrxfrm (void *locale, 28 | const xmlChar *string); 29 | XSLTPUBFUN void XSLTCALL 30 | xsltFreeLocales (void); 31 | 32 | /* Backward compatibility */ 33 | typedef void *xsltLocale; 34 | typedef xmlChar xsltLocaleChar; 35 | XSLTPUBFUN int XSLTCALL 36 | xsltLocaleStrcmp (void *locale, 37 | const xmlChar *str1, 38 | const xmlChar *str2); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* __XML_XSLTLOCALE_H__ */ 45 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | How to install the XSLT library: 2 | 3 | Requirements: 4 | ============= 5 | 6 | this library requires a recent version of libxml2 which you can grab from 7 | either the GNOME download server or the GitLab release page: 8 | 9 | https://gitlab.gnome.org/GNOME/libxml2/-/releases 10 | https://download.gnome.org/sources/libxml2/ 11 | 12 | When installing from a distribution package like a tar.gz: 13 | ========================================================== 14 | 15 | expand the package 16 | 17 | run ./configure possibly indicating the desired installation prefix: 18 | 19 | ./configure --prefix=/usr 20 | 21 | then run 22 | 23 | make 24 | 25 | to build the project and 26 | 27 | make install 28 | 29 | (possibly after having gained root access) to install the library 30 | and associated include and scripts. 31 | 32 | When installing from a Git clone: 33 | ================================= 34 | 35 | 36 | run ./autogen.sh possibly indicating the desired installation prefix: 37 | 38 | ./autogen.sh --prefix=/usr 39 | 40 | then run 41 | 42 | make 43 | 44 | to build the project and 45 | 46 | make install 47 | 48 | (possibly after having gained root access) to instal the library 49 | and associated include and scripts. 50 | 51 | -------------------------------------------------------------------------------- /win32/libxslt.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rcVersion.h" 3 | 4 | VS_VERSION_INFO VERSIONINFO 5 | FILEVERSION LIBXSLT_MAJOR_VERSION,LIBXSLT_MINOR_VERSION,LIBXSLT_MICRO_VERSION,0 6 | PRODUCTVERSION LIBXSLT_MAJOR_VERSION,LIBXSLT_MINOR_VERSION,LIBXSLT_MICRO_VERSION,0 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 8 | #ifdef _DEBUG 9 | FILEFLAGS VS_FF_DEBUG 10 | #else 11 | FILEFLAGS 0 12 | #endif 13 | FILEOS VOS__WINDOWS32 14 | FILETYPE VFT_DLL 15 | FILESUBTYPE VFT2_UNKNOWN // not used 16 | BEGIN 17 | BLOCK "StringFileInfo" 18 | BEGIN 19 | BLOCK "04090000" /* Lang = US English, Charset = ASCII */ 20 | BEGIN 21 | VALUE "FileDescription", "libxslt library\0" 22 | VALUE "FileVersion", LIBXSLT_DOTTED_VERSION "\0" 23 | VALUE "InternalName", "libxslt.dll\0" 24 | VALUE "LegalCopyright", "Copyright (C) Daniel Veillard\0" 25 | VALUE "LegalTrademarks", "\0" 26 | VALUE "OriginalFilename", "libxslt.dll\0" 27 | VALUE "ProductName", "libxslt\0" 28 | VALUE "ProductVersion", LIBXSLT_DOTTED_VERSION "\0" 29 | VALUE "Comments", "For more information visit . Alternative build from .\0" 30 | END 31 | END 32 | BLOCK "VarFileInfo" 33 | BEGIN 34 | VALUE "Translation", 0x0409, 0 /* US English, ASCII */ 35 | END 36 | END 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libxslt-win-build 2 | 3 | libxslt Windows build with Visual Studio. 4 | 5 | This version is libxslt-1.1.45. 6 | 7 | Note that LZMA support is now available for libxml2-2.12.0 or later but only for VS2013 or later. 8 | 9 | To build, simply open the required solution file, and 10 | you know how to use Visual Studio, right? 11 | (or perhaps this is the wrong place for you.) 12 | 13 | Depends on: 14 | * libxml2-win-build 15 | * libiconv-win-build 16 | * zlib-win-build 17 | * xz-win-build (VS2013 or later) 18 | 19 | There are hard references assuming all these sit next to libxslt-win-build. 20 | 21 | Basically, in a command prompt: 22 | 23 | > \> cd {somewhere}\\ 24 | > \> git clone https://github.com/kiyolee/libiconv-win-build.git 25 | > \> git clone https://github.com/kiyolee/zlib-win-build.git 26 | > \> git clone https://github.com/kiyolee/xz-win-build.git (VS2013 or later) 27 | > \> git clone https://github.com/kiyolee/libxml2-win-build.git 28 | > \> git clone https://github.com/kiyolee/libxslt-win-build.git 29 | 30 | Build all these dependencies in the suggested order as shown above and 31 | finally libxslt, with the same corresponding Visual Studio solution of course. 32 | 33 | This repository tracks only officially released versions of libxslt. 34 | Check branch win-build of https://github.com/kiyolee/libxslt.git that follows latest development. 35 | -------------------------------------------------------------------------------- /libexslt/exsltexports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: macros for marking symbols as exportable/importable. 3 | * 4 | * Copy: See Copyright for the status of this software. 5 | */ 6 | 7 | #ifndef __EXSLT_EXPORTS_H__ 8 | #define __EXSLT_EXPORTS_H__ 9 | 10 | #if defined(_WIN32) || defined(__CYGWIN__) 11 | /** DOC_DISABLE */ 12 | 13 | #ifdef LIBEXSLT_STATIC 14 | #define EXSLTPUBLIC 15 | #elif defined(IN_LIBEXSLT) 16 | #define EXSLTPUBLIC __declspec(dllexport) 17 | #else 18 | #define EXSLTPUBLIC __declspec(dllimport) 19 | #endif 20 | 21 | #define EXSLTCALL __cdecl 22 | 23 | /** DOC_ENABLE */ 24 | #else /* not Windows */ 25 | 26 | /** 27 | * EXSLTPUBLIC: 28 | * 29 | * Macro which declares a public symbol 30 | */ 31 | #define EXSLTPUBLIC 32 | 33 | /** 34 | * EXSLTCALL: 35 | * 36 | * Macro which declares the calling convention for exported functions 37 | */ 38 | #define EXSLTCALL 39 | 40 | #endif /* platform switch */ 41 | 42 | /* 43 | * EXSLTPUBFUN: 44 | * 45 | * Macro which declares an exportable function 46 | */ 47 | #define EXSLTPUBFUN EXSLTPUBLIC 48 | 49 | /** 50 | * EXSLTPUBVAR: 51 | * 52 | * Macro which declares an exportable variable 53 | */ 54 | #define EXSLTPUBVAR EXSLTPUBLIC extern 55 | 56 | /* Compatibility */ 57 | #if !defined(LIBEXSLT_PUBLIC) 58 | #define LIBEXSLT_PUBLIC EXSLTPUBVAR 59 | #endif 60 | 61 | #endif /* __EXSLT_EXPORTS_H__ */ 62 | 63 | 64 | -------------------------------------------------------------------------------- /libxslt/win32config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: Windows configuration header 3 | * Description: Windows configuration header 4 | * 5 | * Copy: See Copyright for the status of this software. 6 | * 7 | * Author: Igor Zlatkovic 8 | */ 9 | #ifndef __LIBXSLT_WIN32_CONFIG__ 10 | #define __LIBXSLT_WIN32_CONFIG__ 11 | 12 | #define MODULE_EXTENSION ".dll" 13 | 14 | /* snprintf emulation taken from http://stackoverflow.com/a/8712996/1956010 */ 15 | #if defined(_MSC_VER) && _MSC_VER < 1900 16 | 17 | #include 18 | #include 19 | 20 | #define snprintf c99_snprintf 21 | #define vsnprintf c99_vsnprintf 22 | 23 | __inline int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) 24 | { 25 | int count = -1; 26 | 27 | if (size != 0) 28 | count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap); 29 | if (count == -1) 30 | count = _vscprintf(format, ap); 31 | 32 | return count; 33 | } 34 | 35 | __inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...) 36 | { 37 | int count; 38 | va_list ap; 39 | 40 | va_start(ap, format); 41 | count = c99_vsnprintf(outBuf, size, format, ap); 42 | va_end(ap); 43 | 44 | return count; 45 | } 46 | 47 | #endif /* defined(_MSC_VER) && _MSC_VER < 1900 */ 48 | 49 | #define HAVE_SYS_STAT_H 50 | #define HAVE__STAT 51 | 52 | #endif /* __LIBXSLT_WIN32_CONFIG__ */ 53 | 54 | -------------------------------------------------------------------------------- /libxslt/keys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the key matching used in key() and template matches. 3 | * Description: implementation of the key mechanims. 4 | * 5 | * Copy: See Copyright for the status of this software. 6 | * 7 | * Author: Daniel Veillard 8 | */ 9 | 10 | #ifndef __XML_XSLT_KEY_H__ 11 | #define __XML_XSLT_KEY_H__ 12 | 13 | #include 14 | #include "xsltexports.h" 15 | #include "xsltInternals.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /** 22 | * NODE_IS_KEYED: 23 | * 24 | * check for bit 15 set 25 | */ 26 | #define NODE_IS_KEYED (1 >> 15) 27 | 28 | XSLTPUBFUN int XSLTCALL 29 | xsltAddKey (xsltStylesheetPtr style, 30 | const xmlChar *name, 31 | const xmlChar *nameURI, 32 | const xmlChar *match, 33 | const xmlChar *use, 34 | xmlNodePtr inst); 35 | XSLTPUBFUN xmlNodeSetPtr XSLTCALL 36 | xsltGetKey (xsltTransformContextPtr ctxt, 37 | const xmlChar *name, 38 | const xmlChar *nameURI, 39 | const xmlChar *value); 40 | XSLTPUBFUN void XSLTCALL 41 | xsltInitCtxtKeys (xsltTransformContextPtr ctxt, 42 | xsltDocumentPtr doc); 43 | XSLTPUBFUN void XSLTCALL 44 | xsltFreeKeys (xsltStylesheetPtr style); 45 | XSLTPUBFUN void XSLTCALL 46 | xsltFreeDocumentKeys (xsltDocumentPtr doc); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* __XML_XSLT_H__ */ 53 | 54 | -------------------------------------------------------------------------------- /win32/libexslt.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rcVersion.h" 3 | 4 | VS_VERSION_INFO VERSIONINFO 5 | FILEVERSION LIBEXSLT_MAJOR_VERSION,LIBEXSLT_MINOR_VERSION,LIBEXSLT_MICRO_VERSION,0 6 | PRODUCTVERSION LIBEXSLT_MAJOR_VERSION,LIBEXSLT_MINOR_VERSION,LIBEXSLT_MICRO_VERSION,0 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 8 | #ifdef _DEBUG 9 | FILEFLAGS VS_FF_DEBUG 10 | #else 11 | FILEFLAGS 0 12 | #endif 13 | FILEOS VOS__WINDOWS32 14 | FILETYPE VFT_DLL 15 | FILESUBTYPE VFT2_UNKNOWN // not used 16 | BEGIN 17 | BLOCK "StringFileInfo" 18 | BEGIN 19 | BLOCK "04090000" /* Lang = US English, Charset = ASCII */ 20 | BEGIN 21 | VALUE "FileDescription", "libexslt library\0" 22 | VALUE "FileVersion", LIBEXSLT_DOTTED_VERSION "\0" 23 | VALUE "InternalName", "libexslt.dll\0" 24 | VALUE "LegalCopyright", "Copyright (C) Thomas Broyer, Charlie Bozeman and Daniel Veillard\0" 25 | VALUE "LegalTrademarks", "\0" 26 | VALUE "OriginalFilename", "libexslt.dll\0" 27 | VALUE "ProductName", "libexslt\0" 28 | VALUE "ProductVersion", LIBEXSLT_DOTTED_VERSION "\0" 29 | VALUE "Comments", "For more information visit . Alternative build from .\0" 30 | END 31 | END 32 | BLOCK "VarFileInfo" 33 | BEGIN 34 | VALUE "Translation", 0x0409, 0 /* US English, ASCII */ 35 | END 36 | END 37 | -------------------------------------------------------------------------------- /libxslt/xsltexports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: macros for marking symbols as exportable/importable. 3 | * Description: macros for marking symbols as exportable/importable. 4 | * 5 | * Copy: See Copyright for the status of this software. 6 | */ 7 | 8 | #ifndef __XSLT_EXPORTS_H__ 9 | #define __XSLT_EXPORTS_H__ 10 | 11 | #if defined(_WIN32) || defined(__CYGWIN__) 12 | /** DOC_DISABLE */ 13 | 14 | #ifdef LIBXSLT_STATIC 15 | #define XSLTPUBLIC 16 | #elif defined(IN_LIBXSLT) 17 | #define XSLTPUBLIC __declspec(dllexport) 18 | #else 19 | #define XSLTPUBLIC __declspec(dllimport) 20 | #endif 21 | 22 | #define XSLTCALL __cdecl 23 | 24 | /** DOC_ENABLE */ 25 | #else /* not Windows */ 26 | 27 | /** 28 | * XSLTPUBLIC: 29 | * 30 | * Macro which declares a public symbol 31 | */ 32 | #define XSLTPUBLIC 33 | 34 | /** 35 | * XSLTCALL: 36 | * 37 | * Macro which declares the calling convention for exported functions 38 | */ 39 | #define XSLTCALL 40 | 41 | #endif /* platform switch */ 42 | 43 | /* 44 | * XSLTPUBFUN: 45 | * 46 | * Macro which declares an exportable function 47 | */ 48 | #define XSLTPUBFUN XSLTPUBLIC 49 | 50 | /** 51 | * XSLTPUBVAR: 52 | * 53 | * Macro which declares an exportable variable 54 | */ 55 | #define XSLTPUBVAR XSLTPUBLIC extern 56 | 57 | /* Compatibility */ 58 | #if !defined(LIBXSLT_PUBLIC) 59 | #define LIBXSLT_PUBLIC XSLTPUBVAR 60 | #endif 61 | 62 | #endif /* __XSLT_EXPORTS_H__ */ 63 | 64 | 65 | -------------------------------------------------------------------------------- /libxslt/libxslt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: internal header only used during the compilation of libxslt 3 | * Description: internal header only used during the compilation of libxslt 4 | * 5 | * Copy: See Copyright for the status of this software. 6 | * 7 | * Author: Daniel Veillard 8 | */ 9 | 10 | #ifndef __XSLT_LIBXSLT_H__ 11 | #define __XSLT_LIBXSLT_H__ 12 | 13 | /* 14 | * These macros must be defined before including system headers. 15 | * Do not add any #include directives above this block. 16 | */ 17 | #ifndef NO_LARGEFILE_SOURCE 18 | #ifndef _LARGEFILE_SOURCE 19 | #define _LARGEFILE_SOURCE 20 | #endif 21 | #ifndef _FILE_OFFSET_BITS 22 | #define _FILE_OFFSET_BITS 64 23 | #endif 24 | #endif 25 | 26 | #if defined(_WIN32) && !defined (__MINGW32__) 27 | #include 28 | #else 29 | #include "config.h" 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #if !defined LIBXSLT_PUBLIC 36 | #if (defined (__CYGWIN__) || defined _MSC_VER) && !defined IN_LIBXSLT && !defined LIBXSLT_STATIC 37 | #define LIBXSLT_PUBLIC __declspec(dllimport) 38 | #else 39 | #define LIBXSLT_PUBLIC 40 | #endif 41 | #endif 42 | 43 | #if defined(_MSC_VER) || defined(__MINGW32__) 44 | #include 45 | #include 46 | #define mkdir(p,m) _mkdir(p) 47 | #endif 48 | 49 | #ifdef __GNUC__ 50 | #define ATTRIBUTE_UNUSED __attribute__((unused)) 51 | #else 52 | #define ATTRIBUTE_UNUSED 53 | #endif 54 | 55 | #endif /* ! __XSLT_LIBXSLT_H__ */ 56 | -------------------------------------------------------------------------------- /libexslt/exsltconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * exsltconfig.h: compile-time version information for the EXSLT library 3 | * 4 | * See Copyright for the status of this software. 5 | * 6 | * daniel@veillard.com 7 | */ 8 | 9 | #ifndef __XML_EXSLTCONFIG_H__ 10 | #define __XML_EXSLTCONFIG_H__ 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * LIBEXSLT_DOTTED_VERSION: 18 | * 19 | * the version string like "1.2.3" 20 | */ 21 | #define LIBEXSLT_DOTTED_VERSION "0.8.25" 22 | 23 | /** 24 | * LIBEXSLT_VERSION: 25 | * 26 | * the version number: 1.2.3 value is 10203 27 | */ 28 | #define LIBEXSLT_VERSION 825 29 | 30 | /** 31 | * LIBEXSLT_VERSION_STRING: 32 | * 33 | * the version number string, 1.2.3 value is "10203" 34 | */ 35 | #define LIBEXSLT_VERSION_STRING "825" 36 | 37 | /** 38 | * LIBEXSLT_VERSION_EXTRA: 39 | * 40 | * extra version information, used to show a Git commit description 41 | */ 42 | #define LIBEXSLT_VERSION_EXTRA "" 43 | 44 | /** 45 | * WITH_CRYPTO: 46 | * 47 | * Whether crypto support is configured into exslt 48 | */ 49 | #if 1 50 | #define EXSLT_CRYPTO_ENABLED 51 | #endif 52 | 53 | /** 54 | * ATTRIBUTE_UNUSED: 55 | * 56 | * This macro is used to flag unused function parameters to GCC 57 | */ 58 | #ifdef __GNUC__ 59 | #ifndef ATTRIBUTE_UNUSED 60 | #define ATTRIBUTE_UNUSED __attribute__((unused)) 61 | #endif 62 | #else 63 | #define ATTRIBUTE_UNUSED 64 | #endif 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __XML_EXSLTCONFIG_H__ */ 71 | -------------------------------------------------------------------------------- /distfiles/libxslt-1.1.45-import.lst: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | Copyright 3 | FEATURES 4 | INSTALL 5 | NEWS 6 | README.libxslt.md 7 | TODO 8 | libexslt/common.c 9 | libexslt/crypto.c 10 | libexslt/date.c 11 | libexslt/dynamic.c 12 | libexslt/exslt.c 13 | libexslt/exslt.h 14 | libexslt/exsltexports.h 15 | libexslt/functions.c 16 | libexslt/libexslt.h 17 | libexslt/math.c 18 | libexslt/saxon.c 19 | libexslt/sets.c 20 | libexslt/strings.c 21 | libxslt/attributes.c 22 | libxslt/attributes.h 23 | libxslt/attrvt.c 24 | libxslt/documents.c 25 | libxslt/documents.h 26 | libxslt/extensions.c 27 | libxslt/extensions.h 28 | libxslt/extra.c 29 | libxslt/extra.h 30 | libxslt/functions.c 31 | libxslt/functions.h 32 | libxslt/imports.c 33 | libxslt/imports.h 34 | libxslt/keys.c 35 | libxslt/keys.h 36 | libxslt/libxslt.h 37 | libxslt/namespaces.c 38 | libxslt/namespaces.h 39 | libxslt/numbers.c 40 | libxslt/numbersInternals.h 41 | libxslt/pattern.c 42 | libxslt/pattern.h 43 | libxslt/preproc.c 44 | libxslt/preproc.h 45 | libxslt/security.c 46 | libxslt/security.h 47 | libxslt/templates.c 48 | libxslt/templates.h 49 | libxslt/transform.c 50 | libxslt/transform.h 51 | libxslt/transformInternals.h 52 | libxslt/trio.h 53 | libxslt/triodef.h 54 | libxslt/variables.c 55 | libxslt/variables.h 56 | libxslt/win32config.h 57 | libxslt/xslt.c 58 | libxslt/xslt.h 59 | libxslt/xsltInternals.h 60 | libxslt/xsltexports.h 61 | libxslt/xsltlocale.c 62 | libxslt/xsltlocale.h 63 | libxslt/xsltutils.c 64 | libxslt/xsltutils.h 65 | xsltproc/testThreads.c 66 | xsltproc/xsltproc.c 67 | -------------------------------------------------------------------------------- /libxslt/extra.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the non-standard features 3 | * Description: implement some extension outside the XSLT namespace 4 | * but not EXSLT with is in a different library. 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Daniel Veillard 9 | */ 10 | 11 | #ifndef __XML_XSLT_EXTRA_H__ 12 | #define __XML_XSLT_EXTRA_H__ 13 | 14 | #include 15 | #include "xsltexports.h" 16 | #include "xsltInternals.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * XSLT_LIBXSLT_NAMESPACE: 24 | * 25 | * This is the libxslt namespace for specific extensions. 26 | */ 27 | #define XSLT_LIBXSLT_NAMESPACE ((xmlChar *) "http://xmlsoft.org/XSLT/namespace") 28 | 29 | /** 30 | * XSLT_SAXON_NAMESPACE: 31 | * 32 | * This is Michael Kay's Saxon processor namespace for extensions. 33 | */ 34 | #define XSLT_SAXON_NAMESPACE ((xmlChar *) "http://icl.com/saxon") 35 | 36 | /** 37 | * XSLT_XT_NAMESPACE: 38 | * 39 | * This is James Clark's XT processor namespace for extensions. 40 | */ 41 | #define XSLT_XT_NAMESPACE ((xmlChar *) "http://www.jclark.com/xt") 42 | 43 | /** 44 | * XSLT_XALAN_NAMESPACE: 45 | * 46 | * This is the Apache project XALAN processor namespace for extensions. 47 | */ 48 | #define XSLT_XALAN_NAMESPACE ((xmlChar *) \ 49 | "org.apache.xalan.xslt.extensions.Redirect") 50 | 51 | 52 | XSLTPUBFUN void XSLTCALL 53 | xsltFunctionNodeSet (xmlXPathParserContextPtr ctxt, 54 | int nargs); 55 | XSLTPUBFUN void XSLTCALL 56 | xsltDebug (xsltTransformContextPtr ctxt, 57 | xmlNodePtr node, 58 | xmlNodePtr inst, 59 | xsltElemPreCompPtr comp); 60 | 61 | 62 | XSLTPUBFUN void XSLTCALL 63 | xsltRegisterExtras (xsltTransformContextPtr ctxt); 64 | XSLTPUBFUN void XSLTCALL 65 | xsltRegisterAllExtras (void); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __XML_XSLT_EXTRA_H__ */ 72 | 73 | -------------------------------------------------------------------------------- /libxslt/namespaces.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the XSLT namespace handling 3 | * Description: set of function easing the processing and generation 4 | * of namespace nodes in XSLT. 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Daniel Veillard 9 | */ 10 | 11 | #ifndef __XML_XSLT_NAMESPACES_H__ 12 | #define __XML_XSLT_NAMESPACES_H__ 13 | 14 | #include 15 | #include "xsltexports.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* 22 | * Used within nsAliases hashtable when the default namespace is required 23 | * but it's not been explicitly defined 24 | */ 25 | /** 26 | * UNDEFINED_DEFAULT_NS: 27 | * 28 | * Special value for undefined namespace, internal 29 | */ 30 | #define UNDEFINED_DEFAULT_NS (const xmlChar *) -1L 31 | 32 | XSLTPUBFUN void XSLTCALL 33 | xsltNamespaceAlias (xsltStylesheetPtr style, 34 | xmlNodePtr node); 35 | XSLTPUBFUN xmlNsPtr XSLTCALL 36 | xsltGetNamespace (xsltTransformContextPtr ctxt, 37 | xmlNodePtr cur, 38 | xmlNsPtr ns, 39 | xmlNodePtr out); 40 | XSLTPUBFUN xmlNsPtr XSLTCALL 41 | xsltGetPlainNamespace (xsltTransformContextPtr ctxt, 42 | xmlNodePtr cur, 43 | xmlNsPtr ns, 44 | xmlNodePtr out); 45 | XSLTPUBFUN xmlNsPtr XSLTCALL 46 | xsltGetSpecialNamespace (xsltTransformContextPtr ctxt, 47 | xmlNodePtr cur, 48 | const xmlChar *URI, 49 | const xmlChar *prefix, 50 | xmlNodePtr out); 51 | XSLTPUBFUN xmlNsPtr XSLTCALL 52 | xsltCopyNamespace (xsltTransformContextPtr ctxt, 53 | xmlNodePtr elem, 54 | xmlNsPtr ns); 55 | XSLTPUBFUN xmlNsPtr XSLTCALL 56 | xsltCopyNamespaceList (xsltTransformContextPtr ctxt, 57 | xmlNodePtr node, 58 | xmlNsPtr cur); 59 | XSLTPUBFUN void XSLTCALL 60 | xsltFreeNamespaceAliasHashes 61 | (xsltStylesheetPtr style); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __XML_XSLT_NAMESPACES_H__ */ 68 | 69 | -------------------------------------------------------------------------------- /libxslt/imports.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the XSLT import support 3 | * Description: macros and fuctions needed to implement and 4 | * access the import tree 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Daniel Veillard 9 | */ 10 | 11 | #ifndef __XML_XSLT_IMPORTS_H__ 12 | #define __XML_XSLT_IMPORTS_H__ 13 | 14 | #include 15 | #include "xsltexports.h" 16 | #include "xsltInternals.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * XSLT_GET_IMPORT_PTR: 24 | * 25 | * A macro to import pointers from the stylesheet cascading order. 26 | */ 27 | #define XSLT_GET_IMPORT_PTR(res, style, name) { \ 28 | xsltStylesheetPtr st = style; \ 29 | res = NULL; \ 30 | while (st != NULL) { \ 31 | if (st->name != NULL) { res = st->name; break; } \ 32 | st = xsltNextImport(st); \ 33 | }} 34 | 35 | /** 36 | * XSLT_GET_IMPORT_INT: 37 | * 38 | * A macro to import intergers from the stylesheet cascading order. 39 | */ 40 | #define XSLT_GET_IMPORT_INT(res, style, name) { \ 41 | xsltStylesheetPtr st = style; \ 42 | res = -1; \ 43 | while (st != NULL) { \ 44 | if (st->name != -1) { res = st->name; break; } \ 45 | st = xsltNextImport(st); \ 46 | }} 47 | 48 | /* 49 | * Module interfaces 50 | */ 51 | XSLTPUBFUN int XSLTCALL 52 | xsltParseStylesheetImport(xsltStylesheetPtr style, 53 | xmlNodePtr cur); 54 | XSLTPUBFUN int XSLTCALL 55 | xsltParseStylesheetInclude 56 | (xsltStylesheetPtr style, 57 | xmlNodePtr cur); 58 | XSLTPUBFUN xsltStylesheetPtr XSLTCALL 59 | xsltNextImport (xsltStylesheetPtr style); 60 | XSLTPUBFUN int XSLTCALL 61 | xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt); 62 | XSLTPUBFUN int XSLTCALL 63 | xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, 64 | xmlNodePtr node); 65 | XSLTPUBFUN xsltTemplatePtr XSLTCALL 66 | xsltFindTemplate (xsltTransformContextPtr ctxt, 67 | const xmlChar *name, 68 | const xmlChar *nameURI); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif /* __XML_XSLT_IMPORTS_H__ */ 75 | 76 | -------------------------------------------------------------------------------- /libxslt/functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the XSLT functions not from XPath 3 | * Description: a set of extra functions coming from XSLT but not in XPath 4 | * 5 | * Copy: See Copyright for the status of this software. 6 | * 7 | * Author: Daniel Veillard and Bjorn Reese 8 | */ 9 | 10 | #ifndef __XML_XSLT_FUNCTIONS_H__ 11 | #define __XML_XSLT_FUNCTIONS_H__ 12 | 13 | #include 14 | #include 15 | #include "xsltexports.h" 16 | #include "xsltInternals.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * XSLT_REGISTER_FUNCTION_LOOKUP: 24 | * 25 | * Registering macro, not general purpose at all but used in different modules. 26 | */ 27 | #define XSLT_REGISTER_FUNCTION_LOOKUP(ctxt) \ 28 | xmlXPathRegisterFuncLookup((ctxt)->xpathCtxt, \ 29 | xsltXPathFunctionLookup, \ 30 | (void *)(ctxt->xpathCtxt)); 31 | 32 | XSLTPUBFUN xmlXPathFunction XSLTCALL 33 | xsltXPathFunctionLookup (void *vctxt, 34 | const xmlChar *name, 35 | const xmlChar *ns_uri); 36 | 37 | /* 38 | * Interfaces for the functions implementations. 39 | */ 40 | 41 | XSLTPUBFUN void XSLTCALL 42 | xsltDocumentFunction (xmlXPathParserContextPtr ctxt, 43 | int nargs); 44 | XSLTPUBFUN void XSLTCALL 45 | xsltKeyFunction (xmlXPathParserContextPtr ctxt, 46 | int nargs); 47 | XSLTPUBFUN void XSLTCALL 48 | xsltUnparsedEntityURIFunction (xmlXPathParserContextPtr ctxt, 49 | int nargs); 50 | XSLTPUBFUN void XSLTCALL 51 | xsltFormatNumberFunction (xmlXPathParserContextPtr ctxt, 52 | int nargs); 53 | XSLTPUBFUN void XSLTCALL 54 | xsltGenerateIdFunction (xmlXPathParserContextPtr ctxt, 55 | int nargs); 56 | XSLTPUBFUN void XSLTCALL 57 | xsltSystemPropertyFunction (xmlXPathParserContextPtr ctxt, 58 | int nargs); 59 | XSLTPUBFUN void XSLTCALL 60 | xsltElementAvailableFunction (xmlXPathParserContextPtr ctxt, 61 | int nargs); 62 | XSLTPUBFUN void XSLTCALL 63 | xsltFunctionAvailableFunction (xmlXPathParserContextPtr ctxt, 64 | int nargs); 65 | 66 | /* 67 | * And the registration 68 | */ 69 | 70 | XSLTPUBFUN void XSLTCALL 71 | xsltRegisterAllFunctions (xmlXPathContextPtr ctxt); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /* __XML_XSLT_FUNCTIONS_H__ */ 78 | 79 | -------------------------------------------------------------------------------- /libxslt/numbersInternals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: Implementation of the XSLT number functions 3 | * Description: Implementation of the XSLT number functions 4 | * 5 | * Copy: See Copyright for the status of this software. 6 | * 7 | * Author: Bjorn Reese and Daniel Veillard 8 | */ 9 | 10 | #ifndef __XML_XSLT_NUMBERSINTERNALS_H__ 11 | #define __XML_XSLT_NUMBERSINTERNALS_H__ 12 | 13 | #include 14 | #include "xsltexports.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | struct _xsltCompMatch; 21 | 22 | /** 23 | * xsltNumberData: 24 | * 25 | * This data structure is just a wrapper to pass xsl:number data in. 26 | */ 27 | typedef struct _xsltNumberData xsltNumberData; 28 | typedef xsltNumberData *xsltNumberDataPtr; 29 | 30 | struct _xsltNumberData { 31 | const xmlChar *level; 32 | const xmlChar *count; 33 | const xmlChar *from; 34 | const xmlChar *value; 35 | const xmlChar *format; 36 | int has_format; 37 | int digitsPerGroup; 38 | int groupingCharacter; 39 | int groupingCharacterLen; 40 | xmlDocPtr doc; 41 | xmlNodePtr node; 42 | struct _xsltCompMatch *countPat; 43 | struct _xsltCompMatch *fromPat; 44 | 45 | /* 46 | * accelerators 47 | */ 48 | }; 49 | 50 | /** 51 | * xsltFormatNumberInfo,: 52 | * 53 | * This data structure lists the various parameters needed to format numbers. 54 | */ 55 | typedef struct _xsltFormatNumberInfo xsltFormatNumberInfo; 56 | typedef xsltFormatNumberInfo *xsltFormatNumberInfoPtr; 57 | 58 | struct _xsltFormatNumberInfo { 59 | int integer_hash; /* Number of '#' in integer part */ 60 | int integer_digits; /* Number of '0' in integer part */ 61 | int frac_digits; /* Number of '0' in fractional part */ 62 | int frac_hash; /* Number of '#' in fractional part */ 63 | int group; /* Number of chars per display 'group' */ 64 | int multiplier; /* Scaling for percent or permille */ 65 | char add_decimal; /* Flag for whether decimal point appears in pattern */ 66 | char is_multiplier_set; /* Flag to catch multiple occurences of percent/permille */ 67 | char is_negative_pattern;/* Flag for processing -ve prefix/suffix */ 68 | }; 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | #endif /* __XML_XSLT_NUMBERSINTERNALS_H__ */ 74 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Daniel Veillard: 2 | daniel@veillard.com 3 | DV on #gnome IRC channel 4 | http://veillard.com/ 5 | Used to work at W3C, now Red Hat 6 | co-chair of W3C XML Linking WG 7 | invited expert on the W3C XML Core WG 8 | Author of libxml2 upon which this library is based. 9 | 10 | Bjorn Reese: 11 | breese@users.sourceforge.net 12 | http://home1.stofanet.dk/breese/ 13 | Software developer at http://www.systematic.dk/ 14 | Member of the XML-MTF Mapping WG. 15 | 16 | William Brack 17 | 18 | Thomas Broyer 19 | 20 | Igor Zlatkovic for the Windows port 21 | 22 | Patches gently provided by a multitude of people : 23 | 24 | Abhishek Arya 25 | Ben Walton 26 | Bjorn Reese 27 | C. M. Sperberg-McQueen 28 | Colin Walters 29 | Daniel Mustieles 30 | Daniel Richard G 31 | Darin Adler 32 | ÉRDI Gergo 33 | Fatih Demir 34 | Federico Mena Quintero 35 | Frederic Crozat 36 | Hao Hu 37 | Havoc Pennington 38 | IlyaS 39 | jacob berkman 40 | Jason Viers 41 | Jérôme Carretero 42 | Joachim Breitner 43 | Johan Dahlin 44 | John Fleck 45 | Jose Maria Celorio 46 | Julio M. Merino Vidal 47 | Kasimier T. Buchcik 48 | Kjartan Maraas 49 | Laurence Rowe 50 | Malcolm Purvis 51 | Martin 52 | Michael Bonfils 53 | Mike Hommey 54 | money_seshu Dronamraju 55 | Nick Wellnhofer 56 | Nix 57 | Pedro F. Giffuni 58 | Peter Williams 59 | Rob Richards 60 | Roumen Petrov 61 | Stefan Kost 62 | Tomasz Kłoczko 63 | Chris Evans 64 | Iván Chavero 65 | -------------------------------------------------------------------------------- /libxslt/pattern.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the pattern matching used in template matches. 3 | * Description: the implementation of the lookup of the right template 4 | * for a given node must be really fast in order to keep 5 | * decent performances. 6 | * 7 | * Copy: See Copyright for the status of this software. 8 | * 9 | * Author: Daniel Veillard 10 | */ 11 | 12 | #ifndef __XML_XSLT_PATTERN_H__ 13 | #define __XML_XSLT_PATTERN_H__ 14 | 15 | #include "xsltInternals.h" 16 | #include "xsltexports.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * xsltCompMatch: 24 | * 25 | * Data structure used for the implementation of patterns. 26 | * It is kept private (in pattern.c). 27 | */ 28 | typedef struct _xsltCompMatch xsltCompMatch; 29 | typedef xsltCompMatch *xsltCompMatchPtr; 30 | 31 | /* 32 | * Pattern related interfaces. 33 | */ 34 | 35 | XSLTPUBFUN xsltCompMatchPtr XSLTCALL 36 | xsltCompilePattern (const xmlChar *pattern, 37 | xmlDocPtr doc, 38 | xmlNodePtr node, 39 | xsltStylesheetPtr style, 40 | xsltTransformContextPtr runtime); 41 | XSLTPUBFUN void XSLTCALL 42 | xsltFreeCompMatchList (xsltCompMatchPtr comp); 43 | XSLTPUBFUN int XSLTCALL 44 | xsltTestCompMatchList (xsltTransformContextPtr ctxt, 45 | xmlNodePtr node, 46 | xsltCompMatchPtr comp); 47 | XSLTPUBFUN void XSLTCALL 48 | xsltCompMatchClearCache (xsltTransformContextPtr ctxt, 49 | xsltCompMatchPtr comp); 50 | XSLTPUBFUN void XSLTCALL 51 | xsltNormalizeCompSteps (void *payload, 52 | void *data, 53 | const xmlChar *name); 54 | 55 | /* 56 | * Template related interfaces. 57 | */ 58 | XSLTPUBFUN int XSLTCALL 59 | xsltAddTemplate (xsltStylesheetPtr style, 60 | xsltTemplatePtr cur, 61 | const xmlChar *mode, 62 | const xmlChar *modeURI); 63 | XSLTPUBFUN xsltTemplatePtr XSLTCALL 64 | xsltGetTemplate (xsltTransformContextPtr ctxt, 65 | xmlNodePtr node, 66 | xsltStylesheetPtr style); 67 | XSLTPUBFUN void XSLTCALL 68 | xsltFreeTemplateHashes (xsltStylesheetPtr style); 69 | XSLTPUBFUN void XSLTCALL 70 | xsltCleanupTemplates (xsltStylesheetPtr style); 71 | 72 | #if 0 73 | int xsltMatchPattern (xsltTransformContextPtr ctxt, 74 | xmlNodePtr node, 75 | const xmlChar *pattern, 76 | xmlDocPtr ctxtdoc, 77 | xmlNodePtr ctxtnode); 78 | #endif 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* __XML_XSLT_PATTERN_H__ */ 84 | 85 | -------------------------------------------------------------------------------- /libxslt/xslt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: Interfaces, constants and types related to the XSLT engine 3 | * Description: Interfaces, constants and types related to the XSLT engine 4 | * 5 | * Copy: See Copyright for the status of this software. 6 | * 7 | * Author: Daniel Veillard 8 | */ 9 | 10 | #ifndef __XML_XSLT_H__ 11 | #define __XML_XSLT_H__ 12 | 13 | #include 14 | #include "xsltexports.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /** 21 | * XSLT_DEFAULT_VERSION: 22 | * 23 | * The default version of XSLT supported. 24 | */ 25 | #define XSLT_DEFAULT_VERSION "1.0" 26 | 27 | /** 28 | * XSLT_DEFAULT_VENDOR: 29 | * 30 | * The XSLT "vendor" string for this processor. 31 | */ 32 | #define XSLT_DEFAULT_VENDOR "libxslt" 33 | 34 | /** 35 | * XSLT_DEFAULT_URL: 36 | * 37 | * The XSLT "vendor" URL for this processor. 38 | */ 39 | #define XSLT_DEFAULT_URL "http://xmlsoft.org/XSLT/" 40 | 41 | /** 42 | * XSLT_NAMESPACE: 43 | * 44 | * The XSLT specification namespace. 45 | */ 46 | #define XSLT_NAMESPACE ((const xmlChar *)"http://www.w3.org/1999/XSL/Transform") 47 | 48 | /** 49 | * XSLT_PARSE_OPTIONS: 50 | * 51 | * The set of options to pass to an xmlReadxxx when loading files for 52 | * XSLT consumption. 53 | */ 54 | #define XSLT_PARSE_OPTIONS \ 55 | XML_PARSE_NOENT | XML_PARSE_DTDLOAD | XML_PARSE_DTDATTR | XML_PARSE_NOCDATA 56 | 57 | /** 58 | * xsltMaxDepth: 59 | * 60 | * This value is used to detect templates loops. 61 | */ 62 | XSLTPUBVAR int xsltMaxDepth; 63 | 64 | /** 65 | * * xsltMaxVars: 66 | * * 67 | * * This value is used to detect templates loops. 68 | * */ 69 | XSLTPUBVAR int xsltMaxVars; 70 | 71 | /** 72 | * xsltEngineVersion: 73 | * 74 | * The version string for libxslt. 75 | */ 76 | XSLTPUBVAR const char *xsltEngineVersion; 77 | 78 | /** 79 | * xsltLibxsltVersion: 80 | * 81 | * The version of libxslt compiled. 82 | */ 83 | XSLTPUBVAR const int xsltLibxsltVersion; 84 | 85 | /** 86 | * xsltLibxmlVersion: 87 | * 88 | * The version of libxml libxslt was compiled against. 89 | */ 90 | XSLTPUBVAR const int xsltLibxmlVersion; 91 | 92 | /* 93 | * Global initialization function. 94 | */ 95 | 96 | XSLTPUBFUN void XSLTCALL 97 | xsltInit (void); 98 | 99 | /* 100 | * Global cleanup function. 101 | */ 102 | XSLTPUBFUN void XSLTCALL 103 | xsltCleanupGlobals (void); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* __XML_XSLT_H__ */ 110 | 111 | -------------------------------------------------------------------------------- /libxslt/templates.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the template processing 3 | * Description: This set of routine encapsulates XPath calls 4 | * and Attribute Value Templates evaluation. 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Daniel Veillard 9 | */ 10 | 11 | #ifndef __XML_XSLT_TEMPLATES_H__ 12 | #define __XML_XSLT_TEMPLATES_H__ 13 | 14 | #include 15 | #include 16 | #include "xsltexports.h" 17 | #include "xsltInternals.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | XSLTPUBFUN int XSLTCALL 24 | xsltEvalXPathPredicate (xsltTransformContextPtr ctxt, 25 | xmlXPathCompExprPtr comp, 26 | xmlNsPtr *nsList, 27 | int nsNr); 28 | XSLTPUBFUN xmlChar * XSLTCALL 29 | xsltEvalTemplateString (xsltTransformContextPtr ctxt, 30 | xmlNodePtr contextNode, 31 | xmlNodePtr inst); 32 | XSLTPUBFUN xmlChar * XSLTCALL 33 | xsltEvalAttrValueTemplate (xsltTransformContextPtr ctxt, 34 | xmlNodePtr node, 35 | const xmlChar *name, 36 | const xmlChar *ns); 37 | XSLTPUBFUN const xmlChar * XSLTCALL 38 | xsltEvalStaticAttrValueTemplate (xsltStylesheetPtr style, 39 | xmlNodePtr node, 40 | const xmlChar *name, 41 | const xmlChar *ns, 42 | int *found); 43 | 44 | /* TODO: this is obviously broken ... the namespaces should be passed too ! */ 45 | XSLTPUBFUN xmlChar * XSLTCALL 46 | xsltEvalXPathString (xsltTransformContextPtr ctxt, 47 | xmlXPathCompExprPtr comp); 48 | XSLTPUBFUN xmlChar * XSLTCALL 49 | xsltEvalXPathStringNs (xsltTransformContextPtr ctxt, 50 | xmlXPathCompExprPtr comp, 51 | int nsNr, 52 | xmlNsPtr *nsList); 53 | 54 | XSLTPUBFUN xmlNodePtr * XSLTCALL 55 | xsltTemplateProcess (xsltTransformContextPtr ctxt, 56 | xmlNodePtr node); 57 | XSLTPUBFUN xmlAttrPtr XSLTCALL 58 | xsltAttrListTemplateProcess (xsltTransformContextPtr ctxt, 59 | xmlNodePtr target, 60 | xmlAttrPtr cur); 61 | XSLTPUBFUN xmlAttrPtr XSLTCALL 62 | xsltAttrTemplateProcess (xsltTransformContextPtr ctxt, 63 | xmlNodePtr target, 64 | xmlAttrPtr attr); 65 | XSLTPUBFUN xmlChar * XSLTCALL 66 | xsltAttrTemplateValueProcess (xsltTransformContextPtr ctxt, 67 | const xmlChar* attr); 68 | XSLTPUBFUN xmlChar * XSLTCALL 69 | xsltAttrTemplateValueProcessNode(xsltTransformContextPtr ctxt, 70 | const xmlChar* str, 71 | xmlNodePtr node); 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif /* __XML_XSLT_TEMPLATES_H__ */ 77 | 78 | -------------------------------------------------------------------------------- /libxslt/documents.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the document handling 3 | * Description: implements document loading and cache (multiple 4 | * document() reference for the same resources must 5 | * be equal. 6 | * 7 | * Copy: See Copyright for the status of this software. 8 | * 9 | * Author: Daniel Veillard 10 | */ 11 | 12 | #ifndef __XML_XSLT_DOCUMENTS_H__ 13 | #define __XML_XSLT_DOCUMENTS_H__ 14 | 15 | #include 16 | #include "xsltexports.h" 17 | #include "xsltInternals.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | XSLTPUBFUN xsltDocumentPtr XSLTCALL 24 | xsltNewDocument (xsltTransformContextPtr ctxt, 25 | xmlDocPtr doc); 26 | XSLTPUBFUN xsltDocumentPtr XSLTCALL 27 | xsltLoadDocument (xsltTransformContextPtr ctxt, 28 | const xmlChar *URI); 29 | XSLTPUBFUN xsltDocumentPtr XSLTCALL 30 | xsltFindDocument (xsltTransformContextPtr ctxt, 31 | xmlDocPtr doc); 32 | XSLTPUBFUN void XSLTCALL 33 | xsltFreeDocuments (xsltTransformContextPtr ctxt); 34 | 35 | XSLTPUBFUN xsltDocumentPtr XSLTCALL 36 | xsltLoadStyleDocument (xsltStylesheetPtr style, 37 | const xmlChar *URI); 38 | XSLTPUBFUN xsltDocumentPtr XSLTCALL 39 | xsltNewStyleDocument (xsltStylesheetPtr style, 40 | xmlDocPtr doc); 41 | XSLTPUBFUN void XSLTCALL 42 | xsltFreeStyleDocuments (xsltStylesheetPtr style); 43 | 44 | /* 45 | * Hooks for document loading 46 | */ 47 | 48 | /** 49 | * xsltLoadType: 50 | * 51 | * Enum defining the kind of loader requirement. 52 | */ 53 | typedef enum { 54 | XSLT_LOAD_START = 0, /* loading for a top stylesheet */ 55 | XSLT_LOAD_STYLESHEET = 1, /* loading for a stylesheet include/import */ 56 | XSLT_LOAD_DOCUMENT = 2 /* loading document at transformation time */ 57 | } xsltLoadType; 58 | 59 | /** 60 | * xsltDocLoaderFunc: 61 | * @URI: the URI of the document to load 62 | * @dict: the dictionary to use when parsing that document 63 | * @options: parsing options, a set of xmlParserOption 64 | * @ctxt: the context, either a stylesheet or a transformation context 65 | * @type: the xsltLoadType indicating the kind of loading required 66 | * 67 | * An xsltDocLoaderFunc is a signature for a function which can be 68 | * registered to load document not provided by the compilation or 69 | * transformation API themselve, for example when an xsl:import, 70 | * xsl:include is found at compilation time or when a document() 71 | * call is made at runtime. 72 | * 73 | * Returns the pointer to the document (which will be modified and 74 | * freed by the engine later), or NULL in case of error. 75 | */ 76 | typedef xmlDocPtr (*xsltDocLoaderFunc) (const xmlChar *URI, 77 | xmlDictPtr dict, 78 | int options, 79 | void *ctxt, 80 | xsltLoadType type); 81 | 82 | XSLTPUBFUN void XSLTCALL 83 | xsltSetLoaderFunc (xsltDocLoaderFunc f); 84 | 85 | /* the loader may be needed by extension libraries so it is exported */ 86 | XSLTPUBVAR xsltDocLoaderFunc xsltDocDefaultLoader; 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __XML_XSLT_DOCUMENTS_H__ */ 93 | 94 | -------------------------------------------------------------------------------- /Copyright: -------------------------------------------------------------------------------- 1 | Licence for libxslt except libexslt 2 | ---------------------------------------------------------------------- 3 | Copyright (C) 2001-2002 Daniel Veillard. All Rights Reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is fur- 10 | nished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 17 | NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | DANIEL VEILLARD BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON- 20 | NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | Except as contained in this notice, the name of Daniel Veillard shall not 23 | be used in advertising or otherwise to promote the sale, use or other deal- 24 | ings in this Software without prior written authorization from him. 25 | 26 | ---------------------------------------------------------------------- 27 | 28 | Licence for libexslt 29 | ---------------------------------------------------------------------- 30 | Copyright (C) 2001-2002 Thomas Broyer, Charlie Bozeman and Daniel Veillard. 31 | All Rights Reserved. 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is fur- 38 | nished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in 41 | all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 45 | NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 47 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON- 48 | NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 49 | 50 | Except as contained in this notice, the name of the authors shall not 51 | be used in advertising or otherwise to promote the sale, use or other deal- 52 | ings in this Software without prior written authorization from him. 53 | ---------------------------------------------------------------------- 54 | -------------------------------------------------------------------------------- /libxslt/security.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the libxslt security framework 3 | * Description: the libxslt security framework allow to restrict 4 | * the access to new resources (file or URL) from 5 | * the stylesheet at runtime. 6 | * 7 | * Copy: See Copyright for the status of this software. 8 | * 9 | * Author: Daniel Veillard 10 | */ 11 | 12 | #ifndef __XML_XSLT_SECURITY_H__ 13 | #define __XML_XSLT_SECURITY_H__ 14 | 15 | #include 16 | #include "xsltexports.h" 17 | #include "xsltInternals.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * xsltSecurityPref: 25 | * 26 | * structure to indicate the preferences for security in the XSLT 27 | * transformation. 28 | */ 29 | typedef struct _xsltSecurityPrefs xsltSecurityPrefs; 30 | typedef xsltSecurityPrefs *xsltSecurityPrefsPtr; 31 | 32 | /** 33 | * xsltSecurityOption: 34 | * 35 | * the set of option that can be configured 36 | */ 37 | typedef enum { 38 | XSLT_SECPREF_READ_FILE = 1, 39 | XSLT_SECPREF_WRITE_FILE, 40 | XSLT_SECPREF_CREATE_DIRECTORY, 41 | XSLT_SECPREF_READ_NETWORK, 42 | XSLT_SECPREF_WRITE_NETWORK 43 | } xsltSecurityOption; 44 | 45 | /** 46 | * xsltSecurityCheck: 47 | * 48 | * User provided function to check the value of a string like a file 49 | * path or an URL ... 50 | */ 51 | typedef int (*xsltSecurityCheck) (xsltSecurityPrefsPtr sec, 52 | xsltTransformContextPtr ctxt, 53 | const char *value); 54 | 55 | /* 56 | * Module interfaces 57 | */ 58 | XSLTPUBFUN xsltSecurityPrefsPtr XSLTCALL 59 | xsltNewSecurityPrefs (void); 60 | XSLTPUBFUN void XSLTCALL 61 | xsltFreeSecurityPrefs (xsltSecurityPrefsPtr sec); 62 | XSLTPUBFUN int XSLTCALL 63 | xsltSetSecurityPrefs (xsltSecurityPrefsPtr sec, 64 | xsltSecurityOption option, 65 | xsltSecurityCheck func); 66 | XSLTPUBFUN xsltSecurityCheck XSLTCALL 67 | xsltGetSecurityPrefs (xsltSecurityPrefsPtr sec, 68 | xsltSecurityOption option); 69 | 70 | XSLTPUBFUN void XSLTCALL 71 | xsltSetDefaultSecurityPrefs (xsltSecurityPrefsPtr sec); 72 | XSLTPUBFUN xsltSecurityPrefsPtr XSLTCALL 73 | xsltGetDefaultSecurityPrefs (void); 74 | 75 | XSLTPUBFUN int XSLTCALL 76 | xsltSetCtxtSecurityPrefs (xsltSecurityPrefsPtr sec, 77 | xsltTransformContextPtr ctxt); 78 | 79 | XSLTPUBFUN int XSLTCALL 80 | xsltSecurityAllow (xsltSecurityPrefsPtr sec, 81 | xsltTransformContextPtr ctxt, 82 | const char *value); 83 | XSLTPUBFUN int XSLTCALL 84 | xsltSecurityForbid (xsltSecurityPrefsPtr sec, 85 | xsltTransformContextPtr ctxt, 86 | const char *value); 87 | /* 88 | * internal interfaces 89 | */ 90 | XSLTPUBFUN int XSLTCALL 91 | xsltCheckWrite (xsltSecurityPrefsPtr sec, 92 | xsltTransformContextPtr ctxt, 93 | const xmlChar *URL); 94 | XSLTPUBFUN int XSLTCALL 95 | xsltCheckRead (xsltSecurityPrefsPtr sec, 96 | xsltTransformContextPtr ctxt, 97 | const xmlChar *URL); 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* __XML_XSLT_SECURITY_H__ */ 104 | 105 | -------------------------------------------------------------------------------- /libexslt/common.c: -------------------------------------------------------------------------------- 1 | #define IN_LIBEXSLT 2 | #include "libexslt/libexslt.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "exslt.h" 16 | 17 | static void 18 | exsltNodeSetFunction (xmlXPathParserContextPtr ctxt, int nargs) { 19 | if (nargs != 1) { 20 | xmlXPathSetArityError(ctxt); 21 | return; 22 | } 23 | if (xmlXPathStackIsNodeSet (ctxt)) { 24 | xsltFunctionNodeSet (ctxt, nargs); 25 | return; 26 | } else { 27 | xmlDocPtr fragment; 28 | xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt); 29 | xmlNodePtr txt; 30 | xmlChar *strval; 31 | xmlXPathObjectPtr obj; 32 | /* 33 | * SPEC EXSLT: 34 | * "You can also use this function to turn a string into a text 35 | * node, which is helpful if you want to pass a string to a 36 | * function that only accepts a node-set." 37 | */ 38 | fragment = xsltCreateRVT(tctxt); 39 | if (fragment == NULL) { 40 | xsltTransformError(tctxt, NULL, tctxt->inst, 41 | "exsltNodeSetFunction: Failed to create a tree fragment.\n"); 42 | tctxt->state = XSLT_STATE_STOPPED; 43 | return; 44 | } 45 | xsltRegisterLocalRVT(tctxt, fragment); 46 | 47 | strval = xmlXPathPopString (ctxt); 48 | 49 | txt = xmlNewDocText (fragment, strval); 50 | xmlAddChild((xmlNodePtr) fragment, txt); 51 | obj = xmlXPathNewNodeSet(txt); 52 | if (obj == NULL) { 53 | xsltTransformError(tctxt, NULL, tctxt->inst, 54 | "exsltNodeSetFunction: Failed to create a node set object.\n"); 55 | tctxt->state = XSLT_STATE_STOPPED; 56 | } 57 | if (strval != NULL) 58 | xmlFree (strval); 59 | 60 | valuePush (ctxt, obj); 61 | } 62 | } 63 | 64 | static void 65 | exsltObjectTypeFunction (xmlXPathParserContextPtr ctxt, int nargs) { 66 | xmlXPathObjectPtr obj, ret; 67 | 68 | if (nargs != 1) { 69 | xmlXPathSetArityError(ctxt); 70 | return; 71 | } 72 | 73 | obj = valuePop(ctxt); 74 | 75 | switch (obj->type) { 76 | case XPATH_STRING: 77 | ret = xmlXPathNewCString("string"); 78 | break; 79 | case XPATH_NUMBER: 80 | ret = xmlXPathNewCString("number"); 81 | break; 82 | case XPATH_BOOLEAN: 83 | ret = xmlXPathNewCString("boolean"); 84 | break; 85 | case XPATH_NODESET: 86 | ret = xmlXPathNewCString("node-set"); 87 | break; 88 | case XPATH_XSLT_TREE: 89 | ret = xmlXPathNewCString("RTF"); 90 | break; 91 | case XPATH_USERS: 92 | ret = xmlXPathNewCString("external"); 93 | break; 94 | default: 95 | xsltGenericError(xsltGenericErrorContext, 96 | "object-type() invalid arg\n"); 97 | ctxt->error = XPATH_INVALID_TYPE; 98 | xmlXPathFreeObject(obj); 99 | return; 100 | } 101 | xmlXPathFreeObject(obj); 102 | valuePush(ctxt, ret); 103 | } 104 | 105 | 106 | /** 107 | * exsltCommonRegister: 108 | * 109 | * Registers the EXSLT - Common module 110 | */ 111 | 112 | void 113 | exsltCommonRegister (void) { 114 | xsltRegisterExtModuleFunction((const xmlChar *) "node-set", 115 | EXSLT_COMMON_NAMESPACE, 116 | exsltNodeSetFunction); 117 | xsltRegisterExtModuleFunction((const xmlChar *) "object-type", 118 | EXSLT_COMMON_NAMESPACE, 119 | exsltObjectTypeFunction); 120 | xsltRegisterExtModuleElement((const xmlChar *) "document", 121 | EXSLT_COMMON_NAMESPACE, 122 | xsltDocumentComp, 123 | xsltDocumentElem); 124 | } 125 | -------------------------------------------------------------------------------- /libexslt/exslt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: main header file 3 | * 4 | * Copy: See Copyright for the status of this software. 5 | */ 6 | 7 | 8 | #ifndef __EXSLT_H__ 9 | #define __EXSLT_H__ 10 | 11 | #include 12 | #include 13 | #include "exsltexports.h" 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | EXSLTPUBVAR const char *exsltLibraryVersion; 21 | EXSLTPUBVAR const int exsltLibexsltVersion; 22 | EXSLTPUBVAR const int exsltLibxsltVersion; 23 | EXSLTPUBVAR const int exsltLibxmlVersion; 24 | 25 | /** 26 | * EXSLT_COMMON_NAMESPACE: 27 | * 28 | * Namespace for EXSLT common functions 29 | */ 30 | #define EXSLT_COMMON_NAMESPACE ((const xmlChar *) "http://exslt.org/common") 31 | /** 32 | * EXSLT_CRYPTO_NAMESPACE: 33 | * 34 | * Namespace for EXSLT crypto functions 35 | */ 36 | #define EXSLT_CRYPTO_NAMESPACE ((const xmlChar *) "http://exslt.org/crypto") 37 | /** 38 | * EXSLT_MATH_NAMESPACE: 39 | * 40 | * Namespace for EXSLT math functions 41 | */ 42 | #define EXSLT_MATH_NAMESPACE ((const xmlChar *) "http://exslt.org/math") 43 | /** 44 | * EXSLT_SETS_NAMESPACE: 45 | * 46 | * Namespace for EXSLT set functions 47 | */ 48 | #define EXSLT_SETS_NAMESPACE ((const xmlChar *) "http://exslt.org/sets") 49 | /** 50 | * EXSLT_FUNCTIONS_NAMESPACE: 51 | * 52 | * Namespace for EXSLT functions extension functions 53 | */ 54 | #define EXSLT_FUNCTIONS_NAMESPACE ((const xmlChar *) "http://exslt.org/functions") 55 | /** 56 | * EXSLT_STRINGS_NAMESPACE: 57 | * 58 | * Namespace for EXSLT strings functions 59 | */ 60 | #define EXSLT_STRINGS_NAMESPACE ((const xmlChar *) "http://exslt.org/strings") 61 | /** 62 | * EXSLT_DATE_NAMESPACE: 63 | * 64 | * Namespace for EXSLT date functions 65 | */ 66 | #define EXSLT_DATE_NAMESPACE ((const xmlChar *) "http://exslt.org/dates-and-times") 67 | /** 68 | * EXSLT_DYNAMIC_NAMESPACE: 69 | * 70 | * Namespace for EXSLT dynamic functions 71 | */ 72 | #define EXSLT_DYNAMIC_NAMESPACE ((const xmlChar *) "http://exslt.org/dynamic") 73 | 74 | /** 75 | * SAXON_NAMESPACE: 76 | * 77 | * Namespace for SAXON extensions functions 78 | */ 79 | #define SAXON_NAMESPACE ((const xmlChar *) "http://icl.com/saxon") 80 | 81 | EXSLTPUBFUN void EXSLTCALL exsltCommonRegister (void); 82 | #ifdef EXSLT_CRYPTO_ENABLED 83 | EXSLTPUBFUN void EXSLTCALL exsltCryptoRegister (void); 84 | #endif 85 | EXSLTPUBFUN void EXSLTCALL exsltMathRegister (void); 86 | EXSLTPUBFUN void EXSLTCALL exsltSetsRegister (void); 87 | EXSLTPUBFUN void EXSLTCALL exsltFuncRegister (void); 88 | EXSLTPUBFUN void EXSLTCALL exsltStrRegister (void); 89 | EXSLTPUBFUN void EXSLTCALL exsltDateRegister (void); 90 | EXSLTPUBFUN void EXSLTCALL exsltSaxonRegister (void); 91 | EXSLTPUBFUN void EXSLTCALL exsltDynRegister(void); 92 | 93 | EXSLTPUBFUN void EXSLTCALL exsltRegisterAll (void); 94 | 95 | EXSLTPUBFUN int EXSLTCALL exsltDateXpathCtxtRegister (xmlXPathContextPtr ctxt, 96 | const xmlChar *prefix); 97 | EXSLTPUBFUN int EXSLTCALL exsltMathXpathCtxtRegister (xmlXPathContextPtr ctxt, 98 | const xmlChar *prefix); 99 | EXSLTPUBFUN int EXSLTCALL exsltSetsXpathCtxtRegister (xmlXPathContextPtr ctxt, 100 | const xmlChar *prefix); 101 | EXSLTPUBFUN int EXSLTCALL exsltStrXpathCtxtRegister (xmlXPathContextPtr ctxt, 102 | const xmlChar *prefix); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | #endif /* __EXSLT_H__ */ 108 | 109 | -------------------------------------------------------------------------------- /distfiles/libxslt-1.1.45-import.md5: -------------------------------------------------------------------------------- 1 | 19eee4c025f2977d49f6247251425095 AUTHORS 2 | 0cd9a07afbeb24026c9b03aecfeba458 Copyright 3 | 0d9bd2fa90bd3a631ca9d9aabd801345 FEATURES 4 | 0204c456fe221f77aff226b90e9aab06 INSTALL 5 | 71e9c5bf17f635347917978575decad6 NEWS 6 | eef64f647c5d3389744959576a6ab6fd README.libxslt.md 7 | 1671e62be479162b8d9a012c81bc235e TODO 8 | 8912730100a2f79c41f5dd2723a9a32b libexslt/common.c 9 | f9fef3bf112c1ad9e3befecc89d24ed4 libexslt/crypto.c 10 | a8fc8c117459f96b8e9d69f44547ad42 libexslt/date.c 11 | cf9d8554d6d4530980f07a0c110cff00 libexslt/dynamic.c 12 | d33e58bd10bcc83e0feabf76eb071ca6 libexslt/exslt.c 13 | e3f739c7235640b1ba7c8e8928a63c82 libexslt/exslt.h 14 | 4a24ae19aba4feafb1acd0e8d4e880cb libexslt/exsltexports.h 15 | 96da2b5faa2cf9d618e00b59750c03fc libexslt/functions.c 16 | 33f2c417882aaa9a9be9cd98231e144f libexslt/libexslt.h 17 | c289c932c158e0a4899c4a6e4258279e libexslt/math.c 18 | 3bce123d618557a268f12b13c9457b4b libexslt/saxon.c 19 | 3c0cf99d615b4758655a3a26929ae7c9 libexslt/sets.c 20 | 2f356e14eb63ea5b11546456e423ba84 libexslt/strings.c 21 | 1196d3fb4f29723819f6da12cf695e27 libxslt/attributes.c 22 | 2dd0d8f663f0bfbb044589e38c531265 libxslt/attributes.h 23 | ad65dd2bf68938a4a1df976f5de6b04b libxslt/attrvt.c 24 | 758d7b88c2416cfcba80b405fefc8ce1 libxslt/documents.c 25 | 22a35bd1102fd1ac301e50cf650a8b8a libxslt/documents.h 26 | 53ed3fd7006ea87059475e9a33ef9a6d libxslt/extensions.c 27 | 45e4867f0daebf1eb905471a4be5184c libxslt/extensions.h 28 | e203d3012061029953db472adc29f3d3 libxslt/extra.c 29 | 94fe9ce1c0c47724aae4a1bcb8c29433 libxslt/extra.h 30 | 417a51afb903eb378c7132b22169c5e2 libxslt/functions.c 31 | 052fd28e9971416b2bbebdc3d1103c4e libxslt/functions.h 32 | 6d4aaa7ff80654536ce32bf36602fa03 libxslt/imports.c 33 | 66e26ad969e3c37fdeedcbc2716d7cf3 libxslt/imports.h 34 | 288a83e2af3c512f3dfbf84f3bbb084a libxslt/keys.c 35 | 77a11ee3de841d02d3461b829cfcc11e libxslt/keys.h 36 | 0a869195da28a2f69a5f574e56b9d099 libxslt/libxslt.h 37 | e36c1ec3153a21e117c539ab6895bce9 libxslt/namespaces.c 38 | c784b4b8e80274491fe023ce26d4847b libxslt/namespaces.h 39 | 6dd22c399e8285ac83c65e85082f68ef libxslt/numbers.c 40 | 27c2c21ab1535f84710fe1c8c8829018 libxslt/numbersInternals.h 41 | 6575b99017a1102e2933fbcbc646c254 libxslt/pattern.c 42 | adf6b78e6c68a7d34ae680f6dc3f5240 libxslt/pattern.h 43 | 5958f0a1e95c4abb86654861af2918ce libxslt/preproc.c 44 | 43092de4393f5033e08aea3b9ecb9012 libxslt/preproc.h 45 | 3c414325bcc1cea8d2486b36a42a4cc0 libxslt/security.c 46 | 1b24b61ea6afe01d18c647c94b1245c7 libxslt/security.h 47 | 4c97dca7a2bf3197bfba014131efb55c libxslt/templates.c 48 | 6901f4c8fad239b588b9f6d4cdfef5ac libxslt/templates.h 49 | 24972ad16fc1d485e971cb29ee5099d7 libxslt/transform.c 50 | ccbcce4553f3231003b1944002814246 libxslt/transform.h 51 | d034084359f34dc640b1944c107dc8e8 libxslt/transformInternals.h 52 | 7da7b1fcf378330699c7ecdd96908641 libxslt/trio.h 53 | e41149b088de4a04c067c85969f4db3c libxslt/triodef.h 54 | 72699370eb8ba14af881c37a3fc52809 libxslt/variables.c 55 | 08a56c0d4d50e48e897bf5eb4554d525 libxslt/variables.h 56 | 9f9dd8c70f50b3d5694a6ee06f400a02 libxslt/win32config.h 57 | 48c3f1965af25904069cf4f6b862d317 libxslt/xslt.c 58 | 0c08b8e7223b72f822a58457520b6387 libxslt/xslt.h 59 | bba1fa0c21b057828bb3056fe124dd75 libxslt/xsltInternals.h 60 | f9de2ff0a2e168ccf84d1bed6339d41d libxslt/xsltexports.h 61 | 65d88e37f8f19325830527b23c18fc9f libxslt/xsltlocale.c 62 | da1d63c112c339b051a9155359b6d2d7 libxslt/xsltlocale.h 63 | 53cea8bec0d2c4afbd4f7698ee38730c libxslt/xsltutils.c 64 | 9eeea4bbd2cbafc8a7ed24420cb9b11c libxslt/xsltutils.h 65 | cff031fc94f7f45e58e1559e4065029b xsltproc/testThreads.c 66 | d0377478a8503bc011b3f2b4c9a0789f xsltproc/xsltproc.c 67 | -------------------------------------------------------------------------------- /libxslt/variables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the variable matching and lookup. 3 | * Description: interface for the variable matching and lookup. 4 | * 5 | * Copy: See Copyright for the status of this software. 6 | * 7 | * Author: Daniel Veillard 8 | */ 9 | 10 | #ifndef __XML_XSLT_VARIABLES_H__ 11 | #define __XML_XSLT_VARIABLES_H__ 12 | 13 | #include 14 | #include 15 | #include "xsltexports.h" 16 | #include "xsltInternals.h" 17 | #include "functions.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | 24 | /** 25 | * XSLT_REGISTER_VARIABLE_LOOKUP: 26 | * 27 | * Registering macro, not general purpose at all but used in different modules. 28 | */ 29 | 30 | #define XSLT_REGISTER_VARIABLE_LOOKUP(ctxt) \ 31 | xmlXPathRegisterVariableLookup((ctxt)->xpathCtxt, \ 32 | xsltXPathVariableLookup, (void *)(ctxt)); \ 33 | xsltRegisterAllFunctions((ctxt)->xpathCtxt); \ 34 | xsltRegisterAllElement(ctxt); \ 35 | (ctxt)->xpathCtxt->extra = ctxt 36 | 37 | /* 38 | * Flags for memory management of RVTs 39 | */ 40 | 41 | /** 42 | * XSLT_RVT_LOCAL: 43 | * 44 | * RVT is destroyed after the current instructions ends. 45 | */ 46 | #define XSLT_RVT_LOCAL 1 47 | 48 | /** 49 | * XSLT_RVT_FUNC_RESULT: 50 | * 51 | * RVT is part of results returned with func:result. The RVT won't be 52 | * destroyed after exiting a template and will be reset to XSLT_RVT_LOCAL or 53 | * XSLT_RVT_VARIABLE in the template that receives the return value. 54 | */ 55 | #define XSLT_RVT_FUNC_RESULT 2 56 | 57 | /** 58 | * XSLT_RVT_GLOBAL: 59 | * 60 | * RVT is part of a global variable. 61 | */ 62 | #define XSLT_RVT_GLOBAL 3 63 | 64 | /* 65 | * Interfaces for the variable module. 66 | */ 67 | 68 | XSLTPUBFUN int XSLTCALL 69 | xsltEvalGlobalVariables (xsltTransformContextPtr ctxt); 70 | XSLTPUBFUN int XSLTCALL 71 | xsltEvalUserParams (xsltTransformContextPtr ctxt, 72 | const char **params); 73 | XSLTPUBFUN int XSLTCALL 74 | xsltQuoteUserParams (xsltTransformContextPtr ctxt, 75 | const char **params); 76 | XSLTPUBFUN int XSLTCALL 77 | xsltEvalOneUserParam (xsltTransformContextPtr ctxt, 78 | const xmlChar * name, 79 | const xmlChar * value); 80 | XSLTPUBFUN int XSLTCALL 81 | xsltQuoteOneUserParam (xsltTransformContextPtr ctxt, 82 | const xmlChar * name, 83 | const xmlChar * value); 84 | 85 | XSLTPUBFUN void XSLTCALL 86 | xsltParseGlobalVariable (xsltStylesheetPtr style, 87 | xmlNodePtr cur); 88 | XSLTPUBFUN void XSLTCALL 89 | xsltParseGlobalParam (xsltStylesheetPtr style, 90 | xmlNodePtr cur); 91 | XSLTPUBFUN void XSLTCALL 92 | xsltParseStylesheetVariable (xsltTransformContextPtr ctxt, 93 | xmlNodePtr cur); 94 | XSLTPUBFUN void XSLTCALL 95 | xsltParseStylesheetParam (xsltTransformContextPtr ctxt, 96 | xmlNodePtr cur); 97 | XSLTPUBFUN xsltStackElemPtr XSLTCALL 98 | xsltParseStylesheetCallerParam (xsltTransformContextPtr ctxt, 99 | xmlNodePtr cur); 100 | XSLTPUBFUN int XSLTCALL 101 | xsltAddStackElemList (xsltTransformContextPtr ctxt, 102 | xsltStackElemPtr elems); 103 | XSLTPUBFUN void XSLTCALL 104 | xsltFreeGlobalVariables (xsltTransformContextPtr ctxt); 105 | XSLTPUBFUN xmlXPathObjectPtr XSLTCALL 106 | xsltVariableLookup (xsltTransformContextPtr ctxt, 107 | const xmlChar *name, 108 | const xmlChar *ns_uri); 109 | XSLTPUBFUN xmlXPathObjectPtr XSLTCALL 110 | xsltXPathVariableLookup (void *ctxt, 111 | const xmlChar *name, 112 | const xmlChar *ns_uri); 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | 117 | #endif /* __XML_XSLT_VARIABLES_H__ */ 118 | 119 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | ******** 2 | * * 3 | * TODO * 4 | * * 5 | ******** 6 | 7 | Lifetime of result Value Tree, make sure we keep pointers. Exslt 8 | handling of node set values is especially nasty in this respect, 9 | lots of potential mem leaks... 10 | 11 | Pattern tester: 12 | -> try to optimize for ID scan and tests. 13 | 14 | Pattern scanner: 15 | -> add error checks on all returns 16 | 17 | Sorting: 18 | -> add lang and case-order 19 | -> add foreign sorting functions (interfaces ?). 20 | 21 | ******** 22 | * * 23 | * DONE * 24 | * * 25 | ******** 26 | 27 | Design: 28 | - should transforms for a given stylesheet be thread clean, 29 | -> the precompilation now occur only at stylesheet processing 30 | time (except the binding for named templates and extension 31 | functions which need to be computed once at run-time). 32 | Multiple threads should be able to reuse the same stylesheet 33 | now. 34 | 35 | Embedding Stylesheets: 36 | - example in 2.7 would force to validate, we do it by default now 37 | 38 | ID and Key support: 39 | -> Done 40 | 41 | Extra functions: 42 | -> document() should not be a problem since Result Tree Fragments are 43 | implemented 44 | => Done 45 | 46 | Templates: 47 | -> check the built-in template rule for attributes 48 | -> make sure @xxx matches are applied 49 | 50 | Contextual error reporting: 51 | -> provide a couple of functions providing context analysis, not urgent 52 | 53 | Validity: 54 | -> should we add validation by default ? Make this an option 55 | -> redirrect validity errors 56 | => done added a special parsing mode 57 | 58 | Import: 59 | -> parse them 60 | -> provide functions to circulate in the import tree of stylesheets 61 | -> make sure we use the cascade wherever it's needed 62 | 63 | Extra functions: 64 | -> make a separate module. 65 | => done functions.[ch] 66 | 67 | Support Attribute value templates: 68 | -> starts to be urgent. Design it in flexible ways but try to optimize 69 | to handle most of it at the stylesheet parse time ... 70 | => Done for the most part need to check all attributes in XSLT constructs 71 | using them and use the dedicated readin function. 72 | -> optimization by checking their existence at stylesheet parse time. 73 | => done when building the preproc function 74 | 75 | Sorting: 76 | -> add support for imbricated sorts 77 | => done but not well tested. 78 | 79 | Separate util module: 80 | -> macros, config, verbosity ? 81 | => xsltutils.[ch] 82 | 83 | Support for disable-output-escaping="yes": 84 | -> looks problematic, libxml has no support for anything like this, 85 | and unless adding a new node type :-( or tweaking text node and 86 | output routines this is gonna be messy ... must be handled at libxml 87 | level. 88 | => Done with a trick, text node name is different, requires > 2.2.11 89 | 90 | Pattern scanner: 91 | -> compute priority 92 | -> handle unions 93 | -> support for mode 94 | => done 95 | 96 | Pattern tester: 97 | -> also put fast lookup for "text()", "comment()", "node()" 98 | based patterns lists. 99 | => done 100 | 101 | Support Attribute value templates: 102 | -> namespace support for attribute value templates is not done, need 103 | a small API redesign 104 | 105 | Doc: 106 | - put a page at http://xmlsoft.org/XSLT/ 107 | - generate/transform the DocBook to HTML 108 | - add HTML to package 109 | - manpage and doc for xsltproc 110 | 111 | 112 | Error handling: 113 | -> check the version stuff, design a separate module for error interfacing 114 | and default handling, parsing vs. runtime, fatal / compat / warning, 115 | and lack of optionnal features. 116 | -> reports context 117 | 118 | ID and Key support: 119 | -> done but namespace support in keys is not defined 120 | -> make sure keys are recomputed on new document input 121 | 122 | Profiler: 123 | -> added looks good enough 124 | -> autocorrection of initial calibration loop 125 | -------------------------------------------------------------------------------- /libxslt/xsltconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: compile-time version information for the XSLT engine 3 | * Description: compile-time version information for the XSLT engine 4 | * this module is autogenerated. 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Daniel Veillard 9 | */ 10 | 11 | #ifndef __XML_XSLTCONFIG_H__ 12 | #define __XML_XSLTCONFIG_H__ 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | /** 19 | * LIBXSLT_DOTTED_VERSION: 20 | * 21 | * the version string like "1.2.3" 22 | */ 23 | #define LIBXSLT_DOTTED_VERSION "1.1.45" 24 | 25 | /** 26 | * LIBXSLT_VERSION: 27 | * 28 | * the version number: 1.2.3 value is 10203 29 | */ 30 | #define LIBXSLT_VERSION 10145 31 | 32 | /** 33 | * LIBXSLT_VERSION_STRING: 34 | * 35 | * the version number string, 1.2.3 value is "10203" 36 | */ 37 | #define LIBXSLT_VERSION_STRING "10145" 38 | 39 | /** 40 | * LIBXSLT_VERSION_EXTRA: 41 | * 42 | * extra version information, used to show a Git commit description 43 | */ 44 | #define LIBXSLT_VERSION_EXTRA "" 45 | 46 | /** 47 | * WITH_XSLT_DEBUG: 48 | * 49 | * Activate the compilation of the debug reporting. Speed penalty 50 | * is insignifiant and being able to run xsltpoc -v is useful. On 51 | * by default unless --without-debug is passed to configure 52 | */ 53 | #if 1 54 | #define WITH_XSLT_DEBUG 55 | #endif 56 | 57 | #if 0 58 | /** 59 | * DEBUG_MEMORY: 60 | * 61 | * should be activated only when debugging libxslt. It replaces the 62 | * allocator with a collect and debug shell to the libc allocator. 63 | * Use configure --with-mem-debug to activate it on both library 64 | */ 65 | #define DEBUG_MEMORY 66 | 67 | /** 68 | * DEBUG_MEMORY_LOCATION: 69 | * 70 | * should be activated only when debugging libxslt. 71 | * DEBUG_MEMORY_LOCATION should be activated only when libxml has 72 | * been configured with --with-debug-mem too 73 | */ 74 | #define DEBUG_MEMORY_LOCATION 75 | #endif 76 | 77 | /** 78 | * XSLT_NEED_TRIO: 79 | * 80 | * should be activated if the existing libc library lacks some of the 81 | * string formatting function, in that case reuse the Trio ones already 82 | * compiled in the libxml2 library. 83 | */ 84 | 85 | #if 0 86 | #define XSLT_NEED_TRIO 87 | #endif 88 | #ifdef __VMS 89 | #define HAVE_SYS_STAT_H 1 90 | #ifndef XSLT_NEED_TRIO 91 | #define XSLT_NEED_TRIO 92 | #endif 93 | #endif 94 | 95 | #ifdef XSLT_NEED_TRIO 96 | #define TRIO_REPLACE_STDIO 97 | #endif 98 | 99 | /** 100 | * WITH_XSLT_DEBUGGER: 101 | * 102 | * Activate the compilation of the debugger support. Speed penalty 103 | * is insignifiant. 104 | * On by default unless --without-debugger is passed to configure 105 | */ 106 | #if 1 107 | #ifndef WITH_DEBUGGER 108 | #define WITH_DEBUGGER 109 | #endif 110 | #endif 111 | 112 | /** 113 | * WITH_PROFILER: 114 | * 115 | * Activate the compilation of the profiler. Speed penalty 116 | * is insignifiant. 117 | * On by default unless --without-profiler is passed to configure 118 | */ 119 | #if 1 120 | #ifndef WITH_PROFILER 121 | #define WITH_PROFILER 122 | #endif 123 | #endif 124 | 125 | /** 126 | * WITH_MODULES: 127 | * 128 | * Whether module support is configured into libxslt 129 | * Note: no default module path for win32 platforms 130 | */ 131 | #if 0 132 | #ifndef WITH_MODULES 133 | #define WITH_MODULES 134 | #endif 135 | #define LIBXSLT_DEFAULT_PLUGINS_PATH() "NULL" 136 | #endif 137 | 138 | /** 139 | * ATTRIBUTE_UNUSED: 140 | * 141 | * This macro is used to flag unused function parameters to GCC 142 | */ 143 | #ifdef __GNUC__ 144 | #ifndef ATTRIBUTE_UNUSED 145 | #define ATTRIBUTE_UNUSED __attribute__((unused)) 146 | #endif 147 | #else 148 | #define ATTRIBUTE_UNUSED 149 | #endif 150 | 151 | /** 152 | * LIBXSLT_ATTR_FORMAT: 153 | * 154 | * This macro is used to indicate to GCC the parameters are printf-like 155 | */ 156 | #ifdef __GNUC__ 157 | #define LIBXSLT_ATTR_FORMAT(fmt,args) __attribute__((__format__(__printf__,fmt,args))) 158 | #else 159 | #define LIBXSLT_ATTR_FORMAT(fmt,args) 160 | #endif 161 | 162 | /** 163 | * LIBXSLT_PUBLIC: 164 | * 165 | * This macro is used to declare PUBLIC variables for Cygwin and for MSC on Windows 166 | */ 167 | #if !defined LIBXSLT_PUBLIC 168 | #if (defined(__CYGWIN__) || defined _MSC_VER) && !defined IN_LIBXSLT && !defined LIBXSLT_STATIC 169 | #define LIBXSLT_PUBLIC __declspec(dllimport) 170 | #else 171 | #define LIBXSLT_PUBLIC 172 | #endif 173 | #endif 174 | 175 | #ifdef __cplusplus 176 | } 177 | #endif 178 | 179 | #endif /* __XML_XSLTCONFIG_H__ */ 180 | -------------------------------------------------------------------------------- /FEATURES: -------------------------------------------------------------------------------- 1 | Status of implementation of the XSLT 1.0 Features: 2 | ================================================== 3 | 4 | Stylesheet Constructs: 5 | ====================== 6 | 7 | YES xsl:stylesheet 8 | ? id = id 9 | YES extension-element-prefixes = tokens 10 | YES exclude-result-prefixes = tokens 11 | YES version = number 12 | 13 | YES xsl:transform 14 | ? id = id 15 | YES extension-element-prefixes = tokens 16 | YES exclude-result-prefixes = tokens 17 | YES version = number 18 | 19 | 20 | YES Literal Result Element as Stylesheet 21 | 22 | YES Embedding Stylesheets 23 | 24 | NO mediaType 25 | 26 | Top Level Elements: 27 | =================== 28 | 29 | YES xsl:include 30 | YES href = uri-reference 31 | 32 | YES xsl:import 33 | YES href = uri-reference 34 | 35 | YES xsl:strip-space 36 | YES elements = tokens 37 | 38 | YES xsl:preserve-space 39 | YES elements = tokens 40 | 41 | YES xsl:template 42 | YES match = pattern 43 | YES name = qname 44 | YES priority = number 45 | YES mode = qname 46 | 47 | YES xsl:namespace-alias 48 | YES stylesheet-prefix = prefix | "#default" 49 | YES result-prefix = prefix | "#default" 50 | 51 | YES xsl:attribute-set 52 | YES name = qname 53 | YES use-attribute-sets = qnames 54 | 55 | YES xsl:variable 56 | YES name = qname 57 | YES select = expression 58 | YES Content: template 59 | 60 | YES xsl:param 61 | YES name = qname 62 | YES select = expression 63 | YES Content: template 64 | 65 | YES xsl:key 66 | YES name = qname 67 | YES match = pattern 68 | YES use = expression 69 | 70 | YES xsl:output 71 | YES method = "xml" | "html" | "text" | qname-but-not-ncname 72 | YES version = nmtoken 73 | YES encoding = string 74 | YES omit-xml-declaration = "yes" | "no" 75 | YES standalone = "yes" | "no" 76 | YES doctype-public = string 77 | YES doctype-system = string 78 | YES cdata-section-elements = qnames 79 | YES indent = "yes" | "no" 80 | YES media-type = string 81 | 82 | Instructions: 83 | ============= 84 | 85 | YES xsl:apply-templates 86 | YES select = node-set-expression 87 | YES mode = qname 88 | 89 | YES xsl:apply-imports 90 | 91 | YES xsl:call-template 92 | YES name = qname 93 | 94 | YES xsl:element 95 | YES name = { qname } 96 | YES namespace = { uri-reference } 97 | YES use-attribute-sets = qnames 98 | 99 | YES xsl:attribute 100 | YES name = { qname } 101 | YES namespace = { uri-reference } 102 | 103 | YES xsl:text 104 | YES disable-output-escaping = "yes" | "no" 105 | 106 | YES xsl:processing-instruction 107 | YES name = { ncname } 108 | 109 | YES xsl:comment 110 | 111 | YES xsl:copy 112 | YES use-attribute-sets = qnames 113 | 114 | YES xsl:value-of 115 | YES select = string-expression 116 | YES disable-output-escaping = "yes" | "no" 117 | 118 | YES xsl:number 119 | YES level = "single" | "multiple" | "any" 120 | YES count = pattern 121 | YES from = pattern 122 | YES value = number-expression 123 | YES format = { string } 124 | NO lang = { nmtoken } 125 | NO letter-value = { "alphabetic" | "traditional" } 126 | YES grouping-separator = { char } 127 | YES grouping-size = { number } 128 | 129 | YES xsl:for-each 130 | YES select = node-set-expression 131 | 132 | YES xsl:if 133 | YES test = boolean-expression 134 | 135 | YES xsl:choose 136 | 137 | YES xsl:when 138 | YES test = boolean-expression 139 | 140 | YES xsl:otherwise 141 | 142 | YES xsl:sort 143 | YES select = string-expression 144 | NO lang = { nmtoken } 145 | YES data-type = { "text" | "number" | qname-but-not-ncname } 146 | YES order = { "ascending" | "descending" } 147 | NO case-order = { "upper-first" | "lower-first" } 148 | 149 | YES xsl:variable 150 | YES name = qname 151 | YES select = expression 152 | YES Content: template 153 | 154 | YES xsl:param 155 | YES name = qname 156 | YES select = expression 157 | YES Content: template 158 | 159 | YES xsl:copy-of 160 | YES select = expression 161 | 162 | YES xsl:with-param 163 | YES name = qname 164 | YES select = expression 165 | 166 | YES xsl:decimal-format 167 | YES name = qname 168 | YES decimal-separator = char 169 | YES grouping-separator = char 170 | YES infinity = string 171 | YES minus-sign = char 172 | YES NaN = string 173 | YES percent = char 174 | YES per-mille = char 175 | YES zero-digit = char 176 | YES digit = char 177 | YES pattern-separator = char 178 | 179 | YES xsl:message 180 | YES terminate = "yes" | "no" 181 | 182 | YES xsl:fallback 183 | 184 | General: 185 | ======== 186 | 187 | YES Conflict Resolution for Template Rules 188 | 189 | YES Whitespace Stripping 190 | 191 | YES Built-in Template Rules 192 | YES match="*|/" 193 | YES match="text()|@*" 194 | YES match="processing-instruction()|comment()" 195 | YES Namespace 196 | YES Mode 197 | 198 | YES Extension Elements 199 | 200 | YES Extension Functions 201 | 202 | YES Attribute Value Templates 203 | 204 | YES Result Tree Fragments 205 | 206 | Functions: 207 | ========== 208 | 209 | YES node-set document(object, node-set?) 210 | YES node-set key(string, object) 211 | YES string format-number(number, string, string?) 212 | YES node-set current() 213 | YES string unparsed-entity-uri(string) 214 | YES string generate-id(node-set?) 215 | YES object system-property(string) 216 | YES boolean element-available(string) 217 | YES boolean function-available(string) 218 | 219 | Patterns: 220 | ========= 221 | 222 | YES para 223 | YES * 224 | YES chapter|appendix 225 | YES olist/item 226 | YES appendix//para 227 | YES / 228 | YES text() 229 | YES processing-instruction() 230 | YES node() 231 | YES id("W11") 232 | YES para[1] 233 | YES *[position()=1 and self::para] 234 | YES para[last()=1] 235 | YES items/item[position()>1] 236 | YES item[position() mod 2 = 1] 237 | YES div[@class="appendix"]//p 238 | YES @class 239 | YES @* 240 | YES except ns for key key('a','b') 241 | 242 | daniel@veillard.com 243 | -------------------------------------------------------------------------------- /libxslt/extra.c: -------------------------------------------------------------------------------- 1 | /* 2 | * extra.c: Implementation of non-standard features 3 | * 4 | * Reference: 5 | * Michael Kay "XSLT Programmer's Reference" pp 637-643 6 | * The node-set() extension function 7 | * 8 | * See Copyright for the status of this software. 9 | * 10 | * daniel@veillard.com 11 | */ 12 | 13 | #define IN_LIBXSLT 14 | #include "libxslt.h" 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "xslt.h" 25 | #include "xsltInternals.h" 26 | #include "xsltutils.h" 27 | #include "extensions.h" 28 | #include "variables.h" 29 | #include "transform.h" 30 | #include "extra.h" 31 | #include "preproc.h" 32 | 33 | #ifdef WITH_XSLT_DEBUG 34 | #define WITH_XSLT_DEBUG_EXTRA 35 | #endif 36 | 37 | /************************************************************************ 38 | * * 39 | * Handling of XSLT debugging * 40 | * * 41 | ************************************************************************/ 42 | 43 | /** 44 | * xsltDebug: 45 | * @ctxt: an XSLT processing context 46 | * @node: The current node 47 | * @inst: the instruction in the stylesheet 48 | * @comp: precomputed information 49 | * 50 | * Process an debug node 51 | */ 52 | void 53 | xsltDebug(xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, 54 | xmlNodePtr inst ATTRIBUTE_UNUSED, 55 | xsltElemPreCompPtr comp ATTRIBUTE_UNUSED) 56 | { 57 | int i, j; 58 | 59 | xsltGenericError(xsltGenericErrorContext, "Templates:\n"); 60 | for (i = 0, j = ctxt->templNr - 1; ((i < 15) && (j >= 0)); i++, j--) { 61 | xsltGenericError(xsltGenericErrorContext, "#%d ", i); 62 | if (ctxt->templTab[j]->name != NULL) 63 | xsltGenericError(xsltGenericErrorContext, "name %s ", 64 | ctxt->templTab[j]->name); 65 | if (ctxt->templTab[j]->match != NULL) 66 | xsltGenericError(xsltGenericErrorContext, "name %s ", 67 | ctxt->templTab[j]->match); 68 | if (ctxt->templTab[j]->mode != NULL) 69 | xsltGenericError(xsltGenericErrorContext, "name %s ", 70 | ctxt->templTab[j]->mode); 71 | xsltGenericError(xsltGenericErrorContext, "\n"); 72 | } 73 | xsltGenericError(xsltGenericErrorContext, "Variables:\n"); 74 | for (i = 0, j = ctxt->varsNr - 1; ((i < 15) && (j >= 0)); i++, j--) { 75 | xsltStackElemPtr cur; 76 | 77 | if (ctxt->varsTab[j] == NULL) 78 | continue; 79 | xsltGenericError(xsltGenericErrorContext, "#%d\n", i); 80 | cur = ctxt->varsTab[j]; 81 | while (cur != NULL) { 82 | if (cur->comp == NULL) { 83 | xsltGenericError(xsltGenericErrorContext, 84 | "corrupted !!!\n"); 85 | } else if (cur->comp->type == XSLT_FUNC_PARAM) { 86 | xsltGenericError(xsltGenericErrorContext, "param "); 87 | } else if (cur->comp->type == XSLT_FUNC_VARIABLE) { 88 | xsltGenericError(xsltGenericErrorContext, "var "); 89 | } 90 | if (cur->name != NULL) 91 | xsltGenericError(xsltGenericErrorContext, "%s ", 92 | cur->name); 93 | else 94 | xsltGenericError(xsltGenericErrorContext, "noname !!!!"); 95 | #ifdef LIBXML_DEBUG_ENABLED 96 | if (cur->value != NULL) { 97 | if ((xsltGenericDebugContext == stdout) || 98 | (xsltGenericDebugContext == stderr)) 99 | xmlXPathDebugDumpObject((FILE*)xsltGenericDebugContext, 100 | cur->value, 1); 101 | } else { 102 | xsltGenericError(xsltGenericErrorContext, "NULL !!!!"); 103 | } 104 | #endif 105 | xsltGenericError(xsltGenericErrorContext, "\n"); 106 | cur = cur->next; 107 | } 108 | 109 | } 110 | } 111 | 112 | /************************************************************************ 113 | * * 114 | * Classic extensions as described by M. Kay * 115 | * * 116 | ************************************************************************/ 117 | 118 | /** 119 | * xsltFunctionNodeSet: 120 | * @ctxt: the XPath Parser context 121 | * @nargs: the number of arguments 122 | * 123 | * Implement the node-set() XSLT function 124 | * node-set node-set(result-tree) 125 | * 126 | * This function is available in libxslt, saxon or xt namespace. 127 | */ 128 | void 129 | xsltFunctionNodeSet(xmlXPathParserContextPtr ctxt, int nargs){ 130 | if (nargs != 1) { 131 | xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, 132 | "node-set() : expects one result-tree arg\n"); 133 | ctxt->error = XPATH_INVALID_ARITY; 134 | return; 135 | } 136 | if ((ctxt->value == NULL) || 137 | ((ctxt->value->type != XPATH_XSLT_TREE) && 138 | (ctxt->value->type != XPATH_NODESET))) { 139 | xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, 140 | "node-set() invalid arg expecting a result tree\n"); 141 | ctxt->error = XPATH_INVALID_TYPE; 142 | return; 143 | } 144 | if (ctxt->value->type == XPATH_XSLT_TREE) { 145 | ctxt->value->type = XPATH_NODESET; 146 | } 147 | } 148 | 149 | /** 150 | * xsltRegisterExtras: 151 | * @ctxt: a XSLT process context 152 | * 153 | * Registers the built-in extensions. This function is deprecated, use 154 | * xsltRegisterAllExtras instead. 155 | */ 156 | void 157 | xsltRegisterExtras(xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED) { 158 | xsltRegisterAllExtras(); 159 | } 160 | 161 | /** 162 | * xsltRegisterAllExtras: 163 | * 164 | * Registers the built-in extensions 165 | */ 166 | void 167 | xsltRegisterAllExtras (void) { 168 | xsltRegisterExtModuleFunction((const xmlChar *) "node-set", 169 | XSLT_LIBXSLT_NAMESPACE, 170 | xsltFunctionNodeSet); 171 | xsltRegisterExtModuleFunction((const xmlChar *) "node-set", 172 | XSLT_SAXON_NAMESPACE, 173 | xsltFunctionNodeSet); 174 | xsltRegisterExtModuleFunction((const xmlChar *) "node-set", 175 | XSLT_XT_NAMESPACE, 176 | xsltFunctionNodeSet); 177 | xsltRegisterExtModuleElement((const xmlChar *) "debug", 178 | XSLT_LIBXSLT_NAMESPACE, 179 | NULL, 180 | xsltDebug); 181 | xsltRegisterExtModuleElement((const xmlChar *) "output", 182 | XSLT_SAXON_NAMESPACE, 183 | xsltDocumentComp, 184 | xsltDocumentElem); 185 | xsltRegisterExtModuleElement((const xmlChar *) "write", 186 | XSLT_XALAN_NAMESPACE, 187 | xsltDocumentComp, 188 | xsltDocumentElem); 189 | xsltRegisterExtModuleElement((const xmlChar *) "document", 190 | XSLT_XT_NAMESPACE, 191 | xsltDocumentComp, 192 | xsltDocumentElem); 193 | xsltRegisterExtModuleElement((const xmlChar *) "document", 194 | XSLT_NAMESPACE, 195 | xsltDocumentComp, 196 | xsltDocumentElem); 197 | } 198 | -------------------------------------------------------------------------------- /libxslt/transform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: the XSLT engine transformation part. 3 | * Description: This module implements the bulk of the actual 4 | * transformation processing. Most of the xsl: element 5 | * constructs are implemented in this module. 6 | * 7 | * Copy: See Copyright for the status of this software. 8 | * 9 | * Author: Daniel Veillard 10 | */ 11 | 12 | #ifndef __XML_XSLT_TRANSFORM_H__ 13 | #define __XML_XSLT_TRANSFORM_H__ 14 | 15 | #include 16 | #include 17 | #include "xsltexports.h" 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * XInclude default processing. 26 | */ 27 | XSLTPUBFUN void XSLTCALL 28 | xsltSetXIncludeDefault (int xinclude); 29 | XSLTPUBFUN int XSLTCALL 30 | xsltGetXIncludeDefault (void); 31 | 32 | /** 33 | * Export context to users. 34 | */ 35 | XSLTPUBFUN xsltTransformContextPtr XSLTCALL 36 | xsltNewTransformContext (xsltStylesheetPtr style, 37 | xmlDocPtr doc); 38 | 39 | XSLTPUBFUN void XSLTCALL 40 | xsltFreeTransformContext(xsltTransformContextPtr ctxt); 41 | 42 | XSLTPUBFUN xmlDocPtr XSLTCALL 43 | xsltApplyStylesheetUser (xsltStylesheetPtr style, 44 | xmlDocPtr doc, 45 | const char **params, 46 | const char *output, 47 | FILE * profile, 48 | xsltTransformContextPtr userCtxt); 49 | XSLTPUBFUN void XSLTCALL 50 | xsltProcessOneNode (xsltTransformContextPtr ctxt, 51 | xmlNodePtr node, 52 | xsltStackElemPtr params); 53 | /** 54 | * Private Interfaces. 55 | */ 56 | XSLTPUBFUN void XSLTCALL 57 | xsltApplyStripSpaces (xsltTransformContextPtr ctxt, 58 | xmlNodePtr node); 59 | XSLTPUBFUN xmlDocPtr XSLTCALL 60 | xsltApplyStylesheet (xsltStylesheetPtr style, 61 | xmlDocPtr doc, 62 | const char **params); 63 | XSLTPUBFUN xmlDocPtr XSLTCALL 64 | xsltProfileStylesheet (xsltStylesheetPtr style, 65 | xmlDocPtr doc, 66 | const char **params, 67 | FILE * output); 68 | XSLTPUBFUN int XSLTCALL 69 | xsltRunStylesheet (xsltStylesheetPtr style, 70 | xmlDocPtr doc, 71 | const char **params, 72 | const char *output, 73 | xmlSAXHandlerPtr SAX, 74 | xmlOutputBufferPtr IObuf); 75 | XSLTPUBFUN int XSLTCALL 76 | xsltRunStylesheetUser (xsltStylesheetPtr style, 77 | xmlDocPtr doc, 78 | const char **params, 79 | const char *output, 80 | xmlSAXHandlerPtr SAX, 81 | xmlOutputBufferPtr IObuf, 82 | FILE * profile, 83 | xsltTransformContextPtr userCtxt); 84 | XSLTPUBFUN void XSLTCALL 85 | xsltApplyOneTemplate (xsltTransformContextPtr ctxt, 86 | xmlNodePtr node, 87 | xmlNodePtr list, 88 | xsltTemplatePtr templ, 89 | xsltStackElemPtr params); 90 | XSLTPUBFUN void XSLTCALL 91 | xsltDocumentElem (xsltTransformContextPtr ctxt, 92 | xmlNodePtr node, 93 | xmlNodePtr inst, 94 | xsltElemPreCompPtr comp); 95 | XSLTPUBFUN void XSLTCALL 96 | xsltSort (xsltTransformContextPtr ctxt, 97 | xmlNodePtr node, 98 | xmlNodePtr inst, 99 | xsltElemPreCompPtr comp); 100 | XSLTPUBFUN void XSLTCALL 101 | xsltCopy (xsltTransformContextPtr ctxt, 102 | xmlNodePtr node, 103 | xmlNodePtr inst, 104 | xsltElemPreCompPtr comp); 105 | XSLTPUBFUN void XSLTCALL 106 | xsltText (xsltTransformContextPtr ctxt, 107 | xmlNodePtr node, 108 | xmlNodePtr inst, 109 | xsltElemPreCompPtr comp); 110 | XSLTPUBFUN void XSLTCALL 111 | xsltElement (xsltTransformContextPtr ctxt, 112 | xmlNodePtr node, 113 | xmlNodePtr inst, 114 | xsltElemPreCompPtr comp); 115 | XSLTPUBFUN void XSLTCALL 116 | xsltComment (xsltTransformContextPtr ctxt, 117 | xmlNodePtr node, 118 | xmlNodePtr inst, 119 | xsltElemPreCompPtr comp); 120 | XSLTPUBFUN void XSLTCALL 121 | xsltAttribute (xsltTransformContextPtr ctxt, 122 | xmlNodePtr node, 123 | xmlNodePtr inst, 124 | xsltElemPreCompPtr comp); 125 | XSLTPUBFUN void XSLTCALL 126 | xsltProcessingInstruction(xsltTransformContextPtr ctxt, 127 | xmlNodePtr node, 128 | xmlNodePtr inst, 129 | xsltElemPreCompPtr comp); 130 | XSLTPUBFUN void XSLTCALL 131 | xsltCopyOf (xsltTransformContextPtr ctxt, 132 | xmlNodePtr node, 133 | xmlNodePtr inst, 134 | xsltElemPreCompPtr comp); 135 | XSLTPUBFUN void XSLTCALL 136 | xsltValueOf (xsltTransformContextPtr ctxt, 137 | xmlNodePtr node, 138 | xmlNodePtr inst, 139 | xsltElemPreCompPtr comp); 140 | XSLTPUBFUN void XSLTCALL 141 | xsltNumber (xsltTransformContextPtr ctxt, 142 | xmlNodePtr node, 143 | xmlNodePtr inst, 144 | xsltElemPreCompPtr comp); 145 | XSLTPUBFUN void XSLTCALL 146 | xsltApplyImports (xsltTransformContextPtr ctxt, 147 | xmlNodePtr node, 148 | xmlNodePtr inst, 149 | xsltElemPreCompPtr comp); 150 | XSLTPUBFUN void XSLTCALL 151 | xsltCallTemplate (xsltTransformContextPtr ctxt, 152 | xmlNodePtr node, 153 | xmlNodePtr inst, 154 | xsltElemPreCompPtr comp); 155 | XSLTPUBFUN void XSLTCALL 156 | xsltApplyTemplates (xsltTransformContextPtr ctxt, 157 | xmlNodePtr node, 158 | xmlNodePtr inst, 159 | xsltElemPreCompPtr comp); 160 | XSLTPUBFUN void XSLTCALL 161 | xsltChoose (xsltTransformContextPtr ctxt, 162 | xmlNodePtr node, 163 | xmlNodePtr inst, 164 | xsltElemPreCompPtr comp); 165 | XSLTPUBFUN void XSLTCALL 166 | xsltIf (xsltTransformContextPtr ctxt, 167 | xmlNodePtr node, 168 | xmlNodePtr inst, 169 | xsltElemPreCompPtr comp); 170 | XSLTPUBFUN void XSLTCALL 171 | xsltForEach (xsltTransformContextPtr ctxt, 172 | xmlNodePtr node, 173 | xmlNodePtr inst, 174 | xsltElemPreCompPtr comp); 175 | XSLTPUBFUN void XSLTCALL 176 | xsltRegisterAllElement (xsltTransformContextPtr ctxt); 177 | 178 | XSLTPUBFUN xmlNodePtr XSLTCALL 179 | xsltCopyTextString (xsltTransformContextPtr ctxt, 180 | xmlNodePtr target, 181 | const xmlChar *string, 182 | int noescape); 183 | 184 | /* Following 2 functions needed for libexslt/functions.c */ 185 | XSLTPUBFUN void XSLTCALL 186 | xsltLocalVariablePop (xsltTransformContextPtr ctxt, 187 | int limitNr, 188 | int level); 189 | XSLTPUBFUN int XSLTCALL 190 | xsltLocalVariablePush (xsltTransformContextPtr ctxt, 191 | xsltStackElemPtr variable, 192 | int level); 193 | /* 194 | * Hook for the debugger if activated. 195 | */ 196 | XSLTPUBFUN void XSLTCALL 197 | xslHandleDebugger (xmlNodePtr cur, 198 | xmlNodePtr node, 199 | xsltTemplatePtr templ, 200 | xsltTransformContextPtr ctxt); 201 | 202 | #ifdef __cplusplus 203 | } 204 | #endif 205 | 206 | #endif /* __XML_XSLT_TRANSFORM_H__ */ 207 | 208 | -------------------------------------------------------------------------------- /libxslt/triodef.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * $Id$ 4 | * 5 | * Copyright (C) 2001 Bjorn Reese 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 12 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 13 | * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND 14 | * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. 15 | * 16 | ************************************************************************/ 17 | 18 | #ifndef TRIO_TRIODEF_H 19 | #define TRIO_TRIODEF_H 20 | 21 | /************************************************************************* 22 | * Platform and compiler support detection 23 | */ 24 | #if defined(__GNUC__) 25 | # define TRIO_COMPILER_GCC 26 | #elif defined(__SUNPRO_C) 27 | # define TRIO_COMPILER_SUNPRO 28 | #elif defined(__SUNPRO_CC) 29 | # define TRIO_COMPILER_SUNPRO 30 | # define __SUNPRO_C __SUNPRO_CC 31 | #elif defined(__xlC__) || defined(__IBMC__) || defined(__IBMCPP__) 32 | # define TRIO_COMPILER_XLC 33 | #elif defined(_AIX) && !defined(__GNUC__) 34 | # define TRIO_COMPILER_XLC /* Workaround for old xlc */ 35 | #elif defined(__DECC) || defined(__DECCXX) 36 | # define TRIO_COMPILER_DECC 37 | #elif defined(__osf__) && defined(__LANGUAGE_C__) 38 | # define TRIO_COMPILER_DECC /* Workaround for old DEC C compilers */ 39 | #elif defined(_MSC_VER) 40 | # define TRIO_COMPILER_MSVC 41 | #elif defined(__BORLANDC__) 42 | # define TRIO_COMPILER_BCB 43 | #endif 44 | 45 | #if defined(VMS) || defined(__VMS) 46 | /* 47 | * VMS is placed first to avoid identifying the platform as Unix 48 | * based on the DECC compiler later on. 49 | */ 50 | # define TRIO_PLATFORM_VMS 51 | #elif defined(unix) || defined(__unix) || defined(__unix__) 52 | # define TRIO_PLATFORM_UNIX 53 | #elif defined(TRIO_COMPILER_XLC) || defined(_AIX) 54 | # define TRIO_PLATFORM_UNIX 55 | #elif defined(TRIO_COMPILER_DECC) || defined(__osf___) 56 | # define TRIO_PLATFORM_UNIX 57 | #elif defined(__NetBSD__) 58 | # define TRIO_PLATFORM_UNIX 59 | #elif defined(__QNX__) 60 | # define TRIO_PLATFORM_UNIX 61 | # define TRIO_PLATFORM_QNX 62 | #elif defined(__CYGWIN__) 63 | # define TRIO_PLATFORM_UNIX 64 | #elif defined(AMIGA) && defined(TRIO_COMPILER_GCC) 65 | # define TRIO_PLATFORM_UNIX 66 | #elif defined(TRIO_COMPILER_MSVC) || defined(WIN32) || defined(_WIN32) 67 | # define TRIO_PLATFORM_WIN32 68 | #elif defined(mpeix) || defined(__mpexl) 69 | # define TRIO_PLATFORM_MPEIX 70 | #endif 71 | 72 | #if defined(_AIX) 73 | # define TRIO_PLATFORM_AIX 74 | #elif defined(__hpux) 75 | # define TRIO_PLATFORM_HPUX 76 | #elif defined(sun) || defined(__sun__) 77 | # if defined(__SVR4) || defined(__svr4__) 78 | # define TRIO_PLATFORM_SOLARIS 79 | # else 80 | # define TRIO_PLATFORM_SUNOS 81 | # endif 82 | #endif 83 | 84 | #if defined(__STDC__) || defined(TRIO_COMPILER_MSVC) || defined(TRIO_COMPILER_BCB) 85 | # define TRIO_COMPILER_SUPPORTS_C89 86 | # if defined(__STDC_VERSION__) 87 | # define TRIO_COMPILER_SUPPORTS_C90 88 | # if (__STDC_VERSION__ >= 199409L) 89 | # define TRIO_COMPILER_SUPPORTS_C94 90 | # endif 91 | # if (__STDC_VERSION__ >= 199901L) 92 | # define TRIO_COMPILER_SUPPORTS_C99 93 | # endif 94 | # elif defined(TRIO_COMPILER_SUNPRO) 95 | # if (__SUNPRO_C >= 0x420) 96 | # define TRIO_COMPILER_SUPPORTS_C94 97 | # endif 98 | # endif 99 | #endif 100 | 101 | #if defined(_XOPEN_SOURCE) 102 | # if defined(_XOPEN_SOURCE_EXTENDED) 103 | # define TRIO_COMPILER_SUPPORTS_UNIX95 104 | # endif 105 | # if (_XOPEN_VERSION >= 500) 106 | # define TRIO_COMPILER_SUPPORTS_UNIX98 107 | # endif 108 | # if (_XOPEN_VERSION >= 600) 109 | # define TRIO_COMPILER_SUPPORTS_UNIX01 110 | # endif 111 | #endif 112 | 113 | /************************************************************************* 114 | * Generic defines 115 | */ 116 | 117 | #if !defined(TRIO_PUBLIC) 118 | # define TRIO_PUBLIC 119 | #endif 120 | #if !defined(TRIO_PRIVATE) 121 | # define TRIO_PRIVATE static 122 | #endif 123 | 124 | #if !(defined(TRIO_COMPILER_SUPPORTS_C89) || defined(__cplusplus)) 125 | # define TRIO_COMPILER_ANCIENT 126 | #endif 127 | 128 | #if defined(TRIO_COMPILER_ANCIENT) 129 | # define TRIO_CONST 130 | # define TRIO_VOLATILE 131 | # define TRIO_SIGNED 132 | typedef double trio_long_double_t; 133 | typedef char * trio_pointer_t; 134 | # define TRIO_SUFFIX_LONG(x) x 135 | # define TRIO_PROTO(x) () 136 | # define TRIO_NOARGS 137 | # define TRIO_ARGS1(list,a1) list a1; 138 | # define TRIO_ARGS2(list,a1,a2) list a1; a2; 139 | # define TRIO_ARGS3(list,a1,a2,a3) list a1; a2; a3; 140 | # define TRIO_ARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4; 141 | # define TRIO_ARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5; 142 | # define TRIO_ARGS6(list,a1,a2,a3,a4,a5,a6) list a1; a2; a3; a4; a5; a6; 143 | # define TRIO_VARGS2(list,a1,a2) list a1; a2 144 | # define TRIO_VARGS3(list,a1,a2,a3) list a1; a2; a3 145 | # define TRIO_VARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4 146 | # define TRIO_VARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5 147 | # define TRIO_VA_DECL va_dcl 148 | # define TRIO_VA_START(x,y) va_start(x) 149 | # define TRIO_VA_END(x) va_end(x) 150 | #else /* ANSI C */ 151 | # define TRIO_CONST const 152 | # define TRIO_VOLATILE volatile 153 | # define TRIO_SIGNED signed 154 | typedef long double trio_long_double_t; 155 | typedef void * trio_pointer_t; 156 | # define TRIO_SUFFIX_LONG(x) x ## L 157 | # define TRIO_PROTO(x) x 158 | # define TRIO_NOARGS void 159 | # define TRIO_ARGS1(list,a1) (a1) 160 | # define TRIO_ARGS2(list,a1,a2) (a1,a2) 161 | # define TRIO_ARGS3(list,a1,a2,a3) (a1,a2,a3) 162 | # define TRIO_ARGS4(list,a1,a2,a3,a4) (a1,a2,a3,a4) 163 | # define TRIO_ARGS5(list,a1,a2,a3,a4,a5) (a1,a2,a3,a4,a5) 164 | # define TRIO_ARGS6(list,a1,a2,a3,a4,a5,a6) (a1,a2,a3,a4,a5,a6) 165 | # define TRIO_VARGS2 TRIO_ARGS2 166 | # define TRIO_VARGS3 TRIO_ARGS3 167 | # define TRIO_VARGS4 TRIO_ARGS4 168 | # define TRIO_VARGS5 TRIO_ARGS5 169 | # define TRIO_VA_DECL ... 170 | # define TRIO_VA_START(x,y) va_start(x,y) 171 | # define TRIO_VA_END(x) va_end(x) 172 | #endif 173 | 174 | #if defined(TRIO_COMPILER_SUPPORTS_C99) || defined(__cplusplus) 175 | # define TRIO_INLINE inline 176 | #elif defined(TRIO_COMPILER_GCC) 177 | # define TRIO_INLINE __inline__ 178 | #elif defined(TRIO_COMPILER_MSVC) 179 | # define TRIO_INLINE _inline 180 | #elif defined(TRIO_COMPILER_BCB) 181 | # define TRIO_INLINE __inline 182 | #else 183 | # define TRIO_INLINE 184 | #endif 185 | 186 | /************************************************************************* 187 | * Workarounds 188 | */ 189 | 190 | #if defined(TRIO_PLATFORM_VMS) 191 | /* 192 | * Computations done with constants at compile time can trigger these 193 | * even when compiling with IEEE enabled. 194 | */ 195 | # pragma message disable (UNDERFLOW, FLOATOVERFL) 196 | 197 | # if (__CRTL_VER < 80000000) 198 | /* 199 | * Although the compiler supports C99 language constructs, the C 200 | * run-time library does not contain all C99 functions. 201 | * 202 | * This was the case for 70300022. Update the 80000000 value when 203 | * it has been accurately determined what version of the library 204 | * supports C99. 205 | */ 206 | # if defined(TRIO_COMPILER_SUPPORTS_C99) 207 | # undef TRIO_COMPILER_SUPPORTS_C99 208 | # endif 209 | # endif 210 | #endif 211 | 212 | /* 213 | * Not all preprocessors supports the LL token. 214 | */ 215 | #if defined(TRIO_COMPILER_BCB) 216 | #else 217 | # define TRIO_COMPILER_SUPPORTS_LL 218 | #endif 219 | 220 | #endif /* TRIO_TRIODEF_H */ 221 | -------------------------------------------------------------------------------- /libxslt/extensions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: interface for the extension support 3 | * Description: This provide the API needed for simple and module 4 | * extension support. 5 | * 6 | * Copy: See Copyright for the status of this software. 7 | * 8 | * Author: Daniel Veillard 9 | */ 10 | 11 | #ifndef __XML_XSLT_EXTENSION_H__ 12 | #define __XML_XSLT_EXTENSION_H__ 13 | 14 | #include 15 | #include "xsltexports.h" 16 | #include "xsltInternals.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * Extension Modules API. 24 | */ 25 | 26 | /** 27 | * xsltInitGlobals: 28 | * 29 | * Initialize the global variables for extensions 30 | * 31 | */ 32 | 33 | XSLTPUBFUN void XSLTCALL 34 | xsltInitGlobals (void); 35 | 36 | /** 37 | * xsltStyleExtInitFunction: 38 | * @ctxt: an XSLT stylesheet 39 | * @URI: the namespace URI for the extension 40 | * 41 | * A function called at initialization time of an XSLT extension module. 42 | * 43 | * Returns a pointer to the module specific data for this transformation. 44 | */ 45 | typedef void * (*xsltStyleExtInitFunction) (xsltStylesheetPtr style, 46 | const xmlChar *URI); 47 | 48 | /** 49 | * xsltStyleExtShutdownFunction: 50 | * @ctxt: an XSLT stylesheet 51 | * @URI: the namespace URI for the extension 52 | * @data: the data associated to this module 53 | * 54 | * A function called at shutdown time of an XSLT extension module. 55 | */ 56 | typedef void (*xsltStyleExtShutdownFunction) (xsltStylesheetPtr style, 57 | const xmlChar *URI, 58 | void *data); 59 | 60 | /** 61 | * xsltExtInitFunction: 62 | * @ctxt: an XSLT transformation context 63 | * @URI: the namespace URI for the extension 64 | * 65 | * A function called at initialization time of an XSLT extension module. 66 | * 67 | * Returns a pointer to the module specific data for this transformation. 68 | */ 69 | typedef void * (*xsltExtInitFunction) (xsltTransformContextPtr ctxt, 70 | const xmlChar *URI); 71 | 72 | /** 73 | * xsltExtShutdownFunction: 74 | * @ctxt: an XSLT transformation context 75 | * @URI: the namespace URI for the extension 76 | * @data: the data associated to this module 77 | * 78 | * A function called at shutdown time of an XSLT extension module. 79 | */ 80 | typedef void (*xsltExtShutdownFunction) (xsltTransformContextPtr ctxt, 81 | const xmlChar *URI, 82 | void *data); 83 | 84 | XSLTPUBFUN int XSLTCALL 85 | xsltRegisterExtModule (const xmlChar *URI, 86 | xsltExtInitFunction initFunc, 87 | xsltExtShutdownFunction shutdownFunc); 88 | XSLTPUBFUN int XSLTCALL 89 | xsltRegisterExtModuleFull 90 | (const xmlChar * URI, 91 | xsltExtInitFunction initFunc, 92 | xsltExtShutdownFunction shutdownFunc, 93 | xsltStyleExtInitFunction styleInitFunc, 94 | xsltStyleExtShutdownFunction styleShutdownFunc); 95 | 96 | XSLTPUBFUN int XSLTCALL 97 | xsltUnregisterExtModule (const xmlChar * URI); 98 | 99 | XSLTPUBFUN void * XSLTCALL 100 | xsltGetExtData (xsltTransformContextPtr ctxt, 101 | const xmlChar *URI); 102 | 103 | XSLTPUBFUN void * XSLTCALL 104 | xsltStyleGetExtData (xsltStylesheetPtr style, 105 | const xmlChar *URI); 106 | #ifdef XSLT_REFACTORED 107 | XSLTPUBFUN void * XSLTCALL 108 | xsltStyleStylesheetLevelGetExtData( 109 | xsltStylesheetPtr style, 110 | const xmlChar * URI); 111 | #endif 112 | XSLTPUBFUN void XSLTCALL 113 | xsltShutdownCtxtExts (xsltTransformContextPtr ctxt); 114 | 115 | XSLTPUBFUN void XSLTCALL 116 | xsltShutdownExts (xsltStylesheetPtr style); 117 | 118 | XSLTPUBFUN xsltTransformContextPtr XSLTCALL 119 | xsltXPathGetTransformContext 120 | (xmlXPathParserContextPtr ctxt); 121 | 122 | /* 123 | * extension functions 124 | */ 125 | XSLTPUBFUN int XSLTCALL 126 | xsltRegisterExtModuleFunction 127 | (const xmlChar *name, 128 | const xmlChar *URI, 129 | xmlXPathFunction function); 130 | XSLTPUBFUN xmlXPathFunction XSLTCALL 131 | xsltExtModuleFunctionLookup (const xmlChar *name, 132 | const xmlChar *URI); 133 | XSLTPUBFUN int XSLTCALL 134 | xsltUnregisterExtModuleFunction 135 | (const xmlChar *name, 136 | const xmlChar *URI); 137 | 138 | /* 139 | * extension elements 140 | */ 141 | typedef xsltElemPreCompPtr (*xsltPreComputeFunction) 142 | (xsltStylesheetPtr style, 143 | xmlNodePtr inst, 144 | xsltTransformFunction function); 145 | 146 | XSLTPUBFUN xsltElemPreCompPtr XSLTCALL 147 | xsltNewElemPreComp (xsltStylesheetPtr style, 148 | xmlNodePtr inst, 149 | xsltTransformFunction function); 150 | XSLTPUBFUN void XSLTCALL 151 | xsltInitElemPreComp (xsltElemPreCompPtr comp, 152 | xsltStylesheetPtr style, 153 | xmlNodePtr inst, 154 | xsltTransformFunction function, 155 | xsltElemPreCompDeallocator freeFunc); 156 | 157 | XSLTPUBFUN int XSLTCALL 158 | xsltRegisterExtModuleElement 159 | (const xmlChar *name, 160 | const xmlChar *URI, 161 | xsltPreComputeFunction precomp, 162 | xsltTransformFunction transform); 163 | XSLTPUBFUN xsltTransformFunction XSLTCALL 164 | xsltExtElementLookup (xsltTransformContextPtr ctxt, 165 | const xmlChar *name, 166 | const xmlChar *URI); 167 | XSLTPUBFUN xsltTransformFunction XSLTCALL 168 | xsltExtModuleElementLookup 169 | (const xmlChar *name, 170 | const xmlChar *URI); 171 | XSLTPUBFUN xsltPreComputeFunction XSLTCALL 172 | xsltExtModuleElementPreComputeLookup 173 | (const xmlChar *name, 174 | const xmlChar *URI); 175 | XSLTPUBFUN int XSLTCALL 176 | xsltUnregisterExtModuleElement 177 | (const xmlChar *name, 178 | const xmlChar *URI); 179 | 180 | /* 181 | * top-level elements 182 | */ 183 | typedef void (*xsltTopLevelFunction) (xsltStylesheetPtr style, 184 | xmlNodePtr inst); 185 | 186 | XSLTPUBFUN int XSLTCALL 187 | xsltRegisterExtModuleTopLevel 188 | (const xmlChar *name, 189 | const xmlChar *URI, 190 | xsltTopLevelFunction function); 191 | XSLTPUBFUN xsltTopLevelFunction XSLTCALL 192 | xsltExtModuleTopLevelLookup 193 | (const xmlChar *name, 194 | const xmlChar *URI); 195 | XSLTPUBFUN int XSLTCALL 196 | xsltUnregisterExtModuleTopLevel 197 | (const xmlChar *name, 198 | const xmlChar *URI); 199 | 200 | 201 | /* These 2 functions are deprecated for use within modules. */ 202 | XSLTPUBFUN int XSLTCALL 203 | xsltRegisterExtFunction (xsltTransformContextPtr ctxt, 204 | const xmlChar *name, 205 | const xmlChar *URI, 206 | xmlXPathFunction function); 207 | XSLTPUBFUN int XSLTCALL 208 | xsltRegisterExtElement (xsltTransformContextPtr ctxt, 209 | const xmlChar *name, 210 | const xmlChar *URI, 211 | xsltTransformFunction function); 212 | 213 | /* 214 | * Extension Prefix handling API. 215 | * Those are used by the XSLT (pre)processor. 216 | */ 217 | 218 | XSLTPUBFUN int XSLTCALL 219 | xsltRegisterExtPrefix (xsltStylesheetPtr style, 220 | const xmlChar *prefix, 221 | const xmlChar *URI); 222 | XSLTPUBFUN int XSLTCALL 223 | xsltCheckExtPrefix (xsltStylesheetPtr style, 224 | const xmlChar *URI); 225 | XSLTPUBFUN int XSLTCALL 226 | xsltCheckExtURI (xsltStylesheetPtr style, 227 | const xmlChar *URI); 228 | XSLTPUBFUN int XSLTCALL 229 | xsltInitCtxtExts (xsltTransformContextPtr ctxt); 230 | XSLTPUBFUN void XSLTCALL 231 | xsltFreeCtxtExts (xsltTransformContextPtr ctxt); 232 | XSLTPUBFUN void XSLTCALL 233 | xsltFreeExts (xsltStylesheetPtr style); 234 | 235 | XSLTPUBFUN xsltElemPreCompPtr XSLTCALL 236 | xsltPreComputeExtModuleElement 237 | (xsltStylesheetPtr style, 238 | xmlNodePtr inst); 239 | /* 240 | * Extension Infos access. 241 | * Used by exslt initialisation 242 | */ 243 | 244 | XSLTPUBFUN xmlHashTablePtr XSLTCALL 245 | xsltGetExtInfo (xsltStylesheetPtr style, 246 | const xmlChar *URI); 247 | 248 | /** 249 | * Test of the extension module API 250 | */ 251 | XSLTPUBFUN void XSLTCALL 252 | xsltRegisterTestModule (void); 253 | XSLTPUBFUN void XSLTCALL 254 | xsltDebugDumpExtensions (FILE * output); 255 | 256 | 257 | #ifdef __cplusplus 258 | } 259 | #endif 260 | 261 | #endif /* __XML_XSLT_EXTENSION_H__ */ 262 | 263 | -------------------------------------------------------------------------------- /libxslt/trio.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * $Id$ 4 | * 5 | * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 12 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 13 | * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND 14 | * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. 15 | * 16 | ************************************************************************* 17 | * 18 | * http://ctrio.sourceforge.net/ 19 | * 20 | ************************************************************************/ 21 | 22 | #ifndef TRIO_TRIO_H 23 | #define TRIO_TRIO_H 24 | 25 | #if !defined(WITHOUT_TRIO) 26 | 27 | /* 28 | * Use autoconf defines if present. Packages using trio must define 29 | * HAVE_CONFIG_H as a compiler option themselves. 30 | */ 31 | #if defined(HAVE_CONFIG_H) 32 | # include 33 | #endif 34 | 35 | #include "triodef.h" 36 | 37 | #include 38 | #include 39 | #if defined(TRIO_COMPILER_ANCIENT) 40 | # include 41 | #else 42 | # include 43 | #endif 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /* 50 | * Error codes. 51 | * 52 | * Remember to add a textual description to trio_strerror. 53 | */ 54 | enum { 55 | TRIO_EOF = 1, 56 | TRIO_EINVAL = 2, 57 | TRIO_ETOOMANY = 3, 58 | TRIO_EDBLREF = 4, 59 | TRIO_EGAP = 5, 60 | TRIO_ENOMEM = 6, 61 | TRIO_ERANGE = 7, 62 | TRIO_ERRNO = 8, 63 | TRIO_ECUSTOM = 9 64 | }; 65 | 66 | /* Error macros */ 67 | #define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF) 68 | #define TRIO_ERROR_POSITION(x) ((-(x)) >> 8) 69 | #define TRIO_ERROR_NAME(x) trio_strerror(x) 70 | 71 | typedef int (*trio_outstream_t) TRIO_PROTO((trio_pointer_t, int)); 72 | typedef int (*trio_instream_t) TRIO_PROTO((trio_pointer_t)); 73 | 74 | TRIO_CONST char *trio_strerror TRIO_PROTO((int)); 75 | 76 | /************************************************************************* 77 | * Print Functions 78 | */ 79 | 80 | int trio_printf TRIO_PROTO((TRIO_CONST char *format, ...)); 81 | int trio_vprintf TRIO_PROTO((TRIO_CONST char *format, va_list args)); 82 | int trio_printfv TRIO_PROTO((TRIO_CONST char *format, void **args)); 83 | 84 | int trio_fprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...)); 85 | int trio_vfprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args)); 86 | int trio_fprintfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args)); 87 | 88 | int trio_dprintf TRIO_PROTO((int fd, TRIO_CONST char *format, ...)); 89 | int trio_vdprintf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args)); 90 | int trio_dprintfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args)); 91 | 92 | int trio_cprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, 93 | TRIO_CONST char *format, ...)); 94 | int trio_vcprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, 95 | TRIO_CONST char *format, va_list args)); 96 | int trio_cprintfv TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, 97 | TRIO_CONST char *format, void **args)); 98 | 99 | int trio_sprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, ...)); 100 | int trio_vsprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, va_list args)); 101 | int trio_sprintfv TRIO_PROTO((char *buffer, TRIO_CONST char *format, void **args)); 102 | 103 | int trio_snprintf TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...)); 104 | int trio_vsnprintf TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, 105 | va_list args)); 106 | int trio_snprintfv TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, 107 | void **args)); 108 | 109 | int trio_snprintfcat TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...)); 110 | int trio_vsnprintfcat TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, 111 | va_list args)); 112 | 113 | char *trio_aprintf TRIO_PROTO((TRIO_CONST char *format, ...)); 114 | char *trio_vaprintf TRIO_PROTO((TRIO_CONST char *format, va_list args)); 115 | 116 | int trio_asprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, ...)); 117 | int trio_vasprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, va_list args)); 118 | 119 | /************************************************************************* 120 | * Scan Functions 121 | */ 122 | int trio_scanf TRIO_PROTO((TRIO_CONST char *format, ...)); 123 | int trio_vscanf TRIO_PROTO((TRIO_CONST char *format, va_list args)); 124 | int trio_scanfv TRIO_PROTO((TRIO_CONST char *format, void **args)); 125 | 126 | int trio_fscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...)); 127 | int trio_vfscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args)); 128 | int trio_fscanfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args)); 129 | 130 | int trio_dscanf TRIO_PROTO((int fd, TRIO_CONST char *format, ...)); 131 | int trio_vdscanf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args)); 132 | int trio_dscanfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args)); 133 | 134 | int trio_cscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, 135 | TRIO_CONST char *format, ...)); 136 | int trio_vcscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, 137 | TRIO_CONST char *format, va_list args)); 138 | int trio_cscanfv TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, 139 | TRIO_CONST char *format, void **args)); 140 | 141 | int trio_sscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, ...)); 142 | int trio_vsscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args)); 143 | int trio_sscanfv TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, void **args)); 144 | 145 | /************************************************************************* 146 | * Locale Functions 147 | */ 148 | void trio_locale_set_decimal_point TRIO_PROTO((char *decimalPoint)); 149 | void trio_locale_set_thousand_separator TRIO_PROTO((char *thousandSeparator)); 150 | void trio_locale_set_grouping TRIO_PROTO((char *grouping)); 151 | 152 | /************************************************************************* 153 | * Renaming 154 | */ 155 | #ifdef TRIO_REPLACE_STDIO 156 | /* Replace the functions */ 157 | #ifndef HAVE_PRINTF 158 | # define printf trio_printf 159 | #endif 160 | #ifndef HAVE_VPRINTF 161 | # define vprintf trio_vprintf 162 | #endif 163 | #ifndef HAVE_FPRINTF 164 | # define fprintf trio_fprintf 165 | #endif 166 | #ifndef HAVE_VFPRINTF 167 | # define vfprintf trio_vfprintf 168 | #endif 169 | #ifndef HAVE_SPRINTF 170 | # define sprintf trio_sprintf 171 | #endif 172 | #ifndef HAVE_VSPRINTF 173 | # define vsprintf trio_vsprintf 174 | #endif 175 | #ifndef HAVE_SNPRINTF 176 | # define snprintf trio_snprintf 177 | #endif 178 | #ifndef HAVE_VSNPRINTF 179 | # define vsnprintf trio_vsnprintf 180 | #endif 181 | #ifndef HAVE_SCANF 182 | # define scanf trio_scanf 183 | #endif 184 | #ifndef HAVE_VSCANF 185 | # define vscanf trio_vscanf 186 | #endif 187 | #ifndef HAVE_FSCANF 188 | # define fscanf trio_fscanf 189 | #endif 190 | #ifndef HAVE_VFSCANF 191 | # define vfscanf trio_vfscanf 192 | #endif 193 | #ifndef HAVE_SSCANF 194 | # define sscanf trio_sscanf 195 | #endif 196 | #ifndef HAVE_VSSCANF 197 | # define vsscanf trio_vsscanf 198 | #endif 199 | /* These aren't stdio functions, but we make them look similar */ 200 | #define dprintf trio_dprintf 201 | #define vdprintf trio_vdprintf 202 | #define aprintf trio_aprintf 203 | #define vaprintf trio_vaprintf 204 | #define asprintf trio_asprintf 205 | #define vasprintf trio_vasprintf 206 | #define dscanf trio_dscanf 207 | #define vdscanf trio_vdscanf 208 | #endif 209 | 210 | #ifdef __cplusplus 211 | } /* extern "C" */ 212 | #endif 213 | 214 | #endif /* WITHOUT_TRIO */ 215 | 216 | #endif /* TRIO_TRIO_H */ 217 | -------------------------------------------------------------------------------- /xsltproc/testThreads.c: -------------------------------------------------------------------------------- 1 | /** 2 | * testThreads.c: testing of heavilly multithreaded concurrent accesses 3 | * 4 | * See Copyright for the status of this software. 5 | * 6 | * daniel@veillard.com 7 | */ 8 | 9 | /* 10 | * TODO: extend it to allow giving the stylesheets/input as filenames on the 11 | * command line to test specifics, also add exslt 12 | */ 13 | 14 | #if defined(_WIN32) && !defined (__CYGWIN__) && (!__MINGW32__) 15 | #include 16 | #else 17 | #include "config.h" 18 | #endif 19 | #include "libexslt/exslt.h" 20 | #include 21 | #include 22 | 23 | #ifndef _REENTRANT 24 | #define _REENTRANT 25 | #endif 26 | #include 27 | 28 | #if defined(LIBXML_THREAD_ENABLED) && defined(HAVE_PTHREAD_H) 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #if !defined(_MSC_VER) 44 | #include 45 | #endif 46 | #include 47 | 48 | #define MAX_ARGC 20 49 | 50 | static pthread_t tid[MAX_ARGC]; 51 | 52 | #define EXT_NS BAD_CAST "http://foo.org" 53 | #define EXT_DATA "bar" 54 | 55 | const char *stylesheet = "\ 59 | \ 60 | Success \ 61 | \ 62 | \ 63 | "; 64 | 65 | int init = 0; 66 | 67 | const char *doc = "Failed"; 68 | const char *expect = "\nSuccess foo\n"; 69 | 70 | static void fooFunction(xmlXPathParserContextPtr ctxt, 71 | int nargs ATTRIBUTE_UNUSED) { 72 | xmlXPathReturnString(ctxt, xmlStrdup(BAD_CAST "foo")); 73 | } 74 | 75 | static 76 | void * registerFooExtensions(ATTRIBUTE_UNUSED xsltTransformContextPtr ctxt, 77 | ATTRIBUTE_UNUSED const xmlChar *URI) { 78 | xsltRegisterExtModuleFunction(BAD_CAST "foo", EXT_NS, fooFunction); 79 | return((void *)EXT_DATA); 80 | } 81 | 82 | static 83 | void shutdownFooExtensions(xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED, 84 | const xmlChar *URI, void *data) { 85 | const char *str = (const char *) data; 86 | if (!xmlStrEqual(URI, EXT_NS)) { 87 | fprintf(stderr, "Mismatch in extensions shutdown URI"); 88 | } 89 | if (!xmlStrEqual(BAD_CAST str, BAD_CAST EXT_DATA)) { 90 | fprintf(stderr, "Mismatch in extensions shutdown DATA"); 91 | } 92 | } 93 | 94 | static void registerFooModule(void) { 95 | xsltRegisterExtModule(EXT_NS, registerFooExtensions, shutdownFooExtensions); 96 | } 97 | 98 | static void * 99 | threadRoutine1(void *data) 100 | { 101 | xmlDocPtr input; 102 | xmlDocPtr style; 103 | xmlDocPtr res; 104 | xmlChar *result; 105 | int len; 106 | xsltStylesheetPtr cur; 107 | int id = (int) (size_t) data; 108 | 109 | input = xmlReadMemory(doc, strlen(doc), "doc.xml", NULL, 0); 110 | if (input == NULL) { 111 | fprintf(stderr, "Thread id %d failed to parse input\n", id); 112 | exit(1); 113 | } 114 | style = xmlReadMemory(stylesheet, strlen(stylesheet), "doc.xsl", NULL, 0); 115 | if (style == NULL) { 116 | fprintf(stderr, "Thread id %d failed to parse stylesheet\n", id); 117 | exit(1); 118 | } 119 | cur = xsltParseStylesheetDoc(style); 120 | if (cur == NULL) { 121 | fprintf(stderr, "Thread id %d failed to compile stylesheet\n", id); 122 | exit(1); 123 | } 124 | res = xsltApplyStylesheet(cur, input, NULL); 125 | if (res == NULL) { 126 | fprintf(stderr, "Thread id %d failed to apply stylesheet\n", id); 127 | exit(1); 128 | } 129 | if (xsltSaveResultToString(&result, &len, res, cur) < 0) { 130 | fprintf(stderr, "Thread id %d failed to output result\n", id); 131 | exit(1); 132 | } 133 | if (!xmlStrEqual(BAD_CAST expect, result)) { 134 | fprintf(stderr, "Thread id %d output not conform\n", id); 135 | exit(1); 136 | } 137 | xsltFreeStylesheet(cur); 138 | xmlFreeDoc(input); 139 | xmlFreeDoc(res); 140 | xmlFree(result); 141 | return(0); 142 | } 143 | 144 | static void * 145 | threadRoutine2(void *data) 146 | { 147 | xmlDocPtr input; 148 | xmlDocPtr res; 149 | xmlChar *result; 150 | int len; 151 | xsltStylesheetPtr cur = (xsltStylesheetPtr) data; 152 | 153 | if (cur == NULL) { 154 | fprintf(stderr, "Thread failed to get the stylesheet\n"); 155 | exit(1); 156 | } 157 | input = xmlReadMemory(doc, strlen(doc), "doc.xml", NULL, 0); 158 | if (input == NULL) { 159 | fprintf(stderr, "Thread failed to parse input\n"); 160 | exit(1); 161 | } 162 | res = xsltApplyStylesheet(cur, input, NULL); 163 | if (res == NULL) { 164 | fprintf(stderr, "Thread failed to apply stylesheet\n"); 165 | exit(1); 166 | } 167 | if (xsltSaveResultToString(&result, &len, res, cur) < 0) { 168 | fprintf(stderr, "Thread failed to output result\n"); 169 | exit(1); 170 | } 171 | if (!xmlStrEqual(BAD_CAST expect, result)) { 172 | fprintf(stderr, "Thread output not conform\n"); 173 | exit(1); 174 | } 175 | xmlFreeDoc(input); 176 | xmlFreeDoc(res); 177 | xmlFree(result); 178 | return(0); 179 | } 180 | int 181 | main(void) 182 | { 183 | unsigned int i, repeat; 184 | unsigned int num_threads = 8; 185 | void *results[MAX_ARGC]; 186 | int ret; 187 | 188 | xmlInitParser(); 189 | 190 | /* 191 | * Register the EXSLT extensions and the test module 192 | */ 193 | exsltRegisterAll(); 194 | xsltRegisterTestModule(); 195 | 196 | /* 197 | * Register our own extension module 198 | */ 199 | registerFooModule(); 200 | 201 | /* 202 | * First pass each thread has its own version of the stylesheet 203 | * each of them will initialize and shutdown the extension 204 | */ 205 | printf("Pass 1\n"); 206 | for (repeat = 0;repeat < 500;repeat++) { 207 | memset(results, 0, sizeof(*results)*num_threads); 208 | memset(tid, 0xff, sizeof(*tid)*num_threads); 209 | 210 | for (i = 0; i < num_threads; i++) { 211 | ret = pthread_create(&tid[i], NULL, threadRoutine1, 212 | (void *) (size_t) i); 213 | if (ret != 0) { 214 | perror("pthread_create"); 215 | exit(1); 216 | } 217 | } 218 | for (i = 0; i < num_threads; i++) { 219 | ret = pthread_join(tid[i], &results[i]); 220 | if (ret != 0) { 221 | perror("pthread_join"); 222 | exit(1); 223 | } 224 | } 225 | } 226 | 227 | /* 228 | * Second pass all threads share the same stylesheet instance 229 | * look for transformation clashes 230 | */ 231 | printf("Pass 2\n"); 232 | for (repeat = 0;repeat < 500;repeat++) { 233 | xmlDocPtr style; 234 | xsltStylesheetPtr cur; 235 | 236 | style = xmlReadMemory(stylesheet, strlen(stylesheet), "doc.xsl", 237 | NULL, 0); 238 | if (style == NULL) { 239 | fprintf(stderr, "Main failed to parse stylesheet\n"); 240 | exit(1); 241 | } 242 | cur = xsltParseStylesheetDoc(style); 243 | if (cur == NULL) { 244 | fprintf(stderr, "Main failed to compile stylesheet\n"); 245 | exit(1); 246 | } 247 | memset(results, 0, sizeof(*results)*num_threads); 248 | memset(tid, 0xff, sizeof(*tid)*num_threads); 249 | 250 | for (i = 0; i < num_threads; i++) { 251 | ret = pthread_create(&tid[i], NULL, threadRoutine2, (void *) cur); 252 | if (ret != 0) { 253 | perror("pthread_create"); 254 | exit(1); 255 | } 256 | } 257 | for (i = 0; i < num_threads; i++) { 258 | ret = pthread_join(tid[i], &results[i]); 259 | if (ret != 0) { 260 | perror("pthread_join"); 261 | exit(1); 262 | } 263 | } 264 | xsltFreeStylesheet(cur); 265 | } 266 | xsltCleanupGlobals(); 267 | xmlCleanupParser(); 268 | printf("Ok\n"); 269 | return (0); 270 | } 271 | #else /* !LIBXML_THREADS_ENABLED | !HAVE_PTHREAD_H */ 272 | int 273 | main(void) 274 | { 275 | fprintf(stderr, "libxml was not compiled with thread\n"); 276 | return (0); 277 | } 278 | #endif 279 | -------------------------------------------------------------------------------- /libexslt/sets.c: -------------------------------------------------------------------------------- 1 | #define IN_LIBEXSLT 2 | #include "libexslt/libexslt.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "exslt.h" 13 | 14 | /** 15 | * exsltSetsDifferenceFunction: 16 | * @ctxt: an XPath parser context 17 | * @nargs: the number of arguments 18 | * 19 | * Wraps #xmlXPathDifference for use by the XPath processor 20 | */ 21 | static void 22 | exsltSetsDifferenceFunction (xmlXPathParserContextPtr ctxt, int nargs) { 23 | xmlNodeSetPtr arg1, arg2, ret; 24 | 25 | if (nargs != 2) { 26 | xmlXPathSetArityError(ctxt); 27 | return; 28 | } 29 | 30 | arg2 = xmlXPathPopNodeSet(ctxt); 31 | if (xmlXPathCheckError(ctxt)) 32 | return; 33 | 34 | arg1 = xmlXPathPopNodeSet(ctxt); 35 | if (xmlXPathCheckError(ctxt)) { 36 | xmlXPathFreeNodeSet(arg2); 37 | return; 38 | } 39 | 40 | ret = xmlXPathDifference(arg1, arg2); 41 | 42 | if (ret != arg1) 43 | xmlXPathFreeNodeSet(arg1); 44 | xmlXPathFreeNodeSet(arg2); 45 | 46 | xmlXPathReturnNodeSet(ctxt, ret); 47 | } 48 | 49 | /** 50 | * exsltSetsIntersectionFunction: 51 | * @ctxt: an XPath parser context 52 | * @nargs: the number of arguments 53 | * 54 | * Wraps #xmlXPathIntersection for use by the XPath processor 55 | */ 56 | static void 57 | exsltSetsIntersectionFunction (xmlXPathParserContextPtr ctxt, int nargs) { 58 | xmlNodeSetPtr arg1, arg2, ret; 59 | 60 | if (nargs != 2) { 61 | xmlXPathSetArityError(ctxt); 62 | return; 63 | } 64 | 65 | arg2 = xmlXPathPopNodeSet(ctxt); 66 | if (xmlXPathCheckError(ctxt)) 67 | return; 68 | 69 | arg1 = xmlXPathPopNodeSet(ctxt); 70 | if (xmlXPathCheckError(ctxt)) { 71 | xmlXPathFreeNodeSet(arg2); 72 | return; 73 | } 74 | 75 | ret = xmlXPathIntersection(arg1, arg2); 76 | 77 | xmlXPathFreeNodeSet(arg1); 78 | xmlXPathFreeNodeSet(arg2); 79 | 80 | xmlXPathReturnNodeSet(ctxt, ret); 81 | } 82 | 83 | /** 84 | * exsltSetsDistinctFunction: 85 | * @ctxt: an XPath parser context 86 | * @nargs: the number of arguments 87 | * 88 | * Wraps #xmlXPathDistinct for use by the XPath processor 89 | */ 90 | static void 91 | exsltSetsDistinctFunction (xmlXPathParserContextPtr ctxt, int nargs) { 92 | xmlXPathObjectPtr obj; 93 | xmlNodeSetPtr ns, ret; 94 | int boolval = 0; 95 | void *user = NULL; 96 | 97 | if (nargs != 1) { 98 | xmlXPathSetArityError(ctxt); 99 | return; 100 | } 101 | 102 | if (ctxt->value != NULL) { 103 | boolval = ctxt->value->boolval; 104 | user = ctxt->value->user; 105 | ctxt->value->boolval = 0; 106 | ctxt->value->user = NULL; 107 | } 108 | ns = xmlXPathPopNodeSet(ctxt); 109 | if (xmlXPathCheckError(ctxt)) 110 | return; 111 | 112 | /* !!! must be sorted !!! */ 113 | ret = xmlXPathDistinctSorted(ns); 114 | 115 | if (ret != ns) 116 | xmlXPathFreeNodeSet(ns); 117 | 118 | obj = xmlXPathWrapNodeSet(ret); 119 | if (obj != NULL) { 120 | obj->user = user; 121 | obj->boolval = boolval; 122 | } 123 | valuePush(ctxt, obj); 124 | } 125 | 126 | /** 127 | * exsltSetsHasSameNodesFunction: 128 | * @ctxt: an XPath parser context 129 | * @nargs: the number of arguments 130 | * 131 | * Wraps #xmlXPathHasSameNodes for use by the XPath processor 132 | */ 133 | static void 134 | exsltSetsHasSameNodesFunction (xmlXPathParserContextPtr ctxt, 135 | int nargs) { 136 | xmlNodeSetPtr arg1, arg2; 137 | int ret; 138 | 139 | if (nargs != 2) { 140 | xmlXPathSetArityError(ctxt); 141 | return; 142 | } 143 | 144 | arg2 = xmlXPathPopNodeSet(ctxt); 145 | if (xmlXPathCheckError(ctxt)) 146 | return; 147 | 148 | arg1 = xmlXPathPopNodeSet(ctxt); 149 | if (xmlXPathCheckError(ctxt)) { 150 | xmlXPathFreeNodeSet(arg2); 151 | return; 152 | } 153 | 154 | ret = xmlXPathHasSameNodes(arg1, arg2); 155 | 156 | xmlXPathFreeNodeSet(arg1); 157 | xmlXPathFreeNodeSet(arg2); 158 | 159 | xmlXPathReturnBoolean(ctxt, ret); 160 | } 161 | 162 | /** 163 | * exsltSetsLeadingFunction: 164 | * @ctxt: an XPath parser context 165 | * @nargs: the number of arguments 166 | * 167 | * Wraps #xmlXPathLeading for use by the XPath processor 168 | */ 169 | static void 170 | exsltSetsLeadingFunction (xmlXPathParserContextPtr ctxt, int nargs) { 171 | xmlNodeSetPtr arg1, arg2, ret; 172 | 173 | if (nargs != 2) { 174 | xmlXPathSetArityError(ctxt); 175 | return; 176 | } 177 | 178 | arg2 = xmlXPathPopNodeSet(ctxt); 179 | if (xmlXPathCheckError(ctxt)) 180 | return; 181 | 182 | arg1 = xmlXPathPopNodeSet(ctxt); 183 | if (xmlXPathCheckError(ctxt)) { 184 | xmlXPathFreeNodeSet(arg2); 185 | return; 186 | } 187 | 188 | /* If the second node set is empty, then the first node set is 189 | * returned. 190 | */ 191 | if (xmlXPathNodeSetIsEmpty(arg2)) { 192 | xmlXPathReturnNodeSet(ctxt, arg1); 193 | 194 | xmlXPathFreeNodeSet(arg2); 195 | 196 | return; 197 | } 198 | /* !!! must be sorted */ 199 | ret = xmlXPathNodeLeadingSorted(arg1, xmlXPathNodeSetItem(arg2, 0)); 200 | 201 | xmlXPathFreeNodeSet(arg1); 202 | xmlXPathFreeNodeSet(arg2); 203 | 204 | xmlXPathReturnNodeSet(ctxt, ret); 205 | } 206 | 207 | /** 208 | * exsltSetsTrailingFunction: 209 | * @ctxt: an XPath parser context 210 | * @nargs: the number of arguments 211 | * 212 | * Wraps #xmlXPathTrailing for use by the XPath processor 213 | */ 214 | static void 215 | exsltSetsTrailingFunction (xmlXPathParserContextPtr ctxt, int nargs) { 216 | xmlNodeSetPtr arg1, arg2, ret; 217 | 218 | if (nargs != 2) { 219 | xmlXPathSetArityError(ctxt); 220 | return; 221 | } 222 | 223 | arg2 = xmlXPathPopNodeSet(ctxt); 224 | if (xmlXPathCheckError(ctxt)) 225 | return; 226 | 227 | arg1 = xmlXPathPopNodeSet(ctxt); 228 | if (xmlXPathCheckError(ctxt)) { 229 | xmlXPathFreeNodeSet(arg2); 230 | return; 231 | } 232 | 233 | /* If the second node set is empty, then the first node set is 234 | * returned. 235 | */ 236 | if (xmlXPathNodeSetIsEmpty(arg2)) { 237 | xmlXPathReturnNodeSet(ctxt, arg1); 238 | 239 | xmlXPathFreeNodeSet(arg2); 240 | 241 | return; 242 | } 243 | /* !!! mist be sorted */ 244 | ret = xmlXPathNodeTrailingSorted(arg1, xmlXPathNodeSetItem(arg2, 0)); 245 | 246 | xmlXPathFreeNodeSet(arg1); 247 | xmlXPathFreeNodeSet(arg2); 248 | 249 | xmlXPathReturnNodeSet(ctxt, ret); 250 | } 251 | 252 | /** 253 | * exsltSetsRegister: 254 | * 255 | * Registers the EXSLT - Sets module 256 | */ 257 | 258 | void 259 | exsltSetsRegister (void) { 260 | xsltRegisterExtModuleFunction ((const xmlChar *) "difference", 261 | EXSLT_SETS_NAMESPACE, 262 | exsltSetsDifferenceFunction); 263 | xsltRegisterExtModuleFunction ((const xmlChar *) "intersection", 264 | EXSLT_SETS_NAMESPACE, 265 | exsltSetsIntersectionFunction); 266 | xsltRegisterExtModuleFunction ((const xmlChar *) "distinct", 267 | EXSLT_SETS_NAMESPACE, 268 | exsltSetsDistinctFunction); 269 | xsltRegisterExtModuleFunction ((const xmlChar *) "has-same-node", 270 | EXSLT_SETS_NAMESPACE, 271 | exsltSetsHasSameNodesFunction); 272 | xsltRegisterExtModuleFunction ((const xmlChar *) "leading", 273 | EXSLT_SETS_NAMESPACE, 274 | exsltSetsLeadingFunction); 275 | xsltRegisterExtModuleFunction ((const xmlChar *) "trailing", 276 | EXSLT_SETS_NAMESPACE, 277 | exsltSetsTrailingFunction); 278 | } 279 | 280 | /** 281 | * exsltSetsXpathCtxtRegister: 282 | * 283 | * Registers the EXSLT - Sets module for use outside XSLT 284 | */ 285 | int 286 | exsltSetsXpathCtxtRegister (xmlXPathContextPtr ctxt, const xmlChar *prefix) 287 | { 288 | if (ctxt 289 | && prefix 290 | && !xmlXPathRegisterNs(ctxt, 291 | prefix, 292 | (const xmlChar *) EXSLT_SETS_NAMESPACE) 293 | && !xmlXPathRegisterFuncNS(ctxt, 294 | (const xmlChar *) "difference", 295 | (const xmlChar *) EXSLT_SETS_NAMESPACE, 296 | exsltSetsDifferenceFunction) 297 | && !xmlXPathRegisterFuncNS(ctxt, 298 | (const xmlChar *) "intersection", 299 | (const xmlChar *) EXSLT_SETS_NAMESPACE, 300 | exsltSetsIntersectionFunction) 301 | && !xmlXPathRegisterFuncNS(ctxt, 302 | (const xmlChar *) "distinct", 303 | (const xmlChar *) EXSLT_SETS_NAMESPACE, 304 | exsltSetsDistinctFunction) 305 | && !xmlXPathRegisterFuncNS(ctxt, 306 | (const xmlChar *) "has-same-node", 307 | (const xmlChar *) EXSLT_SETS_NAMESPACE, 308 | exsltSetsHasSameNodesFunction) 309 | && !xmlXPathRegisterFuncNS(ctxt, 310 | (const xmlChar *) "leading", 311 | (const xmlChar *) EXSLT_SETS_NAMESPACE, 312 | exsltSetsLeadingFunction) 313 | && !xmlXPathRegisterFuncNS(ctxt, 314 | (const xmlChar *) "trailing", 315 | (const xmlChar *) EXSLT_SETS_NAMESPACE, 316 | exsltSetsTrailingFunction)) { 317 | return 0; 318 | } 319 | return -1; 320 | } 321 | -------------------------------------------------------------------------------- /libxslt/xsltutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Summary: set of utilities for the XSLT engine 3 | * Description: interfaces for the utilities module of the XSLT engine. 4 | * things like message handling, profiling, and other 5 | * generally useful routines. 6 | * 7 | * Copy: See Copyright for the status of this software. 8 | * 9 | * Author: Daniel Veillard 10 | */ 11 | 12 | #ifndef __XML_XSLTUTILS_H__ 13 | #define __XML_XSLTUTILS_H__ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "xsltexports.h" 20 | #include "xsltInternals.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * XSLT_TODO: 28 | * 29 | * Macro to flag unimplemented blocks. 30 | */ 31 | #define XSLT_TODO \ 32 | xsltGenericError(xsltGenericErrorContext, \ 33 | "Unimplemented block at %s:%d\n", \ 34 | __FILE__, __LINE__); 35 | 36 | /** 37 | * XSLT_STRANGE: 38 | * 39 | * Macro to flag that a problem was detected internally. 40 | */ 41 | #define XSLT_STRANGE \ 42 | xsltGenericError(xsltGenericErrorContext, \ 43 | "Internal error at %s:%d\n", \ 44 | __FILE__, __LINE__); 45 | 46 | /** 47 | * IS_XSLT_ELEM: 48 | * 49 | * Checks that the element pertains to XSLT namespace. 50 | */ 51 | #define IS_XSLT_ELEM(n) \ 52 | (((n) != NULL) && ((n)->type == XML_ELEMENT_NODE) && \ 53 | ((n)->ns != NULL) && (xmlStrEqual((n)->ns->href, XSLT_NAMESPACE))) 54 | 55 | /** 56 | * IS_XSLT_NAME: 57 | * 58 | * Checks the value of an element in XSLT namespace. 59 | */ 60 | #define IS_XSLT_NAME(n, val) \ 61 | (xmlStrEqual((n)->name, (const xmlChar *) (val))) 62 | 63 | /** 64 | * IS_XSLT_REAL_NODE: 65 | * 66 | * Check that a node is a 'real' one: document, element, text or attribute. 67 | */ 68 | #define IS_XSLT_REAL_NODE(n) \ 69 | (((n) != NULL) && \ 70 | (((n)->type == XML_ELEMENT_NODE) || \ 71 | ((n)->type == XML_TEXT_NODE) || \ 72 | ((n)->type == XML_CDATA_SECTION_NODE) || \ 73 | ((n)->type == XML_ATTRIBUTE_NODE) || \ 74 | ((n)->type == XML_DOCUMENT_NODE) || \ 75 | ((n)->type == XML_HTML_DOCUMENT_NODE) || \ 76 | ((n)->type == XML_COMMENT_NODE) || \ 77 | ((n)->type == XML_PI_NODE))) 78 | 79 | /* 80 | * Our own version of namespaced attributes lookup. 81 | */ 82 | XSLTPUBFUN xmlChar * XSLTCALL 83 | xsltGetNsProp (xmlNodePtr node, 84 | const xmlChar *name, 85 | const xmlChar *nameSpace); 86 | XSLTPUBFUN const xmlChar * XSLTCALL 87 | xsltGetCNsProp (xsltStylesheetPtr style, 88 | xmlNodePtr node, 89 | const xmlChar *name, 90 | const xmlChar *nameSpace); 91 | XSLTPUBFUN int XSLTCALL 92 | xsltGetUTF8Char (const unsigned char *utf, 93 | int *len); 94 | #ifdef IN_LIBXSLT 95 | /** DOC_DISABLE */ 96 | XSLTPUBFUN int XSLTCALL 97 | xsltGetUTF8CharZ (const unsigned char *utf, 98 | int *len); 99 | /** DOC_ENABLE */ 100 | #endif 101 | 102 | /* 103 | * XSLT Debug Tracing Tracing Types 104 | */ 105 | typedef enum { 106 | XSLT_TRACE_ALL = -1, 107 | XSLT_TRACE_NONE = 0, 108 | XSLT_TRACE_COPY_TEXT = 1<<0, 109 | XSLT_TRACE_PROCESS_NODE = 1<<1, 110 | XSLT_TRACE_APPLY_TEMPLATE = 1<<2, 111 | XSLT_TRACE_COPY = 1<<3, 112 | XSLT_TRACE_COMMENT = 1<<4, 113 | XSLT_TRACE_PI = 1<<5, 114 | XSLT_TRACE_COPY_OF = 1<<6, 115 | XSLT_TRACE_VALUE_OF = 1<<7, 116 | XSLT_TRACE_CALL_TEMPLATE = 1<<8, 117 | XSLT_TRACE_APPLY_TEMPLATES = 1<<9, 118 | XSLT_TRACE_CHOOSE = 1<<10, 119 | XSLT_TRACE_IF = 1<<11, 120 | XSLT_TRACE_FOR_EACH = 1<<12, 121 | XSLT_TRACE_STRIP_SPACES = 1<<13, 122 | XSLT_TRACE_TEMPLATES = 1<<14, 123 | XSLT_TRACE_KEYS = 1<<15, 124 | XSLT_TRACE_VARIABLES = 1<<16 125 | } xsltDebugTraceCodes; 126 | 127 | /** 128 | * XSLT_TRACE: 129 | * 130 | * Control the type of xsl debugtrace messages emitted. 131 | */ 132 | #define XSLT_TRACE(ctxt,code,call) \ 133 | if (ctxt->traceCode && (*(ctxt->traceCode) & code)) \ 134 | call 135 | 136 | XSLTPUBFUN void XSLTCALL 137 | xsltDebugSetDefaultTrace(xsltDebugTraceCodes val); 138 | XSLTPUBFUN xsltDebugTraceCodes XSLTCALL 139 | xsltDebugGetDefaultTrace(void); 140 | 141 | /* 142 | * XSLT specific error and debug reporting functions. 143 | */ 144 | XSLTPUBVAR xmlGenericErrorFunc xsltGenericError; 145 | XSLTPUBVAR void *xsltGenericErrorContext; 146 | XSLTPUBVAR xmlGenericErrorFunc xsltGenericDebug; 147 | XSLTPUBVAR void *xsltGenericDebugContext; 148 | 149 | XSLTPUBFUN void XSLTCALL 150 | xsltPrintErrorContext (xsltTransformContextPtr ctxt, 151 | xsltStylesheetPtr style, 152 | xmlNodePtr node); 153 | XSLTPUBFUN void XSLTCALL 154 | xsltMessage (xsltTransformContextPtr ctxt, 155 | xmlNodePtr node, 156 | xmlNodePtr inst); 157 | XSLTPUBFUN void XSLTCALL 158 | xsltSetGenericErrorFunc (void *ctx, 159 | xmlGenericErrorFunc handler); 160 | XSLTPUBFUN void XSLTCALL 161 | xsltSetGenericDebugFunc (void *ctx, 162 | xmlGenericErrorFunc handler); 163 | XSLTPUBFUN void XSLTCALL 164 | xsltSetTransformErrorFunc (xsltTransformContextPtr ctxt, 165 | void *ctx, 166 | xmlGenericErrorFunc handler); 167 | XSLTPUBFUN void XSLTCALL 168 | xsltTransformError (xsltTransformContextPtr ctxt, 169 | xsltStylesheetPtr style, 170 | xmlNodePtr node, 171 | const char *msg, 172 | ...) LIBXSLT_ATTR_FORMAT(4,5); 173 | 174 | XSLTPUBFUN int XSLTCALL 175 | xsltSetCtxtParseOptions (xsltTransformContextPtr ctxt, 176 | int options); 177 | /* 178 | * Sorting. 179 | */ 180 | 181 | XSLTPUBFUN void XSLTCALL 182 | xsltDocumentSortFunction (xmlNodeSetPtr list); 183 | XSLTPUBFUN void XSLTCALL 184 | xsltSetSortFunc (xsltSortFunc handler); 185 | XSLTPUBFUN void XSLTCALL 186 | xsltSetCtxtSortFunc (xsltTransformContextPtr ctxt, 187 | xsltSortFunc handler); 188 | XSLTPUBFUN void XSLTCALL 189 | xsltSetCtxtLocaleHandlers (xsltTransformContextPtr ctxt, 190 | xsltNewLocaleFunc newLocale, 191 | xsltFreeLocaleFunc freeLocale, 192 | xsltGenSortKeyFunc genSortKey); 193 | XSLTPUBFUN void XSLTCALL 194 | xsltDefaultSortFunction (xsltTransformContextPtr ctxt, 195 | xmlNodePtr *sorts, 196 | int nbsorts); 197 | XSLTPUBFUN void XSLTCALL 198 | xsltDoSortFunction (xsltTransformContextPtr ctxt, 199 | xmlNodePtr * sorts, 200 | int nbsorts); 201 | XSLTPUBFUN xmlXPathObjectPtr * XSLTCALL 202 | xsltComputeSortResult (xsltTransformContextPtr ctxt, 203 | xmlNodePtr sort); 204 | 205 | /* 206 | * QNames handling. 207 | */ 208 | 209 | XSLTPUBFUN const xmlChar * XSLTCALL 210 | xsltSplitQName (xmlDictPtr dict, 211 | const xmlChar *name, 212 | const xmlChar **prefix); 213 | XSLTPUBFUN const xmlChar * XSLTCALL 214 | xsltGetQNameURI (xmlNodePtr node, 215 | xmlChar **name); 216 | 217 | XSLTPUBFUN const xmlChar * XSLTCALL 218 | xsltGetQNameURI2 (xsltStylesheetPtr style, 219 | xmlNodePtr node, 220 | const xmlChar **name); 221 | 222 | /* 223 | * Output, reuse libxml I/O buffers. 224 | */ 225 | XSLTPUBFUN int XSLTCALL 226 | xsltSaveResultTo (xmlOutputBufferPtr buf, 227 | xmlDocPtr result, 228 | xsltStylesheetPtr style); 229 | XSLTPUBFUN int XSLTCALL 230 | xsltSaveResultToFilename (const char *URI, 231 | xmlDocPtr result, 232 | xsltStylesheetPtr style, 233 | int compression); 234 | XSLTPUBFUN int XSLTCALL 235 | xsltSaveResultToFile (FILE *file, 236 | xmlDocPtr result, 237 | xsltStylesheetPtr style); 238 | XSLTPUBFUN int XSLTCALL 239 | xsltSaveResultToFd (int fd, 240 | xmlDocPtr result, 241 | xsltStylesheetPtr style); 242 | XSLTPUBFUN int XSLTCALL 243 | xsltSaveResultToString (xmlChar **doc_txt_ptr, 244 | int * doc_txt_len, 245 | xmlDocPtr result, 246 | xsltStylesheetPtr style); 247 | 248 | /* 249 | * XPath interface 250 | */ 251 | XSLTPUBFUN xmlXPathCompExprPtr XSLTCALL 252 | xsltXPathCompile (xsltStylesheetPtr style, 253 | const xmlChar *str); 254 | XSLTPUBFUN xmlXPathCompExprPtr XSLTCALL 255 | xsltXPathCompileFlags (xsltStylesheetPtr style, 256 | const xmlChar *str, 257 | int flags); 258 | 259 | #ifdef IN_LIBXSLT 260 | /** DOC_DISABLE */ 261 | #define XSLT_SOURCE_NODE_MASK 15u 262 | #define XSLT_SOURCE_NODE_HAS_KEY 1u 263 | #define XSLT_SOURCE_NODE_HAS_ID 2u 264 | int 265 | xsltGetSourceNodeFlags(xmlNodePtr node); 266 | int 267 | xsltSetSourceNodeFlags(xsltTransformContextPtr ctxt, xmlNodePtr node, 268 | int flags); 269 | int 270 | xsltClearSourceNodeFlags(xmlNodePtr node, int flags); 271 | void ** 272 | xsltGetPSVIPtr(xmlNodePtr cur); 273 | /** DOC_ENABLE */ 274 | #endif 275 | 276 | #ifdef WITH_PROFILER 277 | /* 278 | * Profiling. 279 | */ 280 | XSLTPUBFUN void XSLTCALL 281 | xsltSaveProfiling (xsltTransformContextPtr ctxt, 282 | FILE *output); 283 | XSLTPUBFUN xmlDocPtr XSLTCALL 284 | xsltGetProfileInformation (xsltTransformContextPtr ctxt); 285 | 286 | XSLTPUBFUN long XSLTCALL 287 | xsltTimestamp (void); 288 | XSLTPUBFUN void XSLTCALL 289 | xsltCalibrateAdjust (long delta); 290 | #endif 291 | 292 | /** 293 | * XSLT_TIMESTAMP_TICS_PER_SEC: 294 | * 295 | * Sampling precision for profiling 296 | */ 297 | #define XSLT_TIMESTAMP_TICS_PER_SEC 100000l 298 | 299 | /* 300 | * Hooks for the debugger. 301 | */ 302 | 303 | typedef enum { 304 | XSLT_DEBUG_NONE = 0, /* no debugging allowed */ 305 | XSLT_DEBUG_INIT, 306 | XSLT_DEBUG_STEP, 307 | XSLT_DEBUG_STEPOUT, 308 | XSLT_DEBUG_NEXT, 309 | XSLT_DEBUG_STOP, 310 | XSLT_DEBUG_CONT, 311 | XSLT_DEBUG_RUN, 312 | XSLT_DEBUG_RUN_RESTART, 313 | XSLT_DEBUG_QUIT 314 | } xsltDebugStatusCodes; 315 | 316 | XSLTPUBVAR int xslDebugStatus; 317 | 318 | typedef void (*xsltHandleDebuggerCallback) (xmlNodePtr cur, xmlNodePtr node, 319 | xsltTemplatePtr templ, xsltTransformContextPtr ctxt); 320 | typedef int (*xsltAddCallCallback) (xsltTemplatePtr templ, xmlNodePtr source); 321 | typedef void (*xsltDropCallCallback) (void); 322 | 323 | XSLTPUBFUN int XSLTCALL 324 | xsltGetDebuggerStatus (void); 325 | #ifdef WITH_DEBUGGER 326 | XSLTPUBFUN void XSLTCALL 327 | xsltSetDebuggerStatus (int value); 328 | XSLTPUBFUN int XSLTCALL 329 | xsltSetDebuggerCallbacks (int no, void *block); 330 | XSLTPUBFUN int XSLTCALL 331 | xslAddCall (xsltTemplatePtr templ, 332 | xmlNodePtr source); 333 | XSLTPUBFUN void XSLTCALL 334 | xslDropCall (void); 335 | #endif 336 | 337 | #ifdef __cplusplus 338 | } 339 | #endif 340 | 341 | #endif /* __XML_XSLTUTILS_H__ */ 342 | 343 | 344 | -------------------------------------------------------------------------------- /libexslt/dynamic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dynamic.c: Implementation of the EXSLT -- Dynamic module 3 | * 4 | * References: 5 | * http://www.exslt.org/dyn/dyn.html 6 | * 7 | * See Copyright for the status of this software. 8 | * 9 | * Authors: 10 | * Mark Vakoc 11 | * Thomas Broyer 12 | * 13 | * TODO: 14 | * elements: 15 | * functions: 16 | * min 17 | * max 18 | * sum 19 | * map 20 | * closure 21 | */ 22 | 23 | #define IN_LIBEXSLT 24 | #include "libexslt/libexslt.h" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include "exslt.h" 35 | 36 | /** 37 | * exsltDynEvaluateFunction: 38 | * @ctxt: an XPath parser context 39 | * @nargs: the number of arguments 40 | * 41 | * Evaluates the string as an XPath expression and returns the result 42 | * value, which may be a boolean, number, string, node set, result tree 43 | * fragment or external object. 44 | */ 45 | 46 | static void 47 | exsltDynEvaluateFunction(xmlXPathParserContextPtr ctxt, int nargs) { 48 | xmlChar *str = NULL; 49 | xmlXPathObjectPtr ret = NULL; 50 | 51 | if (ctxt == NULL) 52 | return; 53 | if (nargs != 1) { 54 | xsltPrintErrorContext(xsltXPathGetTransformContext(ctxt), NULL, NULL); 55 | xsltGenericError(xsltGenericErrorContext, 56 | "dyn:evalute() : invalid number of args %d\n", nargs); 57 | ctxt->error = XPATH_INVALID_ARITY; 58 | return; 59 | } 60 | str = xmlXPathPopString(ctxt); 61 | /* return an empty node-set if an empty string is passed in */ 62 | if (!str||!xmlStrlen(str)) { 63 | if (str) xmlFree(str); 64 | valuePush(ctxt,xmlXPathNewNodeSet(NULL)); 65 | return; 66 | } 67 | #if LIBXML_VERSION >= 20911 68 | /* 69 | * Recursive evaluation can grow the call stack quickly. 70 | */ 71 | ctxt->context->depth += 5; 72 | #endif 73 | ret = xmlXPathEval(str,ctxt->context); 74 | #if LIBXML_VERSION >= 20911 75 | ctxt->context->depth -= 5; 76 | #endif 77 | if (ret) 78 | valuePush(ctxt,ret); 79 | else { 80 | xsltGenericError(xsltGenericErrorContext, 81 | "dyn:evaluate() : unable to evaluate expression '%s'\n",str); 82 | valuePush(ctxt,xmlXPathNewNodeSet(NULL)); 83 | } 84 | xmlFree(str); 85 | return; 86 | } 87 | 88 | /** 89 | * exsltDynMapFunction: 90 | * @ctxt: an XPath parser context 91 | * @nargs: the number of arguments 92 | * 93 | * Evaluates the string as an XPath expression and returns the result 94 | * value, which may be a boolean, number, string, node set, result tree 95 | * fragment or external object. 96 | */ 97 | 98 | static void 99 | exsltDynMapFunction(xmlXPathParserContextPtr ctxt, int nargs) 100 | { 101 | xmlChar *str = NULL; 102 | xmlNodeSetPtr nodeset = NULL; 103 | xsltTransformContextPtr tctxt; 104 | xmlXPathCompExprPtr comp = NULL; 105 | xmlXPathObjectPtr ret = NULL; 106 | xmlDocPtr oldDoc, container = NULL; 107 | xmlNodePtr oldNode; 108 | int oldContextSize; 109 | int oldProximityPosition; 110 | int i, j; 111 | 112 | 113 | if (nargs != 2) { 114 | xmlXPathSetArityError(ctxt); 115 | return; 116 | } 117 | str = xmlXPathPopString(ctxt); 118 | if (xmlXPathCheckError(ctxt)) 119 | goto cleanup; 120 | 121 | nodeset = xmlXPathPopNodeSet(ctxt); 122 | if (xmlXPathCheckError(ctxt)) 123 | goto cleanup; 124 | 125 | ret = xmlXPathNewNodeSet(NULL); 126 | if (ret == NULL) { 127 | xsltGenericError(xsltGenericErrorContext, 128 | "exsltDynMapFunction: ret == NULL\n"); 129 | goto cleanup; 130 | } 131 | 132 | tctxt = xsltXPathGetTransformContext(ctxt); 133 | if (tctxt == NULL) { 134 | xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, 135 | "dyn:map : internal error tctxt == NULL\n"); 136 | goto cleanup; 137 | } 138 | 139 | if (str == NULL || !xmlStrlen(str) || 140 | !(comp = xmlXPathCtxtCompile(tctxt->xpathCtxt, str))) 141 | goto cleanup; 142 | 143 | oldDoc = ctxt->context->doc; 144 | oldNode = ctxt->context->node; 145 | oldContextSize = ctxt->context->contextSize; 146 | oldProximityPosition = ctxt->context->proximityPosition; 147 | 148 | /** 149 | * since we really don't know we're going to be adding node(s) 150 | * down the road we create the RVT regardless 151 | */ 152 | container = xsltCreateRVT(tctxt); 153 | if (container == NULL) { 154 | xsltTransformError(tctxt, NULL, NULL, 155 | "dyn:map : internal error container == NULL\n"); 156 | goto cleanup; 157 | } 158 | xsltRegisterLocalRVT(tctxt, container); 159 | if (nodeset && nodeset->nodeNr > 0) { 160 | xmlXPathNodeSetSort(nodeset); 161 | ctxt->context->contextSize = nodeset->nodeNr; 162 | ctxt->context->proximityPosition = 0; 163 | for (i = 0; i < nodeset->nodeNr; i++) { 164 | xmlXPathObjectPtr subResult = NULL; 165 | xmlNodePtr cur = nodeset->nodeTab[i]; 166 | 167 | ctxt->context->proximityPosition++; 168 | ctxt->context->node = cur; 169 | 170 | if (cur->type == XML_NAMESPACE_DECL) { 171 | /* 172 | * The XPath module sets the owner element of a ns-node on 173 | * the ns->next field. 174 | */ 175 | cur = (xmlNodePtr) ((xmlNsPtr) cur)->next; 176 | if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE)) { 177 | xsltGenericError(xsltGenericErrorContext, 178 | "Internal error in exsltDynMapFunction: " 179 | "Cannot retrieve the doc of a namespace node.\n"); 180 | continue; 181 | } 182 | ctxt->context->doc = cur->doc; 183 | } else { 184 | ctxt->context->doc = cur->doc; 185 | } 186 | 187 | subResult = xmlXPathCompiledEval(comp, ctxt->context); 188 | if (subResult != NULL) { 189 | switch (subResult->type) { 190 | case XPATH_NODESET: 191 | if (subResult->nodesetval != NULL) 192 | for (j = 0; j < subResult->nodesetval->nodeNr; 193 | j++) 194 | xmlXPathNodeSetAdd(ret->nodesetval, 195 | subResult->nodesetval-> 196 | nodeTab[j]); 197 | break; 198 | case XPATH_BOOLEAN: 199 | if (container != NULL) { 200 | xmlNodePtr newChildNode = 201 | xmlNewTextChild((xmlNodePtr) container, NULL, 202 | BAD_CAST "boolean", 203 | BAD_CAST (subResult-> 204 | boolval ? "true" : "")); 205 | if (newChildNode != NULL) { 206 | newChildNode->ns = 207 | xmlNewNs(newChildNode, 208 | BAD_CAST 209 | "http://exslt.org/common", 210 | BAD_CAST "exsl"); 211 | xmlXPathNodeSetAddUnique(ret->nodesetval, 212 | newChildNode); 213 | } 214 | } 215 | break; 216 | case XPATH_NUMBER: 217 | if (container != NULL) { 218 | xmlChar *val = 219 | xmlXPathCastNumberToString(subResult-> 220 | floatval); 221 | xmlNodePtr newChildNode = 222 | xmlNewTextChild((xmlNodePtr) container, NULL, 223 | BAD_CAST "number", val); 224 | if (val != NULL) 225 | xmlFree(val); 226 | 227 | if (newChildNode != NULL) { 228 | newChildNode->ns = 229 | xmlNewNs(newChildNode, 230 | BAD_CAST 231 | "http://exslt.org/common", 232 | BAD_CAST "exsl"); 233 | xmlXPathNodeSetAddUnique(ret->nodesetval, 234 | newChildNode); 235 | } 236 | } 237 | break; 238 | case XPATH_STRING: 239 | if (container != NULL) { 240 | xmlNodePtr newChildNode = 241 | xmlNewTextChild((xmlNodePtr) container, NULL, 242 | BAD_CAST "string", 243 | subResult->stringval); 244 | if (newChildNode != NULL) { 245 | newChildNode->ns = 246 | xmlNewNs(newChildNode, 247 | BAD_CAST 248 | "http://exslt.org/common", 249 | BAD_CAST "exsl"); 250 | xmlXPathNodeSetAddUnique(ret->nodesetval, 251 | newChildNode); 252 | } 253 | } 254 | break; 255 | default: 256 | break; 257 | } 258 | xmlXPathFreeObject(subResult); 259 | } 260 | } 261 | } 262 | ctxt->context->doc = oldDoc; 263 | ctxt->context->node = oldNode; 264 | ctxt->context->contextSize = oldContextSize; 265 | ctxt->context->proximityPosition = oldProximityPosition; 266 | 267 | 268 | cleanup: 269 | /* restore the xpath context */ 270 | if (comp != NULL) 271 | xmlXPathFreeCompExpr(comp); 272 | if (nodeset != NULL) 273 | xmlXPathFreeNodeSet(nodeset); 274 | if (str != NULL) 275 | xmlFree(str); 276 | valuePush(ctxt, ret); 277 | return; 278 | } 279 | 280 | 281 | /** 282 | * exsltDynRegister: 283 | * 284 | * Registers the EXSLT - Dynamic module 285 | */ 286 | 287 | void 288 | exsltDynRegister (void) { 289 | xsltRegisterExtModuleFunction ((const xmlChar *) "evaluate", 290 | EXSLT_DYNAMIC_NAMESPACE, 291 | exsltDynEvaluateFunction); 292 | xsltRegisterExtModuleFunction ((const xmlChar *) "map", 293 | EXSLT_DYNAMIC_NAMESPACE, 294 | exsltDynMapFunction); 295 | 296 | } 297 | -------------------------------------------------------------------------------- /libexslt/saxon.c: -------------------------------------------------------------------------------- 1 | #define IN_LIBEXSLT 2 | #include "libexslt/libexslt.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "exslt.h" 15 | 16 | /** 17 | * exsltSaxonInit: 18 | * @ctxt: an XSLT transformation context 19 | * @URI: the namespace URI for the extension 20 | * 21 | * Initializes the SAXON module. 22 | * 23 | * Returns the data for this transformation 24 | */ 25 | static void * 26 | exsltSaxonInit (xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED, 27 | const xmlChar *URI ATTRIBUTE_UNUSED) { 28 | return xmlHashCreate(1); 29 | } 30 | 31 | static void 32 | exsltSaxonFreeCompExprEntry(void *payload, 33 | const xmlChar *name ATTRIBUTE_UNUSED) { 34 | xmlXPathFreeCompExpr((xmlXPathCompExprPtr) payload); 35 | } 36 | 37 | /** 38 | * exsltSaxonShutdown: 39 | * @ctxt: an XSLT transformation context 40 | * @URI: the namespace URI for the extension 41 | * @data: the module data to free up 42 | * 43 | * Shutdown the SAXON extension module 44 | */ 45 | static void 46 | exsltSaxonShutdown (xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED, 47 | const xmlChar *URI ATTRIBUTE_UNUSED, 48 | void *vdata) { 49 | xmlHashTablePtr data = (xmlHashTablePtr) vdata; 50 | xmlHashFree(data, exsltSaxonFreeCompExprEntry); 51 | } 52 | 53 | 54 | /** 55 | * exsltSaxonExpressionFunction: 56 | * @ctxt: an XPath parser context 57 | * @nargs: the number of arguments 58 | * 59 | * The supplied string must contain an XPath expression. The result of 60 | * the function is a stored expression, which may be supplied as an 61 | * argument to other extension functions such as saxon:eval(), 62 | * saxon:sum() and saxon:distinct(). The result of the expression will 63 | * usually depend on the current node. The expression may contain 64 | * references to variables that are in scope at the point where 65 | * saxon:expression() is called: these variables will be replaced in 66 | * the stored expression with the values they take at the time 67 | * saxon:expression() is called, not the values of the variables at 68 | * the time the stored expression is evaluated. Similarly, if the 69 | * expression contains namespace prefixes, these are interpreted in 70 | * terms of the namespace declarations in scope at the point where the 71 | * saxon:expression() function is called, not those in scope where the 72 | * stored expression is evaluated. 73 | * 74 | * TODO: current implementation doesn't conform to SAXON behaviour 75 | * regarding context and namespaces. 76 | */ 77 | static void 78 | exsltSaxonExpressionFunction (xmlXPathParserContextPtr ctxt, int nargs) { 79 | xmlChar *arg; 80 | xmlXPathCompExprPtr ret; 81 | xmlHashTablePtr hash; 82 | xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt); 83 | 84 | if (nargs != 1) { 85 | xmlXPathSetArityError(ctxt); 86 | return; 87 | } 88 | 89 | arg = xmlXPathPopString(ctxt); 90 | if (xmlXPathCheckError(ctxt) || (arg == NULL)) { 91 | xmlXPathSetTypeError(ctxt); 92 | return; 93 | } 94 | 95 | hash = (xmlHashTablePtr) xsltGetExtData(tctxt, 96 | ctxt->context->functionURI); 97 | 98 | ret = xmlHashLookup(hash, arg); 99 | 100 | if (ret == NULL) { 101 | ret = xmlXPathCtxtCompile(tctxt->xpathCtxt, arg); 102 | if (ret == NULL) { 103 | xmlFree(arg); 104 | xmlXPathSetError(ctxt, XPATH_EXPR_ERROR); 105 | return; 106 | } 107 | if (xmlHashAddEntry(hash, arg, (void *) ret) < 0) { 108 | xmlXPathFreeCompExpr(ret); 109 | xmlFree(arg); 110 | xmlXPathSetError(ctxt, XPATH_MEMORY_ERROR); 111 | return; 112 | } 113 | } 114 | 115 | xmlFree(arg); 116 | 117 | xmlXPathReturnExternal(ctxt, ret); 118 | } 119 | 120 | /** 121 | * exsltSaxonEvalFunction: 122 | * @ctxt: an XPath parser context 123 | * @nargs: number of arguments 124 | * 125 | * Implements de SAXON eval() function: 126 | * object saxon:eval (saxon:stored-expression) 127 | * Returns the result of evaluating the supplied stored expression. 128 | * A stored expression may be obtained as the result of calling 129 | * the saxon:expression() function. 130 | * The stored expression is evaluated in the current context, that 131 | * is, the context node is the current node, and the context position 132 | * and context size are the same as the result of calling position() 133 | * or last() respectively. 134 | */ 135 | static void 136 | exsltSaxonEvalFunction (xmlXPathParserContextPtr ctxt, int nargs) { 137 | xmlXPathCompExprPtr expr; 138 | xmlXPathObjectPtr ret; 139 | 140 | if (nargs != 1) { 141 | xmlXPathSetArityError(ctxt); 142 | return; 143 | } 144 | 145 | if (!xmlXPathStackIsExternal(ctxt)) { 146 | xmlXPathSetTypeError(ctxt); 147 | return; 148 | } 149 | 150 | expr = (xmlXPathCompExprPtr) xmlXPathPopExternal(ctxt); 151 | 152 | ret = xmlXPathCompiledEval(expr, ctxt->context); 153 | if (ret == NULL) { 154 | xmlXPathSetError(ctxt, XPATH_EXPR_ERROR); 155 | return; 156 | } 157 | 158 | valuePush(ctxt, ret); 159 | } 160 | 161 | /** 162 | * exsltSaxonEvaluateFunction: 163 | * @ctxt: an XPath parser context 164 | * @nargs: number of arguments 165 | * 166 | * Implements the SAXON evaluate() function 167 | * object saxon:evaluate (string) 168 | * The supplied string must contain an XPath expression. The result of 169 | * the function is the result of evaluating the XPath expression. This 170 | * is useful where an expression needs to be constructed at run-time or 171 | * passed to the stylesheet as a parameter, for example where the sort 172 | * key is determined dynamically. The context for the expression (e.g. 173 | * which variables and namespaces are available) is exactly the same as 174 | * if the expression were written explicitly at this point in the 175 | * stylesheet. The function saxon:evaluate(string) is shorthand for 176 | * saxon:eval(saxon:expression(string)). 177 | */ 178 | static void 179 | exsltSaxonEvaluateFunction (xmlXPathParserContextPtr ctxt, int nargs) { 180 | if (nargs != 1) { 181 | xmlXPathSetArityError(ctxt); 182 | return; 183 | } 184 | 185 | exsltSaxonExpressionFunction(ctxt, 1); 186 | exsltSaxonEvalFunction(ctxt, 1); 187 | } 188 | 189 | /** 190 | * exsltSaxonSystemIdFunction: 191 | * @ctxt: an XPath parser context 192 | * @nargs: number of arguments 193 | * 194 | * Implements the SAXON systemId() function 195 | * string saxon:systemId () 196 | * This function returns the system ID of the document being styled. 197 | */ 198 | static void 199 | exsltSaxonSystemIdFunction(xmlXPathParserContextPtr ctxt, int nargs) 200 | { 201 | if (ctxt == NULL) 202 | return; 203 | if (nargs != 0) { 204 | xmlXPathSetArityError(ctxt); 205 | return; 206 | } 207 | 208 | if ((ctxt->context) && (ctxt->context->doc) && 209 | (ctxt->context->doc->URL)) 210 | valuePush(ctxt, xmlXPathNewString(ctxt->context->doc->URL)); 211 | else 212 | valuePush(ctxt, xmlXPathNewString(BAD_CAST "")); 213 | } 214 | 215 | /** 216 | * exsltSaxonLineNumberFunction: 217 | * @ctxt: an XPath parser context 218 | * @nargs: number of arguments 219 | * 220 | * Implements the SAXON line-number() function 221 | * integer saxon:line-number() 222 | * 223 | * This returns the line number of the context node in the source document 224 | * within the entity that contains it. There are no arguments. If line numbers 225 | * are not maintained for the current document, the function returns -1. (To 226 | * ensure that line numbers are maintained, use the -l option on the command 227 | * line) 228 | * 229 | * The extension has been extended to have the following form: 230 | * integer saxon:line-number([node-set-1]) 231 | * If a node-set is given, this extension will return the line number of the 232 | * node in the argument node-set that is first in document order. 233 | */ 234 | static void 235 | exsltSaxonLineNumberFunction(xmlXPathParserContextPtr ctxt, int nargs) { 236 | xmlNodePtr cur = NULL; 237 | xmlXPathObjectPtr obj = NULL; 238 | long lineNo = -1; 239 | 240 | if (nargs == 0) { 241 | cur = ctxt->context->node; 242 | } else if (nargs == 1) { 243 | xmlNodeSetPtr nodelist; 244 | int i; 245 | 246 | if ((ctxt->value == NULL) || (ctxt->value->type != XPATH_NODESET)) { 247 | xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, 248 | "saxon:line-number() : invalid arg expecting a node-set\n"); 249 | ctxt->error = XPATH_INVALID_TYPE; 250 | return; 251 | } 252 | 253 | obj = valuePop(ctxt); 254 | nodelist = obj->nodesetval; 255 | if ((nodelist != NULL) && (nodelist->nodeNr > 0)) { 256 | cur = nodelist->nodeTab[0]; 257 | for (i = 1;i < nodelist->nodeNr;i++) { 258 | int ret = xmlXPathCmpNodes(cur, nodelist->nodeTab[i]); 259 | if (ret == -1) 260 | cur = nodelist->nodeTab[i]; 261 | } 262 | } 263 | } else { 264 | xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, 265 | "saxon:line-number() : invalid number of args %d\n", 266 | nargs); 267 | ctxt->error = XPATH_INVALID_ARITY; 268 | return; 269 | } 270 | 271 | if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) { 272 | /* 273 | * The XPath module sets the owner element of a ns-node on 274 | * the ns->next field. 275 | */ 276 | cur = (xmlNodePtr) ((xmlNsPtr) cur)->next; 277 | if (cur == NULL || cur->type != XML_ELEMENT_NODE) { 278 | xsltGenericError(xsltGenericErrorContext, 279 | "Internal error in exsltSaxonLineNumberFunction: " 280 | "Cannot retrieve the doc of a namespace node.\n"); 281 | cur = NULL; 282 | } 283 | } 284 | 285 | if (cur != NULL) 286 | lineNo = xmlGetLineNo(cur); 287 | 288 | valuePush(ctxt, xmlXPathNewFloat(lineNo)); 289 | 290 | xmlXPathFreeObject(obj); 291 | } 292 | 293 | /** 294 | * exsltSaxonRegister: 295 | * 296 | * Registers the SAXON extension module 297 | */ 298 | void 299 | exsltSaxonRegister (void) { 300 | xsltRegisterExtModule (SAXON_NAMESPACE, 301 | exsltSaxonInit, 302 | exsltSaxonShutdown); 303 | xsltRegisterExtModuleFunction((const xmlChar *) "expression", 304 | SAXON_NAMESPACE, 305 | exsltSaxonExpressionFunction); 306 | xsltRegisterExtModuleFunction((const xmlChar *) "eval", 307 | SAXON_NAMESPACE, 308 | exsltSaxonEvalFunction); 309 | xsltRegisterExtModuleFunction((const xmlChar *) "evaluate", 310 | SAXON_NAMESPACE, 311 | exsltSaxonEvaluateFunction); 312 | xsltRegisterExtModuleFunction ((const xmlChar *) "line-number", 313 | SAXON_NAMESPACE, 314 | exsltSaxonLineNumberFunction); 315 | xsltRegisterExtModuleFunction ((const xmlChar *) "systemId", 316 | SAXON_NAMESPACE, 317 | exsltSaxonSystemIdFunction); 318 | } 319 | -------------------------------------------------------------------------------- /libxslt/attrvt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * attrvt.c: Implementation of the XSL Transformation 1.0 engine 3 | * attribute value template handling part. 4 | * 5 | * References: 6 | * http://www.w3.org/TR/1999/REC-xslt-19991116 7 | * 8 | * Michael Kay "XSLT Programmer's Reference" pp 637-643 9 | * Writing Multiple Output Files 10 | * 11 | * See Copyright for the status of this software. 12 | * 13 | * daniel@veillard.com 14 | */ 15 | 16 | #define IN_LIBXSLT 17 | #include "libxslt.h" 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "xslt.h" 26 | #include "xsltutils.h" 27 | #include "xsltInternals.h" 28 | #include "templates.h" 29 | 30 | #ifdef WITH_XSLT_DEBUG 31 | #define WITH_XSLT_DEBUG_AVT 32 | #endif 33 | 34 | #define MAX_AVT_SEG 10 35 | 36 | typedef struct _xsltAttrVT xsltAttrVT; 37 | typedef xsltAttrVT *xsltAttrVTPtr; 38 | struct _xsltAttrVT { 39 | struct _xsltAttrVT *next; /* next xsltAttrVT */ 40 | int nb_seg; /* Number of segments */ 41 | int max_seg; /* max capacity before re-alloc needed */ 42 | int strstart; /* is the start a string */ 43 | /* 44 | * the namespaces in scope 45 | */ 46 | xmlNsPtr *nsList; 47 | int nsNr; 48 | /* 49 | * the content is an alternate of string and xmlXPathCompExprPtr 50 | */ 51 | #if __STDC_VERSION__ >= 199901L 52 | /* Using a C99 flexible array member avoids false positives under UBSan */ 53 | void *segments[]; 54 | #else 55 | void *segments[1]; 56 | #endif 57 | }; 58 | 59 | /** 60 | * xsltNewAttrVT: 61 | * @style: a XSLT process context 62 | * 63 | * Build a new xsltAttrVT structure 64 | * 65 | * Returns the structure or NULL in case of error 66 | */ 67 | static xsltAttrVTPtr 68 | xsltNewAttrVT(xsltStylesheetPtr style) { 69 | xsltAttrVTPtr cur; 70 | size_t size = sizeof(xsltAttrVT) + MAX_AVT_SEG * sizeof(void*); 71 | 72 | cur = (xsltAttrVTPtr) xmlMalloc(size); 73 | if (cur == NULL) { 74 | xsltTransformError(NULL, style, NULL, 75 | "xsltNewAttrVTPtr : malloc failed\n"); 76 | if (style != NULL) style->errors++; 77 | return(NULL); 78 | } 79 | memset(cur, 0, size); 80 | 81 | cur->nb_seg = 0; 82 | cur->max_seg = MAX_AVT_SEG; 83 | cur->strstart = 0; 84 | cur->next = style->attVTs; 85 | /* 86 | * Note: this pointer may be changed by a re-alloc within xsltCompileAttr, 87 | * so that code may change the stylesheet pointer also! 88 | */ 89 | style->attVTs = (xsltAttrVTPtr) cur; 90 | 91 | return(cur); 92 | } 93 | 94 | /** 95 | * xsltFreeAttrVT: 96 | * @avt: pointer to an xsltAttrVT structure 97 | * 98 | * Free up the memory associated to the attribute value template 99 | */ 100 | static void 101 | xsltFreeAttrVT(xsltAttrVTPtr avt) { 102 | int i; 103 | 104 | if (avt == NULL) return; 105 | 106 | if (avt->strstart == 1) { 107 | for (i = 0;i < avt->nb_seg; i += 2) 108 | if (avt->segments[i] != NULL) 109 | xmlFree((xmlChar *) avt->segments[i]); 110 | for (i = 1;i < avt->nb_seg; i += 2) 111 | xmlXPathFreeCompExpr((xmlXPathCompExprPtr) avt->segments[i]); 112 | } else { 113 | for (i = 0;i < avt->nb_seg; i += 2) 114 | xmlXPathFreeCompExpr((xmlXPathCompExprPtr) avt->segments[i]); 115 | for (i = 1;i < avt->nb_seg; i += 2) 116 | if (avt->segments[i] != NULL) 117 | xmlFree((xmlChar *) avt->segments[i]); 118 | } 119 | if (avt->nsList != NULL) 120 | xmlFree(avt->nsList); 121 | xmlFree(avt); 122 | } 123 | 124 | /** 125 | * xsltFreeAVTList: 126 | * @avt: pointer to an list of AVT structures 127 | * 128 | * Free up the memory associated to the attribute value templates 129 | */ 130 | void 131 | xsltFreeAVTList(void *avt) { 132 | xsltAttrVTPtr cur = (xsltAttrVTPtr) avt, next; 133 | 134 | while (cur != NULL) { 135 | next = cur->next; 136 | xsltFreeAttrVT(cur); 137 | cur = next; 138 | } 139 | } 140 | /** 141 | * xsltSetAttrVTsegment: 142 | * @ avt: pointer to an xsltAttrVT structure 143 | * @ val: the value to be set to the next available segment 144 | * 145 | * Within xsltCompileAttr there are several places where a value 146 | * needs to be added to the 'segments' array within the xsltAttrVT 147 | * structure, and at each place the allocated size may have to be 148 | * re-allocated. This routine takes care of that situation. 149 | * 150 | * Returns the avt pointer, which may have been changed by a re-alloc 151 | */ 152 | static xsltAttrVTPtr 153 | xsltSetAttrVTsegment(xsltAttrVTPtr avt, void *val) { 154 | if (avt->nb_seg >= avt->max_seg) { 155 | size_t size = sizeof(xsltAttrVT) + 156 | (avt->max_seg + MAX_AVT_SEG) * sizeof(void *); 157 | avt = (xsltAttrVTPtr) xmlRealloc(avt, size); 158 | if (avt == NULL) 159 | return NULL; 160 | memset(&avt->segments[avt->nb_seg], 0, MAX_AVT_SEG*sizeof(void *)); 161 | avt->max_seg += MAX_AVT_SEG; 162 | } 163 | avt->segments[avt->nb_seg++] = val; 164 | return avt; 165 | } 166 | 167 | /** 168 | * xsltCompileAttr: 169 | * @style: a XSLT process context 170 | * @attr: the attribute coming from the stylesheet. 171 | * 172 | * Precompile an attribute in a stylesheet, basically it checks if it is 173 | * an attribute value template, and if yes, establish some structures needed 174 | * to process it at transformation time. 175 | */ 176 | void 177 | xsltCompileAttr(xsltStylesheetPtr style, xmlAttrPtr attr) { 178 | const xmlChar *str; 179 | const xmlChar *cur; 180 | xmlChar *ret = NULL; 181 | xmlChar *expr = NULL; 182 | xmlXPathCompExprPtr comp = NULL; 183 | xsltAttrVTPtr avt, tmp; 184 | int i = 0, lastavt = 0; 185 | 186 | if ((style == NULL) || (attr == NULL) || (attr->children == NULL)) 187 | return; 188 | if ((attr->children->type != XML_TEXT_NODE) || 189 | (attr->children->next != NULL)) { 190 | xsltTransformError(NULL, style, attr->parent, 191 | "Attribute '%s': The content is expected to be a single text " 192 | "node when compiling an AVT.\n", attr->name); 193 | style->errors++; 194 | return; 195 | } 196 | str = attr->children->content; 197 | if ((xmlStrchr(str, '{') == NULL) && 198 | (xmlStrchr(str, '}') == NULL)) return; 199 | 200 | #ifdef WITH_XSLT_DEBUG_AVT 201 | xsltGenericDebug(xsltGenericDebugContext, 202 | "Found AVT %s: %s\n", attr->name, str); 203 | #endif 204 | if (attr->psvi != NULL) { 205 | #ifdef WITH_XSLT_DEBUG_AVT 206 | xsltGenericDebug(xsltGenericDebugContext, 207 | "AVT %s: already compiled\n", attr->name); 208 | #endif 209 | return; 210 | } 211 | /* 212 | * Create a new AVT object. 213 | */ 214 | avt = xsltNewAttrVT(style); 215 | if (avt == NULL) 216 | return; 217 | attr->psvi = avt; 218 | 219 | avt->nsList = xmlGetNsList(attr->doc, attr->parent); 220 | if (avt->nsList != NULL) { 221 | while (avt->nsList[i] != NULL) 222 | i++; 223 | } 224 | avt->nsNr = i; 225 | 226 | cur = str; 227 | while (*cur != 0) { 228 | if (*cur == '{') { 229 | if (*(cur+1) == '{') { /* escaped '{' */ 230 | cur++; 231 | ret = xmlStrncat(ret, str, cur - str); 232 | cur++; 233 | str = cur; 234 | continue; 235 | } 236 | if (*(cur+1) == '}') { /* skip empty AVT */ 237 | ret = xmlStrncat(ret, str, cur - str); 238 | cur += 2; 239 | str = cur; 240 | continue; 241 | } 242 | if ((ret != NULL) || (cur - str > 0)) { 243 | ret = xmlStrncat(ret, str, cur - str); 244 | str = cur; 245 | if (avt->nb_seg == 0) 246 | avt->strstart = 1; 247 | if ((tmp = xsltSetAttrVTsegment(avt, (void *) ret)) == NULL) 248 | goto error; 249 | avt = tmp; 250 | ret = NULL; 251 | lastavt = 0; 252 | } 253 | 254 | cur++; 255 | while ((*cur != 0) && (*cur != '}')) { 256 | /* Need to check for literal (bug539741) */ 257 | if ((*cur == '\'') || (*cur == '"')) { 258 | char delim = *(cur++); 259 | while ((*cur != 0) && (*cur != delim)) 260 | cur++; 261 | if (*cur != 0) 262 | cur++; /* skip the ending delimiter */ 263 | } else 264 | cur++; 265 | } 266 | if (*cur == 0) { 267 | xsltTransformError(NULL, style, attr->parent, 268 | "Attribute '%s': The AVT has an unmatched '{'.\n", 269 | attr->name); 270 | style->errors++; 271 | goto error; 272 | } 273 | str++; 274 | expr = xmlStrndup(str, cur - str); 275 | if (expr == NULL) { 276 | /* 277 | * TODO: What needs to be done here? 278 | */ 279 | XSLT_TODO 280 | goto error; 281 | } else { 282 | comp = xsltXPathCompile(style, expr); 283 | if (comp == NULL) { 284 | xsltTransformError(NULL, style, attr->parent, 285 | "Attribute '%s': Failed to compile the expression " 286 | "'%s' in the AVT.\n", attr->name, expr); 287 | style->errors++; 288 | goto error; 289 | } 290 | if (avt->nb_seg == 0) 291 | avt->strstart = 0; 292 | if (lastavt == 1) { 293 | if ((tmp = xsltSetAttrVTsegment(avt, NULL)) == NULL) { 294 | xsltTransformError(NULL, style, attr->parent, 295 | "out of memory\n"); 296 | goto error; 297 | } 298 | avt = tmp; 299 | } 300 | if ((tmp = xsltSetAttrVTsegment(avt, (void *) comp)) == NULL) { 301 | xsltTransformError(NULL, style, attr->parent, 302 | "out of memory\n"); 303 | goto error; 304 | } 305 | avt = tmp; 306 | lastavt = 1; 307 | xmlFree(expr); 308 | expr = NULL; 309 | comp = NULL; 310 | } 311 | cur++; 312 | str = cur; 313 | } else if (*cur == '}') { 314 | cur++; 315 | if (*cur == '}') { /* escaped '}' */ 316 | ret = xmlStrncat(ret, str, cur - str); 317 | cur++; 318 | str = cur; 319 | continue; 320 | } else { 321 | xsltTransformError(NULL, style, attr->parent, 322 | "Attribute '%s': The AVT has an unmatched '}'.\n", 323 | attr->name); 324 | goto error; 325 | } 326 | } else 327 | cur++; 328 | } 329 | if ((ret != NULL) || (cur - str > 0)) { 330 | ret = xmlStrncat(ret, str, cur - str); 331 | str = cur; 332 | if (avt->nb_seg == 0) 333 | avt->strstart = 1; 334 | if ((tmp = xsltSetAttrVTsegment(avt, (void *) ret)) == NULL) 335 | goto error; 336 | avt = tmp; 337 | ret = NULL; 338 | } 339 | 340 | error: 341 | if (avt == NULL) { 342 | xsltTransformError(NULL, style, attr->parent, 343 | "xsltCompileAttr: malloc problem\n"); 344 | } else { 345 | if (attr->psvi != avt) { /* may have changed from realloc */ 346 | attr->psvi = avt; 347 | /* 348 | * This is a "hack", but I can't see any clean method of 349 | * doing it. If a re-alloc has taken place, then the pointer 350 | * for this AVT may have changed. style->attVTs was set by 351 | * xsltNewAttrVT, so it needs to be re-set to the new value! 352 | */ 353 | style->attVTs = avt; 354 | } 355 | } 356 | if (ret != NULL) 357 | xmlFree(ret); 358 | if (expr != NULL) 359 | xmlFree(expr); 360 | if (comp != NULL) 361 | xmlXPathFreeCompExpr(comp); 362 | } 363 | 364 | 365 | /** 366 | * xsltEvalAVT: 367 | * @ctxt: the XSLT transformation context 368 | * @avt: the prevompiled attribute value template info 369 | * @node: the node hosting the attribute 370 | * 371 | * Process the given AVT, and return the new string value. 372 | * 373 | * Returns the computed string value or NULL, must be deallocated by the 374 | * caller. 375 | */ 376 | xmlChar * 377 | xsltEvalAVT(xsltTransformContextPtr ctxt, void *avt, xmlNodePtr node) { 378 | xmlChar *ret = NULL, *tmp; 379 | xmlXPathCompExprPtr comp; 380 | xsltAttrVTPtr cur = (xsltAttrVTPtr) avt; 381 | int i; 382 | int str; 383 | 384 | if ((ctxt == NULL) || (avt == NULL) || (node == NULL)) 385 | return(NULL); 386 | str = cur->strstart; 387 | for (i = 0;i < cur->nb_seg;i++) { 388 | if (str) { 389 | ret = xmlStrcat(ret, (const xmlChar *) cur->segments[i]); 390 | } else { 391 | comp = (xmlXPathCompExprPtr) cur->segments[i]; 392 | tmp = xsltEvalXPathStringNs(ctxt, comp, cur->nsNr, cur->nsList); 393 | if (tmp != NULL) { 394 | if (ret != NULL) { 395 | ret = xmlStrcat(ret, tmp); 396 | xmlFree(tmp); 397 | } else { 398 | ret = tmp; 399 | } 400 | } 401 | } 402 | str = !str; 403 | } 404 | return(ret); 405 | } 406 | -------------------------------------------------------------------------------- /libxslt/imports.c: -------------------------------------------------------------------------------- 1 | /* 2 | * imports.c: Implementation of the XSLT imports 3 | * 4 | * Reference: 5 | * http://www.w3.org/TR/1999/REC-xslt-19991116 6 | * 7 | * See Copyright for the status of this software. 8 | * 9 | * daniel@veillard.com 10 | */ 11 | 12 | #define IN_LIBXSLT 13 | #include "libxslt.h" 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "xslt.h" 23 | #include "xsltInternals.h" 24 | #include "xsltutils.h" 25 | #include "preproc.h" 26 | #include "imports.h" 27 | #include "documents.h" 28 | #include "security.h" 29 | #include "pattern.h" 30 | 31 | 32 | /************************************************************************ 33 | * * 34 | * Module interfaces * 35 | * * 36 | ************************************************************************/ 37 | /** 38 | * xsltFixImportedCompSteps: 39 | * @master: the "master" stylesheet 40 | * @style: the stylesheet being imported by the master 41 | * 42 | * normalize the comp steps for the stylesheet being imported 43 | * by the master, together with any imports within that. 44 | * 45 | */ 46 | static void xsltFixImportedCompSteps(xsltStylesheetPtr master, 47 | xsltStylesheetPtr style) { 48 | xsltStylesheetPtr res; 49 | xmlHashScan(style->templatesHash, xsltNormalizeCompSteps, master); 50 | master->extrasNr += style->extrasNr; 51 | for (res = style->imports; res != NULL; res = res->next) { 52 | xsltFixImportedCompSteps(master, res); 53 | } 54 | } 55 | 56 | #define XSLT_MAX_NESTING 40 57 | 58 | static int 59 | xsltCheckCycle(xsltStylesheetPtr style, xmlNodePtr cur, const xmlChar *URI) { 60 | xsltStylesheetPtr ancestor; 61 | xsltDocumentPtr docptr; 62 | int depth; 63 | 64 | /* 65 | * Check imported stylesheets. 66 | */ 67 | depth = 0; 68 | ancestor = style; 69 | while (ancestor != NULL) { 70 | if (++depth >= XSLT_MAX_NESTING) { 71 | xsltTransformError(NULL, style, cur, 72 | "maximum nesting depth exceeded: %s\n", URI); 73 | return(-1); 74 | } 75 | if (xmlStrEqual(ancestor->doc->URL, URI)) { 76 | xsltTransformError(NULL, style, cur, 77 | "recursion detected on imported URL %s\n", URI); 78 | return(-1); 79 | } 80 | 81 | /* 82 | * Check included stylesheets. 83 | */ 84 | docptr = ancestor->includes; 85 | while (docptr != NULL) { 86 | if (++depth >= XSLT_MAX_NESTING) { 87 | xsltTransformError(NULL, style, cur, 88 | "maximum nesting depth exceeded: %s\n", URI); 89 | return(-1); 90 | } 91 | if (xmlStrEqual(docptr->doc->URL, URI)) { 92 | xsltTransformError(NULL, style, cur, 93 | "recursion detected on included URL %s\n", URI); 94 | return(-1); 95 | } 96 | docptr = docptr->includes; 97 | } 98 | 99 | ancestor = ancestor->parent; 100 | } 101 | 102 | return(0); 103 | } 104 | 105 | /** 106 | * xsltParseStylesheetImport: 107 | * @style: the XSLT stylesheet 108 | * @cur: the import element 109 | * 110 | * parse an XSLT stylesheet import element 111 | * 112 | * Returns 0 in case of success -1 in case of failure. 113 | */ 114 | 115 | int 116 | xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) { 117 | int ret = -1; 118 | xmlDocPtr import = NULL; 119 | xmlChar *base = NULL; 120 | xmlChar *uriRef = NULL; 121 | xmlChar *URI = NULL; 122 | xsltStylesheetPtr res; 123 | xsltSecurityPrefsPtr sec; 124 | 125 | if ((cur == NULL) || (style == NULL)) 126 | return (ret); 127 | 128 | uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL); 129 | if (uriRef == NULL) { 130 | xsltTransformError(NULL, style, cur, 131 | "xsl:import : missing href attribute\n"); 132 | goto error; 133 | } 134 | 135 | base = xmlNodeGetBase(style->doc, cur); 136 | URI = xmlBuildURI(uriRef, base); 137 | if (URI == NULL) { 138 | xsltTransformError(NULL, style, cur, 139 | "xsl:import : invalid URI reference %s\n", uriRef); 140 | goto error; 141 | } 142 | 143 | if (xsltCheckCycle(style, cur, URI) < 0) 144 | goto error; 145 | 146 | /* 147 | * Security framework check 148 | */ 149 | sec = xsltGetDefaultSecurityPrefs(); 150 | if (sec != NULL) { 151 | int secres; 152 | 153 | secres = xsltCheckRead(sec, NULL, URI); 154 | if (secres <= 0) { 155 | if (secres == 0) 156 | xsltTransformError(NULL, NULL, NULL, 157 | "xsl:import: read rights for %s denied\n", 158 | URI); 159 | goto error; 160 | } 161 | } 162 | 163 | import = xsltDocDefaultLoader(URI, style->dict, XSLT_PARSE_OPTIONS, 164 | (void *) style, XSLT_LOAD_STYLESHEET); 165 | if (import == NULL) { 166 | xsltTransformError(NULL, style, cur, 167 | "xsl:import : unable to load %s\n", URI); 168 | goto error; 169 | } 170 | 171 | res = xsltParseStylesheetImportedDoc(import, style); 172 | if (res != NULL) { 173 | res->next = style->imports; 174 | style->imports = res; 175 | if (style->parent == NULL) { 176 | xsltFixImportedCompSteps(style, res); 177 | } 178 | ret = 0; 179 | } else { 180 | xmlFreeDoc(import); 181 | } 182 | 183 | error: 184 | if (uriRef != NULL) 185 | xmlFree(uriRef); 186 | if (base != NULL) 187 | xmlFree(base); 188 | if (URI != NULL) 189 | xmlFree(URI); 190 | 191 | return (ret); 192 | } 193 | 194 | /** 195 | * xsltParseStylesheetInclude: 196 | * @style: the XSLT stylesheet 197 | * @cur: the include node 198 | * 199 | * parse an XSLT stylesheet include element 200 | * 201 | * Returns 0 in case of success -1 in case of failure 202 | */ 203 | 204 | int 205 | xsltParseStylesheetInclude(xsltStylesheetPtr style, xmlNodePtr cur) { 206 | int ret = -1; 207 | xmlDocPtr oldDoc; 208 | xmlChar *base = NULL; 209 | xmlChar *uriRef = NULL; 210 | xmlChar *URI = NULL; 211 | xsltStylesheetPtr result; 212 | xsltDocumentPtr include; 213 | int oldNopreproc; 214 | 215 | if ((cur == NULL) || (style == NULL)) 216 | return (ret); 217 | 218 | uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL); 219 | if (uriRef == NULL) { 220 | xsltTransformError(NULL, style, cur, 221 | "xsl:include : missing href attribute\n"); 222 | goto error; 223 | } 224 | 225 | base = xmlNodeGetBase(style->doc, cur); 226 | URI = xmlBuildURI(uriRef, base); 227 | if (URI == NULL) { 228 | xsltTransformError(NULL, style, cur, 229 | "xsl:include : invalid URI reference %s\n", uriRef); 230 | goto error; 231 | } 232 | 233 | if (xsltCheckCycle(style, cur, URI) < 0) 234 | goto error; 235 | 236 | include = xsltLoadStyleDocument(style, URI); 237 | if (include == NULL) { 238 | xsltTransformError(NULL, style, cur, 239 | "xsl:include : unable to load %s\n", URI); 240 | goto error; 241 | } 242 | #ifdef XSLT_REFACTORED 243 | if (IS_XSLT_ELEM_FAST(cur) && (cur->psvi != NULL)) { 244 | ((xsltStyleItemIncludePtr) cur->psvi)->include = include; 245 | } else { 246 | xsltTransformError(NULL, style, cur, 247 | "Internal error: (xsltParseStylesheetInclude) " 248 | "The xsl:include element was not compiled.\n", URI); 249 | style->errors++; 250 | } 251 | #endif 252 | oldDoc = style->doc; 253 | style->doc = include->doc; 254 | /* chain to stylesheet for recursion checking */ 255 | include->includes = style->includes; 256 | style->includes = include; 257 | oldNopreproc = style->nopreproc; 258 | style->nopreproc = include->preproc; 259 | /* 260 | * TODO: This will change some values of the 261 | * including stylesheet with every included module 262 | * (e.g. excluded-result-prefixes) 263 | * We need to strictly seperate such stylesheet-owned values. 264 | */ 265 | result = xsltParseStylesheetProcess(style, include->doc); 266 | style->nopreproc = oldNopreproc; 267 | include->preproc = 1; 268 | style->includes = include->includes; 269 | style->doc = oldDoc; 270 | if (result == NULL) { 271 | ret = -1; 272 | goto error; 273 | } 274 | ret = 0; 275 | 276 | error: 277 | if (uriRef != NULL) 278 | xmlFree(uriRef); 279 | if (base != NULL) 280 | xmlFree(base); 281 | if (URI != NULL) 282 | xmlFree(URI); 283 | 284 | return (ret); 285 | } 286 | 287 | /** 288 | * xsltNextImport: 289 | * @cur: the current XSLT stylesheet 290 | * 291 | * Find the next stylesheet in import precedence. 292 | * 293 | * Returns the next stylesheet or NULL if it was the last one 294 | */ 295 | 296 | xsltStylesheetPtr 297 | xsltNextImport(xsltStylesheetPtr cur) { 298 | if (cur == NULL) 299 | return(NULL); 300 | if (cur->imports != NULL) 301 | return(cur->imports); 302 | if (cur->next != NULL) 303 | return(cur->next) ; 304 | do { 305 | cur = cur->parent; 306 | if (cur == NULL) break; 307 | if (cur->next != NULL) return(cur->next); 308 | } while (cur != NULL); 309 | return(cur); 310 | } 311 | 312 | /** 313 | * xsltNeedElemSpaceHandling: 314 | * @ctxt: an XSLT transformation context 315 | * 316 | * Checks whether that stylesheet requires white-space stripping 317 | * 318 | * Returns 1 if space should be stripped, 0 if not 319 | */ 320 | 321 | int 322 | xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt) { 323 | xsltStylesheetPtr style; 324 | 325 | if (ctxt == NULL) 326 | return(0); 327 | style = ctxt->style; 328 | while (style != NULL) { 329 | if (style->stripSpaces != NULL) 330 | return(1); 331 | style = xsltNextImport(style); 332 | } 333 | return(0); 334 | } 335 | 336 | /** 337 | * xsltFindElemSpaceHandling: 338 | * @ctxt: an XSLT transformation context 339 | * @node: an XML node 340 | * 341 | * Find strip-space or preserve-space information for an element 342 | * respect the import precedence or the wildcards 343 | * 344 | * Returns 1 if space should be stripped, 0 if not, and 2 if everything 345 | * should be CDTATA wrapped. 346 | */ 347 | 348 | int 349 | xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node) { 350 | xsltStylesheetPtr style; 351 | const xmlChar *val; 352 | 353 | if ((ctxt == NULL) || (node == NULL)) 354 | return(0); 355 | style = ctxt->style; 356 | while (style != NULL) { 357 | if (node->ns != NULL) { 358 | val = (const xmlChar *) 359 | xmlHashLookup2(style->stripSpaces, node->name, node->ns->href); 360 | if (val == NULL) { 361 | val = (const xmlChar *) 362 | xmlHashLookup2(style->stripSpaces, BAD_CAST "*", 363 | node->ns->href); 364 | } 365 | } else { 366 | val = (const xmlChar *) 367 | xmlHashLookup2(style->stripSpaces, node->name, NULL); 368 | } 369 | if (val != NULL) { 370 | if (xmlStrEqual(val, (xmlChar *) "strip")) 371 | return(1); 372 | if (xmlStrEqual(val, (xmlChar *) "preserve")) 373 | return(0); 374 | } 375 | if (style->stripAll == 1) 376 | return(1); 377 | if (style->stripAll == -1) 378 | return(0); 379 | 380 | style = xsltNextImport(style); 381 | } 382 | return(0); 383 | } 384 | 385 | /** 386 | * xsltFindTemplate: 387 | * @ctxt: an XSLT transformation context 388 | * @name: the template name 389 | * @nameURI: the template name URI 390 | * 391 | * Finds the named template, apply import precedence rule. 392 | * REVISIT TODO: We'll change the nameURI fields of 393 | * templates to be in the string dict, so if the 394 | * specified @nameURI is in the same dict, then use pointer 395 | * comparison. Check if this can be done in a sane way. 396 | * Maybe this function is not needed internally at 397 | * transformation-time if we hard-wire the called templates 398 | * to the caller. 399 | * 400 | * Returns the xsltTemplatePtr or NULL if not found 401 | */ 402 | xsltTemplatePtr 403 | xsltFindTemplate(xsltTransformContextPtr ctxt, const xmlChar *name, 404 | const xmlChar *nameURI) { 405 | xsltTemplatePtr cur; 406 | xsltStylesheetPtr style; 407 | 408 | if ((ctxt == NULL) || (name == NULL)) 409 | return(NULL); 410 | style = ctxt->style; 411 | while (style != NULL) { 412 | if (style->namedTemplates != NULL) { 413 | cur = (xsltTemplatePtr) 414 | xmlHashLookup2(style->namedTemplates, name, nameURI); 415 | if (cur != NULL) 416 | return(cur); 417 | } 418 | 419 | style = xsltNextImport(style); 420 | } 421 | return(NULL); 422 | } 423 | 424 | -------------------------------------------------------------------------------- /libxslt/documents.c: -------------------------------------------------------------------------------- 1 | /* 2 | * documents.c: Implementation of the documents handling 3 | * 4 | * See Copyright for the status of this software. 5 | * 6 | * daniel@veillard.com 7 | */ 8 | 9 | #define IN_LIBXSLT 10 | #include "libxslt.h" 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "xslt.h" 20 | #include "xsltInternals.h" 21 | #include "xsltutils.h" 22 | #include "documents.h" 23 | #include "transform.h" 24 | #include "imports.h" 25 | #include "keys.h" 26 | #include "security.h" 27 | 28 | #ifdef LIBXML_XINCLUDE_ENABLED 29 | #include 30 | #endif 31 | 32 | #define WITH_XSLT_DEBUG_DOCUMENTS 33 | 34 | #ifdef WITH_XSLT_DEBUG 35 | #define WITH_XSLT_DEBUG_DOCUMENTS 36 | #endif 37 | 38 | /************************************************************************ 39 | * * 40 | * Hooks for the document loader * 41 | * * 42 | ************************************************************************/ 43 | 44 | /** 45 | * xsltDocDefaultLoaderFunc: 46 | * @URI: the URI of the document to load 47 | * @dict: the dictionary to use when parsing that document 48 | * @options: parsing options, a set of xmlParserOption 49 | * @ctxt: the context, either a stylesheet or a transformation context 50 | * @type: the xsltLoadType indicating the kind of loading required 51 | * 52 | * Default function to load document not provided by the compilation or 53 | * transformation API themselve, for example when an xsl:import, 54 | * xsl:include is found at compilation time or when a document() 55 | * call is made at runtime. 56 | * 57 | * Returns the pointer to the document (which will be modified and 58 | * freed by the engine later), or NULL in case of error. 59 | */ 60 | static xmlDocPtr 61 | xsltDocDefaultLoaderFunc(const xmlChar * URI, xmlDictPtr dict, int options, 62 | void *ctxt ATTRIBUTE_UNUSED, 63 | xsltLoadType type ATTRIBUTE_UNUSED) 64 | { 65 | xmlParserCtxtPtr pctxt; 66 | xmlParserInputPtr inputStream; 67 | xmlDocPtr doc; 68 | 69 | pctxt = xmlNewParserCtxt(); 70 | if (pctxt == NULL) 71 | return(NULL); 72 | if ((dict != NULL) && (pctxt->dict != NULL)) { 73 | xmlDictFree(pctxt->dict); 74 | pctxt->dict = NULL; 75 | } 76 | if (dict != NULL) { 77 | pctxt->dict = dict; 78 | xmlDictReference(pctxt->dict); 79 | #ifdef WITH_XSLT_DEBUG 80 | xsltGenericDebug(xsltGenericDebugContext, 81 | "Reusing dictionary for document\n"); 82 | #endif 83 | } 84 | xmlCtxtUseOptions(pctxt, options); 85 | inputStream = xmlLoadExternalEntity((const char *) URI, NULL, pctxt); 86 | if (inputStream == NULL) { 87 | xmlFreeParserCtxt(pctxt); 88 | return(NULL); 89 | } 90 | 91 | #if LIBXML_VERSION >= 21300 92 | doc = xmlCtxtParseDocument(pctxt, inputStream); 93 | #else 94 | inputPush(pctxt, inputStream); 95 | 96 | xmlParseDocument(pctxt); 97 | 98 | if (pctxt->wellFormed) { 99 | doc = pctxt->myDoc; 100 | } 101 | else { 102 | doc = NULL; 103 | xmlFreeDoc(pctxt->myDoc); 104 | pctxt->myDoc = NULL; 105 | } 106 | #endif 107 | 108 | xmlFreeParserCtxt(pctxt); 109 | 110 | return(doc); 111 | } 112 | 113 | 114 | xsltDocLoaderFunc xsltDocDefaultLoader = xsltDocDefaultLoaderFunc; 115 | 116 | /** 117 | * xsltSetLoaderFunc: 118 | * @f: the new function to handle document loading. 119 | * 120 | * Set the new function to load document, if NULL it resets it to the 121 | * default function. 122 | */ 123 | 124 | void 125 | xsltSetLoaderFunc(xsltDocLoaderFunc f) { 126 | if (f == NULL) 127 | xsltDocDefaultLoader = xsltDocDefaultLoaderFunc; 128 | else 129 | xsltDocDefaultLoader = f; 130 | } 131 | 132 | /************************************************************************ 133 | * * 134 | * Module interfaces * 135 | * * 136 | ************************************************************************/ 137 | 138 | /** 139 | * xsltNewDocument: 140 | * @ctxt: an XSLT transformation context (or NULL) 141 | * @doc: a parsed XML document 142 | * 143 | * Register a new document, apply key computations 144 | * 145 | * Returns a handler to the document 146 | */ 147 | xsltDocumentPtr 148 | xsltNewDocument(xsltTransformContextPtr ctxt, xmlDocPtr doc) { 149 | xsltDocumentPtr cur; 150 | 151 | cur = (xsltDocumentPtr) xmlMalloc(sizeof(xsltDocument)); 152 | if (cur == NULL) { 153 | xsltTransformError(ctxt, NULL, (xmlNodePtr) doc, 154 | "xsltNewDocument : malloc failed\n"); 155 | return(NULL); 156 | } 157 | memset(cur, 0, sizeof(xsltDocument)); 158 | cur->doc = doc; 159 | if (ctxt != NULL) { 160 | if (! XSLT_IS_RES_TREE_FRAG(doc)) { 161 | cur->next = ctxt->docList; 162 | ctxt->docList = cur; 163 | } 164 | /* 165 | * A key with a specific name for a specific document 166 | * will only be computed if there's a call to the key() 167 | * function using that specific name for that specific 168 | * document. I.e. computation of keys will be done in 169 | * xsltGetKey() (keys.c) on an on-demand basis. 170 | * 171 | * xsltInitCtxtKeys(ctxt, cur); not called here anymore 172 | */ 173 | } 174 | return(cur); 175 | } 176 | 177 | /** 178 | * xsltNewStyleDocument: 179 | * @style: an XSLT style sheet 180 | * @doc: a parsed XML document 181 | * 182 | * Register a new document, apply key computations 183 | * 184 | * Returns a handler to the document 185 | */ 186 | xsltDocumentPtr 187 | xsltNewStyleDocument(xsltStylesheetPtr style, xmlDocPtr doc) { 188 | xsltDocumentPtr cur; 189 | 190 | cur = (xsltDocumentPtr) xmlMalloc(sizeof(xsltDocument)); 191 | if (cur == NULL) { 192 | xsltTransformError(NULL, style, (xmlNodePtr) doc, 193 | "xsltNewStyleDocument : malloc failed\n"); 194 | return(NULL); 195 | } 196 | memset(cur, 0, sizeof(xsltDocument)); 197 | cur->doc = doc; 198 | if (style != NULL) { 199 | cur->next = style->docList; 200 | style->docList = cur; 201 | } 202 | return(cur); 203 | } 204 | 205 | /** 206 | * xsltFreeStyleDocuments: 207 | * @style: an XSLT stylesheet (representing a stylesheet-level) 208 | * 209 | * Frees the node-trees (and xsltDocument structures) of all 210 | * stylesheet-modules of the stylesheet-level represented by 211 | * the given @style. 212 | */ 213 | void 214 | xsltFreeStyleDocuments(xsltStylesheetPtr style) { 215 | xsltDocumentPtr doc, cur; 216 | #ifdef XSLT_REFACTORED_XSLT_NSCOMP 217 | xsltNsMapPtr nsMap; 218 | #endif 219 | 220 | if (style == NULL) 221 | return; 222 | 223 | #ifdef XSLT_REFACTORED_XSLT_NSCOMP 224 | if (XSLT_HAS_INTERNAL_NSMAP(style)) 225 | nsMap = XSLT_GET_INTERNAL_NSMAP(style); 226 | else 227 | nsMap = NULL; 228 | #endif 229 | 230 | cur = style->docList; 231 | while (cur != NULL) { 232 | doc = cur; 233 | cur = cur->next; 234 | #ifdef XSLT_REFACTORED_XSLT_NSCOMP 235 | /* 236 | * Restore all changed namespace URIs of ns-decls. 237 | */ 238 | if (nsMap) 239 | xsltRestoreDocumentNamespaces(nsMap, doc->doc); 240 | #endif 241 | xsltFreeDocumentKeys(doc); 242 | if (!doc->main) 243 | xmlFreeDoc(doc->doc); 244 | xmlFree(doc); 245 | } 246 | } 247 | 248 | /** 249 | * xsltFreeDocuments: 250 | * @ctxt: an XSLT transformation context 251 | * 252 | * Free up all the space used by the loaded documents 253 | */ 254 | void 255 | xsltFreeDocuments(xsltTransformContextPtr ctxt) { 256 | xsltDocumentPtr doc, cur; 257 | 258 | cur = ctxt->docList; 259 | while (cur != NULL) { 260 | doc = cur; 261 | cur = cur->next; 262 | xsltFreeDocumentKeys(doc); 263 | if (!doc->main) 264 | xmlFreeDoc(doc->doc); 265 | xmlFree(doc); 266 | } 267 | cur = ctxt->styleList; 268 | while (cur != NULL) { 269 | doc = cur; 270 | cur = cur->next; 271 | xsltFreeDocumentKeys(doc); 272 | if (!doc->main) 273 | xmlFreeDoc(doc->doc); 274 | xmlFree(doc); 275 | } 276 | } 277 | 278 | /** 279 | * xsltLoadDocument: 280 | * @ctxt: an XSLT transformation context 281 | * @URI: the computed URI of the document 282 | * 283 | * Try to load a document (not a stylesheet) 284 | * within the XSLT transformation context 285 | * 286 | * Returns the new xsltDocumentPtr or NULL in case of error 287 | */ 288 | xsltDocumentPtr 289 | xsltLoadDocument(xsltTransformContextPtr ctxt, const xmlChar *URI) { 290 | xsltDocumentPtr ret; 291 | xmlDocPtr doc; 292 | 293 | if ((ctxt == NULL) || (URI == NULL)) 294 | return(NULL); 295 | 296 | /* 297 | * Security framework check 298 | */ 299 | if (ctxt->sec != NULL) { 300 | int res; 301 | 302 | res = xsltCheckRead(ctxt->sec, ctxt, URI); 303 | if (res <= 0) { 304 | if (res == 0) 305 | xsltTransformError(ctxt, NULL, NULL, 306 | "xsltLoadDocument: read rights for %s denied\n", 307 | URI); 308 | return(NULL); 309 | } 310 | } 311 | 312 | /* 313 | * Walk the context list to find the document if preparsed 314 | */ 315 | ret = ctxt->docList; 316 | while (ret != NULL) { 317 | if ((ret->doc != NULL) && (ret->doc->URL != NULL) && 318 | (xmlStrEqual(ret->doc->URL, URI))) 319 | return(ret); 320 | ret = ret->next; 321 | } 322 | 323 | doc = xsltDocDefaultLoader(URI, ctxt->dict, ctxt->parserOptions, 324 | (void *) ctxt, XSLT_LOAD_DOCUMENT); 325 | 326 | if (doc == NULL) 327 | return(NULL); 328 | 329 | if (ctxt->xinclude != 0) { 330 | #ifdef LIBXML_XINCLUDE_ENABLED 331 | #if LIBXML_VERSION >= 20603 332 | xmlXIncludeProcessFlags(doc, ctxt->parserOptions); 333 | #else 334 | xmlXIncludeProcess(doc); 335 | #endif 336 | #else 337 | xsltTransformError(ctxt, NULL, NULL, 338 | "xsltLoadDocument(%s) : XInclude processing not compiled in\n", 339 | URI); 340 | #endif 341 | } 342 | /* 343 | * Apply white-space stripping if asked for 344 | */ 345 | if (xsltNeedElemSpaceHandling(ctxt)) 346 | xsltApplyStripSpaces(ctxt, xmlDocGetRootElement(doc)); 347 | if (ctxt->debugStatus == XSLT_DEBUG_NONE) 348 | xmlXPathOrderDocElems(doc); 349 | 350 | ret = xsltNewDocument(ctxt, doc); 351 | return(ret); 352 | } 353 | 354 | /** 355 | * xsltLoadStyleDocument: 356 | * @style: an XSLT style sheet 357 | * @URI: the computed URI of the document 358 | * 359 | * Try to load a stylesheet document within the XSLT transformation context 360 | * 361 | * Returns the new xsltDocumentPtr or NULL in case of error 362 | */ 363 | xsltDocumentPtr 364 | xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI) { 365 | xsltDocumentPtr ret; 366 | xmlDocPtr doc; 367 | xsltSecurityPrefsPtr sec; 368 | 369 | if ((style == NULL) || (URI == NULL)) 370 | return(NULL); 371 | 372 | /* 373 | * Security framework check 374 | */ 375 | sec = xsltGetDefaultSecurityPrefs(); 376 | if (sec != NULL) { 377 | int res; 378 | 379 | res = xsltCheckRead(sec, NULL, URI); 380 | if (res <= 0) { 381 | if (res == 0) 382 | xsltTransformError(NULL, NULL, NULL, 383 | "xsltLoadStyleDocument: read rights for %s denied\n", 384 | URI); 385 | return(NULL); 386 | } 387 | } 388 | 389 | /* 390 | * Walk the context list to find the document if preparsed 391 | */ 392 | ret = style->docList; 393 | while (ret != NULL) { 394 | if ((ret->doc != NULL) && (ret->doc->URL != NULL) && 395 | (xmlStrEqual(ret->doc->URL, URI))) 396 | return(ret); 397 | ret = ret->next; 398 | } 399 | 400 | doc = xsltDocDefaultLoader(URI, style->dict, XSLT_PARSE_OPTIONS, 401 | (void *) style, XSLT_LOAD_STYLESHEET); 402 | if (doc == NULL) 403 | return(NULL); 404 | 405 | ret = xsltNewStyleDocument(style, doc); 406 | if (ret == NULL) 407 | xmlFreeDoc(doc); 408 | return(ret); 409 | } 410 | 411 | /** 412 | * xsltFindDocument: 413 | * @ctxt: an XSLT transformation context 414 | * @doc: a parsed XML document 415 | * 416 | * Try to find a document within the XSLT transformation context. 417 | * This will not find document infos for temporary 418 | * Result Tree Fragments. 419 | * 420 | * Returns the desired xsltDocumentPtr or NULL in case of error 421 | */ 422 | xsltDocumentPtr 423 | xsltFindDocument (xsltTransformContextPtr ctxt, xmlDocPtr doc) { 424 | xsltDocumentPtr ret; 425 | 426 | if ((ctxt == NULL) || (doc == NULL)) 427 | return(NULL); 428 | 429 | /* 430 | * Walk the context list to find the document 431 | */ 432 | ret = ctxt->docList; 433 | while (ret != NULL) { 434 | if (ret->doc == doc) 435 | return(ret); 436 | ret = ret->next; 437 | } 438 | if (doc == ctxt->style->doc) 439 | return(ctxt->document); 440 | return(NULL); 441 | } 442 | 443 | -------------------------------------------------------------------------------- /libxslt/security.c: -------------------------------------------------------------------------------- 1 | /* 2 | * security.c: Implementation of the XSLT security framework 3 | * 4 | * See Copyright for the status of this software. 5 | * 6 | * daniel@veillard.com 7 | */ 8 | 9 | #define IN_LIBXSLT 10 | #include "libxslt.h" 11 | 12 | #include 13 | 14 | #ifdef HAVE_SYS_TYPES_H 15 | #include 16 | #endif 17 | #ifdef HAVE_SYS_STAT_H 18 | #include 19 | #endif 20 | 21 | #if defined(_WIN32) 22 | #include 23 | #ifndef INVALID_FILE_ATTRIBUTES 24 | #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 25 | #endif 26 | #endif 27 | 28 | #ifndef HAVE_STAT 29 | # ifdef HAVE__STAT 30 | /* MS C library seems to define stat and _stat. The definition 31 | * is identical. Still, mapping them to each other causes a warning. */ 32 | # ifndef _MSC_VER 33 | # define stat(x,y) _stat(x,y) 34 | # endif 35 | # define HAVE_STAT 36 | # endif 37 | #endif 38 | 39 | #include 40 | #include 41 | #include 42 | #include "xslt.h" 43 | #include "xsltInternals.h" 44 | #include "xsltutils.h" 45 | #include "extensions.h" 46 | #include "security.h" 47 | 48 | 49 | struct _xsltSecurityPrefs { 50 | xsltSecurityCheck readFile; 51 | xsltSecurityCheck createFile; 52 | xsltSecurityCheck createDir; 53 | xsltSecurityCheck readNet; 54 | xsltSecurityCheck writeNet; 55 | }; 56 | 57 | static xsltSecurityPrefsPtr xsltDefaultSecurityPrefs = NULL; 58 | 59 | /************************************************************************ 60 | * * 61 | * Module interfaces * 62 | * * 63 | ************************************************************************/ 64 | 65 | /** 66 | * xsltNewSecurityPrefs: 67 | * 68 | * Create a new security preference block 69 | * 70 | * Returns a pointer to the new block or NULL in case of error 71 | */ 72 | xsltSecurityPrefsPtr 73 | xsltNewSecurityPrefs(void) { 74 | xsltSecurityPrefsPtr ret; 75 | 76 | xsltInitGlobals(); 77 | 78 | ret = (xsltSecurityPrefsPtr) xmlMalloc(sizeof(xsltSecurityPrefs)); 79 | if (ret == NULL) { 80 | xsltTransformError(NULL, NULL, NULL, 81 | "xsltNewSecurityPrefs : malloc failed\n"); 82 | return(NULL); 83 | } 84 | memset(ret, 0, sizeof(xsltSecurityPrefs)); 85 | return(ret); 86 | } 87 | 88 | /** 89 | * xsltFreeSecurityPrefs: 90 | * @sec: the security block to free 91 | * 92 | * Free up a security preference block 93 | */ 94 | void 95 | xsltFreeSecurityPrefs(xsltSecurityPrefsPtr sec) { 96 | if (sec == NULL) 97 | return; 98 | xmlFree(sec); 99 | } 100 | 101 | /** 102 | * xsltSetSecurityPrefs: 103 | * @sec: the security block to update 104 | * @option: the option to update 105 | * @func: the user callback to use for this option 106 | * 107 | * Update the security option to use the new callback checking function 108 | * 109 | * Returns -1 in case of error, 0 otherwise 110 | */ 111 | int 112 | xsltSetSecurityPrefs(xsltSecurityPrefsPtr sec, xsltSecurityOption option, 113 | xsltSecurityCheck func) { 114 | xsltInitGlobals(); 115 | if (sec == NULL) 116 | return(-1); 117 | switch (option) { 118 | case XSLT_SECPREF_READ_FILE: 119 | sec->readFile = func; return(0); 120 | case XSLT_SECPREF_WRITE_FILE: 121 | sec->createFile = func; return(0); 122 | case XSLT_SECPREF_CREATE_DIRECTORY: 123 | sec->createDir = func; return(0); 124 | case XSLT_SECPREF_READ_NETWORK: 125 | sec->readNet = func; return(0); 126 | case XSLT_SECPREF_WRITE_NETWORK: 127 | sec->writeNet = func; return(0); 128 | } 129 | return(-1); 130 | } 131 | 132 | /** 133 | * xsltGetSecurityPrefs: 134 | * @sec: the security block to update 135 | * @option: the option to lookup 136 | * 137 | * Lookup the security option to get the callback checking function 138 | * 139 | * Returns NULL if not found, the function otherwise 140 | */ 141 | xsltSecurityCheck 142 | xsltGetSecurityPrefs(xsltSecurityPrefsPtr sec, xsltSecurityOption option) { 143 | if (sec == NULL) 144 | return(NULL); 145 | switch (option) { 146 | case XSLT_SECPREF_READ_FILE: 147 | return(sec->readFile); 148 | case XSLT_SECPREF_WRITE_FILE: 149 | return(sec->createFile); 150 | case XSLT_SECPREF_CREATE_DIRECTORY: 151 | return(sec->createDir); 152 | case XSLT_SECPREF_READ_NETWORK: 153 | return(sec->readNet); 154 | case XSLT_SECPREF_WRITE_NETWORK: 155 | return(sec->writeNet); 156 | } 157 | return(NULL); 158 | } 159 | 160 | /** 161 | * xsltSetDefaultSecurityPrefs: 162 | * @sec: the security block to use 163 | * 164 | * Set the default security preference application-wide 165 | */ 166 | void 167 | xsltSetDefaultSecurityPrefs(xsltSecurityPrefsPtr sec) { 168 | 169 | xsltDefaultSecurityPrefs = sec; 170 | } 171 | 172 | /** 173 | * xsltGetDefaultSecurityPrefs: 174 | * 175 | * Get the default security preference application-wide 176 | * 177 | * Returns the current xsltSecurityPrefsPtr in use or NULL if none 178 | */ 179 | xsltSecurityPrefsPtr 180 | xsltGetDefaultSecurityPrefs(void) { 181 | return(xsltDefaultSecurityPrefs); 182 | } 183 | 184 | /** 185 | * xsltSetCtxtSecurityPrefs: 186 | * @sec: the security block to use 187 | * @ctxt: an XSLT transformation context 188 | * 189 | * Set the security preference for a specific transformation 190 | * 191 | * Returns -1 in case of error, 0 otherwise 192 | */ 193 | int 194 | xsltSetCtxtSecurityPrefs(xsltSecurityPrefsPtr sec, 195 | xsltTransformContextPtr ctxt) { 196 | if (ctxt == NULL) 197 | return(-1); 198 | ctxt->sec = (void *) sec; 199 | return(0); 200 | } 201 | 202 | 203 | /** 204 | * xsltSecurityAllow: 205 | * @sec: the security block to use 206 | * @ctxt: an XSLT transformation context 207 | * @value: unused 208 | * 209 | * Function used to always allow an operation 210 | * 211 | * Returns 1 always 212 | */ 213 | int 214 | xsltSecurityAllow(xsltSecurityPrefsPtr sec ATTRIBUTE_UNUSED, 215 | xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED, 216 | const char *value ATTRIBUTE_UNUSED) { 217 | return(1); 218 | } 219 | 220 | /** 221 | * xsltSecurityForbid: 222 | * @sec: the security block to use 223 | * @ctxt: an XSLT transformation context 224 | * @value: unused 225 | * 226 | * Function used to always forbid an operation 227 | * 228 | * Returns 0 always 229 | */ 230 | int 231 | xsltSecurityForbid(xsltSecurityPrefsPtr sec ATTRIBUTE_UNUSED, 232 | xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED, 233 | const char *value ATTRIBUTE_UNUSED) { 234 | return(0); 235 | } 236 | 237 | /************************************************************************ 238 | * * 239 | * Internal interfaces * 240 | * * 241 | ************************************************************************/ 242 | 243 | /** 244 | * xsltCheckFilename 245 | * @path: the path to check 246 | * 247 | * function checks to see if @path is a valid source 248 | * (file, socket...) for XML. 249 | * 250 | * TODO: remove at some point !!! 251 | * Local copy of xmlCheckFilename to avoid a hard dependency on 252 | * a new version of libxml2 253 | * 254 | * if stat is not available on the target machine, 255 | * returns 1. if stat fails, returns 0 (if calling 256 | * stat on the filename fails, it can't be right). 257 | * if stat succeeds and the file is a directory, 258 | * returns 2. otherwise returns 1. 259 | */ 260 | 261 | static int 262 | xsltCheckFilename (const char *path) 263 | { 264 | #ifdef HAVE_STAT 265 | #if defined(_MSC_VER) && _MSC_VER >= 1500 266 | struct _stat64 stat_buffer; 267 | #else 268 | struct stat stat_buffer; 269 | #endif 270 | #if defined(_WIN32) 271 | DWORD dwAttrs; 272 | 273 | dwAttrs = GetFileAttributesA(path); 274 | if (dwAttrs != INVALID_FILE_ATTRIBUTES) { 275 | if (dwAttrs & FILE_ATTRIBUTE_DIRECTORY) { 276 | return 2; 277 | } 278 | } 279 | #endif 280 | 281 | if ( 282 | #if defined(_MSC_VER) && _MSC_VER >= 1500 283 | _stat64(path, &stat_buffer) 284 | #else 285 | stat(path, &stat_buffer) 286 | #endif 287 | == -1) 288 | return 0; 289 | 290 | #ifdef S_ISDIR 291 | if (S_ISDIR(stat_buffer.st_mode)) { 292 | return 2; 293 | } 294 | #endif 295 | #endif 296 | return 1; 297 | } 298 | 299 | static int 300 | xsltCheckWritePath(xsltSecurityPrefsPtr sec, 301 | xsltTransformContextPtr ctxt, 302 | const char *path) 303 | { 304 | int ret; 305 | xsltSecurityCheck check; 306 | char *directory; 307 | 308 | check = xsltGetSecurityPrefs(sec, XSLT_SECPREF_WRITE_FILE); 309 | if (check != NULL) { 310 | ret = check(sec, ctxt, path); 311 | if (ret == 0) { 312 | xsltTransformError(ctxt, NULL, NULL, 313 | "File write for %s refused\n", path); 314 | return(0); 315 | } 316 | } 317 | 318 | directory = xmlParserGetDirectory (path); 319 | 320 | if (directory != NULL) { 321 | ret = xsltCheckFilename(directory); 322 | if (ret == 0) { 323 | /* 324 | * The directory doesn't exist check for creation 325 | */ 326 | check = xsltGetSecurityPrefs(sec, 327 | XSLT_SECPREF_CREATE_DIRECTORY); 328 | if (check != NULL) { 329 | ret = check(sec, ctxt, directory); 330 | if (ret == 0) { 331 | xsltTransformError(ctxt, NULL, NULL, 332 | "Directory creation for %s refused\n", 333 | path); 334 | xmlFree(directory); 335 | return(0); 336 | } 337 | } 338 | ret = xsltCheckWritePath(sec, ctxt, directory); 339 | if (ret == 1) 340 | ret = mkdir(directory, 0755); 341 | } 342 | xmlFree(directory); 343 | if (ret < 0) 344 | return(ret); 345 | } 346 | 347 | return(1); 348 | } 349 | 350 | /** 351 | * xsltCheckWrite: 352 | * @sec: the security options 353 | * @ctxt: an XSLT transformation context 354 | * @URL: the resource to be written 355 | * 356 | * Check if the resource is allowed to be written, if necessary makes 357 | * some preliminary work like creating directories 358 | * 359 | * Return 1 if write is allowed, 0 if not and -1 in case or error. 360 | */ 361 | int 362 | xsltCheckWrite(xsltSecurityPrefsPtr sec, 363 | xsltTransformContextPtr ctxt, const xmlChar *URL) { 364 | int ret; 365 | xmlURIPtr uri; 366 | xsltSecurityCheck check; 367 | 368 | uri = xmlParseURI((const char *)URL); 369 | if (uri == NULL) { 370 | uri = xmlCreateURI(); 371 | if (uri == NULL) { 372 | xsltTransformError(ctxt, NULL, NULL, 373 | "xsltCheckWrite: out of memory for %s\n", URL); 374 | return(-1); 375 | } 376 | uri->path = (char *)xmlStrdup(URL); 377 | } 378 | if ((uri->scheme == NULL) || 379 | (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) { 380 | 381 | #if defined(_WIN32) 382 | if ((uri->path)&&(uri->path[0]=='/')&& 383 | (uri->path[1]!='\0')&&(uri->path[2]==':')) 384 | ret = xsltCheckWritePath(sec, ctxt, uri->path+1); 385 | else 386 | #endif 387 | { 388 | /* 389 | * Check if we are allowed to write this file 390 | */ 391 | ret = xsltCheckWritePath(sec, ctxt, uri->path); 392 | } 393 | 394 | if (ret <= 0) { 395 | xmlFreeURI(uri); 396 | return(ret); 397 | } 398 | } else { 399 | /* 400 | * Check if we are allowed to write this network resource 401 | */ 402 | check = xsltGetSecurityPrefs(sec, XSLT_SECPREF_WRITE_NETWORK); 403 | if (check != NULL) { 404 | ret = check(sec, ctxt, (const char *)URL); 405 | if (ret == 0) { 406 | xsltTransformError(ctxt, NULL, NULL, 407 | "File write for %s refused\n", URL); 408 | xmlFreeURI(uri); 409 | return(0); 410 | } 411 | } 412 | } 413 | xmlFreeURI(uri); 414 | return(1); 415 | } 416 | 417 | 418 | /** 419 | * xsltCheckRead: 420 | * @sec: the security options 421 | * @ctxt: an XSLT transformation context 422 | * @URL: the resource to be read 423 | * 424 | * Check if the resource is allowed to be read 425 | * 426 | * Return 1 if read is allowed, 0 if not and -1 in case or error. 427 | */ 428 | int 429 | xsltCheckRead(xsltSecurityPrefsPtr sec, 430 | xsltTransformContextPtr ctxt, const xmlChar *URL) { 431 | int ret; 432 | xmlURIPtr uri; 433 | xsltSecurityCheck check; 434 | 435 | if (xmlStrstr(URL, BAD_CAST "://") == NULL) { 436 | check = xsltGetSecurityPrefs(sec, XSLT_SECPREF_READ_FILE); 437 | if (check != NULL) { 438 | ret = check(sec, ctxt, (const char *) URL); 439 | if (ret == 0) { 440 | xsltTransformError(ctxt, NULL, NULL, 441 | "Local file read for %s refused\n", URL); 442 | return(0); 443 | } 444 | } 445 | return(1); 446 | } 447 | 448 | uri = xmlParseURI((const char *)URL); 449 | if (uri == NULL) { 450 | xsltTransformError(ctxt, NULL, NULL, 451 | "xsltCheckRead: URL parsing failed for %s\n", 452 | URL); 453 | return(-1); 454 | } 455 | if ((uri->scheme == NULL) || 456 | (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) { 457 | 458 | /* 459 | * Check if we are allowed to read this file 460 | */ 461 | check = xsltGetSecurityPrefs(sec, XSLT_SECPREF_READ_FILE); 462 | if (check != NULL) { 463 | ret = check(sec, ctxt, uri->path); 464 | if (ret == 0) { 465 | xsltTransformError(ctxt, NULL, NULL, 466 | "Local file read for %s refused\n", URL); 467 | xmlFreeURI(uri); 468 | return(0); 469 | } 470 | } 471 | } else { 472 | /* 473 | * Check if we are allowed to write this network resource 474 | */ 475 | check = xsltGetSecurityPrefs(sec, XSLT_SECPREF_READ_NETWORK); 476 | if (check != NULL) { 477 | ret = check(sec, ctxt, (const char *)URL); 478 | if (ret == 0) { 479 | xsltTransformError(ctxt, NULL, NULL, 480 | "Network file read for %s refused\n", URL); 481 | xmlFreeURI(uri); 482 | return(0); 483 | } 484 | } 485 | } 486 | xmlFreeURI(uri); 487 | return(1); 488 | } 489 | 490 | --------------------------------------------------------------------------------