OpenCBM
Typedefs | Functions
configuration.h File Reference

Shared library / DLL for accessing the driver Read configuration file. More...

Go to the source code of this file.

Typedefs

typedef struct
opencbm_configuration_s
opencbm_configuration_handle
 Handle to a configuration file.
 
typedef int opencbm_configuration_enum_sections_callback_t (opencbm_configuration_handle Handle, const char Section[], void *Context)
 Callback type for section enumeration. More...
 
typedef int opencbm_configuration_enum_data_callback_t (opencbm_configuration_handle Handle, const char Section[], const char Entry[], void *Context)
 Callback type for entry enumeration. More...
 

Functions

const char * configuration_get_default_filename (void)
 Get the default filename for the configuration file. More...
 
const char * configuration_get_default_filename_for_install (unsigned int local_install)
 Get the default filename for the configuration file on installation. More...
 
opencbm_configuration_handle opencbm_configuration_open (const char *Filename)
 Open the configuration file. More...
 
opencbm_configuration_handle opencbm_configuration_create (const char *Filename)
 Creates the configuration file for reading and writing. More...
 
int opencbm_configuration_close (opencbm_configuration_handle Handle)
 Close the configuration file. More...
 
int opencbm_configuration_flush (opencbm_configuration_handle Handle)
 Flush the configuration file. More...
 
int opencbm_configuration_get_data (opencbm_configuration_handle Handle, const char Section[], const char Entry[], char **ReturnBuffer)
 Read data from the configuration file. More...
 
int opencbm_configuration_set_data (opencbm_configuration_handle Handle, const char Section[], const char Entry[], const char Value[])
 Write/Change data to/in the configuration file. More...
 
int opencbm_configuration_enum_sections (opencbm_configuration_handle Handle, opencbm_configuration_enum_sections_callback_t Callback, void *Context)
 Enumerate sections in the configuration file. More...
 
int opencbm_configuration_enum_data (opencbm_configuration_handle Handle, const char Section[], opencbm_configuration_enum_data_callback_t Callback, void *Context)
 Enumerate data in the configuration file. More...
 

Detailed Description

Shared library / DLL for accessing the driver Read configuration file.



Author
Spiro Trikaliotis

Definition in file configuration.h.

Typedef Documentation

typedef int opencbm_configuration_enum_data_callback_t(opencbm_configuration_handle Handle, const char Section[], const char Entry[], void *Context)

Callback type for entry enumeration.

This function type is used as the callback function in opencbm_configuration_enum_data()

Parameters
HandleHandle to the configuration file
SectionName of the section
EntryName of the enumerated entry
ContextContext data as given in the call to opencbm_configuration_enum_data(). This data is not interpreted, but forwarded "as is".
Returns
0 on success; everything else indicates an error.

Definition at line 72 of file configuration.h.

typedef int opencbm_configuration_enum_sections_callback_t(opencbm_configuration_handle Handle, const char Section[], void *Context)

Callback type for section enumeration.

This function type is used as the callback function in opencbm_configuration_enum_sections()

Parameters
HandleHandle to the configuration file
SectionName of the enumerated section
ContextContext data as given in the call to opencbm_configuration_enum_sections(). This data is not interpreted, but forwarded "as is".
Returns
0 on success; everything else indicates an error.

Definition at line 45 of file configuration.h.

Function Documentation

const char* configuration_get_default_filename ( void  )

Get the default filename for the configuration file.

Get the default filename of the configuration file.

Returns
Returns a newly allocated memory area with the default file name.

Definition at line 50 of file LINUX/configuration_name.c.

References cbmlibmisc_strcat(), cbmlibmisc_strdup(), and OPENCBM_DEFAULT_CONFIGURATION_FILE_NAME.

Referenced by opencbm_plugin_get_all_plugin_names(), and opencbm_plugin_install_plugin_data().

const char* configuration_get_default_filename_for_install ( unsigned int  DefaultLocation)

Get the default filename for the configuration file on installation.

Get the default filename of the configuration file. This function returns a filename even if no configuration exists yet. This is used for the installation, where the name for the initial configuration file must be found.

Parameters
DefaultLocationIn case a new file has to be created, give the preference of one of the locations to use.
Returns
Returns a newly allocated memory area with the default file name.

Definition at line 224 of file WINDOWS/configuration_name.c.

Referenced by opencbm_plugin_install_generic().

int opencbm_configuration_close ( opencbm_configuration_handle  Handle)

Close the configuration file.

Closes the configuration file after it has been used. If it has been changed in the mean time, it is first stored to permanent storage.

Parameters
HandleHandle to the opened configuration file, as obtained from opencbm_configuration_open()
Returns
0 if the function succeeded, 1 otherwise.

Definition at line 967 of file configuration.c.

References opencbm_configuration_flush().

Referenced by get_all_installed_plugins(), opencbm_plugin_get_all_plugin_names(), opencbm_plugin_install_generic(), and opencbm_plugin_install_plugin_data().

opencbm_configuration_handle opencbm_configuration_create ( const char *  Filename)

Creates the configuration file for reading and writing.

Opens the configuration file so it can be used later on with opencbm_configuration_get_data(). If the file does not exist, a new, empty one is created.

Parameters
FilenameThe name of the configuration file to open
Returns
Returns a handle to the configuration file which can be used in subsequent calls to the other configuration file functions.

Definition at line 869 of file configuration.c.

References opencbm_configuration_open().

Referenced by opencbm_plugin_install_generic().

int opencbm_configuration_enum_data ( opencbm_configuration_handle  Handle,
const char  Section[],
opencbm_configuration_enum_data_callback_t  Callback,
void *  Data 
)

Enumerate data in the configuration file.

This function enumerates all entries in a given section of the configuration file. For every entry, a given callback function is called.

Parameters
HandleHandle to the opened configuration file, as obtained from opencbm_configuration_open().
SectionA string which holds the name of the section from where to get the data.
CallbackThe callback function to call with the section name
DataSome data which is forwarded to the Callback function.
Returns
Returns 0 if the data entry was found. If ReturnBufferLength != 0, the return value is 0 only if the buffer was large enough to hold the data.
Note
If ReturnBufferLength is zero, this function only tests if the Entry exists in the given Section. In this case, this function returns 0; otherwise, it returns 1.

Definition at line 1335 of file configuration.c.

References opencbm_configuration_section_s::Entries, opencbm_configuration_entry_s::Name, opencbm_configuration_section_s::Name, and opencbm_configuration_entry_s::Next.

int opencbm_configuration_enum_sections ( opencbm_configuration_handle  Handle,
opencbm_configuration_enum_sections_callback_t  Callback,
void *  Data 
)

Enumerate sections in the configuration file.

This function enumerates all sections in the configuration file. For every section name, a given callback function is called.

Parameters
HandleHandle to the opened configuration file, as obtained from opencbm_configuration_open().
CallbackThe callback function to call with the section name
DataSome data which is forwarded to the Callback function.
Returns
Returns 0 if the data entry was found. If ReturnBufferLength != 0, the return value is 0 only if the buffer was large enough to hold the data.
Note
If ReturnBufferLength is zero, this function only tests if the Entry exists in the given Section. In this case, this function returns 0; otherwise, it returns 1.

Definition at line 1285 of file configuration.c.

References opencbm_configuration_section_s::Name, opencbm_configuration_section_s::Next, and opencbm_configuration_s::Sections.

Referenced by opencbm_plugin_get_all_plugin_names().

int opencbm_configuration_flush ( opencbm_configuration_handle  Handle)

Flush the configuration file.

Flushes the configuration file. This is, if it has been changed, it is stored to permanent storage.

Parameters
HandleHandle to the opened configuration file, as obtained from opencbm_configuration_open()
Returns
0 if the function succeeded, 1 otherwise.

Definition at line 934 of file configuration.c.

References opencbm_configuration_s::Changed.

Referenced by opencbm_configuration_close().

int opencbm_configuration_get_data ( opencbm_configuration_handle  Handle,
const char  Section[],
const char  Entry[],
char **  ReturnBuffer 
)

Read data from the configuration file.

This function searches for a specific enty in the configuration file and returns the value found there.

Parameters
HandleHandle to the opened configuration file, as obtained from opencbm_configuration_open().
SectionA string which holds the name of the section from where to get the data.
EntryA string which holds the name of the entry to get.
ReturnBufferA buffer which holds the return value on success. If the function returns with something different than 0, the buffer pointer to by ReturnBuffer will not be changed. Can be NULL, cf. note below.
Returns
Returns 0 if the data entry was found. If ReturnBufferLength != 0, the return value is 0 only if the buffer was large enough to hold the data.
Note
If ReturnBuffer is NULL, this function only tests if the Entry exists in the given Section. In this case, this function returns 0; otherwise, it returns 1.

Definition at line 1226 of file configuration.c.

References cbmlibmisc_strdup(), and opencbm_configuration_entry_s::Value.

Referenced by plugin_is_active().

opencbm_configuration_handle opencbm_configuration_open ( const char *  Filename)

Open the configuration file.

Opens the configuration file so it can be used later on with opencbm_configuration_get_data(). If the file does not exist, this function fails.

Parameters
FilenameThe name of the configuration file to open
Returns
Returns a handle to the configuration file which can be used in subsequent calls to the other configuration file functions for reading. Write operations are not allowed after using this function.

If the configuration file does not exist, this function returns NULL.

Definition at line 804 of file configuration.c.

References cbmlibmisc_strcat(), cbmlibmisc_strdup(), cbmlibmisc_strfree(), opencbm_configuration_s::Changed, opencbm_configuration_s::FileName, opencbm_configuration_s::FileNameForWrite, and opencbm_configuration_s::Sections.

Referenced by opencbm_configuration_create(), opencbm_plugin_get_all_plugin_names(), and opencbm_plugin_install_plugin_data().

int opencbm_configuration_set_data ( opencbm_configuration_handle  Handle,
const char  Section[],
const char  Entry[],
const char  Value[] 
)

Write/Change data to/in the configuration file.

This function searches for a specific entry in the configuration file and changes it if it exists. If it does not exist, a new entry is generated.

Parameters
HandleHandle to the opened configuration file, as obtained from opencbm_configuration_open().
SectionA string which holds the name of the section where to set the data.
EntryA string which holds the name of the entry to set.
ValueA buffer which holds the value of the entry which is to be set.
Returns
0 if the data could be written, 1 otherwise

Definition at line 1390 of file configuration.c.

References cbmlibmisc_strdup(), cbmlibmisc_strfree(), opencbm_configuration_s::Changed, and opencbm_configuration_entry_s::Value.

Referenced by opencbm_plugin_install_generic(), and opencbm_plugin_install_plugin_data().