void CIMExportClient::connect( const String& host, const Uint32 portNumber) { PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "CIMExportClient::connect()"); // If already connected, bail out! if (_connected) { PEG_METHOD_EXIT(); throw AlreadyConnectedException(); } // // If the host is empty, set hostName to "localhost" // String hostName = host; if (host == String::EMPTY) { hostName = "localhost"; } // // Set authentication information // _authenticator.clear(); _connectSSLContext.reset(0); _connectHost = hostName; _connectPortNumber = portNumber; _connect(); PEG_METHOD_EXIT(); }
void WMIClientRep::connectLocal() { // // If already connected, bail out! // if (_connected) throw AlreadyConnectedException(); _connected = true; }
void WbemExecClient::connect( const String& host, Uint32 portNumber, const SSLContext* sslContext, const String& userName, const String& password) { // // If already connected, bail out! // if (_connected) throw AlreadyConnectedException(); // // If the host is empty, set hostName to "localhost" // String hostName = host; if (host == String::EMPTY) { hostName = "localhost"; } // // Set authentication information // _authenticator.clear(); if (userName.size()) { _authenticator.setUserName(userName); } if (password.size()) { _authenticator.setPassword(password); _password = password; } if (sslContext) { _connectSSLContext.reset(new SSLContext(*sslContext)); } else { _connectSSLContext.reset(); } _connectHost = hostName; _connectPortNumber = portNumber; _connect(); _isRemote = true; }
void CIMClientRep::connect( const String& host, const Uint32 portNumber, const String& userName, const String& password ) { // // If already connected, bail out! // if (_connected) throw AlreadyConnectedException(); // // If the host is empty, set hostName to "localhost" // String hostName = host; if (host == String::EMPTY) { hostName = "localhost"; } // // Set authentication information // _authenticator.clear(); if (userName.size()) { _authenticator.setUserName(userName); } if (password.size()) { _authenticator.setPassword(password); } _connectSSLContext.reset(); _connectHost = hostName; _connectPortNumber = portNumber; _connect(); }
void ExportClient::connect( const String& host, const Uint32 portNumber, const SSLContext& sslContext) { PEG_METHOD_ENTER (TRC_EXPORT_CLIENT, "ExportClient::connect()"); // If already connected, bail out! if (_connected) { PEG_METHOD_EXIT(); throw AlreadyConnectedException(); } // // If the host is empty, set hostName to "localhost" // String hostName = host; if (host == String::EMPTY) { hostName = "localhost"; } _authenticator.clear(); _connectSSLContext.reset(new SSLContext(sslContext)); _connectHost = hostName; _connectPortNumber = portNumber; try { _connect(); } catch (...) { _connectSSLContext.reset(); PEG_METHOD_EXIT(); throw; } PEG_METHOD_EXIT(); }
void WbemExecClient::connectLocal() { // // If already connected, bail out! // if (_connected) throw AlreadyConnectedException(); // // Set authentication type // _authenticator.clear(); _authenticator.setAuthType(ClientAuthenticator::LOCAL); #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET _connectSSLContext.reset(); _connectHost = String::EMPTY; _connectPortNumber = 0; _connect(); #else try { // // Look up the WBEM HTTP port number for the local system // _connectPortNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT); // // Assign host // _connectHost.assign(System::getHostName()); _connectSSLContext.reset(); _connect(); } catch (CannotConnectException&) { #ifdef PEGASUS_HAS_SSL // // Look up the WBEM HTTPS port number for the local system // _connectPortNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT); // // Assign host // _connectHost.assign(System::getHostName()); // // Create SSLContext // const char* pegasusHome = getenv("PEGASUS_HOME"); String certpath = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE); String randFile; #ifdef PEGASUS_SSL_RANDOMFILE randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE); #endif _connectSSLContext.reset( new SSLContext(certpath, verifyServerCertificate, randFile)); _connect(); #else throw; #endif // PEGASUS_HAS_SSL } #endif // PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET _isRemote = false; }
void CIMClientRep::connectLocal() { // // If already connected, bail out! // if (_connected) throw AlreadyConnectedException(); // // Set authentication type // _authenticator.clear(); _authenticator.setAuthType(ClientAuthenticator::LOCAL); #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET _connectSSLContext.reset(); _connectHost = String::EMPTY; _connectPortNumber = 0; _connect(); #else try { // // Look up the WBEM HTTP port number for the local system // _connectPortNumber = System::lookupPort (WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT); // // Assign host // _connectHost.assign(_getLocalHostName()); _connectSSLContext.reset(); _connect(); } catch(const CannotConnectException &) { // // Look up the WBEM HTTPS port number for the local system // _connectPortNumber = System::lookupPort (WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT); // // Assign host // _connectHost.assign(_getLocalHostName()); // // Create SSLContext // #ifdef PEGASUS_OS_OS400 #pragma convert(37) const char* env = getenv("PEGASUS_HOME"); #pragma convert(0) char pegasusHome[256] = {0}; if (env != NULL && strlen(env) < 256) { strcpy(pegasusHome, env); EtoA(pegasusHome); } #else const char* pegasusHome = getenv("PEGASUS_HOME"); #endif String randFile = String::EMPTY; #ifdef PEGASUS_SSL_RANDOMFILE randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE); #endif try { _connectSSLContext.reset( new SSLContext(String::EMPTY, NULL, randFile)); } catch (const SSLException &) { throw; } _connect(); } #endif }
// // connect() // bool SocketChannel::connect(const SocketAddress& remote,const char* interface) throw(AlreadyConnectedException, ConnectionPendingException, ClosedChannelException, AsynchronousCloseException, ClosedByInterruptException, UnresolvedAddressException, UnsupportedAddressTypeException, IOException) { int error = 0; try { // Sincroniza esta operacion con finishConnect() Synchronized synchronized(_connect); { // Comprueba si ya esta conectado if (isConnected()) { throw AlreadyConnectedException("Channel already connected"); } // Comprueba si hay una operacion de conexion en curso if (isConnectionPending()) { throw ConnectionPendingException( "Non-blocking connection already in progress"); } // Comprueba si esta cerrado if (! isOpen()) { throw ClosedChannelException("Channel is closed"); } // Comprueba si 'remote' es un objeto InetSocketAddress const InetSocketAddress* remoteptr = dynamic_cast<const InetSocketAddress*>(&remote); if (remoteptr == NULL) { throw UnsupportedAddressTypeException("Invalid SocketAddress"); } // Comprueba si la direccion SockAddress esta resuelta if (remoteptr->isUnresolved()) { throw UnresolvedAddressException( "Remote address not fully resolved"); } // Comprueba si esta en modo bloqueante if (isBlocking()) { // Intenta la conexion _socket->connect(remote,interface); // Modifica el estado Synchronized synchronized(_sync); { _status |= TID_SOCKET_CHANNEL_STATUS_CONNECTED; } return true; } // Prepara los datos de la conexion PlainSocketImpl::toSockAddr(remoteptr->getAddress(), remoteptr->getPort(), _sockaddr, _socksize, interface); // Conexion no bloqueante int fd = (int) _socket->_impl->getFileDescriptor(); error = ::connect(fd, (struct sockaddr*)&_sockaddr, _socksize); if (error && (errno != EINPROGRESS)) { throw IOException("connect() error", errno); } // Modifica el estado Synchronized synchronized(_sync); { if (error == 0) _status |= TID_SOCKET_CHANNEL_STATUS_CONNECTED; else _status |= TID_SOCKET_CHANNEL_STATUS_CONNECTION_PENDING; } } // Fin sincronizacion con finishConnect() } catch(TIDThr::Exception& e) { throw IOException(e.what()); } return (error == 0); }