void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config) { char *name = NULL; mapcache_tileset *tileset = NULL; ezxml_t cur_node; char* value; int havewgs84bbox=0; if(config->mode == MAPCACHE_MODE_NORMAL) { name = (char*)ezxml_attr(node,"name"); } else { name = "mirror"; } if(!name || !strlen(name)) { ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <tileset>"); return; } else { name = apr_pstrdup(ctx->pool, name); /* check we don't already have a cache defined with this name */ if(mapcache_configuration_get_tileset(config, name)) { ctx->set_error(ctx, 400, "duplicate tileset with name \"%s\"",name); return; } } tileset = mapcache_tileset_create(ctx); tileset->name = name; if ((cur_node = ezxml_child(node,"metadata")) != NULL) { parseMetadata(ctx, cur_node, tileset->metadata); GC_CHECK_ERROR(ctx); } if ((value = (char*)apr_table_get(tileset->metadata,"wgs84boundingbox")) != NULL) { double *values; int nvalues; value = apr_pstrdup(ctx->pool,value); if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, value, NULL, &values, &nvalues) || nvalues != 4) { ctx->set_error(ctx, 400, "failed to parse extent array %s." "(expecting 4 space separated numbers, got %d (%f %f %f %f)" "eg <wgs84bbox>-180 -90 180 90</wgs84bbox>", value,nvalues,values[0],values[1],values[2],values[3]); return; } tileset->wgs84bbox[0] = values[0]; tileset->wgs84bbox[1] = values[1]; tileset->wgs84bbox[2] = values[2]; tileset->wgs84bbox[3] = values[3]; havewgs84bbox = 1; } for(cur_node = ezxml_child(node,"grid"); cur_node; cur_node = cur_node->next) { int i; mapcache_grid *grid; mapcache_grid_link *gridlink; char *restrictedExtent = NULL, *sTolerance = NULL; double *extent; int tolerance; if (tileset->grid_links == NULL) { tileset->grid_links = apr_array_make(ctx->pool,1,sizeof(mapcache_grid_link*)); } grid = mapcache_configuration_get_grid(config, cur_node->txt); if(!grid) { ctx->set_error(ctx, 400, "tileset \"%s\" references grid \"%s\"," " but it is not configured", name, cur_node->txt); return; } gridlink = apr_pcalloc(ctx->pool,sizeof(mapcache_grid_link)); gridlink->grid = grid; gridlink->minz = 0; gridlink->maxz = grid->nlevels; gridlink->grid_limits = apr_pcalloc(ctx->pool,grid->nlevels*sizeof(int*)); for(i=0;i<grid->nlevels;i++) { gridlink->grid_limits[i] = apr_pcalloc(ctx->pool,4*sizeof(int)); } restrictedExtent = (char*)ezxml_attr(cur_node,"restricted_extent"); if(restrictedExtent) { int nvalues; restrictedExtent = apr_pstrdup(ctx->pool,restrictedExtent); if(MAPCACHE_SUCCESS != mapcache_util_extract_double_list(ctx, restrictedExtent, NULL, &gridlink->restricted_extent, &nvalues) || nvalues != 4) { ctx->set_error(ctx, 400, "failed to parse extent array %s." "(expecting 4 space separated numbers, " "eg <grid restricted_extent=\"-180 -90 180 90\">foo</grid>", restrictedExtent); return; } extent = gridlink->restricted_extent; } else { extent = grid->extent; } tolerance = 5; sTolerance = (char*)ezxml_attr(cur_node,"tolerance"); if(sTolerance) { char *endptr; tolerance = (int)strtol(sTolerance,&endptr,10); if(*endptr != 0 || tolerance < 0) { ctx->set_error(ctx, 400, "failed to parse grid tolerance %s (expecting a positive integer)", sTolerance); return; } } mapcache_grid_compute_limits(grid,extent,gridlink->grid_limits,tolerance); sTolerance = (char*)ezxml_attr(cur_node,"minzoom"); if(sTolerance) { char *endptr; tolerance = (int)strtol(sTolerance,&endptr,10); if(*endptr != 0 || tolerance < 0) { ctx->set_error(ctx, 400, "failed to parse grid minzoom %s (expecting a positive integer)", sTolerance); return; } gridlink->minz = tolerance; } sTolerance = (char*)ezxml_attr(cur_node,"maxzoom"); if(sTolerance) { char *endptr; tolerance = (int)strtol(sTolerance,&endptr,10); if(*endptr != 0 || tolerance < 0) { ctx->set_error(ctx, 400, "failed to parse grid maxzoom %s (expecting a positive integer)", sTolerance); return; } gridlink->maxz = tolerance + 1; } if(gridlink->minz<0 || gridlink->maxz>grid->nlevels || gridlink->minz>=gridlink->maxz) { ctx->set_error(ctx, 400, "invalid grid maxzoom/minzoom %d/%d", gridlink->minz,gridlink->maxz); return; } /* compute wgs84 bbox if it wasn't supplied already */ if(!havewgs84bbox && !strcasecmp(grid->srs,"EPSG:4326")) { tileset->wgs84bbox[0] = extent[0]; tileset->wgs84bbox[1] = extent[1]; tileset->wgs84bbox[2] = extent[2]; tileset->wgs84bbox[3] = extent[3]; } APR_ARRAY_PUSH(tileset->grid_links,mapcache_grid_link*) = gridlink; } if ((cur_node = ezxml_child(node,"dimensions")) != NULL) { parseDimensions(ctx, cur_node, tileset); GC_CHECK_ERROR(ctx); } if ((cur_node = ezxml_child(node,"cache")) != NULL) { mapcache_cache *cache = mapcache_configuration_get_cache(config, cur_node->txt); if(!cache) { ctx->set_error(ctx, 400, "tileset \"%s\" references cache \"%s\"," " but it is not configured", name, cur_node->txt); return; } tileset->cache = cache; } if ((cur_node = ezxml_child(node,"source")) != NULL) { mapcache_source *source = mapcache_configuration_get_source(config, cur_node->txt); if(!source) { ctx->set_error(ctx, 400, "tileset \"%s\" references source \"%s\"," " but it is not configured", name, cur_node->txt); return; } tileset->source = source; } if ((cur_node = ezxml_child(node,"metatile")) != NULL) { int *values, nvalues; value = apr_pstrdup(ctx->pool,cur_node->txt); if(MAPCACHE_SUCCESS != mapcache_util_extract_int_list(ctx, cur_node->txt, NULL, &values, &nvalues) || nvalues != 2) { ctx->set_error(ctx, 400, "failed to parse metatile dimension %s." "(expecting 2 space separated integers, " "eg <metatile>5 5</metatile>", cur_node->txt); return; } tileset->metasize_x = values[0]; tileset->metasize_y = values[1]; } if ((cur_node = ezxml_child(node,"watermark")) != NULL) { if(!*cur_node->txt) { ctx->set_error(ctx,400, "watermark config entry empty"); return; } mapcache_tileset_add_watermark(ctx,tileset,cur_node->txt); GC_CHECK_ERROR(ctx); } if ((cur_node = ezxml_child(node,"expires")) != NULL) { char *endptr; tileset->expires = (int)strtol(cur_node->txt,&endptr,10); if(*endptr != 0) { ctx->set_error(ctx, 400, "failed to parse expires %s." "(expecting an integer, " "eg <expires>3600</expires>", cur_node->txt); return; } } if ((cur_node = ezxml_child(node,"auto_expire")) != NULL) { char *endptr; tileset->auto_expire = (int)strtol(cur_node->txt,&endptr,10); if(*endptr != 0) { ctx->set_error(ctx, 400, "failed to parse auto_expire %s." "(expecting an integer, " "eg <auto_expire>3600</auto_expire>", cur_node->txt); return; } } if ((cur_node = ezxml_child(node,"metabuffer")) != NULL) { char *endptr; tileset->metabuffer = (int)strtol(cur_node->txt,&endptr,10); if(*endptr != 0) { ctx->set_error(ctx, 400, "failed to parse metabuffer %s." "(expecting an integer, " "eg <metabuffer>1</metabuffer>", cur_node->txt); return; } } if ((cur_node = ezxml_child(node,"format")) != NULL) { mapcache_image_format *format = mapcache_configuration_get_image_format(config,cur_node->txt); if(!format) { ctx->set_error(ctx, 400, "tileset \"%s\" references format \"%s\"," " but it is not configured",name,cur_node->txt); return; } tileset->format = format; } mapcache_tileset_configuration_check(ctx,tileset); GC_CHECK_ERROR(ctx); mapcache_configuration_add_tileset(config,tileset,name); return; }
void parseCache(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config) { char *name = NULL, *type = NULL; mapcache_cache *cache = NULL; ezxml_t cur_node; name = (char*)ezxml_attr(node,"name"); type = (char*)ezxml_attr(node,"type"); if(!name || !strlen(name)) { ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <cache>"); return; } else { name = apr_pstrdup(ctx->pool, name); /* check we don't already have a cache defined with this name */ if(mapcache_configuration_get_cache(config, name)) { ctx->set_error(ctx, 400, "duplicate cache with name \"%s\"",name); return; } } if(!type || !strlen(type)) { ctx->set_error(ctx, 400, "mandatory attribute \"type\" not found in <cache>"); return; } if(!strcmp(type,"disk")) { cache = mapcache_cache_disk_create(ctx); } else if(!strcmp(type,"fallback")) { cache = mapcache_cache_fallback_create(ctx); } else if(!strcmp(type,"multitier")) { cache = mapcache_cache_multitier_create(ctx); } else if(!strcmp(type,"composite")) { cache = mapcache_cache_composite_create(ctx); } else if(!strcmp(type,"rest")) { cache = mapcache_cache_rest_create(ctx); } else if(!strcmp(type,"s3")) { cache = mapcache_cache_s3_create(ctx); } else if(!strcmp(type,"azure")) { cache = mapcache_cache_azure_create(ctx); } else if(!strcmp(type,"google")) { cache = mapcache_cache_google_create(ctx); } else if(!strcmp(type,"bdb")) { cache = mapcache_cache_bdb_create(ctx); } else if(!strcmp(type,"tokyocabinet")) { cache = mapcache_cache_tc_create(ctx); } else if(!strcmp(type,"sqlite3")) { cache = mapcache_cache_sqlite_create(ctx); } else if(!strcmp(type,"mbtiles")) { cache = mapcache_cache_mbtiles_create(ctx); } else if(!strcmp(type,"memcache")) { cache = mapcache_cache_memcache_create(ctx); } else if(!strcmp(type,"tiff")) { cache = mapcache_cache_tiff_create(ctx); } else if(!strcmp(type,"couchbase")) { cache = mapcache_cache_couchbase_create(ctx); } else if(!strcmp(type,"riak")) { cache = mapcache_cache_riak_create(ctx); } else { ctx->set_error(ctx, 400, "unknown cache type %s for cache \"%s\"", type, name); return; } GC_CHECK_ERROR(ctx); if(cache == NULL) { ctx->set_error(ctx, 400, "failed to parse cache \"%s\"", name); return; } cache->name = name; if ((cur_node = ezxml_child(node,"retries")) != NULL) { cache->retry_count = atoi(cur_node->txt); if(cache->retry_count > 10) { ctx->set_error(ctx,400,"cache (%s) <retries> count of %d is unreasonably large. max is 10", cache->name, cache->retry_count); return; } } if ((cur_node = ezxml_child(node,"retry_delay")) != NULL) { cache->retry_delay = (double)atof(cur_node->txt); if(cache->retry_delay < 0) { ctx->set_error(ctx,400,"cache (%s) retry delay of %f must be positive",cache->name, cache->retry_delay); return; } } cache->configuration_parse_xml(ctx,node,cache,config); GC_CHECK_ERROR(ctx); mapcache_configuration_add_cache(config,cache,name); return; }
void parseCache(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config) { char *name = NULL, *type = NULL; mapcache_cache *cache = NULL; name = (char*)ezxml_attr(node,"name"); type = (char*)ezxml_attr(node,"type"); if(!name || !strlen(name)) { ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <cache>"); return; } else { name = apr_pstrdup(ctx->pool, name); /* check we don't already have a cache defined with this name */ if(mapcache_configuration_get_cache(config, name)) { ctx->set_error(ctx, 400, "duplicate cache with name \"%s\"",name); return; } } if(!type || !strlen(type)) { ctx->set_error(ctx, 400, "mandatory attribute \"type\" not found in <cache>"); return; } if(!strcmp(type,"disk")) { cache = mapcache_cache_disk_create(ctx); } else if(!strcmp(type,"bdb")) { #ifdef USE_BDB cache = mapcache_cache_bdb_create(ctx); #else ctx->set_error(ctx,400, "failed to add cache \"%s\": Berkeley DB support is not available on this build",name); return; #endif } else if(!strcmp(type,"sqlite3")) { #ifdef USE_SQLITE cache = mapcache_cache_sqlite_create(ctx); #else ctx->set_error(ctx,400, "failed to add cache \"%s\": sqlite support is not available on this build",name); return; #endif } else if(!strcmp(type,"mbtiles")) { #ifdef USE_SQLITE cache = mapcache_cache_mbtiles_create(ctx); #else ctx->set_error(ctx,400, "failed to add cache \"%s\": sqlite support is not available on this build",name); return; #endif } else if(!strcmp(type,"memcache")) { #ifdef USE_MEMCACHE cache = mapcache_cache_memcache_create(ctx); #else ctx->set_error(ctx,400, "failed to add cache \"%s\": memcache support is not available on this build",name); return; #endif } else if(!strcmp(type,"tiff")) { #ifdef USE_TIFF cache = mapcache_cache_tiff_create(ctx); #else ctx->set_error(ctx,400, "failed to add cache \"%s\": tiff support is not available on this build",name); return; #endif } else { ctx->set_error(ctx, 400, "unknown cache type %s for cache \"%s\"", type, name); return; } if(cache == NULL) { ctx->set_error(ctx, 400, "failed to parse cache \"%s\"", name); return; } cache->name = name; cache->configuration_parse_xml(ctx,node,cache,config); GC_CHECK_ERROR(ctx); mapcache_configuration_add_cache(config,cache,name); return; }