Exemplo n.º 1
0
/** Refresh subscription */
static void nua_subscribe_usage_refresh(nua_handle_t *nh,
					nua_dialog_state_t *ds,
					nua_dialog_usage_t *du,
					sip_time_t now)
{
  nua_client_request_t *cr = du->du_cr;
  struct event_usage *eu = nua_dialog_usage_private(du);

  assert(eu);

  if (eu->eu_final_wait) {
    /* Did not receive NOTIFY for fetch */
    sip_event_t const *o = du->du_event;
    char const *id = o ? o->o_id : NULL;

    SU_DEBUG_3(("nua(%p): event %s%s%s fetch timeouts\n",
		(void *)nh, o ? o->o_type : "(empty)",
		id ? "; id=" : "", id ? id : ""));

    nua_stack_tevent(nh->nh_nua, nh,  NULL,
		     nua_i_notify, 408, "Fetch Timeouts without NOTIFY",
		     NUTAG_SUBSTATE(nua_substate_terminated),
		     SIPTAG_EVENT(du->du_event),
		     TAG_END());
    nua_dialog_usage_remove(nh, ds, du, NULL, NULL);

    return;
  }

  if (cr) {
    if (nua_client_resend_request(cr, 0) >= 0)
      return;
  }
  else if (eu->eu_refer) {
    /*
     * XXX - If we have received a NOTIFY, we should try to terminate
     * subscription
     */
  }

  if (!eu->eu_unsolicited)
    nua_stack_tevent(nh->nh_nua, nh, NULL,
		     nua_i_notify, NUA_ERROR_AT(__FILE__, __LINE__),
		     NUTAG_SUBSTATE(nua_substate_terminated),
		     SIPTAG_EVENT(du->du_event),
		     TAG_END());

  nua_dialog_usage_remove(nh, ds, du, NULL, NULL);
}
Exemplo n.º 2
0
static int nua_notify_client_report(nua_client_request_t *cr,
				    int status, char const *phrase,
				    sip_t const *sip,
				    nta_outgoing_t *orq,
				    tagi_t const *tags)
{
  nua_handle_t *nh = cr->cr_owner;
  nua_dialog_usage_t *du = cr->cr_usage;
  struct notifier_usage *nu = nua_dialog_usage_private(du);
  enum nua_substate substate = nua_substate_terminated;

  if (nu && !cr->cr_terminated)
    substate = nu->nu_substate;

  nua_stack_tevent(nh->nh_nua, nh,
		   nta_outgoing_getresponse(orq),
		   (enum nua_event_e)cr->cr_event,
		   status, phrase,
		   NUTAG_SUBSTATE(substate),
		   SIPTAG_EVENT(du ? du->du_event : NULL),
		   TAG_NEXT(tags));

  if (du && du->du_cr == cr && !cr->cr_terminated) {
    if (nu->nu_requested) {
      /* Re-SUBSCRIBEd while NOTIFY was in progress, resend NOTIFY */
      nua_client_resend_request(cr, 0);
    }
    else if (nu->nu_expires) {
      nua_dialog_usage_set_refresh_at(du, nu->nu_expires);
    }
  }

  return 0;
}
Exemplo n.º 3
0
static void nua_notify_usage_refresh(nua_handle_t *nh,
				     nua_dialog_state_t *ds,
				     nua_dialog_usage_t *du,
				     sip_time_t now)
{
  struct notifier_usage *nu = nua_dialog_usage_private(du);
  nua_client_request_t *cr = du->du_cr;
  nua_event_t e = nua_r_notify;

  if (cr) {
    int terminating = 0;

    if (nu->nu_expires && nu->nu_expires <= now)
      terminating = 1;
    else if (nu->nu_requested && nu->nu_requested <= now)
      terminating = 1;

    if (nua_client_resend_request(cr, terminating) >= 0)
      return;
  }
  else {
    if (nua_client_create(nh, e, &nua_notify_client_methods, NULL) >= 0)
      return;
  }

  nua_stack_tevent(nh->nh_nua, nh, NULL, e, NUA_ERROR_AT(__FILE__, __LINE__),
		   NUTAG_SUBSTATE(nua_substate_terminated),
		   TAG_END());

  nua_dialog_usage_remove(nh, ds, du, NULL, NULL);
}
Exemplo n.º 4
0
static int nua_refer_client_request(nua_client_request_t *cr,
				    msg_t *msg, sip_t *sip,
				    tagi_t const *tags)
{
  nua_handle_t *nh = cr->cr_owner;
  nua_dialog_usage_t *du, *du0 = cr->cr_usage;
  struct event_usage *eu;
  sip_event_t *event;
  int error;

  cr->cr_usage = NULL;

  event = sip_event_format(nh->nh_home, "refer;id=%u", sip->sip_cseq->cs_seq);
  if (!event)
    return -1;

  if (du0 == NULL ||
      du0->du_event == NULL ||
      du0->du_event->o_id == NULL ||
      strcmp(du0->du_event->o_id, event->o_id)) {
    du = nua_dialog_usage_add(nh, nh->nh_ds, nua_subscribe_usage, event);
    if (!du)
      return -1;
  }
  else {
    du = du0, du0 = NULL;
  }

  if (du0)
    nua_dialog_usage_remove(nh, nh->nh_ds, du0, NULL, NULL);

  eu = nua_dialog_usage_private(cr->cr_usage = du);
  eu ->eu_refer = 1;

  error = nua_base_client_request(cr, msg, sip, tags);

  if (!error) {
    /* Give application an Event header for matching NOTIFYs with REFER */
    nua_stack_tevent(nh->nh_nua, nh, NULL,
		     (enum nua_event_e)cr->cr_event, SIP_100_TRYING,
		     NUTAG_REFER_EVENT(event),
		     SIPTAG_EVENT(event),
		     TAG_END());
    su_free(nh->nh_home, event);
  }

  return error;
}
Exemplo n.º 5
0
static void nua_notify_usage_refresh(nua_handle_t *nh,
				     nua_dialog_state_t *ds,
				     nua_dialog_usage_t *du)
{
  struct notifier_usage *nu = nua_dialog_usage_private(du);
  nua_client_request_t *cr = du->du_cr;
  nua_event_t e = nua_r_notify;

  if (cr) {
    int terminating = 0;
    sip_time_t now = sip_now();

    SU_DEBUG_7(("%s(%p, %p, %p): using existing cr=%p\n",
		"nua_notify_usage_refresh",
		(void *)nh, (void *)ds, (void *)du, (void *)cr));

    if (nu->nu_expires && nu->nu_expires <= now)
      terminating = 1;
    else if (nu->nu_requested && nu->nu_requested <= now)
      terminating = 1;

    if (nua_client_resend_request(cr, terminating) >= 0)
      return;
  }
  else {
    SU_DEBUG_7(("%s(%p, %p, %p): new NOTIFY cr for %s\n",
		"nua_notify_usage_refresh",
		(void *)nh, (void *)ds, (void *)du,
		du->du_event ? du->du_event->o_type : "<implicit>"));

    if (nua_client_create(nh, e, &nua_notify_client_methods, NULL) >= 0)
      return;
  }

  nua_stack_tevent(nh->nh_nua, nh, NULL, e, NUA_ERROR_AT(__FILE__, __LINE__),
		   NUTAG_SUBSTATE(nua_substate_terminated),
		   TAG_END());

  nua_dialog_usage_remove(nh, ds, du, NULL, NULL);
}
Exemplo n.º 6
0
void
nua_stack_notifier(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tags)
{
  su_home_t home[1] = { SU_HOME_INIT(home) };
  sip_event_t const *event = NULL;
  sip_content_type_t const *ct = NULL;
  sip_payload_t const *pl = NULL;
  url_string_t const *url = NULL;
  char const *event_s = NULL, *ct_s = NULL, *pl_s = NULL;
  nea_event_t *ev;
  int status = 900;
  char const *phrase = nua_internal_error;

  nua_stack_init_handle(nua, nh, tags);

  tl_gets(tags,
	  NUTAG_URL_REF(url),
	  SIPTAG_EVENT_REF(event),
	  SIPTAG_EVENT_STR_REF(event_s),
	  SIPTAG_CONTENT_TYPE_STR_REF(ct_s),
	  SIPTAG_PAYLOAD_REF(pl),
	  SIPTAG_PAYLOAD_STR_REF(pl_s),
	  TAG_END());

  if (!event && !event_s)
    status = 400, phrase = "Missing Event";

  else if (!ct && !ct_s)
    status = 400, phrase = "Missing Content-Type";

  else if (!nh->nh_notifier &&
	   !(nh->nh_notifier =
	     nea_server_create(nua->nua_nta, nua->nua_root,
			       url->us_url,
			       NH_PGET(nh, max_subscriptions),
			       NULL, nh,
			       TAG_NEXT(tags))))
    status = 900, phrase = nua_internal_error;

  else if (!event && !(event = sip_event_make(home, event_s)))
    status = 900, phrase = "Could not create an event header";

  else if (!(ev = nh_notifier_event(nh, home, event, tags)))
    status = 900, phrase = "Could not create an event view";

  else if (nea_server_update(nh->nh_notifier, ev,  TAG_NEXT(tags)) < 0)
    status = 900, phrase = "No content for event";

  else if (nea_server_notify(nh->nh_notifier, ev) < 0)
    status = 900, phrase = "Error when notifying watchers";

  else
    nua_stack_tevent(nua, nh, NULL, e, status = SIP_200_OK,
		     SIPTAG_EVENT(event),
		     SIPTAG_CONTENT_TYPE(ct),
		     TAG_END());

  if (status != 200)
    nua_stack_event(nua, nh, NULL, e, status, phrase, NULL);

  su_home_deinit(home);
}
Exemplo n.º 7
0
/* Callback from nea_server asking nua to authorize subscription */
static
void authorize_watcher(nea_server_t *nes,
		       nua_handle_t *nh,
		       nea_event_t *ev,
		       nea_subnode_t *sn,
		       sip_t const *sip)
{
  nua_t *nua = nh->nh_nua;
  msg_t *msg = NULL;
  nta_incoming_t *irq = NULL;
  int substate = sn->sn_state;
  int status; char const *phrase;

  SET_STATUS1(SIP_200_OK);

  /* OK. In nhp (nua_handle_preferences_t) structure we have the
     current default action (or state) for incoming
     subscriptions.
     Action can now be modified by the application with NUTAG_SUBSTATE().
  */
  irq = nea_sub_get_request(sn->sn_subscriber);
  msg = nta_incoming_getrequest(irq);

  if (sn->sn_state == nea_embryonic) {
    char const *what;

    substate = NH_PGET(nh, substate);

    if (substate == nua_substate_embryonic)
      substate = nua_substate_pending;

    if (substate == nua_substate_terminated) {
      what = "rejected"; SET_STATUS1(SIP_403_FORBIDDEN);
    }
    else if (substate == nua_substate_pending) {
      what = "pending"; SET_STATUS1(SIP_202_ACCEPTED);
    }
    else {
      what = "active";
    }

    SU_DEBUG_7(("nua(%p): authorize_watcher: %s\n", (void *)nh, what));
    nea_sub_auth(sn->sn_subscriber, (nea_state_t)substate,
		 TAG_IF(substate == nua_substate_pending,
			NEATAG_FAKE(1)),
		 TAG_IF(substate == nua_substate_terminated,
			NEATAG_REASON("rejected")),
		 TAG_END());
  }
  else if (sn->sn_state == nea_terminated || sn->sn_expires == 0) {
    substate = nua_substate_terminated;
    nea_server_flush(nes, NULL);
    SU_DEBUG_7(("nua(%p): authorize_watcher: %s\n",
		(void *)nh, "watcher is removed"));
  }

  nua_stack_tevent(nua, nh, msg, nua_i_subscription, status, phrase,
		   NUTAG_SUBSTATE(substate),
		   NEATAG_SUB(sn->sn_subscriber),
		   TAG_END());
}