msg_mime.h 8.52 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
 * * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#ifndef MSG_MIME_H /** Defined when <msg_mime.h> has been included. */
#define MSG_MIME_H \
"$Id: msg_mime.h,v 1.1.1.1 2005/07/20 20:35:23 kaiv Exp $"
/**@ingroup msg_mime
 * @file msg_mime.h
 *
 * MIME headers and multipart messages (RFC 2045).
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Fri Aug 16 19:18:26 EEST 2002 ppessi
 * 
 * $Date: 2005/07/20 20:35:23 $
 */

#ifndef URL_H
#include <url.h>
#endif

#ifndef MSG_TYPES_H
#include <msg_types.h>
#endif
#ifndef SU_TYPES_H
#include <su_types.h>
#endif

typedef struct msg_accept_any_s     msg_accept_any_t;

typedef struct msg_accept_s  	    msg_accept_t;

typedef msg_accept_any_t            msg_accept_charset_t;
typedef msg_accept_any_t      	    msg_accept_encoding_t;
typedef msg_accept_any_t     	    msg_accept_language_t;

typedef struct msg_content_disposition_s 
                                    msg_content_disposition_t;
typedef msg_list_t	      	    msg_content_encoding_t;
typedef msg_generic_t               msg_content_base_t;
typedef msg_generic_t               msg_content_id_t;
typedef struct msg_content_length_s msg_content_length_t;
typedef msg_generic_t               msg_content_location_t;
typedef msg_list_t                  msg_content_language_t;
typedef msg_generic_t               msg_content_md5_t;
typedef msg_generic_t	     	    msg_content_transfer_encoding_t;
typedef struct msg_content_type_s   msg_content_type_t;
typedef msg_generic_t	     	    msg_mime_version_t;
typedef struct msg_warning_s	    msg_warning_t;

/** Multipart body object. */
typedef struct msg_multipart_s      msg_multipart_t;

/**@ingroup msg_accept
 * @brief Structure for @b Accept header.
 */
struct msg_accept_s
{
  msg_common_t        ac_common[1]; /**< Common fragment info */
  msg_accept_t       *ac_next;	    /**< Pointer to next Accept header */
  char const         *ac_type;	    /**< Pointer to type/subtype */
  char const         *ac_subtype;   /**< Points after first slash in type */
  msg_param_t const  *ac_params;    /**< List of parameters */
  msg_param_t         ac_q;	    /**< Value of q parameter */
};

/**@ingroup msg_accept_encoding
 * @brief Structure for @b Accept-Charset, @b Accept-Encoding and
 * @b Accept-Language headers.
 */
struct msg_accept_any_s
{
  msg_common_t        aa_common[1]; /**< Common fragment info */
  msg_accept_any_t   *aa_next;	    /**< Pointer to next Accept-* header */
  char const         *aa_value;	    /**< Token */
  msg_param_t const  *aa_params;    /**< List of parameters */
  char const         *aa_q;	    /**< Value of q parameter */
};

/**@ingroup msg_content_disposition 
 * @brief Structure for @b Content-Disposition header.
 */
struct msg_content_disposition_s
{
  msg_common_t       cd_common[1];  /**< Common fragment info */
  msg_error_t       *cd_next;	    /**< Link to next (dummy) */
  char const        *cd_type;	    /**< Disposition type */
  msg_param_t const *cd_params;	    /**< List of parameters */
  msg_param_t        cd_handling;   /**< Value of @b handling parameter */
  unsigned           cd_required:1; /**< True if handling=required */
  unsigned           cd_optional:1; /**< True if handling=optional */
  unsigned           :0;	    /* pad */
};

/**@ingroup msg_content_length
 * @brief Structure for Content-Length header.
 */
struct msg_content_length_s
{
  msg_common_t   l_common[1];	    /**< Common fragment info */
  msg_error_t   *l_next;	    /**< Link to next (dummy) */
  unsigned long  l_length;	    /**< Digits */
};


/**@ingroup msg_content_type
 * @brief Structure for Content-Type header.
 */
struct msg_content_type_s
{
  msg_common_t        c_common[1];  /**< Common fragment info */
  msg_error_t        *c_next;	    /**< Dummy link to next */
  char const         *c_type;	    /**< Pointer to type/subtype */
  char const         *c_subtype;    /**< Points after first slash in type */
  msg_param_t const  *c_params;	    /**< List of parameters */
};


