static char* _get_dbname(mapcache_context *ctx, mapcache_tileset *tileset, mapcache_grid *grid) { mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*) tileset->cache; char *path = cache->dbname_template; path = mapcache_util_str_replace(ctx->pool, path, "{tileset}", tileset->name); path = mapcache_util_str_replace(ctx->pool, path, "{grid}", grid->name); return path; }
static void _mapcache_cache_disk_template_tile_key(mapcache_context *ctx, mapcache_tile *tile, char **path) { mapcache_cache_disk *dcache = (mapcache_cache_disk*)tile->tileset->cache; *path = dcache->filename_template; *path = mapcache_util_str_replace(ctx->pool,*path, "{tileset}", tile->tileset->name); *path = mapcache_util_str_replace(ctx->pool,*path, "{grid}", tile->grid_link->grid->name); *path = mapcache_util_str_replace(ctx->pool,*path, "{ext}", tile->tileset->format?tile->tileset->format->extension:"png"); if(strstr(*path,"{x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{x}", apr_psprintf(ctx->pool,"%d",tile->x)); else *path = mapcache_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 = mapcache_util_str_replace(ctx->pool,*path, "{y}", apr_psprintf(ctx->pool,"%d",tile->y)); else *path = mapcache_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 = mapcache_util_str_replace(ctx->pool,*path, "{z}", apr_psprintf(ctx->pool,"%d",tile->z)); else *path = mapcache_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 = mapcache_util_str_replace(ctx->pool,*path, "{dim}", dimstring); } if(!*path) { ctx->set_error(ctx,500, "failed to allocate tile key"); } }
/** * \brief return filename for given tile * * \param tile the tile to get the key from * \param path pointer to a char* that will contain the filename * \param r * \private \memberof mapcache_cache_tiff */ static void _mapcache_cache_tiff_tile_key(mapcache_context *ctx, mapcache_cache_tiff *cache, mapcache_tile *tile, char **path) { if( cache->storage.type == MAPCACHE_TIFF_STORAGE_REST ) { *path = apr_pstrcat(ctx->pool, "/vsicurl/", cache->filename_template, NULL); } else if( cache->storage.type == MAPCACHE_TIFF_STORAGE_GOOGLE && strncmp(cache->filename_template, "https://storage.googleapis.com/", strlen("https://storage.googleapis.com/")) == 0) { *path = apr_pstrcat(ctx->pool, "/vsigs/", cache->filename_template + strlen("https://storage.googleapis.com/"), NULL); } else { *path = apr_pstrdup(ctx->pool, cache->filename_template); } /* * generic template substitutions */ if(strstr(*path,"{tileset}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{tileset}", tile->tileset->name); if(strstr(*path,"{grid}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{grid}", tile->grid_link->grid->name); if(tile->dimensions && strstr(*path,"{dim")) { char *dimstring=""; int i = tile->dimensions->nelts; while(i--) { mapcache_requested_dimension *rdim = APR_ARRAY_IDX(tile->dimensions,i,mapcache_requested_dimension*); const char *dimval = mapcache_util_str_sanitize(ctx->pool,rdim->cached_value,"/.",'#'); char *dim_key = apr_pstrcat(ctx->pool,"{dim:",rdim->dimension->name,"}",NULL); dimstring = apr_pstrcat(ctx->pool,dimstring,"#",dimval,NULL); if(strstr(*path,dim_key)) { *path = mapcache_util_str_replace(ctx->pool,*path, dim_key, dimval); } } *path = mapcache_util_str_replace(ctx->pool,*path, "{dim}", dimstring); }
/** * \brief return filename for given tile * * \param tile the tile to get the key from * \param path pointer to a char* that will contain the filename * \param r * \private \memberof mapcache_cache_tiff */ static void _mapcache_cache_tiff_tile_key(mapcache_context *ctx, mapcache_tile *tile, char **path) { mapcache_cache_tiff *dcache = (mapcache_cache_tiff*)tile->tileset->cache; *path = dcache->filename_template; /* * generic template substitutions */ if(strstr(*path,"{tileset}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{tileset}", tile->tileset->name); if(strstr(*path,"{grid}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{grid}", tile->grid_link->grid->name); if(tile->dimensions && strstr(*path,"{dim}")) { 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)); const char *dimval = mapcache_util_str_sanitize(ctx->pool,entry->val,"/.",'#'); dimstring = apr_pstrcat(ctx->pool,dimstring,"#",dimval,NULL); } *path = mapcache_util_str_replace(ctx->pool,*path, "{dim}", dimstring); } while(strstr(*path,"{z}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{z}", apr_psprintf(ctx->pool,dcache->z_fmt,tile->z)); /* * x and y replacing, when the tiff files are numbered with an increasing * x,y scheme (adjacent tiffs have x-x'=1 or y-y'=1 */ while(strstr(*path,"{div_x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{div_x}", apr_psprintf(ctx->pool,dcache->div_x_fmt,tile->x/dcache->count_x)); while(strstr(*path,"{div_y}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{div_y}", apr_psprintf(ctx->pool,dcache->div_y_fmt,tile->y/dcache->count_y)); while(strstr(*path,"{inv_div_y}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{inv_div_y}", apr_psprintf(ctx->pool,dcache->inv_div_y_fmt,(tile->grid_link->grid->levels[tile->z]->maxy - tile->y - 1)/dcache->count_y)); while(strstr(*path,"{inv_div_x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{inv_div_x}", apr_psprintf(ctx->pool,dcache->inv_div_x_fmt,(tile->grid_link->grid->levels[tile->z]->maxx - tile->x - 1)/dcache->count_x)); /* * x and y replacing, when the tiff files are numbered with the index * of their bottom-left tile * adjacent tiffs have x-x'=count_x or y-y'=count_y */ while(strstr(*path,"{x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{x}", apr_psprintf(ctx->pool,dcache->x_fmt,tile->x/dcache->count_x*dcache->count_x)); while(strstr(*path,"{y}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{y}", apr_psprintf(ctx->pool,dcache->y_fmt,tile->y/dcache->count_y*dcache->count_y)); while(strstr(*path,"{inv_y}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{inv_y}", apr_psprintf(ctx->pool,dcache->inv_y_fmt,(tile->grid_link->grid->levels[tile->z]->maxy - tile->y - 1)/dcache->count_y*dcache->count_y)); while(strstr(*path,"{inv_x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{inv_x}", apr_psprintf(ctx->pool,dcache->inv_x_fmt,(tile->grid_link->grid->levels[tile->z]->maxx - tile->x - 1)/dcache->count_x*dcache->count_y)); if(!*path) { ctx->set_error(ctx,500, "failed to allocate tile key"); } }
/** * \brief return sqlite db filename for given tile * * \param tile the tile to get the key from * \param path pointer to a char* that will contain the filename * \param r * \private \memberof mapcache_cache_sqlite */ static void _mapcache_cache_sqlite_filename_for_tile(mapcache_context *ctx, mapcache_cache_sqlite *dcache, mapcache_tile *tile, char **path) { *path = dcache->dbfile; if(strstr(*path,"{")) { /* * generic template substitutions */ if(strstr(*path,"{tileset}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{tileset}", tile->tileset->name); if(strstr(*path,"{grid}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{grid}", tile->grid_link->grid->name); if(tile->dimensions && strstr(*path,"{dim}")) { 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)); const char *dimval = mapcache_util_str_sanitize(ctx->pool,entry->val,"/.",'#'); dimstring = apr_pstrcat(ctx->pool,dimstring,"#",dimval,NULL); } *path = mapcache_util_str_replace(ctx->pool,*path, "{dim}", dimstring); } while(strstr(*path,"{z}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{z}", apr_psprintf(ctx->pool,dcache->z_fmt,tile->z)); if(dcache->count_x > 0) { while(strstr(*path,"{div_x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{div_x}", apr_psprintf(ctx->pool,dcache->div_x_fmt,tile->x/dcache->count_x)); while(strstr(*path,"{inv_div_x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{inv_div_x}", apr_psprintf(ctx->pool,dcache->inv_div_x_fmt,(tile->grid_link->grid->levels[tile->z]->maxx - tile->x - 1)/dcache->count_x)); while(strstr(*path,"{x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{x}", apr_psprintf(ctx->pool,dcache->x_fmt,tile->x/dcache->count_x*dcache->count_x)); while(strstr(*path,"{inv_x}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{inv_x}", apr_psprintf(ctx->pool,dcache->inv_x_fmt,(tile->grid_link->grid->levels[tile->z]->maxx - tile->x - 1)/dcache->count_x*dcache->count_x)); } if(dcache->count_y > 0) { while(strstr(*path,"{div_y}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{div_y}", apr_psprintf(ctx->pool,dcache->div_y_fmt,tile->y/dcache->count_y)); while(strstr(*path,"{inv_div_y}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{inv_div_y}", apr_psprintf(ctx->pool,dcache->inv_div_y_fmt,(tile->grid_link->grid->levels[tile->z]->maxy - tile->y - 1)/dcache->count_y)); while(strstr(*path,"{y}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{y}", apr_psprintf(ctx->pool,dcache->y_fmt,tile->y/dcache->count_y*dcache->count_y)); while(strstr(*path,"{inv_y}")) *path = mapcache_util_str_replace(ctx->pool,*path, "{inv_y}", apr_psprintf(ctx->pool,dcache->inv_y_fmt,(tile->grid_link->grid->levels[tile->z]->maxy - tile->y - 1)/dcache->count_y*dcache->count_y)); } } if(!*path) { ctx->set_error(ctx,500, "failed to allocate tile key"); } }