]>
Commit | Line | Data |
---|---|---|
b1322259 RS |
1 | /* |
2 | * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | |
d02b48c6 | 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 | |
0e1c0612 UM |
15 | static int null_write(BIO *h, const char *buf, int num); |
16 | static int null_read(BIO *h, char *buf, int size); | |
17 | static int null_puts(BIO *h, const char *str); | |
18 | static int null_gets(BIO *h, char *str, int size); | |
19 | static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2); | |
d02b48c6 RE |
20 | static int null_new(BIO *h); |
21 | static int null_free(BIO *data); | |
04f6b0fd | 22 | static const BIO_METHOD null_method = { |
0f113f3e MC |
23 | BIO_TYPE_NULL, |
24 | "NULL", | |
3befffa3 MC |
25 | /* TODO: Convert to new style write function */ |
26 | bwrite_conv, | |
0f113f3e | 27 | null_write, |
d07aee2c MC |
28 | /* TODO: Convert to new style read function */ |
29 | bread_conv, | |
0f113f3e MC |
30 | null_read, |
31 | null_puts, | |
32 | null_gets, | |
33 | null_ctrl, | |
34 | null_new, | |
35 | null_free, | |
36 | NULL, | |
37 | }; | |
d02b48c6 | 38 | |
04f6b0fd | 39 | const BIO_METHOD *BIO_s_null(void) |
0f113f3e | 40 | { |
26a7d938 | 41 | return &null_method; |
0f113f3e | 42 | } |
d02b48c6 | 43 | |
6b691a5c | 44 | static int null_new(BIO *bi) |
0f113f3e MC |
45 | { |
46 | bi->init = 1; | |
47 | bi->num = 0; | |
48 | bi->ptr = (NULL); | |
208fb891 | 49 | return 1; |
0f113f3e | 50 | } |
d02b48c6 | 51 | |
6b691a5c | 52 | static int null_free(BIO *a) |
0f113f3e MC |
53 | { |
54 | if (a == NULL) | |
26a7d938 | 55 | return 0; |
208fb891 | 56 | return 1; |
0f113f3e MC |
57 | } |
58 | ||
6b691a5c | 59 | static int null_read(BIO *b, char *out, int outl) |
0f113f3e | 60 | { |
26a7d938 | 61 | return 0; |
0f113f3e | 62 | } |
d02b48c6 | 63 | |
0e1c0612 | 64 | static int null_write(BIO *b, const char *in, int inl) |
0f113f3e | 65 | { |
26a7d938 | 66 | return inl; |
0f113f3e | 67 | } |
d02b48c6 | 68 | |
0e1c0612 | 69 | static long null_ctrl(BIO *b, int cmd, long num, void *ptr) |
0f113f3e MC |
70 | { |
71 | long ret = 1; | |
d02b48c6 | 72 | |
0f113f3e MC |
73 | switch (cmd) { |
74 | case BIO_CTRL_RESET: | |
75 | case BIO_CTRL_EOF: | |
76 | case BIO_CTRL_SET: | |
77 | case BIO_CTRL_SET_CLOSE: | |
78 | case BIO_CTRL_FLUSH: | |
79 | case BIO_CTRL_DUP: | |
80 | ret = 1; | |
81 | break; | |
82 | case BIO_CTRL_GET_CLOSE: | |
83 | case BIO_CTRL_INFO: | |
84 | case BIO_CTRL_GET: | |
85 | case BIO_CTRL_PENDING: | |
86 | case BIO_CTRL_WPENDING: | |
87 | default: | |
88 | ret = 0; | |
89 | break; | |
90 | } | |
26a7d938 | 91 | return ret; |
0f113f3e | 92 | } |
d02b48c6 | 93 | |
6b691a5c | 94 | static int null_gets(BIO *bp, char *buf, int size) |
0f113f3e | 95 | { |
26a7d938 | 96 | return 0; |
0f113f3e | 97 | } |
d02b48c6 | 98 | |
0e1c0612 | 99 | static int null_puts(BIO *bp, const char *str) |
0f113f3e MC |
100 | { |
101 | if (str == NULL) | |
26a7d938 K |
102 | return 0; |
103 | return strlen(str); | |
0f113f3e | 104 | } |