Example #1
0
enum SCP_SERVER_STATES_E
scp_v1s_request_password(struct SCP_CONNECTION* c, struct SCP_SESSION* s, char* reason)
{
  tui8 sz;
  tui32 version;
  tui32 size;
  tui16 cmdset;
  tui16 cmd;
  int rlen;
  char buf[257];

  init_stream(c->in_s, c->in_s->size);
  init_stream(c->out_s, c->out_s->size);

  /* forcing message not to exceed 64k */
  rlen = g_strlen(reason);
  if (rlen > 65535)
  {
    rlen = 65535;
  }

  /* send password request */
  version=1;
  cmd=3;

  out_uint32_be(c->out_s, version);                 /* version */
  out_uint32_be(c->out_s, 14+rlen);                 /* size    */
  out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset  */
  out_uint16_be(c->out_s, cmd);                     /* cmd     */

  out_uint16_be(c->out_s, rlen);
  out_uint8p(c->out_s, reason, rlen);

  if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, 14+rlen))
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  /* receive password & username */
  if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  in_uint32_be(c->in_s, version);
  if (version!=1)
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__);
    return SCP_SERVER_STATE_VERSION_ERR;
  }

  in_uint32_be(c->in_s, size);
  if (size<12)
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__);
    return SCP_SERVER_STATE_SIZE_ERR;
  }

  init_stream(c->in_s, c->in_s->size);
  if (0!=scp_tcp_force_recv(c->in_sck, c->in_s->data, (size-8)))
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  in_uint16_be(c->in_s, cmdset);
  if (cmdset != SCP_COMMAND_SET_DEFAULT)
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__);
    return SCP_SERVER_STATE_SEQUENCE_ERR;
  }

  in_uint16_be(c->in_s, cmd);
  if (cmd != 4)
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__);
    return SCP_SERVER_STATE_SEQUENCE_ERR;
  }

  buf[256] = '\0';
  /* reading username */
  in_uint8(c->in_s, sz);
  buf[sz] = '\0';
  in_uint8a(c->in_s, buf, sz);
  if (0 != scp_session_set_username(s, buf))
  {
    scp_session_destroy(s);
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__);
    return SCP_SERVER_STATE_INTERNAL_ERR;
  }

  /* reading password */
  in_uint8(c->in_s, sz);
  buf[sz]='\0';
  in_uint8a(c->in_s, buf, sz);
  if (0 != scp_session_set_password(s, buf))
  {
    scp_session_destroy(s);
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__);
    return SCP_SERVER_STATE_INTERNAL_ERR;
  }

  return SCP_SERVER_STATE_OK;
}
Example #2
0
static enum SCP_SERVER_STATES_E
_scp_v1s_mng_check_response(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
{
    tui32 version;
    tui32 size;
    tui16 cmd;
    //   tui8 dim;
    //   char buf[257];

    init_stream(c->in_s, c->in_s->size);

    if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
    {
        log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    in_uint32_be(c->in_s, version);

    if (version != 1)
    {
        log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: version error", __LINE__);
        return SCP_SERVER_STATE_VERSION_ERR;
    }

    in_uint32_be(c->in_s, size);

    init_stream(c->in_s, c->in_s->size);

    /* read the rest of the packet */
    if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
    {
        log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    in_uint16_be(c->in_s, cmd);

    if (cmd != SCP_COMMAND_SET_MANAGE)
    {
        log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__);
        return SCP_SERVER_STATE_SEQUENCE_ERR;
    }

    in_uint16_be(c->in_s, cmd);

    if (cmd == SCP_CMD_MNG_LIST_REQ) /* request session list */
    {
        log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] request session list", __LINE__);
        return SCP_SERVER_STATE_MNG_LISTREQ;
    }
    else if (cmd == SCP_CMD_MNG_ACTION) /* execute an action */
    {
        /*in_uint8(c->in_s, dim);
        buf[dim]='\0';
        in_uint8a(c->in_s, buf, dim);
        scp_session_set_errstr(s, buf);*/

        log_message(LOG_LEVEL_INFO, "[v1s_mng:%d] action request", __LINE__);
        return SCP_SERVER_STATE_MNG_ACTION;
    }

    /* else if (cmd == 20) / * password change * /
    {
      in_uint16_be(c->in_s, s->display);

      return SCP_SERVER_STATE_OK;
    }
    else if (cmd == 40) / * session list * /
    {
      return SCP_SERVER_STATE_SESSION_LIST;
    }*/

    log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: sequence error", __LINE__);
    return SCP_SERVER_STATE_SEQUENCE_ERR;
}
Example #3
0
int EXPORT_CC
libxrdp_send_bitmap(struct xrdp_session* session, int width, int height,
                    int bpp, char* data, int x, int y, int cx, int cy)
{
  int line_size = 0;
  int i = 0;
  int j = 0;
  int total_lines = 0;
  int lines_sending = 0;
  int Bpp = 0;
  int e = 0;
  int bufsize = 0;
  int total_bufsize = 0;
  int num_updates = 0;
  char* p_num_updates = (char *)NULL;
  char* p = (char *)NULL;
  char* q = (char *)NULL;
  struct stream* s = (struct stream *)NULL;
  struct stream* temp_s = (struct stream *)NULL;

  DEBUG(("libxrdp_send_bitmap sending bitmap"));
  Bpp = (bpp + 7) / 8;
  e = width % 4;
  if (e != 0)
  {
    e = 4 - e;
  }
  line_size = width * Bpp;
  make_stream(s);
  init_stream(s, 8192);
  if (session->client_info->use_bitmap_comp)
  {
    make_stream(temp_s);
    init_stream(temp_s, 65536);
    i = 0;
    if (cy <= height)
    {
      i = cy;
    }
    while (i > 0)
    {
      total_bufsize = 0;
      num_updates = 0;
      xrdp_rdp_init_data((struct xrdp_rdp*)session->rdp, s);
      out_uint16_le(s, RDP_UPDATE_BITMAP);
      p_num_updates = s->p;
      out_uint8s(s, 2); /* num_updates set later */
      do
      {
        if (session->client_info->op1)
        {
          s_push_layer(s, channel_hdr, 18);
        }
        else
        {
          s_push_layer(s, channel_hdr, 26);
        }
        p = s->p;
        lines_sending = xrdp_bitmap_compress(data, width, height,
                                             s, bpp,
                                             4096 - total_bufsize,
                                             i - 1, temp_s, e);
        if (lines_sending == 0)
        {
          break;
        }
        num_updates++;
        bufsize = s->p - p;
        total_bufsize += bufsize;
        i = i - lines_sending;
        s_mark_end(s);
        s_pop_layer(s, channel_hdr);
        out_uint16_le(s, x); /* left */
        out_uint16_le(s, y + i); /* top */
        out_uint16_le(s, (x + cx) - 1); /* right */
        out_uint16_le(s, (y + i + lines_sending) - 1); /* bottom */
        out_uint16_le(s, width + e); /* width */
        out_uint16_le(s, lines_sending); /* height */
        out_uint16_le(s, bpp); /* bpp */
        if (session->client_info->op1)
        {
          out_uint16_le(s, 0x401); /* compress */
          out_uint16_le(s, bufsize); /* compressed size */
          j = (width + e) * Bpp;
          j = j * lines_sending;
        }
        else
        {
          out_uint16_le(s, 0x1); /* compress */
          out_uint16_le(s, bufsize + 8);
          out_uint8s(s, 2); /* pad */
          out_uint16_le(s, bufsize); /* compressed size */
          j = (width + e) * Bpp;
          out_uint16_le(s, j); /* line size */
          j = j * lines_sending;
          out_uint16_le(s, j); /* final size */
        }
        if (j > 32768)
        {
          g_writeln("error, decompressed size too big, its %d", j);
        }
        if (bufsize > 8192)
        {
          g_writeln("error, compressed size too big, its %d", bufsize);
        }
        s->p = s->end;
      } while (total_bufsize < 4096 && i > 0);
      p_num_updates[0] = num_updates;
      p_num_updates[1] = num_updates >> 8;
      xrdp_rdp_send_data((struct xrdp_rdp*)session->rdp, s,
                         RDP_DATA_PDU_UPDATE);
      if (total_bufsize > 8192)
      {
        g_writeln("error, total compressed size too big, its %d",
                 total_bufsize);
      }
    }
    free_stream(temp_s);
  }
Example #4
0
int APP_CC
trans_check_wait_objs(struct trans* self)
{
  tbus in_sck = (tbus)0;
  struct trans* in_trans = (struct trans *)NULL;
  int read_bytes = 0;
  int to_read = 0;
  int read_so_far = 0;
  int rv = 0;

  if (self == 0)
  {
    return 1;
  }
  if (self->status != TRANS_STATUS_UP)
  {
    return 1;
  }
  rv = 0;
  if (self->type1 == TRANS_TYPE_LISTENER) /* listening */
  {
    if (g_tcp_can_recv(self->sck, 0))
    {
      in_sck = g_tcp_accept(self->sck);
      if (in_sck == -1)
      {
        if (g_tcp_last_error_would_block(self->sck))
        {
          /* ok, but shouldn't happen */
        }
        else
        {
          /* error */
          self->status = TRANS_STATUS_DOWN;
          return 1;
        }
      }
      if (in_sck != -1)
      {
        if (self->trans_conn_in != 0) /* is function assigned */
        {
          in_trans = trans_create(self->mode, self->in_s->size,
                                  self->out_s->size);
          in_trans->sck = in_sck;
          in_trans->type1 = TRANS_TYPE_SERVER;
          in_trans->status = TRANS_STATUS_UP;
          if (self->trans_conn_in(self, in_trans) != 0)
          {
            trans_delete(in_trans);
          }
        }
        else
        {
          g_tcp_close(in_sck);
        }
      }
    }
  }
  else /* connected server or client (2 or 3) */
  {
    if (g_tcp_can_recv(self->sck, 0))
    {
      read_so_far = (int)(self->in_s->end - self->in_s->data);
      to_read = self->header_size - read_so_far;
      if (to_read > 0)
      {
        read_bytes = g_tcp_recv(self->sck, self->in_s->end, to_read, 0);
        if (read_bytes == -1)
        {
          if (g_tcp_last_error_would_block(self->sck))
          {
            /* ok, but shouldn't happen */
          }
          else
          {
            /* error */
            self->status = TRANS_STATUS_DOWN;
            return 1;
          }
        }
        else if (read_bytes == 0)
        {
          /* error */
          self->status = TRANS_STATUS_DOWN;
          return 1;
        }
        else
        {
          self->in_s->end += read_bytes;
        }
      }
      read_so_far = (int)(self->in_s->end - self->in_s->data);
      if (read_so_far == self->header_size)
      {
        if (self->trans_data_in != 0)
        {
          rv = self->trans_data_in(self);
          init_stream(self->in_s, 0);
        }
      }
    }
  }
  return rv;
}
Example #5
0
int main() {

    fprintf(stderr, "Starting audio_receiver test...\n");

    // Open files to write audio
    if ((F_audio1 = fopen(name_audio1, "wb")) == NULL) {
        perror(name_audio1);
        exit(errno);
    }
    if ((F_audio2 = fopen(name_audio2, "wb")) == NULL) {
        perror(name_audio2);
        exit(errno);
    }

    // General pourpouse variables.
    time_t start, stop;
    audio_frame2 *audio_frame;

    // Receiver configuration
    stream_list_t *video_stream_list = init_stream_list(); // Not used
    stream_list_t *audio_stream_list = init_stream_list();
    receiver_t *receiver = init_receiver(video_stream_list, audio_stream_list, 5004, 5006);

    // First stream and participant configuration
    participant_data_t *p1 = init_participant(1, INPUT, NULL, 0);
    stream_data_t *stream1 = init_stream(AUDIO, INPUT, rand(), I_AWAIT, 25.0, "Stream1");
    add_participant_stream(stream1, p1);
    add_stream(receiver->audio_stream_list, stream1);
    fprintf(stderr, " ·Stream1 configuration: 1 bps, 32000Hz, 1 channel, mulaw\n");
    ap_config(stream1->audio, 1, 32000, 1, AC_MULAW);
    ap_worker_start(stream1->audio);

    // Second stream and participant configuration
    participant_data_t *p2 = init_participant(2, INPUT, NULL, 0);
    stream_data_t *stream2 = init_stream(AUDIO, INPUT, rand(), I_AWAIT, 25.0, "Stream2");
    add_participant_stream(stream2, p2);
    add_stream(receiver->audio_stream_list, stream2);
    fprintf(stderr, " ·Stream2 configuration: 1 bps, 8000Hz, 1 channel, mulaw\n");
    ap_config(stream2->audio, 1, 8000, 1, AC_MULAW);
    ap_worker_start(stream2->audio);

    if (start_receiver(receiver)) {
        fprintf(stderr, " ·Receiver started!\n");

#ifdef STREAM1
        // STREAM1 recording block
        fprintf(stderr, "  ·Waiting for audio_frame2 data\n");
        while (stream1->audio->decoded_cq->level == CIRCULAR_QUEUE_EMPTY) {
#ifdef QUEUE_PRINT
            print_cq_status(stream1->audio->decoded_cq, "wait stream1");
#endif
        }
#ifdef QUEUE_PRINT
        print_cq_status(stream1->audio->decoded_cq, "continue stream1");
#endif

        fprintf(stderr, "   ·Copying to file... ");
        start = time(NULL);
        stop = start + RECORD_TIME;
        while (time(NULL) < stop) { // RECORD_TIME seconds loop
            audio_frame = cq_get_front(stream1->audio->decoded_cq);
            if (audio_frame != NULL) {
                fwrite(audio_frame->data[0], audio_frame->data_len[0], 1, F_audio1);
                cq_remove_bag(stream1->audio->decoded_cq);
            }
        }
        fprintf(stderr, "Done!\n");
#endif //STREAM1

#ifdef STREAM2
        // STREAM2 recording block
        fprintf(stderr, "  ·Waiting for audio_frame2 data\n");
        while (stream2->audio->decoded_cq->level == CIRCULAR_QUEUE_EMPTY) {
#ifdef QUEUE_PRINT
            print_cq_status(stream2->audio->decoded_cq, "wait stream2");
#endif
        }
#ifdef QUEUE_PRINT
        print_cq_status(stream2->audio->decoded_cq, "continue stream2");
#endif
        fprintf(stderr, "   ·Copying to file... ");
        start = time(NULL);
        stop = start + RECORD_TIME;
        while (time(NULL) < stop) { // RECORD_TIME seconds loop
            audio_frame = cq_get_front(stream2->audio->decoded_cq);
            if (audio_frame != NULL) {
                fwrite(audio_frame->data[0], audio_frame->data_len[0], 1, F_audio2);
                cq_remove_bag(stream2->audio->decoded_cq);
            }
        }
        fprintf(stderr, "Done!\n");
#endif //STREAM2

        // Finish and destroy objects
        stop_receiver(receiver);
        destroy_receiver(receiver);
        fprintf(stderr, " ·Receiver stopped\n");
        destroy_stream_list(video_stream_list);
        destroy_stream_list(audio_stream_list);
    }

    if (fclose(F_audio1) != 0) {
        perror(name_audio1);
        exit(-1);
    }
    if (fclose(F_audio2) != 0) {
        perror(name_audio2);
        exit(-1);
    }
    fprintf(stderr, "Finished\n");
}
Example #6
0
/* returns error
   returns 0 if everything is ok
   returns 1 if problem reading file */
static int APP_CC
l_file_read_sections(int fd, int max_file_size, struct list* names)
{
  struct stream* s;
  char text[256];
  char c;
  int in_it;
  int in_comment = false;
  int in_it_index;
  int len;
  int index;
  int rv;

  rv = 0;
  g_file_seek(fd, 0);
  in_it_index = 0;
  in_it = 0;
  g_memset(text, 0, 256);
  list_clear(names);
  make_stream(s);
  init_stream(s, max_file_size);
  len = g_file_read(fd, s->data, max_file_size);
  if (len > 0)
  {
    s->end = s->p + len;
    for (index = 0; index < len; index++)
    {
      in_uint8(s, c);
      if (c == '#' || c == ';' || c == '/')
      {
        in_comment = true;
        continue;
      }
      else if (c == '\n')
      {
        in_comment = false;
        continue;
      }
      if (in_comment)
      {
        continue;
      }
      if (c == '[')
      {
        in_it = 1;
      }
      else if (c == ']')
      {
        list_add_item(names, (tbus)g_strdup(text));
        in_it = 0;
        in_it_index = 0;
        g_memset(text, 0, 256);
      }
      else if (in_it)
      {
        text[in_it_index] = c;
        in_it_index++;
      }
    }
  }
  else if (len < 0)
  {
    rv = 1;
  }
  free_stream(s);
  return rv;
}
Example #7
0
HS_PUBLIC_API
hs_error_t hs_scan_vector(const hs_database_t *db, const char * const * data,
                          const unsigned int *length, unsigned int count,
                          UNUSED unsigned int flags, hs_scratch_t *scratch,
                          match_event_handler onEvent, void *context) {
    if (unlikely(!scratch || !data || !length)) {
        return HS_INVALID;
    }

    hs_error_t err = validDatabase(db);
    if (unlikely(err != HS_SUCCESS)) {
        return err;
    }

    const struct RoseEngine *rose = hs_get_bytecode(db);
    if (unlikely(!ISALIGNED_16(rose))) {
        return HS_INVALID;
    }

    if (unlikely(rose->mode != HS_MODE_VECTORED)) {
        return HS_DB_MODE_ERROR;
    }

    if (unlikely(!validScratch(rose, scratch))) {
        return HS_INVALID;
    }

    if (unlikely(markScratchInUse(scratch))) {
        return HS_SCRATCH_IN_USE;
    }

    hs_stream_t *id = (hs_stream_t *)(scratch->bstate);

    init_stream(id, rose); /* open stream */

    for (u32 i = 0; i < count; i++) {
        DEBUG_PRINTF("block %u/%u offset=%llu len=%u\n", i, count, id->offset,
                     length[i]);
#ifdef DEBUG
        dumpData(data[i], length[i]);
#endif
        hs_error_t ret
            = hs_scan_stream_internal(id, data[i], length[i], 0, scratch,
                                      onEvent, context);
        if (ret != HS_SUCCESS) {
            unmarkScratchInUse(scratch);
            return ret;
        }
    }

    /* close stream */
    if (onEvent) {
        report_eod_matches(id, scratch, onEvent, context);

        if (told_to_stop_matching(scratch)) {
            unmarkScratchInUse(scratch);
            return HS_SCAN_TERMINATED;
        }
    }

    unmarkScratchInUse(scratch);

    return HS_SUCCESS;
}
Example #8
0
/* returns error */
static int APP_CC
process_message_channel_data(struct stream *s)
{
    int chan_id = 0;
    int chan_flags = 0;
    int rv = 0;
    int length = 0;
    int total_length = 0;
    struct stream *ls;

    in_uint16_le(s, chan_id);
    in_uint16_le(s, chan_flags);
    in_uint16_le(s, length);
    in_uint32_le(s, total_length);
    LOGM((LOG_LEVEL_DEBUG, "process_message_channel_data: chan_id %d "
          "chan_flags %d", chan_id, chan_flags));
    LOG(10, ("process_message_channel_data"));
    rv = send_channel_data_response_message();

    if (rv == 0)
    {
        if (chan_id == g_cliprdr_chan_id)
        {
            rv = clipboard_data_in(s, chan_id, chan_flags, length, total_length);
        }
        else if (chan_id == g_rdpsnd_chan_id)
        {
            rv = sound_data_in(s, chan_id, chan_flags, length, total_length);
        }
        else if (chan_id == g_rdpdr_chan_id)
        {
            rv = dev_redir_data_in(s, chan_id, chan_flags, length, total_length);
        }
        else if (chan_id == g_rail_chan_id)
        {
            rv = rail_data_in(s, chan_id, chan_flags, length, total_length);
        }
        else if (chan_id == g_drdynvc_chan_id)
        {
            rv = drdynvc_data_in(s, chan_id, chan_flags, length, total_length);
        }
        else if (chan_id == ((struct xrdp_api_data *)
                             (g_api_con_trans->callback_data))->chan_id)
        {
            LOG(10, ("process_message_channel_data length %d total_length %d "
                     "chan_flags 0x%8.8x", length, total_length, chan_flags));
            ls = g_api_con_trans->out_s;

            if (chan_flags & 1) /* first */
            {
                init_stream(ls, total_length);
            }

            out_uint8a(ls, s->p, length);

            if (chan_flags & 2) /* last */
            {
                s_mark_end(ls);
                trans_force_write(g_api_con_trans);
            }
        }
    }

    return rv;
}
Example #9
0
enum SCP_CLIENT_STATES_E
scp_v0c_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
{
    tui32 version;
    tui32 size;
    tui16 sz;

    init_stream(c->in_s, c->in_s->size);
    init_stream(c->out_s, c->in_s->size);

    LOG_DBG("[v0:%d] starting connection", __LINE__);
    g_tcp_set_non_blocking(c->in_sck);
    g_tcp_set_no_delay(c->in_sck);
    s_push_layer(c->out_s, channel_hdr, 8);

    /* code */
    if (s->type == SCP_SESSION_TYPE_XVNC)
    {
        out_uint16_be(c->out_s, 0);
    }
    else if (s->type == SCP_SESSION_TYPE_XRDP)
    {
        out_uint16_be(c->out_s, 10);
    }
    else if (s->type == SCP_SESSION_TYPE_XORG)
    {
        out_uint16_be(c->out_s, 20);
    }
    else
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
        return SCP_CLIENT_STATE_INTERNAL_ERR;
    }

    sz = g_strlen(s->username);
    out_uint16_be(c->out_s, sz);
    out_uint8a(c->out_s, s->username, sz);

    sz = g_strlen(s->password);
    out_uint16_be(c->out_s, sz);
    out_uint8a(c->out_s, s->password, sz);
    out_uint16_be(c->out_s, s->width);
    out_uint16_be(c->out_s, s->height);
    out_uint16_be(c->out_s, s->bpp);

    s_mark_end(c->out_s);
    s_pop_layer(c->out_s, channel_hdr);

    /* version */
    out_uint32_be(c->out_s, 0);
    /* size */
    out_uint32_be(c->out_s, c->out_s->end - c->out_s->data);

    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
        return SCP_CLIENT_STATE_NETWORK_ERR;
    }

    if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
        return SCP_CLIENT_STATE_NETWORK_ERR;
    }

    in_uint32_be(c->in_s, version);

    if (0 != version)
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__);
        return SCP_CLIENT_STATE_VERSION_ERR;
    }

    in_uint32_be(c->in_s, size);

    if (size < 14)
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: packet size error", __LINE__);
        return SCP_CLIENT_STATE_SIZE_ERR;
    }

    /* getting payload */
    init_stream(c->in_s, c->in_s->size);

    if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
        return SCP_CLIENT_STATE_NETWORK_ERR;
    }

    /* check code */
    in_uint16_be(c->in_s, sz);

    if (3 != sz)
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__);
        return SCP_CLIENT_STATE_SEQUENCE_ERR;
    }

    /* message payload */
    in_uint16_be(c->in_s, sz);

    if (1 != sz)
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: connection denied", __LINE__);
        return SCP_CLIENT_STATE_CONNECTION_DENIED;
    }

    in_uint16_be(c->in_s, sz);
    s->display = sz;

    LOG_DBG("[v0:%d] connection terminated", __LINE__);
    return SCP_CLIENT_STATE_END;
}
Example #10
0
/* send a chunk of the file from server to client */
static int APP_CC
clipboard_send_file_data(int streamId, int lindex,
                         int nPositionLow, int cbRequested)
{
    struct stream *s;
    int size;
    int rv;
    int fd;
    char full_fn[256];
    struct cb_file_info *cfi;

    if (g_files_list == 0)
    {
        log_error("clipboard_send_file_data: error g_files_list is nil");
        return 1;
    }
    cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex);
    if (cfi == 0)
    {
        log_error("clipboard_send_file_data: error cfi is nil");
        return 1;
    }
    log_debug("clipboard_send_file_data: streamId %d lindex %d "
                "nPositionLow %d cbRequested %d", streamId, lindex,
                nPositionLow, cbRequested);
    g_snprintf(full_fn, 255, "%s/%s", cfi->pathname, cfi->filename);
    fd = g_file_open_ex(full_fn, 1, 0, 0, 0);
    if (fd == -1)
    {
        log_error("clipboard_send_file_data: file open [%s] failed",
                   full_fn);
        return 1;
    }
    if (g_file_seek(fd, nPositionLow) < 0)
    {
        log_message(LOG_LEVEL_ERROR, "clipboard_send_file_data: seek error "
            "in file: %s", full_fn);
        g_file_close(fd);
        return 1;
    }
    make_stream(s);
    init_stream(s, cbRequested + 64);
    size = g_file_read(fd, s->data + 12, cbRequested);
    if (size < 1)
    {
        log_error("clipboard_send_file_data: read error, want %d got %d",
                   cbRequested, size);
        free_stream(s);
        g_file_close(fd);
        return 1;
    }
    out_uint16_le(s, CB_FILECONTENTS_RESPONSE); /* 9 */
    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
    out_uint32_le(s, size + 4);
    out_uint32_le(s, streamId);
    s->p += size;
    out_uint32_le(s, 0);
    s_mark_end(s);
    size = (int)(s->end - s->data);
    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
    free_stream(s);
    g_file_close(fd);
    return rv;
}
Example #11
0
enum SCP_SERVER_STATES_E
scp_v0s_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s, int skipVchk)
{
    tui32 version = 0;
    tui32 size;
    struct SCP_SESSION *session = 0;
    tui16 sz;
    tui32 code = 0;
    char buf[257];

    if (!skipVchk)
    {
        LOG_DBG("[v0:%d] starting connection", __LINE__);

        if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
        {
            c->in_s->end = c->in_s->data + 8;
            in_uint32_be(c->in_s, version);

            if (version != 0)
            {
                log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: version error", __LINE__);
                return SCP_SERVER_STATE_VERSION_ERR;
            }
        }
        else
        {
            log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
            return SCP_SERVER_STATE_NETWORK_ERR;
        }
    }

    in_uint32_be(c->in_s, size);

    init_stream(c->in_s, 8196);

    if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    c->in_s->end = c->in_s->data + (size - 8);

    in_uint16_be(c->in_s, code);

    if (code == 0 || code == 10 || code == 20)
    {
        session = scp_session_create();

        if (0 == session)
        {
            log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
            return SCP_SERVER_STATE_INTERNAL_ERR;
        }

        scp_session_set_version(session, version);

        if (code == 0)
        {
            scp_session_set_type(session, SCP_SESSION_TYPE_XVNC);
        }
        else if (code == 10)
        {
            scp_session_set_type(session, SCP_SESSION_TYPE_XRDP);
        }
        else if (code == 20)
        {
            scp_session_set_type(session, SCP_SESSION_TYPE_XORG);
        }

        /* reading username */
        in_uint16_be(c->in_s, sz);
        buf[sz] = '\0';
        in_uint8a(c->in_s, buf, sz);

        if (0 != scp_session_set_username(session, buf))
        {
            scp_session_destroy(session);
            log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting username", __LINE__);
            return SCP_SERVER_STATE_INTERNAL_ERR;
        }

        /* reading password */
        in_uint16_be(c->in_s, sz);
        buf[sz] = '\0';
        in_uint8a(c->in_s, buf, sz);

        if (0 != scp_session_set_password(session, buf))
        {
            scp_session_destroy(session);
            log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__);
            return SCP_SERVER_STATE_INTERNAL_ERR;
        }

        /* width */
        in_uint16_be(c->in_s, sz);
        scp_session_set_width(session, sz);
        /* height */
        in_uint16_be(c->in_s, sz);
        scp_session_set_height(session, sz);
        /* bpp */
        in_uint16_be(c->in_s, sz);
        scp_session_set_bpp(session, (tui8)sz);

        if (s_check_rem(c->in_s, 2))
        {
            /* reading domain */
            in_uint16_be(c->in_s, sz);

            if (sz > 0)
            {
                in_uint8a(c->in_s, buf, sz);
                buf[sz] = '\0';
                scp_session_set_domain(session, buf);
            }
        }

        if (s_check_rem(c->in_s, 2))
        {
            /* reading program */
            in_uint16_be(c->in_s, sz);

            if (sz > 0)
            {
                in_uint8a(c->in_s, buf, sz);
                buf[sz] = '\0';
                scp_session_set_program(session, buf);
            }
        }

        if (s_check_rem(c->in_s, 2))
        {
            /* reading directory */
            in_uint16_be(c->in_s, sz);

            if (sz > 0)
            {
                in_uint8a(c->in_s, buf, sz);
                buf[sz] = '\0';
                scp_session_set_directory(session, buf);
            }
        }

        if (s_check_rem(c->in_s, 2))
        {
            /* reading client IP address */
            in_uint16_be(c->in_s, sz);

            if (sz > 0)
            {
                in_uint8a(c->in_s, buf, sz);
                buf[sz] = '\0';
                scp_session_set_client_ip(session, buf);
            }
        }
    }
    else if (code == SCP_GW_AUTHENTICATION)
    {
        /* g_writeln("Command is SCP_GW_AUTHENTICATION"); */
        session = scp_session_create();

        if (0 == session)
        {
            /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error",      __LINE__);*/
            return SCP_SERVER_STATE_INTERNAL_ERR;
        }

        scp_session_set_version(session, version);
        scp_session_set_type(session, SCP_GW_AUTHENTICATION);
        /* reading username */
        in_uint16_be(c->in_s, sz);
        buf[sz] = '\0';
        in_uint8a(c->in_s, buf, sz);

        /* g_writeln("Received user name: %s",buf); */
        if (0 != scp_session_set_username(session, buf))
        {
            scp_session_destroy(session);
            /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting        username", __LINE__);*/
            return SCP_SERVER_STATE_INTERNAL_ERR;
        }

        /* reading password */
        in_uint16_be(c->in_s, sz);
        buf[sz] = '\0';
        in_uint8a(c->in_s, buf, sz);

        /* g_writeln("Received password: %s",buf); */
        if (0 != scp_session_set_password(session, buf))
        {
            scp_session_destroy(session);
            /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: error setting password", __LINE__); */
            return SCP_SERVER_STATE_INTERNAL_ERR;
        }
    }
    else
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: sequence error", __LINE__);
        return SCP_SERVER_STATE_SEQUENCE_ERR;
    }

    (*s) = session;
    return SCP_SERVER_STATE_OK;
}
Example #12
0
int
xrdp_caps_send_demand_active(struct xrdp_rdp *self)
{
    struct stream *s;
    int caps_count;
    int caps_size;
    int codec_caps_count;
    int codec_caps_size;
    int flags;
    char *caps_count_ptr;
    char *caps_size_ptr;
    char *caps_ptr;
    char *codec_caps_count_ptr;
    char *codec_caps_size_ptr;

    make_stream(s);
    init_stream(s, 8192);

    DEBUG(("in xrdp_caps_send_demand_active"));

    if (xrdp_rdp_init(self, s) != 0)
    {
        free_stream(s);
        return 1;
    }

    caps_count = 0;
    out_uint32_le(s, self->share_id);
    out_uint16_le(s, 4); /* 4 chars for RDP\0 */
    /* 2 bytes size after num caps, set later */
    caps_size_ptr = s->p;
    out_uint8s(s, 2);
    out_uint8a(s, "RDP", 4);
    /* 4 byte num caps, set later */
    caps_count_ptr = s->p;
    out_uint8s(s, 4);
    caps_ptr = s->p;

    /* Output share capability set */
    caps_count++;
    out_uint16_le(s, CAPSTYPE_SHARE);
    out_uint16_le(s, CAPSTYPE_SHARE_LEN);
    out_uint16_le(s, self->mcs_channel);
    out_uint16_be(s, 0xb5e2); /* 0x73e1 */

    /* Output general capability set */
    caps_count++;
    out_uint16_le(s, CAPSTYPE_GENERAL);
    out_uint16_le(s, CAPSTYPE_GENERAL_LEN);
    out_uint16_le(s, OSMAJORTYPE_WINDOWS);
    out_uint16_le(s, OSMINORTYPE_WINDOWS_NT);
    out_uint16_le(s, 0x200); /* Protocol version */
    out_uint16_le(s, 0); /* pad */
    out_uint16_le(s, 0); /* Compression types */
    if (self->client_info.use_fast_path & 1)
    {
        out_uint16_le(s, NO_BITMAP_COMPRESSION_HDR | FASTPATH_OUTPUT_SUPPORTED);
    }
    else
    {
        out_uint16_le(s, NO_BITMAP_COMPRESSION_HDR);
    }
    out_uint16_le(s, 0); /* Update capability */
    out_uint16_le(s, 0); /* Remote unshare capability */
    out_uint16_le(s, 0); /* Compression level */
    out_uint16_le(s, 0); /* Pad */

    /* Output bitmap capability set */
    caps_count++;
    out_uint16_le(s, CAPSTYPE_BITMAP);
    out_uint16_le(s, CAPSTYPE_BITMAP_LEN);
    out_uint16_le(s, self->client_info.bpp); /* Preferred BPP */
    out_uint16_le(s, 1); /* Receive 1 BPP */
    out_uint16_le(s, 1); /* Receive 4 BPP */
    out_uint16_le(s, 1); /* Receive 8 BPP */
    out_uint16_le(s, self->client_info.width); /* width */
    out_uint16_le(s, self->client_info.height); /* height */
    out_uint16_le(s, 0); /* Pad */
    out_uint16_le(s, 1); /* Allow resize */
    out_uint16_le(s, 1); /* bitmap compression */
    out_uint16_le(s, 0); /* unknown */
    out_uint16_le(s, 0); /* unknown */
    out_uint16_le(s, 0); /* pad */

    /* Output font capability set */
    caps_count++;
    out_uint16_le(s, CAPSTYPE_FONT);
    out_uint16_le(s, CAPSTYPE_FONT_LEN);

    /* Output order capability set */
    caps_count++;
    out_uint16_le(s, CAPSTYPE_ORDER);
    out_uint16_le(s, CAPSTYPE_ORDER_LEN);
    out_uint8s(s, 16);
    out_uint32_be(s, 0x40420f00);
    out_uint16_le(s, 1); /* Cache X granularity */
    out_uint16_le(s, 20); /* Cache Y granularity */
    out_uint16_le(s, 0); /* Pad */
    out_uint16_le(s, 1); /* Max order level */
    out_uint16_le(s, 0x2f); /* Number of fonts */
    out_uint16_le(s, 0x22); /* Capability flags */
    /* caps */
    out_uint8(s, 1); /* NEG_DSTBLT_INDEX                0x00 0 */
    out_uint8(s, 1); /* NEG_PATBLT_INDEX                0x01 1 */
    out_uint8(s, 1); /* NEG_SCRBLT_INDEX                0x02 2 */
    out_uint8(s, 1); /* NEG_MEMBLT_INDEX                0x03 3 */
    out_uint8(s, 0); /* NEG_MEM3BLT_INDEX               0x04 4 */
    out_uint8(s, 0); /* NEG_ATEXTOUT_INDEX              0x05 5 */
    out_uint8(s, 0); /* NEG_AEXTTEXTOUT_INDEX           0x06 6 */
    out_uint8(s, 0); /* NEG_DRAWNINEGRID_INDEX          0x07 7 */
    out_uint8(s, 1); /* NEG_LINETO_INDEX                0x08 8 */
    out_uint8(s, 0); /* NEG_MULTI_DRAWNINEGRID_INDEX    0x09 9 */
    out_uint8(s, 1); /* NEG_OPAQUE_RECT_INDEX           0x0A 10 */
    out_uint8(s, 0); /* NEG_SAVEBITMAP_INDEX            0x0B 11 */
    out_uint8(s, 0); /* NEG_WTEXTOUT_INDEX              0x0C 12 */
    out_uint8(s, 0); /* NEG_MEMBLT_V2_INDEX             0x0D 13 */
    out_uint8(s, 0); /* NEG_MEM3BLT_V2_INDEX            0x0E 14 */
    out_uint8(s, 0); /* NEG_MULTIDSTBLT_INDEX           0x0F 15 */
    out_uint8(s, 0); /* NEG_MULTIPATBLT_INDEX           0x10 16 */
    out_uint8(s, 0); /* NEG_MULTISCRBLT_INDEX           0x11 17 */
    out_uint8(s, 1); /* NEG_MULTIOPAQUERECT_INDEX       0x12 18 */
    out_uint8(s, 0); /* NEG_FAST_INDEX_INDEX            0x13 19 */
    out_uint8(s, 0); /* NEG_POLYGON_SC_INDEX            0x14 20 */
    out_uint8(s, 0); /* NEG_POLYGON_CB_INDEX            0x15 21 */
    out_uint8(s, 0); /* NEG_POLYLINE_INDEX              0x16 22 */
    out_uint8(s, 0); /* unused                          0x17 23 */
    out_uint8(s, 0); /* NEG_FAST_GLYPH_INDEX            0x18 24 */
    out_uint8(s, 0); /* NEG_ELLIPSE_SC_INDEX            0x19 25 */
    out_uint8(s, 0); /* NEG_ELLIPSE_CB_INDEX            0x1A 26 */
    out_uint8(s, 1); /* NEG_GLYPH_INDEX_INDEX           0x1B 27 */
    out_uint8(s, 0); /* NEG_GLYPH_WEXTTEXTOUT_INDEX     0x1C 28 */
    out_uint8(s, 0); /* NEG_GLYPH_WLONGTEXTOUT_INDEX    0x1D 29 */
    out_uint8(s, 0); /* NEG_GLYPH_WLONGEXTTEXTOUT_INDEX 0x1E 30 */
    out_uint8(s, 0); /* unused                          0x1F 31 */
    out_uint16_le(s, 0x6a1);
    /* declare support of bitmap cache rev3 */
    out_uint16_le(s, XR_ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT);
    out_uint32_le(s, 0x0f4240); /* desk save */
    out_uint32_le(s, 0x0f4240); /* desk save */
    out_uint32_le(s, 1); /* ? */
    out_uint32_le(s, 0); /* ? */

    /* Output bmpcodecs capability set */
    caps_count++;
    out_uint16_le(s, CAPSSETTYPE_BITMAP_CODECS);
    codec_caps_size_ptr = s->p;
    out_uint8s(s, 2); /* cap len set later */
    codec_caps_count = 0;
    codec_caps_count_ptr = s->p;
    out_uint8s(s, 1); /* bitmapCodecCount set later */
    /* nscodec */
    codec_caps_count++;
    out_uint8a(s, XR_CODEC_GUID_NSCODEC, 16);
    out_uint8(s, 1); /* codec id, must be 1 */
    out_uint16_le(s, 3); /* codecPropertiesLength */
    out_uint8(s, 0x01); /* fAllowDynamicFidelity */
    out_uint8(s, 0x01); /* fAllowSubsampling */
    out_uint8(s, 0x03); /* colorLossLevel */
#if defined(XRDP_RFXCODEC) || defined(XRDP_NEUTRINORDP)
    /* remotefx */
    codec_caps_count++;
    out_uint8a(s, XR_CODEC_GUID_REMOTEFX, 16);
    out_uint8(s, 0); /* codec id, client sets */
    out_uint16_le(s, 4); /* codecPropertiesLength */
    out_uint32_le(s, 0); /* reserved */
    /* image remotefx */
    codec_caps_count++;
    out_uint8a(s, XR_CODEC_GUID_IMAGE_REMOTEFX, 16);
    out_uint8(s, 0); /* codec id, client sets */
    out_uint16_le(s, 4); /* codecPropertiesLength */
    out_uint32_le(s, 0); /* reserved */
#endif
    /* jpeg */
    codec_caps_count++;
    out_uint8a(s, XR_CODEC_GUID_JPEG, 16);
    out_uint8(s, 0); /* codec id, client sets */
    out_uint16_le(s, 1); /* codecPropertiesLength */
    out_uint8(s, 75); /* jpeg compression ratio */
    /* calculate and set size and count */
    codec_caps_size = (int)(s->p - codec_caps_size_ptr);
    codec_caps_size += 2; /* 2 bytes for CAPSTYPE_BMPCODECS above */
    codec_caps_size_ptr[0] = codec_caps_size;
    codec_caps_size_ptr[1] = codec_caps_size >> 8;
    codec_caps_count_ptr[0] = codec_caps_count;

    /* Output color cache capability set */
    caps_count++;
    out_uint16_le(s, CAPSTYPE_COLORCACHE);
    out_uint16_le(s, CAPSTYPE_COLORCACHE_LEN);
    out_uint16_le(s, 6); /* cache size */
    out_uint16_le(s, 0); /* pad */

    /* Output pointer capability set */
    caps_count++;
    out_uint16_le(s, CAPSTYPE_POINTER);
    out_uint16_le(s, CAPSTYPE_POINTER_LEN);
    out_uint16_le(s, 1); /* Colour pointer */
    out_uint16_le(s, 0x19); /* Cache size */
    out_uint16_le(s, 0x19); /* Cache size */

    /* Output input capability set */
    caps_count++;
    out_uint16_le(s, CAPSTYPE_INPUT);
    out_uint16_le(s, CAPSTYPE_INPUT_LEN);

    flags = INPUT_FLAG_SCANCODES |
            INPUT_FLAG_MOUSEX    |
            INPUT_FLAG_UNICODE   |
            TS_INPUT_FLAG_MOUSE_HWHEEL;

    if (self->client_info.use_fast_path & 2)
    {
        flags |= INPUT_FLAG_FASTPATH_INPUT | INPUT_FLAG_FASTPATH_INPUT2;
    }
    out_uint16_le(s, flags);
    out_uint8s(s, 82);

    if (self->client_info.rail_enable) /* MS-RDPERP 3.3.5.1.4 */
    {
        /* Remote Programs Capability Set */
        caps_count++;
        out_uint16_le(s, CAPSTYPE_RAIL);
        out_uint16_le(s, 8); /* LengthCapability: MS-RDPERP 2.2.1.1.1 */
        out_uint32_le(s, 3); /* See: https://msdn.microsoft.com/en-us/library/cc242518.aspx
                                TS_RAIL_LEVEL_SUPPORTED
                                TS_RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED */

        /* Window List Capability Set */
        caps_count++;
        out_uint16_le(s, CAPSTYPE_WINDOW);
        out_uint16_le(s, 11); /* LengthCapability: MS-RDPERP 2.2.1.1.2 */
        out_uint32_le(s, TS_WINDOW_LEVEL_SUPPORTED_EX);
        out_uint8(s, 3); /* NumIconCaches */
        out_uint16_le(s, 12); /* NumIconCacheEntries */
    }

    /* 6 - bitmap cache v3 codecid */
    caps_count++;
    out_uint16_le(s, 0x0006);
    out_uint16_le(s, 5);
    out_uint8(s, 0); /* client sets */

    if (self->client_info.use_fast_path & FASTPATH_OUTPUT_SUPPORTED) /* fastpath output on */
    {
        /* multifragment update */
        caps_count++;
        out_uint16_le(s, CAPSSETTYPE_MULTIFRAGMENTUPDATE);
        out_uint16_le(s, CAPSSETTYPE_MULTIFRAGMENTUPDATE_LEN);
        out_uint32_le(s, 3 * 1024 * 1024); /* 3MB */

        /* frame acks */
        caps_count++;
        out_uint16_le(s, CAPSTYPE_FRAME_ACKNOWLEDGE);
        out_uint16_le(s, CAPSTYPE_FRAME_ACKNOWLEDGE_LEN);
        out_uint32_le(s, 2); /* 2 frames in flight */

        /* surface commands */
        caps_count++;
        out_uint16_le(s, CAPSETTYPE_SURFACE_COMMANDS);
        out_uint16_le(s, CAPSETTYPE_SURFACE_COMMANDS_LEN);
        out_uint32_le(s, (SURFCMDS_SETSURFACEBITS |
                          SURFCMDS_FRAMEMARKER |
                          SURFCMDS_STREAMSUFRACEBITS)); /* cmdFlags */
        out_uint32_le(s, 0); /* reserved */
    }

    out_uint8s(s, 4); /* pad */

    s_mark_end(s);

    caps_size = (int)(s->end - caps_ptr);
    caps_size_ptr[0] = caps_size;
    caps_size_ptr[1] = caps_size >> 8;

    caps_count_ptr[0] = caps_count;
    caps_count_ptr[1] = caps_count >> 8;
    caps_count_ptr[2] = caps_count >> 16;
    caps_count_ptr[3] = caps_count >> 24;

    if (xrdp_rdp_send(self, s, PDUTYPE_DEMANDACTIVEPDU) != 0)
    {
        free_stream(s);
        return 1;
    }
    DEBUG(("out (1) xrdp_caps_send_demand_active"));

    /* send Monitor Layout PDU for dual monitor */
    if (self->client_info.monitorCount > 0 &&
        self->client_info.multimon == 1)
    {
        DEBUG(("xrdp_caps_send_demand_active: sending monitor layout pdu"));
        if (xrdp_caps_send_monitorlayout(self) != 0)
        {
          g_writeln("xrdp_caps_send_demand_active: error sending monitor layout pdu");
        }
    }

    free_stream(s);
    return 0;
}
Example #13
0
void* scp_process_start(void *sck)
{
	struct SCP_CONNECTION scon;
	struct SCP_SESSION *sdata;

	/* making a local copy of the socket (it's on the stack) */
	/* probably this is just paranoia                        */
	scon.in_sck = g_thread_sck;
	LOG_DBG("started scp thread on socket %d", scon.in_sck);

	/* unlocking g_thread_sck */
	lock_socket_release();

	make_stream(scon.in_s);
	make_stream(scon.out_s);

	init_stream(scon.in_s, 8192);
	init_stream(scon.out_s, 8192);

	switch (scp_vXs_accept(&scon, &(sdata)))
	{
		case SCP_SERVER_STATE_OK:

			if (sdata->version == 0)
			{
				/* starts processing an scp v0 connection */
				LOG_DBG("accept ok, go on with scp v0\n", 0);
				scp_v0_process(&scon, sdata);
			}
			else
			{
				LOG_DBG("accept ok, go on with scp v1\n", 0);
				/*LOG_DBG("user: %s\npass: %s",sdata->username, sdata->password);*/
				scp_v1_process(&scon, sdata);
			}
			break;

		case SCP_SERVER_STATE_START_MANAGE:
			/* starting a management session */
			log_message(LOG_LEVEL_WARNING, "starting a sesman management session...");
			scp_v1_mng_process(&scon, sdata);
			break;

		case SCP_SERVER_STATE_VERSION_ERR:
			/* an unknown scp version was requested, so we shut down the */
			/* connection (and log the fact)                             */
			log_message(LOG_LEVEL_WARNING, "unknown protocol version specified. connection refused.");
			break;

		case SCP_SERVER_STATE_NETWORK_ERR:
			log_message(LOG_LEVEL_WARNING, "libscp network error.");
			break;

		case SCP_SERVER_STATE_SEQUENCE_ERR:
			log_message(LOG_LEVEL_WARNING, "libscp sequence error.");
			break;

		case SCP_SERVER_STATE_INTERNAL_ERR:
			/* internal error occurred (eg. malloc() error, ecc.) */
			log_message(LOG_LEVEL_ERROR, "libscp internal error occurred.");
			break;

		default:
			log_message(LOG_LEVEL_ALWAYS, "unknown return from scp_vXs_accept()");
	}

	g_tcp_close(scon.in_sck);
	free_stream(scon.in_s);
	free_stream(scon.out_s);
	return 0;
}
Example #14
0
File: frame.c Project: richq/w3m
static int
createFrameFile(struct frameset *f, FILE * f1, Buffer *current, int level,
		int force_reload)
{
    int r, c, t_stack;
    URLFile f2;
#ifdef USE_M17N
    wc_ces charset, doc_charset;
#endif
    char *d_target, *p_target, *s_target, *t_target;
    ParsedURL *currentURL, base;
    MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL;
    int flag;

    if (f == NULL)
	return -1;

    if (level == 0) {
	if (SETJMP(AbortLoading) != 0) {
	    TRAP_OFF;
	    return -1;
	}
	TRAP_ON;
	f->name = "_top";
    }

    if (level > 7) {
	fputs("Too many frameset tasked.\n", f1);
	return -1;
    }

    if (level == 0) {
	fprintf(f1, "<html><head><title>%s</title></head><body>\n",
		html_quote(current->buffername));
	fputs("<table hborder width=\"100%\">\n", f1);
    }
    else
	fputs("<table hborder>\n", f1);

    currentURL = f->currentURL ? f->currentURL : &current->currentURL;
    for (r = 0; r < f->row; r++) {
	fputs("<tr valign=top>\n", f1);
	for (c = 0; c < f->col; c++) {
	    union frameset_element frame;
	    struct frameset *f_frameset;
	    int i = c + r * f->col;
	    char *p = "";
	    int status = R_ST_NORMAL;
	    Str tok = Strnew();
	    int pre_mode = 0;
	    int end_tag = 0;

	    frame = f->frame[i];

	    if (frame.element == NULL) {
		fputs("<td>\n</td>\n", f1);
		continue;
	    }

	    fputs("<td", f1);
	    if (frame.element->name)
		fprintf(f1, " id=\"_%s\"", html_quote(frame.element->name));
	    if (!r)
		fprintf(f1, " width=\"%s\"", f->width[c]);
	    fputs(">\n", f1);

	    flag = 0;
	    if (force_reload) {
		flag |= RG_NOCACHE;
		if (frame.element->attr == F_BODY)
		    unloadFrame(frame.body);
	    }
	    switch (frame.element->attr) {
	    default:
		/* FIXME: gettextize? */
		fprintf(f1, "Frameset \"%s\" frame %d: type unrecognized",
			html_quote(f->name), i + 1);
		break;
	    case F_UNLOADED:
		if (!frame.body->name && f->name) {
		    frame.body->name = Sprintf("%s_%d", f->name, i)->ptr;
		}
		fflush(f1);
		f_frameset = frame_download_source(frame.body,
						   currentURL,
						   current->baseURL, flag);
		if (f_frameset) {
		    deleteFrame(frame.body);
		    f->frame[i].set = frame.set = f_frameset;
		    goto render_frameset;
		}
		/* fall through */
	    case F_BODY:
		init_stream(&f2, SCM_LOCAL, NULL);
		if (frame.body->source) {
		    fflush(f1);
		    examineFile(frame.body->source, &f2);
		}
		if (f2.stream == NULL) {
		    frame.body->attr = F_UNLOADED;
		    if (frame.body->flags & FB_NO_BUFFER)
			/* FIXME: gettextize? */
			fprintf(f1, "Open %s with other method",
				html_quote(frame.body->url));
		    else if (frame.body->url)
			/* FIXME: gettextize? */
			fprintf(f1, "Can't open %s",
				html_quote(frame.body->url));
		    else
			/* FIXME: gettextize? */
			fprintf(f1,
				"This frame (%s) contains no src attribute",
				frame.body->name ? html_quote(frame.body->name)
				: "(no name)");
		    break;
		}
		parseURL2(frame.body->url, &base, currentURL);
		p_target = f->name;
		s_target = frame.body->name;
		t_target = "_blank";
		d_target = TargetSelf ? s_target : t_target;
#ifdef USE_M17N
		charset = WC_CES_US_ASCII;
		if (current->document_charset != WC_CES_US_ASCII)
		    doc_charset = current->document_charset;
		else
		    doc_charset = DocumentCharset;
#endif
		t_stack = 0;
		if (frame.body->type &&
		    !strcasecmp(frame.body->type, "text/plain")) {
		    Str tmp;
		    fprintf(f1, "<pre>\n");
		    while ((tmp = StrmyUFgets(&f2))->length) {
			tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
					  doc_charset);
			fprintf(f1, "%s", html_quote(tmp->ptr));
		    }
		    fprintf(f1, "</pre>\n");
		    UFclose(&f2);
		    break;
		}
		do {
		    int is_tag = FALSE;
		    char *q;
		    struct parsed_tag *tag;

		    do {
			if (*p == '\0') {
			    Str tmp = StrmyUFgets(&f2);
			    if (tmp->length == 0)
				break;
			    tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
					      doc_charset);
			    p = tmp->ptr;
			}
			read_token(tok, &p, &status, 1, status != R_ST_NORMAL);
		    } while (status != R_ST_NORMAL);

		    if (tok->length == 0)
			continue;

		    if (tok->ptr[0] == '<') {
			if (tok->ptr[1] &&
			    REALLY_THE_BEGINNING_OF_A_TAG(tok->ptr))
			    is_tag = TRUE;
			else if (!(pre_mode & (RB_PLAIN | RB_INTXTA |
					       RB_SCRIPT | RB_STYLE))) {
			    p = Strnew_m_charp(tok->ptr + 1, p, NULL)->ptr;
			    tok = Strnew_charp("&lt;");
			}
		    }
		    if (is_tag) {
			if (pre_mode & (RB_PLAIN | RB_INTXTA | RB_SCRIPT |
					RB_STYLE)) {
			    q = tok->ptr;
			    if ((tag = parse_tag(&q, FALSE)) &&
				tag->tagid == end_tag) {
				if (pre_mode & RB_PLAIN) {
				    fputs("</PRE_PLAIN>", f1);
				    pre_mode = 0;
				    end_tag = 0;
				    goto token_end;
				}
				pre_mode = 0;
				end_tag = 0;
				goto proc_normal;
			    }
			    if (strncmp(tok->ptr, "<!--", 4) &&
				(q = strchr(tok->ptr + 1, '<'))) {
				tok = Strnew_charp_n(tok->ptr, q - tok->ptr);
				p = Strnew_m_charp(q, p, NULL)->ptr;
				status = R_ST_NORMAL;
			    }
			    is_tag = FALSE;
			}
			else if (pre_mode & RB_INSELECT) {
			    q = tok->ptr;
			    if ((tag = parse_tag(&q, FALSE))) {
				if ((tag->tagid == end_tag) ||
				    (tag->tagid == HTML_N_FORM)) {
				    if (tag->tagid == HTML_N_FORM)
					fputs("</SELECT>", f1);
				    pre_mode = 0;
				    end_tag = 0;
				    goto proc_normal;
				}
				if (t_stack) {
				    switch (tag->tagid) {
				    case HTML_TABLE:
				    case HTML_N_TABLE:
				      CASE_TABLE_TAG:
					fputs("</SELECT>", f1);
					pre_mode = 0;
					end_tag = 0;
					goto proc_normal;
				    }
				}
			    }
			}
		    }

		  proc_normal:
		    if (is_tag) {
			char *q = tok->ptr;
			int j, a_target = 0;
			ParsedURL url;

			if (!(tag = parse_tag(&q, FALSE)))
			    goto token_end;

			switch (tag->tagid) {
			case HTML_TITLE:
			    fputs("<!-- title:", f1);
			    goto token_end;
			case HTML_N_TITLE:
			    fputs("-->", f1);
			    goto token_end;
			case HTML_BASE:
			    /* "BASE" is prohibit tag */
			    if (parsedtag_get_value(tag, ATTR_HREF, &q)) {
				q = url_encode(remove_space(q), NULL, charset);
				parseURL(q, &base, NULL);
			    }
			    if (parsedtag_get_value(tag, ATTR_TARGET, &q)) {
				if (!strcasecmp(q, "_self"))
				    d_target = s_target;
				else if (!strcasecmp(q, "_parent"))
				    d_target = p_target;
				else
				    d_target = url_quote_conv(q, charset);
			    }
			    Strshrinkfirst(tok, 1);
			    Strshrink(tok, 1);
			    fprintf(f1, "<!-- %s -->", html_quote(tok->ptr));
			    goto token_end;
			case HTML_META:
			    if (parsedtag_get_value(tag, ATTR_HTTP_EQUIV, &q)
				&& !strcasecmp(q, "refresh")) {
				if (parsedtag_get_value(tag, ATTR_CONTENT, &q)
				    ) {
				    Str s_tmp = NULL;
				    int refresh_interval =
					getMetaRefreshParam(q, &s_tmp);
				    if (s_tmp) {
					q = html_quote(s_tmp->ptr);
					fprintf(f1,
						"Refresh (%d sec) <a href=\"%s\">%s</a>\n",
						refresh_interval, q, q);
				    }
				}
			    }
#ifdef USE_M17N
			    if (UseContentCharset &&
				parsedtag_get_value(tag, ATTR_HTTP_EQUIV, &q)
				&& !strcasecmp(q, "Content-Type")
				&& parsedtag_get_value(tag, ATTR_CONTENT, &q)
				&& (q = strcasestr(q, "charset")) != NULL) {
				q += 7;
				SKIP_BLANKS(q);
				if (*q == '=') {
				    wc_ces c;
				    q++;
				    SKIP_BLANKS(q);
				    if ((c = wc_guess_charset(q, 0)) != 0) {
					doc_charset = c;
					charset = WC_CES_US_ASCII;
				    }
				}
			    }
#endif
			    /* fall thru, "META" is prohibit tag */
			case HTML_HEAD:
			case HTML_N_HEAD:
			case HTML_BODY:
			case HTML_N_BODY:
			case HTML_DOCTYPE:
			    /* prohibit_tags */
			    Strshrinkfirst(tok, 1);
			    Strshrink(tok, 1);
			    fprintf(f1, "<!-- %s -->", html_quote(tok->ptr));
			    goto token_end;
			case HTML_TABLE:
			    t_stack++;
			    break;
			case HTML_N_TABLE:
			    t_stack--;
			    if (t_stack < 0) {
				t_stack = 0;
				Strshrinkfirst(tok, 1);
				Strshrink(tok, 1);
				fprintf(f1,
					"<!-- table stack underflow: %s -->",
					html_quote(tok->ptr));
				goto token_end;
			    }
			    break;
			  CASE_TABLE_TAG:
			    /* table_tags MUST be in table stack */
			    if (!t_stack) {
				Strshrinkfirst(tok, 1);
				Strshrink(tok, 1);
				fprintf(f1, "<!-- %s -->",
					html_quote(tok->ptr));
				goto token_end;

			    }
			    break;
			case HTML_SELECT:
			    pre_mode = RB_INSELECT;
			    end_tag = HTML_N_SELECT;
			    break;
			case HTML_TEXTAREA:
			    pre_mode = RB_INTXTA;
			    end_tag = HTML_N_TEXTAREA;
			    break;
			case HTML_SCRIPT:
			    pre_mode = RB_SCRIPT;
			    end_tag = HTML_N_SCRIPT;
			    break;
			case HTML_STYLE:
			    pre_mode = RB_STYLE;
			    end_tag = HTML_N_STYLE;
			    break;
			case HTML_LISTING:
			    pre_mode = RB_PLAIN;
			    end_tag = HTML_N_LISTING;
			    fputs("<PRE_PLAIN>", f1);
			    goto token_end;
			case HTML_XMP:
			    pre_mode = RB_PLAIN;
			    end_tag = HTML_N_XMP;
			    fputs("<PRE_PLAIN>", f1);
			    goto token_end;
			case HTML_PLAINTEXT:
			    pre_mode = RB_PLAIN;
			    end_tag = MAX_HTMLTAG;
			    fputs("<PRE_PLAIN>", f1);
			    goto token_end;
			default:
			    break;
			}
			for (j = 0; j < TagMAP[tag->tagid].max_attribute; j++) {
			    switch (tag->attrid[j]) {
			    case ATTR_SRC:
			    case ATTR_HREF:
			    case ATTR_ACTION:
				if (!tag->value[j])
				    break;
				tag->value[j] =
				    url_encode(remove_space(tag->value[j]),
					       &base, charset);
				tag->need_reconstruct = TRUE;
				parseURL2(tag->value[j], &url, &base);
				if (url.scheme == SCM_UNKNOWN ||
#ifndef USE_W3MMAILER
				    url.scheme == SCM_MAILTO ||
#endif
				    url.scheme == SCM_MISSING)
				    break;
				a_target |= 1;
				tag->value[j] = parsedURL2Str(&url)->ptr;
				parsedtag_set_value(tag,
						    ATTR_REFERER,
						    parsedURL2Str(&base)->ptr);
#ifdef USE_M17N
				if (tag->attrid[j] == ATTR_ACTION &&
				    charset != WC_CES_US_ASCII)
				    parsedtag_set_value(tag,
							ATTR_CHARSET,
							wc_ces_to_charset
							(charset));
#endif
				break;
			    case ATTR_TARGET:
				if (!tag->value[j])
				    break;
				a_target |= 2;
				if (!strcasecmp(tag->value[j], "_self")) {
				    parsedtag_set_value(tag,
							ATTR_TARGET, s_target);
				}
				else if (!strcasecmp(tag->value[j], "_parent")) {
				    parsedtag_set_value(tag,
							ATTR_TARGET, p_target);
				}
				break;
			    case ATTR_NAME:
			    case ATTR_ID:
				if (!tag->value[j])
				    break;
				parsedtag_set_value(tag,
						    ATTR_FRAMENAME, s_target);
				break;
			    }
			}
			if (a_target == 1) {
			    /* there is HREF attribute and no TARGET
			     * attribute */
			    parsedtag_set_value(tag, ATTR_TARGET, d_target);
			}
			if (parsedtag_need_reconstruct(tag))
			    tok = parsedtag2str(tag);
			Strfputs(tok, f1);
		    }
		    else {
			if (pre_mode & RB_PLAIN)
			    fprintf(f1, "%s", html_quote(tok->ptr));
			else if (pre_mode & RB_INTXTA)
			    fprintf(f1, "%s",
				    html_quote(html_unquote(tok->ptr)));
			else
			    Strfputs(tok, f1);
		    }
		  token_end:
		    Strclear(tok);
		} while (*p != '\0' || !iseos(f2.stream));
		if (pre_mode & RB_PLAIN)
		    fputs("</PRE_PLAIN>\n", f1);
		else if (pre_mode & RB_INTXTA)
		    fputs("</TEXTAREA></FORM>\n", f1);
		else if (pre_mode & RB_INSELECT)
		    fputs("</SELECT></FORM>\n", f1);
		else if (pre_mode & (RB_SCRIPT | RB_STYLE)) {
		    if (status != R_ST_NORMAL)
			fputs(correct_irrtag(status)->ptr, f1);
		    if (pre_mode & RB_SCRIPT)
			fputs("</SCRIPT>\n", f1);
		    else if (pre_mode & RB_STYLE)
			fputs("</STYLE>\n", f1);
		}
		while (t_stack--)
		    fputs("</TABLE>\n", f1);
		UFclose(&f2);
		break;
	    case F_FRAMESET:
	      render_frameset:
		if (!frame.set->name && f->name) {
		    frame.set->name = Sprintf("%s_%d", f->name, i)->ptr;
		}
		createFrameFile(frame.set, f1, current, level + 1,
				force_reload);
		break;
	    }
	    fputs("</td>\n", f1);
	}
	fputs("</tr>\n", f1);
    }

    fputs("</table>\n", f1);
    if (level == 0) {
	fputs("</body></html>\n", f1);
	TRAP_OFF;
    }
    return 0;
}
Example #15
0
int main(int argc, void* argv[]){
    int i=0,res=0,x,y;
    char str_path[100]={0};
    SDL_Rect rect;
    SDL_AudioSpec   wanted_spec, spec;
    SDL_Event      event;
 
    /*打开文件*/
    strcpy(str_path,argv[1]);
    res = init_stream(str_path);
    if(res <0 ){
        fprintf(stderr, "open file fail code[%d]", res);
        return 0;
    }
    LOGE("open file ok!!");
 
    /*初始化视频*/
    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
        fprintf(stderr, "Could not  initialize SDL - %s", SDL_GetError());
        exit(1);
    }
    LOGE("init video ok!!");
    Screen = SDL_SetVideoMode(VideoWidth,VideoHeight, BITS_PER_PIXEL, SDL_HWSURFACE);
    if(!Screen) { 
        fprintf(stderr, "SDL: could not set video mode - exiting");
        exit(1);
    }
    LOGE("Screen ok BitsPerPixel[%d], BytesPerPixel[%d], pitch[%d] x[%d]y[%d]w[%d]h[%d]!!! ",
            Screen->format->BitsPerPixel, Screen->format->BytesPerPixel, Screen->pitch,
            Screen->clip_rect.x, Screen->clip_rect.y, Screen->clip_rect.w, Screen->clip_rect.h);
    LOGE("video is ready !!\n");
 
    /*初始化音频,音频需要流的信息*/
    wanted_spec.freq = ff_play_getaudio_samplerate();
    wanted_spec.format = AUDIO_S16LSB;
    wanted_spec.channels = ff_play_getaudio_channels();
    wanted_spec.silence = 0;
    wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE;
    wanted_spec.callback = my_play_sdl_audio_callback2;
    wanted_spec.userdata = NULL;
    LOGE("samplerate[%d],channle[%d]", wanted_spec.freq,wanted_spec.channels);
    if (SDL_OpenAudio(&wanted_spec, &spec) < 0) {
                fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
                return -1;
    }
    LOGE("ready to play!!");
 
    /*let's play*/
    SDL_PauseAudio(0);
    res = pthread_create(&Task_Video, NULL, my_play_video_thread, NULL);
    while(1){
        SDL_PollEvent(&event);
        switch(event.type) {
            case SDL_QUIT:
                Isrun_Video = STOP;
                while(Isrun_Video != EXIT);
                SDL_CloseAudio();
                ff_play_FreeAll();
                SDL_Quit();
                return 0;
            case SDL_KEYDOWN:
                switch (event.key.keysym.sym) {
                case SDLK_RIGHT:
                    ff_play_jump(1);
//                  LOGE("SDLK_RIGHT DOWN!!!!!");
                    break;
                case SDLK_LEFT:
                    ff_play_jump(-1);
//                  LOGE("SDLK_LEFT DOWN!!!!!");
                    break;
                case SDLK_UP:
//                  LOGE("SDLK_UP DOWN!!!!!");
                    break;
                case SDLK_DOWN:
//                  LOGE("SDLK_DOWN DOWN!!!!!");
                    break;
                case SDLK_SPACE:
                    my_play_pause();
 
                }break;
            default:
                break;
        }
    }
    return 0;
}
Example #16
0
/* returns error */
int APP_CC
xrdp_tcp_init(struct xrdp_tcp* self, struct stream* s)
{
    init_stream(s, 8192);
    return 0;
}
Example #17
0
/* response to client asking for clipboard contents that is file list */
int 
clipboard_send_data_response_for_file(char *data, int data_size)
{
    struct stream *s;
    int size;
    int rv;
    int bytes_after_header;
    int cItems;
    int flags;
    int index;
    tui32 ui32;
    char fn[256];
    struct cb_file_info *cfi;

    LLOGLN(10, ("clipboard_send_data_response_for_file: data_size %d",
                data_size));
    //g_hexdump(data, data_size);
    if (g_files_list == 0)
    {
        g_files_list = list_create();
        g_files_list->auto_free = 1;
    }
    list_clear(g_files_list);
    clipboard_get_files(data, data_size);
    cItems = g_files_list->count;
    bytes_after_header = cItems * 592 + 4;
    make_stream(s);
    init_stream(s, 64 + bytes_after_header);
    out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */
    out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
    out_uint32_le(s, bytes_after_header);
    out_uint32_le(s, cItems);
    for (index = 0; index < cItems; index++)
    {
        cfi = (struct cb_file_info *)list_get_item(g_files_list, index);
        flags = CB_FD_ATTRIBUTES | CB_FD_FILESIZE | CB_FD_WRITESTIME | CB_FD_PROGRESSUI;
        out_uint32_le(s, flags);
        out_uint8s(s, 32); /* reserved1 */
        flags = cfi->flags;
        out_uint32_le(s, flags);
        out_uint8s(s, 16); /* reserved2 */
        /* file time */
        /* 100-nanoseconds intervals since 1 January 1601 */
        //out_uint32_le(s, 0x2c305d08); /* 25 October 2009, 21:17 */
        //out_uint32_le(s, 0x01ca55f3);
        ui32 = cfi->time & 0xffffffff;
        out_uint32_le(s, ui32);
        ui32 = cfi->time >> 32;
        out_uint32_le(s, ui32);
        /* file size */
        out_uint32_le(s, 0);
        out_uint32_le(s, cfi->size);
        g_snprintf(fn, 255, "%s", cfi->filename);
        clipboard_out_unicode(s, fn, 256);
        out_uint8s(s, 8); /* pad */
    }
    out_uint32_le(s, 0);
    s_mark_end(s);
    size = (int)(s->end - s->data);
    rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
    free_stream(s);
    return rv;
}
Example #18
0
/*
 * called when WTSVirtualChannelWrite() is invoked in xrdpapi.c
 *
 ******************************************************************************/
