Commit 46b416d7 authored by Pekka Pessi's avatar Pekka Pessi

msg: unobfuscated casts of msg_header_t

Ignore-this: 23d5cbaa736941987e871f5238c12a79

darcs-hash:20090513163719-db55f-9c74b2be5a96d83d393ec4c5d32dd4007676b3cd.gz
parent c9887a6b
......@@ -130,7 +130,7 @@ issize_t msg_auth_e(char b[], isize_t bsiz, msg_header_t const *h, int f)
*/
isize_t msg_auth_dup_xtra(msg_header_t const *h, isize_t offset)
{
msg_auth_t const *au = h->sh_auth;
msg_auth_t const *au = (msg_auth_t *)h;
MSG_PARAMS_SIZE(offset, au->au_params);
offset += MSG_STRING_SIZE(au->au_scheme);
......@@ -144,8 +144,8 @@ char *msg_auth_dup_one(msg_header_t *dst,
char *b,
isize_t xtra)
{
msg_auth_t *au = dst->sh_auth;
msg_auth_t const *o = src->sh_auth;
msg_auth_t *au = (msg_auth_t *)dst;
msg_auth_t const *o = (msg_auth_t const *)src;
char *end = b + xtra;
b = msg_params_dup(&au->au_params, o->au_params, b, xtra);
......
......@@ -235,8 +235,10 @@ msg_payload_t *msg_payload_create(su_home_t *home, void const *data, usize_t len
/** Parse payload. */
issize_t msg_payload_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{
h->sh_payload->pl_len = slen;
h->sh_payload->pl_data = s;
msg_payload_t *pl = (msg_payload_t *)h;
pl->pl_len = slen;
pl->pl_data = s;
h->sh_len = slen;
h->sh_data = s;
......@@ -246,11 +248,14 @@ issize_t msg_payload_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
issize_t msg_payload_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
size_t len = h->sh_payload->pl_len;
msg_payload_t *pl = (msg_payload_t *)h;
size_t len = pl->pl_len;
if (bsiz > 0) {
memcpy(b, h->sh_payload->pl_data, bsiz > len ? len : bsiz);
b[bsiz > len ? len : bsiz - 1] = '\0';
if (len < bsiz)
memcpy(b, pl->pl_data, len), b[len] = '\0';
else
memcpy(b, pl->pl_data, bsiz - 1), b[bsiz - 1] = '\0';
}
return len;
......@@ -258,7 +263,8 @@ issize_t msg_payload_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
isize_t msg_payload_dup_xtra(msg_header_t const *h, isize_t offset)
{
return offset + h->sh_payload->pl_len + 1;
msg_payload_t *pl = (msg_payload_t *)h;
return offset + pl->pl_len + 1;
}
char *msg_payload_dup_one(msg_header_t *dst,
......@@ -266,13 +272,13 @@ char *msg_payload_dup_one(msg_header_t *dst,
char *b,
isize_t xtra)
{
msg_payload_t *pl = dst->sh_payload;
msg_payload_t const *o = src->sh_payload;
msg_payload_t *pl = (msg_payload_t *)dst;
msg_payload_t const *o = (msg_payload_t const *)src;
memcpy(pl->pl_data = b, o->pl_data, pl->pl_len = o->pl_len);
pl->pl_common->h_data = pl->pl_data;
pl->pl_common->h_len = pl->pl_len;
dst->sh_data = pl->pl_data;
dst->sh_len = pl->pl_len;
pl->pl_data[pl->pl_len] = 0; /* NUL terminate just in case */
......@@ -322,12 +328,13 @@ MSG_HEADER_CLASS(msg_, separator, NULL, "", sep_common, single,
issize_t msg_separator_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{
int len = CRLF_TEST(s);
msg_separator_t *sep = (msg_separator_t *)h;
if (len == 0 && slen > 0)
return -1;
memcpy(h->sh_separator->sep_data, s, len);
h->sh_separator->sep_data[len] = '\0';
memcpy(sep->sep_data, s, len);
sep->sep_data[len] = '\0';
return 0;
}
......@@ -335,19 +342,20 @@ issize_t msg_separator_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen
/** Encode a separator line. */
issize_t msg_separator_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
size_t n = strlen(h->sh_separator->sep_data);
msg_separator_t const *sep = (msg_separator_t const *)h;
size_t n = strlen(sep->sep_data);
if (bsiz > n)
strcpy(b, h->sh_separator->sep_data);
strcpy(b, sep->sep_data);
return (issize_t)n;
}
msg_separator_t *msg_separator_create(su_home_t *home)
{
msg_separator_t *sep =
msg_header_alloc(home, msg_separator_class, 0)->sh_separator;
msg_separator_t *sep;
sep = (msg_separator_t *)msg_header_alloc(home, msg_separator_class, 0);
if (sep)
strcpy(sep->sep_data, CRLF);
......
......@@ -68,7 +68,8 @@ issize_t msg_generic_d(su_home_t *home,
char *s,
isize_t slen)
{
h->sh_generic->g_string = s;
msg_generic_t *g = (msg_generic_t *)h;
g->g_string = s;
return 0;
}
......@@ -80,7 +81,7 @@ issize_t msg_generic_d(su_home_t *home,
*/
issize_t msg_generic_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
msg_generic_t const *g = h->sh_generic;
msg_generic_t const *g = (msg_generic_t const *)h;
size_t n = strlen(g->g_string);
if (bsiz > n)
......@@ -92,7 +93,7 @@ issize_t msg_generic_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
/** Calculate the size of strings associated with a @c msg_generic_t object. */
isize_t msg_generic_dup_xtra(msg_header_t const *h, isize_t offset)
{
msg_generic_t const *g = h->sh_generic;
msg_generic_t const *g = (msg_generic_t const *)h;
return offset + MSG_STRING_SIZE(g->g_string);
}
......@@ -102,8 +103,10 @@ char *msg_generic_dup_one(msg_header_t *dst,
char *b,
isize_t xtra)
{
msg_generic_t *g = (msg_generic_t *)dst;
msg_generic_t const *o = (msg_generic_t const *)src;
char *end = b + xtra;
MSG_STRING_DUP(b, dst->sh_generic->g_string, src->sh_generic->g_string);
MSG_STRING_DUP(b, g->g_string, o->g_string);
assert(b <= end); (void)end;
return b;
}
......@@ -117,7 +120,7 @@ issize_t msg_numeric_d(su_home_t *home,
uint32_t value = 0;
issize_t retval = msg_uint32_d(&s, &value);
assert(x->x_common->h_class->hc_size >= sizeof *x);
assert(h->sh_class->hc_size >= sizeof *x);
x->x_value = value;
......@@ -150,15 +153,17 @@ issize_t msg_numeric_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
issize_t msg_list_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{
return msg_commalist_d(home, &s, &h->sh_list->k_items, NULL);
msg_list_t *k = (msg_list_t *)h;
return msg_commalist_d(home, &s, &k->k_items, NULL);
}
issize_t msg_list_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
msg_list_t *k = (msg_list_t *)h;
int compact = MSG_IS_COMPACT(flags);
char *b0 = b, *end = b + bsiz;
MSG_COMMALIST_E(b, end, h->sh_list->k_items, compact);
MSG_COMMALIST_E(b, end, k->k_items, compact);
MSG_TERM_E(b, end);
return b - b0;
......@@ -176,7 +181,8 @@ issize_t msg_list_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
*/
isize_t msg_list_dup_xtra(msg_header_t const *h, isize_t offset)
{
MSG_PARAMS_SIZE(offset, h->sh_list->k_items);
msg_list_t const *k = (msg_list_t const *)h;
MSG_PARAMS_SIZE(offset, k->k_items);
return offset;
}
......@@ -185,10 +191,12 @@ char *msg_list_dup_one(msg_header_t *dst,
char *b,
isize_t xtra)
{
msg_list_t *k = (msg_list_t *)dst;
msg_list_t const *o = (msg_list_t const *)src;
char *end = b + xtra;
msg_param_t const ** items = (msg_param_t const **)&dst->sh_list->k_items;
msg_param_t const ** items = (msg_param_t const **)&k->k_items;
b = msg_params_dup(items, src->sh_list->k_items, b, xtra);
b = msg_params_dup(items, o->k_items, b, xtra);
assert(b <= end); (void)end;
......
......@@ -1003,7 +1003,7 @@ extract_next(msg_t *msg, msg_pub_t *mo, char *b, isize_t bsiz,
/** Extract a header. */
issize_t msg_extract_header(msg_t *msg, msg_pub_t *mo,
char b[], isize_t bsiz, int eos)
char b[], isize_t bsiz, int eos)
{
return extract_header(msg, mo, b, bsiz, eos, 0);
}
......@@ -1143,6 +1143,7 @@ msg_header_t *header_parse(msg_t *msg, msg_pub_t *mo,
/* XXX - This should be done by msg_header_free_all() */
msg_header_t *h_next;
msg_param_t *h_params;
msg_error_t *er;
while (h) {
h_next = h->sh_next;
......@@ -1157,10 +1158,12 @@ msg_header_t *header_parse(msg_t *msg, msg_pub_t *mo,
/* XXX - This should be done by msg_header_free_all() */
hr = msg->m_class->mc_error;
h = msg_header_alloc(home, hr->hr_class, 0);
if (!h)
return h;
er = (msg_error_t *)h;
h->sh_error->er_name = hc->hc_name;
if (!er)
return NULL;
er->er_name = hc->hc_name;
hh = (msg_header_t **)((char *)mo + hr->hr_offset);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment