|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|