update libressl to v2.7.4
[unleashed.git] / lib / libcrypto / bio / bio_meth.c
blobc795c3f231795f0e314c8973ca0e3ed44d8ec943
1 /* $OpenBSD: bio_meth.c,v 1.5 2018/02/20 18:51:35 tb Exp $ */
2 /*
3 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <stdlib.h>
20 #include <openssl/bio.h>
22 BIO_METHOD *
23 BIO_meth_new(int type, const char *name)
25 BIO_METHOD *biom;
27 if ((biom = calloc(1, sizeof(*biom))) == NULL)
28 return NULL;
30 biom->type = type;
31 biom->name = name;
33 return biom;
36 void
37 BIO_meth_free(BIO_METHOD *biom)
39 free(biom);
42 int
43 (*BIO_meth_get_write(BIO_METHOD *biom))(BIO *, const char *, int)
45 return biom->bwrite;
48 int
49 BIO_meth_set_write(BIO_METHOD *biom, int (*write)(BIO *, const char *, int))
51 biom->bwrite = write;
52 return 1;
55 int
56 (*BIO_meth_get_read(BIO_METHOD *biom))(BIO *, char *, int)
58 return biom->bread;
61 int
62 BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int))
64 biom->bread = read;
65 return 1;
68 int
69 (*BIO_meth_get_puts(BIO_METHOD *biom))(BIO *, const char *)
71 return biom->bputs;
74 int
75 BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *))
77 biom->bputs = puts;
78 return 1;
81 int
82 (*BIO_meth_get_gets(BIO_METHOD *biom))(BIO *, char *, int)
84 return biom->bgets;
87 int
88 BIO_meth_set_gets(BIO_METHOD *biom, int (*gets)(BIO *, char *, int))
90 biom->bgets = gets;
91 return 1;
94 long
95 (*BIO_meth_get_ctrl(BIO_METHOD *biom))(BIO *, int, long, void *)
97 return biom->ctrl;
101 BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl)(BIO *, int, long, void *))
103 biom->ctrl = ctrl;
104 return 1;
108 (*BIO_meth_get_create(BIO_METHOD *biom))(BIO *)
110 return biom->create;
114 BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *))
116 biom->create = create;
117 return 1;
121 (*BIO_meth_get_destroy(BIO_METHOD *biom))(BIO *)
123 return biom->destroy;
127 BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *))
129 biom->destroy = destroy;
130 return 1;
133 long
134 (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom))(BIO *, int, BIO_info_cb *)
136 return
137 (long (*)(BIO *, int, BIO_info_cb *))biom->callback_ctrl; /* XXX */
141 BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
142 long (*callback_ctrl)(BIO *, int, BIO_info_cb *))
144 biom->callback_ctrl =
145 (long (*)(BIO *, int, bio_info_cb *))callback_ctrl; /* XXX */
146 return 1;