Skip to content

Commit

Permalink
modify for Win32 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jmckenna committed Feb 27, 2013
1 parent f42f9cc commit ff5e3b1
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 60 deletions.
4 changes: 2 additions & 2 deletions Makefile.vc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ LINK= link

MAPCACHE_OBJS = lib\axisorder.obj lib\dimension.obj lib\imageio_mixed.obj lib\service_wms.obj \
lib\buffer.obj lib\ezxml.obj lib\imageio_png.obj lib\service_wmts.obj \
lib\cache_disk.obj lib\lock.obj lib\services.obj \
lib\cache_disk.obj lib\lock.obj lib\services.obj lib\cache_bdb.obj \
lib\cache_memcache.obj lib\grid.obj lib\source.obj \
lib\cache_sqlite.obj lib\http.obj lib\source_gdal.obj \
lib\cache_sqlite.obj lib\http.obj lib\source_gdal.obj lib\source_dummy.obj \
lib\cache_tiff.obj lib\image.obj lib\service_demo.obj lib\source_mapserver.obj \
lib\configuration.obj lib\image_error.obj lib\service_kml.obj lib\source_wms.obj \
lib\configuration_xml.obj lib\imageio.obj lib\service_tms.obj lib\tileset.obj \
Expand Down
2 changes: 1 addition & 1 deletion apache/mod_mapcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ static int write_http_response(mapcache_context_apache_request *ctx, mapcache_ht

static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s)
{
int threaded;
pchild = pool;
#ifdef APR_HAS_THREADS
int threaded;
ap_mpm_query(AP_MPMQ_IS_THREADED,&threaded);
if(threaded) {
apr_thread_mutex_create(&thread_mutex,APR_THREAD_MUTEX_DEFAULT,pool);
Expand Down
53 changes: 33 additions & 20 deletions lib/cache_bdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

#ifndef _WIN32
#include <unistd.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
#endif

#include <db.h>
Expand All @@ -63,6 +67,8 @@ struct bdb_env {
static apr_status_t _bdb_reslist_get_connection(void **conn_, void *params, apr_pool_t *pool)
{
int ret;
int env_flags;
int mode;
mapcache_cache_bdb *cache = (mapcache_cache_bdb*)params;
char *dbfile = apr_pstrcat(pool,cache->basedir,"/",cache->cache.name,".db",NULL);
struct bdb_env *benv = calloc(1,sizeof(struct bdb_env));
Expand All @@ -78,7 +84,7 @@ static apr_status_t _bdb_reslist_get_connection(void **conn_, void *params, apr_
benv->errmsg = apr_psprintf(pool, "bdb cache failure for db->set_cachesize: %s", db_strerror(ret));
return APR_EGENERAL;
}
int env_flags = DB_INIT_CDB|DB_INIT_MPOOL|DB_CREATE;
env_flags = DB_INIT_CDB|DB_INIT_MPOOL|DB_CREATE;
ret = benv->env->open(benv->env,cache->basedir,env_flags,0);
if(ret) {
benv->errmsg = apr_psprintf(pool,"bdb cache failure for env->open: %s", db_strerror(ret));
Expand All @@ -89,7 +95,7 @@ static apr_status_t _bdb_reslist_get_connection(void **conn_, void *params, apr_
benv->errmsg = apr_psprintf(pool,"bdb cache failure for db_create: %s", db_strerror(ret));
return APR_EGENERAL;
}
int mode = DB_BTREE;
mode = DB_BTREE;
ret = benv->db->set_pagesize(benv->db,PAGESIZE); /* set pagesize to maximum allowed, as tile data is usually pretty large */
if(ret) {
benv->errmsg = apr_psprintf(pool,"bdb cache failure for db->set_pagesize: %s", db_strerror(ret));
Expand Down Expand Up @@ -328,6 +334,7 @@ static size_t trns_offset = 0x34;
static int _mapcache_cache_bdb_get(mapcache_context *ctx, mapcache_tile *tile)
{
DBT key,data;
int ret;
struct bdb_env *benv = _bdb_get_conn(ctx,tile,1);
mapcache_cache_bdb *cache = (mapcache_cache_bdb*)tile->tileset->cache;
char *skey = mapcache_util_get_tile_key(ctx,tile,cache->key_template,NULL,NULL);
Expand All @@ -338,25 +345,28 @@ static int _mapcache_cache_bdb_get(mapcache_context *ctx, mapcache_tile *tile)
key.data = skey;
key.size = strlen(skey)+1;

int ret = benv->db->get(benv->db, NULL, &key, &data, 0);
ret = benv->db->get(benv->db, NULL, &key, &data, 0);


if(ret == 0) {
if(((char*)(data.data))[0] == '#') {
int pltecrc;
unsigned char *dd;
tile->encoded_data = mapcache_buffer_create(sizeof(empty_png)+4,ctx->pool);
unsigned char *dd = tile->encoded_data->buf;
dd = tile->encoded_data->buf;
memcpy(dd,empty_png,sizeof(empty_png));
memcpy(dd+plte_offset+4,data.data+3,1); // r;
memcpy(dd+plte_offset+5,data.data+2,1); // g;
memcpy(dd+plte_offset+6,data.data+1,1); // b;
int pltecrc = crc(dd+plte_offset,7);
memcpy(dd+plte_offset+4,((char*)data.data)+3,1); // r;
memcpy(dd+plte_offset+5,((char*)data.data)+2,1); // g;
memcpy(dd+plte_offset+6,((char*)data.data)+1,1); // b;
pltecrc = crc(dd+plte_offset,7);
dd[plte_offset+7] = (unsigned char)((pltecrc >> 24) & 0xff);
dd[plte_offset+8] = (unsigned char)((pltecrc >> 16) & 0xff);
dd[plte_offset+9] = (unsigned char)((pltecrc >> 8) & 0xff);
dd[plte_offset+10] = (unsigned char)(pltecrc & 0xff);
if((unsigned char*)(data.data+4) != 255) {
memcpy(dd+trns_offset+4,data.data+4,1); // a;
int trnscrc = crc(dd+trns_offset,5);
if((unsigned char*)(((char*)data.data)+4) != 255) {
int trnscrc;
memcpy(dd+trns_offset+4,((char*)data.data)+4,1); // a;
trnscrc = crc(dd+trns_offset,5);
dd[trns_offset+5] = (unsigned char)((trnscrc >> 24) & 0xff);
dd[trns_offset+6] = (unsigned char)((trnscrc >> 16) & 0xff);
dd[trns_offset+7] = (unsigned char)((trnscrc >> 8) & 0xff);
Expand All @@ -370,7 +380,7 @@ static int _mapcache_cache_bdb_get(mapcache_context *ctx, mapcache_tile *tile)
tile->encoded_data->avail = data.size;
apr_pool_cleanup_register(ctx->pool, tile->encoded_data->buf,(void*)free, apr_pool_cleanup_null);
}
tile->mtime = *((apr_time_t*)(data.data+data.size-sizeof(apr_time_t)));
tile->mtime = *((apr_time_t*)(((char*)data.data)+data.size-sizeof(apr_time_t)));
ret = MAPCACHE_SUCCESS;
} else if(ret == DB_NOTFOUND) {
ret = MAPCACHE_CACHE_MISS;
Expand All @@ -387,11 +397,12 @@ static void _mapcache_cache_bdb_set(mapcache_context *ctx, mapcache_tile *tile)
{
DBT key,data;
int ret;
apr_time_t now;
mapcache_cache_bdb *cache = (mapcache_cache_bdb*)tile->tileset->cache;
char *skey = mapcache_util_get_tile_key(ctx,tile,cache->key_template,NULL,NULL);
struct bdb_env *benv = _bdb_get_conn(ctx,tile,0);
GC_CHECK_ERROR(ctx);
apr_time_t now = apr_time_now();
now = apr_time_now();
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));

Expand All @@ -406,8 +417,8 @@ static void _mapcache_cache_bdb_set(mapcache_context *ctx, mapcache_tile *tile)
data.size = 5+sizeof(apr_time_t);
data.data = apr_palloc(ctx->pool,data.size);
(((char*)data.data)[0])='#';
memcpy(data.data+1,tile->raw_image->data,4);
memcpy(data.data+5,&now,sizeof(apr_time_t));
memcpy(((char*)data.data)+1,tile->raw_image->data,4);
memcpy(((char*)data.data)+5,&now,sizeof(apr_time_t));
} else {
if(!tile->encoded_data) {
tile->encoded_data = tile->tileset->format->write(ctx, tile->raw_image, tile->tileset->format);
Expand All @@ -434,18 +445,20 @@ static void _mapcache_cache_bdb_multiset(mapcache_context *ctx, mapcache_tile *t
{
DBT key,data;
int ret,i;
apr_time_t now;
mapcache_cache_bdb *cache = (mapcache_cache_bdb*)tiles[0].tileset->cache;
struct bdb_env *benv = _bdb_get_conn(ctx,&tiles[0],0);
GC_CHECK_ERROR(ctx);
apr_time_t now = apr_time_now();
now = apr_time_now();
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));

for(i=0; i<ntiles; i++) {
char *skey;
mapcache_tile *tile;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
char *skey;
mapcache_tile *tile = &tiles[i];
tile = &tiles[i];
skey = mapcache_util_get_tile_key(ctx,tile,cache->key_template,NULL,NULL);
if(!tile->raw_image) {
tile->raw_image = mapcache_imageio_decode(ctx, tile->encoded_data);
Expand All @@ -455,8 +468,8 @@ static void _mapcache_cache_bdb_multiset(mapcache_context *ctx, mapcache_tile *t
data.size = 5+sizeof(apr_time_t);
data.data = apr_palloc(ctx->pool,data.size);
(((char*)data.data)[0])='#';
memcpy(data.data+1,tile->raw_image->data,4);
memcpy(data.data+5,&now,sizeof(apr_time_t));
memcpy(((char*)data.data)+1,tile->raw_image->data,4);
memcpy(((char*)data.data)+5,&now,sizeof(apr_time_t));
} else {
if(!tile->encoded_data) {
tile->encoded_data = tile->tileset->format->write(ctx, tile->raw_image, tile->tileset->format);
Expand Down
2 changes: 1 addition & 1 deletion lib/cache_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ static void _mapcache_cache_disk_set(mapcache_context *ctx, mapcache_tile *tile)
char errmsg[120];
char *filename, *hackptr1, *hackptr2=NULL;
const int creation_retry = ((mapcache_cache_disk*)tile->tileset->cache)->creation_retry;
int retry_count_create_file = 0;

#ifdef DEBUG
/* all this should be checked at a higher level */
Expand Down Expand Up @@ -581,7 +582,6 @@ static void _mapcache_cache_disk_set(mapcache_context *ctx, mapcache_tile *tile)
GC_CHECK_ERROR(ctx);
}

int retry_count_create_file = 0;
/*
* depending on configuration file creation will retry if it fails.
* this can happen on nfs mounted network storage.
Expand Down
6 changes: 3 additions & 3 deletions lib/cache_sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ static int _sqlite_set_pragmas(apr_pool_t *pool, mapcache_cache_sqlite* cache, s
static apr_status_t _sqlite_reslist_get_rw_connection(void **conn_, void *params, apr_pool_t *pool)
{
int ret;
int flags;
mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*) params;
struct sqlite_conn *conn = apr_pcalloc(pool, sizeof (struct sqlite_conn));
*conn_ = conn;
int flags;
flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_CREATE;
ret = sqlite3_open_v2(cache->dbfile, &conn->handle, flags, NULL);
if (ret != SQLITE_OK) {
Expand Down Expand Up @@ -135,10 +135,10 @@ static apr_status_t _sqlite_reslist_get_rw_connection(void **conn_, void *params
static apr_status_t _sqlite_reslist_get_ro_connection(void **conn_, void *params, apr_pool_t *pool)
{
int ret;
int flags;
mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*) params;
struct sqlite_conn *conn = apr_pcalloc(pool, sizeof (struct sqlite_conn));
*conn_ = conn;
int flags;
flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_NOMUTEX;
ret = sqlite3_open_v2(cache->dbfile, &conn->handle, flags, NULL);
if (ret != SQLITE_OK) {
Expand Down Expand Up @@ -370,12 +370,12 @@ static void _bind_mbtiles_params(mapcache_context *ctx, void *vstmt, mapcache_ti

paramidx = sqlite3_bind_parameter_index(stmt, ":color");
if (paramidx) {
assert(tile->raw_image);
char *key = apr_psprintf(ctx->pool,"#%02x%02x%02x%02x",
tile->raw_image->data[0],
tile->raw_image->data[1],
tile->raw_image->data[2],
tile->raw_image->data[3]);
assert(tile->raw_image);
sqlite3_bind_text(stmt, paramidx, key, -1, SQLITE_STATIC);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/service_wmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static ezxml_t _wmts_service_contactinfo(mapcache_context *ctx, mapcache_cfg *cf
{
const char *value;
int addNode = 0;
ezxml_t nodeAddress;

ezxml_t nodeInfo = ezxml_new("ows:ContactInfo");
ezxml_t nodePhone = ezxml_new("ows:Phone");
Expand All @@ -196,7 +197,7 @@ static ezxml_t _wmts_service_contactinfo(mapcache_context *ctx, mapcache_cfg *cf


addNode = 0;
ezxml_t nodeAddress = ezxml_new("ows:Address");
nodeAddress = ezxml_new("ows:Address");

value = apr_table_get(cfg->metadata,"contactorganization");
if(value) {
Expand Down
Loading

0 comments on commit ff5e3b1

Please sign in to comment.