Exemple #1
0
        public void recv(BServer server, BMessage msg, BAsyncResultIF <BMessage> asyncResult)
        {
            if (log.isDebugEnabled())
            {
                log.debug("recv(");
            }

            BInput bin       = getInput(msg.header, msg.buf);
            Object methodObj = bin.load();

            if (log.isDebugEnabled())
            {
                log.debug("methodObj=" + methodObj);
            }

            MethodResult methodResult = new MethodResult(this, asyncResult, bin);

            BTargetId clientTargetId = bin.header.targetId;

            if (log.isDebugEnabled())
            {
                log.debug("clientTargetId=" + clientTargetId);
            }

            if (log.isDebugEnabled())
            {
                log.debug("server.recv");
            }
            server.recv(clientTargetId, methodObj, methodResult);

            if (log.isDebugEnabled())
            {
                log.debug(")recv");
            }
        }
Exemple #2
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            BTargetId other = (BTargetId)obj;

            if (serverId != other.serverId)
            {
                return(false);
            }
            if (v1 != other.v1)
            {
                return(false);
            }
            if (v2 != other.v2)
            {
                return(false);
            }
            return(true);
        }
Exemple #3
0
 public BTransport(BApiDescriptor apiDesc, BWire wire, BRemoteRegistry remoteRegistry)
 {
     this.apiDesc        = apiDesc;
     this.wire           = wire;
     this.targetId       = new BTargetId();
     this.remoteRegistry = remoteRegistry;
 }
Exemple #4
0
        internal BContentStream createStreamRequest(Stream strm)
        {
            if (streams == null)
            {
                streams = new List <BContentStream>();
            }

            BContentStream bstrm = null;

            if (strm is BContentStream)
            {
                bstrm = (BContentStream)strm;
            }
            else
            {
                bstrm = new BContentStreamWrapper(strm);
            }

            // If the stream has already a streamId, it has been received
            // from the server. In this case, the application obviously
            // wants to forward the stream to another client. Thus
            // we do not have to upload the stream.

            if (bstrm.TargetId.isZero())
            {
                BTargetId targetId = new BTargetId(
                    transport.getConnectedServerId(),
                    header.messageId,
                    transport.getWire().makeMessageId());
                bstrm.TargetId = targetId;
                streams.Add(bstrm);
            }

            return(bstrm);
        }
Exemple #5
0
 public virtual void copyProperties(BContentStream rhs)
 {
     contentTypeVal    = rhs.ContentType;
     contentLengthVal  = rhs.ContentLength;
     fileNameVal       = rhs.FileName;
     attachmentCodeVal = rhs.AttachmentCode;
     targetIdVal       = rhs.TargetId;
 }
Exemple #6
0
 public override BContentStream getStream(BTargetId targetId)
 {
     Dictionary<long, ByteBuffer> map = null;
     if (!mapStreams.TryGetValue(targetId.getMessageId(), out map)) throw new IOException("Stream not found.");
     ByteBuffer buf = null;
     if (!map.TryGetValue(targetId.getStreamId(), out buf)) throw new IOException("Stream not found.");
     return new BContentStreamWrapper(new MemoryStream(buf.array(), buf.position(), buf.remaining()));
 }
Exemple #7
0
        public RequestToCancel createRequestForGetStream(BTargetId targetId, BAsyncResultIF <BMessage> asyncResult)
        {
            RequestToCancel r = new RequestToCancel(this, ERequestDirection.FORWARD, targetId.getMessageId(), null, null, targetId.getStreamId(), 0L,
                                                    timeoutMillisClient, timeoutMillisClient, asyncResult);

            addRequest(r);
            return(r);
        }
Exemple #8
0
 public void setTargetId(BTargetId targetId)
 {
     lock (this)
     {
         this.targetId          = targetId;
         this.connectedServerId = targetId.getServerId();
     }
 }
Exemple #9
0
        public override void write(Object obj, BOutput bout1, long version)
        {
            BOutputBin bout     = ((BOutputBin)bout1);
            BRemote    remote   = (BRemote)obj;
            BTargetId  targetId = remote.BRemote_getTargetId();

            targetId.write(bout.bbuf.getBuffer(), bout1.header.bversion);
        }
Exemple #10
0
 public BNegotiate(BNegotiate rhs)
 {
     protocols = rhs.protocols;
     bversion  = rhs.bversion;
     version   = rhs.version;
     byteOrder = rhs.byteOrder;
     targetId  = rhs.targetId;
     sessionId = rhs.sessionId;
 }
