[mapserver-commits] r12202 - in trunk/mapserver/mapcache: include src

svn at osgeo.org svn at osgeo.org
Fri Aug 26 07:06:46 EDT 2011


Author: tbonfort
Date: 2011-08-26 04:06:46 -0700 (Fri, 26 Aug 2011)
New Revision: 12202

Modified:
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/fastcgi_geocache.c
   trunk/mapserver/mapcache/src/imageio_jpeg.c
   trunk/mapserver/mapcache/src/imageio_png.c
   trunk/mapserver/mapcache/src/mod_geocache.c
   trunk/mapserver/mapcache/src/services.c
Log:
use source defined srs rather than tileset one (and print a warning if they are different when loading the config file)
thomas.bonfort | 2011-01-06 12:55:45 +0100 (Thu, 06 Jan 2011)

Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:06:40 UTC (rev 12201)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:06:46 UTC (rev 12202)
@@ -63,6 +63,11 @@
 typedef struct geocache_source_gdal geocache_source_gdal;
 typedef struct geocache_cache_disk geocache_cache_disk;
 typedef struct geocache_request geocache_request;
+typedef struct geocache_request_get_capabilities geocache_request_get_capabilities;
+typedef struct geocache_request_get_capabilities_wms geocache_request_get_capabilities_wms;
+typedef struct geocache_request_get_capabilities_tms geocache_request_get_capabilities_tms;
+
+typedef struct geocache_request_get_tile geocache_request_get_tile;
 typedef struct geocache_service geocache_service;
 typedef struct geocache_service_wms geocache_service_wms;
 typedef struct geocache_service_wmts geocache_service_wmts;
@@ -287,29 +292,59 @@
 typedef enum {
    GEOCACHE_REQUEST_UNKNOWN,
    GEOCACHE_REQUEST_GET_TILE,
-   GEOCACHE_REQUEST_GET_CAPABILITIES
+   GEOCACHE_REQUEST_GET_MAP,
+   GEOCACHE_REQUEST_GET_CAPABILITIES,
 } geocache_request_type;
 /**
  * \brief a request sent by a client
  */
+
 struct geocache_request {
    geocache_request_type type;
+};
 
+struct geocache_request_get_tile {
+   geocache_request request;
+
+   /**
+    * a list of tiles requested by the client
+    */
+   geocache_tile **tiles;
+
+   /**
+    * the number of tiles requested by the client.
+    * If more than one, and merging is enabled,
+    * the supplied tiles will be merged together
+    * before being returned to the client
+    */
+   int ntiles;
+};
+
+struct geocache_request_get_capabilities {
+   geocache_request request;
+
+   /**
+    * the body of the capabilities
+    */
    char *capabilities;
-    /**
-     * a list of tiles requested by the client
-     */
-    geocache_tile **tiles;
 
-    /**
-     * the number of tiles requested by the client.
-     * If more than one, and merging is enabled,
-     * the supplied tiles will be merged together
-     * before being returned to the client
-     */
-    int ntiles;
+   /**
+    * the mime type
+    */
+   char *mime_type;
 };
 
+struct geocache_request_get_capabilities_tms {
+   geocache_request_get_capabilities request;
+   geocache_tileset *tileset;
+   char *version;
+};
+
+struct geocache_request_get_capabilities_wms {
+   geocache_request_get_capabilities request;
+   char *version;
+};
+
 /** \defgroup services Services*/
 /** @{ */
 
@@ -330,9 +365,15 @@
     geocache_service_type type;
     /**
      * \returns a geocache_request corresponding to the parameters received
-     * \returns NULL if the request does not correspond the the service
+     * \returns NULL if the request does not correspond to the service
      */
-    geocache_request * (*parse_request)(geocache_context *ctx, char *uri, char *path_info, apr_table_t *params, geocache_cfg * config);
+    geocache_request * (*parse_request)(geocache_context *ctx, char *path_info, apr_table_t *params, geocache_cfg * config);
+
+    /**
+     * \param request the received request (should be of type GEOCACHE_REQUEST_CAPABILITIES
+     * \param url the full url at which the service is available
+     */
+    void (*create_capabilities_response)(geocache_context *ctx, geocache_request_get_capabilities *request, char *url, char *path_info, geocache_cfg *config);
 };
 
 /**\class geocache_service_wms
@@ -776,6 +817,7 @@
 struct geocache_image_format {
     char *name; /**< the key by which this format will be referenced */
     char *extension; /**< the extension to use when saving a file with this format */
