Commit a19d75a4 authored by Pekka Pessi's avatar Pekka Pessi

msg: checking header class of msg_numeric_t type headers when encoding/decoding

darcs-hash:20070919142729-65a35-e6bf5e6145af7b745c0d6230126386f9096c48a9.gz
parent bad27123
......@@ -112,10 +112,13 @@ issize_t msg_numeric_d(su_home_t *home,
char *s,
isize_t slen)
{
msg_numeric_t *x = (msg_numeric_t *)h;
uint32_t value = 0;
issize_t retval = msg_uint32_d(&s, &value);
h->sh_numeric->x_value = value;
assert(x->x_common->h_class->hc_size >= sizeof *x);
x->x_value = value;
if (*s)
return -1;
......@@ -125,12 +128,14 @@ issize_t msg_numeric_d(su_home_t *home,
issize_t msg_numeric_e(char b[], isize_t bsiz, msg_header_t const *h, int flags)
{
uint32_t value = h->sh_numeric->x_value;
msg_numeric_t *x = (msg_numeric_t *)h;
assert(x->x_common->h_class->hc_size >= sizeof *x);
if (h->sh_numeric->x_value > 0xffffffff)
if (x->x_value > 0xffffffffU)
return -1;
return snprintf(b, bsiz, "%lu", (unsigned long)value);
return snprintf(b, bsiz, "%lu", x->x_value);
}
/* ====================================================================== */
......
......@@ -134,7 +134,8 @@ struct msg_pub_s {
/** Numeric header.
*
* A numeric header has a 32-bit integer as its value.
* A numeric header has value range of a 32-bit, 0..4294967295. The @a
* x_value field is unsigned long, however.
*/
struct msg_numeric_s {
msg_common_t x_common[1]; /**< Common fragment info */
......
......@@ -193,6 +193,14 @@ char *msg_status_dup_one(msg_header_t *dst, msg_header_t const *src,
return b;
}
msg_hclass_t test_numeric_class[] =
MSG_HEADER_CLASS(msg_, numeric, "Numeric", "", x_common,
single, msg_generic, msg_generic);
msg_hclass_t test_auth_class[] =
MSG_HEADER_CLASS(msg_, auth, "Auth", "", au_params,
append, msg_auth, msg_generic);
/** Extract the message body, including separator line.
*
* @param[in,out] msg message object
......@@ -411,3 +419,4 @@ int tst_add_tl(msg_t *msg, msg_test_t *tst,
return t ? -1 : 0;
}
......@@ -110,6 +110,9 @@ typedef struct msg_test_s {
msg_content_encoding_t *msg_content_encoding;
/**< Content-Encoding */
msg_content_length_t *msg_content_length; /**< Content-Length */
msg_auth_t *msg_auth; /**< Auth (testing) */
msg_numeric_t *msg_numeric; /**< Numeric (testing) */
/* === Headers end here */
msg_unknown_t *msg_unknown;
......@@ -160,6 +163,17 @@ msg_test_t *msg_test_public(msg_t *msg)
return (msg_test_t *)msg_public(msg, MSG_TEST_PROTOCOL_TAG);
}
#define msg_auth_class test_auth_class
#define msg_numeric_class test_numeric_class
enum {
msg_auth_hash = 22894,
msg_numeric_hash = 24435
};
SOFIAPUBVAR msg_hclass_t test_auth_class[1], test_numeric_class[1];
SOFIA_END_DECLS
#endif /* !defined(TEST_CLASS_H) */
......@@ -127,7 +127,7 @@ static int msg_time_test(void)
char *s;
msg_numeric_t x[1];
memset(x, 0, sizeof (x));
memset(x, 0, sizeof (x)); x->x_common->h_class = test_numeric_class;
TEST_1(msg_numeric_d(NULL, (msg_header_t *)x, s = error1, strlen(error1)) < 0);
}
......
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