use do ... while (0) style for parse.h

ulab-original
jsorg71 15 years ago
parent 0156c1448d
commit d83ebaa97a

@ -1,5 +1,5 @@
/*
Copyright (c) 2004-2009 Jay Sorg
Copyright (c) 2004-2010 Jay Sorg
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@ -64,12 +64,10 @@ struct stream
/******************************************************************************/
#define make_stream(s) \
{ \
(s) = (struct stream*)g_malloc(sizeof(struct stream), 1); \
}
(s) = (struct stream*)g_malloc(sizeof(struct stream), 1)
/******************************************************************************/
#define init_stream(s, v) \
#define init_stream(s, v) do \
{ \
if ((v) > (s)->size) \
{ \
@ -80,54 +78,50 @@ struct stream
(s)->p = (s)->data; \
(s)->end = (s)->data; \
(s)->next_packet = 0; \
}
} while (0)
/******************************************************************************/
#define free_stream(s) \
#define free_stream(s) do \
{ \
if ((s) != 0) \
{ \
g_free((s)->data); \
} \
g_free((s)); \
} \
} while (0)
/******************************************************************************/
#define s_push_layer(s, h, n) \
#define s_push_layer(s, h, n) do \
{ \
(s)->h = (s)->p; \
(s)->p += (n); \
}
} while (0)
/******************************************************************************/
#define s_pop_layer(s, h) \
{ \
(s)->p = (s)->h; \
}
(s)->p = (s)->h
/******************************************************************************/
#define s_mark_end(s) \
{ \
(s)->end = (s)->p; \
}
(s)->end = (s)->p
/******************************************************************************/
#define in_sint8(s, v) \
#define in_sint8(s, v) do \
{ \
(v) = *((signed char*)((s)->p)); \
(s)->p++; \
}
} while (0)
/******************************************************************************/
#define in_uint8(s, v) \
#define in_uint8(s, v) do \
{ \
(v) = *((unsigned char*)((s)->p)); \
(s)->p++; \
}
} while (0)
/******************************************************************************/
#if defined(B_ENDIAN) || defined(NEED_ALIGN)
#define in_sint16_le(s, v) \
#define in_sint16_le(s, v) do \
{ \
(v) = (signed short) \
( \
@ -135,18 +129,18 @@ struct stream
(*((unsigned char*)((s)->p + 1)) << 8) \
); \
(s)->p += 2; \
}
} while (0)
#else
#define in_sint16_le(s, v) \
#define in_sint16_le(s, v) do \
{ \
(v) = *((signed short*)((s)->p)); \
(s)->p += 2; \
}
} while (0)
#endif
/******************************************************************************/
#if defined(B_ENDIAN) || defined(NEED_ALIGN)
#define in_uint16_le(s, v) \
#define in_uint16_le(s, v) do \
{ \
(v) = (unsigned short) \
( \
@ -154,28 +148,28 @@ struct stream
(*((unsigned char*)((s)->p + 1)) << 8) \
); \
(s)->p += 2; \
}
} while (0)
#else
#define in_uint16_le(s, v) \
#define in_uint16_le(s, v) do \
{ \
(v) = *((unsigned short*)((s)->p)); \
(s)->p += 2; \
}
} while (0)
#endif
/******************************************************************************/
#define in_uint16_be(s, v) \
#define in_uint16_be(s, v) do \
{ \
(v) = *((unsigned char*)((s)->p)); \
(s)->p++; \
(v) <<= 8; \
(v) |= *((unsigned char*)((s)->p)); \
(s)->p++; \
}
} while (0)
/******************************************************************************/
#if defined(B_ENDIAN) || defined(NEED_ALIGN)
#define in_uint32_le(s, v) \
#define in_uint32_le(s, v) do \
{ \
(v) = (unsigned int) \
( \
@ -185,17 +179,17 @@ struct stream
(*((unsigned char*)((s)->p + 3)) << 24) \
); \
(s)->p += 4; \
}
} while (0)
#else
#define in_uint32_le(s, v) \
#define in_uint32_le(s, v) do \
{ \
(v) = *((unsigned int*)((s)->p)); \
(s)->p += 4; \
}
} while (0)
#endif
/******************************************************************************/
#define in_uint32_be(s, v) \
#define in_uint32_be(s, v) do \
{ \
(v) = *((unsigned char*)((s)->p)); \
(s)->p++; \
@ -208,44 +202,44 @@ struct stream
(v) <<= 8; \
(v) |= *((unsigned char*)((s)->p)); \
(s)->p++; \
}
} while (0)
/******************************************************************************/
#define out_uint8(s, v) \
#define out_uint8(s, v) do \
{ \
*((s)->p) = (unsigned char)(v); \
(s)->p++; \
}
} while (0)
/******************************************************************************/
#if defined(B_ENDIAN) || defined(NEED_ALIGN)
#define out_uint16_le(s, v) \
#define out_uint16_le(s, v) do \
{ \
*((s)->p) = (unsigned char)((v) >> 0); \
(s)->p++; \
*((s)->p) = (unsigned char)((v) >> 8); \
(s)->p++; \
}
} while (0)
#else
#define out_uint16_le(s, v) \
#define out_uint16_le(s, v) do \
{ \
*((unsigned short*)((s)->p)) = (unsigned short)(v); \
(s)->p += 2; \
}
} while (0)
#endif
/******************************************************************************/
#define out_uint16_be(s, v) \
#define out_uint16_be(s, v) do \
{ \
*((s)->p) = (unsigned char)((v) >> 8); \
(s)->p++; \
*((s)->p) = (unsigned char)((v) >> 0); \
(s)->p++; \
}
} while (0)
/******************************************************************************/
#if defined(B_ENDIAN) || defined(NEED_ALIGN)
#define out_uint32_le(s, v) \
#define out_uint32_le(s, v) do \
{ \
*((s)->p) = (unsigned char)((v) >> 0); \
(s)->p++; \
@ -255,17 +249,17 @@ struct stream
(s)->p++; \
*((s)->p) = (unsigned char)((v) >> 24); \
(s)->p++; \
}
} while (0)
#else
#define out_uint32_le(s, v) \
#define out_uint32_le(s, v) do \
{ \
*((unsigned int*)((s)->p)) = (v); \
(s)->p += 4; \
}
} while (0)
#endif
/******************************************************************************/
#define out_uint32_be(s, v) \
#define out_uint32_be(s, v) do \
{ \
*((s)->p) = (unsigned char)((v) >> 24); \
s->p++; \
@ -275,46 +269,42 @@ struct stream
s->p++; \
*((s)->p) = (unsigned char)(v); \
(s)->p++; \
}
} while (0)
/******************************************************************************/
#define in_uint8p(s, v, n) \
#define in_uint8p(s, v, n) do \
{ \
(v) = (s)->p; \
(s)->p += (n); \
}
} while (0)
/******************************************************************************/
#define in_uint8a(s, v, n) \
#define in_uint8a(s, v, n) do \
{ \
g_memcpy((v), (s)->p, (n)); \
(s)->p += (n); \
}
} while (0)
/******************************************************************************/
#define in_uint8s(s, n) \
{ \
(s)->p += (n); \
}
(s)->p += (n)
/******************************************************************************/
#define out_uint8p(s, v, n) \
#define out_uint8p(s, v, n) do \
{ \
g_memcpy((s)->p, (v), (n)); \
(s)->p += (n); \
}
} while (0)
/******************************************************************************/
#define out_uint8a(s, v, n) \
{ \
out_uint8p((s), (v), (n)); \
}
out_uint8p((s), (v), (n))
/******************************************************************************/
#define out_uint8s(s, n) \
#define out_uint8s(s, n) do \
{ \
g_memset((s)->p, 0, (n)); \
(s)->p += (n); \
}
} while (0)
#endif

@ -319,7 +319,7 @@ libxrdp_send_bitmap(struct xrdp_session* session, int width, int height,
for (j = 0; j < lines_sending; j++)
{
q = q - line_size;
out_uint8a(s, q, line_size) /* B_ENDIAN doesn't work here, todo */
out_uint8a(s, q, line_size); /* B_ENDIAN doesn't work here, todo */
out_uint8s(s, e * Bpp);
}
s_mark_end(s);

@ -662,11 +662,11 @@ xrdp_orders_screen_blt(struct xrdp_orders* self, int x, int y,
present |= 0x40;
if (order_flags & RDP_ORDER_DELTA)
{
out_uint8(self->out_s, srcy - self->orders_state.scr_blt_srcy)
out_uint8(self->out_s, srcy - self->orders_state.scr_blt_srcy);
}
else
{
out_uint16_le(self->out_s, srcy)
out_uint16_le(self->out_s, srcy);
}
self->orders_state.scr_blt_srcy = srcy;
}
@ -911,7 +911,7 @@ xrdp_orders_dest_blt(struct xrdp_orders* self, int x, int y,
out_uint8s(self->out_s, 1);
if (order_flags & RDP_ORDER_CHANGE)
{
out_uint8(self->out_s, self->orders_state.last_order)
out_uint8(self->out_s, self->orders_state.last_order);
}
present = 0;
/* present, set later, 1 byte */
@ -1067,7 +1067,7 @@ xrdp_orders_line(struct xrdp_orders* self, int mix_mode,
if (mix_mode != self->orders_state.line_mix_mode)
{
present |= 0x0001;
out_uint16_le(self->out_s, mix_mode)
out_uint16_le(self->out_s, mix_mode);
self->orders_state.line_mix_mode = mix_mode;
}
if (startx != self->orders_state.line_startx)
@ -1125,15 +1125,15 @@ xrdp_orders_line(struct xrdp_orders* self, int mix_mode,
if (bg_color != self->orders_state.line_bg_color)
{
present |= 0x0020;
out_uint8(self->out_s, bg_color)
out_uint8(self->out_s, bg_color >> 8)
out_uint8(self->out_s, bg_color >> 16)
out_uint8(self->out_s, bg_color);
out_uint8(self->out_s, bg_color >> 8);
out_uint8(self->out_s, bg_color >> 16);
self->orders_state.line_bg_color = bg_color;
}
if (rop != self->orders_state.line_rop)
{
present |= 0x0040;
out_uint8(self->out_s, rop)
out_uint8(self->out_s, rop);
self->orders_state.line_rop = rop;
}
if (pen == 0)
@ -1144,21 +1144,21 @@ xrdp_orders_line(struct xrdp_orders* self, int mix_mode,
if (pen->style != self->orders_state.line_pen.style)
{
present |= 0x0080;
out_uint8(self->out_s, pen->style)
out_uint8(self->out_s, pen->style);
self->orders_state.line_pen.style = pen->style;
}
if (pen->width != self->orders_state.line_pen.width)
{
present |= 0x0100;
out_uint8(self->out_s, pen->width)
out_uint8(self->out_s, pen->width);
self->orders_state.line_pen.width = pen->width;
}
if (pen->color != self->orders_state.line_pen.color)
{
present |= 0x0200;
out_uint8(self->out_s, pen->color)
out_uint8(self->out_s, pen->color >> 8)
out_uint8(self->out_s, pen->color >> 16)
out_uint8(self->out_s, pen->color);
out_uint8(self->out_s, pen->color >> 8);
out_uint8(self->out_s, pen->color >> 16);
self->orders_state.line_pen.color = pen->color;
}
xrdp_order_pack_small_or_tiny(self, order_flags_ptr, order_flags,
@ -1224,7 +1224,7 @@ xrdp_orders_mem_blt(struct xrdp_orders* self, int cache_id,
out_uint8s(self->out_s, 1);
if (order_flags & RDP_ORDER_CHANGE)
{
out_uint8(self->out_s, self->orders_state.last_order)
out_uint8(self->out_s, self->orders_state.last_order);
}
present = 0;
/* present, set later, 2 bytes */
@ -1423,17 +1423,17 @@ xrdp_orders_text(struct xrdp_orders* self,
if (fg_color != self->orders_state.text_fg_color)
{
present |= 0x000010;
out_uint8(self->out_s, fg_color)
out_uint8(self->out_s, fg_color >> 8)
out_uint8(self->out_s, fg_color >> 16)
out_uint8(self->out_s, fg_color);
out_uint8(self->out_s, fg_color >> 8);
out_uint8(self->out_s, fg_color >> 16);
self->orders_state.text_fg_color = fg_color;
}
if (bg_color != self->orders_state.text_bg_color)
{
present |= 0x000020;
out_uint8(self->out_s, bg_color)
out_uint8(self->out_s, bg_color >> 8)
out_uint8(self->out_s, bg_color >> 16)
out_uint8(self->out_s, bg_color);
out_uint8(self->out_s, bg_color >> 8);
out_uint8(self->out_s, bg_color >> 16);
self->orders_state.text_bg_color = bg_color;
}
if (clip_left != self->orders_state.text_clip_left)

@ -234,7 +234,7 @@ clipboard_init(void)
{
g_clip_up = 1;
make_stream(g_ins);
init_stream(g_ins, 8192)
init_stream(g_ins, 8192);
}
else
{
@ -622,7 +622,7 @@ clipboard_data_in(struct stream* s, int chan_id, int chan_flags, int length,
{
if (chan_flags & 1)
{
init_stream(g_ins, total_length)
init_stream(g_ins, total_length);
}
in_uint8a(s, g_ins->end, length);
g_ins->end += length;

@ -398,7 +398,7 @@ _scp_v1c_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
return SCP_CLIENT_STATE_SEQUENCE_ERR;
}
in_uint16_be(c->in_s, cmd)
in_uint16_be(c->in_s, cmd);
if (cmd == 2) /* connection denied */
{
in_uint16_be(c->in_s, dim);

@ -378,7 +378,7 @@ _scp_v1c_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
return SCP_CLIENT_STATE_SEQUENCE_ERR;
}
in_uint16_be(c->in_s, cmd)
in_uint16_be(c->in_s, cmd);
if (cmd == SCP_CMD_MNG_LOGIN_ALLOW) /* connection ok */
{
log_message(s_log, LOG_LEVEL_INFO, "[v1c_mng:%d] connection ok", __LINE__);

@ -203,7 +203,7 @@ scp_v1s_deny_connection(struct SCP_CONNECTION* c, char* reason)
out_uint32_be(c->out_s, rlen+14);
out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
out_uint16_be(c->out_s, 2);
out_uint16_be(c->out_s, rlen)
out_uint16_be(c->out_s, rlen);
out_uint8p(c->out_s, reason, rlen);
if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, rlen+14))

@ -152,7 +152,7 @@ scp_v1s_mng_deny_connection(struct SCP_CONNECTION* c, char* reason)
out_uint32_be(c->out_s, rlen+14);
out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_DENY);
out_uint16_be(c->out_s, rlen)
out_uint16_be(c->out_s, rlen);
out_uint8p(c->out_s, reason, rlen);
if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, rlen+14))
@ -307,7 +307,7 @@ _scp_v1s_mng_check_response(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
return SCP_SERVER_STATE_SEQUENCE_ERR;
}
in_uint16_be(c->in_s, cmd)
in_uint16_be(c->in_s, cmd);
if (cmd == SCP_CMD_MNG_LIST_REQ) /* request session list */
{
log_message(s_log, LOG_LEVEL_INFO, "[v1s_mng:%d] request session list", __LINE__);

Loading…
Cancel
Save