/** * \brief creates and initializes a mapcache_sqlite_cache */ mapcache_cache* mapcache_cache_mbtiles_create(mapcache_context *ctx) { mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*) mapcache_cache_sqlite_create(ctx); if (!cache) { return NULL; } cache->cache.configuration_post_config = _mapcache_cache_mbtiles_configuration_post_config; cache->cache.tile_set = _mapcache_cache_mbtiles_set; cache->cache.tile_multi_set = _mapcache_cache_mbtiles_multi_set; cache->cache.tile_delete = _mapcache_cache_mbtiles_delete; cache->create_stmt.sql = apr_pstrdup(ctx->pool, "create table if not exists images(tile_id text, tile_data blob, primary key(tile_id));"\ "CREATE TABLE IF NOT EXISTS map (zoom_level integer, tile_column integer, tile_row integer, tile_id text, foreign key(tile_id) references images(tile_id), primary key(tile_row,tile_column,zoom_level));"\ "create table if not exists metadata(name text, value text);"\ "create view if not exists tiles AS SELECT map.zoom_level AS zoom_level, map.tile_column AS tile_column, map.tile_row AS tile_row, images.tile_data AS tile_data FROM map JOIN images ON images.tile_id = map.tile_id;" ); cache->exists_stmt.sql = apr_pstrdup(ctx->pool, "select 1 from tiles where tile_column=:x and tile_row=:y and zoom_level=:z"); cache->get_stmt.sql = apr_pstrdup(ctx->pool, "select tile_data from tiles where tile_column=:x and tile_row=:y and zoom_level=:z"); cache->delete_stmt.sql = apr_pstrdup(ctx->pool, "delete from tiles where tile_column=:x and tile_row=:y and zoom_level=:z"); cache->n_prepared_statements = 9; cache->bind_stmt = _bind_mbtiles_params; return (mapcache_cache*) cache; }
/** * \brief creates and initializes a mapcache_sqlite_cache */ mapcache_cache* mapcache_cache_mbtiles_create(mapcache_context *ctx) { mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*)mapcache_cache_sqlite_create(ctx); if(!cache) { return NULL; } cache->create_stmt.sql = apr_pstrdup(ctx->pool, "CREATE TABLE IF NOT EXISTS tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob, primary key(tile_row, tile_column, zoom_level)); create table if not exists metadata(name text, value text);"); cache->exists_stmt.sql = apr_pstrdup(ctx->pool, "select 1 from tiles where tile_column=:x and tile_row=:y and zoom_level=:z"); cache->get_stmt.sql = apr_pstrdup(ctx->pool, "select tile_data from tiles where tile_column=:x and tile_row=:y and zoom_level=:z"); cache->set_stmt.sql = apr_pstrdup(ctx->pool, "insert or replace into tiles(tile_column,tile_row,zoom_level,tile_data) values (:x,:y,:z,:data)"); cache->delete_stmt.sql = apr_pstrdup(ctx->pool, "delete from tiles where tile_column=:x and tile_row=:y and zoom_level=:z"); cache->hitstat_stmt.sql = apr_pstrdup(ctx->pool, "select 1"); return (mapcache_cache*)cache; }
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; }