fcgi.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2015 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #include "php_ini.h"
  24. #include "ext/standard/info.h"
  25. #include "php_fcgi.h"
  26. #include <fcgi_stdio.h>
  27. static int le_fcgi;
  28. const zend_function_entry fcgi_functions[] = {
  29. PHP_FE(confirm_fcgi_compiled, NULL) /* For testing, remove later. */
  30. PHP_FE(fcgi_init, NULL)
  31. PHP_FE(fcgi_fini, NULL)
  32. PHP_FE(fcgi_accept, NULL)
  33. PHP_FE(fcgi_finish, NULL)
  34. PHP_FE(fcgi_getparam, NULL)
  35. PHP_FE(fcgi_echo, NULL)
  36. PHP_FE_END /* Must be the last line in fcgi_functions[] */
  37. };
  38. zend_module_entry fcgi_module_entry = {
  39. #if ZEND_MODULE_API_NO >= 20010901
  40. STANDARD_MODULE_HEADER,
  41. #endif
  42. "fcgi",
  43. fcgi_functions,
  44. PHP_MINIT(fcgi),
  45. PHP_MSHUTDOWN(fcgi),
  46. PHP_RINIT(fcgi), /* Replace with NULL if there's nothing to do at request start */
  47. PHP_RSHUTDOWN(fcgi), /* Replace with NULL if there's nothing to do at request end */
  48. PHP_MINFO(fcgi),
  49. #if ZEND_MODULE_API_NO >= 20010901
  50. PHP_FCGI_VERSION,
  51. #endif
  52. STANDARD_MODULE_PROPERTIES
  53. };
  54. /* }}} */
  55. #ifdef COMPILE_DL_FCGI
  56. ZEND_GET_MODULE(fcgi)
  57. #endif
  58. PHP_MINIT_FUNCTION(fcgi)
  59. {
  60. /* If you have INI entries, uncomment these lines
  61. REGISTER_INI_ENTRIES();
  62. */
  63. return SUCCESS;
  64. }
  65. PHP_MSHUTDOWN_FUNCTION(fcgi)
  66. {
  67. /* uncomment this line if you have INI entries
  68. UNREGISTER_INI_ENTRIES();
  69. */
  70. return SUCCESS;
  71. }
  72. PHP_RINIT_FUNCTION(fcgi)
  73. {
  74. return SUCCESS;
  75. }
  76. PHP_RSHUTDOWN_FUNCTION(fcgi)
  77. {
  78. return SUCCESS;
  79. }
  80. PHP_MINFO_FUNCTION(fcgi)
  81. {
  82. php_info_print_table_start();
  83. php_info_print_table_header(2, "fcgi support", "enabled");
  84. php_info_print_table_end();
  85. }
  86. PHP_FUNCTION(confirm_fcgi_compiled)
  87. {
  88. char *arg = NULL;
  89. int arg_len, len;
  90. char *strg;
  91. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
  92. return;
  93. }
  94. len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "fcgi", arg);
  95. RETURN_STRINGL(strg, len, 0);
  96. }
  97. PHP_FUNCTION(fcgi_init)
  98. {
  99. }
  100. PHP_FUNCTION(fcgi_fini)
  101. {
  102. }
  103. static FCGX_Stream* stInstream;
  104. static FCGX_Stream* stOutstream;
  105. static FCGX_Stream* stErrstream;
  106. static FCGX_ParamArray stParams;
  107. PHP_FUNCTION(fcgi_accept)
  108. {
  109. int ret = FCGX_Accept(&stInstream,&stOutstream,&stErrstream,&stParams);
  110. if(stInstream == NULL) {
  111. fcgi_log("Error: in stream = null \r\n");
  112. }
  113. if(stOutstream == NULL) {
  114. fcgi_log("Error: out stream = null \r\n");
  115. }
  116. if(stErrstream == NULL) {
  117. fcgi_log("Error: err stream = null \r\n");
  118. }
  119. if(ret < 0) {
  120. fcgi_log("Error: fcgi_accept ret < 0.\r\n");
  121. }
  122. RETVAL_LONG(ret);
  123. }
  124. PHP_FUNCTION(fcgi_getparam)
  125. {
  126. char *arg = NULL;
  127. int arg_len;
  128. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
  129. return;
  130. }
  131. const char* ret = FCGX_GetParam(arg, stParams);
  132. ret == NULL ? "" : ret;
  133. char* result = estrdup(ret);
  134. RETURN_STRINGL(result,strlen(result),0);
  135. }
  136. PHP_FUNCTION(fcgi_echo)
  137. {
  138. char *arg = NULL;
  139. int arg_len;
  140. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
  141. return;
  142. }
  143. if(arg != NULL) {
  144. FCGX_PutS(arg,stOutstream);
  145. }
  146. }
  147. PHP_FUNCTION(fcgi_finish)
  148. {
  149. FCGX_Finish();
  150. }