int DEFAULT_CC
my_api_trans_data_in(struct trans *trans)
{
    struct stream        *s;
    int                   bytes_read;
    int                   i32;
    struct xrdp_api_data *ad;

    //g_writeln("my_api_trans_data_in:");

    LOG(10, ("my_api_trans_data_in:"));

    if (trans == 0)
    {
        return 0;
    }

    if (trans != g_api_con_trans)
    {
        return 1;
    }

    LOGM((LOG_LEVEL_DEBUG, "my_api_trans_data_in:"));

    s = trans_get_in_s(trans);
    bytes_read = g_tcp_recv(trans->sck, s->data, 16, 0);
    if (bytes_read == 16)
    {
        if (g_memcmp(s->data, g_xrdpapi_magic, 12) == 0)
        {
            in_uint8s(s, 12);
            in_uint32_le(s, bytes_read);
            init_stream(s, bytes_read);
            trans_force_read(trans, bytes_read);
        }
        else if (g_tcp_select(trans->sck, 0) & 1)
        {
            i32 = bytes_read;
            bytes_read = g_tcp_recv(trans->sck, s->data + bytes_read,
                                    8192 * 4 - bytes_read, 0);
            if (bytes_read > 0)
            {
                bytes_read += i32;
            }
        }
    }

    //g_writeln("bytes_read %d", bytes_read);

    if (bytes_read > 0)
    {
        LOG(10, ("my_api_trans_data_in: got data %d", bytes_read));
        ad = (struct xrdp_api_data *) trans->callback_data;

        if (ad->dvc_chan_id < 0)
        {
            /* writing data to a static virtual channel */
            if (send_channel_data(ad->chan_id, s->data, bytes_read) != 0)
            {
                LOG(0, ("my_api_trans_data_in: send_channel_data failed"));
            }
        }
        else
        {
            /* writing data to a dynamic virtual channel */
            drdynvc_write_data(ad->dvc_chan_id, s->data, bytes_read);
        }
    }
    else
    {
        ad = (struct xrdp_api_data *) (trans->callback_data);
        if ((ad != NULL) && (ad->dvc_chan_id > 0))
        {
            /* WTSVirtualChannelClose() was invoked, or connection dropped */
            LOG(10, ("my_api_trans_data_in: g_tcp_recv failed or disconnected for DVC"));
            ad->transp = NULL;
            ad->is_connected = 0;
            remove_struct_with_chan_id(ad->dvc_chan_id);
        }
        else
        {
            LOG(10, ("my_api_trans_data_in: g_tcp_recv failed or disconnected for SVC"));
        }
        return 1;
    }

    return 0;
}
Example #19
0
void cliprdr_process_message(struct stream* packet, int length, int total_length) {
	log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
			"New message for clipchannel");
	int msg_type;
	int msg_flags;
	int msg_size;

	struct stream* s;

	if(length != total_length)
	{
		log_message(l_config, LOG_LEVEL_DEBUG_PLUS, "vchannel_cliprdr[cliprdr_process_message]: "
			"Packet is fragmented");
		if(is_fragmented_packet == 0)
		{
			log_message(l_config, LOG_LEVEL_DEBUG_PLUS, "vchannel_cliprdr[cliprdr_process_message]: "
				"Packet is fragmented : first part");
			is_fragmented_packet = 1;
			fragment_size = length;
			make_stream(splitted_packet);
			init_stream(splitted_packet, total_length);
			g_memcpy(splitted_packet->p, packet->p, length);
			return;
		}
		else
		{
			g_memcpy(splitted_packet->p+fragment_size, packet->p, length);
			fragment_size += length;
			if (fragment_size == total_length)
			{
				log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_process_message]: "
					"Packet is fragmented : last part");
				s = splitted_packet;
			}
			else
			{
				log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_process_message]: "
					"Packet is fragmented : next part");
				return;
			}
		}
	}
	else
	{
		s = packet;
	}

	in_uint16_le(s, msg_type);
	log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
			"Message type : %04x", msg_type);
	in_uint16_le(s, msg_flags);
	log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
			"Message flags : %04x", msg_flags);
	in_uint32_le(s, msg_size);
	log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
			"Message size : %i", msg_size);

	switch (msg_type)
	{
	case CB_FORMAT_LIST :
		log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
				"Client format list announce");
		cliprdr_process_format_list(s, msg_flags, msg_size);
		//cliprdr_send_format_list();
		break;

	case CB_FORMAT_DATA_RESPONSE :
		log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
				"Client data request response");
		cliprdr_process_data_request_response(s, msg_flags, msg_size);
		pthread_cond_signal(&reply_cond);

		break;
	case CB_FORMAT_LIST_RESPONSE :
		log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
				"Client format list response");
		break;

	case CB_FORMAT_DATA_REQUEST :
		log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
				"Client data request");
		cliprdr_process_data_request(s, msg_flags, msg_size);
		break;

	default:
		log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[process_message]: "
				"Unknow message type : %i", msg_type);

	}
	if(is_fragmented_packet == 1)
	{
		is_fragmented_packet = 0;
		fragment_size = 0;
		free_stream(s);
	}
}
Example #20
0
/* return error */
static int APP_CC
l_file_read_section(int fd, int max_file_size, const char* section,
                    struct list* names, struct list* values)
{
  struct stream* s;
  char text[512];
  char name[512];
  char value[512];
  char c;
  int in_it;
  int in_it_index;
  int len;
  int index;
  int file_size;

