|
|
|
@ -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
|
|
|
|
|