You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2007/02/19 13:01:43 UTC

svn commit: r509173 - in /tomcat/connectors/trunk/jk: native/apache-1.3/mod_jk.c native/apache-2.0/mod_jk.c xdocs/miscellaneous/changelog.xml xdocs/reference/apache.xml xdocs/webserver_howto/apache.xml

Author: rjung
Date: Mon Feb 19 04:01:40 2007
New Revision: 509173

URL: http://svn.apache.org/viewvc?view=rev&rev=509173
Log:
Change semantics of empty defaults for JkEnvVar variables.

Modified:
    tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
    tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c
    tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml
    tomcat/connectors/trunk/jk/xdocs/reference/apache.xml
    tomcat/connectors/trunk/jk/xdocs/webserver_howto/apache.xml

Modified: tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c?view=diff&rev=509173&r1=509172&r2=509173
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c Mon Feb 19 04:01:40 2007
@@ -102,6 +102,16 @@
 #endif
 
 /*
+ * Environment variable forward object
+ */
+typedef struct
+{
+    int has_default;
+    char *name;
+    char *value;
+} envvar_item;
+
+/*
  * Configuration object for the mod_jk module.
  */
 typedef struct
@@ -169,6 +179,8 @@
      */
     int envvars_in_use;
     table *envvars;
+    table *envvars_def;
+    array_header *envvar_items;
 
     server_rec *s;
 } jk_server_conf_t;
@@ -655,25 +667,33 @@
         }
 
         if (conf->envvars_in_use) {
-            array_header *t = ap_table_elts(conf->envvars);
+            const array_header *t = conf->envvar_items;
             if (t && t->nelts) {
                 int i;
-                table_entry *elts = (table_entry *) t->elts;
+                int j = 0;
+                envvar_item *elts = (envvar_item *) t->elts;
                 s->attributes_names =
                     ap_palloc(r->pool, sizeof(char *) * t->nelts);
                 s->attributes_values =
                     ap_palloc(r->pool, sizeof(char *) * t->nelts);
 
                 for (i = 0; i < t->nelts; i++) {
-                    s->attributes_names[i] = elts[i].key;
-                    s->attributes_values[i] =
-                        (char *)ap_table_get(r->subprocess_env, elts[i].key);
-                    if (!s->attributes_values[i]) {
-                        s->attributes_values[i] = elts[i].val;
+                    s->attributes_names[i - j] = elts[i].name;
+                    s->attributes_values[i - j] =
+                        (char *)ap_table_get(r->subprocess_env, elts[i].name);
+                    if (!s->attributes_values[i - j]) {
+                        if (elts[i].has_default) {
+                            s->attributes_values[i - j] = elts[i].value;
+                        }
+                        else {
+                            s->attributes_values[i - j] = "";
+                            s->attributes_names[i - j] = "";
+                            j++;
+                        }
                     }
                 }
 
-                s->num_attributes = t->nelts;
+                s->num_attributes = t->nelts - j;
             }
         }
     }
@@ -1682,9 +1702,10 @@
 
 
     /* env_name is mandatory, default_value is optional.
-     * No value means set the variable to an empty string.
+     * No value means send the attribute only, if the env var is set during runtime.
      */
     ap_table_setn(conf->envvars, env_name, default_value ? default_value : "");
+    ap_table_setn(conf->envvars_def, env_name, default_value ? "1" : "0");
 
     return NULL;
 }
@@ -2139,6 +2160,8 @@
 
     c->envvars_in_use = JK_FALSE;
     c->envvars = ap_make_table(p, 0);
+    c->envvars_def = ap_make_table(p, 0);
+    c->envvar_items = ap_make_array(p, 0, sizeof(envvar_item));
 
     c->s = s;
     jk_map_put(c->worker_properties, "ServerRoot", ap_server_root, NULL);
@@ -2215,6 +2238,16 @@
                 }
             }
         }
