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); }
END_TEST START_TEST(subscribe_6_1_3) { nua_handle_t *nh; struct message *response; struct event *notify, *event; S2_CASE("6.1.3", "Subscription terminated by notifier", "NUA sends SUBSCRIBE, waits for NOTIFY, " "gets NOTIFY terminating the subscription,"); 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); fail_if(s2_sip_request_to(dialog, SIP_METHOD_NOTIFY, NULL, SIPTAG_EVENT_STR(event_type), SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), 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); nua_handle_destroy(nh); }
/** 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; }
int luasofia_nua_handle_create(lua_State *L, nua_t *nua) { luasofia_nua_handle_t *lnh = NULL; nua_handle_t *nh = NULL; su_home_t *home = su_home_create(); tagi_t *tags = luasofia_tags_table_to_taglist(L, 2, home); /* create a nua_handle object */ lnh = (luasofia_nua_handle_t*)lua_newuserdata(L, sizeof(luasofia_nua_handle_t)); /* create the nua_handle_t */ nh = nua_handle(nua, lnh, TAG_NEXT(tags)); if (!nh) luaL_error(L, "nua_handle failed!"); /* set Lua state */ lnh->L = L; lnh->nh = nh; /* set its metatable */ luaL_getmetatable(L, NUA_HANDLE_MTABLE); lua_setmetatable(L, -2); /* store nua handle at luasofia userdata table */ luasofia_userdata_table_set(L, nh); su_home_unref(home); return 1; }
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(); }
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(); }
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(); }
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(); }
static void mrcp_sofia_on_session_redirect( int status, mrcp_sofia_agent_t *sofia_agent, nua_handle_t *nh, mrcp_sofia_session_t *sofia_session, sip_t const *sip, tagi_t tags[]) { mrcp_session_t *session = sofia_session->session; sip_contact_t *sip_contact; if(!sip) { return; } sip_contact = sip->sip_contact; if(!sip_contact || !sip_contact->m_url) { return; } if(sip_contact->m_url->url_user && sip_contact->m_url->url_user != '\0') { sofia_session->sip_to_str = apr_psprintf(session->pool,"sip:%s@%s:%s", sip_contact->m_url->url_user, sip_contact->m_url->url_host, sip_contact->m_url->url_port); } else { sofia_session->sip_to_str = apr_psprintf(session->pool,"sip:%s:%s", sip_contact->m_url->url_host, sip_contact->m_url->url_port); } apr_thread_mutex_lock(sofia_session->mutex); apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,session->log_obj,"Redirect "APT_NAMESID_FMT" to %s", session->name, MRCP_SESSION_SID(session), sofia_session->sip_to_str); if(sofia_session->nh) { nua_handle_bind(sofia_session->nh, NULL); nua_handle_destroy(sofia_session->nh); sofia_session->nh = NULL; } sofia_session->nh = nua_handle( sofia_agent->nua, sofia_session, SIPTAG_TO_STR(sofia_session->sip_to_str), SIPTAG_FROM_STR(sofia_agent->sip_from_str), SIPTAG_CONTACT_STR(sofia_agent->sip_contact_str), TAG_END()); apr_thread_mutex_unlock(sofia_session->mutex); mrcp_sofia_session_offer(sofia_session->session,sofia_session->descriptor); }
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); }
END_TEST START_TEST(SIP_CC_OE_CE_TI_011_012) { nua_handle_t *nh; struct message *invite; S2_CASE("6.1.2", "SIP_CC_OE_CE_TI_011_012", "Ensure that the IUT, when an INVITE client transaction " "has been in the Terminated state, on receipt of a " "retransmitted Success (200 OK) responses sends an ACK " "request until 64*T1 duration expires, after this, " "on receipt of a retransmitted Success (200 OK) " "responses does not send an ACK request."); nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END()); invite = invite_sent_by_nua(nh, TAG_END()); process_offer(invite); respond_with_sdp(invite, d1, SIP_200_OK, TAG_END()); fail_unless_event(nua_r_invite, 200); fail_unless(s2_check_callstate(nua_callstate_ready)); fail_unless(s2_sip_check_request(SIP_METHOD_ACK)); s2_nua_fast_forward(5, s2base->root); respond_with_sdp(invite, d1, SIP_200_OK, TAG_END()); fail_unless(s2_sip_check_request(SIP_METHOD_ACK)); s2_nua_fast_forward(5, s2base->root); respond_with_sdp(invite, d1, SIP_200_OK, TAG_END()); fail_unless(s2_sip_check_request(SIP_METHOD_ACK)); s2_nua_fast_forward(20, s2base->root); respond_with_sdp(invite, d1, SIP_200_OK, TAG_END()); fail_unless(s2_sip_check_request(SIP_METHOD_ACK)); /* Stack times out the INVITE transaction */ s2_nua_fast_forward(5, s2base->root); respond_with_sdp(invite, d1, SIP_200_OK, SIPTAG_SUBJECT_STR("Stray 200 OK"), TAG_END()); s2_sip_free_message(invite); mark_point(); fail_if(s2_sip_check_request_timeout(SIP_METHOD_ACK, 3)); bye_by_nua(d1, nh, TAG_END()); nua_handle_destroy(nh); }
END_TEST START_TEST(SIP_CC_OE_CE_TI_008) { nua_handle_t *nh; struct message *invite; S2_CASE("6.1.2", "SIP_CC_OE_CE_TI_008", "If an unreliable transport is used, ensure that " "the IUT, when an INVITE client transaction is in " "the Completed state, on receipt of final responses " "that matches the transaction, still answer with an " "ACK request until timer D set to at least 32 second expires."); nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END()); invite = invite_sent_by_nua(nh, TAG_END()); s2_sip_respond_to(invite, d1, 404, "First not found", TAG_END()); fail_unless_event(nua_r_invite, 404); fail_unless(s2_check_callstate(nua_callstate_terminated)); fail_unless(s2_sip_check_request(SIP_METHOD_ACK)); s2_nua_fast_forward(5, s2base->root); s2_sip_respond_to(invite, d1, 404, "Not found after 5 seconds", TAG_END()); fail_unless(s2_sip_check_request(SIP_METHOD_ACK)); s2_nua_fast_forward(5, s2base->root); s2_sip_respond_to(invite, d1, 404, "Not found after 10 seconds", TAG_END()); fail_unless(s2_sip_check_request(SIP_METHOD_ACK)); s2_nua_fast_forward(21, s2base->root); s2_sip_respond_to(invite, d1, 404, "Not found after 31 seconds", TAG_END()); fail_unless(s2_sip_check_request(SIP_METHOD_ACK)); s2_nua_fast_forward(5, s2base->root); /* Wake up nua thread and let it time out INVITE transaction */ nua_set_params(s2->nua, TAG_END()); fail_unless_event(nua_r_set_params, 0); s2_sip_respond_to(invite, d1, 404, "Not found after 32 seconds", TAG_END()); s2_sip_free_message(invite); fail_if(s2_sip_check_request_timeout(SIP_METHOD_ACK, 3)); nua_handle_destroy(nh); }
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); }
} END_TEST START_TEST(register_1_3_2_1) { nua_handle_t *nh = nua_handle(nua, NULL, TAG_END()); S2_CASE("1.3.2.1", "Register behind NAT", "Authenticate, outbound activated"); mark_point(); s2->registration->nh = nh; make_auth_natted_register(nh, NUTAG_PROXY(s2sip->tcp.contact->m_url), TAG_END()); fail_if(!tport_is_tcp(s2->registration->tport)); s2_register_teardown(); }
} 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
END_TEST START_TEST(subscribe_6_1_5) { nua_handle_t *nh; struct event *notify; sip_via_t *vorig = s2_sip_tport_via(s2sip->udp.tport); sip_via_t via[2]; char *v0_params[8] = {}, *v1_params[8] = {}; char branch0[32], branch1[32]; S2_CASE("6.1.5", "Via handling in response to NOTIFY", "NUA sends SUBSCRIBE, waits for NOTIFY, sends un-SUBSCRIBE"); nh = nua_handle(nua, NULL, SIPTAG_TO(s2sip->aor), TAG_END()); nua_subscribe(nh, SIPTAG_EVENT_STR(event_type), TAG_END()); s2_sip_msg_flags = MSG_FLG_COMMA_LISTS|MSG_FLG_COMPACT; fail_if(vorig == NULL); via[0] = *vorig; via[0].v_host = "example.org"; via[0].v_params = (void *)v0_params; snprintf(v0_params[0] = branch0, sizeof branch0, "branch=z9hG4bK%lx", ++s2sip->tid); fail_if(vorig == NULL); via[1] = *vorig; via[1].v_params = (void *)v1_params; snprintf(v1_params[0] = branch1, sizeof branch1, "branch=z9hG4bK%lx", ++s2sip->tid); notify = subscription_by_nua(nh, nua_substate_embryonic, SIPTAG_VIA(via + 1), SIPTAG_VIA(via + 0), TAG_END()); s2_sip_msg_flags = 0; s2_free_event(notify); unsubscribe_by_nua(nh, TAG_END()); nua_handle_destroy(nh); }
END_TEST START_TEST(subscribe_6_1_4) { nua_handle_t *nh; struct message *response; struct event *notify, *event; S2_CASE("6.1.4", "Subscription terminated by notifier, re-established", "NUA sends SUBSCRIBE, waits for NOTIFY, " "gets NOTIFY terminating the subscription,"); 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); fail_if(s2_sip_request_to(dialog, SIP_METHOD_NOTIFY, NULL, SIPTAG_EVENT_STR(event_type), SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=deactivated"), TAG_END())); event = s2_wait_for_event(nua_i_notify, 200); fail_if(!event); fail_unless(s2_check_substate(event, nua_substate_embryonic)); s2_free_event(event); response = s2_sip_wait_for_response(200, SIP_METHOD_NOTIFY); fail_if(!response); s2_sip_free_message(response); su_home_unref((void *)dialog), dialog = su_home_new(sizeof *dialog); fail_if(!dialog); s2_nua_fast_forward(5, s2base->root); /* nua re-establishes the subscription */ notify = subscription_by_nua(nh, nua_substate_embryonic, TAG_END()); s2_free_event(notify); /* Unsubscribe with nua_subscribe() Expires: 0 */ nua_subscribe(nh, SIPTAG_EVENT_STR(event_type), SIPTAG_EXPIRES_STR("0"), TAG_END()); notify = subscription_by_nua(nh, nua_substate_active, TAG_END()); s2_free_event(notify); nua_handle_destroy(nh); }
static apt_bool_t mrcp_sofia_session_create(mrcp_session_t *session, mrcp_sig_settings_t *settings) { mrcp_sofia_agent_t *sofia_agent = mrcp_sofia_agent_get(session); mrcp_sofia_session_t *sofia_session; session->request_vtable = &session_request_vtable; if(!sofia_agent->nua) { return FALSE; } sofia_session = apr_palloc(session->pool,sizeof(mrcp_sofia_session_t)); sofia_session->mutex = NULL; sofia_session->home = su_home_new(sizeof(*sofia_session->home)); sofia_session->session = session; sofia_session->sip_settings = settings; sofia_session->terminate_requested = FALSE; sofia_session->descriptor = NULL; session->obj = sofia_session; if(settings->user_name && settings->user_name != '\0') { sofia_session->sip_to_str = apr_psprintf(session->pool,"sip:%s@%s:%hu", settings->user_name, settings->server_ip, settings->server_port); } else { sofia_session->sip_to_str = apr_psprintf(session->pool,"sip:%s:%hu", settings->server_ip, settings->server_port); } sofia_session->nh = nua_handle( sofia_agent->nua, sofia_session, SIPTAG_TO_STR(sofia_session->sip_to_str), SIPTAG_FROM_STR(sofia_agent->sip_from_str), SIPTAG_CONTACT_STR(sofia_agent->sip_contact_str), TAG_IF(settings->feature_tags,SIPTAG_ACCEPT_CONTACT_STR(settings->feature_tags)), TAG_END()); sofia_session->nua_state = nua_callstate_init; apr_thread_mutex_create(&sofia_session->mutex,APR_THREAD_MUTEX_DEFAULT,session->pool); return TRUE; }
END_TEST START_TEST(fetch_6_2_2) { nua_handle_t *nh; struct event *notify; S2_CASE("6.2.2", "Event fetch - NOTIFY before 200", "NUA sends SUBSCRIBE with Expires 0, waits for NOTIFY"); send_notify_before_response = 1; 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()); notify = subscription_by_nua(nh, nua_substate_embryonic, TAG_END()); s2_check_substate(notify, nua_substate_terminated); s2_free_event(notify); nua_handle_destroy(nh); }
static apt_bool_t mrcp_sofia_session_create(mrcp_session_t *session) { mrcp_sofia_agent_t *sofia_agent = session->signaling_agent->obj; mrcp_sofia_session_t *sofia_session; session->request_vtable = &session_request_vtable; sofia_session = apr_palloc(session->pool,sizeof(mrcp_sofia_session_t)); sofia_session->home = su_home_new(sizeof(*sofia_session->home)); sofia_session->session = session; sofia_session->terminate_requested = FALSE; session->obj = sofia_session; sofia_session->nh = nua_handle( sofia_agent->nua, sofia_session, SIPTAG_TO_STR(sofia_agent->sip_to_str), SIPTAG_FROM_STR(sofia_agent->sip_from_str), SIPTAG_CONTACT_STR(sofia_agent->sip_contact_str), TAG_END()); return TRUE; }
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); }
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 */ }
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(); }
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
/** * Creates a new operation object and stores it the list of * active operations for 'cli'. */ ssc_oper_t *ssc_oper_create(ssc_t *ssc, sip_method_t method, char const *name, char const *address, tag_type_t tag, tag_value_t value, ...) { ssc_oper_t *op, *old; ta_list ta; enter; for (old = ssc->ssc_operations; old; old = old->op_next) if (!old->op_persistent) break; if (address) { int have_url = 1; sip_to_t *to; to = sip_to_make(ssc->ssc_home, address); if (to == NULL) { printf("%s: %s: invalid address: %s\n", ssc->ssc_name, name, address); return NULL; } /* Try to make sense out of the URL */ if (url_sanitize(to->a_url) < 0) { printf("%s: %s: invalid address\n", ssc->ssc_name, name); return NULL; } if (!(op = su_zalloc(ssc->ssc_home, sizeof(*op)))) { printf("%s: %s: cannot create handle\n", ssc->ssc_name, name); return NULL; } op->op_next = ssc->ssc_operations; op->op_prev_state = -1; op->op_ssc = ssc; ssc->ssc_operations = op; if (method == sip_method_register) have_url = 0; ta_start(ta, tag, value); op->op_handle = nua_handle(ssc->ssc_nua, op, TAG_IF(have_url, NUTAG_URL(to->a_url)), SIPTAG_TO(to), ta_tags(ta)); ta_end(ta); op->op_ident = sip_header_as_string(ssc->ssc_home, (sip_header_t *)to); ssc_oper_assign(op, method, name); if (!op->op_persistent) { ssc_oper_t *old_next; for (; old; old = old_next) { /* Clean old handles */ old_next = old->op_next; if (!old->op_persistent && !old->op_callstate) ssc_oper_destroy(ssc, old); } } su_free(ssc->ssc_home, to); } else if (method || name) ssc_oper_assign(op = old, method, name); else return old; if (!op) { if (address) printf("%s: %s: invalid destination\n", ssc->ssc_name, name); else printf("%s: %s: no destination\n", ssc->ssc_name, name); return NULL; } return op; }
int test_extension(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; sip_t const *sip; /* Test for EXTENSION A B |------EXTENSION---->| |<--------501--------| (method not recognized) | | |------EXTENSION---->| |<-------200---------| (method allowed, responded) | | */ if (print_headings) printf("TEST NUA-13.1: EXTENSION\n"); TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END())); /* Test first without NUTAG_METHOD() */ METHOD(a, a_call, a_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, NULL); /* Client events: nua_method(), nua_r_method */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method); TEST(e->data->e_status, 900); /* Internal error */ TEST_1(!e->data->e_msg); TEST_1(!e->next); free_events_in_list(ctx, a->events); nua_handle_destroy(a_call->nh), a_call->nh = NULL; TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END())); METHOD(a, a_call, a_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)), NUTAG_METHOD("EXTENSION"), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, NULL); /* Client events: nua_method(), nua_r_method */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method); TEST(e->data->e_status, 501); TEST_1(!e->next); free_events_in_list(ctx, a->events); nua_handle_destroy(a_call->nh), a_call->nh = NULL; free_events_in_list(ctx, b->events); nua_handle_destroy(b_call->nh), b_call->nh = NULL; nua_set_params(b->nua, NUTAG_ALLOW("EXTENSION"), 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())); METHOD(a, a_call, a_call->nh, TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)), NUTAG_METHOD("EXTENSION"), TAG_END()); run_ab_until(ctx, -1, save_until_final_response, -1, respond_to_extension); /* Client events: nua_method(), nua_r_method */ TEST_1(e = a->events->head); TEST_E(e->data->e_event, nua_r_method); TEST(e->data->e_status, 200); TEST_1(sip = sip_object(e->data->e_msg)); TEST_1(!e->next); /* Server events: nua_i_method */ TEST_1(e = b->events->head); TEST_E(e->data->e_event, nua_i_method); TEST(e->data->e_status, 100); TEST_1(!e->next); free_events_in_list(ctx, a->events); nua_handle_destroy(a_call->nh), a_call->nh = NULL; free_events_in_list(ctx, b->events); nua_handle_destroy(b_call->nh), b_call->nh = NULL; nua_set_params(b->nua, SIPTAG_ALLOW(b->allow), NUTAG_APPL_METHOD(NULL), NUTAG_APPL_METHOD(b->appl_method), TAG_END()); run_b_until(ctx, nua_r_set_params, until_final_response); if (print_headings) printf("TEST NUA-13.1: PASSED\n"); END(); }