+    char *mime_type;
     geocache_buffer * (*write)(geocache_context *ctx, geocache_image *image, geocache_image_format * format);
     /**< pointer to a function that returns a geocache_buffer containing the given image encoded
      * in the specified format

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:06:40 UTC (rev 12201)
+++ trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:06:46 UTC (rev 12202)
@@ -65,7 +65,7 @@
          0.597164283371
    };
    double wgs84_extent[4]={-180,-90,180,90};
-   double google_extent[4]={-20037508.3392,-20037508.3392,20037508.3392,20037508.3392};
+   double google_extent[4]={-20037508.34,-20037508.34,20037508.34,20037508.34};
 
    geocache_cfg *cfg = (geocache_cfg*)apr_pcalloc(pool, sizeof(geocache_cfg));
    cfg->caches = apr_hash_make(pool);

Modified: trunk/mapserver/mapcache/src/fastcgi_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/fastcgi_geocache.c	2011-08-26 11:06:40 UTC (rev 12201)
+++ trunk/mapserver/mapcache/src/fastcgi_geocache.c	2011-08-26 11:06:46 UTC (rev 12202)
@@ -151,8 +151,8 @@
    return 200;
 }
 
-static int geocache_write_capabilities(geocache_context_fcgi_request *ctx, geocache_request *request) {
-   FCGX_FPrintF(ctx->out,"Content-type: text/xml\r\n\r\n");
+static int geocache_write_capabilities(geocache_context_fcgi_request *ctx, geocache_request_get_capabilities *request) {
+   FCGX_FPrintF(ctx->out,"Content-type: %s\r\n\r\n",request->mime_type);
    FCGX_PutStr(request->capabilities, strlen(request->capabilities),ctx->out);
 
    return 200;
@@ -185,54 +185,59 @@
       apr_table_t *params;
       geocache_context *ctx = (geocache_context*) fcgi_context_request_create(globalctx,out,err); 
       geocache_tile *tile;
+      geocache_service *service;
       geocache_request *request = NULL;
-      char *host = FCGX_GetParam("SERVER_NAME",envp);
-      char *port = FCGX_GetParam("SERVER_PORT",envp);
-      char *fullhost;
-      if(FCGX_GetParam("HTTPS",envp)) {
-         if(!port || !strcmp(port,"443")) {
-            fullhost = apr_psprintf(ctx->pool,"https://%s",host);
-         } else {
-            fullhost = apr_psprintf(ctx->pool,"https://%s:%s",host,port);
-         }
-      } else {
-         if(!port || !strcmp(port,"80")) {
-            fullhost = apr_psprintf(ctx->pool,"http://%s",host);
-         } else {
-            fullhost = apr_psprintf(ctx->pool,"http://%s:%s",host,port);
-         }
-      }
       char *pathInfo = FCGX_GetParam("PATH_INFO",envp);
-      char *uri = apr_psprintf(ctx->pool,"%s%s",
-            fullhost,
-            FCGX_GetParam("SCRIPT_NAME",envp)
-            );
-
       int i;
+      
 
-
       params = geocache_http_parse_param_string((geocache_context*)ctx, FCGX_GetParam("QUERY_STRING",envp));
-
       for(i=0;i<GEOCACHE_SERVICES_COUNT;i++) {
-         geocache_service *service = cfg->services[i];
+         service = cfg->services[i];
          if(!service) continue;
-         request = service->parse_request(ctx,uri,pathInfo,params,cfg);
+         request = service->parse_request(ctx,pathInfo,params,cfg);
          if(request)
             break;
       }
+      
       if(!request || GC_HAS_ERROR(ctx)) {
          FCGX_FPrintF(out,"Status: 404 Not Found\r\n\r\n");
          goto cleanup;
       }
       if(request->type == GEOCACHE_REQUEST_GET_CAPABILITIES) {
-         geocache_write_capabilities((geocache_context_fcgi_request*)ctx,request);
+         geocache_request_get_capabilities *req = (geocache_request_get_capabilities*)request;
+         char *host = FCGX_GetParam("SERVER_NAME",envp);
+         char *port = FCGX_GetParam("SERVER_PORT",envp);
+         char *fullhost;
+         char *url;
+         if(FCGX_GetParam("HTTPS",envp)) {
+            if(!port || !strcmp(port,"443")) {
+               fullhost = apr_psprintf(ctx->pool,"https://%s",host);
+            } else {
+               fullhost = apr_psprintf(ctx->pool,"https://%s:%s",host,port);
+            }
+         } else {
+            if(!port || !strcmp(port,"80")) {
+               fullhost = apr_psprintf(ctx->pool,"http://%s",host);
+            } else {
+               fullhost = apr_psprintf(ctx->pool,"http://%s:%s",host,port);
+            }
+         }
+         url = apr_psprintf(ctx->pool,"%s%s",
+               fullhost,
+               FCGX_GetParam("SCRIPT_NAME",envp)
+               );
+         ctx->log(ctx,GEOCACHE_INFO,"toto");
+         service->create_capabilities_response(ctx,req,url,pathInfo,cfg);
+         geocache_write_capabilities((geocache_context_fcgi_request*)ctx,req);
       } else {
-         if(!request->ntiles) {
+         geocache_request_get_tile *req = (geocache_request_get_tile*)request;
+         if(!req->ntiles) {
             FCGX_FPrintF(out,"Status: 404 Not Found\r\n\r\n");
             goto cleanup;
          }
-         for(i=0;i<request->ntiles;i++) {
-            geocache_tile *tile = request->tiles[i];
+         for(i=0;i<req->ntiles;i++) {
+            geocache_tile *tile = req->tiles[i];
             geocache_tileset_tile_get(ctx,tile);
             if(GC_HAS_ERROR(ctx)) {
                ctx->log(ctx,GEOCACHE_DEBUG,ctx->get_error_message(ctx));
@@ -240,10 +245,10 @@
                goto cleanup;
             }
          }
-         if(request->ntiles == 1) {
-            tile = request->tiles[0];
+         if(req->ntiles == 1) {
+            tile = req->tiles[0];
          } else {
-            tile = geocache_image_merge_tiles(ctx,cfg->merge_format,request->tiles,request->ntiles);
+            tile = geocache_image_merge_tiles(ctx,cfg->merge_format,req->tiles,req->ntiles);
             if(!tile) {
                ctx->log(ctx,GEOCACHE_ERROR, "tile merging failed to return data");
                if(ctx->get_error(ctx)) {
@@ -254,7 +259,7 @@
                FCGX_FPrintF(out,"Status: 500 Internal Server Error\r\n\r\n");
                goto cleanup;
             }
-            tile->tileset = request->tiles[0]->tileset;
+            tile->tileset = req->tiles[0]->tileset;
          }
          geocache_write_tile((geocache_context_fcgi_request*)ctx,tile);
       }

Modified: trunk/mapserver/mapcache/src/imageio_jpeg.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_jpeg.c	2011-08-26 11:06:40 UTC (rev 12201)
+++ trunk/mapserver/mapcache/src/imageio_jpeg.c	2011-08-26 11:06:46 UTC (rev 12202)
@@ -15,6 +15,7 @@
  */
 
 #include "geocache.h"
+#include <apr_strings.h>
 #include <jpeglib.h>
 
 /**\addtogroup imageio_jpg */
@@ -254,7 +255,9 @@
 geocache_image_format* geocache_imageio_create_jpeg_format(apr_pool_t *pool, char *name, int quality ) {
    geocache_image_format_jpeg *format = apr_pcalloc(pool, sizeof(geocache_image_format_jpeg));
    format->format.name = name;
-   format->format.extension = "jpg";
+   format->format.extension = apr_pstrdup(pool,"jpg");
+   format->format.mime_type = apr_pstrdup(pool,"image/jpeg");
+
    format->format.write = _geocache_imageio_jpeg_encode;
    format->quality = quality;
    return (geocache_image_format*)format;

Modified: trunk/mapserver/mapcache/src/imageio_png.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_png.c	2011-08-26 11:06:40 UTC (rev 12201)
+++ trunk/mapserver/mapcache/src/imageio_png.c	2011-08-26 11:06:46 UTC (rev 12202)
@@ -16,7 +16,9 @@
 
 #include "geocache.h"
 #include <png.h>
+#include <apr_strings.h>
 
+
 /**\addtogroup imageio_png */
 /** @{ */
 typedef struct _geocache_buffer_closure _geocache_buffer_closure;
@@ -1066,7 +1068,8 @@
 geocache_image_format* geocache_imageio_create_png_format(apr_pool_t *pool, char *name, geocache_compression_type compression) {
    geocache_image_format_png *format = apr_pcalloc(pool, sizeof(geocache_image_format_png));
    format->format.name = name;
-   format->format.extension = "png";
+   format->format.extension = apr_pstrdup(pool,"png");
+   format->format.mime_type = apr_pstrdup(pool,"image/png");
    format->compression_level = compression;
    format->format.write = _geocache_imageio_png_encode;
    return (geocache_image_format*)format;
@@ -1075,7 +1078,8 @@
 geocache_image_format* geocache_imageio_create_png_q_format(apr_pool_t *pool, char *name, geocache_compression_type compression, int ncolors) {
    geocache_image_format_png_q *format = apr_pcalloc(pool, sizeof(geocache_image_format_png_q));
    format->format.format.name = name;
-   format->format.format.extension = "png";
+   format->format.format.extension = apr_pstrdup(pool,"png");
+   format->format.format.mime_type = apr_pstrdup(pool,"image/png");
    format->format.compression_level = compression;
    format->format.format.write = _geocache_imageio_png_q_encode;
    format->ncolors = ncolors;

Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:06:40 UTC (rev 12201)
+++ trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:06:46 UTC (rev 12202)
@@ -171,10 +171,7 @@
    ap_set_last_modified(r);
    ap_set_content_length(r,tile->data->size);
    if(tile->tileset->format) {
-      if(!strcmp(tile->tileset->format->extension,"png"))
-         ap_set_content_type(r, "image/png");
-      else
-         ap_set_content_type(r, "image/jpeg");
+      ap_set_content_type(r, tile->tileset->format->mime_type);
    } else {
       geocache_image_format_type t = geocache_imageio_header_sniff((geocache_context*)ctx,tile->data);
       if(t == GC_PNG)
@@ -191,9 +188,9 @@
    return OK;
 }
 
-static int geocache_write_capabilities(geocache_context_apache_request *ctx, geocache_request *request) {
+static int geocache_write_capabilities(geocache_context_apache_request *ctx, geocache_request_get_capabilities *request) {
    request_rec *r = ctx->request;
-   ap_set_content_type(r, "text/xml");
+   ap_set_content_type(r, request->mime_type);
    ap_rputs(request->capabilities, r);
 
    return OK;
@@ -203,12 +200,13 @@
    apr_table_t *params;
    geocache_cfg *config = NULL;
    geocache_request *request = NULL;
+   geocache_request_get_tile *req_tile = NULL;
+
    geocache_context_apache_request *apache_ctx = apache_request_context_create(r); 
    geocache_context *global_ctx = (geocache_context*)apache_ctx;
    geocache_tile *tile;
-   request_rec *original;
+   geocache_service *service;
    int i,ret;
-   char *uri;
 
    if (!r->handler || strcmp(r->handler, "geocache")) {
       return DECLINED;
@@ -219,16 +217,12 @@
 
    params = geocache_http_parse_param_string(global_ctx, r->args);
    config = ap_get_module_config(r->per_dir_config, &geocache_module);
-   if(r->main)
-      original = r->main;
-   else
-      original = r;
-   uri = ap_construct_url(r->pool,original->parsed_uri.path,original);
+
    for(i=0;i<GEOCACHE_SERVICES_COUNT;i++) {
       /* loop through the services that have been configured */
-      geocache_service *service = config->services[i];
+      service = config->services[i];
       if(!service) continue;
-      request = service->parse_request(global_ctx,uri,original->path_info,params,config);
+      request = service->parse_request(global_ctx,r->path_info,params,config);
       /* the service has recognized the request if it returns a non NULL value */
       if(request || GC_HAS_ERROR(global_ctx))
          break;
@@ -238,28 +232,53 @@
    }
 
    if(request->type == GEOCACHE_REQUEST_GET_CAPABILITIES) {
-      return geocache_write_capabilities(apache_ctx,request);
-   } else if( request->type != GEOCACHE_REQUEST_GET_TILE || !request->ntiles) {
+      geocache_request_get_capabilities *req_caps = (geocache_request_get_capabilities*)request;
+      request_rec *original;
+      char *url;
+      if(r->main)
+         original = r->main;
+      else
+         original = r;
+      url = ap_construct_url(r->pool,original->uri,original);
+
+      /*
+       * remove the path_info from the end of the url (we want the url of the base of the service)
+       * TODO: is there an apache api to access this ?
+       */
+      if(*(original->path_info)) {
+         char *end = strstr(url,original->path_info);
+         if(end) {
+            *end = '\0';
+         }
+      }
+      service->create_capabilities_response(global_ctx,req_caps,url,original->path_info,config);
+      return geocache_write_capabilities(apache_ctx,req_caps);
+   } else if( request->type != GEOCACHE_REQUEST_GET_TILE) {
       return report_error(HTTP_BAD_REQUEST, apache_ctx);
    }
+   req_tile = (geocache_request_get_tile*)request;
 
+   if( !req_tile->ntiles) {
+      return report_error(HTTP_BAD_REQUEST, apache_ctx);
+   }
 
-   for(i=0;i<request->ntiles;i++) {
-      geocache_tile *tile = request->tiles[i];
+
+   for(i=0;i<req_tile->ntiles;i++) {
+      geocache_tile *tile = req_tile->tiles[i];
       geocache_tileset_tile_get(global_ctx, tile);
       if(GC_HAS_ERROR(global_ctx)) {
          return report_error(HTTP_INTERNAL_SERVER_ERROR, apache_ctx);
       }
    }
-   if(request->ntiles == 1) {
-      tile = request->tiles[0];
+   if(req_tile->ntiles == 1) {
+      tile = req_tile->tiles[0];
    } else {
       /* TODO: individual check on tiles if merging is allowed */
-      tile = (geocache_tile*)geocache_image_merge_tiles(global_ctx,config->merge_format,request->tiles,request->ntiles);
+      tile = (geocache_tile*)geocache_image_merge_tiles(global_ctx,config->merge_format,req_tile->tiles,req_tile->ntiles);
       if(!tile || GC_HAS_ERROR(global_ctx)) {
          return report_error(HTTP_INTERNAL_SERVER_ERROR, apache_ctx);
       }
-      tile->tileset = request->tiles[0]->tileset;
+      tile->tileset = req_tile->tiles[0]->tileset;
    }
    ret = geocache_write_tile(apache_ctx,tile);
    return ret;

Modified: trunk/mapserver/mapcache/src/services.c
===================================================================
--- trunk/mapserver/mapcache/src/services.c	2011-08-26 11:06:40 UTC (rev 12201)
+++ trunk/mapserver/mapcache/src/services.c	2011-08-26 11:06:46 UTC (rev 12202)
@@ -80,11 +80,15 @@
               "<BoundingBox srs=\"%s\" minx=\"%f\" miny=\"%f\" maxx=\"%f\" maxy=\"%f\" />\n"
             "</Layer>\n";
 
-geocache_request* _geocache_service_wms_capabilities(geocache_context *ctx, char *uri, geocache_cfg *cfg) {
-   geocache_request *request = (geocache_request*)apr_pcalloc(ctx->pool,sizeof(geocache_request));
-   request->type = GEOCACHE_REQUEST_GET_CAPABILITIES;
-   char *host = uri;
-   char *caps = apr_psprintf(ctx->pool,wms_capabilities_preamble,host,host,host);
+void _create_capabilities_wms(geocache_context *ctx, geocache_request_get_capabilities *req, char *url, char *path_info, geocache_cfg *cfg) {
+   geocache_request_get_capabilities_wms *request = (geocache_request_get_capabilities_wms*)req;
+#ifdef DEBUG
+   if(request->request.request.type != GEOCACHE_REQUEST_GET_CAPABILITIES) {
+      ctx->set_error(ctx,GEOCACHE_ERROR,"wrong wms capabilities request");
+      return;
+   }
+#endif
+   char *caps = apr_psprintf(ctx->pool,wms_capabilities_preamble,url,url,url);
    apr_hash_index_t *tileindex_index = apr_hash_first(ctx->pool,cfg->tilesets);
 
    while(tileindex_index) {
@@ -94,7 +98,7 @@
       char *resolutions="";
       int i;
       for(i=0;i<tileset->grid->levels;i++) {
-         resolutions = apr_psprintf(ctx->pool,"%s%f ",resolutions,tileset->grid->resolutions[i]);
+         resolutions = apr_psprintf(ctx->pool,"%s%.20f ",resolutions,tileset->grid->resolutions[i]);
       }
       char *tilesetcaps = apr_psprintf(ctx->pool,wms_tileset,
             tileset->grid->srs,
@@ -136,20 +140,103 @@
    caps = apr_psprintf(ctx->pool,"%s%s",caps,"</Layer>\n"
              "</Capability>\n"
            "</WMT_MS_Capabilities>\n");
-   request->capabilities = caps;
-   return request;
+   request->request.capabilities = caps;
+   request->request.mime_type = apr_pstrdup(ctx->pool,"text/xml");
 }
 
+static const char *tms_0 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+      "<Services>\n"
+      "<TileMapService version=\"1.0.0\" href=\"%s/1.0.0/\" />\n"
+      "</Services>\n";
+
+static const char *tms_1 = "<TileMap \n"
+      "href=\"%s/%s/%s/\"\n"
+      "srs=\"%s\"\n"
+      "title=\"%s\"\n"
+      "profile=\"global-geodetic\" />";
+
+static const char *tms_2="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+      "<TileMap version=\"%s\" tilemapservice=\"%s/%s/\">\n"
+      "<Title>%s</Title>\n"
+      "<Abstract/>\n"
+      "<SRS>%s</SRS>\n"
+      "<BoundingBox minx=\"%f\" miny=\"%f\" maxx=\"%f\" maxy=\"%f\"/>\n"
+      "<Origin x=\"%f\" y=\"%f\"/>\n"
+      "<TileFormat width=\"%d\" height=\"%d\" mime-type=\"%s\" extension=\"%s\"/>\n"
+      "<TileSets>\n";
+
+
+void _create_capabilities_tms(geocache_context *ctx, geocache_request_get_capabilities *req, char *url, char *path_info, geocache_cfg *cfg) {
+   geocache_request_get_capabilities_tms *request = (geocache_request_get_capabilities_tms*)req;
+#ifdef DEBUG
+   if(request->request.request.type != GEOCACHE_REQUEST_GET_CAPABILITIES) {
+      ctx->set_error(ctx,GEOCACHE_ERROR,"wrong tms capabilities request");
+      return;
+   }
+#endif
+   char *caps;
+   request->request.mime_type = apr_pstrdup(ctx->pool,"text/xml");
+   if(!request->version) {
+      caps = apr_psprintf(ctx->pool,tms_0,url);
+   } else {
+      if(!request->tileset) {
+         caps = apr_psprintf(ctx->pool,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+               "<TileMapService version=\"%s\">\n"
+               "<TileMaps>",
+               request->version);
+         apr_hash_index_t *tileindex_index = apr_hash_first(ctx->pool,cfg->tilesets);
+
+         while(tileindex_index) {
+            geocache_tileset *tileset;
+            char *tilesetcaps;
+            const void *key; apr_ssize_t keylen;
+            apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);
+            tilesetcaps = apr_psprintf(ctx->pool,tms_1,url,request->version,tileset->name,tileset->grid->srs,tileset->name);
+            caps = apr_psprintf(ctx->pool,"%s%s",caps,tilesetcaps);
+            tileindex_index = apr_hash_next(tileindex_index);
+         }
+         caps = apr_psprintf(ctx->pool,"%s</TileMaps>\n</TileMapService>\n",caps);
+
+      } else {
+         geocache_tileset *tileset = request->tileset;
+         geocache_grid *grid = tileset->grid;
+         int i;
+         caps = apr_psprintf(ctx->pool,tms_2,
+               request->version, url, request->version,
+               tileset->name, grid->srs,
+               grid->extents[0][0], grid->extents[0][1],
+               grid->extents[0][2], grid->extents[0][3],
+               grid->extents[0][0], grid->extents[0][1],
+               grid->tile_sx, grid->tile_sy,
+               tileset->format->mime_type,
+               tileset->format->extension
+         );
+         for(i=0;i<grid->levels;i++) {
+            caps = apr_psprintf(ctx->pool,"%s\n<TileSet href=\"%s/%s/%s/%d\" units-per-pixel=\"%.20f\" order=\"%d\"/>",
+                  caps,url,request->version,tileset->name,i,
+                  grid->resolutions[i],i
+            );
+         }
+         
+         request->request.capabilities = apr_psprintf(ctx->pool,"info about layer %s",request->tileset->name);
+         caps = apr_psprintf(ctx->pool,"%s</TileSets>\n</TileMap>\n",caps);
+      }
+   }
+   request->request.capabilities = caps;
+
+
+}
+
+
 /**
  * \brief parse a WMS request
  * \private \memberof geocache_service_wms
  * \sa geocache_service::parse_request()
  */
-geocache_request* _geocache_service_wms_parse_request(geocache_context *ctx, char *uri, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
+geocache_request* _geocache_service_wms_parse_request(geocache_context *ctx, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
    char *str = NULL, *srs=NULL;
    int width=0, height=0;
    double *bbox;
-   geocache_request *request = NULL;
    
    str = (char*)apr_table_get(params,"SERVICE");
    if(!str)
@@ -166,7 +253,10 @@
       return NULL;
    }
    if( ! strcasecmp(str,"getcapabilities") ) {
-      return _geocache_service_wms_capabilities(ctx, uri, config);
+      geocache_request_get_capabilities_wms *request = (geocache_request_get_capabilities_wms*)
+            apr_pcalloc(ctx->pool,sizeof(geocache_request_get_capabilities_wms));
+      request->request.request.type = GEOCACHE_REQUEST_GET_CAPABILITIES;
+      return (geocache_request*)request;
    } else if( strcasecmp(str,"getmap")) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms with invalid request %s",str);
       return NULL;
@@ -236,8 +326,9 @@
       char *last, *key;
       int count=1;
       char *sep=",";
-      request = (geocache_request*)apr_pcalloc(ctx->pool,sizeof(geocache_request));
-      request->type = GEOCACHE_REQUEST_GET_TILE;
+      geocache_request_get_tile *request = (geocache_request_get_tile*)apr_pcalloc(
+            ctx->pool,sizeof(geocache_request_get_tile));
+      request->request.type = GEOCACHE_REQUEST_GET_TILE;
       str = apr_pstrdup(ctx->pool,str);
       for(key=str;*key;key++) if(*key == ',') count++;
       request->ntiles = 0;
@@ -281,8 +372,8 @@
          }
          request->tiles[request->ntiles++] = tile;
       }
+      return (geocache_request*)request;
    }
-   return request;
 }
 
 /**
@@ -290,63 +381,78 @@
  * \private \memberof geocache_service_tms
  * \sa geocache_service::parse_request()
  */
-geocache_request* _geocache_service_tms_parse_request(geocache_context *ctx, char *uri, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
+geocache_request* _geocache_service_tms_parse_request(geocache_context *ctx, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
    int index = 0;
    char *last, *key, *endptr;
    geocache_tileset *tileset = NULL;
-   geocache_tile *tile = NULL;
-   geocache_request *request = NULL;
-   /* parse a path_info like /1.0.0/global_mosaic/0/0/0.jpg */ 
-   for (key = apr_strtok(pathinfo, "/", &last); key != NULL;
-         key = apr_strtok(NULL, "/", &last)) {
-      if(!*key) continue; /* skip an empty string, could happen if the url contains // */
-      switch(++index) {
-      case 1: /* version */
-         if(strcmp("1.0.0",key)) {
-            //r->log(r,GEOCACHE_INFO, "received tms request with invalid version %s", key);
+   int x,y,z;
+   /* parse a path_info like /1.0.0/global_mosaic/0/0/0.jpg */
+   if(pathinfo) {
+      for (key = apr_strtok(pathinfo, "/", &last); key != NULL;
+            key = apr_strtok(NULL, "/", &last)) {
+         if(!*key) continue; /* skip an empty string, could happen if the url contains // */
+         switch(++index) {
+         case 1: /* version */
+            if(strcmp("1.0.0",key)) {
+               //r->log(r,GEOCACHE_INFO, "received tms request with invalid version %s", key);
+               return NULL;
+            }
+            break;
+         case 2: /* layer name */
+            tileset = geocache_configuration_get_tileset(config,key);
+            if(!tileset) {
+               ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request with invalid layer %s", key);
+               return NULL;
+            }
+            break;
+         case 3:
+            z = (int)strtol(key,&endptr,10);
+            if(*endptr != 0) {
+               ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid z %s", pathinfo, key);
+               return NULL;
+            }
+            break;
+         case 4:
+            x = (int)strtol(key,&endptr,10);
+            if(*endptr != 0) {
+               ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid x %s", pathinfo, key);
+               return NULL;
+            }
+            break;
+         case 5:
+            y = (int)strtol(key,&endptr,10);
+            if(*endptr != '.') {
+               ctx->log(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid y %s", pathinfo, key);
+               return NULL;
+            }
+            break;
+         default:
+            ctx->log(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid parameter %s", pathinfo, key);
             return NULL;
          }
-         break;
-      case 2: /* layer name */
-         tileset = geocache_configuration_get_tileset(config,key);
-         if(!tileset) {
-            ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request with invalid layer %s", key);
-            return NULL;
-         }
-         request = (geocache_request*)apr_pcalloc(ctx->pool,sizeof(geocache_request));
-         request->ntiles = 1;
-         request->tiles = (geocache_tile**)apr_pcalloc(ctx->pool,sizeof(geocache_tile*)); 
-         tile = geocache_tileset_tile_create(ctx->pool, tileset);
-         request->tiles[0]=tile;
-         break;
-      case 3:
-         tile->z = (int)strtol(key,&endptr,10);
-         if(*endptr != 0) {
-            ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid z %s", pathinfo, key);
-            return NULL;
-         }
-         break;
-      case 4:
-         tile->x = (int)strtol(key,&endptr,10);
-         if(*endptr != 0) {
-            ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid x %s", pathinfo, key);
-            return NULL;
-         }
-         break;
-      case 5:
-         tile->y = (int)strtol(key,&endptr,10);
-         if(*endptr != '.') {
-            ctx->log(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid y %s", pathinfo, key);
-            return NULL;
-         }
-         break;
-      default:
-         ctx->log(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid parameter %s", pathinfo, key);
-         return NULL;
       }
    }
    if(index == 5) {
-      return request;
+      geocache_request_get_tile *request = (geocache_request_get_tile*)apr_pcalloc(ctx->pool,sizeof(geocache_request_get_tile));
+      request->request.type = GEOCACHE_REQUEST_GET_TILE;
+      request->ntiles = 1;
+      request->tiles = (geocache_tile**)apr_pcalloc(ctx->pool,sizeof(geocache_tile*));
+      request->tiles[0] = geocache_tileset_tile_create(ctx->pool, tileset);
+      request->tiles[0]->x = x;
+      request->tiles[0]->y = y;
+      request->tiles[0]->z = z;
+      return (geocache_request*)request;
+   } else if(index<3) {
+      geocache_request_get_capabilities_tms *request = (geocache_request_get_capabilities_tms*)apr_pcalloc(
+            ctx->pool,sizeof(geocache_request_get_capabilities_tms));
+      request->request.request.type = GEOCACHE_REQUEST_GET_CAPABILITIES;
+      if(index >= 2) {
+         request->tileset = tileset;
+      }
+      if(index >= 1) {
+         request->version = apr_pstrdup(ctx->pool,"1.0.0");
+      }
+      return (geocache_request*)request;
    }
    else {
       ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with wrong number of arguments", pathinfo);
@@ -362,6 +468,7 @@
    }
    service->service.type = GEOCACHE_SERVICE_WMS;
    service->service.parse_request = _geocache_service_wms_parse_request;
+   service->service.create_capabilities_response = _create_capabilities_wms;
    return (geocache_service*)service;
 }
 
@@ -373,6 +480,7 @@
    }
    service->service.type = GEOCACHE_SERVICE_TMS;
    service->service.parse_request = _geocache_service_tms_parse_request;
+   service->service.create_capabilities_response = _create_capabilities_tms;
    return (geocache_service*)service;
 }
 



More information about the mapserver-commits mailing list