/[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 1104 - (show annotations)
Fri Mar 10 13:34:41 2006 UTC (18 years, 3 months ago) by astrand
File MIME type: text/plain
File size: 5063 byte(s)
Always call strtol with zero base, to be tolerant

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
23 /* #define WITH_DEBUG_SEAMLESS */
24
25 #ifdef WITH_DEBUG_SEAMLESS
26 #define DEBUG_SEAMLESS(args) printf args;
27 #else
28 #define DEBUG_SEAMLESS(args)
29 #endif
30
31 extern BOOL g_seamless_rdp;
32 static VCHANNEL *seamless_channel;
33
34 static char *
35 seamless_get_token(char **s)
36 {
37 char *comma, *head;
38 head = *s;
39
40 if (!head)
41 return NULL;
42
43 comma = strchr(head, ',');
44 if (comma)
45 {
46 *comma = '\0';
47 *s = comma + 1;
48 }
49 else
50 {
51 *s = NULL;
52 }
53
54 return head;
55 }
56
57
58 static BOOL
59 seamless_process_line(const char *line, void *data)
60 {
61 char *p, *l;
62 char *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8;
63 unsigned long id, flags;
64 char *endptr;
65
66 l = xstrdup(line);
67 p = l;
68
69 DEBUG_SEAMLESS(("seamlessrdp line:%s\n", p));
70
71 if (!g_seamless_rdp)
72 return True;
73
74 tok1 = seamless_get_token(&p);
75 tok2 = seamless_get_token(&p);
76 tok3 = seamless_get_token(&p);
77 tok4 = seamless_get_token(&p);
78 tok5 = seamless_get_token(&p);
79 tok6 = seamless_get_token(&p);
80 tok7 = seamless_get_token(&p);
81 tok8 = seamless_get_token(&p);
82
83 if (!strcmp("CREATE", tok1))
84 {
85 unsigned long parent;
86 if (!tok4)
87 return False;
88
89 id = strtol(tok2, &endptr, 0);
90 if (*endptr)
91 return False;
92
93 parent = strtol(tok3, &endptr, 0);
94 if (*endptr)
95 return False;
96
97 flags = strtol(tok4, &endptr, 0);
98 if (*endptr)
99 return False;
100
101 ui_seamless_create_window(id, parent, flags);
102 }
103 else if (!strcmp("DESTROY", tok1))
104 {
105 if (!tok3)
106 return False;
107
108 id = strtol(tok2, &endptr, 0);
109 if (*endptr)
110 return False;
111
112 flags = strtol(tok3, &endptr, 0);
113 if (*endptr)
114 return False;
115
116 ui_seamless_destroy_window(id, flags);
117
118 }
119 else if (!strcmp("SETICON", tok1))
120 {
121 unimpl("SeamlessRDP SETICON1\n");
122 }
123 else if (!strcmp("POSITION", tok1))
124 {
125 int x, y, width, height;
126
127 if (!tok7)
128 return False;
129
130 id = strtol(tok2, &endptr, 0);
131 if (*endptr)
132 return False;
133
134 x = strtol(tok3, &endptr, 0);
135 if (*endptr)
136 return False;
137 y = strtol(tok4, &endptr, 0);
138 if (*endptr)
139 return False;
140
141 width = strtol(tok5, &endptr, 0);
142 if (*endptr)
143 return False;
144 height = strtol(tok6, &endptr, 0);
145 if (*endptr)
146 return False;
147
148 flags = strtol(tok7, &endptr, 0);
149 if (*endptr)
150 return False;
151
152 ui_seamless_move_window(id, x, y, width, height, flags);
153 }
154 else if (!strcmp("ZCHANGE", tok1))
155 {
156 unimpl("SeamlessRDP ZCHANGE1\n");
157 }
158 else if (!strcmp("TITLE", tok1))
159 {
160 if (!tok4)
161 return False;
162
163 id = strtol(tok2, &endptr, 0);
164 if (*endptr)
165 return False;
166
167 flags = strtol(tok4, &endptr, 0);
168 if (*endptr)
169 return False;
170
171 ui_seamless_settitle(id, tok3, flags);
172 }
173 else if (!strcmp("STATE", tok1))
174 {
175 unsigned int state;
176
177 if (!tok4)
178 return False;
179
180 id = strtol(tok2, &endptr, 0);
181 if (*endptr)
182 return False;
183
184 state = strtol(tok3, &endptr, 0);
185 if (*endptr)
186 return False;
187
188 flags = strtol(tok4, &endptr, 0);
189 if (*endptr)
190 return False;
191
192 ui_seamless_setstate(id, state, flags);
193 }
194 else if (!strcmp("DEBUG", tok1))
195 {
196 printf("SeamlessRDP:%s\n", line);
197 }
198
199 xfree(l);
200 return True;
201 }
202
203
204 static BOOL
205 seamless_line_handler(const char *line, void *data)
206 {
207 if (!seamless_process_line(line, data))
208 {
209 warning("SeamlessRDP: Invalid request:%s\n", line);
210 }
211 return True;
212 }
213
214
215 static void
216 seamless_process(STREAM s)
217 {
218 unsigned int pkglen;
219 static char *rest = NULL;
220 char *buf;
221
222 pkglen = s->end - s->p;
223 /* str_handle_lines requires null terminated strings */
224 buf = xmalloc(pkglen + 1);
225 STRNCPY(buf, (char *) s->p, pkglen + 1);
226 #if 0
227 printf("seamless recv:\n");
228 hexdump(s->p, pkglen);
229 #endif
230
231 str_handle_lines(buf, &rest, seamless_line_handler, NULL);
232
233 xfree(buf);
234 }
235
236
237 BOOL
238 seamless_init(void)
239 {
240 seamless_channel =
241 channel_register("seamrdp", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
242 seamless_process);
243 return (seamless_channel != NULL);
244 }
245
246
247 static void
248 seamless_send(const char *output)
249 {
250 STREAM s;
251 size_t len;
252
253 len = strlen(output);
254 s = channel_init(seamless_channel, len);
255 out_uint8p(s, output, len) s_mark_end(s);
256
257 #if 0
258 printf("seamless send:\n");
259 hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8);
260 #endif
261
262 channel_send(s, seamless_channel);
263 }
264
265
266 void
267 seamless_send_sync()
268 {
269 seamless_send("SYNC\n");
270 }

  ViewVC Help
Powered by ViewVC 1.1.26