diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libtls/tls_bio_cb.c | 73 |
1 files changed, 7 insertions, 66 deletions
diff --git a/src/lib/libtls/tls_bio_cb.c b/src/lib/libtls/tls_bio_cb.c index f53039fa00..75d9685cb3 100644 --- a/src/lib/libtls/tls_bio_cb.c +++ b/src/lib/libtls/tls_bio_cb.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_bio_cb.c,v 1.16 2017/01/12 16:01:47 jsing Exp $ */ | 1 | /* $OpenBSD: tls_bio_cb.c,v 1.17 2017/01/12 16:08:49 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2016 Tobias Pape <tobias@netshed.de> | 3 | * Copyright (c) 2016 Tobias Pape <tobias@netshed.de> |
4 | * | 4 | * |
@@ -28,14 +28,6 @@ static int bio_cb_write(BIO *bio, const char *buf, int num); | |||
28 | static int bio_cb_read(BIO *bio, char *buf, int size); | 28 | static int bio_cb_read(BIO *bio, char *buf, int size); |
29 | static int bio_cb_puts(BIO *bio, const char *str); | 29 | static int bio_cb_puts(BIO *bio, const char *str); |
30 | static long bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr); | 30 | static long bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr); |
31 | static int bio_cb_new(BIO *bio); | ||
32 | static int bio_cb_free(BIO *bio); | ||
33 | |||
34 | struct bio_cb { | ||
35 | int (*write_cb)(BIO *bio, const char *buf, int num, void *cb_arg); | ||
36 | int (*read_cb)(BIO *bio, char *buf, int size, void *cb_arg); | ||
37 | void *cb_arg; | ||
38 | }; | ||
39 | 31 | ||
40 | static BIO_METHOD bio_cb_method = { | 32 | static BIO_METHOD bio_cb_method = { |
41 | .type = BIO_TYPE_MEM, | 33 | .type = BIO_TYPE_MEM, |
@@ -44,8 +36,6 @@ static BIO_METHOD bio_cb_method = { | |||
44 | .bread = bio_cb_read, | 36 | .bread = bio_cb_read, |
45 | .bputs = bio_cb_puts, | 37 | .bputs = bio_cb_puts, |
46 | .ctrl = bio_cb_ctrl, | 38 | .ctrl = bio_cb_ctrl, |
47 | .create = bio_cb_new, | ||
48 | .destroy = bio_cb_free, | ||
49 | }; | 39 | }; |
50 | 40 | ||
51 | static BIO_METHOD * | 41 | static BIO_METHOD * |
@@ -55,52 +45,6 @@ bio_s_cb(void) | |||
55 | } | 45 | } |
56 | 46 | ||
57 | static int | 47 | static int |
58 | bio_cb_new(BIO *bio) | ||
59 | { | ||
60 | struct bio_cb *bcb; | ||
61 | |||
62 | if ((bcb = calloc(1, sizeof(struct bio_cb))) == NULL) | ||
63 | return (0); | ||
64 | |||
65 | bio->shutdown = 1; | ||
66 | bio->init = 1; | ||
67 | bio->num = -1; | ||
68 | bio->ptr = bcb; | ||
69 | |||
70 | return (1); | ||
71 | } | ||
72 | |||
73 | static int | ||
74 | bio_cb_free(BIO *bio) | ||
75 | { | ||
76 | if (bio == NULL) | ||
77 | return (0); | ||
78 | |||
79 | if (bio->shutdown) { | ||
80 | if ((bio->init) && (bio->ptr != NULL)) { | ||
81 | free(bio->ptr); | ||
82 | bio->ptr = NULL; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | return (1); | ||
87 | } | ||
88 | |||
89 | static int | ||
90 | bio_cb_read(BIO *bio, char *buf, int size) | ||
91 | { | ||
92 | struct bio_cb *bcb = bio->ptr; | ||
93 | return (bcb->read_cb(bio, buf, size, bcb->cb_arg)); | ||
94 | } | ||
95 | |||
96 | static int | ||
97 | bio_cb_write(BIO *bio, const char *buf, int num) | ||
98 | { | ||
99 | struct bio_cb *bcb = bio->ptr; | ||
100 | return (bcb->write_cb(bio, buf, num, bcb->cb_arg)); | ||
101 | } | ||
102 | |||
103 | static int | ||
104 | bio_cb_puts(BIO *bio, const char *str) | 48 | bio_cb_puts(BIO *bio, const char *str) |
105 | { | 49 | { |
106 | int n; | 50 | int n; |
@@ -135,9 +79,9 @@ bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr) | |||
135 | } | 79 | } |
136 | 80 | ||
137 | static int | 81 | static int |
138 | tls_bio_write_cb(BIO *bio, const char *buf, int num, void *cb_arg) | 82 | bio_cb_write(BIO *bio, const char *buf, int num) |
139 | { | 83 | { |
140 | struct tls *ctx = cb_arg; | 84 | struct tls *ctx = bio->ptr; |
141 | int rv; | 85 | int rv; |
142 | 86 | ||
143 | BIO_clear_retry_flags(bio); | 87 | BIO_clear_retry_flags(bio); |
@@ -153,9 +97,9 @@ tls_bio_write_cb(BIO *bio, const char *buf, int num, void *cb_arg) | |||
153 | } | 97 | } |
154 | 98 | ||
155 | static int | 99 | static int |
156 | tls_bio_read_cb(BIO *bio, char *buf, int size, void *cb_arg) | 100 | bio_cb_read(BIO *bio, char *buf, int size) |
157 | { | 101 | { |
158 | struct tls *ctx = cb_arg; | 102 | struct tls *ctx = bio->ptr; |
159 | int rv; | 103 | int rv; |
160 | 104 | ||
161 | BIO_clear_retry_flags(bio); | 105 | BIO_clear_retry_flags(bio); |
@@ -173,7 +117,6 @@ tls_bio_read_cb(BIO *bio, char *buf, int size, void *cb_arg) | |||
173 | static BIO * | 117 | static BIO * |
174 | tls_get_new_cb_bio(struct tls *ctx) | 118 | tls_get_new_cb_bio(struct tls *ctx) |
175 | { | 119 | { |
176 | struct bio_cb *bcb; | ||
177 | BIO *bio; | 120 | BIO *bio; |
178 | 121 | ||
179 | if (ctx->read_cb == NULL || ctx->write_cb == NULL) { | 122 | if (ctx->read_cb == NULL || ctx->write_cb == NULL) { |
@@ -185,10 +128,8 @@ tls_get_new_cb_bio(struct tls *ctx) | |||
185 | return (NULL); | 128 | return (NULL); |
186 | } | 129 | } |
187 | 130 | ||
188 | bcb = (struct bio_cb *)bio->ptr; | 131 | bio->ptr = ctx; |
189 | bcb->read_cb = tls_bio_read_cb; | 132 | bio->init = 1; |
190 | bcb->write_cb = tls_bio_write_cb; | ||
191 | bcb->cb_arg = ctx; | ||
192 | 133 | ||
193 | return (bio); | 134 | return (bio); |
194 | } | 135 | } |