OpenVAS Scanner 23.40.3
nasl_http2.h File Reference
#include "nasl_lex_ctxt.h"
Include dependency graph for nasl_http2.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

tree_cellnasl_http2_handle (lex_ctxt *)
 Creates a handle for http requests.
tree_cellnasl_http2_close_handle (lex_ctxt *)
 Close a handle for http requests previously initialized.
tree_cellnasl_http2_get_response_code (lex_ctxt *)
 Get the http response code after performing a HTTP request.
tree_cellnasl_http2_set_custom_header (lex_ctxt *)
 Set a custom header element in the header.
tree_cellnasl_http2_get (lex_ctxt *)
 Wrapper function for GET request. See _http2_req.
tree_cellnasl_http2_head (lex_ctxt *)
 Wrapper function for HEAD request. See _http2_req.
tree_cellnasl_http2_post (lex_ctxt *)
 Wrapper function for POST request. See _http2_req.
tree_cellnasl_http2_delete (lex_ctxt *)
 Wrapper function for DELETE request. See _http2_req.
tree_cellnasl_http2_put (lex_ctxt *)
 Wrapper function for PUT request. See _http2_req.

Function Documentation

◆ nasl_http2_close_handle()

tree_cell * nasl_http2_close_handle ( lex_ctxt * lexic)

Close a handle for http requests previously initialized.

NASL Function: http2_handle\n
NASL Named Parameters:\n
  • handle The handle identifier for the handle to be closed
NASL Returns:\n O on success, -1 on error
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
The function returns a tree-cell with a integer. O on success, -1 on error.

Definition at line 129 of file nasl_http2.c.

130{
131 tree_cell *retc = NULL;
132 int handle_id = get_int_var_by_num (lexic, 0, -1);
133 unsigned int table_slot;
134 int ret = 0;
135
136 for (table_slot = 0; table_slot < MAX_HANDLES; table_slot++)
137 {
138 if (handle_table[table_slot]->handle_id == handle_id)
139 {
140 curl_easy_cleanup (handle_table[table_slot]->handle);
141 handle_table[table_slot]->handle = NULL;
142 handle_table[table_slot]->handle_id = 0;
143 handle_table[table_slot] = NULL;
144 }
145 else
146 {
147 g_message ("%s: Unknown handle identifier %d", __func__, handle_id);
148 ret = -1;
149 }
150 }
152 retc->x.i_val = ret;
153 return retc;
154}
#define MAX_HANDLES
Definition nasl_http2.c:55
static struct handle_table_s * handle_table[MAX_HANDLES]
Handle Table.
Definition nasl_http2.c:59
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition nasl_var.c:1094
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
@ CONST_INT
Definition nasl_tree.h:79
struct TC tree_cell
long int i_val
Definition nasl_tree.h:104
union TC::@332262321161220155002104006201360276211317150140 x

References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), handle_table_s::handle, handle_table_s::handle_id, handle_table, TC::i_val, MAX_HANDLES, and TC::x.

Here is the call graph for this function:

◆ nasl_http2_delete()

tree_cell * nasl_http2_delete ( lex_ctxt * lexic)

Wrapper function for DELETE request. See _http2_req.

Definition at line 549 of file nasl_http2.c.

550{
551 return _http2_req (lexic, DELETE);
552}
@ DELETE
Definition nasl_http2.c:42
static tree_cell * _http2_req(lex_ctxt *lexic, KEYWORD keyword)
Perform an HTTP request. Forcing HTTP2 if possible.
Definition nasl_http2.c:252

References _http2_req(), and DELETE.

Here is the call graph for this function:

◆ nasl_http2_get()

tree_cell * nasl_http2_get ( lex_ctxt * lexic)

Wrapper function for GET request. See _http2_req.

Definition at line 525 of file nasl_http2.c.

526{
527 return _http2_req (lexic, GET);
528}
@ GET
Definition nasl_http2.c:40

References _http2_req(), and GET.

Here is the call graph for this function:

◆ nasl_http2_get_response_code()

tree_cell * nasl_http2_get_response_code ( lex_ctxt * lexic)

Get the http response code after performing a HTTP request.

NASL Named Parameters:\n
  • handle The handle identifier
NASL Returns:\n http code or 0 if not set. NULL on error
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
On success the function returns a tree-cell with and integer representing the http code response. Null on error.

Definition at line 436 of file nasl_http2.c.

437{
438 tree_cell *retc = NULL;
439 unsigned int table_slot;
440 int handle_id = get_int_var_by_name (lexic, "handle", -1);
441
442 if (handle_id < 0)
443 {
444 nasl_perror (lexic,
445 "Error : http2_* functions have the following syntax :\n");
446 nasl_perror (lexic, "http_*(handle: <handle>\n");
447 return NULL;
448 }
449
450 for (table_slot = 0; table_slot < MAX_HANDLES; table_slot++)
451 {
452 if (handle_table[table_slot]->handle_id == handle_id)
453 break;
454 else
455 {
456 g_message ("%s: Unknown handle identifier %d", __func__, handle_id);
457 return NULL;
458 }
459 }
460
462 retc->x.i_val = handle_table[table_slot]->http_code;
463 return retc;
464}
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition nasl_debug.c:105
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition nasl_var.c:1101

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), handle_table, TC::i_val, MAX_HANDLES, nasl_perror(), and TC::x.

