0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 /*. * Copyright
0010: 28 43 29 20 31 39 39 37 2d 32 30 30 30 20 4d 61 (C) 1997-2000 Ma
0020: 74 74 20 4e 65 77 6d 61 6e 20 3c 6d 61 74 74 40 tt Newman <matt@
0030: 6e 6f 76 61 64 69 67 6d 2e 63 6f 6d 3e 0a 20 2a novadigm.com>. *
0040: 0a 20 2a 20 50 72 6f 76 69 64 65 73 20 42 49 4f . * Provides BIO
0050: 20 6c 61 79 65 72 20 74 6f 20 69 6e 74 65 72 66 layer to interf
0060: 61 63 65 20 6f 70 65 6e 73 73 6c 20 74 6f 20 54 ace openssl to T
0070: 63 6c 2e 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 cl.. */..#includ
0080: 65 20 22 74 6c 73 49 6e 74 2e 68 22 0a 0a 23 69 e "tlsInt.h"..#i
0090: 66 64 65 66 20 54 43 4c 54 4c 53 5f 4f 50 45 4e fdef TCLTLS_OPEN
00a0: 53 53 4c 5f 50 52 45 5f 31 5f 31 5f 41 50 49 0a SSL_PRE_1_1_API.
00b0: 23 64 65 66 69 6e 65 20 42 49 4f 5f 67 65 74 5f #define BIO_get_
00c0: 64 61 74 61 28 62 69 6f 29 20 20 20 20 20 20 20 data(bio)
00d0: 20 20 20 20 20 20 20 20 20 28 28 62 69 6f 29 2d ((bio)-
00e0: 3e 70 74 72 29 0a 23 64 65 66 69 6e 65 20 42 49 >ptr).#define BI
00f0: 4f 5f 67 65 74 5f 69 6e 69 74 28 62 69 6f 29 20 O_get_init(bio)
0100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 28 (
0110: 28 62 69 6f 29 2d 3e 69 6e 69 74 29 0a 23 64 65 (bio)->init).#de
0120: 66 69 6e 65 20 42 49 4f 5f 67 65 74 5f 73 68 75 fine BIO_get_shu
0130: 74 64 6f 77 6e 28 62 69 6f 29 20 20 20 20 20 20 tdown(bio)
0140: 20 20 20 20 20 20 28 28 62 69 6f 29 2d 3e 73 68 ((bio)->sh
0150: 75 74 64 6f 77 6e 29 0a 23 64 65 66 69 6e 65 20 utdown).#define
0160: 42 49 4f 5f 73 65 74 5f 64 61 74 61 28 62 69 6f BIO_set_data(bio
0170: 2c 20 76 61 6c 29 20 20 20 20 20 20 20 20 20 20 , val)
0180: 20 28 62 69 6f 29 2d 3e 70 74 72 20 3d 20 28 76 (bio)->ptr = (v
0190: 61 6c 29 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f al).#define BIO_
01a0: 73 65 74 5f 69 6e 69 74 28 62 69 6f 2c 20 76 61 set_init(bio, va
01b0: 6c 29 20 20 20 20 20 20 20 20 20 20 20 28 62 69 l) (bi
01c0: 6f 29 2d 3e 69 6e 69 74 20 3d 20 28 76 61 6c 29 o)->init = (val)
01d0: 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f 73 65 74 .#define BIO_set
01e0: 5f 73 68 75 74 64 6f 77 6e 28 62 69 6f 2c 20 76 _shutdown(bio, v
01f0: 61 6c 29 20 20 20 20 20 20 20 28 62 69 6f 29 2d al) (bio)-
0200: 3e 73 68 75 74 64 6f 77 6e 20 3d 20 28 76 61 6c >shutdown = (val
0210: 29 0a 0a 2f 2a 20 58 58 58 3a 20 54 68 69 73 20 )../* XXX: This
0220: 61 73 73 75 6d 65 73 20 74 68 65 20 76 61 72 69 assumes the vari
0230: 61 62 6c 65 20 62 65 69 6e 67 20 61 73 73 69 67 able being assig
0240: 6e 65 64 20 74 6f 20 69 73 20 42 69 6f 4d 65 74 ned to is BioMet
0250: 68 6f 64 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 hods */.#define
0260: 42 49 4f 5f 6d 65 74 68 5f 6e 65 77 28 74 79 70 BIO_meth_new(typ
0270: 65 5f 2c 20 6e 61 6d 65 5f 29 20 20 20 20 20 20 e_, name_)
0280: 20 28 42 49 4f 5f 4d 45 54 48 4f 44 20 2a 29 54 (BIO_METHOD *)T
0290: 63 6c 5f 41 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 cl_Alloc(sizeof(
02a0: 42 49 4f 5f 4d 45 54 48 4f 44 29 29 3b 20 5c 0a BIO_METHOD)); \.
02b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
02c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
02d0: 20 20 20 20 20 20 20 20 20 6d 65 6d 73 65 74 28 memset(
02e0: 42 69 6f 4d 65 74 68 6f 64 73 2c 20 30 2c 20 73 BioMethods, 0, s
02f0: 69 7a 65 6f 66 28 42 49 4f 5f 4d 45 54 48 4f 44 izeof(BIO_METHOD
0300: 29 29 3b 20 5c 0a 20 20 20 20 20 20 20 20 20 20 )); \.
0310: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0320: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 42 B
0330: 69 6f 4d 65 74 68 6f 64 73 2d 3e 74 79 70 65 20 ioMethods->type
0340: 3d 20 74 79 70 65 5f 3b 20 5c 0a 20 20 20 20 20 = type_; \.
0350: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0360: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0370: 20 20 20 20 42 69 6f 4d 65 74 68 6f 64 73 2d 3e BioMethods->
0380: 6e 61 6d 65 20 3d 20 6e 61 6d 65 5f 3b 0a 23 64 name = name_;.#d
0390: 65 66 69 6e 65 20 42 49 4f 5f 6d 65 74 68 5f 73 efine BIO_meth_s
03a0: 65 74 5f 77 72 69 74 65 28 62 69 6f 2c 20 76 61 et_write(bio, va
03b0: 6c 29 20 20 20 20 20 28 62 69 6f 29 2d 3e 62 77 l) (bio)->bw
03c0: 72 69 74 65 20 3d 20 76 61 6c 3b 0a 23 64 65 66 rite = val;.#def
03d0: 69 6e 65 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74 ine BIO_meth_set
03e0: 5f 72 65 61 64 28 62 69 6f 2c 20 76 61 6c 29 20 _read(bio, val)
03f0: 20 20 20 20 20 28 62 69 6f 29 2d 3e 62 72 65 61 (bio)->brea
0400: 64 20 3d 20 76 61 6c 3b 0a 23 64 65 66 69 6e 65 d = val;.#define
0410: 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 70 75 BIO_meth_set_pu
0420: 74 73 28 62 69 6f 2c 20 76 61 6c 29 20 20 20 20 ts(bio, val)
0430: 20 20 28 62 69 6f 29 2d 3e 62 70 75 74 73 20 3d (bio)->bputs =
0440: 20 76 61 6c 3b 0a 23 64 65 66 69 6e 65 20 42 49 val;.#define BI
0450: 4f 5f 6d 65 74 68 5f 73 65 74 5f 63 74 72 6c 28 O_meth_set_ctrl(
0460: 62 69 6f 2c 20 76 61 6c 29 20 20 20 20 20 20 28 bio, val) (
0470: 62 69 6f 29 2d 3e 63 74 72 6c 20 3d 20 76 61 6c bio)->ctrl = val
0480: 3b 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f 6d 65 ;.#define BIO_me
0490: 74 68 5f 73 65 74 5f 63 72 65 61 74 65 28 62 69 th_set_create(bi
04a0: 6f 2c 20 76 61 6c 29 20 20 20 20 28 62 69 6f 29 o, val) (bio)
04b0: 2d 3e 63 72 65 61 74 65 20 3d 20 76 61 6c 3b 0a ->create = val;.
04c0: 23 64 65 66 69 6e 65 20 42 49 4f 5f 6d 65 74 68 #define BIO_meth
04d0: 5f 73 65 74 5f 64 65 73 74 72 6f 79 28 62 69 6f _set_destroy(bio
04e0: 2c 20 76 61 6c 29 20 20 20 28 62 69 6f 29 2d 3e , val) (bio)->
04f0: 64 65 73 74 72 6f 79 20 3d 20 76 61 6c 3b 0a 23 destroy = val;.#
0500: 65 6e 64 69 66 0a 0a 2f 2a 0a 20 2a 20 46 6f 72 endif../*. * For
0510: 77 61 72 64 20 64 65 63 6c 61 72 61 74 69 6f 6e ward declaration
0520: 73 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e s. */..static in
0530: 74 20 42 69 6f 57 72 69 74 65 09 5f 41 4e 53 49 t BioWrite._ANSI
0540: 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68 2c _ARGS_ ((BIO *h,
0550: 20 43 4f 4e 53 54 20 63 68 61 72 20 2a 62 75 66 CONST char *buf
0560: 2c 20 69 6e 74 20 6e 75 6d 29 29 3b 0a 73 74 61 , int num));.sta
0570: 74 69 63 20 69 6e 74 20 42 69 6f 52 65 61 64 09 tic int BioRead.
0580: 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49 _ANSI_ARGS_ ((BI
0590: 4f 20 2a 68 2c 20 63 68 61 72 20 2a 62 75 66 2c O *h, char *buf,
05a0: 20 69 6e 74 20 6e 75 6d 29 29 3b 0a 73 74 61 74 int num));.stat
05b0: 69 63 20 69 6e 74 20 42 69 6f 50 75 74 73 09 5f ic int BioPuts._
05c0: 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49 4f ANSI_ARGS_ ((BIO
05d0: 20 2a 68 2c 20 43 4f 4e 53 54 20 63 68 61 72 20 *h, CONST char
05e0: 2a 73 74 72 29 29 3b 0a 73 74 61 74 69 63 20 6c *str));.static l
05f0: 6f 6e 67 20 42 69 6f 43 74 72 6c 09 5f 41 4e 53 ong BioCtrl._ANS
0600: 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68 I_ARGS_ ((BIO *h
0610: 2c 20 69 6e 74 20 63 6d 64 2c 20 6c 6f 6e 67 20 , int cmd, long
0620: 61 72 67 31 2c 20 76 6f 69 64 20 2a 70 74 72 29 arg1, void *ptr)
0630: 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 42 69 );.static int Bi
0640: 6f 4e 65 77 09 5f 41 4e 53 49 5f 41 52 47 53 5f oNew._ANSI_ARGS_
0650: 20 28 28 42 49 4f 20 2a 68 29 29 3b 0a 73 74 61 ((BIO *h));.sta
0660: 74 69 63 20 69 6e 74 20 42 69 6f 46 72 65 65 09 tic int BioFree.
0670: 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49 _ANSI_ARGS_ ((BI
0680: 4f 20 2a 68 29 29 3b 0a 0a 42 49 4f 20 2a 0a 42 O *h));..BIO *.B
0690: 49 4f 5f 6e 65 77 5f 74 63 6c 28 73 74 61 74 65 IO_new_tcl(state
06a0: 50 74 72 2c 20 66 6c 61 67 73 29 0a 20 20 20 20 Ptr, flags).
06b0: 53 74 61 74 65 20 2a 73 74 61 74 65 50 74 72 3b State *statePtr;
06c0: 0a 20 20 20 20 69 6e 74 20 66 6c 61 67 73 3b 0a . int flags;.
06d0: 7b 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a {. BIO *bio;.
06e0: 20 20 20 20 73 74 61 74 69 63 20 42 49 4f 5f 4d static BIO_M
06f0: 45 54 48 4f 44 20 2a 42 69 6f 4d 65 74 68 6f 64 ETHOD *BioMethod
0700: 73 20 3d 20 4e 55 4c 4c 3b 0a 0a 20 20 20 20 64 s = NULL;.. d
0710: 70 72 69 6e 74 66 28 22 42 49 4f 5f 6e 65 77 5f printf("BIO_new_
0720: 74 63 6c 28 29 20 63 61 6c 6c 65 64 22 29 3b 0a tcl() called");.
0730: 0a 20 20 20 20 69 66 20 28 42 69 6f 4d 65 74 68 . if (BioMeth
0740: 6f 64 73 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 20 ods == NULL) {.
0750: 20 20 20 20 20 20 20 42 69 6f 4d 65 74 68 6f 64 BioMethod
0760: 73 20 3d 20 42 49 4f 5f 6d 65 74 68 5f 6e 65 77 s = BIO_meth_new
0770: 28 42 49 4f 5f 54 59 50 45 5f 54 43 4c 2c 20 22 (BIO_TYPE_TCL, "
0780: 74 63 6c 22 29 3b 0a 20 20 20 20 20 20 20 20 42 tcl");. B
0790: 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 77 72 69 74 IO_meth_set_writ
07a0: 65 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 69 e(BioMethods, Bi
07b0: 6f 57 72 69 74 65 29 3b 0a 20 20 20 20 20 20 20 oWrite);.
07c0: 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 72 65 BIO_meth_set_re
07d0: 61 64 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 ad(BioMethods, B
07e0: 69 6f 52 65 61 64 29 3b 0a 20 20 20 20 20 20 20 ioRead);.
07f0: 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 70 75 BIO_meth_set_pu
0800: 74 73 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 ts(BioMethods, B
0810: 69 6f 50 75 74 73 29 3b 0a 20 20 20 20 20 20 20 ioPuts);.
0820: 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 63 74 BIO_meth_set_ct
0830: 72 6c 28 42 69 6f 4d 65 74 68 6f 64 73 2c 20 42 rl(BioMethods, B
0840: 69 6f 43 74 72 6c 29 3b 0a 20 20 20 20 20 20 20 ioCtrl);.
0850: 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 63 72 BIO_meth_set_cr
0860: 65 61 74 65 28 42 69 6f 4d 65 74 68 6f 64 73 2c eate(BioMethods,
0870: 20 42 69 6f 4e 65 77 29 3b 0a 20 20 20 20 20 20 BioNew);.
0880: 20 20 42 49 4f 5f 6d 65 74 68 5f 73 65 74 5f 64 BIO_meth_set_d
0890: 65 73 74 72 6f 79 28 42 69 6f 4d 65 74 68 6f 64 estroy(BioMethod
08a0: 73 2c 20 42 69 6f 46 72 65 65 29 3b 0a 20 20 20 s, BioFree);.
08b0: 20 7d 0a 0a 20 20 20 20 62 69 6f 20 3d 20 42 49 }.. bio = BI
08c0: 4f 5f 6e 65 77 28 42 69 6f 4d 65 74 68 6f 64 73 O_new(BioMethods
08d0: 29 3b 0a 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f );.. BIO_set_
08e0: 64 61 74 61 28 62 69 6f 2c 20 73 74 61 74 65 50 data(bio, stateP
08f0: 74 72 29 3b 0a 20 20 20 20 42 49 4f 5f 73 65 74 tr);. BIO_set
0900: 5f 69 6e 69 74 28 62 69 6f 2c 20 31 29 3b 0a 20 _init(bio, 1);.
0910: 20 20 20 42 49 4f 5f 73 65 74 5f 73 68 75 74 64 BIO_set_shutd
0920: 6f 77 6e 28 62 69 6f 2c 20 66 6c 61 67 73 29 3b own(bio, flags);
0930: 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 62 69 6f .. return bio
0940: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a ;.}..static int.
0950: 42 69 6f 57 72 69 74 65 20 28 62 69 6f 2c 20 62 BioWrite (bio, b
0960: 75 66 2c 20 62 75 66 4c 65 6e 29 0a 20 20 20 20 uf, bufLen).
0970: 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 43 4f BIO *bio;. CO
0980: 4e 53 54 20 63 68 61 72 20 2a 62 75 66 3b 0a 20 NST char *buf;.
0990: 20 20 20 69 6e 74 20 62 75 66 4c 65 6e 3b 0a 7b int bufLen;.{
09a0: 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c . Tcl_Channel
09b0: 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 chan = Tls_GetP
09c0: 61 72 65 6e 74 28 28 53 74 61 74 65 2a 29 42 49 arent((State*)BI
09d0: 4f 5f 67 65 74 5f 64 61 74 61 28 62 69 6f 29 29 O_get_data(bio))
09e0: 3b 0a 20 20 20 20 69 6e 74 20 72 65 74 3b 0a 0a ;. int ret;..
09f0: 20 20 20 20 64 70 72 69 6e 74 66 28 22 42 69 6f dprintf("Bio
0a00: 57 72 69 74 65 28 25 70 2c 20 3c 62 75 66 3e 2c Write(%p, <buf>,
0a10: 20 25 64 29 20 5b 25 70 5d 22 2c 0a 09 20 20 20 %d) [%p]",..
0a20: 20 28 76 6f 69 64 20 2a 29 20 62 69 6f 2c 20 62 (void *) bio, b
0a30: 75 66 4c 65 6e 2c 20 28 76 6f 69 64 20 2a 29 20 ufLen, (void *)
0a40: 63 68 61 6e 29 3b 0a 0a 20 20 20 20 69 66 20 28 chan);.. if (
0a50: 63 68 61 6e 6e 65 6c 54 79 70 65 56 65 72 73 69 channelTypeVersi
0a60: 6f 6e 20 3d 3d 20 54 4c 53 5f 43 48 41 4e 4e 45 on == TLS_CHANNE
0a70: 4c 5f 56 45 52 53 49 4f 4e 5f 32 29 20 7b 0a 09 L_VERSION_2) {..
0a80: 72 65 74 20 3d 20 54 63 6c 5f 57 72 69 74 65 52 ret = Tcl_WriteR
0a90: 61 77 28 63 68 61 6e 2c 20 62 75 66 2c 20 62 75 aw(chan, buf, bu
0aa0: 66 4c 65 6e 29 3b 0a 20 20 20 20 7d 20 65 6c 73 fLen);. } els
0ab0: 65 20 7b 0a 09 72 65 74 20 3d 20 54 63 6c 5f 57 e {..ret = Tcl_W
0ac0: 72 69 74 65 28 63 68 61 6e 2c 20 62 75 66 2c 20 rite(chan, buf,
0ad0: 62 75 66 4c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a bufLen);. }..
0ae0: 20 20 20 20 64 70 72 69 6e 74 66 28 22 5b 25 70 dprintf("[%p
0af0: 5d 20 42 69 6f 57 72 69 74 65 28 25 64 29 20 2d ] BioWrite(%d) -
0b00: 3e 20 25 64 20 5b 25 64 2e 25 64 5d 22 2c 0a 09 > %d [%d.%d]",..
0b10: 20 20 20 20 28 76 6f 69 64 20 2a 29 20 63 68 61 (void *) cha
0b20: 6e 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c 20 n, bufLen, ret,
0b30: 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 2c 20 54 Tcl_Eof(chan), T
0b40: 63 6c 5f 47 65 74 45 72 72 6e 6f 28 29 29 3b 0a cl_GetErrno());.
0b50: 0a 20 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 . BIO_clear_f
0b60: 6c 61 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c lags(bio, BIO_FL
0b70: 41 47 53 5f 57 52 49 54 45 7c 42 49 4f 5f 46 4c AGS_WRITE|BIO_FL
0b80: 41 47 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59 AGS_SHOULD_RETRY
0b90: 29 3b 0a 0a 20 20 20 20 69 66 20 28 72 65 74 20 );.. if (ret
0ba0: 3d 3d 20 30 29 20 7b 0a 09 69 66 20 28 21 54 63 == 0) {..if (!Tc
0bb0: 6c 5f 45 6f 66 28 63 68 61 6e 29 29 20 7b 0a 09 l_Eof(chan)) {..
0bc0: 20 20 20 20 42 49 4f 5f 73 65 74 5f 72 65 74 72 BIO_set_retr
0bd0: 79 5f 77 72 69 74 65 28 62 69 6f 29 3b 0a 09 20 y_write(bio);..
0be0: 20 20 20 72 65 74 20 3d 20 2d 31 3b 0a 09 7d 0a ret = -1;..}.
0bf0: 20 20 20 20 7d 0a 20 20 20 20 69 66 20 28 42 49 }. if (BI
0c00: 4f 5f 73 68 6f 75 6c 64 5f 72 65 61 64 28 62 69 O_should_read(bi
0c10: 6f 29 29 20 7b 0a 09 42 49 4f 5f 73 65 74 5f 72 o)) {..BIO_set_r
0c20: 65 74 72 79 5f 72 65 61 64 28 62 69 6f 29 3b 0a etry_read(bio);.
0c30: 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e }. return
0c40: 20 72 65 74 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 ret;.}..static
0c50: 69 6e 74 0a 42 69 6f 52 65 61 64 20 28 62 69 6f int.BioRead (bio
0c60: 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 0a 20 , buf, bufLen).
0c70: 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 BIO *bio;.
0c80: 20 63 68 61 72 20 2a 62 75 66 3b 0a 20 20 20 20 char *buf;.
0c90: 69 6e 74 20 62 75 66 4c 65 6e 3b 0a 7b 0a 20 20 int bufLen;.{.
0ca0: 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 Tcl_Channel ch
0cb0: 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 65 an = Tls_GetPare
0cc0: 6e 74 28 28 53 74 61 74 65 2a 29 42 49 4f 5f 67 nt((State*)BIO_g
0cd0: 65 74 5f 64 61 74 61 28 62 69 6f 29 29 3b 0a 20 et_data(bio));.
0ce0: 20 20 20 69 6e 74 20 72 65 74 20 3d 20 30 3b 0a int ret = 0;.
0cf0: 20 20 20 20 69 6e 74 20 74 63 6c 45 6f 66 43 68 int tclEofCh
0d00: 61 6e 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 an;.. dprintf
0d10: 28 22 42 69 6f 52 65 61 64 28 25 70 2c 20 3c 62 ("BioRead(%p, <b
0d20: 75 66 3e 2c 20 25 64 29 20 5b 25 70 5d 22 2c 20 uf>, %d) [%p]",
0d30: 28 76 6f 69 64 20 2a 29 20 62 69 6f 2c 20 62 75 (void *) bio, bu
0d40: 66 4c 65 6e 2c 20 28 76 6f 69 64 20 2a 29 20 63 fLen, (void *) c
0d50: 68 61 6e 29 3b 0a 0a 20 20 20 20 69 66 20 28 62 han);.. if (b
0d60: 75 66 20 3d 3d 20 4e 55 4c 4c 29 20 72 65 74 75 uf == NULL) retu
0d70: 72 6e 20 30 3b 0a 0a 20 20 20 20 69 66 20 28 63 rn 0;.. if (c
0d80: 68 61 6e 6e 65 6c 54 79 70 65 56 65 72 73 69 6f hannelTypeVersio
0d90: 6e 20 3d 3d 20 54 4c 53 5f 43 48 41 4e 4e 45 4c n == TLS_CHANNEL
0da0: 5f 56 45 52 53 49 4f 4e 5f 32 29 20 7b 0a 09 72 _VERSION_2) {..r
0db0: 65 74 20 3d 20 54 63 6c 5f 52 65 61 64 52 61 77 et = Tcl_ReadRaw
0dc0: 28 63 68 61 6e 2c 20 62 75 66 2c 20 62 75 66 4c (chan, buf, bufL
0dd0: 65 6e 29 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 en);. } else
0de0: 7b 0a 09 72 65 74 20 3d 20 54 63 6c 5f 52 65 61 {..ret = Tcl_Rea
0df0: 64 28 63 68 61 6e 2c 20 62 75 66 2c 20 62 75 66 d(chan, buf, buf
0e00: 4c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 Len);. }..
0e10: 20 74 63 6c 45 6f 66 43 68 61 6e 20 3d 20 54 63 tclEofChan = Tc
0e20: 6c 5f 45 6f 66 28 63 68 61 6e 29 3b 0a 0a 20 20 l_Eof(chan);..
0e30: 20 20 64 70 72 69 6e 74 66 28 22 5b 25 70 5d 20 dprintf("[%p]
0e40: 42 69 6f 52 65 61 64 28 25 64 29 20 2d 3e 20 25 BioRead(%d) -> %
0e50: 64 20 5b 74 63 6c 45 6f 66 3d 25 64 3b 20 74 63 d [tclEof=%d; tc
0e60: 6c 45 72 72 6e 6f 3d 25 64 5d 22 2c 0a 09 20 20 lErrno=%d]",..
0e70: 20 20 28 76 6f 69 64 20 2a 29 20 63 68 61 6e 2c (void *) chan,
0e80: 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c 20 74 63 bufLen, ret, tc
0e90: 6c 45 6f 66 43 68 61 6e 2c 20 54 63 6c 5f 47 65 lEofChan, Tcl_Ge
0ea0: 74 45 72 72 6e 6f 28 29 29 3b 0a 0a 20 20 20 20 tErrno());..
0eb0: 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 BIO_clear_flags(
0ec0: 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47 53 5f 52 bio, BIO_FLAGS_R
0ed0: 45 41 44 7c 42 49 4f 5f 46 4c 41 47 53 5f 53 48 EAD|BIO_FLAGS_SH
0ee0: 4f 55 4c 44 5f 52 45 54 52 59 29 3b 0a 0a 20 20 OULD_RETRY);..
0ef0: 20 20 69 66 20 28 72 65 74 20 3d 3d 20 30 29 20 if (ret == 0)
0f00: 7b 0a 09 69 66 20 28 21 74 63 6c 45 6f 66 43 68 {..if (!tclEofCh
0f10: 61 6e 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 an) {.
0f20: 20 20 64 70 72 69 6e 74 66 28 22 47 6f 74 20 30 dprintf("Got 0
0f30: 20 66 72 6f 6d 20 54 63 6c 5f 52 65 61 64 20 6f from Tcl_Read o
0f40: 72 20 54 63 6c 5f 52 65 61 64 52 61 77 2c 20 61 r Tcl_ReadRaw, a
0f50: 6e 64 20 45 4f 46 20 69 73 20 6e 6f 74 20 73 65 nd EOF is not se
0f60: 74 20 2d 2d 20 72 65 74 20 3d 3d 20 2d 31 20 6e t -- ret == -1 n
0f70: 6f 77 22 29 3b 0a 09 20 20 20 20 42 49 4f 5f 73 ow");.. BIO_s
0f80: 65 74 5f 72 65 74 72 79 5f 72 65 61 64 28 62 69 et_retry_read(bi
0f90: 6f 29 3b 0a 09 20 20 20 20 72 65 74 20 3d 20 2d o);.. ret = -
0fa0: 31 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 20 20 20 1;..} else {.
0fb0: 20 20 20 20 20 20 20 20 20 64 70 72 69 6e 74 66 dprintf
0fc0: 28 22 47 6f 74 20 30 20 66 72 6f 6d 20 54 63 6c ("Got 0 from Tcl
0fd0: 5f 52 65 61 64 20 6f 72 20 54 63 6c 5f 52 65 61 _Read or Tcl_Rea
0fe0: 64 52 61 77 2c 20 61 6e 64 20 45 4f 46 20 69 73 dRaw, and EOF is
0ff0: 20 73 65 74 22 29 3b 0a 20 20 20 20 20 20 20 20 set");.
1000: 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 }. } else {.
1010: 20 20 20 20 20 20 20 64 70 72 69 6e 74 66 28 22 dprintf("
1020: 47 6f 74 20 6e 6f 6e 2d 7a 65 72 6f 20 66 72 6f Got non-zero fro
1030: 6d 20 54 63 6c 5f 52 65 61 64 20 6f 72 20 54 63 m Tcl_Read or Tc
1040: 6c 5f 52 65 61 64 52 61 77 20 3d 3d 20 72 65 74 l_ReadRaw == ret
1050: 20 3d 3d 20 25 69 22 2c 20 72 65 74 29 3b 0a 20 == %i", ret);.
1060: 20 20 20 7d 0a 20 20 20 20 69 66 20 28 42 49 4f }. if (BIO
1070: 5f 73 68 6f 75 6c 64 5f 77 72 69 74 65 28 62 69 _should_write(bi
1080: 6f 29 29 20 7b 0a 09 42 49 4f 5f 73 65 74 5f 72 o)) {..BIO_set_r
1090: 65 74 72 79 5f 77 72 69 74 65 28 62 69 6f 29 3b etry_write(bio);
10a0: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 64 70 72 69 . }.. dpri
10b0: 6e 74 66 28 22 42 69 6f 52 65 61 64 28 25 70 2c ntf("BioRead(%p,
10c0: 20 3c 62 75 66 3e 2c 20 25 64 29 20 5b 25 70 5d <buf>, %d) [%p]
10d0: 20 72 65 74 75 72 6e 69 6e 67 20 25 69 22 2c 20 returning %i",
10e0: 28 76 6f 69 64 20 2a 29 20 62 69 6f 2c 20 62 75 (void *) bio, bu
10f0: 66 4c 65 6e 2c 20 28 76 6f 69 64 20 2a 29 20 63 fLen, (void *) c
1100: 68 61 6e 2c 20 72 65 74 29 3b 0a 0a 20 20 20 20 han, ret);..
1110: 72 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 73 return ret;.}..s
1120: 74 61 74 69 63 20 69 6e 74 0a 42 69 6f 50 75 74 tatic int.BioPut
1130: 73 09 28 62 69 6f 2c 20 73 74 72 29 0a 20 20 20 s.(bio, str).
1140: 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 43 BIO *bio;. C
1150: 4f 4e 53 54 20 63 68 61 72 20 2a 73 74 72 3b 0a ONST char *str;.
1160: 7b 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 42 {. dprintf("B
1170: 69 6f 50 75 74 73 28 25 70 2c 20 3c 73 74 72 69 ioPuts(%p, <stri
1180: 6e 67 3a 25 70 3e 29 20 63 61 6c 6c 65 64 22 2c ng:%p>) called",
1190: 20 62 69 6f 2c 20 73 74 72 29 3b 0a 20 20 20 20 bio, str);.
11a0: 72 65 74 75 72 6e 20 42 69 6f 57 72 69 74 65 28 return BioWrite(
11b0: 62 69 6f 2c 20 73 74 72 2c 20 28 69 6e 74 29 20 bio, str, (int)
11c0: 73 74 72 6c 65 6e 28 73 74 72 29 29 3b 0a 7d 0a strlen(str));.}.
11d0: 0a 73 74 61 74 69 63 20 6c 6f 6e 67 0a 42 69 6f .static long.Bio
11e0: 43 74 72 6c 09 28 62 69 6f 2c 20 63 6d 64 2c 20 Ctrl.(bio, cmd,
11f0: 6e 75 6d 2c 20 70 74 72 29 0a 20 20 20 20 42 49 num, ptr). BI
1200: 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 69 6e 74 20 O *bio;. int
1210: 63 6d 64 3b 0a 20 20 20 20 6c 6f 6e 67 20 6e 75 cmd;. long nu
1220: 6d 3b 0a 20 20 20 20 76 6f 69 64 20 2a 70 74 72 m;. void *ptr
1230: 3b 0a 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e ;.{. Tcl_Chan
1240: 6e 65 6c 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 nel chan = Tls_G
1250: 65 74 50 61 72 65 6e 74 28 28 53 74 61 74 65 2a etParent((State*
1260: 29 42 49 4f 5f 67 65 74 5f 64 61 74 61 28 62 69 )BIO_get_data(bi
1270: 6f 29 29 3b 0a 20 20 20 20 6c 6f 6e 67 20 72 65 o));. long re
1280: 74 20 3d 20 31 3b 0a 0a 20 20 20 20 64 70 72 69 t = 1;.. dpri
1290: 6e 74 66 28 22 42 69 6f 43 74 72 6c 28 25 70 2c ntf("BioCtrl(%p,
12a0: 20 30 78 25 78 2c 20 30 78 25 78 2c 20 25 70 29 0x%x, 0x%x, %p)
12b0: 22 2c 0a 09 20 20 20 20 28 76 6f 69 64 20 2a 29 ",.. (void *)
12c0: 20 62 69 6f 2c 20 28 75 6e 73 69 67 6e 65 64 20 bio, (unsigned
12d0: 69 6e 74 29 20 63 6d 64 2c 20 28 75 6e 73 69 67 int) cmd, (unsig
12e0: 6e 65 64 20 69 6e 74 29 20 6e 75 6d 2c 0a 09 20 ned int) num,..
12f0: 20 20 20 28 76 6f 69 64 20 2a 29 20 70 74 72 29 (void *) ptr)
1300: 3b 0a 0a 20 20 20 20 73 77 69 74 63 68 20 28 63 ;.. switch (c
1310: 6d 64 29 20 7b 0a 20 20 20 20 63 61 73 65 20 42 md) {. case B
1320: 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54 3a 0a 09 IO_CTRL_RESET:..
1330: 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 20 63 61 73 num = 0;. cas
1340: 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53 45 45 e BIO_C_FILE_SEE
1350: 4b 3a 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f K:. case BIO_
1360: 43 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a 09 72 65 C_FILE_TELL:..re
1370: 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b 0a 20 t = 0;..break;.
1380: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c case BIO_CTRL
1390: 5f 49 4e 46 4f 3a 0a 09 72 65 74 20 3d 20 31 3b _INFO:..ret = 1;
13a0: 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 ..break;. cas
13b0: 65 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44 3a 0a e BIO_C_SET_FD:.
13c0: 20 20 20 20 20 20 20 20 64 70 72 69 6e 74 66 28 dprintf(
13d0: 22 55 6e 73 75 70 70 6f 72 74 65 64 20 63 61 6c "Unsupported cal
13e0: 6c 3a 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44 22 l: BIO_C_SET_FD"
13f0: 29 3b 0a 20 20 20 20 20 20 20 20 72 65 74 20 3d );. ret =
1400: 20 2d 31 3b 0a 20 20 20 20 20 20 20 20 62 72 65 -1;. bre
1410: 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f ak;. case BIO
1420: 5f 43 5f 47 45 54 5f 46 44 3a 0a 20 20 20 20 20 _C_GET_FD:.
1430: 20 20 20 64 70 72 69 6e 74 66 28 22 55 6e 73 75 dprintf("Unsu
1440: 70 70 6f 72 74 65 64 20 63 61 6c 6c 3a 20 42 49 pported call: BI
1450: 4f 5f 43 5f 47 45 54 5f 46 44 22 29 3b 0a 20 20 O_C_GET_FD");.
1460: 20 20 20 20 20 20 72 65 74 20 3d 20 2d 31 3b 0a ret = -1;.
1470: 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 break;.
1480: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c case BIO_CTRL
1490: 5f 47 45 54 5f 43 4c 4f 53 45 3a 0a 09 72 65 74 _GET_CLOSE:..ret
14a0: 20 3d 20 42 49 4f 5f 67 65 74 5f 73 68 75 74 64 = BIO_get_shutd
14b0: 6f 77 6e 28 62 69 6f 29 3b 0a 09 62 72 65 61 6b own(bio);..break
14c0: 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 ;. case BIO_C
14d0: 54 52 4c 5f 53 45 54 5f 43 4c 4f 53 45 3a 0a 09 TRL_SET_CLOSE:..
14e0: 42 49 4f 5f 73 65 74 5f 73 68 75 74 64 6f 77 6e BIO_set_shutdown
14f0: 28 62 69 6f 2c 20 6e 75 6d 29 3b 0a 09 62 72 65 (bio, num);..bre
1500: 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f ak;. case BIO
1510: 5f 43 54 52 4c 5f 45 4f 46 3a 0a 09 64 70 72 69 _CTRL_EOF:..dpri
1520: 6e 74 66 28 22 42 49 4f 5f 43 54 52 4c 5f 45 4f ntf("BIO_CTRL_EO
1530: 46 22 29 3b 0a 09 72 65 74 20 3d 20 54 63 6c 5f F");..ret = Tcl_
1540: 45 6f 66 28 63 68 61 6e 29 3b 0a 09 62 72 65 61 Eof(chan);..brea
1550: 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f k;. case BIO_
1560: 43 54 52 4c 5f 50 45 4e 44 49 4e 47 3a 0a 09 72 CTRL_PENDING:..r
1570: 65 74 20 3d 20 28 54 63 6c 5f 49 6e 70 75 74 42 et = (Tcl_InputB
1580: 75 66 66 65 72 65 64 28 63 68 61 6e 29 20 3f 20 uffered(chan) ?
1590: 31 20 3a 20 30 29 3b 0a 09 64 70 72 69 6e 74 66 1 : 0);..dprintf
15a0: 28 22 42 49 4f 5f 43 54 52 4c 5f 50 45 4e 44 49 ("BIO_CTRL_PENDI
15b0: 4e 47 28 25 64 29 22 2c 20 28 69 6e 74 29 20 72 NG(%d)", (int) r
15c0: 65 74 29 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 et);..break;.
15d0: 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 57 case BIO_CTRL_W
15e0: 50 45 4e 44 49 4e 47 3a 0a 09 72 65 74 20 3d 20 PENDING:..ret =
15f0: 30 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 0;..break;. c
1600: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 44 55 50 ase BIO_CTRL_DUP
1610: 3a 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 :..break;. ca
1620: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 se BIO_CTRL_FLUS
1630: 48 3a 0a 09 64 70 72 69 6e 74 66 28 22 42 49 4f H:..dprintf("BIO
1640: 5f 43 54 52 4c 5f 46 4c 55 53 48 22 29 3b 0a 09 _CTRL_FLUSH");..
1650: 69 66 20 28 63 68 61 6e 6e 65 6c 54 79 70 65 56 if (channelTypeV
1660: 65 72 73 69 6f 6e 20 3d 3d 20 54 4c 53 5f 43 48 ersion == TLS_CH
1670: 41 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f 32 29 ANNEL_VERSION_2)
1680: 20 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 28 28 {.. ret = ((
1690: 54 63 6c 5f 57 72 69 74 65 52 61 77 28 63 68 61 Tcl_WriteRaw(cha
16a0: 6e 2c 20 22 22 2c 20 30 29 20 3e 3d 20 30 29 20 n, "", 0) >= 0)
16b0: 3f 20 31 20 3a 20 2d 31 29 3b 0a 09 7d 20 65 6c ? 1 : -1);..} el
16c0: 73 65 20 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 se {.. ret =
16d0: 28 28 54 63 6c 5f 46 6c 75 73 68 28 63 68 61 6e ((Tcl_Flush(chan
16e0: 29 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 3f 20 31 ) == TCL_OK) ? 1
16f0: 20 3a 20 2d 31 29 3b 0a 09 7d 0a 20 20 20 20 20 : -1);..}.
1700: 20 20 20 64 70 72 69 6e 74 66 28 22 42 49 4f 5f dprintf("BIO_
1710: 43 54 52 4c 5f 46 4c 55 53 48 20 72 65 74 75 72 CTRL_FLUSH retur
1720: 6e 69 6e 67 20 76 61 6c 75 65 20 25 6c 69 22 2c ning value %li",
1730: 20 72 65 74 29 3b 0a 09 62 72 65 61 6b 3b 0a 20 ret);..break;.
1740: 20 20 20 64 65 66 61 75 6c 74 3a 0a 09 72 65 74 default:..ret
1750: 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 = 0;..break;.
1760: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 28 72 }. return(r
1770: 65 74 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 et);.}..static i
1780: 6e 74 0a 42 69 6f 4e 65 77 09 28 62 69 6f 29 0a nt.BioNew.(bio).
1790: 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 7b 0a BIO *bio;.{.
17a0: 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 42 69 . dprintf("Bi
17b0: 6f 4e 65 77 28 25 70 29 20 63 61 6c 6c 65 64 22 oNew(%p) called"
17c0: 2c 20 62 69 6f 29 3b 0a 0a 20 20 20 20 42 49 4f , bio);.. BIO
17d0: 5f 73 65 74 5f 69 6e 69 74 28 62 69 6f 2c 20 30 _set_init(bio, 0
17e0: 29 3b 0a 20 20 20 20 42 49 4f 5f 73 65 74 5f 64 );. BIO_set_d
17f0: 61 74 61 28 62 69 6f 2c 20 4e 55 4c 4c 29 3b 0a ata(bio, NULL);.
1800: 20 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c BIO_clear_fl
1810: 61 67 73 28 62 69 6f 2c 20 2d 31 29 3b 0a 0a 20 ags(bio, -1);..
1820: 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a 0a return 1;.}..
1830: 73 74 61 74 69 63 20 69 6e 74 0a 42 69 6f 46 72 static int.BioFr
1840: 65 65 09 28 62 69 6f 29 0a 20 20 20 20 42 49 4f ee.(bio). BIO
1850: 20 2a 62 69 6f 3b 0a 7b 0a 20 20 20 20 69 66 20 *bio;.{. if
1860: 28 62 69 6f 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a (bio == NULL) {.
1870: 09 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 20 7d .return 0;. }
1880: 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 22 42 .. dprintf("B
1890: 69 6f 46 72 65 65 28 25 70 29 20 63 61 6c 6c 65 ioFree(%p) calle
18a0: 64 22 2c 20 62 69 6f 29 3b 0a 0a 20 20 20 20 69 d", bio);.. i
18b0: 66 20 28 42 49 4f 5f 67 65 74 5f 73 68 75 74 64 f (BIO_get_shutd
18c0: 6f 77 6e 28 62 69 6f 29 29 20 7b 0a 09 69 66 20 own(bio)) {..if
18d0: 28 42 49 4f 5f 67 65 74 5f 69 6e 69 74 28 62 69 (BIO_get_init(bi
18e0: 6f 29 29 20 7b 0a 09 20 20 20 20 2f 2a 73 68 75 o)) {.. /*shu
18f0: 74 64 6f 77 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20 tdown(bio->num,
1900: 32 29 20 2a 2f 0a 09 20 20 20 20 2f 2a 63 6c 6f 2) */.. /*clo
1910: 73 65 73 6f 63 6b 65 74 28 62 69 6f 2d 3e 6e 75 sesocket(bio->nu
1920: 6d 29 20 2a 2f 0a 09 7d 0a 20 20 20 20 20 20 20 m) */..}.
1930: 20 42 49 4f 5f 73 65 74 5f 69 6e 69 74 28 62 69 BIO_set_init(bi
1940: 6f 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 20 42 o, 0);. B
1950: 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 62 IO_clear_flags(b
1960: 69 6f 2c 20 2d 31 29 3b 0a 20 20 20 20 7d 0a 20 io, -1);. }.
1970: 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a return 1;.}.