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

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

revision 391 by forsberg, Fri Jun 6 09:29:01 2003 UTC revision 395 by forsberg, Fri Jun 6 09:32:15 2003 UTC
# Line 26  extern BOOL encryption; Line 26  extern BOOL encryption;
26  extern Display *display;  extern Display *display;
27  extern Window wnd;  extern Window wnd;
28  extern Time last_gesturetime;  extern Time last_gesturetime;
29    extern Atom ipc_atom;
30    
31  // static Time selection_timestamp;  // static Time selection_timestamp;
32  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;
# Line 35  static uint16 num_server_formats = 0; Line 36  static uint16 num_server_formats = 0;
36  static XSelectionEvent selection_event;  static XSelectionEvent selection_event;
37  static uint16 clipboard_channelno;  static uint16 clipboard_channelno;
38  static Atom targets[NUM_TARGETS];  static Atom targets[NUM_TARGETS];
39    static int have_primary = 0;
40    static int rdesktop_is_selection_owner = 0;
41    
42  static void  static void
43  cliprdr_print_server_formats(void)  cliprdr_print_server_formats(void)
# Line 75  cliprdr_set_selection_timestamp(void) Line 78  cliprdr_set_selection_timestamp(void)
78  static void  static void
79  cliprdr_send_format_announce(void)  cliprdr_send_format_announce(void)
80  {  {
         DEBUG_CLIPBOARD(("Sending format announce\n"));  
   
81          STREAM s;          STREAM s;
82    
83            DEBUG_CLIPBOARD(("Sending (empty) format announce\n"));
84          int number_of_formats = 1;          int number_of_formats = 1;
85          s = sec_init(encryption ? SEC_ENCRYPT : 0, number_of_formats*36+12+4+4);          s = sec_init(encryption ? SEC_ENCRYPT : 0, number_of_formats*36+12+4+4);
86          out_uint32_le(s, number_of_formats*36+12);          out_uint32_le(s, number_of_formats*36+12);
# Line 101  cliprdr_send_format_announce(void) Line 104  cliprdr_send_format_announce(void)
104                              clipboard_channelno);                              clipboard_channelno);
105  }  }
106    
107    void cliprdr_ipc_format_announce(unsigned char *data, uint16 length)
108    {
109            STREAM s;
110            rdesktop_is_selection_owner = 1;
111            DEBUG_CLIPBOARD(("cliprdr_ipc_format_announce called, length is %d, data is %s, sending native format announce\n", length, data));
112    
113            s = sec_init(encryption ? SEC_ENCRYPT : 0, length+12+4+4);
114            out_uint32_le(s, length+12);
115            out_uint32_le(s, 0x13);
116            out_uint16_le(s, 2);
117            out_uint16_le(s, 0);
118            out_uint32_le(s, length);
119            out_uint8p(s, data, length);
120            out_uint32_le(s, 0); // Pad
121            s_mark_end(s);
122    
123            sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0,
124                                clipboard_channelno);
125    }
126    
127    
128    
129    
130  static void  static void
131  cliprdr_send_empty_datapacket(void)  cliprdr_send_empty_datapacket(void)
# Line 193  cliprdr_handle_SelectionNotify(XSelectio Line 218  cliprdr_handle_SelectionNotify(XSelectio
218                                    wnd, event->time);                                    wnd, event->time);
219    
220          }          }
221    
222          else  /* Other clipboard data */          else  /* Other clipboard data */
223          {          {
224                                    
# Line 221  cliprdr_handle_SelectionNotify(XSelectio Line 247  cliprdr_handle_SelectionNotify(XSelectio
247                          return;                          return;
248                  }                  }
249    
                 DEBUG_CLIPBOARD(("Received %d bytes of clipboard data from X, there is %d remaining\n",  
                                  nitems, bytes_left));  
                 DEBUG_CLIPBOARD(("type_return is %s\n",  
                                  XGetAtomName(display, type_return)));  
   
