OpenVAS Scanner 23.23.1
nasl_http2.c File Reference
#include "nasl_http2.h"
#include "../misc/plugutils.h"
#include "../misc/user_agent.h"
#include "exec.h"
#include "nasl_debug.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_lex_ctxt.h"
#include "nasl_socket.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include <ctype.h>
#include <curl/curl.h>
#include <gnutls/gnutls.h>
#include <gvm/base/prefs.h>
#include <gvm/util/kb.h>
#include <string.h>

Data Structures

struct  handle_table_s
 Struct to store handles. More...
struct  string
 Define a string struct for storing the response. More...

Macros

#define G_LOG_DOMAIN   "lib nasl"
 GLib log domain.
#define MAX_HANDLES   10

Typedefs

typedef enum KEYWORD_E KEYWORD
 Allowed methods.

Enumerations

enum  KEYWORD_E {
  POST , GET , PUT , DELETE ,
  HEAD
}
 Allowed methods. More...

Functions

static int next_handle_id (void)
 Get the new available handle identifier.
tree_cellnasl_http2_handle (lex_ctxt *lexic)
 Creates a handle for http requests.
tree_cellnasl_http2_close_handle (lex_ctxt *lexic)
 Close a handle for http requests previously initialized.
static void init_string (struct string *s)
 Initialize the string struct to hold the response or header.
static size_t response_callback_fn (void *ptr, size_t size, size_t nmemb, void *struct_string)
 Call back function to stored the response.
static size_t header_callback_fn (char *buffer, size_t size, size_t nmemb, void *struct_string)
 Call back function to stored the header.
static tree_cell_http2_req (lex_ctxt *lexic, KEYWORD keyword)
 Perform an HTTP request. Forcing HTTP2 if possible.
tree_cellnasl_http2_get_response_code (lex_ctxt *lexic)
 Get the http response code after performing a HTTP request.
tree_cellnasl_http2_set_custom_header (lex_ctxt *lexic)
 Set a custom header element in the header.
tree_cellnasl_http2_get (lex_ctxt *lexic)
 Wrapper function for GET request. See @_http2_req.
tree_cellnasl_http2_head (lex_ctxt *lexic)
 Wrapper function for HEAD request. See @_http2_req.
tree_cellnasl_http2_post (lex_ctxt *lexic)
 Wrapper function for POST request. See @_http2_req.
tree_cellnasl_http2_delete (lex_ctxt *lexic)
 Wrapper function for DELETE request. See @_http2_req.
tree_cellnasl_http2_put (lex_ctxt *lexic)
 Wrapper function for PUT request. See @_http2_req.

Variables

static struct handle_table_shandle_table [MAX_HANDLES]
 Handle Table.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nasl"

GLib log domain.

◆ MAX_HANDLES

#define MAX_HANDLES   10

Typedef Documentation

◆ KEYWORD

typedef enum KEYWORD_E KEYWORD

Allowed methods.

Enumeration Type Documentation

◆ KEYWORD_E

enum KEYWORD_E

Allowed methods.

Enumerator
POST 
GET 
PUT 
DELETE 
HEAD 

Function Documentation

◆ _http2_req()

tree_cell * _http2_req ( lex_ctxt * lexic,
KEYWORD keyword )
static

Perform an HTTP request. Forcing HTTP2 if possible.

NASL Named Parameters:\n
  • handle The handle identifier
  • port The port to use for the connection
  • item The path
  • schema Optional URL schema to be used. http or https. Default to https.
  • data Optional data to be sent with POST or PUT
NASL Returns:\n http header followed by the response from the server. Null on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
On success the function returns a tree-cell with the http header followed by the response from the server. Null on error.

◆ header_callback_fn()

size_t header_callback_fn ( char * buffer,
size_t size,
size_t nmemb,
void * struct_string )
static

Call back function to stored the header.

@description The function signature is the necessary to work with libcurl. It stores the header in s. It reallocate memory if necessary.

◆ init_string()

void init_string ( struct string * s)
static

Initialize the string struct to hold the response or header.

Parameters
s[in/out]The string struct to be initialized

◆ 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.

◆ nasl_http2_delete()

tree_cell * nasl_http2_delete ( lex_ctxt * lexic)

Wrapper function for DELETE request. See @_http2_req.

◆ nasl_http2_get()

tree_cell * nasl_http2_get ( lex_ctxt * lexic)

Wrapper function for GET request. See @_http2_req.

◆ 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.

◆ 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.

◆ nasl_http2_head()

tree_cell * nasl_http2_head ( lex_ctxt * lexic)

Wrapper function for HEAD request. See @_http2_req.

◆ nasl_http2_post()

tree_cell * nasl_http2_post ( lex_ctxt * lexic)

Wrapper function for POST request. See @_http2_req.

◆ nasl_http2_put()

tree_cell * nasl_http2_put ( lex_ctxt * lexic)

Wrapper function for PUT request. See @_http2_req.

◆ 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.

◆ next_handle_id()

int next_handle_id ( void )
static

Get the new available handle identifier.

◆ response_callback_fn()

size_t response_callback_fn ( void * ptr,
size_t size,
size_t nmemb,
void * struct_string )
static

Call back function to stored the response.

@description The function signature is the necessary to work with libcurl. It stores the response in s. It reallocate memory if necessary.

Variable Documentation

◆ handle_table

struct handle_table_s* handle_table[MAX_HANDLES]
static

Handle Table.