| OLD | NEW |
| 1 /* crypto/bio/bss_fd.c */ | 1 /* crypto/bio/bss_fd.c */ |
| 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * This package is an SSL implementation written | 5 * This package is an SSL implementation written |
| 6 * by Eric Young (eay@cryptsoft.com). | 6 * by Eric Young (eay@cryptsoft.com). |
| 7 * The implementation was written so as to conform with Netscapes SSL. | 7 * The implementation was written so as to conform with Netscapes SSL. |
| 8 * | 8 * |
| 9 * This library is free for commercial and non-commercial use as long as | 9 * This library is free for commercial and non-commercial use as long as |
| 10 * the following conditions are aheared to. The following conditions | 10 * the following conditions are aheared to. The following conditions |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 * The licence and distribution terms for any publically available version or | 53 * The licence and distribution terms for any publically available version or |
| 54 * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 55 * copied and put under another distribution licence | 55 * copied and put under another distribution licence |
| 56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
| 57 */ | 57 */ |
| 58 | 58 |
| 59 #include <stdio.h> | 59 #include <stdio.h> |
| 60 #include <errno.h> | 60 #include <errno.h> |
| 61 #define USE_SOCKETS | 61 #define USE_SOCKETS |
| 62 #include "cryptlib.h" | 62 #include "cryptlib.h" |
| 63 |
| 64 #if defined(OPENSSL_NO_POSIX_IO) |
| 65 /* |
| 66 * One can argue that one should implement dummy placeholder for |
| 67 * BIO_s_fd here... |
| 68 */ |
| 69 #else |
| 63 /* | 70 /* |
| 64 * As for unconditional usage of "UPLINK" interface in this module. | 71 * As for unconditional usage of "UPLINK" interface in this module. |
| 65 * Trouble is that unlike Unix file descriptors [which are indexes | 72 * Trouble is that unlike Unix file descriptors [which are indexes |
| 66 * in kernel-side per-process table], corresponding descriptors on | 73 * in kernel-side per-process table], corresponding descriptors on |
| 67 * platforms which require "UPLINK" interface seem to be indexes | 74 * platforms which require "UPLINK" interface seem to be indexes |
| 68 * in a user-land, non-global table. Well, in fact they are indexes | 75 * in a user-land, non-global table. Well, in fact they are indexes |
| 69 * in stdio _iob[], and recall that _iob[] was the very reason why | 76 * in stdio _iob[], and recall that _iob[] was the very reason why |
| 70 * "UPLINK" interface was introduced in first place. But one way on | 77 * "UPLINK" interface was introduced in first place. But one way on |
| 71 * another. Neither libcrypto or libssl use this BIO meaning that | 78 * another. Neither libcrypto or libssl use this BIO meaning that |
| 72 * file descriptors can only be provided by application. Therefore | 79 * file descriptors can only be provided by application. Therefore |
| 73 * "UPLINK" calls are due... | 80 * "UPLINK" calls are due... |
| 74 */ | 81 */ |
| 75 #include "bio_lcl.h" | 82 #include "bio_lcl.h" |
| 76 | 83 |
| 77 static int fd_write(BIO *h, const char *buf, int num); | 84 static int fd_write(BIO *h, const char *buf, int num); |
| 78 static int fd_read(BIO *h, char *buf, int size); | 85 static int fd_read(BIO *h, char *buf, int size); |
| 79 static int fd_puts(BIO *h, const char *str); | 86 static int fd_puts(BIO *h, const char *str); |
| 87 static int fd_gets(BIO *h, char *buf, int size); |
| 80 static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 88 static long fd_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
| 81 static int fd_new(BIO *h); | 89 static int fd_new(BIO *h); |
| 82 static int fd_free(BIO *data); | 90 static int fd_free(BIO *data); |
| 83 int BIO_fd_should_retry(int s); | 91 int BIO_fd_should_retry(int s); |
| 84 | 92 |
| 85 static BIO_METHOD methods_fdp= | 93 static BIO_METHOD methods_fdp= |
| 86 { | 94 { |
| 87 BIO_TYPE_FD,"file descriptor", | 95 BIO_TYPE_FD,"file descriptor", |
| 88 fd_write, | 96 fd_write, |
| 89 fd_read, | 97 fd_read, |
| 90 fd_puts, | 98 fd_puts, |
| 91 » NULL, /* fd_gets, */ | 99 » fd_gets, |
| 92 fd_ctrl, | 100 fd_ctrl, |
| 93 fd_new, | 101 fd_new, |
| 94 fd_free, | 102 fd_free, |
| 95 NULL, | 103 NULL, |
| 96 }; | 104 }; |
| 97 | 105 |
| 98 BIO_METHOD *BIO_s_fd(void) | 106 BIO_METHOD *BIO_s_fd(void) |
| 99 { | 107 { |
| 100 return(&methods_fdp); | 108 return(&methods_fdp); |
| 101 } | 109 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 228 |
| 221 static int fd_puts(BIO *bp, const char *str) | 229 static int fd_puts(BIO *bp, const char *str) |
| 222 { | 230 { |
| 223 int n,ret; | 231 int n,ret; |
| 224 | 232 |
| 225 n=strlen(str); | 233 n=strlen(str); |
| 226 ret=fd_write(bp,str,n); | 234 ret=fd_write(bp,str,n); |
| 227 return(ret); | 235 return(ret); |
| 228 } | 236 } |
| 229 | 237 |
| 238 static int fd_gets(BIO *bp, char *buf, int size) |
| 239 { |
| 240 int ret=0; |
| 241 char *ptr=buf; |
| 242 char *end=buf+size-1; |
| 243 |
| 244 while ( (ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n') ) |
| 245 ptr++; |
| 246 |
| 247 ptr[0]='\0'; |
| 248 |
| 249 if (buf[0] != '\0') |
| 250 ret=strlen(buf); |
| 251 return(ret); |
| 252 } |
| 253 |
| 230 int BIO_fd_should_retry(int i) | 254 int BIO_fd_should_retry(int i) |
| 231 { | 255 { |
| 232 int err; | 256 int err; |
| 233 | 257 |
| 234 if ((i == 0) || (i == -1)) | 258 if ((i == 0) || (i == -1)) |
| 235 { | 259 { |
| 236 err=get_last_sys_error(); | 260 err=get_last_sys_error(); |
| 237 | 261 |
| 238 #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not?
Ben 4/1/99 */ | 262 #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not?
Ben 4/1/99 */ |
| 239 if ((i == -1) && (err == 0)) | 263 if ((i == -1) && (err == 0)) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 #ifdef EALREADY | 309 #ifdef EALREADY |
| 286 case EALREADY: | 310 case EALREADY: |
| 287 #endif | 311 #endif |
| 288 return(1); | 312 return(1); |
| 289 /* break; */ | 313 /* break; */ |
| 290 default: | 314 default: |
| 291 break; | 315 break; |
| 292 } | 316 } |
| 293 return(0); | 317 return(0); |
| 294 } | 318 } |
| 319 #endif |
| OLD | NEW |