/[rdesktop]/jpeg/rdesktop/trunk/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

Contents of /jpeg/rdesktop/trunk/cliprdr.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1201 - (show annotations)
Mon Mar 27 08:24:41 2006 UTC (18 years, 1 month ago) by ossman_
Original Path: sourceforge.net/trunk/rdesktop/cliprdr.c
File MIME type: text/plain
File size: 4518 byte(s)
More clipboard debug output.

1 /* -*- 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 Copyright (C) Matthew Chapman 2003
6
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 #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
30 #define CLIPRDR_REQUEST 0
31 #define CLIPRDR_RESPONSE 1
32 #define CLIPRDR_ERROR 2
33
34 static VCHANNEL *cliprdr_channel;
35
36 static void
37 cliprdr_send_packet(uint16 type, uint16 status, uint8 * data, uint32 length)
38 {
39 STREAM s;
40
41 DEBUG_CLIPBOARD(("CLIPRDR send: type=%d, status=%d, length=%d\n", type, status, length));
42
43 s = channel_init(cliprdr_channel, length + 12);
44 out_uint16_le(s, type);
45 out_uint16_le(s, status);
46 out_uint32_le(s, length);
47 out_uint8p(s, data, length);
48 out_uint32(s, 0); /* pad? */
49 s_mark_end(s);
50 channel_send(s, cliprdr_channel);
51 }
52
53 /* 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 void
59 cliprdr_send_simple_native_format_announce(uint32 format)
60 {
61 uint8 buffer[36];
62
63 DEBUG_CLIPBOARD(("cliprdr_send_simple_native_format_announce\n"));
64
65 buf_out_uint32(buffer, format);
66 memset(buffer + 4, 0, sizeof(buffer) - 4); /* description */
67 cliprdr_send_native_format_announce(buffer, sizeof(buffer));
68 }
69
70 /* Announces our readiness to supply clipboard data in multiple
71 formats, each denoted by a 36-byte format descriptor of
72 [ uint32 format + 32-byte description ].
73 */
74 void
75 cliprdr_send_native_format_announce(uint8 * formats_data, uint32 formats_data_length)
76 {
77 DEBUG_CLIPBOARD(("cliprdr_send_native_format_announce\n"));
78 cliprdr_send_packet(CLIPRDR_FORMAT_ANNOUNCE, CLIPRDR_REQUEST, formats_data,
79 formats_data_length);
80 }
81
82 void
83 cliprdr_send_data_request(uint32 format)
84 {
85 uint8 buffer[4];
86
87 DEBUG_CLIPBOARD(("cliprdr_send_data_request\n"));
88 buf_out_uint32(buffer, format);
89 cliprdr_send_packet(CLIPRDR_DATA_REQUEST, CLIPRDR_REQUEST, buffer, sizeof(buffer));
90 }
91
92 void
93 cliprdr_send_data(uint8 * data, uint32 length)
94 {
95 DEBUG_CLIPBOARD(("cliprdr_send_data\n"));
96 cliprdr_send_packet(CLIPRDR_DATA_RESPONSE, CLIPRDR_RESPONSE, data, length);
97 }
98
99 static void
100 cliprdr_process(STREAM s)
101 {
102 uint16 type, status;
103 uint32 length, format;
104 uint8 *data;
105
106 in_uint16_le(s, type);
107 in_uint16_le(s, status);
108 in_uint32_le(s, length);
109 data = s->p;
110
111 DEBUG_CLIPBOARD(("CLIPRDR recv: type=%d, status=%d, length=%d\n", type, status, length));
112
113 if (status == CLIPRDR_ERROR)
114 {
115 if (type == CLIPRDR_FORMAT_ACK)
116 {
117 /* FIXME: We seem to get this when we send an announce while the server is
118 still processing a paste. Try sending another announce. */
119 cliprdr_send_simple_native_format_announce(CF_TEXT);
120 return;
121 }
122
123 DEBUG_CLIPBOARD(("CLIPRDR error (type=%d)\n", type));
124 return;
125 }
126
127 switch (type)
128 {
129 case CLIPRDR_CONNECT:
130 ui_clip_sync();
131 break;
132 case CLIPRDR_FORMAT_ANNOUNCE:
133 ui_clip_format_announce(data, length);
134 cliprdr_send_packet(CLIPRDR_FORMAT_ACK, CLIPRDR_RESPONSE, NULL, 0);
135 return;
136 case CLIPRDR_FORMAT_ACK:
137 break;
138 case CLIPRDR_DATA_REQUEST:
139 in_uint32_le(s, format);
140 ui_clip_request_data(format);
141 break;
142 case CLIPRDR_DATA_RESPONSE:
143 ui_clip_handle_data(data, length);
144 break;
145 case 7: /* TODO: W2K3 SP1 sends this on connect with a value of 1 */
146 break;
147 default:
148 unimpl("CLIPRDR packet type %d\n", type);
149 }
150 }
151
152 BOOL
153 cliprdr_init(void)
154 {
155 cliprdr_channel =
156 channel_register("cliprdr",
157 CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
158 CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL,
159 cliprdr_process);
160 return (cliprdr_channel != NULL);
161 }

  ViewVC Help
Powered by ViewVC 1.1.26