aboutsummaryrefslogtreecommitdiffstats
path: root/g10/compressed.c
blob: cc0eafcfa612e5231d4d5b72263ace755154e154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* compressed.c -  process an compressed packet
 *	Copyright (c) 1997 by Werner Koch (dd9jn)
 *
 * This file is part of G10.
 *
 * G10 is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * G10 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
/*#include <zlib.h>*/
#include "util.h"
#include "memory.h"
#include "packet.h"


/****************
 * Handle a compressed packet
 */
int
handle_compressed( PKT_compressed *zd )
{
  return -1;
  #if 0
    int c, zrc, rc = 0;
    z_stream *zs = NULL;
    unsigned inbufsize = 4096;
    unsigned outbufsize = 16384;
    unsigned n;
    byte *inbuf = NULL;
    byte *outbuf = NULL;

    if( zd->algorithm != 1 ) {
	rc =G10ERR_COMPR_ALGO;
	goto leave;
    }

    zs = m_alloc_clear( sizeof *zs );
    if( (zrc = inflateInit( zs )) != Z_OK ) {
	log_fatal("zlib problem: %s\n", zs->msg? zs->msg :
			      zrc == Z_MEM_ERROR ? "out of core" :
			      zrc == Z_VERSION_ERROR ? "invalid lib version" :
						       "unknown error" );
    }

    inbuf = m_alloc( inbufsize );
    outbuf = m_alloc( outbufsize ); /* Fixme: put it in secure space? */

    zs->next_in = inbuf;
    zs->avail_in = inbufsize;
    zs->next_out = outbuf;
    zs->avail_out = outbufsize;

    n = 0;
    inbuf[n++] = 0x58;
    inbuf[n++] = 0x09;
    for(; n < inbufsize && (c=iobuf_get(zd->buf)) != -1 ; n++ )
	inbuf[n] = c;
    if( n ) {
	{ int i;
	  printf("start of compressed packet (n=%u):\n", n);
	  for(i=0; i < 32 && i < n; i++ )
	    printf(" %02x", inbuf[i] );
	  putchar('\n');
	}
	zrc = inflate( zs, Z_PARTIAL_FLUSH );
	switch( zrc ) {
	  case Z_OK:
	    log_info("inflate returned okay\n");
	    break;
	  case Z_STREAM_END:
	    log_info("inflate returned stream-end\n");
	    break;
	  case Z_NEED_DICT:
	  case Z_DATA_ERROR:
	  case Z_STREAM_ERROR:
	  case Z_MEM_ERROR:
	  case Z_BUF_ERROR:
	  default:
	    if( zs->msg )
		log_error("zlib inflate problem: %s\n", zs->msg );
	    else
		log_error("zlib inflate problem: rc=%d\n", zrc );
	    break;
	}
    }

  leave:
    if( zs ) {
	inflateEnd(zs);
	m_free(zs);
    }
    m_free(inbuf);
    m_free(outbuf);
    return rc;
  #endif
}