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

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


Author: tbonfort
Date: 2011-08-26 04:15:12 -0700 (Fri, 26 Aug 2011)
New Revision: 12302

Modified:
   trunk/mapserver/mapcache/geocache.xml
   trunk/mapserver/mapcache/include/errors.h
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/imageio_jpeg.c
   trunk/mapserver/mapcache/src/imageio_png.c
   trunk/mapserver/mapcache/src/mod_geocache.c
Log:
add forwarding for full wms
thomas.bonfort | 2011-02-10 08:39:28 +0100 (Thu, 10 Feb 2011)

Modified: trunk/mapserver/mapcache/geocache.xml
===================================================================
--- trunk/mapserver/mapcache/geocache.xml	2011-08-26 11:15:06 UTC (rev 12301)
+++ trunk/mapserver/mapcache/geocache.xml	2011-08-26 11:15:12 UTC (rev 12302)
@@ -333,7 +333,7 @@
          NOTE: when adding a <grid> element, you *MUST* make sure that the source you have selected is able to
          return images in the grid's srs.
       -->
-      <grid>WGS84</grid>
+         <grid restricted_extent="-10 40 10 50">WGS84</grid>
       <grid>google</grid>
 
       <!-- metadata
@@ -479,7 +479,7 @@
       recommended to use a png format with "fast"compression here, unless you have plenty
       of server cpu power and or limited bandwidth
    -->
-   <merge_format>PNGQ_FAST</merge_format>
+   <merge_format>JPEG</merge_format>
 
    <!-- services
       services that will be responded to by mod-geocache
@@ -508,4 +508,16 @@
       -->
       <demo>true</demo>
    </services>
+
+   <!-- errors
+        configure how error will be reported back to a client:
+          - log : no error is reported back, except an http error code.
+          - report : return the error message to the client in textual format
+          - empty_img : return an empty image to the client. the actual error code is in the X-Geocache-Error http header
+          - report_img : return an image with the error text included inside. not implemented yet.
+
+        the default setting is to report the error message back to the user. In production, you might want to set this to "log"
+        if you're paranoid, or to "empty_img" if you want to play nice with non-conforming clients.
+   -->
+   <errors>empty_img</errors>
 </geocache>

Modified: trunk/mapserver/mapcache/include/errors.h
===================================================================
--- trunk/mapserver/mapcache/include/errors.h	2011-08-26 11:15:06 UTC (rev 12301)
+++ trunk/mapserver/mapcache/include/errors.h	2011-08-26 11:15:12 UTC (rev 12302)
@@ -27,7 +27,9 @@
 typedef enum {
    GEOCACHE_REPORT_LOG,
    GEOCACHE_REPORT_MSG,
-   GEOCACHE_REPORT_IMG
+   GEOCACHE_REPORT_ERROR_IMG,
+   GEOCACHE_REPORT_EMPTY_IMG,
+   GEOCACHE_REPORT_CUSTOM_IMG
 } geocache_error_reporting;
 
 #endif /* ERRORS_H_ */

Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:15:06 UTC (rev 12301)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:15:12 UTC (rev 12302)
@@ -685,6 +685,7 @@
       * how should error messages be reported to the user
       */
      geocache_error_reporting reporting;
+     geocache_buffer *empty_image;
      
      apr_table_t *metadata;
 };
@@ -1019,6 +1020,9 @@
     /**< pointer to a function that returns a geocache_buffer containing the given image encoded
      * in the specified format
      */
+
+    geocache_buffer* (*create_empty_image)(geocache_context *ctx, geocache_image_format *format,
+          size_t width, size_t height, unsigned int color);
     apr_table_t *metadata;
 };
 

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:15:06 UTC (rev 12301)
+++ trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:15:12 UTC (rev 12302)
@@ -840,6 +840,16 @@
    }
 }
 
+static void createEmptyImages(geocache_context *ctx, geocache_cfg *cfg) {
+   unsigned int color=0;
+   if(!strstr(cfg->merge_format->mime_type,"png")) {
+      color = 0xffffffff;
+   }
+   cfg->empty_image = cfg->merge_format->create_empty_image(ctx, cfg->merge_format,
+         256,256, color);
+   GC_CHECK_ERROR(ctx);
+}
+
 void geocache_configuration_parse(geocache_context *ctx, const char *filename, geocache_cfg *config) {
    ezxml_t doc, node;
    doc = ezxml_parse_file(filename);
@@ -904,9 +914,31 @@
                node->txt);
          goto cleanup;
       }
+      config->merge_format = format;
    }
 
+   if ((node = ezxml_child(doc,"errors")) != NULL) {
+      if(!strcmp(node->txt,"log")) {
+         config->reporting = GEOCACHE_REPORT_LOG;
+      } else if(!strcmp(node->txt,"report")) {
+         config->reporting = GEOCACHE_REPORT_MSG;
+      } else if(!strcmp(node->txt,"empty_img")) {
+         config->reporting = GEOCACHE_REPORT_EMPTY_IMG;
+         createEmptyImages(ctx, config);
+         if(GC_HAS_ERROR(ctx)) goto cleanup;
+      } else if(!strcmp(node->txt, "report_img")) {
+         config->reporting = GEOCACHE_REPORT_ERROR_IMG;
+         ctx->set_error(ctx,501,"<errors>: report_img not implemented");
+         goto cleanup;
+      } else {
+         ctx->set_error(ctx,400,"<errors>: unknown value %s (allowed are log, report, empty_img, report_img)",
+               node->txt);
+         goto cleanup;
+      }
+   }
 
+
+
 cleanup:
    ezxml_free(doc);
    return;

Modified: trunk/mapserver/mapcache/src/imageio_jpeg.c
===================================================================
--- trunk/mapserver/mapcache/src/imageio_jpeg.c	2011-08-26 11:15:06 UTC (rev 12301)
+++ trunk/mapserver/mapcache/src/imageio_jpeg.c	2011-08-26 11:15:12 UTC (rev 12302)
@@ -252,13 +252,45 @@
 
 }
 
+static geocache_buffer* _geocache_imageio_jpg_create_empty(geocache_context *ctx, geocache_image_format *format,
+      size_t width, size_t height, unsigned int color) {
+
+   geocache_image_format_jpeg *f = (geocache_image_format_jpeg*)format;
+
+   apr_pool_t *pool = NULL;
+   if(apr_pool_create(&pool,ctx->pool) != APR_SUCCESS) {
+      ctx->set_error(ctx,500,"png create empty: failed to create temp memory pool");
+      return NULL;
+   }
+   geocache_image *empty = geocache_image_create(ctx);
+   if(GC_HAS_ERROR(ctx)) {
+      return NULL;
+   }
+   empty->data = (unsigned char*)apr_pcalloc(pool,width*height*4*sizeof(unsigned char)); 
+   int i;
+   for(i=0;i<width*height;i++) {
+      ((unsigned int*)empty->data)[i] = color;
+   }
+   empty->w = width;
+   empty->h = height;
+   empty->stride = width * 4;
+
+   /*temp switch format compression*/
+   int tmpquality = f->quality;
+   f->quality = 1;
+   geocache_buffer *buf = format->write(ctx,empty,format);
+   apr_pool_destroy(pool);
+   f->quality = tmpquality;
+   return buf;
+}
+
 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 = apr_pstrdup(pool,"jpg");
    format->format.mime_type = apr_pstrdup(pool,"image/jpeg");
    format->format.metadata = apr_table_make(pool,3);
-
+   format->format.create_empty_image = _geocache_imageio_jpg_create_empty;
    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:15:06 UTC (rev 12301)
+++ trunk/mapserver/mapcache/src/imageio_png.c	2011-08-26 11:15:12 UTC (rev 12302)
@@ -1067,7 +1067,39 @@
    return buffer;
 }
 
+static geocache_buffer* _geocache_imageio_png_create_empty(geocache_context *ctx, geocache_image_format *format,
+      size_t width, size_t height, unsigned int color) {
 
+   geocache_image_format_png *f = (geocache_image_format_png*)format;
+
+   apr_pool_t *pool = NULL;
+   if(apr_pool_create(&pool,ctx->pool) != APR_SUCCESS) {
+      ctx->set_error(ctx,500,"png create empty: failed to create temp memory pool");
+      return NULL;
+   }
+   geocache_image *empty = geocache_image_create(ctx);
+   if(GC_HAS_ERROR(ctx)) {
+      return NULL;
+   }
+   empty->data = (unsigned char*)apr_pcalloc(pool,width*height*4*sizeof(unsigned char)); 
+   int i;
+   for(i=0;i<width*height;i++) {
+      ((unsigned int*)empty->data)[i] = color;
+   }
+   empty->w = width;
+   empty->h = height;
+   empty->stride = width * 4;
+
+   /*temp switch format compression*/
+   geocache_compression_type tmpcomp = f->compression_level;
+   f->compression_level = GEOCACHE_COMPRESSION_BEST;
+   geocache_buffer *buf = format->write(ctx,empty,format);
+   apr_pool_destroy(pool);
+   f->compression_level = tmpcomp;
+   return buf;
+}
+
+
 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;
@@ -1076,6 +1108,7 @@
    format->compression_level = compression;
    format->format.metadata = apr_table_make(pool,3);
    format->format.write = _geocache_imageio_png_encode;
+   format->format.create_empty_image = _geocache_imageio_png_create_empty;
    return (geocache_image_format*)format;
 }
 
@@ -1086,6 +1119,7 @@
    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->format.format.create_empty_image = _geocache_imageio_png_create_empty;
    format->format.format.metadata = apr_table_make(pool,3);
    format->ncolors = ncolors;
    return (geocache_image_format*)format;

Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:15:06 UTC (rev 12301)
+++ trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:15:12 UTC (rev 12302)
@@ -68,7 +68,19 @@
       ap_set_content_type(apache_ctx->request, "text/plain");
       ap_rprintf(apache_ctx->request,"error: %s",msg);
       return OK;
-   } else {
+   } else if(ctx->config && ctx->config->reporting == GEOCACHE_REPORT_EMPTY_IMG) {
+      if(ctx->config->empty_image) { /*should never fail*/
+         apache_ctx->request->status = code;
+         ap_set_content_length(apache_ctx->request, ctx->config->empty_image->size);
+         apr_table_set(apache_ctx->request->headers_out, "X-Geocache-Error", msg);
+         ap_set_content_type(apache_ctx->request, ctx->config->merge_format->mime_type);
+         ap_rwrite((void*)ctx->config->empty_image->buf, ctx->config->empty_image->size, apache_ctx->request);
+         return OK;
+      } else {
+         return code;
+      }
+   }
+   else {
       return code;
    }
 }



More information about the mapserver-commits mailing list