|
rpm-build |
0fba15 |
/*
|
|
rpm-build |
0fba15 |
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* SPDX-License-Identifier: LGPL-2.0+
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is free software; you can redistribute it and/or
|
|
rpm-build |
0fba15 |
* modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License as published by the Free Software Foundation; either
|
|
rpm-build |
0fba15 |
* version 2 of the License, or (at your option) any later version.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0fba15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0fba15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0fba15 |
* Lesser General Public License for more details.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* You should have received a copy of the GNU Lesser General
|
|
rpm-build |
0fba15 |
* Public License along with this library; if not, write to the
|
|
rpm-build |
0fba15 |
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
rpm-build |
0fba15 |
* Boston, MA 02111-1307, USA.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "config.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "ostree-checksum-input-stream.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
enum {
|
|
rpm-build |
0fba15 |
PROP_0,
|
|
rpm-build |
0fba15 |
PROP_CHECKSUM
|
|
rpm-build |
0fba15 |
};
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
G_DEFINE_TYPE (OstreeChecksumInputStream, ostree_checksum_input_stream, G_TYPE_FILTER_INPUT_STREAM)
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
struct _OstreeChecksumInputStreamPrivate {
|
|
rpm-build |
0fba15 |
GChecksum *checksum;
|
|
rpm-build |
0fba15 |
};
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void ostree_checksum_input_stream_set_property (GObject *object,
|
|
rpm-build |
0fba15 |
guint prop_id,
|
|
rpm-build |
0fba15 |
const GValue *value,
|
|
rpm-build |
0fba15 |
GParamSpec *pspec);
|
|
rpm-build |
0fba15 |
static void ostree_checksum_input_stream_get_property (GObject *object,
|
|
rpm-build |
0fba15 |
guint prop_id,
|
|
rpm-build |
0fba15 |
GValue *value,
|
|
rpm-build |
0fba15 |
GParamSpec *pspec);
|
|
rpm-build |
0fba15 |
static gssize ostree_checksum_input_stream_read (GInputStream *stream,
|
|
rpm-build |
0fba15 |
void *buffer,
|
|
rpm-build |
0fba15 |
gsize count,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
ostree_checksum_input_stream_class_init (OstreeChecksumInputStreamClass *klass)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
rpm-build |
0fba15 |
GInputStreamClass *stream_class = G_INPUT_STREAM_CLASS (klass);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_type_class_add_private (klass, sizeof (OstreeChecksumInputStreamPrivate));
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
gobject_class->get_property = ostree_checksum_input_stream_get_property;
|
|
rpm-build |
0fba15 |
gobject_class->set_property = ostree_checksum_input_stream_set_property;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
stream_class->read_fn = ostree_checksum_input_stream_read;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/*
|
|
rpm-build |
0fba15 |
* OstreeChecksumInputStream:checksum:
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* The checksum that the stream updates.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
g_object_class_install_property (gobject_class,
|
|
rpm-build |
0fba15 |
PROP_CHECKSUM,
|
|
rpm-build |
0fba15 |
g_param_spec_pointer ("checksum",
|
|
rpm-build |
0fba15 |
"", "",
|
|
rpm-build |
0fba15 |
G_PARAM_READWRITE |
|
|
rpm-build |
0fba15 |
G_PARAM_CONSTRUCT_ONLY |
|
|
rpm-build |
0fba15 |
G_PARAM_STATIC_STRINGS));
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
ostree_checksum_input_stream_set_property (GObject *object,
|
|
rpm-build |
0fba15 |
guint prop_id,
|
|
rpm-build |
0fba15 |
const GValue *value,
|
|
rpm-build |
0fba15 |
GParamSpec *pspec)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
OstreeChecksumInputStream *self;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
self = OSTREE_CHECKSUM_INPUT_STREAM (object);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
switch (prop_id)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
case PROP_CHECKSUM:
|
|
rpm-build |
0fba15 |
self->priv->checksum = g_value_get_pointer (value);
|
|
rpm-build |
0fba15 |
break;
|
|
rpm-build |
0fba15 |
default:
|
|
rpm-build |
0fba15 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
rpm-build |
0fba15 |
break;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
ostree_checksum_input_stream_get_property (GObject *object,
|
|
rpm-build |
0fba15 |
guint prop_id,
|
|
rpm-build |
0fba15 |
GValue *value,
|
|
rpm-build |
0fba15 |
GParamSpec *pspec)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
OstreeChecksumInputStream *self;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
self = OSTREE_CHECKSUM_INPUT_STREAM (object);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
switch (prop_id)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
case PROP_CHECKSUM:
|
|
rpm-build |
0fba15 |
g_value_set_pointer (value, self->priv->checksum);
|
|
rpm-build |
0fba15 |
break;
|
|
rpm-build |
0fba15 |
default:
|
|
rpm-build |
0fba15 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
ostree_checksum_input_stream_init (OstreeChecksumInputStream *self)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
|
rpm-build |
0fba15 |
OSTREE_TYPE_CHECKSUM_INPUT_STREAM,
|
|
rpm-build |
0fba15 |
OstreeChecksumInputStreamPrivate);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
OstreeChecksumInputStream *
|
|
rpm-build |
0fba15 |
ostree_checksum_input_stream_new (GInputStream *base,
|
|
rpm-build |
0fba15 |
GChecksum *checksum)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
OstreeChecksumInputStream *stream;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_return_val_if_fail (G_IS_INPUT_STREAM (base), NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
stream = g_object_new (OSTREE_TYPE_CHECKSUM_INPUT_STREAM,
|
|
rpm-build |
0fba15 |
"base-stream", base,
|
|
rpm-build |
0fba15 |
"checksum", checksum,
|
|
rpm-build |
0fba15 |
NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return (OstreeChecksumInputStream*) (stream);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static gssize
|
|
rpm-build |
0fba15 |
ostree_checksum_input_stream_read (GInputStream *stream,
|
|
rpm-build |
0fba15 |
void *buffer,
|
|
rpm-build |
0fba15 |
gsize count,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
OstreeChecksumInputStream *self = (OstreeChecksumInputStream*) stream;
|
|
rpm-build |
0fba15 |
GFilterInputStream *fself = (GFilterInputStream*) self;
|
|
rpm-build |
0fba15 |
gssize res = -1;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (g_cancellable_set_error_if_cancelled (cancellable, error))
|
|
rpm-build |
0fba15 |
return -1;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
res = g_input_stream_read (fself->base_stream,
|
|
rpm-build |
0fba15 |
buffer,
|
|
rpm-build |
0fba15 |
count,
|
|
rpm-build |
0fba15 |
cancellable,
|
|
rpm-build |
0fba15 |
error);
|
|
rpm-build |
0fba15 |
if (res > 0)
|
|
rpm-build |
0fba15 |
g_checksum_update (self->priv->checksum, buffer, res);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return res;
|
|
rpm-build |
0fba15 |
}
|