示例#1
0
void run_stream()
{
	std::vector<int> a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

	auto m = make_stream(a);
	float total = m.reduce(0.f, [](float acc, const int x) { 
		return acc + x; 
	});

	std::cout << total << "\n";

	auto filtered = m.filter([](int i) { return i >= 5; });
	filtered.for_each([](int i) { std::cout << i << " "; });
	std::cout << "\n";

	std::vector<char> b = { 'a', 'b', 'c', 'd', 'e', 'f' };
	auto result1 = m.zip(b);
	auto result2 = make_stream(b).zip(a);

	auto result3 = m.to_container();
	auto result4 = m.to_container<std::list>();

	auto result5 = make_stream(b)
					.sorted([](int i, int j) { return j < i; })
					.to_container();
}
示例#2
0
xmlDocPtr DEFAULT_CC
xml_receive_message(int client)
{
	struct stream* s;
	int data_length;
	int res = 0;
	make_stream(s);
	init_stream(s, 1024);
	xmlDocPtr doc;

	res= g_tcp_recv(client, s->data, sizeof(int), 0);

	if (res != sizeof(int))
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[xml_received_message]: "
				"Unable to read size header with error %s", strerror(g_get_errno()));
		return NULL;
	}
	in_uint32_be(s,data_length);
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_received_message]: "
			"data_length : %i", data_length);
	free_stream(s);
	make_stream(s);
	init_stream(s, data_length + 1);

	g_tcp_recv(client, s->data, data_length, 0);
	s->data[data_length] = 0;
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_received_message]: "
			"data : %s",s->data);
	doc = xmlReadMemory(s->data, data_length, "noname.xml", NULL, 0);
	free_stream(s);
	return doc;
}
示例#3
0
int APP_CC
xrdp_image_compress_rle(int width, int height, int bpp, unsigned char* data, char* dest)
{
   struct stream *s;
   struct stream *tmp_s;
   int e;
   int i;
   int bufsize;
   make_stream(s);
   init_stream(s, IMAGE_TILE_MAX_BUFFER_SIZE);
   make_stream(tmp_s);
   init_stream(tmp_s, IMAGE_TILE_MAX_BUFFER_SIZE);
   e = width % 4;

   if (e != 0)
       e = 4 - e;

   i = height;
   xrdp_bitmap_compress(data, width, height, s, bpp, IMAGE_TILE_MAX_BUFFER_SIZE, i - 1, tmp_s, e);
   bufsize = (int) (s->p - s->data);
   g_memcpy(dest, s->data, bufsize);
   free_stream(tmp_s);
   free_stream(s);
   return bufsize;
}
示例#4
0
struct trans* APP_CC
trans_create(int mode, int in_size, int out_size)
{
  struct trans* self;

  self = (struct trans*)g_malloc(sizeof(struct trans), 1);
  make_stream(self->in_s);
  init_stream(self->in_s, in_size);
  make_stream(self->out_s);
  init_stream(self->out_s, out_size);
  self->mode = mode;
  return self;
}
示例#5
0
文件: chansrv.c 项目: eric011/xrdp
/* returns error */
static int APP_CC
add_data_to_chan_item(struct chan_item *chan_item, char *data, int size)
{
    struct stream *s;
    struct chan_out_data *cod;

    make_stream(s);
    init_stream(s, size);
    g_memcpy(s->data, data, size);
    s->end = s->data + size;
    cod = (struct chan_out_data *)g_malloc(sizeof(struct chan_out_data), 1);
    cod->s = s;

    if (chan_item->tail == 0)
    {
        chan_item->tail = cod;
        chan_item->head = cod;
    }
    else
    {
        chan_item->tail->next = cod;
        chan_item->tail = cod;
    }

    return 0;
}
示例#6
0
TEST(InputStream, new_line_3)
{
    klex::InputStream is(make_stream("a\r\n\r\r\nb\r"));
    ASSERT_EQ(1, is.get_line());
    ASSERT_EQ(1, is.get_line());
    ASSERT_EQ('a', is.get());
    ASSERT_EQ(1, is.get_line());
    ASSERT_EQ(2, is.get_column());
    ASSERT_EQ('\n', is.get());
    ASSERT_EQ(2, is.get_line());
    ASSERT_EQ(1, is.get_column());
    ASSERT_EQ('\n', is.get());
    ASSERT_EQ(3, is.get_line());
    ASSERT_EQ(1, is.get_column());
    ASSERT_EQ('\n', is.get());
    ASSERT_EQ(4, is.get_line());
    ASSERT_EQ(1, is.get_column());
    ASSERT_EQ('b', is.get());
    ASSERT_EQ(4, is.get_line());
    ASSERT_EQ(2, is.get_column());
    ASSERT_EQ('\n', is.get());
    ASSERT_EQ(5, is.get_line());
    ASSERT_EQ(1, is.get_column());
    ASSERT_EQ(EOF, is.get());
    ASSERT_EQ(5, is.get_line());
    ASSERT_EQ(1, is.get_column());
}
示例#7
0
文件: libxrdp.c 项目: Osirium/xrdp
int EXPORT_CC
libxrdp_send_bell(struct xrdp_session *session)
{
    struct stream *s = (struct stream *)NULL;

    DEBUG(("libxrdp_send_bell sending bell signal"));
    /* see MS documentation: Server play sound PDU, TS_PLAY_SOUND_PDU_DATA */

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

    if (xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s) != 0)
    {
        free_stream(s);
        return 1;
    }

    out_uint32_le(s, 440); /* frequency */
    out_uint32_le(s, 100); /* duration (ms) */
    s_mark_end(s);

    if (xrdp_rdp_send_data((struct xrdp_rdp *)session->rdp, s, RDP_DATA_PDU_PLAY_SOUND) != 0)
    {
        free_stream(s);
        return 1;
    }

    free_stream(s);
    return 0;
}
示例#8
0
void cliprdr_send_data(int request_type)
{
	struct stream* s;
	int clipboard_size = clipboard_get_current_clipboard_data_size(&clipboard, format_utf8_string_atom);
	char* clipboard_data = (char*)clipboard_get_current_clipboard_data(&clipboard, format_utf8_string_atom);

	int uni_clipboard_len = (clipboard_size+1)*2;
	int packet_len = uni_clipboard_len + 12;
	char* temp;

	make_stream(s);
	init_stream(s,packet_len);

	log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_send_data]:");
	/* clip header */
	out_uint16_le(s, CB_FORMAT_DATA_RESPONSE);             /* msg type */
	out_uint16_le(s, 0);                                   /* msg flag */
	out_uint32_le(s, uni_clipboard_len);                   /* msg size */
	temp = s->p;
	uni_rdp_out_str(s, clipboard_data, uni_clipboard_len);


	s_mark_end(s);
	cliprdr_send(s);
	free_stream(s);

}
示例#9
0
文件: sound.c 项目: OSgenie/xrdp
static int
sound_send_training(void)
{
    struct stream *s;
    int bytes;
    int time;
    char *size_ptr;

    print_got_here();

    make_stream(s);
    init_stream(s, 8182);
    out_uint16_le(s, SNDC_TRAINING);
    size_ptr = s->p;
    out_uint16_le(s, 0); /* size, set later */
    time = g_time2();
    g_training_sent_time = time;
    out_uint16_le(s, time);
    out_uint16_le(s, 1024);
    out_uint8s(s, (1024 - 4));
    s_mark_end(s);
    bytes = (int)((s->end - s->data) - 4);
    size_ptr[0] = bytes;
    size_ptr[1] = bytes >> 8;
    bytes = (int)(s->end - s->data);
    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
    free_stream(s);
    return 0;
}
示例#10
0
void cliprdr_send_capability()
{
	/* this message is ignored by rdp applet */
	struct stream* s;

	make_stream(s);
	init_stream(s,1024);

	log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[cliprdr_send_capability]:");
	/* clip header */
	out_uint16_le(s, CB_CLIP_CAPS);                        /* msg type */
	out_uint16_le(s, 0x00);                                /* msg flag */
	out_uint32_le(s, 0);                                   /* msg size */
	/* we only support one capability for now */
	out_uint16_le(s, 1);                                   /* cCapabilitiesSets */
	out_uint8s(s, 16);                                     /* pad */
	/* CLIPRDR_CAPS_SET */
	out_uint16_le(s, CB_CAPSTYPE_GENERAL);                 /* capabilitySetType */
	out_uint16_le(s, 92);                                  /* lengthCapability */
	out_uint32_le(s, CB_CAPS_VERSION_1);                   /* version */
	out_uint32_le(s, 0);                                   /* general flags */


	s_mark_end(s);
	cliprdr_send(s);
	free_stream(s);

}
示例#11
0
bool APP_CC
xrdp_emt_send_request(struct xrdp_rdp* self, struct xrdp_emt* emt, int type)
{
  struct stream* s;

  if (emt == NULL)
  {
    printf("emt is null\n");
    return false;
  }

  make_stream(s);
  init_stream(s, 40);
  xrdp_sec_init(self->sec_layer, s);

  out_uint8(s, SEC_AUTODETECT_REQ_LENGTH);               // headerLength
  out_uint8(s, TYPE_ID_AUTODETECT_REQUEST);              // headerTypeId
  out_uint16_le(s, emt->seq_number++);                   // sequenceNumber
  out_uint16_le(s, type);                                // responseType
  s_mark_end(s);

  xrdp_emt_send_packet(self, emt, s);
  free_stream(s);

  return true;
}
示例#12
0
bool APP_CC
xrdp_emt_send_result(struct xrdp_rdp* self, struct xrdp_emt* emt)
{
  struct stream* s;

  if (emt == NULL)
  {
    printf("emt is null\n");
    return false;
  }

  make_stream(s);
  init_stream(s, 40);
  xrdp_sec_init(self->sec_layer, s);

  out_uint8(s, SEC_AUTODETECT_REQ_LENGTH);               // headerLength
  out_uint8(s, TYPE_ID_AUTODETECT_REQUEST);              // headerTypeId
  out_uint16_le(s, emt->seq_number++);                   // sequenceNumber
  out_uint16_le(s, field_all);                           // responseType

  out_uint32_le(s, self->session->base_RTT);
  out_uint32_le(s, self->session->bandwidth);
  out_uint32_le(s, self->session->average_RTT);

  s_mark_end(s);

  xrdp_emt_send_packet(self, emt, s);
  free_stream(s);

  return true;
}
示例#13
0
文件: gopcnx-xup.c 项目: nrich/xrdp
/* return error */
static int APP_CC
send_paint_rect_ack(struct mod *mod, int flags, int x, int y, int cx, int cy,
                    int frame_id)
{
    int len;
    struct stream *s;

    make_stream(s);
    init_stream(s, 8192);
    s_push_layer(s, iso_hdr, 4);
    out_uint16_le(s, 105);
    out_uint32_le(s, flags);
    out_uint32_le(s, frame_id);
    out_uint32_le(s, x);
    out_uint32_le(s, y);
    out_uint32_le(s, cx);
    out_uint32_le(s, cy);
    s_mark_end(s);
    len = (int)(s->end - s->data);
    s_pop_layer(s, iso_hdr);
    out_uint32_le(s, len);
    lib_send(mod, s->data, len);
    free_stream(s);
    return 0;
}
示例#14
0
int main(int argc, char** args) {
    int i;
    for (i=1; i < argc; i++) {
	printf("%s\n", *(args+i));
	stream input_stream = make_stream(*(args+i));
	while (next(input_stream)) {
	    printf("%c", current(input_stream));
	}
	next(input_stream);
	next(input_stream);
	next(input_stream);
	while (back(input_stream)) {
	    printf("%c", current(input_stream));
	}
	while (next(input_stream)) {
	    printf("%c", current(input_stream));
	}
	while (back(input_stream)) {
	    printf("%c", current(input_stream));
	}
	printf("!\n");
	dispose_stream(input_stream);
	//tokenize(*(args+i));
    }

    return 0;
}
示例#15
0
int APP_CC
dev_redir_process_close_io_request(int completion_id)
{
	struct stream* s;

	log_message(&log_conf, LOG_LEVEL_DEBUG, "chansrv[dev_redir_process_close_io_request]:"
	  		"close file : %s",actions[completion_id].path);
	make_stream(s);
	init_stream(s,1100);
	actions[completion_id].last_req = IRP_MJ_CLOSE;
	out_uint16_le(s, RDPDR_CTYP_CORE);
	out_uint16_le(s, PAKID_CORE_DEVICE_IOREQUEST);
	out_uint32_le(s, actions[completion_id].device);
	out_uint32_le(s, actions[completion_id].file_id);
	out_uint32_le(s, completion_id);
	out_uint32_le(s, IRP_MJ_CLOSE);   	/* major version */
	out_uint32_le(s, 0);								/* minor version */
	out_uint8s(s,32);
	s_mark_end(s);
	dev_redir_send(s);
	actions[completion_id].message_id++;
	free_stream(s);
	return 0;
	free_stream(s);
}
示例#16
0
/* returns error */
int APP_CC
xrdp_iso_incoming(struct xrdp_iso* self)
{
  int code;
  struct stream* s;

  make_stream(s);
  init_stream(s, 8192);
  DEBUG(("   in xrdp_iso_incoming"));
  if (xrdp_iso_recv_msg(self, s, &code) != 0)
  {
    free_stream(s);
    return 1;
  }

  if (! xrdp_iso_parse_connection_request(self, s, code))
  {
    free_stream(s);
    return 1;
  }

  if (code != ISO_PDU_CR)
  {
    free_stream(s);
    return 1;
  }
  if (xrdp_iso_send_connection_confirm(self, s) != 0)
  {
    free_stream(s);
    return 1;
  }
  DEBUG(("   out xrdp_iso_incoming"));
  free_stream(s);
  return 0;
}
示例#17
0
/* return error */
int DEFAULT_CC
lib_mod_event(struct mod* mod, int msg, tbus param1, tbus param2,
              tbus param3, tbus param4)
{
  struct stream* s;
  int len;
  int rv;

  LIB_DEBUG(mod, "in lib_mod_event");
  make_stream(s);
  init_stream(s, 8192);
  s_push_layer(s, iso_hdr, 4);
  out_uint16_le(s, 103);
  out_uint32_le(s, msg);
  out_uint32_le(s, param1);
  out_uint32_le(s, param2);
  out_uint32_le(s, param3);
  out_uint32_le(s, param4);
  s_mark_end(s);
  len = (int)(s->end - s->data);
  s_pop_layer(s, iso_hdr);
  out_uint32_le(s, len);
  rv = lib_send(mod, s->data, len);
  free_stream(s);
  LIB_DEBUG(mod, "out lib_mod_event");
  return rv;
}
示例#18
0
/* ask the client to send the file size */
int
clipboard_request_file_size(int stream_id, int lindex)
{
    struct stream *s;
    int size;
    int rv;

    log_debug("clipboard_request_file_size:");
    if (g_file_request_sent_type != 0)
    {
        log_error("clipboard_request_file_size: warning, still waiting "
                   "for CB_FILECONTENTS_RESPONSE");
    }
    make_stream(s);
    init_stream(s, 8192);
    out_uint16_le(s, CB_FILECONTENTS_REQUEST); /* 8 */
    out_uint16_le(s, 0);
    out_uint32_le(s, 28);
    out_uint32_le(s, stream_id);
    out_uint32_le(s, lindex);
    out_uint32_le(s, CB_FILECONTENTS_SIZE);
    out_uint32_le(s, 0); /* nPositionLow */
    out_uint32_le(s, 0); /* nPositionHigh */
    out_uint32_le(s, 0); /* cbRequested */
    out_uint32_le(s, 0); /* clipDataId */
    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_request_sent_type = CB_FILECONTENTS_SIZE;
    return rv;
}
示例#19
0
文件: sound.c 项目: OSgenie/xrdp
static int APP_CC
sound_send_server_formats(void)
{
    struct stream *s;
    int bytes;
    char *size_ptr;

    print_got_here();

    make_stream(s);
    init_stream(s, 8182);
    out_uint16_le(s, SNDC_FORMATS);
    size_ptr = s->p;
    out_uint16_le(s, 0);        /* size, set later */
    out_uint32_le(s, 0);        /* dwFlags */
    out_uint32_le(s, 0);        /* dwVolume */
    out_uint32_le(s, 0);        /* dwPitch */
    out_uint16_le(s, 0);        /* wDGramPort */
    out_uint16_le(s, 1);        /* wNumberOfFormats */
    out_uint8(s, g_cBlockNo);   /* cLastBlockConfirmed */
    out_uint16_le(s, 2);        /* wVersion */
    out_uint8(s, 0);            /* bPad */

    /* sndFormats */
    /*
        wFormatTag      2 byte offset 0
        nChannels       2 byte offset 2
        nSamplesPerSec  4 byte offset 4
        nAvgBytesPerSec 4 byte offset 8
        nBlockAlign     2 byte offset 12
        wBitsPerSample  2 byte offset 14
        cbSize          2 byte offset 16
        data            variable offset 18
    */

    /*  examples
        01 00 02 00 44 ac 00 00 10 b1 02 00 04 00 10 00 ....D...........
        00 00
        01 00 02 00 22 56 00 00 88 58 01 00 04 00 10 00 ...."V...X......
        00 00
    */

    out_uint16_le(s, 1);         // wFormatTag - WAVE_FORMAT_PCM
    out_uint16_le(s, 2);         // num of channels
    out_uint32_le(s, 44100);     // samples per sec
    out_uint32_le(s, 176400);    // avg bytes per sec
    out_uint16_le(s, 4);         // block align
    out_uint16_le(s, 16);        // bits per sample
    out_uint16_le(s, 0);         // size

    s_mark_end(s);
    bytes = (int)((s->end - s->data) - 4);
    size_ptr[0] = bytes;
    size_ptr[1] = bytes >> 8;
    bytes = (int)(s->end - s->data);
    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
    free_stream(s);
    return 0;
}
示例#20
0
int main( int argc, char** argv )
{
    #ifdef WIN32
    std::cerr << "io-cat: not implemented on windows" << std::endl;
    return 1;
    #endif
    try
    {
        if( argc < 2 ) { usage(); }
        comma::command_line_options options( argc, argv, usage );
        unsigned int size = options.value( "--size,-s", 0 );
        bool unbuffered = options.exists( "--flush,--unbuffered,-u" );
        const std::vector< std::string >& unnamed = options.unnamed( "--flush,--unbuffered,-u", "-.+" );
        #ifdef WIN32
        if( size || unnamed.size() == 1 ) { _setmode( _fileno( stdout ), _O_BINARY ); }
        #endif
        if( unnamed.empty() ) { std::cerr << "io-cat: please specify at least one source" << std::endl; return 1; }
        boost::ptr_vector< stream > streams;
        comma::io::select select;
        for( unsigned int i = 0; i < unnamed.size(); ++i )
        { 
            streams.push_back( make_stream( unnamed[i], size, size || unnamed.size() == 1 ) );
            select.read().add( streams.back() );
        }
        const unsigned int max_count = size ? ( size > 65536u ? 1 : 65536u / size ) : 0;
        std::vector< char > buffer( size ? size * max_count : 65536u );
        unsigned int round_robin_count = unnamed.size() > 1 ? options.value( "--round-robin", 0 ) : 0;
        comma::signal_flag is_shutdown;
        for( bool done = false; !is_shutdown && !done; )
        {
            if( select.wait( boost::posix_time::seconds( 1 ) ) == 0 ) { continue; }
            done = true;
            for( unsigned int i = 0; i < streams.size(); ++i )
            {
                if( streams[i].eof() ) { continue; }
                if( !select.read().ready( streams[i].fd() ) ) { done = false; continue; }
                unsigned int countdown = round_robin_count;
                while( !is_shutdown && !streams[i].eof() )
                {
                    unsigned int bytes_read = streams[i].read_available( buffer, countdown ? countdown : max_count );
                    if( bytes_read == 0 ) { break; }
                    done = false;
                    if( size && bytes_read % size != 0 ) { std::cerr << "io-cat: expected " << size << " byte(s), got only " << ( bytes_read % size ) << " on " << streams[i].address() << std::endl; return 1; }
                    std::cout.write( &buffer[0], bytes_read );
                    if( unbuffered ) { std::cout.flush(); }
                    if( round_robin_count )
                    {
                        countdown -= ( size ? bytes_read / size : 1 );
                        if( countdown == 0 ) { break; }
                    }
                }
            }
        }
        return 0;
    }
    catch( std::exception& ex ) { std::cerr << "io-cat: " << ex.what() << std::endl; }
    catch( ... ) { std::cerr << "io-cat: unknown exception" << std::endl; }
    return 1;
}
示例#21
0
int main() {
    auto ctx = tl::launch_local(1);
    auto stream = make_stream(10);
    auto result = stream.then(
        [] (FList<int>& x) { return sum_stream(x, 0); }
    ).unwrap().get();
    std::cout << "Total: " << result << std::endl;
}
示例#22
0
void tokenize(char* input) {
    stream input_stream = make_stream(input);
    while (next(input_stream)) {
	printf("%c is %swhitespace\n", 
	       current(input_stream), isspace(current(input_stream)) ? "" : "not ");
    }
    dispose_stream(input_stream);
}
示例#23
0
secure_vector<byte> Stream_Compression::start_raw(const byte[], size_t nonce_len)
   {
   if(!valid_nonce_length(nonce_len))
      throw Invalid_IV_Length(name(), nonce_len);

   m_stream.reset(make_stream());
   return secure_vector<byte>();
   }
