⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sapi_apache2.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	php_apache_sapi_register_variables,	php_apache_sapi_log_message,			/* Log message */	STANDARD_SAPI_MODULE_PROPERTIES};static apr_status_tphp_apache_server_shutdown(void *tmp){	apache2_sapi_module.shutdown(&apache2_sapi_module);	sapi_shutdown();#ifdef ZTS	tsrm_shutdown();#endif	return APR_SUCCESS;}static void php_apache_add_version(apr_pool_t *p){	TSRMLS_FETCH();	if (PG(expose_php)) {		ap_add_version_component(p, "PHP/" PHP_VERSION);	}}static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp){#ifndef ZTS	int threaded_mpm;	ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm);	if(threaded_mpm) {		ap_log_error(APLOG_MARK, APLOG_CRIT, 0, 0, "Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe.  You need to recompile PHP.");		return DONE;	}#endif	/* When this is NULL, apache won't override the hard-coded default	 * php.ini path setting. */	apache2_php_ini_path_override = NULL;	return OK;}static intphp_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s){	void *data = NULL;	const char *userdata_key = "apache2hook_post_config";	/* Apache will load, unload and then reload a DSO module. This	 * prevents us from starting PHP until the second load. */	apr_pool_userdata_get(&data, userdata_key, s->process->pool);	if (data == NULL) {		/* We must use set() here and *not* setn(), otherwise the		 * static string pointed to by userdata_key will be mapped		 * to a different location when the DSO is reloaded and the		 * pointers won't match, causing get() to return NULL when		 * we expected it to return non-NULL. */		apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool);		return OK;	}	/* Set up our overridden path. */	if (apache2_php_ini_path_override) {		apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;	}#ifdef ZTS	tsrm_startup(1, 1, 0, NULL);#endif	sapi_startup(&apache2_sapi_module);	apache2_sapi_module.startup(&apache2_sapi_module);	apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);	php_apache_add_version(pconf);	return OK;}static apr_status_t php_server_context_cleanup(void *data_){	void **data = data_;	*data = NULL;	return APR_SUCCESS;}static int php_apache_request_ctor(request_rec *r, php_struct *ctx TSRMLS_DC){	char *content_type;	char *content_length;	const char *auth;	SG(sapi_headers).http_response_code = !r->status ? HTTP_OK : r->status;	SG(request_info).content_type = apr_table_get(r->headers_in, "Content-Type");	SG(request_info).query_string = apr_pstrdup(r->pool, r->args);	SG(request_info).request_method = r->method;	SG(request_info).request_uri = apr_pstrdup(r->pool, r->uri);	SG(request_info).path_translated = apr_pstrdup(r->pool, r->filename);	r->no_local_copy = 1;	content_type = sapi_get_default_content_type(TSRMLS_C);	ap_set_content_type(r, apr_pstrdup(r->pool, content_type));	efree(content_type);	content_length = (char *) apr_table_get(r->headers_in, "Content-Length");	SG(request_info).content_length = (content_length ? atoi(content_length) : 0);	apr_table_unset(r->headers_out, "Content-Length");	apr_table_unset(r->headers_out, "Last-Modified");	apr_table_unset(r->headers_out, "Expires");	apr_table_unset(r->headers_out, "ETag");	if (!PG(safe_mode) || (PG(safe_mode) && !ap_auth_type(r))) {		auth = apr_table_get(r->headers_in, "Authorization");		php_handle_auth_data(auth TSRMLS_CC);		ctx->r->user = apr_pstrdup(ctx->r->pool, SG(request_info).auth_user);	} else {		SG(request_info).auth_user = NULL;		SG(request_info).auth_password = NULL;	}	return php_request_startup(TSRMLS_C);}static void php_apache_request_dtor(request_rec *r TSRMLS_DC){	php_request_shutdown(NULL);}static void php_apache_ini_dtor(request_rec *r, request_rec *p TSRMLS_DC){	if (strcmp(r->protocol, "INCLUDED")) {		zend_try { zend_ini_deactivate(TSRMLS_C); } zend_end_try();	}	if (p) {		((php_struct *)SG(server_context))->r = p;	} else {		apr_pool_cleanup_run(r->pool, (void *)&SG(server_context), php_server_context_cleanup);	}}static int php_handler(request_rec *r){	php_struct *ctx;	void *conf;	apr_bucket_brigade *brigade;	apr_bucket *bucket;	apr_status_t rv;	request_rec *parent_req = NULL;	TSRMLS_FETCH();#define PHPAP_INI_OFF php_apache_ini_dtor(r, parent_req TSRMLS_CC);	conf = ap_get_module_config(r->per_dir_config, &php4_module);	/* apply_config() needs r in some cases, so allocate server_context early */	ctx = SG(server_context);	if (ctx == NULL || (ctx && ctx->request_processed && !strcmp(r->protocol, "INCLUDED"))) {		ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx));		/* register a cleanup so we clear out the SG(server_context)		 * after each request. Note: We pass in the pointer to the		 * server_context in case this is handled by a different thread.		 */		apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), php_server_context_cleanup, apr_pool_cleanup_null);		ctx->r = r;		ctx = NULL; /* May look weird to null it here, but it is to catch the right case in the first_try later on */	} else {		parent_req = ctx->r;		ctx->r = r;	}	apply_config(conf);	if (strcmp(r->handler, PHP_MAGIC_TYPE) && strcmp(r->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(r->handler, PHP_SCRIPT)) {		/* Check for xbithack in this case. */		if (!AP2(xbithack) || strcmp(r->handler, "text/html") || !(r->finfo.protection & APR_UEXECUTE)) {			PHPAP_INI_OFF;			return DECLINED;		}	}	/* Give a 404 if PATH_INFO is used but is explicitly disabled in	 * the configuration; default behaviour is to accept. */ 	if (r->used_path_info == AP_REQ_REJECT_PATH_INFO		&& r->path_info && r->path_info[0]) {		PHPAP_INI_OFF;		return HTTP_NOT_FOUND;	}	/* handle situations where user turns the engine off */	if (!AP2(engine)) {		PHPAP_INI_OFF;		return DECLINED;	}	if (r->finfo.filetype == 0) {		php_apache_sapi_log_message_ex("script '%s' not found or unable to stat", r);		PHPAP_INI_OFF;		return HTTP_NOT_FOUND;	}	if (r->finfo.filetype == APR_DIR) {		php_apache_sapi_log_message_ex("attempt to invoke directory '%s' as script", r);		PHPAP_INI_OFF;		return HTTP_FORBIDDEN;	}	/* Setup the CGI variables if this is the main request */	if (r->main == NULL || 		/* .. or if the sub-request envinronment differs from the main-request. */ 		r->subprocess_env != r->main->subprocess_env	) {		/* setup standard CGI variables */		ap_add_common_vars(r);		ap_add_cgi_vars(r);	}zend_first_try {	if (ctx == NULL) {normal:		brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);		ctx = SG(server_context);		ctx->brigade = brigade;		if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {			zend_bailout();		}	} else {		if (!parent_req) {			parent_req = ctx->r;		}		if (parent_req && parent_req->handler && strcmp(parent_req->handler, PHP_MAGIC_TYPE) && strcmp(parent_req->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(parent_req->handler, PHP_SCRIPT)) {			if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) {				zend_bailout();			}		}				/* check if comming due to ErrorDocument */		if (parent_req && parent_req->status != HTTP_OK && strcmp(r->protocol, "INCLUDED")) {			parent_req = NULL;			goto normal;		}		ctx->r = r;		brigade = ctx->brigade;	}	if (AP2(last_modified)) {		ap_update_mtime(r, r->finfo.mtime);		ap_set_last_modified(r);	}	/* Determine if we need to parse the file or show the source */	if (strncmp(r->handler, PHP_SOURCE_MAGIC_TYPE, sizeof(PHP_SOURCE_MAGIC_TYPE) - 1) == 0) {		zend_syntax_highlighter_ini syntax_highlighter_ini;		php_get_highlight_struct(&syntax_highlighter_ini);		highlight_file((char *)r->filename, &syntax_highlighter_ini TSRMLS_CC);	} else {		zend_file_handle zfd = {0};		zfd.type = ZEND_HANDLE_FILENAME;		zfd.filename = (char *) r->filename;		zfd.free_filename = 0;		zfd.opened_path = NULL;		if (!parent_req) {			php_execute_script(&zfd TSRMLS_CC);		} else {			zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &zfd);		}#if MEMORY_LIMIT		{			char *mem_usage;						mem_usage = apr_psprintf(ctx->r->pool, "%u", AG(allocated_memory_peak));			apr_table_set(r->notes, "mod_php_memory_usage", mem_usage);		}#endif	}} zend_end_try();	if (!parent_req) {		php_apache_request_dtor(r TSRMLS_CC);		ctx->request_processed = 1;		bucket = apr_bucket_eos_create(r->connection->bucket_alloc);		APR_BRIGADE_INSERT_TAIL(brigade, bucket);		rv = ap_pass_brigade(r->output_filters, brigade);		if (rv != APR_SUCCESS || r->connection->aborted) {zend_first_try {			php_handle_aborted_connection();} zend_end_try();		}		apr_brigade_cleanup(brigade);	} else {		ctx->r = parent_req;	}	return OK;}static void php_register_hook(apr_pool_t *p){	ap_hook_pre_config(php_pre_config, NULL, NULL, APR_HOOK_MIDDLE);	ap_hook_post_config(php_apache_server_startup, NULL, NULL, APR_HOOK_MIDDLE);	ap_hook_handler(php_handler, NULL, NULL, APR_HOOK_MIDDLE);}AP_MODULE_DECLARE_DATA module php4_module = {	STANDARD20_MODULE_STUFF,	create_php_config,		/* create per-directory config structure */	merge_php_config,		/* merge per-directory config structures */	NULL,				/* create per-server config structure */	NULL,				/* merge per-server config structures */	php_dir_cmds,			/* command apr_table_t */	php_register_hook		/* register hooks */};/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 fdm=marker * vim<600: sw=4 ts=4 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -