Greenbone Vulnerability Management Libraries 22.32.0
prefs.h File Reference

Protos and data structures for NVT Information data sets. More...

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

Go to the source code of this file.

Functions

void prefs_config (const char *)
 Apply the configs from given file as preferences.
const gchar * prefs_get (const gchar *key)
 Get a string preference value via a key.
int prefs_get_bool (const gchar *key)
 Get a boolean expression of a preference value via a key.
void prefs_set (const gchar *, const gchar *)
 Set a string preference value via a key.
void prefs_dump (void)
 Dump the preferences to stdout.
int prefs_nvt_timeout (const char *)
GHashTable * preferences_get (void)
 Get the pointer to the global preferences structure. Eventually this function should not be used anywhere.

Detailed Description

Protos and data structures for NVT Information data sets.

This file contains the protos for prefs.c

Definition in file prefs.h.

Function Documentation

◆ preferences_get()

GHashTable * preferences_get ( void )

Get the pointer to the global preferences structure. Eventually this function should not be used anywhere.

Returns
Pointer to the global preferences structure.

Definition at line 81 of file prefs.c.

82{
83 if (!global_prefs)
84 prefs_init ();
85
86 return global_prefs;
87}
static void prefs_init(void)
Initializes the preferences structure. If it was already initialized, remove old settings and start f...
Definition prefs.c:40
static GHashTable * global_prefs
Definition prefs.c:29

References global_prefs, and prefs_init().

Referenced by Ensure(), and Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prefs_config()

void prefs_config ( const char * config)

Apply the configs from given file as preferences.

Parameters
configFilename of the configuration file.

Definition at line 156 of file prefs.c.

157{
158 settings_iterator_t settings;
159
160 if (!global_prefs)
161 prefs_init ();
162
163 if (!init_settings_iterator_from_file (&settings, config, "Misc"))
164 {
165 while (settings_iterator_next (&settings))
166 {
167 gchar *value;
168
169 value = settings_iterator_value (&settings);
170 prefs_set (settings_iterator_name (&settings), value);
171 g_free (value);
172 }
173
174 cleanup_settings_iterator (&settings);
175 }
176
177 prefs_set ("config_file", config);
178}
void prefs_set(const gchar *, const gchar *)
Set a string preference value via a key.
Definition prefs.c:142
gboolean settings_iterator_next(settings_iterator_t *iterator)
Increment an iterator.
Definition settings.c:150
void cleanup_settings_iterator(settings_iterator_t *iterator)
Cleanup a settings iterator.
Definition settings.c:136
int init_settings_iterator_from_file(settings_iterator_t *iterator, const gchar *filename, const gchar *group)
Initialise a settings iterator from a file.
Definition settings.c:98
gchar * settings_iterator_value(settings_iterator_t *iterator)
Get the value from a settings iterator.
Definition settings.c:179
const gchar * settings_iterator_name(settings_iterator_t *iterator)
Get the name from a settings iterator.
Definition settings.c:166
Struct holding options to iterate over a GKeyFile.
Definition settings.h:36

References cleanup_settings_iterator(), global_prefs, init_settings_iterator_from_file(), prefs_init(), prefs_set(), settings_iterator_name(), settings_iterator_next(), and settings_iterator_value().

Referenced by Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prefs_dump()

void prefs_dump ( void )

Dump the preferences to stdout.

Definition at line 184 of file prefs.c.

185{
186 void *name, *value;
187 GHashTableIter iter;
188
189 if (global_prefs)
190 {
191 g_hash_table_iter_init (&iter, global_prefs);
192 while (g_hash_table_iter_next (&iter, &name, &value))
193 {
194 printf ("%s = %s\n", (char *) name, (char *) value);
195 }
196 }
197}

References global_prefs.

◆ prefs_get()

const gchar * prefs_get ( const gchar * key)

Get a string preference value via a key.

Parameters
keyThe identifier for the preference.
Returns
A pointer to a string with the value for the preference. NULL in case for the key no preference was found or the preference is not of type string.

Definition at line 99 of file prefs.c.

100{
101 if (!global_prefs)
102 prefs_init ();
103
104 return g_hash_table_lookup (global_prefs, key);
105}

References global_prefs, and prefs_init().

Referenced by Ensure(), Ensure(), Ensure(), Ensure(), and Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prefs_get_bool()

int prefs_get_bool ( const gchar * key)

Get a boolean expression of a preference value via a key.

Parameters
keyThe identifier for the preference.
Returns
1 if the value is considered to represent "true" and 0 if the value is considered to represent "false". If the preference is of type string, value "yes" is true, anything else is false. Any other type or non-existing key is false.

Definition at line 119 of file prefs.c.

120{
121 gchar *str;
122
123 if (!global_prefs)
124 prefs_init ();
125
126 str = g_hash_table_lookup (global_prefs, key);
127 if (str && !strcmp (str, "yes"))
128 return 1;
129
130 return 0;
131}

References global_prefs, and prefs_init().

Referenced by Ensure(), Ensure(), and Ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prefs_nvt_timeout()

int prefs_nvt_timeout ( const char * )

◆ prefs_set()

void prefs_set ( const gchar * key,
const gchar * value )

Set a string preference value via a key.

Parameters
keyThe identifier for the preference. A copy of this will be created if necessary.
valueThe value to set. A copy of this will be created.

Definition at line 142 of file prefs.c.

143{
144 if (!global_prefs)
145 prefs_init ();
146
147 g_hash_table_insert (global_prefs, g_strdup (key), g_strdup (value));
148}

References global_prefs, and prefs_init().

Referenced by Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), prefs_config(), and prefs_init().

Here is the call graph for this function:
Here is the caller graph for this function: