nua_dialog.h 7.58 KB
Newer Older
1 2 3
/*
 * This file is part of the Sofia-SIP package
 *
4
 * Copyright (C) 2006 Nokia Corporation.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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
 *
 */

25 26
#ifndef NUA_DIALOG_H
/** Defined when <nua_dialog.h> has been included. */
27 28
#define NUA_DIALOG_H

29
/**@IFILE nua_dialog.h
30 31 32 33 34 35 36 37
 * @brief Dialog and dialog usage handling
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * @author Kai Vehmanen <Kai.Vehmanen@nokia.com>
 *
 * @date Created: Wed Mar  8 11:38:18 EET 2006  ppessi
 */

38
#include <nua_types.h>
39

40 41 42 43
#ifndef NTA_H
#include <sofia-sip/nta.h>
#endif

44 45 46 47
#ifndef SOA_H
#include <sofia-sip/soa.h>
#endif

48 49
struct nua_dialog_state
{
50 51 52
  /** Dialog owner */
  nua_owner_t            *ds_owner;

53 54 55
  /** Dialog usages. */
  nua_dialog_usage_t     *ds_usage;

56 57 58 59 60
  /** Client requests */
  nua_client_request_t   *ds_cr;
  /** Server requests */
  nua_server_request_t *ds_sr;

61 62
  soa_session_t *ds_soa;	/**< Media session */

63
  /* Dialog and subscription state */
64 65
  unsigned ds_reporting:1;	/**< We are reporting */

66
  unsigned ds_route:1;		/**< We have route */
67
  unsigned ds_terminating:1;	/**< Being terminated */
68 69 70 71

  unsigned ds_has_session:1;	/**< We have session */
  unsigned ds_has_register:1;	/**< We have registration */
  unsigned ds_has_publish:1;	/**< We have publish */
72

73
  unsigned ds_got_session:1;	/**< We have (or have had) session */
74
  unsigned ds_got_referrals:1;	/**< We have (or have had) referrals */
75

76 77 78 79 80 81 82 83 84
  unsigned :0;

  unsigned ds_has_events;	/**< We have events */
  unsigned ds_has_subscribes;   /**< We have subscriptions */
  unsigned ds_has_notifys;	/**< We have notifiers */

  sip_from_t const *ds_local;		/**< Local address */
  sip_to_t const *ds_remote;		/**< Remote address */
  nta_leg_t      *ds_leg;
85
  sip_contact_t  *ds_ltarget;	        /**< Local target */
86 87
  char const     *ds_remote_tag;	/**< Remote tag (if any).
					 * Should be non-NULL
88 89
					 * if dialog is established.
					 */
90

91
  struct nua_dialog_peer_info {
92 93 94 95 96 97 98 99
    sip_allow_t      *nr_allow;
    sip_accept_t     *nr_accept;
    sip_require_t    *nr_require;
    sip_supported_t  *nr_supported;
    sip_user_agent_t *nr_user_agent;
  } ds_remote_ua[1];
};

Pekka Pessi's avatar
Pekka Pessi committed
100
/* Virtual function pointer table for dialog usage. */
101 102
typedef struct {
  unsigned usage_size, usage_class_size;
103
  int (*usage_add)(nua_owner_t *,
104 105
		   nua_dialog_state_t *ds,
		   nua_dialog_usage_t *du);
106
  void (*usage_remove)(nua_owner_t *,
107
		       nua_dialog_state_t *ds,
108 109 110
		       nua_dialog_usage_t *du,
		       nua_client_request_t *cr,
		       nua_server_request_t *sr);
111
  char const *(*usage_name)(nua_dialog_usage_t const *du);
112 113 114 115
  void (*usage_update_params)(nua_dialog_usage_t const *du,
			      nua_handle_preferences_t const *changed,
			      nua_handle_preferences_t const *params,
			      nua_handle_preferences_t const *defaults);
116 117 118
  void (*usage_peer_info)(nua_dialog_usage_t *du,
			  nua_dialog_state_t const *ds,
			  sip_t const *sip);
119
  void (*usage_refresh)(nua_owner_t *, nua_dialog_state_t *ds,
120
			nua_dialog_usage_t *du);
121
  int (*usage_shutdown)(nua_owner_t *, nua_dialog_state_t *ds,
122
			nua_dialog_usage_t *);
123 124
} nua_usage_class;

125

Pekka Pessi's avatar
Pekka Pessi committed
126
/* Base structure for dialog usage. */
127 128 129
struct nua_dialog_usage {
  nua_dialog_usage_t *du_next;
  nua_usage_class const *du_class;
130
  nua_dialog_state_t *du_dialog;
131
  nua_client_request_t *du_cr;	        /**< Client request bound with usage */
132
  sip_time_t   du_refquested;	        /**< When refreshed was requested */
133
  su_timer_t  *du_refresh_timer;        /**< The timer for refresh, expiration, or retry */
134 135

