]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/bio/bf_null.c
BIO: at the end of BIO_new, declare the BIO inited if no create method present
[thirdparty/openssl.git] / crypto / bio / bf_null.c
CommitLineData
b1322259
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
0f113f3e 3 *
b1322259
RS
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
d02b48c6
RE
8 */
9
10#include <stdio.h>
11#include <errno.h>
a146ae55 12#include "bio_lcl.h"
b39fc560 13#include "internal/cryptlib.h"
d02b48c6 14
0f113f3e
MC
15/*
16 * BIO_put and BIO_get both add to the digest, BIO_gets returns the digest
17 */
d02b48c6 18
0e1c0612
UM
19static int nullf_write(BIO *h, const char *buf, int num);
20static int nullf_read(BIO *h, char *buf, int size);
21static int nullf_puts(BIO *h, const char *str);
22static int nullf_gets(BIO *h, char *str, int size);
23static long nullf_ctrl(BIO *h, int cmd, long arg1, void *arg2);
d02b48c6
RE
24static int nullf_new(BIO *h);
25static int nullf_free(BIO *data);
fce78bd4 26static long nullf_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
04f6b0fd 27static const BIO_METHOD methods_nullf = {
0f113f3e
MC
28 BIO_TYPE_NULL_FILTER,
29 "NULL filter",
3befffa3
MC
30 /* TODO: Convert to new style write function */
31 bwrite_conv,
0f113f3e 32 nullf_write,
d07aee2c
MC
33 /* TODO: Convert to new style read function */
34 bread_conv,
0f113f3e
MC
35 nullf_read,
36 nullf_puts,
37 nullf_gets,
38 nullf_ctrl,
39 nullf_new,
40 nullf_free,
41 nullf_callback_ctrl,
42};
d02b48c6 43
04f6b0fd 44const BIO_METHOD *BIO_f_null(void)
0f113f3e 45{
26a7d938 46 return &methods_nullf;
0f113f3e 47}
d02b48c6 48
6b691a5c 49static int nullf_new(BIO *bi)
0f113f3e
MC
50{
51 bi->init = 1;
52 bi->ptr = NULL;
53 bi->flags = 0;
208fb891 54 return 1;
0f113f3e 55}
d02b48c6 56
6b691a5c 57static int nullf_free(BIO *a)
0f113f3e
MC
58{
59 if (a == NULL)
26a7d938 60 return 0;
35a1cc90
MC
61 /*-
62 a->ptr=NULL;
63 a->init=0;
64 a->flags=0;
65 */
208fb891 66 return 1;
0f113f3e
MC
67}
68
6b691a5c 69static int nullf_read(BIO *b, char *out, int outl)
0f113f3e
MC
70{
71 int ret = 0;
72
73 if (out == NULL)
26a7d938 74 return 0;
0f113f3e 75 if (b->next_bio == NULL)
26a7d938 76 return 0;
0f113f3e
MC
77 ret = BIO_read(b->next_bio, out, outl);
78 BIO_clear_retry_flags(b);
79 BIO_copy_next_retry(b);
26a7d938 80 return ret;
0f113f3e 81}
d02b48c6 82
0e1c0612 83static int nullf_write(BIO *b, const char *in, int inl)
0f113f3e
MC
84{
85 int ret = 0;
86
87 if ((in == NULL) || (inl <= 0))
26a7d938 88 return 0;
0f113f3e 89 if (b->next_bio == NULL)
26a7d938 90 return 0;
0f113f3e
MC
91 ret = BIO_write(b->next_bio, in, inl);
92 BIO_clear_retry_flags(b);
93 BIO_copy_next_retry(b);
26a7d938 94 return ret;
0f113f3e 95}
d02b48c6 96
0e1c0612 97static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
0f113f3e
MC
98{
99 long ret;
100
101 if (b->next_bio == NULL)
26a7d938 102 return 0;
0f113f3e
MC
103 switch (cmd) {
104 case BIO_C_DO_STATE_MACHINE:
105 BIO_clear_retry_flags(b);
106 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
107 BIO_copy_next_retry(b);
108 break;
109 case BIO_CTRL_DUP:
110 ret = 0L;
111 break;
112 default:
113 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
114 }
26a7d938 115 return ret;
0f113f3e 116}
d02b48c6 117
fce78bd4 118static long nullf_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
0f113f3e
MC
119{
120 long ret = 1;
121
122 if (b->next_bio == NULL)
26a7d938 123 return 0;
0f113f3e
MC
124 switch (cmd) {
125 default:
126 ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
127 break;
128 }
26a7d938 129 return ret;
0f113f3e 130}
d3442bc7 131
6b691a5c 132static int nullf_gets(BIO *bp, char *buf, int size)
0f113f3e
MC
133{
134 if (bp->next_bio == NULL)
26a7d938
K
135 return 0;
136 return BIO_gets(bp->next_bio, buf, size);
0f113f3e 137}
d02b48c6 138
0e1c0612 139static int nullf_puts(BIO *bp, const char *str)
0f113f3e
MC
140{
141 if (bp->next_bio == NULL)
26a7d938
K
142 return 0;
143 return BIO_puts(bp->next_bio, str);
0f113f3e 144}