You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by mx...@apache.org on 2012/05/07 23:20:12 UTC

svn commit: r1335266 - in /tcl/rivet/trunk: ChangeLog rivet/rivet-tcl/lassign.tcl src/apache-2/Makefile.am src/apache-2/mod_rivet.c src/apache-2/mod_rivet.h src/apache-2/rivetConf.c src/apache-2/rivetCore.c

Author: mxmanghi
Date: Mon May  7 21:20:11 2012
New Revision: 1335266

URL: http://svn.apache.org/viewvc?rev=1335266&view=rev
Log:
    * src/apache-2/rivetCore.c: new command ::rivet::inspect implementing function Rivet_InspectCmd
    * src/apache-2/rivetConf.c: Ancillary functions for instrospection procedure Rivet_InspectCmd
    * src/apache-2/Makefile.am: Added handling of rivetConf.c
    * src/apache-2/mod_rivet.c: Handling of configuration directives restricted to meaningful
    options when RivetDirConf or RivetUserConf directives are set. An error message is printed
    when child process initialization directives are set by RivetDirConf and RivetUserConf.
    Rivet_PropagatePerDirConfArrays and Rivet_PropagateServerConfArray functions disabled as the
    ::rivet::inspect command can work out a better alternative creating the RivetServerConf,
    RivetDirConf and RivetUserConf on demand.
    * src/apache-2/mod_rivet.h: Added declaration for functions in rivetConf.c
    * rivet/rivet-tcl/lassign.tcl: removed, since Tcl 8.5 lassign implements and extends the
    same functionalities 


Added:
    tcl/rivet/trunk/src/apache-2/rivetConf.c   (with props)
Removed:
    tcl/rivet/trunk/rivet/rivet-tcl/lassign.tcl
Modified:
    tcl/rivet/trunk/ChangeLog
    tcl/rivet/trunk/src/apache-2/Makefile.am
    tcl/rivet/trunk/src/apache-2/mod_rivet.c
    tcl/rivet/trunk/src/apache-2/mod_rivet.h
    tcl/rivet/trunk/src/apache-2/rivetCore.c

Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1335266&r1=1335265&r2=1335266&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Mon May  7 21:20:11 2012
@@ -1,3 +1,18 @@
+2012-05-07 Massimo Manghi <mx...@apache.org>
+    * src/apache-2/rivetCore.c: new command ::rivet::inspect implementing function
+    Rivet_InspectCmd
+    * src/apache-2/rivetConf.c: Ancillary functions for instrospection procedure Rivet_InspectCmd
+    * src/apache-2/Makefile.am: Added handling of rivetConf.c
+    * src/apache-2/mod_rivet.c: Handling of configuration directives restricted to meaningful
+    options when RivetDirConf or RivetUserConf directives are set. An error message is printed
+    when child process initialization directives are set by RivetDirConf and RivetUserConf.
+    Rivet_PropagatePerDirConfArrays and Rivet_PropagateServerConfArray functions disabled as the
+    ::rivet::inspect command can work out a better alternative creating the RivetServerConf,
+    RivetDirConf and RivetUserConf on demand.
+    * src/apache-2/mod_rivet.h: Added declaration for functions in rivetConf.c
+    * rivet/rivet-tcl/lassign.tcl: removed, since Tcl 8.5 lassign implements and extends the
+    same functionalities 
+
 2012-04-30 Massimo Manghi <mx...@apache.org>
     * rivet/packages/form/form.tcl: Patch provided by Jeff Lawson to manage -label switches.
     The package now requires package uuid from Tcllib.

Modified: tcl/rivet/trunk/src/apache-2/Makefile.am
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/Makefile.am?rev=1335266&r1=1335265&r2=1335266&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/Makefile.am (original)
+++ tcl/rivet/trunk/src/apache-2/Makefile.am Mon May  7 21:20:11 2012
@@ -37,6 +37,7 @@ mod_rivet_la_SOURCES = 			        \
 	        mod_rivet.c 				\
 	        TclWebapache.c 				\
 	        rivetCore.c					\
+            rivetConf.c                 \
 	        ../rivetChannel.c 			\
             ../rivetParser.c
 

