Beispiel #1
0
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;
}