llconf  0.0.2
Functions | Variables
modules.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <dlfcn.h>
#include "strutils.h"
#include "nodes.h"
#include "modules.h"

Functions

void register_cnfmodule (struct cnfmodule *cm, struct cnfnode *opt_root)
 Register a module. More...
 
void unregister_all (void)
 
void destroy_cnfmodule (struct cnfmodule *cm)
 Destroy a module previously created using clone_cnfmodule(). More...
 
struct cnfmoduleclone_cnfmodule (struct cnfmodule *cm, const char *new_name, const char *default_file, struct cnfnode *opt_root)
 Clone a module. More...
 
struct cnfmodulefind_cnfmodule (const char *name)
 Find a module by name. More...
 
void cnfmodule_setopts (struct cnfmodule *cm, struct cnfnode *opt_root)
 Set module options. More...
 
void cnfmodule_setname (struct cnfmodule *cm, const char *name)
 Set module options. More...
 
struct cnfnodeparse_options (const char *string)
 Parse module options Parse an option string into a cnfnode tree. More...
 
struct cnfnodecnfmodule_parse (struct cnfmodule *cm, FILE *fin)
 Parse from a stream. More...
 
struct cnfnodecnfmodule_parse_file (struct cnfmodule *cm, const char *fname)
 Parse from a file. More...
 
int cnfmodule_unparse (struct cnfmodule *cm, FILE *fout, struct cnfnode *cn_root)
 Unparse to a stream. More...
 
int cnfmodule_unparse_file (struct cnfmodule *cm, const char *fname, struct cnfnode *cn_root)
 Unparse to a file. More...
 
int cnfmodule_register_plugin (const char *name, const char *path, struct cnfnode *opt_root)
 Load a shared library module Load a shared library module and register a new parser by calling a register function. More...
 

Variables

struct cnfmodulecnfmodules = NULL
 

Function Documentation

struct cnfmodule* clone_cnfmodule ( struct cnfmodule cm,
const char *  new_name,
const char *  default_file,
struct cnfnode opt_root 
)
read

Clone a module.

Copy a module structure, and give the copy a new name, and optionally another default file and options.

Parameters
cmpointer to the module to be copied
new_namepointer to the name of the new module
default_filepointer to the new default file. If NULL, the value of the original will be copied
opt_rootpointer to the root of the options tree. If NULL, the value of the original will be copied
Returns
pointer to the new module
struct cnfnode* cnfmodule_parse ( struct cnfmodule cm,
FILE *  fin 
)
read

Parse from a stream.

Parameters
cmpointer to the module
finpointer to the stream
Returns
if successful, the pointer to root of the parsed tree.
struct cnfnode* cnfmodule_parse_file ( struct cnfmodule cm,
const char *  fname 
)
read

Parse from a file.

Parameters
cmpointer to the module
fnamepointer to the filename. If NULL, the default of the module will be used.
Returns
if successful, the pointer to root of the parsed tree.
int cnfmodule_register_plugin ( const char *  name,
const char *  path,
struct cnfnode opt_root 
)

Load a shared library module Load a shared library module and register a new parser by calling a register function.

The register function needs to have a register function of the prototype void llconf_register_foo(struct cnfnode *opt_root), with 'foo' replaced by the name.

Parameters
namename of the parser
pathpath to the shared library object
opt_rootpointer to the root of the options tree. Can be NULL.
Returns
0 on success
void cnfmodule_setname ( struct cnfmodule cm,
const char *  name 
)

Set module options.

Parameters
cmpointer to the module
namepointer to the name
void cnfmodule_setopts ( struct cnfmodule cm,
struct cnfnode opt_root 
)

Set module options.

Parameters
cmpointer to the module
opt_rootpointer to the root of the options tree. Although the
opt_rootsyntax of this tree depends on the implementation of the module,
opt_rootthis will most likely be one returned by the parse_options() function
See Also
parse_options
int cnfmodule_unparse ( struct cnfmodule cm,
FILE *  fout,
struct cnfnode cn_root 
)

Unparse to a stream.

Parameters
cmpointer to the module
foutpointer to the stream
cn_rootthe pointer to root of the parsed tree
Returns
0 if successful
int cnfmodule_unparse_file ( struct cnfmodule cm,
const char *  fname,
struct cnfnode cn_root 
)

Unparse to a file.

Parameters
cmpointer to the module
fnamepointer to the filename. If NULL, the default of the module will be used.
cn_rootthe pointer to root of the parsed tree
Returns
0 if successful
void destroy_cnfmodule ( struct cnfmodule cm)

Destroy a module previously created using clone_cnfmodule().

free the resources of a module. The module MUST have been created by clone_module.

Parameters
cmpointer to the module to be destroyed
struct cnfmodule* find_cnfmodule ( const char *  name)
read

Find a module by name.

Searches in the list of registered modules for a module with a matching name.

Parameters
namethe name
Returns
pointer to the found module, or NULL if no module was found.
struct cnfnode* parse_options ( const char *  string)
read

Parse module options Parse an option string into a cnfnode tree.

This can be used to set options for a particular node.

Parameters
string
Returns
the root to the options tree
void register_cnfmodule ( struct cnfmodule cm,
struct cnfnode opt_root 
)

Register a module.

This will usually be called by the parser module in one of the register_* functions.

Parameters
cmpointer to the module
opt_rootpointer to the root of the options tree. Can be NULL.
void unregister_all ( void  )

Variable Documentation

struct cnfmodule* cnfmodules = NULL