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

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


Author: tbonfort
Date: 2011-08-26 04:07:02 -0700 (Fri, 26 Aug 2011)
New Revision: 12205

Modified:
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/fastcgi_geocache.c
   trunk/mapserver/mapcache/src/mod_geocache.c
   trunk/mapserver/mapcache/src/services.c
   trunk/mapserver/mapcache/src/util.c
Log:
restore google grid to 900913, add GoogleMapsCompatible for epsg:3857
thomas.bonfort | 2011-01-06 19:29:25 +0100 (Thu, 06 Jan 2011)

Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:06:57 UTC (rev 12204)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:07:02 UTC (rev 12205)
@@ -302,6 +302,7 @@
 
 struct geocache_request {
    geocache_request_type type;
+   geocache_service *service;
 };
 
 struct geocache_request_get_tile {
@@ -369,11 +370,18 @@
  */
 struct geocache_service {
     geocache_service_type type;
+    
     /**
-     * \returns a geocache_request corresponding to the parameters received
-     * \returns NULL if the request does not correspond to the service
+     * the pathinfo prefix of the url that routes to this service
+     * eg, for accessing a wms service on http://host/geocache/mywmsservice? ,
+     * url_prefix would take the value "mywmsservice"
      */
-    geocache_request * (*parse_request)(geocache_context *ctx, char *path_info, apr_table_t *params, geocache_cfg * config);
+    char *url_prefix;
+    
+    /**
+     * \brief allocates and populates a geocache_request corresponding to the parameters received
+     */
+    void (*parse_request)(geocache_context *ctx, geocache_request **request, const char *path_info, apr_table_t *params, geocache_cfg * config);
 
     /**
      * \param request the received request (should be of type GEOCACHE_REQUEST_CAPABILITIES
@@ -424,6 +432,16 @@
  */
 geocache_service* geocache_service_wmts_create(geocache_context *ctx);
 
+/**
+ * \brief return the request that corresponds to the given url
+ */
+void geocache_service_dispatch_request(geocache_context *ctx,
+      geocache_request **request,
+      char *pathinfo,
+      apr_table_t *params,
+      geocache_cfg *config);
+
+
 /** @} */
 
 /** \defgroup image Image Data Handling */
@@ -797,9 +815,9 @@
 
 
 /* in util.c */
-int geocache_util_extract_int_list(geocache_context *ctx, char* args, const char sep, int **numbers,
+int geocache_util_extract_int_list(geocache_context *ctx, const char* args, const char sep, int **numbers,
         int *numbers_count);
-int geocache_util_extract_double_list(geocache_context *ctx, char* args, const char sep, double **numbers,
+int geocache_util_extract_double_list(geocache_context *ctx, const char* args, const char sep, double **numbers,
         int *numbers_count);
 
 /*

Modified: trunk/mapserver/mapcache/src/fastcgi_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/fastcgi_geocache.c	2011-08-26 11:06:57 UTC (rev 12204)
+++ trunk/mapserver/mapcache/src/fastcgi_geocache.c	2011-08-26 11:07:02 UTC (rev 12205)
@@ -185,25 +185,18 @@
       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 *pathInfo = FCGX_GetParam("PATH_INFO",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++) {
-         service = cfg->services[i];
-         if(!service) continue;
-         request = service->parse_request(ctx,pathInfo,params,cfg);
-         if(request)
-            break;
+      geocache_service_dispatch_request(ctx,&request,pathInfo,params,cfg);
+      if(GC_HAS_ERROR(ctx)) {
+        FCGX_FPrintF(out,"Status: 404 Not Found\r\n\r\n");
+        goto cleanup;
       }
       
-      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_request_get_capabilities *req = (geocache_request_get_capabilities*)request;
          char *host = FCGX_GetParam("SERVER_NAME",envp);
@@ -228,7 +221,7 @@
                FCGX_GetParam("SCRIPT_NAME",envp)
                );
          ctx->log(ctx,GEOCACHE_INFO,"toto");
-         service->create_capabilities_response(ctx,req,url,pathInfo,cfg);
+         request->service->create_capabilities_response(ctx,req,url,pathInfo,cfg);
          geocache_write_capabilities((geocache_context_fcgi_request*)ctx,req);
       } else {
          geocache_request_get_tile *req = (geocache_request_get_tile*)request;

Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:06:57 UTC (rev 12204)
+++ trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:07:02 UTC (rev 12205)
@@ -205,7 +205,6 @@
    geocache_context_apache_request *apache_ctx = apache_request_context_create(r); 
    geocache_context *global_ctx = (geocache_context*)apache_ctx;
    geocache_tile *tile;
-   geocache_service *service;
    int i,ret;
 
    if (!r->handler || strcmp(r->handler, "geocache")) {
@@ -214,26 +213,16 @@
    if (r->method_number != M_GET) {
       return HTTP_METHOD_NOT_ALLOWED;
    }
+   
+   
 
    params = geocache_http_parse_param_string(global_ctx, r->args);
    config = ap_get_module_config(r->per_dir_config, &geocache_module);
 
-   for(i=0;i<GEOCACHE_SERVICES_COUNT;i++) {
-      /* loop through the services that have been configured */
-      service = config->services[i];
-      if(!service) continue;
-      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;
-   }
+   geocache_service_dispatch_request(global_ctx,&request,r->path_info,params,config);
    if(GC_HAS_ERROR(global_ctx)) {
       return report_error(HTTP_BAD_REQUEST, apache_ctx);
    }
-   if(!request) {
-      global_ctx->set_error(global_ctx,GEOCACHE_REQUEST_ERROR,"failed to recognize request");
-      return report_error(HTTP_NOT_FOUND, apache_ctx);
-   }
 
    if(request->type == GEOCACHE_REQUEST_GET_CAPABILITIES) {
       geocache_request_get_capabilities *req_caps = (geocache_request_get_capabilities*)request;
@@ -255,7 +244,7 @@
             *end = '\0';
          }
       }
-      service->create_capabilities_response(global_ctx,req_caps,url,original->path_info,config);
+      request->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);

Modified: trunk/mapserver/mapcache/src/services.c
===================================================================
--- trunk/mapserver/mapcache/src/services.c	2011-08-26 11:06:57 UTC (rev 12204)
+++ trunk/mapserver/mapcache/src/services.c	2011-08-26 11:07:02 UTC (rev 12205)
@@ -245,146 +245,151 @@
  * \private \memberof geocache_service_wms
  * \sa geocache_service::parse_request()
  */
-geocache_request* _geocache_service_wms_parse_request(geocache_context *ctx, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
-   char *str = NULL, *srs=NULL;
+void _geocache_service_wms_parse_request(geocache_context *ctx, geocache_request **request,
+      const char *pathinfo, apr_table_t *params, geocache_cfg *config) {
+   const char *str = NULL;
+   const char *srs=NULL;
    int width=0, height=0;
    double *bbox;
    
-   str = (char*)apr_table_get(params,"SERVICE");
+   str = apr_table_get(params,"SERVICE");
    if(!str)
-      str = (char*)apr_table_get(params,"service");
-   if(!str || strcasecmp(str,"wms")) {
-      return NULL;
+      str = apr_table_get(params,"service");
+   if(!str) {
+      ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR,"received wms request with no service param");
+      return;
    }
+   if( strcasecmp(str,"wms") ) {
+      ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR,"received wms request with invalid service param %s", str);
+      return;
+   }
       
-   str = (char*)apr_table_get(params,"REQUEST");
+   str = apr_table_get(params,"REQUEST");
    if(!str)
-      str = (char*)apr_table_get(params,"request");
+      str = apr_table_get(params,"request");
    if(!str) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms with no request");
-      return NULL;
+      return;
    }
    if( ! strcasecmp(str,"getcapabilities") ) {
-      geocache_request_get_capabilities_wms *request = (geocache_request_get_capabilities_wms*)
+      *request = (geocache_request*)
             apr_pcalloc(ctx->pool,sizeof(geocache_request_get_capabilities_wms));
-      request->request.request.type = GEOCACHE_REQUEST_GET_CAPABILITIES;
-      return (geocache_request*)request;
+      (*request)->type = GEOCACHE_REQUEST_GET_CAPABILITIES;
+      return; /* OK */
    } else if( strcasecmp(str,"getmap")) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms with invalid request %s",str);
-      return NULL;
+      return;
    }
 
 
-   str = (char*)apr_table_get(params,"BBOX");
+   str = apr_table_get(params,"BBOX");
    if(!str)
-      str = (char*)apr_table_get(params,"bbox");
+      str = apr_table_get(params,"bbox");
    if(!str) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with no bbox");
-      return NULL;
+      return;
    } else {
       int nextents;
       if(GEOCACHE_SUCCESS != geocache_util_extract_double_list(ctx, str,',',&bbox,&nextents) ||
             nextents != 4) {
          ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with invalid bbox");
-         return NULL;
+         return;
       }
    }
 
-   str = (char*)apr_table_get(params,"WIDTH");
+   str = apr_table_get(params,"WIDTH");
    if(!str)
-      str = (char*)apr_table_get(params,"width");
+      str = apr_table_get(params,"width");
    if(!str) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with no width");
-      return NULL;
+      return;
    } else {
       char *endptr;
       width = (int)strtol(str,&endptr,10);
       if(*endptr != 0 || width <= 0) {
          ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with invalid width");
-         return NULL;
+         return;
       }
    }
 
-   str = (char*)apr_table_get(params,"HEIGHT");
+   str = apr_table_get(params,"HEIGHT");
    if(!str)
-      str = (char*)apr_table_get(params,"height");
+      str = apr_table_get(params,"height");
    if(!str) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with no height");
-      return NULL;
+      return;
    } else {
       char *endptr;
       height = (int)strtol(str,&endptr,10);
       if(*endptr != 0 || height <= 0) {
          ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with invalid height");
-         return NULL;
+         return;
       }
    }
 
-   srs = (char*)apr_table_get(params,"SRS");
+   srs = apr_table_get(params,"SRS");
    if(!srs)
-      srs = (char*)apr_table_get(params,"srs");
+      srs = apr_table_get(params,"srs");
    if(!srs) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with no srs");
-      return NULL;
+      return;
    }
 
-   str = (char*)apr_table_get(params,"LAYERS");
+   str = apr_table_get(params,"LAYERS");
    if(!str)
-      str = (char*)apr_table_get(params,"layers");
+      str = apr_table_get(params,"layers");
    if(!str) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with no layers");
-      return NULL;
+      return;
    } else {
-      char *last, *key;
+      char *last, *key, *layers;
       int count=1;
       char *sep=",";
-      geocache_request_get_tile *request = (geocache_request_get_tile*)apr_pcalloc(
+      geocache_request_get_tile *req = (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;
-      request->tiles = (geocache_tile**)apr_pcalloc(ctx->pool,count * sizeof(geocache_tile*));
-      for (key = apr_strtok(str, sep, &last); key != NULL;
+      layers = apr_pstrdup(ctx->pool,str);
+      req->request.type = GEOCACHE_REQUEST_GET_TILE;
+      for(key=layers;*key;key++) if(*key == ',') count++;
+      req->ntiles = 0;
+      req->tiles = (geocache_tile**)apr_pcalloc(ctx->pool,count * sizeof(geocache_tile*));
+      for (key = apr_strtok(layers, sep, &last); key != NULL;
             key = apr_strtok(NULL, sep, &last)) {
          geocache_tile *tile;
          geocache_tileset *tileset = geocache_configuration_get_tileset(config,key);
          if(!tileset) {
             ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wms request with invalid layer %s", key);
-            return NULL;
+            return;
          }
          if(strcasecmp(tileset->grid->srs,srs)) {
             ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR,
                   "received wms request with invalid srs (got %s, expected %s)",
                   srs,tileset->grid->srs);
-            return NULL;
+            return;
          }
          if(tileset->grid->tile_sx != width) {
             ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR,
                   "received wms request with invalid width (got %d, expected %d)",
                   width,tileset->grid->tile_sx);
-            return NULL;
+            return;
          }
          if(tileset->grid->tile_sy != height) {
             ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR,
                   "received wms request with invalid height (got %d, expected %d)",
                   height,tileset->grid->tile_sy);
-            return NULL;
+            return;
          }
 
 
          tile = geocache_tileset_tile_create(ctx->pool, tileset);
          if(!tile) {
             ctx->set_error(ctx, GEOCACHE_ALLOC_ERROR, "failed to allocate tile");
-            return NULL;
+            return;
          }
          geocache_tileset_tile_lookup(ctx, tile, bbox);
-         if(GC_HAS_ERROR(ctx)) {
-            return NULL;
-         }
-         request->tiles[request->ntiles++] = tile;
+         GC_CHECK_ERROR(ctx);
+         req->tiles[req->ntiles++] = tile;
       }
-      return (geocache_request*)request;
+      *request = (geocache_request*)req;
    }
 }
 
@@ -393,33 +398,40 @@
  * \private \memberof geocache_service_wmts
  * \sa geocache_service::parse_request()
  */
