Ejemplo n.º 1
0
/* returns error
   data coming in from the channel handler, send it to the client */
static int APP_CC
xrdp_mm_trans_process_channel_data(struct xrdp_mm* self, struct trans* trans)
{
  struct stream* s = (struct stream *)NULL;
  int size = 0;
  int total_size = 0;
  int chan_id = 0;
  int chan_flags = 0;
  int rv = 0;

  s = trans_get_in_s(trans);
  if (s == 0)
  {
    return 1;
  }
  in_uint16_le(s, chan_id);
  in_uint16_le(s, chan_flags);
  in_uint16_le(s, size);
  in_uint32_le(s, total_size);
  rv = xrdp_mm_trans_send_channel_data_response(self, trans);
  if (rv == 0)
  {
    rv = libxrdp_send_to_channel(self->wm->session, chan_id, s->p, size, total_size,
                                 chan_flags);
  }
  return rv;
}
Ejemplo n.º 2
0
/* this is callback from trans obj
   returns error */
static int APP_CC
xrdp_mm_chan_data_in(struct trans* trans)
{
  struct xrdp_mm* self = (struct xrdp_mm *)NULL;
  struct stream* s = (struct stream *)NULL;
  int id = 0;
  int size = 0;
  int error = 0;

  if (trans == 0)
  {
    return 1;
  }
  self = (struct xrdp_mm*)(trans->callback_data);
  s = trans_get_in_s(trans);
  if (s == 0)
  {
    return 1;
  }
  in_uint32_le(s, id);
  in_uint32_le(s, size);
  error = trans_force_read(trans, size - 8);
  if (error == 0)
  {
    /* here, the entire message block is read in, process it */
    error = xrdp_mm_chan_process_msg(self, trans, s);
  }
  return error;
}
Ejemplo n.º 3
0
/* returns error */
int DEFAULT_CC
my_trans_data_in(struct trans *trans)
{
    struct stream *s = (struct stream *)NULL;
    int id = 0;
    int size = 0;
    int error = 0;

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

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

    LOGM((LOG_LEVEL_DEBUG, "my_trans_data_in:"));
    s = trans_get_in_s(trans);
    in_uint32_le(s, id);
    in_uint32_le(s, size);
    error = trans_force_read(trans, size - 8);

    if (error == 0)
    {
        /* here, the entire message block is read in, process it */
        error = process_message();
    }

    return error;
}
Ejemplo n.º 4
0
/* returns error */
	int DEFAULT_CC
my_trans_data_in(struct trans* trans)
{
	struct stream* s;
	int id;
	int size;
	int error;

	if (trans == 0)
	{
		return 0;
	}
	if (trans != g_con_trans)
	{
		return 1;
	}
	log_message(&log_conf, LOG_LEVEL_DEBUG, "chansrv[my_trans_data_in]: "
			"my_trans_data_in:");
	s = trans_get_in_s(trans);
	in_uint32_le(s, id);
	in_uint32_le(s, size);
	error = trans_force_read(trans, size - 8);
	if (error == 0)
	{
		/* here, the entire message block is read in, process it */
		error = process_message();
	}
	return error;
}
Ejemplo n.º 5
0
/* returns error */
static int APP_CC
process_message(void)
{
    struct stream *s = (struct stream *)NULL;
    int size = 0;
    int id = 0;
    int rv = 0;
    char *next_msg = (char *)NULL;

    if (g_con_trans == 0)
    {
        return 1;
    }

    s = trans_get_in_s(g_con_trans);

    if (s == 0)
    {
        return 1;
    }

    rv = 0;

    while (s_check_rem(s, 8))
    {
        next_msg = s->p;
        in_uint32_le(s, id);
        in_uint32_le(s, size);
        next_msg += size;

        switch (id)
        {
            case 1: /* init */
                rv = process_message_init(s);
                break;
            case 3: /* channel setup */
                rv = process_message_channel_setup(s);
                break;
            case 5: /* channel data */
                rv = process_message_channel_data(s);
                break;
            case 7: /* channel data response */
                rv = process_message_channel_data_response(s);
                break;
            default:
                LOGM((LOG_LEVEL_ERROR, "process_message: error in process_message ",
                      "unknown msg %d", id));
                break;
        }

        if (rv != 0)
        {
            break;
        }

        s->p = next_msg;
    }

    return rv;
}
Ejemplo n.º 6
0
/* returns error */
	static int APP_CC
process_message(void)
{
	struct stream* s;
	int size;
	int id;
	int rv;
	char* next_msg;

	if (g_con_trans == 0)
	{
		return 1;
	}
	s = trans_get_in_s(g_con_trans);
	if (s == 0)
	{
		return 1;
	}
	rv = 0;
	while (s_check_rem(s, 8))
	{
		next_msg = s->p;
		in_uint32_le(s, id);
		in_uint32_le(s, size);
		next_msg += size;
		switch (id)
		{
			case 1: /* init */
				rv = process_message_init(s);
				break;
			case 3: /* channel setup */
				rv = process_message_channel_setup(s);
				break;
			case 5: /* channel data */
				rv = process_message_channel_data(s);
				break;
			case 7: /* channel data response */
				rv = process_message_channel_data_response(s);
				break;
			default:
				log_message(&log_conf, LOG_LEVEL_DEBUG, "chansrv[process_message]: "
						"unknown msg %d", id);
				break;
		}
		if (rv != 0)
		{
			break;
		}
		s->p = next_msg;
	}
	return rv;
}
Ejemplo n.º 7
0
static int APP_CC
xrdp_mm_sesman_data_in(struct trans* trans)
{
  struct xrdp_mm* self = (struct xrdp_mm *)NULL;
  struct stream* s = (struct stream *)NULL;
  int version = 0;
  int size = 0;
  int error = 0;
  int code = 0;

  if (trans == 0)
  {
    return 1;
  }
  self = (struct xrdp_mm*)(trans->callback_data);
  s = trans_get_in_s(trans);
  if (s == 0)
  {
    return 1;
  }
  in_uint32_be(s, version);
  in_uint32_be(s, size);
  error = trans_force_read(trans, size - 8);
  if (error == 0)
  {
    in_uint16_be(s, code);
    switch (code)
    {
      case 3:
        error = xrdp_mm_process_login_response(self, s);
        break;
      default:
        g_writeln("xrdp_mm_sesman_data_in: unknown code %d", code);
        break;
    }
  }

  return error;
}
Ejemplo n.º 8
0
Archivo: sound.c Proyecto: OSgenie/xrdp
/* data coming in from audio source, eg pulse, alsa */
static int DEFAULT_CC
sound_trans_audio_data_in(struct trans *trans)
{
    struct stream *s;
    int id;
    int size;
    int error;

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

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

    s = trans_get_in_s(trans);
    in_uint32_le(s, id);
    in_uint32_le(s, size);

    if ((id != 0) || (size > 128 * 1024 + 8) || (size < 8))
    {
        LOG(0, ("sound_trans_audio_data_in: bad message id %d size %d", id, size));
        return 1;
    }
    LOG(10, ("sound_trans_audio_data_in: good message id %d size %d", id, size));

    error = trans_force_read(trans, size - 8);

    if (error == 0)
    {
        /* here, the entire message block is read in, process it */
        error = process_pcm_message(id, size - 8, s);
    }

    return error;
}
Ejemplo n.º 9
0
/*
 * called when WTSVirtualChannelOpenEx is invoked in xrdpapi.c
 *
 ******************************************************************************/
int DEFAULT_CC
my_api_trans_conn_in(struct trans *trans, struct trans *new_trans)
{
    struct xrdp_api_data *ad;
    struct stream        *s;
    int                   error;
    int                   index;
    char                  chan_pri;

    if ((trans == 0) || (trans != g_api_lis_trans) || (new_trans == 0))
    {
        return 1;
    }

    LOGM((LOG_LEVEL_DEBUG, "my_api_trans_conn_in:"));
    LOG(10, ("my_api_trans_conn_in: got incoming"));

    s = trans_get_in_s(new_trans);
    s->end = s->data;

    error = trans_force_read(new_trans, 64);

    if (error != 0)
    {
        LOG(0, ("my_api_trans_conn_in: trans_force_read failed"));
        trans_delete(new_trans);
    }

    s->end = s->data;

    ad = (struct xrdp_api_data *) g_malloc(sizeof(struct xrdp_api_data), 1);
    g_memcpy(ad->header, s->data, 64);

    ad->flags = GGET_UINT32(ad->header, 16);
    ad->chan_id = -1;
    ad->dvc_chan_id = -1;

    if (ad->flags > 0)
    {
        /* opening a dynamic virtual channel */

        if ((index = find_empty_slot_in_dvc_channels()) < 0)
        {
            /* exceeded MAX_DVC_CHANNELS */
            LOG(0, ("my_api_trans_conn_in: MAX_DVC_CHANNELS reached; giving up!"))
            g_free(ad);
            trans_delete(new_trans);
            return 1;
        }

        g_dvc_channels[index] = ad;
        chan_pri = 4 - ad->flags;
        ad->dvc_chan_id = g_dvc_chan_id++;
        ad->is_connected = 0;
        ad->transp = new_trans;
        drdynvc_send_open_channel_request(chan_pri, ad->dvc_chan_id, ad->header);
    }
    else
    {
        /* opening a static virtual channel */

        for (index = 0; index < g_num_chan_items; index++)
        {
            LOG(10, ("my_api_trans_conn_in:  %s %s", ad->header,
                    g_chan_items[index].name));

            if (g_strcasecmp(ad->header, g_chan_items[index].name) == 0)
            {
                LOG(10, ("my_api_trans_conn_in: found it at %d", index));
                ad->chan_id = g_chan_items[index].id;
                break;
            }
        }
        if (index == g_num_chan_items)
        {
            g_writeln("did not find SVC named %s", ad->header);
        }
    }

    new_trans->callback_data = ad;

    trans_delete(g_api_con_trans);
    g_api_con_trans = new_trans;
    g_api_con_trans->trans_data_in = my_api_trans_data_in;
    g_api_con_trans->header_size = 0;

    return 0;
}
Ejemplo n.º 10
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;
}