|
|
| version 1.8, 2001/03/23 10:14:37 | version 1.9, 2001/03/23 10:27:34 |
|---|---|
| Line 7 | Line 7 |
| #include <httpext.h> | #include <httpext.h> |
| #include "pa_sapi.h" | |
| #include "pa_globals.h" | #include "pa_globals.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_version.h" | #include "pa_version.h" |
| Line 14 | Line 15 |
| #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION") | #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION") |
| //@{ | //@{ |
| /// service func decl | /// SAPI funcs decl |
| struct sapi_func_context { | struct sapi_func_context { |
| LPEXTENSION_CONTROL_BLOCK lpECB; | LPEXTENSION_CONTROL_BLOCK lpECB; |
| String *header; | String *header; |
| DWORD http_response_code; | DWORD http_response_code; |
| }; | }; |
| static const char *sapi_get_env(Pool& pool, const char *name) { | const char *SAPI::get_env(Pool& pool, const char *name) { |
| sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); | sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); |
| char *variable_buf=(char *)pool.malloc(MAX_STRING); | char *variable_buf=(char *)pool.malloc(MAX_STRING); |
| Line 45 static const char *sapi_get_env(Pool& po | Line 45 static const char *sapi_get_env(Pool& po |
| return 0; | return 0; |
| } | } |
| static uint sapi_read_post(Pool& pool, char *buf, uint max_bytes) { | uint SAPI::read_post(Pool& pool, char *buf, uint max_bytes) { |
| sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); | sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); |
| DWORD read_from_buf=0; | DWORD read_from_buf=0; |
| Line 75 static uint sapi_read_post(Pool& pool, c | Line 75 static uint sapi_read_post(Pool& pool, c |
| return total_read; | return total_read; |
| } | } |
| static void sapi_add_header_attribute(Pool& pool, const char *key, const char *value) { | void SAPI::add_header_attribute(Pool& pool, const char *key, const char *value) { |
| sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); | sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); |
| if(strcasecmp(key, "location")==0) | if(strcasecmp(key, "location")==0) |
| Line 92 static void sapi_add_header_attribute(Po | Line 92 static void sapi_add_header_attribute(Po |
| } | } |
| /// @todo intelligent cache-control | /// @todo intelligent cache-control |
| static void sapi_send_header(Pool& pool) { | void SAPI::send_header(Pool& pool) { |
| sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); | sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); |
| ctx.header->APPEND_CONST( | ctx.header->APPEND_CONST( |
| Line 128 static void sapi_send_header(Pool& pool) | Line 128 static void sapi_send_header(Pool& pool) |
| HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); | HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); |
| } | } |
| static void sapi_send_body(Pool& pool, const char *buf, size_t size) { | void SAPI::send_body(Pool& pool, const char *buf, size_t size) { |
| sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); | sapi_func_context& ctx=*static_cast<sapi_func_context *>(pool.context()); |
| DWORD num_bytes=size; | DWORD num_bytes=size; |
| Line 137 static void sapi_send_body(Pool& pool, c | Line 137 static void sapi_send_body(Pool& pool, c |
| } | } |
| //@} | //@} |
| /// SAPI | |
| SAPI sapi={ | |
| sapi_get_env, | |
| sapi_read_post, | |
| sapi_add_header_attribute, | |
| sapi_send_header, | |
| sapi_send_body | |
| }; | |
| // | // |
| static void parser_init() { | static void parser_init() { |
| Line 157 static void parser_init() { | Line 148 static void parser_init() { |
| static Pool pool; // global pool | static Pool pool; // global pool |
| PTRY { | PTRY { |
| // init global variables | // init global variables |
| globals_init(pool); | pa_globals_init(pool); |
| //... | //... |
| } PCATCH(e) { // global problem | } PCATCH(e) { // global problem |
| Line 199 DWORD WINAPI HttpExtensionProc(LPEXTENSI | Line 190 DWORD WINAPI HttpExtensionProc(LPEXTENSI |
| // Request info | // Request info |
| Request::Info request_info; | Request::Info request_info; |
| if(!(request_info.document_root=sapi_get_env(pool, "APPL_PHYSICAL_PATH"))) | if(!(request_info.document_root=SAPI::get_env(pool, "APPL_PHYSICAL_PATH"))) |
| PTHROW(0, 0, | PTHROW(0, 0, |
| 0, | 0, |
| "can not get server variable APPL_PHYSICAL_PATH (error #%lu)", | "can not get server variable APPL_PHYSICAL_PATH (error #%lu)", |
| Line 221 DWORD WINAPI HttpExtensionProc(LPEXTENSI | Line 212 DWORD WINAPI HttpExtensionProc(LPEXTENSI |
| request_info.content_type=lpECB->lpszContentType; | request_info.content_type=lpECB->lpszContentType; |
| request_info.content_length=lpECB->cbTotalBytes; | request_info.content_length=lpECB->cbTotalBytes; |
| request_info.cookie=sapi_get_env(pool, "HTTP_COOKIE"); | request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE"); |
| // prepare to process request | // prepare to process request |
| Request request(pool, | Request request(pool, |
| Line 248 DWORD WINAPI HttpExtensionProc(LPEXTENSI | Line 239 DWORD WINAPI HttpExtensionProc(LPEXTENSI |
| int content_length=strlen(body); | int content_length=strlen(body); |
| // prepare header | // prepare header |
| sapi_add_header_attribute(pool, "content-type", "text/plain"); | SAPI::add_header_attribute(pool, "content-type", "text/plain"); |
| char content_length_cstr[MAX_NUMBER]; | char content_length_cstr[MAX_NUMBER]; |
| snprintf(content_length_cstr, MAX_NUMBER, "%lu", content_length); | snprintf(content_length_cstr, MAX_NUMBER, "%lu", content_length); |
| sapi_add_header_attribute(pool, "content-length", content_length_cstr); | SAPI::add_header_attribute(pool, "content-length", content_length_cstr); |
| // send header | // send header |
| sapi_send_header(pool); | SAPI::send_header(pool); |
| // send body | // send body |
| if(!header_only) | if(!header_only) |
| sapi_send_body(pool, body, content_length); | SAPI::send_body(pool, body, content_length); |
| // unsuccessful finish | // unsuccessful finish |
| _endthread(); | _endthread(); |