msg_internal.h 4.47 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
 *
 */

25 26
#ifndef MSG_INTERNAL_H
/** Defined when <msg_internal.h> has been included. */
Pekka Pessi's avatar
Pekka Pessi committed
27 28
#define MSG_INTERNAL_H 

29
/**@IFILE msg_internal.h 
Pekka Pessi's avatar
Pekka Pessi committed
30 31 32 33 34 35 36 37 38 39 40 41
 * @brief Abstract messages - internal interface 
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Thu Jun 29 15:58:06 2000 ppessi
 *
 */

#ifdef MSG_H
#error "msg_internal.h" should be included before "msg.h"
#endif

42 43 44
#include "sofia-sip/msg.h"
#include "sofia-sip/msg_addr.h"
#include "sofia-sip/msg_buffer.h"
Pekka Pessi's avatar
Pekka Pessi committed
45 46

#ifndef SU_ALLOC_H
47
#include <sofia-sip/su_alloc.h>
Pekka Pessi's avatar
Pekka Pessi committed
48 49
#endif

50 51
SOFIA_BEGIN_DECLS

52 53 54 55 56 57 58
/* ---------------------------------------------------------------------- */
/* Types used when handling streaming */

typedef struct msg_buffer_s msg_buffer_t;

/* ---------------------------------------------------------------------- */

Pekka Pessi's avatar
Pekka Pessi committed
59 60 61 62 63 64 65 66
struct msg_s {
  su_home_t           m_home[1]; /**< Memory home */

  msg_mclass_t const *m_class;	/**< Message class */
  int                 m_oflags;	/**< Original flags */

  msg_pub_t          *m_object;	/**< Public view to parsed message */

67 68
  size_t              m_maxsize;/**< Maximum size */
  size_t              m_size;	/**< Total size of fragments */
Pekka Pessi's avatar
Pekka Pessi committed
69 70 71 72 73 74 75 76 77

  msg_header_t       *m_chain;	/**< Fragment chain */
  msg_header_t      **m_tail;	/**< Tail of fragment chain */

  msg_payload_t      *m_chunk;	/**< Incomplete payload fragment */

  /* Parsing/printing buffer */
  struct msg_mbuffer_s {
    char     *mb_data;		/**< Pointer to data */
78 79 80
    usize_t   mb_size;		/**< Size of buffer */
    usize_t   mb_used;		/**< Used data */
    usize_t   mb_commit;	/**< Data committed to msg */
Pekka Pessi's avatar
Pekka Pessi committed
81 82 83 84 85
    unsigned  mb_eos:1;		/**< End-of-stream flag */
    unsigned :0;
  } m_buffer[1];

  msg_buffer_t  *m_stream;	/**< User-provided buffers */
86
  size_t         m_ssize;	/**< Stream size */
Pekka Pessi's avatar
Pekka Pessi committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

  unsigned short m_extract_err; /**< Bitmask of erroneous headers */
  /* Internal flags */
  unsigned     	 m_set_buffer:1;/**< Buffer has been set */
  unsigned     	 m_streaming:1; /**< Use streaming with message */
  unsigned       m_prepared:1;	/**< Prepared/not */
  unsigned  :0;

  msg_t        	*m_next;	/**< Next message */

  msg_t        	*m_parent;	/**< Reference to a parent message */
  int          	 m_refs;	/**< Number of references to this message */

  su_addrinfo_t	 m_addrinfo;	/**< Message addressing info (protocol) */
  su_sockaddr_t	 m_addr[1];	/**< Message address */

  int          	 m_errno;	/**< Errno */
};

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
/** Buffer for message body. */
struct msg_buffer_s {
  char           *b_data;	    /**< Data - may contain NUL */
  size_t          b_size;	    /**< Length of message payload */
  size_t          b_used;	    /**< Used data */
  size_t          b_avail;	    /**< Available data */
  int             b_complete;	    /**< This buffer completes the message */
  msg_buffer_t   *b_next;	    /**< Next buffer */
  msg_payload_t  *b_chunks;	    /**< List of body chunks */
};

/** Maximum size when streaming. */
#define MSG_SSIZE_MAX (USIZE_MAX)

/* ---------------------------------------------------------------------- */
/* Header-kind predicate functions. */
122
su_inline int msg_is_single(msg_header_t const *h)
123 124 125 126
{
  return h->sh_class->hc_kind == msg_kind_single;
}

127
su_inline int msg_is_prepend(msg_header_t const *h)
128 129 130 131
{
  return h->sh_class->hc_kind == msg_kind_prepend;
}

132
su_inline int msg_is_append(msg_header_t const *h)
133 134 135 136 137 138
{
  return 
    h->sh_class->hc_kind == msg_kind_append ||
    h->sh_class->hc_kind == msg_kind_apndlist;
}

139
su_inline int msg_is_list(msg_header_t const *h)
140 141 142 143
{
  return h->sh_class->hc_kind == msg_kind_list;
}

144
su_inline int msg_is_special(msg_header_t const *h)
145 146 147 148
{
  return h->sh_class->hc_hash < 0;
}

149 150
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
151
#endif /* MSG_INTERNAL_H */