/[rdesktop]/sourceforge.net/trunk/rdesktop/cliprdr.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sourceforge.net/trunk/rdesktop/cliprdr.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1025 - (hide annotations)
Mon Nov 7 13:15:19 2005 UTC (18 years, 7 months ago) by forsberg
File MIME type: text/plain
File size: 4287 byte(s)
Applied patch 1349027 by Ilya Konstantinov.

Generalizes code for sending clipboard format announces to RDP side,
and uses new code in appropriate places.

1 forsberg 383 /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - Clipboard functions
4     Copyright (C) Erik Forsberg <forsberg@cendio.se> 2003
5 matthewc 432 Copyright (C) Matthew Chapman 2003
6 forsberg 383
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20     */
21    
22     #include "rdesktop.h"
23    
24 matthewc 432 #define CLIPRDR_CONNECT 1
25     #define CLIPRDR_FORMAT_ANNOUNCE 2
26     #define CLIPRDR_FORMAT_ACK 3
27     #define CLIPRDR_DATA_REQUEST 4
28     #define CLIPRDR_DATA_RESPONSE 5
29 forsberg 383
30 matthewc 432 #define CLIPRDR_REQUEST 0
31     #define CLIPRDR_RESPONSE 1
32     #define CLIPRDR_ERROR 2
33 forsberg 383
34 matthewc 432 static VCHANNEL *cliprdr_channel;
35 forsberg 396
36 forsberg 386 static void
37 astrand 435 cliprdr_send_packet(uint16 type, uint16 status, uint8 * data, uint32 length)
38 forsberg 387 {
39 forsberg 395 STREAM s;
40 forsberg 387
41 matthewc 432 DEBUG_CLIPBOARD(("CLIPRDR send: type=%d, status=%d, length=%d\n", type, status, length));
42 forsberg 387
43 matthewc 432 s = channel_init(cliprdr_channel, length + 12);
44     out_uint16_le(s, type);
45     out_uint16_le(s, status);
46 forsberg 394 out_uint32_le(s, length);
47     out_uint8p(s, data, length);
48 astrand 435 out_uint32(s, 0); /* pad? */
49 forsberg 394 s_mark_end(s);
50 matthewc 432 channel_send(s, cliprdr_channel);
51 forsberg 394 }
52    
53 forsberg 1025 /* Helper which announces our readiness to supply clipboard data
54     in a single format (such as CF_TEXT) to the RDP side.
55     To announce more than one format at a time, use
56     cliprdr_send_native_format_announce.
57     */
58 matthewc 432 void
59 forsberg 1025 cliprdr_send_simple_native_format_announce(uint32 format)
60 forsberg 386 {
61 matthewc 432 uint8 buffer[36];
62 forsberg 396
63 forsberg 1025 buf_out_uint32(buffer, format);
64 astrand 435 memset(buffer + 4, 0, sizeof(buffer) - 4); /* description */
65 forsberg 1025 cliprdr_send_native_format_announce(buffer, sizeof(buffer));
66 forsberg 386 }
67    
68 forsberg 1025 /* Announces our readiness to supply clipboard data in multiple
69     formats, each denoted by a 36-byte format descriptor of
70     [ uint32 format + 32-byte description ].
71     */
72 forsberg 396 void
73 forsberg 1025 cliprdr_send_native_format_announce(uint8 * formats_data, uint32 formats_data_length)
74 forsberg 383 {
75 forsberg 1025 cliprdr_send_packet(CLIPRDR_FORMAT_ANNOUNCE, CLIPRDR_REQUEST, formats_data, formats_data_length);
76 forsberg 383 }
77    
78     void
79 matthewc 432 cliprdr_send_data_request(uint32 format)
80 forsberg 384 {
81 matthewc 432 uint8 buffer[4];
82 forsberg 384
83 matthewc 432 buf_out_uint32(buffer, format);
84     cliprdr_send_packet(CLIPRDR_DATA_REQUEST, CLIPRDR_REQUEST, buffer, sizeof(buffer));
85 forsberg 384 }
86    
87 forsberg 383 void
88 astrand 435 cliprdr_send_data(uint8 * data, uint32 length)
89 forsberg 383 {
90 matthewc 432 cliprdr_send_packet(CLIPRDR_DATA_RESPONSE, CLIPRDR_RESPONSE, data, length);
91 forsberg 384 }
92 forsberg 383
93 forsberg 396 static void
94 matthewc 432 cliprdr_process(STREAM s)
95 forsberg 384 {
96 matthewc 432 uint16 type, status;
97     uint32 length, format;
98 matthewc 536 uint8 *data;
99 forsberg 384
100 matthewc 432 in_uint16_le(s, type);
101     in_uint16_le(s, status);
102     in_uint32_le(s, length);
103     data = s->p;
104 forsberg 384
105 matthewc 432 DEBUG_CLIPBOARD(("CLIPRDR recv: type=%d, status=%d, length=%d\n", type, status, length));
106 forsberg 383
107 matthewc 432 if (status == CLIPRDR_ERROR)
108 forsberg 396 {
109 matthewc 432 if (type == CLIPRDR_FORMAT_ACK)
110 forsberg 396 {
111 matthewc 432 /* FIXME: We seem to get this when we send an announce while the server is
112     still processing a paste. Try sending another announce. */
113 forsberg 1025 cliprdr_send_simple_native_format_announce(CF_TEXT);
114 matthewc 432 return;
115 forsberg 383 }
116    
117 stargo 556 DEBUG_CLIPBOARD(("CLIPRDR error (type=%d)\n", type));
118 forsberg 392 return;
119 forsberg 396 }
120 forsberg 392
121 matthewc 432 switch (type)
122 forsberg 392 {
123 matthewc 432 case CLIPRDR_CONNECT:
124     ui_clip_sync();
125     break;
126     case CLIPRDR_FORMAT_ANNOUNCE:
127     ui_clip_format_announce(data, length);
128     cliprdr_send_packet(CLIPRDR_FORMAT_ACK, CLIPRDR_RESPONSE, NULL, 0);
129 forsberg 383 return;
130 matthewc 432 case CLIPRDR_FORMAT_ACK:
131     break;
132     case CLIPRDR_DATA_REQUEST:
133     in_uint32_le(s, format);
134     ui_clip_request_data(format);
135     break;
136     case CLIPRDR_DATA_RESPONSE:
137     ui_clip_handle_data(data, length);
138     break;
139 stargo 885 case 7: /* TODO: W2K3 SP1 sends this on connect with a value of 1 */
140     break;
141 matthewc 432 default:
142     unimpl("CLIPRDR packet type %d\n", type);
143 forsberg 396 }
144 forsberg 383 }
145    
146 matthewc 432 BOOL
147 forsberg 396 cliprdr_init(void)
148 forsberg 383 {
149 astrand 435 cliprdr_channel =
150     channel_register("cliprdr",
151     CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
152     CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL,
153     cliprdr_process);
154 matthewc 432 return (cliprdr_channel != NULL);
155 forsberg 383 }

  ViewVC Help
Powered by ViewVC 1.1.26