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.
This commit is contained in:
Barnabás Pőcze 2022-09-08 15:33:32 +02:00
parent e5ca5d0480
commit 2d7eb8678b
3 changed files with 13 additions and 8 deletions

View file

@ -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)

View file

@ -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);
}

View file

@ -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);