Greenbone Vulnerability Management Libraries  11.0.0
prefs.h File Reference

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

#include <glib.h>
Include dependency graph for prefs.h:

Go to the source code of this file.

Functions

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

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 72 of file prefs.c.

73 {
74  if (!global_prefs)
75  prefs_init ();
76 
77  return global_prefs;
78 }

References global_prefs, and prefs_init().

Here is the call 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 147 of file prefs.c.

148 {
149  settings_iterator_t settings;
150  char buffer[2048];
151 
152  if (!global_prefs)
153  prefs_init ();
154 
155  strncpy (buffer, config, sizeof (buffer));
156  if (!init_settings_iterator_from_file (&settings, buffer, "Misc"))
157  {
158  while (settings_iterator_next (&settings))
159  prefs_set (settings_iterator_name (&settings),
160  settings_iterator_value (&settings));
161 
162  cleanup_settings_iterator (&settings);
163  }
164 
165  prefs_set ("config_file", buffer);
166 }

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().

Here is the call graph for this function:

◆ prefs_dump()

void prefs_dump ( void  )

Dump the preferences to stdout.

Definition at line 172 of file prefs.c.

173 {
174  void *name, *value;
175  GHashTableIter iter;
176 
177  if (global_prefs)
178  {
179  g_hash_table_iter_init (&iter, global_prefs);
180  while (g_hash_table_iter_next (&iter, &name, &value))
181  {
182  printf ("%s = %s\n", (char *) name, (char *) value);
183  }
184  }
185 }

References global_prefs, and nvti::name.

◆ 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 90 of file prefs.c.

91 {
92  if (!global_prefs)
93  prefs_init ();
94 
95  return g_hash_table_lookup (global_prefs, key);
96 }

References global_prefs, and prefs_init().

Referenced by prefs_nvt_timeout().

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 110 of file prefs.c.

111 {
112  gchar *str;
113 
114  if (!global_prefs)
115  prefs_init ();
116 
117  str = g_hash_table_lookup (global_prefs, key);
118  if (str && !strcmp (str, "yes"))
119  return 1;
120 
121  return 0;
122 }

References global_prefs, and prefs_init().

Here is the call graph for this function:

◆ prefs_nvt_timeout()

int prefs_nvt_timeout ( const char *  oid)

Returns the timeout defined by the client or 0 if none was set.

Parameters
oidOID of NVT to ask timeout value of.
Returns
0 if no timeout for the NVT oid was found, timeout in seconds otherwise.

Definition at line 196 of file prefs.c.

197 {
198  char *pref_name = g_strdup_printf ("timeout.%s", oid);
199  const char *val = prefs_get (pref_name);
200  int timeout = (val ? atoi (val) : 0);
201 
202  g_free (pref_name);
203 
204  return timeout;
205 }

References nvti::oid, prefs_get(), and nvti::timeout.

Here is the call graph for this function:

◆ 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 133 of file prefs.c.

134 {
135  if (!global_prefs)
136  prefs_init ();
137 
138  g_hash_table_insert (global_prefs, g_strdup (key), g_strdup (value));
139 }

References global_prefs, and prefs_init().

Referenced by prefs_config(), and prefs_init().

Here is the call graph for this function:
Here is the caller graph for this function:
prefs_init
static void prefs_init(void)
Initializes the preferences structure. If it was already initialized, remove old settings and start f...
Definition: prefs.c:46
settings_iterator_t
Struct holding options to iterate over a GKeyFile.
Definition: settings.h:49
init_settings_iterator_from_file
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:106
prefs_set
void prefs_set(const gchar *, const gchar *)
Set a string preference value via a key.
Definition: prefs.c:133
settings_iterator_value
const gchar * settings_iterator_value(settings_iterator_t *iterator)
Get the value from a settings iterator.
Definition: settings.c:187
cleanup_settings_iterator
void cleanup_settings_iterator(settings_iterator_t *iterator)
Cleanup a settings iterator.
Definition: settings.c:144
prefs_get
const gchar * prefs_get(const gchar *key)
Get a string preference value via a key.
Definition: prefs.c:90
global_prefs
static GHashTable * global_prefs
Definition: prefs.c:35
settings_iterator_name
const gchar * settings_iterator_name(settings_iterator_t *iterator)
Get the name from a settings iterator.
Definition: settings.c:174
settings_iterator_next
gboolean settings_iterator_next(settings_iterator_t *iterator)
Increment an iterator.
Definition: settings.c:158