Here is the call graph for this function:

◆ nasl_http2_handle()

tree_cell * nasl_http2_handle ( lex_ctxt * lexic)

Creates a handle for http requests.

NASL Function: http2_handle\n
NASL Returns:\n Handle identifier. Null on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
On success the function returns a tree-cell with the handle identifier. Null on error.

Definition at line 84 of file nasl_http2.c.

85{
86 (void) lexic;
87 tree_cell *retc = NULL;
88 CURL *handle = curl_easy_init ();
89 unsigned int table_slot;
90
91 if (!handle)
92 return NULL;
93
94 for (table_slot = 0; table_slot < MAX_HANDLES; table_slot++)
95 if (!handle_table[table_slot] || !handle_table[table_slot]->handle_id)
96 break;
97
98 if (!(table_slot < MAX_HANDLES))
99 {
100 g_message ("%s: No space left in HTTP2 handle table", __func__);
101 curl_easy_cleanup (handle);
102 return NULL;
103 }
104
105 handle_table[table_slot] = g_malloc0 (sizeof (struct handle_table_s));
106 handle_table[table_slot]->handle = handle;
107 handle_table[table_slot]->handle_id = next_handle_id ();
108
110 retc->x.i_val = handle_table[table_slot]->handle_id;
111 return retc;
112}
static int next_handle_id(void)
Get the new available handle identifier.
Definition nasl_http2.c:64
Struct to store handles.
Definition nasl_http2.c:49

References alloc_typed_cell(), CONST_INT, handle_table_s::handle, handle_table_s::handle_id, handle_table, TC::i_val, MAX_HANDLES, next_handle_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_http2_head()

tree_cell * nasl_http2_head ( lex_ctxt * lexic)

Wrapper function for HEAD request. See _http2_req.

Definition at line 533 of file nasl_http2.c.

534{
535 return _http2_req (lexic, HEAD);
536}
@ HEAD
Definition nasl_http2.c:43

References _http2_req(), and HEAD.

Here is the call graph for this function:

◆ nasl_http2_post()

tree_cell * nasl_http2_post ( lex_ctxt * lexic)

Wrapper function for POST request. See _http2_req.

Definition at line 541 of file nasl_http2.c.

542{
543 return _http2_req (lexic, POST);
544}
@ POST
Definition nasl_http2.c:39

References _http2_req(), and POST.

Here is the call graph for this function:

◆ nasl_http2_put()

tree_cell * nasl_http2_put ( lex_ctxt * lexic)

Wrapper function for PUT request. See _http2_req.

Definition at line 557 of file nasl_http2.c.

558{
559 return _http2_req (lexic, PUT);
560}
@ PUT
Definition nasl_http2.c:41

References _http2_req(), and PUT.

Here is the call graph for this function:

◆ nasl_http2_set_custom_header()

tree_cell * nasl_http2_set_custom_header ( lex_ctxt * lexic)

Set a custom header element in the header.

NASL Named Parameters:\n
  • handle The handle identifier
  • header_item A string to add to the header
NASL Returns:\n 0 on success. NULL on error
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
On success the function returns a tree-cell integer 0 on success. Null on error.

Definition at line 482 of file nasl_http2.c.

483{
484 tree_cell *retc = NULL;
485 struct curl_slist *customheader = NULL;
486 unsigned int table_slot;
487 CURL *handle;
488 int handle_id = get_int_var_by_name (lexic, "handle", -1);
489 char *headeritem = get_str_var_by_name (lexic, "header_item");
490
491 if (handle_id < 0 || headeritem == NULL)
492 {
493 nasl_perror (lexic,
494 "Error : http2_* functions have the following syntax :\n");
495 nasl_perror (lexic,
496 "http_*(handle: <handle>, header_item:<header_item>\n");
497 return NULL;
498 }
499
500 for (table_slot = 0; table_slot < MAX_HANDLES; table_slot++)
501 {
502 if (handle_table[table_slot]->handle_id == handle_id)
503 break;
504 else
505 {
506 g_message ("%s: Unknown handle identifier %d", __func__, handle_id);
507 return NULL;
508 }
509 }
510 handle = handle_table[table_slot]->handle;
511
512 // SET Content type
513 customheader = curl_slist_append (customheader, headeritem);
514 curl_easy_setopt (handle, CURLOPT_HTTPHEADER, customheader);
515
517 retc->x.i_val = 0;
518
519 return retc;
520}
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1118

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_str_var_by_name(), handle_table, TC::i_val, MAX_HANDLES, nasl_perror(), and TC::x.

Here is the call graph for this function: