You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xrdp-proprietary/xrdp/parse.h

300 lines
7.0 KiB

21 years ago
/*
rdesktop: A Remote Desktop Protocol client.
Parsing primitives
Copyright (C) Matthew Chapman 1999-2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* modified for xrdp */
/* this is a super fast stream method, you bet */
20 years ago
#if defined L_ENDIAN
#elif defined B_ENDIAN
#else
#error Unknown endianness.
#endif
21 years ago
/* parser state */
struct stream
{
char* p;
char* end;
char* data;
int size;
/* offsets of various headers */
char* iso_hdr;
char* mcs_hdr;
char* sec_hdr;
char* rdp_hdr;
char* channel_hdr;
char* next_packet;
21 years ago
};
20 years ago
/******************************************************************************/
21 years ago
#define s_check(s) (s->p <= s->end)
20 years ago
/******************************************************************************/
21 years ago
#define s_check_rem(s, n) (s->p + n <= s->end)
20 years ago
/******************************************************************************/
21 years ago
#define s_check_end(s) (s->p == s->end)
20 years ago
/******************************************************************************/
#define make_stream(s) \
{ \
s = (struct stream*)g_malloc(sizeof(struct stream), 1); \
}
20 years ago
/******************************************************************************/
21 years ago
#define init_stream(s, v) \
{ \
if (v > s->size) \
{ \
g_free(s->data); \
s->data = (char*)g_malloc(v, 0); \
} \
s->p = s->data; \
s->end = s->data; \
s->size = v; \
s->next_packet = 0; \
21 years ago
}
20 years ago
/******************************************************************************/
#define free_stream(s) \
{ \
if (s != 0) \
g_free(s->data); \
g_free(s); \
} \
20 years ago
/******************************************************************************/
21 years ago
#define s_push_layer(s, h, n) \
{ \
s->h = s->p; \
s->p += n; \
}
20 years ago
/******************************************************************************/
21 years ago
#define s_pop_layer(s, h) \
{ \
s->p = s->h; \
}
20 years ago
/******************************************************************************/
21 years ago
#define s_mark_end(s) \
{ \
s->end = s->p; \
}
20 years ago
/******************************************************************************/
21 years ago
#define in_uint8(s, v) \
{ \
v = *((unsigned char*)(s->p)); \
s->p++; \
}
20 years ago
/******************************************************************************/
#if defined B_ENDIAN || defined NEED_ALIGN
#define in_sint16_le(s, v) \
{ \
v = (signed short) \
( \
(*((unsigned char*)(s->p + 0)) << 0) | \
(*((unsigned char*)(s->p + 1)) << 8) \
); \
s->p += 2; \
}
#else
#define in_sint16_le(s, v) \
{ \
v = *((signed short*)(s->p)); \
s->p += 2; \
}
20 years ago
#endif
20 years ago
/******************************************************************************/
#if defined B_ENDIAN || defined NEED_ALIGN
#define in_uint16_le(s, v) \
{ \
v = (unsigned short) \
( \
(*((unsigned char*)(s->p + 0)) << 0) | \
(*((unsigned char*)(s->p + 1)) << 8) \
); \
s->p += 2; \
}
#else
21 years ago
#define in_uint16_le(s, v) \
{ \
v = *((unsigned short*)(s->p)); \
s->p += 2; \
}
20 years ago
#endif
21 years ago
20 years ago
/******************************************************************************/
21 years ago
#define in_uint16_be(s, v) \
{ \
v = *((unsigned char*)(s->p)); \
s->p++; \
v = v << 8; \
v = v | *((unsigned char*)(s->p)); \
s->p++; \
}
20 years ago
/******************************************************************************/
#if defined B_ENDIAN || defined NEED_ALIGN
#define in_uint32_le(s, v) \
{ \
v = (unsigned long) \
( \
(*((unsigned char*)(s->p + 0)) << 0) | \
(*((unsigned char*)(s->p + 1)) << 8) | \
(*((unsigned char*)(s->p + 2)) << 16) | \
(*((unsigned char*)(s->p + 3)) << 24) \
); \
s->p += 4; \
}
#else
21 years ago
#define in_uint32_le(s, v) \
{ \
20 years ago
v = *((unsigned long*)(s->p)); \
21 years ago
s->p += 4; \
}
20 years ago
#endif
21 years ago
20 years ago
/******************************************************************************/
21 years ago
#define in_uint32_be(s, v) \
{ \
v = *((unsigned char*)(s->p)); \
s->p++; \
v = v << 8; \
v = v | *((unsigned char*)(s->p)); \
s->p++; \
v = v << 8; \
v = v | *((unsigned char*)(s->p)); \
s->p++; \
v = v << 8; \
v = v | *((unsigned char*)(s->p)); \
s->p++; \
}
20 years ago
/******************************************************************************/
21 years ago
#define out_uint8(s, v) \
{ \
20 years ago
*(s->p) = (unsigned char)(v); \
21 years ago
s->p++; \
}
20 years ago
/******************************************************************************/
#if defined B_ENDIAN || defined NEED_ALIGN
#define out_uint16_le(s, v) \
{ \
*(s->p) = (unsigned char)(v); \
s->p++; \
*(s->p) = (unsigned char)((v) >> 8); \
s->p++; \
}
#else
21 years ago
#define out_uint16_le(s, v) \
{ \
*((unsigned short*)(s->p)) = (unsigned short)(v); \
s->p += 2; \
}
20 years ago
#endif
21 years ago
20 years ago
/******************************************************************************/
21 years ago
#define out_uint16_be(s, v) \
{ \
20 years ago
*(s->p) = (unsigned char)((v) >> 8); \
21 years ago
s->p++; \
20 years ago
*(s->p) = (unsigned char)(v); \
21 years ago
s->p++; \
}
20 years ago
/******************************************************************************/
#if defined B_ENDIAN || defined NEED_ALIGN
#define out_uint32_le(s, v) \
{ \
*(s->p) = (unsigned char)(v); \
s->p++; \
*(s->p) = (unsigned char)((v) >> 8); \
s->p++; \
*(s->p) = (unsigned char)((v) >> 16); \
s->p++; \
*(s->p) = (unsigned char)((v) >> 24); \
s->p++; \
}
#else
21 years ago
#define out_uint32_le(s, v) \
{ \
*((unsigned long*)(s->p)) = (v); \
s->p += 4; \
}
20 years ago
#endif
21 years ago
20 years ago
/******************************************************************************/
21 years ago
#define out_uint32_be(s, v) \
{ \
20 years ago
*(s->p) = (unsigned char)((v) >> 24); \
21 years ago
s->p++; \
20 years ago
*(s->p) = (unsigned char)((v) >> 16); \
21 years ago
s->p++; \
20 years ago
*(s->p) = (unsigned char)((v) >> 8); \
21 years ago
s->p++; \
20 years ago
*(s->p) = (unsigned char)(v); \
21 years ago
s->p++; \
}
20 years ago
/******************************************************************************/
21 years ago
#define in_uint8p(s, v, n) \
{ \
v = s->p; \
s->p += n; \
}
20 years ago
/******************************************************************************/
21 years ago
#define in_uint8a(s, v, n) \
{ \
g_memcpy(v, s->p, n); \
s->p += n; \
}
20 years ago
/******************************************************************************/
21 years ago
#define in_uint8s(s, n) \
{ \
s->p += n; \
}
20 years ago
/******************************************************************************/
21 years ago
#define out_uint8p(s, v, n) \
{ \
g_memcpy(s->p, v, n); \
s->p += n; \
}
20 years ago
/******************************************************************************/
21 years ago
#define out_uint8a(s, v, n) \
{ \
out_uint8p(s, v, n); \
}
20 years ago
/******************************************************************************/
21 years ago
#define out_uint8s(s, n) \
{ \
g_memset(s->p, 0, n); \
s->p += n; \
}