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 2021/11/01 23:23:37 UTC
[tcl-rivet] branch master updated: add comments to new functions
introduced for the environment variables resolution
This is an automated email from the ASF dual-hosted git repository.
mxmanghi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git
The following commit(s) were added to refs/heads/master by this push:
new beedc59 add comments to new functions introduced for the environment variables resolution
beedc59 is described below
commit beedc59a670710e7e6fd8baebfe4abe49db7e939
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Tue Nov 2 00:23:23 2021 +0100
add comments to new functions introduced for the environment variables resolution
---
ChangeLog | 38 +++++++++++---------
doc/xml/commands.xml | 10 +++---
src/mod_rivet_ng/TclWebapache.c | 79 ++++++++++++++++++++++++++++++++++++++---
3 files changed, 100 insertions(+), 27 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 2a4beef..de0035c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2021-11-01 Massimo Manghi <mx...@apache.org>
+ * src/mod_rivet_ng/Tclwebapache.c: expanded comments to newly
+ introduced functions
+
2021-10-25 Massimo Manghi <mx...@apache.org>
* src/mod_rivet_ng/Tclwebapache.c: extended comments
* src/rivet.h: new macro MINSTRLEN
@@ -93,37 +97,37 @@
to test multiple uploads)
2019-12-12 Massimo Manghi <mx...@apache.org>
- * src/mod_rivet_ng/apache_config.c: copying also upload_files_to_var in
- Rivet_MergeConfig
+ * src/mod_rivet_ng/apache_config.c: copying also upload_files_to_var in
+ Rivet_MergeConfig
2019-12-06 Massimo Manghi <mx...@apache.org>
- * src/mod_rivet_ng/rivetCore.c: expanded error info data in Rivet_Upload
- * doc/rivet.css: new color scheme for docbook manual
+ * src/mod_rivet_ng/rivetCore.c: expanded error info data in Rivet_Upload
+ * doc/rivet.css: new color scheme for docbook manual
2019-12-04 Massimo Manghi <mx...@apache.org>
- * src/mod_rivet_ng/rivetCore.c: new branch uploadcmdfix with improved
- argument checking in Rivet_Upload that was the cause of random crashes
+ * src/mod_rivet_ng/rivetCore.c: new branch uploadcmdfix with improved
+ argument checking in Rivet_Upload that was the cause of random crashes
2019-11-29 Brice Hamon <bh...@apache.org>
- * src/mod_rivet_ng/mod_rivet_cache.h: added RivetCache_DeleteEntry
- * src/mod_rivet_ng/mod_rivet_cache.c:
- * src/mod_rivet_ng/rivetCore.c: fixed crash when rvt file not readable
+ * src/mod_rivet_ng/mod_rivet_cache.h: added RivetCache_DeleteEntry
+ * src/mod_rivet_ng/mod_rivet_cache.c:
+ * src/mod_rivet_ng/rivetCore.c: fixed crash when rvt file not readable
2019-10-13 Massimo Manghi <mx...@apache.org>
- * doc/xml/directives.xml: configuration directives table expanded
- * doc/examples/
+ * doc/xml/directives.xml: configuration directives table expanded
+ * doc/examples/
2019-09-30 Massimo Manghi <mx...@apache.org>
- * src/mod_rivet_ng/rivetCore.c: revised argument checking
+ * src/mod_rivet_ng/rivetCore.c: revised argument checking
2019-09-29 Massimo Manghi <mx...@apache.org>
- * doc/xml/commands.xml: Completed manual page for command ::rivet::thread_id
- * src/mod_rivet_ng/rivetCore.c: Rivet_GetThreadId rewritten. Now the
- command accepts an optional argument to select decimal or hexadecimal (default)
- output
+ * doc/xml/commands.xml: Completed manual page for command ::rivet::thread_id
+ * src/mod_rivet_ng/rivetCore.c: Rivet_GetThreadId rewritten. Now the
+ command accepts an optional argument to select decimal or hexadecimal (default)
+ output
2019-08-05 Massimo Manghi <mx...@apache.org>
- * doc/xml/directives.xml: Documenting SingleThreadExit directive
+ * doc/xml/directives.xml: Documenting SingleThreadExit directive
2019-07-27 Massimo Manghi <mx...@apache.org>
* doc/xml/commands.xml,src/mod_rivet_ng/rivetCore.c: Add ::rivet::thread_id
diff --git a/doc/xml/commands.xml b/doc/xml/commands.xml
index 8e1c3e0..d25fa50 100644
--- a/doc/xml/commands.xml
+++ b/doc/xml/commands.xml
@@ -509,12 +509,12 @@
<refsect1>
<title>Description</title>
<para>
- If just one environmental variable is needed <command>::rivet::env</command>
- returns the variable value or an empty string if the environment
+ <command>::rivet::env</command> resolves a single environment
+ variable and returns its value or an empty string if the environment
variable name in the argument is not defined.
- This command has some performance advantages with respect to
- <command>::rivet::load_env</command> since it avoids the
- loading of the whole set of environment and header variables.
+ This command is the recommended way to resolve an environment
+ variable leaving <command>::rivet::load_env</command> to debugging
+ and development operations.
</para>
</refsect1>
</refentry>
diff --git a/src/mod_rivet_ng/TclWebapache.c b/src/mod_rivet_ng/TclWebapache.c
index 4d009c9..82148a6 100644
--- a/src/mod_rivet_ng/TclWebapache.c
+++ b/src/mod_rivet_ng/TclWebapache.c
@@ -53,7 +53,7 @@ extern mod_rivet_globals* module_globals;
#define ENV_COMMON_VARS(env) env |= ENV_COMMON_VARS_M;
#define ENV_CGI_VARS(env) env |= ENV_CGI_VARS_M;
#define ENV_VARS(env) env |= ENV_VARS_M;
-
+#define ENV_LOADED(env) env |= ENV_COMMON_VARS_M | ENV_CGI_VARS_M | ENV_VARS_M;
#define ENV_IS_LOADED(env) (env == (ENV_COMMON_VARS_M | ENV_CGI_VARS_M | ENV_VARS_M))
#define ENV_COMMON_VARS_LOADED(env) (env & ENV_COMMON_VARS_M) != 0
#define ENV_CGI_VARS_LOADED(env) (env & ENV_CGI_VARS_M) != 0
@@ -459,7 +459,13 @@ TclWeb_VarNumber(Tcl_Obj *result, int source, TclWebRequest *req)
}
/* These 2 array must be aligned and a one-to-one correspondence preserved
- * The enum include_vars_idx must be terminated by 'invalid_env_var'
+ * The enum include_vars_idx *must* be terminated by 'invalid_env_var'
+ * Adding a new env variable requires
+ * + the name of the variable be listed in include_env_vars
+ * + a new value in the enumerator include_vars_idx must be added in the
+ * corresponding position of the variable names array
+ * + the switch construct in function TclWeb_SelectEnvIncludeVar must
+ * be expanded to handle the new case identified by the new enumerator value
*/
static const char* include_env_vars[] =
@@ -474,6 +480,27 @@ enum include_vars_idx {
invalid_env_var
};
+/* -- TclWeb_SelectEnvIncludeVar
+ *
+ * Depending on the value idx of the enumerator a method is selected
+ * to return a string of a specific environment variable methods
+ * Adding new environment variables need new cases of the switch
+ * construct to be added, provided the data can be obtained from
+ * the rivet_thread_private structure
+ *
+ * Arguments:
+ *
+ * + rivet_thread_private* private: pointer to a thread private data structure
+ * + int idx: an integer value listed in the enumerator include_vars_idx
+ *
+ * Results:
+ *
+ * A character string pointer to the value of the environment variable or
+ * NULL if the enumerator value idx was invalid or resolving the environment
+ * variable was impossible
+ *
+ */
+
static char*
TclWeb_SelectEnvIncludeVar (rivet_thread_private* private,int idx)
{
@@ -591,12 +618,10 @@ TclWeb_InitEnvVars (rivet_thread_private* private)
if (!ENV_CGI_VARS_LOADED(req->environment_set))
{
ap_add_cgi_vars(req->req);
- ENV_CGI_VARS(req->environment_set);
}
if (!ENV_COMMON_VARS_LOADED(req->environment_set))
{
ap_add_common_vars(req->req);
- ENV_COMMON_VARS(req->environment_set)
}
/* Loading into 'table' the include vars */
@@ -614,11 +639,24 @@ TclWeb_InitEnvVars (rivet_thread_private* private)
{
apr_table_set(table,include_env_vars[idx],TclWeb_SelectEnvIncludeVar(private,idx));
}
- ENV_VARS(req->environment_set)
}
+ ENV_LOADED(req->environment_set)
}
+/* -- TclWeb_GetEnvIncludeVar
+ *
+ * the environment variable named in key is searched among the include
+ * variables and then resolved by calling TclWeb_SelectEnvIncludeVar
+ *
+ * Result:
+ *
+ * a character string pointer to the environment variable value or
+ * NULL if the environment variable name in invalid or the variable
+ * could not be resolved
+ *
+ */
+
static char*
TclWeb_GetEnvIncludeVar (rivet_thread_private* private,char* key)
{
@@ -940,6 +978,31 @@ int TclWeb_UploadNames(TclWebRequest *req)
return TCL_OK;
}
+/*
+ * -- TclWeb_GetEnvVar
+ *
+ * basically is the core of the ::rivet::env rivet command. The argument to
+ * the command is stored in 'key' and the function starts a search in various
+ * tables following the following order
+ *
+ * + though undocumented in the manual the first table checked is HTTP
+ * headers table. ::rivet::env is actually like ::rivet::headers but for
+ * the *request_rec->headers_in table
+ * + the common CGI variables table is checked
+ * + the CGI 1.1 headers table is checked
+ * + the include variables list is checked calling TclWeb_GetEnvIncludeVar
+ *
+ * Arguments:
+ *
+ * - key: a string with the environment variable name
+ *
+ * Results:
+ *
+ * - a string pointer to the string with the variable translation or
+ * NULL if the environment variable is not found
+ *
+ */
+
char *
TclWeb_GetEnvVar(rivet_thread_private* private,char *key)
{
@@ -970,6 +1033,12 @@ TclWeb_GetEnvVar(rivet_thread_private* private,char *key)
}
val = (char *)apr_table_get(req->req->subprocess_env,key);
if (val) { return val; }
+
+ /* If everything failed we assumed the variable is one of
+ * the 'include variables' and we try to resolve it calling
+ * TclWeb_GetEnvIncludeVar, which returns NULL if the variable
+ * is undefined */
+
return TclWeb_GetEnvIncludeVar(private,key);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org