mirror of
https://git.proxmox.com/git/fwupd
synced 2025-07-27 09:46:25 +00:00
trivial: Move getting the SoupSession to common code
This commit is contained in:
parent
c77e111449
commit
7120667ccd
@ -415,3 +415,48 @@ fu_util_cmd_array_to_string (GPtrArray *array)
|
|||||||
|
|
||||||
return g_string_free (string, FALSE);
|
return g_string_free (string, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SoupSession *
|
||||||
|
fu_util_setup_networking (GError **error)
|
||||||
|
{
|
||||||
|
const gchar *http_proxy;
|
||||||
|
g_autofree gchar *user_agent = NULL;
|
||||||
|
g_autoptr(SoupSession) session = NULL;
|
||||||
|
|
||||||
|
/* create the soup session */
|
||||||
|
user_agent = fwupd_build_user_agent (PACKAGE_NAME, PACKAGE_VERSION);
|
||||||
|
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 NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set the proxy */
|
||||||
|
http_proxy = g_getenv ("https_proxy");
|
||||||
|
if (http_proxy == NULL)
|
||||||
|
http_proxy = g_getenv ("HTTPS_PROXY");
|
||||||
|
if (http_proxy == NULL)
|
||||||
|
http_proxy = g_getenv ("http_proxy");
|
||||||
|
if (http_proxy == NULL)
|
||||||
|
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);
|
||||||
|
return g_steal_pointer (&session);
|
||||||
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <fwupd.h>
|
#include <fwupd.h>
|
||||||
|
#include <libsoup/soup.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ gboolean fu_util_prompt_for_boolean (gboolean def);
|
|||||||
gboolean fu_util_print_device_tree (GNode *n, gpointer data);
|
gboolean fu_util_print_device_tree (GNode *n, gpointer data);
|
||||||
gboolean fu_util_is_interesting_device (FwupdDevice *dev);
|
gboolean fu_util_is_interesting_device (FwupdDevice *dev);
|
||||||
gchar *fu_util_get_user_cache_path (const gchar *fn);
|
gchar *fu_util_get_user_cache_path (const gchar *fn);
|
||||||
|
SoupSession *fu_util_setup_networking (GError **error);
|
||||||
|
|
||||||
gchar *fu_util_get_versions (void);
|
gchar *fu_util_get_versions (void);
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include <json-glib/json-glib.h>
|
#include <json-glib/json-glib.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <libsoup/soup.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "fu-history.h"
|
#include "fu-history.h"
|
||||||
@ -182,54 +181,6 @@ 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 ("https_proxy");
|
|
||||||
if (http_proxy == NULL)
|
|
||||||
http_proxy = g_getenv ("HTTPS_PROXY");
|
|
||||||
if (http_proxy == NULL)
|
|
||||||
http_proxy = g_getenv ("http_proxy");
|
|
||||||
if (http_proxy == NULL)
|
|
||||||
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_perhaps_show_unreported (FuUtilPrivate *priv, GError **error)
|
fu_util_perhaps_show_unreported (FuUtilPrivate *priv, GError **error)
|
||||||
{
|
{
|
||||||
@ -860,8 +811,11 @@ fu_util_report_history (FuUtilPrivate *priv, gchar **values, GError **error)
|
|||||||
g_autoptr(GPtrArray) remotes = NULL;
|
g_autoptr(GPtrArray) remotes = NULL;
|
||||||
|
|
||||||
/* set up networking */
|
/* set up networking */
|
||||||
if (!fu_util_setup_networking (priv, error))
|
if (priv->soup_session == NULL) {
|
||||||
return FALSE;
|
priv->soup_session = fu_util_setup_networking (error);
|
||||||
|
if (priv->soup_session == NULL)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* create a map of RemoteID to RemoteURI */
|
/* create a map of RemoteID to RemoteURI */
|
||||||
remotes = fwupd_client_get_remotes (priv->client, NULL, error);
|
remotes = fwupd_client_get_remotes (priv->client, NULL, error);
|
||||||
@ -1143,8 +1097,11 @@ fu_util_download_file (FuUtilPrivate *priv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set up networking */
|
/* set up networking */
|
||||||
if (!fu_util_setup_networking (priv, error))
|
if (priv->soup_session == NULL) {
|
||||||
return FALSE;
|
priv->soup_session = fu_util_setup_networking (error);
|
||||||
|
if (priv->soup_session == NULL)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* download data */
|
/* download data */
|
||||||
uri_str = soup_uri_to_string (uri, FALSE);
|
uri_str = soup_uri_to_string (uri, FALSE);
|
||||||
|
Loading…
Reference in New Issue
Block a user