  file_size = 32 * 1024; /* 32 K file size limit */
  g_file_seek(fd, 0);
  in_it_index = 0;
  in_it = 0;
  g_memset(text, 0, 512);
  list_clear(names);
  list_clear(values);
  make_stream(s);
  init_stream(s, file_size);
  len = g_file_read(fd, s->data, file_size);
  if (len > 0)
  {
    s->end = s->p + len;
    for (index = 0; index < len; index++)
    {
      in_uint8(s, c);
      if (c == '[')
      {
        in_it = 1;
      }
      else if (c == ']')
      {
        if (g_strcasecmp(section, text) == 0)
        {
          file_read_line(s, text);
          while (file_read_line(s, text) == 0)
          {
            if (g_strlen(text) > 0)
            {
              file_split_name_value(text, name, value);
              list_add_item(names, (tbus)g_strdup(name));
              list_add_item(values, (tbus)g_strdup(value));
            }
          }
          free_stream(s);
          return 0;
        }
        in_it = 0;
        in_it_index = 0;
        g_memset(text, 0, 512);
      }
      else if (in_it)
      {
        text[in_it_index] = c;
        in_it_index++;
      }
    }
  }
  free_stream(s);
  return 1;
}
Example #21
0
int DEFAULT_CC
main(int argc, char** argv)
{
  int sck;
  int code;
  int i;
  int size;
  int version;
  int width;
  int height;
  int bpp;
  int keylayout;
  int display;
  struct stream* in_s;
  struct stream* out_s;
  char* username;
  char* password;
  char* exec;
  long data;

  if (0 != config_read(&g_cfg))
  {
    g_printf("sesrun: error reading config. quitting.\n");
    return 1;
  }

  g_pid = g_getpid();
  if (argc == 1)
  {
    g_printf("xrdp session starter v0.2\n");
    g_printf("\nusage:\n");
    g_printf("sesrun <server> <username> <password> <exec> <width> <height> <bpp> <keylayout>\n");
  }
  else if (argc == 9)
  {
    username = argv[2];
    password = argv[3];
    exec = argv[4];
    width = g_atoi(argv[5]);
    height = g_atoi(argv[6]);
    bpp = g_atoi(argv[7]);
    keylayout = g_atoi(argv[8]);
    make_stream(in_s);
    init_stream(in_s, 8192);
    make_stream(out_s);
    init_stream(out_s, 8192);
    sck = g_tcp_socket();
    if (g_tcp_connect(sck, argv[1], "3350") == 0)
    {
      s_push_layer(out_s, channel_hdr, 8);
      out_uint16_be(out_s, 20); /* code */
      i = g_strlen(username);
      out_uint16_be(out_s, i);
      out_uint8a(out_s, username, i);
      i = g_strlen(password);
      out_uint16_be(out_s, i);
      out_uint8a(out_s, password, i);
      i = g_strlen(exec);
      out_uint16_be(out_s, i);
      out_uint8a(out_s, exec, i);
      out_uint16_be(out_s, width);
      out_uint16_be(out_s, height);
      out_uint16_be(out_s, bpp);
      out_uint16_be(out_s, keylayout);
      s_mark_end(out_s);
      s_pop_layer(out_s, channel_hdr);
      out_uint32_be(out_s, 0); /* version */
      out_uint32_be(out_s, out_s->end - out_s->data); /* size */
      tcp_force_send(sck, out_s->data, out_s->end - out_s->data);
      if (tcp_force_recv(sck, in_s->data, 8) == 0)
      {
        in_uint32_be(in_s, version);
        in_uint32_be(in_s, size);
        init_stream(in_s, 8192);
        if (tcp_force_recv(sck, in_s->data, size - 8) == 0)
        {
          if (version == 0)
          {
            in_uint16_be(in_s, code);
            if (code == 3)
            {
              in_uint16_be(in_s, data);
              in_uint16_be(in_s, display);
              g_printf("ok %d display %d\n", data, display);
            }
          }
        }
      }
    }
    else
    {
      g_printf("connect error\n");
    }
    g_tcp_close(sck);
    free_stream(in_s);
    free_stream(out_s);
  }
  return 0;
}
Example #22
0
int main(int argc, char **argv)
{
	int c;
	const char *optstring = "vhanof:?";
	int linenumbers = 0;
	bool add_vfcodes = FALSE;
	char *vfc_filnam = NULL;

	while (1) {
#ifdef __GLIBC__
		int option_index = 0;
		static struct option long_options[] = {
			{"verbose", 0, 0, 'v'},
			{"help", 0, 0, 'h'},
			{"all", 0, 0, 'a'},
			{"linenumbers", 0, 0, 'n'},
			{"offsets", 0, 0, 'o'},
			{"fcodes", 1, 0, 'f'},
			{0, 0, 0, 0}
		};

		c = getopt_long(argc, argv, optstring,
				long_options, &option_index);
#else
		c = getopt(argc, argv, optstring);
#endif
		if (c == -1)
			break;

		switch (c) {
		case 'v':
			verbose = TRUE;
			break;
		case 'a':
			decode_all = TRUE;
			break;
		case 'n':
			linenumbers |= 1;
			show_linenumbers = TRUE;
			break;
		case 'o':
			linenumbers |= 2;
			show_linenumbers = TRUE;
			show_offsets = TRUE;
			break;
		case 'f':
			add_vfcodes = TRUE;
			vfc_filnam = optarg;
			break;
		case 'h':
		case '?':
			print_copyright(TRUE);
			usage(argv[0]);
			return 0;
		default:
			print_copyright(TRUE);
			printf("%s: unknown option.\n", argv[0]);
			usage(argv[0]);
			return 1;
		}
	}

	if (verbose)
		print_copyright(FALSE);

	if (linenumbers > 2)
		printremark
		    ("Line numbers will be disabled in favour of offsets.\n");

	if (optind >= argc) {
		print_copyright(TRUE);
		printf("%s: filename missing.\n", argv[0]);
		usage(argv[0]);
		return 1;
	}

	init_dictionary();

	if (add_vfcodes) {
		if (add_fcodes_from_list(vfc_filnam)) {
			freeze_dictionary();
		}
	}

	while (optind < argc) {

		if (init_stream(argv[optind])) {
			printf("Could not open file \"%s\".\n", argv[optind]);
			optind++;
			continue;
		}
		detokenize();
		close_stream();

		optind++;
		reset_dictionary();
	}

	printf("\n");

	return 0;
}
Example #23
0
int main(void) {
    printf("01\t--------------------------------------------\n");
    printf("02\t1 successor, 2 non threaded consumers\n");
    printf("03\tConsumer 2 disconnects, consumer 1 continues\n");
    printf("04\tgetting token, consumer 2 reconnects\n");
    printf("03\t--------------------------------------------\n");

    int con_delay = 0;
    int suc_delay = 0;

    pthread_t s1;

    stream_t suc1;
    stream_t cons1;
    stream_t cons2;

    init_stream(&suc1, &suc_delay);
    init_stream(&cons1, NULL);
    init_stream(&cons2, NULL);

    stream_connect(&cons1, &suc1);
    stream_connect(&cons2, &suc1);

    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    pthread_create(&s1, &attr, suc, (void*)&suc1);

    printf("Both consumers connected\n");
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    printf("Disconnecting consumer 2\n");
    sleep(con_delay); stream_disconnect(&cons2, &suc1);
    sleep(con_delay); printf("  Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("  Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("  Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("  Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("  Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("  Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("  Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("  Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    printf("Reconnecting consumer 2\n");
    sleep(con_delay); stream_connect(&cons2, &suc1);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    printf("Disconnecting consumer 1\n");
    sleep(con_delay); stream_disconnect(&cons1, &suc1);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    sleep(con_delay); printf("Consumer 2 got: %d\n", *(int*)consume_single((void*)&cons2)); //print_buffers(&cons2);
    printf("Reconnecting consumer 1\n");
    sleep(con_delay); stream_connect(&cons1, &suc1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);
    sleep(con_delay); printf("Consumer 1 got: %d\n", *(int*)consume_single((void*)&cons1)); //print_buffers(&cons1);

    sleep(con_delay); printf("done\n");

    pthread_cancel(s1);

    kill_stream(&suc1);

    return 0;
}
Example #24
0
int
main (int argc, char *argv[])
{
	int type;
	void *data = g_malloc0 (MAX_ENTRY_SIZE);
	int num_args = argc - 1;
	int num_nums = 0;
	int num_vtables = 0;
	int i;
	long nums [num_args];
	long vtables [num_args];
	gboolean dump_all = FALSE;
	gboolean pause_times = FALSE;
	gboolean pause_times_stopped = FALSE;
	gboolean pause_times_concurrent = FALSE;
	gboolean pause_times_finish = FALSE;
	gboolean color_output = FALSE;
	long long pause_times_ts = 0;
	const char *input_path = NULL;
	int input_file;
	EntryStream stream;
	unsigned long long entry_index;
	unsigned long long first_entry_to_consider = 0;

	for (i = 0; i < num_args; ++i) {
		char *arg = argv [i + 1];
		char *next_arg = argv [i + 2];
		if (!strcmp (arg, "--all")) {
			dump_all = TRUE;
		} else if (!strcmp (arg, "--pause-times")) {
			pause_times = TRUE;
		} else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
			vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
			++i;
		} else if (!strcmp (arg, "-s") || !strcmp (arg, "--start-at")) {
			first_entry_to_consider = strtoull (next_arg, NULL, 10);
			++i;
		} else if (!strcmp (arg, "-c") || !strcmp (arg, "--color")) {
			color_output = TRUE;
		} else if (!strcmp (arg, "-i") || !strcmp (arg, "--input")) {
			input_path = next_arg;
			++i;
		} else if (!strcmp (arg, "--help")) {
			printf (
				"\n"
				"Usage:\n"
				"\n"
				"\tsgen-grep-binprot [options] [pointer...]\n"
				"\n"
				"Examples:\n"
				"\n"
				"\tsgen-grep-binprot --all </tmp/binprot\n"
				"\tsgen-grep-binprot --input /tmp/binprot --color 0xdeadbeef\n"
				"\n"
				"Options:\n"
				"\n"
				"\t--all                    Print all entries.\n"
				"\t--color, -c              Highlight matches in color.\n"
				"\t--help                   You're looking at it.\n"
				"\t--input FILE, -i FILE    Read input from FILE instead of standard input.\n"
				"\t--pause-times            Print GC pause times.\n"
				"\t--start-at N, -s N       Begin filtering at the Nth entry.\n"
				"\t--vtable PTR, -v PTR     Search for vtable pointer PTR.\n"
				"\n");
			return 0;
		} else {
			nums [num_nums++] = strtoul (arg, NULL, 16);
		}
	}

	if (dump_all)
		assert (!pause_times);
	if (pause_times)
		assert (!dump_all);

	input_file = input_path ? open (input_path, O_RDONLY) : STDIN_FILENO;
	init_stream (&stream, input_file);
	entry_index = 0;
	while ((type = read_entry (&stream, data)) != SGEN_PROTOCOL_EOF) {
		if (entry_index < first_entry_to_consider)
			goto next_entry;
		if (pause_times) {
			switch (type) {
			case PROTOCOL_ID (binary_protocol_world_stopping): {
				PROTOCOL_STRUCT (binary_protocol_world_stopping) *entry = data;
				assert (!pause_times_stopped);
				pause_times_concurrent = FALSE;
				pause_times_finish = FALSE;
				pause_times_ts = entry->timestamp;
				pause_times_stopped = TRUE;
				break;
			}
			case PROTOCOL_ID (binary_protocol_concurrent_finish):
				pause_times_finish = TRUE;
			case PROTOCOL_ID (binary_protocol_concurrent_start):
			case PROTOCOL_ID (binary_protocol_concurrent_update):
				pause_times_concurrent = TRUE;
				break;
			case PROTOCOL_ID (binary_protocol_world_restarted): {
				PROTOCOL_STRUCT (binary_protocol_world_restarted) *entry = data;
				assert (pause_times_stopped);
				printf ("pause-time %d %d %d %lld %lld\n",
						entry->generation,
						pause_times_concurrent,
						pause_times_finish,
						entry->timestamp - pause_times_ts,
						pause_times_ts);
				pause_times_stopped = FALSE;
				break;
			}
			}
		} else {
			int match_indices [num_nums + 1];
			gboolean match = is_always_match (type);
			match_indices [num_nums] = num_nums == 0 ? match_index (NULL, type, data) : BINARY_PROTOCOL_NO_MATCH;
			match = match_indices [num_nums] != BINARY_PROTOCOL_NO_MATCH;
			for (i = 0; i < num_nums; ++i) {
				match_indices [i] = match_index ((gpointer) nums [i], type, data);
				match = match || match_indices [i] != BINARY_PROTOCOL_NO_MATCH;
			}
			if (!match) {
				for (i = 0; i < num_vtables; ++i) {
					if (is_vtable_match ((gpointer) vtables [i], type, data)) {
						match = TRUE;
						break;
					}
				}
			}
			if (match || dump_all)
				printf ("%12lld ", entry_index);
			if (dump_all)
				printf (match ? "* " : "  ");
			if (match || dump_all)
				print_entry (type, data, num_nums, match_indices, color_output);
		}
	next_entry:
		++entry_index;
	}
	close_stream (&stream);
	if (input_path)
		close (input_file);
	g_free (data);

	return 0;
}
Example #25
0
int EXPORT_CC
libxrdp_send_palette(struct xrdp_session *session, int *palette)
{
    int i = 0;
    int color = 0;
    struct stream *s = (struct stream *)NULL;

    if (session->client_info->bpp > 8)
    {
        return 0;
    }

    DEBUG(("libxrdp_send_palette sending palette"));

    /* clear orders */
    libxrdp_orders_force_send(session);
    make_stream(s);
    init_stream(s, 8192);

    if (session->client_info->use_fast_path & 1) /* fastpath output supported */
    {
        LLOGLN(10, ("libxrdp_send_palette: fastpath"));
        if (xrdp_rdp_init_fastpath((struct xrdp_rdp *)session->rdp, s) != 0)
        {
            free_stream(s);
            return 1;
        }
    }
    else {
        LLOGLN(10, ("libxrdp_send_palette: slowpath"));
        xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s);
    }

    /* TS_UPDATE_PALETTE_DATA */
    out_uint16_le(s, RDP_UPDATE_PALETTE);
    out_uint16_le(s, 0);
    out_uint16_le(s, 256); /* # of colors */
    out_uint16_le(s, 0);

    for (i = 0; i < 256; i++)
    {
        color = palette[i];
        out_uint8(s, color >> 16);
        out_uint8(s, color >> 8);
        out_uint8(s, color);
    }

    s_mark_end(s);
    if (session->client_info->use_fast_path & 1) /* fastpath output supported */
    {
       if (xrdp_rdp_send_fastpath((struct xrdp_rdp *)session->rdp, s,
                                   FASTPATH_UPDATETYPE_PALETTE) != 0)
       {
           free_stream(s);
           return 1;
       }
    }
    else
    {
       xrdp_rdp_send_data((struct xrdp_rdp *)session->rdp, s,
                           RDP_DATA_PDU_UPDATE);
    }
    free_stream(s);

    /* send the orders palette too */
    libxrdp_orders_init(session);
    libxrdp_orders_send_palette(session, palette, 0);
    libxrdp_orders_send(session);
    return 0;
}
int APP_CC
xrdp_bitmap_compress(char* in_data, int width, int height,
                     struct stream* s, int bpp, int byte_limit,
                     int start_line, struct stream* temp_s,
                     int e)
{
  char* line;
  char* last_line;
  char fom_mask[8192]; /* good for up to 64K bitmap */
  int lines_sent;
  int pixel;
  int count;
  int color_count;
  int last_pixel;
  int bicolor_count;
  int bicolor1;
  int bicolor2;
  int bicolor_spin;
  int end;
  int i;
  int out_count;
  int ypixel;
  int last_ypixel;
  int fill_count;
  int mix_count;
  int mix;
  int fom_count;
  int fom_mask_len;
  int temp; /* used in macros */

  init_stream(temp_s, 0);
  fom_mask_len = 0;
  last_line = 0;
  lines_sent = 0;
  end = width + e;
  count = 0;
  color_count = 0;
  last_pixel = 0;
  last_ypixel = 0;
  bicolor_count = 0;
  bicolor1 = 0;
  bicolor2 = 0;
  bicolor_spin = 0;
  fill_count = 0;
  mix_count = 0;
  fom_count = 0;
  if (bpp == 8)
  {
    mix = 0xff;
    out_count = end;
    line = in_data + width * start_line;
    while (start_line >= 0 && out_count < 32768)
    {
      i = (s->p - s->data) + count;
      if (i - color_count >= byte_limit &&
          i - bicolor_count >= byte_limit &&
          i - fill_count >= byte_limit &&
          i - mix_count >= byte_limit &&
          i - fom_count >= byte_limit)
      {
        break;
      }
      out_count += end;
      for (i = 0; i < end; i++)
      {
        /* read next pixel */
        IN_PIXEL8(line, i, 0, width, last_pixel, pixel);
        IN_PIXEL8(last_line, i, 0, width, last_ypixel, ypixel);
        if (!TEST_FILL)
        {
          if (fill_count > 3 &&
              fill_count >= color_count &&
              fill_count >= bicolor_count &&
              fill_count >= mix_count &&
              fill_count >= fom_count)
          {
            count -= fill_count;
            OUT_COPY_COUNT1(count, s, temp_s);
            OUT_FILL_COUNT1(fill_count, s);
            RESET_COUNTS;
          }
          fill_count = 0;
        }
        if (!TEST_MIX)
        {
          if (mix_count > 3 &&
              mix_count >= fill_count &&
              mix_count >= bicolor_count &&
              mix_count >= color_count &&
              mix_count >= fom_count)
          {
            count -= mix_count;
            OUT_COPY_COUNT1(count, s, temp_s);
            OUT_MIX_COUNT1(mix_count, s);
            RESET_COUNTS;
          }
          mix_count = 0;
        }
        if (!TEST_COLOR)
        {
          if (color_count > 3 &&
              color_count >= fill_count &&
              color_count >= bicolor_count &&
              color_count >= mix_count &&
              color_count >= fom_count)
          {
            count -= color_count;
            OUT_COPY_COUNT1(count, s, temp_s);
            OUT_COLOR_COUNT1(color_count, s, last_pixel);
            RESET_COUNTS;
          }
          color_count = 0;
        }
        if (!TEST_BICOLOR)
        {
          if (bicolor_count > 3 &&
              bicolor_count >= fill_count &&
              bicolor_count >= color_count &&
              bicolor_count >= mix_count &&
              bicolor_count >= fom_count)
          {
            if ((bicolor_count % 2) == 0)
            {
              count -= bicolor_count;
              OUT_COPY_COUNT1(count, s, temp_s);
              OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2);
            }
            else
            {
              bicolor_count--;
              count -= bicolor_count;
              OUT_COPY_COUNT1(count, s, temp_s);
              OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor2, bicolor1);
            }
            RESET_COUNTS;
          }
          bicolor_count = 0;
          bicolor1 = last_pixel;
          bicolor2 = pixel;
          bicolor_spin = 0;
        }
        if (!TEST_FOM)
        {
          if (fom_count > 3 &&
              fom_count >= fill_count &&
              fom_count >= color_count &&
              fom_count >= mix_count &&
              fom_count >= bicolor_count)
          {
            count -= fom_count;
            OUT_COPY_COUNT1(count, s, temp_s);
            OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len);
            RESET_COUNTS;
          }
          fom_count = 0;
          fom_mask_len = 0;
        }
        if (TEST_FILL)
        {
          fill_count++;
        }
        if (TEST_MIX)
        {
          mix_count++;
        }
        if (TEST_COLOR)
        {
          color_count++;
        }
        if (TEST_BICOLOR)
        {
          bicolor_spin = !bicolor_spin;
          bicolor_count++;
        }
        if (TEST_FOM)
        {
          if ((fom_count % 8) == 0)
          {
            fom_mask[fom_mask_len] = 0;
            fom_mask_len++;
          }
          if (pixel == (ypixel ^ mix))
          {
            fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8));
          }
          fom_count++;
        }
        out_uint8(temp_s, pixel);
        count++;
        last_pixel = pixel;
        last_ypixel = ypixel;
      }
      /* can't take fix, mix, or fom past first line */
      if (last_line == 0)
      {
        if (fill_count > 3 &&
            fill_count >= color_count &&
            fill_count >= bicolor_count &&
            fill_count >= mix_count &&
            fill_count >= fom_count)
        {
          count -= fill_count;
          OUT_COPY_COUNT1(count, s, temp_s);
          OUT_FILL_COUNT1(fill_count, s);
          RESET_COUNTS;
        }
        fill_count = 0;
        if (mix_count > 3 &&
            mix_count >= fill_count &&
            mix_count >= bicolor_count &&
            mix_count >= color_count &&
            mix_count >= fom_count)
        {
          count -= mix_count;
          OUT_COPY_COUNT1(count, s, temp_s);
          OUT_MIX_COUNT1(mix_count, s);
          RESET_COUNTS;
        }
        mix_count = 0;
        if (fom_count > 3 &&
            fom_count >= fill_count &&
            fom_count >= color_count &&
            fom_count >= mix_count &&
            fom_count >= bicolor_count)
        {
          count -= fom_count;
          OUT_COPY_COUNT1(count, s, temp_s);
          OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len);
          RESET_COUNTS;
        }
        fom_count = 0;
        fom_mask_len = 0;
      }
      last_line = line;
      line = line - width;
      start_line--;
      lines_sent++;
    }
    if (fill_count > 3 &&
        fill_count >= color_count &&
        fill_count >= bicolor_count &&
        fill_count >= mix_count &&
        fill_count >= fom_count)
    {
      count -= fill_count;
      OUT_COPY_COUNT1(count, s, temp_s);
      OUT_FILL_COUNT1(fill_count, s);
    }
    else if (mix_count > 3 &&
             mix_count >= color_count &&
             mix_count >= bicolor_count &&
             mix_count >= fill_count &&
             mix_count >= fom_count)
    {
      count -= mix_count;
      OUT_COPY_COUNT1(count, s, temp_s);
      OUT_MIX_COUNT1(mix_count, s);
    }
    else if (color_count > 3 &&
             color_count >= mix_count &&
             color_count >= bicolor_count &&
             color_count >= fill_count &&
             color_count >= fom_count)
    {
      count -= color_count;
      OUT_COPY_COUNT1(count, s, temp_s);
      OUT_COLOR_COUNT1(color_count, s, last_pixel);
    }
    else if (bicolor_count > 3 &&
             bicolor_count >= mix_count &&
             bicolor_count >= color_count &&
             bicolor_count >= fill_count &&
             bicolor_count >= fom_count)
    {
      if ((bicolor_count % 2) == 0)
      {
        count -= bicolor_count;
        OUT_COPY_COUNT1(count, s, temp_s);
        OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2);
      }
      else
      {
        bicolor_count--;
        count -= bicolor_count;
        OUT_COPY_COUNT1(count, s, temp_s);
        OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor2, bicolor1);
      }
      count -= bicolor_count;
      OUT_COPY_COUNT1(count, s, temp_s);
      OUT_BICOLOR_COUNT1(bicolor_count, s, bicolor1, bicolor2);
    }
    else if (fom_count > 3 &&
             fom_count >= mix_count &&
             fom_count >= color_count &&
             fom_count >= fill_count &&
             fom_count >= bicolor_count)
    {
      count -= fom_count;
      OUT_COPY_COUNT1(count, s, temp_s);
      OUT_FOM_COUNT1(fom_count, s, fom_mask, fom_mask_len);
    }
    else
    {
      OUT_COPY_COUNT1(count, s, temp_s);
    }
  }
  else if (bpp == 16)
  {
    mix = 0xffff;
    out_count = end * 2;
    line = in_data + width * start_line * 2;
    while (start_line >= 0 && out_count < 32768)
    {
      i = (s->p - s->data) + count * 2;
      if (i - (color_count * 2) >= byte_limit &&
          i - (bicolor_count * 2) >= byte_limit &&
          i - (fill_count * 2) >= byte_limit &&
          i - (mix_count * 2) >= byte_limit &&
          i - (fom_count * 2) >= byte_limit)
      {
        break;
      }
      out_count += end * 2;
      for (i = 0; i < end; i++)
      {
        /* read next pixel */
        IN_PIXEL16(line, i, 0, width, last_pixel, pixel);
        IN_PIXEL16(last_line, i, 0, width, last_ypixel, ypixel);
        if (!TEST_FILL)
        {
          if (fill_count > 3 &&
              fill_count >= color_count &&
              fill_count >= bicolor_count &&
              fill_count >= mix_count &&
              fill_count >= fom_count)
          {
            count -= fill_count;
            OUT_COPY_COUNT2(count, s, temp_s);
            OUT_FILL_COUNT2(fill_count, s);
            RESET_COUNTS;
          }
          fill_count = 0;
        }
        if (!TEST_MIX)
        {
          if (mix_count > 3 &&
              mix_count >= fill_count &&
              mix_count >= bicolor_count &&
              mix_count >= color_count &&
              mix_count >= fom_count)
          {
            count -= mix_count;
            OUT_COPY_COUNT2(count, s, temp_s);
            OUT_MIX_COUNT2(mix_count, s);
            RESET_COUNTS;
          }
          mix_count = 0;
        }
        if (!TEST_COLOR)
        {
          if (color_count > 3 &&
              color_count >= fill_count &&
              color_count >= bicolor_count &&
              color_count >= mix_count &&
              color_count >= fom_count)
          {
            count -= color_count;
            OUT_COPY_COUNT2(count, s, temp_s);
            OUT_COLOR_COUNT2(color_count, s, last_pixel);
            RESET_COUNTS;
          }
          color_count = 0;
        }
        if (!TEST_BICOLOR)
        {
          if (bicolor_count > 3 &&
              bicolor_count >= fill_count &&
              bicolor_count >= color_count &&
              bicolor_count >= mix_count &&
              bicolor_count >= fom_count)
          {
            if ((bicolor_count % 2) == 0)
            {
              count -= bicolor_count;
              OUT_COPY_COUNT2(count, s, temp_s);
              OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2);
            }
            else
            {
              bicolor_count--;
              count -= bicolor_count;
              OUT_COPY_COUNT2(count, s, temp_s);
              OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor2, bicolor1);
            }
            RESET_COUNTS;
          }
          bicolor_count = 0;
          bicolor1 = last_pixel;
          bicolor2 = pixel;
          bicolor_spin = 0;
        }
        if (!TEST_FOM)
        {
          if (fom_count > 3 &&
              fom_count >= fill_count &&
              fom_count >= color_count &&
              fom_count >= mix_count &&
              fom_count >= bicolor_count)
          {
            count -= fom_count;
            OUT_COPY_COUNT2(count, s, temp_s);
            OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len);
            RESET_COUNTS;
          }
          fom_count = 0;
          fom_mask_len = 0;
        }
        if (TEST_FILL)
        {
          fill_count++;
        }
        if (TEST_MIX)
        {
          mix_count++;
        }
        if (TEST_COLOR)
        {
          color_count++;
        }
        if (TEST_BICOLOR)
        {
          bicolor_spin = !bicolor_spin;
          bicolor_count++;
        }
        if (TEST_FOM)
        {
          if ((fom_count % 8) == 0)
          {
            fom_mask[fom_mask_len] = 0;
            fom_mask_len++;
          }
          if (pixel == (ypixel ^ mix))
          {
            fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8));
          }
          fom_count++;
        }
        out_uint16_le(temp_s, pixel);
        count++;
        last_pixel = pixel;
        last_ypixel = ypixel;
      }
      /* can't take fix, mix, or fom past first line */
      if (last_line == 0)
      {
        if (fill_count > 3 &&
            fill_count >= color_count &&
            fill_count >= bicolor_count &&
            fill_count >= mix_count &&
            fill_count >= fom_count)
        {
          count -= fill_count;
          OUT_COPY_COUNT2(count, s, temp_s);
          OUT_FILL_COUNT2(fill_count, s);
          RESET_COUNTS;
        }
        fill_count = 0;
        if (mix_count > 3 &&
            mix_count >= fill_count &&
            mix_count >= bicolor_count &&
            mix_count >= color_count &&
            mix_count >= fom_count)
        {
          count -= mix_count;
          OUT_COPY_COUNT2(count, s, temp_s);
          OUT_MIX_COUNT2(mix_count, s);
          RESET_COUNTS;
        }
        mix_count = 0;
        if (fom_count > 3 &&
            fom_count >= fill_count &&
            fom_count >= color_count &&
            fom_count >= mix_count &&
            fom_count >= bicolor_count)
        {
          count -= fom_count;
          OUT_COPY_COUNT2(count, s, temp_s);
          OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len);
          RESET_COUNTS;
        }
        fom_count = 0;
        fom_mask_len = 0;
      }
      last_line = line;
      line = line - width * 2;
      start_line--;
      lines_sent++;
    }
    if (fill_count > 3 &&
        fill_count >= color_count &&
        fill_count >= bicolor_count &&
        fill_count >= mix_count &&
        fill_count >= fom_count)
    {
      count -= fill_count;
      OUT_COPY_COUNT2(count, s, temp_s);
      OUT_FILL_COUNT2(fill_count, s);
    }
    else if (mix_count > 3 &&
             mix_count >= color_count &&
             mix_count >= bicolor_count &&
             mix_count >= fill_count &&
             mix_count >= fom_count)
    {
      count -= mix_count;
      OUT_COPY_COUNT2(count, s, temp_s);
      OUT_MIX_COUNT2(mix_count, s);
    }
    else if (color_count > 3 &&
             color_count >= mix_count &&
             color_count >= bicolor_count &&
             color_count >= fill_count &&
             color_count >= fom_count)
    {
      count -= color_count;
      OUT_COPY_COUNT2(count, s, temp_s);
      OUT_COLOR_COUNT2(color_count, s, last_pixel);
    }
    else if (bicolor_count > 3 &&
             bicolor_count >= mix_count &&
             bicolor_count >= color_count &&
             bicolor_count >= fill_count &&
             bicolor_count >= fom_count)
    {
      if ((bicolor_count % 2) == 0)
      {
        count -= bicolor_count;
        OUT_COPY_COUNT2(count, s, temp_s);
        OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2);
      }
      else
      {
        bicolor_count--;
        count -= bicolor_count;
        OUT_COPY_COUNT2(count, s, temp_s);
        OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor2, bicolor1);
      }
      count -= bicolor_count;
      OUT_COPY_COUNT2(count, s, temp_s);
      OUT_BICOLOR_COUNT2(bicolor_count, s, bicolor1, bicolor2);
    }
    else if (fom_count > 3 &&
             fom_count >= mix_count &&
             fom_count >= color_count &&
             fom_count >= fill_count &&
             fom_count >= bicolor_count)
    {
      count -= fom_count;
      OUT_COPY_COUNT2(count, s, temp_s);
      OUT_FOM_COUNT2(fom_count, s, fom_mask, fom_mask_len);
    }
    else
    {
      OUT_COPY_COUNT2(count, s, temp_s);
    }
  }
  else if (bpp == 24)
  {
    mix = 0xffffff;
    out_count = end * 3;
    line = in_data + width * start_line * 4;
    while (start_line >= 0 && out_count < 32768)
    {
      i = (s->p - s->data) + count * 3;
      if (i - (color_count * 3) >= byte_limit &&
          i - (bicolor_count * 3) >= byte_limit &&
          i - (fill_count * 3) >= byte_limit &&
          i - (mix_count * 3) >= byte_limit &&
          i - (fom_count * 3) >= byte_limit)
      {
        break;
      }
      out_count += end * 3;
      for (i = 0; i < end; i++)
      {
        /* read next pixel */
        IN_PIXEL32(line, i, 0, width, last_pixel, pixel);
        IN_PIXEL32(last_line, i, 0, width, last_ypixel, ypixel);
        if (!TEST_FILL)
        {
          if (fill_count > 3 &&
              fill_count >= color_count &&
              fill_count >= bicolor_count &&
              fill_count >= mix_count &&
              fill_count >= fom_count)
          {
            count -= fill_count;
            OUT_COPY_COUNT3(count, s, temp_s);
            OUT_FILL_COUNT3(fill_count, s);
            RESET_COUNTS;
          }
          fill_count = 0;
        }
        if (!TEST_MIX)
        {
          if (mix_count > 3 &&
              mix_count >= fill_count &&
              mix_count >= bicolor_count &&
              mix_count >= color_count &&
              mix_count >= fom_count)
          {
            count -= mix_count;
            OUT_COPY_COUNT3(count, s, temp_s);
            OUT_MIX_COUNT3(mix_count, s);
            RESET_COUNTS;
          }
          mix_count = 0;
        }
        if (!TEST_COLOR)
        {
          if (color_count > 3 &&
              color_count >= fill_count &&
              color_count >= bicolor_count &&
              color_count >= mix_count &&
              color_count >= fom_count)
          {
            count -= color_count;
            OUT_COPY_COUNT3(count, s, temp_s);
            OUT_COLOR_COUNT3(color_count, s, last_pixel);
            RESET_COUNTS;
          }
          color_count = 0;
        }
        if (!TEST_BICOLOR)
        {
          if (bicolor_count > 3 &&
              bicolor_count >= fill_count &&
              bicolor_count >= color_count &&
              bicolor_count >= mix_count &&
              bicolor_count >= fom_count)
          {
            if ((bicolor_count % 2) == 0)
            {
              count -= bicolor_count;
              OUT_COPY_COUNT3(count, s, temp_s);
              OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2);
            }
            else
            {
              bicolor_count--;
              count -= bicolor_count;
              OUT_COPY_COUNT3(count, s, temp_s);
              OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor2, bicolor1);
            }
            RESET_COUNTS;
          }
          bicolor_count = 0;
          bicolor1 = last_pixel;
          bicolor2 = pixel;
          bicolor_spin = 0;
        }
        if (!TEST_FOM)
        {
          if (fom_count > 3 &&
              fom_count >= fill_count &&
              fom_count >= color_count &&
              fom_count >= mix_count &&
              fom_count >= bicolor_count)
          {
            count -= fom_count;
            OUT_COPY_COUNT3(count, s, temp_s);
            OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len);
            RESET_COUNTS;
          }
          fom_count = 0;
          fom_mask_len = 0;
        }
        if (TEST_FILL)
        {
          fill_count++;
        }
        if (TEST_MIX)
        {
          mix_count++;
        }
        if (TEST_COLOR)
        {
          color_count++;
        }
        if (TEST_BICOLOR)
        {
          bicolor_spin = !bicolor_spin;
          bicolor_count++;
        }
        if (TEST_FOM)
        {
          if ((fom_count % 8) == 0)
          {
            fom_mask[fom_mask_len] = 0;
            fom_mask_len++;
          }
          if (pixel == (ypixel ^ mix))
          {
            fom_mask[fom_mask_len - 1] |= (1 << (fom_count % 8));
          }
          fom_count++;
        }
        out_uint8(temp_s, pixel & 0xff);
        out_uint8(temp_s, (pixel >> 8) & 0xff);
        out_uint8(temp_s, (pixel >> 16) & 0xff);
        count++;
        last_pixel = pixel;
        last_ypixel = ypixel;
      }
      /* can't take fix, mix, or fom past first line */
      if (last_line == 0)
      {
        if (fill_count > 3 &&
            fill_count >= color_count &&
            fill_count >= bicolor_count &&
            fill_count >= mix_count &&
            fill_count >= fom_count)
        {
          count -= fill_count;
          OUT_COPY_COUNT3(count, s, temp_s);
          OUT_FILL_COUNT3(fill_count, s);
          RESET_COUNTS;
        }
        fill_count = 0;
        if (mix_count > 3 &&
            mix_count >= fill_count &&
            mix_count >= bicolor_count &&
            mix_count >= color_count &&
            mix_count >= fom_count)
        {
          count -= mix_count;
          OUT_COPY_COUNT3(count, s, temp_s);
          OUT_MIX_COUNT3(mix_count, s);
          RESET_COUNTS;
        }
        mix_count = 0;
        if (fom_count > 3 &&
            fom_count >= fill_count &&
            fom_count >= color_count &&
            fom_count >= mix_count &&
            fom_count >= bicolor_count)
        {
          count -= fom_count;
          OUT_COPY_COUNT3(count, s, temp_s);
          OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len);
          RESET_COUNTS;
        }
        fom_count = 0;
        fom_mask_len = 0;
      }
      last_line = line;
      line = line - width * 4;
      start_line--;
      lines_sent++;
    }
    if (fill_count > 3 &&
        fill_count >= color_count &&
        fill_count >= bicolor_count &&
        fill_count >= mix_count &&
        fill_count >= fom_count)
    {
      count -= fill_count;
      OUT_COPY_COUNT3(count, s, temp_s);
      OUT_FILL_COUNT3(fill_count, s);
    }
    else if (mix_count > 3 &&
             mix_count >= color_count &&
             mix_count >= bicolor_count &&
             mix_count >= fill_count &&
             mix_count >= fom_count)
    {
      count -= mix_count;
      OUT_COPY_COUNT3(count, s, temp_s);
      OUT_MIX_COUNT3(mix_count, s);
    }
    else if (color_count > 3 &&
             color_count >= mix_count &&
             color_count >= bicolor_count &&
             color_count >= fill_count &&
             color_count >= fom_count)
    {
      count -= color_count;
      OUT_COPY_COUNT3(count, s, temp_s);
      OUT_COLOR_COUNT3(color_count, s, last_pixel);
    }
    else if (bicolor_count > 3 &&
             bicolor_count >= mix_count &&
             bicolor_count >= color_count &&
             bicolor_count >= fill_count &&
             bicolor_count >= fom_count)
    {
      if ((bicolor_count % 2) == 0)
      {
        count -= bicolor_count;
        OUT_COPY_COUNT3(count, s, temp_s);
        OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2);
      }
      else
      {
        bicolor_count--;
        count -= bicolor_count;
        OUT_COPY_COUNT3(count, s, temp_s);
        OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor2, bicolor1);
      }
      count -= bicolor_count;
      OUT_COPY_COUNT3(count, s, temp_s);
      OUT_BICOLOR_COUNT3(bicolor_count, s, bicolor1, bicolor2);
    }
    else if (fom_count > 3 &&
             fom_count >= mix_count &&
             fom_count >= color_count &&
             fom_count >= fill_count &&
             fom_count >= bicolor_count)
    {
      count -= fom_count;
      OUT_COPY_COUNT3(count, s, temp_s);
      OUT_FOM_COUNT3(fom_count, s, fom_mask, fom_mask_len);
    }
    else
    {
      OUT_COPY_COUNT3(count, s, temp_s);
    }
  }
