FOSSology  4.4.0
Open Source License Compliance by Open Source Software
fossconfig.h File Reference

FOSSology library to read config file. More...

#include <glib.h>
Include dependency graph for fossconfig.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  fo_conf
 

Macros

#define PARSE_ERROR   1
 
#define RETRIEVE_ERROR   2
 

Enumerations

enum  fo_error_codes {
  fo_missing_file , fo_missing_group , fo_missing_key , fo_invalid_key ,
  fo_invalid_group , fo_invalid_file , fo_invalid_join , fo_load_config
}
 

Functions

fo_conffo_config_load (char *fname, GError **error)
 Load the configuration information from the provided file. More...
 
void fo_config_free (fo_conf *conf)
 Frees the memory associated with the internal configuration data structures. More...
 
void fo_config_join (fo_conf *dst, fo_conf *src, GError **error)
 Takes all groups and key from a fo_conf and adds them to another. More...
 
char * fo_config_get (fo_conf *conf, const char *group, const char *key, GError **error)
 Gets an element based on its group name and key name. If the group or key is not found, the error object is set and NULL is returned. More...
 
char * fo_config_get_list (fo_conf *conf, char *group, char *key, int idx, GError **error)
 
int fo_config_is_list (fo_conf *conf, char *group, char *key, GError **error)
 Checks if a particular value is a list or just a normal value. More...
 
int fo_config_list_length (fo_conf *conf, char *group, char *key, GError **error)
 Gets the length of the list associated with a particular list key. More...
 
char ** fo_config_group_set (fo_conf *conf, int *length)
 Gets the set of group names. More...
 
char ** fo_config_key_set (fo_conf *conf, char *group, int *length)
 Gets the set of key names for a particular group. More...
 
int fo_config_has_group (fo_conf *conf, char *group)
 Checks if the currently parsed configuration file has a specific group. More...
 
int fo_config_has_key (fo_conf *conf, char *group, char *key)
 Checks if the a specific group in the currently parsed configuration file has a specific key. More...
 
char * trim (char *ptext)
 Trimming whitespace. More...
 

Detailed Description

FOSSology library to read config file.

Definition in file fossconfig.h.

Macro Definition Documentation

◆ PARSE_ERROR

#define PARSE_ERROR   1

The parser error domain

Definition at line 16 of file fossconfig.h.

Enumeration Type Documentation

◆ fo_error_codes

Parser error codes

Enumerator
fo_missing_file 

File is missing.

fo_missing_group 

Required group is missing.

fo_missing_key 

Required key is missing.

fo_invalid_key 

Requested key is invalid.

fo_invalid_group 

Requested group is invalid.

fo_invalid_file 

File is invalid.

fo_invalid_join 

Join is invalid.

fo_load_config 

Unable to load config.

Definition at line 20 of file fossconfig.h.

Function Documentation

◆ fo_config_free()

void fo_config_free ( fo_conf conf)

Frees the memory associated with the internal configuration data structures.

Parameters
confThe fo_conf struct to free

Definition at line 506 of file fossconfig.c.

◆ fo_config_get()

char* fo_config_get ( fo_conf conf,
const char *  group,
const char *  key,
GError **  error 
)

Gets an element based on its group name and key name. If the group or key is not found, the error object is set and NULL is returned.

Parameters
conffo_conf object to load from
groupC string that is the name of the group
keyC string that is the name of the key for the key/value pair
Returns
The C string representation of the value

Definition at line 336 of file fossconfig.c.

◆ fo_config_get_list()

char* fo_config_get_list ( fo_conf conf,
char *  group,
char *  key,
int  idx,
GError **  error 
)

Keys can be associated with multiple values. If this is the case for a particular key, use this function instead of fo_config_get(). This also takes the index of the element in the list. Index work identically to standard c-array indices. It is important to note event though keys will appear as "key[]" in the config file this function just takes "key" as the key

Parameters
conffo_conf object to load from
groupC string that is the name of the group
keyC string that is the name of the key for the key/value pair
idxThe index of the value in the value list
errorobject that allows errors to propagate up the stack
Returns
c string representation of the value, once returned the caller owns this pointer. make sure to call g_free on it

Definition at line 382 of file fossconfig.c.

◆ fo_config_group_set()

char** fo_config_group_set ( fo_conf conf,
int *  length 
)

Gets the set of group names.

This function returns an array of strings that the user can iterate to get all group names. The user does not own the return of this function and should not free any of the memory associated with it.

Parameters
conffo_conf object to load from
lengthPointer allowing the number of groups to be returned
Returns
Array of strings containing all the group names

Definition at line 572 of file fossconfig.c.

◆ fo_config_has_group()

int fo_config_has_group ( fo_conf conf,
char *  group 
)

Checks if the currently parsed configuration file has a specific group.

Parameters
conffo_conf object to load from
groupThe name of the group to check for
Returns
1 if the group exists, 0 if it does not

Definition at line 651 of file fossconfig.c.

◆ fo_config_has_key()

int fo_config_has_key ( fo_conf conf,
char *  group,
char *  key 
)

Checks if the a specific group in the currently parsed configuration file has a specific key.

Parameters
groupThe group to check for the key
keyThe key to check for
Returns
1 if the group has the key, 0 if it does not

Definition at line 668 of file fossconfig.c.

◆ fo_config_is_list()

int fo_config_is_list ( fo_conf conf,
char *  group,
char *  key,
GError **  error 
)

Checks if a particular value is a list or just a normal value.

Parameters
conffo_conf object to load from
groupC string name of the group
keyC string name of the key
Returns
0 if it isn't a list, 1 if it is

Definition at line 439 of file fossconfig.c.

◆ fo_config_join()

void fo_config_join ( fo_conf dst,
fo_conf src,
GError **  error 
)

Takes all groups and key from a fo_conf and adds them to another.

This will iterate across the groups of a configuration and add each to another configuration. This joins the two configurations, making it possible to see multiple configuration files as a single configuration.

Parameters
dstThe destination for all the information in src
srcThe information that will be duplicated into dst
errorA location to returns errors from

Definition at line 531 of file fossconfig.c.

◆ fo_config_key_set()

char** fo_config_key_set ( fo_conf conf,
char *  group,
int *  length 
)

Gets the set of key names for a particular group.

This returns an array of strings that the user can iterate to get all of the key's for a particular group. This is useful if the keys are not known for a particular group. The array returned by this is owned by the config library and should not be freed by the caller.

Parameters
conffo_conf object to load from
groupC string name of the group
lengthPointer allowing the number of keys to be returned
Returns
Array of string containing all the key names for a group

Definition at line 614 of file fossconfig.c.

◆ fo_config_list_length()

int fo_config_list_length ( fo_conf conf,
char *  group,
char *  key,
GError **  error 
)

Gets the length of the list associated with a particular list key.

Parameters
groupC string name of the group
keyC string name of the key
Returns
The number of elements in the list, on error returns 0

Definition at line 475 of file fossconfig.c.

◆ fo_config_load()

fo_conf* fo_config_load ( char *  rawname,
GError **  error 
)

Load the configuration information from the provided file.

If the user has not done a fo_config_free since the last fo_config_load, this will make sure to call that first. In other words, it is assumed that if this is called the configuration file has changed and the user would like to use the new copy.

Parameters
rawnameThe name of the configuration file
errorObject that allows errors to propagate up the stack
Returns
0 for failure, 1 for success

Definition at line 275 of file fossconfig.c.

◆ trim()

char* trim ( char *  ptext)

Trimming whitespace.

Will trim the lead/trail space

Parameters
ptextThe string to trim
Returns
The string after trim

Definition at line 690 of file fossconfig.c.