Skip to content

Commit

Permalink
new struct to be used with curl multiperform which allows the custom …
Browse files Browse the repository at this point in the history
…header list cleanup
  • Loading branch information
jjnicola committed Oct 16, 2024
1 parent 837d955 commit b33f2c2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
44 changes: 33 additions & 11 deletions openvasd/openvasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,30 +529,47 @@ openvasd_get_version (openvasd_connector_t *conn)
g_free (resp.ptr);
return response;

Check warning on line 530 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L529-L530

Added lines #L529 - L530 were not covered by tests
}

/**
* @brief Wrapps a CURLM * handler
* @brief Wrapps a CURLM * handler and the custom header.
*/
struct openvasd_curlm
{
CURLM *h;
struct curl_slist *customheader;
};

/**
* @brief Allocate openvasd curl handler
*
* @return Openvasd curl handler.
*/
openvasd_curlm_t
openvasd_curlm_t *
openvasd_curlm_handler_new (void)

Check warning on line 548 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L548

Added line #L548 was not covered by tests
{
CURLM *h = NULL;
return h;
return (openvasd_curlm_t *) g_malloc0 (sizeof (struct openvasd_curlm));

Check warning on line 550 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L550

Added line #L550 was not covered by tests
}

/**
* @brief Cleanup an openvasd curl handler
*
* @param h Openvasd curl handler to clean
*/
void
openvasd_curl_handler_close (openvasd_curlm_t *h)
openvasd_curlm_handler_close (openvasd_curlm_t *h)

Check warning on line 559 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L559

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

Check warning on line 561 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L561

Added line #L561 was not covered by tests

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

Check warning on line 564 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L564

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

Check warning on line 573 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L569-L573

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

Check warning on line 575 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L575

Added line #L575 was not covered by tests
Expand Down Expand Up @@ -598,7 +615,12 @@ openvasd_get_vts_stream_init (openvasd_connector_t *conn,

h = curl_multi_init ();
curl_multi_add_handle (h, hnd);

Check warning on line 617 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L616-L617

Added lines #L616 - L617 were not covered by tests
*mhnd = h;

if (mhnd == NULL)
mhnd = openvasd_curlm_handler_new ();

Check warning on line 620 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L620

Added line #L620 was not covered by tests

mhnd->h = h;
mhnd->customheader = customheader;

Check warning on line 623 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L622-L623

Added lines #L622 - L623 were not covered by tests

response->code = RESP_CODE_OK;
return response;

Check warning on line 626 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L625-L626

Added lines #L625 - L626 were not covered by tests
Expand All @@ -616,10 +638,10 @@ openvasd_get_vts_stream_init (openvasd_connector_t *conn,
* transmision finished. -1 on error
*/
int
openvasd_get_vts_stream (openvasd_curlm_t mhnd)
openvasd_get_vts_stream (openvasd_curlm_t *mhnd)

Check warning on line 641 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L641

Added line #L641 was not covered by tests
{
static int running = 0;
CURLM *h = mhnd;
CURLM *h = mhnd->h;

Check warning on line 644 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L644

Added line #L644 was not covered by tests
if (!(h))
{
return -1;

Check warning on line 647 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L647

Added line #L647 was not covered by tests
Expand Down
10 changes: 5 additions & 5 deletions openvasd/openvasd.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ char *
openvasd_build_scan_config_json (openvasd_target_t *, GHashTable *, GSList *);

/* Curl multiperform wrapper */

typedef void *openvasd_curlm_t;
typedef struct openvasd_curlm openvasd_curlm_t;

/** @brief Define a string struct for storing the response.
*/
Expand All @@ -288,17 +287,18 @@ typedef struct openvasd_string
void
init_openvasd_stringstream (openvasd_stringstream *s);

openvasd_curlm_t
openvasd_curlm_t *
openvasd_curlm_handler_new (void);

void
openvasd_curl_handler_close (openvasd_curlm_t *);
openvasd_curlm_handler_close (openvasd_curlm_t *);

openvasd_resp_t
openvasd_get_vts_stream_init (openvasd_connector_t *, openvasd_curlm_t *,
openvasd_stringstream *);

int openvasd_get_vts_stream (openvasd_curlm_t);
int
openvasd_get_vts_stream (openvasd_curlm_t *);

nvti_t *
openvasd_parse_vt (gvm_json_pull_parser_t *, gvm_json_pull_event_t *);
Expand Down

0 comments on commit b33f2c2

Please sign in to comment.