1 /* plaintext.c - process an plaintext packet
2 * Copyright (c) 1997 by Werner Koch (dd9jn)
4 * This file is part of G10.
6 * G10 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 * G10 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
35 * Handle a plaintext packet. If MFX is not NULL, update the MDs
36 * Note: we should use the filter stuff here, but we have to add some
37 * easy mimic to set a read limit, so we calculate only the
38 * bytes from the plaintext.
41 handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx )
48 /* create the filename as C string */
50 fname = m_alloc( strlen( opt.outfile ) + 1);
51 strcpy(fname, opt.outfile );
54 fname = m_alloc( pt->namelen +1 );
55 memcpy( fname, pt->name, pt->namelen );
56 fname[pt->namelen] = 0;
59 if( !*fname ) { /* no filename given */
60 if( opt.outfile_is_stdout )
63 log_error("no outputfile given\n");
67 else if( overwrite_filep( fname ) )
72 else if( !(fp = fopen(fname,"wb")) ) {
73 log_error("Error creating '%s': %s\n", fname, strerror(errno) );
74 rc = G10ERR_WRITE_FILE;
79 for( ; pt->len; pt->len-- ) {
80 if( (c = iobuf_get(pt->buf)) == -1 ) {
81 log_error("Problem reading source\n");
82 rc = G10ERR_READ_FILE;
86 rmd160_putchar(mfx->rmd160, c );
88 md5_putchar(mfx->md5, c );
89 if( putc( c, fp ) == EOF ) {
90 log_error("Error writing to '%s': %s\n", fname, strerror(errno) );
91 rc = G10ERR_WRITE_FILE;
97 while( (c = iobuf_get(pt->buf)) != -1 ) {
99 rmd160_putchar(mfx->rmd160, c );
101 md5_putchar(mfx->md5, c );
102 if( putc( c, fp ) == EOF ) {
103 log_error("Error writing to '%s': %s\n",
104 fname, strerror(errno) );
105 rc = G10ERR_WRITE_FILE;
109 iobuf_clear_eof(pt->buf);
112 if( fp && fp != stdout && fclose(fp) ) {
113 log_error("Error closing '%s': %s\n", fname, strerror(errno) );
115 rc = G10ERR_WRITE_FILE;
121 if( fp && fp != stdout )