[mapserver-commits] r12452 - in trunk/mapserver/mapcache: . include
src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:27:40 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:27:40 -0700 (Fri, 26 Aug 2011)
New Revision: 12452
Modified:
trunk/mapserver/mapcache/geocache.xml
trunk/mapserver/mapcache/include/geocache.h
trunk/mapserver/mapcache/src/cache_disk.c
trunk/mapserver/mapcache/src/configuration_xml.c
trunk/mapserver/mapcache/src/util.c
Log:
Modified: trunk/mapserver/mapcache/geocache.xml
===================================================================
--- trunk/mapserver/mapcache/geocache.xml 2011-08-26 11:27:35 UTC (rev 12451)
+++ trunk/mapserver/mapcache/geocache.xml 2011-08-26 11:27:40 UTC (rev 12452)
@@ -337,12 +337,9 @@
-->
<symlink_blank/>
</cache>
-
-<!--
- a cache is where tiles are stored once they have been rendered
- -->
- <cache name="tmpl" type="template">
- <template>/tmp/tmpl/{{tileset}}/{{grid}}/{{z}}-{{x}}-{{inv_y}}.{{ext}}</template>
+
+ <cache name="tmpl" type="disk">
+ <template>/tmp/template-test/{tileset}#{grid}#{dim}/{z}/{x}/{y}.{ext}</template>
</cache>
<!-- memcache cache
@@ -674,7 +671,7 @@
</tileset>
<tileset name="test2">
<source>nexrad</source>
- <cache>tmpl</cache>
+ <cache>disk</cache>
<format>mixed</format>
<grid>WGS84</grid>
</tileset>
@@ -692,7 +689,7 @@
<abstract>see http://mapserver-utils.googlecode.com</abstract>
</metadata>
<source>osm</source>
- <cache>sqlite</cache>
+ <cache>tmpl</cache>
<format>PNG</format>
<grid>FXX</grid>
<grid>MILLER</grid>
Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:27:35 UTC (rev 12451)
+++ trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:27:40 UTC (rev 12452)
@@ -87,9 +87,7 @@
#if 0
typedef struct geocache_source_gdal geocache_source_gdal;
#endif
-typedef struct geocache_cache_filesystem geocache_cache_filesystem;
typedef struct geocache_cache_disk geocache_cache_disk;
-typedef struct geocache_cache_disk_template geocache_cache_disk_template;
typedef struct geocache_http geocache_http;
typedef struct geocache_request geocache_request;
typedef struct geocache_request_proxy geocache_request_proxy;
@@ -320,8 +318,7 @@
/** @{ */
typedef enum {
- GEOCACHE_CACHE_DISK,
- GEOCACHE_CACHE_DISK_TEMPLATE
+ GEOCACHE_CACHE_DISK
#ifdef USE_MEMCACHE
,GEOCACHE_CACHE_MEMCACHE
#endif
@@ -367,36 +364,18 @@
void (*configuration_post_config)(geocache_context *ctx, geocache_cache * cache, geocache_cfg *config);
};
-/**\class geocache_cache_filesystem
+/**\class geocache_cache_disk
* \brief a geocache_cache on a filesytem
* \implements geocache_cache
*/
-struct geocache_cache_filesystem {
+struct geocache_cache_disk {
geocache_cache cache;
- void (*tile_key)(geocache_context *ctx, geocache_tile *tile, const char **path);
- void (*blank_key)(geocache_context *ctx, geocache_tile *tile, unsigned char *color, char **path);
+ char *base_directory;
+ char *filename_template;
int symlink_blank;
};
-/**\class geocache_cache_disk
- * \brief a geocache_cache
- * \implements geocache_cache
- */
-struct geocache_cache_disk {
- geocache_cache_filesystem cache;
- char *base_directory;
-};
-/**\class geocache_cache_disk
- * \brief a geocache_cache on a filesytem
- * \implements geocache_cache
- */
-struct geocache_cache_disk_template {
- geocache_cache_filesystem cache;
- char *template;
-};
-
-
#ifdef USE_SQLITE
/**\class geocache_cache_sqlite
* \brief a geocache_cache on a filesytem
@@ -934,7 +913,6 @@
* \memberof geocache_cache_disk
*/
geocache_cache* geocache_cache_disk_create(geocache_context *ctx);
-geocache_cache* geocache_cache_disk_template_create(geocache_context *ctx);
/** \defgroup tileset Tilesets*/
@@ -1242,7 +1220,7 @@
int *numbers_count);
int geocache_util_extract_double_list(geocache_context *ctx, const char* args, const char sep, double **numbers,
int *numbers_count);
-const char *geocache_util_str_replace(apr_pool_t *pool, const char *string, const char *substr,
+char *geocache_util_str_replace(apr_pool_t *pool, const char *string, const char *substr,
const char *replacement );
/*
Modified: trunk/mapserver/mapcache/src/cache_disk.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_disk.c 2011-08-26 11:27:35 UTC (rev 12451)
+++ trunk/mapserver/mapcache/src/cache_disk.c 2011-08-26 11:27:40 UTC (rev 12452)
@@ -26,6 +26,7 @@
#endif
static void _geocache_cache_disk_blank_tile_key(geocache_context *ctx, geocache_tile *tile, unsigned char *color, char **path) {
+ /* not implemented for template caches, as symlink_blank will never be set */
*path = apr_psprintf(ctx->pool,"%s/%s/%s/blanks/%02X%02X%02X%02X.%s",
((geocache_cache_disk*)tile->tileset->cache)->base_directory,
tile->tileset->name,
@@ -47,68 +48,98 @@
* \param r
* \private \memberof geocache_cache_disk
*/
-static void _geocache_cache_disk_tile_key(geocache_context *ctx, geocache_tile *tile, const char **path) {
- char *start;
- start = apr_pstrcat(ctx->pool,
- ((geocache_cache_disk*)tile->tileset->cache)->base_directory,"/",
- tile->tileset->name,"/",
- tile->grid_link->grid->name,
- NULL);
- if(tile->dimensions) {
- const apr_array_header_t *elts = apr_table_elts(tile->dimensions);
- 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 = '#';
+static void _geocache_cache_disk_tile_key(geocache_context *ctx, geocache_tile *tile, char **path) {
+ geocache_cache_disk *dcache = (geocache_cache_disk*)tile->tileset->cache;
+ if(dcache->base_directory) {
+ char *start;
+ start = apr_pstrcat(ctx->pool,
+ dcache->base_directory,"/",
+ tile->tileset->name,"/",
+ tile->grid_link->grid->name,
+ NULL);
+ if(tile->dimensions) {
+ const apr_array_header_t *elts = apr_table_elts(tile->dimensions);
+ 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++;
}
- iter++;
+ start = apr_pstrcat(ctx->pool,start,"/",entry->key,"/",dimval,NULL);
}
- start = apr_pstrcat(ctx->pool,start,"/",entry->key,"/",dimval,NULL);
}
+ *path = apr_psprintf(ctx->pool,"%s/%02d/%03d/%03d/%03d/%03d/%03d/%03d.%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->tileset->format?tile->tileset->format->extension:"png");
+ } else {
+ *path = dcache->filename_template;
+ *path = geocache_util_str_replace(ctx->pool,*path, "{tileset}", tile->tileset->name);
+ *path = geocache_util_str_replace(ctx->pool,*path, "{grid}", tile->grid_link->grid->name);
+ *path = geocache_util_str_replace(ctx->pool,*path, "{ext}",
+ tile->tileset->format?tile->tileset->format->extension:"png");
+ if(strstr(*path,"{x}"))
+ *path = geocache_util_str_replace(ctx->pool,*path, "{x}",
+ apr_psprintf(ctx->pool,"%d",tile->x));
+ else
+ *path = geocache_util_str_replace(ctx->pool,*path, "{inv_x}",
+ apr_psprintf(ctx->pool,"%d",
+ tile->grid_link->grid->levels[tile->z]->maxx - tile->x - 1));
+ if(strstr(*path,"{y}"))
+ *path = geocache_util_str_replace(ctx->pool,*path, "{y}",
+ apr_psprintf(ctx->pool,"%d",tile->y));
+ else
+ *path = geocache_util_str_replace(ctx->pool,*path, "{inv_y}",
+ apr_psprintf(ctx->pool,"%d",
+ tile->grid_link->grid->levels[tile->z]->maxy - tile->y - 1));
+ if(strstr(*path,"{z}"))
+ *path = geocache_util_str_replace(ctx->pool,*path, "{z}",
+ apr_psprintf(ctx->pool,"%d",tile->z));
+ else
+ *path = geocache_util_str_replace(ctx->pool,*path, "{inv_z}",
+ apr_psprintf(ctx->pool,"%d",
+ tile->grid_link->grid->nlevels - tile->z - 1));
+ if(tile->dimensions) {
+ char *dimstring="";
+ const apr_array_header_t *elts = apr_table_elts(tile->dimensions);
+ 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++;
+ }
+ dimstring = apr_pstrcat(ctx->pool,dimstring,"#",entry->key,"#",dimval,NULL);
+ }
+ *path = geocache_util_str_replace(ctx->pool,*path, "{dim}", dimstring);
+ }
}
- *path = apr_psprintf(ctx->pool,"%s/%02d/%03d/%03d/%03d/%03d/%03d/%03d.%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->tileset->format?tile->tileset->format->extension:"png");
if(!*path) {
ctx->set_error(ctx,500, "failed to allocate tile key");
}
-
}
-
-static void _geocache_cache_template_tile_key(geocache_context *ctx, geocache_tile *tile, const char **path) {
- geocache_cache_disk_template *tcache = (geocache_cache_disk_template*)tile->tileset->cache;
- *path = tcache->template;
- *path = geocache_util_str_replace(ctx->pool,*path, "{{tileset}}", tile->tileset->name);
- *path = geocache_util_str_replace(ctx->pool,*path, "{{grid}}", tile->grid_link->grid->name);
- *path = geocache_util_str_replace(ctx->pool,*path, "{{ext}}", tile->tileset->format?tile->tileset->format->extension:"png");
- *path = geocache_util_str_replace(ctx->pool,*path, "{{x}}",apr_psprintf(ctx->pool,"%d",tile->x));
- *path = geocache_util_str_replace(ctx->pool,*path, "{{y}}",apr_psprintf(ctx->pool,"%d",tile->y));
- *path = geocache_util_str_replace(ctx->pool,*path, "{{z}}",apr_psprintf(ctx->pool,"%d",tile->z));
- *path = geocache_util_str_replace(ctx->pool,*path, "{{inv_x}}",apr_psprintf(ctx->pool,"%d",tile->grid_link->grid->levels[tile->z]->maxx - tile->x - 1));
- *path = geocache_util_str_replace(ctx->pool,*path, "{{inv_y}}",apr_psprintf(ctx->pool,"%d",tile->grid_link->grid->levels[tile->z]->maxy - tile->y - 1));
- *path = geocache_util_str_replace(ctx->pool,*path, "{{inv_z}}",apr_psprintf(ctx->pool,"%d",tile->grid_link->grid->nlevels - tile->z - 1));
-
- ctx->log(ctx,GEOCACHE_WARNING, "key is %s", *path);
-}
-
-static int _geocache_cache_filesystem_has_tile(geocache_context *ctx, geocache_tile *tile) {
- geocache_cache_filesystem *fcache = (geocache_cache_filesystem*)tile->tileset->cache;
- const char *filename;
+static int _geocache_cache_disk_has_tile(geocache_context *ctx, geocache_tile *tile) {
+ char *filename;
apr_file_t *f;
- fcache->tile_key(ctx, tile, &filename);
+ _geocache_cache_disk_tile_key(ctx, tile, &filename);
if(GC_HAS_ERROR(ctx)) {
return GEOCACHE_FALSE;
}
@@ -120,13 +151,12 @@
return GEOCACHE_FALSE;
}
-static void _geocache_cache_filesystem_delete(geocache_context *ctx, geocache_tile *tile) {
- geocache_cache_filesystem *fcache = (geocache_cache_filesystem*)tile->tileset->cache;
+static void _geocache_cache_disk_delete(geocache_context *ctx, geocache_tile *tile) {
apr_status_t ret;
char errmsg[120];
- const char *filename;
+ char *filename;
apr_file_t *f;
- fcache->tile_key(ctx, tile, &filename);
+ _geocache_cache_disk_tile_key(ctx, tile, &filename);
GC_CHECK_ERROR(ctx);
/* delete the tile file if it already exists */
@@ -155,14 +185,13 @@
* \private \memberof geocache_cache_disk
* \sa geocache_cache::tile_get()
*/
-static int _geocache_cache_filesystem_get(geocache_context *ctx, geocache_tile *tile) {
- geocache_cache_filesystem *fcache = (geocache_cache_filesystem*)tile->tileset->cache;
- const char *filename;
+static int _geocache_cache_disk_get(geocache_context *ctx, geocache_tile *tile) {
+ char *filename;
apr_file_t *f;
apr_finfo_t finfo;
apr_status_t rv;
apr_size_t size;
- fcache->tile_key(ctx, tile, &filename);
+ _geocache_cache_disk_tile_key(ctx, tile, &filename);
if(GC_HAS_ERROR(ctx)) {
return GEOCACHE_FAILURE;
}
@@ -215,14 +244,12 @@
* \private \memberof geocache_cache_disk
* \sa geocache_cache::tile_set()
*/
-static void _geocache_cache_filesystem_set(geocache_context *ctx, geocache_tile *tile) {
- geocache_cache_filesystem *fcache = (geocache_cache_filesystem*)tile->tileset->cache;
+static void _geocache_cache_disk_set(geocache_context *ctx, geocache_tile *tile) {
apr_size_t bytes;
apr_file_t *f;
apr_status_t ret;
char errmsg[120];
- const char *filename, *hackptr1;
- char *hackptr2=NULL;
+ char *filename, *hackptr1, *hackptr2=NULL;
#ifdef DEBUG
/* all this should be checked at a higher level */
if(!tile->data || !tile->data->size) {
@@ -230,14 +257,14 @@
return;
}
#endif
- fcache->tile_key(ctx, tile, &filename);
+ _geocache_cache_disk_tile_key(ctx, tile, &filename);
GC_CHECK_ERROR(ctx);
/* find the location of the last '/' in the string */
hackptr1 = filename;
while(*hackptr1) {
if(*hackptr1 == '/')
- hackptr2 = (char*)hackptr1;
+ hackptr2 = hackptr1;
hackptr1++;
}
*hackptr2 = '\0';
@@ -266,12 +293,12 @@
#ifdef HAVE_SYMLINK
- if(fcache->symlink_blank) {
+ if(((geocache_cache_disk*)tile->tileset->cache)->symlink_blank) {
geocache_image *image = geocache_imageio_decode(ctx, tile->data);
GC_CHECK_ERROR(ctx);
if(geocache_image_blank_color(image) != GEOCACHE_FALSE) {
char *blankname;
- fcache->blank_key(ctx,tile,image->data,&blankname);
+ _geocache_cache_disk_blank_tile_key(ctx,tile,image->data,&blankname);
GC_CHECK_ERROR(ctx);
ctx->global_lock_aquire(ctx);
GC_CHECK_ERROR(ctx);
@@ -361,45 +388,30 @@
/**
* \private \memberof geocache_cache_disk
*/
-static void _geocache_cache_template_configuration_parse_xml(geocache_context *ctx, ezxml_t node, geocache_cache *cache) {
- ezxml_t cur_node;
- geocache_cache_disk_template *dcache = (geocache_cache_disk_template*)cache;
-
- if ((cur_node = ezxml_child(node,"template")) != NULL) {
- dcache->template = apr_pstrdup(ctx->pool,cur_node->txt);
- }
-}
-/**
- * \private \memberof geocache_cache_disk
- */
static void _geocache_cache_disk_configuration_parse_xml(geocache_context *ctx, ezxml_t node, geocache_cache *cache) {
ezxml_t cur_node;
geocache_cache_disk *dcache = (geocache_cache_disk*)cache;
if ((cur_node = ezxml_child(node,"base")) != NULL) {
dcache->base_directory = apr_pstrdup(ctx->pool,cur_node->txt);
- }
-
- if ((cur_node = ezxml_child(node,"symlink_blank")) != NULL) {
- if(strcasecmp(cur_node->txt,"false")){
+ /* we don't check for symlinking in the case where we are using a "template" cache type */
+ if ((cur_node = ezxml_child(node,"symlink_blank")) != NULL) {
+ if(strcasecmp(cur_node->txt,"false")){
#ifdef HAVE_SYMLINK
- dcache->cache.symlink_blank = 1;
+ dcache->symlink_blank = 1;
#else
- ctx->set_error(ctx,400,"cache %s: host system does not support file symbolic linking",cache->name);
- return;
+ ctx->set_error(ctx,400,"cache %s: host system does not support file symbolic linking",cache->name);
+ return;
#endif
+ }
}
+ } else {
+ if ((cur_node = ezxml_child(node,"template")) != NULL) {
+ dcache->filename_template = apr_pstrdup(ctx->pool,cur_node->txt);
+ }
}
}
-static void _geocache_cache_template_configuration_post_config(geocache_context *ctx, geocache_cache *cache,
- geocache_cfg *cfg) {
- geocache_cache_disk_template *dcache = (geocache_cache_disk_template*)cache;
- if(!dcache->template || !strlen(dcache->template)) {
- ctx->set_error(ctx, 400, "disk cache %s has no base directory",cache->name);
- return;
- }
-}
/**
* \private \memberof geocache_cache_disk
*/
@@ -407,72 +419,33 @@
geocache_cfg *cfg) {
geocache_cache_disk *dcache = (geocache_cache_disk*)cache;
/* check all required parameters are configured */
- if(!dcache->base_directory || !strlen(dcache->base_directory)) {
- ctx->set_error(ctx, 400, "disk cache %s has no base directory",dcache->cache.cache.name);
+ if((!dcache->base_directory || !strlen(dcache->base_directory)) &&
+ (!dcache->filename_template || !strlen(dcache->filename_template))) {
+ ctx->set_error(ctx, 400, "disk cache %s has no base directory or template",dcache->cache.name);
return;
}
-
- apr_dir_t *basedir;
- apr_status_t rv;
- rv = apr_dir_open(&basedir,dcache->base_directory,ctx->pool);
- char errmsg[120];
- if(rv != APR_SUCCESS) {
- ctx->log(ctx,GEOCACHE_WARNING, "failed to open base directory %s for cache %s: %s."\
- " This might lead to problems later on if the apache user does not have the rights to create this directory",
- dcache->base_directory,cache->name,apr_strerror(rv,errmsg,120));
- }
- return;
}
/**
* \brief creates and initializes a geocache_disk_cache
*/
geocache_cache* geocache_cache_disk_create(geocache_context *ctx) {
- geocache_cache_disk *dcache = apr_pcalloc(ctx->pool,sizeof(geocache_cache_disk));
- geocache_cache_filesystem *fcache = (geocache_cache_filesystem*)dcache;
- geocache_cache *cache = (geocache_cache*)dcache;
+ geocache_cache_disk *cache = apr_pcalloc(ctx->pool,sizeof(geocache_cache_disk));
if(!cache) {
ctx->set_error(ctx, 500, "failed to allocate disk cache");
return NULL;
}
- fcache->symlink_blank = 0;
- fcache->tile_key = _geocache_cache_disk_tile_key;
- fcache->blank_key = _geocache_cache_disk_blank_tile_key;
- cache->metadata = apr_table_make(ctx->pool,3);
- cache->type = GEOCACHE_CACHE_DISK;
- cache->tile_delete = _geocache_cache_filesystem_delete;
- cache->tile_get = _geocache_cache_filesystem_get;
- cache->tile_exists = _geocache_cache_filesystem_has_tile;
- cache->tile_set = _geocache_cache_filesystem_set;
- cache->configuration_post_config = _geocache_cache_disk_configuration_post_config;
- cache->configuration_parse_xml = _geocache_cache_disk_configuration_parse_xml;
+ cache->symlink_blank = 0;
+ cache->cache.metadata = apr_table_make(ctx->pool,3);
+ cache->cache.type = GEOCACHE_CACHE_DISK;
+ cache->cache.tile_delete = _geocache_cache_disk_delete;
+ cache->cache.tile_get = _geocache_cache_disk_get;
+ cache->cache.tile_exists = _geocache_cache_disk_has_tile;
+ cache->cache.tile_set = _geocache_cache_disk_set;
+ cache->cache.configuration_post_config = _geocache_cache_disk_configuration_post_config;
+ cache->cache.configuration_parse_xml = _geocache_cache_disk_configuration_parse_xml;
return (geocache_cache*)cache;
}
-/**
- * \brief creates and initializes a geocache_cache_disk_template
- */
-geocache_cache* geocache_cache_disk_template_create(geocache_context *ctx) {
- geocache_cache_disk_template *dcache = apr_pcalloc(ctx->pool,sizeof(geocache_cache_disk_template));
- geocache_cache_filesystem *fcache = (geocache_cache_filesystem*)dcache;
- geocache_cache *cache = (geocache_cache*)dcache;
- if(!cache) {
- ctx->set_error(ctx, 500, "failed to allocate disk template cache");
- return NULL;
- }
- fcache->symlink_blank = 0;
- fcache->tile_key = _geocache_cache_template_tile_key;
- fcache->blank_key = _geocache_cache_disk_blank_tile_key;
- cache->metadata = apr_table_make(ctx->pool,3);
- cache->type = GEOCACHE_CACHE_DISK_TEMPLATE;
- cache->tile_delete = _geocache_cache_filesystem_delete;
- cache->tile_get = _geocache_cache_filesystem_get;
- cache->tile_exists = _geocache_cache_filesystem_has_tile;
- cache->tile_set = _geocache_cache_filesystem_set;
- cache->configuration_post_config = _geocache_cache_template_configuration_post_config;
- cache->configuration_parse_xml = _geocache_cache_template_configuration_parse_xml;
- return (geocache_cache*)cache;
-}
-
/* vim: ai ts=3 sts=3 et sw=3
*/
Modified: trunk/mapserver/mapcache/src/configuration_xml.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration_xml.c 2011-08-26 11:27:35 UTC (rev 12451)
+++ trunk/mapserver/mapcache/src/configuration_xml.c 2011-08-26 11:27:40 UTC (rev 12452)
@@ -578,8 +578,6 @@
}
if(!strcmp(type,"disk")) {
cache = geocache_cache_disk_create(ctx);
- } else if(!strcmp(type,"template")) {
- cache = geocache_cache_disk_template_create(ctx);
} else if(!strcmp(type,"sqlite3")) {
#ifdef USE_SQLITE
cache = geocache_cache_sqlite_create(ctx);
Modified: trunk/mapserver/mapcache/src/util.c
===================================================================
--- trunk/mapserver/mapcache/src/util.c 2011-08-26 11:27:35 UTC (rev 12451)
+++ trunk/mapserver/mapcache/src/util.c 2011-08-26 11:27:40 UTC (rev 12452)
@@ -75,6 +75,20 @@
return GEOCACHE_SUCCESS;
}
+char *geocache_util_str_replace(apr_pool_t *pool, const char *string, const char *substr, const char *replacement ){
+ char *tok = NULL;
+ char *newstr = NULL;
+
+ tok = strstr( string, substr );
+ if( tok == NULL ) return apr_pstrdup( pool, string );
+ newstr = apr_pcalloc(pool, strlen( string ) - strlen( substr ) + strlen( replacement ) + 1 );
+ memcpy( newstr, string, tok - string );
+ memcpy( newstr + (tok - string), replacement, strlen( replacement ) );
+ memcpy( newstr + (tok - string) + strlen( replacement ), tok + strlen( substr ), strlen( string ) - strlen( substr ) - ( tok - string ) );
+ memset( newstr + strlen( string ) - strlen( substr ) + strlen( replacement ), 0, 1 );
+ return newstr;
+}
+
#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)
{
@@ -130,19 +144,5 @@
ctx->clear_errors = _geocache_context_clear_error_default;
}
-const char *geocache_util_str_replace(apr_pool_t *pool, const char *string, const char *substr, const char *replacement ){
- char *tok = NULL;
- char *newstr = NULL;
-
- tok = strstr( string, substr );
- if( tok == NULL ) return apr_pstrdup( pool, string );
- newstr = apr_pcalloc(pool, strlen( string ) - strlen( substr ) + strlen( replacement ) + 1 );
- memcpy( newstr, string, tok - string );
- memcpy( newstr + (tok - string), replacement, strlen( replacement ) );
- memcpy( newstr + (tok - string) + strlen( replacement ), tok + strlen( substr ), strlen( string ) - strlen( substr ) - ( tok - string ) );
- memset( newstr + strlen( string ) - strlen( substr ) + strlen( replacement ), 0, 1 );
- return newstr;
-}
-
/* vim: ai ts=3 sts=3 et sw=3
*/
More information about the mapserver-commits
mailing list