OpenVAS Manager  7.0.3~git
iterator.h File Reference
#include "lsc_crypt.h"
#include <glib.h>
Include dependency graph for iterator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  iterator
 A generic SQL iterator. More...
 

Typedefs

typedef long long int resource_t
 A resource, like a task or target. More...
 
typedef struct sql_stmt sql_stmt_t
 A prepared SQL statement. More...
 
typedef struct iterator iterator_t
 

Functions

void cleanup_iterator (iterator_t *)
 Cleanup an iterator. More...
 
gboolean next (iterator_t *)
 Increment an iterator. More...
 

Typedef Documentation

◆ iterator_t

typedef struct iterator iterator_t

Definition at line 60 of file iterator.h.

◆ resource_t

typedef long long int resource_t

A resource, like a task or target.

Definition at line 42 of file iterator.h.

◆ sql_stmt_t

typedef struct sql_stmt sql_stmt_t

A prepared SQL statement.

Definition at line 47 of file iterator.h.

Function Documentation

◆ cleanup_iterator()

void cleanup_iterator ( iterator_t iterator)

Cleanup an iterator.

Parameters
[in]iteratorIterator.

Definition at line 664 of file sql.c.

665 {
666  if (iterator == NULL)
667  {
668  g_warning ("%s: null iterator pointer.\n", __FUNCTION__);
669  return;
670  }
671 
672  if (iterator->prepared == 0)
674  if (iterator->crypt_ctx)
675  {
677  iterator->crypt_ctx = NULL;
678  }
679 }
A generic SQL iterator.
Definition: iterator.h:52
lsc_crypt_ctx_t crypt_ctx
Encryption context.
Definition: iterator.h:57
sql_stmt_t * stmt
SQL statement.
Definition: iterator.h:54
int prepared
Prepared flag.
Definition: iterator.h:56
void lsc_crypt_release(lsc_crypt_ctx_t ctx)
Release an LSC encryption context.
Definition: lsc_crypt.c:528
void sql_finalize(sql_stmt_t *)
Free a prepared statement.
Definition: sql_pg.c:824

Referenced by acl_users_with_access_sql(), check_db_sequences(), check_generate_scripts(), delete_reports(), get_nvti_xml(), get_ovaldi_files(), migrate_122_to_123(), migrate_12_to_13(), migrate_143_to_144(), migrate_153_to_154(), migrate_156_to_157(), migrate_158_to_159(), migrate_160_to_161(), migrate_165_to_166(), migrate_16_to_17(), migrate_19_to_20(), migrate_1_to_2(), migrate_21_to_22(), migrate_35_to_36(), migrate_3_to_4(), migrate_4_to_5_copy_data(), migrate_55_to_56(), migrate_9_to_10(), refresh_nvt_cves(), sql_rename_column(), and task_observers().

Here is the caller graph for this function:

◆ next()

gboolean next ( iterator_t iterator)

Increment an iterator.

Parameters
[in]iteratorIterator.
Returns
TRUE if there was a next item, else FALSE.

Definition at line 689 of file sql.c.

690 {
691  int ret;
692 
693  if (iterator->done) return FALSE;
694 
696  while (1)
697  {
698  ret = sql_exec_internal (1, iterator->stmt);
699  if (ret == 0)
700  {
701  iterator->done = TRUE;
702  return FALSE;
703  }
704  if (ret == -1)
705  {
706  if (log_errors)
707  g_warning ("%s: sql_exec_internal failed\n", __FUNCTION__);
708  abort ();
709  }
710  if (ret == -2)
711  {
712  /* Busy or locked, with statement reset. Just try step again like
713  * we used to do in sql_exec_internal. We're not supposed to do this
714  * for SQLite, but it would mean quite a bit of reworking in the
715  * callers to be able to handle this case. */
716  g_warning ("%s: stepping after reset\n", __FUNCTION__);
717  continue;
718  }
719  if (ret == 2)
720  {
721  /* Schema changed, for example an internal change due to a VACUUM.
722  * Retrying will result in the same error, so abort. We lock
723  * exclusively around the VACUUM in --optimize, so hopefully when
724  * using --optimize the schema error will happen earlier, in the
725  * the init function for the iterator.
726  *
727  * This only applies to SQLite3. */
728  g_warning ("%s: schema error.\n"
729  " This is possibly due to running VACUUM while Manager\n"
730  " is running. Restart Manager. In future use\n"
731  " --optimize=vacuum instead of running VACUUM"
732  " directly.\n",
733  __FUNCTION__);
734  abort ();
735  }
736  break;
737  }
738  assert (ret == 1);
739  return TRUE;
740 }
A generic SQL iterator.
Definition: iterator.h:52
int log_errors
Whether to log errors.
Definition: sql.c:62
lsc_crypt_ctx_t crypt_ctx
Encryption context.
Definition: iterator.h:57
gboolean done
End flag.
Definition: iterator.h:55
int sql_exec_internal(int, sql_stmt_t *)
Execute a prepared statement.
Definition: sql_pg.c:482
void lsc_crypt_flush(lsc_crypt_ctx_t ctx)
Flush an LSC encryption context.
Definition: lsc_crypt.c:586
sql_stmt_t * stmt
SQL statement.
Definition: iterator.h:54

Referenced by acl_users_with_access_sql(), buffer_aggregate_xml(), check_db_sequences(), check_generate_scripts(), get_nvti_xml(), get_ovaldi_files(), manage_schedule(), migrate_122_to_123(), migrate_12_to_13(), migrate_138_to_139(), migrate_143_to_144(), migrate_153_to_154(), migrate_156_to_157(), migrate_158_to_159(), migrate_160_to_161(), migrate_165_to_166(), migrate_168_to_169(), migrate_16_to_17(), migrate_19_to_20(), migrate_1_to_2(), migrate_21_to_22(), migrate_24_to_25(), migrate_35_to_36(), migrate_3_to_4(), migrate_4_to_5_copy_data(), migrate_55_to_56(), migrate_9_to_10(), refresh_nvt_cves(), sql_rename_column(), stop_active_tasks(), and task_observers().

Here is the caller graph for this function: