xmlsup.c File Reference

XML configuration parser. More...

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlerror.h>
#include "assert.h"
#include "main.h"
#include "data.h"
#include "chromo.h"
#include "xmlsup.h"
#include "modsup.h"
#include "error.h"
#include "gettext.h"

Defines

#define FAIL(msg, node)   fatal(_(msg))
 Convenience macro for XML parser. Same as fatal(). It automatically appends line number of the XML node with error.
#define NOPROP(prop, node)   fatal(_("Tag <%s> without required property '%s'"), node->name, prop)
 Convenience macro for XML parser. Use when a required XML node property is not defined.
#define INVPROP(prop, node)   fatal(_("Invalid value of property '%s' in tag <%s>"), prop, node->name)
 Convenience macro for XML parser. Use when a property has an invalid value (e.g. property is not an integer when it should be).
#define XMLCHAR   (xmlChar *)
 Cast to (xmlChar *).
#define CHAR   (char *)
 Cast to (char *).

Functions

static void parser_fatal (const char *fmt, int no,...)
 Replacement for the fatal() function that adds line number to the message.
static void parser_newprop_int (xmlNodePtr cur, const xmlChar *prop, int value)
 Add an integer property to a XML node.
static int parser_getprop_int (xmlNodePtr cur, const xmlChar *prop)
 Get an integer property from a XML node.
static xmlChar * parser_getprop_str (xmlNodePtr cur, const xmlChar *prop)
 Get a string property from a XML node.
static resourceparser_event_get_res (xmlNodePtr cur, resourcetype *restype)
 Get a resource definition for an event from the XML tree.
static void parser_event_add_res (xmlNodePtr cur, resource *res)
 Add a resource definition for an event to the XML tree.
static void parser_info (xmlNodePtr cur)
 Parse miscellaneous information.
static moduleoptionparser_options (xmlNodePtr cur, moduleoption *opt)
 Parse module options.
static void parser_modules (xmlNodePtr cur)
 Parse modules.
static int parser_event_restrictions (xmlNodePtr cur, int tupleid, int repeats)
 Parse restrictions for a single event and call proper restriction handlers.
static void parser_events_restrictions (xmlNodePtr cur)
 Parse all event restrictions.
static void parser_event (xmlNodePtr event, tupleinfo *tuple)
 Parse a single event.
static void parser_events (xmlNodePtr cur)
 Parse all events.
static int parser_resource_restrictions_one (xmlNodePtr cur, resource *res)
 Parse restrictions for a single resource and call proper handlers.
static void parser_resource_restrictions (xmlNodePtr cur, resourcetype *restype)
 Parse all resource restrictions for a single resource type.
static void parser_resources_restrictions (xmlNodePtr cur)
 Parse all resource restrictions.
static void parser_resource (xmlNodePtr cur, resourcetype *restype)
 Parse all resources in a resource type.
static void parser_restype (xmlNodePtr cur, int var)
 Define a new resource type.
static void parser_resources (xmlNodePtr start)
 Parse all resource types.
void parser_handler (void *ctx, const char *msg,...)
 Custom error handler for libxml.
static void parser_libxml_init (char *filename)
 Parser initialization.
static void parser_version_check (xmlNodePtr root)
 Check version of the configuration file.
int parser_main (char *filename)
 Parses an XML configuration file.
static void parser_clean (xmlNodePtr cur)
 Removes definitions of variable resources for an event in the XML tree.
static void parser_remove_repeats (xmlNodePtr cur)
 Replaces event tags with repeats > 1 with multiple tags with repeats = 1.
void parser_gettable (table *tab)
 Loads definitions of variable resources for all events in the XML tree to a table struct.tab Pointer to the table struct.
void parser_addtable (table *tab)
 Saves definitions of variable resources for all events in the table struct to the XML tree.tab Pointer to the table struct.
void parser_dump (FILE *f)
 Dumps XML tree into a file.
void parser_exit ()
 Free all memory allocated by the parser.

Variables

static xmlDocPtr config
 XML Configuration file.


Detailed Description

XML configuration parser.


Define Documentation

#define CHAR   (char *)

Cast to (char *).

This macro should only be used when it is certain that the pointer contains a valid UTF-8 encoded NULL terminated string.

#define FAIL ( msg,
node   )     fatal(_(msg))

Convenience macro for XML parser. Same as fatal(). It automatically appends line number of the XML node with error.

Parameters:
msg Error message.
node Pointer to the XML node with error.

#define INVPROP ( prop,
node   )     fatal(_("Invalid value of property '%s' in tag <%s>"), prop, node->name)

Convenience macro for XML parser. Use when a property has an invalid value (e.g. property is not an integer when it should be).

Parameters:
prop Name of the property
node Pointer to the XML node with error.

#define NOPROP ( prop,
node   )     fatal(_("Tag <%s> without required property '%s'"), node->name, prop)

Convenience macro for XML parser. Use when a required XML node property is not defined.

Parameters:
prop Name of the property.
node Pointer to the XML node with error.

#define XMLCHAR   (xmlChar *)

Cast to (xmlChar *).

This macro should only be used when it is certain that the pointer contains a valid UTF-8 encoded NULL terminated string.


Function Documentation

void parser_addtable ( table tab  ) 

Saves definitions of variable resources for all events in the table struct to the XML tree.tab Pointer to the table struct.

Any previous definitions of variable resources are replaced.