-geocache_request* _geocache_service_wmts_parse_request(geocache_context *ctx, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
-   char *str;
-   str = (char*)apr_table_get(params,"SERVICE");
+void _geocache_service_wmts_parse_request(geocache_context *ctx, geocache_request **request,
+      const char *pathinfo, apr_table_t *params, geocache_cfg *config) {
+   const char *str;
+   str = apr_table_get(params,"SERVICE");
    if(!str)
-      str = (char*)apr_table_get(params,"service");
-   if(!str || strcasecmp(str,"wmts")) {
-      return NULL;
+      str = apr_table_get(params,"service");
+   if(!str) {
+      ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR,"received wmts request with no service param");
+      return;
    }
+   if( strcasecmp(str,"wmts") ) {
+      ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR,"received wmts request with invalid service param %s", str);
+      return;
+   }
       
-   str = (char*)apr_table_get(params,"REQUEST");
+   str = apr_table_get(params,"REQUEST");
    if(!str)
-      str = (char*)apr_table_get(params,"request");
+      str = apr_table_get(params,"request");
    if(!str) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wmts request with no request");
-      return NULL;
+      return;
    }
    if( ! strcasecmp(str,"getcapabilities") ) {
-      geocache_request_get_capabilities_wmts *request = (geocache_request_get_capabilities_wmts*)
+      geocache_request_get_capabilities_wmts *req = (geocache_request_get_capabilities_wmts*)
             apr_pcalloc(ctx->pool,sizeof(geocache_request_get_capabilities_wmts));
-      request->request.request.type = GEOCACHE_REQUEST_GET_CAPABILITIES;
-      return (geocache_request*)request;
+      req->request.request.type = GEOCACHE_REQUEST_GET_CAPABILITIES;
+      *request = (geocache_request*)req;
+      return;
    } else if( strcasecmp(str,"gettile")) {
       ctx->set_error(ctx, GEOCACHE_REQUEST_ERROR, "received wmts request with invalid request %s",str);
-      return NULL;
+      return;
    } else {
       //TODO getTile
-      return NULL;
+      return;
    }
 }
 /**
@@ -427,86 +439,88 @@
  * \private \memberof geocache_service_tms
  * \sa geocache_service::parse_request()
  */
-geocache_request* _geocache_service_tms_parse_request(geocache_context *ctx, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
+void _geocache_service_tms_parse_request(geocache_context *ctx, geocache_request **request,
+      const char *cpathinfo, apr_table_t *params, geocache_cfg *config) {
    int index = 0;
    char *last, *key, *endptr;
    geocache_tileset *tileset = NULL;
+   char *pathinfo;
    int x,y,z;
    
-   /*if we have some key/values, then we're not a tms request*/
-   if(!apr_is_empty_table(params))
-      return NULL;
-   /* parse a path_info like /1.0.0/global_mosaic/0/0/0.jpg */
-   if(pathinfo) {
+   if(cpathinfo) {
+      pathinfo = apr_pstrdup(ctx->pool,cpathinfo);
+      /* 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);
-               return NULL;
+               ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request with invalid version %s", key);
+               return;
             }
             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;
+               return;
             }
             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;
+               return;
             }
             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;
+               return;
             }
             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;
+               return;
             }
             break;
          default:
-            ctx->log(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid parameter %s", pathinfo, key);
-            return NULL;
+            ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with invalid parameter %s", pathinfo, key);
+            return;
          }
       }
    }
    if(index == 5) {
-      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;
+      geocache_request_get_tile *req = (geocache_request_get_tile*)apr_pcalloc(ctx->pool,sizeof(geocache_request_get_tile));
+      req->request.type = GEOCACHE_REQUEST_GET_TILE;
+      req->ntiles = 1;
+      req->tiles = (geocache_tile**)apr_pcalloc(ctx->pool,sizeof(geocache_tile*));
+      req->tiles[0] = geocache_tileset_tile_create(ctx->pool, tileset);
+      req->tiles[0]->x = x;
+      req->tiles[0]->y = y;
+      req->tiles[0]->z = z;
+      *request = (geocache_request*)req;
+      return;
    } else if(index<3) {
-      geocache_request_get_capabilities_tms *request = (geocache_request_get_capabilities_tms*)apr_pcalloc(
+      geocache_request_get_capabilities_tms *req = (geocache_request_get_capabilities_tms*)apr_pcalloc(
             ctx->pool,sizeof(geocache_request_get_capabilities_tms));
-      request->request.request.type = GEOCACHE_REQUEST_GET_CAPABILITIES;
+      req->request.request.type = GEOCACHE_REQUEST_GET_CAPABILITIES;
       if(index >= 2) {
-         request->tileset = tileset;
+         req->tileset = tileset;
       }
       if(index >= 1) {
-         request->version = apr_pstrdup(ctx->pool,"1.0.0");
+         req->version = apr_pstrdup(ctx->pool,"1.0.0");
       }
-      return (geocache_request*)request;
+      *request = (geocache_request*)req;
+      return;
    }
    else {
       ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR, "received tms request %s with wrong number of arguments", pathinfo);
-      return NULL;
+      return;
    }
 }
 
@@ -516,6 +530,7 @@
       ctx->set_error(ctx, GEOCACHE_ALLOC_ERROR, "failed to allocate wms service");
       return NULL;
    }
+   service->service.url_prefix = apr_pstrdup(ctx->pool,"wms");
    service->service.type = GEOCACHE_SERVICE_WMS;
    service->service.parse_request = _geocache_service_wms_parse_request;
    service->service.create_capabilities_response = _create_capabilities_wms;
@@ -528,6 +543,7 @@
       ctx->set_error(ctx, GEOCACHE_ALLOC_ERROR, "failed to allocate tms service");
       return NULL;
    }
+   service->service.url_prefix = apr_pstrdup(ctx->pool,"tms");
    service->service.type = GEOCACHE_SERVICE_TMS;
    service->service.parse_request = _geocache_service_tms_parse_request;
    service->service.create_capabilities_response = _create_capabilities_tms;
@@ -540,12 +556,48 @@
       ctx->set_error(ctx, GEOCACHE_ALLOC_ERROR, "failed to allocate wtms service");
       return NULL;
    }
+   service->service.url_prefix = apr_pstrdup(ctx->pool,"wmts");
    service->service.type = GEOCACHE_SERVICE_WMTS;
    service->service.parse_request = _geocache_service_wmts_parse_request;
    service->service.create_capabilities_response = _create_capabilities_wmts;
    return (geocache_service*)service;
 }
 
+void geocache_service_dispatch_request(geocache_context *ctx, geocache_request **request, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
+   int i;
+   geocache_service *service = NULL;
+   
+   /* skip empty pathinfo */
+   if(!pathinfo) {
+      ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR,"missing a service");
+      return;
+   }
+   
+   /*skip leading /'s */
+   while((*pathinfo) == '/')
+      ++pathinfo;
+   
+   if(!(*pathinfo)) {
+      ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR,"missing a service");
+      return;
+   }
+   
+   for(i=0;i<GEOCACHE_SERVICES_COUNT;i++) {
+      int prefixlen;
+      /* loop through the services that have been configured */
+      service = config->services[i];
+      prefixlen = strlen(service->url_prefix);
+      if(!service) continue; /* skip an unconfigured service */
+      if(strncmp(service->url_prefix,pathinfo, prefixlen)) continue; /*skip a service who's prefix does not correspond */
+      pathinfo += prefixlen; /* advance pathinfo to after the service prefix */
+      service->parse_request(ctx,request,pathinfo,params,config);
+      GC_CHECK_ERROR(ctx);
+      (*request)->service = service;
+      return;
+   }
+   ctx->set_error(ctx,GEOCACHE_REQUEST_ERROR,"unknown service");
+}
+
 /** @} */
 
 

Modified: trunk/mapserver/mapcache/src/util.c
===================================================================
--- trunk/mapserver/mapcache/src/util.c	2011-08-26 11:06:57 UTC (rev 12204)
+++ trunk/mapserver/mapcache/src/util.c	2011-08-26 11:07:02 UTC (rev 12205)
@@ -20,9 +20,10 @@
 #include <apr_tables.h>
 #include <curl/curl.h>
 
-int geocache_util_extract_int_list(geocache_context *ctx, char* args, const char sep, int **numbers,
+int geocache_util_extract_int_list(geocache_context *ctx, const char* cargs, const char sep, int **numbers,
       int *numbers_count) {
    char *last, *key, *endptr;
+   char *args = apr_pstrdup(ctx->pool,cargs);
    int tmpcount=1;
    char delim[2];
    delim[0] = sep;
@@ -43,9 +44,10 @@
    return GEOCACHE_SUCCESS;
 }
 
-int geocache_util_extract_double_list(geocache_context *ctx, char* args, const char sep, double **numbers,
+int geocache_util_extract_double_list(geocache_context *ctx, const char* cargs, const char sep, double **numbers,
       int *numbers_count) {
    char *last, *key, *endptr;
+   char *args = apr_pstrdup(ctx->pool,cargs);
    int tmpcount=1;
    char delim[2];
    delim[0] = sep;



More information about the mapserver-commits mailing list