📄 jk_isapi_plugin.c
字号:
l = 0; name[l] = '\0'; }}/* Apache code to escape a URL */#define T_OS_ESCAPE_PATH (4)static const BYTE test_char_table[256] = { 0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 0, 7, 6, 1, 6, 1, 1, 9, 9, 1, 0, 8, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 15, 15, 8, 15, 15, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 15, 15, 7, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 7, 15, 1, 14, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6};#define TEST_CHAR(c, f) (test_char_table[(unsigned int)(c)] & (f))static const char c2x_table[] = "0123456789abcdef";static BYTE *c2x(unsigned int what, BYTE *where){ *where++ = '%'; *where++ = c2x_table[what >> 4]; *where++ = c2x_table[what & 0xf]; return where;}static char *status_reason(int status){ static struct reasons { int status; char *reason; } *r, reasons[] = { { 100, "Continue" }, { 101, "Switching Protocols" }, { 200, "OK" }, { 201, "Created" }, { 202, "Accepted" }, { 203, "Non-Authoritative Information" }, { 204, "No Content" }, { 205, "Reset Content" }, { 206, "Partial Content" }, { 300, "Multiple Choices" }, { 301, "Moved Permanently" }, { 302, "Moved Temporarily" }, { 303, "See Other" }, { 304, "Not Modified" }, { 305, "Use Proxy" }, { 400, "Bad Request" }, { 401, "Unauthorized" }, { 402, "Payment Required" }, { 403, "Forbidden" }, { 404, "Not Found" }, { 405, "Method Not Allowed" }, { 406, "Not Acceptable" }, { 407, "Proxy Authentication Required" }, { 408, "Request Timeout" }, { 409, "Conflict" }, { 410, "Gone" }, { 411, "Length Required" }, { 412, "Precondition Failed" }, { 413, "Request Entity Too Large" }, { 414, "Request-URI Too Long" }, { 415, "Unsupported Media Type" }, { 500, "Internal Server Error" }, { 501, "Not Implemented" }, { 502, "Bad Gateway" }, { 503, "Service Unavailable" }, { 504, "Gateway Timeout" }, { 505, "HTTP Version Not Supported" }, { 000, NULL} }; r = reasons; while (r->status <= status) if (r->status == status) return r->reason; else r++; return "No Reason";}static int escape_url(const char *path, char *dest, int destsize){ const BYTE *s = (const BYTE *)path; BYTE *d = (BYTE *)dest; BYTE *e = d + destsize - 1; BYTE *ee = d + destsize - 3; while (*s) { if (TEST_CHAR(*s, T_OS_ESCAPE_PATH)) { if (d >= ee) return JK_FALSE; d = c2x(*s, d); } else { if (d >= e) return JK_FALSE; *d++ = *s; } ++s; } *d = '\0'; return JK_TRUE;}/* * Find the first occurrence of find in s. */static char *stristr(const char *s, const char *find){ char c, sc; size_t len; if ((c = tolower((unsigned char)(*find++))) != 0) { len = strlen(find); do { do { if ((sc = tolower((unsigned char)(*s++))) == 0) return (NULL); } while (sc != c); } while (strnicmp(s, find, len) != 0); s--; } return ((char *)s);}static int uri_is_web_inf(const char *uri){ if (stristr(uri, "/web-inf")) { return JK_TRUE; } if (stristr(uri, "/meta-inf")) { return JK_TRUE; } return JK_FALSE;}static void write_error_response(PHTTP_FILTER_CONTEXT pfc, char *status, char *msg){ DWORD len = (DWORD)strlen(msg); /* reject !!! */ pfc->AddResponseHeaders(pfc, CONTENT_TYPE, 0); pfc->ServerSupportFunction(pfc, SF_REQ_SEND_RESPONSE_HEADER, status, 0, 0); pfc->WriteClient(pfc, msg, &len, 0);}static void write_error_message(LPEXTENSION_CONTROL_BLOCK lpEcb, int err){ DWORD len; if (err = 500) { lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, "500 Internal Server Error", 0, (LPDWORD)CONTENT_TYPE); len = (DWORD)(sizeof(HTML_ERROR_500) - 1); lpEcb->WriteClient(lpEcb->ConnID, HTML_ERROR_503, &len, 0); } else if (err == 503) { lpEcb->ServerSupportFunction(lpEcb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, "503 Service Unavailable", 0, (LPDWORD)CONTENT_TYPE); len = (DWORD)(sizeof(HTML_ERROR_503) - 1); lpEcb->WriteClient(lpEcb->ConnID, HTML_ERROR_503, &len, 0); } else { return; }}static int JK_METHOD start_response(jk_ws_service_t *s, int status, const char *reason, const char *const *header_names, const char *const *header_values, unsigned int num_of_headers){ static char crlf[3] = { (char)13, (char)10, '\0' }; JK_TRACE_ENTER(logger); if (status < 100 || status > 1000) { jk_log(logger, JK_LOG_ERROR, "invalid status %d", status); JK_TRACE_EXIT(logger); return JK_FALSE; } if (s && s->ws_private) { int rv = JK_TRUE; isapi_private_data_t *p = s->ws_private; if (!p->request_started) { char *status_str; DWORD status_str_len; char *headers_str = NULL; BOOL keep_alive = FALSE; p->request_started = JK_TRUE; /* * Create the status line */ if (!reason) { reason = status_reason(status); } status_str = (char *)malloc((6 + strlen(reason))); StringCbPrintf(status_str, 6 + strlen(reason), "%d %s", status, reason); status_str_len = (DWORD)strlen(status_str); /* * Create response headers string */ if (num_of_headers) { size_t i, len_of_headers = 0; for (i = 0, len_of_headers = 0; i < num_of_headers; i++) { len_of_headers += strlen(header_names[i]); len_of_headers += strlen(header_values[i]); len_of_headers += 4; /* extra for colon, space and crlf */ } len_of_headers += 3; /* crlf and terminating null char */ headers_str = (char *)malloc(len_of_headers); headers_str[0] = '\0'; for (i = 0; i < num_of_headers; i++) { StringCbCat(headers_str, len_of_headers, header_names[i]); StringCbCat(headers_str, len_of_headers, ": "); StringCbCat(headers_str, len_of_headers, header_values[i]); StringCbCat(headers_str, len_of_headers, crlf); } StringCbCat(headers_str, len_of_headers, crlf); } else { headers_str = crlf; } if (!p->lpEcb->ServerSupportFunction(p->lpEcb->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, status_str, &status_str_len, (LPDWORD)headers_str)) { jk_log(logger, JK_LOG_ERROR, "HSE_REQ_SEND_RESPONSE_HEADER failed with error=%08x", GetLastError()); rv = JK_FALSE; } if (headers_str) free(headers_str); if (status_str) free(status_str); } JK_TRACE_EXIT(logger); return rv; } JK_LOG_NULL_PARAMS(logger); JK_TRACE_EXIT(logger); return JK_FALSE;}static int JK_METHOD read(jk_ws_service_t *s, void *b, unsigned int l, unsigned int *a){ JK_TRACE_ENTER(logger); if (s && s->ws_private && b && a) { isapi_private_data_t *p = s->ws_private; if (JK_IS_DEBUG_LEVEL(logger)) { jk_log(logger, JK_LOG_DEBUG, "Preparing to read %d bytes. " "ECB reports %d bytes total, with %d available.", l, p->lpEcb->cbTotalBytes, p->lpEcb->cbAvailable); } *a = 0; if (l) { char *buf = b; DWORD already_read = p->lpEcb->cbAvailable - p->bytes_read_so_far; if (already_read >= l) { if (JK_IS_DEBUG_LEVEL(logger)) { jk_log(logger, JK_LOG_DEBUG, "Already read %d bytes - supplying %d bytes from buffer", already_read, l); } memcpy(buf, p->lpEcb->lpbData + p->bytes_read_so_far, l); p->bytes_read_so_far += l; *a = l; } else { /* * Try to copy what we already have */ if (already_read > 0) { if (JK_IS_DEBUG_LEVEL(logger)) { jk_log(logger, JK_LOG_DEBUG, "Supplying %d bytes from buffer", already_read); } memcpy(buf, p->lpEcb->lpbData + p->bytes_read_so_far, already_read); buf += already_read; l -= already_read; p->bytes_read_so_far = p->lpEcb->cbAvailable; *a = already_read; } /* * Now try to read from the client ... */ if (JK_IS_DEBUG_LEVEL(logger)) { jk_log(logger, JK_LOG_DEBUG, "Attempting to read %d bytes from client", l); } if (p->lpEcb->ReadClient(p->lpEcb->ConnID, buf, (LPDWORD)&l)) { *a += l; } else { jk_log(logger, JK_LOG_ERROR, "ReadClient failed with %08x", GetLastError()); JK_TRACE_EXIT(logger); return JK_FALSE; } } } JK_TRACE_EXIT(logger); return JK_TRUE; } JK_LOG_NULL_PARAMS(logger); JK_TRACE_EXIT(logger); return JK_FALSE;}static int JK_METHOD write(jk_ws_service_t *s, const void *b, unsigned int l){ JK_TRACE_ENTER(logger); if (s && s->ws_private && b) { isapi_private_data_t *p = s->ws_private; if (l) { unsigned int written = 0; char *buf = (char *)b; if (!p->request_started) { start_response(s, 200, NULL, NULL, NULL, 0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -