/* Output a string in Unicode */ void uni_rdp_out_str(struct stream* s, char *string, int len) { #ifdef HAVE_ICONV size_t ibl = strlen(string) + 1, obl = len ; static iconv_t iconv_h = (iconv_t) - 1; char *pin = string, *pout = (char *) s->p; memset(pout, 0, len + 4); if (g_iconv_works) { if (iconv_h == (iconv_t) - 1) { if ((iconv_h = iconv_open(WINDOWS_CODEPAGE, DEFAULT_CODEPAGE)) == (iconv_t) - 1) { printf("rdp_out_unistr: iconv_open[%s -> %s] fail %p\n", DEFAULT_CODEPAGE, WINDOWS_CODEPAGE, iconv_h); g_iconv_works = 0; uni_rdp_out_str(s, string, len); return; } pin = string; pout = (char *) s->p; } if (iconv(iconv_h, (ICONV_CONST char **) &pin, &ibl, &pout, &obl) == (size_t) - 1) { iconv_close(iconv_h); iconv_h = (iconv_t) - 1; printf("rdp_out_unistr: iconv(1) fail, errno %d %s\n", errno, strerror(errno)); g_iconv_works = 0; uni_rdp_out_str(s, string, len); return; } s->p += len; } else #endif { int i = 0, j = 0; while (i < len) { s->p[i++] = string[j++]; s->p[i++] = 0; } s->p += len; } }
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); }