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

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

sourceforge.net/branches/RDESKTOP/rdesktop/parse.h revision 3 by matty, Wed May 10 07:36:34 2000 UTC sourceforge.net/trunk/rdesktop/parse.h revision 1365 by jsorg71, Thu Jan 4 05:39:39 2007 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - parsing layer     Parsing primitives
4     Copyright (C) Matthew Chapman 1999-2000     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 21  Line 21 
21  /* Parser state */  /* Parser state */
22  typedef struct stream  typedef struct stream
23  {  {
24          /* Parsing layer */          unsigned char *p;
25          unsigned char *data;          unsigned char *end;
26            unsigned char *data;
27          unsigned int size;          unsigned int size;
         unsigned int offset;  
         unsigned int end;  
         BOOL marshall;  
         BOOL error;  
   
         /* Other layers */  
         int iso_offset;  
         int mcs_offset;  
         int rdp_offset;  
28    
29  } *STREAM;          /* Offsets of various headers */
30            unsigned char *iso_hdr;
31            unsigned char *mcs_hdr;
32            unsigned char *sec_hdr;
33            unsigned char *rdp_hdr;
34            unsigned char *channel_hdr;
35    
36    }
37     *STREAM;
38    
39    #define s_push_layer(s,h,n)     { (s)->h = (s)->p; (s)->p += n; }
40    #define s_pop_layer(s,h)        (s)->p = (s)->h;
41    #define s_mark_end(s)           (s)->end = (s)->p;
42    #define s_check(s)              ((s)->p <= (s)->end)
43    #define s_check_rem(s,n)        ((s)->p + n <= (s)->end)
44    #define s_check_end(s)          ((s)->p == (s)->end)
45    
46    #if defined(L_ENDIAN) && !defined(NEED_ALIGN)
47    #define in_uint16_le(s,v)       { v = *(uint16 *)((s)->p); (s)->p += 2; }
48    #define in_uint32_le(s,v)       { v = *(uint32 *)((s)->p); (s)->p += 4; }
49    #define out_uint16_le(s,v)      { *(uint16 *)((s)->p) = v; (s)->p += 2; }
50    #define out_uint32_le(s,v)      { *(uint32 *)((s)->p) = v; (s)->p += 4; }
51    
52    #else
53    #define in_uint16_le(s,v)       { v = *((s)->p++); v += *((s)->p++) << 8; }
54    #define in_uint32_le(s,v)       { in_uint16_le(s,v) \
55                                    v += *((s)->p++) << 16; v += *((s)->p++) << 24; }
56    #define out_uint16_le(s,v)      { *((s)->p++) = (v) & 0xff; *((s)->p++) = ((v) >> 8) & 0xff; }
57    #define out_uint32_le(s,v)      { out_uint16_le(s, (v) & 0xffff); out_uint16_le(s, ((v) >> 16) & 0xffff); }
58    #endif
59    
60    #if defined(B_ENDIAN) && !defined(NEED_ALIGN)
61    #define in_uint16_be(s,v)       { v = *(uint16 *)((s)->p); (s)->p += 2; }
62    #define in_uint32_be(s,v)       { v = *(uint32 *)((s)->p); (s)->p += 4; }
63    #define out_uint16_be(s,v)      { *(uint16 *)((s)->p) = v; (s)->p += 2; }
64    #define out_uint32_be(s,v)      { *(uint32 *)((s)->p) = v; (s)->p += 4; }
65    
66    #define B_ENDIAN_PREFERRED
67    #define in_uint16(s,v)          in_uint16_be(s,v)
68    #define in_uint32(s,v)          in_uint32_be(s,v)
69    #define out_uint16(s,v)         out_uint16_be(s,v)
70    #define out_uint32(s,v)         out_uint32_be(s,v)
71    
72    #else
73    #define in_uint16_be(s,v)       { v = *((s)->p++); next_be(s,v); }
74    #define in_uint32_be(s,v)       { in_uint16_be(s,v); next_be(s,v); next_be(s,v); }
75    #define out_uint16_be(s,v)      { *((s)->p++) = ((v) >> 8) & 0xff; *((s)->p++) = (v) & 0xff; }
76    #define out_uint32_be(s,v)      { out_uint16_be(s, ((v) >> 16) & 0xffff); out_uint16_be(s, (v) & 0xffff); }
77    #endif
78    
79    #ifndef B_ENDIAN_PREFERRED
80    #define in_uint16(s,v)          in_uint16_le(s,v)
81    #define in_uint32(s,v)          in_uint32_le(s,v)
82    #define out_uint16(s,v)         out_uint16_le(s,v)
83    #define out_uint32(s,v)         out_uint32_le(s,v)
84    #endif
85    
86    #define in_uint8(s,v)           v = *((s)->p++);
87    #define in_uint8p(s,v,n)        { v = (s)->p; (s)->p += n; }
88    #define in_uint8a(s,v,n)        { memcpy(v,(s)->p,n); (s)->p += n; }
89    #define in_uint8s(s,n)          (s)->p += n;
90    #define out_uint8(s,v)          *((s)->p++) = v;
91    #define out_uint8p(s,v,n)       { memcpy((s)->p,v,n); (s)->p += n; }
92    #define out_uint8a(s,v,n)       out_uint8p(s,v,n);
93    #define out_uint8s(s,n)         { memset((s)->p,0,n); (s)->p += n; }
94    
95  /* Connection state */  #define next_be(s,v)            v = ((v) << 8) + *((s)->p++);
 typedef struct connection  
 {  
         /* Parsing layer */  
         struct stream in;  
         struct stream out;  
   
         /* TCP layer */  
         int tcp_socket;  
   
         /* MCS layer */  
         uint16 mcs_userid;  
   
 } *HCONN;  
   
 #define STREAM_INIT(s,m)   { s.data = xmalloc(2048); s.end = s.size = 2048; s.offset = 0; s.marshall = m; s.error = False; }  
 #define STREAM_SIZE(s,l)   { if (l > s.size) { s.data = xrealloc(s.data,l); s.end = s.size = l; } }  
 #define REMAINING(s)       ( s->end - s->offset )  
 #define PUSH_LAYER(s,v,l)  { s.v = s.offset; s.offset += l; }  
 #define POP_LAYER(s,v)     { s.offset = s.v; }  
 #define MARK_END(s)        { s.end = s.offset; }  

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

  ViewVC Help
Powered by ViewVC 1.1.26