123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- /*
- +----------------------------------------------------------------------+
- | 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 <fcgi_stdio.h>
- 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_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);
- }
- extern void swap_init();
- extern void fcgi_log(const char* szBuf);
- extern void swap_fini();
- extern void start_accept();
- extern void fini_accept(void (* pFun)(char*) );
- PHP_FUNCTION(fcgi_init)
- {
- char *arg = NULL;
- int arg_len;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
- return;
- }
- swap_init(arg);
- }
- PHP_FUNCTION(fcgi_fini)
- {
- swap_fini();
- }
- static FCGX_Stream* stInstream;
- static FCGX_Stream* stOutstream;
- static FCGX_Stream* stErrstream;
- static FCGX_ParamArray stParams;
- PHP_FUNCTION(fcgi_accept)
- {
- fcgi_log("\r\n\r\nstart fcgi_accept:\r\n");
- start_accept();
- int ret = FCGX_Accept(&stInstream,&stOutstream,&stErrstream,&stParams);
- printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
- 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);
- }
- void print_fun(char* szBuf)
- {
- if(stOutstream && szBuf) {
- FCGX_PutS(szBuf,stOutstream);
- }
- }
- PHP_FUNCTION(fcgi_finish)
- {
- fini_accept(print_fun);
- FCGX_Finish();
- fcgi_log("fcgi_finish\r\n");
- }
|