Exemplo n.º 1
0
 checkSupportedProtocolEncoding(Ice.EncodingVersion v)
 {
     if (v.major != protocolEncodingMajor || v.minor > protocolEncodingMinor)
     {
         throw new Ice.UnsupportedEncodingException("", v, Ice.Util.currentProtocolEncoding);
     }
 }
Exemplo n.º 2
0
        private static void printRequestHeader(System.IO.StringWriter s, Ice.InputStream str)
        {
            printIdentityFacetOperation(s, str);

            try
            {
                byte mode = str.readByte();
                s.Write("\nmode = " + (int)mode + ' ');
                switch ((Ice.OperationMode)mode)
                {
                case Ice.OperationMode.Normal:
                {
                    s.Write("(normal)");
                    break;
                }

                case Ice.OperationMode.Nonmutating:
                {
                    s.Write("(nonmutating)");
                    break;
                }

                case Ice.OperationMode.Idempotent:
                {
                    s.Write("(idempotent)");
                    break;
                }

                default:
                {
                    s.Write("(unknown)");
                    break;
                }
                }

                int sz = str.readSize();
                s.Write("\ncontext = ");
                while (sz-- > 0)
                {
                    string key = str.readString();
                    string val = str.readString();
                    s.Write(key + '/' + val);
                    if (sz > 0)
                    {
                        s.Write(", ");
                    }
                }

                Ice.EncodingVersion v = str.skipEncapsulation();
                if (!v.Equals(Ice.Util.Encoding_1_0))
                {
                    s.Write("\nencoding = ");
                    s.Write(Ice.Util.encodingVersionToString(v));
                }
            }
            catch (System.IO.IOException)
            {
                Debug.Assert(false);
            }
        }
Exemplo n.º 3
0
 checkSupportedEncoding(Ice.EncodingVersion v)
 {
     if (v.major != encodingMajor || v.minor > encodingMinor)
     {
         throw new Ice.UnsupportedEncodingException("", v, Ice.Util.CurrentEncoding);
     }
 }
Exemplo n.º 4
0
        public OpaqueEndpointI(short type, Ice.InputStream s)
        {
            _type = type;
            _rawEncoding = s.getEncoding();
            int sz = s.getEncapsulationSize();
            _rawBytes = new byte[sz];
            s.readBlob(_rawBytes);

            calcHashValue();
        }
Exemplo n.º 5
0
 getCompatibleEncoding(Ice.EncodingVersion v)
 {
     if (v.major != Ice.Util.currentEncoding.major)
     {
         return(v); // Unsupported encoding, return as is.
     }
     else if (v.minor < Ice.Util.currentEncoding.minor)
     {
         return(v); // Supported encoding.
     }
     else
     {
         //
         // Unsupported but compatible, use the currently supported
         // encoding, that's the best we can do.
         //
         return(Ice.Util.currentEncoding);
     }
 }
Exemplo n.º 6
0
        public OpaqueEndpointI(List<string> args)
        {
            _type = -1;
            _rawEncoding = Ice.Util.Encoding_1_0;
            _rawBytes = new byte[0];

            initWithOptions(args);

            if(_type < 0)
            {
                throw new Ice.EndpointParseException("no -t option in endpoint " + ToString());
            }
            if(_rawBytes.Length == 0)
            {
                throw new Ice.EndpointParseException("no -v option in endpoint " + ToString());
            }

            calcHashValue();
        }
