nua_glib.c 76.7 KB
Newer Older
1 2 3 4 5 6
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005-2006 Nokia Corporation.
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
7 8
 * Copyright (C) 2005 Collabora Ltd.
 *
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * 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
 *
 */

/**@file nua_glib.c Interface towards libsofia-sip-ua.
 * 
 * @author Kai Vehmanen <kai.vehmanen@nokia.com>
 * @author Rob Taylor <rob.taylor@collabora.co.uk>
 * @author Pekka Pessi <pekka.pessi@nokia.com>
31
 * @author Martti Mela <martti.mela@nokia.com>
32 33 34 35 36 37 38 39 40 41 42 43 44
 */

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>

#include <glib.h>

#include "sofia-sip/nua_glib.h"
#include "nua_glib_priv.h"
45
#include "nua_glib_op.h"
46 47 48
#include "nua_glib_marshal.h"

/*=============== Class and Object init ===============*/
49
G_DEFINE_TYPE(NuaGlib, nua_glib, G_TYPE_OBJECT);
50 51 52 53
  
/*signal enum*/
enum
{
54 55 56 57 58 59 60 61 62 63 64 65 66
  NGSIG_CALL_FORKED = 1,
  NGSIG_INCOMING_INVITE,
  NGSIG_INCOMING_REINVITE,
  NGSIG_CALL_STATE_CHANGED,
  NGSIG_INCOMING_ACTIVE,
  NGSIG_CALL_TERMINATED,
  NGSIG_INCOMING_PRACK,
  NGSIG_INCOMING_BYE,
  NGSIG_INCOMING_CANCEL,
  NGSIG_INCOMING_MESSAGE,
  NGSIG_INCOMING_INFO,
  NGSIG_INCOMING_REFER,
  NGSIG_INCOMING_NOTIFY,
67
  NGSIG_INCOMING_SUBSCRIBE,
68 69 70 71 72 73 74 75 76

  NGSIG_ERROR,
  NGSIG_SHUTDOWN,

  NGSIG_REGISTER_ANSWERED,
  NGSIG_UNREGISTER_ANSWERED,
  NGSIG_PUBLISH_ANSWERED,
  NGSIG_INVITE_ANSWERED,
  NGSIG_BYE_ANSWERED,
77
  NGSIG_CANCEL_ANSWERED,
78 79 80 81 82 83 84 85 86 87 88
  NGSIG_MESSAGE_ANSWERED,
  NGSIG_INFO_ANSWERED,
  NGSIG_REFER_ANSWERED,
  NGSIG_SUBSCRIBE_ANSWERED,
  NGSIG_UNSUBSCRIBE_ANSWERED,
  NGSIG_NOTIFY_ANSWERED,
  NGSIG_OPTIONS_ANSWERED,

  NGSIG_AUTH_REQUIRED,

  NGSIG_LAST_SIGNAL
89 90
};

91 92
/*=============== Static variables ===============*/

93
static guint signals[NGSIG_LAST_SIGNAL] = {0};
94 95 96

enum
{
97 98 99
  PROP_ADDRESS = 1,
  PROP_PASSWORD,
  PROP_CONTACT,
100 101
  PROP_PROXY,
  PROP_REGISTRAR,
102
  PROP_STUN_SERVER,
103 104 105 106 107
  LAST_PROPERTY
};

static GObjectClass *parent_class=NULL;  

108 109
/*=============== Private function declarations ===============*/

110
static int sof_init(NuaGlibPrivate *priv, const char *contact);
111
static void priv_submit_authlist(NuaGlibOp *op);
112 113
static void priv_oper_handle_auth (NuaGlib *self, NuaGlibOp *op, sip_t const *sip, tagi_t *tags);
static void priv_oper_check_response_for_auth(NuaGlib *self, NuaGlibOp *op, int status, sip_t const *sip, tagi_t *tags);
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
static void sof_callback(nua_event_t event,
		  int status, char const *phrase,
		  nua_t *nua, NuaGlib *self,
		  nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		  tagi_t tags[]);

static void sof_r_register(int status, char const *phrase,
		      nua_t *nua, NuaGlib *self,
		      nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		      tagi_t tags[]);

static void sof_r_unregister(int status, char const *phrase,
		      nua_t *nua, NuaGlib *self,
		      nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		      tagi_t tags[]);

static void sof_r_publish(int status, char const *phrase,
		   nua_t *nua, NuaGlib *self,
		   nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		   tagi_t tags[]);

static void sof_r_invite(int status, char const *phrase,
		  nua_t *nua, NuaGlib *self,
		  nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		  tagi_t tags[]);
static void sof_i_fork(int status, char const *phrase,
		nua_t *nua, NuaGlib *self,
		nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		tagi_t tags[]);

static void sof_i_invite(nua_t *nua, NuaGlib *self,
145 146
			 nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
			 tagi_t tags[]);
147 148

static void sof_i_state(int status, char const *phrase, 
149 150 151
			nua_t *nua, NuaGlib *self,
			nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
			tagi_t tags[]);
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

static void sof_i_active(nua_t *nua, NuaGlib *self,
		    nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		    tagi_t tags[]);

