nua.h 11.6 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
/**@file sofia-sip/nua.h  
 * @brief Sofia-SIP User Agent Library API
Pekka Pessi's avatar
Pekka Pessi committed
27 28 29 30 31 32 33
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Wed Feb 14 17:09:44 2001 ppessi
 */

#ifndef NUA_H
34
/** Defined when <sofia-sip/nua.h> has been included. */
Pekka Pessi's avatar
Pekka Pessi committed
35
#define NUA_H
Pekka Pessi's avatar
Pekka Pessi committed
36 37

#ifndef SU_WAIT_H
38
#include <sofia-sip/su_wait.h>
Pekka Pessi's avatar
Pekka Pessi committed
39 40
#endif

41 42 43 44
#ifndef SU_OS_NW_H
#include <sofia-sip/su_os_nw.h>
#endif

Pekka Pessi's avatar
Pekka Pessi committed
45
#ifndef URL_H
46
#include <sofia-sip/url.h>
Pekka Pessi's avatar
Pekka Pessi committed
47 48 49
#endif

#ifndef SIP_H
50
#include <sofia-sip/sip.h>
Pekka Pessi's avatar
Pekka Pessi committed
51 52
#endif

53
#ifndef NUA_TAG_H
54
#include <sofia-sip/nua_tag.h>
55 56 57 58
#endif

SOFIA_BEGIN_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
59 60 61 62 63 64 65 66 67 68 69 70
#ifndef NUA_MAGIC_T 
#define NUA_MAGIC_T void
#endif
/** Application context for NUA agent. */
typedef NUA_MAGIC_T nua_magic_t;

#ifndef NUA_HMAGIC_T 
#define NUA_HMAGIC_T void
#endif
/** Application context for NUA handle. */
typedef NUA_HMAGIC_T nua_hmagic_t;

71 72 73 74 75 76 77
/**Network change event levels given to NUTAG_DETECT_NETWORK_UPDATES().
 *
 * @sa NUTAG_DETECT_NETWORK_UPDATES(), #nua_i_network_changed
 *
 * @since New in @VERSION_1_12_2.
 */
typedef enum nua_nw_detector_e {
78 79 80 81 82
  NUA_NW_DETECT_NOTHING = 0,
  NUA_NW_DETECT_ONLY_INFO,
  NUA_NW_DETECT_TRY_FULL,
} nua_nw_detector_t;

