axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject cvs commit: ws-axis/c/src/transport/axis3/HTTPSSLChannel HTTPSSLChannel.cpp
Date Fri, 28 Jan 2005 13:10:32 GMT
prestonf    2005/01/28 05:10:32

  Modified:    c/src/transport/axis3/HTTPSSLChannel HTTPSSLChannel.cpp
  Log:
  Hi All,
  No fix, just tidying of code.
  
  Revision  Changes    Path
  1.8       +291 -40   ws-axis/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp
  
  Index: HTTPSSLChannel.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HTTPSSLChannel.cpp	24 Jan 2005 14:05:02 -0000	1.7
  +++ HTTPSSLChannel.cpp	28 Jan 2005 13:10:32 -0000	1.8
  @@ -1,4 +1,12 @@
   #include "HTTPSSLChannel.hpp"
  +#include "../../../platforms/PlatformAutoSense.hpp"
  +
  +/**
  + * cert_verify_callback( int ok, X509_STORE_CTX * ctx)
  + *
  + * cert_verify_callback callback
  + *
  + */
   
   static int cert_verify_callback( int ok, X509_STORE_CTX * ctx)
   {
  @@ -11,6 +19,13 @@
     return ok;
   }
   
  +/**
  + * HTTPSSLChannel::HTTPSSLChannel()
  + *
  + * HTTPSSLChannel constuctor
  + *
  + */
  +
   HTTPSSLChannel::HTTPSSLChannel()
   {
   	m_LastError = "No Errors";
  @@ -38,6 +53,13 @@
   	m_sslHandle = NULL;
   }
   
  +/**
  + * HTTPSSLChannel::~HTTPSSLChannel()
  + *
  + * HTTPSSLChannel destuctor
  + *
  + */
  +
   HTTPSSLChannel::~HTTPSSLChannel()
   {
   	OpenSSL_Close();
  @@ -52,23 +74,57 @@
   	StopSockets();
   }
   
  +/**
  + * HTTPSSLChannel::getURL()
  + *
  + * Return the URL currently assicated with the channel object.
  + *
  + * @return char * containing the URL associated with the open socket
  + */
  +
   const char * HTTPSSLChannel::getURL()
   {
  -// Return the URL currently assicated with the channel object.
       return m_URL.getURL();
   }
   
  +/**
  + * HTTPSSLChannel::setURL( const char * cpURL)
  + *
  + * Set the Channel URL to the new value.
  + *
  + * @param const char * containing the new URL
  + */
  +
   void HTTPSSLChannel::setURL( const char * cpURL)
   {
  -// Set the Channel URL to the new value.
       m_URL.setURL( cpURL);
   }
   
  +/**
  + * HTTPSSLChannel::getURLObject()
  + *
  + * Return the current URL object
  + *
  + * @return URL & current URL object
  + */
  +
   URL & HTTPSSLChannel::getURLObject()
   {
       return m_URL;
   }
   
  +/**
  + * HTTPSSLChannel::open()
  + *
  + * Main method for opening a HTTP channel.  If a channel is already open, it is
  + * closed before attempting to open a new channel.  If the method fails to open
  + * a new channel then an exception will be thrown.
  + *
  + * @return boolean flag set to AXIS_FAIL or AXIS_SUCCESS depending on outcome
  + * of opening a channel (Since an exception is always thrown on failure, the
  + * returned flag will only be returned on a successful outcome).
  + */
  +
   bool HTTPSSLChannel::open() throw (HTTPTransportException&)
   {
   	bool	bSuccess = (bool) AXIS_FAIL;
  @@ -78,6 +134,8 @@
   		CloseChannel();
   	}
   
  +	m_LastError = "No Errors";
  +
   	if( (bSuccess = OpenChannel()) != AXIS_SUCCESS)
   	{
   		throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR,
  @@ -89,6 +147,15 @@
   	return bSuccess;
   }
   
  +/**
  + * HTTPSSLChannel::close()
  + *
  + * Main method for closing a HTTP channel.
  + *
  + * @return boolean flag set to AXIS_FAIL or AXIS_SUCCESS depending on outcome
  + * of closing the channel.
  + */
  +
   bool HTTPSSLChannel::close()
   {
       if( m_Sock != INVALID_SOCKET)
  @@ -101,11 +168,34 @@
   	return AXIS_SUCCESS;
   }
   
  +/**
  + * HTTPSSLChannel::GetLastErrorMsg()
  + *
  + * Returns the last reported error on the channel.
  + *
  + * @return string containing last error.
  + */
  +
   const std::string & HTTPSSLChannel::GetLastErrorMsg()
   {
   	return m_LastError;
   }
   
  +/**
  + * HTTPSSLChannel::operator >> (const char * msg)
  + *
  + * This method attempts to read a message from the curently open channel.  If
  + * there is no currently open channel, then the method throws an exception.  If
  + * there is an open channel, but nothing to recieve, then then method will
  + * timeout and throw an exception.  If the mesage is interrupted or the
  + * transmitting side closes then an exception is thrown.
  + *
  + * @param character pointer containing an array of character that can be filled
  + * by the reieved message (NB: The maximum message length is BUF_SIZE).
  + * @return character pointer pointing to the array of character containing the
  + * recieved message.
  + */
  +
   const IChannel & HTTPSSLChannel::operator >> (const char * msg)
   {
       if (INVALID_SOCKET == m_Sock)
  @@ -125,6 +215,18 @@
   	return *this;
   }
   
  +/**
  + * HTTPSSLChannel::operator << (const char * msg)
  + *
  + * This method attempts to write a message to the curently open channel.  If
  + * there is no currently open channel, then the method throws an exception.  If
  + * there is an open channel, but the mesage is interrupted or the recieving
  + * side closes then an exception is thrown.
  + *
  + * @param character pointer pointing to the array of character containing the
  + * message to be transmitted.
  + */
  +
   const IChannel & HTTPSSLChannel::operator << (const char * msg)
   {
   // Check that the Tx/Rx sockets are valid (this will have been done if the
  @@ -145,16 +247,52 @@
   	return *this;
   }
   
  +/**
  + * HTTPSSLChannel::setTimeout( const long lSeconds)
  + *
  + * Set the Rx message timeout (in seconds)
  + *
  + * @param long containing timeout value in seconds
  + */
  +
   void HTTPSSLChannel::setTimeout( const long lSeconds)
   {
       m_lTimeoutSeconds = lSeconds;
   }
   
  +/**
  + * HTTPSSLChannel::setSocket( unsigned int uiNewSocket)
  + *
  + * This is used by the server side to change the server socket.
  + *
  + * @param unsigned int containing the new server socket.
  + */
  +
   void HTTPSSLChannel::setSocket( unsigned int uiNewSocket)
   {
       m_Sock = uiNewSocket;
   }
   
  +/**
  + * HTTPSSLChannel::setTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type, const char
* value)
  + *
  + * The following list can be set using this property:-
  + * SOAPACTION_HEADER			- No action
  + * SERVICE_URI					- No action
  + * OPERATION_NAME				- No action
  + * SOAP_MESSAGE_LENGTH			- No action
  + * TRANSPORT_PROPERTIES			- No action
  + * SECURE_PROPERTIES			- No action
  + * DLL_NAME						- No action
  + * CHANNEL_HTTP_SSL_DLL_NAME	- No action
  + * CHANNEL_HTTP_DLL_NAME		- No action
  + *
  + * @param AXIS_TRANSPORT_INFORMATION_TYPE contains the type of property to be
  + *        set.
  + *        const char * contains the value for the type to be set to.
  + * @return boolean flag indicating success of the alteration. 
  + */
  +
   bool HTTPSSLChannel::setTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type, const
