OpenCBM
Data Structures | Macros | Typedefs | Functions
configuration.c File Reference

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

#include "arch.h"
#include "configuration.h"
#include "libmisc.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  opencbm_configuration_entry_s
 
struct  opencbm_configuration_section_s
 
struct  opencbm_configuration_s
 

Macros

#define ASSUMED_MAX_LINE_LENGTH   256
 the maximum line length we expect in a configuration file More...
 

Typedefs

typedef struct
opencbm_configuration_entry_s 
opencbm_configuration_entry_t
 
typedef struct
opencbm_configuration_section_s 
opencbm_configuration_section_t
 
typedef struct
opencbm_configuration_s 
opencbm_configuration_t
 

Functions

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_flush (opencbm_configuration_handle Handle)
 Flush the configuration file. More...
 
int opencbm_configuration_close (opencbm_configuration_handle Handle)
 Close 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_enum_sections (opencbm_configuration_handle Handle, opencbm_configuration_enum_sections_callback_t Callback, void *Data)
 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 *Data)
 Enumerate data in 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_section_remove (opencbm_configuration_handle Handle, const char Section[])
 Remove a complete section from the configuration file. More...
 
int opencbm_configuration_entry_remove (opencbm_configuration_handle Handle, const char Section[], const char EntryName[])
 Remove an entry from the configuration file. More...
 

Detailed Description

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



Author
Spiro Trikaliotis

Definition in file configuration.c.

Macro Definition Documentation

#define ASSUMED_MAX_LINE_LENGTH   256

the maximum line length we expect in a configuration file

Remarks
: If a line is longer, it will still be processed. The only drawback is that the line is read in with multiple fgets() calls. Thus, it is slower and produces more work and possibly fragmentation on the heap.

Definition at line 37 of file configuration.c.

Typedef Documentation

a convenient name for opencbm_configuration_entry_s

Definition at line 40 of file configuration.c.

a convenient name for opencbm_configuration_section_s

Definition at line 60 of file configuration.c.

this struct holds a complete configuration file The handle to the configuration file is a pointer to this struct, actually.

Function Documentation

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_entry_remove ( opencbm_configuration_handle  Handle,
const char  Section[],
const char  EntryName[] 
)

Remove an entry from the configuration file.

This function searches for a specific entry in a given section in the configuration file and removes it if it exists.

Parameters
HandleHandle to the opened configuration file, as obtained from opencbm_configuration_open().
SectionA string which holds the name of the section from which to remove.
EntryNameA string which holds the name of the entry to remove.
Returns
0 if the data was removed. 1 otherwise. This means the entry did not exist in the first place.
Todo:
Test opencbm_configuration_entry_remove()

Definition at line 1498 of file configuration.c.

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

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_section_remove ( opencbm_configuration_handle  Handle,
const char  Section[] 
)

Remove a complete section from the configuration file.

This function searches for a specific section in the configuration file and completely removes it if it exists.

Parameters
HandleHandle to the opened configuration file, as obtained from opencbm_configuration_open().
SectionA string which holds the name of the section to remove.
Returns
0 if the data was removed. 1 otherwise. This means the section did not exist in the first place.
Todo:
Test opencbm_configuration_section_remove()

Definition at line 1444 of file configuration.c.

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

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().