summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>1999-09-25 18:51:38 +0000
committerSascha Schumann <sas@php.net>1999-09-25 18:51:38 +0000
commitb5524a0981fae475d45647d55272b8e16b37db76 (patch)
treef2c3d39a19c7d959ff4fd48635bc8a0d2a22aafb
parent104209a32880e4d2403fa01f4e2aea0aa08fb77c (diff)
downloadphp-git-b5524a0981fae475d45647d55272b8e16b37db76.tar.gz
* use faster Ns_ConnWrite()
* access cookies correctly * set HTTP_* variables for script
-rw-r--r--aolserver.c61
1 files changed, 47 insertions, 14 deletions
diff --git a/aolserver.c b/aolserver.c
index ecc9d5e839..e629f6a1ab 100644
--- a/aolserver.c
+++ b/aolserver.c
@@ -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 void php_ns_config(php_ns_context *ctx);
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_sapi_send_headers(sapi_headers_struct *sapi_headers SLS_DC)
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 @@ php_ns_sapi_read_post(char *buf, uint count_bytes SLS_DC)
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 @@ static sapi_module_struct sapi_module = {
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 @@ php_ns_module_main(php_ns_context *ctx SLS_DC)
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);