static void parser_clean ( xmlNodePtr  cur  )  [static]

Removes definitions of variable resources for an event in the XML tree.

Parameters:
cur Pointer to the <event> node in the XML tree.

void parser_dump ( FILE *  f  ) 

Dumps XML tree into a file.

Parameters:
f File to dump the XML tree to.

static void parser_event ( xmlNodePtr  event,
tupleinfo tuple 
) [static]

Parse a single event.

Parameters:
event Pointer to the <event> node.
tuple Pointer to the tuple info struct for this event.

static void parser_event_add_res ( xmlNodePtr  cur,
resource res 
) [static]

Add a resource definition for an event to the XML tree.

Parameters:
cur Pointer to the <event> node.
res Pointer to the resource to add.

static resource* parser_event_get_res ( xmlNodePtr  cur,
resourcetype restype 
) [static]

Get a resource definition for an event from the XML tree.

Parameters:
cur Pointer to the <event> node.
restype Get a resource definition for this resource type.

static int parser_event_restrictions ( xmlNodePtr  cur,
int  tupleid,
int  repeats 
) [static]

Parse restrictions for a single event and call proper restriction handlers.

Parameters:
cur Pointer to the <event> node.
tupleid Tuple ID for this event.
repeats Number of repeats of this event.
Returns:
1 if there were unknown restrictions or 0 otherwise.

static void parser_events ( xmlNodePtr  cur  )  [static]

Parse all events.

Parameters:
cur Pointer to the <events> node.

static void parser_events_restrictions ( xmlNodePtr  cur  )  [static]

Parse all event restrictions.

Parameters:
cur Pointer to the <events> node.

static void parser_fatal ( const char *  fmt,
int  no,
  ... 
) [static]

Replacement for the fatal() function that adds line number to the message.

Parameters:
fmt Format string.
no Line number.

static int parser_getprop_int ( xmlNodePtr  cur,
const xmlChar *  prop 
) [static]

Get an integer property from a XML node.

Calls fatal() if property was not found or was not integer.

Parameters:
cur Pointer to the XML node.
prop Name of the property.
Returns:
Content of the property.

static xmlChar* parser_getprop_str ( xmlNodePtr  cur,
const xmlChar *  prop 
) [static]

Get a string property from a XML node.

Calls fatal() if property was not found.

Parameters:
cur Pointer to the XML node.
prop Name of the property.
Returns:
Content of the property. Must be freed with xmlFree() after use.

static void parser_info ( xmlNodePtr  cur  )  [static]

Parse miscellaneous information.

Parameters:
cur Pointer to the <info> node.

static void parser_libxml_init ( char *  filename  )  [static]

Parser initialization.

Parameters:
filename Name of the XML configuration file to open.

int parser_main ( char *  filename  ) 

Parses an XML configuration file.

Parameters:
filename Name of the configuration file.
Returns:
0 on success and -1 on error.
Defines all resources and all tuples, loads miscellaneous information and loads and initializes all modules.

static void parser_modules ( xmlNodePtr  cur  )  [static]

Parse modules.

Parameters:
cur Pointer to the <modules> node.

static void parser_newprop_int ( xmlNodePtr  cur,
const xmlChar *  prop,
int  value 
) [static]

Add an integer property to a XML node.

If a property with this name already exists it is overwritten.

Parameters:
cur Pointer to the XML node.
prop Name of the property.
value Value of the property.

static moduleoption* parser_options ( xmlNodePtr  cur,
moduleoption opt 
) [static]

Parse module options.

Parameters:
cur Pointer to the <module> node.
opt Pointer to the linked list of module options.

static void parser_remove_repeats ( xmlNodePtr  cur  )  [static]

Replaces event tags with repeats > 1 with multiple tags with repeats = 1.

Parameters:
cur Pointer to the <events> node in the XML tree.

static void parser_resource ( xmlNodePtr  cur,
resourcetype restype 
) [static]

Parse all resources in a resource type.

Parameters:
cur Pointer to the <resourcetype> node.
restype Pointer to the resource type struct for this resource type.

static void parser_resource_restrictions ( xmlNodePtr  cur,
resourcetype restype 
) [static]

Parse all resource restrictions for a single resource type.

Parameters:
cur Pointer to the <resourcetype> node.
restype Pointer to the resource type struct for this resource type.

static int parser_resource_restrictions_one ( xmlNodePtr  cur,
resource res 
) [static]

Parse restrictions for a single resource and call proper handlers.

Parameters:
cur Pointer to the <resource> node.
res Pointer to the resource struct for this resource.
Returns:
1 if there were unknown restrictions or 0 otherwise.

static void parser_resources ( xmlNodePtr  start  )  [static]

Parse all resource types.

Parameters:
start Pointer to the <resources> node.

static void parser_resources_restrictions ( xmlNodePtr  cur  )  [static]

Parse all resource restrictions.

Parameters:
cur Pointer to the <resources> node.

static void parser_restype ( xmlNodePtr  cur,
int  var 
) [static]

Define a new resource type.

Parameters:
cur pointer to the <resourcetype> node.
var Set to 1 if this node is under <variable> node.

static void parser_version_check ( xmlNodePtr  root  )  [static]

Check version of the configuration file.

Parameters:
root Pointer to the root node of the XML tree.


Generated on Tue Jul 3 13:23:36 2007 for Tablix by  doxygen 1.5.2