You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tcl.apache.org by mx...@apache.org on 2024/04/30 14:31:50 UTC

(tcl-rivet) branch quattuor updated (df3ed13 -> f0b8710)

This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a change to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git


    from df3ed13  Converted CONST84 to CONST86
     new 2596517  fixing some comments
     new a12c8ac  fix conflict in Changelog
     new 644270c  handling length of data in POST requests
     new 26a0202  test scripts improved, new test for ::rivet::raw_post
     new 7db3813  Handling the server_rec pointer in the module globals for the benefit of logging into the specific virtual host log file during child init stage
     new f0b8710  merging from master

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ChangeLog                                | 33 +++++++++++
 rivet/init.tcl.in                        |  4 +-
 rivet/packages/session/session-class.tcl |  9 +--
 rivet/rivet-tcl/parray.tcl               | 14 ++---
 src/mod_rivet_ng/TclWebapache.c          |  4 +-
 src/mod_rivet_ng/mod_rivet.c             | 32 +++++------
 src/mod_rivet_ng/mod_rivet.h             |  1 +
 src/mod_rivet_ng/mod_rivet_common.c      |  8 +--
 src/mod_rivet_ng/mod_rivet_generator.c   |  2 -
 src/mod_rivet_ng/rivetCore.c             | 21 +++++--
 src/mod_rivet_ng/rivet_types.h           |  3 +-
 src/mod_rivet_ng/worker_prefork_common.c | 97 +++++++++++++++++++++++++-------
 src/request/apache_request.c             | 15 ++++-
 src/request/apache_request.h             |  2 +-
 tests/apachetest/apachetest.tcl          | 37 +++++++++---
 tests/channel.test                       | 43 +++++++-------
 tests/post.rvt                           |  7 ++-
 tests/post.test                          |  9 +++
 tests/rivet.test                         | 18 +++---
 19 files changed, 251 insertions(+), 108 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


(tcl-rivet) 01/06: fixing some comments

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit 2596517147631921bc3e207595a4e194d130ab59
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Tue Jan 10 10:13:39 2023 +0100

    fixing some comments
---
 ChangeLog                                | 3 +++
 src/mod_rivet_ng/mod_rivet.c             | 9 ++++-----
 src/mod_rivet_ng/worker_prefork_common.c | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e058337..0f3f17a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2023-01-10 Massimo Manghi <mx...@apache.org>
+	* src/mod_rivet_ng/mod_rivet.c: fixing some
+ comments
 2023-01-09 Massimo Manghi <mx...@apache.org>
 	* src/mod_rivet_ng/TclWebaapache.c: replaced CONST84 with CONST86 which is supported by Tcl 8.7
 	* src/mod_rivet_ng/rivet[Channel|Core].c: 
diff --git a/src/mod_rivet_ng/mod_rivet.c b/src/mod_rivet_ng/mod_rivet.c
index 088d1f2..37549ff 100644
--- a/src/mod_rivet_ng/mod_rivet.c
+++ b/src/mod_rivet_ng/mod_rivet.c
@@ -324,7 +324,7 @@ Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, ser
             Tcl_Obj*    server_init;
 
             /* either we want separate virtual interps or we haven't
-             * created an interpreter so far we create one
+             * created an interpreter so far, thus we create one
              */
 
             if ((interp_obj == NULL) || module_globals->separate_virtual_interps)
@@ -514,9 +514,9 @@ static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
     //Tcl_InitNotifier();
 #endif
 
-    /* We can rely on the existence of module_globals only we are
+    /* We can rely on the existence of module_globals only when we are
      * running the prefork MPM, otherwise the pointer is NULL and
-     * the structure need to be filled
+     * the structure needs to be filled
      */
 
     if (module_globals == NULL)
@@ -533,8 +533,7 @@ static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
     apr_thread_mutex_create(&module_globals->pool_mutex, APR_THREAD_MUTEX_UNNESTED, pChild);
 
     /* Once we have established a pool with the same lifetime of the child process we
-     * process all the configured server records assigning an integer as unique key
-     * to each of them
+     * process all the configured server records assigning to each record a unique integer key
      */
 
     root_server_conf = RIVET_SERVER_CONF(server->module_config);
diff --git a/src/mod_rivet_ng/worker_prefork_common.c b/src/mod_rivet_ng/worker_prefork_common.c
index 18f7e5c..48c4b36 100644
--- a/src/mod_rivet_ng/worker_prefork_common.c
+++ b/src/mod_rivet_ng/worker_prefork_common.c
@@ -178,7 +178,7 @@ void Rivet_ProcessorCleanup (rivet_thread_private* private)
      * Rivet channel is set as stdout channel of Tcl and as such is treated
      * by Tcl_UnregisterChannel is a special way. When its refCount reaches 1
      * the channel is released immediately by forcing the refCount to 0
-     * (see Tcl source code: generic/TclIO.c). Unregistering for each interpreter
+     * (see Tcl source code: generic/TclIO.c). Unregistering each interpreter
      * causes the process to segfault at least for certain Tcl versions.
      * In order to avoid the crash the channel is unset as stdout
      */


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


(tcl-rivet) 04/06: test scripts improved, new test for ::rivet::raw_post

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit 26a0202a1f90f336306f767cb22d4497b5d47664
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Thu May 4 08:46:28 2023 +0200

    test scripts improved, new test for ::rivet::raw_post
