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 34 20 32 30 30 30 2f 30 O.c,v 1.4 2000/0
0090: 38 2f 31 35 20 30 30 3a 30 32 3a 30 38 20 68 6f 8/15 00:02:08 ho
00a0: 62 62 73 20 45 78 70 20 24 0a 20 2a 0a 20 2a 20 bbs Exp $. *. *
00b0: 50 72 6f 76 69 64 65 73 20 42 49 4f 20 6c 61 79 Provides BIO lay
00c0: 65 72 20 74 6f 20 69 6e 74 65 72 66 61 63 65 20 er to interface
00d0: 6f 70 65 6e 73 73 6c 20 74 6f 20 54 63 6c 2e 0a openssl to Tcl..
00e0: 20 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 22 74 */..#include "t
00f0: 6c 73 49 6e 74 2e 68 22 0a 0a 2f 2a 0a 20 2a 20 lsInt.h"../*. *
0100: 46 6f 72 77 61 72 64 20 64 65 63 6c 61 72 61 74 Forward declarat
0110: 69 6f 6e 73 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 ions. */..static
0120: 20 69 6e 74 20 42 69 6f 57 72 69 74 65 09 5f 41 int BioWrite._A
0130: 4e 53 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 NSI_ARGS_ ((BIO
0140: 2a 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 69 *h, char *buf, i
0150: 6e 74 20 6e 75 6d 29 29 3b 0a 73 74 61 74 69 63 nt num));.static
0160: 20 69 6e 74 20 42 69 6f 52 65 61 64 09 5f 41 4e int BioRead._AN
0170: 53 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a SI_ARGS_ ((BIO *
0180: 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 69 6e h, char *buf, in
0190: 74 20 6e 75 6d 29 29 3b 0a 73 74 61 74 69 63 20 t num));.static
01a0: 69 6e 74 20 42 69 6f 50 75 74 73 09 5f 41 4e 53 int BioPuts._ANS
01b0: 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68 I_ARGS_ ((BIO *h
01c0: 2c 20 63 68 61 72 20 2a 73 74 72 29 29 3b 0a 73 , char *str));.s
01d0: 74 61 74 69 63 20 6c 6f 6e 67 20 42 69 6f 43 74 tatic long BioCt
01e0: 72 6c 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 rl._ANSI_ARGS_ (
01f0: 28 42 49 4f 20 2a 68 2c 20 69 6e 74 20 63 6d 64 (BIO *h, int cmd
0200: 2c 20 6c 6f 6e 67 20 61 72 67 31 2c 20 63 68 61 , long arg1, cha
0210: 72 20 2a 70 74 72 29 29 3b 0a 73 74 61 74 69 63 r *ptr));.static
0220: 20 69 6e 74 20 42 69 6f 4e 65 77 09 5f 41 4e 53 int BioNew._ANS
0230: 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68 I_ARGS_ ((BIO *h
0240: 29 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 42 ));.static int B
0250: 69 6f 46 72 65 65 09 5f 41 4e 53 49 5f 41 52 47 ioFree._ANSI_ARG
0260: 53 5f 20 28 28 42 49 4f 20 2a 68 29 29 3b 0a 0a S_ ((BIO *h));..
0270: 0a 73 74 61 74 69 63 20 42 49 4f 5f 4d 45 54 48 .static BIO_METH
0280: 4f 44 20 42 69 6f 4d 65 74 68 6f 64 73 20 3d 20 OD BioMethods =
0290: 7b 0a 20 20 20 20 42 49 4f 5f 54 59 50 45 5f 54 {. BIO_TYPE_T
02a0: 43 4c 2c 20 22 74 63 6c 22 2c 0a 20 20 20 20 42 CL, "tcl",. B
02b0: 69 6f 57 72 69 74 65 2c 0a 20 20 20 20 42 69 6f ioWrite,. Bio
02c0: 52 65 61 64 2c 0a 20 20 20 20 42 69 6f 50 75 74 Read,. BioPut
02d0: 73 2c 0a 20 20 20 20 4e 55 4c 4c 2c 09 2f 2a 20 s,. NULL,./*
02e0: 42 69 6f 47 65 74 73 20 2a 2f 0a 20 20 20 20 42 BioGets */. B
02f0: 69 6f 43 74 72 6c 2c 0a 20 20 20 20 42 69 6f 4e ioCtrl,. BioN
0300: 65 77 2c 0a 20 20 20 20 42 69 6f 46 72 65 65 2c ew,. BioFree,
0310: 0a 7d 3b 0a 0a 42 49 4f 20 2a 0a 42 49 4f 5f 6e .};..BIO *.BIO_n
0320: 65 77 5f 74 63 6c 28 73 74 61 74 65 50 74 72 2c ew_tcl(statePtr,
0330: 20 66 6c 61 67 73 29 0a 20 20 20 20 53 74 61 74 flags). Stat
0340: 65 20 2a 73 74 61 74 65 50 74 72 3b 0a 20 20 20 e *statePtr;.
0350: 20 69 6e 74 20 66 6c 61 67 73 3b 0a 7b 0a 20 20 int flags;.{.
0360: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 0a 20 20 20 BIO *bio;..
0370: 20 62 69 6f 09 09 09 3d 20 42 49 4f 5f 6e 65 77 bio...= BIO_new
0380: 28 26 42 69 6f 4d 65 74 68 6f 64 73 29 3b 0a 20 (&BioMethods);.
0390: 20 20 20 62 69 6f 2d 3e 70 74 72 09 09 3d 20 28 bio->ptr..= (
03a0: 63 68 61 72 2a 29 73 74 61 74 65 50 74 72 3b 0a char*)statePtr;.
03b0: 20 20 20 20 62 69 6f 2d 3e 69 6e 69 74 09 09 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 09 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 28 62 69 6f ent((State*)(bio
04b0: 2d 3e 70 74 72 29 29 3b 0a 20 20 20 20 69 6e 74 ->ptr));. int
04c0: 20 72 65 74 3b 0a 0a 20 20 20 20 64 70 72 69 6e ret;.. dprin
04d0: 74 66 28 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f tf(stderr,"\nBio
04e0: 57 72 69 74 65 28 30 78 25 78 2c 20 3c 62 75 66 Write(0x%x, <buf
04f0: 3e 2c 20 25 64 29 20 5b 30 78 25 78 5d 22 2c 20 >, %d) [0x%x]",
0500: 62 69 6f 2c 20 62 75 66 4c 65 6e 2c 20 63 68 61 bio, bufLen, cha
0510: 6e 29 3b 0a 0a 20 20 20 20 69 66 20 28 63 68 61 n);.. if (cha
0520: 6e 6e 65 6c 54 79 70 65 56 65 72 73 69 6f 6e 20 nnelTypeVersion
0530: 3d 3d 20 54 4c 53 5f 43 48 41 4e 4e 45 4c 5f 56 == TLS_CHANNEL_V
0540: 45 52 53 49 4f 4e 5f 32 29 20 7b 0a 09 72 65 74 ERSION_2) {..ret
0550: 20 3d 20 54 63 6c 5f 57 72 69 74 65 52 61 77 28 = Tcl_WriteRaw(
0560: 63 68 61 6e 2c 20 62 75 66 2c 20 62 75 66 4c 65 chan, buf, bufLe
0570: 6e 29 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b n);. } else {
0580: 0a 09 72 65 74 20 3d 20 54 63 6c 5f 57 72 69 74 ..ret = Tcl_Writ
0590: 65 28 63 68 61 6e 2c 20 62 75 66 2c 20 62 75 66 e(chan, buf, buf
05a0: 4c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 Len);. }..
05b0: 20 64 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c dprintf(stderr,
05c0: 22 5c 6e 5b 30 78 25 78 5d 20 42 69 6f 57 72 69 "\n[0x%x] BioWri
05d0: 74 65 28 25 64 29 20 2d 3e 20 25 64 20 5b 25 64 te(%d) -> %d [%d
05e0: 2e 25 64 5d 22 2c 20 63 68 61 6e 2c 20 62 75 66 .%d]", chan, buf
05f0: 4c 65 6e 2c 20 72 65 74 2c 0a 09 20 20 20 20 54 Len, ret,.. T
0600: 63 6c 5f 45 6f 66 28 63 68 61 6e 29 2c 20 54 63 cl_Eof(chan), Tc
0610: 6c 5f 47 65 74 45 72 72 6e 6f 28 29 29 3b 0a 0a l_GetErrno());..
0620: 20 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c BIO_clear_fl
0630: 61 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 ags(bio, BIO_FLA
0640: 47 53 5f 57 52 49 54 45 7c 42 49 4f 5f 46 4c 41 GS_WRITE|BIO_FLA
0650: 47 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59 29 GS_SHOULD_RETRY)
0660: 3b 0a 0a 20 20 20 20 69 66 20 28 72 65 74 20 3d ;.. if (ret =
0670: 3d 20 30 29 20 7b 0a 09 69 66 20 28 21 54 63 6c = 0) {..if (!Tcl
0680: 5f 45 6f 66 28 63 68 61 6e 29 29 20 7b 0a 09 20 _Eof(chan)) {..
0690: 20 20 20 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 BIO_set_retry
06a0: 5f 77 72 69 74 65 28 62 69 6f 29 3b 0a 09 20 20 _write(bio);..
06b0: 20 20 72 65 74 20 3d 20 2d 31 3b 0a 09 7d 0a 20 ret = -1;..}.
06c0: 20 20 20 7d 0a 20 20 20 20 69 66 20 28 42 49 4f }. if (BIO
06d0: 5f 73 68 6f 75 6c 64 5f 72 65 61 64 28 62 69 6f _should_read(bio
06e0: 29 29 20 7b 0a 09 42 49 4f 5f 73 65 74 5f 72 65 )) {..BIO_set_re
06f0: 74 72 79 5f 72 65 61 64 28 62 69 6f 29 3b 0a 20 try_read(bio);.
0700: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
0710: 72 65 74 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 ret;.}..static i
0720: 6e 74 0a 42 69 6f 52 65 61 64 20 28 62 69 6f 2c nt.BioRead (bio,
0730: 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 0a 20 20 buf, bufLen).
0740: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 BIO *bio;.
0750: 63 68 61 72 20 2a 62 75 66 3b 0a 20 20 20 20 69 char *buf;. i
0760: 6e 74 20 62 75 66 4c 65 6e 3b 0a 7b 0a 20 20 20 nt bufLen;.{.
0770: 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 Tcl_Channel cha
0780: 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72 65 6e n = Tls_GetParen
0790: 74 28 28 53 74 61 74 65 2a 29 62 69 6f 2d 3e 70 t((State*)bio->p
07a0: 74 72 29 3b 0a 20 20 20 20 69 6e 74 20 72 65 74 tr);. int ret
07b0: 20 3d 20 30 3b 0a 0a 20 20 20 20 64 70 72 69 6e = 0;.. dprin
07c0: 74 66 28 73 74 64 65 72 72 2c 22 5c 6e 42 69 6f tf(stderr,"\nBio
07d0: 52 65 61 64 28 30 78 25 78 2c 20 3c 62 75 66 3e Read(0x%x, <buf>
07e0: 2c 20 25 64 29 20 5b 30 78 25 78 5d 22 2c 20 62 , %d) [0x%x]", b
07f0: 69 6f 2c 20 62 75 66 4c 65 6e 2c 20 63 68 61 6e io, bufLen, chan
0800: 29 3b 0a 0a 20 20 20 20 69 66 20 28 62 75 66 20 );.. if (buf
0810: 3d 3d 20 4e 55 4c 4c 29 20 72 65 74 75 72 6e 20 == NULL) return
0820: 30 3b 0a 0a 20 20 20 20 69 66 20 28 63 68 61 6e 0;.. if (chan
0830: 6e 65 6c 54 79 70 65 56 65 72 73 69 6f 6e 20 3d nelTypeVersion =
0840: 3d 20 54 4c 53 5f 43 48 41 4e 4e 45 4c 5f 56 45 = TLS_CHANNEL_VE
0850: 52 53 49 4f 4e 5f 32 29 20 7b 0a 09 72 65 74 20 RSION_2) {..ret
0860: 3d 20 54 63 6c 5f 52 65 61 64 52 61 77 28 63 68 = Tcl_ReadRaw(ch
0870: 61 6e 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 an, buf, bufLen)
0880: 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 ;. } else {..
0890: 72 65 74 20 3d 20 54 63 6c 5f 52 65 61 64 28 63 ret = Tcl_Read(c
08a0: 68 61 6e 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e han, buf, bufLen
08b0: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 64 70 );. }.. dp
08c0: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 22 5c 6e rintf(stderr,"\n
08d0: 5b 30 78 25 78 5d 20 42 69 6f 52 65 61 64 28 25 [0x%x] BioRead(%
08e0: 64 29 20 2d 3e 20 25 64 20 5b 25 64 2e 25 64 5d d) -> %d [%d.%d]
08f0: 22 2c 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e 2c ", chan, bufLen,
0900: 20 72 65 74 2c 0a 09 20 20 20 20 54 63 6c 5f 45 ret,.. Tcl_E
0910: 6f 66 28 63 68 61 6e 29 2c 20 54 63 6c 5f 47 65 of(chan), Tcl_Ge
0920: 74 45 72 72 6e 6f 28 29 29 3b 0a 0a 20 20 20 20 tErrno());..
0930: 42 49 4f 5f 63 6c 65 61 72 5f 66 6c 61 67 73 28 BIO_clear_flags(
0940: 62 69 6f 2c 20 42 49 4f 5f 46 4c 41 47 53 5f 52 bio, BIO_FLAGS_R
0950: 45 41 44 7c 42 49 4f 5f 46 4c 41 47 53 5f 53 48 EAD|BIO_FLAGS_SH
0960: 4f 55 4c 44 5f 52 45 54 52 59 29 3b 0a 0a 20 20 OULD_RETRY);..
0970: 20 20 69 66 20 28 72 65 74 20 3d 3d 20 30 29 20 if (ret == 0)
0980: 7b 0a 09 69 66 20 28 21 54 63 6c 5f 45 6f 66 28 {..if (!Tcl_Eof(
0990: 63 68 61 6e 29 29 20 7b 0a 09 20 20 20 20 42 49 chan)) {.. BI
09a0: 4f 5f 73 65 74 5f 72 65 74 72 79 5f 72 65 61 64 O_set_retry_read
09b0: 28 62 69 6f 29 3b 0a 09 20 20 20 20 72 65 74 20 (bio);.. ret
09c0: 3d 20 2d 31 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 = -1;..}. }.
09d0: 20 20 20 69 66 20 28 42 49 4f 5f 73 68 6f 75 6c if (BIO_shoul
09e0: 64 5f 77 72 69 74 65 28 62 69 6f 29 29 20 7b 0a d_write(bio)) {.
09f0: 09 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f 77 .BIO_set_retry_w
0a00: 72 69 74 65 28 62 69 6f 29 3b 0a 20 20 20 20 7d rite(bio);. }
0a10: 0a 20 20 20 20 72 65 74 75 72 6e 20 72 65 74 3b . return ret;
0a20: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a 42 .}..static int.B
0a30: 69 6f 50 75 74 73 09 28 62 69 6f 2c 20 73 74 72 ioPuts.(bio, str
0a40: 29 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a ). BIO *bio;.
0a50: 20 20 20 20 63 68 61 72 20 2a 73 74 72 3b 0a 7b char *str;.{
0a60: 0a 20 20 20 20 72 65 74 75 72 6e 20 42 69 6f 57 . return BioW
0a70: 72 69 74 65 28 62 69 6f 2c 20 73 74 72 2c 20 73 rite(bio, str, s
0a80: 74 72 6c 65 6e 28 73 74 72 29 29 3b 0a 7d 0a 0a trlen(str));.}..
0a90: 73 74 61 74 69 63 20 6c 6f 6e 67 0a 42 69 6f 43 static long.BioC
0aa0: 74 72 6c 09 28 62 69 6f 2c 20 63 6d 64 2c 20 6e trl.(bio, cmd, n
0ab0: 75 6d 2c 20 70 74 72 29 0a 20 20 20 20 42 49 4f um, ptr). BIO
0ac0: 20 2a 62 69 6f 3b 0a 20 20 20 20 69 6e 74 20 63 *bio;. int c
0ad0: 6d 64 3b 0a 20 20 20 20 6c 6f 6e 67 20 6e 75 6d md;. long num
0ae0: 3b 0a 20 20 20 20 63 68 61 72 20 2a 70 74 72 3b ;. char *ptr;
0af0: 0a 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e .{. Tcl_Chann
0b00: 65 6c 20 63 68 61 6e 20 3d 20 54 6c 73 5f 47 65 el chan = Tls_Ge
0b10: 74 50 61 72 65 6e 74 28 28 53 74 61 74 65 2a 29 tParent((State*)
0b20: 62 69 6f 2d 3e 70 74 72 29 3b 0a 20 20 20 20 6c bio->ptr);. l
0b30: 6f 6e 67 20 72 65 74 20 3d 20 31 3b 0a 20 20 20 ong ret = 1;.
0b40: 20 69 6e 74 20 2a 69 70 3b 0a 0a 20 20 20 20 64 int *ip;.. d
0b50: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 22 5c printf(stderr,"\
0b60: 6e 42 69 6f 43 74 72 6c 28 30 78 25 78 2c 20 30 nBioCtrl(0x%x, 0
0b70: 78 25 78 2c 20 30 78 25 78 2c 20 30 78 25 78 29 x%x, 0x%x, 0x%x)
0b80: 22 2c 20 62 69 6f 2c 20 63 6d 64 2c 20 6e 75 6d ", bio, cmd, num
0b90: 2c 20 70 74 72 29 3b 0a 0a 20 20 20 20 73 77 69 , ptr);.. swi
0ba0: 74 63 68 20 28 63 6d 64 29 20 7b 0a 20 20 20 20 tch (cmd) {.
0bb0: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 52 45 case BIO_CTRL_RE
0bc0: 53 45 54 3a 0a 09 6e 75 6d 20 3d 20 30 3b 0a 20 SET:..num = 0;.
0bd0: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 5f 46 49 case BIO_C_FI
0be0: 4c 45 5f 53 45 45 4b 3a 0a 20 20 20 20 63 61 73 LE_SEEK:. cas
0bf0: 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c e BIO_C_FILE_TEL
0c00: 4c 3a 0a 09 72 65 74 20 3d 20 30 3b 0a 09 62 72 L:..ret = 0;..br
0c10: 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 eak;. case BI
0c20: 4f 5f 43 54 52 4c 5f 49 4e 46 4f 3a 0a 09 72 65 O_CTRL_INFO:..re
0c30: 74 20 3d 20 31 3b 0a 09 62 72 65 61 6b 3b 0a 20 t = 1;..break;.
0c40: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 5f 53 45 case BIO_C_SE
0c50: 54 5f 46 44 3a 0a 09 42 69 6f 46 72 65 65 28 62 T_FD:..BioFree(b
0c60: 69 6f 29 3b 0a 09 2f 2a 20 53 65 74 73 20 53 74 io);../* Sets St
0c70: 61 74 65 2a 20 2a 2f 0a 09 62 69 6f 2d 3e 70 74 ate* */..bio->pt
0c80: 72 09 3d 20 2a 28 28 63 68 61 72 20 2a 2a 29 70 r.= *((char **)p
0c90: 74 72 29 3b 0a 09 62 69 6f 2d 3e 73 68 75 74 64 tr);..bio->shutd
0ca0: 6f 77 6e 09 3d 20 28 69 6e 74 29 6e 75 6d 3b 0a own.= (int)num;.
0cb0: 09 62 69 6f 2d 3e 69 6e 69 74 09 3d 20 31 3b 0a .bio->init.= 1;.
0cc0: 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 .break;. case
0cd0: 20 42 49 4f 5f 43 5f 47 45 54 5f 46 44 3a 0a 09 BIO_C_GET_FD:..
0ce0: 69 66 20 28 62 69 6f 2d 3e 69 6e 69 74 29 20 7b if (bio->init) {
0cf0: 0a 09 20 20 20 20 69 70 20 3d 20 28 69 6e 74 20 .. ip = (int
0d00: 2a 29 70 74 72 3b 0a 09 20 20 20 20 69 66 20 28 *)ptr;.. if (
0d10: 69 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 ip != NULL) {...
0d20: 2a 69 70 20 3d 20 62 69 6f 2d 3e 6e 75 6d 3b 0a *ip = bio->num;.
0d30: 09 20 20 20 20 7d 0a 09 20 20 20 20 72 65 74 20 . }.. ret
0d40: 3d 20 62 69 6f 2d 3e 6e 75 6d 3b 0a 09 7d 20 65 = bio->num;..} e
0d50: 6c 73 65 20 7b 0a 09 20 20 20 20 72 65 74 20 3d lse {.. ret =
0d60: 20 2d 31 3b 0a 09 7d 0a 09 62 72 65 61 6b 3b 0a -1;..}..break;.
0d70: 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 case BIO_CTR
0d80: 4c 5f 47 45 54 5f 43 4c 4f 53 45 3a 0a 09 72 65 L_GET_CLOSE:..re
0d90: 74 20 3d 20 62 69 6f 2d 3e 73 68 75 74 64 6f 77 t = bio->shutdow
0da0: 6e 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 n;..break;. c
0db0: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 53 45 54 ase BIO_CTRL_SET
0dc0: 5f 43 4c 4f 53 45 3a 0a 09 62 69 6f 2d 3e 73 68 _CLOSE:..bio->sh
0dd0: 75 74 64 6f 77 6e 20 3d 20 28 69 6e 74 29 6e 75 utdown = (int)nu
0de0: 6d 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 m;..break;. c
0df0: 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 ase BIO_CTRL_EOF
0e00: 3a 0a 09 64 70 72 69 6e 74 66 28 73 74 64 65 72 :..dprintf(stder
0e10: 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 r, "BIO_CTRL_EOF
0e20: 5c 6e 22 29 3b 0a 09 72 65 74 20 3d 20 54 63 6c \n");..ret = Tcl
0e30: 5f 45 6f 66 28 63 68 61 6e 29 3b 0a 09 62 72 65 _Eof(chan);..bre
0e40: 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f ak;. case BIO
0e50: 5f 43 54 52 4c 5f 50 45 4e 44 49 4e 47 3a 0a 09 _CTRL_PENDING:..
0e60: 72 65 74 20 3d 20 28 54 63 6c 5f 49 6e 70 75 74 ret = (Tcl_Input
0e70: 42 75 66 66 65 72 65 64 28 63 68 61 6e 29 20 3f Buffered(chan) ?
0e80: 20 31 20 3a 20 30 29 3b 0a 09 64 70 72 69 6e 74 1 : 0);..dprint
0e90: 66 28 73 74 64 65 72 72 2c 20 22 42 49 4f 5f 43 f(stderr, "BIO_C
0ea0: 54 52 4c 5f 50 45 4e 44 49 4e 47 28 25 64 29 5c TRL_PENDING(%d)\
0eb0: 6e 22 2c 20 72 65 74 29 3b 0a 09 62 72 65 61 6b n", ret);..break
0ec0: 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 ;. case BIO_C
0ed0: 54 52 4c 5f 57 50 45 4e 44 49 4e 47 3a 0a 09 72 TRL_WPENDING:..r
0ee0: 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b 0a et = 0;..break;.
0ef0: 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 case BIO_CTR
0f00: 4c 5f 44 55 50 3a 0a 09 62 72 65 61 6b 3b 0a 20 L_DUP:..break;.
0f10: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c case BIO_CTRL
0f20: 5f 46 4c 55 53 48 3a 0a 09 64 70 72 69 6e 74 66 _FLUSH:..dprintf
0f30: 28 73 74 64 65 72 72 2c 20 22 42 49 4f 5f 43 54 (stderr, "BIO_CT
0f40: 52 4c 5f 46 4c 55 53 48 5c 6e 22 29 3b 0a 09 69 RL_FLUSH\n");..i
0f50: 66 20 28 63 68 61 6e 6e 65 6c 54 79 70 65 56 65 f (channelTypeVe
0f60: 72 73 69 6f 6e 20 3d 3d 20 54 4c 53 5f 43 48 41 rsion == TLS_CHA
0f70: 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f 32 29 20 NNEL_VERSION_2)
0f80: 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 28 28 54 {.. ret = ((T
0f90: 63 6c 5f 57 72 69 74 65 52 61 77 28 63 68 61 6e cl_WriteRaw(chan
0fa0: 2c 20 22 22 2c 20 30 29 20 3e 3d 20 30 29 20 3f , "", 0) >= 0) ?
0fb0: 20 31 20 3a 20 2d 31 29 3b 0a 09 7d 20 65 6c 73 1 : -1);..} els
0fc0: 65 20 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 28 e {.. ret = (
0fd0: 28 54 63 6c 5f 46 6c 75 73 68 28 63 68 61 6e 29 (Tcl_Flush(chan)
0fe0: 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 3f 20 31 20 == TCL_OK) ? 1
0ff0: 3a 20 2d 31 29 3b 0a 09 7d 0a 09 62 72 65 61 6b : -1);..}..break
1000: 3b 0a 20 20 20 20 64 65 66 61 75 6c 74 3a 0a 09 ;. default:..
1010: 72 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b ret = 0;..break;
1020: 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 . }. retur
1030: 6e 28 72 65 74 29 3b 0a 7d 0a 0a 73 74 61 74 69 n(ret);.}..stati
1040: 63 20 69 6e 74 0a 42 69 6f 4e 65 77 09 28 62 69 c int.BioNew.(bi
1050: 6f 29 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b o). BIO *bio;
1060: 0a 7b 0a 20 20 20 20 62 69 6f 2d 3e 69 6e 69 74 .{. bio->init
1070: 09 3d 20 30 3b 0a 20 20 20 20 62 69 6f 2d 3e 6e .= 0;. bio->n
1080: 75 6d 09 3d 20 30 3b 0a 20 20 20 20 62 69 6f 2d um.= 0;. bio-
1090: 3e 70 74 72 09 3d 20 4e 55 4c 4c 3b 0a 20 20 20 >ptr.= NULL;.
10a0: 20 62 69 6f 2d 3e 66 6c 61 67 73 09 3d 20 30 3b bio->flags.= 0;
10b0: 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a .. return 1;.
10c0: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a 42 69 }..static int.Bi
10d0: 6f 46 72 65 65 09 28 62 69 6f 29 0a 20 20 20 20 oFree.(bio).
10e0: 42 49 4f 20 2a 62 69 6f 3b 0a 7b 0a 20 20 20 20 BIO *bio;.{.
10f0: 69 66 20 28 62 69 6f 20 3d 3d 20 4e 55 4c 4c 29 if (bio == NULL)
1100: 20 7b 0a 09 72 65 74 75 72 6e 20 30 3b 0a 20 20 {..return 0;.
1110: 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 62 69 6f }.. if (bio
1120: 2d 3e 73 68 75 74 64 6f 77 6e 29 20 7b 0a 09 69 ->shutdown) {..i
1130: 66 20 28 62 69 6f 2d 3e 69 6e 69 74 29 20 7b 0a f (bio->init) {.
1140: 09 20 20 20 20 2f 2a 73 68 75 74 64 6f 77 6e 28 . /*shutdown(
1150: 62 69 6f 2d 3e 6e 75 6d 2c 20 32 29 20 2a 2f 0a bio->num, 2) */.
1160: 09 20 20 20 20 2f 2a 63 6c 6f 73 65 73 6f 63 6b . /*closesock
1170: 65 74 28 62 69 6f 2d 3e 6e 75 6d 29 20 2a 2f 0a et(bio->num) */.
1180: 09 7d 0a 09 62 69 6f 2d 3e 69 6e 69 74 09 3d 20 .}..bio->init.=
1190: 30 3b 0a 09 62 69 6f 2d 3e 66 6c 61 67 73 09 3d 0;..bio->flags.=
11a0: 20 30 3b 0a 09 62 69 6f 2d 3e 6e 75 6d 09 3d 20 0;..bio->num.=
11b0: 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 0;. }. ret
11c0: 75 72 6e 20 31 3b 0a 7d 0a urn 1;.}.