dnxCfgParser.h File Reference

Definitions and prototypes for parsing DNX server config files. More...

#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  DnxCfgDict
 An array of these structures defines a user's configuration variables. More...
struct  DnxCfgParser
 An abstraction data type for the DNX configuration parser. More...

Typedefs

typedef int DnxCfgValidator_t (DnxCfgDict *dict, void *ppvals[], void *passthru)
 A function type defining the prototype for a validator function.

Enumerations

enum  DnxCfgType {
  DNX_CFG_STRING, DNX_CFG_STRING_ARRAY, DNX_CFG_INT, DNX_CFG_INT_ARRAY,
  DNX_CFG_UNSIGNED, DNX_CFG_UNSIGNED_ARRAY, DNX_CFG_URL, DNX_CFG_FSPATH,
  DNX_CFG_BOOL
}
 An enumeration of data types that the configuration parser understands. More...

Functions

int dnxCfgParserCreate (char *cfgdefs, char *cfgfile, char *cmdover, DnxCfgDict *dict, DnxCfgValidator_t *vfp, DnxCfgParser **cpp)
 Create a new configuration parser object.
int dnxCfgParserParse (DnxCfgParser *cp, void *passthru)
 Parse a configuration file into a value array.
int dnxCfgParserGetCfg (DnxCfgParser *cp, char *buf, size_t *bufszp)
 Return the current configuration as a formatted string.
void dnxCfgParserDestroy (DnxCfgParser *cp)
 Destroy a previously created configuration parser object.


Detailed Description

Definitions and prototypes for parsing DNX server config files.

Author:
John Calcote (jcalcote@users.sourceforge.net)
Attention:
Please submit patches to http://dnx.sourceforge.net

Definition in file dnxCfgParser.h.


Typedef Documentation

typedef int DnxCfgValidator_t(DnxCfgDict *dict, void *ppvals[], void *passthru)

A function type defining the prototype for a validator function.

The elements of ppvals correspond directly to the entries in the user specified configuration dictionary. However, these pointers refer to temporary space. Once this validator function has returned success, then the values in this temporary space are exported to the user dictionary.

Parameters:
[in] dict - a reference to (a copy of) the user-specified dictionary.
[in] ppvals - an array of pointers to configuration values.
[in] passthru - an opaque pointer passed through from the dnxCfgParserCreate passthru parameter.
Returns:
Zero on success, or a non-zero error value which is subsequently returned through the dnxCfgParserParse function.

Definition at line 90 of file dnxCfgParser.h.


Enumeration Type Documentation

enum DnxCfgType

An enumeration of data types that the configuration parser understands.

The comment after each type in the enumeration describes the data type that should be passed as a void pointer in the value field of the dictionary structure.

The syntax is clearly not strictly conformant to C language syntax. For example, (&char*) indicates that the address of a character pointer should be passed. Strict C language syntax would be more like (char**), but this syntax is ambiguous. It could mean that a variable defined as char ** is passed by value, or that a variable of type char * is passed by address.

The addresses of pointer types (eg., &char*) are returned as references to allocated heap blocks, while the addresses of pointer-sized integral types (eg., &unsigned) are returned by value as objects.

Strings, string arrays and pointer arrays are null-terminated. The first element of integer arrays is the size of the remaining array of values.

Allocated memory may be freed by calling dnxCfgFreeValues.

Enumerator:
DNX_CFG_STRING  Text string (&char*).
DNX_CFG_STRING_ARRAY  String array; comma-delimited (&char**).
DNX_CFG_INT  Signed integer (&int).
DNX_CFG_INT_ARRAY  Comma-delimited array (&int*).
DNX_CFG_UNSIGNED  Unsigned integer (&unsigned).
DNX_CFG_UNSIGNED_ARRAY  Comma-delimited array (&unsigned*).
DNX_CFG_URL  URL (&char*).
DNX_CFG_FSPATH  File system path (&char*).
DNX_CFG_BOOL  Boolean (&unsigned).

Definition at line 54 of file dnxCfgParser.h.


Function Documentation

int dnxCfgParserCreate ( char *  cfgdefs,
char *  cfgfile,
char *  cmdover,
DnxCfgDict dict,
DnxCfgValidator_t vfp,
DnxCfgParser **  cpp 
)

Create a new configuration parser object.

A configuration parser is used to read and parse a specified configuration file using a user-provided configuration variable dictionary to validate and convert the string values into usable data values.

A null-terminated string containing default configuration file entries may optionally be passed in the cfgdefs parameter. The format of the string is the same as that of a configuration file. The cfgdefs string is parsed BEFORE the configuration file, thus configuration file entries override default configuration entries.

A null-terminated string containing command-line overrides for existing configuration file entries may optionally be passed in the cmdover parameter. The format of the string is the same as that of a configuration file. The cmdover string is parsed AFTER the configuration file, thus cmdover entries override configuration file entries.

