Asterisk - The Open Source Telephony Project GIT-master-6144b6b
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 */
69};
70
71/*
72 * The first 29 fields are reserved for the websocket client core.
73 */
74#define AST_WS_CLIENT_FIELD_USER_START 30
75
79 AST_STRING_FIELD(uri); /*!< Server URI */
80 AST_STRING_FIELD(protocols); /*!< Websocket protocols to use with server */
81 AST_STRING_FIELD(username); /*!< Auth user name */
82 AST_STRING_FIELD(password); /*!< Auth password */
83 AST_STRING_FIELD(ca_list_file); /*!< CA file */
84 AST_STRING_FIELD(ca_list_path); /*!< CA path */
85 AST_STRING_FIELD(cert_file); /*!< Certificate file */
86 AST_STRING_FIELD(priv_key_file); /*!< Private key file */
87 );
88 int invalid; /*!< Invalid configuration */
89 enum ast_ws_client_fields invalid_fields; /*!< Invalid fields */
90 enum ast_websocket_type connection_type; /*!< Connection type */
91 int connect_timeout; /*!< Connection timeout (ms) */
92 unsigned int reconnect_attempts; /*!< How many attempts before returning an error */
93 unsigned int reconnect_interval; /*!< How often to attempt a reconnect (ms) */
94 int tls_enabled; /*!< TLS enabled */
95 int verify_server_cert; /*!< Verify server certificate */
96 int verify_server_hostname; /*!< Verify server hostname */
97 AST_STRING_FIELD_EXTENDED(uri_params); /*!< Additional URI parameters */
98 AST_STRING_FIELD_EXTENDED(proxy_host); /*!< Proxy server URI */
99 AST_STRING_FIELD_EXTENDED(proxy_username); /*!< Proxy username */
100 AST_STRING_FIELD_EXTENDED(proxy_password); /*!< Proxy password */
101 int tcp_keepalives; /*!< Enable TCP Keepalives */
102 unsigned int tcp_keepalive_time; /*!< Start sending when connection has been idle for this many seconds */
103 unsigned int tcp_keepalive_interval; /*!< Send keepalives at this interval in seconds */
104 unsigned int tcp_keepalive_probes; /*!< Close connection after this many missed responses */
105 int pingpongs; /*!< Enable WebSocket PING/PONGs */
106 unsigned int pingpong_interval; /*!< Send WebSocket PINGs at this interval in seconds */
107 unsigned int pingpong_probes; /*!< Close connection after this many missed PONG responses */
108};
109
110/*!
111 * \brief Retrieve a container of all websocket client objects.
112 *
113 * \return The container. It may be empty but must always be cleaned up by the caller.
114 */
116
117/*!
118 * \brief Retrieve a websocket client object by ID.
119 *
120 * \param id The ID of the websocket client object.
121 * \return The websocket client ao2 object or NULL if not found. The reference
122 * must be cleaned up by the caller.
123 */
125
126/*!
127 * \brief Detect changes between two websocket client configurations.
128 *
129 * \param old_ow The old websocket configuration.
130 * \param new_ow The new websocket configuration.
131 * \return A bitmask of changed fields.
132 */
134 struct ast_websocket_client *old_wc,
135 struct ast_websocket_client *new_wc);
136
137/*!
138 * \brief Add sorcery observers for websocket client events.
139 *
140 * \param callbacks The observer callbacks to add.
141 * \return 0 on success, -1 on failure.
142 */
144 const struct ast_sorcery_observer *callbacks);
145
146/*!
147 * \brief Remove sorcery observers for websocket client events.
148 *
149 * \param callbacks The observer callbacks to remove.
150 */
152 const struct ast_sorcery_observer *callbacks);
153
154/*!
155 * \brief Connect to a websocket server using the configured authentication,
156 * retry and TLS options.
157 *
158 * \param wc A pointer to the ast_websocket_structure
159 * \param lock_obj A pointer to an ao2 object to lock while the
160 * connection is being attempted or NULL if no locking is needed.
161 * \param display_name An id string to use for logging messages.
162 * If NULL or empty the connection's ID will be used.
163 * \param result A pointer to an enum ast_websocket_result to store the
164 * result of the connection attempt.
165 *
166 * \return A pointer to the ast_websocket structure on success, or NULL on failure.
167 *
168 * \warning The returned websocket must be closed with \ref ast_websocket_close
169 * and its reference count decremented with \ref ast_websocket_unref when
170 * it's no longer needed.
171 */
173 void *lock_obj, const char *display_name, enum ast_websocket_result *result);
174
175/*!
176 * \brief Add additional parameters to the URI.
177 *
178 * \param wc A pointer to the ast_websocket_structure
179 * \param uri_params A string containing URLENCODED parameters to append to the URI.
180 */
182 const char *uri_params);
183
184/*!
185 * \brief Force res_websocket_client to reload its configuration.
186 * \return 0 on success, -1 on failure.
187 */
189
190#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 @509 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_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.