Exemple #11
0
 public BNegotiate(BNegotiate rhs)
 {
     protocols = rhs.protocols;
     bversion = rhs.bversion;
     version = rhs.version;
     byteOrder = rhs.byteOrder;
     targetId = rhs.targetId;
     sessionId = rhs.sessionId;
 }
Exemple #12
0
        private void internalStartR()
        {
            BTargetId targetId  = getTransport().getTargetId();
            String    sessionId = getTransport().getSessionId();

            serverR.transport.setTargetId(targetId);
            serverR.transport.setSessionId(sessionId);
            serverR.start();
        }
Exemple #13
0
        public BTransport(BTransport rhs, BTargetId targetId)
        {
            this.apiDesc   = rhs.apiDesc;
            this.wire      = rhs.wire;
            this.targetId  = targetId;
            this.sessionId = rhs.sessionId;
            this.protocol  = rhs.getProtocol();

            // Still connected to the server given by rhs.
            this.connectedServerId = rhs.targetId.getServerId();
        }
Exemple #14
0
 public BMessageHeader(BMessageHeader rhs)
 {
     this.magic = rhs.magic;
     this.bversion = rhs.bversion;
     this.version = rhs.version;
     this.byteOrder = rhs.byteOrder;
     this.error = rhs.error;
     this.flags = rhs.flags;
     this.messageId = rhs.messageId;
     this.targetId = rhs.targetId;
     this.sessionId = rhs.sessionId;
 }
Exemple #15
0
 public BMessageHeader(BMessageHeader rhs)
 {
     this.magic     = rhs.magic;
     this.bversion  = rhs.bversion;
     this.version   = rhs.version;
     this.byteOrder = rhs.byteOrder;
     this.error     = rhs.error;
     this.flags     = rhs.flags;
     this.messageId = rhs.messageId;
     this.targetId  = rhs.targetId;
     this.sessionId = rhs.sessionId;
 }
Exemple #16
0
        public BProtocol negotiateProtocolServer(BTargetId targetId, ByteBuffer buf, BAsyncResultIF <ByteBuffer> asyncResult)
        {
            if (log.isDebugEnabled())
            {
                log.debug("negotiateProtocolServer(targetId=" + targetId);
            }
            BProtocol ret = null;

            try
            {
                if (log.isDebugEnabled())
                {
                    log.debug("read nego msg");
                }
                BNegotiate nego = new BNegotiate();
                nego.read(buf);

                lock (this)
                {
                    this.protocol = ret = createNegotiatedProtocol(nego);
                    this.setTargetId(targetId);
                    this.setSessionId(targetId.toSessionId());
                }
                if (log.isDebugEnabled())
                {
                    log.debug("protocol=" + this.protocol + ", targetId=" + this.targetId);
                }

                ByteBuffer bout = ByteBuffer.allocate(BNegotiate.NEGOTIATE_MAX_SIZE);
                try
                {
                    nego.targetId  = targetId;
                    nego.sessionId = targetId.toSessionId();
                    nego.write(bout);
                    bout.flip();
                    asyncResult.setAsyncResult(bout, null);
                }
                finally
                {
                }
            }
            catch (Exception e)
            {
                asyncResult.setAsyncResult(null, e);
            }
            if (log.isDebugEnabled())
            {
                log.debug(")negotiateProtocolServer=" + ret);
            }
            return(ret);
        }
Exemple #17
0
        public override Object read(Object obj, BInput bin1, long version)
        {
            BInputBin       bin      = ((BInputBin)bin1);
            BRemote         remote   = null;
            BTargetId       targetId = BTargetId.read(bin.bbuf.getBuffer(), bin1.header.bversion);
            BRemoteRegistry rreg     = bin.transport.getRemoteRegistry();

            if (rreg != null)
            {
                remote = rreg.getRemote(bin.header.targetId, targetId, typeId);
            }
            else
            {
                BTransport transport = new BTransport(bin.transport, targetId);
                remote = internalCreate(transport);
            }
            return(remote);
        }
Exemple #18
0
        private void readBinaryWithoutMagic(ByteBuffer buf)
        {
            error = buf.getInt();
            flags = buf.getInt();

            if ((flags & FLAG_BYPS_VERSION) != 0)
            {
                bversion = buf.getInt();
            }

            version   = buf.getLong();
            targetId  = BTargetId.read(buf, bversion);
            messageId = buf.getLong();

            if (bversion >= BYPS_VERSION_WITH_SESSIONID)
            {
                sessionId = BTargetId.readSessionId(buf);
            }
        }
Exemple #19
0
        public override Object read(Object obj, BInput bin1, long version)
        {
            BInputBin bin = ((BInputBin)bin1);
            BTargetId targetId = null;
            long contentLength = -1;
            String contentType = BContentStream.DEFAULT_CONTENT_TYPE;
            int attachmentCode = 0;
            String fileName = "";
            bool withProps = bin1.header.bversion >= BMessageHeader.BYPS_VERSION_EXTENDED_STREAM_INFORMATION;

            if (withProps)
            {
                targetId = BTargetId.read(bin.bbuf.getBuffer(), bin1.header.bversion);
                contentLength = bin.bbuf.getLong();
                contentType = bin.bbuf.getString();
                attachmentCode = bin.bbuf.getInt();
                fileName = bin.bbuf.getString();
            }
            else
            {
                long streamId = bin.bbuf.getLong();
                int serverId = bin1.transport.getTargetId().getServerId();
                long messageId = bin1.header.messageId;
                targetId = new BTargetId(serverId, messageId, streamId);
            }

            try
            {
                BContentStream strm = bin.transport.getWire().getStream(targetId);
                bin.onObjectCreated(strm);
                strm.ContentLength = contentLength;
                strm.ContentType = contentType;
                strm.AttachmentCode = attachmentCode;
                strm.FileName = fileName;
                return strm;
            }
            catch (IOException e)
            {
                throw new BException(BExceptionC.IOERROR, e.Message);
            }

        }
Exemple #20
0
        public void write(ByteBuffer buf)
        {
            buf.putInt(MAGIC_BINARY_STREAM);
            buf.putInt(error);
            buf.putInt(flags);

            if ((flags & FLAG_BYPS_VERSION) != 0)
            {
                buf.putInt(bversion);
            }

            buf.putLong(version);
            targetId.write(buf, bversion);
            buf.putLong(messageId);

            if (bversion >= BYPS_VERSION_WITH_SESSIONID)
            {
                BTargetId.writeSessionId(buf, sessionId);
            }
        }
Exemple #21
0
        public override Object read(Object obj, BInput bin1, long version)
        {
            BInputBin bin            = ((BInputBin)bin1);
            BTargetId targetId       = null;
            long      contentLength  = -1;
            String    contentType    = BContentStream.DEFAULT_CONTENT_TYPE;
            int       attachmentCode = 0;
            String    fileName       = "";
            bool      withProps      = bin1.header.bversion >= BMessageHeader.BYPS_VERSION_EXTENDED_STREAM_INFORMATION;

            if (withProps)
            {
                targetId       = BTargetId.read(bin.bbuf.getBuffer(), bin1.header.bversion);
                contentLength  = bin.bbuf.getLong();
                contentType    = bin.bbuf.getString();
                attachmentCode = bin.bbuf.getInt();
                fileName       = bin.bbuf.getString();
            }
            else
            {
                long streamId  = bin.bbuf.getLong();
                int  serverId  = bin1.transport.getTargetId().getServerId();
                long messageId = bin1.header.messageId;
                targetId = new BTargetId(serverId, messageId, streamId);
            }

            try
            {
                BContentStream strm = bin.transport.getWire().getStream(targetId);
                bin.onObjectCreated(strm);
                strm.ContentLength  = contentLength;
                strm.ContentType    = contentType;
                strm.AttachmentCode = attachmentCode;
                strm.FileName       = fileName;
                return(strm);
            }
            catch (IOException e)
            {
                throw new BException(BExceptionC.IOERROR, e.Message);
            }
        }
Exemple #22
0
        public override void write(Object obj, BOutput bout1, long version)
        {
            BOutputBin     bout      = ((BOutputBin)bout1);
            Stream         strm      = (Stream)obj;
            BContentStream bstream   = bout.createStreamRequest(strm);
            BTargetId      targetId  = bstream.TargetId;
            bool           withProps = bout1.header.bversion >= BMessageHeader.BYPS_VERSION_EXTENDED_STREAM_INFORMATION;

            if (withProps)
            {
                bstream.TargetId.write(bout.bbuf.getBuffer(), bout1.header.bversion);
                bout.bbuf.putLong(bstream.ContentLength);
                bout.bbuf.putString(bstream.ContentType);
                bout.bbuf.putInt(bstream.AttachmentCode);
                bout.bbuf.putString(bstream.FileName);
            }
            else
            {
                bout.bbuf.putLong(targetId.getStreamId());
            }
        }