Exemplo n.º 7
0
        public void invoke(ServantManager servantManager, BasicStream stream)
        {
            _is = stream;

            int start = _is.pos();

            //
            // Read the current.
            //
            current_.id.read__(_is);

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = _is.readStringSeq();
            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.MarshalException();
                }
                current_.facet = facetPath[0];
            }
            else
            {
                current_.facet = "";
            }

            current_.operation = _is.readString();
            current_.mode      = (Ice.OperationMode)(int) _is.readByte();
            current_.ctx       = new Dictionary <string, string>();
            int sz = _is.readSize();

            while (sz-- > 0)
            {
                string first  = _is.readString();
                string second = _is.readString();
                current_.ctx[first] = second;
            }

            Ice.Instrumentation.CommunicatorObserver obsv = instance_.getObserver();
            if (obsv != null)
            {
                // Read the encapsulation size.
                int size = _is.readInt();
                _is.pos(_is.pos() - 4);

                observer_ = obsv.getDispatchObserver(current_, _is.pos() - start + size);
                if (observer_ != null)
                {
                    observer_.attach();
                }
            }

            //
            // Don't put the code above into the try block below. Exceptions
            // in the code above are considered fatal, and must propagate to
            // the caller of this operation.
            //

            if (servantManager != null)
            {
                servant_ = servantManager.findServant(current_.id, current_.facet);
                if (servant_ == null)
                {
                    locator_ = servantManager.findServantLocator(current_.id.category);
                    if (locator_ == null && current_.id.category.Length > 0)
                    {
                        locator_ = servantManager.findServantLocator("");
                    }

                    if (locator_ != null)
                    {
                        try
                        {
                            servant_ = locator_.locate(current_, out cookie_);
                        }
                        catch (Ice.UserException ex)
                        {
                            Ice.EncodingVersion encoding = _is.skipEncaps(); // Required for batch requests.

                            if (observer_ != null)
                            {
                                observer_.userException();
                            }

                            if (response_)
                            {
                                os_.writeByte(ReplyStatus.replyUserException);
                                os_.startWriteEncaps(encoding, Ice.FormatType.DefaultFormat);
                                os_.writeUserException(ex);
                                os_.endWriteEncaps();
                                if (observer_ != null)
                                {
                                    observer_.reply(os_.size() - Protocol.headerSize - 4);
                                }
                                connection_.sendResponse(os_, compress_);
                            }
                            else
                            {
                                connection_.sendNoResponse();
                            }

                            if (observer_ != null)
                            {
                                observer_.detach();
                                observer_ = null;
                            }
                            connection_ = null;
                            return;
                        }
                        catch (System.Exception ex)
                        {
                            _is.skipEncaps(); // Required for batch requests.
                            handleException__(ex);
                            return;
                        }
                    }
                }
            }

            try
            {
                if (servant_ != null)
                {
                    //
                    // DispatchAsync is a "pseudo dispatch status", used internally only
                    // to indicate async dispatch.
                    //
                    if (servant_.dispatch__(this, current_) == Ice.DispatchStatus.DispatchAsync)
                    {
                        //
                        // If this was an asynchronous dispatch, we're done here.
                        //
                        return;
                    }

                    if (locator_ != null && !servantLocatorFinished__())
                    {
                        return;
                    }
                }
                else
                {
                    //
                    // Skip the input parameters, this is required for reading
                    // the next batch request if dispatching batch requests.
                    //
                    _is.skipEncaps();

                    if (servantManager != null && servantManager.hasServant(current_.id))
                    {
                        throw new Ice.FacetNotExistException(current_.id, current_.facet, current_.operation);
                    }
                    else
                    {
                        throw new Ice.ObjectNotExistException(current_.id, current_.facet, current_.operation);
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (servant_ != null && locator_ != null && !servantLocatorFinished__())
                {
                    return;
                }
                handleException__(ex);
                return;
            }

            //
            // Don't put the code below into the try block above. Exceptions
            // in the code below are considered fatal, and must propagate to
            // the caller of this operation.
            //

            Debug.Assert(connection_ != null);

            if (response_)
            {
                if (observer_ != null)
                {
                    observer_.reply(os_.size() - Protocol.headerSize - 4);
                }
                connection_.sendResponse(os_, compress_);
            }
            else
            {
                connection_.sendNoResponse();
            }

            if (observer_ != null)
            {
                observer_.detach();
                observer_ = null;
            }
            connection_ = null;
        }
Exemplo n.º 8
0
 isSupported(Ice.EncodingVersion version, Ice.EncodingVersion supported) =>
 version.major == supported.major && version.minor <= supported.minor;
Exemplo n.º 9
0
        public Reference create(string s, string propertyPrefix)
        {
            if (s.Length == 0)
            {
                return(null);
            }

            const string delim = " \t\n\r";

            int beg;
            int end = 0;

            beg = IceUtilInternal.StringUtil.findFirstNotOf(s, delim, end);
            if (beg == -1)
            {
                Ice.ProxyParseException e = new Ice.ProxyParseException();
                e.str = "no non-whitespace characters found in `" + s + "'";
                throw e;
            }

            //
            // Extract the identity, which may be enclosed in single
            // or double quotation marks.
            //
            string idstr = null;

            end = IceUtilInternal.StringUtil.checkQuote(s, beg);
            if (end == -1)
            {
                Ice.ProxyParseException e = new Ice.ProxyParseException();
                e.str = "mismatched quotes around identity in `" + s + "'";
                throw e;
            }
            else if (end == 0)
            {
                end = IceUtilInternal.StringUtil.findFirstOf(s, delim + ":@", beg);
                if (end == -1)
                {
                    end = s.Length;
                }
                idstr = s.Substring(beg, end - beg);
            }
            else
            {
                beg++; // Skip leading quote
                idstr = s.Substring(beg, end - beg);
                end++; // Skip trailing quote
            }

            if (beg == end)
            {
                Ice.ProxyParseException e = new Ice.ProxyParseException();
                e.str = "no identity in `" + s + "'";
                throw e;
            }

            //
            // Parsing the identity may raise IdentityParseException.
            //
            Ice.Identity ident = instance_.stringToIdentity(idstr);

            if (ident.name.Length == 0)
            {
                //
                // An identity with an empty name and a non-empty
                // category is illegal.
                //
                if (ident.category.Length > 0)
                {
                    Ice.IllegalIdentityException e = new Ice.IllegalIdentityException();
                    e.id = ident;
                    throw e;
                }
                //
                // Treat a stringified proxy containing two double
                // quotes ("") the same as an empty string, i.e.,
                // a null proxy, but only if nothing follows the
                // quotes.
                //
                else if (IceUtilInternal.StringUtil.findFirstNotOf(s, delim, end) != -1)
                {
                    Ice.ProxyParseException e = new Ice.ProxyParseException();
                    e.str = "invalid characters after identity in `" + s + "'";
                    throw e;
                }
                else
                {
                    return(null);
                }
            }

            string facet = "";

            Reference.Mode mode   = Reference.Mode.ModeTwoway;
            bool           secure = false;

            Ice.EncodingVersion encoding = instance_.defaultsAndOverrides().defaultEncoding;
            Ice.ProtocolVersion protocol = Ice.Util.Protocol_1_0;
            string adapter = "";

            while (true)
            {
                beg = IceUtilInternal.StringUtil.findFirstNotOf(s, delim, end);
                if (beg == -1)
                {
                    break;
                }

                if (s[beg] == ':' || s[beg] == '@')
                {
                    break;
                }

                end = IceUtilInternal.StringUtil.findFirstOf(s, delim + ":@", beg);
                if (end == -1)
                {
                    end = s.Length;
                }

                if (beg == end)
                {
                    break;
                }

                string option = s.Substring(beg, end - beg);
                if (option.Length != 2 || option[0] != '-')
                {
                    Ice.ProxyParseException e = new Ice.ProxyParseException();
                    e.str = "expected a proxy option but found `" + option + "' in `" + s + "'";
                    throw e;
                }

                //
                // Check for the presence of an option argument. The
                // argument may be enclosed in single or double
                // quotation marks.
                //
                string argument    = null;
                int    argumentBeg = IceUtilInternal.StringUtil.findFirstNotOf(s, delim, end);
                if (argumentBeg != -1)
                {
                    char ch = s[argumentBeg];
                    if (ch != '@' && ch != ':' && ch != '-')
                    {
                        beg = argumentBeg;
                        end = IceUtilInternal.StringUtil.checkQuote(s, beg);
                        if (end == -1)
                        {
                            Ice.ProxyParseException e = new Ice.ProxyParseException();
                            e.str = "mismatched quotes around value for " + option + " option in `" + s + "'";
                            throw e;
                        }
                        else if (end == 0)
                        {
                            end = IceUtilInternal.StringUtil.findFirstOf(s, delim + ":@", beg);
                            if (end == -1)
                            {
                                end = s.Length;
                            }
                            argument = s.Substring(beg, end - beg);
                        }
                        else
                        {
                            beg++; // Skip leading quote
                            argument = s.Substring(beg, end - beg);
                            end++; // Skip trailing quote
                        }
                    }
                }

                //
                // If any new options are added here,
                // IceInternal::Reference::toString() and its derived classes must be updated as well.
                //
                switch (option[1])
                {
                case 'f':
                {
                    if (argument == null)
                    {
                        Ice.ProxyParseException e = new Ice.ProxyParseException();
                        e.str = "no argument provided for -f option in `" + s + "'";
                        throw e;
                    }

                    try
                    {
                        facet = IceUtilInternal.StringUtil.unescapeString(argument, 0, argument.Length);
                    }
                    catch (System.ArgumentException argEx)
                    {
                        Ice.ProxyParseException e = new Ice.ProxyParseException();
                        e.str = "invalid facet in `" + s + "': " + argEx.Message;
                        throw e;
                    }
                    break;
                }

                case 't':
                {
                    if (argument != null)
                    {
                        Ice.ProxyParseException e = new Ice.ProxyParseException();
                        e.str = "unexpected argument `" + argument + "' provided for -t option in `" + s + "'";
                        throw e;
                    }
                    mode = Reference.Mode.ModeTwoway;
                    break;
                }

                case 'o':
                {
                    if (argument != null)
                    {
                        Ice.ProxyParseException e = new Ice.ProxyParseException();
                        e.str = "unexpected argument `" + argument + "' provided for -o option in `" + s + "'";
                        throw e;
                    }
                    mode = Reference.Mode.ModeOneway;
                    break;
                }

                case 'O':
                {
                    if (argument != null)
                    {
                        Ice.ProxyParseException e = new Ice.ProxyParseException();
                        e.str = "unexpected argument `" + argument + "' provided for -O option in `" + s + "'";
                        throw e;
                    }
                    mode = Reference.Mode.ModeBatchOneway;
                    break;
                }

                case 'd':
                {
                    if (argument != null)
                    {
                        Ice.ProxyParseException e = new Ice.ProxyParseException();
                        e.str = "unexpected argument `" + argument + "' provided for -d option in `" + s + "'";
                        throw e;
                    }
                    mode = Reference.Mode.ModeDatagram;
                    break;
                }

                case 'D':
                {
                    if (argument != null)
                    {
                        Ice.ProxyParseException e = new Ice.ProxyParseException();
                        e.str = "unexpected argument `" + argument + "' provided for -D option in `" + s + "'";
                        throw e;
                    }
                    mode = Reference.Mode.ModeBatchDatagram;
                    break;
                }

                case 's':
                {
                    if (argument != null)
                    {
                        Ice.ProxyParseException e = new Ice.ProxyParseException();
                        e.str = "unexpected argument `" + argument + "' provided for -s option in `" + s + "'";
                        throw e;
                    }
                    secure = true;
                    break;
                }

                case 'e':
                {
                    if (argument == null)
                    {
                        throw new Ice.ProxyParseException("no argument provided for -e option `" + s + "'");
                    }

                    try
                    {
                        encoding = Ice.Util.stringToEncodingVersion(argument);
                    }
                    catch (Ice.VersionParseException e)
                    {
                        throw new Ice.ProxyParseException("invalid encoding version `" + argument + "' in `" + s +
                                                          "':\n" + e.str);
                    }
                    break;
                }

                case 'p':
                {
                    if (argument == null)
                    {
                        throw new Ice.ProxyParseException("no argument provided for -p option `" + s + "'");
                    }

                    try
                    {
                        protocol = Ice.Util.stringToProtocolVersion(argument);
                    }
                    catch (Ice.VersionParseException e)
                    {
                        throw new Ice.ProxyParseException("invalid protocol version `" + argument + "' in `" + s +
                                                          "':\n" + e.str);
                    }
                    break;
                }

                default:
                {
                    Ice.ProxyParseException e = new Ice.ProxyParseException();
                    e.str = "unknown option `" + option + "' in `" + s + "'";
                    throw e;
                }
                }
            }

            if (beg == -1)
            {
                return(create(ident, facet, mode, secure, protocol, encoding, null, null, propertyPrefix));
            }

            List <EndpointI> endpoints = new List <EndpointI>();

            if (s[beg] == ':')
            {
                List <string> unknownEndpoints = new List <string>();
                end = beg;

                while (end < s.Length && s[end] == ':')
                {
                    beg = end + 1;

                    end = beg;
                    while (true)
                    {
                        end = s.IndexOf(':', end);
                        if (end == -1)
                        {
                            end = s.Length;
                            break;
                        }
                        else
                        {
                            bool quoted = false;
                            int  quote  = beg;
                            while (true)
                            {
                                quote = s.IndexOf((System.Char) '\"', quote);
                                if (quote == -1 || end < quote)
                                {
                                    break;
                                }
                                else
                                {
                                    quote = s.IndexOf((System.Char) '\"', ++quote);
                                    if (quote == -1)
                                    {
                                        break;
                                    }
                                    else if (end < quote)
                                    {
                                        quoted = true;
                                        break;
                                    }
                                    ++quote;
                                }
                            }
                            if (!quoted)
                            {
                                break;
                            }
                            ++end;
                        }
                    }

                    string    es   = s.Substring(beg, end - beg);
                    EndpointI endp = instance_.endpointFactoryManager().create(es, false);
                    if (endp != null)
                    {
                        endpoints.Add(endp);
                    }
                    else
                    {
                        unknownEndpoints.Add(es);
                    }
                }
                if (endpoints.Count == 0)
                {
                    Debug.Assert(unknownEndpoints.Count > 0);
                    Ice.EndpointParseException e2 = new Ice.EndpointParseException();
                    e2.str = "invalid endpoint `" + unknownEndpoints[0] + "' in `" + s + "'";
                    throw e2;
                }
                else if (unknownEndpoints.Count != 0 &&
                         instance_.initializationData().properties.getPropertyAsIntWithDefault(
                             "Ice.Warn.Endpoints", 1) > 0)
                {
                    StringBuilder msg = new StringBuilder("Proxy contains unknown endpoints:");
                    int           sz  = unknownEndpoints.Count;
                    for (int idx = 0; idx < sz; ++idx)
                    {
                        msg.Append(" `");
                        msg.Append((string)unknownEndpoints[idx]);
                        msg.Append("'");
                    }
                    instance_.initializationData().logger.warning(msg.ToString());
                }

                EndpointI[] ep = endpoints.ToArray();
                return(create(ident, facet, mode, secure, protocol, encoding, ep, null, propertyPrefix));
            }
            else if (s[beg] == '@')
            {
                beg = IceUtilInternal.StringUtil.findFirstNotOf(s, delim, beg + 1);
                if (beg == -1)
                {
                    Ice.ProxyParseException e = new Ice.ProxyParseException();
                    e.str = "missing adapter id in `" + s + "'";
                    throw e;
                }

                string adapterstr = null;
                end = IceUtilInternal.StringUtil.checkQuote(s, beg);
                if (end == -1)
                {
                    Ice.ProxyParseException e = new Ice.ProxyParseException();
                    e.str = "mismatched quotes around adapter id in `" + s + "'";
                    throw e;
                }
                else if (end == 0)
                {
                    end = IceUtilInternal.StringUtil.findFirstOf(s, delim, beg);
                    if (end == -1)
                    {
                        end = s.Length;
                    }
                    adapterstr = s.Substring(beg, end - beg);
                }
                else
                {
                    beg++; // Skip leading quote
                    adapterstr = s.Substring(beg, end - beg);
                    end++; // Skip trailing quote
                }

                if (end != s.Length && IceUtilInternal.StringUtil.findFirstNotOf(s, delim, end) != -1)
                {
                    Ice.ProxyParseException e = new Ice.ProxyParseException();
                    e.str = "invalid trailing characters after `" + s.Substring(0, end + 1) + "' in `" + s + "'";
                    throw e;
                }

                try
                {
                    adapter = IceUtilInternal.StringUtil.unescapeString(adapterstr, 0, adapterstr.Length);
                }
                catch (System.ArgumentException argEx)
                {
                    Ice.ProxyParseException e = new Ice.ProxyParseException();
                    e.str = "invalid adapter id in `" + s + "': " + argEx.Message;
                    throw e;
                }
                if (adapter.Length == 0)
                {
                    Ice.ProxyParseException e = new Ice.ProxyParseException();
                    e.str = "empty adapter id in `" + s + "'";
                    throw e;
                }
                return(create(ident, facet, mode, secure, protocol, encoding, null, adapter, propertyPrefix));
            }

            Ice.ProxyParseException ex = new Ice.ProxyParseException();
            ex.str = "malformed proxy `" + s + "'";
            throw ex;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Skips an empty encapsulation.
        /// </summary>
        /// <returns>The encapsulation's encoding version.</returns>
        public EncodingVersion skipEmptyEncapsulation()
        {
            int sz = readInt();
            if(sz < 6)
            {
                throw new Ice.EncapsulationException();
            }
            if(sz - 4 > _buf.b.remaining())
            {
                throw new Ice.UnmarshalOutOfBoundsException();
            }

            Ice.EncodingVersion encoding = new Ice.EncodingVersion();
            encoding.read__(this);
            if(encoding.Equals(Ice.Util.Encoding_1_0))
            {
                if(sz != 6)
                {
                    throw new Ice.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;
        }
Exemplo n.º 11
0
 isSupported(Ice.EncodingVersion version, Ice.EncodingVersion supported)
 {
     return(version.major == supported.major && version.minor <= supported.minor);
 }
Exemplo n.º 12
0
        protected override bool checkOption(string option, string argument, string endpoint)
        {
            if (base.checkOption(option, argument, endpoint))
            {
                return(true);
            }

            if (option.Equals("-c"))
            {
                if (argument != null)
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException();
                    e.str = "unexpected argument `" + argument + "' provided for -c option in " + endpoint;
                    throw e;
                }

                _connect = true;
            }
            else if (option.Equals("-z"))
            {
                if (argument != null)
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException();
                    e.str = "unexpected argument `" + argument + "' provided for -z option in " + endpoint;
                    throw e;
                }

                _compress = true;
            }
            else if (option.Equals("-v") || option.Equals("-e"))
            {
                if (argument == null)
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException();
                    e.str = "no argument provided for " + option + " option in endpoint " + endpoint;
                    throw e;
                }

                try
                {
                    Ice.EncodingVersion v = Ice.Util.stringToEncodingVersion(argument);
                    if (v.major != 1 || v.minor != 0)
                    {
                        instance_.logger().warning("deprecated udp endpoint option: " + option);
                    }
                }
                catch (Ice.VersionParseException ex)
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException();
                    e.str = "invalid version `" + argument + "' in endpoint " + endpoint + ":\n" + ex.str;
                    throw e;
                }
            }
            else if (option.Equals("--ttl"))
            {
                if (argument == null)
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException();
                    e.str = "no argument provided for --ttl option in endpoint " + endpoint;
                    throw e;
                }

                try
                {
                    _mcastTtl = int.Parse(argument, CultureInfo.InvariantCulture);
                }
                catch (FormatException ex)
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException(ex);
                    e.str = "invalid TTL value `" + argument + "' in endpoint " + endpoint;
                    throw e;
                }

                if (_mcastTtl < 0)
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException();
                    e.str = "TTL value `" + argument + "' out of range in endpoint " + endpoint;
                    throw e;
                }
            }
            else if (option.Equals("--interface"))
            {
                if (argument == null)
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException();
                    e.str = "no argument provided for --interface option in endpoint " + endpoint;
                    throw e;
                }
                _mcastInterface = argument;
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 13
0
        protected override bool checkOption(string option, string argument, string endpoint)
        {
            switch(option[1])
            {
            case 't':
            {
                if(_type > -1)
                {
                    throw new Ice.EndpointParseException("multiple -t options in endpoint " + endpoint);
                }
                if(argument == null)
                {
                    throw new Ice.EndpointParseException("no argument provided for -t option in endpoint " + endpoint);
                }

                int t;
                try
                {
                    t = System.Int32.Parse(argument, CultureInfo.InvariantCulture);
                }
                catch(System.FormatException)
                {
                    throw new Ice.EndpointParseException("invalid type value `" + argument + "' in endpoint " +
                                                         endpoint);
                }

                if(t < 0 || t > 65535)
                {
                    throw new Ice.EndpointParseException("type value `" + argument + "' out of range in endpoint " +
                                                         endpoint);
                }

                _type = (short)t;
                return true;
            }

            case 'v':
            {
                if(_rawBytes.Length > 0)
                {
                    throw new Ice.EndpointParseException("multiple -v options in endpoint " + endpoint);
                }
                if(argument == null)
                {
                    throw new Ice.EndpointParseException("no argument provided for -v option in endpoint " + endpoint);
                }

                for(int j = 0; j < argument.Length; ++j)
                {
                    if(!IceUtilInternal.Base64.isBase64(argument[j]))
                    {
                        throw new Ice.EndpointParseException("invalid base64 character `" + argument[j] +
                                                             "' (ordinal " + ((int)argument[j]) +
                                                             ") in endpoint " + endpoint);
                    }
                }
                _rawBytes = IceUtilInternal.Base64.decode(argument);
                return true;
            }

            case 'e':
            {
                if(argument == null)
                {
                    throw new Ice.EndpointParseException("no argument provided for -e option in endpoint " + endpoint);
                }

                try
                {
                    _rawEncoding = Ice.Util.stringToEncodingVersion(argument);
                }
                catch(Ice.VersionParseException e)
                {
                    throw new Ice.EndpointParseException("invalid encoding version `" + argument +
                                                         "' in endpoint " + endpoint + ":\n" + e.str);
                }
                return true;
            }

            default:
            {
                return false;
            }
            }
        }
