Hello, everyone!I want to connect to my camera using libcurl and RTSP and I've wrote simple function to do it. In case of using basic auth it works fine but I don't know how can I auth in case of digest method. Here is my code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
static int
rtsp_describe(CURL *curl, const char *uri, const char *user, const char *pwd)
{
char *userpwd = calloc(0, strlen(user) + strlen(pwd) + 2);
if (userpwd == NULL) {
fprintf(stderr, "Error: memory allocation failed!\n");
return -1;
}
strcat(userpwd, user);
strcat(userpwd, ":");
strcat(userpwd, pwd);
fprintf(stdout, "RTSP: DESCRIBE %s\n", uri);
curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, uri);
curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout);
curl_easy_perform(curl);
curl_easy_reset(curl);
free(userpwd);
return 0;
}
int
main(int argc, char **argv)
{
if (argc != 4) {
fprintf(stderr, "Usage: %s addr username password\n", argv[0]);
exit(EXIT_FAILURE);
}
CURLcode ret = CURLE_OK;
const char *url = argv[1];
char *uri = malloc(strlen(url) + 32);
if (uri == NULL) {
fprintf(stderr, "Error: memory allocation failed!\n");
exit(EXIT_FAILURE);
}
ret = curl_global_init(CURL_GLOBAL_ALL);
if (ret == CURLE_OK) {
CURL *curl = curl_easy_init();
if (curl != NULL) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout);
curl_easy_setopt(curl, CURLOPT_URL, url);
snprintf(uri, strlen(url) + 32, "%s", url);
rtsp_describe(curl, uri, argv[2], argv[3]);
curl_easy_cleanup(curl);
}
}
free(uri);
return 0;
}
If I delete line with CURLAUTH_DIGEST it work fine using basic auth. So, the question is, how can I login using digest auth? How can I get realm and nonce from camera in my code? Sorry, if this question is stupid, but I really stuck on it, and after my long googling I couldn't find anything useful.