msg_parser.c File Reference


Detailed Description

HTTP-like message parser engine.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>
Date:
Created: Thu Oct 5 14:01:24 2000 ppessi

#include "config.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <limits.h>
#include <errno.h>
#include <stdarg.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/su.h>
#include <sofia-sip/su_alloc.h>
#include "msg_internal.h"
#include "sofia-sip/msg_header.h"
#include "sofia-sip/bnf.h"
#include "sofia-sip/msg_parser.h"
#include "sofia-sip/msg_mclass.h"
#include "sofia-sip/msg_mclass_hash.h"
#include "sofia-sip/msg_mime.h"

Include dependency graph for msg_parser.c:


Defines

#define msg_header_is_removed(h)
 Test if header is not in the chain.
#define CRLF_TEST(b)
 Calculate length of line ending (0, 1 or 2).

Functions

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.
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.
void * msg_buf_alloc (msg_t *msg, unsigned size)
 Allocate a buffer of size octets, with slack of msg_min_size.
void * msg_buf_exact (msg_t *msg, unsigned size)
 Allocate a buffer exactly of size octets, without any slack.
unsigned msg_buf_commit (msg_t *msg, unsigned size, int eos)
 Commit data into buffer.
unsigned msg_buf_committed (msg_t const *msg)
 Get length of committed data.
void * msg_buf_committed_data (msg_t const *msg)
 Get committed data.
void msg_buf_set (msg_t *msg, void *b, unsigned size)
 Set buffer.
void * msg_buf_move (msg_t *dst, msg_t const *src)
 Move unparsed data from src to dst.
int msg_recv_buffer (msg_t *msg, void **return_buffer)
 Obtain a buffer for receiving data.
int msg_set_next (msg_t *msg, msg_t *next)
 Set next message of the stream.
void msg_clear_committed (msg_t *msg)
 Clear committed data.
int msg_extract_header (msg_t *msg, msg_pub_t *mo, char b[], int bsiz, int eos)
 Extract a header.
msg_header_tmsg_header_d (su_home_t *home, msg_t const *msg, char const *b)
 Decode a message header.
int msg_extract_separator (msg_t *msg, msg_pub_t *mo, char b[], int bsiz, int eos)
 Extract a separator line.
int msg_extract_payload (msg_t *msg, msg_pub_t *mo, msg_header_t **return_payload, unsigned body_len, char b[], int bsiz, int eos)
 Extract a message body of body_len bytes.
void msg_unprepare (msg_t *msg)
 Clear 'prepared' flag.
int msg_is_prepared (msg_t const *msg)
 Return true if message is prepared.
int msg_headers_prepare (msg_t *msg, msg_header_t *headers, int flags)
 Encode headers in chain.
int msg_header_e (char b[], int bsiz, msg_header_t const *h, int flags)
 Encode a header.
msg_header_t ** msg_chain_head (msg_t const *msg)
 Return head of the fragment chain.
int msg_iovec (msg_t *msg, msg_iovec_t vec[], int veclen)
 Fill an I/O vector with message contents.
msg_header_tmsg_header_alloc (su_home_t *home, msg_hclass_t *hc, int extra)
 Allocate a header structure.
int msg_header_add (msg_t *msg, msg_pub_t *pub, msg_header_t **hh, msg_header_t *h)
 Add a (list of) header(s) to the header structure and fragment chain.
int msg_header_prepend (msg_t *msg, msg_pub_t *pub, msg_header_t **hh, msg_header_t *h)
 Prepend a (list of) header(s) to the header structure and fragment chain.
msg_header_t ** msg_hclass_offset (msg_mclass_t const *mc, msg_pub_t const *mo, msg_hclass_t *hc)
 Find place to insert header of the class hc.
int msg_header_add_dup (msg_t *msg, msg_pub_t *pub, msg_header_t const *src)
 Duplicate and add a (list of) header(s) to the message.
int msg_header_add_dup_as (msg_t *msg, msg_pub_t *pub, msg_hclass_t *hc, msg_header_t const *src)
 Duplicate a header as a given type and add the duplicate into message.
int msg_header_add_make (msg_t *msg, msg_pub_t *pub, msg_hclass_t *hc, char const *s)
 Parse a string as a given header field and add result to the message.
int msg_header_add_str (msg_t *msg, msg_pub_t *pub, char const *str)
 Parse a string and add resulting headers to the message.
int msg_header_insert (msg_t *msg, msg_pub_t *pub, msg_header_t *h)
 Insert a (list of) header(s) to the fragment chain.
int msg_header_remove (msg_t *msg, msg_pub_t *pub, msg_header_t *h)
 Remove a header from the header structure and fragment chain.
int msg_header_remove_all (msg_t *msg, msg_pub_t *pub, msg_header_t *h)
 Remove a header list from the header structure and fragment chain.
int msg_header_replace (msg_t *msg, msg_pub_t *pub, msg_header_t *replaced, msg_header_t *h)
 Replace a header item with a (list of) header(s).
void msg_header_free (su_home_t *home, msg_header_t *h)
 Free a header structure.
void msg_header_free_all (su_home_t *home, msg_header_t *h)
 Free a (list of) header structures.

Function Documentation

int msg_header_add ( msg_t msg,
msg_pub_t pub,
msg_header_t **  hh,
msg_header_t h 
)

Add a (list of) header(s) to the header structure and fragment chain.

The function msg_header_add() adds a header or list of headers into the given place within the message structure. It also inserts the headers into the the message fragment chain, if it exists.

If the header is a prepend header, the new header is inserted before existing headers of the same class. If the header is an append header, the new header is inserted after existing headers of the same class. If the header is a singleton, existing headers of the same class are removed. If the header is a list header, the values in the new header are added to the existing list.

