Split up renderd.conf processing by section type (#397)

This commit is contained in:
Hummeltech
2024-03-01 20:04:09 -07:00
committed by GitHub
parent 04a0bf0f09
commit 2de946dde1
9 changed files with 355 additions and 250 deletions

View File

@ -20,8 +20,8 @@
#include <mapnik/map.hpp>
typedef void (*parameterize_function_ptr)(mapnik::Map &m, char * parameter);
typedef void (*parameterize_function_ptr)(mapnik::Map &m, char *parameter);
parameterize_function_ptr init_parameterization_function(char * function_name);
parameterize_function_ptr init_parameterization_function(const char *function_name);
#endif

View File

@ -34,31 +34,34 @@ int daemon(int nochdir, int noclose);
#define MAX_SLAVES 5
typedef struct {
char *iphostname;
char *mapnik_font_dir;
char *mapnik_plugins_dir;
char *pid_filename;
char *socketname;
char *stats_filename;
char *tile_dir;
const char *iphostname;
const char *mapnik_font_dir;
const char *mapnik_plugins_dir;
const char *name;
const char *pid_filename;
const char *socketname;
const char *stats_filename;
const char *tile_dir;
int ipport;
int mapnik_font_dir_recurse;
int num_threads;
} renderd_config;
typedef struct {
char *attribution;
char *cors;
char *description;
char *host;
char *htcpip;
char *output_format;
char *parameterization;
char *server_alias;
char *tile_dir;
char *xmlfile;
char *xmlname;
char *xmluri;
const char *attribution;
const char *cors;
const char *description;
const char *file_extension;
const char *host;
const char *htcpip;
const char *mime_type;
const char *output_format;
const char *parameterization;
const char *server_alias;
const char *tile_dir;
const char *xmlfile;
const char *xmlname;
const char *xmluri;
double scale_factor;
int aspect_x;
int aspect_y;

View File

@ -25,13 +25,20 @@
extern "C" {
#endif
extern int num_slave_threads;
extern renderd_config config;
extern renderd_config config_slaves[MAX_SLAVES];
extern xmlconfigitem maps[XMLCONFIGS_MAX];
int num_slave_threads;
renderd_config config;
renderd_config config_slaves[MAX_SLAVES];
xmlconfigitem maps[XMLCONFIGS_MAX];
int min_max_int_opt(const char *opt_arg, const char *opt_type_name, int minimum, int maximum);
void free_map_section(xmlconfigitem map_section);
void free_map_sections(xmlconfigitem *map_sections);
void free_renderd_section(renderd_config renderd_section);
void free_renderd_sections(renderd_config *renderd_sections);
void process_config_file(const char *config_file_name, int active_renderd_section_num, int log_level);
void process_map_sections(const char *config_file_name, xmlconfigitem *maps_dest, const char *default_tile_dir, int num_threads);
void process_mapnik_section(const char *config_file_name, renderd_config *config_dest);
void process_renderd_sections(const char *config_file_name, renderd_config *configs_dest);
#ifdef __cplusplus
}

View File

@ -15,24 +15,22 @@
* along with this program; If not, see http://www.gnu.org/licenses/.
*/
#include <mapnik/version.hpp>
#include <mapnik/map.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/params.hpp>
#include <boost/optional.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/layer.hpp>
#include <mapnik/map.hpp>
#include <mapnik/params.hpp>
#include <mapnik/version.hpp>
#include <boost/optional.hpp>
#include "parameterize_style.hpp"
#include "g_logger.h"
#include "parameterize_style.hpp"
static void parameterize_map_language(mapnik::Map &m, char * parameter)
static void parameterize_map_language(mapnik::Map &m, char *parameter)
{
unsigned int i;
char * data = strdup(parameter);
char * tok;
char *data = strdup(parameter);
char *tok;
char name_replace[256];
name_replace[0] = 0;
@ -41,7 +39,7 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)
if (!tok) {
free(data);
return; //No parameterization given
return; // No parameterization given
}
strncat(name_replace, ", coalesce(", 255);
@ -56,7 +54,6 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)
}
tok = strtok(NULL, ",");
}
free(data);
@ -64,7 +61,7 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)
strncat(name_replace, ") as name", 255);
for (i = 0; i < m.layer_count(); i++) {
mapnik::layer& l = m.get_layer(i);
mapnik::layer &l = m.get_layer(i);
mapnik::parameters params = l.datasource()->params();
if (params.find("table") != params.end()) {
@ -78,12 +75,10 @@ static void parameterize_map_language(mapnik::Map &m, char * parameter)
l.set_datasource(mapnik::datasource_cache::instance().create(params));
}
}
}
}
parameterize_function_ptr init_parameterization_function(char * function_name)
parameterize_function_ptr init_parameterization_function(const char *function_name)
{
if (strcmp(function_name, "") == 0) {
g_logger(G_LOG_LEVEL_DEBUG, "Parameterize_style not specified (or empty string specified)");

View File

@ -745,7 +745,7 @@ int main(int argc, char **argv)
switch (c) {
case 'c': /* -c, --config */
config_file_name = strdup(optarg);
config_file_name = strndup(optarg, PATH_MAX);
config_file_name_passed = 1;
struct stat buffer;
@ -777,7 +777,7 @@ int main(int argc, char **argv)
fprintf(stderr, " -V, --version display the version number and exit\n");
return 0;
case 'V':
case 'V': /* -V, --version */
fprintf(stdout, "%s\n", VERSION);
return 0;
@ -799,6 +799,10 @@ int main(int argc, char **argv)
process_config_file(config_file_name, active_renderd_section_num, G_LOG_LEVEL_INFO);
if (config_file_name_passed) {
free((void *)config_file_name);
}
fd = server_socket_init(&config);
#if 0
@ -867,10 +871,9 @@ int main(int argc, char **argv)
}
if (active_renderd_section_num == 0) {
//Only the master renderd opens connections to its slaves
// Only the master renderd opens connections to its slaves
k = 0;
slave_threads
= (pthread_t *) malloc(sizeof(pthread_t) * num_slave_threads);
slave_threads = (pthread_t *) malloc(sizeof(pthread_t) * num_slave_threads);
for (i = 1; i < MAX_SLAVES; i++) {
for (j = 0; j < config_slaves[i].num_threads; j++) {
@ -881,6 +884,13 @@ int main(int argc, char **argv)
}
}
}
} else {
for (i = 0; i < MAX_SLAVES; i++) {
if (active_renderd_section_num != i && config_slaves[i].num_threads != 0) {
g_logger(G_LOG_LEVEL_DEBUG, "Freeing unused renderd config section %i: %s", i, config_slaves[i].name);
free_renderd_section(config_slaves[i]);
}
}
}
process_loop(fd);

View File

@ -15,6 +15,8 @@
* along with this program; If not, see http://www.gnu.org/licenses/.
*/
#define _GNU_SOURCE
#include "config.h"
#include "g_logger.h"
#include "render_config.h"
@ -26,54 +28,27 @@
#include <iniparser.h>
#endif
int num_slave_threads;
renderd_config config;
renderd_config config_slaves[MAX_SLAVES];
xmlconfigitem maps[XMLCONFIGS_MAX];
static void copy_string_with_snprintf(const char *src, char **dest, size_t maxlen)
static void copy_string(const char *src, const char **dest, size_t maxlen)
{
int len, size;
size_t size = sizeof(char) * strnlen(src, maxlen);
size = sizeof(char) * strnlen(src, maxlen) + sizeof(char);
*dest = malloc(size);
*dest = strndup(src, size);
if (*dest == NULL) {
g_logger(G_LOG_LEVEL_CRITICAL, "malloc error");
exit(7);
}
len = snprintf(*dest, size, "%s", src);
if (len < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "snprintf encoding error");
exit(7);
} else if (len >= maxlen) {
g_logger(G_LOG_LEVEL_CRITICAL, "snprintf buffer too small");
g_logger(G_LOG_LEVEL_CRITICAL, "copy_string: strndup error");
exit(7);
}
}
static char *name_with_section(const char *section, const char *name)
{
int len, maxlen = INILINE_MAX - 1;
size_t len;
char *key;
key = malloc(sizeof(char) * maxlen);
len = asprintf(&key, "%s:%s", section, name);
if (key == NULL) {
g_logger(G_LOG_LEVEL_CRITICAL, "malloc error");
exit(7);
}
len = snprintf(key, maxlen, "%s:%s", section, name);
if (len < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "snprintf encoding error");
exit(7);
} else if (len >= maxlen) {
g_logger(G_LOG_LEVEL_CRITICAL, "snprintf buffer too small");
if (len == -1) {
g_logger(G_LOG_LEVEL_CRITICAL, "name_with_section: asprintf error");
exit(7);
}
@ -116,27 +91,73 @@ static void process_config_int(const dictionary *ini, const char *section, const
free(key);
}
static void process_config_string(const dictionary *ini, const char *section, const char *name, char **dest, char *notfound, int maxlen)
static void process_config_string(const dictionary *ini, const char *section, const char *name, const char **dest, const char *notfound, size_t maxlen)
{
int len;
char *key = name_with_section(section, name);
const char *src = iniparser_getstring(ini, key, notfound);
g_logger(G_LOG_LEVEL_DEBUG, "\tRead %s: '%s'", key, src);
copy_string_with_snprintf(src, dest, maxlen);
copy_string(src, dest, maxlen);
free(key);
}
void free_map_section(xmlconfigitem map_section)
{
free((void *)map_section.attribution);
free((void *)map_section.cors);
free((void *)map_section.description);
free((void *)map_section.file_extension);
free((void *)map_section.host);
free((void *)map_section.htcpip);
free((void *)map_section.mime_type);
free((void *)map_section.output_format);
free((void *)map_section.parameterization);
free((void *)map_section.server_alias);
free((void *)map_section.tile_dir);
free((void *)map_section.xmlfile);
free((void *)map_section.xmlname);
free((void *)map_section.xmluri);
bzero(&map_section, sizeof(xmlconfigitem));
}
void free_map_sections(xmlconfigitem *map_sections)
{
for (int i = 0; i < XMLCONFIGS_MAX; i++) {
if (map_sections[i].xmlname != NULL) {
free_map_section(map_sections[i]);
}
}
}
void free_renderd_section(renderd_config renderd_section)
{
free((void *)renderd_section.iphostname);
free((void *)renderd_section.mapnik_font_dir);
free((void *)renderd_section.mapnik_plugins_dir);
free((void *)renderd_section.name);
free((void *)renderd_section.pid_filename);
free((void *)renderd_section.socketname);
free((void *)renderd_section.stats_filename);
free((void *)renderd_section.tile_dir);
bzero(&renderd_section, sizeof(renderd_config));
}
void free_renderd_sections(renderd_config *renderd_sections)
{
for (int i = 0; i < MAX_SLAVES; i++) {
if (renderd_sections[i].num_threads != 0) {
free_renderd_section(renderd_sections[i]);
}
}
}
int min_max_int_opt(const char *opt_arg, const char *opt_type_name, int minimum, int maximum)
{
int opt;
float opt_float;
char *endptr, *endptr_float;
opt = strtol(opt_arg, &endptr, 10);
opt_float = strtof(opt_arg, &endptr_float);
int opt = strtol(opt_arg, &endptr, 10);
float opt_float = strtof(opt_arg, &endptr_float);
if (endptr == opt_arg || endptr_float == opt_arg || (float)opt != opt_float) {
g_logger(G_LOG_LEVEL_CRITICAL, "Invalid %s, must be an integer (%s was provided)", opt_type_name, opt_arg);
@ -152,14 +173,10 @@ int min_max_int_opt(const char *opt_arg, const char *opt_type_name, int minimum,
return opt;
}
void process_config_file(const char *config_file_name, int active_renderd_section_num, int log_level)
void process_map_sections(const char *config_file_name, xmlconfigitem *maps_dest, const char *default_tile_dir, int num_threads)
{
int i, map_section_num = -1;
bzero(&config, sizeof(renderd_config));
bzero(config_slaves, sizeof(renderd_config) * MAX_SLAVES);
bzero(maps, sizeof(xmlconfigitem) * XMLCONFIGS_MAX);
int map_section_num = -1;
g_logger(log_level, "Parsing renderd config file '%s':", config_file_name);
dictionary *ini = iniparser_load(config_file_name);
if (!ini) {
@ -167,7 +184,158 @@ void process_config_file(const char *config_file_name, int active_renderd_sectio
exit(1);
}
num_slave_threads = 0;
bzero(maps_dest, sizeof(xmlconfigitem) * XMLCONFIGS_MAX);
g_logger(G_LOG_LEVEL_DEBUG, "Parsing map config section(s)");
for (int section_num = 0; section_num < iniparser_getnsec(ini); section_num++) {
const char *section = iniparser_getsecname(ini, section_num);
if (strncmp(section, "renderd", 7) && strcmp(section, "mapnik")) {
/* this is a map config section */
map_section_num++;
g_logger(G_LOG_LEVEL_DEBUG, "Parsing map config section %i: %s", map_section_num, section);
if (map_section_num >= XMLCONFIGS_MAX) {
g_logger(G_LOG_LEVEL_CRITICAL, "Can't handle more than %i map config sections", XMLCONFIGS_MAX);
exit(7);
}
copy_string(section, &maps_dest[map_section_num].xmlname, XMLCONFIG_MAX);
process_config_int(ini, section, "aspectx", &maps_dest[map_section_num].aspect_x, 1);
process_config_int(ini, section, "aspecty", &maps_dest[map_section_num].aspect_y, 1);
process_config_int(ini, section, "tilesize", &maps_dest[map_section_num].tile_px_size, 256);
process_config_string(ini, section, "attribution", &maps_dest[map_section_num].attribution, "", PATH_MAX);
process_config_string(ini, section, "cors", &maps_dest[map_section_num].cors, "", PATH_MAX);
process_config_string(ini, section, "description", &maps_dest[map_section_num].description, "", PATH_MAX);
process_config_string(ini, section, "host", &maps_dest[map_section_num].host, "", PATH_MAX);
process_config_string(ini, section, "htcphost", &maps_dest[map_section_num].htcpip, "", PATH_MAX);
process_config_string(ini, section, "parameterize_style", &maps_dest[map_section_num].parameterization, "", PATH_MAX);
process_config_string(ini, section, "server_alias", &maps_dest[map_section_num].server_alias, "", PATH_MAX);
process_config_string(ini, section, "tiledir", &maps_dest[map_section_num].tile_dir, default_tile_dir, PATH_MAX);
process_config_string(ini, section, "uri", &maps_dest[map_section_num].xmluri, "", PATH_MAX);
process_config_string(ini, section, "xml", &maps_dest[map_section_num].xmlfile, "", PATH_MAX);
process_config_double(ini, section, "scale", &maps_dest[map_section_num].scale_factor, 1.0);
if (maps_dest[map_section_num].scale_factor < 0.1) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified scale factor (%lf) is too small, must be greater than or equal to %lf.", maps_dest[map_section_num].scale_factor, 0.1);
exit(7);
} else if (maps_dest[map_section_num].scale_factor > 8.0) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified scale factor (%lf) is too large, must be less than or equal to %lf.", maps_dest[map_section_num].scale_factor, 8.0);
exit(7);
}
process_config_int(ini, section, "maxzoom", &maps_dest[map_section_num].max_zoom, MAX_ZOOM);
if (maps_dest[map_section_num].max_zoom < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified max zoom (%i) is too small, must be greater than or equal to %i.", maps_dest[map_section_num].max_zoom, 0);
exit(7);
} else if (maps_dest[map_section_num].max_zoom > MAX_ZOOM) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified max zoom (%i) is too large, must be less than or equal to %i.", maps_dest[map_section_num].max_zoom, MAX_ZOOM);
exit(7);
}
process_config_int(ini, section, "minzoom", &maps_dest[map_section_num].min_zoom, 0);
if (maps_dest[map_section_num].min_zoom < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified min zoom (%i) is too small, must be greater than or equal to %i.", maps_dest[map_section_num].min_zoom, 0);
exit(7);
} else if (maps_dest[map_section_num].min_zoom > maps_dest[map_section_num].max_zoom) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified min zoom (%i) is larger than max zoom (%i).", maps_dest[map_section_num].min_zoom, maps_dest[map_section_num].max_zoom);
exit(7);
}
char *file_extension = malloc(INILINE_MAX);
char *mime_type = malloc(INILINE_MAX);
char *output_format = malloc(INILINE_MAX);
const char *ini_type;
int num_ini_type_parts;
process_config_string(ini, section, "type", &ini_type, "png image/png png256", INILINE_MAX);
num_ini_type_parts = sscanf(ini_type, "%[^ ] %[^ ] %[^ ]", file_extension, mime_type, output_format);
if (num_ini_type_parts < 2) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified type (%s) has too few parts, there must be at least 2, e.g., 'png image/png'.", ini_type);
exit(7);
}
copy_string(file_extension, &maps_dest[map_section_num].file_extension, INILINE_MAX);
copy_string(mime_type, &maps_dest[map_section_num].mime_type, INILINE_MAX);
if (num_ini_type_parts == 3) {
copy_string(output_format, &maps_dest[map_section_num].output_format, INILINE_MAX);
} else {
copy_string("png256", &maps_dest[map_section_num].output_format, INILINE_MAX);
}
free((void *)ini_type);
free(file_extension);
free(mime_type);
free(output_format);
/* Pass this information into the rendering threads,
* as it is needed to configure mapniks number of connections
*/
maps_dest[map_section_num].num_threads = num_threads;
}
}
iniparser_freedict(ini);
if (map_section_num < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "No map config sections were found in file: %s", config_file_name);
exit(1);
}
}
void process_mapnik_section(const char *config_file_name, renderd_config *config_dest)
{
int mapnik_section_num = -1;
dictionary *ini = iniparser_load(config_file_name);
if (!ini) {
g_logger(G_LOG_LEVEL_CRITICAL, "Failed to load config file: %s", config_file_name);
exit(1);
}
g_logger(G_LOG_LEVEL_DEBUG, "Parsing mapnik config section");
for (int section_num = 0; section_num < iniparser_getnsec(ini); section_num++) {
const char *section = iniparser_getsecname(ini, section_num);
if (strcmp(section, "mapnik") == 0) {
/* this is a mapnik config section */
mapnik_section_num = section_num;
process_config_bool(ini, section, "font_dir_recurse", &config_dest->mapnik_font_dir_recurse, MAPNIK_FONTS_DIR_RECURSE);
process_config_string(ini, section, "font_dir", &config_dest->mapnik_font_dir, MAPNIK_FONTS_DIR, PATH_MAX);
process_config_string(ini, section, "plugins_dir", &config_dest->mapnik_plugins_dir, MAPNIK_PLUGINS_DIR, PATH_MAX);
break;
}
}
iniparser_freedict(ini);
if (mapnik_section_num < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "No mapnik config section was found in file: %s", config_file_name);
exit(1);
}
}
void process_renderd_sections(const char *config_file_name, renderd_config *configs_dest)
{
int renderd_section_num = -1;
dictionary *ini = iniparser_load(config_file_name);
if (!ini) {
g_logger(G_LOG_LEVEL_CRITICAL, "Failed to load config file: %s", config_file_name);
exit(1);
}
bzero(configs_dest, sizeof(renderd_config) * MAX_SLAVES);
g_logger(G_LOG_LEVEL_DEBUG, "Parsing renderd config section(s)");
@ -176,8 +344,6 @@ void process_config_file(const char *config_file_name, int active_renderd_sectio
if (strncmp(section, "renderd", 7) == 0) {
/* this is a renderd config section */
int renderd_section_num = 0;
if (sscanf(section, "renderd%i", &renderd_section_num) != 1) {
renderd_section_num = 0;
}
@ -189,131 +355,74 @@ void process_config_file(const char *config_file_name, int active_renderd_sectio
exit(7);
}
process_config_int(ini, section, "ipport", &config_slaves[renderd_section_num].ipport, 0);
process_config_int(ini, section, "num_threads", &config_slaves[renderd_section_num].num_threads, NUM_THREADS);
process_config_string(ini, section, "iphostname", &config_slaves[renderd_section_num].iphostname, "", INILINE_MAX - 1);
process_config_string(ini, section, "pid_file", &config_slaves[renderd_section_num].pid_filename, RENDERD_PIDFILE, PATH_MAX - 1);
process_config_string(ini, section, "socketname", &config_slaves[renderd_section_num].socketname, RENDERD_SOCKET, PATH_MAX - 1);
process_config_string(ini, section, "stats_file", &config_slaves[renderd_section_num].stats_filename, "", PATH_MAX - 1);
process_config_string(ini, section, "tile_dir", &config_slaves[renderd_section_num].tile_dir, RENDERD_TILE_DIR, PATH_MAX - 1);
copy_string(section, &configs_dest[renderd_section_num].name, 10);
if (config_slaves[renderd_section_num].num_threads == -1) {
config_slaves[renderd_section_num].num_threads = sysconf(_SC_NPROCESSORS_ONLN);
process_config_int(ini, section, "ipport", &configs_dest[renderd_section_num].ipport, 0);
process_config_int(ini, section, "num_threads", &configs_dest[renderd_section_num].num_threads, NUM_THREADS);
process_config_string(ini, section, "iphostname", &configs_dest[renderd_section_num].iphostname, "", INILINE_MAX);
process_config_string(ini, section, "pid_file", &configs_dest[renderd_section_num].pid_filename, RENDERD_PIDFILE, PATH_MAX);
process_config_string(ini, section, "socketname", &configs_dest[renderd_section_num].socketname, RENDERD_SOCKET, PATH_MAX);
process_config_string(ini, section, "stats_file", &configs_dest[renderd_section_num].stats_filename, "", PATH_MAX);
process_config_string(ini, section, "tile_dir", &configs_dest[renderd_section_num].tile_dir, RENDERD_TILE_DIR, PATH_MAX);
if (configs_dest[renderd_section_num].num_threads == -1) {
configs_dest[renderd_section_num].num_threads = sysconf(_SC_NPROCESSORS_ONLN);
}
if (renderd_section_num == active_renderd_section_num) {
config = config_slaves[renderd_section_num];
} else {
num_slave_threads += config_slaves[renderd_section_num].num_threads;
}
}
}
g_logger(G_LOG_LEVEL_DEBUG, "Parsing mapnik config section");
for (int section_num = 0; section_num < iniparser_getnsec(ini); section_num++) {
const char *section = iniparser_getsecname(ini, section_num);
if (strcmp(section, "mapnik") == 0) {
/* this is a mapnik config section */
if (config.num_threads == 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "No valid (active) renderd config section available");
exit(7);
}
process_config_bool(ini, section, "font_dir_recurse", &config.mapnik_font_dir_recurse, MAPNIK_FONTS_DIR_RECURSE);
process_config_string(ini, section, "font_dir", &config.mapnik_font_dir, MAPNIK_FONTS_DIR, PATH_MAX - 1);
process_config_string(ini, section, "plugins_dir", &config.mapnik_plugins_dir, MAPNIK_PLUGINS_DIR, PATH_MAX - 1);
}
}
g_logger(G_LOG_LEVEL_DEBUG, "Parsing map config section(s)");
for (int section_num = 0; section_num < iniparser_getnsec(ini); section_num++) {
const char *section = iniparser_getsecname(ini, section_num);
if (strncmp(section, "renderd", 7) && strcmp(section, "mapnik")) {
/* this is a map config section */
if (config.num_threads == 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "No valid (active) renderd config section available");
exit(7);
}
map_section_num++;
g_logger(G_LOG_LEVEL_DEBUG, "Parsing map config section %i: %s", map_section_num, section);
if (map_section_num >= XMLCONFIGS_MAX) {
g_logger(G_LOG_LEVEL_CRITICAL, "Can't handle more than %i map config sections", XMLCONFIGS_MAX);
exit(7);
}
copy_string_with_snprintf(section, &maps[map_section_num].xmlname, XMLCONFIG_MAX - 1);
process_config_int(ini, section, "aspectx", &maps[map_section_num].aspect_x, 1);
process_config_int(ini, section, "aspecty", &maps[map_section_num].aspect_y, 1);
process_config_int(ini, section, "tilesize", &maps[map_section_num].tile_px_size, 256);
process_config_string(ini, section, "attribution", &maps[map_section_num].attribution, "", PATH_MAX - 1);
process_config_string(ini, section, "cors", &maps[map_section_num].cors, "", PATH_MAX - 1);
process_config_string(ini, section, "description", &maps[map_section_num].description, "", PATH_MAX - 1);
process_config_string(ini, section, "host", &maps[map_section_num].host, "", PATH_MAX - 1);
process_config_string(ini, section, "htcphost", &maps[map_section_num].htcpip, "", PATH_MAX - 1);
process_config_string(ini, section, "parameterize_style", &maps[map_section_num].parameterization, "", PATH_MAX - 1);
process_config_string(ini, section, "server_alias", &maps[map_section_num].server_alias, "", PATH_MAX - 1);
process_config_string(ini, section, "tiledir", &maps[map_section_num].tile_dir, config.tile_dir, PATH_MAX - 1);
process_config_string(ini, section, "uri", &maps[map_section_num].xmluri, "", PATH_MAX - 1);
process_config_string(ini, section, "xml", &maps[map_section_num].xmlfile, "", PATH_MAX - 1);
process_config_double(ini, section, "scale", &maps[map_section_num].scale_factor, 1.0);
if (maps[map_section_num].scale_factor < 0.1) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified scale factor (%lf) is too small, must be greater than or equal to %lf.", maps[map_section_num].scale_factor, 0.1);
exit(7);
} else if (maps[map_section_num].scale_factor > 8.0) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified scale factor (%lf) is too large, must be less than or equal to %lf.", maps[map_section_num].scale_factor, 8.0);
exit(7);
}
process_config_int(ini, section, "maxzoom", &maps[map_section_num].max_zoom, 18);
if (maps[map_section_num].max_zoom < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified max zoom (%i) is too small, must be greater than or equal to %i.", maps[map_section_num].max_zoom, 0);
exit(7);
} else if (maps[map_section_num].max_zoom > MAX_ZOOM) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified max zoom (%i) is too large, must be less than or equal to %i.", maps[map_section_num].max_zoom, MAX_ZOOM);
exit(7);
}
process_config_int(ini, section, "minzoom", &maps[map_section_num].min_zoom, 0);
if (maps[map_section_num].min_zoom < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified min zoom (%i) is too small, must be greater than or equal to %i.", maps[map_section_num].min_zoom, 0);
exit(7);
} else if (maps[map_section_num].min_zoom > maps[map_section_num].max_zoom) {
g_logger(G_LOG_LEVEL_CRITICAL, "Specified min zoom (%i) is larger than max zoom (%i).", maps[map_section_num].min_zoom, maps[map_section_num].max_zoom);
exit(7);
}
char ini_fileExtension[] = "png";
char ini_mimeType[] = "image/png";
char ini_outputFormat[] = "png256";
char *ini_type;
process_config_string(ini, section, "type", &ini_type, "png image/png png256", INILINE_MAX - 1);
sscanf(ini_type, "%[^ ] %[^ ] %[^;#]", ini_fileExtension, ini_mimeType, ini_outputFormat);
copy_string_with_snprintf(ini_outputFormat, &maps[map_section_num].output_format, INILINE_MAX - 1);
free(ini_type);
/* Pass this information into the rendering threads,
* as it is needed to configure mapniks number of connections
*/
maps[map_section_num].num_threads = config.num_threads;
}
}
iniparser_freedict(ini);
if (renderd_section_num < 0) {
g_logger(G_LOG_LEVEL_CRITICAL, "No renderd config sections were found in file: %s", config_file_name);
exit(1);
}
}
void process_config_file(const char *config_file_name, int active_renderd_section_num, int log_level)
{
extern int num_slave_threads;
extern renderd_config config;
extern renderd_config config_slaves[MAX_SLAVES];
extern xmlconfigitem maps[XMLCONFIGS_MAX];
num_slave_threads = 0;
g_logger(log_level, "Parsing renderd config file '%s':", config_file_name);
process_renderd_sections(config_file_name, config_slaves);
process_mapnik_section(config_file_name, &config_slaves[active_renderd_section_num]);
process_map_sections(config_file_name, maps, config_slaves[active_renderd_section_num].tile_dir, config_slaves[active_renderd_section_num].num_threads);
config = config_slaves[active_renderd_section_num];
for (int i = 0; i < MAX_SLAVES; i++) {
if (config_slaves[i].num_threads == 0) {
continue;
}
if (i == active_renderd_section_num) {
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): Active", i);
} else {
num_slave_threads += config_slaves[i].num_threads;
}
if (config_slaves[i].ipport > 0) {
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): ip socket = '%s:%i'", i, config_slaves[i].iphostname, config_slaves[i].ipport);
} else {
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): unix socketname = '%s'", i, config_slaves[i].socketname);
}
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): num_threads = '%i'", i, config_slaves[i].num_threads);
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): pid_file = '%s'", i, config_slaves[i].pid_filename);
if (strnlen(config_slaves[i].stats_filename, PATH_MAX)) {
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): stats_file = '%s'", i, config_slaves[i].stats_filename);
}
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): tile_dir = '%s'", i, config_slaves[i].tile_dir);
}
if (config.ipport > 0) {
g_logger(log_level, "\trenderd: ip socket = '%s':%i", config.iphostname, config.ipport);
} else {
@ -328,7 +437,7 @@ void process_config_file(const char *config_file_name, int active_renderd_sectio
g_logger(log_level, "\trenderd: pid_file = '%s'", config.pid_filename);
if (strnlen(config.stats_filename, PATH_MAX - 1)) {
if (strnlen(config.stats_filename, PATH_MAX)) {
g_logger(log_level, "\trenderd: stats_file = '%s'", config.stats_filename);
}
@ -337,34 +446,9 @@ void process_config_file(const char *config_file_name, int active_renderd_sectio
g_logger(log_level, "\tmapnik: font_dir_recurse = '%s'", config.mapnik_font_dir_recurse ? "true" : "false");
g_logger(log_level, "\tmapnik: plugins_dir = '%s'", config.mapnik_plugins_dir);
for (i = 0; i < XMLCONFIGS_MAX; i++) {
for (int i = 0; i < XMLCONFIGS_MAX; i++) {
if (maps[i].xmlname != NULL) {
g_logger(log_level, "\tmap %i: name(%s) file(%s) uri(%s) output_format(%s) htcp(%s) host(%s)", i, maps[i].xmlname, maps[i].xmlfile, maps[i].xmluri, maps[i].output_format, maps[i].htcpip, maps[i].host);
}
}
for (i = 0; i < MAX_SLAVES; i++) {
if (config_slaves[i].num_threads == 0) {
continue;
}
if (i == active_renderd_section_num) {
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): Active", i);
}
if (config_slaves[i].ipport > 0) {
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): ip socket = '%s:%i'", i, config_slaves[i].iphostname, config_slaves[i].ipport);
} else {
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): unix socketname = '%s'", i, config_slaves[i].socketname);
}
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): num_threads = '%i'", i, config_slaves[i].num_threads);
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): pid_file = '%s'", i, config_slaves[i].pid_filename);
if (strnlen(config_slaves[i].stats_filename, PATH_MAX - 1)) {
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): stats_file = '%s'", i, config_slaves[i].stats_filename);
}
g_logger(G_LOG_LEVEL_DEBUG, "\trenderd(%i): tile_dir = '%s'", i, config_slaves[i].tile_dir);
}
}

