📄 sablot.c
字号:
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 */ int i; /* iterator for Situation */ if (argc < 3 || argc > 6 || zend_get_parameters_ex(argc, &processor_p, &xml_p, &xslt_p, &result_p, &args_p, ¶ms_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); /* Can return NULL */ if (args) { TSRMLS_FETCH(); i=0; while (args[i]) { /* We can safely add args[i+1] since xslt_make_array sets args[i] to NULL if a key on the array is missing. */ /* For now, we don't care about the error. So don't store it. */ SablotAddArgBuffer(XSLT_SITUATION(handle), XSLT_PROCESSOR(handle), args[i], args[i+1]); i += 2; } /* Since we have args passed, we need to set the base uri, so pull in executor globals and set the base, using the current filename, specifcally for the 'arg' scheme */ if(XSLT_BASE_ISSET(handle) == 0) { char *baseuri; spprintf(&baseuri, 0, "file://%s", zend_get_executed_filename(TSRMLS_C)); SablotSetBaseForScheme(XSLT_PROCESSOR(handle), "arg", baseuri); if(baseuri) efree(baseuri); } } } if (argc > 5) { xslt_make_array(params_p, ¶ms); /* Can return NULL */ if (params) { i=0; while (params[i]) { SablotAddParam(XSLT_SITUATION(handle), XSLT_PROCESSOR(handle), params[i], params[i+1]); i += 2; } } } /* Perform transformation */ error = SablotRunProcessorGen(XSLT_SITUATION(handle), XSLT_PROCESSOR(handle), xslt, xml, result); 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); if (XSLT_ERRSTR(handle)) { RETURN_STRING(XSLT_ERRSTR(handle), 1); } else { RETURN_FALSE; }}/* }}} *//* {{{ 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));}/* }}} *//* {{{ proto int xslt_set_object(resource parser, object obj) sets the object in which to resolve callback functions */PHP_FUNCTION(xslt_set_object){ zval *processor_p; /* Resource pointer to a PHP-XSLT processor */ zval *myobj; /* The object that will handle the callback */ php_xslt *handle; /* A PHP-XSLT processor */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zo", &processor_p, &myobj) == FAILURE) return; ZEND_FETCH_RESOURCE(handle, php_xslt *, &processor_p, -1, le_xslt_name, le_xslt); handle->object = myobj; RETURN_TRUE;}/* }}} *//* {{{ proto int xslt_setopt(resource processor, int newmask) Set options on a given xsl processor */PHP_FUNCTION(xslt_setopt){ zval **processor_p; /* Resource pointer to a PHP-XSLT processor */ zval **zbitmask; /* A bitmask created by through processor specific constants */ php_xslt *handle; /* A PHP-XSLT processor */ int error; /* Error return codes */ int newmask; /* New mask */#ifdef HAVE_SABLOT_GET_OPTIONS int prevmask; /* Previous mask */#endif if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &processor_p, &zbitmask) == FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt); convert_to_long_ex(zbitmask); newmask = Z_LVAL_PP(zbitmask); if (newmask < 0) { php_error_docref("function.xslt-setopt" TSRMLS_CC, E_WARNING, "Invalid bitmask: %i", newmask); RETURN_FALSE; }#ifdef HAVE_SABLOT_GET_OPTIONS prevmask = SablotGetOptions(XSLT_SITUATION(handle));#endif error = SablotSetOptions(XSLT_SITUATION(handle), newmask); if (error) { /* FIXME: Need to analyze the return code to give a more verbose error description */ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Failed to set options"); }#ifdef HAVE_SABLOT_GET_OPTIONS RETURN_LONG(prevmask);#else RETURN_TRUE;#endif}/* }}} */#ifdef HAVE_SABLOT_GET_OPTIONS/* {{{ proto int xslt_getopt(resource processor) Get options on a given xsl processor */PHP_FUNCTION(xslt_getopt){ 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(SablotGetOptions(XSLT_SITUATION(handle)));}/* }}} */#endif/* {{{ proto string xslt_backend_version() Returns the version number of Sablotron (if available) */PHP_FUNCTION(xslt_backend_version){#ifdef SAB_VERSION RETURN_STRING(SAB_VERSION,1);#else RETURN_FALSE;#endif }/* }}} *//* {{{ proto string xslt_backend_name() Returns the name of the Backend (here "Sablotron")*/PHP_FUNCTION(xslt_backend_name){ RETURN_STRING("Sablotron",1);}/* }}} *//* {{{ proto string xslt_backend_info() Returns the information on the compilation settings of the backend */PHP_FUNCTION(xslt_backend_info){#ifdef HAVE_SABLOT_CONFIG RETURN_STRING(SAB_INFO, strlen(SAB_INFO));#else RETURN_STRING(XSLT_NO_INFO, strlen(XSLT_NO_INFO));#endif}/* }}} *//* {{{ 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)); SablotDestroySituation(XSLT_SITUATION(handle)); } /* Free Scheme handlers */ XSLT_FUNCH_FREE(XSLT_SCHEME(handle).sh_get_all); XSLT_FUNCH_FREE(XSLT_SCHEME(handle).sh_open); XSLT_FUNCH_FREE(XSLT_SCHEME(handle).sh_get); XSLT_FUNCH_FREE(XSLT_SCHEME(handle).sh_put); XSLT_FUNCH_FREE(XSLT_SCHEME(handle).sh_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 TSRMLS_DC){ zval **current; /* The current handler we're grabbing */ /* Grab and assign handler 1 */ if (zend_hash_index_find(Z_ARRVAL_PP(handler), 0, (void **) ¤t) == SUCCESS) { *handler1 = *current; zval_add_ref(handler1); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong format of arguments"); return; } /* Grab and assign handler 2 */ if (zend_hash_index_find(Z_ARRVAL_PP(handler), 1, (void **) ¤t) == SUCCESS) { *handler2 = *current; zval_add_ref(handler2); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong format of arguments"); 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 */ int result; 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).sh_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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -