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.

136 lines
4.5 KiB

23 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 4 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2003 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.02 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://www.php.net/license/2_02.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@fast.no> |
  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. */
  35. if (display_source_mode) {
  36. zend_syntax_highlighter_ini syntax_highlighter_ini;
  37. php_get_highlight_struct(&syntax_highlighter_ini);
  38. if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC)){
  39. return OK;
  40. } else {
  41. return NOT_FOUND;
  42. }
  43. } else {
  44. file_handle.type = ZEND_HANDLE_FILENAME;
  45. file_handle.handle.fd = 0;
  46. file_handle.filename = SG(request_info).path_translated;
  47. file_handle.opened_path = NULL;
  48. file_handle.free_filename = 0;
  49. (void) php_execute_script(&file_handle TSRMLS_CC);
  50. }
  51. AP(in_request) = 0;
  52. return (OK);
  53. }
  54. /* }}} */
  55. /* {{{ apache_php_module_hook
  56. */
  57. int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRMLS_DC)
  58. {
  59. zend_file_handle file_handle;
  60. zval *req;
  61. char *tmp;
  62. #if PHP_SIGCHILD
  63. signal(SIGCHLD, sigchld_handler);
  64. #endif
  65. if(AP(current_hook) == AP_RESPONSE) {
  66. if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
  67. return FAILURE;
  68. }
  69. else {
  70. if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
  71. return FAILURE;
  72. }
  73. req = php_apache_request_new(r);
  74. if(PG(register_globals)) {
  75. php_register_variable_ex("request", req, NULL TSRMLS_CC);
  76. }
  77. else {
  78. php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
  79. }
  80. switch(handler->type) {
  81. case AP_HANDLER_TYPE_FILE:
  82. php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
  83. memset(&file_handle, 0, sizeof(file_handle));
  84. file_handle.type = ZEND_HANDLE_FILENAME;
  85. file_handle.filename = handler->name;
  86. (void) php_execute_simple_script(&file_handle, ret TSRMLS_CC);
  87. break;
  88. case AP_HANDLER_TYPE_METHOD:
  89. if( (tmp = strstr(handler->name, "::")) != NULL && *(tmp+2) != '\0' ) {
  90. zval *class;
  91. zval *method;
  92. *tmp = '\0';
  93. ALLOC_ZVAL(class);
  94. ZVAL_STRING(class, handler->name, 1);
  95. ALLOC_ZVAL(method);
  96. ZVAL_STRING(method, tmp +2, 1);
  97. *tmp = ':';
  98. call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL TSRMLS_CC);
  99. zval_dtor(class);
  100. zval_dtor(method);
  101. }
  102. else {
  103. php_error(E_ERROR, "Unable to call %s - not a Class::Method\n", handler->name);
  104. /* not a class::method */
  105. }
  106. break;
  107. default:
  108. /* not a valid type */
  109. assert(0);
  110. break;
  111. }
  112. zval_dtor(req);
  113. AP(in_request) = 0;
  114. return OK;
  115. }
  116. /* }}} */
  117. /*
  118. * Local variables:
  119. * tab-width: 4
  120. * c-basic-offset: 4
  121. * End:
  122. * vim600: sw=4 ts=4 fdm=marker
  123. * vim<600: sw=4 ts=4
  124. */