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

Diff of /sourceforge.net/trunk/rdesktop/cliprdr.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 383 by forsberg, Fri Jun 6 09:20:53 2003 UTC revision 385 by forsberg, Fri Jun 6 09:23:28 2003 UTC
# Line 30  extern Time last_keyrelease; Line 30  extern Time last_keyrelease;
30  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;
31  static cliprdr_dataformat *server_formats = NULL;  static cliprdr_dataformat *server_formats = NULL;
32  static uint16 num_server_formats = 0;  static uint16 num_server_formats = 0;
33    static XSelectionEvent selection_event;
34    
35  static void  static void
36  cliprdr_print_server_formats(void)  cliprdr_print_server_formats(void)
# Line 45  cliprdr_print_server_formats(void) Line 46  cliprdr_print_server_formats(void)
46                  i++;                  i++;
47                  this = this->next;                  this = this->next;
48          }          }
49          DEBUG_CLIPBOARD(("There was %d server formats.\n", i));          DEBUG_CLIPBOARD(("There were %d server formats.\n", i));
50  #endif  #endif
51  }  }
52    
# Line 89  void print_X_error(int res) Line 90  void print_X_error(int res)
90                  break;                  break;
91    
92          case BadWindow:          case BadWindow:
93                  DEBUG_CLIPBOARD(("BadWindo\n"));                  DEBUG_CLIPBOARD(("BadWindow\n"));
94                  break;                  break;
95    
96          default:          default:
# Line 97  void print_X_error(int res) Line 98  void print_X_error(int res)
98          }          }
99  }  }
100    
101    static void
102    cliprdr_request_clipboard_data(uint32 formatcode)
103    {
104            STREAM s;
105            s = sec_init(encryption ? SEC_ENCRYPT : 0, 24);
106            out_uint32_le(s, 16);
107            out_uint32_le(s, 0x13);
108            out_uint16_le(s, 4);
109            out_uint16_le(s, 0);
110            out_uint32_le(s, 4); // Remaining length
111            out_uint32_le(s, formatcode);
112            out_uint32_le(s, 0); // Unknown. Garbage pad?
113    
114            s_mark_end(s);
115    
116            sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!
117    }
118    
119    
120  void  void
121  cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent)  cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent)
122  {  {
123    
         Atom type_return;  
124          Atom *targets;          Atom *targets;
         int format_return;  
         long nitems_return;  
         long bytes_after_return;  
         char **prop_return;  
125          int res;          int res;
126    
127          XSelectionEvent xev;          XSelectionEvent xev;
128          DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n"));          DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n"));
129          DEBUG_CLIPBOARD(("Requestor window id 0x%x ", xevent->requestor));          DEBUG_CLIPBOARD(("Requestor window id 0x%x ",
130                             (unsigned)xevent->requestor));
131          if (clipboard_atom == xevent->selection) {          if (clipboard_atom == xevent->selection) {
132                  DEBUG_CLIPBOARD(("wants CLIPBOARD\n"));                  DEBUG_CLIPBOARD(("wants CLIPBOARD\n"));
133          }          }
# Line 120  cliprdr_handle_SelectionRequest(XSelecti Line 136  cliprdr_handle_SelectionRequest(XSelecti
136          }            }  
137          DEBUG_CLIPBOARD(("Target is %s (0x%x), property is %s (0x%x)\n",          DEBUG_CLIPBOARD(("Target is %s (0x%x), property is %s (0x%x)\n",
138                           XGetAtomName(display, xevent->target),                           XGetAtomName(display, xevent->target),
139                           xevent->target,                           (unsigned)xevent->target,
140                           XGetAtomName(display, xevent->property),                           XGetAtomName(display, xevent->property),
141                           xevent->property));                           (unsigned)xevent->property));
142    
143          xev.type = SelectionNotify;          xev.type = SelectionNotify;
144          xev.serial = 0;          xev.serial = 0;
# Line 161  cliprdr_handle_SelectionRequest(XSelecti Line 177  cliprdr_handle_SelectionRequest(XSelecti
177          } else if (timestamp_atom == xevent->target)          } else if (timestamp_atom == xevent->target)
178          {          {
179                  DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n",                  DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n",
180                                   last_keyrelease));                                   (unsigned)last_keyrelease));
181                  res = XChangeProperty(display,                  res = XChangeProperty(display,
182                                        xevent->requestor,                                        xevent->requestor,
183                                        xevent->property,                                        xevent->property,
# Line 177  cliprdr_handle_SelectionRequest(XSelecti Line 193  cliprdr_handle_SelectionRequest(XSelecti
193                                   (XEvent *)&xev);                                   (XEvent *)&xev);
194          } else /* Some other target */          } else /* Some other target */
195          {          {
196                  res = XChangeProperty(display,                  cliprdr_request_clipboard_data(CF_TEXT);
197                                        xevent->requestor,                  memcpy(&selection_event, &xev, sizeof(xev));
198                                        xevent->property,                  /* Return and wait for data, handled by
199                                        XInternAtom(display, "STRING", False),                     cliprdr_handle_server_data */
200                                        8,          }
201                                        PropModeAppend,  }
                                       "krattoflabkat",  
                                       13);  
202    
                 DEBUG_CLIPBOARD(("res after XChangeProperty is "));  
                 print_X_error(res);      
           
                 xev.type = SelectionNotify;  
                 xev.serial = 0;  
                 xev.send_event = True;  
                 xev.requestor = xevent->requestor;  
                 xev.selection = xevent->selection;  
                 xev.target = xevent->target;  
                 xev.property = xevent->property;  
                 xev.time = xevent->time;  
203    
204                  res = XSendEvent(display,  static void
205                                   xevent->requestor,  cliprdr_ack_format_list(void)
206                                   False,  {
207                                   NoEventMask,          STREAM s;
208                                   (XEvent *)&xev);          s = sec_init(encryption ? SEC_ENCRYPT : 0, 20);
209                    out_uint32_le(s, 12);
210                  DEBUG_CLIPBOARD(("res after XSendEvent is "));          out_uint32_le(s, 0x13);
211                  print_X_error(res);          out_uint16_le(s, 3);
212          }          out_uint16_le(s, 1);
213            out_uint32_le(s, 0);
214            out_uint32_le(s, 0x0000c0da);
215    
216            s_mark_end(s);
217    
218            sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!
219  }  }
220    
221                    
222    
223    
224    
225  static void  static void
226  cliprdr_register_server_formats(STREAM s)  cliprdr_register_server_formats(STREAM s)
# Line 238  cliprdr_register_server_formats(STREAM s Line 250  cliprdr_register_server_formats(STREAM s
250          while (1 < num_formats) {          while (1 < num_formats) {
251                  in_uint32_le(s, this->identifier);                  in_uint32_le(s, this->identifier);
252                  in_uint8a(s, this->textual_description, 32);                  in_uint8a(s, this->textual_description, 32);
253                  DEBUG_CLIPBOARD(("Stored format description with numeric id %d\n", this->identifier));                  DEBUG_CLIPBOARD(("Stored format description with numeric id %d\n",
254                                     this->identifier));
255                  this-> next = xmalloc(sizeof(cliprdr_dataformat));                  this-> next = xmalloc(sizeof(cliprdr_dataformat));
256                  this = this->next;                  this = this->next;
257                  num_formats--;                  num_formats--;
# Line 267  cliprdr_select_X_clipboards(void) Line 280  cliprdr_select_X_clipboards(void)
280                    
281  }  }
282    
283            
284    
285  static void  static void
286  cliprdr_send_format_announce(void)  cliprdr_send_format_announce(void)
287  {  {
# Line 279  cliprdr_send_format_announce(void) Line 294  cliprdr_send_format_announce(void)
294          out_uint16_le(s, 0);          out_uint16_le(s, 0);
295          out_uint32_le(s, number_of_formats*36);          out_uint32_le(s, number_of_formats*36);
296                    
297          out_uint32_le(s, 0xd); // FIXME: This is a rather bogus unicode text description..          //      out_uint32_le(s, 0xd); // FIXME: This is a rather bogus unicode text description..
298          //      rdp_out_unistr(s, "", 16);          //      rdp_out_unistr(s, "", 16);
299            //      out_uint8s(s, 32);
300    
301    
302            out_uint32_le(s, 1); // FIXME: This is a rather bogus text description..
303          out_uint8s(s, 32);          out_uint8s(s, 32);
304    
305          out_uint32_le(s, 0);          out_uint32_le(s, 0);
# Line 288  cliprdr_send_format_announce(void) Line 307  cliprdr_send_format_announce(void)
307          s_mark_end(s);          s_mark_end(s);
308          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!
309  }  }
310                    
311    
312  static void  static void
313  cliprdr_handle_first_handshake(STREAM s)  cliprdr_handle_first_handshake(STREAM s)
# Line 301  cliprdr_handle_first_handshake(STREAM s) Line 320  cliprdr_handle_first_handshake(STREAM s)
320          cliprdr_send_format_announce();          cliprdr_send_format_announce();
321  }  }
322    
323    void cliprdr_handle_server_data(uint32 length, STREAM s)
324    {
325            uint32 remaining_length;
326            char *data;
327            int res;
328            in_uint32_le(s, remaining_length);
329            data = s->p;
330            res = XChangeProperty(display,
331                                  selection_event.requestor,
332                                  selection_event.property,
333                                  XInternAtom(display, "STRING", False),
334                                  8,
335                                  PropModeAppend,
336                                  data,
337                                  remaining_length);
338    
339            DEBUG_CLIPBOARD(("res after XChangeProperty is "));
340            print_X_error(res);    
341            
342            res = XSendEvent(display,
343                             selection_event.requestor,
344                             False,
345                             NoEventMask,
346                             (XEvent *)&selection_event);
347            
348            DEBUG_CLIPBOARD(("res after XSendEvent is "));
349            print_X_error(res);
350    
351    }
352    
353    void cliprdr_handle_server_data_request(STREAM s)
354    {
355            uint32 remaining_length;
356            uint32 wanted_formatcode, pad;
357            int ret;
358            STREAM out;
359    
360            in_uint32_le(s, remaining_length);
361            in_uint32_le(s, wanted_formatcode);
362            in_uint32_le(s, pad);
363    
364            /* FIXME: Check that we support this formatcode */
365    
366            DEBUG_CLIPBOARD(("Request from server for format %d\n",
367                             wanted_formatcode));
368    
369            out =  sec_init(encryption ? SEC_ENCRYPT : 0,
370                            26);
371            out_uint32_le(out, 18);
372            out_uint32_le(out, 0x13);
373            out_uint16_le(out, 5);
374            out_uint16_le(out, 1);
375            out_uint32_le(out, 6);
376            out_uint8p(out, "fnorp", 6);
377            out_uint32_le(out, 0);
378    
379            s_mark_end(out);
380            
381            sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!  
382    
383            /*      
384            if (1 != wanted_formatcode)
385            {
386                    out =  sec_init(encryption ? SEC_ENCRYPT : 0,
387                                    20);
388                    out_uint32_le(s, 12);
389                    out_uint32_le(s, 0x13);
390                    out_uint16_le(s, 5);
391                    out_uint16_le(s, 2);
392                    out_uint32_le(s, 0);
393                    out_uint32_le(s, 0);
394                    s_mark_end(s);
395                    sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!
396            }
397            */              
398    }
399            
400    
401  void cliprdr_callback(STREAM s)  void cliprdr_callback(STREAM s)
402  {  {
403          uint32 length, flags;          uint32 length, flags;
# Line 329  void cliprdr_callback(STREAM s) Line 426  void cliprdr_callback(STREAM s)
426                          // but probably not.                          // but probably not.
427                          DEBUG_CLIPBOARD(("Received format announce ACK\n"));                          DEBUG_CLIPBOARD(("Received format announce ACK\n"));
428                          return;                          return;
429    
430                  } else if (2 == ptype0 && 0 == ptype1)                  } else if (2 == ptype0 && 0 == ptype1)
431                  {                  {
432                          cliprdr_register_server_formats(s);                          cliprdr_register_server_formats(s);
433                          cliprdr_select_X_clipboards();                          cliprdr_select_X_clipboards();
434                            cliprdr_ack_format_list();
435                          return;                          return;
436                    } else if (5 == ptype0 && 1 == ptype1)
437                    {
438                            cliprdr_handle_server_data(length, s);
439                    } else if (4 == ptype0 && 0 == ptype1)
440                    {
441                            cliprdr_handle_server_data_request(s);
442                  }                  }
443    
444                                    
445          }          }
446  }  }
447    
448    
449  void cliprdr_init(void)  void cliprdr_init(void)
450  {  {
451          primary_atom = XInternAtom(display, "PRIMARY", False);          primary_atom = XInternAtom(display, "PRIMARY", False);

Legend:
Removed from v.383  
changed lines
  Added in v.385

  ViewVC Help
Powered by ViewVC 1.1.26