|
mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
|
#include <glib.h>#include <limits.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <sys/un.h>#include <unistd.h>#include "config.h"#include "g_logger.h"#include "protocol.h"#include "render_config.h"#include "renderd.h"#include <iniparser.h>Macros | |
| #define | _GNU_SOURCE |
| #define | INIPARSER_DICT_CAST(d) |
| Pass a const dictionary * directly to const-correct iniparser functions. | |
| #define | INIPARSER_STR_CAST(s) |
| Pass a const char * directly to const-correct iniparser functions. | |
Functions | |
| static void | copy_string (const char *src, const char **dest, size_t maxlen) |
| Duplicate up to maxlen bytes of src onto the heap and store in *dest. | |
| static char * | name_with_section (const char *section, const char *name) |
| Format an iniparser lookup key as "<section>:<name>". | |
| static void | process_config_bool (const dictionary *ini, const char *section, const char *name, int *dest, int notfound) |
| Read a boolean configuration value from an INI dictionary. | |
| static void | process_config_double (const dictionary *ini, const char *section, const char *name, double *dest, double notfound) |
| Read a floating-point (double) configuration value from an INI dictionary. | |
| static void | process_config_int (const dictionary *ini, const char *section, const char *name, int *dest, int notfound) |
| Read an integer configuration value from an INI dictionary. | |
| static void | process_config_string (const dictionary *ini, const char *section, const char *name, const char **dest, const char *notfound, size_t maxlen) |
| Read a string configuration value from an INI dictionary and duplicate it onto the heap. | |
| static void | process_config_string_with_trailing_slash (const dictionary *ini, const char *section, const char *name, const char **dest, const char *notfound, size_t maxlen) |
| Read a string configuration value and guarantee it ends with a trailing '/'. | |
| void | free_map_section (xmlconfigitem *map_section) |
| Free all heap-allocated string fields inside a single xmlconfigitem and zero the struct. | |
| void | free_map_sections (xmlconfigitem *map_sections) |
| Free all populated entries in an array of XMLCONFIGS_MAX map configurations. | |
| void | free_renderd_section (renderd_config *renderd_section) |
| Free all heap-allocated string fields inside a single renderd_config and zero the struct. | |
| void | free_renderd_sections (renderd_config *renderd_sections) |
| Free all populated entries in an array of MAX_SLAVES renderd instance configurations. | |
| double | min_max_double_opt (const char *opt_arg, const char *opt_type_name, double minimum, double maximum) |
| Parse and validate a double command-line or config option against optional bounds. | |
| int | min_max_int_opt (const char *opt_arg, const char *opt_type_name, int minimum, int maximum) |
| Parse and validate an int command-line or config option against optional bounds. | |
| void | process_map_sections (const dictionary *ini, const char *config_file_name, xmlconfigitem *maps_dest, const char *default_tile_dir, int num_threads) |
| Parse all map style sections from a renderd.conf INI file into maps_dest[]. | |
| void | process_mapnik_section (const dictionary *ini, const char *config_file_name, renderd_config *config_dest) |
| Parse the [mapnik] section from a renderd.conf INI file into config_dest. | |
| void | process_renderd_sections (const dictionary *ini, const char *config_file_name, renderd_config *configs_dest) |
| Parse all [renderd] and [renderdN] sections from a renderd.conf INI file. | |
| void | process_config_file (const char *config_file_name, int active_renderd_section_num, int log_level) |
| Load and parse a complete renderd.conf file and populate global configuration state. | |
Variables | |
| int | num_maps = 0 |
| Total number of map style sections parsed into maps[]. | |
| int | num_slave_threads = 0 |
| Sum of num_threads across all inactive (slave) [renderdN] sections. | |
| renderd_config * | config |
| Pointer to the active renderd_config entry inside config_slaves[]. | |
| renderd_config | config_slaves [MAX_SLAVES] |
| Array of parsed [renderd] / [renderdN] instance configurations indexed by section number. | |
| xmlconfigitem | maps [XMLCONFIGS_MAX] |
| Array of parsed map style configurations ([default], etc.) up to XMLCONFIGS_MAX. | |
| #define _GNU_SOURCE |
| #define INIPARSER_DICT_CAST | ( | d | ) |
Pass a const dictionary * directly to const-correct iniparser functions.
| #define INIPARSER_STR_CAST | ( | s | ) |
Pass a const char * directly to const-correct iniparser functions.
|
static |
Duplicate up to maxlen bytes of src onto the heap and store in *dest.
Logs a critical error and terminates with exit code 7 if strndup() fails.
| src | Source null-terminated string to copy. |
| dest | Output pointer receiving the newly allocated string. |
| maxlen | Maximum number of characters to copy from src. |
| void free_map_section | ( | xmlconfigitem * | map_section | ) |
Free all heap-allocated string fields inside a single xmlconfigitem and zero the struct.
| map_section | Pointer to the xmlconfigitem structure to release. |
| void free_map_sections | ( | xmlconfigitem * | map_sections | ) |
Free all populated entries in an array of XMLCONFIGS_MAX map configurations.
| map_sections | Array of xmlconfigitem structures (XMLCONFIGS_MAX elements). |
| void free_renderd_section | ( | renderd_config * | renderd_section | ) |
Free all heap-allocated string fields inside a single renderd_config and zero the struct.
| renderd_section | Pointer to the renderd_config structure to release. |
| void free_renderd_sections | ( | renderd_config * | renderd_sections | ) |
Free all populated entries in an array of MAX_SLAVES renderd instance configurations.
| renderd_sections | Array of renderd_config structures (MAX_SLAVES elements). |
| double min_max_double_opt | ( | const char * | opt_arg, |
| const char * | opt_type_name, | ||
| double | minimum, | ||
| double | maximum ) |
Parse and validate a double command-line or config option against optional bounds.
Terminates the process with exit(1) if opt_arg cannot be parsed as a floating-point number or violates [minimum, maximum] (where -1 disables the corresponding bound check).
| opt_arg | Input string to parse as a double. |
| opt_type_name | Descriptive option name used in error log messages. |
| minimum | Inclusive lower bound, or -1 to skip lower-bound validation. |
| maximum | Inclusive upper bound, or -1 to skip upper-bound validation. |
| int min_max_int_opt | ( | const char * | opt_arg, |
| const char * | opt_type_name, | ||
| int | minimum, | ||
| int | maximum ) |
Parse and validate an int command-line or config option against optional bounds.
Rejects non-numeric strings as well as fractional numbers (by comparing strtol() and strtof() results), and enforces [minimum, maximum] (where -1 disables a bound check). Terminates with exit(1) on invalid input.
| opt_arg | Input string to parse as an int. |
| opt_type_name | Descriptive option name used in error log messages. |
| minimum | Inclusive lower bound, or -1 to skip lower-bound validation. |
| maximum | Inclusive upper bound, or -1 to skip upper-bound validation. |
|
static |
Format an iniparser lookup key as "<section>:<name>".
Allocates the combined key string on the heap (caller must free()). Exits with code 7 if section or name is NULL or if asprintf() fails.
| section | INI section name (e.g., "renderd"). |
| name | INI key name within the section (e.g., "num_threads"). |
|
static |
Read a boolean configuration value from an INI dictionary.
| ini | Parsed iniparser dictionary. |
| section | INI section name. |
| name | INI option name. |
| dest | Output integer receiving 1 (true) or 0 (false). |
| notfound | Default boolean value returned if the key is absent. |
|
static |
Read a floating-point (double) configuration value from an INI dictionary.
| ini | Parsed iniparser dictionary. |
| section | INI section name. |
| name | INI option name. |
| dest | Output double receiving the parsed value. |
| notfound | Default double value returned if the key is absent. |
| void process_config_file | ( | const char * | config_file_name, |
| int | active_renderd_section_num, | ||
| int | log_level ) |
Load and parse a complete renderd.conf file and populate global configuration state.
Orchestrates parsing of [renderd*] sections into config_slaves[], selects config = &config_slaves[active_renderd_section_num], parses [mapnik] into the active config, parses all map sections into maps[], totals num_slave_threads across non-active instances, and logs the effective runtime configuration.
| config_file_name | Filesystem path to renderd.conf. |
| active_renderd_section_num | Index (0 .. MAX_SLAVES - 1) of the [renderd*] section this process instance should run as. |
| log_level | GLib log level used to emit the parsed configuration summary. |
|
static |
Read an integer configuration value from an INI dictionary.
| ini | Parsed iniparser dictionary. |
| section | INI section name. |
| name | INI option name. |
| dest | Output integer receiving the parsed value. |
| notfound | Default integer value returned if the key is absent. |
|
static |
Read a string configuration value from an INI dictionary and duplicate it onto the heap.
| ini | Parsed iniparser dictionary. |
| section | INI section name. |
| name | INI option name. |
| dest | Output pointer receiving the heap-allocated copy of the string. |
| notfound | Default fallback string if the key is absent. |
| maxlen | Maximum byte length to copy via copy_string(). |
|
static |
Read a string configuration value and guarantee it ends with a trailing '/'.
Used for URI path prefixes (uri) so tile paths can be concatenated directly. If the configured value is empty or does not end with '/', appends '/' before copying to *dest.
| ini | Parsed iniparser dictionary. |
| section | INI section name. |
| name | INI option name. |
| dest | Output pointer receiving the heap-allocated slash-terminated string. |
| notfound | Default fallback string if the key is absent. |
| maxlen | Maximum byte length to copy via copy_string(). |
| void process_map_sections | ( | const dictionary * | ini, |
| const char * | config_file_name, | ||
| xmlconfigitem * | maps_dest, | ||
| const char * | default_tile_dir, | ||
| int | num_threads ) |
Parse all map style sections from a renderd.conf INI file into maps_dest[].
Treats every INI section whose name neither starts with "renderd" nor equals "mapnik" as a map configuration section. Parses tile dimensions, zoom range (0..MAX_ZOOM), scale factor (0.1..8.0), paths, HTCP settings, and space-delimited type (<ext> <mime> [format]), then verifies that at least one map exists and no earlier map's xmluri is a prefix of a later map's xmluri. Updates the global num_maps counter.
| ini | Pre-loaded iniparser dictionary, or NULL to load config_file_name locally. |
| config_file_name | Path to the configuration file (used for loading if ini == NULL and in logs). |
| maps_dest | Destination array of XMLCONFIGS_MAX xmlconfigitem entries. |
| default_tile_dir | Fallback tile directory inherited from the active [renderd] section. |
| num_threads | Active worker thread count propagated to each xmlconfigitem. |
| void process_mapnik_section | ( | const dictionary * | ini, |
| const char * | config_file_name, | ||
| renderd_config * | config_dest ) |
Parse the [mapnik] section from a renderd.conf INI file into config_dest.
Extracts font_dir_recurse, font_dir, and plugins_dir. Exits with code 1 if the [mapnik] section is missing.
| ini | Pre-loaded iniparser dictionary, or NULL to load config_file_name locally. |
| config_file_name | Path to the configuration file (used for loading if ini == NULL and in logs). |
| config_dest | Destination renderd_config structure receiving the Mapnik paths. |
| void process_renderd_sections | ( | const dictionary * | ini, |
| const char * | config_file_name, | ||
| renderd_config * | configs_dest ) |
Parse all [renderd] and [renderdN] sections from a renderd.conf INI file.
Maps [renderd] and [renderd0] to index 0, and [renderdN] (1 <= N < MAX_SLAVES) to index N in configs_dest[]. Resolves num_threads = -1 to the online CPU core count (sysconf(_SC_NPROCESSORS_ONLN)), validates Unix socket path length against sockaddr_un.sun_path, and rejects duplicate or out-of-range section indices.
| ini | Pre-loaded iniparser dictionary, or NULL to load config_file_name locally. |
| config_file_name | Path to the configuration file (used for loading if ini == NULL and in logs). |
| configs_dest | Destination array of MAX_SLAVES renderd_config entries. |
| renderd_config* config |
Pointer to the active renderd_config entry inside config_slaves[].
| renderd_config config_slaves[MAX_SLAVES] |
Array of parsed [renderd] / [renderdN] instance configurations indexed by section number.
| xmlconfigitem maps[XMLCONFIGS_MAX] |
Array of parsed map style configurations ([default], etc.) up to XMLCONFIGS_MAX.
| int num_maps = 0 |
Total number of map style sections parsed into maps[].
| int num_slave_threads = 0 |
Sum of num_threads across all inactive (slave) [renderdN] sections.