コード例 #1
0
END_TEST

START_TEST(client_1_4_2)
{
    nua_handle_t *nh;
    struct message *message;
    struct event *response;

    S2_CASE("1.4.2", "Retry-After a delay",
            "Retry MESSAGE after a delay");

    nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
    nua_message(nh,
                SIPTAG_CONTENT_TYPE_STR("text/plain"),
                SIPTAG_PAYLOAD_STR("hello"),
                TAG_END());
    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    s2_sip_respond_to(message, NULL, SIP_503_SERVICE_UNAVAILABLE,
                      SIPTAG_RETRY_AFTER_STR("3"),
                      TAG_END());
    s2_sip_free_message(message);
    response = s2_wait_for_event(nua_r_message, 100);
    s2_free_event(response);

    s2_nua_fast_forward(32, s2base->root);

    /* Too long delay */
    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    s2_sip_respond_to(message, NULL, SIP_503_SERVICE_UNAVAILABLE,
                      SIPTAG_RETRY_AFTER_STR("32"),
                      TAG_END());
    s2_sip_free_message(message);
    response = s2_wait_for_event(nua_r_message, 503);
    s2_free_event(response);

    nua_set_params(nua, NUTAG_MAX_RETRY_AFTER(0), TAG_END());
    fail_unless_event(nua_r_set_params, 200);

    /* Disable feature */
    nua_message(nh,
                SIPTAG_CONTENT_TYPE_STR("text/plain"),
                SIPTAG_PAYLOAD_STR("hello"),
                TAG_END());
    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    s2_sip_respond_to(message, NULL, SIP_503_SERVICE_UNAVAILABLE,
                      SIPTAG_RETRY_AFTER_STR("3"),
                      TAG_END());
    s2_sip_free_message(message);
    response = s2_wait_for_event(nua_r_message, 503);
    s2_free_event(response);

    nua_handle_destroy(nh);
}
コード例 #2
0
static void
unsubscribe_by_nua(nua_handle_t *nh, tag_type_t tag, tag_value_t value, ...)
{
    struct message *subscribe, *response;
    struct event *event;

    nua_unsubscribe(nh, TAG_END());
    subscribe = s2_sip_wait_for_request(SIP_METHOD_SUBSCRIBE);

    s2_sip_respond_to(subscribe, dialog, SIP_200_OK, SIPTAG_EXPIRES_STR("0"), TAG_END());

    event = s2_wait_for_event(nua_r_unsubscribe, 200);
    fail_if(!event);
    fail_unless(s2_check_substate(event, nua_substate_active));
    s2_free_event(event);

    fail_if(s2_sip_request_to(dialog, SIP_METHOD_NOTIFY, NULL,
                              SIPTAG_EVENT(subscribe->sip->sip_event),
                              SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=timeout"),
                              SIPTAG_CONTENT_TYPE_STR(event_mime_type),
                              SIPTAG_PAYLOAD_STR(event_state),
                              TAG_END()));

    event = s2_wait_for_event(nua_i_notify, 200);
    fail_if(!event);
    fail_unless(s2_check_substate(event, nua_substate_terminated));
    s2_free_event(event);

    response = s2_sip_wait_for_response(200, SIP_METHOD_NOTIFY);
    fail_if(!response);
    s2_sip_free_message(response);
    s2_sip_free_message(subscribe);
}
コード例 #3
0
static struct event *
notify_to_nua(enum nua_substate expect_substate,
              tag_type_t tag, tag_value_t value, ...)
{
    struct event *event;
    struct message *response;
    ta_list ta;
    int status;

    ta_start(ta, tag, value);
    fail_if(s2_sip_request_to(dialog, SIP_METHOD_NOTIFY, NULL,
                              SIPTAG_CONTENT_TYPE_STR(event_mime_type),
                              SIPTAG_PAYLOAD_STR(event_state),
                              ta_tags(ta)));
    ta_end(ta);

    response = s2_sip_wait_for_response(0, SIP_METHOD_NOTIFY);
    fail_if(!response);
    status = response->sip->sip_status->st_status;
    fail_unless(status == 200);
    s2_sip_free_message(response);

    event = s2_wait_for_event(nua_i_notify, 200);
    fail_if(!event);
    fail_unless(s2_check_substate(event, expect_substate));

    return event;
}
コード例 #4
0
END_TEST

START_TEST(subscribe_6_1_2)
{
    nua_handle_t *nh;
    struct message *subscribe, *response;
    struct event *notify, *event;

    S2_CASE("6.1.2", "Basic subscription with refresh",
            "NUA sends SUBSCRIBE, waits for NOTIFY, "
            "sends re-SUBSCRIBE, waits for NOTIFY, "
            "sends un-SUBSCRIBE");

    send_notify_before_response = 1;

    nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
    nua_subscribe(nh, SIPTAG_EVENT_STR(event_type), TAG_END());
    notify = subscription_by_nua(nh, nua_substate_embryonic, TAG_END());
    s2_free_event(notify);

    /* Wait for refresh */
    s2_nua_fast_forward(600, s2base->root);
    subscribe = s2_sip_wait_for_request(SIP_METHOD_SUBSCRIBE);
    s2_sip_respond_to(subscribe, dialog, SIP_200_OK,
                      SIPTAG_EXPIRES_STR("600"),
                      TAG_END());

    event = s2_wait_for_event(nua_r_subscribe, 200);
    fail_if(!event);
    fail_unless(s2_check_substate(event, nua_substate_active));
    s2_free_event(event);

    fail_if(s2_sip_request_to(dialog, SIP_METHOD_NOTIFY, NULL,
                              SIPTAG_EVENT(subscribe->sip->sip_event),
                              SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=600"),
                              SIPTAG_CONTENT_TYPE_STR(event_mime_type),
                              SIPTAG_PAYLOAD_STR(event_state),
                              TAG_END()));
    event = s2_wait_for_event(nua_i_notify, 200);
    fail_if(!event);
    fail_unless(s2_check_substate(event, nua_substate_active));
    s2_free_event(event);
    response = s2_sip_wait_for_response(200, SIP_METHOD_NOTIFY);
    fail_if(!response);
    s2_sip_free_message(response);

    unsubscribe_by_nua(nh, TAG_END());

    nua_handle_destroy(nh);
}
コード例 #5
0
static
int nua_refer_server_report(nua_server_request_t *sr, tagi_t const *tags)
{
  nua_handle_t *nh = sr->sr_owner;
  struct notifier_usage *nu = nua_dialog_usage_private(sr->sr_usage);
  sip_t const *sip = sr->sr_request.sip;
  sip_referred_by_t *by = sip->sip_referred_by, default_by[1];
  sip_event_t const *o = sr->sr_usage->du_event;
  enum nua_substate substate = nua_substate_terminated;
  int initial = sr->sr_initial, retval;

  if (nu) {
    if (!sr->sr_terminating)
      substate = nu->nu_substate;
  }

  if (by == NULL) {
     by = sip_referred_by_init(default_by);

    by->b_display = sip->sip_from->a_display;
    *by->b_url = *sip->sip_from->a_url;
  }

  retval = nua_base_server_treport(sr,
				   NUTAG_SUBSTATE(substate),
				   NUTAG_REFER_EVENT(o),
				   TAG_IF(by, SIPTAG_REFERRED_BY(by)),
				   TAG_END());

  if (retval >= 2 || nu == NULL)
    return retval;

  if (initial)
    nua_stack_post_signal(nh,
			  nua_r_notify,
			  SIPTAG_EVENT(o),
			  SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
			  SIPTAG_PAYLOAD_STR("SIP/2.0 100 Trying\r\n"),
			  TAG_END());

  return retval;
}
コード例 #6
0
ファイル: outbound.c プロジェクト: FreeMCU/freemcu
/** Answer to the connectivity probe OPTIONS */
int outbound_process_request(outbound_t *ob,
			     nta_incoming_t *irq,
			     sip_t const *sip)
{
  /* XXX - We assume that Call-ID is not modified. */
  if (strcmp(sip->sip_call_id->i_id, ob->ob_cookie))
    return 0;

  if (ob->ob_keepalive.validating) {
    SU_DEBUG_5(("outbound(%p): registration check OPTIONS received\n",
		(void *)ob->ob_owner));
    ob->ob_keepalive.validated = 1;
  }

  nta_incoming_treply(irq, SIP_200_OK,
		      SIPTAG_CONTENT_TYPE_STR(outbound_content_type),
		      SIPTAG_PAYLOAD_STR(ob->ob_cookie),
		      TAG_END());
  return 200;
}
コード例 #7
0
static void
respond_with_sdp(struct message *request,
		 struct dialog *dialog,
		 int status, char const *phrase,
		 tag_type_t tag, tag_value_t value, ...)
{
  ta_list ta;

  char const *body;
  isize_t bodylen;

  fail_if(soa_get_local_sdp(soa, NULL, &body, &bodylen) != 1);

  ta_start(ta, tag, value);
  s2_sip_respond_to(request, dialog, status, phrase,
		SIPTAG_CONTENT_TYPE_STR("application/sdp"),
		SIPTAG_PAYLOAD_STR(body),
		SIPTAG_CONTENT_DISPOSITION_STR("session"),
		ta_tags(ta));
  ta_end(ta);
}
コード例 #8
0
END_TEST

