navit  0.5.3-trunk
xmlconfig.c File Reference
#include <stdlib.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <string.h>
#include <ctype.h>
#include "debug.h"
#include "file.h"
#include "coord.h"
#include "item.h"
#include "xmlconfig.h"
#include "layout.h"
#include "mapset.h"
#include "projection.h"
#include "map.h"
#include "navigation.h"
#include "navit.h"
#include "plugin.h"
#include "route.h"
#include "speech.h"
#include "track.h"
#include "vehicle.h"
#include "point.h"
#include "graphics.h"
#include "gui.h"
#include "osd.h"
#include "log.h"
#include "announcement.h"
#include "vehicleprofile.h"
#include "callback.h"
#include "config_.h"

Data Structures

struct  xistate
 
struct  xmldocument
 
struct  xmlstate
 
struct  attr_fixme
 
struct  element_func
 
struct  attr_iter
 

Macros

#define NEW(x)   (void *(*)(struct attr *, struct attr **))(x)
 
#define GET(x)   (int (*)(void *, enum attr_type type, struct attr *attr, struct attr_iter *iter))(x)
 
#define ITERN(x)   (struct attr_iter * (*)(void *))(x)
 
#define ITERD(x)   (void (*)(struct attr_iter *iter))(x)
 
#define SET(x)   (int (*)(void *, struct attr *attr))(x)
 
#define ADD(x)   (int (*)(void *, struct attr *attr))(x)
 
#define REMOVE(x)   (int (*)(void *, struct attr *attr))(x)
 
#define INIT(x)   (int (*)(void *))(x)
 
#define DESTROY(x)   (void (*)(void *))(x)
 

Functions

static struct attr ** convert_to_attrs (struct xmlstate *state, struct attr_fixme *fixme)
 
static const char * find_attribute (struct xmlstate *state, const char *attribute, int required)
 
static int find_boolean (struct xmlstate *state, const char *attribute, int deflt, int required)
 
static int convert_number (const char *val)
 
static int xmlconfig_announce (struct xmlstate *state)
 
struct object_funcobject_func_lookup (enum attr_type type)
 
static void initStatic (void)
 
static void start_element (xml_context *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, xmlerror **error)
 
static void end_element (xml_context *context, const gchar *element_name, gpointer user_data, xmlerror **error)
 
static gboolean parse_file (struct xmldocument *document, xmlerror **error)
 
static void xinclude (xml_context *context, const gchar **attribute_names, const gchar **attribute_values, struct xmldocument *doc_old, xmlerror **error)
 Handle xi:include XML tags. More...
 
static int strncmp_len (const char *s1, int s1len, const char *s2)
 
static int xpointer_value (const char *test, int len, struct xistate *elem, const char **out, int out_len)
 
static int xpointer_test (const char *test, int len, struct xistate *elem)
 
static int xpointer_element_match (const char *xpointer, int len, struct xistate *elem)
 
static int xpointer_xpointer_match (const char *xpointer, int len, struct xistate *first)
 
static int xpointer_match (const char *xpointer, struct xistate *first)
 
static void xi_start_element (xml_context *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, xmlerror **error)
 
static void xi_end_element (xml_context *context, const gchar *element_name, gpointer user_data, xmlerror **error)
 
static void xi_text (xml_context *context, const gchar *text, gsize text_len, gpointer user_data, xmlerror **error)
 
static void parse_node_text (ezxml_t node, void *data, void(*start)(void *, const char *, const char **, const char **, void *, void *), void(*end)(void *, const char *, void *, void *), void(*text)(void *, const char *, int, void *, void *))
 
int xml_parse_file (char *filename, void *data, void(*start)(xml_context *, const char *, const char **, const char **, void *, GError **), void(*end)(xml_context *, const char *, void *, GError **), void(*text)(xml_context *, const char *, gsize, void *, GError **))
 Parses an XML file. More...
 
int xml_parse_text (const char *document, void *data, void(*start)(xml_context *, const char *, const char **, const char **, void *, GError **), void(*end)(xml_context *, const char *, void *, GError **), void(*text)(xml_context *, const char *, gsize, void *, GError **))
 Parses XML text. More...
 
static void parse_node (struct xmldocument *document, ezxml_t node)
 
gboolean config_load (const char *filename, xmlerror **error)
 
int navit_object_set_methods (void *in, int in_size, void *out, int out_size)
 
struct navit_objectnavit_object_new (struct attr **attrs, struct object_func *func, int size)
 