250                  datap = data;                  datap = data;
251    
252                  if (nitems+1 <= MAX_CLIPRDR_STANDALONE_DATASIZE)                  if (nitems+1 <= MAX_CLIPRDR_STANDALONE_DATASIZE)
# Line 285  cliprdr_handle_SelectionNotify(XSelectio Line 306  cliprdr_handle_SelectionNotify(XSelectio
306                                  datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE;                                  datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE;
307                                                                    
308                          }                          }
309                          DEBUG_CLIPBOARD(("Sending %d bytes of data\n",                          DEBUG_CLIPBOARD(("Sending %u bytes of data\n",
310                                           12+bytes_left_to_transfer));                                           12+bytes_left_to_transfer));
311                          out =  sec_init(encryption ? SEC_ENCRYPT : 0,                          out =  sec_init(encryption ? SEC_ENCRYPT : 0,
312                                          12+bytes_left_to_transfer);                                          12+bytes_left_to_transfer);
# Line 303  cliprdr_handle_SelectionNotify(XSelectio Line 324  cliprdr_handle_SelectionNotify(XSelectio
324    
325    
326                  XFree(data);                  XFree(data);
327                  cliprdr_send_format_announce();                  if (!rdesktop_clipboard_target_atom)
328                            cliprdr_send_format_announce();
329                                    
330          }          }
331                    
# Line 314  void Line 336  void
336  cliprdr_handle_SelectionClear(void)  cliprdr_handle_SelectionClear(void)
337  {  {
338          DEBUG_CLIPBOARD(("cliprdr_handle_SelectionClear\n"));          DEBUG_CLIPBOARD(("cliprdr_handle_SelectionClear\n"));
339            have_primary = 0;
340            ipc_send_message(RDESKTOP_IPC_CLIPRDR_PRIMARY_LOST,
341                             "", 0);
342          cliprdr_send_format_announce();          cliprdr_send_format_announce();
343  }  }
344    
# Line 343  cliprdr_handle_SelectionRequest(XSelecti Line 368  cliprdr_handle_SelectionRequest(XSelecti
368  {  {
369    
370          XSelectionEvent xev;          XSelectionEvent xev;
371            unsigned long   nitems, bytes_left;
372            Atom type_return;      
373            uint32 *wanted_formatcode;
374            int format;
375            
376          DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n"));          DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n"));
377          DEBUG_CLIPBOARD(("Requestor window id 0x%x ",          DEBUG_CLIPBOARD(("Requestor window id 0x%x ",
378                           (unsigned)xevent->requestor));                           (unsigned)xevent->requestor));
# Line 367  cliprdr_handle_SelectionRequest(XSelecti Line 397  cliprdr_handle_SelectionRequest(XSelecti
397          xev.property = xevent->property;          xev.property = xevent->property;
398          xev.time = xevent->time;          xev.time = xevent->time;
399    
400          if (targets_atom == xevent->target)          memcpy(&selection_event, &xev, sizeof(xev));
401    
402            if (ipc_atom == xevent->target)
403            {
404                    DEBUG_CLIPBOARD(("Target atom is ipc_atom, getting INTEGER from requestor\n"));
405                    XGetWindowProperty(display, xevent->requestor,
406                                       rdesktop_clipboard_target_atom,
407                                       0,
408                                       1,
409                                       True, XA_INTEGER,
410                                       &type_return,
411                                       &format,
412                                       &nitems,
413                                       &bytes_left,
414                                       (unsigned char **)&wanted_formatcode);
415                    DEBUG_CLIPBOARD(("Got wanted formatcode %d, format is %d\n", *wanted_formatcode, format));
416                    cliprdr_request_clipboard_data(*wanted_formatcode);
417            }
418    
419            else if (targets_atom == xevent->target)
420          {          {
421                  DEBUG_CLIPBOARD(("TARGETS requested, sending list..\n"));                  DEBUG_CLIPBOARD(("TARGETS requested, sending list..\n"));
422                  XChangeProperty(display,                  XChangeProperty(display,
# Line 387  cliprdr_handle_SelectionRequest(XSelecti Line 436  cliprdr_handle_SelectionRequest(XSelecti
436                  return;                  return;
437          } else if (timestamp_atom == xevent->target)          } else if (timestamp_atom == xevent->target)
438          {          {
439                    DEBUG_CLIPBOARD(("Sending TIMESTAMP\n"));
440                  XChangeProperty(display,                  XChangeProperty(display,
441                                  xevent->requestor,                                  xevent->requestor,
442                                  xevent->property,                                  xevent->property,
# Line 403  cliprdr_handle_SelectionRequest(XSelecti Line 453  cliprdr_handle_SelectionRequest(XSelecti
453          } else /* Some other target */          } else /* Some other target */
454          {          {
455                  cliprdr_request_clipboard_data(CF_TEXT);                  cliprdr_request_clipboard_data(CF_TEXT);
                 memcpy(&selection_event, &xev, sizeof(xev));  
456                  /* Return and wait for data, handled by                  /* Return and wait for data, handled by
457                     cliprdr_handle_server_data */                     cliprdr_handle_server_data */
458          }          }
# Line 439  cliprdr_register_server_formats(STREAM s Line 488  cliprdr_register_server_formats(STREAM s
488          uint16 num_formats;          uint16 num_formats;
489          cliprdr_dataformat *this, *next;          cliprdr_dataformat *this, *next;
490    
         DEBUG_CLIPBOARD(("cliprdr_register_server_formats\n"));  
491          in_uint32_le(s, remaining_length);          in_uint32_le(s, remaining_length);
492            DEBUG_CLIPBOARD(("cliprdr_register_server_formats, remaining_length is %d\n", remaining_length));
493    
494    
495          num_formats = remaining_length / 36;          num_formats = remaining_length / 36;
496    
497            ipc_send_message(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE,
498                             s->p, remaining_length);
499          if (NULL != server_formats) {          if (NULL != server_formats) {
500                  this = server_formats;                  this = server_formats;
501                  next = this->next;                  next = this->next;
# Line 481  cliprdr_select_X_clipboards(void) Line 534  cliprdr_select_X_clipboards(void)
534          if (wnd != XGetSelectionOwner(display, primary_atom))          if (wnd != XGetSelectionOwner(display, primary_atom))
535          {          {
536                  warning("Failed to aquire ownership of PRIMARY clipboard\n");                  warning("Failed to aquire ownership of PRIMARY clipboard\n");
537            }
538            else
539            {
540                    have_primary = 1;
541          }          }
542          XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime);          XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime);
543          if (wnd != XGetSelectionOwner(display, clipboard_atom))          if (wnd != XGetSelectionOwner(display, clipboard_atom))
# Line 490  cliprdr_select_X_clipboards(void) Line 547  cliprdr_select_X_clipboards(void)
547                    
548  }  }
549    
           
   
550    
551    
552  static void  static void
# Line 505  cliprdr_handle_first_handshake(STREAM s) Line 560  cliprdr_handle_first_handshake(STREAM s)
560          cliprdr_send_format_announce();          cliprdr_send_format_announce();
561  }  }
562    
563  void cliprdr_handle_server_data(uint32 length, STREAM s)  void cliprdr_handle_server_data(uint32 length, uint32 flags, STREAM s)
564  {  {
565          uint32 remaining_length;          static uint32 remaining_length;
566          char *data;          static char *data, *datap;
567          in_uint32_le(s, remaining_length);          static uint32 bytes_left_to_read;
568          data = s->p;          DEBUG_CLIPBOARD(("In cliprdr_handle_server_data, flags is %d\n",
569                             flags));
570            if (3 == flags)  /* One-op write, no packets follows */
571            {
572                    in_uint32_le(s, remaining_length);
573                    data = s->p;
574            } else if (1 == flags) /* First of several packets */
575            {      
576                    in_uint32_le(s, remaining_length);
577                    DEBUG_CLIPBOARD(("Remaining length is %d\n",
578                                     remaining_length));
579                    data = xmalloc(remaining_length);
580                    datap = data;
581                    DEBUG_CLIPBOARD(("Copying first %d bytes\n",
582                                     MAX_CLIPRDR_STANDALONE_DATASIZE));
583                    memcpy(datap, s->p, MAX_CLIPRDR_STANDALONE_DATASIZE);
584    
585                    datap+=MAX_CLIPRDR_STANDALONE_DATASIZE;
586                    bytes_left_to_read = remaining_length-MAX_CLIPRDR_STANDALONE_DATASIZE;
587                    return;
588            } else if (0 == flags)
589            {
590                    DEBUG_CLIPBOARD(("Copying %d middle bytes",
591                                     MAX_CLIPRDR_CONTINUATION_DATASIZE));
592                    memcpy(datap, s->p, MAX_CLIPRDR_CONTINUATION_DATASIZE);
593    
594                    datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE;
595                    bytes_left_to_read-=MAX_CLIPRDR_CONTINUATION_DATASIZE;
596                    return;
597            } else if (2 == flags)
598            {
599                    DEBUG_CLIPBOARD(("Copying last %d bytes\n",
600                                     bytes_left_to_read));
601                    memcpy(datap, s->p, bytes_left_to_read);
602            }
603            DEBUG_CLIPBOARD(("Setting target atom (%s) on %d\n",
604                             XGetAtomName(display, selection_event.property),
605                             selection_event.requestor));
606          XChangeProperty(display,          XChangeProperty(display,
607                          selection_event.requestor,                          selection_event.requestor,
608                          selection_event.property,                          selection_event.property,
# Line 518  void cliprdr_handle_server_data(uint32 l Line 610  void cliprdr_handle_server_data(uint32 l
610                          8,                          8,
611                          PropModeAppend,                          PropModeAppend,
612                          data,                          data,
613                          remaining_length);                          remaining_length-1);
614    
615          XSendEvent(display,          XSendEvent(display,
616                     selection_event.requestor,                     selection_event.requestor,
617                     False,                     False,
618                     NoEventMask,                     NoEventMask,
619                     (XEvent *)&selection_event);                     (XEvent *)&selection_event);
620            
621            if (2 == flags)
622                    xfree(data);
623    
624  }  }
625    
# Line 546  void cliprdr_handle_server_data_request( Line 640  void cliprdr_handle_server_data_request(
640    
641          selectionowner = XGetSelectionOwner(display, primary_atom);          selectionowner = XGetSelectionOwner(display, primary_atom);
642    
643            if (rdesktop_is_selection_owner)
644            {
645                    DEBUG_CLIPBOARD(("XChangeProperty, rdesktop_is_selection_owner\n"));
646                    XChangeProperty(display, wnd, rdesktop_clipboard_target_atom,
647                                    XA_INTEGER, 32, PropModeReplace,
648                                    (unsigned char *)&wanted_formatcode, 1);
649    
650                    XConvertSelection(display, primary_atom,
651                                      ipc_atom,
652                                      rdesktop_clipboard_target_atom,
653                                      wnd, CurrentTime);
654                    return;
655            }
656    
657    
658          if (None != selectionowner)          if (None != selectionowner)
659          {          {
660                    
# Line 579  void cliprdr_callback(STREAM s, uint16 c Line 688  void cliprdr_callback(STREAM s, uint16 c
688          clipboard_channelno = channelno;          clipboard_channelno = channelno;
689          DEBUG_CLIPBOARD(("cliprdr_callback called with channelno %d, clipboard data:\n", channelno));          DEBUG_CLIPBOARD(("cliprdr_callback called with channelno %d, clipboard data:\n", channelno));
690  #ifdef WITH_DEBUG_CLIPBOARD  #ifdef WITH_DEBUG_CLIPBOARD
691          hexdump(s->p, s->end - s->p);          //      hexdump(s->p, s->end - s->p);
692  #endif  #endif
693          in_uint32_le(s, length);          in_uint32_le(s, length);
694          in_uint32_le(s, flags);          in_uint32_le(s, flags);
695    
696          DEBUG_CLIPBOARD(("length is %d, flags are %d\n", length, flags));          DEBUG_CLIPBOARD(("length is %d, flags are %d\n", length, flags));
697    
698          if (flags & 0x03 || flags & 0x01) /* Single-write op or first-packet-of-several op */          if (3 == flags || 1 == flags) /* Single-write op or first-packet-of-several op */
699          {          {
700                  in_uint16_le(s, ptype0);                  in_uint16_le(s, ptype0);
701                  in_uint16_le(s, ptype1);                  in_uint16_le(s, ptype1);
# Line 631  void cliprdr_callback(STREAM s, uint16 c Line 740  void cliprdr_callback(STREAM s, uint16 c
740                          return;                          return;
741                  } else if (5 == ptype0 && 1 == ptype1)                  } else if (5 == ptype0 && 1 == ptype1)
742                  {                  {
743                          cliprdr_handle_server_data(length, s);                          cliprdr_handle_server_data(length, flags, s);
744                  } else if (4 == ptype0 && 0 == ptype1)                  } else if (4 == ptype0 && 0 == ptype1)
745                  {                  {
746                          cliprdr_handle_server_data_request(s);                          cliprdr_handle_server_data_request(s);
747                  }                  }
748    
749                                    
750            }
751            else
752            {
753                    DEBUG_CLIPBOARD(("Handling middle or last packet\n"));
754                    cliprdr_handle_server_data(length, flags, s);
755          }          }
756  }  }
757    
758    void cliprdr_ipc_primary_lost(unsigned char *data, uint16 length)
759    {
760            DEBUG_CLIPBOARD(("cliprdr_ipc_primary_lost called\n"));
761            if (!have_primary)
762                    cliprdr_send_format_announce();
763            rdesktop_is_selection_owner = 0;
764    }
765    
766    
767  void cliprdr_init(void)  void cliprdr_init(void)
768  {  {
# Line 656  void cliprdr_init(void) Line 778  void cliprdr_init(void)
778          targets[3] = XInternAtom(display, "text/unicode", False);          targets[3] = XInternAtom(display, "text/unicode", False);
779          targets[4] = XInternAtom(display, "TIMESTAMP", False);          targets[4] = XInternAtom(display, "TIMESTAMP", False);
780          targets[5] = XInternAtom(display, "STRING", False);          targets[5] = XInternAtom(display, "STRING", False);
781            ipc_register_ipcnotify(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE,
782                                   cliprdr_ipc_format_announce);
783            ipc_register_ipcnotify(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE,
784                                   cliprdr_ipc_primary_lost);
785    
786    
787  }  }

Legend:
Removed from v.391  
changed lines
  Added in v.395

  ViewVC Help
Powered by ViewVC 1.1.26