START_TEST(message_6_4_3)
{
    nua_handle_t *nh;
    struct message *message;
    struct event *response;
    sip_call_id_t *i;

    S2_CASE("6.4.1", "SIMPLE MESSAGE",
            "Send MESSAGE");

    nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
    nua_message(nh,
                SIPTAG_CONTENT_TYPE_STR("text/plain"),
                SIPTAG_PAYLOAD_STR("hello"),
                TAG_END());
    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    s2_sip_respond_to(message, NULL,
                      SIP_407_PROXY_AUTH_REQUIRED,
                      SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
                      TAG_END());
    i = sip_call_id_dup(NULL, message->sip->sip_call_id);
    fail_unless(i != NULL);
    s2_sip_free_message(message);
    fail_unless_event(nua_r_message, 407);

    nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END());

    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    s2_sip_respond_to(message, NULL, SIP_202_ACCEPTED, TAG_END());
    fail_unless(su_strmatch(i->i_id, message->sip->sip_call_id->i_id));
    s2_sip_free_message(message);
    response = s2_wait_for_event(nua_r_message, 202);
    s2_free_event(response);

    nua_handle_destroy(nh);
}
コード例 #9
0
ファイル: test_sip_events.c プロジェクト: FreeMCU/freemcu
int test_events(struct context *ctx)
{
  BEGIN();

  struct endpoint *a = &ctx->a,  *b = &ctx->b;
  struct call *a_call = a->call, *b_call = b->call;
  struct event *e, *en, *es;
  sip_t const *sip;
  tagi_t const *t, *n_tags, *r_tags;
  url_t b_url[1];
  enum nua_substate substate;
  nea_sub_t *sub = NULL;

  char const open[] =
    "<?xml version='1.0' encoding='UTF-8'?>\n"
    "<presence xmlns='urn:ietf:params:xml:ns:cpim-pidf' \n"
    "   entity='pres:[email protected]'>\n"
    "  <tuple id='ksac9udshce'>\n"
    "    <status><basic>open</basic></status>\n"
    "    <contact priority='1.0'>sip:[email protected]</contact>\n"
    "  </tuple>\n"
    "</presence>\n";

  char const closed[] =
    "<?xml version='1.0' encoding='UTF-8'?>\n"
    "<presence xmlns='urn:ietf:params:xml:ns:cpim-pidf' \n"
    "   entity='pres:[email protected]'>\n"
    "  <tuple id='ksac9udshce'>\n"
    "    <status><basic>closed</basic></status>\n"
    "  </tuple>\n"
    "</presence>\n";


/* SUBSCRIBE test

   A			B
   |------SUBSCRIBE---->|
   |<--------405--------|
   |			|

*/
  if (print_headings)
    printf("TEST NUA-12.1: SUBSCRIBE without notifier\n");

  nua_set_params(b->nua, SIPTAG_ALLOW_EVENTS(NULL), TAG_END());
  run_b_until(ctx, nua_r_set_params, until_final_response);

  TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));

  SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url),
	    SIPTAG_EVENT_STR("presence"),
	    TAG_END());

  run_ab_until(ctx, -1, save_until_final_response,
	       -1, NULL /* XXX save_until_received */);

  /* Client events:
     nua_subscribe(), nua_r_subscribe
  */
  TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_subscribe);
  TEST(e->data->e_status, 489);
  TEST_1(!e->next);

#if 0				/* XXX */
  /*
   Server events:
   nua_i_subscribe
  */
  TEST_1(e = b->events->head);
  TEST_E(e->data->e_event, nua_i_subscribe);
  TEST(e->data->e_status, 405);
  TEST_1(sip = sip_object(e->data->e_msg));
  TEST_1(sip->sip_event);
  TEST_S(sip->sip_event->o_type, "presence");
  TEST_1(!e->next);
#endif

  free_events_in_list(ctx, a->events);
  free_events_in_list(ctx, b->events);
  nua_handle_destroy(b_call->nh), b_call->nh = NULL;

  if (print_headings)
    printf("TEST NUA-12.1: PASSED\n");

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

/* SUBSCRIBE test using notifier and establishing subscription

   A			B
   |                    |
   |------SUBSCRIBE---->|
   |<--------202--------|
   |<------NOTIFY-------|
   |-------200 OK------>|
   |                    |
*/

  if (print_headings)
    printf("TEST NUA-12.2: using notifier and establishing subscription\n");

  TEST_1(b_call->nh = nua_handle(b->nua, b_call, TAG_END()));

  *b_url = *b->contact->m_url;

  NOTIFIER(b, b_call, b_call->nh,
	   NUTAG_URL(b_url),
	   SIPTAG_EVENT_STR("presence"),
	   SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"),
	   SIPTAG_PAYLOAD_STR(closed),
	   NEATAG_THROTTLE(1),
	   TAG_END());
  run_b_until(ctx, nua_r_notifier, until_final_response);

  SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url),
	    SIPTAG_EVENT_STR("presence"),
	    SIPTAG_ACCEPT_STR("application/xpidf, application/pidf+xml"),
	    TAG_END());

  run_ab_until(ctx, -1, save_until_notified_and_responded,
	       -1, save_until_received);

  /* Client events:
     nua_subscribe(), nua_i_notify/nua_r_subscribe
  */
  TEST_1(en = event_by_type(a->events->head, nua_i_notify));
  TEST_1(es = event_by_type(a->events->head, nua_r_subscribe));

  TEST_1(e = es); TEST_E(e->data->e_event, nua_r_subscribe);
  r_tags = e->data->e_tags;
  TEST_1(tl_find(r_tags, nutag_substate));
  if (es->next == en) {
    TEST_1(200 <= e->data->e_status && e->data->e_status < 300);
    TEST(tl_find(r_tags, nutag_substate)->t_value, nua_substate_embryonic);
  }
  else {
    TEST_1(200 <= e->data->e_status && e->data->e_status < 300);
    TEST(tl_find(r_tags, nutag_substate)->t_value, nua_substate_active);
  }

  TEST_1(e = en); TEST_E(e->data->e_event, nua_i_notify);
  TEST_1(sip = sip_object(e->data->e_msg));
  n_tags = e->data->e_tags;

  TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
  TEST_1(sip->sip_content_type);
  TEST_S(sip->sip_content_type->c_type, "application/pidf+xml");
  TEST_1(sip->sip_subscription_state);
  TEST_S(sip->sip_subscription_state->ss_substate, "active");
  TEST_1(sip->sip_subscription_state->ss_expires);
  TEST_1(tl_find(n_tags, nutag_substate));
  TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active);
  TEST_1(!en->next || !es->next);
  free_events_in_list(ctx, a->events);

  /* XXX --- Do not check server side events */
  free_events_in_list(ctx, b->events);

  if (print_headings)
    printf("TEST NUA-12.2: PASSED\n");

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

