Files
m241Neelima/components/ip_net2-6.9/ipike/src/ipike_configuration_parse.h
T
2026-07-30 11:19:44 +05:30

297 lines
11 KiB
C

/*
******************************************************************************
* INTERPEAK HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipike_configuration_parse.h,v $ $Revision: 1.5.12.3 $
* $Source: /home/interpeak/CVSRoot/ipike/src/ipike_configuration_parse.h,v $
* $Author: svc-cmnet $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
******************************************************************************
*/
#ifndef _IPIKE_CONFIGURATION_PARSE_H
#define _IPIKE_CONFIGURATION_PARSE_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/* Generic parsning of a the IKE configuration format. The format consists
* of a list of sections and entries.
*
* Format:
*
* <section> ::= <name> [<value>] {
* <entry>/<section>
* ...
* <entry>/<section>
* }
*
* <entry> ::= <name> <value>;
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
#include "ipike_config.h"
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
#define IPIKE_CONFIG_NONE 0
#define IPIKE_CONFIG_SECTION 1
#define IPIKE_CONFIG_ENTRY 2
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
typedef struct Ipike_config_struct
{
int type; /* Config type */
char* name; /* IP_NULL terminated string */
char* value; /* IP_NULL terminated string */
struct Ipike_config_struct** entries; /* IP_NULL terminated array of entries */
struct Ipike_config_struct** sections; /* IP_NULL terminated array of sections */
struct Ipike_config_struct* root; /* Pointer to top configuration root */
}
Ipike_config;
/*
****************************************************************************
* 6 FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipike_parse_get_string
*===========================================================================
* Description: Get next string and increase string pointer. The strings are
* separated with stop character. The destination string will
* be allocated with ipcom_malloc.
* Parameters: src - source string.
* stop - separator character.
* dst - destination string.
* Returns: IPIKE_SUCCESS, IPIKE_OUT_OF_MEMORY, IPIKE_CONF_PARSE_ERROR
*/
IP_GLOBAL Ipike_error
ipike_parse_get_string(const char** src, char stop, char** dst);
/*
*===========================================================================
* ipike_parse_get_first_string
*===========================================================================
* Description: Get next string. The strings are separated with stop
* character. The destination string will be allocated with
* ipcom_malloc.
* Parameters: src - source string.
* stop - separator character.
* dst - destination string.
* Returns: IPIKE_SUCCESS, IPIKE_OUT_OF_MEMORY, IPIKE_CONF_PARSE_ERROR
*/
IP_GLOBAL Ipike_error
ipike_parse_get_first_string(const char* src, char stop, char** dst);
/*
*===========================================================================
* ipike_parse_bool
*===========================================================================
* Description: Parse boolean value.
* Parameters: str - string representation of bool value.
* value - will receive bool value (TRUE/FALSE)
* Returns: IPIKE_SUCCESS
*/
IP_GLOBAL Ipike_error
ipike_parse_bool(const char* str, Ip_bool* value);
/*
*===========================================================================
* ipike_parse_int
*===========================================================================
* Description: Parse int value.
* Parameters: str - string representation of intgear value.
* value - will receive integear value.
* Returns: IPIKE_SUCCESS, IPIKE_CONF_INVALID_VALUE
*/
IP_GLOBAL Ipike_error
ipike_parse_int(const char* str, int *value);
/*
*===========================================================================
* ipike_parse_string
*===========================================================================
* Description: Parse string value.
* Parameters: str - string representation of value.
* value - will receive string value
* Returns: IPIKE_SUCCESS, IPIKE_OUT_OF_MEMORY
*/
IP_GLOBAL Ipike_error
ipike_parse_string(const char* str, const char** value);
/*
*===========================================================================
* ipike_parse_delete_string
*===========================================================================
* Description: Delete string allocated above.
* Parameters: str - the string to delete.
* Returns:
*/
IP_GLOBAL void
ipike_parse_delete_string(const char* str);
/*
*===========================================================================
* ipike_parse_number
*===========================================================================
* Description: Parse Ip_u32 value. Will return IPIKE_CONF_INVALID_VALUE if
* the string is invalid or a negative number.
*
* Parameters: str - string representation of Ip_u32 value.
* value - will receive Ip_u32 value.
* Returns: IPIKE_SUCCESS, IPIKE_CONF_INVALID_VALUE
*/
IP_GLOBAL Ipike_error
ipike_parse_number(const char* str, Ip_u32* value);
/*
*===========================================================================
* ipike_parse_number_default
*===========================================================================
* Description: Parse Ip_u32 value. The value will receive the default_value
* if it str is a NULL pointer otherwise it will return
* IPIKE_CONF_INVALID_VALUE if the string is invalid or
* a negative number.
*
* Parameters: str - string representation of Ip_u32 value.
* value - will receive Ip_u32 value.
* default_value - Default value
* Returns: IPIKE_SUCCESS, IPIKE_CONF_INVALID_VALUE
*/
IP_GLOBAL Ipike_error
ipike_parse_number_default(
const char* str,
Ip_u32* value,
Ip_u32 default_value);
/*
*===========================================================================
* ipike_parse_number_range
*===========================================================================
* Description: Parses a range of Ip_u32 values in the form 'X-Y' and places
* them in the 'low' and 'high' parameters.
* If the string only contains a single number it will be placed
* in both 'low' and high.
* Will return IPIKE_CONF_INVALID_VALUE if the string is invalid
* ,if it contains a negative number or if X > Y.
*
* Parameters: str - string representation of Ip_u32 value.
* low - will receive lower Ip_u32 value.
* high - will receive lower Ip_u32 value.
* Returns: IPIKE_SUCCESS, IPIKE_CONF_INVALID_VALUE
*/
IP_GLOBAL Ipike_error
ipike_parse_number_range(const char* str, Ip_u32* low, Ip_u32* high);
/*
*===========================================================================
* ipike_configuration_new
*===========================================================================
* Description: Parse the configuration data to a configuration structure.
* Free the configuration structure with ipike_parse_config.
* Parameters: parse_str - a string with the configuration.
* parse_str_len - Length of string.
* config - will retrieved the configuration structure.
* Returns: IPIKE_SUCCESS, IPIKE_OUT_OF_MEMORY, IPIKE_CONF_PARSE_ERROR
*/
IP_GLOBAL Ipike_error
ipike_configuration_new(
const char* parse_str,
Ip_size_t parse_str_len,
Ipike_config** config);
/*
*===========================================================================
* ipike_configuration_free
*===========================================================================
* Description: Free the configuration structure, generated by
* ipike_parse_config.
* Parameters: config - the configuration structure.
* Returns:
*/
IP_GLOBAL void
ipike_configuration_free(Ipike_config* config);
/*
*===========================================================================
* ipike_configuration_from_file
*===========================================================================
* Description: Parse the configuration file to a configuration structure.
* Free the configuration structure with ipike_parse_config.
* Parameters: filename - name of the configuration file.
* config - will retrieved the configuration structure.
* Returns: IPIKE_SUCCESS, IPIKE_OUT_OF_MEMORY, IPIKE_CONF_PARSE_ERROR
*/
IP_GLOBAL Ipike_error
ipike_configuration_from_file(const char* filename, Ipike_config** config);
/*
*===========================================================================
* ipike_configuration_get
*===========================================================================
* Description: Get a section/entry from the configuration. Separate with '/'
* to get sublevel section/entry.
* Parameters: name - name of the configuration section/entry.
* config - the configuration to search.
* Returns: IP_NULL or the found entry/section
*/
IP_GLOBAL Ipike_config*
ipike_configuration_get(const char* name, Ipike_config* config);
/*
*===========================================================================
* ipike_configuration_enum
*===========================================================================
* Description: Enumerate all entries/sections in the given config section.
* Parameters: config - the configuration to search.
* last - the last returned section or IP_NULL if first call.
* Returns: IP_NULL or the next entry/section
*/
IP_GLOBAL Ipike_config*
ipike_configuration_enum(Ipike_config* config, Ipike_config* last);
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/