Skip to content

Commit

Permalink
Use json pull lib instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Oct 11, 2024
1 parent 17f5f5f commit 5a18152
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pkg_check_modules (LIBGVM_BASE REQUIRED libgvm_base>=22.12)
pkg_check_modules (LIBGVM_UTIL REQUIRED libgvm_util>=22.12)
pkg_check_modules (LIBGVM_OSP REQUIRED libgvm_osp>=22.12)
pkg_check_modules (LIBGVM_GMP REQUIRED libgvm_gmp>=22.12)
pkg_check_modules (LIBGVM_OPENVASD REQUIRED libgvm_openvasd>=22.12)
pkg_check_modules (GNUTLS REQUIRED gnutls>=3.2.15)
pkg_check_modules (GLIB REQUIRED glib-2.0>=2.42)
pkg_check_modules (LIBBSD REQUIRED libbsd)
Expand Down
1 change: 0 additions & 1 deletion src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -60271,7 +60271,6 @@ add_openvasd_result_to_report (openvasd_result_t res, gpointer *results_aux)
res->detail_value, &hash_value,
rep_aux->hash_hostdetails))
{

insert_report_host_detail (rep_aux->report, host, "openvasd", "",
"Openvasd Host Detail", res->detail_name,
res->detail_value, hash_value);
Expand Down
40 changes: 23 additions & 17 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
/**
* @brief Enable extra GNU functions.
*/
#include "base/nvti.h"

#include <gvm/base/nvti.h>
#include "glibconfig.h"
#include "manage.h"
#include "openvasd/openvasd.h"
#include "openvasd/jsonutils.h"
#define _GNU_SOURCE

#include <assert.h>
Expand All @@ -40,6 +39,9 @@
#include <string.h>
#include <unistd.h>

#include <gvm/util/jsonpull.h>
#include <gvm/openvasd/openvasd.h>
#include <gvm/openvasd/vtparser.h>
#include <gvm/base/cvss.h>

#include "manage_sql_nvts.h"
Expand Down Expand Up @@ -2155,9 +2157,10 @@ update_nvts_from_vts (element_t *get_vts_response,
* @return 0 success, 1 VT integrity check failed, -1 error
*/
static int
update_nvts_from_json_vts (jreader_t *get_vts_response,
const gchar *scanner_feed_version,
int rebuild)
update_nvts_from_json_vts (gvm_json_pull_parser_t *parser,
gvm_json_pull_event_t *event,
const gchar *scanner_feed_version,
int rebuild)
{
GList *preferences;
int count_modified_vts, count_new_vts;
Expand Down Expand Up @@ -2203,7 +2206,7 @@ update_nvts_from_json_vts (jreader_t *get_vts_response,
vt_refs_batch = batch_start (vt_ref_insert_size);
vt_sevs_batch = batch_start (vt_sev_insert_size);

nvti_t *nvti = gvm_jnode_parse_vt (*get_vts_response);
nvti_t *nvti = openvasd_parse_vt (parser,event);
while (nvti)
{
if (nvti == NULL)
Expand All @@ -2230,7 +2233,7 @@ update_nvts_from_json_vts (jreader_t *get_vts_response,
g_list_free_full (preferences, (GDestroyNotify) preference_free);

nvti_free (nvti);
nvti = gvm_jnode_parse_vt (*get_vts_response);
nvti = openvasd_parse_vt (parser, event);
}

batch_end (vt_refs_batch);
Expand Down Expand Up @@ -2666,15 +2669,17 @@ update_nvt_cache_openvasd (gchar* openvasd_uuid, gchar *db_feed_version,
return -1;
}

jparser_t parser;
jreader_t reader;

parser = gvm_parse_jnode ();
gvm_read_jnode (resp->body, parser, &reader);
FILE *stream;
gvm_json_pull_event_t event;
gvm_json_pull_parser_t parser;

ret = update_nvts_from_json_vts (&reader, scanner_feed_version, rebuild);
gvm_close_jnode_reader (reader);
gvm_close_jnode_parser (parser);
stream = fmemopen (resp->body, strlen (resp->body), "r");
gvm_json_pull_parser_init (&parser, stream);
gvm_json_pull_event_init (&event);
ret = update_nvts_from_json_vts (&parser, &event, scanner_feed_version,
rebuild);
fclose(stream);
gvm_json_pull_parser_cleanup (&parser);

openvasd_response_free (resp);

Expand Down Expand Up @@ -2966,7 +2971,8 @@ manage_update_nvt_cache_osp (const gchar *update_socket)
sql_int ("SELECT count (*) FROM nvts;"));

#if OPENVASD == 1
ret = update_nvt_cache_openvasd (SCANNER_UUID_OPENVASD_DEFAULT, db_feed_version,
ret = update_nvt_cache_openvasd (SCANNER_UUID_OPENVASD_DEFAULT,
db_feed_version,
scanner_feed_version, 0);
#else
ret = update_nvt_cache_osp (update_socket, db_feed_version,
Expand Down

0 comments on commit 5a18152

Please sign in to comment.