Skip to content

Commit

Permalink
Added tile_dir support to httpd.conf directive AddTileConfig (#370
Browse files Browse the repository at this point in the history
)

_Also_:
- Changed `AddTileConfig` parsing directive
  - From `AP_INIT_RAW_ARGS` to `AP_INIT_TAKE_ARGV`
  - Makes code a bit cleaner, e.g.:
    - Checking for first two "arguments"
    - Iterating "arguments"
- Applied Artistic Style Formatting 
  - After merging #346
- Added deprecation notice when using `AddTileMimeConfig`
- Enabled commented `AddTileConfig`/`AddTileMimeConfig` tests
  • Loading branch information
hummeltech authored Jan 12, 2024
1 parent d761f96 commit 8cca561
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 95 deletions.
89 changes: 46 additions & 43 deletions src/mod_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2092,60 +2092,63 @@ static const char *_add_tile_config(cmd_parms *cmd, void *mconfig,

static const char *add_tile_mime_config(cmd_parms *cmd, void *mconfig, const char *baseuri, const char *name, const char * fileExtension)
{
// this configuration option should be deprecated and be replaced by
// a version of AddTileConfig with "extension=xxx"
// how to log a warning here?
if (strcmp(fileExtension, "png") == 0) {
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "image/png", NULL, NULL, 0, NULL, NULL, NULL, 0);
}
char *cors = NULL;
char *mimeType = "image/png";

if (strcmp(fileExtension, "js") == 0) {
return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "text/javascript", NULL, NULL, 0, NULL, "*", NULL, 0);
cors = "*";
mimeType = "text/javascript";
}

return _add_tile_config(cmd, mconfig, baseuri, name, 0, MAX_ZOOM, 1, 1, fileExtension, "image/png", NULL, NULL, 0, NULL, NULL, NULL, 0);
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);
}