static void sof_i_terminated(int status, char const *phrase, 
		      nua_t *nua, NuaGlib *self,
		      nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		      tagi_t tags[]);

static void sof_i_prack(nua_t *nua, NuaGlib *self,
		 nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		 tagi_t tags[]);

static void sof_r_bye(int status, char const *phrase, 
167 168 169
		      nua_t *nua, NuaGlib *self,
		      nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		      tagi_t tags[]);
170 171 172 173 174 175 176 177 178

static void sof_i_bye(nua_t *nua, NuaGlib *self,
		 nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		 tagi_t tags[]);

static void sof_i_cancel(nua_t *nua, NuaGlib *self,
		    nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		    tagi_t tags[]);

179 180 181 182 183
static void sof_r_cancel(int status, char const *phrase, 
			 nua_t *nua, NuaGlib *self,
			 nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
			 tagi_t tags[]);

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
static void sof_r_message(int status, char const *phrase,
		   nua_t *nua, NuaGlib *self,
		   nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		   tagi_t tags[]);

static void sof_i_message(nua_t *nua, NuaGlib *self,
		   nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		   tagi_t tags[]);

static void sof_r_info(int status, char const *phrase,
		nua_t *nua, NuaGlib *self,
		nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		tagi_t tags[]);

static void sof_i_info(nua_t *nua, NuaGlib *self,
		nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		tagi_t tags[]);

static void sof_r_refer(int status, char const *phrase,
		   nua_t *nua, NuaGlib *self,
		   nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		   tagi_t tags[]);

static void sof_i_refer(nua_t *nua, NuaGlib *self,
		   nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		   tagi_t tags[]);

211 212 213 214 215 216 217 218 219
static void sof_r_notifier(nua_event_t event, int status,
			   char const *phrase, nua_t *nua,
			   NuaGlib *self, nua_handle_t *nh,
			   NuaGlibOp *op, sip_t const *sip,
			   tagi_t tags[]);

static void sof_i_subscribe(nua_t *nua, NuaGlib *self, nua_handle_t *nh,
			    NuaGlibOp *op, sip_t const *sip, tagi_t tags[]);

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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
static void sof_r_subscribe(int status, char const *phrase,
		     nua_t *nua, NuaGlib *self,
		     nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		     tagi_t tags[]);

static void sof_r_unsubscribe(int status, char const *phrase,
		       nua_t *nua, NuaGlib *self,
		       nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		       tagi_t tags[]);

static void sof_r_notify(int status, char const *phrase,
		   nua_t *nua, NuaGlib *self,
		   nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		   tagi_t tags[]);

static void sof_i_notify(nua_t *nua, NuaGlib *self,
		    nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		    tagi_t tags[]);

static void sof_r_options(int status, char const *phrase,
		   nua_t *nua, NuaGlib *self,
		   nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		   tagi_t tags[]);

static void sof_r_shutdown(int status, char const *phrase, 
		    nua_t *nua, NuaGlib *self,
		    nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		    tagi_t tags[]);

static void sof_r_get_params(int status, char const *phrase,
		      nua_t *nua, NuaGlib *self,
		      nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
		      tagi_t tags[]);

static void sof_i_error(nua_t *nua, NuaGlib *self, nua_handle_t *nh, NuaGlibOp *op, 
		 int status, char const *phrase,
		 tagi_t tags[]);

/*=============== Function definitions ===============*/

void final_shutdown(NuaGlib *self)
{
  g_object_unref(self);
}
264 265 266

static GObject *
nua_glib_constructor (GType                  type,
267 268
		      guint                  n_construct_properties,
		      GObjectConstructParam *construct_properties)
269 270 271 272
{
  GObject *obj;
  int res = 0;
  GSource *gsource;
Pekka Pessi's avatar
Pekka Pessi committed
273
  NuaGlib *self;
274 275 276 277 278 279 280 281 282 283 284 285 286 287

  {
    /* Invoke parent constructor.
     * this calls our init, and then set_property with any
     * CONSTRUCT params
     */
    NuaGlibClass *klass;
    klass = NUA_GLIB_CLASS (g_type_class_peek (NUA_GLIB_TYPE));
    parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
    obj = parent_class->constructor (type,
                                     n_construct_properties,
                                     construct_properties);
  }
  
Pekka Pessi's avatar
Pekka Pessi committed
288
  self = NUA_GLIB(obj);
289 290 291

  /* create a su event loop and connect it to glib */
  self->priv->root = su_root_source_create(self);
292
  g_assert(self->priv->root);
293
  gsource = su_root_gsource(self->priv->root);
294
  g_assert(gsource);
295 296 297 298 299
  g_source_attach(gsource, NULL);

  /*check address has been set*/
  g_assert(strcmp(self->priv->address, "no-address-set")!=0);

300
  res = sof_init(self->priv, self->priv->contact);
301 302 303

  if (res != -1) {
    self->priv->nua = nua_create(self->priv->root, 
304 305
				 sof_callback, self,
				 NUTAG_SOA_NAME("default"),
306 307
				 TAG_IF(self->priv->stun_server,
					STUNTAG_SERVER(self->priv->stun_server)),
308 309
				 TAG_IF(self->priv->contact,
					NUTAG_URL(self->priv->contact)),
310
				 /* XXX: SOATAG_CAPS_SDP_STR(local_caps), */
311
				 TAG_NULL());
312 313 314 315 316 317 318
    if (self->priv->nua) {

      nua_set_params(self->priv->nua,
                     TAG_IF(self->priv->proxy, NUTAG_PROXY(self->priv->proxy)),
                     TAG_IF(self->priv->registrar, NUTAG_REGISTRAR(self->priv->registrar)),
                     NUTAG_ENABLEMESSAGE(1),
                     NUTAG_ENABLEINVITE(1),
319 320
                     /* NUTAG_SESSION_TIMER(s_e), */
                     /* NUTAG_MIN_SE(min_se), */
321 322
                     SOATAG_AF(SOA_AF_IP4_IP6),
                     SIPTAG_FROM_STR(self->priv->address),
323
                     /* NUTAG_CERTIFICATE_DIR(getenv("SIPCERTDIR")),*/
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
                     TAG_NULL());
      nua_get_params(self->priv->nua, TAG_ANY(), TAG_NULL());

      self->priv->init=TRUE;
      g_signal_connect_after(self, "shutdown", (GCallback)final_shutdown, NULL);
    }
  }
  return obj;
}

