Asterisk - The Open Source Telephony Project GIT-master-6144b6b
Loading...
Searching...
No Matches
http_websocket.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2012, Digium, Inc.
5 *
6 * Joshua Colp <jcolp@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19#ifndef _ASTERISK_HTTP_WEBSOCKET_H
20#define _ASTERISK_HTTP_WEBSOCKET_H
21
22#include "asterisk/http.h"
24
25#include <errno.h>
26
27/*! \brief Default websocket write timeout, in ms */
28#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT 100
29
30/*! \brief Default websocket write timeout, in ms (as a string) */
31#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR "100"
32
33/*!
34 * \file
35 *
36 * \brief Support for WebSocket connections within the Asterisk HTTP server and client
37 * WebSocket connections to a server.
38 *
39 * Supported WebSocket versions in server implementation:
40 * Version 7 defined in specification http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07
41 * Version 8 defined in specification http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10
42 * Version 13 defined in specification http://tools.ietf.org/html/rfc6455
43 * Supported WebSocket versions in client implementation:
44 * Version 13 defined in specification http://tools.ietf.org/html/rfc6455
45 *
46 * \author Joshua Colp <jcolp@digium.com>
47 *
48 */
49
50/*! \brief WebSocket connection/configuration types.
51 *
52 * These may look like they overlap or are redundant, but
53 * they're shared by other modules like ari and chan_websocket
54 * and it didn't make sense to force them to define their
55 * own types.
56 */
66
68
69
70/*! \brief WebSocket operation codes */
72 AST_WEBSOCKET_OPCODE_TEXT = 0x1, /*!< Text frame */
73 AST_WEBSOCKET_OPCODE_BINARY = 0x2, /*!< Binary frame */
74 AST_WEBSOCKET_OPCODE_PING = 0x9, /*!< Request that the other side respond with a pong */
75 AST_WEBSOCKET_OPCODE_PONG = 0xA, /*!< Response to a ping */
76 AST_WEBSOCKET_OPCODE_CLOSE = 0x8, /*!< Connection is being closed */
77 AST_WEBSOCKET_OPCODE_CONTINUATION = 0x0, /*!< Continuation of a previous frame */
78 AST_WEBSOCKET_OPCODE_UNKNOWN = 0xf, /*!< Error */
79};
80
81/*! \brief Websocket Status Codes from RFC-6455 */
100
101#ifdef LOW_MEMORY
102/*! \brief Size of the pre-determined buffer for WebSocket frames */
103#define AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE 8192
104#else
105/*! \brief Size of the pre-determined buffer for WebSocket frames */
106#define AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE 65535
107#endif
108
109/*!
110 * \brief Opaque structure for WebSocket server.
111 * \since 12
112 */
114
115/*!
116 * \brief Opaque structure for WebSocket sessions.
117 */
118struct ast_websocket;
119
120/*!
121 * \brief Callback from the HTTP request attempting to establish a websocket connection
122 *
123 * This callback occurs when an HTTP request is made to establish a websocket connection.
124 * Implementers of \ref ast_websocket_protocol can use this to deny a request, or to
125 * set up application specific data before invocation of \ref ast_websocket_callback.
126 *
127 * \param ser The TCP/TLS session
128 * \param parameters Parameters extracted from the request URI
129 * \param headers Headers included in the request
130 * \param session_id The id of the current session.
131 *
132 * \retval 0 The session should be accepted
133 * \retval -1 The session should be rejected. Note that the caller must send an error
134 * response using \ref ast_http_error.
135 * \since 13.5.0
136 */
137typedef int (*ast_websocket_pre_callback)(struct ast_tcptls_session_instance *ser, struct ast_variable *parameters, struct ast_variable *headers, const char *session_id);
138
139/*!
140 * \brief Callback for when a new connection for a sub-protocol is established
141 *
142 * \param session A WebSocket session structure
143 * \param parameters Parameters extracted from the request URI
144 * \param headers Headers included in the request
145 *
146 * \note Once called the ownership of the session is transferred to the sub-protocol handler. It
147 * is responsible for closing and cleaning up.
148 *
149 */
150typedef void (*ast_websocket_callback)(struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers);
151
152/*!
153 * \brief A websocket protocol implementation
154 *
155 * Users of the Websocket API can register themselves as a websocket
156 * protocol. See \ref ast_websocket_add_protocol2 and \ref ast_websocket_server_add_protocol2.
157 * Simpler implementations may use only \ref ast_websocket_add_protocol and
158 * \ref ast_websocket_server_add_protocol.
159 *
160 * \since 13.5.0
161 */
163 /*! \brief Name of the protocol */
164 char *name;
165/*!
166 * \brief Protocol version. This prevents dynamically loadable modules from registering
167 * if this struct is changed.
168 */
169#define AST_WEBSOCKET_PROTOCOL_VERSION 1
170 /*! \brief Protocol version. Should be set to /ref AST_WEBSOCKET_PROTOCOL_VERSION */
171 unsigned int version;
172 /*! \brief Callback called when a new session is attempted. Optional. */
174 /*! \brief Callback called when a new session is established. Mandatory. */
176};
177
178/*!
179 * \brief Creates a \ref ast_websocket_server
180 *
181 * \return New \ref ast_websocket_server instance
182 * \retval NULL on error
183 * \since 12
184 */
186
187/*!
188 * \brief Callback suitable for use with a \ref ast_http_uri.
189 *
190 * Set the data field of the ast_http_uri to \ref ast_websocket_server.
191 * \since 12
192 */
193AST_OPTIONAL_API(int, 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), { return -1; });
194
195/*!
196 * \brief Allocate a websocket sub-protocol instance
197 *
198 * \return An instance of \ref ast_websocket_protocol on success
199 * \retval NULL on error
200 * \since 13.5.0
201 */
203
204/*!
205 * \brief Add a sub-protocol handler to the default /ws server
206 *
207 * \param name Name of the sub-protocol to register
208 * \param callback Callback called when a new connection requesting the sub-protocol is established
209 *
210 * \retval 0 success
211 * \retval -1 if sub-protocol handler could not be registered
212 */
214
215/*!
216 * \brief Add a sub-protocol handler to the default /ws server
217 *
218 * \param protocol The sub-protocol to register. Note that this must
219 * be allocated using /ref ast_websocket_sub_protocol_alloc.
220 *
221 * \note This method is reference stealing. It will steal the reference to \p protocol
222 * on success.
223 *
224 * \retval 0 success
225 * \retval -1 if sub-protocol handler could not be registered
226 * \since 13.5.0
227 */
228AST_OPTIONAL_API(int, ast_websocket_add_protocol2, (struct ast_websocket_protocol *protocol), {return -1;});
229
230/*!
231 * \brief Remove a sub-protocol handler from the default /ws server.
232 *
233 * \param name Name of the sub-protocol to unregister
234 * \param callback Session Established callback that was previously registered with the sub-protocol
235 *
236 * \retval 0 success
237 * \retval -1 if sub-protocol was not found or if callback did not match
238 */
240
241/*!
242 * \brief Add a sub-protocol handler to the given server.
243 *
244 * \param server The server to add the sub-protocol to
245 * \param name Name of the sub-protocol to register
246 * \param callback Callback called when a new connection requesting the sub-protocol is established
247 *
248 * \retval 0 success
249 * \retval -1 if sub-protocol handler could not be registered
250 * \since 12
251 */
253
254/*!
255 * \brief Add a sub-protocol handler to the given server.
256 *
257 * \param server The server to add the sub-protocol to.
258 * \param protocol The sub-protocol to register. Note that this must
259 * be allocated using /ref ast_websocket_sub_protocol_alloc.
260 *
261 * \note This method is reference stealing. It will steal the reference to \p protocol
262 * on success.
263 *
264 * \retval 0 success
265 * \retval -1 if sub-protocol handler could not be registered
266 * \since 13.5.0
267 */
268AST_OPTIONAL_API(int, ast_websocket_server_add_protocol2, (struct ast_websocket_server *server, struct ast_websocket_protocol *protocol), {return -1;});
269
270/*!
271 * \brief Remove a sub-protocol handler from the given server.
272 *
273 * \param server The server to unregister the sub-protocol from
274 * \param name Name of the sub-protocol to unregister
275 * \param callback Callback that was previously registered with the sub-protocol
276 *
277 * \retval 0 success
278 * \retval -1 if sub-protocol was not found or if callback did not match
279 * \since 12
280 */
282
283/*!
284 * \brief Read a WebSocket frame and handle it
285 *
286 * \param session Pointer to the WebSocket session
287 * \param payload Pointer to a char* which will be populated with a pointer to the payload if present
288 * \param payload_len Pointer to a uint64_t which will be populated with the length of the payload if present
289 * \param opcode Pointer to an enum which will be populated with the opcode of the frame
290 * \param fragmented Pointer to an int which is set to 1 if payload is fragmented and 0 if not
291 *
292 * \retval -1 on error
293 * \retval 0 on success
294 *
295 * \note Once an AST_WEBSOCKET_OPCODE_CLOSE opcode is received the socket will be closed
296 */
297AST_OPTIONAL_API(int, ast_websocket_read, (struct ast_websocket *session, char **payload, uint64_t *payload_len, enum ast_websocket_opcode *opcode, int *fragmented), { errno = ENOSYS; return -1;});
298
299/*!
300 * \brief Read a WebSocket frame containing string data.
301 *
302 * \note The caller is responsible for freeing the output "buf".
303 *
304 * \param ws pointer to the websocket
305 * \param buf string buffer to populate with data read from socket
306 * \retval -1 on error
307 * \return number of bytes read on success
308 *
309 * \note Once an AST_WEBSOCKET_OPCODE_CLOSE opcode is received the socket will be closed
310 */
312 (struct ast_websocket *ws, char **buf),
313 { errno = ENOSYS; return -1;});
314
315/*!
316 * \brief Construct and transmit a WebSocket frame
317 *
318 * \param session Pointer to the WebSocket session
319 * \param opcode WebSocket operation code to place in the frame
320 * \param payload Optional pointer to a payload to add to the frame
321 * \param payload_size Length of the payload (0 if no payload)
322 *
323 * \retval 0 if successfully written
324 * \retval -1 if error occurred
325 */
326AST_OPTIONAL_API(int, ast_websocket_write, (struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t payload_size), { errno = ENOSYS; return -1;});
327
328/*!
329 * \brief Construct and transmit a WebSocket frame containing string data.
330 *
331 * \param ws pointer to the websocket
332 * \param buf string data to write to socket
333 * \retval 0 if successfully written
334 * \retval -1 if error occurred
335 */
337 (struct ast_websocket *ws, const char *buf),
338 { errno = ENOSYS; return -1;});
339/*!
340 * \brief Close a WebSocket session by sending a message with the CLOSE opcode and an optional code
341 *
342 * \param session Pointer to the WebSocket session
343 * \param reason Reason code for closing the session as defined in the RFC
344 *
345 * \retval 0 if successfully written
346 * \retval -1 if error occurred
347 */
348AST_OPTIONAL_API(int, ast_websocket_close, (struct ast_websocket *session, uint16_t reason), { errno = ENOSYS; return -1;});
349
350/*!
351 * \brief Enable multi-frame reconstruction up to a certain number of bytes
352 *
353 * \param session Pointer to the WebSocket session
354 * \param bytes If a reconstructed payload exceeds the specified number of bytes the payload will be returned
355 * and upon reception of the next multi-frame a new reconstructed payload will begin.
356 */
357AST_OPTIONAL_API(void, ast_websocket_reconstruct_enable, (struct ast_websocket *session, size_t bytes), {return;});
358
359/*!
360 * \brief Disable multi-frame reconstruction
361 *
362 * \param session Pointer to the WebSocket session
363 *
364 * \note If reconstruction is disabled each message that is part of a multi-frame message will be sent up to
365 * the user when ast_websocket_read is called.
366 */
368
369/*!
370 * \brief Increase the reference count for a WebSocket session
371 *
372 * \param session Pointer to the WebSocket session
373 */
374AST_OPTIONAL_API(void, ast_websocket_ref, (struct ast_websocket *session), {return;});
375
376/*!
377 * \brief Decrease the reference count for a WebSocket session
378 *
379 * \param session Pointer to the WebSocket session
380 */
381AST_OPTIONAL_API(void, ast_websocket_unref, (struct ast_websocket *session), {return;});
382
383/*!
384 * \brief Get the file descriptor for a WebSocket session.
385 *
386 * \return file descriptor
387 *
388 * \note You must *not* directly read from or write to this file descriptor. It should only be used for polling.
389 */
390AST_OPTIONAL_API(int, ast_websocket_fd, (struct ast_websocket *session), { errno = ENOSYS; return -1;});
391
392/*!
393 * \brief Wait for the WebSocket session to be ready to be read.
394 * \since 16.8.0
395 * \since 17.2.0
396 *
397 * \param session Pointer to the WebSocket session
398 * \param timeout the number of milliseconds to wait
399 *
400 * \retval -1 if error occurred
401 * \retval 0 if the timeout expired
402 * \retval 1 if the WebSocket session is ready for reading
403 */
404AST_OPTIONAL_API(int, ast_websocket_wait_for_input, (struct ast_websocket *session, int timeout), { errno = ENOSYS; return -1; });
405
406/*!
407 * \brief Get the remote address for a WebSocket connected session.
408 *
409 * \return Remote address
410 */
412
413/*!
414 * \brief Get the local address for a WebSocket connection session.
415 *
416 * \return Local address
417 *
418 * \since 13.19.0
419 */
421
422/*!
423 * \brief Get whether the WebSocket session is using a secure transport or not.
424 *
425 * \retval 0 if unsecure
426 * \retval 1 if secure
427 */
428AST_OPTIONAL_API(int, ast_websocket_is_secure, (struct ast_websocket *session), { errno = ENOSYS; return -1;});
429
430/*!
431 * \brief Set the socket of a WebSocket session to be non-blocking.
432 *
433 * \retval 0 on success
434 * \retval -1 on failure
435 */
436AST_OPTIONAL_API(int, ast_websocket_set_nonblock, (struct ast_websocket *session), { errno = ENOSYS; return -1;});
437
438/*!
439 * \brief Get the session ID for a WebSocket session.
440 *
441 * \return session id
442 */
443AST_OPTIONAL_API(const char *, ast_websocket_session_id, (struct ast_websocket *session), { errno = ENOSYS; return NULL;});
444
445/*!
446 * \brief Result code for a websocket client.
447 */
466
467/*!
468 * \brief Create, and connect, a websocket client.
469 *
470 * If the client websocket successfully connects, then the accepted protocol can be
471 * checked via a call to ast_websocket_client_accept_protocol.
472 *
473 * \note While connecting this *will* block until a response is
474 * received from the remote host.
475 * \note Expected uri form:
476 * \verbatim ws[s]://<address>[:port][/<path>] \endverbatim
477 * The address (can be a host name) and port are parsed out and used to connect
478 * to the remote server. If multiple IPs are returned during address
479 * resolution then the first one is chosen.
480 *
481 * \param uri uri to connect to
482 * \param protocols a comma separated string of supported protocols
483 * \param tls_cfg secure websocket credentials
484 * \param result result code set on client failure
485 *
486 * \return a client websocket.
487 * \retval NULL if object could not be created or connected
488 * \since 13
489 *
490 * \warning The returned websocket must be closed with \ref ast_websocket_close
491 * and its reference count decremented with \ref ast_websocket_unref when
492 * it's no longer needed.
493 *
494 */
496 (const char *uri, const char *protocols,
497 struct ast_tls_config *tls_cfg,
498 enum ast_websocket_result *result), { return NULL;});
499
500/*!
501 * \brief Options used for a websocket client
502 */
504 /*!
505 * The URI to connect to
506 *
507 * Expected uri form:
508 * \verbatim ws[s]://<address>[:port][/<path>] \endverbatim
509 * The address (can be a host name) and port are parsed out and used to connect
510 * to the remote server. If multiple IPs are returned during address
511 * resolution then the first one is chosen.
512 */
513 const char *uri;
514 /*!
515 * A comma separated string of supported protocols
516 */
517 const char *protocols;
518 /*!
519 * Optional connection timeout
520 *
521 * How long (in milliseconds) to attempt to connect (-1 equals infinite)
522 */
524 /*!
525 * Secure websocket credentials
526 */
528 const char *username; /*!< WebSocket server auth username */
529 const char *password; /*!< WebSocket server auth password */
530
531 int suppress_connection_msgs; /*!< Suppress connection log messages */
532 /*!
533 * Forward proxy
534 */
535 const char *proxy_host; /*!< Proxy server host:port */
536 const char *proxy_username; /*!< Proxy server auth username */
537 const char *proxy_password; /*!< Proxy server auth password */
538 /*!
539 * TCP Keepalives
540 */
541 int tcp_keepalives; /*!< Enable TCP keepalives */
542 unsigned int tcp_keepalive_time; /*!< Start sending when connection has been idle for this many seconds */
543 unsigned int tcp_keepalive_interval; /*!< Send keepalives at this interval in seconds */
544 unsigned int tcp_keepalive_probes; /*!< Close connection after this many missed responses */
545 /*!
546 * WebSocket PING/PONG
547 */
548 int pingpongs; /*!< Enable Websocket PING/PONGs */
549 unsigned int pingpong_interval; /*!< Send PING messages at this interval in seconds */
550 unsigned int pingpong_probes; /*!< Close connection after this many missed responses */
551};
552
553/*!
554 * \brief Create, and connect, a websocket client using given options.
555 *
556 * If the client websocket successfully connects, then the accepted protocol can be
557 * checked via a call to ast_websocket_client_accept_protocol.
558 *
559 * \note While connecting this *will* block until a response is received
560 * from the remote host, or the connection timeout is reached
561 *
562 * \param options Websocket client options
563 * \param result result code set on client failure
564 *
565 * \return a client websocket.
566 * \retval NULL if object could not be created or connected
567 *
568 * \warning The returned websocket must be closed with \ref ast_websocket_close
569 * and its reference count decremented with \ref ast_websocket_unref when
570 * it's no longer needed.
571 */
574 enum ast_websocket_result *result), { return NULL;});
575
576/*!
577 * \brief Retrieve the server accepted sub-protocol on the client.
578 *
579 * \param ws the websocket client
580 * \return the accepted client sub-protocol.
581 * \since 13
582 */
584 (struct ast_websocket *ws), { return NULL;});
585
586/*!
587 * \brief Set the timeout on a non-blocking WebSocket session.
588 *
589 * \since 11.11.0
590 * \since 12.4.0
591 *
592 * \retval 0 on success
593 * \retval -1 on failure
594 */
595AST_OPTIONAL_API(int, ast_websocket_set_timeout, (struct ast_websocket *session, int timeout), {return -1;});
596
597/*!
598 * \brief Convert a websocket result code to a string.
599 *
600 * \param result The result code to convert
601 *
602 * \return A string representation of the result code
603 */
605
606/*!
607 * \brief Convert a websocket status code to a string.
608 *
609 * \param code The code to convert
610 *
611 * \return A string representation of the code
612 */
613AST_OPTIONAL_API(const char *, ast_websocket_status_to_str, (enum ast_websocket_status_code code), {return "";});
614
615#endif
static struct ast_mansession session
static PGresult * result
Definition cel_pgsql.c:84
static const char type[]
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags, int rdlock)
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static const char name[]
Definition format_mp3.c:68
Support for Private Asterisk HTTP Servers.
ast_http_method
HTTP Request methods known by Asterisk.
Definition http.h:58
void AST_OPTIONAL_API_NAME() ast_websocket_ref(struct ast_websocket *session)
Increase the reference count for a WebSocket session.
int AST_OPTIONAL_API_NAME() ast_websocket_add_protocol(const char *name, ast_websocket_callback callback)
Add a sub-protocol handler to the default /ws server.
const char *AST_OPTIONAL_API_NAME() ast_websocket_session_id(struct ast_websocket *session)
Get the session ID for a WebSocket session.
int AST_OPTIONAL_API_NAME() ast_websocket_write(struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t payload_size)
Construct and transmit a WebSocket frame.
ast_websocket_status_code
Websocket Status Codes from RFC-6455.
@ AST_WEBSOCKET_STATUS_RESERVED_1015
@ AST_WEBSOCKET_STATUS_BAD_GATEWAY
@ AST_WEBSOCKET_STATUS_UNSUPPORTED_DATA
@ AST_WEBSOCKET_STATUS_PROTOCOL_ERROR
@ AST_WEBSOCKET_STATUS_NORMAL
@ AST_WEBSOCKET_STATUS_MANDATORY_EXT
@ AST_WEBSOCKET_STATUS_TOO_BIG
@ AST_WEBSOCKET_STATUS_RESERVED_1006
@ AST_WEBSOCKET_STATUS_RESERVED_1004
@ AST_WEBSOCKET_STATUS_RESERVED_1013
@ AST_WEBSOCKET_STATUS_RESERVED_1005
@ AST_WEBSOCKET_STATUS_POLICY_VIOLATION
@ AST_WEBSOCKET_STATUS_GOING_AWAY
@ AST_WEBSOCKET_STATUS_INTERNAL_ERROR
@ AST_WEBSOCKET_STATUS_RESERVED_1012
@ AST_WEBSOCKET_STATUS_INVALID_FRAME
int AST_OPTIONAL_API_NAME() ast_websocket_server_add_protocol2(struct ast_websocket_server *server, struct ast_websocket_protocol *protocol)
Add a sub-protocol handler to the given server.
int AST_OPTIONAL_API_NAME() ast_websocket_write_string(struct ast_websocket *ws, const char *buf)
Construct and transmit a WebSocket frame containing string data.
void AST_OPTIONAL_API_NAME() ast_websocket_reconstruct_enable(struct ast_websocket *session, size_t bytes)
Enable multi-frame reconstruction up to a certain number of bytes.
struct ast_sockaddr *AST_OPTIONAL_API_NAME() ast_websocket_local_address(struct ast_websocket *session)
Get the local address for a WebSocket connection session.
struct ast_websocket *AST_OPTIONAL_API_NAME() 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.
struct ast_sockaddr *AST_OPTIONAL_API_NAME() ast_websocket_remote_address(struct ast_websocket *session)
Get the remote address for a WebSocket connected session.
int AST_OPTIONAL_API_NAME() 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.
ast_websocket_result
Result code for a websocket client.
@ WS_BAD_REQUEST
@ WS_TLS_ERROR
@ WS_URL_NOT_FOUND
@ WS_CLIENT_START_ERROR
@ WS_KEY_ERROR
@ WS_NOT_SUPPORTED
@ WS_ALLOCATE_ERROR
@ WS_HEADER_MISMATCH
@ WS_WRITE_ERROR
@ WS_UNAUTHORIZED
@ WS_URI_RESOLVE_ERROR
@ WS_OK
@ WS_INVALID_RESPONSE
@ WS_BAD_STATUS
@ WS_URI_PARSE_ERROR
@ WS_HEADER_MISSING
int AST_OPTIONAL_API_NAME() ast_websocket_is_secure(struct ast_websocket *session)
Get whether the WebSocket session is using a secure transport or not.
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.
void AST_OPTIONAL_API_NAME() ast_websocket_reconstruct_disable(struct ast_websocket *session)
Disable multi-frame reconstruction.
struct ast_websocket *AST_OPTIONAL_API_NAME() 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.
int AST_OPTIONAL_API_NAME() ast_websocket_wait_for_input(struct ast_websocket *session, int timeout)
Wait for the WebSocket session to be ready to be read.
const char * ast_websocket_type_to_str(enum ast_websocket_type type)
int AST_OPTIONAL_API_NAME() ast_websocket_fd(struct ast_websocket *session)
Get the file descriptor for a WebSocket session.
ast_websocket_opcode
WebSocket operation codes.
@ AST_WEBSOCKET_OPCODE_PING
@ AST_WEBSOCKET_OPCODE_PONG
@ AST_WEBSOCKET_OPCODE_CONTINUATION
@ AST_WEBSOCKET_OPCODE_BINARY
@ AST_WEBSOCKET_OPCODE_UNKNOWN
@ AST_WEBSOCKET_OPCODE_CLOSE
@ AST_WEBSOCKET_OPCODE_TEXT
const char *AST_OPTIONAL_API_NAME() ast_websocket_client_accept_protocol(struct ast_websocket *ws)
Retrieve the server accepted sub-protocol on the client.
int AST_OPTIONAL_API_NAME() ast_websocket_set_nonblock(struct ast_websocket *session)
Set the socket of a WebSocket session to be non-blocking.
int AST_OPTIONAL_API_NAME() 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.
const char *AST_OPTIONAL_API_NAME() ast_websocket_status_to_str(enum ast_websocket_status_code code)
Convert a websocket status code to a string.
ast_websocket_type
WebSocket connection/configuration types.
@ AST_WS_TYPE_ANY
@ AST_WS_TYPE_CLIENT
@ AST_WS_TYPE_INBOUND
@ AST_WS_TYPE_CLIENT_PER_CALL_CONFIG
@ AST_WS_TYPE_SERVER
@ AST_WS_TYPE_CLIENT_PERSISTENT
@ AST_WS_TYPE_CLIENT_PER_CALL
int AST_OPTIONAL_API_NAME() 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.
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.
struct ast_websocket_protocol *AST_OPTIONAL_API_NAME() ast_websocket_sub_protocol_alloc(const char *name)
Allocate a websocket sub-protocol instance.
int AST_OPTIONAL_API_NAME() ast_websocket_set_timeout(struct ast_websocket *session, int timeout)
Set the timeout on a non-blocking WebSocket session.
int AST_OPTIONAL_API_NAME() 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_OPTIONAL_API_NAME() 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.
struct ast_websocket_server *AST_OPTIONAL_API_NAME() ast_websocket_server_create(void)
Creates a ast_websocket_server.
int AST_OPTIONAL_API_NAME() ast_websocket_remove_protocol(const char *name, ast_websocket_callback callback)
Remove a sub-protocol handler from the default /ws server.
void AST_OPTIONAL_API_NAME() ast_websocket_unref(struct ast_websocket *session)
Decrease the reference count for a WebSocket session.
int AST_OPTIONAL_API_NAME() ast_websocket_read_string(struct ast_websocket *ws, char **buf)
Read a WebSocket frame containing string data.
int AST_OPTIONAL_API_NAME() ast_websocket_add_protocol2(struct ast_websocket_protocol *protocol)
Add a sub-protocol handler to the default /ws server.
const char *AST_OPTIONAL_API_NAME() ast_websocket_result_to_str(enum ast_websocket_result result)
Convert a websocket result code to a string.
int errno
Optional API function macros.
#define AST_OPTIONAL_API(result, name, proto, stub)
Declare an optional API function.
const char * method
Definition res_pjsip.c:1273
#define NULL
Definition resample.c:96
Definition of a URI handler.
Definition http.h:102
Socket address structure.
Definition netsock2.h:97
describes a server instance
Definition tcptls.h:151
Structure for variables, used for configurations and for channel variables.
Options used for a websocket client.
struct ast_tls_config * tls_cfg
A websocket protocol implementation.
ast_websocket_callback session_established
Callback called when a new session is established. Mandatory.
unsigned int version
Protocol version. Should be set to /ref AST_WEBSOCKET_PROTOCOL_VERSION.
char * name
Name of the protocol.
ast_websocket_pre_callback session_attempted
Callback called when a new session is attempted. Optional.
Structure for a WebSocket server.
Structure definition for session.
static struct test_options options