static const char *add_tile_config(cmd_parms *cmd, void *mconfig, const char *args)
static const char *add_tile_config(cmd_parms *cmd, void *mconfig, int argc, char *const argv[])
{
const char *baseuri = ap_getword_conf(cmd->pool, &args);
if (!baseuri) return("AddTileConfig error");
const char *name = ap_getword_conf(cmd->pool, &args);
if (!name) return("AddTileConfig error");
if (argc < 1) {
return ("AddTileConfig error, URL path not defined");
}

if (argc < 2) {
return ("AddTileConfig error, name of renderd config not defined");
}

int maxzoom = MAX_ZOOM;
int minzoom = 0;
const char *extension = "png";
const char *mimeType = "image/png";
char *token = ap_getword_conf(cmd->pool, &args);
while(token)
{
char *eq = strchr(token, '=');
if (eq)
{
*eq++=0;
if (!strcmp(token, "maxzoom"))
{
maxzoom = atoi(eq);
}
else if (!strcmp(token, "minzoom"))
{
minzoom = atoi(eq);
}
else if (!strcmp(token, "extension"))
{
extension = eq;
}
else if (!strcmp(token, "mimetype"))
{
mimeType = eq;
char *baseuri = argv[0];
char *name = argv[1];
char *fileExtension = "png";
char *mimeType = "image/png";
char *tile_dir = RENDERD_TILE_DIR;

int i;

for (i = 2; i < argc; i++) {
char *value = strchr(argv[i], '=');

if (value) {
*value++ = 0;

if (!strcmp(argv[i], "maxzoom")) {
maxzoom = strtol(value, NULL, 10);
} else if (!strcmp(argv[i], "minzoom")) {
minzoom = strtol(value, NULL, 10);
} else if (!strcmp(argv[i], "extension")) {
fileExtension = value;
} else if (!strcmp(argv[i], "mimetype")) {
mimeType = value;
} else if (!strcmp(argv[i], "tile_dir")) {
tile_dir = value;
}
}
if (!*args) break;
token = ap_getword_conf(cmd->pool, &args);
}

return _add_tile_config(cmd, mconfig, baseuri, name, minzoom, maxzoom, 1, 1, extension, mimeType, NULL,NULL,0,NULL,NULL,NULL,0);
return _add_tile_config(cmd, mconfig, baseuri, name, minzoom, maxzoom, 1, 1, fileExtension, mimeType, NULL, NULL, 0, NULL, NULL, tile_dir, 0);
}

static const char *load_tile_config(cmd_parms *cmd, void *mconfig, const char *conffile)
{
FILE * hini ;
Expand Down Expand Up @@ -2889,19 +2892,19 @@ static const command_rec tile_cmds[] = {
OR_OPTIONS, /* where available */
"load an entire renderd config file" /* directive description */
),
AP_INIT_RAW_ARGS(
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, and optional key-value pairs for renderd config to use" /* directive description */
"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 and file extension of renderd config to use" /* directive description */
"path, name of renderd config and file extension to use" /* directive description */
),
AP_INIT_TAKE1(
"ModTileRequestTimeout", /* directive name */
Expand Down
103 changes: 51 additions & 52 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
\" at /\${CONFIG_NAME}/ \"
\" extension .jpg \"
\" mime type image/jpeg$\"
# \" tile directory ${TILE_DIR} \"
\" tile directory ${RENDERD_TILE_DIR} \"
\" tile directory ${TILE_DIR} \"
\" zooms 10 - 15 \"
)
echo \"Searching log line '\${SEARCH_LINE}'\"
Expand Down Expand Up @@ -404,17 +403,17 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
\" tile directory ${RENDERD_TILE_DIR} \"
\" zooms 0 - 20 \"
)
# echo \"Searching log line '\${SEARCH_LINE}'\"
# for SEARCH_STR in \"\${SEARCH_STRS[@]}\"; do
# echo \"\tFor '\${SEARCH_STR}'\"
# echo \"\${SEARCH_LINE}\" | ${GREP_EXECUTABLE} -q -e \"\${SEARCH_STR}\" || exit 1
# done
# SEARCH_LINE=\$(${GREP_EXECUTABLE} \"AddTileMimeConfig will be deprecated\" ${HTTPD_LOG} | \
# ${GREP_EXECUTABLE} -m1 \"\${CONFIG_NAME}\")
# echo \"Searching log line '\${SEARCH_LINE}'\"
# SEARCH_STR=\"AddTileConfig /\${CONFIG_NAME}/ \${CONFIG_NAME} mimetype=\${MIME_TYPE} extension=\${SEARCH_CONFIG}\"
# echo \"\tFor '\${SEARCH_STR}'\"
# echo \"\${SEARCH_LINE}\" | ${GREP_EXECUTABLE} -q -e \"\${SEARCH_STR}\" || exit 1
echo \"Searching log line '\${SEARCH_LINE}'\"
for SEARCH_STR in \"\${SEARCH_STRS[@]}\"; do
echo \"\tFor '\${SEARCH_STR}'\"
echo \"\${SEARCH_LINE}\" | ${GREP_EXECUTABLE} -q -e \"\${SEARCH_STR}\" || exit 1
done
SEARCH_LINE=\$(${GREP_EXECUTABLE} \"AddTileMimeConfig will be deprecated\" ${HTTPD_LOG} | \
${GREP_EXECUTABLE} -m1 \"\${CONFIG_NAME}\")
echo \"Searching log line '\${SEARCH_LINE}'\"
SEARCH_STR=\"AddTileConfig /\${CONFIG_NAME}/ \${CONFIG_NAME} mimetype=\${MIME_TYPE} extension=\${SEARCH_CONFIG}\"
echo \"\tFor '\${SEARCH_STR}'\"
echo \"\${SEARCH_LINE}\" | ${GREP_EXECUTABLE} -q -e \"\${SEARCH_STR}\" || exit 1
done
"
WORKING_DIRECTORY tests
Expand Down Expand Up @@ -536,47 +535,47 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
)
endforeach()

# set(TILE_URL_PATH "/download_add_tile_config/${TILE_ZXY}.png")
# set(HTTPD0_URL "http://${HTTPD0_HOST}:${HTTPD0_PORT}${TILE_URL_PATH}")
# set(HTTPD1_URL "http://${HTTPD1_HOST}:${HTTPD1_PORT}${TILE_URL_PATH}")
# set(TILE_FILE_NAME "tile.add_tile_config.${STORAGE_BACKEND}")
# add_test(
# NAME download_tile_add_tile_config_${STORAGE_BACKEND}
# COMMAND ${BASH} -c "
# until $(${CURL_CMD} ${HTTPD0_URL} --output ${TILE_FILE_NAME}.0); do
# echo 'Sleeping 1s (${TILE_FILE_NAME}.0)';
# sleep 1;
# done
# until $(${CURL_CMD} ${HTTPD1_URL} --output ${TILE_FILE_NAME}.1); do
# echo 'Sleeping 1s (${TILE_FILE_NAME}.1)';
# sleep 1;
# done
# "
# WORKING_DIRECTORY tests
# )
# set_tests_properties(download_tile_add_tile_config_${STORAGE_BACKEND} PROPERTIES
# FIXTURES_REQUIRED services_started_${STORAGE_BACKEND}
# FIXTURES_SETUP tiles_downloaded_${STORAGE_BACKEND}
# TIMEOUT 10
# )
# add_test(
# NAME remove_tile_add_tile_config_${STORAGE_BACKEND}
# COMMAND ${RM} -v ${TILE_FILE_NAME}.0 ${TILE_FILE_NAME}.1
# WORKING_DIRECTORY tests
# )
# set_tests_properties(remove_tile_add_tile_config_${STORAGE_BACKEND} PROPERTIES
# DEPENDS_ON download_tile_add_tile_config_${STORAGE_BACKEND}
# FIXTURES_CLEANUP tiles_downloaded_${STORAGE_BACKEND}
# REQUIRED_FILES "${TILE_FILE_NAME}.0;${TILE_FILE_NAME}.1"
# )
set(TILE_URL_PATH "/download_add_tile_config/${TILE_ZXY}.png")
set(HTTPD0_URL "http://${HTTPD0_HOST}:${HTTPD0_PORT}${TILE_URL_PATH}")
set(HTTPD1_URL "http://${HTTPD1_HOST}:${HTTPD1_PORT}${TILE_URL_PATH}")
set(TILE_FILE_NAME "tile.add_tile_config.${STORAGE_BACKEND}")
add_test(
NAME download_tile_add_tile_config_${STORAGE_BACKEND}
COMMAND ${BASH} -c "
until $(${CURL_CMD} ${HTTPD0_URL} --output ${TILE_FILE_NAME}.0); do
echo 'Sleeping 1s (${TILE_FILE_NAME}.0)';
sleep 1;
done
until $(${CURL_CMD} ${HTTPD1_URL} --output ${TILE_FILE_NAME}.1); do
echo 'Sleeping 1s (${TILE_FILE_NAME}.1)';
sleep 1;
done
"
WORKING_DIRECTORY tests
)
set_tests_properties(download_tile_add_tile_config_${STORAGE_BACKEND} PROPERTIES
FIXTURES_REQUIRED services_started_${STORAGE_BACKEND}
FIXTURES_SETUP tiles_downloaded_${STORAGE_BACKEND}
TIMEOUT 10
)
add_test(
NAME remove_tile_add_tile_config_${STORAGE_BACKEND}
COMMAND ${RM} -v ${TILE_FILE_NAME}.0 ${TILE_FILE_NAME}.1
WORKING_DIRECTORY tests
)
set_tests_properties(remove_tile_add_tile_config_${STORAGE_BACKEND} PROPERTIES
DEPENDS_ON download_tile_add_tile_config_${STORAGE_BACKEND}
FIXTURES_CLEANUP tiles_downloaded_${STORAGE_BACKEND}
REQUIRED_FILES "${TILE_FILE_NAME}.0;${TILE_FILE_NAME}.1"
)

add_test(
NAME check_tiles_${STORAGE_BACKEND}
COMMAND ${BASH} -c "
# (echo '${TILE_PNG256_SHA256SUM} tile.add_tile_config.${STORAGE_BACKEND}.0' | ${SHA256SUM_EXECUTABLE} -c) && \
# (echo '${TILE_PNG256_SHA256SUM} tile.add_tile_config.${STORAGE_BACKEND}.1' | ${SHA256SUM_EXECUTABLE} -c) && \
(echo '${TILE_JPG_SHA256SUM} tile.jpg.${STORAGE_BACKEND}.0' | ${SHA256SUM_EXECUTABLE} -c) && \
(echo '${TILE_JPG_SHA256SUM} tile.jpg.${STORAGE_BACKEND}.1' | ${SHA256SUM_EXECUTABLE} -c) && \
(echo '${TILE_PNG256_SHA256SUM} tile.add_tile_config.${STORAGE_BACKEND}.0' | ${SHA256SUM_EXECUTABLE} -c) && \
(echo '${TILE_PNG256_SHA256SUM} tile.add_tile_config.${STORAGE_BACKEND}.1' | ${SHA256SUM_EXECUTABLE} -c) && \
(echo '${TILE_PNG256_SHA256SUM} tile.png256.${STORAGE_BACKEND}.0' | ${SHA256SUM_EXECUTABLE} -c) && \
(echo '${TILE_PNG256_SHA256SUM} tile.png256.${STORAGE_BACKEND}.1' | ${SHA256SUM_EXECUTABLE} -c) && \
(echo '${TILE_PNG32_SHA256SUM} tile.png32.${STORAGE_BACKEND}.0' | ${SHA256SUM_EXECUTABLE} -c) && \
Expand Down Expand Up @@ -746,14 +745,14 @@ endforeach()

# Test mal-formed HTTPD configuration directives
set(DIRECTIVES
# "AddTileConfig"
# "AddTileConfig /bad/"
"AddTileConfig"
"AddTileConfig /bad/"
"LoadTileConfigFile"
"LoadTileConfigFile /tmp/bad/file/name"
)
set(DIRECTIVE_ERRORS
# "AddTileConfig error, URL path not defined"
# "AddTileConfig error, name of renderd config not defined"
"AddTileConfig error, URL path not defined"
"AddTileConfig error, name of renderd config not defined"
"LoadTileConfigFile takes one argument, load an entire renderd config file"
"Unable to open config file"
)
Expand Down

0 comments on commit 8cca561

Please sign in to comment.