+        arr = ap_table_elts(base->envvars_def);
+        if (arr) {
+            overrides->envvars_in_use = JK_TRUE;
+            elts = (const table_entry *)arr->elts;
+            for (i = 0; i < arr->nelts; ++i) {
+                if (!ap_table_get(overrides->envvars_def, elts[i].key)) {
+                    ap_table_setn(overrides->envvars_def, elts[i].key, elts[i].val);
+                }
+            }
+        }
     }
 
     if (overrides->mount_file_reload == JK_UNSET)
@@ -2395,6 +2428,34 @@
                                  "JkRequestLogFormat format array NULL");
             }
             sconf->options &= ~sconf->exclude_options;
+            if (sconf->envvars_in_use) {
+                int i;
+                const array_header *arr;
+                const table_entry *elts;
+                envvar_item *item;
+                const char *envvar_def;
+
+                arr = ap_table_elts(sconf->envvars);
+                if (arr) {
+                    elts = (const table_entry *)arr->elts;
+                    for (i = 0; i < arr->nelts; ++i) {
+                        item = (envvar_item *)ap_push_array(sconf->envvar_items);
+                        if (!item)
+                            jk_error_exit(APLOG_MARK, APLOG_EMERG, srv,
+                                          p, "Memory error");
+                        item->name = elts[i].key;
+                        envvar_def = ap_table_get(sconf->envvars_def, elts[i].key);
+                        if (envvar_def && !strcmp("1", envvar_def) ) {
+                            item->value = elts[i].val;
+                            item->has_default = 1;
+                        }
+                        else {
+                            item->value = "";
+                            item->has_default = 0;
+                        }
+                    }
+                }
+            }
         }
     }
 

Modified: tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c?view=diff&rev=509173&r1=509172&r2=509173
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c Mon Feb 19 04:01:40 2007
@@ -136,6 +136,19 @@
 /* module MODULE_VAR_EXPORT jk_module; */
 AP_MODULE_DECLARE_DATA module jk_module;
 
+/*
+ * Environment variable forward object
+ */
+typedef struct
+{
+    int has_default;
+    char *name;
+    char *value;
+} envvar_item;
+
+/*
+ * Configuration object for the mod_jk module.
+ */
 typedef struct
 {
 
@@ -203,6 +216,8 @@
      */
     int envvars_in_use;
     apr_table_t *envvars;
+    apr_table_t *envvars_def;
+    apr_array_header_t *envvar_items;
 
     server_rec *s;
 } jk_server_conf_t;
@@ -683,25 +698,33 @@
         }
 
         if (conf->envvars_in_use) {
-            const apr_array_header_t *t = apr_table_elts(conf->envvars);
+            const apr_array_header_t *t = conf->envvar_items;
             if (t && t->nelts) {
                 int i;
-                apr_table_entry_t *elts = (apr_table_entry_t *) t->elts;
+                int j = 0;
+                envvar_item *elts = (envvar_item *) t->elts;
                 s->attributes_names = apr_palloc(r->pool,
                                                  sizeof(char *) * t->nelts);
                 s->attributes_values = apr_palloc(r->pool,
                                                   sizeof(char *) * t->nelts);
 
                 for (i = 0; i < t->nelts; i++) {
-                    s->attributes_names[i] = elts[i].key;
-                    s->attributes_values[i] =
-                        (char *)apr_table_get(r->subprocess_env, elts[i].key);
-                    if (!s->attributes_values[i]) {
-                        s->attributes_values[i] = elts[i].val;
+                    s->attributes_names[i - j] = elts[i].name;
+                    s->attributes_values[i - j] =
+                        (char *)apr_table_get(r->subprocess_env, elts[i].name);
+                    if (!s->attributes_values[i - j]) {
+                        if (elts[i].has_default) {
+                            s->attributes_values[i - j] = elts[i].value;
+                        }
+                        else {
+                            s->attributes_values[i - j] = "";
+                            s->attributes_names[i - j] = "";
+                            j++;
+                        }
                     }
                 }
 
-                s->num_attributes = t->nelts;
+                s->num_attributes = t->nelts - j;
             }
         }
     }
@@ -1716,9 +1739,10 @@
     conf->envvars_in_use = JK_TRUE;
 
     /* env_name is mandatory, default_value is optional.
-     * No value means set the variable to an empty string.
+     * No value means send the attribute only, if the env var is set during runtime.
      */
     apr_table_setn(conf->envvars, env_name, default_value ? default_value : "");
+    apr_table_setn(conf->envvars_def, env_name, default_value ? "1" : "0");
 
     return NULL;
 }
@@ -2263,6 +2287,8 @@
 
     c->envvars_in_use = JK_FALSE;
     c->envvars = apr_table_make(p, 0);
+    c->envvars_def = apr_table_make(p, 0);
+    c->envvar_items = apr_array_make(p, 0, sizeof(envvar_item));
 
     c->s = s;
     jk_map_put(c->worker_properties, "ServerRoot", ap_server_root, NULL);
@@ -2344,6 +2370,16 @@
                 }
             }
         }
+        arr = apr_table_elts(base->envvars_def);
+        if (arr) {
+            overrides->envvars_in_use = JK_TRUE;
+            elts = (const apr_table_entry_t *)arr->elts;
+            for (i = 0; i < arr->nelts; ++i) {
+                if (!apr_table_get(overrides->envvars_def, elts[i].key)) {
+                    apr_table_setn(overrides->envvars_def, elts[i].key, elts[i].val);
+                }
+            }
+        }
     }
 
     if (overrides->mount_file_reload == JK_UNSET)
@@ -2680,6 +2716,33 @@
                                          "JkRequestLogFormat format array NULL");
                     }
                     sconf->options &= ~sconf->exclude_options;
+                    if (sconf->envvars_in_use) {
+                        int i;
+                        const apr_array_header_t *arr;
+                        const apr_table_entry_t *elts;
+                        envvar_item *item;
+                        const char *envvar_def;
+
+                        arr = apr_table_elts(sconf->envvars);
+                        if (arr) {
+                            elts = (const apr_table_entry_t *)arr->elts;
+                            for (i = 0; i < arr->nelts; ++i) {
+                                item = (envvar_item *)apr_array_push(sconf->envvar_items);
+                                if (!item)
+                                    return HTTP_INTERNAL_SERVER_ERROR;
+                                item->name = elts[i].key;
+                                envvar_def = apr_table_get(sconf->envvars_def, elts[i].key);
+                                if (envvar_def && !strcmp("1", envvar_def) ) {
+                                    item->value = elts[i].val;
+                                    item->has_default = 1;
+                                }
+                                else {
+                                    item->value = "";
+                                    item->has_default = 0;
+                                }
+                            }
+                        }
+                    }
                 }
             }
             init_jk(pconf, conf, s);

Modified: tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml?view=diff&rev=509173&r1=509172&r2=509173
==============================================================================
--- tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml (original)
+++ tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml Mon Feb 19 04:01:40 2007
@@ -26,6 +26,14 @@
   <br />
   <subsection name="Native">
     <changelog>
+      <add>
+      Change semantics of empty defaults for JkEnvVar variables.
+      Until 1.2.19: not allowed. In 1.2.20: send variables as empty strings, if
+      neither set to non empty in config, nor during runtime.
+      Starting with 1.2.21: If config has no second argument only send
+      variable if set (even when set to empty string) during runtime.
+      Allows good combination with condition attribute in tomcat access log. (rjung)
+      </add>
       <fix>
         <bug>41610</bug>: Fix incorrect detection of missing Content-Length
         header leading to duplicate headers. Contributed by Boris Maras. (rjung)

Modified: tomcat/connectors/trunk/jk/xdocs/reference/apache.xml
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/xdocs/reference/apache.xml?view=diff&rev=509173&r1=509172&r2=509173
==============================================================================
--- tomcat/connectors/trunk/jk/xdocs/reference/apache.xml (original)
+++ tomcat/connectors/trunk/jk/xdocs/reference/apache.xml Mon Feb 19 04:01:40 2007
@@ -209,12 +209,16 @@
 <attribute name="JkEnvVar" required="false"><p>
 Adds a name and an optional default value of environment variable
 that should be sent to servlet-engine as a request attribute.
