summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--xrdp/parse.h111
-rw-r--r--xrdp/xrdp.h20
-rw-r--r--xrdp/xrdp_orders.c39
3 files changed, 141 insertions, 29 deletions
diff --git a/xrdp/parse.h b/xrdp/parse.h
index 05d0e4b3..057ef002 100644
--- a/xrdp/parse.h
+++ b/xrdp/parse.h
@@ -20,7 +20,12 @@
/* modified for xrdp */
/* this is a super fast stream method, you bet */
-/* all little endian for now */
+
+#if defined L_ENDIAN
+#elif defined B_ENDIAN
+#else
+#error Unknown endianness.
+#endif
/* parser state */
struct stream
@@ -38,17 +43,22 @@ struct stream
char* next_packet;
};
+/******************************************************************************/
#define s_check(s) (s->p <= s->end)
+/******************************************************************************/
#define s_check_rem(s, n) (s->p + n <= s->end)
+/******************************************************************************/
#define s_check_end(s) (s->p == s->end)
+/******************************************************************************/
#define make_stream(s) \
{ \
s = (struct stream*)g_malloc(sizeof(struct stream), 1); \
} \
+/******************************************************************************/
#define init_stream(s, v) \
{ \
if (v > s->size) \
@@ -62,6 +72,7 @@ struct stream
s->next_packet = 0; \
}
+/******************************************************************************/
#define free_stream(s) \
{ \
if (s != 0) \
@@ -69,40 +80,71 @@ struct stream
g_free(s); \
} \
+/******************************************************************************/
#define s_push_layer(s, h, n) \
{ \
s->h = s->p; \
s->p += n; \
}
+/******************************************************************************/
#define s_pop_layer(s, h) \
{ \
s->p = s->h; \
}
+/******************************************************************************/
#define s_mark_end(s) \
{ \
s->end = s->p; \
}
+/******************************************************************************/
#define in_uint8(s, v) \
{ \
v = *((unsigned char*)(s->p)); \
s->p++; \
}
+/******************************************************************************/
+#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; \
}
+#endif
+/******************************************************************************/
+#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
#define in_uint16_le(s, v) \
{ \
v = *((unsigned short*)(s->p)); \
s->p += 2; \
}
+#endif
+/******************************************************************************/
#define in_uint16_be(s, v) \
{ \
v = *((unsigned char*)(s->p)); \
@@ -112,12 +154,28 @@ struct stream
s->p++; \
}
+/******************************************************************************/
+#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
#define in_uint32_le(s, v) \
{ \
- v = *(unsigned long*)(s->p); \
+ v = *((unsigned long*)(s->p)); \
s->p += 4; \
}
+#endif
+/******************************************************************************/
#define in_uint32_be(s, v) \
{ \
v = *((unsigned char*)(s->p)); \
@@ -133,72 +191,107 @@ struct stream
s->p++; \
}
+/******************************************************************************/
#define out_uint8(s, v) \
{ \
- *((unsigned char*)(s->p)) = (unsigned char)(v); \
+ *(s->p) = (unsigned char)(v); \
s->p++; \
}
+/******************************************************************************/
+#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
#define out_uint16_le(s, v) \
{ \
*((unsigned short*)(s->p)) = (unsigned short)(v); \
s->p += 2; \
}
+#endif
+/******************************************************************************/
#define out_uint16_be(s, v) \
{ \
- *((unsigned char*)(s->p)) = (unsigned char)((v) >> 8); \
+ *(s->p) = (unsigned char)((v) >> 8); \
s->p++; \
- *((unsigned char*)(s->p)) = (unsigned char)(v); \
+ *(s->p) = (unsigned char)(v); \
s->p++; \
}
+/******************************************************************************/
+#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
#define out_uint32_le(s, v) \
{ \
*((unsigned long*)(s->p)) = (v); \
s->p += 4; \
}
+#endif
+/******************************************************************************/
#define out_uint32_be(s, v) \
{ \
- *((unsigned char*)(s->p)) = (unsigned char)((v) >> 24); \
+ *(s->p) = (unsigned char)((v) >> 24); \
s->p++; \
- *((unsigned char*)(s->p)) = (unsigned char)((v) >> 16); \
+ *(s->p) = (unsigned char)((v) >> 16); \
s->p++; \
- *((unsigned char*)(s->p)) = (unsigned char)((v) >> 8); \
+ *(s->p) = (unsigned char)((v) >> 8); \
s->p++; \
- *((unsigned char*)(s->p)) = (unsigned char)(v); \
+ *(s->p) = (unsigned char)(v); \
s->p++; \
}
+/******************************************************************************/
#define in_uint8p(s, v, n) \
{ \
v = s->p; \
s->p += n; \
}
+/******************************************************************************/
#define in_uint8a(s, v, n) \
{ \
g_memcpy(v, s->p, n); \
s->p += n; \
}
+/******************************************************************************/
#define in_uint8s(s, n) \
{ \
s->p += n; \
}
+/******************************************************************************/
#define out_uint8p(s, v, n) \
{ \
g_memcpy(s->p, v, n); \
s->p += n; \
}
+/******************************************************************************/
#define out_uint8a(s, v, n) \
{ \
out_uint8p(s, v, n); \
}
+/******************************************************************************/
#define out_uint8s(s, n) \
{ \
g_memset(s->p, 0, n); \
diff --git a/xrdp/xrdp.h b/xrdp/xrdp.h
index 7d538840..75b19282 100644
--- a/xrdp/xrdp.h
+++ b/xrdp/xrdp.h
@@ -13,22 +13,36 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2004
main include file
*/
+/* check endianess */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define L_ENDIAN
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define B_ENDIAN
+#endif
+/* check if we need to align data */
+#if defined(__sparc__) || defined(__alpha__) || defined(__hppa__) || \
+ defined(__AIX__) || defined(__PPC__) || defined(__mips__) || \
+ defined(__ia64__)
+#define NEED_ALIGN
+#endif
+/* include other h files */
#include "parse.h"
#include "xrdp_types.h"
#include "constants.h"
-
+/* check for debug */
#ifdef XRDP_DEBUG
#define DEBUG(args) g_printf args;
#else
#define DEBUG(args)
#endif
-
+/* other macros */
#undef MIN
#define MIN(x1, x2) ((x1) < (x2) ? (x1) : (x2))
#undef MAX
@@ -39,7 +53,7 @@
#define LOWORD(in) ((in) & 0x0000ffff)
#undef MAKELONG
#define MAKELONG(hi, lo) ((((hi) & 0xffff) << 16) | ((lo) & 0xffff))
-
+/* font macros */
#define FONT_DATASIZE(f) ((((f)->height * (((f)->width + 7) / 8)) + 3) & ~3);
/* os_calls.c */
diff --git a/xrdp/xrdp_orders.c b/xrdp/xrdp_orders.c
index ba9a953d..7e76e48b 100644
--- a/xrdp/xrdp_orders.c
+++ b/xrdp/xrdp_orders.c
@@ -76,7 +76,8 @@ int xrdp_orders_send(struct xrdp_orders* self)
if (self->order_level == 0)
{
s_mark_end(self->out_s);
- *((short*)self->order_count_ptr) = self->order_count;
+ self->order_count_ptr[0] = self->order_count;
+ self->order_count_ptr[1] = self->order_count >> 8;
if (xrdp_rdp_send_data(self->rdp_layer, self->out_s,
RDP_DATA_PDU_UPDATE) != 0)
rv = 1;
@@ -92,7 +93,8 @@ int xrdp_orders_force_send(struct xrdp_orders* self)
if (self->order_count > 0)
{
s_mark_end(self->out_s);
- *((short*)self->order_count_ptr) = self->order_count;
+ self->order_count_ptr[0] = self->order_count;
+ self->order_count_ptr[1] = self->order_count >> 8;
if (xrdp_rdp_send_data(self->rdp_layer, self->out_s,
RDP_DATA_PDU_UPDATE) != 0)
return 1;
@@ -306,7 +308,7 @@ int xrdp_orders_rect(struct xrdp_orders* self, int x, int y, int cx, int cy,
self->rect_color = (self->rect_color & 0x00ffff) | (color & 0xff0000);
out_uint8(self->out_s, color >> 16);
}
- *present_ptr = present;
+ present_ptr[0] = present;
return 0;
}
@@ -412,7 +414,7 @@ int xrdp_orders_screen_blt(struct xrdp_orders* self, int x, int y,
out_uint16_le(self->out_s, srcy)
self->scr_blt_srcy = srcy;
}
- *present_ptr = present;
+ present_ptr[0] = present;
return 0;
}
@@ -553,7 +555,8 @@ int xrdp_orders_pat_blt(struct xrdp_orders* self, int x, int y,
out_uint8a(self->out_s, brush->pattern + 1, 7);
g_memcpy(self->pat_blt_brush.pattern + 1, brush->pattern + 1, 7);
}
- *((short*)present_ptr) = present;
+ present_ptr[0] = present;
+ present_ptr[1] = present >> 8;
return 0;
}
@@ -639,7 +642,7 @@ int xrdp_orders_dest_blt(struct xrdp_orders* self, int x, int y,
out_uint8(self->out_s, rop);
self->dest_blt_rop = rop;
}
- *present_ptr = present;
+ present_ptr[0] = present;
return 0;
}
@@ -767,7 +770,8 @@ int xrdp_orders_line(struct xrdp_orders* self, int mix_mode,
out_uint8(self->out_s, pen->color >> 16)
self->line_pen.color = pen->color;
}
- *((short*)present_ptr) = present;
+ present_ptr[0] = present;
+ present_ptr[1] = present >> 8;
return 0;
}
@@ -890,7 +894,8 @@ int xrdp_orders_mem_blt(struct xrdp_orders* self, int cache_id,
out_uint16_le(self->out_s, cache_idx);
self->mem_blt_cache_idx = cache_idx;
}
- *((short*)present_ptr) = present;
+ present_ptr[0] = present;
+ present_ptr[1] = present >> 8;
return 0;
}
@@ -1028,16 +1033,16 @@ int xrdp_orders_text(struct xrdp_orders* self,
out_uint16_le(self->out_s, y);
self->text_y = y;
}
- /* always send text */
- present |= 0x200000;
- out_uint8(self->out_s, data_len);
- out_uint8a(self->out_s, data, data_len);
+ {
+ /* always send text */
+ present |= 0x200000;
+ out_uint8(self->out_s, data_len);
+ out_uint8a(self->out_s, data, data_len);
+ }
/* send 3 byte present */
- *present_ptr = present;
- present_ptr++;
- *present_ptr = present >> 8;
- present_ptr++;
- *present_ptr = present >> 16;
+ present_ptr[0] = present;
+ present_ptr[1] = present >> 8;
+ present_ptr[2] = present >> 16;
return 0;
}