/**@ingroup sip_warning
 * @brief Structure for @b Warning header.
 */
struct msg_warning_s
{
  msg_common_t        w_common[1];  /**< Common fragment info */
  msg_warning_t      *w_next;	    /**< Link to next Warning header */
  unsigned            w_code;       /**< Warning code */
  char const         *w_host;	    /**< Hostname or pseudonym */
  char const         *w_port;	    /**< Port number */
  char const         *w_text;       /**< Warning text */
};


/**@ingroup msg_multipart
 *
 * @brief Structure for a part in MIME multipart message.
 */
struct msg_multipart_s
{
  msg_common_t            mp_common[1];	/**< Common fragment information */
  msg_multipart_t        *mp_next;      /**< Next part in multipart body */
  /* Preamble for this part */
  char                   *mp_data;	/**< Boundary string. */
  unsigned                mp_len;	/**< Length of boundary (mp_data).*/
  unsigned                mp_flags;
  msg_error_t            *mp_error;

  /* === Headers start here */
  msg_content_type_t     *mp_content_type;	/**< Content-Type */
  msg_content_disposition_t *mp_content_disposition;
                                                /**< Content-Disposition */
  msg_content_location_t *mp_content_location;	/**< Content-Location */
  msg_content_base_t     *mp_content_base;      /**< Content-Base */
  msg_content_id_t       *mp_content_id;        /**< Content-ID */
  msg_content_language_t *mp_content_language;	/**< Content-Language */
  msg_content_encoding_t *mp_content_encoding;	/**< Content-Encoding */
  msg_content_transfer_encoding_t *mp_content_transfer_encoding;
                                        /**< Content-Transfer-Encoding */
#if 0
  /* === Hash headers end here */
  /* These MIME headers are here for msg_parser.awk */
  msg_accept_t           *mp_accept;		/**< Accept */
  msg_accept_charset_t   *mp_accept_charset;	/**< Accept-Charset */
  msg_accept_encoding_t  *mp_accept_encoding;	/**< Accept-Encoding */
  msg_accept_language_t  *mp_accept_language;	/**< Accept-Language */
  msg_mime_version_t     *mp_mime_version;	/**< MIME-Version */
  msg_content_md5_t      *mp_content_md5;	/**< Content-MD5 */
  msg_content_length_t   *mp_content_length;	/**< Content-Length */
  msg_multipart_t        *mp_multipart;		/**< Recursive multipart */
  msg_warning_t          *mp_warning;           /**< Warning */
#endif
  /* === Headers end here */

  /** Unknown and extra headers. */
  msg_unknown_t          *mp_unknown;           /**< Unknown headers */

  msg_separator_t        *mp_separator;	        /**< Separator */
  msg_payload_t          *mp_payload;	        /**< Body part */

  msg_multipart_t        *mp_multipart;		/**< Recursive multipart */

  msg_payload_t          *mp_close_delim;       /**< Closing delimiter */
};

msg_multipart_t *msg_multipart_create(su_home_t *home,
				      char const *content_type,
				      void const *data,
				      int dlen);
msg_multipart_t *msg_multipart_parse(su_home_t *home, 
				     msg_content_type_t const *c,
				     msg_payload_t *pl);
int msg_multipart_complete(su_home_t *home, 
			   msg_content_type_t *c,
			   msg_multipart_t *mp);
msg_header_t *msg_multipart_serialize(msg_header_t **head0, 
				      msg_multipart_t *mp);

int msg_multipart_prepare(msg_t *msg, msg_multipart_t *mp, int flags);

int msg_accept_any_dup_xtra(msg_header_t const *h, int offset);

char *msg_accept_any_dup_one(msg_header_t *dst, msg_header_t const *src,
			     char *b, int xtra);

msg_content_length_t *msg_content_length_create(su_home_t *home, uint32_t n);

/** MIME multipart protocol name. @HIDE */
#define MSG_MULTIPART_VERSION_CURRENT msg_mime_version_1_0
extern char const msg_mime_version_1_0[];

/** MIME multipart parser table identifier. @HIDE */
#define MSG_MULTIPART_PROTOCOL_TAG   ((void *)0x4d494d45)	/* 'MIME' */

#endif /** MSG_MIME_H */