Pekka Pessi's avatar
Pekka Pessi committed
83 84 85
/** Events */
typedef enum nua_event_e {
  /* Indications */
Pekka Pessi's avatar
Pekka Pessi committed
86
  nua_i_error,			/**< Error indication */
Pekka Pessi's avatar
Pekka Pessi committed
87 88

  nua_i_invite,			/**< Incoming call */
89 90
  nua_i_cancel,			/**< Incoming INVITE has been cancelled */
  nua_i_ack,			/**< Response to INVITE has been ACKed */
Pekka Pessi's avatar
Pekka Pessi committed
91 92
  nua_i_fork,			/**< Outgoing call has been forked */
  nua_i_active,			/**< A call has been activated */
93 94
  nua_i_terminated,		/**< A call has been terminated */
  nua_i_state,		        /**< Call state has changed */
Pekka Pessi's avatar
Pekka Pessi committed
95

Pekka Pessi's avatar
Pekka Pessi committed
96 97
  nua_i_outbound,		/**< Status from outbound processing */

Pekka Pessi's avatar
Pekka Pessi committed
98 99 100 101 102 103 104 105 106 107
  nua_i_bye,			/**< Incoming call hangup */
  nua_i_options,		/**< Incoming options */
  nua_i_refer,			/**< Incoming call transfer */
  nua_i_publish,		/**< Incoming PUBLISH */
  nua_i_prack,			/**< Incoming PRACK */
  nua_i_info,			/**< Incoming session INFO */
  nua_i_update,			/**< Incoming session UPDATE */
  nua_i_message,		/**< Incoming MESSAGE */
  nua_i_chat,			/**< Incoming chat MESSAGE  */
  nua_i_subscribe,		/**< Incoming subscription */
108
  nua_i_subscription,		/**< Incoming subscription to be authorized */
Pekka Pessi's avatar
Pekka Pessi committed
109 110 111
  nua_i_notify,			/**< Incoming event */
  nua_i_method,			/**< Incoming, unknown method */

Pekka Pessi's avatar
Pekka Pessi committed
112
  nua_i_media_error,		/**< Offer-answer error indication */
Pekka Pessi's avatar
Pekka Pessi committed
113 114

  /* Responses */
115
  nua_r_set_params,		/**< Answer to nua_set_params() */
116
  nua_r_get_params,		/**< Answer to nua_get_params() or 
117
				 * nua_get_hparams(). */
Pekka Pessi's avatar
Pekka Pessi committed
118 119 120
  nua_r_shutdown,		/**< Answer to nua_shutdown() */
  nua_r_notifier,		/**< Answer to nua_notifier() */
  nua_r_terminate,		/**< Answer to nua_terminate() */
121
  nua_r_authorize,		/**< Answer to nua_authorize()  */
Pekka Pessi's avatar
Pekka Pessi committed
122 123 124 125 126

  /* SIP responses */
  nua_r_register,		/**< Answer to outgoing REGISTER */
  nua_r_unregister,		/**< Answer to outgoing un-REGISTER */
  nua_r_invite,		        /**< Answer to outgoing INVITE */
127
  nua_r_cancel,			/**< Answer to outgoing CANCEL */
Pekka Pessi's avatar
Pekka Pessi committed
128 129 130 131
  nua_r_bye,			/**< Answer to outgoing BYE */
  nua_r_options,		/**< Answer to outgoing OPTIONS */
  nua_r_refer,			/**< Answer to outgoing REFER */
  nua_r_publish,		/**< Answer to outgoing PUBLISH */
Pekka Pessi's avatar
Pekka Pessi committed
132
  nua_r_unpublish,		/**< Answer to outgoing un-PUBLISH */
Pekka Pessi's avatar
Pekka Pessi committed
133
  nua_r_info,		        /**< Answer to outgoing INFO */
Pekka Pessi's avatar
Pekka Pessi committed
134
  nua_r_prack,			/**< Answer to outgoing PRACK */
Pekka Pessi's avatar
Pekka Pessi committed
135 136
  nua_r_update,		        /**< Answer to outgoing UPDATE */
  nua_r_message,		/**< Answer to outgoing MESSAGE */
Pekka Pessi's avatar
Pekka Pessi committed
137
  nua_r_chat,			/**< Answer to outgoing chat message */
Pekka Pessi's avatar
Pekka Pessi committed
138 139 140
  nua_r_subscribe,		/**< Answer to outgoing SUBSCRIBE */
  nua_r_unsubscribe,		/**< Answer to outgoing un-SUBSCRIBE */
  nua_r_notify,			/**< Answer to outgoing NOTIFY */
Pekka Pessi's avatar
Pekka Pessi committed
141
  nua_r_method,			/**< Answer to unknown outgoing method */
Martti Mela's avatar
Martti Mela committed
142
 
143
  /* Internal events: nua hides them from application */
Pekka Pessi's avatar
Pekka Pessi committed
144 145 146 147
  nua_r_authenticate,
  nua_r_redirect,
  nua_r_destroy,
  nua_r_respond,
148
  nua_r_nit_respond,
Pekka Pessi's avatar
Pekka Pessi committed
149 150
  nua_r_ack,			/*#< Answer to ACK */

Martti Mela's avatar
Martti Mela committed
151 152
  /* NOTE: Post 1.12 release events come here (below) to keep ABI
     compatibility! */
153
  nua_i_network_changed,        /**< Local IP(v6) address has changed */
Martti Mela's avatar
Martti Mela committed
154

Pekka Pessi's avatar
Pekka Pessi committed
155 156
} nua_event_t;

157 158 159 160 161 162 163 164 165 166
typedef struct event_s {
  nua_handle_t *e_nh;
  int           e_event;
  short         e_always;
  short         e_status;
  char const   *e_phrase;
  msg_t        *e_msg;
  tagi_t        e_tags[1];
} nua_event_data_t;

Pekka Pessi's avatar
Pekka Pessi committed
167 168 169
/** NUA API version */
#define NUA_VERSION "2.0"
/** NUA module version */
170
SOFIAPUBVAR char const nua_version[];
Pekka Pessi's avatar
Pekka Pessi committed
171 172 173 174 175 176 177 178 179

typedef void (*nua_callback_f)(nua_event_t event,
			       int status, char const *phrase,
			       nua_t *nua, nua_magic_t *magic,
			       nua_handle_t *nh, nua_hmagic_t *hmagic,
			       sip_t const *sip,
			       tagi_t tags[]);

/** Create a NUA agent. */
180 181 182 183 184
SOFIAPUBFUN nua_t *nua_create(su_root_t *root,
			      nua_callback_f callback,
			      nua_magic_t *magic,
			      tag_type_t tag, tag_value_t value,
			      ...);
Pekka Pessi's avatar
Pekka Pessi committed
185 186

/** Shutdown NUA stack. */
187
SOFIAPUBFUN void nua_shutdown(nua_t *nua);
Pekka Pessi's avatar
Pekka Pessi committed
188 189

/** Destroy the NUA stack. */
190
SOFIAPUBFUN void nua_destroy(nua_t *nua);
Pekka Pessi's avatar
Pekka Pessi committed
191 192

/** Set NUA parameters. */
193
SOFIAPUBFUN void nua_set_params(nua_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
194 195

/** Get NUA parameters. */
196
SOFIAPUBFUN void nua_get_params(nua_t *nua, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
197 198

/** Obtain default operation handle of the NUA stack object. */
199
SOFIAPUBFUN nua_handle_t *nua_default(nua_t *nua);
Pekka Pessi's avatar
Pekka Pessi committed
200 201

/** Create an operation handle */
202 203
SOFIAPUBFUN nua_handle_t *nua_handle(nua_t *nua, nua_hmagic_t *hmagic,
				     tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
204 205

/** Destroy a handle */
206
SOFIAPUBFUN void nua_handle_destroy(nua_handle_t *h);
Pekka Pessi's avatar
Pekka Pessi committed
207

208
/** Make a new reference to handle */
209
SOFIAPUBFUN nua_handle_t *nua_handle_ref(nua_handle_t *);
210 211

/** Destroy reference to handle */
212
SOFIAPUBFUN int nua_handle_unref(nua_handle_t *);
213

Pekka Pessi's avatar
Pekka Pessi committed
214
/** Bind a callback context to an operation handle. */
215
SOFIAPUBFUN void nua_handle_bind(nua_handle_t *nh, nua_hmagic_t *magic);
Pekka Pessi's avatar
Pekka Pessi committed
216

217
/** Set handle parameters. */
218
SOFIAPUBFUN void nua_set_hparams(nua_handle_t *, tag_type_t, tag_value_t, ...);
219 220

/** Get handle parameters. */
221
SOFIAPUBFUN void nua_get_hparams(nua_handle_t *, tag_type_t, tag_value_t, ...);
222

Pekka Pessi's avatar
Pekka Pessi committed
223
/** Check if operation handle is used for INVITE */
224
SOFIAPUBFUN int nua_handle_has_invite(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
225 226

/** Check if operation handle has been used with outgoing SUBSCRIBE of REFER request. */
227
SOFIAPUBFUN int nua_handle_has_subscribe(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
228 229

/** Check if operation handle has been used with nua_register() or nua_unregister(). */
230
SOFIAPUBFUN int nua_handle_has_register(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
231 232

/** Check if operation handle has an active call */
233
SOFIAPUBFUN int nua_handle_has_active_call(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
234 235

/** Check if operation handle has a call on hold */
236
SOFIAPUBFUN int nua_handle_has_call_on_hold(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
237 238

/** Check if handle has active event subscriptions (refers sent). */
239
SOFIAPUBFUN int nua_handle_has_events(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
240 241

/** Check if operation handle has active registrations */
242
SOFIAPUBFUN int nua_handle_has_registrations(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
243 244

/** Get the remote address (From/To header) of operation handle */
245
SOFIAPUBFUN sip_to_t const *nua_handle_remote(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
246 247

/** Get the local address (From/To header) of operation handle  */
248
SOFIAPUBFUN sip_to_t const *nua_handle_local(nua_handle_t const *nh);
Pekka Pessi's avatar
Pekka Pessi committed
249 250

/** Get name for NUA event. */
251
SOFIAPUBFUN char const *nua_event_name(nua_event_t event);
Pekka Pessi's avatar
Pekka Pessi committed
252

Pekka Pessi's avatar
Pekka Pessi committed
253 254 255
/** Get name for NUA callstate. */
SOFIAPUBFUN char const *nua_callstate_name(enum nua_callstate state);

Pekka Pessi's avatar
Pekka Pessi committed
256
/** Send SIP REGISTER request to the registrar. */ 
257
SOFIAPUBFUN void nua_register(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
258 259

/** Unregister. */ 
260
SOFIAPUBFUN void nua_unregister(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
261 262

/** Place a call using SIP INVITE method. */
263
SOFIAPUBFUN void nua_invite(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
264 265

/** Acknowledge a succesfull response to INVITE request. */ 
266
SOFIAPUBFUN void nua_ack(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
267

268
/** Acknowledge a reliable preliminary response to INVITE request. */
269
SOFIAPUBFUN void nua_prack(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
270

Pekka Pessi's avatar
Pekka Pessi committed
271
/** Query capabilities from server */
272
SOFIAPUBFUN void nua_options(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
273 274

/** Send PUBLISH request to publication server. */
275
SOFIAPUBFUN void nua_publish(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
276

Pekka Pessi's avatar
Pekka Pessi committed
277
/** Send un-PUBLISH request to publication server. */
278
SOFIAPUBFUN void nua_unpublish(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
279

Pekka Pessi's avatar
Pekka Pessi committed
280
/** Send an instant message. */
281
SOFIAPUBFUN void nua_message(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
282 283

/** Send a chat message. */
284
SOFIAPUBFUN void nua_chat(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
285 286

/** Send an INFO request. */
287
SOFIAPUBFUN void nua_info(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
288 289

/** Subscribe a SIP event. */
290
SOFIAPUBFUN void nua_subscribe(nua_handle_t *nh, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
291 292

/** Unsubscribe an event. */
293
SOFIAPUBFUN void nua_unsubscribe(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
294 295

/** Send a NOTIFY message. */
296
SOFIAPUBFUN void nua_notify(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
297 298

/** Create an event server. */
299
SOFIAPUBFUN void nua_notifier(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
300 301

/** Terminate an event server. */
302
SOFIAPUBFUN void nua_terminate(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
303 304

/** Transfer a call. */
305
SOFIAPUBFUN void nua_refer(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
306 307

/** Update a call */ 
308
SOFIAPUBFUN void nua_update(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
309 310

/** Hangdown a call. */
311
SOFIAPUBFUN void nua_bye(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
312 313

/** Cancel an INVITE operation */
314
SOFIAPUBFUN void nua_cancel(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
315 316
 
/** Authenticate an operation. */
317
SOFIAPUBFUN void nua_authenticate(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
318

319
/** Authorize a subscriber. */
320
SOFIAPUBFUN void nua_authorize(nua_handle_t *, tag_type_t, tag_value_t, ...);
321

322
/*# Redirect an operation. @deprecated */
323
SOFIAPUBFUN void nua_redirect(nua_handle_t *, tag_type_t, tag_value_t, ...);
Pekka Pessi's avatar
Pekka Pessi committed
324

325
/** Respond with given status. */
326 327 328 329
SOFIAPUBFUN void nua_respond(nua_handle_t *nh, 
			     int status, char const *phrase,
			     tag_type_t, tag_value_t, 
			     ...);
Pekka Pessi's avatar
Pekka Pessi committed
330 331 332

#define nua_handle_home(nh) ((su_home_t *)(nh))

333
/** Generate an instance identifier */
334
SOFIAPUBFUN char const *nua_generate_instance_identifier(su_home_t *);
335

Pekka Pessi's avatar
Pekka Pessi committed
336 337 338
#ifndef NUA_SAVED_EVENT_T
#define NUA_SAVED_EVENT_T struct nua_saved_event *
#endif
339
/** Abstract type for saved nua events. */
Pekka Pessi's avatar
Pekka Pessi committed
340 341
typedef NUA_SAVED_EVENT_T nua_saved_event_t;

342
/** Save last nua event */
343
SOFIAPUBFUN int nua_save_event(nua_t *nua, nua_saved_event_t return_saved[1]);
Pekka Pessi's avatar
Pekka Pessi committed
344

345
/** Get information from saved event */
346
SOFIAPUBFUN nua_event_data_t const *nua_event_data(nua_saved_event_t const saved[1]);
Pekka Pessi's avatar
Pekka Pessi committed
347

348
/** Destroy a save nua event */
349
SOFIAPUBFUN void nua_destroy_event(nua_saved_event_t *saved);
Pekka Pessi's avatar
Pekka Pessi committed
350

351 352
SOFIA_END_DECLS

Pekka Pessi's avatar
Pekka Pessi committed
353
#endif