2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 2008,2009 Zmanda, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
28 * This declaration is entirely private; nothing but xfer_filter_xor() references
32 GType xfer_filter_xor_get_type(void);
33 #define XFER_FILTER_XOR_TYPE (xfer_filter_xor_get_type())
34 #define XFER_FILTER_XOR(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_filter_xor_get_type(), XferFilterXor)
35 #define XFER_FILTER_XOR_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_filter_xor_get_type(), XferFilterXor const)
36 #define XFER_FILTER_XOR_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), xfer_filter_xor_get_type(), XferFilterXorClass)
37 #define IS_XFER_FILTER_XOR(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), xfer_filter_xor_get_type ())
38 #define XFER_FILTER_XOR_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), xfer_filter_xor_get_type(), XferFilterXorClass)
40 static GObjectClass *parent_class = NULL;
43 * Main object structure
46 typedef struct XferFilterXor {
47 XferElement __parent__;
57 XferElementClass __parent__;
73 /* Apply XOR. This is a pretty sophisticated encryption algorithm! */
74 for (i = 0; i < len; i++) {
88 XferFilterXor *self = (XferFilterXor *)elt;
92 /* drain our upstream only if we're expecting an EOF */
93 if (elt->expect_eof) {
94 xfer_element_drain_buffers(XFER_ELEMENT(self)->upstream);
102 /* get a buffer from upstream, xor it, and hand it back */
103 buf = xfer_element_pull_buffer(XFER_ELEMENT(self)->upstream, size);
105 apply_xor(buf, *size, self->xor_key);
115 XferFilterXor *self = (XferFilterXor *)elt;
117 /* drop the buffer if we've been cancelled */
118 if (elt->cancelled) {
123 /* xor the given buffer and pass it downstream */
125 apply_xor(buf, len, self->xor_key);
127 xfer_element_push_buffer(XFER_ELEMENT(self)->downstream, buf, len);
134 elt->can_generate_eof = TRUE;
139 XferFilterXorClass * selfc)
141 XferElementClass *klass = XFER_ELEMENT_CLASS(selfc);
142 static xfer_element_mech_pair_t mech_pairs[] = {
143 { XFER_MECH_PULL_BUFFER, XFER_MECH_PULL_BUFFER, XFER_NROPS(1), XFER_NTHREADS(0) },
144 { XFER_MECH_PUSH_BUFFER, XFER_MECH_PUSH_BUFFER, XFER_NROPS(1), XFER_NTHREADS(0) },
145 { XFER_MECH_NONE, XFER_MECH_NONE, XFER_NROPS(0), XFER_NTHREADS(0) },
148 klass->push_buffer = push_buffer_impl;
149 klass->pull_buffer = pull_buffer_impl;
151 klass->perl_class = "Amanda::Xfer::Filter::Xor";
152 klass->mech_pairs = mech_pairs;
154 parent_class = g_type_class_peek_parent(selfc);
158 xfer_filter_xor_get_type (void)
160 static GType type = 0;
162 if G_UNLIKELY(type == 0) {
163 static const GTypeInfo info = {
164 sizeof (XferFilterXorClass),
165 (GBaseInitFunc) NULL,
166 (GBaseFinalizeFunc) NULL,
167 (GClassInitFunc) class_init,
168 (GClassFinalizeFunc) NULL,
169 NULL /* class_data */,
170 sizeof (XferFilterXor),
172 (GInstanceInitFunc) instance_init,
176 type = g_type_register_static (XFER_ELEMENT_TYPE, "XferFilterXor", &info, 0);
182 /* create an element of this class; prototype is in xfer-element.h */
185 unsigned char xor_key)
187 XferFilterXor *xfx = (XferFilterXor *)g_object_new(XFER_FILTER_XOR_TYPE, NULL);
188 XferElement *elt = XFER_ELEMENT(xfx);
190 xfx->xor_key = xor_key;