예제 #1
0
static void
recv_data_cb (BlockTxClient *client)
{
    int ret = 0;

    /* Let evbuffer determine how much data can be read. */
    int n = evbuffer_read (client->recv_buf, client->data_fd, -1);
    if (n == 0) {
        seaf_warning ("Data connection is closed by the server.\n");
        client->break_loop = TRUE;
        client->info->result = BLOCK_CLIENT_NET_ERROR;
        return;
    } else if (n < 0) {
        seaf_warning ("Read data connection error: %s.\n",
                      evutil_socket_error_to_string(evutil_socket_geterror(client->data_fd)));
        client->break_loop = TRUE;
        client->info->result = BLOCK_CLIENT_NET_ERROR;
        return;
    }

    switch (client->recv_state) {
    case RECV_STATE_HANDSHAKE:
        ret = handle_handshake_response (client);
        break;
    case RECV_STATE_AUTH:
        ret = handle_auth_response (client);
        break;
    case RECV_STATE_HEADER:
        ret = handle_block_header (client);
        if (ret < 0)
            break;

        if (client->recv_state == RECV_STATE_CONTENT &&
            client->info->task->type == TASK_TYPE_DOWNLOAD)
            ret = handle_block_content (client);

        break;
    case RECV_STATE_CONTENT:
        ret = handle_block_content (client);
        break;
    }

    if (ret < 0)
        client->break_loop = TRUE;
}
예제 #2
0
static void filter_client_line(void)
{
  int offset;
  const char* cmd;

  if (!handle_auth_response(&linebuf, 0)) {
    if ((offset = parse_label()) > 0) {
      cmd = linebuf.s + offset;
      /* If we see a "AUTHENTICATE" or "LOGIN" command, save the preceding
       * label for reference when looking for the corresponding "OK" */
      if(!strncasecmp(cmd, "AUTHENTICATE ", 13)) {
	if (handle_auth_parameter(&linebuf, offset + 13))
	  str_copy(&saved_label, &label);
      }
      else if (!strncasecmp(cmd, "LOGIN ", 6))
	handle_login(offset + 6);
    }
  }
}