gschlossnagle Sun Nov 17 19:59:23 2002 EDT
Modified files:
/php4/main main.c php_main.h SAPI.c SAPI.h
Log:
added support functions for the apache_hooks SAPI
Index: php4/main/main.c
diff -u php4/main/main.c:1.514 php4/main/main.c:1.515
--- php4/main/main.c:1.514 Sun Nov 17 17:52:47 2002
+++ php4/main/main.c Sun Nov 17 19:59:23 2002
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.514 2002/11/17 22:52:47 iliaa Exp $ */
+/* $Id: main.c,v 1.515 2002/11/18 00:59:23 gschlossnagle Exp $ */
/* {{{ includes
*/
@@ -811,8 +811,39 @@
static int php_hash_environment(TSRMLS_D);
+/* {{{ php_start_sapi()
+ */
+static int php_start_sapi()
+{
+ int retval = SUCCESS;
+
+ if(!SG(sapi_started)) {
+ zend_try {
+ PG(during_request_startup) = 1;
+
+ /* initialize global variables */
+ PG(modules_activated) = 0;
+ PG(header_is_being_sent) = 0;
+ PG(connection_status) = PHP_CONNECTION_NORMAL;
+
+ zend_activate(TSRMLS_C);
+ zend_set_timeout(EG(timeout_seconds));
+ zend_activate_modules(TSRMLS_C);
+ PG(modules_activated)=1;
+ } zend_catch {
+ retval = FAILURE;
+ } zend_end_try();
+
+ SG(sapi_started) = 1;
+ }
+ return retval;
+}
+
+/* }}} */
+
/* {{{ php_request_startup
*/
+ #ifndef APACHE_HOOKS
int php_request_startup(TSRMLS_D)
{
int retval = SUCCESS;
@@ -868,6 +899,56 @@
return retval;
}
+# else
+int php_request_startup(TSRMLS_D)
+{
+ int retval = SUCCESS;
+
+#if PHP_SIGCHILD
+ signal(SIGCHLD, sigchld_handler);
+#endif
+
+ if (php_start_sapi() == FAILURE)
+ return FAILURE;
+
+ php_output_activate(TSRMLS_C);
+ sapi_activate(TSRMLS_C);
+ php_hash_environment(TSRMLS_C);
+
+ zend_try {
+ PG(during_request_startup) = 1;
+ php_output_activate(TSRMLS_C);
+ if (PG(expose_php)) {
+ sapi_add_header(SAPI_PHP_VERSION_HEADER,
+sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
+ }
+ } zend_catch {
+ retval = FAILURE;
+ } zend_end_try();
+
+ return retval;
+}
+# endif
+/* }}} */
+
+/* {{{ php_request_startup_for_hook
+ */
+int php_request_startup_for_hook(TSRMLS_D)
+{
+ int retval = SUCCESS;
+
+#if PHP_SIGCHLD
+ signal(SIGCHLD, sigchld_handler);
+#endif
+
+ if (php_start_sapi() == FAILURE)
+ return FAILURE;
+
+ php_output_activate(TSRMLS_C);
+ sapi_activate_headers_only(TSRMLS_C);
+ php_hash_environment(TSRMLS_C);
+
+ return retval;
+}
/* }}} */
/* {{{ php_request_shutdown_for_exec
@@ -882,6 +963,44 @@
}
/* }}} */
+/* {{{ php_request_shutdown_for_hook
+ */
+void php_request_shutdown_for_hook(void *dummy)
+{
+ TSRMLS_FETCH();
+ if (PG(modules_activated)) zend_try {
+ php_call_shutdown_functions();
+ } zend_end_try();
+
+ if (PG(modules_activated)) {
+ zend_deactivate_modules(TSRMLS_C);
+ }
+
+ zend_try {
+ int i;
+
+ for (i = 0; i < NUM_TRACK_VARS; i++) {
+ zval_ptr_dtor(&PG(http_globals)[i]);
+ }
+ } zend_end_try();
+
+ zend_deactivate(TSRMLS_C);
+
+ zend_try {
+ sapi_deactivate(TSRMLS_C);
+ } zend_end_try();
+
+ zend_try {
+ shutdown_memory_manager(CG(unclean_shutdown), 0);
+ } zend_end_try();
+
+ zend_try {
+ zend_unset_timeout(TSRMLS_C);
+ } zend_end_try();
+}
+
+/* }}} */
+
/* {{{ php_request_shutdown
*/
void php_request_shutdown(void *dummy)
@@ -1559,6 +1678,41 @@
}
free_alloca(old_cwd);
return retval;
+}
+/* }}} */
+
+/* {{{ php_execute_simple_script
+ */
+PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret
+TSRMLS_DC)
+{
+ char *old_cwd;
+
+ EG(exit_status) = 0;
+#define OLD_CWD_SIZE 4096
+ old_cwd = do_alloca(OLD_CWD_SIZE);
+ old_cwd[0] = '\0';
+
+ zend_try {
+#ifdef PHP_WIN32
+ UpdateIniFromRegistry(primary_file->filename TSRMLS_CC);
+#endif
+
+ PG(during_request_startup) = 0;
+
+ if (primary_file->type == ZEND_HANDLE_FILENAME
+ && primary_file->filename) {
+ VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
+ VCWD_CHDIR_FILE(primary_file->filename);
+ }
+ zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, ret, 1, primary_file);
+ } zend_end_try();
+
+ if (old_cwd[0] != '\0') {
+ VCWD_CHDIR(old_cwd);
+ }
+
+ free_alloca(old_cwd);
+ return EG(exit_status);
}
/* }}} */
Index: php4/main/php_main.h
diff -u php4/main/php_main.h:1.23 php4/main/php_main.h:1.24
--- php4/main/php_main.h:1.23 Wed Sep 18 17:57:29 2002
+++ php4/main/php_main.h Sun Nov 17 19:59:23 2002
@@ -18,7 +18,7 @@
*/
-/* $Id: php_main.h,v 1.23 2002/09/18 21:57:29 zeev Exp $ */
+/* $Id: php_main.h,v 1.24 2002/11/18 00:59:23 gschlossnagle Exp $ */
#ifndef PHP_MAIN_H
@@ -39,6 +39,7 @@
PHPAPI int php_startup_extensions(zend_module_entry **ptr, int count);
PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC);
+PHPAPI int php_execute_simple_script(zend_file_handle *primary_file, zval **ret
+TSRMLS_DC);
PHPAPI int php_handle_special_queries(TSRMLS_D);
PHPAPI int php_lint_script(zend_file_handle *file TSRMLS_DC);
Index: php4/main/SAPI.c
diff -u php4/main/SAPI.c:1.155 php4/main/SAPI.c:1.156
--- php4/main/SAPI.c:1.155 Tue Nov 12 13:29:11 2002
+++ php4/main/SAPI.c Sun Nov 17 19:59:23 2002
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: SAPI.c,v 1.155 2002/11/12 18:29:11 hholzgra Exp $ */
+/* $Id: SAPI.c,v 1.156 2002/11/18 00:59:23 gschlossnagle Exp $ */
#include <ctype.h>
#include <sys/stat.h>
@@ -278,10 +278,42 @@
return 0;
}
+SAPI_API void sapi_activate_headers_only(TSRMLS_D)
+{
+ if (SG(request_info).headers_read == 1)
+ return;
+ SG(request_info).headers_read = 1;
+ zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void
+(*)(void *)) sapi_free_header, 0);
+ SG(sapi_headers).send_default_content_type = 1;
+
+ /*
+ SG(sapi_headers).http_response_code = 200;
+ */
+ SG(sapi_headers).http_status_line = NULL;
+ SG(request_info).current_user = NULL;
+ SG(request_info).current_user_length = 0;
+ SG(request_info).no_headers = 0;
+
+ /* It's possible to override this general case in the activate() callback, if
+ * necessary.
+ */
+ if (SG(request_info).request_method && !strcmp(SG(request_info).request_method,
+"HEAD")) {
+ SG(request_info).headers_only = 1;
+ } else {
+ SG(request_info).headers_only = 0;
+ }
+ if (SG(server_context)) {
+ SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C);
+ if (sapi_module.activate) {
+ sapi_module.activate(TSRMLS_C);
+ }
+ }
+}
/*
* Called from php_request_startup() for every request.
*/
+
SAPI_API void sapi_activate(TSRMLS_D)
{
zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void
(*)(void *)) sapi_free_header, 0);
@@ -389,6 +421,9 @@
SG(sapi_headers).mimetype = NULL;
}
sapi_send_headers_free(TSRMLS_C);
+ SG(sapi_started) = 0;
+ SG(headers_sent) = 0;
+ SG(request_info).headers_read = 0;
}
Index: php4/main/SAPI.h
diff -u php4/main/SAPI.h:1.87 php4/main/SAPI.h:1.88
--- php4/main/SAPI.h:1.87 Tue Nov 12 15:56:47 2002
+++ php4/main/SAPI.h Sun Nov 17 19:59:23 2002
@@ -83,6 +83,7 @@
zend_bool headers_only;
zend_bool no_headers;
+ zend_bool headers_read;
sapi_post_entry *post_entry;
@@ -117,6 +118,7 @@
HashTable *rfc1867_uploaded_files;
long post_max_size;
int options;
+ zend_bool sapi_started;
} sapi_globals_struct;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php