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

◆ clone_cnfmodule()

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

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

◆ cnfmodule_parse()

struct cnfnode* cnfmodule_parse ( struct cnfmodule cm,
FILE *  fin 
)

Parse from a stream.

Parameters
cmpointer to the module
finpointer to the stream
Returns
if successful, the pointer to root of the parsed tree.

◆ cnfmodule_parse_file()

struct cnfnode* cnfmodule_parse_file ( struct cnfmodule cm,
const char *  fname 
)

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.

◆ cnfmodule_register_plugin()

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

◆ cnfmodule_setname()

void cnfmodule_setname ( struct cnfmodule cm,
const char *  name 
)

Set module options.

Parameters
cmpointer to the module
namepointer to the name

◆ cnfmodule_setopts()

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

◆ cnfmodule_unparse()

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

◆ cnfmodule_unparse_file()

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

◆ destroy_cnfmodule()

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

◆ find_cnfmodule()

struct cnfmodule* find_cnfmodule ( const char *  name)

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.

◆ parse_options()

struct cnfnode* parse_options ( const char *  string)

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

◆ register_cnfmodule()

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.

◆ unregister_all()

void unregister_all ( void  )

Variable Documentation

◆ cnfmodules

struct cnfmodule* cnfmodules = NULL