Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Typedefs | Enumerations | Functions
http_websocket.h File Reference

Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to a server. More...

#include "asterisk/http.h"
#include "asterisk/optional_api.h"
#include <errno.h>
Include dependency graph for http_websocket.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_websocket_protocol
 A websocket protocol implementation. More...
 

Macros

#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT   100
 Default websocket write timeout, in ms. More...
 
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR   "100"
 Default websocket write timeout, in ms (as a string) More...
 
#define AST_WEBSOCKET_PROTOCOL_VERSION   1
 Protocol version. This prevents dynamically loadable modules from registering if this struct is changed. More...
 

Typedefs

typedef void(* ast_websocket_callback) (struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers)
 Callback for when a new connection for a sub-protocol is established. More...
 
typedef int(* ast_websocket_pre_callback) (struct ast_tcptls_session_instance *ser, struct ast_variable *parameters, struct ast_variable *headers, const char *session_id)
 Callback from the HTTP request attempting to establish a websocket connection. More...
 

Enumerations

enum  ast_websocket_opcode {
  AST_WEBSOCKET_OPCODE_TEXT = 0x1, AST_WEBSOCKET_OPCODE_BINARY = 0x2, AST_WEBSOCKET_OPCODE_PING = 0x9, AST_WEBSOCKET_OPCODE_PONG = 0xA,
  AST_WEBSOCKET_OPCODE_CLOSE = 0x8, AST_WEBSOCKET_OPCODE_CONTINUATION = 0x0
}
 WebSocket operation codes. More...
 
enum  ast_websocket_result {
  WS_OK, WS_ALLOCATE_ERROR, WS_KEY_ERROR, WS_URI_PARSE_ERROR,
  WS_URI_RESOLVE_ERROR, WS_BAD_STATUS, WS_INVALID_RESPONSE, WS_BAD_REQUEST,
  WS_URL_NOT_FOUND, WS_HEADER_MISMATCH, WS_HEADER_MISSING, WS_NOT_SUPPORTED,
  WS_WRITE_ERROR, WS_CLIENT_START_ERROR
}
 Result code for a websocket client. More...
 

Functions

static void __dtor__ast_websocket_add_protocol (void)
 
static void __dtor__ast_websocket_add_protocol2 (void)
 
static void __dtor__ast_websocket_client_accept_protocol (void)
 
static void __dtor__ast_websocket_client_create (void)
 
static void __dtor__ast_websocket_close (void)
 
static void __dtor__ast_websocket_fd (void)
 
static void __dtor__ast_websocket_is_secure (void)
 
static void __dtor__ast_websocket_local_address (void)
 
static void __dtor__ast_websocket_read (void)
 
static void __dtor__ast_websocket_read_string (void)
 
static void __dtor__ast_websocket_reconstruct_disable (void)
 
static void __dtor__ast_websocket_reconstruct_enable (void)
 
static void __dtor__ast_websocket_ref (void)
 
static void __dtor__ast_websocket_remote_address (void)
 
static void __dtor__ast_websocket_remove_protocol (void)
 
static void __dtor__ast_websocket_server_add_protocol (void)
 
static void __dtor__ast_websocket_server_add_protocol2 (void)
 
static void __dtor__ast_websocket_server_create (void)
 
static void __dtor__ast_websocket_server_remove_protocol (void)
 
static void __dtor__ast_websocket_session_id (void)
 
static void __dtor__ast_websocket_set_nonblock (void)
 
static void __dtor__ast_websocket_set_timeout (void)
 
static void __dtor__ast_websocket_sub_protocol_alloc (void)
 
static void __dtor__ast_websocket_unref (void)
 
static void __dtor__ast_websocket_uri_cb (void)
 
static void __dtor__ast_websocket_wait_for_input (void)
 
static void __dtor__ast_websocket_write (void)
 
static void __dtor__ast_websocket_write_string (void)
 
static void __init__ast_websocket_add_protocol (void)
 
static void __init__ast_websocket_add_protocol2 (void)
 
static void __init__ast_websocket_client_accept_protocol (void)
 
static void __init__ast_websocket_client_create (void)
 
static void __init__ast_websocket_close (void)
 
static void __init__ast_websocket_fd (void)
 
static void __init__ast_websocket_is_secure (void)
 
static void __init__ast_websocket_local_address (void)
 
static void __init__ast_websocket_read (void)
 
static void __init__ast_websocket_read_string (void)
 
static void __init__ast_websocket_reconstruct_disable (void)
 
static void __init__ast_websocket_reconstruct_enable (void)
 
static void __init__ast_websocket_ref (void)
 
static void __init__ast_websocket_remote_address (void)
 
static void __init__ast_websocket_remove_protocol (void)
 
static void __init__ast_websocket_server_add_protocol (void)
 
static void __init__ast_websocket_server_add_protocol2 (void)
 
static void __init__ast_websocket_server_create (void)
 
static void __init__ast_websocket_server_remove_protocol (void)
 
static void __init__ast_websocket_session_id (void)
 
static void __init__ast_websocket_set_nonblock (void)
 
static void __init__ast_websocket_set_timeout (void)
 
static void __init__ast_websocket_sub_protocol_alloc (void)
 
static void __init__ast_websocket_unref (void)
 
static void __init__ast_websocket_uri_cb (void)
 
static void __init__ast_websocket_wait_for_input (void)
 
static void __init__ast_websocket_write (void)
 
static void __init__ast_websocket_write_string (void)
 
static int __stub__ast_websocket_add_protocol (const char *name, ast_websocket_callback callback)
 Add a sub-protocol handler to the default /ws server. More...
 
static int __stub__ast_websocket_add_protocol2 (struct ast_websocket_protocol *protocol)
 Add a sub-protocol handler to the default /ws server. More...
 
static const char * __stub__ast_websocket_client_accept_protocol (struct ast_websocket *ws)
 Retrieve the server accepted sub-protocol on the client. More...
 
static struct ast_websocket__stub__ast_websocket_client_create (const char *uri, const char *protocols, struct ast_tls_config *tls_cfg, enum ast_websocket_result *result)
 Create, and connect, a websocket client. More...
 
static int __stub__ast_websocket_close (struct ast_websocket *session, uint16_t reason)
 Close a WebSocket session by sending a message with the CLOSE opcode and an optional code. More...
 
static int __stub__ast_websocket_fd (struct ast_websocket *session)
 Get the file descriptor for a WebSocket session. More...
 
static int __stub__ast_websocket_is_secure (struct ast_websocket *session)
 Get whether the WebSocket session is using a secure transport or not. More...
 
static struct ast_sockaddr__stub__ast_websocket_local_address (struct ast_websocket *session)
 Get the local address for a WebSocket connection session. More...
 
static int __stub__ast_websocket_read (struct ast_websocket *session, char **payload, uint64_t *payload_len, enum ast_websocket_opcode *opcode, int *fragmented)
 Read a WebSocket frame and handle it. More...
 
static int __stub__ast_websocket_read_string (struct ast_websocket *ws, char **buf)
 Read a WebSocket frame containing string data. More...
 
static void __stub__ast_websocket_reconstruct_disable (struct ast_websocket *session)
 Disable multi-frame reconstruction. More...
 
static void __stub__ast_websocket_reconstruct_enable (struct ast_websocket *session, size_t bytes)
 Enable multi-frame reconstruction up to a certain number of bytes. More...
 
static void __stub__ast_websocket_ref (struct ast_websocket *session)
 Increase the reference count for a WebSocket session. More...
 
static struct ast_sockaddr__stub__ast_websocket_remote_address (struct ast_websocket *session)
 Get the remote address for a WebSocket connected session. More...
 
static int __stub__ast_websocket_remove_protocol (const char *name, ast_websocket_callback callback)
 Remove a sub-protocol handler from the default /ws server. More...
 
static int __stub__ast_websocket_server_add_protocol (struct ast_websocket_server *server, const char *name, ast_websocket_callback callback)
 Add a sub-protocol handler to the given server. More...
 
static int __stub__ast_websocket_server_add_protocol2 (struct ast_websocket_server *server, struct ast_websocket_protocol *protocol)
 Add a sub-protocol handler to the given server. More...
 
static struct ast_websocket_server__stub__ast_websocket_server_create (void)
 Creates a websocket_server. More...
 
static int __stub__ast_websocket_server_remove_protocol (struct ast_websocket_server *server, const char *name, ast_websocket_callback callback)
 Remove a sub-protocol handler from the given server. More...
 
static const char * __stub__ast_websocket_session_id (struct ast_websocket *session)
 Get the session ID for a WebSocket session. More...
 
static int __stub__ast_websocket_set_nonblock (struct ast_websocket *session)
 Set the socket of a WebSocket session to be non-blocking. More...
 
static int __stub__ast_websocket_set_timeout (struct ast_websocket *session, int timeout)
 Set the timeout on a non-blocking WebSocket session. More...
 
static struct ast_websocket_protocol__stub__ast_websocket_sub_protocol_alloc (const char *name)
 Allocate a websocket sub-protocol instance. More...
 
static void __stub__ast_websocket_unref (struct ast_websocket *session)
 Decrease the reference count for a WebSocket session. More...
 
static int __stub__ast_websocket_uri_cb (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_vars, struct ast_variable *headers)
 Callback suitable for use with a ast_http_uri. More...
 
static int __stub__ast_websocket_wait_for_input (struct ast_websocket *session, int timeout)
 Wait for the WebSocket session to be ready to be read. More...
 
static int __stub__ast_websocket_write (struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t payload_size)
 Construct and transmit a WebSocket frame. More...
 
static int __stub__ast_websocket_write_string (struct ast_websocket *ws, const char *buf)
 Construct and transmit a WebSocket frame containing string data. More...
 
static typeof (__stub__ast_websocket_server_create) *ast_websocket_server_create
 
static typeof (__stub__ast_websocket_uri_cb) *ast_websocket_uri_cb
 
static typeof (__stub__ast_websocket_sub_protocol_alloc) *ast_websocket_sub_protocol_alloc
 
static typeof (__stub__ast_websocket_add_protocol) *ast_websocket_add_protocol
 
static typeof (__stub__ast_websocket_add_protocol2) *ast_websocket_add_protocol2
 
static typeof (__stub__ast_websocket_remove_protocol) *ast_websocket_remove_protocol
 
static typeof (__stub__ast_websocket_server_add_protocol) *ast_websocket_server_add_protocol
 
static typeof (__stub__ast_websocket_server_add_protocol2) *ast_websocket_server_add_protocol2
 
static typeof (__stub__ast_websocket_server_remove_protocol) *ast_websocket_server_remove_protocol
 
static typeof (__stub__ast_websocket_read) *ast_websocket_read
 
static typeof (__stub__ast_websocket_read_string) *ast_websocket_read_string
 
static typeof (__stub__ast_websocket_write) *ast_websocket_write
 
static typeof (__stub__ast_websocket_write_string) *ast_websocket_write_string
 
static typeof (__stub__ast_websocket_close) *ast_websocket_close
 
static typeof (__stub__ast_websocket_reconstruct_enable) *ast_websocket_reconstruct_enable
 
static typeof (__stub__ast_websocket_reconstruct_disable) *ast_websocket_reconstruct_disable
 
static typeof (__stub__ast_websocket_ref) *ast_websocket_ref
 
static typeof (__stub__ast_websocket_unref) *ast_websocket_unref
 
static typeof (__stub__ast_websocket_fd) *ast_websocket_fd
 
static typeof (__stub__ast_websocket_wait_for_input) *ast_websocket_wait_for_input
 
static typeof (__stub__ast_websocket_remote_address) *ast_websocket_remote_address
 
static typeof (__stub__ast_websocket_local_address) *ast_websocket_local_address
 
static typeof (__stub__ast_websocket_is_secure) *ast_websocket_is_secure
 
static typeof (__stub__ast_websocket_set_nonblock) *ast_websocket_set_nonblock
 
static typeof (__stub__ast_websocket_session_id) *ast_websocket_session_id
 
static typeof (__stub__ast_websocket_client_create) *ast_websocket_client_create
 
static typeof (__stub__ast_websocket_client_accept_protocol) *ast_websocket_client_accept_protocol
 
static typeof (__stub__ast_websocket_set_timeout) *ast_websocket_set_timeout
 

Detailed Description

Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to a server.

Supported WebSocket versions in server implementation: Version 7 defined in specification http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07 Version 8 defined in specification http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10 Version 13 defined in specification http://tools.ietf.org/html/rfc6455 Supported WebSocket versions in client implementation: Version 13 defined in specification http://tools.ietf.org/html/rfc6455

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file http_websocket.h.

Macro Definition Documentation

◆ AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT

#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT   100

Default websocket write timeout, in ms.

Definition at line 28 of file http_websocket.h.

Referenced by ast_websocket_uri_cb(), get_write_timeout(), and reload_config().

◆ AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR

#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR   "100"

Default websocket write timeout, in ms (as a string)

Definition at line 31 of file http_websocket.h.

Referenced by ast_ari_config_init(), and ast_sip_initialize_sorcery_transport().

◆ AST_WEBSOCKET_PROTOCOL_VERSION

#define AST_WEBSOCKET_PROTOCOL_VERSION   1

Protocol version. This prevents dynamically loadable modules from registering if this struct is changed.

Definition at line 119 of file http_websocket.h.

Referenced by ast_websocket_server_add_protocol2(), and ast_websocket_sub_protocol_alloc().

Typedef Documentation

◆ ast_websocket_callback

typedef void(* ast_websocket_callback) (struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers)

Callback for when a new connection for a sub-protocol is established.

Parameters
sessionA WebSocket session structure
parametersParameters extracted from the request URI
headersHeaders included in the request
Note
Once called the ownership of the session is transferred to the sub-protocol handler. It is responsible for closing and cleaning up.

Definition at line 100 of file http_websocket.h.

◆ ast_websocket_pre_callback

typedef int(* ast_websocket_pre_callback) (struct ast_tcptls_session_instance *ser, struct ast_variable *parameters, struct ast_variable *headers, const char *session_id)

Callback from the HTTP request attempting to establish a websocket connection.

This callback occurs when an HTTP request is made to establish a websocket connection. Implementers of ast_websocket_protocol can use this to deny a request, or to set up application specific data before invocation of ast_websocket_callback.

Parameters
serThe TCP/TLS session
parametersParameters extracted from the request URI
headersHeaders included in the request
session_idThe id of the current session.
Return values
0The session should be accepted
-1The session should be rejected. Note that the caller must send an error response using ast_http_error.
Since
13.5.0

Definition at line 87 of file http_websocket.h.

Enumeration Type Documentation

◆ ast_websocket_opcode

WebSocket operation codes.

Enumerator
AST_WEBSOCKET_OPCODE_TEXT 

Text frame

AST_WEBSOCKET_OPCODE_BINARY 

Binary frame

AST_WEBSOCKET_OPCODE_PING 

Request that the other side respond with a pong

AST_WEBSOCKET_OPCODE_PONG 

Response to a ping

AST_WEBSOCKET_OPCODE_CLOSE 

Connection is being closed

AST_WEBSOCKET_OPCODE_CONTINUATION 

Continuation of a previous frame

Definition at line 50 of file http_websocket.h.

50  {
51  AST_WEBSOCKET_OPCODE_TEXT = 0x1, /*!< Text frame */
52  AST_WEBSOCKET_OPCODE_BINARY = 0x2, /*!< Binary frame */
53  AST_WEBSOCKET_OPCODE_PING = 0x9, /*!< Request that the other side respond with a pong */
54  AST_WEBSOCKET_OPCODE_PONG = 0xA, /*!< Response to a ping */
55  AST_WEBSOCKET_OPCODE_CLOSE = 0x8, /*!< Connection is being closed */
56  AST_WEBSOCKET_OPCODE_CONTINUATION = 0x0, /*!< Continuation of a previous frame */
57 };

◆ ast_websocket_result

Result code for a websocket client.

Enumerator
WS_OK 
WS_ALLOCATE_ERROR 
WS_KEY_ERROR 
WS_URI_PARSE_ERROR 
WS_URI_RESOLVE_ERROR 
WS_BAD_STATUS 
WS_INVALID_RESPONSE 
WS_BAD_REQUEST 
WS_URL_NOT_FOUND 
WS_HEADER_MISMATCH 
WS_HEADER_MISSING 
WS_NOT_SUPPORTED 
WS_WRITE_ERROR 
WS_CLIENT_START_ERROR 

Definition at line 396 of file http_websocket.h.

Function Documentation

◆ __dtor__ast_websocket_add_protocol()

static void __dtor__ast_websocket_add_protocol ( void  )
static

Definition at line 163 of file http_websocket.h.

163 {return -1;});

◆ __dtor__ast_websocket_add_protocol2()

static void __dtor__ast_websocket_add_protocol2 ( void  )
static

Definition at line 178 of file http_websocket.h.

178 {return -1;});

◆ __dtor__ast_websocket_client_accept_protocol()

static void __dtor__ast_websocket_client_accept_protocol ( void  )
static

Definition at line 447 of file http_websocket.h.

447 { return NULL;});
#define NULL
Definition: resample.c:96

◆ __dtor__ast_websocket_client_create()

static void __dtor__ast_websocket_client_create ( void  )
static

Definition at line 437 of file http_websocket.h.

437 { return NULL;});
#define NULL
Definition: resample.c:96

◆ __dtor__ast_websocket_close()

static void __dtor__ast_websocket_close ( void  )
static

Definition at line 296 of file http_websocket.h.

296 { errno = ENOSYS; return -1;});
int errno

◆ __dtor__ast_websocket_fd()

static void __dtor__ast_websocket_fd ( void  )
static

Definition at line 338 of file http_websocket.h.

338 { errno = ENOSYS; return -1;});
int errno

◆ __dtor__ast_websocket_is_secure()

static void __dtor__ast_websocket_is_secure ( void  )
static

Definition at line 376 of file http_websocket.h.

376 { errno = ENOSYS; return -1;});
int errno

◆ __dtor__ast_websocket_local_address()

static void __dtor__ast_websocket_local_address ( void  )
static

Definition at line 368 of file http_websocket.h.

368 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __dtor__ast_websocket_read()

static void __dtor__ast_websocket_read ( void  )
static

Definition at line 245 of file http_websocket.h.

245 { errno = ENOSYS; return -1;});
int errno

◆ __dtor__ast_websocket_read_string()

static void __dtor__ast_websocket_read_string ( void  )
static

Definition at line 261 of file http_websocket.h.

261 { errno = ENOSYS; return -1;});
int errno

◆ __dtor__ast_websocket_reconstruct_disable()

static void __dtor__ast_websocket_reconstruct_disable ( void  )
static

Definition at line 315 of file http_websocket.h.

315 {return;});

◆ __dtor__ast_websocket_reconstruct_enable()

static void __dtor__ast_websocket_reconstruct_enable ( void  )
static

Definition at line 305 of file http_websocket.h.

305 {return;});

◆ __dtor__ast_websocket_ref()

static void __dtor__ast_websocket_ref ( void  )
static

Definition at line 322 of file http_websocket.h.

322 {return;});

◆ __dtor__ast_websocket_remote_address()

static void __dtor__ast_websocket_remote_address ( void  )
static

Definition at line 359 of file http_websocket.h.

359 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __dtor__ast_websocket_remove_protocol()

static void __dtor__ast_websocket_remove_protocol ( void  )
static

Definition at line 189 of file http_websocket.h.

189 {return -1;});

◆ __dtor__ast_websocket_server_add_protocol()

static void __dtor__ast_websocket_server_add_protocol ( void  )
static

Definition at line 201 of file http_websocket.h.

201 {return -1;});

◆ __dtor__ast_websocket_server_add_protocol2()

static void __dtor__ast_websocket_server_add_protocol2 ( void  )
static

Definition at line 217 of file http_websocket.h.

217 {return -1;});

◆ __dtor__ast_websocket_server_create()

static void __dtor__ast_websocket_server_create ( void  )
static

Definition at line 135 of file http_websocket.h.

135 { return NULL; });
#define NULL
Definition: resample.c:96

◆ __dtor__ast_websocket_server_remove_protocol()

static void __dtor__ast_websocket_server_remove_protocol ( void  )
static

Definition at line 229 of file http_websocket.h.

229 {return -1;});

◆ __dtor__ast_websocket_session_id()

static void __dtor__ast_websocket_session_id ( void  )
static

Definition at line 391 of file http_websocket.h.

391 { errno = ENOSYS; return NULL;});
#define NULL
Definition: resample.c:96
int errno

◆ __dtor__ast_websocket_set_nonblock()

static void __dtor__ast_websocket_set_nonblock ( void  )
static

Definition at line 384 of file http_websocket.h.

384 { errno = ENOSYS; return -1;});
int errno

◆ __dtor__ast_websocket_set_timeout()

static void __dtor__ast_websocket_set_timeout ( void  )
static

Definition at line 458 of file http_websocket.h.

458 {return -1;});

◆ __dtor__ast_websocket_sub_protocol_alloc()

static void __dtor__ast_websocket_sub_protocol_alloc ( void  )
static

Definition at line 152 of file http_websocket.h.

152 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __dtor__ast_websocket_unref()

static void __dtor__ast_websocket_unref ( void  )
static

Definition at line 329 of file http_websocket.h.

329 {return;});

◆ __dtor__ast_websocket_uri_cb()

static void __dtor__ast_websocket_uri_cb ( void  )
static

Definition at line 143 of file http_websocket.h.

143 { return -1; });

◆ __dtor__ast_websocket_wait_for_input()

static void __dtor__ast_websocket_wait_for_input ( void  )
static

Definition at line 352 of file http_websocket.h.