---
 ChangeLog                       |  9 +++++++++
 tests/apachetest/apachetest.tcl | 37 ++++++++++++++++++++++++++++---------
 tests/post.rvt                  |  7 +++++--
 tests/post.test                 |  9 +++++++++
 tests/rivet.test                | 18 +++++++++++-------
 5 files changed, 62 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f0f648d..2b82f58 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-05-14 Massimo Manghi <mx...@apache.org>
+	* tests/rivet.test: more contributions provided by Scott Pitcher <sc...@svptechnicalservices.com.au>)
+	* tests/apachetest/apachetest.tcl: More improvements to the test script. Now
+	handling also Apache directive IncludeOptional and enabling execution control 
+	through environment variables
+	* tests/post.rvt:
+	* tests/post.test: add a test for ::rivet::raw_post
+
+	* 
 2023-04-11 Massimo Manghi <mx...@apache.org>
 	* src/mod_rivet_ng/TclWebapache.c:
 	* src/mod_rivet_ng/rivetCore.c:
diff --git a/tests/apachetest/apachetest.tcl b/tests/apachetest/apachetest.tcl
index d9658c8..3549b23 100644
--- a/tests/apachetest/apachetest.tcl
+++ b/tests/apachetest/apachetest.tcl
@@ -70,6 +70,12 @@ namespace eval apachetest {
 	variable httpd_version  $::httpd_version
     # this file should be in the same directory this script is.
     variable templatefile [file join [file dirname [info script]] template.conf.2.tcl]
+
+    variable httpd_root
+    set httpd_root ""
+    variable server_config_file
+    set server_config_file ""
+
 }
 
 # apachetest::need_modules --
@@ -271,17 +277,21 @@ proc apachetest::gethttpdconf { binname } {
 #	Text of configuration files.
 
 proc apachetest::getallincludes { conffile } {
+    variable httpd_root
     if [file exists $conffile] {
-	    set fl [open $conffile r]
-	    set data [read $fl]
-	    close $fl
-
-	    set newdata {}
-	    foreach line [split $data \n] {
-		# Look for Include lines.
-            if { [regexp -line {^[^\#]*Include +(.*)} $line match file] } {
+	set fl [open $conffile r]
+	set data [read $fl]
+	close $fl
+
+	set newdata {}
+	foreach line [split $data \n] {
+	    # Look for Include lines.
+            if { [regexp -line {^[^\#]*Include(?:|Optional) +(.*)} $line match file]} {
                 puts "including files from $file"
                 set file [string trim $file]
+                if {[string index $file 0] != "/"} {
+		    set file [file join $httpd_root $file]
+                }
 
                 # Include directives accept as argument a file, a directory
                 # or a glob-style file matching pattern. Patterns usually match
@@ -338,11 +348,15 @@ proc apachetest::getallincludes { conffile } {
 
 
 proc apachetest::getloadmodules { conffile needtoget } {
+    variable httpd_root
     puts "checking $conffile "
     set confdata [getallincludes $conffile]
     set loadline [list]
     regexp -line {^[^#]*(ServerRoot[\s]?[\"]?)([^\"]+)()([\"]?)} $confdata \
-    match sub1 server_root_path sub2 
+	match sub1 server_root_path sub2
+    if {![info exists server_root_path]} {
+	set server_root_path $httpd_root
+    }
     foreach mod $needtoget {
 
     	# Look for LoadModule lines.
@@ -371,9 +385,14 @@ proc apachetest::getloadmodules { conffile needtoget } {
 # Compare what's compiled in with what we need.
 
 proc apachetest::determinemodules { binname } {
+    variable server_config_file
+    variable httpd_root
     variable module_assoc
+
     set compiledin [lsort [getcompiledin $binname]]
     set conffile [gethttpdconf $binname]
+    set server_config_file $conffile
+    set httpd_root [file dirname $conffile]
 
     foreach {n k} [array get module_assoc] {
         lappend needed $k
diff --git a/tests/post.rvt b/tests/post.rvt
index 1257750..a887723 100644
--- a/tests/post.rvt
+++ b/tests/post.rvt
@@ -1,5 +1,5 @@
 <?
-
+::rivet::load_env env
 if { [ ::rivet::var number ] > 0 } {
     # get/post variables 1.1
     if { [ ::rivet::var exists foobar ] } {
@@ -16,6 +16,9 @@ if { [ ::rivet::var number ] > 0 } {
     if { [::rivet::var exists lstvar2] } {
         puts "\[::rivet::var list lstvar2\] = [::rivet::var list lstvar2]\n"
     }
-}
 
+} elseif {[string match "POST" $env(REQUEST_METHOD)]} {
+    # Return the raw body encoded as ascii
+    puts -nonewline "\[::rivet::raw_post\] = [binary encode hex [::rivet::raw_post]]"
+}
 ?>
diff --git a/tests/post.test b/tests/post.test
index 8fed8dc..bb7a737 100644
--- a/tests/post.test
+++ b/tests/post.test
@@ -60,3 +60,12 @@ var_post = postarg1 val1 postarg2 val2}
     set match [::http::data $page]
     set match
 } {OK}
+
+::tcltest::test postvariables-6.1 {::rivet::raw_post} {
+    set payload "\x00\x00\x00\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39"
+    set page [::http::geturl "${urlbase}post.rvt" \
+			    -query $payload \
+			    -type application/octet-stream]
+    regexp -line {^\[::rivet::raw_post\] = 00000030313233343536373839$} [ ::http::data $page ] match
+    set match
+} {[::rivet::raw_post] = 00000030313233343536373839}
diff --git a/tests/rivet.test b/tests/rivet.test
index 139a625..dbda8b8 100755
--- a/tests/rivet.test
+++ b/tests/rivet.test
@@ -30,19 +30,23 @@ set urlbase "http://localhost:8081/"
 
 # Use this to start and stop the server:
 
-set TestList {rivetlib.test shorthand.test headers.test \
-              cookies.test get.test post.test tclfile.test \
-              env.test hello.test include.test binary.test \
-              parse.test upload.test makeurl.test commands.test}
+if {[info exists ::env(TestList)]} {
+    set TestList $::env(TestList)
+} else {
+    set TestList {rivetlib.test shorthand.test headers.test \
+		cookies.test get.test post.test tclfile.test \
+		env.test hello.test include.test binary.test \
+		parse.test upload.test makeurl.test commands.test}
+}
 
 # Test stanzas are created by giving the test a name and a
 # description. The code is then executed, and the results compared
 # with the desired result, which is placed after the block of code.
 # See man tcltest for more information.
 
-set testgroup1 1
-set testgroup2 1
-set testgroup3 1
+set testgroup1 [expr [info exists ::env(testgroup1)] ? $::env(testgroup1) : 1]
+set testgroup2 [expr [info exists ::env(testgroup2)] ? $::env(testgroup2) : 1]
+set testgroup3 [expr [info exists ::env(testgroup3)] ? $::env(testgroup3) : 1]
 
 # Run all tests against one server process.
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


(tcl-rivet) 05/06: Handling the server_rec pointer in the module globals for the benefit of logging into the specific virtual host log file during child init stage

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit 7db381382295ce3736285e9f8ba604ed59a679e7
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Thu May 18 17:12:24 2023 +0200

    Handling the server_rec pointer in the module globals for the benefit of logging into the specific virtual host log file during child init stage
---
 ChangeLog                                | 12 +++-
 src/mod_rivet_ng/mod_rivet.c             | 12 ++--
 src/mod_rivet_ng/mod_rivet.h             |  1 +
 src/mod_rivet_ng/mod_rivet_common.c      |  8 +--
 src/mod_rivet_ng/rivetCore.c             | 14 ++++-
 src/mod_rivet_ng/worker_prefork_common.c | 95 ++++++++++++++++++++++++++------
 6 files changed, 111 insertions(+), 31 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2b82f58..91f4d2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,13 @@
-2023-05-14 Massimo Manghi <mx...@apache.org>
+2023-05-18 Massimo Manghi <mx...@apache.org>
+	* src/mod_rivet_ng/mod_rivet.c:
+	* src/mod_rivet_ng/mod_rivet.h:
+	* src/mod_rivet_ng/mod_rivet_common.c:
+	* src/mod_rivet_ng/rivetCore.c:
+	* src/mod_rivet_ng/worker_prefork_common.c: now storing the server record in the intepreter globals
+	to be used by Rivet_LogErrorCmd instead of module_globals->server when threads private data are
+	not available (like when ChildInitScript is executed)
+
+2023-05-04 Massimo Manghi <mx...@apache.org>
 	* tests/rivet.test: more contributions provided by Scott Pitcher <sc...@svptechnicalservices.com.au>)
 	* tests/apachetest/apachetest.tcl: More improvements to the test script. Now
 	handling also Apache directive IncludeOptional and enabling execution control 
@@ -6,7 +15,6 @@
 	* tests/post.rvt:
 	* tests/post.test: add a test for ::rivet::raw_post
 
-	* 
 2023-04-11 Massimo Manghi <mx...@apache.org>
 	* src/mod_rivet_ng/TclWebapache.c:
 	* src/mod_rivet_ng/rivetCore.c:
diff --git a/src/mod_rivet_ng/mod_rivet.c b/src/mod_rivet_ng/mod_rivet.c
index 37549ff..c63efda 100644
--- a/src/mod_rivet_ng/mod_rivet.c
+++ b/src/mod_rivet_ng/mod_rivet.c
@@ -289,15 +289,19 @@ Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, ser
     {
         char* parent_pid_var = NULL;
 
+        /* if the environment variable AP_PARENT_PID is set
+         * we know we are in a child process of the winnt MPM
+         */
+        
         apr_env_get(&parent_pid_var,"AP_PARENT_PID",pTemp);
         if (parent_pid_var != NULL)
         {
-            ap_log_error(APLOG_MARK,APLOG_DEBUG,0,server,
-                        "AP_PARENT_PID found: not running the Tcl server script in winnt MPM child process");
+            ap_log_perror(APLOG_MARK,APLOG_INFO,0,pPool,
+                    "AP_PARENT_PID found: not running the Tcl server script in winnt MPM child process");
             return OK;
         } else {
-            ap_log_error(APLOG_MARK,APLOG_DEBUG,0,server,
-                        "AP_PARENT_PID undefined, we proceed with server initialization");
+            ap_log_perror(APLOG_MARK,APLOG_INFO,0,pPool,
+                     "AP_PARENT_PID undefined, we proceed with server initialization");
         }
     }
 
diff --git a/src/mod_rivet_ng/mod_rivet.h b/src/mod_rivet_ng/mod_rivet.h
index c107690..8239c31 100644
--- a/src/mod_rivet_ng/mod_rivet.h
+++ b/src/mod_rivet_ng/mod_rivet.h
@@ -253,6 +253,7 @@ typedef struct _thread_worker_private {
 
 typedef struct _rivet_interp_globals {
     Tcl_Namespace*      rivet_ns;           /* Rivet commands namespace             */
+    server_rec*         server;             /* Virtual host server rec              */
 } rivet_interp_globals;
 
 rivet_server_conf *Rivet_GetConf(request_rec *r);
diff --git a/src/mod_rivet_ng/mod_rivet_common.c b/src/mod_rivet_ng/mod_rivet_common.c
index 35fe13b..2103849 100644
--- a/src/mod_rivet_ng/mod_rivet_common.c
+++ b/src/mod_rivet_ng/mod_rivet_common.c
@@ -250,7 +250,7 @@ void Rivet_ReleasePerDirScripts(rivet_thread_interp* rivet_interp)
  *
  * Rivet_PerInterpInit --
  *
- *  Do the initialization that needs to happen to every interpreter.
+ *  Do the interpreter environment creation and initialization.
  *
  * Results:
  *  None.
@@ -283,11 +283,11 @@ void Rivet_PerInterpInit(rivet_thread_interp* interp_obj,
     //Tcl_SetAssocData (interp,"rivet",NULL,globals);
 
     /*
-     * the ::rivet namespace is the only information still stored
-     * in the interpreter global data
+     * we store in the globals some information relevant to
+     * the embedded interpreter work
      */
 
-    /* Rivet commands namespace is created */
+    /* the ::rivet namespace is created */
 
     interp_obj->rivet_ns =
         Tcl_CreateNamespace (interp,RIVET_NS,private,(Tcl_NamespaceDeleteProc *)NULL);
diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c
index c32ed15..82fba23 100644
--- a/src/mod_rivet_ng/rivetCore.c
+++ b/src/mod_rivet_ng/rivetCore.c
@@ -1770,7 +1770,7 @@ TCL_CMD_HEADER( Rivet_InspectCmd )
  *-----------------------------------------------------------------------------
  */
 
-TCL_CMD_HEADER( Rivet_LogErrorCmd )
+TCL_CMD_HEADER(Rivet_LogErrorCmd)
 {
     char *message = NULL;
 
@@ -1855,9 +1855,17 @@ TCL_CMD_HEADER( Rivet_LogErrorCmd )
     /* if we are serving a page, we know our server,
      * else send null for server
      */
-    serverRec = ((private == NULL) || (private->r == NULL)) ? module_globals->server : private->r->server;
 
-    ap_log_error (APLOG_MARK, apLogLevel, 0, serverRec, "%s", message);
+    if ((private == NULL) || (private->r == NULL))
+    {
+        rivet_interp_globals* globals = Tcl_GetAssocData(interp, "rivet", NULL);
+        serverRec = globals->server;
+    }
+    else
+    {
+        serverRec = private->r->server;
+    }
+    ap_log_error (APLOG_MARK,apLogLevel,0,serverRec,"%s",message);
     return TCL_OK;
 }
 
diff --git a/src/mod_rivet_ng/worker_prefork_common.c b/src/mod_rivet_ng/worker_prefork_common.c
index 48c4b36..ec92c33 100644
--- a/src/mod_rivet_ng/worker_prefork_common.c
+++ b/src/mod_rivet_ng/worker_prefork_common.c
@@ -40,6 +40,34 @@ extern DLLIMPORT apr_threadkey_t*   rivet_thread_key;
 extern DLLIMPORT module             rivet_module;
 
 /* -- Rivet_SetupInterps
+ *
+ *
+ */
+
+rivet_thread_interp*
+Rivet_DuplicateVHostInterp(apr_pool_t* pool, rivet_thread_interp* source_obj)
+{
+    rivet_thread_interp* interp_obj = apr_pcalloc(pool,sizeof(rivet_thread_interp));
+
+    interp_obj->interp      = source_obj->interp;
+    interp_obj->channel     = source_obj->channel;
+    interp_obj->cache_free  = source_obj->cache_free;
+    interp_obj->cache_size  = source_obj->cache_size;
+
+    /* An intepreter must have its own cache */
+
+    if (interp_obj->cache_size) {
+        RivetCache_Create(source_obj);
+    }
+
+    interp_obj->pool            = source_obj->pool;
+    interp_obj->scripts         = (running_scripts *) apr_pcalloc(pool,sizeof(running_scripts));
+    interp_obj->per_dir_scripts = apr_hash_make(pool);
+    interp_obj->flags           = source_obj->flags;
+    return interp_obj;
+}
+
+/* -- Rivet_VirtualHostsInterps
  *
  * The server_rec chain is walked through and server configurations are read to
  * set up the thread private configuration and interpreters database
@@ -60,7 +88,7 @@ extern DLLIMPORT module             rivet_module;
 
 rivet_thread_private* Rivet_SetupInterps (rivet_thread_private* private)
 {
-    server_rec*             s;
+    server_rec*             vhost_server;
     server_rec*             root_server = module_globals->server;
     rivet_server_conf*      root_server_conf;
     void*                   parentfunction;     /* this is topmost initialization script */
@@ -77,15 +105,15 @@ rivet_thread_private* Rivet_SetupInterps (rivet_thread_private* private)
 
     parentfunction = root_server_conf->rivet_child_init_script;
 
-    for (s = root_server; s != NULL; s = s->next)
+    for (vhost_server = root_server; vhost_server != NULL; vhost_server = vhost_server->next)
     {
         rivet_server_conf*      rsc;
         rivet_thread_interp*    interp_obj;
 
-        rsc = RIVET_SERVER_CONF(s->module_config);
+        rsc = RIVET_SERVER_CONF(vhost_server->module_config);
         interp_obj = private->ext->interps[rsc->idx];
 
-        if ((s != root_server) &&
+        if ((vhost_server != root_server) &&
             module_globals->separate_channels &&
             module_globals->separate_virtual_interps)
         {
@@ -97,42 +125,73 @@ rivet_thread_private* Rivet_SetupInterps (rivet_thread_private* private)
 
         /* interpreter base running scripts definition and initialization */
 
-        interp_obj->scripts = Rivet_RunningScripts(private->pool,interp_obj->scripts,rsc);
-
-        private->ext->interps[rsc->idx] = interp_obj;
+        interp_obj->scripts = Rivet_RunningScripts (private->pool,interp_obj->scripts,rsc);
+        RIVET_POKE_INTERP(private,rsc,interp_obj);
 
         /* Basic Rivet packages and libraries are loaded here */
 
-        Rivet_PerInterpInit(interp_obj, private, s, private->pool);
+        if ((interp_obj->flags & RIVET_INTERP_INITIALIZED) == 0)
+        {
+            Rivet_PerInterpInit(interp_obj,private,vhost_server,private->pool);
+        }
 
         /* It seems that allocating from a shared APR memory pool is not thread safe,
          * but it's not very well documented actually. In any case we protect this
          * memory allocation with a mutex
          */
 
+        /*  this stuff must be allocated from the module global pool which
+         *  has the child process' same lifespan
+         */
+
+        apr_thread_mutex_lock(module_globals->pool_mutex);
+        rsc->server_name = (char*) apr_pstrdup (private->pool,vhost_server->server_hostname);
+        apr_thread_mutex_unlock(module_globals->pool_mutex);
+
         /* when configured a child init script gets evaluated */
 
         function = rsc->rivet_child_init_script;
         if (function &&
-            (s == root_server || module_globals->separate_virtual_interps || function != parentfunction))
+            (vhost_server == root_server || module_globals->separate_virtual_interps || function != parentfunction))
         {
             char*       errmsg = MODNAME ": Error in Child init script: %s";
-            Tcl_Interp* interp = interp_obj->interp;
             Tcl_Obj*    tcl_child_init = Tcl_NewStringObj(function,-1);
+            rivet_interp_globals* globals = NULL;
 
             Tcl_IncrRefCount(tcl_child_init);
-            Tcl_Preserve (interp);
+            Tcl_Preserve (interp_obj->interp);
+
+            /* There is a lot of passing pointers around among various structures.
+             * We should understand if this is all that necessary.
+             * Here we assign the server_rec pointer to the interpreter which
+             * is wrong, because without separate interpreters it doens't make
+             * any sense. TODO
+             */
+
+            /* before we run a script we have to store the pointer to the
+             * running configuration in the thread private data. The design has
+             * to improve and running a script must have everything sanely
+             * prepared TODO
+             */
+
+            globals = Tcl_GetAssocData(interp_obj->interp, "rivet", NULL);
+
+            /*
+             * The current server record is stored to enable ::rivet::apache_log_error and
+             * other commands to log error messages in the virtual host's designated log file
+             */
 
+            globals->server = vhost_server;
             private->running_conf = rsc;
 
-            if (Tcl_EvalObjEx(interp,tcl_child_init, 0) != TCL_OK) {
-                ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, root_server, errmsg, function);
-                ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, root_server,
-                             "errorCode: %s", Tcl_GetVar(interp, "errorCode", 0));
-                ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, root_server,
-                             "errorInfo: %s", Tcl_GetVar(interp, "errorInfo", 0));
+            if (Tcl_EvalObjEx(interp_obj->interp,tcl_child_init, 0) != TCL_OK) {
+                ap_log_error(APLOG_MARK, APLOG_ERR,APR_EGENERAL,vhost_server,errmsg, function);
+                ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL,vhost_server,
+                             "errorCode: %s", Tcl_GetVar(interp_obj->interp, "errorCode", 0));
+                ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL,vhost_server,
+                             "errorInfo: %s", Tcl_GetVar(interp_obj->interp, "errorInfo", 0));
             }
-            Tcl_Release (interp);
+            Tcl_Release (interp_obj->interp);
             Tcl_DecrRefCount(tcl_child_init);
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


(tcl-rivet) 03/06: handling length of data in POST requests

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit 644270c489d664e90071b82cfebd7124415f6785
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Thu Apr 27 00:57:03 2023 +0200

    handling length of data in POST requests
---
 ChangeLog                       |  9 +++++++++
 src/mod_rivet_ng/TclWebapache.c |  4 ++--
 src/mod_rivet_ng/rivetCore.c    |  7 ++++---
 src/mod_rivet_ng/rivet_types.h  |  3 ++-
 src/request/apache_request.c    | 15 +++++++++++++--
 src/request/apache_request.h    |  2 +-
 6 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bb27059..f0f648d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-04-11 Massimo Manghi <mx...@apache.org>
+	* src/mod_rivet_ng/TclWebapache.c:
+	* src/mod_rivet_ng/rivetCore.c:
+	* src/mod_rivet_ng/rivet_types.h:
+	* src/request/apache_request.c:
+	* src/request/apache_request.h: handling length of data in POST requests. It
+	fixes ::rivet::raw_post when the POSTed data don't have variable sections (patch
+	provided by Scott Pitcher <sc...@svptechnicalservices.com.au>)
+
 2023-01-11 Massimo Manghi <mx...@apache.org>
 	* src/TclWeb.h: also this include file had a CONST84 specifier that needed to
 	be converted as CONST86
diff --git a/src/mod_rivet_ng/TclWebapache.c b/src/mod_rivet_ng/TclWebapache.c
index 6cb3522..44bc4db 100644
--- a/src/mod_rivet_ng/TclWebapache.c
+++ b/src/mod_rivet_ng/TclWebapache.c
@@ -1063,7 +1063,7 @@ TclWeb_GetVirtualFile(TclWebRequest *req, char *virtualname)
  */
 
 char *
-TclWeb_GetRawPost ( TclWebRequest *req )
+TclWeb_GetRawPost ( TclWebRequest *req, int *len )
 {
-    return ApacheRequest_get_raw_post(req->apachereq);
+    return ApacheRequest_get_raw_post(req->apachereq, len);
 }
diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c
index c2c5266..c32ed15 100644
--- a/src/mod_rivet_ng/rivetCore.c
+++ b/src/mod_rivet_ng/rivetCore.c
@@ -63,7 +63,7 @@
 #define COOKIES_ARRAY_NAME "cookies"
 
 extern module rivet_module;
-extern char* TclWeb_GetRawPost (TclWebRequest *req);
+extern char* TclWeb_GetRawPost (TclWebRequest *req, int *len);
 extern mod_rivet_globals* module_globals;
 extern apr_threadkey_t*  rivet_thread_key;
 
@@ -1277,18 +1277,19 @@ TCL_CMD_HEADER( Rivet_Upload )
 TCL_CMD_HEADER ( Rivet_RawPost )
 {
     char*                   data;
+    int                     length;
     Tcl_Obj*                retval;
     rivet_thread_private*   private;
 
     THREAD_PRIVATE_DATA(private)
     CHECK_REQUEST_REC(private,"::rivet::raw_post")
 
-    data = TclWeb_GetRawPost(private->req);
+    data = TclWeb_GetRawPost(private->req, &length);
 
     if (!data) {
         data = "";
     }
-    retval = Tcl_NewStringObj(data, -1);
+    retval = Tcl_NewByteArrayObj((const unsigned char *)data, length);
     Tcl_SetObjResult(interp, retval);
     return TCL_OK;
 }
diff --git a/src/mod_rivet_ng/rivet_types.h b/src/mod_rivet_ng/rivet_types.h
index 69a9a4a..6568073 100644
--- a/src/mod_rivet_ng/rivet_types.h
+++ b/src/mod_rivet_ng/rivet_types.h
@@ -74,7 +74,8 @@ typedef struct _ApacheRequest {
     int             (*upload_hook)(void *ptr, char *buf, int len, ApacheUpload *upload);
     void*           hook_data;
     const char*     temp_dir;
-    char*           raw_post; /* Raw post data. */
+    char*           raw_post;           /* Raw post data. */
+    int             raw_length;
     request_rec*    r;
     int             nargs;
 } ApacheRequest;
diff --git a/src/request/apache_request.c b/src/request/apache_request.c
index 79c3f20..611e75f 100644
--- a/src/request/apache_request.c
+++ b/src/request/apache_request.c
@@ -31,7 +31,7 @@ static void req_plustospace(char *str)
 }
 
 static int
-util_read(ApacheRequest *req, const char **rbuf)
+util_read(ApacheRequest *req, const char **rbuf, int *rlen)
 {
     request_rec *r = req->r;
     int rc = OK;
@@ -55,6 +55,7 @@ util_read(ApacheRequest *req, const char **rbuf)
         }
 
         *rbuf = apr_pcalloc(r->pool, length + 1);
+	*rlen = length;
 
         while ((len_read =
                     ap_get_client_block(r, buff, sizeof(buff))) > 0) {
@@ -209,6 +210,7 @@ ApacheRequest *ApacheRequest_new(apr_pool_t *pool)
     req->hook_data      = NULL;
     req->temp_dir       = NULL;
     req->raw_post       = NULL;
+    req->raw_length     = 0;
     req->parsed         = 0;
     req->r              = NULL;
     req->nargs          = 0;
@@ -228,6 +230,7 @@ ApacheRequest *ApacheRequest_init(ApacheRequest* req, request_rec *r)
     req->hook_data      = NULL;
     req->temp_dir       = NULL;
     req->raw_post       = NULL;
+    req->raw_length     = 0;
     req->parsed         = 0;
     req->r              = r;
     req->nargs          = 0;
@@ -426,6 +429,7 @@ int ApacheRequest_parse_urlencoded(ApacheRequest *req)
 
     if (r->method_number == M_POST || r->method_number == M_PUT || r->method_number == M_DELETE) {
     	const char *data = NULL;
+	int length = 0;
 
     /*
         const char *type;
@@ -437,12 +441,13 @@ int ApacheRequest_parse_urlencoded(ApacheRequest *req)
     	}
     */
 
-    	if ((rc = util_read(req, &data)) != OK) {
+    	if ((rc = util_read(req, &data, &length)) != OK) {
     	    return rc;
     	}
 
     	if (data) {
     	    req->raw_post = (char*) data; /* Give people a way of getting at the raw data. */
+    	    req->raw_length = length;
     	    split_to_parms(req, data);
     	}
     }
@@ -733,3 +738,9 @@ char *ApacheRequest_expires(ApacheRequest *req, char *time_str)
     return ApacheUtil_expires(req->r->pool, time_str, EXPIRES_HTTP);
 }
 
+char *ApacheRequest_get_raw_post(ApacheRequest *req, int *len)
+{
+    if (len)
+	*len = req->raw_length;
+    return req->raw_post;
+}
diff --git a/src/request/apache_request.h b/src/request/apache_request.h
index 300da12..8855961 100644
--- a/src/request/apache_request.h
+++ b/src/request/apache_request.h
@@ -102,7 +102,7 @@ ApacheUpload_info((upload), "Content-Type")
 #define ApacheRequest_set_post_max(req, max) ((req)->post_max = (max))
 #define ApacheRequest_set_temp_dir(req, dir) ((req)->temp_dir = (dir))
 
-#define ApacheRequest_get_raw_post(req) ((req)->raw_post)
+char *ApacheRequest_get_raw_post(ApacheRequest *req, int *len);
 
 char *ApacheUtil_expires(apr_pool_t *p, char *time_str, int type);
 #define EXPIRES_HTTP   1


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


(tcl-rivet) 06/06: merging from master

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit f0b871006786d1babeb98bc2aac1bdfd72fa6de0
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Wed Jun 14 17:21:25 2023 +0200

    merging from master
---
 ChangeLog                                |  9 ++++++-
 rivet/init.tcl.in                        |  4 +--
 rivet/packages/session/session-class.tcl |  9 +++----
 rivet/rivet-tcl/parray.tcl               | 14 +++++------
 src/mod_rivet_ng/mod_rivet.c             | 11 +++-----
 src/mod_rivet_ng/mod_rivet_generator.c   |  2 --
 tests/channel.test                       | 43 ++++++++++++++++----------------
 7 files changed, 45 insertions(+), 47 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 91f4d2f..b33ff6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-06-14 Massimo Manghi <mx...@apache.org>
+	* tests/channel.test: indenting code for improved readability
+	* src/mod_rivet_ng/mod_rivet.c,mod_rivet_generator.c: Removed unused code that
+	ha been commented out long ago
+	* rivet/rivet-tcl/parray.tcl: ::rivet::parray now accepting alternative way to
+	return output.
+
 2023-05-18 Massimo Manghi <mx...@apache.org>
 	* src/mod_rivet_ng/mod_rivet.c:
 	* src/mod_rivet_ng/mod_rivet.h:
@@ -7,7 +14,7 @@
 	to be used by Rivet_LogErrorCmd instead of module_globals->server when threads private data are
 	not available (like when ChildInitScript is executed)
 
-2023-05-04 Massimo Manghi <mx...@apache.org>
+2023-05-14 Massimo Manghi <mx...@apache.org>
 	* tests/rivet.test: more contributions provided by Scott Pitcher <sc...@svptechnicalservices.com.au>)
 	* tests/apachetest/apachetest.tcl: More improvements to the test script. Now
 	handling also Apache directive IncludeOptional and enabling execution control 
diff --git a/rivet/init.tcl.in b/rivet/init.tcl.in
index 9ab96b9..e260953 100644
--- a/rivet/init.tcl.in
+++ b/rivet/init.tcl.in
@@ -235,8 +235,8 @@ proc ::Rivet::tcl_commands_export_list {tclpath} {
         variable auto_index
         array set auto_index {}
 
-        # the auto_index in ${tclpath}/tclIndex is loaded
-        # this array is used to fetch a list of Rivet commands
+        # The auto_index in ${tclpath}/tclIndex is loaded.
+        # This array is used to fetch a list of Rivet commands
         # implemented in Rivet
 
         set dir $tclpath
diff --git a/rivet/packages/session/session-class.tcl b/rivet/packages/session/session-class.tcl
index 28fb3e1..1ce51f4 100644
--- a/rivet/packages/session/session-class.tcl
+++ b/rivet/packages/session/session-class.tcl
@@ -346,21 +346,18 @@ package require Itcl
     }
 
     #
-    # stash -
+    # stash - given a packagename and a key-value dictionary of data
+    # the procedure calls method store to data into the cache table using
+    # the dictionary keys as column _key value
     #
     #
 
     method stash {packageName keyvalue_d} {
-
         dict for {key value} $keyvalue_d {
-
             $this store $packageName $key $value
-
         }
-
     }
 
-
     #
     # load - given a package names returns a dictionary storing the key - value pairs for this session
     #
diff --git a/rivet/rivet-tcl/parray.tcl b/rivet/rivet-tcl/parray.tcl
index 784b01e..b9f2582 100644
--- a/rivet/rivet-tcl/parray.tcl
+++ b/rivet/rivet-tcl/parray.tcl
@@ -7,13 +7,11 @@
 ##    arrayName - Name of the array to display.
 ##    pattern   - A wildcard pattern of variables within the array to display.
 ##
-## $Id$
-##
 ###
 
 namespace eval ::rivet {
 
-    proc parray {arrayName {pattern *}} {
+    proc parray {arrayName {pattern *} {outputcmd "puts stdout"}} {
         upvar 1 $arrayName array
         if {![array exists array]} {
             return -code error "\"$arrayName\" isn't an array"
@@ -24,14 +22,14 @@ namespace eval ::rivet {
                 set maxl [string length $name]
             }
         }
-        puts stdout "<PRE><B>$arrayName</B>"
+        set html_text [list "<b>$arrayName</b>"]
         set maxl [expr {$maxl + [string length $arrayName] + 2}]
         foreach name [lsort [array names array $pattern]] {
-            set nameString [format %s(%s) $arrayName [::rivet::escape_sgml_chars $name]]
-            puts stdout [format "%-*s = %s" $maxl $nameString [::rivet::escape_sgml_chars $array($name)]]
+            set nameString [format "%s(%s)" $arrayName [::rivet::escape_sgml_chars $name]]
+            lappend html_text [format "%-*s = %s" $maxl $nameString [::rivet::escape_sgml_chars $array($name)]]
         }
-        puts stdout "</PRE>"
+
+        eval $outputcmd [list <pre>[join $html_text "\n"]</pre>]
     }
 
-    namespace export parray
 }
diff --git a/src/mod_rivet_ng/mod_rivet.c b/src/mod_rivet_ng/mod_rivet.c
index c63efda..24c685b 100644
--- a/src/mod_rivet_ng/mod_rivet.c
+++ b/src/mod_rivet_ng/mod_rivet.c
@@ -389,6 +389,9 @@ Rivet_RunServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, ser
  * Post config hook. The server initialization loads the MPM bridge
  * and runs the Tcl server initialization script
  *
+ * The module globals structure is allocated and initialized by
+ * the pre-config hook procedure (Rivet_InitGlobals)
+ *
  */
 
 static int
@@ -421,13 +424,7 @@ Rivet_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server
         return OK; /* This would be the first time through */
 	}
 	
-    /* Everything revolves around this structure: module_globals */
-
-    /* the module global structure is allocated and the MPM bridge name established */
-
-    // module_globals = Rivet_CreateModuleGlobals (pPool,server);
-
-    /* We can proceed initializing the globals with information stored in the module configuration */
+    /* We determine the Rivet Bridge and we store its pointer in the module globals */
 
     module_globals->rivet_mpm_bridge = Rivet_SeekMPMBridge(pPool);
     module_globals->server           = server;
diff --git a/src/mod_rivet_ng/mod_rivet_generator.c b/src/mod_rivet_ng/mod_rivet_generator.c
index 7d81d7f..54c9861 100644
--- a/src/mod_rivet_ng/mod_rivet_generator.c
+++ b/src/mod_rivet_ng/mod_rivet_generator.c
@@ -359,8 +359,6 @@ sendcleanup:
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, private->r,
                                   "thread terminating with code %d",private->exit_status);
         RIVET_MPM_BRIDGE_CALL(exit_handler,private);
-        //Tcl_Exit(private->exit_status);
-        //exit(private->exit_status);
     }
 
     /* We now reset the status to prepare the child process for another request */
diff --git a/tests/channel.test b/tests/channel.test
index e2f6454..0c2967b 100644
--- a/tests/channel.test
+++ b/tests/channel.test
@@ -2,27 +2,28 @@
 
 foreach {sep_channel offset_value} {On 0 Off 1} {
 
-::tcltest::test channel-1.1 [list checking SeparateChannel] {
-	apachetest::start {} "
-RivetServerConf SeparateVirtualInterps  On
-RivetServerConf SeparateChannels        $sep_channel
-#NameVirtualHost 127.0.0.1
-<VirtualHost *>
-    ServerName vhost1
-    RivetServerConf ChildInitScript \"fconfigure stdout -buffersize 8192\"
-</VirtualHost>
+    ::tcltest::test channel-1.1 [list checking SeparateChannel] {
+        apachetest::start {} "
+        RivetServerConf SeparateVirtualInterps  On
+        RivetServerConf SeparateChannels        $sep_channel
+        #NameVirtualHost 127.0.0.1
+        <VirtualHost *>
+            ServerName vhost1
+            RivetServerConf ChildInitScript \"fconfigure stdout -buffersize 8192\"
+        </VirtualHost>
 
-<VirtualHost *>
-    ServerName vhost2
-    RivetServerConf ChildInitScript \"fconfigure stdout -buffersize 16384\"
-</VirtualHost>
-" {
-    set page1 [::http::geturl "${urlbase}channel.tcl" -headers [list Host vhost1]]
-    set page2 [::http::geturl "${urlbase}channel.tcl" -headers [list Host vhost2]]
+        <VirtualHost *>
+            ServerName vhost2
+            RivetServerConf ChildInitScript \"fconfigure stdout -buffersize 16384\"
+        </VirtualHost>
+        " {
+            set page1 [::http::geturl "${urlbase}channel.tcl" -headers [list Host vhost1]]
+            set page2 [::http::geturl "${urlbase}channel.tcl" -headers [list Host vhost2]]
+
+            puts "[::http::data $page1] [::http::data $page2]"
+            set diff [expr ([::http::data $page2]-[::http::data $page1] != 0) + $offset_value]
+        }
+        set diff
+    } {1}
 
-    puts "[::http::data $page1] [::http::data $page2]"
-    set diff [expr ([::http::data $page2]-[::http::data $page1] != 0) + $offset_value]
-}
-set diff
-} {1}
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org


(tcl-rivet) 02/06: fix conflict in Changelog

Posted by mx...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit a12c8ac5c2eef416f68ae4b52b3ddb40413c31b0
Merge: 2596517 df3ed13
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Fri Oct 6 10:46:44 2023 +0200

    fix conflict in Changelog

 ChangeLog    | 7 ++++---
 src/TclWeb.h | 9 +--------
 2 files changed, 5 insertions(+), 11 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org