/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */ /* $Id$ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_fcgi.h" #include static int le_fcgi; const zend_function_entry fcgi_functions[] = { PHP_FE(confirm_fcgi_compiled, NULL) /* For testing, remove later. */ PHP_FE(fcgi_init, NULL) PHP_FE(fcgi_fini, NULL) PHP_FE(fcgi_accept, NULL) PHP_FE(fcgi_finish, NULL) PHP_FE(fcgi_getparam, NULL) PHP_FE(fcgi_echo, NULL) PHP_FE_END /* Must be the last line in fcgi_functions[] */ }; zend_module_entry fcgi_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "fcgi", fcgi_functions, PHP_MINIT(fcgi), PHP_MSHUTDOWN(fcgi), PHP_RINIT(fcgi), /* Replace with NULL if there's nothing to do at request start */ PHP_RSHUTDOWN(fcgi), /* Replace with NULL if there's nothing to do at request end */ PHP_MINFO(fcgi), #if ZEND_MODULE_API_NO >= 20010901 PHP_FCGI_VERSION, #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_FCGI ZEND_GET_MODULE(fcgi) #endif PHP_MINIT_FUNCTION(fcgi) { /* If you have INI entries, uncomment these lines REGISTER_INI_ENTRIES(); */ return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(fcgi) { /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ return SUCCESS; } PHP_RINIT_FUNCTION(fcgi) { return SUCCESS; } PHP_RSHUTDOWN_FUNCTION(fcgi) { return SUCCESS; } PHP_MINFO_FUNCTION(fcgi) { php_info_print_table_start(); php_info_print_table_header(2, "fcgi support", "enabled"); php_info_print_table_end(); } PHP_FUNCTION(confirm_fcgi_compiled) { char *arg = NULL; int arg_len, len; char *strg; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "fcgi", arg); RETURN_STRINGL(strg, len, 0); } PHP_FUNCTION(fcgi_init) { } PHP_FUNCTION(fcgi_fini) { } static FCGX_Stream* stInstream; static FCGX_Stream* stOutstream; static FCGX_Stream* stErrstream; static FCGX_ParamArray stParams; PHP_FUNCTION(fcgi_accept) { int ret = FCGX_Accept(&stInstream,&stOutstream,&stErrstream,&stParams); if(stInstream == NULL) { fcgi_log("Error: in stream = null \r\n"); } if(stOutstream == NULL) { fcgi_log("Error: out stream = null \r\n"); } if(stErrstream == NULL) { fcgi_log("Error: err stream = null \r\n"); } if(ret < 0) { fcgi_log("Error: fcgi_accept ret < 0.\r\n"); } RETVAL_LONG(ret); } PHP_FUNCTION(fcgi_getparam) { char *arg = NULL; int arg_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } const char* ret = FCGX_GetParam(arg, stParams); ret == NULL ? "" : ret; char* result = estrdup(ret); RETURN_STRINGL(result,strlen(result),0); } PHP_FUNCTION(fcgi_echo) { char *arg = NULL; int arg_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) { return; } if(arg != NULL) { FCGX_PutS(arg,stOutstream); } } PHP_FUNCTION(fcgi_finish) { FCGX_Finish(); }