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

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

revision 24 by matty, Sat Jan 6 03:12:10 2001 UTC revision 438 by jsorg71, Fri Aug 1 17:01:58 2003 UTC
# Line 1  Line 1 
1  /*  /* -*- 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-2000     Copyright (C) Matthew Chapman 1999-2002
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
# Line 21  Line 21 
21  #include "rdesktop.h"  #include "rdesktop.h"
22    
23  /* Send a self-contained ISO PDU */  /* Send a self-contained ISO PDU */
24  static void iso_send_msg(uint8 code)  static void
25    iso_send_msg(uint8 code)
26  {  {
27          STREAM s;          STREAM s;
28    
# Line 41  static void iso_send_msg(uint8 code) Line 42  static void iso_send_msg(uint8 code)
42          tcp_send(s);          tcp_send(s);
43  }  }
44    
45    static void
46    iso_send_connection_request(char *username)
47    {
48            STREAM s;
49            int length = 30 + strlen(username);
50    
51            s = tcp_init(length);
52    
53            out_uint8(s, 3);        /* version */
54            out_uint8(s, 0);        /* reserved */
55            out_uint16_be(s, length);       /* length */
56    
57            out_uint8(s, length - 5);       /* hdrlen */
58            out_uint8(s, ISO_PDU_CR);
59            out_uint16(s, 0);       /* dst_ref */
60            out_uint16(s, 0);       /* src_ref */
61            out_uint8(s, 0);        /* class */
62    
63            out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash="));
64            out_uint8p(s, username, strlen(username));
65    
66            out_uint8(s, 0x0d);     /* Unknown */
67            out_uint8(s, 0x0a);     /* Unknown */
68    
69            s_mark_end(s);
70            tcp_send(s);
71    }
72    
73  /* Receive a message on the ISO layer, return code */  /* Receive a message on the ISO layer, return code */
74  static STREAM iso_recv_msg(uint8 *code)  static STREAM
75    iso_recv_msg(uint8 * code)
76  {  {
77          STREAM s;          STREAM s;
78          uint16 length;          uint16 length;
79          uint8 version;          uint8 version;
80    
81          s = tcp_recv(4);          next_packet:
82            s = tcp_recv(NULL, 4);
83          if (s == NULL)          if (s == NULL)
84                  return False;                  return NULL;
85    
86          in_uint8(s, version);          in_uint8(s, version);
87          if (version != 3)          switch (version & 3)
88          {          {
89                  ERROR("TPKT v%d\n", version);                  case 0:
90                  return False;                          in_uint8(s, length);
91                            if (length & 0x80)
92                            {
93                                    length &= ~0x80;
94                                    next_be(s, length);
95                            }
96                            break;
97    
98                    case 3:
99                            in_uint8s(s, 1);        /* pad */
100                            in_uint16_be(s, length);
101                            break;
102    
103                    default:
104                            error("TPKT v%d\n", version);
105                            return NULL;
106          }          }
107    
108          in_uint8s(s, 1);        /* pad */          s = tcp_recv(s, length - 4);
         in_uint16_be(s, length);  
   
         s = tcp_recv(length - 4);  
109          if (s == NULL)          if (s == NULL)
110                  return False;                  return NULL;
111    
112            if ((version & 3) == 0)
113            {
114                    rdp5_process(s, version & 0x80);
115                    goto next_packet;
116            }
117    
118          in_uint8s(s, 1);        /* hdrlen */          in_uint8s(s, 1);        /* hdrlen */
119          in_uint8(s, *code);          in_uint8(s, *code);
# Line 80  static STREAM iso_recv_msg(uint8 *code) Line 129  static STREAM iso_recv_msg(uint8 *code)
129  }  }
130    
131  /* Initialise ISO transport data packet */  /* Initialise ISO transport data packet */
132  STREAM iso_init(int length)  STREAM
133    iso_init(int length)
134  {  {
135          STREAM s;          STREAM s;
136    
# Line 91  STREAM iso_init(int length) Line 141  STREAM iso_init(int length)
141  }  }
142    
143  /* Send an ISO data PDU */  /* Send an ISO data PDU */
144  void iso_send(STREAM s)  void
145    iso_send(STREAM s)
146  {  {
147          uint16 length;          uint16 length;
148    
# Line 110  void iso_send(STREAM s) Line 161  void iso_send(STREAM s)
161  }  }
162    
163  /* Receive ISO transport data packet */  /* Receive ISO transport data packet */
164  STREAM iso_recv()  STREAM
165    iso_recv(void)
166  {  {
167          STREAM s;          STREAM s;
168          uint8 code;          uint8 code;
169    
170          s = iso_recv_msg(&code);          s = iso_recv_msg(&code);
171          if ((s == NULL) || (code != ISO_PDU_DT))          if (s == NULL)
172                    return NULL;
173    
174            if (code != ISO_PDU_DT)
175          {          {
176                  ERROR("expected DT, got %d\n", code);                  error("expected DT, got 0x%x\n", code);
177                  return False;                  return NULL;
178          }          }
179    
180          return s;          return s;
181  }  }
182    
183  /* Establish a connection up to the ISO layer */  /* Establish a connection up to the ISO layer */
184  BOOL iso_connect(char *server)  BOOL
185    iso_connect(char *server, char *username)
186  {  {
187          uint8 code;          uint8 code;
188    
189          if (!tcp_connect(server))          if (!tcp_connect(server))
190                  return False;                  return False;
191    
192          iso_send_msg(ISO_PDU_CR);          iso_send_connection_request(username);
193    
194            if (iso_recv_msg(&code) == NULL)
195                    return False;
196    
197          if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC))          if (code != ISO_PDU_CC)
198          {          {
199                  ERROR("expected CC, got %d\n", code);                  error("expected CC, got 0x%x\n", code);
200                  tcp_disconnect();                  tcp_disconnect();
201                  return False;                  return False;
202          }          }
# Line 146  BOOL iso_connect(char *server) Line 205  BOOL iso_connect(char *server)
205  }  }
206    
207  /* Disconnect from the ISO layer */  /* Disconnect from the ISO layer */
208  void iso_disconnect()  void
209    iso_disconnect(void)
210  {  {
211          iso_send_msg(ISO_PDU_DR);          iso_send_msg(ISO_PDU_DR);
212          tcp_disconnect();          tcp_disconnect();

Legend:
Removed from v.24  
changed lines
  Added in v.438

  ViewVC Help
Powered by ViewVC 1.1.26