/[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 1211 - (hide annotations)
Mon Mar 27 12:29:29 2006 UTC (18 years, 2 months ago) by ossman_
File MIME type: text/plain
File size: 5036 byte(s)
Handle when server sends a failure back for a clipboard request.

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 ossman_ 1202 static uint8 *last_formats = NULL;
37     static uint32 last_formats_length = 0;
38    
39 forsberg 386 static void
40 astrand 435 cliprdr_send_packet(uint16 type, uint16 status, uint8 * data, uint32 length)
41 forsberg 387 {
42 forsberg 395 STREAM s;
43 forsberg 387
44 matthewc 432 DEBUG_CLIPBOARD(("CLIPRDR send: type=%d, status=%d, length=%d\n", type, status, length));
45 forsberg 387
46 matthewc 432 s = channel_init(cliprdr_channel, length + 12);
47     out_uint16_le(s, type);
48     out_uint16_le(s, status);
49 forsberg 394 out_uint32_le(s, length);
50     out_uint8p(s, data, length);
51 astrand 435 out_uint32(s, 0); /* pad? */
52 forsberg 394 s_mark_end(s);
53 matthewc 432 channel_send(s, cliprdr_channel);
54 forsberg 394 }
55    
56 forsberg 1025 /* Helper which announces our readiness to supply clipboard data
57     in a single format (such as CF_TEXT) to the RDP side.
58     To announce more than one format at a time, use
59     cliprdr_send_native_format_announce.
60     */
61 matthewc 432 void
62 forsberg 1025 cliprdr_send_simple_native_format_announce(uint32 format)
63 forsberg 386 {
64 matthewc 432 uint8 buffer[36];
65 forsberg 396
66 ossman_ 1201 DEBUG_CLIPBOARD(("cliprdr_send_simple_native_format_announce\n"));
67    
68 forsberg 1025 buf_out_uint32(buffer, format);
69 astrand 435 memset(buffer + 4, 0, sizeof(buffer) - 4); /* description */
70 forsberg 1025 cliprdr_send_native_format_announce(buffer, sizeof(buffer));
71 forsberg 386 }
72    
73 forsberg 1025 /* Announces our readiness to supply clipboard data in multiple
74     formats, each denoted by a 36-byte format descriptor of
75     [ uint32 format + 32-byte description ].
76     */
77 forsberg 396 void
78 forsberg 1025 cliprdr_send_native_format_announce(uint8 * formats_data, uint32 formats_data_length)
79 forsberg 383 {
80 ossman_ 1201 DEBUG_CLIPBOARD(("cliprdr_send_native_format_announce\n"));
81 ossman_ 1202
82 astrand 1028 cliprdr_send_packet(CLIPRDR_FORMAT_ANNOUNCE, CLIPRDR_REQUEST, formats_data,
83     formats_data_length);
84 ossman_ 1202
85     if (formats_data != last_formats)
86     {
87     if (last_formats)
88     xfree(last_formats);
89    
90     last_formats = xmalloc(formats_data_length);
91     memcpy(last_formats, formats_data, formats_data_length);
92     last_formats_length = formats_data_length;
93     }
94 forsberg 383 }
95    
96     void
97 matthewc 432 cliprdr_send_data_request(uint32 format)
98 forsberg 384 {
99 matthewc 432 uint8 buffer[4];
100 forsberg 384
101 ossman_ 1201 DEBUG_CLIPBOARD(("cliprdr_send_data_request\n"));
102 matthewc 432 buf_out_uint32(buffer, format);
103     cliprdr_send_packet(CLIPRDR_DATA_REQUEST, CLIPRDR_REQUEST, buffer, sizeof(buffer));
104 forsberg 384 }
105    
106 forsberg 383 void
107 astrand 435 cliprdr_send_data(uint8 * data, uint32 length)
108 forsberg 383 {
109 ossman_ 1201 DEBUG_CLIPBOARD(("cliprdr_send_data\n"));
110 matthewc 432 cliprdr_send_packet(CLIPRDR_DATA_RESPONSE, CLIPRDR_RESPONSE, data, length);
111 forsberg 384 }
112 forsberg 383
113 forsberg 396 static void
114 matthewc 432 cliprdr_process(STREAM s)
115 forsberg 384 {
116 matthewc 432 uint16 type, status;
117     uint32 length, format;
118 matthewc 536 uint8 *data;
119 forsberg 384
120 matthewc 432 in_uint16_le(s, type);
121     in_uint16_le(s, status);
122     in_uint32_le(s, length);
123     data = s->p;
124 forsberg 384
125 matthewc 432 DEBUG_CLIPBOARD(("CLIPRDR recv: type=%d, status=%d, length=%d\n", type, status, length));
126 forsberg 383
127 matthewc 432 if (status == CLIPRDR_ERROR)
128 forsberg 396 {
129 ossman_ 1211 switch (type)
130 forsberg 396 {
131 ossman_ 1211 case CLIPRDR_FORMAT_ACK:
132     /* FIXME: We seem to get this when we send an announce while the server is
133     still processing a paste. Try sending another announce. */
134     cliprdr_send_native_format_announce(last_formats,
135     last_formats_length);
136     break;
137     case CLIPRDR_DATA_RESPONSE:
138     ui_clip_request_failed();
139     break;
140     default:
141     DEBUG_CLIPBOARD(("CLIPRDR error (type=%d)\n", type));
142 forsberg 383 }
143    
144 forsberg 392 return;
145 forsberg 396 }
146 forsberg 392
147 matthewc 432 switch (type)
148 forsberg 392 {
149 matthewc 432 case CLIPRDR_CONNECT:
150     ui_clip_sync();
151     break;
152     case CLIPRDR_FORMAT_ANNOUNCE:
153     ui_clip_format_announce(data, length);
154     cliprdr_send_packet(CLIPRDR_FORMAT_ACK, CLIPRDR_RESPONSE, NULL, 0);
155 forsberg 383 return;
156 matthewc 432 case CLIPRDR_FORMAT_ACK:
157     break;
158     case CLIPRDR_DATA_REQUEST:
159     in_uint32_le(s, format);
160     ui_clip_request_data(format);
161     break;
162     case CLIPRDR_DATA_RESPONSE:
163     ui_clip_handle_data(data, length);
164     break;
165 stargo 885 case 7: /* TODO: W2K3 SP1 sends this on connect with a value of 1 */
166     break;
167 matthewc 432 default:
168     unimpl("CLIPRDR packet type %d\n", type);
169 forsberg 396 }
170 forsberg 383 }
171    
172 ossman_ 1207 void
173     cliprdr_set_mode(const char *optarg)
174     {
175     ui_clip_set_mode(optarg);
176     }
177    
178 matthewc 432 BOOL
179 forsberg 396 cliprdr_init(void)
180 forsberg 383 {
181 astrand 435 cliprdr_channel =
182     channel_register("cliprdr",
183     CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP |
184     CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL,
185     cliprdr_process);
186 matthewc 432 return (cliprdr_channel != NULL);
187 forsberg 383 }

  ViewVC Help
Powered by ViewVC 1.1.26