struct navit_objectnavit_object_ref (struct navit_object *obj)
 
void * navit_object_unref (struct navit_object *obj)
 
struct attr_iternavit_object_attr_iter_new (void *unused)
 
void navit_object_attr_iter_destroy (struct attr_iter *iter)
 
int navit_object_get_attr (struct navit_object *obj, enum attr_type type, struct attr *attr, struct attr_iter *iter)
 Generic get function. More...
 
void navit_object_callbacks (struct navit_object *obj, struct attr *attr)
 
int navit_object_set_attr (struct navit_object *obj, struct attr *attr)
 
int navit_object_add_attr (struct navit_object *obj, struct attr *attr)
 
int navit_object_remove_attr (struct navit_object *obj, struct attr *attr)
 
void navit_object_destroy (struct navit_object *obj)
 

Variables

static struct object_func object_funcs []
 
struct element_funcelements
 
static char * attr_fixme_itemgra []
 
static char * attr_fixme_text []
 
static char * attr_fixme_circle []
 
static struct attr_fixme attr_fixmes []
 
static char * element_fixmes []
 

Macro Definition Documentation

◆ ADD

#define ADD (   x)    (int (*)(void *, struct attr *attr))(x)

◆ DESTROY

#define DESTROY (   x)    (void (*)(void *))(x)

◆ GET

#define GET (   x)    (int (*)(void *, enum attr_type type, struct attr *attr, struct attr_iter *iter))(x)

◆ INIT

#define INIT (   x)    (int (*)(void *))(x)

◆ ITERD

#define ITERD (   x)    (void (*)(struct attr_iter *iter))(x)

◆ ITERN

#define ITERN (   x)    (struct attr_iter * (*)(void *))(x)

◆ NEW

#define NEW (   x)    (void *(*)(struct attr *, struct attr **))(x)
  • Define the elements in our config

◆ REMOVE

#define REMOVE (   x)    (int (*)(void *, struct attr *attr))(x)

◆ SET

#define SET (   x)    (int (*)(void *, struct attr *attr))(x)

Function Documentation

◆ config_load()

gboolean config_load ( const char *  filename,
xmlerror **  error 
)
  • Load and parse the master config file
  • Parameters
    filenameFQFN of the file
  • Parameters
    errorptr to error details, if any
  • Returns
    boolean TRUE or FALSE (if error detected)

References attr_create_hash(), attr_destroy_hash(), dbg, xmlstate::document, xmlstate::element, filename, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE, xmldocument::href, initStatic(), item_create_hash(), item_destroy_hash(), lvl_debug, parse_file(), and xmldocument::user_data.

Referenced by config_load_py(), and main_real().

◆ convert_number()

static int convert_number ( const char *  val)
static
  • Convert a string number to int
  • Parameters
    valthe string value to convert
  • Returns
    int value of converted string

◆ convert_to_attrs()

static struct attr** convert_to_attrs ( struct xmlstate state,
struct attr_fixme fixme 
)
static

◆ end_element()

static void end_element ( xml_context context,
const gchar *  element_name,
gpointer  user_data,
xmlerror **  error 
)
static

◆ find_attribute()

static const char* find_attribute ( struct xmlstate state,
const char *  attribute,
int  required 
)
static

◆ find_boolean()

static int find_boolean ( struct xmlstate state,
const char *  attribute,
int  deflt,
int  required 
)
static

References find_attribute(), and value.

Referenced by start_element().

◆ initStatic()

static void initStatic ( void  )
static

◆ navit_object_add_attr()

◆ navit_object_attr_iter_destroy()

void navit_object_attr_iter_destroy ( struct attr_iter iter)

References attr_iter::iter.

Referenced by config_attr_iter_destroy().

◆ navit_object_attr_iter_new()

struct attr_iter* navit_object_attr_iter_new ( void *  unused)

Referenced by config_attr_iter_new().

◆ navit_object_callbacks()

void navit_object_callbacks ( struct navit_object obj,
struct attr attr 
)

◆ navit_object_destroy()

void navit_object_destroy ( struct navit_object obj)

References attr_list_free().

Referenced by speech_destroy(), and traffic_new().

◆ navit_object_get_attr()

int navit_object_get_attr ( struct navit_object obj,
enum attr_type  type,
struct attr attr,
struct attr_iter iter 
)

Generic get function.

This function searches an attribute list for an attribute of a given type and stores it in the

