📄 shorthand_isapi.cpp
字号:
}
total_read += cbRead;
}
return total_read;
}
*/
/*
static char *sapi_isapi_read_cookies(TSRMLS_D)
{
LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) {
return estrndup(variable_buf, variable_len);
} else if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) {
char *tmp_variable_buf = (char *) emalloc(variable_len+1);
if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) {
tmp_variable_buf[variable_len] = 0;
return tmp_variable_buf;
} else {
efree(tmp_variable_buf);
}
}
return NULL;
}
*/
/*
static void sapi_isapi_register_server_variables2(char **server_variables, LPEXTENSION_CONTROL_BLOCK lpECB, zval *track_vars_array, char **recorded_values TSRMLS_DC)
{
char **p=server_variables;
DWORD variable_len;
char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
char *variable_buf;
while (*p) {
variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
if (lpECB->GetServerVariable(lpECB->ConnID, *p, static_variable_buf, &variable_len)
&& static_variable_buf[0]) {
php_register_variable(*p, static_variable_buf, track_vars_array TSRMLS_CC);
if (recorded_values) {
recorded_values[p-server_variables] = estrndup(static_variable_buf, variable_len);
}
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
variable_buf = (char *) emalloc(variable_len+1);
if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len)
&& variable_buf[0]) {
php_register_variable(*p, variable_buf, track_vars_array TSRMLS_CC);
}
if (recorded_values) {
recorded_values[p-server_variables] = variable_buf;
} else {
efree(variable_buf);
}
}
p++;
}
}
*/
/*
static void sapi_isapi_register_server_variables(zval *track_vars_array TSRMLS_DC)
{
DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
char *variable;
char *strtok_buf = NULL;
char *isapi_special_server_variables[NUM_SPECIAL_VARS];
LPEXTENSION_CONTROL_BLOCK lpECB;
lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
// Register the special ISAPI variables
memset(isapi_special_server_variables, 0, sizeof(isapi_special_server_variables));
sapi_isapi_register_server_variables2(isapi_special_server_variable_names, lpECB, track_vars_array, isapi_special_server_variables TSRMLS_CC);
if (SG(request_info).cookie_data) {
php_register_variable("HTTP_COOKIE", SG(request_info).cookie_data, track_vars_array TSRMLS_CC);
}
// Register the standard ISAPI variables
sapi_isapi_register_server_variables2(isapi_server_variable_names, lpECB, track_vars_array, NULL TSRMLS_CC);
if (isapi_special_server_variables[SPECIAL_VAR_HTTPS]
&& atoi(isapi_special_server_variables[SPECIAL_VAR_HTTPS])) {
// Register SSL ISAPI variables
sapi_isapi_register_server_variables2(isapi_secure_server_variable_names, lpECB, track_vars_array, NULL TSRMLS_CC);
}
if (isapi_special_server_variables[SPECIAL_VAR_HTTPS]) {
efree(isapi_special_server_variables[SPECIAL_VAR_HTTPS]);
}
#ifdef WITH_ZEUS
sapi_isapi_register_zeus_variables(lpECB, track_vars_array TSRMLS_CC);
#endif
// PHP_SELF support
if (isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]) {
php_register_variable("PHP_SELF", isapi_special_server_variables[SPECIAL_VAR_PHP_SELF], track_vars_array TSRMLS_CC);
efree(isapi_special_server_variables[SPECIAL_VAR_PHP_SELF]);
}
if (isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP]) {
// Register the internal bits of ALL_HTTP
variable = php_strtok_r(isapi_special_server_variables[SPECIAL_VAR_ALL_HTTP], "\r\n", &strtok_buf);
while (variable) {
char *colon = strchr(variable, ':');
if (colon) {
char *value = colon+1;
while (*value==' ') {
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]);
}
#ifdef PHP_WIN32
{
HSE_URL_MAPEX_INFO humi;
DWORD path_len = 2;
char path[] = "/";
if (lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_MAP_URL_TO_PATH_EX, path, &path_len, (LPDWORD) &humi)) {
// Remove trailing \
if (humi.lpszPath[path_len-2] == '\\') {
humi.lpszPath[path_len-2] = 0;
}
php_register_variable("DOCUMENT_ROOT", humi.lpszPath, track_vars_array TSRMLS_CC);
}
}
#endif
}
*/
#if 0
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 */
NULL, /* Block interruptions */
NULL, /* Unblock interruptions */
STANDARD_SAPI_MODULE_PROPERTIES
};
#endif
/**
* The GetFilterVersion function is the first entry-point function called by
* IIS on your ISAPI filter, and must be present for the filter to work properly.
* IIS passes a pointer to a HTTP_FILTER_VERSION Structure data structure, which
* can be used to supply important filter configuration information to IIS.
* The most important information passed to IIS is the bitmask that contains
* flags that specify which notification events your filter can process, and
* a flag that indicates the overall processing priority for your filter.
*/
BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion)
{
TRACE((3, "ISAPI: GetFilterVersion() started\n"));
bFilterLoaded = 1;
pFilterVersion->dwFilterVersion = HTTP_FILTER_REVISION;
strcpy(pFilterVersion->lpszFilterDesc, "ShortHand");
pFilterVersion->dwFlags= (SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_PREPROC_HEADERS);
return TRUE;
}
/**
* IIS calls the HttpFilterProc entry point function whenever a notification event
* for which the filter has registered occurs. IIS uses this function to pass
* information and control to your ISAPI filter
*/
DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pvNotification)
{
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)
{
// TODO!!!
/*
SG(request_info).request_method = lpECB->lpszMethod;
SG(request_info).query_string = lpECB->lpszQueryString;
SG(request_info).path_translated = lpECB->lpszPathTranslated;
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;
}
*/
}
/*
static void php_isapi_report_exception(char *message, int message_len)
{
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;
lstrcpyn(pVer->lpszExtensionDesc, "ShortHand", HSE_MAX_EXT_DLL_NAME_LEN);
return TRUE;
}
static void my_endthread()
{
#ifdef PHP_WIN32
if (bTerminateThreadsOnError) {
_endthread();
}
#endif
}
/* 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;
}
DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
{
int file_handle;
bool stack_overflown=0;
file_handle = 0;
LPEXCEPTION_POINTERS e;
__try {
init_request_info(lpECB);
//SG(server_context) = lpECB;
TRACE((10, "HttpExtensionProc(): lpszPathTranslated = '%s'\n", lpECB->lpszPathTranslated));
//isapi_write_client(lpECB, "<html><body>Hello, ISAPI !</body></html>");
isapi_shorthand_main(lpECB, 0);
/*
file_handle.filename = SG(request_info.path_translated);
file_handle.free_filename = 0;
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.opened_path = NULL;*/
//php_request_startup(TSRMLS_C);
//TODO!!!
//php_execute_script(&file_handle);
//TODO!!!
//if (SG(request_info).cookie_data) { efree(SG(request_info).cookie_data); }
}
__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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -