예제 #1
0
  /**
   * Constructor, specifying the server host:port combination, login data and an output stream.
   *
   * @param host server name
   * @param port server port
   * @param user user name
   * @param pass password
   * @param output client output; if set to {@code null}, results will be returned as strings.
   * @throws IOException I/O exception
   */
  public ClientSession(
      final String host,
      final int port,
      final String user,
      final String pass,
      final OutputStream output)
      throws IOException {

    super(output);
    ehost = host;
    socket = new Socket();
    try {
      // limit timeout to five seconds
      socket.connect(new InetSocketAddress(host, port), 5000);
    } catch (final IllegalArgumentException ex) {
      throw new BaseXException(ex);
    }
    sin = socket.getInputStream();

    // receive timestamp
    final BufferInput bi = new BufferInput(sin);
    final String ts = bi.readString();

    // send user name and hashed password/timestamp
    sout = PrintOutput.get(socket.getOutputStream());
    send(user);
    send(Token.md5(Token.md5(pass) + ts));
    sout.flush();

    // receive success flag
    if (!ok(bi)) throw new LoginException();
  }
예제 #2
0
 /**
  * Test client with different user.
  *
  * @throws IOException I/O exception
  */
 @Test
 public void user() throws IOException {
   run("-cexit", "-cdrop user " + NAME);
   equals(
       "5",
       new String[] {"-U" + NAME, "-P" + NAME, "-q5"},
       new String[] {"-ccreate user " + NAME + ' ' + Token.md5(NAME)});
   run("-cexit", "-cdrop user " + NAME);
 }
예제 #3
0
  /**
   * Calculates the text offset and writes the text value.
   *
   * @param value value to be inlined
   * @param text text/attribute flag
   * @return inline value or text position
   * @throws IOException I/O exception
   */
  private long textOff(final byte[] value, final boolean text) throws IOException {
    // inline integer values...
    final long v = Token.toSimpleInt(value);
    if (v != Integer.MIN_VALUE) return v | IO.OFFNUM;

    // store text
    final DataOutput store = text ? xout : vout;
    final long off = store.size();
    final byte[] val = COMP.get().pack(value);
    store.writeToken(val);
    return val == value ? off : off | IO.OFFCOMP;
  }
예제 #4
0
 /**
  * Sends a string to the server.
  *
  * @param s string to be sent
  * @throws IOException I/O exception
  */
 protected void send(final String s) throws IOException {
   sout.write(Token.token(s));
   sout.write(0);
 }