View File

@ -252,7 +252,7 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
${PS_EXECUTABLE} -p \${PID} || exit 1\;
echo \${PID} > ${RENDERD1_PID}"
"$<TARGET_FILE:renderd> --config ${RENDERD_CONF} --slave 2"
"${HTTPD_EXECUTABLE} -e debug -f ${HTTPD_CONF} -k start > ${HTTPD_LOG} 2>&1"
"${HTTPD_EXECUTABLE} -e debug -E ${HTTPD_LOG} -f ${HTTPD_CONF} -k start"
)
# Conditionally append memcached start commands to SERVICES_START_CMDS based on STORAGE_BACKEND value
@ -647,13 +647,17 @@ foreach(STORAGE_BACKEND_INDEX RANGE ${STORAGE_BACKENDS_LENGTH})
set_tests_properties(tile_expired_${MAP_NAME}_${STORAGE_BACKEND} PROPERTIES
FIXTURES_REQUIRED services_started_${STORAGE_BACKEND}
)
set(TILE_URL_PATH "/tiles/${MAP_NAME}/3/0/3.${EXTENSION}")
set(HTTPD1_URL "http://${HTTPD1_HOST}:${HTTPD1_PORT}${TILE_URL_PATH}")
set(HTTPD2_URL "http://${HTTPD2_HOST}:${HTTPD2_PORT}${TILE_URL_PATH}")
add_test(NAME throttling_xforward_${MAP_NAME}_${STORAGE_BACKEND}
COMMAND ${BASH} -c "
TEST_CURL_CMD=\"${CURL_CMD} --header 'X-Forwarded-For: ${CTEST_HOST}, 127.0.0.1' --output /dev/null\"
for i in {0..10}; do
if ! ${CURL_CMD} --header \"X-Forwarded-For: ${CTEST_HOST}, ${CTEST_HOST}\" --output /dev/null ${HTTPD1_URL}; then
if ! \${TEST_CURL_CMD} ${HTTPD1_URL}; then
echo \"${HTTPD1_URL}\";
fi
if ! ${CURL_CMD} --header \"X-Forwarded-For: ${CTEST_HOST}, ${CTEST_HOST}\" --output /dev/null ${HTTPD2_URL}; then
if ! \${TEST_CURL_CMD} ${HTTPD2_URL}; then
echo \"${HTTPD2_URL}\";
fi
done
@ -977,6 +981,7 @@ foreach(DIRECTIVE_INDEX RANGE ${DIRECTIVES_LENGTH})
HTTPD_OUTPUT=$(${HTTPD_EXECUTABLE} -e debug -f ${HTTPD_CONF} -t 2>&1)
if [ \"\${?}\" -eq \"0\" ]; then
echo \"Unexpected success.\"
echo \"\${HTTPD_OUTPUT}\"
exit 1;
fi
if echo \"\${HTTPD_OUTPUT}\" | ${GREP_EXECUTABLE} -q \"${DIRECTIVE_ERROR}\"; then

View File

@ -88,8 +88,8 @@ Redirect /renderd-example-map/leaflet/leaflet.min.js https://unpkg.com/leaflet/d
ModTileMissingRequestTimeout 3
ModTileRenderdSocketName @RENDERD2_SOCKET@
ModTileRequestTimeout 3
ModTileThrottlingRenders 128 0.2
ModTileThrottlingTiles 10000 1
ModTileThrottlingRenders 1 0.2
ModTileThrottlingTiles 1 1
ModTileTileDir @TILE_DIR@
ModTileVeryOldThreshold -10000000
</VirtualHost>

View File

@ -53,7 +53,8 @@ XML=@PROJECT_SOURCE_DIR@/utils/example-map/mapnik.xml
[@DEFAULT_MAP_NAME@_parameterization]
PARAMETERIZE_STYLE=language
TILEDIR=@TILE_DIR@
URI=/tiles/parameterization/
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