Definition: attr.h:157

parameter. Internally it calls attr_generic_get_attr(struct attr **, struct attr **, enum attr_type, struct attr *, struct attr_iter *) to retrieve the attribute; see its documentation for details.

Searching for attr_any or attr_any_xml is supported.

An iterator can be specified to get multiple attributes of the same type: The first call will return the first match; each subsequent call with the same iterator will return the next match. If no more matching attributes are found in either of them, false is returned.

Parameters
objThe object to return an attribute for. This can be any Navit object type, but the parameter should be cast to
struct navit_object *
Definition: xmlconfig.h:122
to avoid compiler warnings.
typeThe attribute type to search for. Searching for
attr_any
or
attr_any_xml
is possible.
attrPoints to a
struct attr
which will receive the attribute
iterAn iterator to receive multiple attributes of the same type with subsequent calls. If
NULL
, the first matching attribute will be retrieved.
Returns
True if a matching attribute was found, false if not.

References attr_generic_get_attr(), attr_iter::iter, and type.

Referenced by navigation_get_attr(), navit_get_attr(), and osd_get_attr().

◆ navit_object_new()

struct navit_object* navit_object_new ( struct attr **  attrs,
struct object_func func,
int  size 
)

◆ navit_object_ref()

◆ navit_object_remove_attr()

int navit_object_remove_attr ( struct navit_object obj,
struct attr attr 
)

◆ navit_object_set_attr()

◆ navit_object_set_methods()

int navit_object_set_methods ( void *  in,
int  in_size,
void *  out,
int  out_size 
)

References size.

Referenced by osd_set_methods().

◆ navit_object_unref()

void* navit_object_unref ( struct navit_object obj)

References attr_to_name(), dbg, and lvl_debug.

Referenced by layer_set_attr_do().

◆ object_func_lookup()

◆ parse_file()

static gboolean parse_file ( struct xmldocument document,
xmlerror **  error 
)
static

◆ parse_node()

static void parse_node ( struct xmldocument document,
ezxml_t  node 
)
static

References xi_end_element(), xi_start_element(), and xi_text().

Referenced by parse_file().

◆ parse_node_text()

static void parse_node_text ( ezxml_t  node,
void *  data,
void(*)(void *, const char *, const char **, const char **, void *, void *)  start,
void(*)(void *, const char *, void *, void *)  end,
void(*)(void *, const char *, int, void *, void *)  text 
)
static

References data, and attr::text.

Referenced by xml_parse_file(), and xml_parse_text().

◆ start_element()

static void start_element ( xml_context context,
const gchar *  element_name,
const gchar **  attribute_names,
const gchar **  attribute_values,
gpointer  user_data,
xmlerror **  error 
)
static
  • Parse the opening tag of a config element
  • Parameters
    contextdocument parse context
  • Parameters
    element_namethe current tag name
  • Parameters
    attribute_namesptr to return the set of attribute names
  • Parameters
    attribute_valuesptr return the set of attribute values
  • Parameters
    user_dataptr to xmlstate structure
  • Parameters
    errorptr return error context
  • Returns
    nothing

References attr_fixmes, attr_from_name(), attr::attrs, convert_to_attrs(), attr::data, dbg, element_fixmes, elements, find_boolean(), element_func::func, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, G_MARKUP_ERROR_UNKNOWN_ELEMENT, lvl_error, lvl_info, element_func::name, object_func_lookup(), element_func::parent, and attr::u.

Referenced by xi_start_element().

◆ strncmp_len()

static int strncmp_len ( const char *  s1,
int  s1len,
const char *  s2 
)
static

References s1.

Referenced by xpointer_element_match(), xpointer_test(), and xpointer_value().

◆ xi_end_element()

static void xi_end_element ( xml_context context,
const gchar *  element_name,
gpointer  user_data,
xmlerror **  error 
)
static
  • Reached closing tag of a config element
  • Parameters
    context
  • Parameters
    elementname
  • Parameters
    user_dataptr to xmldocument
  • Parameters
    errorptr to struct for error information
  • Returns
    nothing

References xmldocument::active, xistate::attribute_names, xistate::attribute_values, xistate::child, end_element(), xmldocument::first, xmldocument::last, xistate::parent, and xmldocument::user_data.

Referenced by parse_node().

◆ xi_start_element()

static void xi_start_element ( xml_context context,
const gchar *  element_name,
const gchar **  attribute_names,
const gchar **  attribute_values,
gpointer  user_data,
xmlerror **  error 
)
static

