File: http_scanner.h

package info (click to toggle)
gvm-libs 22.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,908 kB
  • sloc: ansic: 38,225; makefile: 26
file content (254 lines) | stat: -rw-r--r-- 6,754 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/* SPDX-FileCopyrightText: 2025 Greenbone AG
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

/**
 * @file
 * @brief API for communication with an HTTP scanner.
 */

#ifndef _GVM_HTTP_SCANNER_H
#define _GVM_HTTP_SCANNER_H

#include "../util/jsonpull.h"

#include <glib.h>
#include <stdio.h>
#include <time.h>

/** @brief HTTP scanner Errors. */
enum HTTP_SCANNER_ERROR
{
  HTTP_SCANNER_INVALID_OPT,
  HTTP_SCANNER_NOT_INITIALIZED,
  HTTP_SCANNER_INVALID_VALUE,
  HTTP_SCANNER_ERROR,
  HTTP_SCANNER_OK,
};

/** @brief options for the connector builder. */
enum HTTP_SCANNER_CONNECTOR_OPTS
{
  HTTP_SCANNER_CA_CERT,
  HTTP_SCANNER_CERT,
  HTTP_SCANNER_KEY,
  HTTP_SCANNER_API_KEY,
  HTTP_SCANNER_PROTOCOL,
  HTTP_SCANNER_HOST,
  HTTP_SCANNER_SCAN_ID,
  HTTP_SCANNER_PORT,
  HTTP_SCANNER_SCAN_PREFIX,
};

/** @brief Members of an HTTP scanner result. */
enum HTTP_SCANNER_RESULT_MEMBER_STRING
{
  TYPE,
  IP_ADDRESS,
  HOSTNAME,
  OID,
  PORT,
  MESSAGE,
  DETAIL_NAME,
  DETAIL_VALUE,
  DETAIL_SOURCE_NAME,
  DETAIL_SOURCE_TYPE,
  DETAIL_SOURCE_DESCRIPTION,
};

/** @brief Members of an HTTP scanner result. */
enum HTTP_SCANNER_RESULT_MEMBER_INT
{
  ID,
};

/** @brief Openvasd scan status. */
typedef enum
{
  HTTP_SCANNER_SCAN_STATUS_ERROR = -2,  /**< Error status. */
  HTTP_SCANNER_SCAN_STATUS_FAILED = -1, /**< Failed status. */
  HTTP_SCANNER_SCAN_STATUS_STORED,      /**< Stored status. */
  HTTP_SCANNER_SCAN_STATUS_REQUESTED,   /**< Queued status. */
  HTTP_SCANNER_SCAN_STATUS_RUNNING,     /**< Running status. */
  HTTP_SCANNER_SCAN_STATUS_STOPPED,     /**< Stopped status. */
  HTTP_SCANNER_SCAN_STATUS_SUCCEEDED,   /**< Succeeded status. */
} http_scanner_status_t;

/** @brief Struct to hold an HTTP scanner response. */
struct http_scanner_response
{
  long code;     /**< HTTP code response. */
  gchar *body;   /**< String containing the body response. */
  gchar *header; /**< A header value. */
};

/** @brief Struct to hold an HTTP scanner scan status. */
struct http_scanner_scan_status
{
  time_t start_time;
  time_t end_time;
  int progress;
  http_scanner_status_t status;
  long response_code;
};

/** @brief Struct to hold an scan result. */
struct http_scanner_result
{
  unsigned long id;
  gchar *type;
  gchar *ip_address;
  gchar *hostname;
  gchar *oid;
  gchar *port;
  gchar *message;
  gchar *detail_name;
  gchar *detail_value;
  gchar *detail_source_type;
  gchar *detail_source_name;
  gchar *detail_source_description;
};

/** @brief Struct holding options for HTTP scanner parameters. */
struct http_scanner_param
{
  gchar *id;          /**< Parameter id. */
  gchar *name;        /**< Parameter name. */
  gchar *defval;      /**< Default value. */
  gchar *description; /**< Description. */
  gchar *type;        /**< Parameter type. */
  int mandatory;      /**< If mandatory. */
};

/**
 * @brief HTTP Scanner Request methods
 */
typedef enum
{
  HTTP_SCANNER_GET,
  HTTP_SCANNER_POST,
  HTTP_SCANNER_PUT,
  HTTP_SCANNER_DELETE,
  HTTP_SCANNER_HEAD,
  HTTP_SCANNER_PATCH
} http_scanner_method_t;

typedef enum HTTP_SCANNER_CONNECTOR_OPTS http_scanner_conn_opt_t;

typedef enum HTTP_SCANNER_RESULT_MEMBER_INT http_scanner_result_member_int_t;

typedef enum HTTP_SCANNER_RESULT_MEMBER_STRING
  http_scanner_result_member_string_t;

typedef enum HTTP_SCANNER_ERROR http_scanner_error_t;

typedef struct http_scanner_connector *http_scanner_connector_t;

typedef struct http_scanner_response *http_scanner_resp_t;

typedef struct http_scanner_result *http_scanner_result_t;

typedef struct http_scanner_scan_status *http_scanner_scan_status_t;

typedef struct http_scanner_param http_scanner_param_t;

http_scanner_connector_t
http_scanner_connector_new (void);

http_scanner_error_t
http_scanner_connector_builder (http_scanner_connector_t,
                                http_scanner_conn_opt_t, const void *);

http_scanner_error_t http_scanner_connector_free (http_scanner_connector_t);

void http_scanner_response_cleanup (http_scanner_resp_t);

http_scanner_resp_t
http_scanner_init_request_multi (http_scanner_connector_t, const gchar *);

int
http_scanner_process_request_multi (http_scanner_connector_t, int);

http_scanner_resp_t http_scanner_get_version (http_scanner_connector_t);

http_scanner_resp_t
http_scanner_create_scan (http_scanner_connector_t, gchar *);

http_scanner_resp_t http_scanner_start_scan (http_scanner_connector_t);

http_scanner_resp_t http_scanner_get_scan_status (http_scanner_connector_t);

http_scanner_resp_t http_scanner_stop_scan (http_scanner_connector_t);

http_scanner_resp_t http_scanner_delete_scan (http_scanner_connector_t);

http_scanner_resp_t
http_scanner_get_scan_results (http_scanner_connector_t, long, long);

http_scanner_result_t
http_scanner_result_new (unsigned long, gchar *, gchar *, gchar *, gchar *,
                         gchar *, gchar *, gchar *, gchar *, gchar *, gchar *,
                         gchar *, gchar *);

void http_scanner_result_free (http_scanner_result_t);

char *http_scanner_get_result_member_str (http_scanner_result_t,
                                          http_scanner_result_member_string_t);

int http_scanner_get_result_member_int (http_scanner_result_t,
                                        http_scanner_result_member_int_t);

int
http_scanner_parsed_results (http_scanner_connector_t, unsigned long,
                             unsigned long, GSList **);

http_scanner_scan_status_t
  http_scanner_parsed_scan_status (http_scanner_connector_t);

int http_scanner_get_scan_progress (http_scanner_connector_t);

http_scanner_resp_t http_scanner_get_health_alive (http_scanner_connector_t);

http_scanner_resp_t http_scanner_get_health_ready (http_scanner_connector_t);

http_scanner_resp_t http_scanner_get_health_started (http_scanner_connector_t);

http_scanner_resp_t
  http_scanner_get_scan_preferences (http_scanner_connector_t);

int
http_scanner_parsed_scans_preferences (http_scanner_connector_t, GSList **);

void
http_scanner_param_free (http_scanner_param_t *);

char *
http_scanner_param_id (http_scanner_param_t *);

char *
http_scanner_param_name (http_scanner_param_t *);

char *
http_scanner_param_desc (http_scanner_param_t *);

int
http_scanner_param_mandatory (http_scanner_param_t *);

char *
http_scanner_param_type (http_scanner_param_t *);

char *
http_scanner_param_default (http_scanner_param_t *);

void http_scanner_reset_stream (http_scanner_connector_t);

gchar *http_scanner_stream_str (http_scanner_connector_t);

size_t http_scanner_stream_len (http_scanner_connector_t);

http_scanner_resp_t
http_scanner_send_request (http_scanner_connector_t, http_scanner_method_t,
                           const gchar *, const gchar *, const gchar *);

#endif /* _GVM_HTTP_SCANNER_H */