Exemplo n.º 1
0
        public virtual void Identify(string database)
        {
            // handles this.networkStream
            XdrStream inputStream  = this.CreateXdrStream();
            XdrStream outputStream = this.CreateXdrStream();

            try
            {
                outputStream.Write(IscCodes.op_connect);
                outputStream.Write(IscCodes.op_attach);
                outputStream.Write(IscCodes.CONNECT_VERSION2);                  // CONNECT_VERSION2
                outputStream.Write(1);                                          // Architecture	of client -	Generic

                outputStream.Write(database);                                   // Database	path
                outputStream.Write(3);                                          // Protocol	versions understood
                outputStream.WriteBuffer(UserIdentificationStuff());            // User	identification Stuff

                outputStream.Write(IscCodes.PROTOCOL_VERSION10);                //	Protocol version
                outputStream.Write(1);                                          // Architecture	of client -	Generic
                outputStream.Write(2);                                          // Minimum type (ptype_rpc)
                outputStream.Write(3);                                          // Maximum type (ptype_batch_send)
                outputStream.Write(0);                                          // Preference weight

                outputStream.Write(IscCodes.PROTOCOL_VERSION11);                //	Protocol version
                outputStream.Write(1);                                          // Architecture	of client -	Generic
                outputStream.Write(2);                                          // Minumum type (ptype_rpc)
                outputStream.Write(5);                                          // Maximum type (ptype_lazy_send)
                outputStream.Write(1);                                          // Preference weight

                outputStream.Write(IscCodes.PROTOCOL_VERSION12);                //	Protocol version
                outputStream.Write(1);                                          // Architecture	of client -	Generic
                outputStream.Write(2);                                          // Minumum type (ptype_rpc)
                outputStream.Write(5);                                          // Maximum type (ptype_lazy_send)
                outputStream.Write(2);                                          // Preference weight

                outputStream.Flush();

                if (inputStream.ReadOperation() == IscCodes.op_accept)
                {
                    this.protocolVersion      = inputStream.ReadInt32();                // Protocol	version
                    this.protocolArchitecture = inputStream.ReadInt32();                // Architecture	for	protocol
                    this.protocolMinimunType  = inputStream.ReadInt32();                // Minimum type

                    if (this.protocolVersion < 0)
                    {
                        this.protocolVersion = (ushort)(this.protocolVersion & IscCodes.FB_PROTOCOL_MASK) | IscCodes.FB_PROTOCOL_FLAG;
                    }
                }
                else
                {
                    try
                    {
                        this.Disconnect();
                    }
                    catch
                    {
                    }
                    finally
                    {
                        throw new IscException(IscCodes.isc_connect_reject);
                    }
                }
            }
            catch (IOException)
            {
                throw new IscException(IscCodes.isc_network_error);
            }
        }
Exemplo n.º 2
0
 public virtual int ReadOperation()
 {
     return(_xdrStream.ReadOperation());
 }
Exemplo n.º 3
0
        public virtual void Identify(string database)
        {
            // handles this.networkStream
            XdrStream inputStream  = this.CreateXdrStream();
            XdrStream outputStream = this.CreateXdrStream();

            try
            {
                // Here	we identify	the	user to	the	engine.
                // This	may	or may not be used as login	info to	a database.
#if     (!NET_CF)
                byte[] user = Encoding.Default.GetBytes(System.Environment.UserName);
                byte[] host = Encoding.Default.GetBytes(System.Net.Dns.GetHostName());
#else
                byte[] user = Encoding.Default.GetBytes("fbnetcf");
                byte[] host = Encoding.Default.GetBytes(System.Net.Dns.GetHostName());
#endif

                using (MemoryStream user_id = new MemoryStream())
                {
                    // User	Name
                    user_id.WriteByte(1);
                    user_id.WriteByte((byte)user.Length);
                    user_id.Write(user, 0, user.Length);

                    // Host	name
                    user_id.WriteByte(4);
                    user_id.WriteByte((byte)host.Length);
                    user_id.Write(host, 0, host.Length);

                    // Attach/create using this connection will use user verification
                    user_id.WriteByte(6);
                    user_id.WriteByte(0);

                    outputStream.Write(IscCodes.op_connect);
                    outputStream.Write(IscCodes.op_attach);
                    outputStream.Write(IscCodes.CONNECT_VERSION2);   // CONNECT_VERSION2
                    outputStream.Write(1);                           // Architecture	of client -	Generic

                    outputStream.Write(database);                    // Database	path
                    outputStream.Write(3);                           // Protocol	versions understood
                    outputStream.WriteBuffer(user_id.ToArray());     // User	identification Stuff

                    outputStream.Write(IscCodes.PROTOCOL_VERSION10); //	Protocol version
                    outputStream.Write(1);                           // Architecture	of client -	Generic
                    outputStream.Write(2);                           // Minimum type (ptype_rpc)
                    outputStream.Write(3);                           // Maximum type (ptype_batch_send)
                    outputStream.Write(0);                           // Preference weight

                    outputStream.Write(IscCodes.PROTOCOL_VERSION11); //	Protocol version
                    outputStream.Write(1);                           // Architecture	of client -	Generic
                    outputStream.Write(2);                           // Minumum type (ptype_rpc)
                    outputStream.Write(5);                           // Maximum type (ptype_lazy_send)
                    outputStream.Write(1);                           // Preference weight

                    outputStream.Write(IscCodes.PROTOCOL_VERSION12); //	Protocol version
                    outputStream.Write(1);                           // Architecture	of client -	Generic
                    outputStream.Write(2);                           // Minumum type (ptype_rpc)
                    outputStream.Write(5);                           // Maximum type (ptype_lazy_send)
                    outputStream.Write(2);                           // Preference weight
                }
                outputStream.Flush();

                if (inputStream.ReadOperation() == IscCodes.op_accept)
                {
                    this.protocolVersion      = inputStream.ReadInt32(); // Protocol	version
                    this.protocolArchitecture = inputStream.ReadInt32(); // Architecture	for	protocol
                    this.protocolMinimunType  = inputStream.ReadInt32(); // Minimum type

                    if (this.protocolVersion < 0)
                    {
                        this.protocolVersion = (ushort)(this.protocolVersion & IscCodes.FB_PROTOCOL_MASK) | IscCodes.FB_PROTOCOL_FLAG;
                    }
                }
                else
                {
                    try
                    {
                        this.Disconnect();
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        throw new IscException(IscCodes.isc_connect_reject);
                    }
                }
            }
            catch (IOException)
            {
                throw new IscException(IscCodes.isc_network_error);
            }
        }