|
| 1 | + |
| 2 | +#include "bio_frag.h" |
| 3 | + |
| 4 | +static int bwrite(BIO *bio, const char *buf, int len); |
| 5 | +static int bread(BIO *bio, char *buf, int len); |
| 6 | +static long ctrl(BIO *bio, int cmd, long arg1, void *arg2); |
| 7 | +static int create(BIO *bio); |
| 8 | +static int destroy(BIO *bio); |
| 9 | +static long callback_ctrl(BIO *bio, int cmd, BIO_info_cb *fp); |
| 10 | + |
| 11 | +// static const BIO_METHOD bio_methods = { |
| 12 | +// BIO_TYPE_BIO, |
| 13 | +// "DTLS fragmentation for mem BIO", |
| 14 | +// bwrite_conv, |
| 15 | +// bwrite, |
| 16 | +// bread_conv, |
| 17 | +// bread, |
| 18 | +// NULL, |
| 19 | +// NULL, |
| 20 | +// ctrl, |
| 21 | +// create, |
| 22 | +// destroy, |
| 23 | +// callback_ctrl |
| 24 | +// }; |
| 25 | + |
| 26 | +static BIO_METHOD *bio_methods = NULL; |
| 27 | + |
| 28 | +const BIO_METHOD *BIO_f_frag(void) { |
| 29 | + bio_methods = BIO_meth_new(BIO_TYPE_FILTER, "DTLS fragmentation for mem BIO"); |
| 30 | + |
| 31 | + BIO_meth_set_read(bio_methods, bread); |
| 32 | + BIO_meth_set_write(bio_methods, bwrite); |
| 33 | + BIO_meth_set_ctrl(bio_methods, ctrl); |
| 34 | + BIO_meth_set_create(bio_methods, create); |
| 35 | + BIO_meth_set_destroy(bio_methods, destroy); |
| 36 | + BIO_meth_set_callback_ctrl(bio_methods, callback_ctrl); |
| 37 | + |
| 38 | + return bio_methods; |
| 39 | +} |
| 40 | + |
| 41 | +static int create(BIO *bio) { |
| 42 | + DEBUG("BIO frag create"); |
| 43 | + // indicate that BIO initialization is complete |
| 44 | + BIO_set_init(bio, 1); |
| 45 | + return 1; |
| 46 | +} |
| 47 | + |
| 48 | +static int destroy(BIO *bio) { |
| 49 | + DEBUG("BIO frag destroy"); |
| 50 | + if (bio == NULL) { |
| 51 | + return 0; |
| 52 | + } |
| 53 | + |
| 54 | + BIO_set_init(bio, 0); |
| 55 | + return 1; |
| 56 | +} |
| 57 | + |
| 58 | +static int bread(BIO *bio, char *buf, int len) { |
| 59 | + DEBUG("BIO frag bread"); |
| 60 | + BIO *next = BIO_next(bio); |
| 61 | + if (next == NULL) { |
| 62 | + return 0; |
| 63 | + } |
| 64 | + |
| 65 | + return BIO_read(next, buf, len); |
| 66 | +} |
| 67 | + |
| 68 | +static int bwrite(BIO *bio, const char *buf, int len) { |
| 69 | + DEBUG("BIO frag bwrite %d", len); |
| 70 | + BIO *next = BIO_next(bio); |
| 71 | + if (next == NULL) { |
| 72 | + return 0; |
| 73 | + } |
| 74 | + |
| 75 | + return BIO_write(next, buf, len); |
| 76 | +} |
| 77 | + |
| 78 | +static long ctrl(BIO *bio, int cmd, long num, void *ptr) { |
| 79 | + DEBUG("BIO frag ctrl"); |
| 80 | + |
| 81 | + BIO *next = BIO_next(bio); |
| 82 | + if (next == NULL) { |
| 83 | + return 0; |
| 84 | + } |
| 85 | + |
| 86 | + return BIO_ctrl(next, cmd, num, ptr); |
| 87 | +} |
| 88 | + |
| 89 | +static long callback_ctrl(BIO *bio, int cmd, BIO_info_cb *fp) { |
| 90 | + BIO *next = BIO_next(bio); |
| 91 | + if (next == NULL) { |
| 92 | + return 0; |
| 93 | + } |
| 94 | + |
| 95 | + return BIO_callback_ctrl(next, cmd, fp); |
| 96 | +} |
| 97 | + |
| 98 | + |
0 commit comments