Exemple #23
0
        public virtual void recv(BTargetId clientTargetId, Object methodObj, BAsyncResultIF<Object> methodResult)
        {
		
		    try {
                BMethodRequest method = (BMethodRequest)methodObj;

                BRemote remote = null;
			    int remoteId = method.getRemoteId();
			    BTargetId serverTargetId = this.transport.getTargetId();
			
			    // Die Target-ID aus dem Header ist gleich der Target-ID des BServer-Objekts
			    // für einen normalen Client-Server-Request
			    if (clientTargetId.Equals(serverTargetId)) {
				    remotes.TryGetValue(remoteId, out remote);
			    }
			    else {
				
				    // Es wird eine andere Target-ID angesteuert.
				    // Ermittle hier die BRemote-Schnittstelle dieser Target-ID.
				    // Sie kommt möglicherweise von einem anderen Client.
				
				    remote = this.transport.getRemoteRegistry().getRemote(serverTargetId, clientTargetId, remoteId);
			    }
			
                if (remote != null)
                {
                    method.execute(remote, methodResult);
                }
                else
                {
                    BException ex = new BException(BExceptionC.SERVICE_NOT_IMPLEMENTED,
                        "Service not implemented: remoteId=" + remoteId);
                    methodResult.setAsyncResult(null, ex);
			    }
		    }
		    catch (Exception e) {
                methodResult.setAsyncResult(null, e);
		    }
		
	    }
Exemple #24
0
        public virtual void recv(BTargetId clientTargetId, Object methodObj, BAsyncResultIF <Object> methodResult)
        {
            try {
                BMethodRequest method = (BMethodRequest)methodObj;

                BRemote   remote         = null;
                int       remoteId       = method.getRemoteId();
                BTargetId serverTargetId = this.transport.getTargetId();

                // Die Target-ID aus dem Header ist gleich der Target-ID des BServer-Objekts
                // für einen normalen Client-Server-Request
                if (clientTargetId.Equals(serverTargetId))
                {
                    remotes.TryGetValue(remoteId, out remote);
                }
                else
                {
                    // Es wird eine andere Target-ID angesteuert.
                    // Ermittle hier die BRemote-Schnittstelle dieser Target-ID.
                    // Sie kommt möglicherweise von einem anderen Client.

                    remote = this.transport.getRemoteRegistry().getRemote(serverTargetId, clientTargetId, remoteId);
                }

                if (remote != null)
                {
                    method.execute(remote, methodResult);
                }
                else
                {
                    BException ex = new BException(BExceptionC.SERVICE_NOT_IMPLEMENTED,
                                                   "Service not implemented: remoteId=" + remoteId);
                    methodResult.setAsyncResult(null, ex);
                }
            }
            catch (Exception e) {
                methodResult.setAsyncResult(null, e);
            }
        }
Exemple #25
0
 public virtual void copyProperties(BContentStream rhs)
 {
     contentTypeVal = rhs.ContentType;
     contentLengthVal = rhs.ContentLength;
     fileNameVal = rhs.FileName;
     attachmentCodeVal = rhs.AttachmentCode;
     targetIdVal = rhs.TargetId;
 }
Exemple #26
0
         public InputStreamWrapper(BTargetId targetId)
         {
             this.TargetId = targetId;
 	    }
Exemple #27
0
 public MyInputStream(HWireClient wire, BTargetId targetId)
     : base(targetId)
 {
     this.wire = wire;
 }
Exemple #28
0
        public virtual BProtocol negotiate(BTargetId targetId, ByteBuffer bin, BAsyncResultIF<ByteBuffer> asyncResult)
        {
		    BProtocol protocol = transport.negotiateProtocolServer(targetId, bin, asyncResult);
		    return protocol;
	    }
Exemple #29
0
 public virtual BContentStream getStream(BTargetId targetId)
 {
     return(null);
 }
Exemple #30
0
        public void read(ByteBuffer buf)
        {
            String str = Encoding.UTF8.GetString(buf.array(), buf.position(), buf.remaining());

            str = str.Trim();
            if (str.IndexOf("[") == 0)
            {
                int endPos = str.IndexOf("]");
                if (endPos == str.Length - 1)
                {
                    str = str.Substring(1, str.Length - 2);
                    String[] items = str.Split(',');
                    int      idx   = 0;
                    if (items.Length >= 5)
                    {
                        if (items[idx++] == "\"N\"")
                        {
                            protocols = items[idx++];
                            if (protocols.Length >= 3)
                            {
                                protocols = protocols.Substring(1, protocols.Length - 2);

                                String versionStr = items[idx++];
                                versionStr = versionStr.Substring(1, versionStr.Length - 2);
                                version    = BVersioning.stringToLong(versionStr);

                                String byteOrderStr = items[idx++];
                                if (byteOrderStr.Equals("\"L\""))
                                {
                                    byteOrder = ByteOrder.LITTLE_ENDIAN;
                                }
                                else if (byteOrderStr.Equals("\"B\""))
                                {
                                    byteOrder = ByteOrder.BIG_ENDIAN;
                                }
                                else
                                {
                                    byteOrder = ByteOrder.UNDEFINED;
                                }

                                String targetIdStr = items[idx++];
                                if (targetIdStr.Length > 2)
                                {
                                    targetIdStr = targetIdStr.Substring(1, targetIdStr.Length - 2);
                                    targetId    = BTargetId.parseString(targetIdStr);
                                }

                                // BYPS Version.
                                // Due to a bug in versions before BYPS_VERSION_WITH_SESSIONID,
                                // this value is not correctly negotiated. If no sessionId is
                                // found, the bversion is ignored and set to the version number
                                // prior to BYPS_VERSION_WITH_SESSIONID.

                                if (items.Length >= 6)
                                {
                                    bversion = Convert.ToInt32(items[5]);
                                }
                                else
                                {
                                    bversion = 0;
                                }

                                if (items.Length >= 7)
                                {
                                    sessionId = items[6];
                                    if (sessionId.Length > 0)
                                    {
                                        int p = (sessionId[0] == '\"') ? 1 : 0;
                                        int q = (sessionId[sessionId.Length - 1] == '\"') ? sessionId.Length - 1 : 0;
                                        sessionId = sessionId.Substring(p, q - p);
                                    }
                                }
                                else if (bversion >= BMessageHeader.BYPS_VERSION_WITH_SESSIONID)
                                {
                                    bversion = BMessageHeader.BYPS_VERSION_WITH_SESSIONID - 1;
                                }

                                return; // OK
                            }
                        }
                    }
                }
            }

            throw new BException(BExceptionC.CORRUPT, "Invalid negotiate message.");
        }
Exemple #31
0
 public virtual BContentStream getStream(BTargetId targetId)
 {
     return null;
 }
Exemple #32
0
        private void readBinaryWithoutMagic(ByteBuffer buf)
        {
            error = buf.getInt();
            flags = buf.getInt();

            if ((flags & FLAG_BYPS_VERSION) != 0)
            {
                bversion = buf.getInt();
            }

            version = buf.getLong();
            targetId = BTargetId.read(buf, bversion);
            messageId = buf.getLong();
        
            if (bversion >= BYPS_VERSION_WITH_SESSIONID)
            {
                sessionId = BTargetId.readSessionId(buf);
            }
        }
Exemple #33
0
            public override void recv(BTargetId clientTargetId, Object methodObj, BAsyncResultIF<Object> methodResult)
            {
			    innerServer.recv(clientTargetId, methodObj, methodResult);
		    }
Exemple #34
0
            public override BProtocol negotiate(BTargetId targetId, ByteBuffer bin, BAsyncResultIF<ByteBuffer> asyncResult)
            {
			    // negotiate muss bereits vom zugehörigen BClient ausgeführt worden sein.
			    // Die ausgehandelten Eigenschaften werden von BClient übernommen - sie sind in BTransport enthalten.
			    return transport.getProtocol();
		    }
Exemple #35
0
 public override BProtocol negotiate(BTargetId targetId, ByteBuffer bin, BAsyncResultIF <ByteBuffer> asyncResult)
 {
     // negotiate muss bereits vom zugehörigen BClient ausgeführt worden sein.
     // Die ausgehandelten Eigenschaften werden von BClient übernommen - sie sind in BTransport enthalten.
     return(transport.getProtocol());
 }
Exemple #36
0
 public override void recv(BTargetId clientTargetId, Object methodObj, BAsyncResultIF <Object> methodResult)
 {
     innerServer.recv(clientTargetId, methodObj, methodResult);
 }
