[mapserver-commits] r12136 - in trunk/mapserver/mapcache: include
src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:00:50 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:00:50 -0700 (Fri, 26 Aug 2011)
New Revision: 12136
Modified:
trunk/mapserver/mapcache/include/geocache.h
trunk/mapserver/mapcache/src/cache_disk.c
trunk/mapserver/mapcache/src/image.c
trunk/mapserver/mapcache/src/mod_geocache.c
Log:
add an expires header and configuration option
closes issue 12.
thomas.bonfort | 2010-10-19 18:44:34 +0200 (Tue, 19 Oct 2010)
Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:00:44 UTC (rev 12135)
+++ trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:00:50 UTC (rev 12136)
@@ -25,6 +25,7 @@
#include <libxml/tree.h>
#include "util.h"
#include <assert.h>
+#include <apr_time.h>
#define GEOCACHE_SUCCESS 0
@@ -63,6 +64,7 @@
int sx,sy;
geocache_buffer *data;
void *lock;
+ apr_time_t mtime;
} geocache_tile;
typedef struct {
Modified: trunk/mapserver/mapcache/src/cache_disk.c
===================================================================
--- trunk/mapserver/mapcache/src/cache_disk.c 2011-08-26 11:00:44 UTC (rev 12135)
+++ trunk/mapserver/mapcache/src/cache_disk.c 2011-08-26 11:00:50 UTC (rev 12136)
@@ -165,7 +165,7 @@
_geocache_cache_disk_tile_key(r, tile, &filename);
if(apr_file_open(&f, filename, APR_FOPEN_READ|APR_FOPEN_BUFFERED|APR_FOPEN_BINARY,
APR_OS_DEFAULT, r->pool) == APR_SUCCESS) {
- rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, f);
+ rv = apr_file_info_get(&finfo, APR_FINFO_SIZE|APR_FINFO_MTIME, f);
if(!finfo.size) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, "tile %s has no data",filename);
return GEOCACHE_FAILURE;
@@ -180,6 +180,7 @@
* any error that might happen at this stage should only occur if the tile isn't already cached,
* i.e. normally only once.
*/
+ tile->mtime = finfo.mtime;
tile->data = geocache_buffer_create(size,r->pool);
//manually add the data to our buffer
apr_file_read(f,(void*)tile->data->buf,&size);
Modified: trunk/mapserver/mapcache/src/image.c
===================================================================
--- trunk/mapserver/mapcache/src/image.c 2011-08-26 11:00:44 UTC (rev 12135)
+++ trunk/mapserver/mapcache/src/image.c 2011-08-26 11:00:50 UTC (rev 12136)
@@ -63,16 +63,18 @@
geocache_tile* geocache_image_merge_tiles(request_rec *r, geocache_tile **tiles, int ntiles) {
geocache_image *base,*overlay;
int i;
- geocache_tile *tile;
-
+ geocache_tile *tile = apr_pcalloc(r->pool,sizeof(geocache_tile));
+ tile->mtime = tiles[0]->mtime;
base = geocache_imageio_decode(r, tiles[0]->data);
if(!base) return NULL;
for(i=1; i<ntiles; i++) {
overlay = geocache_imageio_decode(r, tiles[i]->data);
+ if(tile->mtime < tiles[i]->mtime)
+ tile->mtime = tiles[i]->mtime;
if(!overlay) return NULL;
_geocache_image_merge(r, base, overlay);
}
- tile = apr_pcalloc(r->pool,sizeof(geocache_tile));
+
tile->data = geocache_imageio_encode(r,base, GEOCACHE_IMAGE_FORMAT_PNG);
tile->sx = base->w;
tile->sy = base->h;
Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c 2011-08-26 11:00:44 UTC (rev 12135)
+++ trunk/mapserver/mapcache/src/mod_geocache.c 2011-08-26 11:00:50 UTC (rev 12136)
@@ -22,7 +22,9 @@
#include <httpd.h>
#include <http_config.h>
#include <http_protocol.h>
+#include <http_request.h>
#include <apr_strings.h>
+#include <apr_time.h>
#include <http_log.h>
#include "geocache.h"
@@ -34,13 +36,17 @@
static int geocache_write_tile(request_rec *r, geocache_tile *tile) {
-
+ int rc;
if(tile->tileset->source->image_format == GEOCACHE_IMAGE_FORMAT_PNG)
ap_set_content_type(r, "image/png");
else
ap_set_content_type(r, "image/jpeg");
-
+ ap_update_mtime(r, tile->mtime);
+ if((rc = ap_meets_conditions(r)) != OK) {
+ return rc;
+ }
+ ap_set_last_modified(r);
ap_set_content_length(r,tile->data->size);
ap_rwrite((void*)tile->data->buf, tile->data->size, r);
@@ -65,9 +71,11 @@
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 */
geocache_service *service = config->services[i];
if(!service) continue;
request = service->parse_request(r,params,config);
+ /* the service has recognized the request if it returns a non NULL value */
if(request)
break;
}
@@ -82,14 +90,6 @@
if(rv != GEOCACHE_SUCCESS) {
return HTTP_NOT_FOUND;
}
-#ifdef MERGE_ENABLED
- if(request->ntiles>1) {
- if(tile->tileset->source->image_format != GEOCACHE_IMAGE_FORMAT_PNG) {
- ap_rprintf(r,"tile merging only supports png source (requested source: %s",tile->tileset->source->name);
- return HTTP_BAD_REQUEST;
- }
- }
-#endif
}
if(request->ntiles == 1) {
tile = request->tiles[0];
More information about the mapserver-commits
mailing list