static void
nua_glib_init(NuaGlib *self)
{
  self->priv =  g_new0(NuaGlibPrivate, 1);
 /* initialize sofia su OS abstraction layer */
  su_init();
  su_home_init(self->priv->home);
}

static void
nua_glib_dispose(GObject *obj)
{
  NuaGlib *self = NUA_GLIB(obj);

  if (self->priv->init)
  {
    g_free((gpointer)self->priv->contact);

    nua_shutdown(self->priv->nua);

    self->priv->init = FALSE;
    /*now hold a ref to ourselves that we drop when distruction is complete*/
    g_object_ref (obj);
357 358

    /* XXX: some start/stop nua funtions to do su_init/de_init?  su_deinit();*/
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  }

  /* Chain up to the parent class */
  G_OBJECT_CLASS (parent_class)->dispose (obj);
}

static void
nua_glib_finalize (GObject *obj)
{
  NuaGlib *self = NUA_GLIB(obj);
  su_root_break(self->priv->root);
  nua_destroy(self->priv->nua);
  su_root_destroy(self->priv->root), self->priv->root = NULL;
  su_home_deinit(self->priv->home);
  g_free(self->priv);

  /* Chain up to the parent class */
  G_OBJECT_CLASS (parent_class)->finalize (obj); 
}

379 380 381 382 383
static
void nua_glib_set_property(GObject      *object,
			   guint         property_id,
			   const GValue *value,
			   GParamSpec   *pspec)
384 385 386
{
  NuaGlib *self = (NuaGlib*) object;

387 388 389 390
#define STORE_PARAM(s, x)			\
  g_free ((gpointer)(s)->priv->x);		\
  (s)->priv->x = g_value_dup_string (value)

391 392 393 394 395
  switch (property_id) {
  case PROP_ADDRESS: {
    if (self->priv->nua)
    {
      nua_set_params(self->priv->nua,
396
                     SIPTAG_FROM_STR(self->priv->address),
397 398 399 400 401 402 403 404 405
                     TAG_NULL());
      nua_get_params(self->priv->nua, TAG_ANY(), TAG_NULL());
    }
    else /*setting in constructor*/
    {
      self->priv->address = su_strdup(self->priv->home, g_value_get_string (value));
    }
    break;
  }
406 407 408 409 410 411 412 413
  case PROP_PASSWORD: {
    STORE_PARAM(self, password);
    break;
  }
  case PROP_CONTACT: {
    STORE_PARAM(self, contact);
    break;
  }
414
  case PROP_PROXY: {
415
    STORE_PARAM(self, proxy);
416 417 418 419 420 421 422 423 424
    if (self->priv->nua)
    {
      nua_set_params(self->priv->nua,
                     NUTAG_PROXY(self->priv->proxy),
                     TAG_NULL());
    }
    break;
  }
  case PROP_REGISTRAR: {
425
    STORE_PARAM(self, registrar);
426 427 428 429 430 431 432 433
    if (self->priv->nua)
    {
      nua_set_params(self->priv->nua,
                     NUTAG_REGISTRAR(self->priv->registrar),
                     TAG_NULL());
    }
    break;
  }
434 435
  case PROP_STUN_SERVER: {
    STORE_PARAM(self, stun_server);
436 437
    break;
  }
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
 default:
    /* We don't have any other property... */
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
    break;
  }
}

static void
nua_glib_get_property (GObject      *object,
                        guint         property_id,
                        GValue       *value,
                        GParamSpec   *pspec)
{
  NuaGlib *self = (NuaGlib *) object;

  switch (property_id) {
  case PROP_ADDRESS: {
    g_value_set_string (value, self->priv->address);
    break;
  }
458 459 460 461 462 463 464 465
  case PROP_PASSWORD: {
    g_value_set_string (value, self->priv->password);
    break;
  }
  case PROP_CONTACT: {
    g_value_set_string (value, self->priv->contact);
    break;
  }
466 467 468 469 470 471 472 473
  case PROP_PROXY: {
    g_value_set_string (value, self->priv->proxy);
    break;
  }
  case PROP_REGISTRAR: {
    g_value_set_string (value, self->priv->registrar);
    break;
  }
474 475
  case PROP_STUN_SERVER: {
    g_value_set_string (value, self->priv->stun_server);
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
    break;
  }
  default:
    /* We don't have any other property... */
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object,property_id,pspec);
    break;
  }
}


