msg_types.h 9.54 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * 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
 *
 */

Pekka Pessi's avatar
Pekka Pessi committed
25 26
#ifndef MSG_TYPES_H
/** Defined when <sofia-sip/msg_types.h> has been included. */
Pekka Pessi's avatar
Pekka Pessi committed
27
#define MSG_TYPES_H
Pekka Pessi's avatar
Pekka Pessi committed
28

Pekka Pessi's avatar
Pekka Pessi committed
29
/**@file sofia-sip/msg_types.h
Pekka Pessi's avatar
Pekka Pessi committed
30 31 32 33 34 35 36 37
 * @brief Types for messages and common headers
 * 
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * 
 * @date Created: Thu Jan 23 15:43:17 2003 ppessi
 *
 */

38 39
#ifndef SU_TYPES_H
#include <sofia-sip/su_types.h>
40 41 42 43
#endif

SOFIA_BEGIN_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
44 45 46 47 48 49 50 51 52 53 54 55 56
/** Message class. */
typedef struct msg_mclass_s       msg_mclass_t;

/** Header class. */
typedef struct msg_hclass_s const msg_hclass_t;

/** Header reference. */
typedef struct msg_href_s         msg_href_t;

/** Message object. */
typedef struct msg_s              msg_t;

#ifndef MSG_TIME_T_DEFINED
57
#define MSG_TIME_T_DEFINED
Pekka Pessi's avatar
Pekka Pessi committed
58 59 60 61
/** Time in seconds since epoch (1900-Jan-01 00:00:00). */
typedef unsigned long msg_time_t;
#endif

62 63 64 65 66
#ifndef MSG_TIME_MAX
/** Latest time that can be expressed with msg_time_t. @HIDE */
#define MSG_TIME_MAX ((msg_time_t)ULONG_MAX)
#endif

Pekka Pessi's avatar
Pekka Pessi committed
67 68 69 70 71 72 73 74 75 76
#ifndef MSG_PUB_T
#ifdef MSG_OBJ_T 
#define MSG_PUB_T MSG_OBJ_T
#else
#define MSG_PUB_T struct msg_pub_s
#endif
#endif

/**Public protocol-specific message structure for accessing the message. 
 * 
77 78 79
 * This type can be either #sip_t, #http_t, or #msg_multipart_t, depending
 * on the message. The base structure used by msg module is defined in
 * struct #msg_pub_s.
Pekka Pessi's avatar
Pekka Pessi committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
 */
typedef MSG_PUB_T msg_pub_t;

#ifndef MSG_HDR_T
#define MSG_HDR_T union msg_header_u
#endif
/** Any protocol-specific header object */
typedef MSG_HDR_T msg_header_t;

typedef struct msg_common_s         msg_common_t;

typedef struct msg_separator_s      msg_separator_t;
typedef struct msg_payload_s        msg_payload_t;
typedef struct msg_unknown_s        msg_unknown_t;
typedef struct msg_error_s          msg_error_t;

typedef msg_common_t msg_frg_t;

typedef char const            	   *msg_param_t;
typedef struct msg_numeric_s  	    msg_numeric_t;
typedef struct msg_generic_s  	    msg_generic_t;
typedef struct msg_list_s     	    msg_list_t;
typedef struct msg_auth_s     	    msg_auth_t;
103
typedef struct msg_auth_info_s      msg_auth_info_t;
Pekka Pessi's avatar
Pekka Pessi committed
104 105 106 107 108

#define MSG_HEADER_N 16377

/** Common part of the header objects (or message fragments). 
 *
109
 * This structure is also known as #msg_common_t or #sip_common_t.
Pekka Pessi's avatar
Pekka Pessi committed
110 111 112 113 114 115
 */
struct msg_common_s {
  msg_header_t       *h_succ;	/**< Pointer to succeeding fragment. */
  msg_header_t      **h_prev;	/**< Pointer to preceeding fragment. */
  msg_hclass_t       *h_class;	/**< Header class. */
  void const         *h_data;	/**< Fragment data */
116
  usize_t             h_len;    /**< Fragment length (including CRLF) */
Pekka Pessi's avatar
Pekka Pessi committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
};


/** Message object, common view */
struct msg_pub_s {
  msg_common_t        msg_common[1]; /**< Recursive */
  msg_pub_t          *msg_next;
  void               *msg_user;
  unsigned            msg_size;
  unsigned            msg_flags;
  msg_error_t        *msg_error;
  msg_header_t       *msg_request;
  msg_header_t       *msg_status;
  msg_header_t       *msg_headers[MSG_HEADER_N];
};

#define msg_ident msg_common->h_class

/** Numeric header. 
 *
137 138
 * A numeric header has value range of a 32-bit, 0..4294967295. The @a
 * x_value field is unsigned long, however.
Pekka Pessi's avatar
Pekka Pessi committed
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
 */
struct msg_numeric_s {
  msg_common_t   x_common[1];	    /**< Common fragment info */
  msg_numeric_t *x_next;	    /**< Link to next header */
  unsigned long  x_value;	    /**< Numeric header value */
};

/** Generic header. 
 *
 * A generic header does not have any internal structure. Its value is
 * represented as a string.
 */
struct msg_generic_s {
  msg_common_t   g_common[1];	    /**< Common fragment info */
  msg_generic_t *g_next;	    /**< Link to next header */
  char const    *g_string;	    /**< Header value */
};

/** List header. 
 * 
 * A list header consists of comma-separated list of tokens.
 */
struct msg_list_s {
  msg_common_t       k_common[1];   /**< Common fragment info */
  msg_list_t        *k_next;	    /**< Link to next header */
  msg_param_t       *k_items;	    /**< List of items */
};