352 { errno = ENOSYS; return -1; });
int errno

◆ __dtor__ast_websocket_write()

static void __dtor__ast_websocket_write ( void  )
static

Definition at line 274 of file http_websocket.h.

274 { errno = ENOSYS; return -1;});
int errno

◆ __dtor__ast_websocket_write_string()

static void __dtor__ast_websocket_write_string ( void  )
static

Definition at line 286 of file http_websocket.h.

286 { errno = ENOSYS; return -1;});
int errno

◆ __init__ast_websocket_add_protocol()

static void __init__ast_websocket_add_protocol ( void  )
static

Definition at line 163 of file http_websocket.h.

163 {return -1;});

◆ __init__ast_websocket_add_protocol2()

static void __init__ast_websocket_add_protocol2 ( void  )
static

Definition at line 178 of file http_websocket.h.

178 {return -1;});

◆ __init__ast_websocket_client_accept_protocol()

static void __init__ast_websocket_client_accept_protocol ( void  )
static

Definition at line 447 of file http_websocket.h.

447 { return NULL;});
#define NULL
Definition: resample.c:96

◆ __init__ast_websocket_client_create()

static void __init__ast_websocket_client_create ( void  )
static

Definition at line 437 of file http_websocket.h.

437 { return NULL;});
#define NULL
Definition: resample.c:96

◆ __init__ast_websocket_close()

static void __init__ast_websocket_close ( void  )
static

Definition at line 296 of file http_websocket.h.

296 { errno = ENOSYS; return -1;});
int errno

◆ __init__ast_websocket_fd()

static void __init__ast_websocket_fd ( void  )
static

Definition at line 338 of file http_websocket.h.

338 { errno = ENOSYS; return -1;});
int errno

◆ __init__ast_websocket_is_secure()

static void __init__ast_websocket_is_secure ( void  )
static

Definition at line 376 of file http_websocket.h.

376 { errno = ENOSYS; return -1;});
int errno

◆ __init__ast_websocket_local_address()

static void __init__ast_websocket_local_address ( void  )
static

Definition at line 368 of file http_websocket.h.

368 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __init__ast_websocket_read()

static void __init__ast_websocket_read ( void  )
static

Definition at line 245 of file http_websocket.h.

245 { errno = ENOSYS; return -1;});
int errno

◆ __init__ast_websocket_read_string()

static void __init__ast_websocket_read_string ( void  )
static

Definition at line 261 of file http_websocket.h.

261 { errno = ENOSYS; return -1;});
int errno

◆ __init__ast_websocket_reconstruct_disable()

static void __init__ast_websocket_reconstruct_disable ( void  )
static

Definition at line 315 of file http_websocket.h.

315 {return;});

◆ __init__ast_websocket_reconstruct_enable()

static void __init__ast_websocket_reconstruct_enable ( void  )
static

Definition at line 305 of file http_websocket.h.

305 {return;});

◆ __init__ast_websocket_ref()

static void __init__ast_websocket_ref ( void  )
static

Definition at line 322 of file http_websocket.h.

322 {return;});

◆ __init__ast_websocket_remote_address()

static void __init__ast_websocket_remote_address ( void  )
static

Definition at line 359 of file http_websocket.h.

359 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __init__ast_websocket_remove_protocol()

static void __init__ast_websocket_remove_protocol ( void  )
static

Definition at line 189 of file http_websocket.h.

189 {return -1;});

◆ __init__ast_websocket_server_add_protocol()

static void __init__ast_websocket_server_add_protocol ( void  )
static

Definition at line 201 of file http_websocket.h.

201 {return -1;});

◆ __init__ast_websocket_server_add_protocol2()

static void __init__ast_websocket_server_add_protocol2 ( void  )
static

Definition at line 217 of file http_websocket.h.

217 {return -1;});

◆ __init__ast_websocket_server_create()

static void __init__ast_websocket_server_create ( void  )
static

Definition at line 135 of file http_websocket.h.

135 { return NULL; });
#define NULL
Definition: resample.c:96

◆ __init__ast_websocket_server_remove_protocol()

static void __init__ast_websocket_server_remove_protocol ( void  )
static

Definition at line 229 of file http_websocket.h.

229 {return -1;});

◆ __init__ast_websocket_session_id()

static void __init__ast_websocket_session_id ( void  )
static

Definition at line 391 of file http_websocket.h.

391 { errno = ENOSYS; return NULL;});
#define NULL
Definition: resample.c:96
int errno

◆ __init__ast_websocket_set_nonblock()

static void __init__ast_websocket_set_nonblock ( void  )
static

Definition at line 384 of file http_websocket.h.

384 { errno = ENOSYS; return -1;});
int errno

◆ __init__ast_websocket_set_timeout()

static void __init__ast_websocket_set_timeout ( void  )
static

Definition at line 458 of file http_websocket.h.

458 {return -1;});

◆ __init__ast_websocket_sub_protocol_alloc()

static void __init__ast_websocket_sub_protocol_alloc ( void  )
static

Definition at line 152 of file http_websocket.h.

152 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __init__ast_websocket_unref()

static void __init__ast_websocket_unref ( void  )
static

Definition at line 329 of file http_websocket.h.

329 {return;});

◆ __init__ast_websocket_uri_cb()

static void __init__ast_websocket_uri_cb ( void  )
static

Definition at line 143 of file http_websocket.h.

143 { return -1; });

◆ __init__ast_websocket_wait_for_input()

static void __init__ast_websocket_wait_for_input ( void  )
static

Definition at line 352 of file http_websocket.h.

