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); }
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 int luasofia_nua_handle_subscribe(lua_State *L) { /* get and check first argument (should be a luasofia_nua_handle_t) */ luasofia_nua_handle_t *lnh = (luasofia_nua_handle_t*) luaL_checkudata(L, 1, NUA_HANDLE_MTABLE); if (lnh->nh) { su_home_t *home = su_home_create(); /* get and check second argument (should be a tag table) */ tagi_t *tags = luasofia_tags_table_to_taglist(L, 2, home); nua_subscribe(lnh->nh, TAG_NEXT(tags)); su_home_unref(home); } return 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); }
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(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); }