/** Authentication header. 
 *
 * An authentication header has authentication scheme name and
 * comma-separated list of parameters as its value.
 */
struct msg_auth_s {
  msg_common_t       au_common[1];  /**< Common fragment info */
  msg_auth_t        *au_next;	    /**< Link to next header */
  char const        *au_scheme;	    /**< Auth-scheme like Basic or Digest */
  msg_param_t const *au_params;	    /**< Comma-separated parameters */
};

179 180 181 182 183 184 185 186 187 188 189
/**Authentication-Info header
 *
 * An Authentication-Info header has comma-separated list of parameters as its value.
 */
struct msg_auth_info_s
{
  msg_common_t        ai_common[1]; /**< Common fragment info */
  msg_error_t        *ai_next;	    /**< Dummy link to next */
  msg_param_t const  *ai_params;    /**< List of ainfo */
};

Pekka Pessi's avatar
Pekka Pessi committed
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
/** Unknown header. */
struct msg_unknown_s {
  msg_common_t    un_common[1];  /**< Common fragment info */
  msg_unknown_t  *un_next;	 /**< Link to next unknown header */
  char const     *un_name;	 /**< Header name */
  char const     *un_value;	 /**< Header field value */
};

/** Erroneus header. */
struct msg_error_s {
  msg_common_t    er_common[1];  /**< Common fragment info */
  msg_error_t    *er_next;	 /**< Link to next header */
  char const     *er_name;       /**< Name of bad header (if any). */
};


/** Separator. */
struct msg_separator_s {
  msg_common_t    sep_common[1]; /**< Common fragment info */
  msg_error_t    *sep_next;	 /**< Dummy link to next header */
  char            sep_data[4];	 /**< NUL-terminated separator */
};

/** Message payload. */
struct msg_payload_s {
  msg_common_t    pl_common[1];	    /**< Common fragment info */
  msg_payload_t  *pl_next;	    /**< Next payload chunk */
  char           *pl_data;	    /**< Data - may contain NUL */
218
  usize_t         pl_len;	    /**< Length of message payload */
Pekka Pessi's avatar
Pekka Pessi committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
};

/** Any header. */
union msg_header_u {
  msg_common_t    sh_common[1];	    /**< Common fragment info */
  struct {
    msg_common_t  shn_common;
    msg_header_t *shn_next;
  }               sh_header_next[1];
#define sh_next   sh_header_next->shn_next
#define sh_class  sh_common->h_class
#define sh_succ   sh_common->h_succ
#define sh_prev   sh_common->h_prev
#define sh_data   sh_common->h_data
#define sh_len    sh_common->h_len

  msg_generic_t   sh_generic[1];
  msg_numeric_t   sh_numeric[1];
  msg_list_t      sh_list[1];
  msg_auth_t      sh_auth[1];
  msg_separator_t sh_separator[1];
  msg_payload_t   sh_payload[1];
  msg_unknown_t   sh_unknown[1];
  msg_error_t     sh_error[1];
};

245 246 247 248 249 250 251 252 253 254 255 256 257 258
/* ====================================================================== */

/**Define how to handle existing headers 
 * when a new header is added to a message. 
 */
typedef enum {
  msg_kind_single,		/**< Only one header is allowed */
  msg_kind_append,		/**< New header is appended */
  msg_kind_list,		/**< A token list header, 
				 * new header is combined with old one. */
  msg_kind_apndlist,		/**< A complex list header. */
  msg_kind_prepend		/**< New header is prepended */
} msg_header_kind_t;

259 260
struct su_home_s;

261 262 263
typedef issize_t msg_parse_f(struct su_home_s *, msg_header_t *, char *, isize_t);
typedef issize_t msg_print_f(char buf[], isize_t bufsiz, 
			     msg_header_t const *, int flags);
264
typedef char *msg_dup_f(msg_header_t *dst, msg_header_t const *src, 
265 266
			char *buf, isize_t bufsiz);
typedef isize_t msg_xtra_f(msg_header_t const *h, isize_t offset);
267

268
typedef int msg_update_f(msg_common_t *, char const *name, isize_t namelen,
269 270
			 char const *value);

271 272 273 274 275 276 277 278 279
/** Factory object for a header. 
 * 
 * The #msg_hclass_t object, "header class", defines how a header is
 * handled. It has parsing and printing functions, functions used to copy
 * header objects, header name and other information used when parsing,
 * printing, removing, adding and replacing headers within a message.
 */
struct msg_hclass_s
{
280
  /* XXX size of header class missing. Someone has saved bits in wrong place. */
281 282 283 284 285
  int               hc_hash;	/**< Header name hash or ID */
  msg_parse_f      *hc_parse;	/**< Parse header. */
  msg_print_f      *hc_print;	/**< Print header. */
  msg_xtra_f       *hc_dxtra;	/**< Calculate extra size for dup */
  msg_dup_f        *hc_dup_one;	/**< Duplicate one header. */
286
  msg_update_f     *hc_update;	/**< Update parameter(s) */
287 288 289 290
  char const 	   *hc_name;	/**< Full name. */
  short             hc_len;	/**< Length of hc_name. */
  char              hc_short[2];/**< Short name, if any. */
  unsigned char     hc_size;	/**< Size of header structure. */
291
  unsigned char     hc_params;	/**< Offset of parameter list */
292
  unsigned          hc_kind:3;	/**< Kind of header (#msg_header_kind_t):
293 294 295 296 297
				 * single, append, list, apndlist, prepend. */
  unsigned          hc_critical:1; /**< True if header is critical */
  unsigned          /*pad*/:0;
};

298 299
#define HC_LEN_MAX SHRT_MAX

300 301
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
302
#endif /* !defined MSG_TYPES_H */