[mapserver-commits] r12769 - in trunk/mapserver/mapcache: include
src
svn at osgeo.org
svn at osgeo.org
Tue Nov 15 05:18:11 EST 2011
Author: tbonfort
Date: 2011-11-15 02:18:11 -0800 (Tue, 15 Nov 2011)
New Revision: 12769
Modified:
trunk/mapserver/mapcache/include/mapcache.h
trunk/mapserver/mapcache/src/cache_disk.c
trunk/mapserver/mapcache/src/cache_memcache.c
trunk/mapserver/mapcache/src/util.c
Log:
add a sanitization function when using dimensions in disk and memcache cache.
change the directory structure and memcache key used in case of dimensions (skip the key) to shorten the filename/memcache key.
Modified: trunk/mapserver/mapcache/include/mapcache.h
===================================================================
--- trunk/mapserver/mapcache/include/mapcache.h 2011-11-14 10:13:31 UTC (rev 12768)
+++ trunk/mapserver/mapcache/include/mapcache.h 2011-11-15 10:18:11 UTC (rev 12769)
@@ -1305,6 +1305,16 @@
char *mapcache_util_str_replace(apr_pool_t *pool, const char *string, const char *substr,
const char *replacement );
+/**
+ * \brief replace dangerous characters in string
+ * \param str the string that must be tested/replaced
+ * \param from array of chars that must be replaced
+ * \param to char that will replace a matched entry
+ * \return the original string if no matches were found, or the sanitized
+ * string allocated from the given pool
+ */
+const char* mapcache_util_str_sanitize(apr_pool_t *pool, const char *str, const char* from, char to);
+
/**\defgroup imageio Image IO */
/** @{ */
Modified: trunk/mapserver/mapcache/src/cache_disk.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_disk.c 2011-11-14 10:13:31 UTC (rev 12768)
+++ trunk/mapserver/mapcache/src/cache_disk.c 2011-11-15 10:18:11 UTC (rev 12769)
@@ -54,6 +54,7 @@
ctx->set_error(ctx,500, "failed to allocate blank tile key");
}
}
+
/**
* \brief return filename for given tile
*
@@ -76,16 +77,8 @@
int i = elts->nelts;
while(i--) {
apr_table_entry_t *entry = &(APR_ARRAY_IDX(elts,i,apr_table_entry_t));
- char *dimval = apr_pstrdup(ctx->pool,entry->val);
- char *iter = dimval;
- while(*iter) {
- /* replace dangerous characters by '#' */
- if(*iter == '.' || *iter == '/') {
- *iter = '#';
- }
- iter++;
- }
- start = apr_pstrcat(ctx->pool,start,"/",entry->key,"/",dimval,NULL);
+ const char *dimval = mapcache_util_str_sanitize(ctx->pool,entry->val,"/.",'#');
+ start = apr_pstrcat(ctx->pool,start,"/",dimval,NULL);
}
}
*path = apr_psprintf(ctx->pool,"%s/%02d/%03d/%03d/%03d/%03d/%03d/%03d.%s",
Modified: trunk/mapserver/mapcache/src/cache_memcache.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_memcache.c 2011-11-14 10:13:31 UTC (rev 12768)
+++ trunk/mapserver/mapcache/src/cache_memcache.c 2011-11-15 10:18:11 UTC (rev 12769)
@@ -52,18 +52,15 @@
int i = elts->nelts;
while(i--) {
apr_table_entry_t *entry = &(APR_ARRAY_IDX(elts,i,apr_table_entry_t));
- start = apr_pstrcat(ctx->pool,start,"/",entry->key,"/",entry->val,NULL);
+ const char *dimval = mapcache_util_str_sanitize(ctx->pool,entry->val," \r\n\t\f\e\a\b",'#');
+ start = apr_pstrcat(ctx->pool,start,"/",dimval,NULL);
}
}
- *path = apr_psprintf(ctx->pool,"%s/%02d/%03d/%03d/%03d/%03d/%03d/%03d.%s",
+ *path = apr_psprintf(ctx->pool,"%s/%d/%d/%d.%s",
start,
tile->z,
- tile->x / 1000000,
- (tile->x / 1000) % 1000,
- tile->x % 1000,
- tile->y / 1000000,
- (tile->y / 1000) % 1000,
- tile->y % 1000,
+ tile->x,
+ tile->y,
tile->tileset->format?tile->tileset->format->extension:"png");
if(!*path) {
ctx->set_error(ctx,500, "failed to allocate tile key");
Modified: trunk/mapserver/mapcache/src/util.c
===================================================================
--- trunk/mapserver/mapcache/src/util.c 2011-11-14 10:13:31 UTC (rev 12768)
+++ trunk/mapserver/mapcache/src/util.c 2011-11-15 10:18:11 UTC (rev 12769)
@@ -107,6 +107,18 @@
return newstr;
}
+const char* mapcache_util_str_sanitize(apr_pool_t *pool, const char *str, const char* from, char to) {
+ size_t pos = strcspn(str,from);
+ if(str[pos]) {
+ str = apr_pstrdup(pool,str);
+ while(str[pos]) {
+ ((char*)str)[pos]=to;
+ pos += strcspn(&str[pos],from);
+ }
+ }
+ return str;
+}
+
#if APR_MAJOR_VERSION < 1 || (APR_MAJOR_VERSION < 2 && APR_MINOR_VERSION < 3)
APR_DECLARE(apr_table_t *) apr_table_clone(apr_pool_t *p, const apr_table_t *t)
{
More information about the mapserver-commits
mailing list