From e89046b5ee26874a8173753915899da406e4f50e Mon Sep 17 00:00:00 2001
From: Hummeltech <6109326+hummeltech@users.noreply.github.com>
Date: Wed, 19 Jun 2024 09:20:50 -0700
Subject: [PATCH] Also use `renderd_config` for `mod_tile` (#440)
Follow-up to #391 & #400
---
Makefile.am | 6 +-
docs/man/renderd.conf.5 | 40 +-
includes/mod_tile.h | 66 +-
src/CMakeLists.txt | 2 +
src/mod_tile.c | 1874 ++++++++++++---------------------
tests/CMakeLists.txt | 50 +-
tests/renderd.conf.in | 8 +-
tests/renderd_config_test.cpp | 2 +-
8 files changed, 749 insertions(+), 1299 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 92a40e4f..393febe7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -149,9 +149,10 @@ test: gen_tile_test renderd_config_test renderd_test render_expired_test render_
all-local:
$(APXS) -c $(DEF_LDLIBS) $(AM_CFLAGS) \
$(subst -pthread,-Wc$(COMMA)-pthread,$(GLIB_CFLAGS)) \
- -I@srcdir@/includes $(AM_LDFLAGS) $(STORE_LDFLAGS) \
+ -I@srcdir@/includes $(AM_LDFLAGS) $(STORE_LDFLAGS) $(INIPARSER_LDFLAGS) \
@srcdir@/src/mod_tile.c \
@srcdir@/src/g_logger.c \
+ @srcdir@/src/renderd_config.c \
@srcdir@/src/store.c \
@srcdir@/src/store_file.c \
@srcdir@/src/store_file_utils.c \
@@ -167,9 +168,10 @@ install-mod_tile:
$(APXS) -S LIBEXECDIR=$(DESTDIR)`$(APXS) \
-q LIBEXECDIR` -c -i $(DEF_LDLIBS) $(AM_CFLAGS) \
$(subst -pthread,-Wc$(COMMA)-pthread,$(GLIB_CFLAGS)) \
- -I@srcdir@/includes $(AM_LDFLAGS) $(STORE_LDFLAGS) \
+ -I@srcdir@/includes $(AM_LDFLAGS) $(STORE_LDFLAGS) $(INIPARSER_LDFLAGS) \
@srcdir@/src/mod_tile.c \
@srcdir@/src/g_logger.c \
+ @srcdir@/src/renderd_config.c \
@srcdir@/src/store.c \
@srcdir@/src/store_file.c \
@srcdir@/src/store_file_utils.c \
diff --git a/docs/man/renderd.conf.5 b/docs/man/renderd.conf.5
index 346ee545..fe4b0c05 100644
--- a/docs/man/renderd.conf.5
+++ b/docs/man/renderd.conf.5
@@ -1,4 +1,4 @@
-.TH RENDERD.CONF 5 "2024-03-16" "mod_tile v0.7.1"
+.TH RENDERD.CONF 5 "2024-06-06" "mod_tile v0.7.1"
.\" Please adjust this date whenever revising the manpage.
.SH NAME
@@ -14,7 +14,7 @@ This manual page documents briefly the \fBrenderd.conf\fR configuration file.
.PP
The default location is \fB'/etc/renderd.conf'\fR (macro definition \fB'RENDERD_CONFIG'\fR).
.PP
-All option names are \fBcase-insensitive\fR unless otherwise specified.
+All option names are \fBcase-insensitive\fR.
.SH RENDERD
@@ -100,37 +100,32 @@ There must be at least one \fB[map]\fR section.
\fB[map]\fR section names can be anything else, but they must all be unique.
.TP
-.B ASPECTX
+.B aspectx
Specify the X aspect to be used by \fBmod_tile\fR.
Only used by \fBmod_tile\fR.
The default value is \fB'1'\fR.
-This option name is \fBcase-sensitive\fR.
.TP
-.B ASPECTY
+.B aspecty
Specify the Y aspect to be used by \fBmod_tile\fR.
Only used by \fBmod_tile\fR.
The default value is \fB'1'\fR.
-This option name is \fBcase-sensitive\fR.
.TP
-.B ATTRIBUTION
+.B attribution
Specify the data attribution to be provided by \fBmod_tile\fR as \fBTileJSON\fR (via \fB{URI}/tile-layer.json\fR).
Only used by \fBmod_tile\fR.
The default value is \fB'©OpenStreetMap and contributors, (ODbL)'\fR (macro definition \fB'DEFAULT_ATTRIBUTION'\fR).
-This option name is \fBcase-sensitive\fR.
.TP
-.B CORS
+.B cors
Specify the CORS configuration for \fBmod_tile\fR.
Only used by \fBmod_tile\fR.
-This option name is \fBcase-sensitive\fR.
.TP
-.B DESCRIPTION
+.B description
Specify the description to be provided by \fBmod_tile\fR as \fBTileJSON\fR (via \fB{URI}/tile-layer.json\fR).
Only used by \fBmod_tile\fR.
-This option name is \fBcase-sensitive\fR.
.TP
.B htcphost
@@ -143,28 +138,24 @@ Specify the IP address/hostname of the Host to be used by \fBrenderd\fR for HTCP
Only used by \fBrenderd\fR.
.TP
-.B MAXZOOM
+.B maxzoom
Specify the maximum zoom level for this section.
The default value is \fB'20'\fR (macro definition \fB'MAX_ZOOM'\fR).
-This option name is \fBcase-sensitive\fR.
.TP
-.B MINZOOM
+.B minzoom
Specify the minimum zoom level for this section.
The default value is \fB'0'\fR.
-This option name is \fBcase-sensitive\fR.
.TP
-.B PARAMETERIZE_STYLE
+.B parameterize_style
Specify the parameterization style/function to be used for this section.
The value of \fB'language'\fR seems to be the only one supported.
-This option name is \fBcase-sensitive\fR.
.TP
-.B SERVER_ALIAS
+.B server_alias
Specify a URL alias of this server to be provided by \fBmod_tile\fR as \fBTileJSON\fR (via \fB{URI}/tile-layer.json\fR).
Only used by \fBmod_tile\fR.
-This option name is \fBcase-sensitive\fR.
.TP
.B scale
@@ -173,10 +164,9 @@ Only used by \fBrenderd\fR.
The default value is \fB'1.0'\fR.
.TP
-.B TILEDIR
+.B tiledir
Specify the directory path into which tiles will be written by \fBrenderd\fR.
The default value is \fB'/var/cache/renderd/tiles'\fR (macro definition \fB'RENDERD_TILE_DIR'\fR).
-This option name is \fBcase-sensitive\fR.
.TP
.B tilesize
@@ -185,14 +175,12 @@ Only used by \fBrenderd\fR.
The default value is \fB'256'\fR.
.TP
-.B TYPE
+.B type
Specify the tile configuration (in the format \fB' '\fR) for this section (e.g. \fB'png image/png png256'\fR).
-This option name is \fBcase-sensitive\fR.
.TP
-.B URI
+.B uri
Specify the URI prefix with which tiles can be accessed for this section.
-This option name is \fBcase-sensitive\fR.
.TP
.B xml
diff --git a/includes/mod_tile.h b/includes/mod_tile.h
index d0e1aa46..5dba438d 100644
--- a/includes/mod_tile.h
+++ b/includes/mod_tile.h
@@ -92,54 +92,54 @@ typedef struct stats_data {
} stats_data;
typedef struct {
- const char *store;
- char xmlname[XMLCONFIG_MAX];
- char baseuri[PATH_MAX];
- char fileExtension[PATH_MAX];
- char mimeType[PATH_MAX];
- const char *description;
+ char **hostnames;
const char *attribution;
+ const char *baseuri;
const char *cors;
- char **hostnames;
- int noHostnames;
- int minzoom;
- int maxzoom;
+ const char *description;
+ const char *fileExtension;
+ const char *mimeType;
+ const char *store;
+ const char *xmlname;
int aspect_x;
int aspect_y;
int enableOptions;
+ int maxzoom;
+ int minzoom;
+ int noHostnames;
} tile_config_rec;
typedef struct {
apr_array_header_t *configs;
- int request_timeout;
- int request_timeout_priority;
- int max_load_old;
- int max_load_missing;
- apr_time_t veryold_threshold;
+ apr_time_t very_old_threshold;
+ const char *cache_extended_hostname;
+ const char *renderd_socket_name;
+ const char *tile_dir;
+ double cache_duration_last_modified_factor;
int cache_duration_dirty;
+ int cache_duration_low_zoom;
int cache_duration_max;
+ int cache_duration_medium_zoom;
int cache_duration_minimum;
- int cache_duration_low_zoom;
+ int cache_extended_duration;
int cache_level_low_zoom;
- int cache_duration_medium_zoom;
int cache_level_medium_zoom;
- double cache_duration_last_modified_factor;
- char renderd_socket_name[PATH_MAX];
- int renderd_socket_port;
- char tile_dir[PATH_MAX];
- char cache_extended_hostname[PATH_MAX];
- int cache_extended_duration;
+ int delaypool_render_size;
+ int delaypool_tile_size;
+ int enable_bulk_mode;
+ int enable_dirty_url;
+ int enable_global_stats;
+ int enable_status_url;
+ int enable_tile_throttling;
+ int enable_tile_throttling_xforward;
+ int max_load_missing;
+ int max_load_old;
int mincachetime[MAX_ZOOM_SERVER + 1];
- int enableGlobalStats;
- int enableTileThrottling;
- int enableTileThrottlingXForward;
- int delaypoolTileSize;
- long delaypoolTileRate;
- int delaypoolRenderSize;
- long delaypoolRenderRate;
- int bulkMode;
- int enableStatusUrl;
- int enableDirtyUrl;
+ int renderd_socket_port;
+ int request_timeout;
+ int request_timeout_priority;
+ long delaypool_render_rate;
+ long delaypool_tile_rate;
} tile_server_conf;
typedef struct tile_request_data {
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8ba80ff0..e7e62d6d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -77,10 +77,12 @@ set(mod_tile_SRCS
${COMMON_SRCS}
${STORE_SRCS}
mod_tile.c
+ renderd_config.c
)
set(mod_tile_LIBS
${APR_LIBRARIES}
${COMMON_LIBRARIES}
+ ${INIPARSER_LIBRARIES}
${STORE_LIBRARIES}
)
add_library(mod_tile SHARED ${mod_tile_SRCS})
diff --git a/src/mod_tile.c b/src/mod_tile.c
index d3fc76ed..39c3d29b 100644
--- a/src/mod_tile.c
+++ b/src/mod_tile.c
@@ -15,66 +15,61 @@
* along with this program; If not, see http://www.gnu.org/licenses/.
*/
-#include
-#include
-#include /* for RLIMIT stuff */
-#include
-#include
-#include
-#include
-
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
-#include
-#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include
-#include
-#include
-#include
-#include
#include
-#include
-#include
-#include
-#include
-#include
-
-module AP_MODULE_DECLARE_DATA tile_module;
-
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include
#include
#include
-#include
-#include
#include
-#include
+#include
#include
+#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
+#include
-#include "gen_tile.h"
+#include "config.h"
+#include "mod_tile.h"
#include "protocol.h"
#include "render_config.h"
+#include "renderd.h"
+#include "renderd_config.h"
#include "store.h"
-#include "mod_tile.h"
#include "sys_utils.h"
+module AP_MODULE_DECLARE_DATA tile_module;
#if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE)
-#include "unixd.h"
+#include
#define MOD_TILE_SET_MUTEX_PERMS /* XXX Apache should define something */
#endif
@@ -96,7 +91,7 @@ int layerCount = 0;
int global_max_zoom = 0;
struct storage_backends {
- struct storage_backend ** stores;
+ struct storage_backend **stores;
int noBackends;
};
@@ -109,19 +104,16 @@ static int error_message(request_rec *r, const char *format, ...)
char *msg;
va_start(ap, format);
- msg = malloc(1000 * sizeof(char));
+ msg = apr_pvsprintf(r->pool, format, ap);
if (msg) {
- vsnprintf(msg, 1000, format, ap);
- //ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "%s", msg);
+ // ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "%s", msg);
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%s", msg);
r->content_type = "text/plain";
if (!r->header_only) {
ap_rputs(msg, r);
}
-
- free(msg);
}
va_end(ap);
@@ -136,17 +128,16 @@ static int socket_init(request_rec *r)
char portnum[16];
char ipstring[INET6_ADDRSTRLEN];
int fd, s;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
if (scfg->renderd_socket_port > 0) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Connecting to renderd on %s:%i via TCP", scfg->renderd_socket_name, scfg->renderd_socket_port);
memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
+ hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_STREAM; /* TCP socket */
hints.ai_flags = 0;
- hints.ai_protocol = 0; /* Any protocol */
+ hints.ai_protocol = 0; /* Any protocol */
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
@@ -215,7 +206,7 @@ static int socket_init(request_rec *r)
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, scfg->renderd_socket_name, sizeof(addr.sun_path) - sizeof(char));
- if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "socket connect failed for: %s with reason: %s", scfg->renderd_socket_name, strerror(errno));
close(fd);
return FD_INVALID;
@@ -232,8 +223,7 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
int retry = 1;
struct protocol resp;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
fd = socket_init(r);
@@ -265,7 +255,7 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
}
}
- if (scfg->bulkMode) {
+ if (scfg->enable_bulk_mode) {
cmd->cmd = cmdRenderBulk;
}
@@ -319,12 +309,12 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
if (ret != sizeof(struct protocol_v2)) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "request_tile: Failed to read response from rendering socket. Got %d bytes but expected %d. Errno %d (%s)",
- ret, (int) sizeof(struct protocol_v2), errno, strerror(errno));
+ ret, (int)sizeof(struct protocol_v2), errno, strerror(errno));
break;
}
if (resp.ver == 3) {
- ret += recv(fd, ((void*)&resp) + sizeof(struct protocol_v2), sizeof(struct protocol) - sizeof(struct protocol_v2), 0);
+ ret += recv(fd, ((void *)&resp) + sizeof(struct protocol_v2), sizeof(struct protocol) - sizeof(struct protocol_v2), 0);
}
if (cmd->x == resp.x && cmd->y == resp.y && cmd->z == resp.z && !strcmp(cmd->xmlname, resp.xmlname)) {
@@ -360,9 +350,9 @@ static int request_tile(request_rec *r, struct protocol *cmd, int renderImmediat
return 0;
}
-static apr_status_t cleanup_storage_backend(void * data)
+static apr_status_t cleanup_storage_backend(void *data)
{
- struct storage_backends * stores = (struct storage_backends *)data;
+ struct storage_backends *stores = (struct storage_backends *)data;
int i;
for (i = 0; i < stores->noBackends; i++) {
@@ -374,45 +364,44 @@ static apr_status_t cleanup_storage_backend(void * data)
return APR_SUCCESS;
}
-static struct storage_backend * get_storage_backend(request_rec *r, int tile_layer)
+static struct storage_backend *get_storage_backend(request_rec *r, int tile_layer)
{
- struct storage_backends * stores = NULL;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
- tile_config_rec *tile_configs = (tile_config_rec *) scfg->configs->elts;
+ struct storage_backends *stores = NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
+ tile_config_rec *tile_configs = (tile_config_rec *)scfg->configs->elts;
tile_config_rec *tile_config = &tile_configs[tile_layer];
- apr_thread_t * current_thread = r->connection->current_thread;
+ apr_thread_t *current_thread = r->connection->current_thread;
apr_pool_t *lifecycle_pool = apr_thread_pool_get(current_thread);
- char * memkey = apr_psprintf(r->pool, "mod_tile_storage_backends");
+ char *memkey = apr_psprintf(r->pool, "mod_tile_storage_backends");
apr_os_thread_t os_thread = apr_os_thread_current();
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: Retrieving storage back end for tile layer %i in pool %pp and thread %li",
- tile_layer, lifecycle_pool, (unsigned long) os_thread);
+ tile_layer, lifecycle_pool, (unsigned long)os_thread);
if (apr_pool_userdata_get((void **)&stores, memkey, lifecycle_pool) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "get_storage_backend: Failed horribly!");
}
if (stores == NULL) {
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: No storage backends for this lifecycle %pp, creating it in thread %li", lifecycle_pool, (unsigned long) os_thread);
- stores = apr_pcalloc(lifecycle_pool, sizeof(struct storage_backends));
- stores->stores = apr_pcalloc(lifecycle_pool, sizeof(struct storage_backend *) * scfg->configs->nelts);
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: No storage backends for this lifecycle %pp, creating it in thread %li", lifecycle_pool, (unsigned long)os_thread);
+ stores = (struct storage_backends *)apr_pcalloc(lifecycle_pool, sizeof(struct storage_backends));
+ stores->stores = (struct storage_backend **)apr_pcalloc(lifecycle_pool, sizeof(struct storage_backend *) * scfg->configs->nelts);
stores->noBackends = scfg->configs->nelts;
if (apr_pool_userdata_set(stores, memkey, &cleanup_storage_backend, lifecycle_pool) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "get_storage_backend: Failed horribly to set user_data!");
}
} else {
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: Found backends (%pp) for this lifecycle %pp in thread %li", stores, lifecycle_pool, (unsigned long) os_thread);
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: Found backends (%pp) for this lifecycle %pp in thread %li", stores, lifecycle_pool, (unsigned long)os_thread);
}
if (stores->stores[tile_layer] == NULL) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: No storage backend in current lifecycle %pp in thread %li for current tile layer %i",
- lifecycle_pool, (unsigned long) os_thread, tile_layer);
+ lifecycle_pool, (unsigned long)os_thread, tile_layer);
stores->stores[tile_layer] = init_storage_backend(tile_config->store);
} else {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "get_storage_backend: Storage backend found in current lifecycle %pp for current tile layer %i in thread %li",
- lifecycle_pool, tile_layer, (unsigned long) os_thread);
+ lifecycle_pool, tile_layer, (unsigned long)os_thread);
}
return stores->stores[tile_layer];
@@ -420,11 +409,10 @@ static struct storage_backend * get_storage_backend(request_rec *r, int tile_lay
static enum tileState tile_state(request_rec *r, struct protocol *cmd)
{
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
struct stat_info stat;
- struct tile_request_data * rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module);
+ struct tile_request_data *rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module);
stat = rdata->store->tile_stat(rdata->store, cmd->xmlname, cmd->options, cmd->x, cmd->y, cmd->z);
@@ -440,7 +428,7 @@ static enum tileState tile_state(request_rec *r, struct protocol *cmd)
}
if (stat.expired) {
- if ((r->request_time - r->finfo.mtime) < scfg->veryold_threshold) {
+ if ((r->request_time - r->finfo.mtime) < scfg->very_old_threshold) {
return tileOld;
} else {
return tileVeryOld;
@@ -454,10 +442,10 @@ static enum tileState tile_state(request_rec *r, struct protocol *cmd)
* Add CORS ( Cross-origin resource sharing ) headers. http://www.w3.org/TR/cors/
* CORS allows requests that would otherwise be forbidden under the same origin policy.
*/
-static int add_cors(request_rec *r, const char * cors)
+static int add_cors(request_rec *r, const char *cors)
{
- const char* headers;
- const char* origin = apr_table_get(r->headers_in, "Origin");
+ const char *headers;
+ const char *origin = apr_table_get(r->headers_in, "Origin");
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking if CORS headers need to be added: Origin: %s Policy: %s", origin, cors);
if (!origin) {
@@ -474,7 +462,6 @@ static int add_cors(request_rec *r, const char * cors)
apr_psprintf(r->pool, "%s", origin));
apr_table_setn(r->headers_out, "Vary",
apr_psprintf(r->pool, "%s", "Origin"));
-
}
if (strcmp(r->method, "OPTIONS") == 0 &&
@@ -499,7 +486,7 @@ static int add_cors(request_rec *r, const char * cors)
}
}
-static void add_expiry(request_rec *r, struct protocol * cmd)
+static void add_expiry(request_rec *r, struct protocol *cmd)
{
apr_time_t holdoff;
apr_table_t *t = r->headers_out;
@@ -508,25 +495,23 @@ static void add_expiry(request_rec *r, struct protocol * cmd)
char *timestr;
long int maxAge, minCache, lastModified;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
- struct tile_request_data * rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module);
- tile_config_rec *tile_configs = (tile_config_rec *) scfg->configs->elts;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
+ struct tile_request_data *rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module);
+ tile_config_rec *tile_configs = (tile_config_rec *)scfg->configs->elts;
tile_config_rec *tile_config = &tile_configs[rdata->layerNumber];
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "expires(%s), uri(%s),, path_info(%s)\n",
r->handler, r->uri, r->path_info);
/* If the hostname matches the "extended caching hostname" then set the cache age accordingly */
- if ((scfg->cache_extended_hostname[0] != 0) && (strstr(r->hostname,
+ if ((strlen(scfg->cache_extended_hostname) != 0) && (strstr(r->hostname,
scfg->cache_extended_hostname) != NULL)) {
maxAge = scfg->cache_extended_duration;
} else {
/* Test if the tile we are serving is out of date, then set a low maxAge*/
if (state == tileOld) {
- holdoff = (scfg->cache_duration_dirty / 2.0) * (rand() / (RAND_MAX
- + 1.0));
+ holdoff = (scfg->cache_duration_dirty / 2.0) * (rand() / (RAND_MAX + 1.0));
maxAge = scfg->cache_duration_dirty + holdoff;
} else {
// cache heuristic based on zoom level
@@ -539,16 +524,14 @@ static void add_expiry(request_rec *r, struct protocol * cmd)
}
// Time to the next known complete rerender
- //planetTimestamp = apr_time_sec(getPlanetTime(r)
+ // planetTimestamp = apr_time_sec(getPlanetTime(r)
// + apr_time_from_sec(PLANET_INTERVAL) - r->request_time);
// Time since the last render of this tile
- lastModified = (int)(((double) apr_time_sec(r->request_time
- - finfo->mtime))
- * scfg->cache_duration_last_modified_factor);
+ lastModified = (int)(((double)apr_time_sec(r->request_time - finfo->mtime)) * scfg->cache_duration_last_modified_factor);
// Add a random jitter of 3 hours to space out cache expiry
holdoff = (3 * 60 * 60) * (rand() / (RAND_MAX + 1.0));
- //maxAge = MAX(minCache, planetTimestamp);
+ // maxAge = MAX(minCache, planetTimestamp);
maxAge = minCache;
maxAge = MAX(maxAge, lastModified);
maxAge += holdoff;
@@ -569,14 +552,12 @@ static void add_expiry(request_rec *r, struct protocol * cmd)
apr_table_mergen(t, "Cache-Control",
apr_psprintf(r->pool, "max-age=%li", maxAge));
- timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
+ timestr = (char *)apr_palloc(r->pool, APR_RFC822_DATE_LEN);
apr_rfc822_date(timestr, (apr_time_from_sec(maxAge) + r->request_time));
apr_table_setn(t, "Expires", timestr);
}
-
-
-static int get_global_lock(request_rec *r, apr_global_mutex_t * mutex)
+static int get_global_lock(request_rec *r, apr_global_mutex_t *mutex)
{
apr_status_t rs;
int camped;
@@ -608,14 +589,13 @@ static int get_global_lock(request_rec *r, apr_global_mutex_t * mutex)
return 0;
}
-static int incRespCounter(int resp, request_rec *r, struct protocol * cmd, int layerNumber)
+static int incRespCounter(int resp, request_rec *r, struct protocol *cmd, int layerNumber)
{
stats_data *stats;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
- if (!scfg->enableGlobalStats) {
+ if (!scfg->enable_global_stats) {
/* If tile stats reporting is not enable
* pretend we correctly updated the counter to
* not fill the logs with warnings about failed
@@ -669,7 +649,6 @@ static int incRespCounter(int resp, request_rec *r, struct protocol * cmd, int l
default: {
stats->noRespOther++;
}
-
}
apr_global_mutex_unlock(stats_mutex);
@@ -686,10 +665,9 @@ static int incFreshCounter(int status, request_rec *r)
{
stats_data *stats;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
- if (!scfg->enableGlobalStats) {
+ if (!scfg->enable_global_stats) {
/* If tile stats reporting is not enable
* pretend we correctly updated the counter to
* not fill the logs with warnings about failed
@@ -731,7 +709,6 @@ static int incFreshCounter(int status, request_rec *r)
stats->noVeryOldRender++;
break;
}
-
}
apr_global_mutex_unlock(stats_mutex);
@@ -748,10 +725,9 @@ static int incTimingCounter(apr_uint64_t duration, int z, request_rec *r)
{
stats_data *stats;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
- if (!scfg->enableGlobalStats) {
+ if (!scfg->enable_global_stats) {
/* If tile stats reporting is not enable
* pretend we correctly updated the counter to
* not fill the logs with warnings about failed
@@ -778,12 +754,12 @@ static int incTimingCounter(apr_uint64_t duration, int z, request_rec *r)
static int delay_allowed(request_rec *r, enum tileState state)
{
- delaypool * delayp;
+ delaypool *delayp;
int delay = 0;
int i, j;
- char * strtok_state;
- char * tmp;
- const char * ip_addr = NULL;
+ char *strtok_state;
+ char *tmp;
+ const char *ip_addr = NULL;
apr_time_t now;
int tiles_topup;
int render_topup;
@@ -791,25 +767,24 @@ static int delay_allowed(request_rec *r, enum tileState state)
struct in_addr sin_addr;
struct in6_addr ip;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
delayp = (delaypool *)apr_shm_baseaddr_get(delaypool_shm);
ip_addr = r->useragent_ip;
- if (scfg->enableTileThrottlingXForward) {
- char * ip_addrs = apr_pstrdup(r->pool, apr_table_get(r->headers_in, "X-Forwarded-For"));
+ if (scfg->enable_tile_throttling_xforward) {
+ char *ip_addrs = apr_pstrdup(r->pool, apr_table_get(r->headers_in, "X-Forwarded-For"));
if (ip_addrs) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking throttling delays: Found X-Forwarded-For header \"%s\", forwarded by %s", ip_addrs, r->connection->client_ip);
- //X-Forwarded-For can be a chain of proxies deliminated by , The first entry in the list is the client, the last entry is the remote address seen by the proxy
- //closest to the tileserver.
+ // X-Forwarded-For can be a chain of proxies deliminated by , The first entry in the list is the client, the last entry is the remote address seen by the proxy
+ // closest to the tileserver.
strtok_state = NULL;
tmp = apr_strtok(ip_addrs, ", ", &strtok_state);
ip_addr = tmp;
- //Use the last entry in the chain of X-Forwarded-For instead of the client, i.e. the entry added by the proxy closest to the tileserver
- //If this is a reverse proxy under our control, its X-Forwarded-For can be trusted.
- if (scfg->enableTileThrottlingXForward == 2) {
+ // Use the last entry in the chain of X-Forwarded-For instead of the client, i.e. the entry added by the proxy closest to the tileserver
+ // If this is a reverse proxy under our control, its X-Forwarded-For can be trusted.
+ if (scfg->enable_tile_throttling_xforward == 2) {
while ((tmp = apr_strtok(NULL, ", ", &strtok_state)) != NULL) {
ip_addr = tmp;
}
@@ -819,9 +794,8 @@ static int delay_allowed(request_rec *r, enum tileState state)
}
}
-
if (inet_pton(AF_INET, ip_addr, &sin_addr) > 0) {
- //ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking delays: for IP %s appears to be an IPv4 address", ip_addr);
+ // ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking delays: for IP %s appears to be an IPv4 address", ip_addr);
memset(ip.s6_addr, 0, 16);
memcpy(&(ip.s6_addr[12]), &(sin_addr.s_addr), 4);
hashkey = sin_addr.s_addr % DELAY_HASHTABLE_WHITELIST_SIZE;
@@ -853,7 +827,7 @@ static int delay_allowed(request_rec *r, enum tileState state)
/* Repeat the process to determine if we have tockens in the bucket, as the fillup only runs once a client hits an empty bucket,
so in the mean time, the bucket might have been filled */
for (j = 0; j < 3; j++) {
- //ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking delays: Current poolsize: %i tiles and %i renders\n", delayp->users[hashkey].available_tiles, delayp->users[hashkey].available_render_req);
+ // ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Checking delays: Current poolsize: %i tiles and %i renders\n", delayp->users[hashkey].available_tiles, delayp->users[hashkey].available_render_req);
delay = 0;
if (delayp->users[hashkey].available_tiles > 0) {
@@ -885,10 +859,10 @@ static int delay_allowed(request_rec *r, enum tileState state)
/* We hit an empty bucket, so run the bucket fillup procedure to check if new tokens should have arrived in the mean time. */
now = apr_time_now();
- tiles_topup = (now - delayp->last_tile_fillup) / scfg->delaypoolTileRate;
- render_topup = (now - delayp->last_render_fillup) / scfg->delaypoolRenderRate;
+ tiles_topup = (now - delayp->last_tile_fillup) / scfg->delaypool_tile_rate;
+ render_topup = (now - delayp->last_render_fillup) / scfg->delaypool_render_rate;
- //ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Filling up pools with %i tiles and %i renders\n", tiles_topup, render_topup);
+ // ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Filling up pools with %i tiles and %i renders\n", tiles_topup, render_topup);
if ((tiles_topup > 0) || (render_topup > 0)) {
delayp->locked = 1;
@@ -896,20 +870,20 @@ static int delay_allowed(request_rec *r, enum tileState state)
delayp->users[i].available_tiles += tiles_topup;
delayp->users[i].available_render_req += render_topup;
- if (delayp->users[i].available_tiles > scfg->delaypoolTileSize) {
- delayp->users[i].available_tiles = scfg->delaypoolTileSize;
+ if (delayp->users[i].available_tiles > scfg->delaypool_tile_size) {
+ delayp->users[i].available_tiles = scfg->delaypool_tile_size;
}
- if (delayp->users[i].available_render_req > scfg->delaypoolRenderSize) {
- delayp->users[i].available_render_req = scfg->delaypoolRenderSize;
+ if (delayp->users[i].available_render_req > scfg->delaypool_render_size) {
+ delayp->users[i].available_render_req = scfg->delaypool_render_size;
}
}
delayp->locked = 0;
}
- delayp->last_tile_fillup += scfg->delaypoolTileRate * tiles_topup;
- delayp->last_render_fillup += scfg->delaypoolRenderRate * render_topup;
+ delayp->last_tile_fillup += scfg->delaypool_tile_rate * tiles_topup;
+ delayp->last_render_fillup += scfg->delaypool_render_rate * render_topup;
} else {
break;
@@ -918,8 +892,8 @@ static int delay_allowed(request_rec *r, enum tileState state)
} else {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Creating a new delaypool for ip %s\n", ip_addr);
memcpy(&(delayp->users[hashkey].ip_addr), &ip, sizeof(struct in6_addr));
- delayp->users[hashkey].available_tiles = scfg->delaypoolTileSize;
- delayp->users[hashkey].available_render_req = scfg->delaypoolRenderSize;
+ delayp->users[hashkey].available_tiles = scfg->delaypool_tile_size;
+ delayp->users[hashkey].available_render_req = scfg->delaypool_render_size;
delay = 0;
}
@@ -933,51 +907,15 @@ static int delay_allowed(request_rec *r, enum tileState state)
}
}
-static int tile_handler_dirty(request_rec *r)
-{
- ap_conf_vector_t *sconf;
- tile_server_conf *scfg;
- struct tile_request_data * rdata;
- struct protocol * cmd;
-
- if (strcmp(r->handler, "tile_dirty")) {
- return DECLINED;
- }
-
- rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module);
- cmd = rdata->cmd;
-
- if (cmd == NULL) {
- return DECLINED;
- }
-
- sconf = r->server->module_config;
- scfg = ap_get_module_config(sconf, &tile_module);
-
- // Is /dirty URL enabled?
- if (!scfg->enableDirtyUrl) {
- ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "tile_handler_dirty: /dirty URL is not enabled");
- return HTTP_NOT_FOUND;
- }
-
- if (scfg->bulkMode) {
- return OK;
- }
-
- request_tile(r, cmd, 0);
- return error_message(r, "Tile submitted for rendering\n");
-}
-
static int tile_storage_hook(request_rec *r)
{
-// char abs_path[PATH_MAX];
+ // char abs_path[PATH_MAX];
double avg;
int renderPrio = 0;
enum tileState state;
- ap_conf_vector_t *sconf;
tile_server_conf *scfg;
- struct tile_request_data * rdata;
- struct protocol * cmd;
+ struct tile_request_data *rdata;
+ struct protocol *cmd;
if (!r->handler) {
return DECLINED;
@@ -987,8 +925,7 @@ static int tile_storage_hook(request_rec *r)
r->handler, r->uri);
// Any status request is OK. tile_dirty also doesn't need to be handled, as tile_handler_dirty will take care of it
- if (!strcmp(r->handler, "tile_status") || !strcmp(r->handler, "tile_dirty") || !strcmp(r->handler, "tile_mod_stats")
- || !(strcmp(r->handler, "tile_json"))) {
+ if (!strcmp(r->handler, "tile_status") || !strcmp(r->handler, "tile_dirty") || !strcmp(r->handler, "tile_mod_stats") || !(strcmp(r->handler, "tile_json"))) {
return OK;
}
@@ -1006,10 +943,9 @@ static int tile_storage_hook(request_rec *r)
avg = get_load_avg();
state = tile_state(r, cmd);
- sconf = r->server->module_config;
- scfg = ap_get_module_config(sconf, &tile_module);
+ scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
- if (scfg->enableTileThrottling && !delay_allowed(r, state)) {
+ if (scfg->enable_tile_throttling && !delay_allowed(r, state)) {
if (!incRespCounter(HTTP_SERVICE_UNAVAILABLE, r, cmd, rdata->layerNumber)) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
"Failed to increase response stats counter");
@@ -1030,7 +966,7 @@ static int tile_storage_hook(request_rec *r)
case tileOld:
case tileVeryOld:
- if (scfg->bulkMode) {
+ if (scfg->enable_bulk_mode) {
return OK;
} else if (avg > scfg->max_load_old) {
// Too much load to render it now, mark dirty but return old tile
@@ -1066,7 +1002,7 @@ static int tile_storage_hook(request_rec *r)
}
if (request_tile(r, cmd, renderPrio)) {
- //TODO: update finfo
+ // TODO: update finfo
if (!incFreshCounter(FRESH_RENDER, r)) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
"Failed to increase fresh stats counter");
@@ -1103,26 +1039,203 @@ static int tile_storage_hook(request_rec *r)
return HTTP_NOT_FOUND;
}
+static int tile_translate(request_rec *r)
+{
+ int i, n, limit, oob;
+ char option[11];
+ char extension[256];
+
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
+
+ tile_config_rec *tile_configs = (tile_config_rec *)scfg->configs->elts;
+
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: uri(%s)", r->uri);
+
+ /*
+ * The page /mod_tile returns global stats about the number of tiles
+ * handled and in what state those tiles were.
+ * This should probably not be hard coded
+ */
+ if (!strncmp("/mod_tile", r->uri, strlen("/mod_tile"))) {
+ r->handler = "tile_mod_stats";
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
+ "tile_translate: retrieving global mod_tile stats");
+ return OK;
+ }
+
+ /*
+ * The page /metrics returns global stats in Prometheus format.
+ */
+ if (!strncmp("/metrics", r->uri, strlen("/metrics"))) {
+ r->handler = "tile_metrics";
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
+ "tile_translate: retrieving global mod_tile metrics");
+ return OK;
+ }
+
+ for (i = 0; i < scfg->configs->nelts; ++i) {
+ tile_config_rec *tile_config = &tile_configs[i];
+
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: testing baseuri(%s) name(%s) extension(%s)",
+ tile_config->baseuri, tile_config->xmlname, tile_config->fileExtension);
+
+ if (!strncmp(tile_config->baseuri, r->uri, strlen(tile_config->baseuri))) {
+
+ struct tile_request_data *rdata = (struct tile_request_data *)apr_pcalloc(r->pool, sizeof(struct tile_request_data));
+ struct protocol *cmd = (struct protocol *)apr_pcalloc(r->pool, sizeof(struct protocol));
+ bzero(cmd, sizeof(struct protocol));
+ bzero(rdata, sizeof(struct tile_request_data));
+
+ if (!strncmp(r->uri + strlen(tile_config->baseuri), "tile-layer.json", strlen("tile-layer.json"))) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Requesting tileJSON for tilelayer %s", tile_config->xmlname);
+ r->handler = "tile_json";
+ rdata->layerNumber = i;
+ ap_set_module_config(r->request_config, &tile_module, rdata);
+ return OK;
+ }
+
+ char parameters[XMLCONFIG_MAX];
+
+ if (tile_config->enableOptions) {
+ cmd->ver = PROTO_VER;
+ n = sscanf(r->uri + strlen(tile_config->baseuri), "%40[^/]/%d/%d/%d.%255[a-z]/%10s", parameters, &(cmd->z), &(cmd->x), &(cmd->y), extension, option);
+
+ if (n < 5) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid URL for tilelayer %s with options", tile_config->xmlname);
+ return DECLINED;
+ }
+ } else {
+ cmd->ver = 2;
+ n = sscanf(r->uri + strlen(tile_config->baseuri), "%d/%d/%d.%255[a-z]/%10s", &(cmd->z), &(cmd->x), &(cmd->y), extension, option);
+
+ if (n < 4) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid URL for tilelayer %s without options", tile_config->xmlname);
+ return DECLINED;
+ }
+
+ parameters[0] = 0;
+ }
+
+ if (strcmp(extension, tile_config->fileExtension) != 0) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid file extension (%s) for tilelayer %s, required %s",
+ extension, tile_config->xmlname, tile_config->fileExtension);
+ return DECLINED;
+ }
+
+ oob = (cmd->z < tile_config->minzoom || cmd->z > tile_config->maxzoom);
+
+ if (!oob) {
+ // valid x/y for tiles are 0 ... 2^zoom-1
+ limit = (1 << cmd->z);
+ oob = (cmd->x < 0 || cmd->x > (limit * tile_config->aspect_x - 1) || cmd->y < 0 || cmd->y > (limit * tile_config->aspect_y - 1));
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: request for %s was %i %i %i", tile_config->xmlname, cmd->x, cmd->y, limit);
+ }
+
+ if (oob) {
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: request for %s was outside of allowed bounds", tile_config->xmlname);
+ sleep(CLIENT_PENALTY);
+ // Don't increase stats counter here,
+ // As we are interested in valid tiles only
+ return HTTP_NOT_FOUND;
+ }
+
+ strcpy(cmd->xmlname, tile_config->xmlname);
+ strcpy(cmd->mimetype, tile_config->mimeType);
+ strcpy(cmd->options, parameters);
+
+ // Store a copy for later
+ rdata->cmd = cmd;
+ rdata->layerNumber = i;
+ rdata->store = get_storage_backend(r, i);
+
+ if (rdata->store == NULL || rdata->store->storage_ctx == NULL) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "tile_translate: failed to get valid storage backend/storage backend context");
+
+ if (!incRespCounter(HTTP_INTERNAL_SERVER_ERROR, r, cmd, rdata->layerNumber)) {
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "Failed to increase response stats counter");
+ }
+
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ ap_set_module_config(r->request_config, &tile_module, rdata);
+
+ r->filename = NULL;
+
+ if ((tile_config->enableOptions && (n == 6)) || (!tile_config->enableOptions && (n == 5))) {
+ if (!strcmp(option, "status")) {
+ r->handler = "tile_status";
+ } else if (!strcmp(option, "dirty")) {
+ r->handler = "tile_dirty";
+ } else {
+ return DECLINED;
+ }
+ } else {
+ r->handler = "tile_serve";
+ }
+
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: op(%s) xml(%s) mime(%s) z(%d) x(%d) y(%d)",
+ r->handler, cmd->xmlname, tile_config->mimeType, cmd->z, cmd->x, cmd->y);
+
+ return OK;
+ }
+ }
+
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: No suitable tile layer found");
+ return DECLINED;
+}
+
+static int tile_handler_dirty(request_rec *r)
+{
+ tile_server_conf *scfg;
+ struct tile_request_data *rdata;
+ struct protocol *cmd;
+
+ if (strcmp(r->handler, "tile_dirty")) {
+ return DECLINED;
+ }
+
+ rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module);
+ cmd = rdata->cmd;
+
+ if (cmd == NULL) {
+ return DECLINED;
+ }
+
+ scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
+
+ // Is /dirty URL enabled?
+ if (!scfg->enable_dirty_url) {
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "tile_handler_dirty: /dirty URL is not enabled");
+ return HTTP_NOT_FOUND;
+ }
+
+ if (scfg->enable_bulk_mode) {
+ return OK;
+ }
+
+ request_tile(r, cmd, 0);
+ return error_message(r, "Tile submitted for rendering\n");
+}
+
static int tile_handler_status(request_rec *r)
{
- ap_conf_vector_t *sconf;
tile_server_conf *scfg;
enum tileState state;
char mtime_str[APR_CTIME_LEN];
char atime_str[APR_CTIME_LEN];
char storage_id[PATH_MAX];
- struct tile_request_data * rdata;
- struct protocol * cmd;
+ struct tile_request_data *rdata;
+ struct protocol *cmd;
if (strcmp(r->handler, "tile_status")) {
return DECLINED;
}
- sconf = r->server->module_config;
- scfg = ap_get_module_config(sconf, &tile_module);
+ scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
// Is /status URL enabled?
- if (!scfg->enableStatusUrl) {
+ if (!scfg->enable_status_url) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "tile_handler_status: /status URL is not enabled");
return HTTP_NOT_FOUND;
}
@@ -1164,8 +1277,7 @@ static int tile_handler_json(request_rec *r)
apr_table_t *t = r->headers_out;
int i;
char *md5;
- struct tile_request_data * rdata;
- ap_conf_vector_t *sconf;
+ struct tile_request_data *rdata;
tile_server_conf *scfg;
tile_config_rec *tile_configs;
tile_config_rec *tile_config;
@@ -1177,9 +1289,8 @@ static int tile_handler_json(request_rec *r)
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Handling tile json request\n");
rdata = (struct tile_request_data *)ap_get_module_config(r->request_config, &tile_module);
- sconf = r->server->module_config;
- scfg = ap_get_module_config(sconf, &tile_module);
- tile_configs = (tile_config_rec *) scfg->configs->elts;
+ scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
+ tile_configs = (tile_config_rec *)scfg->configs->elts;
tile_config = &tile_configs[rdata->layerNumber];
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Handling tile json request for layer %s\n", tile_config->xmlname);
@@ -1191,7 +1302,7 @@ static int tile_handler_json(request_rec *r)
}
}
- buf = malloc(8 * 1024);
+ buf = (char *)malloc(8 * 1024);
snprintf(buf, 8 * 1024,
"{\n"
@@ -1233,7 +1344,7 @@ static int tile_handler_json(request_rec *r)
ap_set_content_length(r, len);
apr_table_mergen(t, "Cache-Control",
apr_psprintf(r->pool, "max-age=%li", maxAge));
- timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
+ timestr = (char *)apr_palloc(r->pool, APR_RFC822_DATE_LEN);
apr_rfc822_date(timestr, (apr_time_from_sec(maxAge) + r->request_time));
apr_table_setn(t, "Expires", timestr);
ap_rwrite(buf, len, r);
@@ -1244,10 +1355,9 @@ static int tile_handler_json(request_rec *r)
static int tile_handler_mod_stats(request_rec *r)
{
- stats_data * stats;
+ stats_data *stats;
stats_data local_stats;
int i;
- ap_conf_vector_t *sconf;
tile_server_conf *scfg;
tile_config_rec *tile_configs;
@@ -1255,23 +1365,22 @@ static int tile_handler_mod_stats(request_rec *r)
return DECLINED;
}
- sconf = r->server->module_config;
- scfg = ap_get_module_config(sconf, &tile_module);
- tile_configs = (tile_config_rec *) scfg->configs->elts;
+ scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
+ tile_configs = (tile_config_rec *)scfg->configs->elts;
- if (!scfg->enableGlobalStats) {
+ if (!scfg->enable_global_stats) {
return error_message(r, "Stats are not enabled for this server");
}
if (get_global_lock(r, stats_mutex) != 0) {
- //Copy over the global counter variable into
- //local variables, that we can immediately
- //release the lock again
- stats = (stats_data *) apr_shm_baseaddr_get(stats_shm);
+ // Copy over the global counter variable into
+ // local variables, that we can immediately
+ // release the lock again
+ stats = (stats_data *)apr_shm_baseaddr_get(stats_shm);
memcpy(&local_stats, stats, sizeof(stats_data));
- local_stats.noResp200Layer = malloc(sizeof(apr_uint64_t) * scfg->configs->nelts);
+ local_stats.noResp200Layer = (apr_uint64_t *)malloc(sizeof(apr_uint64_t) * scfg->configs->nelts);
memcpy(local_stats.noResp200Layer, stats->noResp200Layer, sizeof(apr_uint64_t) * scfg->configs->nelts);
- local_stats.noResp404Layer = malloc(sizeof(apr_uint64_t) * scfg->configs->nelts);
+ local_stats.noResp404Layer = (apr_uint64_t *)malloc(sizeof(apr_uint64_t) * scfg->configs->nelts);
memcpy(local_stats.noResp404Layer, stats->noResp404Layer, sizeof(apr_uint64_t) * scfg->configs->nelts);
apr_global_mutex_unlock(stats_mutex);
} else {
@@ -1316,10 +1425,9 @@ static int tile_handler_mod_stats(request_rec *r)
static int tile_handler_metrics(request_rec *r)
{
- stats_data * stats;
+ stats_data *stats;
stats_data local_stats;
int i;
- ap_conf_vector_t *sconf;
tile_server_conf *scfg;
tile_config_rec *tile_configs;
@@ -1327,23 +1435,22 @@ static int tile_handler_metrics(request_rec *r)
return DECLINED;
}
- sconf = r->server->module_config;
- scfg = ap_get_module_config(sconf, &tile_module);
- tile_configs = (tile_config_rec *) scfg->configs->elts;
+ scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
+ tile_configs = (tile_config_rec *)scfg->configs->elts;
- if (!scfg->enableGlobalStats) {
+ if (!scfg->enable_global_stats) {
return error_message(r, "Stats are not enabled for this server");
}
if (get_global_lock(r, stats_mutex) != 0) {
- //Copy over the global counter variable into
- //local variables, that we can immediately
- //release the lock again
- stats = (stats_data *) apr_shm_baseaddr_get(stats_shm);
+ // Copy over the global counter variable into
+ // local variables, that we can immediately
+ // release the lock again
+ stats = (stats_data *)apr_shm_baseaddr_get(stats_shm);
memcpy(&local_stats, stats, sizeof(stats_data));
- local_stats.noResp200Layer = malloc(sizeof(apr_uint64_t) * scfg->configs->nelts);
+ local_stats.noResp200Layer = (apr_uint64_t *)malloc(sizeof(apr_uint64_t) * scfg->configs->nelts);
memcpy(local_stats.noResp200Layer, stats->noResp200Layer, sizeof(apr_uint64_t) * scfg->configs->nelts);
- local_stats.noResp404Layer = malloc(sizeof(apr_uint64_t) * scfg->configs->nelts);
+ local_stats.noResp404Layer = (apr_uint64_t *)malloc(sizeof(apr_uint64_t) * scfg->configs->nelts);
memcpy(local_stats.noResp404Layer, stats->noResp404Layer, sizeof(apr_uint64_t) * scfg->configs->nelts);
apr_global_mutex_unlock(stats_mutex);
} else {
@@ -1375,7 +1482,6 @@ static int tile_handler_metrics(request_rec *r)
ap_rprintf(r, "modtile_zoom_responses_total{zoom=\"%02i\"} %" APR_UINT64_T_FMT "\n", i, local_stats.noRespZoom[i]);
}
-
ap_rprintf(r, "# HELP modtile_tile_reads_total Tiles served from the tile buffer\n");
ap_rprintf(r, "# TYPE modtile_tile_reads_total counter\n");
@@ -1416,11 +1522,10 @@ static int tile_handler_serve(request_rec *r)
struct timeval start, end;
char *md5;
tile_config_rec *tile_configs;
- struct tile_request_data * rdata;
- struct protocol * cmd;
+ struct tile_request_data *rdata;
+ struct protocol *cmd;
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(r->server->module_config, &tile_module);
if (strcmp(r->handler, "tile_serve")) {
return DECLINED;
@@ -1442,7 +1547,7 @@ static int tile_handler_serve(request_rec *r)
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_handler_serve: xml(%s) z(%d) x(%d) y(%d)", cmd->xmlname, cmd->z, cmd->x, cmd->y);
- tile_configs = (tile_config_rec *) scfg->configs->elts;
+ tile_configs = (tile_config_rec *)scfg->configs->elts;
if (tile_configs[rdata->layerNumber].cors) {
int resp = add_cors(r, tile_configs[rdata->layerNumber].cors);
@@ -1455,7 +1560,7 @@ static int tile_handler_serve(request_rec *r)
gettimeofday(&start, NULL);
// FIXME: It is a waste to do the malloc + read if we are fulfilling a HEAD or returning a 304.
- buf = malloc(tile_max);
+ buf = (char *)malloc(tile_max);
if (!buf) {
if (!incRespCounter(HTTP_INTERNAL_SERVER_ERROR, r, cmd, rdata->layerNumber)) {
@@ -1474,14 +1579,14 @@ static int tile_handler_serve(request_rec *r)
if (len > 0) {
if (compressed) {
- const char* accept_encoding = apr_table_get(r->headers_in, "Accept-Encoding");
+ const char *accept_encoding = apr_table_get(r->headers_in, "Accept-Encoding");
if (accept_encoding && strstr(accept_encoding, "gzip")) {
r->content_encoding = "gzip";
} else {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
"Tile data is compressed, but user agent doesn't support Content-Encoding and we don't know how to decompress it server side");
- //TODO: decompress the output stream before sending it to client
+ // TODO: decompress the output stream before sending it to client
}
}
@@ -1538,158 +1643,10 @@ static int tile_handler_serve(request_rec *r)
return DECLINED;
}
-static int tile_translate(request_rec *r)
-{
- int i, n, limit, oob;
- char option[11];
- char extension[256];
-
- ap_conf_vector_t *sconf = r->server->module_config;
- tile_server_conf *scfg = ap_get_module_config(sconf, &tile_module);
-
- tile_config_rec *tile_configs = (tile_config_rec *) scfg->configs->elts;
-
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: uri(%s)", r->uri);
-
- /*
- * The page /mod_tile returns global stats about the number of tiles
- * handled and in what state those tiles were.
- * This should probably not be hard coded
- */
- if (!strncmp("/mod_tile", r->uri, strlen("/mod_tile"))) {
- r->handler = "tile_mod_stats";
- ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
- "tile_translate: retrieving global mod_tile stats");
- return OK;
- }
-
- /*
- * The page /metrics returns global stats in Prometheus format.
- */
- if (!strncmp("/metrics", r->uri, strlen("/metrics"))) {
- r->handler = "tile_metrics";
- ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
- "tile_translate: retrieving global mod_tile metrics");
- return OK;
- }
-
- for (i = 0; i < scfg->configs->nelts; ++i) {
- tile_config_rec *tile_config = &tile_configs[i];
-
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: testing baseuri(%s) name(%s) extension(%s)",
- tile_config->baseuri, tile_config->xmlname, tile_config->fileExtension);
-
-
- if (!strncmp(tile_config->baseuri, r->uri, strlen(tile_config->baseuri))) {
-
- struct tile_request_data * rdata = (struct tile_request_data *) apr_pcalloc(r->pool, sizeof(struct tile_request_data));
- struct protocol * cmd = (struct protocol *) apr_pcalloc(r->pool, sizeof(struct protocol));
- bzero(cmd, sizeof(struct protocol));
- bzero(rdata, sizeof(struct tile_request_data));
-
- if (!strncmp(r->uri + strlen(tile_config->baseuri), "tile-layer.json", strlen("tile-layer.json"))) {
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Requesting tileJSON for tilelayer %s", tile_config->xmlname);
- r->handler = "tile_json";
- rdata->layerNumber = i;
- ap_set_module_config(r->request_config, &tile_module, rdata);
- return OK;
- }
-
- char parameters[XMLCONFIG_MAX];
-
- if (tile_config->enableOptions) {
- cmd->ver = PROTO_VER;
- n = sscanf(r->uri + strlen(tile_config->baseuri), "%40[^/]/%d/%d/%d.%255[a-z]/%10s", parameters, &(cmd->z), &(cmd->x), &(cmd->y), extension, option);
-
- if (n < 5) {
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid URL for tilelayer %s with options", tile_config->xmlname);
- return DECLINED;
- }
- } else {
- cmd->ver = 2;
- n = sscanf(r->uri + strlen(tile_config->baseuri), "%d/%d/%d.%255[a-z]/%10s", &(cmd->z), &(cmd->x), &(cmd->y), extension, option);
-
- if (n < 4) {
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid URL for tilelayer %s without options", tile_config->xmlname);
- return DECLINED;
- }
-
- parameters[0] = 0;
- }
-
- if (strcmp(extension, tile_config->fileExtension) != 0) {
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: Invalid file extension (%s) for tilelayer %s, required %s",
- extension, tile_config->xmlname, tile_config->fileExtension);
- return DECLINED;
- }
-
- oob = (cmd->z < tile_config->minzoom || cmd->z > tile_config->maxzoom);
-
- if (!oob) {
- // valid x/y for tiles are 0 ... 2^zoom-1
- limit = (1 << cmd->z);
- oob = (cmd->x < 0 || cmd->x > (limit * tile_config->aspect_x - 1) || cmd->y < 0 || cmd->y > (limit * tile_config->aspect_y - 1));
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: request for %s was %i %i %i", tile_config->xmlname, cmd->x, cmd->y, limit);
- }
-
- if (oob) {
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: request for %s was outside of allowed bounds", tile_config->xmlname);
- sleep(CLIENT_PENALTY);
- //Don't increase stats counter here,
- //As we are interested in valid tiles only
- return HTTP_NOT_FOUND;
- }
-
- strcpy(cmd->xmlname, tile_config->xmlname);
- strcpy(cmd->mimetype, tile_config->mimeType);
- strcpy(cmd->options, parameters);
-
- // Store a copy for later
- rdata->cmd = cmd;
- rdata->layerNumber = i;
- rdata->store = get_storage_backend(r, i);
-
- if (rdata->store == NULL || rdata->store->storage_ctx == NULL) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "tile_translate: failed to get valid storage backend/storage backend context");
-
- if (!incRespCounter(HTTP_INTERNAL_SERVER_ERROR, r, cmd, rdata->layerNumber)) {
- ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "Failed to increase response stats counter");
- }
-
- return HTTP_INTERNAL_SERVER_ERROR;
- }
-
- ap_set_module_config(r->request_config, &tile_module, rdata);
-
- r->filename = NULL;
-
- if ((tile_config->enableOptions && (n == 6)) || (!tile_config->enableOptions && (n == 5))) {
- if (!strcmp(option, "status")) {
- r->handler = "tile_status";
- } else if (!strcmp(option, "dirty")) {
- r->handler = "tile_dirty";
- } else {
- return DECLINED;
- }
- } else {
- r->handler = "tile_serve";
- }
-
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: op(%s) xml(%s) mime(%s) z(%d) x(%d) y(%d)",
- r->handler, cmd->xmlname, tile_config->mimeType, cmd->z, cmd->x, cmd->y);
-
- return OK;
- }
- }
-
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "tile_translate: No suitable tile layer found");
- return DECLINED;
-}
-
-/*
- * This routine is called in the parent, so we'll set up the shared
- * memory segment and mutex here.
- */
+/*
+ * This routine is called in the parent, so we'll set up the shared
+ * memory segment and mutex here.
+ */
static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
@@ -1711,7 +1668,7 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_userdata_get(&data, userdata_key, s->process->pool);
if (!data) {
- apr_pool_userdata_set((const void *) 1, userdata_key,
+ apr_pool_userdata_set((const void *)1, userdata_key,
apr_pool_cleanup_null, s->process->pool);
return OK;
} /* Kilroy was here */
@@ -1731,7 +1688,7 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
* not seem to be set at this stage, so rely on previously set layerCount */
rs = apr_shm_create(&stats_shm, sizeof(stats_data) + layerCount * 2 * sizeof(apr_uint64_t),
- (const char *) shmfilename, pconf);
+ (const char *)shmfilename, pconf);
if (rs != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rs, s,
@@ -1741,7 +1698,7 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
}
rs = apr_shm_create(&delaypool_shm, sizeof(delaypool),
- (const char *) shmfilename_delaypool, pconf);
+ (const char *)shmfilename_delaypool, pconf);
if (rs != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rs, s,
@@ -1780,8 +1737,8 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
* followed by two arrays with one element each per layer. All of this sits
* in one shared memory block, and for ease of use, pointers from inside the
* struct point to the arrays. */
- stats->noResp404Layer = (apr_uint64_t *)((char *) stats + sizeof(stats_data));
- stats->noResp200Layer = (apr_uint64_t *)((char *) stats + sizeof(stats_data) + sizeof(apr_uint64_t) * layerCount);
+ stats->noResp404Layer = (apr_uint64_t *)((char *)stats + sizeof(stats_data));
+ stats->noResp200Layer = (apr_uint64_t *)((char *)stats + sizeof(stats_data) + sizeof(apr_uint64_t) * layerCount);
/* zero out all the non-fixed-length stuff */
for (i = 0; i < layerCount; i++) {
@@ -1806,7 +1763,6 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
/* TODO: need a way to initialise the delaypool whitelist */
-
/* Create global mutex */
/*
@@ -1815,9 +1771,9 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
* may or may not be actually created.
*/
mutexfilename = apr_psprintf(pconf, "/tmp/httpd_mutex.%ld",
- (long int) getpid());
+ (long int)getpid());
- rs = apr_global_mutex_create(&stats_mutex, (const char *) mutexfilename,
+ rs = apr_global_mutex_create(&stats_mutex, (const char *)mutexfilename,
APR_LOCK_DEFAULT, pconf);
if (rs != APR_SUCCESS) {
@@ -1845,9 +1801,9 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
* may or may not be actually created.
*/
mutexfilename = apr_psprintf(pconf, "/tmp/httpd_mutex_delay.%ld",
- (long int) getpid());
+ (long int)getpid());
- rs = apr_global_mutex_create(&delay_mutex, (const char *) mutexfilename,
+ rs = apr_global_mutex_create(&delay_mutex, (const char *)mutexfilename,
APR_LOCK_DEFAULT, pconf);
if (rs != APR_SUCCESS) {
@@ -1872,7 +1828,6 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
return OK;
}
-
/*
* This routine gets called when a child inits. We use it to attach
* to the shared memory segment, and reinitialize the mutex and setup
@@ -1891,7 +1846,7 @@ static void mod_tile_child_init(apr_pool_t *p, server_rec *s)
* the mutex pointer global here.
*/
rs = apr_global_mutex_child_init(&stats_mutex,
- (const char *) mutexfilename,
+ (const char *)mutexfilename,
p);
if (rs != APR_SUCCESS) {
@@ -1918,100 +1873,101 @@ static void register_hooks(__attribute__((unused)) apr_pool_t *p)
ap_hook_map_to_storage(tile_storage_hook, NULL, NULL, APR_HOOK_FIRST);
}
-static const char *_add_tile_config(cmd_parms *cmd, void *mconfig,
+static const char *_add_tile_config(cmd_parms *cmd,
const char *baseuri, const char *name, int minzoom, int maxzoom, int aspect_x, int aspect_y,
- const char * fileExtension, const char *mimeType, const char *description, const char * attribution,
- int noHostnames, char ** hostnames, const char * cors, const char * tile_dir, const int parameterize)
+ const char *fileExtension, const char *mimeType, const char *description, const char *attribution,
+ const char *server_alias, const char *cors, const char *tile_dir, const int enableOptions)
{
- int i;
- int urilen;
tile_server_conf *scfg;
tile_config_rec *tilecfg;
- if (strlen(name) == 0) {
- return "ConfigName value must not be null";
- }
-
- if (hostnames == NULL) {
- hostnames = malloc(sizeof(char *));
- /* FIXME: wouldn't be allocationg 7+len+1 bytes be enough? */
- hostnames[0] = malloc(PATH_MAX);
- strncpy(hostnames[0], "http://", PATH_MAX);
+ scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ tilecfg = (tile_config_rec *)apr_array_push(scfg->configs);
- if (cmd->server->server_hostname == NULL) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, APR_SUCCESS, cmd->server,
- "Could not determine host name of server to configure tile-json request. Using localhost instead");
+ int attribution_len = strnlen(attribution, PATH_MAX);
+ int baseuri_len = strnlen(baseuri, PATH_MAX);
+ int hostnames_len = 1;
+ int server_alias_len = strnlen(server_alias, PATH_MAX);
+ int tile_dir_len = strnlen(tile_dir, PATH_MAX);
- strncat(hostnames[0], "localhost", PATH_MAX - 10);
- } else {
- strncat(hostnames[0], cmd->server->server_hostname, PATH_MAX - strlen(hostnames[0]) - 1);
- }
-
- noHostnames = 1;
+ // Set attribution to default
+ if (attribution_len == 0) {
+ attribution = apr_pstrdup(cmd->pool, DEFAULT_ATTRIBUTION);
}
- if (attribution == NULL) {
- attribution = strdup(DEFAULT_ATTRIBUTION);
+ // Ensure URI string ends with a trailing slash
+ if (baseuri_len == 0) {
+ baseuri = apr_pstrdup(cmd->pool, "/");
+ } else if (baseuri[baseuri_len - 1] != '/') {
+ baseuri = apr_psprintf(cmd->pool, "%s/", baseuri);
}
- if ((minzoom < 0) || (maxzoom > MAX_ZOOM_SERVER)) {
- for (i = 0; i < noHostnames; i++) {
- free(hostnames[i]);
- }
-
- free(hostnames);
- hostnames = NULL;
- return "The configured zoom level lies outside of the range supported by this server";
+ // If server_alias is set, increment hostnames_len
+ if (server_alias_len > 0) {
+ hostnames_len++;
}
- if (maxzoom > global_max_zoom) {
- global_max_zoom = maxzoom;
+ // Set tile_dir to default
+ if (tile_dir_len == 0) {
+ tile_dir = apr_pstrndup(cmd->pool, scfg->tile_dir, PATH_MAX);
}
+ char **hostnames = (char **)malloc(sizeof(char *) * hostnames_len);
- scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- tilecfg = apr_array_push(scfg->configs);
-
- if (tile_dir == NULL) {
- tile_dir = strdup(scfg->tile_dir);
+ // Set first hostname to server_hostname value (if set,) otherwise use localhost
+ if (cmd->server->server_hostname == NULL) {
+ hostnames[0] = apr_pstrdup(cmd->pool, "http://localhost");
+ ap_log_perror(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, cmd->pool,
+ "Could not determine hostname of server to configure TileJSON request output for '%s', using '%s'.", name, hostnames[0]);
+ } else {
+ hostnames[0] = apr_pstrcat(cmd->pool, "http://", cmd->server->server_hostname, NULL);
}
- // Ensure URI string ends with a trailing slash
- urilen = strlen(baseuri);
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool,
+ "Using server hostname '%s' to configure TileJSON request output for '%s'.", hostnames[0], name);
- if (urilen == 0) {
- snprintf(tilecfg->baseuri, PATH_MAX, "/");
- } else if (baseuri[urilen - 1] != '/') {
- snprintf(tilecfg->baseuri, PATH_MAX, "%s/", baseuri);
- } else {
- snprintf(tilecfg->baseuri, PATH_MAX, "%s", baseuri);
+ // Set second hostname to server_alias value (if set)
+ if (server_alias_len > 0) {
+ // Ensure second hostname string does not end with a trailing slash
+ if (server_alias[server_alias_len - 1] == '/') {
+ hostnames[1] = apr_pstrndup(cmd->pool, server_alias, server_alias_len - 1);
+ } else {
+ hostnames[1] = apr_pstrdup(cmd->pool, server_alias);
+ }
+
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool,
+ "Also using server hostname '%s' to configure TileJSON request output for '%s'.", hostnames[1], name);
}
- strncpy(tilecfg->xmlname, name, XMLCONFIG_MAX - 1);
- strncpy(tilecfg->fileExtension, fileExtension, XMLCONFIG_MAX - 1);
- strncpy(tilecfg->mimeType, mimeType, XMLCONFIG_MAX - 1);
- tilecfg->xmlname[XMLCONFIG_MAX - 1] = 0;
- tilecfg->minzoom = minzoom;
- tilecfg->maxzoom = maxzoom;
tilecfg->aspect_x = aspect_x;
tilecfg->aspect_y = aspect_y;
- tilecfg->description = description;
tilecfg->attribution = attribution;
- tilecfg->noHostnames = noHostnames;
- tilecfg->hostnames = hostnames;
+ tilecfg->baseuri = baseuri;
tilecfg->cors = cors;
+ tilecfg->description = description;
+ tilecfg->enableOptions = enableOptions;
+ tilecfg->fileExtension = fileExtension;
+ tilecfg->hostnames = hostnames;
+ tilecfg->maxzoom = maxzoom;
+ tilecfg->mimeType = mimeType;
+ tilecfg->minzoom = minzoom;
+ tilecfg->noHostnames = hostnames_len;
tilecfg->store = tile_dir;
- tilecfg->enableOptions = parameterize;
+ tilecfg->xmlname = name;
+
+ if (maxzoom > global_max_zoom) {
+ global_max_zoom = maxzoom;
+ }
ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, cmd->server,
"Loading tile config %s at %s for zooms %i - %i from tile directory %s with extension .%s and mime type %s",
- name, baseuri, minzoom, maxzoom, tile_dir, fileExtension, mimeType);
+ tilecfg->xmlname, tilecfg->baseuri, tilecfg->minzoom, tilecfg->maxzoom, tilecfg->store, tilecfg->fileExtension, tilecfg->mimeType);
layerCount++;
return NULL;
}
-static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name, const char * fileExtension)
+static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name, const char *fileExtension)
{
char *cors = NULL;
char *mimeType = "image/png";
@@ -2024,7 +1980,7 @@ static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const cha
ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, cmd->server,
"AddTileMimeConfig will be deprecated in a future release, please use the following instead: AddTileConfig %s %s mimetype=%s extension=%s",
baseuri, name, mimeType, fileExtension);
- return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, mimeType, NULL, NULL, 0, NULL, cors, NULL, 0);
+ return _add_tile_config(cmd, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, mimeType, "", "", "", cors, "", 0);
}
static const char *add_tile_config(cmd_parms *cmd, void *mconfig, int argc, char *const argv[])
@@ -2043,11 +1999,9 @@ static const char *add_tile_config(cmd_parms *cmd, void *mconfig, int argc, char
char *name = argv[1];
char *fileExtension = "png";
char *mimeType = "image/png";
- char *tile_dir = RENDERD_TILE_DIR;
-
- int i;
+ char *tile_dir = "";
- for (i = 2; i < argc; i++) {
+ for (int i = 2; i < argc; i++) {
char *value = strchr(argv[i], '=');
if (value) {
@@ -2067,732 +2021,390 @@ static const char *add_tile_config(cmd_parms *cmd, void *mconfig, int argc, char
}
}
- return _add_tile_config(cmd, mconfig, baseuri, name, minzoom, maxzoom, 1, 1, fileExtension, mimeType, NULL, NULL, 0, NULL, NULL, tile_dir, 0);
+ if ((minzoom < 0) || (maxzoom > MAX_ZOOM_SERVER)) {
+ return "AddTileConfig error, the configured zoom level lies outside of the range supported by this server";
+ }
+
+ return _add_tile_config(cmd, baseuri, name, minzoom, maxzoom, 1, 1, fileExtension, mimeType, "", "", "", "", tile_dir, 0);
}
-static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *conffile)
+static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *config_file_name)
{
- FILE * hini ;
- char filename[PATH_MAX];
- char url[PATH_MAX];
- char xmlname[XMLCONFIG_MAX];
- char line[INILINE_MAX];
- char key[INILINE_MAX];
- char value[INILINE_MAX];
- const char * result;
- char fileExtension[INILINE_MAX];
- char mimeType[INILINE_MAX];
- char outputFormat[INILINE_MAX];
- char * description = NULL;
- char * attribution = NULL;
- char * cors = NULL;
- char * tile_dir = NULL;
- char **hostnames = NULL;
- char **hostnames_tmp;
- int noHostnames = 0;
- int tilelayer = 0;
- int minzoom = 0;
- int maxzoom = MAX_ZOOM;
- int aspect_x = 1;
- int aspect_y = 1;
- int parameterize = 0;
-
- if (strlen(conffile) == 0) {
- strcpy(filename, RENDERD_CONFIG);
- } else {
- strcpy(filename, conffile);
- }
+ struct stat buffer;
- // Load the config
- if ((hini = fopen(filename, "r")) == NULL) {
+ if (stat(config_file_name, &buffer) != 0) {
return "LoadTileConfigFile error, unable to open config file";
}
- while (fgets(line, INILINE_MAX, hini) != NULL) {
- if (line[0] == '#') {
- continue;
- }
-
- if (line[0] == ';') {
- continue;
- }
-
- if (line[strlen(line) - 1] == '\n') {
- line[strlen(line) - 1] = 0;
- }
-
- if (line[0] == '[') {
- /*Add the previous section to the configuration */
- if (tilelayer == 1) {
- result = _add_tile_config(cmd, mconfig, url, xmlname, minzoom, maxzoom, aspect_x, aspect_y, fileExtension, mimeType,
- description, attribution, noHostnames, hostnames, cors, tile_dir, parameterize);
-
- if (result != NULL) {
- fclose(hini);
- return result;
- }
- }
-
- if (strlen(line) >= XMLCONFIG_MAX) {
- if (description) {
- free(description);
- description = NULL;
- }
-
- if (attribution) {
- free(attribution);
- attribution = NULL;
- }
-
- if (hostnames) {
- free(hostnames);
- hostnames = NULL;
- }
-
- if (cors) {
- free(cors);
- cors = NULL;
- }
-
- fclose(hini);
- return "XML name too long";
- }
-
- if (sscanf(line, "[%[^]]", xmlname) != 1) {
- if (description) {
- free(description);
- description = NULL;
- }
-
- if (attribution) {
- free(attribution);
- attribution = NULL;
- }
-
- if (hostnames) {
- free(hostnames);
- hostnames = NULL;
- }
-
- if (cors) {
- free(cors);
- cors = NULL;
- }
-
- fclose(hini);
- return "Malformed config file";
- }
-
- if ((strcmp(xmlname, "mapnik") == 0) || (strstr(xmlname, "renderd") == xmlname)) {
- /* These aren't tile layers but configuration sections for renderd */
- tilelayer = 0;
- } else {
- tilelayer = 1;
- }
-
- /* Initialise default values for tile layer */
- strcpy(url, "");
- strcpy(fileExtension, "png");
- strcpy(mimeType, "image/png");
- strcpy(outputFormat, "png256");
- description = NULL;
- cors = NULL;
- attribution = NULL;
- tile_dir = NULL;
- hostnames = NULL;
- noHostnames = 0;
- minzoom = 0;
- maxzoom = MAX_ZOOM;
- aspect_x = 1;
- aspect_y = 1;
- parameterize = 0;
- } else if (sscanf(line, "%[^=]=%[^;#]", key, value) == 2
- || sscanf(line, "%[^=]=\"%[^\"]\"", key, value) == 2) {
-
- if (!strcmp(key, "URI")) {
- if (strlen(value) >= PATH_MAX) {
- if (description) {
- free(description);
- description = NULL;
- }
-
- if (attribution) {
- free(attribution);
- attribution = NULL;
- }
-
- if (hostnames) {
- free(hostnames);
- hostnames = NULL;
- }
-
- if (cors) {
- free(cors);
- cors = NULL;
- }
-
- if (tile_dir) {
- free(tile_dir);
- tile_dir = NULL;
- }
-
- fclose(hini);
- return "URI too long";
- }
-
- strcpy(url, value);
- }
-
- if (!strcmp(key, "TYPE")) {
- if (strlen(value) >= PATH_MAX) {
- if (description) {
- free(description);
- description = NULL;
- }
-
- if (attribution) {
- free(attribution);
- attribution = NULL;
- }
-
- if (hostnames) {
- free(hostnames);
- hostnames = NULL;
- }
-
- if (cors) {
- free(cors);
- cors = NULL;
- }
-
- if (tile_dir) {
- free(tile_dir);
- tile_dir = NULL;
- }
-
- fclose(hini);
- return "TYPE too long";
- }
-
- if (sscanf(value, "%[^ ] %[^ ] %[^;#]", fileExtension, mimeType, outputFormat) < 2) {
- if (description) {
- free(description);
- description = NULL;
- }
-
- if (attribution) {
- free(attribution);
- attribution = NULL;
- }
+ const char *result;
- if (hostnames) {
- free(hostnames);
- hostnames = NULL;
- }
+ xmlconfigitem maps[XMLCONFIGS_MAX];
- if (cors) {
- free(cors);
- cors = NULL;
- }
+ process_map_sections(config_file_name, maps, "", 0);
- if (tile_dir) {
- free(tile_dir);
- tile_dir = NULL;
- }
-
- fclose(hini);
- return "TYPE is not correctly parsable";
- }
- }
-
- if (!strcmp(key, "DESCRIPTION")) {
- if (description) {
- free(description);
- }
-
- description = malloc(sizeof(char) * (strlen(value) + 1));
- strcpy(description, value);
- }
-
- if (!strcmp(key, "ATTRIBUTION")) {
- if (attribution) {
- free(attribution);
- }
+ for (int i = 0; i < XMLCONFIGS_MAX; i++) {
+ if (maps[i].xmlname != NULL) {
+ result = _add_tile_config(cmd,
+ maps[i].xmluri, maps[i].xmlname, maps[i].min_zoom, maps[i].max_zoom, maps[i].aspect_x, maps[i].aspect_y,
+ maps[i].file_extension, maps[i].mime_type, maps[i].description, maps[i].attribution,
+ maps[i].server_alias, maps[i].cors, maps[i].tile_dir, strlen(maps[i].parameterization));
- attribution = malloc(sizeof(char) * (strlen(value) + 1));
- strcpy(attribution, value);
+ if (result != NULL) {
+ return result;
}
-
- if (!strcmp(key, "CORS")) {
- if (cors) {
- free(cors);
- }
-
- cors = malloc(sizeof(char) * (strlen(value) + 1));
- strcpy(cors, value);
- }
-
- if (!strcmp(key, "SERVER_ALIAS")) {
- if (hostnames == NULL) {
- noHostnames = 1;
- hostnames = malloc((noHostnames + 1) * sizeof(char *));
- } else {
- hostnames_tmp = hostnames;
- hostnames = malloc((noHostnames + 1) * sizeof(char *));
- memcpy(hostnames, hostnames_tmp, sizeof(char *) * noHostnames);
- free(hostnames_tmp);
- noHostnames++;
- }
-
- hostnames[noHostnames - 1] = malloc(sizeof(char) * (strlen(value) + 1));
- strcpy(hostnames[noHostnames - 1], value);
- }
-
- if (!strcmp(key, "TILEDIR")) {
- if (tile_dir) {
- free(tile_dir);
- }
-
- tile_dir = strdup(value);
- }
-
- if (!strcmp(key, "MINZOOM")) {
- minzoom = atoi(value);
- }
-
- if (!strcmp(key, "MAXZOOM")) {
- maxzoom = atoi(value);
- }
-
- if (!strcmp(key, "ASPECTX")) {
- aspect_x = atoi(value);
- }
-
- if (!strcmp(key, "ASPECTY")) {
- aspect_y = atoi(value);
- }
-
- if (!strcmp(key, "PARAMETERIZE_STYLE")) {
- parameterize = 1;
- }
- }
- }
-
- if (tilelayer == 1) {
- //ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->server,
- // "Committing tile config %s", xmlname);
- result = _add_tile_config(cmd, mconfig, url, xmlname, minzoom, maxzoom, aspect_x, aspect_y, fileExtension, mimeType,
- description, attribution, noHostnames, hostnames, cors, tile_dir, parameterize);
-
- if (result != NULL) {
- fclose(hini);
- return result;
}
}
- fclose(hini);
return NULL;
}
-static const char *mod_tile_request_timeout_config(cmd_parms *cmd, void *mconfig, const char *request_timeout_string)
+static const char *arg_to_apr_int64_t(cmd_parms *cmd, const char *buf, apr_int64_t *dest, const char *config_directive_name)
{
- int request_timeout;
- tile_server_conf *scfg;
+ char *end;
+ apr_int64_t arg = apr_strtoi64(buf, &end, 10);
- if (sscanf(request_timeout_string, "%d", &request_timeout) != 1) {
- return "ModTileRequestTimeout needs integer argument";
+ if (end == buf) {
+ return apr_pstrcat(cmd->pool, config_directive_name, " argument must be an integer", NULL);
}
- scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->request_timeout = request_timeout;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %" APR_INT64_T_FMT, config_directive_name, arg);
+ *dest = arg;
return NULL;
}
-static const char *mod_tile_request_timeout_missing_config(cmd_parms *cmd, void *mconfig, const char *request_timeout_string)
+static const char *arg_to_double(cmd_parms *cmd, const char *buf, double *dest, const char *config_directive_name)
{
- int request_timeout;
- tile_server_conf *scfg;
+ char *end;
+ double arg = strtod(buf, &end);
- if (sscanf(request_timeout_string, "%d", &request_timeout) != 1) {
- return "ModTileMissingRequestTimeout needs integer argument";
+ if (end == buf) {
+ return apr_pstrcat(cmd->pool, config_directive_name, " argument must be a float", NULL);
}
- scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->request_timeout_priority = request_timeout;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %f", config_directive_name, arg);
+ *dest = arg;
return NULL;
}
-static const char *mod_tile_max_load_old_config(cmd_parms *cmd, void *mconfig, const char *max_load_old_string)
+static const char *arg_to_int(cmd_parms *cmd, const char *buf, int *dest, const char *config_directive_name)
{
- int max_load_old;
- tile_server_conf *scfg;
+ char *end;
+ int arg = (int)apr_strtoi64(buf, &end, 10);
- if (sscanf(max_load_old_string, "%d", &max_load_old) != 1) {
- return "ModTileMaxLoadOld needs integer argument";
+ if (end == buf) {
+ return apr_pstrcat(cmd->pool, config_directive_name, " argument must be an integer", NULL);
}
- scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->max_load_old = max_load_old;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %i", config_directive_name, arg);
+ *dest = arg;
return NULL;
}
-static const char *mod_tile_max_load_missing_config(cmd_parms *cmd, void *mconfig, const char *max_load_missing_string)
+static const char *arg_to_string(cmd_parms *cmd, const char *buf, const char **dest, const char *config_directive_name)
{
- int max_load_missing;
- tile_server_conf *scfg;
+ *dest = apr_pstrndup(cmd->pool, buf, PATH_MAX);
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %s", config_directive_name, *dest);
+ return NULL;
+}
- if (sscanf(max_load_missing_string, "%d", &max_load_missing) != 1) {
- return "ModTileMaxLoadMissing needs integer argument";
- }
+static const char *mod_tile_request_timeout_config(cmd_parms *cmd, void *mconfig, const char *request_timeout_string)
+{
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_int(cmd, request_timeout_string, &scfg->request_timeout, cmd->directive->directive);
+}
- scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->max_load_missing = max_load_missing;
- return NULL;
+static const char *mod_tile_request_timeout_priority_config(cmd_parms *cmd, void *mconfig, const char *request_timeout_priority_string)
+{
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_int(cmd, request_timeout_priority_string, &scfg->request_timeout_priority, cmd->directive->directive);
}
-static const char *mod_tile_veryold_threshold_config(cmd_parms *cmd, void *mconfig, const char *veryold_threshold_string)
+static const char *mod_tile_max_load_old_config(cmd_parms *cmd, void *mconfig, const char *max_load_old_string)
{
- apr_time_t veryold_threshold;
- tile_server_conf *scfg;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_int(cmd, max_load_old_string, &scfg->max_load_old, cmd->directive->directive);
+}
- if (sscanf(veryold_threshold_string, "%" SCNd64, &veryold_threshold) != 1) {
- return "ModTileVeryOldThreshold needs integer argument";
- }
+static const char *mod_tile_max_load_missing_config(cmd_parms *cmd, void *mconfig, const char *max_load_missing_string)
+{
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_int(cmd, max_load_missing_string, &scfg->max_load_missing, cmd->directive->directive);
+}
- scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->veryold_threshold = veryold_threshold;
- return NULL;
+static const char *mod_tile_very_old_threshold_config(cmd_parms *cmd, void *mconfig, const char *very_old_threshold_string)
+{
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_apr_int64_t(cmd, very_old_threshold_string, &scfg->very_old_threshold, cmd->directive->directive);
}
static const char *mod_tile_renderd_socket_name_config(cmd_parms *cmd, void *mconfig, const char *renderd_socket_name_string)
{
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- strncpy(scfg->renderd_socket_name, renderd_socket_name_string, PATH_MAX - 1);
- scfg->renderd_socket_name[PATH_MAX - 1] = 0;
- return NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_string(cmd, renderd_socket_name_string, &scfg->renderd_socket_name, cmd->directive->directive);
}
-static const char *mod_tile_renderd_socket_addr_config(cmd_parms *cmd, void *mconfig, const char *renderd_socket_address_string, const char *renderd_socket_port_string)
+static const char *mod_tile_renderd_socket_address_config(cmd_parms *cmd, void *mconfig, const char *renderd_socket_address_string, const char *renderd_socket_port_string)
{
- int port;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- strncpy(scfg->renderd_socket_name, renderd_socket_address_string, PATH_MAX - 1);
+ const char *renderd_socket_address_result;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ renderd_socket_address_result = arg_to_string(cmd, renderd_socket_address_string, &scfg->renderd_socket_name, "ModTileRenderdSocketAddr first");
- if (sscanf(renderd_socket_port_string, "%d", &port) != 1) {
- return "ModTileRenderdSocketAddr TCP port needs to be an integer argument";
+ if (renderd_socket_address_result != NULL) {
+ return renderd_socket_address_result;
}
- scfg->renderd_socket_port = port;
- scfg->renderd_socket_name[PATH_MAX - 1] = 0;
- return NULL;
+ return arg_to_int(cmd, renderd_socket_port_string, &scfg->renderd_socket_port, "ModTileRenderdSocketAddr second");
}
static const char *mod_tile_tile_dir_config(cmd_parms *cmd, void *mconfig, const char *tile_dir_string)
{
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- strncpy(scfg->tile_dir, tile_dir_string, PATH_MAX - 1);
- scfg->tile_dir[PATH_MAX - 1] = 0;
- return NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_string(cmd, tile_dir_string, &scfg->tile_dir, cmd->directive->directive);
}
-static const char *mod_tile_cache_extended_host_name_config(cmd_parms *cmd, void *mconfig, const char *cache_extended_hostname)
+static const char *mod_tile_cache_extended_hostname_config(cmd_parms *cmd, void *mconfig, const char *cache_extended_hostname_string)
{
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- strncpy(scfg->cache_extended_hostname, cache_extended_hostname, PATH_MAX - 1);
- scfg->cache_extended_hostname[PATH_MAX - 1] = 0;
-
- return NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_string(cmd, cache_extended_hostname_string, &scfg->cache_extended_hostname, cmd->directive->directive);
}
-static const char *mod_tile_cache_extended_duration_config(cmd_parms *cmd, void *mconfig, const char *cache_duration_string)
+static const char *mod_tile_cache_extended_duration_config(cmd_parms *cmd, void *mconfig, const char *cache_extended_duration_string)
{
- int cache_duration;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
-
- if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) {
- return "ModTileCacheExtendedDuration needs integer argument";
- }
-
- scfg->cache_extended_duration = cache_duration;
-
- return NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_int(cmd, cache_extended_duration_string, &scfg->cache_extended_duration, cmd->directive->directive);
}
-static const char *mod_tile_cache_lastmod_factor_config(cmd_parms *cmd, void *mconfig, const char *modified_factor_string)
+static const char *mod_tile_cache_duration_last_modified_factor_config(cmd_parms *cmd, void *mconfig, const char *cache_duration_last_modified_factor_string)
{
- float modified_factor;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config,
- &tile_module);
-
- if (sscanf(modified_factor_string, "%f", &modified_factor) != 1) {
- return "ModTileCacheLastModifiedFactor needs float argument";
- }
-
- scfg->cache_duration_last_modified_factor = modified_factor;
- return NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_double(cmd, cache_duration_last_modified_factor_string, &scfg->cache_duration_last_modified_factor, cmd->directive->directive);
}
-static const char *mod_tile_cache_duration_max_config(cmd_parms *cmd, void *mconfig, const char *cache_duration_string)
+static const char *mod_tile_cache_duration_max_config(cmd_parms *cmd, void *mconfig, const char *cache_duration_max_string)
{
- int cache_duration;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config,
- &tile_module);
-
- if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) {
- return "ModTileCacheDurationMax needs integer argument";
- }
-
- scfg->cache_duration_max = cache_duration;
- return NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_int(cmd, cache_duration_max_string, &scfg->cache_duration_max, cmd->directive->directive);
}
-static const char *mod_tile_cache_duration_dirty_config(cmd_parms *cmd, void *mconfig, const char *cache_duration_string)
+static const char *mod_tile_cache_duration_dirty_config(cmd_parms *cmd, void *mconfig, const char *cache_duration_dirty_string)
{
- int cache_duration;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config,
- &tile_module);
-
- if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) {
- return "ModTileCacheDurationDirty needs integer argument";
- }
-
- scfg->cache_duration_dirty = cache_duration;
- return NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_int(cmd, cache_duration_dirty_string, &scfg->cache_duration_dirty, cmd->directive->directive);
}
-static const char *mod_tile_cache_duration_minimum_config(cmd_parms *cmd, void *mconfig, const char *cache_duration_string)
+static const char *mod_tile_cache_duration_minimum_config(cmd_parms *cmd, void *mconfig, const char *cache_duration_minimum_string)
{
- int cache_duration;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config,
- &tile_module);
-
- if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) {
- return "ModTileCacheDurationMinimum needs integer argument";
- }
-
- scfg->cache_duration_minimum = cache_duration;
- return NULL;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ return arg_to_int(cmd, cache_duration_minimum_string, &scfg->cache_duration_minimum, cmd->directive->directive);
}
-static const char *mod_tile_cache_duration_low_config(cmd_parms *cmd, void *mconfig, const char *zoom_level_string, const char *cache_duration_string)
+static const char *mod_tile_cache_duration_low_config(cmd_parms *cmd, void *mconfig, const char *cache_level_low_zoom_string, const char *cache_duration_low_zoom_string)
{
- int zoom_level;
- int cache_duration;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
-
- if (sscanf(zoom_level_string, "%d", &zoom_level) != 1) {
- return "ModTileCacheDurationLowZoom needs integer argument";
- }
+ const char *cache_level_low_zoom_result;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ cache_level_low_zoom_result = arg_to_int(cmd, cache_level_low_zoom_string, &scfg->cache_level_low_zoom, "ModTileCacheDurationLowZoom first");
- if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) {
- return "ModTileCacheDurationLowZoom needs integer argument";
+ if (cache_level_low_zoom_result != NULL) {
+ return cache_level_low_zoom_result;
}
- scfg->cache_level_low_zoom = zoom_level;
- scfg->cache_duration_low_zoom = cache_duration;
-
- return NULL;
+ return arg_to_int(cmd, cache_duration_low_zoom_string, &scfg->cache_duration_low_zoom, "ModTileCacheDurationLowZoom second");
}
-static const char *mod_tile_cache_duration_medium_config(cmd_parms *cmd, void *mconfig, const char *zoom_level_string, const char *cache_duration_string)
-{
- int zoom_level;
- int cache_duration;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- if (sscanf(zoom_level_string, "%d", &zoom_level) != 1) {
- return "ModTileCacheDurationMediumZoom needs integer argument";
- }
+static const char *mod_tile_cache_duration_medium_config(cmd_parms *cmd, void *mconfig, const char *cache_level_medium_zoom_string, const char *cache_duration_medium_zoom_string)
+{
+ const char *cache_level_medium_zoom_result;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ cache_level_medium_zoom_result = arg_to_int(cmd, cache_level_medium_zoom_string, &scfg->cache_level_medium_zoom, "ModTileCacheDurationMediumZoom first");
- if (sscanf(cache_duration_string, "%d", &cache_duration) != 1) {
- return "ModTileCacheDurationMediumZoom needs integer argument";
+ if (cache_level_medium_zoom_result != NULL) {
+ return cache_level_medium_zoom_result;
}
- scfg->cache_level_medium_zoom = zoom_level;
- scfg->cache_duration_medium_zoom = cache_duration;
-
- return NULL;
+ return arg_to_int(cmd, cache_duration_medium_zoom_string, &scfg->cache_duration_medium_zoom, "ModTileCacheDurationMediumZoom second");
}
-static const char *mod_tile_enable_stats(cmd_parms *cmd, void *mconfig, int enableStats)
+static const char *mod_tile_enable_stats(cmd_parms *cmd, void *mconfig, int enable_global_stats)
{
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->enableGlobalStats = enableStats;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %s", cmd->directive->directive, enable_global_stats ? "On" : "Off");
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ scfg->enable_global_stats = enable_global_stats;
return NULL;
}
-static const char *mod_tile_enable_throttling(cmd_parms *cmd, void *mconfig, int enableThrottling)
+static const char *mod_tile_enable_throttling(cmd_parms *cmd, void *mconfig, int enable_tile_throttling)
{
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->enableTileThrottling = enableThrottling;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %s", cmd->directive->directive, enable_tile_throttling ? "On" : "Off");
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ scfg->enable_tile_throttling = enable_tile_throttling;
return NULL;
}
-static const char *mod_tile_enable_throttling_xforward(cmd_parms *cmd, void *mconfig, const char * enableThrottlingXForward)
+static const char *mod_tile_enable_throttling_xforward(cmd_parms *cmd, void *mconfig, const char *enable_tile_throttling_xforward_string)
{
- int throttle_xforward;
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %s", cmd->directive->directive, enable_tile_throttling_xforward_string);
+ const char *enable_tile_throttling_xforward_result;
+ int enable_tile_throttling_xforward;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ enable_tile_throttling_xforward_result = arg_to_int(cmd, enable_tile_throttling_xforward_string, &enable_tile_throttling_xforward, cmd->directive->directive);
- if (sscanf(enableThrottlingXForward, "%d", &throttle_xforward) != 1) {
- return "ModTileEnableTileThrottlingXForward needs integer argument between 0 and 2";
+ if (enable_tile_throttling_xforward_result != NULL) {
+ return enable_tile_throttling_xforward_result;
}
- if ((throttle_xforward < 0) || (throttle_xforward > 2)) {
+ if ((enable_tile_throttling_xforward < 0) || (enable_tile_throttling_xforward > 2)) {
return "ModTileEnableTileThrottlingXForward needs integer argument between 0 and 2 (0 => off; 1 => use client; 2 => use last entry in chain";
}
- scfg->enableTileThrottlingXForward = throttle_xforward;
+ scfg->enable_tile_throttling_xforward = enable_tile_throttling_xforward;
return NULL;
}
-static const char *mod_tile_bulk_mode(cmd_parms *cmd, void *mconfig, int bulkMode)
+static const char *mod_tile_enable_bulk_mode(cmd_parms *cmd, void *mconfig, int enable_bulk_mode)
{
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->bulkMode = bulkMode;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %s", cmd->directive->directive, enable_bulk_mode ? "On" : "Off");
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ scfg->enable_bulk_mode = enable_bulk_mode;
return NULL;
}
-static const char *mod_tile_enable_status_url(cmd_parms *cmd, void *mconfig, int enableStatusUrl)
+static const char *mod_tile_enable_status_url(cmd_parms *cmd, void *mconfig, int enable_status_url)
{
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->enableStatusUrl = enableStatusUrl;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %s", cmd->directive->directive, enable_status_url ? "On" : "Off");
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ scfg->enable_status_url = enable_status_url;
return NULL;
}
-static const char *mod_tile_enable_dirty_url(cmd_parms *cmd, void *mconfig, int enableDirtyUrl)
+static const char *mod_tile_enable_dirty_url(cmd_parms *cmd, void *mconfig, int enable_dirty_url)
{
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
- scfg->enableDirtyUrl = enableDirtyUrl;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, cmd->pool, "Setting %s argument to %s", cmd->directive->directive, enable_dirty_url ? "On" : "Off");
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ scfg->enable_dirty_url = enable_dirty_url;
return NULL;
}
-static const char *mod_tile_delaypool_tiles_config(cmd_parms *cmd, void *mconfig, const char *bucketsize_string, const char *topuprate_string)
+static const char *mod_tile_delaypool_tiles_config(cmd_parms *cmd, void *mconfig, const char *delaypool_tile_size_string, const char *top_up_tile_rate_string)
{
- int bucketsize;
- float topuprate;
-
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
+ const char *delaypool_tile_size_result, *top_up_tile_rate_result;
+ double top_up_tile_rate;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ delaypool_tile_size_result = arg_to_int(cmd, delaypool_tile_size_string, &scfg->delaypool_tile_size, "ModTileThrottlingTiles first");
- if (sscanf(bucketsize_string, "%d", &bucketsize) != 1) {
- return "ModTileThrottlingTiles needs two numerical arguments, the first one must be integer";
+ if (delaypool_tile_size_result != NULL) {
+ return delaypool_tile_size_result;
}
- if (sscanf(topuprate_string, "%f", &topuprate) != 1) {
- return "ModTileThrottlingTiles needs two numerical arguments, the first one must be integer";
- }
+ top_up_tile_rate_result = arg_to_double(cmd, top_up_tile_rate_string, &top_up_tile_rate, "ModTileThrottlingTiles second");
- scfg->delaypoolTileSize = bucketsize;
+ if (top_up_tile_rate_result != NULL) {
+ return top_up_tile_rate_result;
+ }
/*Convert topup rate into microseconds per tile */
- scfg->delaypoolTileRate = (long)(1000000.0 / topuprate);
-
+ scfg->delaypool_tile_rate = (APR_USEC_PER_SEC / top_up_tile_rate);
return NULL;
}
-static const char *mod_tile_delaypool_render_config(cmd_parms *cmd, void *mconfig, const char *bucketsize_string, const char *topuprate_string)
+static const char *mod_tile_delaypool_render_config(cmd_parms *cmd, void *mconfig, const char *delaypool_render_size_string, const char *top_up_render_rate_string)
{
- int bucketsize;
- float topuprate;
-
- tile_server_conf *scfg = ap_get_module_config(cmd->server->module_config, &tile_module);
+ const char *delaypool_render_size_result, *top_up_render_rate_result;
+ double top_up_render_rate;
+ tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(cmd->server->module_config, &tile_module);
+ delaypool_render_size_result = arg_to_int(cmd, delaypool_render_size_string, &scfg->delaypool_render_size, "ModTileThrottlingRenders first");
- if (sscanf(bucketsize_string, "%d", &bucketsize) != 1) {
- return "ModTileThrottlingRenders needs two numerical arguments, the first one must be integer";
+ if (delaypool_render_size_result != NULL) {
+ return delaypool_render_size_result;
}
- if (sscanf(topuprate_string, "%f", &topuprate) != 1) {
- return "ModTileThrottlingRenders needs two numerical arguments, the first one must be integer";
- }
+ top_up_render_rate_result = arg_to_double(cmd, top_up_render_rate_string, &top_up_render_rate, "ModTileThrottlingRenders second");
- scfg->delaypoolRenderSize = bucketsize;
+ if (top_up_render_rate_result != NULL) {
+ return top_up_render_rate_result;
+ }
/*Convert topup rate into microseconds per tile */
- scfg->delaypoolRenderRate = (long)(1000000.0 / topuprate);
-
+ scfg->delaypool_render_rate = (APR_USEC_PER_SEC / top_up_render_rate);
return NULL;
}
static void *create_tile_config(apr_pool_t *p, server_rec *s)
{
- tile_server_conf * scfg = (tile_server_conf *) apr_pcalloc(p, sizeof(tile_server_conf));
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, p, "Running create_tile_config");
+ tile_server_conf *scfg = (tile_server_conf *)apr_pcalloc(p, sizeof(tile_server_conf));
- scfg->configs = apr_array_make(p, 4, sizeof(tile_config_rec));
- scfg->request_timeout = REQUEST_TIMEOUT;
- scfg->request_timeout_priority = REQUEST_TIMEOUT;
- scfg->max_load_old = MAX_LOAD_OLD;
- scfg->max_load_missing = MAX_LOAD_MISSING;
- scfg->veryold_threshold = VERYOLD_THRESHOLD;
- strncpy(scfg->renderd_socket_name, RENDERD_SOCKET, PATH_MAX - 1);
- scfg->renderd_socket_name[PATH_MAX - 1] = 0;
- scfg->renderd_socket_port = 0;
- strncpy(scfg->tile_dir, RENDERD_TILE_DIR, PATH_MAX - 1);
- scfg->tile_dir[PATH_MAX - 1] = 0;
- memset(&(scfg->cache_extended_hostname), 0, PATH_MAX);
- scfg->cache_extended_duration = 0;
scfg->cache_duration_dirty = 15 * 60;
scfg->cache_duration_last_modified_factor = 0.0;
- scfg->cache_duration_max = 7 * 24 * 60 * 60;
- scfg->cache_duration_minimum = 3 * 60 * 60;
scfg->cache_duration_low_zoom = 6 * 24 * 60 * 60;
+ scfg->cache_duration_max = 7 * 24 * 60 * 60;
scfg->cache_duration_medium_zoom = 1 * 24 * 60 * 60;
+ scfg->cache_duration_minimum = 3 * 60 * 60;
+ scfg->cache_extended_duration = 0;
+ scfg->cache_extended_hostname = "";
scfg->cache_level_low_zoom = 0;
scfg->cache_level_medium_zoom = 0;
- scfg->enableGlobalStats = 1;
- scfg->enableTileThrottling = 0;
- scfg->enableTileThrottlingXForward = 0;
- scfg->delaypoolTileSize = AVAILABLE_TILE_BUCKET_SIZE;
- scfg->delaypoolTileRate = RENDER_TOPUP_RATE;
- scfg->delaypoolRenderSize = AVAILABLE_RENDER_BUCKET_SIZE;
- scfg->delaypoolRenderRate = RENDER_TOPUP_RATE;
- scfg->bulkMode = 0;
- scfg->enableStatusUrl = 1;
- scfg->enableDirtyUrl = 1;
-
+ scfg->configs = apr_array_make(p, 4, sizeof(tile_config_rec));
+ scfg->delaypool_render_rate = RENDER_TOPUP_RATE;
+ scfg->delaypool_render_size = AVAILABLE_RENDER_BUCKET_SIZE;
+ scfg->delaypool_tile_rate = RENDER_TOPUP_RATE;
+ scfg->delaypool_tile_size = AVAILABLE_TILE_BUCKET_SIZE;
+ scfg->enable_bulk_mode = 0;
+ scfg->enable_dirty_url = 1;
+ scfg->enable_global_stats = 1;
+ scfg->enable_status_url = 1;
+ scfg->enable_tile_throttling = 0;
+ scfg->enable_tile_throttling_xforward = 0;
+ scfg->max_load_missing = MAX_LOAD_MISSING;
+ scfg->max_load_old = MAX_LOAD_OLD;
+ scfg->renderd_socket_name = apr_pstrndup(p, RENDERD_SOCKET, PATH_MAX);
+ scfg->renderd_socket_port = 0;
+ scfg->request_timeout = REQUEST_TIMEOUT;
+ scfg->request_timeout_priority = REQUEST_TIMEOUT;
+ scfg->tile_dir = apr_pstrndup(p, RENDERD_TILE_DIR, PATH_MAX);
+ scfg->very_old_threshold = VERYOLD_THRESHOLD;
return scfg;
}
static void *merge_tile_config(apr_pool_t *p, void *basev, void *overridesv)
{
- int i;
- tile_server_conf * scfg = (tile_server_conf *) apr_pcalloc(p, sizeof(tile_server_conf));
- tile_server_conf * scfg_base = (tile_server_conf *) basev;
- tile_server_conf * scfg_over = (tile_server_conf *) overridesv;
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, p, "Running merge_tile_config");
+ tile_server_conf *scfg = (tile_server_conf *)apr_pcalloc(p, sizeof(tile_server_conf));
+ tile_server_conf *scfg_base = (tile_server_conf *)basev;
+ tile_server_conf *scfg_over = (tile_server_conf *)overridesv;
- scfg->configs = apr_array_append(p, scfg_base->configs, scfg_over->configs);
- scfg->request_timeout = scfg_over->request_timeout;
- scfg->request_timeout_priority = scfg_over->request_timeout_priority;
- scfg->max_load_old = scfg_over->max_load_old;
- scfg->max_load_missing = scfg_over->max_load_missing;
- scfg->veryold_threshold = scfg_over->veryold_threshold;
- strncpy(scfg->renderd_socket_name, scfg_over->renderd_socket_name, PATH_MAX - 1);
- scfg->renderd_socket_name[PATH_MAX - 1] = 0;
- scfg->renderd_socket_port = scfg_over->renderd_socket_port;
- strncpy(scfg->tile_dir, scfg_over->tile_dir, PATH_MAX - 1);
- scfg->tile_dir[PATH_MAX - 1] = 0;
- strncpy(scfg->cache_extended_hostname, scfg_over->cache_extended_hostname, PATH_MAX - 1);
- scfg->cache_extended_hostname[PATH_MAX - 1] = 0;
- scfg->cache_extended_duration = scfg_over->cache_extended_duration;
scfg->cache_duration_dirty = scfg_over->cache_duration_dirty;
scfg->cache_duration_last_modified_factor = scfg_over->cache_duration_last_modified_factor;
- scfg->cache_duration_max = scfg_over->cache_duration_max;
- scfg->cache_duration_minimum = scfg_over->cache_duration_minimum;
scfg->cache_duration_low_zoom = scfg_over->cache_duration_low_zoom;
+ scfg->cache_duration_max = scfg_over->cache_duration_max;
scfg->cache_duration_medium_zoom = scfg_over->cache_duration_medium_zoom;
+ scfg->cache_duration_minimum = scfg_over->cache_duration_minimum;
+ scfg->cache_extended_duration = scfg_over->cache_extended_duration;
+ scfg->cache_extended_hostname = apr_pstrndup(p, scfg_over->cache_extended_hostname, PATH_MAX);
scfg->cache_level_low_zoom = scfg_over->cache_level_low_zoom;
scfg->cache_level_medium_zoom = scfg_over->cache_level_medium_zoom;
- scfg->enableGlobalStats = scfg_over->enableGlobalStats;
- scfg->enableTileThrottling = scfg_over->enableTileThrottling;
- scfg->enableTileThrottlingXForward = scfg_over->enableTileThrottlingXForward;
- scfg->delaypoolTileSize = scfg_over->delaypoolTileSize;
- scfg->delaypoolTileRate = scfg_over->delaypoolTileRate;
- scfg->delaypoolRenderSize = scfg_over->delaypoolRenderSize;
- scfg->delaypoolRenderRate = scfg_over->delaypoolRenderRate;
- scfg->bulkMode = scfg_over->bulkMode;
- scfg->enableStatusUrl = scfg_over->enableStatusUrl;
- scfg->enableDirtyUrl = scfg_over->enableDirtyUrl;
-
- //Construct a table of minimum cache times per zoom level
- for (i = 0; i <= MAX_ZOOM_SERVER; i++) {
+ scfg->configs = apr_array_append(p, scfg_base->configs, scfg_over->configs);
+ scfg->delaypool_render_rate = scfg_over->delaypool_render_rate;
+ scfg->delaypool_render_size = scfg_over->delaypool_render_size;
+ scfg->delaypool_tile_rate = scfg_over->delaypool_tile_rate;
+ scfg->delaypool_tile_size = scfg_over->delaypool_tile_size;
+ scfg->enable_bulk_mode = scfg_over->enable_bulk_mode;
+ scfg->enable_dirty_url = scfg_over->enable_dirty_url;
+ scfg->enable_global_stats = scfg_over->enable_global_stats;
+ scfg->enable_status_url = scfg_over->enable_status_url;
+ scfg->enable_tile_throttling = scfg_over->enable_tile_throttling;
+ scfg->enable_tile_throttling_xforward = scfg_over->enable_tile_throttling_xforward;
+ scfg->max_load_missing = scfg_over->max_load_missing;
+ scfg->max_load_old = scfg_over->max_load_old;
+ scfg->renderd_socket_name = apr_pstrndup(p, scfg_over->renderd_socket_name, PATH_MAX);
+ scfg->renderd_socket_port = scfg_over->renderd_socket_port;
+ scfg->request_timeout = scfg_over->request_timeout;
+ scfg->request_timeout_priority = scfg_over->request_timeout_priority;
+ scfg->tile_dir = apr_pstrndup(p, scfg_over->tile_dir, PATH_MAX);
+ scfg->very_old_threshold = scfg_over->very_old_threshold;
+
+ // Construct a table of minimum cache times per zoom level
+ for (int i = 0; i <= MAX_ZOOM_SERVER; i++) {
if (i <= scfg->cache_level_low_zoom) {
scfg->mincachetime[i] = scfg->cache_duration_low_zoom;
} else if (i <= scfg->cache_level_medium_zoom) {
@@ -2806,204 +2418,42 @@ static void *merge_tile_config(apr_pool_t *p, void *basev, void *overridesv)
}
static const command_rec tile_cmds[] = {
- AP_INIT_TAKE1(
- "LoadTileConfigFile", /* directive name */
- load_tile_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "load an entire renderd config file" /* directive description */
- ),
- AP_INIT_TAKE_ARGV(
- "AddTileConfig", /* directive name */
- add_tile_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "path, name of renderd config and optional key-value pairs to use" /* directive description */
- ),
- AP_INIT_TAKE3(
- "AddTileMimeConfig", /* directive name */
- add_tile_mime_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "path, name of renderd config and file extension to use" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileRequestTimeout", /* directive name */
- mod_tile_request_timeout_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set timeout in seconds on mod_tile requests" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileMissingRequestTimeout", /* directive name */
- mod_tile_request_timeout_missing_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set timeout in seconds on missing mod_tile requests" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileMaxLoadOld", /* directive name */
- mod_tile_max_load_old_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set max load for rendering old tiles" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileMaxLoadMissing", /* directive name */
- mod_tile_max_load_missing_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set max load for rendering missing tiles" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileVeryOldThreshold", /* directive name */
- mod_tile_veryold_threshold_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "set the time threshold from when an outdated tile ist considered very old and rendered with slightly higher priority." /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileRenderdSocketName", /* directive name */
- mod_tile_renderd_socket_name_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set name of unix domain socket for connecting to rendering daemon" /* directive description */
- ),
- AP_INIT_TAKE2(
- "ModTileRenderdSocketAddr", /* directive name */
- mod_tile_renderd_socket_addr_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set address and port of the TCP socket for connecting to rendering daemon" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileTileDir", /* directive name */
- mod_tile_tile_dir_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set name of tile cache directory" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileCacheExtendedHostName", /* directive name */
- mod_tile_cache_extended_host_name_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "set hostname for extended period caching" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileCacheExtendedDuration", /* directive name */
- mod_tile_cache_extended_duration_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "set length of extended period caching" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileCacheDurationMax", /* directive name */
- mod_tile_cache_duration_max_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set the maximum cache expiry in seconds" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileCacheDurationDirty", /* directive name */
- mod_tile_cache_duration_dirty_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set the cache expiry for serving dirty tiles" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileCacheDurationMinimum", /* directive name */
- mod_tile_cache_duration_minimum_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set the minimum cache expiry" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileCacheLastModifiedFactor", /* directive name */
- mod_tile_cache_lastmod_factor_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set the factor by which the last modified determines cache expiry" /* directive description */
- ),
- AP_INIT_TAKE2(
- "ModTileCacheDurationLowZoom", /* directive name */
- mod_tile_cache_duration_low_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set the minimum cache duration and zoom level for low zoom tiles" /* directive description */
- ),
- AP_INIT_TAKE2(
- "ModTileCacheDurationMediumZoom", /* directive name */
- mod_tile_cache_duration_medium_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set the minimum cache duration and zoom level for medium zoom tiles" /* directive description */
- ),
- AP_INIT_FLAG(
- "ModTileEnableStats", /* directive name */
- mod_tile_enable_stats, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "On Off - enable of keeping stats about what mod_tile is serving" /* directive description */
- ),
- AP_INIT_FLAG(
- "ModTileEnableTileThrottling", /* directive name */
- mod_tile_enable_throttling, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "On Off - enable of throttling of IPs that excessively download tiles such as scrapers" /* directive description */
- ),
- AP_INIT_TAKE1(
- "ModTileEnableTileThrottlingXForward", /* directive name */
- mod_tile_enable_throttling_xforward, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "0 1 2 - use X-Forwarded-For http header to determin IP for throttling when available. 0 => off, 1 => use first entry, 2 => use last entry of the caching chain" /* directive description */
- ),
- AP_INIT_TAKE2(
- "ModTileThrottlingTiles", /* directive name */
- mod_tile_delaypool_tiles_config, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set the initial bucket size (number of tiles) and top up rate (tiles per second) for throttling tile request per IP" /* directive description */
- ),
- AP_INIT_TAKE2(
- "ModTileThrottlingRenders", /* directive name */
- mod_tile_delaypool_render_config,/* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "Set the initial bucket size (number of tiles) and top up rate (tiles per second) for throttling tile request per IP" /* directive description */
- ),
- AP_INIT_FLAG(
- "ModTileBulkMode", /* directive name */
- mod_tile_bulk_mode, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "On Off - make all requests to renderd with bulk render priority, never mark tiles dirty" /* directive description */
- ),
- AP_INIT_FLAG(
- "ModTileEnableStatusURL", /* directive name */
- mod_tile_enable_status_url, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "On Off - whether to handle .../status urls " /* directive description */
- ),
- AP_INIT_FLAG(
- "ModTileEnableDirtyURL", /* directive name */
- mod_tile_enable_dirty_url, /* config action routine */
- NULL, /* argument to include in call */
- OR_OPTIONS, /* where available */
- "On Off - whether to handle .../dirty urls " /* directive description */
- ),
+ AP_INIT_FLAG("ModTileBulkMode", mod_tile_enable_bulk_mode, NULL, OR_OPTIONS, "On Off - make all requests to renderd with bulk render priority, never mark tiles dirty"),
+ AP_INIT_FLAG("ModTileEnableDirtyURL", mod_tile_enable_dirty_url, NULL, OR_OPTIONS, "On Off - whether to handle .../dirty urls "),
+ AP_INIT_FLAG("ModTileEnableStats", mod_tile_enable_stats, NULL, OR_OPTIONS, "On Off - enable of keeping stats about what mod_tile is serving"),
+ AP_INIT_FLAG("ModTileEnableStatusURL", mod_tile_enable_status_url, NULL, OR_OPTIONS, "On Off - whether to handle .../status urls "),
+ AP_INIT_FLAG("ModTileEnableTileThrottling", mod_tile_enable_throttling, NULL, OR_OPTIONS, "On Off - enable of throttling of IPs that excessively download tiles such as scrapers"),
+ AP_INIT_TAKE1("LoadTileConfigFile", load_tile_config, NULL, OR_OPTIONS, "load an entire renderd config file"),
+ AP_INIT_TAKE1("ModTileCacheDurationDirty", mod_tile_cache_duration_dirty_config, NULL, OR_OPTIONS, "Set the cache expiry for serving dirty tiles"),
+ AP_INIT_TAKE1("ModTileCacheDurationMax", mod_tile_cache_duration_max_config, NULL, OR_OPTIONS, "Set the maximum cache expiry in seconds"),
+ AP_INIT_TAKE1("ModTileCacheDurationMinimum", mod_tile_cache_duration_minimum_config, NULL, OR_OPTIONS, "Set the minimum cache expiry"),
+ AP_INIT_TAKE1("ModTileCacheExtendedDuration", mod_tile_cache_extended_duration_config, NULL, OR_OPTIONS, "set length of extended period caching"),
+ AP_INIT_TAKE1("ModTileCacheExtendedHostName", mod_tile_cache_extended_hostname_config, NULL, OR_OPTIONS, "set hostname for extended period caching"),
+ AP_INIT_TAKE1("ModTileCacheLastModifiedFactor", mod_tile_cache_duration_last_modified_factor_config, NULL, OR_OPTIONS, "Set the factor by which the last modified determines cache expiry"),
+ AP_INIT_TAKE1("ModTileEnableTileThrottlingXForward", mod_tile_enable_throttling_xforward, NULL, OR_OPTIONS, "0 1 2 - use X-Forwarded-For http header to determin IP for throttling when available. 0 => off, 1 => use first entry, 2 => use last entry of the caching chain"),
+ AP_INIT_TAKE1("ModTileMaxLoadMissing", mod_tile_max_load_missing_config, NULL, OR_OPTIONS, "Set max load for rendering missing tiles"),
+ AP_INIT_TAKE1("ModTileMaxLoadOld", mod_tile_max_load_old_config, NULL, OR_OPTIONS, "Set max load for rendering old tiles"),
+ AP_INIT_TAKE1("ModTileMissingRequestTimeout", mod_tile_request_timeout_priority_config, NULL, OR_OPTIONS, "Set timeout in seconds on missing mod_tile requests"),
+ AP_INIT_TAKE1("ModTileRenderdSocketName", mod_tile_renderd_socket_name_config, NULL, OR_OPTIONS, "Set name of unix domain socket for connecting to rendering daemon"),
+ AP_INIT_TAKE1("ModTileRequestTimeout", mod_tile_request_timeout_config, NULL, OR_OPTIONS, "Set timeout in seconds on mod_tile requests"),
+ AP_INIT_TAKE1("ModTileTileDir", mod_tile_tile_dir_config, NULL, OR_OPTIONS, "Set name of tile cache directory"),
+ AP_INIT_TAKE1("ModTileVeryOldThreshold", mod_tile_very_old_threshold_config, NULL, OR_OPTIONS, "set the time threshold from when an outdated tile ist considered very old and rendered with slightly higher priority."),
+ AP_INIT_TAKE2("ModTileCacheDurationLowZoom", mod_tile_cache_duration_low_config, NULL, OR_OPTIONS, "Set the minimum cache duration and zoom level for low zoom tiles"),
+ AP_INIT_TAKE2("ModTileCacheDurationMediumZoom", mod_tile_cache_duration_medium_config, NULL, OR_OPTIONS, "Set the minimum cache duration and zoom level for medium zoom tiles"),
+ AP_INIT_TAKE2("ModTileRenderdSocketAddr", mod_tile_renderd_socket_address_config, NULL, OR_OPTIONS, "Set address and port of the TCP socket for connecting to rendering daemon"),
+ AP_INIT_TAKE2("ModTileThrottlingRenders", mod_tile_delaypool_render_config, NULL, OR_OPTIONS, "Set the initial bucket size (number of tiles) and top up rate (tiles per second) for throttling tile request per IP"),
+ AP_INIT_TAKE2("ModTileThrottlingTiles", mod_tile_delaypool_tiles_config, NULL, OR_OPTIONS, "Set the initial bucket size (number of tiles) and top up rate (tiles per second) for throttling tile request per IP"),
+ AP_INIT_TAKE3("AddTileMimeConfig", add_tile_mime_config, NULL, OR_OPTIONS, "path, name of renderd config and file extension to use"),
+ AP_INIT_TAKE_ARGV("AddTileConfig", add_tile_config, NULL, OR_OPTIONS, "path, name of renderd config and optional key-value pairs to use"),
{NULL}
};
module AP_MODULE_DECLARE_DATA tile_module = {
STANDARD20_MODULE_STUFF,
-NULL, /* dir config creater */
-NULL, /* dir merger --- default is to override */
-create_tile_config, /* server config */
-merge_tile_config, /* merge server config */
-tile_cmds, /* command apr_table_t */
-register_hooks /* register hooks */
+NULL, /* dir config creater */
+NULL, /* dir merger --- default is to override */
+create_tile_config, /* server config */
+merge_tile_config, /* merge server config */
+tile_cmds, /* command apr_table_t */
+register_hooks /* register hooks */
};
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 38625afa..cac96ef3 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1020,6 +1020,14 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
if [ \"\${TILE_DEFAULT_TILEJSON_VERSION}\" != \"2.0.0\" ]; then
exit 1;
fi
+ TILE_DEFAULT_TILEJSON_TILES_0=$(echo \"\${TILE_DEFAULT_TILEJSON_OUTPUT}\" | ${JQ_EXECUTABLE} -r .tiles[0])
+ if [ \"\${TILE_DEFAULT_TILEJSON_TILES_0}\" != \"http://localhost/tiles/${DEFAULT_MAP_NAME}/{z}/{x}/{y}.png\" ]; then
+ exit 1;
+ fi
+ TILE_DEFAULT_TILEJSON_TILES_1=$(echo \"\${TILE_DEFAULT_TILEJSON_OUTPUT}\" | ${JQ_EXECUTABLE} -r .tiles[1])
+ if [ \"\${TILE_DEFAULT_TILEJSON_TILES_1}\" != \"http://alias/tiles/${DEFAULT_MAP_NAME}/{z}/{x}/{y}.png\" ]; then
+ exit 1;
+ fi
"
WORKING_DIRECTORY tests
)
@@ -1062,33 +1070,33 @@ set(DIRECTIVES
set(DIRECTIVE_ERRORS
"AddTileConfig error, URL path not defined"
"AddTileConfig error, name of renderd config not defined"
- "The configured zoom level lies outside of the range supported by this server"
+ "AddTileConfig error, the configured zoom level lies outside of the range supported by this server"
"LoadTileConfigFile takes one argument, load an entire renderd config file"
"LoadTileConfigFile error, unable to open config file"
- "ModTileCacheDurationDirty needs integer argument"
- "ModTileCacheDurationLowZoom needs integer argument"
- "ModTileCacheDurationLowZoom needs integer argument"
- "ModTileCacheDurationMax needs integer argument"
- "ModTileCacheDurationMediumZoom needs integer argument"
- "ModTileCacheDurationMediumZoom needs integer argument"
- "ModTileCacheDurationMinimum needs integer argument"
- "ModTileCacheExtendedDuration needs integer argument"
- "ModTileCacheLastModifiedFactor needs float argument"
+ "ModTileCacheDurationDirty argument must be an integer"
+ "ModTileCacheDurationLowZoom second argument must be an integer"
+ "ModTileCacheDurationLowZoom first argument must be an integer"
+ "ModTileCacheDurationMax argument must be an integer"
+ "ModTileCacheDurationMediumZoom second argument must be an integer"
+ "ModTileCacheDurationMediumZoom first argument must be an integer"
+ "ModTileCacheDurationMinimum argument must be an integer"
+ "ModTileCacheExtendedDuration argument must be an integer"
+ "ModTileCacheLastModifiedFactor argument must be a float"
"ModTileEnableTileThrottlingXForward needs integer argument between 0 and 2 (0 => off\;
1 => use client\; 2 => use last entry in chain"
"ModTileEnableTileThrottlingXForward needs integer argument between 0 and 2 (0 => off\;
1 => use client\; 2 => use last entry in chain"
- "ModTileEnableTileThrottlingXForward needs integer argument between 0 and 2"
- "ModTileMaxLoadMissing needs integer argument"
- "ModTileMaxLoadOld needs integer argument"
- "ModTileMissingRequestTimeout needs integer argument"
- "ModTileRenderdSocketAddr TCP port needs to be an integer argument"
- "ModTileRequestTimeout needs integer argument"
- "ModTileThrottlingRenders needs two numerical arguments, the first one must be integer"
- "ModTileThrottlingRenders needs two numerical arguments, the first one must be integer"
- "ModTileThrottlingTiles needs two numerical arguments, the first one must be integer"
- "ModTileThrottlingTiles needs two numerical arguments, the first one must be integer"
- "ModTileVeryOldThreshold needs integer argument"
+ "ModTileEnableTileThrottlingXForward argument must be an integer"
+ "ModTileMaxLoadMissing argument must be an integer"
+ "ModTileMaxLoadOld argument must be an integer"
+ "ModTileMissingRequestTimeout argument must be an integer"
+ "ModTileRenderdSocketAddr second argument must be an integer"
+ "ModTileRequestTimeout argument must be an integer"
+ "ModTileThrottlingRenders second argument must be a float"
+ "ModTileThrottlingRenders first argument must be an integer"
+ "ModTileThrottlingTiles second argument must be a float"
+ "ModTileThrottlingTiles first argument must be an integer"
+ "ModTileVeryOldThreshold argument must be an integer"
)
list(LENGTH DIRECTIVES DIRECTIVES_LENGTH)
math(EXPR DIRECTIVES_LENGTH "${DIRECTIVES_LENGTH} - 1")
diff --git a/tests/renderd.conf.in b/tests/renderd.conf.in
index 649cde86..7e34e0ea 100644
--- a/tests/renderd.conf.in
+++ b/tests/renderd.conf.in
@@ -12,6 +12,7 @@ ATTRIBUTION=Attribution for @DEFAULT_MAP_NAME@
DESCRIPTION=Description for @DEFAULT_MAP_NAME@
MAXZOOM=5
MINZOOM=0
+SERVER_ALIAS=http://alias/
TILEDIR=@TILE_DIR@
URI=/tiles/@DEFAULT_MAP_NAME@/
XML=@PROJECT_SOURCE_DIR@/utils/example-map/mapnik.xml
@@ -42,7 +43,6 @@ HTCPHOST=@HTTPD1_HOST@
MAXZOOM=20
MINZOOM=0
SCALE=1.0
-SERVER_ALIAS=http://localhost/
TILEDIR=@TILE_DIR@
TILESIZE=256
URI=/tiles/htcp/
@@ -53,8 +53,8 @@ XML=@PROJECT_SOURCE_DIR@/utils/example-map/mapnik.xml
[@DEFAULT_MAP_NAME@_parameterization]
PARAMETERIZE_STYLE=language
TILEDIR=@TILE_DIR@
-TYPE=png image/png# Test two parts (rather than three)
-URI=/tiles/parameterization# Test no trailing slash
+TYPE=png image/png # Test two parts (rather than three)
+URI=/tiles/parameterization # Test no trailing slash
XML=@PROJECT_SOURCE_DIR@/utils/example-map/mapnik.xml
# Test Comment: JPEG Map Section
@@ -85,7 +85,7 @@ XML=@PROJECT_SOURCE_DIR@/utils/example-map/mapnik.xml
; Test Comment: WEBP Map Section
[webp]
TILEDIR=@TILE_DIR@
-TYPE=webp image/webp webp
+TYPE=webp image/webp webp # Test extra spaces
URI=/tiles/webp/
XML=@PROJECT_SOURCE_DIR@/utils/example-map/mapnik.xml
diff --git a/tests/renderd_config_test.cpp b/tests/renderd_config_test.cpp
index 777f587b..bcb6ceee 100644
--- a/tests/renderd_config_test.cpp
+++ b/tests/renderd_config_test.cpp
@@ -111,7 +111,7 @@ TEST_CASE("renderd_config min/max double lat generator", "min/max double generat
}
SECTION(option + " option is negative with --help", "should return 0") {
- std::vector argv = {option, std::to_string(min), "--help"};
+ std::vector argv = {option, std::to_string(min), "--help"};
int status = run_command(test_binary, argv);
REQUIRE(WEXITSTATUS(status) == 0);