/[rdesktop]/sourceforge.net/trunk/rdesktop/channels.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/channels.c

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

revision 432 by matthewc, Tue Jul 1 09:31:25 2003 UTC revision 1372 by jsorg71, Mon Jan 8 04:47:06 2007 UTC
# Line 2  Line 2 
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - Virtual channels     Protocol services - Virtual channels
4     Copyright (C) Erik Forsberg <forsberg@cendio.se> 2003     Copyright (C) Erik Forsberg <forsberg@cendio.se> 2003
5     Copyright (C) Matthew Chapman 2003     Copyright (C) Matthew Chapman 2003-2007
6    
7     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 21  Line 21 
21    
22  #include "rdesktop.h"  #include "rdesktop.h"
23    
24  #define MAX_CHANNELS                    4  #define MAX_CHANNELS                    6
25  #define CHANNEL_CHUNK_LENGTH            1600  #define CHANNEL_CHUNK_LENGTH            1600
26  #define CHANNEL_FLAG_FIRST              0x01  #define CHANNEL_FLAG_FIRST              0x01
27  #define CHANNEL_FLAG_LAST               0x02  #define CHANNEL_FLAG_LAST               0x02
28  #define CHANNEL_FLAG_SHOW_PROTOCOL      0x10  #define CHANNEL_FLAG_SHOW_PROTOCOL      0x10
29    
30  extern BOOL use_rdp5;  extern RD_BOOL g_use_rdp5;
31  extern BOOL encryption;  extern RD_BOOL g_encryption;
32    
33  VCHANNEL g_channels[MAX_CHANNELS];  VCHANNEL g_channels[MAX_CHANNELS];
34  unsigned int g_num_channels;  unsigned int g_num_channels;
35    
36  /* FIXME: We should use the information in TAG_SRV_CHANNELS to map RDP5  /* FIXME: We should use the information in TAG_SRV_CHANNELS to map RDP5
37     channels to MCS channels.     channels to MCS channels.
38    
39     The format of TAG_SRV_CHANNELS seems to be     The format of TAG_SRV_CHANNELS seems to be
40    
# Line 48  channel_register(char *name, uint32 flag Line 48  channel_register(char *name, uint32 flag
48  {  {
49          VCHANNEL *channel;          VCHANNEL *channel;
50    
51          if (!use_rdp5)          if (!g_use_rdp5)
52                  return NULL;                  return NULL;
53    
54          if (g_num_channels >= MAX_CHANNELS)          if (g_num_channels >= MAX_CHANNELS)
# Line 67  channel_register(char *name, uint32 flag Line 67  channel_register(char *name, uint32 flag
67  }  }
68    
69  STREAM  STREAM
70  channel_init(VCHANNEL *channel, uint32 length)  channel_init(VCHANNEL * channel, uint32 length)
71  {  {
72          STREAM s;          STREAM s;
73    
74          s = sec_init(encryption ? SEC_ENCRYPT : 0, length + 8);          s = sec_init(g_encryption ? SEC_ENCRYPT : 0, length + 8);
75          s_push_layer(s, channel_hdr, 8);          s_push_layer(s, channel_hdr, 8);
76          return s;          return s;
77  }  }
78    
79  void  void
80  channel_send(STREAM s, VCHANNEL *channel)  channel_send(STREAM s, VCHANNEL * channel)
81  {  {
82          uint32 length, flags;          uint32 length, flags;
83          uint32 thislength, remaining;          uint32 thislength, remaining;
84          char *data;          uint8 *data;
85    
86    #ifdef WITH_SCARD
87            scard_lock(SCARD_LOCK_CHANNEL);
88    #endif
89    
90          /* first fragment sent in-place */          /* first fragment sent in-place */
91          s_pop_layer(s, channel_hdr);          s_pop_layer(s, channel_hdr);
92          length = s->end - s->p - 8;          length = s->end - s->p - 8;
93    
94            DEBUG_CHANNEL(("channel_send, length = %d\n", length));
95    
96          thislength = MIN(length, CHANNEL_CHUNK_LENGTH);          thislength = MIN(length, CHANNEL_CHUNK_LENGTH);
97    /* Note: In the original clipboard implementation, this number was
98       1592, not 1600. However, I don't remember the reason and 1600 seems
99       to work so.. This applies only to *this* length, not the length of
100       continuation or ending packets. */
101          remaining = length - thislength;          remaining = length - thislength;
102          flags = (remaining == 0) ? CHANNEL_FLAG_FIRST|CHANNEL_FLAG_LAST : CHANNEL_FLAG_FIRST;          flags = (remaining == 0) ? CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST : CHANNEL_FLAG_FIRST;
103          if (channel->flags & CHANNEL_OPTION_SHOW_PROTOCOL)          if (channel->flags & CHANNEL_OPTION_SHOW_PROTOCOL)
104                  flags |= CHANNEL_FLAG_SHOW_PROTOCOL;                  flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
105    
106          out_uint32_le(s, length);          out_uint32_le(s, length);
107          out_uint32_le(s, flags);          out_uint32_le(s, flags);
108          data = s->end = s->p + thislength;          data = s->end = s->p + thislength;
109          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, channel->mcs_id);          DEBUG_CHANNEL(("Sending %d bytes with FLAG_FIRST\n", thislength));
110            sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id);
111    
112          /* subsequent segments copied (otherwise would have to generate headers backwards) */          /* subsequent segments copied (otherwise would have to generate headers backwards) */
113          while (remaining > 0)          while (remaining > 0)
# Line 104  channel_send(STREAM s, VCHANNEL *channel Line 115  channel_send(STREAM s, VCHANNEL *channel
115                  thislength = MIN(remaining, CHANNEL_CHUNK_LENGTH);                  thislength = MIN(remaining, CHANNEL_CHUNK_LENGTH);
116                  remaining -= thislength;                  remaining -= thislength;
117                  flags = (remaining == 0) ? CHANNEL_FLAG_LAST : 0;                  flags = (remaining == 0) ? CHANNEL_FLAG_LAST : 0;
118                    if (channel->flags & CHANNEL_OPTION_SHOW_PROTOCOL)
119                            flags |= CHANNEL_FLAG_SHOW_PROTOCOL;
120    
121                    DEBUG_CHANNEL(("Sending %d bytes with flags %d\n", thislength, flags));
122    
123                  s = sec_init(encryption ? SEC_ENCRYPT : 0, thislength + 8);                  s = sec_init(g_encryption ? SEC_ENCRYPT : 0, thislength + 8);
124                  out_uint32_le(s, length);                  out_uint32_le(s, length);
125                  out_uint32_le(s, flags);                  out_uint32_le(s, flags);
126                  out_uint8p(s, data, thislength);                  out_uint8p(s, data, thislength);
127                  s_mark_end(s);                  s_mark_end(s);
128                  sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, channel->mcs_id);                  sec_send_to_channel(s, g_encryption ? SEC_ENCRYPT : 0, channel->mcs_id);
129    
130                  data += thislength;                  data += thislength;
131          }          }
132    
133    #ifdef WITH_SCARD
134            scard_unlock(SCARD_LOCK_CHANNEL);
135    #endif
136  }  }
137    
138  void  void
# Line 121  channel_process(STREAM s, uint16 mcs_cha Line 140  channel_process(STREAM s, uint16 mcs_cha
140  {  {
141          uint32 length, flags;          uint32 length, flags;
142          uint32 thislength;          uint32 thislength;
143          VCHANNEL *channel;          VCHANNEL *channel = NULL;
144          unsigned int i;          unsigned int i;
145          STREAM in;          STREAM in;
146    
# Line 150  channel_process(STREAM s, uint16 mcs_cha Line 169  channel_process(STREAM s, uint16 mcs_cha
169                  {                  {
170                          if (length > in->size)                          if (length > in->size)
171                          {                          {
172                                  in->data = xrealloc(in->data, length);                                  in->data = (uint8 *) xrealloc(in->data, length);
173                                  in->size = length;                                  in->size = length;
174                          }                          }
175                          in->p = in->data;                          in->p = in->data;
176                  }                  }
177    
178                  thislength = s->end - s->p;                  thislength = MIN(s->end - s->p, in->data + in->size - in->p);
179                  memcpy(in->p, s->p, thislength);                  memcpy(in->p, s->p, thislength);
180                  s->p += thislength;                  in->p += thislength;
                 s->end += thislength;  
181    
182                  if (flags & CHANNEL_FLAG_LAST)                  if (flags & CHANNEL_FLAG_LAST)
183                  {                  {
184                            in->end = in->p;
185                          in->p = in->data;                          in->p = in->data;
186                          channel->process(in);                          channel->process(in);
187                  }                  }
188          }          }
189  }  }
   

Legend:
Removed from v.432  
changed lines
  Added in v.1372

  ViewVC Help
Powered by ViewVC 1.1.26