As a lot of variables which are needed by a lot of PHP scripts which use $_SERVER["..."] are not transferred correctly to the PHP script that runs in iPlanet Webserver (4 or 6). An example are the "Host" and "X-Forwarded" headers. This is so, because the transferred variables are static in the SAPI module.
The new nsapi.c file now transfers _ALL_ variables from rc->rq->headers to php_register_variable("HTTP_"+headername_uppercase, ...).
Also missing variables like "SERVER_SOFTWARE" are added.
A lot of customers complain about memory leaks in this module. I hope they are also fixed by freeing the by nsapi allocated strings (the return value of session_dns and http_uri2url).
The patch should work with Netscape/iPlanet Servers from version 3 on (I used no newer API calls).
If you are interested I could eventually create a patch for supporting the "virtual servers" in SunONE/iPlanet Web Server 6, because some vars only get the default-hostname not the real virtual server name (for example $_SERVER["SERVER_URL"] which is often used in scripts to refer together with $_SERVER["PHP_SELF"]). But this mut be done with #ifdefs because some new functions are in the nsapi since version 6. A good fix would be also to map $_SERVER["SERVER_URL"] to "http://$SERVER["HTTP_HOST"]", because in iPlanet-Servers the Host variable is everytime available (if not in original HTTP-headers it is defined to be the default hostname).
Greetings,
Uwe
-----
Uwe Schindler
Addr 1: Bamberger Str. 24a, D-96049 Bamberg
Addr 2: Drausnickstr. 153, D-91052 Erlangen
http://www.thetaphi.de - http:///www.schindlers-software.de
eMails: [EMAIL PROTECTED] (private); [EMAIL PROTECTED] (company)
Tel./Fax: +49 700 PCLATEIN (+49 700 72528346)
Schindlers Software - Home of Schindlers PC-LATEIN 3.10
DIE Software zum Lateinlernen!
--- nsapi.c.old Sun Oct 27 00:00:36 2002
+++ nsapi.c Sun Feb 2 23:46:05 2003
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 4 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2002 The PHP Group |
+ | Copyright (c) 1997-2003 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -66,6 +66,8 @@
#define NSLS_CC , NSLS_C
#define NSG(v) (request_context->v)
+#define NSHEADER_BUF_SIZE 1024
+
/*
* ZTS needs to be defined for NSAPI to work
*/
@@ -95,17 +97,7 @@
static nsapi_equiv nsapi_headers[] = {
{ "CONTENT_LENGTH", "content-length" },
- { "CONTENT_TYPE", "content-type" },
- { "HTTP_ACCEPT", "accept" },
- { "HTTP_ACCEPT_ENCODING", "accept-encoding" },
- { "HTTP_ACCEPT_LANGUAGE", "accept-language" },
- { "HTTP_ACCEPT_CHARSET", "accept-charset" },
- { "HTTP_AUTHORIZATION", "authorization" },
- { "HTTP_COOKIE", "cookie" },
- { "HTTP_IF_MODIFIED_SINCE", "if-modified-since" },
- { "HTTP_REFERER", "referer" },
- { "HTTP_USER_AGENT", "user-agent" },
- { "HTTP_USER_DEFINED", "user-defined" }
+ { "CONTENT_TYPE", "content-type" }
};
static size_t nsapi_headers_size = sizeof(nsapi_headers)/sizeof(nsapi_headers[0]);
@@ -114,6 +106,7 @@
{ "REQUEST_LINE", "clf-request" },
{ "REQUEST_METHOD", "method" },
{ "SCRIPT_NAME", "uri" },
+ { "PHP_SELF", "uri" },
{ "SERVER_PROTOCOL", "protocol" }
};
static size_t nsapi_reqpb_size = sizeof(nsapi_reqpb)/sizeof(nsapi_reqpb[0]);
@@ -130,7 +123,8 @@
static nsapi_equiv nsapi_client[] = {
{ "HTTPS_KEYSIZE", "keysize" },
{ "HTTPS_SECRETSIZE", "secret-keysize" },
- { "REMOTE_ADDR", "ip" }
+ { "REMOTE_ADDR", "ip" },
+ { "REMOTE_HOST", "ip" }
};
static size_t nsapi_client_size = sizeof(nsapi_client)/sizeof(nsapi_client[0]);
@@ -281,8 +275,10 @@
{
nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
size_t i;
- char *value;
- char buf[128];
+ char *value,*p;
+ char c;
+ char buf[NSHEADER_BUF_SIZE + 1];
+ struct pb_entry *entry;
for (i = 0; i < nsapi_reqpb_size; i++) {
value = pblock_findval(nsapi_reqpb[i].nsapi_eq, rc->rq->reqpb);
@@ -290,7 +286,7 @@
php_register_variable( (char *)nsapi_reqpb[i].env_var, value,
track_vars_array TSRMLS_CC );
}
}
-
+
for (i = 0; i < nsapi_headers_size; i++) {
value = pblock_findval(nsapi_headers[i].nsapi_eq, rc->rq->headers);
if (value) {
@@ -298,6 +294,22 @@
}
}
+ for (i=0; i<rc->rq->headers->hsize; i++) {
+ entry=rc->rq->headers->ht[i];
+ while (entry) {
+ snprintf(buf,NSHEADER_BUF_SIZE,"HTTP_%s",entry->param->name);
+ for(p = buf + 5; (c = *p); p++) {
+ c = toupper(c);
+ if(c < 'A' || c > 'Z') {
+ c = '_';
+ }
+ *p = c;
+ }
+ php_register_variable( buf, entry->param->value, track_vars_array
+TSRMLS_CC );
+ entry=entry->next;
+ }
+ }
+
for (i = 0; i < nsapi_vars_size; i++) {
value = pblock_findval(nsapi_vars[i].nsapi_eq, rc->rq->vars);
if (value) {
@@ -311,35 +323,28 @@
php_register_variable( (char *)nsapi_client[i].env_var, value,
track_vars_array TSRMLS_CC );
}
}
-
+
value = session_dns(rc->sn);
if (value) {
- php_register_variable("REMOTE_HOST", value, track_vars_array TSRMLS_CC
);
+ php_register_variable("REMOTE_HOST", value, track_vars_array TSRMLS_CC );
+ free(value);
}
sprintf(buf, "%d", conf_getglobals()->Vport);
php_register_variable("SERVER_PORT", buf, track_vars_array TSRMLS_CC );
- if ((value = util_hostname())) {
- php_register_variable("SERVER_NAME", value, track_vars_array TSRMLS_CC
);
- }
- php_register_variable("SERVER_URL", http_uri2url("", ""), track_vars_array
TSRMLS_CC );
+ php_register_variable("SERVER_NAME", conf_getglobals()->Vserver_hostname,
+track_vars_array TSRMLS_CC );
+ value=http_uri2url("", "");
+ php_register_variable("SERVER_URL", value, track_vars_array TSRMLS_CC );
+ free(value);
php_register_variable("HTTPS", (security_active ? "ON" : "OFF"),
track_vars_array TSRMLS_CC );
-/* php_register_variable("SERVER_SOFTWARE", MAGNUS_VERSION_STRING,
track_vars_array TSRMLS_CC ); */
-
- /*
- * Special PHP_SELF variable.
- */
- value = pblock_findval("uri", rc->rq->reqpb);
- if ( value != NULL ) {
- php_register_variable("PHP_SELF", value, track_vars_array TSRMLS_CC );
- }
+ php_register_variable("SERVER_SOFTWARE", system_version(), track_vars_array
+TSRMLS_CC );
}
-
+
static void
nsapi_log_message(char *message)
{
TSRMLS_FETCH();
nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
- log_error(LOG_INFORM, "PHP_log_message", rc->sn, rc->rq,
+ log_error(LOG_INFORM, "PHP module", rc->sn, rc->rq,
"%s", message);
}
@@ -452,7 +457,7 @@
nsapi_free(SG(request_info).content_type);
}
-int
+int
nsapi_module_main(NSLS_D TSRMLS_DC)
{
zend_file_handle file_handle;
@@ -481,7 +486,7 @@
return SUCCESS;
}
-void NSAPI_PUBLIC
+void NSAPI_PUBLIC
php4_close(void *vparam)
{
if (nsapi_sapi_module.shutdown) {
@@ -545,7 +550,7 @@
/ <Object ppath="path/to/be/authenticated/by/php/*">
/ AuthTrans fn="php4_auth_trans"
/*********************************************************/
-int NSAPI_PUBLIC
+int NSAPI_PUBLIC
php4_auth_trans(pblock * pb, Session * sn, Request * rq)
{
/*This is a DO NOTHING function that allows authentication information
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php
