2006-04-14 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / g10 / filter.h
blob12c5cebed6f9c1ea1e56c39ca57611e9e6efb634
1 /* filter.h
2 * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ifndef G10_FILTER_H
21 #define G10_FILTER_H
23 #include "types.h"
24 #include "cipher.h"
25 #include "iobuf.h"
27 typedef struct {
28 MD_HANDLE md; /* catch all */
29 MD_HANDLE md2; /* if we want to calculate an alternate hash */
30 size_t maxbuf_size;
31 } md_filter_context_t;
33 typedef struct {
34 /* these fields may be initialized */
35 int what; /* what kind of armor headers to write */
36 int only_keyblocks; /* skip all headers but ".... key block" */
37 const char *hdrlines; /* write these headerlines */
39 /* these fileds must be initialized to zero */
40 int no_openpgp_data; /* output flag: "No valid OpenPGP data found" */
42 /* the following fields must be initialized to zero */
43 int inp_checked; /* set if the input has been checked */
44 int inp_bypass; /* set if the input is not armored */
45 int in_cleartext; /* clear text message */
46 int not_dash_escaped; /* clear text is not dash escaped */
47 int hashes; /* detected hash algorithms */
48 int faked; /* we are faking a literal data packet */
49 int truncated; /* number of truncated lines */
50 int qp_detected;
51 int pgp2mode;
53 byte *buffer; /* malloced buffer */
54 unsigned buffer_size; /* and size of this buffer */
55 unsigned buffer_len; /* used length of the buffer */
56 unsigned buffer_pos; /* read position */
58 byte radbuf[4];
59 int idx, idx2;
60 u32 crc;
62 int status; /* an internal state flag */
63 int cancel;
64 int any_data; /* any valid armored data seen */
65 int pending_lf; /* used together with faked */
66 } armor_filter_context_t;
68 struct unarmor_pump_s;
69 typedef struct unarmor_pump_s *UnarmorPump;
72 struct compress_filter_context_s {
73 int status;
74 void *opaque; /* (used for z_stream) */
75 byte *inbuf;
76 unsigned inbufsize;
77 byte *outbuf;
78 unsigned outbufsize;
79 int algo; /* compress algo */
80 int algo1hack;
81 int new_ctb;
82 void (*release)(struct compress_filter_context_s*);
84 typedef struct compress_filter_context_s compress_filter_context_t;
87 typedef struct {
88 DEK *dek;
89 u32 datalen;
90 CIPHER_HANDLE cipher_hd;
91 int header;
92 MD_HANDLE mdc_hash;
93 byte enchash[20];
94 int create_mdc; /* flag will be set by the cipher filter */
95 } cipher_filter_context_t;
99 typedef struct {
100 byte *buffer; /* malloced buffer */
101 unsigned buffer_size; /* and size of this buffer */
102 unsigned buffer_len; /* used length of the buffer */
103 unsigned buffer_pos; /* read position */
104 int truncated; /* number of truncated lines */
105 int not_dash_escaped;
106 int escape_from;
107 MD_HANDLE md;
108 int pending_lf;
109 int pending_esc;
110 } text_filter_context_t;
113 typedef struct {
114 char *what; /* description */
115 u32 last_time; /* last time reported */
116 unsigned long last; /* last amount reported */
117 unsigned long offset; /* current amount */
118 unsigned long total; /* total amount */
119 } progress_filter_context_t;
121 /* encrypt_filter_context_t defined in main.h */
123 /*-- mdfilter.c --*/
124 int md_filter( void *opaque, int control, iobuf_t a, byte *buf, size_t *ret_len);
125 void free_md_filter_context( md_filter_context_t *mfx );
127 /*-- armor.c --*/
128 int use_armor_filter( iobuf_t a );
129 int armor_filter( void *opaque, int control,
130 iobuf_t chain, byte *buf, size_t *ret_len);
131 UnarmorPump unarmor_pump_new (void);
132 void unarmor_pump_release (UnarmorPump x);
133 int unarmor_pump (UnarmorPump x, int c);
135 /*-- compress.c --*/
136 int compress_filter( void *opaque, int control,
137 iobuf_t chain, byte *buf, size_t *ret_len);
139 /*-- cipher.c --*/
140 int cipher_filter( void *opaque, int control,
141 iobuf_t chain, byte *buf, size_t *ret_len);
143 /*-- textfilter.c --*/
144 int text_filter( void *opaque, int control,
145 iobuf_t chain, byte *buf, size_t *ret_len);
146 int copy_clearsig_text( iobuf_t out, iobuf_t inp, MD_HANDLE md,
147 int escape_dash, int escape_from, int pgp2mode );
149 /*-- progress.c --*/
150 int progress_filter (void *opaque, int control,
151 iobuf_t a, byte *buf, size_t *ret_len);
152 void handle_progress (progress_filter_context_t *pfx,
153 iobuf_t inp, const char *name);
155 #endif /*G10_FILTER_H*/