Defines | Enumerations | Functions

sofia-sip/msg.h File Reference

Base message interface. More...

#include <sofia-sip/msg_types.h>
#include <sofia-sip/su_alloc.h>
Include dependency graph for msg.h:

Go to the source code of this file.

Defines

#define MSG_H
 Defined when <sofia-sip/msg.h> has been included.
#define msg_home(h)
 Cast a msg_t pointer to a su_home_t pointer.
#define MSG_FLAGS(f, v)
 Test if all the flags in v are set in f.

Enumerations

enum  msg_streaming_status {
  msg_stop_streaming,
  msg_start_streaming
}
 

Streaming state of a msg_t object.

More...
enum  msg_flg_user {
  MSG_FLG_COMPACT,
  MSG_FLG_CANONIC,
  MSG_FLG_EXTRACT_COPY,
  MSG_FLG_COMMA_LISTS,
  MSG_FLG_MAILBOX,
  MSG_FLG_CHUNKING,
  MSG_FLG_STREAMING,
  MSG_FLG_THRDSAFE
}
 

Flags controlling parser/printer.

More...
enum  msg_flg_parser {
  MSG_FLG_HEADERS,
  MSG_FLG_BODY,
  MSG_FLG_CHUNKS,
  MSG_FLG_TRAILERS,
  MSG_FLG_FRAGS,
  MSG_FLG_COMPLETE,
  MSG_FLG_ERROR,
  MSG_FLG_TOOLARGE,
  MSG_FLG_TRUNC,
  MSG_FLG_TIMEOUT
}
 

Flags used by parser.

More...

Functions

msg_tmsg_create (msg_mclass_t const *mc, int flags)
 Create a message.
void msg_destroy (msg_t *)
 Deinitialize and free a message.
msg_tmsg_copy (msg_t *)
 Copy a message shallowly.
msg_tmsg_dup (msg_t const *)
 Deep copy a message.
msg_tmsg_make (msg_mclass_t const *mc, int flags, void const *data, ssize_t len)
 Parse a message.
char * msg_as_string (su_home_t *home, msg_t *msg, msg_pub_t *pub, int flags, size_t *return_len)
 Convert a message to a string.
void msg_set_parent (msg_t *kid, msg_t *dad)
 Set a message parent.
msg_tmsg_ref_create (msg_t *)
 Increment a message reference count.
void msg_ref_destroy (msg_t *)
 Destroy a reference to a message.
msg_pub_tmsg_public (msg_t const *msg, void *tag)
 Retrieve public message structure of given type.
msg_pub_tmsg_object (msg_t const *msg)
 Retrieve public message structure.
msg_mclass_t const * msg_mclass (msg_t const *msg)
 Retrieve message class.
int msg_extract (msg_t *msg)
 Extract and parse a message from internal buffer.
unsigned msg_extract_errors (msg_t const *msg)
 Get error classification flags.
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.
msg_header_t ** msg_chain_head (msg_t const *msg)
 Return head of the fragment chain.
int msg_serialize (msg_t *msg, msg_pub_t *mo)
 Serialize headers into the fragment chain.
int msg_prepare (msg_t *msg)
 Encode all message fragments.
void msg_unprepare (msg_t *msg)
 Clear 'prepared' flag.
int msg_is_prepared (msg_t const *msg)
 Return true if message is prepared.
usize_t msg_size (msg_t const *msg)
 Total size of message.
usize_t msg_maxsize (msg_t *msg, usize_t maxsize)
 Set the maximum size of a message.
int msg_is_streaming (msg_t const *msg)
 Test if streaming is in progress.
void msg_set_streaming (msg_t *msg, enum msg_streaming_status what)
 Enable/disable streaming.
unsigned msg_mark_as_complete (msg_t *msg, unsigned mask)
 Mark message as complete.
unsigned msg_get_flags (msg_t const *msg, unsigned mask)
 Get message flags.
unsigned msg_set_flags (msg_t *msg, unsigned mask)
 Set message flags.
unsigned msg_zap_flags (msg_t *msg, unsigned mask)
 Clear message flags.

Detailed Description

Base message interface.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>
Date:
Created: Fri Feb 18 08:54:48 2000 ppessi

Define Documentation

#define MSG_FLAGS (   f,
  v 
)

Test if all the flags in v are set in f.

#define msg_home (   h  ) 

Cast a msg_t pointer to a su_home_t pointer.


Enumeration Type Documentation

Flags used by parser.

Enumerator:
MSG_FLG_HEADERS 

Extract headers for this message.

MSG_FLG_BODY 

Extract body for this message.

MSG_FLG_CHUNKS 

Extract chunks for this message.

MSG_FLG_TRAILERS 

Extract trailers for this message.

MSG_FLG_FRAGS 

Extract last component of this message.

MSG_FLG_COMPLETE 

This message has been completely extracted.

MSG_FLG_ERROR 

This message has parsing errors.

MSG_FLG_TOOLARGE 

This message is too large.

MSG_FLG_TRUNC 

This message is truncated.

MSG_FLG_TIMEOUT 

This message has timeout.

Flags controlling parser/printer.

Enumerator:
MSG_FLG_COMPACT 

Use compact form when printing.

MSG_FLG_CANONIC 