示例#24
0
TEST(InputStream, simple_get)
{
    klex::InputStream is(make_stream("abc"));
    ASSERT_EQ('a', is.get());
    ASSERT_EQ('b', is.get());
    ASSERT_EQ('c', is.get());
    ASSERT_EQ(EOF, is.get());
}
示例#25
0
/* send a chunk of the file from server to client */
static int 
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)
    {
        LLOGLN(10, ("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)
    {
        LLOGLN(10, ("clipboard_send_file_data: error cfi is nil"));
        return 1;
    }
    LLOGLN(10, ("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)
    {
        LLOGLN(0, ("clipboard_send_file_data: file open [%s] failed",
                   full_fn));
        return 1;
    }
    g_file_seek(fd, nPositionLow);
    make_stream(s);
    init_stream(s, cbRequested + 64);
    size = g_file_read(fd, s->data + 12, cbRequested);
    if (size < 1)
    {
        LLOGLN(0, ("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;
}
示例#26
0
文件: main.c 项目: harpyham/openulteo
void *thread_vchannel_process (void * arg)
{
	struct stream* s = NULL;
	int rv;
	int length;
	int total_length;

	signal(SIGCHLD, handler);
	cliprdr_send_ready();
	cliprdr_send_capability();

	while(running){
		make_stream(s);
		init_stream(s, 1600);

		rv = vchannel_receive(cliprdr_channel, s->data, &length, &total_length);
		if( rv == ERROR )
		{
			log_message(l_config, LOG_LEVEL_ERROR, "vchannel_cliprdr[thread_vchannel_process]: "
					"Invalid message");
			vchannel_close(cliprdr_channel);
			pthread_exit ((void*)1);
		}
		switch(rv)
		{
		case ERROR:
			log_message(l_config, LOG_LEVEL_ERROR, "vchannel_cliprdr[thread_vchannel_process]: "
					"Invalid message");
			break;
		case STATUS_CONNECTED:
			log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[thread_vchannel_process]: "
					"Status connected");
			break;
		case STATUS_DISCONNECTED:
			log_message(l_config, LOG_LEVEL_DEBUG, "vchannel_cliprdr[thread_vchannel_process]: "
					"Status disconnected");
			running = 0;

			// Send a dummy event in order to unblock XNextEvent function
			send_dummy_event();

			break;
		default:
			if (length == 0)
			{
				running = false;
				send_dummy_event();
				pthread_exit (0);
			}

			cliprdr_process_message(s, length, total_length);
			break;
		}
		free_stream(s);
	}
	pthread_exit (0);
}
示例#27
0
TEST(InputStream, simple_peek)
{
    klex::InputStream is(make_stream("abc"));
    ASSERT_EQ('a', is.peek(0));
    ASSERT_EQ('b', is.peek(1));
    ASSERT_EQ('c', is.peek(2));
    ASSERT_EQ(EOF, is.peek(3));
    ASSERT_EQ('a', is.get());
}
示例#28
0
文件: file.c 项目: 340211173/xrdp
/* 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[FILE_MAX_LINE_BYTES];
    char c;
    int in_it;
    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, FILE_MAX_LINE_BYTES);
    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 == '[')
            {
                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, FILE_MAX_LINE_BYTES);
            }
            else if (in_it)
            {
                text[in_it_index] = c;
                in_it_index++;
            }
        }
    }
    else if (len < 0)
    {
        rv = 1;
    }

    free_stream(s);
    return rv;
}
示例#29
0
int DEFAULT_CC
xml_send_error(int client, const char* message)
{
	xmlChar* xmlbuff;
	xmlDocPtr doc;
	xmlNodePtr node;
	struct stream* s;
	int buff_size, size;
	xmlChar* version;
	xmlChar* error;
	xmlChar* msg;


	version = xmlCharStrdup("1.0");
	doc = xmlNewDoc(version);
	if (doc == NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[xml_send_error]: "
				"Unable to create the document");
		xmlFree(version);
		return 0;
	}
	error = xmlCharStrdup("error");
	msg = xmlCharStrdup(message);
	doc->encoding = xmlCharStrdup("UTF-8");
	node = xmlNewNode(NULL, error);
	xmlNodeSetContent(node, msg);
	xmlDocSetRootElement(doc, node);

	xmlDocDumpFormatMemory(doc, &xmlbuff, &buff_size, 1);
	log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[xml_send_error]: "
			"data send : %s",xmlbuff);

	make_stream(s);
	init_stream(s, buff_size + 6);
	out_uint32_be(s,buff_size);
	out_uint8p(s, xmlbuff, buff_size)
	size = s->p - s->data;
	if (g_tcp_can_send(client, 10))
	{
		buff_size = g_tcp_send(client, s->data, size, 0);
	}
	else
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_send_error]: "
				"Unable to send xml response: %s, cause: %s", xmlbuff, strerror(g_get_errno()));
	}
	free_stream(s);
	xmlFreeDoc(doc);
	xmlFree(xmlbuff);
	xmlFree(version);
	xmlFree(error);
	xmlFree(msg);
	return buff_size;
}
示例#30
0
文件: sound.c 项目: OSgenie/xrdp
static int
sound_send_wave_data(char *data, int data_bytes)
{
    struct stream *s;
    int bytes;
    int time;
    char *size_ptr;

    print_got_here();

    if ((data_bytes < 4) || (data_bytes > 128 * 1024))
    {
        LOG(0, ("sound_send_wave_data: bad data_bytes %d", data_bytes));
    }

    /* part one of 2 PDU wave info */

    LOG(10, ("sound_send_wave_data: sending %d bytes", data_bytes));

    make_stream(s);
    init_stream(s, data_bytes);
    out_uint16_le(s, SNDC_WAVE);
    size_ptr = s->p;
    out_uint16_le(s, 0); /* size, set later */
    time = g_time2();
    out_uint16_le(s, time);
    out_uint16_le(s, 0); /* wFormatNo */
    g_cBlockNo++;
    out_uint8(s, g_cBlockNo);

    LOG(10, ("sound_send_wave_data: sending time %d, g_cBlockNo %d",
             time & 0xffff, g_cBlockNo & 0xff));

    out_uint8s(s, 3);
    out_uint8a(s, data, 4);
    s_mark_end(s);
    bytes = (int)((s->end - s->data) - 4);
    bytes += data_bytes;
    bytes -= 4;
    size_ptr[0] = bytes;
    size_ptr[1] = bytes >> 8;
    bytes = (int)(s->end - s->data);
    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);

    /* part two of 2 PDU wave info */
    init_stream(s, data_bytes);
    out_uint32_le(s, 0);
    out_uint8a(s, data + 4, data_bytes - 4);
    s_mark_end(s);
    bytes = (int)(s->end - s->data);
    send_channel_data(g_rdpsnd_chan_id, s->data, bytes);
    free_stream(s);
    return 0;
}