diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/IceBox/.dummy | 1 | ||||
-rw-r--r-- | cpp/include/IcePatch/.dummy | 1 | ||||
-rw-r--r-- | cpp/slice/IcePatch/Node.ice | 10 | ||||
-rw-r--r-- | cpp/src/IcePatch/.depend | 4 | ||||
-rw-r--r-- | cpp/src/IcePatch/Makefile | 50 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeI.cpp | 71 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeI.h | 45 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeLocator.cpp | 62 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeLocator.h | 33 | ||||
-rw-r--r-- | cpp/src/IcePatch/Server.cpp | 115 |
10 files changed, 389 insertions, 3 deletions
diff --git a/cpp/include/IceBox/.dummy b/cpp/include/IceBox/.dummy new file mode 100644 index 00000000000..7db85338c70 --- /dev/null +++ b/cpp/include/IceBox/.dummy @@ -0,0 +1 @@ +Dummy file, so that `cvs export' creates this otherwise empty directory
\ No newline at end of file diff --git a/cpp/include/IcePatch/.dummy b/cpp/include/IcePatch/.dummy new file mode 100644 index 00000000000..7db85338c70 --- /dev/null +++ b/cpp/include/IcePatch/.dummy @@ -0,0 +1 @@ +Dummy file, so that `cvs export' creates this otherwise empty directory
\ No newline at end of file diff --git a/cpp/slice/IcePatch/Node.ice b/cpp/slice/IcePatch/Node.ice index 60870de4294..80216427686 100644 --- a/cpp/slice/IcePatch/Node.ice +++ b/cpp/slice/IcePatch/Node.ice @@ -13,6 +13,9 @@ #include <Ice/BuiltinSequences.ice> +module IcePatch +{ + exception NodeAccessException { string reason; @@ -20,10 +23,9 @@ exception NodeAccessException interface Node { - string getPath(); }; -sequence<Node> Nodes; +sequence<Node*> Nodes; interface Directory extends Node { @@ -33,9 +35,11 @@ interface Directory extends Node interface File extends Node { - Ice::ByteSeq getChunk(int chunkSize, int n) + Ice::ByteSeq getBytes(int startPos, int howMuch) throws NodeAccessException; }; +}; + #endif diff --git a/cpp/src/IcePatch/.depend b/cpp/src/IcePatch/.depend index e69de29bb2d..1bf64da96ee 100644 --- a/cpp/src/IcePatch/.depend +++ b/cpp/src/IcePatch/.depend @@ -0,0 +1,4 @@ +Node.o: Node.cpp ../../include/Ice/Stream.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h ../../include/IcePatch/Node.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ObjectFactory.h +Server.o: Server.cpp ../../include/Ice/Application.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../IcePatch/NodeLocator.h ../IcePatch/NodeI.h ../../include/IcePatch/Node.h +NodeI.o: NodeI.cpp ../IcePatch/NodeI.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/Node.h +NodeLocator.o: NodeLocator.cpp ../IcePatch/NodeLocator.h ../IcePatch/NodeI.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/Node.h diff --git a/cpp/src/IcePatch/Makefile b/cpp/src/IcePatch/Makefile new file mode 100644 index 00000000000..a880e1291c7 --- /dev/null +++ b/cpp/src/IcePatch/Makefile @@ -0,0 +1,50 @@ +#********************************************************************** +# +# Copyright (c) 2002 +# MutableRealms, Inc. +# Huntsville, AL, USA +# +# All Rights Reserved +# +# ********************************************************************** + +top_srcdir = ../.. + +SERVER = $(top_srcdir)/bin/icepatch + +TARGETS = $(SERVER) + +OBJS = Node.o + +SOBJS = Server.o \ + NodeI.o \ + NodeLocator.o + +COBJS = + +SRCS = $(OBJS:.o=.cpp) \ + $(COBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) + +HDIR = $(includedir)/IcePatch +SDIR = $(slicedir)/IcePatch +SLICECMD = $(SLICE2CPP) --include-dir IcePatch -I$(slicedir) +SLICE2FREEZECMD = $(SLICE2FREEZE) --include-dir IcePatch -I$(slicedir) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I.. $(CPPFLAGS) + +$(SERVER): $(OBJS) $(SOBJS) + rm -f $@ + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(SOBJS) $(LIBS) + +$(HDIR)/Node.h Node.cpp: $(SDIR)/Node.ice $(SLICE2CPP) + rm -f $(HDIR)/Node.h Node.cpp + $(SLICECMD) $(SDIR)/Node.ice + mv Node.h $(HDIR) + +clean:: + rm -f $(HDIR)/Node.h Node.cpp + +include .depend diff --git a/cpp/src/IcePatch/NodeI.cpp b/cpp/src/IcePatch/NodeI.cpp new file mode 100644 index 00000000000..0c41b31f562 --- /dev/null +++ b/cpp/src/IcePatch/NodeI.cpp @@ -0,0 +1,71 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <IcePatch/NodeI.h> + +using namespace std; +using namespace Ice; +using namespace IcePatch; + +string +IcePatch::NodeI::normalizePath(const string& path) +{ + string result = path; + + string::size_type pos; + + for (pos = 0; pos < result.size(); ++pos) + { + if (result[pos] == '\\') + { + result[pos] = '/'; + } + } + + pos = 0; + while ((pos = result.find("//", pos)) != string::npos) + { + result.erase(pos, 1); + } + + pos = 0; + while ((pos = result.find("/./", pos)) != string::npos) + { + result.erase(pos, 2); + } + + return result; +} + +Nodes +IcePatch::DirectoryI::getNodes(const Ice::Current& current) +{ + // + // No synchronization necessary, this servant is completely + // stateless. + // + + string path = normalizePath(current.identity.name); + + return Nodes(); +} + +ByteSeq +IcePatch::FileI::getBytes(Int startPos, Int howMuch, const Ice::Current& current) +{ + // + // No synchronization necessary, this servant is completely + // stateless. + // + + string path = normalizePath(current.identity.name); + + return ByteSeq(); +} diff --git a/cpp/src/IcePatch/NodeI.h b/cpp/src/IcePatch/NodeI.h new file mode 100644 index 00000000000..e2fde84d374 --- /dev/null +++ b/cpp/src/IcePatch/NodeI.h @@ -0,0 +1,45 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef ICE_PATCH_NODE_I_H +#define ICE_PATCH_NODE_I_H + +#include <Ice/Ice.h> +#include <IcePatch/Node.h> + +namespace IcePatch +{ + +class NodeI : virtual public Node +{ +public: + + static std::string normalizePath(const std::string&); +}; + +class DirectoryI : virtual public Directory, + virtual public NodeI +{ +public: + + virtual Nodes getNodes(const Ice::Current&); +}; + +class FileI : virtual public File, + virtual public NodeI +{ +public: + + virtual Ice::ByteSeq getBytes(Ice::Int, Ice::Int, const Ice::Current&); +}; + +} + +#endif diff --git a/cpp/src/IcePatch/NodeLocator.cpp b/cpp/src/IcePatch/NodeLocator.cpp new file mode 100644 index 00000000000..91bea186cc4 --- /dev/null +++ b/cpp/src/IcePatch/NodeLocator.cpp @@ -0,0 +1,62 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <IcePatch/NodeLocator.h> + +using namespace std; +using namespace Ice; +using namespace IcePatch; + + +ObjectPtr +IcePatch::NodeLocator::locate(const ObjectAdapterPtr&, const Current& current, LocalObjectPtr&) +{ + assert(current.identity.category == "IcePack"); + + // + // Check whether the path (= identity.name) is valid. + // + string path = current.identity.name; + + if (path.empty()) + { + return 0; + } + + if (path[0] == '/') // Path must not start with '/'. + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + + if (path.find("..") != string::npos) // Path must not contain '..'. + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + + if (path.find(':') == 1) // Path cannot contain ':' as second character. + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + + return 0; +} + +void +IcePatch::NodeLocator::finished(const ObjectAdapterPtr&, const Current& current, const ObjectPtr&, + const LocalObjectPtr&) +{ + // Nothing to do. +} + +void +IcePatch::NodeLocator::deactivate() +{ + // Nothing to do. +} diff --git a/cpp/src/IcePatch/NodeLocator.h b/cpp/src/IcePatch/NodeLocator.h new file mode 100644 index 00000000000..f25578ed6e1 --- /dev/null +++ b/cpp/src/IcePatch/NodeLocator.h @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef ICE_PATCH_NODE_LOCATOR_H +#define ICE_PATCH_NODE_LOCATOR_H + +#include <IcePatch/NodeI.h> + +namespace IcePatch +{ + +class NodeLocator: virtual public Ice::ServantLocator +{ +public: + + virtual Ice::ObjectPtr locate(const Ice::ObjectAdapterPtr&, const Ice::Current&, Ice::LocalObjectPtr&); + + virtual void finished(const Ice::ObjectAdapterPtr&, const Ice::Current&, const Ice::ObjectPtr&, + const Ice::LocalObjectPtr&); + + virtual void deactivate(); +}; + +} + +#endif diff --git a/cpp/src/IcePatch/Server.cpp b/cpp/src/IcePatch/Server.cpp new file mode 100644 index 00000000000..467655e7fa7 --- /dev/null +++ b/cpp/src/IcePatch/Server.cpp @@ -0,0 +1,115 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Application.h> +#include <IcePatch/NodeLocator.h> + +using namespace std; +using namespace Ice; +using namespace IcePatch; + +namespace IcePatch +{ + +class Server : public Application +{ +public: + + void usage(); + virtual int run(int, char*[]); +}; + +}; + +void +IcePatch::Server::usage() +{ + cerr << "Usage: " << appName() << " [options]\n"; + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display the Ice version.\n" + ; +} + +int +IcePatch::Server::run(int argc, char* argv[]) +{ + for (int i = 1; i < argc; ++i) + { + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) + { + usage(); + return EXIT_SUCCESS; + } + else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) + { + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; + } + else + { + cerr << appName() << ": unknown option `" << argv[i] << "'" << endl; + usage(); + return EXIT_FAILURE; + } + } + + PropertiesPtr properties = communicator()->getProperties(); + + // + // Get the working directory and change to this directory. + // + const char* directoryProperty = "IcePatch.Directory"; + string directory = properties->getProperty(directoryProperty); + if (directory.empty()) + { + cerr << appName() << ": property `" << directoryProperty << "' is not set" << endl; + return EXIT_FAILURE; + } + if(chdir(directory.c_str()) == -1) + { + cerr << appName() << ": can't change to directory `" << directory << "': " << strerror(errno) << endl; + return EXIT_FAILURE; + } + + // + // Initialize Object Adapter + // + const char* endpointsProperty = "IcePatch.Endpoints"; + string endpoints = properties->getProperty(endpointsProperty); + if (endpoints.empty()) + { + cerr << appName() << ": property `" << endpointsProperty << "' is not set" << endl; + return EXIT_FAILURE; + } + ObjectAdapterPtr adapter = communicator()->createObjectAdapterFromProperty("IcePatch", endpointsProperty); + + // + // Create and add the node locator. + // + ServantLocatorPtr nodeLocator = new NodeLocator; + adapter->addServantLocator(nodeLocator, "IcePatch"); + + // + // We're done, let's wait for shutdown. + // + communicator()->waitForShutdown(); + + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + addArgumentPrefix("IcePatch"); + Server app; + return app.main(argc, argv); +} |