From: Sterling Hughes Date: Fri, 24 Nov 2000 16:26:35 +0000 (+0000) Subject: Declaring variables is generally a good thing X-Git-Tag: php-4.0.4RC3~64 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=917cfd14e9dab1f24513053621df67455b2157a6;p=php Declaring variables is generally a good thing --- diff --git a/ext/sablot/sablot.c b/ext/sablot/sablot.c index e3c9906dd7..558e7fb87f 100644 --- a/ext/sablot/sablot.c +++ b/ext/sablot/sablot.c @@ -63,7 +63,7 @@ static zval *_php_sablot_resource_zval(long); /* Free macros */ #define S_FREE(__var) if (__var) efree(__var); -#define FUNCH_FREE(__var) if (__var) zval_del_ref(&(__var)); +#define FUNCH_FREE(__var) if (__var) zval_del_ref(&(__var)); /* ERROR Macros */ @@ -123,9 +123,9 @@ static SAXHandler sax = { * reports that something has gone wrong. */ static MessageHandler mh = { - _php_sablot_make_code, - _php_sablot_error, - _php_sablot_error + _php_sablot_make_code, + _php_sablot_error, + _php_sablot_error }; #ifdef ZTS @@ -139,32 +139,32 @@ static unsigned char sixth_arg_force_ref[] = { 6, BYREF_NONE, BYREF_NONE, BYREF_ static unsigned char third_arg_force_ref[] = { 4, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_NONE }; function_entry sablot_functions[] = { - PHP_FE(xslt_output_begintransform, NULL) - PHP_FE(xslt_output_endtransform, NULL) - PHP_FE(xslt_transform, sixth_arg_force_ref) - PHP_FE(xslt_process, third_arg_force_ref) - PHP_FE(xslt_create, NULL) - PHP_FE(xslt_run, NULL) - PHP_FE(xslt_fetch_result, NULL) - PHP_FE(xslt_openlog, NULL) - PHP_FE(xslt_closelog, NULL) - PHP_FE(xslt_set_sax_handler, NULL) - PHP_FE(xslt_set_error_handler, NULL) - PHP_FE(xslt_free, NULL) - PHP_FE(xslt_error, NULL) - PHP_FE(xslt_errno, NULL) - {NULL, NULL, NULL} + PHP_FE(xslt_output_begintransform, NULL) + PHP_FE(xslt_output_endtransform, NULL) + PHP_FE(xslt_transform, sixth_arg_force_ref) + PHP_FE(xslt_process, third_arg_force_ref) + PHP_FE(xslt_create, NULL) + PHP_FE(xslt_run, NULL) + PHP_FE(xslt_fetch_result, NULL) + PHP_FE(xslt_openlog, NULL) + PHP_FE(xslt_closelog, NULL) + PHP_FE(xslt_set_sax_handler, NULL) + PHP_FE(xslt_set_error_handler, NULL) + PHP_FE(xslt_free, NULL) + PHP_FE(xslt_error, NULL) + PHP_FE(xslt_errno, NULL) + {NULL, NULL, NULL} }; zend_module_entry sablot_module_entry = { - "sablot", - sablot_functions, - PHP_MINIT(sablot), - PHP_MSHUTDOWN(sablot), - NULL, - NULL, - PHP_MINFO(sablot), - STANDARD_MODULE_PROPERTIES + "sablot", + sablot_functions, + PHP_MINIT(sablot), + PHP_MSHUTDOWN(sablot), + NULL, + NULL, + PHP_MINFO(sablot), + STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_SABLOT @@ -177,7 +177,7 @@ PHP_MINIT_FUNCTION(sablot) { le_sablot = zend_register_list_destructors_ex(_php_sablot_free_processor, NULL, "Sablotron XSLT", module_number); - return SUCCESS; + return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(sablot) @@ -194,9 +194,9 @@ PHP_MSHUTDOWN_FUNCTION(sablot) PHP_MINFO_FUNCTION(sablot) { - php_info_print_table_start(); - php_info_print_table_row(2, "Sablotron XSLT support", "enabled"); - php_info_print_table_end(); + php_info_print_table_start(); + php_info_print_table_row(2, "Sablotron XSLT support", "enabled"); + php_info_print_table_end(); } @@ -205,27 +205,27 @@ PHP_MINFO_FUNCTION(sablot) PHP_FUNCTION(xslt_output_begintransform) { /* The name of the file to pass the output through */ - zval **file; - - /* needed for the output transformation file name */ - SABLOTLS_FETCH(); - - if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &file) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(file); - - /* If the buffer exists, free it */ - S_FREE(SABLOTG(output_transform_file)); - - SABLOTG(output_transform_file) = estrndup(Z_STRVAL_PP(file), Z_STRLEN_PP(file)); + zval **file; + + /* needed for the output transformation file name */ + SABLOTLS_FETCH(); + + if (ZEND_NUM_ARGS() != 1 || + zend_get_parameters_ex(1, &file) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(file); + + /* If the buffer exists, free it */ + S_FREE(SABLOTG(output_transform_file)); + + SABLOTG(output_transform_file) = estrndup(Z_STRVAL_PP(file), Z_STRLEN_PP(file)); /** * Start output buffering, NULL signifies that no "user-space" output function * will be used. The 0 disables chunking */ - php_start_ob_buffer(NULL, 0); + php_start_ob_buffer(NULL, 0); } /* }}} */ @@ -233,47 +233,47 @@ PHP_FUNCTION(xslt_output_begintransform) End filtering that data through the XSL file set by xslt_output_transform() and output the data */ PHP_FUNCTION(xslt_output_endtransform) { - char *tRes = NULL, - *buffer = NULL; - int ret = 0; - - /* Fetch both the output globals and the sablotron globals */ - OLS_FETCH(); - SABLOTLS_FETCH(); + char *tRes = NULL, + *buffer = NULL; + int ret = 0; + + /* Fetch both the output globals and the sablotron globals */ + OLS_FETCH(); + SABLOTLS_FETCH(); /** * Make sure that we don't have more than one output buffer going on * at the same time. */ - if (OG(nesting_level) == 0) { - RETURN_NULL(); - } + if (OG(nesting_level) == 0) { + RETURN_NULL(); + } - buffer = estrndup(OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length); + buffer = estrndup(OG(active_ob_buffer).buffer, OG(active_ob_buffer).text_length); /* Nake sure there is data to send */ - if (strlen(buffer)) { - char *args[] = {"/_xmlinput", buffer, - "/_output", NULL}; - - SABLOT_BASIC_CREATE_PROCESSOR(); - - ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, SABLOTG(output_transform_file), - "arg:/_xmlinput", "arg:/_output", NULL, args); - - if (ret) { - SABLOTG(last_errno) = ret; - S_FREE(SABLOTG(output_transform_file)); - RETURN_NULL(); - } - - ret = SablotGetResultArg(SABLOT_BASIC_HANDLE, "arg:/_output", &tRes); - - if (ret) { - SABLOTG(last_errno) = ret; - S_FREE(SABLOTG(output_transform_file)); - RETURN_NULL(); - } + if (strlen(buffer)) { + char *args[] = {"/_xmlinput", buffer, + "/_output", NULL}; + + SABLOT_BASIC_CREATE_PROCESSOR(); + + ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, SABLOTG(output_transform_file), + "arg:/_xmlinput", "arg:/_output", NULL, args); + + if (ret) { + SABLOTG(last_errno) = ret; + S_FREE(SABLOTG(output_transform_file)); + RETURN_NULL(); + } + + ret = SablotGetResultArg(SABLOT_BASIC_HANDLE, "arg:/_output", &tRes); + + if (ret) { + SABLOTG(last_errno) = ret; + S_FREE(SABLOTG(output_transform_file)); + RETURN_NULL(); + } } /** @@ -281,33 +281,33 @@ PHP_FUNCTION(xslt_output_endtransform) * errno (for xslt_errno() and xslt_error()) free the output * transformation file and null. */ - if (ret) { - SABLOTG(last_errno) = ret; - S_FREE(SABLOTG(output_transform_file)); - RETURN_NULL(); - } - - /** - * If there is a buffer, end output buffering and clear the - * current output buffer (so we don't send data twice) - */ - if (tRes) - php_end_ob_buffer(0); - - PUTS(tRes); - - S_FREE(SABLOTG(output_transform_file)); - S_FREE(buffer); + if (ret) { + SABLOTG(last_errno) = ret; + S_FREE(SABLOTG(output_transform_file)); + RETURN_NULL(); + } + + /** + * If there is a buffer, end output buffering and clear the + * current output buffer (so we don't send data twice) + */ + if (tRes) + php_end_ob_buffer(0); + + PUTS(tRes); + + S_FREE(SABLOTG(output_transform_file)); + S_FREE(buffer); /** * If there exists a result, free that result * otherwise just end output buffering and send the * data. */ - if (tRes) - SablotFree(tRes); - else - php_end_ob_buffer(1); + if (tRes) + SablotFree(tRes); + else + php_end_ob_buffer(1); } /* }}} */ @@ -315,38 +315,38 @@ PHP_FUNCTION(xslt_output_endtransform) Transform an XML document, transform_uri, with an XSL stylesheet, xslt_uri with parameters, xslt_params, into the Result buffer, result_uri, xslt_args defines the variables in xslt_uri, transform_uri and result_uri. */ PHP_FUNCTION(xslt_transform) { - zval **xslt_uri, - **transform_uri, - **result_uri, - **xslt_params, - **xslt_args, - **result; - - char **args = NULL, - **params = NULL, - *tResult = NULL; - - int argc = ZEND_NUM_ARGS(), - ret = 0; - - SABLOTLS_FETCH(); - - if (argc < 3 || argc > 6 || - zend_get_parameters_ex(argc, &xslt_uri, &transform_uri, &result_uri, &xslt_params, &xslt_args, &result) == FAILURE) { - WRONG_PARAM_COUNT; - } - multi_convert_to_string_ex(3, xslt_uri, transform_uri, result_uri); - - /** - * if there are more than 3 function arguments, inspect the value of - * the third argument and decide whether or not there are Sablotron - * parameters. - */ - if (argc > 3) { - HashTable *ar = HASH_OF(*xslt_params); + zval **xslt_uri, + **transform_uri, + **result_uri, + **xslt_params, + **xslt_args, + **result; + + char **args = NULL, + **params = NULL, + *tResult = NULL; + + int argc = ZEND_NUM_ARGS(), + ret = 0; + + SABLOTLS_FETCH(); + + if (argc < 3 || argc > 6 || + zend_get_parameters_ex(argc, &xslt_uri, &transform_uri, &result_uri, &xslt_params, &xslt_args, &result) == FAILURE) { + WRONG_PARAM_COUNT; + } + multi_convert_to_string_ex(3, xslt_uri, transform_uri, result_uri); + + /** + * if there are more than 3 function arguments, inspect the value of + * the third argument and decide whether or not there are Sablotron + * parameters. + */ + if (argc > 3) { + HashTable *ar = HASH_OF(*xslt_params); if (ar) { - int numelems, - size; + int numelems, + size; /** * Allocate 2 times the number of elements in @@ -354,79 +354,79 @@ PHP_FUNCTION(xslt_transform) * keys are not counted. */ - numelems = zend_hash_num_elements(ar); - size = (numelems * 2 + 1) * sizeof(char *); - - params = (char **)emalloc(size+1); - memset((char *)params, 0, size); - - /** - * Translate a PHP array (HashTable *) into a - * Sablotron array (char **). - */ - _php_sablot_ht_char(ar, params); - } - } - - /** - * If there are more than 4 function arguments, inspect the value - * of the 4 argument and decide whether or not there are Sablotron - * arguments. - */ - if (argc > 4) { - HashTable *ar = HASH_OF(*xslt_args); - if (ar) { - int numelems, - size; - - numelems = zend_hash_num_elements(ar); - size = (numelems * 2 + 1) * sizeof(char *); - - args = (char **)emalloc(size+1); - memset((char *)args, 0, size); - - _php_sablot_ht_char(ar, args); - } - } - - SABLOT_BASIC_CREATE_PROCESSOR(); - ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, Z_STRVAL_PP(xslt_uri), - Z_STRVAL_PP(transform_uri), Z_STRVAL_PP(result_uri), - params, args); - - if (ret) { - SABLOTG(last_errno) = ret; - - S_FREE(params); - S_FREE(args); - - RETURN_FALSE; - } - - ret = SablotGetResultArg(SABLOT_BASIC_HANDLE, Z_STRVAL_PP(result_uri), &tResult); - - if (ret) { - SABLOTG(last_errno) = ret; - - S_FREE(params); - S_FREE(args); - - if (tResult) - SablotFree(tResult); + numelems = zend_hash_num_elements(ar); + size = (numelems * 2 + 1) * sizeof(char *); + + params = (char **)emalloc(size+1); + memset((char *)params, 0, size); + + /** + * Translate a PHP array (HashTable *) into a + * Sablotron array (char **). + */ + _php_sablot_ht_char(ar, params); + } + } + + /** + * If there are more than 4 function arguments, inspect the value + * of the 4 argument and decide whether or not there are Sablotron + * arguments. + */ + if (argc > 4) { + HashTable *ar = HASH_OF(*xslt_args); + if (ar) { + int numelems, + size; + + numelems = zend_hash_num_elements(ar); + size = (numelems * 2 + 1) * sizeof(char *); + + args = (char **)emalloc(size+1); + memset((char *)args, 0, size); + + _php_sablot_ht_char(ar, args); + } + } + + SABLOT_BASIC_CREATE_PROCESSOR(); + ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, Z_STRVAL_PP(xslt_uri), + Z_STRVAL_PP(transform_uri), Z_STRVAL_PP(result_uri), + params, args); + + if (ret) { + SABLOTG(last_errno) = ret; + + S_FREE(params); + S_FREE(args); + + RETURN_FALSE; + } + + ret = SablotGetResultArg(SABLOT_BASIC_HANDLE, Z_STRVAL_PP(result_uri), &tResult); + + if (ret) { + SABLOTG(last_errno) = ret; + + S_FREE(params); + S_FREE(args); + + if (tResult) + SablotFree(tResult); RETURN_FALSE; } else { RETVAL_TRUE; } - if (tResult && - argc == 6) { - ZVAL_STRING(*result, tResult, 1); - } - - S_FREE(params); - S_FREE(args); - - if (tResult) - SablotFree(tResult); + if (tResult && + argc == 6) { + ZVAL_STRING(*result, tResult, 1); + } + + S_FREE(params); + S_FREE(args); + + if (tResult) + SablotFree(tResult); } /* }}} */ @@ -434,67 +434,67 @@ PHP_FUNCTION(xslt_transform) Process data given by input_str through xslt and place the results in the string result. If base is supplied, it will be used as the base URI. */ PHP_FUNCTION(xslt_process) { - zval **xslt, - **input, - **result, - **base; - char *tRes = NULL; - int ret = 0, - argc = ZEND_NUM_ARGS(); - SABLOTLS_FETCH(); - - if (argc < 3 || argc > 4 || - zend_get_parameters_ex(argc, &xslt, &input, &result, &base) == FAILURE) { - WRONG_PARAM_COUNT; - } - multi_convert_to_string_ex(2, xslt, input); - - SABLOT_BASIC_CREATE_PROCESSOR(); - - /** - * If we have more than three arguments that means we have - * a base! - */ - if (argc > 3) { - convert_to_string_ex(base); - - SablotSetBase(SABLOT_BASIC_HANDLE, Z_STRVAL_PP(base)); - } - - /** - * Need to declare args here (to lazy to actually allocate - * it with emalloc() ;) - */ - { - char *args[] = {"/_stylesheet", Z_STRVAL_PP(xslt), - "/_xmlinput", Z_STRVAL_PP(input), - "/_output", NULL, - NULL}; - - ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, "arg:/_stylesheet", - "arg:/_xmlinput", "arg:/_output", - NULL, args); - } - - if (ret) { - SABLOTG(last_errno) = ret; - RETURN_FALSE; - } - - SablotGetResultArg(SABLOT_BASIC_HANDLE, "arg:/_output", &tRes); - if (ret) { - SABLOTG(last_errno) = ret; - RETURN_FALSE; - - if (tRes) - SablotFree(tRes); - } - - if (tRes) { - ZVAL_STRING(*result, tRes, 1); - SablotFree(tRes); - } - RETURN_TRUE; + zval **xslt, + **input, + **result, + **base; + char *tRes = NULL; + int ret = 0, + argc = ZEND_NUM_ARGS(); + SABLOTLS_FETCH(); + + if (argc < 3 || argc > 4 || + zend_get_parameters_ex(argc, &xslt, &input, &result, &base) == FAILURE) { + WRONG_PARAM_COUNT; + } + multi_convert_to_string_ex(2, xslt, input); + + SABLOT_BASIC_CREATE_PROCESSOR(); + + /** + * If we have more than three arguments that means we have + * a base! + */ + if (argc > 3) { + convert_to_string_ex(base); + + SablotSetBase(SABLOT_BASIC_HANDLE, Z_STRVAL_PP(base)); + } + + /** + * Need to declare args here (to lazy to actually allocate + * it with emalloc() ;) + */ + { + char *args[] = {"/_stylesheet", Z_STRVAL_PP(xslt), + "/_xmlinput", Z_STRVAL_PP(input), + "/_output", NULL, + NULL}; + + ret = SablotRunProcessor(SABLOT_BASIC_HANDLE, "arg:/_stylesheet", + "arg:/_xmlinput", "arg:/_output", + NULL, args); + } + + if (ret) { + SABLOTG(last_errno) = ret; + RETURN_FALSE; + } + + SablotGetResultArg(SABLOT_BASIC_HANDLE, "arg:/_output", &tRes); + if (ret) { + SABLOTG(last_errno) = ret; + RETURN_FALSE; + + if (tRes) + SablotFree(tRes); + } + + if (tRes) { + ZVAL_STRING(*result, tRes, 1); + SablotFree(tRes); + } + RETURN_TRUE; } /* }}} */ @@ -503,42 +503,42 @@ PHP_FUNCTION(xslt_process) Create a new XSL processor and return a resource identifier. */ PHP_FUNCTION(xslt_create) { - php_sablot *handle; - SablotHandle p; - int ret; - SABLOTLS_FETCH(); - - ret = SablotCreateProcessor(&p); - - if (ret) { - SABLOTG(last_errno) = ret; - RETURN_FALSE; - } - - handle = (php_sablot *)emalloc(sizeof(php_sablot)); - if (!handle) { - php_error(E_WARNING, "Couldn't allocate PHP-Sablotron Handle"); - RETURN_FALSE; - } - memset(handle, 0, sizeof(php_sablot)); - - handle->p = p; - ret = SablotRegHandler(handle->p, HLR_SAX, (void *)&sax, (void *)handle); - - if (ret) { - SABLOTG(last_errno) = ret; - RETURN_FALSE; - } - - ret = SablotRegHandler(handle->p, HLR_MESSAGE, (void *)&mh, (void *)handle); - - if (ret) { - SABLOTG(last_errno) = ret; - RETURN_FALSE; - } - - ZEND_REGISTER_RESOURCE(return_value, handle, le_sablot); - handle->index = Z_LVAL_P(return_value); + php_sablot *handle; + SablotHandle p; + int ret; + SABLOTLS_FETCH(); + + ret = SablotCreateProcessor(&p); + + if (ret) { + SABLOTG(last_errno) = ret; + RETURN_FALSE; + } + + handle = (php_sablot *)emalloc(sizeof(php_sablot)); + if (!handle) { + php_error(E_WARNING, "Couldn't allocate PHP-Sablotron Handle"); + RETURN_FALSE; + } + memset(handle, 0, sizeof(php_sablot)); + + handle->p = p; + ret = SablotRegHandler(handle->p, HLR_SAX, (void *)&sax, (void *)handle); + + if (ret) { + SABLOTG(last_errno) = ret; + RETURN_FALSE; + } + + ret = SablotRegHandler(handle->p, HLR_MESSAGE, (void *)&mh, (void *)handle); + + if (ret) { + SABLOTG(last_errno) = ret; + RETURN_FALSE; + } + + ZEND_REGISTER_RESOURCE(return_value, handle, le_sablot); + handle->index = Z_LVAL_P(return_value); } /* }}} */ @@ -546,78 +546,84 @@ PHP_FUNCTION(xslt_create) Process the file data_file with the XSL stylesheet xslt_file and parameters xslt_parameters place the results in the buffer pointed to by the result parameter (defaults to "/_result"), args contains the values of the variables in the other parameters. */ PHP_FUNCTION(xslt_run) { - zval **xh, - **xslt_file, - **data_file, - **xslt_result, - **xslt_params, - **xslt_args; - php_sablot *handle; - char **args = NULL, - **params = NULL, - *result = NULL; - int argc = ZEND_NUM_ARGS(), - ret = 0; - SABLOTLS_FETCH(); - - if (argc < 3 || argc > 6 || - zend_get_parameters_ex(argc, &xh, &xslt_file, &data_file, &xslt_result, &xslt_params, &xslt_args) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron handle", le_sablot); - multi_convert_to_string_ex(2, xslt_file, data_file); - - if (argc == 3) { - result = estrdup("arg:/_result"); - } - - if (argc > 3) { - convert_to_string_ex(xslt_result); - result = estrndup(Z_STRVAL_PP(xslt_result), Z_STRLEN_PP(xslt_result)); - } - - if (argc > 4) { - HashTable *ar = HASH_OF(*xslt_params); + zval **xh, + **xslt_file, + **data_file, + **xslt_result, + **xslt_params, + **xslt_args; + php_sablot *handle; + char **args = NULL, + **params = NULL, + *result = NULL; + int argc = ZEND_NUM_ARGS(), + ret = 0; + SABLOTLS_FETCH(); + + if (argc < 3 || argc > 6 || + zend_get_parameters_ex(argc, &xh, &xslt_file, &data_file, &xslt_result, &xslt_params, &xslt_args) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron handle", le_sablot); + multi_convert_to_string_ex(2, xslt_file, data_file); + + if (argc == 3) { + result = estrdup("arg:/_result"); + } + + if (argc > 3) { + convert_to_string_ex(xslt_result); + result = estrndup(Z_STRVAL_PP(xslt_result), Z_STRLEN_PP(xslt_result)); + } + + if (argc > 4) { + HashTable *ar = HASH_OF(*xslt_params); if (ar) { - numelems = zend_hash_num_elements(ar); - size = (numelems * 2 + 1) * sizeof(char *); - - params = (char **)emalloc(size+1); - memset((char *)params, 0, size); - - _php_sablot_ht_char(ar, params); - } - } - - if (argc > 5) { - HashTable *ar = HASH_OF(*xslt_args); + int numelems, + size; + + numelems = zend_hash_num_elements(ar); + size = (numelems * 2 + 1) * sizeof(char *); + + params = (char **)emalloc(size+1); + memset((char *)params, 0, size); + + _php_sablot_ht_char(ar, params); + } + } + + if (argc > 5) { + HashTable *ar = HASH_OF(*xslt_args); if (ar) { - numelems = zend_hash_num_elements(ar); - size = (numelems * 2 + 1) * sizeof(char *); - - args = (char **)emalloc(size+1); - memset((char *)args, 0, size); - - _php_sablot_ht_char(ar, args); - } - } - - ret = SablotRunProcessor(handle->p, Z_STRVAL_PP(xslt_file), Z_STRVAL_PP(data_file), result, params, args); - - if (ret) { - handle->last_errno = ret; - SABLOTG(last_errno) = ret; - S_FREE(params); - S_FREE(args); - S_FREE(result); - RETURN_FALSE; - } - - S_FREE(params); - S_FREE(args); - S_FREE(result); - - RETURN_TRUE; + int numelems, + size; + + numelems = zend_hash_num_elements(ar); + size = (numelems * 2 + 1) * sizeof(char *); + + args = (char **)emalloc(size+1); + memset((char *)args, 0, size); + + _php_sablot_ht_char(ar, args); + } + } + + ret = SablotRunProcessor(handle->p, Z_STRVAL_PP(xslt_file), Z_STRVAL_PP(data_file), result, params, args); + + if (ret) { + handle->last_errno = ret; + SABLOTG(last_errno) = ret; + S_FREE(params); + S_FREE(args); + S_FREE(result); + RETURN_FALSE; + } + + S_FREE(params); + S_FREE(args); + S_FREE(result); + + RETURN_TRUE; } /* }}} */ @@ -625,36 +631,36 @@ PHP_FUNCTION(xslt_run) Sets a logfile for Sablotron to place all of its error messages */ PHP_FUNCTION(xslt_openlog) { - zval **xh, - **logfile, - **opt_loglevel; - php_sablot *handle; - int ret = 0, - loglevel = 0, - argc = ZEND_NUM_ARGS(); + zval **xh, + **logfile, + **opt_loglevel; + php_sablot *handle; + int ret = 0, + loglevel = 0, + argc = ZEND_NUM_ARGS(); SABLOTLS_FETCH(); - - if (argc < 2 || argc > 3 || - zend_get_parameters_ex(argc, &xh, &logfile, &opt_loglevel) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron", le_sablot); - convert_to_string_ex(logfile); - - if (argc > 2) { - convert_to_long_ex(opt_loglevel); - loglevel = Z_LVAL_PP(opt_loglevel); - } - - ret = SablotSetLog(handle->p, (const char *)Z_STRVAL_PP(logfile), loglevel); - - if (ret) { - handle->last_errno = ret; - SABLOTG(last_errno) = ret; - RETURN_FALSE; - } else { - RETURN_TRUE; - } + + if (argc < 2 || argc > 3 || + zend_get_parameters_ex(argc, &xh, &logfile, &opt_loglevel) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron", le_sablot); + convert_to_string_ex(logfile); + + if (argc > 2) { + convert_to_long_ex(opt_loglevel); + loglevel = Z_LVAL_PP(opt_loglevel); + } + + ret = SablotSetLog(handle->p, (const char *)Z_STRVAL_PP(logfile), loglevel); + + if (ret) { + handle->last_errno = ret; + SABLOTG(last_errno) = ret; + RETURN_FALSE; + } else { + RETURN_TRUE; + } } /* }}} */ @@ -662,23 +668,23 @@ PHP_FUNCTION(xslt_openlog) Clear the logfile for a given instance Sablotron */ PHP_FUNCTION(xslt_closelog) { - zval **xh; - php_sablot *handle; - int ret; - SABLOTLS_FETCH(); - - if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &xh) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron", le_sablot); - - ret = SablotSetLog(handle->p, (const char *)NULL, 1); - - if (ret) { - RETURN_FALSE; - } - RETURN_TRUE; + zval **xh; + php_sablot *handle; + int ret; + SABLOTLS_FETCH(); + + if (ZEND_NUM_ARGS() != 1 || + zend_get_parameters_ex(1, &xh) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron", le_sablot); + + ret = SablotSetLog(handle->p, (const char *)NULL, 1); + + if (ret) { + RETURN_FALSE; + } + RETURN_TRUE; } /* }}} */ @@ -686,45 +692,45 @@ PHP_FUNCTION(xslt_closelog) Fetch a result buffer on process handle, xh, with name, result_name, if name is not given than the "/_result" buffer is fetched. */ PHP_FUNCTION(xslt_fetch_result) { - zval **xh, - **result_name; - php_sablot *handle; - char *value = NULL, - *rname = NULL; - int argc = ZEND_NUM_ARGS(), - ret = 0; - SABLOTLS_FETCH(); - - if (argc < 1 || argc > 2 || - zend_get_parameters_ex(argc, &xh, &result_name) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); - - if (argc > 1) { - convert_to_string_ex(result_name); - rname = estrndup(Z_STRVAL_PP(result_name), Z_STRLEN_PP(result_name)); - } else { - rname = estrdup("/_result"); - } - - ret = SablotGetResultArg(handle->p, rname, &value); - - S_FREE(rname); - - if (ret) { - handle->last_errno = ret; - SABLOTG(last_errno) = ret; - if (value) { - SablotFree(value); - } - RETURN_FALSE; - } - - if (value) { - RETVAL_STRING(value, 1); - SablotFree(value); - } + zval **xh, + **result_name; + php_sablot *handle; + char *value = NULL, + *rname = NULL; + int argc = ZEND_NUM_ARGS(), + ret = 0; + SABLOTLS_FETCH(); + + if (argc < 1 || argc > 2 || + zend_get_parameters_ex(argc, &xh, &result_name) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); + + if (argc > 1) { + convert_to_string_ex(result_name); + rname = estrndup(Z_STRVAL_PP(result_name), Z_STRLEN_PP(result_name)); + } else { + rname = estrdup("/_result"); + } + + ret = SablotGetResultArg(handle->p, rname, &value); + + S_FREE(rname); + + if (ret) { + handle->last_errno = ret; + SABLOTG(last_errno) = ret; + if (value) { + SablotFree(value); + } + RETURN_FALSE; + } + + if (value) { + RETVAL_STRING(value, 1); + SablotFree(value); + } } /* }}} */ @@ -732,17 +738,17 @@ PHP_FUNCTION(xslt_fetch_result) Free resources associated with a xslt handle. */ PHP_FUNCTION(xslt_free) { - zval **xh; - php_sablot *handle; - SABLOTLS_FETCH(); - - if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &xh) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); - zend_list_delete(Z_LVAL_PP(xh)); + zval **xh; + php_sablot *handle; + SABLOTLS_FETCH(); + + if (ZEND_NUM_ARGS() != 1 || + zend_get_parameters_ex(1, &xh) == FAILURE) { + WRONG_PARAM_COUNT; + } + + ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); + zend_list_delete(Z_LVAL_PP(xh)); } /* }}} */ @@ -750,63 +756,63 @@ PHP_FUNCTION(xslt_free) Set SAX Handlers on the resource handle given by xh. */ PHP_FUNCTION(xslt_set_sax_handler) { - zval **xh, - **handlers, - **indiv_handlers; - php_sablot *handle; - HashTable *handlers_list; - char *string_key = NULL; - ulong num_key; - SABLOTLS_FETCH(); - - - if (ZEND_NUM_ARGS() != 2 || - zend_get_parameters_ex(2, &xh, &handlers) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); - - handlers_list = HASH_OF(*handlers); - - for (zend_hash_internal_pointer_reset(handlers_list); - zend_hash_get_current_data(handlers_list, (void **)&indiv_handlers) == SUCCESS; - zend_hash_move_forward(handlers_list)) { - - SEPARATE_ZVAL(indiv_handlers); - - if (zend_hash_get_current_key(handlers_list, &string_key, &num_key) == HASH_KEY_IS_LONG) { - php_error(E_WARNING, "The Keys of the first dimension of your array must be strings"); - RETURN_FALSE; - } - - - if (!strcasecmp("document", string_key)) { - _php_sablot_handler_pair(handle, - &handle->startDocHandler, &handle->endDocHandler, - indiv_handlers); - } else if (!strcasecmp("element", string_key)) { - _php_sablot_handler_pair(handle, - &handle->startElementHandler, &handle->endElementHandler, - indiv_handlers); - } else if (!strcasecmp("namespace", string_key)) { - _php_sablot_handler_pair(handle, - &handle->startNamespaceHandler, &handle->endNamespaceHandler, - indiv_handlers); - } else if (!strcasecmp("comment", string_key)) { - zval_add_ref(indiv_handlers); - handle->commentHandler = *indiv_handlers; - } else if (!strcasecmp("pi", string_key)) { - zval_add_ref(indiv_handlers); - handle->PIHandler = *indiv_handlers; - } else if (!strcasecmp("characters", string_key)) { - zval_add_ref(indiv_handlers); - handle->charactersHandler = *indiv_handlers; - } else { - php_error(E_WARNING, "Invalid option: %s", string_key); - } - - S_FREE(string_key); - } + zval **xh, + **handlers, + **indiv_handlers; + php_sablot *handle; + HashTable *handlers_list; + char *string_key = NULL; + ulong num_key; + SABLOTLS_FETCH(); + + + if (ZEND_NUM_ARGS() != 2 || + zend_get_parameters_ex(2, &xh, &handlers) == FAILURE) { + WRONG_PARAM_COUNT; + } + ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); + + handlers_list = HASH_OF(*handlers); + + for (zend_hash_internal_pointer_reset(handlers_list); + zend_hash_get_current_data(handlers_list, (void **)&indiv_handlers) == SUCCESS; + zend_hash_move_forward(handlers_list)) { + + SEPARATE_ZVAL(indiv_handlers); + + if (zend_hash_get_current_key(handlers_list, &string_key, &num_key) == HASH_KEY_IS_LONG) { + php_error(E_WARNING, "The Keys of the first dimension of your array must be strings"); + RETURN_FALSE; + } + + + if (!strcasecmp("document", string_key)) { + _php_sablot_handler_pair(handle, + &handle->startDocHandler, &handle->endDocHandler, + indiv_handlers); + } else if (!strcasecmp("element", string_key)) { + _php_sablot_handler_pair(handle, + &handle->startElementHandler, &handle->endElementHandler, + indiv_handlers); + } else if (!strcasecmp("namespace", string_key)) { + _php_sablot_handler_pair(handle, + &handle->startNamespaceHandler, &handle->endNamespaceHandler, + indiv_handlers); + } else if (!strcasecmp("comment", string_key)) { + zval_add_ref(indiv_handlers); + handle->commentHandler = *indiv_handlers; + } else if (!strcasecmp("pi", string_key)) { + zval_add_ref(indiv_handlers); + handle->PIHandler = *indiv_handlers; + } else if (!strcasecmp("characters", string_key)) { + zval_add_ref(indiv_handlers); + handle->charactersHandler = *indiv_handlers; + } else { + php_error(E_WARNING, "Invalid option: %s", string_key); + } + + S_FREE(string_key); + } } /* }}} */ @@ -818,42 +824,42 @@ PHP_FUNCTION(xslt_set_sax_handler) Return the error string related to a given error handle. If no handle is given the last error that occurred anywhere is returned. */ PHP_FUNCTION(xslt_error) { - zval **xh; - php_sablot *handle; - int serrno = 0, - argc = ZEND_NUM_ARGS(); - SABLOTLS_FETCH(); - - if (argc < 0 || argc > 1 || - zend_get_parameters_ex(argc, &xh) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (argc) { - ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); - - if (handle->errors) { - if (array_init(return_value) == FAILURE) { - php_error(E_WARNING, "Cannot initialize return array from xslt_error()"); - RETURN_FALSE; - } - - handle->errors = handle->errors_start.next; - while (handle->errors) { - add_assoc_string(return_value, handle->errors->key, handle->errors->value, 0); - handle->errors = handle->errors->next; - } - add_assoc_string(return_value, "errstr", (char *)SablotGetMsgText(handle->last_errno), 1); - add_assoc_long(return_value, "errno", handle->last_errno); - return; - } - - serrno = handle->last_errno; - } else { - serrno = SABLOTG(last_errno); - } - - RETURN_STRING((char *)SablotGetMsgText(serrno), 1); + zval **xh; + php_sablot *handle; + int serrno = 0, + argc = ZEND_NUM_ARGS(); + SABLOTLS_FETCH(); + + if (argc < 0 || argc > 1 || + zend_get_parameters_ex(argc, &xh) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if (argc) { + ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); + + if (handle->errors) { + if (array_init(return_value) == FAILURE) { + php_error(E_WARNING, "Cannot initialize return array from xslt_error()"); + RETURN_FALSE; + } + + handle->errors = handle->errors_start.next; + while (handle->errors) { + add_assoc_string(return_value, handle->errors->key, handle->errors->value, 0); + handle->errors = handle->errors->next; + } + add_assoc_string(return_value, "errstr", (char *)SablotGetMsgText(handle->last_errno), 1); + add_assoc_long(return_value, "errno", handle->last_errno); + return; + } + + serrno = handle->last_errno; + } else { + serrno = SABLOTG(last_errno); + } + + RETURN_STRING((char *)SablotGetMsgText(serrno), 1); } /* }}} */ @@ -861,23 +867,23 @@ PHP_FUNCTION(xslt_error) Return the error number related to a given error handle. If no handle is given the last error number that occurred anywhere is returned. */ PHP_FUNCTION(xslt_errno) { - zval **xh; - php_sablot *handle; - int argc = ZEND_NUM_ARGS(); - - SABLOTLS_FETCH(); - - if (argc < 0 || argc > 1 || - zend_get_parameters_ex(argc, &xh) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (argc) { - ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); - RETURN_LONG(handle->last_errno); - } else { - RETURN_LONG(SABLOTG(last_errno)); - } + zval **xh; + php_sablot *handle; + int argc = ZEND_NUM_ARGS(); + + SABLOTLS_FETCH(); + + if (argc < 0 || argc > 1 || + zend_get_parameters_ex(argc, &xh) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if (argc) { + ZEND_FETCH_RESOURCE(handle, php_sablot *, xh, -1, "PHP-Sablotron Handle", le_sablot); + RETURN_LONG(handle->last_errno); + } else { + RETURN_LONG(SABLOTG(last_errno)); + } } /* }}} */ @@ -889,7 +895,7 @@ PHP_FUNCTION(xslt_set_error_handler) php_sablot *handle; int argc = ZEND_NUM_ARGS(); - SABLOTLS_FETCH(); + SABLOTLS_FETCH(); if (argc > 2 || argc < 1 || zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) { @@ -922,33 +928,33 @@ PHP_FUNCTION(xslt_set_error_handler) Set the handler functions from a two item array */ static void _php_sablot_handler_pair(php_sablot *handle, zval **first_func, zval **second_func, zval **indiv_handlers) { - HashTable *second_level = HASH_OF(*indiv_handlers); - zval **handler; - int item = 0; - - for (zend_hash_internal_pointer_reset(second_level); - zend_hash_get_current_data(second_level, (void **)&handler) == SUCCESS; - zend_hash_move_forward(second_level)) { - - SEPARATE_ZVAL(handler); - zval_add_ref(handler); - - switch (item) - { - case 0: - *first_func = *handler; - break; - case 1: - *second_func = *handler; - break; - default: - convert_to_string_ex(handler); - php_error(E_WARNING, "Sorry, too many elements, %s discarded", Z_STRVAL_PP(handler)); - zval_del_ref(handler); - break; - } - item++; - } + HashTable *second_level = HASH_OF(*indiv_handlers); + zval **handler; + int item = 0; + + for (zend_hash_internal_pointer_reset(second_level); + zend_hash_get_current_data(second_level, (void **)&handler) == SUCCESS; + zend_hash_move_forward(second_level)) { + + SEPARATE_ZVAL(handler); + zval_add_ref(handler); + + switch (item) + { + case 0: + *first_func = *handler; + break; + case 1: + *second_func = *handler; + break; + default: + convert_to_string_ex(handler); + php_error(E_WARNING, "Sorry, too many elements, %s discarded", Z_STRVAL_PP(handler)); + zval_del_ref(handler); + break; + } + item++; + } } /* }}} */ @@ -956,21 +962,21 @@ static void _php_sablot_handler_pair(php_sablot *handle, zval **first_func, zval Call a sablot call handler function, wrapper for call_user_function() */ static void _php_sablot_call_handler_function(zval *handlerName, int argc, zval **args, char *function_name) { - zval *retval; - int i; - ELS_FETCH(); - MAKE_STD_ZVAL(retval); - - if (call_user_function(EG(function_table), NULL, handlerName, retval, argc, args) == FAILURE) { - php_error(E_WARNING, "Sorry, couldn't call %s handler", function_name); - } - - zval_dtor(retval); - efree(retval); - - for (i=0; istartDocHandler) { - zval *args[1]; - args[0] = _php_sablot_resource_zval(handle->index); + if (handle->startDocHandler) { + zval *args[1]; + args[0] = _php_sablot_resource_zval(handle->index); - _php_sablot_call_handler_function(handle->startDocHandler, 1, args, "start document"); - } + _php_sablot_call_handler_function(handle->startDocHandler, 1, args, "start document"); + } } /* }}} */ @@ -993,30 +999,30 @@ static SAX_RETURN _php_sablot_sax_startDoc(void *userData) Start Element handler */ static SAX_RETURN _php_sablot_sax_startElement(void *userData, const char *name, const char **attributes) { - php_sablot *handle = (php_sablot *)userData; - - if (handle->startElementHandler) { - zval *args[3]; - - args[0] = _php_sablot_resource_zval(handle->index); - args[1] = _php_sablot_string_zval(name); - - MAKE_STD_ZVAL(args[2]); - if (array_init(args[2]) == FAILURE) { - php_error(E_WARNING, "Couldn't initialize array to be passed to start element handler"); - return; - } - - while (attributes && *attributes) { - char *key = (char *)attributes[0]; - zval *value = _php_sablot_string_zval(attributes[1]); - - add_assoc_string(args[2], key, Z_STRVAL_P(value), 0); - attributes += 2; - } - - _php_sablot_call_handler_function(handle->startElementHandler, 3, args, "start element"); - } + php_sablot *handle = (php_sablot *)userData; + + if (handle->startElementHandler) { + zval *args[3]; + + args[0] = _php_sablot_resource_zval(handle->index); + args[1] = _php_sablot_string_zval(name); + + MAKE_STD_ZVAL(args[2]); + if (array_init(args[2]) == FAILURE) { + php_error(E_WARNING, "Couldn't initialize array to be passed to start element handler"); + return; + } + + while (attributes && *attributes) { + char *key = (char *)attributes[0]; + zval *value = _php_sablot_string_zval(attributes[1]); + + add_assoc_string(args[2], key, Z_STRVAL_P(value), 0); + attributes += 2; + } + + _php_sablot_call_handler_function(handle->startElementHandler, 3, args, "start element"); + } } /* }}} */ @@ -1024,16 +1030,16 @@ static SAX_RETURN _php_sablot_sax_startElement(void *userData, const char *name, End element handler */ static SAX_RETURN _php_sablot_sax_endElement(void *userData, const char *name) { - php_sablot *handle = (php_sablot *)userData; - - if (handle->endElementHandler) { - zval *args[2]; - - args[0] = _php_sablot_resource_zval(handle->index); - args[1] = _php_sablot_string_zval(name); - - _php_sablot_call_handler_function(handle->endElementHandler, 2, args, "end element"); - } + php_sablot *handle = (php_sablot *)userData; + + if (handle->endElementHandler) { + zval *args[2]; + + args[0] = _php_sablot_resource_zval(handle->index); + args[1] = _php_sablot_string_zval(name); + + _php_sablot_call_handler_function(handle->endElementHandler, 2, args, "end element"); + } } /* }}} */ @@ -1041,17 +1047,17 @@ static SAX_RETURN _php_sablot_sax_endElement(void *userData, const char *name) Start Namespace handler */ static SAX_RETURN _php_sablot_sax_startNamespace(void *userData, const char *prefix, const char *uri) { - php_sablot *handle = (php_sablot *)userData; - - if (handle->startNamespaceHandler) { - zval *args[3]; - - args[0] = _php_sablot_resource_zval(handle->index); - args[1] = _php_sablot_string_zval(prefix); - args[2] = _php_sablot_string_zval(uri); - - _php_sablot_call_handler_function(handle->startNamespaceHandler, 3, args, "start namespace"); - } + php_sablot *handle = (php_sablot *)userData; + + if (handle->startNamespaceHandler) { + zval *args[3]; + + args[0] = _php_sablot_resource_zval(handle->index); + args[1] = _php_sablot_string_zval(prefix); + args[2] = _php_sablot_string_zval(uri); + + _php_sablot_call_handler_function(handle->startNamespaceHandler, 3, args, "start namespace"); + } } /* }}} */ @@ -1059,16 +1065,16 @@ static SAX_RETURN _php_sablot_sax_startNamespace(void *userData, const char *pre End Namespace Handler */ static SAX_RETURN _php_sablot_sax_endNamespace(void *userData, const char *prefix) { - php_sablot *handle = (php_sablot *)userData; - - if (handle->endNamespaceHandler) { - zval *args[2]; - - args[0] = _php_sablot_resource_zval(handle->index); - args[1] = _php_sablot_string_zval(prefix); - - _php_sablot_call_handler_function(handle->endNamespaceHandler, 2, args, "end namespace"); - } + php_sablot *handle = (php_sablot *)userData; + + if (handle->endNamespaceHandler) { + zval *args[2]; + + args[0] = _php_sablot_resource_zval(handle->index); + args[1] = _php_sablot_string_zval(prefix); + + _php_sablot_call_handler_function(handle->endNamespaceHandler, 2, args, "end namespace"); + } } /* }}} */ @@ -1076,16 +1082,16 @@ static SAX_RETURN _php_sablot_sax_endNamespace(void *userData, const char *prefi Comment Handler */ static SAX_RETURN _php_sablot_sax_comment(void *userData, const char *contents) { - php_sablot *handle = (php_sablot *)userData; - - if (handle->commentHandler) { - zval *args[2]; - - args[0] = _php_sablot_resource_zval(handle->index); - args[1] = _php_sablot_string_zval(contents); - - _php_sablot_call_handler_function(handle->commentHandler, 2, args, "comment"); - } + php_sablot *handle = (php_sablot *)userData; + + if (handle->commentHandler) { + zval *args[2]; + + args[0] = _php_sablot_resource_zval(handle->index); + args[1] = _php_sablot_string_zval(contents); + + _php_sablot_call_handler_function(handle->commentHandler, 2, args, "comment"); + } } /* }}} */ @@ -1093,17 +1099,17 @@ static SAX_RETURN _php_sablot_sax_comment(void *userData, const char *contents) Processing Instruction Handler */ static SAX_RETURN _php_sablot_sax_PI(void *userData, const char *target, const char *contents) { - php_sablot *handle = (php_sablot *)userData; - - if (handle->PIHandler) { - zval *args[3]; - - args[0] = _php_sablot_resource_zval(handle->index); - args[1] = _php_sablot_string_zval(target); - args[2] = _php_sablot_string_zval(contents); - - _php_sablot_call_handler_function(handle->PIHandler, 3, args, "PI Handler"); - } + php_sablot *handle = (php_sablot *)userData; + + if (handle->PIHandler) { + zval *args[3]; + + args[0] = _php_sablot_resource_zval(handle->index); + args[1] = _php_sablot_string_zval(target); + args[2] = _php_sablot_string_zval(contents); + + _php_sablot_call_handler_function(handle->PIHandler, 3, args, "PI Handler"); + } } /* }}} */ @@ -1111,16 +1117,16 @@ static SAX_RETURN _php_sablot_sax_PI(void *userData, const char *target, const c Character handler */ static SAX_RETURN _php_sablot_sax_characters(void *userData, const char *contents, int length) { - php_sablot *handle = (php_sablot *)userData; - - if (handle->charactersHandler) { - zval *args[2]; - - args[0] = _php_sablot_resource_zval(handle->index); - args[1] = _php_sablot_string_zval(contents); - - _php_sablot_call_handler_function(handle->charactersHandler, 2, args, "characters"); - } + php_sablot *handle = (php_sablot *)userData; + + if (handle->charactersHandler) { + zval *args[2]; + + args[0] = _php_sablot_resource_zval(handle->index); + args[1] = _php_sablot_string_zval(contents); + + _php_sablot_call_handler_function(handle->charactersHandler, 2, args, "characters"); + } } /* }}} */ @@ -1128,15 +1134,15 @@ static SAX_RETURN _php_sablot_sax_characters(void *userData, const char *content End document handler */ static SAX_RETURN _php_sablot_sax_endDoc(void *userData) { - php_sablot *handle = (php_sablot *)userData; - - if (handle->endDocHandler) { - zval *args[1]; - - args[0] = _php_sablot_resource_zval(handle->index); - - _php_sablot_call_handler_function(handle->endDocHandler, 1, args, "end document"); - } + php_sablot *handle = (php_sablot *)userData; + + if (handle->endDocHandler) { + zval *args[1]; + + args[0] = _php_sablot_resource_zval(handle->index); + + _php_sablot_call_handler_function(handle->endDocHandler, 1, args, "end document"); + } } /* }}} */ @@ -1149,7 +1155,7 @@ static SAX_RETURN _php_sablot_sax_endDoc(void *userData) Makes an error code, currently does nothing */ static MH_ERROR _php_sablot_make_code(void *userData, SablotHandle p, int severity, unsigned short facility, unsigned short code) { - return(code); + return(code); } /* }}} */ @@ -1171,7 +1177,7 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code, idx, len; - SABLOTLS_FETCH(); + SABLOTLS_FETCH(); if (userData == NULL) { SABLOT_FREE_ERROR_HANDLE(SABLOTG_HANDLE); @@ -1223,7 +1229,6 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code, if (errorHandler) { zval *retval; - int i; ELS_FETCH(); MAKE_STD_ZVAL(retval); @@ -1270,7 +1275,7 @@ static MH_ERROR _php_sablot_error(void *userData, SablotHandle p, MH_ERROR code, _php_sablot_standard_error(errors, isAdvanced ? handle->errors_start : SABLOTG(errors_start), code, level); } - return(0); + return(0); } /* }}} */ @@ -1321,22 +1326,22 @@ static void _php_sablot_standard_error(php_sablot_error *errors, php_sablot_erro Free a Sablot handle */ static void _php_sablot_free_processor(zend_rsrc_list_entry *rsrc) { - php_sablot *handle = (php_sablot *)rsrc->ptr; - if (handle->p) { - SablotUnregHandler(handle->p, HLR_MESSAGE, NULL, NULL); - SablotUnregHandler(handle->p, HLR_SAX, NULL, NULL); - SablotDestroyProcessor(handle->p); - } - - FUNCH_FREE(handle->startDocHandler); - FUNCH_FREE(handle->startElementHandler); - FUNCH_FREE(handle->endElementHandler); - FUNCH_FREE(handle->startNamespaceHandler); - FUNCH_FREE(handle->endNamespaceHandler); - FUNCH_FREE(handle->commentHandler); - FUNCH_FREE(handle->PIHandler); - FUNCH_FREE(handle->charactersHandler); - FUNCH_FREE(handle->endDocHandler); + php_sablot *handle = (php_sablot *)rsrc->ptr; + if (handle->p) { + SablotUnregHandler(handle->p, HLR_MESSAGE, NULL, NULL); + SablotUnregHandler(handle->p, HLR_SAX, NULL, NULL); + SablotDestroyProcessor(handle->p); + } + + FUNCH_FREE(handle->startDocHandler); + FUNCH_FREE(handle->startElementHandler); + FUNCH_FREE(handle->endElementHandler); + FUNCH_FREE(handle->startNamespaceHandler); + FUNCH_FREE(handle->endNamespaceHandler); + FUNCH_FREE(handle->commentHandler); + FUNCH_FREE(handle->PIHandler); + FUNCH_FREE(handle->charactersHandler); + FUNCH_FREE(handle->endDocHandler); SABLOT_FREE_ERROR_HANDLE(*handle); } @@ -1350,44 +1355,44 @@ static void _php_sablot_free_processor(zend_rsrc_list_entry *rsrc) Translates a PHP array to a Sablotron character array */ static void _php_sablot_ht_char(HashTable *php, char **sablot) { - zval **value; - char *string_key = NULL; - ulong num_key; - int i = 0; - - for (zend_hash_internal_pointer_reset(php); - zend_hash_get_current_data(php, (void **)&value) == SUCCESS; - zend_hash_move_forward(php)) { - SEPARATE_ZVAL(value); - convert_to_string_ex(value); - - switch (zend_hash_get_current_key(php, &string_key, &num_key)) { - case HASH_KEY_IS_LONG: - sablot[i++] = Z_STRVAL_PP(value); - break; - case HASH_KEY_IS_STRING: - sablot[i++] = string_key; - sablot[i++] = Z_STRVAL_PP(value); - break; - } - } - sablot[i++] = NULL; + zval **value; + char *string_key = NULL; + ulong num_key; + int i = 0; + + for (zend_hash_internal_pointer_reset(php); + zend_hash_get_current_data(php, (void **)&value) == SUCCESS; + zend_hash_move_forward(php)) { + SEPARATE_ZVAL(value); + convert_to_string_ex(value); + + switch (zend_hash_get_current_key(php, &string_key, &num_key)) { + case HASH_KEY_IS_LONG: + sablot[i++] = Z_STRVAL_PP(value); + break; + case HASH_KEY_IS_STRING: + sablot[i++] = string_key; + sablot[i++] = Z_STRVAL_PP(value); + break; + } + } + sablot[i++] = NULL; } /* {{{ _php_sablot_string_zval() Converts a Sablotron string to a zval */ static zval *_php_sablot_string_zval(const char *str) { - zval *ret; - int len = strlen(str); + zval *ret; + int len = strlen(str); - MAKE_STD_ZVAL(ret); - - Z_TYPE_P(ret) = IS_STRING; - Z_STRLEN_P(ret) = len; - Z_STRVAL_P(ret) = estrndup(str, len); + MAKE_STD_ZVAL(ret); + + Z_TYPE_P(ret) = IS_STRING; + Z_STRLEN_P(ret) = len; + Z_STRVAL_P(ret) = estrndup(str, len); - return(ret); + return(ret); } /* }}} */ @@ -1395,15 +1400,15 @@ static zval *_php_sablot_string_zval(const char *str) Converts a long identifier to a resource id */ static zval *_php_sablot_resource_zval(long value) { - zval *ret; - MAKE_STD_ZVAL(ret); - - Z_TYPE_P(ret) = IS_RESOURCE; - Z_LVAL_P(ret) = value; - - zend_list_addref(value); - - return(ret); + zval *ret; + MAKE_STD_ZVAL(ret); + + Z_TYPE_P(ret) = IS_RESOURCE; + Z_LVAL_P(ret) = value; + + zend_list_addref(value); + + return(ret); } /* }}} */