diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_sock.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_sock.c | 131 |
1 files changed, 3 insertions, 128 deletions
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c index 50c6744c06..fdabd16d7e 100644 --- a/src/lib/libcrypto/bio/bss_sock.c +++ b/src/lib/libcrypto/bio/bss_sock.c | |||
@@ -56,7 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #if !defined(NO_SOCK) || defined(BIO_FD) | 59 | #ifndef OPENSSL_NO_SOCK |
60 | 60 | ||
61 | #include <stdio.h> | 61 | #include <stdio.h> |
62 | #include <errno.h> | 62 | #include <errno.h> |
@@ -64,7 +64,6 @@ | |||
64 | #include "cryptlib.h" | 64 | #include "cryptlib.h" |
65 | #include <openssl/bio.h> | 65 | #include <openssl/bio.h> |
66 | 66 | ||
67 | #ifndef BIO_FD | ||
68 | static int sock_write(BIO *h, const char *buf, int num); | 67 | static int sock_write(BIO *h, const char *buf, int num); |
69 | static int sock_read(BIO *h, char *buf, int size); | 68 | static int sock_read(BIO *h, char *buf, int size); |
70 | static int sock_puts(BIO *h, const char *str); | 69 | static int sock_puts(BIO *h, const char *str); |
@@ -72,18 +71,7 @@ static long sock_ctrl(BIO *h, int cmd, long arg1, void *arg2); | |||
72 | static int sock_new(BIO *h); | 71 | static int sock_new(BIO *h); |
73 | static int sock_free(BIO *data); | 72 | static int sock_free(BIO *data); |
74 | int BIO_sock_should_retry(int s); | 73 | int BIO_sock_should_retry(int s); |
75 | #else | ||
76 | 74 | ||
77 | static int fd_write(BIO *h, const char *buf, int num); | ||
78 | static int fd_read(BIO *h, char *buf, int size); | ||
79 | static int fd_puts(BIO *h, const char *str); | ||
80 | static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
81 | static int fd_new(BIO *h); | ||
82 | static int fd_free(BIO *data); | ||
83 | int BIO_fd_should_retry(int s); | ||
84 | #endif | ||
85 | |||
86 | #ifndef BIO_FD | ||
87 | static BIO_METHOD methods_sockp= | 75 | static BIO_METHOD methods_sockp= |
88 | { | 76 | { |
89 | BIO_TYPE_SOCKET, | 77 | BIO_TYPE_SOCKET, |
@@ -102,49 +90,18 @@ BIO_METHOD *BIO_s_socket(void) | |||
102 | { | 90 | { |
103 | return(&methods_sockp); | 91 | return(&methods_sockp); |
104 | } | 92 | } |
105 | #else | ||
106 | static BIO_METHOD methods_fdp= | ||
107 | { | ||
108 | BIO_TYPE_FD,"file descriptor", | ||
109 | fd_write, | ||
110 | fd_read, | ||
111 | fd_puts, | ||
112 | NULL, /* fd_gets, */ | ||
113 | fd_ctrl, | ||
114 | fd_new, | ||
115 | fd_free, | ||
116 | NULL, | ||
117 | }; | ||
118 | |||
119 | BIO_METHOD *BIO_s_fd(void) | ||
120 | { | ||
121 | return(&methods_fdp); | ||
122 | } | ||
123 | #endif | ||
124 | 93 | ||
125 | #ifndef BIO_FD | ||
126 | BIO *BIO_new_socket(int fd, int close_flag) | 94 | BIO *BIO_new_socket(int fd, int close_flag) |
127 | #else | ||
128 | BIO *BIO_new_fd(int fd,int close_flag) | ||
129 | #endif | ||
130 | { | 95 | { |
131 | BIO *ret; | 96 | BIO *ret; |
132 | 97 | ||
133 | #ifndef BIO_FD | ||
134 | ret=BIO_new(BIO_s_socket()); | 98 | ret=BIO_new(BIO_s_socket()); |
135 | #else | ||
136 | ret=BIO_new(BIO_s_fd()); | ||
137 | #endif | ||
138 | if (ret == NULL) return(NULL); | 99 | if (ret == NULL) return(NULL); |
139 | BIO_set_fd(ret,fd,close_flag); | 100 | BIO_set_fd(ret,fd,close_flag); |
140 | return(ret); | 101 | return(ret); |
141 | } | 102 | } |
142 | 103 | ||
143 | #ifndef BIO_FD | ||
144 | static int sock_new(BIO *bi) | 104 | static int sock_new(BIO *bi) |
145 | #else | ||
146 | static int fd_new(BIO *bi) | ||
147 | #endif | ||
148 | { | 105 | { |
149 | bi->init=0; | 106 | bi->init=0; |
150 | bi->num=0; | 107 | bi->num=0; |
@@ -153,23 +110,14 @@ static int fd_new(BIO *bi) | |||
153 | return(1); | 110 | return(1); |
154 | } | 111 | } |
155 | 112 | ||
156 | #ifndef BIO_FD | ||
157 | static int sock_free(BIO *a) | 113 | static int sock_free(BIO *a) |
158 | #else | ||
159 | static int fd_free(BIO *a) | ||
160 | #endif | ||
161 | { | 114 | { |
162 | if (a == NULL) return(0); | 115 | if (a == NULL) return(0); |
163 | if (a->shutdown) | 116 | if (a->shutdown) |
164 | { | 117 | { |
165 | if (a->init) | 118 | if (a->init) |
166 | { | 119 | { |
167 | #ifndef BIO_FD | ||
168 | SHUTDOWN2(a->num); | 120 | SHUTDOWN2(a->num); |
169 | #else /* BIO_FD */ | ||
170 | close(a->num); | ||
171 | #endif | ||
172 | |||
173 | } | 121 | } |
174 | a->init=0; | 122 | a->init=0; |
175 | a->flags=0; | 123 | a->flags=0; |
@@ -177,70 +125,40 @@ static int fd_free(BIO *a) | |||
177 | return(1); | 125 | return(1); |
178 | } | 126 | } |
179 | 127 | ||
180 | #ifndef BIO_FD | ||
181 | static int sock_read(BIO *b, char *out, int outl) | 128 | static int sock_read(BIO *b, char *out, int outl) |
182 | #else | ||
183 | static int fd_read(BIO *b, char *out,int outl) | ||
184 | #endif | ||
185 | { | 129 | { |
186 | int ret=0; | 130 | int ret=0; |
187 | 131 | ||
188 | if (out != NULL) | 132 | if (out != NULL) |
189 | { | 133 | { |
190 | #ifndef BIO_FD | ||
191 | clear_socket_error(); | 134 | clear_socket_error(); |
192 | ret=readsocket(b->num,out,outl); | 135 | ret=readsocket(b->num,out,outl); |
193 | #else | ||
194 | clear_sys_error(); | ||
195 | ret=read(b->num,out,outl); | ||
196 | #endif | ||
197 | BIO_clear_retry_flags(b); | 136 | BIO_clear_retry_flags(b); |
198 | if (ret <= 0) | 137 | if (ret <= 0) |
199 | { | 138 | { |
200 | #ifndef BIO_FD | ||
201 | if (BIO_sock_should_retry(ret)) | 139 | if (BIO_sock_should_retry(ret)) |
202 | #else | ||
203 | if (BIO_fd_should_retry(ret)) | ||
204 | #endif | ||
205 | BIO_set_retry_read(b); | 140 | BIO_set_retry_read(b); |
206 | } | 141 | } |
207 | } | 142 | } |
208 | return(ret); | 143 | return(ret); |
209 | } | 144 | } |
210 | 145 | ||
211 | #ifndef BIO_FD | ||
212 | static int sock_write(BIO *b, const char *in, int inl) | 146 | static int sock_write(BIO *b, const char *in, int inl) |
213 | #else | ||
214 | static int fd_write(BIO *b, const char *in, int inl) | ||
215 | #endif | ||
216 | { | 147 | { |
217 | int ret; | 148 | int ret; |
218 | 149 | ||
219 | #ifndef BIO_FD | ||
220 | clear_socket_error(); | 150 | clear_socket_error(); |
221 | ret=writesocket(b->num,in,inl); | 151 | ret=writesocket(b->num,in,inl); |
222 | #else | ||
223 | clear_sys_error(); | ||
224 | ret=write(b->num,in,inl); | ||
225 | #endif | ||
226 | BIO_clear_retry_flags(b); | 152 | BIO_clear_retry_flags(b); |
227 | if (ret <= 0) | 153 | if (ret <= 0) |
228 | { | 154 | { |
229 | #ifndef BIO_FD | ||
230 | if (BIO_sock_should_retry(ret)) | 155 | if (BIO_sock_should_retry(ret)) |
231 | #else | ||
232 | if (BIO_fd_should_retry(ret)) | ||
233 | #endif | ||
234 | BIO_set_retry_write(b); | 156 | BIO_set_retry_write(b); |
235 | } | 157 | } |
236 | return(ret); | 158 | return(ret); |
237 | } | 159 | } |
238 | 160 | ||
239 | #ifndef BIO_FD | ||
240 | static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) | 161 | static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) |
241 | #else | ||
242 | static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
243 | #endif | ||
244 | { | 162 | { |
245 | long ret=1; | 163 | long ret=1; |
246 | int *ip; | 164 | int *ip; |
@@ -250,26 +168,14 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
250 | case BIO_CTRL_RESET: | 168 | case BIO_CTRL_RESET: |
251 | num=0; | 169 | num=0; |
252 | case BIO_C_FILE_SEEK: | 170 | case BIO_C_FILE_SEEK: |
253 | #ifdef BIO_FD | ||
254 | ret=(long)lseek(b->num,num,0); | ||
255 | #else | ||
256 | ret=0; | 171 | ret=0; |
257 | #endif | ||
258 | break; | 172 | break; |
259 | case BIO_C_FILE_TELL: | 173 | case BIO_C_FILE_TELL: |
260 | case BIO_CTRL_INFO: | 174 | case BIO_CTRL_INFO: |
261 | #ifdef BIO_FD | ||
262 | ret=(long)lseek(b->num,0,1); | ||
263 | #else | ||
264 | ret=0; | 175 | ret=0; |
265 | #endif | ||
266 | break; | 176 | break; |
267 | case BIO_C_SET_FD: | 177 | case BIO_C_SET_FD: |
268 | #ifndef BIO_FD | ||
269 | sock_free(b); | 178 | sock_free(b); |
270 | #else | ||
271 | fd_free(b); | ||
272 | #endif | ||
273 | b->num= *((int *)ptr); | 179 | b->num= *((int *)ptr); |
274 | b->shutdown=(int)num; | 180 | b->shutdown=(int)num; |
275 | b->init=1; | 181 | b->init=1; |
@@ -305,69 +211,38 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
305 | return(ret); | 211 | return(ret); |
306 | } | 212 | } |
307 | 213 | ||
308 | #ifdef undef | ||
309 | static int sock_gets(BIO *bp, char *buf,int size) | ||
310 | { | ||
311 | return(-1); | ||
312 | } | ||
313 | #endif | ||
314 | |||
315 | #ifndef BIO_FD | ||
316 | static int sock_puts(BIO *bp, const char *str) | 214 | static int sock_puts(BIO *bp, const char *str) |
317 | #else | ||
318 | static int fd_puts(BIO *bp, const char *str) | ||
319 | #endif | ||
320 | { | 215 | { |
321 | int n,ret; | 216 | int n,ret; |
322 | 217 | ||
323 | n=strlen(str); | 218 | n=strlen(str); |
324 | #ifndef BIO_FD | ||
325 | ret=sock_write(bp,str,n); | 219 | ret=sock_write(bp,str,n); |
326 | #else | ||
327 | ret=fd_write(bp,str,n); | ||
328 | #endif | ||
329 | return(ret); | 220 | return(ret); |
330 | } | 221 | } |
331 | 222 | ||
332 | #ifndef BIO_FD | ||
333 | int BIO_sock_should_retry(int i) | 223 | int BIO_sock_should_retry(int i) |
334 | #else | ||
335 | int BIO_fd_should_retry(int i) | ||
336 | #endif | ||
337 | { | 224 | { |
338 | int err; | 225 | int err; |
339 | 226 | ||
340 | if ((i == 0) || (i == -1)) | 227 | if ((i == 0) || (i == -1)) |
341 | { | 228 | { |
342 | #ifndef BIO_FD | ||
343 | err=get_last_socket_error(); | 229 | err=get_last_socket_error(); |
344 | #else | ||
345 | err=get_last_sys_error(); | ||
346 | #endif | ||
347 | 230 | ||
348 | #if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ | 231 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ |
349 | if ((i == -1) && (err == 0)) | 232 | if ((i == -1) && (err == 0)) |
350 | return(1); | 233 | return(1); |
351 | #endif | 234 | #endif |
352 | 235 | ||
353 | #ifndef BIO_FD | ||
354 | return(BIO_sock_non_fatal_error(err)); | 236 | return(BIO_sock_non_fatal_error(err)); |
355 | #else | ||
356 | return(BIO_fd_non_fatal_error(err)); | ||
357 | #endif | ||
358 | } | 237 | } |
359 | return(0); | 238 | return(0); |
360 | } | 239 | } |
361 | 240 | ||
362 | #ifndef BIO_FD | ||
363 | int BIO_sock_non_fatal_error(int err) | 241 | int BIO_sock_non_fatal_error(int err) |
364 | #else | ||
365 | int BIO_fd_non_fatal_error(int err) | ||
366 | #endif | ||
367 | { | 242 | { |
368 | switch (err) | 243 | switch (err) |
369 | { | 244 | { |
370 | #if !defined(BIO_FD) && defined(WINDOWS) | 245 | #if defined(OPENSSL_SYS_WINDOWS) |
371 | # if defined(WSAEWOULDBLOCK) | 246 | # if defined(WSAEWOULDBLOCK) |
372 | case WSAEWOULDBLOCK: | 247 | case WSAEWOULDBLOCK: |
373 | # endif | 248 | # endif |