Skip to content

Commit 39e87b1

Browse files
committed
Improving tile URI processing logic and other minor improvements
1 parent 6322446 commit 39e87b1

1 file changed

Lines changed: 49 additions & 5 deletions

File tree

src/mod_tile.c

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,36 @@ static int tile_handler_serve(request_rec *r)
17551755
return DECLINED;
17561756
}
17571757

1758+
static apr_status_t mod_tile_shutdown_handler(void *data)
1759+
{
1760+
server_rec *s = (server_rec *)data;
1761+
tile_server_conf *scfg = (tile_server_conf *)ap_get_module_config(s->module_config, &tile_module);
1762+
tile_config_rec *tile_configs = (tile_config_rec *)scfg->configs->elts;
1763+
int tile_configs_count = scfg->configs->nelts;
1764+
1765+
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
1766+
"Cleaning up %i configs for server %s", tile_configs_count, s->server_hostname);
1767+
1768+
for (int i = 0; i < tile_configs_count; ++i) {
1769+
tile_config_rec *tile_config = &tile_configs[i];
1770+
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
1771+
"Freeing tile config for %s", tile_config->xmlname);
1772+
free((void *)*tile_config->hostnames);
1773+
free((void *)tile_config->hostnames);
1774+
free((void *)tile_config->attribution);
1775+
free((void *)tile_config->baseuri);
1776+
free((void *)tile_config->cors);
1777+
free((void *)tile_config->description);
1778+
free((void *)tile_config->fileExtension);
1779+
free((void *)tile_config->mimeType);
1780+
free((void *)tile_config->store);
1781+
free((void *)tile_config->xmlname);
1782+
free(tile_config);
1783+
}
1784+
1785+
return APR_SUCCESS;
1786+
}
1787+
17581788
/*
17591789
* This routine is called in the parent, so we'll set up the shared
17601790
* memory segment and mutex here.
@@ -1923,6 +1953,10 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
19231953

19241954
#endif /* MOD_TILE_SET_MUTEX_PERMS */
19251955

1956+
for (server_rec *virt = s; virt != NULL; virt = virt->next) {
1957+
apr_pool_cleanup_register(pconf, (void *)virt, mod_tile_shutdown_handler, apr_pool_cleanup_null);
1958+
}
1959+
19261960
return OK;
19271961
}
19281962

@@ -1992,18 +2026,24 @@ static const char *_add_tile_config(cmd_parms *cmd,
19922026
// Set attribution to default
19932027
if (attribution_len == 0) {
19942028
attribution = apr_pstrdup(cmd->pool, DEFAULT_ATTRIBUTION);
2029+
} else {
2030+
attribution = apr_pstrndup(cmd->pool, attribution, PATH_MAX);
19952031
}
19962032

19972033
// Ensure URI string ends with a trailing slash
19982034
if (baseuri_len == 0) {
19992035
baseuri = apr_pstrdup(cmd->pool, "/");
20002036
} else if (baseuri[baseuri_len - 1] != '/') {
20012037
baseuri = apr_psprintf(cmd->pool, "%s/", baseuri);
2038+
} else {
2039+
baseuri = apr_pstrndup(cmd->pool, baseuri, PATH_MAX);
20022040
}
20032041

20042042
// If cors is empty, set it to NULL
20052043
if (cors_len == 0) {
20062044
cors = NULL;
2045+
} else {
2046+
cors = apr_pstrndup(cmd->pool, cors, PATH_MAX);
20072047
}
20082048

20092049
// If server_alias is set, increment hostnames_len
@@ -2014,6 +2054,8 @@ static const char *_add_tile_config(cmd_parms *cmd,
20142054
// Set tile_dir to default
20152055
if (tile_dir_len == 0) {
20162056
tile_dir = apr_pstrndup(cmd->pool, scfg->tile_dir, PATH_MAX);
2057+
} else {
2058+
tile_dir = apr_pstrndup(cmd->pool, tile_dir, PATH_MAX);
20172059
}
20182060

20192061
char **hostnames = (char **)apr_pcalloc(cmd->pool, sizeof(char *) * hostnames_len);
@@ -2048,16 +2090,16 @@ static const char *_add_tile_config(cmd_parms *cmd,
20482090
tilecfg->attribution = attribution;
20492091
tilecfg->baseuri = baseuri;
20502092
tilecfg->cors = cors;
2051-
tilecfg->description = description;
2093+
tilecfg->description = apr_pstrndup(cmd->pool, description, PATH_MAX);
20522094
tilecfg->enableOptions = enableOptions;
2053-
tilecfg->fileExtension = fileExtension;
2095+
tilecfg->fileExtension = apr_pstrndup(cmd->pool, fileExtension, PATH_MAX);
20542096
tilecfg->hostnames = hostnames;
20552097
tilecfg->maxzoom = maxzoom;
2056-
tilecfg->mimeType = mimeType;
2098+
tilecfg->mimeType = apr_pstrndup(cmd->pool, mimeType, PATH_MAX);
20572099
tilecfg->minzoom = minzoom;
20582100
tilecfg->noHostnames = hostnames_len;
20592101
tilecfg->store = tile_dir;
2060-
tilecfg->xmlname = name;
2102+
tilecfg->xmlname = apr_pstrndup(cmd->pool, name, PATH_MAX);
20612103

20622104
if (maxzoom > global_max_zoom) {
20632105
global_max_zoom = maxzoom;
@@ -2144,7 +2186,7 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
21442186

21452187
xmlconfigitem maps[XMLCONFIGS_MAX];
21462188

2147-
process_map_sections(NULL, config_file_name, maps, "", 0);
2189+
process_map_sections(NULL, config_file_name, maps, RENDERD_TILE_DIR, 0);
21482190

21492191
for (int i = 0; i < XMLCONFIGS_MAX; i++) {
21502192
if (maps[i].xmlname != NULL) {
@@ -2159,6 +2201,8 @@ static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *c
21592201
}
21602202
}
21612203

2204+
free_map_sections(maps);
2205+
21622206
return NULL;
21632207
}
21642208

0 commit comments

Comments
 (0)