Beispiel #1
0
/* added the pointer to the cache and send it to client, it also sets the
   client if it finds it
   returns the index in the cache
   does not take ownership of pointer_item */
int APP_CC
xrdp_cache_add_pointer(struct xrdp_cache* self,
                       struct xrdp_pointer_item* pointer_item)
{
  int i;
  int oldest;
  int index;

  if (self == 0)
  {
    return 0;
  }
  self->pointer_stamp++;
  /* look for match */
  for (i = 2; i < self->pointer_cache_entries; i++)
  {
    if (self->pointer_items[i].x == pointer_item->x &&
        self->pointer_items[i].y == pointer_item->y &&
        g_memcmp(self->pointer_items[i].data,
                 pointer_item->data, 32 * 32 * 3) == 0 &&
        g_memcmp(self->pointer_items[i].mask,
                 pointer_item->mask, 32 * 32 / 8) == 0)
    {
      self->pointer_items[i].stamp = self->pointer_stamp;
      xrdp_wm_set_pointer(self->wm, i);
      self->wm->current_pointer = i;
      DEBUG(("found pointer at %d", i));
      return i;
    }
  }
  /* look for oldest */
  index = 2;
  oldest = 0x7fffffff;
  for (i = 2; i < self->pointer_cache_entries; i++)
  {
    if (self->pointer_items[i].stamp < oldest)
    {
      oldest = self->pointer_items[i].stamp;
      index = i;
    }
  }
  self->pointer_items[index].x = pointer_item->x;
  self->pointer_items[index].y = pointer_item->y;
  g_memcpy(self->pointer_items[index].data,
           pointer_item->data, 32 * 32 * 3);
  g_memcpy(self->pointer_items[index].mask,
           pointer_item->mask, 32 * 32 / 8);
  self->pointer_items[index].stamp = self->pointer_stamp;
  xrdp_wm_send_pointer(self->wm, index,
                       self->pointer_items[index].data,
                       self->pointer_items[index].mask,
                       self->pointer_items[index].x,
                       self->pointer_items[index].y);
  self->wm->current_pointer = index;
  DEBUG(("adding pointer at %d", index));
  return index;
}
Beispiel #2
0
/* not sure how to use a palette in rdp */
int APP_CC
xrdp_cache_add_palette(struct xrdp_cache *self, int *palette)
{
    int i;
    int oldest;
    int index;

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

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

    if (self->wm->screen->bpp > 8)
    {
        return 0;
    }

    self->palette_stamp++;

    /* look for match */
    for (i = 0; i < 6; i++)
    {
        if (g_memcmp(palette, self->palette_items[i].palette,
                     256 * sizeof(int)) == 0)
        {
            self->palette_items[i].stamp = self->palette_stamp;
            return i;
        }
    }

    /* look for oldest */
    index = 0;
    oldest = 0x7fffffff;

    for (i = 0; i < 6; i++)
    {
        if (self->palette_items[i].stamp < oldest)
        {
            oldest = self->palette_items[i].stamp;
            index = i;
        }
    }

    /* set, send palette and return */
    g_memcpy(self->palette_items[index].palette, palette, 256 * sizeof(int));
    self->palette_items[index].stamp = self->palette_stamp;
    libxrdp_orders_send_palette(self->session, palette, index);
    return index;
}
Beispiel #3
0
int DEFAULT_CC
server_palette(struct xrdp_mod* mod, int* palette)
{
  struct xrdp_wm* wm;

  wm = (struct xrdp_wm*)(mod->wm);
  if (g_memcmp(wm->palette, palette, 255 * sizeof(int)) != 0)
  {
    g_memcpy(wm->palette, palette, 256 * sizeof(int));
    xrdp_wm_send_palette(wm);
  }
  return 0;
}
Beispiel #4
0
/* this does not take owership of brush_item_data, it makes a copy */
int APP_CC
xrdp_cache_add_brush(struct xrdp_cache *self,
                     char *brush_item_data)
{
    int i;
    int oldest;
    int index;

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

    self->brush_stamp++;

    /* look for match */
    for (i = 0; i < 64; i++)
    {
        if (g_memcmp(self->brush_items[i].pattern,
                     brush_item_data, 8) == 0)
        {
            self->brush_items[i].stamp = self->brush_stamp;
            DEBUG(("found brush at %d", i));
            return i;
        }
    }

    /* look for oldest */
    index = 0;
    oldest = 0x7fffffff;

    for (i = 0; i < 64; i++)
    {
        if (self->brush_items[i].stamp < oldest)
        {
            oldest = self->brush_items[i].stamp;
            index = i;
        }
    }

    g_memcpy(self->brush_items[index].pattern,
             brush_item_data, 8);
    self->brush_items[index].stamp = self->brush_stamp;
    libxrdp_orders_send_brush(self->session, 8, 8, 1, 0x81, 8,
                              self->brush_items[index].pattern, index);
    DEBUG(("adding brush at %d", index));
    return index;
}
Beispiel #5
0
static int APP_CC
xrdp_caps_process_codecs(struct xrdp_rdp *self, struct stream *s, int len)
{
    int codec_id;
    int codec_count;
    int index;
    int codec_properties_length;
    int i1;
    char *codec_guid;
    char *next_guid;

    if (len < 1)
    {
        g_writeln("xrdp_caps_process_codecs: error");
        return 1;
    }
    in_uint8(s, codec_count);
    len--;

    for (index = 0; index < codec_count; index++)
    {
        codec_guid = s->p;
        if (len < 16 + 1 + 2)
        {
            g_writeln("xrdp_caps_process_codecs: error");
            return 1;
        }
        in_uint8s(s, 16);
        in_uint8(s, codec_id);
        in_uint16_le(s, codec_properties_length);
        len -= 16 + 1 + 2;
        if (len < codec_properties_length)
        {
            g_writeln("xrdp_caps_process_codecs: error");
            return 1;
        }
        len -= codec_properties_length;
        next_guid = s->p + codec_properties_length;

        if (g_memcmp(codec_guid, XR_CODEC_GUID_NSCODEC, 16) == 0)
        {
            g_writeln("xrdp_caps_process_codecs: nscodec, codec id %d, properties len %d",
                      codec_id, codec_properties_length);
            self->client_info.ns_codec_id = codec_id;
            i1 = MIN(64, codec_properties_length);
            g_memcpy(self->client_info.ns_prop, s->p, i1);
            self->client_info.ns_prop_len = i1;
        }
        else if (g_memcmp(codec_guid, XR_CODEC_GUID_REMOTEFX, 16) == 0)
        {
            g_writeln("xrdp_caps_process_codecs: RemoteFX, codec id %d, properties len %d",
                      codec_id, codec_properties_length);
            self->client_info.rfx_codec_id = codec_id;
            i1 = MIN(64, codec_properties_length);
            g_memcpy(self->client_info.rfx_prop, s->p, i1);
            self->client_info.rfx_prop_len = i1;
        }
        else if (g_memcmp(codec_guid, XR_CODEC_GUID_JPEG, 16) == 0)
        {
            g_writeln("xrdp_caps_process_codecs: jpeg, codec id %d, properties len %d",
                      codec_id, codec_properties_length);
            self->client_info.jpeg_codec_id = codec_id;
            i1 = MIN(64, codec_properties_length);
            g_memcpy(self->client_info.jpeg_prop, s->p, i1);
            self->client_info.jpeg_prop_len = i1;
            /* make sure that requested quality is  between 0 to 100 */
            if (self->client_info.jpeg_prop[0] < 0 || self->client_info.jpeg_prop[0] > 100)
            {
                g_writeln("  Warning: the requested jpeg quality (%d) is invalid,"
                          " falling back to default", self->client_info.jpeg_prop[0]);
                self->client_info.jpeg_prop[0] = 75; /* use default */
            }
            g_writeln("  jpeg quality set to %d", self->client_info.jpeg_prop[0]);
        }
        else if (g_memcmp(codec_guid, XR_CODEC_GUID_H264, 16) == 0)
        {
            g_writeln("xrdp_caps_process_codecs: h264, codec id %d, properties len %d",
                      codec_id, codec_properties_length);
            self->client_info.h264_codec_id = codec_id;
            i1 = MIN(64, codec_properties_length);
            g_memcpy(self->client_info.h264_prop, s->p, i1);
            self->client_info.h264_prop_len = i1;
        }
        else
        {
            g_writeln("xrdp_caps_process_codecs: unknown codec id %d", codec_id);
        }

        s->p = next_guid;
    }

    return 0;
}
Beispiel #6
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;
}