  unsigned     du_ready:1;	        /**< Established usage */
136
  unsigned     du_shutdown:1;	        /**< Shutdown in progress */
137 138
  unsigned:0;

139 140 141 142 143
  /** When usage expires.
   * Non-zero if the usage is established, SIP_TIME_MAX if there no
   * expiration time.
   */

144
  sip_event_t const *du_event;		/**< Event of usage */
145

146 147
};

148
void nua_dialog_uac_route(nua_owner_t *, nua_dialog_state_t *ds,
149
			  sip_t const *sip, int rtag, int initial);
150 151 152 153
void nua_dialog_uas_route(nua_owner_t *, nua_dialog_state_t *ds,
			  sip_t const *sip, int rtag);
void nua_dialog_store_peer_info(nua_owner_t *, nua_dialog_state_t *ds,
				sip_t const *sip);
154 155
int nua_dialog_zap(nua_owner_t *own,
		   nua_dialog_state_t *ds);
156 157 158
int nua_dialog_remove(nua_owner_t *own,
		      nua_dialog_state_t *ds,
		      nua_dialog_usage_t *usage);
159

160
su_inline int nua_dialog_is_reporting(nua_dialog_state_t const *ds)
161 162 163 164
{
  return ds && ds->ds_reporting;
}

165 166
char const *nua_dialog_usage_name(nua_dialog_usage_t const *du);

167
nua_dialog_usage_t *nua_dialog_usage_add(nua_owner_t *,
168 169 170 171
					 struct nua_dialog_state *ds,
					 nua_usage_class const *uclass,
					 sip_event_t const *event);

172
nua_dialog_usage_t *nua_dialog_usage_get(nua_dialog_state_t const *ds,
173 174 175
					 nua_usage_class const *uclass,
					 sip_event_t const *event);

176
void nua_dialog_usage_remove(nua_owner_t *,
177
			     nua_dialog_state_t *ds,
178 179 180
			     nua_dialog_usage_t *du,
			     nua_client_request_t *cr,
			     nua_server_request_t *sr);
181

182 183 184 185 186 187 188 189 190 191
void nua_dialog_update_params(nua_dialog_state_t *ds,
			      nua_handle_preferences_t const *changed,
			      nua_handle_preferences_t const *params,
			      nua_handle_preferences_t const *defaults);

void nua_base_usage_update_params(nua_dialog_usage_t const *du,
				  nua_handle_preferences_t const *changed,
				  nua_handle_preferences_t const *params,
				  nua_handle_preferences_t const *defaults);

192 193 194
void nua_dialog_deinit(nua_owner_t *own,
		       nua_dialog_state_t *ds);

195 196
int nua_dialog_shutdown(nua_owner_t *owner, nua_dialog_state_t *ds);

197 198 199
int nua_dialog_repeat_shutdown(nua_owner_t *owner,
			       nua_dialog_state_t *ds);

200 201
void nua_dialog_usage_set_refresh(nua_dialog_usage_t *du, unsigned delta);

202 203 204
void nua_dialog_usage_set_refresh_in(nua_dialog_usage_t *du,
                                     unsigned delta);

205
void nua_dialog_usage_set_refresh_range(nua_dialog_usage_t *du,
206
					unsigned min, unsigned max);
207

208
void nua_dialog_usage_set_refresh_at(nua_dialog_usage_t *du,
209
				     sip_time_t target);
210

211 212
void nua_dialog_usage_reset_refresh(nua_dialog_usage_t *du);

213
void nua_dialog_usage_refresh(nua_owner_t *owner,
214
			      nua_dialog_state_t *ds,
215
			      nua_dialog_usage_t *du);
216

217 218 219
int nua_dialog_usage_shutdown(nua_owner_t *owner,
			      nua_dialog_state_t *ds,
			      nua_dialog_usage_t *du);
220

221
su_inline
222 223 224 225 226 227
int nua_dialog_is_established(nua_dialog_state_t const *ds)
{
  return ds->ds_remote_tag != NULL;
}

#if 0
228
su_inline
229 230
void *nua_dialog_usage_private(nua_dialog_usage_t const *du)
{
231 232 233
  return du ? (void *)(du + 1) : NULL;
}

234
su_inline
235 236 237
nua_dialog_usage_t *nua_dialog_usage_public(void const *p)
{
  return p ? (nua_dialog_usage_t *)p - 1 : NULL;
238 239
}
#else
240 241
#define nua_dialog_usage_private(du) ((du) ? (void*)((du) + 1) : NULL)
#define nua_dialog_usage_public(p) ((p) ? (nua_dialog_usage_t*)(p) - 1 : NULL)
242 243
#endif

244 245 246
#define NUA_DIALOG_USAGE_PRIVATE(du) ((void *)((du) + 1))
#define NUA_DIALOG_USAGE_PUBLIC(pu) ((void *)((nua_dialog_usage_t *)(pu) - 1))

247 248
#include "nua_client.h"
#include "nua_server.h"
249

250
#endif /* NUA_DIALOG_H */