Asterisk - The Open Source Telephony Project GIT-master-5963e62
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 */
64 AST_WS_TYPE_ANY = (0xFFFFFFFF),
65};
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};
79
80#ifdef LOW_MEMORY
81/*! \brief Size of the pre-determined buffer for WebSocket frames */
82#define AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE 8192
83#else
84/*! \brief Size of the pre-determined buffer for WebSocket frames */
85#define AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE 65535
86#endif
87
88/*!
89 * \brief Opaque structure for WebSocket server.
90 * \since 12
91 */
93
94/*!
95 * \brief Opaque structure for WebSocket sessions.
96 */
97struct ast_websocket;
98
99/*!
100 * \brief Callback from the HTTP request attempting to establish a websocket connection
101 *
102 * This callback occurs when an HTTP request is made to establish a websocket connection.
103 * Implementers of \ref ast_websocket_protocol can use this to deny a request, or to
104 * set up application specific data before invocation of \ref ast_websocket_callback.
105 *
106 * \param ser The TCP/TLS session
107 * \param parameters Parameters extracted from the request URI
108 * \param headers Headers included in the request
109 * \param session_id The id of the current session.
110 *
111 * \retval 0 The session should be accepted
112 * \retval -1 The session should be rejected. Note that the caller must send an error
113 * response using \ref ast_http_error.
114 * \since 13.5.0
115 */
116typedef int (*ast_websocket_pre_callback)(struct ast_tcptls_session_instance *ser, struct ast_variable *parameters, struct ast_variable *headers, const char *session_id);
117
118/*!
119 * \brief Callback for when a new connection for a sub-protocol is established
120 *
121 * \param session A WebSocket session structure
122 * \param parameters Parameters extracted from the request URI
123 * \param headers Headers included in the request
124 *
125 * \note Once called the ownership of the session is transferred to the sub-protocol handler. It
126 * is responsible for closing and cleaning up.
127 *
128 */
129typedef void (*ast_websocket_callback)(struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers);
130
131/*!
132 * \brief A websocket protocol implementation
133 *
134 * Users of the Websocket API can register themselves as a websocket
135 * protocol. See \ref ast_websocket_add_protocol2 and \ref ast_websocket_server_add_protocol2.
136 * Simpler implementations may use only \ref ast_websocket_add_protocol and
137 * \ref ast_websocket_server_add_protocol.
138 *
139 * \since 13.5.0
140 */
142 /*! \brief Name of the protocol */
143 char *name;
144/*!
145 * \brief Protocol version. This prevents dynamically loadable modules from registering
146 * if this struct is changed.
147 */
148#define AST_WEBSOCKET_PROTOCOL_VERSION 1
149 /*! \brief Protocol version. Should be set to /ref AST_WEBSOCKET_PROTOCOL_VERSION */
150 unsigned int version;
151 /*! \brief Callback called when a new session is attempted. Optional. */
153 /*! \brief Callback called when a new session is established. Mandatory. */
155};
156
157/*!
158 * \brief Creates a \ref ast_websocket_server
159 *
160 * \return New \ref ast_websocket_server instance
161 * \retval NULL on error
162 * \since 12
163 */
165
166/*!
167 * \brief Callback suitable for use with a \ref ast_http_uri.
168 *
169 * Set the data field of the ast_http_uri to \ref ast_websocket_server.
170 * \since 12
171 */
172AST_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; });
173
174/*!
175 * \brief Allocate a websocket sub-protocol instance
176 *
177 * \return An instance of \ref ast_websocket_protocol on success
178 * \retval NULL on error
179 * \since 13.5.0
180 */
182
183/*!
184 * \brief Add a sub-protocol handler to the default /ws server
185 *
186 * \param name Name of the sub-protocol to register
187 * \param callback Callback called when a new connection requesting the sub-protocol is established
188 *
189 * \retval 0 success
190 * \retval -1 if sub-protocol handler could not be registered
191 */
193
194/*!
195 * \brief Add a sub-protocol handler to the default /ws server
196 *
197 * \param protocol The sub-protocol to register. Note that this must
198 * be allocated using /ref ast_websocket_sub_protocol_alloc.
199 *
200 * \note This method is reference stealing. It will steal the reference to \p protocol
201 * on success.
202 *
203 * \retval 0 success
204 * \retval -1 if sub-protocol handler could not be registered
205 * \since 13.5.0
206 */
207AST_OPTIONAL_API(int, ast_websocket_add_protocol2, (struct ast_websocket_protocol *protocol), {return -1;});
208
209/*!
210 * \brief Remove a sub-protocol handler from the default /ws server.
211 *
212 * \param name Name of the sub-protocol to unregister
213 * \param callback Session Established callback that was previously registered with the sub-protocol
214 *
215 * \retval 0 success
216 * \retval -1 if sub-protocol was not found or if callback did not match
217 */
219
220/*!
221 * \brief Add a sub-protocol handler to the given server.
222 *
223 * \param server The server to add the sub-protocol to
224 * \param name Name of the sub-protocol to register
225 * \param callback Callback called when a new connection requesting the sub-protocol is established
226 *
227 * \retval 0 success
228 * \retval -1 if sub-protocol handler could not be registered
229 * \since 12
230 */
232
233/*!
234 * \brief Add a sub-protocol handler to the given server.
235 *
236 * \param server The server to add the sub-protocol to.
237 * \param protocol The sub-protocol to register. Note that this must
238 * be allocated using /ref ast_websocket_sub_protocol_alloc.
239 *
240 * \note This method is reference stealing. It will steal the reference to \p protocol
241 * on success.
242 *
243 * \retval 0 success
244 * \retval -1 if sub-protocol handler could not be registered
245 * \since 13.5.0
246 */
247AST_OPTIONAL_API(int, ast_websocket_server_add_protocol2, (struct ast_websocket_server *server, struct ast_websocket_protocol *protocol), {return -1;});
248
249/*!
250 * \brief Remove a sub-protocol handler from the given server.
251 *
252 * \param server The server to unregister the sub-protocol from
253 * \param name Name of the sub-protocol to unregister
254 * \param callback Callback that was previously registered with the sub-protocol
255 *
256 * \retval 0 success
257 * \retval -1 if sub-protocol was not found or if callback did not match
258 * \since 12
259 */
261
262/*!
263 * \brief Read a WebSocket frame and handle it
264 *
265 * \param session Pointer to the WebSocket session
266 * \param payload Pointer to a char* which will be populated with a pointer to the payload if present
267 * \param payload_len Pointer to a uint64_t which will be populated with the length of the payload if present
268 * \param opcode Pointer to an enum which will be populated with the opcode of the frame
269 * \param fragmented Pointer to an int which is set to 1 if payload is fragmented and 0 if not
270 *
271 * \retval -1 on error
272 * \retval 0 on success
273 *
274 * \note Once an AST_WEBSOCKET_OPCODE_CLOSE opcode is received the socket will be closed
275 */
276AST_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;});
277
278/*!
279 * \brief Read a WebSocket frame containing string data.
280 *
281 * \note The caller is responsible for freeing the output "buf".
282 *
283 * \param ws pointer to the websocket
284 * \param buf string buffer to populate with data read from socket
285 * \retval -1 on error
286 * \return number of bytes read on success
287 *
288 * \note Once an AST_WEBSOCKET_OPCODE_CLOSE opcode is received the socket will be closed
289 */
291 (struct ast_websocket *ws, char **buf),
292 { errno = ENOSYS; return -1;});
293
294/*!
295 * \brief Construct and transmit a WebSocket frame
296 *
297 * \param session Pointer to the WebSocket session
298 * \param opcode WebSocket operation code to place in the frame
299 * \param payload Optional pointer to a payload to add to the frame
300 * \param payload_size Length of the payload (0 if no payload)
301 *
302 * \retval 0 if successfully written
303 * \retval -1 if error occurred
304 */
305AST_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;});
306
307/*!
308 * \brief Construct and transmit a WebSocket frame containing string data.
309 *
310 * \param ws pointer to the websocket
311 * \param buf string data to write to socket
312 * \retval 0 if successfully written
313 * \retval -1 if error occurred
314 */
316 (struct ast_websocket *ws, const char *buf),
317 { errno = ENOSYS; return -1;});
318/*!
319 * \brief Close a WebSocket session by sending a message with the CLOSE opcode and an optional code
320 *
321 * \param session Pointer to the WebSocket session
322 * \param reason Reason code for closing the session as defined in the RFC
323 *
324 * \retval 0 if successfully written
325 * \retval -1 if error occurred
326 */
327AST_OPTIONAL_API(int, ast_websocket_close, (struct ast_websocket *session, uint16_t reason), { errno = ENOSYS; return -1;});
328
329/*!
330 * \brief Enable multi-frame reconstruction up to a certain number of bytes
331 *
332 * \param session Pointer to the WebSocket session
333 * \param bytes If a reconstructed payload exceeds the specified number of bytes the payload will be returned
334 * and upon reception of the next multi-frame a new reconstructed payload will begin.
335 */
336AST_OPTIONAL_API(void, ast_websocket_reconstruct_enable, (struct ast_websocket *session, size_t bytes), {return;});
337
338/*!
339 * \brief Disable multi-frame reconstruction
340 *
341 * \param session Pointer to the WebSocket session
342 *
343 * \note If reconstruction is disabled each message that is part of a multi-frame message will be sent up to
344 * the user when ast_websocket_read is called.
345 */
347
348/*!
349 * \brief Increase the reference count for a WebSocket session
350 *
351 * \param session Pointer to the WebSocket session
352 */
353AST_OPTIONAL_API(void, ast_websocket_ref, (struct ast_websocket *session), {return;});
354
355/*!
356 * \brief Decrease the reference count for a WebSocket session
357 *
358 * \param session Pointer to the WebSocket session
359 */
360AST_OPTIONAL_API(void, ast_websocket_unref, (struct ast_websocket *session), {return;});
361
362/*!
363 * \brief Get the file descriptor for a WebSocket session.
364 *
365 * \return file descriptor
366 *
367 * \note You must *not* directly read from or write to this file descriptor. It should only be used for polling.
368 */
369AST_OPTIONAL_API(int, ast_websocket_fd, (struct ast_websocket *session), { errno = ENOSYS; return -1;});
370
371/*!
372 * \brief Wait for the WebSocket session to be ready to be read.
373 * \since 16.8.0
374 * \since 17.2.0
375 *
376 * \param session Pointer to the WebSocket session
377 * \param timeout the number of milliseconds to wait
378 *
379 * \retval -1 if error occurred
380 * \retval 0 if the timeout expired
381 * \retval 1 if the WebSocket session is ready for reading
382 */
383AST_OPTIONAL_API(int, ast_websocket_wait_for_input, (struct ast_websocket *session, int timeout), { errno = ENOSYS; return -1; });
384
385/*!
386 * \brief Get the remote address for a WebSocket connected session.
387 *
388 * \return Remote address
389 */
391
392/*!
393 * \brief Get the local address for a WebSocket connection session.
394 *
395 * \return Local address
396 *
397 * \since 13.19.0
398 */
400
401/*!
402 * \brief Get whether the WebSocket session is using a secure transport or not.
403 *
404 * \retval 0 if unsecure
405 * \retval 1 if secure
406 */
407AST_OPTIONAL_API(int, ast_websocket_is_secure, (struct ast_websocket *session), { errno = ENOSYS; return -1;});
408
409/*!
410 * \brief Set the socket of a WebSocket session to be non-blocking.
411 *
412 * \retval 0 on success
413 * \retval -1 on failure
414 */
415AST_OPTIONAL_API(int, ast_websocket_set_nonblock, (struct ast_websocket *session), { errno = ENOSYS; return -1;});
416
417/*!
418 * \brief Get the session ID for a WebSocket session.
419 *
420 * \return session id
421 */
422AST_OPTIONAL_API(const char *, ast_websocket_session_id, (struct ast_websocket *session), { errno = ENOSYS; return NULL;});
423
424/*!
425 * \brief Result code for a websocket client.
426 */
428 WS_OK = 0,
443};
444
445/*!
446 * \brief Create, and connect, a websocket client.
447 *
448 * If the client websocket successfully connects, then the accepted protocol can be
449 * checked via a call to ast_websocket_client_accept_protocol.
450 *
451 * \note While connecting this *will* block until a response is
452 * received from the remote host.
453 * \note Expected uri form:
454 * \verbatim ws[s]://<address>[:port][/<path>] \endverbatim
455 * The address (can be a host name) and port are parsed out and used to connect
456 * to the remote server. If multiple IPs are returned during address
457 * resolution then the first one is chosen.
458 *
459 * \param uri uri to connect to
460 * \param protocols a comma separated string of supported protocols
461 * \param tls_cfg secure websocket credentials
462 * \param result result code set on client failure
463 * \return a client websocket.
464 * \retval NULL if object could not be created or connected
465 * \since 13
466 */
468 (const char *uri, const char *protocols,
469 struct ast_tls_config *tls_cfg,
470 enum ast_websocket_result *result), { return NULL;});
471
472/*!
473 * \brief Options used for a websocket client
474 */
476 /*!
477 * The URI to connect to
478 *
479 * Expected uri form:
480 * \verbatim ws[s]://<address>[:port][/<path>] \endverbatim
481 * The address (can be a host name) and port are parsed out and used to connect
482 * to the remote server. If multiple IPs are returned during address
483 * resolution then the first one is chosen.
484 */
485 const char *uri;
486 /*!
487 * A comma separated string of supported protocols
488 */
489 const char *protocols;
490 /*!
491 * Optional connection timeout
492 *
493 * How long (in milliseconds) to attempt to connect (-1 equals infinite)
494 */
496 /*!
497 * Secure websocket credentials
498 */
500 const char *username; /*!< Auth username */
501 const char *password; /*!< Auth password */
502 int suppress_connection_msgs; /*!< Suppress connection log messages */
503};
504
505/*!
506 * \brief Create, and connect, a websocket client using given options.
507 *
508 * If the client websocket successfully connects, then the accepted protocol can be
509 * checked via a call to ast_websocket_client_accept_protocol.
510 *
511 * \note While connecting this *will* block until a response is received
512 * from the remote host, or the connection timeout is reached
513 *
514 * \param options Websocket client options
515 * \param result result code set on client failure
516 *
517 * \return a client websocket.
518 * \retval NULL if object could not be created or connected
519 */
522 enum ast_websocket_result *result), { return NULL;});
523
524/*!
525 * \brief Retrieve the server accepted sub-protocol on the client.
526 *
527 * \param ws the websocket client
528 * \return the accepted client sub-protocol.
529 * \since 13
530 */
532 (struct ast_websocket *ws), { return NULL;});
533
534/*!
535 * \brief Set the timeout on a non-blocking WebSocket session.
536 *
537 * \since 11.11.0
538 * \since 12.4.0
539 *
540 * \retval 0 on success
541 * \retval -1 on failure
542 */
543AST_OPTIONAL_API(int, ast_websocket_set_timeout, (struct ast_websocket *session, int timeout), {return -1;});
544
545/*!
546 * \brief Convert a websocket result code to a string.
547 *
548 * \param result The result code to convert
549 *
550 * \return A string representation of the result code
551 */
553
554#endif
static struct ast_mansession session
static PGresult * result
Definition: cel_pgsql.c:84
static const char type[]
Definition: chan_ooh323.c:109
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
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
struct ast_websocket_protocol * ast_websocket_sub_protocol_alloc(const char *name)
Allocate a websocket sub-protocol instance.
int ast_websocket_read_string(struct ast_websocket *ws, char **buf)
Read a WebSocket frame containing string data.
int ast_websocket_is_secure(struct ast_websocket *session)
Get whether the WebSocket session is using a secure transport or not.
void ast_websocket_reconstruct_disable(struct ast_websocket *session)
Disable multi-frame reconstruction.
int ast_websocket_remove_protocol(const char *name, ast_websocket_callback callback)
Remove a sub-protocol handler from the default /ws server.
int ast_websocket_set_timeout(struct ast_websocket *session, int timeout)
Set the timeout on a non-blocking WebSocket session.
int 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.
int ast_websocket_set_nonblock(struct ast_websocket *session)
Set the socket of a WebSocket session to be non-blocking.
const char * ast_websocket_session_id(struct ast_websocket *session)
Get the session ID for a WebSocket session.
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.
struct ast_sockaddr * ast_websocket_remote_address(struct ast_websocket *session)
Get the remote address for a WebSocket connected session.
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.
int 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.
int 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.
const char * ast_websocket_result_to_str(enum ast_websocket_result result)
Convert a websocket result code to a string.
ast_websocket_result
Result code for a websocket client.
@ WS_BAD_REQUEST
@ 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_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.
struct ast_sockaddr * ast_websocket_local_address(struct ast_websocket *session)
Get the local address for a WebSocket connection session.
struct ast_websocket * 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.
void ast_websocket_ref(struct ast_websocket *session)
Increase the reference count for a WebSocket session.
const char * ast_websocket_type_to_str(enum ast_websocket_type type)
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_CLOSE
@ AST_WEBSOCKET_OPCODE_TEXT
int ast_websocket_add_protocol2(struct ast_websocket_protocol *protocol)
Add a sub-protocol handler to the default /ws server.
void ast_websocket_unref(struct ast_websocket *session)
Decrease the reference count for a WebSocket session.
void ast_websocket_reconstruct_enable(struct ast_websocket *session, size_t bytes)
Enable multi-frame reconstruction up to a certain number of bytes.
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)
Callback suitable for use with a ast_http_uri.
int ast_websocket_server_add_protocol2(struct ast_websocket_server *server, struct ast_websocket_protocol *protocol)
Add a sub-protocol handler to the given server.
const char * ast_websocket_client_accept_protocol(struct ast_websocket *ws)
Retrieve the server accepted sub-protocol on the client.
int ast_websocket_write_string(struct ast_websocket *ws, const char *buf)
Construct and transmit a WebSocket frame containing string data.
int ast_websocket_fd(struct ast_websocket *session)
Get the file descriptor for a WebSocket session.
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
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_server * ast_websocket_server_create(void)
Creates a ast_websocket_server.
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.
int ast_websocket_add_protocol(const char *name, ast_websocket_callback callback)
Add a sub-protocol handler to the default /ws server.
int errno
Optional API function macros.
#define AST_OPTIONAL_API(result, name, proto, stub)
Declare an optional API function.
Definition: optional_api.h:230
const char * method
Definition: res_pjsip.c:1279
#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