chan_websocket: Allow additional URI parameters to be added to the outgoing URI.

* Added a new option to the WebSocket dial string to capture the additional
  URI parameters.
* Added a new API ast_uri_verify_encoded() that verifies that a string
  either doesn't need URI encoding or that it has already been encoded.
* Added a new API ast_websocket_client_add_uri_params() to add the params
  to the client websocket session.
* Added XML documentation that will show up with `core show application Dial`
  that shows how to use it.

Resolves: #1352

UserNote: A new WebSocket channel driver option `v` has been added to the
Dial application that allows you to specify additional URI parameters on
outgoing connections. Run `core show application Dial` from the Asterisk CLI
to see how to use it.
This commit is contained in:
George Joseph
2025-08-13 13:22:38 -06:00
parent 076423aa18
commit de6aaa9623
5 changed files with 214 additions and 2 deletions

View File

@@ -414,6 +414,19 @@ char *ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_fl
*/
void ast_uri_decode(char *s, struct ast_flags spec);
/*!
* \brief Verify if a string is valid as a URI component
*
* This function checks if the string either doesn't need encoding
* or is already properly URI encoded.
* Valid characters are 'a-zA-Z0-9.+_-' and '%xx' escape sequences.
*
* \param string String to be checked
* \retval 1 if the string is valid
* \retval 0 if the string is not valid
*/
int ast_uri_verify_encoded(const char *string);
/*! ast_xml_escape
\brief Escape reserved characters for use in XML.

View File

@@ -74,6 +74,7 @@ struct ast_websocket_client {
int tls_enabled; /*!< TLS enabled */
int verify_server_cert; /*!< Verify server certificate */
int verify_server_hostname; /*!< Verify server hostname */
AST_STRING_FIELD_EXTENDED(uri_params); /*!< Additional URI parameters */
};
/*!
@@ -137,6 +138,15 @@ void ast_websocket_client_observer_remove(
struct ast_websocket *ast_websocket_client_connect(struct ast_websocket_client *wc,
void *lock_obj, const char *display_name, enum ast_websocket_result *result);
/*!
* \brief Add additional parameters to the URI.
*
* \param wc A pointer to the ast_websocket_structure
* \param uri_params A string containing URLENCODED parameters to append to the URI.
*/
void ast_websocket_client_add_uri_params(struct ast_websocket_client *wc,
const char *uri_params);
/*!
* \brief Force res_websocket_client to reload its configuration.
* \return 0 on success, -1 on failure.