/[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

Annotation of /sourceforge.net/branches/seamlessrdp-branch/rdesktop/seamless.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1116 - (hide annotations)
Mon Mar 13 15:04:51 2006 UTC (18 years, 3 months ago) by astrand
File MIME type: text/plain
File size: 5389 byte(s)
Always printing what we are sending, when DEBUG_SEAMLESS is enabled.
Use 0x%08lx instead of 0x%p.

1 astrand 1089 /* -*- 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 astrand 1110 #include <stdarg.h>
23 astrand 1089
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 astrand 1116 DEBUG_SEAMLESS(("seamlessrdp got:%s\n", p));
71 astrand 1089
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 astrand 1090 if (!strcmp("CREATE", tok1))
85 astrand 1089 {
86 astrand 1098 unsigned long parent;
87     if (!tok4)
88 astrand 1089 return False;
89    
90 astrand 1104 id = strtol(tok2, &endptr, 0);
91 astrand 1089 if (*endptr)
92     return False;
93    
94 astrand 1104 parent = strtol(tok3, &endptr, 0);
95 astrand 1089 if (*endptr)
96     return False;
97    
98 astrand 1104 flags = strtol(tok4, &endptr, 0);
99 astrand 1098 if (*endptr)
100     return False;
101    
102     ui_seamless_create_window(id, parent, flags);
103 astrand 1089 }
104 astrand 1090 else if (!strcmp("DESTROY", tok1))
105 astrand 1089 {
106     if (!tok3)
107     return False;
108    
109 astrand 1104 id = strtol(tok2, &endptr, 0);
110 astrand 1089 if (*endptr)
111     return False;
112    
113 astrand 1104 flags = strtol(tok3, &endptr, 0);
114 astrand 1089 if (*endptr)
115     return False;
116    
117     ui_seamless_destroy_window(id, flags);
118    
119     }
120 astrand 1090 else if (!strcmp("SETICON", tok1))
121 astrand 1089 {
122     unimpl("SeamlessRDP SETICON1\n");
123     }
124 astrand 1090 else if (!strcmp("POSITION", tok1))
125 astrand 1089 {
126     int x, y, width, height;
127    
128     if (!tok7)
129     return False;
130    
131 astrand 1104 id = strtol(tok2, &endptr, 0);
132 astrand 1089 if (*endptr)
133     return False;
134    
135 astrand 1104 x = strtol(tok3, &endptr, 0);
136 astrand 1089 if (*endptr)
137     return False;
138 astrand 1104 y = strtol(tok4, &endptr, 0);
139 astrand 1089 if (*endptr)
140     return False;
141    
142 astrand 1104 width = strtol(tok5, &endptr, 0);
143 astrand 1089 if (*endptr)
144     return False;
145 astrand 1104 height = strtol(tok6, &endptr, 0);
146 astrand 1089 if (*endptr)
147     return False;
148    
149 astrand 1104 flags = strtol(tok7, &endptr, 0);
150 astrand 1089 if (*endptr)
151     return False;
152    
153     ui_seamless_move_window(id, x, y, width, height, flags);
154     }
155 astrand 1090 else if (!strcmp("ZCHANGE", tok1))
156 astrand 1089 {
157     unimpl("SeamlessRDP ZCHANGE1\n");
158     }
159 astrand 1094 else if (!strcmp("TITLE", tok1))
160 astrand 1089 {
161 astrand 1094 if (!tok4)
162     return False;
163    
164 astrand 1104 id = strtol(tok2, &endptr, 0);
165 astrand 1094 if (*endptr)
166     return False;
167    
168 astrand 1104 flags = strtol(tok4, &endptr, 0);
169 astrand 1094 if (*endptr)
170     return False;
171    
172     ui_seamless_settitle(id, tok3, flags);
173     }
174     else if (!strcmp("STATE", tok1))
175     {
176 astrand 1089 unsigned int state;
177    
178 astrand 1094 if (!tok4)
179 astrand 1089 return False;
180    
181 astrand 1104 id = strtol(tok2, &endptr, 0);
182 astrand 1089 if (*endptr)
183     return False;
184    
185 astrand 1104 state = strtol(tok3, &endptr, 0);
186 astrand 1089 if (*endptr)
187     return False;
188    
189 astrand 1104 flags = strtol(tok4, &endptr, 0);
190 astrand 1089 if (*endptr)
191     return False;
192    
193     ui_seamless_setstate(id, state, flags);
194     }
195 astrand 1090 else if (!strcmp("DEBUG", tok1))
196 astrand 1089 {
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 astrand 1110 seamless_send(const char *format, ...)
250 astrand 1089 {
251     STREAM s;
252     size_t len;
253 astrand 1110 va_list argp;
254     char buf[1024];
255 astrand 1089
256 astrand 1110 va_start(argp, format);
257     len = vsnprintf(buf, sizeof(buf), format, argp);
258     va_end(argp);
259    
260 astrand 1089 s = channel_init(seamless_channel, len);
261 astrand 1110 out_uint8p(s, buf, len) s_mark_end(s);
262 astrand 1089
263 astrand 1116 DEBUG_SEAMLESS(("SeamlessRDP sending:%s", buf));
264    
265 astrand 1089 #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 astrand 1110
280    
281     void
282     seamless_send_state(unsigned long id, unsigned int state, unsigned long flags)
283     {
284 astrand 1116 seamless_send("STATE,0x%08lx,0x%x,0x%lx\n", id, state, flags);
285 astrand 1110 }

  ViewVC Help
Powered by ViewVC 1.1.26