The validator function vfp is called after all values are parsed. The values will only be written to the user's dictionary after vfp returns success (0).

Parameters:
[in] cfgdefs - an optional string containing default config file entries. Pass NULL if not required.
[in] cfgfile - an optional path name of the config file to be parsed. Pass NULL if not required.
[in] cmdover - an optional string containing command line override entries. Pass NULL if not required.
[in] dict - an array of DnxCfgDict objects, each of which defines a valid configuration variable name and type for this parser. The dict array should be terminated with NULL field values (a NULL pointer in the varname field, and DNX_CFG_NULL in the type field).
[in] vfp - a pointer to a validator function.
[out] cpp - the address of storage for the newly created configuration parser object.
Returns:
Zero on success, or a non-zero error value.

Definition at line 783 of file dnxCfgParser.c.

References iDnxCfgParser::cfgdefs, iDnxCfgParser::cfgfile, iDnxCfgParser::cmdover, copyDictionary(), iDnxCfgParser::dict, iDnxCfgParser::dictsz, DNX_ERR_MEMORY, DNX_OK, strToStrArray(), iDnxCfgParser::vfp, xfree, xmalloc, and xstrdup.

Referenced by initConfig().

void dnxCfgParserDestroy ( DnxCfgParser cp  ) 

Destroy a previously created configuration parser object.

Parameters:
[in] cp - the configuration parser object to be destroyed.

Definition at line 921 of file dnxCfgParser.c.

References iDnxCfgParser::cfgdefs, iDnxCfgParser::cfgfile, iDnxCfgParser::cmdover, iDnxCfgParser::curcfg, iDnxCfgParser::dict, freeArrayPtrs(), and xfree.

Referenced by initConfig(), main(), and releaseConfig().

int dnxCfgParserGetCfg ( DnxCfgParser cp,
char *  buf,
size_t *  bufszp 
)

Return the current configuration as a formatted string.

The configuration string is a set of '
' terminated lines, each containing the same text as might be specified in a configuration file. The set of lines contain the complete current configuration as defined by the specified configuration parser object.

The proper way to use this call is to call it twice, once with a zero length buffer (null for buf and 0 in bufszp). On return, bufszp will then contain the required size of buf, which may then be allocated before the second call. This operation is efficient because the current configuration string is cached by the configuration parser object.

Parameters:
[in] cp - the configuration parser whose current configuration data should be returned.
[out] buf - the address of storage for the formatted configuration string data.
[in,out] bufszp - on entry contains the size of buf; on exit, returns the number of bytes used or required to store the entire formatted configuration string.
Returns:
Zero on success, or a non-zero error value.

Definition at line 896 of file dnxCfgParser.c.

References buildCurrentCfgCache(), iDnxCfgParser::ccsize, iDnxCfgParser::curcfg, iDnxCfgParser::dict, and DNX_ERR_MEMORY.

Referenced by buildMgmtCfgReply().

int dnxCfgParserParse ( DnxCfgParser cp,
void *  passthru 
)

Parse a configuration file into a value array.

Parses an optional default set of configuration values, followed by the configuration file, followed by an optional set of command line override configuration values. After all parsing is complete, calls the validator function (if specified). If the validator passes (returns success - 0), then the parsed values are copied into the user's dictionary and success is returned. Otherwise no dictionary value changes take effect.

Parameters:
[in] cp - the configuration parser object on which to run the parser.
[in] passthru - an opaque pointer to user data that's passed through to the validator function.
Returns:
Zero on success, or a non-zero error value. Possible error values include DNX_OK (on success), DNX_ERR_ACCESS, DNX_ERR_NOTFOUND, DNX_ERR_SYNTAX or DNX_ERR_MEMORY.

Definition at line 814 of file dnxCfgParser.c.

References applyCfgSetString(), iDnxCfgParser::ccsize, iDnxCfgParser::cfgdefs, iDnxCfgParser::cfgfile, iDnxCfgParser::cmdover, iDnxCfgParser::curcfg, iDnxCfgParser::dict, iDnxCfgParser::dictsz, DNX_CFG_BOOL, DNX_CFG_INT, DNX_CFG_UNSIGNED, DNX_ERR_ACCESS, DNX_ERR_INVALID, DNX_ERR_MEMORY, DNX_ERR_NOTFOUND, DNX_MAX_CFG_LINE, dnxErrorString(), dnxLog(), dnxParseCfgLine(), freeArrayPtrs(), INTSWAP, PTRSWAP, DnxCfgDict::type, DnxCfgDict::valptr, iDnxCfgParser::vfp, xfree, and xmalloc.

Referenced by dnxReconfigure(), initConfig(), and processCommands().


Generated on Tue Apr 13 15:48:07 2010 for DNX by  doxygen 1.5.6