Asterisk - The Open Source Telephony Project GIT-master-fe341c2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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
49};
50
51/*
52 * The first 23 fields are reserved for the websocket client core.
53 */
54#define AST_WS_CLIENT_FIELD_USER_START 24
55
59 AST_STRING_FIELD(uri); /*!< Server URI */
60 AST_STRING_FIELD(protocols); /*!< Websocket protocols to use with server */
61 AST_STRING_FIELD(username); /*!< Auth user name */
62 AST_STRING_FIELD(password); /*!< Auth password */
63 AST_STRING_FIELD(ca_list_file); /*!< CA file */
64 AST_STRING_FIELD(ca_list_path); /*!< CA path */
65 AST_STRING_FIELD(cert_file); /*!< Certificate file */
66 AST_STRING_FIELD(priv_key_file); /*!< Private key file */
67 );
68 int invalid; /*!< Invalid configuration */
69 enum ast_ws_client_fields invalid_fields; /*!< Invalid fields */
70 enum ast_websocket_type connection_type; /*!< Connection type */
71 int connect_timeout; /*!< Connection timeout (ms) */
72 unsigned int reconnect_attempts; /*!< How many attempts before returning an error */
73 unsigned int reconnect_interval; /*!< How often to attempt a reconnect (ms) */
74 int tls_enabled; /*!< TLS enabled */
75 int verify_server_cert; /*!< Verify server certificate */
76 int verify_server_hostname; /*!< Verify server hostname */
77};
78
79/*!
80 * \brief Retrieve a container of all websocket client objects.
81 *
82 * \return The container. It may be empty but must always be cleaned up by the caller.
83 */
85
86/*!
87 * \brief Retrieve a websocket client object by ID.
88 *
89 * \param id The ID of the websocket client object.
90 * \return The websocket client ao2 object or NULL if not found. The reference
91 * must be cleaned up by the caller.
92 */
94
95/*!
96 * \brief Detect changes between two websocket client configurations.
97 *
98 * \param old_ow The old websocket configuration.
99 * \param new_ow The new websocket configuration.
100 * \return A bitmask of changed fields.
101 */
103 struct ast_websocket_client *old_wc,
104 struct ast_websocket_client *new_wc);
105
106/*!
107 * \brief Add sorcery observers for websocket client events.
108 *
109 * \param callbacks The observer callbacks to add.
110 * \return 0 on success, -1 on failure.
111 */
113 const struct ast_sorcery_observer *callbacks);
114
115/*!
116 * \brief Remove sorcery observers for websocket client events.
117 *
118 * \param callbacks The observer callbacks to remove.
119 */
121 const struct ast_sorcery_observer *callbacks);
122
123/*!
124 * \brief Connect to a websocket server using the configured authentication,
125 * retry and TLS options.
126 *
127 * \param wc A pointer to the ast_websocket_structure
128 * \param lock_obj A pointer to an ao2 object to lock while the
129 * connection is being attempted or NULL if no locking is needed.
130 * \param display_name An id string to use for logging messages.
131 * If NULL or empty the connection's ID will be used.
132 * \param result A pointer to an enum ast_websocket_result to store the
133 * result of the connection attempt.
134 *
135 * \return A pointer to the ast_websocket structure on success, or NULL on failure.
136 */
138 void *lock_obj, const char *display_name, enum ast_websocket_result *result);
139
140/*!
141 * \brief Force res_websocket_client to reload its configuration.
142 * \return 0 on success, -1 on failure.
143 */
145
146#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 @471 callbacks
Sorcery Data Access Layer API.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definition: stringfields.h:341
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:303
Generic container type.
Interface for a sorcery object type observer.
Definition: sorcery.h:332
unsigned int reconnect_interval
const ast_string_field uri
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
const ast_string_field protocols
const ast_string_field priv_key_file
enum ast_ws_client_fields invalid_fields
unsigned int reconnect_attempts
Structure definition for session.
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_CA_LIST_PATH
@ AST_WS_CLIENT_FIELD_TLS_ENABLED
@ AST_WS_CLIENT_FIELD_CA_LIST_FILE
@ AST_WS_CLIENT_FIELD_USERNAME
@ AST_WS_CLIENT_FIELD_VERIFY_SERVER_CERT
@ AST_WS_CLIENT_FIELD_PASSWORD
@ AST_WS_CLIENT_FIELD_CONNECTION_TIMEOUT
@ AST_WS_CLIENT_FIELD_RECONNECT_ATTEMPTS
@ AST_WS_CLIENT_FIELD_CONNECTION_TYPE
@ AST_WS_CLIENT_FIELD_VERIFY_SERVER_HOSTNAME
@ AST_WS_CLIENT_FIELD_CERT_FILE
@ AST_WS_CLIENT_FIELD_PRIV_KEY_FILE
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.