/* NOTIFY with updated content

   A			B
   |                    |
   |<------NOTIFY-------|
   |-------200 OK------>|
   |                    |
*/
  if (print_headings)
    printf("TEST NUA-12.3: update notifier\n");

  /* Update presence data */

  NOTIFIER(b, b_call, b_call->nh,
	   SIPTAG_EVENT_STR("presence"),
	   SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"),
	   SIPTAG_PAYLOAD_STR(open),
	   TAG_END());

  run_ab_until(ctx, -1, save_until_notified, -1, save_until_received);

  /* subscriber events:
     nua_i_notify
  */
  TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify);
  TEST_1(sip = sip_object(e->data->e_msg));
  TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
  TEST_1(sip->sip_content_type);
  TEST_S(sip->sip_content_type->c_type, "application/pidf+xml");
  TEST_1(sip->sip_subscription_state);
  TEST_S(sip->sip_subscription_state->ss_substate, "active");
  TEST_1(sip->sip_subscription_state->ss_expires);
  n_tags = e->data->e_tags;
  TEST_1(tl_find(n_tags, nutag_substate));
  TEST(tl_find(n_tags, nutag_substate)->t_value,
       nua_substate_active);
  TEST_1(!e->next);
  free_events_in_list(ctx, a->events);

  /* XXX --- Do not check server side events */
  free_events_in_list(ctx, b->events);

  if (print_headings)
    printf("TEST NUA-12.3: PASSED\n");

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

/* un-SUBSCRIBE

   A			B
   |                    |
   |------SUBSCRIBE---->|
   |<--------202--------|
   |<------NOTIFY-------|
   |-------200 OK------>|
   |                    |
*/
  if (print_headings)
    printf("TEST NUA-12.5: un-SUBSCRIBE\n");

  memset(&a->flags, 0, sizeof a->flags);

  UNSUBSCRIBE(a, a_call, a_call->nh, TAG_END());

  run_ab_until(ctx, -1, save_until_notified_and_responded,
	       -1, save_until_subscription);

  /* Client events:
     nua_unsubscribe(), nua_i_notify/nua_r_unsubscribe
  */
  TEST_1(e = a->events->head);
  if (e->data->e_event == nua_i_notify) {
    TEST_E(e->data->e_event, nua_i_notify);
    TEST_1(sip = sip_object(e->data->e_msg));
    n_tags = e->data->e_tags;
    TEST_1(sip->sip_event);
    TEST_1(sip->sip_subscription_state);
    TEST_S(sip->sip_subscription_state->ss_substate, "terminated");
    TEST_1(!sip->sip_subscription_state->ss_expires);
    TEST_1(tl_find(n_tags, nutag_substate));
    TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated);

    TEST_1(e = e->next);
    TEST_E(e->data->e_event, nua_r_unsubscribe);
    TEST_1(tl_find(e->data->e_tags, nutag_substate));
    TEST(tl_find(e->data->e_tags, nutag_substate)->t_value,
       nua_substate_terminated);
  }
  else {
    TEST_E(e->data->e_event, nua_r_unsubscribe);
    TEST_1(tl_find(e->data->e_tags, nutag_substate));
    /* NOTIFY is no more dropped after successful response to unsubscribe */
    TEST(tl_find(e->data->e_tags, nutag_substate)->t_value,
       nua_substate_active);

    TEST_1(e = e->next);
    TEST_E(e->data->e_event, nua_i_notify);
    TEST_1(sip = sip_object(e->data->e_msg));
    n_tags = e->data->e_tags;
    TEST_1(sip->sip_event);
    TEST_1(sip->sip_subscription_state);
    TEST_S(sip->sip_subscription_state->ss_substate, "terminated");
    TEST_1(!sip->sip_subscription_state->ss_expires);
    TEST_1(tl_find(n_tags, nutag_substate));
    TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated);
  }
  TEST_1(!e->next);
  free_events_in_list(ctx, a->events);

  /* Server events: nua_i_subscription with terminated status */
  TEST_1(e = b->events->head);
  TEST_E(e->data->e_event, nua_i_subscription);
  TEST(tl_gets(e->data->e_tags,
               NEATAG_SUB_REF(sub),
               NUTAG_SUBSTATE_REF(substate),
               TAG_END()), 2);
  TEST_1(sub);
  TEST(substate, nua_substate_terminated);
  TEST_1(!e->next);

  free_events_in_list(ctx, b->events);

  if (print_headings)
    printf("TEST NUA-12.5: PASSED\n");

  /* ---------------------------------------------------------------------- */
