📄 php4isapi.c
字号:
/* +----------------------------------------------------------------------+ | PHP Version 4 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2007 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Zeev Suraski <zeev@zend.com> | | Ben Mansell <ben@zeus.com> (Zeus Support) | +----------------------------------------------------------------------+ *//* $Id: php4isapi.c,v 1.92.2.13.2.3 2007/03/05 22:04:54 stas Exp $ */#ifdef PHP_WIN32# include <windows.h># include <process.h>#else# define __try# define __except(val)# define __declspec(foo)#endif#include <httpext.h>#include <httpfilt.h>#include <httpext.h>#include "php.h"#include "php_main.h"#include "SAPI.h"#include "php_globals.h"#include "ext/standard/info.h"#include "php_variables.h"#include "php_ini.h"#ifdef WITH_ZEUS# include "httpext.h"# include <errno.h># define GetLastError() errno#endif#ifdef PHP_WIN32#define PHP_ENABLE_SEH#endif/* uncomment the following lines to turn off exception trapping when running under a debugger #ifdef _DEBUG#undef PHP_ENABLE_SEH#endif*/#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST POSSIBLE STATUS DESCRIPTION")#define ISAPI_SERVER_VAR_BUF_SIZE 1024#define ISAPI_POST_DATA_BUF 1024static zend_bool bFilterLoaded=0;static zend_bool bTerminateThreadsOnError=0;static char *isapi_special_server_variable_names[] = { "ALL_HTTP", "HTTPS",#ifndef WITH_ZEUS "SCRIPT_NAME",#endif NULL};#define NUM_SPECIAL_VARS (sizeof(isapi_special_server_variable_names)/sizeof(char *))#define SPECIAL_VAR_ALL_HTTP 0#define SPECIAL_VAR_HTTPS 1#define SPECIAL_VAR_PHP_SELF 2static char *isapi_server_variable_names[] = { "AUTH_PASSWORD", "AUTH_TYPE", "AUTH_USER", "CONTENT_LENGTH", "CONTENT_TYPE", "PATH_TRANSLATED", "QUERY_STRING", "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_USER", "REQUEST_METHOD", "SERVER_NAME", "SERVER_PORT", "SERVER_PROTOCOL", "SERVER_SOFTWARE",#ifndef WITH_ZEUS "APPL_MD_PATH", "APPL_PHYSICAL_PATH", "INSTANCE_ID", "INSTANCE_META_PATH", "LOGON_USER", "REQUEST_URI", "URL",#else "DOCUMENT_ROOT",#endif NULL};static char *isapi_secure_server_variable_names[] = { "CERT_COOKIE", "CERT_FLAGS", "CERT_ISSUER", "CERT_KEYSIZE", "CERT_SECRETKEYSIZE", "CERT_SERIALNUMBER", "CERT_SERVER_ISSUER", "CERT_SERVER_SUBJECT", "CERT_SUBJECT", "HTTPS_KEYSIZE", "HTTPS_SECRETKEYSIZE", "HTTPS_SERVER_ISSUER", "HTTPS_SERVER_SUBJECT", "SERVER_PORT_SECURE",#ifdef WITH_ZEUS "SSL_CLIENT_CN", "SSL_CLIENT_EMAIL", "SSL_CLIENT_OU", "SSL_CLIENT_O", "SSL_CLIENT_L", "SSL_CLIENT_ST", "SSL_CLIENT_C", "SSL_CLIENT_I_CN", "SSL_CLIENT_I_EMAIL", "SSL_CLIENT_I_OU", "SSL_CLIENT_I_O", "SSL_CLIENT_I_L", "SSL_CLIENT_I_ST", "SSL_CLIENT_I_C", #endif NULL};static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS){ char **p; char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; DWORD variable_len; char **all_variables[] = { isapi_server_variable_names, isapi_special_server_variable_names, isapi_secure_server_variable_names, NULL }; char ***server_variable_names; LPEXTENSION_CONTROL_BLOCK lpECB; lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); php_info_print_table_start(); php_info_print_table_header(2, "Server Variable", "Value"); server_variable_names = all_variables; while (*server_variable_names) { p = *server_variable_names; while (*p) { variable_len = ISAPI_SERVER_VAR_BUF_SIZE; if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) && variable_buf[0]) { php_info_print_table_row(2, *p, variable_buf); } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { char *tmp_variable_buf; tmp_variable_buf = (char *) emalloc(variable_len); if (lpECB->GetServerVariable(lpECB->ConnID, *p, tmp_variable_buf, &variable_len) && variable_buf[0]) { php_info_print_table_row(2, *p, tmp_variable_buf); } efree(tmp_variable_buf); } p++; } server_variable_names++; } php_info_print_table_end();}static zend_module_entry php_isapi_module = { STANDARD_MODULE_HEADER, "ISAPI", NULL, NULL, NULL, NULL, NULL, php_info_isapi, NULL, STANDARD_MODULE_PROPERTIES};static int sapi_isapi_ub_write(const char *str, uint str_length TSRMLS_DC){ DWORD num_bytes = str_length; LPEXTENSION_CONTROL_BLOCK ecb; ecb = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); if (ecb->WriteClient(ecb->ConnID, (char *) str, &num_bytes, HSE_IO_SYNC) == FALSE) { php_handle_aborted_connection(); } return num_bytes;}static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC){ return SAPI_HEADER_ADD;}static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length TSRMLS_DC){ *total_length += sapi_header->header_len+2;}static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr TSRMLS_DC){ memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len); *combined_headers_ptr += sapi_header->header_len; **combined_headers_ptr = '\r'; (*combined_headers_ptr)++; **combined_headers_ptr = '\n'; (*combined_headers_ptr)++;}static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC){ uint total_length = 2; /* account for the trailing \r\n */ char *combined_headers, *combined_headers_ptr; LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); HSE_SEND_HEADER_EX_INFO header_info; sapi_header_struct default_content_type; char *status_buf = NULL; /* Obtain headers length */ if (SG(sapi_headers).send_default_content_type) { sapi_get_default_content_type_header(&default_content_type TSRMLS_CC); accumulate_header_length(&default_content_type, (void *) &total_length TSRMLS_CC); } zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) accumulate_header_length, (void *) &total_length TSRMLS_CC); /* Generate headers */ combined_headers = (char *) emalloc(total_length+1); combined_headers_ptr = combined_headers; if (SG(sapi_headers).send_default_content_type) { concat_header(&default_content_type, (void *) &combined_headers_ptr TSRMLS_CC); sapi_free_header(&default_content_type); /* we no longer need it */ } zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t) concat_header, (void *) &combined_headers_ptr TSRMLS_CC); *combined_headers_ptr++ = '\r'; *combined_headers_ptr++ = '\n'; *combined_headers_ptr = 0; switch (SG(sapi_headers).http_response_code) { case 200: header_info.pszStatus = "200 OK"; break; case 302: header_info.pszStatus = "302 Moved Temporarily"; break; case 401: header_info.pszStatus = "401 Authorization Required"; break; default: { const char *sline = SG(sapi_headers).http_status_line; status_buf = emalloc(MAX_STATUS_LENGTH + 1); /* httpd requires that r->status_line is set to the first digit of * the status-code: */ if (sline && strlen(sline) > 12 && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') { status_buf = estrndup(sline + 9, MAX_STATUS_LENGTH); } else { snprintf(status_buf, MAX_STATUS_LENGTH, "%d Undescribed", SG(sapi_headers).http_response_code); } header_info.pszStatus = status_buf; break; } } header_info.cchStatus = strlen(header_info.pszStatus); header_info.pszHeader = combined_headers; header_info.cchHeader = total_length; header_info.fKeepConn = FALSE; lpECB->dwHttpStatusCode = SG(sapi_headers).http_response_code; lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); efree(combined_headers); if (status_buf) { efree(status_buf); } return SAPI_HEADER_SENT_SUCCESSFULLY;}static int php_isapi_startup(sapi_module_struct *sapi_module){ if (php_module_startup(sapi_module, &php_isapi_module, 1)==FAILURE) { return FAILURE; } else { bTerminateThreadsOnError = (zend_bool) INI_INT("isapi.terminate_threads_on_error"); return SUCCESS; }}static int sapi_isapi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -