Back to index

php5  5.3.10
php_xsl.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author: Christian Stocker <chregu@php.net>                           |
00016   +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: php_xsl.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include "config.h"
00023 #endif
00024 
00025 #include "php.h"
00026 #include "php_ini.h"
00027 #include "ext/standard/info.h"
00028 #include "php_xsl.h"
00029 
00030 zend_class_entry *xsl_xsltprocessor_class_entry;
00031 static zend_object_handlers xsl_object_handlers;
00032 
00033 /* {{{ xsl_functions[]
00034  *
00035  * Every user visible function must have an entry in xsl_functions[].
00036  */
00037 const zend_function_entry xsl_functions[] = {
00038        PHP_FE_END
00039 };
00040 /* }}} */
00041 
00042 static const zend_module_dep xsl_deps[] = {
00043        ZEND_MOD_REQUIRED("libxml")
00044        ZEND_MOD_END
00045 };
00046 
00047 /* {{{ xsl_module_entry
00048  */
00049 zend_module_entry xsl_module_entry = {
00050 #if ZEND_MODULE_API_NO >= 20050617
00051        STANDARD_MODULE_HEADER_EX, NULL,
00052        xsl_deps,
00053 #elif ZEND_MODULE_API_NO >= 20010901
00054        STANDARD_MODULE_HEADER,
00055 #endif
00056        "xsl",
00057        xsl_functions,
00058        PHP_MINIT(xsl),
00059        PHP_MSHUTDOWN(xsl),
00060        PHP_RINIT(xsl),             /* Replace with NULL if there's nothing to do at request start */
00061        PHP_RSHUTDOWN(xsl),  /* Replace with NULL if there's nothing to do at request end */
00062        PHP_MINFO(xsl),
00063 #if ZEND_MODULE_API_NO >= 20010901
00064        "0.1", /* Replace with version number for your extension */
00065 #endif
00066        STANDARD_MODULE_PROPERTIES
00067 };
00068 /* }}} */
00069 
00070 #ifdef COMPILE_DL_XSL
00071 ZEND_GET_MODULE(xsl)
00072 #endif
00073 
00074 /* {{{ xsl_objects_free_storage */
00075 void xsl_objects_free_storage(void *object TSRMLS_DC)
00076 {
00077        xsl_object *intern = (xsl_object *)object;
00078 
00079        zend_object_std_dtor(&intern->std TSRMLS_CC);
00080 
00081        zend_hash_destroy(intern->parameter);
00082        FREE_HASHTABLE(intern->parameter);
00083        
00084        zend_hash_destroy(intern->registered_phpfunctions);
00085        FREE_HASHTABLE(intern->registered_phpfunctions);
00086        
00087        if (intern->node_list) {
00088               zend_hash_destroy(intern->node_list);
00089               FREE_HASHTABLE(intern->node_list);
00090        }
00091 
00092        if (intern->doc) {
00093               php_libxml_decrement_doc_ref(intern->doc TSRMLS_CC);
00094               efree(intern->doc);
00095        }
00096 
00097        if (intern->ptr) {
00098               /* free wrapper */
00099               if (((xsltStylesheetPtr) intern->ptr)->_private != NULL) {
00100                      ((xsltStylesheetPtr) intern->ptr)->_private = NULL;   
00101               }
00102 
00103               xsltFreeStylesheet((xsltStylesheetPtr) intern->ptr);
00104               intern->ptr = NULL;
00105        }
00106        if (intern->profiling) {
00107               efree(intern->profiling);
00108        }
00109        efree(object);
00110 }
00111 /* }}} */
00112 
00113 /* {{{ xsl_objects_new */
00114 zend_object_value xsl_objects_new(zend_class_entry *class_type TSRMLS_DC)
00115 {
00116        zend_object_value retval;
00117        xsl_object *intern;
00118        zval *tmp;
00119 
00120        intern = emalloc(sizeof(xsl_object));
00121        intern->ptr = NULL;
00122        intern->prop_handler = NULL;
00123        intern->parameter = NULL;
00124        intern->hasKeys = 0;
00125        intern->registerPhpFunctions = 0;
00126        intern->registered_phpfunctions = NULL;
00127        intern->node_list = NULL;
00128        intern->doc = NULL;
00129        intern->profiling = NULL;
00130 
00131        zend_object_std_init(&intern->std, class_type TSRMLS_CC);
00132        zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
00133        ALLOC_HASHTABLE(intern->parameter);
00134        zend_hash_init(intern->parameter, 0, NULL, ZVAL_PTR_DTOR, 0);
00135        ALLOC_HASHTABLE(intern->registered_phpfunctions);
00136        zend_hash_init(intern->registered_phpfunctions, 0, NULL, ZVAL_PTR_DTOR, 0);
00137        retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) xsl_objects_free_storage, NULL TSRMLS_CC);
00138        intern->handle = retval.handle;
00139        retval.handlers = &xsl_object_handlers;
00140        return retval;
00141 }
00142 /* }}} */
00143 
00144 PHP_INI_BEGIN()
00145 /* Default is not allowing any write operations. 
00146    XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_NETWORK | XSL_SECPREF_WRITE_FILE == 44 
00147 */
00148 PHP_INI_ENTRY("xsl.security_prefs", "44", PHP_INI_ALL, NULL)
00149 PHP_INI_END()
00150 
00151 /* {{{ PHP_MINIT_FUNCTION
00152  */
00153 PHP_MINIT_FUNCTION(xsl)
00154 {
00155        
00156        zend_class_entry ce;
00157        
00158        memcpy(&xsl_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
00159        xsl_object_handlers.clone_obj = NULL;
00160 
00161        REGISTER_XSL_CLASS(ce, "XSLTProcessor", NULL, php_xsl_xsltprocessor_class_functions, xsl_xsltprocessor_class_entry);
00162 #if HAVE_XSL_EXSLT
00163        exsltRegisterAll();
00164 #endif
00165  
00166        xsltRegisterExtModuleFunction ((const xmlChar *) "functionString",
00167                                (const xmlChar *) "http://php.net/xsl",
00168                                xsl_ext_function_string_php);
00169        xsltRegisterExtModuleFunction ((const xmlChar *) "function",
00170                                (const xmlChar *) "http://php.net/xsl",
00171                                xsl_ext_function_object_php);
00172 
00173        REGISTER_LONG_CONSTANT("XSL_CLONE_AUTO",      0,     CONST_CS | CONST_PERSISTENT);
00174        REGISTER_LONG_CONSTANT("XSL_CLONE_NEVER",    -1,     CONST_CS | CONST_PERSISTENT);
00175        REGISTER_LONG_CONSTANT("XSL_CLONE_ALWAYS",    1,     CONST_CS | CONST_PERSISTENT);
00176 
00177        REGISTER_LONG_CONSTANT("XSL_SECPREF_NONE",             XSL_SECPREF_NONE,             CONST_CS | CONST_PERSISTENT);
00178        REGISTER_LONG_CONSTANT("XSL_SECPREF_READ_FILE",        XSL_SECPREF_READ_FILE,        CONST_CS | CONST_PERSISTENT);
00179        REGISTER_LONG_CONSTANT("XSL_SECPREF_WRITE_FILE",       XSL_SECPREF_WRITE_FILE,       CONST_CS | CONST_PERSISTENT);
00180        REGISTER_LONG_CONSTANT("XSL_SECPREF_CREATE_DIRECTORY", XSL_SECPREF_CREATE_DIRECTORY, CONST_CS | CONST_PERSISTENT);
00181        REGISTER_LONG_CONSTANT("XSL_SECPREF_READ_NETWORK",     XSL_SECPREF_READ_NETWORK,     CONST_CS | CONST_PERSISTENT);
00182        REGISTER_LONG_CONSTANT("XSL_SECPREF_WRITE_NETWORK",    XSL_SECPREF_WRITE_NETWORK,    CONST_CS | CONST_PERSISTENT);
00183        REGISTER_LONG_CONSTANT("XSL_SECPREF_DEFAULT",          XSL_SECPREF_DEFAULT,          CONST_CS | CONST_PERSISTENT);
00184 
00185        REGISTER_LONG_CONSTANT("LIBXSLT_VERSION",           LIBXSLT_VERSION,            CONST_CS | CONST_PERSISTENT);
00186        REGISTER_STRING_CONSTANT("LIBXSLT_DOTTED_VERSION",  LIBXSLT_DOTTED_VERSION,     CONST_CS | CONST_PERSISTENT);
00187 
00188 #if HAVE_XSL_EXSLT
00189        REGISTER_LONG_CONSTANT("LIBEXSLT_VERSION",           LIBEXSLT_VERSION,            CONST_CS | CONST_PERSISTENT);
00190        REGISTER_STRING_CONSTANT("LIBEXSLT_DOTTED_VERSION",  LIBEXSLT_DOTTED_VERSION,     CONST_CS | CONST_PERSISTENT);
00191 #endif
00192 
00193     REGISTER_INI_ENTRIES();
00194 
00195        return SUCCESS;
00196 }
00197 /* }}} */
00198 
00199 /* {{{ xsl_object_get_data */
00200 zval *xsl_object_get_data(void *obj)
00201 {
00202        zval *dom_wrapper;
00203        dom_wrapper = ((xsltStylesheetPtr) obj)->_private;
00204        return dom_wrapper;
00205 }
00206 /* }}} */
00207 
00208 /* {{{ xsl_object_set_data */
00209 static void xsl_object_set_data(void *obj, zval *wrapper TSRMLS_DC)
00210 {
00211        ((xsltStylesheetPtr) obj)->_private = wrapper;
00212 }
00213 /* }}} */
00214 
00215 /* {{{ php_xsl_set_object */
00216 void php_xsl_set_object(zval *wrapper, void *obj TSRMLS_DC)
00217 {
00218        xsl_object *object;
00219 
00220        object = (xsl_object *)zend_objects_get_address(wrapper TSRMLS_CC);
00221        object->ptr = obj;
00222        xsl_object_set_data(obj, wrapper TSRMLS_CC);
00223 }
00224 /* }}} */
00225 
00226 /* {{{ php_xsl_create_object */
00227 zval *php_xsl_create_object(xsltStylesheetPtr obj, int *found, zval *wrapper_in, zval *return_value  TSRMLS_DC)
00228 {
00229        zval *wrapper;
00230        zend_class_entry *ce;
00231 
00232        *found = 0;
00233 
00234        if (!obj) {
00235               if(!wrapper_in) {
00236                      ALLOC_ZVAL(wrapper);
00237               } else {
00238                      wrapper = wrapper_in;
00239               }
00240               ZVAL_NULL(wrapper);
00241               return wrapper;
00242        }
00243 
00244        if ((wrapper = (zval *) xsl_object_get_data((void *) obj))) {
00245               zval_add_ref(&wrapper);
00246               *found = 1;
00247               return wrapper;
00248        }
00249 
00250        if(!wrapper_in) {
00251               wrapper = return_value;
00252        } else {
00253               wrapper = wrapper_in;
00254        }
00255 
00256        
00257        ce = xsl_xsltprocessor_class_entry;
00258 
00259        if(!wrapper_in) {
00260               object_init_ex(wrapper, ce);
00261        }
00262        php_xsl_set_object(wrapper, (void *) obj TSRMLS_CC);
00263        return (wrapper);
00264 }
00265 /* }}} */
00266 
00267 /* {{{ PHP_MSHUTDOWN_FUNCTION
00268  */
00269 PHP_MSHUTDOWN_FUNCTION(xsl)
00270 {
00271        xsltUnregisterExtModuleFunction ((const xmlChar *) "functionString",
00272                                (const xmlChar *) "http://php.net/xsl");
00273        xsltUnregisterExtModuleFunction ((const xmlChar *) "function",
00274                                (const xmlChar *) "http://php.net/xsl");
00275 
00276        xsltCleanupGlobals();
00277 
00278        UNREGISTER_INI_ENTRIES();
00279 
00280        return SUCCESS;
00281 }
00282 /* }}} */
00283 
00284 /* {{{ PHP_RINIT_FUNCTION
00285  */
00286 PHP_RINIT_FUNCTION(xsl)
00287 {
00288        xsltSetGenericErrorFunc(NULL, php_libxml_error_handler);
00289        return SUCCESS;
00290 }
00291 /* }}} */
00292 
00293 /* {{{ PHP_RSHUTDOWN_FUNCTION
00294  */
00295 PHP_RSHUTDOWN_FUNCTION(xsl)
00296 {
00297        xsltSetGenericErrorFunc(NULL, NULL);
00298        return SUCCESS;
00299 }
00300 /* }}} */
00301 
00302 /* {{{ PHP_MINFO_FUNCTION
00303  */
00304 PHP_MINFO_FUNCTION(xsl)
00305 {
00306        php_info_print_table_start();
00307        {
00308               char buffer[128];
00309               int major, minor, subminor;
00310 
00311               php_info_print_table_row(2, "XSL", "enabled");
00312               major = xsltLibxsltVersion/10000;
00313               minor = (xsltLibxsltVersion - major * 10000) / 100;
00314               subminor = (xsltLibxsltVersion - major * 10000 - minor * 100);
00315               snprintf(buffer, 128, "%d.%d.%d", major, minor, subminor);
00316               php_info_print_table_row(2, "libxslt Version", buffer);
00317               major = xsltLibxmlVersion/10000;
00318               minor = (xsltLibxmlVersion - major * 10000) / 100;
00319               subminor = (xsltLibxmlVersion - major * 10000 - minor * 100);
00320               snprintf(buffer, 128, "%d.%d.%d", major, minor, subminor);
00321               php_info_print_table_row(2, "libxslt compiled against libxml Version", buffer);
00322        }
00323 #if HAVE_XSL_EXSLT
00324        php_info_print_table_row(2, "EXSLT", "enabled");
00325        php_info_print_table_row(2, "libexslt Version", LIBEXSLT_DOTTED_VERSION);
00326 #endif
00327        php_info_print_table_end();
00328 }
00329 /* }}} */
00330 
00331 /*
00332  * Local variables:
00333  * tab-width: 4
00334  * c-basic-offset: 4
00335  * End:
00336  * vim600: noet sw=4 ts=4 fdm=marker
00337  * vim<600: noet sw=4 ts=4
00338  */