Skip to content

Commit

Permalink
Doc: add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Aug 6, 2024
1 parent ecc4928 commit 4e98687
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 11 deletions.
56 changes: 53 additions & 3 deletions openvasd/jsonutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include <stdlib.h>
#include <unistd.h>

/**
* @brief VT categories
*/
typedef enum
{
ACT_INIT = 0,
Expand All @@ -31,6 +34,13 @@ typedef enum
ACT_END,
} nvt_category;

/**
* @brief Get the VT category type given the category as string
*
* @param cat The category as string.
*
* @return Integer representing the category type.
*/
static int
get_category_from_name (const char *cat)

Check warning on line 45 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L45

Added line #L45 was not covered by tests
{
Expand Down Expand Up @@ -60,6 +70,10 @@ get_category_from_name (const char *cat)
return -1;

Check warning on line 70 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L70

Added line #L70 was not covered by tests
}

/**
* @brief Get a new json parser object. It must be free with
* gvm_close_jnode_parser() by the caller.
*/
jparser_t
gvm_parse_jnode (void)

Check warning on line 78 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L78

Added line #L78 was not covered by tests
{
Expand All @@ -68,23 +82,39 @@ gvm_parse_jnode (void)
return parser;

Check warning on line 82 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L81-L82

Added lines #L81 - L82 were not covered by tests
}

/**
* @brief Create a JSON reader object
*
* @param[in] str JSON data as string to be read.
* @param[in] parse The JSON parser to be use for loading the JSON data.
* @param[out] read The JSON reader pointing to the begining of the data
*
* @return 0 on sucess, -1 otherwise. It must be free with
* gvm_close_jnode_parser() by the caller.
*/
int
gvm_read_jnode (const char *str, jparser_t parse, jreader_t *reade)
gvm_read_jnode (const char *str, jparser_t parse, jreader_t *read)

Check warning on line 96 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L96

Added line #L96 was not covered by tests
{
JsonParser *parser = parse;

Check warning on line 98 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L98

Added line #L98 was not covered by tests

GError *err = NULL;

Check warning on line 100 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L100

Added line #L100 was not covered by tests
if (!json_parser_load_from_data (parser, str, strlen (str), &err))
{
g_warning ("%s: Parsing json string", __func__);
g_warning ("%s: Parsing json string: %s", __func__, err->message);
g_error_free (err);
g_object_unref (parser);
return -1;

Check warning on line 106 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L103-L106

Added lines #L103 - L106 were not covered by tests
}

*reade = (jreader_t) json_reader_new (json_parser_get_root (parser));
*read = (jreader_t) json_reader_new (json_parser_get_root (parser));
return 0;

Check warning on line 110 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L109-L110

Added lines #L109 - L110 were not covered by tests
}

/**
* @brief Free JSON reader object
*
* @param read JSON Reader to be free()'d.
*/
void
gvm_close_jnode_reader (jreader_t read)

Check warning on line 119 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L119

Added line #L119 was not covered by tests
{
Expand All @@ -93,6 +123,11 @@ gvm_close_jnode_reader (jreader_t read)
g_object_unref (reader);

Check warning on line 123 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L123

Added line #L123 was not covered by tests
}

/**
* @brief Free JSON parser object
*
* @param parse JSON parser to be free()'d.
*/
void
gvm_close_jnode_parser (jparser_t parse)

Check warning on line 132 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L132

Added line #L132 was not covered by tests
{
Expand All @@ -102,6 +137,13 @@ gvm_close_jnode_parser (jparser_t parse)
g_object_unref (parser);

Check warning on line 137 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L137

Added line #L137 was not covered by tests
}

/**
* @brief Count the elements in an array.
*
* @param[in] read JSON reader object pointing to an array.
*
* @return Integer with the amount of elements in the array, -1 otherwise.
*/
int
gvm_jnode_count_elements (jreader_t read)

Check warning on line 148 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L148