Exemplo n.º 14
0
        public Reference create(Ice.Identity ident, Ice.InputStream s)
        {
            //
            // Don't read the identity here. Operations calling this
            // constructor read the identity, and pass it as a parameter.
            //

            if(ident.name.Length == 0 && ident.category.Length == 0)
            {
                return null;
            }

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = s.readStringSeq();
            string facet;
            if(facetPath.Length > 0)
            {
                if(facetPath.Length > 1)
                {
                    throw new Ice.ProxyUnmarshalException();
                }
                facet = facetPath[0];
            }
            else
            {
                facet = "";
            }

            int mode = (int)s.readByte();
            if(mode < 0 || mode > (int)Reference.Mode.ModeLast)
            {
                throw new Ice.ProxyUnmarshalException();
            }

            bool secure = s.readBool();

            Ice.ProtocolVersion protocol;
            Ice.EncodingVersion encoding;
            if(!s.getEncoding().Equals(Ice.Util.Encoding_1_0))
            {
                protocol = new Ice.ProtocolVersion();
                protocol.read__(s);
                encoding = new Ice.EncodingVersion();
                encoding.read__(s);
            }
            else
            {
                protocol = Ice.Util.Protocol_1_0;
                encoding = Ice.Util.Encoding_1_0;
            }

            EndpointI[] endpoints = null;
            string adapterId = "";

            int sz = s.readSize();
            if(sz > 0)
            {
                endpoints = new EndpointI[sz];
                for(int i = 0; i < sz; i++)
                {
                    endpoints[i] = instance_.endpointFactoryManager().read(s);
                }
            }
            else
            {
                adapterId = s.readString();
            }

            return create(ident, facet, (Reference.Mode)mode, secure, protocol, encoding, endpoints, adapterId, null);
        }
Exemplo n.º 15
0
 internal void setEncoding(Ice.EncodingVersion encoding)
 {
     this.encoding = encoding;
     encoding_1_0 = encoding.Equals(Ice.Util.Encoding_1_0);
 }
Exemplo n.º 16
0
 private void initialize(EncodingVersion encoding)
 {
     instance_ = null;
     _encoding = encoding;
     _encapsStack = null;
     _encapsCache = null;
     _traceSlicing = false;
     _closure = null;
     _sliceValues = true;
     _startSeq = -1;
     _minSeqSize = 0;
 }
Exemplo n.º 17
0
        /// <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;
        }
