Lower the CURL version required to fix build in RHEL

Some vendors really really want 1.5.x in newer RHEL versions, but the version
of curl is too old. Add #ifdefs so that we can emulate (somewhat imperfectly)
the 'new' CURLU functonality.
This commit is contained in:
Richard Hughes 2020-12-07 10:25:12 +00:00
parent b6f3ff9330
commit 00640f42f2
6 changed files with 104 additions and 15 deletions

View File

@ -1,7 +1,7 @@
%global glib2_version 2.45.8
%global libxmlb_version 0.1.3
%global libgusb_version 0.3.5
%global libcurl_version 7.62.0
%global libcurl_version 7.61.0
%global libjcat_version 0.1.0
%global systemd_version 231
%global json_glib_version 1.1.1

View File

@ -97,7 +97,9 @@ static guint signals [SIGNAL_LAST] = { 0 };
G_DEFINE_TYPE_WITH_PRIVATE (FwupdClient, fwupd_client, G_TYPE_OBJECT)
#define GET_PRIVATE(o) (fwupd_client_get_instance_private (o))
#ifdef HAVE_LIBCURL_7_62_0
G_DEFINE_AUTOPTR_CLEANUP_FUNC(CURLU, curl_url_cleanup)
#endif
static void
fwupd_client_curl_helper_free (FwupdCurlHelper *helper)
@ -2335,8 +2337,13 @@ fwupd_client_install_release_download_cb (GObject *source, GAsyncResult *res, gp
static gboolean
fwupd_client_is_url (const gchar *perhaps_url)
{
#ifdef HAVE_LIBCURL_7_62_0
g_autoptr(CURLU) h = curl_url ();
return curl_url_set (h, CURLUPART_URL, perhaps_url, 0) == CURLUE_OK;
#else
return g_str_has_prefix (perhaps_url, "http://") ||
g_str_has_prefix (perhaps_url, "https://");
#endif
}
static void

View File

@ -67,9 +67,11 @@ enum {
G_DEFINE_TYPE_WITH_PRIVATE (FwupdRemote, fwupd_remote, G_TYPE_OBJECT)
#define GET_PRIVATE(o) (fwupd_remote_get_instance_private (o))
#ifdef HAVE_LIBCURL_7_62_0
typedef gchar curlptr;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(curlptr, curl_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(CURLU, curl_url_cleanup)
#endif
static void
fwupd_remote_set_username (FwupdRemote *self, const gchar *username)
@ -175,16 +177,14 @@ fwupd_remote_get_suffix_for_keyring_kind (FwupdKeyringKind keyring_kind)
return NULL;
}
static CURLU *
static gchar *
fwupd_remote_build_uri (FwupdRemote *self, const gchar *url, GError **error)
{
FwupdRemotePrivate *priv = GET_PRIVATE (self);
#ifdef HAVE_LIBCURL_7_62_0
g_autoptr(curlptr) tmp_uri = NULL;
g_autoptr(CURLU) uri = curl_url ();
g_return_val_if_fail (FWUPD_IS_REMOTE (self), NULL);
g_return_val_if_fail (url != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
/* create URI, substituting if required */
if (priv->firmware_base_uri != NULL) {
g_autofree gchar *basename = NULL;
@ -237,7 +237,19 @@ fwupd_remote_build_uri (FwupdRemote *self, const gchar *url, GError **error)
curl_url_set (uri, CURLUPART_USER, priv->username, 0);
if (priv->password != NULL)
curl_url_set (uri, CURLUPART_PASSWORD, priv->password, 0);
return g_steal_pointer (&uri);
curl_url_get (uri, CURLUPART_URL, &tmp_uri, 0);
return g_strdup (tmp_uri);
#else
if (priv->firmware_base_uri != NULL) {
g_autofree gchar *basename = g_path_get_basename (url);
return g_build_filename (priv->firmware_base_uri, basename, NULL);
}
if (g_strstr_len (url, -1, "/") == NULL) {
g_autofree gchar *basename = g_path_get_dirname (priv->metadata_uri);
return g_build_filename (basename, url, NULL);
}
return g_strdup (url);
#endif
}
/* note, this has to be set before username and password */
@ -885,12 +897,10 @@ fwupd_remote_get_checksum (FwupdRemote *self)
gchar *
fwupd_remote_build_firmware_uri (FwupdRemote *self, const gchar *url, GError **error)
{
g_autoptr(curlptr) tmp = NULL;
g_autoptr(CURLU) uri = fwupd_remote_build_uri (self, url, error);
if (uri == NULL)
return NULL;
curl_url_get (uri, CURLUPART_URL, &tmp, 0);
return g_strdup (tmp);
g_return_val_if_fail (FWUPD_IS_REMOTE (self), NULL);
g_return_val_if_fail (url != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
return fwupd_remote_build_uri (self, url, error);
}
/**

View File

@ -208,7 +208,10 @@ endif
libjcat = dependency('jcat', version : '>= 0.1.0', fallback : ['libjcat', 'libjcat_dep'])
libjsonglib = dependency('json-glib-1.0', version : '>= 1.1.1')
valgrind = dependency('valgrind', required: false)
libcurl = dependency('libcurl', version : '>= 7.62.0')
libcurl = dependency('libcurl', version : '>= 7.61.0')
if libcurl.version().version_compare('>= 7.62.0')
conf.set('HAVE_LIBCURL_7_62_0', '1')
endif
if build_daemon
if get_option('polkit')
polkit = dependency('polkit-gobject-1', version : '>= 0.103')

View File

@ -34,9 +34,11 @@ struct _FuRedfishClient
G_DEFINE_TYPE (FuRedfishClient, fu_redfish_client, G_TYPE_OBJECT)
#ifdef HAVE_LIBCURL_7_62_0
typedef gchar curlptr;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(curlptr, curl_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(CURLU, curl_url_cleanup)
#endif
static size_t
fu_redfish_client_fetch_data_cb (char *ptr, size_t size, size_t nmemb, void *userdata)
@ -52,10 +54,15 @@ fu_redfish_client_fetch_data (FuRedfishClient *self, const gchar *uri_path, GErr
{
CURLcode res;
g_autofree gchar *port = g_strdup_printf ("%u", self->port);
g_autoptr(CURLU) uri = NULL;
g_autoptr(GByteArray) buf = g_byte_array_new ();
#ifdef HAVE_LIBCURL_7_62_0
g_autoptr(CURLU) uri = NULL;
#else
g_autofree gchar *uri = NULL;
#endif
/* create URI */
#ifdef HAVE_LIBCURL_7_62_0
uri = curl_url ();
curl_url_set (uri, CURLU_DEFAULT_SCHEME, self->use_https ? "https" : "http", 0);
curl_url_set (uri, CURLUPART_PATH, uri_path, 0);
@ -68,19 +75,43 @@ fu_redfish_client_fetch_data (FuRedfishClient *self, const gchar *uri_path, GErr
"failed to create message for URI");
return NULL;
}
#else
uri = g_strdup_printf ("%s://%s:%s%s",
self->use_https ? "https" : "http",
self->hostname,
port,
uri_path);
if (curl_easy_setopt (self->curl, CURLOPT_URL, uri) != CURLE_OK) {
g_set_error_literal (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_FILE,
"failed to create message for URI");
return NULL;
}
#endif
curl_easy_setopt (self->curl, CURLOPT_WRITEFUNCTION, fu_redfish_client_fetch_data_cb);
curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, buf);
res = curl_easy_perform (self->curl);
if (res != CURLE_OK) {
glong status_code = 0;
#ifdef HAVE_LIBCURL_7_62_0
g_autoptr(curlptr) uri_str = NULL;
#endif
curl_easy_getinfo (self->curl, CURLINFO_RESPONSE_CODE, &status_code);
#ifdef HAVE_LIBCURL_7_62_0
curl_url_get (uri, CURLUPART_URL, &uri_str, 0);
g_set_error (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_FILE,
"failed to download %s: %s",
uri_str, curl_easy_strerror (res));
#else
g_set_error (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_FILE,
"failed to download %s: %s",
uri, curl_easy_strerror (res));
#endif
return NULL;
}
@ -572,7 +603,11 @@ fu_redfish_client_update (FuRedfishClient *self, FuDevice *device, GBytes *blob_
curl_mimepart *part;
g_autofree gchar *filename = NULL;
g_autofree gchar *port = g_strdup_printf ("%u", self->port);
#ifdef HAVE_LIBCURL_7_62_0
g_autoptr(CURLU) uri = curl_url ();
#else
g_autofree gchar *uri = NULL;
#endif
g_autoptr(curl_mime) mime = curl_mime_init (self->curl);
/* Get the update version */
@ -587,6 +622,7 @@ fu_redfish_client_update (FuRedfishClient *self, FuDevice *device, GBytes *blob_
}
/* create URI */
#ifdef HAVE_LIBCURL_7_62_0
curl_url_set (uri, CURLU_DEFAULT_SCHEME, self->use_https ? "https" : "http", 0);
curl_url_set (uri, CURLUPART_PATH, self->push_uri_path, 0);
curl_url_set (uri, CURLUPART_HOST, self->hostname, 0);
@ -598,6 +634,20 @@ fu_redfish_client_update (FuRedfishClient *self, FuDevice *device, GBytes *blob_
"failed to create message for URI");
return FALSE;
}
#else
uri = g_strdup_printf ("%s://%s:%s%s",
self->use_https ? "https" : "http",
self->hostname,
port,
self->push_uri_path);
if (curl_easy_setopt (self->curl, CURLOPT_URL, uri) != CURLE_OK) {
g_set_error_literal (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_FILE,
"failed to create message for URI");
return FALSE;
}
#endif
/* Create the multipart request */
curl_easy_setopt (self->curl, CURLOPT_MIMEPOST, mime);
@ -607,8 +657,11 @@ fu_redfish_client_update (FuRedfishClient *self, FuDevice *device, GBytes *blob_
res = curl_easy_perform (self->curl);
if (res != CURLE_OK) {
glong status_code = 0;
#ifdef HAVE_LIBCURL_7_62_0
g_autoptr(curlptr) uri_str = NULL;
#endif
curl_easy_getinfo (self->curl, CURLINFO_RESPONSE_CODE, &status_code);
#ifdef HAVE_LIBCURL_7_62_0
curl_url_get (uri, CURLUPART_URL, &uri_str, 0);
g_set_error (error,
FWUPD_ERROR,
@ -617,6 +670,15 @@ fu_redfish_client_update (FuRedfishClient *self, FuDevice *device, GBytes *blob_
filename, uri_str,
curl_easy_strerror (res));
return FALSE;
#else
g_set_error (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_FILE,
"failed to upload %s to %s: %s",
filename, uri,
curl_easy_strerror (res));
return FALSE;
#endif
}
return TRUE;

View File

@ -2009,11 +2009,18 @@ fu_util_show_unsupported_warn (void)
#endif
}
#ifdef HAVE_LIBCURL_7_62_0
G_DEFINE_AUTOPTR_CLEANUP_FUNC(CURLU, curl_url_cleanup)
#endif
gboolean
fu_util_is_url (const gchar *perhaps_url)
{
#ifdef HAVE_LIBCURL_7_62_0
g_autoptr(CURLU) h = curl_url ();
return curl_url_set (h, CURLUPART_URL, perhaps_url, 0) == CURLUE_OK;
#else
return g_str_has_prefix (perhaps_url, "http://") ||
g_str_has_prefix (perhaps_url, "https://");
#endif
}