/* Fetch event, SUBSCRIBE with expires: 0

   A			B
   |                    |
   |------SUBSCRIBE---->|
   |<--------202--------|
   |<------NOTIFY-------|
   |-------200 OK------>|
   |                    |
*/
  if (print_headings)
    printf("TEST NUA-12.5.1: event fetch\n");

  SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url),
	    SIPTAG_EVENT_STR("presence"),
	    SIPTAG_ACCEPT_STR("application/pidf+xml"),
	    SIPTAG_EXPIRES_STR("0"),
	    TAG_END());

  run_ab_until(ctx, -1, save_until_notified_and_responded,
	       -1, save_until_subscription);

  /* Client events:
     nua_subscribe(), nua_i_notify/nua_r_subscribe
  */
  TEST_1(en = event_by_type(a->events->head, nua_i_notify));
  TEST_1(es = event_by_type(a->events->head, nua_r_subscribe));

  e = es; TEST_E(e->data->e_event, nua_r_subscribe);
  TEST_1(t = tl_find(e->data->e_tags, nutag_substate));
  TEST_1(t->t_value == nua_substate_pending ||
	 t->t_value == nua_substate_terminated ||
	 t->t_value == nua_substate_embryonic);

  e = en; TEST_E(e->data->e_event, nua_i_notify);
  TEST_1(sip = sip_object(e->data->e_msg));
  n_tags = e->data->e_tags;

  TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
  TEST_1(sip->sip_content_type);
  TEST_S(sip->sip_content_type->c_type, "application/pidf+xml");
  TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
  TEST_1(sip->sip_subscription_state);
  TEST_S(sip->sip_subscription_state->ss_substate, "terminated");
  TEST_1(tl_find(n_tags, nutag_substate));
  TEST(tl_find(n_tags, nutag_substate)->t_value,
       nua_substate_terminated);
  TEST_1(!en->next || !es->next);
  free_events_in_list(ctx, a->events);

  /*
   Server events:
   nua_i_subscription
  */
  TEST_1(e = b->events->head);
  TEST_E(e->data->e_event, nua_i_subscription);
  TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), TAG_END()), 1);
  TEST_1(sub);
  TEST_1(!e->next);

  free_events_in_list(ctx, b->events);

  if (print_headings)
    printf("TEST NUA-12.4.1: PASSED\n");


  /* ---------------------------------------------------------------------- */