352 { errno = ENOSYS; return -1; });
int errno

◆ __init__ast_websocket_write()

static void __init__ast_websocket_write ( void  )
static

Definition at line 274 of file http_websocket.h.

274 { errno = ENOSYS; return -1;});
int errno

◆ __init__ast_websocket_write_string()

static void __init__ast_websocket_write_string ( void  )
static

Definition at line 286 of file http_websocket.h.

286 { errno = ENOSYS; return -1;});
int errno

◆ __stub__ast_websocket_add_protocol()

static int __stub__ast_websocket_add_protocol ( const char *  name,
ast_websocket_callback  callback 
)
static

Add a sub-protocol handler to the default /ws server.

Parameters
nameName of the sub-protocol to register
callbackCallback called when a new connection requesting the sub-protocol is established
Return values
0success
-1if sub-protocol handler could not be registered

Definition at line 163 of file http_websocket.h.

163 {return -1;});

◆ __stub__ast_websocket_add_protocol2()

static int __stub__ast_websocket_add_protocol2 ( struct ast_websocket_protocol protocol)
static

Add a sub-protocol handler to the default /ws server.

Parameters
protocolThe sub-protocol to register. Note that this must be allocated using /ref ast_websocket_sub_protocol_alloc.
Note
This method is reference stealing. It will steal the reference to protocol on success.
Return values
0success
-1if sub-protocol handler could not be registered
Since
13.5.0

Definition at line 178 of file http_websocket.h.

178 {return -1;});

◆ __stub__ast_websocket_client_accept_protocol()

static const char* __stub__ast_websocket_client_accept_protocol ( struct ast_websocket ws)
static

Retrieve the server accepted sub-protocol on the client.

Parameters
wsthe websocket client
Return values
theaccepted client sub-protocol.
Since
13

Definition at line 447 of file http_websocket.h.

References NULL.

447 { return NULL;});
#define NULL
Definition: resample.c:96

◆ __stub__ast_websocket_client_create()

static struct ast_websocket* __stub__ast_websocket_client_create ( const char *  uri,
const char *  protocols,
struct ast_tls_config tls_cfg,
enum ast_websocket_result result 
)
static

Create, and connect, a websocket client.

If the client websocket successfully connects, then the accepted protocol can be checked via a call to ast_websocket_client_accept_protocol.

Note
While connecting this will block until a response is received from the remote host.
Expected uri form: ws[s]://<address>[:port][/<path>] The address (can be a host name) and port are parsed out and used to connect to the remote server. If multiple IPs are returned during address resolution then the first one is chosen.
Parameters
uriuri to connect to
protocolsa comma separated string of supported protocols
tls_cfgsecure websocket credentials
resultresult code set on client failure
Return values
aclient websocket.
NULLif object could not be created or connected
Since
13

Definition at line 437 of file http_websocket.h.

References AST_OPTIONAL_API, ast_websocket_client_accept_protocol(), and NULL.

437 { return NULL;});
#define NULL
Definition: resample.c:96

◆ __stub__ast_websocket_close()

static int __stub__ast_websocket_close ( struct ast_websocket session,
uint16_t  reason 
)
static

Close a WebSocket session by sending a message with the CLOSE opcode and an optional code.

Parameters
sessionPointer to the WebSocket session
reasonReason code for closing the session as defined in the RFC
Return values
0if successfully written
-1if error occurred

Definition at line 296 of file http_websocket.h.

References errno.

296 { errno = ENOSYS; return -1;});
int errno

◆ __stub__ast_websocket_fd()

static int __stub__ast_websocket_fd ( struct ast_websocket session)
static

Get the file descriptor for a WebSocket session.

Return values
filedescriptor
Note
You must not directly read from or write to this file descriptor. It should only be used for polling.

Definition at line 338 of file http_websocket.h.

References errno.

338 { errno = ENOSYS; return -1;});
int errno

◆ __stub__ast_websocket_is_secure()

static int __stub__ast_websocket_is_secure ( struct ast_websocket session)
static

Get whether the WebSocket session is using a secure transport or not.

Return values
0if unsecure
1if secure

Definition at line 376 of file http_websocket.h.

References errno.

376 { errno = ENOSYS; return -1;});
int errno

◆ __stub__ast_websocket_local_address()

static struct ast_sockaddr* __stub__ast_websocket_local_address ( struct ast_websocket session)
static

Get the local address for a WebSocket connection session.

Return values
ast_sockaddrLocal address
Since
13.19.0

Definition at line 368 of file http_websocket.h.

References NULL.

368 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __stub__ast_websocket_read()

static int __stub__ast_websocket_read ( struct ast_websocket session,
char **  payload,
uint64_t *  payload_len,
enum ast_websocket_opcode opcode,
int *  fragmented 
)
static

Read a WebSocket frame and handle it.

Parameters
sessionPointer to the WebSocket session
payloadPointer to a char* which will be populated with a pointer to the payload if present
payload_lenPointer to a uint64_t which will be populated with the length of the payload if present
opcodePointer to an enum which will be populated with the opcode of the frame
fragmentedPointer to an int which is set to 1 if payload is fragmented and 0 if not
Return values
-1on error
0on success
Note
Once an AST_WEBSOCKET_OPCODE_CLOSE opcode is received the socket will be closed

Definition at line 245 of file http_websocket.h.

References AST_OPTIONAL_API, ast_websocket_read_string(), buf, and errno.

245 { errno = ENOSYS; return -1;});
int errno

◆ __stub__ast_websocket_read_string()

