res_websocket_client: Create common utilities for websocket clients.

Since multiple Asterisk capabilities now need to create websocket clients
it makes sense to create a common set of utilities rather than making
each of those capabilities implement their own.

* A new configuration file "websocket_client.conf" is used to store common
client parameters in named configuration sections.
* APIs are provided to list and retrieve ast_websocket_client objects created
from the named configurations.
* An API is provided that accepts an ast_websocket_client object, connects
to the remote server with retries and returns an ast_websocket object. TLS is
supported as is basic authentication.
* An observer can be registered to receive notification of loaded or reloaded
client objects.
* An API is provided to compare an existing client object to one just
reloaded and return the fields that were changed. The caller can then decide
what action to take based on which fields changed.

Also as part of thie commit, several sorcery convenience macros were created
to make registering common object fields easier.

UserNote: A new module "res_websocket_client" and config file
"websocket_client.conf" have been added to support several upcoming new
capabilities that need common websocket client configuration.

(cherry picked from commit 36fc358bc9)
This commit is contained in:
George Joseph
2025-05-02 08:52:54 -06:00
parent 62547b25e1
commit 1aea2d50ae
7 changed files with 944 additions and 0 deletions

View File

@@ -103,6 +103,28 @@ struct ast_websocket {
char buf[MAXIMUM_FRAME_SIZE]; /*!< Fixed buffer for reading data into */
};
const char *ast_websocket_type_to_str(enum ast_websocket_type type)
{
switch (type) {
case AST_WS_TYPE_CLIENT_PERSISTENT:
return "persistent";
case AST_WS_TYPE_CLIENT_PER_CALL:
return "per_call";
case AST_WS_TYPE_CLIENT_PER_CALL_CONFIG:
return "per_call_config";
case AST_WS_TYPE_CLIENT:
return "client";
case AST_WS_TYPE_INBOUND:
return "inbound";
case AST_WS_TYPE_SERVER:
return "server";
case AST_WS_TYPE_ANY:
return "any";
default:
return "unknown";
}
}
/*! \brief Hashing function for protocols */
static int protocol_hash_fn(const void *obj, const int flags)
{