-If the default value is not given explicitely, the empty string
-will be used as a default.
+If the default value is not given explicitely, the variable
+will only be send, if it is set during runtime.
 <br/>
 This directive can be used multiple times per virtual server.
 <br/>
 The default is empty, so no additional variables will be sent.
+<br/>
+Empty default values are supported since version 1.2.20.
+Not sending variables with empty defaults and empty runtime value
+has been introduced in version 1.2.21.
 </p></attribute>
 
 
@@ -239,6 +243,7 @@
 <br/>
 <br/>
 </p>
+
 </subsection>
 
 <subsection name="Logging">
@@ -571,8 +576,8 @@
 The directive <b>JkEnvVar</b> allows you to forward environment variables from Apache server to Tomcat engine.
 The variables can be retrieved on the Tomcat side as request attributes.
 You can add a default value as a second parameter to the directive.
-If the default value is not given explicitely, the empty string
-will be used as a default.
+If the default value is not given explicitely, the variable
+will only be send, if it is set during runtime.
 <br/>
 <br/>
 The variables are inherited from the global server to virtual hosts.
@@ -721,6 +726,8 @@
 <p>
 There is no way to delete entries by dynamic reloading, but you can disable or
 exclude mappings.
+<br/>
+<br/>
 </p>
 
 </subsection>

Modified: tomcat/connectors/trunk/jk/xdocs/webserver_howto/apache.xml
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/xdocs/webserver_howto/apache.xml?view=diff&rev=509173&r1=509172&r2=509173
==============================================================================
--- tomcat/connectors/trunk/jk/xdocs/webserver_howto/apache.xml (original)
+++ tomcat/connectors/trunk/jk/xdocs/webserver_howto/apache.xml Mon Feb 19 04:01:40 2007
@@ -628,8 +628,8 @@
 The directive <b>JkEnvVar</b> allows you to forward environment variables from Apache server to Tomcat engine.
 The variables can be retrieved on the Tomcat side as request attributes.
 You can add a default value as a second parameter to the directive.
-If the default value is not given explicitely, the empty string
-will be used as a default.
+If the default value is not given explicitely, the variable
+will only be send, if it is set during runtime.
 <br/>
 <br/>
 The variables are inherited from the global server to virtual hosts.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r509173 - in /tomcat/connectors/trunk/jk: native/apache-1.3/mod_jk.c native/apache-2.0/mod_jk.c xdocs/miscellaneous/changelog.xml xdocs/reference/apache.xml xdocs/webserver_howto/apache.xml

Posted by Rainer Jung <ra...@kippdata.de>.
Hi Mladen,

until 1.2.19 JkEnvVar  would throw apache configuration error, if only 
called with one argument. The behaviour of 1.2.20 and 1.2.21 is the same 
as before, if you use a second argument.

It was only in 1.2.20, that we introduced the possibility to omit the 
second argument, so give no default value.

In this case, if during runtime the variable gets set, again there is no 
change in behaviour.

The only change is, if you use a config that was syntactically wrong 
before 1.2.20 and your variable does not get set during runtime. Then 
1.2.20 would forward an empty string, and 1.2.21 will not forward the 
variable. I changed the documentation accordingly. Somehow the 
additional case in 1.2.20 was implemented with wrong behaviour by me in 
December.

Why is that change interesting?

tomcat has an attribute "condition" for the access log, that allows to 
not log a request, whenever the given request attribute is set. 
Unfortunately the implementation checks for the attribute being set, an 
empty string counts as set. It would be nice, if one could use 
mod_setenvif, to set the attribute e.g. for the probing requests from 
the external load balancers, systems management etc. and thus keep them 
seperate in the tomcat logs.

One is tempted to think, that one could remove the empty attribute in a 
tomcat servlet filter, but unfortunately a servlet filter can not delete 
attributes coming via mod_jk (which might be a bug in itself, but is 
much more difficult to fix).

By not sending the variable if it has no default and doesn't get set 
during runtime, JkEnvVar and "condition" are able to smoothly interoperate.

Regards,

Rainer