static int __stub__ast_websocket_read_string ( struct ast_websocket ws,
char **  buf 
)
static

Read a WebSocket frame containing string data.

Note
The caller is responsible for freeing the output "buf".
Parameters
wspointer to the websocket
bufstring buffer to populate with data read from socket
Return values
-1on error
numberof bytes read on success
Note
Once an AST_WEBSOCKET_OPCODE_CLOSE opcode is received the socket will be closed

Definition at line 261 of file http_websocket.h.

References errno.

261 { errno = ENOSYS; return -1;});
int errno

◆ __stub__ast_websocket_reconstruct_disable()

static void __stub__ast_websocket_reconstruct_disable ( struct ast_websocket session)
static

Disable multi-frame reconstruction.

Parameters
sessionPointer to the WebSocket session
Note
If reconstruction is disabled each message that is part of a multi-frame message will be sent up to the user when ast_websocket_read is called.

Definition at line 315 of file http_websocket.h.

315 {return;});

◆ __stub__ast_websocket_reconstruct_enable()

static void __stub__ast_websocket_reconstruct_enable ( struct ast_websocket session,
size_t  bytes 
)
static

Enable multi-frame reconstruction up to a certain number of bytes.

Parameters
sessionPointer to the WebSocket session
bytesIf a reconstructed payload exceeds the specified number of bytes the payload will be returned and upon reception of the next multi-frame a new reconstructed payload will begin.

Definition at line 305 of file http_websocket.h.

305 {return;});

◆ __stub__ast_websocket_ref()

static void __stub__ast_websocket_ref ( struct ast_websocket session)
static

Increase the reference count for a WebSocket session.

Parameters
sessionPointer to the WebSocket session

Definition at line 322 of file http_websocket.h.

322 {return;});

◆ __stub__ast_websocket_remote_address()

static struct ast_sockaddr* __stub__ast_websocket_remote_address ( struct ast_websocket session)
static

Get the remote address for a WebSocket connected session.

Return values
ast_sockaddrRemote address

Definition at line 359 of file http_websocket.h.

References NULL.

359 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __stub__ast_websocket_remove_protocol()

static int __stub__ast_websocket_remove_protocol ( const char *  name,
ast_websocket_callback  callback 
)
static

Remove a sub-protocol handler from the default /ws server.

Parameters
nameName of the sub-protocol to unregister
callbackSession Established callback that was previously registered with the sub-protocol
Return values
0success
-1if sub-protocol was not found or if callback did not match

Definition at line 189 of file http_websocket.h.

189 {return -1;});

◆ __stub__ast_websocket_server_add_protocol()

static int __stub__ast_websocket_server_add_protocol ( struct ast_websocket_server server,
const char *  name,
ast_websocket_callback  callback 
)
static

Add a sub-protocol handler to the given server.

Parameters
nameName of the sub-protocol to register
callbackCallback called when a new connection requesting the sub-protocol is established
Return values
0success
-1if sub-protocol handler could not be registered
Since
12

Definition at line 201 of file http_websocket.h.

201 {return -1;});

◆ __stub__ast_websocket_server_add_protocol2()

static int __stub__ast_websocket_server_add_protocol2 ( struct ast_websocket_server server,
struct ast_websocket_protocol protocol 
)
static

Add a sub-protocol handler to the given server.

Parameters
serverThe server to add the sub-protocol to.
protocolThe sub-protocol to register. Note that this must be allocated using /ref ast_websocket_sub_protocol_alloc.
Note
This method is reference stealing. It will steal the reference to protocol on success.
Return values
0success
-1if sub-protocol handler could not be registered
Since
13.5.0

Definition at line 217 of file http_websocket.h.

217 {return -1;});

◆ __stub__ast_websocket_server_create()

static struct ast_websocket_server* __stub__ast_websocket_server_create ( void  )
static

Creates a websocket_server.

Return values
Newwebsocket_server instance

Definition at line 135 of file http_websocket.h.

References NULL.

135 { return NULL; });
#define NULL
Definition: resample.c:96

◆ __stub__ast_websocket_server_remove_protocol()

static int __stub__ast_websocket_server_remove_protocol ( struct ast_websocket_server server,
const char *  name,
ast_websocket_callback  callback 
)
static

Remove a sub-protocol handler from the given server.

Parameters
nameName of the sub-protocol to unregister
callbackCallback that was previously registered with the sub-protocol
Return values
0success
-1if sub-protocol was not found or if callback did not match
Since
12

Definition at line 229 of file http_websocket.h.

229 {return -1;});

◆ __stub__ast_websocket_session_id()

static const char* __stub__ast_websocket_session_id ( struct ast_websocket session)
static

Get the session ID for a WebSocket session.

Return values
sessionid

Definition at line 391 of file http_websocket.h.

References errno, and NULL.

391 { errno = ENOSYS; return NULL;});
#define NULL
Definition: resample.c:96
int errno

◆ __stub__ast_websocket_set_nonblock()

static int __stub__ast_websocket_set_nonblock ( struct ast_websocket session)
static

Set the socket of a WebSocket session to be non-blocking.

Return values
0on success
-1on failure

Definition at line 384 of file http_websocket.h.

References errno.

384 { errno = ENOSYS; return -1;});
int errno

◆ __stub__ast_websocket_set_timeout()

static int __stub__ast_websocket_set_timeout ( struct ast_websocket session,
int  timeout 
)
static

Set the timeout on a non-blocking WebSocket session.

Since
11.11.0
12.4.0
Return values
0on success
-1on failure

Definition at line 458 of file http_websocket.h.

458 {return -1;});

