diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_fd.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_fd.c | 221 |
1 files changed, 112 insertions, 109 deletions
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c index ab18a56310..35ddd61359 100644 --- a/src/lib/libcrypto/bio/bss_fd.c +++ b/src/lib/libcrypto/bio/bss_fd.c | |||
@@ -90,9 +90,8 @@ static int fd_new(BIO *h); | |||
90 | static int fd_free(BIO *data); | 90 | static int fd_free(BIO *data); |
91 | int BIO_fd_should_retry(int s); | 91 | int BIO_fd_should_retry(int s); |
92 | 92 | ||
93 | static BIO_METHOD methods_fdp= | 93 | static BIO_METHOD methods_fdp = { |
94 | { | 94 | BIO_TYPE_FD, "file descriptor", |
95 | BIO_TYPE_FD,"file descriptor", | ||
96 | fd_write, | 95 | fd_write, |
97 | fd_read, | 96 | fd_read, |
98 | fd_puts, | 97 | fd_puts, |
@@ -101,178 +100,182 @@ static BIO_METHOD methods_fdp= | |||
101 | fd_new, | 100 | fd_new, |
102 | fd_free, | 101 | fd_free, |
103 | NULL, | 102 | NULL, |
104 | }; | 103 | }; |
105 | 104 | ||
106 | BIO_METHOD *BIO_s_fd(void) | 105 | BIO_METHOD |
107 | { | 106 | *BIO_s_fd(void) |
108 | return(&methods_fdp); | 107 | { |
109 | } | 108 | return (&methods_fdp); |
109 | } | ||
110 | 110 | ||
111 | BIO *BIO_new_fd(int fd,int close_flag) | 111 | BIO |
112 | { | 112 | *BIO_new_fd(int fd, int close_flag) |
113 | { | ||
113 | BIO *ret; | 114 | BIO *ret; |
114 | ret=BIO_new(BIO_s_fd()); | 115 | ret = BIO_new(BIO_s_fd()); |
115 | if (ret == NULL) return(NULL); | 116 | if (ret == NULL) |
116 | BIO_set_fd(ret,fd,close_flag); | 117 | return (NULL); |
117 | return(ret); | 118 | BIO_set_fd(ret, fd, close_flag); |
118 | } | 119 | return (ret); |
120 | } | ||
119 | 121 | ||
120 | static int fd_new(BIO *bi) | 122 | static int |
121 | { | 123 | fd_new(BIO *bi) |
122 | bi->init=0; | 124 | { |
123 | bi->num=-1; | 125 | bi->init = 0; |
124 | bi->ptr=NULL; | 126 | bi->num = -1; |
127 | bi->ptr = NULL; | ||
125 | bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ | 128 | bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ |
126 | return(1); | 129 | return (1); |
127 | } | 130 | } |
128 | 131 | ||
129 | static int fd_free(BIO *a) | 132 | static int |
130 | { | 133 | fd_free(BIO *a) |
131 | if (a == NULL) return(0); | 134 | { |
132 | if (a->shutdown) | 135 | if (a == NULL) |
133 | { | 136 | return (0); |
134 | if (a->init) | 137 | if (a->shutdown) { |
135 | { | 138 | if (a->init) { |
136 | UP_close(a->num); | 139 | UP_close(a->num); |
137 | } | ||
138 | a->init=0; | ||
139 | a->flags=BIO_FLAGS_UPLINK; | ||
140 | } | 140 | } |
141 | return(1); | 141 | a->init = 0; |
142 | a->flags = BIO_FLAGS_UPLINK; | ||
142 | } | 143 | } |
143 | 144 | return (1); | |
144 | static int fd_read(BIO *b, char *out,int outl) | 145 | } |
145 | { | ||
146 | int ret=0; | ||
147 | 146 | ||
148 | if (out != NULL) | 147 | static int |
149 | { | 148 | fd_read(BIO *b, char *out, int outl) |
149 | { | ||
150 | int ret = 0; | ||
151 | |||
152 | if (out != NULL) { | ||
150 | errno = 0; | 153 | errno = 0; |
151 | ret=UP_read(b->num,out,outl); | 154 | ret = UP_read(b->num, out, outl); |
152 | BIO_clear_retry_flags(b); | 155 | BIO_clear_retry_flags(b); |
153 | if (ret <= 0) | 156 | if (ret <= 0) { |
154 | { | ||
155 | if (BIO_fd_should_retry(ret)) | 157 | if (BIO_fd_should_retry(ret)) |
156 | BIO_set_retry_read(b); | 158 | BIO_set_retry_read(b); |
157 | } | ||
158 | } | 159 | } |
159 | return(ret); | ||
160 | } | 160 | } |
161 | return (ret); | ||
162 | } | ||
161 | 163 | ||
162 | static int fd_write(BIO *b, const char *in, int inl) | 164 | static int |
163 | { | 165 | fd_write(BIO *b, const char *in, int inl) |
166 | { | ||
164 | int ret; | 167 | int ret; |
165 | errno = 0; | 168 | errno = 0; |
166 | ret=UP_write(b->num,in,inl); | 169 | ret = UP_write(b->num, in, inl); |
167 | BIO_clear_retry_flags(b); | 170 | BIO_clear_retry_flags(b); |
168 | if (ret <= 0) | 171 | if (ret <= 0) { |
169 | { | ||
170 | if (BIO_fd_should_retry(ret)) | 172 | if (BIO_fd_should_retry(ret)) |
171 | BIO_set_retry_write(b); | 173 | BIO_set_retry_write(b); |
172 | } | ||
173 | return(ret); | ||
174 | } | 174 | } |
175 | return (ret); | ||
176 | } | ||
175 | 177 | ||
176 | static long fd_ctrl(BIO *b, int cmd, long num, void *ptr) | 178 | static long |
177 | { | 179 | fd_ctrl(BIO *b, int cmd, long num, void *ptr) |
178 | long ret=1; | 180 | { |
181 | long ret = 1; | ||
179 | int *ip; | 182 | int *ip; |
180 | 183 | ||
181 | switch (cmd) | 184 | switch (cmd) { |
182 | { | ||
183 | case BIO_CTRL_RESET: | 185 | case BIO_CTRL_RESET: |
184 | num=0; | 186 | num = 0; |
185 | case BIO_C_FILE_SEEK: | 187 | case BIO_C_FILE_SEEK: |
186 | ret=(long)UP_lseek(b->num,num,0); | 188 | ret = (long)UP_lseek(b->num, num, 0); |
187 | break; | 189 | break; |
188 | case BIO_C_FILE_TELL: | 190 | case BIO_C_FILE_TELL: |
189 | case BIO_CTRL_INFO: | 191 | case BIO_CTRL_INFO: |
190 | ret=(long)UP_lseek(b->num,0,1); | 192 | ret = (long)UP_lseek(b->num, 0, 1); |
191 | break; | 193 | break; |
192 | case BIO_C_SET_FD: | 194 | case BIO_C_SET_FD: |
193 | fd_free(b); | 195 | fd_free(b); |
194 | b->num= *((int *)ptr); | 196 | b->num= *((int *)ptr); |
195 | b->shutdown=(int)num; | 197 | b->shutdown = (int)num; |
196 | b->init=1; | 198 | b->init = 1; |
197 | break; | 199 | break; |
198 | case BIO_C_GET_FD: | 200 | case BIO_C_GET_FD: |
199 | if (b->init) | 201 | if (b->init) { |
200 | { | 202 | ip = (int *)ptr; |
201 | ip=(int *)ptr; | 203 | if (ip != NULL) |
202 | if (ip != NULL) *ip=b->num; | 204 | *ip = b->num; |
203 | ret=b->num; | 205 | ret = b->num; |
204 | } | 206 | } else |
205 | else | 207 | ret = -1; |
206 | ret= -1; | ||
207 | break; | 208 | break; |
208 | case BIO_CTRL_GET_CLOSE: | 209 | case BIO_CTRL_GET_CLOSE: |
209 | ret=b->shutdown; | 210 | ret = b->shutdown; |
210 | break; | 211 | break; |
211 | case BIO_CTRL_SET_CLOSE: | 212 | case BIO_CTRL_SET_CLOSE: |
212 | b->shutdown=(int)num; | 213 | b->shutdown = (int)num; |
213 | break; | 214 | break; |
214 | case BIO_CTRL_PENDING: | 215 | case BIO_CTRL_PENDING: |
215 | case BIO_CTRL_WPENDING: | 216 | case BIO_CTRL_WPENDING: |
216 | ret=0; | 217 | ret = 0; |
217 | break; | 218 | break; |
218 | case BIO_CTRL_DUP: | 219 | case BIO_CTRL_DUP: |
219 | case BIO_CTRL_FLUSH: | 220 | case BIO_CTRL_FLUSH: |
220 | ret=1; | 221 | ret = 1; |
221 | break; | 222 | break; |
222 | default: | 223 | default: |
223 | ret=0; | 224 | ret = 0; |
224 | break; | 225 | break; |
225 | } | ||
226 | return(ret); | ||
227 | } | 226 | } |
227 | return (ret); | ||
228 | } | ||
228 | 229 | ||
229 | static int fd_puts(BIO *bp, const char *str) | 230 | static int |
230 | { | 231 | fd_puts(BIO *bp, const char *str) |
231 | int n,ret; | 232 | { |
233 | int n, ret; | ||
232 | 234 | ||
233 | n=strlen(str); | 235 | n = strlen(str); |
234 | ret=fd_write(bp,str,n); | 236 | ret = fd_write(bp, str, n); |
235 | return(ret); | 237 | return (ret); |
236 | } | 238 | } |
237 | 239 | ||
238 | static int fd_gets(BIO *bp, char *buf, int size) | 240 | static int |
239 | { | 241 | fd_gets(BIO *bp, char *buf, int size) |
240 | int ret=0; | 242 | { |
241 | char *ptr=buf; | 243 | int ret = 0; |
242 | char *end=buf+size-1; | 244 | char *ptr = buf; |
245 | char *end = buf + size - 1; | ||
243 | 246 | ||
244 | while ( (ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n') ) | 247 | while ((ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n')) |
245 | ptr++; | 248 | ptr++; |
246 | 249 | ||
247 | ptr[0]='\0'; | 250 | ptr[0] = '\0'; |
248 | 251 | ||
249 | if (buf[0] != '\0') | 252 | if (buf[0] != '\0') |
250 | ret=strlen(buf); | 253 | ret = strlen(buf); |
251 | return(ret); | 254 | return (ret); |
252 | } | 255 | } |
253 | 256 | ||
254 | int BIO_fd_should_retry(int i) | 257 | int |
255 | { | 258 | BIO_fd_should_retry(int i) |
259 | { | ||
256 | int err; | 260 | int err; |
257 | 261 | ||
258 | if ((i == 0) || (i == -1)) | 262 | if ((i == 0) || (i == -1)) { |
259 | { | 263 | err = errno; |
260 | err=errno; | ||
261 | 264 | ||
262 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ | 265 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ |
263 | if ((i == -1) && (err == 0)) | 266 | if ((i == -1) && (err == 0)) |
264 | return(1); | 267 | return (1); |
265 | #endif | 268 | #endif |
266 | 269 | ||
267 | return(BIO_fd_non_fatal_error(err)); | 270 | return (BIO_fd_non_fatal_error(err)); |
268 | } | ||
269 | return(0); | ||
270 | } | 271 | } |
272 | return (0); | ||
273 | } | ||
271 | 274 | ||
272 | int BIO_fd_non_fatal_error(int err) | 275 | int |
273 | { | 276 | BIO_fd_non_fatal_error(int err) |
274 | switch (err) | 277 | { |
275 | { | 278 | switch (err) { |
276 | 279 | ||
277 | #ifdef EWOULDBLOCK | 280 | #ifdef EWOULDBLOCK |
278 | # ifdef WSAEWOULDBLOCK | 281 | # ifdef WSAEWOULDBLOCK |
@@ -309,11 +312,11 @@ int BIO_fd_non_fatal_error(int err) | |||
309 | #ifdef EALREADY | 312 | #ifdef EALREADY |
310 | case EALREADY: | 313 | case EALREADY: |
311 | #endif | 314 | #endif |
312 | return(1); | 315 | return (1); |
313 | /* break; */ | 316 | /* break; */ |
314 | default: | 317 | default: |
315 | break; | 318 | break; |
316 | } | ||
317 | return(0); | ||
318 | } | 319 | } |
320 | return (0); | ||
321 | } | ||
319 | #endif | 322 | #endif |