Exemple #37
0
        internal BContentStream createStreamRequest(Stream strm)
        {
            if (streams == null) streams = new List<BContentStream>();

            BContentStream bstrm = null;

            if (strm is BContentStream)
            {
                bstrm = (BContentStream)strm;
            }
            else
            {
                bstrm = new BContentStreamWrapper(strm);
            }

            // If the stream has already a streamId, it has been received
            // from the server. In this case, the application obviously
            // wants to forward the stream to another client. Thus 
            // we do not have to upload the stream.

            if (bstrm.TargetId.isZero())
            {
                BTargetId targetId = new BTargetId(
                    transport.getConnectedServerId(),
                    header.messageId,
                    transport.getWire().makeMessageId());
                bstrm.TargetId = targetId;
                streams.Add(bstrm);
            }

            return bstrm;
        }
Exemple #38
0
        public override BContentStream getStream(BTargetId targetId)
        {
            BContentStream strm = new MyInputStream(this, targetId);

            return(strm);
        }
Exemple #39
0
	    public void BSkeleton_setTargetId(BTargetId targetId) {
            this.targetId = targetId;
	    }
Exemple #40
0
 public InputStreamWrapper(BTargetId targetId)
 {
     this.TargetId = targetId;
 }
Exemple #41
0
 public void BSkeleton_setTargetId(BTargetId targetId)
 {
     this.targetId = targetId;
 }
Exemple #42
0
        public virtual BProtocol negotiate(BTargetId targetId, ByteBuffer bin, BAsyncResultIF <ByteBuffer> asyncResult)
        {
            BProtocol protocol = transport.negotiateProtocolServer(targetId, bin, asyncResult);

            return(protocol);
        }
Exemple #43
0
        public void read(ByteBuffer buf)
        {
            String str = Encoding.UTF8.GetString(buf.array(), buf.position(), buf.remaining());
            str = str.Trim();
            if (str.IndexOf("[") == 0)
            {
                int endPos = str.IndexOf("]");
                if (endPos == str.Length - 1)
                {
                    str = str.Substring(1, str.Length - 2);
                    String[] items = str.Split(',');
                    int idx = 0;
                    if (items.Length >= 5)
                    {
                        if (items[idx++] == "\"N\"")
                        {
                            protocols = items[idx++];
                            if (protocols.Length >= 3)
                            {
                                protocols = protocols.Substring(1, protocols.Length - 2);

                                String versionStr = items[idx++];
                                versionStr = versionStr.Substring(1, versionStr.Length - 2);
                                version = BVersioning.stringToLong(versionStr);

                                String byteOrderStr = items[idx++];
                                if (byteOrderStr.Equals("\"L\""))
                                {
                                    byteOrder = ByteOrder.LITTLE_ENDIAN;
                                }
                                else if (byteOrderStr.Equals("\"B\""))
                                {
                                    byteOrder = ByteOrder.BIG_ENDIAN;
                                }
                                else
                                {
                                    byteOrder = ByteOrder.UNDEFINED;
                                }

                                String targetIdStr = items[idx++];
                                if (targetIdStr.Length > 2)
                                {
                                    targetIdStr = targetIdStr.Substring(1, targetIdStr.Length - 2);
                                    targetId = BTargetId.parseString(targetIdStr);
                                }

                                // BYPS Version.
                                // Due to a bug in versions before BYPS_VERSION_WITH_SESSIONID, 
                                // this value is not correctly negotiated. If no sessionId is
                                // found, the bversion is ignored and set to the version number
                                // prior to BYPS_VERSION_WITH_SESSIONID.

                                if (items.Length >= 6)
                                {
                                    bversion = Convert.ToInt32(items[5]);
                                }
                                else
                                {
                                    bversion = 0;
                                }

                                if (items.Length >= 7)
                                {
                                    sessionId = items[6];
                                    if (sessionId.Length > 0)
                                    {
                                        int p = (sessionId[0] == '\"') ? 1 : 0;
                                        int q = (sessionId[sessionId.Length-1] == '\"') ? sessionId.Length-1 : 0;
                                        sessionId = sessionId.Substring(p, q - p);
                                    }
                                }
                                else if (bversion >= BMessageHeader.BYPS_VERSION_WITH_SESSIONID)
                                {
                                    bversion = BMessageHeader.BYPS_VERSION_WITH_SESSIONID - 1;
                                }

                                return; // OK
                            }
                        }
                    }
                }
            }

            throw new BException(BExceptionC.CORRUPT, "Invalid negotiate message.");
        }