From 48ef3a2f55b81aa47014912e2ee9b15c3b11c7ff Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Fri, 9 May 2003 09:56:51 +0000 Subject: [PATCH] MFH --- ext/fdf/fdf.c | 124 +++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 67 deletions(-) diff --git a/ext/fdf/fdf.c b/ext/fdf/fdf.c index 2636ab486c..fdd477b96a 100644 --- a/ext/fdf/fdf.c +++ b/ext/fdf/fdf.c @@ -13,7 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Uwe Steinmann | - | Hartmut Holzgraefe | + | Hartmut Holzgraefe | +----------------------------------------------------------------------+ */ @@ -129,8 +129,6 @@ static sapi_post_entry php_fdf_post_entry = { */ PHP_MINIT_FUNCTION(fdf) { - FDFErc err; - le_fdf = zend_register_list_destructors_ex(phpi_FDFClose, NULL, "fdf", module_number); /* add handler for Acrobat FDF form post requests */ @@ -172,9 +170,9 @@ PHP_MINIT_FUNCTION(fdf) #ifdef PHP_WIN32 return SUCCESS; +#else + return (FDFInitialize() == FDFErcOK) ? SUCCESS : FAILURE; #endif - if((err = FDFInitialize()) == FDFErcOK) return SUCCESS; - return FAILURE; } /* }}} */ @@ -201,20 +199,18 @@ PHP_MINFO_FUNCTION(fdf) */ PHP_MSHUTDOWN_FUNCTION(fdf) { - FDFErc err; - /* remove handler for Acrobat FDF form post requests */ sapi_unregister_post_entry(&php_fdf_post_entry); #ifdef PHP_WIN32 return SUCCESS; +#else + return (FDFFinalize() == FDFErcOK) ? SUCCESS : FAILURE; #endif - if((err = FDFFinalize()) == FDFErcOK) return SUCCESS; - return FAILURE; } /* }}} */ -/* {{{ proto int fdf_open(string filename) +/* {{{ proto resource fdf_open(string filename) Opens a new FDF document */ PHP_FUNCTION(fdf_open) { @@ -239,7 +235,7 @@ PHP_FUNCTION(fdf_open) } /* }}} */ -/* {{{ proto int fdf_open_string(string fdf_data) +/* {{{ proto resource fdf_open_string(string fdf_data) Opens a new FDF document from string */ PHP_FUNCTION(fdf_open_string) { @@ -276,7 +272,7 @@ PHP_FUNCTION(fdf_open_string) } /* }}} */ -/* {{{ proto int fdf_create(void) +/* {{{ proto resource fdf_create(void) Creates a new FDF document */ PHP_FUNCTION(fdf_create) { @@ -358,10 +354,7 @@ PHP_FUNCTION(fdf_get_value) } #if HAVE_FDFTK_5 } else if((err == FDFErcValueIsArray) && (which == -1)) { - if (array_init(return_value) == FAILURE) { - efree(buffer); - FDF_FAILURE(FDFErcInternalError); - } + array_init(return_value); which = 0; do { err = FDFGetNthValue(fdf, fieldname, which, buffer, size-2, &nr); @@ -901,7 +894,7 @@ PHP_FUNCTION(fdf_add_template) filespec.ID[1] = NULL; filespec.bVolatile = false; - err = FDFAddTemplate(fdf, Z_LVAL_PP(newpage), &filespec, Z_STRVAL_PP(template), Z_LVAL_PP(rename)); + err = FDFAddTemplate(fdf, (unsigned short)(Z_LVAL_PP(newpage)), &filespec, Z_STRVAL_PP(template), (unsigned short)(Z_LVAL_PP(rename))); if(err != FDFErcOK) { FDF_FAILURE(err); } @@ -994,7 +987,7 @@ PHP_FUNCTION(fdf_set_opt) } /* }}} */ -/* {{{ proto mixed fdf_get_option(resource fdfdof, string fieldname [, int element]) +/* {{{ proto mixed fdf_get_opt(resource fdfdof, string fieldname [, int element]) Gets a value from the opt array of a field */ PHP_FUNCTION(fdf_get_opt) { zval *r_fdf; @@ -1040,9 +1033,7 @@ PHP_FUNCTION(fdf_get_opt) { if(err != FDFErcOK) { FDF_FAILURE(err); } - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } + array_init(return_value); add_next_index_stringl(return_value, buf1, strlen(buf1), 1); add_next_index_stringl(return_value, buf2, strlen(buf2), 1); efree(buf1); @@ -1104,7 +1095,7 @@ PHP_FUNCTION(fdf_set_javascript_action) } /* }}} */ -/* {{{ proto bool fdf_set_encoding(int fdf_document, string encoding) +/* {{{ proto bool fdf_set_encoding(resource fdf_document, string encoding) Sets FDF encoding (either "Shift-JIS" or "Unicode") */ PHP_FUNCTION(fdf_set_encoding) { @@ -1199,14 +1190,14 @@ SAPI_POST_HANDLER_FUNC(fdf_post_handler) } /* }}} */ -/* {{{ int fdf_errno(void) +/* {{{ proto int fdf_errno(void) Gets error code for last operation */ PHP_FUNCTION(fdf_errno) { RETURN_LONG((long)FDF_G(error)); } /* }}} */ -/* {{{ string fdf_error([int errno]) +/* {{{ proto string fdf_error([int errno]) Gets error description for error code */ PHP_FUNCTION(fdf_error) { FDFErc err; @@ -1473,9 +1464,7 @@ PHP_FUNCTION(fdf_get_attachment) { FDF_FAILURE(err); } - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } + array_init(return_value); add_assoc_string(return_value, "path", pathbuf, 1); add_assoc_string(return_value, "type", mimebuf, 1); stat(pathbuf, &statBuf); @@ -1485,53 +1474,54 @@ PHP_FUNCTION(fdf_get_attachment) { #endif /* {{{ enum_values_callback */ - static ASBool enum_values_callback(char *name, char *value, void *userdata) { - zval *retval_ptr, *z_name, *z_value, **args[3]; - long retval = 0; - int numargs = 2; - TSRMLS_FETCH(); - - MAKE_STD_ZVAL(z_name); - ZVAL_STRING(z_name, name, 1); - args[0] = &z_name; - - if(*value) { /* simple value */ - MAKE_STD_ZVAL(z_value); - ZVAL_STRING(z_value, value, 1); - args[1] = &z_value; - } else { /* empty value *might* be an array */ - /* todo do it like fdf_get_value (or re-implement yourself?) */ - } - - if(userdata) { - args[2] = (zval **)userdata; - numargs++; - } - - if (call_user_function_ex(EG(function_table), +static ASBool enum_values_callback(char *name, char *value, void *userdata) +{ + zval *retval_ptr, *z_name, *z_value, **args[3]; + long retval = 0; + int numargs = 2; + TSRMLS_FETCH(); + + MAKE_STD_ZVAL(z_name); + ZVAL_STRING(z_name, name, 1); + args[0] = &z_name; + + if (*value) { /* simple value */ + MAKE_STD_ZVAL(z_value); + ZVAL_STRING(z_value, value, 1); + args[1] = &z_value; + } else { /* empty value *might* be an array */ + /* TODO: do it like fdf_get_value (or re-implement yourself?) */ + } + + if (userdata) { + args[2] = (zval **) userdata; + numargs++; + } + + if (call_user_function_ex(EG(function_table), NULL, FDF_G(enum_callback), &retval_ptr, numargs, args, - 0, NULL TSRMLS_CC)==SUCCESS - && retval_ptr) { - - convert_to_long_ex(&retval_ptr); - retval = Z_LVAL_P(retval_ptr); - zval_ptr_dtor(&retval_ptr); - } else { + 0, NULL TSRMLS_CC) == SUCCESS + && retval_ptr) { + + convert_to_long_ex(&retval_ptr); + retval = Z_LVAL_P(retval_ptr); + zval_ptr_dtor(&retval_ptr); + } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "callback failed"); - } + } - zval_ptr_dtor(&z_name); - zval_ptr_dtor(&z_value); + zval_ptr_dtor(&z_name); + zval_ptr_dtor(&z_value); - return retval; - } + return (ASBool)retval; +} /* }}} */ -/* {{{ proto bool fdf_enum_values(resource fdfdoc, mixed callback [, mixed userdata]) - */ +/* {{{ proto bool fdf_enum_values(resource fdfdoc, callback function [, mixed userdata]) + Call a user defined function for each document value */ PHP_FUNCTION(fdf_enum_values) { zval *r_fdf; zval *callback; @@ -1579,8 +1569,8 @@ PHP_FUNCTION(fdf_enum_values) { } /* }}} */ -/* {{{ proto fdf_header() - Set FDF specific HTTP headers */ +/* {{{ proto void fdf_header(void) + Set FDF specific HTTP headers */ PHP_FUNCTION(fdf_header) { sapi_header_line ctr = {0}; -- 2.50.1