diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IcePatch/Client.cpp | 76 | ||||
-rw-r--r-- | cpp/src/IcePatch/IcePatchI.cpp | 36 | ||||
-rw-r--r-- | cpp/src/IcePatch/IcePatchI.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePatch/Makefile | 2 |
4 files changed, 106 insertions, 10 deletions
diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp index fa9093b2882..e75fdf1cfff 100644 --- a/cpp/src/IcePatch/Client.cpp +++ b/cpp/src/IcePatch/Client.cpp @@ -9,8 +9,13 @@ // ********************************************************************** #include <Ice/Application.h> +#include <Glacier/Glacier.h> #include <IcePatch/FileDescFactory.h> #include <IcePatch/Util.h> +#include <Glacier/Glacier.h> +#include <IceUtil/Base64.h> +#include <Ice/System.h> +#include <Ice/SslExtension.h> #include <iomanip> using namespace std; @@ -72,6 +77,77 @@ IcePatch::Client::run(int argc, char* argv[]) PropertiesPtr properties = communicator()->getProperties(); // + // Do Glacier setup, if so requested. + // + const char* glacierStarterEndpointsProperty = "Glacier.Starter.Endpoints"; + string glacierStarterEndpoints = properties->getProperty(glacierStarterEndpointsProperty); + if (!glacierStarterEndpoints.empty()) + { + ObjectPrx starterBase = communicator()->stringToProxy("Glacier/starter:" + glacierStarterEndpoints); + Glacier::StarterPrx starter = Glacier::StarterPrx::checkedCast(starterBase); + if (!starter) + { + cerr << appName() << ": endpoints `" << glacierStarterEndpoints + << "' do not refer to a glacier router starter" << endl; + return EXIT_FAILURE; + } + + ByteSeq privateKey; + ByteSeq publicKey; + ByteSeq routerCert; + + RouterPrx router; + while (!router) + { + string id; + string pw; + + cout << "user id: " << flush; + cin >> id; + cout << "password: " << flush; + cin >> pw; + + try + { + router = starter->startRouter(id, pw, privateKey, publicKey, routerCert); + } + catch (const Glacier::CannotStartRouterException& ex) + { + cerr << appName() << ": " << ex << ":\n" << ex.reason << endl; + return EXIT_FAILURE; + } + catch (const Glacier::InvalidPasswordException&) + { + cout << "password is invalid, try again" << endl; + } + } + + string clientConfig = properties->getProperty("Ice.SSL.Client.Config"); + string serverConfig = properties->getProperty("Ice.SSL.Server.Config"); + + if (!clientConfig.empty() && !serverConfig.empty()) + { + string privateKeyBase64 = IceUtil::Base64::encode(privateKey); + string publicKeyBase64 = IceUtil::Base64::encode(publicKey); + string routerCertString = IceUtil::Base64::encode(routerCert); + + IceSSL::SystemPtr sslSystem = communicator()->getSslSystem(); + IceSSL::SslExtensionPtr sslExtension = communicator()->getSslExtension(); + + // Configure Server, client is already configured. + sslSystem->configure(IceSSL::Server); + sslSystem->setCertificateVerifier(IceSSL::ClientServer, + sslExtension->getSingleCertVerifier(routerCert)); + + // Set the keys overrides. + sslSystem->setRSAKeysBase64(IceSSL::ClientServer, privateKeyBase64, publicKeyBase64); + sslSystem->addTrustedCertificateBase64(IceSSL::ClientServer, routerCertString); + } + + communicator()->setDefaultRouter(router); + } + + // // Get the IcePatch endpoints. // const char* endpointsProperty = "IcePatch.Endpoints"; diff --git a/cpp/src/IcePatch/IcePatchI.cpp b/cpp/src/IcePatch/IcePatchI.cpp index ead1b2d925f..c059b450679 100644 --- a/cpp/src/IcePatch/IcePatchI.cpp +++ b/cpp/src/IcePatch/IcePatchI.cpp @@ -18,8 +18,10 @@ using namespace IcePatch; IceUtil::RWRecMutex IcePatch::FileI::_globalMutex; IcePatch::FileI::FileI(const ObjectAdapterPtr& adapter) : - _adapter(adapter) + _adapter(adapter), + _logger(adapter->getCommunicator()->getLogger()) { + _traceLevel = atoi(adapter->getCommunicator()->getProperties()->getProperty("IcePatch.Trace.Files").c_str()); } IcePatch::DirectoryI::DirectoryI(const ObjectAdapterPtr& adapter) : @@ -61,9 +63,13 @@ IcePatch::DirectoryI::getContents(const Ice::Current& current) equal_range(paths2.begin(), paths2.end(), removeSuffix(*p)); if (r2.first == r2.second) { - cout << "removing orphaned file `" << *p << "'... " << flush; removeRecursive(*p); - cout << "ok" << endl; + + if (_traceLevel > 0) + { + Trace out(_logger, "IcePatch"); + out << "removed orphaned file `" << *p << "'"; + } } } } @@ -117,9 +123,13 @@ IcePatch::RegularI::describe(const Ice::Current& current) infoMD5 = getFileInfo(path + ".md5", false); if (infoMD5.type != FileTypeRegular || infoMD5.time < info.time) { - cout << "creating .md5 file for `" << path << "'... " << flush; createMD5(path); - cout << "ok" << endl; + + if (_traceLevel > 0) + { + Trace out(_logger, "IcePatch"); + out << "created .md5 file for `" << path << "'"; + } } } @@ -143,9 +153,13 @@ IcePatch::RegularI::getBZ2Size(const Ice::Current& current) infoBZ2 = getFileInfo(path + ".bz2", false); if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) { - cout << "creating .bz2 file for `" << path << "'... " << flush; createBZ2(path); - cout << "ok" << endl; + + if (_traceLevel > 0) + { + Trace out(_logger, "IcePatch"); + out << "created .bz2 file for `" << path << "'"; + } // Get the .bz2 file info again, so that we can return the // size below. This time the .bz2 file must exist, @@ -171,9 +185,13 @@ IcePatch::RegularI::getBZ2(Ice::Int pos, Ice::Int num, const Ice::Current& curre infoBZ2 = getFileInfo(path + ".bz2", false); if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) { - cout << "creating .bz2 file for `" << path << "'... " << flush; createBZ2(path); - cout << "ok" << endl; + + if (_traceLevel > 0) + { + Trace out(_logger, "IcePatch"); + out << "created .bz2 file for `" << path << "'"; + } } } diff --git a/cpp/src/IcePatch/IcePatchI.h b/cpp/src/IcePatch/IcePatchI.h index a395c84cbaf..9b98b614e15 100644 --- a/cpp/src/IcePatch/IcePatchI.h +++ b/cpp/src/IcePatch/IcePatchI.h @@ -27,6 +27,8 @@ public: protected: Ice::ObjectAdapterPtr _adapter; + Ice::LoggerPtr _logger; + Ice::Int _traceLevel; static IceUtil::RWRecMutex _globalMutex; }; diff --git a/cpp/src/IcePatch/Makefile b/cpp/src/IcePatch/Makefile index e205676ce38..ff396e9397b 100644 --- a/cpp/src/IcePatch/Makefile +++ b/cpp/src/IcePatch/Makefile @@ -62,7 +62,7 @@ $(NAME): $(VERSIONED_NAME) $(CLIENT): $(COBJS) rm -f $@ - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(COBJS) -lIcePatch $(LIBS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(COBJS) -lIcePatch -lGlacier $(LIBS) $(SERVER): $(SOBJS) rm -f $@ |