msg_mime.c File Reference


Detailed Description

MIME-related headers and MIME multipart bodies for SIP/HTTP/RTSP.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>
Date:
Created: Tue Jun 13 02:57:51 2000 ppessi

#include "config.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <assert.h>
#include <sofia-sip/su_alloc.h>
#include "msg_internal.h"
#include "sofia-sip/msg.h"
#include "sofia-sip/msg_mime.h"
#include <sofia-sip/su_uniqueid.h>
#include <sofia-sip/su_errno.h>
#include <sofia-sip/msg_parser.h>
#include <sofia-sip/msg_mime_protos.h>

Include dependency graph for msg_mime.c:

Defines

#define MSG_HEADER_CLASS_G(c, l, s, kind)
 Define a header class for headers without any extra data to copy.
#define MSG_HEADER_CLASS_LIST(c, l, s, kind)
 Define a header class for a msg_list_t kind of header.
#define CRLF_TEST(b)
 Calculate length of line ending (0, 1 or 2).

Functions

msg_multipart_tmsg_multipart_create (su_home_t *home, char const *content_type, void const *data, isize_t dlen)
 Create a part for MIME multipart entity.
msg_multipart_tmsg_multipart_parse (su_home_t *home, msg_content_type_t const *c, msg_payload_t *pl)
 Parse a MIME multipart.
int msg_multipart_complete (su_home_t *home, msg_content_type_t *c, msg_multipart_t *mp)
 Add all missing parts to the multipart.
msg_header_tmsg_multipart_serialize (msg_header_t **head0, msg_multipart_t *mp)
 Serialize a multipart message.
issize_t msg_multipart_prepare (msg_t *msg, msg_multipart_t *mp, int flags)
 Encode a multipart.
issize_t msg_multipart_d (su_home_t *home, msg_header_t *h, char *s, isize_t slen)
 Decode a multipart.
issize_t msg_multipart_e (char b[], isize_t bsiz, msg_header_t const *h, int flags)
 Encode a multipart.
isize_t msg_multipart_dup_xtra (msg_header_t const *h, isize_t offset)
 Calculate extra size of a multipart.
char * msg_multipart_dup_one (msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra)
 Duplicate one msg_multipart_t object.
unsigned msg_q_value (char const *q)
 Calculate Q value.
issize_t msg_mediatype_d (char **ss, char const **type)
 Parse media type (type/subtype).
char * msg_accept_dup_one (msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra)
 Duplicate one msg_accept_t object.
int msg_accept_update (msg_common_t *h, char const *name, isize_t namelen, char const *value)
 Update parameter(s) for Accept header.
issize_t msg_accept_any_d (su_home_t *home, msg_header_t *h, char *s, isize_t slen)
 Decode an Accept-* header.
issize_t msg_accept_any_e (char b[], isize_t bsiz, msg_header_t const *h, int f)
 Encode an Accept-* header field.
isize_t msg_accept_any_dup_xtra (msg_header_t const *h, isize_t offset)
 Calculate extra memory used by accept-* headers.
char * msg_accept_any_dup_one (msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra)
 Duplicate one msg_accept_any_t object.
int msg_accept_any_update (msg_common_t *h, char const *name, isize_t namelen, char const *value)
 Update parameter(s) for Accept-* header.
char * msg_content_disposition_dup_one (msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra)
 Duplicate one msg_content_disposition_t object.
int msg_content_disposition_update (msg_common_t *h, char const *name, isize_t namelen, char const *value)
 Update Content-Disposition parameters.
msg_content_length_tmsg_content_length_create (su_home_t *home, uint32_t n)
  Create a Content-Length header object.
char * msg_content_type_dup_one (msg_header_t *dst, msg_header_t const *src, char *b, isize_t xtra)
 Duplicate one msg_content_type_t object.

Variables

char const msg_mime_version_1_0 []
 Protocol version of MIME.
msg_hclass_t msg_accept_class []
 Header class for Accept header.
msg_hclass_t msg_accept_charset_class [1]
 Header class for Accept-Charset header.
msg_hclass_t msg_accept_encoding_class [1]
 Header class for Accept-Encoding header.
