Back to index

php5  5.3.10
sapi_apache.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Rasmus Lerdorf <rasmus@php.net>                             |
00016    | (with helpful hints from Dean Gaudet <dgaudet@arctic.org>            |
00017    | PHP 4.0 patches by:                                                  |
00018    | Zeev Suraski <zeev@zend.com>                                         |
00019    | Stig Bakken <ssb@php.net>                                            |
00020    +----------------------------------------------------------------------+
00021  */
00022 /* $Id: sapi_apache.c 321634 2012-01-01 13:15:04Z felipe $ */
00023 
00024 #include "php_apache_http.h"
00025 
00026 /* {{{ apache_php_module_main
00027  */
00028 int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC)
00029 {
00030        zend_file_handle file_handle;
00031 
00032        if (php_request_startup(TSRMLS_C) == FAILURE) {
00033               return FAILURE;
00034        }
00035        /* sending a file handle to another dll is not working
00036           so let zend open it. */
00037        
00038        if (display_source_mode) {
00039               zend_syntax_highlighter_ini syntax_highlighter_ini;
00040 
00041               php_get_highlight_struct(&syntax_highlighter_ini);
00042               if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC)){
00043                      return OK;
00044               } else {
00045                      return NOT_FOUND;
00046               }
00047        } else {
00048               file_handle.type = ZEND_HANDLE_FILENAME;
00049               file_handle.handle.fd = 0;
00050               file_handle.filename = SG(request_info).path_translated;
00051               file_handle.opened_path = NULL;
00052               file_handle.free_filename = 0;
00053               (void) php_execute_script(&file_handle TSRMLS_CC);
00054        }
00055        AP(in_request) = 0;
00056        
00057        return (OK);
00058 }
00059 /* }}} */
00060 
00061 /* {{{ apache_php_module_hook
00062  */
00063 int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRMLS_DC)
00064 {
00065        zend_file_handle file_handle;
00066        zval *req;
00067     char *tmp;
00068 
00069 #if PHP_SIGCHILD
00070        signal(SIGCHLD, sigchld_handler);
00071 #endif
00072     if(AP(current_hook) == AP_RESPONSE) {
00073         if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
00074             return FAILURE;
00075     }
00076     else {
00077         if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
00078             return FAILURE;
00079     }
00080 
00081        req = php_apache_request_new(r);
00082     if(PG(register_globals)) {
00083         php_register_variable_ex("request", req, NULL TSRMLS_CC);
00084     }
00085     else {
00086         php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
00087     }
00088     switch(handler->type) {
00089         case AP_HANDLER_TYPE_FILE:
00090             php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
00091                memset(&file_handle, 0, sizeof(file_handle));
00092                file_handle.type = ZEND_HANDLE_FILENAME;
00093                file_handle.filename = handler->name;
00094                (void) php_execute_simple_script(&file_handle, ret TSRMLS_CC);
00095             break;
00096         case AP_HANDLER_TYPE_METHOD:
00097             if( (tmp = strstr(handler->name, "::")) != NULL &&  *(tmp+2) != '\0' ) {
00098                 zval *class;
00099                 zval *method;
00100                 *tmp = '\0';
00101                 ALLOC_ZVAL(class);
00102                 ZVAL_STRING(class, handler->name, 1);
00103                 ALLOC_ZVAL(method);
00104                 ZVAL_STRING(method, tmp +2, 1);
00105                 *tmp = ':';
00106                 call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL TSRMLS_CC);
00107                 zval_dtor(class);
00108                 zval_dtor(method);
00109             }
00110             else {
00111                 php_error(E_ERROR, "Unable to call %s - not a Class::Method\n", handler->name);
00112                 /* not a class::method */
00113             }
00114             break;
00115         default:
00116             /* not a valid type */
00117             assert(0);
00118             break;
00119     }
00120        zval_dtor(req);
00121        AP(in_request) = 0;
00122 
00123        return OK;
00124 }
00125 
00126 /* }}} */
00127 
00128 /*
00129  * Local variables:
00130  * tab-width: 4
00131  * c-basic-offset: 4
00132  * End:
00133  * vim600: sw=4 ts=4 fdm=marker
00134  * vim<600: sw=4 ts=4
00135  */