Asterisk - The Open Source Telephony Project GIT-master-545c459
Loading...
Searching...
No Matches
websocket_client.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2025, Sangoma Technologies Corporation
5 *
6 * George Joseph <gjoseph@sangoma.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 _RES_WEBSOCKET_CLIENT_H
20#define _RES_WEBSOCKET_CLIENT_H
21
23#include "asterisk/sorcery.h"
24
25/*
26 * Using 1ULL is important as it forces the enum to be 64 bits.
27 */
70};
71
72/*
73 * The first 29 fields are reserved for the websocket client core.
74 */
75#define AST_WS_CLIENT_FIELD_USER_START 30
76
80 AST_STRING_FIELD(uri); /*!< Server URI */
81 AST_STRING_FIELD(protocols); /*!< Websocket protocols to use with server */
82 AST_STRING_FIELD(username); /*!< Auth user name */
83 AST_STRING_FIELD(password); /*!< Auth password */
84 AST_STRING_FIELD(ca_list_file); /*!< CA file */
85 AST_STRING_FIELD(ca_list_path); /*!< CA path */
86 AST_STRING_FIELD(cert_file); /*!< Certificate file */
87 AST_STRING_FIELD(priv_key_file); /*!< Private key file */
88 );
89 int invalid; /*!< Invalid configuration */
90 enum ast_ws_client_fields invalid_fields; /*!< Invalid fields */
91 enum ast_websocket_type connection_type; /*!< Connection type */
92 int connect_timeout; /*!< Connection timeout (ms) */
93 unsigned int reconnect_attempts; /*!< How many attempts before returning an error */
94 unsigned int reconnect_interval; /*!< How often to attempt a reconnect (ms) */
95 int tls_enabled; /*!< TLS enabled */
96 int verify_server_cert; /*!< Verify server certificate */
97 int verify_server_hostname; /*!< Verify server hostname */
98 AST_STRING_FIELD_EXTENDED(uri_params); /*!< Additional URI parameters */
99 AST_STRING_FIELD_EXTENDED(proxy_host); /*!< Proxy server URI */
100 AST_STRING_FIELD_EXTENDED(proxy_username); /*!< Proxy username */
101 AST_STRING_FIELD_EXTENDED(proxy_password); /*!< Proxy password */
102 int tcp_keepalives; /*!< Enable TCP Keepalives */
103 unsigned int tcp_keepalive_time; /*!< Start sending when connection has been idle for this many seconds */
104 unsigned int tcp_keepalive_interval; /*!< Send keepalives at this interval in seconds */
105 unsigned int tcp_keepalive_probes; /*!< Close connection after this many missed responses */
106 int pingpongs; /*!< Enable WebSocket PING/PONGs */
107 unsigned int pingpong_interval; /*!< Send WebSocket PINGs at this interval in seconds */
108 unsigned int pingpong_probes; /*!< Close connection after this many missed PONG responses */
109 int write_timeout; /*!< Write timeout (ms) */
110};
111
112/*!
113 * \brief Retrieve a container of all websocket client objects.
114 *
115 * \return The container. It may be empty but must always be cleaned up by the caller.
116 */
118
119/*!
120 * \brief Retrieve a websocket client object by ID.
121 *
122 * \param id The ID of the websocket client object.
123 * \return The websocket client ao2 object or NULL if not found. The reference
124 * must be cleaned up by the caller.
125 */
127
128/*!
129 * \brief Detect changes between two websocket client configurations.
130 *
131 * \param old_ow The old websocket configuration.
132 * \param new_ow The new websocket configuration.
133 * \return A bitmask of changed fields.
134 */
136 struct ast_websocket_client *old_wc,
137 struct ast_websocket_client *new_wc);
138
139/*!
140 * \brief Add sorcery observers for websocket client events.
141 *
142 * \param callbacks The observer callbacks to add.
143 * \return 0 on success, -1 on failure.
144 */
146 const struct ast_sorcery_observer *callbacks);
147
148/*!
149 * \brief Remove sorcery observers for websocket client events.
150 *
151 * \param callbacks The observer callbacks to remove.
152 */
154 const struct ast_sorcery_observer *callbacks);
155
156/*!
157 * \brief Connect to a websocket server using the configured authentication,
158 * retry and TLS options.
159 *
160 * \param wc A pointer to the ast_websocket_structure
161 * \param lock_obj A pointer to an ao2 object to lock while the
162 * connection is being attempted or NULL if no locking is needed.
163 * \param display_name An id string to use for logging messages.
164 * If NULL or empty the connection's ID will be used.
165 * \param result A pointer to an enum ast_websocket_result to store the
166 * result of the connection attempt.
167 *
168 * \return A pointer to the ast_websocket structure on success, or NULL on failure.
169 *
170 * \warning The returned websocket must be closed with \ref ast_websocket_close
171 * and its reference count decremented with \ref ast_websocket_unref when
172 * it's no longer needed.
173 */
175 void *lock_obj, const char *display_name, enum ast_websocket_result *result);
176
177/*!
178 * \brief Add additional parameters to the URI.
179 *
180 * \param wc A pointer to the ast_websocket_structure
181 * \param uri_params A string containing URLENCODED parameters to append to the URI.
182 */
184 const char *uri_params);
185
186/*!
187 * \brief Force res_websocket_client to reload its configuration.
188 * \return 0 on success, -1 on failure.
189 */
191
192#endif /* _RES_WEBSOCKET_CLIENT_H */
static PGresult * result
Definition cel_pgsql.c:84
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
ast_websocket_result
Result code for a websocket client.
ast_websocket_type
WebSocket connection/configuration types.
struct @510 callbacks
Sorcery Data Access Layer API.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
Generic container type.
Interface for a sorcery object type observer.
Definition sorcery.h:332
unsigned int pingpong_interval
unsigned int reconnect_interval
const ast_string_field uri
AST_STRING_FIELD_EXTENDED(proxy_host)
enum ast_websocket_type connection_type
const ast_string_field ca_list_path
const ast_string_field cert_file
const ast_string_field password
const ast_string_field username
const ast_string_field ca_list_file
AST_STRING_FIELD_EXTENDED(proxy_password)
unsigned int tcp_keepalive_time
const ast_string_field protocols
AST_STRING_FIELD_EXTENDED(proxy_username)
unsigned int tcp_keepalive_interval
unsigned int tcp_keepalive_probes
const ast_string_field priv_key_file
enum ast_ws_client_fields invalid_fields
unsigned int reconnect_attempts
AST_STRING_FIELD_EXTENDED(uri_params)
Structure definition for session.
void ast_websocket_client_add_uri_params(struct ast_websocket_client *wc, const char *uri_params)
Add additional parameters to the URI.
struct ao2_container * ast_websocket_client_retrieve_all(void)
Retrieve a container of all websocket client objects.
int ast_websocket_client_reload(void)
Force res_websocket_client to reload its configuration.
ast_ws_client_fields
@ AST_WS_CLIENT_FIELD_RECONNECT_INTERVAL
@ AST_WS_CLIENT_FIELD_NONE
@ AST_WS_CLIENT_FIELD_URI
@ AST_WS_CLIENT_FIELD_PROTOCOLS
@ AST_WS_CLIENT_NEEDS_RECONNECT
@ AST_WS_CLIENT_FIELD_TCP_KEEPALIVES
@ AST_WS_CLIENT_FIELD_CA_LIST_PATH
@ AST_WS_CLIENT_FIELD_TLS_ENABLED
@ AST_WS_CLIENT_FIELD_PROXY_PASSWORD
@ AST_WS_CLIENT_FIELD_TCP_KEEPALIVE_TIME
@ AST_WS_CLIENT_FIELD_CA_LIST_FILE
@ AST_WS_CLIENT_FIELD_PINGPONG_PROBES
@ AST_WS_CLIENT_FIELD_USERNAME
@ AST_WS_CLIENT_FIELD_VERIFY_SERVER_CERT
@ AST_WS_CLIENT_FIELD_PASSWORD
@ AST_WS_CLIENT_FIELD_PROXY_USERNAME
@ AST_WS_CLIENT_FIELD_CONNECTION_TIMEOUT
@ AST_WS_CLIENT_FIELD_PINGPONG_INTERVAL
@ AST_WS_CLIENT_FIELD_RECONNECT_ATTEMPTS
@ AST_WS_CLIENT_FIELD_WRITE_TIMEOUT
@ AST_WS_CLIENT_FIELD_CONNECTION_TYPE
@ AST_WS_CLIENT_FIELD_TCP_KEEPALIVE_PROBES
@ AST_WS_CLIENT_FIELD_VERIFY_SERVER_HOSTNAME
@ AST_WS_CLIENT_FIELD_PINGPONGS
@ AST_WS_CLIENT_FIELD_TCP_KEEPALIVE_INTERVAL
@ AST_WS_CLIENT_FIELD_CERT_FILE
@ AST_WS_CLIENT_FIELD_PRIV_KEY_FILE
@ AST_WS_CLIENT_FIELD_PROXY_HOST
enum ast_ws_client_fields ast_websocket_client_get_field_diff(struct ast_websocket_client *old_wc, struct ast_websocket_client *new_wc)
Detect changes between two websocket client configurations.
struct ast_websocket_client * ast_websocket_client_retrieve_by_id(const char *id)
Retrieve a websocket client object by ID.
void ast_websocket_client_observer_remove(const struct ast_sorcery_observer *callbacks)
Remove sorcery observers for websocket client events.
int ast_websocket_client_observer_add(const struct ast_sorcery_observer *callbacks)
Add sorcery observers for websocket client events.
struct ast_websocket * ast_websocket_client_connect(struct ast_websocket_client *wc, void *lock_obj, const char *display_name, enum ast_websocket_result *result)
Connect to a websocket server using the configured authentication, retry and TLS options.