cvs: php4 /ext/fdf fdf.c /main SAPI.c SAPI.h

From: Date: Wed, 11 Oct 2000 22:44:15 +0000
Subject: cvs: php4 /ext/fdf fdf.c /main SAPI.c SAPI.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2020@lists.php.net to get a copy of this message
hholzgra Wed Oct 11 15:44:15 2000 EDT Modified files: /php4/main SAPI.c SAPI.h /php4/ext/fdf fdf.c Log: @ - POST handler for Adobe FDF format (Hartmut) the FDF handler is now working and totaly living in the fdf extension, no more special code in main is needed Index: php4/main/SAPI.c diff -u php4/main/SAPI.c:1.92 php4/main/SAPI.c:1.93 --- php4/main/SAPI.c:1.92 Sat Sep 9 08:02:15 2000 +++ php4/main/SAPI.c Wed Oct 11 15:44:15 2000 @@ -28,9 +28,6 @@ #endif #include "rfc1867.h" -#if HAVE_FDFLIB -#include "fdfdata.h" -#endif #ifdef PHP_WIN32 #define STRCASECMP stricmp @@ -40,17 +37,6 @@ #include "php_content_types.h" -SAPI_POST_READER_FUNC(sapi_read_standard_form_data); -SAPI_POST_READER_FUNC(php_default_post_reader); - -static sapi_post_entry supported_post_entries[] = { -#if HAVE_FDFLIB - { "application/vnd.fdf", sizeof("application/vnd.fdf")-1, php_default_post_reader, fdf_post_handler}, -#endif - { NULL, 0, NULL } -}; - - static HashTable known_post_content_types; SAPI_API void (*sapi_error)(int error_type, const char *message, ...); @@ -77,8 +63,6 @@ sapi_module = *sf; zend_hash_init_ex(&known_post_content_types, 5, NULL, NULL, 1, 0); - sapi_register_post_entries(supported_post_entries); - #ifdef ZTS sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), (ts_allocate_ctor) sapi_globals_ctor, NULL); #else @@ -543,12 +527,10 @@ return zend_hash_add(&known_post_content_types, post_entry->content_type, post_entry->content_type_len+1, (void *) post_entry, sizeof(sapi_post_entry), NULL); } - SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry) { zend_hash_del(&known_post_content_types, post_entry->content_type, post_entry->content_type_len+1); } - SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(SLS_D)) { Index: php4/main/SAPI.h diff -u php4/main/SAPI.h:1.53 php4/main/SAPI.h:1.54 --- php4/main/SAPI.h:1.53 Sat Sep 9 08:02:15 2000 +++ php4/main/SAPI.h Wed Oct 11 15:44:15 2000 @@ -207,6 +207,7 @@ #define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg SLS_DC) SAPI_POST_READER_FUNC(sapi_read_standard_form_data); +SAPI_POST_READER_FUNC(php_default_post_reader); #define STANDARD_SAPI_MODULE_PROPERTIES NULL Index: php4/ext/fdf/fdf.c diff -u php4/ext/fdf/fdf.c:1.31 php4/ext/fdf/fdf.c:1.32 --- php4/ext/fdf/fdf.c:1.31 Mon Aug 21 02:23:37 2000 +++ php4/ext/fdf/fdf.c Wed Oct 11 15:44:15 2000 @@ -13,10 +13,11 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Uwe Steinmann <Uwe.Steinmann@fernuni-hagen.de> | + | Hartmut Holzgraefe <hartmut@six.de> | +----------------------------------------------------------------------+ */ -/* $Id: fdf.c,v 1.31 2000/08/21 09:23:37 steinm Exp $ */ +/* $Id: fdf.c,v 1.32 2000/10/11 22:44:15 hholzgra Exp $ */ /* FdfTk lib 2.0 is a Complete C/C++ FDF Toolkit available from http://beta1.adobe.com/ada/acrosdk/forms.html. */ @@ -28,7 +29,9 @@ #endif #include "php.h" +#include "SAPI.h" #include "ext/standard/head.h" +#include "php_open_temporary_file.h" #include <math.h> #include "php_fdf.h" @@ -65,6 +68,8 @@ int le_fdf; #endif +SAPI_POST_HANDLER_FUNC(fdf_post_handler); + function_entry fdf_functions[] = { PHP_FE(fdf_open, NULL) PHP_FE(fdf_create, NULL) @@ -99,11 +104,49 @@ (void)FDFClose(fdf); } +static sapi_post_entry supported_post_entries[] = { +#if HAVE_FDFLIB + { "application/vnd.fdf", sizeof("application/vnd.fdf")-1, php_default_post_reader, fdf_post_handler}, +#endif + { NULL, 0, NULL } +}; + + +SAPI_API int sapi_add_post_entry(char *content_type, void (*post_reader)(SLS_D), + void (*post_handler)(char *content_type_dup, void *arg SLS_DC)) { + + sapi_post_entry *post_entry = (sapi_post_entry *)emalloc(sizeof(sapi_post_entry)); + if(!post_entry) return 0; + + post_entry->content_type = estrdup(content_type); + if(post_entry->content_type == NULL) return 0; + post_entry->content_type_len = strlen(content_type); + post_entry->post_reader = post_reader; + post_entry->post_handler = post_handler; + + return sapi_register_post_entry(post_entry); +} + +SAPI_API void sapi_remove_post_entry(char *content_type) { + sapi_post_entry *post_entry = (sapi_post_entry *)emalloc(sizeof(sapi_post_entry)); + if(!post_entry) return; + + post_entry->content_type = estrdup(content_type); + if(post_entry->content_type == NULL) return; + + sapi_unregister_post_entry(post_entry); + + efree(post_entry); +} + PHP_MINIT_FUNCTION(fdf) { FDFErc err; FDF_GLOBAL(le_fdf) = register_list_destructors(phpi_FDFClose, NULL); + /* add handler for Acrobat FDF form post requests */ + sapi_add_post_entry("application/vnd.fdf", php_default_post_reader, fdf_post_handler); + /* Constants used by fdf_set_opt() */ REGISTER_LONG_CONSTANT("FDFValue", FDFValue, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("FDFStatus", FDFStatus, CONST_CS | CONST_PERSISTENT); @@ -153,6 +196,10 @@ PHP_MSHUTDOWN_FUNCTION(fdf) { FDFErc err; + + /* remove handler for Acrobat FDF form post requests */ + sapi_remove_post_entry("application/vnd.fdf"); + #ifdef PHP_WIN32 return SUCCESS; #endif @@ -188,7 +235,7 @@ RETURN_LONG(id); } /* }}} */ -/* {{{ proto void fdf_close(int fdfdoc) +/* {{{ proto boolean fdf_close(int fdfdoc) Closes the fdf document */ PHP_FUNCTION(fdf_close) { pval **arg1; @@ -214,7 +261,7 @@ RETURN_TRUE; } /* }}} */ -/* {{{ proto void fdf_create(void) +/* {{{ proto int fdf_create(void) Creates a new fdf document */ PHP_FUNCTION(fdf_create) { int id; @@ -233,7 +280,7 @@ } /* }}} */ -/* {{{ proto void fdf_get_value(int fdfdoc, string fieldname) +/* {{{ proto string fdf_get_value(int fdfdoc, string fieldname) Gets the value of a field as string */ PHP_FUNCTION(fdf_get_value) { pval **arg1, **arg2; @@ -276,7 +323,7 @@ } /* }}} */ -/* {{{ proto void fdf_set_value(int fdfdoc, string fieldname, string value, int isName) +/* {{{ proto boolean fdf_set_value(int fdfdoc, string fieldname, string value, int isName) Sets the value of a field */ PHP_FUNCTION(fdf_set_value) { pval **arg1, **arg2, **arg3, **arg4; @@ -308,7 +355,7 @@ } /* }}} */ -/* {{{ proto void fdf_next_field_name(int fdfdoc [, string fieldname]) +/* {{{ proto string fdf_next_field_name(int fdfdoc [, string fieldname]) Gets the name of the next field name or the first field name */ PHP_FUNCTION(fdf_next_field_name) { pval **argv[2]; @@ -356,7 +403,7 @@ } /* }}} */ -/* {{{ proto void fdf_set_ap(int fdfdoc, string fieldname, int face, string filename, int pagenr) +/* {{{ proto boolean fdf_set_ap(int fdfdoc, string fieldname, int face, string filename, int pagenr) Sets the value of a field */ PHP_FUNCTION(fdf_set_ap) { pval **arg1, **arg2, **arg3, **arg4, **arg5; @@ -405,7 +452,7 @@ } /* }}} */ -/* {{{ proto void fdf_set_status(int fdfdoc, string status) +/* {{{ proto boolean fdf_set_status(int fdfdoc, string status) Sets the value in the /Status key. */ PHP_FUNCTION(fdf_set_status) { pval **arg1, **arg2; @@ -435,7 +482,7 @@ } /* }}} */ -/* {{{ proto void fdf_get_status(int fdfdoc) +/* {{{ proto string fdf_get_status(int fdfdoc) Gets the value in the /Status key. */ PHP_FUNCTION(fdf_get_status) { pval **arg1; @@ -472,7 +519,7 @@ } /* }}} */ -/* {{{ proto void fdf_set_file(int fdfdoc, string filename) +/* {{{ proto boolean fdf_set_file(int fdfdoc, string filename) Sets the value of the FDF's /F key */ PHP_FUNCTION(fdf_set_file) { pval **arg1, **arg2; @@ -502,7 +549,7 @@ } /* }}} */ -/* {{{ proto void fdf_get_file(int fdfdoc) +/* {{{ proto string fdf_get_file(int fdfdoc) Gets the value in the /F key. */ PHP_FUNCTION(fdf_get_file) { pval **arg1; @@ -539,7 +586,7 @@ } /* }}} */ -/* {{{ proto void fdf_save(int fdfdoc, string filename) +/* {{{ proto boolean fdf_save(int fdfdoc, string filename) Writes out an FDF file. */ PHP_FUNCTION(fdf_save) { pval **arg1, **arg2; @@ -568,7 +615,7 @@ RETURN_TRUE; } /* }}} */ -/* {{{ proto void fdf_add_template(int fdfdoc, int newpage, string filename, string template, int rename) +/* {{{ proto boolean fdf_add_template(int fdfdoc, int newpage, string filename, string template, int rename) Adds a template to the FDF*/ PHP_FUNCTION(fdf_add_template) { pval **arg1, **arg2, **arg3, **arg4, **arg5; @@ -610,7 +657,7 @@ } /* }}} */ -/* {{{ proto void fdf_set_flags(int fdfdoc, string fieldname, int whichFlags, int newFlags) +/* {{{ proto boolean fdf_set_flags(int fdfdoc, string fieldname, int whichFlags, int newFlags) modifies a flag for a field in the fdf*/ PHP_FUNCTION(fdf_set_flags) { pval **arg1, **arg2, **arg3, **arg4; @@ -642,7 +689,7 @@ } /* }}} */ -/* {{{ proto void fdf_set_opt(int fdfdoc, string fieldname, int element, string value, string name) +/* {{{ proto boolean fdf_set_opt(int fdfdoc, string fieldname, int element, string value, string name) Sets a value in the opt array for a field in the FDF*/ PHP_FUNCTION(fdf_set_opt) { pval **arg1, **arg2, **arg3, **arg4, **arg5; @@ -675,7 +722,7 @@ } /* }}} */ -/* {{{ proto void fdf_set_submit_form_action(int fdfdoc, string fieldname, int whichTrigger, string url, int flags) +/* {{{ proto booelan fdf_set_submit_form_action(int fdfdoc, string fieldname, int whichTrigger, string url, int flags) sets the submit form action for a field in the fdf*/ PHP_FUNCTION(fdf_set_submit_form_action) { pval **arg1, **arg2, **arg3, **arg4, **arg5; @@ -706,7 +753,7 @@ RETURN_TRUE; } -/* {{{ proto void fdf_set_javascript_action(int fdfdoc, string fieldname, int whichTrigger, string script) +/* {{{ proto boolean fdf_set_javascript_action(int fdfdoc, string fieldname, int whichTrigger, string script) sets the javascript action for a field in the fdf*/ PHP_FUNCTION(fdf_set_javascript_action) { pval **arg1, **arg2, **arg3, **arg4; @@ -734,6 +781,72 @@ printf("Error setting FDF JavaScript action: %d",err); RETURN_TRUE; +} + + +SAPI_POST_HANDLER_FUNC(fdf_post_handler) +{ + FILE *fp; + FDFDoc theFDF; + char *name=NULL,*value=NULL,*p; + int name_len=0,value_len=0; + char *lastfieldname =NULL; + char *strtok_buf = NULL; + char *filename = NULL; + FDFErc err; + ASInt32 nBytes, datalen; + zval *array_ptr = (zval *) arg; + ELS_FETCH(); + PLS_FETCH(); + + fp=php_open_temporary_file(NULL,"fdfdata.",&filename); + if(!fp) { + if(filename) efree(filename); + return; + } + fwrite(SG(request_info).post_data,SG(request_info).post_data_length,1,fp); + fclose(fp); + + err = FDFOpen(filename,0,&theFDF); + + if(err==FDFErcOK){ + name = emalloc(name_len=256); + value= emalloc(value_len=256); + while (1) { + err = FDFNextFieldName(theFDF,lastfieldname,name,name_len-1,&nBytes); + if(err == FDFErcBufTooShort && nBytes >0 ) { + name = erealloc(name,name_len=(nBytes+1)); + err = FDFNextFieldName(theFDF,lastfieldname,name,name_len-1,&nBytes); + } + + if(err != FDFErcOK || nBytes == 0) break; + + if(lastfieldname) efree(lastfieldname); + lastfieldname = estrdup(name); + + err = FDFGetValue(theFDF,name,NULL,0,&nBytes); + if(err != FDFErcOK && err != FDFErcNoValue ) break; + + if(value_len<nBytes+1) value = erealloc(value,value_len=(nBytes+1)); + + if(nBytes>0) { + err = FDFGetValue(theFDF,name,value,value_len-1,&nBytes); + if(err == FDFErcOK && nBytes != 0) { + for(p=value;*p;p++) if(*p=='\r') *p='\n'; + lastfieldname = estrdup(name); + php_register_variable(name, value, array_ptr ELS_CC PLS_CC); + } + } + } + + FDFClose(theFDF); + V_UNLINK((const char *)filename); + efree(filename); + + if(name) efree(name); + if(value) efree(value); + if(lastfieldname) efree(lastfieldname); + } } #endif

« previous php.cvs (#2020) next »