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

Annotation of /jpeg/rdesktop/trunk/parse.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (hide annotations)
Tue Aug 15 10:23:24 2000 UTC (23 years, 9 months ago) by matty
Original Path: sourceforge.net/trunk/rdesktop/parse.h
File MIME type: text/plain
File size: 3614 byte(s)
Major commit of work from laptop - done in various free moments.
Implemented encryption layer and some basic licensing negotiation.
Reorganised code somewhat. While this is not quite as clean, it is
a lot faster - our parser speed was becoming a bottle-neck.

1 matty 3 /*
2     rdesktop: A Remote Desktop Protocol client.
3 matty 10 Parsing primitives
4 matty 3 Copyright (C) Matthew Chapman 1999-2000
5    
6     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
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19     */
20    
21     /* Parser state */
22     typedef struct stream
23     {
24 matty 10 unsigned char *p;
25     unsigned char *end;
26 matty 3 unsigned char *data;
27     unsigned int size;
28    
29 matty 10 /* 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 matty 3
35     } *STREAM;
36    
37 matty 10 #define s_push_layer(s,h,n) { (s)->h = (s)->p; (s)->p += n; }
38     #define s_pop_layer(s,h) (s)->p = (s)->h;
39     #define s_mark_end(s) (s)->end = (s)->p;
40     #define s_check(s) ((s)->p <= (s)->end)
41     #define s_check_rem(s,n) ((s)->p + n <= (s)->end)
42     #define s_check_end(s) ((s)->p == (s)->end)
43 matty 6
44 matty 10 #if defined(L_ENDIAN) && !defined(NEED_ALIGN)
45     #define in_uint16_le(s,v) { v = *(uint16 *)((s)->p); (s)->p += 2; }
46     #define in_uint32_le(s,v) { v = *(uint32 *)((s)->p); (s)->p += 4; }
47     #define out_uint16_le(s,v) { *(uint16 *)((s)->p) = v; (s)->p += 2; }
48     #define out_uint32_le(s,v) { *(uint32 *)((s)->p) = v; (s)->p += 4; }
49 matty 3
50 matty 10 #else
51     #define in_uint16_le(s,v) { v = *((s)->p++); v += *((s)->p++) << 8; }
52     #define in_uint32_le(s,v) { in_uint16_le(s,v) \
53     v += *((s)->p++) << 16; v += *((s)->p++) << 24; }
54     #define out_uint16_le(s,v) { *((s)->p++) = (v) & 0xff; *((s)->p++) = ((v) >> 8) & 0xff; }
55     #define out_uint32_le(s,v) { out_uint16_le(s, (v) & 0xffff); out_uint16_le(s, ((v) >> 16) & 0xffff); }
56     #endif
57 matty 3
58 matty 10 #if defined(B_ENDIAN) && !defined(NEED_ALIGN)
59     #define in_uint16_be(s,v) { v = *(uint16 *)((s)->p); (s)->p += 2; }
60     #define in_uint32_be(s,v) { v = *(uint32 *)((s)->p); (s)->p += 4; }
61     #define out_uint16_be(s,v) { *(uint16 *)((s)->p) = v; (s)->p += 2; }
62     #define out_uint32_be(s,v) { *(uint32 *)((s)->p) = v; (s)->p += 4; }
63 matty 3
64 matty 10 #define B_ENDIAN_PREFERRED
65     #define in_uint16(s,v) in_uint16_be(s,v)
66     #define in_uint32(s,v) in_uint32_be(s,v)
67     #define out_uint16(s,v) out_uint16_be(s,v)
68     #define out_uint32(s,v) out_uint32_be(s,b)
69 matty 3
70 matty 10 #else
71     #define next_be(s,v) v = ((v) << 8) + *((s)->p++);
72     #define in_uint16_be(s,v) { v = *((s)->p++); next_be(s,v); }
73     #define in_uint32_be(s,v) { in_uint16_be(s,v); next_be(s,v); next_be(s,v); }
74     #define out_uint16_be(s,v) { *((s)->p++) = ((v) >> 8) & 0xff; *((s)->p++) = (v) & 0xff; }
75     #define out_uint32_be(s,v) { out_uint16_be(s, ((v) >> 16) & 0xffff); out_uint16_be(s, (v) & 0xffff); }
76     #endif
77    
78     #ifndef B_ENDIAN_PREFERRED
79     #define in_uint16(s,v) in_uint16_le(s,v)
80     #define in_uint32(s,v) in_uint32_le(s,v)
81     #define out_uint16(s,v) out_uint16_le(s,v)
82     #define out_uint32(s,v) out_uint32_le(s,v)
83     #endif
84    
85     #define in_uint8(s,v) v = *((s)->p++);
86     #define in_uint8p(s,v,n) { v = (s)->p; (s)->p += n; }
87     #define in_uint8a(s,v,n) { memcpy(v,(s)->p,n); (s)->p += n; }
88     #define in_uint8s(s,n) (s)->p += n;
89     #define out_uint8(s,v) *((s)->p++) = v;
90     #define out_uint8p(s,v,n) { memcpy((s)->p,v,n); (s)->p += n; }
91     #define out_uint8a(s,v,n) out_uint8p(s,v,n);
92     #define out_uint8s(s,n) { memset((s)->p,0,n); (s)->p += n; }

  ViewVC Help
Powered by ViewVC 1.1.26