Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

config.c File Reference

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <dlfcn.h>
#include "chtbl.h"
#include "config.h"

Go to the source code of this file.

Defines

#define PRIVATE_CODE_ONLY
#define CONFIG_H_ERROR_SIZE   2048
 Number of characters for the buffer used to store the last error message.


Functions

char * conf_get_last_error ()
 Return the last error message. More...

int config_hash_function (const void *key)
 Hash function used by the hash table module. More...

void config_free_user_data (void *d)
 Function used to free allocated memory in the hash table. More...

int config_compare_user_data (const void *d1, const void *d2)
 Function used to compare 2 elements in the hash table. More...

int get_number_of_modem_conf ()
 Return the number of records in the modems' configuration file. More...

char * dummy_mac_processor (char *addr)
 Dummy MAC address calculator. More...

int configlex ()
 Flex generated parser.

int parse_configuration_file (char *path, int *err)
 Load a given configuration file. More...

int modem_conf_get_id (char *mac)
 Returns the ID of a given MAC address. More...

char * modem_conf_get_tag_name (int id)
 Returns the tag name of a given MAC address, representd by its ID. More...

int modem_conf_is_autoconf (int id)
 Returns a value that indicates if a given modem supports auto-configuration. More...

void * modem_conf_get_function (int id)
 Returns the MAC processor for a given MAC address. More...

void free_all_configuration_data ()
 Free all data allocated for the hash table. More...

int get_value (char *tag, char **value)
 Return the value associated with a given tag. More...


Variables

char last_error [CONFIG_H_ERROR_SIZE]
 Buffer that contains the last error message.

int allochtab = 0
 This flag indicates wether the memory allocated for the hash table is freed or not.

CHTbl htab
 Handler to the hash table.

modem_conf_struct modem_configuration_list [MODEM_CONF_MAX_ENTRY]
 This array contains the modems' configuration. The first record is associated with the default configuration.

int nb_modem
 Number of configured modems. This integer represents the number of records in the array "modem_configuration_list".

FILE * configin
 Flex input file descriptor.


Detailed Description

Configuration parser interface.

Definition in file config.c.


Function Documentation

char* conf_get_last_error  
 

Return the last error message.

Author:
Denis BEURIVE
Returns:
The function returns a zero terminated, statically allocated, string of characters that represents the last error message.

Definition at line 31 of file config.c.

References last_error.

Referenced by configuration_load().

int config_compare_user_data const void *    d1,
const void *    d2
 

Function used to compare 2 elements in the hash table.

Author:
Denis BEURIVE
Remarks:
See example for the hash table module.

Definition at line 80 of file config.c.

Referenced by parse_configuration_file().

void config_free_user_data void *    d
 

Function used to free allocated memory in the hash table.

Author:
Denis BEURIVE
Remarks:
See example for the hash table module.

Definition at line 63 of file config.c.

Referenced by parse_configuration_file().

int config_hash_function const void *    key
 

Hash function used by the hash table module.

Author:
Denis BEURIVE
Remarks:
See example for the hash table module.

Definition at line 43 of file config.c.

Referenced by parse_configuration_file().

char* dummy_mac_processor char *    addr
 

Dummy MAC address calculator.

Author:
Denis BEURIVE
Parameters:
addr  Pointer to a zero terminated string of characters that represents the original MAC address.
Returns:
The function returns a pointer to a zero terminated, statically allocated, string of characters. This string contains a copy of the original MAC address.
Remarks:
Make sure that the buffer "mac" is big enough.

Definition at line 122 of file config.c.

Referenced by parse_configuration_file().

void free_all_configuration_data  
 

Free all data allocated for the hash table.

Author:
Denis BEURIVE

Definition at line 330 of file config.c.

References allochtab, and htab.

Referenced by parse_configuration_file().

int get_number_of_modem_conf  
 

Return the number of records in the modems' configuration file.

Author:
Denis BEURIVE
Returns:
The function returns the number of modems' configuration records.

Definition at line 112 of file config.c.

References nb_modem.

Referenced by modem_conf_get_id(), and parse_configuration_file().

int get_value char *    tag,
char **    value
 

Return the value associated with a given tag.

Author:
Denis BEURIVE
Parameters:
tag  Pointer to a zero terminated string of characters that represents the tag to look for.
value  Pointer that will point to the corresponding value (if the tag was found).
Returns:
  • If the tag could not be find, the function returns the value 0. 'value' is NULL.
  • If the tag has been found, the function returns the value 1.
  • If the function ran out of memory, the function returns the value -1. 'value' is NULL.

Definition at line 343 of file config.c.

References htab.

Referenced by configuration_load(), and load_mysql_configuration_from_file().

void* modem_conf_get_function int    id
 

