cvs: php4 /sapi/nsapi/ config.m4 nsapi-readme.txt nsapi.c

[email protected] ("Anthony Whitehead") Tue, 30 May 2000 13:20:18 -0000
Newsgroups php.version4
Message-ID <cvsantw959692818@cvsserver>
antw		Tue May 30 06:20:18 2000 EDT

  Modified files:
    /php4/sapi/nsapi	config.m4 nsapi-readme.txt nsapi.c 
  Log:
  Altered NSAPI autoconf to check for location of include files automatically, tested for Netscape 3.x and iPlanet 4.x.
  Added very basic variable support for usefull things such as PHP_SELF. I'll extend this to supply this rest of the variables soon.
  Commited a patch to activate ZTS in the NSAPI module, this patch comes from
  Jayakumar Muthukumarasamy.
  
  
Index: php4/sapi/nsapi/config.m4
diff -u php4/sapi/nsapi/config.m4:1.4 php4/sapi/nsapi/config.m4:1.5
--- php4/sapi/nsapi/config.m4:1.4	Sun Apr 30 10:28:24 2000
+++ php4/sapi/nsapi/config.m4	Tue May 30 06:20:18 2000
@@ -1,4 +1,4 @@
-dnl ## $Id: config.m4,v 1.4 2000/04/30 17:28:24 rasmus Exp $ -*- sh -*-
+dnl ## $Id: config.m4,v 1.5 2000/05/30 13:20:18 antw Exp $ -*- sh -*-
 
 AC_MSG_CHECKING(for NSAPI support)
 AC_ARG_WITH(nsapi,
@@ -13,13 +13,26 @@
   if test ! -d $PHP_NSAPI/bin ; then
     AC_MSG_ERROR(Please specify the path to the root of your Netscape server using --with-nsapi=DIR)
   fi
+  AC_MSG_CHECKING(for NSAPI include files)
+  NSAPI_INCLUDE=""
+  if test -d $PHP_NSAPI/include ; then
+    NSAPI_INCLUDE=$PHP_NSAPI/include
+    AC_MSG_RESULT(Netscape-Enterprise/3.x style)
+  elif test -d $PHP_NSAPI/plugins/include ; then
+    NSAPI_INCLUDE=$PHP_NSAPI/plugins/include
+    AC_MSG_RESULT(iPlanet/4.x style)
+  else
+    AC_MSG_ERROR(Please check you have nsapi.h in either DIR/include or DIR/plugins/include)
+  fi
+  AC_ADD_INCLUDE($NSAPI_INCLUDE)
   PHP_BUILD_THREAD_SAFE
-  AC_ADD_INCLUDE($PHP_NSAPI/include)
   AC_DEFINE(HAVE_NSAPI,1,[Whether you have a Netscape Server])
   PHP_SAPI=nsapi
   PHP_BUILD_SHARED
   INSTALL_IT="\$(INSTALL) -m 0755 $SAPI_SHARED $PHP_NSAPI/bin/"
 fi
+
+INCLUDES="$INCLUDES -I$NSAPI_INCLUDE"
 
 dnl ## Local Variables:
 dnl ## tab-width: 4
Index: php4/sapi/nsapi/nsapi-readme.txt
diff -u php4/sapi/nsapi/nsapi-readme.txt:1.1 php4/sapi/nsapi/nsapi-readme.txt:1.2
--- php4/sapi/nsapi/nsapi-readme.txt:1.1	Sat May  6 16:05:29 2000
+++ php4/sapi/nsapi/nsapi-readme.txt	Tue May 30 06:20:18 2000
@@ -1,14 +1,27 @@
-nsapi configuration file information
+Configuration of your Netscape or iPlanet Web Server for PHP4
+-------------------------------------------------------------
 
+These instructions are targetted at Netscape Enterprise Web Server
+and SUN/Netscape Alliance iPlanet Web Server. On other web servers
+your milage may vary.
+
+Firstly you may need to add some paths to the LD_LIBRARY_PATH
+environment for netscape to find all the shared libs. This is
+best done in the start script for your netscape server.
+Windows users can probably skip this step. The start
+script is located in:
+<path-to-netscape-server>/https-servername/start
+
 netscape config files are located in:
-/netscape/suitespot/httpd-servername/config
+<path-to-netscape-server>/https-servername/config
 
 add the following line to mime.types
 
 type=magnus-internal/x-httpd-php	exts=php
 
 
-Add the following to obj.conf
+Add the following to obj.conf, shlib will vary depending on your OS, for unix it
+will be something like "<path-to-netscape-server>/bin/libphp4.so".
 
 #note place following two lines after mime types init!
 Init fn="load-modules" funcs="php4_init,php4_close,php4_execute,php4_auth_trans" shlib="/php4/nsapiPHP4.dll"
Index: php4/sapi/nsapi/nsapi.c
diff -u php4/sapi/nsapi/nsapi.c:1.3 php4/sapi/nsapi/nsapi.c:1.4
--- php4/sapi/nsapi/nsapi.c:1.3	Thu May 18 08:34:42 2000
+++ php4/sapi/nsapi/nsapi.c	Tue May 30 06:20:18 2000
@@ -20,16 +20,30 @@
  * PHP includes
  */
 #define NSAPI 1
+#define XP_UNIX
 
 #include "php.h"
-
+#include "php_variables.h"
 #include "ext/standard/info.h"
-
 #include "php_ini.h"
 #include "php_globals.h"
 #include "SAPI.h"
 #include "main.h"
 #include "php_version.h"
+#include "TSRM.h"
+#include "ext/standard/php_standard.h"
+
+/*
+ * If neither XP_UNIX not XP_WIN32 is defined, try to guess which one.
+ * Ideally, this should be done by the configure script.
+ */
+#if !defined(XP_UNIX) && !defined(XP_WIN32)
+	#if defined(WIN32)
+		#define XP_WIN32
+	#else
+		#define XP_UNIX
+	#endif
+#endif
 
 /*
  * NSAPI includes
@@ -44,7 +58,7 @@
 
 /* for unix */
 #ifndef WINAPI
-#define WINAPI
+	#define WINAPI
 #endif
 
 /*
@@ -59,15 +73,10 @@
 #define NSG(v)		(request_context->v)
 
 /*
- * Currently, this doesn't work with ZTS.
+ * ZTS needs to be defined for NSAPI to work
  */
-#if defined(ZTS)
-	#define IF_ZTS(a)	a
-	#define IF_NOT_ZTS(a)
-#else
-	#define IF_ZTS(a)
-	#define IF_NOT_ZTS(a)	a
-	static CRITICAL php_mutex;
+#if !defined(ZTS)
+	#error "NSAPI module needs ZTS to be defined"
 #endif
 
 /*
@@ -259,6 +268,31 @@
 	return cookie_string;
 }
 
+static void
+sapi_nsapi_register_server_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
+{
+	nsapi_request_context *rc = (nsapi_request_context *)SG(server_context);
+	size_t i;
+	char *value = NULL;
+	char buf[128];
+
+	*buf = 0;
+	for (i = 0; i < nsapi_reqpb_size; i++) {
+		if ((value = pblock_findval(nsapi_reqpb[i].nsapi_eq, rc->rq->reqpb)) == NULL) {
+			value = buf;
+		}
+		php_register_variable( (char *)nsapi_reqpb[i].env_var, value, track_vars_array ELS_CC PLS_CC );
+	}
+
+	/*
+	 * Special PHP_SELF variable.
+	 */
+	value = pblock_findval( "uri", rc->rq->reqpb );
+	if( value != NULL ) {
+		php_register_variable( "PHP_SELF", value, track_vars_array ELS_CC PLS_CC );
+	}
+}
+
 static sapi_module_struct sapi_module = {
 	"NSAPI",				/* name */
 
@@ -282,7 +316,7 @@
 	sapi_nsapi_read_post,			/* read POST data */
 	sapi_nsapi_read_cookies,		/* read Cookies */
 
-	NULL,					/* register server variables */
+	sapi_nsapi_register_server_variables,	/* register server variables */
 	NULL,					/* Log message */
 
 	NULL,					/* Block interruptions */
@@ -391,7 +425,7 @@
 	if (uri != NULL)
 		path_translated = request_translate_uri(uri, NSG(sn));
 
-#if 0
+#if defined(NSAPI_DEBUG)
 	log_error(LOG_INFORM, "nsapi_request_ctor", NSG(sn), NSG(rq),
 		"query_string = %s, "
 		"uri = %s, "
@@ -445,7 +479,7 @@
 	file_handle.filename = SG(request_info).path_translated;
 	file_handle.free_filename = 0;
 
-#if 0
+#if defined(NSAPI_DEBUG)
 	log_error(LOG_INFORM, "nsapi_module_main", NSG(sn), NSG(rq),
 		"Parsing [%s]", SG(request_info).path_translated);
 #endif
@@ -468,32 +502,20 @@
 	if (sapi_module.shutdown) {
 		sapi_module.shutdown(&sapi_module);
 	}
-	IF_ZTS(
-		tsrm_shutdown();
-	)
+	tsrm_shutdown();
 }
 
 int WINAPI
 php4_init(pblock *pb, Session *sn, Request *rq)
 {
-	PLS_FETCH();
+	php_core_globals *core_globals;
 
-	/*
-	 * TSRM has not been tested.
-	 */
-	IF_ZTS(
-		tsrm_startup(1, 1, 0);
-	)
+	tsrm_startup(1, 1, 0);
+	core_globals = ts_resource(core_globals_id);
 
 	sapi_startup(&sapi_module);
 	sapi_module.startup(&sapi_module);
 
-	PG(expose_php) = 0;
-
-	IF_NOT_ZTS(
-		php_mutex = crit_init();
-	)
-
 	log_error(LOG_INFORM, "php4_init", sn, rq, "Initialized PHP Module\n");
 	return REQ_PROCEED;
 }
@@ -511,28 +533,11 @@
 	request_context->sn = sn;
 	request_context->rq = rq;
 
-	/*
-	 * Single thread the execution, if ZTS is not enabled. Need to
-	 * understand the behavior of Netscape server when the client
-	 * cancels a request when it is in progress. This could cause
-	 * a deadlock if the thread handling the specific client is not
-	 * cancelled because the php_mutex will likely remain locked
-	 * until the request that was cancelled completes. The behavior
-	 * is also going to be platform specific.
-	 */
-	IF_NOT_ZTS(
-		crit_enter(php_mutex);
-	)
-
 	SG(server_context) = request_context;
 
 	nsapi_request_ctor(NSLS_C SLS_CC);
 	retval = nsapi_module_main(NSLS_C SLS_CC);
 	nsapi_request_dtor(NSLS_C SLS_CC);
-
-	IF_NOT_ZTS(
-		crit_exit(php_mutex);
-	)
 
 	free(request_context);