Commit afe67990 authored by Pekka Pessi's avatar Pekka Pessi

msg: added msg_make().

darcs-hash:20061128110828-65a35-964f784be3ea3724bb196f68c9efbb0ea78b6edb.gz
parent 921234e8
......@@ -1813,3 +1813,48 @@ issize_t msg_random_token(char token[], isize_t tlen,
return i;
}
/** Parse a message.
*
* Parse a message with parser @a mc.
*
* @param mc message class (parser table)
* @param flags message flags (see #msg_flg_user)
* @param data message text
* @param len size of message text (if -1, use strlen(data))
*
* @retval A pointer to a freshly allocated and parsed message.
*
* Upon parsing error, the MSG_FLG_ERROR is set in
* @a msg_object(msg)->msg_flags.
*
* @since New in @VERSION_1_12_4
*/
msg_t *msg_make(msg_mclass_t const *mc, int flags,
char const *data, ssize_t len)
{
msg_t *msg;
msg_iovec_t iovec[2];
if (len == -1)
len = strlen(data);
if (len == 0)
return NULL;
msg = msg_create(mc, flags);
su_home_preload(msg_home(msg), 1, len + 1024);
if (msg_recv_iovec(msg, iovec, 2, len, 1) < 0) {
perror("msg_recv_iovec");
}
assert(iovec->mv_len == len);
memcpy(iovec->mv_base, data, len);
msg_recv_commit(msg, len, 1);
if (msg_extract(msg) < 0)
msg->m_object->msg_flags |= MSG_FLG_ERROR;
return msg;
}
......@@ -44,6 +44,9 @@ SOFIAPUBFUN void msg_destroy(msg_t *);
SOFIAPUBFUN msg_t *msg_copy(msg_t *);
SOFIAPUBFUN msg_t *msg_dup(msg_t const *);
SOFIAPUBFUN msg_t *msg_make(msg_mclass_t const *mc, int flags,
char const *data, ssize_t len);
SOFIAPUBFUN void msg_set_parent(msg_t *kid, msg_t *dad);
SOFIAPUBFUN msg_t *msg_ref_create(msg_t *);
......
......@@ -520,26 +520,7 @@ int hash_test(void)
msg_t *read_msg(char const buffer[])
{
int n, m;
msg_t *msg;
msg_iovec_t iovec[2];
n = strlen(buffer);
if (n == 0)
return NULL;
msg = msg_create(msg_test_mclass, MSG_DO_EXTRACT_COPY);
su_home_preload(msg_home(msg), 1, 4096);
if (msg_recv_iovec(msg, iovec, 2, n, 1) < 0) {
perror("msg_recv_iovec");
}
memcpy(iovec->mv_base, buffer, n);
msg_recv_commit(msg, n, 1);
m = msg_extract(msg);
return msg;
return msg_make(msg_test_mclass, MSG_DO_EXTRACT_COPY, buffer, -1);
}
/**Check if header chain contains any loops.
......
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