Modified: tcl/rivet/trunk/src/apache-2/mod_rivet.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/mod_rivet.c?rev=1335266&r1=1335265&r2=1335266&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/mod_rivet.c (original)
+++ tcl/rivet/trunk/src/apache-2/mod_rivet.c Mon May  7 21:20:11 2012
@@ -285,6 +285,7 @@ Rivet_InitServerVariables( Tcl_Interp *i
 #endif
 }
 
+#if 0
 static void
 Rivet_PropagateServerConfArray( Tcl_Interp *interp, rivet_server_conf *rsc )
 {
@@ -321,6 +322,7 @@ Rivet_PropagateServerConfArray( Tcl_Inte
     }
     Tcl_DecrRefCount(arrayName);
 }
+#endif
 
 /* Calls Tcl_EvalObjEx() and checks for errors
  * Prints the error buffer if any.
@@ -697,6 +699,10 @@ Rivet_MergeDirConfigVars(apr_pool_t *p, 
               rivet_server_conf *base, rivet_server_conf *add )
 {
     FILEDEBUGINFO;
+    new->rivet_child_init_script = add->rivet_child_init_script ?
+        add->rivet_child_init_script : base->rivet_child_init_script;
+    new->rivet_child_exit_script = add->rivet_child_exit_script ?
+        add->rivet_child_exit_script : base->rivet_child_exit_script;
 
     new->rivet_before_script = add->rivet_before_script ?
         add->rivet_before_script : base->rivet_before_script;
@@ -782,8 +788,8 @@ Rivet_CreateConfig(apr_pool_t *p, server
     Tcl_IncrRefCount(rsc->rivet_default_error_script);
 
     /* these are pointers so that they can be passed around...  */
-    rsc->cache_size = apr_pcalloc(p, sizeof(int));
-    rsc->cache_free = apr_pcalloc(p, sizeof(int));
+    rsc->cache_size                 = apr_pcalloc(p, sizeof(int));
+    rsc->cache_free                 = apr_pcalloc(p, sizeof(int));
     *(rsc->cache_size)              = -1;
     *(rsc->cache_free)              = 0;
     rsc->upload_max                 = RIVET_MAX_POST;
@@ -804,6 +810,8 @@ Rivet_CreateConfig(apr_pool_t *p, server
     return rsc;
 }
 
+#if 0
+
 static void
 Rivet_PropagatePerDirConfArrays( Tcl_Interp *interp, rivet_server_conf *rsc )
 {
@@ -861,6 +869,7 @@ Rivet_PropagatePerDirConfArrays( Tcl_Int
     }
     Tcl_DecrRefCount(arrayName);
 }
+#endif
 
 /*
  *-----------------------------------------------------------------------------
@@ -936,7 +945,7 @@ Rivet_PerInterpInit(server_rec *s, rivet
 
     /* Create a global array with information about the server. */
     Rivet_InitServerVariables(interp, p );
-    Rivet_PropagateServerConfArray( interp, rsc );
+//  Rivet_PropagateServerConfArray( interp, rsc );
 
     /* Eval Rivet's init.tcl file to load in the Tcl-level commands. */
 
