diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Service.cpp | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/Activator.cpp | 11 | ||||
-rw-r--r-- | cpp/src/IceGrid/DescriptorHelper.h | 2 | ||||
-rw-r--r-- | cpp/src/IceGrid/NodeCache.cpp | 3 | ||||
-rw-r--r-- | cpp/src/IceGrid/NodeSessionManager.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IceGrid/ReplicaSessionManager.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IceGrid/ReplicaSessionManager.h | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/ServerI.cpp | 4 | ||||
-rw-r--r-- | cpp/src/IceGrid/SessionManager.h | 172 | ||||
-rw-r--r-- | cpp/src/IceGrid/Util.cpp | 25 | ||||
-rw-r--r-- | cpp/src/IceGrid/Util.h | 2 | ||||
-rw-r--r-- | cpp/src/IceSSL/.depend | 4 | ||||
-rw-r--r-- | cpp/src/IceSSL/Instance.cpp | 159 | ||||
-rw-r--r-- | cpp/src/IceSSL/Instance.h | 1 | ||||
-rw-r--r-- | cpp/src/IceSSL/PluginI.cpp | 183 | ||||
-rw-r--r-- | cpp/src/IceSSL/PluginI.h | 4 | ||||
-rw-r--r-- | cpp/src/IceUtil/ArgVector.cpp | 119 | ||||
-rwxr-xr-x | cpp/src/Slice/Preprocessor.cpp | 102 | ||||
-rw-r--r-- | cpp/src/Slice/Util.cpp | 10 | ||||
-rw-r--r-- | cpp/src/slice2html/Gen.cpp | 66 |
20 files changed, 445 insertions, 434 deletions
diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp index af3838b2b5c..c8145f93fd7 100644 --- a/cpp/src/Ice/Service.cpp +++ b/cpp/src/Ice/Service.cpp @@ -709,9 +709,7 @@ int Ice::Service::main(StringSeq& args, const InitializationData& initData) { IceUtilInternal::ArgVector av(args); - int rc = main(av.argc, av.argv, initData); - argsToStringSeq(av.argc, av.argv); - return rc; + return main(av.argc, av.argv, initData); } Ice::CommunicatorPtr diff --git a/cpp/src/IceGrid/Activator.cpp b/cpp/src/IceGrid/Activator.cpp index 1ce7135e15b..501f8110741 100644 --- a/cpp/src/IceGrid/Activator.cpp +++ b/cpp/src/IceGrid/Activator.cpp @@ -682,15 +682,14 @@ Activator::activate(const string& name, for(int i = 0; i < env.argc; i++) { - if(putenv(env.argv[i]) != 0) + // + // Each env is leaked on purpose ... see man putenv(). + // + if(putenv(strdup(env.argv[i])) != 0) { reportChildError(errno, fds[1], "cannot set environment variable", env.argv[i]); } } - // - // Each env is leaked on purpose ... see man putenv(). - // - env.setNoDelete(); // // Change working directory. @@ -701,7 +700,7 @@ Activator::activate(const string& name, { reportChildError(errno, fds[1], "cannot change working directory to", pwdCStr); } - } + } if(execvp(av.argv[0], av.argv) == -1) { diff --git a/cpp/src/IceGrid/DescriptorHelper.h b/cpp/src/IceGrid/DescriptorHelper.h index 4f69318239f..de662d5880c 100644 --- a/cpp/src/IceGrid/DescriptorHelper.h +++ b/cpp/src/IceGrid/DescriptorHelper.h @@ -225,7 +225,9 @@ public: protected: +#if defined(__sun) using ServerHelper::instantiateImpl; +#endif void instantiateImpl(const IceBoxDescriptorPtr&, const Resolver&, const PropertyDescriptorSeq&, const PropertySetDescriptorDict&) const; diff --git a/cpp/src/IceGrid/NodeCache.cpp b/cpp/src/IceGrid/NodeCache.cpp index 5bdb1e12b75..812cb1977df 100644 --- a/cpp/src/IceGrid/NodeCache.cpp +++ b/cpp/src/IceGrid/NodeCache.cpp @@ -932,7 +932,8 @@ NodeEntry::getInternalServerDescriptor(const ServerInfo& info) const { ServiceDescriptorPtr s = p->descriptor; const string path = _session->getInfo()->dataDir + "/servers/" + server->id + "/config/config_" + s->name; - props.push_back(createProperty("IceBox.Service." + s->name, s->entry + " --Ice.Config=\"" + path + "\"")); + props.push_back(createProperty("IceBox.Service." + s->name, s->entry + " --Ice.Config='" + + escapeProperty(path) + "'")); servicesStr += s->name + " "; } if(!hasProperty(info.descriptor->propertySet.properties, "IceBox.InstanceName")) diff --git a/cpp/src/IceGrid/NodeSessionManager.cpp b/cpp/src/IceGrid/NodeSessionManager.cpp index 38ee0b5343c..06ae7828d3f 100644 --- a/cpp/src/IceGrid/NodeSessionManager.cpp +++ b/cpp/src/IceGrid/NodeSessionManager.cpp @@ -19,7 +19,7 @@ using namespace IceGrid; NodeSessionKeepAliveThread::NodeSessionKeepAliveThread(const InternalRegistryPrx& registry, const NodeIPtr& node, const vector<QueryPrx>& queryObjects) : - SessionKeepAliveThread<NodeSessionPrx>(registry), + SessionKeepAliveThread<NodeSessionPrx>(registry, node->getTraceLevels()->logger), _node(node), _queryObjects(queryObjects) { diff --git a/cpp/src/IceGrid/ReplicaSessionManager.cpp b/cpp/src/IceGrid/ReplicaSessionManager.cpp index 665a8a4f08e..a1f4e26c229 100644 --- a/cpp/src/IceGrid/ReplicaSessionManager.cpp +++ b/cpp/src/IceGrid/ReplicaSessionManager.cpp @@ -300,7 +300,7 @@ ReplicaSessionManager::create(const string& name, _queryObjects.push_back(QueryPrx::uncheckedCast(query->ice_endpoints(singleEndpoint))); } - _thread = new Thread(*this, _master); + _thread = new Thread(*this, _master, _traceLevels->logger); _thread->start(); notifyAll(); } diff --git a/cpp/src/IceGrid/ReplicaSessionManager.h b/cpp/src/IceGrid/ReplicaSessionManager.h index dea09b439a7..49f052cb32f 100644 --- a/cpp/src/IceGrid/ReplicaSessionManager.h +++ b/cpp/src/IceGrid/ReplicaSessionManager.h @@ -37,8 +37,8 @@ public: { public: - Thread(ReplicaSessionManager& manager, const InternalRegistryPrx& master) : - SessionKeepAliveThread<ReplicaSessionPrx>(master), + Thread(ReplicaSessionManager& manager, const InternalRegistryPrx& master, const Ice::LoggerPtr& logger) : + SessionKeepAliveThread<ReplicaSessionPrx>(master, logger), _manager(manager) { } diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp index 4dc1d241882..acb22747b52 100644 --- a/cpp/src/IceGrid/ServerI.cpp +++ b/cpp/src/IceGrid/ServerI.cpp @@ -1368,7 +1368,7 @@ ServerI::activate() // Ice::StringSeq options; copy(desc->options.begin(), desc->options.end(), back_inserter(options)); - options.push_back("--Ice.Config=" + _serverDir + "/config/config"); + options.push_back("--Ice.Config=" + escapeProperty(_serverDir + "/config/config")); Ice::StringSeq envs; transform(desc->envs.begin(), desc->envs.end(), back_inserter(envs), EnvironmentEval()); @@ -2143,7 +2143,7 @@ ServerI::updateImpl(const InternalServerDescriptorPtr& descriptor) } else { - configfile << r->name << "=" << r->value << endl; + configfile << escapeProperty(r->name) << "=" << escapeProperty(r->value) << endl; } } configfile.close(); diff --git a/cpp/src/IceGrid/SessionManager.h b/cpp/src/IceGrid/SessionManager.h index 9340699dab5..7760241e865 100644 --- a/cpp/src/IceGrid/SessionManager.h +++ b/cpp/src/IceGrid/SessionManager.h @@ -42,8 +42,9 @@ class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<I public: - SessionKeepAliveThread(const InternalRegistryPrx& registry) : + SessionKeepAliveThread(const InternalRegistryPrx& registry, const Ice::LoggerPtr& logger) : _registry(registry), + _logger(logger), _state(InProgress), _nextAction(None) { @@ -57,108 +58,122 @@ public: IceUtil::Time timeout = IceUtil::Time::seconds(15); Action action = Connect; - while(true) + try { + while(true) { - Lock sync(*this); - if(_state == Destroyed) { - break; - } + Lock sync(*this); + if(_state == Destroyed) + { + break; + } - // - // Update the current state. - // - assert(_state == InProgress); - _state = session ? Connected : Disconnected; - _session = session; - if(_session) - { - _registry = registry; - } + // + // Update the current state. + // + assert(_state == InProgress); + _state = session ? Connected : Disconnected; + _session = session; + if(_session) + { + _registry = registry; + } - if(_nextAction == Connect && _state == Connected) - { - _nextAction = KeepAlive; - } - else if(_nextAction == Disconnect && _state == Disconnected) - { - _nextAction = None; - } - else if(_nextAction == KeepAlive && _state == Disconnected) - { - _nextAction = Connect; - } - notifyAll(); + if(_nextAction == Connect && _state == Connected) + { + _nextAction = KeepAlive; + } + else if(_nextAction == Disconnect && _state == Disconnected) + { + _nextAction = None; + } + else if(_nextAction == KeepAlive && _state == Disconnected) + { + _nextAction = Connect; + } + notifyAll(); - // - // Wait if there's nothing to do and if we are - // connected or if we've just tried to connect. - // - if(_nextAction == None) - { - if(_state == Connected || action == Connect || action == KeepAlive) + // + // Wait if there's nothing to do and if we are + // connected or if we've just tried to connect. + // + if(_nextAction == None) { - IceUtil::Time wakeTime = IceUtil::Time::now() + timeout; - while(_state != Destroyed && _nextAction == None) + if(_state == Connected || action == Connect || action == KeepAlive) { - if(!timedWait(wakeTime - IceUtil::Time::now())) + IceUtil::Time now = IceUtil::Time::now(); + IceUtil::Time wakeTime = now + timeout; + while(_state != Destroyed && _nextAction == None && wakeTime > now) { - break; + timedWait(wakeTime - now); + now = IceUtil::Time::now(); } } + if(_nextAction == None) + { + _nextAction = session ? KeepAlive : Connect; + } } - if(_nextAction == None) + + if(_state == Destroyed) { - _nextAction = session ? KeepAlive : Connect; + break; } + + assert(_nextAction != None); + + action = _nextAction; + registry = InternalRegistryPrx::uncheckedCast( + _registry->ice_timeout(static_cast<int>(timeout.toMilliSeconds()))); + _nextAction = None; + _state = InProgress; + notifyAll(); } - if(_state == Destroyed) + switch(action) { + case Connect: + assert(!session); + session = createSession(registry, timeout); + break; + case Disconnect: + assert(session); + destroySession(session); + session = 0; + break; + case KeepAlive: + assert(session); + if(!keepAlive(session)) + { + session = createSession(registry, timeout); + } break; + case None: + default: + assert(false); } - - assert(_nextAction != None); - - action = _nextAction; - registry = InternalRegistryPrx::uncheckedCast( - _registry->ice_timeout(static_cast<int>(timeout.toMilliSeconds()))); - _nextAction = None; - _state = InProgress; - notifyAll(); } - - switch(action) + + // + // Destroy the session. + // + if(_nextAction == Disconnect && session) { - case Connect: - assert(!session); - session = createSession(registry, timeout); - break; - case Disconnect: - assert(session); destroySession(session); - session = 0; - break; - case KeepAlive: - assert(session); - if(!keepAlive(session)) - { - session = createSession(registry, timeout); - } - break; - case None: - default: - assert(false); } } - - // - // Destroy the session. - // - if(_nextAction == Disconnect && session) + catch(const std::exception& ex) + { + Ice::Error out(_logger); + out << "unknown exception in session manager keep alive thread:\n" << ex.what(); + throw; + } + catch(...) { - destroySession(session); + Ice::Error out(_logger); + out << "unknown exception in session manager keep alive thread"; + throw; } } @@ -274,6 +289,7 @@ public: protected: InternalRegistryPrx _registry; + Ice::LoggerPtr _logger; TPrx _session; State _state; Action _nextAction; diff --git a/cpp/src/IceGrid/Util.cpp b/cpp/src/IceGrid/Util.cpp index 81675c30696..d3b6b998738 100644 --- a/cpp/src/IceGrid/Util.cpp +++ b/cpp/src/IceGrid/Util.cpp @@ -97,6 +97,31 @@ IceGrid::createProperty(const string& name, const string& value) return prop; } +string +IceGrid::escapeProperty(const string& s) +{ + string result; + for(unsigned int i = 0; i < s.size(); ++i) + { + char c = s[i]; + switch(c) + { + case '\\': + case ' ': + case '#': + case '=': + result.push_back('\\'); + result.push_back(c); + break; + + default: + result.push_back(c); + break; + } + } + return result; +} + int IceGrid::getMMVersion(const string& o) { diff --git a/cpp/src/IceGrid/Util.h b/cpp/src/IceGrid/Util.h index 805f870dc69..8b7df2f0d03 100644 --- a/cpp/src/IceGrid/Util.h +++ b/cpp/src/IceGrid/Util.h @@ -43,8 +43,8 @@ std::string toString(const Ice::Exception&); std::string getProperty(const PropertyDescriptorSeq&, const std::string&, const std::string& = std::string()); bool hasProperty(const PropertyDescriptorSeq&, const std::string&); - PropertyDescriptor createProperty(const std::string&, const std::string& = std::string()); +std::string escapeProperty(const std::string&); int getMMVersion(const std::string&); diff --git a/cpp/src/IceSSL/.depend b/cpp/src/IceSSL/.depend index 004fc172fce..2d8ef67fc0f 100644 --- a/cpp/src/IceSSL/.depend +++ b/cpp/src/IceSSL/.depend @@ -2,8 +2,8 @@ AcceptorI$(OBJEXT): AcceptorI.cpp ../IceSSL/AcceptorI.h $(includedir)/Ice/Logger Certificate$(OBJEXT): Certificate.cpp $(includedir)/IceUtil/DisableWarnings.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceSSL/Plugin.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/ConnectionF.h ../IceSSL/Util.h ../IceSSL/UtilF.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Protocol.h ../IceSSL/RFC2253.h ConnectorI$(OBJEXT): ConnectorI.cpp ../IceSSL/ConnectorI.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h ../Ice/TransceiverF.h ../Ice/Connector.h ../Ice/ConnectorF.h ../IceSSL/InstanceF.h ../IceSSL/Instance.h ../IceSSL/UtilF.h $(includedir)/Ice/CommunicatorF.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/ProtocolPluginFacadeF.h $(includedir)/IceSSL/Plugin.h $(includedir)/Ice/Plugin.h ../IceSSL/TrustManagerF.h $(includedir)/Ice/BuiltinSequences.h ../IceSSL/TransceiverI.h $(includedir)/Ice/StatsF.h ../Ice/Transceiver.h ../Ice/SelectorF.h ../IceSSL/EndpointI.h ../Ice/EndpointI.h $(includedir)/IceUtil/Thread.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/InstanceF.h ../Ice/AcceptorF.h $(includedir)/Ice/EndpointFactory.h $(includedir)/Ice/EndpointFactoryF.h ../IceSSL/Util.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/LoggerUtil.h EndpointI$(OBJEXT): EndpointI.cpp ../IceSSL/EndpointI.h ../Ice/EndpointI.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Thread.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/LocalObjectF.h $(includedir)/Ice/Handle.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/InstanceF.h ../Ice/TransceiverF.h ../Ice/ConnectorF.h ../Ice/AcceptorF.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/EndpointFactory.h $(includedir)/Ice/EndpointFactoryF.h ../IceSSL/InstanceF.h ../IceSSL/AcceptorI.h $(includedir)/Ice/LoggerF.h ../Ice/Acceptor.h ../IceSSL/ConnectorI.h ../Ice/Connector.h ../IceSSL/TransceiverI.h $(includedir)/IceSSL/Plugin.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/StatsF.h ../Ice/Transceiver.h ../Ice/SelectorF.h ../IceSSL/Instance.h ../IceSSL/UtilF.h $(includedir)/Ice/CommunicatorF.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/ProtocolPluginFacadeF.h ../IceSSL/TrustManagerF.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/StringConverter.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/LocalException.h ../Ice/DefaultsAndOverrides.h ../Ice/DefaultsAndOverridesF.h -Instance$(OBJEXT): Instance.cpp ../IceSSL/Instance.h ../IceSSL/InstanceF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h ../IceSSL/UtilF.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/LoggerF.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/ProtocolPluginFacadeF.h $(includedir)/IceSSL/Plugin.h $(includedir)/Ice/Plugin.h ../IceSSL/TrustManagerF.h $(includedir)/Ice/BuiltinSequences.h ../IceSSL/EndpointI.h ../Ice/EndpointI.h $(includedir)/IceUtil/Thread.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/InstanceF.h ../Ice/TransceiverF.h ../Ice/ConnectorF.h ../Ice/AcceptorF.h $(includedir)/Ice/EndpointFactory.h $(includedir)/Ice/EndpointFactoryF.h ../IceSSL/Util.h ../IceSSL/TrustManager.h ../IceSSL/RFC2253.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/StringConverter.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Timer.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/ProtocolPluginFacade.h $(includedir)/IceUtil/StringUtil.h $(includedir)/IceUtil/DisableWarnings.h -PluginI$(OBJEXT): PluginI.cpp ../IceSSL/PluginI.h $(includedir)/IceSSL/Plugin.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/ConnectionF.h ../IceSSL/InstanceF.h $(includedir)/Ice/CommunicatorF.h ../IceSSL/Instance.h ../IceSSL/UtilF.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/ProtocolPluginFacadeF.h ../IceSSL/TrustManagerF.h $(includedir)/Ice/BuiltinSequences.h ../IceSSL/TransceiverI.h $(includedir)/Ice/StatsF.h ../Ice/Transceiver.h ../Ice/TransceiverF.h ../Ice/SelectorF.h ../IceSSL/Util.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Logger.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/StringConverter.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/StringUtil.h ../Ice/ConnectionI.h $(includedir)/Ice/Connection.h $(includedir)/Ice/ConnectionFactoryF.h ../Ice/TraceLevelsF.h ../Ice/EventHandler.h ../Ice/EventHandlerF.h ../Ice/ThreadPoolF.h ../Ice/SocketReadyCallback.h ../Ice/SelectorThreadF.h +Instance$(OBJEXT): Instance.cpp ../IceSSL/Instance.h ../IceSSL/InstanceF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h ../IceSSL/UtilF.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/LoggerF.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/ProtocolPluginFacadeF.h $(includedir)/IceSSL/Plugin.h $(includedir)/Ice/Plugin.h ../IceSSL/TrustManagerF.h $(includedir)/Ice/BuiltinSequences.h ../IceSSL/EndpointI.h ../Ice/EndpointI.h $(includedir)/IceUtil/Thread.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/InstanceF.h ../Ice/TransceiverF.h ../Ice/ConnectorF.h ../Ice/AcceptorF.h $(includedir)/Ice/EndpointFactory.h $(includedir)/Ice/EndpointFactoryF.h ../IceSSL/Util.h ../IceSSL/TrustManager.h ../IceSSL/RFC2253.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/StatsF.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/Logger.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Properties.h $(includedir)/Ice/Outgoing.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/StringConverter.h $(includedir)/IceUtil/Unicode.h $(includedir)/Ice/OutgoingAsync.h $(includedir)/IceUtil/Timer.h $(includedir)/Ice/Incoming.h $(includedir)/Ice/ServantLocatorF.h $(includedir)/Ice/ServantManagerF.h $(includedir)/Ice/Direct.h $(includedir)/Ice/ProtocolPluginFacade.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/StringUtil.h $(includedir)/IceUtil/DisableWarnings.h +PluginI$(OBJEXT): PluginI.cpp ../IceSSL/PluginI.h $(includedir)/IceSSL/Plugin.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/ConnectionF.h ../IceSSL/InstanceF.h $(includedir)/Ice/CommunicatorF.h ../IceSSL/Instance.h ../IceSSL/UtilF.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/ProtocolPluginFacadeF.h ../IceSSL/TrustManagerF.h $(includedir)/Ice/BuiltinSequences.h ../IceSSL/TransceiverI.h $(includedir)/Ice/StatsF.h ../Ice/Transceiver.h ../Ice/TransceiverF.h ../Ice/SelectorF.h $(includedir)/Ice/LocalException.h ../Ice/ConnectionI.h $(includedir)/IceUtil/Monitor.h $(includedir)/IceUtil/Cond.h $(includedir)/Ice/Connection.h $(includedir)/Ice/ConnectionFactoryF.h $(includedir)/Ice/InstanceF.h $(includedir)/Ice/ServantManagerF.h ../Ice/TraceLevelsF.h ../Ice/EventHandler.h ../Ice/EventHandlerF.h ../Ice/ThreadPoolF.h $(includedir)/Ice/BasicStream.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/StringConverter.h $(includedir)/IceUtil/Unicode.h ../Ice/SocketReadyCallback.h $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Thread.h ../Ice/SelectorThreadF.h TransceiverI$(OBJEXT): TransceiverI.cpp ../IceSSL/TransceiverI.h ../IceSSL/InstanceF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/IceSSL/Plugin.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LocalObjectF.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/StatsF.h ../Ice/Transceiver.h ../Ice/TransceiverF.h ../Ice/SelectorF.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h ../IceSSL/Instance.h ../IceSSL/UtilF.h $(includedir)/Ice/CommunicatorF.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/Proxy.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/Protocol.h $(includedir)/Ice/ProtocolPluginFacadeF.h ../IceSSL/TrustManagerF.h $(includedir)/Ice/BuiltinSequences.h ../IceSSL/Util.h $(includedir)/Ice/Communicator.h $(includedir)/Ice/ObjectFactoryF.h $(includedir)/Ice/RouterF.h $(includedir)/Ice/LocatorF.h $(includedir)/Ice/PluginF.h $(includedir)/Ice/ImplicitContextF.h $(includedir)/Ice/LoggerUtil.h $(includedir)/Ice/Stats.h $(includedir)/Ice/Buffer.h $(includedir)/Ice/LocalException.h Util$(OBJEXT): Util.cpp ../IceSSL/Util.h ../IceSSL/UtilF.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h ../Ice/Network.h $(includedir)/Ice/PropertiesF.h $(includedir)/Ice/LocalObjectF.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/Proxy.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h $(includedir)/Ice/ProxyFactoryF.h $(includedir)/Ice/ConnectionIF.h $(includedir)/Ice/RequestHandlerF.h $(includedir)/Ice/EndpointIF.h $(includedir)/Ice/Endpoint.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/ObjectAdapterF.h $(includedir)/Ice/ReferenceF.h $(includedir)/Ice/OutgoingAsyncF.h $(includedir)/Ice/Current.h $(includedir)/Ice/ConnectionF.h $(includedir)/Ice/Identity.h $(includedir)/Ice/StreamF.h $(includedir)/Ice/CommunicatorF.h $(includedir)/Ice/Object.h $(includedir)/Ice/IncomingAsyncF.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/Protocol.h $(includedir)/IceSSL/Plugin.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LocalException.h $(includedir)/Ice/BuiltinSequences.h $(includedir)/IceUtil/DisableWarnings.h RFC2253$(OBJEXT): RFC2253.cpp $(includedir)/IceSSL/Plugin.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Config.h $(includedir)/Ice/Plugin.h $(includedir)/Ice/LocalObjectF.h $(includedir)/IceUtil/Shared.h $(includedir)/Ice/Handle.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/Ice/Config.h $(includedir)/Ice/ProxyHandle.h $(includedir)/Ice/ProxyF.h $(includedir)/Ice/ObjectF.h $(includedir)/Ice/GCCountMap.h $(includedir)/Ice/GCShared.h $(includedir)/Ice/Exception.h $(includedir)/Ice/LocalObject.h $(includedir)/Ice/LoggerF.h $(includedir)/Ice/UndefSysMacros.h $(includedir)/Ice/ConnectionF.h ../IceSSL/RFC2253.h diff --git a/cpp/src/IceSSL/Instance.cpp b/cpp/src/IceSSL/Instance.cpp index b5234010cec..a40dc5275cd 100644 --- a/cpp/src/IceSSL/Instance.cpp +++ b/cpp/src/IceSSL/Instance.cpp @@ -19,8 +19,10 @@ #include <Ice/Properties.h> #include <Ice/ProtocolPluginFacade.h> +#include <IceUtil/StaticMutex.h> #include <IceUtil/StringUtil.h> +#include <openssl/rand.h> #include <openssl/err.h> #include <IceUtil/DisableWarnings.h> @@ -31,9 +33,52 @@ using namespace IceSSL; IceUtil::Shared* IceInternal::upCast(IceSSL::Instance* p) { return p; } +static IceUtil::StaticMutex staticMutex = ICE_STATIC_MUTEX_INITIALIZER; +static int instanceCount = 0; +static IceUtil::Mutex* locks = 0; + extern "C" { +// +// OpenSSL mutex callback. +// +void +IceSSL_opensslLockCallback(int mode, int n, const char* file, int line) +{ + if(mode & CRYPTO_LOCK) + { + locks[n].lock(); + } + else + { + locks[n].unlock(); + } +} + +// +// OpenSSL thread id callback. +// +unsigned long +IceSSL_opensslThreadIdCallback() +{ +#if defined(_WIN32) + return static_cast<unsigned long>(GetCurrentThreadId()); +#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__osf1__) + // + // On some platforms, pthread_t is a pointer to a per-thread structure. + // + return reinterpret_cast<unsigned long>(pthread_self()); +#elif (defined(__linux) || defined(__sun) || defined(__hpux)) || defined(_AIX) + // + // On Linux, Solaris, HP-UX and AIX, pthread_t is an integer. + // + return static_cast<unsigned long>(pthread_self()); +#else +# error "Unknown platform" +#endif +} + int IceSSL_opensslPasswordCallback(char* buf, int size, int flag, void* userData) { @@ -87,6 +132,99 @@ IceSSL::Instance::Instance(const CommunicatorPtr& communicator) : { __setNoDelete(true); + // + // Initialize OpenSSL if necessary. + // + IceUtil::StaticMutex::Lock sync(staticMutex); + instanceCount++; + + if(instanceCount == 1) + { + PropertiesPtr properties = communicator->getProperties(); + + // + // Create the mutexes and set the callbacks. + // + locks = new IceUtil::Mutex[CRYPTO_num_locks()]; + CRYPTO_set_locking_callback(IceSSL_opensslLockCallback); + CRYPTO_set_id_callback(IceSSL_opensslThreadIdCallback); + + // + // Load human-readable error messages. + // + SSL_load_error_strings(); + + // + // Initialize the SSL library. + // + SSL_library_init(); + + // + // Initialize the PRNG. + // +#ifdef WINDOWS + RAND_screen(); // Uses data from the screen if possible. +#endif + char randFile[1024]; + if(RAND_file_name(randFile, sizeof(randFile))) // Gets the name of a default seed file. + { + RAND_load_file(randFile, 1024); + } + string randFiles = properties->getProperty("IceSSL.Random"); + if(!randFiles.empty()) + { + vector<string> files; +#ifdef _WIN32 + const string sep = ";"; +#else + const string sep = ":"; +#endif + string defaultDir = properties->getProperty("IceSSL.DefaultDir"); + if(!IceUtilInternal::splitString(randFiles, sep, files)) + { + PluginInitializationException ex(__FILE__, __LINE__); + ex.reason = "IceSSL: invalid value for IceSSL.Random:\n" + randFiles; + throw ex; + } + for(vector<string>::iterator p = files.begin(); p != files.end(); ++p) + { + string file = *p; + if(!checkPath(file, defaultDir, false)) + { + PluginInitializationException ex(__FILE__, __LINE__); + ex.reason = "IceSSL: entropy data file not found:\n" + file; + throw ex; + } + if(!RAND_load_file(file.c_str(), 1024)) + { + PluginInitializationException ex(__FILE__, __LINE__); + ex.reason = "IceSSL: unable to load entropy data from " + file; + throw ex; + } + } + } +#ifndef _WIN32 + // + // The Entropy Gathering Daemon (EGD) is not available on Windows. + // The file should be a Unix domain socket for the daemon. + // + string entropyDaemon = properties->getProperty("IceSSL.EntropyDaemon"); + if(!entropyDaemon.empty()) + { + if(RAND_egd(entropyDaemon.c_str()) <= 0) + { + PluginInitializationException ex(__FILE__, __LINE__); + ex.reason = "IceSSL: EGD failure using file " + entropyDaemon; + throw ex; + } + } +#endif + if(!RAND_status()) + { + communicator->getLogger()->warning("IceSSL: insufficient data to initialize PRNG"); + } + } + _facade = IceInternal::getProtocolPluginFacade(communicator); _securityTraceLevel = communicator->getProperties()->getPropertyAsInt("IceSSL.Trace.Security"); _securityTraceCategory = "Security"; @@ -102,6 +240,27 @@ IceSSL::Instance::Instance(const CommunicatorPtr& communicator) : __setNoDelete(false); } +IceSSL::Instance::~Instance() +{ + // + // Clean up OpenSSL resources. + // + IceUtil::StaticMutex::Lock sync(staticMutex); + + if(--instanceCount == 0) + { + CRYPTO_set_locking_callback(0); + CRYPTO_set_id_callback(0); + delete[] locks; + locks = 0; + + CRYPTO_cleanup_all_ex_data(); + RAND_cleanup(); + ERR_free_strings(); + EVP_cleanup(); + } +} + void IceSSL::Instance::initialize() { diff --git a/cpp/src/IceSSL/Instance.h b/cpp/src/IceSSL/Instance.h index 4cf354760f2..ba9eda28bbd 100644 --- a/cpp/src/IceSSL/Instance.h +++ b/cpp/src/IceSSL/Instance.h @@ -28,6 +28,7 @@ class Instance : public IceUtil::Shared public: Instance(const Ice::CommunicatorPtr&); + ~Instance(); void initialize(); void context(SSL_CTX*); diff --git a/cpp/src/IceSSL/PluginI.cpp b/cpp/src/IceSSL/PluginI.cpp index 25be708e998..005862c605e 100644 --- a/cpp/src/IceSSL/PluginI.cpp +++ b/cpp/src/IceSSL/PluginI.cpp @@ -10,25 +10,10 @@ #include <IceSSL/PluginI.h> #include <IceSSL/Instance.h> #include <IceSSL/TransceiverI.h> -#include <IceSSL/Util.h> -#include <Ice/BuiltinSequences.h> -#include <Ice/Communicator.h> #include <Ice/LocalException.h> -#include <Ice/Logger.h> -#include <Ice/Properties.h> - -#include <IceUtil/StaticMutex.h> -#include <IceUtil/StringUtil.h> - #include <Ice/ConnectionI.h> // For implementation of getConnectionInfo. -#include <openssl/crypto.h> -#include <openssl/err.h> -#include <openssl/evp.h> -#include <openssl/rand.h> -#include <openssl/ssl.h> - using namespace std; using namespace Ice; using namespace IceSSL; @@ -48,61 +33,11 @@ createIceSSL(const CommunicatorPtr& communicator, const string& name, const Stri } -static IceUtil::StaticMutex staticMutex = ICE_STATIC_MUTEX_INITIALIZER; -static int instanceCount = 0; -static IceUtil::Mutex* locks = 0; - -extern "C" -{ - -// -// OpenSSL mutex callback. -// -void -IceSSL_opensslLockCallback(int mode, int n, const char* file, int line) -{ - if(mode & CRYPTO_LOCK) - { - locks[n].lock(); - } - else - { - locks[n].unlock(); - } -} - -// -// OpenSSL thread id callback. -// -unsigned long -IceSSL_opensslThreadIdCallback() -{ -#if defined(_WIN32) - return static_cast<unsigned long>(GetCurrentThreadId()); -#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__osf1__) - // - // On some platforms, pthread_t is a pointer to a per-thread structure. - // - return reinterpret_cast<unsigned long>(pthread_self()); -#elif (defined(__linux) || defined(__sun) || defined(__hpux)) || defined(_AIX) - // - // On Linux, Solaris, HP-UX and AIX, pthread_t is an integer. - // - return static_cast<unsigned long>(pthread_self()); -#else -# error "Unknown platform" -#endif -} - -} - // // Plugin implementation. // IceSSL::PluginI::PluginI(const Ice::CommunicatorPtr& communicator) { - setupSSL(communicator); - _instance = new Instance(communicator); } @@ -117,8 +52,6 @@ IceSSL::PluginI::destroy() { _instance->destroy(); _instance = 0; - - cleanupSSL(); } void @@ -145,122 +78,6 @@ IceSSL::PluginI::setPasswordPrompt(const PasswordPromptPtr& prompt) _instance->setPasswordPrompt(prompt); } -void -IceSSL::PluginI::setupSSL(const CommunicatorPtr& communicator) -{ - // - // Initialize OpenSSL. - // - IceUtil::StaticMutex::Lock sync(staticMutex); - instanceCount++; - - if(instanceCount == 1) - { - PropertiesPtr properties = communicator->getProperties(); - - // - // Create the mutexes and set the callbacks. - // - locks = new IceUtil::Mutex[CRYPTO_num_locks()]; - CRYPTO_set_locking_callback(IceSSL_opensslLockCallback); - CRYPTO_set_id_callback(IceSSL_opensslThreadIdCallback); - - // - // Load human-readable error messages. - // - SSL_load_error_strings(); - - // - // Initialize the SSL library. - // - SSL_library_init(); - - // - // Initialize the PRNG. - // -#ifdef WINDOWS - RAND_screen(); // Uses data from the screen if possible. -#endif - char randFile[1024]; - if(RAND_file_name(randFile, sizeof(randFile))) // Gets the name of a default seed file. - { - RAND_load_file(randFile, 1024); - } - string randFiles = properties->getProperty("IceSSL.Random"); - if(!randFiles.empty()) - { - vector<string> files; -#ifdef _WIN32 - const string sep = ";"; -#else - const string sep = ":"; -#endif - string defaultDir = properties->getProperty("IceSSL.DefaultDir"); - if(!IceUtilInternal::splitString(randFiles, sep, files)) - { - PluginInitializationException ex(__FILE__, __LINE__); - ex.reason = "IceSSL: invalid value for IceSSL.Random:\n" + randFiles; - throw ex; - } - for(vector<string>::iterator p = files.begin(); p != files.end(); ++p) - { - string file = *p; - if(!checkPath(file, defaultDir, false)) - { - PluginInitializationException ex(__FILE__, __LINE__); - ex.reason = "IceSSL: entropy data file not found:\n" + file; - throw ex; - } - if(!RAND_load_file(file.c_str(), 1024)) - { - PluginInitializationException ex(__FILE__, __LINE__); - ex.reason = "IceSSL: unable to load entropy data from " + file; - throw ex; - } - } - } -#ifndef _WIN32 - // - // The Entropy Gathering Daemon (EGD) is not available on Windows. - // The file should be a Unix domain socket for the daemon. - // - string entropyDaemon = properties->getProperty("IceSSL.EntropyDaemon"); - if(!entropyDaemon.empty()) - { - if(RAND_egd(entropyDaemon.c_str()) <= 0) - { - PluginInitializationException ex(__FILE__, __LINE__); - ex.reason = "IceSSL: EGD failure using file " + entropyDaemon; - throw ex; - } - } -#endif - if(!RAND_status()) - { - communicator->getLogger()->warning("IceSSL: insufficient data to initialize PRNG"); - } - } -} - -void -IceSSL::PluginI::cleanupSSL() -{ - IceUtil::StaticMutex::Lock sync(staticMutex); - - if(--instanceCount == 0) - { - CRYPTO_set_locking_callback(0); - CRYPTO_set_id_callback(0); - delete[] locks; - locks = 0; - - CRYPTO_cleanup_all_ex_data(); - RAND_cleanup(); - ERR_free_strings(); - EVP_cleanup(); - } -} - const char* IceSSL::ConnectionInvalidException::_name = "IceSSL::ConnectionInvalidException"; ConnectionInvalidException::ConnectionInvalidException(const char* file, int line, const string& r) : diff --git a/cpp/src/IceSSL/PluginI.h b/cpp/src/IceSSL/PluginI.h index 0ede053872d..a80446d6f65 100644 --- a/cpp/src/IceSSL/PluginI.h +++ b/cpp/src/IceSSL/PluginI.h @@ -13,7 +13,6 @@ #include <IceSSL/Plugin.h> #include <IceSSL/InstanceF.h> #include <Ice/CommunicatorF.h> -#include <Ice/Plugin.h> namespace IceSSL { @@ -40,9 +39,6 @@ public: private: - void setupSSL(const Ice::CommunicatorPtr&); - void cleanupSSL(); - InstancePtr _instance; }; diff --git a/cpp/src/IceUtil/ArgVector.cpp b/cpp/src/IceUtil/ArgVector.cpp index a9f01088b6e..4f7dc1bc910 100644 --- a/cpp/src/IceUtil/ArgVector.cpp +++ b/cpp/src/IceUtil/ArgVector.cpp @@ -14,135 +14,52 @@ IceUtilInternal::ArgVector::ArgVector(int argc, char *argv[]) { assert(argc >= 0); - _noDelete = false; - copyVec(argc, argc, argv); + _args.resize(argc); + for(int i = 0; i < argc; ++i) + { + _args[i] = argv[i]; + } + setupArgcArgv(); } IceUtilInternal::ArgVector::ArgVector(const ::std::vector< ::std::string>& vec) { - _noDelete = false; - copyVec(vec); + _args = vec; + setupArgcArgv(); } IceUtilInternal::ArgVector::ArgVector(const ArgVector& rhs) { - _noDelete = false; - copyVec(rhs.argc, rhs._origArgc, rhs.argv); + _args = rhs._args; + setupArgcArgv(); } IceUtilInternal::ArgVector& IceUtilInternal::ArgVector::operator=(const ArgVector& rhs) { - ArgVector tmp(rhs); - swap(tmp); + delete[] argv; + argv = 0; + _args = rhs._args; + setupArgcArgv(); return *this; } IceUtilInternal::ArgVector::~ArgVector() { - // - // For use with putenv()--see man putenv. - // - if(!_noDelete) - { - for(int i = 0; i < _origArgc; ++i) - { - delete[] argv[i]; - } - } delete[] argv; } void -IceUtilInternal::ArgVector::setNoDelete() +IceUtilInternal::ArgVector::setupArgcArgv() { - _noDelete = true; -} - -void -IceUtilInternal::ArgVector::copyVec(int argc, int origArgc, char** argv) -{ - this->argc = argc; - this->_origArgc = origArgc; - if((this->argv = new char*[argc + 1]) == 0) - { - throw ::std::bad_alloc(); - } - for(int i = 0; i < argc; ++i) - { - try - { - if((this->argv[i] = new char[strlen(argv[i]) + 1]) == 0) - { - throw ::std::bad_alloc(); - } - } - catch(...) - { - for(int j = 0; j < i; ++j) - { - delete[] this->argv[j]; - } - delete[] this->argv; - throw; - } -#if defined(_MSC_VER) && (_MSC_VER >= 1400) - strcpy_s(this->argv[i], strlen(argv[i]) + 1, argv[i]); -#else - strcpy(this->argv[i], argv[i]); -#endif - } - this->argv[argc] = 0; -} - -void -IceUtilInternal::ArgVector::copyVec(const ::std::vector< ::std::string>& vec) -{ - argc = _origArgc = static_cast<int>(vec.size()); + argc = _args.size(); if((argv = new char*[argc + 1]) == 0) { throw ::std::bad_alloc(); } - for(int i = 0; i < argc; ++i) + for(int i = 0; i < argc; i++) { - try - { - if((argv[i] = new char[vec[i].size() + 1]) == 0) - { - throw ::std::bad_alloc(); - } - } - catch(...) - { - for(int j = 0; j < i; ++j) - { - delete[] argv[j]; - } - delete[] argv; - throw; - } -#if defined(_MSC_VER) && (_MSC_VER >= 1400) - strcpy_s(argv[i], vec[i].size() + 1, vec[i].c_str()); -#else - strcpy(argv[i], vec[i].c_str()); -#endif + argv[i] = const_cast<char*>(_args[i].c_str()); } argv[argc] = 0; } - -void -IceUtilInternal::ArgVector::swap(ArgVector& rhs) throw() -{ - int argcTmp = rhs.argc; - int origArgcTmp = rhs._origArgc; - char** argvTmp = rhs.argv; - bool noDeleteTmp = rhs._noDelete; - rhs.argc = argc; - rhs._origArgc = _origArgc; - rhs.argv = argv; - rhs._noDelete = _noDelete; - argc = argcTmp; - _origArgc = origArgcTmp; - argv = argvTmp; - _noDelete = noDeleteTmp; -} diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 089f0938713..fb7bef59d16 100755 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -156,34 +156,39 @@ Slice::Preprocessor::preprocess(bool keepComments) // Call mcpp using memory buffer. // mcpp_use_mem_buffers(1); - mcpp_lib_main(static_cast<int>(args.size()) + 1, const_cast<char**>(argv)); + int status = mcpp_lib_main(static_cast<int>(args.size()) + 1, const_cast<char**>(argv)); delete[] argv; // - // Write output to temporary file. Print errors to stderr. + // Print errors to stderr. // - string result; - char* buf = mcpp_get_mem_buffer(Out); - - _cppFile = ".preprocess." + IceUtil::generateUUID(); - SignalHandler::addFile(_cppFile); -#ifdef _WIN32 - _cppHandle = ::_wfopen(IceUtil::stringToWstring(_cppFile).c_str(), IceUtil::stringToWstring("w+").c_str()); -#else - _cppHandle = ::fopen(_cppFile.c_str(), "w+"); -#endif - if(buf) - { - ::fwrite(buf, strlen(buf), 1, _cppHandle); - } - ::rewind(_cppHandle); - char* err = mcpp_get_mem_buffer(Err); if(err) { ::fputs(err, stderr); } + if(status == 0) + { + // + // Write output to temporary file. + // + char* buf = mcpp_get_mem_buffer(Out); + + _cppFile = ".preprocess." + IceUtil::generateUUID(); + SignalHandler::addFile(_cppFile); +#ifdef _WIN32 + _cppHandle = ::_wfopen(IceUtil::stringToWstring(_cppFile).c_str(), IceUtil::stringToWstring("w+").c_str()); +#else + _cppHandle = ::fopen(_cppFile.c_str(), "w+"); +#endif + if(buf) + { + ::fwrite(buf, strlen(buf), 1, _cppHandle); + } + ::rewind(_cppHandle); + } + // // Calling this again causes the memory buffers to be freed. // @@ -217,11 +222,29 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin // Call mcpp using memory buffer. // mcpp_use_mem_buffers(1); - mcpp_lib_main(static_cast<int>(args.size() + 1), const_cast<char**>(argv)); + int status = mcpp_lib_main(static_cast<int>(args.size() + 1), const_cast<char**>(argv)); delete[] argv; // - // Get mcpp output/errors. + // Print errors to stderr. + // + char* err = mcpp_get_mem_buffer(Err); + if(err) + { + ::fputs(err, stderr); + } + + if(status != 0) + { + // + // Calling this again causes the memory buffers to be freed. + // + mcpp_use_mem_buffers(1); + return; + } + + // + // Get mcpp output. // string unprocessed; char* buf = mcpp_get_mem_buffer(Out); @@ -230,19 +253,13 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin unprocessed = string(buf); } - char* err = mcpp_get_mem_buffer(Err); - if(err) - { - ::fputs(err, stderr); - } - // // Calling this again causes the memory buffers to be freed. // mcpp_use_mem_buffers(1); // - // We now need to massage then result to get desire output. + // We now need to massage the result to get the desired output. // First make it a single line. // string::size_type pos; @@ -268,6 +285,7 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin { fullIncludePaths.push_back(fullPath(*p)); } + string absoluteFileName = fullPath(_fileName); // // Process each dependency. @@ -277,26 +295,32 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin { end += 4; string file = IceUtilInternal::trim(unprocessed.substr(pos, end - pos)); - if(isAbsolute(file)) { - // - // Transform back full paths generated by mcpp to paths relative to the specificed - // include paths. - // - string newFile = file; - for(vector<string>::const_iterator p = fullIncludePaths.begin(); p != fullIncludePaths.end(); ++p) + if(file == absoluteFileName) + { + file = _fileName; + } + else { - if(file.compare(0, p->length(), *p) == 0) + // + // Transform back full paths generated by mcpp to paths relative to the specified + // include paths. + // + string newFile = file; + for(vector<string>::const_iterator p = fullIncludePaths.begin(); p != fullIncludePaths.end(); ++p) { - string s = includePaths[p - fullIncludePaths.begin()] + file.substr(p->length()); - if(isAbsolute(newFile) || s.size() < newFile.size()) + if(file.compare(0, p->length(), *p) == 0) { - newFile = s; + string s = includePaths[p - fullIncludePaths.begin()] + file.substr(p->length()); + if(isAbsolute(newFile) || s.size() < newFile.size()) + { + newFile = s; + } } } + file = newFile; } - file = newFile; } // diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/Util.cpp index 4d6be4e1834..c9d19d80572 100644 --- a/cpp/src/Slice/Util.cpp +++ b/cpp/src/Slice/Util.cpp @@ -93,6 +93,7 @@ Slice::fullPath(const string& path) result = string(cwdbuf) + '/' + result; } } + result = normalizePath(result); string::size_type beg = 0; @@ -115,7 +116,14 @@ Slice::fullPath(const string& path) if(len > 0) { buf[len] = '\0'; - result = normalizePath(buf) + (next != string::npos ? result.substr(next) : string()); + string linkpath = buf; + if(!isAbsolute(linkpath)) // Path relative to the location of the link + { + string::size_type pos = subpath.rfind('/'); + assert(pos != string::npos); + linkpath = subpath.substr(0, pos + 1) + linkpath; + } + result = normalizePath(linkpath) + (next != string::npos ? result.substr(next) : string()); beg = 0; next = 0; } diff --git a/cpp/src/slice2html/Gen.cpp b/cpp/src/slice2html/Gen.cpp index e124e4e96df..49ae1cbd617 100644 --- a/cpp/src/slice2html/Gen.cpp +++ b/cpp/src/slice2html/Gen.cpp @@ -602,7 +602,7 @@ Slice::GeneratorBase::printSummary(const ContainedPtr& p, const ContainerPtr& mo void Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) { - ContainerPtr container = ModulePtr::dynamicCast(c) ? c->container() : ContainerPtr::dynamicCast(c); + ContainerPtr container = ContainerPtr::dynamicCast(c); string scoped = c->scoped(); ContainedList::const_iterator prev = _symbols.end(); ContainedList::const_iterator pos = _symbols.begin(); @@ -618,7 +618,23 @@ Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) bool isFirst = prev == _symbols.end(); bool isLast = next == _symbols.end(); - bool hasParent = ContainedPtr::dynamicCast(container) || EnumPtr::dynamicCast(c); + bool hasParent = false; + if(EnumPtr::dynamicCast(c)) + { + hasParent = true; + } + else if(ModulePtr::dynamicCast(c)) + { + ModulePtr m = ModulePtr::dynamicCast(c); + if(ModulePtr::dynamicCast(m->container())) + { + hasParent = true; + } + } + else if(ContainedPtr::dynamicCast(c)) + { + hasParent = true; + } bool onEnumPage = EnumPtr::dynamicCast(c); @@ -626,7 +642,23 @@ Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) string prevClass; if(!isFirst) { - prevLink = getLinkPath(*prev, container, false, onEnumPage) + ".html"; + prevLink = getLinkPath(*prev, container, ModulePtr::dynamicCast(c), onEnumPage) + ".html"; + if(ModulePtr::dynamicCast(c)) + { + // + // If we are writing the header/footer for a module page, + // and the target is up from the current scope, + // we need to step up an extra level because modules + // are documented one directory up, at the same level as + // the module directory. + // + StringList source = getContainer(c); + StringList target = getContainer(*prev); + if(target.size() < source.size()) + { + prevLink = "../" + prevLink; + } + } prevClass = "Button"; } else @@ -638,7 +670,23 @@ Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) string nextClass; if(!isLast) { - nextLink = getLinkPath(*next, container, false, onEnumPage) + ".html"; + nextLink = getLinkPath(*next, container, ModulePtr::dynamicCast(c), onEnumPage) + ".html"; + if(ModulePtr::dynamicCast(c)) + { + // + // If we are writing the header/footer for a module page, + // and the target is up from the current scope, + // we need to step up an extra level because modules + // are documented one directory up, at the same level as + // the module directory. + // + StringList source = getContainer(c); + StringList target = getContainer(*next); + if(target.size() < source.size()) + { + nextLink = "../" + nextLink; + } + } nextClass = "Button"; } else @@ -650,7 +698,7 @@ Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) string upClass; if(hasParent) { - upLink = getLinkPath(c->container(), container, ModulePtr::dynamicCast(c), onEnumPage) + ".html"; + upLink = getLinkPath(c->container(), container, false, onEnumPage) + ".html"; upClass = "Button"; } else @@ -658,14 +706,14 @@ Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) upClass = "ButtonGrey"; } - string homeLink = getLinkPath(0, container, ModulePtr::dynamicCast(c), onEnumPage); + string homeLink = getLinkPath(0, container, false, onEnumPage); if(!homeLink.empty()) { homeLink += "/"; } homeLink += "index.html"; - string indexLink = getLinkPath(0, container, ModulePtr::dynamicCast(c), onEnumPage); + string indexLink = getLinkPath(0, container, false, onEnumPage); if(!indexLink.empty()) { indexLink += "/"; @@ -683,7 +731,7 @@ Slice::GeneratorBase::printHeaderFooter(const ContainedPtr& c) if(!imageDir.empty()) { - string path = getLinkPath(0, container, ModulePtr::dynamicCast(c), onEnumPage); + string path = getLinkPath(0, container, false, onEnumPage); if(!path.empty()) { path += "/"; @@ -802,7 +850,7 @@ Slice::GeneratorBase::printLogo(const ContainedPtr& c, const ContainerPtr& conta string imageDir = getImageDir(); if(!imageDir.empty()) { - string path = getLinkPath(0, container, ModulePtr::dynamicCast(c), forEnum); + string path = getLinkPath(0, container, false, forEnum); if(!path.empty()) { path += "/"; |