fetcher: Add "config-flags" construct-only property
A lot of effort here just to avoid touching SoupSession directly in ostree_fetcher_new(). The reason will become apparent in subsequent commits. Note this introduces generated enum/flags GTypes using glib-mkenums. I could have just made the property type as plain integer, but doing properties right will henceforth be easier now that the automake-fu is established.
This commit is contained in:
parent
96eed95720
commit
af30fc764a
|
|
@ -33,12 +33,37 @@ lib_LTLIBRARIES += libostree-1.la
|
|||
libostreeincludedir = $(includedir)/ostree-1
|
||||
libostreeinclude_HEADERS = $(libostree_public_headers)
|
||||
|
||||
ENUM_TYPES = \
|
||||
src/libostree/ostree-fetcher.h \
|
||||
$(NULL)
|
||||
|
||||
src/libostree/ostree-enumtypes.h: src/libostree/ostree-enumtypes.h.template $(ENUM_TYPES)
|
||||
$(AM_V_GEN) $(GLIB_MKENUMS) \
|
||||
--template src/libostree/ostree-enumtypes.h.template \
|
||||
$(ENUM_TYPES) > $@
|
||||
|
||||
src/libostree/ostree-enumtypes.c: src/libostree/ostree-enumtypes.c.template $(ENUM_TYPES)
|
||||
$(AM_V_GEN) $(GLIB_MKENUMS) \
|
||||
--template src/libostree/ostree-enumtypes.c.template \
|
||||
--fhead "#include \"ostree-enumtypes.h\"" \
|
||||
$(ENUM_TYPES) > $@
|
||||
|
||||
ENUM_GENERATED = \
|
||||
src/libostree/ostree-enumtypes.h \
|
||||
src/libostree/ostree-enumtypes.c \
|
||||
$(NULL)
|
||||
|
||||
BUILT_SOURCES += $(ENUM_GENERATED)
|
||||
|
||||
CLEANFILES += $(BUILT_SOURCES)
|
||||
|
||||
libbupsplit_la_SOURCES = \
|
||||
src/libostree/bupsplit.h \
|
||||
src/libostree/bupsplit.c \
|
||||
$(NULL)
|
||||
|
||||
libostree_1_la_SOURCES = \
|
||||
$(ENUM_GENERATED) \
|
||||
src/libostree/ostree-async-progress.c \
|
||||
src/libostree/ostree-cmdprivate.h \
|
||||
src/libostree/ostree-cmdprivate.c \
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ AS_IF([test "$YACC" = :], [AC_MSG_ERROR([bison not found but required])])
|
|||
|
||||
PKG_PROG_PKG_CONFIG
|
||||
|
||||
AM_PATH_GLIB_2_0
|
||||
|
||||
GIO_DEPENDENCY="gio-unix-2.0 >= 2.40.0 libgsystem >= 2015.1"
|
||||
PKG_CHECK_MODULES(OT_DEP_GIO_UNIX, $GIO_DEPENDENCY)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
/*** BEGIN file-header ***/
|
||||
/*
|
||||
* Copyright (C) 2015 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
/* enumerations from "@filename@" */
|
||||
#include "@filename@"
|
||||
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN value-header ***/
|
||||
GType
|
||||
@enum_name@_get_type (void)
|
||||
{
|
||||
static volatile gsize the_type__volatile = 0;
|
||||
|
||||
if (g_once_init_enter (&the_type__volatile))
|
||||
{
|
||||
static const G@Type@Value values[] = {
|
||||
/*** END value-header ***/
|
||||
|
||||
/*** BEGIN value-production ***/
|
||||
{ @VALUENAME@,
|
||||
"@VALUENAME@",
|
||||
"@valuenick@" },
|
||||
/*** END value-production ***/
|
||||
|
||||
/*** BEGIN value-tail ***/
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
GType the_type = g_@type@_register_static (
|
||||
g_intern_static_string ("@EnumName@"),
|
||||
values);
|
||||
|
||||
g_once_init_leave (&the_type__volatile, the_type);
|
||||
}
|
||||
|
||||
return the_type__volatile;
|
||||
}
|
||||
|
||||
/*** END value-tail ***/
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*** BEGIN file-header ***/
|
||||
/*
|
||||
* Copyright (C) 2015 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
#pragma once
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* Enumerations from "@filename@" */
|
||||
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN enumeration-production ***/
|
||||
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
|
||||
GType @enum_name@_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/*** END enumeration-production ***/
|
||||
|
||||
/*** BEGIN file-tail ***/
|
||||
G_END_DECLS
|
||||
|
||||
/*** END file-tail ***/
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
#ifdef HAVE_LIBSOUP_CLIENT_CERTS
|
||||
#include "ostree-tls-cert-interaction.h"
|
||||
#endif
|
||||
#include "ostree-enumtypes.h"
|
||||
#include "ostree.h"
|
||||
#include "ostree-repo-private.h"
|
||||
#include "otutil.h"
|
||||
|
|
@ -63,6 +64,7 @@ struct OstreeFetcher
|
|||
{
|
||||
GObject parent_instance;
|
||||
|
||||
OstreeFetcherConfigFlags config_flags;
|
||||
int tmpdir_dfd;
|
||||
char *tmpdir_name;
|
||||
GLnxLockFile tmpdir_lock;
|
||||
|
|
@ -83,6 +85,11 @@ struct OstreeFetcher
|
|||
gint max_outstanding;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CONFIG_FLAGS
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (OstreeFetcher, _ostree_fetcher, G_TYPE_OBJECT)
|
||||
|
||||
static int
|
||||
|
|
@ -111,6 +118,44 @@ pending_uri_free (OstreeFetcherPendingURI *pending)
|
|||
g_free (pending);
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeFetcher *self = OSTREE_FETCHER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONFIG_FLAGS:
|
||||
self->config_flags = g_value_get_flags (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
OstreeFetcher *self = OSTREE_FETCHER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONFIG_FLAGS:
|
||||
g_value_set_flags (value, self->config_flags);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_ostree_fetcher_finalize (GObject *object)
|
||||
{
|
||||
|
|
@ -147,7 +192,20 @@ _ostree_fetcher_class_init (OstreeFetcherClass *klass)
|
|||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
gobject_class->set_property = _ostree_fetcher_set_property;
|
||||
gobject_class->get_property = _ostree_fetcher_get_property;
|
||||
gobject_class->finalize = _ostree_fetcher_finalize;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_CONFIG_FLAGS,
|
||||
g_param_spec_flags ("config-flags",
|
||||
"",
|
||||
"",
|
||||
OSTREE_TYPE_FETCHER_CONFIG_FLAGS,
|
||||
OSTREE_FETCHER_FLAGS_NONE,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -175,6 +233,9 @@ _ostree_fetcher_init (OstreeFetcher *self)
|
|||
if (g_getenv ("OSTREE_DEBUG_HTTP"))
|
||||
soup_session_add_feature (self->session, (SoupSessionFeature*)soup_logger_new (SOUP_LOGGER_LOG_BODY, 500));
|
||||
|
||||
if ((self->config_flags & OSTREE_FETCHER_FLAGS_TLS_PERMISSIVE) > 0)
|
||||
g_object_set (self->session, SOUP_SESSION_SSL_STRICT, FALSE, NULL);
|
||||
|
||||
self->requester = (SoupRequester *)soup_session_get_feature (self->session, SOUP_TYPE_REQUESTER);
|
||||
g_object_get (self->session, "max-conns-per-host", &max_conns, NULL);
|
||||
if (max_conns <= 8)
|
||||
|
|
@ -202,7 +263,9 @@ _ostree_fetcher_new (int tmpdir_dfd,
|
|||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
OstreeFetcher *self = (OstreeFetcher*)g_object_new (OSTREE_TYPE_FETCHER, NULL);
|
||||
OstreeFetcher *self;
|
||||
|
||||
self = g_object_new (OSTREE_TYPE_FETCHER, "config-flags", flags, NULL);
|
||||
|
||||
if (!_ostree_repo_allocate_tmpdir (tmpdir_dfd,
|
||||
"fetcher-",
|
||||
|
|
@ -213,9 +276,7 @@ _ostree_fetcher_new (int tmpdir_dfd,
|
|||
cancellable, error))
|
||||
return NULL;
|
||||
|
||||
self->base_tmpdir_dfd = tmpdir_dfd;
|
||||
if ((flags & OSTREE_FETCHER_FLAGS_TLS_PERMISSIVE) > 0)
|
||||
g_object_set ((GObject*)self->session, "ssl-strict", FALSE, NULL);
|
||||
self->tmpdir_dfd = tmpdir_dfd;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue