OpenCBM
|
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... | |
Shared library / DLL for accessing the driver Process configuration file.
Definition in file configuration.c.
#define ASSUMED_MAX_LINE_LENGTH 256 |
the maximum line length we expect in a configuration file
Definition at line 37 of file configuration.c.
typedef struct opencbm_configuration_entry_s opencbm_configuration_entry_t |
a convenient name for opencbm_configuration_entry_s
Definition at line 40 of file configuration.c.
typedef struct opencbm_configuration_section_s opencbm_configuration_section_t |
a convenient name for opencbm_configuration_section_s
Definition at line 60 of file configuration.c.
typedef struct opencbm_configuration_s opencbm_configuration_t |
this struct holds a complete configuration file The handle to the configuration file is a pointer to this struct, actually.
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.
Handle | Handle to the opened configuration file, as obtained from opencbm_configuration_open() |
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.
Filename | The name of the configuration file to open |
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.
Handle | Handle to the opened configuration file, as obtained from opencbm_configuration_open(). |
Section | A string which holds the name of the section from which to remove. |
EntryName | A string which holds the name of the entry to 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.
Handle | Handle to the opened configuration file, as obtained from opencbm_configuration_open(). |
Section | A string which holds the name of the section from where to get the data. |
Callback | The callback function to call with the section name |
Data | Some data which is forwarded to the Callback function. |
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.
Handle | Handle to the opened configuration file, as obtained from opencbm_configuration_open(). |
Callback | The callback function to call with the section name |
Data | Some data which is forwarded to the Callback function. |
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.
Handle | Handle to the opened configuration file, as obtained from opencbm_configuration_open() |
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.
Handle | Handle to the opened configuration file, as obtained from opencbm_configuration_open(). |
Section | A string which holds the name of the section from where to get the data. |
Entry | A string which holds the name of the entry to get. |
ReturnBuffer | A 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. |
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.
Filename | The name of the configuration file to open |
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.
Handle | Handle to the opened configuration file, as obtained from opencbm_configuration_open(). |
Section | A string which holds the name of the section to 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.
Handle | Handle to the opened configuration file, as obtained from opencbm_configuration_open(). |
Section | A string which holds the name of the section where to set the data. |
Entry | A string which holds the name of the entry to set. |
Value | A buffer which holds the value of the entry which is to be set. |
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().