Parameters:
msg message owning the fragment chain
pub public message structure
hh place in message structure to which header is added
h list of header(s) to be added

int msg_header_add_dup ( msg_t msg,
msg_pub_t pub,
msg_header_t const *  src 
)

Duplicate and add a (list of) header(s) to the message.

The function msg_header_add_dup() duplicates and adds a (list of) header(s) into a message structure.

When inserting headers into the fragment chain, a request (or status) is inserted first and replaces the existing request (or status). Other headers are inserted after the request or status.

If the header is a singleton, existing headers with the same class are removed.

Parameters:
msg message owning the fragment chain
pub public message structure to which header is added
src list of header(s) to be added

int msg_header_add_dup_as ( msg_t msg,
msg_pub_t pub,
msg_hclass_t hc,
msg_header_t const *  src 
)

Duplicate a header as a given type and add the duplicate into message.

The function msg_header_add_dup_as() duplicates a header as a instance of the given header class. It adds the new copy into the message.

When inserting headers into the fragment chain, a request (or status) is inserted first and replaces the existing request (or status). Other headers are inserted after the request or status.

If the header is a singleton, existing headers with the same class are removed.

Parameters:
msg message owning the fragment chain
pub public message structure to which header is added
hc header class for header target type
src list of header(s) to be duplicated and added

int msg_header_add_str ( msg_t msg,
msg_pub_t pub,
char const *  str 
)

Parse a string and add resulting headers to the message.

The function msg_header_add_str() parses a string and adds resulting header objects to the message object.

msg_header_t* msg_header_alloc ( su_home_t home,
msg_hclass_t hc,
int  extra 
)

Allocate a header structure.

The msg_header_alloc() function allocates a generic MO header structure and returns a pointer to it.

Parameters:
home memory home
hc header class
extra amount of extra memory to be allocated after header structure
Returns:
A pointer to the newly created header object, or NULL upon an error.

int msg_header_e ( char  b[],
int  bsiz,
msg_header_t const *  h,
int  flags 
)

Encode a header.

The function msg_header_e() encodes a header field in the buffer b[]. The encoding includes its name and trailing CRLF. The function returns the length of the encoding in bytes, excluding the final NUL. The buffer b must be large enough for whole encoding, including the final NUL.

The flags parameter define how the encoding is done. If the flags specify MSG_DO_COMPACT, the encoding is compact (short form with minimal whitespace).

int msg_header_insert ( msg_t msg,
msg_pub_t pub,
msg_header_t h 
)

Insert a (list of) header(s) to the fragment chain.

The function msg_header_insert() inserts header or list of headers into a message structure. It also inserts them into the the message fragment chain, if it exists.

When inserting headers into the fragment chain, a request (or status) is inserted first and replaces the existing request (or status). Other headers are inserted after the request or status.

If the header is a singleton, existing headers with the same class are removed.

Parameters:
msg message object owning the fragment chain
pub public message structure to which header is added
h list of header(s) to be added

int msg_header_prepend ( msg_t msg,
msg_pub_t pub,
msg_header_t **  hh,
msg_header_t h 
)

Prepend a (list of) header(s) to the header structure and fragment chain.

The function msg_header_prepend() adds a header or list of headers into the given place within the message structure. It also inserts the headers into the the message fragment chain, if it exists.

Unlike msg_header_add(), msg_header_prepend() always inserts header h before other headers of the same class. If the header is a singleton, existing headers of the same class are removed. If the header is a list header, the values in the new header are prepended to the existing list.

Parameters:
msg message owning the fragment chain
pub public message structure
hh place in message structure to which header is added
h list of header(s) to be added

int msg_header_remove ( msg_t msg,
msg_pub_t pub,
msg_header_t h 
)

Remove a header from the header structure and fragment chain.

The function msg_header_remove() removes a header from a message structure. It also removes the message from the message fragment chain and clears the encoding of other headers objects that share same encoding.

Parameters:
msg message owning the fragment chain
pub public message structure to which header is added
h header to be removed

int msg_header_remove_all ( msg_t msg,
msg_pub_t pub,
msg_header_t h 
)

Remove a header list from the header structure and fragment chain.

The function msg_header_remove_all() removes a list of headers from a message structure. It also removes the message from the message fragment chain and clears the encoding of other headers objects that share same encoding.

Parameters:
msg message owning the fragment chain
pub public message structure to which header is added
h header list to be removed

int msg_header_replace ( msg_t msg,
msg_pub_t pub,
msg_header_t replaced,
msg_header_t h 
)

Replace a header item with a (list of) header(s).

The function msg_header_replace() removes a header structure from message and replaces it with a new one or a list of headers. It inserts the new headers into the the message fragment chain, if it exists.

Parameters:
msg message object owning the fragment chain
pub public message structure to which header is added
replaced old header to be removed
h list of header(s) to be added

int msg_headers_prepare ( msg_t msg,
msg_header_t headers,
int  flags 
)

Encode headers in chain.

The function msg_headers_prepare() encodes all the headers in the header chain. 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.

Returns:
The size of all the headers in chain, or -1 upon an error.

int msg_iovec ( msg_t msg,
msg_iovec_t  vec[],
int  veclen 
)

Fill an I/O vector with message contents.

The function msg_iovec() calculates number of entries in the I/O vector required to send a message msg. It also fills in the I/O vector array, if it is provided by the caller and it is large enough.

Parameters:
msg 
vec 
veclen 
Returns:
The function msg_iovec() returns the number of entries in I/O vector required by msg, or 0 upon an error.
Note:
The caller should check that the I/O vector vec has enough entries. If the vec is too short, it should allocate big enough vector and re-invoke msg_iovec().


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