/* 2nd SUBSCRIBE with event id

   A			B
   |                    |
   |------SUBSCRIBE---->|
   |<--------202--------|
   |<------NOTIFY-------|
   |-------200 OK------>|
   |                    |
*/
  /* XXX - we should do this before unsubscribing first one */
  if (print_headings)
    printf("TEST NUA-12.4.2: establishing 2nd subscription\n");

   NOTIFIER(b, b_call, b_call->nh,
	    SIPTAG_EVENT_STR("presence"),
	    SIPTAG_CONTENT_TYPE_STR("application/xpidf+xml"),
	    SIPTAG_PAYLOAD_STR(open),
	    NEATAG_THROTTLE(1),
	    NUTAG_SUBSTATE(nua_substate_pending),
	    TAG_END());
  run_b_until(ctx, nua_r_notifier, until_final_response);

  NOTIFIER(b, b_call, b_call->nh,
	   SIPTAG_EVENT_STR("presence"),
	   SIPTAG_CONTENT_TYPE_STR("application/xpidf+xml"),
	   SIPTAG_PAYLOAD_STR(closed),
	   NEATAG_THROTTLE(1),
	   NEATAG_FAKE(1),
	   NUTAG_SUBSTATE(nua_substate_pending),
	   TAG_END());
  run_b_until(ctx, nua_r_notifier, until_final_response);

  SUBSCRIBE(a, a_call, a_call->nh, NUTAG_URL(b->contact->m_url),
	    SIPTAG_EVENT_STR("presence;id=1"),
	    SIPTAG_ACCEPT_STR("application/xpidf+xml"),
	    TAG_END());

  run_ab_until(ctx, -1, save_until_notified_and_responded,
	       -1, save_until_subscription);

  /* Client events:
     nua_subscribe(), nua_i_notify/nua_r_subscribe
  */
  TEST_1(en = event_by_type(a->events->head, nua_i_notify));
  TEST_1(es = event_by_type(a->events->head, nua_r_subscribe));

  e = es; TEST_E(e->data->e_event, nua_r_subscribe);
  TEST_1(t = tl_find(e->data->e_tags, nutag_substate));
  TEST_1(t->t_value == nua_substate_pending ||
	 t->t_value == nua_substate_embryonic);

  e = en; TEST_E(e->data->e_event, nua_i_notify);
  TEST_1(sip = sip_object(e->data->e_msg));
  n_tags = e->data->e_tags;

  TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
  TEST_S(sip->sip_event->o_id, "1");
  TEST_1(sip->sip_content_type);
  TEST_S(sip->sip_content_type->c_type, "application/xpidf+xml");
  TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
  /* Check that we really got "fake" content */
  TEST_1(memmem(sip->sip_payload->pl_data, sip->sip_payload->pl_len,
		"<basic>closed</basic>", strlen("<basic>closed</basic>")));
  TEST_1(sip->sip_subscription_state);
  TEST_S(sip->sip_subscription_state->ss_substate, "pending");
  TEST_1(sip->sip_subscription_state->ss_expires);
  TEST_1(tl_find(n_tags, nutag_substate));
  TEST(tl_find(n_tags, nutag_substate)->t_value,
       nua_substate_pending);
  TEST_1(!en->next || !es->next);
  free_events_in_list(ctx, a->events);

  /*
   Server events:
   nua_i_subscription
  */
  TEST_1(e = b->events->head);
  TEST_E(e->data->e_event, nua_i_subscription);
  TEST(tl_gets(e->data->e_tags, NEATAG_SUB_REF(sub), TAG_END()), 1);
  TEST_1(sub);
  TEST_1(!e->next);

  free_events_in_list(ctx, b->events);

  /* Authorize user A */
  AUTHORIZE(b, b_call, b_call->nh,
	    NUTAG_SUBSTATE(nua_substate_active),
	    NEATAG_SUB(sub),
	    NEATAG_FAKE(0),
	    TAG_END());

  run_ab_until(ctx, -1, save_until_notified,
	       -1, save_until_final_response);

  /* subscriber events:
     nua_i_notify with NUTAG_SUBSTATE(nua_substate_active)
  */
  TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify);
  TEST_1(sip = sip_object(e->data->e_msg));
  TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
  TEST_1(sip->sip_content_type);
  TEST_S(sip->sip_content_type->c_type, "application/xpidf+xml");
  TEST_1(sip->sip_payload && sip->sip_payload->pl_data);
  /* Check that we really got real content */
  TEST_1(memmem(sip->sip_payload->pl_data, sip->sip_payload->pl_len,
		"<basic>open</basic>", strlen("<basic>open</basic>")));
  TEST_1(sip->sip_subscription_state);
  TEST_S(sip->sip_subscription_state->ss_substate, "active");
  TEST_1(sip->sip_subscription_state->ss_expires);
  n_tags = e->data->e_tags;
  TEST_1(tl_find(n_tags, nutag_substate));
  TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_active);
  TEST_1(!e->next);
  free_events_in_list(ctx, a->events);

  /*
   Server events:
   nua_r_authorize
  */
  TEST_1(e = b->events->head);
  TEST_E(e->data->e_event, nua_r_authorize);
  TEST_1(!e->next);

  free_events_in_list(ctx, b->events);

  if (print_headings)
    printf("TEST NUA-12.4: PASSED\n");

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

