private void connect(isc_db_handle_impl db, DbAttachInfo dbai) throws GDSException { boolean debug = log != null && log.isDebugEnabled(); try { try { db.socket = new Socket(dbai.getServer(), dbai.getPort()); db.socket.setTcpNoDelay(true); if (debug) log.debug("Got socket"); } catch (UnknownHostException ex2) { String message = "Cannot resolve host " + dbai.getServer(); if (debug) log.error(message, ex2); throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_network_error , dbai.getServer()); }  db.out = new XdrOutputStream(db.socket.getOutputStream()); db.in = new XdrInputStream(db.socket.getInputStream());    String user = System.getProperty("user.name"); if (debug) log.debug("user.name: " + user); String host = InetAddress.getLocalHost().getHostName();   byte[] user_id = new byte[6+user.length()+host.length()]; int n = 0; user_id[n++] = 1; user_id[n++] = (byte) user.length(); System.arraycopy(user.getBytes(), 0, user_id, n, user.length()); n += user.length();    user_id[n++] = 4; user_id[n++] = (byte) host.length(); System.arraycopy(host.getBytes(), 0, user_id, n, host.length()); n += host.length();  user_id[n++] = 6; user_id[n++] = 0;  if (debug) log.debug("op_connect "); db.out.writeInt(op_connect); db.out.writeInt(op_attach); db.out.writeInt(2); db.out.writeInt(1);  db.out.writeString(dbai.getFileName()); db.out.writeInt(1); db.out.writeBuffer(user_id);  db.out.writeInt(10); db.out.writeInt(1); db.out.writeInt(2); db.out.writeInt(3); db.out.writeInt(2); db.out.flush(); if (debug) log.debug("sent");  if (debug) log.debug("op_accept "); if (nextOperation(db) == op_accept) { db.setProtocol(db.in.readInt()); int arch = db.in.readInt(); int min = db.in.readInt(); if (debug) log.debug("received"); } else { disconnect(db); if (debug) log.debug("not received"); throw new GDSException(ISCConstants.isc_connect_reject); } } catch (IOException ex) { if (debug) log.debug("IOException while trying to connect to db:", ex); throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_network_error , dbai.getServer()); }
public void connect(isc_db_handle_impl db, String host, Integer port, String filename) throws GDSException { DbAttachInfo dbai = new DbAttachInfo(host, port, filename); connect(db, dbai);
    private void connect(isc_db_handle_impl db,                            DbAttachInfo dbai) throws GDSException {        boolean debug = log != null && log.isDebugEnabled();        try {            try {                db.socket = new Socket(dbai.getServer(), dbai.getPort());                db.socket.setTcpNoDelay(true);                if (debug) log.debug("Got socket");            } catch (UnknownHostException ex2) {                String message = "Cannot resolve host " + dbai.getServer();                if (debug) log.error(message, ex2);                throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_network_error                , dbai.getServer());            }            db.out = new XdrOutputStream(db.socket.getOutputStream());            db.in = new XdrInputStream(db.socket.getInputStream());            //Here we identify the user to the engine.  This may or may not be used             //as login info to a database.            String user = System.getProperty("user.name");            if (debug) log.debug("user.name: " + user);            String host = InetAddress.getLocalHost().getHostName();//            byte[] user_id = new byte[200];            byte[] user_id = new byte[6+user.length()+host.length()];            int n = 0;            user_id[n++] = 1;   // CNCT_user            user_id[n++] = (byte) user.length();            System.arraycopy(user.getBytes(), 0, user_id, n, user.length());            n += user.length();            /*            String passwd = "masterkey";            user_id[n++] = 2;   // CNCT_passwd            user_id[n++] = (byte) passwd.length();            System.arraycopy(passwd.getBytes(), 0, user_id, n, passwd.length());            n += passwd.length();*/            user_id[n++] = 4;     // CNCT_host            user_id[n++] = (byte) host.length();            System.arraycopy(host.getBytes(), 0, user_id, n, host.length());            n += host.length();                        user_id[n++] = 6;     // CNCT_user_verification            user_id[n++] = 0;            if (debug) log.debug("op_connect ");            db.out.writeInt(op_connect);            db.out.writeInt(op_attach);            db.out.writeInt(2);                    // CONNECT_VERSION2            db.out.writeInt(1);                    // arch_generic//            db.out.writeString(file_name);        // p_cnct_file            db.out.writeString(dbai.getFileName());        // p_cnct_file            db.out.writeInt(1);                   // p_cnct_count            db.out.writeBuffer(user_id);       // p_cnct_user_id            db.out.writeInt(10);                   // PROTOCOL_VERSION10            db.out.writeInt(1);                    // arch_generic            db.out.writeInt(2);                    // ptype_rpc            db.out.writeInt(3);                    // ptype_batch_send            db.out.writeInt(2);            db.out.flush();                        if (debug) log.debug("sent");            if (debug) log.debug("op_accept ");            if (nextOperation(db) == op_accept) {                db.setProtocol(db.in.readInt());             // Protocol version number                int arch = db.in.readInt();                  // Architecture for protocol                int min = db.in.readInt();                   // Minimum type                if (debug) log.debug("received");            } else {                disconnect(db);                if (debug) log.debug("not received");                throw new GDSException(ISCConstants.isc_connect_reject);            }        } catch (IOException ex) {            if (debug) log.debug("IOException while trying to connect to db:", ex);            throw new GDSException(ISCConstants.isc_arg_gds, ISCConstants.isc_network_error            , dbai.getServer());        }    }