From 5a18152680d0fc6000b171d0ba24267254b406a9 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 26 Sep 2024 10:38:51 -0300 Subject: [PATCH] Use json pull lib instead --- src/CMakeLists.txt | 1 + src/manage_sql.c | 1 - src/manage_sql_nvts.c | 40 +++++++++++++++++++++++----------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3cd3da580..79884d46e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/manage_sql.c b/src/manage_sql.c index 771dc721f..ce7ab40c6 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -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); diff --git a/src/manage_sql_nvts.c b/src/manage_sql_nvts.c index 934e21a6b..f0de40f62 100644 --- a/src/manage_sql_nvts.c +++ b/src/manage_sql_nvts.c @@ -26,11 +26,10 @@ /** * @brief Enable extra GNU functions. */ -#include "base/nvti.h" + +#include #include "glibconfig.h" #include "manage.h" -#include "openvasd/openvasd.h" -#include "openvasd/jsonutils.h" #define _GNU_SOURCE #include @@ -40,6 +39,9 @@ #include #include +#include +#include +#include #include #include "manage_sql_nvts.h" @@ -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; @@ -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) @@ -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); @@ -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); @@ -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,