@@ -21,11 +21,11 @@ #include /* * Forward declarations */ -static void TlsChannelHandlerTimer(ClientData clientData); +static void TlsChannelHandlerTimer(void *clientData); /* *------------------------------------------------------------------- * * TlsBlockModeProc -- @@ -39,11 +39,11 @@ * Side effects: * Sets the device into blocking or nonblocking mode. * *------------------------------------------------------------------- */ -static int TlsBlockModeProc(ClientData instanceData, int mode) { +static int TlsBlockModeProc(void *instanceData, int mode) { State *statePtr = (State *) instanceData; if (mode == TCL_MODE_NONBLOCKING) { statePtr->flags |= TLS_TCL_ASYNC; } else { @@ -69,29 +69,31 @@ * Side effects: * Closes the socket of the channel. * *------------------------------------------------------------------- */ -static int TlsCloseProc(ClientData instanceData, Tcl_Interp *interp) { - State *statePtr = (State *) instanceData; +static int TlsCloseProc( + void *instanceData, + TCL_UNUSED(Tcl_Interp *)) +{ + State *statePtr = (State *)instanceData; - dprintf("TlsCloseProc(%p)", (void *) statePtr); + dprintf("TlsCloseProc(%p)", statePtr); Tls_Clean(statePtr); - Tcl_EventuallyFree((ClientData)statePtr, Tls_Free); - return(0); + Tcl_EventuallyFree(statePtr, Tls_Free); + return TCL_OK; } -static int TlsClose2Proc(ClientData instanceData, /* The socket state. */ +static int TlsClose2Proc( + void *instanceData, /* The socket state. */ Tcl_Interp *interp, /* For errors - can be NULL. */ int flags) /* Flags to close read and/or write side of channel */ { - State *statePtr = (State *) instanceData; + dprintf("TlsClose2Proc(%p)", instanceData); - dprintf("TlsClose2Proc(%p)", (void *) statePtr); - - if ((flags & (TCL_CLOSE_READ|TCL_CLOSE_WRITE)) == 0) { + if (!(flags & (TCL_CLOSE_READ|TCL_CLOSE_WRITE))) { return TlsCloseProc(instanceData, interp); } return EINVAL; } @@ -112,11 +114,11 @@ unsigned long backingError; int err, rc; int bioShouldRetry; *errorCodePtr = 0; - dprintf("WaitForConnect(%p)", (void *) statePtr); + dprintf("WaitForConnect(%p)", statePtr); dprintFlags(statePtr); if (!(statePtr->flags & TLS_TCL_INIT)) { dprintf("Tls_WaitForConnect called on already initialized channel -- returning with immediate success"); return(0); @@ -143,11 +145,10 @@ /* Not initialized yet! Also calls SSL_do_handshake. */ if (statePtr->flags & TLS_TCL_SERVER) { dprintf("Calling SSL_accept()"); err = SSL_accept(statePtr->ssl); - } else { dprintf("Calling SSL_connect()"); err = SSL_connect(statePtr->ssl); } @@ -278,11 +279,11 @@ dprintf("Removing the \"TLS_TCL_INIT\" flag since we have completed the handshake"); statePtr->flags &= ~TLS_TCL_INIT; dprintf("Returning in success"); *errorCodePtr = 0; - return(0); + return 0; } /* *------------------------------------------------------------------- * @@ -298,11 +299,17 @@ * Side effects: * Reads input from the input device of the channel. * *------------------------------------------------------------------- */ -static int TlsInputProc(ClientData instanceData, char *buf, int bufSize, int *errorCodePtr) { + +static int TlsInputProc( + void *instanceData, + char *buf, + int bufSize, + int *errorCodePtr) +{ unsigned long backingError; State *statePtr = (State *) instanceData; int bytesRead; int tlsConnect; int err; @@ -434,11 +441,11 @@ Tls_Error(statePtr, "Unknown error"); break; } dprintf("Input(%d) -> %d [%d]", bufSize, bytesRead, *errorCodePtr); - return(bytesRead); + return bytesRead; } /* *------------------------------------------------------------------- * @@ -454,11 +461,17 @@ * Side effects: * Writes output on the output device of the channel. * *------------------------------------------------------------------- */ -static int TlsOutputProc(ClientData instanceData, const char *buf, int toWrite, int *errorCodePtr) { + +static int TlsOutputProc( + void *instanceData, + const char *buf, + int toWrite, + int *errorCodePtr) +{ unsigned long backingError; State *statePtr = (State *) instanceData; int written, err; int tlsConnect; @@ -523,42 +536,36 @@ written = BIO_write(statePtr->bio, buf, toWrite); dprintf("BIO_write(%p, %d) -> [%d]", (void *) statePtr, toWrite, written); err = SSL_get_error(statePtr->ssl, written); backingError = ERR_get_error(); - switch (err) { case SSL_ERROR_NONE: if (written < 0) { written = 0; } break; - case SSL_ERROR_WANT_WRITE: dprintf("Got SSL_ERROR_WANT_WRITE, mapping it to EAGAIN"); *errorCodePtr = EAGAIN; written = -1; Tls_Error(statePtr, "SSL_ERROR_WANT_WRITE"); break; - case SSL_ERROR_WANT_READ: dprintf(" write R BLOCK"); Tls_Error(statePtr, "SSL_ERROR_WANT_READ"); break; - case SSL_ERROR_WANT_X509_LOOKUP: dprintf(" write X BLOCK"); Tls_Error(statePtr, "SSL_ERROR_WANT_X509_LOOKUP"); break; - case SSL_ERROR_ZERO_RETURN: dprintf(" closed"); written = 0; *errorCodePtr = 0; Tls_Error(statePtr, "Peer has closed the connection for writing by sending the close_notify alert"); break; - case SSL_ERROR_SYSCALL: /* Some non-recoverable, fatal I/O error occurred */ if (backingError == 0 && written == 0) { dprintf("EOF reached") @@ -591,11 +598,10 @@ Tls_Error(statePtr, "Unknown SSL error"); } *errorCodePtr = ECONNABORTED; written = -1; break; - default: dprintf("unknown error: %d", err); Tls_Error(statePtr, "Unknown error"); break; } @@ -619,11 +625,11 @@ * Updates channel option to new value. * *------------------------------------------------------------------- */ static int -TlsSetOptionProc(ClientData instanceData, /* Socket state. */ +TlsSetOptionProc(void *instanceData, /* Socket state. */ Tcl_Interp *interp, /* For errors - can be NULL. */ const char *optionName, /* Name of the option to set the value for, or * NULL to get all options and their values. */ const char *optionValue) /* Value for option. */ { @@ -664,11 +670,12 @@ * None. * *------------------------------------------------------------------- */ static int -TlsGetOptionProc(ClientData instanceData, /* Socket state. */ +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 *optionValue) /* Where to store the computed value initialized by caller. */ { @@ -706,12 +713,14 @@ * 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. */ +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; @@ -768,11 +777,11 @@ /* * 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); + statePtr->timer = Tcl_CreateTimerHandler(TLS_TCL_DELAY, TlsChannelHandlerTimer, statePtr); } } /* *------------------------------------------------------------------- @@ -788,15 +797,16 @@ * Side effects: * None. * *------------------------------------------------------------------- */ -static int TlsGetHandleProc(ClientData instanceData, /* Socket state. */ +static int TlsGetHandleProc( + void *instanceData, /* Socket state. */ int direction, /* TCL_READABLE or TCL_WRITABLE */ - ClientData *handlePtr) /* Handle associated with the channel */ + void **handlePtr) /* Handle associated with the channel */ { - State *statePtr = (State *) instanceData; + State *statePtr = (State *)instanceData; return(Tcl_GetChannelHandle(Tls_GetParent(statePtr, TLS_TCL_FASTPATH), direction, handlePtr)); } /* @@ -813,15 +823,17 @@ * Side effects: * May process the incoming event by itself. * *------------------------------------------------------------------- */ -static int TlsNotifyProc(ClientData instanceData, /* Socket state. */ + +static int TlsNotifyProc( + void *instanceData, /* Socket state. */ int mask) /* type of event that occurred: * OR-ed combination of TCL_READABLE or TCL_WRITABLE */ { - State *statePtr = (State *) instanceData; + State *statePtr = (State *)instanceData; int errorCode; /* * An event occurred in the underlying channel. This * transformation doesn't process such events thus returns the @@ -878,11 +890,11 @@ * Result: * None. * *------------------------------------------------------* */ -static void TlsChannelHandlerTimer(ClientData clientData) { +static void TlsChannelHandlerTimer(void *clientData) { State *statePtr = (State *) clientData; int mask = 0; dprintf("Called"); @@ -937,22 +949,22 @@ "tls", /* Type name */ TCL_CHANNEL_VERSION_5, /* v5 channel */ TlsCloseProc, /* Close proc */ TlsInputProc, /* Input proc */ TlsOutputProc, /* Output proc */ - NULL, /* Seek proc */ + 0, /* Seek proc */ TlsSetOptionProc, /* Set option proc */ TlsGetOptionProc, /* Get option proc */ TlsWatchProc, /* Initialize notifier */ TlsGetHandleProc, /* Get OS handles out of channel */ TlsClose2Proc, /* close2proc */ TlsBlockModeProc, /* Set blocking/nonblocking mode*/ - NULL, /* Flush proc */ + 0, /* Flush proc */ TlsNotifyProc, /* Handling of events bubbling up */ - NULL, /* Wide seek proc */ + 0, /* Wide seek proc */ NULL, /* Thread action */ NULL /* Truncate */ }; const Tcl_ChannelType *Tls_ChannelType(void) { return &tlsChannelType; }