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