summaryrefslogtreecommitdiff
path: root/ext/xslt
diff options
context:
space:
mode:
Diffstat (limited to 'ext/xslt')
-rw-r--r--ext/xslt/EXPERIMENTAL5
-rw-r--r--ext/xslt/Makefile.in8
-rw-r--r--ext/xslt/README.XSLT-BACKENDS284
-rw-r--r--ext/xslt/config.m494
-rw-r--r--ext/xslt/php_sablot.h126
-rw-r--r--ext/xslt/php_xslt.h63
-rw-r--r--ext/xslt/sablot.c1573
-rw-r--r--ext/xslt/tests/001.phpt12
-rw-r--r--ext/xslt/xslt.c257
-rw-r--r--ext/xslt/xslt.dsp115
10 files changed, 0 insertions, 2537 deletions
diff --git a/ext/xslt/EXPERIMENTAL b/ext/xslt/EXPERIMENTAL
deleted file mode 100644
index 6443e99646..0000000000
--- a/ext/xslt/EXPERIMENTAL
+++ /dev/null
@@ -1,5 +0,0 @@
-this extension is experimental,
-its functions may change their names
-or move to extension all together
-so do not rely to much on them
-you have been warned!
diff --git a/ext/xslt/Makefile.in b/ext/xslt/Makefile.in
deleted file mode 100644
index df6a07d830..0000000000
--- a/ext/xslt/Makefile.in
+++ /dev/null
@@ -1,8 +0,0 @@
-# $Id$
-
-LTLIBRARY_NAME = libxslt.la
-LTLIBRARY_SOURCES = xslt.c sablot.c
-LTLIBRARY_SHARED_NAME = xslt.la
-LTLIBRARY_SHARED_LIBADD = $(XSLT_SHARED_LIBADD)
-
-include $(top_srcdir)/build/dynlib.mk
diff --git a/ext/xslt/README.XSLT-BACKENDS b/ext/xslt/README.XSLT-BACKENDS
deleted file mode 100644
index 07594ceb64..0000000000
--- a/ext/xslt/README.XSLT-BACKENDS
+++ /dev/null
@@ -1,284 +0,0 @@
-+------------------------------------------------------------------------------+
-| CREATING XSLT BACKENDS |
-+------------------------------------------------------------------------------+
-
- Author(s): Sterling Hughes <sterling@php.net>
-
- Introduction
- -------------------------------------------------------------------------------
- Truth be told, at this point in time there are about a zillion and two
- different XSLT libraries, each with there unique merits and faults. If you
- provide a Sablotron extension, people will clamor for a Xalan extension, if you
- provide a Xalan extension people will clamor for a libxslt extension.
-
- In order to be as user friendly as possible, we try and provide the most
- amount of options to the user. At the same time we must try to keep a level of
- consistency, so the user does not need to remember 15 different syntaxes, etc.
- for each XSLT extension, and when switching from XSLT backends, no changes in
- the PHP code should be necessary (akin to the concept of a database independent
- api, but with XSLT libraries).
-
- At the same time, you'll also notice that in some cases extensions seem to
- duplicate each others functionality. All extensions need code for calling
- user-defined handlers, omitting debug messages, etc. In the interests of
- laziness, we must also try to make these as minimal as possible.
-
- Therefore, I've create a processor independent api for XSLT, aka, the XSLT
- extension (but doesn't "A processor independent API for XSLT" sound cooler?).
- It defines a set of functions which every XSLT backend must provide, as well
- as a syntax which those functions must adhere to. Furthermore, the underlying
- code, provides a "library" if you will, of code that is relevant to all XSLT
- extensions.
-
- The API
- -------------------------------------------------------------------------------
- Every extension must define the following functions:
-
- - xslt_create()
- - xslt_set_scheme_handlers()
- - xslt_set_sax_handlers()
- - xslt_set_error_handler()
- - xslt_set_log()
- - xslt_process()
- - xslt_error()
- - xslt_errno()
- - xslt_free()
-
- These functions are common or implementable with every single XSLT library that
- I've come across so far (at least every C library) and should there for be
- defined by the extension.
-
-
- resource xslt_create(void)
-
- The XSLT create function allocates a new XSLT processor and returns a resource
- pointer to the XSLT processor. It also handles any initialization that the
- processor requires.
-
-
- void xslt_set_scheme_handlers(resource processor, array handlers)
-
- Registers the scheme handlers for the document (aka XPath handlers), given a
- XSLT processor resource (allocated by xslt_create()) and an array in the
- following format:
-
- array(
- "get_all" => function,
- "open" => function,
- "get" => function,
- "put" => function,
- "close" => function
- )
-
- Where function is either a function name or an array in the following format:
-
- array(&$obj, "method")
-
- Note: You do not need to handle the array(&$obj, "method") syntax by yourself
- as this is handled in the call_xslt_function() library function (and
- more specifically, Zend's call_user_function_ex() function.
- Note: The given array does not need to contain all of the different scheme
- handler elements (although it can), but it only needs to conform to
- the "handler" => "function" format described above.
-
- Each of the individual scheme handler functions called are in the formats
- below:
-
- string get_all(resource processor, string scheme, string rest)
- resource open(resource processor, string scheme, string rest)
- int get(resource processor, resource fp, string &data)
- int put(resource processor, resource fp, string data)
- void close(resource processor, resource fp)
-
-
- void xslt_set_sax_handlers(resource processor, array handlers)
-
- Registers the SAX handlers for the document, given a XSLT processor resource
- (allocated by xslt_create()) and an array in the following format:
-
- array(
- "document" => array(document_start_function,
- document_end_function),
- "element" => array(element_start_function,
- element_end_function),
- "namespace" => array(namespace_start_function,
- namespace_end_function),
- "comment" => function,
- "pi" => function,
- "character" => function
- )
-
- Where the functions follow the syntax described for the scheme handler
- functions.
-
- Each of the individual SAX handler functions are in the format below:
-
- void start_doc(resource processor)
- void end_doc(resource processor)
- void start_element(resource processor, string name, array attributes)
- void end_element(resource processor, string name)
- void start_namespace(resource processor, string prefix, string uri)
- void end_namespace(resource processor, string prefix)
- void comment(resource processor, string contents)
- void pi(resource processor, string target, string contents)
- void characters(resource processor, string contents)
-
-
- void xslt_set_error_handler(resource processor, function error_handler)
-
- This function sets the user defined error handler to be called when a
- processing or any other type of error occurs. It is given a XSLT
- processor resource (allocated by xslt_create()) and an error function of
- the same syntax described for the scheme handler function.
-
- The user defined error handler as the following syntax:
-
- void error(resource processor, int level, int error, array info)
-
-
- void xslt_set_log(resource processor, string logname)
-
- Sets the XSLT log to record log information (processor messages, not errors).
- Its given a XSLT processor (allocated by xslt_create()) and a string containing
- the name of the log file. If the string is "php://stderr" then the logging
- should go to standard error (stderr). Also the default place to send log
- messages is standard error (if no log file is set).
-
-
- mixed xslt_process(resource processor,
- string xml,
- string xsl[,
- string result[,
- array arguments[,
- array parameters]]])
-
- This function performs the magic, it takes the user's data, performs the
- transformation and depending on the context either saves the result to a file
- or returns the data to the user.
-
- To understand the way the xslt_process() function works, you must first
- understand the concept of "argument buffers". Argument buffers are equivalent
- to the concept of symlinks on a Unix system, take the following example:
-
- <?php
-
- /**
- * $xml contains the contents of an XML file and $xsl contains
- * the contents of an XSLT stylesheet
- */
- $args = array("/_xml" => $xml,
- "/_xsl" => $xsl);
-
- $xh = xslt_create();
- $data = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args);
- xslt_free($xh);
-
- print( "The results of the transformation were\n" );
- print( "<br>\n<hr>\n<br>" );
- print( $data );
- print( "<br>\n<hr>\n<br>" );
- ?>
-
- See what was done? The argument buffer was declared ($args) and the different
- arguments were defined. Then when the xslt_process() function was called
- instead of giving the XML filename and XSLT filename we instead gave
- "arguments", which correspond to the XML and XSLT data in the argument buffers.
-
- This concept is a bit foreign to some people, however, I find it the best way
- to handle processing xsl data. If your still having trouble with this, try
- playing around with the sablotron backend a bit, you should be able to catch on
- pretty quickly.
-
- In order to use argument buffers, the XSLT extension provides a couple of easy
- to use API functions, you can use them as follows:
-
- {
- zval **arguments_zp;
- char **arguments_cp;
- xslt_args *arguments;
- char *types[] = { "file", "data" };
-
- /* Fetch the arguments from the user into a zval ** */
-
- /* Translate the zval array into a character array */
- xslt_make_array(&arguments_cp, arguments_zp);
-
- /* Translate the character array into an xslt_arg * structure */
- arguments = xslt_parse_arguments(arguments_cp);
-
- /* Print out the resulting xslt_arg * structure */
- php_printf("XML type: %s\n", types[arguments->xml.type]);
- php_printf("XML data: %s\n", arguments->xml.ptr);
- PUTS("\n");
- php_printf("XSLT type: %s\n", types[arguments->xsl.type]);
- php_printf("XSLT data: %s\n", arguments->xsl.ptr);
- PUTS("\n");
- php_printf("Result type: %s\n", types[arguments->result.type]);
- php_printf("Result data: %s\n", arguments->result.ptr);
- PUTS("\n");
- }
-
- You can also test the "type" field by using the XSLT_IS_FILE and XSLT_IS_DATA
- constants.
-
- Anyway back to the syntax of the xslt_process() function. The first argument
- to the xslt_process() function is a resource pointer to the XSLT processor to
- be used. The second argument is either an "argument buffer" pointing to the
- XML data or the name of a file containing the XML data. The third argument is
- either an argument buffer pointing to the XSLT data or a file containing the
- XSLT data. The fourth argument is optional, it either contains the name of the
- file to place the results of the transformation into, NULL or "arg:/_result",
- in the latter 2 cases, the results of the transformation will be returned. The
- fifth optional argument is the "argument buffer" itself, it is an associative
- PHP array of "argument_name" => "value" pairs, or NULL, if no arguments are to
- be passed. The final optional argument is a set of parameters to pass to the
- XSLT stylesheet. The parameter argument is an associative array of
- "parameter_name" => "value" pairs.
-
-
- string xslt_error(resource processor)
-
- The xslt_error() function returns the last error that occured, given a XSLT
- processor resource (allocated by xslt_create()).
-
-
- int xslt_errno(resource processor)
-
- The xslt_errno() function returns the last error number that occured given a
- XSLT processor resource (allocated by xslt_create()).
-
-
- void xslt_free(resource processor)
-
- The xslt_free() function free's the given XSLT processor resource (allocated
- by xslt_create()).
-
-
- Config.m4
- -------------------------------------------------------------------------------
-
- The XSLT extensions "magic" really occurs in the config.m4 file. Here you must
- add a couple of things in order for your backend to be enabled. Its a bit too
- complex to describe (but easy to implement and understand). Take a look at
- config.m4 (which is well commented) to see what is necessary.
-
-
- Makefile.in
- -------------------------------------------------------------------------------
-
- Simply add the source files for your backend to the LTLIBRARY_SOURCES variable
- and you're all set with this file.
-
-
- Conclusion
- -------------------------------------------------------------------------------
-
- Nobody's perfect, I'm sure I've made some mistakes while thinking this whole
- thing through and I would be glad to here from any of you who think I'm a
- colossal moron and think you have a better way to do it. Please e-mail at
- sterling@php.net, this extension will only get better with feedback.
-
- With that said, the concepts here may take a little bit of time to sink in, I
- know I've written a whole lot. My suggestion to you, if you're planning on
- writing an XSLT backend is simply to go off and implement, taking the api
- section as a guide and making sure you match that api as closely as possible.
diff --git a/ext/xslt/config.m4 b/ext/xslt/config.m4
deleted file mode 100644
index 024ea0fa4b..0000000000
--- a/ext/xslt/config.m4
+++ /dev/null
@@ -1,94 +0,0 @@
-dnl config.m4 for extension xslt
-dnl +------------------------------------------------------------------------------+
-dnl | This is where the magic of the extension reallly is. Depending on what |
-dnl | backend the user chooses, this script performs the magic |
-dnl +------------------------------------------------------------------------------+
-dnl $Id$
-
-PHP_ARG_ENABLE(xslt, whether to enable xslt support,
-[ --enable-xslt Enable xslt support])
-
-PHP_ARG_WITH(xslt-sablot, whether to enable the XSLT Sablotron backend,
-[ --with-xslt-sablot XSLT: Enable the sablotron backend])
-
-PHP_ARG_WITH(expat-dir, libexpat dir for Sablotron XSL support,
-[ --with-expat-dir=DIR Sablotron: libexpat dir for Sablotron 0.50])
-
-if test "$PHP_XSLT" != "no"; then
-
- PHP_EXTENSION(xslt, $ext_shared)
- PHP_SUBST(XSLT_SHARED_LIBADD)
-
- if test "$PHP_XSLT_SABLOT" != "no"; then
- XSLT_CHECK_DIR=$PHP_XSLT_SABLOT
- XSLT_TEST_FILE=/include/sablot.h
- XSLT_BACKEND_NAME=Sablotron
- XSLT_LIBNAME=sablot
- fi
-
- if test -z "$XSLT_BACKEND_NAME"; then
- AC_MSG_ERROR(No backend specified for XSLT extension.)
- fi
-
- condition="$XSLT_CHECK_DIR$XSLT_TEST_FILE"
-
- if test -r $condition; then
- XSLT_DIR=$XSLT_CHECK_DIR
- else
- AC_MSG_CHECKING(for $XSLT_BACKEND_NAME libraries in the default path)
- for i in /usr /usr/local; do
- condition="$i$XSLT_TEST_FILE"
- if test -r $condition; then
- XSLT_DIR=$i
- AC_MSG_RESULT(found $XSLT_BACKEND_NAME in $i)
- fi
- done
- fi
-
- if test -z "$XSLT_DIR"; then
- AC_MSG_ERROR(not found. Please re-install the $XSLT_BACKEND_NAME distribution)
- fi
-
- if test "$PHP_XSLT_SABLOT" != "no"; then
- found_expat=no
- for i in $PHP_EXPAT_DIR $XSLT_DIR; do
- if test -f $i/lib/libexpat.a -o -f $i/lib/libexpat.so; then
- AC_DEFINE(HAVE_LIBEXPAT2, 1, [ ])
- PHP_ADD_INCLUDE($i/include)
- PHP_ADD_LIBRARY_WITH_PATH(expat, $i/lib, XSLT_SHARED_LIBADD)
- found_expat=yes
- fi
- done
-
- if test "$found_expat" = "no"; then
- PHP_ADD_LIBRARY(xmlparse)
- PHP_ADD_LIBRARY(xmltok)
- fi
-
- found_iconv=no
- AC_CHECK_LIB(c, iconv_open, found_iconv=yes)
- if test "$found_iconv" = "no"; then
- if test "$PHP_ICONV" = "no"; then
- for i in /usr /usr/local; do
- if test -f $i/lib/libconv.a -o -f $i/lib/libiconv.so; then
- PHP_ADD_LIBRARY_WITH_PATH(iconv, $i/lib)
- found_iconv=yes
- fi
- done
- fi
- fi
-
- if test "$found_iconv" = "no"; then
- AC_MSG_ERROR(iconv not found, in order to build sablotron you need the iconv library)
- fi
-
- AC_DEFINE(HAVE_SABLOT_BACKEND, 1, [ ])
- AC_CHECK_LIB(sablot, SablotSetEncoding, AC_DEFINE(HAVE_SABLOT_SET_ENCODING, 1, [ ]))
-
- fi
-
- PHP_ADD_INCLUDE($XSLT_DIR/include)
- PHP_ADD_LIBRARY_WITH_PATH($XSLT_LIBNAME, $XSLT_DIR/lib, XSLT_SHARED_LIBADD)
-
- AC_DEFINE(HAVE_XSLT, 1, [ ])
-fi
diff --git a/ext/xslt/php_sablot.h b/ext/xslt/php_sablot.h
deleted file mode 100644
index 9a967e38d7..0000000000
--- a/ext/xslt/php_sablot.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sterling Hughes <sterling@php.net> |
- +----------------------------------------------------------------------+
- */
-
-#ifndef PHP_XSLT_H
-#define PHP_XSLT_H
-
-#include "php.h"
-
-#if HAVE_SABLOT_BACKEND
-
-#include "php_xslt.h"
-
-#include <sablot.h>
-
-extern zend_module_entry xslt_module_entry;
-#define phpext_xslt_ptr &xslt_module_entry
-
-#ifdef PHP_WIN32
-#define PHP_XSLT_API __declspec(dllexport)
-#else
-#define PHP_XSLT_API
-#endif
-
-#define XSLT_SCHEME(handle) ((handle)->handlers->scheme)
-#define XSLT_SAX(handle) ((handle)->handlers->sax)
-#define XSLT_ERROR(handle) ((handle)->handlers->error)
-
-#define XSLT_PROCESSOR(handle) ((handle)->processor.ptr)
-
-#define XSLT_ERRNO(handle) ((handle)->err->no)
-#define XSLT_ERRSTR(handle) ((handle)->err->str)
-#define XSLT_LOG(handle) ((handle)->err->log)
-
-#define XSLT_FUNCH_FREE(__var) if (__var) zval_ptr_dtor(&(__var));
-
-PHP_MINIT_FUNCTION(xslt);
-PHP_MINFO_FUNCTION(xslt);
-
-PHP_FUNCTION(xslt_create);
-PHP_FUNCTION(xslt_set_sax_handlers);
-PHP_FUNCTION(xslt_set_scheme_handlers);
-PHP_FUNCTION(xslt_set_error_handler);
-PHP_FUNCTION(xslt_set_base);
-PHP_FUNCTION(xslt_set_encoding);
-PHP_FUNCTION(xslt_set_log);
-PHP_FUNCTION(xslt_process);
-PHP_FUNCTION(xslt_error);
-PHP_FUNCTION(xslt_errno);
-PHP_FUNCTION(xslt_free);
-
-struct scheme_handlers {
- zval *get_all;
- zval *open;
- zval *get;
- zval *put;
- zval *close;
-};
-
-struct sax_handlers {
- zval *doc_start;
- zval *element_start;
- zval *element_end;
- zval *namespace_start;
- zval *namespace_end;
- zval *comment;
- zval *pi;
- zval *characters;
- zval *doc_end;
-};
-
-struct xslt_handlers {
- struct scheme_handlers scheme;
- struct sax_handlers sax;
- zval *error;
-};
-
-struct xslt_processor {
- SablotHandle ptr;
- long idx;
-};
-
-struct xslt_log {
- char *path;
- int fd;
- int do_log;
-};
-
-struct xslt_error {
- struct xslt_log log;
- char *str;
- int no;
-};
-
-typedef struct {
- struct xslt_handlers *handlers;
- struct xslt_processor processor;
- struct xslt_error *err;
-} php_xslt;
-
-#else
-#define phpext_xslt_ptr NULL
-#endif
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/ext/xslt/php_xslt.h b/ext/xslt/php_xslt.h
deleted file mode 100644
index 73ef3ee18c..0000000000
--- a/ext/xslt/php_xslt.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sterling Hughes <sterling@php.net> |
- +----------------------------------------------------------------------+
- */
-
-#ifndef _PHP_XSLT_H
-#define _PHP_XSLT_H
-
-#include "php.h"
-#include "ext/standard/php_filestat.h"
-
-#ifdef HAVE_XSLT
-
-#define XSLT_OBJ(__func) (&(__func)->obj)
-#define XSLT_FUNC(__func) ((__func)->func)
-
-#define XSLT_IS_FILE 0
-#define XSLT_IS_DATA 1
-
-struct xslt_function {
- zval *obj;
- zval *func;
-};
-
-struct _xslt_argument {
- char *ptr;
- int type;
-};
-
-typedef struct {
- struct _xslt_argument xml;
- struct _xslt_argument xsl;
- struct _xslt_argument result;
-} xslt_args;
-
-extern xslt_args *xslt_parse_arguments(char *, char *, char *, char **);
-extern void xslt_free_arguments(xslt_args *);
-
-extern void xslt_assign_handler(struct xslt_function **, zval **);
-extern void xslt_free_handler(struct xslt_function *);
-extern void xslt_call_function(char *, zval *, int, zval **, zval **);
-
-extern void xslt_debug(char *, char *, ...);
-
-extern void xslt_make_array(zval **zarr, char ***carr);
-extern void xslt_free_array(char **arr);
-
-#endif
-
-#endif
diff --git a/ext/xslt/sablot.c b/ext/xslt/sablot.c
deleted file mode 100644
index f439311555..0000000000
--- a/ext/xslt/sablot.c
+++ /dev/null
@@ -1,1573 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sterling Hughes <sterling@php.net> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "php.h"
-#include "php_xslt.h"
-#include "php_sablot.h"
-#include "ext/standard/info.h"
-
-#if HAVE_SABLOT_BACKEND
-
-#include <sablot.h>
-
-#include <string.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-/* functions relating to handlers */
-static void register_sax_handler_pair(zval *, zval *, zval **);
-
-/* Free processor */
-static void free_processor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
-
-/* Scheme handler functions */
-static int scheme_getall(void *, SablotHandle, const char *, const char *, char **, int *);
-static int scheme_freememory(void *, SablotHandle, char *);
-static int scheme_open(void *, SablotHandle, const char *, const char *, int *);
-static int scheme_get(void *, SablotHandle, int, char *, int *);
-static int scheme_put(void *, SablotHandle, int, const char *, int *);
-static int scheme_close(void *, SablotHandle, int);
-
-/* Sax handler functions */
-static SAX_RETURN sax_startdoc(void *);
-static SAX_RETURN sax_startelement(void *, const char *, const char **);
-static SAX_RETURN sax_endelement(void *, const char *);
-static SAX_RETURN sax_startnamespace(void *, const char *, const char *);
-static SAX_RETURN sax_endnamespace(void *, const char *);
-static SAX_RETURN sax_comment(void *, const char *);
-static SAX_RETURN sax_pi(void *, const char *, const char *);
-static SAX_RETURN sax_characters(void *, const char *, int);
-static SAX_RETURN sax_enddoc(void *);
-
-/* Error handlers */
-static MH_ERROR error_makecode(void *, SablotHandle, int, unsigned short, unsigned short);
-static MH_ERROR error_log(void *, SablotHandle, MH_ERROR, MH_LEVEL, char **);
-static MH_ERROR error_print(void *, SablotHandle, MH_ERROR, MH_LEVEL, char **);
-
-/* Resource related */
-#define le_xslt_name "XSLT Processor"
-static int le_xslt;
-
-/* {{{ xslt_functions[]
- */
-function_entry xslt_functions[] = {
- PHP_FE(xslt_create, NULL)
- PHP_FE(xslt_set_sax_handlers, NULL)
- PHP_FE(xslt_set_scheme_handlers, NULL)
- PHP_FE(xslt_set_error_handler, NULL)
- PHP_FE(xslt_set_base, NULL)
-#ifdef HAVE_SABLOT_SET_ENCODING
- PHP_FE(xslt_set_encoding, NULL)
-#else
- PHP_FALIAS(xslt_set_encoding, warn_not_available, NULL)
-#endif
- PHP_FE(xslt_set_log, NULL)
- PHP_FE(xslt_process, NULL)
- PHP_FE(xslt_error, NULL)
- PHP_FE(xslt_errno, NULL)
- PHP_FE(xslt_free, NULL)
-};
-/* }}} */
-
-/* {{{ xslt_module_entry
- */
-zend_module_entry xslt_module_entry = {
- "xslt",
- xslt_functions,
- PHP_MINIT(xslt),
- NULL,
- NULL,
- NULL,
- PHP_MINFO(xslt),
- STANDARD_MODULE_PROPERTIES
-};
-/* }}} */
-
-#ifdef COMPILE_DL_XSLT
-ZEND_GET_MODULE(xslt)
-#endif
-
-/* {{{ handler structs
- A structure containing the sax handlers, automatically
- registered whether the user defines them or not */
-static SAXHandler sax_handlers =
-{
- sax_startdoc,
- sax_startelement,
- sax_endelement,
- sax_startnamespace,
- sax_endnamespace,
- sax_comment,
- sax_pi,
- sax_characters,
- sax_enddoc
-};
-
-/* Error handlers, automatically registered */
-static MessageHandler message_handler = {
- error_makecode,
- error_log,
- error_print
-};
-
-/* Scheme handlers automatically registered */
-static SchemeHandler scheme_handler = {
- scheme_getall,
- scheme_freememory,
- scheme_open,
- scheme_get,
- scheme_put,
- scheme_close
-};
-/* }}} */
-
-/* {{{ PHP_MINIT_FUNCTION
- */
-PHP_MINIT_FUNCTION(xslt)
-{
- le_xslt = zend_register_list_destructors_ex(free_processor, NULL, le_xslt_name, module_number);
- return SUCCESS;
-}
-/* }}} */
-
-/* {{{ PHP_MINFO_FUNCTION
- */
-PHP_MINFO_FUNCTION(xslt)
-{
- php_info_print_table_start();
- php_info_print_table_header(2, "XSLT support", "enabled");
- php_info_print_table_end();
-}
-/* }}} */
-
-/* {{{ proto resource xslt_create(void)
- Create a new XSLT processor */
-PHP_FUNCTION(xslt_create)
-{
- php_xslt *handle; /* The php -> sablotron handle */
- SablotHandle processor; /* The sablotron processor */
- int error; /* The error container */
-
- /* Allocate the php-sablotron handle */
- handle = ecalloc(1, sizeof(php_xslt));
- handle->handlers = ecalloc(1, sizeof(struct xslt_handlers));
- handle->err = ecalloc(1, sizeof(struct xslt_error));
-
- XSLT_LOG(handle).path = NULL;
-
- /* Allocate the actual processor itself, via sablotron */
- error = SablotCreateProcessor(&processor);
- if (error) {
- XSLT_ERRNO(handle) = error;
- RETURN_FALSE;
- }
-
- /* Save the processor and set the default handlers */
- XSLT_PROCESSOR(handle) = processor;
- SablotRegHandler(XSLT_PROCESSOR(handle), HLR_SAX, (void *) &sax_handlers, (void *) handle);
- SablotRegHandler(XSLT_PROCESSOR(handle), HLR_MESSAGE, (void *) &message_handler, (void *) handle);
- SablotRegHandler(XSLT_PROCESSOR(handle), HLR_SCHEME, (void *) &scheme_handler, (void *) handle);
-
- /* Register the processor as a resource and return it to the user */
- ZEND_REGISTER_RESOURCE(return_value, handle, le_xslt);
-
- /* The resource index, save it for later use */
- handle->processor.idx = Z_LVAL_P(return_value);
-}
-/* }}} */
-
-/* {{{ proto void xslt_set_sax_handlers(resource processor, array handlers)
- Set the SAX handlers to be called when the XML document gets processed */
-PHP_FUNCTION(xslt_set_sax_handlers)
-{
- zval **processor_p, /* Resource pointer to the php->sablotron handle */
- **sax_handlers_p, /* Pointer to the sax handlers php array */
- **handler; /* Individual handler, or handler pair */
- HashTable *sax_handlers; /* PHP array of sax handlers */
- php_xslt *handle; /* Pointer to a php_xslt handle */
- char *string_key; /* String key for the hash */
- ulong num_key; /* (unused) hash's numerical key */
- int key_type; /* The type of the current hash key */
-
- if (ZEND_NUM_ARGS() != 2 ||
- zend_get_parameters_ex(2, &processor_p, &sax_handlers_p) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
-
- /* Convert the sax_handlers_p zval ** to a hash table we can process */
- sax_handlers = HASH_OF(*sax_handlers_p);
- if (!sax_handlers) {
- php_error(E_WARNING, "Expecting an array as the second argument to xslt_set_sax_handlers()");
- return;
- }
-
- /* Loop through the HashTable containing the SAX handlers */
- for (zend_hash_internal_pointer_reset(sax_handlers);
- zend_hash_get_current_data(sax_handlers, (void **) &handler) == SUCCESS;
- zend_hash_move_forward(sax_handlers)) {
-
- /* Allocate the handler */
- SEPARATE_ZVAL(handler);
-
- key_type = zend_hash_get_current_key(sax_handlers, &string_key, &num_key, 0);
- if (key_type == HASH_KEY_IS_LONG) {
- convert_to_string_ex(handler);
- php_error(E_NOTICE, "Skipping numerical index %d (with value %s) in xslt_set_sax_handlers()",
- num_key, Z_STRVAL_PP(handler));
- continue;
- }
-
- /* Document handlers (document start, document end) */
- if (strcasecmp(string_key, "document") == 0) {
- register_sax_handler_pair(XSLT_SAX(handle).doc_start,
- XSLT_SAX(handle).doc_end,
- handler);
- }
- /* Element handlers, start of an element, and end of an element */
- else if (strcasecmp(string_key, "element") == 0) {
- register_sax_handler_pair(XSLT_SAX(handle).element_start,
- XSLT_SAX(handle).element_end,
- handler);
- }
- /* Namespace handlers, start of a namespace, end of a namespace */
- else if (strcasecmp(string_key, "namespace") == 0) {
- register_sax_handler_pair(XSLT_SAX(handle).namespace_start,
- XSLT_SAX(handle).namespace_end,
- handler);
- }
- /* Comment handlers, called when a comment is reached */
- else if (strcasecmp(string_key, "comment") == 0) {
- XSLT_SAX(handle).comment = *handler;
- zval_add_ref(&XSLT_SAX(handle).comment);
- }
- /* Processing instructions handler called when processing instructions
- (<? ?>) */
- else if (strcasecmp(string_key, "pi") == 0) {
- XSLT_SAX(handle).pi = *handler;
- zval_add_ref(&XSLT_SAX(handle).pi);
- }
- /* Character handler, called when data is found */
- else if (strcasecmp(string_key, "character") == 0) {
- XSLT_SAX(handle).characters = *handler;
- zval_add_ref(&XSLT_SAX(handle).characters);
- }
- /* Invalid handler name, tsk, tsk, tsk :) */
- else {
- php_error(E_WARNING, "Invalid option to xslt_set_sax_handlers(): %s", string_key);
- }
- }
-}
-/* }}} */
-
-/* {{{ proto void xslt_set_scheme_handlers(resource processor, array handlers)
- Set the scheme handlers for the XSLT processor */
-PHP_FUNCTION(xslt_set_scheme_handlers)
-{
- zval **processor_p, /* Resource pointer to the php->sablotron handle */
- **scheme_handlers_p, /* Pointer to the scheme handler array */
- **handler; /* Individual scheme handler */
- zval *assign_handle; /* The handler to assign to */
- HashTable *scheme_handlers; /* Scheme handler array */
- php_xslt *handle; /* php->sablotron handle */
- char *string_key; /* Hash key (string) */
- ulong num_key; /* (unused) Hash key (number) */
- int key_type; /* The type of the current key */
-
- if (ZEND_NUM_ARGS() != 2 ||
- zend_get_parameters_ex(2, &processor_p, &scheme_handlers_p) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
-
- scheme_handlers = HASH_OF(*scheme_handlers_p);
- if (!scheme_handlers) {
- php_error(E_WARNING, "2nd argument to xslt_set_scheme_handlers() must be an array");
- return;
- }
-
- /* Loop through the scheme handlers array, setting the given
- scheme handlers */
- for (zend_hash_internal_pointer_reset(scheme_handlers);
- zend_hash_get_current_data(scheme_handlers, (void **) &handler) == SUCCESS;
- zend_hash_move_forward(scheme_handlers)) {
-
- SEPARATE_ZVAL(handler);
-
- key_type = zend_hash_get_current_key(scheme_handlers, &string_key, &num_key, 0);
- if (key_type == HASH_KEY_IS_LONG) {
- php_error(E_NOTICE, "Numerical key %d (with value %s) being ignored in xslt_set_scheme_handlers()",
- num_key, Z_STRVAL_PP(handler));
- continue;
- }
-
- /* Open the URI and return the whole string */
- if (strcasecmp(string_key, "get_all") == 0) {
- assign_handle = XSLT_SCHEME(handle).get_all;
- }
- /* Open the URI and return a handle */
- else if (strcasecmp(string_key, "open") == 0) {
- assign_handle = XSLT_SCHEME(handle).open;
- }
- /* Retrieve data from the URI */
- else if (strcasecmp(string_key, "get") == 0) {
- assign_handle = XSLT_SCHEME(handle).get;
- }
- /* Save data to the URI */
- else if (strcasecmp(string_key, "put") == 0) {
- assign_handle = XSLT_SCHEME(handle).put;
- }
- /* Close the URI */
- else if (strcasecmp(string_key, "close") == 0) {
- assign_handle = XSLT_SCHEME(handle).close;
- }
- /* Invalid handler name */
- else {
- php_error(E_WARNING, "Invalid option to xslt_set_scheme_handlers(): %s", string_key);
- }
-
- assign_handle = *handler;
- zval_add_ref(&assign_handle);
- }
-}
-/* }}} */
-
-/* {{{ proto void xslt_set_error_handler(resource processor, mixed error_func)
- Set the error handler, to be called when an XSLT error happens */
-PHP_FUNCTION(xslt_set_error_handler)
-{
- zval **processor_p, /* Resource Pointer to a PHP-XSLT processor */
- **error_func; /* Name of the user defined error function */
- php_xslt *handle; /* A PHP-XSLT processor */
-
- if (ZEND_NUM_ARGS() != 2 ||
- zend_get_parameters_ex(2, &processor_p, &error_func) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
-
- XSLT_ERROR(handle) = *error_func;
- zval_add_ref(&XSLT_ERROR(handle));
-}
-/* }}} */
-
-/* {{{ proto void xslt_set_base(resource processor, string base)
- Sets the base URI for all XSLT transformations */
-PHP_FUNCTION(xslt_set_base)
-{
- zval **processor_p, /* Resource Pointer to a PHP-XSLT processor */
- **base; /* The base URI for the transformation */
- php_xslt *handle; /* A PHP-XSLT processor */
-
- if (ZEND_NUM_ARGS() != 2 ||
- zend_get_parameters_ex(2, &processor_p, &base) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
- convert_to_string_ex(base);
-
- /* Set the base */
- SablotSetBase(XSLT_PROCESSOR(handle), Z_STRVAL_PP(base));
-}
-/* }}} */
-
-/* {{{ proto void xslt_set_encoding(resource processor, string encoding)
- Set the output encoding for the current stylesheet */
-PHP_FUNCTION(xslt_set_encoding)
-{
-/* The user has to explicitly compile sablotron with sablotron
- encoding functions in order for SablotSetEncoding to be
- enabled. config.m4 automatically checks for this... */
-
-#ifdef HAVE_SABLOT_SET_ENCODING
- zval **processor_p, /* Resource Pointer to a PHP-XSLT processor */
- **encoding; /* The encoding to use for the output */
- php_xslt *handle; /* A PHP-XSLT processor */
-
- if (ZEND_NUM_ARGS() != 2 ||
- zend_get_parameters_ex(2, &processor_p, &encoding) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
- convert_to_string_ex(encoding);
-
- /* Set the encoding */
- SablotSetEncoding(XSLT_PROCESSOR(handle), Z_STRVAL_PP(encoding));
-#endif
-
-}
-/* }}} */
-
-/* {{{ proto void xslt_set_log(resource processor, string logfile)
- Set the log file to write the errors to (defaults to stderr) */
-PHP_FUNCTION(xslt_set_log)
-{
- zval **processor_p, /* Resource pointer to a PHP-XSLT processor */
- **logfile; /* Path to the logfile */
- php_xslt *handle; /* A PHP-XSLT processor */
- int argc = ZEND_NUM_ARGS(); /* Argument count */
-
- if (argc < 1 || argc > 2 ||
- zend_get_parameters_ex(argc, &processor_p, &logfile) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
-
- if (Z_TYPE_PP(logfile) == IS_LONG || Z_TYPE_PP(logfile) == IS_BOOL || Z_TYPE_PP(logfile) == IS_DOUBLE) {
- XSLT_LOG(handle).do_log = Z_LVAL_PP(logfile);
- RETURN_NULL();
- }
- else {
- convert_to_string_ex(logfile);
- }
-
- /* If the log file already exists, free it */
- if (XSLT_LOG(handle).path) {
- efree(XSLT_LOG(handle).path);
- }
-
- /* Copy the path */
- XSLT_LOG(handle).path = estrndup(Z_STRVAL_PP(logfile),
- Z_STRLEN_PP(logfile));
-}
-/* }}} */
-
-/* {{{ proto string xslt_process(resource processor, string xml, string xslt[, mixed result[, array args[, array params]]])
- Perform the xslt transformation */
-PHP_FUNCTION(xslt_process)
-{
- zval **processor_p, /* Resource Pointer to a PHP-XSLT processor */
- **xml_p, /* A zval pointer to the XML data */
- **xslt_p, /* A zval pointer to the XSLT data */
- **result_p, /* A zval pointer to the transformation results */
- **params_p, /* A zval pointer to the XSLT parameters array */
- **args_p; /* A zval pointer to the XSLT arguments array */
- php_xslt *handle; /* A PHP-XSLT processor */
- char **params = NULL; /* A Sablotron parameter array (derived from the zval parameter array) */
- char **args = NULL; /* A Sablotron argument array (derived from the zval argument array) */
- char *xslt; /* The XSLT stylesheet or argument buffer (pointer to xslt_p) */
- char *xml; /* The XML stylesheet or argument buffer (pointer to xml_p) */
- char *result; /* The result file or argument buffer */
- int argc = ZEND_NUM_ARGS(); /* The number of arguments given */
- int error; /* Our error container */
-
- if (argc < 3 || argc > 6 ||
- zend_get_parameters_ex(argc, &processor_p, &xml_p, &xslt_p, &result_p, &args_p, &params_p) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
- convert_to_string_ex(xml_p);
- convert_to_string_ex(xslt_p);
-
- xml = Z_STRVAL_PP(xml_p);
- xslt = Z_STRVAL_PP(xslt_p);
-
- /* Well, no result file was given or result buffer, that means (guess what?)
- we're returning the result yipp di doo! */
- if (argc < 4 || Z_TYPE_PP(result_p) == IS_NULL) {
- result = "arg:/_result";
- }
- /* The result buffer to place the data into, either a file or an argument buffer, etc. */
- else {
- convert_to_string_ex(result_p);
- result = Z_STRVAL_PP(result_p);
- }
-
- /* Translate a PHP array into a Sablotron array */
- if (argc > 4) {
- xslt_make_array(args_p, &args);
- }
-
- if (argc > 5) {
- xslt_make_array(params_p, &params);
- }
-
- /* Perform transformation */
- error = SablotRunProcessor(XSLT_PROCESSOR(handle), xslt, xml, result, params, args);
- if (error) {
- XSLT_ERRNO(handle) = error;
-
- if (params) xslt_free_array(params);
- if (args) xslt_free_array(args);
-
- RETURN_FALSE;
- }
-
- /* If the result buffer is specified, then we return the results of the XSLT
- transformation */
- if (!strcmp(result, "arg:/_result")) {
- char *trans_result;
-
- /* Fetch the result buffer into trans_result */
- error = SablotGetResultArg(handle->processor.ptr, "arg:/_result", &trans_result);
- if (error) {
- /* Save the error number */
- XSLT_ERRNO(handle) = error;
-
- /* Cleanup */
- if (params) xslt_free_array(params);
- if (args) xslt_free_array(args);
-
- RETURN_FALSE;
- }
-
- RETVAL_STRING(trans_result, 1);
- SablotFree(trans_result);
- }
- else {
- RETVAL_TRUE;
- }
-
- /* Cleanup */
- if (params) xslt_free_array(params);
- if (args) xslt_free_array(args);
-}
-/* }}} */
-
-/* {{{ proto int xslt_errno(resource processor)
- Error number */
-PHP_FUNCTION(xslt_errno)
-{
- zval **processor_p; /* Resource pointer to a PHP-XSLT processor */
- php_xslt *handle; /* A PHP-XSLT processor */
-
- if (ZEND_NUM_ARGS() != 1 ||
- zend_get_parameters_ex(1, &processor_p) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
-
- RETURN_LONG(XSLT_ERRNO(handle));
-}
-/* }}} */
-
-/* {{{ proto string xslt_error(resource processor)
- Error string */
-PHP_FUNCTION(xslt_error)
-{
- zval **processor_p; /* Resource pointer to a PHP-XSLT processor */
- php_xslt *handle; /* A PHP-XSLT processor */
-
- if (ZEND_NUM_ARGS() != 1 ||
- zend_get_parameters_ex(1, &processor_p) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
-
- RETURN_STRING(XSLT_ERRSTR(handle), 1);
-}
-/* }}} */
-
-/* {{{ proto void xslt_free(resource processor)
- Free the xslt processor up */
-PHP_FUNCTION(xslt_free)
-{
- zval **processor_p; /* Resource pointer to a php-xslt processor */
- php_xslt *handle; /* A PHP-XSLT processor */
-
- if (ZEND_NUM_ARGS() != 1 ||
- zend_get_parameters_ex(1, &processor_p) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt);
-
- /* Remove the entry from the list */
- zend_list_delete(Z_LVAL_PP(processor_p));
-}
-/* }}} */
-
-/* {{{ free_processor()
- Free an XSLT processor */
-static void free_processor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
-{
- php_xslt *handle = (php_xslt *) rsrc->ptr; /* A PHP-XSLT processor */
-
- /* Free the processor */
- if (XSLT_PROCESSOR(handle)) {
- SablotUnregHandler(XSLT_PROCESSOR(handle), HLR_MESSAGE, NULL, NULL);
- SablotUnregHandler(XSLT_PROCESSOR(handle), HLR_SAX, NULL, NULL);
- SablotUnregHandler(XSLT_PROCESSOR(handle), HLR_SCHEME, NULL, NULL);
- SablotDestroyProcessor(XSLT_PROCESSOR(handle));
- }
-
- /* Free Scheme handlers */
- XSLT_FUNCH_FREE(XSLT_SCHEME(handle).get_all);
- XSLT_FUNCH_FREE(XSLT_SCHEME(handle).open);
- XSLT_FUNCH_FREE(XSLT_SCHEME(handle).get);
- XSLT_FUNCH_FREE(XSLT_SCHEME(handle).put);
- XSLT_FUNCH_FREE(XSLT_SCHEME(handle).close);
- /* Free SAX handlers */
- XSLT_FUNCH_FREE(XSLT_SAX(handle).doc_start);
- XSLT_FUNCH_FREE(XSLT_SAX(handle).element_start);
- XSLT_FUNCH_FREE(XSLT_SAX(handle).element_end);
- XSLT_FUNCH_FREE(XSLT_SAX(handle).namespace_start);
- XSLT_FUNCH_FREE(XSLT_SAX(handle).namespace_end);
- XSLT_FUNCH_FREE(XSLT_SAX(handle).comment);
- XSLT_FUNCH_FREE(XSLT_SAX(handle).pi);
- XSLT_FUNCH_FREE(XSLT_SAX(handle).characters);
- XSLT_FUNCH_FREE(XSLT_SAX(handle).doc_end);
- /* Free error handler */
- XSLT_FUNCH_FREE(XSLT_ERROR(handle));
-
- /* Free error message, if any */
- if (XSLT_ERRSTR(handle)) {
- efree(XSLT_ERRSTR(handle));
- }
-
- /* Close log file */
- if (XSLT_LOG(handle).fd) {
- close(XSLT_LOG(handle).fd);
- }
-
- /* Free log file path */
- if (XSLT_LOG(handle).path) {
- efree(XSLT_LOG(handle).path);
- }
-
- /* Free up the handle */
- efree(handle->handlers);
- efree(handle->err);
- efree(handle);
-}
-/* }}} */
-
-/* {{{ register_sax_handler_pair()
- Register a pair of sax handlers */
-static void register_sax_handler_pair(zval *handler1, zval *handler2, zval **handler)
-{
- zval **current; /* The current handler we're grabbing */
-
- /* Grab and assign handler 1 */
- if (zend_hash_index_find(Z_ARRVAL_PP(handler), 0, (void **) &current) == SUCCESS) {
- handler1 = *current;
- zval_add_ref(&handler1);
- }
- else {
- php_error(E_WARNING, "Wrong format of arguments to xslt_set_sax_handlers()");
- return;
- }
-
- /* Grab and assign handler 2 */
- if (zend_hash_index_find(Z_ARRVAL_PP(handler), 1, (void **) &current) == SUCCESS) {
- handler2 = *current;
- zval_add_ref(&handler2);
- }
- else {
- php_error(E_WARNING, "Wrong format of arguments to xslt_set_sax_handlers()");
- return;
- }
-}
-/* }}} */
-
-/* {{{ scheme_getall()
- The getall scheme handler */
-static int scheme_getall(void *user_data, SablotHandle proc, const char *scheme, const char *rest, char **buffer, int *byte_count)
-{
- zval *argv[3]; /* Arguments to the scheme getall function */
- zval *retval; /* Return value from the scheme getall function */
- php_xslt *handle = (php_xslt *) user_data; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If the scheme handler get all function doesn't
- exist, exit out */
- if (!XSLT_SCHEME(handle).get_all) {
- return 0;
- }
-
- /* Allocate and initialize */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
- MAKE_STD_ZVAL(argv[2]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: Scheme (string)
- Argument 3: Rest (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRING(argv[1], (char *) scheme, 1);
- ZVAL_STRING(argv[2], (char *) rest, 1);
-
- xslt_call_function("scheme get all", XSLT_SCHEME(handle).get_all,
- 3, argv, &retval);
-
- /* Save the return value in the buffer (copying it) */
- *buffer = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
- *byte_count = Z_STRLEN_P(retval);
-
- /* Free return value */
- zval_ptr_dtor(&retval);
-
- return 0;
-}
-/* }}} */
-
-/* {{{ scheme_handler_is_registered()
- Check to see if the scheme handler is registered with the user */
-static int scheme_handler_is_registered(php_xslt *handle)
-{
- /* If one of the functions is exists, then scheme
- handlers are registered */
- if (XSLT_SCHEME(handle).get_all ||
- XSLT_SCHEME(handle).open ||
- XSLT_SCHEME(handle).get ||
- XSLT_SCHEME(handle).put ||
- XSLT_SCHEME(handle).close)
- return 1;
- /* otherwise, no cigar */
- else
- return 0;
-}
-/* }}} */
-
-/* {{{ scheme_freememory()
- Called when sablotron needs to free memory related to scheme handling */
-static int scheme_freememory(void *user_data, SablotHandle proc, char *buffer)
-{
- /* If we don't have any scheme handler's registered, then emalloc() wasn't
- used, and if emalloc() wasn't then efree shouldn't be used */
- if (!scheme_handler_is_registered((php_xslt *) user_data)) {
- return 0;
- }
-
- /* Free the memory using efree() and remove it from the register */
- efree(buffer);
-
- return 0;
-}
-/* }}} */
-
-/* {{{ scheme_open()
- Called when the URI needs to be opened */
-static int scheme_open(void *user_data, SablotHandle proc, const char *scheme, const char *rest, int *fd)
-{
- zval *argv[3]; /* Arguments to the scheme open function */
- zval *retval; /* The return value from the scheme open function */
- php_xslt *handle = (php_xslt *) user_data; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If no open handler exists, let's exit */
- if (!XSLT_SCHEME(handle).open) {
- return 0;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
- MAKE_STD_ZVAL(argv[2]);
-
- /* Argument 1: XSLT Processor (resource)
- Argument 2: Scheme (string)
- Argument 3: Rest (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRING(argv[1], (char *) scheme, 1);
- ZVAL_STRING(argv[2], (char *) rest, 1);
-
- /* Call the function */
- xslt_call_function("scheme open", XSLT_SCHEME(handle).open,
- 3, argv, &retval);
-
- /* Return value is a resource pointer to an open file */
- *fd = Z_LVAL_P(retval);
-
- /* Free it all up */
- zval_ptr_dtor(&retval);
-
- /* return success */
- return 0;
-}
-/* }}} */
-
-/* {{{ scheme_get()
- Called when data needs to be fetched from the URI */
-static int scheme_get(void *user_data, SablotHandle proc, int fd, char *buffer, int *byte_count)
-{
- zval *argv[3]; /* Arguments to the scheme get function */
- zval *retval; /* Return value from the scheme get function */
- php_xslt *handle = (php_xslt *) user_data; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If no get handler exists, let's exit */
- if (!XSLT_SCHEME(handle).get) {
- return 0;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
- MAKE_STD_ZVAL(argv[2]);
-
- /* Argument 1: XSLT Processor (resource)
- Argument 2: File Pointer (resource)
- Argument 3: Data (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_RESOURCE(argv[1], fd);
- zend_list_addref(fd);
- ZVAL_STRINGL(argv[2], buffer, *byte_count, 0);
-
- /* Call the function */
- xslt_call_function("scheme get", XSLT_SCHEME(handle).get,
- 3, argv, &retval);
-
- /* Returns the number of bytes read */
- *byte_count = Z_LVAL_P(retval);
-
- /* Free things up */
- zval_ptr_dtor(&retval);
-
- /* return success */
- return 0;
-}
-/* }}} */
-
-/* {{{ scheme_put()
- Called when data needs to be written */
-static int scheme_put(void *user_data, SablotHandle proc, int fd, const char *buffer, int *byte_count)
-{
- zval *argv[3]; /* Arguments to the scheme put function */
- zval *retval; /* Return value from the scheme put function */
- php_xslt *handle = (php_xslt *) user_data; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If no put handler exists, let's exit */
- if (!XSLT_SCHEME(handle).put) {
- return 0;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
- MAKE_STD_ZVAL(argv[2]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: File pointer (resource)
- Argument 3: Data (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_RESOURCE(argv[1], fd);
- zend_list_addref(fd);
- ZVAL_STRINGL(argv[2], (char *) buffer, *byte_count, 1);
-
- /* Call the scheme put function already */
- xslt_call_function("scheme put", XSLT_SCHEME(handle).put,
- 3, argv, &retval);
-
- /* The return value is the number of bytes written */
- *byte_count = Z_LVAL_P(retval);
-
- /* Free everything up */
- zval_ptr_dtor(&retval);
-
- /* Return success */
- return 0;
-}
-/* }}} */
-
-/* {{{ scheme_close()
- Called when its time to close the fd */
-static int scheme_close(void *user_data, SablotHandle proc, int fd)
-{
- zval *argv[2]; /* Arguments to the scheme close function*/
- zval *retval; /* Return value from the scheme close function */
- php_xslt *handle = (php_xslt *) user_data; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* if no close handler exists, exit */
- if (!XSLT_SCHEME(handle).close) {
- return 0;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: File pointer (resource)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_RESOURCE(argv[1], fd);
- zend_list_addref(fd);
-
- /* Call the scheme handler close function */
- xslt_call_function("scheme close", XSLT_SCHEME(handle).close,
- 2, argv, &retval);
-
- /* Free everything up */
- zval_ptr_dtor(&retval);
-
- /* Return success */
- return 0;
-}
-/* }}} */
-
-/* {{{ sax_startdoc()
- Called when the document starts to be processed */
-static SAX_RETURN sax_startdoc(void *ctx)
-{
- zval *argv[1]; /* Arguments to the sax start doc function */
- zval *retval; /* Return value from sax start doc function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* if no document start function exists, exit */
- if (!XSLT_SAX(handle).doc_start) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
-
- /* Argument 1: XSLT processor (resource) */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
-
- /* Call the Sax start doc function */
- xslt_call_function("sax start doc", XSLT_SAX(handle).doc_start,
- 1, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ sax_startelement()
- Called when an element is begun to be processed */
-static SAX_RETURN sax_startelement(void *ctx,
- const char *name,
- const char **attr)
-{
- zval *argv[3]; /* Arguments to the sax start element function */
- zval *retval; /* Return value from the sax start element function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- char **p; /* Pointer to attributes */
- TSRMLS_FETCH();
-
- /* If no element start function is found, exit */
- if (!XSLT_SAX(handle).element_start) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
- MAKE_STD_ZVAL(argv[2]);
- array_init(argv[2]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: Element name (string)
- Argument 3: Element attributes (array)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRING(argv[1], (char *) name, 1);
-
- /* loop through the attributes array, copying it onto our
- php array */
- p = (char **) attr;
- while (p && *p) {
- add_assoc_string(argv[2], *p, *(p + 1), 1);
- p += 2;
- }
-
- /* Call the sax element start function */
- xslt_call_function("sax start element", XSLT_SAX(handle).element_start,
- 3, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ xslt_sax_endelement()
- Called when an ending XML element is encountered */
-static SAX_RETURN sax_endelement(void *ctx, const char *name)
-{
- zval *argv[2]; /* Arguments to the sax end element function */
- zval *retval; /* Return value from the sax end element function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If no element end function exists, exit */
- if (!XSLT_SAX(handle).element_end) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: Element name (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRING(argv[1], (char *) name, 1);
-
- /* Call the sax end element function */
- xslt_call_function("sax end element", XSLT_SAX(handle).element_end,
- 2, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ sax_startnamespace()
- Called at the beginning of the parsing of a new namespace */
-static SAX_RETURN sax_startnamespace(void *ctx,
- const char *prefix,
- const char *uri)
-{
- zval *argv[3]; /* Arguments to the sax start namespace function */
- zval *retval; /* Return value from the sax start namespace function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* if no namespace start function exists, exit */
- if (!XSLT_SAX(handle).namespace_start) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
- MAKE_STD_ZVAL(argv[2]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: Prefix (string)
- Argument 3: URI (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRING(argv[1], (char *) prefix, 1);
- ZVAL_STRING(argv[2], (char *) uri, 1);
-
- /* Call the sax start namespace function */
- xslt_call_function("sax start namespace", XSLT_SAX(handle).namespace_start,
- 3, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ sax_endnamespace()
- Called when a new namespace is finished being parsed */
-static SAX_RETURN sax_endnamespace(void *ctx, const char *prefix)
-{
- zval *argv[2]; /* Arguments to the sax end namespace function */
- zval *retval; /* Return value from the sax end namespace function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If no namespace end function exists, exit */
- if (!XSLT_SAX(handle).namespace_end) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: Prefix (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRING(argv[1], (char *) prefix, 1);
-
- /* Call the sax end namespace function */
- xslt_call_function("sax end namespace", XSLT_SAX(handle).namespace_end,
- 2, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ sax_comment()
- Called when a comment is found */
-static SAX_RETURN sax_comment(void *ctx, const char *contents)
-{
- zval *argv[2]; /* Arguments to the sax comment function */
- zval *retval; /* Return value from the sax comment function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* if no comment function exists, exit */
- if (!XSLT_SAX(handle).comment) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: Comment contents (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRING(argv[1], (char *) contents, 1);
-
- /* Call the sax comment function */
- xslt_call_function("sax comment", XSLT_SAX(handle).comment,
- 2, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ sax_pi()
- Called when processing instructions are found */
-static SAX_RETURN sax_pi(void *ctx,
- const char *target,
- const char *contents)
-{
- zval *argv[3]; /* Arguments to the sax processing instruction function */
- zval *retval; /* Return value from the sax processing instruction function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If no processing instructions function exists, exit */
- if (!XSLT_SAX(handle).pi) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
- MAKE_STD_ZVAL(argv[2]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: Target of the pi (string)
- Argument 3: Contents of the pi (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRING(argv[1], (char *) target, 1);
- ZVAL_STRING(argv[2], (char *) contents, 1);
-
- /* Call processing instructions function */
- xslt_call_function("sax processing instructions", XSLT_SAX(handle).pi,
- 3, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ sax_characters()
- Called when characters are come upon */
-static SAX_RETURN sax_characters(void *ctx,
- const char *contents,
- int length)
-{
- zval *argv[2]; /* Arguments to the sax characters function */
- zval *retval; /* Return value to the sax characters function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If no characters function exists, exit */
- if (!XSLT_SAX(handle).characters) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
-
- /* Argument 1: XSLT processor (resource)
- Argument 2: Contents (string)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_STRINGL(argv[1], (char *) contents, length, 1);
-
- /* Call characters function */
- xslt_call_function("sax characters", XSLT_SAX(handle).characters,
- 2, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ sax_enddoc()
- Called when the document is finished being parsed */
-static SAX_RETURN sax_enddoc(void *ctx)
-{
- zval *argv[1]; /* Arguments to the end document function */
- zval *retval; /* Return value from the end document function */
- php_xslt *handle = (php_xslt *) ctx; /* A PHP-XSLT processor */
- TSRMLS_FETCH();
-
- /* If no end document function exists, exit */
- if (!XSLT_SAX(handle).doc_end) {
- return;
- }
-
- /* Allocate and initialize arguments */
- MAKE_STD_ZVAL(argv[0]);
-
- /* Argument 1: XSLT Processor (resource)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
-
- /* Call the function */
- xslt_call_function("sax end doc", XSLT_SAX(handle).doc_end,
- 1, argv, &retval);
-
- /* Cleanup */
- zval_ptr_dtor(&retval);
-}
-/* }}} */
-
-/* {{{ error_makecode()
- Make the error code */
-static MH_ERROR error_makecode(void *user_data, SablotHandle proc, int severity, unsigned short facility, unsigned short code)
-{
- return(0);
-}
-/* }}} */
-
-/* {{{ error_log()
- Called when its time to log data */
-static MH_ERROR error_log(void *user_data, SablotHandle proc, MH_ERROR code, MH_LEVEL level, char **fields)
-{
- php_xslt *handle = (php_xslt *) user_data; /* A PHP-XSLT processor */
- char *errmsg = NULL; /* Error message*/
- char *errtype = NULL; /* Error type */
- char *errline = NULL; /* Error line */
- char *msgbuf = NULL; /* Message buffer */
- char msgformat[] = "Sablotron Message on line %s, level %s: %s\n"; /* Message format */
- int error = 0; /* Error container */
-
- if (!XSLT_LOG(handle).do_log)
- return 0;
-
- /* Parse the error array */
- /* Loop through the error array */
- if (fields) {
- while (fields && *fields) {
- char *key; /* Key to for the message */
- char *val; /* The message itself */
- char *ptr; /* Pointer to the location of the ':' (separator) */
- int pos; /* Position of the ':' (separator) */
- int len; /* Length of the string */
-
- len = strlen(*fields);
-
- /* Grab the separator's position */
- ptr = strchr(*fields, ':');
- if (!ptr) {
- continue;
- }
- pos = ptr - *fields;
-
- /* Allocate the key and value and copy the data onto them */
- key = emalloc(pos + 1);
- val = emalloc((len - pos) + 1);
-
- memcpy(key, *fields, pos);
- memcpy(val, *fields + pos + 1, len - pos - 1);
-
- key[pos] = '\0';
- val[len - pos - 1] = '\0';
-
- /* Check to see whether or not we want to save the data */
- if (!strcmp(key, "msg")) {
- errmsg = estrndup(val, len - pos -1);
- }
- else if (!strcmp(key, "type")) {
- errtype = estrndup(val, len - pos - 1);
- }
- else if (!strcmp(key, "line")) {
- errline = estrndup(val, len - pos - 1);
- }
-
- /* Cleanup */
- if (key) efree(key);
- if (val) efree(val);
-
- /* Next key:value pair please :) */
- fields++;
- }
- }
-
-
- /* If no error line is given, then place none in the
- file */
- if (!errline) {
- errline = estrndup("none", sizeof("none") - 1);
- }
-
- /* Default type is a log handle */
- if (!errtype) {
- errtype = estrndup("log", sizeof("log") - 1);
- }
-
- /* No error message, no cry */
- if (!errmsg) {
- errmsg = estrndup("unknown error", sizeof("unknown error") - 1);
- }
-
- /* Allocate the message buf and copy the data into it */
- msgbuf = emalloc((sizeof(msgformat) - 6) +
- strlen(errmsg) +
- strlen(errline) +
- strlen(errtype) + 1);
- sprintf(msgbuf, msgformat, errline, errtype, errmsg);
-
- /* If the error is serious enough, copy it to our error buffer
- which will show up when someone calls the xslt_error() function */
- if (level == MH_LEVEL_WARN ||
- level == MH_LEVEL_ERROR ||
- level == MH_LEVEL_CRITICAL) {
- if (XSLT_ERRSTR(handle))
- efree(XSLT_ERRSTR(handle));
-
- XSLT_ERRSTR(handle) = estrdup(errmsg);
- }
-
- /* If we haven't allocated and opened the file yet */
- if (!XSLT_LOG(handle).fd) {
- /* Lets open up a file */
- if (XSLT_LOG(handle).path && strcmp(XSLT_LOG(handle).path, "php://stderr")) {
- /* open for append */
- XSLT_LOG(handle).fd = open(XSLT_LOG(handle).path,
- O_WRONLY|O_CREAT|O_APPEND,
- S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR);
- if (XSLT_LOG(handle).fd < 0) {
- php_error(E_WARNING, "Cannot open log file, %s [%d]: %s",
- XSLT_LOG(handle).path, errno, strerror(errno));
- XSLT_LOG(handle).fd = 0;
- }
- }
- /* Default is stderr, or if the user provided "php://stderr" that's the
- stream */
- else {
- XSLT_LOG(handle).fd = 2;
- }
- }
-
- /* Write the error to the file */
- error = write(XSLT_LOG(handle).fd, msgbuf, strlen(msgbuf));
- if (error < 1) {
- php_error(E_WARNING, "Cannot write data to log file, %s, with fd, %d [%d]: %s",
- (XSLT_LOG(handle).path ? XSLT_LOG(handle).path : "stderr"),
- XSLT_LOG(handle).fd,
- error,
- strerror(error));
- return 0;
- }
-
- /* Cleanup */
- if (msgbuf) efree(msgbuf);
- if (errtype) efree(errtype);
- if (errline) efree(errline);
- if (errmsg) efree(errmsg);
-
- return 0;
-}
-/* }}} */
-
-/* {{{ error_print()
- Print out an error message or call the error handler */
-static MH_ERROR error_print(void *user_data, SablotHandle proc, MH_ERROR code, MH_LEVEL level, char **fields)
-{
- php_xslt *handle = (php_xslt *) user_data; /* A PHP-XSLT processor */
-
- if (XSLT_ERROR(handle)) {
- zval *argv[4]; /* Arguments to the error function */
- zval *retval; /* Return value from the error function */
- TSRMLS_FETCH();
-
- /* Allocate and initialize */
- MAKE_STD_ZVAL(argv[0]);
- MAKE_STD_ZVAL(argv[1]);
- MAKE_STD_ZVAL(argv[2]);
- MAKE_STD_ZVAL(argv[3]);
- array_init(argv[3]);
-
- /* Argument 1: XSLT Processor (resource)
- Argument 2: Error level (long)
- Argument 3: Error code (long)
- Argument 4: Error messages (array)
- */
- ZVAL_RESOURCE(argv[0], handle->processor.idx);
- zend_list_addref(handle->processor.idx);
- ZVAL_LONG(argv[1], level);
- ZVAL_LONG(argv[2], code);
-
- if (fields) {
- while (fields && *fields) {
- char *key; /* Key to for the message */
- char *val; /* The message itself */
- char *ptr; /* Pointer to the location of the ':' (separator) */
- int pos; /* Position of the ':' (separator) */
- int len; /* Length of the string */
-
- len = strlen(*fields);
-
- /* Grab the separator's position */
- ptr = strchr(*fields, ':');
- if (!ptr) {
- continue;
- }
- pos = ptr - *fields;
-
- /* Allocate the key and value and copy the data onto them */
- key = emalloc(pos + 1);
- val = emalloc((len - pos) + 1);
-
- memcpy(key, *fields, pos);
- memcpy(val, *fields + pos + 1, len - pos - 1);
- key[pos] = '\0';
- val[len - pos - 1] = '\0';
-
- /* Add it */
- add_assoc_stringl_ex(argv[3], key, pos, val, len - pos - 1, 1);
-
- /* Cleanup */
- efree(key);
- efree(val);
-
- /* Next field please */
- fields++;
- }
- }
-
- /* Call the function */
- xslt_call_function("error handler", XSLT_ERROR(handle),
- 4, argv, &retval);
-
- /* Free up */
- zval_ptr_dtor(&retval);
- }
- else {
- char *errmsg = NULL; /* Error message */
- char *errline = NULL; /* Error line */
- char *msgbuf = NULL; /* Message buffer */
- char msgformat[] = "Sablotron error on line %s: %s"; /* Message format */
-
- /* If the error is not serious, exit out */
- if (code == MH_LEVEL_WARN ||
- code == MH_LEVEL_ERROR ||
- code == MH_LEVEL_CRITICAL) {
- return 0;
- }
-
- /* Loop through and extract the error message and the
- error line */
- if (fields) {
- while (fields && *fields) {
- char *key; /* Key to for the message */
- char *val; /* The message itself */
- char *ptr; /* Pointer to the location of the ':' (separator) */
- int pos; /* Position of the ':' (separator) */
- int len; /* Length of the string */
-
- len = strlen(*fields);
-
- /* Grab the separator's position */
- ptr = strchr(*fields, ':');
- if (!ptr) {
- continue;
- }
- pos = ptr - *fields;
-
- /* Allocate the key and value and copy the data onto them */
- key = emalloc(pos + 1);
- val = emalloc((len - pos) + 1);
-
- memcpy(key, *fields, pos);
- memcpy(val, *fields + pos + 1, len - pos - 1);
-
- key[pos] = '\0';
- val[len - pos - 1] = '\0';
-
- /* Check to see whether or not we want to save the data */
- if (!strcmp(key, "msg")) {
- errmsg = estrdup(val);
- }
- else if (!strcmp(key, "line")) {
- errline = estrdup(val);
- }
-
- /* Cleanup */
- if (key) efree(key);
- if (val) efree(val);
-
- /* Next key:value pair please :) */
- fields++;
- }
- }
-
- if (!errline) {
- errline = estrndup("none", sizeof("none") - 1);
- }
-
- /* Allocate the message buffer and copy the data onto it */
- msgbuf = emalloc((sizeof(msgformat) - 4) + strlen(errmsg) + strlen(errline) + 1);
- sprintf(msgbuf, msgformat, errline, errmsg);
-
- /* Copy the error message onto the handle for use when
- the xslt_error function is called */
- XSLT_ERRSTR(handle) = estrdup(errmsg);
-
- /* Output a warning */
- php_error(E_WARNING, msgbuf);
-
- /* Cleanup */
- efree(msgbuf);
- efree(errmsg);
- efree(errline);
- }
-
- return(0);
-}
-/* }}} */
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/xslt/tests/001.phpt b/ext/xslt/tests/001.phpt
deleted file mode 100644
index 3270c3f20e..0000000000
--- a/ext/xslt/tests/001.phpt
+++ /dev/null
@@ -1,12 +0,0 @@
---TEST--
-Check for xslt presence
---SKIPIF--
-<?php if (!extension_loaded("xslt")) print "skip"; ?>
---POST--
---GET--
---FILE--
-<?php
-echo "xslt extension is available";
-?>
---EXPECT--
-xslt extension is available \ No newline at end of file
diff --git a/ext/xslt/xslt.c b/ext/xslt/xslt.c
deleted file mode 100644
index 54e6e85714..0000000000
--- a/ext/xslt/xslt.c
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sterling Hughes <sterling@php.net> |
- +----------------------------------------------------------------------+
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "php.h"
-#include "php_xslt.h"
-
-#if HAVE_XSLT
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-
-static int debug = 0;
-
-/* {{{ xslt_debug()
- Output a debug message if debugging is enabled */
-extern void xslt_debug(char *function_name, char *format, ...)
-{
- if (debug) {
- va_list argv;
- char buffer[1024];
-
- va_start(argv, format);
- vsnprintf(buffer, sizeof(buffer) - 1, format, argv);
- va_end(argv);
-
- buffer[sizeof(buffer) - 1] = '\0';
-
- php_printf("<b>XSLT Debug</b>: %s: %s<br>\n",
- function_name, buffer);
- }
-}
-/* }}} */
-
-/* {{{ find_xslt_argument()
- Find and return an xslt argument from the argument buffer */
-static char *_find_xslt_argument(const char **argv, const char *key)
-{
- char **ptr; /* Pointer to the passed char ** array */
- char *return_value = NULL; /* Value to return from the function */
-
- /* Loop through the array searching for the value */
- ptr = (char **) argv;
- while (ptr && *ptr) {
- /* If we have a match, save the value and exit out */
- if (! strcmp(*ptr, key)) {
- return_value = estrdup(*ptr);
- break;
- }
-
- ptr++;
- }
-
- return return_value;
-}
-/* }}} */
-
-/* {{{ xslt_make_array()
- Make an XSLT array (char **) from a zval array (HashTable *) */
-extern void xslt_make_array(zval **zarr, char ***carr)
-{
- zval **current;
- HashTable *arr;
- int idx = 0;
- TSRMLS_FETCH();
-
- arr = HASH_OF(*zarr);
- if (! arr) {
- php_error(E_WARNING, "Invalid argument or parameter array to %s",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- *carr = emalloc(((zend_hash_num_elements(arr) * 2) + 1) * sizeof(char *));
-
- for (zend_hash_internal_pointer_reset(arr);
- zend_hash_get_current_data(arr, (void **) &current) == SUCCESS;
- zend_hash_move_forward(arr)) {
- char *string_key = NULL;
- ulong num_key;
- int type;
-
- SEPARATE_ZVAL(current);
- convert_to_string_ex(current);
-
- type = zend_hash_get_current_key(arr, &string_key, &num_key, 0);
- if (type == HASH_KEY_IS_LONG) {
- php_error(E_WARNING, "Invalid argument or parameter array to %s",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- (*carr)[idx++] = estrdup(string_key);
- (*carr)[idx++] = estrndup(Z_STRVAL_PP(current), Z_STRLEN_PP(current));
- }
-
- (*carr)[idx] = NULL;
-}
-/* }}} */
-
-/* {{{ xslt_free_array()
- Free an xslt array built by xslt_make_array() */
-extern void xslt_free_array(char **arr)
-{
- char **ptr = arr;
-
- while (*ptr != NULL) {
- efree(*ptr);
- ptr++;
- }
-
- efree(arr);
-}
-/* }}} */
-
-/* {{{ xslt_parse_arguments()
- Parse an XSLT argument buffer */
-extern xslt_args *xslt_parse_arguments(char *xml,
- char *xsl,
- char *result,
- char **argv)
-{
- xslt_args *return_value; /* The value to return from the function */
-
- return_value = emalloc(sizeof(xslt_args));
-
- /* The xml argument */
- if (! strncasecmp(xml, "arg:", 4)) {
- char *key = xml + 5;
-
- return_value->xml.type = XSLT_IS_DATA;
- return_value->xml.ptr = _find_xslt_argument((const char **) argv,
- (const char *) key);
- }
- else {
- return_value->xml.type = XSLT_IS_FILE;
- return_value->xml.ptr = estrdup(xml);
- }
-
- /* The xslt arguments */
- if (! strncasecmp(xsl, "arg:", 4)) {
- char *key = xsl + 5;
-
- return_value->xsl.type = XSLT_IS_DATA;
- return_value->xsl.ptr = _find_xslt_argument((const char **) argv,
- (const char *) key);
- }
- else {
- return_value->xsl.type = XSLT_IS_FILE;
- return_value->xsl.ptr = estrdup(xsl);
- }
-
- /* The result argument */
- if (! strncasecmp(result, "arg:", 4)) {
- char *key = result + 5;
-
- return_value->result.type = XSLT_IS_DATA;
- return_value->result.ptr = _find_xslt_argument((const char **) argv,
- (const char *) key);
- }
- else {
- return_value->result.type = XSLT_IS_FILE;
- return_value->result.ptr = estrdup(result);
- }
-
- return return_value;
-}
-/* }}} */
-
-/* {{{ free_xslt_arguments()
- Free's an XSLT argument list returned from parse_xslt_arguments() */
-extern void xslt_free_arguments(xslt_args *to_free)
-{
- if (to_free->xml.ptr) {
- efree(to_free->xml.ptr);
- }
-
- if (to_free->xsl.ptr) {
- efree(to_free->xsl.ptr);
- }
-
- if (to_free->result.ptr) {
- efree(to_free->result.ptr);
- }
-
- efree(to_free);
-}
-/* }}} */
-
-/* {{{ call_xslt_function()
- Call an XSLT handler */
-extern void xslt_call_function(char *name,
- zval *function,
- int argc,
- zval **user_args,
- zval **retval)
-{
- zval ***argv; /* Argument container, maps around for call_user_function_ex() */
- int error; /* Error container */
- int idx; /* Idx, when looping through and free'ing the arguments */
- TSRMLS_FETCH(); /* For TS mode, fetch the executor globals */
-
- /* Allocate and initialize return value from the function */
- MAKE_STD_ZVAL(*retval);
-
- argv = emalloc(argc * sizeof(zval **));
- for (idx = 0; idx < argc; idx++) {
- argv[idx] = &user_args[idx];
- }
-
- /* Call the function */
- error = call_user_function_ex(EG(function_table),
- NULL, function,
- retval, argc, argv, 0, NULL TSRMLS_CC);
- if (error == FAILURE) {
- php_error(E_WARNING, "Cannot call the %s handler: %s",
- name, Z_STRVAL_P(function));
- }
-
- /* Cleanup arguments */
- for (idx = 0; idx < argc; idx++) {
- /* Decrease refcount and free if refcount is <= 0 */
- zval_ptr_dtor(argv[idx]);
- }
-
- efree(argv);
-}
-/* }}} */
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/xslt/xslt.dsp b/ext/xslt/xslt.dsp
deleted file mode 100644
index fd8c2dc10e..0000000000
--- a/ext/xslt/xslt.dsp
+++ /dev/null
@@ -1,115 +0,0 @@
-# Microsoft Developer Studio Project File - Name="xslt" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=xslt - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "xslt.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "xslt.mak" CFG="xslt - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "xslt - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "xslt - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "xslt - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XSLT_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\main" /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\win32" /D "WIN32" /D "COMPILE_DL_XSLT" /D ZTS=1 /D HAVE_XSLT=1 /D ZEND_DEBUG=0 /D "NDEBUG" /D "_WINDOWS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "HAVE_SABLOT_BACKEND" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib php4ts.lib sablot.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_xslt.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-
-!ELSEIF "$(CFG)" == "xslt - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XSLT_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_XSLT=1 /D COMPILE_DL_XSLT=1 /D "HAVE_SABLOT_BACKEND" /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "_DEBUG"
-# ADD RSC /l 0x407 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib php4ts_debug.lib sablot.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_xslt.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "xslt - Win32 Release_TS"
-# Name "xslt - Win32 Debug_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\sablot.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\xslt.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_sablot.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_xslt.h
-# End Source File
-# End Group
-# End Target
-# End Project