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

📄 php4isapi.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
					value++;				}				*colon = 0;				php_register_variable(variable, value, track_vars_array TSRMLS_CC);				*colon = ':';			}			variable = php_strtok_r(NULL, "\r\n", &strtok_buf);		}		efree(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]);	}}static sapi_module_struct isapi_sapi_module = {	"isapi",						/* name */	"ISAPI",						/* pretty name */										php_isapi_startup,				/* startup */	php_module_shutdown_wrapper,	/* shutdown */	NULL,							/* activate */	NULL,							/* deactivate */	sapi_isapi_ub_write,			/* unbuffered write */	NULL,							/* flush */	NULL,							/* get uid */	NULL,							/* getenv */	php_error,						/* error handler */	sapi_isapi_header_handler,		/* header handler */	sapi_isapi_send_headers,		/* send headers handler */	NULL,							/* send header handler */	sapi_isapi_read_post,			/* read POST data */	sapi_isapi_read_cookies,		/* read Cookies */	sapi_isapi_register_server_variables,	/* register server variables */	NULL,									/* Log message */	STANDARD_SAPI_MODULE_PROPERTIES};BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion){	bFilterLoaded = 1;	pFilterVersion->dwFilterVersion = HTTP_FILTER_REVISION;	strcpy(pFilterVersion->lpszFilterDesc, isapi_sapi_module.pretty_name);	pFilterVersion->dwFlags= (SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_PREPROC_HEADERS);	return TRUE;}DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pvNotification){	TSRMLS_FETCH();	switch (notificationType) {		case SF_NOTIFY_PREPROC_HEADERS:			SG(request_info).auth_user = NULL;			SG(request_info).auth_password = NULL;			break;		case SF_NOTIFY_AUTHENTICATION: {				char *auth_user = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszUser;				char *auth_password = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszPassword;				if (auth_user && auth_user[0]) {					SG(request_info).auth_user = estrdup(auth_user);				}					if (auth_password && auth_password[0]) {					SG(request_info).auth_password = estrdup(auth_password);				}				return SF_STATUS_REQ_HANDLED_NOTIFICATION;			}			break;	}	return SF_STATUS_REQ_NEXT_NOTIFICATION;}static void init_request_info(LPEXTENSION_CONTROL_BLOCK lpECB TSRMLS_DC){	DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;	char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];#ifndef WITH_ZEUS	HSE_URL_MAPEX_INFO humi;#endif	SG(request_info).request_method = lpECB->lpszMethod;	SG(request_info).query_string = lpECB->lpszQueryString;	SG(request_info).request_uri = lpECB->lpszPathInfo;	SG(request_info).content_type = lpECB->lpszContentType;	SG(request_info).content_length = lpECB->cbTotalBytes;	SG(sapi_headers).http_response_code = 200;  /* I think dwHttpStatusCode is invalid at this stage -RL */	if (!bFilterLoaded) { /* we don't have valid ISAPI Filter information */		SG(request_info).auth_user = SG(request_info).auth_password = NULL;	}#ifdef WITH_ZEUS	/* PATH_TRANSLATED can contain extra PATH_INFO stuff after the	 * file being loaded, so we must use SCRIPT_FILENAME instead	 */	if(lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_FILENAME", static_variable_buf, &variable_len)) {		SG(request_info).path_translated = estrdup(static_variable_buf);	} else #else	/* happily, IIS gives us SCRIPT_NAME which is correct (without PATH_INFO stuff)	   so we can just map that to the physical path and we have our filename */	lpECB->GetServerVariable(lpECB->ConnID, "SCRIPT_NAME", static_variable_buf, &variable_len);	if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, static_variable_buf, &variable_len, (LPDWORD) &humi)) {		SG(request_info).path_translated = estrdup(humi.lpszPath);	} else #endif		/* if mapping fails, default to what the server tells us */		SG(request_info).path_translated = estrdup(lpECB->lpszPathTranslated);	/* some server configurations allow '..' to slip through in the	   translated path.   We'll just refuse to handle such a path. */	if (strstr(SG(request_info).path_translated,"..")) {		SG(sapi_headers).http_response_code = 404;		efree(SG(request_info).path_translated);		SG(request_info).path_translated = NULL;	}}static void php_isapi_report_exception(char *message, int message_len TSRMLS_DC){	if (!SG(headers_sent)) {		HSE_SEND_HEADER_EX_INFO header_info;		LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);		header_info.pszStatus = "500 Internal Server Error";		header_info.cchStatus = strlen(header_info.pszStatus);		header_info.pszHeader = "Content-Type: text/html\r\n\r\n";		header_info.cchHeader = strlen(header_info.pszHeader);		lpECB->dwHttpStatusCode = 500;		lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL);		SG(headers_sent)=1;	}	sapi_isapi_ub_write(message, message_len TSRMLS_CC);}BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer){	pVer->dwExtensionVersion = HSE_VERSION;#ifdef WITH_ZEUS	strncpy( pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN);#else	lstrcpyn(pVer->lpszExtensionDesc, isapi_sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN);#endif	return TRUE;}static void my_endthread(){#ifdef PHP_WIN32	if (bTerminateThreadsOnError) {		_endthread();	}#endif}#ifdef PHP_WIN32/* ep is accessible only in the context of the __except expression, * so we have to call this function to obtain it. */BOOL exceptionhandler(LPEXCEPTION_POINTERS *e, LPEXCEPTION_POINTERS ep){	*e=ep;	return TRUE;}#endifDWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB){	zend_file_handle file_handle = {0};	zend_bool stack_overflown=0;	int retval = FAILURE;#ifdef PHP_ENABLE_SEH	LPEXCEPTION_POINTERS e;#endif	TSRMLS_FETCH();	zend_first_try {#ifdef PHP_ENABLE_SEH		__try {#endif			init_request_info(lpECB TSRMLS_CC);			SG(server_context) = lpECB;			php_request_startup(TSRMLS_C);			file_handle.filename = SG(request_info).path_translated;			file_handle.free_filename = 0;			file_handle.type = ZEND_HANDLE_FILENAME;			file_handle.opened_path = NULL;			/* open the script here so we can 404 if it fails */			if (file_handle.filename)				retval = php_fopen_primary_script(&file_handle TSRMLS_CC);			if (!file_handle.filename || retval == FAILURE) {				SG(sapi_headers).http_response_code = 404;				PUTS("No input file specified.\n");			} else {				php_execute_script(&file_handle TSRMLS_CC);			}			if (SG(request_info).cookie_data) {				efree(SG(request_info).cookie_data);			}			if (SG(request_info).path_translated)				efree(SG(request_info).path_translated);#ifdef PHP_ENABLE_SEH		} __except(exceptionhandler(&e, GetExceptionInformation())) {			char buf[1024];			if (_exception_code()==EXCEPTION_STACK_OVERFLOW) {				LPBYTE lpPage;				static SYSTEM_INFO si;				static MEMORY_BASIC_INFORMATION mi;				static DWORD dwOldProtect;				GetSystemInfo(&si);				/* Get page ESP is pointing to */				_asm mov lpPage, esp;				/* Get stack allocation base */				VirtualQuery(lpPage, &mi, sizeof(mi));				/* Go to the page below the current page */				lpPage = (LPBYTE) (mi.BaseAddress) - si.dwPageSize;				/* Free pages below current page */				if (!VirtualFree(mi.AllocationBase, (LPBYTE)lpPage - (LPBYTE) mi.AllocationBase, MEM_DECOMMIT)) {					_endthread();				}				/* Restore the guard page */				if (!VirtualProtect(lpPage, si.dwPageSize, PAGE_GUARD | PAGE_READWRITE, &dwOldProtect)) {					_endthread();				}				CG(unclean_shutdown)=1;				_snprintf(buf, sizeof(buf)-1,"PHP has encountered a Stack overflow");				php_isapi_report_exception(buf, strlen(buf) TSRMLS_CC);			} else if (_exception_code()==EXCEPTION_ACCESS_VIOLATION) {				_snprintf(buf, sizeof(buf)-1,"PHP has encountered an Access Violation at %p", e->ExceptionRecord->ExceptionAddress);				php_isapi_report_exception(buf, strlen(buf) TSRMLS_CC);				my_endthread();			} else {				_snprintf(buf, sizeof(buf)-1,"PHP has encountered an Unhandled Exception Code %d at %p", e->ExceptionRecord->ExceptionCode , e->ExceptionRecord->ExceptionAddress);				php_isapi_report_exception(buf, strlen(buf) TSRMLS_CC);				my_endthread();			}		}#endif#ifdef PHP_ENABLE_SEH		__try {			php_request_shutdown(NULL);		} __except(EXCEPTION_EXECUTE_HANDLER) {			my_endthread();		}#else		php_request_shutdown(NULL);#endif	} zend_catch {		zend_try {			php_request_shutdown(NULL);		} zend_end_try();		return HSE_STATUS_ERROR;	} zend_end_try();	return HSE_STATUS_SUCCESS;}__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){	switch (fdwReason) {		case DLL_PROCESS_ATTACH:#ifdef WITH_ZEUS			tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "TSRM.log");#else			tsrm_startup(128, 1, TSRM_ERROR_LEVEL_CORE, "C:\\TSRM.log");#endif			sapi_startup(&isapi_sapi_module);			if (isapi_sapi_module.startup) {				isapi_sapi_module.startup(&sapi_module);			}			break;		case DLL_THREAD_ATTACH:			break;		case DLL_THREAD_DETACH:			ts_free_thread();			break;		case DLL_PROCESS_DETACH:			if (isapi_sapi_module.shutdown) {				isapi_sapi_module.shutdown(&sapi_module);			}			sapi_shutdown();			tsrm_shutdown();			break;	}	return TRUE;}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */

⌨️ 快捷键说明

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