/// <summary> /// Wraps encoded data with an input stream for dynamic invocation and dispatch. /// The stream uses the given encoding version. /// </summary> /// <param name="communicator">The communicator for the stream.</param> /// <param name="bytes">An encoded request or reply.</param> /// <param name="v">The desired encoding version.</param> /// <returns>The input stream.</returns> public static InputStream wrapInputStream(Communicator communicator, byte[] bytes, EncodingVersion v) { return new InputStreamI(communicator, bytes, v, false); }
public void startEncapsulation(EncodingVersion encoding, FormatType format) { _os.startWriteEncaps(encoding, format); }
private bool validate(int operation) { if(!_endpoint.datagram()) // Datagram connections are always implicitly validated. { if(_adapter != null) // The server side has the active role for connection validation. { if(_writeStream.size() == 0) { _writeStream.writeBlob(IceInternal.Protocol.magic); Ice.Util.currentProtocol.write__(_writeStream); Ice.Util.currentProtocolEncoding.write__(_writeStream); _writeStream.writeByte(IceInternal.Protocol.validateConnectionMsg); _writeStream.writeByte((byte)0); // Compression status (always zero for validate connection). _writeStream.writeInt(IceInternal.Protocol.headerSize); // Message size. IceInternal.TraceUtil.traceSend(_writeStream, _logger, _traceLevels); _writeStream.prepareWrite(); } if(_observer != null) { observerStartWrite(_writeStream.pos()); } if(_writeStream.pos() != _writeStream.size() && !_transceiver.write(_writeStream.getBuffer())) { scheduleTimeout(IceInternal.SocketOperation.Write, connectTimeout()); _threadPool.update(this, operation, IceInternal.SocketOperation.Write); return false; } if(_observer != null) { observerFinishWrite(_writeStream.pos()); } } else // The client side has the passive role for connection validation. { if(_readStream.size() == 0) { _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); } if(_observer != null) { observerStartRead(_readStream.pos()); } if(_readStream.pos() != _readStream.size() && !_transceiver.read(_readStream.getBuffer())) { scheduleTimeout(IceInternal.SocketOperation.Read, connectTimeout()); _threadPool.update(this, operation, IceInternal.SocketOperation.Read); return false; } if(_observer != null) { observerFinishRead(_readStream.pos()); } Debug.Assert(_readStream.pos() == IceInternal.Protocol.headerSize); _readStream.pos(0); byte[] m = _readStream.readBlob(4); if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { BadMagicException ex = new BadMagicException(); ex.badMagic = m; throw ex; } ProtocolVersion pv = new ProtocolVersion(); pv.read__(_readStream); IceInternal.Protocol.checkSupportedProtocol(pv); EncodingVersion ev = new EncodingVersion(); ev.read__(_readStream); IceInternal.Protocol.checkSupportedProtocolEncoding(ev); byte messageType = _readStream.readByte(); if(messageType != IceInternal.Protocol.validateConnectionMsg) { throw new ConnectionNotValidatedException(); } _readStream.readByte(); // Ignore compression status for validate connection. int size = _readStream.readInt(); if(size != IceInternal.Protocol.headerSize) { throw new IllegalMessageSizeException(); } IceInternal.TraceUtil.traceRecv(_readStream, _logger, _traceLevels); _validated = true; } } _writeStream.resize(0, false); _writeStream.pos(0); _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; return true; }
private void initialize(EncodingVersion encoding) { instance_ = null; _encoding = encoding; _encapsStack = null; _encapsCache = null; _traceSlicing = false; _closure = null; _sliceValues = true; _startSeq = -1; _minSeqSize = 0; }
public static Test.IMyClassPrx allTests(global::Test.TestHelper helper) { var communicator = helper.communicator(); var output = helper.getWriter(); output.Write("testing stringToProxy... "); output.Flush(); string rf = "test:" + helper.getTestEndpoint(0); var baseProxy = IObjectPrx.Parse(rf, communicator); test(baseProxy != null); var b1 = IObjectPrx.Parse("test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("test ", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test ", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse(" test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("'test -f facet'", communicator); test(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("\"test -f facet'", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("\"test -f facet\"", communicator); test(b1.Identity.Name.Equals("test -f facet") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test\"", communicator); test(b1.Identity.Name.Equals("test -f facet@test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); b1 = IObjectPrx.Parse("\"test -f facet@test @test\"", communicator); test(b1.Identity.Name.Equals("test -f facet@test @test") && b1.Identity.Category.Length == 0 && b1.Facet.Length == 0); try { b1 = IObjectPrx.Parse("test test", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\040test", communicator); test(b1.Identity.Name.Equals("test test") && b1.Identity.Category.Length == 0); try { b1 = IObjectPrx.Parse("test\\777", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test\\40test", communicator); test(b1.Identity.Name.Equals("test test")); // Test some octal and hex corner cases. b1 = IObjectPrx.Parse("test\\4test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\04test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\004test", communicator); test(b1.Identity.Name.Equals("test\u0004test")); b1 = IObjectPrx.Parse("test\\1114test", communicator); test(b1.Identity.Name.Equals("test\u00494test")); b1 = IObjectPrx.Parse("test\\b\\f\\n\\r\\t\\'\\\"\\\\test", communicator); test(b1.Identity.Name.Equals("test\b\f\n\r\t\'\"\\test") && b1.Identity.Category.Length == 0); b1 = IObjectPrx.Parse("category/test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test:tcp --sourceAddress \"::1\"", communicator); test(b1.Equals(IObjectPrx.Parse(b1.ToString(), communicator))); b1 = IObjectPrx.Parse("test:udp --sourceAddress \"::1\" --interface \"0:0:0:0:0:0:0:1%lo\"", communicator); test(b1.Equals(IObjectPrx.Parse(b1.ToString(), communicator))); try { b1 = IObjectPrx.Parse("", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("\"\"", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("\"\" test", communicator); // Invalid trailing characters. test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("test:", communicator); // Missing endpoint. test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Equals("adapter")); try { b1 = IObjectPrx.Parse("id@adapter test", communicator); test(false); } catch (ArgumentException) { } b1 = IObjectPrx.Parse("category/test@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("category/test@adapter:tcp", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter:tcp")); b1 = IObjectPrx.Parse("'category 1/test'@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category 1") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test 1'@adapter", communicator); test(b1.Identity.Name.Equals("test 1") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("'category/test'@'adapter 1'", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category") && b1.AdapterId.Equals("adapter 1")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@adapter", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") && b1.AdapterId.Equals("adapter")); b1 = IObjectPrx.Parse("\"category \\/test@foo/test\"@\"adapter:tcp\"", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Equals("category /test@foo") && b1.AdapterId.Equals("adapter:tcp")); b1 = IObjectPrx.Parse("id -f facet", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet")); b1 = IObjectPrx.Parse("id -f 'facet x'", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet x")); b1 = IObjectPrx.Parse("id -f \"facet x\"", communicator); test(b1.Identity.Name.Equals("id") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet x")); try { b1 = IObjectPrx.Parse("id -f \"facet x", communicator); test(false); } catch (FormatException) { } try { b1 = IObjectPrx.Parse("id -f \'facet x", communicator); test(false); } catch (FormatException) { } b1 = IObjectPrx.Parse("test -f facet:tcp", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f \"facet:tcp\"", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet:tcp") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f facet@test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet") && b1.AdapterId.Equals("test")); b1 = IObjectPrx.Parse("test -f 'facet@test'", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet@test") && b1.AdapterId.Length == 0); b1 = IObjectPrx.Parse("test -f 'facet@test'@test", communicator); test(b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.Facet.Equals("facet@test") && b1.AdapterId.Equals("test")); try { b1 = IObjectPrx.Parse("test -f facet@test @test", communicator); test(false); } catch (ArgumentException) { } b1 = IObjectPrx.Parse("test", communicator); test(!b1.IsOneway); b1 = IObjectPrx.Parse("test -t", communicator); test(!b1.IsOneway); b1 = IObjectPrx.Parse("test -o", communicator); test(b1.IsOneway); b1 = IObjectPrx.Parse("test -O", communicator); test(b1.InvocationMode == InvocationMode.BatchOneway); b1 = IObjectPrx.Parse("test -d", communicator); test(b1.InvocationMode == InvocationMode.Datagram); b1 = IObjectPrx.Parse("test -D", communicator); test(b1.InvocationMode == InvocationMode.BatchDatagram); b1 = IObjectPrx.Parse("test", communicator); test(!b1.IsSecure); b1 = IObjectPrx.Parse("test -s", communicator); test(b1.IsSecure); test(b1.EncodingVersion.Equals(Util.CurrentEncoding)); b1 = IObjectPrx.Parse("test -e 1.0", communicator); test(b1.EncodingVersion.Major == 1 && b1.EncodingVersion.Minor == 0); b1 = IObjectPrx.Parse("test -e 6.5", communicator); test(b1.EncodingVersion.Major == 6 && b1.EncodingVersion.Minor == 5); b1 = IObjectPrx.Parse("test -p 1.0 -e 1.0", communicator); test(b1.ToString().Equals("test -t -e 1.0")); b1 = IObjectPrx.Parse("test -p 6.5 -e 1.0", communicator); test(b1.ToString().Equals("test -t -p 6.5 -e 1.0")); try { IObjectPrx.Parse("test:tcp@adapterId", communicator); test(false); } catch (FormatException) { } // This is an unknown endpoint warning, not a parse exception. // //try //{ // b1 = communicator.stringToProxy("test -f the:facet:tcp"); // test(false); //} //catch(EndpointParseException) //{ //} try { IObjectPrx.Parse("test: :tcp", communicator); test(false); } catch (FormatException) { } // // Test invalid endpoint syntax // try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", " : "); test(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", "tcp: "); test(false); } catch (FormatException) { } try { communicator.CreateObjectAdapterWithEndpoints("BadAdapter", ":tcp"); test(false); } catch (FormatException) { } // // Test for bug ICE-5543: escaped escapes in stringToIdentity // var id = new Identity("test", ",X2QNUAzSBcJ_e$AV;E\\"); var id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); test(id.Equals(id2)); id = new Identity("test", ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\"); id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); test(id.Equals(id2)); id = new Identity("/test", "cat/"); string idStr = id.ToString(communicator.ToStringMode); test(idStr == "cat\\//\\/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); // Input string with various pitfalls id = Identity.Parse("\\342\\x82\\254\\60\\x9\\60\\"); test(id.Name == "€0\t0\\" && id.Category == ""); try { // Illegal character < 32 id = Identity.Parse("xx\01FooBar"); test(false); } catch (FormatException) { } try { // Illegal surrogate id = Identity.Parse("xx\\ud911"); test(false); } catch (FormatException) { } // Testing bytes 127(\x7F, \177) and € id = new Identity("test", "\x7f€"); idStr = id.ToString(ToStringMode.Unicode); test(idStr == "\\u007f€/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); test(id.ToString() == idStr); idStr = id.ToString(ToStringMode.ASCII); test(idStr == "\\u007f\\u20ac/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.Compat); test(idStr == "\\177\\342\\202\\254/test"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); id2 = Identity.Parse(id.ToString(communicator.ToStringMode)); test(id.Equals(id2)); // More unicode character id = new Identity("banana \x0E-\ud83c\udf4c\u20ac\u00a2\u0024", "greek \ud800\udd6a"); idStr = id.ToString(ToStringMode.Unicode); test(idStr == "greek \ud800\udd6a/banana \\u000e-\ud83c\udf4c\u20ac\u00a2$"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.ASCII); test(idStr == "greek \\U0001016a/banana \\u000e-\\U0001f34c\\u20ac\\u00a2$"); id2 = Identity.Parse(idStr); test(id.Equals(id2)); idStr = id.ToString(ToStringMode.Compat); id2 = Identity.Parse(idStr); test(idStr == "greek \\360\\220\\205\\252/banana \\016-\\360\\237\\215\\214\\342\\202\\254\\302\\242$"); test(id.Equals(id2)); output.WriteLine("ok"); output.Write("testing proxyToString... "); output.Flush(); b1 = IObjectPrx.Parse(rf, communicator); var b2 = IObjectPrx.Parse(b1.ToString(), communicator); test(b1.Equals(b2)); if (b1.GetConnection() != null) // not colloc-optimized target { b2 = b1.GetConnection().CreateProxy(Identity.Parse("fixed"), IObjectPrx.Factory); string str = b2.ToString(); test(b2.ToString() == str); string str2 = b1.Clone(b2.Identity).Clone(secure: b2.IsSecure).ToString(); // Verify that the stringified fixed proxy is the same as a regular stringified proxy // but without endpoints test(str2.StartsWith(str)); test(str2[str.Length] == ':'); } output.WriteLine("ok"); output.Write("testing propertyToProxy... "); output.Flush(); string propertyPrefix = "Foo.Proxy"; communicator.SetProperty(propertyPrefix, "test:" + helper.getTestEndpoint(0)); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.Identity.Name.Equals("test") && b1.Identity.Category.Length == 0 && b1.AdapterId.Length == 0 && b1.Facet.Length == 0); string property; property = propertyPrefix + ".Locator"; test(b1.Locator == null); communicator.SetProperty(property, "locator:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator")); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; test(b1.LocatorCacheTimeout == -1); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.LocatorCacheTimeout == 1); communicator.SetProperty(property, ""); // Now retest with an indirect proxy. communicator.SetProperty(propertyPrefix, "test"); property = propertyPrefix + ".Locator"; communicator.SetProperty(property, "locator:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.Locator != null && b1.Locator.Identity.Name.Equals("locator")); communicator.SetProperty(property, ""); property = propertyPrefix + ".LocatorCacheTimeout"; test(b1.LocatorCacheTimeout == -1); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1 != null && b1.LocatorCacheTimeout == 1); communicator.SetProperty(property, ""); // This cannot be tested so easily because the property is cached // on communicator initialization. // //communicator.SetProperty("Default.LocatorCacheTimeout", "60"); //b1 = communicator.propertyToProxy(propertyPrefix); //test(b1.LocatorCacheTimeout == 60); //communicator.SetProperty("Default.LocatorCacheTimeout", ""); communicator.SetProperty(propertyPrefix, "test:" + helper.getTestEndpoint(0)); property = propertyPrefix + ".Router"; test(b1.Router == null); communicator.SetProperty(property, "router:default -p 10000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.Router != null && b1.Router.Identity.Name.Equals("router")); communicator.RemoveProperty(property); property = propertyPrefix + ".PreferSecure"; test(!b1.IsPreferSecure); communicator.SetProperty(property, "1"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.IsPreferSecure); communicator.RemoveProperty(property); property = propertyPrefix + ".ConnectionCached"; test(b1.IsConnectionCached); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(!b1.IsConnectionCached); communicator.RemoveProperty(property); property = propertyPrefix + ".InvocationTimeout"; test(b1.InvocationTimeout == -1); communicator.SetProperty(property, "1000"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.InvocationTimeout == 1000); communicator.RemoveProperty(property); property = propertyPrefix + ".EndpointSelection"; test(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Random"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.EndpointSelection == EndpointSelectionType.Random); communicator.SetProperty(property, "Ordered"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.EndpointSelection == EndpointSelectionType.Ordered); communicator.RemoveProperty(property); property = propertyPrefix + ".CollocationOptimized"; test(b1.IsCollocationOptimized); communicator.SetProperty(property, "0"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(!b1.IsCollocationOptimized); communicator.RemoveProperty(property); property = propertyPrefix + ".Context.c1"; test(!b1.Context.ContainsKey("c1")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.Context["c1"].Equals("TEST")); property = propertyPrefix + ".Context.c2"; test(!b1.Context.ContainsKey("c2")); communicator.SetProperty(property, "TEST"); b1 = communicator.GetPropertyAsProxy(propertyPrefix, IObjectPrx.Factory); test(b1.Context["c2"].Equals("TEST")); communicator.SetProperty(propertyPrefix + ".Context.c1", ""); communicator.SetProperty(propertyPrefix + ".Context.c2", ""); output.WriteLine("ok"); output.Write("testing proxyToProperty... "); output.Flush(); var router = IRouterPrx.Parse("router", communicator).Clone( collocationOptimized: false, connectionCached: true, preferSecure: true, endpointSelectionType: EndpointSelectionType.Random, locatorCacheTimeout: 200, invocationTimeout: 1500); var locator = ILocatorPrx.Parse("locator", communicator).Clone( collocationOptimized: true, connectionCached: false, preferSecure: true, endpointSelectionType: EndpointSelectionType.Random, locatorCacheTimeout: 300, invocationTimeout: 1500, router: router); b1 = IObjectPrx.Parse("test", communicator).Clone( collocationOptimized: true, connectionCached: true, preferSecure: false, endpointSelectionType: EndpointSelectionType.Ordered, locatorCacheTimeout: 100, invocationTimeout: 1234, encodingVersion: new EncodingVersion(1, 0), locator: locator); Dictionary <string, string> proxyProps = b1.ToProperty("Test"); test(proxyProps.Count == 21); test(proxyProps["Test"].Equals("test -t -e 1.0")); test(proxyProps["Test.CollocationOptimized"].Equals("1")); test(proxyProps["Test.ConnectionCached"].Equals("1")); test(proxyProps["Test.PreferSecure"].Equals("0")); test(proxyProps["Test.EndpointSelection"].Equals("Ordered")); test(proxyProps["Test.LocatorCacheTimeout"].Equals("100")); test(proxyProps["Test.InvocationTimeout"].Equals("1234")); test(proxyProps["Test.Locator"].Equals( "locator -t -e " + Util.EncodingVersionToString(Util.CurrentEncoding))); // Locator collocation optimization is always disabled. //test(proxyProps["Test.Locator.CollocationOptimized"].Equals("1")); test(proxyProps["Test.Locator.ConnectionCached"].Equals("0")); test(proxyProps["Test.Locator.PreferSecure"].Equals("1")); test(proxyProps["Test.Locator.EndpointSelection"].Equals("Random")); test(proxyProps["Test.Locator.LocatorCacheTimeout"].Equals("300")); test(proxyProps["Test.Locator.InvocationTimeout"].Equals("1500")); test(proxyProps["Test.Locator.Router"].Equals( "router -t -e " + Util.EncodingVersionToString(Util.CurrentEncoding))); test(proxyProps["Test.Locator.Router.CollocationOptimized"].Equals("0")); test(proxyProps["Test.Locator.Router.ConnectionCached"].Equals("1")); test(proxyProps["Test.Locator.Router.PreferSecure"].Equals("1")); test(proxyProps["Test.Locator.Router.EndpointSelection"].Equals("Random")); test(proxyProps["Test.Locator.Router.LocatorCacheTimeout"].Equals("200")); test(proxyProps["Test.Locator.Router.InvocationTimeout"].Equals("1500")); output.WriteLine("ok"); output.Write("testing ice_getCommunicator... "); output.Flush(); test(baseProxy.Communicator == communicator); output.WriteLine("ok"); output.Write("testing proxy methods... "); test(baseProxy.Clone(facet: "facet").Facet.Equals("facet")); test(baseProxy.Clone(adapterId: "id").AdapterId.Equals("id")); test(!baseProxy.Clone(invocationMode: InvocationMode.Twoway).IsOneway); test(baseProxy.Clone(invocationMode: InvocationMode.Oneway).IsOneway); test(baseProxy.Clone(invocationMode: InvocationMode.Datagram).IsOneway); test(baseProxy.Clone(invocationMode: InvocationMode.BatchOneway).InvocationMode == InvocationMode.BatchOneway); test(baseProxy.Clone(invocationMode: InvocationMode.Datagram).InvocationMode == InvocationMode.Datagram); test(baseProxy.Clone(invocationMode: InvocationMode.BatchDatagram).InvocationMode == InvocationMode.BatchDatagram); test(baseProxy.Clone(secure: true).IsSecure); test(!baseProxy.Clone(secure: false).IsSecure); test(baseProxy.Clone(collocationOptimized: true).IsCollocationOptimized); test(!baseProxy.Clone(collocationOptimized: false).IsCollocationOptimized); test(baseProxy.Clone(preferSecure: true).IsPreferSecure); test(!baseProxy.Clone(preferSecure: false).IsPreferSecure); try { baseProxy.Clone(connectionTimeout: 0); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(connectionTimeout: -1); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(connectionTimeout: -2); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: 0); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(invocationTimeout: -1); baseProxy.Clone(invocationTimeout: -2); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(invocationTimeout: -3); test(false); } catch (ArgumentException) { } try { baseProxy.Clone(locatorCacheTimeout: 0); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(locatorCacheTimeout: -1); } catch (ArgumentException) { test(false); } try { baseProxy.Clone(locatorCacheTimeout: -2); test(false); } catch (ArgumentException) { } output.WriteLine("ok"); output.Write("testing proxy comparison... "); output.Flush(); test(object.Equals(IObjectPrx.Parse("foo", communicator), IObjectPrx.Parse("foo", communicator))); test(!IObjectPrx.Parse("foo", communicator).Equals(IObjectPrx.Parse("foo2", communicator))); var compObj = IObjectPrx.Parse("foo", communicator); test(compObj.Clone(facet: "facet").Equals(compObj.Clone(facet: "facet"))); test(!compObj.Clone(facet: "facet").Equals(compObj.Clone(facet: "facet1"))); test(compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Oneway))); test(!compObj.Clone(invocationMode: InvocationMode.Oneway).Equals( compObj.Clone(invocationMode: InvocationMode.Twoway))); test(compObj.Clone(secure: true).Equals(compObj.Clone(secure: true))); test(!compObj.Clone(secure: false).Equals(compObj.Clone(secure: true))); test(compObj.Clone(collocationOptimized: true).Equals(compObj.Clone(collocationOptimized: true))); test(!compObj.Clone(collocationOptimized: false).Equals(compObj.Clone(collocationOptimized: true))); test(compObj.Clone(connectionCached: true).Equals(compObj.Clone(connectionCached: true))); test(!compObj.Clone(connectionCached: false).Equals(compObj.Clone(connectionCached: true))); test(compObj.Clone(endpointSelectionType: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelectionType: EndpointSelectionType.Random))); test(!compObj.Clone(endpointSelectionType: EndpointSelectionType.Random).Equals( compObj.Clone(endpointSelectionType: EndpointSelectionType.Ordered))); test(compObj.Clone(connectionId: "id2").Equals(compObj.Clone(connectionId: "id2"))); test(!compObj.Clone(connectionId: "id1").Equals(compObj.Clone(connectionId: "id2"))); test(compObj.Clone(connectionId: "id1").ConnectionId.Equals("id1")); test(compObj.Clone(connectionId: "id2").ConnectionId.Equals("id2")); test(compObj.Clone(compress: true).Equals(compObj.Clone(compress: true))); test(!compObj.Clone(compress: false).Equals(compObj.Clone(compress: true))); test(!compObj.Compress.HasValue); test(compObj.Clone(compress: true).Compress.Value == true); test(compObj.Clone(compress: false).Compress.Value == false); test(compObj.Clone(connectionTimeout: 20).Equals(compObj.Clone(connectionTimeout: 20))); test(!compObj.Clone(connectionTimeout: 10).Equals(compObj.Clone(connectionTimeout: 20))); test(!compObj.ConnectionTimeout.HasValue); test(compObj.Clone(connectionTimeout: 10).ConnectionTimeout.Value == 10); test(compObj.Clone(connectionTimeout: 20).ConnectionTimeout.Value == 20); ILocatorPrx loc1 = ILocatorPrx.Parse("loc1:default -p 10000", communicator); ILocatorPrx loc2 = ILocatorPrx.Parse("loc2:default -p 10000", communicator); test(compObj.Clone(clearLocator: true).Equals(compObj.Clone(clearLocator: true))); test(compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc1))); test(!compObj.Clone(locator: loc1).Equals(compObj.Clone(clearLocator: true))); test(!compObj.Clone(clearLocator: true).Equals(compObj.Clone(locator: loc2))); test(!compObj.Clone(locator: loc1).Equals(compObj.Clone(locator: loc2))); IRouterPrx rtr1 = IRouterPrx.Parse("rtr1:default -p 10000", communicator); IRouterPrx rtr2 = IRouterPrx.Parse("rtr2:default -p 10000", communicator); test(compObj.Clone(clearRouter: true).Equals(compObj.Clone(clearRouter: true))); test(compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr1))); test(!compObj.Clone(router: rtr1).Equals(compObj.Clone(clearRouter: true))); test(!compObj.Clone(clearRouter: true).Equals(compObj.Clone(router: rtr2))); test(!compObj.Clone(router: rtr1).Equals(compObj.Clone(router: rtr2))); Dictionary <string, string> ctx1 = new Dictionary <string, string>(); ctx1["ctx1"] = "v1"; Dictionary <string, string> ctx2 = new Dictionary <string, string>(); ctx2["ctx2"] = "v2"; test(compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: new Dictionary <string, string>()))); test(compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx1))); test(!compObj.Clone(context: ctx1).Equals( compObj.Clone(context: new Dictionary <string, string>()))); test(!compObj.Clone(context: new Dictionary <string, string>()).Equals( compObj.Clone(context: ctx2))); test(!compObj.Clone(context: ctx1).Equals(compObj.Clone(context: ctx2))); test(compObj.Clone(preferSecure: true).Equals(compObj.Clone(preferSecure: true))); test(!compObj.Clone(preferSecure: true).Equals(compObj.Clone(preferSecure: false))); var compObj1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator); var compObj2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator); test(!compObj1.Equals(compObj2)); compObj1 = IObjectPrx.Parse("foo@MyAdapter1", communicator); compObj2 = IObjectPrx.Parse("foo@MyAdapter2", communicator); test(!compObj1.Equals(compObj2)); test(compObj1.Clone(locatorCacheTimeout: 20).Equals(compObj1.Clone(locatorCacheTimeout: 20))); test(!compObj1.Clone(locatorCacheTimeout: 10).Equals(compObj1.Clone(locatorCacheTimeout: 20))); test(compObj1.Clone(invocationTimeout: 20).Equals(compObj1.Clone(invocationTimeout: 20))); test(!compObj1.Clone(invocationTimeout: 10).Equals(compObj1.Clone(invocationTimeout: 20))); compObj1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 1000", communicator); compObj2 = IObjectPrx.Parse("foo@MyAdapter1", communicator); test(!compObj1.Equals(compObj2)); IEndpoint[] endpts1 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints; IEndpoint[] endpts2 = IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10001", communicator).Endpoints; test(!endpts1[0].Equals(endpts2[0])); test(endpts1[0].Equals(IObjectPrx.Parse("foo:tcp -h 127.0.0.1 -p 10000", communicator).Endpoints[0])); Connection baseConnection = baseProxy.GetConnection(); if (baseConnection != null) { Connection baseConnection2 = baseProxy.Clone(connectionId: "base2").GetConnection(); compObj1 = compObj1.Clone(fixedConnection: baseConnection); compObj2 = compObj2.Clone(fixedConnection: baseConnection2); test(!compObj1.Equals(compObj2)); } output.WriteLine("ok"); output.Write("testing checked cast... "); output.Flush(); Test.IMyClassPrx cl = Test.IMyClassPrx.CheckedCast(baseProxy); test(cl != null); Test.IMyDerivedClassPrx derived = Test.IMyDerivedClassPrx.CheckedCast(cl); test(derived != null); test(cl.Equals(baseProxy)); test(derived.Equals(baseProxy)); test(cl.Equals(derived)); try { Test.IMyDerivedClassPrx.CheckedCast(cl.Clone(facet: "facet")); test(false); } catch (ObjectNotExistException) { } output.WriteLine("ok"); output.Write("testing checked cast with context... "); output.Flush(); Dictionary <string, string> c = cl.getContext(); test(c == null || c.Count == 0); c = new Dictionary <string, string>(); c["one"] = "hello"; c["two"] = "world"; cl = Test.IMyClassPrx.CheckedCast(baseProxy, c); Dictionary <string, string> c2 = cl.getContext(); test(global::Test.Collections.Equals(c, c2)); output.WriteLine("ok"); output.Write("testing ice_fixed... "); output.Flush(); { Connection connection = cl.GetConnection(); if (connection != null) { test(!cl.IsFixed); Test.IMyClassPrx prx = cl.Clone(fixedConnection: connection); test(prx.IsFixed); prx.IcePing(); try { cl.Clone(secure: true, fixedConnection: connection); test(false); } catch (ArgumentException) { } test(cl.Clone(facet: "facet", fixedConnection: connection).Facet.Equals("facet")); test(cl.Clone(invocationMode: InvocationMode.Oneway, fixedConnection: connection).IsOneway); Dictionary <string, string> ctx = new Dictionary <string, string>(); ctx["one"] = "hello"; ctx["two"] = "world"; test(cl.Clone(fixedConnection: connection).Context.Count == 0); test(cl.Clone(context: ctx, fixedConnection: connection).Context.Count == 2); test(cl.Clone(fixedConnection: connection).InvocationTimeout == -1); test(cl.Clone(invocationTimeout: 10, fixedConnection: connection).InvocationTimeout == 10); test(cl.Clone(fixedConnection: connection).GetConnection() == connection); test(cl.Clone(fixedConnection: connection).Clone(fixedConnection: connection).GetConnection() == connection); test(!cl.Clone(fixedConnection: connection).ConnectionTimeout.HasValue); test(cl.Clone(compress: true, fixedConnection: connection).Compress.Value); Connection fixedConnection = cl.Clone(connectionId: "ice_fixed").GetConnection(); test(cl.Clone(fixedConnection: connection).Clone(fixedConnection: fixedConnection).GetConnection() == fixedConnection); try { cl.Clone(secure: !connection.Endpoint.GetInfo().Secure(), fixedConnection: connection); test(false); } catch (ArgumentException) { } try { cl.Clone(invocationMode: InvocationMode.Datagram, fixedConnection: connection); test(false); } catch (ArgumentException) { } } } output.WriteLine("ok"); output.Write("testing encoding versioning... "); output.Flush(); string ref20 = "test -e 2.0:" + helper.getTestEndpoint(0); Test.IMyClassPrx cl20 = Test.IMyClassPrx.Parse(ref20, communicator); try { cl20.IcePing(); test(false); } catch (UnsupportedEncodingException) { // Server 2.0 endpoint doesn't support 1.1 version. } // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the // call will use the 1.1 encoding string ref13 = "test -e 1.3:" + helper.getTestEndpoint(0); Test.IMyClassPrx cl13 = Test.IMyClassPrx.Parse(ref13, communicator); cl13.IcePing(); cl13.IcePingAsync().Wait(); try { // Send request with bogus 1.2 encoding. EncodingVersion version = new EncodingVersion(1, 2); OutputStream os = new OutputStream(communicator); os.StartEncapsulation(); os.EndEncapsulation(); byte[] inEncaps = os.Finished(); inEncaps[4] = version.Major; inEncaps[5] = version.Minor; byte[] outEncaps; cl.Invoke("ice_ping", idempotent: false, inEncaps, out outEncaps); test(false); } catch (UnknownLocalException ex) { test(ex.Unknown.IndexOf("UnsupportedEncodingException") > 0); } try { // Send request with bogus 2.0 encoding. EncodingVersion version = new EncodingVersion(2, 0); OutputStream os = new OutputStream(communicator); os.StartEncapsulation(); os.EndEncapsulation(); byte[] inEncaps = os.Finished(); inEncaps[4] = version.Major; inEncaps[5] = version.Minor; byte[] outEncaps; cl.Invoke("ice_ping", idempotent: false, inEncaps, out outEncaps); test(false); } catch (UnknownLocalException ex) { test(ex.Unknown.IndexOf("UnsupportedEncodingException") > 0); } output.WriteLine("ok"); output.Write("testing protocol versioning... "); output.Flush(); ref20 = "test -p 2.0:" + helper.getTestEndpoint(0); cl20 = Test.IMyClassPrx.Parse(ref20, communicator); try { cl20.IcePing(); test(false); } catch (UnsupportedProtocolException) { // Server 2.0 proxy doesn't support 1.0 version. } // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the // call will use the 1.1 protocol ref13 = "test -p 1.3:" + helper.getTestEndpoint(0); cl13 = Test.IMyClassPrx.Parse(ref13, communicator); cl13.IcePing(); cl13.IcePingAsync().Wait(); output.WriteLine("ok"); output.Write("testing opaque endpoints... "); output.Flush(); try { // Invalid -x option IObjectPrx.Parse("id:opaque -t 99 -v abcd -x abc", communicator); test(false); } catch (FormatException) { } try { // Missing -t and -v IObjectPrx.Parse("id:opaque", communicator); test(false); } catch (FormatException) { } try { // Repeated -t IObjectPrx.Parse("id:opaque -t 1 -t 1 -v abcd", communicator); test(false); } catch (FormatException) { } try { // Repeated -v IObjectPrx.Parse("id:opaque -t 1 -v abcd -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing -t IObjectPrx.Parse("id:opaque -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing -v IObjectPrx.Parse("id:opaque -t 1", communicator); test(false); } catch (FormatException) { } try { // Missing arg for -t IObjectPrx.Parse("id:opaque -t -v abcd", communicator); test(false); } catch (FormatException) { } try { // Missing arg for -v IObjectPrx.Parse("id:opaque -t 1 -v", communicator); test(false); } catch (FormatException) { } try { // Not a number for -t IObjectPrx.Parse("id:opaque -t x -v abcd", communicator); test(false); } catch (FormatException) { } try { // < 0 for -t IObjectPrx.Parse("id:opaque -t -1 -v abcd", communicator); test(false); } catch (FormatException) { } try { // Invalid char for -v IObjectPrx.Parse("id:opaque -t 99 -v x?c", communicator); test(false); } catch (FormatException) { } try { // Invalid lenght for base64 input IObjectPrx.Parse("id:opaque -t 99 -v xc", communicator); test(false); } catch (FormatException) { } // Legal TCP endpoint expressed as opaque endpoint var p1 = IObjectPrx.Parse("test -e 1.1:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==", communicator); string pstr = p1.ToString(); test(pstr.Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000")); // Opaque endpoint encoded with 1.1 encoding. var p2 = IObjectPrx.Parse("test -e 1.1:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==", communicator); test(p2.ToString().Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000")); if ((communicator.GetPropertyAsInt("IPv6") ?? 0) == 0) { // Working? bool ssl = communicator.GetProperty("Default.Protocol") == "ssl"; bool tcp = communicator.GetProperty("Default.Protocol") == "tcp"; // Two legal TCP endpoints expressed as opaque endpoints p1 = IObjectPrx.Parse("test -e 1.1:" + "" + "opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:" + "opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA==", communicator); pstr = p1.ToString(); test(pstr.Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000:tcp -h 127.0.0.2 -p 12011 -t 10000")); // Test that an SSL endpoint and a nonsense endpoint get written back out as an opaque endpoint. p1 = IObjectPrx.Parse("test -e 1.1:opaque -e 1.1 -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -e 1.1 -t 99 -v abch", communicator); pstr = p1.ToString(); if (ssl) { test(pstr.Equals("test -t -e 1.1:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.1 -v abch")); } else if (tcp) { test(pstr.Equals( "test -t -e 1.1:opaque -t 2 -e 1.1 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.1 -v abch")); } } output.WriteLine("ok"); output.Write("testing communicator shutdown/destroy... "); output.Flush(); { Communicator com = new Communicator(); com.Shutdown(); test(com.IsShutdown()); com.WaitForShutdown(); com.Destroy(); com.Shutdown(); test(com.IsShutdown()); com.WaitForShutdown(); com.Destroy(); } output.WriteLine("ok"); return(cl); }
/// <summary> /// Reads the start of an encapsulation. /// </summary> /// <returns>The encapsulation encoding version.</returns> public EncodingVersion startEncapsulation() { Encaps curr = _encapsCache; if(curr != null) { curr.reset(); _encapsCache = _encapsCache.next; } else { curr = new Encaps(); } curr.next = _encapsStack; _encapsStack = curr; _encapsStack.start = _buf.b.position(); // // I don't use readSize() for encapsulations, because when creating an encapsulation, // I must know in advance how many bytes the size information will require in the data // stream. If I use an Int, it is always 4 bytes. For readSize(), it could be 1 or 5 bytes. // int sz = readInt(); if(sz < 6) { throw new UnmarshalOutOfBoundsException(); } if(sz - 4 > _buf.b.remaining()) { throw new UnmarshalOutOfBoundsException(); } _encapsStack.sz = sz; EncodingVersion encoding = new EncodingVersion(); encoding.read__(this); Protocol.checkSupportedEncoding(encoding); // Make sure the encoding is supported. _encapsStack.setEncoding(encoding); return encoding; }
public InputStream(IceInternal.Instance instance, EncodingVersion encoding, IceInternal.Buffer buf, bool adopt) { initialize(instance, encoding); _buf = new IceInternal.Buffer(buf, adopt); }
internal void setEncoding(EncodingVersion encoding) { this.encoding = encoding; encoding_1_0 = encoding.Equals(Util.Encoding_1_0); }
/// <summary> /// Returns a blob of bytes representing an encapsulation. The encapsulation's encoding version /// is returned in the argument. /// </summary> /// <param name="encoding">The encapsulation's encoding version.</param> /// <returns>The encoded encapsulation.</returns> public byte[] readEncapsulation(out EncodingVersion encoding) { int sz = readInt(); if(sz < 6) { throw new UnmarshalOutOfBoundsException(); } if(sz - 4 > _buf.b.remaining()) { throw new UnmarshalOutOfBoundsException(); } encoding = new EncodingVersion(); encoding.read__(this); _buf.b.position(_buf.b.position() - 6); byte[] v = new byte[sz]; try { _buf.b.get(v); return v; } catch(InvalidOperationException ex) { throw new UnmarshalOutOfBoundsException(ex); } }
/// <summary> /// Skips an empty encapsulation. /// </summary> /// <returns>The encapsulation's encoding version.</returns> public EncodingVersion skipEmptyEncapsulation() { int sz = readInt(); if(sz < 6) { throw new EncapsulationException(); } if(sz - 4 > _buf.b.remaining()) { throw new UnmarshalOutOfBoundsException(); } var encoding = new EncodingVersion(); encoding.read__(this); if(encoding.Equals(Util.Encoding_1_0)) { if(sz != 6) { throw new EncapsulationException(); } } else { // Skip the optional content of the encapsulation if we are expecting an // empty encapsulation. _buf.b.position(_buf.b.position() + sz - 6); } return encoding; }
/// <summary> /// Swaps the contents of one stream with another. /// </summary> /// <param name="other">The other stream.</param> public void swap(InputStream other) { Debug.Assert(instance_ == other.instance_); IceInternal.Buffer tmpBuf = other._buf; other._buf = _buf; _buf = tmpBuf; EncodingVersion tmpEncoding = other._encoding; other._encoding = _encoding; _encoding = tmpEncoding; bool tmpTraceSlicing = other._traceSlicing; other._traceSlicing = _traceSlicing; _traceSlicing = tmpTraceSlicing; object tmpClosure = other._closure; other._closure = _closure; _closure = tmpClosure; bool tmpSliceValues = other._sliceValues; other._sliceValues = _sliceValues; _sliceValues = tmpSliceValues; // // Swap is never called for InputStreams that have encapsulations being read. However, // encapsulations might still be set in case un-marshalling failed. We just // reset the encapsulations if there are still some set. // resetEncapsulation(); other.resetEncapsulation(); int tmpStartSeq = other._startSeq; other._startSeq = _startSeq; _startSeq = tmpStartSeq; int tmpMinSeqSize = other._minSeqSize; other._minSeqSize = _minSeqSize; _minSeqSize = tmpMinSeqSize; ValueFactoryManager tmpVfm = other._valueFactoryManager; other._valueFactoryManager = _valueFactoryManager; _valueFactoryManager = tmpVfm; Logger tmpLogger = other._logger; other._logger = _logger; _logger = tmpLogger; CompactIdResolver tmpCompactIdResolver = other._compactIdResolver; other._compactIdResolver = _compactIdResolver; _compactIdResolver = tmpCompactIdResolver; ClassResolver tmpClassResolver = other._classResolver; other._classResolver = _classResolver; _classResolver = tmpClassResolver; }
public UnsupportedEncodingException(string reason, EncodingVersion bad, EncodingVersion supported, System.Exception ex) : base(reason, ex) { this.bad = bad; this.supported = supported; }
public UnsupportedEncodingException(System.Exception ex) : base(ex) { this.bad = new EncodingVersion(); this.supported = new EncodingVersion(); }
public UnsupportedEncodingException() { this.bad = new EncodingVersion(); this.supported = new EncodingVersion(); }
private bool validate(int operation) { if(!_endpoint.datagram()) // Datagram connections are always implicitly validated. { if(_adapter != null) // The server side has the active role for connection validation. { if(_writeStream.size() == 0) { _writeStream.writeBlob(IceInternal.Protocol.magic); Ice.Util.currentProtocol.write__(_writeStream); Ice.Util.currentProtocolEncoding.write__(_writeStream); _writeStream.writeByte(IceInternal.Protocol.validateConnectionMsg); _writeStream.writeByte((byte)0); // Compression status (always zero for validate connection). _writeStream.writeInt(IceInternal.Protocol.headerSize); // Message size. IceInternal.TraceUtil.traceSend(_writeStream, _logger, _traceLevels); _writeStream.prepareWrite(); } if(_observer != null) { observerStartWrite(_writeStream.getBuffer()); } if(_writeStream.pos() != _writeStream.size()) { int op = write(_writeStream.getBuffer()); if(op != 0) { scheduleTimeout(op); _threadPool.update(this, operation, op); return false; } } if(_observer != null) { observerFinishWrite(_writeStream.getBuffer()); } } else // The client side has the passive role for connection validation. { if(_readStream.size() == 0) { _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); } if(_observer != null) { observerStartRead(_readStream.getBuffer()); } if(_readStream.pos() != _readStream.size()) { int op = read(_readStream.getBuffer()); if(op != 0) { scheduleTimeout(op); _threadPool.update(this, operation, op); return false; } } if(_observer != null) { observerFinishRead(_readStream.getBuffer()); } Debug.Assert(_readStream.pos() == IceInternal.Protocol.headerSize); _readStream.pos(0); byte[] m = _readStream.readBlob(4); if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { BadMagicException ex = new BadMagicException(); ex.badMagic = m; throw ex; } ProtocolVersion pv = new ProtocolVersion(); pv.read__(_readStream); IceInternal.Protocol.checkSupportedProtocol(pv); EncodingVersion ev = new EncodingVersion(); ev.read__(_readStream); IceInternal.Protocol.checkSupportedProtocolEncoding(ev); byte messageType = _readStream.readByte(); if(messageType != IceInternal.Protocol.validateConnectionMsg) { throw new ConnectionNotValidatedException(); } _readStream.readByte(); // Ignore compression status for validate connection. int size = _readStream.readInt(); if(size != IceInternal.Protocol.headerSize) { throw new IllegalMessageSizeException(); } IceInternal.TraceUtil.traceRecv(_readStream, _logger, _traceLevels); _validated = true; } } _writeStream.resize(0, false); _writeStream.pos(0); _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; if(_instance.traceLevels().network >= 1) { StringBuilder s = new StringBuilder(); if(_endpoint.datagram()) { s.Append("starting to "); s.Append(_connector != null ? "send" : "receive"); s.Append(" "); s.Append(_endpoint.protocol()); s.Append(" messages\n"); s.Append(_transceiver.toDetailedString()); } else { s.Append(_connector != null ? "established" : "accepted"); s.Append(" "); s.Append(_endpoint.protocol()); s.Append(" connection\n"); s.Append(ToString()); } _instance.initializationData().logger.trace(_instance.traceLevels().networkCat, s.ToString()); } return true; }
/// <summary> /// This constructor uses the given encoding version. /// </summary> /// <param name="encoding">The desired encoding version.</param> /// <param name="data">The byte array containing encoded Slice types.</param> public InputStream(EncodingVersion encoding, byte[] data) { initialize(encoding); _buf = new IceInternal.Buffer(data); }
protected OpaqueEndpointInfo() { this.rawEncoding = new EncodingVersion(); }
public InputStream(EncodingVersion encoding, IceInternal.ByteBuffer buf) { initialize(encoding); _buf = new IceInternal.Buffer(buf); }
public InputStream(IceInternal.Instance instance, EncodingVersion encoding, IceInternal.Buffer buf) : this(instance, encoding, buf, false) { }
public InputStream(EncodingVersion encoding, IceInternal.Buffer buf) : this(encoding, buf, false) { }
private void initialize(IceInternal.Instance instance, EncodingVersion encoding) { initialize(encoding); instance_ = instance; _traceSlicing = instance_.traceLevels().slicing > 0; _valueFactoryManager = instance_.initializationData().valueFactoryManager; _logger = instance_.initializationData().logger; _classResolver = instance_.resolveClass; }
public InputStream(EncodingVersion encoding, IceInternal.Buffer buf, bool adopt) { initialize(encoding); _buf = new IceInternal.Buffer(buf, adopt); }
/// <summary> /// Initializes the stream to use the given communicator and encoding version. /// </summary> /// <param name="communicator">The communicator to use when initializing the stream.</param> /// <param name="encoding">The desired encoding version.</param> public void initialize(Communicator communicator, EncodingVersion encoding) { Debug.Assert(communicator != null); IceInternal.Instance instance = IceInternal.Util.getInstance(communicator); initialize(instance, encoding); }
/// <summary> /// This constructor uses the given encoding version. /// </summary> /// <param name="communicator">The communicator to use when initializing the stream.</param> /// <param name="encoding">The desired encoding version.</param> /// <param name="data">The byte array containing encoded Slice types.</param> public InputStream(Communicator communicator, EncodingVersion encoding, byte[] data) { initialize(communicator, encoding); _buf = new IceInternal.Buffer(data); }
public InputStreamI(Communicator communicator, byte[] data, EncodingVersion v, bool copyData) { _communicator = communicator; initialize(IceInternal.Util.getInstance(communicator), data, v, copyData); }
public InputStream(Communicator communicator, EncodingVersion encoding, IceInternal.Buffer buf) : this(communicator, encoding, buf, false) { }
public override void message(ref IceInternal.ThreadPoolCurrent current) { StartCallback startCB = null; Queue<OutgoingMessage> sentCBs = null; MessageInfo info = new MessageInfo(); IceInternal.ThreadPoolMessage msg = new IceInternal.ThreadPoolMessage(_m); _m.Lock(); try { if(!msg.startIOScope(ref current)) { return; } if(_state >= StateClosed) { return; } try { unscheduleTimeout(current.operation); if((current.operation & IceInternal.SocketOperation.Write) != 0 && !_writeStream.isEmpty()) { if(_observer != null) { observerStartWrite(_writeStream.pos()); } if(_writeStream.getBuffer().b.hasRemaining() && !_transceiver.write(_writeStream.getBuffer())) { Debug.Assert(!_writeStream.isEmpty()); scheduleTimeout(IceInternal.SocketOperation.Write, _endpoint.timeout()); return; } if(_observer != null) { observerFinishWrite(_writeStream.pos()); } Debug.Assert(!_writeStream.getBuffer().b.hasRemaining()); } if((current.operation & IceInternal.SocketOperation.Read) != 0 && !_readStream.isEmpty()) { if(_readHeader) // Read header if necessary. { if(_readStream.getBuffer().b.hasRemaining() && !_transceiver.read(_readStream.getBuffer())) { return; } Debug.Assert(!_readStream.getBuffer().b.hasRemaining()); _readHeader = false; if(_observer != null) { _observer.receivedBytes(IceInternal.Protocol.headerSize); } int pos = _readStream.pos(); if(pos < IceInternal.Protocol.headerSize) { // // This situation is possible for small UDP packets. // throw new Ice.IllegalMessageSizeException(); } _readStream.pos(0); byte[] m = new byte[4]; m[0] = _readStream.readByte(); m[1] = _readStream.readByte(); m[2] = _readStream.readByte(); m[3] = _readStream.readByte(); if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { Ice.BadMagicException ex = new Ice.BadMagicException(); ex.badMagic = m; throw ex; } ProtocolVersion pv = new ProtocolVersion(); pv.read__(_readStream); IceInternal.Protocol.checkSupportedProtocol(pv); EncodingVersion ev = new EncodingVersion(); ev.read__(_readStream); IceInternal.Protocol.checkSupportedProtocolEncoding(ev); _readStream.readByte(); // messageType _readStream.readByte(); // compress int size = _readStream.readInt(); if(size < IceInternal.Protocol.headerSize) { throw new Ice.IllegalMessageSizeException(); } if(size > _instance.messageSizeMax()) { IceInternal.Ex.throwMemoryLimitException(size, _instance.messageSizeMax()); } if(size > _readStream.size()) { _readStream.resize(size, true); } _readStream.pos(pos); } if(_readStream.getBuffer().b.hasRemaining()) { if(_endpoint.datagram()) { throw new Ice.DatagramLimitException(); // The message was truncated. } else { if(_observer != null) { observerStartRead(_readStream.pos()); } if(!_transceiver.read(_readStream.getBuffer())) { Debug.Assert(!_readStream.isEmpty()); scheduleTimeout(IceInternal.SocketOperation.Read, _endpoint.timeout()); return; } if(_observer != null) { observerFinishRead(_readStream.pos()); } Debug.Assert(!_readStream.getBuffer().b.hasRemaining()); } } } if(_state <= StateNotValidated) { if(_state == StateNotInitialized && !initialize(current.operation)) { return; } if(_state <= StateNotValidated && !validate(current.operation)) { return; } _threadPool.unregister(this, current.operation); // // We start out in holding state. // setState(StateHolding); startCB = _startCallback; _startCallback = null; } else { Debug.Assert(_state <= StateClosing); // // We parse messages first, if we receive a close // connection message we won't send more messages. // if((current.operation & IceInternal.SocketOperation.Read) != 0) { parseMessage(ref info); } if((current.operation & IceInternal.SocketOperation.Write) != 0) { sentCBs = sendNextMessage(); } } // // We increment the dispatch count to prevent the // communicator destruction during the callback. // if(sentCBs != null || info.outAsync != null) { ++_dispatchCount; } if(_acmTimeout > 0) { _acmAbsoluteTimeoutMillis = IceInternal.Time.currentMonotonicTimeMillis() + _acmTimeout * 1000; } if(startCB == null && sentCBs == null && info.invokeNum == 0 && info.outAsync == null) { return; // Nothing to dispatch. } msg.completed(ref current); } catch(DatagramLimitException) // Expected. { if(_warnUdp) { _logger.warning("maximum datagram size of " + _readStream.pos() + " exceeded"); } _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; return; } catch(SocketException ex) { setState(StateClosed, ex); return; } catch(LocalException ex) { if(_endpoint.datagram()) { if(_warn) { String s = "datagram connection exception:\n" + ex + '\n' + _desc; _logger.warning(s); } _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; } else { setState(StateClosed, ex); } return; } finally { msg.finishIOScope(ref current); } // // Unlike C++/Java, this method is called from an IO thread of the .NET thread // pool or from the communicator async IO thread. While it's fine to handle the // non-blocking activity of the connection from these threads, the dispatching // of the message must be taken care of by the Ice thread pool. // IceInternal.ThreadPoolCurrent c = current; _threadPool.execute( delegate() { if(_dispatcher != null) { try { _dispatcher(delegate() { dispatch(startCB, sentCBs, info); }, this); } catch(System.Exception ex) { if(_instance.initializationData().properties.getPropertyAsIntWithDefault( "Ice.Warn.Dispatch", 1) > 1) { warning("dispatch exception", ex); } } } else { dispatch(startCB, sentCBs, info); } msg.destroy(ref c); }); } finally { _m.Unlock(); } }
public InputStream(Communicator communicator, EncodingVersion encoding, IceInternal.Buffer buf, bool adopt) { initialize(communicator, encoding); _buf = new IceInternal.Buffer(buf, adopt); }
/// <summary> /// Creates an input stream for dynamic invocation and dispatch. The stream uses /// the given encoding version. /// </summary> /// <param name="communicator">The communicator for the stream.</param> /// <param name="bytes">An encoded request or reply.</param> /// <param name="v">The desired encoding version.</param> /// <returns>The input stream.</returns> public static InputStream createInputStream(Communicator communicator, byte[] bytes, EncodingVersion v) { return new InputStreamI(communicator, bytes, v, true); }
/// <summary> /// Skips over an encapsulation. /// </summary> /// <returns>The encoding version of the skipped encapsulation.</returns> public EncodingVersion skipEncapsulation() { int sz = readInt(); if(sz < 6) { throw new UnmarshalOutOfBoundsException(); } EncodingVersion encoding = new EncodingVersion(); encoding.read__(this); try { _buf.b.position(_buf.b.position() + sz - 6); } catch(ArgumentOutOfRangeException ex) { throw new Ice.UnmarshalOutOfBoundsException(ex); } return encoding; }
/// <summary> /// Creates an output stream for dynamic invocation and dispatch. The stream uses /// the given encoding version. /// </summary> /// <param name="communicator">The communicator for the stream.</param> /// <param name="v">The desired encoding version.</param> /// <returns>The output stream.</returns> public static OutputStream createOutputStream(Communicator communicator, EncodingVersion v) { return new OutputStreamI(communicator, v); }
public InputStream(IceInternal.Instance instance, EncodingVersion encoding, byte[] data) { initialize(instance, encoding); _buf = new IceInternal.Buffer(data); }
public override void message(ref IceInternal.ThreadPoolCurrent current) { StartCallback startCB = null; Queue<OutgoingMessage> sentCBs = null; MessageInfo info = new MessageInfo(); int dispatchCount = 0; IceInternal.ThreadPoolMessage msg = new IceInternal.ThreadPoolMessage(this); try { lock(this) { if(!msg.startIOScope(ref current)) { return; } if(_state >= StateClosed) { return; } int readyOp = current.operation; try { unscheduleTimeout(current.operation); int writeOp = IceInternal.SocketOperation.None; int readOp = IceInternal.SocketOperation.None; if((readyOp & IceInternal.SocketOperation.Write) != 0) { if(_observer != null) { observerStartWrite(_writeStream.getBuffer()); } writeOp = write(_writeStream.getBuffer()); if(_observer != null && (writeOp & IceInternal.SocketOperation.Write) == 0) { observerFinishWrite(_writeStream.getBuffer()); } } while((readyOp & IceInternal.SocketOperation.Read) != 0) { IceInternal.Buffer buf = _readStream.getBuffer(); if(_observer != null && !_readHeader) { observerStartRead(buf); } readOp = read(buf); if((readOp & IceInternal.SocketOperation.Read) != 0) { break; } if(_observer != null && !_readHeader) { Debug.Assert(!buf.b.hasRemaining()); observerFinishRead(buf); } if(_readHeader) // Read header if necessary. { _readHeader = false; if(_observer != null) { _observer.receivedBytes(IceInternal.Protocol.headerSize); } int pos = _readStream.pos(); if(pos < IceInternal.Protocol.headerSize) { // // This situation is possible for small UDP packets. // throw new Ice.IllegalMessageSizeException(); } _readStream.pos(0); byte[] m = new byte[4]; m[0] = _readStream.readByte(); m[1] = _readStream.readByte(); m[2] = _readStream.readByte(); m[3] = _readStream.readByte(); if(m[0] != IceInternal.Protocol.magic[0] || m[1] != IceInternal.Protocol.magic[1] || m[2] != IceInternal.Protocol.magic[2] || m[3] != IceInternal.Protocol.magic[3]) { Ice.BadMagicException ex = new Ice.BadMagicException(); ex.badMagic = m; throw ex; } ProtocolVersion pv = new ProtocolVersion(); pv.read__(_readStream); IceInternal.Protocol.checkSupportedProtocol(pv); EncodingVersion ev = new EncodingVersion(); ev.read__(_readStream); IceInternal.Protocol.checkSupportedProtocolEncoding(ev); _readStream.readByte(); // messageType _readStream.readByte(); // compress int size = _readStream.readInt(); if(size < IceInternal.Protocol.headerSize) { throw new Ice.IllegalMessageSizeException(); } if(size > _messageSizeMax) { IceInternal.Ex.throwMemoryLimitException(size, _messageSizeMax); } if(size > _readStream.size()) { _readStream.resize(size, true); } _readStream.pos(pos); } if(buf.b.hasRemaining()) { if(_endpoint.datagram()) { throw new Ice.DatagramLimitException(); // The message was truncated. } continue; } break; } int newOp = readOp | writeOp; readyOp &= ~newOp; Debug.Assert(readyOp != 0 || newOp != 0); if(_state <= StateNotValidated) { if(newOp != 0) { // // Wait for all the transceiver conditions to be // satisfied before continuing. // scheduleTimeout(newOp); _threadPool.update(this, current.operation, newOp); return; } if(_state == StateNotInitialized && !initialize(current.operation)) { return; } if(_state <= StateNotValidated && !validate(current.operation)) { return; } _threadPool.unregister(this, current.operation); // // We start out in holding state. // setState(StateHolding); if(_startCallback != null) { startCB = _startCallback; _startCallback = null; if(startCB != null) { ++dispatchCount; } } } else { Debug.Assert(_state <= StateClosingPending); // // We parse messages first, if we receive a close // connection message we won't send more messages. // if((readyOp & IceInternal.SocketOperation.Read) != 0) { newOp |= parseMessage(ref info); dispatchCount += info.messageDispatchCount; } if((readyOp & IceInternal.SocketOperation.Write) != 0) { newOp |= sendNextMessage(out sentCBs); if(sentCBs != null) { ++dispatchCount; } } if(_state < StateClosed) { scheduleTimeout(newOp); _threadPool.update(this, current.operation, newOp); } } if(_acmLastActivity > -1) { _acmLastActivity = IceInternal.Time.currentMonotonicTimeMillis(); } if(dispatchCount == 0) { return; // Nothing to dispatch we're done! } _dispatchCount += dispatchCount; msg.completed(ref current); } catch(DatagramLimitException) // Expected. { if(_warnUdp) { _logger.warning("maximum datagram size of " + _readStream.pos() + " exceeded"); } _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; return; } catch(SocketException ex) { setState(StateClosed, ex); return; } catch(LocalException ex) { if(_endpoint.datagram()) { if(_warn) { String s = "datagram connection exception:\n" + ex + '\n' + _desc; _logger.warning(s); } _readStream.resize(IceInternal.Protocol.headerSize, true); _readStream.pos(0); _readHeader = true; } else { setState(StateClosed, ex); } return; } IceInternal.ThreadPoolCurrent c = current; _threadPool.dispatch(() => { dispatch(startCB, sentCBs, info); msg.destroy(ref c); }, this); } } finally { msg.finishIOScope(ref current); } }
/// <summary> /// Skips an empty encapsulation. /// </summary> /// <returns>The encapsulation's encoding version.</returns> public EncodingVersion skipEmptyEncapsulation() { int sz = readInt(); if(sz != 6) { throw new EncapsulationException(); } EncodingVersion encoding = new EncodingVersion(); encoding.read__(this); return encoding; }