Hex Artifact Content

Artifact b90d32218c207f2497a3e05d211d90749128f8d2:


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 2f 2a  e "tlsInt.h"../*
0090: 0a 20 2a 20 46 6f 72 77 61 72 64 20 64 65 63 6c  . * Forward decl
00a0: 61 72 61 74 69 6f 6e 73 0a 20 2a 2f 0a 0a 73 74  arations. */..st
00b0: 61 74 69 63 20 69 6e 74 20 42 69 6f 57 72 69 74  atic int BioWrit
00c0: 65 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28 28  e._ANSI_ARGS_ ((
00d0: 42 49 4f 20 2a 68 2c 20 43 4f 4e 53 54 20 63 68  BIO *h, CONST ch
00e0: 61 72 20 2a 62 75 66 2c 20 69 6e 74 20 6e 75 6d  ar *buf, int num
00f0: 29 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 42  ));.static int B
0100: 69 6f 52 65 61 64 09 5f 41 4e 53 49 5f 41 52 47  ioRead._ANSI_ARG
0110: 53 5f 20 28 28 42 49 4f 20 2a 68 2c 20 63 68 61  S_ ((BIO *h, cha
0120: 72 20 2a 62 75 66 2c 20 69 6e 74 20 6e 75 6d 29  r *buf, int num)
0130: 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 42 69  );.static int Bi
0140: 6f 50 75 74 73 09 5f 41 4e 53 49 5f 41 52 47 53  oPuts._ANSI_ARGS
0150: 5f 20 28 28 42 49 4f 20 2a 68 2c 20 43 4f 4e 53  _ ((BIO *h, CONS
0160: 54 20 63 68 61 72 20 2a 73 74 72 29 29 3b 0a 73  T char *str));.s
0170: 74 61 74 69 63 20 6c 6f 6e 67 20 42 69 6f 43 74  tatic long BioCt
0180: 72 6c 09 5f 41 4e 53 49 5f 41 52 47 53 5f 20 28  rl._ANSI_ARGS_ (
0190: 28 42 49 4f 20 2a 68 2c 20 69 6e 74 20 63 6d 64  (BIO *h, int cmd
01a0: 2c 20 6c 6f 6e 67 20 61 72 67 31 2c 20 76 6f 69  , long arg1, voi
01b0: 64 20 2a 70 74 72 29 29 3b 0a 73 74 61 74 69 63  d *ptr));.static
01c0: 20 69 6e 74 20 42 69 6f 4e 65 77 09 5f 41 4e 53   int BioNew._ANS
01d0: 49 5f 41 52 47 53 5f 20 28 28 42 49 4f 20 2a 68  I_ARGS_ ((BIO *h
01e0: 29 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 42  ));.static int B
01f0: 69 6f 46 72 65 65 09 5f 41 4e 53 49 5f 41 52 47  ioFree._ANSI_ARG
0200: 53 5f 20 28 28 42 49 4f 20 2a 68 29 29 3b 0a 0a  S_ ((BIO *h));..
0210: 0a 73 74 61 74 69 63 20 42 49 4f 5f 4d 45 54 48  .static BIO_METH
0220: 4f 44 20 42 69 6f 4d 65 74 68 6f 64 73 20 3d 20  OD BioMethods = 
0230: 7b 0a 20 20 20 20 42 49 4f 5f 54 59 50 45 5f 54  {.    BIO_TYPE_T
0240: 43 4c 2c 20 22 74 63 6c 22 2c 0a 20 20 20 20 42  CL, "tcl",.    B
0250: 69 6f 57 72 69 74 65 2c 0a 20 20 20 20 42 69 6f  ioWrite,.    Bio
0260: 52 65 61 64 2c 0a 20 20 20 20 42 69 6f 50 75 74  Read,.    BioPut
0270: 73 2c 0a 20 20 20 20 4e 55 4c 4c 2c 09 2f 2a 20  s,.    NULL,./* 
0280: 42 69 6f 47 65 74 73 20 2a 2f 0a 20 20 20 20 42  BioGets */.    B
0290: 69 6f 43 74 72 6c 2c 0a 20 20 20 20 42 69 6f 4e  ioCtrl,.    BioN
02a0: 65 77 2c 0a 20 20 20 20 42 69 6f 46 72 65 65 2c  ew,.    BioFree,
02b0: 0a 7d 3b 0a 0a 42 49 4f 20 2a 0a 42 49 4f 5f 6e  .};..BIO *.BIO_n
02c0: 65 77 5f 74 63 6c 28 73 74 61 74 65 50 74 72 2c  ew_tcl(statePtr,
02d0: 20 66 6c 61 67 73 29 0a 20 20 20 20 53 74 61 74   flags).    Stat
02e0: 65 20 2a 73 74 61 74 65 50 74 72 3b 0a 20 20 20  e *statePtr;.   
02f0: 20 69 6e 74 20 66 6c 61 67 73 3b 0a 7b 0a 20 20   int flags;.{.  
0300: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 0a 20 20 20    BIO *bio;..   
0310: 20 62 69 6f 09 09 09 3d 20 42 49 4f 5f 6e 65 77   bio...= BIO_new
0320: 28 26 42 69 6f 4d 65 74 68 6f 64 73 29 3b 0a 20  (&BioMethods);. 
0330: 20 20 20 62 69 6f 2d 3e 70 74 72 09 09 3d 20 28     bio->ptr..= (
0340: 63 68 61 72 2a 29 73 74 61 74 65 50 74 72 3b 0a  char*)statePtr;.
0350: 20 20 20 20 62 69 6f 2d 3e 69 6e 69 74 09 09 3d      bio->init..=
0360: 20 31 3b 0a 20 20 20 20 62 69 6f 2d 3e 73 68 75   1;.    bio->shu
0370: 74 64 6f 77 6e 09 3d 20 66 6c 61 67 73 3b 0a 0a  tdown.= flags;..
0380: 20 20 20 20 72 65 74 75 72 6e 20 62 69 6f 3b 0a      return bio;.
0390: 7d 0a 0a 42 49 4f 5f 4d 45 54 48 4f 44 20 2a 0a  }..BIO_METHOD *.
03a0: 42 49 4f 5f 73 5f 74 63 6c 28 29 0a 7b 0a 20 20  BIO_s_tcl().{.  
03b0: 20 20 72 65 74 75 72 6e 20 26 42 69 6f 4d 65 74    return &BioMet
03c0: 68 6f 64 73 3b 0a 7d 0a 0a 73 74 61 74 69 63 20  hods;.}..static 
03d0: 69 6e 74 0a 42 69 6f 57 72 69 74 65 20 28 62 69  int.BioWrite (bi
03e0: 6f 2c 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 0a  o, buf, bufLen).
03f0: 20 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20      BIO *bio;.  
0400: 20 20 43 4f 4e 53 54 20 63 68 61 72 20 2a 62 75    CONST char *bu
0410: 66 3b 0a 20 20 20 20 69 6e 74 20 62 75 66 4c 65  f;.    int bufLe
0420: 6e 3b 0a 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61  n;.{.    Tcl_Cha
0430: 6e 6e 65 6c 20 63 68 61 6e 20 3d 20 54 6c 73 5f  nnel chan = Tls_
0440: 47 65 74 50 61 72 65 6e 74 28 28 53 74 61 74 65  GetParent((State
0450: 2a 29 28 62 69 6f 2d 3e 70 74 72 29 29 3b 0a 20  *)(bio->ptr));. 
0460: 20 20 20 69 6e 74 20 72 65 74 3b 0a 0a 20 20 20     int ret;..   
0470: 20 64 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c   dprintf(stderr,
0480: 22 5c 6e 42 69 6f 57 72 69 74 65 28 30 78 25 78  "\nBioWrite(0x%x
0490: 2c 20 3c 62 75 66 3e 2c 20 25 64 29 20 5b 30 78  , <buf>, %d) [0x
04a0: 25 78 5d 22 2c 0a 09 20 20 20 20 28 75 6e 73 69  %x]",..    (unsi
04b0: 67 6e 65 64 20 69 6e 74 29 20 62 69 6f 2c 20 62  gned int) bio, b
04c0: 75 66 4c 65 6e 2c 20 28 75 6e 73 69 67 6e 65 64  ufLen, (unsigned
04d0: 20 69 6e 74 29 20 63 68 61 6e 29 3b 0a 0a 20 20   int) chan);..  
04e0: 20 20 69 66 20 28 63 68 61 6e 6e 65 6c 54 79 70    if (channelTyp
04f0: 65 56 65 72 73 69 6f 6e 20 3d 3d 20 54 4c 53 5f  eVersion == TLS_
0500: 43 48 41 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f  CHANNEL_VERSION_
0510: 32 29 20 7b 0a 09 72 65 74 20 3d 20 54 63 6c 5f  2) {..ret = Tcl_
0520: 57 72 69 74 65 52 61 77 28 63 68 61 6e 2c 20 62  WriteRaw(chan, b
0530: 75 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 20 20 20  uf, bufLen);.   
0540: 20 7d 20 65 6c 73 65 20 7b 0a 09 72 65 74 20 3d   } else {..ret =
0550: 20 54 63 6c 5f 57 72 69 74 65 28 63 68 61 6e 2c   Tcl_Write(chan,
0560: 20 62 75 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 20   buf, bufLen);. 
0570: 20 20 20 7d 0a 0a 20 20 20 20 64 70 72 69 6e 74     }..    dprint
0580: 66 28 73 74 64 65 72 72 2c 22 5c 6e 5b 30 78 25  f(stderr,"\n[0x%
0590: 78 5d 20 42 69 6f 57 72 69 74 65 28 25 64 29 20  x] BioWrite(%d) 
05a0: 2d 3e 20 25 64 20 5b 25 64 2e 25 64 5d 22 2c 0a  -> %d [%d.%d]",.
05b0: 09 20 20 20 20 28 75 6e 73 69 67 6e 65 64 20 69  .    (unsigned i
05c0: 6e 74 29 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e  nt) chan, bufLen
05d0: 2c 20 72 65 74 2c 20 54 63 6c 5f 45 6f 66 28 63  , ret, Tcl_Eof(c
05e0: 68 61 6e 29 2c 20 54 63 6c 5f 47 65 74 45 72 72  han), Tcl_GetErr
05f0: 6e 6f 28 29 29 3b 0a 0a 20 20 20 20 42 49 4f 5f  no());..    BIO_
0600: 63 6c 65 61 72 5f 66 6c 61 67 73 28 62 69 6f 2c  clear_flags(bio,
0610: 20 42 49 4f 5f 46 4c 41 47 53 5f 57 52 49 54 45   BIO_FLAGS_WRITE
0620: 7c 42 49 4f 5f 46 4c 41 47 53 5f 53 48 4f 55 4c  |BIO_FLAGS_SHOUL
0630: 44 5f 52 45 54 52 59 29 3b 0a 0a 20 20 20 20 69  D_RETRY);..    i
0640: 66 20 28 72 65 74 20 3d 3d 20 30 29 20 7b 0a 09  f (ret == 0) {..
0650: 69 66 20 28 21 54 63 6c 5f 45 6f 66 28 63 68 61  if (!Tcl_Eof(cha
0660: 6e 29 29 20 7b 0a 09 20 20 20 20 42 49 4f 5f 73  n)) {..    BIO_s
0670: 65 74 5f 72 65 74 72 79 5f 77 72 69 74 65 28 62  et_retry_write(b
0680: 69 6f 29 3b 0a 09 20 20 20 20 72 65 74 20 3d 20  io);..    ret = 
0690: 2d 31 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20  -1;..}.    }.   
06a0: 20 69 66 20 28 42 49 4f 5f 73 68 6f 75 6c 64 5f   if (BIO_should_
06b0: 72 65 61 64 28 62 69 6f 29 29 20 7b 0a 09 42 49  read(bio)) {..BI
06c0: 4f 5f 73 65 74 5f 72 65 74 72 79 5f 72 65 61 64  O_set_retry_read
06d0: 28 62 69 6f 29 3b 0a 20 20 20 20 7d 0a 20 20 20  (bio);.    }.   
06e0: 20 72 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a   return ret;.}..
06f0: 73 74 61 74 69 63 20 69 6e 74 0a 42 69 6f 52 65  static int.BioRe
0700: 61 64 20 28 62 69 6f 2c 20 62 75 66 2c 20 62 75  ad (bio, buf, bu
0710: 66 4c 65 6e 29 0a 20 20 20 20 42 49 4f 20 2a 62  fLen).    BIO *b
0720: 69 6f 3b 0a 20 20 20 20 63 68 61 72 20 2a 62 75  io;.    char *bu
0730: 66 3b 0a 20 20 20 20 69 6e 74 20 62 75 66 4c 65  f;.    int bufLe
0740: 6e 3b 0a 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61  n;.{.    Tcl_Cha
0750: 6e 6e 65 6c 20 63 68 61 6e 20 3d 20 54 6c 73 5f  nnel chan = Tls_
0760: 47 65 74 50 61 72 65 6e 74 28 28 53 74 61 74 65  GetParent((State
0770: 2a 29 62 69 6f 2d 3e 70 74 72 29 3b 0a 20 20 20  *)bio->ptr);.   
0780: 20 69 6e 74 20 72 65 74 20 3d 20 30 3b 0a 0a 20   int ret = 0;.. 
0790: 20 20 20 64 70 72 69 6e 74 66 28 73 74 64 65 72     dprintf(stder
07a0: 72 2c 22 5c 6e 42 69 6f 52 65 61 64 28 30 78 25  r,"\nBioRead(0x%
07b0: 78 2c 20 3c 62 75 66 3e 2c 20 25 64 29 20 5b 30  x, <buf>, %d) [0
07c0: 78 25 78 5d 22 2c 0a 09 20 20 20 20 28 75 6e 73  x%x]",..    (uns
07d0: 69 67 6e 65 64 20 69 6e 74 29 20 62 69 6f 2c 20  igned int) bio, 
07e0: 62 75 66 4c 65 6e 2c 20 28 75 6e 73 69 67 6e 65  bufLen, (unsigne
07f0: 64 20 69 6e 74 29 20 63 68 61 6e 29 3b 0a 0a 20  d int) chan);.. 
0800: 20 20 20 69 66 20 28 62 75 66 20 3d 3d 20 4e 55     if (buf == NU
0810: 4c 4c 29 20 72 65 74 75 72 6e 20 30 3b 0a 0a 20  LL) return 0;.. 
0820: 20 20 20 69 66 20 28 63 68 61 6e 6e 65 6c 54 79     if (channelTy
0830: 70 65 56 65 72 73 69 6f 6e 20 3d 3d 20 54 4c 53  peVersion == TLS
0840: 5f 43 48 41 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e  _CHANNEL_VERSION
0850: 5f 32 29 20 7b 0a 09 72 65 74 20 3d 20 54 63 6c  _2) {..ret = Tcl
0860: 5f 52 65 61 64 52 61 77 28 63 68 61 6e 2c 20 62  _ReadRaw(chan, b
0870: 75 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 20 20 20  uf, bufLen);.   
0880: 20 7d 20 65 6c 73 65 20 7b 0a 09 72 65 74 20 3d   } else {..ret =
0890: 20 54 63 6c 5f 52 65 61 64 28 63 68 61 6e 2c 20   Tcl_Read(chan, 
08a0: 62 75 66 2c 20 62 75 66 4c 65 6e 29 3b 0a 20 20  buf, bufLen);.  
08b0: 20 20 7d 0a 0a 20 20 20 20 64 70 72 69 6e 74 66    }..    dprintf
08c0: 28 73 74 64 65 72 72 2c 22 5c 6e 5b 30 78 25 78  (stderr,"\n[0x%x
08d0: 5d 20 42 69 6f 52 65 61 64 28 25 64 29 20 2d 3e  ] BioRead(%d) ->
08e0: 20 25 64 20 5b 25 64 2e 25 64 5d 22 2c 0a 09 20   %d [%d.%d]",.. 
08f0: 20 20 20 28 75 6e 73 69 67 6e 65 64 20 69 6e 74     (unsigned int
0900: 29 20 63 68 61 6e 2c 20 62 75 66 4c 65 6e 2c 20  ) chan, bufLen, 
0910: 72 65 74 2c 20 54 63 6c 5f 45 6f 66 28 63 68 61  ret, Tcl_Eof(cha
0920: 6e 29 2c 20 54 63 6c 5f 47 65 74 45 72 72 6e 6f  n), Tcl_GetErrno
0930: 28 29 29 3b 0a 0a 20 20 20 20 42 49 4f 5f 63 6c  ());..    BIO_cl
0940: 65 61 72 5f 66 6c 61 67 73 28 62 69 6f 2c 20 42  ear_flags(bio, B
0950: 49 4f 5f 46 4c 41 47 53 5f 52 45 41 44 7c 42 49  IO_FLAGS_READ|BI
0960: 4f 5f 46 4c 41 47 53 5f 53 48 4f 55 4c 44 5f 52  O_FLAGS_SHOULD_R
0970: 45 54 52 59 29 3b 0a 0a 20 20 20 20 69 66 20 28  ETRY);..    if (
0980: 72 65 74 20 3d 3d 20 30 29 20 7b 0a 09 69 66 20  ret == 0) {..if 
0990: 28 21 54 63 6c 5f 45 6f 66 28 63 68 61 6e 29 29  (!Tcl_Eof(chan))
09a0: 20 7b 0a 09 20 20 20 20 42 49 4f 5f 73 65 74 5f   {..    BIO_set_
09b0: 72 65 74 72 79 5f 72 65 61 64 28 62 69 6f 29 3b  retry_read(bio);
09c0: 0a 09 20 20 20 20 72 65 74 20 3d 20 2d 31 3b 0a  ..    ret = -1;.
09d0: 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 20  .}.    }.    if 
09e0: 28 42 49 4f 5f 73 68 6f 75 6c 64 5f 77 72 69 74  (BIO_should_writ
09f0: 65 28 62 69 6f 29 29 20 7b 0a 09 42 49 4f 5f 73  e(bio)) {..BIO_s
0a00: 65 74 5f 72 65 74 72 79 5f 77 72 69 74 65 28 62  et_retry_write(b
0a10: 69 6f 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72  io);.    }.    r
0a20: 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 73 74  eturn ret;.}..st
0a30: 61 74 69 63 20 69 6e 74 0a 42 69 6f 50 75 74 73  atic int.BioPuts
0a40: 09 28 62 69 6f 2c 20 73 74 72 29 0a 20 20 20 20  .(bio, str).    
0a50: 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20 20 43 4f  BIO *bio;.    CO
0a60: 4e 53 54 20 63 68 61 72 20 2a 73 74 72 3b 0a 7b  NST char *str;.{
0a70: 0a 20 20 20 20 72 65 74 75 72 6e 20 42 69 6f 57  .    return BioW
0a80: 72 69 74 65 28 62 69 6f 2c 20 73 74 72 2c 20 28  rite(bio, str, (
0a90: 69 6e 74 29 20 73 74 72 6c 65 6e 28 73 74 72 29  int) strlen(str)
0aa0: 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 6c 6f 6e  );.}..static lon
0ab0: 67 0a 42 69 6f 43 74 72 6c 09 28 62 69 6f 2c 20  g.BioCtrl.(bio, 
0ac0: 63 6d 64 2c 20 6e 75 6d 2c 20 70 74 72 29 0a 20  cmd, num, ptr). 
0ad0: 20 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 20 20 20     BIO *bio;.   
0ae0: 20 69 6e 74 20 63 6d 64 3b 0a 20 20 20 20 6c 6f   int cmd;.    lo
0af0: 6e 67 20 6e 75 6d 3b 0a 20 20 20 20 76 6f 69 64  ng num;.    void
0b00: 20 2a 70 74 72 3b 0a 7b 0a 20 20 20 20 54 63 6c   *ptr;.{.    Tcl
0b10: 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e 20 3d 20  _Channel chan = 
0b20: 54 6c 73 5f 47 65 74 50 61 72 65 6e 74 28 28 53  Tls_GetParent((S
0b30: 74 61 74 65 2a 29 62 69 6f 2d 3e 70 74 72 29 3b  tate*)bio->ptr);
0b40: 0a 20 20 20 20 6c 6f 6e 67 20 72 65 74 20 3d 20  .    long ret = 
0b50: 31 3b 0a 20 20 20 20 69 6e 74 20 2a 69 70 3b 0a  1;.    int *ip;.
0b60: 0a 20 20 20 20 64 70 72 69 6e 74 66 28 73 74 64  .    dprintf(std
0b70: 65 72 72 2c 22 5c 6e 42 69 6f 43 74 72 6c 28 30  err,"\nBioCtrl(0
0b80: 78 25 78 2c 20 30 78 25 78 2c 20 30 78 25 78 2c  x%x, 0x%x, 0x%x,
0b90: 20 30 78 25 78 29 22 2c 0a 09 20 20 20 20 28 75   0x%x)",..    (u
0ba0: 6e 73 69 67 6e 65 64 20 69 6e 74 29 20 62 69 6f  nsigned int) bio
0bb0: 2c 20 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 29  , (unsigned int)
0bc0: 20 63 6d 64 2c 20 28 75 6e 73 69 67 6e 65 64 20   cmd, (unsigned 
0bd0: 69 6e 74 29 20 6e 75 6d 2c 0a 09 20 20 20 20 28  int) num,..    (
0be0: 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 20 70 74  unsigned int) pt
0bf0: 72 29 3b 0a 0a 20 20 20 20 73 77 69 74 63 68 20  r);..    switch 
0c00: 28 63 6d 64 29 20 7b 0a 20 20 20 20 63 61 73 65  (cmd) {.    case
0c10: 20 42 49 4f 5f 43 54 52 4c 5f 52 45 53 45 54 3a   BIO_CTRL_RESET:
0c20: 0a 09 6e 75 6d 20 3d 20 30 3b 0a 20 20 20 20 63  ..num = 0;.    c
0c30: 61 73 65 20 42 49 4f 5f 43 5f 46 49 4c 45 5f 53  ase BIO_C_FILE_S
0c40: 45 45 4b 3a 0a 20 20 20 20 63 61 73 65 20 42 49  EEK:.    case BI
0c50: 4f 5f 43 5f 46 49 4c 45 5f 54 45 4c 4c 3a 0a 09  O_C_FILE_TELL:..
0c60: 72 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b 3b  ret = 0;..break;
0c70: 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54  .    case BIO_CT
0c80: 52 4c 5f 49 4e 46 4f 3a 0a 09 72 65 74 20 3d 20  RL_INFO:..ret = 
0c90: 31 3b 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20 63  1;..break;.    c
0ca0: 61 73 65 20 42 49 4f 5f 43 5f 53 45 54 5f 46 44  ase BIO_C_SET_FD
0cb0: 3a 0a 09 42 69 6f 46 72 65 65 28 62 69 6f 29 3b  :..BioFree(bio);
0cc0: 0a 09 2f 2a 20 53 65 74 73 20 53 74 61 74 65 2a  ../* Sets State*
0cd0: 20 2a 2f 0a 09 62 69 6f 2d 3e 70 74 72 09 3d 20   */..bio->ptr.= 
0ce0: 2a 28 28 63 68 61 72 20 2a 2a 29 70 74 72 29 3b  *((char **)ptr);
0cf0: 0a 09 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 09  ..bio->shutdown.
0d00: 3d 20 28 69 6e 74 29 6e 75 6d 3b 0a 09 62 69 6f  = (int)num;..bio
0d10: 2d 3e 69 6e 69 74 09 3d 20 31 3b 0a 09 62 72 65  ->init.= 1;..bre
0d20: 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f  ak;.    case BIO
0d30: 5f 43 5f 47 45 54 5f 46 44 3a 0a 09 69 66 20 28  _C_GET_FD:..if (
0d40: 62 69 6f 2d 3e 69 6e 69 74 29 20 7b 0a 09 20 20  bio->init) {..  
0d50: 20 20 69 70 20 3d 20 28 69 6e 74 20 2a 29 70 74    ip = (int *)pt
0d60: 72 3b 0a 09 20 20 20 20 69 66 20 28 69 70 20 21  r;..    if (ip !
0d70: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 2a 69 70 20  = NULL) {...*ip 
0d80: 3d 20 62 69 6f 2d 3e 6e 75 6d 3b 0a 09 20 20 20  = bio->num;..   
0d90: 20 7d 0a 09 20 20 20 20 72 65 74 20 3d 20 62 69   }..    ret = bi
0da0: 6f 2d 3e 6e 75 6d 3b 0a 09 7d 20 65 6c 73 65 20  o->num;..} else 
0db0: 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 2d 31 3b  {..    ret = -1;
0dc0: 0a 09 7d 0a 09 62 72 65 61 6b 3b 0a 20 20 20 20  ..}..break;.    
0dd0: 63 61 73 65 20 42 49 4f 5f 43 54 52 4c 5f 47 45  case BIO_CTRL_GE
0de0: 54 5f 43 4c 4f 53 45 3a 0a 09 72 65 74 20 3d 20  T_CLOSE:..ret = 
0df0: 62 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 3b 0a 09  bio->shutdown;..
0e00: 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20  break;.    case 
0e10: 42 49 4f 5f 43 54 52 4c 5f 53 45 54 5f 43 4c 4f  BIO_CTRL_SET_CLO
0e20: 53 45 3a 0a 09 62 69 6f 2d 3e 73 68 75 74 64 6f  SE:..bio->shutdo
0e30: 77 6e 20 3d 20 28 69 6e 74 29 6e 75 6d 3b 0a 09  wn = (int)num;..
0e40: 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20  break;.    case 
0e50: 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 3a 0a 09 64  BIO_CTRL_EOF:..d
0e60: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22  printf(stderr, "
0e70: 42 49 4f 5f 43 54 52 4c 5f 45 4f 46 5c 6e 22 29  BIO_CTRL_EOF\n")
0e80: 3b 0a 09 72 65 74 20 3d 20 54 63 6c 5f 45 6f 66  ;..ret = Tcl_Eof
0e90: 28 63 68 61 6e 29 3b 0a 09 62 72 65 61 6b 3b 0a  (chan);..break;.
0ea0: 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54 52      case BIO_CTR
0eb0: 4c 5f 50 45 4e 44 49 4e 47 3a 0a 09 72 65 74 20  L_PENDING:..ret 
0ec0: 3d 20 28 54 63 6c 5f 49 6e 70 75 74 42 75 66 66  = (Tcl_InputBuff
0ed0: 65 72 65 64 28 63 68 61 6e 29 20 3f 20 31 20 3a  ered(chan) ? 1 :
0ee0: 20 30 29 3b 0a 09 64 70 72 69 6e 74 66 28 73 74   0);..dprintf(st
0ef0: 64 65 72 72 2c 20 22 42 49 4f 5f 43 54 52 4c 5f  derr, "BIO_CTRL_
0f00: 50 45 4e 44 49 4e 47 28 25 64 29 5c 6e 22 2c 20  PENDING(%d)\n", 
0f10: 28 69 6e 74 29 20 72 65 74 29 3b 0a 09 62 72 65  (int) ret);..bre
0f20: 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f  ak;.    case BIO
0f30: 5f 43 54 52 4c 5f 57 50 45 4e 44 49 4e 47 3a 0a  _CTRL_WPENDING:.
0f40: 09 72 65 74 20 3d 20 30 3b 0a 09 62 72 65 61 6b  .ret = 0;..break
0f50: 3b 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43  ;.    case BIO_C
0f60: 54 52 4c 5f 44 55 50 3a 0a 09 62 72 65 61 6b 3b  TRL_DUP:..break;
0f70: 0a 20 20 20 20 63 61 73 65 20 42 49 4f 5f 43 54  .    case BIO_CT
0f80: 52 4c 5f 46 4c 55 53 48 3a 0a 09 64 70 72 69 6e  RL_FLUSH:..dprin
0f90: 74 66 28 73 74 64 65 72 72 2c 20 22 42 49 4f 5f  tf(stderr, "BIO_
0fa0: 43 54 52 4c 5f 46 4c 55 53 48 5c 6e 22 29 3b 0a  CTRL_FLUSH\n");.
0fb0: 09 69 66 20 28 63 68 61 6e 6e 65 6c 54 79 70 65  .if (channelType
0fc0: 56 65 72 73 69 6f 6e 20 3d 3d 20 54 4c 53 5f 43  Version == TLS_C
0fd0: 48 41 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f 32  HANNEL_VERSION_2
0fe0: 29 20 7b 0a 09 20 20 20 20 72 65 74 20 3d 20 28  ) {..    ret = (
0ff0: 28 54 63 6c 5f 57 72 69 74 65 52 61 77 28 63 68  (Tcl_WriteRaw(ch
1000: 61 6e 2c 20 22 22 2c 20 30 29 20 3e 3d 20 30 29  an, "", 0) >= 0)
1010: 20 3f 20 31 20 3a 20 2d 31 29 3b 0a 09 7d 20 65   ? 1 : -1);..} e
1020: 6c 73 65 20 7b 0a 09 20 20 20 20 72 65 74 20 3d  lse {..    ret =
1030: 20 28 28 54 63 6c 5f 46 6c 75 73 68 28 63 68 61   ((Tcl_Flush(cha
1040: 6e 29 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 3f 20  n) == TCL_OK) ? 
1050: 31 20 3a 20 2d 31 29 3b 0a 09 7d 0a 09 62 72 65  1 : -1);..}..bre
1060: 61 6b 3b 0a 20 20 20 20 64 65 66 61 75 6c 74 3a  ak;.    default:
1070: 0a 09 72 65 74 20 3d 20 30 3b 0a 09 62 72 65 61  ..ret = 0;..brea
1080: 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74  k;.    }.    ret
1090: 75 72 6e 28 72 65 74 29 3b 0a 7d 0a 0a 73 74 61  urn(ret);.}..sta
10a0: 74 69 63 20 69 6e 74 0a 42 69 6f 4e 65 77 09 28  tic int.BioNew.(
10b0: 62 69 6f 29 0a 20 20 20 20 42 49 4f 20 2a 62 69  bio).    BIO *bi
10c0: 6f 3b 0a 7b 0a 20 20 20 20 62 69 6f 2d 3e 69 6e  o;.{.    bio->in
10d0: 69 74 09 3d 20 30 3b 0a 20 20 20 20 62 69 6f 2d  it.= 0;.    bio-
10e0: 3e 6e 75 6d 09 3d 20 30 3b 0a 20 20 20 20 62 69  >num.= 0;.    bi
10f0: 6f 2d 3e 70 74 72 09 3d 20 4e 55 4c 4c 3b 0a 20  o->ptr.= NULL;. 
1100: 20 20 20 62 69 6f 2d 3e 66 6c 61 67 73 09 3d 20     bio->flags.= 
1110: 30 3b 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 31  0;..    return 1
1120: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a  ;.}..static int.
1130: 42 69 6f 46 72 65 65 09 28 62 69 6f 29 0a 20 20  BioFree.(bio).  
1140: 20 20 42 49 4f 20 2a 62 69 6f 3b 0a 7b 0a 20 20    BIO *bio;.{.  
1150: 20 20 69 66 20 28 62 69 6f 20 3d 3d 20 4e 55 4c    if (bio == NUL
1160: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 30 3b 0a  L) {..return 0;.
1170: 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 62      }..    if (b
1180: 69 6f 2d 3e 73 68 75 74 64 6f 77 6e 29 20 7b 0a  io->shutdown) {.
1190: 09 69 66 20 28 62 69 6f 2d 3e 69 6e 69 74 29 20  .if (bio->init) 
11a0: 7b 0a 09 20 20 20 20 2f 2a 73 68 75 74 64 6f 77  {..    /*shutdow
11b0: 6e 28 62 69 6f 2d 3e 6e 75 6d 2c 20 32 29 20 2a  n(bio->num, 2) *
11c0: 2f 0a 09 20 20 20 20 2f 2a 63 6c 6f 73 65 73 6f  /..    /*closeso
11d0: 63 6b 65 74 28 62 69 6f 2d 3e 6e 75 6d 29 20 2a  cket(bio->num) *
11e0: 2f 0a 09 7d 0a 09 62 69 6f 2d 3e 69 6e 69 74 09  /..}..bio->init.
11f0: 3d 20 30 3b 0a 09 62 69 6f 2d 3e 66 6c 61 67 73  = 0;..bio->flags
1200: 09 3d 20 30 3b 0a 09 62 69 6f 2d 3e 6e 75 6d 09  .= 0;..bio->num.
1210: 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72  = 0;.    }.    r
1220: 65 74 75 72 6e 20 31 3b 0a 7d 0a                 eturn 1;.}.