summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2002-04-03 21:22:52 +0000
committerMarc Laukien <marc@zeroc.com>2002-04-03 21:22:52 +0000
commit4178ad80a3978cfbd2f53a7e47bf0120ded7d4d5 (patch)
tree94813a418f0973f780a2620d70e975a97bfc8b6d /cpp/src
parentstarted with IcePatch (diff)
downloadice-4178ad80a3978cfbd2f53a7e47bf0120ded7d4d5.tar.bz2
ice-4178ad80a3978cfbd2f53a7e47bf0120ded7d4d5.tar.xz
ice-4178ad80a3978cfbd2f53a7e47bf0120ded7d4d5.zip
started with IcePatch
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IcePatch/.depend4
-rw-r--r--cpp/src/IcePatch/Makefile50
-rw-r--r--cpp/src/IcePatch/NodeI.cpp71
-rw-r--r--cpp/src/IcePatch/NodeI.h45
-rw-r--r--cpp/src/IcePatch/NodeLocator.cpp62
-rw-r--r--cpp/src/IcePatch/NodeLocator.h33
-rw-r--r--cpp/src/IcePatch/Server.cpp115
7 files changed, 380 insertions, 0 deletions
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);
+}