From 2d7eb8678b407dfacdc21d788f9f235837471125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 8 Sep 2022 15:33:32 +0200 Subject: [PATCH] pipewire: rtsp-client: allow sending arbitrary binary data Previously, the content had to be a null-terminated byte sequence because the sending function used `strlen()` to determine its length. However, `rtsp_do_auth_setup()` needs to send a non-textual byte sequence, and it only worked so far because it did not happen to have any zero bytes in it. Add a "content_length" parameter and change the type of "content" to facilitate sending arbitrary byte sequences. --- src/modules/module-raop-sink.c | 5 +++-- src/modules/module-raop/rtsp-client.c | 14 +++++++++----- src/modules/module-raop/rtsp-client.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/modules/module-raop-sink.c b/src/modules/module-raop-sink.c index 63e803003..a7fb2f0f8 100644 --- a/src/modules/module-raop-sink.c +++ b/src/modules/module-raop-sink.c @@ -1072,13 +1072,14 @@ static void rtsp_auth_setup_reply(void *data, int status, const struct spa_dict static int rtsp_do_auth_setup(struct impl *impl) { - static const char content[] = + static const unsigned char content[33] = "\x01" "\x59\x02\xed\xe9\x0d\x4e\xf2\xbd\x4c\xb6\x8a\x63\x30\x03\x82\x07" "\xa9\x4d\xbd\x50\xd8\xaa\x46\x5b\x5d\x8c\x01\x2a\x0c\x7e\x1d\x4e"; return pw_rtsp_client_url_send(impl->rtsp, "/auth-setup", "POST", &impl->headers->dict, - "application/octet-stream", content, rtsp_auth_setup_reply, impl); + "application/octet-stream", content, sizeof(content), + rtsp_auth_setup_reply, impl); } static const char *find_attr(char **tokens, const char *key) diff --git a/src/modules/module-raop/rtsp-client.c b/src/modules/module-raop/rtsp-client.c index d1f84e9d6..c01b46ef6 100644 --- a/src/modules/module-raop/rtsp-client.c +++ b/src/modules/module-raop/rtsp-client.c @@ -485,7 +485,7 @@ int pw_rtsp_client_disconnect(struct pw_rtsp_client *client) int pw_rtsp_client_url_send(struct pw_rtsp_client *client, const char *url, const char *cmd, const struct spa_dict *headers, - const char *content_type, const char *content, + const char *content_type, const void *content, size_t content_length, void (*reply) (void *user_data, int status, const struct spa_dict *headers), void *user_data) { @@ -510,13 +510,13 @@ int pw_rtsp_client_url_send(struct pw_rtsp_client *client, const char *url, fprintf(f, "%s: %s\r\n", it->key, it->value); } if (content_type != NULL && content != NULL) { - fprintf(f, "Content-Type: %s\r\nContent-Length: %d\r\n", - content_type, (int)strlen(content)); + fprintf(f, "Content-Type: %s\r\nContent-Length: %zu\r\n", + content_type, content_length); } fprintf(f, "\r\n"); if (content_type && content) - fprintf(f, "%s", content); + fwrite(content, 1, content_length, f); fclose(f); @@ -543,5 +543,9 @@ int pw_rtsp_client_send(struct pw_rtsp_client *client, void (*reply) (void *user_data, int status, const struct spa_dict *headers), void *user_data) { - return pw_rtsp_client_url_send(client, client->url, cmd, headers, content_type, content, reply, user_data); + const size_t content_length = content ? strlen(content) : 0; + + return pw_rtsp_client_url_send(client, client->url, cmd, headers, + content_type, content, content_length, + reply, user_data); } diff --git a/src/modules/module-raop/rtsp-client.h b/src/modules/module-raop/rtsp-client.h index 1ff13ee59..75b1ce6a1 100644 --- a/src/modules/module-raop/rtsp-client.h +++ b/src/modules/module-raop/rtsp-client.h @@ -73,7 +73,7 @@ int pw_rtsp_client_get_local_ip(struct pw_rtsp_client *client, int pw_rtsp_client_url_send(struct pw_rtsp_client *client, const char *url, const char *cmd, const struct spa_dict *headers, - const char *content_type, const char *content, + const char *content_type, const void *content, size_t content_length, void (*reply) (void *user_data, int status, const struct spa_dict *headers), void *user_data);