Diff
Bounty program for improvements to Tcl and certain Tcl packages.

Differences From Artifact [574ea1f12d]:

To Artifact [caad573382]:


1
2
3
4
5
6
7
8
9
10
11
/*
 * Copyright (C) 1997-1999 Matt Newman <[email protected]>
 *
 * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tls.c,v 1.4 2000/06/05 18:09:53 welch Exp $
 *
 * TLS (aka SSL) Channel - can be layered on any bi-directional
 * Tcl_Channel (Note: Requires Trf Core Patch)
 *
 * This was built (almost) from scratch based upon observation of
 * OpenSSL 0.9.2B
 *


|







1
2
3
4
5
6
7
8
9
10
11
/*
 * Copyright (C) 1997-1999 Matt Newman <[email protected]>
 *
 * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tls.c,v 1.5 2000/06/06 01:04:35 stanton Exp $
 *
 * TLS (aka SSL) Channel - can be layered on any bi-directional
 * Tcl_Channel (Note: Requires Trf Core Patch)
 *
 * This was built (almost) from scratch based upon observation of
 * OpenSSL 0.9.2B
 *
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
			       (TCL_READABLE | TCL_WRITABLE), statePtr->parent);
#else
    statePtr->self = chan;
    Tcl_StackChannel( interp, Tls_ChannelType(), (ClientData) statePtr,
			       (TCL_READABLE | TCL_WRITABLE), chan);
#endif
    if (statePtr->self == (Tcl_Channel) NULL) {
	Tls_Free(statePtr);
/*        Tcl_EventuallyFree( (ClientData)statePtr, Tls_Free); */
        return TCL_ERROR;
    }

    /* allocate script */
    if (script) {
	char * tmp = Tcl_GetStringFromObj(script, NULL);
	if (tmp && *tmp) {






|
<







724
725
726
727
728
729
730
731

732
733
734
735
736
737
738
			       (TCL_READABLE | TCL_WRITABLE), statePtr->parent);
#else
    statePtr->self = chan;
    Tcl_StackChannel( interp, Tls_ChannelType(), (ClientData) statePtr,
			       (TCL_READABLE | TCL_WRITABLE), chan);
#endif
    if (statePtr->self == (Tcl_Channel) NULL) {
	Tls_Free((char *) statePtr);

        return TCL_ERROR;
    }

    /* allocate script */
    if (script) {
	char * tmp = Tcl_GetStringFromObj(script, NULL);
	if (tmp && *tmp) {
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
    statePtr->ssl = SSL_new(statePtr->ctx);
    if (!statePtr->ssl) {
        /* SSL library error */
        Tcl_AppendResult(interp,
                         "couldn't construct ssl session: ", REASON(),
                         (char *) NULL);
	Tls_Free(statePtr);
/*        Tcl_EventuallyFree( (ClientData)statePtr, Tls_Free); */
        return TCL_ERROR;
    }

    /*
     * SSL Callbacks
     */







|
<







752
753
754
755
756
757
758
759

760
761
762
763
764
765
766
    statePtr->ssl = SSL_new(statePtr->ctx);
    if (!statePtr->ssl) {
        /* SSL library error */
        Tcl_AppendResult(interp,
                         "couldn't construct ssl session: ", REASON(),
                         (char *) NULL);
	Tls_Free((char *) statePtr);

        return TCL_ERROR;
    }

    /*
     * SSL Callbacks
     */

1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
 *-------------------------------------------------------------------
 */
void
Tls_Free( char *blockPtr )
{
    State *statePtr = (State *)blockPtr;

    Tls_Clean(blockPtr);
    Tcl_Free((char *)statePtr);
}

/*
 *-------------------------------------------------------------------
 *
 * Tls_Clean --
 *






|
|







1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
 *-------------------------------------------------------------------
 */
void
Tls_Free( char *blockPtr )
{
    State *statePtr = (State *)blockPtr;

    Tls_Clean(statePtr);
    Tcl_Free(blockPtr);
}

/*
 *-------------------------------------------------------------------
 *
 * Tls_Clean --
 *
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
 *
 * Side effects:
 *	Frees all the state
 *
 *-------------------------------------------------------------------
 */
void
Tls_Clean( char *blockPtr )
{
    State *statePtr = (State *)blockPtr;

    /* we're assuming here that we're single-threaded */
    if (statePtr->ssl) {
	SSL_shutdown(statePtr->ssl);
	SSL_free(statePtr->ssl);
	statePtr->ssl = NULL;
    }
    if (statePtr->callback) {
	Tcl_DecrRefCount(statePtr->callback);
	statePtr->callback = NULL;
    }

    if (statePtr->timer != (Tcl_TimerToken)NULL) {
	Tcl_DeleteTimerHandler (statePtr->timer);
	statePtr->timer = NULL;
    }

}

/*
 *-------------------------------------------------------------------
 *
 * Tls_Init --
 *






<
<
|
|















<







1050
1051
1052
1053
1054
1055
1056


1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076
1077
1078
1079
1080
 *
 * Side effects:
 *	Frees all the state
 *
 *-------------------------------------------------------------------
 */
void


Tls_Clean(State *statePtr)
{
    /* we're assuming here that we're single-threaded */
    if (statePtr->ssl) {
	SSL_shutdown(statePtr->ssl);
	SSL_free(statePtr->ssl);
	statePtr->ssl = NULL;
    }
    if (statePtr->callback) {
	Tcl_DecrRefCount(statePtr->callback);
	statePtr->callback = NULL;
    }

    if (statePtr->timer != (Tcl_TimerToken)NULL) {
	Tcl_DeleteTimerHandler (statePtr->timer);
	statePtr->timer = NULL;
    }

}

/*
 *-------------------------------------------------------------------
 *
 * Tls_Init --
 *