Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer hostname determination to the post_config hook #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/mod_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,28 @@ static int mod_tile_post_config(apr_pool_t *pconf, apr_pool_t *plog,
stats_data *stats;
delaypool *delayp;
int i;
tile_server_conf *scfg;

scfg = ap_get_module_config(s->module_config, &tile_module);

for (i = 0; i < scfg->configs->nelts; ++i) {
tile_config_rec *tilecfg = (tile_config_rec *)scfg->configs->elts + i;

if (tilecfg->hostnames == NULL) {
tilecfg->hostnames = malloc(sizeof(char *));
/* FIXME: wouldn't be allocationg 7+len+1 bytes be enough? */
tilecfg->hostnames[0] = malloc(PATH_MAX);
strncpy(tilecfg->hostnames[0], "http://", PATH_MAX);
if (s->server_hostname == NULL) {
ap_log_error(APLOG_MARK, APLOG_WARNING, APR_SUCCESS, s,
"Could not determine host name of server to configure tile-json request. Using localhost instead");
strncat(tilecfg->hostnames[0], "localhost", PATH_MAX - 8);
} else {
strncat(tilecfg->hostnames[0], s->server_hostname, PATH_MAX - 8);
}
tilecfg->noHostnames = 1;
}
}

/*
* The following checks if this routine has been called before.
Expand Down Expand Up @@ -1632,21 +1654,6 @@ static const char *_add_tile_config(cmd_parms *cmd, void *mconfig,
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);
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");

strncat(hostnames[0],"localhost",PATH_MAX-10);
} else
strncat(hostnames[0],cmd->server->server_hostname,PATH_MAX-strlen(hostnames[0])-1);
noHostnames = 1;
}

if (attribution == NULL) {
attribution = strdup(DEFAULT_ATTRIBUTION);
}
Expand Down