@@ -962,15 +971,9 @@ Rivet_PerInterpInit(server_rec *s, rivet
 
     /* Loading into the interpreter the commands provided by librivet.so */
 
-   /* It would be nice to have to whole set of Rivet commands
-    * loaded into the interpreter at this stage. Unfortunately
-    * a problem with the dynamic loader of some OS prevents us 
-    * from callingTcl_PkgRequire for 'rivetlib' because Apache segfaults
-    * shortly after the extension library is loaded.
-    * The problem was investigated on Linux and it became clear 
-    * that it's linked to the way Tcl calls dlopen (Bug #3216070)
-    * The problem could be solved in Tcl8.6 
-    */
+    /* Bug #3216070 has been solved with 8.5.10 and commands shipped with
+     * Rivetlib can be mapped at this stage
+     */
 
     if (Tcl_PkgRequire(interp, RIVETLIB_TCL_PACKAGE, "1.2", 1) == NULL)
     {
@@ -1085,12 +1088,14 @@ Rivet_SetScript (apr_pool_t *pool, rivet
  *
  * Command Arguments:
  *
+ *  RivetServerConf ServerInitScript <script>
  *  RivetServerConf GlobalInitScript <script>
  *  RivetServerConf ChildInitScript <script>
  *  RivetServerConf ChildExitScript <script>
  *  RivetServerConf BeforeScript <script>
  *  RivetServerConf AfterScript <script>
  *  RivetServerConf ErrorScript <script>
+ *  RivetServerConf AfterEveryScript <script>
  *  RivetServerConf CacheSize <integer>
  *  RivetServerConf UploadDirectory <directory>
  *  RivetServerConf UploadMaxSize <integer>
@@ -1140,6 +1145,7 @@ Rivet_ServerConf( cmd_parms *cmd, void *
  *  RivetDirConf BeforeScript <script>
  *  RivetDirConf AfterScript <script>
  *  RivetDirConf ErrorScript <script>
+ *  RivetDirConf AfterEveryScript <script>
  *  RivetDirConf UploadDirectory <directory>
  */
 
@@ -1159,7 +1165,19 @@ Rivet_DirConf( cmd_parms *cmd, void *vrd
     if( STREQU( var, "UploadDirectory" ) ) {
         rdc->upload_dir = val;
     } else {
-        string = Rivet_SetScript( cmd->pool, rdc, var, val );
+        if (STREQU(var,"BeforeScript")      || 
+            STREQU(var,"AfterScript")       || 
+            STREQU(var,"AbortScript")       ||
+            STREQU(var,"AfterEveryScript")  ||
+            STREQU(var,"ErrorScript"))
+        {
+            string = Rivet_SetScript( cmd->pool, rdc, var, val );
+        }
+        else
+        {
+            return apr_pstrcat(cmd->pool, "Rivet configuration error: '",var, 
+                                          "' not valid for RivetDirConf", NULL);
+        }
     }
 
     if (string != NULL) apr_table_set( rdc->rivet_dir_vars, var, string );
@@ -1176,7 +1194,8 @@ Rivet_DirConf( cmd_parms *cmd, void *vrd
  */
 
 static const char *
-Rivet_UserConf( cmd_parms *cmd, void *vrdc, 
+Rivet_UserConf( cmd_parms *cmd, 
+                void *vrdc, 
                 const char *var, 
                 const char *val )
 {
@@ -1192,9 +1211,23 @@ Rivet_UserConf( cmd_parms *cmd, void *vr
     /* We have modified these scripts. */
     /* This is less than ideal though, because it will get set to 1
      * every time - FIXME. */
+
     rdc->user_scripts_updated = 1;
 
-    string = Rivet_SetScript( cmd->pool, rdc, var, val );
+    if (STREQU(var,"BeforeScript")  || 
+        STREQU(var,"AfterScript")   || 
+        STREQU(var,"AbortScript")   ||
+        STREQU(var,"AfterEveryScript") ||
+        STREQU(var,"ErrorScript"))
+    {
+        string = Rivet_SetScript( cmd->pool, rdc, var, val );
+    }
+    else
+    {
+        return apr_pstrcat(cmd->pool, "Rivet configuration error: '",var, 
+                                      "' not valid for RivetUserConf", NULL);
+    }
+
     /* XXX Need to figure out what to do about setting the table.  */
     if (string != NULL) apr_table_set( rdc->rivet_user_vars, var, string );
     return NULL;
@@ -1824,9 +1857,9 @@ Rivet_SendContent(request_rec *r)
     }
 
 #ifdef USE_APACHE_RSC
-    Rivet_PropagatePerDirConfArrays( interp, rsc );
+//  Rivet_PropagatePerDirConfArrays( interp, rsc );
 #else
-    Rivet_PropagatePerDirConfArrays( interp, rdc );
+//  Rivet_PropagatePerDirConfArrays( interp, rdc );
 #endif
 
     /* Initialize this the first time through and keep it around. */

Modified: tcl/rivet/trunk/src/apache-2/mod_rivet.h
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/mod_rivet.h?rev=1335266&r1=1335265&r2=1335266&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/mod_rivet.h (original)
+++ tcl/rivet/trunk/src/apache-2/mod_rivet.h Mon May  7 21:20:11 2012
@@ -131,5 +131,14 @@ rivet_server_conf *Rivet_GetConf(request
 #define RIVET_NEW_CONF(p) \
 	(rivet_server_conf *)apr_pcalloc(p, sizeof(rivet_server_conf))
 
+Tcl_Obj* Rivet_BuildConfDictionary ( Tcl_Interp*        interp,
+                                    rivet_server_conf*  rivet_conf);
+
+Tcl_Obj* Rivet_ReadConfParameter (  Tcl_Interp*         interp,
+                                    rivet_server_conf*  rivet_conf,
+                                    Tcl_Obj*            par_name);
+
+Tcl_Obj* Rivet_CurrentConfDict (    Tcl_Interp*           interp,
+                                    rivet_server_conf*    rivet_conf);
 #endif /* MOD_RIVET_H */
 

Added: tcl/rivet/trunk/src/apache-2/rivetConf.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/rivetConf.c?rev=1335266&view=auto
==============================================================================
--- tcl/rivet/trunk/src/apache-2/rivetConf.c (added)
+++ tcl/rivet/trunk/src/apache-2/rivetConf.c Mon May  7 21:20:11 2012
@@ -0,0 +1,422 @@
+/*
+ * rivetConf.c - Functions for accessing Rivet configuration variables
+ *
+ * Functions in this file implement core function to be called mainly
+ * by the Rivet_InspectCmd function, which implments command 'inspect'
+ *
+ */
+
+/* Copyright 2002-2004 The Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+/* $Id: */
+
+#include <tcl.h>
+#include <string.h>
+#include <apr_errno.h>
+#include <apr_strings.h>
+#include <apr_tables.h>
+
+#include "httpd.h"
+#include "http_config.h"
+#include "http_request.h"
+#include "http_core.h"
+#include "http_main.h"
+#include "util_script.h"
+#include "http_config.h"
+
+#include "mod_rivet.h"
+
+static const char* confDirectives[] = 
+{ 
+                    "ServerInitScript", 
+                    "GlobalInitScript",
+                    "ChildInitScript",
+                    "ChildExitScript",
+                    "BeforeScript",
+                    "AfterScript",
+                    "AfterEveryScript",
+                    "AbortScript",
+                    "ErrorScript",
+                    "UploadMaxSize",
+                    "UploadDirectory",
+                    "UploadFilesToVar",
+                    "SeparateVirtualInterps",
+                    "HonorHeaderOnlyRequests",
+                    NULL 
+};
+
+enum confIndices {
+                    server_init_script,
+                    global_init_script,
+                    child_init_script,
+                    child_exit_script,
+                    before_script,
+                    after_script,
+                    after_every_script,
+                    abort_script,
+                    error_script,
+                    upload_max,
+                    upload_directory,
+                    upload_files_to_var,
+                    separate_virtual_interps,
+                    honor_header_only_requests,
+                    conf_index_terminator 
+                };
+
+/* 
+ * -- Rivet_ReadConfParameter
+ *
+ * This procedure reads a single field named par_name from 
+ * rivet_server_conf structure and returns a Tcl_Obj pointer
+ * containing the field value. See confDirectives for a list
+ * of possible names. If the procedure is queried for a non  
+ * existing field a NULL is returned.
+ *
+ *  Arguments:
+ *
+ *  - interp: pointer to the current Tcl interpreter structure
+ *  - rsc: a pointer to a rivet_server_conf structure
+ *  - par_name: parameter name (as listed in confDirectives)
+ *
+ * Returned value:
+ *
+ *  - A Tcl_Obj pointer to the parameter value whose refCount is
+ *    set to 1 before returning to the caller
+ *
+ */
+
+Tcl_Obj*
+Rivet_ReadConfParameter ( Tcl_Interp* interp,
+                          rivet_server_conf* rsc,
+                          Tcl_Obj*    par_name)
+{
+    int parameter_i;
+    Tcl_Obj* par_value;
+
+    if (Tcl_GetIndexFromObj(interp, par_name, confDirectives,
+                "<one of conf directives>", 0, &parameter_i) == TCL_ERROR) {
+        return NULL;
+    }
+
+    switch (parameter_i)
+    {
+        case server_init_script:
+        {
+            par_value = rsc->rivet_server_init_script;
+            break;
+        }
+        case global_init_script:
+        {
+            par_value = rsc->rivet_global_init_script;
+            break;
+        }
+        case child_init_script:
+        {
+            par_value = rsc->rivet_child_init_script;
+            break;
+        }
+        case child_exit_script:
+        {
+            par_value = rsc->rivet_child_exit_script;
+            break;
+        }
+        case before_script:
+        {
+            par_value = rsc->rivet_before_script;
+            break;
+        }
+        case after_script:
+        {
+            par_value = rsc->rivet_after_script;
+            break;
+        }
+        case after_every_script:
+        {
+            par_value = rsc->after_every_script;
+            break;
+        }
+        case abort_script:
+        {
+            par_value = rsc->rivet_abort_script;
+            break;
+        }
+        case error_script:
+        {
+            par_value = rsc->rivet_error_script;
+            break;
+        }
+        case upload_max:
+        {
+            par_value = Tcl_NewIntObj(rsc->upload_max);
+            break;
+        }
+        case upload_directory:
+        {
+            par_value = Tcl_NewStringObj(rsc->upload_dir,-1);
+            break;
+        }
+        case upload_files_to_var:
+        {
+            par_value = Tcl_NewIntObj(rsc->upload_files_to_var);
+            break;
+        }
+        case separate_virtual_interps:
+        {
+            par_value = Tcl_NewIntObj(rsc->separate_virtual_interps);
+            break;
+        }
+        case honor_header_only_requests:
+        {
+            par_value = Tcl_NewIntObj(rsc->honor_header_only_reqs);
+            break;
+        }
+        default:
+        {
+            return NULL;
+        }
+    }
+
+    if (par_value == NULL) 
+    {
+        par_value=Tcl_NewStringObj("<undef>",-1);
+    }
+
+    Tcl_IncrRefCount(par_value);
+
+    return par_value;
+}
+
+/* 
+ * Rivet_ReadConfTable: 
+ * 
+ * This procedure builds a key-value list from an apr table
+ * It called from Rivet_BuildConfDictionary for Rivet configuration
+ * tables but it could work for every apr table
+ *
+ * Arguments:
+ *
+ *  - interp: Tcl_Interp pointer
+ *  - table: an apr_table_t pointer
+ */
+
+Tcl_Obj* Rivet_ReadConfTable (  Tcl_Interp*           interp,
+                                apr_table_t*          table)
+{
+    Tcl_Obj*                key;
+    Tcl_Obj*                val;
+    apr_array_header_t      *arr;
+    apr_table_entry_t       *elts;
+    int                     nelts,i;
+    int                     tcl_status = TCL_OK;
+    Tcl_Obj*                keyval_list = Tcl_NewObj();
+
+    Tcl_IncrRefCount(keyval_list);
+
+    arr   = (apr_array_header_t*) apr_table_elts( table );
+    elts  = (apr_table_entry_t *) arr->elts;
+    nelts = arr->nelts;
+
+/*
+    if (Tcl_IsShared(keyval_list))
+    {
+        fprintf(stderr,"building duplicate keyval_list\n");
+        keyval_list = Tcl_DuplicateObj(keyval_list);
+    }
+ */
+
+    for (i = 0; i < nelts; i++)
+    {
+        key = Tcl_NewStringObj( elts[i].key, -1);
+        val = Tcl_NewStringObj( elts[i].val, -1);
+        Tcl_IncrRefCount(key);
+        Tcl_IncrRefCount(val);
+
+        tcl_status = Tcl_ListObjAppendElement (interp,keyval_list,key);
+        if (tcl_status == TCL_ERROR)
+        {   
+            Tcl_DecrRefCount(keyval_list);
+            Tcl_DecrRefCount(key);
+            Tcl_DecrRefCount(val);
+            return NULL;
+        }
+
+        tcl_status = Tcl_ListObjAppendElement (interp,keyval_list,val);
+        if (tcl_status == TCL_ERROR)
+        {
+            Tcl_DecrRefCount(keyval_list);
+            Tcl_DecrRefCount(key);
+            Tcl_DecrRefCount(val);
+            return NULL;
+        }
+
+        Tcl_DecrRefCount(key);
+        Tcl_DecrRefCount(val);
+    }
+
+    return keyval_list;
+}
+
+
+/*
+ * -- Rivet_BuildConfDictionary
+ * 
+ * Parameters set in the configuration files are collected in three
+ * APR tables by Rivet_ServerConf,Rivet_DirConf and Rivet_UserConf. 
+ *
+ * Arguments:
+ *
+ * - interp: Tcl_Interp pointer
+ * - rivet_conf: pointer to a rivet_server_conf structure as
+ *   returned by Rivet_GetConf
+ *
+ * Returned value:
+ *
+ *  - Tcl dictionary storing the dir/user/server configuration. The
+ *    dictionary refCount is incremented 
+ *
+ */
+
+Tcl_Obj* Rivet_BuildConfDictionary ( Tcl_Interp*           interp,
+                                     rivet_server_conf*    rivet_conf)
+{
+    apr_table_t* conf_tables[3];
+    Tcl_Obj*     keyval_list = NULL;
+    Tcl_Obj*     key_list[2];
+    int          it;
+    Tcl_Obj*     conf_dict = Tcl_NewObj();
+
+    static const char* section_names[] = 
+    {
+        "dir",
+        "user",
+        "server"
+    };
+
+    enum
+    {
+        dir_conf_section,
+        user_conf_section,
+        server_conf_section
+    };
+
+    conf_tables[0] = rivet_conf->rivet_dir_vars;
+    conf_tables[1] = rivet_conf->rivet_user_vars;
+    conf_tables[2] = rivet_conf->rivet_server_vars;
+
+    Tcl_IncrRefCount(conf_dict);
+
+    for (it=0; it < 3; it++)
+    {
+        keyval_list = Rivet_ReadConfTable(interp,conf_tables[it]);
+
+        if (keyval_list != NULL)
+        {
+            int       i;
+            Tcl_Obj** objArrayPnt;
+            int       objArrayCnt;
+            Tcl_Obj*  val;
+
+            key_list[0] = Tcl_NewStringObj(section_names[it],-1);
+            Tcl_IncrRefCount(key_list[0]);
+
+            Tcl_ListObjGetElements(interp,keyval_list,&objArrayCnt,&objArrayPnt);
+            for (i=0; i < objArrayCnt; i+=2)
+            {
+                key_list[1] = objArrayPnt[i];
+                val         = objArrayPnt[i+1];
+
+                Tcl_IncrRefCount(key_list[1]);
+                Tcl_IncrRefCount(val);
+
+                Tcl_DictObjPutKeyList(interp,conf_dict,2,key_list,val);
+
+                Tcl_DecrRefCount(key_list[1]);
+                Tcl_DecrRefCount(val);
+            }
+            Tcl_DecrRefCount(key_list[0]);
+            Tcl_DecrRefCount(keyval_list);
+        }
+        else
+        {
+            return NULL;
+        }
+    }
+
+    return conf_dict;
+}
+
+
+/*
+ * Rivet_CurrentConfDict 
+ *
+ * This function is called by Rivet_InspectCmd which implements command
+ * '::rivet::inspect -all'. The function returns a dictionary where every
+ * parameter name (confDirectives) is associated to its value stored in
+ * the rivet_server_conf as returned by Rivet_GetConf
+ *
+ * Arguments:
+ *
+ * - interp: Tcl interpreter pointer
+ * - rivet_conf: a pointer to a rivet_server_conf structure
+ *
+ * Returned value_
+ *
+ * - a Tcl_Obj* pointer to a dictionary. The dictionary object
+ *  refCount is set to 1
+ */
+
+Tcl_Obj* Rivet_CurrentConfDict ( Tcl_Interp*           interp,
+                                 rivet_server_conf*    rivet_conf)
+{
+    Tcl_Obj* dictObj = Tcl_NewObj();
+    Tcl_Obj* par_name; 
+    static const char** p;
+
+    Tcl_IncrRefCount(dictObj);
+
+    for (p = confDirectives; (*p) != NULL; p++)
+    {
+        Tcl_Obj* par_value;
+
+        par_name = Tcl_NewStringObj(*p,-1);
+        Tcl_IncrRefCount(par_name);
+
+        par_value = Rivet_ReadConfParameter(interp,rivet_conf,par_name);
+        if (par_value != NULL)
+        {
+            Tcl_DictObjPut(interp,dictObj,par_name,par_value);
+            Tcl_DecrRefCount(par_value);
+        }
+        else
+        {
+            Tcl_Obj* message = Tcl_NewStringObj("Invalid configuration option: ",-1);
+            
+            Tcl_IncrRefCount(message);
+            Tcl_AppendObjToObj(message,par_name);
+            Tcl_AddErrorInfo(interp, Tcl_GetStringFromObj(message,NULL));
+
+            Tcl_DecrRefCount(message);
+            Tcl_DecrRefCount(par_name);
+            Tcl_DecrRefCount(dictObj);
+            dictObj = NULL;
+            break;
+        }
+        Tcl_DecrRefCount(par_name);
+
+    }
+
+    return dictObj;
+}

Propchange: tcl/rivet/trunk/src/apache-2/rivetConf.c
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: tcl/rivet/trunk/src/apache-2/rivetCore.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/apache-2/rivetCore.c?rev=1335266&r1=1335265&r2=1335266&view=diff
==============================================================================
--- tcl/rivet/trunk/src/apache-2/rivetCore.c (original)
+++ tcl/rivet/trunk/src/apache-2/rivetCore.c Mon May  7 21:20:11 2012
@@ -1230,6 +1230,84 @@ TCL_CMD_HEADER( Rivet_VirtualFilenameCmd
 /*
  *-----------------------------------------------------------------------------
  *
+ * Rivet_Inspect --
+ *
+ *      Rivet configuration introspection. Command '::rivet::inspect' 
+ *      returns a dictionary of configuration data:
+ *
+ * Results:
+ *      A dictionary or parameter value
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+TCL_CMD_HEADER( Rivet_InspectCmd )
+{
+    rivet_interp_globals*   globals = Tcl_GetAssocData( interp, "rivet", NULL );
+    rivet_server_conf*      rsc = Rivet_GetConf(globals->r); 
+    int                     status = TCL_OK;
+
+    if (objc == 1)
+    {
+        Tcl_Obj* dictObj;
+
+        dictObj = Rivet_BuildConfDictionary(interp,rsc);
+        if (dictObj != NULL) {
+            Tcl_SetObjResult(interp,dictObj);
+            Tcl_DecrRefCount(dictObj);
+        } else {
+            status = TCL_ERROR;
+        }
+    }
+    else if (objc == 2)
+    {
+        Tcl_Obj* par_name = objv[1];
+
+        Tcl_IncrRefCount(par_name);
+        if (STRNEQU(Tcl_GetStringFromObj(par_name,NULL),"-all"))
+        {
+            Tcl_Obj* dictObj;
+
+            dictObj = Rivet_CurrentConfDict(interp,rsc);
+            if (dictObj == NULL)
+            {
+                status = TCL_ERROR;
+            }
+            else
+            {
+                Tcl_SetObjResult(interp,dictObj);            
+                Tcl_DecrRefCount(dictObj);
+            }
+        }
+        else
+        {
+            Tcl_Obj* par_value = NULL;
+
+            par_value = Rivet_ReadConfParameter(interp,rsc,par_name);
+            if (par_value == NULL)
+            {
+                status = TCL_ERROR;
+            }
+            else
+            {
+                Tcl_SetObjResult(interp,par_value);
+                Tcl_DecrRefCount(par_value);
+            }
+        }
+
+        Tcl_DecrRefCount(par_name);
+    }
+    else 
+    {
+        Tcl_WrongNumArgs( interp, 1, objv, "?server | dir | user? ?parameter name?" );
+        status = TCL_ERROR;
+    }
+    return status;
+}
+
+/*
+ *-----------------------------------------------------------------------------
+ *
  * Rivet_LogError --
  *
  *      Log an error from Rivet
@@ -1421,6 +1499,7 @@ Rivet_InitCore( Tcl_Interp *interp )
     RIVET_OBJ_CMD ("no_body",Rivet_NoBody);
     RIVET_OBJ_CMD ("env",Rivet_EnvCmd);
     RIVET_OBJ_CMD ("apache_log_error",Rivet_LogErrorCmd);
+    RIVET_OBJ_CMD ("inspect",Rivet_InspectCmd);
 
 #ifdef TESTPANIC
     RIVET_OBJ_CMD ("testpanic",TestpanicCmd);



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