mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-06 11:07:37 +00:00
trivial: Do the fwupdmgr network setup in a new function
This is for future use by other commands.
This commit is contained in:
parent
054b68457d
commit
d980ccb757
@ -53,6 +53,7 @@ typedef struct {
|
|||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
GOptionContext *context;
|
GOptionContext *context;
|
||||||
GPtrArray *cmd_array;
|
GPtrArray *cmd_array;
|
||||||
|
SoupSession *soup_session;
|
||||||
FwupdInstallFlags flags;
|
FwupdInstallFlags flags;
|
||||||
FwupdClient *client;
|
FwupdClient *client;
|
||||||
FuProgressbar *progressbar;
|
FuProgressbar *progressbar;
|
||||||
@ -287,6 +288,48 @@ fu_util_prompt_for_device (FuUtilPrivate *priv, GError **error)
|
|||||||
return g_object_ref (dev);
|
return g_object_ref (dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
fu_util_setup_networking (FuUtilPrivate *priv, GError **error)
|
||||||
|
{
|
||||||
|
const gchar *http_proxy;
|
||||||
|
g_autofree gchar *user_agent = NULL;
|
||||||
|
|
||||||
|
/* already done */
|
||||||
|
if (priv->soup_session != NULL)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
/* create the soup session */
|
||||||
|
user_agent = fwupd_build_user_agent (PACKAGE_NAME, PACKAGE_VERSION);
|
||||||
|
priv->soup_session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT, user_agent,
|
||||||
|
SOUP_SESSION_TIMEOUT, 60,
|
||||||
|
NULL);
|
||||||
|
if (priv->soup_session == NULL) {
|
||||||
|
g_set_error_literal (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INTERNAL,
|
||||||
|
"failed to setup networking");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the proxy */
|
||||||
|
http_proxy = g_getenv ("http_proxy");
|
||||||
|
if (http_proxy != NULL) {
|
||||||
|
g_autoptr(SoupURI) proxy_uri = soup_uri_new (http_proxy);
|
||||||
|
if (proxy_uri == NULL) {
|
||||||
|
g_set_error (error,
|
||||||
|
FWUPD_ERROR,
|
||||||
|
FWUPD_ERROR_INTERNAL,
|
||||||
|
"invalid proxy URI: %s", http_proxy);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
g_object_set (priv->soup_session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this disables the double-compression of the firmware.xml.gz file */
|
||||||
|
soup_session_remove_feature_by_type (priv->soup_session, SOUP_TYPE_CONTENT_DECODER);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fu_util_get_devices (FuUtilPrivate *priv, gchar **values, GError **error)
|
fu_util_get_devices (FuUtilPrivate *priv, gchar **values, GError **error)
|
||||||
{
|
{
|
||||||
@ -635,14 +678,11 @@ fu_util_download_file (FuUtilPrivate *priv,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GChecksumType checksum_type;
|
GChecksumType checksum_type;
|
||||||
const gchar *http_proxy;
|
|
||||||
guint status_code;
|
guint status_code;
|
||||||
g_autoptr(GError) error_local = NULL;
|
g_autoptr(GError) error_local = NULL;
|
||||||
g_autofree gchar *checksum_actual = NULL;
|
g_autofree gchar *checksum_actual = NULL;
|
||||||
g_autofree gchar *user_agent = NULL;
|
|
||||||
g_autofree gchar *uri_str = NULL;
|
g_autofree gchar *uri_str = NULL;
|
||||||
g_autoptr(SoupMessage) msg = NULL;
|
g_autoptr(SoupMessage) msg = NULL;
|
||||||
g_autoptr(SoupSession) session = NULL;
|
|
||||||
|
|
||||||
/* check if the file already exists with the right checksum */
|
/* check if the file already exists with the right checksum */
|
||||||
checksum_type = fwupd_checksum_guess_kind (checksum_expected);
|
checksum_type = fwupd_checksum_guess_kind (checksum_expected);
|
||||||
@ -651,35 +691,9 @@ fu_util_download_file (FuUtilPrivate *priv,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the soup session */
|
/* set up networking */
|
||||||
user_agent = fwupd_build_user_agent (PACKAGE_NAME, PACKAGE_VERSION);
|
if (!fu_util_setup_networking (priv, error))
|
||||||
session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT, user_agent,
|
|
||||||
SOUP_SESSION_TIMEOUT, 60,
|
|
||||||
NULL);
|
|
||||||
if (session == NULL) {
|
|
||||||
g_set_error_literal (error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_INTERNAL,
|
|
||||||
"failed to setup networking");
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
/* set the proxy */
|
|
||||||
http_proxy = g_getenv ("http_proxy");
|
|
||||||
if (http_proxy != NULL) {
|
|
||||||
g_autoptr(SoupURI) proxy_uri = soup_uri_new (http_proxy);
|
|
||||||
if (proxy_uri == NULL) {
|
|
||||||
g_set_error (error,
|
|
||||||
FWUPD_ERROR,
|
|
||||||
FWUPD_ERROR_INTERNAL,
|
|
||||||
"invalid proxy URI: %s", http_proxy);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
g_object_set (session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* this disables the double-compression of the firmware.xml.gz file */
|
|
||||||
soup_session_remove_feature_by_type (session, SOUP_TYPE_CONTENT_DECODER);
|
|
||||||
|
|
||||||
/* download data */
|
/* download data */
|
||||||
uri_str = soup_uri_to_string (uri, FALSE);
|
uri_str = soup_uri_to_string (uri, FALSE);
|
||||||
@ -709,7 +723,7 @@ fu_util_download_file (FuUtilPrivate *priv,
|
|||||||
}
|
}
|
||||||
g_signal_connect (msg, "got-chunk",
|
g_signal_connect (msg, "got-chunk",
|
||||||
G_CALLBACK (fu_util_download_chunk_cb), priv);
|
G_CALLBACK (fu_util_download_chunk_cb), priv);
|
||||||
status_code = soup_session_send_message (session, msg);
|
status_code = soup_session_send_message (priv->soup_session, msg);
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
if (status_code != SOUP_STATUS_OK) {
|
if (status_code != SOUP_STATUS_OK) {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
@ -1564,6 +1578,8 @@ fu_util_private_free (FuUtilPrivate *priv)
|
|||||||
g_ptr_array_unref (priv->cmd_array);
|
g_ptr_array_unref (priv->cmd_array);
|
||||||
if (priv->client != NULL)
|
if (priv->client != NULL)
|
||||||
g_object_unref (priv->client);
|
g_object_unref (priv->client);
|
||||||
|
if (priv->soup_session != NULL)
|
||||||
|
g_object_unref (priv->soup_session);
|
||||||
g_main_loop_unref (priv->loop);
|
g_main_loop_unref (priv->loop);
|
||||||
g_object_unref (priv->cancellable);
|
g_object_unref (priv->cancellable);
|
||||||
g_object_unref (priv->progressbar);
|
g_object_unref (priv->progressbar);
|
||||||
|
Loading…
Reference in New Issue
Block a user