︙ | | | ︙ | |
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
*/
#include "tlsInt.h"
/*
* Forward declarations
*/
static int TlsBlockModeProc (ClientData instanceData, int mode);
static int TlsCloseProc (ClientData instanceData, Tcl_Interp *interp);
static int TlsInputProc (ClientData instanceData, char *buf, int bufSize, int *errorCodePtr);
static int TlsOutputProc (ClientData instanceData, const char *buf, int toWrite, int *errorCodePtr);
static int TlsGetOptionProc (ClientData instanceData, Tcl_Interp *interp, const char *optionName, Tcl_DString *dsPtr);
static void TlsWatchProc (ClientData instanceData, int mask);
static int TlsGetHandleProc (ClientData instanceData, int direction, ClientData *handlePtr);
static int TlsNotifyProc (ClientData instanceData, int mask);
static void TlsChannelHandlerTimer (ClientData clientData);
/*
* TLS Channel Type
*/
static const Tcl_ChannelType tlsChannelType = {
"tls", /* typeName */
TCL_CHANNEL_VERSION_5, /* version */
TlsCloseProc, /* closeProc */
TlsInputProc, /* inputProc */
TlsOutputProc, /* outputProc */
0, /* seekProc */
0, /* setOptionProc */
TlsGetOptionProc, /* getOptionProc */
TlsWatchProc, /* watchProc */
TlsGetHandleProc, /* getHandleProc */
NULL, /* close2Proc */
TlsBlockModeProc, /* blockModeProc */
0, /* flushProc */
TlsNotifyProc /* handlerProc */
};
/*
*-------------------------------------------------------------------
*
* Tls_ChannelType --
|
|
|
>
|
|
|
|
|
|
|
|
|
>
>
>
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
*/
#include "tlsInt.h"
/*
* Forward declarations
*/
static int TlsBlockModeProc (void *instanceData, int mode);
static int TlsCloseProc (void *instanceData, Tcl_Interp *interp);
static int TlsClose2Proc (void *instanceData, Tcl_Interp *interp, int flags);
static int TlsInputProc (void *instanceData, char *buf, int bufSize, int *errorCodePtr);
static int TlsOutputProc (void *instanceData, const char *buf, int toWrite, int *errorCodePtr);
static int TlsGetOptionProc (void *instanceData, Tcl_Interp *interp, const char *optionName, Tcl_DString *dsPtr);
static void TlsWatchProc (void *instanceData, int mask);
static int TlsGetHandleProc (void *instanceData, int direction, void **handlePtr);
static int TlsNotifyProc (void *instanceData, int mask);
static void TlsChannelHandlerTimer (void *clientData);
/*
* TLS Channel Type
*/
static const Tcl_ChannelType tlsChannelType = {
"tls", /* typeName */
TCL_CHANNEL_VERSION_5, /* version */
TlsCloseProc, /* closeProc */
TlsInputProc, /* inputProc */
TlsOutputProc, /* outputProc */
0, /* seekProc */
0, /* setOptionProc */
TlsGetOptionProc, /* getOptionProc */
TlsWatchProc, /* watchProc */
TlsGetHandleProc, /* getHandleProc */
TlsClose2Proc, /* close2Proc */
TlsBlockModeProc, /* blockModeProc */
0, /* flushProc */
TlsNotifyProc, /* handlerProc */
0, /* wideSeekProc */
0, /* threadActionProc */
0 /* truncateProc */
};
/*
*-------------------------------------------------------------------
*
* Tls_ChannelType --
|
︙ | | | ︙ | |
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
* 0 if successful, errno when failed.
*
* Side effects:
* Sets the device into blocking or nonblocking mode.
*
*-------------------------------------------------------------------
*/
static int TlsBlockModeProc(ClientData instanceData, int mode) {
State *statePtr = (State *) instanceData;
if (mode == TCL_MODE_NONBLOCKING) {
statePtr->flags |= TLS_TCL_ASYNC;
} else {
statePtr->flags &= ~(TLS_TCL_ASYNC);
}
|
|
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
* 0 if successful, errno when failed.
*
* Side effects:
* Sets the device into blocking or nonblocking mode.
*
*-------------------------------------------------------------------
*/
static int TlsBlockModeProc(void *instanceData, int mode) {
State *statePtr = (State *) instanceData;
if (mode == TCL_MODE_NONBLOCKING) {
statePtr->flags |= TLS_TCL_ASYNC;
} else {
statePtr->flags &= ~(TLS_TCL_ASYNC);
}
|
︙ | | | ︙ | |
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
* 0 if successful, the value of Tcl_GetErrno() if failed.
*
* Side effects:
* Closes the socket of the channel.
*
*-------------------------------------------------------------------
*/
static int TlsCloseProc(ClientData instanceData, TCL_UNUSED(Tcl_Interp *)) {
State *statePtr = (State *) instanceData;
dprintf("TlsCloseProc(%p)", statePtr);
Tls_Clean(statePtr);
Tcl_EventuallyFree(statePtr, Tls_Free);
dprintf("Returning TCL_OK");
return(TCL_OK);
}
/*
*------------------------------------------------------*
*
* Tls_WaitForConnect --
*
* Sideeffects:
|
|
>
>
>
>
>
>
>
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
* 0 if successful, the value of Tcl_GetErrno() if failed.
*
* Side effects:
* Closes the socket of the channel.
*
*-------------------------------------------------------------------
*/
static int TlsCloseProc(void *instanceData, TCL_UNUSED(Tcl_Interp *)) {
State *statePtr = (State *) instanceData;
dprintf("TlsCloseProc(%p)", statePtr);
Tls_Clean(statePtr);
Tcl_EventuallyFree(statePtr, Tls_Free);
dprintf("Returning TCL_OK");
return(TCL_OK);
}
static int TlsClose2Proc(void *instanceData, Tcl_Interp *interp, int flags) {
if (!(flags&(TCL_CLOSE_READ|TCL_CLOSE_WRITE))) {
return TlsCloseProc(instanceData, interp);
}
return EINVAL;
}
/*
*------------------------------------------------------*
*
* Tls_WaitForConnect --
*
* Sideeffects:
|
︙ | | | ︙ | |
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
*
* Side effects:
* Reads input from the input device of the channel.
*
*-------------------------------------------------------------------
*/
static int TlsInputProc(ClientData instanceData, char *buf, int bufSize, int *errorCodePtr) {
unsigned long backingError;
State *statePtr = (State *) instanceData;
int bytesRead;
int tlsConnect;
int err;
*errorCodePtr = 0;
|
|
|
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
*
* Side effects:
* Reads input from the input device of the channel.
*
*-------------------------------------------------------------------
*/
static int TlsInputProc(void *instanceData, char *buf, int bufSize, int *errorCodePtr) {
unsigned long backingError;
State *statePtr = (State *) instanceData;
int bytesRead;
int tlsConnect;
int err;
*errorCodePtr = 0;
|
︙ | | | ︙ | |
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
*
* Side effects:
* Writes output on the output device of the channel.
*
*-------------------------------------------------------------------
*/
static int TlsOutputProc(ClientData instanceData, const char *buf, int toWrite, int *errorCodePtr) {
unsigned long backingError;
State *statePtr = (State *) instanceData;
int written, err;
int tlsConnect;
*errorCodePtr = 0;
|
|
|
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
*
* Side effects:
* Writes output on the output device of the channel.
*
*-------------------------------------------------------------------
*/
static int TlsOutputProc(void *instanceData, const char *buf, int toWrite, int *errorCodePtr) {
unsigned long backingError;
State *statePtr = (State *) instanceData;
int written, err;
int tlsConnect;
*errorCodePtr = 0;
|
︙ | | | ︙ | |
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
|
*
* Side effects:
* None.
*
*-------------------------------------------------------------------
*/
static int
TlsGetOptionProc(ClientData instanceData, /* Socket state. */
Tcl_Interp *interp, /* For errors - can be NULL. */
const char *optionName, /* Name of the option to
* retrieve the value for, or
* NULL to get all options and
* their values. */
Tcl_DString *dsPtr) /* Where to store the computed value
* initialized by caller. */
|
|
|
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
|
*
* Side effects:
* None.
*
*-------------------------------------------------------------------
*/
static int
TlsGetOptionProc(void *instanceData, /* Socket state. */
Tcl_Interp *interp, /* For errors - can be NULL. */
const char *optionName, /* Name of the option to
* retrieve the value for, or
* NULL to get all options and
* their values. */
Tcl_DString *dsPtr) /* Where to store the computed value
* initialized by caller. */
|
︙ | | | ︙ | |
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
|
* Sets up the notifier so that a future event on the channel
* will be seen by Tcl.
*
*-------------------------------------------------------------------
*/
static void
TlsWatchProc(ClientData instanceData, /* The socket state. */
int mask) /* Events of interest; an OR-ed
* combination of TCL_READABLE,
* TCL_WRITABLE and TCL_EXCEPTION. */
{
Tcl_Channel downChan;
State *statePtr = (State *) instanceData;
|
|
|
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
|
* Sets up the notifier so that a future event on the channel
* will be seen by Tcl.
*
*-------------------------------------------------------------------
*/
static void
TlsWatchProc(void *instanceData, /* The socket state. */
int mask) /* Events of interest; an OR-ed
* combination of TCL_READABLE,
* TCL_WRITABLE and TCL_EXCEPTION. */
{
Tcl_Channel downChan;
State *statePtr = (State *) instanceData;
|
︙ | | | ︙ | |
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
if (mask & TCL_READABLE) {
if (Tcl_InputBuffered(statePtr->self) > 0 || BIO_ctrl_pending(statePtr->bio) > 0) {
/*
* There is interest in readable events and we actually have
* data waiting, so generate a timer to flush that.
*/
dprintf("Creating a new timer since data appears to be waiting");
statePtr->timer = Tcl_CreateTimerHandler(TLS_TCL_DELAY, TlsChannelHandlerTimer, (ClientData) statePtr);
}
}
}
/*
*-------------------------------------------------------------------
*
* TlsGetHandleProc --
*
* Called from Tcl_GetChannelFile to retrieve o/s file handler
* from the SSL socket based channel.
*
* Results:
* The appropriate Tcl_File or NULL if not present.
*
* Side effects:
* None.
*
*-------------------------------------------------------------------
*/
static int TlsGetHandleProc(ClientData instanceData, int direction, ClientData *handlePtr) {
State *statePtr = (State *) instanceData;
return(Tcl_GetChannelHandle(Tls_GetParent(statePtr, TLS_TCL_FASTPATH), direction, handlePtr));
}
/*
*-------------------------------------------------------------------
|
|
|
|
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
|
if (mask & TCL_READABLE) {
if (Tcl_InputBuffered(statePtr->self) > 0 || BIO_ctrl_pending(statePtr->bio) > 0) {
/*
* There is interest in readable events and we actually have
* data waiting, so generate a timer to flush that.
*/
dprintf("Creating a new timer since data appears to be waiting");
statePtr->timer = Tcl_CreateTimerHandler(TLS_TCL_DELAY, TlsChannelHandlerTimer, statePtr);
}
}
}
/*
*-------------------------------------------------------------------
*
* TlsGetHandleProc --
*
* Called from Tcl_GetChannelFile to retrieve o/s file handler
* from the SSL socket based channel.
*
* Results:
* The appropriate Tcl_File or NULL if not present.
*
* Side effects:
* None.
*
*-------------------------------------------------------------------
*/
static int TlsGetHandleProc(void *instanceData, int direction, void **handlePtr) {
State *statePtr = (State *) instanceData;
return(Tcl_GetChannelHandle(Tls_GetParent(statePtr, TLS_TCL_FASTPATH), direction, handlePtr));
}
/*
*-------------------------------------------------------------------
|
︙ | | | ︙ | |
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
|
*
* Side effects:
* May process the incoming event by itself.
*
*-------------------------------------------------------------------
*/
static int TlsNotifyProc(ClientData instanceData, int mask) {
State *statePtr = (State *) instanceData;
int errorCode;
/*
* An event occured in the underlying channel. This
* transformation doesn't process such events thus returns the
* incoming mask unchanged.
|
|
|
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
|
*
* Side effects:
* May process the incoming event by itself.
*
*-------------------------------------------------------------------
*/
static int TlsNotifyProc(void *instanceData, int mask) {
State *statePtr = (State *) instanceData;
int errorCode;
/*
* An event occured in the underlying channel. This
* transformation doesn't process such events thus returns the
* incoming mask unchanged.
|
︙ | | | ︙ | |
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
|
* None.
*
*------------------------------------------------------*
*/
static void
TlsChannelHandler (clientData, mask)
ClientData clientData;
int mask;
{
State *statePtr = (State *) clientData;
dprintf("HANDLER(0x%x)", mask);
Tcl_Preserve( (ClientData)statePtr);
if (mask & TCL_READABLE) {
BIO_set_flags(statePtr->p_bio, BIO_FLAGS_READ);
} else {
BIO_clear_flags(statePtr->p_bio, BIO_FLAGS_READ);
}
|
|
|
|
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
* None.
*
*------------------------------------------------------*
*/
static void
TlsChannelHandler (clientData, mask)
void * clientData;
int mask;
{
State *statePtr = (State *) clientData;
dprintf("HANDLER(0x%x)", mask);
Tcl_Preserve(statePtr);
if (mask & TCL_READABLE) {
BIO_set_flags(statePtr->p_bio, BIO_FLAGS_READ);
} else {
BIO_clear_flags(statePtr->p_bio, BIO_FLAGS_READ);
}
|
︙ | | | ︙ | |
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
|
statePtr->timer = (Tcl_TimerToken)NULL;
}
if ((mask & TCL_READABLE) && Tcl_InputBuffered(statePtr->self) > 0) {
/*
* Data is waiting, flush it out in short time
*/
statePtr->timer = Tcl_CreateTimerHandler(TLS_TCL_DELAY,
TlsChannelHandlerTimer, (ClientData) statePtr);
}
Tcl_Release( (ClientData)statePtr);
}
#endif
/*
*------------------------------------------------------*
*
* TlsChannelHandlerTimer --
|
|
|
|
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
|
statePtr->timer = (Tcl_TimerToken)NULL;
}
if ((mask & TCL_READABLE) && Tcl_InputBuffered(statePtr->self) > 0) {
/*
* Data is waiting, flush it out in short time
*/
statePtr->timer = Tcl_CreateTimerHandler(TLS_TCL_DELAY,
TlsChannelHandlerTimer, statePtr);
}
Tcl_Release(statePtr);
}
#endif
/*
*------------------------------------------------------*
*
* TlsChannelHandlerTimer --
|
︙ | | | ︙ | |
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
|
*
* Result:
* None.
*
*------------------------------------------------------*
*/
static void TlsChannelHandlerTimer(ClientData clientData) {
State *statePtr = (State *) clientData;
int mask = 0;
dprintf("Called");
statePtr->timer = (Tcl_TimerToken) NULL;
|
|
|
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
|
*
* Result:
* None.
*
*------------------------------------------------------*
*/
static void TlsChannelHandlerTimer(void *clientData) {
State *statePtr = (State *) clientData;
int mask = 0;
dprintf("Called");
statePtr->timer = (Tcl_TimerToken) NULL;
|
︙ | | | ︙ | |