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 Sep 26, 2024
1 parent be62aa6 commit a19d368
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
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
33 changes: 19 additions & 14 deletions src/manage_sql_nvts.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "manage.h"
#include "openvasd/openvasd.h"
#include "openvasd/jsonutils.h"
#include "util/jsonpull.h"
#define _GNU_SOURCE

#include <assert.h>
Expand Down Expand Up @@ -2155,9 +2156,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 +2205,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 +2232,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 +2668,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 +2970,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 a19d368

Please sign in to comment.