Exemplo n.º 18
0
 public InfoI(short type, Ice.EncodingVersion rawEncoding, byte[] rawBytes) :
     base(null, -1, false, rawEncoding, rawBytes)
 {
     _type = type;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Converts an encoding version to a string.
 /// </summary>
 /// <param name="v">The encoding version to convert.</param>
 /// <returns>The converted string.</returns>
 public static string encodingVersionToString(Ice.EncodingVersion v)
 {
     return(majorMinorToString(v.major, v.minor));
 }
Exemplo n.º 20
0
 public LocatorKey(Ice.LocatorPrx prx)
 {
     Reference r = ((Ice.ObjectPrxHelperBase)prx).reference__();
     _id = r.getIdentity();
     _encoding = r.getEncoding();
 }
Exemplo n.º 21
0
        private static void printReply(System.IO.StringWriter s, Ice.InputStream str)
        {
            int requestId = str.readInt();

            s.Write("\nrequest id = " + requestId);

            byte replyStatus = str.readByte();

            s.Write("\nreply status = " + (int)replyStatus + ' ');

            switch (replyStatus)
            {
            case ReplyStatus.replyOK:
            {
                s.Write("(ok)");
                break;
            }

            case ReplyStatus.replyUserException:
            {
                s.Write("(user exception)");
                break;
            }

            case ReplyStatus.replyObjectNotExist:
            case ReplyStatus.replyFacetNotExist:
            case ReplyStatus.replyOperationNotExist:
            {
                switch (replyStatus)
                {
                case ReplyStatus.replyObjectNotExist:
                {
                    s.Write("(object not exist)");
                    break;
                }

                case ReplyStatus.replyFacetNotExist:
                {
                    s.Write("(facet not exist)");
                    break;
                }

                case ReplyStatus.replyOperationNotExist:
                {
                    s.Write("(operation not exist)");
                    break;
                }

                default:
                {
                    Debug.Assert(false);
                    break;
                }
                }

                printIdentityFacetOperation(s, str);
                break;
            }

            case ReplyStatus.replyUnknownException:
            case ReplyStatus.replyUnknownLocalException:
            case ReplyStatus.replyUnknownUserException:
            {
                switch (replyStatus)
                {
                case ReplyStatus.replyUnknownException:
                {
                    s.Write("(unknown exception)");
                    break;
                }

                case ReplyStatus.replyUnknownLocalException:
                {
                    s.Write("(unknown local exception)");
                    break;
                }

                case ReplyStatus.replyUnknownUserException:
                {
                    s.Write("(unknown user exception)");
                    break;
                }

                default:
                {
                    Debug.Assert(false);
                    break;
                }
                }

                string unknown = str.readString();
                s.Write("\nunknown = " + unknown);
                break;
            }

            default:
            {
                s.Write("(unknown)");
                break;
            }
            }

            if (replyStatus == ReplyStatus.replyOK || replyStatus == ReplyStatus.replyUserException)
            {
                Ice.EncodingVersion v = str.skipEncapsulation();
                if (!v.Equals(Ice.Util.Encoding_1_0))
                {
                    s.Write("\nencoding = ");
                    s.Write(Ice.Util.encodingVersionToString(v));
                }
            }
        }
Exemplo n.º 22
0
        public UdpEndpointI(Instance instance, string str, bool oaEndpoint) : base("")
        {
            instance_ = instance;
            _host     = null;
            _port     = 0;
            _connect  = false;
            _compress = false;

            string delim = " \t\n\r";

            int beg;
            int end = 0;

            while (true)
            {
                beg = IceUtilInternal.StringUtil.findFirstNotOf(str, delim, end);
                if (beg == -1)
                {
                    break;
                }

                end = IceUtilInternal.StringUtil.findFirstOf(str, delim, beg);
                if (end == -1)
                {
                    end = str.Length;
                }

                string option = str.Substring(beg, end - beg);
                if (option[0] != '-')
                {
                    Ice.EndpointParseException e = new Ice.EndpointParseException();
                    e.str = "expected an endpoint option but found `" + option + "' in endpoint `udp " + str + "'";
                    throw e;
                }

                string argument    = null;
                int    argumentBeg = IceUtilInternal.StringUtil.findFirstNotOf(str, delim, end);
                if (argumentBeg != -1 && str[argumentBeg] != '-')
                {
                    beg = argumentBeg;
                    if (str[beg] == '\"')
                    {
                        end = IceUtilInternal.StringUtil.findFirstOf(str, "\"", beg + 1);
                        if (end == -1)
                        {
                            Ice.EndpointParseException e = new Ice.EndpointParseException();
                            e.str = "mismatched quotes around `" + argument + "' in endpoint `udp " + str + "'";
                            throw e;
                        }
                        else
                        {
                            ++end;
                        }
                    }
                    else
                    {
                        end = IceUtilInternal.StringUtil.findFirstOf(str, delim, beg);
                        if (end == -1)
                        {
                            end = str.Length;
                        }
                    }
                    argument = str.Substring(beg, end - beg);
                    if (argument[0] == '\"' && argument[argument.Length - 1] == '\"')
                    {
                        argument = argument.Substring(1, argument.Length - 2);
                    }
                }

                if (option.Equals("-h"))
                {
                    if (argument == null)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "no argument provided for -h option in endpoint `udp " + str + "'";
                        throw e;
                    }

                    _host = argument;
                }
                else if (option.Equals("-p"))
                {
                    if (argument == null)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "no argument provided for -p option in endpoint `udp " + str + "'";
                        throw e;
                    }

                    try
                    {
                        _port = System.Int32.Parse(argument, CultureInfo.InvariantCulture);
                    }
                    catch (System.FormatException ex)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException(ex);
                        e.str = "invalid port value `" + argument + "' in endpoint `udp " + str + "'";
                        throw e;
                    }

                    if (_port < 0 || _port > 65535)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "port value `" + argument + "' out of range in endpoint `udp " + str + "'";
                        throw e;
                    }
                }
                else if (option.Equals("-c"))
                {
                    if (argument != null)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "unexpected argument `" + argument + "' provided for -c option in `udp " + str + "'";
                        throw e;
                    }

                    _connect = true;
                }
                else if (option.Equals("-z"))
                {
                    if (argument != null)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "unexpected argument `" + argument + "' provided for -z option in `udp " + str + "'";
                        throw e;
                    }

                    _compress = true;
                }
                else if (option.Equals("-v") || option.Equals("-e"))
                {
                    if (argument == null)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "no argument provided for " + option + " option in endpoint " + "`udp " + str + "'";
                        throw e;
                    }

                    try
                    {
                        Ice.EncodingVersion v = Ice.Util.stringToEncodingVersion(argument);
                        if (v.major != 1 || v.minor != 0)
                        {
                            instance_.initializationData().logger.warning("deprecated udp endpoint option: " + option);
                        }
                    }
                    catch (Ice.VersionParseException ex)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "invalid version `" + argument + "' in endpoint `udp " + str + "':\n" + ex.str;
                        throw e;
                    }
                }
                else if (option.Equals("--interface"))
                {
                    if (argument == null)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "no argument provided for --interface option in endpoint `udp " + str + "'";
                        throw e;
                    }

                    _mcastInterface = argument;
                }
                else if (option.Equals("--ttl"))
                {
                    if (argument == null)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "no argument provided for --ttl option in endpoint `udp " + str + "'";
                        throw e;
                    }

                    try
                    {
                        _mcastTtl = System.Int32.Parse(argument, CultureInfo.InvariantCulture);
                    }
                    catch (System.FormatException ex)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException(ex);
                        e.str = "invalid TTL value `" + argument + "' in endpoint `udp " + str + "'";
                        throw e;
                    }

                    if (_mcastTtl < 0)
                    {
                        Ice.EndpointParseException e = new Ice.EndpointParseException();
                        e.str = "TTL value `" + argument + "' out of range in endpoint `udp " + str + "'";
                        throw e;
                    }
                }
                else
                {
                    parseOption(option, argument, "udp", str);
                }
            }

            if (_host == null)
            {
                _host = instance_.defaultsAndOverrides().defaultHost;
            }
            else if (_host.Equals("*"))
            {
                if (oaEndpoint)
                {
                    _host = null;
                }
                else
                {
                    throw new Ice.EndpointParseException("`-h *' not valid for proxy endpoint `udp " + str + "'");
                }
            }

            if (_host == null)
            {
                _host = "";
            }

            calcHashValue();
        }
Exemplo n.º 23
0
        public Reference create(Ice.Identity ident, Ice.InputStream s)
        {
            //
            // Don't read the identity here. Operations calling this
            // constructor read the identity, and pass it as a parameter.
            //

            if (ident.name.Length == 0 && ident.category.Length == 0)
            {
                return(null);
            }

            //
            // For compatibility with the old FacetPath.
            //
            string[] facetPath = s.readStringSeq();
            string   facet;

            if (facetPath.Length > 0)
            {
                if (facetPath.Length > 1)
                {
                    throw new Ice.ProxyUnmarshalException();
                }
                facet = facetPath[0];
            }
            else
            {
                facet = "";
            }

            int mode = (int)s.readByte();

            if (mode < 0 || mode > (int)Reference.Mode.ModeLast)
            {
                throw new Ice.ProxyUnmarshalException();
            }

            bool secure = s.readBool();

            Ice.ProtocolVersion protocol;
            Ice.EncodingVersion encoding;
            if (!s.getEncoding().Equals(Ice.Util.Encoding_1_0))
            {
                protocol = new Ice.ProtocolVersion();
                protocol.read__(s);
                encoding = new Ice.EncodingVersion();
                encoding.read__(s);
            }
            else
            {
                protocol = Ice.Util.Protocol_1_0;
                encoding = Ice.Util.Encoding_1_0;
            }

            EndpointI[] endpoints = null;
            string      adapterId = "";

            int sz = s.readSize();

            if (sz > 0)
            {
                endpoints = new EndpointI[sz];
                for (int i = 0; i < sz; i++)
                {
                    endpoints[i] = instance_.endpointFactoryManager().read(s);
                }
            }
            else
            {
                adapterId = s.readString();
            }

            return(create(ident, facet, (Reference.Mode)mode, secure, protocol, encoding, endpoints, adapterId, null));
        }
