sapi_apache.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 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. | Authors: Rasmus Lerdorf <rasmus@php.net> |
  16. | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> |
  17. | PHP 4.0 patches by: |
  18. | Zeev Suraski <zeev@zend.com> |
  19. | Stig Bakken <ssb@php.net> |
  20. +----------------------------------------------------------------------+
  21. */
  22. /* $Id$ */
  23. #include "php_apache_http.h"
  24. /* {{{ apache_php_module_main
  25. */
  26. int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC)
  27. {
  28. zend_file_handle file_handle;
  29. if (php_request_startup(TSRMLS_C) == FAILURE) {
  30. return FAILURE;
  31. }
  32. /* sending a file handle to another dll is not working
  33. so let zend open it. */
  34. if (display_source_mode) {
  35. zend_syntax_highlighter_ini syntax_highlighter_ini;
  36. php_get_highlight_struct(&syntax_highlighter_ini);
  37. if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC)){
  38. return OK;
  39. } else {
  40. return NOT_FOUND;
  41. }
  42. } else {
  43. file_handle.type = ZEND_HANDLE_FILENAME;
  44. file_handle.handle.fd = 0;
  45. file_handle.filename = SG(request_info).path_translated;
  46. file_handle.opened_path = NULL;
  47. file_handle.free_filename = 0;
  48. (void) php_execute_script(&file_handle TSRMLS_CC);
  49. }
  50. AP(in_request) = 0;
  51. return (OK);
  52. }
  53. /* }}} */
  54. /* {{{ apache_php_module_hook
  55. */
  56. int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRMLS_DC)
  57. {
  58. zend_file_handle file_handle;
  59. zval *req;
  60. char *tmp;
  61. #if PHP_SIGCHILD
  62. signal(SIGCHLD, sigchld_handler);
  63. #endif
  64. if(AP(current_hook) == AP_RESPONSE) {
  65. if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
  66. return FAILURE;
  67. }
  68. else {
  69. if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
  70. return FAILURE;
  71. }
  72. req = php_apache_request_new(r);
  73. php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
  74. switch(handler->type) {
  75. case AP_HANDLER_TYPE_FILE:
  76. php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
  77. memset(&file_handle, 0, sizeof(file_handle));
  78. file_handle.type = ZEND_HANDLE_FILENAME;
  79. file_handle.filename = handler->name;
  80. (void) php_execute_simple_script(&file_handle, ret TSRMLS_CC);
  81. break;
  82. case AP_HANDLER_TYPE_METHOD:
  83. if( (tmp = strstr(handler->name, "::")) != NULL && *(tmp+2) != '\0' ) {
  84. zval *class;
  85. zval *method;
  86. *tmp = '\0';
  87. ALLOC_ZVAL(class);
  88. ZVAL_STRING(class, handler->name, 1);
  89. ALLOC_ZVAL(method);
  90. ZVAL_STRING(method, tmp +2, 1);
  91. *tmp = ':';
  92. call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL TSRMLS_CC);
  93. zval_dtor(class);
  94. zval_dtor(method);
  95. }
  96. else {
  97. php_error(E_ERROR, "Unable to call %s - not a Class::Method\n", handler->name);
  98. /* not a class::method */
  99. }
  100. break;
  101. default:
  102. /* not a valid type */
  103. assert(0);
  104. break;
  105. }
  106. zval_dtor(req);
  107. AP(in_request) = 0;
  108. return OK;
  109. }
  110. /* }}} */
  111. /*
  112. * Local variables:
  113. * tab-width: 4
  114. * c-basic-offset: 4
  115. * End:
  116. * vim600: sw=4 ts=4 fdm=marker
  117. * vim<600: sw=4 ts=4
  118. */