⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fdf.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
		WRONG_PARAM_COUNT;	}	ZEND_FETCH_RESOURCE(fdf, FDFDoc *, fdfp, -1, "fdf", le_fdf);	convert_to_string_ex(fieldname);	convert_to_long_ex(trigger);	convert_to_string_ex(url);	convert_to_long_ex(flags);	err = FDFSetSubmitFormAction(fdf, Z_STRVAL_PP(fieldname), Z_LVAL_PP(trigger), Z_STRVAL_PP(url), Z_LVAL_PP(flags));	if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;}/* }}} *//* {{{ proto bool fdf_set_javascript_action(resource fdfdoc, string fieldname, int whichtrigger, string script)   Sets the javascript action for a field */PHP_FUNCTION(fdf_set_javascript_action) {	zval **fdfp, **fieldname, **trigger, **script;	FDFDoc fdf;	FDFErc err;		if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &fdfp, &fieldname, &trigger, &script) == FAILURE) {		WRONG_PARAM_COUNT;	}	ZEND_FETCH_RESOURCE(fdf, FDFDoc *, fdfp, -1, "fdf", le_fdf);	convert_to_string_ex(fieldname);	convert_to_long_ex(trigger);	convert_to_string_ex(script);		err = FDFSetJavaScriptAction(fdf, Z_STRVAL_PP(fieldname), Z_LVAL_PP(trigger), Z_STRVAL_PP(script));	if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;}/* }}} *//* {{{ proto bool fdf_set_encoding(resource fdf_document, string encoding)   Sets FDF encoding (either "Shift-JIS" or "Unicode") */  PHP_FUNCTION(fdf_set_encoding) {	zval **fdfp, **enc;	FDFDoc fdf;	FDFErc err;	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fdfp, &enc) == FAILURE) {		WRONG_PARAM_COUNT;	}	ZEND_FETCH_RESOURCE(fdf, FDFDoc *, fdfp, -1, "fdf", le_fdf);	convert_to_string_ex(enc);	err = FDFSetEncoding(fdf, Z_STRVAL_PP(enc));    	if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;}/* }}} *//* {{{ SAPI_POST_HANDLER_FUNC * SAPI post handler for FDF forms */SAPI_POST_HANDLER_FUNC(fdf_post_handler){	FILE *fp;	FDFDoc theFDF;	char *name=NULL, *value=NULL, *p, *data;	int name_len=0, value_len=0;	char *lastfieldname =NULL;	char *filename = NULL;	FDFErc err;	ASInt32 nBytes;	zval *array_ptr = (zval *) arg;		fp=php_open_temporary_file(NULL, "fdfdata.", &filename TSRMLS_CC);	if(!fp) {		if(filename) efree(filename);		return;	}	fwrite(SG(request_info).post_data, SG(request_info).post_data_length, 1, fp);	fclose(fp);	/* Set HTTP_FDF_DATA variable */	data = estrndup(SG(request_info).post_data, SG(request_info).post_data_length);	SET_VAR_STRINGL("HTTP_FDF_DATA", data, SG(request_info).post_data_length); 	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';					if(lastfieldname) efree(lastfieldname);					lastfieldname = estrdup(name);					php_register_variable(name, value, array_ptr TSRMLS_CC);				} 			}		}   		FDFClose(theFDF);		if(name)          efree(name);		if(value)         efree(value);		if(lastfieldname) efree(lastfieldname);	} 	VCWD_UNLINK((const char *)filename);	efree(filename);}/* }}} *//* {{{ proto int fdf_errno(void)    Gets error code for last operation */PHP_FUNCTION(fdf_errno) {	RETURN_LONG((long)FDF_G(error));}/* }}} *//* {{{ proto string fdf_error([int errno])    Gets error description for error code */PHP_FUNCTION(fdf_error) {	FDFErc err;	long p_err = -1;	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &p_err)	   == FAILURE) {		return;	}	err = (p_err >= 0) ? (FDFErc)p_err : FDF_G(error);	switch(err) {	case FDFErcOK: 		RETURN_STRING("no error", 1);	case FDFErcInternalError: 		RETURN_STRING("An internal FDF Library error occurred", 1);	case FDFErcBadParameter: 		RETURN_STRING("One or more of the parameters passed were invalid. ", 1);	case FDFErcFileSysErr: 		RETURN_STRING("A file system error occurred or the file was not found", 1);	case FDFErcBadFDF: 		RETURN_STRING("The FDF file being opened or parsed was invalid", 1);	case FDFErcFieldNotFound: 		RETURN_STRING("The field whose name was passed in the parameter fieldName does not exist in the FDF file", 1);	case FDFErcNoValue: 		RETURN_STRING("The field whose value was requested has no value", 1);	case FDFErcEnumStopped: 		RETURN_STRING("Enumeration was stopped by FDFEnumValues by returning FALSE", 1);	case FDFErcCantInsertField: 		RETURN_STRING("The field whose name was passed in the parameter fieldName cannot be inserted into the FDF file", 1);	case FDFErcNoOption: 		RETURN_STRING("The requested element in a fields /Opt key does not exist, or the field has no /Opt key. ", 1);	case FDFErcNoFlags: 		RETURN_STRING("The field has no /F or /Ff keys", 1);	case FDFErcBadPDF:		RETURN_STRING("The PDF file passed as the parameter to FDFSetAP was invalid, or did not contain the requested page ", 1);	case FDFErcBufTooShort: 		RETURN_STRING("The buffer passed as a parameter was too short", 1);	case FDFErcNoAP: 		RETURN_STRING("The field has no /AP key", 1);	case FDFErcIncompatibleFDF: 		RETURN_STRING("An attempt to mix classic and template-based FDF files was made", 1);#ifdef HAVE_FDFTK_5	case FDFErcNoAppendSaves: 		RETURN_STRING("The FDF does not include a /Difference key", 1);	case FDFErcValueIsArray: 		RETURN_STRING("The value of this field is an array. Use FDFGetNthValue. ", 1);	case FDFErcEmbeddedFDFs: 		RETURN_STRING("The FDF you passed as a parameter is a container for one or more FDFs embedded within it. Use FDFOpenFromEmbedded to gain access to each embedded FDF", 1);	case FDFErcNoMoreFDFs: 		RETURN_STRING("Returned by FDFOpenFromEmbedded when parameter iWhich >= the number of embedded FDFs (including the case when the passed FDF does not contain any embedded FDFs)", 1);	case FDFErcInvalidPassword: 		RETURN_STRING("Returned by FDFOpenFromEmbedded when the embedded FDF is encrypted, and you did not provide the correct password", 1);#endif	case FDFErcLast: 		RETURN_STRING("Reserved for future use", 1);	default: 		RETURN_STRING("unknown error", 1);	}}/* }}} *//* {{{ proto string fdf_get_version([resource fdfdoc])    Gets version number for FDF api or file */PHP_FUNCTION(fdf_get_version) {	zval *r_fdf = NULL;	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &r_fdf)	   == FAILURE) {		return;	}	if(r_fdf) {#if HAVE_FDFTK_5		const char *fdf_version; 		FDFDoc fdf;		ZEND_FETCH_RESOURCE(fdf, FDFDoc *, &r_fdf, -1, "fdf", le_fdf);		fdf_version = FDFGetFDFVersion(fdf);		RETURN_STRING((char *)fdf_version, 1);#else		RETURN_STRING("1.2",1);#endif	} else {		const char *api_version = FDFGetVersion();		RETURN_STRING((char *)api_version, 1);	}}/* }}} */#ifdef HAVE_FDFTK_5/* {{{ proto bool fdf_set_version(resourece fdfdoc, string version)   Sets FDF version for a file*/PHP_FUNCTION(fdf_set_version) {	zval *r_fdf;	char *version;	int version_len;	FDFDoc fdf;	FDFErc err;		if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &r_fdf, &version, &version_len)	   == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(fdf, FDFDoc *, &r_fdf, -1, "fdf", le_fdf);	err = FDFSetFDFVersion(fdf, version);	if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;}/* }}} *//* {{{ proto bool fdf_add_doc_javascript(resource fdfdoc, string scriptname, string script) 	 Add javascript code to the fdf file */PHP_FUNCTION(fdf_add_doc_javascript) {	zval *r_fdf;	char *name, *script;	int name_len, script_len;	FDFDoc fdf;	FDFErc err;		if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &r_fdf, 							 &name, &name_len,							 &script, &script_len							 )	   == FAILURE) {		return;	}		ZEND_FETCH_RESOURCE(fdf, FDFDoc *, &r_fdf, -1, "fdf", le_fdf);		err = FDFAddDocJavaScript(fdf, name, script);		if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;}/* }}} *//* {{{ proto bool fdf_set_on_import_javascript(resource fdfdoc, string script [, bool before_data_import])   Adds javascript code to be executed when Acrobat opens the FDF */PHP_FUNCTION(fdf_set_on_import_javascript) {	zval *r_fdf;	char *script;	int script_len;	zend_bool before;	FDFDoc fdf;	FDFErc err;		if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsb", &r_fdf, 							 &script, &script_len, &before							 )	   == FAILURE) {		return;	}		ZEND_FETCH_RESOURCE(fdf, FDFDoc *, &r_fdf, -1, "fdf", le_fdf);		err = FDFSetOnImportJavaScript(fdf, script, before);		if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;} /* }}} *//* {{{ proto bool fdf_set_target_frame(resource fdfdoc, string target)   Sets target frame for form */PHP_FUNCTION(fdf_set_target_frame) {	zval *r_fdf;	char *target;	int target_len;	FDFDoc fdf;	FDFErc err;		if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &r_fdf, 							 &target, &target_len							 )	   == FAILURE) {		return;	}		ZEND_FETCH_RESOURCE(fdf, FDFDoc *, &r_fdf, -1, "fdf", le_fdf);		err = FDFSetTargetFrame(fdf, target);		if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;} /* }}} */#endif/* {{{ proto bool fdf_remove_item(resource fdfdoc, string fieldname, int item)   Sets target frame for form */PHP_FUNCTION(fdf_remove_item) {	zval *r_fdf;	char *fieldname;	int fieldname_len;	long item;	FDFDoc fdf;	FDFErc err;		if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsl", &r_fdf, 							 &fieldname, &fieldname_len,							 &item							 )	   == FAILURE) {		return;	}		ZEND_FETCH_RESOURCE(fdf, FDFDoc *, &r_fdf, -1, "fdf", le_fdf);		err = FDFRemoveItem(fdf, *fieldname ? fieldname : NULL, item);		if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;} /* }}} */#ifdef HAVE_FDFTK_5/* {{{ proto array fdf_get_attachment(resource fdfdoc, string fieldname, string savepath)   Get attached uploaded file */PHP_FUNCTION(fdf_get_attachment) {	zval *r_fdf;	char *fieldname, *savepath;	int fieldname_len, savepath_len;	int is_dir=0;	FDFDoc fdf;	FDFErc err;	char pathbuf[MAXPATHLEN], mimebuf[1024];    struct stat statBuf;	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &r_fdf, 							 &fieldname, &fieldname_len,							 &savepath, &savepath_len							 )	   == FAILURE) {		return;	}		ZEND_FETCH_RESOURCE(fdf, FDFDoc *, &r_fdf, -1, "fdf", le_fdf);	if (php_check_open_basedir(savepath TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(savepath, "wb+", CHECKUID_CHECK_MODE_PARAM))) {		RETURN_FALSE;	}	strlcpy(pathbuf, savepath, sizeof(pathbuf));	if(0 == stat(pathbuf, &statBuf)) {		is_dir = S_ISDIR(statBuf.st_mode);	}	err = FDFExtractAttachment(fdf, fieldname, pathbuf, sizeof(pathbuf), is_dir, mimebuf, sizeof(mimebuf)); 		if(err != FDFErcOK) {		FDF_FAILURE(err);	}	array_init(return_value);	add_assoc_string(return_value, "path", pathbuf, 1);    add_assoc_string(return_value, "type", mimebuf, 1);	stat(pathbuf, &statBuf);	add_assoc_long(return_value, "size", statBuf.st_size);}/* }}} */#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), 								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 {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "callback failed");	}	zval_ptr_dtor(&z_name);	zval_ptr_dtor(&z_value);	return (ASBool)retval;}/* }}} *//* {{{ 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;	zval *userdata = NULL;	FDFDoc fdf;	FDFErc err;	char *name;	char namebuf[1024], valbuf[1024];	if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &r_fdf, 							 &callback, &userdata							 )	   == FAILURE) {		return;	}	ZEND_FETCH_RESOURCE(fdf, FDFDoc *, &r_fdf, -1, "fdf", le_fdf);	if (Z_TYPE_P(callback) != IS_ARRAY && 		Z_TYPE_P(callback) != IS_STRING) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong syntax for function name");		RETURN_FALSE;	}	convert_to_string_ex(&callback);	if (!zend_is_callable(callback, 0, &name)) {		php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Second argument is expected to be a valid callback");		efree(name);		RETURN_FALSE;	}	efree(name);	FDF_G(enum_callback) = callback;	FDF_G(enum_fdf) = fdf;	err = FDFEnumValues(fdf, enum_values_callback, 						namebuf, sizeof(namebuf), 						valbuf, sizeof(valbuf), 						userdata ? &userdata : NULL, 0); 	if(err != FDFErcOK) {		FDF_FAILURE(err);	}	FDF_SUCCESS;}/* }}} *//* {{{ proto void fdf_header(void)    Set FDF specific HTTP headers */PHP_FUNCTION(fdf_header) {	sapi_header_line ctr = {0};		ctr.line = "Content-type: application/vnd.fdf";	ctr.line_len = strlen(ctr.line);	ctr.response_code = 200;	sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);} /* }}} */#endif/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -