END_TEST


START_TEST(register_1_3_2_2)
{
  nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
  struct message *m;

  S2_CASE("1.3.2.2", "Register behind NAT with TCP",
	  "Detect NAT over TCP using rport. "
	  "Authenticate, detect NAT, "
	  "close TCP at server, wait for re-REGISTERs.");

  nua_set_params(nua, NTATAG_TCP_RPORT(1), TAG_END());
  fail_unless_event(nua_r_set_params, 200);

  mark_point();
  s2->registration->nh = nh;
  make_auth_natted_register(
    nh, NUTAG_PROXY(s2sip->tcp.contact->m_url),
    NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
    TAG_END());
  fail_if(!tport_is_tcp(s2->registration->tport));
  tport_shutdown(s2->registration->tport, 2);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  /* The "NAT binding" changed when new TCP connection is established */
  /* => NUA re-REGISTERs with newly detected contact */
  fail_unless_event(nua_r_register, 100);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_r_register, 200);

  fail_unless(s2->registration->contact != NULL);
  fail_if(s2->registration->contact->m_next != NULL);

  s2_register_teardown();
}
Example #2
0
END_TEST


START_TEST(register_1_1_2)
{
    nua_handle_t *nh;
    struct message *m;

    S2_CASE("1.1.2", "Register with dual authentication",
            "Register, authenticate");

    nh = nua_handle(nua, NULL, TAG_END());

    nua_register(nh, TAG_END());

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    s2_sip_respond_to(m, NULL,
                      SIP_407_PROXY_AUTH_REQUIRED,
                      SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
                      TAG_END());
    s2_sip_free_message(m);
    fail_unless_event(nua_r_register, 407);

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

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    s2_sip_respond_to(m, NULL,
                      SIP_401_UNAUTHORIZED,
                      SIPTAG_WWW_AUTHENTICATE_STR(s2_auth2_digest_str),
                      SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
                      TAG_END());
    s2_sip_free_message(m);
    fail_unless_event(nua_r_register, 401);

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

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_authorization);
    fail_if(!m->sip->sip_proxy_authorization);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      TAG_END());
    s2_sip_free_message(m);

    assert(s2->registration->contact != NULL);
    fail_unless_event(nua_r_register, 200);

    s2->registration->nh = nh;

    s2_register_teardown();

}
Example #3
0
END_TEST

START_TEST(notify_6_3_5)
{
    nua_handle_t *nh;
    struct message *notify;
    struct event *response;
    sip_t *sip;

    S2_CASE("6.3.4", "NOTIFY server - terminate with error response to NOTIFY",
            "NUA receives SUBSCRIBE, sends 202 and NOTIFY. "
            "The subscription terminates when watcher "
            "returns 481 to NOTIFY.");

    nh = subscribe_to_nua("presence", SIPTAG_EXPIRES_STR("300"), TAG_END());

    nua_notify(nh,
               SIPTAG_SUBSCRIPTION_STATE_STR("active"),
               SIPTAG_PAYLOAD_STR(presence_closed),
               TAG_END());
    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());
    fail_unless_event(nua_r_notify, 200);

    nua_notify(nh,
               SIPTAG_SUBSCRIPTION_STATE_STR("active"),
               SIPTAG_PAYLOAD_STR(presence_open),
               TAG_END());
    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));

    nua_notify(nh,
               NUTAG_NEWSUB(1),
               SIPTAG_SUBSCRIPTION_STATE_STR("active"),
               SIPTAG_PAYLOAD_STR(presence_open),
               TAG_END());

    s2_sip_respond_to(notify, dialog, SIP_481_NO_TRANSACTION, TAG_END());
    response = s2_wait_for_event(nua_r_notify, 481);
    fail_unless(s2_event_substate(response) == nua_substate_terminated);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    s2_sip_respond_to(notify, dialog, SIP_481_NO_TRANSACTION, TAG_END());
    response = s2_wait_for_event(nua_r_notify, 481);
    fail_unless(s2_event_substate(response) == nua_substate_terminated);

    nua_handle_destroy(nh);
}
Example #4
0
END_TEST


START_TEST(register_1_2_2_3)
{
    nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
    struct message *m;

    S2_CASE("1.2.2.3", "Register behind NAT",
            "Authenticate, outbound activated, "
            "detect NAT binding change when re-REGISTERing");

    mark_point();

    make_auth_natted_register(nh,
                              NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
                              TAG_END());
    s2->registration->nh = nh;

    s2_nua_fast_forward(3600, s2base->root);
    mark_point();

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_authorization);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      SIPTAG_VIA(natted_via(m, receive_natted2)),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless_event(nua_r_register, 100);

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_authorization);
    fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      SIPTAG_VIA(natted_via(m, receive_natted2)),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless(s2->registration->contact != NULL);
    fail_if(s2->registration->contact->m_next != NULL);

    fail_unless_event(nua_r_register, 200);

    s2_register_teardown();

}
Example #5
0
END_TEST


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

START_TEST(register_1_3_1)
{
    nua_handle_t *nh;
    struct message *m;

    S2_CASE("1.3.1", "Register over TCP via NAT",
            "REGISTER via TCP, detect NTA, re-REGISTER");

    nh = nua_handle(nua, NULL, TAG_END());

    nua_register(nh, NUTAG_PROXY(s2sip->tcp.contact->m_url), TAG_END());

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_contact || m->sip->sip_contact->m_next);
    fail_if(!tport_is_tcp(m->tport));
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      SIPTAG_VIA(natted_via(m, receive_natted)),
                      TAG_END());
    s2_sip_free_message(m);

    assert(s2->registration->contact != NULL);
    fail_unless_event(nua_r_register, 100);

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      SIPTAG_VIA(natted_via(m, receive_natted)),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless(s2->registration->contact != NULL);
    fail_if(s2->registration->contact->m_next != NULL);
    fail_unless(
        url_has_param(s2->registration->contact->m_url, "transport=tcp"));
    fail_unless_event(nua_r_register, 200);

    s2->registration->nh = nh;

    s2_register_teardown();

}
Example #6
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);
}
Example #7
0
END_TEST


static nua_handle_t *make_auth_natted_register(
    nua_handle_t *nh,
    tag_type_t tag, tag_value_t value, ...)
{
    struct message *m;

    ta_list ta;
    ta_start(ta, tag, value);
    nua_register(nh, ta_tags(ta));
    ta_end(ta);

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    s2_sip_respond_to(m, NULL,
                      SIP_401_UNAUTHORIZED,
                      SIPTAG_WWW_AUTHENTICATE_STR(s2_auth_digest_str),
                      SIPTAG_VIA(natted_via(m, receive_natted)),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless_event(nua_r_register, 401);

    /* NAT detected event */
    fail_unless_event(nua_i_outbound, 101);

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

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_authorization);
    /* should not unregister the previous contact
     * as it has not been successfully registered */
    fail_if(!m->sip->sip_contact);
    fail_if(m->sip->sip_contact->m_next);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      SIPTAG_VIA(natted_via(m, receive_natted)),
                      TAG_END());
    s2_sip_free_message(m);

    assert(s2->registration->contact != NULL);
    fail_unless_event(nua_r_register, 200);

    return nh;
}
Example #8
0
END_TEST

START_TEST(fetch_6_2_3)
{
    nua_handle_t *nh;
    struct message *subscribe;
    struct event *event;

    S2_CASE("6.2.3", "Event fetch - no NOTIFY",
            "NUA sends SUBSCRIBE with Expires 0, waits for NOTIFY, times out");

    nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END());
    nua_subscribe(nh, SIPTAG_EVENT_STR(event_type), SIPTAG_EXPIRES_STR("0"), TAG_END());
    subscribe = s2_sip_wait_for_request(SIP_METHOD_SUBSCRIBE);
    s2_sip_respond_to(subscribe, dialog, SIP_202_ACCEPTED,
                      SIPTAG_EXPIRES_STR("0"), TAG_END());
    s2_sip_free_message(subscribe);

    event = s2_wait_for_event(nua_r_subscribe, 202);
    fail_if(!event);
    fail_unless(s2_check_substate(event, nua_substate_embryonic));
    s2_free_event(event);

    s2_nua_fast_forward(600, s2base->root);

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

    nua_handle_destroy(nh);
}
Example #9
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);
}
Example #10
0
/** Register NUA user.
 *
 * <pre>
 *  A                  B
 *  |-----REGISTER---->|
 *  |<-----200 OK------|
 *  |                  |
 * </pre>
 */
void s2_register_setup(void)
{
  nua_handle_t *nh;
  struct message *m;

  assert(s2 && s2->nua);
  assert(!s2->registration->nh);

  nh = nua_handle(s2->nua, NULL, TAG_END());

  nua_register(nh, TAG_END());

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  assert(m);

  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		TAG_END());
  s2_sip_free_message(m);

  assert(s2->registration->contact != NULL);
  fail_unless_event(nua_r_register, 200);

  s2->registration->nh = nh;
}
END_TEST

START_TEST(client_2_0_1)
{
    nta_outgoing_t *orq;
    struct message *request;
    struct event *response;

    S2_CASE("client-2.0.1", "Send MESSAGE",
            "Basic non-INVITE transaction with "
            "numeric per-transaction outbound proxy");

    orq = nta_outgoing_tcreate(s2->default_leg,
                               s2_nta_orq_callback, NULL,
                               (url_string_t *)s2sip->contact->m_url,
                               SIP_METHOD_MESSAGE,
                               URL_STRING_MAKE("sip:test2.0.example.org"),
                               SIPTAG_FROM_STR("<sip:[email protected]>"),
                               TAG_END());
    fail_unless(orq != NULL);
    request = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    fail_unless(request != NULL);
    s2_sip_respond_to(request, NULL, 200, "OK 2.0.1", TAG_END());
    response = s2_nta_wait_for(wait_for_orq, orq,
                               wait_for_status, 200,
                               0);
    s2_sip_free_message(request);
    s2_nta_free_event(response);
    nta_outgoing_destroy(orq);
}
} END_TEST


START_TEST(register_1_2_3) {
  nua_handle_t *nh;
  struct message *m;

  S2_CASE("1.2.3", "Register behind NAT",
	  "Outbound activated by error response");

  nh = nua_handle(nua, NULL, TAG_END());
  nua_register(nh, TAG_END());

  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m);
  fail_if(!m->sip->sip_contact || m->sip->sip_contact->m_next);

  s2_sip_respond_to(m, NULL,
		400, "Bad Contact",
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_r_register, 100);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless(s2->registration->contact != NULL);
  fail_if(s2->registration->contact->m_next != NULL);
  fail_unless_event(nua_r_register, 200);

  s2->registration->nh = nh;

  s2_register_teardown();

} END_TEST
Example #13
0
static struct event *
subscription_by_nua(nua_handle_t *nh,
                    enum nua_substate current,
                    tag_type_t tag, tag_value_t value, ...)
{
    struct message *subscribe;
    struct event *notify, *event;
    ta_list ta;
    enum nua_substate substate = nua_substate_active;
    char const *substate_str = subscription_state;
    char const *expires = "600";

    subscribe = s2_sip_wait_for_request(SIP_METHOD_SUBSCRIBE);
    if (event_type)
        fail_if(!subscribe->sip->sip_event ||
                strcmp(event_type, subscribe->sip->sip_event->o_type));

    if (subscribe->sip->sip_expires && subscribe->sip->sip_expires->ex_delta == 0) {
        substate = nua_substate_terminated;
        substate_str = "terminated;reason=timeout";
        expires = "0";
    }

    ta_start(ta, tag, value);

    if (send_notify_before_response) {
        s2_sip_save_uas_dialog(dialog, subscribe->sip);
        notify = notify_to_nua(substate,
                               SIPTAG_EVENT(subscribe->sip->sip_event),
                               SIPTAG_SUBSCRIPTION_STATE_STR(substate_str),
                               ta_tags(ta));
        event = respond_to_subscribe(subscribe, nua_r_subscribe, substate,
                                     SIP_200_OK,
                                     SIPTAG_EXPIRES_STR(expires),
                                     TAG_END());
        s2_free_event(event);
    }
    else {
        event = respond_to_subscribe(subscribe, nua_r_subscribe, current,
                                     SIP_202_ACCEPTED,
                                     SIPTAG_EXPIRES_STR(expires),
                                     TAG_END());
        s2_free_event(event);
        notify = notify_to_nua(substate,
                               SIPTAG_EVENT(subscribe->sip->sip_event),
                               SIPTAG_SUBSCRIPTION_STATE_STR(substate_str),
                               ta_tags(ta));
    }

    s2_sip_free_message(subscribe);

    return notify;
}
Example #14
0
END_TEST

START_TEST(notify_6_3_2)
{
    nua_handle_t *nh;
    struct message *notify;
    sip_t *sip;

    S2_CASE("6.3.2", "NOTIFY server - automatic subscription termination",
            "NUA receives SUBSCRIBE, sends 202 and NOTIFY. "
            "The subscription terminates with timeout. ");

    nh = subscribe_to_nua("presence", SIPTAG_EXPIRES_STR("300"), TAG_END());

    nua_notify(nh,
               NUTAG_SUBSTATE(nua_substate_active),
               SIPTAG_PAYLOAD_STR(presence_closed),
               TAG_END());
    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());
    fail_unless_event(nua_r_notify, 200);

    s2_nua_fast_forward(300, s2base->root);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "terminated"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());
    fail_unless_event(nua_r_notify, 200);

    nua_handle_destroy(nh);
}
Example #15
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);
}
Example #16
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);
}
Example #17
0
static struct message *
invite_sent_by_nua(nua_handle_t *nh,
                   tag_type_t tag, tag_value_t value, ...)
{
  ta_list ta;
  ta_start(ta, tag, value);
  nua_invite(nh, SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
             ta_tags(ta));
  ta_end(ta);

  fail_unless(s2_check_callstate(nua_callstate_calling));

  return s2_sip_wait_for_request(SIP_METHOD_INVITE);
}
Example #18
0
static void
bye_by_nua(struct dialog *dialog, nua_handle_t *nh,
	   tag_type_t tag, tag_value_t value, ...)
{
  ta_list ta;
  struct message *bye;

  ta_start(ta, tag, value);
  nua_bye(nh, ta_tags(ta));
  ta_end(ta);

  bye = s2_sip_wait_for_request(SIP_METHOD_BYE);
  fail_if(!bye);
  s2_sip_respond_to(bye, dialog, SIP_200_OK, TAG_END());
  s2_sip_free_message(bye);
  fail_unless_event(nua_r_bye, 200);
  fail_unless(s2_check_callstate(nua_callstate_terminated));
}
END_TEST

START_TEST(client_2_0_2)
{
    nta_outgoing_t *orq;
    struct message *request;
    struct event *response;

    char payload[2048];

    S2_CASE("client-2.0.2", "Send MESSAGE",
            "Basic non-INVITE transaction exceeding "
            "default path MTU (1300 bytes)");

    memset(payload, 'x', sizeof payload);
    payload[(sizeof payload) - 1] = '\0';

    orq = nta_outgoing_tcreate(s2->default_leg,
                               s2_nta_orq_callback, NULL, NULL,
                               SIP_METHOD_MESSAGE,
                               URL_STRING_MAKE("sip:test2.0.example.org"),
                               SIPTAG_FROM_STR("<sip:[email protected]>"),
                               SIPTAG_PAYLOAD_STR(payload),
                               TAG_END());
    fail_unless(orq != NULL);
    request = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    fail_unless(request != NULL);
    fail_unless(request->sip->sip_via->v_protocol == sip_transport_tcp);

    s2_sip_respond_to(request, NULL, 200, "OK 2.0.2", TAG_END());
    response = s2_nta_wait_for(wait_for_orq, orq,
                               wait_for_status, 200,
                               0);
    s2_nta_free_event(response);
    nta_outgoing_destroy(orq);
}
Example #20
0
/** Un-register NUA user.
 *
 * <pre>
 *  A                  B
 *  |-----REGISTER---->|
 *  |<-----200 OK------|
 *  |                  |
 * </pre>
 */
void s2_register_teardown(void)
{
  if (s2 && s2->registration->nh) {
    nua_handle_t *nh = s2->registration->nh;
    struct message *m;

    nua_unregister(nh, TAG_END());

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); assert(m);
    s2_save_register(m);
    s2_sip_respond_to(m, NULL,
		  SIP_200_OK,
		  SIPTAG_CONTACT(s2->registration->contact),
		  TAG_END());
    assert(s2->registration->contact == NULL);

    s2_sip_free_message(m);

    fail_unless_event(nua_r_unregister, 200);

    nua_handle_destroy(nh);
    s2->registration->nh = NULL;
  }
}
END_TEST

START_TEST(client_2_3_2)
{
    nta_outgoing_t *orq, *tagged, *prack;
    struct message *request, *r_prack, *r_ack;
    sip_t *sip;
    struct event *response;

    S2_CASE("client-2.3.2", "INVITE with 100rel",
            "Forked INVITE transaction with 100rel");

    orq = nta_outgoing_tcreate(leg, s2_nta_orq_callback, NULL, NULL,
                               SIP_METHOD_INVITE,
                               (url_string_t *)s2sip->udp.contact->m_url,
                               SIPTAG_SUPPORTED_STR("100rel"),
                               TAG_END());
    fail_unless(orq != NULL);

    request = s2_sip_wait_for_request(SIP_METHOD_INVITE);
    fail_unless(request != NULL);

    s2_sip_respond_to(request, dialog, SIP_183_SESSION_PROGRESS,
                      SIPTAG_RSEQ_STR("1"),
                      SIPTAG_REQUIRE_STR("100rel"),
                      TAG_END());

    response = s2_nta_wait_for(wait_for_orq, orq,
                               wait_for_status, 183,
                               0);

    sip = response->sip;
    tagged = nta_outgoing_tagged(orq, s2_nta_orq_callback, NULL,
                                 sip->sip_to->a_tag, sip->sip_rseq);
    fail_unless(tagged != NULL);

    fail_unless(nta_leg_rtag(leg, sip->sip_to->a_tag) != NULL);

    prack = nta_outgoing_prack(leg, tagged, s2_nta_orq_callback, NULL,
                               NULL, sip, TAG_END());
    r_prack = s2_sip_wait_for_request(SIP_METHOD_PRACK);
    fail_unless(r_prack != NULL);
    s2_sip_respond_to(r_prack, dialog, SIP_200_OK,
                      TAG_END());
    s2_sip_free_message(r_prack);

    response = s2_nta_wait_for(wait_for_orq, prack,
                               wait_for_status, 200,
                               0);
    fail_unless(response != NULL);

    nta_outgoing_destroy(prack);

    s2_sip_respond_to(request, NULL, SIP_480_TEMPORARILY_UNAVAILABLE, TAG_END());
    s2_nta_free_event(response);
    response = s2_nta_wait_for(wait_for_orq, orq,
                               wait_for_status, 480,
                               0);
    fail_unless(response != NULL);
    s2_nta_free_event(response), response = NULL;
    r_ack = s2_sip_wait_for_request(SIP_METHOD_ACK);
    s2_sip_free_message(r_ack);
    nta_outgoing_destroy(orq), orq = NULL;
    s2_sip_free_message(request);

    /* 408 is eventually received by tagged transaction */
    response = s2_nta_wait_for(wait_for_orq, tagged,
                               wait_for_status, 408,
                               0);
    fail_unless(response != NULL);
    nta_outgoing_destroy(tagged);

    s2_nta_free_event(response);
}
END_TEST

START_TEST(client_2_1_2)
{
    nta_outgoing_t *orq;
    struct message *request;
    struct event *response;
    url_t udpurl[1];

    S2_CASE("client-2.1.2", "Send MESSAGE",
            "Non-INVITE transaction to TCP-only server");

    client_setup_tcp_only_server();

    *udpurl = *s2sip->tcp.contact->m_url;
    udpurl->url_params = "transport=udp";

    /* Create DNS records for both UDP and TCP, resolver matches UDP */
    s2_dns_domain("udptcp.org", 1,
                  "s2", 1, udpurl,
                  "s2", 2, s2sip->tcp.contact->m_url,
                  NULL);

    /* Sent to tport selected by resolver */
    orq = nta_outgoing_tcreate(s2->default_leg,
                               s2_nta_orq_callback, NULL,
                               URL_STRING_MAKE("sip:udptcp.org"),
                               SIP_METHOD_MESSAGE,
                               URL_STRING_MAKE("sip:test2.0.example.org"),
                               SIPTAG_FROM_STR("<sip:[email protected]>"),
                               TAG_END());
    fail_unless(orq != NULL);
    response = s2_nta_wait_for(wait_for_orq, orq,
                               wait_for_status, 503,
                               0);
    s2_nta_free_event(response);
    nta_outgoing_destroy(orq);

    /* Message size exceeds 1300, tries to use TCP even if NAPTR points to UDP */
    orq = nta_outgoing_tcreate(s2->default_leg,
                               s2_nta_orq_callback, NULL,
                               URL_STRING_MAKE("sip:udptcp.org"),
                               SIP_METHOD_MESSAGE,
                               URL_STRING_MAKE("sip:test2.0.example.org"),
                               SIPTAG_FROM_STR("<sip:[email protected]>"),
#define ROW "012345678901234567890123456789012345678901234\n"
                               SIPTAG_PAYLOAD_STR( /* > 1300 bytes */
                                   "0000 " ROW "0050 " ROW
                                   "0100 " ROW "0150 " ROW
                                   "0200 " ROW "0250 " ROW
                                   "0300 " ROW "0350 " ROW
                                   "0400 " ROW "0450 " ROW
                                   "0500 " ROW "0550 " ROW
                                   "0600 " ROW "0650 " ROW
                                   "0700 " ROW "0750 " ROW
                                   "0800 " ROW "0850 " ROW
                                   "0900 " ROW "0950 " ROW
                                   "1000 " ROW "1050 " ROW
                                   "1100 " ROW "1150 " ROW
                                   "1200 " ROW "1250 " ROW
                               ),
#undef ROW
                               TAG_END());
    fail_unless(orq != NULL);
    request = s2_sip_wait_for_request(SIP_METHOD_MESSAGE);
    fail_unless(request != NULL);
    fail_unless(request->sip->sip_via->v_protocol == sip_transport_tcp);
    s2_sip_respond_to(request, NULL, 200, "2.1.2", TAG_END());
    s2_sip_free_message(request);
    response = s2_nta_wait_for(wait_for_orq, orq,
                               wait_for_status, 200,
                               0);
    s2_nta_free_event(response);
    nta_outgoing_destroy(orq);
}
Example #23
0
END_TEST

#include <sys/time.h>

START_TEST(register_1_2_4)
{
    nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
    struct message *m;
    struct event *e;
    unsigned t1, n;

    S2_CASE("1.2.4", "Register behind NAT",
            "Authenticate, outbound activated, "
            "drop OPTIONS, check that OPTIONS is not retried");

    mark_point();
    make_auth_natted_register(nh,
                              NUTAG_OUTBOUND("validate, no-options-keepalive"),  /* test with a round of unanswered plain keepalives as well? */
                              TAG_END());

    s2->registration->nh = nh;
    mark_point();

    t1 = 500;

    for (t1 = 500, n = 0; n < 20; n++) {
        e = NULL, m = NULL;

        s2_next_thing(&e, &m);

        if (e)
            break;

        fail_if(!m);
        fail_if(!m->sip->sip_request);
        fail_if(m->sip->sip_request->rq_method != sip_method_options);
        s2_sip_free_message(m);

        mark_point();

        s2_nua_fast_forward((t1 + 500) / 1000, s2base->root);
        t1 *= 2;
        if (t1 > 4000)
            t1 = 4000;
    }

    fail_unless(e != NULL);
    fail_unless(e->data->e_event == nua_i_outbound);
    fail_unless(e->data->e_status == 408);
    s2_free_event(e);

    s2_sip_flush_messages();

    s2_nua_fast_forward(3600, s2base->root);

    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
    fail_if(!m);
    fail_if(!m->sip->sip_authorization);
    fail_if(!m->sip->sip_contact);

    s2_default_registration_duration = 120;
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless_event(nua_r_register, 200);

    fail_unless(s2->registration->contact != NULL);
    fail_if(s2->registration->contact->m_next != NULL);

    s2_sip_flush_messages();

    while (s2sip->received == NULL) {
        s2_nua_fast_forward(10, s2base->root);
    }

    m = s2_sip_remove_message(s2sip->received);
    fail_if(!m);
    fail_unless(m->sip->sip_request->rq_method == sip_method_register);
    fail_if(!m->sip->sip_authorization);
    fail_if(!m->sip->sip_contact);
    s2_save_register(m);

    s2_sip_respond_to(m, NULL,
                      SIP_200_OK,
                      SIPTAG_CONTACT(s2->registration->contact),
                      TAG_END());
    s2_sip_free_message(m);

    fail_unless_event(nua_r_register, 200);

    s2_register_teardown();

}
END_TEST
#endif

START_TEST(register_1_3_3_2)
{
  nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
  struct message *m;
  tport_t *tcp;
  int i;

  S2_CASE("1.3.3.2", "Register behind NAT with TCP",
	  "Register w/ TCP using rport, pingpong. ");

  nua_set_params(nua, NTATAG_TCP_RPORT(1), TAG_END());
  fail_unless_event(nua_r_set_params, 200);

  mark_point();
  s2->registration->nh = nh;

  nua_register(nh,
	       NUTAG_PROXY(s2sip->tcp.contact->m_url),
	       NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
	       TAG_END());

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m);

  fail_unless(tport_is_tcp(m->tport));

  tcp = tport_ref(m->tport);

  /* Respond to request over TCP */
  s2_sip_respond_to(m, NULL,
		SIP_401_UNAUTHORIZED,
		SIPTAG_WWW_AUTHENTICATE_STR(s2_auth_digest_str),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);
  fail_unless_event(nua_r_register, 401);
  nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END());

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  fail_if(!m->sip->sip_contact);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_r_register, 200);

  fail_unless(s2->registration->contact != NULL);
  fail_if(s2->registration->contact->m_next != NULL);

  /* Turn off pong */
  tport_set_params(tcp, TPTAG_PONG2PING(0), TAG_END());

  /* Wait until ping-pong failure closes the TCP connection */
  for (i = 0; i < 100; i++) {
    s2_nua_fast_forward(5, s2base->root);
    if (tport_is_closed(tcp))
      break;
  }

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_unless(tport_is_tcp(m->tport));
  fail_unless(tcp != m->tport);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  fail_if(!m->sip->sip_contact);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  tport_unref(tcp);

  /* Contact changed */
  fail_unless_event(nua_r_register, 100);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  fail_if(!m->sip->sip_contact);
  fail_if(!m->sip->sip_contact->m_next);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_r_register, 200);

  s2_register_teardown();
}
END_TEST

#if nomore
START_TEST(register_1_3_3_1)
{
  nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
  struct message *m;
  tport_t *tcp;

  S2_CASE("1.3.3.1", "Register behind NAT with UDP and TCP",
	  "Register with UDP, UDP time-outing, then w/ TCP using rport. ");

  nua_set_params(nua, NTATAG_TCP_RPORT(1), TAG_END());
  fail_unless_event(nua_r_set_params, 200);

  mark_point();
  s2->registration->nh = nh;

  nua_register(nh,
	       NUTAG_OUTBOUND("no-options-keepalive, no-validate"),
	       TAG_END());

  /* NTA tries with UDP, we drop them */
  for (;;) {
    m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m);
    if (!tport_is_udp(m->tport)) /* Drop UDP */
      break;
    s2_sip_free_message(m);
    s2_nua_fast_forward(4, s2base->root);
  }

  tcp = tport_ref(m->tport);

  /* Respond to request over TCP */
  s2_sip_respond_to(m, NULL,
		SIP_401_UNAUTHORIZED,
		SIPTAG_WWW_AUTHENTICATE_STR(s2_auth_digest_str),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);
  fail_unless_event(nua_r_register, 401);
  nua_authenticate(nh, NUTAG_AUTH(s2_auth_credentials), TAG_END());

  /* Turn off pong */
  tport_set_params(tcp, TPTAG_PONG2PING(0), TAG_END());

  /* Now request over UDP ... registering TCP contact! */
  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  s2_save_register(m);
  fail_unless(
    url_has_param(s2->registration->contact->m_url, "transport=tcp"));
  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  /* NUA detects oops... re-registers UDP */
  fail_unless_event(nua_r_register, 100);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_r_register, 200);

  fail_unless(s2->registration->contact != NULL);
  fail_if(s2->registration->contact->m_next != NULL);

  /* Wait until ping-pong failure closes the TCP connection */
  {
    int i;
    for (i = 0; i < 5; i++) {
      su_root_step(s2base->root, 5);
      su_root_step(s2base->root, 5);
      su_root_step(s2base->root, 5);
      s2_nua_fast_forward(5, s2base->root);
    }
  }

  s2_register_teardown();
}
Example #26
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);
}
END_TEST

START_TEST(register_1_2_2_2)
{
  nua_handle_t *nh = nua_handle(nua, NULL, TAG_END());
  struct message *m;

  S2_CASE("1.2.2.2", "Register behind NAT",
	  "Authenticate, outbound activated, "
	  "authenticate OPTIONS probe, "
	  "NAT binding change");

  mark_point();
  make_auth_natted_register(nh, TAG_END());
  s2->registration->nh = nh;

  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_OPTIONS);
  fail_if(!m);
  s2_sip_respond_to(m, NULL,
		SIP_407_PROXY_AUTH_REQUIRED,
		SIPTAG_VIA(natted_via(m, receive_natted)),
		SIPTAG_PROXY_AUTHENTICATE_STR(s2_auth_digest_str),
		TAG_END());
  s2_sip_free_message(m);
  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_OPTIONS);
  fail_if(!m); fail_if(!m->sip->sip_proxy_authorization);
  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  su_root_step(s2base->root, 20); su_root_step(s2base->root, 20);
  s2_nua_fast_forward(120, s2base->root);	  /* Default keepalive interval */
  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_OPTIONS);
  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_VIA(natted_via(m, receive_natted)),
		TAG_END());
  s2_sip_free_message(m);

  su_root_step(s2base->root, 20); su_root_step(s2base->root, 20);
  s2_nua_fast_forward(120, s2base->root);	  /* Default keepalive interval */
  mark_point();

  m = s2_sip_wait_for_request(SIP_METHOD_OPTIONS);
  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_VIA(natted_via(m, receive_natted2)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_i_outbound, 0);

  m = s2_sip_wait_for_request(SIP_METHOD_REGISTER);
  fail_if(!m); fail_if(!m->sip->sip_authorization);
  fail_if(!m->sip->sip_contact || !m->sip->sip_contact->m_next);
  s2_save_register(m);

  s2_sip_respond_to(m, NULL,
		SIP_200_OK,
		SIPTAG_CONTACT(s2->registration->contact),
		SIPTAG_VIA(natted_via(m, receive_natted2)),
		TAG_END());
  s2_sip_free_message(m);

  fail_unless_event(nua_r_register, 200);

  fail_unless(s2->registration->contact != NULL);
  fail_if(s2->registration->contact->m_next != NULL);

  s2_register_teardown();

} END_TEST
Example #28
0
END_TEST

START_TEST(notify_6_3_6)
{
    nua_handle_t *nh;
    struct event *subscribe;
    struct message *notify, *response;
    sip_t *sip;

    S2_CASE("6.3.6", "Explicit refresh with NUTAG_APPL_EVENT()",
            "Process subscription refresh by application");

    nua_set_params(nua,
                   NUTAG_APPL_METHOD("SUBSCRIBE"),
                   NUTAG_APPL_EVENT("presence"),
                   SIPTAG_ALLOW_EVENTS_STR("presence"),
                   TAG_END());
    fail_unless_event(nua_r_set_params, 200);

    s2_sip_request_to(dialog, SIP_METHOD_SUBSCRIBE, NULL,
                      SIPTAG_EVENT_STR("presence"),
                      TAG_END());
    subscribe = s2_wait_for_event(nua_i_subscribe, 100);
    nh = subscribe->nh;
    nua_respond(nh, SIP_202_ACCEPTED,
                NUTAG_WITH_SAVED(subscribe->event),
                TAG_END());
    s2_free_event(subscribe);

    response = s2_sip_wait_for_response(202, SIP_METHOD_SUBSCRIBE);
    s2_sip_update_dialog(dialog, response);
    fail_unless(response->sip->sip_expires != NULL);
    s2_sip_free_message(response);

    nua_notify(nh,
               NUTAG_SUBSTATE(nua_substate_active),
               SIPTAG_PAYLOAD_STR(presence_closed),
               TAG_END());
    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());

    fail_unless_event(nua_r_notify, 200);

    s2_sip_request_to(dialog, SIP_METHOD_SUBSCRIBE, NULL,
                      SIPTAG_EVENT_STR("presence"),
                      TAG_END());
    subscribe = s2_wait_for_event(nua_i_subscribe, 100);
    nh = subscribe->nh;
    nua_respond(nh, SIP_202_ACCEPTED,
                NUTAG_WITH_SAVED(subscribe->event),
                TAG_END());
    s2_free_event(subscribe);

    response = s2_sip_wait_for_response(202, SIP_METHOD_SUBSCRIBE);
    s2_sip_update_dialog(dialog, response);
    fail_unless(response->sip->sip_expires != NULL);
    s2_sip_free_message(response);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());

    fail_unless_event(nua_r_notify, 200);

    /* Now clear list of application events */
    nua_set_params(nua,
                   NUTAG_APPL_EVENT(NULL),
                   NUTAG_SUB_EXPIRES(360),
                   TAG_END());
    fail_unless_event(nua_r_set_params, 200);

    s2_sip_request_to(dialog, SIP_METHOD_SUBSCRIBE, NULL,
                      SIPTAG_EVENT_STR("presence"),
                      TAG_END());
    /* Automatically responded && refreshed */
    subscribe = s2_wait_for_event(nua_i_subscribe, 200);
    s2_free_event(subscribe);

    response = s2_sip_wait_for_response(200, SIP_METHOD_SUBSCRIBE);
    s2_sip_update_dialog(dialog, response);
    fail_unless(response->sip->sip_expires != NULL);
    fail_unless(response->sip->sip_expires->ex_delta == 360);
    s2_sip_free_message(response);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    fail_unless(notify != NULL);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "active"));
    s2_sip_respond_to(notify, dialog, SIP_200_OK, TAG_END());

    fail_unless_event(nua_r_notify, 200);

    nua_handle_destroy(nh);

    notify = s2_sip_wait_for_request(SIP_METHOD_NOTIFY);
    sip = notify->sip;
    fail_unless(sip->sip_subscription_state != NULL);
    fail_unless(su_strmatch(sip->sip_subscription_state->ss_substate,
                            "terminated"));
    s2_sip_respond_to(notify, dialog, SIP_481_NO_TRANSACTION, TAG_END());
}