summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bss_sock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio/bss_sock.c')
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c220
1 files changed, 29 insertions, 191 deletions
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
index d907a2867b..fdabd16d7e 100644
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ b/src/lib/libcrypto/bio/bss_sock.c
@@ -56,55 +56,22 @@
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>
63#define USE_SOCKETS 63#define USE_SOCKETS
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio.h" 65#include <openssl/bio.h>
66 66
67#ifndef BIO_FD 67static int sock_write(BIO *h, const char *buf, int num);
68#ifndef NOPROTO 68static int sock_read(BIO *h, char *buf, int size);
69static int sock_write(BIO *h,char *buf,int num); 69static int sock_puts(BIO *h, const char *str);
70static int sock_read(BIO *h,char *buf,int size); 70static long sock_ctrl(BIO *h, int cmd, long arg1, void *arg2);
71static int sock_puts(BIO *h,char *str);
72static long sock_ctrl(BIO *h,int cmd,long arg1,char *arg2);
73static int sock_new(BIO *h); 71static int sock_new(BIO *h);
74static int sock_free(BIO *data); 72static int sock_free(BIO *data);
75int BIO_sock_should_retry(int s); 73int BIO_sock_should_retry(int s);
76#else
77static int sock_write();
78static int sock_read();
79static int sock_puts();
80static long sock_ctrl();
81static int sock_new();
82static int sock_free();
83int BIO_sock_should_retry();
84#endif
85
86#else
87
88#ifndef NOPROTO
89static int fd_write(BIO *h,char *buf,int num);
90static int fd_read(BIO *h,char *buf,int size);
91static int fd_puts(BIO *h,char *str);
92static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2);
93static int fd_new(BIO *h);
94static int fd_free(BIO *data);
95int BIO_fd_should_retry(int s);
96#else
97static int fd_write();
98static int fd_read();
99static int fd_puts();
100static long fd_ctrl();
101static int fd_new();
102static int fd_free();
103int BIO_fd_should_retry();
104#endif
105#endif
106 74
107#ifndef BIO_FD
108static BIO_METHOD methods_sockp= 75static BIO_METHOD methods_sockp=
109 { 76 {
110 BIO_TYPE_SOCKET, 77 BIO_TYPE_SOCKET,
@@ -116,57 +83,25 @@ static BIO_METHOD methods_sockp=
116 sock_ctrl, 83 sock_ctrl,
117 sock_new, 84 sock_new,
118 sock_free, 85 sock_free,
86 NULL,
119 }; 87 };
120 88
121BIO_METHOD *BIO_s_socket() 89BIO_METHOD *BIO_s_socket(void)
122 { 90 {
123 return(&methods_sockp); 91 return(&methods_sockp);
124 } 92 }
125#else
126static BIO_METHOD methods_fdp=
127 {
128 BIO_TYPE_FD,"file descriptor",
129 fd_write,
130 fd_read,
131 fd_puts,
132 NULL, /* fd_gets, */
133 fd_ctrl,
134 fd_new,
135 fd_free,
136 };
137 93
138BIO_METHOD *BIO_s_fd() 94BIO *BIO_new_socket(int fd, int close_flag)
139 {
140 return(&methods_fdp);
141 }
142#endif
143
144#ifndef BIO_FD
145BIO *BIO_new_socket(fd,close_flag)
146#else
147BIO *BIO_new_fd(fd,close_flag)
148#endif
149int fd;
150int close_flag;
151 { 95 {
152 BIO *ret; 96 BIO *ret;
153 97
154#ifndef BIO_FD
155 ret=BIO_new(BIO_s_socket()); 98 ret=BIO_new(BIO_s_socket());
156#else
157 ret=BIO_new(BIO_s_fd());
158#endif
159 if (ret == NULL) return(NULL); 99 if (ret == NULL) return(NULL);
160 BIO_set_fd(ret,fd,close_flag); 100 BIO_set_fd(ret,fd,close_flag);
161 return(ret); 101 return(ret);
162 } 102 }
163 103
164#ifndef BIO_FD 104static int sock_new(BIO *bi)
165static int sock_new(bi)
166#else
167static int fd_new(bi)
168#endif
169BIO *bi;
170 { 105 {
171 bi->init=0; 106 bi->init=0;
172 bi->num=0; 107 bi->num=0;
@@ -175,29 +110,14 @@ BIO *bi;
175 return(1); 110 return(1);
176 } 111 }
177 112
178#ifndef BIO_FD 113static int sock_free(BIO *a)
179static int sock_free(a)
180#else
181static int fd_free(a)
182#endif
183BIO *a;
184 { 114 {
185 if (a == NULL) return(0); 115 if (a == NULL) return(0);
186 if (a->shutdown) 116 if (a->shutdown)
187 { 117 {
188 if (a->init) 118 if (a->init)
189 { 119 {
190#ifndef BIO_FD 120 SHUTDOWN2(a->num);
191 shutdown(a->num,2);
192# ifdef WINDOWS
193 closesocket(a->num);
194# else
195 close(a->num);
196# endif
197#else /* BIO_FD */
198 close(a->num);
199#endif
200
201 } 121 }
202 a->init=0; 122 a->init=0;
203 a->flags=0; 123 a->flags=0;
@@ -205,80 +125,40 @@ BIO *a;
205 return(1); 125 return(1);
206 } 126 }
207 127
208#ifndef BIO_FD 128static int sock_read(BIO *b, char *out, int outl)
209static int sock_read(b,out,outl)
210#else
211static int fd_read(b,out,outl)
212#endif
213BIO *b;
214char *out;
215int outl;
216 { 129 {
217 int ret=0; 130 int ret=0;
218 131
219 if (out != NULL) 132 if (out != NULL)
220 { 133 {
221#if defined(WINDOWS) && !defined(BIO_FD)
222 clear_socket_error(); 134 clear_socket_error();
223 ret=recv(b->num,out,outl,0); 135 ret=readsocket(b->num,out,outl);
224#else
225 clear_sys_error();
226 ret=read(b->num,out,outl);
227#endif
228 BIO_clear_retry_flags(b); 136 BIO_clear_retry_flags(b);
229 if (ret <= 0) 137 if (ret <= 0)
230 { 138 {
231#ifndef BIO_FD
232 if (BIO_sock_should_retry(ret)) 139 if (BIO_sock_should_retry(ret))
233#else
234 if (BIO_fd_should_retry(ret))
235#endif
236 BIO_set_retry_read(b); 140 BIO_set_retry_read(b);
237 } 141 }
238 } 142 }
239 return(ret); 143 return(ret);
240 } 144 }
241 145
242#ifndef BIO_FD 146static int sock_write(BIO *b, const char *in, int inl)
243static int sock_write(b,in,inl)
244#else
245static int fd_write(b,in,inl)
246#endif
247BIO *b;
248char *in;
249int inl;
250 { 147 {
251 int ret; 148 int ret;
252 149
253#if defined(WINDOWS) && !defined(BIO_FD)
254 clear_socket_error(); 150 clear_socket_error();
255 ret=send(b->num,in,inl,0); 151 ret=writesocket(b->num,in,inl);
256#else
257 clear_sys_error();
258 ret=write(b->num,in,inl);
259#endif
260 BIO_clear_retry_flags(b); 152 BIO_clear_retry_flags(b);
261 if (ret <= 0) 153 if (ret <= 0)
262 { 154 {
263#ifndef BIO_FD
264 if (BIO_sock_should_retry(ret)) 155 if (BIO_sock_should_retry(ret))
265#else
266 if (BIO_fd_should_retry(ret))
267#endif
268 BIO_set_retry_write(b); 156 BIO_set_retry_write(b);
269 } 157 }
270 return(ret); 158 return(ret);
271 } 159 }
272 160
273#ifndef BIO_FD 161static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
274static long sock_ctrl(b,cmd,num,ptr)
275#else
276static long fd_ctrl(b,cmd,num,ptr)
277#endif
278BIO *b;
279int cmd;
280long num;
281char *ptr;
282 { 162 {
283 long ret=1; 163 long ret=1;
284 int *ip; 164 int *ip;
@@ -286,21 +166,16 @@ char *ptr;
286 switch (cmd) 166 switch (cmd)
287 { 167 {
288 case BIO_CTRL_RESET: 168 case BIO_CTRL_RESET:
289#ifdef BIO_FD 169 num=0;
290 ret=(long)lseek(b->num,0,0); 170 case BIO_C_FILE_SEEK:
291#else
292 ret=0; 171 ret=0;
293#endif
294 break; 172 break;
173 case BIO_C_FILE_TELL:
295 case BIO_CTRL_INFO: 174 case BIO_CTRL_INFO:
296 ret=0; 175 ret=0;
297 break; 176 break;
298 case BIO_C_SET_FD: 177 case BIO_C_SET_FD:
299#ifndef BIO_FD
300 sock_free(b); 178 sock_free(b);
301#else
302 fd_free(b);
303#endif
304 b->num= *((int *)ptr); 179 b->num= *((int *)ptr);
305 b->shutdown=(int)num; 180 b->shutdown=(int)num;
306 b->init=1; 181 b->init=1;
@@ -329,7 +204,6 @@ char *ptr;
329 case BIO_CTRL_FLUSH: 204 case BIO_CTRL_FLUSH:
330 ret=1; 205 ret=1;
331 break; 206 break;
332 break;
333 default: 207 default:
334 ret=0; 208 ret=0;
335 break; 209 break;
@@ -337,82 +211,46 @@ char *ptr;
337 return(ret); 211 return(ret);
338 } 212 }
339 213
340#ifdef undef 214static int sock_puts(BIO *bp, const char *str)
341static int sock_gets(bp,buf,size)
342BIO *bp;
343char *buf;
344int size;
345 {
346 return(-1);
347 }
348#endif
349
350#ifndef BIO_FD
351static int sock_puts(bp,str)
352#else
353static int fd_puts(bp,str)
354#endif
355BIO *bp;
356char *str;
357 { 215 {
358 int n,ret; 216 int n,ret;
359 217
360 n=strlen(str); 218 n=strlen(str);
361#ifndef BIO_FD
362 ret=sock_write(bp,str,n); 219 ret=sock_write(bp,str,n);
363#else
364 ret=fd_write(bp,str,n);
365#endif
366 return(ret); 220 return(ret);
367 } 221 }
368 222
369#ifndef BIO_FD 223int BIO_sock_should_retry(int i)
370int BIO_sock_should_retry(i)
371#else
372int BIO_fd_should_retry(i)
373#endif
374int i;
375 { 224 {
376 int err; 225 int err;
377 226
378 if ((i == 0) || (i == -1)) 227 if ((i == 0) || (i == -1))
379 { 228 {
380#if !defined(BIO_FD) && defined(WINDOWS)
381 err=get_last_socket_error(); 229 err=get_last_socket_error();
382#else
383 err=get_last_sys_error();
384#endif
385 230
386#if defined(WINDOWS) /* more microsoft stupidity */ 231#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
387 if ((i == -1) && (err == 0)) 232 if ((i == -1) && (err == 0))
388 return(1); 233 return(1);
389#endif 234#endif
390 235
391#ifndef BIO_FD
392 return(BIO_sock_non_fatal_error(err)); 236 return(BIO_sock_non_fatal_error(err));
393#else
394 return(BIO_fd_non_fatal_error(err));
395#endif
396 } 237 }
397 return(0); 238 return(0);
398 } 239 }
399 240
400#ifndef BIO_FD 241int BIO_sock_non_fatal_error(int err)
401int BIO_sock_non_fatal_error(err)
402#else
403int BIO_fd_non_fatal_error(err)
404#endif
405int err;
406 { 242 {
407 switch (err) 243 switch (err)
408 { 244 {
409#if !defined(BIO_FD) && defined(WINDOWS) 245#if defined(OPENSSL_SYS_WINDOWS)
410# if defined(WSAEWOULDBLOCK) 246# if defined(WSAEWOULDBLOCK)
411 case WSAEWOULDBLOCK: 247 case WSAEWOULDBLOCK:
412# endif 248# endif
413 249
414# if defined(WSAENOTCONN) 250# if 0 /* This appears to always be an error */
251# if defined(WSAENOTCONN)
415 case WSAENOTCONN: 252 case WSAENOTCONN:
253# endif
416# endif 254# endif
417#endif 255#endif
418 256
@@ -452,7 +290,7 @@ int err;
452 case EALREADY: 290 case EALREADY:
453#endif 291#endif
454 return(1); 292 return(1);
455 break; 293 /* break; */
456 default: 294 default:
457 break; 295 break;
458 } 296 }