Wed May 13 11:37:19 CDT 2009 Pekka Pessi <first.last@nokia.com>

* msg: unobfuscated casts of msg_header_t



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13341 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2009-05-15 16:09:12 +00:00
parent ae9f6cc6d1
commit 8937b3a4e1
5 changed files with 53 additions and 34 deletions

View File

@ -1 +1 @@
Fri May 15 11:07:28 CDT 2009 Fri May 15 11:08:48 CDT 2009

View File

@ -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) 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); MSG_PARAMS_SIZE(offset, au->au_params);
offset += MSG_STRING_SIZE(au->au_scheme); offset += MSG_STRING_SIZE(au->au_scheme);
@ -144,8 +144,8 @@ char *msg_auth_dup_one(msg_header_t *dst,
char *b, char *b,
isize_t xtra) isize_t xtra)
{ {
msg_auth_t *au = dst->sh_auth; msg_auth_t *au = (msg_auth_t *)dst;
msg_auth_t const *o = src->sh_auth; msg_auth_t const *o = (msg_auth_t const *)src;
char *end = b + xtra; char *end = b + xtra;
b = msg_params_dup(&au->au_params, o->au_params, b, xtra); b = msg_params_dup(&au->au_params, o->au_params, b, xtra);

View File

@ -235,8 +235,10 @@ msg_payload_t *msg_payload_create(su_home_t *home, void const *data, usize_t len
/** Parse payload. */ /** Parse payload. */
issize_t msg_payload_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen) issize_t msg_payload_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{ {
h->sh_payload->pl_len = slen; msg_payload_t *pl = (msg_payload_t *)h;
h->sh_payload->pl_data = s;
pl->pl_len = slen;
pl->pl_data = s;
h->sh_len = slen; h->sh_len = slen;
h->sh_data = s; 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) 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) { if (bsiz > 0) {
memcpy(b, h->sh_payload->pl_data, bsiz > len ? len : bsiz); if (len < bsiz)
b[bsiz > len ? len : bsiz - 1] = '\0'; memcpy(b, pl->pl_data, len), b[len] = '\0';
else
memcpy(b, pl->pl_data, bsiz - 1), b[bsiz - 1] = '\0';
} }
return len; 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) 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, char *msg_payload_dup_one(msg_header_t *dst,
@ -266,13 +272,13 @@ char *msg_payload_dup_one(msg_header_t *dst,
char *b, char *b,
isize_t xtra) isize_t xtra)
{ {
msg_payload_t *pl = dst->sh_payload; msg_payload_t *pl = (msg_payload_t *)dst;
msg_payload_t const *o = src->sh_payload; msg_payload_t const *o = (msg_payload_t const *)src;
memcpy(pl->pl_data = b, o->pl_data, pl->pl_len = o->pl_len); memcpy(pl->pl_data = b, o->pl_data, pl->pl_len = o->pl_len);
pl->pl_common->h_data = pl->pl_data; dst->sh_data = pl->pl_data;
pl->pl_common->h_len = pl->pl_len; dst->sh_len = pl->pl_len;
pl->pl_data[pl->pl_len] = 0; /* NUL terminate just in case */ 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) issize_t msg_separator_d(su_home_t *home, msg_header_t *h, char *s, isize_t slen)
{ {
int len = CRLF_TEST(s); int len = CRLF_TEST(s);
msg_separator_t *sep = (msg_separator_t *)h;
if (len == 0 && slen > 0) if (len == 0 && slen > 0)
return -1; return -1;
memcpy(h->sh_separator->sep_data, s, len); memcpy(sep->sep_data, s, len);
h->sh_separator->sep_data[len] = '\0'; sep->sep_data[len] = '\0';
return 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. */ /** Encode a separator line. */
issize_t msg_separator_e(char b[], isize_t bsiz, msg_header_t const *h, int flags) 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) if (bsiz > n)
strcpy(b, h->sh_separator->sep_data); strcpy(b, sep->sep_data);
return (issize_t)n; return (issize_t)n;
} }
msg_separator_t *msg_separator_create(su_home_t *home) msg_separator_t *msg_separator_create(su_home_t *home)
{ {
msg_separator_t *sep = msg_separator_t *sep;
msg_header_alloc(home, msg_separator_class, 0)->sh_separator;
sep = (msg_separator_t *)msg_header_alloc(home, msg_separator_class, 0);
if (sep) if (sep)
strcpy(sep->sep_data, CRLF); strcpy(sep->sep_data, CRLF);

View File

@ -68,7 +68,8 @@ issize_t msg_generic_d(su_home_t *home,
char *s, char *s,
isize_t slen) isize_t slen)
{ {
h->sh_generic->g_string = s; msg_generic_t *g = (msg_generic_t *)h;
g->g_string = s;
return 0; 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) 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); size_t n = strlen(g->g_string);
if (bsiz > n) 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. */ /** 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) 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); return offset + MSG_STRING_SIZE(g->g_string);
} }
@ -102,8 +103,10 @@ char *msg_generic_dup_one(msg_header_t *dst,
char *b, char *b,
isize_t xtra) 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; 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; assert(b <= end); (void)end;
return b; return b;
} }
@ -117,7 +120,7 @@ issize_t msg_numeric_d(su_home_t *home,
uint32_t value = 0; uint32_t value = 0;
issize_t retval = msg_uint32_d(&s, &value); 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; 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) 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) 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); int compact = MSG_IS_COMPACT(flags);
char *b0 = b, *end = b + bsiz; 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); MSG_TERM_E(b, end);
return b - b0; 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) 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; return offset;
} }
@ -185,10 +191,12 @@ char *msg_list_dup_one(msg_header_t *dst,
char *b, char *b,
isize_t xtra) 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; 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; assert(b <= end); (void)end;

View File

@ -1003,7 +1003,7 @@ extract_next(msg_t *msg, msg_pub_t *mo, char *b, isize_t bsiz,
/** Extract a header. */ /** Extract a header. */
issize_t msg_extract_header(msg_t *msg, msg_pub_t *mo, 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); 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() */ /* XXX - This should be done by msg_header_free_all() */
msg_header_t *h_next; msg_header_t *h_next;
msg_param_t *h_params; msg_param_t *h_params;
msg_error_t *er;
while (h) { while (h) {
h_next = h->sh_next; 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() */ /* XXX - This should be done by msg_header_free_all() */
hr = msg->m_class->mc_error; hr = msg->m_class->mc_error;
h = msg_header_alloc(home, hr->hr_class, 0); h = msg_header_alloc(home, hr->hr_class, 0);
if (!h) er = (msg_error_t *)h;
return 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); hh = (msg_header_t **)((char *)mo + hr->hr_offset);
} }
} }