You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.5 KiB

21 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2005 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.0 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_0.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. if(PG(register_globals)) {
  74. php_register_variable_ex("request", req, NULL TSRMLS_CC);
  75. }
  76. else {
  77. php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
  78. }
  79. switch(handler->type) {
  80. case AP_HANDLER_TYPE_FILE:
  81. php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
  82. memset(&file_handle, 0, sizeof(file_handle));
  83. file_handle.type = ZEND_HANDLE_FILENAME;
  84. file_handle.filename = handler->name;
  85. (void) php_execute_simple_script(&file_handle, ret TSRMLS_CC);
  86. break;
  87. case AP_HANDLER_TYPE_METHOD:
  88. if( (tmp = strstr(handler->name, "::")) != NULL && *(tmp+2) != '\0' ) {
  89. zval *class;
  90. zval *method;
  91. *tmp = '\0';
  92. ALLOC_ZVAL(class);
  93. ZVAL_STRING(class, handler->name, 1);
  94. ALLOC_ZVAL(method);
  95. ZVAL_STRING(method, tmp +2, 1);
  96. *tmp = ':';
  97. call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL TSRMLS_CC);
  98. zval_dtor(class);
  99. zval_dtor(method);
  100. }
  101. else {
  102. php_error(E_ERROR, "Unable to call %s - not a Class::Method\n", handler->name);
  103. /* not a class::method */
  104. }
  105. break;
  106. default:
  107. /* not a valid type */
  108. assert(0);
  109. break;
  110. }
  111. zval_dtor(req);
  112. AP(in_request) = 0;
  113. return OK;
  114. }
  115. /* }}} */
  116. /*
  117. * Local variables:
  118. * tab-width: 4
  119. * c-basic-offset: 4
  120. * End:
  121. * vim600: sw=4 ts=4 fdm=marker
  122. * vim<600: sw=4 ts=4
  123. */