mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
Loading...
Searching...
No Matches
renderd_config.c File Reference
#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.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

◆ INIPARSER_DICT_CAST

#define INIPARSER_DICT_CAST ( d)
Value:
(d)

Pass a const dictionary * directly to const-correct iniparser functions.

◆ INIPARSER_STR_CAST

#define INIPARSER_STR_CAST ( s)
Value:
(s)

Pass a const char * directly to const-correct iniparser functions.

Function Documentation

◆ copy_string()

void copy_string ( const char * src,
const char ** dest,
size_t maxlen )
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.

Parameters
srcSource null-terminated string to copy.
destOutput pointer receiving the newly allocated string.
maxlenMaximum number of characters to copy from src.

◆ free_map_section()

void free_map_section ( xmlconfigitem * map_section)

Free all heap-allocated string fields inside a single xmlconfigitem and zero the struct.

Parameters
map_sectionPointer to the xmlconfigitem structure to release.

◆ free_map_sections()

void free_map_sections ( xmlconfigitem * map_sections)

Free all populated entries in an array of XMLCONFIGS_MAX map configurations.

Parameters
map_sectionsArray of xmlconfigitem structures (XMLCONFIGS_MAX elements).

◆ free_renderd_section()

void free_renderd_section ( renderd_config * renderd_section)

Free all heap-allocated string fields inside a single renderd_config and zero the struct.

Parameters
renderd_sectionPointer to the renderd_config structure to release.

◆ free_renderd_sections()

void free_renderd_sections ( renderd_config * renderd_sections)

Free all populated entries in an array of MAX_SLAVES renderd instance configurations.

Parameters
renderd_sectionsArray of renderd_config structures (MAX_SLAVES elements).

◆ min_max_double_opt()

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).

Parameters
opt_argInput string to parse as a double.
opt_type_nameDescriptive option name used in error log messages.
minimumInclusive lower bound, or -1 to skip lower-bound validation.
maximumInclusive upper bound, or -1 to skip upper-bound validation.
Returns
Parsed and validated double value.

◆ min_max_int_opt()

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.

Parameters
opt_argInput string to parse as an int.
opt_type_nameDescriptive option name used in error log messages.
minimumInclusive lower bound, or -1 to skip lower-bound validation.
maximumInclusive upper bound, or -1 to skip upper-bound validation.
Returns
Parsed and validated integer value.

◆ name_with_section()

char * name_with_section ( const char * section,
const char * name )
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.

Parameters
sectionINI section name (e.g., "renderd").
nameINI key name within the section (e.g., "num_threads").
Returns
Heap-allocated "section:name" key string.

◆ process_config_bool()

void process_config_bool ( const dictionary * ini,
const char * section,
const char * name,
int * dest,
int notfound )
static

Read a boolean configuration value from an INI dictionary.

Parameters
iniParsed iniparser dictionary.
sectionINI section name.
nameINI option name.
destOutput integer receiving 1 (true) or 0 (false).
notfoundDefault boolean value returned if the key is absent.

◆ process_config_double()

void process_config_double ( const dictionary * ini,
const char * section,
const char * name,
double * dest,
double notfound )
static

Read a floating-point (double) configuration value from an INI dictionary.

Parameters
iniParsed iniparser dictionary.
sectionINI section name.
nameINI option name.
destOutput double receiving the parsed value.
notfoundDefault double value returned if the key is absent.

◆ process_config_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.

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.

Parameters
config_file_nameFilesystem path to renderd.conf.
active_renderd_section_numIndex (0 .. MAX_SLAVES - 1) of the [renderd*] section this process instance should run as.
log_levelGLib log level used to emit the parsed configuration summary.

◆ process_config_int()

void process_config_int ( const dictionary * ini,
const char * section,
const char * name,
int * dest,
int notfound )
static

Read an integer configuration value from an INI dictionary.

Parameters
iniParsed iniparser dictionary.
sectionINI section name.
nameINI option name.
destOutput integer receiving the parsed value.
notfoundDefault integer value returned if the key is absent.

◆ process_config_string()

void process_config_string ( const dictionary * ini,
const char * section,
const char * name,
const char ** dest,
const char * notfound,
size_t maxlen )
static

Read a string configuration value from an INI dictionary and duplicate it onto the heap.

Parameters
iniParsed iniparser dictionary.
sectionINI section name.
nameINI option name.
destOutput pointer receiving the heap-allocated copy of the string.
notfoundDefault fallback string if the key is absent.
maxlenMaximum byte length to copy via copy_string().

◆ process_config_string_with_trailing_slash()

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 )
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.

Parameters
iniParsed iniparser dictionary.
sectionINI section name.
nameINI option name.
destOutput pointer receiving the heap-allocated slash-terminated string.
notfoundDefault fallback string if the key is absent.
maxlenMaximum byte length to copy via copy_string().

◆ process_map_sections()

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.

Parameters
iniPre-loaded iniparser dictionary, or NULL to load config_file_name locally.
config_file_namePath to the configuration file (used for loading if ini == NULL and in logs).
maps_destDestination array of XMLCONFIGS_MAX xmlconfigitem entries.
default_tile_dirFallback tile directory inherited from the active [renderd] section.
num_threadsActive worker thread count propagated to each xmlconfigitem.

◆ process_mapnik_section()

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.

Parameters
iniPre-loaded iniparser dictionary, or NULL to load config_file_name locally.
config_file_namePath to the configuration file (used for loading if ini == NULL and in logs).
config_destDestination renderd_config structure receiving the Mapnik paths.

◆ process_renderd_sections()

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.

Parameters
iniPre-loaded iniparser dictionary, or NULL to load config_file_name locally.
config_file_namePath to the configuration file (used for loading if ini == NULL and in logs).
configs_destDestination array of MAX_SLAVES renderd_config entries.

Variable Documentation

◆ config

renderd_config* config

Pointer to the active renderd_config entry inside config_slaves[].

◆ config_slaves

renderd_config config_slaves[MAX_SLAVES]

Array of parsed [renderd] / [renderdN] instance configurations indexed by section number.

◆ maps

Array of parsed map style configurations ([default], etc.) up to XMLCONFIGS_MAX.

◆ num_maps

int num_maps = 0

Total number of map style sections parsed into maps[].

◆ num_slave_threads

int num_slave_threads = 0

Sum of num_threads across all inactive (slave) [renderdN] sections.