Ejemplo n.º 1
0
        public virtual void ConnectionRequest(out int auxHandle, out string ipAddress, out int portNumber)
        {
            try
            {
                XdrStream.Write(IscCodes.op_connect_request);
                XdrStream.Write(IscCodes.P_REQ_async);
                XdrStream.Write(_handle);
                XdrStream.Write(PartnerIdentification);

                XdrStream.Flush();

                ReadOperation();

                auxHandle = XdrStream.ReadInt32();

                // garbage
                XdrStream.ReadBytes(8);

                int respLen = XdrStream.ReadInt32();
                respLen += respLen % 4;

                // sin_family
                XdrStream.ReadBytes(2);
                respLen -= 2;

                // sin_port
                byte[] buffer = XdrStream.ReadBytes(2);
                portNumber = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(buffer, 0));
                respLen   -= 2;

                // * The address returned by the server may be incorrect if it is behind a NAT box
                // * so we must use the address that was used to connect the main socket, not the
                // * address reported by the server.
                // sin_addr
                buffer = XdrStream.ReadBytes(4);
                //ipAddress = string.Format(
                //    CultureInfo.InvariantCulture,
                //    "{0}.{1}.{2}.{3}",
                //    buffer[0], buffer[1], buffer[2], buffer[3]);
                ipAddress = _connection.IPAddress.ToString();
                respLen  -= 4;

                // garbage
                XdrStream.ReadBytes(respLen);

                XdrStream.ReadStatusVector();
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
            }
        }
Ejemplo n.º 2
0
 public virtual void ReleaseObject(int op, int id)
 {
     try
     {
         DoReleaseObjectPacket(op, id);
         XdrStream.Flush();
         ProcessReleaseObjectResponse(ReadResponse());
     }
     catch (IOException ex)
     {
         throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
     }
 }
Ejemplo n.º 3
0
 public virtual void CreateDatabase(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey)
 {
     try
     {
         SendCreateToBuffer(dpb, database);
         XdrStream.Flush();
         ProcessCreateResponse(ReadGenericResponse());
     }
     catch (IOException ex)
     {
         throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
     }
 }
Ejemplo n.º 4
0
        public virtual void Detach()
        {
            if (TransactionCount > 0)
            {
                throw IscException.ForErrorCodeIntParam(IscCodes.isc_open_trans, TransactionCount);
            }

            try
            {
                CloseEventManager();

                var detach = _handle != -1;
                if (detach)
                {
                    XdrStream.Write(IscCodes.op_detach);
                    XdrStream.Write(_handle);
                }
                XdrStream.Write(IscCodes.op_disconnect);
                XdrStream.Flush();
                if (detach)
                {
                    ReadResponse();
                }

                CloseConnection();

#warning Here
                _xdrStream?.Dispose();

                _transactionCount = 0;
                _handle           = -1;
                _dialect          = 0;
                _packetSize       = 0;
                _xdrStream        = null;
                _charset          = null;
                _connection       = null;
                _serverVersion    = null;
            }
            catch (IOException ex)
            {
                try
                {
                    CloseConnection();
                }
                catch (IOException ex2)
                {
                    throw IscException.ForErrorCode(IscCodes.isc_network_error, ex2);
                }
                throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
            }
        }
Ejemplo n.º 5
0
        public void CancelEvents(RemoteEvent events)
        {
            try
            {
                XdrStream.Write(IscCodes.op_cancel_events);
                XdrStream.Write(_handle);
                XdrStream.Write(events.LocalId);

                XdrStream.Flush();

                ReadResponse();
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
            }
        }
Ejemplo n.º 6
0
        public virtual void DropDatabase()
        {
            try
            {
                XdrStream.Write(IscCodes.op_drop_database);
                XdrStream.Write(_handle);
                XdrStream.Flush();

                ReadResponse();

                _handle = -1;
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
            }
        }
Ejemplo n.º 7
0
        public void QueueEvents(RemoteEvent events)
        {
            if (_eventManager == null)
            {
                string ipAddress  = string.Empty;
                int    portNumber = 0;
                int    auxHandle  = 0;

                ConnectionRequest(out auxHandle, out ipAddress, out portNumber);

                _eventManager = new GdsEventManager(auxHandle, ipAddress, portNumber);
            }

            lock (SyncObject)
            {
                try
                {
                    events.LocalId = Interlocked.Increment(ref _eventsId);

                    // Enqueue events in the event manager
                    _eventManager.QueueEvents(events);

                    EventParameterBuffer epb = events.ToEpb();

                    XdrStream.Write(IscCodes.op_que_events);
                    XdrStream.Write(_handle);                                     // Database object id
                    XdrStream.WriteBuffer(epb.ToArray());                         // Event description block
                    XdrStream.Write(0);                                           // Address of ast routine
                    XdrStream.Write(0);                                           // Argument to ast routine
                    XdrStream.Write(events.LocalId);                              // Client side id of remote event

                    XdrStream.Flush();

                    GenericResponse response = (GenericResponse)ReadResponse();

                    // Update event	Remote event ID
                    events.RemoteId = response.ObjectHandle;
                }
                catch (IOException ex)
                {
                    throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
                }
            }
        }
Ejemplo n.º 8
0
        public virtual void Attach(DatabaseParameterBuffer dpb, string dataSource, int port, string database, byte[] cryptKey)
        {
            try
            {
                SendAttachToBuffer(dpb, database);
                XdrStream.Flush();
                ProcessAttachResponse(ReadGenericResponse());
            }
            catch (IscException)
            {
                SafelyDetach();
                throw;
            }
            catch (IOException ex)
            {
                SafelyDetach();
                throw IscException.ForErrorCode(IscCodes.isc_net_write_err, ex);
            }

            AfterAttachActions();
        }
Ejemplo n.º 9
0
        public void CancelEvents(RemoteEvent events)
        {
            lock (SyncObject)
            {
                try
                {
                    XdrStream.Write(IscCodes.op_cancel_events);
                    XdrStream.Write(_handle);                                 // Database object id
                    XdrStream.Write(events.LocalId);                          // Event ID

                    XdrStream.Flush();

                    ReadResponse();

                    _eventManager.CancelEvents(events);
                }
                catch (IOException ex)
                {
                    throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
                }
            }
        }
 public void Flush()
 {
     _outputStream.Flush();
 }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
            }
        }