[PHP4BETA] CVS update: php4/php4isapi
| From: | zeev | Date: | Sun, 09 May 1999 08:48:06 +0000 |
| Subject: | [PHP4BETA] CVS update: php4/php4isapi | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-723@lists.php.net to get a copy of this message | ||
Date: Sunday May 9, 1999 @ 4:48
Author: zeev
Update of /repository/php4/php4isapi
In directory php:/tmp/cvs-serv25538/php4isapi
Modified Files:
php4isapi.c
Log Message:
* Finalizing the PHP version of SAPI. Support POST and cookies among other things.
* Fully implement ISAPI support - POST and cookies among other things.
* Almost completely rewrote phpinfo(). Allow modules to easily display their
information in phpinfo() without modifying phpinfo() itself (prototype for
the module info function was changed, thus the large amount of updated module
files).
* Initial extended SAPI support for Apache, completely untested.
* CGI now uses SAPI fully as well.
Index: php4/php4isapi/php4isapi.c
diff -u php4/php4isapi/php4isapi.c:1.10 php4/php4isapi/php4isapi.c:1.11
--- php4/php4isapi/php4isapi.c:1.10 Thu May 6 17:58:49 1999
+++ php4/php4isapi/php4isapi.c Sun May 9 04:48:06 1999
@@ -6,9 +6,94 @@
#include "main.h"
#include "SAPI.h"
#include "php_globals.h"
+#include "ext/standard/info.h"
#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION")
+#define ISAPI_SERVER_VAR_BUF_SIZE 1024
+#define ISAPI_POST_DATA_BUF 1024
+static char *isapi_server_variables[] = {
+ "ALL_HTTP",
+ "APPL_MD_PATH",
+ "APPL_PHYSICAL_PATH",
+ "AUTH_PASSWORD",
+ "AUTH_TYPE",
+ "AUTH_USER",
+ "CERT_COOKIE",
+ "CERT_FLAGS",
+ "CERT_ISSUER",
+ "CERT_KEYSIZE",
+ "CERT_SECRETKEYSIZE",
+ "CERT_SERIALNUMBER",
+ "CERT_SERVER_ISSUER",
+ "CERT_SERVER_SUBJECT",
+ "CERT_SUBJECT",
+ "CONTENT_LENGTH",
+ "CONTENT_TYPE",
+ "LOGON_USER",
+ "HTTP_COOKIE",
+ "HTTPS",
+ "HTTPS_KEYSIZE",
+ "HTTPS_SECRETKEYSIZE",
+ "HTTPS_SERVER_ISSUER",
+ "HTTPS_SERVER_SUBJECT",
+ "INSTANCE_ID",
+ "INSTANCE_META_PATH",
+ "PATH_INFO",
+ "PATH_TRANSLATED",
+ "QUERY_STRING",
+ "REMOTE_ADDR",
+ "REMOTE_HOST",
+ "REMOTE_USER",
+ "REQUEST_METHOD",
+ "SCRIPT_NAME",
+ "SERVER_NAME",
+ "SERVER_PORT",
+ "SERVER_PORT_SECURE",
+ "SERVER_PROTOCOL",
+ "SERVER_SOFTWARE",
+ "URL",
+ NULL
+};
+
+
+static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS)
+{
+ char **p = isapi_server_variables;
+ char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
+ DWORD variable_len;
+ LPEXTENSION_CONTROL_BLOCK lpECB;
+ SLS_FETCH();
+
+ lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
+
+ PUTS("<table border=5 width=\"600\">\n");
+ php_info_print_table_header(2, "Server Variable", "Value");
+ while (*p) {
+ variable_len = ISAPI_SERVER_VAR_BUF_SIZE;
+ if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len)
+ && variable_buf[0]) {
+ php_info_print_table_row(2, *p, variable_buf);
+ }
+ p++;
+ }
+
+ PUTS("</table>");
+}
+
+
+static zend_module_entry php_isapi_module = {
+ "ISAPI",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ php_info_isapi,
+ STANDARD_MODULE_PROPERTIES
+};
+
+
static int zend_isapi_ub_write(const char *str, uint str_length)
{
DWORD num_bytes = str_length;
@@ -21,7 +106,7 @@
}
-static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct
*sapi_headers)
+static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct
*sapi_headers SLS_DC)
{
/* This will probably become a bit more complex */
return SAPI_HEADER_ADD;
@@ -53,24 +138,20 @@
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;
- }
+ sapi_header_struct default_content_type = { SAPI_DEFAULT_CONTENT_TYPE,
sizeof(SAPI_DEFAULT_CONTENT_TYPE)-1 };
/* Obtain headers length */
- accumulate_header_length(&SG(sapi_headers).content_type, (void *) &total_length);
+ if (SG(sapi_headers).send_default_content_type) {
+ accumulate_header_length(&default_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);
+ if (SG(sapi_headers).send_default_content_type) {
+ concat_header(&default_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';
@@ -84,18 +165,63 @@
lpECB->ServerSupportFunction(lpECB, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL,
NULL);
efree(combined_headers);
- if (default_content_type) {
- SG(sapi_headers).content_type.header = NULL;
- }
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
+static int php_isapi_startup(sapi_module_struct *sapi_module)
+{
+ if (php_module_startup(sapi_module)==FAILURE
+ || zend_register_module(&php_isapi_module)==FAILURE) {
+ return FAILURE;
+ } else {
+ return SUCCESS;
+ }
+}
+
+
+/* does not support queries over 4GB */
+static char *sapi_isapi_read_post(SLS_D)
+{
+ LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
+ DWORD cbRead, cbSize;
+ char *result;
+
+ result = (char *) emalloc(lpECB->cbTotalBytes+1);
+ memcpy(result, lpECB->lpbData, lpECB->cbAvailable);
+
+ cbRead = lpECB->cbAvailable;
+
+ while (cbRead < lpECB->cbTotalBytes) {
+ cbSize = lpECB->cbTotalBytes - cbRead;
+ if (!lpECB->ReadClient(lpECB->ConnID, result+cbRead, &cbSize) || cbSize==0) {
+ break;
+ }
+ cbRead += cbSize;
+ }
+ result[cbRead] = 0;
+ return result;
+}
+
+
+static char *sapi_isapi_read_cookies(SLS_D)
+{
+ LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context);
+ char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE];
+ DWORD variable_len;
+
+ if (!lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", variable_buf,
&variable_len)) {
+ return NULL;
+ }
+ return estrndup(variable_buf, variable_len);
+}
+
+
static sapi_module_struct sapi_module = {
"PHP Language", /* name */
- php_module_startup, /* startup */
+ php_isapi_startup, /* startup */
php_module_shutdown_wrapper, /* shutdown */
zend_isapi_ub_write, /* unbuffered write */
@@ -105,6 +231,9 @@
sapi_isapi_header_handler, /* header handler */
sapi_isapi_send_headers, /* send headers handler */
NULL, /* send header handler */
+
+ sapi_isapi_read_post, /* read POST data */
+ sapi_isapi_read_cookies /* read Cookies */
};
@@ -143,6 +272,7 @@
static void init_request_info(sapi_globals_struct *sapi_globals, LPEXTENSION_CONTROL_BLOCK lpECB)
{
+ SG(request_info).request_method = lpECB->lpszMethod;
SG(request_info).query_string = lpECB->lpszQueryString;
SG(request_info).path_translated = lpECB->lpszPathTranslated;
SG(request_info).request_uri = lpECB->lpszPathInfo;
@@ -151,6 +281,8 @@
} else {
SG(request_info).headers_only = 0;
}
+ SG(request_info).content_type = lpECB->lpszContentType;
+ SG(request_info).content_length = lpECB->cbTotalBytes;
}
@@ -194,6 +326,9 @@
php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC);
php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
+ if (SG(request_info).cookie_data) {
+ efree(SG(request_info).cookie_data);
+ }
php_request_shutdown(NULL);
return HSE_STATUS_SUCCESS;
--
PHP 4 Beta