Exemplo n.º 24
0
    public static Test.MyClassPrx allTests(Ice.Communicator communicator)
    {
        Write("testing stringToProxy... ");
        Flush();
        string rf = "test:default -p 12010";
        Ice.ObjectPrx baseProxy = communicator.stringToProxy(rf);
        test(baseProxy != null);

        Ice.ObjectPrx b1 = communicator.stringToProxy("test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getAdapterId().Length == 0 && b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy("test ");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy(" test ");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy(" test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy("'test -f facet'");
        test(b1.ice_getIdentity().name.Equals("test -f facet") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        try
        {
            b1 = communicator.stringToProxy("\"test -f facet'");
            test(false);
        }
        catch(Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("\"test -f facet\"");
        test(b1.ice_getIdentity().name.Equals("test -f facet") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy("\"test -f facet@test\"");
        test(b1.ice_getIdentity().name.Equals("test -f facet@test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        b1 = communicator.stringToProxy("\"test -f facet@test @test\"");
        test(b1.ice_getIdentity().name.Equals("test -f facet@test @test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Length == 0);
        try
        {
            b1 = communicator.stringToProxy("test test");
            test(false);
        }
        catch(Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("test\\040test");
        test(b1.ice_getIdentity().name.Equals("test test") && b1.ice_getIdentity().category.Length == 0);
        try
        {
            b1 = communicator.stringToProxy("test\\777");
            test(false);
        }
        catch(Ice.IdentityParseException)
        {
        }
        b1 = communicator.stringToProxy("test\\40test");
        test(b1.ice_getIdentity().name.Equals("test test"));

        // Test some octal and hex corner cases.
        b1 = communicator.stringToProxy("test\\4test");
        test(b1.ice_getIdentity().name.Equals("test\u0004test"));
        b1 = communicator.stringToProxy("test\\04test");
        test(b1.ice_getIdentity().name.Equals("test\u0004test"));
        b1 = communicator.stringToProxy("test\\004test");
        test(b1.ice_getIdentity().name.Equals("test\u0004test"));
        b1 = communicator.stringToProxy("test\\1114test");
        test(b1.ice_getIdentity().name.Equals("test\u00494test"));

        b1 = communicator.stringToProxy("test\\b\\f\\n\\r\\t\\'\\\"\\\\test");
        test(b1.ice_getIdentity().name.Equals("test\b\f\n\r\t\'\"\\test") && b1.ice_getIdentity().category.Length == 0);

        b1 = communicator.stringToProxy("category/test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Length == 0);

        b1 = communicator.stringToProxy("");
        test(b1 == null);
        b1 = communicator.stringToProxy("\"\"");
        test(b1 == null);
        try
        {
            b1 = communicator.stringToProxy("\"\" test"); // Invalid trailing characters.
            test(false);
        }
        catch(Ice.ProxyParseException)
        {
        }
        try
        {
            b1 = communicator.stringToProxy("test:"); // Missing endpoint.
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        b1 = communicator.stringToProxy("test@adapter");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getAdapterId().Equals("adapter"));
        try
        {
            b1 = communicator.stringToProxy("id@adapter test");
            test(false);
        }
        catch(Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("category/test@adapter");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Equals("adapter"));
        b1 = communicator.stringToProxy("category/test@adapter:tcp");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Equals("adapter:tcp"));
        b1 = communicator.stringToProxy("'category 1/test'@adapter");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category 1") &&
             b1.ice_getAdapterId().Equals("adapter"));
        b1 = communicator.stringToProxy("'category/test 1'@adapter");
        test(b1.ice_getIdentity().name.Equals("test 1") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Equals("adapter"));
        b1 = communicator.stringToProxy("'category/test'@'adapter 1'");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category") &&
             b1.ice_getAdapterId().Equals("adapter 1"));
        b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@adapter");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category /test@foo") &&
             b1.ice_getAdapterId().Equals("adapter"));
        b1 = communicator.stringToProxy("\"category \\/test@foo/test\"@\"adapter:tcp\"");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Equals("category /test@foo") &&
             b1.ice_getAdapterId().Equals("adapter:tcp"));

        b1 = communicator.stringToProxy("id -f facet");
        test(b1.ice_getIdentity().name.Equals("id") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet"));
        b1 = communicator.stringToProxy("id -f 'facet x'");
        test(b1.ice_getIdentity().name.Equals("id") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet x"));
        b1 = communicator.stringToProxy("id -f \"facet x\"");
        test(b1.ice_getIdentity().name.Equals("id") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet x"));
        try
        {
            b1 = communicator.stringToProxy("id -f \"facet x");
            test(false);
        }
        catch(Ice.ProxyParseException)
        {
        }
        try
        {
            b1 = communicator.stringToProxy("id -f \'facet x");
            test(false);
        }
        catch(Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("test -f facet:tcp");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet") && b1.ice_getAdapterId().Length == 0);
        b1 = communicator.stringToProxy("test -f \"facet:tcp\"");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet:tcp") && b1.ice_getAdapterId().Length == 0);
        b1 = communicator.stringToProxy("test -f facet@test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet") && b1.ice_getAdapterId().Equals("test"));
        b1 = communicator.stringToProxy("test -f 'facet@test'");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet@test") && b1.ice_getAdapterId().Length == 0);
        b1 = communicator.stringToProxy("test -f 'facet@test'@test");
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getFacet().Equals("facet@test") && b1.ice_getAdapterId().Equals("test"));
        try
        {
            b1 = communicator.stringToProxy("test -f facet@test @test");
            test(false);
        }
        catch(Ice.ProxyParseException)
        {
        }
        b1 = communicator.stringToProxy("test");
        test(b1.ice_isTwoway());
        b1 = communicator.stringToProxy("test -t");
        test(b1.ice_isTwoway());
        b1 = communicator.stringToProxy("test -o");
        test(b1.ice_isOneway());
        b1 = communicator.stringToProxy("test -O");
        test(b1.ice_isBatchOneway());
        b1 = communicator.stringToProxy("test -d");
        test(b1.ice_isDatagram());
        b1 = communicator.stringToProxy("test -D");
        test(b1.ice_isBatchDatagram());
        b1 = communicator.stringToProxy("test");
        test(!b1.ice_isSecure());
        b1 = communicator.stringToProxy("test -s");
        test(b1.ice_isSecure());

        test(b1.ice_getEncodingVersion().Equals(Ice.Util.currentEncoding));

        b1 = communicator.stringToProxy("test -e 1.0");
        test(b1.ice_getEncodingVersion().major == 1 && b1.ice_getEncodingVersion().minor == 0);

        b1 = communicator.stringToProxy("test -e 6.5");
        test(b1.ice_getEncodingVersion().major == 6 && b1.ice_getEncodingVersion().minor == 5);

        b1 = communicator.stringToProxy("test -p 1.0 -e 1.0");
        test(b1.ToString().Equals("test -t -e 1.0"));

        b1 = communicator.stringToProxy("test -p 6.5 -e 1.0");
        test(b1.ToString().Equals("test -t -p 6.5 -e 1.0"));

        try
        {
            b1 = communicator.stringToProxy("test:tcp@adapterId");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }
        // This is an unknown endpoint warning, not a parse exception.
        //
        //try
        //{
        //   b1 = communicator.stringToProxy("test -f the:facet:tcp");
        //   test(false);
        //}
        //catch(Ice.EndpointParseException)
        //{
        //}
        try
        {
            b1 = communicator.stringToProxy("test::tcp");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        //
        // Test for bug ICE-5543: escaped escapes in stringToIdentity
        //
        Ice.Identity id = new Ice.Identity("test", ",X2QNUAzSBcJ_e$AV;E\\");
        Ice.Identity id2 = Ice.Util.stringToIdentity(Ice.Util.identityToString(id));
        test(id.Equals(id2));

        id = new Ice.Identity("test", ",X2QNUAz\\SB\\/cJ_e$AV;E\\\\");
        id2 = Ice.Util.stringToIdentity(Ice.Util.identityToString(id));
        test(id.Equals(id2));

        WriteLine("ok");

        Write("testing propertyToProxy... ");
        Flush();
        Ice.Properties prop = communicator.getProperties();
        String propertyPrefix = "Foo.Proxy";
        prop.setProperty(propertyPrefix, "test:default -p 12010");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getIdentity().name.Equals("test") && b1.ice_getIdentity().category.Length == 0 &&
             b1.ice_getAdapterId().Length == 0 && b1.ice_getFacet().Length == 0);

        string property;

        property = propertyPrefix + ".Locator";
        test(b1.ice_getLocator() == null);
        prop.setProperty(property, "locator:default -p 10000");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getLocator() != null && b1.ice_getLocator().ice_getIdentity().name.Equals("locator"));
        try
        {
            prop.setProperty(property, "");
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        property = propertyPrefix + ".LocatorCacheTimeout";
        test(b1.ice_getLocatorCacheTimeout() == -1);
        prop.setProperty(property, "1");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getLocatorCacheTimeout() == 1);
        prop.setProperty(property, "");

        // Now retest with an indirect proxy.
        prop.setProperty(propertyPrefix, "test");
        property = propertyPrefix + ".Locator";
        prop.setProperty(property, "locator:default -p 10000");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getLocator() != null && b1.ice_getLocator().ice_getIdentity().name.Equals("locator"));
        prop.setProperty(property, "");

        property = propertyPrefix + ".LocatorCacheTimeout";
        test(b1.ice_getLocatorCacheTimeout() == -1);
        prop.setProperty(property, "1");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getLocatorCacheTimeout() == 1);
        prop.setProperty(property, "");

        // This cannot be tested so easily because the property is cached
        // on communicator initialization.
        //
        //prop.setProperty("Ice.Default.LocatorCacheTimeout", "60");
        //b1 = communicator.propertyToProxy(propertyPrefix);
        //test(b1.ice_getLocatorCacheTimeout() == 60);
        //prop.setProperty("Ice.Default.LocatorCacheTimeout", "");

        prop.setProperty(propertyPrefix, "test:default -p 12010");

        property = propertyPrefix + ".Router";
        test(b1.ice_getRouter() == null);
        prop.setProperty(property, "router:default -p 10000");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getRouter() != null && b1.ice_getRouter().ice_getIdentity().name.Equals("router"));
        prop.setProperty(property, "");

        property = propertyPrefix + ".PreferSecure";
        test(!b1.ice_isPreferSecure());
        prop.setProperty(property, "1");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_isPreferSecure());
        prop.setProperty(property, "");

        property = propertyPrefix + ".ConnectionCached";
        test(b1.ice_isConnectionCached());
        prop.setProperty(property, "0");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(!b1.ice_isConnectionCached());
        prop.setProperty(property, "");

        property = propertyPrefix + ".InvocationTimeout";
        test(b1.ice_getInvocationTimeout() == -1);
        prop.setProperty(property, "1000");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getInvocationTimeout() == 1000);
        prop.setProperty(property, "");

        property = propertyPrefix + ".EndpointSelection";
        test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);
        prop.setProperty(property, "Random");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);
        prop.setProperty(property, "Ordered");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
        prop.setProperty(property, "");

        property = propertyPrefix + ".CollocationOptimized";
        test(b1.ice_isCollocationOptimized());
        prop.setProperty(property, "0");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(!b1.ice_isCollocationOptimized());
        prop.setProperty(property, "");

        property = propertyPrefix + ".Context.c1";
        test(!b1.ice_getContext().ContainsKey("c1"));
        prop.setProperty(property, "TEST");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getContext()["c1"].Equals("TEST"));

        property = propertyPrefix + ".Context.c2";
        test(!b1.ice_getContext().ContainsKey("c2"));
        prop.setProperty(property, "TEST");
        b1 = communicator.propertyToProxy(propertyPrefix);
        test(b1.ice_getContext()["c2"].Equals("TEST"));

        prop.setProperty(propertyPrefix + ".Context.c1", "");
        prop.setProperty(propertyPrefix + ".Context.c2", "");

        WriteLine("ok");

        Write("testing proxyToProperty... ");
        Flush();

        b1 = communicator.stringToProxy("test");
        b1 = b1.ice_collocationOptimized(true);
        b1 = b1.ice_connectionCached(true);
        b1 = b1.ice_preferSecure(false);
        b1 = b1.ice_endpointSelection(Ice.EndpointSelectionType.Ordered);
        b1 = b1.ice_locatorCacheTimeout(100);
        b1 = b1.ice_invocationTimeout(1234);
        b1 = b1.ice_encodingVersion(new Ice.EncodingVersion(1, 0));

        Ice.ObjectPrx router = communicator.stringToProxy("router");
        router = router.ice_collocationOptimized(false);
        router = router.ice_connectionCached(true);
        router = router.ice_preferSecure(true);
        router = router.ice_endpointSelection(Ice.EndpointSelectionType.Random);
        router = router.ice_locatorCacheTimeout(200);
        router = router.ice_invocationTimeout(1500);

        Ice.ObjectPrx locator = communicator.stringToProxy("locator");
        locator = locator.ice_collocationOptimized(true);
        locator = locator.ice_connectionCached(false);
        locator = locator.ice_preferSecure(true);
        locator = locator.ice_endpointSelection(Ice.EndpointSelectionType.Random);
        locator = locator.ice_locatorCacheTimeout(300);
        locator = locator.ice_invocationTimeout(1500);

        locator = locator.ice_router(Ice.RouterPrxHelper.uncheckedCast(router));
        b1 = b1.ice_locator(Ice.LocatorPrxHelper.uncheckedCast(locator));

        Dictionary<string, string> proxyProps = communicator.proxyToProperty(b1, "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 " + Ice.Util.encodingVersionToString(Ice.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 " + Ice.Util.encodingVersionToString(Ice.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"));

        WriteLine("ok");

        Write("testing ice_getCommunicator... ");
        Flush();
        test(baseProxy.ice_getCommunicator() == communicator);
        WriteLine("ok");

        Write("testing proxy methods... ");

        // Disable Obsolete warning/error
        #pragma warning disable 612, 618
        test(communicator.identityToString(
                 baseProxy.ice_identity(communicator.stringToIdentity("other")).ice_getIdentity()).Equals("other"));
        #pragma warning restore 612, 618
        test(Ice.Util.identityToString(
                 baseProxy.ice_identity(Ice.Util.stringToIdentity("other")).ice_getIdentity()).Equals("other"));
        test(baseProxy.ice_facet("facet").ice_getFacet().Equals("facet"));
        test(baseProxy.ice_adapterId("id").ice_getAdapterId().Equals("id"));
        test(baseProxy.ice_twoway().ice_isTwoway());
        test(baseProxy.ice_oneway().ice_isOneway());
        test(baseProxy.ice_batchOneway().ice_isBatchOneway());
        test(baseProxy.ice_datagram().ice_isDatagram());
        test(baseProxy.ice_batchDatagram().ice_isBatchDatagram());
        test(baseProxy.ice_secure(true).ice_isSecure());
        test(!baseProxy.ice_secure(false).ice_isSecure());
        test(baseProxy.ice_collocationOptimized(true).ice_isCollocationOptimized());
        test(!baseProxy.ice_collocationOptimized(false).ice_isCollocationOptimized());
        test(baseProxy.ice_preferSecure(true).ice_isPreferSecure());
        test(!baseProxy.ice_preferSecure(false).ice_isPreferSecure());

        try
        {
            baseProxy.ice_timeout(0);
            test(false);
        }
        catch(ArgumentException)
        {
        }

        try
        {
            baseProxy.ice_timeout(-1);
        }
        catch(ArgumentException)
        {
            test(false);
        }

        try
        {
            baseProxy.ice_timeout(-2);
            test(false);
        }
        catch(ArgumentException)
        {
        }

        try
        {
            baseProxy.ice_invocationTimeout(0);
            test(false);
        }
        catch(ArgumentException)
        {
        }

        try
        {
            baseProxy.ice_invocationTimeout(-1);
            baseProxy.ice_invocationTimeout(-2);
        }
        catch(ArgumentException)
        {
            test(false);
        }

        try
        {
            baseProxy.ice_invocationTimeout(-3);
            test(false);
        }
        catch(ArgumentException)
        {
        }

        try
        {
            baseProxy.ice_locatorCacheTimeout(0);
        }
        catch(ArgumentException)
        {
            test(false);
        }

        try
        {
            baseProxy.ice_locatorCacheTimeout(-1);
        }
        catch(ArgumentException)
        {
            test(false);
        }

        try
        {
            baseProxy.ice_locatorCacheTimeout(-2);
            test(false);
        }
        catch(ArgumentException)
        {
        }

        WriteLine("ok");

        Write("testing proxy comparison... ");
        Flush();

        test(communicator.stringToProxy("foo").Equals(communicator.stringToProxy("foo")));
        test(!communicator.stringToProxy("foo").Equals(communicator.stringToProxy("foo2")));

        Ice.ObjectPrx compObj = communicator.stringToProxy("foo");

        test(compObj.ice_facet("facet").Equals(compObj.ice_facet("facet")));
        test(!compObj.ice_facet("facet").Equals(compObj.ice_facet("facet1")));

        test(compObj.ice_oneway().Equals(compObj.ice_oneway()));
        test(!compObj.ice_oneway().Equals(compObj.ice_twoway()));

        test(compObj.ice_secure(true).Equals(compObj.ice_secure(true)));
        test(!compObj.ice_secure(false).Equals(compObj.ice_secure(true)));

        test(compObj.ice_collocationOptimized(true).Equals(compObj.ice_collocationOptimized(true)));
        test(!compObj.ice_collocationOptimized(false).Equals(compObj.ice_collocationOptimized(true)));

        test(compObj.ice_connectionCached(true).Equals(compObj.ice_connectionCached(true)));
        test(!compObj.ice_connectionCached(false).Equals(compObj.ice_connectionCached(true)));

        test(compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).Equals(
                 compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random)));
        test(!compObj.ice_endpointSelection(Ice.EndpointSelectionType.Random).Equals(
                 compObj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)));

        test(compObj.ice_connectionId("id2").Equals(compObj.ice_connectionId("id2")));
        test(!compObj.ice_connectionId("id1").Equals(compObj.ice_connectionId("id2")));
        test(compObj.ice_connectionId("id1").ice_getConnectionId().Equals("id1"));
        test(compObj.ice_connectionId("id2").ice_getConnectionId().Equals("id2"));

        test(compObj.ice_compress(true).Equals(compObj.ice_compress(true)));
        test(!compObj.ice_compress(false).Equals(compObj.ice_compress(true)));

        test(compObj.ice_timeout(20).Equals(compObj.ice_timeout(20)));
        test(!compObj.ice_timeout(10).Equals(compObj.ice_timeout(20)));

        Ice.LocatorPrx loc1 = Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("loc1:default -p 10000"));
        Ice.LocatorPrx loc2 = Ice.LocatorPrxHelper.uncheckedCast(communicator.stringToProxy("loc2:default -p 10000"));
        test(compObj.ice_locator(null).Equals(compObj.ice_locator(null)));
        test(compObj.ice_locator(loc1).Equals(compObj.ice_locator(loc1)));
        test(!compObj.ice_locator(loc1).Equals(compObj.ice_locator(null)));
        test(!compObj.ice_locator(null).Equals(compObj.ice_locator(loc2)));
        test(!compObj.ice_locator(loc1).Equals(compObj.ice_locator(loc2)));

        Ice.RouterPrx rtr1 = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("rtr1:default -p 10000"));
        Ice.RouterPrx rtr2 = Ice.RouterPrxHelper.uncheckedCast(communicator.stringToProxy("rtr2:default -p 10000"));
        test(compObj.ice_router(null).Equals(compObj.ice_router(null)));
        test(compObj.ice_router(rtr1).Equals(compObj.ice_router(rtr1)));
        test(!compObj.ice_router(rtr1).Equals(compObj.ice_router(null)));
        test(!compObj.ice_router(null).Equals(compObj.ice_router(rtr2)));
        test(!compObj.ice_router(rtr1).Equals(compObj.ice_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.ice_context(null).Equals(compObj.ice_context(null)));
        test(compObj.ice_context(ctx1).Equals(compObj.ice_context(ctx1)));
        test(!compObj.ice_context(ctx1).Equals(compObj.ice_context(null)));
        test(!compObj.ice_context(null).Equals(compObj.ice_context(ctx2)));
        test(!compObj.ice_context(ctx1).Equals(compObj.ice_context(ctx2)));

        test(compObj.ice_preferSecure(true).Equals(compObj.ice_preferSecure(true)));
        test(!compObj.ice_preferSecure(true).Equals(compObj.ice_preferSecure(false)));

        Ice.ObjectPrx compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000");
        Ice.ObjectPrx compObj2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001");
        test(!compObj1.Equals(compObj2));

        compObj1 = communicator.stringToProxy("foo@MyAdapter1");
        compObj2 = communicator.stringToProxy("foo@MyAdapter2");
        test(!compObj1.Equals(compObj2));

        test(compObj1.ice_locatorCacheTimeout(20).Equals(compObj1.ice_locatorCacheTimeout(20)));
        test(!compObj1.ice_locatorCacheTimeout(10).Equals(compObj1.ice_locatorCacheTimeout(20)));

        test(compObj1.ice_invocationTimeout(20).Equals(compObj1.ice_invocationTimeout(20)));
        test(!compObj1.ice_invocationTimeout(10).Equals(compObj1.ice_invocationTimeout(20)));

        compObj1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 1000");
        compObj2 = communicator.stringToProxy("foo@MyAdapter1");
        test(!compObj1.Equals(compObj2));

        Ice.Endpoint[] endpts1 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints();
        Ice.Endpoint[] endpts2 = communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10001").ice_getEndpoints();
        test(!endpts1[0].Equals(endpts2[0]));
        test(endpts1[0].Equals(communicator.stringToProxy("foo:tcp -h 127.0.0.1 -p 10000").ice_getEndpoints()[0]));

        //
        // TODO: Ideally we should also test comparison of fixed proxies.
        //
        WriteLine("ok");

        Write("testing checked cast... ");
        Flush();
        Test.MyClassPrx cl = Test.MyClassPrxHelper.checkedCast(baseProxy);
        test(cl != null);
        Test.MyDerivedClassPrx derived = Test.MyDerivedClassPrxHelper.checkedCast(cl);
        test(derived != null);
        test(cl.Equals(baseProxy));
        test(derived.Equals(baseProxy));
        test(cl.Equals(derived));
        WriteLine("ok");

        Write("testing checked cast with context... ");
        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.MyClassPrxHelper.checkedCast(baseProxy, c);
        Dictionary<string, string> c2 = cl.getContext();
        test(Ice.CollectionComparer.Equals(c, c2));
        WriteLine("ok");

        Write("testing encoding versioning... ");
        Flush();
        string ref20 = "test -e 2.0:default -p 12010";
        Test.MyClassPrx cl20 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref20));
        try
        {
            cl20.ice_ping();
            test(false);
        }
        catch(Ice.UnsupportedEncodingException)
        {
            // Server 2.0 endpoint doesn't support 1.1 version.
        }

        string ref10 = "test -e 1.0:default -p 12010";
        Test.MyClassPrx cl10 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref10));
        cl10.ice_ping();
        cl10.ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();
        cl.ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();

        // 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:default -p 12010";
        Test.MyClassPrx cl13 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref13));
        cl13.ice_ping();
        cl13.end_ice_ping(cl13.begin_ice_ping());

        try
        {
            // Send request with bogus 1.2 encoding.
            Ice.EncodingVersion version = new Ice.EncodingVersion(1, 2);
            Ice.OutputStream os = new Ice.OutputStream(communicator);
            os.startEncapsulation();
            os.endEncapsulation();
            byte[] inEncaps = os.finished();
            inEncaps[4] = version.major;
            inEncaps[5] = version.minor;
            byte[] outEncaps;
            cl.ice_invoke("ice_ping", Ice.OperationMode.Normal, inEncaps,
                                                          out outEncaps);
            test(false);
        }
        catch(Ice.UnknownLocalException ex)
        {
            // The server thrown an UnsupportedEncodingException
            test(ex.unknown.IndexOf("UnsupportedEncodingException") > 0);
        }

        try
        {
            // Send request with bogus 2.0 encoding.
            Ice.EncodingVersion version = new Ice.EncodingVersion(2, 0);
            Ice.OutputStream os = new Ice.OutputStream(communicator);
            os.startEncapsulation();
            os.endEncapsulation();
            byte[] inEncaps = os.finished();
            inEncaps[4] = version.major;
            inEncaps[5] = version.minor;
            byte[] outEncaps;
            cl.ice_invoke("ice_ping", Ice.OperationMode.Normal, inEncaps,
                                                          out outEncaps);
            test(false);
        }
        catch(Ice.UnknownLocalException ex)
        {
            // The server thrown an UnsupportedEncodingException
            test(ex.unknown.IndexOf("UnsupportedEncodingException") > 0);
        }

        WriteLine("ok");

        Write("testing protocol versioning... ");
        Flush();
        ref20 = "test -p 2.0:default -p 12010";
        cl20 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref20));
        try
        {
            cl20.ice_ping();
            test(false);
        }
        catch(Ice.UnsupportedProtocolException)
        {
            // Server 2.0 proxy doesn't support 1.0 version.
        }

        ref10 = "test -p 1.0:default -p 12010";
        cl10 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref10));
        cl10.ice_ping();

        // 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:default -p 12010";
        cl13 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref13));
        cl13.ice_ping();
        cl13.end_ice_ping(cl13.begin_ice_ping());
        WriteLine("ok");

        Write("testing opaque endpoints... ");
        Flush();

        try
        {
            // Invalid -x option
            communicator.stringToProxy("id:opaque -t 99 -v abc -x abc");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing -t and -v
            communicator.stringToProxy("id:opaque");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Repeated -t
            communicator.stringToProxy("id:opaque -t 1 -t 1 -v abc");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Repeated -v
            communicator.stringToProxy("id:opaque -t 1 -v abc -v abc");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing -t
            communicator.stringToProxy("id:opaque -v abc");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing -v
            communicator.stringToProxy("id:opaque -t 1");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing arg for -t
            communicator.stringToProxy("id:opaque -t -v abc");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Missing arg for -v
            communicator.stringToProxy("id:opaque -t 1 -v");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Not a number for -t
            communicator.stringToProxy("id:opaque -t x -v abc");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // < 0 for -t
            communicator.stringToProxy("id:opaque -t -1 -v abc");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        try
        {
            // Invalid char for -v
            communicator.stringToProxy("id:opaque -t 99 -v x?c");
            test(false);
        }
        catch(Ice.EndpointParseException)
        {
        }

        // Legal TCP endpoint expressed as opaque endpoint
        Ice.ObjectPrx p1 = communicator.stringToProxy("test -e 1.1:opaque -t 1 -e 1.0 -v CTEyNy4wLjAuMeouAAAQJwAAAA==");
        string pstr = communicator.proxyToString(p1);
        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.
        Ice.ObjectPrx p2 = communicator.stringToProxy("test -e 1.1:opaque -e 1.1 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==");
        test(communicator.proxyToString(p2).Equals("test -t -e 1.1:tcp -h 127.0.0.1 -p 12010 -t 10000"));

        if(communicator.getProperties().getPropertyAsInt("Ice.IPv6") == 0)
        {
            // Working?
            bool ssl = communicator.getProperties().getProperty("Ice.Default.Protocol").Equals("ssl");
            bool tcp = communicator.getProperties().getProperty("Ice.Default.Protocol").Equals("tcp");
            if(tcp)
            {
                p1.ice_encodingVersion(Ice.Util.Encoding_1_0).ice_ping();
            }

            // Two legal TCP endpoints expressed as opaque endpoints
            p1 = communicator.stringToProxy("test -e 1.0:opaque -e 1.0 -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==:opaque -e 1.0 -t 1 -v CTEyNy4wLjAuMusuAAAQJwAAAA==");
            pstr = communicator.proxyToString(p1);
            test(pstr.Equals("test -t -e 1.0: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 = communicator.stringToProxy("test -e 1.0:opaque -e 1.0 -t 2 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -e 1.0 -t 99 -v abch");
            pstr = communicator.proxyToString(p1);
            if(ssl)
            {
                test(pstr.Equals("test -t -e 1.0:ssl -h 127.0.0.1 -p 10001 -t infinite:opaque -t 99 -e 1.0 -v abch"));
            }
            else if(tcp)
            {
                test(pstr.Equals(
                    "test -t -e 1.0:opaque -t 2 -e 1.0 -v CTEyNy4wLjAuMREnAAD/////AA==:opaque -t 99 -e 1.0 -v abch"));
            }
        }

        WriteLine("ok");
        return cl;
    }
Exemplo n.º 25
0
        private Reference create(Ice.Identity ident,
                                 string facet,
                                 Reference.Mode mode,
                                 bool secure,
                                 Ice.ProtocolVersion protocol,
                                 Ice.EncodingVersion encoding,
                                 EndpointI[] endpoints,
                                 string adapterId,
                                 string propertyPrefix)
        {
            DefaultsAndOverrides defaultsAndOverrides = instance_.defaultsAndOverrides();

            //
            // Default local proxy options.
            //
            LocatorInfo locatorInfo = null;

            if (_defaultLocator != null)
            {
                if (!((Ice.ObjectPrxHelperBase)_defaultLocator).reference__().getEncoding().Equals(encoding))
                {
                    locatorInfo = instance_.locatorManager().get(
                        (Ice.LocatorPrx)_defaultLocator.ice_encodingVersion(encoding));
                }
                else
                {
                    locatorInfo = instance_.locatorManager().get(_defaultLocator);
                }
            }
            RouterInfo routerInfo      = instance_.routerManager().get(_defaultRouter);
            bool       collocOptimized = defaultsAndOverrides.defaultCollocationOptimization;
            bool       cacheConnection = true;
            bool       preferSecure    = defaultsAndOverrides.defaultPreferSecure;

            Ice.EndpointSelectionType endpointSelection = defaultsAndOverrides.defaultEndpointSelection;
            int locatorCacheTimeout             = defaultsAndOverrides.defaultLocatorCacheTimeout;
            int invocationTimeout               = defaultsAndOverrides.defaultInvocationTimeout;
            Dictionary <string, string> context = null;

            //
            // Override the defaults with the proxy properties if a property prefix is defined.
            //
            if (propertyPrefix != null && propertyPrefix.Length > 0)
            {
                Ice.Properties properties = instance_.initializationData().properties;

                //
                // Warn about unknown properties.
                //
                if (properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0)
                {
                    checkForUnknownProperties(propertyPrefix);
                }

                string property;

                property = propertyPrefix + ".Locator";
                Ice.LocatorPrx locator = Ice.LocatorPrxHelper.uncheckedCast(_communicator.propertyToProxy(property));
                if (locator != null)
                {
                    if (!((Ice.ObjectPrxHelperBase)locator).reference__().getEncoding().Equals(encoding))
                    {
                        locatorInfo = instance_.locatorManager().get(
                            (Ice.LocatorPrx)locator.ice_encodingVersion(encoding));
                    }
                    else
                    {
                        locatorInfo = instance_.locatorManager().get(locator);
                    }
                }

                property = propertyPrefix + ".Router";
                Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(_communicator.propertyToProxy(property));
                if (router != null)
                {
                    if (propertyPrefix.EndsWith(".Router", StringComparison.Ordinal))
                    {
                        string s = "`" + property + "=" + properties.getProperty(property) +
                                   "': cannot set a router on a router; setting ignored";
                        instance_.initializationData().logger.warning(s);
                    }
                    else
                    {
                        routerInfo = instance_.routerManager().get(router);
                    }
                }

                property        = propertyPrefix + ".CollocationOptimized";
                collocOptimized = properties.getPropertyAsIntWithDefault(property, collocOptimized ? 1 : 0) > 0;

                property        = propertyPrefix + ".ConnectionCached";
                cacheConnection = properties.getPropertyAsIntWithDefault(property, cacheConnection ? 1 : 0) > 0;

                property     = propertyPrefix + ".PreferSecure";
                preferSecure = properties.getPropertyAsIntWithDefault(property, preferSecure ? 1 : 0) > 0;

                property = propertyPrefix + ".EndpointSelection";
                if (properties.getProperty(property).Length > 0)
                {
                    string type = properties.getProperty(property);
                    if (type.Equals("Random"))
                    {
                        endpointSelection = Ice.EndpointSelectionType.Random;
                    }
                    else if (type.Equals("Ordered"))
                    {
                        endpointSelection = Ice.EndpointSelectionType.Ordered;
                    }
                    else
                    {
                        throw new Ice.EndpointSelectionTypeParseException("illegal value `" + type +
                                                                          "'; expected `Random' or `Ordered'");
                    }
                }

                property = propertyPrefix + ".LocatorCacheTimeout";
                string val = properties.getProperty(property);
                if (val.Length > 0)
                {
                    locatorCacheTimeout = properties.getPropertyAsIntWithDefault(property, locatorCacheTimeout);
                    if (locatorCacheTimeout < -1)
                    {
                        locatorCacheTimeout = -1;

                        StringBuilder msg = new StringBuilder("invalid value for ");
                        msg.Append(property);
                        msg.Append(" `");
                        msg.Append(properties.getProperty(property));
                        msg.Append("': defaulting to -1");
                        instance_.initializationData().logger.warning(msg.ToString());
                    }
                }

                property = propertyPrefix + ".InvocationTimeout";
                val      = properties.getProperty(property);
                if (val.Length > 0)
                {
                    invocationTimeout = properties.getPropertyAsIntWithDefault(property, invocationTimeout);
                    if (invocationTimeout < 1 && invocationTimeout != -1)
                    {
                        invocationTimeout = -1;

                        StringBuilder msg = new StringBuilder("invalid value for ");
                        msg.Append(property);
                        msg.Append(" `");
                        msg.Append(properties.getProperty(property));
                        msg.Append("': defaulting to -1");
                        instance_.initializationData().logger.warning(msg.ToString());
                    }
                }

                property = propertyPrefix + ".Context.";
                Dictionary <string, string> contexts = properties.getPropertiesForPrefix(property);
                if (contexts.Count != 0)
                {
                    context = new Dictionary <string, string>();
                    foreach (KeyValuePair <string, string> e in contexts)
                    {
                        context.Add(e.Key.Substring(property.Length), e.Value);
                    }
                }
            }

            //
            // Create new reference
            //
            return(new RoutableReference(instance_,
                                         _communicator,
                                         ident,
                                         facet,
                                         mode,
                                         secure,
                                         protocol,
                                         encoding,
                                         endpoints,
                                         adapterId,
                                         locatorInfo,
                                         routerInfo,
                                         collocOptimized,
                                         cacheConnection,
                                         preferSecure,
                                         endpointSelection,
                                         locatorCacheTimeout,
                                         invocationTimeout,
                                         context));
        }
Exemplo n.º 26
0
        internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger)
        {
            string val;

            defaultProtocol = properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp");

            val = properties.getProperty("Ice.Default.Host");
            if(val.Length != 0)
            {
                defaultHost = val;
            }
            else
            {
                defaultHost = null;
            }

            val = properties.getProperty("Ice.Default.SourceAddress");
            if(val.Length > 0)
            {
                defaultSourceAddress = Network.getNumericAddress(val);
                if(defaultSourceAddress == null)
                {
                    throw new Ice.InitializationException("invalid IP address set for Ice.Default.SourceAddress: `" +
                                                          val + "'");
                }
            }
            else
            {
                defaultSourceAddress = null;
            }

            val = properties.getProperty("Ice.Override.Timeout");
            if(val.Length > 0)
            {
                overrideTimeout = true;
                overrideTimeoutValue = properties.getPropertyAsInt("Ice.Override.Timeout");
                if(overrideTimeoutValue < 1 && overrideTimeoutValue != -1)
                {
                    overrideTimeoutValue = -1;
                    StringBuilder msg = new StringBuilder("invalid value for Ice.Override.Timeout `");
                    msg.Append(properties.getProperty("Ice.Override.Timeout"));
                    msg.Append("': defaulting to -1");
                    logger.warning(msg.ToString());
                }
            }
            else
            {
                overrideTimeout = false;
                overrideTimeoutValue = -1;
            }

            val = properties.getProperty("Ice.Override.ConnectTimeout");
            if(val.Length > 0)
            {
                overrideConnectTimeout = true;
                overrideConnectTimeoutValue = properties.getPropertyAsInt("Ice.Override.ConnectTimeout");
                if(overrideConnectTimeoutValue < 1 && overrideConnectTimeoutValue != -1)
                {
                    overrideConnectTimeoutValue = -1;
                    StringBuilder msg = new StringBuilder("invalid value for Ice.Override.ConnectTimeout `");
                    msg.Append(properties.getProperty("Ice.Override.ConnectTimeout"));
                    msg.Append("': defaulting to -1");
                    logger.warning(msg.ToString());
                }
            }
            else
            {
                overrideConnectTimeout = false;
                overrideConnectTimeoutValue = -1;
            }

            val = properties.getProperty("Ice.Override.CloseTimeout");
            if(val.Length > 0)
            {
                overrideCloseTimeout = true;
                overrideCloseTimeoutValue = properties.getPropertyAsInt("Ice.Override.CloseTimeout");
                if(overrideCloseTimeoutValue < 1 && overrideCloseTimeoutValue != -1)
                {
                    overrideCloseTimeoutValue = -1;
                    StringBuilder msg = new StringBuilder("invalid value for Ice.Override.CloseTimeout `");
                    msg.Append(properties.getProperty("Ice.Override.CloseTimeout"));
                    msg.Append("': defaulting to -1");
                    logger.warning(msg.ToString());
                }
            }
            else
            {
                overrideCloseTimeout = false;
                overrideCloseTimeoutValue = -1;
            }

            val = properties.getProperty("Ice.Override.Compress");
            if(val.Length > 0)
            {
                overrideCompress = true;
                overrideCompressValue = properties.getPropertyAsInt("Ice.Override.Compress") > 0;
                if(!BZip2.supported() && overrideCompressValue)
                {
                    string lib = AssemblyUtil.runtime_ == AssemblyUtil.Runtime.Mono ? "bzip2 library" : "bzip2.dll";
                    Console.Error.WriteLine("warning: " + lib + " not found, Ice.Override.Compress ignored.");
                    overrideCompressValue = false;
                }
            }
            else
            {
                overrideCompress = !BZip2.supported();
                overrideCompressValue = false;
            }

            val = properties.getProperty("Ice.Override.Secure");
            if(val.Length > 0)
            {
                overrideSecure = true;
                overrideSecureValue = properties.getPropertyAsInt("Ice.Override.Secure") > 0;
            }
            else
            {
                overrideSecure = false;
                overrideSecureValue = false;
            }

            defaultCollocationOptimization =
                properties.getPropertyAsIntWithDefault("Ice.Default.CollocationOptimized", 1) > 0;

            val = properties.getPropertyWithDefault("Ice.Default.EndpointSelection", "Random");
            if(val.Equals("Random"))
            {
                defaultEndpointSelection = Ice.EndpointSelectionType.Random;
            }
            else if(val.Equals("Ordered"))
            {
                defaultEndpointSelection = Ice.EndpointSelectionType.Ordered;
            }
            else
            {
                Ice.EndpointSelectionTypeParseException ex = new Ice.EndpointSelectionTypeParseException();
                ex.str = "illegal value `" + val + "'; expected `Random' or `Ordered'";
                throw ex;
            }

            defaultTimeout = properties.getPropertyAsIntWithDefault("Ice.Default.Timeout", 60000);
            if(defaultTimeout < 1 && defaultTimeout != -1)
            {
                defaultTimeout = 60000;
                StringBuilder msg = new StringBuilder("invalid value for Ice.Default.Timeout `");
                msg.Append(properties.getProperty("Ice.Default.Timeout"));
                msg.Append("': defaulting to 60000");
                logger.warning(msg.ToString());
            }

            defaultLocatorCacheTimeout = properties.getPropertyAsIntWithDefault("Ice.Default.LocatorCacheTimeout", -1);
            if(defaultLocatorCacheTimeout < -1)
            {
                defaultLocatorCacheTimeout = -1;
                StringBuilder msg = new StringBuilder("invalid value for Ice.Default.LocatorCacheTimeout `");
                msg.Append(properties.getProperty("Ice.Default.LocatorCacheTimeout"));
                msg.Append("': defaulting to -1");
                logger.warning(msg.ToString());
            }

            defaultInvocationTimeout = properties.getPropertyAsIntWithDefault("Ice.Default.InvocationTimeout", -1);
            if(defaultInvocationTimeout < 1 && defaultInvocationTimeout != -1 && defaultInvocationTimeout != -2)
            {
                defaultInvocationTimeout = -1;
                StringBuilder msg = new StringBuilder("invalid value for Ice.Default.InvocationTimeout `");
                msg.Append(properties.getProperty("Ice.Default.InvocationTimeout"));
                msg.Append("': defaulting to -1");
                logger.warning(msg.ToString());
            }

            defaultPreferSecure = properties.getPropertyAsIntWithDefault("Ice.Default.PreferSecure", 0) > 0;

            val = properties.getPropertyWithDefault("Ice.Default.EncodingVersion",
                                                    Ice.Util.encodingVersionToString(Ice.Util.currentEncoding));
            defaultEncoding = Ice.Util.stringToEncodingVersion(val);
            Protocol.checkSupportedEncoding(defaultEncoding);

            bool slicedFormat = properties.getPropertyAsIntWithDefault("Ice.Default.SlicedFormat", 0) > 0;
            defaultFormat = slicedFormat ? Ice.FormatType.SlicedFormat : Ice.FormatType.CompactFormat;
        }