summaryrefslogtreecommitdiff
path: root/lib/libcrypto/bio/bio_meth.c
blob: b9c07d5111c7e75ac9a2dc898794d4e28ba4550a (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*	$OpenBSD: bio_meth.c,v 1.7 2022/01/07 09:02:17 tb Exp $	*/
/*
 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <stdlib.h>

#include <openssl/bio.h>

#include "bio_local.h"

BIO_METHOD *
BIO_meth_new(int type, const char *name)
{
	BIO_METHOD *biom;

	if ((biom = calloc(1, sizeof(*biom))) == NULL)
		return NULL;

	biom->type = type;
	biom->name = name;

	return biom;
}

void
BIO_meth_free(BIO_METHOD *biom)
{
	free(biom);
}

int
(*BIO_meth_get_write(const BIO_METHOD *biom))(BIO *, const char *, int)
{
	return biom->bwrite;
}

int
BIO_meth_set_write(BIO_METHOD *biom, int (*write)(BIO *, const char *, int))
{
	biom->bwrite = write;
	return 1;
}

int
(*BIO_meth_get_read(const BIO_METHOD *biom))(BIO *, char *, int)
{
	return biom->bread;
}

int
BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int))
{
	biom->bread = read;
	return 1;
}

int
(*BIO_meth_get_puts(const BIO_METHOD *biom))(BIO *, const char *)
{
	return biom->bputs;
}

int
BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *))
{
	biom->bputs = puts;
	return 1;
}

int
(*BIO_meth_get_gets(const BIO_METHOD *biom))(BIO *, char *, int)
{
	return biom->bgets;
}

int
BIO_meth_set_gets(BIO_METHOD *biom, int (*gets)(BIO *, char *, int))
{
	biom->bgets = gets;
	return 1;
}

long
(*BIO_meth_get_ctrl(const BIO_METHOD *biom))(BIO *, int, long, void *)
{
	return biom->ctrl;
}

int
BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl)(BIO *, int, long, void *))
{
	biom->ctrl = ctrl;
	return 1;
}

int
(*BIO_meth_get_create(const BIO_METHOD *biom))(BIO *)
{
	return biom->create;
}

int
BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *))
{
	biom->create = create;
	return 1;
}

int
(*BIO_meth_get_destroy(const BIO_METHOD *biom))(BIO *)
{
	return biom->destroy;
}

int
BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *))
{
	biom->destroy = destroy;
	return 1;
}

long
(*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, BIO_info_cb *)
{
	return
	    (long (*)(BIO *, int, BIO_info_cb *))biom->callback_ctrl; /* XXX */
}

int
BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
    long (*callback_ctrl)(BIO *, int, BIO_info_cb *))
{
	biom->callback_ctrl =
	    (long (*)(BIO *, int, bio_info_cb *))callback_ctrl;	/* XXX */
	return 1;
}