Diffstat (limited to 'noncore/net/opierdesktop/parse.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opierdesktop/parse.h | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/noncore/net/opierdesktop/parse.h b/noncore/net/opierdesktop/parse.h new file mode 100644 index 0000000..f54c05f --- a/dev/null +++ b/noncore/net/opierdesktop/parse.h | |||
@@ -0,0 +1,108 @@ | |||
1 | /* | ||
2 | rdesktop: A Remote Desktop Protocol client. | ||
3 | Parsing primitives | ||
4 | Copyright (C) Matthew Chapman 1999-2002 | ||
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 | unsigned char *p; | ||
25 | unsigned char *end; | ||
26 | unsigned char *data; | ||
27 | unsigned int size; | ||
28 | //unsigned char *next_packet; | ||
29 | |||
30 | |||
31 | /* Offsets of various headers */ | ||
32 | unsigned char *iso_hdr; | ||
33 | unsigned char *mcs_hdr; | ||
34 | unsigned char *sec_hdr; | ||
35 | unsigned char *rdp_hdr; | ||
36 | |||
37 | } | ||
38 | *STREAM; | ||
39 | |||
40 | #define s_push_layer(s,h,n){ (s)->h = (s)->p; (s)->p += n; } | ||
41 | #define s_pop_layer(s,h)(s)->p = (s)->h; | ||
42 | #define s_mark_end(s) (s)->end = (s)->p; | ||
43 | #define s_check(s) ((s)->p <= (s)->end) | ||
44 | #define s_check_rem(s,n)((s)->p + n <= (s)->end) | ||
45 | #define s_check_end(s) ((s)->p == (s)->end) | ||
46 | |||
47 | #if defined(L_ENDIAN) && !defined(NEED_ALIGN) | ||
48 | #define in_uint16_le(s,v){ v = *(uint16 *)((s)->p); (s)->p += 2; } | ||
49 | #define in_uint32_le(s,v){ v = *(uint32 *)((s)->p); (s)->p += 4; } | ||
50 | #define out_uint16_le(s,v){ *(uint16 *)((s)->p) = v; (s)->p += 2; } | ||
51 | #define out_uint32_le(s,v){ *(uint32 *)((s)->p) = v; (s)->p += 4; } | ||
52 | |||
53 | #else | ||
54 | #define in_uint16_le(s,v){ v = *((s)->p++); v += *((s)->p++) << 8; } | ||
55 | #define in_uint32_le(s,v){ in_uint16_le(s,v) \ | ||
56 | v += *((s)->p++) << 16; v += *((s)->p++) << 24; } | ||
57 | #define out_uint16_le(s,v){ *((s)->p++) = (v) & 0xff; *((s)->p++) = ((v) >> 8) & 0xff; } | ||
58 | #define out_uint32_le(s,v){ out_uint16_le(s, (v) & 0xffff); out_uint16_le(s, ((v) >> 16) & 0xffff); } | ||
59 | #endif | ||
60 | |||
61 | #if defined(B_ENDIAN) && !defined(NEED_ALIGN) | ||
62 | #define in_uint16_be(s,v){ v = *(uint16 *)((s)->p); (s)->p += 2; } | ||
63 | #define in_uint32_be(s,v){ v = *(uint32 *)((s)->p); (s)->p += 4; } | ||
64 | #define out_uint16_be(s,v){ *(uint16 *)((s)->p) = v; (s)->p += 2; } | ||
65 | #define out_uint32_be(s,v){ *(uint32 *)((s)->p) = v; (s)->p += 4; } | ||
66 | |||
67 | #define B_ENDIAN_PREFERRED | ||
68 | #define in_uint16(s,v) in_uint16_be(s,v) | ||
69 | #define in_uint32(s,v) in_uint32_be(s,v) | ||
70 | #define out_uint16(s,v) out_uint16_be(s,v) | ||
71 | #define out_uint32(s,v) out_uint32_be(s,v) | ||
72 | |||
73 | #else | ||
74 | #define next_be(s,v) v = ((v) << 8) + *((s)->p++); | ||
75 | #define in_uint16_be(s,v){ v = *((s)->p++); next_be(s,v); } | ||
76 | #define in_uint32_be(s,v){ in_uint16_be(s,v); next_be(s,v); next_be(s,v); } | ||
77 | #define out_uint16_be(s,v){ *((s)->p++) = ((v) >> 8) & 0xff; *((s)->p++) = (v) & 0xff; } | ||
78 | #define out_uint32_be(s,v){ out_uint16_be(s, ((v) >> 16) & 0xffff); out_uint16_be(s, (v) & 0xffff); } | ||
79 | #endif | ||
80 | |||
81 | #ifndef B_ENDIAN_PREFERRED | ||
82 | #define in_uint16(s,v) in_uint16_le(s,v) | ||
83 | #define in_uint32(s,v) in_uint32_le(s,v) | ||
84 | #define out_uint16(s,v) out_uint16_le(s,v) | ||
85 | #define out_uint32(s,v) out_uint32_le(s,v) | ||
86 | #endif | ||
87 | |||
88 | #define in_uint8(s,v) v = *((s)->p++); | ||
89 | #define in_uint8p(s,v,n){ v = (s)->p; (s)->p += n; } | ||
90 | #define in_uint8a(s,v,n){ memcpy(v,(s)->p,n); (s)->p += n; } | ||
91 | #define in_uint8s(s,n) (s)->p += n; | ||
92 | #define out_uint8(s,v) *((s)->p++) = v; | ||
93 | #define out_uint8p(s,v,n){ memcpy((s)->p,v,n); (s)->p += n; } | ||
94 | #define out_uint8a(s,v,n)out_uint8p(s,v,n); | ||
95 | #define out_uint8s(s,n) { memset((s)->p,0,n); (s)->p += n; } | ||
96 | |||
97 | #if defined(B_ENDIAN) | ||
98 | |||
99 | #endif | ||
100 | #if defined(B_ENDIAN_PREFERRED) | ||
101 | |||
102 | #endif | ||
103 | #if defined(NEED_ALIGN) | ||
104 | |||
105 | #endif | ||
106 | #if defined(L_ENDIAN) | ||
107 | |||
108 | #endif | ||