Example #27
0
int EXPORT_CC
libxrdp_send_bitmap(struct xrdp_session *session, int width, int height,
                    int bpp, char *data, int x, int y, int cx, int cy)
{
    int line_bytes = 0;
    int i = 0;
    int j = 0;
    int k;
    int total_lines = 0;
    int lines_sending = 0;
    int Bpp = 0;
    int e = 0;
    int bufsize = 0;
    int total_bufsize = 0;
    int num_updates = 0;
    int line_pad_bytes;
    int server_line_bytes;
    char *p_num_updates = (char *)NULL;
    char *p = (char *)NULL;
    char *q = (char *)NULL;
    struct stream *s = (struct stream *)NULL;
    struct stream *temp_s = (struct stream *)NULL;
    tui32 pixel;

    LLOGLN(10, ("libxrdp_send_bitmap: sending bitmap"));
    Bpp = (bpp + 7) / 8;
    e = (4 - width) & 3;
    switch (bpp)
    {
        case 15:
        case 16:
            server_line_bytes = width * 2;
            break;
        case 24:
        case 32:
            server_line_bytes = width * 4;
            break;
        default: /* 8 bpp */
            server_line_bytes = width;
            break;
    }
    line_bytes = width * Bpp;
    line_pad_bytes = line_bytes + e * Bpp;

    LLOGLN(10, ("libxrdp_send_bitmap: bpp %d Bpp %d line_bytes %d "
           "server_line_bytes %d", bpp, Bpp, line_bytes, server_line_bytes));
    make_stream(s);
    init_stream(s, MAX_BITMAP_BUF_SIZE);

    if (session->client_info->use_bitmap_comp)
    {
        LLOGLN(10, ("libxrdp_send_bitmap: compression"));
        make_stream(temp_s);
        init_stream(temp_s, 65536);
        i = 0;

        if (cy <= height)
        {
            i = cy;
        }

        while (i > 0)
        {
            LLOGLN(10, ("libxrdp_send_bitmap: i %d", i));

            total_bufsize = 0;
            num_updates = 0;
            xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s);
            out_uint16_le(s, RDP_UPDATE_BITMAP);
            p_num_updates = s->p;
            out_uint8s(s, 2); /* num_updates set later */

            do
            {
                if (session->client_info->op1)
                {
                    s_push_layer(s, channel_hdr, 18);
                }
                else
                {
                    s_push_layer(s, channel_hdr, 26);
                }

                p = s->p;

                if (bpp > 24)
                {
                    LLOGLN(10, ("libxrdp_send_bitmap: 32 bpp"));
                    lines_sending = xrdp_bitmap32_compress(data, width, height,
                                                           s, 32,
                                   (MAX_BITMAP_BUF_SIZE - 100) - total_bufsize,
                                                           i - 1, temp_s, e, 0x10);
                    LLOGLN(10, ("libxrdp_send_bitmap: i %d lines_sending %d",
                           i, lines_sending));
                }
                else
                {
                    lines_sending = xrdp_bitmap_compress(data, width, height,
                                                         s, bpp,
                                 (MAX_BITMAP_BUF_SIZE - 100) - total_bufsize,
                                                         i - 1, temp_s, e);
                    LLOGLN(10, ("libxrdp_send_bitmap: i %d lines_sending %d",
                           i, lines_sending));
                }

                if (lines_sending == 0)
                {
                    break;
                }

                num_updates++;
                bufsize = s->p - p;
                total_bufsize += bufsize;
                i = i - lines_sending;
                s_mark_end(s);
                s_pop_layer(s, channel_hdr);
                out_uint16_le(s, x); /* left */
                out_uint16_le(s, y + i); /* top */
                out_uint16_le(s, (x + cx) - 1); /* right */
                out_uint16_le(s, (y + i + lines_sending) - 1); /* bottom */
                out_uint16_le(s, width + e); /* width */
                out_uint16_le(s, lines_sending); /* height */
                out_uint16_le(s, bpp); /* bpp */

                if (session->client_info->op1)
                {
                    out_uint16_le(s, 0x401); /* compress */
                    out_uint16_le(s, bufsize); /* compressed size */
                    j = (width + e) * Bpp;
                    j = j * lines_sending;
                    total_bufsize += 18; /* bytes since pop layer */
                }
                else
                {
                    out_uint16_le(s, 0x1); /* compress */
                    out_uint16_le(s, bufsize + 8);
                    out_uint8s(s, 2); /* pad */
                    out_uint16_le(s, bufsize); /* compressed size */
                    j = (width + e) * Bpp;
                    out_uint16_le(s, j); /* line size */
                    j = j * lines_sending;
                    out_uint16_le(s, j); /* final size */
                    total_bufsize += 26; /* bytes since pop layer */
                }

                LLOGLN(10, ("libxrdp_send_bitmap: decompressed pixels %d "
                       "decompressed bytes %d compressed bytes %d",
                       lines_sending * (width + e),
                       line_pad_bytes * lines_sending, bufsize));

                if (j > MAX_BITMAP_BUF_SIZE)
                {
                    LLOGLN(0, ("libxrdp_send_bitmap: error, decompressed "
                           "size too big: %d bytes", j));
                }

                if (bufsize > MAX_BITMAP_BUF_SIZE)
                {
                    LLOGLN(0, ("libxrdp_send_bitmap: error, compressed size "
                           "too big: %d bytes", bufsize));
                }

                s->p = s->end;
            }
            while (total_bufsize < MAX_BITMAP_BUF_SIZE && i > 0);

            LLOGLN(10, ("libxrdp_send_bitmap: num_updates %d total_bufsize %d",
                   num_updates, total_bufsize));

            p_num_updates[0] = num_updates;
            p_num_updates[1] = num_updates >> 8;
            xrdp_rdp_send_data((struct xrdp_rdp *)session->rdp, s,
                               RDP_DATA_PDU_UPDATE);

            if (total_bufsize > MAX_BITMAP_BUF_SIZE)
            {
                LLOGLN(0, ("libxrdp_send_bitmap: error, total compressed "
                       "size too big: %d bytes", total_bufsize));
            }
        }

        free_stream(temp_s);
    }
Example #28
0
/* server API */
enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION* c, struct SCP_SESSION** s, int skipVchk)
{
  struct SCP_SESSION* session;
  tui32 version;
  tui32 size;
  tui16 cmdset;
  tui16 cmd;
  tui8 sz;
  char buf[257];

  if (!skipVchk)
  {

    if (0 == scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
    {
      in_uint32_be(c->in_s, version);
      if (version != 1)
      {
        log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: version error", __LINE__);
        return SCP_SERVER_STATE_VERSION_ERR;
      }
    }
    else
    {
      log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
      return SCP_SERVER_STATE_NETWORK_ERR;
    }
  }

  in_uint32_be(c->in_s, size);
  if (size < 12)
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: size error", __LINE__);
    return SCP_SERVER_STATE_SIZE_ERR;
  }

  init_stream(c->in_s, c->in_s->size);
  if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, (size-8)))
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  /* reading command set */
  in_uint16_be(c->in_s, cmdset);

  /* if we are starting a management session */
  if (cmdset == SCP_COMMAND_SET_MANAGE)
  {
    log_message(LOG_LEVEL_DEBUG, "[v1s:%d] requested management connection", __LINE__);
    /* should return SCP_SERVER_STATE_START_MANAGE */
    return scp_v1s_mng_accept(c, s);
  }

  /* if we started with resource sharing... */
  if (cmdset == SCP_COMMAND_SET_RSR)
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__);
    return SCP_SERVER_STATE_SEQUENCE_ERR;
  }

  /* reading command */
  in_uint16_be(c->in_s, cmd);
  if (cmd != 1)
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: sequence error", __LINE__);
    return SCP_SERVER_STATE_SEQUENCE_ERR;
  }

  session = scp_session_create();
  if (0 == session)
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error (malloc returned NULL)", __LINE__);
    return SCP_SERVER_STATE_INTERNAL_ERR;
  }
  scp_session_set_version(session, 1);

  in_uint8(c->in_s, sz);
  if ((sz != SCP_SESSION_TYPE_XVNC) && (sz != SCP_SESSION_TYPE_XRDP))
  {
    scp_session_destroy(session);
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: unknown session type", __LINE__);
    return SCP_SERVER_STATE_SESSION_TYPE_ERR;
  }
  scp_session_set_type(session, sz);

  in_uint16_be(c->in_s, cmd);
  scp_session_set_height(session, cmd);
  in_uint16_be(c->in_s, cmd);
  scp_session_set_height(session, cmd);
  in_uint8(c->in_s, sz);
  scp_session_set_bpp(session, sz);
  in_uint8(c->in_s, sz);
  scp_session_set_rsr(session, sz);
  in_uint8a(c->in_s, buf, 17);
    buf[17]='\0';
  scp_session_set_locale(session, buf);

  in_uint8(c->in_s, sz);
  if (sz == SCP_ADDRESS_TYPE_IPV4)
  {
    in_uint32_be(c->in_s, size);
    scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &size);
  }
  else if (sz == SCP_ADDRESS_TYPE_IPV6)
  {
    in_uint8a(c->in_s, buf, 16);
    scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV6_BIN, buf);
  }

  buf[256] = '\0';
  /* reading hostname */
  in_uint8(c->in_s, sz);
  buf[sz]='\0';
  in_uint8a(c->in_s, buf, sz);
  if (0 != scp_session_set_hostname(session, buf))
  {
    scp_session_destroy(session);
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__);
    return SCP_SERVER_STATE_INTERNAL_ERR;
  }

  /* reading username */
  in_uint8(c->in_s, sz);
  buf[sz]='\0';
  in_uint8a(c->in_s, buf, sz);
  if (0 != scp_session_set_username(session, buf))
  {
    scp_session_destroy(session);
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__);
    return SCP_SERVER_STATE_INTERNAL_ERR;
  }

  /* reading password */
  in_uint8(c->in_s, sz);
  buf[sz]='\0';
  in_uint8a(c->in_s, buf, sz);
  if (0 != scp_session_set_password(session, buf))
  {
    scp_session_destroy(session);
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: internal error", __LINE__);
    return SCP_SERVER_STATE_INTERNAL_ERR;
  }

  /* returning the struct */
  (*s)=session;

  return SCP_SERVER_STATE_OK;
}
Example #29
0
/* 006 */
enum SCP_SERVER_STATES_E
scp_v1s_mng_list_sessions(struct SCP_CONNECTION *c, struct SCP_SESSION *s,
                          int sescnt, struct SCP_DISCONNECTED_SESSION *ds)
{
    tui32 version = 1;
    tui32 size = 12;
    tui16 cmd = SCP_CMD_MNG_LIST;
    int pktcnt;
    int idx;
    int sidx;
    int pidx;
    struct SCP_DISCONNECTED_SESSION *cds;

    /* calculating the number of packets to send */
    pktcnt = sescnt / SCP_SERVER_MAX_LIST_SIZE;

    if ((sescnt % SCP_SERVER_MAX_LIST_SIZE) != 0)
    {
        pktcnt++;
    }

    for (idx = 0; idx < pktcnt; idx++)
    {
        /* ok, we send session session list */
        init_stream(c->out_s, c->out_s->size);

        /* size: ver+size+cmdset+cmd+sescnt+continue+count */
        size = 4 + 4 + 2 + 2 + 4 + 1 + 1;

        /* header */
        s_push_layer(c->out_s, channel_hdr, 8);
        out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
        out_uint16_be(c->out_s, cmd);

        /* session count */
        out_uint32_be(c->out_s, sescnt);

        /* setting the continue flag */
        if ((idx + 1)*SCP_SERVER_MAX_LIST_SIZE >= sescnt)
        {
            out_uint8(c->out_s, 0);
            /* setting session count for this packet */
            pidx = sescnt - (idx * SCP_SERVER_MAX_LIST_SIZE);
            out_uint8(c->out_s, pidx);
        }
        else
        {
            out_uint8(c->out_s, 1);
            /* setting session count for this packet */
            pidx = SCP_SERVER_MAX_LIST_SIZE;
            out_uint8(c->out_s, pidx);
        }

        /* adding session descriptors */
        for (sidx = 0; sidx < pidx; sidx++)
        {
            /* shortcut to the current session to send */
            cds = ds + ((idx) * SCP_SERVER_MAX_LIST_SIZE) + sidx;

            /* session data */
            out_uint32_be(c->out_s, cds->SID); /* session id */
            out_uint8(c->out_s, cds->type);
            out_uint16_be(c->out_s, cds->height);
            out_uint16_be(c->out_s, cds->width);
            out_uint8(c->out_s, cds->bpp);
            out_uint8(c->out_s, cds->idle_days);
            out_uint8(c->out_s, cds->idle_hours);
            out_uint8(c->out_s, cds->idle_minutes);
            size += 13;

            out_uint16_be(c->out_s, cds->conn_year);
            out_uint8(c->out_s, cds->conn_month);
            out_uint8(c->out_s, cds->conn_day);
            out_uint8(c->out_s, cds->conn_hour);
            out_uint8(c->out_s, cds->conn_minute);
            out_uint8(c->out_s, cds->addr_type);
            size += 7;

            if (cds->addr_type == SCP_ADDRESS_TYPE_IPV4)
            {
                in_uint32_be(c->out_s, cds->ipv4addr);
                size += 4;
            }
            else if (cds->addr_type == SCP_ADDRESS_TYPE_IPV6)
            {
                in_uint8a(c->out_s, cds->ipv6addr, 16);
                size += 16;
            }
        }

        s_pop_layer(c->out_s, channel_hdr);
        out_uint32_be(c->out_s, version);
        out_uint32_be(c->out_s, size);

        if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
        {
            log_message(LOG_LEVEL_WARNING, "[v1s_mng:%d] connection aborted: network error", __LINE__);
            return SCP_SERVER_STATE_NETWORK_ERR;
        }
    }

    return _scp_v1s_mng_check_response(c, s);
}