msg_s Class Reference

#include <msg.h>

Collaboration diagram for msg_s:

Collaboration graph
[legend]

Detailed Description

Message object.

The message object is used by Sofia parsers for SIP, RTSP and HTTP protocols. The message object has an abstract, protocol-independent inteface type msg_t, and a separate public protocol-specific interface msg_pub_t (which is typedef'ed to sip_t, rtsp_t or http_t depending on the protocol).

The main interface to abstract messages is defined in <msg.h>. The network I/O interface used by transport protocols is defined in <msg_addr.h>. The protocol-specific parser table, also known as message class, is defined in <msg_mclass.h>. (The message class is used as a factory object when a message object is created with msg_create()).


Data Fields

su_home_t m_home [1]
 Memory home.
msg_mclass_t const * m_class
 Message class.
int m_oflags
 Original flags.
msg_pub_tm_object
 Public view to parsed message.
unsigned m_maxsize
 Maximum size.
unsigned m_size
 Total size of fragments.
msg_header_tm_chain
 Fragment chain.
msg_header_t ** m_tail
 Tail of fragment chain.
msg_payload_tm_chunk
 Incomplete payload fragment.
msg_buffer_tm_stream
 User-provided buffers.
unsigned m_ssize
 Stream size.
unsigned short m_extract_err
 Bitmask of erroneous headers.
unsigned m_set_buffer:1
 Buffer has been set.
unsigned m_streaming:1
 Use streaming with message.
unsigned m_prepared:1
 Prepared/not.
msg_tm_next
 Next message.
msg_tm_parent
 Reference to a parent message.
int m_refs
 Number of references to this message.
su_addrinfo_t m_addrinfo
 Message addressing info (protocol).
su_sockaddr_t m_addr [1]
 Message address.
int m_errno
 Errno.

Related Functions

(Note that these are not member functions.)

msg_tmsg_create (msg_mclass_t const *mc, int flags)
 Create a message.
msg_tmsg_ref_create (msg_t *msg)
 Increment a message reference count.
void msg_set_parent (msg_t *kid, msg_t *dad)
 Set a message parent.
void msg_ref_destroy (msg_t *ref)
 Destroy a reference to a message.
void msg_destroy (msg_t *msg)
 Deinitialize and free a message.
msg_pub_tmsg_public (msg_t const *msg, void *tag)
 Retrieve public message structure of given type.
msg_mclass_t const * msg_mclass (msg_t const *msg)
 Retrieve message class.
msg_tmsg_copy (msg_t *original)
 Copy a message shallowly.
msg_tmsg_dup (msg_t const *original)
 Deep copy a message.
int msg_recv_iovec (msg_t *msg, msg_iovec_t vec[], int veclen, unsigned n, int exact)
 Obtain iovec for receiving the data.
int msg_recv_commit (msg_t *msg, unsigned n, int eos)
 Commit n bytes of buffers.
msg_tmsg_next (msg_t *msg)
 Get a next message of the stream.
unsigned msg_mark_as_complete (msg_t *msg, unsigned mask)
 Mark message as complete.
int msg_is_complete (msg_t const *msg)
 Return true if message is complete.
int msg_has_error (msg_t const *msg)
 Return true if message has parsing errors.
unsigned msg_size (msg_t const *msg)
 Total size of message.
unsigned msg_maxsize (msg_t *msg, unsigned maxsize)
 Set the maximum size of a message.
unsigned msg_streaming_size (msg_t *msg, unsigned ssize)
 Set the size of next fragment.
int msg_buf_external (msg_t *msg, unsigned N, unsigned blocksize)
 Allocate a list of external buffers.
int msg_extract (msg_t *msg)
 Extract and parse a message from internal buffer.
int msg_prepare (msg_t *msg)
 Encode all message fragments.
int msg_serialize (msg_t *msg, msg_pub_t *pub)
 Serialize headers into the fragment chain.


Friends And Related Function Documentation

int msg_buf_external ( msg_t msg,
unsigned  N,
unsigned  blocksize 
) [related]

Allocate a list of external buffers.

The function msg_buf_external() allocates at most msg_n_fragments external buffers for the message body.

Returns:
The function msg_buf_external() returns number of allocated buffers, or -1 upon an error.

msg_t * msg_copy ( msg_t original  )  [related]

Copy a message shallowly.

Copy a message and the header structures. The copied message will share all the strings with the original message. It will keep a reference to the original message, and the original message is not destroyed until all the copies have been destroyed.

Parameters:
original message to be copied

msg_t * msg_create ( msg_mclass_t const *  mc,
int  flags 
) [related]

Create a message.

Parameters:
mc message class
flags message control flags

void msg_destroy ( msg_t msg  )  [related]

Deinitialize and free a message.

Parameters:
msg message to be destroyed

msg_t * msg_dup ( msg_t const *  original  )  [related]

Deep copy a message.

Copy a message, the header structures and all the related strings. The duplicated message does not share any (non-const) data with original. Note that the cached representation (in h_data) is not copied.

Parameters:
original message to be duplicated

int msg_extract ( msg_t msg  )  [related]

Extract and parse a message from internal buffer.

This function parses the internal buffer and adds the parsed fragments to the message object. It marks the successfully parsed data as extracted.

Parameters:
msg message to be parsed
Return values:
positive if a complete message was parsed
0 if message was incomplete
negative if an error occurred

unsigned msg_maxsize ( msg_t msg,
unsigned  maxsize 
) [related]

Set the maximum size of a message.

The function msg_maxsize() sets the maximum buffer size of a message. It returns the previous maximum size. If the maxsize is 0, maximum size is not set, but the current maximum size is returned.

If the message size exceeds maxsize, msg_errno() returns ENOBUFS, MSG_FLG_TOOLARGE and MSG_FLG_ERROR flags are set.

msg_mclass_t const * msg_mclass ( msg_t const *  msg  )  [related]

Retrieve message class.

The function msg_mclass() returns a pointer to the message class object (factory object for the message).

Parameters:
msg pointer to msg object
Returns:
A pointer to the message class, or NULL if none.

msg_t * msg_next ( msg_t msg  )  [related]

Get a next message of the stream.

When parsing a transport stream, only the first message in the stream is created with msg_create(). The rest of the messages should be created with msg_next() after previous message has been completely received and parsed.

int msg_prepare ( msg_t msg  )  [related]

Encode all message fragments.

The function msg_prepare() prepares a message for sending. It encodes all serialized fragments in the message. You have to call msg_serialize() before calling msg_headers_prepare() in order to make sure that all the heades and other message fragments are included in the chain.

After encoding, the msg_common_s::h_data field will point to the encoding result of size msg_common_s::h_len bytes in in each fragment.

When multiple header fields are represented as a comma-separated list within a single header line, the first fragment in the header will contain all the text belonging to the header. The rest of the header fields will have zero-length encoding with msg_common_s::h_data that points to the end of the line.

Returns:
Total size of the encoded message in bytes, or -1 upon an error.
See also:
msg_extract(), msg_serialize()

msg_pub_t * msg_public ( msg_t const *  msg,
void *  tag 
) [related]

Retrieve public message structure of given type.

This function returns a pointer to the public message structure of the given protocol.

Parameters:
msg pointer to msg object
tag tag of public message structure
Returns:
A pointer to the public message structure, or NULL if there is none or the message is not for desired protocol.

int msg_recv_commit ( msg_t msg,
unsigned  n,
int  eos 
) [related]

Commit n bytes of buffers.

The function msg_recv_commit() is called after n bytes of data has been received to the message buffers and the parser can extract the received data.

Parameters:
msg pointer to message object
n number of bytes received
eos true if stream is complete
Note:
The eos should be always true for message-based transports. It should also be true when a stram oin stream-based transport ends, for instance, when TCP FIN is received.
Return values:
0 when successful
-1 upon an error.

int msg_recv_iovec ( msg_t msg,
msg_iovec_t  vec[],
int  veclen,
unsigned  n,
int  exact 
) [related]

Obtain iovec for receiving the data.

The function msg_recv_iovec() allocates buffers for receiving n bytes of data available from network. It returns the buffers in the I/O vector vec. The vec is allocated by the caller, the available length is given as veclen. If the protocol is message-oriented like UDP or SCTP and the available data ends at message boundary, the caller should set the exact as 1. Otherwise some extra buffer (known as slack) is allocated).

Currently, the msg_recv_iovec() allocates buffers in at most two blocks, so the caller should allocate at least two elements for the I/O vector vec.

Parameters:
msg message object [IN]
vec I/O vector [OUT]
veclen available length of vec [IN]
n number of available bytes [IN]
exact true if data ends at message boundary [IN]
Returns:
The function msg_recv_iovec() returns the length of I/O vector to receive data, 0 if there are not enough buffers, or -1 upon an error.

msg_t * msg_ref_create ( msg_t msg  )  [related]

Increment a message reference count.

The function msg_ref_create() creates a reference to a message. The referenced message is not freed until all the references have been destroyed.

Parameters:
msg message of which a reference is created
Returns:
The function msg_ref_create() returns a reference to a message.

int msg_serialize ( msg_t msg,
msg_pub_t pub 
) [related]

Serialize headers into the fragment chain.

The msg_serialize() collects the headers and other message components in the fragment chain. It should be called before msg_prepare().

Parameters:
msg pointer to message object
pub public message structure
Return values:
0 when successful
-1 upon an error

void msg_set_parent ( msg_t kid,
msg_t dad 
) [related]

Set a message parent.

Set a parent for a message. The parent message is not destroyed until all its kids have been destroyed - each kid keeps a reference to its parent message.

Parameters:
kid child message
dad parent message

unsigned msg_streaming_size ( msg_t msg,
unsigned  ssize 
) [related]

Set the size of next fragment.

The function msg_streaming_size() sets the size of the message body for streaming.


Sofia-SIP 1.12.1 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.