/[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 385 by forsberg, Fri Jun 6 09:23:28 2003 UTC revision 386 by forsberg, Fri Jun 6 09:24:15 2003 UTC
# Line 28  extern Window wnd; Line 28  extern Window wnd;
28  extern Time last_keyrelease;  extern Time last_keyrelease;
29    
30  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;
31    static Atom rdesktop_clipboard_target_atom;
32  static cliprdr_dataformat *server_formats = NULL;  static cliprdr_dataformat *server_formats = NULL;
33  static uint16 num_server_formats = 0;  static uint16 num_server_formats = 0;
34  static XSelectionEvent selection_event;  static XSelectionEvent selection_event;
# Line 50  cliprdr_print_server_formats(void) Line 51  cliprdr_print_server_formats(void)
51  #endif  #endif
52  }  }
53    
54    static void
55    cliprdr_send_empty_datapacket(void)
56    {
57            STREAM out;
58            out =  sec_init(encryption ? SEC_ENCRYPT : 0,
59                            20);
60            out_uint32_le(out, 12);
61            out_uint32_le(out, 0x13);
62            out_uint16_le(out, 5);
63            out_uint16_le(out, 1);
64            out_uint32_le(out, 0);
65            /* Insert null string here? */
66            out_uint32_le(out, 0);
67            s_mark_end(out);
68            
69            sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!  
70    }
71    
72    
73  void  void
74  cliprdr_handle_SelectionNotify(void)  cliprdr_handle_SelectionNotify(XSelectionEvent *event)
75  {  {
76    
77            unsigned char   *data;
78            unsigned long   nitems, bytes_left;
79            int res;
80    
81            int format;
82            Atom type_return;
83            Atom best_target;
84    
85            STREAM out;
86            
87          DEBUG_CLIPBOARD(("cliprdr_handle_SelectionNotify\n"));          DEBUG_CLIPBOARD(("cliprdr_handle_SelectionNotify\n"));
88    
89            if (None == event->property) {
90                    cliprdr_send_empty_datapacket();
91                    return; /* Selection failed */
92            }
93    
94            DEBUG_CLIPBOARD(("selection: %s, target: %s, property: %s\n",
95                             XGetAtomName(display, event->selection),
96                             XGetAtomName(display, event->target),
97                             XGetAtomName(display, event->property)));
98    
99            if (targets_atom == event->target) {
100                    /* Response to TARGETS request. Let's find the target
101                       we want and request that */
102                    res = XGetWindowProperty(display, wnd,
103                                             rdesktop_clipboard_target_atom,
104                                             0L, 4096L, False, AnyPropertyType,
105                                             &type_return,
106                                             &format, &nitems, &bytes_left, &data);
107    
108                    if (Success != res)
109                    {
110                            DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n"));
111                            cliprdr_send_empty_datapacket();
112                            return;
113                    }
114    
115                    if (None == type_return)
116                            /* The owner might no support TARGETS. Just try
117                               STRING */
118                            best_target = XA_STRING;
119                    else
120                    {
121                            /* FIXME: We should choose format here based
122                               on what the server wanted */
123                            best_target = XInternAtom(display, "TEXT", False);
124                            
125                            
126                    }
127    
128                    XConvertSelection(display, primary_atom,
129                                      best_target,
130                                      rdesktop_clipboard_target_atom,
131                                      wnd, event->time);
132    
133            }
134            else  /* Other clipboard data */
135            {
136                    
137                    res = XGetWindowProperty(display, wnd,
138                                             rdesktop_clipboard_target_atom,
139                                             0L, 4096L, False, AnyPropertyType,
140                                             &type_return,
141                                             &format, &nitems, &bytes_left, &data);
142    
143                    if (Success != res)
144                    {
145                            DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n"));
146                            cliprdr_send_empty_datapacket();
147                            return;
148                    }
149    
150                    /* We need to handle INCR as well */
151    
152                    out =  sec_init(encryption ? SEC_ENCRYPT : 0,
153                                    20+nitems);
154                    out_uint32_le(out, 12+nitems);
155                    out_uint32_le(out, 0x13);
156                    out_uint16_le(out, 5);
157                    out_uint16_le(out, 1);
158                    out_uint32_le(out, nitems);
159                    out_uint8p(out, data, nitems);
160                    /* Insert null string here? */
161                    out_uint32_le(out, 0);
162                    s_mark_end(out);
163            
164                    sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!  
165                    
166            }
167            
168            
169  }  }
170    
171  void  void
# Line 352  void cliprdr_handle_server_data(uint32 l Line 464  void cliprdr_handle_server_data(uint32 l
464    
465  void cliprdr_handle_server_data_request(STREAM s)  void cliprdr_handle_server_data_request(STREAM s)
466  {  {
467            Window selectionowner;
468          uint32 remaining_length;          uint32 remaining_length;
469          uint32 wanted_formatcode, pad;          uint32 wanted_formatcode, pad;
         int ret;  
         STREAM out;  
470    
471          in_uint32_le(s, remaining_length);          in_uint32_le(s, remaining_length);
472          in_uint32_le(s, wanted_formatcode);          in_uint32_le(s, wanted_formatcode);
# Line 366  void cliprdr_handle_server_data_request( Line 477  void cliprdr_handle_server_data_request(
477          DEBUG_CLIPBOARD(("Request from server for format %d\n",          DEBUG_CLIPBOARD(("Request from server for format %d\n",
478                           wanted_formatcode));                           wanted_formatcode));
479    
480          out =  sec_init(encryption ? SEC_ENCRYPT : 0,          selectionowner = XGetSelectionOwner(display, primary_atom);
                         26);  
         out_uint32_le(out, 18);  
         out_uint32_le(out, 0x13);  
         out_uint16_le(out, 5);  
         out_uint16_le(out, 1);  
         out_uint32_le(out, 6);  
         out_uint8p(out, "fnorp", 6);  
         out_uint32_le(out, 0);  
481    
482          s_mark_end(out);          if (None != selectionowner)
483            {
484                    
485          sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!                    /* FIXME: Perhaps we should check if we are the owner? */
486    
487                    XConvertSelection(display, primary_atom,
488                                      targets_atom,
489                                      rdesktop_clipboard_target_atom,
490                                      wnd, CurrentTime);
491    
492          /*                        /* The rest of the transfer is handled in
493          if (1 != wanted_formatcode)                     cliprdr_handle_SelectionNotify */
494    
495            } else
496          {          {
497                  out =  sec_init(encryption ? SEC_ENCRYPT : 0,                  DEBUG_CLIPBOARD(("There were no owner for PRIMARY, sending empty string\n")); // FIXME: Should we always send an empty string?
498                                  20);  
499                  out_uint32_le(s, 12);                  cliprdr_send_empty_datapacket();
                 out_uint32_le(s, 0x13);  
                 out_uint16_le(s, 5);  
                 out_uint16_le(s, 2);  
                 out_uint32_le(s, 0);  
                 out_uint32_le(s, 0);  
                 s_mark_end(s);  
                 sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!  
500          }          }
501          */                
502    
503  }  }
504                    
505    
# Line 450  void cliprdr_init(void) Line 555  void cliprdr_init(void)
555  {  {
556          primary_atom = XInternAtom(display, "PRIMARY", False);          primary_atom = XInternAtom(display, "PRIMARY", False);
557          clipboard_atom = XInternAtom(display, "CLIPBOARD", False);          clipboard_atom = XInternAtom(display, "CLIPBOARD", False);
558          targets_atom = XInternAtom(display, "TARGETS", True);          targets_atom = XInternAtom(display, "TARGETS", False);
559          timestamp_atom = XInternAtom(display, "TIMESTAMP", True);          timestamp_atom = XInternAtom(display, "TIMESTAMP", False);
560            rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False);
561  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26