Use canonic representation when printing.

MSG_FLG_EXTRACT_COPY 

Cache a copy of headers when parsing.

MSG_FLG_COMMA_LISTS 

Print comma-separated lists instead of separate headers.

MSG_FLG_MAILBOX 

Use mailbox format when parsing - in mailbox format message has no body unless Content-Length header is present.

MSG_FLG_CHUNKING 

Use multiple parts for message body.

MSG_FLG_STREAMING 

Enable streaming - parser gives completed message fragments when they are ready to upper layers.

MSG_FLG_THRDSAFE 

Make messages threadsafe.

Streaming state of a msg_t object.

Enumerator:
msg_stop_streaming 

Disable streaming.

msg_start_streaming 

Enable streaming.


Function Documentation

char* msg_as_string ( su_home_t home,
msg_t msg,
msg_pub_t pub,
int  flags,
size_t *  return_len 
)

Convert a message to a string.

A message is encoded and the encoding result is returned as a string. Because the message may contain binary payload (or NUL in headers), the message length is returned separately in *return_len, too.

Note that the message is serialized as a side effect.

Parameters:
home memory home used to allocate the string
msg message to encode
pub message object to encode (may be NULL)
flags flags used when encoding
return_len return-value parameter for encoded message length
Returns:
Encoding result as a C string.
Since:
New in 1.12.4
See also:
msg_make(), msg_prepare(), msg_serialize().
msg_t * msg_copy ( msg_t original  ) 

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
Return values:
pointer to newly copied message object when successful
NULL upon an error
msg_t * msg_create ( msg_mclass_t const *  mc,
int  flags 
)

Create a message.

Parameters:
mc message class
flags message control flags
void msg_destroy ( msg_t msg  ) 

Deinitialize and free a message.

Parameters:
msg message to be destroyed
msg_t * msg_dup ( msg_t const *  original  ) 

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
Return values:
pointer to newly duplicated message object when successful
NULL upon an error
int msg_extract ( msg_t msg  ) 

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_extract_errors ( msg_t const *  msg  ) 

Get error classification flags.

If the message parser fails to parse certain headers in the message, it sets the corresponding extract error flags. The flags corresponding to each header are stored in the message parser (msg_mclass_t) structure. They are set when the header is added to the parser table.

The SIP flags are defined in <sofia-sip/sip_headers.h>. For well-known SIP headers, the flags for each header are listed in a separate text file (sip_bad_mask) read by msg_parser.awk.

The flags can be used directly by NTA (the mask triggering 400 response is set with NTATAG_BAD_REQ_MASK(), the mask triggering response messages to be dropped is set with NTATAG_BAD_RESP_MASK()). Alternatively the application can check them based on the method or required SIP features.

See also:
msg_mclass_insert_with_mask(), NTATAG_BAD_REQ_MASK(), NTATAG_BAD_RESP_MASK().
unsigned msg_get_flags ( msg_t const *  msg,
unsigned  mask 
)

Get message flags.

int msg_is_prepared ( msg_t const *  msg  ) 

Return true if message is prepared.

int msg_is_streaming ( msg_t const *  msg  ) 

Test if streaming is in progress.

msg_t* msg_make ( msg_mclass_t const *  mc,
int  flags,
void const *  data,
ssize_t  len 
)

Parse a message.

Parse a text message with parser mc. The data is copied and it is not modified or referenced by the parsed message.

Example
Parse a SIP message fragment (e.g., payload of NOTIFY sent in response to REFER):
 msg_t *m = msg_make(sip_default_mclass(), 0, pl->pl_data, pl->pl_len);
 sip_t *frag = sip_object(m);
Parameters:
mc message class (parser table)
flags message flags (see msg_flg_user)
data message text
len size of message text (if -1, use strlen(data))
Return values:
A pointer to a freshly allocated and parsed message.

Upon parsing error, the header structure may be left incomplete. The MSG_FLG_ERROR is set in msg_object(msg)->msg_flags.

Since:
New in 1.12.4
See also:
msg_as_string(), msg_extract()
usize_t msg_maxsize ( msg_t msg,
usize_t  maxsize 
)

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  ) 

Retrieve message class.

Get 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_pub_t* msg_object ( msg_t const *  msg  ) 

Retrieve public message structure.

Get a pointer to the public message structure.

Parameters:
msg pointer to msg object
Returns:
A pointer to the public message structure, or NULL if none.
int msg_prepare ( msg_t msg  ) 

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 
)

Retrieve public message structure of given type.

Get 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.
msg_t * msg_ref_create ( msg_t msg  ) 

Increment a message reference count.

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:
A pointer to a message.
void msg_ref_destroy ( msg_t ref  ) 

Destroy a reference to a message.

Parameters:
ref pointer to msg object
Deprecated:
Use msg_destroy() instead.
int msg_serialize ( msg_t msg,
msg_pub_t pub 
)

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
unsigned msg_set_flags ( msg_t msg,
unsigned  mask 
)

Set message flags.

void msg_set_parent ( msg_t kid,
msg_t dad 
)

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
void msg_unprepare ( msg_t msg  ) 

Clear 'prepared' flag.

unsigned msg_zap_flags ( msg_t msg,
unsigned  mask 
)

Clear message flags.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

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