msg_hclass_t msg_accept_language_class [1]
 Header class for Accept-Language header.
msg_hclass_t msg_content_disposition_class []
 Header class for Content-Disposition header.
msg_hclass_t msg_content_encoding_class []
 Header class for Content-Encoding header.
msg_hclass_t msg_content_language_class []
 Header class for Content-Language header.
msg_hclass_t msg_content_length_class []
 Header class for Content-Length header.
msg_hclass_t msg_content_md5_class []
 Header class for Content-MD5 header.
msg_hclass_t msg_content_id_class []
 Header class for Content-ID header.
msg_hclass_t msg_content_type_class []
 Header class for Content-Type header.
msg_hclass_t msg_mime_version_class []
 Header class for MIME-Version header.
msg_hclass_t msg_content_location_class []
 Header class for Content-Location header.
msg_hclass_t msg_content_transfer_encoding_class []
 Header class for Content-Transfer-Encoding header.
msg_hclass_t msg_warning_class []
 Header class for Warning header.


Function Documentation

issize_t msg_mediatype_d ( char **  ss,
char const **  type 
)

Parse media type (type/subtype).

The function msg_mediatype_d() parses a mediatype string.

Parameters:
[in,out] ss string to be parsed
[out] type value result for media type
Return values:
0 when successful,
-1 upon an error.

int msg_multipart_complete ( su_home_t *  home,
msg_content_type_t c,
msg_multipart_t mp 
)

Add all missing parts to the multipart.

Add missing components such as boundaries between body parts, separators between body-part headers and data, and close-delimiter after last body-part to the multipart message.

Parameters:
[in,out] home home for allocating structures
[in,out] c content-type header for multipart
[in,out] mp pointer to first multipart structure
Return values:
0 when successful
-1 upon an error
Errors:
EBADMSG The Content-Type header c is malformed, or multipart message contains a malformed Content-Type header.
ENOMEM A memory allocation failed.
EINVAL The function msg_multipart_complete() was given invalid arguments.

msg_multipart_t* msg_multipart_create ( su_home_t *  home,
char const *  content_type,
void const *  data,
isize_t  dlen 
)

Create a part for MIME multipart entity.

The function msg_multipart_create() allocates a new msg_multipart_t object from memory home home. If content_type is non-NULL, it makes a msg_content_type_t header object and adds the header to the msg_multipart_t object. If dlen is nonzero, it allocates a msg_payload_t structure of dlen bytes for the payload of the newly created msg_multipart_t object. If data is non-NULL, it copies the dlen bytes of of data to the payload of the newly created msg_multipart_t object.

Returns:
A pointer to the newly created msg_multipart_t object, or NULL upon an error.

issize_t msg_multipart_e ( char  b[],
isize_t  bsiz,
msg_header_t const *  h,
int  flags 
)

Encode a multipart.

Please note that here we just encode a element, the msg_multipart_t itself.

msg_multipart_t* msg_multipart_parse ( su_home_t *  home,
msg_content_type_t const *  c,
msg_payload_t pl 
)

Parse a MIME multipart.

The function msg_multipart_parse() parses a MIME multipart message. The common syntax of multiparts is described in RFC 2046 (section 7).

Parameters:
[in,out] home home for allocating structures
[in] c content-type header for multipart
[in] pl payload structure for multipart
After parsing, the pl will contain the plain-text preamble (if any).

Note:
If no Content-Type header is given, the msg_multipart_parse() tries to look for a suitable boundary. Currently, it takes first boundary-looking string and uses that, so it can be fooled with, for instance, signature "--Pekka".

issize_t msg_multipart_prepare ( msg_t msg,
msg_multipart_t mp,
int  flags 
)

Encode a multipart.

Returns:
The size of multipart in bytes, or -1 upon an error.

unsigned msg_q_value ( char const *  q  ) 

Calculate Q value.

The function msg_q_value() converts q-value string q to numeric value in range (0..1000). Q values are used, for instance, to describe relative priorities of registered contacts.

Parameters:
q q-value string ("1" | "." 1,3DIGIT)
Returns:
The function msg_q_value() returns an integer in range 0 .. 1000.


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