◆ __stub__ast_websocket_sub_protocol_alloc()

static struct ast_websocket_protocol* __stub__ast_websocket_sub_protocol_alloc ( const char *  name)
static

Allocate a websocket sub-protocol instance.

Return values
Aninstance of ast_websocket_protocol on success
NULLon error
Since
13.5.0

Definition at line 152 of file http_websocket.h.

References NULL.

152 {return NULL;});
#define NULL
Definition: resample.c:96

◆ __stub__ast_websocket_unref()

static void __stub__ast_websocket_unref ( struct ast_websocket session)
static

Decrease the reference count for a WebSocket session.

Parameters
sessionPointer to the WebSocket session

Definition at line 329 of file http_websocket.h.

329 {return;});

◆ __stub__ast_websocket_uri_cb()

static int __stub__ast_websocket_uri_cb ( struct ast_tcptls_session_instance ser,
const struct ast_http_uri urih,
const char *  uri,
enum ast_http_method  method,
struct ast_variable get_vars,
struct ast_variable headers 
)
static

Callback suitable for use with a ast_http_uri.

Set the data field of the ast_http_uri to ast_websocket_server.

Since
12

Definition at line 143 of file http_websocket.h.

143 { return -1; });

◆ __stub__ast_websocket_wait_for_input()

static int __stub__ast_websocket_wait_for_input ( struct ast_websocket session,
int  timeout 
)
static

Wait for the WebSocket session to be ready to be read.

Since
16.8.0
17.2.0
Parameters
sessionPointer to the WebSocket session
timeoutthe number of milliseconds to wait
Return values
-1if error occurred
0if the timeout expired
1if the WebSocket session is ready for reading

Definition at line 352 of file http_websocket.h.

References errno.

352 { errno = ENOSYS; return -1; });
int errno

◆ __stub__ast_websocket_write()

static int __stub__ast_websocket_write ( struct ast_websocket session,
enum ast_websocket_opcode  opcode,
char *  payload,
uint64_t  payload_size 
)
static

Construct and transmit a WebSocket frame.

Parameters
sessionPointer to the WebSocket session
opcodeWebSocket operation code to place in the frame
payloadOptional pointer to a payload to add to the frame
payload_sizeLength of the payload (0 if no payload)
Return values
0if successfully written
-1if error occurred

Definition at line 274 of file http_websocket.h.

References AST_OPTIONAL_API, ast_websocket_write_string(), and errno.

274 { errno = ENOSYS; return -1;});
int errno

◆ __stub__ast_websocket_write_string()

static int __stub__ast_websocket_write_string ( struct ast_websocket ws,
const char *  buf 
)
static

Construct and transmit a WebSocket frame containing string data.

Parameters
wspointer to the websocket
bufstring data to write to socket
Return values
0if successfully written
-1if error occurred

Definition at line 286 of file http_websocket.h.

References errno.

286 { errno = ENOSYS; return -1;});
int errno

◆ typeof() [1/28]

static typeof ( __stub__ast_websocket_server_create  )
static

◆ typeof() [2/28]

static typeof ( __stub__ast_websocket_uri_cb  )
static

◆ typeof() [3/28]

static typeof ( __stub__ast_websocket_sub_protocol_alloc  )
static

◆ typeof() [4/28]

static typeof ( __stub__ast_websocket_add_protocol  )
static

◆ typeof() [5/28]

static typeof ( __stub__ast_websocket_add_protocol2  )
static

◆ typeof() [6/28]

static typeof ( __stub__ast_websocket_remove_protocol  )
static

◆ typeof() [7/28]

static typeof ( __stub__ast_websocket_server_add_protocol  )
static

◆ typeof() [8/28]

static typeof ( __stub__ast_websocket_server_add_protocol2  )
static

◆ typeof() [9/28]

◆ typeof() [10/28]

static typeof ( __stub__ast_websocket_read  )
static

◆ typeof() [11/28]

static typeof ( __stub__ast_websocket_read_string  )
static

◆ typeof() [12/28]

static typeof ( __stub__ast_websocket_write  )
static

◆ typeof() [13/28]

static typeof ( __stub__ast_websocket_write_string  )
static

◆ typeof() [14/28]

static typeof ( __stub__ast_websocket_close  )
static

◆ typeof() [15/28]

static typeof ( __stub__ast_websocket_reconstruct_enable  ) const
static

◆ typeof() [16/28]

static typeof ( __stub__ast_websocket_reconstruct_disable  ) const
static

◆ typeof() [17/28]

static typeof ( __stub__ast_websocket_ref  )
static

◆ typeof() [18/28]

static typeof ( __stub__ast_websocket_unref  )
static

◆ typeof() [19/28]

static typeof ( __stub__ast_websocket_fd  )
static

◆ typeof() [20/28]

static typeof ( __stub__ast_websocket_wait_for_input  )
static

◆ typeof() [21/28]

static typeof ( __stub__ast_websocket_remote_address  )
static

◆ typeof() [22/28]

static typeof ( __stub__ast_websocket_local_address  )
static

◆ typeof() [23/28]

static typeof ( __stub__ast_websocket_is_secure  )
static

◆ typeof() [24/28]

static typeof ( __stub__ast_websocket_set_nonblock  )
static

◆ typeof() [25/28]

static typeof ( __stub__ast_websocket_session_id  )
static

◆ typeof() [26/28]

static typeof ( __stub__ast_websocket_client_create  )
static

◆ typeof() [27/28]

◆ typeof() [28/28]

static typeof ( __stub__ast_websocket_set_timeout  )
static