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 1b159ff
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 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 Down Expand Up @@ -740,7 +745,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 748 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L746-L748

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

Check warning on line 786 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L786

Added line #L786 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 789 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L788-L789

Added lines #L788 - L789 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
response->code = RESP_CODE_ERR;
Expand Down Expand Up @@ -844,9 +851,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 854 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L852-L854

Added lines #L852 - L854 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 +908,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 911 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L910-L911

Added lines #L910 - L911 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 +962,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 965 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L964-L965

Added lines #L964 - L965 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand Down Expand Up @@ -1236,7 +1244,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 1247 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1246-L1247

Added lines #L1246 - L1247 were not covered by tests
if (hnd == NULL)
{
curl_slist_free_all (customheader);
g_string_free (path, TRUE);
Expand Down Expand Up @@ -1480,8 +1489,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 1492 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1491-L1492

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

Check warning on line 1526 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1526

Added line #L1526 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 1529 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1528-L1529

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

response = g_malloc0 (sizeof (struct openvasd_response));

Check warning on line 1561 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1561

Added line #L1561 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 1564 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1563-L1564

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

Check warning on line 1595 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1595

Added line #L1595 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 1598 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L1597-L1598

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

0 comments on commit 1b159ff

Please sign in to comment.