| 361 | // general error handler |
| 362 | |
| 363 | void ExtensionError(CControlBlock *pcb, const char *errmsg) |
| 364 | { |
| 365 | char *windows_error = ::GetLastError() ? |
| 366 | ::FormatSysError(::GetLastError()) : NULL; |
| 367 | { // temp scope to release python lock |
| 368 | CEnterLeavePython celp; |
| 369 | PySys_WriteStderr("Internal Extension Error: %s\n", errmsg); |
| 370 | if (windows_error) |
| 371 | PySys_WriteStderr("Last Windows error: %s\n", windows_error); |
| 372 | if (PyErr_Occurred()) { |
| 373 | PyErr_Print(); |
| 374 | PyErr_Clear(); |
| 375 | } |
| 376 | } // end temp scope |
| 377 | if (pcb) { |
| 378 | char *htmlStream = HTMLErrorResp(errmsg); |
| 379 | |
| 380 | pcb->SetStatus(HSE_STATUS_ERROR); |
| 381 | pcb->SetLogMessage(errmsg); |
| 382 | HSE_SEND_HEADER_EX_INFO SendHeaderExInfo; |
| 383 | SendHeaderExInfo.pszStatus = "200 OK"; |
| 384 | SendHeaderExInfo.cchStatus = strlen(SendHeaderExInfo.pszStatus); |
| 385 | SendHeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n"; |
| 386 | SendHeaderExInfo.cchHeader = strlen(SendHeaderExInfo.pszHeader); |
| 387 | SendHeaderExInfo.fKeepConn = FALSE; |
| 388 | EXTENSION_CONTROL_BLOCK * ecb = pcb->GetECB(); |
| 389 | ecb->ServerSupportFunction(ecb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &SendHeaderExInfo, NULL,NULL); |
| 390 | pcb->WriteStream(htmlStream, strlen(htmlStream)); |
| 391 | if (windows_error) { |
| 392 | static char *chunk = "<br>Last Windows error:"; |
| 393 | pcb->WriteStream(chunk, strlen(chunk)); |
| 394 | pcb->WriteStream(windows_error, strlen(windows_error)); |
| 395 | } |
| 396 | } |
| 397 | const char *inserts[] = {errmsg, windows_error ? windows_error : "n/a"}; |
| 398 | WriteEventLogMessage(EVENTLOG_ERROR_TYPE, E_PYISAPI_EXTENSION_FAILED, |
| 399 | 2, inserts); |
| 400 | if (windows_error) |
| 401 | free(windows_error); |
| 402 | } |
| 403 | |
| 404 | void FilterError(CFilterContext *pfc, const char *errmsg) |
| 405 | { |
no test coverage detected