📄 mod_isapi.c
字号:
ap_log_rerror(APLOG_MARK, APLOG_WARNING, r, "ISAPI asynchronous I/O not supported: %s", r->filename); case HSE_STATUS_ERROR: default: return SERVER_ERROR; }}#pragma optimize("",on)BOOL WINAPI GetServerVariable (HCONN hConn, LPSTR lpszVariableName, LPVOID lpvBuffer, LPDWORD lpdwSizeofBuffer) { request_rec *r = ((isapi_cid *)hConn)->r; table *e = r->subprocess_env; const char *result; /* Mostly, we just grab it from the environment, but there are * a couple of special cases */ if (!strcasecmp(lpszVariableName, "UNMAPPED_REMOTE_USER")) { /* We don't support NT users, so this is always the same as * REMOTE_USER */ result = ap_table_get(e, "REMOTE_USER"); } else if (!strcasecmp(lpszVariableName, "SERVER_PORT_SECURE")) { /* Apache doesn't support secure requests inherently, so * we have no way of knowing. We'll be conservative, and say * all requests are insecure. */ result = "0"; } else if (!strcasecmp(lpszVariableName, "URL")) { result = r->uri; } else { result = ap_table_get(e, lpszVariableName); } if (result) { if (strlen(result) > *lpdwSizeofBuffer) { *lpdwSizeofBuffer = strlen(result); SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } strncpy(lpvBuffer, result, *lpdwSizeofBuffer); return TRUE; } /* Didn't find it */ SetLastError(ERROR_INVALID_INDEX); return FALSE;}BOOL WINAPI WriteClient (HCONN ConnID, LPVOID Buffer, LPDWORD lpwdwBytes, DWORD dwReserved) { request_rec *r = ((isapi_cid *)ConnID)->r; int writ; /* written, actually, but why shouldn't I make up words? */ /* We only support synchronous writing */ if (dwReserved && dwReserved != HSE_IO_SYNC) { ap_log_rerror(APLOG_MARK, APLOG_WARNING, r, "ISAPI asynchronous I/O not supported: %s", r->filename); SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } if ((writ = ap_rwrite(Buffer, *lpwdwBytes, r)) == EOF) { SetLastError(ERROR); /* XXX: Find the right error code */ return FALSE; } *lpwdwBytes = writ; return TRUE;}BOOL WINAPI ReadClient (HCONN ConnID, LPVOID lpvBuffer, LPDWORD lpdwSize) { /* Doesn't need to do anything; we've read all the data already */ return TRUE;}/* XXX: There is an O(n^2) attack possible here. */BOOL WINAPI ServerSupportFunction (HCONN hConn, DWORD dwHSERequest, LPVOID lpvBuffer, LPDWORD lpdwSize, LPDWORD lpdwDataType) { isapi_cid *cid = (isapi_cid *)hConn; request_rec *subreq, *r = cid->r; char *data; switch (dwHSERequest) { case HSE_REQ_SEND_URL_REDIRECT_RESP: /* Set the status to be returned when the HttpExtensionProc() * is done. */ ap_table_set (r->headers_out, "Location", lpvBuffer); cid->status = cid->r->status = cid->ecb->dwHttpStatusCode = REDIRECT; return TRUE; case HSE_REQ_SEND_URL: /* Read any additional input */ if (r->remaining > 0) { char argsbuffer[HUGE_STRING_LEN]; while (ap_get_client_block(r, argsbuffer, HUGE_STRING_LEN)); } /* Reset the method to GET */ r->method = ap_pstrdup(r->pool, "GET"); r->method_number = M_GET; /* Don't let anyone think there's still data */ ap_table_unset(r->headers_in, "Content-Length"); ap_internal_redirect((char *)lpvBuffer, r); return TRUE; case HSE_REQ_SEND_RESPONSE_HEADER: r->status_line = lpvBuffer ? lpvBuffer : ap_pstrdup(r->pool, "200 OK"); sscanf(r->status_line, "%d", &r->status); cid->ecb->dwHttpStatusCode = r->status; /* Now fill in the HTTP headers, and the rest of it. Ick. * lpdwDataType contains a string that has headers (in MIME * format), a blank like, then (possibly) data. We need * to parse it. * * Easy case first: */ if (!lpdwDataType) { ap_send_http_header(r); return TRUE; } /* Make a copy - don't disturb the original */ data = ap_pstrdup(r->pool, (char *)lpdwDataType); /* We *should* break before this while loop ends */ while (*data) { char *value, *lf = strchr(data, '\n'); int p;#ifdef RELAX_HEADER_RULE if (lf) *lf = '\0';#else if (!lf) { /* Huh? Invalid data, I think */ ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "ISA sent invalid headers: %s", r->filename); SetLastError(ERROR); /* XXX: Find right error */ return FALSE; } /* Get rid of \n and \r */ *lf = '\0';#endif p = strlen(data); if (p > 0 && data[p-1] == '\r') data[p-1] = '\0'; /* End of headers */ if (*data == '\0') {#ifdef RELAX_HEADER_RULE if (lf)#endif data = lf + 1; /* Reset data */ break; } if (!(value = strchr(data, ':'))) { SetLastError(ERROR); /* XXX: Find right error */ ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "ISA sent invalid headers", r->filename); return FALSE; } *value++ = '\0'; while (*value && ap_isspace(*value)) ++value; /* Check all the special-case headers. Similar to what * scan_script_header() does (see that function for * more detail) */ if (!strcasecmp(data, "Content-Type")) { char *tmp; /* Nuke trailing whitespace */ char *endp = value + strlen(value) - 1; while (endp > value && ap_isspace(*endp)) *endp-- = '\0'; tmp = ap_pstrdup (r->pool, value); ap_str_tolower(tmp); r->content_type = tmp; } else if (!strcasecmp(data, "Content-Length")) { ap_table_set(r->headers_out, data, value); } else if (!strcasecmp(data, "Transfer-Encoding")) { ap_table_set(r->headers_out, data, value); } else if (!strcasecmp(data, "Set-Cookie")) { ap_table_add(r->err_headers_out, data, value); } else { ap_table_merge(r->err_headers_out, data, value); } /* Reset data */#ifdef RELAX_HEADER_RULE if (!lf) { data += p; break; }#endif data = lf + 1; } /* All the headers should be set now */ ap_send_http_header(r); /* Any data left should now be sent directly */ ap_rputs(data, r); return TRUE; case HSE_REQ_MAP_URL_TO_PATH: /* Map a URL to a filename */ subreq = ap_sub_req_lookup_uri(ap_pstrndup(r->pool, (char *)lpvBuffer, *lpdwSize), r); GetFullPathName(subreq->filename, *lpdwSize - 1, (char *)lpvBuffer, NULL); /* IIS puts a trailing slash on directories, Apache doesn't */ if (S_ISDIR (subreq->finfo.st_mode)) { int l = strlen((char *)lpvBuffer); ((char *)lpvBuffer)[l] = '\\'; ((char *)lpvBuffer)[l + 1] = '\0'; } return TRUE; case HSE_REQ_DONE_WITH_SESSION: /* Do nothing... since we don't support async I/O, they'll * return from HttpExtensionProc soon */ return TRUE; /* We don't support all this async I/O, Microsoft-specific stuff */ case HSE_REQ_IO_COMPLETION: case HSE_REQ_TRANSMIT_FILE: ap_log_rerror(APLOG_MARK, APLOG_WARNING, r, "ISAPI asynchronous I/O not supported: %s", r->filename); default: SetLastError(ERROR_INVALID_PARAMETER); return FALSE; }}handler_rec isapi_handlers[] = {{ "isapi-isa", isapi_handler },{ NULL}};module isapi_module = { STANDARD_MODULE_STUFF, NULL, /* initializer */ NULL, /* create per-dir config */ NULL, /* merge per-dir config */ NULL, /* server config */ NULL, /* merge server config */ NULL, /* command table */ isapi_handlers, /* handlers */ NULL, /* filename translation */ NULL, /* check_user_id */ NULL, /* check auth */ NULL, /* check access */ NULL, /* type_checker */ NULL, /* logger */ NULL /* header parser */};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -