cvs: /php4 aolserver.c
| From: | Sascha Schumann | Date: | Sat, 25 Sep 1999 18:52:08 +0000 |
| Subject: | cvs: /php4 aolserver.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-4916@lists.php.net to get a copy of this message | ||
sas Sat Sep 25 14:52:08 1999 EDT
Modified files:
/php4 aolserver.c
Log:
* use faster Ns_ConnWrite()
* access cookies correctly
* set HTTP_* variables for script
Index: php4/aolserver.c
diff -u php4/aolserver.c:1.5 php4/aolserver.c:1.6
--- php4/aolserver.c:1.5 Sat Sep 25 12:51:18 1999
+++ php4/aolserver.c Sat Sep 25 14:51:38 1999
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: aolserver.c,v 1.5 1999/09/25 16:51:18 sas Exp $ */
+/* $Id: aolserver.c,v 1.6 1999/09/25 18:51:38 sas Exp $ */
/* conflict between PHP and aolserver */
#define Debug php_Debug
@@ -37,11 +37,14 @@
int Ns_ModuleVersion = 1;
typedef struct {
+ /* per server */
sapi_module_struct *sapi_module;
- Ns_DString content_type;
- Ns_Conn *conn;
char *ns_server;
char *ns_module;
+
+ /* per request */
+ Ns_Conn *conn;
+ Ns_DString content_type;
} php_ns_context;
static void php_ns_config(php_ns_context *ctx);
@@ -49,18 +52,15 @@
static int
php_ns_sapi_ub_write(const char *str, uint str_length)
{
- Ns_DString dstr;
+ int sent_bytes;
php_ns_context *ctx;
SLS_FETCH();
ctx = (php_ns_context *) SG(server_context);
- Ns_DStringInit(&dstr);
- Ns_DStringNAppend(&dstr, (char *) str, str_length);
- Ns_ConnSendDString(ctx->conn, &dstr);
- Ns_DStringFree(&dstr);
+ sent_bytes = Ns_ConnWrite(ctx->conn, (void *) str, str_length);
- return str_length;
+ return sent_bytes;
}
static int
@@ -99,6 +99,9 @@
php_ns_context *ctx;
ctx = (php_ns_context *) SG(server_context);
+ if(SG(sapi_headers).send_default_content_type) {
+ Ns_ConnSetRequiredHeaders(ctx->conn, "text/html", 0);
+ }
Ns_ConnFlushHeaders(ctx->conn, SG(sapi_headers).http_response_code);
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
@@ -121,14 +124,13 @@
static char *
php_ns_sapi_read_cookies(SLS_D)
{
- Ns_Set *headers;
- char *http_cookie;
+ int i;
+ char *http_cookie = NULL;
php_ns_context *ctx = (php_ns_context *) SG(server_context);
-
- headers = Ns_ConnHeaders(conn);
- if(headers) {
- http_cookie = Ns_SetGet(headers, "HTTP_COOKIE");
+ i = Ns_SetFind(ctx->conn->headers, "cookie");
+ if(i != -1) {
+ http_cookie = Ns_SetValue(ctx->conn->headers, i);
}
return http_cookie;
@@ -154,6 +156,36 @@
STANDARD_SAPI_MODULE_PROPERTIES
};
+static void
+php_ns_hash_environment(php_ns_context *ctx CLS_DC ELS_DC PLS_DC SLS_DC)
+{
+ int i;
+
+ for(i = 0; i < Ns_SetSize(ctx->conn->headers); i++) {
+ char *key = Ns_SetKey(ctx->conn->headers, i);
+ char *value = Ns_SetValue(ctx->conn->headers, i);
+ char *p;
+ zval *pval;
+ char buf[512];
+ int buf_len;
+
+ buf_len = snprintf(buf, 511, "HTTP_%s", key);
+ for(p = buf; *p; p++) {
+ *p = toupper(*p);
+ if(*p < 'A' || *p > 'Z') {
+ *p = '_';
+ }
+ }
+
+ MAKE_STD_ZVAL(pval);
+ pval->type = IS_STRING;
+ pval->value.str.len = strlen(value);
+ pval->value.str.val = estrndup(value, pval->value.str.len);
+
+ zend_hash_update(&EG(symbol_table), buf, buf_len + 1, &pval, sizeof(zval *), NULL);
+ }
+}
+
static int
php_ns_module_main(php_ns_context *ctx SLS_DC)
{
@@ -166,6 +198,7 @@
file_handle.filename = SG(request_info).path_translated;
php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC);
+ php_ns_hash_environment(ctx CLS_CC ELS_CC PLS_CC SLS_CC);
php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
php_request_shutdown(NULL);