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

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

revision 347 by forsberg, Thu Mar 27 13:11:58 2003 UTC revision 1365 by jsorg71, Thu Jan 4 05:39:39 2007 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - ISO layer     Protocol services - ISO layer
4     Copyright (C) Matthew Chapman 1999-2002     Copyright (C) Matthew Chapman 1999-2007
5      
6     This program is free software; you can redistribute it and/or modify     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     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     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.     (at your option) any later version.
10      
11     This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.     GNU General Public License for more details.
15      
16     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Line 72  iso_send_connection_request(char *userna Line 72  iso_send_connection_request(char *userna
72    
73  /* Receive a message on the ISO layer, return code */  /* Receive a message on the ISO layer, return code */
74  static STREAM  static STREAM
75  iso_recv_msg(uint8 * code)  iso_recv_msg(uint8 * code, uint8 * rdpver)
76  {  {
77          STREAM s;          STREAM s;
78          uint16 length;          uint16 length;
79          uint8 version;          uint8 version;
         BOOL shortform = False; // Shut the compiler up.  
80    
81        next_packet:          s = tcp_recv(NULL, 4);
         s = tcp_recv(4);  
82          if (s == NULL)          if (s == NULL)
83                  return NULL;                  return NULL;
   
84          in_uint8(s, version);          in_uint8(s, version);
85          switch (version & 3)          if (rdpver != NULL)
86                    *rdpver = version;
87            if (version == 3)
88          {          {
89                  case 0:                  in_uint8s(s, 1);        /* pad */
90                          in_uint8(s, length);                  in_uint16_be(s, length);
                         if (length & 0x80)  
                         {  
                                 length &= ~0x80;  
                                 next_be(s, length);  
                                 shortform = False;  
                         }  
                         else  
                         {  
                                 shortform = True;  
                         }  
                         break;  
   
                 case 3:  
                         in_uint8s(s, 1);        /* pad */  
                         in_uint16_be(s, length);  
                         break;  
   
                 default:  
                         error("TPKT v%d\n", version);  
                         return NULL;  
91          }          }
92            else
         s = tcp_recv(length - 4);  
         if (s == NULL)  
                 return NULL;  
   
         if ((version & 3) == 0)  
93          {          {
94                  rdp5_process(s, version & 0x80, shortform);                  in_uint8(s, length);
95                  goto next_packet;                  if (length & 0x80)
96                    {
97                            length &= ~0x80;
98                            next_be(s, length);
99                    }
100          }          }
101            s = tcp_recv(s, length - 4);
102            if (s == NULL)
103                    return NULL;
104            if (version != 3)
105                    return s;
106          in_uint8s(s, 1);        /* hdrlen */          in_uint8s(s, 1);        /* hdrlen */
107          in_uint8(s, *code);          in_uint8(s, *code);
   
108          if (*code == ISO_PDU_DT)          if (*code == ISO_PDU_DT)
109          {          {
110                  in_uint8s(s, 1);        /* eot */                  in_uint8s(s, 1);        /* eot */
111                  return s;                  return s;
112          }          }
   
113          in_uint8s(s, 5);        /* dst_ref, src_ref, class */          in_uint8s(s, 5);        /* dst_ref, src_ref, class */
114          return s;          return s;
115  }  }
# Line 168  iso_send(STREAM s) Line 148  iso_send(STREAM s)
148    
149  /* Receive ISO transport data packet */  /* Receive ISO transport data packet */
150  STREAM  STREAM
151  iso_recv(void)  iso_recv(uint8 * rdpver)
152  {  {
153          STREAM s;          STREAM s;
154          uint8 code;          uint8 code = 0;
155    
156          s = iso_recv_msg(&code);          s = iso_recv_msg(&code, rdpver);
157          if (s == NULL)          if (s == NULL)
158                  return NULL;                  return NULL;
159            if (rdpver != NULL)
160                    if (*rdpver != 3)
161                            return s;
162          if (code != ISO_PDU_DT)          if (code != ISO_PDU_DT)
163          {          {
164                  error("expected DT, got 0x%x\n", code);                  error("expected DT, got 0x%x\n", code);
165                  return NULL;                  return NULL;
166          }          }
   
167          return s;          return s;
168  }  }
169    
# Line 190  iso_recv(void) Line 171  iso_recv(void)
171  BOOL  BOOL
172  iso_connect(char *server, char *username)  iso_connect(char *server, char *username)
173  {  {
174          uint8 code;          uint8 code = 0;
175    
176          if (!tcp_connect(server))          if (!tcp_connect(server))
177                  return False;                  return False;
178    
179          iso_send_connection_request(username);          iso_send_connection_request(username);
180    
181          if (iso_recv_msg(&code) == NULL)          if (iso_recv_msg(&code, NULL) == NULL)
182                    return False;
183    
184            if (code != ISO_PDU_CC)
185            {
186                    error("expected CC, got 0x%x\n", code);
187                    tcp_disconnect();
188                    return False;
189            }
190    
191            return True;
192    }
193    
194    /* Establish a reconnection up to the ISO layer */
195    BOOL
196    iso_reconnect(char *server)
197    {
198            uint8 code = 0;
199    
200            if (!tcp_connect(server))
201                    return False;
202    
203            iso_send_msg(ISO_PDU_CR);
204    
205            if (iso_recv_msg(&code, NULL) == NULL)
206                  return False;                  return False;
207    
208          if (code != ISO_PDU_CC)          if (code != ISO_PDU_CC)
# Line 217  iso_disconnect(void) Line 222  iso_disconnect(void)
222          iso_send_msg(ISO_PDU_DR);          iso_send_msg(ISO_PDU_DR);
223          tcp_disconnect();          tcp_disconnect();
224  }  }
225    
226    /* reset the state to support reconnecting */
227    void
228    iso_reset_state(void)
229    {
230            tcp_reset_state();
231    }

Legend:
Removed from v.347  
changed lines
  Added in v.1365

  ViewVC Help
Powered by ViewVC 1.1.26