Skip to content

Commit

Permalink
vcap/rtsp: correctly set user/pass
Browse files Browse the repository at this point in the history
The parsing was quite bogus, especially if there was no user:pass but
a port specification in URI (with ':').

The stuff doesn't seem to be essential, anyways, since userinfo is also
passed to the server as part of the URI.
  • Loading branch information
MartinPulec committed Jul 19, 2024
1 parent e365a88 commit 8a7aed3
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/video_capture/rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,28 +1041,35 @@ rtsp_get_parameters(CURL *curl, const char *uri) {
return 1;
}

static void
rtsp_set_user_pass(CURL *curl, char *user_pass)
{
char *save_ptr = NULL;
char *user = strtok_r(user_pass, ":", &save_ptr);
assert(user != NULL);
my_curl_easy_setopt(curl, CURLOPT_USERNAME, user, return);
char *pass = strtok_r(NULL, ":", &save_ptr);
if (!pass) {
return;
}
my_curl_easy_setopt(curl, CURLOPT_PASSWORD, pass, return);
}

/**
* send RTSP OPTIONS request
*/
static int
rtsp_options(CURL *curl, const char *uri) {
char control[1501] = "",
user[1501] = "",
pass[1501] = "",
*strtoken;
char control[1501] = "";

verbose_msg("\n[rtsp] OPTIONS %s\n", uri);
my_curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri, return -1);

sscanf(uri, "rtsp://%1500s", control);
strtoken = strtok(control, ":");
assert(strtoken != NULL);
strncpy(user, strtoken, sizeof user - 1);
strtoken = strtok(NULL, "@");
if (strtoken != NULL) {
strncpy(pass, strtoken, sizeof pass - 1);
my_curl_easy_setopt(curl, CURLOPT_USERNAME, user, return -1);
my_curl_easy_setopt(curl, CURLOPT_PASSWORD, pass, return -1);

if (strchr(control, '@') != NULL) {
*strchr(control, '@') = '\0';
rtsp_set_user_pass(curl, control);
}

my_curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, (long )CURL_RTSPREQ_OPTIONS, return -1);
Expand Down

0 comments on commit 8a7aed3

Please sign in to comment.