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 24 48 65 61 64 65 72 3a 20 2f 68 6f . * $Header: /ho
0050: 6d 65 2f 72 6b 65 65 6e 65 2f 74 6d 70 2f 63 76 me/rkeene/tmp/cv
0060: 73 32 66 6f 73 73 69 6c 2f 2e 2e 2f 74 63 6c 74 s2fossil/../tclt
0070: 6c 73 2f 74 6c 73 2f 74 6c 73 2f 74 6c 73 42 49 ls/tls/tls/tlsBI
0080: 4f 2e 63 2c 76 20 31 2e 32 2e 32 2e 32 20 32 30 O.c,v 1.2.2.2 20
0090: 30 30 2f 30 37 2f 31 32 20 30 31 3a 35 34 3a 32 00/07/12 01:54:2
00a0: 36 20 68 6f 62 62 73 20 45 78 70 20 24 0a 20 2a 6 hobbs Exp $. *
00b0: 0a 20 2a 20 50 72 6f 76 69 64 65 73 20 42 49 4f . * Provides BIO
00c0: 20 6c 61 79 65 72 20 74 6f 20 69 6e 74 65 72 66 layer to interf
00d0: 61 63 65 20 6f 70 65 6e 73 73 6c 20 74 6f 20 54 ace openssl to T
00e0: 63 6c 2e 0a 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 cl.. */..#includ
00f0: 65 20 22 74 6c 73 49 6e 74 2e 68 22 0a 0a 2f 2a e "tlsInt.h"../*
0100: 0a 20 2a 20 46 6f 72 77 61 72 64 20 64 65 63 6c . * Forward decl
0110: 61 72 61 74 69 6f 6e 73 0a 20 2a 2f 0a 0a 73 74 arations. */..st
0120: 61 74 69 63 20 69 6e 74 20 42 69 6f 57 72 69 74 atic int BioWrit
0130: 65 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 e._ANSI_ARGS_ ((
0140: 42 49 4f 20 2a 68 2c 20 63 68 61 72 20 2a 62 75 BIO *h, char *bu
0150: 66 2c 20 69 6e 74 20 6e 75 6d 29 29 3b 0a 73 74 f, int num));.st
0160: 61 74 69 63 20 69 6e 74 20 42 69 6f 52 65 61 64 atic int BioRead
0170: 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 ._ANSI_ARGS_ ((B
0180: 49 4f 20 2a 68 2c 20 63 68 61 72 20 2a 62 75 66 IO *h, char *buf
0190: 2c 20 69 6e 74 20 6e 75 6d 29 29 3b 0a 73 74 61 , int num));.sta
01a0: 74 69 63 20 69 6e 74 20 42 69 6f 50 75 74 73 09 tic int BioPuts.
01b0: 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49 _ANSI_ARGS_ ((BI
01c0: 4f 20 2a 68 2c 20 63 68 61 72 20 2a 73 74 72 29 O *h, char *str)
01d0: 29 3b 0a 73 74 61 74 69 63 20 6c 6f 6e 67 20 42 );.static long B
01e0: 69 6f 43 74 72 6c 09 5f 41 4e 53 49 5f 41 52 47 ioCtrl._ANSI_ARG
01f0: 53 5f 20 28 28 42 49 4f 20 2a 68 2c 20 69 6e 74 S_ ((BIO *h, int
0200: 20 63 6d 64 2c 20 6c 6f 6e 67 20 61 72 67 31 2c cmd, long arg1,
0210: 20 63 68 61 72 20 2a 70 74 72 29 29 3b 0a 73 74 char *ptr));.st
0220: 61 74 69 63 20 69 6e 74 20 42 69 6f 4e 65 77 09 atic int BioNew.
0230: 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49 _ANSI_ARGS_ ((BI
0240: 4f 20 2a 68 29 29 3b 0a 73 74 61 74 69 63 20 69 O *h));.static i
0250: 6e 74 20 42 69 6f 46 72 65 65 09 5f 41 4e 53 49 nt BioFree._ANSI
0260: 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68 29 _ARGS_ ((BIO *h)
0270: 29 3b 0a 0a 0a 73 74 61 74 69 63 20 42 49 4f 5f );...static BIO_
0280: 4d 45 54 48 4f 44 20 42 69 6f 4d 65 74 68 6f 64 METHOD BioMethod
0290: 73 20 3d 20 7b 0a 20 20 20 20 42 49 4f 5f 54 59 s = {. BIO_TY
02a0: 50 45 5f 54 43 4c 2c 20 22 74 63 6c 22 2c 0a 20 PE_TCL, "tcl",.
02b0: 20 20 20 42 69 6f 57 72 69 74 65 2c 0a 20 20 20 BioWrite,.
02c0: 20 42 69 6f 52 65 61 64 2c 0a 20 20 20 20 42 69 BioRead,. Bi
02d0: 6f 50 75 74 73 2c 0a 20 20 20 20 4e 55 4c 4c 2c oPuts,. NULL,
02e0: 09 2f 2a 20 42 69 6f 47 65 74 73 20 2a 2f 0a 20 ./* BioGets */.
02f0: 20 20 20 42 69 6f 43 74 72 6c 2c 0a 20 20 20 20 BioCtrl,.
0300: 42 69 6f 4e 65 77 2c 0a 20 20 20 20 42 69 6f 46 BioNew,. BioF
0310: 72 65 65 2c 0a 7d 3b 0a 0a 42 49 4f 20 2a 0a 42 ree,.};..BIO *.B
0320: 49 4f 5f 6e 65 77 5f 74 63 6c 28 73 74 61 74 65 IO_new_tcl(state
0330: 50 74 72 2c 20 66 6c 61 67 73 29 0a 20 20 20 20 Ptr, flags).
0340: 53 74 61 74 65 20 2a 73 74 61 74 65 50 74 72 3b State *statePtr;
0350: 0a 20 20 20 20 69 6e 74 20 66 6c 61 67 73 3b 0a . int flags;.
0360: 7b 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a {. BIO *bio;.
0370: 0a 20 20 20 20 62 69 6f 20 3d 20 42 49 4f 5f 6e . bio = BIO_n
0380: 65 77 28 26 42 69 6f 4d 65 74 68 6f 64 73 29 3b ew(&BioMethods);
0390: 0a 20 20 20 20 62 69 6f 2d 3e 70 74 72 20 3d 20 . bio->ptr =
03a0: 28 63 68 61 72 2a 29 73 74 61 74 65 50 74 72 3b (char*)statePtr;
03b0: 0a 20 20 20 20 62 69 6f 2d 3e 69 6e 69 74 20 3d . bio->init =
03c0: 20 31 3b 0a 20 20 20 20 62 69 6f 2d 3e 73 68 75 1;. bio->shu
03d0: 74 64 6f 77 6e 20 3d 20 66 6c 61 67 73 3b 0a 0a tdown = flags;..
03e0: 20 20 20 20 72 65 74 75 72 6e 20 62 69 6f 3b 0a return bio;.
03f0: 7d 0a 0a 42 49 4f 5f 4d 45 54 48 4f 44 20 2a 0a }..BIO_METHOD *.
0400: 42 49 4f 5f 73 5f 74 63 6c 28 29 0a 7b 0a 20 20 BIO_s_tcl().{.
0410: 20 20 72 65 74 75 72 6e 20 26 42 69 6f 4d 65 74 return &BioMet
0420: 68 6f 64 73 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 hods;.}..static
0430: 69 6e 74 0a 42 69 6f 57 72 69 74 65 20 28 62 69 int.BioWrite (bi
0440: 6f 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 0a o, buf, bufLen).
0450: 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 BIO *bio;.
0460: 20 20 63 68 61 72 20 2a 62 75 66 3b 0a 20 20 20 char *buf;.
0470: 20 69 6e 74 20 62 75 66 4c 65 6e 3b 0a 7b 0a 20 int bufLen;.{.
0480: 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 Tcl_Channel c
0490: 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 han = Tls_GetPar
04a0: 65 6e 74 28 28 53 74 61 74 65 2a 29 62 69 6f 2d ent((State*)bio-
04b0: 3e 70 74 72 29 3b 0a 20 20 20 20 69 6e 74 20 72 >ptr);. int r
04c0: 65 74 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 et;.. dprintf
04d0: 28 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f 57 72 (stderr,"\nBioWr
04e0: 69 74 65 28 30 78 25 78 2c 20 3c 62 75 66 3e 2c ite(0x%x, <buf>,
04f0: 20 25 64 29 20 5b 30 78 25 78 5d 22 2c 20 62 69 %d) [0x%x]", bi
0500: 6f 2c 20 62 75 66 4c 65 6e 2c 20 63 68 61 6e 29 o, bufLen, chan)
0510: 3b 0a 0a 23 69 66 64 65 66 20 54 43 4c 5f 43 48 ;..#ifdef TCL_CH
0520: 41 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f 32 0a ANNEL_VERSION_2.
0530: 20 20 20 20 72 65 74 20 3d 20 54 63 6c 5f 57 72 ret = Tcl_Wr
0540: 69 74 65 52 61 77 28 20 63 68 61 6e 2c 20 62 75 iteRaw( chan, bu
0550: 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 23 65 6c 73 f, bufLen);.#els
0560: 65 0a 20 20 20 20 72 65 74 20 3d 20 54 63 6c 5f e. ret = Tcl_
0570: 57 72 69 74 65 28 20 63 68 61 6e 2c 20 62 75 66 Write( chan, buf
0580: 2c 20 62 75 66 4c 65 6e 29 3b 0a 23 65 6e 64 69 , bufLen);.#endi
0590: 66 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 73 f.. dprintf(s
05a0: 74 64 65 72 72 2c 22 5c 6e 5b 30 78 25 78 5d 20 tderr,"\n[0x%x]
05b0: 42 69 6f 57 72 69 74 65 28 25 64 29 20 2d 3e 20 BioWrite(%d) ->
05c0: 25 64 20 5b 25 64 2e 25 64 5d 22 2c 20 63 68 61 %d [%d.%d]", cha
05d0: 6e 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c 0a n, bufLen, ret,.
05e0: 09 09 54 63 6c 5f 45 6f 66 28 20 63 68 61 6e 29 ..Tcl_Eof( chan)
05f0: 2c 20 54 63 6c 5f 47 65 74 45 72 72 6e 6f 28 29 , Tcl_GetErrno()
0600: 29 3b 0a 0a 20 20 20 20 42 49 4f 5f 63 6c 65 61 );.. BIO_clea
0610: 72 5f 66 6c 61 67 73 28 62 69 6f 2c 20 42 49 4f r_flags(bio, BIO
0620: 5f 46 4c 41 47 53 5f 57 52 49 54 45 7c 42 49 4f _FLAGS_WRITE|BIO
0630: 5f 46 4c 41 47 53 5f 53 48 4f 55 4c 44 5f 52 45 _FLAGS_SHOULD_RE
0640: 54 52 59 29 3b 0a 0a 20 20 20 20 69 66 20 28 72 TRY);.. if (r
0650: 65 74 20 3d 3d 20 30 29 20 7b 0a 09 69 66 20 28 et == 0) {..if (
0660: 21 54 63 6c 5f 45 6f 66 28 20 63 68 61 6e 29 29 !Tcl_Eof( chan))
0670: 20 7b 0a 09 20 20 20 20 42 49 4f 5f 73 65 74 5f {.. BIO_set_
0680: 72 65 74 72 79 5f 77 72 69 74 65 28 62 69 6f 29 retry_write(bio)
0690: 3b 0a 09 20 20 20 20 72 65 74 20 3d 20 2d 31 3b ;.. ret = -1;
06a0: 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 ..}. }. if
06b0: 20 28 42 49 4f 5f 73 68 6f 75 6c 64 5f 72 65 61 (BIO_should_rea
06c0: 64 28 62 69 6f 29 29 0a 09 42 49 4f 5f 73 65 74 d(bio))..BIO_set
06d0: 5f 72 65 74 72 79 5f 72 65 61 64 28 62 69 6f 29 _retry_read(bio)
06e0: 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 72 65 74 ;. return ret
06f0: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a ;.}..static int.
0700: 42 69 6f 52 65 61 64 20 28 62 69 6f 2c 20 62 75 BioRead (bio, bu
0710: 66 2c 20 62 75 66 4c 65 6e 29 0a 20 20 20 20 42 f, bufLen). B
0720: 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 63 68 61 IO *bio;. cha
0730: 72 20 2a 62 75 66 3b 0a 20 20 20 20 69 6e 74 20 r *buf;. int
0740: 62 75 66 4c 65 6e 3b 0a 7b 0a 20 20 20 20 54 63 bufLen;.{. Tc
0750: 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e 20 3d l_Channel chan =
0760: 20 54 6c 73 5f 47 65 74 50 61 72 65 6e 74 28 28 Tls_GetParent((
0770: 53 74 61 74 65 2a 29 62 69 6f 2d 3e 70 74 72 29 State*)bio->ptr)
0780: 3b 0a 20 20 20 20 69 6e 74 20 72 65 74 20 3d 20 ;. int ret =
0790: 30 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74 66 28 0;.. dprintf(
07a0: 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f 52 65 61 stderr,"\nBioRea
07b0: 64 28 30 78 25 78 2c 20 3c 62 75 66 3e 2c 20 25 d(0x%x, <buf>, %
07c0: 64 29 20 5b 30 78 25 78 5d 22 2c 20 62 69 6f 2c d) [0x%x]", bio,
07d0: 20 62 75 66 4c 65 6e 2c 20 63 68 61 6e 29 3b 0a bufLen, chan);.
07e0: 0a 20 20 20 20 69 66 20 28 62 75 66 20 3d 3d 20 . if (buf ==
07f0: 4e 55 4c 4c 29 20 72 65 74 75 72 6e 20 30 3b 0a NULL) return 0;.
0800: 0a 23 69 66 64 65 66 20 54 43 4c 5f 43 48 41 4e .#ifdef TCL_CHAN
0810: 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f 32 0a 20 20 NEL_VERSION_2.
0820: 20 20 72 65 74 20 3d 20 54 63 6c 5f 52 65 61 64 ret = Tcl_Read
0830: 52 61 77 28 20 63 68 61 6e 2c 20 62 75 66 2c 20 Raw( chan, buf,
0840: 62 75 66 4c 65 6e 29 3b 0a 23 65 6c 73 65 0a 20 bufLen);.#else.
0850: 20 20 20 72 65 74 20 3d 20 54 63 6c 5f 52 65 61 ret = Tcl_Rea
0860: 64 28 20 63 68 61 6e 2c 20 62 75 66 2c 20 62 75 d( chan, buf, bu
0870: 66 4c 65 6e 29 3b 0a 23 65 6e 64 69 66 0a 0a 20 fLen);.#endif..
0880: 20 20 20 64 70 72 69 6e 74 66 28 73 74 64 65 72 dprintf(stder
0890: 72 2c 22 5c 6e 5b 30 78 25 78 5d 20 42 69 6f 52 r,"\n[0x%x] BioR
08a0: 65 61 64 28 25 64 29 20 2d 3e 20 25 64 20 5b 25 ead(%d) -> %d [%
08b0: 64 2e 25 64 5d 22 2c 20 63 68 61 6e 2c 20 62 75 d.%d]", chan, bu
08c0: 66 4c 65 6e 2c 20 72 65 74 2c 0a 09 54 63 6c 5f fLen, ret,..Tcl_
08d0: 45 6f 66 28 63 68 61 6e 29 2c 20 54 63 6c 5f 47 Eof(chan), Tcl_G
08e0: 65 74 45 72 72 6e 6f 28 29 29 3b 0a 0a 20 20 20 etErrno());..
08f0: 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 BIO_clear_flags
0900: 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47 53 5f (bio, BIO_FLAGS_
0910: 52 45 41 44 7c 42 49 4f 5f 46 4c 41 47 53 5f 53 READ|BIO_FLAGS_S
0920: 48 4f 55 4c 44 5f 52 45 54 52 59 29 3b 0a 0a 20 HOULD_RETRY);..
0930: 20 20 20 69 66 20 28 72 65 74 20 3d 3d 20 30 29 if (ret == 0)
0940: 20 7b 0a 09 69 66 20 28 21 54 63 6c 5f 45 6f 66 {..if (!Tcl_Eof
0950: 28 20 63 68 61 6e 29 29 20 7b 0a 09 20 20 20 20 ( chan)) {..
0960: 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f 72 65 BIO_set_retry_re
0970: 61 64 28 62 69 6f 29 3b 0a 09 20 20 20 20 72 65 ad(bio);.. re
0980: 74 20 3d 20 2d 31 3b 0a 09 7d 0a 20 20 20 20 7d t = -1;..}. }
0990: 0a 20 20 20 20 69 66 20 28 42 49 4f 5f 73 68 6f . if (BIO_sho
09a0: 75 6c 64 5f 77 72 69 74 65 28 62 69 6f 29 29 0a uld_write(bio)).
09b0: 09 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f 77 .BIO_set_retry_w
09c0: 72 69 74 65 28 62 69 6f 29 3b 0a 20 20 20 20 72 rite(bio);. r
09d0: 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 73 74 eturn ret;.}..st
09e0: 61 74 69 63 20 69 6e 74 0a 42 69 6f 50 75 74 73 atic int.BioPuts
09f0: 09 28 62 69 6f 2c 20 73 74 72 29 0a 20 20 20 20 .(bio, str).
0a00: 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 63 68 BIO *bio;. ch
0a10: 61 72 20 2a 73 74 72 3b 0a 7b 0a 20 20 20 20 72 ar *str;.{. r
0a20: 65 74 75 72 6e 20 42 69 6f 57 72 69 74 65 28 20 eturn BioWrite(
0a30: 62 69 6f 2c 20 73 74 72 2c 20 73 74 72 6c 65 6e bio, str, strlen
0a40: 28 73 74 72 29 29 3b 0a 7d 0a 0a 73 74 61 74 69 (str));.}..stati
0a50: 63 20 6c 6f 6e 67 0a 42 69 6f 43 74 72 6c 09 28 c long.BioCtrl.(
0a60: 62 69 6f 2c 20 63 6d 64 2c 20 6e 75 6d 2c 20 70 bio, cmd, num, p
0a70: 74 72 29 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f tr). BIO *bio
0a80: 3b 0a 20 20 20 20 69 6e 74 20 63 6d 64 3b 0a 20 ;. int cmd;.
0a90: 20 20 20 6c 6f 6e 67 20 6e 75 6d 3b 0a 20 20 20 long num;.
0aa0: 20 63 68 61 72 20 2a 70 74 72 3b 0a 7b 0a 20 20 char *ptr;.{.
0ab0: 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 Tcl_Channel ch
0ac0: 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 65 an = Tls_GetPare
0ad0: 6e 74 28 28 53 74 61 74 65 2a 29 62 69 6f 2d 3e nt((State*)bio->
0ae0: 70 74 72 29 3b 0a 20 20 20 20 6c 6f 6e 67 20 72 ptr);. long r
0af0: 65 74 20 3d 20 31 3b 0a 20 20 20 20 69 6e 74 20 et = 1;. int
0b00: 2a 69 70 3b 0a 0a 20 20 20 20 64 70 72 69 6e 74 *ip;.. dprint
0b10: 66 28 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f 43 f(stderr,"\nBioC
0b20: 74 72 6c 28 30 78 25 78 2c 20 30 78 25 78 2c 20 trl(0x%x, 0x%x,
0b30: 30 78 25 78 2c 20 30 78 25 78 29 22 2c 20 62 69 0x%x, 0x%x)", bi
0b40: 6f 2c 20 63 6d 64 2c 20 6e 75 6d 2c 20 70 74 72 o, cmd, num, ptr
0b50: 29 3b 0a 0a 20 20 20 20 73 77 69 74 63 68 20 28 );.. switch (
0b60: 63 6d 64 29 20 7b 0a 20 20 20 20 63 61 73 65 20 cmd) {. case
0b70: 42 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54 3a 0a BIO_CTRL_RESET:.
0b80: 09 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 20 63 61 .num = 0;. ca
0b90: 73 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53 45 se BIO_C_FILE_SE
0ba0: 45 4b 3a 0a 20 20 20 20 63 61 73 65 20 42 49 4f EK:. case BIO
0bb0: 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a 09 72 _C_FILE_TELL:..r
0bc0: 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b 0a et = 0;..break;.
0bd0: 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 case BIO_CTR
0be0: 4c 5f 49 4e 46 4f 3a 0a 09 72 65 74 20 3d 20 31 L_INFO:..ret = 1
0bf0: 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 ;..break;. ca
0c00: 73 65 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44 3a se BIO_C_SET_FD:
0c10: 0a 09 42 69 6f 46 72 65 65 28 62 69 6f 29 3b 0a ..BioFree(bio);.
0c20: 09 2f 2a 20 53 65 74 73 20 53 74 61 74 65 2a 20 ./* Sets State*
0c30: 2a 2f 0a 09 62 69 6f 2d 3e 70 74 72 20 3d 20 2a */..bio->ptr = *
0c40: 28 28 63 68 61 72 20 2a 2a 29 70 74 72 29 3b 0a ((char **)ptr);.
0c50: 09 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 20 3d .bio->shutdown =
0c60: 20 28 69 6e 74 29 6e 75 6d 3b 0a 09 62 69 6f 2d (int)num;..bio-
0c70: 3e 69 6e 69 74 20 3d 20 31 3b 0a 09 62 72 65 61 >init = 1;..brea
0c80: 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f k;. case BIO_
0c90: 43 5f 47 45 54 5f 46 44 3a 0a 09 69 66 20 28 62 C_GET_FD:..if (b
0ca0: 69 6f 2d 3e 69 6e 69 74 29 20 7b 0a 09 20 20 20 io->init) {..
0cb0: 20 69 70 3d 28 69 6e 74 20 2a 29 70 74 72 3b 0a ip=(int *)ptr;.
0cc0: 09 20 20 20 20 69 66 20 28 69 70 20 21 3d 20 4e . if (ip != N
0cd0: 55 4c 4c 29 20 2a 69 70 3d 62 69 6f 2d 3e 6e 75 ULL) *ip=bio->nu
0ce0: 6d 3b 0a 09 09 72 65 74 3d 62 69 6f 2d 3e 6e 75 m;...ret=bio->nu
0cf0: 6d 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 m;..} else {..
0d00: 20 20 72 65 74 3d 20 2d 31 3b 0a 09 7d 0a 09 62 ret= -1;..}..b
0d10: 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 reak;. case B
0d20: 49 4f 5f 43 54 52 4c 5f 47 45 54 5f 43 4c 4f 53 IO_CTRL_GET_CLOS
0d30: 45 3a 0a 09 72 65 74 3d 62 69 6f 2d 3e 73 68 75 E:..ret=bio->shu
0d40: 74 64 6f 77 6e 3b 0a 09 62 72 65 61 6b 3b 0a 20 tdown;..break;.
0d50: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c case BIO_CTRL
0d60: 5f 53 45 54 5f 43 4c 4f 53 45 3a 0a 09 62 69 6f _SET_CLOSE:..bio
0d70: 2d 3e 73 68 75 74 64 6f 77 6e 3d 28 69 6e 74 29 ->shutdown=(int)
0d80: 6e 75 6d 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 num;..break;.
0d90: 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 45 case BIO_CTRL_E
0da0: 4f 46 3a 0a 09 64 70 72 69 6e 74 66 28 73 74 64 OF:..dprintf(std
0db0: 65 72 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f 45 err, "BIO_CTRL_E
0dc0: 4f 46 5c 6e 22 29 3b 0a 09 72 65 74 20 3d 20 54 OF\n");..ret = T
0dd0: 63 6c 5f 45 6f 66 28 20 63 68 61 6e 29 3b 0a 09 cl_Eof( chan);..
0de0: 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 break;. case
0df0: 42 49 4f 5f 43 54 52 4c 5f 50 45 4e 44 49 4e 47 BIO_CTRL_PENDING
0e00: 3a 0a 09 69 66 20 28 54 63 6c 5f 49 6e 70 75 74 :..if (Tcl_Input
0e10: 42 75 66 66 65 72 65 64 28 63 68 61 6e 29 29 0a Buffered(chan)).
0e20: 09 20 20 20 20 72 65 74 20 3d 20 31 3b 0a 09 65 . ret = 1;..e
0e30: 6c 73 65 0a 09 20 20 20 20 72 65 74 20 3d 20 30 lse.. ret = 0
0e40: 3b 0a 09 64 70 72 69 6e 74 66 28 73 74 64 65 72 ;..dprintf(stder
0e50: 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f 50 45 4e r, "BIO_CTRL_PEN
0e60: 44 49 4e 47 28 25 64 29 5c 6e 22 2c 20 72 65 74 DING(%d)\n", ret
0e70: 29 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 );..break;. c
0e80: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 57 50 45 ase BIO_CTRL_WPE
0e90: 4e 44 49 4e 47 3a 0a 09 72 65 74 3d 30 3b 0a 09 NDING:..ret=0;..
0ea0: 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 break;. case
0eb0: 42 49 4f 5f 43 54 52 4c 5f 44 55 50 3a 0a 09 62 BIO_CTRL_DUP:..b
0ec0: 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 reak;. case B
0ed0: 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 3a 0a 09 IO_CTRL_FLUSH:..
0ee0: 64 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 dprintf(stderr,
0ef0: 22 42 49 4f 5f 43 54 52 4c 5f 46 4c 55 53 48 5c "BIO_CTRL_FLUSH\
0f00: 6e 22 29 3b 0a 09 69 66 20 28 0a 23 69 66 64 65 n");..if (.#ifde
0f10: 66 20 54 43 4c 5f 43 48 41 4e 4e 45 4c 5f 56 45 f TCL_CHANNEL_VE
0f20: 52 53 49 4f 4e 5f 32 0a 09 20 20 20 20 54 63 6c RSION_2.. Tcl
0f30: 5f 57 72 69 74 65 52 61 77 28 63 68 61 6e 2c 20 _WriteRaw(chan,
0f40: 22 22 2c 20 30 29 20 3e 3d 20 30 0a 23 65 6c 73 "", 0) >= 0.#els
0f50: 65 0a 09 20 20 20 20 54 63 6c 5f 46 6c 75 73 68 e.. Tcl_Flush
0f60: 28 20 63 68 61 6e 29 20 3d 3d 20 54 43 4c 5f 4f ( chan) == TCL_O
0f70: 4b 0a 23 65 6e 64 69 66 0a 09 20 20 20 20 29 20 K.#endif.. )
0f80: 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 31 3b 0a {.. ret = 1;.
0f90: 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 72 .} else {.. r
0fa0: 65 74 20 3d 20 2d 31 3b 0a 09 7d 0a 09 62 72 65 et = -1;..}..bre
0fb0: 61 6b 3b 0a 20 20 20 20 64 65 66 61 75 6c 74 3a ak;. default:
0fc0: 0a 09 72 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 ..ret = 0;..brea
0fd0: 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 k;. }. ret
0fe0: 75 72 6e 28 72 65 74 29 3b 0a 7d 0a 0a 73 74 61 urn(ret);.}..sta
0ff0: 74 69 63 20 69 6e 74 0a 42 69 6f 4e 65 77 09 28 tic int.BioNew.(
1000: 62 69 6f 29 0a 20 20 20 20 42 49 4f 20 2a 62 69 bio). BIO *bi
1010: 6f 3b 0a 7b 0a 20 20 20 20 62 69 6f 2d 3e 69 6e o;.{. bio->in
1020: 69 74 20 3d 20 30 3b 0a 20 20 20 20 62 69 6f 2d it = 0;. bio-
1030: 3e 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 20 62 69 >num = 0;. bi
1040: 6f 2d 3e 70 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 o->ptr = NULL;.
1050: 20 20 20 62 69 6f 2d 3e 66 6c 61 67 73 20 3d 20 bio->flags =
1060: 30 3b 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 31 0;.. return 1
1070: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a ;.}..static int.
1080: 42 69 6f 46 72 65 65 09 28 62 69 6f 29 0a 20 20 BioFree.(bio).
1090: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 7b 0a 20 20 BIO *bio;.{.
10a0: 20 20 69 66 20 28 62 69 6f 20 3d 3d 20 4e 55 4c if (bio == NUL
10b0: 4c 29 0a 09 72 65 74 75 72 6e 20 30 3b 0a 0a 20 L)..return 0;..
10c0: 20 20 20 69 66 20 28 62 69 6f 2d 3e 73 68 75 74 if (bio->shut
10d0: 64 6f 77 6e 29 20 7b 0a 09 69 66 20 28 62 69 6f down) {..if (bio
10e0: 2d 3e 69 6e 69 74 29 20 7b 0a 09 20 20 20 20 2f ->init) {.. /
10f0: 2a 73 68 75 74 64 6f 77 6e 28 62 69 6f 2d 3e 6e *shutdown(bio->n
1100: 75 6d 2c 20 32 29 20 2a 2f 0a 09 20 20 20 20 2f um, 2) */.. /
1110: 2a 63 6c 6f 73 65 73 6f 63 6b 65 74 28 62 69 6f *closesocket(bio
1120: 2d 3e 6e 75 6d 29 20 2a 2f 0a 09 7d 0a 09 62 69 ->num) */..}..bi
1130: 6f 2d 3e 69 6e 69 74 20 3d 20 30 3b 0a 09 62 69 o->init = 0;..bi
1140: 6f 2d 3e 66 6c 61 67 73 20 3d 20 30 3b 0a 09 62 o->flags = 0;..b
1150: 69 6f 2d 3e 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 io->num = 0;.
1160: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 31 3b }. return 1;
1170: 0a 7d 0a .}.