tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rj...@apache.org
Subject svn commit: r550203 - in /tomcat/connectors/trunk/jk: native/apache-1.3/ native/apache-2.0/ native/common/ native/iis/ native/netscape/ native/nt_service/ xdocs/miscellaneous/
Date Sun, 24 Jun 2007 10:33:28 GMT
Author: rjung
Date: Sun Jun 24 03:33:27 2007
New Revision: 550203

URL: http://svn.apache.org/viewvc?view=rev&rev=550203
Log:
Common: Refactored and unified jk_map_read_prop* and jk_map_load_prop*
for all use cases.

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/native/common/jk_map.c
    tomcat/connectors/trunk/jk/native/common/jk_map.h
    tomcat/connectors/trunk/jk/native/common/jk_uri_worker_map.c
    tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c
    tomcat/connectors/trunk/jk/native/netscape/jk_nsapi_plugin.c
    tomcat/connectors/trunk/jk/native/nt_service/jk_nt_service.c
    tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.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=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-1.3/mod_jk.c Sun Jun 24 03:33:27 2007
@@ -1822,7 +1822,8 @@
         (jk_server_conf_t *) ap_get_module_config(s->module_config,
                                                   &jk_module);
 
-    if (jk_map_read_property(conf->worker_properties, line, 1, conf->log) == JK_FALSE)
+    if (jk_map_read_property(conf->worker_properties, line,
+                             JK_MAP_HANDLE_DUPLICATES, conf->log) == JK_FALSE)
         return ap_pstrcat(cmd->temp_pool, "Invalid JkWorkerProperty ", line, NULL);
 
     return NULL;
@@ -2628,7 +2629,8 @@
 */
 
     if ((conf->worker_file != NULL) &&
-        !jk_map_read_properties(init_map, conf->worker_file, NULL, 1, conf->log)) {
+        !jk_map_read_properties(init_map, conf->worker_file, NULL,
+                                JK_MAP_HANDLE_DUPLICATES, conf->log)) {
         jk_error_exit(APLOG_MARK, APLOG_EMERG | APLOG_NOERRNO, s, p,
                       "Error in reading worker properties from '%s'",
                       conf->worker_file);

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=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c (original)
+++ tomcat/connectors/trunk/jk/native/apache-2.0/mod_jk.c Sun Jun 24 03:33:27 2007
@@ -1859,7 +1859,8 @@
         return err_string;
     }
 
-    if (jk_map_read_property(conf->worker_properties, line, 1, conf->log) == JK_FALSE)
+    if (jk_map_read_property(conf->worker_properties, line,
+                             JK_MAP_HANDLE_DUPLICATES, conf->log) == JK_FALSE)
         return apr_pstrcat(cmd->temp_pool, "Invalid JkWorkerProperty ", line, NULL);
 
     return NULL;
@@ -2746,7 +2747,8 @@
     jk_set_worker_def_cache_size(mpm_threads);
 
     if ((conf->worker_file != NULL) &&
-        !jk_map_read_properties(init_map, conf->worker_file, NULL, 1, conf->log)) {
+        !jk_map_read_properties(init_map, conf->worker_file, NULL,
+                                JK_MAP_HANDLE_DUPLICATES, conf->log)) {
         ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s,
                      "Error in reading worker properties from '%s'",
                      conf->worker_file);

Modified: tomcat/connectors/trunk/jk/native/common/jk_map.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_map.c?view=diff&rev=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_map.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_map.c Sun Jun 24 03:33:27 2007
@@ -395,7 +395,66 @@
     return rc;
 }
 
-int jk_map_read_property(jk_map_t *m, const char *str, int allow_duplicates, jk_logger_t
*l)
+
+static int jk_map_validate_property(char *prp, jk_logger_t *l)
+{
+    int off = (int)strlen(prp) - (int)JK_MAP_REFERENCE_SZ;
+    /* check the worker properties */
+    if (off <= 0 || strncmp(&prp[off], JK_MAP_REFERENCE, JK_MAP_REFERENCE_SZ) ) {
+        if (!jk_is_valid_property(prp)) {
+            jk_log(l, JK_LOG_ERROR,
+                   "The attribute '%s' is not supported - please check"
+                   " the documentation for the supported attributes.",
+                   prp);
+            return JK_FALSE;
+        }
+        if (jk_is_deprecated_property(prp)) {
+            jk_log(l, JK_LOG_WARNING,
+                   "The attribute '%s' is deprecated - please check"
+                   " the documentation for the correct replacement.",
+                   prp);
+        }
+    }
+    return JK_TRUE;
+}
+
+static int jk_map_handle_duplicates(jk_map_t *m, const char *prp, char *v,
+                                    int treatment, jk_logger_t *l)
+{
+    const char *oldv = jk_map_get_string(m, prp, NULL);
+    if (oldv) {
+        if ((treatment == JK_MAP_HANDLE_DUPLICATES)
+            && jk_is_unique_property(prp) == JK_FALSE) {
+            char *tmpv = jk_pool_alloc(&m->p,
+                                       strlen(v) + strlen(oldv) + 3);
+            if (tmpv) {
+                char sep = '*';
+                if (jk_is_path_property(prp))
+                    sep = PATH_SEPERATOR;
+                else if (jk_is_cmd_line_property(prp))
+                    sep = ' ';
+                else if (jk_is_list_property(prp))
+                    sep = ',';
+                sprintf(tmpv, "%s%c%s", oldv, sep, v);
+            }
+            v = tmpv;
+            return JK_FALSE;
+        }
+        else {
+            jk_log(l, JK_LOG_WARNING,
+                   "Duplicate key '%s' detected - previous value '%s'"
+                   " will be overwritten with '%s'.",
+                   prp, oldv ? oldv : "(null)", v ? v : "(null)");
+            return JK_TRUE;
+        }
+    }
+    else {
+        return JK_TRUE;
+    }
+}
+
+int jk_map_read_property(jk_map_t *m, const char *str,
+                         int treatment, jk_logger_t *l)
 {
     int rc = JK_TRUE;
     char buf[LENGTH_OF_LINE + 1];
@@ -417,52 +476,15 @@
             trim(prp);
             trim(v);
             if (strlen(v) && strlen(prp)) {
-                const char *oldv;
-                int off = (int)strlen(prp) - (int)JK_MAP_REFERENCE_SZ;
-                /* check the worker properties */
-                if (off <= 0 || strncmp(&prp[off], JK_MAP_REFERENCE, JK_MAP_REFERENCE_SZ)
) {
-                    if (!jk_is_valid_property(prp)) {
-                        jk_log(l, JK_LOG_ERROR,
-                               "The attribute '%s' is not supported - please check"
-                               " the documentation for the supported attributes.",
-                               prp);
-                        return JK_FALSE;
-                    }
-                    if (jk_is_deprecated_property(prp)) {
-                        jk_log(l, JK_LOG_WARNING,
-                               "The attribute '%s' is deprecated - please check"
-                               " the documentation for the correct replacement.",
-                               prp);
-                    }
-                }
-                oldv = jk_map_get_string(m, prp, NULL);
-                v = jk_map_replace_properties(m, v);
-                if (oldv) {
-                    if (allow_duplicates && jk_is_unique_property(prp) == JK_FALSE)
{
-                        char *tmpv = jk_pool_alloc(&m->p,
-                                           strlen(v) + strlen(oldv) + 3);
-                        if (tmpv) {
-                            char sep = '*';
-                            if (jk_is_path_property(prp))
-                                sep = PATH_SEPERATOR;
-                            else if (jk_is_cmd_line_property(prp))
-                                sep = ' ';
-                            else if (jk_is_list_property(prp))
-                                sep = ',';
-                            sprintf(tmpv, "%s%c%s", oldv, sep, v);
-                        }
-                        v = tmpv;
-                    }
-                    else {
-                        jk_log(l, JK_LOG_WARNING,
-                               "Duplicate key '%s' detected - previous value '%s'"
-                               " will be overwritten with '%s'.",
-                               prp, oldv ? oldv : "(null)", v ? v : "(null)");
-                        v = jk_pool_strdup(&m->p, v);
-                    }
+                if (treatment == JK_MAP_HANDLE_RAW) {
+                    v = jk_pool_strdup(&m->p, v);
                 }
                 else {
-                    v = jk_pool_strdup(&m->p, v);
+                    if (jk_map_validate_property(prp, l) == JK_FALSE)
+                        return JK_FALSE;
+                    v = jk_map_replace_properties(m, v);
+                    if (jk_map_handle_duplicates(m, prp, v, treatment, l) == JK_TRUE)
+                        v = jk_pool_strdup(&m->p, v);
                 }
                 if (v) {
                     jk_map_put(m, prp, v, NULL);
@@ -478,7 +500,8 @@
 }
 
 
-int jk_map_read_properties(jk_map_t *m, const char *f, time_t *modified, int allow_duplicates,
jk_logger_t *l)
+int jk_map_read_properties(jk_map_t *m, const char *f, time_t *modified,
+                           int treatment, jk_logger_t *l)
 {
     int rc = JK_FALSE;
 
@@ -502,7 +525,7 @@
             while (NULL != (prp = fgets(buf, LENGTH_OF_LINE, fp))) {
                 trim_prp_comment(prp);
                 if (*prp) {
-                    if ((rc = jk_map_read_property(m, prp, allow_duplicates, l)) == JK_FALSE)
+                    if ((rc = jk_map_read_property(m, prp, treatment, l)) == JK_FALSE)
                         break;
                 }
             }
@@ -806,78 +829,3 @@
     }
     return rc;
 }
-
-int jk_map_load_property(jk_map_t *m, const char *str, jk_logger_t *l)
-{
-    int rc = JK_TRUE;
-    char buf[LENGTH_OF_LINE + 1];
-    char *prp = &buf[0];
-
-    if (strlen(str) > LENGTH_OF_LINE) {
-        jk_log(l, JK_LOG_WARNING,
-               "Line to long (%d > %d), ignoring entry",
-               strlen(str), LENGTH_OF_LINE);
-        return JK_FALSE;
-    }
-
-    strcpy(prp, str);
-    if (trim(prp)) {
-        char *v = strchr(prp, '=');
-        if (v) {
-            *v = '\0';
-            v++;
-            trim(prp);
-            trim(v);
-            if (strlen(v) && strlen(prp)) {
-                v = jk_pool_strdup(&m->p, v);
-                if (v) {
-                    jk_map_put(m, prp, v, NULL);
-                }
-                else {
-                    JK_LOG_NULL_PARAMS(l);
-                    rc = JK_FALSE;
-                }
-            }
-        }
-    }
-    return rc;
-}
-
-
-int jk_map_load_properties(jk_map_t *m, const char *f, time_t *modified, jk_logger_t *l)
-{
-    int rc = JK_FALSE;
-
-    if (m && f) {
-        FILE *fp;
-        struct stat statbuf;
-        if (jk_stat(f, &statbuf) == -1)
-            return JK_FALSE;
-#if defined(AS400) && !defined(AS400_UTF8)
-        fp = fopen(f, "r, o_ccsid=0");
-#else
-        fp = fopen(f, "r");
-#endif
-
-        if (fp) {
-            char buf[LENGTH_OF_LINE + 1];
-            char *prp;
-
-            rc = JK_TRUE;
-
-            while (NULL != (prp = fgets(buf, LENGTH_OF_LINE, fp))) {
-                trim_prp_comment(prp);
-                if (*prp) {
-                    if ((rc = jk_map_load_property(m, prp, l)) == JK_FALSE)
-                        break;
-                }
-            }
-            fclose(fp);
-            if (modified)
-                *modified = statbuf.st_mtime;
-        }
-    }
-
-    return rc;
-}
-

Modified: tomcat/connectors/trunk/jk/native/common/jk_map.h
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_map.h?view=diff&rev=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_map.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_map.h Sun Jun 24 03:33:27 2007
@@ -30,6 +30,9 @@
 {
 #endif                          /* __cplusplus */
 
+#define JK_MAP_HANDLE_NORMAL     0
+#define JK_MAP_HANDLE_DUPLICATES 1
+#define JK_MAP_HANDLE_RAW        2
 
 struct jk_map;
 typedef struct jk_map jk_map_t;
@@ -67,19 +70,15 @@
 
 int jk_map_put(jk_map_t *m, const char *name, const void *value, void **old);
 
-int jk_map_read_property(jk_map_t *m, const char *str, int allow_duplicates, jk_logger_t
*l);
+int jk_map_read_property(jk_map_t *m, const char *str, int treatment, jk_logger_t *l);
 
-int jk_map_read_properties(jk_map_t *m, const char *f, time_t *modified, int allow_duplicates,
jk_logger_t *l);
+int jk_map_read_properties(jk_map_t *m, const char *f, time_t *modified, int treatment, jk_logger_t
*l);
 
 int jk_map_size(jk_map_t *m);
 
 const char *jk_map_name_at(jk_map_t *m, int idex);
 
 void *jk_map_value_at(jk_map_t *m, int idex);
-
-int jk_map_load_property(jk_map_t *m, const char *str, jk_logger_t *l);
-
-int jk_map_load_properties(jk_map_t *m, const char *f, time_t *modified, jk_logger_t *l);
 
 /**
  *  Replace $(property) in value.

Modified: tomcat/connectors/trunk/jk/native/common/jk_uri_worker_map.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_uri_worker_map.c?view=diff&rev=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_uri_worker_map.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_uri_worker_map.c Sun Jun 24 03:33:27 2007
@@ -664,8 +664,8 @@
     jk_map_t *map;
 
     jk_map_alloc(&map);
-    if (jk_map_read_properties(map, uw_map->fname,
-                               &uw_map->modified, 0, l)) {
+    if (jk_map_read_properties(map, uw_map->fname, &uw_map->modified,
+                               JK_MAP_HANDLE_NORMAL, l)) {
         int i;
         if (JK_IS_DEBUG_LEVEL(l))
             jk_log(l, JK_LOG_DEBUG,

Modified: tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c?view=diff&rev=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c (original)
+++ tomcat/connectors/trunk/jk/native/iis/jk_isapi_plugin.c Sun Jun 24 03:33:27 2007
@@ -1691,7 +1691,8 @@
     }
 
     if (rewrite_rule_file[0] && jk_map_alloc(&rewrite_map)) {
-        if (jk_map_load_properties(rewrite_map, rewrite_rule_file, NULL, logger)) {
+        if (jk_map_read_properties(rewrite_map, rewrite_rule_file,
+                                   NULL, JK_MAP_HANDLE_RAW, logger)) {
             int i;
             if (JK_IS_DEBUG_LEVEL(logger)) {
                 jk_log(logger, JK_LOG_DEBUG, "Loaded rewrite rule file %s.",
@@ -1744,7 +1745,8 @@
     if (rc) {
         rc = JK_FALSE;
         if (jk_map_alloc(&workers_map)) {
-            if (jk_map_read_properties(workers_map, worker_file, NULL, 1, logger)) {
+            if (jk_map_read_properties(workers_map, worker_file, NULL,
+                                       JK_MAP_HANDLE_DUPLICATES, logger)) {
                 /* we add the URI->WORKER MAP since workers using AJP14 will feed it */
 
                 if (jk_map_resolve_references(workers_map, "worker.", 1, 1, logger) == JK_FALSE)
{
@@ -1816,7 +1818,8 @@
     jk_map_t *map = NULL;
 
     if (jk_map_alloc(&map)) {
-        if (jk_map_read_properties(map, ini_file_name, NULL, 1, logger)) {
+        if (jk_map_read_properties(map, ini_file_name, NULL,
+                                   JK_MAP_HANDLE_DUPLICATES, logger)) {
             using_ini_file = JK_TRUE;
             src = map;
         }

Modified: tomcat/connectors/trunk/jk/native/netscape/jk_nsapi_plugin.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/netscape/jk_nsapi_plugin.c?view=diff&rev=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/native/netscape/jk_nsapi_plugin.c (original)
+++ tomcat/connectors/trunk/jk/native/netscape/jk_nsapi_plugin.c Sun Jun 24 03:33:27 2007
@@ -265,7 +265,8 @@
     
     jk_shm_open(shm_file, JK_SHM_DEF_SIZE, logger);
     if (jk_map_alloc(&init_map)) {
-        if (jk_map_read_properties(init_map, worker_prp_file, NULL, 1, logger)) {
+        if (jk_map_read_properties(init_map, worker_prp_file, NULL,
+                                   JK_MAP_HANDLE_DUPLICATES, logger)) {
             int sleep_cnt;
             SYS_THREAD s;
 

Modified: tomcat/connectors/trunk/jk/native/nt_service/jk_nt_service.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/nt_service/jk_nt_service.c?view=diff&rev=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/native/nt_service/jk_nt_service.c (original)
+++ tomcat/connectors/trunk/jk/native/nt_service/jk_nt_service.c Sun Jun 24 03:33:27 2007
@@ -956,7 +956,8 @@
             jk_map_t *init_map;
             
             if(jk_map_alloc(&init_map)) {
-                if(jk_map_read_properties(init_map, prp_file, NULL, 1, NULL)) {
+                if(jk_map_read_properties(init_map, prp_file, NULL,
+                                          JK_MAP_HANDLE_DUPLICATES, NULL)) {
                     jk_tomcat_startup_data_t data;
                     jk_pool_t p;
                     jk_pool_atom_t buf[HUGE_POOL_SIZE];

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=550203&r1=550202&r2=550203
==============================================================================
--- tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml (original)
+++ tomcat/connectors/trunk/jk/xdocs/miscellaneous/changelog.xml Sun Jun 24 03:33:27 2007
@@ -28,6 +28,10 @@
   <subsection name="Native">
     <changelog>
       <update>
+      Common: Refactored and unified jk_map_read_prop* and jk_map_load_prop*
+      for all use cases. (rjung)
+      </update>
+      <update>
       Common/Apache/IIS/Netscape: Add an option to check decoded URLs for
       potentially malicious constructions. (rjung)
       </update>



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


Mime
View raw message