@@ -59,10 +59,6 @@ int Ns_ModuleVersion = 1;
59
59
#define NSG (v ) (ns_context->v)
60
60
#define NSLS_FETCH () ns_globals_struct *ns_context = ts_resource(ns_globals_id)
61
61
62
- /* TSRM id */
63
-
64
- static int ns_globals_id ;
65
-
66
62
/* php_ns_context is per-server (thus only once at all) */
67
63
68
64
typedef struct {
@@ -78,6 +74,16 @@ typedef struct {
78
74
size_t data_avail ;
79
75
} ns_globals_struct ;
80
76
77
+ /* TSRM id */
78
+
79
+ static int ns_globals_id ;
80
+
81
+ /* global context */
82
+
83
+ static php_ns_context * global_context ;
84
+
85
+ static void php_ns_config (php_ns_context * ctx , char global );
86
+
81
87
/*
82
88
* php_ns_sapi_ub_write() writes data to the client connection.
83
89
*/
@@ -412,9 +418,11 @@ php_ns_module_main(NSLS_D SLS_DC)
412
418
file_handle .filename = SG (request_info ).path_translated ;
413
419
file_handle .free_filename = 0 ;
414
420
421
+ php_ns_config (global_context , 0 );
415
422
if (php_request_startup (CLS_C ELS_CC PLS_CC SLS_CC ) == FAILURE ) {
416
423
return NS_ERROR ;
417
424
}
425
+
418
426
php_ns_hash_environment (NSLS_C CLS_CC ELS_CC PLS_CC SLS_CC );
419
427
php_execute_script (& file_handle CLS_CC ELS_CC PLS_CC );
420
428
php_request_shutdown (NULL );
@@ -510,7 +518,7 @@ php_ns_request_handler(void *context, Ns_Conn *conn)
510
518
*/
511
519
512
520
static void
513
- php_ns_config (php_ns_context * ctx )
521
+ php_ns_config (php_ns_context * ctx , char global )
514
522
{
515
523
int i ;
516
524
char * path ;
@@ -519,20 +527,20 @@ php_ns_config(php_ns_context *ctx)
519
527
path = Ns_ConfigGetPath (ctx -> ns_server , ctx -> ns_module , NULL );
520
528
set = Ns_ConfigGetSection (path );
521
529
522
- for (i = 0 ; set && i < Ns_SetSize (set ); i ++ ) {
530
+ for (i = 0 ; set && i < Ns_SetSize (set ); i ++ ) {
523
531
char * key = Ns_SetKey (set , i );
524
532
char * value = Ns_SetValue (set , i );
525
533
526
- if ( !strcasecmp (key , "map" )) {
534
+ if ( global && !strcasecmp (key , "map" )) {
527
535
Ns_Log (Notice , "Registering PHP for \"%s\"" , value );
528
536
Ns_RegisterRequest (ctx -> ns_server , "GET" , value , php_ns_request_handler , NULL , ctx , 0 );
529
537
Ns_RegisterRequest (ctx -> ns_server , "POST" , value , php_ns_request_handler , NULL , ctx , 0 );
530
538
Ns_RegisterRequest (ctx -> ns_server , "HEAD" , value , php_ns_request_handler , NULL , ctx , 0 );
531
- } else if ( !strcasecmp (key , "php_value" )) {
539
+ } else if (! global && !strcasecmp (key , "php_value" )) {
532
540
char * val ;
533
541
534
542
val = strchr (value , ' ' );
535
- if (val ) {
543
+ if (val ) {
536
544
char * new_key ;
537
545
538
546
new_key = estrndup (value , val - value );
@@ -598,7 +606,9 @@ int Ns_ModuleInit(char *server, char *module)
598
606
ctx -> ns_module = strdup (module );
599
607
600
608
/* read the configuration */
601
- php_ns_config (ctx );
609
+ php_ns_config (ctx , 1 );
610
+
611
+ global_context = ctx ;
602
612
603
613
/* register shutdown handler */
604
614
Ns_RegisterServerShutdown (server , php_ns_server_shutdown , ctx );
0 commit comments