◆ xi_text()

static void xi_text ( xml_context context,
const gchar *  text,
gsize  text_len,
gpointer  user_data,
xmlerror **  error 
)
static

◆ xinclude()

static void xinclude ( xml_context context,
const gchar **  attribute_names,
const gchar **  attribute_values,
struct xmldocument doc_old,
xmlerror **  error 
)
static

Handle xi:include XML tags.

Parameters
contextThe XML context in which we are parsing
[in]attribute_namesAn array of strings containing all XML attributes of the xi:include tag
[in]attribute_valuesAn array of strings containing all XML values (one per entry in attribute_names)
doc_oldThe current document being parsed (before moving to the one referenced in this xi:include
[out]errorA description of the error encountered if any

References dbg, file_exists(), file_is_dir(), file_wordexp_destroy(), file_wordexp_get_array(), file_wordexp_get_count(), file_wordexp_new(), G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, xmldocument::href, xmldocument::level, lvl_debug, lvl_error, parse_file(), xmldocument::user_data, file_wordexp::we, and xmldocument::xpointer.

Referenced by xi_start_element().

◆ xml_parse_file()

int xml_parse_file ( char *  filename,
void *  data,
void(*)(xml_context *, const char *, const char **, const char **, void *, GError **)  start,
void(*)(xml_context *, const char *, void *, GError **)  end,
void(*)(xml_context *, const char *, gsize, void *, GError **)  text 
)

Parses an XML file.

Parameters
filenameThe XML file to parse
dataPoints to a user-defined data structure which will be passed to each of the callbacks passed in the following arguments
startCallback which will be called when an open tag is encountered
endCallback which will be called when a close tag is encountered
textCallback which will be called when character data is encountered
Returns
True on success, false on failure.

References data, dbg, filename, lvl_debug, lvl_error, parse_node_text(), attr::text, and xml_parse_text().

Referenced by traffic_get_messages_from_xml_file().

◆ xml_parse_text()

int xml_parse_text ( const char *  document,
void *  data,
void(*)(xml_context *, const char *, const char **, const char **, void *, GError **)  start,
void(*)(xml_context *, const char *, void *, GError **)  end,
void(*)(xml_context *, const char *, gsize, void *, GError **)  text 
)

Parses XML text.

Parameters
documentThe XML data to parse
dataPoints to a user-defined data structure which will be passed to each of the callbacks passed in the following arguments
startCallback which will be called when an open tag is encountered
endCallback which will be called when a close tag is encountered
textCallback which will be called when character data is encountered
Returns
True on success, false on failure.

References context, data, dbg, lvl_error, parse_node_text(), attr::str, and attr::text.

Referenced by gui_internal_html_parse_text(), traffic_get_messages_from_xml_string(), and xml_parse_file().

◆ xmlconfig_announce()

static int xmlconfig_announce ( struct xmlstate state)
static

Referenced by initStatic().

◆ xpointer_element_match()

static int xpointer_element_match ( const char *  xpointer,
int  len,
struct xistate elem 
)
static

◆ xpointer_match()

static int xpointer_match ( const char *  xpointer,
struct xistate first 
)
static

References xpointer_xpointer_match().

Referenced by xi_start_element().

◆ xpointer_test()

static int xpointer_test ( const char *  test,
int  len,
struct xistate elem 
)
static

References c, strncmp_len(), and xpointer_value().

Referenced by xpointer_element_match().

◆ xpointer_value()

static int xpointer_value ( const char *  test,
int  len,
struct xistate elem,
const char **  out,
int  out_len 
)
static

◆ xpointer_xpointer_match()

static int xpointer_xpointer_match ( const char *  xpointer,
int  len,
struct xistate first 
)
static

Variable Documentation

◆ attr_fixme_circle

char* attr_fixme_circle[]
static
Initial value:
= {
"label_size","text_size",
NULL,NULL,
}

◆ attr_fixme_itemgra

char* attr_fixme_itemgra[]
static
Initial value:
= {
"type","item_types",
NULL,NULL,
}

◆ attr_fixme_text

char* attr_fixme_text[]
static
Initial value:
= {
"label_size","text_size",
NULL,NULL,
}

◆ attr_fixmes

struct attr_fixme attr_fixmes[]
static
Initial value:
= {
{"itemgra",attr_fixme_itemgra},
{"text",attr_fixme_text},
{"label",attr_fixme_text},
{"circle",attr_fixme_circle},
{NULL,NULL},
}
static char * attr_fixme_circle[]
Definition: xmlconfig.c:316
static char * attr_fixme_itemgra[]
Definition: xmlconfig.c:306
static char * attr_fixme_text[]
Definition: xmlconfig.c:311

Referenced by start_element().

◆ element_fixmes

char* element_fixmes[]
static
Initial value:
= {
"item","itemgra",
"label","text",
NULL,NULL,
}

Referenced by start_element().

◆ elements

struct element_func* elements

◆ object_funcs

struct object_func object_funcs[]
static
Initial value:
= {
{ attr_arrows, NEW(arrows_new)},
{ attr_spikes, NEW(spikes_new)},
{ attr_circle, NEW(circle_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
{ attr_coord, NEW(coord_new_from_attrs)},
{ attr_cursor, NEW(cursor_new), NULL, NULL, NULL, NULL, ADD(cursor_add_attr)},
{ attr_debug, NEW(debug_new)},
{ attr_graphics, NEW(graphics_new), GET(graphics_get_attr)},
{ attr_gui, NEW(gui_new), GET(gui_get_attr), NULL, NULL, SET(gui_set_attr), ADD(gui_add_attr)},
{ attr_icon, NEW(icon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
{ attr_image, NEW(image_new)},
{ attr_itemgra, NEW(itemgra_new), NULL, NULL, NULL, NULL, ADD(itemgra_add_attr)},
{ attr_plugins, NEW(plugins_new), NULL, NULL, NULL, NULL, NULL, NULL, INIT(plugins_init)},
{ attr_plugin, NEW(plugin_new)},
{ attr_polygon, NEW(polygon_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
{ attr_polyline, NEW(polyline_new), NULL, NULL, NULL, NULL, ADD(element_add_attr)},
{ attr_text, NEW(text_new)},
}
int announcement_get_attr(struct announcement *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: announcement.c:41
int announcement_set_attr(struct announcement *this_, struct attr *attr)
Definition: announcement.c:45
int announcement_add_attr(struct announcement *this_, struct attr *attr)
Definition: announcement.c:50
struct announcement * announcement_new(struct attr *parent, struct attr **attrs)
Definition: announcement.c:30
struct debug * debug_new(struct attr *parent, struct attr **attrs)
Definition: debug.c:160
int graphics_get_attr(struct graphics *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Gets an attribute of the graphics instance.
Definition: graphics.c:419
struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
Definition: graphics.c:334
static struct graphics_image_priv * image_new(struct graphics_priv *gra, struct graphics_image_methods *meth, char *path, int *w, int *h, struct point *hot, int rotation)
Definition: graphics_android.c:199
struct coord * coord_new_from_attrs(struct attr *parent, struct attr **attrs)
Definition: coord.c:57
struct plugin * plugin_new(struct attr *parent, struct attr **attrs)
Definition: plugin.c:231
int plugins_init(struct plugins *pls)
Definition: plugin.c:303
struct plugins * plugins_new(struct attr *in, struct attr **out)
Definition: plugin.c:223
int gui_add_attr(struct gui *this_, struct attr *attr)
Definition: gui.c:85
int gui_set_attr(struct gui *this_, struct attr *attr)
Definition: gui.c:76
struct gui * gui_new(struct attr *parent, struct attr **attrs)
Definition: gui.c:38
int gui_get_attr(struct gui *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
Definition: gui.c:61
struct polygon * polygon_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:522
int itemgra_add_attr(struct itemgra *itemgra, struct attr *attr)
Definition: layout.c:393
struct circle * circle_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:585
struct arrows * arrows_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:666
struct spikes * spikes_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:677
int cursor_add_attr(struct cursor *this_, struct attr *attr)
Definition: layout.c:240
struct cursor * cursor_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:198
int element_add_attr(struct element *e, struct attr *attr)
Definition: layout.c:687
struct polyline * polyline_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:570
struct text * text_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:605
struct icon * icon_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:623
struct itemgra * itemgra_new(struct attr *parent, struct attr **attrs)
Definition: layout.c:354
#define SET(x)
Definition: xmlconfig.c:221
#define ADD(x)
Definition: xmlconfig.c:222
#define INIT(x)
Definition: xmlconfig.c:224
#define NEW(x)
Definition: xmlconfig.c:217
#define GET(x)
Definition: xmlconfig.c:218

Referenced by object_func_lookup().