| APT2 Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
#include <apt.h> #define APT_CONFIGURATION_ERROR enum AptConfigurationError; AptConfiguration; AptConfiguration * apt_configuration_new (void); AptConfiguration * apt_configuration_ref (AptConfiguration *configuration); void apt_configuration_unref (AptConfiguration *configuration); GOptionGroup * apt_configuration_get_option_group (AptConfiguration *configuration); gboolean apt_configuration_init_defaults (AptConfiguration *configuration,GError **error); const gchar * apt_configuration_get (AptConfiguration *configuration,const gchar *name); void apt_configuration_set (AptConfiguration *configuration,const gchar *name,const gchar *value); gboolean apt_configuration_get_boolean (AptConfiguration *configuration,const gchar *name); gchar * apt_configuration_get_file (AptConfiguration *configuration,const gchar *name); gint apt_configuration_get_int (AptConfiguration *configuration,const gchar *name); const gchar ** apt_configuration_get_list (AptConfiguration *configuration,const gchar *name,gsize *length); gboolean apt_configuration_parse_file (AptConfiguration *configuration,const gchar *filename,GError **error); gboolean apt_configuration_parse_dir (AptConfiguration *configuration,const gchar *dirname,GError **error); gboolean apt_configuration_parse_text (AptConfiguration *configuration,const gchar *text,GError **error); gchar * apt_configuration_dumps (AptConfiguration *configuration);
The APT configuration system is basically a tree of options. Each option can have zero or more sub-options and these suboptions can either all have a name or no name (which makes them list elements). The levels of the tree are seperated by two colons, like C++.
#define APT_CONFIGURATION_ERROR apt_configuration_error_quark()
The error domain for configuration parsing.
typedef enum {
APT_CONFIGURATION_ERROR_FAILED
} AptConfigurationError;
Error values for the configuration subsystem.
typedef struct _AptConfiguration AptConfiguration;
AptConfiguration is an opaque data type which may only be accessed using the following functions.
AptConfiguration * apt_configuration_new (void);
Creates a new AptConfiguration.
Returns : |
A newly allocated AptConfiguration with reference count 1. |
AptConfiguration * apt_configuration_ref (AptConfiguration *configuration);
Increments the reference count of configuration.
|
An AptConfiguration |
Returns : |
configuration |
void apt_configuration_unref (AptConfiguration *configuration);
Decrements the reference count of configuration. If the reference count
drops to 0, the memory pointed to by configuration will be freed.
|
An AptConfiguration |
GOptionGroup * apt_configuration_get_option_group (AptConfiguration *configuration);
Gets a new GOptionGroup for configuration containing the options
'config-file' (-c) and 'option' (-o).
|
An AptConfiguration |
Returns : |
A newly allocated GOptionGroup for configuration. It holds
its own reference to configuration. |
gboolean apt_configuration_init_defaults (AptConfiguration *configuration,GError **error);
Initializes configuration using default values and by reading the
configuration file specified by the environment variable APT_CONFIG
and then the file specified by the option Dir::Etc::main and the files
in the directory specified by the option Dir::Etc::parts.
|
An AptConfiguration |
|
Return location to store a GError. |
Returns : |
TRUE if everything succeded, FALSE otherwise. |
const gchar * apt_configuration_get (AptConfiguration *configuration,const gchar *name);
Gets the value of the option name and returns it as a constant
string. Please note that the returned string may be freed at any
time a new value for this option is set. Thus, if you want to keep
the value around, call g_strdup() on it. If the requested option is
not set, NULL is returned.
|
An AptConfiguration. |
|
The name of the option that shall be retrieved. |
Returns : |
A constant string containing the value or NULL if the
option is not set. |
void apt_configuration_set (AptConfiguration *configuration,const gchar *name,const gchar *value);
Sets the configuration option name to value. The parameter name is
pushed to lower-case before insertion, and both parameters are duplicated
before they are inserted into the hashtable.
|
An AptConfiguration |
|
The name of the option that should be set. |
|
The value that the option should be set to. |
gboolean apt_configuration_get_boolean (AptConfiguration *configuration,const gchar *name);
Calls apt_configuration_get() and converts the result into a
gboolean. Valid boolean values are "no", "false", "off", "disable",
"without", and "0" for FALSE; and "yes", "true", "on", "enable",
"with", and 1 for TRUE. If the value of the option name is not
one of those strings or if the option name is not set, FALSE
is returned.
|
An AptConfiguration. |
|
The name of the option that shall be retrieved. |
Returns : |
The boolean value stored at name or FALSE if name is
not set or is not a valid boolean value. |
gchar * apt_configuration_get_file (AptConfiguration *configuration,const gchar *name);
Lookup a file in the configuration space. This lookups the value
at name and goes upwards in the configuration tree, prepending
every value found until the path is absolute or a relative path
starting with "./" or "../". If a special configuration option
named "rootdir" exists, its value is prepended to the string.
|
An AptConfiguration |
|
The name of the option to be looked up |
Returns : |
A string which contains the path to the file and
must be freed using g_free() when no longer required. |
gint apt_configuration_get_int (AptConfiguration *configuration,const gchar *name);
Calls apt_configuration_get() and converts the result into an
integer.
|
An AptConfiguration. |
|
The name of the option that shall be retrieved. |
Returns : |
The integer stored at name, or 0 if the option does not
exist or is no integer. |
const gchar ** apt_configuration_get_list (AptConfiguration *configuration,const gchar *name,gsize *length);
Gets the list stored at the given option.
|
An AptConfiguration |
|
The name of the list option, including the :: suffix. |
|
Location to store the length of the list. |
Returns : |
A list of strings of the values at the given option. |
gboolean apt_configuration_parse_file (AptConfiguration *configuration,const gchar *filename,GError **error);
Parses the configuration file located at filename and inserts the
option it defines into configuration.
|
An AptConfiguration. |
|
The name of the file which shall be parsed. |
|
Location to store an error. |
Returns : |
TRUE if the file could be parsed, FALSE otherwise. |
gboolean apt_configuration_parse_dir (AptConfiguration *configuration,const gchar *dirname,GError **error);
Parses the configuration files located in the directory dirname and
insert the options they define into configuration.
|
An AptConfiguration. |
|
The name of the directory containing the files to be parsed. |
|
Location to store an error. |
Returns : |
TRUE if all files could be parsed, FALSE otherwise. |
gboolean apt_configuration_parse_text (AptConfiguration *configuration,const gchar *text,GError **error);
Parses text which must be a string in the format of APT configuration
files and inserts the options it defines into configuration.
|
An AptConfiguration. |
|
The text that shall be parsed. |
|
Location to store an error. |
Returns : |
TRUE if the text could be parsed, FALSE otherwise. |
gchar * apt_configuration_dumps (AptConfiguration *configuration);
Gets a string describing the options held in configuration that can
be parsed by apt_configuration_parse_text().
|
An AptConfiguration. |