Returns the MAC processor for a given MAC address.

Author:
Denis BEURIVE
Parameters:
id  ID of the MAC address (as returned by the function modem_conf_get_id()).
Returns:
The function returns a pointer to a function used to calculate the new MAC address.

Definition at line 321 of file config.c.

References modem_conf_struct::calculate_mac_address.

int modem_conf_get_id char *    mac
 

Returns the ID of a given MAC address.

Author:
Denis BEURIVE
Parameters:
mac  Pointer to a zero terminated string of characters that represents the modem's MAC address.
Returns:
The function returns a integer that represents the modem's ID.

Definition at line 281 of file config.c.

References get_number_of_modem_conf().

char* modem_conf_get_tag_name int    id
 

Returns the tag name of a given MAC address, representd by its ID.

Author:
Denis BEURIVE
Parameters:
id  ID of the MAC address (as returned by the function modem_conf_get_id()).
Returns:
The function returns a pointer to a zero terminated string of characters that represents the tag name.

Definition at line 297 of file config.c.

References modem_conf_struct::tag_name.

int modem_conf_is_autoconf int    id
 

Returns a value that indicates if a given modem supports auto-configuration.

Author:
Denis BEURIVE
Parameters:
id  ID of the MAC address (as returned by the function modem_conf_get_id()).
Returns:
The function returns one of the following values:
  • 1: The modem supports auto-configuration.
  • 0: The modem does not support auto-configuration.

Definition at line 309 of file config.c.

Referenced by main().

int parse_configuration_file char *    path,
int *    err
 

Load a given configuration file.

Author:
Denis BEURIVE
Parameters:
path  Path to the configuration file to load.
err  Pointer to an integer that will be used to store the value of 'errno' if an error occured.
Returns:
Upon successful completion, the function returns tha value PARSE_CONFIGURATION_OK. Otherwise the function may return one of the following values:
  • PARSE_CONFIGURATION_NO_MEM: Could not allocate memory.
  • PARSE_CONFIGURATION_FILE_NOT_FOUND: Could not open configuration file. "errno' is set.
  • PARSE_CONFIGURATION_SYNTAX_ERROR: Syntax error in configuration file.
  • PARSE_CONFIGURATION_DUPLICATED_TAG: Configuration contains a duplicated tag.
  • PARSE_CONFIGURATION_DLL_OPEN_ERROR: Could not load DLL.
  • PARSE_CONFIGURATION_DLL_INVALID: DLL is not valid.
  • PARSE_CONFIGURATION_MODEM_CONF_NOT_VALID: Modem's configuration record is not valid.
  • PARSE_CONFIGURATION_OK: Success.
Warning:
  • If the returned value is PARSE_CONFIGURATION_NO_MEM, the module does not free allocated memory. You should abort the program.
  • If the returned value is PARSE_CONFIGURATION_FILE_NOT_FOUND, PARSE_CONFIGURATION_SYNTAX_ERROR, PARSE_CONFIGURATION_DUPLICATED_TAG, PARSE_CONFIGURATION_DLL_OPEN_ERROR, PARSE_CONFIGURATION_DLL_INVALID, PARSE_CONFIGURATION_MODEM_CONF_NOT_VALID, the module free all allocated memory.
Remarks:
In case you think that the same DLL is loaded multiple times, consider this: Only a single copy of an shared library file is brought into the address space, even if dlopen is invoked multiple times in reference to the file, and even if different pathnames are used to reference the file.

Definition at line 171 of file config.c.

References allochtab, modem_conf_struct::calculate_mac_address, config_compare_user_data(), config_free_user_data(), CONFIG_H_ERROR_SIZE, config_hash_function(), configin, configlex(), modem_conf_struct::dll, dummy_mac_processor(), free_all_configuration_data(), get_number_of_modem_conf(), htab, modem_conf_struct::id, last_error, MODEM_CONF_ACTION_SIZE, MODEM_CONF_AUTOCONF_SIZE, MODEM_CONF_IDENTIFIER_SIZE, MODEM_CONF_TAG_NAME_SIZE, nb_modem, PARSE_CONFIGURATION_DLL_INVALID, PARSE_CONFIGURATION_DLL_OPEN_ERROR, PARSE_CONFIGURATION_DUPLICATED_TAG, PARSE_CONFIGURATION_FILE_NOT_FOUND, PARSE_CONFIGURATION_MODEM_CONF_NOT_VALID, PARSE_CONFIGURATION_NO_MEM, PARSE_CONFIGURATION_OK, and PARSE_CONFIGURATION_SYNTAX_ERROR.

Referenced by configuration_load(), and load_mysql_configuration_from_file().


Generated on Mon Jun 19 12:31:06 2006 for MyDhcp_V2 by doxygen1.2.15