Added line #L148 was not covered by tests
{
Expand All @@ -116,6 +158,14 @@ gvm_jnode_count_elements (jreader_t read)
return json_reader_count_elements (reader);

Check warning on line 158 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L158

Added line #L158 was not covered by tests
}

/**
* @brief Parse a VT element given in json format.
*
* @param[in] reader JSON reader object pointing to an VT element.
*
* @return nvti structur containing the VT metadata, NULL otherwise.
* The nvti struct must be free() by the caller
*/
nvti_t *
gvm_jnode_parse_vt (jreader_t reader)

Check warning on line 170 in openvasd/jsonutils.c

View check run for this annotation

Codecov / codecov/patch

openvasd/jsonutils.c#L170

Added line #L170 was not covered by tests
{
Expand Down
50 changes: 42 additions & 8 deletions openvasd/openvasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@

#define RESP_CODE_ERR -1

/**
* @brief Struct holding the data for connecting with Openvasd.
*/
struct openvasd_connector
{
char *ca_cert; // Path to the directory holding the CA certificate
char *cert; // Client certificate
char *key; // Client key
char *apikey; // API key for authentication
char *server; // original openvasd server URL
char *host; // server hostname
char *scan_id; // Scan ID
int port; // server port
char *ca_cert; /**< Path to the directory holding the CA certificate. */
char *cert; /**< Client certificate. */
char *key; /**< Client key. */
char *apikey; /**< API key for authentication. */
char *server; /**< original openvasd server URL. */
char *host; /**< server hostname. */
char *scan_id; /**< Scan ID. */
int port; /**< server port. */
};

/**
Expand Down Expand Up @@ -92,6 +95,9 @@ struct openvasd_vt_single
GHashTable *vt_values;
};

/**
* @brief Request methods
*/
enum openvas_request_method
{
POST,
Expand Down Expand Up @@ -203,6 +209,11 @@ openvasd_connector_free (openvasd_connector_t *conn)
return OPENVASD_OK;

Check warning on line 209 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L209

Added line #L209 was not covered by tests
}

/**
* @brief Free an openvasd response struct
*
* @param resp Response to be free()'d
*/
void
openvasd_response_free (openvasd_resp_t resp)

Check warning on line 218 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L218

Added line #L218 was not covered by tests
{
Expand Down Expand Up @@ -459,12 +470,27 @@ openvasd_send_request (openvasd_connector_t *conn, openvasd_req_method_t method,
return response;

Check warning on line 470 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L470

Added line #L470 was not covered by tests
}

/**
* @brief Request HEAD
*
* @param conn Connector struct with the data necessary for the connection
*
* @return Response containing the header information
*/
openvasd_resp_t
openvasd_get_version (openvasd_connector_t *conn)

Check warning on line 481 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L481

Added line #L481 was not covered by tests
{
return openvasd_send_request (conn, HEAD, "/", NULL, NULL);

Check warning on line 483 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L483

Added line #L483 was not covered by tests
}

/**
* @brief Get VT's metadata
*
* @param conn Connector struct with the data necessary for the connection
*
* @return Response Struct containing the feed metadata in json format in the
* body. NULL on error.
*/
openvasd_resp_t
openvasd_get_vts (openvasd_connector_t *conn)

Check warning on line 495 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L495

Added line #L495 was not covered by tests
{
Expand All @@ -484,6 +510,14 @@ openvasd_get_vts (openvasd_connector_t *conn)
return response;

Check warning on line 510 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L510

Added line #L510 was not covered by tests
}

/**
* @brief Get VT's metadata
*
* @param conn Connector struct with the data necessary for the connection
*
* @return Response Struct containing the feed metadata in json format in the
* body. NULL on error.
*/
openvasd_resp_t
openvasd_start_scan (openvasd_connector_t *conn, char *data)

Check warning on line 522 in openvasd/openvasd.c

View check run for this annotation

Codecov / codecov/patch

openvasd/openvasd.c#L522

Added line #L522 was not covered by tests
{
Expand Down

0 comments on commit 4e98687

Please sign in to comment.