~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to crypto/bio/b_dump.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2005-12-13 21:37:42 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051213213742-d0ydaylf80l16bj1
Tags: upstream-0.9.8a
ImportĀ upstreamĀ versionĀ 0.9.8a

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 
63
63
#include <stdio.h>
64
64
#include "cryptlib.h"
65
 
#include <openssl/bio.h>
 
65
#include "bio_lcl.h"
66
66
 
67
67
#define TRUNCATE
68
68
#define DUMP_WIDTH      16
69
69
#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
70
70
 
71
 
int BIO_dump(BIO *bio, const char *s, int len)
 
71
int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
 
72
        void *u, const char *s, int len)
72
73
        {
73
 
        return BIO_dump_indent(bio, s, len, 0);
 
74
        return BIO_dump_indent_cb(cb, u, s, len, 0);
74
75
        }
75
76
 
76
 
int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
 
77
int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
 
78
        void *u, const char *s, int len, int indent)
77
79
        {
78
80
        int ret=0;
79
81
        char buf[288+1],tmp[20],str[128+1];
80
 
        int i,j,rows,trunc;
 
82
        int i,j,rows,trc;
81
83
        unsigned char ch;
82
84
        int dump_width;
83
 
        
84
 
        trunc=0;
85
 
        
 
85
 
 
86
        trc=0;
 
87
 
86
88
#ifdef TRUNCATE
87
 
        for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) 
88
 
                trunc++;
 
89
        for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
 
90
                trc++;
89
91
#endif
90
92
 
91
93
        if (indent < 0)
96
98
                memset(str,' ',indent);
97
99
                }
98
100
        str[indent]='\0';
99
 
        
 
101
 
100
102
        dump_width=DUMP_WIDTH_LESS_INDENT(indent);
101
103
        rows=(len/dump_width);
102
104
        if ((rows*dump_width)<len)
117
119
                                {
118
120
                                ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
119
121
                                BIO_snprintf(tmp,sizeof tmp,"%02x%c",ch,
120
 
                                         j==7?'-':' ');
 
122
                                        j==7?'-':' ');
121
123
                                BUF_strlcat(buf,tmp,sizeof buf);
122
124
                                }
123
125
                        }
129
131
                        ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
130
132
#ifndef CHARSET_EBCDIC
131
133
                        BIO_snprintf(tmp,sizeof tmp,"%c",
132
 
                                 ((ch>=' ')&&(ch<='~'))?ch:'.');
 
134
                                ((ch>=' ')&&(ch<='~'))?ch:'.');
133
135
#else
134
136
                        BIO_snprintf(tmp,sizeof tmp,"%c",
135
 
                                 ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
136
 
                                 ? os_toebcdic[ch]
137
 
                                 : '.');
 
137
                                ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
 
138
                                ? os_toebcdic[ch]
 
139
                                : '.');
138
140
#endif
139
141
                        BUF_strlcat(buf,tmp,sizeof buf);
140
142
                        }
141
143
                BUF_strlcat(buf,"\n",sizeof buf);
142
 
                /* if this is the last call then update the ddt_dump thing so that
143
 
                 * we will move the selection point in the debug window 
 
144
                /* if this is the last call then update the ddt_dump thing so
 
145
                 * that we will move the selection point in the debug window
144
146
                 */
145
 
                ret+=BIO_write(bio,(char *)buf,strlen(buf));
 
147
                ret+=cb((void *)buf,strlen(buf),u);
146
148
                }
147
149
#ifdef TRUNCATE
148
 
        if (trunc > 0)
 
150
        if (trc > 0)
149
151
                {
150
152
                BIO_snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
151
 
                         len+trunc);
152
 
                ret+=BIO_write(bio,(char *)buf,strlen(buf));
 
153
                        len+trc);
 
154
                ret+=cb((void *)buf,strlen(buf),u);
153
155
                }
154
156
#endif
155
157
        return(ret);
156
158
        }
 
159
 
 
160
#ifndef OPENSSL_NO_FP_API
 
161
static int write_fp(const void *data, size_t len, void *fp)
 
162
        {
 
163
        return UP_fwrite(data, len, 1, fp);
 
164
        }
 
165
int BIO_dump_fp(FILE *fp, const char *s, int len)
 
166
        {
 
167
        return BIO_dump_cb(write_fp, fp, s, len);
 
168
        }
 
169
int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
 
170
        {
 
171
        return BIO_dump_indent_cb(write_fp, fp, s, len, indent);
 
172
        }
 
173
#endif
 
174
 
 
175
static int write_bio(const void *data, size_t len, void *bp)
 
176
        {
 
177
        return BIO_write((BIO *)bp, (const char *)data, len);
 
178
        }
 
179
int BIO_dump(BIO *bp, const char *s, int len)
 
180
        {
 
181
        return BIO_dump_cb(write_bio, bp, s, len);
 
182
        }
 
183
int BIO_dump_indent(BIO *bp, const char *s, int len, int indent)
 
184
        {
 
185
        return BIO_dump_indent_cb(write_bio, bp, s, len, indent);
 
186
        }
 
187