module-raop-sink: Rename a bunch of things

This commit is contained in:
Christian Glombek 2023-07-30 00:41:15 +02:00
parent 1daae4c369
commit a9e3459c71

View file

@ -228,8 +228,8 @@ struct impl {
unsigned int do_disconnect:1; unsigned int do_disconnect:1;
uint8_t key[AES_CHUNK_SIZE]; /* Key for aes-cbc */ uint8_t aes_key[AES_CHUNK_SIZE]; /* Key for aes-cbc */
uint8_t iv[AES_CHUNK_SIZE]; /* Initialization vector for cbc */ uint8_t aes_iv[AES_CHUNK_SIZE]; /* Initialization vector for cbc */
EVP_CIPHER_CTX *ctx; EVP_CIPHER_CTX *ctx;
uint16_t control_port; uint16_t control_port;
@ -287,7 +287,7 @@ static inline void bit_writer(uint8_t **p, int *pos, uint8_t data, int len)
static int aes_encrypt(struct impl *impl, uint8_t *data, int len) static int aes_encrypt(struct impl *impl, uint8_t *data, int len)
{ {
int i = len & ~0xf, clen = i; int i = len & ~0xf, clen = i;
EVP_EncryptInit(impl->ctx, EVP_aes_128_cbc(), impl->key, impl->iv); EVP_EncryptInit(impl->ctx, EVP_aes_128_cbc(), impl->aes_key, impl->aes_iv);
EVP_EncryptUpdate(impl->ctx, data, &clen, data, i); EVP_EncryptUpdate(impl->ctx, data, &clen, data, i);
return i; return i;
} }
@ -783,7 +783,7 @@ static int MD5_hash(char hash[MD5_HASH_LENGTH+1], const char *fmt, ...)
return 0; return 0;
} }
static int rtsp_add_auth(struct impl *impl, const char *method) static int rtsp_add_raop_auth_header(struct impl *impl, const char *method)
{ {
char auth[1024]; char auth[1024];
@ -831,7 +831,7 @@ static int rtsp_send(struct impl *impl, const char *method,
{ {
int res; int res;
rtsp_add_auth(impl, method); rtsp_add_raop_auth_header(impl, method);
res = pw_rtsp_client_send(impl->rtsp, method, &impl->headers->dict, res = pw_rtsp_client_send(impl->rtsp, method, &impl->headers->dict,
content_type, content, reply, impl); content_type, content, reply, impl);
@ -1105,7 +1105,7 @@ error:
return -EIO; return -EIO;
} }
static int rtsp_announce_reply(void *data, int status, const struct spa_dict *headers, const struct pw_array *content) static int rtsp_raop_announce_reply(void *data, int status, const struct spa_dict *headers, const struct pw_array *content)
{ {
struct impl *impl = data; struct impl *impl = data;
@ -1205,12 +1205,12 @@ error:
goto done; goto done;
} }
static int rtsp_do_announce(struct impl *impl) static int rtsp_do_raop_announce(struct impl *impl)
{ {
const char *host; const char *host;
uint8_t rsakey[512]; uint8_t rsa_key[512];
char key[512*2]; char rsa_key_b64enc[512*2];
char iv[16*2]; char rsa_iv_b64enc[16*2];
int res, frames, rsa_len, ip_version; int res, frames, rsa_len, ip_version;
spa_autofree char *sdp = NULL; spa_autofree char *sdp = NULL;
char local_ip[256]; char local_ip[256];
@ -1241,7 +1241,6 @@ static int rtsp_do_announce(struct impl *impl)
if (!sdp) if (!sdp)
return -errno; return -errno;
break; break;
case CRYPTO_AUTH_SETUP: case CRYPTO_AUTH_SETUP:
sdp = spa_aprintf("v=0\r\n" sdp = spa_aprintf("v=0\r\n"
"o=iTunes %s 0 IN IP%d %s\r\n" "o=iTunes %s 0 IN IP%d %s\r\n"
@ -1260,16 +1259,16 @@ static int rtsp_do_announce(struct impl *impl)
break; break;
case CRYPTO_RSA: case CRYPTO_RSA:
if ((res = pw_getrandom(impl->key, sizeof(impl->key), 0)) < 0 || if ((res = pw_getrandom(impl->aes_key, sizeof(impl->aes_key), 0)) < 0 ||
(res = pw_getrandom(impl->iv, sizeof(impl->iv), 0)) < 0) (res = pw_getrandom(impl->aes_iv, sizeof(impl->aes_iv), 0)) < 0)
return res; return res;
rsa_len = rsa_encrypt(impl->key, 16, rsakey); rsa_len = rsa_encrypt(impl->aes_key, 16, rsa_key);
if (rsa_len < 0) if (rsa_len < 0)
return -rsa_len; return -rsa_len;
base64_encode(rsakey, rsa_len, key, '='); base64_encode(rsa_key, rsa_len, rsa_key_b64enc, '=');
base64_encode(impl->iv, 16, iv, '='); base64_encode(impl->aes_iv, 16, rsa_iv_b64enc, '=');
sdp = spa_aprintf("v=0\r\n" sdp = spa_aprintf("v=0\r\n"
"o=iTunes %s 0 IN IP%d %s\r\n" "o=iTunes %s 0 IN IP%d %s\r\n"
@ -1283,7 +1282,7 @@ static int rtsp_do_announce(struct impl *impl)
"a=aesiv:%s\r\n", "a=aesiv:%s\r\n",
impl->session_id, ip_version, local_ip, impl->session_id, ip_version, local_ip,
ip_version, host, frames, impl->info.rate, ip_version, host, frames, impl->info.rate,
key, iv); rsa_key_b64enc, rsa_iv_b64enc);
if (!sdp) if (!sdp)
return -errno; return -errno;
break; break;
@ -1291,19 +1290,19 @@ static int rtsp_do_announce(struct impl *impl)
return -ENOTSUP; return -ENOTSUP;
} }
return rtsp_send(impl, "ANNOUNCE", "application/sdp", sdp, rtsp_announce_reply); return rtsp_send(impl, "ANNOUNCE", "application/sdp", sdp, rtsp_raop_announce_reply);
} }
static int rtsp_auth_setup_reply(void *data, int status, const struct spa_dict *headers, const struct pw_array *content) static int rtsp_raop_auth_setup_reply(void *data, int status, const struct spa_dict *headers, const struct pw_array *content)
{ {
struct impl *impl = data; struct impl *impl = data;
pw_log_info("auth-setup status: %d", status); pw_log_info("auth-setup status: %d", status);
return rtsp_do_announce(impl); return rtsp_do_raop_announce(impl);
} }
static int rtsp_do_auth_setup(struct impl *impl) static int rtsp_do_raop_auth_setup(struct impl *impl)
{ {
static const unsigned char content[33] = static const unsigned char content[33] =
"\x01" "\x01"
@ -1312,22 +1311,22 @@ static int rtsp_do_auth_setup(struct impl *impl)
return pw_rtsp_client_url_send(impl->rtsp, "/auth-setup", "POST", &impl->headers->dict, return pw_rtsp_client_url_send(impl->rtsp, "/auth-setup", "POST", &impl->headers->dict,
"application/octet-stream", content, sizeof(content), "application/octet-stream", content, sizeof(content),
rtsp_auth_setup_reply, impl); rtsp_raop_auth_setup_reply, impl);
} }
static int rtsp_auth_reply(void *data, int status, const struct spa_dict *headers, const struct pw_array *content) static int rtsp_raop_auth_reply(void *data, int status, const struct spa_dict *headers, const struct pw_array *content)
{ {
struct impl *impl = data; struct impl *impl = data;
int res = 0; int res = 0;
pw_log_info("auth status: %d", status); pw_log_info("raop auth status: %d", status);
switch (status) { switch (status) {
case 200: case 200:
if (impl->encryption == CRYPTO_AUTH_SETUP) if (impl->encryption == CRYPTO_AUTH_SETUP)
res = rtsp_do_auth_setup(impl); res = rtsp_do_raop_auth_setup(impl);
else else
res = rtsp_do_announce(impl); res = rtsp_do_raop_announce(impl);
break; break;
} }
return res; return res;
@ -1351,7 +1350,7 @@ static const char *find_attr(char **tokens, const char *key)
return NULL; return NULL;
} }
static int rtsp_do_auth(struct impl *impl, const struct spa_dict *headers) static int rtsp_do_raop_auth(struct impl *impl, const struct spa_dict *headers)
{ {
const char *str, *realm, *nonce; const char *str, *realm, *nonce;
int n_tokens; int n_tokens;
@ -1382,10 +1381,10 @@ static int rtsp_do_auth(struct impl *impl, const struct spa_dict *headers)
impl->nonce = strdup(nonce); impl->nonce = strdup(nonce);
} }
return rtsp_send(impl, "OPTIONS", NULL, NULL, rtsp_auth_reply); return rtsp_send(impl, "OPTIONS", NULL, NULL, rtsp_raop_auth_reply);
} }
static int rtsp_options_reply(void *data, int status, const struct spa_dict *headers, const struct pw_array *content) static int rtsp_raop_options_reply(void *data, int status, const struct spa_dict *headers, const struct pw_array *content)
{ {
struct impl *impl = data; struct impl *impl = data;
int res = 0; int res = 0;
@ -1394,13 +1393,13 @@ static int rtsp_options_reply(void *data, int status, const struct spa_dict *hea
switch (status) { switch (status) {
case 401: case 401:
res = rtsp_do_auth(impl, headers); res = rtsp_do_raop_auth(impl, headers);
break; break;
case 200: case 200:
if (impl->encryption == CRYPTO_AUTH_SETUP) if (impl->encryption == CRYPTO_AUTH_SETUP)
res = rtsp_do_auth_setup(impl); res = rtsp_do_raop_auth_setup(impl);
else else
res = rtsp_do_announce(impl); res = rtsp_do_raop_announce(impl);
break; break;
} }
return res; return res;
@ -1433,7 +1432,7 @@ static void rtsp_connected(void *data)
pw_properties_set(impl->headers, "User-Agent", DEFAULT_USER_AGENT); pw_properties_set(impl->headers, "User-Agent", DEFAULT_USER_AGENT);
pw_rtsp_client_send(impl->rtsp, "OPTIONS", &impl->headers->dict, pw_rtsp_client_send(impl->rtsp, "OPTIONS", &impl->headers->dict,
NULL, NULL, rtsp_options_reply, impl); NULL, NULL, rtsp_raop_options_reply, impl);
} }
static void connection_cleanup(struct impl *impl) static void connection_cleanup(struct impl *impl)
@ -1530,7 +1529,7 @@ static int rtsp_do_connect(struct impl *impl)
if (impl->connected) { if (impl->connected) {
if (!impl->ready) if (!impl->ready)
return rtsp_do_announce(impl); return rtsp_do_raop_announce(impl);
return 0; return 0;
} }