28#define log_error(obj, fmt, ...) aeap_error(obj, "websocket", fmt, ##__VA_ARGS__)
38 const char *protocol,
int timeout)
44 .protocols = protocol,
50 if (ws_result !=
WS_OK) {
51 log_error(self,
"connect failure (%d)", (
int)ws_result);
85 uint64_t bytes_read = 0;
86 uint64_t total_bytes_read = 0;
93 log_error(self,
"unavailable for reading");
120 if (!transport->
ws) {
131 log_error(self,
"read failure (%d): %s", opcode, strerror(
errno));
139 if (total_bytes_read + bytes_read > size) {
140 log_error(self,
"attempted to read too many bytes into (%jd) sized buffer", size);
144 memcpy(
buf + total_bytes_read, payload, bytes_read);
145 total_bytes_read += bytes_read;
160 if (total_bytes_read == size) {
161 log_error(self,
"unable to write string terminator");
165 *((
char *)(
buf + total_bytes_read)) =
'\0';
172 return total_bytes_read;
195 log_error(self,
"problem writing to websocket (closed)");
219 return &websocket_vtable;
242 transport =
ast_calloc(1,
sizeof(*transport));
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
int 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.
int ast_websocket_wait_for_input(struct ast_websocket *session, int timeout)
Wait for the WebSocket session to be ready to be read.
struct ast_websocket * ast_websocket_client_create_with_options(struct ast_websocket_client_options *options, enum ast_websocket_result *result)
Create, and connect, a websocket client using given options.
ast_websocket_result
Result code for a websocket client.
ast_websocket_opcode
WebSocket operation codes.
@ AST_WEBSOCKET_OPCODE_CONTINUATION
@ AST_WEBSOCKET_OPCODE_BINARY
@ AST_WEBSOCKET_OPCODE_CLOSE
@ AST_WEBSOCKET_OPCODE_TEXT
void ast_websocket_unref(struct ast_websocket *session)
Decrease the reference count for a WebSocket session.
int ast_websocket_fd(struct ast_websocket *session)
Get the file descriptor for a WebSocket session.
int ast_websocket_write(struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t payload_size)
Construct and transmit a WebSocket frame.
#define ast_mutex_unlock(a)
#define ast_mutex_lock(a)
AST_AEAP_DATA_TYPE
Supported Asterisk external application data types.
@ AST_AEAP_DATA_TYPE_NONE
@ AST_AEAP_DATA_TYPE_BINARY
@ AST_AEAP_DATA_TYPE_STRING
Asterisk external application transport virtual table.
int(* connect)(struct aeap_transport *self, const char *url, const char *protocol, int timeout)
Connect a transport.
struct aeap_transport base
struct ast_websocket * ws
Asterisk external application transport structure to be "derived" by specific transport implementatio...
Options used for a websocket client.
Structure definition for session.
int aeap_transport_disconnect(struct aeap_transport *transport)
Disconnect a transport.
static void websocket_destroy(struct aeap_transport *self)
static int websocket_disconnect(struct aeap_transport *self)
static intmax_t websocket_read(struct aeap_transport *self, void *buf, intmax_t size, enum AST_AEAP_DATA_TYPE *rtype)
static intmax_t websocket_write(struct aeap_transport *self, const void *buf, intmax_t size, enum AST_AEAP_DATA_TYPE wtype)
struct aeap_transport_websocket * aeap_transport_websocket_create(void)
Creates (heap allocated), and initializes a transport websocket.
static int transport_websocket_init(struct aeap_transport_websocket *transport)
Initialize a transport websocket object, and set its virtual table.
#define log_error(obj, fmt,...)
static int websocket_connect(struct aeap_transport *self, const char *url, const char *protocol, int timeout)
static struct aeap_transport_vtable * transport_websocket_vtable(void)