Skip to content

Commit

Permalink
Merge branch 'branch-1-4'
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Feb 16, 2016
2 parents a2c994f + 93fef0d commit 732b3fd
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 83 deletions.
8 changes: 7 additions & 1 deletion apache/mod_mapcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,14 @@ static const char* mapcache_add_alias(cmd_parms *cmd, void *cfg, const char *ali
mapcache_server_cfg *sconfig;
mapcache_alias_entry *alias_entry;
mapcache_context *ctx;
unsigned forbidden = NOT_IN_DIRECTORY|NOT_IN_FILES;
const char *err;

const char *err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES|NOT_IN_HTACCESS);
#if (AP_SERVER_MAJORVERSION_NUMBER > 2) || (AP_SERVER_MINORVERSION_NUMBER >= 4)
forbidden |= NOT_IN_HTACCESS;
#endif

err = ap_check_cmd_context(cmd, forbidden);
if (err) {
return err;
}
Expand Down
1 change: 1 addition & 0 deletions include/mapcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,7 @@ char* mapcache_util_get_tile_dimkey(mapcache_context *ctx, mapcache_tile *tile,

char* mapcache_util_get_tile_key(mapcache_context *ctx, mapcache_tile *tile, char *stemplate,
char* sanitized_chars, char *sanitize_to);
void mapcache_make_parent_dirs(mapcache_context *ctx, char *filename);

/**\defgroup imageio Image IO */
/** @{ */
Expand Down
66 changes: 10 additions & 56 deletions lib/cache_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static void _mapcache_cache_disk_set(mapcache_context *ctx, mapcache_cache *pcac
apr_file_t *f;
apr_status_t ret;
char errmsg[120];
char *filename, *hackptr1, *hackptr2=NULL;
char *filename;
mapcache_cache_disk *cache = (mapcache_cache_disk*)pcache;
const int creation_retry = cache->creation_retry;
int retry_count_create_file = 0;
Expand All @@ -506,26 +506,8 @@ static void _mapcache_cache_disk_set(mapcache_context *ctx, mapcache_cache *pcac
cache->tile_key(ctx, cache, tile, &filename);
GC_CHECK_ERROR(ctx);

/* find the location of the last '/' in the string */
hackptr1 = filename;
while(*hackptr1) {
if(*hackptr1 == '/')
hackptr2 = hackptr1;
hackptr1++;
}
*hackptr2 = '\0';

if(APR_SUCCESS != (ret = apr_dir_make_recursive(filename,APR_OS_DEFAULT,ctx->pool))) {
/*
* apr_dir_make_recursive sometimes sends back this error, although it should not.
* ignore this one
*/
if(!APR_STATUS_IS_EEXIST(ret)) {
ctx->set_error(ctx, 500, "failed to create directory %s: %s",filename, apr_strerror(ret,errmsg,120));
return;
}
}
*hackptr2 = '/';
mapcache_make_parent_dirs(ctx,filename);
GC_CHECK_ERROR(ctx);

ret = apr_file_remove(filename,ctx->pool);
if(ret != APR_SUCCESS && !APR_STATUS_IS_ENOENT(ret)) {
Expand All @@ -545,25 +527,15 @@ static void _mapcache_cache_disk_set(mapcache_context *ctx, mapcache_cache *pcac
char *blankname_rel = NULL;
_mapcache_cache_disk_blank_tile_key(ctx,cache,tile,tile->raw_image->data,&blankname);
if(apr_file_open(&f, blankname, APR_FOPEN_READ, APR_OS_DEFAULT, ctx->pool) != APR_SUCCESS) {
/* create the blank file */
int isLocked;
void *lock;
char *blankdirname;
if(!tile->encoded_data) {
tile->encoded_data = tile->tileset->format->write(ctx, tile->raw_image, tile->tileset->format);
GC_CHECK_ERROR(ctx);
}
/* create the blank file */
blankdirname = apr_psprintf(ctx->pool, "%s/%s/%s/blanks",
cache->base_directory,
tile->tileset->name,
tile->grid_link->grid->name);
if(APR_SUCCESS != (ret = apr_dir_make_recursive(
blankdirname, APR_OS_DEFAULT,ctx->pool))) {
if(!APR_STATUS_IS_EEXIST(ret)) {
ctx->set_error(ctx, 500, "failed to create directory %s for blank tiles",blankdirname, apr_strerror(ret,errmsg,120));
return;
}
}
mapcache_make_parent_dirs(ctx,blankname);
GC_CHECK_ERROR(ctx);

/* aquire a lock on the blank file */
isLocked = mapcache_lock_or_wait_for_resource(ctx,ctx->config->locker,blankname, &lock);
Expand Down Expand Up @@ -621,17 +593,8 @@ static void _mapcache_cache_disk_set(mapcache_context *ctx, mapcache_cache *pcac
ctx->set_error(ctx, 500, "failed to link tile %s to %s: %s",filename, blankname_rel, error);
return; /* we could not create the file */
}

*hackptr2 = '\0';

if(APR_SUCCESS != (ret = apr_dir_make_recursive(filename,APR_OS_DEFAULT,ctx->pool))) {
if(!APR_STATUS_IS_EEXIST(ret)) {
ctx->set_error(ctx, 500, "failed to create symlink, can not create directory %s: %s",filename, apr_strerror(ret,errmsg,120));
return; /* we could not create the file */
}
}

*hackptr2 = '/';
mapcache_make_parent_dirs(ctx,filename);
GC_CHECK_ERROR(ctx);
}
#ifdef DEBUG
ctx->log(ctx, MAPCACHE_DEBUG, "linked blank tile %s to %s",filename,blankname);
Expand Down Expand Up @@ -663,17 +626,8 @@ static void _mapcache_cache_disk_set(mapcache_context *ctx, mapcache_cache *pcac
ctx->set_error(ctx, 500, "failed to create file %s: %s",filename, apr_strerror(ret,errmsg,120));
return; /* we could not create the file */
}

*hackptr2 = '\0';

if(APR_SUCCESS != (ret = apr_dir_make_recursive(filename,APR_OS_DEFAULT,ctx->pool))) {
if(!APR_STATUS_IS_EEXIST(ret)) {
ctx->set_error(ctx, 500, "failed to create file, can not create directory %s: %s",filename, apr_strerror(ret,errmsg,120));
return; /* we could not create the file */
}
}

*hackptr2 = '/';
mapcache_make_parent_dirs(ctx,filename);
GC_CHECK_ERROR(ctx);
}

bytes = (apr_size_t)tile->encoded_data->size;
Expand Down
2 changes: 2 additions & 0 deletions lib/cache_sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ void mapcache_sqlite_connection_constructor(mapcache_context *ctx, void **conn_,
flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_NOMUTEX;
} else {
flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_CREATE;
mapcache_make_parent_dirs(ctx,sq_params->dbfile);
GC_CHECK_ERROR(ctx);
}
ret = sqlite3_open_v2(sq_params->dbfile, &conn->handle, flags, NULL);
if (ret != SQLITE_OK) {
Expand Down
25 changes: 2 additions & 23 deletions lib/cache_tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,8 @@ static void _mapcache_cache_tiff_set(mapcache_context *ctx, mapcache_cache *pcac
int rv;
void *lock;
int create;
char errmsg[120];
mapcache_cache_tiff *cache;
mapcache_image_format_jpeg *format;
char *hackptr1,*hackptr2;
int tilew;
int tileh;
unsigned char *rgb;
Expand All @@ -554,27 +552,8 @@ static void _mapcache_cache_tiff_set(mapcache_context *ctx, mapcache_cache *pcac
/*
* create the directory where the tiff file will be stored
*/

/* find the location of the last '/' in the string */
hackptr2 = hackptr1 = filename;
while(*hackptr1) {
if(*hackptr1 == '/')
hackptr2 = hackptr1;
hackptr1++;
}
*hackptr2 = '\0';

if(APR_SUCCESS != (rv = apr_dir_make_recursive(filename,APR_OS_DEFAULT,ctx->pool))) {
/*
* apr_dir_make_recursive sometimes sends back this error, although it should not.
* ignore this one
*/
if(!APR_STATUS_IS_EEXIST(rv)) {
ctx->set_error(ctx, 500, "failed to create directory %s: %s",filename, apr_strerror(rv,errmsg,120));
return;
}
}
*hackptr2 = '/';
mapcache_make_parent_dirs(ctx,filename);
GC_CHECK_ERROR(ctx);

tilew = tile->grid_link->grid->tile_sx;
tileh = tile->grid_link->grid->tile_sy;
Expand Down
2 changes: 1 addition & 1 deletion lib/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void mapcache_http_do_request(mapcache_context *ctx, mapcache_http *req, mapcach
int i;
for (i = 0; i < array->nelts; i++) {
char *val = elts[i].val;
if(strchr(val,'{') && ctx->headers_in) {
if(val && strchr(val,'{') && ctx->headers_in) {
_header_replace_str(ctx,ctx->headers_in,&val);
}
curl_headers = curl_slist_append(curl_headers, apr_pstrcat(ctx->pool,elts[i].key,": ",val,NULL));
Expand Down
42 changes: 40 additions & 2 deletions lib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <apr_tables.h>
#include <curl/curl.h>
#include <math.h>
#include <apr_file_io.h>

#ifndef _WIN32
#include <unistd.h>
Expand Down Expand Up @@ -398,9 +399,41 @@ char* mapcache_util_get_tile_key(mapcache_context *ctx, mapcache_tile *tile, cha
return path;
}

void mapcache_make_parent_dirs(mapcache_context *ctx, char *filename) {
char *hackptr1,*hackptr2=NULL;
apr_status_t ret;
char errmsg[120];

/* find the location of the last '/' in the string */
hackptr1 = filename;
while(*hackptr1) {
if(*hackptr1 == '/')
hackptr2 = hackptr1;
hackptr1++;
}

if(hackptr2) {
/* terminate string on last '/' */
*hackptr2 = '\0';
}

/* vim: ts=2 sts=2 et sw=2
*/
ret = apr_dir_make_recursive(filename,APR_OS_DEFAULT,ctx->pool);

if(hackptr2) {
*hackptr2 = '/';
}


if(APR_SUCCESS != ret) {
/*
* apr_dir_make_recursive sometimes sends back this error, although it should not.
* ignore this one
*/
if(!APR_STATUS_IS_EEXIST(ret)) {
ctx->set_error(ctx, 500, "failed to create directory %s: %s",filename, apr_strerror(ret,errmsg,120));
}
}
}


#if defined(_WIN32) && !defined(__CYGWIN__)
Expand Down Expand Up @@ -454,3 +487,8 @@ void mapcache_gettimeofday(struct mctimeval* tp, void* tzp)


#endif

/* vim: ts=2 sts=2 et sw=2
*/


0 comments on commit 732b3fd

Please sign in to comment.