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.c118
1 files changed, 40 insertions, 78 deletions
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
index d907a2867b..d336b99fe8 100644
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ b/src/lib/libcrypto/bio/bss_sock.c
@@ -62,10 +62,9 @@
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 67#ifndef BIO_FD
68#ifndef NOPROTO
69static int sock_write(BIO *h,char *buf,int num); 68static int sock_write(BIO *h,char *buf,int num);
70static int sock_read(BIO *h,char *buf,int size); 69static int sock_read(BIO *h,char *buf,int size);
71static int sock_puts(BIO *h,char *str); 70static int sock_puts(BIO *h,char *str);
@@ -74,18 +73,7 @@ static int sock_new(BIO *h);
74static int sock_free(BIO *data); 73static int sock_free(BIO *data);
75int BIO_sock_should_retry(int s); 74int BIO_sock_should_retry(int s);
76#else 75#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 76
88#ifndef NOPROTO
89static int fd_write(BIO *h,char *buf,int num); 77static int fd_write(BIO *h,char *buf,int num);
90static int fd_read(BIO *h,char *buf,int size); 78static int fd_read(BIO *h,char *buf,int size);
91static int fd_puts(BIO *h,char *str); 79static int fd_puts(BIO *h,char *str);
@@ -93,15 +81,6 @@ static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2);
93static int fd_new(BIO *h); 81static int fd_new(BIO *h);
94static int fd_free(BIO *data); 82static int fd_free(BIO *data);
95int BIO_fd_should_retry(int s); 83int 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 84#endif
106 85
107#ifndef BIO_FD 86#ifndef BIO_FD
@@ -118,7 +97,7 @@ static BIO_METHOD methods_sockp=
118 sock_free, 97 sock_free,
119 }; 98 };
120 99
121BIO_METHOD *BIO_s_socket() 100BIO_METHOD *BIO_s_socket(void)
122 { 101 {
123 return(&methods_sockp); 102 return(&methods_sockp);
124 } 103 }
@@ -135,19 +114,17 @@ static BIO_METHOD methods_fdp=
135 fd_free, 114 fd_free,
136 }; 115 };
137 116
138BIO_METHOD *BIO_s_fd() 117BIO_METHOD *BIO_s_fd(void)
139 { 118 {
140 return(&methods_fdp); 119 return(&methods_fdp);
141 } 120 }
142#endif 121#endif
143 122
144#ifndef BIO_FD 123#ifndef BIO_FD
145BIO *BIO_new_socket(fd,close_flag) 124BIO *BIO_new_socket(int fd, int close_flag)
146#else 125#else
147BIO *BIO_new_fd(fd,close_flag) 126BIO *BIO_new_fd(int fd,int close_flag)
148#endif 127#endif
149int fd;
150int close_flag;
151 { 128 {
152 BIO *ret; 129 BIO *ret;
153 130
@@ -162,11 +139,10 @@ int close_flag;
162 } 139 }
163 140
164#ifndef BIO_FD 141#ifndef BIO_FD
165static int sock_new(bi) 142static int sock_new(BIO *bi)
166#else 143#else
167static int fd_new(bi) 144static int fd_new(BIO *bi)
168#endif 145#endif
169BIO *bi;
170 { 146 {
171 bi->init=0; 147 bi->init=0;
172 bi->num=0; 148 bi->num=0;
@@ -176,11 +152,10 @@ BIO *bi;
176 } 152 }
177 153
178#ifndef BIO_FD 154#ifndef BIO_FD
179static int sock_free(a) 155static int sock_free(BIO *a)
180#else 156#else
181static int fd_free(a) 157static int fd_free(BIO *a)
182#endif 158#endif
183BIO *a;
184 { 159 {
185 if (a == NULL) return(0); 160 if (a == NULL) return(0);
186 if (a->shutdown) 161 if (a->shutdown)
@@ -189,11 +164,7 @@ BIO *a;
189 { 164 {
190#ifndef BIO_FD 165#ifndef BIO_FD
191 shutdown(a->num,2); 166 shutdown(a->num,2);
192# ifdef WINDOWS
193 closesocket(a->num); 167 closesocket(a->num);
194# else
195 close(a->num);
196# endif
197#else /* BIO_FD */ 168#else /* BIO_FD */
198 close(a->num); 169 close(a->num);
199#endif 170#endif
@@ -206,21 +177,18 @@ BIO *a;
206 } 177 }
207 178
208#ifndef BIO_FD 179#ifndef BIO_FD
209static int sock_read(b,out,outl) 180static int sock_read(BIO *b, char *out, int outl)
210#else 181#else
211static int fd_read(b,out,outl) 182static int fd_read(BIO *b, char *out,int outl)
212#endif 183#endif
213BIO *b;
214char *out;
215int outl;
216 { 184 {
217 int ret=0; 185 int ret=0;
218 186
219 if (out != NULL) 187 if (out != NULL)
220 { 188 {
221#if defined(WINDOWS) && !defined(BIO_FD) 189#ifndef BIO_FD
222 clear_socket_error(); 190 clear_socket_error();
223 ret=recv(b->num,out,outl,0); 191 ret=readsocket(b->num,out,outl);
224#else 192#else
225 clear_sys_error(); 193 clear_sys_error();
226 ret=read(b->num,out,outl); 194 ret=read(b->num,out,outl);
@@ -240,19 +208,16 @@ int outl;
240 } 208 }
241 209
242#ifndef BIO_FD 210#ifndef BIO_FD
243static int sock_write(b,in,inl) 211static int sock_write(BIO *b, char *in, int inl)
244#else 212#else
245static int fd_write(b,in,inl) 213static int fd_write(BIO *b, char *in, int inl)
246#endif 214#endif
247BIO *b;
248char *in;
249int inl;
250 { 215 {
251 int ret; 216 int ret;
252 217
253#if defined(WINDOWS) && !defined(BIO_FD) 218#ifndef BIO_FD
254 clear_socket_error(); 219 clear_socket_error();
255 ret=send(b->num,in,inl,0); 220 ret=writesocket(b->num,in,inl);
256#else 221#else
257 clear_sys_error(); 222 clear_sys_error();
258 ret=write(b->num,in,inl); 223 ret=write(b->num,in,inl);
@@ -271,14 +236,10 @@ int inl;
271 } 236 }
272 237
273#ifndef BIO_FD 238#ifndef BIO_FD
274static long sock_ctrl(b,cmd,num,ptr) 239static long sock_ctrl(BIO *b, int cmd, long num, char *ptr)
275#else 240#else
276static long fd_ctrl(b,cmd,num,ptr) 241static long fd_ctrl(BIO *b, int cmd, long num, char *ptr)
277#endif 242#endif
278BIO *b;
279int cmd;
280long num;
281char *ptr;
282 { 243 {
283 long ret=1; 244 long ret=1;
284 int *ip; 245 int *ip;
@@ -286,14 +247,21 @@ char *ptr;
286 switch (cmd) 247 switch (cmd)
287 { 248 {
288 case BIO_CTRL_RESET: 249 case BIO_CTRL_RESET:
250 num=0;
251 case BIO_C_FILE_SEEK:
289#ifdef BIO_FD 252#ifdef BIO_FD
290 ret=(long)lseek(b->num,0,0); 253 ret=(long)lseek(b->num,num,0);
291#else 254#else
292 ret=0; 255 ret=0;
293#endif 256#endif
294 break; 257 break;
258 case BIO_C_FILE_TELL:
295 case BIO_CTRL_INFO: 259 case BIO_CTRL_INFO:
260#ifdef BIO_FD
261 ret=(long)lseek(b->num,0,1);
262#else
296 ret=0; 263 ret=0;
264#endif
297 break; 265 break;
298 case BIO_C_SET_FD: 266 case BIO_C_SET_FD:
299#ifndef BIO_FD 267#ifndef BIO_FD
@@ -329,7 +297,6 @@ char *ptr;
329 case BIO_CTRL_FLUSH: 297 case BIO_CTRL_FLUSH:
330 ret=1; 298 ret=1;
331 break; 299 break;
332 break;
333 default: 300 default:
334 ret=0; 301 ret=0;
335 break; 302 break;
@@ -338,22 +305,17 @@ char *ptr;
338 } 305 }
339 306
340#ifdef undef 307#ifdef undef
341static int sock_gets(bp,buf,size) 308static int sock_gets(BIO *bp, char *buf,int size)
342BIO *bp;
343char *buf;
344int size;
345 { 309 {
346 return(-1); 310 return(-1);
347 } 311 }
348#endif 312#endif
349 313
350#ifndef BIO_FD 314#ifndef BIO_FD
351static int sock_puts(bp,str) 315static int sock_puts(BIO *bp, char *str)
352#else 316#else
353static int fd_puts(bp,str) 317static int fd_puts(BIO *bp, char *str)
354#endif 318#endif
355BIO *bp;
356char *str;
357 { 319 {
358 int n,ret; 320 int n,ret;
359 321
@@ -367,23 +329,22 @@ char *str;
367 } 329 }
368 330
369#ifndef BIO_FD 331#ifndef BIO_FD
370int BIO_sock_should_retry(i) 332int BIO_sock_should_retry(int i)
371#else 333#else
372int BIO_fd_should_retry(i) 334int BIO_fd_should_retry(int i)
373#endif 335#endif
374int i;
375 { 336 {
376 int err; 337 int err;
377 338
378 if ((i == 0) || (i == -1)) 339 if ((i == 0) || (i == -1))
379 { 340 {
380#if !defined(BIO_FD) && defined(WINDOWS) 341#ifndef BIO_FD
381 err=get_last_socket_error(); 342 err=get_last_socket_error();
382#else 343#else
383 err=get_last_sys_error(); 344 err=get_last_sys_error();
384#endif 345#endif
385 346
386#if defined(WINDOWS) /* more microsoft stupidity */ 347#if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
387 if ((i == -1) && (err == 0)) 348 if ((i == -1) && (err == 0))
388 return(1); 349 return(1);
389#endif 350#endif
@@ -398,11 +359,10 @@ int i;
398 } 359 }
399 360
400#ifndef BIO_FD 361#ifndef BIO_FD
401int BIO_sock_non_fatal_error(err) 362int BIO_sock_non_fatal_error(int err)
402#else 363#else
403int BIO_fd_non_fatal_error(err) 364int BIO_fd_non_fatal_error(int err)
404#endif 365#endif
405int err;
406 { 366 {
407 switch (err) 367 switch (err)
408 { 368 {
@@ -411,8 +371,10 @@ int err;
411 case WSAEWOULDBLOCK: 371 case WSAEWOULDBLOCK:
412# endif 372# endif
413 373
414# if defined(WSAENOTCONN) 374# if 0 /* This appears to always be an error */
375# if defined(WSAENOTCONN)
415 case WSAENOTCONN: 376 case WSAENOTCONN:
377# endif
416# endif 378# endif
417#endif 379#endif
418 380
@@ -452,7 +414,7 @@ int err;
452 case EALREADY: 414 case EALREADY:
453#endif 415#endif
454 return(1); 416 return(1);
455 break; 417 /* break; */
456 default: 418 default:
457 break; 419 break;
458 } 420 }