[PHP4BETA] CVS update: php4/php4isapi
| From: | andi | Date: | Wed, 05 May 1999 18:25:21 +0000 |
| Subject: | [PHP4BETA] CVS update: php4/php4isapi | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-655@lists.php.net to get a copy of this message | ||
Date: Wednesday May 5, 1999 @ 14:25
Author: andi
Update of /repository/php4/php4isapi
In directory php:/tmp/cvs-serv4330/php4isapi
Modified Files:
php4isapi.c
Log Message:
Added initial headers support in SAPI
*untested*
It definitely broke the thread-safe CGI, it may have broken other stuff as well.
Index: php4/php4isapi/php4isapi.c
diff -u php4/php4isapi/php4isapi.c:1.5 php4/php4isapi/php4isapi.c:1.6
--- php4/php4isapi/php4isapi.c:1.5 Sun May 2 15:55:20 1999
+++ php4/php4isapi/php4isapi.c Wed May 5 14:25:21 1999
@@ -7,7 +7,8 @@
#include "SAPI.h"
#include "php_globals.h"
-
+#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION")
+
static int zend_isapi_ub_write(const char *str, uint str_length)
{
DWORD num_bytes = str_length;
@@ -20,6 +21,78 @@
}
+static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct
*sapi_headers)
+{
+ /* This will probably become a bit more complex */
+ return SAPI_HEADER_ADD;
+}
+
+
+
+static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length)
+{
+ *total_length += sapi_header->header_len+2;
+}
+
+
+static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr)
+{
+ memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len);
+ *combined_headers_ptr += sapi_header->header_len;
+ **combined_headers_ptr = '\r';
+ (*combined_headers_ptr)++;
+ **combined_headers_ptr = '\n';
+ (*combined_headers_ptr)++;
+}
+
+
+static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers SLS_DC)
+{
+ uint total_length = 2; /* account for the trailing \r\n */
+ char *combined_headers, *combined_headers_ptr;
+ LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
+ HSE_SEND_HEADER_EX_INFO header_info;
+ char status_buf[MAX_STATUS_LENGTH];
+ int default_content_type;
+
+ if (SG(sapi_headers).content_type.header) {
+ default_content_type=0;
+ } else {
+ default_content_type=1;
+ SG(sapi_headers).content_type.header = DEFAULT_CONTENT_TYPE;
+ SG(sapi_headers).content_type.header_len = sizeof(DEFAULT_CONTENT_TYPE)-1;
+ }
+
+ /* Obtain headers length */
+ accumulate_header_length(&SG(sapi_headers).content_type, (void *) &total_length);
+ zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *))
accumulate_header_length, (void *) &total_length);
+
+ /* Generate headers */
+ combined_headers = (char *) emalloc(total_length+1);
+ combined_headers_ptr = combined_headers;
+ concat_header(&SG(sapi_headers).content_type, (void *) combined_headers_ptr);
+ zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *))
concat_header, (void *) &combined_headers_ptr);
+ *combined_headers_ptr++ = '\r';
+ *combined_headers_ptr++ = '\n';
+ *combined_headers_ptr = 0;
+
+ header_info.cchStatus = snprintf(status_buf, MAX_STATUS_LENGTH, "%d OK",
SG(sapi_headers).http_response_code);
+ header_info.pszStatus = status_buf;
+ header_info.pszHeader = combined_headers;
+ header_info.cchHeader = total_length;
+
+ lpECB->ServerSupportFunction(lpECB, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL,
NULL);
+
+ efree(combined_headers);
+ if (!default_content_type) {
+ efree(SG(sapi_headers).content_type.header);
+ SG(sapi_headers).content_type.header = NULL;
+ }
+
+ return SAPI_HEADER_SENT_SUCCESSFULLY;
+}
+
+
static sapi_module_struct sapi_module = {
"PHP Language", /* name */
@@ -27,6 +100,10 @@
php_module_shutdown_wrapper, /* shutdown */
zend_isapi_ub_write, /* unbuffered write */
+
+ sapi_isapi_header_handler, /* header handler */
+ sapi_isapi_send_headers, /* send headers handler */
+ NULL, /* send header handler */
};
@@ -68,6 +145,11 @@
SG(request_info).query_string = lpECB->lpszQueryString;
SG(request_info).path_translated = lpECB->lpszPathTranslated;
SG(request_info).request_uri = lpECB->lpszPathInfo;
+ if (!strcmp(lpECB->lpszMethod, "HEAD")) {
+ SG(request_info).headers_only = 1;
+ } else {
+ SG(request_info).headers_only = 0;
+ }
}
@@ -103,6 +185,7 @@
ELS_FETCH();
PLS_FETCH();
+ sapi_activate(SLS_C);
init_request_info(sapi_globals, lpECB);
SG(server_context) = lpECB;
--
PHP 4 Beta