Hex Artifact Content

Artifact 61828ed639151ec868a176f76e6b35112107d26b:


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 35 20 32 30 30 30 2f 30  O.c,v 1.5 2000/0
0090: 38 2f 31 38 20 31 39 3a 31 37 3a 33 36 20 68 6f  8/18 19:17:36 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 0a  >, %d) [0x%x]",.
0500: 09 20 20 20 20 28 75 6e 73 69 67 6e 65 64 20 69  .    (unsigned i
0510: 6e 74 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e 2c  nt) bio, bufLen,
0520: 20 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 20   (unsigned int) 
0530: 63 68 61 6e 29 3b 0a 0a 20 20 20 20 69 66 20 28  chan);..    if (
0540: 63 68 61 6e 6e 65 6c 54 79 70 65 56 65 72 73 69  channelTypeVersi
0550: 6f 6e 20 3d 3d 20 54 4c 53 5f 43 48 41 4e 4e 45  on == TLS_CHANNE
0560: 4c 5f 56 45 52 53 49 4f 4e 5f 32 29 20 7b 0a 09  L_VERSION_2) {..
0570: 72 65 74 20 3d 20 54 63 6c 5f 57 72 69 74 65 52  ret = Tcl_WriteR
0580: 61 77 28 63 68 61 6e 2c 20 62 75 66 2c 20 62 75  aw(chan, buf, bu
0590: 66 4c 65 6e 29 3b 0a 20 20 20 20 7d 20 65 6c 73  fLen);.    } els
05a0: 65 20 7b 0a 09 72 65 74 20 3d 20 54 63 6c 5f 57  e {..ret = Tcl_W
05b0: 72 69 74 65 28 63 68 61 6e 2c 20 62 75 66 2c 20  rite(chan, buf, 
05c0: 62 75 66 4c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a  bufLen);.    }..
05d0: 20 20 20 20 64 70 72 69 6e 74 66 28 73 74 64 65      dprintf(stde
05e0: 72 72 2c 22 5c 6e 5b 30 78 25 78 5d 20 42 69 6f  rr,"\n[0x%x] Bio
05f0: 57 72 69 74 65 28 25 64 29 20 2d 3e 20 25 64 20  Write(%d) -> %d 
0600: 5b 25 64 2e 25 64 5d 22 2c 0a 09 20 20 20 20 28  [%d.%d]",..    (
0610: 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 20 63 68  unsigned int) ch
0620: 61 6e 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c  an, bufLen, ret,
0630: 20 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 2c 20   Tcl_Eof(chan), 
0640: 54 63 6c 5f 47 65 74 45 72 72 6e 6f 28 29 29 3b  Tcl_GetErrno());
0650: 0a 0a 20 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f  ..    BIO_clear_
0660: 66 6c 61 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46  flags(bio, BIO_F
0670: 4c 41 47 53 5f 57 52 49 54 45 7c 42 49 4f 5f 46  LAGS_WRITE|BIO_F
0680: 4c 41 47 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52  LAGS_SHOULD_RETR
0690: 59 29 3b 0a 0a 20 20 20 20 69 66 20 28 72 65 74  Y);..    if (ret
06a0: 20 3d 3d 20 30 29 20 7b 0a 09 69 66 20 28 21 54   == 0) {..if (!T
06b0: 63 6c 5f 45 6f 66 28 63 68 61 6e 29 29 20 7b 0a  cl_Eof(chan)) {.
06c0: 09 20 20 20 20 42 49 4f 5f 73 65 74 5f 72 65 74  .    BIO_set_ret
06d0: 72 79 5f 77 72 69 74 65 28 62 69 6f 29 3b 0a 09  ry_write(bio);..
06e0: 20 20 20 20 72 65 74 20 3d 20 2d 31 3b 0a 09 7d      ret = -1;..}
06f0: 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 20 28 42  .    }.    if (B
0700: 49 4f 5f 73 68 6f 75 6c 64 5f 72 65 61 64 28 62  IO_should_read(b
0710: 69 6f 29 29 20 7b 0a 09 42 49 4f 5f 73 65 74 5f  io)) {..BIO_set_
0720: 72 65 74 72 79 5f 72 65 61 64 28 62 69 6f 29 3b  retry_read(bio);
0730: 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72  .    }.    retur
0740: 6e 20 72 65 74 3b 0a 7d 0a 0a 73 74 61 74 69 63  n ret;.}..static
0750: 20 69 6e 74 0a 42 69 6f 52 65 61 64 20 28 62 69   int.BioRead (bi
0760: 6f 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 0a  o, buf, bufLen).
0770: 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20      BIO *bio;.  
0780: 20 20 63 68 61 72 20 2a 62 75 66 3b 0a 20 20 20    char *buf;.   
0790: 20 69 6e 74 20 62 75 66 4c 65 6e 3b 0a 7b 0a 20   int bufLen;.{. 
07a0: 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63     Tcl_Channel c
07b0: 68 61 6e 20 3d 20 54 6c 73 5f 47 65 74 50 61 72  han = Tls_GetPar
07c0: 65 6e 74 28 28 53 74 61 74 65 2a 29 62 69 6f 2d  ent((State*)bio-
07d0: 3e 70 74 72 29 3b 0a 20 20 20 20 69 6e 74 20 72  >ptr);.    int r
07e0: 65 74 20 3d 20 30 3b 0a 0a 20 20 20 20 64 70 72  et = 0;..    dpr
07f0: 69 6e 74 66 28 73 74 64 65 72 72 2c 22 5c 6e 42  intf(stderr,"\nB
0800: 69 6f 52 65 61 64 28 30 78 25 78 2c 20 3c 62 75  ioRead(0x%x, <bu
0810: 66 3e 2c 20 25 64 29 20 5b 30 78 25 78 5d 22 2c  f>, %d) [0x%x]",
0820: 0a 09 20 20 20 20 28 75 6e 73 69 67 6e 65 64 20  ..    (unsigned 
0830: 69 6e 74 29 20 62 69 6f 2c 20 62 75 66 4c 65 6e  int) bio, bufLen
0840: 2c 20 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 29  , (unsigned int)
0850: 20 63 68 61 6e 29 3b 0a 0a 20 20 20 20 69 66 20   chan);..    if 
0860: 28 62 75 66 20 3d 3d 20 4e 55 4c 4c 29 20 72 65  (buf == NULL) re
0870: 74 75 72 6e 20 30 3b 0a 0a 20 20 20 20 69 66 20  turn 0;..    if 
0880: 28 63 68 61 6e 6e 65 6c 54 79 70 65 56 65 72 73  (channelTypeVers
0890: 69 6f 6e 20 3d 3d 20 54 4c 53 5f 43 48 41 4e 4e  ion == TLS_CHANN
08a0: 45 4c 5f 56 45 52 53 49 4f 4e 5f 32 29 20 7b 0a  EL_VERSION_2) {.
08b0: 09 72 65 74 20 3d 20 54 63 6c 5f 52 65 61 64 52  .ret = Tcl_ReadR
08c0: 61 77 28 63 68 61 6e 2c 20 62 75 66 2c 20 62 75  aw(chan, buf, bu
08d0: 66 4c 65 6e 29 3b 0a 20 20 20 20 7d 20 65 6c 73  fLen);.    } els
08e0: 65 20 7b 0a 09 72 65 74 20 3d 20 54 63 6c 5f 52  e {..ret = Tcl_R
08f0: 65 61 64 28 63 68 61 6e 2c 20 62 75 66 2c 20 62  ead(chan, buf, b
0900: 75 66 4c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20  ufLen);.    }.. 
0910: 20 20 20 64 70 72 69 6e 74 66 28 73 74 64 65 72     dprintf(stder
0920: 72 2c 22 5c 6e 5b 30 78 25 78 5d 20 42 69 6f 52  r,"\n[0x%x] BioR
0930: 65 61 64 28 25 64 29 20 2d 3e 20 25 64 20 5b 25  ead(%d) -> %d [%
0940: 64 2e 25 64 5d 22 2c 0a 09 20 20 20 20 28 75 6e  d.%d]",..    (un
0950: 73 69 67 6e 65 64 20 69 6e 74 29 20 63 68 61 6e  signed int) chan
0960: 2c 20 62 75 66 4c 65 6e 2c 20 72 65 74 2c 20 54  , bufLen, ret, T
0970: 63 6c 5f 45 6f 66 28 63 68 61 6e 29 2c 20 54 63  cl_Eof(chan), Tc
0980: 6c 5f 47 65 74 45 72 72 6e 6f 28 29 29 3b 0a 0a  l_GetErrno());..
0990: 20 20 20 20 42 49 4f 5f 63 6c 65 61 72 5f 66 6c      BIO_clear_fl
09a0: 61 67 73 28 62 69 6f 2c 20 42 49 4f 5f 46 4c 41  ags(bio, BIO_FLA
09b0: 47 53 5f 52 45 41 44 7c 42 49 4f 5f 46 4c 41 47  GS_READ|BIO_FLAG
09c0: 53 5f 53 48 4f 55 4c 44 5f 52 45 54 52 59 29 3b  S_SHOULD_RETRY);
09d0: 0a 0a 20 20 20 20 69 66 20 28 72 65 74 20 3d 3d  ..    if (ret ==
09e0: 20 30 29 20 7b 0a 09 69 66 20 28 21 54 63 6c 5f   0) {..if (!Tcl_
09f0: 45 6f 66 28 63 68 61 6e 29 29 20 7b 0a 09 20 20  Eof(chan)) {..  
0a00: 20 20 42 49 4f 5f 73 65 74 5f 72 65 74 72 79 5f    BIO_set_retry_
0a10: 72 65 61 64 28 62 69 6f 29 3b 0a 09 20 20 20 20  read(bio);..    
0a20: 72 65 74 20 3d 20 2d 31 3b 0a 09 7d 0a 20 20 20  ret = -1;..}.   
0a30: 20 7d 0a 20 20 20 20 69 66 20 28 42 49 4f 5f 73   }.    if (BIO_s
0a40: 68 6f 75 6c 64 5f 77 72 69 74 65 28 62 69 6f 29  hould_write(bio)
0a50: 29 20 7b 0a 09 42 49 4f 5f 73 65 74 5f 72 65 74  ) {..BIO_set_ret
0a60: 72 79 5f 77 72 69 74 65 28 62 69 6f 29 3b 0a 20  ry_write(bio);. 
0a70: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20     }.    return 
0a80: 72 65 74 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69  ret;.}..static i
0a90: 6e 74 0a 42 69 6f 50 75 74 73 09 28 62 69 6f 2c  nt.BioPuts.(bio,
0aa0: 20 73 74 72 29 0a 20 20 20 20 42 49 4f 20 2a 62   str).    BIO *b
0ab0: 69 6f 3b 0a 20 20 20 20 63 68 61 72 20 2a 73 74  io;.    char *st
0ac0: 72 3b 0a 7b 0a 20 20 20 20 72 65 74 75 72 6e 20  r;.{.    return 
0ad0: 42 69 6f 57 72 69 74 65 28 62 69 6f 2c 20 73 74  BioWrite(bio, st
0ae0: 72 2c 20 73 74 72 6c 65 6e 28 73 74 72 29 29 3b  r, strlen(str));
0af0: 0a 7d 0a 0a 73 74 61 74 69 63 20 6c 6f 6e 67 0a  .}..static long.
0b00: 42 69 6f 43 74 72 6c 09 28 62 69 6f 2c 20 63 6d  BioCtrl.(bio, cm
0b10: 64 2c 20 6e 75 6d 2c 20 70 74 72 29 0a 20 20 20  d, num, ptr).   
0b20: 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 69   BIO *bio;.    i
0b30: 6e 74 20 63 6d 64 3b 0a 20 20 20 20 6c 6f 6e 67  nt cmd;.    long
0b40: 20 6e 75 6d 3b 0a 20 20 20 20 63 68 61 72 20 2a   num;.    char *
0b50: 70 74 72 3b 0a 7b 0a 20 20 20 20 54 63 6c 5f 43  ptr;.{.    Tcl_C
0b60: 68 61 6e 6e 65 6c 20 63 68 61 6e 20 3d 20 54 6c  hannel chan = Tl
0b70: 73 5f 47 65 74 50 61 72 65 6e 74 28 28 53 74 61  s_GetParent((Sta
0b80: 74 65 2a 29 62 69 6f 2d 3e 70 74 72 29 3b 0a 20  te*)bio->ptr);. 
0b90: 20 20 20 6c 6f 6e 67 20 72 65 74 20 3d 20 31 3b     long ret = 1;
0ba0: 0a 20 20 20 20 69 6e 74 20 2a 69 70 3b 0a 0a 20  .    int *ip;.. 
0bb0: 20 20 20 64 70 72 69 6e 74 66 28 73 74 64 65 72     dprintf(stder
0bc0: 72 2c 22 5c 6e 42 69 6f 43 74 72 6c 28 30 78 25  r,"\nBioCtrl(0x%
0bd0: 78 2c 20 30 78 25 78 2c 20 30 78 25 78 2c 20 30  x, 0x%x, 0x%x, 0
0be0: 78 25 78 29 22 2c 0a 09 20 20 20 20 28 75 6e 73  x%x)",..    (uns
0bf0: 69 67 6e 65 64 20 69 6e 74 29 20 62 69 6f 2c 20  igned int) bio, 
0c00: 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 20 63  (unsigned int) c
0c10: 6d 64 2c 20 28 75 6e 73 69 67 6e 65 64 20 69 6e  md, (unsigned in
0c20: 74 29 20 6e 75 6d 2c 0a 09 20 20 20 20 28 75 6e  t) num,..    (un
0c30: 73 69 67 6e 65 64 20 69 6e 74 29 20 70 74 72 29  signed int) ptr)
0c40: 3b 0a 0a 20 20 20 20 73 77 69 74 63 68 20 28 63  ;..    switch (c
0c50: 6d 64 29 20 7b 0a 20 20 20 20 63 61 73 65 20 42  md) {.    case B
0c60: 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54 3a 0a 09  IO_CTRL_RESET:..
0c70: 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 20 63 61 73  num = 0;.    cas
0c80: 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53 45 45  e BIO_C_FILE_SEE
0c90: 4b 3a 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f  K:.    case BIO_
0ca0: 43 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a 09 72 65  C_FILE_TELL:..re
0cb0: 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b 0a 20  t = 0;..break;. 
0cc0: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c     case BIO_CTRL
0cd0: 5f 49 4e 46 4f 3a 0a 09 72 65 74 20 3d 20 31 3b  _INFO:..ret = 1;
0ce0: 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73  ..break;.    cas
0cf0: 65 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44 3a 0a  e BIO_C_SET_FD:.
0d00: 09 42 69 6f 46 72 65 65 28 62 69 6f 29 3b 0a 09  .BioFree(bio);..
0d10: 2f 2a 20 53 65 74 73 20 53 74 61 74 65 2a 20 2a  /* Sets State* *
0d20: 2f 0a 09 62 69 6f 2d 3e 70 74 72 09 3d 20 2a 28  /..bio->ptr.= *(
0d30: 28 63 68 61 72 20 2a 2a 29 70 74 72 29 3b 0a 09  (char **)ptr);..
0d40: 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 09 3d 20  bio->shutdown.= 
0d50: 28 69 6e 74 29 6e 75 6d 3b 0a 09 62 69 6f 2d 3e  (int)num;..bio->
0d60: 69 6e 69 74 09 3d 20 31 3b 0a 09 62 72 65 61 6b  init.= 1;..break
0d70: 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43  ;.    case BIO_C
0d80: 5f 47 45 54 5f 46 44 3a 0a 09 69 66 20 28 62 69  _GET_FD:..if (bi
0d90: 6f 2d 3e 69 6e 69 74 29 20 7b 0a 09 20 20 20 20  o->init) {..    
0da0: 69 70 20 3d 20 28 69 6e 74 20 2a 29 70 74 72 3b  ip = (int *)ptr;
0db0: 0a 09 20 20 20 20 69 66 20 28 69 70 20 21 3d 20  ..    if (ip != 
0dc0: 4e 55 4c 4c 29 20 7b 0a 09 09 2a 69 70 20 3d 20  NULL) {...*ip = 
0dd0: 62 69 6f 2d 3e 6e 75 6d 3b 0a 09 20 20 20 20 7d  bio->num;..    }
0de0: 0a 09 20 20 20 20 72 65 74 20 3d 20 62 69 6f 2d  ..    ret = bio-
0df0: 3e 6e 75 6d 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a  >num;..} else {.
0e00: 09 20 20 20 20 72 65 74 20 3d 20 2d 31 3b 0a 09  .    ret = -1;..
0e10: 7d 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63 61  }..break;.    ca
0e20: 73 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45 54 5f  se BIO_CTRL_GET_
0e30: 43 4c 4f 53 45 3a 0a 09 72 65 74 20 3d 20 62 69  CLOSE:..ret = bi
0e40: 6f 2d 3e 73 68 75 74 64 6f 77 6e 3b 0a 09 62 72  o->shutdown;..br
0e50: 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49  eak;.    case BI
0e60: 4f 5f 43 54 52 4c 5f 53 45 54 5f 43 4c 4f 53 45  O_CTRL_SET_CLOSE
0e70: 3a 0a 09 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e  :..bio->shutdown
0e80: 20 3d 20 28 69 6e 74 29 6e 75 6d 3b 0a 09 62 72   = (int)num;..br
0e90: 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49  eak;.    case BI
0ea0: 4f 5f 43 54 52 4c 5f 45 4f 46 3a 0a 09 64 70 72  O_CTRL_EOF:..dpr
0eb0: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 42 49  intf(stderr, "BI
0ec0: 4f 5f 43 54 52 4c 5f 45 4f 46 5c 6e 22 29 3b 0a  O_CTRL_EOF\n");.
0ed0: 09 72 65 74 20 3d 20 54 63 6c 5f 45 6f 66 28 63  .ret = Tcl_Eof(c
0ee0: 68 61 6e 29 3b 0a 09 62 72 65 61 6b 3b 0a 20 20  han);..break;.  
0ef0: 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f    case BIO_CTRL_
0f00: 50 45 4e 44 49 4e 47 3a 0a 09 72 65 74 20 3d 20  PENDING:..ret = 
0f10: 28 54 63 6c 5f 49 6e 70 75 74 42 75 66 66 65 72  (Tcl_InputBuffer
0f20: 65 64 28 63 68 61 6e 29 20 3f 20 31 20 3a 20 30  ed(chan) ? 1 : 0
0f30: 29 3b 0a 09 64 70 72 69 6e 74 66 28 73 74 64 65  );..dprintf(stde
0f40: 72 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f 50 45  rr, "BIO_CTRL_PE
0f50: 4e 44 49 4e 47 28 25 64 29 5c 6e 22 2c 20 28 69  NDING(%d)\n", (i
0f60: 6e 74 29 20 72 65 74 29 3b 0a 09 62 72 65 61 6b  nt) ret);..break
0f70: 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43  ;.    case BIO_C
0f80: 54 52 4c 5f 57 50 45 4e 44 49 4e 47 3a 0a 09 72  TRL_WPENDING:..r
0f90: 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b 0a  et = 0;..break;.
0fa0: 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52      case BIO_CTR
0fb0: 4c 5f 44 55 50 3a 0a 09 62 72 65 61 6b 3b 0a 20  L_DUP:..break;. 
0fc0: 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52 4c     case BIO_CTRL
0fd0: 5f 46 4c 55 53 48 3a 0a 09 64 70 72 69 6e 74 66  _FLUSH:..dprintf
0fe0: 28 73 74 64 65 72 72 2c 20 22 42 49 4f 5f 43 54  (stderr, "BIO_CT
0ff0: 52 4c 5f 46 4c 55 53 48 5c 6e 22 29 3b 0a 09 69  RL_FLUSH\n");..i
1000: 66 20 28 63 68 61 6e 6e 65 6c 54 79 70 65 56 65  f (channelTypeVe
1010: 72 73 69 6f 6e 20 3d 3d 20 54 4c 53 5f 43 48 41  rsion == TLS_CHA
1020: 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f 32 29 20  NNEL_VERSION_2) 
1030: 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 28 28 54  {..    ret = ((T
1040: 63 6c 5f 57 72 69 74 65 52 61 77 28 63 68 61 6e  cl_WriteRaw(chan
1050: 2c 20 22 22 2c 20 30 29 20 3e 3d 20 30 29 20 3f  , "", 0) >= 0) ?
1060: 20 31 20 3a 20 2d 31 29 3b 0a 09 7d 20 65 6c 73   1 : -1);..} els
1070: 65 20 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 28  e {..    ret = (
1080: 28 54 63 6c 5f 46 6c 75 73 68 28 63 68 61 6e 29  (Tcl_Flush(chan)
1090: 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 3f 20 31 20   == TCL_OK) ? 1 
10a0: 3a 20 2d 31 29 3b 0a 09 7d 0a 09 62 72 65 61 6b  : -1);..}..break
10b0: 3b 0a 20 20 20 20 64 65 66 61 75 6c 74 3a 0a 09  ;.    default:..
10c0: 72 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b  ret = 0;..break;
10d0: 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72  .    }.    retur
10e0: 6e 28 72 65 74 29 3b 0a 7d 0a 0a 73 74 61 74 69  n(ret);.}..stati
10f0: 63 20 69 6e 74 0a 42 69 6f 4e 65 77 09 28 62 69  c int.BioNew.(bi
1100: 6f 29 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b  o).    BIO *bio;
1110: 0a 7b 0a 20 20 20 20 62 69 6f 2d 3e 69 6e 69 74  .{.    bio->init
1120: 09 3d 20 30 3b 0a 20 20 20 20 62 69 6f 2d 3e 6e  .= 0;.    bio->n
1130: 75 6d 09 3d 20 30 3b 0a 20 20 20 20 62 69 6f 2d  um.= 0;.    bio-
1140: 3e 70 74 72 09 3d 20 4e 55 4c 4c 3b 0a 20 20 20  >ptr.= NULL;.   
1150: 20 62 69 6f 2d 3e 66 6c 61 67 73 09 3d 20 30 3b   bio->flags.= 0;
1160: 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a  ..    return 1;.
1170: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a 42 69  }..static int.Bi
1180: 6f 46 72 65 65 09 28 62 69 6f 29 0a 20 20 20 20  oFree.(bio).    
1190: 42 49 4f 20 2a 62 69 6f 3b 0a 7b 0a 20 20 20 20  BIO *bio;.{.    
11a0: 69 66 20 28 62 69 6f 20 3d 3d 20 4e 55 4c 4c 29  if (bio == NULL)
11b0: 20 7b 0a 09 72 65 74 75 72 6e 20 30 3b 0a 20 20   {..return 0;.  
11c0: 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 62 69 6f    }..    if (bio
11d0: 2d 3e 73 68 75 74 64 6f 77 6e 29 20 7b 0a 09 69  ->shutdown) {..i
11e0: 66 20 28 62 69 6f 2d 3e 69 6e 69 74 29 20 7b 0a  f (bio->init) {.
11f0: 09 20 20 20 20 2f 2a 73 68 75 74 64 6f 77 6e 28  .    /*shutdown(
1200: 62 69 6f 2d 3e 6e 75 6d 2c 20 32 29 20 2a 2f 0a  bio->num, 2) */.
1210: 09 20 20 20 20 2f 2a 63 6c 6f 73 65 73 6f 63 6b  .    /*closesock
1220: 65 74 28 62 69 6f 2d 3e 6e 75 6d 29 20 2a 2f 0a  et(bio->num) */.
1230: 09 7d 0a 09 62 69 6f 2d 3e 69 6e 69 74 09 3d 20  .}..bio->init.= 
1240: 30 3b 0a 09 62 69 6f 2d 3e 66 6c 61 67 73 09 3d  0;..bio->flags.=
1250: 20 30 3b 0a 09 62 69 6f 2d 3e 6e 75 6d 09 3d 20   0;..bio->num.= 
1260: 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74  0;.    }.    ret
1270: 75 72 6e 20 31 3b 0a 7d 0a                       urn 1;.}.