Skip to content

Commit

Permalink
Apply suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Nov 8, 2024
1 parent ae963be commit ed1bc24
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions openvasd/openvasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,20 @@ openvasd_curlm_handler_new (void)
* @param h Openvasd curl handler to clean
*/
static void
openvasd_curlm_handler_close (openvasd_curlm_t **h)
openvasd_curlm_handler_close (openvasd_curlm_t *h)

Check warning on line 155 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L155

Added line #L155 was not covered by tests
{
int queued = 0;

Check warning on line 157 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L157

Added line #L157 was not covered by tests

/* when an easy handle has completed, remove it */
CURLMsg *msg = curl_multi_info_read ((*h)->h, &queued);
CURLMsg *msg = curl_multi_info_read (h->h, &queued);

Check warning on line 160 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L160

Added line #L160 was not covered by tests
if (msg)
{
if (msg->msg == CURLMSG_DONE)
{
curl_multi_remove_handle ((*h)->h, msg->easy_handle);
curl_multi_remove_handle (h->h, msg->easy_handle);
curl_easy_cleanup (msg->easy_handle);
curl_slist_free_all ((*h)->customheader);
curl_multi_cleanup ((*h)->h);
curl_slist_free_all (h->customheader);
curl_multi_cleanup (h->h);
return;

Check warning on line 169 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L165-L169

Added lines #L165 - L169 were not covered by tests
}
g_warning ("%s: Not possible to clean up the curl handler", __func__);

Check warning on line 171 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L171

Added line #L171 was not covered by tests
Expand Down Expand Up @@ -194,13 +194,16 @@ openvasd_vt_stream_new (void)
* @param s The string struct to be freed
*/
static void
openvasd_vt_stream_cleanup (openvasd_vt_stream_t s)
openvasd_vt_stream_free (openvasd_vt_stream_t s)

Check warning on line 197 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L197

Added line #L197 was not covered by tests
{
if (s)
g_free (s->ptr);
if (s == NULL)
return;

Check warning on line 200 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L200

Added line #L200 was not covered by tests

g_free (s->ptr);

Check warning on line 202 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L202

Added line #L202 was not covered by tests
if (s->curl_hnd)
openvasd_curlm_handler_close (&(s->curl_hnd));
openvasd_curlm_handler_close (s->curl_hnd);

Check warning on line 204 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L204

Added line #L204 was not covered by tests

g_free (s);

Check warning on line 206 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L206

Added line #L206 was not covered by tests
}

/** @brief Reinitialize the string struct to hold the response
Expand Down Expand Up @@ -312,7 +315,7 @@ openvasd_connector_free (openvasd_connector_t conn)
g_free (conn->server);
g_free (conn->host);
g_free (conn->scan_id);
openvasd_vt_stream_cleanup (conn->stream_resp);
openvasd_vt_stream_free (conn->stream_resp);
g_free (conn);
conn = NULL;

Check warning on line 320 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L311-L320

Added lines #L311 - L320 were not covered by tests

Expand Down Expand Up @@ -600,7 +603,8 @@ openvasd_get_version (openvasd_connector_t conn)
response = g_malloc0 (sizeof (struct openvasd_response));

Check warning on line 603 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L603

Added line #L603 was not covered by tests

customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, HEAD, "/", NULL, customheader, &err)) == NULL)
hnd = handler (conn, HEAD, "/", NULL, customheader, &err);

Check warning on line 606 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L605-L606

Added lines #L605 - L606 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
response->code = RESP_CODE_ERR;
Expand Down Expand Up @@ -644,7 +648,8 @@ openvasd_get_vt_stream_init (openvasd_connector_t conn)

path = g_string_new ("/vts?information=1");
customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, GET, path->str, NULL, customheader, &err)) == NULL)
hnd = handler (conn, GET, path->str, NULL, customheader, &err);

Check warning on line 651 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L649-L651

Added lines #L649 - L651 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand All @@ -657,9 +662,6 @@ openvasd_get_vt_stream_init (openvasd_connector_t conn)
h = curl_multi_init ();
curl_multi_add_handle (h, hnd);

Check warning on line 663 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L662-L663

Added lines #L662 - L663 were not covered by tests

if (conn->stream_resp->curl_hnd->h == NULL)
conn->stream_resp->curl_hnd->h = openvasd_curlm_handler_new ();

conn->stream_resp->curl_hnd->h = h;
conn->stream_resp->curl_hnd->customheader = customheader;

Check warning on line 666 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L665-L666

Added lines #L665 - L666 were not covered by tests

Expand Down Expand Up @@ -740,7 +742,8 @@ openvasd_get_vts (openvasd_connector_t conn)

path = g_string_new ("/vts?information=1");
customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, GET, path->str, NULL, customheader, &err)) == NULL)
hnd = handler (conn, GET, path->str, NULL, customheader, &err);

Check warning on line 745 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L743-L745

Added lines #L743 - L745 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand Down Expand Up @@ -780,7 +783,8 @@ openvasd_start_scan (openvasd_connector_t conn, gchar *data)
response = g_malloc0 (sizeof (struct openvasd_response));

Check warning on line 783 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L783

Added line #L783 was not covered by tests

customheader = init_customheader (conn->apikey, TRUE);
if ((hnd = handler (conn, POST, "/scans", data, customheader, &err)) == NULL)
hnd = handler (conn, POST, "/scans", data, customheader, &err);

Check warning on line 786 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L785-L786

Added lines #L785 - L786 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
response->code = RESP_CODE_ERR;
Expand Down Expand Up @@ -844,9 +848,9 @@ openvasd_start_scan (openvasd_connector_t conn, gchar *data)

openvasd_reset_vt_stream (conn);
customheader = init_customheader (conn->apikey, TRUE);
if ((hnd = handler (conn, POST, path->str, "{\"action\": \"start\"}",
customheader, &err))
== NULL)
hnd = handler (conn, POST, path->str, "{\"action\": \"start\"}", customheader,

Check warning on line 851 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L849-L851

Added lines #L849 - L851 were not covered by tests
&err);
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand Down Expand Up @@ -901,9 +905,9 @@ openvasd_stop_scan (openvasd_connector_t conn)
}

customheader = init_customheader (conn->apikey, TRUE);
if ((hnd = handler (conn, POST, path->str, "{\"action\": \"stop\"}",
customheader, &err))
== NULL)
hnd = handler (conn, POST, path->str, "{\"action\": \"stop\"}", customheader,

Check warning on line 908 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L907-L908

Added lines #L907 - L908 were not covered by tests
&err);
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand Down Expand Up @@ -955,7 +959,8 @@ openvasd_get_scan_results (openvasd_connector_t conn, long first, long last)
}

customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, GET, path->str, NULL, customheader, &err)) == NULL)
hnd = handler (conn, GET, path->str, NULL, customheader, &err);

Check warning on line 962 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L961-L962

Added lines #L961 - L962 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand Down Expand Up @@ -1236,7 +1241,8 @@ openvasd_get_scan_status (openvasd_connector_t conn)
}

customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, GET, path->str, NULL, customheader, &err)) == NULL)
hnd = handler (conn, GET, path->str, NULL, customheader, &err);

Check warning on line 1244 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1243-L1244

Added lines #L1243 - L1244 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand Down Expand Up @@ -1480,8 +1486,8 @@ openvasd_delete_scan (openvasd_connector_t conn)
}

customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, DELETE, path->str, NULL, customheader, &err))
== NULL)
hnd = handler (conn, DELETE, path->str, NULL, customheader, &err);

Check warning on line 1489 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1488-L1489

Added lines #L1488 - L1489 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand Down Expand Up @@ -1517,8 +1523,8 @@ openvasd_get_health_alive (openvasd_connector_t conn)
response = g_malloc0 (sizeof (struct openvasd_response));

Check warning on line 1523 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1523

Added line #L1523 was not covered by tests

customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, GET, "/health/alive", NULL, customheader, &err))
== NULL)
hnd = handler (conn, GET, "/health/alive", NULL, customheader, &err);

Check warning on line 1526 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1525-L1526

Added lines #L1525 - L1526 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
response->code = RESP_CODE_ERR;
Expand Down Expand Up @@ -1551,10 +1557,9 @@ openvasd_get_health_ready (openvasd_connector_t conn)

response = g_malloc0 (sizeof (struct openvasd_response));

Check warning on line 1558 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1558

Added line #L1558 was not covered by tests

// openvasd_vt_stream_init (conn->vt_stream);
customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, GET, "/health/ready", NULL, customheader, &err))
== NULL)
hnd = handler (conn, GET, "/health/ready", NULL, customheader, &err);

Check warning on line 1561 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1560-L1561

Added lines #L1560 - L1561 were not covered by tests
if (hnd == NULL)
{
response->code = RESP_CODE_ERR;
response->body = err;
Expand Down Expand Up @@ -1587,8 +1592,8 @@ openvasd_get_health_started (openvasd_connector_t conn)
response = g_malloc0 (sizeof (struct openvasd_response));

Check warning on line 1592 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1592

Added line #L1592 was not covered by tests

customheader = init_customheader (conn->apikey, FALSE);
if ((hnd = handler (conn, GET, "/health/started", NULL, customheader, &err))
== NULL)
hnd = handler (conn, GET, "/health/started", NULL, customheader, &err);

Check warning on line 1595 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1594-L1595

Added lines #L1594 - L1595 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
response->code = RESP_CODE_ERR;
Expand Down

0 comments on commit ed1bc24

Please sign in to comment.