1 |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
3 |
Seamless Windows support |
4 |
Copyright (C) Peter Astrand <astrand@cendio.se> 2005-2006 |
5 |
|
6 |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
8 |
the Free Software Foundation; either version 2 of the License, or |
9 |
(at your option) any later version. |
10 |
|
11 |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
15 |
|
16 |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
20 |
|
21 |
#include "rdesktop.h" |
22 |
#include <stdarg.h> |
23 |
|
24 |
/* #define WITH_DEBUG_SEAMLESS */ |
25 |
|
26 |
#ifdef WITH_DEBUG_SEAMLESS |
27 |
#define DEBUG_SEAMLESS(args) printf args; |
28 |
#else |
29 |
#define DEBUG_SEAMLESS(args) |
30 |
#endif |
31 |
|
32 |
extern BOOL g_seamless_rdp; |
33 |
static VCHANNEL *seamless_channel; |
34 |
|
35 |
static char * |
36 |
seamless_get_token(char **s) |
37 |
{ |
38 |
char *comma, *head; |
39 |
head = *s; |
40 |
|
41 |
if (!head) |
42 |
return NULL; |
43 |
|
44 |
comma = strchr(head, ','); |
45 |
if (comma) |
46 |
{ |
47 |
*comma = '\0'; |
48 |
*s = comma + 1; |
49 |
} |
50 |
else |
51 |
{ |
52 |
*s = NULL; |
53 |
} |
54 |
|
55 |
return head; |
56 |
} |
57 |
|
58 |
|
59 |
static BOOL |
60 |
seamless_process_line(const char *line, void *data) |
61 |
{ |
62 |
char *p, *l; |
63 |
char *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8; |
64 |
unsigned long id, flags; |
65 |
char *endptr; |
66 |
|
67 |
l = xstrdup(line); |
68 |
p = l; |
69 |
|
70 |
DEBUG_SEAMLESS(("seamlessrdp got:%s\n", p)); |
71 |
|
72 |
if (!g_seamless_rdp) |
73 |
return True; |
74 |
|
75 |
tok1 = seamless_get_token(&p); |
76 |
tok2 = seamless_get_token(&p); |
77 |
tok3 = seamless_get_token(&p); |
78 |
tok4 = seamless_get_token(&p); |
79 |
tok5 = seamless_get_token(&p); |
80 |
tok6 = seamless_get_token(&p); |
81 |
tok7 = seamless_get_token(&p); |
82 |
tok8 = seamless_get_token(&p); |
83 |
|
84 |
if (!strcmp("CREATE", tok1)) |
85 |
{ |
86 |
unsigned long parent; |
87 |
if (!tok4) |
88 |
return False; |
89 |
|
90 |
id = strtoul(tok2, &endptr, 0); |
91 |
if (*endptr) |
92 |
return False; |
93 |
|
94 |
parent = strtoul(tok3, &endptr, 0); |
95 |
if (*endptr) |
96 |
return False; |
97 |
|
98 |
flags = strtoul(tok4, &endptr, 0); |
99 |
if (*endptr) |
100 |
return False; |
101 |
|
102 |
ui_seamless_create_window(id, parent, flags); |
103 |
} |
104 |
else if (!strcmp("DESTROY", tok1)) |
105 |
{ |
106 |
if (!tok3) |
107 |
return False; |
108 |
|
109 |
id = strtoul(tok2, &endptr, 0); |
110 |
if (*endptr) |
111 |
return False; |
112 |
|
113 |
flags = strtoul(tok3, &endptr, 0); |
114 |
if (*endptr) |
115 |
return False; |
116 |
|
117 |
ui_seamless_destroy_window(id, flags); |
118 |
|
119 |
} |
120 |
else if (!strcmp("SETICON", tok1)) |
121 |
{ |
122 |
unimpl("SeamlessRDP SETICON1\n"); |
123 |
} |
124 |
else if (!strcmp("POSITION", tok1)) |
125 |
{ |
126 |
int x, y, width, height; |
127 |
|
128 |
if (!tok7) |
129 |
return False; |
130 |
|
131 |
id = strtoul(tok2, &endptr, 0); |
132 |
if (*endptr) |
133 |
return False; |
134 |
|
135 |
x = strtol(tok3, &endptr, 0); |
136 |
if (*endptr) |
137 |
return False; |
138 |
y = strtol(tok4, &endptr, 0); |
139 |
if (*endptr) |
140 |
return False; |
141 |
|
142 |
width = strtol(tok5, &endptr, 0); |
143 |
if (*endptr) |
144 |
return False; |
145 |
height = strtol(tok6, &endptr, 0); |
146 |
if (*endptr) |
147 |
return False; |
148 |
|
149 |
flags = strtoul(tok7, &endptr, 0); |
150 |
if (*endptr) |
151 |
return False; |
152 |
|
153 |
ui_seamless_move_window(id, x, y, width, height, flags); |
154 |
} |
155 |
else if (!strcmp("ZCHANGE", tok1)) |
156 |
{ |
157 |
unimpl("SeamlessRDP ZCHANGE1\n"); |
158 |
} |
159 |
else if (!strcmp("TITLE", tok1)) |
160 |
{ |
161 |
if (!tok4) |
162 |
return False; |
163 |
|
164 |
id = strtoul(tok2, &endptr, 0); |
165 |
if (*endptr) |
166 |
return False; |
167 |
|
168 |
flags = strtoul(tok4, &endptr, 0); |
169 |
if (*endptr) |
170 |
return False; |
171 |
|
172 |
ui_seamless_settitle(id, tok3, flags); |
173 |
} |
174 |
else if (!strcmp("STATE", tok1)) |
175 |
{ |
176 |
unsigned int state; |
177 |
|
178 |
if (!tok4) |
179 |
return False; |
180 |
|
181 |
id = strtoul(tok2, &endptr, 0); |
182 |
if (*endptr) |
183 |
return False; |
184 |
|
185 |
state = strtoul(tok3, &endptr, 0); |
186 |
if (*endptr) |
187 |
return False; |
188 |
|
189 |
flags = strtoul(tok4, &endptr, 0); |
190 |
if (*endptr) |
191 |
return False; |
192 |
|
193 |
ui_seamless_setstate(id, state, flags); |
194 |
} |
195 |
else if (!strcmp("DEBUG", tok1)) |
196 |
{ |
197 |
printf("SeamlessRDP:%s\n", line); |
198 |
} |
199 |
else if (!strcmp("SYNCBEGIN", tok1)) |
200 |
{ |
201 |
if (!tok2) |
202 |
return False; |
203 |
|
204 |
flags = strtoul(tok2, &endptr, 0); |
205 |
if (*endptr) |
206 |
return False; |
207 |
|
208 |
ui_seamless_syncbegin(flags); |
209 |
} |
210 |
else if (!strcmp("SYNCEND", tok1)) |
211 |
{ |
212 |
if (!tok2) |
213 |
return False; |
214 |
|
215 |
flags = strtoul(tok2, &endptr, 0); |
216 |
if (*endptr) |
217 |
return False; |
218 |
|
219 |
/* do nothing, currently */ |
220 |
} |
221 |
|
222 |
|
223 |
xfree(l); |
224 |
return True; |
225 |
} |
226 |
|
227 |
|
228 |
static BOOL |
229 |
seamless_line_handler(const char *line, void *data) |
230 |
{ |
231 |
if (!seamless_process_line(line, data)) |
232 |
{ |
233 |
warning("SeamlessRDP: Invalid request:%s\n", line); |
234 |
} |
235 |
return True; |
236 |
} |
237 |
|
238 |
|
239 |
static void |
240 |
seamless_process(STREAM s) |
241 |
{ |
242 |
unsigned int pkglen; |
243 |
static char *rest = NULL; |
244 |
char *buf; |
245 |
|
246 |
pkglen = s->end - s->p; |
247 |
/* str_handle_lines requires null terminated strings */ |
248 |
buf = xmalloc(pkglen + 1); |
249 |
STRNCPY(buf, (char *) s->p, pkglen + 1); |
250 |
#if 0 |
251 |
printf("seamless recv:\n"); |
252 |
hexdump(s->p, pkglen); |
253 |
#endif |
254 |
|
255 |
str_handle_lines(buf, &rest, seamless_line_handler, NULL); |
256 |
|
257 |
xfree(buf); |
258 |
} |
259 |
|
260 |
|
261 |
BOOL |
262 |
seamless_init(void) |
263 |
{ |
264 |
seamless_channel = |
265 |
channel_register("seamrdp", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP, |
266 |
seamless_process); |
267 |
return (seamless_channel != NULL); |
268 |
} |
269 |
|
270 |
|
271 |
static void |
272 |
seamless_send(const char *format, ...) |
273 |
{ |
274 |
STREAM s; |
275 |
size_t len; |
276 |
va_list argp; |
277 |
char buf[1024]; |
278 |
|
279 |
va_start(argp, format); |
280 |
len = vsnprintf(buf, sizeof(buf), format, argp); |
281 |
va_end(argp); |
282 |
|
283 |
s = channel_init(seamless_channel, len); |
284 |
out_uint8p(s, buf, len) s_mark_end(s); |
285 |
|
286 |
DEBUG_SEAMLESS(("SeamlessRDP sending:%s", buf)); |
287 |
|
288 |
#if 0 |
289 |
printf("seamless send:\n"); |
290 |
hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); |
291 |
#endif |
292 |
|
293 |
channel_send(s, seamless_channel); |
294 |
} |
295 |
|
296 |
|
297 |
void |
298 |
seamless_send_sync() |
299 |
{ |
300 |
seamless_send("SYNC\n"); |
301 |
} |
302 |
|
303 |
|
304 |
void |
305 |
seamless_send_state(unsigned long id, unsigned int state, unsigned long flags) |
306 |
{ |
307 |
seamless_send("STATE,0x%08lx,0x%x,0x%lx\n", id, state, flags); |
308 |
} |