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