/[rdesktop]/sourceforge.net/branches/seamlessrdp-branch/rdesktop/seamless.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 /sourceforge.net/branches/seamlessrdp-branch/rdesktop/seamless.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1121 - (show annotations)
Wed Mar 15 08:18:05 2006 UTC (18 years, 3 months ago) by astrand
File MIME type: text/plain
File size: 5405 byte(s)
Changed strtoll/strtol to strtoul.

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 = strtoul(tok3, &endptr, 0);
136 if (*endptr)
137 return False;
138 y = strtoul(tok4, &endptr, 0);
139 if (*endptr)
140 return False;
141
142 width = strtoul(tok5, &endptr, 0);
143 if (*endptr)
144 return False;
145 height = strtoul(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
200 xfree(l);
201 return True;
202 }
203
204
205 static BOOL
206 seamless_line_handler(const char *line, void *data)
207 {
208 if (!seamless_process_line(line, data))
209 {
210 warning("SeamlessRDP: Invalid request:%s\n", line);
211 }
212 return True;
213 }
214
215
216 static void
217 seamless_process(STREAM s)
218 {
219 unsigned int pkglen;
220 static char *rest = NULL;
221 char *buf;
222
223 pkglen = s->end - s->p;
224 /* str_handle_lines requires null terminated strings */
225 buf = xmalloc(pkglen + 1);
226 STRNCPY(buf, (char *) s->p, pkglen + 1);
227 #if 0
228 printf("seamless recv:\n");
229 hexdump(s->p, pkglen);
230 #endif
231
232 str_handle_lines(buf, &rest, seamless_line_handler, NULL);
233
234 xfree(buf);
235 }
236
237
238 BOOL
239 seamless_init(void)
240 {
241 seamless_channel =
242 channel_register("seamrdp", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
243 seamless_process);
244 return (seamless_channel != NULL);
245 }
246
247
248 static void
249 seamless_send(const char *format, ...)
250 {
251 STREAM s;
252 size_t len;
253 va_list argp;
254 char buf[1024];
255
256 va_start(argp, format);
257 len = vsnprintf(buf, sizeof(buf), format, argp);
258 va_end(argp);
259
260 s = channel_init(seamless_channel, len);
261 out_uint8p(s, buf, len) s_mark_end(s);
262
263 DEBUG_SEAMLESS(("SeamlessRDP sending:%s", buf));
264
265 #if 0
266 printf("seamless send:\n");
267 hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8);
268 #endif
269
270 channel_send(s, seamless_channel);
271 }
272
273
274 void
275 seamless_send_sync()
276 {
277 seamless_send("SYNC\n");
278 }
279
280
281 void
282 seamless_send_state(unsigned long id, unsigned int state, unsigned long flags)
283 {
284 seamless_send("STATE,0x%08lx,0x%x,0x%lx\n", id, state, flags);
285 }

  ViewVC Help
Powered by ViewVC 1.1.26