Prequisites for ARI Outbound Websockets

stasis:
* Added stasis_app_is_registered().
* Added stasis_app_control_mark_failed().
* Added stasis_app_control_is_failed().
* Fixed res_stasis_device_state so unsubscribe all works properly.
* Modified stasis_app_unregister() to unsubscribe from all event sources.
* Modified stasis_app_exec to return -1 if stasis_app_control_is_failed()
  returns true.

http:
* Added ast_http_create_basic_auth_header().

md5:
* Added define for MD5_DIGEST_LENGTH.

tcptls:
* Added flag to ast_tcptls_session_args to suppress connection log messages
  to give callers more control over logging.

http_websocket:
* Add flag to ast_websocket_client_options to suppress connection log messages
  to give callers more control over logging.
* Added username and password to ast_websocket_client_options to support
  outbound basic authentication.
* Added ast_websocket_result_to_str().

(cherry picked from commit cc92adc5fb)
This commit is contained in:
George Joseph
2025-04-16 13:40:52 -06:00
committed by Asterisk Development Team
parent 26d6a3da6a
commit a6dca5bf3a
12 changed files with 285 additions and 41 deletions

View File

@@ -1667,6 +1667,50 @@ struct ast_http_auth *ast_http_get_auth(struct ast_variable *headers)
return NULL;
}
struct ast_variable *ast_http_create_basic_auth_header(const char *userid,
const char *password)
{
int encoded_size = 0;
int userinfo_len = 0;
RAII_VAR(char *, userinfo, NULL, ast_free);
char *encoded_userinfo = NULL;
struct ast_variable *auth_header = NULL;
if (ast_strlen_zero(userid)) {
return NULL;
}
if (strchr(userid, ':')) {
userinfo = ast_strdup(userid);
userinfo_len = strlen(userinfo);
} else {
if (ast_strlen_zero(password)) {
return NULL;
}
userinfo_len = ast_asprintf(&userinfo, "%s:%s", userid, password);
}
if (!userinfo) {
return NULL;
}
/*
* The header value is "Basic " + base64(userinfo).
* Doubling the userinfo length then adding the length
* of the "Basic " prefix is a conservative estimate of the
* final encoded size.
*/
encoded_size = userinfo_len * 2 * sizeof(char) + 1 + BASIC_LEN;
encoded_userinfo = ast_alloca(encoded_size);
strcpy(encoded_userinfo, BASIC_PREFIX); /* Safe */
ast_base64encode(encoded_userinfo + BASIC_LEN, (unsigned char *)userinfo,
userinfo_len, encoded_size - BASIC_LEN);
auth_header = ast_variable_new("Authorization",
encoded_userinfo, "");
return auth_header;
}
int ast_http_response_status_line(const char *buf, const char *version, int code)
{
int status_code;