char* value)
   {
   	bool	bSuccess = false;
  @@ -162,11 +300,39 @@
   	return bSuccess;
   }
   
  +/**
  + * HTTPSSLChannel::getTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type)
  + *
  + * The following list can be retrieved using this property:-
  + * SOAPACTION_HEADER			- No action
  + * SERVICE_URI					- No action
  + * OPERATION_NAME				- No action
  + * SOAP_MESSAGE_LENGTH			- No action
  + * TRANSPORT_PROPERTIES			- No action
  + * SECURE_PROPERTIES			- No action
  + * DLL_NAME						- No action
  + * CHANNEL_HTTP_SSL_DLL_NAME	- No action
  + * CHANNEL_HTTP_DLL_NAME		- No action
  + *
  + * @param AXIS_TRANSPORT_INFORMATION_TYPE contains the type of property to be
  + *        recovered.
  + * @return const char * contains the value for the requested type.
  + */
  +
   const char * HTTPSSLChannel::getTransportProperty( AXIS_TRANSPORT_INFORMATION_TYPE type)
   {
   	return NULL;
   }
   
  +/**
  + * HTTPSSLChannel::setProxy( const char * pcProxyHost, unsigned int uiProxyPort)
  + *
  + * Setup he proxy values to be used by the channel.
  + *
  + * @param const char * containing the name of the proxy host.
  + *		  unsigned int containing the proxy port value.
  + */
  +
   void HTTPSSLChannel::setProxy (const char *pcProxyHost, unsigned int uiProxyPort)
   {
       m_strProxyHost = pcProxyHost;
  @@ -178,8 +344,19 @@
   // | Protected methods														  |
   // | -----------------														  |
   // +--------------------------------------------------------------------------+
  +
  +/**
  + * HTTPSSLChannel::OpenChannel()
  + *
  + * Protected function
  + *
  + * @param
  + * @return 
  + */
  +
   bool HTTPSSLChannel::OpenChannel()
   {
  +// This method is common to all channel implementations
   	bool	bSuccess = (bool) AXIS_FAIL;
   
   // Create the Client (Rx) side first.
  @@ -191,7 +368,8 @@
       // hints is used after zero cleared
       memset( &aiHints, 0, sizeof( aiHints));
   
  -    aiHints.ai_family = PF_UNSPEC;
  +    aiHints.ai_family = PF_UNSPEC;		// This allows the sockets code to use
  +										// whatever socket family is available.
       aiHints.ai_socktype = SOCK_STREAM;
   
       char szPort[7];
  @@ -225,11 +403,26 @@
           {
               // Cannot open a channel to the remote end, shutting down the
               // channel and then throw an exception.
  -            CloseChannel();
  +            // Before we do anything else get the last error message;
  +			long dw = GETLASTERROR
   
  +			CloseChannel();
               free( paiAddrInfo0);
  +			
  +			string* message = PLATFORM_GET_ERROR_MESSAGE(dw);
  +
  +			char fullMessage[600];
  +			sprintf(fullMessage,
  +				"Failed to open connection to server: \n \
  +				hostname='%s'\n\
  +				port='%d'\n\
  +				Error Message='%s'\
  +				Error Code='%d'\n",
  +				m_URL.getHostName(), m_URL.getPort(), message->c_str(), (int)dw);
  +				
  +			delete(message);
   
  -            throw HTTPTransportException( SERVER_TRANSPORT_SOCKET_CONNECT_ERROR);
  +			throw HTTPTransportException( CLIENT_TRANSPORT_OPEN_CONNECTION_FAILED, fullMessage);
           }
   
           break;
  @@ -240,7 +433,7 @@
   
       if( m_Sock < 0)
       {
  -        // Sockets error - Couldn't create socket.  Close the channel and throw
  +        // Sockets error Couldn't create socket.  Close the channel and throw
           // an exception.
           CloseChannel();
   
  @@ -316,44 +509,26 @@
   // Cannot open a channel to the remote end, shutting down the
   // channel and then throw an exception.
   
  -#ifdef WIN32
   // Before we do anything else get the last error message;
  -// I'd like to put the getting of the error message into platform specifics
  -// but not sure how!  I think it would be nicer to make the platform
  -// specifics a class and not just macros.  That way we could have e.g.
  -// char * Windows#getLastErrorMessage().
  -		long lLastError = GetLastError();
  -#endif // WIN32
  +			long dw = GETLASTERROR
  +			CloseChannel();
   
  -		CloseChannel();
  +			
  +			string* message = PLATFORM_GET_ERROR_MESSAGE(dw);
   
  -#ifdef WIN32
  -		char	szErrorBuffer[200]; 
  -	    LPVOID	lpErrorBuffer;
  +			char fullMessage[600];
  +			sprintf(fullMessage,
  +				"Failed to open connection to server: \n \
  +				hostname='%s'\n\
  +				port='%d'\n\
  +				Error Message='%s'\
  +				Error Code='%d'\n",
  +				m_URL.getHostName(), m_URL.getPort(), message->c_str(), dw);
  +				
  +			delete(message);
   
  -		FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
  -					   NULL,
  -					   lLastError,
  -					   MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT),
  -					   (LPTSTR) &lpErrorBuffer,
  -					   0,
  -					   NULL);
  -
  -		sprintf( szErrorBuffer, 
  -				 "Failed to open connection to server:\n\
  -				 hostname='%s'\n\
  -				 port='%d'\n\
  -				 Error Message='%s'\
  -				 Error Code='%d'\n",                     \
  -				 m_URL.getHostName(), m_URL.getPort(), lpErrorBuffer, lLastError); 
  - 
  -	    LocalFree( lpErrorBuffer);
  -
  -		m_LastError = szErrorBuffer;
  -#else // WIN32 not defined
  -		m_LastError = "Cannot open a channel to the remote end.";
  +		m_LastError = fullMessage;
   
  -#endif // WIN32
   	    return bSuccess;
       }
   	else
  @@ -380,6 +555,15 @@
       return bSuccess;
   }
   
  +/**
  + * HTTPSSLChannel::CloseChannel()
  + *
  + * Protected function
  + *
  + * @param
  + * @return 
  + */
  +
   void HTTPSSLChannel::CloseChannel()
   {
       if( INVALID_SOCKET != m_Sock) // Check if socket already closed : AXISCPP-185
  @@ -393,6 +577,15 @@
   	}
   }
   
  +/**
  + * HTTPSSLChannel::StartSockets()
  + *
  + * Protected function
  + *
  + * @param
  + * @return 
  + */
  +
   bool HTTPSSLChannel::StartSockets()
   {
   	bool	bSuccess = false;
  @@ -437,6 +630,15 @@
       return bSuccess;
   }
   
  +/**
  + * HTTPSSLChannel::StopSockets()
  + *
  + * Protected function
  + *
  + * @param
  + * @return 
  + */
  +
   void HTTPSSLChannel::StopSockets()
   {
   #ifdef WIN32
  @@ -445,10 +647,11 @@
   }
   
   /**
  - * Channel::applyTimeout()
  + * HTTPSSLChannel::applyTimeout()
    *
    * @return int 
    */
  +
   int HTTPSSLChannel::applyTimeout()
   {
       fd_set			set;
  @@ -466,6 +669,14 @@
       return select( FD_SETSIZE, &set, NULL, NULL, &timeout);
   }
   
  +/**
  + * HTTPSSLChannel::ReadFromSocket( const char * pszRxBuffer)
  + *
  + * Protected function
  + *
  + * @return int 
  + */
  +
   int HTTPSSLChannel::ReadFromSocket( const char * pszRxBuffer)
   {
       int nByteRecv = 0;
  @@ -487,6 +698,14 @@
   	return nByteRecv;
   }
   
  +/**
  + * HTTPSSLChannel::WriteToSocket( const char * psTxBuffer, int iSize)
  + *
  + * Protected function
  + *
  + * @return int 
  + */
  +
   int HTTPSSLChannel::WriteToSocket( const char * psTxBuffer, int iSize)
   {
   	int nByteSent;
  @@ -504,6 +723,14 @@
   	return nByteSent;
   }
   
  +/**
  + * HTTPSSLChannel::OpenSSL_Initialise()
  + *
  + * Protected function
  + *
  + * @return int 
  + */
  +
   void HTTPSSLChannel::OpenSSL_Initialise()
   {
   // Lets get nice error messages
  @@ -513,6 +740,14 @@
   	SSLeay_add_ssl_algorithms();
   }
   
  +/**
  + * HTTPSSLChannel::OpenSSL_Open()
  + *
  + * Protected function
  + *
  + * @return int 
  + */
  +
   bool HTTPSSLChannel::OpenSSL_Open()
   {
       SSL_METHOD *	req_method = SSLv23_client_method();
  @@ -566,6 +801,14 @@
   	return bSuccess;
   }
   
  +/**
  + * HTTPSSLChannel::OpenSSL_Close()
  + *
  + * Protected function
  + *
  + * @return int 
  + */
  +
   int HTTPSSLChannel::OpenSSL_Close()
   {
       if( m_sslHandle)
  @@ -586,6 +829,14 @@
   	return 0;
   }
   
  +/**
  + * HTTPSSLChannel::OpenSSL_SetSecureError( int iError)
  + *
  + * Protected function
  + *
  + * @return int 
  + */
  +
   void HTTPSSLChannel::OpenSSL_SetSecureError( int iError)
   {
       switch( iError)
  
  
  

Mime
View raw message