static void
nua_glib_class_init (NuaGlibClass *nua_glib_class)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS(nua_glib_class);
  GParamSpec *param_spec;
 
  gobject_class->constructor = nua_glib_constructor;
  gobject_class->dispose = nua_glib_dispose;
  gobject_class->finalize = nua_glib_finalize;

  gobject_class->set_property = nua_glib_set_property;
  gobject_class->get_property = nua_glib_get_property;
  
  param_spec = g_param_spec_string("address",
                                   "NuaGlib construction property",
501
                                   "The address-of-record for this UA (e.g. 'sip:first.surname@myprovider.com')",
502 503 504 505 506 507
                                   "no-address-set", /*default value*/
                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
  g_object_class_install_property (gobject_class,
                                   PROP_ADDRESS,
                                   param_spec);

508
  param_spec = g_param_spec_string("password",
509
                                   "NuaGlib construction property",
510
                                   "SIP account password",
511
                                   NULL, /*default value*/
512
                                   G_PARAM_READWRITE);
513
  g_object_class_install_property (gobject_class,
514
                                   PROP_PASSWORD,
515 516
                                   param_spec);

517
  param_spec = g_param_spec_string("contact",
518
                                   "NuaGlib construction property",
519
                                   "local bind interface (e.g. 'sip:0.0.0.0:*') [optional]",
520 521 522
                                   NULL, /*default value*/
                                   G_PARAM_READWRITE );
  g_object_class_install_property (gobject_class,
523
                                   PROP_CONTACT,
524 525
                                   param_spec);

526
  param_spec = g_param_spec_string("proxy",
527
                                   "NuaGlib construction property",
528
                                   "SIP outgoing proxy URI (e.g. 'sip:sipproxy.myprovider.com') [optional]",
529 530 531
                                   NULL, /*default value*/
                                   G_PARAM_READWRITE );
  g_object_class_install_property (gobject_class,
532
                                   PROP_PROXY,
533 534
                                   param_spec);

535 536 537 538 539 540 541 542
  param_spec = g_param_spec_string("registrar",
                                   "NuaGlib construction property",
                                   "SIP registrar URI (e.g. 'sip:sip.myprovider.com') [optional]",
                                   NULL, /*default value*/
                                   G_PARAM_READWRITE );
  g_object_class_install_property (gobject_class,
                                   PROP_REGISTRAR,
                                   param_spec);
543

544
  param_spec = g_param_spec_string("stun-server",
545
                                   "NuaGlib construction property",
546
                                   "STUN server address (FQDN or dotted-decimal) [optional]",
547 548 549
                                   "", /*default value*/
                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
  g_object_class_install_property (gobject_class,
550
                                   PROP_STUN_SERVER,
551 552
                                   param_spec);

553 554 555 556 557 558 559 560 561 562
  /**
   * NuaGlib::call-forked:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the call that was forked
   * @status: SIP status of fork (see SIP RFC)
   * @phrase: Reason for fork
   *
   * Emitted when an outgoing call has been forked.
   * This is when an INVITE request is answered with multiple 200 responses.
   */
563
  signals[NGSIG_CALL_FORKED] =
564
    g_signal_new("call-forked",
565 566 567 568 569 570 571 572 573 574
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);


  /**
   * NuaGlib::incoming-invite:
   * @nua_glib: the object that received the signal
575 576
   * @op: pointer to the operation created to represent this 
   *      call (also contains the sender information)
577 578 579 580 581 582
   * @display: the display name of the invite recipient
   * @url: the url of the invite recipient
   * @subject: the subject of the invite (can be NULL)
   *
   * Emitted when an call invite is received
   * Should be answered with nua_glib_answer or nua_glib_decline
583 584 585
   *
   * XXX: a bit ugly that sender information is carried in 'op', while
   *      recipient display name and URI are as arguments
586
   */
587
  signals[NGSIG_INCOMING_INVITE] =
588 589 590 591 592 593
   g_signal_new("incoming-invite",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_STRING_STRING_STRING,
    G_TYPE_NONE, 4, G_TYPE_POINTER , G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
594
  
595 596 597 598 599 600 601 602
  /**
   * NuaGlib::incoming-reinvite:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   *
   * Emitted when an call invite is received for a call already in progress
   * Usually represents
   */
603
  signals[NGSIG_INCOMING_REINVITE] =
604 605 606 607 608 609 610
   g_signal_new("incoming-reinvite",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    g_cclosure_marshal_VOID__POINTER,
    G_TYPE_NONE, 1, G_TYPE_POINTER);

611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
  /**
   * NuaGlib::incoming-subscribe:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation created to represent this 
   *      dialog (also contains the sender information)
   * @display: the display name of the subscribing recipient
   * @url: the url of the subscribing recipient
   * @event: the event to be subscribed to
   * @content_type: the payload content type of the subscription
   *
   * Emitted when a subscribtion is received
   * Should be answered with nua_glib_subscribe_respond
   *
   * XXX: a bit ugly that sender information is carried in 'op', while
   *      recipient display name and URI are as arguments
   */
  signals[NGSIG_INCOMING_SUBSCRIBE] =
   g_signal_new("incoming-subscribe",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_STRING_STRING_STRING_STRING,
    G_TYPE_NONE, 5, G_TYPE_POINTER , G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
    G_TYPE_STRING);

636 637 638 639 640 641 642 643 644 645 646 647 648 649
  /**
   * NuaGlib::call-state-changed:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @audio: #NuaGlibMediaActive describing audio availiablity
   * @video: #NuaGlibMediaActive describing video availiablity
   * @image: #NuaGlibMediaActive describing image availiablity
   * @chat: #NuaGlibMediaActive describing chat availiablity
   * @l_sdp: String containing any new local caps as SDP, can be NULL
   * @r_sdp: String containing any new remote cap as SDP, can be NULL
   *
   * Emitted when call state changes.
   */
 
650
  signals[NGSIG_CALL_STATE_CHANGED] =
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
   g_signal_new("call-state-changed",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_INT_INT_INT_STRING_STRING,
    G_TYPE_NONE, 7, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT,
                    G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);

  /**
   * NuaGlib::incoming-active:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   *
   * Emitted when a call goes active.
   */
 
667
  signals[NGSIG_INCOMING_ACTIVE] =
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
   g_signal_new("incoming-active",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    g_cclosure_marshal_VOID__POINTER,
    G_TYPE_NONE, 1, G_TYPE_POINTER);

  /**
   * NuaGlib::call-terminated:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing callA
   * @status: SIP status of termination (see SIP RFC)
   *
   * This will be emitted after a call has been terminated.
   * 
   * A call is terminated, when
   * 1) an error response (300..599) is sent to an incoming initial INVITE 
   * 2) a reliable response (200..299 or reliable preliminary response) to an 
   * incoming initial INVITE is not acknowledged with ACK or PRACK 
   * 3) BYE is received or sent
   *
   * Any references you hold to @op should be dropped at this point
   */
 
692
  signals[NGSIG_CALL_TERMINATED] =
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
   g_signal_new("call-terminated",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT,
    G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_INT);

  /**
   * NuaGlib::incoming-prack:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @rack: pointer to RAck that was PRACKed FIXME!!!
   *
   * Emitted when a PRACK is received
   */
 
709
  signals[NGSIG_INCOMING_PRACK] =
710 711 712 713 714 715 716 717 718 719 720 721 722
   g_signal_new("incoming-prack",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_POINTER,
    G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);

  /**
   * NuaGlib::incoming-bye:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   *
   */
723
  signals[NGSIG_INCOMING_BYE] =
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
   g_signal_new("incoming-bye",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    g_cclosure_marshal_VOID__POINTER,
    G_TYPE_NONE, 1, G_TYPE_POINTER);

  /**
   * NuaGlib::incoming-cancel:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of cancel (see SIP RFC)
   * @phrase: Reason for cancel 
   *
   * Emitted when incoming INVITE has been cancelled or no ACK has 
   * been received for an accepted call.
   */
 
742
  signals[NGSIG_INCOMING_CANCEL] =
743 744 745 746 747 748 749 750 751 752
   g_signal_new("incoming-cancel",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    g_cclosure_marshal_VOID__POINTER,
    G_TYPE_NONE, 1, G_TYPE_POINTER);

  /**
   * NuaGlib::incoming-message:
   * @nua_glib: the object that received the signal
753 754
   * @op: pointer to the operation created to represent this 
   *      call (also contains the sender information)
755 756 757 758 759
   * @display: the display name of the invite recipient
   * @url: the url of the invite recipient
   * @subject: the subject of the invite (can be NULL)
   *
   * Emitted when a message is received
760 761 762
   *
   * XXX: a bit ugly that sender information is carried in 'op', while
   *      recipient display name and URI are as arguments
763
   */
764
  signals[NGSIG_INCOMING_MESSAGE] =
765 766 767 768
   g_signal_new("incoming-message",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
769 770
    nua_glib_marshal_VOID__POINTER_STRING_STRING_STRING_STRING,
    G_TYPE_NONE, 5, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
771 772 773 774

  /**
   * NuaGlib::incoming-info:
   * @nua_glib: the object that received the signal
775 776
   * @op: pointer to the operation created to represent this 
   *      call (also contains the sender information)
777 778 779 780 781
   * @display_name: the display name of the info sender
   * @address: the address of the info sender
   * @subject: the subject of the invite (can be NULL)
   *
   * Emitted when an INFO message is received
782 783 784
   *
   * XXX: a bit ugly that sender information is carried in 'op', while
   *      recipient display name and URI are as arguments
785
   */
786
  signals[NGSIG_INCOMING_INFO] =
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
   g_signal_new("incoming-info",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_STRING_STRING_STRING,
    G_TYPE_NONE, 4, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);

  /**
   * NuaGlib::incoming-refer:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation for the call that originated this refer
   * @display: the display name of the REFERER 
   * @address: the address of the REFERER 
   * @refer_address: the address you have been requested to refer to
   * @op2: a pointer to an operation to use to respond to this refer, NULL if 
   *       REFER url was not a SIP uri.
   *
   * Emitted when a REFER message is received
   * You should reply to this with #nua_glib_notify to cancel it or 
   * #nua_glib_follow_refer, and probably close * the call that referred 
   * you to follow it.
   */
809
  signals[NGSIG_INCOMING_REFER] =
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
   g_signal_new("incoming-refer",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_STRING_STRING_STRING_POINTER,
    G_TYPE_NONE, 5, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
                    G_TYPE_POINTER);

  /**
   * NuaGlib::incoming-notify:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation created to represent this call, NULL if 
   *      this was a rogue notify
   * @event: name of event, can be NULL
   * @content-type: content type of event, can be NULL
   * @payload: payload of event
   *
   * Emitted when an NOTIFY message is received
   */
 
830
  signals[NGSIG_INCOMING_NOTIFY] =
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
   g_signal_new("incoming-notify",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_STRING_STRING_STRING,
    G_TYPE_NONE, 4, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);

  /**
   * NuaGlib::error:
   * @nua_glib: the object that received the signal
   * @status: SIP status for error (see SIP RFC)
   * @phrase: Reason for error
   *
   * If you get this, run around waving your hands and screaming.
   */
 
847
  signals[NGSIG_ERROR] =
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
   g_signal_new("error",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__INT_STRING,
    G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::register-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of REGISTER answer (see SIP RFC)
   * @phrase: Reason for REGISTER answer 
   *
   * if status >=300 and not 401 or 407, you should drop any references you hold 
   * on @op
   */
865
  signals[NGSIG_REGISTER_ANSWERED] =
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
   g_signal_new("register-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::unregister-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of REGISTER answer (see SIP RFC)
   * @phrase: Reason for REGISTER answer 
   *
   * if status >=300 and not 401 or 407, you should drop any references you hold 
   * on @op
   */
 
884
  signals[NGSIG_UNREGISTER_ANSWERED] =
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
   g_signal_new("unregister-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::publish-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of PUBLISH answer (see SIP RFC)
   * @phrase: Reason for PUBLISH answer 
   *
   * if status >=300 and not 401 or 407, you should drop any references you hold 
   * on @op
   */
 
903
  signals[NGSIG_PUBLISH_ANSWERED] =
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
   g_signal_new("publish-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::invite-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of INVITE answer (see SIP RFC)
   * @phrase: Reason for INVITE answer 
   *
   */
919
  signals[NGSIG_INVITE_ANSWERED] =
920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
   g_signal_new("invite-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::bye-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of bye answer (see SIP RFC)
   * @phrase: Reason for bye answer 
   *
   */
935
  signals[NGSIG_BYE_ANSWERED] =
936 937 938 939 940 941 942
   g_signal_new("bye-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
  /**
   * NuaGlib::cancel-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of CANCEL answer (see SIP RFC)
   * @phrase: Reason for CANCEL answer 
   *
   */
  signals[NGSIG_CANCEL_ANSWERED] =
   g_signal_new("cancel-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

959 960 961 962 963 964 965 966
  /**
   * NuaGlib::message-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of message answer (see SIP RFC)
   * @phrase: Reason for message answer
   *
   */
967
  signals[NGSIG_MESSAGE_ANSWERED] =
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982
   g_signal_new("message-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::info-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of INFO answer (see SIP RFC)
   * @phrase: Reason for INFO answer
   *
   */
983
  signals[NGSIG_INFO_ANSWERED] =
984 985 986 987 988 989 990 991 992 993 994 995 996 997
   g_signal_new("info-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::refer-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of REFER answer (see SIP RFC)
   * @phrase: Reason for REFER answer 
   *
998 999
   * XXX: should we pass the even header as param (see nua_refer()
   * documentation and SIPTAG_EVENT())
1000
   */
1001
  signals[NGSIG_REFER_ANSWERED] =
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
   g_signal_new("refer-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::subscribe-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of SUBSCRIBE answer (see SIP RFC)
   * @phrase: Reason for SUBSCRIBE answer
   *
   */
1017
  signals[NGSIG_SUBSCRIBE_ANSWERED] =
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
   g_signal_new("subscribe-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::unsubscribe-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of UNSUBSCRIBE answer (see SIP RFC)
   * @phrase: Reason for UNSUBSCRIBE answer
   *
   *You should remove any references you have to @op after receiving this signal
   */
1034
  signals[NGSIG_UNSUBSCRIBE_ANSWERED] =
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
   g_signal_new("unsubscribe-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::notify-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of NOTIFY answer (see SIP RFC)
   * @phrase: Reason for NOTIFY answer 
   *
   */
1050
  signals[NGSIG_NOTIFY_ANSWERED] =
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
   g_signal_new("notify-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::options-answered:
   * @nua_glib: the object that received the signal
   * @op: pointer to the operation representing the existing call
   * @status: SIP status of options answer (see SIP RFC)
   * @phrase: Reason for options answer 
   *
1065
   * XXX: not OPTIONS response payload is not delivered to the application
1066
   */
1067
  signals[NGSIG_OPTIONS_ANSWERED] =
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082
   g_signal_new("options-answered",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_INT_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_INT, G_TYPE_STRING);

  /**
   * NuaGlib::shutdown:
   * @nua_glib: the object that received the signal
   *
   * The sip stack is shutting down, 
   * drop all #NuaGlibOp references you hold
   * and unref the object it was emited on
   */
1083
 signals[NGSIG_SHUTDOWN] =
1084 1085 1086 1087 1088 1089 1090
   g_signal_new("shutdown",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    g_cclosure_marshal_VOID__VOID,
    G_TYPE_NONE, 0, NULL);

1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
  /**
   * NuaGlib::auth_required:
   * @nua_glib: the object that received the signal
   * @op: pointer to the related operation
   * @method: string describing the method (RFC2617: "Basic", "Digest", ..)
   * @realm: realm of the challenge (RFC2617) 
   *
   * The sip stack is shutting down, 
   * drop all #NuaGlibOp references you hold
   * and unref the object it was emited on
   */
 signals[NGSIG_AUTH_REQUIRED] =
   g_signal_new("auth-required",
    G_OBJECT_CLASS_TYPE (nua_glib_class),
    G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
    0, NULL, NULL,
    nua_glib_marshal_VOID__POINTER_STRING_STRING,
    G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
}

/* ====================================================================== */
int sof_init(NuaGlibPrivate *priv, const char *contact)
{
  priv->name = "UA";
  priv->contact = g_strdup(contact);

  su_root_threading(priv->root, 0);

  return 0;
}


static void 
sof_callback(nua_event_t event,
1125 1126 1127 1128
	     int status, char const *phrase,
	     nua_t *nua, NuaGlib *self,
	     nua_handle_t *nh, NuaGlibOp *op, sip_t const *sip,
	     tagi_t tags[])
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
{
  g_return_if_fail(self);

  switch (event) {
  case nua_r_shutdown:    
    sof_r_shutdown(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_r_get_params:    
    sof_r_get_params(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_r_register:
    sof_r_register(status, phrase, nua, self, nh, op, sip, tags);
    return;
    
  case nua_r_unregister:
    sof_r_unregister(status, phrase, nua, self, nh, op, sip, tags);
    return;
    
  case nua_r_options:
    sof_r_options(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_r_invite:
    sof_r_invite(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_i_fork:
    sof_i_fork(status, phrase, nua, self, nh, op, sip, tags);
    return;
    
  case nua_i_invite:
    sof_i_invite(nua, self, nh, op, sip, tags);
    return;

  case nua_i_prack:
    sof_i_prack(nua, self, nh, op, sip, tags);
    return;

  case nua_i_active:
    sof_i_active(nua, self, nh, op, sip, tags);
    return;

  case nua_i_state:
    sof_i_state(status, phrase, nua, self, nh, op, sip, tags);
    return;
    
  case nua_i_terminated:
    sof_i_terminated(status, phrase, nua, self, nh, op, sip, tags);
    return;
    
  case nua_r_bye:
    sof_r_bye(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_i_bye:
    sof_i_bye(nua, self, nh, op, sip, tags);
    return;

1189 1190 1191 1192
  case nua_r_cancel:
    sof_r_cancel(status, phrase, nua, self, nh, op, sip, tags);
    return;

1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216
  case nua_r_message:
    sof_r_message(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_i_message:
    sof_i_message(nua, self, nh, op, sip, tags);
    return;

  case nua_r_info:
    sof_r_info(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_i_info:
    sof_i_info(nua, self, nh, op, sip, tags);
    return;

  case nua_r_refer:
    sof_r_refer(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_i_refer:
    sof_i_refer(nua, self, nh, op, sip, tags);
    return;
     
1217 1218 1219 1220
  case nua_r_notifier:
    sof_r_notifier(event, status, phrase, nua, self, nh, op, sip, tags);
    break;

1221 1222 1223 1224
  case nua_r_subscribe:
    sof_r_subscribe(status, phrase, nua, self, nh, op, sip, tags);
    return;

1225 1226 1227 1228
  case nua_i_subscribe:
    sof_i_subscribe(nua, self, nh, op, sip, tags);
    return;

1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
  case nua_r_unsubscribe:
    sof_r_unsubscribe(status, phrase, nua, self, nh, op, sip, tags);
    return;

  case nua_r_publish:
    sof_r_publish(status, phrase, nua, self, nh, op, sip, tags);
    return;
    
  case nua_r_notify:
    sof_r_notify(status, phrase, nua, self, nh, op, sip, tags);
    return;
     
  case nua_i_notify:
    sof_i_notify(nua, self, nh, op, sip, tags);
    return;

  case nua_i_cancel:
    sof_i_cancel(nua, self, nh, op, sip, tags);
    return;

  case nua_i_error:
    sof_i_error(nua, self, nh, op, status, phrase, tags);
    return;

  default:
    break;
  }

  if (status > 100)
    g_warning("%s: unknown event %d: %03d %s\n", 
           self->priv->name, event, status, phrase);
  else
    g_warning("%s: unknown event %d\n", self->priv->name, event);

  tl_print(stderr, "", tags);
1264 1265 1266 1267 1268 1269

  if (nua_glib_op_find_by_handle(self, nh) == NULL) {
    /* note: unknown handle, not associated to any existing call,
     *       message, registration, etc, so it can be safely destroyed */
    nua_handle_destroy(nh);
  }
1270 1271 1272 1273
}

/* ====================================================================== */

1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
/**
 * Helper function called from all response callback handler.
 * Checks whether authentication is needed, and handles it if 
 * require. Marks succesful authentications as completed.
 */
static void priv_oper_check_response_for_auth(NuaGlib *self, NuaGlibOp *op, int status, sip_t const *sip, tagi_t *tags)
{
  if (status == 401 || status == 407) {
    priv_oper_handle_auth(self, op, sip, tags);
  }
  else if (status >= 200 && status <= 299){
    if (op->op_authstate != opa_none && 
	op->op_authstate != opa_auth_ok) {
      op->op_authstate = opa_auth_ok;
      SU_DEBUG_3(("%s: authorization of %s (%p) was succesful\n", 
1289
		  self->priv->name, sip_method_name(op->op_method, "<NONE>"), op));
1290 1291 1292 1293
    }
  }
}

1294 1295 1296
/**
 * Handles authentication challenge for operation 'op'.
 */
1297
static void priv_oper_handle_auth (NuaGlib *self, NuaGlibOp *op, sip_t const *sip, tagi_t *tags)
1298 1299 1300
{
  sip_www_authenticate_t const *wa = sip->sip_www_authenticate;
  sip_proxy_authenticate_t const *pa = sip->sip_proxy_authenticate;
1301 1302 1303
  sip_from_t const *sipfrom = sip->sip_from;
  const char *realm = NULL;

1304 1305 1306 1307 1308 1309 1310
  enter;

  tl_gets(tags, 
          SIPTAG_WWW_AUTHENTICATE_REF(wa),
          SIPTAG_PROXY_AUTHENTICATE_REF(pa),
          TAG_NULL());

1311
  SU_DEBUG_3(("%s: %s (%p) was unauthorized\n", self->priv->name, sip_method_name(op->op_method, "<NONE>"), op));
1312

1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
  /* step: the initial challenge */
  if (op->op_authstate == opa_none) {
    if (wa) {
      sl_header_print(stdout, "Server auth: %s\n", (sip_header_t *)wa);
      realm = msg_params_find(wa->au_params, "realm=");  
      nua_glib_auth_add(self, op, wa->au_scheme, realm, sipfrom->a_url->url_user, self->priv->password);
    }
    if (pa) {
      sl_header_print(stdout, "Proxy auth: %s\n", (sip_header_t *)pa);
      realm = msg_params_find(pa->au_params, "realm=");  
      nua_glib_auth_add(self, op, pa->au_scheme, realm, sipfrom->a_url->url_user, self->priv->password);
    }

    op->op_authstate = opa_try_derived;
    priv_submit_authlist(op);
1328
  }
1329 1330 1331
  /* step: a new challenge and local credentials updated since last attempt */
  else if (op->op_authstate == opa_retry) {
    priv_submit_authlist(op);
1332
  }
1333 1334 1335
  /* step: a new challenge, ask for matching credentials */
  else if (op->op_authstate == opa_try_derived) {
    g_message("Requesting for additional authentication credentials %s(%s)",
1336
	      self->priv->name, sip_method_name(op->op_method, "<NONE>"));
1337
    op->op_authstate = opa_auth_req;
1338
    g_signal_emit(self, signals[NGSIG_AUTH_REQUIRED], 0, op, sip_method_name(op->op_method, "<NONE>"), realm);
1339 1340 1341
  }
  /* step: a new challenge, ask for matching credentials */
  else if (op->op_authstate == opa_auth_req) {
1342
    g_message("Failed auth for %s by %s",
1343
	      sip_method_name(op->op_method, "<NONE>"), self->priv->name);
1344
    op->op_authstate = opa_failed;
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
  }
}


/**
 * nua_glib_op_owner:
 *
 * get the owning NuaGlib for a given NuaGlibOp
 */
NuaGlib* 
nua_glib_op_owner(NuaGlibOp *op)
{
1357
  g_assert(op);
1358 1359 1360 1361 1362 1363
  return op->op_parent;
}

sip_method_t
nua_glib_op_method_type(NuaGlibOp *op)
{
1364
  g_assert(op);
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
  return op->op_method;
}
/**
 * nua_glib_op_set_data:
 * @op: op to attach data to
 * @data: data to attach
 *
 * Attach an applciation specific blob of data to a NuaGlibOp
 * The application is in charge of deleting the data when it 
 * removes any internal references to the @op. When it has done 
 * so, it should call this function with @data set to NULL
 * Failing to do so will cause an assertion.
 */
void
nua_glib_op_set_data(NuaGlibOp *op, gpointer data)
{
1381
  g_assert(op);