Mladen Turk wrote:
> rjung@apache.org wrote:
>>  
>>      /* env_name is mandatory, default_value is optional.
>> -     * No value means set the variable to an empty string.
>> +     * No value means send the attribute only, if the env var is set 
>> during runtime.
>>       */
> 
> Think this will break any existing configuration.
> Something like that cannot be part of the 1.2.x branch thought.
> 
>>  The directive <b>JkEnvVar</b> allows you to forward environment 
>> variables from Apache server to Tomcat engine.
>>  The variables can be retrieved on the Tomcat side as request attributes.
>>  You can add a default value as a second parameter to the directive.
>> -If the default value is not given explicitely, the empty string
>> -will be used as a default.
>> +If the default value is not given explicitely, the variable
>> +will only be send, if it is set during runtime.
> 
> What will be send in this cases:
> JkEnvVar FOO1
> JkEnvVar FOO2 BAR
> 
> 
> Regards,
> Mladen.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r509173 - in /tomcat/connectors/trunk/jk: native/apache-1.3/mod_jk.c native/apache-2.0/mod_jk.c xdocs/miscellaneous/changelog.xml xdocs/reference/apache.xml xdocs/webserver_howto/apache.xml

Posted by Rainer Jung <ra...@kippdata.de>.
Please read my reply describing the detailed consequences of this change.

The behaviour only changes n a corner case, which only exists since our
latest version 1.2.20, wihch is not very old. everything that was
possible with JkEnvVar before 1.2.20 neither changed in 1.2.20 not due
to this patch.

Regards,

Rainer

Jim Jagielski schrieb:
> 
> On Feb 19, 2007, at 9:44 AM, Mladen Turk wrote:
> 
>> rjung@apache.org wrote:
>>>       /* env_name is mandatory, default_value is optional.
>>> -     * No value means set the variable to an empty string.
>>> +     * No value means send the attribute only, if the env var is set
>>> during runtime.
>>>       */
>>
>> Think this will break any existing configuration.
>> Something like that cannot be part of the 1.2.x branch thought.
>>
> 
> If it does break existing configs, and therefore
> introduces a regression, then -1 on the patch.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r509173 - in /tomcat/connectors/trunk/jk: native/apache-1.3/mod_jk.c native/apache-2.0/mod_jk.c xdocs/miscellaneous/changelog.xml xdocs/reference/apache.xml xdocs/webserver_howto/apache.xml

Posted by Jim Jagielski <ji...@jaguNET.com>.
On Feb 19, 2007, at 9:44 AM, Mladen Turk wrote:

> rjung@apache.org wrote:
>>       /* env_name is mandatory, default_value is optional.
>> -     * No value means set the variable to an empty string.
>> +     * No value means send the attribute only, if the env var is  
>> set during runtime.
>>       */
>
> Think this will break any existing configuration.
> Something like that cannot be part of the 1.2.x branch thought.
>

If it does break existing configs, and therefore
introduces a regression, then -1 on the patch.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r509173 - in /tomcat/connectors/trunk/jk: native/apache-1.3/mod_jk.c native/apache-2.0/mod_jk.c xdocs/miscellaneous/changelog.xml xdocs/reference/apache.xml xdocs/webserver_howto/apache.xml

Posted by Mladen Turk <mt...@apache.org>.
rjung@apache.org wrote:
>  
>      /* env_name is mandatory, default_value is optional.
> -     * No value means set the variable to an empty string.
> +     * No value means send the attribute only, if the env var is set during runtime.
>       */

Think this will break any existing configuration.
Something like that cannot be part of the 1.2.x branch thought.

>  The directive <b>JkEnvVar</b> allows you to forward environment variables from Apache server to Tomcat engine.
>  The variables can be retrieved on the Tomcat side as request attributes.
>  You can add a default value as a second parameter to the directive.
> -If the default value is not given explicitely, the empty string
> -will be used as a default.
> +If the default value is not given explicitely, the variable
> +will only be send, if it is set during runtime.

What will be send in this cases:
JkEnvVar FOO1
JkEnvVar FOO2 BAR


Regards,
Mladen.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org