/* NOTIFY terminating subscription

   A			B
   |                    |
   |<------NOTIFY-------|
   |-------200 OK------>|
   |                    |
*/

  if (print_headings)
    printf("TEST NUA-12.6: terminate notifier\n");

  TERMINATE(b, b_call, b_call->nh, TAG_END());

  run_ab_until(ctx, -1, save_until_notified, -1, until_final_response);

  /* Client events:
     nua_i_notify
  */
  TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_i_notify);
  TEST_1(sip = sip_object(e->data->e_msg));
  TEST_1(sip->sip_event); TEST_S(sip->sip_event->o_type, "presence");
  TEST_S(sip->sip_event->o_id, "1");
  TEST_1(sip->sip_subscription_state);
  TEST_S(sip->sip_subscription_state->ss_substate, "terminated");
  TEST_1(!sip->sip_subscription_state->ss_expires);
  n_tags = e->data->e_tags;
  TEST_1(tl_find(n_tags, nutag_substate));
  TEST(tl_find(n_tags, nutag_substate)->t_value, nua_substate_terminated);
  TEST_1(!e->next);
  free_events_in_list(ctx, a->events);

  if (print_headings)
    printf("TEST NUA-12.6: PASSED\n");

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


  nua_handle_destroy(a_call->nh), a_call->nh = NULL;
  nua_handle_destroy(b_call->nh), b_call->nh = NULL;

  END();			/* test_events */
}
コード例 #10
0
END_TEST

START_TEST(message_6_4_2)
{
    nua_handle_t *nh;
    struct message *message;
    struct event *response;

    S2_CASE("6.4.2", "MESSAGE with 302/305",
            "Send MESSAGE");

    nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());

    nua_message(nh,
                SIPTAG_CONTENT_TYPE_STR("text/plain"),
                SIPTAG_PAYLOAD_STR("hello"),
                TAG_END());
    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    s2_sip_respond_to(message, NULL, SIP_302_MOVED_TEMPORARILY,
                      SIPTAG_CONTACT_STR("<sip:[email protected]>"),
                      TAG_END());
    s2_sip_free_message(message);

    response = s2_wait_for_event(nua_r_message, 100);
    s2_free_event(response);

    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    fail_unless(message->sip->sip_request->rq_url->url_user != NULL);
    fail_if(strcmp(message->sip->sip_request->rq_url->url_user, "302ed"));
    s2_sip_respond_to(message, NULL, SIP_305_USE_PROXY,
                      SIPTAG_CONTACT_STR("<sip:[email protected];lr>"),
                      TAG_END());
    s2_sip_free_message(message);

    response = s2_wait_for_event(nua_r_message, 100);
    s2_free_event(response);

    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    fail_unless(message->sip->sip_route != NULL);
    fail_unless(message->sip->sip_route->r_url->url_user != NULL);
    fail_if(strcmp(message->sip->sip_route->r_url->url_user, "routed"));
    s2_sip_respond_to(message, NULL, SIP_200_OK, TAG_END());
    s2_sip_free_message(message);

    response = s2_wait_for_event(nua_r_message, 200);
    s2_free_event(response);

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

    nua_message(nh,
                NUTAG_AUTO302(0),
                SIPTAG_CONTENT_TYPE_STR("text/plain"),
                SIPTAG_PAYLOAD_STR("hello 2"),
                TAG_END());

    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    s2_sip_respond_to(message, NULL, SIP_302_MOVED_TEMPORARILY,
                      SIPTAG_CONTACT_STR("<sip:[email protected]>"),
                      TAG_END());
    s2_sip_free_message(message);

    response = s2_wait_for_event(nua_r_message, 302);

    fail_unless(response->sip && response->sip->sip_contact);
    nua_message(nh,
                NUTAG_URL(response->sip->sip_contact->m_url),
                NUTAG_AUTO305(0),
                SIPTAG_CONTENT_TYPE_STR("text/plain"),
                SIPTAG_PAYLOAD_STR("hello 2"),
                TAG_END());

    s2_free_event(response);

    message = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    fail_unless(message->sip->sip_request->rq_url->url_user != NULL);
    fail_if(strcmp(message->sip->sip_request->rq_url->url_user, "not302ed"));
    s2_sip_respond_to(message, NULL, SIP_305_USE_PROXY,
                      SIPTAG_CONTACT_STR("<sip:[email protected]>"),
                      TAG_END());
    s2_sip_free_message(message);

    response = s2_wait_for_event(nua_r_message, 305);
    s2_free_event(response);

    nua_handle_destroy(nh);
}