DWORD WINAPI WorkerFunction(IN LPVOID vECB) { char szHeader[] = "Content-type: text/html\r\n\r\n"; char szContent[] = "<html> <form method=get action=WorkerThread.dll><h1>Worker Thread Sample</h1><hr>" "<input type=submit value=\"Send Request\"> </form></html>"; /* Initialize local ECB pointer to void pointer passed to thread */ EXTENSION_CONTROL_BLOCK *pECB = vECB; DWORD dwSize = strlen(szContent); /* Send outgoing header */ SendHttpHeaders(pECB, "200 OK", szHeader, FALSE); /* Simulate extended processing for 5 seconds */ Sleep(5000); /* Send content */ pECB->WriteClient(pECB->ConnID, szContent, &dwSize, 0); /* Inform server that the request has been satisfied, and the connection may now be dropped */ pECB->ServerSupportFunction(pECB->ConnID, HSE_REQ_DONE_WITH_SESSION, NULL, NULL, NULL); /* update global thread count */ InterlockedDecrement(&g_dwThreadCount); return 0; }
void ExtensionError(CControlBlock *pcb, const char *errmsg) { char *windows_error = ::GetLastError() ? ::FormatSysError(::GetLastError()) : NULL; { // temp scope to release python lock CEnterLeavePython celp; PySys_WriteStderr("Internal Extension Error: %s\n", errmsg); if (windows_error) PySys_WriteStderr("Last Windows error: %s\n", windows_error); if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } } // end temp scope if (pcb) { char *htmlStream = HTMLErrorResp(errmsg); pcb->SetStatus(HSE_STATUS_ERROR); pcb->SetLogMessage(errmsg); HSE_SEND_HEADER_EX_INFO SendHeaderExInfo; SendHeaderExInfo.pszStatus = "200 OK"; SendHeaderExInfo.cchStatus = strlen(SendHeaderExInfo.pszStatus); SendHeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n"; SendHeaderExInfo.cchHeader = strlen(SendHeaderExInfo.pszHeader); SendHeaderExInfo.fKeepConn = FALSE; EXTENSION_CONTROL_BLOCK * ecb = pcb->GetECB(); ecb->ServerSupportFunction(ecb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &SendHeaderExInfo, NULL,NULL); pcb->WriteStream(htmlStream, strlen(htmlStream)); if (windows_error) { static char *chunk = "<br>Last Windows error:"; pcb->WriteStream(chunk, strlen(chunk)); pcb->WriteStream(windows_error, strlen(windows_error)); } } const char *inserts[] = {errmsg, windows_error ? windows_error : "n/a"}; WriteEventLogMessage(EVENTLOG_ERROR_TYPE, E_PYISAPI_EXTENSION_FAILED, 2, inserts); if (windows_error) free(windows_error); }