|
Packit Service |
392537 |
/*
|
|
Packit Service |
392537 |
* Amanda, The Advanced Maryland Automatic Network Disk Archiver
|
|
Packit Service |
392537 |
* Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
|
|
Packit Service |
392537 |
* Copyright (c) 2013-2016 Carbonite, Inc. All Rights Reserved.
|
|
Packit Service |
392537 |
*
|
|
Packit Service |
392537 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
392537 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
392537 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
392537 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
392537 |
*
|
|
Packit Service |
392537 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit Service |
392537 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit Service |
392537 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit Service |
392537 |
* for more details.
|
|
Packit Service |
392537 |
*
|
|
Packit Service |
392537 |
* You should have received a copy of the GNU General Public License along
|
|
Packit Service |
392537 |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit Service |
392537 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
Packit Service |
392537 |
*
|
|
Packit Service |
392537 |
* Contact information: Carbonite Inc., 756 N Pastoria Ave
|
|
Packit Service |
392537 |
* Sunnyvale, CA 94085, or: http://www.zmanda.com
|
|
Packit Service |
392537 |
*/
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
#include "amanda.h"
|
|
Packit Service |
392537 |
#include "amxfer.h"
|
|
Packit Service |
392537 |
#include "simpleprng.h"
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
/*
|
|
Packit Service |
392537 |
* Class declaration
|
|
Packit Service |
392537 |
*
|
|
Packit Service |
392537 |
* This declaration is entirely private; nothing but xfer_dest_null() references
|
|
Packit Service |
392537 |
* it directly.
|
|
Packit Service |
392537 |
*/
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
GType xfer_dest_null_get_type(void);
|
|
Packit Service |
392537 |
#define XFER_DEST_NULL_TYPE (xfer_dest_null_get_type())
|
|
Packit Service |
392537 |
#define XFER_DEST_NULL(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_dest_null_get_type(), XferDestNull)
|
|
Packit Service |
392537 |
#define XFER_DEST_NULL_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_dest_null_get_type(), XferDestNull const)
|
|
Packit Service |
392537 |
#define XFER_DEST_NULL_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), xfer_dest_null_get_type(), XferDestNullClass)
|
|
Packit Service |
392537 |
#define IS_XFER_DEST_NULL(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), xfer_dest_null_get_type ())
|
|
Packit Service |
392537 |
#define XFER_DEST_NULL_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), xfer_dest_null_get_type(), XferDestNullClass)
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
static GObjectClass *parent_class = NULL;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
/*
|
|
Packit Service |
392537 |
* Main object structure
|
|
Packit Service |
392537 |
*/
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
typedef struct XferDestNull {
|
|
Packit Service |
392537 |
XferElement __parent__;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
gboolean sent_info;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
gboolean do_verify;
|
|
Packit Service |
392537 |
simpleprng_state_t prng;
|
|
Packit Service |
392537 |
guint64 byte_position;
|
|
Packit Service |
392537 |
} XferDestNull;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
/*
|
|
Packit Service |
392537 |
* Class definition
|
|
Packit Service |
392537 |
*/
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
typedef struct {
|
|
Packit Service |
392537 |
XferElementClass __parent__;
|
|
Packit Service |
392537 |
} XferDestNullClass;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
/*
|
|
Packit Service |
392537 |
* Implementation
|
|
Packit Service |
392537 |
*/
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
static void
|
|
Packit Service |
392537 |
push_buffer_impl(
|
|
Packit Service |
392537 |
XferElement *elt,
|
|
Packit Service |
392537 |
gpointer buf,
|
|
Packit Service |
392537 |
size_t len)
|
|
Packit Service |
392537 |
{
|
|
Packit Service |
392537 |
XferDestNull *self = (XferDestNull *)elt;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
if (buf) {
|
|
Packit Service |
392537 |
crc32_add(buf, len, &elt->crc);
|
|
Packit Service |
392537 |
} else {
|
|
Packit Service |
392537 |
XMsg *msg = xmsg_new((XferElement *)self, XMSG_CRC, 0);
|
|
Packit Service |
392537 |
msg->crc = crc32_finish(&elt->crc);
|
|
Packit Service |
392537 |
msg->size = elt->crc.size;
|
|
Packit Service |
392537 |
xfer_queue_message(XFER_ELEMENT(self)->xfer, msg);
|
|
Packit Service |
392537 |
return;
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
if (self->do_verify && !elt->cancelled) {
|
|
Packit Service |
392537 |
if (!simpleprng_verify_buffer(&self->prng, buf, len)) {
|
|
Packit Service |
392537 |
xfer_cancel_with_error(elt,
|
|
Packit Service |
392537 |
"verification of incoming bytestream failed; see stderr for details"),
|
|
Packit Service |
392537 |
wait_until_xfer_cancelled(elt->xfer);
|
|
Packit Service |
392537 |
amfree(buf);
|
|
Packit Service |
392537 |
return;
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
self->byte_position += len;
|
|
Packit Service |
392537 |
if (!self->sent_info) {
|
|
Packit Service |
392537 |
/* send a superfluous message (this is a testing XferElement,
|
|
Packit Service |
392537 |
* after all) */
|
|
Packit Service |
392537 |
XMsg *msg = xmsg_new((XferElement *)self, XMSG_INFO, 0);
|
|
Packit Service |
392537 |
msg->message = g_strdup("Is this thing on?");
|
|
Packit Service |
392537 |
xfer_queue_message(XFER_ELEMENT(self)->xfer, msg);
|
|
Packit Service |
392537 |
self->sent_info = TRUE;
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
amfree(buf);
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
static void
|
|
Packit Service |
392537 |
push_buffer_static_impl(
|
|
Packit Service |
392537 |
XferElement *elt,
|
|
Packit Service |
392537 |
gpointer buf,
|
|
Packit Service |
392537 |
size_t len)
|
|
Packit Service |
392537 |
{
|
|
Packit Service |
392537 |
XferDestNull *self = (XferDestNull *)elt;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
if (buf && len != 0) {
|
|
Packit Service |
392537 |
crc32_add(buf, len, &elt->crc);
|
|
Packit Service |
392537 |
} else {
|
|
Packit Service |
392537 |
XMsg *msg = xmsg_new((XferElement *)self, XMSG_CRC, 0);
|
|
Packit Service |
392537 |
msg->crc = crc32_finish(&elt->crc);
|
|
Packit Service |
392537 |
msg->size = elt->crc.size;
|
|
Packit Service |
392537 |
xfer_queue_message(XFER_ELEMENT(self)->xfer, msg);
|
|
Packit Service |
392537 |
return;
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
if (self->do_verify && !elt->cancelled) {
|
|
Packit Service |
392537 |
if (!simpleprng_verify_buffer(&self->prng, buf, len)) {
|
|
Packit Service |
392537 |
xfer_cancel_with_error(elt,
|
|
Packit Service |
392537 |
"verification of incoming bytestream failed; see stderr for details"),
|
|
Packit Service |
392537 |
wait_until_xfer_cancelled(elt->xfer);
|
|
Packit Service |
392537 |
return;
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
self->byte_position += len;
|
|
Packit Service |
392537 |
if (!self->sent_info) {
|
|
Packit Service |
392537 |
/* send a superfluous message (this is a testing XferElement,
|
|
Packit Service |
392537 |
* after all) */
|
|
Packit Service |
392537 |
XMsg *msg = xmsg_new((XferElement *)self, XMSG_INFO, 0);
|
|
Packit Service |
392537 |
msg->message = g_strdup("Is this thing on?");
|
|
Packit Service |
392537 |
xfer_queue_message(XFER_ELEMENT(self)->xfer, msg);
|
|
Packit Service |
392537 |
self->sent_info = TRUE;
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
static void
|
|
Packit Service |
392537 |
class_init(
|
|
Packit Service |
392537 |
XferDestNullClass * selfc)
|
|
Packit Service |
392537 |
{
|
|
Packit Service |
392537 |
XferElementClass *klass = XFER_ELEMENT_CLASS(selfc);
|
|
Packit Service |
392537 |
static xfer_element_mech_pair_t mech_pairs[] = {
|
|
Packit Service |
392537 |
{ XFER_MECH_PUSH_BUFFER, XFER_MECH_NONE, XFER_NROPS(0), XFER_NTHREADS(0), XFER_NALLOC(0) },
|
|
Packit Service |
392537 |
{ XFER_MECH_PUSH_BUFFER_STATIC, XFER_MECH_NONE, XFER_NROPS(0), XFER_NTHREADS(0), XFER_NALLOC(0) },
|
|
Packit Service |
392537 |
{ XFER_MECH_NONE, XFER_MECH_NONE, XFER_NROPS(0), XFER_NTHREADS(0), XFER_NALLOC(0) },
|
|
Packit Service |
392537 |
};
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
klass->push_buffer = push_buffer_impl;
|
|
Packit Service |
392537 |
klass->push_buffer_static = push_buffer_static_impl;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
klass->perl_class = "Amanda::Xfer::Dest::Null";
|
|
Packit Service |
392537 |
klass->mech_pairs = mech_pairs;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
parent_class = g_type_class_peek_parent(selfc);
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
GType
|
|
Packit Service |
392537 |
xfer_dest_null_get_type (void)
|
|
Packit Service |
392537 |
{
|
|
Packit Service |
392537 |
static GType type = 0;
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
if (G_UNLIKELY(type == 0)) {
|
|
Packit Service |
392537 |
static const GTypeInfo info = {
|
|
Packit Service |
392537 |
sizeof (XferDestNullClass),
|
|
Packit Service |
392537 |
(GBaseInitFunc) NULL,
|
|
Packit Service |
392537 |
(GBaseFinalizeFunc) NULL,
|
|
Packit Service |
392537 |
(GClassInitFunc) class_init,
|
|
Packit Service |
392537 |
(GClassFinalizeFunc) NULL,
|
|
Packit Service |
392537 |
NULL /* class_data */,
|
|
Packit Service |
392537 |
sizeof (XferDestNull),
|
|
Packit Service |
392537 |
0 /* n_preallocs */,
|
|
Packit Service |
392537 |
(GInstanceInitFunc) NULL,
|
|
Packit Service |
392537 |
NULL
|
|
Packit Service |
392537 |
};
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
type = g_type_register_static (XFER_ELEMENT_TYPE, "XferDestNull", &info, 0);
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
return type;
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
/* create an element of this class; prototype is in xfer-element.h */
|
|
Packit Service |
392537 |
XferElement *
|
|
Packit Service |
392537 |
xfer_dest_null(
|
|
Packit Service |
392537 |
guint32 prng_seed)
|
|
Packit Service |
392537 |
{
|
|
Packit Service |
392537 |
XferDestNull *self = (XferDestNull *)g_object_new(XFER_DEST_NULL_TYPE, NULL);
|
|
Packit Service |
392537 |
XferElement *elt = XFER_ELEMENT(self);
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
if (prng_seed) {
|
|
Packit Service |
392537 |
self->do_verify = TRUE;
|
|
Packit Service |
392537 |
simpleprng_seed(&self->prng, prng_seed);
|
|
Packit Service |
392537 |
} else {
|
|
Packit Service |
392537 |
self->do_verify = FALSE;
|
|
Packit Service |
392537 |
}
|
|
Packit Service |
392537 |
crc32_init(&elt->crc);
|
|
Packit Service |
392537 |
|
|
Packit Service |
392537 |
return elt;
|
|
Packit Service |
392537 |
}
|