summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bio_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio/bio_lib.c')
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
index b72688ea90..cf8e6150fd 100644
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -63,7 +63,7 @@
63#include <openssl/bio.h> 63#include <openssl/bio.h>
64#include <openssl/stack.h> 64#include <openssl/stack.h>
65 65
66static STACK *bio_meth=NULL; 66static STACK_OF(CRYPTO_EX_DATA_FUNCS) *bio_meth=NULL;
67static int bio_meth_num=0; 67static int bio_meth_num=0;
68 68
69BIO *BIO_new(BIO_METHOD *method) 69BIO *BIO_new(BIO_METHOD *method)
@@ -100,7 +100,7 @@ int BIO_set(BIO *bio, BIO_METHOD *method)
100 bio->references=1; 100 bio->references=1;
101 bio->num_read=0L; 101 bio->num_read=0L;
102 bio->num_write=0L; 102 bio->num_write=0L;
103 CRYPTO_new_ex_data(bio_meth,(char *)bio,&bio->ex_data); 103 CRYPTO_new_ex_data(bio_meth,bio,&bio->ex_data);
104 if (method->create != NULL) 104 if (method->create != NULL)
105 if (!method->create(bio)) 105 if (!method->create(bio))
106 return(0); 106 return(0);
@@ -129,7 +129,7 @@ int BIO_free(BIO *a)
129 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0)) 129 ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
130 return(i); 130 return(i);
131 131
132 CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); 132 CRYPTO_free_ex_data(bio_meth,a,&a->ex_data);
133 133
134 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); 134 if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
135 ret=a->method->destroy(a); 135 ret=a->method->destroy(a);
@@ -317,16 +317,43 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
317 return(ret); 317 return(ret);
318 } 318 }
319 319
320long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)())
321 {
322 long ret;
323 long (*cb)();
324
325 if (b == NULL) return(0);
326
327 if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
328 {
329 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
330 return(-2);
331 }
332
333 cb=b->callback;
334
335 if ((cb != NULL) &&
336 ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0))
337 return(ret);
338
339 ret=b->method->callback_ctrl(b,cmd,fp);
340
341 if (cb != NULL)
342 ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd,
343 0,ret);
344 return(ret);
345 }
346
320/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros 347/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
321 * do; but those macros have inappropriate return type, and for interfacing 348 * do; but those macros have inappropriate return type, and for interfacing
322 * from other programming languages, C macros aren't much of a help anyway. */ 349 * from other programming languages, C macros aren't much of a help anyway. */
323size_t BIO_ctrl_pending(BIO *bio) 350size_t BIO_ctrl_pending(BIO *bio)
324 { 351 {
325 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); 352 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
326 } 353 }
327 354
328size_t BIO_ctrl_wpending(BIO *bio) 355size_t BIO_ctrl_wpending(BIO *bio)
329 { 356 {
330 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); 357 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
331 } 358 }
332 359
@@ -476,21 +503,32 @@ void BIO_copy_next_retry(BIO *b)
476 b->retry_reason=b->next_bio->retry_reason; 503 b->retry_reason=b->next_bio->retry_reason;
477 } 504 }
478 505
479int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), 506int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
480 int (*dup_func)(), void (*free_func)()) 507 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
481 { 508 {
482 bio_meth_num++; 509 bio_meth_num++;
483 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, 510 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth,
484 argl,argp,new_func,dup_func,free_func)); 511 argl,argp,new_func,dup_func,free_func));
485 } 512 }
486 513
487int BIO_set_ex_data(BIO *bio, int idx, char *data) 514int BIO_set_ex_data(BIO *bio, int idx, void *data)
488 { 515 {
489 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); 516 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
490 } 517 }
491 518
492char *BIO_get_ex_data(BIO *bio, int idx) 519void *BIO_get_ex_data(BIO *bio, int idx)
493 { 520 {
494 return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); 521 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
495 } 522 }
496 523
524unsigned long BIO_number_read(BIO *bio)
525{
526 if(bio) return bio->num_read;
527 return 0;
528}
529
530unsigned long BIO_number_written(BIO *bio)
531{
532 if(bio) return bio->num_write;
533 return 0;
534}