mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 06:58:56 +00:00
curl*sink: report errors from curl when setting options
https://bugzilla.gnome.org/show_bug.cgi?id=728960
This commit is contained in:
parent
c75c7a9a53
commit
241c3acad5
6 changed files with 324 additions and 87 deletions
|
@ -607,28 +607,81 @@ static gboolean
|
||||||
gst_curl_base_sink_transfer_set_common_options_unlocked (GstCurlBaseSink * sink)
|
gst_curl_base_sink_transfer_set_common_options_unlocked (GstCurlBaseSink * sink)
|
||||||
{
|
{
|
||||||
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_VERBOSE, 1);
|
res = curl_easy_setopt (sink->curl, CURLOPT_VERBOSE, 1);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set verbose: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_URL, sink->url);
|
res = curl_easy_setopt (sink->curl, CURLOPT_URL, sink->url);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set URL: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_CONNECTTIMEOUT, sink->timeout);
|
res = curl_easy_setopt (sink->curl, CURLOPT_CONNECTTIMEOUT, sink->timeout);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set connection timeout: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* using signals in a multi-threaded application is dangerous */
|
/* using signals in a multi-threaded application is dangerous */
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_NOSIGNAL, 1);
|
res = curl_easy_setopt (sink->curl, CURLOPT_NOSIGNAL, 1);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set no signalling: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* socket settings */
|
/* socket settings */
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_SOCKOPTDATA, sink);
|
res = curl_easy_setopt (sink->curl, CURLOPT_SOCKOPTDATA, sink);
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_SOCKOPTFUNCTION,
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set sockopt user data: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
res = curl_easy_setopt (sink->curl, CURLOPT_SOCKOPTFUNCTION,
|
||||||
gst_curl_base_sink_transfer_socket_cb);
|
gst_curl_base_sink_transfer_socket_cb);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set sockopt function: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_READFUNCTION, klass->transfer_read_cb);
|
res = curl_easy_setopt (sink->curl, CURLOPT_READDATA, sink);
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_READDATA, sink);
|
if (res != CURLE_OK) {
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_WRITEFUNCTION,
|
sink->error = g_strdup_printf ("failed to set read user data: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
res = curl_easy_setopt (sink->curl, CURLOPT_READFUNCTION,
|
||||||
|
klass->transfer_read_cb);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set read function: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = curl_easy_setopt (sink->curl, CURLOPT_WRITEDATA, sink);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set write user data: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
res = curl_easy_setopt (sink->curl, CURLOPT_WRITEFUNCTION,
|
||||||
gst_curl_base_sink_transfer_write_cb);
|
gst_curl_base_sink_transfer_write_cb);
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_WRITEDATA, sink);
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set write function: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -636,22 +689,34 @@ gst_curl_base_sink_transfer_set_common_options_unlocked (GstCurlBaseSink * sink)
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_curl_base_sink_transfer_set_options_unlocked (GstCurlBaseSink * sink)
|
gst_curl_base_sink_transfer_set_options_unlocked (GstCurlBaseSink * sink)
|
||||||
{
|
{
|
||||||
gboolean res = FALSE;
|
|
||||||
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
gst_curl_base_sink_transfer_set_common_options_unlocked (sink);
|
if (!gst_curl_base_sink_transfer_set_common_options_unlocked (sink)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* authentication settings */
|
/* authentication settings */
|
||||||
if (sink->user != NULL && strlen (sink->user)) {
|
if (sink->user != NULL && strlen (sink->user)) {
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_USERNAME, sink->user);
|
res = curl_easy_setopt (sink->curl, CURLOPT_USERNAME, sink->user);
|
||||||
curl_easy_setopt (sink->curl, CURLOPT_PASSWORD, sink->passwd);
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set user name: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
res = curl_easy_setopt (sink->curl, CURLOPT_PASSWORD, sink->passwd);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
sink->error = g_strdup_printf ("failed to set password: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (klass->set_options_unlocked) {
|
if (klass->set_options_unlocked) {
|
||||||
res = klass->set_options_unlocked (sink);
|
return klass->set_options_unlocked (sink);
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
|
|
|
@ -185,10 +185,15 @@ static gboolean
|
||||||
set_file_dynamic_options_unlocked (GstCurlBaseSink * basesink)
|
set_file_dynamic_options_unlocked (GstCurlBaseSink * basesink)
|
||||||
{
|
{
|
||||||
gchar *tmp = g_strdup_printf ("%s%s", basesink->url, basesink->file_name);
|
gchar *tmp = g_strdup_printf ("%s%s", basesink->url, basesink->file_name);
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
|
res = curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
|
||||||
|
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
basesink->error = g_strdup_printf ("failed to set URL: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +201,14 @@ set_file_dynamic_options_unlocked (GstCurlBaseSink * basesink)
|
||||||
static gboolean
|
static gboolean
|
||||||
set_file_options_unlocked (GstCurlBaseSink * basesink)
|
set_file_options_unlocked (GstCurlBaseSink * basesink)
|
||||||
{
|
{
|
||||||
curl_easy_setopt (basesink->curl, CURLOPT_UPLOAD, 1L);
|
CURLcode res;
|
||||||
|
|
||||||
|
res = curl_easy_setopt (basesink->curl, CURLOPT_UPLOAD, 1L);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
basesink->error = g_strdup_printf ("failed to prepare for upload: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,6 +178,7 @@ set_ftp_dynamic_options_unlocked (GstCurlBaseSink * basesink)
|
||||||
{
|
{
|
||||||
gchar *tmp = NULL;
|
gchar *tmp = NULL;
|
||||||
GstCurlFtpSink *sink = GST_CURL_FTP_SINK (basesink);
|
GstCurlFtpSink *sink = GST_CURL_FTP_SINK (basesink);
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
if (sink->tmpfile_create) {
|
if (sink->tmpfile_create) {
|
||||||
gchar *rename_from = NULL;
|
gchar *rename_from = NULL;
|
||||||
|
@ -213,10 +214,25 @@ set_ftp_dynamic_options_unlocked (GstCurlBaseSink * basesink)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = g_strdup_printf ("%s%s", basesink->url, uploadfile_as);
|
tmp = g_strdup_printf ("%s%s", basesink->url, uploadfile_as);
|
||||||
curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
|
|
||||||
|
res = curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
g_free (tmp);
|
||||||
|
basesink->error = g_strdup_printf ("failed to set URL: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
sink->headerlist = curl_slist_append (sink->headerlist, rename_from);
|
sink->headerlist = curl_slist_append (sink->headerlist, rename_from);
|
||||||
sink->headerlist = curl_slist_append (sink->headerlist, rename_to);
|
sink->headerlist = curl_slist_append (sink->headerlist, rename_to);
|
||||||
curl_easy_setopt (basesink->curl, CURLOPT_POSTQUOTE, sink->headerlist);
|
|
||||||
|
res = curl_easy_setopt (basesink->curl, CURLOPT_POSTQUOTE, sink->headerlist);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
g_free (tmp);
|
||||||
|
basesink->error = g_strdup_printf ("failed to set post quote: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
g_free (rename_from);
|
g_free (rename_from);
|
||||||
g_free (rename_to);
|
g_free (rename_to);
|
||||||
|
@ -228,7 +244,13 @@ set_ftp_dynamic_options_unlocked (GstCurlBaseSink * basesink)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmp = g_strdup_printf ("%s%s", basesink->url, basesink->file_name);
|
tmp = g_strdup_printf ("%s%s", basesink->url, basesink->file_name);
|
||||||
curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
|
res = curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
g_free (tmp);
|
||||||
|
basesink->error = g_strdup_printf ("failed to set URL: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
|
@ -240,12 +262,18 @@ static gboolean
|
||||||
set_ftp_options_unlocked (GstCurlBaseSink * basesink)
|
set_ftp_options_unlocked (GstCurlBaseSink * basesink)
|
||||||
{
|
{
|
||||||
GstCurlFtpSink *sink = GST_CURL_FTP_SINK (basesink);
|
GstCurlFtpSink *sink = GST_CURL_FTP_SINK (basesink);
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
curl_easy_setopt (basesink->curl, CURLOPT_UPLOAD, 1L);
|
res = curl_easy_setopt (basesink->curl, CURLOPT_UPLOAD, 1L);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
basesink->error = g_strdup_printf ("failed to prepare for upload: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (sink->ftp_port_arg != NULL && (strlen (sink->ftp_port_arg) > 0)) {
|
if (sink->ftp_port_arg != NULL && (strlen (sink->ftp_port_arg) > 0)) {
|
||||||
/* Connect data stream actively. */
|
/* Connect data stream actively. */
|
||||||
CURLcode res = curl_easy_setopt (basesink->curl, CURLOPT_FTPPORT,
|
res = curl_easy_setopt (basesink->curl, CURLOPT_FTPPORT,
|
||||||
sink->ftp_port_arg);
|
sink->ftp_port_arg);
|
||||||
|
|
||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
|
@ -253,21 +281,31 @@ set_ftp_options_unlocked (GstCurlBaseSink * basesink)
|
||||||
curl_easy_strerror (res));
|
curl_easy_strerror (res));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
goto end;
|
/* Connect data stream passively.
|
||||||
|
* libcurl will always attempt to use EPSV before PASV.
|
||||||
|
*/
|
||||||
|
if (!sink->epsv_mode) {
|
||||||
|
/* send only plain PASV command */
|
||||||
|
res = curl_easy_setopt (basesink->curl, CURLOPT_FTP_USE_EPSV, 0);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
basesink->error =
|
||||||
|
g_strdup_printf ("failed to set extended passive mode: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connect data stream passively.
|
|
||||||
* libcurl will always attempt to use EPSV before PASV.
|
|
||||||
*/
|
|
||||||
if (!sink->epsv_mode) {
|
|
||||||
/* send only plain PASV command */
|
|
||||||
curl_easy_setopt (basesink->curl, CURLOPT_FTP_USE_EPSV, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
end:
|
|
||||||
if (sink->create_dirs) {
|
if (sink->create_dirs) {
|
||||||
curl_easy_setopt (basesink->curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
|
res = curl_easy_setopt (basesink->curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
|
||||||
|
1L);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
basesink->error =
|
||||||
|
g_strdup_printf ("failed to set create missing dirs: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -317,6 +317,7 @@ gst_curl_http_sink_set_header_unlocked (GstCurlBaseSink * bcsink)
|
||||||
{
|
{
|
||||||
GstCurlHttpSink *sink = GST_CURL_HTTP_SINK (bcsink);
|
GstCurlHttpSink *sink = GST_CURL_HTTP_SINK (bcsink);
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
if (sink->header_list) {
|
if (sink->header_list) {
|
||||||
curl_slist_free_all (sink->header_list);
|
curl_slist_free_all (sink->header_list);
|
||||||
|
@ -355,7 +356,12 @@ set_headers:
|
||||||
"\"%s\"", bcsink->file_name);
|
"\"%s\"", bcsink->file_name);
|
||||||
sink->header_list = curl_slist_append (sink->header_list, tmp);
|
sink->header_list = curl_slist_append (sink->header_list, tmp);
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_HTTPHEADER, sink->header_list);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_HTTPHEADER, sink->header_list);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set HTTP headers: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -365,6 +371,7 @@ gst_curl_http_sink_set_options_unlocked (GstCurlBaseSink * bcsink)
|
||||||
{
|
{
|
||||||
GstCurlHttpSink *sink = GST_CURL_HTTP_SINK (bcsink);
|
GstCurlHttpSink *sink = GST_CURL_HTTP_SINK (bcsink);
|
||||||
GstCurlTlsSinkClass *parent_class;
|
GstCurlTlsSinkClass *parent_class;
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
/* proxy settings */
|
/* proxy settings */
|
||||||
if (sink->proxy != NULL) {
|
if (sink->proxy != NULL) {
|
||||||
|
@ -373,10 +380,21 @@ gst_curl_http_sink_set_options_unlocked (GstCurlBaseSink * bcsink)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_POST, 1L);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_POST, 1L);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set HTTP POST: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* FIXME: check user & passwd */
|
/* FIXME: check user & passwd */
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error =
|
||||||
|
g_strdup_printf ("failed to set HTTP authentication methods: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
parent_class = GST_CURL_TLS_SINK_GET_CLASS (sink);
|
parent_class = GST_CURL_TLS_SINK_GET_CLASS (sink);
|
||||||
|
|
||||||
|
@ -449,30 +467,58 @@ static gboolean
|
||||||
proxy_setup (GstCurlBaseSink * bcsink)
|
proxy_setup (GstCurlBaseSink * bcsink)
|
||||||
{
|
{
|
||||||
GstCurlHttpSink *sink = GST_CURL_HTTP_SINK (bcsink);
|
GstCurlHttpSink *sink = GST_CURL_HTTP_SINK (bcsink);
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
if (curl_easy_setopt (bcsink->curl, CURLOPT_PROXY, sink->proxy)
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_PROXY, sink->proxy);
|
||||||
!= CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set proxy: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curl_easy_setopt (bcsink->curl, CURLOPT_PROXYPORT, sink->proxy_port)
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_PROXYPORT, sink->proxy_port);
|
||||||
!= CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set proxy port: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sink->proxy_user != NULL &&
|
if (sink->proxy_user != NULL &&
|
||||||
strlen (sink->proxy_user) &&
|
strlen (sink->proxy_user) &&
|
||||||
sink->proxy_passwd != NULL && strlen (sink->proxy_passwd)) {
|
sink->proxy_passwd != NULL && strlen (sink->proxy_passwd)) {
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_PROXYUSERNAME, sink->proxy_user);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_PROXYUSERNAME,
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_PROXYPASSWORD, sink->proxy_passwd);
|
sink->proxy_user);
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set proxy user name: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_PROXYPASSWORD,
|
||||||
|
sink->proxy_passwd);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set proxy password: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error =
|
||||||
|
g_strdup_printf ("failed to set proxy authentication method: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
sink->proxy_auth = TRUE;
|
sink->proxy_auth = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_str_has_prefix (bcsink->url, "https://")) {
|
if (g_str_has_prefix (bcsink->url, "https://")) {
|
||||||
/* tunnel all operations through a given HTTP proxy */
|
/* tunnel all operations through a given HTTP proxy */
|
||||||
if (curl_easy_setopt (bcsink->curl, CURLOPT_HTTPPROXYTUNNEL, 1L)
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
|
||||||
!= CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set HTTP proxy tunnel: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -630,6 +630,7 @@ gst_curl_smtp_sink_set_transfer_options_unlocked (GstCurlBaseSink * bcsink)
|
||||||
gchar *from_header = NULL;
|
gchar *from_header = NULL;
|
||||||
gchar *enc_from;
|
gchar *enc_from;
|
||||||
gint i;
|
gint i;
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
g_assert (sink->payload_headers == NULL);
|
g_assert (sink->payload_headers == NULL);
|
||||||
g_assert (sink->mail_rcpt != NULL);
|
g_assert (sink->mail_rcpt != NULL);
|
||||||
|
@ -694,7 +695,13 @@ gst_curl_smtp_sink_set_transfer_options_unlocked (GstCurlBaseSink * bcsink)
|
||||||
g_free (from_header);
|
g_free (from_header);
|
||||||
g_free (request_headers);
|
g_free (request_headers);
|
||||||
|
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_MAIL_FROM, sink->mail_from);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_MAIL_FROM, sink->mail_from);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error =
|
||||||
|
g_strdup_printf ("failed to set SMTP sender email address: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (sink->curl_recipients != NULL) {
|
if (sink->curl_recipients != NULL) {
|
||||||
curl_slist_free_all (sink->curl_recipients);
|
curl_slist_free_all (sink->curl_recipients);
|
||||||
|
@ -709,7 +716,14 @@ gst_curl_smtp_sink_set_transfer_options_unlocked (GstCurlBaseSink * bcsink)
|
||||||
g_strfreev (tmp_list);
|
g_strfreev (tmp_list);
|
||||||
|
|
||||||
/* note that the CURLOPT_MAIL_RCPT takes a list, not a char array */
|
/* note that the CURLOPT_MAIL_RCPT takes a list, not a char array */
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_MAIL_RCPT, sink->curl_recipients);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_MAIL_RCPT,
|
||||||
|
sink->curl_recipients);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error =
|
||||||
|
g_strdup_printf ("failed to set SMTP recipient email address: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
parent_class = GST_CURL_TLS_SINK_GET_CLASS (sink);
|
parent_class = GST_CURL_TLS_SINK_GET_CLASS (sink);
|
||||||
|
|
||||||
|
@ -954,29 +968,44 @@ gst_curl_smtp_sink_prepare_transfer (GstCurlBaseSink * bcsink)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_easy_setopt (sink->pop_curl, CURLOPT_URL, sink->pop_location);
|
res = curl_easy_setopt (sink->pop_curl, CURLOPT_URL, sink->pop_location);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set URL: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (sink->pop_user != NULL && strlen (sink->pop_user) &&
|
if (sink->pop_user != NULL && strlen (sink->pop_user) &&
|
||||||
sink->pop_passwd != NULL && strlen (sink->pop_passwd)) {
|
sink->pop_passwd != NULL && strlen (sink->pop_passwd)) {
|
||||||
curl_easy_setopt (sink->pop_curl, CURLOPT_USERNAME, sink->pop_user);
|
res = curl_easy_setopt (sink->pop_curl, CURLOPT_USERNAME, sink->pop_user);
|
||||||
curl_easy_setopt (sink->pop_curl, CURLOPT_PASSWORD, sink->pop_passwd);
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set user name: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = curl_easy_setopt (sink->pop_curl, CURLOPT_PASSWORD,
|
||||||
|
sink->pop_passwd);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set user name: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sink->pop_curl == NULL) {
|
if (sink->pop_curl != NULL) {
|
||||||
goto end;
|
/* ready to initialize connection to POP server */
|
||||||
|
res = curl_easy_perform (sink->pop_curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("POP transfer failed: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
ret = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_cleanup (sink->pop_curl);
|
||||||
|
sink->pop_curl = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ready to initialize connection to POP server */
|
|
||||||
res = curl_easy_perform (sink->pop_curl);
|
|
||||||
if (res != CURLE_OK) {
|
|
||||||
bcsink->error = g_strdup_printf ("POP transfer failed: %s",
|
|
||||||
curl_easy_strerror (res));
|
|
||||||
ret = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_easy_cleanup (sink->pop_curl);
|
|
||||||
sink->pop_curl = NULL;
|
|
||||||
|
|
||||||
end:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,21 +235,34 @@ static gboolean
|
||||||
gst_curl_tls_sink_set_options_unlocked (GstCurlBaseSink * bcsink)
|
gst_curl_tls_sink_set_options_unlocked (GstCurlBaseSink * bcsink)
|
||||||
{
|
{
|
||||||
GstCurlTlsSink *sink = GST_CURL_TLS_SINK (bcsink);
|
GstCurlTlsSink *sink = GST_CURL_TLS_SINK (bcsink);
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
if (!g_str_has_prefix (bcsink->url, "http"))
|
if (!g_str_has_prefix (bcsink->url, "http")) {
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set SSL level: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* crypto engine */
|
/* crypto engine */
|
||||||
if ((g_strcmp0 (sink->crypto_engine, "auto") == 0) ||
|
if ((g_strcmp0 (sink->crypto_engine, "auto") == 0) ||
|
||||||
(sink->crypto_engine == NULL)) {
|
(sink->crypto_engine == NULL)) {
|
||||||
if (curl_easy_setopt (bcsink->curl, CURLOPT_SSLENGINE_DEFAULT, 1L)
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_SSLENGINE_DEFAULT, 1L);
|
||||||
!= CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
GST_WARNING ("Error setting up default SSL engine.");
|
bcsink->error =
|
||||||
|
g_strdup_printf ("failed to set default crypto engine: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (curl_easy_setopt (bcsink->curl, CURLOPT_SSLENGINE,
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_SSLENGINE,
|
||||||
sink->crypto_engine) == CURLE_SSL_ENGINE_NOTFOUND) {
|
sink->crypto_engine);
|
||||||
GST_WARNING ("Error setting up SSL engine: %s.", sink->crypto_engine);
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set crypto engine: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,28 +271,62 @@ gst_curl_tls_sink_set_options_unlocked (GstCurlBaseSink * bcsink)
|
||||||
* certificates. */
|
* certificates. */
|
||||||
if (sink->ca_cert != NULL && strlen (sink->ca_cert)) {
|
if (sink->ca_cert != NULL && strlen (sink->ca_cert)) {
|
||||||
GST_DEBUG ("setting ca cert");
|
GST_DEBUG ("setting ca cert");
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_CAINFO, sink->ca_cert);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_CAINFO, sink->ca_cert);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set certificate: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sink->ca_path != NULL && strlen (sink->ca_path)) {
|
if (sink->ca_path != NULL && strlen (sink->ca_path)) {
|
||||||
GST_DEBUG ("setting ca path");
|
GST_DEBUG ("setting ca path");
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_CAPATH, sink->ca_path);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_CAPATH, sink->ca_path);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set certificate path: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sink->insecure) {
|
if (!sink->insecure) {
|
||||||
/* identify authenticity of the peer's certificate */
|
/* identify authenticity of the peer's certificate */
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error = g_strdup_printf ("failed to set verification of peer: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
/* when CURLOPT_SSL_VERIFYHOST is 2, the commonName or subjectAltName
|
/* when CURLOPT_SSL_VERIFYHOST is 2, the commonName or subjectAltName
|
||||||
* fields are verified */
|
* fields are verified */
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error =
|
||||||
|
g_strdup_printf
|
||||||
|
("failed to set verification of server certificate: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* allow "insecure" SSL connections and transfers */
|
||||||
|
if (sink->insecure) {
|
||||||
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error =
|
||||||
|
g_strdup_printf ("failed to set verification of peer: %s",
|
||||||
|
curl_easy_strerror (res));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
res = curl_easy_setopt (bcsink->curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||||
}
|
if (res != CURLE_OK) {
|
||||||
|
bcsink->error =
|
||||||
/* allow "insecure" SSL connections and transfers */
|
g_strdup_printf
|
||||||
if (sink->insecure) {
|
("failed to set verification of server certificate: %s",
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
curl_easy_strerror (res));
|
||||||
curl_easy_setopt (bcsink->curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
Loading…
Reference in a new issue